1
0
Fork 0
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:
Henrik Hautakoski 2018-10-28 14:53:41 +01:00
parent 3db5f117d6
commit 6f60b1a74a
No known key found for this signature in database
GPG key ID: 839F3A7EAFAEAFAA
3 changed files with 120 additions and 73 deletions

View file

@ -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 */