]> git.sur5r.net Git - cc65/blob - libsrc/cbm/cpeekc.s
cbm stuff from greggs pull request
[cc65] / libsrc / cbm / cpeekc.s
1 ;
2 ; 2016-02-28, Groepaz
3 ; 2017-06-22, Greg King
4 ;
5 ; char cpeekc (void);
6 ;
7
8         .export         _cpeekc
9
10 ; Get a system-specific file.
11 ; Note:  The cbm610, and c128 targets need special
12 ; versions that handle RAM banking and the 80-column VDC.
13
14 .if     .def(__C16__)
15         .include        "plus4.inc"     ; both C16 and Plus4
16 .elseif .def(__C64__)
17         .include        "c64.inc"
18 .elseif .def(__CBM510__)
19         .import         CURS_X: zp, SCREEN_PTR: zp
20         .include        "cbm510.inc"
21 .elseif .def(__PET__)
22         .include        "pet.inc"
23 .elseif .def(__VIC20__)
24         .include        "vic20.inc"
25 .endif
26
27
28 _cpeekc:
29         ldy     CURS_X
30         lda     (SCREEN_PTR),y  ; get screen code
31         ldx     #>$0000
32         and     #<~$80          ; remove reverse bit
33
34 ; Convert the screen code into a PetSCII code.
35 ; $00 - $1F: +$40
36 ; $20 - $3F
37 ; $40 - $5f: +$20
38 ; $60 - $7F: +$40
39
40         cmp     #$20
41         bcs     @sk1            ;(bge)
42         ora     #$40
43         rts
44
45 @sk1:   cmp     #$40
46         bcc     @end            ;(blt)
47         cmp     #$60
48         bcc     @sk2            ;(blt)
49         ;sec
50         adc     #$20 - $01
51 @sk2:   ;clc                    ; both above cmp and adc clear carry flag
52         adc     #$20
53 @end:   rts