From 542474e9201cc81bda1171c7d438a154395a19f6 Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Tue, 31 Mar 2020 17:59:50 +0200 Subject: [PATCH] Improve `readkey` on CBM targets. PET improvements. --- include/keyboard.mfk | 41 +++++++++++++++++++++++++++++++++++++++++ include/pet.ini | 5 ++++- include/pet_kernal.mfk | 18 ++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/include/keyboard.mfk b/include/keyboard.mfk index 7d51372b..8da5706a 100644 --- a/include/keyboard.mfk +++ b/include/keyboard.mfk @@ -7,6 +7,8 @@ const byte KEY_ENTER = 13 #if CBM_64 noinline asm byte readkey() { + LDA #0 + STA $C6 __read_key__start: LDA $C6 BEQ __read_key__start @@ -18,6 +20,8 @@ __read_key__start: #if CBM_128 noinline asm byte readkey() { + LDA #0 + STA $D0 __read_key__start: LDA $D0 BEQ __read_key__start @@ -30,6 +34,8 @@ __read_key__start: #if CBM_264 noinline asm byte readkey() { + LDA #0 + STA $EF __read_key__start: LDA $EF BEQ __read_key__start @@ -42,6 +48,8 @@ __read_key__start: #if CBM_VIC noinline asm byte readkey() { + LDA #0 + STA $C6 __read_key__start: LDA $C6 BEQ __read_key__start @@ -51,6 +59,39 @@ __read_key__start: #endif +#if CBM_PET + +#if not(PET2001_SUPPORT) && not(PET3000_SUPPORT) && not(PET4000_SUPPORT) +#error At least one of PET2000_SUPPORT, PET3000_SUPPORT, PET4000_SUPPORT has to be defined +#endif + +noinline asm byte readkey() { +#if PET2001_SUPPORT + JSR is_pet2000 + BNE __read_key__start_new + // ROM 1.0: + LDA #0 + STA $20D +__read_key__start1: + LDA $20D + BEQ __read_key__start1 + LDA $20F + RTS + + // ROM 2.0 and above: +__read_key__start_new: + LDA #0 + STA $9E +__read_key__start2: + LDA $9E + BEQ __read_key__start2 + LDA $026F + RTS +} +#define OK = 1 +#endif + + #if ATARI_8 noinline asm byte readkey() { lda #$C diff --git a/include/pet.ini b/include/pet.ini index fa08b27f..34e89040 100644 --- a/include/pet.ini +++ b/include/pet.ini @@ -2,7 +2,7 @@ arch=nmos encoding=oldpetscii screen_encoding=petscr -modules=loader_0401,pet_kernal,default_panic +modules=loader_0401,pet_kernal,default_panic,stdlib [allocation] @@ -18,6 +18,9 @@ WIDESCREEN=0 KEYBOARD=1 JOYSTICKS=0 HAS_BITMAP_MODE=0 +PET2000_SUPPORT=1 +PET3000_SUPPORT=1 +PET4000_SUPPORT=1 [output] style=single diff --git a/include/pet_kernal.mfk b/include/pet_kernal.mfk index 59376250..e401ea61 100644 --- a/include/pet_kernal.mfk +++ b/include/pet_kernal.mfk @@ -11,3 +11,21 @@ asm void putchar(byte register(a) char) @$FFD2 extern inline void new_line() { putchar(13) } + +inline asm set_zero is_pet2000() { + ? LDA #$CA + CMP $FFFB + ? RTS +} + +inline asm set_zero is_pet3000() { + ? LDA #$FC + CMP $FFFB + ? RTS +} + +inline asm set_zero is_pet4000() { + ? LDA #$FD + CMP $FFFB + ? RTS +}