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.
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. */
31 void profile_z80(int addr
, int ticks
);
33 void PRNM(pushpc
)(void)
46 static int parity(int b
)
52 for(i
= 8; i
; i
--) par
^= (b
& 1), b
>>= 1;
56 void PRNM(local_init
)(void)
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
++) {
99 z80c_addf_tbl
[i
] |= SF
;
100 z80c_subf_tbl
[i
] |= SF
;
103 z80c_addf_tbl
[i
] |= B5F
;
104 z80c_subf_tbl
[i
] |= B5F
;
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
;
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
);
137 SPECP(fe_inport_high
) = SPNM(fe_inport_high
);
143 int PRNM(step
)(int tc
)
151 DANM(rl7
) = RR
& 0x80;
153 if(DANM(haltstate
)) {
155 nn
= (DANM(tc
) - 1) / 4 + 1;
165 int startTC
= DANM(tc
);
175 z80p
= (*z80c_op_tab
[nextop
])(z80p
);
177 (*z80c_op_tab
[nextop
])();
181 profile_z80(pc
, startTC
- DANM(tc
));
185 } while(DANM(tc
) > 0);
187 RR
= (RR
& 0x7F) | DANM(rl7
);