2 ; cputc/cputcxy for Challenger 1P
3 ; Based on PET/CBM implementation
5 ; void cputcxy (unsigned char x, unsigned char y, char c);
8 .export _cputcxy, _cputc, cputdirect, putchar
15 FIRSTVISC = $85 ; Offset of first visible character in video RAM
16 LINEDIST = $20 ; Offset in video RAM between two lines
17 BLOCKSIZE = $100 ; Size of block to scroll
22 jsr _gotoxy ; Set cursor, drop x
25 ; Plot a character - also used as internal function
27 _cputc: cmp #$0A ; CR?
31 beq plot ; Recalculate pointers
34 beq newline ; Recalculate pointers
37 jsr putchar ; Write the character to the screen
39 ; Advance cursor position
44 jsr newline ; New line
53 cmp #SCR_HEIGHT ; Screen height
55 dec CURS_Y ; Bottom of screen reached, scroll
58 .repeat 3, I ; Scroll screen in three blocks of size
60 lda SCRNBASE+(I*BLOCKSIZE)+FIRSTVISC+LINEDIST,x
61 sta SCRNBASE+(I*BLOCKSIZE)+FIRSTVISC,x
66 lda #' ' ; Clear bottom line of screen
68 sta SCRNBASE+(3*BLOCKSIZE)+FIRSTVISC,x
80 ; Write one character to the screen without doing anything else, return X
85 sta (SCREEN_PTR),y ; Set char
88 ; Screen address tables - offset to real screen
92 ScrLo: .byte $85, $A5, $C5, $E5, $05, $25, $45, $65
93 .byte $85, $A5, $C5, $E5, $05, $25, $45, $65
94 .byte $85, $A5, $C5, $E5, $05, $25, $45, $65
97 ScrHi: .byte $D0, $D0, $D0, $D0, $D1, $D1, $D1, $D1
98 .byte $D1, $D1, $D1, $D1, $D2, $D2, $D2, $D2
99 .byte $D2, $D2, $D2, $D2, $D3, $D3, $D3, $D3