Crap Game: Snake but the only instruction is LD

People are still making stuff for the Sinclair related machines. Tell us about new games and other software that runs on the Spectrum, ZX80/ZX81, Pentagon and Next.
User avatar
Seven.FFF
Manic Miner
Posts: 744
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Crap Game: Snake but the only instruction is LD

Post by Seven.FFF »

This is flippin’ genius. Infinite hats doffed to you!
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
MrPixel
Microbot
Posts: 170
Joined: Sat Mar 24, 2018 7:42 pm

Re: Crap Game: Snake but the only instruction is LD

Post by MrPixel »

I half expected the game code to start screaming at me to let it die. Viewer discretion indeed :lol:
User avatar
djnzx48
Manic Miner
Posts: 730
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Crap Game: Snake but the only instruction is LD

Post by djnzx48 »

Are there any other instructions this could be done with other than LD? I was thinking that the shift/rotate instructions look like the best bet, plus you can use the undocumented instructions such as LD B, RLC (IX+d). You could use this along with an address in ROM to effectively load a value into a register, except you'd have to account for the value being shifted over one.
User avatar
djnzx48
Manic Miner
Posts: 730
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Crap Game: Snake but the only instruction is LD

Post by djnzx48 »

Ah no, that wouldn't work because there doesn't seem to be a way to do jumps without somehow modifying the stack pointer, which you can't do with shifts/rotates. Using the all-RAM configuration on a +3 wouldn't really work either because the screen would get in the way.

I did consider either moving the stack to the location of the FRAMES system variable, or setting IY to point to the stack, so that when the interrupt routine increments FRAMES it increments the return address. This would only let you do 256 byte jumps, but if the calling code is after $FF00 it could potentially be used to jump into ROM which then does a RET to the desired location? So maybe a sequel is possible after all :)
User avatar
R-Tape
Site Admin
Posts: 6397
Joined: Thu Nov 09, 2017 11:46 am

Re: Crap Game: Snake but the only instruction is LD

Post by R-Tape »

djnzx48 wrote: Wed May 30, 2018 6:16 am Are there any other instructions this could be done with other than LD?
I'm still getting my head around this one! I can see how it loops by repeating LD A,(HL) and changing the stack so the interrupt does it for you, but I need to put a cold flannel on my head and work out how you can do everything else without even using CP!

I wouldn't have thought this possible.
User avatar
djnzx48
Manic Miner
Posts: 730
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Crap Game: Snake but the only instruction is LD

Post by djnzx48 »

Well this technique is very limited :)

Instead of thinking of branches and choosing whether to do some computation or not based on a condition, you basically always do the computation, but set it up so that if the condition is false you end up with what you had before. So for example, the food always gets drawn every frame, but if there's still food on the screen or if the screen position where it's supposed to appear is occupied, it just draws whatever colour is already on the screen and so nothing changes. There's still a lot of things that are basically impossible to do without resorting to complicated loops, even just adding two numbers or checking whether one value is greater than another.
MrPixel
Microbot
Posts: 170
Joined: Sat Mar 24, 2018 7:42 pm

Re: Crap Game: Snake but the only instruction is LD

Post by MrPixel »

is there a version for the WinAPE?
MrPixel
Microbot
Posts: 170
Joined: Sat Mar 24, 2018 7:42 pm

Re: Crap Game: Snake but the only instruction is LD

Post by MrPixel »

djnzx48 wrote: Tue May 29, 2018 10:28 am Image
Z80 machine code has a lot of instructions, and it can be difficult trying to keep track of them all. Does PUSH decrement the stack pointer before or afterwards? What's the difference between IFF1 and IFF2? And what exactly does DAA even do?

Well, here's some good news: you don't have to memorise any of these instructions, since it turns out that all of them are in fact useless! (Cries of 'blow me down' and 'well I never'. Ed.) Well, it's true. And to prove it, here's a version of that gaming classic, Snake, where every single instruction is replaced with the humble LD. Nope, there's no trickery or self-modifying code going on here - it's all just LD instructions.

Download here: snake.tap
Runs on any 48K/128K Spectrum. Controls are QAOP or 5678.

