]> git.sur5r.net Git - cc65/commitdiff
fix cpeeks() for C128 VDC
authormrdudz <mrdudz@users.noreply.github.com>
Tue, 12 Dec 2017 16:05:24 +0000 (17:05 +0100)
committermrdudz <mrdudz@users.noreply.github.com>
Tue, 12 Dec 2017 16:05:24 +0000 (17:05 +0100)
libsrc/c128/cpeeks.s

index e0723e694d307b136e051a883bd33b54d58136fc..12c3349e4e4a4544b80bb59669dc418ba2fa9de4 100644 (file)
@@ -1,5 +1,6 @@
 ;
 ; 2017-07-05, Greg King
+; 2017-12-12, Groepaz
 ;
 ; void cpeeks (char* s, unsigned length);
 ;
@@ -22,6 +23,9 @@ _cpeeks:
         eor     #>$FFFF
         sta     ptr3+1
 
+        lda     MODE
+        bmi     c80
+
         lda     SCREEN_PTR
         ldx     SCREEN_PTR+1
         sta     ptr2
@@ -77,3 +81,79 @@ L3:     inc     ptr3            ; count length
         ldy     tmp1
         sta     (ptr1),y
         rts
+
+        ;-----------------------------------------------------------
+c80:
+        lda     SCREEN_PTR
+        clc
+        adc     CURS_X
+        sta     ptr2
+        lda     SCREEN_PTR+1
+        adc     #0
+        sta     ptr2+1
+
+        jsr     popax
+        sta     tmp1            ; (will be a .Y index)
+        stx     ptr1+1
+        ldx     #<$0000
+        stx     ptr1
+        bze     L3a              ; branch always
+
+L4a:
+        lda     ptr2
+        ldy     ptr2+1
+        inc     ptr2
+        bne     @s
+        inc     ptr2+1
+@s:
+        ; get byte from VDC mem
+        ldx     #VDC_DATA_LO
+        stx     VDC_INDEX
+@L0:    bit     VDC_INDEX
+        bpl     @L0
+        sta     VDC_DATA
+        dex
+        stx     VDC_INDEX
+        sty     VDC_DATA
+
+        ldx     #VDC_RAM_RW
+        stx     VDC_INDEX
+@L1:    bit     VDC_INDEX
+        bpl     @L1             ; wait for blanking
+        lda     VDC_DATA
+
+        and     #<~$80          ; remove reverse bit
+
+; Convert the screen code into a PetSCII code.
+; $00 - $1F: +$40
+; $20 - $3F
+; $40 - $5f: +$20
+; $60 - $7F: +$40
+
+        cmp     #$20
+        blt     @sk1            ;(bcc)
+        cmp     #$40
+        blt     L5a
+        cmp     #$60
+        blt     @sk2            ;(bcc)
+        clc
+@sk1:   adc     #$20
+@sk2:   ;clc                    ; both above cmp and adc clear carry flag
+        adc     #$20
+
+L5a:    ldy     tmp1
+        sta     (ptr1),y
+        iny
+        bnz     L1a
+        inc     ptr1+1
+L1a:    sty     tmp1
+
+L3a:    inc     ptr3            ; count length
+        bnz     L4a
+        inc     ptr3+1
+        bnz     L4a
+
+        lda     #0              ; terminate the string
+        ldy     tmp1
+        sta     (ptr1),y
+        rts