Masken, "fullscreen" snake game in 1k

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
abacaxi
Posts: 17
Joined: Thu Dec 05, 2024 8:20 pm

Masken, "fullscreen" snake game in 1k

Post by abacaxi »

So, as promised here's my 30x20 characters (28x17 play area) almost fullscreen snake in 1k implementation. As in my "masken" game on the palmpilot, gameboy and javascript from ca '97 the controls are just left and right (N and M on the keyboard), more fun that way imo, and the snake grows over time whether you eat something or not.

I'm using O, C, Q and G for the segments to track the tail so no extra memory is necessary, which is the key to the small size. The actual game loop is highly optimized but I could probably get a few more lines by optimizing the "support" routines. The rnd function is 24 bytes, I guess a sys call could work but I've no idea how to make those, and the initialization of the field can probably be done slightly more efficient. There's possibly a print function in rom for the score? I'm currently spending 24 bytes putting a three digit number on the screen. Together i'm sure I could fit two more columns. I'm also trying to figure out how to move the "game over" text to $4000 on load, another nine bytes that can be used as screen memory.

This is so much fun. I've done some stuff on the spectrum but that usually means counting t-states rather than bytes.
Attachments
zxmaskentest.P
(988 Bytes) Downloaded 189 times
abacaxi
Posts: 17
Joined: Thu Dec 05, 2024 8:20 pm

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

Post by abacaxi »

ok I made the score printing shorter so now it's 32x20, new version attached. any code you'd like to look at?
Attachments
zxmaskentest.P
(998 Bytes) Downloaded 796 times
David G
Posts: 632
Joined: Thu Jul 17, 2014 7:58 am
Location: 48 North

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

Post by David G »

Neither of them load in 1K for me. The file size is 998 bytes ... but it does run with 16K
abacaxi
Posts: 17
Joined: Thu Dec 05, 2024 8:20 pm

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

Post by abacaxi »

damn, I really don't understand how to make my emulator, zxsp, set the SP correctly. So 980 or so is the max size i guess? i did a couple of tiny optimizations and removed one column so now it's 942 bytes.
Attachments
zxmaskentest.P
(942 Bytes) Downloaded 763 times
David G
Posts: 632
Joined: Thu Jul 17, 2014 7:58 am
Location: 48 North

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

Post by David G »

Yes, that one is working on my 1K. Not sure on the max size, it probably depend on the program's use of stack
David G
Posts: 632
Joined: Thu Jul 17, 2014 7:58 am
Location: 48 North

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

Post by David G »

The code is much cleaner now

The only things I can see for saving bytes:
* extra E9 byte just before 80MARK/lastbyte
* The subroutine at 40FB is only called once, so in-lining it will save four bytes
* Change "GAME OVER" TO "END" and move the code down to fill that space

But that's only 11 bytes saved. Is it enough for the extra row?
abacaxi
Posts: 17
Joined: Thu Dec 05, 2024 8:20 pm

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

Post by abacaxi »

Great suggestions, it's 32x20 again by using end instead of game over and removed the word score, inlining the pseudo rnd function that was indeed only called once plus some further optimizations. 948 bytes. As for the extra E9 that's the "jp (hl)" i took from beep's code?

I've also included my source code this time for better, maybe, readability.
Attachments
zxmaskentest.asm
(8.8 KiB) Downloaded 175 times
zxmaskentest.P
(948 Bytes) Downloaded 148 times
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 »

Compress the screen and copy some code over the sysvar and decompress screen.
This can give you not only around 50 bytes of code but you can make more lines since the loaded code will be shorter.
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 »

So I played a round.

Nice trick to use left and right only although it is likely more in code than just left/right/up/down since you need to do a relative move depending
the current drection.

The direction of the tail stored in OGCQ is done before and is working. It however shows a changing snake.
When you invert the display you indicate the size of the screen with inverted spaces and you can add the drawn border to the playingfield.
It also allows you to hide the tail with hidden opcodes and you see a perfect snake.

My version of SNAKEBINGO has extra gameplay where you need to get items in order.
Without that extra code you can get a full screen version.
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 »

David G wrote: Sun Dec 08, 2024 8:13 am Yes, that one is working on my 1K. Not sure on the max size, it probably depend on the program's use of stack
Max size is 949 which will always load. Larger can give errors.
Post Reply