ZX81 Character detection

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
PrimitivePerson
Posts: 17
Joined: Fri Oct 22, 2010 6:55 pm

ZX81 Character detection

Post by PrimitivePerson »

Does anyone know a little BASIC routine that can detect what character is displayed at a particular PRINT position? I typed in quite an interesting puzzle game from the Nov 1982 Sinclair User, which moves characters around on a 20x26 grid, and the game is pretty good, but has no scoring mechanism or means of detecting when you've finished the puzzle. You have to change the whole grid to "+" symbols, so I need a routine that will...

* Go through the grid, working out which character is displayed at each position
* The grid, by the way, is 26 columns and 20 rows.
* Stopping and jumping out as soon as it finds something that isn't a "+" symbol
* Finishing the game and printing an end message if it gets to the end of the list and finds no different characters.

Any ideas?

Cheers

Lee
User avatar
bobs
Posts: 325
Joined: Thu Aug 27, 2009 10:49 pm
Location: UK
Contact:

Re: ZX81 Character detection

Post by bobs »

You'd need to scan the actual display file for that, but you'd need to understand how it works.

The display in the ZX81 is stored row by row for all 24 rows, but not all 32 characters on a row are stored, in order to save memory. If an entire row is empty for example only the end-of-row marker is stored, thus using only 1 byte rather than the 33 which would be required for all 32 characters + the end-of-row marker.

Therefore it should be quite easy to write a small routine which "walks" the display file from the top left, keeping note of which row & column is currently being checked.
User avatar
thewiz
Posts: 58
Joined: Sun Aug 16, 2009 8:36 pm
Location: Crewe

Re: ZX81 Character detection

Post by thewiz »

Hi PrimitivePerson,

What Bobs is describing is a collapsed display which is used when the ZX81 has less then 3.25Kb of memory. With enough memory, e.g. 16Kb, the zx81 expands the display to a full 24 X 33 bytes.

In that case, you can use something like this to get the value of a particular screen position:

Code: Select all

10 let a=peek(16396) + (peek(16397) * 256) + 1
20 let b=a+(x*33+y)
30 let c=peek(b)
This is all from memory so that "+ 1" might be wrong. The 'x' variable represents line 0 to 23. The 'y' variable represents the column 0 to 31. If that works, replace x and y with a couple of FOR/NEXT loops.

Happy coding.

thewiz
Memotech rules
User avatar
kmurta
Posts: 302
Joined: Tue Sep 01, 2009 5:04 am
Location: Belo Horizonte - BR
Contact:

Re: ZX81 Character detection

Post by kmurta »

Another way to get the same result:

Code: Select all

10 PRINT AT X,Y;
20 LET C=PEEK (PEEK 16398+256*PEEK 16399)
Enjoy ;)
1 x ZX81, 2 x TK85 , 1 TK82C, 1 TK95, 1 x Alphacom 32 printer, 1 x ZXpand
ZeXtender board, Joy81 - Programmable Joystick Controller, Turbo Sound 81
http://zx81.eu5.org
https://toddysoftware.itch.io/
User avatar
bobs
Posts: 325
Joined: Thu Aug 27, 2009 10:49 pm
Location: UK
Contact:

Re: ZX81 Character detection

Post by bobs »

kmurta wrote:Another way to get the same result:

Code: Select all

10 PRINT AT X,Y;
20 LET C=PEEK (PEEK 16398+256*PEEK 16399)
Enjoy ;)
Now that is neat, hat's off! (You can tell I haven't programmed BASIC on an '81 since... well, about 1981 actually!)
Post Reply