]> git.sur5r.net Git - cc65/blob - libsrc/osic1p/cputc.s
More room by default for zero-page data.
[cc65] / libsrc / osic1p / cputc.s
1 ;
2 ; cputc/cputcxy for Challenger 1P
3 ; Based on PET/CBM implementation
4 ;
5 ; void cputcxy (unsigned char x, unsigned char y, char c);
6 ; void cputc (char c);
7 ;
8         .export         _cputcxy, _cputc, cputdirect, putchar
9         .export         newline, plot
10         .import         popa, _gotoxy
11
12         .include        "osic1p.inc"
13         .include        "extzp.inc"
14
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
18
19 _cputcxy:
20         pha                     ; Save C
21         jsr     popa            ; Get Y
22         jsr     _gotoxy         ; Set cursor, drop x
23         pla                     ; Restore C
24
25 ; Plot a character - also used as internal function
26
27 _cputc: cmp     #$0A            ; CR?
28         bne     L1
29         lda     #0
30         sta     CURS_X
31         beq     plot            ; Recalculate pointers
32
33 L1:     cmp     #$0D            ; LF?
34         beq     newline         ; Recalculate pointers
35
36 cputdirect:
37         jsr     putchar         ; Write the character to the screen
38
39 ; Advance cursor position
40
41 advance:
42         cpy     #(SCR_WIDTH - 1)
43         bne     L3
44         jsr     newline         ; New line
45         ldy     #$FF            ; + cr
46 L3:     iny
47         sty     CURS_X
48         rts
49
50 newline:
51         inc     CURS_Y
52         lda     CURS_Y
53         cmp     #SCR_HEIGHT     ; Screen height
54         bne     plot
55         dec     CURS_Y          ; Bottom of screen reached, scroll
56         ldx     #0
57 scroll:
58 .repeat 3, I                    ; Scroll screen in three blocks of size
59                                 ; BLOCKSIZE
60         lda     SCRNBASE+(I*BLOCKSIZE)+FIRSTVISC+LINEDIST,x
61         sta     SCRNBASE+(I*BLOCKSIZE)+FIRSTVISC,x
62 .endrepeat
63         inx
64         bne scroll
65
66         lda     #' '            ; Clear bottom line of screen
67 bottom:
68         sta     SCRNBASE+(3*BLOCKSIZE)+FIRSTVISC,x
69         inx
70         cpx     #SCR_WIDTH
71         bne     bottom
72
73 plot:   ldy     CURS_Y
74         lda     ScrLo,y
75         sta     SCREEN_PTR
76         lda     ScrHi,y
77         sta     SCREEN_PTR+1
78         rts
79
80 ; Write one character to the screen without doing anything else, return X
81 ; position in Y
82
83 putchar:
84         ldy     CURS_X
85         sta     (SCREEN_PTR),y  ; Set char
86         rts
87
88 ; Screen address tables - offset to real screen
89
90 .rodata
91
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
95         .byte   $85
96
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
100         .byte   $D3