PZ80emu  0.1
z80.h
Go to the documentation of this file.
1 
7 #ifndef __PZ80emu__z80__
8 #define __PZ80emu__z80__
9 
10 #include <stdint.h>
11 
12 #include "bus.h"
13 
15 #define INIT_PC 0x0000
16 
18 #define INTERRUPT_PERIOD 10240
19 
21 typedef union {
22  uint16_t W;
28  struct {
29 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
30  /* ...in low-endian architecture */
31  uint8_t l;
32  uint8_t h;
33 #else
34  /* ...in high-endian architecture */
35  uint8_t h;
36  uint8_t l;
37 #endif
38  } B;
39 } word;
40 
44 typedef enum {
45  IM0,
46  IM1,
47  IM2
49 
51 struct z80 {
52  int counter;
53  word pc;
54  word af;
55  word bc;
56  word de;
57  word hl;
58  word ix;
59  word iy;
60  word ir;
65  word sp;
66  struct bus *bus;
68  bool iff1;
69  bool iff2;
70 };
71 
72 #define CARRY 0
73 #define SUBTRACT 1
74 #define PARITY_OVERFLOW 2
75 #define F3 3
76 #define HALF_CARRY 4
77 #define F5 5
78 #define ZERO 6
79 #define SIGN 7
81 __BEGIN_DECLS
82 struct z80 *new_cpu(void);
83 void reset_cpu(struct z80 *);
84 int run(struct z80 *, uint8_t *, long, bool);
85 __END_DECLS
86 
87 #endif /* defined(__PZ80emu__z80__) */
z80::bus
struct bus * bus
Definition: z80.h:66
z80::sp
word sp
Definition: z80.h:65
INTERRUPT_PERIOD
#define INTERRUPT_PERIOD
number of cycles to run before triggering interrupt
Definition: z80.h:18
memory
z80 memory class
Definition: memory.h:19
run
int run(struct z80 *cpu, uint8_t *memory, long runcycles, bool s_flag)
Definition: z80.c:66
interrupt_mode
interrupt_mode
enum to contain all possible interrupt modes
Definition: z80.h:44
z80::pc
word pc
Definition: z80.h:53
IM0
@ IM0
Definition: z80.h:45
z80::ix
word ix
Definition: z80.h:58
z80::counter
int counter
Definition: z80.h:52
z80::_bc
word _bc
Definition: z80.h:62
interpreter.h
bus::nmi
bool nmi
Definition: bus.h:18
z80::im
interrupt_mode im
Definition: z80.h:67
new_cpu
__BEGIN_DECLS struct z80 * new_cpu(void)
Definition: z80.c:26
z80::ir
word ir
Definition: z80.h:60
z80
Definition: z80.h:51
bus::busreq
bool busreq
Definition: bus.h:16
z80.h
z80 CPU data structure and functions
z80::iff1
bool iff1
Definition: z80.h:68
bus::interrupt
bool interrupt
Definition: bus.h:17
display_mem
void display_mem(uint8_t *memory)
display the current memory contents to STDOUT
Definition: display.c:144
z80::_af
word _af
Definition: z80.h:61
z80::bc
word bc
Definition: z80.h:55
word::l
uint8_t l
low order byte
Definition: z80.h:31
word::h
uint8_t h
high order byte
Definition: z80.h:32
bus
z80 bus class
Definition: bus.h:15
run
int run(struct z80 *, uint8_t *, long, bool)
Definition: z80.c:66
IM2
@ IM2
Definition: z80.h:47
z80::af
word af
Definition: z80.h:54
display.h
z80::_hl
word _hl
Definition: z80.h:64
display_registers
void display_registers(struct z80 *cpu)
display the current register state to STDOUT
Definition: display.c:177
word::W
uint16_t W
16-bit pair
Definition: z80.h:22
reset_cpu
void reset_cpu(struct z80 *cpu)
Definition: z80.c:48
z80::iy
word iy
Definition: z80.h:59
z80::de
word de
Definition: z80.h:56
word
type to deal with endianness and access of high/low bits
Definition: z80.h:21
new_cpu
struct z80 * new_cpu(void)
Definition: z80.c:26
bus.h
reset_cpu
void reset_cpu(struct z80 *)
Definition: z80.c:48
z80::hl
word hl
Definition: z80.h:57
_instruction
void _instruction(struct z80 *cpu, uint8_t *memory)
parses an opcode from the main instruction set
Definition: interpreter.c:158
IM1
@ IM1
Definition: z80.h:46
z80::iff2
bool iff2
Definition: z80.h:69
z80::_de
word _de
Definition: z80.h:63