X-Git-Url: http://git.squeep.com/?p=dcpu16;a=blobdiff_plain;f=dcpu16.h;h=f0e4d8b54abb2d19ead94757e3858949d7819cf8;hp=c9510c25ddda35042f599c46af7fce5f0ac30203;hb=a44fc6f0eb899b6f745fe8ab43d5cb3e5b743c21;hpb=28bd5d99ce17285ed06b4762a6027d3f25693265 diff --git a/dcpu16.h b/dcpu16.h index c9510c2..f0e4d8b 100644 --- a/dcpu16.h +++ b/dcpu16.h @@ -1,6 +1,45 @@ #ifndef DCPU16_H_3XXIQQG2 #define DCPU16_H_3XXIQQG2 +/* the target system's concept of a word */ typedef unsigned short DCPU16_WORD; +/* how much ram the system has */ +#define DCPU16_RAM 0x10000 + +/* a self-contained dcpu16 core */ +struct dcpu16 { + unsigned long long cycle; /* number of cycles this core has executed */ + DCPU16_WORD reg[8]; /* system registers, a b c x y z i j */ + DCPU16_WORD pc; /* program counter */ + DCPU16_WORD sp; /* stack pointer */ + DCPU16_WORD o; /* overflow */ + unsigned int skip_ : 1; /* skip execution of next instruction */ + DCPU16_WORD ram[DCPU16_RAM]; /* memory */ + DCPU16_WORD reg_work_[2]; /* (private) work registers for holding literal values while decoding instructions */ +}; + +/* instantiate a new core */ +struct dcpu16 *dcpu16_new(void); + +/* print the current state of a core */ +void dcpu16_state_print(struct dcpu16 *); + +/* print the contents of ram from second to third argument */ +void dcpu16_dump_ram(struct dcpu16 *, DCPU16_WORD, DCPU16_WORD); + +/* print the instruction at the specified address */ +void dcpu16_disassemble_print(struct dcpu16 *, DCPU16_WORD); + + +/* execute the next instruction */ +void dcpu16_step(struct dcpu16 *); + +/* release a core */ +void dcpu16_delete(struct dcpu16 **); + +/* register callbacks to handle warning and debug messages, defaults to writing to stderr */ +void dcpu16_warn_cb_set(void (*)(char *, ...)); +void dcpu16_trace_cb_set(void (*)(char *, ...)); + #endif /* DCPU16_H_3XXIQQG2 */