Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best replacement for 'READ/DATA'
#1
I have a scenario in a program I'm converting from Spectrum BASIC to ZX Basic where I need to replace a READ/DATA setup. The code prints messages something like this:

10 restore x: read a, b
20 for n = 1 to b: read i, m$: print ink i; at a+n, 0; m$: next n: return
30 data 10, 3, 6, "test", 7, "test 2", 5, "test 3"

So the code sets 'x' to the DATA row containing the message you want to print (in this case x=30), then you call the subroutine at line 10 which reads the position and number of rows, then loops through 'b' rows reading the ink colour and the message and printing them to the screen.

I need to replace this in ZX Basic with something different. At the minute I've just shoved everything into arrays, but this is very inefficient because I'm effectively storing the data twice so the message bank takes up a lot more memory than it needs to.

What's the 'best' way to do this? I was thinking of maybe having a bunch of DEFB statements to directly replace the DATA lines, terminating each string with a 0 marker. That way I can read the bytes for 'a', 'b' and 'i' easily with PEEKs, and build the messages up by reading until I reach the '0'. I'm not sure how performant that would be, though - is there a faster way to copy a chunk of memory into a string?

Interested to hear any ideas!
Reply
#2
READ / DATA / RESTORE is planned (mostly for compatibility purposes like this).
It's hard because of the mix of types and even FUNCTIONS that Sinclair BASIC allows.
e.g. DATA 5, x * x, 23, "Hello" are allowed
Reply
#3
Yes, this was incredibly convenient in Spectrum BASIC but is proving to be more of a challenge than I expected in ZX Basic. Big Grin

I'm going to try some experiments over the weekend, see what seems to work best.
Reply
#4
The idea of turning the DATA rows into defb statements and null-terminating the strings works quite nicely. It'd probably be too slow for an arcade game, but now I have a solution and saved over 3k of memory! Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)