From 5e5115936732df42526950e650b321c3b7f56bc6 Mon Sep 17 00:00:00 2001 From: Neil McPhail Date: Thu, 4 Sep 2025 11:51:39 +0000 Subject: [PATCH] Test case showing difference between local and global arrays --- Makefile | 7 +++++++ array.bas | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 Makefile create mode 100644 array.bas diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2a6799c --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +array.tap: array.bas + zxbc -o $@ -f tap -B -a $< + +clean: + rm -f array.tap + +.PHONY: clean \ No newline at end of file diff --git a/array.bas b/array.bas new file mode 100644 index 0000000..f48350a --- /dev/null +++ b/array.bas @@ -0,0 +1,30 @@ +DIM global(5) AS UByte => { 47h, 4Ch, 4Fh, 42h, 41h, 4Ch } + +subroutine() +STOP + +SUB subroutine() + DIM local(4) AS UByte => { 4Ch, 4Fh, 43h, 41h, 4Ch } + refer(6, @global) + refer(5, @local) +END SUB + +SUB refer(chars AS UByte, pointer AS UInteger) + DIM i AS UByte + REM Are we pointing to .array.__DATA__ ? + PRINT "If reference points to the DATA field ("; pointer;"): "; + FOR i = 0 TO chars - 1 + PRINT CHR$(PEEK (pointer + i));" "; + NEXT i + PRINT + + REM Are we pointing to .array, where pointer + 2 = data pointer? + pointer = PEEK(pointer + 2) + 256 * PEEK(pointer + 3) + PRINT "If reference points to pointer field ("; pointer;"): "; + FOR i = 0 TO chars - 1 + PRINT CHR$(PEEK (pointer + i));" "; + NEXT i + PRINT +END SUB + +37568 \ No newline at end of file