Gigatron Clone Ideas

Using, learning, programming and modding the Gigatron and anything related.
Forum rules
Be nice. No drama.
bmwtcu
Posts: 145
Joined: 01 Nov 2018, 12:02

Re: Gigatron Clone Ideas

Post by bmwtcu »

Sounds consistent with the two known failures we've been talking about.
alastair
Posts: 68
Joined: 10 Oct 2019, 14:28

Re: Gigatron Clone Ideas

Post by alastair »

I was close, but it is the last jump in the image trampoline page. E.g.

Code: Select all

              0dfd 1406  ld   $06,y
              0dfe fe00  bra  ac
              0dff e0bc  jmp  y,$bc
The issue here is the trampoline returns at the end of the page. That causes the program counter to increment the page when it dispatches the trampoline instruction. It hits the page above causing the pixel displacement. It starts to do Jupiter and things work until it trampolines to a jump or branch instruction in the page above. That's when it gets stuck.

This is an artifact of the design, not necessarily a bug. The fix would be to back off the picture trampoline code so that return jump doesn't happen at the end of the page. There is room to do this since that code is padded with a NOP or two to fit at the end. The assembler could check for this condition and raise an error. It only appears in the image trampoline pages prior to ROM5.
alastair
Posts: 68
Joined: 10 Oct 2019, 14:28

Re: Gigatron Clone Ideas

Post by alastair »

fixed.jpg
fixed.jpg (165.18 KiB) Viewed 1240 times
I updated ROMv3 with this fix. I can't create a PR, but this is the diff:

Code: Select all

--- a/Core/ROMv3.asm.py
+++ b/Core/ROMv3.asm.py
@@ -2241,11 +2241,11 @@ def trampoline3a():
   ld([sysArgs+6])               #22
   adda(1)                       #23
   bra(AC)                       #24
-  bra(250)                      #25 trampoline3b
+  bra(256-7)                    #25 trampoline3b
 
 def trampoline3b():
   """Read 3 bytes from ROM page (continue)"""
-  while pc()&255 < 256-6:
+  while pc()&255 < 256-7:
     nop()
   st([sysArgs+1])               #27
   C('Trampoline for page $%02x00 reading (continue)' % (pc()>>8))
@@ -2254,6 +2254,8 @@ def trampoline3b():
   ld(hi('txReturn'), Y)         #30
   bra(AC)                       #31
   jmp(Y,'txReturn')             #32
+  nop()
+  C('Avoid end of page return at $%04x' % (pc()-1))
The image pages are updated as follows:

Code: Select all

--- a/ROMv3.lst
+++ b/ROMv3.lst
@@ -3078,7 +3078,7 @@ packedParrot: 0d00 0000  ld   $00         ;Pixels for packedParrot line 0
               0d7c 012a  ld   [$2a]
               0d7d 8001  adda $01
               0d7e fe00  bra  ac
-              0d7f fcfa  bra  $0dfa
+              0d7f fcf9  bra  $0df9
               0d80 0000  ld   $00         ;Pixels for packedParrot line 1
               0d81 0000  ld   $00
               0d82 0000  ld   $00
@@ -3173,13 +3173,13 @@ packedParrot: 0d00 0000  ld   $00         ;Pixels for packedParrot line 0
               0df6 0005  ld   $05
               0df7 0000  ld   $00
               0df8 0200  nop
-              0df9 0200  nop
-              0dfa c225  st   [$25]       ;Trampoline for page $0d00 reading (continue)
-              0dfb 012a  ld   [$2a]
-              0dfc 8002  adda $02
-              0dfd 1406  ld   $06,y
-              0dfe fe00  bra  ac
-              0dff e0bc  jmp  y,$bc
+              0df9 c225  st   [$25]       ;Trampoline for page $0d00 reading (continue)
+              0dfa 012a  ld   [$2a]
+              0dfb 8002  adda $02
+              0dfc 1406  ld   $06,y
+              0dfd fe00  bra  ac
+              0dfe e0bc  jmp  y,$bc
+              0dff 0200  nop              ;Avoid end of page return at $0dff
               0e00 0000  ld   $00         ;Pixels for packedParrot line 2
               0e01 0000  ld   $00
               0e02 0000  ld   $00

at67
Site Admin
Posts: 647
Joined: 14 May 2018, 08:29

Re: Gigatron Clone Ideas

Post by at67 »

OK, I've had a better look at this, single stepping native code on ROMv4 in both SW emulation and on real Gigatron hardware and I can't see an issue at all with the original code or the original circuit timing.

If I had to guess, there seems to be a race condition between the JMP instruction and incrementing PC into the next page for both the original FPGA design and yours.

Right now without more information, I don't think your change to the trampoline is a valid one; of course I am only speculating here based on the experiments I have just performed, so please feel free to correct me.

Spitballing: It seems that your HW is overwriting the currently fetched trampoline pixel with the first LD instruction in the next page and for the last scanline of Jupiter the X register is being corrupted from the first instruction of SYS_RacerUpdateVideoX_40.

Can you single step the native code on your HW? That might be an interesting experiment.
alastair
Posts: 68
Joined: 10 Oct 2019, 14:28

Re: Gigatron Clone Ideas

Post by alastair »

Thanks for taking a look @at67. I was actually thinking how you could "fix" this issue by connecting ~PL to the CEP input of the upper two counters. I took a closer look at the Gigatron schematic and this is exactly what Marcel has done {insert facepalm}. Yes, I totally missed that when I transcribed the schematic. I guess the FPGA design did the same thing :lol:

For reference, this is what was happening.

Code: Select all

ROM		IR
----		----
0DFF		bra ac		;AC=XX
				;—clk— PC low=XX, PC high increments (U4 TC is high)
0EXX		jmp y		;same code but jumped to wrong page
				;—clk— PC low=$BC, PC high=Y ($06)
06BC		ld d		;instruction loaded from wrong page
				;—clk— 
06BD		ld y		;back to SYS_Read3_40
I'll update my design to fix this when I get to the Rev.3 board.
bmwtcu
Posts: 145
Joined: 01 Nov 2018, 12:02

Re: Gigatron Clone Ideas

Post by bmwtcu »

Schweet! Fixed the FPGA code by adding if(cu_pl_n) to the PC increment. Tested on ROMv3/v4/vX0. (Love those DIP switches!)
at67
Site Admin
Posts: 647
Joined: 14 May 2018, 08:29

Re: Gigatron Clone Ideas

Post by at67 »

bmwtcu wrote: 30 Jun 2022, 01:29 Schweet! Fixed the FPGA code by adding if(cu_pl_n) to the PC increment. Tested on ROMv3/v4/vX0. (Love those DIP switches!)
Good job!

P.S. I have been switching between three ROM's with the press of one button since 2018 :P
https://forum.gigatron.io/viewtopic.php?p=172#p172
Post Reply