I'm trying to write a Space Invaders emulator to teach myself about writing emulators. I'm a professional programmer in the games industry and I've always been interested in emulators and fancied giving it a go.
I picked the Space Invaders cabinet because it seems extremely simple. I can theoretically just take existing 8080 or Z80 emulator code and just wire in the required functions to handle memory and whatnot.
Obviously, in future I'd like to do everything from scratch but as a start I thought I could knock up something like this in a couple of hours easily enough.
I'm using Marat Fayzullin's Z80 emulator code from
http://fms.komkon.org. I've got a 64k memory buffer of which only the first 32k should be being used (16k for the cab and then the mirrored 16k). I'm loading the roms (invaders.h, invaders.g, invaders.f and invaders.e in that order) into the first 8k of my buffer.
I'm not sure how to do the mirror exactly but at the minute I'm literally just mirroring the first 16k into the second 16k (i.e. 0xab, 0x12, 0xd4 ... 0xd4, 0x12, 0xab).
The problem I'm having immediately is that only the read memory function from the Z80 emulator code is being accessed. The write memory, read port and write port functions don't get called at all from the Z80 code.
I'm presuming that the Z80 code starts picking up instructions at address 0x00 (the first element in my memory buffer and the first byte read in from the roms) and just runs from there. The first address it tries to read from is 0x00, followed by 0x01, 0x02, 0x03, 0x04 and 0x05. This would result in the following byte values being accessed 0x00, 0x00, 0x00, 0xc3, 0xd4, 0x18. Now I'm not sure how the Z80 works which is why I'm posting on here but the seventh address it tries to read is 0xd418 which seems strange to me for two reasons. 1) because it's greater than the 32k of memory that the cabinet is supposed to have (16k and 16k mirrored) but the main reason I find it strange is because 0xd418 is the combined value of the last two returned values (from accessing addresses 0x04 and 0x05).
I'm not sure whether it's a bug in the Z80 code or, more likely, something I'm doing wrong or not understanding.
My foray into the world of emulation is only a couple of hours long so far but I'm already enjoying it and am hoping someone can point me in the right direction.