Minor changes

This commit is contained in:
Loïc Guégan 2023-12-25 18:36:53 +01:00
parent 90c372fc35
commit ab71de02f4
2 changed files with 17 additions and 24 deletions

View file

@ -13,7 +13,7 @@ int main(int argc, char *argv[])
// Initialize // Initialize
MemInit(); MemInit();
MemLoadROM("../roms/chip8-test-suite/3-corax+.ch8"); MemLoadROM("../roms/chip8-test-suite/4-flags.ch8");
ScreenInit(800,400); ScreenInit(800,400);
VCPUInit(); VCPUInit();

View file

@ -122,43 +122,36 @@ void VCPUExecute(){
break; break;
case 0x4: // VX = VX + VY case 0x4: // VX = VX + VY
if((State.V[State.X] + State.V[State.Y]) > 255) unsigned char x=State.V[State.X];
State.V[REG_FLAG]=1; unsigned char y=State.V[State.Y];
else State.V[State.X]=x+y;
State.V[REG_FLAG]=0; State.V[REG_FLAG]=((x+y) > 255);
State.V[State.X]=State.V[State.X] + State.V[State.Y];
break; break;
case 0x5: // VX = VX - VY case 0x5: // VX = VX - VY
if(State.V[State.X] > State.V[State.Y]) unsigned char x2=State.V[State.X];
State.V[REG_FLAG]=1; unsigned char y2=State.V[State.Y];
else State.V[State.X]=x2-y2;
State.V[REG_FLAG]=0; State.V[REG_FLAG]=(x2>=y2);
State.V[State.X]=State.V[State.X] - State.V[State.Y];
break; break;
case 0x6: // VX = VX SHR 1 case 0x6: // VX = VX SHR 1
if(State.V[State.X] & 0x1 == 1) char flag=State.V[State.X] & 0x1 == 1;
State.V[REG_FLAG]=1;
else
State.V[REG_FLAG]=0;
State.V[State.X]=State.V[State.X] >> 1; State.V[State.X]=State.V[State.X] >> 1;
State.V[REG_FLAG]=flag;
break; break;
case 0x7: // VX = VY - VX case 0x7: // VX = VY - VX
if(State.V[State.Y] > State.V[State.X]) unsigned char x3=State.V[State.X];
State.V[REG_FLAG]=1; unsigned char y3=State.V[State.Y];
else State.V[State.X]=y3-x3;
State.V[REG_FLAG]=0; State.V[REG_FLAG]=(y3>=x3);
State.V[State.X]=State.V[State.Y] - State.V[State.X];
break; break;
case 0xE: // VX = VX SHL 1 case 0xE: // VX = VX SHL 1
if(State.V[State.X] >> 7 == 1) char flag2=State.V[State.X] >> 7 == 1;
State.V[REG_FLAG]=1;
else
State.V[REG_FLAG]=0;
State.V[State.X]=State.V[State.X] << 1; State.V[State.X]=State.V[State.X] << 1;
State.V[REG_FLAG]=flag2;
break; break;
} }