]> git.sur5r.net Git - cc65/blob - libsrc/cbm/cpeeks.s
cbm stuff from greggs pull request
[cc65] / libsrc / cbm / 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
12         .macpack        generic
13
14 ; Get a system-specific file.
15 ; Note:  The cbm610, and c128 targets need special
16 ; versions that handle RAM banking and the 80-column VDC.
17
18 .if     .def(__C16__)
19         .include        "plus4.inc"     ; both C16 and Plus4
20 .elseif .def(__C64__)
21         .include        "c64.inc"
22 .elseif .def(__CBM510__)
23         .import         CURS_X: zp, SCREEN_PTR: zp
24         .include        "cbm510.inc"
25 .elseif .def(__PET__)
26         .include        "pet.inc"
27 .elseif .def(__VIC20__)
28         .include        "vic20.inc"
29 .endif
30
31
32 _cpeeks:
33         eor     #<$FFFF         ; counting a word upward is faster
34         sta     ptr3            ; so, we use -(length + 1)
35         txa
36         eor     #>$FFFF
37         sta     ptr3+1
38
39         lda     SCREEN_PTR
40         ldx     SCREEN_PTR+1
41         sta     ptr2
42         stx     ptr2+1
43         ldy     CURS_X
44         sty     tmp2
45
46         jsr     popax
47         sta     tmp1            ; (will be a .Y index)
48         stx     ptr1+1
49         ldx     #<$0000
50         stx     ptr1
51         bze     L3              ; branch always
52
53 L4:     ldy     tmp2
54         lda     (ptr2),y        ; get char
55         iny
56         bnz     L2
57         inc     ptr2+1
58 L2:     sty     tmp2
59         and     #<~$80          ; remove reverse bit
60
61 ; Convert the screen code into a PetSCII code.
62 ; $00 - $1F: +$40
63 ; $20 - $3F
64 ; $40 - $5f: +$20
65 ; $60 - $7F: +$40
66
67         cmp     #$20
68         blt     @sk1            ;(bcc)
69         cmp     #$40
70         blt     L5
71         cmp     #$60
72         blt     @sk2            ;(bcc)
73         clc
74 @sk1:   adc     #$20
75 @sk2:   ;clc                    ; both above cmp and adc clear carry flag
76         adc     #$20
77
78 L5:     ldy     tmp1
79         sta     (ptr1),y
80         iny
81         bnz     L1
82         inc     ptr1+1
83 L1:     sty     tmp1
84
85 L3:     inc     ptr3            ; count length
86         bnz     L4
87         inc     ptr3+1
88         bnz     L4
89
90         txa                     ; terminate the string
91         ldy     tmp1
92         sta     (ptr1),y
93         rts