-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexec_flags.S
575 lines (498 loc) · 10.2 KB
/
exec_flags.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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
; ****************************************************************************
;
; Execute flags
;
; ****************************************************************************
#include "include.inc"
.text
; ----------------------------------------------------------------------------
; Set flag
; ----------------------------------------------------------------------------
; B0: F_INV ... INV flag
; B1: F_EE ... EE mode (not set together with Eng)
; B2: F_ENG ... Eng mode (not set together with EE)
; B3: F_RESDEC ... restart DecNum function
; B4: F_DP ... decimal point entered
; B5: F_EXP ... entering exponent
; B6: F_INKEY ... waiting input keys
; B7: F_OLDTRACE ... old trace state
; B0: F2_ERRDEC ... overflow error in DecNum function
; B1: F2_OLDERR old error flag during DecNum
; B2: F2_DEBUG debug mode, display HEX mantissa
; B3: F2_OLDRUN old running flag during ExecPr
; B4: F2_DISP_REGT display mode reg T (or flags otherwise)
; B5: F2_DISP_TEXT display mode text (or T/flags otherwise, reset by CLR)
; set flag INV
; DESTROYS: -
.global FlagSetInv
FlagSetInv:
push r25
ldi r25,BIT(F_INV)
FlagSet:
push r24
ldd r24,Y+DATA_FLAGS
or r24,r25
std Y+DATA_FLAGS,r24
pop r24
pop r25
ret
; set flag 'EE mode'
; DESTROYS: -
.global FlagSetEE
FlagSetEE:
push r25
ldi r25,BIT(F_EE)
rjmp FlagSet
; set flag 'Eng mode'
; DESTROYS: -
.global FlagSetEng
FlagSetEng:
push r25
ldi r25,BIT(F_ENG)
rjmp FlagSet
; set flag 'restart DecNum'
; DESTROYS: -
.global FlagSetResDec
FlagSetResDec:
push r25
ldi r25,BIT(F_RESDEC)
rjmp FlagSet
; set flag 'decimal point'
; DESTROYS: -
.global FlagSetDP
FlagSetDP:
push r25
ldi r25,BIT(F_DP)
rjmp FlagSet
; set flag 'exponent'
; DESTROYS: -
.global FlagSetExp
FlagSetExp:
push r25
ldi r25,BIT(F_EXP)
rjmp FlagSet
; set flag 'input keys'
; DESTROYS: -
.global FlagSetInKey
FlagSetInKey:
push r25
ldi r25,BIT(F_INKEY)
rjmp FlagSet
; set flag 'old trace' (served in DispTrace)
; DESTROYS: -
;.global FlagSetOldTrace
;FlagSetOldTrace:
; push r25
; ldi r25,BIT(F_OLDTRACE)
; rjmp FlagSet
; set flag ErrDec
; DESTROYS: -
.global FlagSetErrDec
FlagSetErrDec:
push r25
ldi r25,BIT(F2_ERRDEC)
FlagSet2:
push r24
ldd r24,Y+DATA_FLAGS2
or r24,r25
std Y+DATA_FLAGS2,r24
pop r24
pop r25
ret
; set flag OldErr
; DESTROYS: -
.global FlagSetOldErr
FlagSetOldErr:
push r25
ldi r25,BIT(F2_OLDERR)
rjmp FlagSet2
; set flag Debug
; DESTROYS: -
.global FlagSetDebug
FlagSetDebug:
push r25
ldi r25,BIT(F2_DEBUG)
rjmp FlagSet2
; set flag OldRun
; DESTROYS: -
.global FlagSetOldRun
FlagSetOldRun:
push r25
ldi r25,BIT(F2_OLDRUN)
rjmp FlagSet2
; set flag DispRegT
; DESTROYS: -
.global FlagSetDispRegT
FlagSetDispRegT:
push r25
ldi r25,BIT(F2_DISP_REGT)
rjmp FlagSet2
; set flag DispText
; DESTROYS: -
.global FlagSetDispText
FlagSetDispText:
push r25
ldi r25,BIT(F2_DISP_TEXT)
rjmp FlagSet2
; ----------------------------------------------------------------------------
; Clear flag
; ----------------------------------------------------------------------------
; clear flag INV
; DESTROYS: -
.global FlagClrInv
FlagClrInv:
push r25
ldi r25,~BIT(F_INV)
FlagClr:
push r24
ldd r24,Y+DATA_FLAGS
and r24,r25
std Y+DATA_FLAGS,r24
pop r24
pop r25
ret
; clear flag 'EE mode'
; DESTROYS: -
.global FlagClrEE
FlagClrEE:
push r25
ldi r25,~BIT(F_EE)
rjmp FlagClr
; clear flag 'Eng mode'
; DESTROYS: -
.global FlagClrEng
FlagClrEng:
push r25
ldi r25,~BIT(F_ENG)
rjmp FlagClr
; clear flag 'restart DecNum'
; DESTROYS: -
.global FlagClrResDec
FlagClrResDec:
push r25
ldi r25,~BIT(F_RESDEC)
rjmp FlagClr
; clear flag 'decimal point'
; DESTROYS: -
.global FlagClrDP
FlagClrDP:
push r25
ldi r25,~BIT(F_DP)
rjmp FlagClr
; clear flag 'exponent'
; DESTROYS: -
.global FlagClrExp
FlagClrExp:
push r25
ldi r25,~BIT(F_EXP)
rjmp FlagClr
; clear flag 'input keys'
; DESTROYS: -
.global FlagClrInKey
FlagClrInKey:
push r25
ldi r25,~BIT(F_INKEY)
rjmp FlagClr
; clear flag 'old trace' (served in DispTrace)
; DESTROYS: -
;.global FlagClrOldTrace
;FlagClrOldTrace:
; push r25
; ldi r25,~BIT(F_OLDTRACE)
; rjmp FlagClr
; clear flag ErrDec
; DESTROYS: -
.global FlagClrErrDec
FlagClrErrDec:
push r25
ldi r25,~BIT(F2_ERRDEC)
FlagClr2:
push r24
ldd r24,Y+DATA_FLAGS2
and r24,r25
std Y+DATA_FLAGS2,r24
pop r24
pop r25
ret
; clear flag OldErr
; DESTROYS: -
.global FlagClrOldErr
FlagClrOldErr:
push r25
ldi r25,~BIT(F2_OLDERR)
rjmp FlagClr2
; clear flag Debug
; DESTROYS: -
.global FlagClrDebug
FlagClrDebug:
push r25
ldi r25,~BIT(F2_DEBUG)
rjmp FlagClr2
; clear flag OldRun
; DESTROYS: -
.global FlagClrOldRun
FlagClrOldRun:
push r25
ldi r25,~BIT(F2_OLDRUN)
rjmp FlagClr2
; clear flag DispRegT
; DESTROYS: -
.global FlagClrDispRegT
FlagClrDispRegT:
push r25
ldi r25,~BIT(F2_DISP_REGT)
rjmp FlagClr2
; clear flag DispText
; DESTROYS: -
.global FlagClrDispText
FlagClrDispText:
push r25
ldi r25,~BIT(F2_DISP_TEXT)
rjmp FlagClr2
; ----------------------------------------------------------------------------
; Test flag
; ----------------------------------------------------------------------------
; test flag INV
; OUTPUT: NZ = flag is set
; DESTROYS: -
.global FlagTestInv
FlagTestInv:
push r25
ldi r25,BIT(F_INV)
FlagTest:
push r24
ldd r24,Y+DATA_FLAGS
and r24,r25
pop r24
pop r25
ret
; test flag 'EE mode'
; OUTPUT: NZ = flag is set
; DESTROYS: -
.global FlagTestEE
FlagTestEE:
push r25
ldi r25,BIT(F_EE)
rjmp FlagTest
; test flag 'Eng mode'
; OUTPUT: NZ = flag is set
; DESTROYS: -
.global FlagTestEng
FlagTestEng:
push r25
ldi r25,BIT(F_ENG)
rjmp FlagTest
; test flag 'EE mode' and 'Eng mode'
; OUTPUT: NZ = flag is set
; DESTROYS: -
.global FlagTestEEEng
FlagTestEEEng:
push r25
ldi r25,BIT(F_EE)+BIT(F_ENG)
rjmp FlagTest
; test flag 'restart DecNum'
; OUTPUT: NZ = flag is set
; DESTROYS: -
.global FlagTestResDec
FlagTestResDec:
push r25
ldi r25,BIT(F_RESDEC)
rjmp FlagTest
; test flag 'decimal point'
; OUTPUT: NZ = flag is set
; DESTROYS: -
.global FlagTestDP
FlagTestDP:
push r25
ldi r25,BIT(F_DP)
rjmp FlagTest
; test flag 'exponent'
; OUTPUT: NZ = flag is set
; DESTROYS: -
.global FlagTestExp
FlagTestExp:
push r25
ldi r25,BIT(F_EXP)
rjmp FlagTest
; test flag 'input keys'
; OUTPUT: NZ = flag is set
; DESTROYS: -
.global FlagTestInKey
FlagTestInKey:
push r25
ldi r25,BIT(F_INKEY)
rjmp FlagTest
; test flag 'old trace' (served in DispTrace)
;.global FlagTestOldTrace
;FlagTestOldTrace:
; push r25
; ldi r25,BIT(F_OLDTRACE)
; rjmp FlagTest
; test flag ErrDec
; OUTPUT: NZ = flag is set
; DESTROYS: -
.global FlagTestErrDec
FlagTestErrDec:
push r25
ldi r25,BIT(F2_ERRDEC)
FlagTest2:
push r24
ldd r24,Y+DATA_FLAGS2
and r24,r25
pop r24
pop r25
ret
; test flag OldErr
; OUTPUT: NZ = flag is set
; DESTROYS: -
.global FlagTestOldErr
FlagTestOldErr:
push r25
ldi r25,BIT(F2_OLDERR)
rjmp FlagTest2
; test flag Debug
; OUTPUT: NZ = flag is set
; DESTROYS: -
.global FlagTestDebug
FlagTestDebug:
push r25
ldi r25,BIT(F2_DEBUG)
rjmp FlagTest2
; test flag OldRun
; OUTPUT: NZ = flag is set
; DESTROYS: -
.global FlagTestOldRun
FlagTestOldRun:
push r25
ldi r25,BIT(F2_OLDRUN)
rjmp FlagTest2
; test flag DispRegT
; OUTPUT: NZ = flag is set
; DESTROYS: -
.global FlagTestDispRegT
FlagTestDispRegT:
push r25
ldi r25,BIT(F2_DISP_REGT)
rjmp FlagTest2
; test flag DispText
; OUTPUT: NZ = flag is set
; DESTROYS: -
.global FlagTestDispText
FlagTestDispText:
push r25
ldi r25,BIT(F2_DISP_TEXT)
rjmp FlagTest2
; ----------------------------------------------------------------------------
; Test user flag
; ----------------------------------------------------------------------------
; INPUT: R24 = index of user flag (0..15)
; OUTPUT: R24 = flag state (1 or 0)
; Z flag set if bit not set (breq = not set '0', brne = set '1')
; ----------------------------------------------------------------------------
; 7=error on Op18/19, 8=stop on error, 9=print log, 15=error
.global UserFlagTest
UserFlagTest:
; error flag
cpi r24,15
breq 9f
push r25
mov r25,r24 ; flag index
ldd r24,Y+DATA_USERFLAGS ; flags low
cpi r25,8 ; flag 8 or more?
brcs 4f ; flag < 8
ldd r24,Y+DATA_USERFLAGS+1 ; flags high
sub r25,8 ; index correction
rjmp 4f
2: lsr r24 ; shift flags right
4: dec r25 ; index counter
brpl 2b ; index >= 0, do next shift
andi r24,1 ; mask bit
pop r25
ret
; test error flag
9: clr r24 ; not set
IF_ERROR ; if error flag
inc r24 ; set
ret
; ----------------------------------------------------------------------------
; Set user flag
; ----------------------------------------------------------------------------
; INPUT: R24 = index of user flag (0..15)
; DESTROYS: -
; ----------------------------------------------------------------------------
; 7=error on Op18/19, 8=stop on error, 9=print log, 15=error
.global UserFlagSet
UserFlagSet:
; error flag
cpi r24,15
breq 9f
push r24
push r25
ldi r25,1 ; bit mask
cpi r24,8
brcs 4f ; flag < 8
; flag 8..15
subi r24,8
rjmp 2f
1: lsl r25
2: dec r24
brpl 1b
ldd r24,Y+DATA_USERFLAGS+1
or r24,r25
std Y+DATA_USERFLAGS+1,r24
rjmp 8f
; flag 0..7
3: lsl r25
4: dec r24
brpl 3b
ldd r24,Y+DATA_USERFLAGS
or r24,r25
std Y+DATA_USERFLAGS,r24
8: pop r25
pop r24
ret
; set error flag
9: SET_ERROR ; set error flag
ret
; ----------------------------------------------------------------------------
; Clear user flag
; ----------------------------------------------------------------------------
; INPUT: R24 = index of user flag (0..15)
; DESTROYS: -
; ----------------------------------------------------------------------------
; 7=error on Op18/19, 8=stop on error, 9=print log, 15=error
.global UserFlagClr
UserFlagClr:
; error flag
cpi r24,15
breq 9f
push r24
push r25
ldi r25,1 ; bit mask
cpi r24,8
brcs 4f ; flag < 8
; flag 8..15
subi r24,8
rjmp 2f
1: lsl r25
2: dec r24
brpl 1b
ldd r24,Y+DATA_USERFLAGS+1
or r24,r25
eor r24,r25
std Y+DATA_USERFLAGS+1,r24
rjmp 8f
; flag 0..7
3: lsl r25
4: dec r24
brpl 3b
ldd r24,Y+DATA_USERFLAGS
or r24,r25
eor r24,r25
std Y+DATA_USERFLAGS,r24
8: pop r25
pop r24
ret
; clear error flag
9: CLR_ERROR ; clear error flag
ret