-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hookup emu-russia/dmgcpu #1
base: master
Are you sure you want to change the base?
Conversation
Hi Rodrigo, thank you very much for sharing your work. I want to look into this, and I just realized that I had fixed two small bugs in my working directory that I hadn't committed yet. I just committed them now, so maybe you want to rebase your stuff to the new changes on master. At first glance, I'm very happy that you found a stupid mistake I made with the SERY inverter feeding itself. I still had graphical glitches when simulating Zelda DX. I will run a new simulation with this fix, maybe it helps. If you wouldn't mind, could you make a separate pull request for that SERY fix? I will merge that immediately. I will comment a bit more on this when I have more time and after I made a few tests myself. Thanks, |
was set to `sery = !sery` before.
Was need when trying to hook up emurussia/dmgcpu.
1413192
to
d424855
Compare
Okay, it looks to me, that the CPU is misbehaving. It raises the What we can see is that I removed this port from the CPU instantiation:
Then I added these two lines somewhere above or below the CPU instantiation:
In a hackish way, this ensures that I noticed that you added the timescale directive everywhere. This isn't necessary in Icarus. I configured the timescale in the timescale.f file. It is given to Icarus at command line. But maybe you need this for Verilator, idk. I don't even know which one Icarus uses if both are given. I hope this hack helps you to continue with your research. I don't know where exactly the issue is. I'm planning to do my own implementation of the CPU, but first I want to finish the CPU layout that I'm recreating in Electric VLSI. I'm working on that for a while now and it is very frustrating, because it seems that I can't get the proportions right while simultaneously obeying the spacing rules of the MOSIS fabrication technology that I've selected for the project. It's good to know that someone finds this stuff useful. I think @ogamespec will be also happy that you are using his CPU. If he's not reacting here, then maybe you could also write him an issue on his project, just to let him know at least. |
I just noticed, something else is not working correctly. The conditional jump instruction at address 0x000a at the beginning of the bootrom is failing somehow and the CPU restarts executing at address 0 over and over again.
|
Thank you! So it is exactly what I had first suspected. I tried looking at the CPU sequencer netlist trace to see if there was anything obviously wrong, but I had no confidence I would figure out something. I will start using your hack.
I will make an issue there, at least to make things more cross-referenced.
I will take a look at that. I had my emulator emitting VCD traces, so it is easier to spot where an error is first introduced. Again, thank you for the help! |
Glad I could help. Let me know if there is any progress. |
Hi, I've read what's been written here, but for the most part it's all outside the SM83 Core, and that's not my "expertise" there (it's already been studied by others and I don't go there).
That is, 1 simulation step is equal to 1 ns, but I made the CLK transit longer, so that the circuits had time to "settle". |
Updated the With emu-russia/dmgcpu#219 fixed, the CPU now starts running instructions. I am testing the execution in |
Fix check of conditional flags. See emu-russia/dmgcpu#266.
The delays in the CLK6 is not necessary anymore. A transparent DLatch was added to the condtional branch logic (as the original hardware has), avoiding the need of the delays.
Hello! For some weeks now, I have been investigating if I could use the Verilog simulation in this repo to better understand the inner workings of the Game Boy and in some way improve the precision of my Game Boy emulator.
The main point that I want to investigate was the inner work of the PPU, and the precise read/write timing between the CPU and the PPU. But, as far as I know, you are using only an equivalent CPU implementation, not a reverse-engineered CPU from the Game Boy. This made me a little hesitant in learning its timing, knowing it may still be off.
But I discovered that there is a reverse-engineered HDL of the CPU core at https://github.com/emu-russia/dmgcpu, and I decided to try hooking it up with the simulation in this repo.
Connecting the two together went almost painless. But I could not get it to work; the CPU never starts running after the circuit RESET.
I tried investigating where things were going wrong, but I still could not figure it out (my investigation is resumed in
notes.txt
, copied in the section below), and I am not experienced in debugging Verilog. I could investigate a little more, but I presume there will be many more problems after fixing this one, so I became a little demotivated.Regardless, I decided to publish my work here to not make it all go to waste.
Investigation
The address bus of the CPU, when running in dmg-sim, never increments, whereas the simulation in dmgcpu does.
The signal
d
of the Sequencer never changes from 0x00..04000 to 0x00402..00, like the simulation indmgcpu
does.The following inputs to the CPU differ from the simulation in dmgcpu:
OSC_STABLE
becomes high whenUPOF
(last bit ofDIV
, 16Hz) is high, andTUBO
, a latch for theCLK_ENA
signal from the CPU, becomes low. In dmgcpu,UPOF
is hardcoded to be high.OSC_STABLE = T1&~T2 | ~T1&T2 | UPOF&~TUBO
TUBO = nor_latch(.set(CLK_ENA), .reset(RESET | ~OSC_ENA))
OSC_STABLE
feeds theSYNC_RESET
(CPU T12), which becomes locked low inASOL
latch. This made me think thatCLK_ENA
should only go high afterSYNC_RESET
is low.Looking at Seq.v (see logic.py),
CLK_ENA
is low whenRESET
is high, or if the CPU halted:~(d[100] | IR[4] & d[101]) | SeqControl_1
~(d[100] | IR[4] & d[101])
From
_GekkioNames.v
:So
CLK_ENA
is almost unaffected bySYNC_RESET
.Another way to make
OSC_STABLE
go high is to ensure to only reset whenUPOF
is high. ButUPOF
does not run untilRESET
is low! And the CPURESET
is directly connected to the global simulation RESET!Maybe
UPOF
should be reset high? Probably not, it may mess up with theDIV
timing, and the simulation is too slow to make guessed changes.UPOF
is reset byRESET_DIV
:~RESET_DIV = ~(RESET | ~OSC_STABLE | (FF04_FF07 & CPU_WR & ~A1 & ~A2))
.RESET_DIV = RESET | ~OSC_STABLE | <write to DIV>
ASOL
is reset byRESET
.