nesdev.com
http://forums.nesdev.com/

Space Invaders arcade emulation
http://forums.nesdev.com/viewtopic.php?f=23&t=14953
Page 1 of 1

Author:  DarkMoe [ Mon Oct 17, 2016 3:15 pm ]
Post subject:  Space Invaders arcade emulation

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,

Author:  mic_ [ Mon Oct 17, 2016 11:24 pm ]
Post subject:  Re: Space Invaders arcade emulation

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.

Author:  DarkMoe [ Tue Oct 18, 2016 5:28 am ]
Post subject:  Re: Space Invaders arcade emulation

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.

Author:  mic_ [ Tue Oct 18, 2016 6:44 am ]
Post subject:  Re: Space Invaders arcade emulation

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?

Author:  DarkMoe [ Tue Oct 18, 2016 7:25 am ]
Post subject:  Re: Space Invaders arcade emulation

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).

Author:  mic_ [ Tue Oct 18, 2016 8:36 am ]
Post subject:  Re: Space Invaders arcade emulation

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).

Author:  DarkMoe [ Tue Oct 18, 2016 11:32 am ]
Post subject:  Re: Space Invaders arcade emulation

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 =(

Author:  mic_ [ Tue Oct 18, 2016 12:21 pm ]
Post subject:  Re: Space Invaders arcade emulation

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)

Author:  DarkMoe [ Tue Oct 18, 2016 1:04 pm ]
Post subject:  Re: Space Invaders arcade emulation

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

Author:  lidnariq [ Tue Oct 18, 2016 1:19 pm ]
Post subject:  Re: Space Invaders arcade emulation

Should be easy enough to use MAME's debugger to figure out which, right?

Author:  DarkMoe [ Tue Oct 18, 2016 1:41 pm ]
Post subject:  Re: Space Invaders arcade emulation

Ive used MAME for 17 years, and never used the debugger, shame on me.

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

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/