forked from buricco/marduk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
z80.h
62 lines (53 loc) · 2.24 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
/*
* Copyright (c) 2019 Nicolas Allemand.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following condition: The
* above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef Z80_Z80_H_
#define Z80_Z80_H_
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
typedef struct z80 z80;
struct z80 {
uint8_t (*read_byte)(void*, uint16_t);
void (*write_byte)(void*, uint16_t, uint8_t);
uint8_t (*port_in)(z80*, uint8_t);
void (*port_out)(z80*, uint8_t, uint8_t);
void* userdata;
unsigned long cyc; /* cycle count (t-states) */
uint16_t pc, sp, ix, iy; /* special purpose registers */
uint16_t mem_ptr; /* "wz" register */
uint8_t a, b, c, d, e, h, l; /* main registers */
uint8_t a_, b_, c_, d_, e_, h_, l_, f_; /* alternate registers */
uint8_t i, r; /* interrupt vector, memory refresh */
/* flags: sign, zero, yf, half-carry, xf, parity/overflow, negative, carry */
bool sf : 1, zf : 1, yf : 1, hf : 1, xf : 1, pf : 1, nf : 1, cf : 1;
uint8_t iff_delay;
uint8_t interrupt_mode;
uint8_t int_data;
bool iff1 : 1, iff2 : 1;
bool halted : 1;
bool int_pending : 1, nmi_pending : 1;
};
void z80_init(z80* const z);
void z80_step(z80* const z);
void z80_debug_output(z80* const z);
void z80_gen_nmi(z80* const z);
void z80_gen_int(z80* const z, uint8_t state, uint8_t data);
#endif /* Z80_Z80_H_ */