]> git.sur5r.net Git - cc65/blob - libsrc/pet/cputc.s
This commit was generated by cvs2svn to compensate for changes in r2,
[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         advance, 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     #$0D            ; CR?
25         bne     L1
26         lda     #0
27         sta     CURS_X
28         beq     plot            ; Recalculate pointers
29
30 L1:     cmp     #$0A            ; LF?
31         bne     L2
32         ldy     CURS_Y
33         iny
34         bne     newline         ; Recalculate pointers
35
36 ; Printable char of some sort
37
38 L2:     cmp     #' '
39         bcc     cputdirect      ; Other control char
40         tay
41         bmi     L10
42         cmp     #$60
43         bcc     L3
44         and     #$DF
45         bne     cputdirect      ; Branch always
46 L3:     and     #$3F
47
48 cputdirect:
49         jsr     putchar         ; Write the character to the screen
50
51 ; Advance cursor position
52
53 advance:
54         iny
55         cpy     xsize
56         bne     L9
57         ldy     #0              ; new line
58 newline:
59         clc
60         lda     xsize
61         adc     SCREEN_PTR
62         sta     SCREEN_PTR
63         bcc     L4
64         inc     SCREEN_PTR+1
65 L4:     inc     CURS_Y
66 L9:     sty     CURS_X
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