]> git.sur5r.net Git - cc65/blob - libsrc/c128/cpeeks.s
Fixed gcc compiler warning (#867)
[cc65] / libsrc / c128 / cpeeks.s
1 ;
2 ; 2017-07-05, Greg King
3 ; 2017-12-12, Groepaz
4 ;
5 ; void cpeeks (char* s, unsigned length);
6 ;
7
8         .export         _cpeeks
9
10         .import         popax
11         .importzp       ptr1, ptr2, ptr3, tmp1, tmp2
12
13         .macpack        generic
14
15 ; FIXME c128 needs special version that handles the 80-column VDC.
16
17         .include        "c128.inc"
18
19 _cpeeks:
20         eor     #<$FFFF         ; counting a word upward is faster
21         sta     ptr3            ; so, we use -(length + 1)
22         txa
23         eor     #>$FFFF
24         sta     ptr3+1
25
26         lda     MODE
27         bmi     c80
28
29         lda     SCREEN_PTR
30         ldx     SCREEN_PTR+1
31         sta     ptr2
32         stx     ptr2+1
33         ldy     CURS_X
34         sty     tmp2
35
36         jsr     popax
37         sta     tmp1            ; (will be a .Y index)
38         stx     ptr1+1
39         ldx     #<$0000
40         stx     ptr1
41         bze     L3              ; branch always
42
43 L4:     ldy     tmp2
44         lda     (ptr2),y        ; get char
45         iny
46         bnz     L2
47         inc     ptr2+1
48 L2:     sty     tmp2
49         and     #<~$80          ; remove reverse bit
50
51 ; Convert the screen code into a PetSCII code.
52 ; $00 - $1F: +$40
53 ; $20 - $3F
54 ; $40 - $5f: +$20
55 ; $60 - $7F: +$40
56
57         cmp     #$20
58         blt     @sk1            ;(bcc)
59         cmp     #$40
60         blt     L5
61         cmp     #$60
62         blt     @sk2            ;(bcc)
63         clc
64 @sk1:   adc     #$20
65 @sk2:   ;clc                    ; both above cmp and adc clear carry flag
66         adc     #$20
67
68 L5:     ldy     tmp1
69         sta     (ptr1),y
70         iny
71         bnz     L1
72         inc     ptr1+1
73 L1:     sty     tmp1
74
75 L3:     inc     ptr3            ; count length
76         bnz     L4
77         inc     ptr3+1
78         bnz     L4
79
80         txa                     ; terminate the string
81         ldy     tmp1
82         sta     (ptr1),y
83         rts
84
85         ;-----------------------------------------------------------
86 c80:
87         lda     SCREEN_PTR
88         clc
89         adc     CURS_X
90         sta     ptr2
91         lda     SCREEN_PTR+1
92         adc     #0
93         sta     ptr2+1
94
95         jsr     popax
96         sta     tmp1            ; (will be a .Y index)
97         stx     ptr1+1
98         ldx     #<$0000
99         stx     ptr1
100         bze     L3a              ; branch always
101
102 L4a:
103         lda     ptr2
104         ldy     ptr2+1
105         inc     ptr2
106         bne     @s
107         inc     ptr2+1
108 @s:
109         ; get byte from VDC mem
110         ldx     #VDC_DATA_LO
111         stx     VDC_INDEX
112 @L0:    bit     VDC_INDEX
113         bpl     @L0
114         sta     VDC_DATA
115         dex
116         stx     VDC_INDEX
117         sty     VDC_DATA
118
119         ldx     #VDC_RAM_RW
120         stx     VDC_INDEX
121 @L1:    bit     VDC_INDEX
122         bpl     @L1             ; wait for blanking
123         lda     VDC_DATA
124
125         and     #<~$80          ; remove reverse bit
126
127 ; Convert the screen code into a PetSCII code.
128 ; $00 - $1F: +$40
129 ; $20 - $3F
130 ; $40 - $5f: +$20
131 ; $60 - $7F: +$40
132
133         cmp     #$20
134         blt     @sk1            ;(bcc)
135         cmp     #$40
136         blt     L5a
137         cmp     #$60
138         blt     @sk2            ;(bcc)
139         clc
140 @sk1:   adc     #$20
141 @sk2:   ;clc                    ; both above cmp and adc clear carry flag
142         adc     #$20
143
144 L5a:    ldy     tmp1
145         sta     (ptr1),y
146         iny
147         bnz     L1a
148         inc     ptr1+1
149 L1a:    sty     tmp1
150
151 L3a:    inc     ptr3            ; count length
152         bnz     L4a
153         inc     ptr3+1
154         bnz     L4a
155
156         lda     #0              ; terminate the string
157         ldy     tmp1
158         sta     (ptr1),y
159         rts