7741c93ebe263c511c14360bd2ca604153c97f13
1 #ifndef DCPU16_H_3XXIQQG2
2 #define DCPU16_H_3XXIQQG2
6 /* the target system's concept of a word */
7 typedef unsigned short DCPU16_WORD
;
9 /* how much ram the system has */
10 #define DCPU16_RAM 0x10000
12 /* a self-contained dcpu16 core */
14 struct dcpu16_acct_cb
*cb_table_
; /* list of callbacks to invoke for certain events */
15 size_t cb_table_entries_
; /* callback list maintenance */
16 size_t cb_table_allocated_
; /* callback list maintenance */
17 unsigned int skip_
: 1; /* skip execution of next instruction */
18 DCPU16_WORD reg_work_
[2]; /* work registers for holding literal values while decoding instructions */
20 unsigned long long cycle
; /* number of cycles this core has executed */
21 DCPU16_WORD reg
[8]; /* system registers, a b c x y z i j */
22 DCPU16_WORD pc
; /* program counter */
23 DCPU16_WORD sp
; /* stack pointer */
24 DCPU16_WORD o
; /* overflow */
25 DCPU16_WORD ram
[DCPU16_RAM
]; /* memory */
28 /* these are used for accounting/watchpointing/modules/&c */
29 typedef unsigned int dcpu16_acct_event
;
30 typedef void (dcpu16_ev_cb_t
)(struct dcpu16
*, dcpu16_acct_event
, DCPU16_WORD
, void *);
31 #define DCPU16_ACCT_EV_READ (1<<1)
32 #define DCPU16_ACCT_EV_WRITE (1<<2)
33 #define DCPU16_ACCT_EV_NOP (1<<3)
34 #define DCPU16_ACCT_EV_RESET (1<<4)
35 struct dcpu16_acct_cb
{
38 dcpu16_acct_event mask
;
41 /* instantiate a new core */
42 struct dcpu16
*dcpu16_new(void);
44 /* reset a core to initial state */
45 void dcpu16_reset(struct dcpu16
*);
47 /* print the current state of a core */
48 void dcpu16_state_print(struct dcpu16
*);
50 /* print the contents of ram from second to third argument */
51 void dcpu16_dump_ram(struct dcpu16
*, DCPU16_WORD
, DCPU16_WORD
);
53 /* print the instruction at the specified address, returns number of words consumed in decoding */
54 DCPU16_WORD
dcpu16_disassemble_print(struct dcpu16
*, DCPU16_WORD
);
56 /* register a callback for an accounting event */
57 int dcpu16_acct_add(struct dcpu16
*, dcpu16_acct_event mask
, dcpu16_ev_cb_t
*fn
, void *data
);
59 /* execute the next instruction */
60 void dcpu16_step(struct dcpu16
*);
63 void dcpu16_delete(struct dcpu16
**);
65 /* register callbacks to handle warning and debug messages, default is writing to stderr, may be set to null */
66 void dcpu16_warn_cb_set(void (*)(char *, ...));
67 void dcpu16_trace_cb_set(void (*)(char *, ...));
69 #endif /* DCPU16_H_3XXIQQG2 */