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