From a7e509cd43f4ff54a11873757615f8bf68d49940 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Wed, 25 Jun 2025 21:39:03 +0200 Subject: [PATCH] better handling of the cursor, use kernal function to read key, not the UART directly --- asminc/cbm_kernal.inc | 1 + libsrc/c65/cgetc.s | 32 ++++++++++++++++++++++++++++++++ libsrc/c65/cursor.s | 26 -------------------------- libsrc/c65/kbhit.s | 12 +----------- libsrc/mega65/cgetc.s | 32 ++++++++++++++++++++++++++++++++ libsrc/mega65/cursor.s | 26 -------------------------- libsrc/mega65/kbhit.s | 10 ---------- 7 files changed, 66 insertions(+), 73 deletions(-) create mode 100644 libsrc/c65/cgetc.s delete mode 100644 libsrc/c65/cursor.s create mode 100644 libsrc/mega65/cgetc.s delete mode 100644 libsrc/mega65/cursor.s diff --git a/asminc/cbm_kernal.inc b/asminc/cbm_kernal.inc index 963ab1985..f06483a47 100644 --- a/asminc/cbm_kernal.inc +++ b/asminc/cbm_kernal.inc @@ -244,4 +244,5 @@ UDTIM := $FFEA KBDREAD := $D8C1 .elseif .def(__C65__) || .def(__MEGA65__) ; CLRSCR := $E0EC ; ??? + KBDREAD := $E006 .endif diff --git a/libsrc/c65/cgetc.s b/libsrc/c65/cgetc.s new file mode 100644 index 000000000..3b2d5934d --- /dev/null +++ b/libsrc/c65/cgetc.s @@ -0,0 +1,32 @@ + + + .include "cbm_kernal.inc" + .import cursor + .export _cgetc +_cgetc: + + lda cursor + beq nocursor + + ; enable the cursor + clc + jsr CURSOR + +nocursor: + ; wait for a key + ; FIXME: is $d610 mega65 specific? +: + lda $d610 + beq :- + + jsr KBDREAD + + pha + ; disable the cursor + sec + jsr CURSOR + + pla + ldx #0 + rts + diff --git a/libsrc/c65/cursor.s b/libsrc/c65/cursor.s deleted file mode 100644 index 8c36a7a32..000000000 --- a/libsrc/c65/cursor.s +++ /dev/null @@ -1,26 +0,0 @@ -; -; unsigned char cursor (unsigned char onoff); -; - - .include "cbm_kernal.inc" - - .export _cursor - .import cursor - -.proc _cursor - pha - ; A != 0 to enable, 0 to disable - cmp #0 - beq disable ; C = 1 - clc -disable: - ; C = 0 to enable, 1 to disable - jsr CURSOR - - ply ; onoff into Y - ldx #0 ; High byte of result - lda cursor ; Get old value - sty cursor ; Set new value - rts -.endproc - diff --git a/libsrc/c65/kbhit.s b/libsrc/c65/kbhit.s index 63b34629b..683451b03 100644 --- a/libsrc/c65/kbhit.s +++ b/libsrc/c65/kbhit.s @@ -1,17 +1,7 @@ - ; FIXME: is $d610 mega65 specific? ; FIXME: this should rather use the kernal (with keyboard buffer etc) - .export _cgetc -_cgetc: - -: lda $d610 - beq :- - ldx #0 - stx $d610 - rts - .export _kbhit _kbhit: lda $d610 @@ -19,6 +9,6 @@ _kbhit: lda #1 : - ldx #0 + ldx #>$0000 rts diff --git a/libsrc/mega65/cgetc.s b/libsrc/mega65/cgetc.s new file mode 100644 index 000000000..3b2d5934d --- /dev/null +++ b/libsrc/mega65/cgetc.s @@ -0,0 +1,32 @@ + + + .include "cbm_kernal.inc" + .import cursor + .export _cgetc +_cgetc: + + lda cursor + beq nocursor + + ; enable the cursor + clc + jsr CURSOR + +nocursor: + ; wait for a key + ; FIXME: is $d610 mega65 specific? +: + lda $d610 + beq :- + + jsr KBDREAD + + pha + ; disable the cursor + sec + jsr CURSOR + + pla + ldx #0 + rts + diff --git a/libsrc/mega65/cursor.s b/libsrc/mega65/cursor.s deleted file mode 100644 index 8c36a7a32..000000000 --- a/libsrc/mega65/cursor.s +++ /dev/null @@ -1,26 +0,0 @@ -; -; unsigned char cursor (unsigned char onoff); -; - - .include "cbm_kernal.inc" - - .export _cursor - .import cursor - -.proc _cursor - pha - ; A != 0 to enable, 0 to disable - cmp #0 - beq disable ; C = 1 - clc -disable: - ; C = 0 to enable, 1 to disable - jsr CURSOR - - ply ; onoff into Y - ldx #0 ; High byte of result - lda cursor ; Get old value - sty cursor ; Set new value - rts -.endproc - diff --git a/libsrc/mega65/kbhit.s b/libsrc/mega65/kbhit.s index b88b0f48a..683451b03 100644 --- a/libsrc/mega65/kbhit.s +++ b/libsrc/mega65/kbhit.s @@ -1,17 +1,7 @@ - ; FIXME: is $d610 mega65 specific? ; FIXME: this should rather use the kernal (with keyboard buffer etc) - .export _cgetc -_cgetc: - -: lda $d610 - beq :- - ldx #0 - stx $d610 - rts - .export _kbhit _kbhit: lda $d610