-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathz80.h
152 lines (130 loc) · 4.97 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* MIT License
*
* Copyright (c) 2017 Mockba the Borg
*
* 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 conditions:
*
* 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_H
#define Z80_H
#include <stdint.h>
#include "globals.h"
#include "console.h"
typedef struct {
int32_t pcx; /* external view of PC */
int32_t af; /* AF register */
int32_t bc; /* BC register */
int32_t de; /* DE register */
int32_t hl; /* HL register */
int32_t ix; /* IX register */
int32_t iy; /* IY register */
int32_t pc; /* program counter */
int32_t sp; /* SP register */
int32_t af1; /* alternate AF register */
int32_t bc1; /* alternate BC register */
int32_t de1; /* alternate DE register */
int32_t hl1; /* alternate HL register */
int32_t iff; /* Interrupt Flip Flop */
int32_t ir; /* Interrupt (upper) / Refresh (lower) register */
int32_t status; /* Status of the CPU 0=running 1=end request 2=back to CCP */
int32_t debug;
int32_t brk;
int32_t step;
#if defined(DEBUG) || defined(iDEBUG)
int32_t watch;
#endif
#ifdef iDEBUG
FILE *iLogFile;
char iLogBuffer[16];
const char *iLogTxt;
#endif
void *intercept_ctx;
void (*intercept)(void *);
#ifdef RAM_FAST
uint8_t RAM[MEMSIZE];
#endif
} z80;
#define PCX cpu->pcx
#define AF cpu->af
#define BC cpu->bc
#define DE cpu->de
#define HL cpu->hl
#define IX cpu->ix
#define IY cpu->iy
#define PC cpu->pc
#define SP cpu->sp
#define AF1 cpu->af1
#define BC1 cpu->bc1
#define DE1 cpu->de1
#define HL1 cpu->hl1
#define IFF cpu->iff
#define IR cpu->ir
/*
Functions needed by the soft CPU implementation
*/
void cpu_out(z80 *cpu, const uint32_t Port, const uint32_t Value);
uint32_t cpu_in(z80 *cpu, const uint32_t Port);
/* Z80 Custom soft core */
/* simulator stop codes */
#define STOP_HALT 0 /* HALT */
#define STOP_IBKPT 1 /* breakpoint (program counter) */
#define STOP_MEM 2 /* breakpoint (memory access) */
#define STOP_INSTR 3 /* breakpoint (instruction access) */
#define STOP_OPCODE 4 /* invalid operation encountered (8080, Z80, 8086) */
#define ADDRMASK 0xffff
#define FLAG_C 1
#define FLAG_N 2
#define FLAG_P 4
#define FLAG_H 16
#define FLAG_Z 64
#define FLAG_S 128
#define SETFLAG(f,c) (AF = (c) ? AF | FLAG_ ## f : AF & ~FLAG_ ## f)
#define TSTFLAG(f) ((AF & FLAG_ ## f) != 0)
#define PARITY(x) parityTable[(x) & 0xff]
#define SET_PVS(s) (((cbits >> 6) ^ (cbits >> 5)) & 4)
#define SET_PV (SET_PVS(sum))
#define SET_PV2(x) ((temp == (x)) << 2)
#define POP(x) { \
register uint32_t y = RAM_PP(SP); \
x = y + (RAM_PP(SP) << 8); \
}
#define JPC(cond) { \
if (cond) { \
PC = GET_WORD(PC); \
} else { \
PC += 2; \
} \
}
#define CALLC(cond) { \
if (cond) { \
register uint32_t adrr = GET_WORD(PC); \
PUSH(PC + 2); \
PC = adrr; \
} else { \
PC += 2; \
} \
}
z80 *z80_new();
void z80_set_intercept(z80 *cpu, void *intercept_ctx,
void (*intercept)(void *));
void z80_reset(z80 *cpu);
void z80_debug(z80 *cpu);
void z80_run(z80 *cpu);
void z80_destroy(z80 *cpu);
#endif