Masken, "fullscreen" snake game in 1k

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
dr beep
Posts: 2428
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Masken, "fullscreen" snake game in 1k

Post by dr beep »

abacaxi wrote: Wed Mar 12, 2025 1:36 am
(beep, why do you ld sp,dfile-1+1024 and not just dfile-1?)

On a 1K ZX81 this will mirror back to RAM 1K lower. On a ZX81 with more RAM the SP will be 1K higher.

My ZX81-emulator on the ZX Spectrum is coded on maximal speed not on perfect emulation.
This means that during an intrupt more registers are stacked than on a ZX81.
When a game in 1K has a tight stack (many of my games) then these would crash in my own emulator so I always use the displaced SP trick
to have tight games run on my own emulator.
abacaxi
Posts: 17
Joined: Thu Dec 05, 2024 8:20 pm

Re: Masken, "fullscreen" snake game in 1k

Post by abacaxi »

Got it, very interesting.
dr beep
Posts: 2428
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Masken, "fullscreen" snake game in 1k

Post by dr beep »

I downloaded the .P and made a disassembly of it.

If you want I can scan the code and reply with the optimizations:

Example:

Code: Select all

	LD A, ($4005)		 ; 4096 3A 05 40
	CP $EF			 ; 4099 FE EF
	JR NZ, L_40A2		 ; 409B 20 05
	CALL $4111		 ; 409D CD 11 41
	JR L_40AF		 ; 40A0 18 0D
L_40A2: CP $F7			 ; 40A2 FE F7
	JR NZ, L_40AF		 ; 40A4 20 09
	CALL $4111		 ; 40A6 CD 11 41
	CALL $4111		 ; 40A9 CD 11 41
	CALL $4111		 ; 40AC CD 11 41
L_40AF: XOR A			 ; 40AF AF
Can be

Code: Select all

	LD A, ($4005)		 
	CP $EF			 
	JR Z, AeqEF		 
	CP $F7			 
	JR NZ, L_40AF		 
	CALL $4111		 
	CALL $4111		 
AeqEF CALL $4111		 
	XOR A			 ; 40AF AF
5 bytes won!
abacaxi
Posts: 17
Joined: Thu Dec 05, 2024 8:20 pm

Re: Masken, "fullscreen" snake game in 1k

Post by abacaxi »

Thank you. I found several similar optimizations myself, whenever I find myself doing something similar several times there's usually a lot to save by restructuring. The key detection in particular can be made much shorter I'm sure. It's a mess. :)
dr beep
Posts: 2428
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Masken, "fullscreen" snake game in 1k

Post by dr beep »

Quick view on keyreading:

You want to keep any key pressed during the delay.
This is not needed. Better is to do the delay and then use the IN A,(254) to read B to space and check the bits

Code: Select all

	LD HL,frames
	LD A,(HL)
	SUB 7
wait	CP (HL)
	JR NZ,wait
	
	LD	A,127		; IN port B-space
	IN	A,(254)		; read port
	BIT	2,A			; test M pressed
	JR 	Z,do-M
	BIT	3,A			; test N pressed
	JR	Z,do_N
abacaxi
Posts: 17
Joined: Thu Dec 05, 2024 8:20 pm

Re: Masken, "fullscreen" snake game in 1k

Post by abacaxi »

Yes but the responsiveness increases a lot if I check every frame, and I need to check for key up in order to avoid double turns, I'm not checking that it's still down. A common strategy in this type of game is to very quickly double tap a key to make a u turn, which was very sketchy when l only checked after the delay.
Post Reply