]> git.sur5r.net Git - cc65/blob - libsrc/atari5200/cputc.s
Optimized mul20 & mul40 and extracted to new library.
[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, 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         ldy     COLCRS_5200
87         sta     (ptr4),y
88         jmp     setcursor
89
90         .rodata
91 ataint: .byte   64,0,32,96
92