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

Damn you and your integers C#!

Sign in to follow this  

254 views

Guess what? It's time to play "spot the bug" again!


public static int RRCA( Processor Processor, Opcode Opcode )
{
int Carry = ( Processor.A << 7 );
Processor.A = (byte)( ( Processor.A >> 1 ) | Carry );
Processor.NegativeFlag = false;
Processor.HalfCarryFlag = false;
Processor.CarryFlag = ( Carry != 0 );
return 0;
}



Yep thanks to C#'s "lets make everything an integer" policy, Carry isn't just limited to 0 or 128. Well part of this is of course my fault for making Carry an integer or forgetting that shifting a byte doesn't return a byte.

New version:


public static int RRCA( Processor Processor, Opcode Opcode )
{
Processor.A = (byte)( ( Processor.A >> 1 ) | ( Processor.A << 7 ) );
Processor.NegativeFlag = false;
Processor.HalfCarryFlag = false;
Processor.CarryFlag = ( ( Processor.A & 0x80 ) != 0 );
return 0;
}



This fixes the "platform bug" in Mega Man 2 that I showed a couple entries ago. Unfortunately it hasn't fixed much else [sad].


Sign in to follow this  


3 Comments


Recommended Comments

There's nothing worse than fixing a fundamental emulation issue to have it fix almost nothing.

If it makes you feel any better, I spent all day trying to figure out what was going wrong with emulation of Metroid, only to find out that the bug that I was trying to fix exists on the actual console.

Share this comment


Link to comment
Quote:
Original post by Drilian
If it makes you feel any better, I spent all day trying to figure out what was going wrong with emulation of Metroid, only to find out that the bug that I was trying to fix exists on the actual console.


What exactly was the problem?

Share this comment


Link to comment
When there gets to be a lot of things on-screen, all of the sprites on-screen start to flicker like crazy and, occasionally, show different characters. Turns out, it's just that the game code can't keep up with the game update time because of all of the stuff going on, and the sprite data loading is one of the last things to run, so it doesn't have time to completely finish before rendering, eventually causing graphical corruption.

I also tried debugging a (very similar) issue in Super Mario Bros...if you get a bit too much going on at once, the game will skip a frame and not scroll the status bar at the top to its correct location, so it flickers off to the side.

That's the biggest problem with writing an emulator (once you have the majority of it up and running, anyway): it's hard to tell which things you see are bugs, and which things are just how things are.

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