]> git.sur5r.net Git - cc65/blob - libsrc/atari5200/cputc.s
8fc00fcdcc3853e0d611b4de3d4619b94a176c38
[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         .constructor    screen_setup, 26
19         .import         screen_setup_20x24
20 screen_setup    = screen_setup_20x24
21
22
23 _cputcxy:
24         pha                     ; Save C
25         jsr      gotoxy         ; Set cursor, drop x and y
26         pla                     ; Restore C
27
28 _cputc:
29         cmp     #$0D            ; CR
30         bne     L4
31         lda     #0
32         sta     COLCRS_5200
33         beq     plot            ; return
34
35 L4:     cmp     #$0A            ; LF
36         beq     newline
37         cmp     #ATEOL          ; Atari-EOL?
38         beq     newline
39
40         tay
41         rol     a
42         rol     a
43         rol     a
44         rol     a
45         and     #3
46         tax
47         tya
48         and     #$9F
49         ora     ataint,x
50
51 cputdirect:                     ; accepts screen code
52         jsr     putchar
53
54 ; advance cursor
55         inc     COLCRS_5200
56         lda     COLCRS_5200
57         cmp     #screen_width
58         bcc     plot
59         lda     #0
60         sta     COLCRS_5200
61
62         .export newline
63 newline:
64         inc     ROWCRS_5200
65         lda     ROWCRS_5200
66         cmp     #screen_height
67         bne     plot
68         lda     #0
69         sta     ROWCRS_5200
70 plot:   ldy     COLCRS_5200
71         ldx     ROWCRS_5200
72         rts
73
74 putchar:
75         pha                     ; save char
76
77         lda     ROWCRS_5200
78         jsr     _mul20          ; destroys tmp4, carry is cleared
79         adc     SAVMSC          ; add start of screen memory
80         sta     ptr4
81         txa
82         adc     SAVMSC+1
83         sta     ptr4+1
84         pla                     ; get char again
85
86 ;       and     #$C0            ; without this we are compatible with the old version. user must not try to output a char >= $3F
87         ora     conio_color
88
89         ldy     COLCRS_5200
90         sta     (ptr4),y
91         rts
92
93         .rodata
94 ataint: .byte   64,0,32,96