Lots of progress

Published January 23, 2008
Advertisement
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.

Previous Entry Two thousand and seven
Next Entry Almost there
0 likes 5 comments

Comments

benryves
Looking good, glad to see you got it working. [smile]

Dare I ask why the methods are static and return int?
January 24, 2008 11:41 AM
Drilian
A name for your dual NES/Gameboy emulator?

How about 2systems1cup.

Er, uh...nevermind.
January 24, 2008 02:17 PM
Scet
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.

January 24, 2008 04:48 PM
Jotaf
I was thinking about NEStlé because chocolates are yummy.

Find a string with substring "NES" and go with that! x)
January 24, 2008 09:14 PM
Scet
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.

January 25, 2008 08:20 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement