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