diff options
Diffstat (limited to 'apps/plugins/zxbox/z80_step.c')
-rw-r--r-- | apps/plugins/zxbox/z80_step.c | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/apps/plugins/zxbox/z80_step.c b/apps/plugins/zxbox/z80_step.c new file mode 100644 index 0000000000..803079c970 --- /dev/null +++ b/apps/plugins/zxbox/z80_step.c | |||
@@ -0,0 +1,176 @@ | |||
1 | /* | ||
2 | * Copyright (C) 1996-1998 Szeredi Miklos | ||
3 | * Email: mszeredi@inf.bme.hu | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. See the file COPYING. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
18 | * | ||
19 | */ | ||
20 | |||
21 | #include "z80_def.h" | ||
22 | |||
23 | byte z80c_incf_tbl[256]; | ||
24 | byte z80c_decf_tbl[256]; | ||
25 | byte z80c_addf_tbl[256]; | ||
26 | byte z80c_subf_tbl[256]; | ||
27 | byte z80c_orf_tbl[256]; | ||
28 | |||
29 | |||
30 | void PRNM(pushpc)(void) | ||
31 | { | ||
32 | #ifdef PROCP | ||
33 | Z80 *z80p; | ||
34 | z80p = &PRNM(proc); | ||
35 | #endif | ||
36 | |||
37 | SP--; | ||
38 | PUTMEM(SP, SPP, PCH); | ||
39 | SP--; | ||
40 | PUTMEM(SP, SPP, PCL); | ||
41 | } | ||
42 | |||
43 | static int parity(int b) | ||
44 | { | ||
45 | int i; | ||
46 | int par; | ||
47 | |||
48 | par = 0; | ||
49 | for(i = 8; i; i--) par ^= (b & 1), b >>= 1; | ||
50 | return par; | ||
51 | } | ||
52 | |||
53 | void PRNM(local_init)(void) | ||
54 | { | ||
55 | int i; | ||
56 | |||
57 | #ifdef PROCP | ||
58 | Z80 *z80p; | ||
59 | z80p = &PRNM(proc); | ||
60 | #endif | ||
61 | |||
62 | for(i = 0; i < 0x100; i++) { | ||
63 | z80c_incf_tbl[i] = z80c_decf_tbl[i] = z80c_orf_tbl[i] = 0; | ||
64 | |||
65 | z80c_orf_tbl[i] |= i & (SF | B3F | B5F); | ||
66 | z80c_incf_tbl[i] |= i & (SF | B3F | B5F); | ||
67 | z80c_decf_tbl[i] |= i & (SF | B3F | B5F); | ||
68 | |||
69 | if(!parity(i)) z80c_orf_tbl[i] |= PVF; | ||
70 | } | ||
71 | |||
72 | z80c_incf_tbl[0] |= ZF; | ||
73 | z80c_decf_tbl[0] |= ZF; | ||
74 | z80c_orf_tbl[0] |= ZF; | ||
75 | |||
76 | z80c_incf_tbl[0x80] |= PVF; | ||
77 | z80c_decf_tbl[0x7F] |= PVF; | ||
78 | |||
79 | for(i = 0; i < 0x100; i++) { | ||
80 | int cr, c1, c2; | ||
81 | int hr, h1, h2; | ||
82 | int b5r; | ||
83 | |||
84 | cr = i & 0x80; | ||
85 | c1 = i & 0x40; | ||
86 | b5r = i & 0x20; | ||
87 | c2 = i & 0x10; | ||
88 | |||
89 | hr = i & 0x08; | ||
90 | h1 = i & 0x04; | ||
91 | h2 = i & 0x01; | ||
92 | |||
93 | z80c_addf_tbl[i] = 0; | ||
94 | z80c_subf_tbl[i] = 0; | ||
95 | if(cr) { | ||
96 | z80c_addf_tbl[i] |= SF; | ||
97 | z80c_subf_tbl[i] |= SF; | ||
98 | } | ||
99 | if(b5r) { | ||
100 | z80c_addf_tbl[i] |= B5F; | ||
101 | z80c_subf_tbl[i] |= B5F; | ||
102 | } | ||
103 | if(hr) { | ||
104 | z80c_addf_tbl[i] |= B3F; | ||
105 | z80c_subf_tbl[i] |= B3F; | ||
106 | } | ||
107 | |||
108 | if((c1 && c2) || (!cr && (c1 || c2))) z80c_addf_tbl[i] |= CF; | ||
109 | if((h1 && h2) || (!hr && (h1 || h2))) z80c_addf_tbl[i] |= HF; | ||
110 | |||
111 | if((!c1 && !c2 && cr) || (c1 && c2 && !cr)) z80c_addf_tbl[i] |= PVF; | ||
112 | |||
113 | |||
114 | if((c2 && cr) || (!c1 && (c2 || cr))) z80c_subf_tbl[i] |= CF; | ||
115 | if((h2 && hr) || (!h1 && (h2 || hr))) z80c_subf_tbl[i] |= HF; | ||
116 | |||
117 | if((!c2 && !cr && c1) || (c2 && cr && !c1)) z80c_subf_tbl[i] |= PVF; | ||
118 | |||
119 | |||
120 | z80c_subf_tbl[i] |= NF; | ||
121 | } | ||
122 | |||
123 | |||
124 | #ifdef PROCP | ||
125 | TAB(incf_tbl) = z80c_incf_tbl; | ||
126 | TAB(decf_tbl) = z80c_decf_tbl; | ||
127 | TAB(addf_tbl) = z80c_addf_tbl; | ||
128 | TAB(subf_tbl) = z80c_subf_tbl; | ||
129 | TAB(orf_tbl) = z80c_orf_tbl; | ||
130 | |||
131 | PORT(inports) = PRNM(inports); | ||
132 | PORT(outports) = PRNM(outports); | ||
133 | #ifdef SPECT_MEM | ||
134 | SPECP(fe_inport_high) = SPNM(fe_inport_high); | ||
135 | #endif | ||
136 | #endif | ||
137 | } | ||
138 | |||
139 | |||
140 | int PRNM(step)(int tc) | ||
141 | { | ||
142 | #ifdef PROCP | ||
143 | Z80 *z80p; | ||
144 | z80p = &PRNM(proc); | ||
145 | #endif | ||
146 | |||
147 | DANM(tc) = tc; | ||
148 | DANM(rl7) = RR & 0x80; | ||
149 | |||
150 | if(DANM(haltstate)) { | ||
151 | register int nn; | ||
152 | nn = (DANM(tc) - 1) / 4 + 1; | ||
153 | |||
154 | DANM(tc) -= 4 * nn; | ||
155 | RR += nn; | ||
156 | } | ||
157 | else do { | ||
158 | register int nextop; | ||
159 | |||
160 | #ifdef DEBUG_Z80 | ||
161 | debug_z80(); | ||
162 | #endif | ||
163 | nextop = *PCP; | ||
164 | PC++; | ||
165 | |||
166 | #ifdef PROCP | ||
167 | z80p = (*z80c_op_tab[nextop])(z80p); | ||
168 | #else | ||
169 | (*z80c_op_tab[nextop])(); | ||
170 | #endif | ||
171 | RR++; | ||
172 | } while(DANM(tc) > 0); | ||
173 | |||
174 | RR = (RR & 0x7F) | DANM(rl7); | ||
175 | return DANM(tc); | ||
176 | } | ||