1
0
mirror of https://github.com/KarolS/millfork.git synced 2025-01-01 06:29:53 +00:00

Add readkey for C64 & ZXS. Fix putchar('{q}') on C64.

This commit is contained in:
Karol Stasiak 2019-06-25 18:19:33 +02:00
parent e394fe15c3
commit e9e52d11a7
4 changed files with 56 additions and 14 deletions

View File

@ -8,16 +8,34 @@ However, as they are not the part of the standard library, they might not be ava
Prints a single character. 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, Note that this function may obey typical platform idiosyncrasies, for example:
for example on CBM targets the quote character will toggle the quotation mode.
* 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()` #### `void new_line()`
Moves the cursor to the next 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()` #### `pointer readline()`
@ -28,8 +46,8 @@ Available for:
ZX Spectrum, ZX Spectrum,
NEC PC-88, NEC PC-88,
MSX, MSX,
Commodore 64 with `c64_basic` module, Commodore 64 with `c64_basic` module (requires KERNAL and BASIC),
Commodore 16 or Plus/4 with `c264_basic` module. Commodore 16 or Plus/4 with `c264_basic` module (requires KERNAL and BASIC).
#### `word readword()` #### `word readword()`
@ -39,14 +57,15 @@ Available for:
ZX Spectrum, ZX Spectrum,
NEC PC-88, NEC PC-88,
MSX, MSX,
Commodore 64 with `c64_basic` module, Commodore 64 with `c64_basic` module (requires KERNAL and BASIC),
Commodore 16 or Plus/4 with `c264_basic` module. Commodore 16 or Plus/4 with `c264_basic` module (requires KERNAL and BASIC).
#### `void bell()` #### `void bell()`
Beeps. Beeps.
Available for: Apple 2, ZX Spectrum. 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)` #### `void set_bg_color(byte color)`

View File

@ -4,14 +4,12 @@
The `stdio` module automatically imports the `string` and `err` modules. 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. 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)` #### `void putstr(pointer str, byte len)`
Prints a string of length `len` located at address `str`. 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)` #### `void putstrz(pointer str)`
Prints a null-terminated string located at address `str`. Prints a null-terminated string located at address `str`.

View File

@ -2,11 +2,12 @@
// CHROUT. Write byte to default output. (If not screen, must call OPEN and CHKOUT beforehands.) // CHROUT. Write byte to default output. (If not screen, must call OPEN and CHKOUT beforehands.)
// Input: A = Byte to write. // 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.) // 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. // 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.) // CHKIN. Define file as default input. (Must call OPEN beforehands.)
// Input: X = Logical number. // Input: X = Logical number.
@ -23,8 +24,22 @@ asm void clrchn() @$FFCC extern
// Output: A = Device status. // Output: A = Device status.
asm byte readst() @$FFB7 extern 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() { inline void new_line() {
putchar(13) chrout(13)
} }
// OPEN. Open file. (Must call SETLFS and SETNAM beforehands.) // OPEN. Open file. (Must call SETLFS and SETNAM beforehands.)

View File

@ -14,6 +14,16 @@ inline void new_line() {
putchar(13) 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) { inline asm void set_border(byte a) {
out (254),a out (254),a
? ret ? ret