Minor changes

This commit is contained in:
Loïc Guégan 2023-12-25 07:32:11 +01:00
parent 001e18b3d4
commit 14e9dd9258
2 changed files with 27 additions and 25 deletions

View file

@ -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
;;

View file

@ -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;