From e9e52d11a771a0c0b469a32e435170df62037413 Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Tue, 25 Jun 2019 18:19:33 +0200 Subject: [PATCH] Add readkey for C64 & ZXS. Fix putchar('{q}') on C64. --- docs/stdlib/frequent.md | 35 +++++++++++++++++++++++++++-------- docs/stdlib/stdio.md | 4 +--- include/c64_kernal.mfk | 21 ++++++++++++++++++--- include/zxspectrum.mfk | 10 ++++++++++ 4 files changed, 56 insertions(+), 14 deletions(-) diff --git a/docs/stdlib/frequent.md b/docs/stdlib/frequent.md index 1367939c..b14cdabd 100644 --- a/docs/stdlib/frequent.md +++ b/docs/stdlib/frequent.md @@ -8,16 +8,34 @@ However, as they are not the part of the standard library, they might not be ava Prints a single character. -Available for: all computer targets. +Available for: all computer targets. +Uses ROM routines, so requires the appropriate ROM to be enabled if applicable. -Note that this function obeys typical platform idiosyncrasies, -for example on CBM targets the quote character will toggle the quotation mode. +Note that this function may obey typical platform idiosyncrasies, for example: + +* on CBM targets other than C64 the quote character toggles the quotation mode + +* printing past the end of line might insert a blank line below the current one + +* printing past the end of the screen might ask the user to confirm scrolling + +The exact behaviour is platform-dependent. +Future library versions will strive to eliminate those issues. #### `void new_line()` Moves the cursor to the next line. -Available for: all computer targets. +Available for: all computer targets. +Uses ROM routines, so requires the appropriate ROM to be enabled if applicable. + +#### `byte readkey()` + +Waits for and reads a single keypress. + +Available for: +Commodore 64 (requires KERNAL), +ZX Spectrum. #### `pointer readline()` @@ -28,8 +46,8 @@ Available for: ZX Spectrum, NEC PC-88, MSX, -Commodore 64 with `c64_basic` module, -Commodore 16 or Plus/4 with `c264_basic` module. +Commodore 64 with `c64_basic` module (requires KERNAL and BASIC), +Commodore 16 or Plus/4 with `c264_basic` module (requires KERNAL and BASIC). #### `word readword()` @@ -39,14 +57,15 @@ Available for: ZX Spectrum, NEC PC-88, MSX, -Commodore 64 with `c64_basic` module, -Commodore 16 or Plus/4 with `c264_basic` module. +Commodore 64 with `c64_basic` module (requires KERNAL and BASIC), +Commodore 16 or Plus/4 with `c264_basic` module (requires KERNAL and BASIC). #### `void bell()` Beeps. Available for: Apple 2, ZX Spectrum. +Uses ROM routines, so requires the appropriate ROM to be enabled if applicable. #### `void set_bg_color(byte color)` diff --git a/docs/stdlib/stdio.md b/docs/stdlib/stdio.md index a73dc9d6..0eedf2f5 100644 --- a/docs/stdlib/stdio.md +++ b/docs/stdlib/stdio.md @@ -4,14 +4,12 @@ The `stdio` module automatically imports the `string` and `err` modules. It requires an implementation of `void putchar(byte a)` and therefore works only on targets with console output. +On targets with idiosyncratic behaviour of `putchar`, functions in this module inherit that behaviour. #### `void putstr(pointer str, byte len)` Prints a string of length `len` located at address `str`. -Note that both this function and `putstrz` obey typical platform idiosyncrasies, -for example on CBM targets the quote character will toggle the quotation mode. This may be subject to change. - #### `void putstrz(pointer str)` Prints a null-terminated string located at address `str`. diff --git a/include/c64_kernal.mfk b/include/c64_kernal.mfk index 354cac47..cc2982ba 100644 --- a/include/c64_kernal.mfk +++ b/include/c64_kernal.mfk @@ -2,11 +2,12 @@ // CHROUT. Write byte to default output. (If not screen, must call OPEN and CHKOUT beforehands.) // Input: A = Byte to write. -asm void putchar(byte a) @$FFD2 extern +asm void chrout(byte a) @$FFD2 extern // CHRIN. Read byte from default input (for keyboard, read a line from the screen). (If not keyboard, must call OPEN and CHKIN beforehands.) // Output: A = Byte read. -asm byte getchar() @$FFCF extern +asm byte chrin() @$FFCF extern +alias getchar = chrin // CHKIN. Define file as default input. (Must call OPEN beforehands.) // Input: X = Logical number. @@ -23,8 +24,22 @@ asm void clrchn() @$FFCC extern // Output: A = Device status. asm byte readst() @$FFB7 extern +inline asm void putchar(byte a) { + JSR chrout + LDA #0 + STA $D4 + ? RTS +} + +noinline asm byte readkey() { +__read_key__start + LDA $C6 + BEQ __read_key__start + JMP $E5B4 +} + inline void new_line() { - putchar(13) + chrout(13) } // OPEN. Open file. (Must call SETLFS and SETNAM beforehands.) diff --git a/include/zxspectrum.mfk b/include/zxspectrum.mfk index 1fcd63db..4e8da414 100644 --- a/include/zxspectrum.mfk +++ b/include/zxspectrum.mfk @@ -14,6 +14,16 @@ inline void new_line() { putchar(13) } +asm byte readkey() { + ld hl,23560 + ld (hl),0 +__readkey__start: + ld a,(hl) + or a + jr z,__readkey__start + ? ret +} + inline asm void set_border(byte a) { out (254),a ? ret