Minor changes

This commit is contained in:
Loïc Guégan 2023-12-25 15:59:36 +01:00
parent c6ddcbe2bd
commit 9550924042
5 changed files with 42 additions and 22 deletions

View file

@ -16,7 +16,7 @@ void VCPUInit(){
void VCPUFetch(){
unsigned char byte[2];
MemRead(byte,2,State.PC); // Little indian to -1 no +1
MemLoad(byte,2,State.PC); // Little indian to -1 no +1
State.opcode=byte[0];
State.opcode=State.opcode<<8;
State.opcode=State.opcode | byte[1];
@ -56,7 +56,7 @@ void VCPUDoubleDabble(unsigned char x, unsigned char *u, unsigned char *t, unsig
}
void VCPUExecute(){
VCPUDump();
// VCPUDump();
switch(State.opcode >> 12){
case 0x0: // Clear screen or return from subroutine
if(State.N == 0x0){ // Clear screen
@ -185,17 +185,17 @@ void VCPUExecute(){
break;
case 0xD: // Draw a sprite
int X=State.V[State.X]&63;
int Y=State.V[State.Y]&31;
State.V[REG_FLAG]=0; // Set flag to 0
int width, height;
ScreenWH(&width,&height);
int X=State.V[State.X]%width;
int Y=State.V[State.Y]%height;
for(char row=0;row<State.N;row++){
// Stop if row out of screen
if(Y+row>=height)
break;
unsigned char sprite;
MemRead(&sprite,1,State.I+row); // Load sprite
MemLoad(&sprite,1,State.I+row); // Load sprite
// Draw sprite
for(int shift=0;shift<8;shift++){
// Stop if column is out of screen
@ -240,18 +240,18 @@ void VCPUExecute(){
case 0x33:
unsigned char units, tens, hundreds;
VCPUDoubleDabble(State.V[State.X],&units,&tens,&hundreds);
MemCopy(&hundreds,1,State.I);
MemCopy(&tens,1,State.I+1);
MemCopy(&units,1,State.I+2);
MemStore(&hundreds,1,State.I);
MemStore(&tens,1,State.I+1);
MemStore(&units,1,State.I+2);
// printf("hundreds:%d tens:%d units:%d byte:%d\n",hundreds,tens,units,State.V[State.X]);
break;
case 0x55:
MemCopy(State.V,0xF,State.I);
MemStore(State.V,16,State.I);
break;
case 0x65:
MemRead(State.V,0xF,State.I);
MemLoad(State.V,16,State.I);
break;
}
@ -266,4 +266,7 @@ void VCPUDump(){
printf("N: 0x%01x\n",State.N);
printf("NN: 0x%02x\n",State.NN);
printf("NNN: 0x%03x\n",State.NNN);
for(int i=0;i<16;i++){
printf("V%d: 0x%02x\n",i,State.V[i]);
}
}