]> git.sur5r.net Git - cc65/blob - libsrc/osic1p/cputc.s
Rename c1p target to osic1p
[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 _cputcxy:
16         pha                     ; Save C
17         jsr     popa            ; Get Y
18         jsr     _gotoxy         ; Set cursor, drop x
19         pla                     ; Restore C
20
21 ; Plot a character - also used as internal function
22
23 _cputc: cmp     #$0A            ; CR?
24         bne     L1
25         lda     #0
26         sta     CURS_X
27         beq     plot            ; Recalculate pointers
28
29 L1:     cmp     #$0D            ; LF?
30         beq     newline         ; Recalculate pointers
31
32 cputdirect:
33         jsr     putchar         ; Write the character to the screen
34
35 ; Advance cursor position
36
37 advance:
38         cpy     SCR_LINELEN     ; xsize-1
39         bne     L3
40         jsr     newline         ; new line
41         ldy     #$FF            ; + cr
42 L3:     iny
43         sty     CURS_X
44         rts
45
46 newline:
47         inc     CURS_Y
48         lda     CURS_Y
49         cmp     #24             ; screen height 25 lines hardcoded
50         bne     plot
51         lda     #0              ; wrap around to line 0
52         sta     CURS_Y
53
54 plot:   ldy     CURS_Y
55         lda     ScrLo,y
56         sta     SCREEN_PTR
57         lda     ScrHi,y
58         sta     SCREEN_PTR+1
59         rts
60
61 ; Write one character to the screen without doing anything else, return X
62 ; position in Y
63
64 putchar:
65         ldy     CURS_X
66         sta     (SCREEN_PTR),y  ; Set char
67         rts
68
69 ; Screen address tables - offset to real screen
70
71 .rodata
72
73 ScrLo:  .byte   $83, $A3, $C3, $E3, $03, $23, $43, $63
74         .byte   $83, $A3, $C3, $E3, $03, $23, $43, $63
75         .byte   $83, $A3, $C3, $E3, $03, $23, $43, $63
76         .byte   $83
77
78 ScrHi:  .byte   $D0, $D0, $D0, $D0, $D1, $D1, $D1, $D1
79         .byte   $D1, $D1, $D1, $D1, $D2, $D2, $D2, $D2
80         .byte   $D2, $D2, $D2, $D2, $D3, $D3, $D3, $D3
81         .byte   $D3