Planned features: Extra levels, redefinable keys, multiple speed settings, online leaderboard, ability to make phone calls, VR support, Rolos dispensed when you win...

Source code available here if you want to experience the true horror. Viewer discretion is advised.
please remap the keys to traditional arrow or wasd please
User avatar
Seven.FFF
Manic Miner
Posts: 744
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Crap Game: Snake but the only instruction is LD

Post by Seven.FFF »

5678 *is* traditional arrow.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
Kweepa
Manic Miner
Posts: 311
Joined: Sat Feb 03, 2018 6:14 pm
Location: Albuquerque, New Mexico

Re: Crap Game: Snake but the only instruction is LD

Post by Kweepa »

Plays like a dream!
User avatar
djnzx48
Manic Miner
Posts: 730
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Crap Game: Snake but the only instruction is LD

Post by djnzx48 »

I was thinking of adding WASD keys but that clashes with QAOP which is more 'traditional', IMHO. I'll probably add redefinable keys in a future update. I don't know anything about Amstrad machines, so no idea if anything like this is possible there.

EDIT: Would ESDF do? It's the same basic configuration but just shifted over one.
User avatar
djnzx48
Manic Miner
Posts: 730
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Crap Game: Snake but the only instruction is LD

Post by djnzx48 »

[mention]MrPixel[/mention] there's a new update here adding ESDF controls in addition to the old QAOP and 5678 controls.
MrPixel
Microbot
Posts: 170
Joined: Sat Mar 24, 2018 7:42 pm

Re: Crap Game: Snake but the only instruction is LD

Post by MrPixel »

djnzx48 wrote: Thu May 31, 2018 12:46 am I was thinking of adding WASD keys but that clashes with QAOP which is more 'traditional', IMHO. I'll probably add redefinable keys in a future update. I don't know anything about Amstrad machines, so no idea if anything like this is possible there.

EDIT: Would ESDF do? It's the same basic configuration but just shifted over one.
what about I,j,k,l or plain arrow keys. i'm on a latop so the traditional 5,6,7,8 keys are in a straight vertical line, not marked. good game though. i'm amazed that you were able to pull this off. won't run in zxspin assembler though
MrPixel
Microbot
Posts: 170
Joined: Sat Mar 24, 2018 7:42 pm

Re: Crap Game: Snake but the only instruction is LD

Post by MrPixel »

so, the base game is good, impressive even. however, the snake lacks any sort of ability to reverse direction. maybe add in some sort of bumper (like in sonic CD in Collision Chaos) that would help the snake reverse direction. also, some music. take advantage of the Spectrum 128's capabilities and create something suitable. i would also suggest you remove the ground barriers as well as the ceiling as i had some trouble with them. your decision but keep it in mind. happy coding :D
User avatar
djnzx48
Manic Miner
Posts: 730
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Crap Game: Snake but the only instruction is LD

Post by djnzx48 »

Yeah there are probably too many obstacles, I spent about 5 minutes making the layout for the game so it could definitely be improved. I'd like to add music but there's no way to play it with just the LD instruction, so it would have to be done with some ROM routine and things could get quite tricky. Not sure quite what you mean about reversing direction?
User avatar
djnzx48
Manic Miner
Posts: 730
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Crap Game: Snake but the only instruction is LD

Post by djnzx48 »

New version released here: snake.tap

This release adds variety with new levels every 50 points, adds cursor controls, decreases the game speed and adds a brilliant new loading screen courtesy of [mention]R-Tape[/mention]!
Image
User avatar
Ersh
Manic Miner
Posts: 480
Joined: Mon Nov 13, 2017 1:06 pm

Re: Crap Game: Snake but the only instruction is LD

Post by Ersh »

That's great! Ruddy brilliant screen by R-Tape, love the snake/logo and the background is just clever as hell. :)
User avatar
Joefish
Rick Dangerous
Posts: 2058
Joined: Tue Nov 14, 2017 10:26 am

Re: Crap Game: Snake but the only instruction is LD

Post by Joefish »

It's cheating, loading a screen like that. It should load a block of LDs that then draw the screen! :lol:
Post Reply