WIP: Tetris + any GCL tips?

Using, learning, programming and modding the Gigatron and anything related.
Forum rules
Be nice. No drama.
User avatar
marcelk
Posts: 488
Joined: 13 May 2018, 08:26

Re: WIP: Tetris + any GCL tips?

Post by marcelk »

After loading the start address into vLR, can't you just RET?
Yes :D

Code: Select all

0x5b, 0x86, 0x06, // Patch segment, 6 bytes at $5b86
0x11, 0x00, 0x02, // LDWI $0200
0x2b, 0x1a,       // STW  vLR
0xff,             // RET
0x00, 0x5b, 0x86, // Execute: run patch first
What if the loader writes the start address minus 2 and the start address minus nothing to the vPC and vLR in page 0, and not send the start command. Wouldn't the return from the sys call jump to the start address?
I don't believe that would work. Loader is a vCPU application, so it uses vPC. Only two small critical parts are native code. Also, any zero-page segment has to be the first in the file. A workaround is then to write 4 bytes into page $80 with the last segment, but that breaks on 64K systems. But maybe I overlook something again.
I worked around this by padding all pages out with zeros, so I guess it would consistently execute harmless code - for me, this gives consistent behaviour on hardware and emulators, but could issues still arise doing this? I've not seen any bad loads doing this yet.
If it works it is entirely accidental, but possibly reliable. The video loop is continuously modifying the sound channel variables at the end of page 1-4, so there is a potential race condition. And letting the vCPU jump to offset 0 in its page will almost certainly cause a small timing glitch on the /HS video signal. Not all VGA monitors will keep sync. The newer ones are quite unforgiving.
The patching method is a bit of a shame as memory is already very limited, but I guess it's just a few bytes
It is in a useless RAM area so it doesn't eat from your real program. I tucked it away behind the load buffer. The entire Loader is running within screen area. The 3 lines below the "Ready to load" text are:
  1. Activity indicator (red for mismatched checksum, green for good checksum, white as some kind of cursor)
  2. vCPU code for the Loader's inner loop
  3. 60 byte buffer
Cwiiis
Posts: 27
Joined: 14 May 2018, 09:04

Re: WIP: Tetris + any GCL tips?

Post by Cwiiis »

marcelk wrote: 16 May 2018, 09:08 It is in a useless RAM area so it doesn't eat from your real program. I tucked it away behind the load buffer. The entire Loader is running within screen area.
Oh of course, very clever :)
User avatar
marcelk
Posts: 488
Joined: 13 May 2018, 08:26

Re: WIP: Tetris + any GCL tips?

Post by marcelk »

Core/compilegcl.py now injects this patch into the GT1 files it creates. I generated a couple of them, and they work fine. I checked them into GitHub as well for now.

Code: Select all

marcelk@mbook-3:~/Projects/Gigatron-1/Design/theloop> Core/compilegcl.py Apps/HelloWorld.gcl theloop.sym 
Compiling file Apps/HelloWorld.gcl label Main
 Segment at 0200 size 250 used 214 unused  36
 Variables count 12 bytes 24 end 0048
 Symbols BgColor Char ClearScreen Color Pos PrintChar PrintText StringHelloWorld
 Symbols Text fontData i p
Success ROM 0000-00da

Create file HelloWorld.gt1
marcelk@mbook-3:~/Projects/Gigatron-1/Design/theloop> 
You can see the patch (not needed for this program BTW):

Code: Select all

