-
Notifications
You must be signed in to change notification settings - Fork 1
/
simz80.h
129 lines (106 loc) · 3.09 KB
/
simz80.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
/* Header file for the instruction set simulator.
Copyright (C) 1995 Frank D. Cringle.
This file is part of yaze - yet another Z80 emulator.
Yaze is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* $Id: simz80.h,v 1.4 2004/04/23 09:50:15 fdc Exp $ */
#include <limits.h>
#if UCHAR_MAX == 255
typedef unsigned char BYTE;
#else
#error Need to find an 8-bit type for BYTE
#endif
#if USHRT_MAX == 65535
typedef unsigned short WORD;
#else
#error Need to find an 16-bit type for WORD
#endif
/* FASTREG needs to be at least 16 bits wide and efficient for the
host architecture */
#if UINT_MAX >= 65535
typedef unsigned int FASTREG;
#else
typedef unsigned long FASTREG;
#endif
/* FASTWORK needs to be wider than 16 bits and efficient for the host
architecture */
#if UINT_MAX > 65535
typedef unsigned int FASTWORK;
#else
typedef unsigned long FASTWORK;
#endif
/* accessible by the monitor */
extern char *perl_params;
/* two sets of accumulator / flags */
extern WORD af[2];
extern int af_sel;
/* two sets of 16-bit registers */
extern struct ddregs {
WORD bc;
WORD de;
WORD hl;
} regs[2];
extern int regs_sel;
extern WORD ir;
extern WORD ix;
extern WORD iy;
extern WORD sp;
extern WORD pc;
extern WORD IFF;
extern WORD IM;
#ifndef MEMSIZE
#define MEMSIZE 64
#endif
extern BYTE ram[MEMSIZE*1024];
#ifdef MMU
extern BYTE *pagetable[16];
#endif
#ifdef DEBUG
extern volatile int stopsim;
#endif
extern FASTWORK simz80(FASTREG PC);
#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 ldig(x) ((x) & 0xf)
#define hdig(x) (((x)>>4)&0xf)
#define lreg(x) ((x)&0xff)
#define hreg(x) (((x)>>8)&0xff)
#define Setlreg(x, v) x = (((x)&0xff00) | ((v)&0xff))
#define Sethreg(x, v) x = (((x)&0xff) | (((v)&0xff) << 8))
#ifdef MMU
#define RAM(a) *(pagetable[((a)&0xffff)>>12]+((a)&0x0fff))
#else
#define RAM(a) ram[(a)&0xffff]
#endif
#define GetBYTE(a) RAM(a)
#define PutBYTE(a, v) RAM(a) = v
#define GetWORD(a) (RAM(a) | (RAM((a)+1) << 8))
#define PutWORD(a, v) \
do { RAM(a) = (BYTE)(v); \
RAM((a)+1) = (v) >> 8; \
} while (0)
#ifndef BIOS
extern int in(unsigned int);
extern void out(unsigned int, unsigned char);
#define Input(port) in(port)
#define Output(port, value) out(port,value)
#else
/* Define these as macros or functions if you really want to simulate I/O */
#define Input(port) 0
#define Output(port, value)
#endif