forked from A2osX/A2osX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathX.PRINTF.S.txt
227 lines (187 loc) · 3.8 KB
/
X.PRINTF.S.txt
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
NEW
PREFIX /A2OSX.BUILD
AUTO 4,1
.LIST OFF
*--------------------------------------
PrintFAX sta PrintFAX.Next+1
stx PrintFAX.Next+2
pla
sta PrintFAX.99+1
pla
sta PrintFAX.98+1
lda $C011 RDLCBNK2
sta PrintFAX.91+1
lda $C012 RDLCRAM
sta PrintFAX.90+1
lda $C08A RROMBNK1, make sure $D000-$FFFF ROM selected
lda $CFFF get access to $C800-$CFFF internal ROM
PrintFAX.1 stz X.b0Flag
stz X.DigitCount
jsr PrintFAX.Next
beq PrintFAX.90
cmp #'%'
bne .7
.2 jsr PrintFAX.Next
beq PrintFAX.90
cmp #'0'
bne .3
ror X.b0Flag beq -> CS
bra .2
.3 bcc .4
cmp #'9'+1
bcs .4
and #$0f
sta X.DigitCount
bra .2
.4 ldx #PrintFAX.Tbl-PrintFAX.Esc-1
.5 cmp PrintFAX.Esc,x
beq .6
dex
bpl .5
bra PrintFAX.1
.6 txa
asl
tax
jmp (PrintFAX.Tbl,x)
.7 cmp #'\'
bne .8
jsr PrintFAX.Next
beq PrintFAX.90
cmp #'n'
bne .8
lda #$0D
.8 ora #$80
jsr $FDED COUT
bra PrintFAX.1
PrintFAX.90 lda #$ff
bpl PrintFAX.98 ROM was selected, nothing to do
PrintFAX.91 lda #$ff
bmi PrintFAX.92 RAM bank 2 was selected
ldx #$8B RRAMWRAMBNK1
.HS 2C bit abs
PrintFAX.92 ldx #$83 RRAMWRAMBNK2
lda $C000,x
lda $C000,x
PrintFAX.98 lda #$ff Self modified RTS HI
pha
PrintFAX.99 lda #$ff Self modified RTS LOPrintFAXPrintFAX
pha
rts
*--------------------------------------
PrintFAX.Next lda $ffff
beq .8
inc PrintFAX.Next+1
bne .8
inc PrintFAX.Next+2 Always !=0
.8 rts
*--------------------------------------
PrintFAX.Esc .AS "dDhHS"
PrintFAX.Tbl .DA PrintFAX.D
.DA PrintFAX.DD
.DA PrintFAX.H
.DA PrintFAX.HH
.DA PrintFAX.S
*--------------------------------------
PrintFAX.D ldx #0
.HS D0 bne
PrintFAX.DD plx
pla
sta X.HexBuffer
stx X.HexBuffer+1
stz X.BCDBuffer
stz X.BCDBuffer+1
stz X.BCDBuffer+2
ldx #16 let's roll 16 bits
sed
.2 asl X.HexBuffer
rol X.HexBuffer+1
php cpy will disturb carry while BCD adc
ldy #0
.3 plp
lda X.BCDBuffer,y
adc X.BCDBuffer,y
sta X.BCDBuffer,y
php
iny
cpy #3 Last byte of X.BCDBufferBUF?
bne .3
plp
dex
bne .2
cld
ldx #0
ldy #5
.4 lda X.BCDBuffer,x
pha
and #$0F
ora #$B0
sta X.DigitBuffer,y
dey
pla
lsr
lsr
lsr
lsr
ora #$B0
sta X.DigitBuffer,y
inx
dey
bpl .4
lda X.DigitCount
beq .5
lda #6
sec
sbc X.DigitCount
.5 tay
.6 lda X.DigitBuffer,y
cmp #"0"
beq .7
sec
ror X.b0Flag
bra .8
.7 cpy #5
beq .8
lda #" "
bit X.b0Flag
bpl .81
lda #"0"
.8 phy
jsr $FDED COUT
ply
.81 iny
cpy #6
bne .6
.9 jmp PrintFAX.1
*--------------------------------------
PrintFAX.HH pla
jsr $FDDA PRBYTE
PrintFAX.H pla
jsr $FDDA PRBYTE
jmp PrintFAX.1
*--------------------------------------
PrintFAX.S pla
sta .1+2
sta .2+2
pla
sta .1+1
sta .2+1
.1 lda $ffff
beq .9
tax
ldy #1
.2 lda $ffff,y
ora #$80
jsr $FDED COUT
iny
dex
bne .2
.9 jmp PrintFAX.1
*--------------------------------------
X.HexBuffer .BS 2
X.BCDBuffer .BS 3
X.b0Flag .BS 1
X.DigitCount .BS 1
X.DigitBuffer .BS 6
*--------------------------------------
MAN
SAVE /A2OSX.SRC/X.PRINTF.S