From a7a45959e95db8841c09e9d60b396f1ca9e831fa Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Sat, 23 Oct 2021 11:06:38 +0200 Subject: [PATCH] fix: fix POINT screen offset --- src/arch/zx48k/library/point.bas | 20 +++++++++++++++++--- src/arch/zx48k/library/sinclair.bas | 15 +++++++-------- src/arch/zxnext/library/point.bas | 20 +++++++++++++++++--- src/arch/zxnext/library/sinclair.bas | 15 +++++++-------- tests/runtime/cases/point.bas | 14 ++++++++++++++ tests/runtime/expected/point.tzx.scr | Bin 0 -> 6912 bytes tests/runtime/run | 5 ++--- 7 files changed, 64 insertions(+), 25 deletions(-) create mode 100644 tests/runtime/cases/point.bas create mode 100644 tests/runtime/expected/point.tzx.scr diff --git a/src/arch/zx48k/library/point.bas b/src/arch/zx48k/library/point.bas index 142e328a6..0568de015 100644 --- a/src/arch/zx48k/library/point.bas +++ b/src/arch/zx48k/library/point.bas @@ -24,7 +24,7 @@ REM Avoid recursive / multiple inclusion ' Returns: ' 1 if point is plot 0 otherwise (byte) ' ---------------------------------------------------------------- -function point(x as ubyte, y as ubyte) as byte +function fastcall point(x as ubyte, y as ubyte) as byte asm PROC @@ -35,8 +35,22 @@ function point(x as ubyte, y as ubyte) as byte PIXEL_ADDR EQU (22AAh + 6) ; ROM addrs which calculate screen addr - ld b, (ix+7) - ld c, (ix+5) + pop hl + ex (sp), hl ; callee => put RET address back. H = y + ld b, h + ld c, a + +#ifdef SCREEN_Y_OFFSET + ld a, SCREEN_Y_OFFSET + add a, b + ld b, a +#endif + +#ifdef SCREEN_X_OFFSET + ld a, SCREEN_X_OFFSET + add a, c + ld c, a +#endif ld a, 191 ; Max y value sub b diff --git a/src/arch/zx48k/library/sinclair.bas b/src/arch/zx48k/library/sinclair.bas index 436a6eadf..1243fa801 100644 --- a/src/arch/zx48k/library/sinclair.bas +++ b/src/arch/zx48k/library/sinclair.bas @@ -16,11 +16,17 @@ REM Avoid recursive / multiple inclusion REM This library includes other classic Sinclair ZX Spectrum Routines +REM Shift the screen 16 pixels UP to match that of the original BASIC +REM ... unless the user has specified otherwise + +#ifndef SCREEN_Y_OFFSET +# define SCREEN_Y_OFFSET 16 +#endif + #include once #include once #include once - REM This is not the original Sinclair INPUT, but better than nothing #include once @@ -30,11 +36,4 @@ REM This needed to initialize USR "a" to a memory heap space REM Now updates UDG system var to new UDG memory zone POKE Uinteger 23675, allocate(21 * 8) : REM 8 bytes per UDG (21 total) -REM Shift the screen 16 pixels UP to match that of the original BASIC -REM ... unless the user has specified otherwise -#ifndef SCREEN_Y_OFFSET -# define SCREEN_Y_OFFSET 16 #endif - -#endif - diff --git a/src/arch/zxnext/library/point.bas b/src/arch/zxnext/library/point.bas index 142e328a6..0568de015 100644 --- a/src/arch/zxnext/library/point.bas +++ b/src/arch/zxnext/library/point.bas @@ -24,7 +24,7 @@ REM Avoid recursive / multiple inclusion ' Returns: ' 1 if point is plot 0 otherwise (byte) ' ---------------------------------------------------------------- -function point(x as ubyte, y as ubyte) as byte +function fastcall point(x as ubyte, y as ubyte) as byte asm PROC @@ -35,8 +35,22 @@ function point(x as ubyte, y as ubyte) as byte PIXEL_ADDR EQU (22AAh + 6) ; ROM addrs which calculate screen addr - ld b, (ix+7) - ld c, (ix+5) + pop hl + ex (sp), hl ; callee => put RET address back. H = y + ld b, h + ld c, a + +#ifdef SCREEN_Y_OFFSET + ld a, SCREEN_Y_OFFSET + add a, b + ld b, a +#endif + +#ifdef SCREEN_X_OFFSET + ld a, SCREEN_X_OFFSET + add a, c + ld c, a +#endif ld a, 191 ; Max y value sub b diff --git a/src/arch/zxnext/library/sinclair.bas b/src/arch/zxnext/library/sinclair.bas index 436a6eadf..1243fa801 100644 --- a/src/arch/zxnext/library/sinclair.bas +++ b/src/arch/zxnext/library/sinclair.bas @@ -16,11 +16,17 @@ REM Avoid recursive / multiple inclusion REM This library includes other classic Sinclair ZX Spectrum Routines +REM Shift the screen 16 pixels UP to match that of the original BASIC +REM ... unless the user has specified otherwise + +#ifndef SCREEN_Y_OFFSET +# define SCREEN_Y_OFFSET 16 +#endif + #include once #include once #include once - REM This is not the original Sinclair INPUT, but better than nothing #include once @@ -30,11 +36,4 @@ REM This needed to initialize USR "a" to a memory heap space REM Now updates UDG system var to new UDG memory zone POKE Uinteger 23675, allocate(21 * 8) : REM 8 bytes per UDG (21 total) -REM Shift the screen 16 pixels UP to match that of the original BASIC -REM ... unless the user has specified otherwise -#ifndef SCREEN_Y_OFFSET -# define SCREEN_Y_OFFSET 16 #endif - -#endif - diff --git a/tests/runtime/cases/point.bas b/tests/runtime/cases/point.bas new file mode 100644 index 000000000..0990ed6f9 --- /dev/null +++ b/tests/runtime/cases/point.bas @@ -0,0 +1,14 @@ +#include "lib/tst_framework.bas" + +INIT("Testing SCREEN X,Y coords shift") + +#define SCREEN_Y_OFFSET 96 +#define SCREEN_X_OFFSET 127 + +#include + +PLOT 0, 0 +PLOT -20, 20 +PRINT POINT(0, 0); " "; POINT(-20, 20); " "; POINT(20, -20); " "; POINT(-20, -20) + +FINISH diff --git a/tests/runtime/expected/point.tzx.scr b/tests/runtime/expected/point.tzx.scr new file mode 100644 index 0000000000000000000000000000000000000000..b1ebb52c38b3db1590d3fdf99258cea36bee4949 GIT binary patch literal 6912 zcmeH|p^gGU5Jc-PlN@42O9WyC0*P$VxpXES1d>nKuNbjG@Zsc&gr5~3*|`EDRA4rr&lMGy#Yf@SWe}`cV|$ILDw@G-b)T?BV57Pz3U!EL#~#>TBjK`- zfO(zg6NkOS7%`f|+kP!ru}8MoNK+B=fBWoyB)=^D!TE>qW!(5rY_Ab7/dev/null ../../zxbc.py -TaB $1 --debug-memory || exit 1 -fuse --auto-load --speed=19000 "$RUN.tzx" & - +fuse --auto-load --speed=19000 --machine=plus2 "$RUN.tzx" &