-
Notifications
You must be signed in to change notification settings - Fork 85
/
format
339 lines (339 loc) · 5.42 KB
/
format
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
.PAG 'FORMAT'
;
;*THIS MODULE FORMATS THE DATA
; ACCORDING TO THE FLAGS SET BY
; THE INTERP MODULE
;
FMTNUM LDA OPT ;GET OPTIONS BYTE
ROR A ;PRINT LEADING SIGN?
BCC FN20 ;IF CC, NO
;
;*FOUND LEADING SIGN FIELD
;
LDA #'+
LDX SGN
BPL FN10
LDA #'-
FN10 JSR INSERT
;
;*NOW CHECK FOR OVERFLOW IN FIELD
;
FN20 BIT SGN ;EXPONENT NEG?
BVS FN70 ;IF VS, YES. CAN'T OVERFLOW
LDA LW ;IS EXP>LW?
CMP EXP
BCS FN70 ;IF CS, NO. NUMBER FITS INTO FIELD
;
;*PROCESS THE OVERFLOW BY FILLING
; THE FIELD WITH *'S
;
;*PRINT THE DOLLAR SIGN IF PRESENT
;
FN23 LDA OPT
AND #PRTDOL
BNE LOOP
LDA OPT
AND #$10
BEQ FN25
LDA #'\
JSR INSERT
JMP FN25
;
;*FOUND A DOLLAR SIGN FIELD
;
LOOP LDA #'$
JSR INSERT
;
;*FILL THE LHS IF PRESENT
;
FN25 DEC LW ;ANY POSN LEFT TO FILL ON LHS?
BMI FN30 ;IF MI, NO.
LDA #'* ;YES
JSR INSERT
BCC FN25
;
;*PUT IN THE DECIMAL IF PRESENT
;
FN30 BIT OPT ;DECIMAL PT?
BVC FN40 ;IF VC, NO
;
;*FOUND A DECIMAL POINT FIELD
;
LDA #'. ;INSERT THE DECIMAL PT
JSR INSERT
;
;*NOW FILL THE RHS IF PRESENT
;
FN35 DEC RW ;ANY POSNS LEFT TO FILL ON RHS?
BMI FN40 ;IF MI, NO.
LDA #'* ;FILL POSN W/*
JSR INSERT
BCC FN35
;
FN40 BIT OPT ;TRAILING SIGN FIELD?
BPL FN60 ;IF PL, NO. DONE PROCESSING OVERFLOW
;
;*FOUND A TRAILING SIGN FIELD.
;
LDA #BLANK ;ASSUME POSITIVE #
BIT SGN ;# POSITIVE?
BPL FN45 ;IF PL, YES
LDA #'- ;NEG #
FN45 JSR INSERT
;
;*END OF OVERFLOW PROCESSING.
;
FN60 JMP FN280
;
;*NO OVERFLOW. IS THERE A DOLLAR FIELD?
;
FN70 LDA OPT
AND #PRTDOL
BNE FN100
LDA OPT
AND #PRTYEN
BEQ FN73
LDA OPT
AND #PRTFYN
BNE FN73
LDA #'\
JSR INSERT
JMP FN73
;
;*FOUND A DOLLAR SIGN FIELD.
; IS IT REALLY FLOATING DOLLARS?
;
FN100 LDA OPT
AND #PRTFDL
BNE FN73
;
;*FOUND A FIXED DOLLAR SIGN FIELD.
; PRINT IT.
LDA #'$
JSR INSERT
;
;*ALGOL EQUIVALENT FOR THE FOLLOWING CODE:
; WRKBYT:=IF EXPSGN<0 THEN LW ELSE LW-EXP;
; IF EXP=0 AND RW=0 THEN WRKBYT:=WRKBYT-1;
; (LAST STMNT ALLOWS ROOM FOR A 0 IF ZERO WAS SENT BY THE PET)
FN73 LDA LW ;WRKBYT:=IF EXPSGN<0 THEN LW ELSE LW-EXP;
;
BIT SGN
BVS FN75
SEC
SBC EXP
FN75 STA WRKBYT
LDA EXP ;IF EXP=0 AND RW=0 THEN WRKBYT:=WRKBYT-1;
BNE FN78
LDA RW
BNE FN78
DEC WRKBYT
;
;*ALGOL EQUIVALENT BELOW:
; WHILE (WRKBYT:=WRKBYT-1)>0
; DO CALL INSERT( IF PRTLZ&OPT=0 THEN ' ' ELSE '0' );
;
FN78 DEC WRKBYT ;WHILE (WRKBYT:=WRKBYT-1)>0;
BMI FN85
LDY #BLANK ;IF PRTLZ&OPT=0 THEN ' ' ELSE '0';
LDA OPT
AND #PRTLZ
BEQ FN80
LDY #'0
FN80 TYA
JSR INSERT
BCC FN78 ;BR ALWAYS
;
;*ALGOL:
; IF PRTFDL&OPT<>0 THEN CALL INSERT('$');
;
FN85 LDA OPT
AND #PRTFDL
BNE FN103
LDA OPT
AND #PRTFYN
BEQ FN90
LDA #'\
JSR INSERT
JMP FN90
FN103 LDA #'$
JSR INSERT
;
;*ALGOL:
; IF EXP=0 AND LW=0 THEN CALL INSERT('0');
;
FN90 LDA EXP
BNE FN95
LDA RW
BNE FN95
LDA #'0
JSR INSERT
FN95
FN140 BIT SGN ;EXPONENT NEG?
BVS FN170 ;IF VE, YES
LDX #0
STX WRKBYT
FN150 LDX WRKBYT
CPX EXP
BEQ FN170
LDA FACC,X
CPX #9
BCC FN160
LDA #'0
FN160 JSR INSERT
INC WRKBYT
BNE FN150
FN170 BIT OPT ;PRINT DECIMAL PT?
BVC FN260 ;IF VC, NO
LDA #'.
JSR INSERT
LDA RW
BEQ FN260
BIT SGN ;EXPONENT NEG?
BVS FN220 ;IF VS, YES
LDX EXP
CPX #9
BCC FN200
FN190 DEC RW
BMI FN260
JSR INSZER
BCC FN190
FN200 LDA RW
CLC
ADC EXP
STA RW
FN210 LDX EXP
CPX RW
BCS FN260
LDA FACC,X
CPX #9
BCC *+4
LDA #'0
JSR INSERT
INC EXP
BNE FN210
FN220 LDX EXP
CPX RW
BCC *+4
LDX RW
STX WRKBYT
LDA RW
SEC
SBC WRKBYT
STA RW
FN230 DEC WRKBYT
BMI FN240
JSR INSZER
BCC FN230
FN240 LDX #1
STX WRKBYT
FN250 LDX WRKBYT
CPX RW
BEQ FN255
BCS FN260
FN255 LDA FACC-1,X
JSR INSERT
INC WRKBYT
BNE FN250
FN260 BIT OPT ;PRINT TRAILING SIGN?
BPL FN280 ;IF PL, NO
;
;*FOUND TRAILING SIGN FIELD
;
LDA #BLANK
LDX SGN
BPL FN270
LDA #'-
FN270 JSR INSERT
FN280 JMP FMT10
.SKI 5
;
;*SKPNUM-SKIP NUMERIC FIELD.
; THIS ROUTINE REPLACES EACH
; OUTPUT POSITION SET UP BY
; THE INTERP MODULE WITH
; BLANKS.
;
;*FILL LHS W/BLANKS IF PRESENT.
;
SKPNUM LDA LW ;REPLACE LHS W/BLANKS
BEQ SKPNU4 ;IF ZERO, NO POSNS TO REPLACE ON LHS
SKPNU2 LDA #BLANK
JSR INSERT
DEC LW ;DONE?
BNE SKPNU2 ;IF NE, NO
;
;*NOW FILL RHS.
;
SKPNU4 LDA RW
BEQ SKPNU6
SKPNU5 LDA #BLANK
JSR INSERT
DEC RW ;DONE?
BNE SKPNU5
;
;*NOW FILL OTHER FIELDS
;
SKPNU6 LDX #8 ;SET UP BIT CTR
STX LW ;USE LW AS TEMP CTR
LDA #PRTLS+PRTDOL+PRTDP+PRTTS
AND OPT ;THESE FIELDS GENERATE ONE CHAR EACH
STA OPT
SKPNU7 LSR OPT ;THIS OPT BIT SET?
BCC SKPNU8 ;IF NOT , DON'T INSERT BLANK
LDA #BLANK
JSR INSERT
SKPNU8 DEC LW
BNE SKPNU7
JSR IEEE ;NOW DUMP SKIP CHAR
BVS ALP20 ;AND HOPE THE SA DIDN'T CHANGE ON US
JMP FMT10 ;THRU PROCESSING SKIP
.SKI 5
;
;*PROCESS ALPHA FIELD.
;
;
;*ELIMINATE LEADING BLANKS
;
ALPHA JSR TERML
BCS ALP80 ;LEAVE IF CS(TERMINAL)
CMP #SKIP
BEQ ALP50 ;GO BLANK FILL
CMP #$20 ;LEADING BLANK
BNE ALP30 ;IF NE, NO. GO USE CHAR
JSR IEEE ;IGNORE BLANK
BVC ALPHA ;IF NO SA CHANGE, LOOP
JMP FINI20 ;ERROR
;
;*LEFT JUSTIFY DATA
;
ALP10 JSR IEEE
ALP20 BVS ALP85 ;IF VS, MISSING TERMINATOR ERROR
JSR TERML ;ABORT FORMATTER?
BCS ALP80 ;IF CS, YES
CMP #SKIP ;SKIP OUT OF ALPHA?
BEQ ALP50 ;IF EQ, YES
ALP30 LDX LW ;FIELD FULL?
BEQ ALP10 ;IF EQ, YES
JSR INSERT ;NO, SO INSERT CHAR
LDA DATA ;PRINTABLE CHAR?
AND #$7F
CMP #$20
BCC ALP10 ;IF CC, NO. DON'T CNT
DEC LW ;YES, ONE LESS CHAR POSN LEFT
BCS ALP10 ;BR ALWAYS
;
;*PAD RIGHT WITH BLANKS
;
ALP50 LDX LW ;FIELD ALREADY FULL?
BEQ ALP70 ;IF EQ, YES
ALP55 LDA #BLANK ;NO, SO BLANK FILL
JSR INSERT
DEC LW ;DONE?
BNE ALP55
ALP70 JSR IEEE
BVS ALP85 ;IF VS, ERROR
JMP FMT10
ALP80 JMP FINI20 ;ABORT FORMATTER
ALP85 JMP FINI90 ;MISSING TERMINATOR ERROR
.END