Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1814 | yogev_ezra | 1 | /*===================================================================== |
2 | z80.c -> Header file related to the Z80 emulation code. |
||
3 | |||
4 | Please read documentation files to know how this works :) |
||
5 | |||
6 | Thanks to Marat Fayzullin for writing the "How to write a Computer |
||
7 | Eemulator" HOWTO. This emulator is based on his tutorials and the |
||
8 | code organization (very readable!) of his "Z80 Portable Emulator". |
||
9 | I've learnt a lot from it, and I've taken some ideas of his code |
||
10 | to write this emulator.I think that almost all of the undocumented |
||
11 | Z80 opcodes are covered on this emulator. I also asked Marat |
||
12 | Fayzullin (by email) about ideas and so on (his Z80 emulator is |
||
13 | quite good, so go check it :-). |
||
14 | |||
15 | Of course, I can't forget Raśl Gomez (he answered me thousands |
||
16 | of email questions) and Philip Kendall. Whitout his ___kind___ |
||
17 | people surely you won't be reading this file now... |
||
18 | |||
19 | "Programming the Z80" (from Rodnay Zaks) and the comp.sys.sinclair |
||
20 | FAQ were another excelent sources of info! |
||
21 | |||
22 | This program is free software; you can redistribute it and/or modify |
||
23 | it under the terms of the GNU General Public License as published by |
||
24 | the Free Software Foundation; either version 2 of the License, or |
||
25 | (at your option) any later version. |
||
26 | |||
27 | This program is distributed in the hope that it will be useful, |
||
28 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
29 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
30 | GNU General Public License for more details. |
||
31 | |||
32 | You should have received a copy of the GNU General Public License |
||
33 | along with this program; if not, write to the Free Software |
||
34 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
||
35 | |||
36 | Copyright (c) 2000 Santiago Romero Iglesias. |
||
37 | Email: sromero@escomposlinux.org |
||
38 | ======================================================================*/ |
||
39 | |||
40 | |||
41 | #ifndef Z80_H |
||
42 | #define Z80_H |
||
43 | |||
44 | #define USING_ALLEGRO |
||
45 | |||
46 | #define DEBUG |
||
47 | #define _DEV_DEBUG_ /* development debugging */ |
||
48 | #define LOW_ENDIAN |
||
49 | /*#define HI_ENDIAN */ |
||
50 | |||
51 | /* Used by the Z80Debug() function */ |
||
52 | #define DEBUG_OK 1 |
||
53 | #define DEBUG_QUIT 0 |
||
54 | |||
55 | |||
56 | #define video vscreen |
||
57 | |||
58 | |||
59 | /*=== Some common standard data types: ==============================*/ |
||
60 | typedef unsigned char byte; |
||
61 | typedef unsigned short word; |
||
62 | typedef unsigned long dword; |
||
63 | typedef signed char offset; |
||
64 | |||
65 | |||
66 | /*--- Thanks to Philip Kendall for it's help using the flags --------*/ |
||
67 | extern byte halfcarry_add_table[]; |
||
68 | extern byte halfcarry_sub_table[]; |
||
69 | extern byte overflow_add_table[]; |
||
70 | extern byte overflow_sub_table[]; |
||
71 | extern byte sz53_table[]; |
||
72 | extern byte sz53p_table[]; |
||
73 | extern byte parity_table[]; |
||
74 | |||
75 | extern byte ioblock_inc1_table[]; |
||
76 | extern byte ioblock_dec1_table[]; |
||
77 | extern byte ioblock_2_table[]; |
||
78 | |||
79 | |||
80 | /*===================================================================== |
||
81 | Z80 Flag Register: --------------------------------- |
||
82 | | 7 6 5 4 3 2 1 0 | |
||
83 | --------------------------------- |
||
84 | | S Z x H x O/P N C | |
||
85 | --------------------------------- |
||
86 | If (1) means that: S = Negative result. |
||
87 | Z = Zero result. |
||
88 | x = special cases (by opcode) |
||
89 | H = Halfcarry/borrow. |
||
90 | O/P = Overflow/Parity Flag. |
||
91 | N = Substraction. |
||
92 | C = Carry/borrow. |
||
93 | ====================================================================*/ |
||
94 | #define S_FLAG 0x80 |
||
95 | #define Z_FLAG 0x40 |
||
96 | #define H_FLAG 0x10 |
||
97 | #define P_FLAG 0x04 |
||
98 | #define O_FLAG 0x04 |
||
99 | #define N_FLAG 0x02 |
||
100 | #define C_FLAG 0x01 |
||
101 | |||
102 | |||
103 | /* |
||
104 | Defines for interrupts and special Z80Hardware() codes: |
||
105 | ======================================================================= |
||
106 | INT_QUIT = Exit the emulation (for Z80Run()) |
||
107 | INT_NOINT = No interrupt required |
||
108 | INT_IRQ = Standard RST 38h interrupt |
||
109 | INT_NMI = Non-maskerable interrupt |
||
110 | */ |
||
111 | #define INT_QUIT 0xFFFE |
||
112 | #define INT_NOINT 0xFFFF |
||
113 | #define INT_IRQ 0x0038 |
||
114 | #define INT_NMI 0x0066 |
||
115 | |||
116 | |||
117 | |||
118 | /*=== A register is defined as follows: =============================*/ |
||
119 | typedef union |
||
120 | { |
||
121 | #ifdef LOW_ENDIAN |
||
122 | struct |
||
123 | { |
||
124 | byte l,h; |
||
125 | } B; |
||
126 | #else |
||
127 | struct |
||
128 | { |
||
129 | byte h,l; |
||
130 | } B; |
||
131 | #endif |
||
132 | word W; |
||
133 | } eword; |
||
134 | |||
135 | |||
136 | #define WE_ARE_ON_DD 1 |
||
137 | #define WE_ARE_ON_FD 2 |
||
138 | |||
139 | /*=== Now we define the Z80 registers using the previous definition =*/ |
||
140 | typedef struct |
||
141 | { |
||
142 | char machine_type; |
||
143 | byte *RAM; |
||
144 | int we_are_on_ddfd; |
||
145 | |||
146 | /* general and shadow z80 registers */ |
||
147 | eword AF, BC, DE, HL, IX, IY, PC, SP, R, |
||
148 | AFs, BCs, DEs, HLs; |
||
149 | |||
150 | /* IFF and I registers, used on interrupts. */ |
||
151 | byte IFF1, IFF2, I, halted; |
||
152 | char IM; |
||
153 | word IRequest; |
||
154 | |||
155 | /* the following is to take care of cycle counting */ |
||
156 | int IPeriod, ICount, IBackup; |
||
157 | |||
158 | /* DecodingErrors = set this to 1 for debugging purposes in order |
||
159 | to trap undocumented or non implemented opcodes. |
||
160 | Trace = set this to 1 to start tracing. It's also set |
||
161 | when PC reaches TrapAddress value. */ |
||
162 | byte DecodingErrors; |
||
163 | word TrapAddress; |
||
164 | byte Trace, dobreak; |
||
165 | byte BorderColor; |
||
166 | |||
167 | } Z80Regs; |
||
168 | |||
169 | |||
170 | /*==================================================================== |
||
171 | Function declarations, read the .c file to know what they do. |
||
172 | ===================================================================*/ |
||
173 | void Z80Reset( register Z80Regs *regs, int ); |
||
174 | void Z80Interrupt( register Z80Regs *, register word ); |
||
175 | word Z80Run( register Z80Regs *, int ); |
||
176 | byte Z80MemRead( register word, Z80Regs * ); |
||
177 | void Z80MemWrite( register word, register byte, Z80Regs * ); |
||
178 | byte Z80InPort( register word ); |
||
179 | void Z80OutPort( register Z80Regs *regs, register word, register byte ); |
||
180 | void Z80Patch( register Z80Regs * ); |
||
181 | byte Z80Debug( register Z80Regs * ); |
||
182 | word Z80Hardware( register Z80Regs * ); |
||
183 | |||
184 | void Z80FlagTables(void); |
||
185 | word ParseOpcode( char *, char *, char *, word, Z80Regs * ); |
||
186 | word Z80Dissasembler ( Z80Regs *, char *, char * ); |
||
187 | |||
188 | #endif |