]> git.sur5r.net Git - cc65/blob - libsrc/creativision/cputc.s
Cleanups for Creativision.
[cc65] / libsrc / creativision / cputc.s
1 ;
2 ; Written by Groepaz/Hitmen <groepaz@gmx.net>
3 ; Cleanup by Ullrich von Bassewitz <uz@cc65.org>
4 ;
5 ; void cputcxy (unsigned char x, unsigned char y, char c);
6 ; void cputc (char c);
7 ;
8
9         .export         _cputcxy, _cputc, cputdirect, putchar
10         .export         newline
11         .constructor    initconio
12         .import         popa, _gotoxy
13         .import         setcursor
14
15         .importzp       tmp3,tmp4
16
17         .include        "creativision.inc"
18         .include        "boxchars.inc"
19
20 ;-----------------------------------------------------------------------------
21
22 .code
23
24 _cputcxy:
25         pha                     ; Save C
26         jsr     popa            ; Get Y
27         jsr     _gotoxy         ; Set cursor, drop x
28         pla                     ; Restore C
29
30 ; Plot a character - also used as internal function
31
32 _cputc: cmp     #$0D            ; CR?
33         bne     L1
34         lda     #0
35         sta     CURSOR_X
36         beq     plot            ; Recalculate pointers
37
38 L1:     cmp     #$0A            ; LF?
39         beq     newline         ; Recalculate pointers
40
41 ; Printable char of some sort
42
43 cputdirect:
44         jsr     putchar         ; Write the character to the screen
45
46 ; Advance cursor position
47
48 advance:
49         ldy     CURSOR_X
50         iny
51         cpy     #SCREEN_COLS
52         bne     L3
53         inc     CURSOR_Y          ; new line
54         ldy     #0              ; + cr
55 L3:     sty     CURSOR_X
56         jmp     plot
57
58 newline:
59         inc     CURSOR_Y
60
61 ; Set cursor position, calculate RAM pointers
62
63 plot:   ldy     CURSOR_X
64         ldx     CURSOR_Y
65         jmp     setcursor       ; Set the new cursor
66
67
68 ; Write one character to the screen without doing anything else, return X
69 ; position in Y
70
71 putchar:
72         cmp     #$5B
73         bcc     IS_UPPER
74
75         clc
76         sbc     #$1F
77
78 IS_UPPER:
79         cmp     #$20
80         bcc     BAD_CHAR
81
82         pha
83         lda     SCREEN_PTR
84         sei
85         sta     VDP_CONTROL_W
86         lda     SCREEN_PTR+1
87         ora     #$40
88         sta     VDP_CONTROL_W
89         pla
90         clc
91         adc     #160
92         sta     VDP_DATA_W
93         cli
94
95 BAD_CHAR:
96         jmp     plot
97
98 ;-----------------------------------------------------------------------------
99 ; Initialize the conio subsystem. Code goes into the INIT segment, which may
100 ; be reused after startup.
101
102 .segment        "INIT"
103
104 initconio:
105         lda     #$0
106         sta     SCREEN_PTR
107         lda     #$10
108         sta     SCREEN_PTR+1
109
110         ; Copy box characters to slot
111         sei
112         lda     #08
113         sta     VDP_CONTROL_W
114         lda     #$46
115         sta     VDP_CONTROL_W
116         ldx     #0
117
118 LL:     lda     boxchars,x
119         sta     VDP_DATA_W
120         inx
121         cpx     #48
122         bne     LL
123
124         cli
125         jmp plot