]> git.sur5r.net Git - cc65/blob - libsrc/pet/cputc.s
Added mouse module from C64
[cc65] / libsrc / pet / cputc.s
1 ;
2 ; Ullrich von Bassewitz, 06.08.1998
3 ;
4 ; void cputcxy (unsigned char x, unsigned char y, char c);
5 ; void cputc (char c);
6 ;
7
8         .export         _cputcxy, _cputc, cputdirect, putchar
9         .export         newline, plot
10         .import         popa, _gotoxy
11         .import         xsize, revers
12
13         .include        "pet.inc"
14         .include        "../cbm/cbm.inc"
15
16 _cputcxy:
17         pha                     ; Save C
18         jsr     popa            ; Get Y
19         jsr     _gotoxy         ; Set cursor, drop x
20         pla                     ; Restore C
21
22 ; Plot a character - also used as internal function
23
24 _cputc: cmp     #$0A            ; CR?
25         bne     L1
26         lda     #0
27         sta     CURS_X
28         beq     plot            ; Recalculate pointers
29
30 L1:     cmp     #$0D            ; LF?
31         beq     newline         ; Recalculate pointers
32
33 ; Printable char of some sort
34
35         cmp     #' '
36         bcc     cputdirect      ; Other control char
37         tay
38         bmi     L10
39         cmp     #$60
40         bcc     L2
41         and     #$DF
42         bne     cputdirect      ; Branch always
43 L2:     and     #$3F
44
45 cputdirect:
46         jsr     putchar         ; Write the character to the screen
47
48 ; Advance cursor position
49
50 advance:
51         iny
52         cpy     xsize
53         bne     L3
54         jsr     newline         ; new line
55         ldy     #0              ; + cr
56 L3:     sty     CURS_X
57         rts
58
59 newline:
60         clc
61         lda     xsize
62         adc     SCREEN_PTR
63         sta     SCREEN_PTR
64         bcc     L4
65         inc     SCREEN_PTR+1
66 L4:     inc     CURS_Y
67         rts
68
69 ; Handle character if high bit set
70
71 L10:    and     #$7F
72         cmp     #$7E            ; PI?
73         bne     L11
74         lda     #$5E            ; Load screen code for PI
75         bne     cputdirect
76 L11:    ora     #$40
77         bne     cputdirect
78
79
80
81 ; Set cursor position, calculate RAM pointers
82
83 plot:   ldy     CURS_Y
84         lda     ScrLo,y
85         sta     SCREEN_PTR
86         lda     ScrHi,y
87         ldy     xsize
88         cpy     #40
89         beq     @L1
90         asl     SCREEN_PTR              ; 80 column mode
91         rol     a
92 @L1:    ora     #$80                    ; Screen at $8000
93         sta     SCREEN_PTR+1
94         rts
95
96
97 ; Write one character to the screen without doing anything else, return X
98 ; position in Y
99
100 putchar:
101         ora     revers          ; Set revers bit
102         ldy     CURS_X
103         sta     (SCREEN_PTR),y  ; Set char
104         rts
105
106 ; Screen address tables - offset to real screen
107
108 .rodata
109
110 ScrLo:  .byte   $00, $28, $50, $78, $A0, $C8, $F0, $18
111         .byte   $40, $68, $90, $B8, $E0, $08, $30, $58
112         .byte   $80, $A8, $D0, $F8, $20, $48, $70, $98
113         .byte   $C0
114
115 ScrHi:  .byte   $00, $00, $00, $00, $00, $00, $00, $01
116         .byte   $01, $01, $01, $01, $01, $02, $02, $02
117         .byte   $02, $02, $02, $02, $03, $03, $03, $03
118         .byte   $03
119
120