Space Invaders arcade emulation

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Space Invaders arcade emulation
by on (#180951)
Hi !

I started for fun, a SI emulator, and got stuck at probably one stupid cpu, or flags bug.

I have working inputs, the game boots perfectly, shift registers are emulated, but when all the aliens are shown, the game makes a jump HL() instruction to what was on the stack, which is 0000, and resets itself obviously.

Here's the complete disassembled code:
http://www.computerarcheology.com/Arcad ... /Code.html

The problem happens at PC: 0550
HL is set to 0x2073, then the copy block function is called, which copies 2073 and 2074 with 00, and those 00 are later feeding the HL register from stack, and making that invalid jump.

Any idea of what is going on ? I know is hard to find the problem, but I've seen it in other forums (with no replies).

Thanks,
Re: Space Invaders arcade emulation
by on (#180977)
Where is the JP (HL)?

Quote:
copies 2073 and 2074 with 00, and those 00 are later feeding the HL register from stack

That doesn't sound right. According to that page, the stack is located at $2300-$23FF.
Re: Space Invaders arcade emulation
by on (#180982)
026E: E9 JP (HL) ; Run object's code (will return to next line)

That's the line .. they were doing some sort of smart code there calling different functions while injecting manually the return vector to the stack.
Re: Space Invaders arcade emulation
by on (#180983)
Well, based on that page, SP should never be in the $20xx range, so "copies 2073 and 2074 with 00, and those 00 are later feeding the HL register from stack" should not be possible. Have you perhaps implemented EX (SP),HL as EX SP,HL by mistake?
Re: Space Invaders arcade emulation
by on (#180984)
I have those instructions correct, what is happening is this:

0262: 23 INC HL ; xx03
0263: 5E LD E,(HL) ; Get handler address LSB
0264: 23 INC HL ; xx04
0265: 56 LD D,(HL) ; Get handler address MSB

When PC is 0x262, HL = 0x2072, gets incremented to 0x2073, which previously was loaded with memory value held at 0x2055 (which is 0), same with 0x2074 (read value from 0x2056). Then DE is exchanged to HL, so now HL = 0000 .. then eventually HL gets loaded with value from stack, and Jump (HL) is jump to 0000, which resets the game.

This happens exactly when the last alien is drawn (either on demo mode, or playing).
Re: Space Invaders arcade emulation
by on (#180986)
Based on the comments it seems like HL shouldn't be 0x2072 at that point. Perhaps you can work backwards from there to see how L got the value 0x72 rather than 0x02 (which the comments imply is the correct value).
Re: Space Invaders arcade emulation
by on (#180994)
I think those comments are not quite right, since the first line of that function sets HL = 0x2010

I think every 0x10 bytes, theres a different object and the code is looping all of them, jumping to their respective handlers to handle logic, and then returning.

For some reason, Im getting handler 0000 for a game object, still cant fix this stupid bug =(
Re: Space Invaders arcade emulation
by on (#181000)
The "RAM use" page lists 5 game objects, located at 0x201x-0x205x.

0x2073 and 0x2074 are supposedly used for:

Code:
aShotStatus   Bit 0 set if shot is blowing up, bit 7 set if active
aShotStepCnt   Count of steps made by shot (used for fire reload rate)
Re: Space Invaders arcade emulation
by on (#181004)
Ok fair enough.

I will keep checking .. it's getting very difficult to debug and find an issue.

I'm 80% certain that there's an issue with the flags.

In some documents I read that the sign flag is set if there's a substract operation and clear if it's a sum. Others say that sign flag is set to the most significant bit of the result (bit 7).

Not sure what to make of that
Re: Space Invaders arcade emulation
by on (#181007)
Should be easy enough to use MAME's debugger to figure out which, right?
Re: Space Invaders arcade emulation
by on (#181011)
Ive used MAME for 17 years, and never used the debugger, shame on me.

I will check it out on the official site, thanks !