summaryrefslogtreecommitdiff
path: root/src/vcpu.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vcpu.c')
-rw-r--r--src/vcpu.c39
1 files changed, 16 insertions, 23 deletions
diff --git a/src/vcpu.c b/src/vcpu.c
index 08f4e06..d3eeb11 100644
--- a/src/vcpu.c
+++ b/src/vcpu.c
@@ -122,43 +122,36 @@ void VCPUExecute(){
break;
case 0x4: // VX = VX + VY
- if((State.V[State.X] + State.V[State.Y]) > 255)
- State.V[REG_FLAG]=1;
- else
- State.V[REG_FLAG]=0;
- State.V[State.X]=State.V[State.X] + State.V[State.Y];
+ unsigned char x=State.V[State.X];
+ unsigned char y=State.V[State.Y];
+ State.V[State.X]=x+y;
+ State.V[REG_FLAG]=((x+y) > 255);
break;
case 0x5: // VX = VX - VY
- if(State.V[State.X] > State.V[State.Y])
- State.V[REG_FLAG]=1;
- else
- State.V[REG_FLAG]=0;
- State.V[State.X]=State.V[State.X] - State.V[State.Y];
+ unsigned char x2=State.V[State.X];
+ unsigned char y2=State.V[State.Y];
+ State.V[State.X]=x2-y2;
+ State.V[REG_FLAG]=(x2>=y2);
break;
case 0x6: // VX = VX SHR 1
- if(State.V[State.X] & 0x1 == 1)
- State.V[REG_FLAG]=1;
- else
- State.V[REG_FLAG]=0;
+ char flag=State.V[State.X] & 0x1 == 1;
State.V[State.X]=State.V[State.X] >> 1;
+ State.V[REG_FLAG]=flag;
break;
case 0x7: // VX = VY - VX
- if(State.V[State.Y] > State.V[State.X])
- State.V[REG_FLAG]=1;
- else
- State.V[REG_FLAG]=0;
- State.V[State.X]=State.V[State.Y] - State.V[State.X];
+ unsigned char x3=State.V[State.X];
+ unsigned char y3=State.V[State.Y];
+ State.V[State.X]=y3-x3;
+ State.V[REG_FLAG]=(y3>=x3);
break;
case 0xE: // VX = VX SHL 1
- if(State.V[State.X] >> 7 == 1)
- State.V[REG_FLAG]=1;
- else
- State.V[REG_FLAG]=0;
+ char flag2=State.V[State.X] >> 7 == 1;
State.V[State.X]=State.V[State.X] << 1;
+ State.V[REG_FLAG]=flag2;
break;
}