marcelk@mbook-3:~/Projects/Gigatron-1/Design/theloop> hd < HelloWorld.gt1 | tail -5
000000b0  44 cd ba 48 65 6c 6c 6f  20 57 6f 72 6c 64 00 2b  |D..Hello World.+|
000000c0  46 59 3f 2b 3e 59 00 2b  36 11 00 08 cf 38 11 00  |FY?+>Y.+6....8..|
000000d0  08 2b 30 21 46 cf 44 90  d2 5b 86 06 11 00 02 2b  |.+0!F.D..[.....+|
000000e0  1a ff 00 5b 86              ^^^^^^^^^^^^^^^^^^^^  |...[.|
000000e5. ^^^^^^^^^^^^^^
marcelk@mbook-3:~/Projects/Gigatron-1/Design/theloop> 
On my Mac I use the LoaderTest/sendGt1.py script to send these files into the board. This script needs a bit of tweaking for Linux and Windows to know what USB port to start talking to. This script takes care of the flow control between PC and Arduino. The PROGMEM route still works as well of course.

Code: Select all

marcelk@mbook-3:~/Projects/Gigatron-1/Design/theloop> LoaderTest/sendGt1.py HelloWorld.gt1 
Connecting to /dev/tty.usbmodem1411
Reseting Gigatron
Starting Loader
Sending program 'HelloWorld.gt1'
.....
Finished
I also refactored Core/asm.py slightly so that the (semi-)standalone GCL compiler doesn't generate spurious files any longer. A step in the right overall direction.
Cwiiis
Posts: 27
Joined: 14 May 2018, 09:04

Re: WIP: Tetris + any GCL tips?

Post by Cwiiis »

marcelk wrote: 16 May 2018, 21:44 Core/compilegcl.py now injects this patch into the GT1 files it creates. I generated a couple of them, and they work fine. I checked them into GitHub as well for now.

I also refactored Core/asm.py slightly so that the (semi-)standalone GCL compiler doesn't generate spurious files any longer. A step in the right overall direction.
Just tested this out and I can remove all my Loader hacks now, great stuff!
Cwiiis
Posts: 27
Joined: 14 May 2018, 09:04

Re: WIP: Tetris + any GCL tips?

Post by Cwiiis »

The same Dropbox link as before: https://www.dropbox.com/s/oshibfempa9d3 ... s.gt1?dl=0, I've gotten to what I now consider to be an alpha state - the game is entirely playable, has scoring, level progression, line count, next-piece display, etc. I think a couple of the pieces need tweaking to match the NES version (which is what I'm aiming for), but that's just polish.

Sound is still entirely missing, as is high-score tracking - I'm actually getting pretty low on space, it's looking like music may not be feasible, but I'll have to see... If I packed the graphics better, I could probably free up quite a few after-screen pages so it's more of a question of how much patience I have at this point :)

I could probably save myself a lot of time by working on the compiler to do things like automatic arrangement of functions in RAM to make best use of available space... (and to add things like labels and macros) Definitely upgrading to 64k RAM is a worthwhile thing to do if you're developing games, it's by far the biggest challenge as far as I can see (fitting everything into small pages).

For a v2 ROM, an 8-bit vCPU with a couple of 16-bit functions would be quite interesting, mainly to make better use of RAM. Though I try to take advantage of some of the 16-bit functions, it's pretty much all to save space that I wouldn't need to do on an 8-bit system.
User avatar
marcelk
Posts: 488
Joined: 13 May 2018, 08:26

Re: WIP: Tetris + any GCL tips?

Post by marcelk »

Works for me! I've also sped up the USB loader by bumping up the baud rate and removing some stupidity. It now takes 12.5 seconds to send a reset, start the loader, push Gigatris.gt1 into the board and start execution.

Today my 10.1 inch LCD monitor arrived from Amazon. It goes well with one of the mini PS/2-keyboards I found on our local variant of Craigslist.

IMG_3313.jpg
IMG_3313.jpg (519.94 KiB) Viewed 6677 times

Here you see me playing Gigatris using the arrows on the keyboard. I included the keyboard handling from Terminal.ino and mapped the cursor keys to game controller codes. Snake is playable this way. Racer is not playable because there you need to push down the [A] button and that is not well-handled by the Arduino.

From here I think the next step (for me) should be a monitor program, so you can inspect memory locations and modify them. Plenty of time after Belgrade...

P.S.: There are some quirks in Gigatris, but I won't bother you until you declare it "beta".
Cwiiis
Posts: 27
Joined: 14 May 2018, 09:04

Re: WIP: Tetris + any GCL tips?

Post by Cwiiis »

marcelk wrote: 18 May 2018, 22:58 Works for me! I've also sped up the USB loader by bumping up the baud rate and removing some stupidity. It now takes 12.5 seconds to send a reset, start the loader, push Gigatris.gt1 into the board and start execution.

Today my 10.1 inch LCD monitor arrived from Amazon. It goes well with one of the mini PS/2-keyboards I found on our local variant of Craigslist.


IMG_3313.jpg


Here you see me playing Gigatris using the arrows on the keyboard. I included the keyboard handling from Terminal.ino and mapped the cursor keys to game controller codes. Snake is playable this way. Racer is not playable because there you need to push down the [A] button and that is not well-handled by the Arduino.

From here I think the next step (for me) should be a monitor program, so you can inspect memory locations and modify them. Plenty of time after Belgrade...

P.S.: There are some quirks in Gigatris, but I won't bother you until you declare it "beta".
Glad to see it working, and cool to hear about the progress with keyboards - I wonder how long until someone writes a BASIC interpreter...

Re quirks, I'm definitely still interested in hearing about any you find - some may be intentional, but it's more likely that they aren't :)
User avatar
marcelk
Posts: 488
Joined: 13 May 2018, 08:26

Re: WIP: Tetris + any GCL tips?

Post by marcelk »

Just some things that caught my attention just because I remember them differently (my memories are worthless, so don't worry):
  1. The bricks don't stay at their position when rotating repeatedly. They start to travel right to left.
  2. Dropping a brick is slow. I expected them to fall quickly once telling them to drop
  3. The bricks won't turn when near the wall. I don't remember what the other clones do here.
Cwiiis
Posts: 27
Joined: 14 May 2018, 09:04

Re: WIP: Tetris + any GCL tips?

Post by Cwiiis »

marcelk wrote: 20 May 2018, 19:52 Just some things that caught my attention just because I remember them differently (my memories are worthless, so don't worry):
  1. The bricks don't stay at their position when rotating repeatedly. They start to travel right to left.
  2. Dropping a brick is slow. I expected them to fall quickly once telling them to drop
  3. The bricks won't turn when near the wall. I don't remember what the other clones do here.
  1. This shouldn't happen, I'll double-check, but there are some pieces that aren't defined quite right so the rotations feel 'off' - on my TODO list to fix
  2. As in instant-drop? I'm going for NES-style atm, instant drop wouldn't be too hard to add by pressing up though... Tempting, but I think I'll concentrate on other polish areas first.
  3. This is what NES Tetris does - blocks can only move if the move would be valid (same for spins - newer Tetrises, like Puyo Puyo Tetris, allow for spins based on some weird 'physics' model that allows for what ought to be impossible spins... I'm not a fan, so sticking with NES-style :))
Good to hear there's nothing too drastic/that I wasn't already aware of, hopefully I can polish it up a bit more and it'll feel better :) I'd really like to include a starting level select and high-score entry screen, will have to see what I can do about packing things in RAM better... I've ordered a replacement SRAM chip to upgrade to 64k, it's quite tempting to program a 64k version where I can go all out, but I like that this will run on a stock Gigatron. We're already in an extreme niche, seems silly to divide it even further!
Marko
Posts: 8
Joined: 24 May 2018, 19:48

Re: WIP: Tetris + any GCL tips?

Post by Marko »

Image

Working for me too :) I just swapped the Arduino plug out for the game controller.

Really nice!
Post Reply