#ifndef __VB_H__ #define __VB_H__ #ifdef __cplusplus extern "C" { #endif #ifndef VBAPI #define VBAPI extern #endif /* Header includes */ #include #include /********************************* Constants *********************************/ /* Value types */ #define VB_S8 0 #define VB_U8 1 #define VB_S16 2 #define VB_U16 3 #define VB_S32 4 /* System register IDs */ #define VB_ADTRE 25 #define VB_CHCW 24 #define VB_ECR 4 #define VB_EIPC 0 #define VB_EIPSW 1 #define VB_FEPC 2 #define VB_FEPSW 3 #define VB_PIR 6 #define VB_PSW 5 #define VB_TKCW 7 /*********************************** Types ***********************************/ /* Simulation state */ typedef struct VB VB; struct VB { /* Game pak */ struct { uint8_t *rom; /* Active ROM buffer */ uint32_t romSize; /* Size of ROM data */ uint8_t *sram; /* Active SRAM buffer */ uint32_t sramSize; /* Size of SRAM data */ } cart; /* CPU */ struct { /* System registers */ uint32_t adtre; /* Address trap register for execution */ uint32_t eipc; /* Exception/Interrupt PC */ uint32_t eipsw; /* Exception/Interrupt PSW */ uint32_t fepc; /* Fatal error PC */ uint32_t fepsw; /* Fatal error PSW */ uint32_t sr29; /* Unknown system register */ uint32_t sr31; /* Unknown system register */ /* Cache control word */ struct { int8_t ice; /* Instruction cache enable */ } chcw; /* Exception cause register */ struct { uint16_t eicc; /* Exception/interrupt cause code */ uint16_t fecc; /* Fatal error cause code */ } ecr; /* Program status word */ struct { int8_t ae; /* Address trap enable */ int8_t cy; /* Carry */ int8_t ep; /* Exception pending */ int8_t fiv; /* Floating invalid */ int8_t fov; /* Floating overflow */ int8_t fpr; /* Floating precision */ int8_t fro; /* Floating reserved operand */ int8_t fud; /* Floating underflow */ int8_t fzd; /* Floating zero divide */ int8_t i; /* Interrupt level */ int8_t id; /* Interrupt disable */ int8_t np; /* NMI pending */ int8_t ov; /* Overflow */ int8_t s; /* Sign */ int8_t z; /* Zero */ } psw; /* Other registers */ uint32_t pc; /* Program counter */ int32_t program[32]; /* program registers */ /* Other fields */ uint32_t clocks; /* Clocks until next action */ uint8_t fatch; /* Index of fetch unit */ uint8_t state; /* Operations state */ } cpu; /* Other fields */ uint8_t wram[0x10000]; /* Main memory */ }; /**************************** Function Prototypes ****************************/ VBAPI uint32_t vbGetProgramCounter (VB *emu); VBAPI int32_t vbGetProgramRegister (VB *emu, int id); VBAPI uint32_t vbGetSystemRegister (VB *emu, int id); VBAPI void vbInit (VB *emu); VBAPI int32_t vbRead (VB *emu, uint32_t address, int type, int debug); VBAPI void vbReset (VB *emu); VBAPI uint32_t vbSetProgramCounter (VB *emu, uint32_t value); VBAPI int32_t vbSetProgramRegister (VB *emu, int id, int32_t value); VBAPI int vbSetROM (VB *emu, void *rom, uint32_t size); VBAPI int vbSetSRAM (VB *emu, void *sram, uint32_t size); VBAPI uint32_t vbSetSystemRegister (VB *emu, int id, uint32_t value); VBAPI void vbWrite (VB *emu, uint32_t address, int type, int32_t value, int debug); #ifdef __cplusplus } #endif #endif /* __VB_H__ */