-
Notifications
You must be signed in to change notification settings - Fork 0
/
z80.h
135 lines (116 loc) · 2.84 KB
/
z80.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifndef _Z80_H
#define _Z80_H
#include <stdint.h>
#include <stdbool.h>
#include "mem.h"
typedef struct z80_io_read_hook_s {
void *cookie;
uint8_t (*func)(void *, uint8_t);
} z80_io_read_hook_t;
typedef struct z80_io_write_hook_s {
void *cookie;
void (*func)(void *, uint8_t, uint8_t);
} z80_io_write_hook_t;
typedef struct z80_s {
uint16_t pc; /* Program Counter */
uint16_t sp; /* Stack Pointer */
uint8_t i; /* Interrupt Page Address */
uint8_t r; /* Memory Refresh */
bool iff1; /* Interrupt Flip-Flop #1 */
bool iff2; /* Interrupt Flip-Flop #2 */
int im; /* Interrupt Mode */
union {
struct {
union {
struct {
uint8_t c : 1; /* Carry */
uint8_t n : 1; /* Add/Subtract */
uint8_t pv : 1; /* Parity/Overflow */
uint8_t x1 : 1; /* Unused #1 */
uint8_t h : 1; /* Half Carry */
uint8_t x2 : 1; /* Unused #2 */
uint8_t z : 1; /* Zero */
uint8_t s : 1; /* Sign */
} flag;
uint8_t f; /* Flag */
};
uint8_t a; /* Accumulator */
};
uint16_t af; /* Combined AF */
};
union {
struct {
uint8_t c; /* General Purpose C */
uint8_t b; /* General Purpose B */
};
uint16_t bc; /* General Purpose BC */
};
union {
struct {
uint8_t e; /* General Purpose E */
uint8_t d; /* General Purpose D */
};
uint16_t de; /* General Purpose DE */
};
union {
struct {
uint8_t l; /* General Purpose L */
uint8_t h; /* General Purpose H */
};
uint16_t hl; /* General Purpose HL */
};
union {
struct {
uint8_t ixl; /* IX Low Part */
uint8_t ixh; /* IX High Part */
};
uint16_t ix; /* Index Register X */
};
union {
struct {
uint8_t iyl; /* IY Low Part */
uint8_t iyh; /* IY High Part */
};
uint16_t iy; /* Index Register Y */
};
union {
struct {
uint8_t f_; /* Alternate F' */
uint8_t a_; /* Alternate A' */
};
uint16_t af_; /* Alternate AF' */
};
union {
struct {
uint8_t c_; /* Alternate C' */
uint8_t b_; /* Alternate B' */
};
uint16_t bc_; /* Alternate BC' */
};
union {
struct {
uint8_t e_; /* Alternate E' */
uint8_t d_; /* Alternate D' */
};
uint16_t de_; /* Alternate DE' */
};
union {
struct {
uint8_t l_; /* Alternate L' */
uint8_t h_; /* Alternate H' */
};
uint16_t hl_; /* Alternate HL' */
};
z80_io_read_hook_t io_read[UINT8_MAX + 1];
z80_io_write_hook_t io_write[UINT8_MAX + 1];
uint32_t cycles;
bool halted;
bool ei_executed;
} z80_t;
void z80_init(z80_t *z80);
void z80_execute(z80_t *z80, mem_t *mem);
void z80_irq(z80_t *z80, mem_t *mem);
void z80_trace_init(void);
void z80_trace_dump(FILE *fh);
void z80_dump(FILE *fh, z80_t *z80, mem_t *mem);
#endif /* _Z80_H */