]> git.sur5r.net Git - cc65/blob - libsrc/cbm610/cpeeks.s
Issue 814
[cc65] / libsrc / cbm610 / cpeeks.s
1 ;
2 ; 2017-07-05, Greg King
3 ;
4 ; void cpeeks (char* s, unsigned length);
5 ;
6
7         .export         _cpeeks
8
9         .import         popax
10         .importzp       ptr1, ptr2, ptr3, tmp1, tmp2
11         .importzp       CURS_X, CharPtr
12
13         .include        "cbm610.inc"
14         .macpack        generic
15
16
17 _cpeeks:
18         eor     #<$FFFF         ; counting a word upward is faster
19         sta     ptr3            ; so, we use -(length + 1)
20         txa
21         eor     #>$FFFF
22         sta     ptr3+1
23
24         lda     CharPtr
25         ldx     CharPtr+1
26         sta     ptr2
27         stx     ptr2+1
28         ldy     CURS_X
29         sty     tmp2
30
31         jsr     popax
32         sta     tmp1            ; (will be a .Y index)
33         stx     ptr1+1
34         ldx     IndReg
35         ldy     #<$0000
36         sty     ptr1
37         bze     L3              ; branch always
38
39 L4:     ldy     #$0F
40         sty     IndReg
41         ldy     tmp2
42         lda     (ptr2),y        ; get char from system bank
43         stx     IndReg
44         iny
45         bnz     L2
46         inc     ptr2+1
47 L2:     sty     tmp2
48         and     #<~$80          ; remove reverse bit
49
50 ; Convert the screen code into a PetSCII code.
51 ; $00 - $1F: +$40
52 ; $20 - $3F
53 ; $40 - $5f: +$20
54 ; $60 - $7F: +$40
55
56         cmp     #$20
57         blt     @sk1            ;(bcc)
58         cmp     #$40
59         blt     L5
60         cmp     #$60
61         blt     @sk2            ;(bcc)
62         clc
63 @sk1:   adc     #$20
64 @sk2:   ;clc                    ; both above cmp and adc clear carry flag
65         adc     #$20
66
67 L5:     ldy     tmp1
68         sta     (ptr1),y
69         iny
70         bnz     L1
71         inc     ptr1+1
72 L1:     sty     tmp1
73
74 L3:     inc     ptr3            ; count length
75         bnz     L4
76         inc     ptr3+1
77         bnz     L4
78
79         lda     #$00            ; terminate the string
80         ldy     tmp1
81         sta     (ptr1),y
82         rts