-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsoft80_cputc.s
700 lines (619 loc) · 17.1 KB
/
soft80_cputc.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
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
//
// Groepaz/Hitmen, 11.10.2015
//
// high level implementation for the soft80 implementation
//
// void cputcxy (unsigned char x, unsigned char y, char c)//
// void cputc (char c)//
//
// .import gotoxy
#import "soft80.inc"
// x, y coordinate scalars
.macro soft80_putcxy_(x, y)
{
soft80_pos_(x, y)
jsr soft80_cputc
}
// x,y coordinate addr
.macro soft80_putcxy(x, y)
{
soft80_pos(x, y)
jsr soft80_cputc
}
// x, y coordinate scalars
.macro soft80_pos_(x, y)
{
pha
ldy #x
tya
and #%00000001
beq !+
dey // align X-coord
!: ldx #y
clc
jsr soft80_kplot // set with aligned X
lda #x
and #%00000001
beq !+
jsr adv_cur // not aligned X, so advance by 1
!: pla
}
// x, y coordinate addr
.macro soft80_pos(x, y)
{
pha
ldy x
tya
and #%00000001
beq !+
dey // align X-coord
!: ldx y
clc
jsr soft80_kplot // set with aligned X
lda x
and #%00000001
beq !+
jsr adv_cur // not aligned X, so advance by 1
!: pla
}
.macro soft80_delc()
{
pha
sec
jsr soft80_kplot // get x, y
dey // dec X-coordinate
sty P.zpp1
stx P.zpp2
soft80_pos(P.zpp1, P.zpp2)
lda #' '
jsr soft80_putchar // without advancing cursor
pla
}
.macro soft80_wstring(x, y, addr)
{
soft80_pos_(x, y)
ldy #$00
!loop: lda addr, y
beq !+
jsr soft80_cputc
iny
jmp !loop-
!:
}
soft80_crlf:
lda #$0d
jsr soft80_cputc
lda #$0a
jsr soft80_cputc
rts
gotoxy:
// not used
rts
soft80_cputcxy: // qeird X-> y-reg, Y -> x-reg
clc
jsr soft80_kplot
// Plot a character - also used as internal function
soft80_cputc:
cmp #$0A // CR?
bne !L1+
lda #0
sta CURS_X
// Set cursor position, calculate RAM pointers
soft80_plot:
ldx CURS_Y
ldy CURS_X
clc
jmp soft80_kplot // Set the new cursor
!L1: cmp #$0D // LF?
beq soft80_newline // Recalculate pointers
// shortcut for codes < $80 ... codes $20-$7f can be printed directly,
// codes $00-$1f are control codes which are not printable and thus may
// give undefined result.
tay
bpl !L10+
// codes $80-$ff must get converted like this:
// $80-$9f -> dont care (control codes)
// $a0-$bf -> $00-$1f
// $c0-$df -> $60-$7f
// $e0-$ff -> $00-$1f
ora #%01000000 // $40
clc
adc #%00100000 // $20
and #%01111111 // $7f
!L10:
// entry point for direct output of a character. the value passed in
// akku must match the offset in the charset.
// - the following may not modify tmp1
soft80_cputdirect:
jsr soft80_putchar // Write the character to the screen
// Advance cursor position
adv_cur:
iny // contains CURS_X
cpy #charsperline
beq !L3+
sty CURS_X
tya
and #$01
sta soft80_internal_cursorxlsb
bne !L5+
lda SCREEN_PTR
clc
adc #8
sta SCREEN_PTR
bcc !L4+
inc SCREEN_PTR+1
!L4:
inc CRAM_PTR
bne !L5+
inc CRAM_PTR+1
!L5:
rts
!L3:
inc CURS_Y // new line
ldy #0 // + cr
sty CURS_X
jmp soft80_plot
// - the following may not modify tmp1
soft80_newline:
lda SCREEN_PTR
clc
adc #<(40*8)
sta SCREEN_PTR
lda SCREEN_PTR+1
adc #>(40*8)
sta SCREEN_PTR+1
lda CRAM_PTR
clc
adc #40
sta CRAM_PTR
bcc !L5+
inc CRAM_PTR+1
!L5:
inc CURS_Y
rts
//-------------------------------------------------------------------------------
// All following code belongs to the character output to bitmap
//
// this stuff is going to be used a lot so we unroll it a bit for speed
//-------------------------------------------------------------------------------
#if SOFT80FASTSPACE
// output inverted space (odd)
draw_spaceinvers_odd:
/*
.repeat 8,line
lda (SCREEN_PTR),y
and #$f0
sta (SCREEN_PTR),y
.if line < 7
iny
.endif
.endrepeat
*/
.for (var line = 0; line < 8; line++) {
lda (SCREEN_PTR),y
and #$f0
sta (SCREEN_PTR),y
.if (line < 7) {
iny
}
}
jmp draw_back
// output inverted space (general entry point)
// in: y must be $00
draw_spaceinvers:
#if SOFT80COLORVOODOO
jsr soft80_putcolor
#else
lda soft80_internal_cellcolor
sta (CRAM_PTR),y // vram
#endif
lda soft80_internal_cursorxlsb
bne draw_spaceinvers_odd
// output inverted space (even)
/* .repeat 8,line
lda (SCREEN_PTR),y
and #$0f
sta (SCREEN_PTR),y
.if line < 7
iny
.endif
.endrepeat
*/
.for (var line = 0; line < 8; line++) {
lda (SCREEN_PTR),y
and #$0f
sta (SCREEN_PTR),y
.if (line < 7) {
iny
}
}
jmp draw_back
// output space (odd)
draw_space_odd:
/*
.repeat 8,line
lda (SCREEN_PTR),y
ora #$0f
sta (SCREEN_PTR),y
.if line < 7
iny
.endif
.endrepeat
*/
.for (var line = 0; line < 8; line++) {
lda (SCREEN_PTR),y
ora #$0f
sta (SCREEN_PTR),y
.if (line < 7) {
iny
}
}
jmp draw_back
// output space (general entry point)
// in: y must be $00
draw_space:
lda RVS
beq !+
jmp draw_spaceinvers
!:
#if SOFT80COLORVOODOO
jsr remcolor
#endif
//ldy #$00 // is still $00
lda soft80_internal_cursorxlsb
bne draw_space_odd
// output space (even)
/* .repeat 8,line
lda (SCREEN_PTR),y
ora #$f0
sta (SCREEN_PTR),y
.if (line < 7)
iny
.endif
.endrepeat
*/
.for (var line = 0; line < 8; line++) {
lda (SCREEN_PTR),y
ora #$f0
sta (SCREEN_PTR),y
.if (line < 7) {
iny
}
}
jmp draw_back
#endif
//-------------------------------------------------------------------------------
// output one character in internal encoding without advancing cursor position
// generic entry point
//
// - the following may not modify tmp1
// in: A: charcode
// out: Y: CURS_X
//
soft80_putchar:
sta soft80.tmp3 // remember charcode
sei
ldx $01
stx soft80.tmp4
ldx #$34
stx $01 // will stay $34 for space
ldy #$00 // will be $00 from now on
#if SOFT80FASTSPACE
cmp #' ' // space is a special (optimized) case
beq draw_space
#endif
#if SOFT80COLORVOODOO
jsr soft80_putcolor
#else
lda soft80_internal_cellcolor
sta (CRAM_PTR),y // vram
#endif
// output character
ldx soft80.tmp3 // get charcode
lda RVS
beq !skp+
jmp draw_charinvers
!skp:
lda soft80_internal_cursorxlsb
bne draw_char_even
// output character (odd)
/* .repeat 8,line
lda (SCREEN_PTR),y
and #$0f
ora soft80_hi_charset+(line*$80),x
sta (SCREEN_PTR),y
.if line < 7
iny
.endif
.endrepeat
*/
.for (var line = 0; line < 8; line++) {
lda (SCREEN_PTR),y
and #$0f
ora soft80_hi_charset+(line*$80),x
sta (SCREEN_PTR),y
.if (line < 7) {
iny
}
}
jmp draw_back
// output character (even)
draw_char_even:
/*
.repeat 8,line
lda (SCREEN_PTR),y
and #$f0
ora soft80_lo_charset+(line*$80),x
sta (SCREEN_PTR),y
.if line < 7
iny
.endif
.endrepeat
*/
.for (var line = 0; line < 8; line++) {
lda (SCREEN_PTR),y
and #$f0
ora soft80_lo_charset+(line*$80),x
sta (SCREEN_PTR),y
.if (line < 7) {
iny
}
}
draw_back:
lda soft80.tmp4
sta $01
cli
ldy CURS_X
rts
// output inverted character (odd)
draw_charinvers_odd:
/* .repeat 8,line
lda (SCREEN_PTR),y
ora #$0f
eor soft80_lo_charset+(line*$80),x
sta (SCREEN_PTR),y
.if line < 7
iny
.endif
.endrepeat
*/
.for (var line = 0; line < 8; line++) {
lda (SCREEN_PTR),y
ora #$0f
eor soft80_lo_charset+(line*$80),x
sta (SCREEN_PTR),y
.if (line < 7) {
iny
}
}
jmp draw_back
// output inverted character (generic)
draw_charinvers:
lda soft80_internal_cursorxlsb
bne draw_charinvers_odd
/*
.repeat 8,line
lda (SCREEN_PTR),y
ora #$f0
eor soft80_hi_charset+(line*$80),x
sta (SCREEN_PTR),y
.if line < 7
iny
.endif
.endrepeat
*/
.for (var line = 0; line < 8; line++) {
lda (SCREEN_PTR),y
ora #$f0
eor soft80_hi_charset+(line*$80),x
sta (SCREEN_PTR),y
.if (line < 7) {
iny
}
}
jmp draw_back
//-------------------------------------------------------------------------------
// optional "color voodoo". the problem is that each 8x8 cell can only contain
// two colors, one of which is used for the background color, so two characters
// have to share the same text color.
//
// - in a cell that contains two spaces, both the color ram and the text color
// in vram contain the background color
//
// - in a cell that contains one character, its text color goes into vram. the
// color ram contains the background color.
//
// - in a cell that contains two characters, the color of the left character goes
// to vram (and is shared by both for display). the "would be" color of the
// right character goes to color ram as a reminder and can be restored when one
// of the two characters is cleared by a space.
#if SOFT80COLORVOODOO
// remove color from cell, called before putting a "space" character to the bitmap
//
// __ -> __ -
// _A -> _A -
// B_ -> B_ -
// _A -> __ vram = bgcol
// B_ -> __ vram = bgcol
// BA -> _A vram = colram, colram = bgcol
// BA -> B_ colram = bgcol
//
// in: x must be $34
// y must be $00
// out: x = $34
// y = $00
remcolor:
//ldy #$00 // is still $00
// if the textcolor in vram is equal to the background color, then
// no (visible) character is in the current cell and we can exit
// immediately.
lda (CRAM_PTR),y // vram (textcolor)
and #$0f
cmp soft80_internal_bgcolor
beq !sk1_+ // yes, vram==bgcolor
// now check if the textcolor in color ram is equal the background color,
// if yes then there is only one (visible) character in the current cell
inc $01 // $35
lda (CRAM_PTR),y // colram (2nd textcolor)
stx $01 // $34
and #$0f
cmp soft80_internal_bgcolor
beq !sk2+ // yes, colram==bgcolor
sta soft80.tmp3 // A contains colram
// two characters in the current cell, of which one will get removed
lda soft80_internal_cursorxlsb
bne !sk3+
// vram = colram
lda (CRAM_PTR),y // vram
and #$f0
ora soft80.tmp3 // colram value
sta (CRAM_PTR),y // vram
!sk3:
// colram = bgcolor
lda soft80_internal_bgcolor
inc $01 // $35
sta (CRAM_PTR),y // colram
stx $01 // $34
rts
!sk2:
// colram is bgcolor
// => only one char in cell used
jsr soft80_checkchar
bcs !sk1+ // space at current position
// vram (textcolor) = bgcolor
lda (CRAM_PTR),y // vram
and #$f0
ora soft80_internal_bgcolor
sta (CRAM_PTR),y // vram
!sk1_:
rts
// put color to cell
//
// __ -> _A vram = textcol
// __ -> B_ vram = textcol
// _A -> BA colram = vram, vram = textcol
// B_ -> BA colram = textcol
//
// _A -> _C vram = textcol
// B_ -> C_ vram = textcol
// BA -> BC colram = textcol
// BA -> CA vram = textcol
//
// in: $01 is $34 (RAM under I/O) when entering
// x must be $34
// y must be $00
// out: x = $34
// y = $00
soft80_putcolor:
//ldy #$00 // is still $00
lda (CRAM_PTR),y // vram
and #$0f
cmp soft80_internal_bgcolor
beq !sk1+ // vram==bgcolor => first char in cell
// vram!=bgcolor => second char in cell
inc $01 // $35
lda (CRAM_PTR),y // colram
stx $01 // $34
and #$0f
cmp soft80_internal_bgcolor
beq !l2s+ // colram==bgcolor -> second char in cell
// botch characters in the cell are used
lda soft80_internal_cursorxlsb
bne !sk2+ // jump if odd xpos
// vram = textcol
lda soft80_internal_cellcolor
sta (CRAM_PTR),y // vram
rts
!l2s:
// one character in cell is already used
jsr soft80_checkchar
bcc !sk1+ // char at current position => overwrite 1st
lda soft80_internal_cursorxlsb
beq !sk3+ // jump if even xpos
!sk2:
// colram = textcol
lda CHARCOLOR
inc $01 // $35
sta (CRAM_PTR),y // colram
stx $01 // $34
rts
!sk3:
// colram=vram
lda (CRAM_PTR),y // vram
inc $01 // $35
sta (CRAM_PTR),y // colram
stx $01 // $34
!sk1:
// vram = textcol
lda soft80_internal_cellcolor
sta (CRAM_PTR),y // vram
rts
#endif // COLORVOODOO
//
// test if there is a space or a character at current position
//
// in: x = $34
// $01 must be $34
//
// out: SEC: space
// CLC: character
// x = $34
// y = $00
soft80_checkchar:
lda soft80_internal_cursorxlsb
bne !l1a+
// check charset data from bottom up, since a lot of eg lowercase chars
// have no data in the top rows, but all of them DO have data in the
// second to bottom row, this will likely be faster in average.
ldy #7
/*
.repeat 8,line
lda (SCREEN_PTR),y
and #$f0
cmp #$f0
bne ischar
.if (line < 7)
dey
.endif
.endrepeat
*/
.for (var line = 0; line < 8; line++) {
lda (SCREEN_PTR),y
and #$f0
cmp #$f0
bne !ischar+
.if (line < 7) {
dey
}
}
//ldy #$00 // is 0
//sec // is set
rts
!ischar:
ldy #$00
//clc // is cleared
rts
!l1a:
ldy #$07
/* .repeat 8,line
lda (SCREEN_PTR),y
and #$0f
cmp #$0f
bne ischar
.if line < 7
dey
.endif
.endrepeat
*/
.for (var line = 0; line < 8; line++) {
lda (SCREEN_PTR),y
and #$0f
cmp #$0f
bne !ischar-
.if (line < 7) {
dey
}
}
//ldy #$00 // is 0
//sec // is set
rts