Page 1 of 4

Resetting Micro Machines

Posted: Mon Jan 23, 2017 7:17 pm
by zeroone
In Nintendulator and my emulator, if you reset Micro Machines, it crashes the CPU (it jumps to a bad location and executes a KIL instruction). But, I have yet to figure out why. It must be sensitive to initial memory values or the state of the CPU. Anyone have a clue on this one?

Re: Resetting Micro Machines

Posted: Mon Jan 23, 2017 8:14 pm
by tepples
Did you try to reset twice in a row?

I don't own a copy of Micro Machines, but I do own a copy of Bee 52, and I know that all Codemasters games share library code, such as the "happy face" ROM test and possibly the CHR codec. While testing the Codemasters logo screen for zeroone, I discovered that if I press Reset once, the power light turns off and stays off. If I press Reset again, it comes back up. Perhaps a Reset press at certain points in the program confuses the code that drives the CIC stun circuit.

Re: Resetting Micro Machines

Posted: Mon Jan 23, 2017 8:21 pm
by zeroone
tepples wrote:Did you try to reset twice in a row?

I don't own a copy of Micro Machines, but I do own a copy of Bee 52, and I know that all Codemasters games share library code, such as the "happy face" ROM test and possibly the CHR codec. While testing the Codemasters logo screen for zeroone, I discovered that if I press Reset once, the power light turns off and stays off. If I press Reset again, it comes back up. Perhaps a Reset press at certain points in the program confuses the code that drives the CIC stun circuit.
It's a bit difficult to reset a crashed CPU in an emulator.

Re: Resetting Micro Machines

Posted: Mon Jan 23, 2017 10:25 pm
by tepples
Instead of choosing Emulation > Soft Reset (FCEUX SDL) or NES > Reset (FCEUX Windows) or Nintendulator's counterpart once, choose the menu item twice.

Re: Resetting Micro Machines

Posted: Tue Jan 24, 2017 8:30 am
by zeroone
tepples wrote:Instead of choosing Emulation > Soft Reset (FCEUX SDL) or NES > Reset (FCEUX Windows) or Nintendulator's counterpart once, choose the menu item twice.
I don't follow. Can you please clarify what you want me to try?

Re: Resetting Micro Machines

Posted: Tue Jan 24, 2017 8:48 am
by tepples
I want you to try a soft reset in your emulator, but try it twice in a row. If the first leads to a STP (also called KIL), the second may cause execution to continue.

Or am I misunderstanding what you meant by "a crashed CPU"? Is your emulator's core actually crashing? Or does a soft reset fail to pull it out of STP?

Re: Resetting Micro Machines

Posted: Tue Jan 24, 2017 8:55 am
by zeroone
tepples wrote:I want you to try a soft reset in your emulator, but try it twice in a row. If the first leads to a STP (also called KIL), the second may cause execution to continue.

Or am I misunderstanding what you meant by "a crashed CPU"? Is your emulator's core actually crashing? Or does a soft reset fail to pull it out of STP?
Ah. I understand now.

The second reset does pull it out of the halt state; however, it shortly thereafter executes the same KIL instruction that halted it on the first reset. Successive resets produce more halts.

Edit: For testing purposes, I modified my emulator to clear main memory and vram on reset, to reset all the mapper banks and to clear all the CPU registers and flags. And, the CPU still jams on reset! That's really strange. Some other state information is causing this.

Re: Resetting Micro Machines

Posted: Tue Jan 24, 2017 9:26 am
by thefox
Create a trace log from a power-on, then from a soft reset. See where they diverge.

Re: Resetting Micro Machines

Posted: Tue Jan 24, 2017 11:30 am
by zeroone
thefox wrote:Create a trace log from a power-on, then from a soft reset. See where they diverge.

Code: Select all

