OP 08 June, 2019 - 02:52 PM
So I'm implementing a gameboy CPU in C# to make an emulator. And I need someone good in ASM to check an implementation I make which I have a doubt on.
The OPCODE 0x9F translates to instruction SBC (source here http://www.pastraiser.com/cpu/gameboy/ga...codes.html) so substract with carry.
I just need someone to check my implementation, like @MeSvAk cause apparently he knows ASM.
Right now I have this made :
The OPCODE 0x9F translates to instruction SBC (source here http://www.pastraiser.com/cpu/gameboy/ga...codes.html) so substract with carry.
I just need someone to check my implementation, like @MeSvAk cause apparently he knows ASM.
Right now I have this made :
Code:
/// <summary>
/// Substract n + carry flag from A.
/// </summary>
/// <param name="r1">n</param>
private static void sbc(byte r1)
{
// TODO Double check this implementation
uint substractResult = (uint)Gameboy.Cpu.Registers.A - r1 - Convert.ToUInt32(Gameboy.Cpu.Registers.F.C);
// Set zero flag if result is 0.
Gameboy.Cpu.Registers.F.Z = ((byte)substractResult) == 0;
// Set half-carry flag if no borrow from bit 4. IM UNSURE ABOUT THIS. This should mean if result is 0b0001_0000, we have a carry, but is it really how to implement it?
Gameboy.Cpu.Registers.F.H = ((Gameboy.Cpu.Registers.A ^ r1 ^ substractResult) & 0x10) != 0;
// Set the carry flag if no borrow at all 0b0001_0000_0000 (so more than 8 bits)
Gameboy.Cpu.Registers.F.C = ((substractResult & 0x100) != 0);
// The substract flag is set as we performed a sub op.
Gameboy.Cpu.Registers.F.N = true;
}
Whoever trades his freedom for his safety deserves neither.
I may have coded Axenta, vapor and some other useless shit nobody uses
I may have coded Axenta, vapor and some other useless shit nobody uses