Space Invaders arcade emulation

Discussion of development of software for any "obsolete" computer or video game system.
Post Reply
DarkMoe
Posts: 70
Joined: Sat Jun 27, 2015 1:09 pm

Space Invaders arcade emulation

Post by DarkMoe » Mon Oct 17, 2016 3:15 pm

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,

mic_
Posts: 917
Joined: Thu Oct 05, 2006 6:29 am

Re: Space Invaders arcade emulation

Post by mic_ » Mon Oct 17, 2016 11:24 pm

Where is the JP (HL)?
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.

DarkMoe
Posts: 70
Joined: Sat Jun 27, 2015 1:09 pm

Re: Space Invaders arcade emulation

Post by DarkMoe » Tue Oct 18, 2016 5:28 am

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.

mic_
Posts: 917
Joined: Thu Oct 05, 2006 6:29 am

Re: Space Invaders arcade emulation

Post by mic_ » Tue Oct 18, 2016 6:44 am

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?

DarkMoe
Posts: 70
Joined: Sat Jun 27, 2015 1:09 pm

Re: Space Invaders arcade emulation

Post by DarkMoe » Tue Oct 18, 2016 7:25 am

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

mic_
Posts: 917
Joined: Thu Oct 05, 2006 6:29 am

Re: Space Invaders arcade emulation

Post by mic_ » Tue Oct 18, 2016 8:36 am

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

DarkMoe
Posts: 70
Joined: Sat Jun 27, 2015 1:09 pm

Re: Space Invaders arcade emulation

Post by DarkMoe » Tue Oct 18, 2016 11:32 am

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

mic_
Posts: 917
Joined: Thu Oct 05, 2006 6:29 am

Re: Space Invaders arcade emulation

Post by mic_ » Tue Oct 18, 2016 12:21 pm

The "RAM use" page lists 5 game objects, located at 0x201x-0x205x.

0x2073 and 0x2074 are supposedly used for:

Code: Select all

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)

DarkMoe
Posts: 70
Joined: Sat Jun 27, 2015 1:09 pm

Re: Space Invaders arcade emulation

Post by DarkMoe » Tue Oct 18, 2016 1:04 pm

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

lidnariq
Posts: 8780
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Space Invaders arcade emulation

Post by lidnariq » Tue Oct 18, 2016 1:19 pm

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

DarkMoe
Posts: 70
Joined: Sat Jun 27, 2015 1:09 pm

Re: Space Invaders arcade emulation

Post by DarkMoe » Tue Oct 18, 2016 1:41 pm

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

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

Post Reply