2023-12-25 07:24:17 +01:00
|
|
|
#include "vcpu.h"
|
|
|
|
#include "mem.h"
|
|
|
|
#include "screen.h"
|
|
|
|
|
|
|
|
|
|
|
|
// Current VCPU state
|
|
|
|
VCPU_State State;
|
|
|
|
|
|
|
|
void VCPUInit(){
|
2023-12-25 07:32:11 +01:00
|
|
|
State.PC=ADDR_ROM;
|
2023-12-25 07:24:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void VCPUFetch(){
|
2023-12-25 07:32:11 +01:00
|
|
|
MemRead((char *)&(State.opcode),2,State.PC);
|
|
|
|
State.PC+=2;
|
2023-12-25 07:24:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void VCPUDecode(){
|
2023-12-25 07:30:17 +01:00
|
|
|
State.X=(State.opcode<<4) & 0xF0;
|
|
|
|
State.Y=(State.opcode<<8) & 0xF0;
|
|
|
|
State.N=(State.opcode<<12) & 0xF0;
|
|
|
|
State.NN=(State.opcode<<8) & 0xFF;
|
|
|
|
State.NNN=(State.opcode<<4) & 0xFFF0;
|
2023-12-25 07:24:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void VCPUExecute(){
|
2023-12-25 07:30:17 +01:00
|
|
|
switch(State.opcode & 0xF){
|
|
|
|
case 0x0:
|
2023-12-25 07:24:17 +01:00
|
|
|
ScreenClear();
|
|
|
|
break
|
|
|
|
;;
|
2023-12-25 07:30:17 +01:00
|
|
|
case 0x1:
|
2023-12-25 07:32:11 +01:00
|
|
|
State.PC=State.NNN;
|
2023-12-25 07:30:17 +01:00
|
|
|
break
|
|
|
|
;;
|
|
|
|
case 0x6:
|
2023-12-25 07:32:11 +01:00
|
|
|
State.V[State.X]=State.NN;
|
2023-12-25 07:30:17 +01:00
|
|
|
break
|
|
|
|
;;
|
|
|
|
case 0x7:
|
2023-12-25 07:32:11 +01:00
|
|
|
State.V[State.X]+=State.NN;
|
2023-12-25 07:30:17 +01:00
|
|
|
break
|
|
|
|
;;
|
|
|
|
case 0xA:
|
2023-12-25 07:32:11 +01:00
|
|
|
State.I=State.NNN;
|
2023-12-25 07:30:17 +01:00
|
|
|
break
|
|
|
|
;;
|
2023-12-25 07:24:17 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|