From 4db5ac6c142479ec92f4bc09cd19e7aa98184209 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Wed, 25 Jun 2025 05:13:09 +0200 Subject: [PATCH] SCREEN_PTR does only contain the offset apparently (unlike on other cbm systems), so we need extra handling --- libsrc/c65/cpeekc.s | 45 +++++++++++++++++++++ libsrc/c65/cpeekcolor.s | 25 ++++++++++++ libsrc/c65/cpeeks.s | 80 +++++++++++++++++++++++++++++++++++++ libsrc/c65/cputc.s | 24 ++++++----- libsrc/cbm/cpeekc.s | 4 -- libsrc/cbm/cpeekcolor.s | 4 -- libsrc/cbm/cpeeks.s | 4 -- libsrc/mega65/cpeekc.s | 45 +++++++++++++++++++++ libsrc/mega65/cpeekcolor.s | 25 ++++++++++++ libsrc/mega65/cpeekrevers.s | 28 +++++++++++++ libsrc/mega65/cpeeks.s | 80 +++++++++++++++++++++++++++++++++++++ libsrc/mega65/cputc.s | 26 ++++++------ libsrc/mega65/kbhit.s | 2 +- 13 files changed, 356 insertions(+), 36 deletions(-) create mode 100644 libsrc/c65/cpeekc.s create mode 100644 libsrc/c65/cpeekcolor.s create mode 100644 libsrc/c65/cpeeks.s create mode 100644 libsrc/mega65/cpeekc.s create mode 100644 libsrc/mega65/cpeekcolor.s create mode 100644 libsrc/mega65/cpeekrevers.s create mode 100644 libsrc/mega65/cpeeks.s diff --git a/libsrc/c65/cpeekc.s b/libsrc/c65/cpeekc.s new file mode 100644 index 000000000..a64e13cfd --- /dev/null +++ b/libsrc/c65/cpeekc.s @@ -0,0 +1,45 @@ +; +; 2016-02-28, Groepaz +; 2017-06-22, Greg King +; +; char cpeekc (void); +; + + .include "c65.inc" + + .export _cpeekc + .importzp ptr1 + +_cpeekc: + lda SCREEN_PTR + 1 + clc + adc #>$0800 + sta ptr1 + 1 + lda SCREEN_PTR + sta ptr1 + + ldy CURS_X + lda (ptr1),y ; get screen code + ldx #>$0000 + 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 + bcs @sk1 ;(bge) + ora #$40 + rts + +@sk1: cmp #$40 + bcc @end ;(blt) + cmp #$60 + bcc @sk2 ;(blt) + ;sec + adc #$20 - $01 +@sk2: ;clc ; both above cmp and adc clear carry flag + adc #$20 +@end: rts diff --git a/libsrc/c65/cpeekcolor.s b/libsrc/c65/cpeekcolor.s new file mode 100644 index 000000000..f4b4a5573 --- /dev/null +++ b/libsrc/c65/cpeekcolor.s @@ -0,0 +1,25 @@ +; +; 2016-02-28, Groepaz +; 2017-06-22, Greg King +; +; unsigned char cpeekcolor (void); +; + + .include "c65.inc" + + .export _cpeekcolor + .importzp ptr1 + +_cpeekcolor: + lda SCREEN_PTR + 1 + clc + adc #>$D800 + sta ptr1 + 1 + lda SCREEN_PTR + sta ptr1 + + ldy #0 + lda (ptr1),y + + ldx #>$0000 + rts diff --git a/libsrc/c65/cpeeks.s b/libsrc/c65/cpeeks.s new file mode 100644 index 000000000..9c33831f1 --- /dev/null +++ b/libsrc/c65/cpeeks.s @@ -0,0 +1,80 @@ +; +; 2017-07-05, Greg King +; +; void cpeeks (char* s, unsigned length); +; + + .include "c65.inc" + + .export _cpeeks + + .import popax + .importzp ptr1, ptr2, ptr3, tmp1, tmp2 + + .macpack generic + +_cpeeks: + eor #<$FFFF ; counting a word upward is faster + sta ptr3 ; so, we use -(length + 1) + txa + eor #>$FFFF + sta ptr3+1 + + lda SCREEN_PTR + sta ptr2 + lda SCREEN_PTR+1 + clc + adc #>$0800 + sta ptr2+1 + + ldy CURS_X + sty tmp2 + + jsr popax + sta tmp1 ; (will be a .Y index) + stx ptr1+1 + ldx #<$0000 + stx ptr1 + bze L3 ; branch always + +L4: ldy tmp2 + lda (ptr2),y ; get char + iny + bnz L2 + inc ptr2+1 +L2: sty tmp2 + 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 L5 + cmp #$60 + blt @sk2 ;(bcc) + clc +@sk1: adc #$20 +@sk2: ;clc ; both above cmp and adc clear carry flag + adc #$20 + +L5: ldy tmp1 + sta (ptr1),y + iny + bnz L1 + inc ptr1+1 +L1: sty tmp1 + +L3: inc ptr3 ; count length + bnz L4 + inc ptr3+1 + bnz L4 + + txa ; terminate the string + ldy tmp1 + sta (ptr1),y + rts diff --git a/libsrc/c65/cputc.s b/libsrc/c65/cputc.s index a34262437..99a81b67d 100644 --- a/libsrc/c65/cputc.s +++ b/libsrc/c65/cputc.s @@ -96,23 +96,25 @@ plot: ldy CURS_X putchar: ora RVS ; Set revers bit - ldy CURS_X - pha + tay lda SCREEN_PTR + 1 clc adc #>$0800 - sta SCREEN_PTR + 1 - pla + sta ptr4 + 1 + lda SCREEN_PTR + sta ptr4 + tya - sta (SCREEN_PTR),y ; Set char + ldy CURS_X + sta (ptr4),y ; Set char - lda SCREEN_PTR + 1 - sec - sbc #>$0800 - sta SCREEN_PTR + 1 + lda ptr4 + 1 + clc + adc #>$d000 + sta ptr4 + 1 lda CHARCOLOR -; lda #$88 -; sta (CRAM_PTR),y ; Set color + sta (ptr4),y ; Set color + rts diff --git a/libsrc/cbm/cpeekc.s b/libsrc/cbm/cpeekc.s index 32dc0456e..05c7fc718 100644 --- a/libsrc/cbm/cpeekc.s +++ b/libsrc/cbm/cpeekc.s @@ -22,10 +22,6 @@ .include "pet.inc" .elseif .def(__VIC20__) .include "vic20.inc" -.elseif .def(__C65__) - .include "c65.inc" -.elseif .def(__MEGA65__) - .include "mega65.inc" .endif diff --git a/libsrc/cbm/cpeekcolor.s b/libsrc/cbm/cpeekcolor.s index a0d7efe6c..9c961b771 100644 --- a/libsrc/cbm/cpeekcolor.s +++ b/libsrc/cbm/cpeekcolor.s @@ -17,10 +17,6 @@ .include "c64.inc" .elseif .def(__VIC20__) .include "vic20.inc" -.elseif .def(__C65__) - .include "c65.inc" -.elseif .def(__MEGA65__) - .include "mega65.inc" .endif diff --git a/libsrc/cbm/cpeeks.s b/libsrc/cbm/cpeeks.s index d73192d73..215998e37 100644 --- a/libsrc/cbm/cpeeks.s +++ b/libsrc/cbm/cpeeks.s @@ -26,10 +26,6 @@ .include "pet.inc" .elseif .def(__VIC20__) .include "vic20.inc" -.elseif .def(__C65__) - .include "c65.inc" -.elseif .def(__MEGA65__) - .include "mega65.inc" .endif diff --git a/libsrc/mega65/cpeekc.s b/libsrc/mega65/cpeekc.s new file mode 100644 index 000000000..f75926d3e --- /dev/null +++ b/libsrc/mega65/cpeekc.s @@ -0,0 +1,45 @@ +; +; 2016-02-28, Groepaz +; 2017-06-22, Greg King +; +; char cpeekc (void); +; + + .include "mega65.inc" + + .export _cpeekc + .importzp ptr1 + +_cpeekc: + lda SCREEN_PTR + 1 + clc + adc #>$0800 + sta ptr1 + 1 + lda SCREEN_PTR + sta ptr1 + + ldy CURS_X + lda (ptr1),y ; get screen code + ldx #>$0000 + 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 + bcs @sk1 ;(bge) + ora #$40 + rts + +@sk1: cmp #$40 + bcc @end ;(blt) + cmp #$60 + bcc @sk2 ;(blt) + ;sec + adc #$20 - $01 +@sk2: ;clc ; both above cmp and adc clear carry flag + adc #$20 +@end: rts diff --git a/libsrc/mega65/cpeekcolor.s b/libsrc/mega65/cpeekcolor.s new file mode 100644 index 000000000..45a59f3cb --- /dev/null +++ b/libsrc/mega65/cpeekcolor.s @@ -0,0 +1,25 @@ +; +; 2016-02-28, Groepaz +; 2017-06-22, Greg King +; +; unsigned char cpeekcolor (void); +; + + .include "mega65.inc" + + .export _cpeekcolor + .importzp ptr1 + +_cpeekcolor: + lda SCREEN_PTR + 1 + clc + adc #>$d800 + sta ptr1 + 1 + lda SCREEN_PTR + sta ptr1 + + ldy CURS_X + lda (ptr1),y + + ldx #>$0000 + rts diff --git a/libsrc/mega65/cpeekrevers.s b/libsrc/mega65/cpeekrevers.s new file mode 100644 index 000000000..a8e03e91e --- /dev/null +++ b/libsrc/mega65/cpeekrevers.s @@ -0,0 +1,28 @@ +; +; 2016-02-28, Groepaz +; 2017-06-15, Greg King +; +; unsigned char cpeekrevers (void); +; + + .include "mega65.inc" + + .export _cpeekrevers + .importzp ptr1 + +_cpeekrevers: + lda SCREEN_PTR + 1 + clc + adc #>$0800 + sta ptr1 + 1 + lda SCREEN_PTR + sta ptr1 + + ldy CURS_X + lda (ptr1),y ; get screen code + and #$80 ; get reverse bit + asl a + tax ; ldx #>$0000 + rol a ; return boolean value + + rts diff --git a/libsrc/mega65/cpeeks.s b/libsrc/mega65/cpeeks.s new file mode 100644 index 000000000..9c33831f1 --- /dev/null +++ b/libsrc/mega65/cpeeks.s @@ -0,0 +1,80 @@ +; +; 2017-07-05, Greg King +; +; void cpeeks (char* s, unsigned length); +; + + .include "c65.inc" + + .export _cpeeks + + .import popax + .importzp ptr1, ptr2, ptr3, tmp1, tmp2 + + .macpack generic + +_cpeeks: + eor #<$FFFF ; counting a word upward is faster + sta ptr3 ; so, we use -(length + 1) + txa + eor #>$FFFF + sta ptr3+1 + + lda SCREEN_PTR + sta ptr2 + lda SCREEN_PTR+1 + clc + adc #>$0800 + sta ptr2+1 + + ldy CURS_X + sty tmp2 + + jsr popax + sta tmp1 ; (will be a .Y index) + stx ptr1+1 + ldx #<$0000 + stx ptr1 + bze L3 ; branch always + +L4: ldy tmp2 + lda (ptr2),y ; get char + iny + bnz L2 + inc ptr2+1 +L2: sty tmp2 + 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 L5 + cmp #$60 + blt @sk2 ;(bcc) + clc +@sk1: adc #$20 +@sk2: ;clc ; both above cmp and adc clear carry flag + adc #$20 + +L5: ldy tmp1 + sta (ptr1),y + iny + bnz L1 + inc ptr1+1 +L1: sty tmp1 + +L3: inc ptr3 ; count length + bnz L4 + inc ptr3+1 + bnz L4 + + txa ; terminate the string + ldy tmp1 + sta (ptr1),y + rts diff --git a/libsrc/mega65/cputc.s b/libsrc/mega65/cputc.s index ad93ba7e5..df44f5bdd 100644 --- a/libsrc/mega65/cputc.s +++ b/libsrc/mega65/cputc.s @@ -9,10 +9,10 @@ .export newline, plot .import gotoxy .import PLOT + .importzp ptr4 .include "mega65.inc" - _cputcxy: pha ; Save C jsr gotoxy ; Set cursor, drop x and y @@ -96,23 +96,25 @@ plot: ldy CURS_X putchar: ora RVS ; Set revers bit - ldy CURS_X - pha + tay lda SCREEN_PTR + 1 clc adc #>$0800 - sta SCREEN_PTR + 1 - pla + sta ptr4 + 1 + lda SCREEN_PTR + sta ptr4 + tya - sta (SCREEN_PTR),y ; Set char + ldy CURS_X + sta (ptr4),y ; Set char - lda SCREEN_PTR + 1 - sec - sbc #>$0800 - sta SCREEN_PTR + 1 + lda ptr4 + 1 + clc + adc #>$d000 + sta ptr4 + 1 lda CHARCOLOR -; lda #$88 -; sta (CRAM_PTR),y ; Set color + sta (ptr4),y ; Set color + rts diff --git a/libsrc/mega65/kbhit.s b/libsrc/mega65/kbhit.s index 63b34629b..b88b0f48a 100644 --- a/libsrc/mega65/kbhit.s +++ b/libsrc/mega65/kbhit.s @@ -19,6 +19,6 @@ _kbhit: lda #1 : - ldx #0 + ldx #>$0000 rts