BFC8  CA        DEX                             A:0B X:B3 Y:01 P:A5 SP:FB CYC:302 SL:240 
BFC9  D0 FD     BNE $BFC8                       A:0B X:B3 Y:01 P:A5 SP:FB CYC:308 SL:240 
BFC8  CA        DEX                             A:0B X:B2 Y:01 P:A5 SP:FB CYC:317 SL:240 
BFC9  D0 FD     BNE $BFC8                       A:0B X:B2 Y:01 P:A5 SP:FB CYC:323 SL:240 
BFC8  CA        DEX                             A:0B X:B1 Y:01 P:A5 SP:FB CYC:332 SL:240 
BFC9  D0 FD     BNE $BFC8                       A:0B X:B1 Y:01 P:A5 SP:F8 CYC:338 SL:240 
0300  4C 1A FC  JMP $FC1A                       A:0B X:B1 Y:01 P:A5 SP:F8 CYC: 27 SL:241 
FC1A  A6 21     LDX $21 = FA                    A:0B X:FA Y:01 P:A5 SP:F8 CYC: 36 SL:241 
FC1C  9A        TXS                             A:0B X:FA Y:01 P:A5 SP:FA CYC: 45 SL:241 
FC1D  6C 03 03  JMP ($0303) = 9EC7              A:0B X:FA Y:01 P:A5 SP:FA CYC: 51 SL:241 
9EC7  33 99     RLA ($99),Y = 0000 @ 0001 = 78  A:01 X:FA Y:01 P:24 SP:FA CYC: 66 SL:241 
9EC9  CC E6 72  CPY $72E6 = 00                  A:01 X:FA Y:01 P:25 SP:FA CYC: 90 SL:241 
9ECC  90 3C     BCC $9F0A                       A:01 X:FA Y:01 P:25 SP:FA CYC:102 SL:241 
9ECE  18        CLC                             A:01 X:FA Y:01 P:24 SP:FA CYC:108 SL:241 
9ECF  00        BRK                             A:01 X:FA Y:01 P:24 SP:F7 CYC:114 SL:241 
FFFF  FF 00 F1  ISB $F100,X @ F1FA = 53         A:AC X:FA Y:01 P:A4 SP:F7 CYC:135 SL:241
The deviation happens at that spontaneous jump to $0300. From the SL, it coincides with NMI. Prior to the jump, it was in loop that was decrementing X to 0. I will keep investigating.

Edit:

The last bank in mapper 71 is fixed. Here is the NMI address:

Code: Select all

 0F:FFFA:00        BRK 
 0F:FFFB:03        UNDEFINED
NMI directs execution to code loaded into RAM.

Edit 2:

I can fix the problem by writing $00 to the PPU CTRL register ($2000) on reset, disabling NMI's. Should that be happening?

Re: Resetting Micro Machines

Posted: Tue Jan 24, 2017 11:51 am
by thefox
zeroone wrote:I can fix the problem by writing $00 to the PPU CTRL register ($2000) on reset, disabling NMI's. Should that be happening?
Yes on NES. No on Famicom (reset line is not connected to PPU).

http://wiki.nesdev.com/w/index.php/PPU_power_up_state

Re: Resetting Micro Machines

Posted: Tue Jan 24, 2017 2:38 pm
by rainwarrior
So Micro Machines has yet another way that it runs properly on an NES but not a Famicom! Interesting.

(The other way is reading $2004.)

Re: Resetting Micro Machines

Posted: Tue Jan 24, 2017 3:03 pm
by zeroone
rainwarrior wrote:So Micro Machines has yet another way that it runs properly on an NES but not a Famicom! Interesting.

(The other way is reading $2004.)
It sounds like it should also fail on reset for the NES-101. If anyone has the hardware, please confirm.

What is the reading $2004 issue?

Re: Resetting Micro Machines

Posted: Tue Jan 24, 2017 3:35 pm
by rainwarrior
$2004 isn't readable on a lot of Famicom units. Micro Machines polls it to time some raster effects.

Re: Resetting Micro Machines

Posted: Tue Jan 24, 2017 3:45 pm
by Zepper
zeroone wrote:I can fix the problem by writing $00 to the PPU CTRL register ($2000) on reset, disabling NMI's. Should that be happening?
The wiki says clearly to set $2000 to $00 on powerup and RESET in the NTSC version. Well, so the PPU state is different in a Famicom..???

Re: Resetting Micro Machines

Posted: Tue Jan 24, 2017 4:40 pm
by rainwarrior
Zepper wrote:
zeroone wrote:I can fix the problem by writing $00 to the PPU CTRL register ($2000) on reset, disabling NMI's. Should that be happening?
The wiki says clearly to set $2000 to $00 on powerup and RESET in the NTSC version. Well, so the PPU state is different in a Famicom..???
Indeed:
The wiki wrote:On top-loaders (Famicom, NES-101), the Reset button resets only the CPU.