The NES portion of the emulator is coming along. The processor, memory(including VRAM) and a few mappers are implemented. I can actually run and trace programs, but nothing shows up because I haven't implemented the PPU. I'm waiting till the GameBoy portion works to make sure my timing is right.
GameBoy Progress
Have you ever looked at code only a few months old and wondered how you where able to program something that looks like an ungodly abomination that begs for apocalypse? Well that's what happened when I opened up GameKnight again. I'm warning you about the next piece of code.
public static int DEC8( Processor Processor, Opcode Opcode ){ byte* Pointer = Processor.GetRegisterPointer( ( ( Opcode.Value >> 3 ) & 0x07 ) ); *Pointer = (byte)( *Pointer - 1 ); Processor.SetFlags( Processor.GetFlags( Flags.Carry ) ); Processor.AddFlags( Flags.Negative ); Processor.AddFlags( Flags.HalfCarry, ( ( *Pointer & 0x0F ) == 0x0F ) ); Processor.AddFlags( Flags.Zero, ( *Pointer == 0 ) ); return 0;}
Yes pointers in C# and they where everywhere.
Here's the new version for comparison:
public static int DEC8( Processor Processor, Opcode Opcode ){ int RegisterIndex = ( ( Opcode.Value >> 3 ) & 0x07 ); byte Value = (byte)( Processor.GetRegisterValue( RegisterIndex ) - 1 ); Processor.NegativeFlag = true; Processor.HalfCarryFlag = ( ( Value & 0x0F ) == 0x0F ); Processor.ZeroFlag = ( Value == 0 ); Processor.SetRegisterValue( RegisterIndex, Value ); return 0;}
much better, no pointers or that "SetFlags/AddFlags" nonsense.
While rewriting the opcodes I stumbled upon one bug so bad, I'm blaming it for all my lost progress in October. That is I'm pretty sure that this bug wasted a month of my life as after fixing it almost every single game works.
Here's the unfixed version:
public static int RES( Processor Processor, Opcode Opcode ){ int RegisterIndex = ( Opcode.Value & 0x07 ); byte Value = Processor.GetRegisterValue( RegisterIndex ); Value &= (byte)( 1 << ( ( Opcode.Value >> 3 ) & 0x07 ) ); Processor.SetRegisterValue( RegisterIndex, Value ); return 0;}
I'll let you guys figure it out. If you don't know the Z80, the RES instruction is supposed to reset a bit(set it to 0).
Unfortunately while most games now work, a few don't, oddly they're all ones that do work in GameKnight.
Anyway here's what everyone came here to see, screenshots!
I haven't implemented windowing or sprite priorities yet, so if it looks like something is missing, it is.
Name my emulator!
As you can see from the screenshots the emulator is named "GreatNES". This worked when it was just supposed to be for the NES, but now that it works for multiple systems, it seems weird.
So any suggestions are welcome for a new name.
Dare I ask why the methods are static and return int?