]> git.sur5r.net Git - cc65/blob - libsrc/atari5200/cputc.s
atari5200: name conio constructor 'initconio'
[cc65] / libsrc / atari5200 / cputc.s
1 ;
2 ; adapted from Atari version
3 ; Christian Groessler, 2014
4 ;
5 ; void cputcxy (unsigned char x, unsigned char y, char c);
6 ; void cputc (char c);
7 ;
8
9         .include        "atari5200.inc"
10
11         .export         _cputcxy, _cputc
12         .export         plot, cputdirect, putchar
13         .import         gotoxy, _mul20
14         .import         conio_color
15         .importzp       screen_width, screen_height
16         .importzp       ptr4
17
18         .import         screen_setup
19         .constructor    initconio
20 initconio               =       screen_setup
21
22 _cputcxy:
23         pha                     ; Save C
24         jsr      gotoxy         ; Set cursor, drop x and y
25         pla                     ; Restore C
26
27 _cputc:
28         cmp     #$0D            ; CR
29         bne     L4
30         lda     #0
31         sta     COLCRS_5200
32         beq     plot            ; return
33
34 L4:     cmp     #$0A            ; LF
35         beq     newline
36         cmp     #ATEOL          ; Atari-EOL?
37         beq     newline
38
39         tay
40         rol     a
41         rol     a
42         rol     a
43         rol     a
44         and     #3
45         tax
46         tya
47         and     #$9F
48         ora     ataint,x
49
50 cputdirect:                     ; accepts screen code
51         jsr     putchar
52
53 ; advance cursor
54         inc     COLCRS_5200
55         lda     COLCRS_5200
56         cmp     #screen_width
57         bcc     plot
58         lda     #0
59         sta     COLCRS_5200
60
61         .export newline
62 newline:
63         inc     ROWCRS_5200
64         lda     ROWCRS_5200
65         cmp     #screen_height
66         bne     plot
67         lda     #0
68         sta     ROWCRS_5200
69 plot:   ldy     COLCRS_5200
70         ldx     ROWCRS_5200
71         rts
72
73 putchar:
74         pha                     ; save char
75
76         lda     ROWCRS_5200
77         jsr     _mul20          ; destroys tmp4, carry is cleared
78         adc     SAVMSC          ; add start of screen memory
79         sta     ptr4
80         txa
81         adc     SAVMSC+1
82         sta     ptr4+1
83         pla                     ; get char again
84
85         and     #$3F            ; clear palette index bits
86         ora     conio_color     ; use currently selected palette
87
88         ldy     COLCRS_5200
89         sta     (ptr4),y
90         rts
91
92         .rodata
93 ataint: .byte   64,0,32,96