What's new

Sega Master System

OP
albertwesker

albertwesker

New member
things are moving along, but i was wondering if someone could explain how to determine if the half-carry flag is to be set or cleared. the P/V flag is a little confusing too, but i haven't come accross an opcode where that flag is affected yet.

i've read that most emulation problems with the z80 occur because of incorrect flag register implementation... :plain:
 

ShizZy

Emulator Developer
A carry occurs if the value of a bit carries over to the next bit to the left after an operation occurs. So say if it says to set Flag H if there is a carry from bit3, you check if bit4 (the next bit) is set after the operation. Simple as if(answer&0x10). A half carry is the same as a carry, except that it only occurs in the lower nibble of the byte.

Just so you know the H and N flags are BCD flags, and thus only used by the DAA function for scores and what not. So H/N flag errors for the most part won't cause a game to break. You should be more concerned about the Carry and Zero flags, which are used for jumps and things.
 
OP
albertwesker

albertwesker

New member
ShizZie said:
A carry occurs if the value of a bit carries over to the next bit to the left after an operation occurs. So say if it says to set Flag H if there is a carry from bit3, you check if bit4 (the next bit) is set after the operation. Simple as if(answer&0x10). A half carry is the same as a carry, except that it only occurs in the lower nibble of the byte.

Just so you know the H and N flags are BCD flags, and thus only used by the DAA function for scores and what not. So H/N flag errors for the most part won't cause a game to break. You should be more concerned about the Carry and Zero flags, which are used for jumps and things.

shizzie, wouldn't it be (answer&0x8) to check the fourth bit? and also, in a carry operation in binary arithmetic, if the fourth bit was already a 1, then a carry from the addition of the third bits would cause the fourth bit to be 0 and cause it to carry to the fifth bit, etc.

here is an example of this scenario:

in this case the fourth bit for each operand was already 0, so the carry to the fourth bit made the fourth bit 1 for a binary result of 1000 or 0x8.

0000 0100
0000 0100
----------
0000 1000

here, the fourth bit is already set in one of the operands (in this case, the first), so a carry from the addition of the third bit causes another carry in the addition of the fourth over in to the fifth, resulting in the binary value 10000 or 0x10.

0000 1100
0000 0100
----------
0001 0000

taking this into consideration, i think to figure out if a half carry occurs at the third bit during and INC r instruction, where the register is simply incremented by '1', i would simply do this:

//run this before the increment operation
if(reg.B&0x7){
// then the result is a carry
}

in other words if
reg.B = 0111
and 0111 + 0001 = 1000 then
we have a half-carry situation and need to set the appropriate flag.

perhaps i'm missing something? :plain:
 
Last edited:

ShizZy

Emulator Developer
Yeah... it isn't the 4th bit, it's bit 4. There's bits 0-7, so actually it'd be the 5th bit - 0x10. And by bit three they mean the 4th bit. That's how the docs refer to them ;)
 

blueshogun96

A lowdown dirty shame
Ok, I have officially started my SMS emulator a few days ago. Right now, I'm just trying to get my z80 core out of the way. Heh, the jump from the 1802 to the z80 is a bit more difficult than I anticipated, lol.

I have a quick question about the z80 state flags. This is how I calculate my flags so far.

// Bit 3 of status thingy
#define RegX(p) ( ( p >> 3 ) & 0x1 )

Is there a better way of calculating flags? I'm getting lost quite easily here on the z80 emulation part. My strengths ly in the GPU not CPU :\
 

ShizZy

Emulator Developer
You're trying to see if there's a carry from bit 3, right?
This would be better:

#define RegX(p) (p&0x10)

Check bit 4 to see if it'd be carried into the bit 3. Easy as that.
 
Last edited:
OP
albertwesker

albertwesker

New member
here's an update of where i am. the cpu core is complete and the vdp is nearing completion. rom paging is next, then sound. so far this is easier than i had anticipated. thanks to finally sitting down and pouring through some documentation, things starting coming together. here's an early screenshot of Hang On on the Mega Master System:

mega.jpg


and obviously, there's still quite a bit of work left.
 

hap

New member
I see you implemented tile flipping (updated screenshots :p )

Anyway, looking good.
How about an alpha/beta for us to try out ?
 
OP
albertwesker

albertwesker

New member
thanks hap!

i've got a few issues i need to fix in the cpu core and the mem mapper and then it will be ready for an alpha release.
 

GbaGuy

New member
edited: I found what I needed at links provided earlier in the thread. I failed horribly at GB emus. I can write a chip8 emulator as fast as it takes to type it out. I can write a NES emu to the point of having most of the common mapper games playable (no sound). Let's watch me fail at SMS...
 
Last edited:
OP
albertwesker

albertwesker

New member
GbaGuy said:
edited: I found what I needed at links provided earlier in the thread. I failed horribly at GB emus. I can write a chip8 emulator as fast as it takes to type it out. I can write a NES emu to the point of having most of the common mapper games playable (no sound). Let's watch me fail at SMS...

in case you didn't know, the gameboy's z80 has only a subset of the opcodes that the master system's z80 has.
 

GbaGuy

New member
Yeah, I realized that rather quickly. I started working on GB emu once more, this time in Java (for the hell of it). I don't think CPU emulation is my problem. I just never seem to get the graphics and interrupts working right. Perhaps this time I'll post in the GameBoy thread for help once I get everything implemented and see what I can get to work and what doesn't, etc.
 

aprentice

Moderator
i tried a sms emu a year or two ago, i only got complete memory emulation with banking etc done then i just got bored and stopped working on it, maybe i will continue it in the future when im done with my current projects, it didnt look too difficult
 

Top