Rearange menu of mpegplayer. Add new menu with "settings" and "quit", and remove...
[kugel-rb.git] / apps / plugins / zxbox / z80_step.c
blob803079c9702dfd9eb37d3082b609d5f8cf20a12b
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];
30 void PRNM(pushpc)(void)
32 #ifdef PROCP
33 Z80 *z80p;
34 z80p = &PRNM(proc);
35 #endif
37 SP--;
38 PUTMEM(SP, SPP, PCH);
39 SP--;
40 PUTMEM(SP, SPP, PCL);
43 static int parity(int b)
45 int i;
46 int par;
48 par = 0;
49 for(i = 8; i; i--) par ^= (b & 1), b >>= 1;
50 return par;
53 void PRNM(local_init)(void)
55 int i;
57 #ifdef PROCP
58 Z80 *z80p;
59 z80p = &PRNM(proc);
60 #endif
62 for(i = 0; i < 0x100; i++) {
63 z80c_incf_tbl[i] = z80c_decf_tbl[i] = z80c_orf_tbl[i] = 0;
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);
69 if(!parity(i)) z80c_orf_tbl[i] |= PVF;
72 z80c_incf_tbl[0] |= ZF;
73 z80c_decf_tbl[0] |= ZF;
74 z80c_orf_tbl[0] |= ZF;
76 z80c_incf_tbl[0x80] |= PVF;
77 z80c_decf_tbl[0x7F] |= PVF;
79 for(i = 0; i < 0x100; i++) {
80 int cr, c1, c2;
81 int hr, h1, h2;
82 int b5r;
84 cr = i & 0x80;
85 c1 = i & 0x40;
86 b5r = i & 0x20;
87 c2 = i & 0x10;
89 hr = i & 0x08;
90 h1 = i & 0x04;
91 h2 = i & 0x01;
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;
99 if(b5r) {
100 z80c_addf_tbl[i] |= B5F;
101 z80c_subf_tbl[i] |= B5F;
103 if(hr) {
104 z80c_addf_tbl[i] |= B3F;
105 z80c_subf_tbl[i] |= B3F;
108 if((c1 && c2) || (!cr && (c1 || c2))) z80c_addf_tbl[i] |= CF;
109 if((h1 && h2) || (!hr && (h1 || h2))) z80c_addf_tbl[i] |= HF;
111 if((!c1 && !c2 && cr) || (c1 && c2 && !cr)) z80c_addf_tbl[i] |= PVF;
114 if((c2 && cr) || (!c1 && (c2 || cr))) z80c_subf_tbl[i] |= CF;
115 if((h2 && hr) || (!h1 && (h2 || hr))) z80c_subf_tbl[i] |= HF;
117 if((!c2 && !cr && c1) || (c2 && cr && !c1)) z80c_subf_tbl[i] |= PVF;
120 z80c_subf_tbl[i] |= NF;
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;
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
140 int PRNM(step)(int tc)
142 #ifdef PROCP
143 Z80 *z80p;
144 z80p = &PRNM(proc);
145 #endif
147 DANM(tc) = tc;
148 DANM(rl7) = RR & 0x80;
150 if(DANM(haltstate)) {
151 register int nn;
152 nn = (DANM(tc) - 1) / 4 + 1;
154 DANM(tc) -= 4 * nn;
155 RR += nn;
157 else do {
158 register int nextop;
160 #ifdef DEBUG_Z80
161 debug_z80();
162 #endif
163 nextop = *PCP;
164 PC++;
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);
174 RR = (RR & 0x7F) | DANM(rl7);
175 return DANM(tc);