Reorganized/sorted some of the known programs
[virtual-nascom.git] / simz80.h
blob5021da08a3e70a7510b16e8290449eb88ea38a7e
1 /* Header file for the instruction set simulator.
2 Copyright (C) 1995 Frank D. Cringle.
4 This file is part of yaze - yet another Z80 emulator.
6 Yaze is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 #include <limits.h>
22 #if UCHAR_MAX == 255
23 typedef unsigned char BYTE;
24 #else
25 #error Need to find an 8-bit type for BYTE
26 #endif
28 #if USHRT_MAX == 65535
29 typedef unsigned short WORD;
30 #else
31 #error Need to find an 16-bit type for WORD
32 #endif
34 /* FASTREG needs to be at least 16 bits wide and efficient for the
35 host architecture */
36 #if UINT_MAX >= 65535
37 typedef unsigned int FASTREG;
38 #else
39 typedef unsigned long FASTREG;
40 #endif
42 /* FASTWORK needs to be wider than 16 bits and efficient for the host
43 architecture */
44 #if UINT_MAX > 65535
45 typedef unsigned int FASTWORK;
46 #else
47 typedef unsigned long FASTWORK;
48 #endif
50 /* two sets of accumulator / flags */
51 extern WORD af[2];
52 extern int af_sel;
54 /* two sets of 16-bit registers */
55 extern struct ddregs {
56 WORD bc;
57 WORD de;
58 WORD hl;
59 } regs[2];
60 extern int regs_sel;
62 extern WORD ir;
63 extern WORD ix;
64 extern WORD iy;
65 extern WORD sp;
66 extern WORD pc;
67 extern WORD IFF;
69 #ifndef MEMSIZE
70 #define MEMSIZE 64
71 #endif
72 extern BYTE ram[MEMSIZE*1024];
73 #ifdef MMU
74 extern BYTE *pagetable[MEMSIZE/4];
75 #endif
77 #ifdef DEBUG
78 extern volatile int stopsim;
79 #endif
81 extern FASTWORK simz80(FASTREG PC, int, int (*)());
83 #define FLAG_C 1
84 #define FLAG_N 2
85 #define FLAG_P 4
86 #define FLAG_H 16
87 #define FLAG_Z 64
88 #define FLAG_S 128
90 #define SETFLAG(f,c) AF = (c) ? AF | FLAG_ ## f : AF & ~FLAG_ ## f
91 #define TSTFLAG(f) ((AF & FLAG_ ## f) != 0)
93 #define ldig(x) ((x) & 0xf)
94 #define hdig(x) (((x)>>4)&0xf)
95 #define lreg(x) ((x)&0xff)
96 #define hreg(x) (((x)>>8)&0xff)
98 #define Setlreg(x, v) x = (((x)&0xff00) | ((v)&0xff))
99 #define Sethreg(x, v) x = (((x)&0xff) | (((v)&0xff) << 8))
101 #ifdef MMU
102 #define RAM(a) *(pagetable[((a)&0xffff)>>12]+((a)&0x0fff))
103 #else
104 #define RAM(a) ram[(a)&0xffff]
105 #endif
106 #define GetBYTE(a) RAM(a)
108 /* Fast write inside [3K; 64K-8K]
110 NOTICE: This is dependent on the assumption that the 8KB Basic ROM
111 is present
114 void slow_write(unsigned int a, unsigned char v);
115 #define PutBYTE(a,v) \
116 do { \
117 if (((a + 8192) & 0xFFFF) > 11*1024) \
118 RAM(a) = v; \
119 else \
120 slow_write(a,v); \
121 } while (0)
123 /*#define PutBYTE(a, v) RAM(a) = v*/
125 #define GetWORD(a) (RAM(a) | (RAM((a)+1) << 8))
126 #define PutWORD(a, v) \
127 do { PutBYTE(a, ((int)(v)&255)); \
128 PutBYTE((a)+1, (v) >> 8); \
129 } while (0)
131 #ifndef BIOS
132 extern int in(unsigned int);
133 extern void out(unsigned int, unsigned char);
134 #define Input(port) in(port)
135 #define Output(port, value) out(port,value)
136 #else
137 /* Define these as macros or functions if you really want to simulate I/O */
138 #define Input(port) 0
139 #define Output(port, value)
140 #endif