forked from dwsJason/f256_pexec
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathterm.s
More file actions
430 lines (378 loc) · 7.35 KB
/
term.s
File metadata and controls
430 lines (378 loc) · 7.35 KB
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
;
; Terminal Module for Jr
;
TextBuffer = $C000
; Terminal Variables
.virtual $C0
term_width .fill 1
term_height .fill 1
term_x .fill 1
term_y .fill 1
term_ptr .fill 2
term_temp0 .fill 4
term_temp1 .fill 4
term_temp2 .fill 2
.endv
;TermCOUT - COUT, prints character in A, right now only special character code #13 is supported <cr>
;TermPUTS - AX is a pointer to a 0 terminated string, this function will send the characters into COUT
;TermPrintAN - print nybble value in A
;TermPrintAH - print value in A, as HEX
;TermPrintAI - print value in A, as DEC
;TermPrintAXH - print value in AX, as HEX (it will end up XA, because high, then low)
;TermPrintAXI - print value in AX, as DEC
;TermPrintAXYH - print values in AXY, as HEX
;TermSetXY - cursor position X in X, Y in Y
;------------------------------------------------------------------------------
TermInit
jsr TermClearTextBuffer
stz term_x
stz term_y
lda #80
sta term_width
lda #60
sta term_height
lda #<TextBuffer
sta term_ptr
lda #>TextBuffer
sta term_ptr+1
rts
;------------------------------------------------------------------------------
; ldx #XX
; ldy #YY
TermSetXY
stx term_x
sty term_y
txa
clc
adc Term80Table_lo,y
sta term_ptr
lda #0
adc Term80Table_hi,y
sta term_ptr+1
rts
;------------------------------------------------------------------------------
TermCR lda #13
;------------------------------------------------------------------------------
TermCOUT
cmp #13
beq _cr
sta (term_ptr)
inc term_ptr
bne _skiphi
inc term_ptr+1
_skiphi
lda term_x
inc a
cmp term_width
bcc _x
_incy
lda term_y
inc a
cmp term_height
bcs _scroll_savexy
_y sta term_y
lda #0
_x sta term_x
rts
_cr
phy
phx
lda term_y
inc a
cmp term_height
bcs _scroll
tay
ldx #0
jsr TermSetXY
plx
ply
rts
_scroll_savexy
phy
phx
_scroll
_pSrc = term_temp0
_pDst = term_temp0+2
stz _pDst
lda #80
sta _pSrc
lda #>TextBuffer
sta _pDst+1
sta _pSrc+1
ldx term_height
dex
_lp
ldy #0
_inlp
lda (_pSrc),y
sta (_pDst),y
iny
cpy term_width
bcc _inlp
clc
lda _pSrc
sta _pDst
adc term_width
sta _pSrc
lda _pSrc+1
sta _pDst+1
adc #0
sta _pSrc+1
dex
bne _lp
; clear line
ldy #0
lda #' '
_lclrp sta (_pDst),y
iny
cpy term_width
bcc _lclrp
ldx #0
ldy term_height
dey
jsr TermSetXY
plx
ply
rts
;------------------------------------------------------------------------------
; Fill Text Buffer with spaces
TermClearTextBuffer
stz io_ctrl
stz $D010 ; disable cursor
lda #3
sta io_ctrl ; swap in the color memory
;lda $C000 ; get current color attribute
lda #$F2 ; white on blue
jsr _clear
; We need a rainbow up top
ldx #79
_cloop lda #$12 ; red
sta $C000+80*1,x
sta $C000+80*51,x
lda #$92 ; orange
sta $C000+80*2,x
sta $C000+80*52,x
lda #$D2 ; yello
sta $C000+80*3,x
sta $C000+80*53,x
lda #$C2 ; green
sta $C000+80*4,x
sta $C000+80*54,x
lda #$72 ; bright blue
sta $C000+80*5,x
sta $C000+80*55,x
lda #$32 ; purple
sta $C000+80*6,x
sta $C000+80*56,x
lda #$B2 ; pink
sta $C000+80*7,x
sta $C000+80*57,x
lda #$A2 ; grey
sta $C000+80*8,x
sta $C000+80*58,x
dex
bpl _cloop
lda #2
sta io_ctrl ; swap in the text memory
lda #' '
_clear
ldx #0
_lp
sta $C000,x
sta $C100,x
sta $C200,x
sta $C300,x
sta $C400,x
sta $C500,x
sta $C600,x
sta $C700,x
sta $C800,x
sta $C900,x
sta $CA00,x
sta $CB00,x
sta $CC00,x
sta $CD00,x
sta $CE00,x
sta $CF00,x
sta $D000,x
sta $D100,x
sta $D200,x
dex
bne _lp
rts
;------------------------------------------------------------------------------
Term80Table_lo
.for _n := 0, _n < 60, _n += 1
.byte <(TextBuffer + _n * 80)
.next
Term80Table_hi
.for _n := 0, _n < 60, _n += 1
.byte >(TextBuffer + _n * 80)
.next
;------------------------------------------------------------------------------
TermPUTS
_pString = term_temp2
sta _pString
stx _pString+1
_lp lda (_pString)
beq _done
jsr TermCOUT
inc _pString
bne _lp
inc _pString+1
bra _lp
_done
rts
;------------------------------------------------------------------------------
;TermPrintAXH - print value in AX, as HEX (it will end up XA, because high, then low)
TermPrintAXYH
pha
phx
tya
jsr TermPrintAH
pla
jsr TermPrintAH
pla
; bra TermPrintAH
;------------------------------------------------------------------------------
;TermPrintAH - print value in A, as HEX
TermPrintAH
pha
lsr
lsr
lsr
lsr
tax
lda Term_chars,x
jsr TermCOUT
pla
and #$0F
tax
lda Term_chars,x
jmp TermCOUT
Term_chars .text "0123456789ABCDEF"
;TermPrintAN - print nybble value in A
TermPrintAN
and #$0F
tax
lda Term_chars,x
jmp TermCOUT
;------------------------------------------------------------------------------
;TermPrintAXH - print value in AX, as HEX (it will end up XA, because high, then low)
TermPrintAXH
pha
txa
jsr TermPrintAH
pla
bra TermPrintAH
;------------------------------------------------------------------------------
;TermPrintAI - print value in A, as DEC
TermPrintAI
_bcd = term_temp1
jsr BINBCD8
lda _bcd+1
and #$0F
beq _skip
jsr TermPrintAN
lda _bcd
bra TermPrintAH
_skip
lda _bcd
and #$F0
beq _single_digit
lda _bcd
bra TermPrintAH
_single_digit
lda _bcd
bra TermPrintAN
rts
;------------------------------------------------------------------------------
;TermPrintAXI - print value in AX, as DEC
TermPrintAXI
_bcd = term_temp1
jsr BINBCD16
lda _bcd+2
and #$0F
beq _skip1
; 5 digits
jsr TermPrintAN
_digit4
lda _bcd
ldx _bcd+1
bra TermPrintAXH
_skip1
lda _bcd+1
beq _skip2
and #$F0
bne _digit4
lda _bcd+1
jsr TermPrintAN ; just the nybble
lda _bcd
bra TermPrintAH
_skip2
lda _bcd
and #$F0
beq _single_digit
lda _bcd
jmp TermPrintAH
_single_digit
lda _bcd
bra TermPrintAN
rts
;------------------------------------------------------------------------------
; Andrew Jacobs, 28-Feb-2004
BINBCD8
_bin = term_temp0
_bcd = term_temp1
sta _bin
sed ; Switch to decimal mode
stz _bcd+0
stz _bcd+1
ldx #8 ; The number of source bits
_CNVBIT asl _bin ; Shift out one bit
lda _bcd+0 ; And add into result
adc _bcd+0
sta _bcd+0
lda _bcd+1 ; propagating any carry
adc _bcd+1
sta _bcd+1
dex ; And repeat for next bit
bne _CNVBIT
cld ; Back to binary
rts
; Convert an 16 bit binary value to BCD
;
; This function converts a 16 bit binary value into a 24 bit BCD. It
; works by transferring one bit a time from the source and adding it
; into a BCD value that is being doubled on each iteration. As all the
; arithmetic is being done in BCD the result is a binary to decimal
; conversion. All conversions take 915 clock cycles.
;
; See BINBCD8 for more details of its operation.
;
; Andrew Jacobs, 28-Feb-2004
BINBCD16
_bin = term_temp0
_bcd = term_temp1
sta _bin
stx _bin+1
sed ; Switch to decimal mode
stz _bcd+0
stz _bcd+1
stz _bcd+2
ldx #16 ; The number of source bits
_CNVBIT asl _bin+0 ; Shift out one bit
rol _bin+1
lda _bcd+0 ; And add into result
adc _bcd+0
sta _bcd+0
lda _bcd+1 ; propagating any carry
adc _bcd+1
sta _bcd+1
lda _bcd+2 ; ... thru whole result
adc _bcd+2
sta _bcd+2
dex ; And repeat for next bit
bne _CNVBIT
cld ; Back to binary
rts