]> git.sur5r.net Git - cc65/blob - libsrc/cbm510/cputc.s
remove superfluous ".code" line
[cc65] / libsrc / cbm510 / cputc.s
1 ;
2 ; Ullrich von Bassewitz, 14.09.2001
3 ;
4 ; void cputcxy (unsigned char x, unsigned char y, char c);
5 ; void cputc (char c);
6 ;
7
8         .export         _cputcxy, _cputc, cputdirect, putchar
9         .export         newline, plot
10
11         .import         popa, _gotoxy
12         .import         __VIDRAM_START__
13         .import         CURS_X: zp, CURS_Y: zp, CHARCOLOR: zp, RVS: zp
14         .import         SCREEN_PTR: zp, CRAM_PTR: zp
15
16         .include        "cbm510.inc"
17
18         .macpack        generic
19
20 ; ------------------------------------------------------------------------
21 ;
22
23 _cputcxy:
24         pha                     ; Save C
25         jsr     popa            ; Get Y
26         jsr     _gotoxy         ; Set cursor, drop x
27         pla                     ; Restore C
28
29 ; Plot a character - also used as internal function
30
31 _cputc: cmp     #$0A            ; CR?
32         bne     L1
33         lda     #0
34         sta     CURS_X
35         beq     plot            ; Recalculate pointers
36
37 L1:     cmp     #$0D            ; LF?
38         beq     newline         ; Recalculate pointers
39
40 ; Printable char of some sort
41
42         cmp     #' '
43         bcc     cputdirect      ; Other control char
44         tay
45         bmi     L10
46         cmp     #$60
47         bcc     L2
48         and     #$DF
49         bne     cputdirect      ; Branch always
50 L2:     and     #$3F
51
52 cputdirect:
53         jsr     putchar         ; Write the character to the screen
54
55 ; Advance cursor position
56
57 advance:
58         iny
59         cpy     #XSIZE
60         bne     L3
61         jsr     newline         ; new line
62         ldy     #0              ; + cr
63 L3:     sty     CURS_X
64         rts
65
66 ; Handle character if high bit set
67
68 L10:    and     #$7F
69         cmp     #$7E            ; PI?
70         bne     L11
71         lda     #$5E            ; Load screen code for PI
72         bne     cputdirect
73 L11:    ora     #$40
74         bne     cputdirect      ; Branch always
75
76 ; Move the cursor into the next line
77
78 newline:
79         inc     CURS_Y
80
81 ; Set cursor position, calculate RAM pointers
82
83 plot:   ldx     CURS_Y
84         lda     LineLSBTab,x
85         sta     SCREEN_PTR
86         sta     CRAM_PTR
87         lda     LineMSBTab,x
88         sta     SCREEN_PTR+1
89         add     #.hibyte(COLOR_RAM - __VIDRAM_START__)
90         sta     CRAM_PTR+1
91         rts
92
93 ; Write one character to the screen without doing anything else, return X
94 ; position in Y
95
96 putchar:
97         ora     RVS             ; Set revers bit
98         ldy     CURS_X
99         sta     (SCREEN_PTR),y  ; Set char
100         ldx     IndReg
101         lda     #$0F
102         sta     IndReg
103         lda     CHARCOLOR
104         sta     (CRAM_PTR),y    ; Set color
105         stx     IndReg
106         rts
107
108 ; -------------------------------------------------------------------------
109 ; Low bytes of the start address of the screen lines
110
111 .rodata
112
113 LineLSBTab:
114         .repeat 25, I
115         .byte   .lobyte(__VIDRAM_START__ + I * 40)
116         .endrep
117
118 ; -------------------------------------------------------------------------
119 ; High bytes of the start address of the screen lines
120
121 LineMSBTab:
122         .repeat 25, I
123         .byte   .hibyte(__VIDRAM_START__ + I * 40)
124         .endrep