Sign in to follow this  
  • entries
    177
  • comments
    531
  • views
    163577

Lots of progress

Sign in to follow this  
Scet

180 views

NES Progress

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.

Sign in to follow this  


5 Comments


Recommended Comments

Quote:
Original post by benryves
Dare I ask why the methods are static and return int?


They're static so that I could just create the opcode array in a file, instead of having it in the constructor(it's huge!). The return is the number of extra cycles to add, so most of them return 0.

Share this comment


Link to comment
Quote:
Original post by Jotaf
Find a string with substring "NES" and go with that! x)


Uhh, that's what I'm trying to avoid since it makes it sound like it's just for the NES.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now