forked from christianhujer/expensereport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExpenseReport.s
307 lines (268 loc) · 4.76 KB
/
ExpenseReport.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
_LVOOpenLibrary EQU -552
_LVOCloseLibrary EQU -414
_LVOFindTask EQU -294
_LVOWrite EQU -48
OS_VERSION EQU 33
DINNER EQU 1
BREAKFAST EQU 2
CAR_RENTAL EQU 3
MC68020 ; using divul.l for itoa
SECTION TEXT
main
move.l 4.w,a6
.openDos
lea (dosName),a1
moveq #OS_VERSION,d0
jsr (_LVOOpenLibrary,a6)
move.l d0,dosBase
bne.s .dosOk
.dosError
move.l #2,(exitStatus)
bra .exit
.dosOk
.cli
sub.l a1,a1
jsr (_LVOFindTask,a6)
move.l d0,a0
tst.l (172,a0) ; CLI Process?
bne.s .cliOk
.cliError
move.l #2,(exitStatus)
bra.s .closeDos
.cliOk
move.l (160,a0),d0
move.l d0,(stdout)
lea (expenses),a0
bsr.s printReport
.closeDos
move.l (dosBase),a1
jsr (_LVOCloseLibrary,a6)
.exit
move.l (exitStatus),d0
moveq #1,d1
rts
printReport
movem.l d2/d3/d5/d6/d7/a2/a6,-(sp)
move.l a0,a2
moveq #0,d5 ; mealExpenses
moveq #0,d6 ; totalExpenses
move.l (dosBase),a6
move.l (stdout),d1
move.l #expenseReport,d2
moveq #expenseReportEnd-expenseReport,d3
jsr (_LVOWrite,a6)
move.l (stdout),d1
move.l #newline,d2
moveq #1,d3
jsr (_LVOWrite,a6)
.loop
move.l (a2),d0
beq .loopDone
cmp.l #DINNER,d0
beq.s .meal
cmp.l #BREAKFAST,d0
beq.s .meal
bra.s .notMeal
.meal
move.l (4,a2),d1
add.l d1,d5
.notMeal
lea (expenseNames),a0
move.l (a0,d0*4),a0
move.l a0,d2
.countExpenseName
move.b (a0)+,d0
bne.s .countExpenseName
move.l a0,d3
sub.l d2,d3
subq #1,d3
move.l (stdout),d1
jsr (_LVOWrite,a6)
lea (tab),a0
move.l (stdout),d1
move.l a0,d2
moveq #1,d3
jsr (_LVOWrite,a6)
move.l (4,a2),d0
lea buffer,a0
bsr itoa10
move.l d0,d2
move.l d2,a0
.countAmount
move.b (a0)+,d0
bne.s .countAmount
move.l a0,d3
sub.l d2,d3
subq #1,d3
move.l (stdout),d1
jsr (_LVOWrite,a6)
lea (tab),a0
move.l (stdout),d1
move.l a0,d2
moveq #1,d3
jsr (_LVOWrite,a6)
move.l (a2),d0
move.l (4,a2),d1
cmp.l #DINNER,d0
bne.s .notDinner
cmp.l #5000,d1
bgt.s .mealOverExpense
bra.s .mealNotOverExpense
.notDinner
cmp.l #BREAKFAST,d0
bne.s .notBreakfast
cmp.l #1000,d1
bgt.s .mealOverExpense
bra.s .mealNotOverExpense
.notBreakfast
bra.s .mealNotOverExpense
.mealOverExpense
lea (mealOverExpensesMarker),a0
bra.s .printMealOverExpensesMarker
.mealNotOverExpense
lea (mealNotOverExpensesMarker),a0
.printMealOverExpensesMarker
move.l (stdout),d1
move.l a0,d2
moveq #1,d3
jsr (_LVOWrite,a6)
lea (newline),a0
move.l (stdout),d1
move.l a0,d2
moveq #1,d3
jsr (_LVOWrite,a6)
move.l (4,a2),d1
add.l d1,d6
addq #8,a2 ; next expense
bra .loop
.loopDone
move.l (stdout),d1
lea (meals),a0
move.l a0,d2
moveq #mealsEnd-meals,d3
jsr (_LVOWrite,a6)
move.l d5,d0
lea (buffer),a0
bsr itoa10
move.l d0,d2
move.l d2,a0
.count2
move.b (a0)+,d0
bne.s .count2
move.l a0,d3
sub.l d2,d3
subq #1,d3
move.l (stdout),d1
move.l (dosBase),a6
jsr (_LVOWrite,a6)
move.l (stdout),d1
lea (newline),a0
move.l a0,d2
moveq #1,d3
jsr (_LVOWrite,a6)
move.l (stdout),d1
lea (total),a0
move.l a0,d2
moveq #totalEnd-total,d3
jsr (_LVOWrite,a6)
move.l d6,d0
lea (buffer),a0
bsr itoa10
move.l d0,d2
move.l d2,a0
.count3
move.b (a0)+,d0
bne.s .count3
move.l a0,d3
sub.l d2,d3
subq #1,d3
move.l (stdout),d1
move.l (dosBase),a6
jsr (_LVOWrite,a6)
move.l (stdout),d1
lea (newline),a0
move.l a0,d2
moveq #1,d3
jsr (_LVOWrite,a6)
movem.l (sp)+,d2/d3/d5/d6/d7/a2/a6
rts
; Returns the length of a NUL-terminated string, without the NUL byte
; @param a0 NUL-terminated string
; @return d0 Length of the NUL-terminated string
; @destroys d0,a0,a1
strlen
move.l a0,a1
.count
move.b (a1)+,d0
bne.s .count
move.l a1,d0
sub.l a0,d0
subq #1,d0
rts
; Converts a number into a decimal string
; @param a0 buffer in which to convert the number
; @param d0 number to convert
; @return d0 buffer from a0
; @destroys d1,a0,a1
itoa10
movem.l a0/d2,-(sp)
.loop
moveq #10,d1
divul.l d1,d1:d0
add.l #'0',d1
move.b d1,(a0)+
tst.l d0
bne.s .loop
move.b #0,d1
move.b d1,(a0)+
movem.l (sp)+,a0/d2
move.l a0,d0
move.l a0,a1
.count
move.b (a1)+,d1
bne.s .count
subq #2,a1
.reverse
cmp.l a0,a1
ble.s .reverseDone
move.b (a0),d1
move.b (a1),(a0)
move.b d1,(a1)
subq #1,a1
addq #1,a0
bra.s .reverse
.reverseDone
rts
SECTION DATA
dosName dc.b "dos.library",0
SECTION DATA
align.l
expenseNames dc.l 0,dinner,breakfast,car_rental
dinner dc.b "Dinner",0
breakfast dc.b "Breakfast",0
car_rental dc.b "Car Rental",0
tab dc.b 9,0
newline dc.b 10,0
expenseReport dc.b "Expenses: "
expenseReportEnd dc.b 0
meals dc.b "Meal Expenses: "
mealsEnd dc.b 0
total dc.b "Total Expenses: "
totalEnd dc.b 0
mealOverExpensesMarker dc.b "X",0
mealNotOverExpensesMarker dc.b " ",0
SECTION DATA
align.l
expenses
dc.l DINNER,5000
dc.l DINNER,5001
dc.l BREAKFAST,1000
dc.l BREAKFAST,1001
dc.l CAR_RENTAL,4
dc.l 0,0
SECTION BSS
exitStatus ds.l 1
dosBase ds.l 1
stdout ds.l 1
buffer ds.b 11
END