Hackfix and re-enable strtoull and wcstoull, see bug #3798.
[sdcc.git] / sdcc-extra / emu / rrz80 / cpu / z80_step.c
blob5b6ba2367da5a9350f5f436ca5b0f3e746f37b07
1 /*
2 * Copyright (C) 1996-1998 Szeredi Miklos
3 * Email: mszeredi@inf.bme.hu
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.
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.
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.
21 #include "z80_def.h"
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];
29 /* PENDING: Forward definitions. */
30 void debug_z80(void);
31 void profile_z80(int addr, int ticks);
33 void PRNM(pushpc)(void)
35 #ifdef PROCP
36 Z80 *z80p;
37 z80p = &PRNM(proc);
38 #endif
40 SP--;
41 PUTMEM(SP, SPP, PCH);
42 SP--;
43 PUTMEM(SP, SPP, PCL);
46 static int parity(int b)
48 int i;
49 int par;
51 par = 0;
52 for(i = 8; i; i--) par ^= (b & 1), b >>= 1;
53 return par;
56 void PRNM(local_init)(void)
58 int i;
60 #ifdef PROCP
61 Z80 *z80p;
62 z80p = &PRNM(proc);
63 #endif
65 for(i = 0; i < 0x100; i++) {
66 z80c_incf_tbl[i] = z80c_decf_tbl[i] = z80c_orf_tbl[i] = 0;
68 z80c_orf_tbl[i] |= i & (SF | B3F | B5F);
69 z80c_incf_tbl[i] |= i & (SF | B3F | B5F);
70 z80c_decf_tbl[i] |= i & (SF | B3F | B5F);
72 if(!parity(i)) z80c_orf_tbl[i] |= PVF;
75 z80c_incf_tbl[0] |= ZF;
76 z80c_decf_tbl[0] |= ZF;
77 z80c_orf_tbl[0] |= ZF;
79 z80c_incf_tbl[0x80] |= PVF;
80 z80c_decf_tbl[0x7F] |= PVF;
82 for(i = 0; i < 0x100; i++) {
83 int cr, c1, c2;
84 int hr, h1, h2;
85 int b5r;
87 cr = i & 0x80;
88 c1 = i & 0x40;
89 b5r = i & 0x20;
90 c2 = i & 0x10;
92 hr = i & 0x08;
93 h1 = i & 0x04;
94 h2 = i & 0x01;
96 z80c_addf_tbl[i] = 0;
97 z80c_subf_tbl[i] = 0;
98 if(cr) {
99 z80c_addf_tbl[i] |= SF;
100 z80c_subf_tbl[i] |= SF;
102 if(b5r) {
103 z80c_addf_tbl[i] |= B5F;
104 z80c_subf_tbl[i] |= B5F;
106 if(hr) {
107 z80c_addf_tbl[i] |= B3F;
108 z80c_subf_tbl[i] |= B3F;
111 if((c1 && c2) || (!cr && (c1 || c2))) z80c_addf_tbl[i] |= CF;
112 if((h1 && h2) || (!hr && (h1 || h2))) z80c_addf_tbl[i] |= HF;
114 if((!c1 && !c2 && cr) || (c1 && c2 && !cr)) z80c_addf_tbl[i] |= PVF;
117 if((c2 && cr) || (!c1 && (c2 || cr))) z80c_subf_tbl[i] |= CF;
118 if((h2 && hr) || (!h1 && (h2 || hr))) z80c_subf_tbl[i] |= HF;
120 if((!c2 && !cr && c1) || (c2 && cr && !c1)) z80c_subf_tbl[i] |= PVF;
123 z80c_subf_tbl[i] |= NF;
127 #ifdef PROCP
128 TAB(incf_tbl) = z80c_incf_tbl;
129 TAB(decf_tbl) = z80c_decf_tbl;
130 TAB(addf_tbl) = z80c_addf_tbl;
131 TAB(subf_tbl) = z80c_subf_tbl;
132 TAB(orf_tbl) = z80c_orf_tbl;
134 PORT(inports) = PRNM(inports);
135 PORT(outports) = PRNM(outports);
136 #ifdef SPECT_MEM
137 SPECP(fe_inport_high) = SPNM(fe_inport_high);
138 #endif
139 #endif
143 int PRNM(step)(int tc)
145 #ifdef PROCP
146 Z80 *z80p;
147 z80p = &PRNM(proc);
148 #endif
150 DANM(tc) = tc;
151 DANM(rl7) = RR & 0x80;
153 if(DANM(haltstate)) {
154 register int nn;
155 nn = (DANM(tc) - 1) / 4 + 1;
157 DANM(tc) -= 4 * nn;
158 RR += nn;
160 else do {
161 register int nextop;
163 #if !DISABLE_PROFILE
164 int pc = PC;
165 int startTC = DANM(tc);
166 #endif
168 #ifdef DEBUG_Z80
169 debug_z80();
170 #endif
171 nextop = *PCP;
172 PC++;
174 #ifdef PROCP
175 z80p = (*z80c_op_tab[nextop])(z80p);
176 #else
177 (*z80c_op_tab[nextop])();
178 #endif
180 #if !DISABLE_PROFILE
181 profile_z80(pc, startTC - DANM(tc));
182 #endif
184 RR++;
185 } while(DANM(tc) > 0);
187 RR = (RR & 0x7F) | DANM(rl7);
188 return DANM(tc);