Minor changes
This commit is contained in:
parent
001e18b3d4
commit
14e9dd9258
2 changed files with 27 additions and 25 deletions
32
src/vcpu.c
32
src/vcpu.c
|
@ -2,35 +2,17 @@
|
|||
#include "mem.h"
|
||||
#include "screen.h"
|
||||
|
||||
// Program Counter (16 bits but only 12 bits used (4096 memory addresses))
|
||||
unsigned short PC;
|
||||
|
||||
// Index register (16 bits but only 12 bits used (4096 memory addresses))
|
||||
unsigned short I;
|
||||
|
||||
// Stack register (16 bits)
|
||||
unsigned short S;
|
||||
|
||||
// General purpose registers (8 bits each)
|
||||
// Note last one often used as a flag register
|
||||
unsigned char V[16];
|
||||
|
||||
// Delay timer (8 bits)
|
||||
unsigned char DT;
|
||||
|
||||
// Sound timer (8 bits)
|
||||
unsigned char ST;
|
||||
|
||||
// Current VCPU state
|
||||
VCPU_State State;
|
||||
|
||||
void VCPUInit(){
|
||||
PC=ADDR_ROM;
|
||||
State.PC=ADDR_ROM;
|
||||
}
|
||||
|
||||
void VCPUFetch(){
|
||||
MemRead((char *)&(State.opcode),2,PC);
|
||||
PC+=2;
|
||||
MemRead((char *)&(State.opcode),2,State.PC);
|
||||
State.PC+=2;
|
||||
}
|
||||
|
||||
void VCPUDecode(){
|
||||
|
@ -48,19 +30,19 @@ void VCPUExecute(){
|
|||
break
|
||||
;;
|
||||
case 0x1:
|
||||
PC=State.NNN;
|
||||
State.PC=State.NNN;
|
||||
break
|
||||
;;
|
||||
case 0x6:
|
||||
V[State.X]=State.NN;
|
||||
State.V[State.X]=State.NN;
|
||||
break
|
||||
;;
|
||||
case 0x7:
|
||||
V[State.X]+=State.NN;
|
||||
State.V[State.X]+=State.NN;
|
||||
break
|
||||
;;
|
||||
case 0xA:
|
||||
I=State.NNN;
|
||||
State.I=State.NNN;
|
||||
break
|
||||
;;
|
||||
|
||||
|
|
20
src/vcpu.h
20
src/vcpu.h
|
@ -1,6 +1,26 @@
|
|||
#pragma once
|
||||
|
||||
typedef struct VCPU_State {
|
||||
// Program Counter (16 bits but only 12 bits used (4096 memory addresses))
|
||||
unsigned short PC;
|
||||
|
||||
// Index register (16 bits but only 12 bits used (4096 memory addresses))
|
||||
unsigned short I;
|
||||
|
||||
// Stack register (16 bits)
|
||||
unsigned short S;
|
||||
|
||||
// General purpose registers (8 bits each)
|
||||
// Note last one often used as a flag register
|
||||
unsigned char V[16];
|
||||
|
||||
// Delay timer (8 bits)
|
||||
unsigned char DT;
|
||||
|
||||
// Sound timer (8 bits)
|
||||
unsigned char ST;
|
||||
|
||||
// Intruction (opcode + decoded fields)
|
||||
short opcode;
|
||||
char X;
|
||||
char Y;
|
||||
|
|
Loading…
Add table
Reference in a new issue