diff --git a/compiler/res/prog8lib/c128/textio.p8 b/compiler/res/prog8lib/c128/textio.p8 index 3e11c0ebd..7ab0adf2b 100644 --- a/compiler/res/prog8lib/c128/textio.p8 +++ b/compiler/res/prog8lib/c128/textio.p8 @@ -406,6 +406,7 @@ asmsub width() clobbers(X,Y) -> ubyte @A { ; -- returns the text screen width (number of columns) %asm {{ jsr cbm.SCREEN + inx txa rts }} @@ -415,11 +416,22 @@ asmsub height() clobbers(X, Y) -> ubyte @A { ; -- returns the text screen height (number of rows) %asm {{ jsr cbm.SCREEN + iny tya rts }} } +asmsub size() clobbers(A) -> ubyte @X, ubyte @Y { + ; -- returns the text screen width in X and height in Y (number of columns and rows) + %asm {{ + jsr cbm.SCREEN + inx + iny + rts + }} +} + asmsub waitkey() -> ubyte @A { %asm {{ - jsr cbm.GETIN diff --git a/compiler/res/prog8lib/c64/textio.p8 b/compiler/res/prog8lib/c64/textio.p8 index fc2709641..722de7cc2 100644 --- a/compiler/res/prog8lib/c64/textio.p8 +++ b/compiler/res/prog8lib/c64/textio.p8 @@ -424,6 +424,14 @@ asmsub height() clobbers(X, Y) -> ubyte @A { }} } +asmsub size() clobbers(A) -> ubyte @X, ubyte @Y { + ; -- returns the text screen width in X and height in Y (number of columns and rows) + %asm {{ + jmp cbm.SCREEN + }} +} + + asmsub waitkey() -> ubyte @A { %asm {{ - jsr cbm.GETIN diff --git a/compiler/res/prog8lib/cx16/textio.p8 b/compiler/res/prog8lib/cx16/textio.p8 index b3447082b..d1422d155 100644 --- a/compiler/res/prog8lib/cx16/textio.p8 +++ b/compiler/res/prog8lib/cx16/textio.p8 @@ -615,6 +615,13 @@ asmsub height() clobbers(X, Y) -> ubyte @A { }} } +asmsub size() clobbers(A) -> ubyte @X, ubyte @Y { + ; -- returns the text screen width in X and height in Y (number of columns and rows) + %asm {{ + jmp cbm.SCREEN + }} +} + asmsub waitkey() -> ubyte @A { %asm {{ - jsr cbm.GETIN diff --git a/compiler/res/prog8lib/pet32/textio.p8 b/compiler/res/prog8lib/pet32/textio.p8 index 44272048c..f0b36f606 100644 --- a/compiler/res/prog8lib/pet32/textio.p8 +++ b/compiler/res/prog8lib/pet32/textio.p8 @@ -236,6 +236,17 @@ asmsub height() clobbers(X, Y) -> ubyte @A { }} } +asmsub size() clobbers(A) -> ubyte @X, ubyte @Y { + ; -- returns the text screen width in X and height in Y (number of columns and rows) + %asm {{ + jsr width + tax + jsr height + tay + rts + }} +} + asmsub waitkey() -> ubyte @A { %asm {{ - jsr cbm.GETIN diff --git a/compiler/res/prog8lib/virtual/textio.p8 b/compiler/res/prog8lib/virtual/textio.p8 index 3ad7b3f52..678903c64 100644 --- a/compiler/res/prog8lib/virtual/textio.p8 +++ b/compiler/res/prog8lib/virtual/textio.p8 @@ -21,6 +21,11 @@ sub height() -> ubyte { }} } +sub size() -> ubyte, ubyte { + ; -- returns the text screen width and height (number of columns and rows) + return width(), height() +} + sub clear_screen() { str @shared sequence = "\x1b[2J\x1B[H" %ir {{ diff --git a/docs/source/_static/symboldumps/skeletons-c128.txt b/docs/source/_static/symboldumps/skeletons-c128.txt index ce4a4e5f2..3dc2468ed 100644 --- a/docs/source/_static/symboldumps/skeletons-c128.txt +++ b/docs/source/_static/symboldumps/skeletons-c128.txt @@ -825,6 +825,7 @@ txt { setcc (ubyte col, ubyte row, ubyte character, ubyte charcolor) setchr (ubyte col @X, ubyte row @Y, ubyte character @A) clobbers (A,Y) setclr (ubyte col @X, ubyte row @Y, ubyte color @A) clobbers (A,Y) + size () clobbers (A) -> ubyte @X, ubyte @Y spc () uppercase () waitkey () -> ubyte @A diff --git a/docs/source/_static/symboldumps/skeletons-c64.txt b/docs/source/_static/symboldumps/skeletons-c64.txt index 84798d25d..4031721ea 100644 --- a/docs/source/_static/symboldumps/skeletons-c64.txt +++ b/docs/source/_static/symboldumps/skeletons-c64.txt @@ -938,6 +938,7 @@ txt { setcc (ubyte col, ubyte row, ubyte character, ubyte charcolor) setchr (ubyte col @X, ubyte row @Y, ubyte character @A) clobbers (A,Y) setclr (ubyte col @X, ubyte row @Y, ubyte color @A) clobbers (A,Y) + size () clobbers (A) -> ubyte @X, ubyte @Y spc () uppercase () waitkey () -> ubyte @A diff --git a/docs/source/_static/symboldumps/skeletons-cx16.txt b/docs/source/_static/symboldumps/skeletons-cx16.txt index 4dedcc5c4..44eb0c834 100644 --- a/docs/source/_static/symboldumps/skeletons-cx16.txt +++ b/docs/source/_static/symboldumps/skeletons-cx16.txt @@ -1422,6 +1422,7 @@ txt { setcc2 (ubyte col, ubyte row, ubyte character, ubyte colors) setchr (ubyte col @X, ubyte row @Y, ubyte character @A) clobbers (A) setclr (ubyte col @X, ubyte row @Y, ubyte color @A) clobbers (A) + size () clobbers (A) -> ubyte @X, ubyte @Y spc () t256c (bool enable) uppercase () diff --git a/docs/source/_static/symboldumps/skeletons-pet32.txt b/docs/source/_static/symboldumps/skeletons-pet32.txt index 14adc0599..e099497bb 100644 --- a/docs/source/_static/symboldumps/skeletons-pet32.txt +++ b/docs/source/_static/symboldumps/skeletons-pet32.txt @@ -540,6 +540,7 @@ txt { setcc (ubyte col, ubyte row, ubyte character, ubyte charcolor_ignored) setchr (ubyte col @X, ubyte row @Y, ubyte character @A) clobbers (A,Y) setclr (ubyte col, ubyte row, ubyte color) + size () clobbers (A) -> ubyte @X, ubyte @Y spc () uppercase () waitkey () -> ubyte @A diff --git a/docs/source/_static/symboldumps/skeletons-virtual.txt b/docs/source/_static/symboldumps/skeletons-virtual.txt index 04c859926..8c69704d1 100644 --- a/docs/source/_static/symboldumps/skeletons-virtual.txt +++ b/docs/source/_static/symboldumps/skeletons-virtual.txt @@ -559,6 +559,7 @@ txt { rvs_off () rvs_on () setchr (ubyte col, ubyte row, ubyte char) + size () -> ubyte, ubyte spc () uppercase () width () -> ubyte diff --git a/examples/customtarget/libraries/atari/textio.p8 b/examples/customtarget/libraries/atari/textio.p8 index 8c0ccf9d6..11eb8dbe7 100644 --- a/examples/customtarget/libraries/atari/textio.p8 +++ b/examples/customtarget/libraries/atari/textio.p8 @@ -412,20 +412,28 @@ asmsub waitkey() -> ubyte @A { asmsub width() clobbers(X,Y) -> ubyte @A { ; -- returns the text screen width (number of columns) - ; TODO %asm {{ - lda #0 + lda #DEFAULT_WIDTH rts }} } asmsub height() clobbers(X, Y) -> ubyte @A { ; -- returns the text screen height (number of rows) - ; TODO %asm {{ - lda #0 + lda #DEFAULT_HEIGHT rts }} } +asmsub size() clobbers(A) -> ubyte @X, ubyte @Y { + ; -- returns the text screen width in X and height in Y (number of columns and rows) + %asm {{ + ldx #DEFAULT_WIDTH + ldy #DEFAULT_HEIGHT + rts + }} +} + + } diff --git a/examples/customtarget/libraries/f256/textio.p8 b/examples/customtarget/libraries/f256/textio.p8 index e33b511fa..49cfe3de7 100644 --- a/examples/customtarget/libraries/f256/textio.p8 +++ b/examples/customtarget/libraries/f256/textio.p8 @@ -417,7 +417,7 @@ asmsub plot (ubyte col @ Y, ubyte row @ X) { asmsub width() clobbers(X,Y) -> ubyte @A { ; -- returns the text screen width (number of columns) %asm {{ - lda DEFAULT_WIDTH + lda #DEFAULT_WIDTH rts }} } @@ -425,11 +425,21 @@ asmsub width() clobbers(X,Y) -> ubyte @A { asmsub height() clobbers(X, Y) -> ubyte @A { ; -- returns the text screen height (number of rows) %asm {{ - lda DEFAULT_HEIGHT + lda #DEFAULT_HEIGHT rts }} } +asmsub size() clobbers(A) -> ubyte @X, ubyte @Y { + ; -- returns the text screen width in X and height in Y (number of columns and rows) + %asm {{ + ldx #DEFAULT_HEIGHT + ldy #DEFAULT_HEIGHT + rts + }} +} + + ; TODO: jmp to cbm.CHRIN? asmsub waitkey() -> ubyte @A { %asm {{ diff --git a/examples/test.p8 b/examples/test.p8 index 07c63ac31..afec9fc27 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,18 +1,32 @@ %import textio -%import math %zeropage basicsafe %option no_sysinit main { sub start() { - long @shared lv, lv2 + ubyte w,h - lv = $11111111 - lv2 = $55555555 + w,h = txt.size() + txt.print("Screen size: ") + txt.print_ub(w) + txt.spc() + txt.print_ub(h) + txt.nl() + txt.print("width/height=") + txt.print_ub(txt.width()) + txt.spc() + txt.print_ub(txt.height()) + txt.nl() - lv = lv | lv2 ^ 999999 - txt.print_ulhex(lv, true) ; $555b177b +; long @shared lv, lv2 +; +; lv = $11111111 +; lv2 = $55555555 +; +; lv = lv | lv2 ^ 999999 +; +; txt.print_ulhex(lv, true) ; $555b177b ; long @shared lv1 = $12345678