]> git.sur5r.net Git - cc65/blob - libsrc/atari5200/cputc.s
860eea88d253ce9ef9e0ac64a1f47153e8a2c940
[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         .importzp       ptr4
15         .import         setcursor
16
17         .constructor    screen_setup, 26
18         .import         screen_setup_20x24
19 screen_setup    = screen_setup_20x24
20
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     #20
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     #24
66         bne     plot
67         lda     #0
68         sta     ROWCRS_5200
69 plot:   jsr     setcursor
70         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
79         clc
80         adc     SAVMSC          ; add start of screen memory
81         sta     ptr4
82         txa
83         adc     SAVMSC+1
84         sta     ptr4+1
85         pla                     ; get char again
86
87         ldy     COLCRS_5200
88         sta     (ptr4),y
89         jmp     setcursor
90
91         .rodata
92 ataint: .byte   64,0,32,96
93