Skip to content

Commit 7af8134

Browse files
authored
Merge pull request #579 from boriel/fix/point
fix: fix POINT screen offset
2 parents f2b39de + a7a4595 commit 7af8134

7 files changed

Lines changed: 64 additions & 25 deletions

File tree

src/arch/zx48k/library/point.bas

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ REM Avoid recursive / multiple inclusion
2424
' Returns:
2525
' 1 if point is plot 0 otherwise (byte)
2626
' ----------------------------------------------------------------
27-
function point(x as ubyte, y as ubyte) as byte
27+
function fastcall point(x as ubyte, y as ubyte) as byte
2828
asm
2929

3030
PROC
@@ -35,8 +35,22 @@ function point(x as ubyte, y as ubyte) as byte
3535

3636
PIXEL_ADDR EQU (22AAh + 6) ; ROM addrs which calculate screen addr
3737

38-
ld b, (ix+7)
39-
ld c, (ix+5)
38+
pop hl
39+
ex (sp), hl ; callee => put RET address back. H = y
40+
ld b, h
41+
ld c, a
42+
43+
#ifdef SCREEN_Y_OFFSET
44+
ld a, SCREEN_Y_OFFSET
45+
add a, b
46+
ld b, a
47+
#endif
48+
49+
#ifdef SCREEN_X_OFFSET
50+
ld a, SCREEN_X_OFFSET
51+
add a, c
52+
ld c, a
53+
#endif
4054

4155
ld a, 191 ; Max y value
4256
sub b

src/arch/zx48k/library/sinclair.bas

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ REM Avoid recursive / multiple inclusion
1616

1717
REM This library includes other classic Sinclair ZX Spectrum Routines
1818

19+
REM Shift the screen 16 pixels UP to match that of the original BASIC
20+
REM ... unless the user has specified otherwise
21+
22+
#ifndef SCREEN_Y_OFFSET
23+
# define SCREEN_Y_OFFSET 16
24+
#endif
25+
1926
#include once <attr.bas>
2027
#include once <point.bas>
2128
#include once <screen.bas>
2229

23-
2430
REM This is not the original Sinclair INPUT, but better than nothing
2531
#include once <input.bas>
2632

@@ -30,11 +36,4 @@ REM This needed to initialize USR "a" to a memory heap space
3036
REM Now updates UDG system var to new UDG memory zone
3137
POKE Uinteger 23675, allocate(21 * 8) : REM 8 bytes per UDG (21 total)
3238

33-
REM Shift the screen 16 pixels UP to match that of the original BASIC
34-
REM ... unless the user has specified otherwise
35-
#ifndef SCREEN_Y_OFFSET
36-
# define SCREEN_Y_OFFSET 16
3739
#endif
38-
39-
#endif
40-

src/arch/zxnext/library/point.bas

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ REM Avoid recursive / multiple inclusion
2424
' Returns:
2525
' 1 if point is plot 0 otherwise (byte)
2626
' ----------------------------------------------------------------
27-
function point(x as ubyte, y as ubyte) as byte
27+
function fastcall point(x as ubyte, y as ubyte) as byte
2828
asm
2929

3030
PROC
@@ -35,8 +35,22 @@ function point(x as ubyte, y as ubyte) as byte
3535

3636
PIXEL_ADDR EQU (22AAh + 6) ; ROM addrs which calculate screen addr
3737

38-
ld b, (ix+7)
39-
ld c, (ix+5)
38+
pop hl
39+
ex (sp), hl ; callee => put RET address back. H = y
40+
ld b, h
41+
ld c, a
42+
43+
#ifdef SCREEN_Y_OFFSET
44+
ld a, SCREEN_Y_OFFSET
45+
add a, b
46+
ld b, a
47+
#endif
48+
49+
#ifdef SCREEN_X_OFFSET
50+
ld a, SCREEN_X_OFFSET
51+
add a, c
52+
ld c, a
53+
#endif
4054

4155
ld a, 191 ; Max y value
4256
sub b

src/arch/zxnext/library/sinclair.bas

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ REM Avoid recursive / multiple inclusion
1616

1717
REM This library includes other classic Sinclair ZX Spectrum Routines
1818

19+
REM Shift the screen 16 pixels UP to match that of the original BASIC
20+
REM ... unless the user has specified otherwise
21+
22+
#ifndef SCREEN_Y_OFFSET
23+
# define SCREEN_Y_OFFSET 16
24+
#endif
25+
1926
#include once <attr.bas>
2027
#include once <point.bas>
2128
#include once <screen.bas>
2229

23-
2430
REM This is not the original Sinclair INPUT, but better than nothing
2531
#include once <input.bas>
2632

@@ -30,11 +36,4 @@ REM This needed to initialize USR "a" to a memory heap space
3036
REM Now updates UDG system var to new UDG memory zone
3137
POKE Uinteger 23675, allocate(21 * 8) : REM 8 bytes per UDG (21 total)
3238

33-
REM Shift the screen 16 pixels UP to match that of the original BASIC
34-
REM ... unless the user has specified otherwise
35-
#ifndef SCREEN_Y_OFFSET
36-
# define SCREEN_Y_OFFSET 16
3739
#endif
38-
39-
#endif
40-

tests/runtime/cases/point.bas

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "lib/tst_framework.bas"
2+
3+
INIT("Testing SCREEN X,Y coords shift")
4+
5+
#define SCREEN_Y_OFFSET 96
6+
#define SCREEN_X_OFFSET 127
7+
8+
#include <point.bas>
9+
10+
PLOT 0, 0
11+
PLOT -20, 20
12+
PRINT POINT(0, 0); " "; POINT(-20, 20); " "; POINT(20, -20); " "; POINT(-20, -20)
13+
14+
FINISH
6.75 KB
Binary file not shown.

tests/runtime/run

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
#!/bin/bash
1+
22
# vim:et:ts=4:
33

44
RUN=$(basename -s .bas $1)
55
rm -f "$RUN.tzx"
66
killall fuse 2>/dev/null
77
../../zxbc.py -TaB $1 --debug-memory || exit 1
8-
fuse --auto-load --speed=19000 "$RUN.tzx" &
9-
8+
fuse --auto-load --speed=19000 --machine=plus2 "$RUN.tzx" &

0 commit comments

Comments
 (0)