FAQ  •  Register  •  Login

Best replacement for 'READ/DATA'

<<

LTee

Posts: 153

Joined: Tue Jul 07, 2009 2:54 pm

Post Thu Jun 22, 2017 9:14 pm

Best replacement for 'READ/DATA'

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!
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Fri Jun 23, 2017 10:33 am

Re: Best replacement for 'READ/DATA'

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
<<

LTee

Posts: 153

Joined: Tue Jul 07, 2009 2:54 pm

Post Fri Jun 23, 2017 2:57 pm

Re: Best replacement for 'READ/DATA'

Yes, this was incredibly convenient in Spectrum BASIC but is proving to be more of a challenge than I expected in ZX Basic. :D

I'm going to try some experiments over the weekend, see what seems to work best.
<<

LTee

Posts: 153

Joined: Tue Jul 07, 2009 2:54 pm

Post Sat Jun 24, 2017 6:57 pm

Re: Best replacement for 'READ/DATA'

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! :)

Return to Help & Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO