From ff324955dde6810653326a211a79e09295a80f83 Mon Sep 17 00:00:00 2001 From: markjreed Date: Tue, 7 Nov 2023 16:19:16 -0500 Subject: [PATCH] Feature/read cursor position (#111) * feat: add ability to read cursor position on CBM machines * feat: implement plot()/column() for atari target; add get_cursor(), get_column(), row(), and get_row() * feat: implement wait_key() for Commodore targets; add get_cursor(), get_column(), row(), get_row() * feat: really implement waitkey() on CBM targets * fix: make waitkey void for compatibility with atari --- compiler/res/prog8lib/atari/textio.p8 | 36 ++++++++++++++------- compiler/res/prog8lib/c128/textio.p8 | 46 +++++++++++++++++++++++++++ compiler/res/prog8lib/c64/textio.p8 | 46 +++++++++++++++++++++++++++ compiler/res/prog8lib/cx16/textio.p8 | 44 +++++++++++++++++++++++++ compiler/res/prog8lib/pet32/textio.p8 | 46 +++++++++++++++++++++++++++ 5 files changed, 207 insertions(+), 11 deletions(-) diff --git a/compiler/res/prog8lib/atari/textio.p8 b/compiler/res/prog8lib/atari/textio.p8 index 121ca9553..cdc0b4268 100644 --- a/compiler/res/prog8lib/atari/textio.p8 +++ b/compiler/res/prog8lib/atari/textio.p8 @@ -24,12 +24,24 @@ sub spc() { txt.chrout(' ') } -asmsub column(ubyte col @A) clobbers(A, X, Y) { +const uword COLCRS = 85 +const uword ROWCRS = 84 +sub column(ubyte col) { ; ---- set the cursor on the given column (starting with 0) on the current line - ; TODO - %asm {{ - rts - }} + pokew(COLCRS, col as uword) +} + +sub get_column() -> ubyte { + return peekw(COLCRS) as ubyte +} + +sub row(ubyte rownum) { + ; ---- set the cursor on the given row (starting with 0) on the current line + @(ROWCRS) = rownum +} + +sub get_row() -> ubyte { + return @(ROWCRS) } asmsub fill_screen (ubyte character @ A, ubyte color @ Y) clobbers(A) { @@ -372,12 +384,14 @@ sub setcc (ubyte col, ubyte row, ubyte char, ubyte charcolor) { }} } -asmsub plot (ubyte col @ Y, ubyte row @ A) { - ; ---- set cursor at specific position - ; TODO - %asm {{ - rts - }} +sub plot(ubyte col, ubyte rownum) { + column(col) + row(rownum) +} + +sub get_cursor(uword colptr, uword rowptr) { + @(colptr) = get_column() + @(rowptr) = get_row() } asmsub width() clobbers(X,Y) -> ubyte @A { diff --git a/compiler/res/prog8lib/c128/textio.p8 b/compiler/res/prog8lib/c128/textio.p8 index ffd5844fb..c0d5473f3 100644 --- a/compiler/res/prog8lib/c128/textio.p8 +++ b/compiler/res/prog8lib/c128/textio.p8 @@ -40,6 +40,45 @@ asmsub column(ubyte col @A) clobbers(A, X, Y) { }} } + +asmsub get_column() -> ubyte @Y { + %asm {{ + sec + jmp cbm.PLOT + }} +} + +asmsub row(ubyte rownum @A) clobbers(A, X, Y) { + ; ---- set the cursor on the given row (starting with 0) on the current line + %asm {{ + sec + jsr cbm.PLOT + tax + clc + jmp cbm.PLOT + }} +} + +asmsub get_row() -> ubyte @X { + %asm {{ + sec + jmp cbm.PLOT + }} +} + +sub get_cursor(uword colptr, uword rowptr) { + %asm {{ + sec + jsr cbm.PLOT + tya + ldy #$00 + sta (colptr),y + txa + sta (rowptr),y + }} +} + + asmsub fill_screen (ubyte char @ A, ubyte color @ Y) clobbers(A) { ; ---- fill the character screen with the given fill character and character color. ; (assumes screen and color matrix are at their default addresses) @@ -587,4 +626,11 @@ asmsub height() clobbers(X, Y) -> ubyte @A { }} } +asmsub waitkey() { + %asm {{ +- jsr cbm.GETIN + beq - + rts + }} +} } diff --git a/compiler/res/prog8lib/c64/textio.p8 b/compiler/res/prog8lib/c64/textio.p8 index c9d5ed6f0..8bdf8bded 100644 --- a/compiler/res/prog8lib/c64/textio.p8 +++ b/compiler/res/prog8lib/c64/textio.p8 @@ -41,6 +41,45 @@ asmsub column(ubyte col @A) clobbers(A, X, Y) { }} } + +asmsub get_column() -> ubyte @Y { + %asm {{ + sec + jmp cbm.PLOT + }} +} + +asmsub row(ubyte rownum @A) clobbers(A, X, Y) { + ; ---- set the cursor on the given row (starting with 0) on the current line + %asm {{ + sec + jsr cbm.PLOT + tax + clc + jmp cbm.PLOT + }} +} + +asmsub get_row() -> ubyte @X { + %asm {{ + sec + jmp cbm.PLOT + }} +} + +sub get_cursor(uword colptr, uword rowptr) { + %asm {{ + sec + jsr cbm.PLOT + tya + ldy #$00 + sta (colptr),y + txa + sta (rowptr),y + }} +} + + asmsub fill_screen (ubyte character @ A, ubyte color @ Y) clobbers(A) { ; ---- fill the character screen with the given fill character and character color. ; (assumes screen and color matrix are at their default addresses) @@ -586,4 +625,11 @@ asmsub height() clobbers(X, Y) -> ubyte @A { }} } +asmsub waitkey() { + %asm {{ +- jsr cbm.GETIN + beq - + rts + }} +} } diff --git a/compiler/res/prog8lib/cx16/textio.p8 b/compiler/res/prog8lib/cx16/textio.p8 index 57c425829..bb7747cbb 100644 --- a/compiler/res/prog8lib/cx16/textio.p8 +++ b/compiler/res/prog8lib/cx16/textio.p8 @@ -44,6 +44,43 @@ asmsub column(ubyte col @A) clobbers(A, X, Y) { }} } +asmsub get_column() -> ubyte @Y { + %asm {{ + sec + jmp cbm.PLOT + }} +} + +asmsub row(ubyte rownum @A) clobbers(A, X, Y) { + ; ---- set the cursor on the given row (starting with 0) on the current line + %asm {{ + sec + jsr cbm.PLOT + tax + clc + jmp cbm.PLOT + }} +} + +asmsub get_row() -> ubyte @X { + %asm {{ + sec + jmp cbm.PLOT + }} +} + +sub get_cursor(uword colptr, uword rowptr) { + %asm {{ + sec + jsr cbm.PLOT + tya + ldy #$00 + sta (colptr),y + txa + sta (rowptr),y + }} +} + asmsub fill_screen (ubyte character @ A, ubyte color @ Y) clobbers(A, X) { ; ---- fill the character screen with the given fill character and character color. %asm {{ @@ -759,4 +796,11 @@ asmsub height() clobbers(X, Y) -> ubyte @A { }} } +asmsub waitkey() { + %asm {{ +- jsr cbm.GETIN + beq - + rts + }} +} } diff --git a/compiler/res/prog8lib/pet32/textio.p8 b/compiler/res/prog8lib/pet32/textio.p8 index 886317f83..fd4fe9ad2 100644 --- a/compiler/res/prog8lib/pet32/textio.p8 +++ b/compiler/res/prog8lib/pet32/textio.p8 @@ -30,6 +30,45 @@ sub spc() { } + +asmsub get_column() -> ubyte @Y { + %asm {{ + sec + jmp cbm.PLOT + }} +} + +asmsub row(ubyte rownum @A) clobbers(A, X, Y) { + ; ---- set the cursor on the given row (starting with 0) on the current line + %asm {{ + sec + jsr cbm.PLOT + tax + clc + jmp cbm.PLOT + }} +} + +asmsub get_row() -> ubyte @X { + %asm {{ + sec + jmp cbm.PLOT + }} +} + +sub get_cursor(uword colptr, uword rowptr) { + %asm {{ + sec + jsr cbm.PLOT + tya + ldy #$00 + sta (colptr),y + txa + sta (rowptr),y + }} +} + + asmsub fill_screen (ubyte character @ A, ubyte color @ Y) clobbers(A) { ; ---- fill the character screen with the given fill character. color is ignored on PET %asm {{ @@ -456,4 +495,11 @@ asmsub height() clobbers(X, Y) -> ubyte @A { }} } +asmsub waitkey() { + %asm {{ +- jsr cbm.GETIN + beq - + rts + }} +} }