Hi, for a summer project I would like to write a Master System emulator, very simple system to emulate. Anyway I have started the Z-80 CPU emulation core, everything is going fine I got around 45~50 instructions implemented so far. I'm sure some of you who have coded the Z-80 remember the Half-Carry flag. On many operations the half carry flag is set when there is a borrow from bit 4. I was wondering if there is an x86 instruction that does something similar so I won't have to write the code to detect it myself.
Posted on 2003-05-01 21:19:12 by x86asm
I don't know about z80 but you can do this on x86 to test if bit 4 on a register is set or not
test eax, 10h

jnz __Bit4OfRegisterEAXisSet
or if you want to set bit 4 of a register
bts eax, 4
this one also copies bit 4 of register EAX to the carry flag(CF) :)
Posted on 2003-05-01 22:37:09 by arkane
Hi x86asm,

I programmed long time ago z80 (under MSX based system)

http://www.zophar.net/Files/cpu/makez80.zip This packet usefull and included z80 to 32bit asm (C code but nasm based) source code.

And other examples http://www.zophar.net/z80.html

I hope help you :)


Edit: "until" -->"under" (sorry my English)

Regards,
Posted on 2003-05-02 02:51:36 by CYDONIA
Hey x86, it was a project I wanted to do there is a long time : unfortunaly lacking of time to do it... :)

Btw, I know there is already good z80 libraries written... have a look at some emulators and emu-websites....

Also have a look at http://cgfm2.emuviews.com/segastuf.htm#sms : it has some useful docs : the Megadrive - Genesis was very useful to me some time ago when I did some programming on it !

I was around the emu-scene for a long time : at this time, there was a real need of a good sms emulator (Good old Meka doesn't work on NT based systems).

Anyway, be ready to deal with strange things : example : some games not doing things in the *documented* way : creating delay problems with sound, graphics bugs etc... :)

Keep up the good work : you will probably have great fun by writing this...
Posted on 2003-05-02 05:57:49 by JCP

Hey x86, it was a project I wanted to do there is a long time : unfortunaly lacking of time to do it... :)

Btw, I know there is already good z80 libraries written... have a look at some emulators and emu-websites....

Also have a look at http://cgfm2.emuviews.com/segastuf.htm#sms : it has some useful docs : the Megadrive - Genesis was very useful to me some time ago when I did some programming on it !

I was around the emu-scene for a long time : at this time, there was a real need of a good sms emulator (Good old Meka doesn't work on NT based systems).

Anyway, be ready to deal with strange things : example : some games not doing things in the *documented* way : creating delay problems with sound, graphics bugs etc... :)

Keep up the good work : you will probably have great fun by writing this...


aww man thanks I needed this info :D, the info I have wasnt very descriptive!
Posted on 2003-05-02 06:51:06 by x86asm
Thanks Cydonia and Arkane I will look at trying both of ur suggestions :D
Posted on 2003-05-02 06:52:17 by x86asm
nice one, readiosys, could i got some more link / forum about those stuff? uhmm... that kinda suitable to my current job :grin: :grin:
Posted on 2003-05-02 07:08:42 by dion
Personally, not, but you can mail the emulators authors : they are most of the time very sympathic and do not hesitate to share their documentations, and sometimes even sources...
Posted on 2003-05-02 07:29:55 by JCP
you can also set bit 4 to 1 by
xor eax, 10h
or set bit 4 to 0 by
and eax, 0FFFFFFEFh
:)
Posted on 2003-05-02 13:44:23 by arkane
Erm, I'm sure he knows that.

Anyway, the A flag is set when there's a carry from bit 3 to bit 4. This goes in bit 4 of our flag register. Incidentally, this is also bit 4 of the Z80's flag register.
Posted on 2003-05-02 17:05:09 by Sephiroth3

Erm, I'm sure he knows that.

Anyway, the A flag is set when there's a carry from bit 3 to bit 4. This goes in bit 4 of our flag register. Incidentally, this is also bit 4 of the Z80's flag register.


So after the resultant Z-80 operation, I move the status of bit 4 into the Half-Carry flag and thats it?
Posted on 2003-05-03 16:51:43 by x86asm
Yeah, and keep bit 0, too (the carry). Bit 11 (overflow) should be moved into bit 2. Bit 7 (sign) goes in bit 1.
Posted on 2003-05-03 20:30:28 by Sephiroth3