Adding registers panes of CPU window

This commit is contained in:
2021-09-02 00:16:22 +00:00
parent 3dc8b93f94
commit ff07e1907f
32 changed files with 2437 additions and 444 deletions
+20 -26
View File
@@ -1,15 +1,21 @@
/* This file is included into vb.c and cannot be compiled on its own. */
#ifdef VBAPI
/**************************** Component Functions ****************************/
/* Read a data unit from a memory buffer */
static int32_t busReadMemory(uint8_t *mem, int type) {
/* Little-endian implementation */
#ifdef VB_LITTLEENDIAN
switch (type) {
case VB_S8 : return *(int8_t *)mem;
case VB_U8 : return * mem;
case VB_S16: return *(int16_t *)mem;
case VB_U16: return *(uint16_t *)mem;
}
return *(int32_t *)mem;
/* Generic implementation */
#ifdef VB_BIGENDIAN
#else
switch (type) {
case VB_S8 : return (int8_t) *mem;
case VB_U8 : return *mem;
@@ -18,16 +24,6 @@ static int32_t busReadMemory(uint8_t *mem, int type) {
}
return (int32_t ) mem[3] << 24 | (uint32_t) mem[2] << 16 |
(uint32_t) mem[1] << 8 | mem[0];
/* Little-endian implementation */
#else
switch (type) {
case VB_S8 : return *(int8_t *)mem;
case VB_U8 : return * mem;
case VB_S16: return *(int16_t *)mem;
case VB_U16: return *(uint16_t *)mem;
}
return *(int32_t *)mem;
#endif
}
@@ -60,8 +56,16 @@ static int32_t busRead(VB *emu, uint32_t address, int type, int debug) {
/* Write a data unit to a memory buffer */
static void busWriteMemory(uint8_t *mem, int type, int32_t value) {
/* Little-endian implementation */
#ifdef VB_LITTLEENDIAN
switch (type) {
case VB_S16: case VB_U16: *(uint16_t *)mem = value; return;
case VB_S8 : case VB_U8 : * mem = value; return;
}
*(int32_t *)mem = value;
/* Generic implementation */
#ifdef VB_BIGENDIAN
#else
switch (type) {
case VB_S32:
mem[3] = value >> 24;
@@ -72,14 +76,6 @@ static void busWriteMemory(uint8_t *mem, int type, int32_t value) {
mem[1] = value >> 8;
}
mem[0] = value;
/* Little-endian implementation */
#else
switch (type) {
case VB_S16: case VB_U16: *(uint16_t *)mem = value; return;
case VB_S8 : case VB_U8 : * mem = value; return;
}
*(int32_t *)mem = value;
#endif
}
@@ -114,6 +110,4 @@ static void busWrite(
}
#endif /* VBAPI */
+23 -16
View File
@@ -29,8 +29,13 @@ static const uint8_t TYPE_SIZES[] = { 1, 1, 2, 2, 4 };
/******************************* API Functions *******************************/
/* Retrieve the value of PC */
uint32_t vbGetProgramCounter(VB *emu) {
return emu->cpu.pc;
uint32_t vbGetProgramCounter(VB *emu, int type) {
switch (type) {
case VB_PC : return emu->cpu.pc;
case VB_PC_FROM: return emu->cpu.pcFrom;
case VB_PC_TO : return emu->cpu.pcTo;
}
return 0;
}
/* Retrieve the value of a program register */
@@ -64,6 +69,7 @@ uint32_t vbGetSystemRegister(VB *emu, int id) {
case VB_PIR : return 0x00005346;
case VB_TKCW : return 0x000000E0;
case 29 : return emu->cpu.sr29;
case 30 : return 0x00000004;
case 31 : return emu->cpu.sr31;
case VB_ECR : return
(uint32_t) emu->cpu.ecr.fecc << 16 | emu->cpu.ecr.eicc;
@@ -109,28 +115,29 @@ int32_t vbRead(VB *emu, uint32_t address, int type, int debug) {
/* Simulate a hardware reset */
void vbReset(VB *emu) {
uint32_t x;
uint32_t x; /* Iterator */
/* Initialize CPU registers */
/* CPU registers */
emu->cpu.pc = 0xFFFFFFF0;
vbSetSystemRegister(emu, VB_ECR, 0x0000FFF0);
vbSetSystemRegister(emu, VB_PSW, 0x00008000);
/* Initialize extra CPU registers (the hardware does not do this) */
/* Extra CPU registers (the hardware does not do this) */
for (x = 0; x < 32; x++)
emu->cpu.program[x] = 0;
emu->cpu.adtre = 0;
emu->cpu.eipc = 0;
emu->cpu.eipsw = 0;
emu->cpu.fepc = 0;
emu->cpu.fepsw = 0;
emu->cpu.sr29 = 0;
emu->cpu.sr31 = 0;
emu->cpu.program[x] = 0x00000000;
emu->cpu.adtre = 0x00000000;
emu->cpu.eipc = 0x00000000;
emu->cpu.eipsw = 0x00000000;
emu->cpu.fepc = 0x00000000;
emu->cpu.fepsw = 0x00000000;
emu->cpu.sr29 = 0x00000000;
emu->cpu.sr31 = 0x00000000;
emu->cpu.pcFrom = 0xFFFFFFF0;
emu->cpu.pcTo = 0xFFFFFFF0;
/* Erase WRAM (the hardware does not do this) */
/* WRAM (the hardware does not do this) */
for (x = 0; x < 0x10000; x++)
emu->wram[x] = 0;
emu->wram[x] = 0x00;
}
/* Specify a new value for PC */
+10 -3
View File
@@ -17,7 +17,7 @@ extern "C" {
/********************************* Constants *********************************/
/* Value types */
/* Memory access types */
#define VB_S8 0
#define VB_U8 1
#define VB_S16 2
@@ -36,6 +36,11 @@ extern "C" {
#define VB_PSW 5
#define VB_TKCW 7
/* PC types */
#define VB_PC 0
#define VB_PC_FROM 1
#define VB_PC_TO 2
/*********************************** Types ***********************************/
@@ -96,11 +101,13 @@ struct VB {
/* Other registers */
uint32_t pc; /* Program counter */
uint32_t pcFrom; /* Source of most recent jump */
uint32_t pcTo; /* Destination of most recent jump */
int32_t program[32]; /* program registers */
/* Other fields */
uint32_t clocks; /* Clocks until next action */
uint8_t fatch; /* Index of fetch unit */
uint8_t fetch; /* Index of fetch unit */
uint8_t state; /* Operations state */
} cpu;
@@ -112,7 +119,7 @@ struct VB {
/**************************** Function Prototypes ****************************/
VBAPI uint32_t vbGetProgramCounter (VB *emu);
VBAPI uint32_t vbGetProgramCounter (VB *emu, int type);
VBAPI int32_t vbGetProgramRegister (VB *emu, int id);
VBAPI void* vbGetROM (VB *emu, uint32_t *size);
VBAPI void* vbGetSRAM (VB *emu, uint32_t *size);