mirror of
https://github.com/pnx/m16vm
synced 2026-06-17 03:50:03 +02:00
src/cpu.c: alot of refactoring, store state in a struct. and make vm.c "own" the state.
This commit is contained in:
parent
3db5f117d6
commit
6f60b1a74a
3 changed files with 120 additions and 73 deletions
27
src/cpu.h
27
src/cpu.h
|
|
@ -25,12 +25,31 @@
|
|||
|
||||
#define CPU_NUM_REGS 16
|
||||
|
||||
int cpu_instr_load(void *ptr, unsigned len);
|
||||
#define CPU_FLAGS_HALT (1<<0)
|
||||
|
||||
void cpu_instr_unload();
|
||||
struct cpu_state {
|
||||
// Registers r0, r15
|
||||
int16_t reg[CPU_NUM_REGS];
|
||||
|
||||
void cpu_set_pc(uint16_t addr);
|
||||
// Program counter
|
||||
uint16_t pc;
|
||||
|
||||
void cpu_run();
|
||||
// flags
|
||||
unsigned char flags;
|
||||
|
||||
// Instruction
|
||||
unsigned char *instr_mem;
|
||||
unsigned long instr_cnt;
|
||||
};
|
||||
|
||||
void cpu_init(struct cpu_state *state);
|
||||
|
||||
int cpu_instr_load(struct cpu_state *state, void *ptr, unsigned len);
|
||||
|
||||
void cpu_instr_unload(struct cpu_state *state);
|
||||
|
||||
void cpu_set_pc(struct cpu_state *state, uint16_t addr);
|
||||
|
||||
int cpu_tick(struct cpu_state *state);
|
||||
|
||||
#endif /* CPU_H */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue