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