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