What's new

Z80 emulator help needed??

TJA

New member
I'm currently programming a z80 emulator to be used in a gameboy emulator, but have become a little unsure how to implement one of the opcodes 0x3a.

In the gameboy manual it says:

LDD A,(HL)
Description:
Put value at address HL into A. Decrement HL.

And so I implemented it like this:

reg_A = read_mem(reg_HL);
reg_HL--;

I decided to test my progress by making a half arsed phoenix emulator.
and this is where I ran into trouble, on checking othe emulators from the gameboy thread in this fourm it seems this is how they too have implemented it in this way, It seems to work if I change the opcode to simply:

reg_PC+=2; ( reg_PC being the program counter)

I know that phoenix uses the 8080 not z80 but It runs fine on other open source z80 emus, and it apears they do not implement this opcode as described in the gameboy document either. Although I cant seem to figure exactly how it is the have done it as there source code is somewhat cryptic.

Any help or comments on this opcode whould be greatly appreciated.

Cheers, TJA
 

ShizZy

Emulator Developer
reg_A = read_mem(reg_HL);
reg_HL--;

is correct. Your bug is elsewhere. Just double checked my source to see how I did it.
 
OP
T

TJA

New member
Does your emulator work fully correctly?? Because I checked some other Z80 documents I have and they define 3A as:
LD A,(nn) Load accumulator with location nn.
This explans why PC+=2; worked ( although not fully correct )

On further look at the Z80 emu from Marat Fayzullin this seems to be how he has implemented it too.

Also LDD as 3A is called in the gameboy doc is actually:
LDD Load location (DE) with location (HL), decrement
which is opcode ED A8.

This leads me to assume that the processor used in the gameboy is not a true Z80 processor is this correct?? and therefore testing my cpu with any other system will not work, which is a shame. As I had planned to use my cpu unchanged in other projects.
Oh well at least this means that there are not acctually bugs in other areas of my code.

Cheers, TJA
 

Cyberman

Moderator
Moderator
TJA yes the processor in the GB was a Sharp produced unit that is NOT a Z80 at all. It has some instructions removed or implemented differently than the Z80. For example there are no IX or IY registers and there are no A'-F' registers either (Register mirror for fast handling of interrupts). This means 2 prefix instructions are missing (IX/IY variants of HL pair usage). Also it means it has no support for IO ports (0-255 on Z80) as well as no support for the R register (Refresh).
The added some instructions such as the index HL addressing with auto increment or decrement. The block copy instructions do not exist as well.

Cyb
 
OP
T

TJA

New member
Thanks cyberman. Do you know of any document that lists the differences in opcodes between these processors so that I may do a quick sweep of those opcodes to make sure I have done them correct and also so that I may change them later on so I have a z80 emulator without starting from scratch. Or checking every opcode.

Cheers, TJA.
 

Top