Help: ZX81 'BASIC' Peek function [duplicate]
Asked Answered
T

2

9

I need a way to find if the character ('<') has hit a wall (Black pixel Graphic)

-On a ZX81 game.

I'm been looking at another game... which uses code

if peek(peek 16398 +256*peek 16399) = code "blackpixel graphic" then ...

Which seems to work for them...

Is this correct code?

I'm not really knowledgable with addresses and getting memory and stuff.

Please help me...

-If you know a better way. Please answer :) -Someone mentioned 'cursor position' what the hell is that on a ZX81? Thanks,

Trifid answered 7/7, 2010 at 16:31 Comment(2)
+1 For a question on how to program a ZX81 in 2010 :)Switcheroo
@Switcheroo +1, too. And there is still a great manual in 2021, nowadays online: Mastering Machine Code on Your ZX81.Macrospore
J
6

PEEK(PEEK 16398+256*PEEK 16399) is an idiom meaning “get the character number at the current PRINT position”. This works because the two-byte word at 16398 is used by the ZX81 BASIC/ROM to store a pointer to the memory location in the screen data block corresponding to the PRINT position.

So to do collision detection, you'd first have to set:

PRINT AT X,Y;

co-ordinates to where the > is about to move, then read

LET C= PEEK(PEEK 16398+256*PEEK 16399)

then you can print the > on-screen (overwriting the previous character whose code is now in C) if you want to before doing the check:

IF C=128 THEN ...

(I'm guessing the character you want is the all-black character 128, █.)

Oh boy, do I feel old.

Jacquline answered 7/7, 2010 at 18:12 Comment(7)
Ok thanks alot. Sounds perfect. Let me try it, one problem: You said 'print at X,Y' where is about to move? to you mean where it is now moving? -I'm confused how you can print it, then after the peek bit you comment 'then you can print the >' do you print it twice? =/Trifid
PRINT AT without a string just sets the print cursor position.Jacquline
Wow, I never knew that =] Thanks alot. -Thats the advice i needed =]Trifid
I tried that... Keep getting 'C= 211'? =/ with letters and black graphics =/Trifid
Nvm I peeked it too many times. But still keep getting 0 now... =/ -peek of address 16777 is 0 =/Trifid
Ah, try PRINT AT X,Y; with a semicolon on the end (updated answer). I think without the semicolon, it goes onto the next line, which might put your positioning off.Jacquline
Thanks, works... Perfectly. :) Thanks so much :) I would give you more rep if possible =] You deserve it :)Trifid
H
1

Wow does this go back. I haven't used a ZX81, but I did write some games on a TRS-80 way back in the day.

The inner part:

(peek 16398 +256*peek 16399)

is pretty much taking the value of two memory locations (8 bit) and creating a 16 bit

number from them, which is then used as the address of the outer peek; you might rewrite this as:

addrToCheck = (peek 16398 +256*peek 16399)

pixelValue = peek(addrToCheck)

if pixelValue = code "blackpixel graphic" then...

I'm guessing that the 'addrToCheck' value is actually the character position in the game, expressed as an address on the screen. So if the value is not a wall, then you would update the values in address 16398 and 16399 with a new character position (using a 'poke', no doubt).

Hope this helps

Hui answered 7/7, 2010 at 16:59 Comment(2)
Character position in the game? How would I set that up?Trifid
By picking a memory location (or locations, apparently, according to the original source) to use, initializing it to whatever screen memory location you want the character to start at, and going for it.Hui

© 2022 - 2024 — McMap. All rights reserved.