2011-07-18 19:48:57 +00:00
|
|
|
/**
|
|
|
|
** Supermodel
|
|
|
|
** A Sega Model 3 Arcade Emulator.
|
2011-09-14 19:08:43 +00:00
|
|
|
** Copyright 2011 Bart Trzynadlowski, Nik Henson
|
2011-07-18 19:48:57 +00:00
|
|
|
**
|
|
|
|
** This file is part of Supermodel.
|
|
|
|
**
|
|
|
|
** Supermodel is free software: you can redistribute it and/or modify it under
|
|
|
|
** the terms of the GNU General Public License as published by the Free
|
|
|
|
** Software Foundation, either version 3 of the License, or (at your option)
|
|
|
|
** any later version.
|
|
|
|
**
|
|
|
|
** Supermodel is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
** more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License along
|
|
|
|
** with Supermodel. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Z80.cpp
|
|
|
|
*
|
|
|
|
* Z80 instruction set simulator.
|
|
|
|
* Copyright (C) 1995 Frank D. Cringle.
|
|
|
|
* Adapted for use in Supermodel by Bart Trzynadlowski (July 15, 2011).
|
|
|
|
*
|
|
|
|
* Please see Z80.h for a discussion of known inaccuracies.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cstdio> // for NULL
|
2011-08-09 18:36:29 +00:00
|
|
|
#include "Supermodel.h"
|
2011-09-18 22:21:14 +00:00
|
|
|
#include "Z80.h" // must include this first to define CZ80
|
2011-07-18 19:48:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
Internal Helper Macros
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
// Address space access
|
|
|
|
#define GetBYTE(a) ( Bus->Read8(a&0xFFFF) )
|
|
|
|
#define GetBYTE_pp(a) ( Bus->Read8(((a)++)&0xFFFF) )
|
|
|
|
#define GetBYTE_mm(a) ( Bus->Read8(((a)--)&0xFFFF) )
|
|
|
|
#define mm_GetBYTE(a) ( Bus->Read8((--(a))&0xFFFF) )
|
|
|
|
|
|
|
|
#define PutBYTE(a,v) Bus->Write8((a)&0xFFFF,v)
|
|
|
|
#define PutBYTE_pp(a,v) Bus->Write8(((a)++)&0xFFFF,v)
|
|
|
|
#define PutBYTE_mm(a,v) Bus->Write8(((a)--)&0xFFFF,v)
|
|
|
|
#define mm_PutBYTE(a,v) Bus->Write8((--(a))&0xFFFF,v)
|
|
|
|
|
|
|
|
#define GetWORD(a) (Bus->Read8((a)&0xFFFF) | (Bus->Read8(((a)+1)&0xFFFF)<<8))
|
|
|
|
|
|
|
|
#define PutWORD(a, v) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
PutBYTE((a),(v)&0xFF); \
|
|
|
|
PutBYTE((a)+1,((v)>>8)); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define OUTPUT(a,v) Bus->IOWrite8((a)&0xFF,v)
|
|
|
|
#define INPUT(a) ( Bus->IORead8((a)&0xFF) )
|
|
|
|
|
|
|
|
// Flags
|
|
|
|
#define FLAG_C 1
|
|
|
|
#define FLAG_N 2
|
|
|
|
#define FLAG_P 4
|
|
|
|
#define FLAG_H 16
|
|
|
|
#define FLAG_Z 64
|
|
|
|
#define FLAG_S 128
|
|
|
|
|
|
|
|
#define SETFLAG(f,c) AF = (c) ? AF | FLAG_ ## f : AF & ~FLAG_ ## f
|
|
|
|
#define TSTFLAG(f) ((AF & FLAG_ ## f) != 0)
|
|
|
|
|
|
|
|
// Piecewise register access
|
|
|
|
#define ldig(x) ((x) & 0xf)
|
|
|
|
#define hdig(x) (((x)>>4)&0xf)
|
|
|
|
#define lreg(x) ((x)&0xff)
|
|
|
|
#define hreg(x) (((x)>>8)&0xff)
|
|
|
|
|
|
|
|
#define Setlreg(x, v) x = (((x)&0xff00) | ((v)&0xff))
|
|
|
|
#define Sethreg(x, v) x = (((x)&0xff) | (((v)&0xff) << 8))
|
|
|
|
|
|
|
|
// Parity bit calculation
|
|
|
|
static const unsigned char partab[256] = {
|
|
|
|
4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,
|
|
|
|
0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,
|
|
|
|
0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,
|
|
|
|
4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,
|
|
|
|
0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,
|
|
|
|
4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,
|
|
|
|
4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,
|
|
|
|
0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,
|
|
|
|
0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,
|
|
|
|
4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,
|
|
|
|
4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,
|
|
|
|
0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,
|
|
|
|
4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,
|
|
|
|
0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,
|
|
|
|
0,4,4,0,4,0,0,4,4,0,0,4,0,4,4,0,
|
|
|
|
4,0,0,4,0,4,4,0,0,4,4,0,4,0,0,4,
|
|
|
|
};
|
|
|
|
|
2011-07-26 21:47:59 +00:00
|
|
|
// Instruction cycle tables
|
|
|
|
static const unsigned char cycleTables[5][256] = {
|
|
|
|
{
|
|
|
|
// Table 0: single byte instructions
|
|
|
|
4,10,7,6,4,4,7,4,4,11,7,6,4,4,7,4,
|
|
|
|
8,10,7,6,4,4,7,4,12,11,7,6,4,4,7,4,
|
|
|
|
7,10,16,6,4,4,7,4,7,11,16,6,4,4,7,4,
|
|
|
|
7,10,13,6,11,11,10,4,7,11,13,6,4,4,7,4,
|
|
|
|
4,4,4,4,4,4,7,4,4,4,4,4,4,4,7,4,
|
|
|
|
4,4,4,4,4,4,7,4,4,4,4,4,4,4,7,4,
|
|
|
|
4,4,4,4,4,4,7,4,4,4,4,4,4,4,7,4,
|
|
|
|
7,7,7,7,7,7,4,7,4,4,4,4,4,4,7,4,
|
|
|
|
4,4,4,4,4,4,7,4,4,4,4,4,4,4,7,4,
|
|
|
|
4,4,4,4,4,4,7,4,4,4,4,4,4,4,7,4,
|
|
|
|
4,4,4,4,4,4,7,4,4,4,4,4,4,4,7,4,
|
|
|
|
4,4,4,4,4,4,7,4,4,4,4,4,4,4,7,4,
|
|
|
|
5,10,10,10,10,11,7,11,5,10,10,0,10,17,7,11,
|
|
|
|
5,10,10,11,10,11,7,11,5,4,10,11,10,0,7,11,
|
|
|
|
5,10,10,19,10,11,7,11,5,4,10,4,10,0,7,11,
|
|
|
|
5,10,10,4,10,11,7,11,5,6,10,4,10,0,7,11
|
|
|
|
}, {
|
|
|
|
// Table 1: two byte instructions of form CB-XX
|
|
|
|
8,8,8,8,8,8,15,8,8,8,8,8,8,8,15,8,
|
|
|
|
8,8,8,8,8,8,15,8,8,8,8,8,8,8,15,8,
|
|
|
|
8,8,8,8,8,8,15,8,8,8,8,8,8,8,15,8,
|
|
|
|
8,8,8,8,8,8,15,8,8,8,8,8,8,8,15,8,
|
|
|
|
8,8,8,8,8,8,12,8,8,8,8,8,8,8,12,8,
|
|
|
|
8,8,8,8,8,8,12,8,8,8,8,8,8,8,12,8,
|
|
|
|
8,8,8,8,8,8,12,8,8,8,8,8,8,8,12,8,
|
|
|
|
8,8,8,8,8,8,12,8,8,8,8,8,8,8,12,8,
|
|
|
|
8,8,8,8,8,8,15,8,8,8,8,8,8,8,15,8,
|
|
|
|
8,8,8,8,8,8,15,8,8,8,8,8,8,8,15,8,
|
|
|
|
8,8,8,8,8,8,15,8,8,8,8,8,8,8,15,8,
|
|
|
|
8,8,8,8,8,8,15,8,8,8,8,8,8,8,15,8,
|
|
|
|
8,8,8,8,8,8,15,8,8,8,8,8,8,8,15,8,
|
|
|
|
8,8,8,8,8,8,15,8,8,8,8,8,8,8,15,8,
|
|
|
|
8,8,8,8,8,8,15,8,8,8,8,8,8,8,15,8,
|
|
|
|
8,8,8,8,8,8,15,8,8,8,8,8,8,8,15,8
|
|
|
|
}, {
|
|
|
|
// Table 2: two byte instructions of form ED-XX
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
12,12,15,20,8,14,8,9,12,12,15,20,0,14,0,9,
|
|
|
|
12,12,15,20,0,0,8,9,12,12,15,20,0,0,8,9,
|
|
|
|
12,12,15,20,0,0,0,18,12,12,15,20,0,0,0,18,
|
|
|
|
12,0,15,20,0,0,0,0,12,12,15,20,0,0,0,0,
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
16,16,16,16,0,0,0,0,16,16,16,16,0,0,0,0,
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
|
|
|
}, {
|
|
|
|
// Table 3: two byte instructions of form DD-XX or FD-XX
|
|
|
|
0,0,0,0,0,0,0,0,0,15,0,0,0,0,0,0,
|
|
|
|
0,0,0,0,0,0,0,0,0,15,0,0,0,0,0,0,
|
|
|
|
0,14,20,10,9,9,9,0,0,15,20,10,9,9,9,0,
|
|
|
|
0,0,0,0,23,23,19,0,0,15,0,0,0,0,0,0,
|
|
|
|
0,0,0,0,9,9,19,0,0,0,0,0,9,9,19,0,
|
|
|
|
0,0,0,0,9,9,19,0,0,0,0,0,9,9,19,0,
|
|
|
|
9,9,9,9,9,9,19,9,9,9,9,9,9,9,19,9,
|
|
|
|
19,19,19,19,19,19,19,19,0,0,0,0,9,9,19,0,
|
|
|
|
0,0,0,0,9,9,19,0,0,0,0,0,9,9,19,0,
|
|
|
|
0,0,0,0,9,9,19,0,0,0,0,0,9,9,19,0,
|
|
|
|
0,0,0,0,9,9,19,0,0,0,0,0,9,9,19,0,
|
|
|
|
0,0,0,0,9,9,19,0,0,0,0,0,9,9,19,0,
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
|
|
0,14,0,23,0,15,0,0,0,8,0,0,0,0,0,0,
|
|
|
|
0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0
|
|
|
|
}, {
|
|
|
|
// Table 4: three byte instructions of form DD-CB-XX or FD-CB-XX
|
|
|
|
0,0,0,0,0,0,23,0,0,0,0,0,0,0,23,0,
|
|
|
|
0,0,0,0,0,0,23,0,0,0,0,0,0,0,23,0,
|
|
|
|
0,0,0,0,0,0,23,0,0,0,0,0,0,0,23,0,
|
|
|
|
0,0,0,0,0,0,23,0,0,0,0,0,0,0,23,0,
|
|
|
|
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
|
|
|
|
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
|
|
|
|
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
|
|
|
|
20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
|
|
|
|
0,0,0,0,0,0,23,0,0,0,0,0,0,0,23,0,
|
|
|
|
0,0,0,0,0,0,23,0,0,0,0,0,0,0,23,0,
|
|
|
|
0,0,0,0,0,0,23,0,0,0,0,0,0,0,23,0,
|
|
|
|
0,0,0,0,0,0,23,0,0,0,0,0,0,0,23,0,
|
|
|
|
0,0,0,0,0,0,23,0,0,0,0,0,0,0,23,0,
|
|
|
|
0,0,0,0,0,0,23,0,0,0,0,0,0,0,23,0,
|
|
|
|
0,0,0,0,0,0,23,0,0,0,0,0,0,0,23,0,
|
|
|
|
0,0,0,0,0,0,23,0,0,0,0,0,0,0,23,0
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-07-18 19:48:57 +00:00
|
|
|
#define parity(x) partab[(x)&0xff]
|
|
|
|
|
|
|
|
// Stack
|
|
|
|
#define POP(x) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
unsigned int y = GetBYTE_pp(SP); \
|
|
|
|
x = y + (GetBYTE_pp(SP) << 8); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define PUSH(x) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
mm_PutBYTE(SP,((x)>>8)); \
|
|
|
|
mm_PutBYTE(SP,(x)&0xFF); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
// Branching
|
|
|
|
#define Jpc(cond) pc = cond ? GetWORD(pc) : pc+2
|
|
|
|
|
|
|
|
#define CALLC(cond) \
|
|
|
|
{ \
|
|
|
|
if (cond) \
|
|
|
|
{ \
|
|
|
|
unsigned int adrr = GetWORD(pc); \
|
|
|
|
PUSH(pc+2); \
|
|
|
|
pc = adrr; \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
pc += 2; \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
Functions
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2011-07-26 21:47:59 +00:00
|
|
|
int CZ80::Run(int numCycles)
|
2011-07-18 19:48:57 +00:00
|
|
|
{
|
2011-09-18 22:21:14 +00:00
|
|
|
#ifdef SUPERMODEL_DEBUGGER
|
|
|
|
// If debugging enabled, don't optimize access to registers as they need to be accesible to debugger during execution
|
|
|
|
#define AF af[af_sel]
|
|
|
|
#define BC regs[regs_sel].bc
|
|
|
|
#define DE regs[regs_sel].de
|
|
|
|
#define HL regs[regs_sel].hl
|
|
|
|
#define SP sp
|
|
|
|
#define IX ix
|
|
|
|
#define IY iy
|
|
|
|
#else
|
2011-07-18 19:48:57 +00:00
|
|
|
// Optimization: copy registers into native word-sized local variables
|
|
|
|
unsigned int AF = af[af_sel];
|
|
|
|
unsigned int BC = regs[regs_sel].bc;
|
|
|
|
unsigned int DE = regs[regs_sel].de;
|
|
|
|
unsigned int HL = regs[regs_sel].hl;
|
|
|
|
unsigned int SP = sp;
|
|
|
|
unsigned int IX = ix;
|
|
|
|
unsigned int IY = iy;
|
2011-09-18 22:21:14 +00:00
|
|
|
#endif
|
2011-07-18 19:48:57 +00:00
|
|
|
unsigned int temp, acu, sum, cbits;
|
|
|
|
unsigned int op, adr;
|
2011-09-18 22:21:14 +00:00
|
|
|
|
2011-07-26 21:47:59 +00:00
|
|
|
int cycles = numCycles;
|
2011-09-18 22:21:14 +00:00
|
|
|
#ifdef SUPERMODEL_DEBUGGER
|
|
|
|
if (Debug != NULL)
|
|
|
|
{
|
|
|
|
Debug->CPUActive();
|
|
|
|
lastCycles += numCycles;
|
|
|
|
}
|
|
|
|
#endif // SUPERMODEL_DEBUGGER
|
|
|
|
|
2011-07-26 21:47:59 +00:00
|
|
|
while (cycles > 0)
|
|
|
|
{
|
|
|
|
op = GetBYTE_pp(pc);
|
2011-09-18 22:21:14 +00:00
|
|
|
#ifdef SUPERMODEL_DEBUGGER
|
|
|
|
if (Debug != NULL)
|
|
|
|
{
|
|
|
|
while (Debug->CPUExecute(pc - 1, op, lastCycles - cycles))
|
|
|
|
op = GetBYTE_pp(pc);
|
|
|
|
lastCycles = cycles;
|
|
|
|
}
|
|
|
|
#endif // SUPERMODEL_DEBUGGER
|
2011-07-26 21:47:59 +00:00
|
|
|
switch(op) {
|
2011-07-18 19:48:57 +00:00
|
|
|
case 0x00: /* NOP */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x00];
|
2011-07-18 19:48:57 +00:00
|
|
|
break;
|
|
|
|
case 0x01: /* LD BC,nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x01];
|
2011-07-18 19:48:57 +00:00
|
|
|
BC = GetWORD(pc);
|
|
|
|
pc += 2;
|
|
|
|
break;
|
|
|
|
case 0x02: /* LD (BC),A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x02];
|
2011-07-18 19:48:57 +00:00
|
|
|
PutBYTE(BC, hreg(AF));
|
|
|
|
break;
|
|
|
|
case 0x03: /* INC BC */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x03];
|
2011-07-18 19:48:57 +00:00
|
|
|
++BC;
|
|
|
|
break;
|
|
|
|
case 0x04: /* INC B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x04];
|
2011-07-18 19:48:57 +00:00
|
|
|
BC += 0x100;
|
|
|
|
temp = hreg(BC);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0) << 4) |
|
|
|
|
((temp == 0x80) << 2);
|
|
|
|
break;
|
|
|
|
case 0x05: /* DEC B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x05];
|
2011-07-18 19:48:57 +00:00
|
|
|
BC -= 0x100;
|
|
|
|
temp = hreg(BC);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0xf) << 4) |
|
|
|
|
((temp == 0x7f) << 2) | 2;
|
|
|
|
break;
|
|
|
|
case 0x06: /* LD B,nn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x06];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(BC, GetBYTE_pp(pc));
|
|
|
|
break;
|
|
|
|
case 0x07: /* RLCA */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x07];
|
2011-07-18 19:48:57 +00:00
|
|
|
AF = ((AF >> 7) & 0x0128) | ((AF << 1) & ~0x1ff) |
|
|
|
|
(AF & 0xc4) | ((AF >> 15) & 1);
|
|
|
|
break;
|
|
|
|
case 0x08: /* EX AF,AF' */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x08];
|
2011-07-18 19:48:57 +00:00
|
|
|
af[af_sel] = AF;
|
|
|
|
af_sel = 1 - af_sel;
|
|
|
|
AF = af[af_sel];
|
|
|
|
break;
|
|
|
|
case 0x09: /* ADD HL,BC */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x09];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL &= 0xffff;
|
|
|
|
BC &= 0xffff;
|
|
|
|
sum = HL + BC;
|
|
|
|
cbits = (HL ^ BC ^ sum) >> 8;
|
|
|
|
HL = sum;
|
|
|
|
AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x0A: /* LD A,(BC) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x0A];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(AF, GetBYTE(BC));
|
|
|
|
break;
|
|
|
|
case 0x0B: /* DEC BC */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x0B];
|
2011-07-18 19:48:57 +00:00
|
|
|
--BC;
|
|
|
|
break;
|
|
|
|
case 0x0C: /* INC C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x0C];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(BC)+1;
|
|
|
|
Setlreg(BC, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0) << 4) |
|
|
|
|
((temp == 0x80) << 2);
|
|
|
|
break;
|
|
|
|
case 0x0D: /* DEC C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x0D];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(BC)-1;
|
|
|
|
Setlreg(BC, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0xf) << 4) |
|
|
|
|
((temp == 0x7f) << 2) | 2;
|
|
|
|
break;
|
|
|
|
case 0x0E: /* LD C,nn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x0E];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(BC, GetBYTE_pp(pc));
|
|
|
|
break;
|
|
|
|
case 0x0F: /* RRCA */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x0F];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(AF);
|
|
|
|
sum = temp >> 1;
|
|
|
|
AF = ((temp & 1) << 15) | (sum << 8) |
|
|
|
|
(sum & 0x28) | (AF & 0xc4) | (temp & 1);
|
|
|
|
break;
|
|
|
|
case 0x10: /* DJNZ dd */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x10];
|
2011-07-18 19:48:57 +00:00
|
|
|
pc += ((BC -= 0x100) & 0xff00) ? (signed char) GetBYTE(pc) + 1 : 1;
|
|
|
|
break;
|
|
|
|
case 0x11: /* LD DE,nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x11];
|
2011-07-18 19:48:57 +00:00
|
|
|
DE = GetWORD(pc);
|
|
|
|
pc += 2;
|
|
|
|
break;
|
|
|
|
case 0x12: /* LD (DE),A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x12];
|
2011-07-18 19:48:57 +00:00
|
|
|
PutBYTE(DE, hreg(AF));
|
|
|
|
break;
|
|
|
|
case 0x13: /* INC DE */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x13];
|
2011-07-18 19:48:57 +00:00
|
|
|
++DE;
|
|
|
|
break;
|
|
|
|
case 0x14: /* INC D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x14];
|
2011-07-18 19:48:57 +00:00
|
|
|
DE += 0x100;
|
|
|
|
temp = hreg(DE);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0) << 4) |
|
|
|
|
((temp == 0x80) << 2);
|
|
|
|
break;
|
|
|
|
case 0x15: /* DEC D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x15];
|
2011-07-18 19:48:57 +00:00
|
|
|
DE -= 0x100;
|
|
|
|
temp = hreg(DE);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0xf) << 4) |
|
|
|
|
((temp == 0x7f) << 2) | 2;
|
|
|
|
break;
|
|
|
|
case 0x16: /* LD D,nn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x16];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(DE, GetBYTE_pp(pc));
|
|
|
|
break;
|
|
|
|
case 0x17: /* RLA */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x17];
|
2011-07-18 19:48:57 +00:00
|
|
|
AF = ((AF << 8) & 0x0100) | ((AF >> 7) & 0x28) | ((AF << 1) & ~0x01ff) |
|
|
|
|
(AF & 0xc4) | ((AF >> 15) & 1);
|
|
|
|
break;
|
|
|
|
case 0x18: /* JR dd */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x18];
|
2011-07-18 19:48:57 +00:00
|
|
|
pc += (1) ? (signed char) GetBYTE(pc) + 1 : 1;
|
|
|
|
break;
|
|
|
|
case 0x19: /* ADD HL,DE */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x19];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL &= 0xffff;
|
|
|
|
DE &= 0xffff;
|
|
|
|
sum = HL + DE;
|
|
|
|
cbits = (HL ^ DE ^ sum) >> 8;
|
|
|
|
HL = sum;
|
|
|
|
AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x1A: /* LD A,(DE) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x1A];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(AF, GetBYTE(DE));
|
|
|
|
break;
|
|
|
|
case 0x1B: /* DEC DE */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x1B];
|
2011-07-18 19:48:57 +00:00
|
|
|
--DE;
|
|
|
|
break;
|
|
|
|
case 0x1C: /* INC E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x1C];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(DE)+1;
|
|
|
|
Setlreg(DE, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0) << 4) |
|
|
|
|
((temp == 0x80) << 2);
|
|
|
|
break;
|
|
|
|
case 0x1D: /* DEC E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x1D];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(DE)-1;
|
|
|
|
Setlreg(DE, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0xf) << 4) |
|
|
|
|
((temp == 0x7f) << 2) | 2;
|
|
|
|
break;
|
|
|
|
case 0x1E: /* LD E,nn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x1E];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(DE, GetBYTE_pp(pc));
|
|
|
|
break;
|
|
|
|
case 0x1F: /* RRA */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x1F];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(AF);
|
|
|
|
sum = temp >> 1;
|
|
|
|
AF = ((AF & 1) << 15) | (sum << 8) |
|
|
|
|
(sum & 0x28) | (AF & 0xc4) | (temp & 1);
|
|
|
|
break;
|
|
|
|
case 0x20: /* JR NZ,dd */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x20];
|
2011-07-18 19:48:57 +00:00
|
|
|
pc += (!TSTFLAG(Z)) ? (signed char) GetBYTE(pc) + 1 : 1;
|
|
|
|
break;
|
|
|
|
case 0x21: /* LD HL,nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x21];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL = GetWORD(pc);
|
|
|
|
pc += 2;
|
|
|
|
break;
|
|
|
|
case 0x22: /* LD (nnnn),HL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x22];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetWORD(pc);
|
|
|
|
PutWORD(temp, HL);
|
|
|
|
pc += 2;
|
|
|
|
break;
|
|
|
|
case 0x23: /* INC HL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x23];
|
2011-07-18 19:48:57 +00:00
|
|
|
++HL;
|
|
|
|
break;
|
|
|
|
case 0x24: /* INC H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x24];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL += 0x100;
|
|
|
|
temp = hreg(HL);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0) << 4) |
|
|
|
|
((temp == 0x80) << 2);
|
|
|
|
break;
|
|
|
|
case 0x25: /* DEC H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x25];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL -= 0x100;
|
|
|
|
temp = hreg(HL);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0xf) << 4) |
|
|
|
|
((temp == 0x7f) << 2) | 2;
|
|
|
|
break;
|
|
|
|
case 0x26: /* LD H,nn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x26];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(HL, GetBYTE_pp(pc));
|
|
|
|
break;
|
|
|
|
case 0x27: /* DAA */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x27];
|
2011-07-18 19:48:57 +00:00
|
|
|
acu = hreg(AF);
|
|
|
|
temp = ldig(acu);
|
|
|
|
cbits = TSTFLAG(C);
|
|
|
|
if (TSTFLAG(N)) { /* last operation was a subtract */
|
|
|
|
int hd = cbits || acu > 0x99;
|
|
|
|
if (TSTFLAG(H) || (temp > 9)) { /* adjust low digit */
|
|
|
|
if (temp > 5)
|
|
|
|
SETFLAG(H, 0);
|
|
|
|
acu -= 6;
|
|
|
|
acu &= 0xff;
|
|
|
|
}
|
|
|
|
if (hd) /* adjust high digit */
|
|
|
|
acu -= 0x160;
|
|
|
|
}
|
|
|
|
else { /* last operation was an add */
|
|
|
|
if (TSTFLAG(H) || (temp > 9)) { /* adjust low digit */
|
|
|
|
SETFLAG(H, (temp > 9));
|
|
|
|
acu += 6;
|
|
|
|
}
|
|
|
|
if (cbits || ((acu & 0x1f0) > 0x90)) /* adjust high digit */
|
|
|
|
acu += 0x60;
|
|
|
|
}
|
|
|
|
cbits |= (acu >> 8) & 1;
|
|
|
|
acu &= 0xff;
|
|
|
|
AF = (acu << 8) | (acu & 0xa8) | ((acu == 0) << 6) |
|
|
|
|
(AF & 0x12) | partab[acu] | cbits;
|
|
|
|
break;
|
|
|
|
case 0x28: /* JR Z,dd */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x28];
|
2011-07-18 19:48:57 +00:00
|
|
|
pc += (TSTFLAG(Z)) ? (signed char) GetBYTE(pc) + 1 : 1;
|
|
|
|
break;
|
|
|
|
case 0x29: /* ADD HL,HL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x29];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL &= 0xffff;
|
|
|
|
sum = HL + HL;
|
|
|
|
cbits = (HL ^ HL ^ sum) >> 8;
|
|
|
|
HL = sum;
|
|
|
|
AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x2A: /* LD HL,(nnnn) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x2A];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetWORD(pc);
|
|
|
|
HL = GetWORD(temp);
|
|
|
|
pc += 2;
|
|
|
|
break;
|
|
|
|
case 0x2B: /* DEC HL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x2B];
|
2011-07-18 19:48:57 +00:00
|
|
|
--HL;
|
|
|
|
break;
|
|
|
|
case 0x2C: /* INC L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x2C];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(HL)+1;
|
|
|
|
Setlreg(HL, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0) << 4) |
|
|
|
|
((temp == 0x80) << 2);
|
|
|
|
break;
|
|
|
|
case 0x2D: /* DEC L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x2D];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(HL)-1;
|
|
|
|
Setlreg(HL, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0xf) << 4) |
|
|
|
|
((temp == 0x7f) << 2) | 2;
|
|
|
|
break;
|
|
|
|
case 0x2E: /* LD L,nn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x2E];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(HL, GetBYTE_pp(pc));
|
|
|
|
break;
|
|
|
|
case 0x2F: /* CPL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x2F];
|
2011-07-18 19:48:57 +00:00
|
|
|
AF = (~AF & ~0xff) | (AF & 0xc5) | ((~AF >> 8) & 0x28) | 0x12;
|
|
|
|
break;
|
|
|
|
case 0x30: /* JR NC,dd */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x30];
|
2011-07-18 19:48:57 +00:00
|
|
|
pc += (!TSTFLAG(C)) ? (signed char) GetBYTE(pc) + 1 : 1;
|
|
|
|
break;
|
|
|
|
case 0x31: /* LD SP,nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x31];
|
2011-07-18 19:48:57 +00:00
|
|
|
SP = GetWORD(pc);
|
|
|
|
pc += 2;
|
|
|
|
break;
|
|
|
|
case 0x32: /* LD (nnnn),A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x32];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetWORD(pc);
|
|
|
|
PutBYTE(temp, hreg(AF));
|
|
|
|
pc += 2;
|
|
|
|
break;
|
|
|
|
case 0x33: /* INC SP */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x33];
|
2011-07-18 19:48:57 +00:00
|
|
|
++SP;
|
|
|
|
break;
|
|
|
|
case 0x34: /* INC (HL) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x34];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetBYTE(HL)+1;
|
|
|
|
PutBYTE(HL, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0) << 4) |
|
|
|
|
((temp == 0x80) << 2);
|
|
|
|
break;
|
|
|
|
case 0x35: /* DEC (HL) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x35];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetBYTE(HL)-1;
|
|
|
|
PutBYTE(HL, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0xf) << 4) |
|
|
|
|
((temp == 0x7f) << 2) | 2;
|
|
|
|
break;
|
|
|
|
case 0x36: /* LD (HL),nn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x36];
|
2011-07-18 19:48:57 +00:00
|
|
|
PutBYTE(HL, GetBYTE_pp(pc));
|
|
|
|
break;
|
|
|
|
case 0x37: /* SCF */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x37];
|
2011-07-18 19:48:57 +00:00
|
|
|
AF = (AF&~0x3b)|((AF>>8)&0x28)|1;
|
|
|
|
break;
|
|
|
|
case 0x38: /* JR C,dd */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x38];
|
2011-07-18 19:48:57 +00:00
|
|
|
pc += (TSTFLAG(C)) ? (signed char) GetBYTE(pc) + 1 : 1;
|
|
|
|
break;
|
|
|
|
case 0x39: /* ADD HL,SP */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x39];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL &= 0xffff;
|
|
|
|
SP &= 0xffff;
|
|
|
|
sum = HL + SP;
|
|
|
|
cbits = (HL ^ SP ^ sum) >> 8;
|
|
|
|
HL = sum;
|
|
|
|
AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x3A: /* LD A,(nnnn) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x3A];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetWORD(pc);
|
|
|
|
Sethreg(AF, GetBYTE(temp));
|
|
|
|
pc += 2;
|
|
|
|
break;
|
|
|
|
case 0x3B: /* DEC SP */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x3B];
|
2011-07-18 19:48:57 +00:00
|
|
|
--SP;
|
|
|
|
break;
|
|
|
|
case 0x3C: /* INC A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x3C];
|
2011-07-18 19:48:57 +00:00
|
|
|
AF += 0x100;
|
|
|
|
temp = hreg(AF);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0) << 4) |
|
|
|
|
((temp == 0x80) << 2);
|
|
|
|
break;
|
|
|
|
case 0x3D: /* DEC A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x3D];
|
2011-07-18 19:48:57 +00:00
|
|
|
AF -= 0x100;
|
|
|
|
temp = hreg(AF);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0xf) << 4) |
|
|
|
|
((temp == 0x7f) << 2) | 2;
|
|
|
|
break;
|
|
|
|
case 0x3E: /* LD A,nn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x3E];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(AF, GetBYTE_pp(pc));
|
|
|
|
break;
|
|
|
|
case 0x3F: /* CCF */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x3F];
|
2011-07-18 19:48:57 +00:00
|
|
|
AF = (AF&~0x3b)|((AF>>8)&0x28)|((AF&1)<<4)|(~AF&1);
|
|
|
|
break;
|
|
|
|
case 0x40: /* LD B,B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x40];
|
2011-07-18 19:48:57 +00:00
|
|
|
/* nop */
|
|
|
|
break;
|
|
|
|
case 0x41: /* LD B,C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x41];
|
2011-07-18 19:48:57 +00:00
|
|
|
BC = (BC & 255) | ((BC & 255) << 8);
|
|
|
|
break;
|
|
|
|
case 0x42: /* LD B,D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x42];
|
2011-07-18 19:48:57 +00:00
|
|
|
BC = (BC & 255) | (DE & ~255);
|
|
|
|
break;
|
|
|
|
case 0x43: /* LD B,E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x43];
|
2011-07-18 19:48:57 +00:00
|
|
|
BC = (BC & 255) | ((DE & 255) << 8);
|
|
|
|
break;
|
|
|
|
case 0x44: /* LD B,H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x44];
|
2011-07-18 19:48:57 +00:00
|
|
|
BC = (BC & 255) | (HL & ~255);
|
|
|
|
break;
|
|
|
|
case 0x45: /* LD B,L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x45];
|
2011-07-18 19:48:57 +00:00
|
|
|
BC = (BC & 255) | ((HL & 255) << 8);
|
|
|
|
break;
|
|
|
|
case 0x46: /* LD B,(HL) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x46];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(BC, GetBYTE(HL));
|
|
|
|
break;
|
|
|
|
case 0x47: /* LD B,A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x47];
|
2011-07-18 19:48:57 +00:00
|
|
|
BC = (BC & 255) | (AF & ~255);
|
|
|
|
break;
|
|
|
|
case 0x48: /* LD C,B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x48];
|
2011-07-18 19:48:57 +00:00
|
|
|
BC = (BC & ~255) | ((BC >> 8) & 255);
|
|
|
|
break;
|
|
|
|
case 0x49: /* LD C,C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x49];
|
2011-07-18 19:48:57 +00:00
|
|
|
/* nop */
|
|
|
|
break;
|
|
|
|
case 0x4A: /* LD C,D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x4A];
|
2011-07-18 19:48:57 +00:00
|
|
|
BC = (BC & ~255) | ((DE >> 8) & 255);
|
|
|
|
break;
|
|
|
|
case 0x4B: /* LD C,E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x4B];
|
2011-07-18 19:48:57 +00:00
|
|
|
BC = (BC & ~255) | (DE & 255);
|
|
|
|
break;
|
|
|
|
case 0x4C: /* LD C,H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x4C];
|
2011-07-18 19:48:57 +00:00
|
|
|
BC = (BC & ~255) | ((HL >> 8) & 255);
|
|
|
|
break;
|
|
|
|
case 0x4D: /* LD C,L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x4D];
|
2011-07-18 19:48:57 +00:00
|
|
|
BC = (BC & ~255) | (HL & 255);
|
|
|
|
break;
|
|
|
|
case 0x4E: /* LD C,(HL) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x4E];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(BC, GetBYTE(HL));
|
|
|
|
break;
|
|
|
|
case 0x4F: /* LD C,A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x4F];
|
2011-07-18 19:48:57 +00:00
|
|
|
BC = (BC & ~255) | ((AF >> 8) & 255);
|
|
|
|
break;
|
|
|
|
case 0x50: /* LD D,B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x50];
|
2011-07-18 19:48:57 +00:00
|
|
|
DE = (DE & 255) | (BC & ~255);
|
|
|
|
break;
|
|
|
|
case 0x51: /* LD D,C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x51];
|
2011-07-18 19:48:57 +00:00
|
|
|
DE = (DE & 255) | ((BC & 255) << 8);
|
|
|
|
break;
|
|
|
|
case 0x52: /* LD D,D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x52];
|
2011-07-18 19:48:57 +00:00
|
|
|
/* nop */
|
|
|
|
break;
|
|
|
|
case 0x53: /* LD D,E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x53];
|
2011-07-18 19:48:57 +00:00
|
|
|
DE = (DE & 255) | ((DE & 255) << 8);
|
|
|
|
break;
|
|
|
|
case 0x54: /* LD D,H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x54];
|
2011-07-18 19:48:57 +00:00
|
|
|
DE = (DE & 255) | (HL & ~255);
|
|
|
|
break;
|
|
|
|
case 0x55: /* LD D,L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x55];
|
2011-07-18 19:48:57 +00:00
|
|
|
DE = (DE & 255) | ((HL & 255) << 8);
|
|
|
|
break;
|
|
|
|
case 0x56: /* LD D,(HL) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x56];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(DE, GetBYTE(HL));
|
|
|
|
break;
|
|
|
|
case 0x57: /* LD D,A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x57];
|
2011-07-18 19:48:57 +00:00
|
|
|
DE = (DE & 255) | (AF & ~255);
|
|
|
|
break;
|
|
|
|
case 0x58: /* LD E,B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x58];
|
2011-07-18 19:48:57 +00:00
|
|
|
DE = (DE & ~255) | ((BC >> 8) & 255);
|
|
|
|
break;
|
|
|
|
case 0x59: /* LD E,C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x59];
|
2011-07-18 19:48:57 +00:00
|
|
|
DE = (DE & ~255) | (BC & 255);
|
|
|
|
break;
|
|
|
|
case 0x5A: /* LD E,D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x5A];
|
2011-07-18 19:48:57 +00:00
|
|
|
DE = (DE & ~255) | ((DE >> 8) & 255);
|
|
|
|
break;
|
|
|
|
case 0x5B: /* LD E,E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x5B];
|
2011-07-18 19:48:57 +00:00
|
|
|
/* nop */
|
|
|
|
break;
|
|
|
|
case 0x5C: /* LD E,H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x5C];
|
2011-07-18 19:48:57 +00:00
|
|
|
DE = (DE & ~255) | ((HL >> 8) & 255);
|
|
|
|
break;
|
|
|
|
case 0x5D: /* LD E,L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x5D];
|
2011-07-18 19:48:57 +00:00
|
|
|
DE = (DE & ~255) | (HL & 255);
|
|
|
|
break;
|
|
|
|
case 0x5E: /* LD E,(HL) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x5E];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(DE, GetBYTE(HL));
|
|
|
|
break;
|
|
|
|
case 0x5F: /* LD E,A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x5F];
|
2011-07-18 19:48:57 +00:00
|
|
|
DE = (DE & ~255) | ((AF >> 8) & 255);
|
|
|
|
break;
|
|
|
|
case 0x60: /* LD H,B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x60];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL = (HL & 255) | (BC & ~255);
|
|
|
|
break;
|
|
|
|
case 0x61: /* LD H,C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x61];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL = (HL & 255) | ((BC & 255) << 8);
|
|
|
|
break;
|
|
|
|
case 0x62: /* LD H,D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x62];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL = (HL & 255) | (DE & ~255);
|
|
|
|
break;
|
|
|
|
case 0x63: /* LD H,E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x63];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL = (HL & 255) | ((DE & 255) << 8);
|
|
|
|
break;
|
|
|
|
case 0x64: /* LD H,H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x64];
|
2011-07-18 19:48:57 +00:00
|
|
|
/* nop */
|
|
|
|
break;
|
|
|
|
case 0x65: /* LD H,L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x65];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL = (HL & 255) | ((HL & 255) << 8);
|
|
|
|
break;
|
|
|
|
case 0x66: /* LD H,(HL) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x66];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(HL, GetBYTE(HL));
|
|
|
|
break;
|
|
|
|
case 0x67: /* LD H,A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x67];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL = (HL & 255) | (AF & ~255);
|
|
|
|
break;
|
|
|
|
case 0x68: /* LD L,B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x68];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL = (HL & ~255) | ((BC >> 8) & 255);
|
|
|
|
break;
|
|
|
|
case 0x69: /* LD L,C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x69];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL = (HL & ~255) | (BC & 255);
|
|
|
|
break;
|
|
|
|
case 0x6A: /* LD L,D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x6A];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL = (HL & ~255) | ((DE >> 8) & 255);
|
|
|
|
break;
|
|
|
|
case 0x6B: /* LD L,E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x6B];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL = (HL & ~255) | (DE & 255);
|
|
|
|
break;
|
|
|
|
case 0x6C: /* LD L,H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x6C];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL = (HL & ~255) | ((HL >> 8) & 255);
|
|
|
|
break;
|
|
|
|
case 0x6D: /* LD L,L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x6D];
|
2011-07-18 19:48:57 +00:00
|
|
|
/* nop */
|
|
|
|
break;
|
|
|
|
case 0x6E: /* LD L,(HL) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x6E];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(HL, GetBYTE(HL));
|
|
|
|
break;
|
|
|
|
case 0x6F: /* LD L,A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x6F];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL = (HL & ~255) | ((AF >> 8) & 255);
|
|
|
|
break;
|
|
|
|
case 0x70: /* LD (HL),B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x70];
|
2011-07-18 19:48:57 +00:00
|
|
|
PutBYTE(HL, hreg(BC));
|
|
|
|
break;
|
|
|
|
case 0x71: /* LD (HL),C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x71];
|
2011-07-18 19:48:57 +00:00
|
|
|
PutBYTE(HL, lreg(BC));
|
|
|
|
break;
|
|
|
|
case 0x72: /* LD (HL),D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x72];
|
2011-07-18 19:48:57 +00:00
|
|
|
PutBYTE(HL, hreg(DE));
|
|
|
|
break;
|
|
|
|
case 0x73: /* LD (HL),E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x73];
|
2011-07-18 19:48:57 +00:00
|
|
|
PutBYTE(HL, lreg(DE));
|
|
|
|
break;
|
|
|
|
case 0x74: /* LD (HL),H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x74];
|
2011-07-18 19:48:57 +00:00
|
|
|
PutBYTE(HL, hreg(HL));
|
|
|
|
break;
|
|
|
|
case 0x75: /* LD (HL),L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x75];
|
2011-07-18 19:48:57 +00:00
|
|
|
PutBYTE(HL, lreg(HL));
|
|
|
|
break;
|
|
|
|
case 0x76: /* HALT */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x76];
|
2011-07-18 19:48:57 +00:00
|
|
|
// ErrorLog("Z80 encountered an unemulated instruction at 0x%04X", (pc-1)&0xFFFF);
|
|
|
|
goto HALTExit;
|
|
|
|
case 0x77: /* LD (HL),A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x77];
|
2011-07-18 19:48:57 +00:00
|
|
|
PutBYTE(HL, hreg(AF));
|
|
|
|
break;
|
|
|
|
case 0x78: /* LD A,B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x78];
|
2011-07-18 19:48:57 +00:00
|
|
|
AF = (AF & 255) | (BC & ~255);
|
|
|
|
break;
|
|
|
|
case 0x79: /* LD A,C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x79];
|
2011-07-18 19:48:57 +00:00
|
|
|
AF = (AF & 255) | ((BC & 255) << 8);
|
|
|
|
break;
|
|
|
|
case 0x7A: /* LD A,D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x7A];
|
2011-07-18 19:48:57 +00:00
|
|
|
AF = (AF & 255) | (DE & ~255);
|
|
|
|
break;
|
|
|
|
case 0x7B: /* LD A,E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x7B];
|
2011-07-18 19:48:57 +00:00
|
|
|
AF = (AF & 255) | ((DE & 255) << 8);
|
|
|
|
break;
|
|
|
|
case 0x7C: /* LD A,H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x7C];
|
2011-07-18 19:48:57 +00:00
|
|
|
AF = (AF & 255) | (HL & ~255);
|
|
|
|
break;
|
|
|
|
case 0x7D: /* LD A,L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x7D];
|
2011-07-18 19:48:57 +00:00
|
|
|
AF = (AF & 255) | ((HL & 255) << 8);
|
|
|
|
break;
|
|
|
|
case 0x7E: /* LD A,(HL) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x7E];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(AF, GetBYTE(HL));
|
|
|
|
break;
|
|
|
|
case 0x7F: /* LD A,A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x7F];
|
2011-07-18 19:48:57 +00:00
|
|
|
/* nop */
|
|
|
|
break;
|
|
|
|
case 0x80: /* ADD A,B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x80];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(BC);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x81: /* ADD A,C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x81];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(BC);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x82: /* ADD A,D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x82];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(DE);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x83: /* ADD A,E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x83];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(DE);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x84: /* ADD A,H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x84];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(HL);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x85: /* ADD A,L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x85];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(HL);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x86: /* ADD A,(HL) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x86];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetBYTE(HL);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x87: /* ADD A,A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x87];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(AF);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x88: /* ADC A,B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x88];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(BC);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp + TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x89: /* ADC A,C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x89];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(BC);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp + TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x8A: /* ADC A,D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x8A];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(DE);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp + TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x8B: /* ADC A,E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x8B];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(DE);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp + TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x8C: /* ADC A,H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x8C];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(HL);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp + TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x8D: /* ADC A,L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x8D];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(HL);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp + TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x8E: /* ADC A,(HL) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x8E];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetBYTE(HL);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp + TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x8F: /* ADC A,A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x8F];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(AF);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp + TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x90: /* SUB B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x90];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(BC);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x91: /* SUB C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x91];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(BC);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x92: /* SUB D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x92];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(DE);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x93: /* SUB E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x93];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(DE);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x94: /* SUB H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x94];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(HL);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x95: /* SUB L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x95];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(HL);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x96: /* SUB (HL) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x96];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetBYTE(HL);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x97: /* SUB A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x97];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(AF);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x98: /* SBC A,B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x98];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(BC);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp - TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x99: /* SBC A,C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x99];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(BC);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp - TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x9A: /* SBC A,D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x9A];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(DE);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp - TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x9B: /* SBC A,E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x9B];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(DE);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp - TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x9C: /* SBC A,H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x9C];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(HL);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp - TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x9D: /* SBC A,L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x9D];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(HL);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp - TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x9E: /* SBC A,(HL) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x9E];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetBYTE(HL);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp - TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x9F: /* SBC A,A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0x9F];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(AF);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp - TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0xA0: /* AND B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xA0];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF & (BC)) >> 8) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) |
|
|
|
|
((sum == 0) << 6) | 0x10 | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xA1: /* AND C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xA1];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF >> 8) & BC) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | 0x10 |
|
|
|
|
((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xA2: /* AND D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xA2];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF & (DE)) >> 8) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) |
|
|
|
|
((sum == 0) << 6) | 0x10 | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xA3: /* AND E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xA3];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF >> 8) & DE) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | 0x10 |
|
|
|
|
((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xA4: /* AND H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xA4];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF & (HL)) >> 8) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) |
|
|
|
|
((sum == 0) << 6) | 0x10 | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xA5: /* AND L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xA5];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF >> 8) & HL) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | 0x10 |
|
|
|
|
((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xA6: /* AND (HL) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xA6];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF >> 8) & GetBYTE(HL)) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | 0x10 |
|
|
|
|
((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xA7: /* AND A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xA7];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF & (AF)) >> 8) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) |
|
|
|
|
((sum == 0) << 6) | 0x10 | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xA8: /* XOR B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xA8];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF ^ (BC)) >> 8) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xA9: /* XOR C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xA9];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF >> 8) ^ BC) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xAA: /* XOR D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xAA];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF ^ (DE)) >> 8) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xAB: /* XOR E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xAB];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF >> 8) ^ DE) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xAC: /* XOR H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xAC];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF ^ (HL)) >> 8) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xAD: /* XOR L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xAD];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF >> 8) ^ HL) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xAE: /* XOR (HL) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xAE];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF >> 8) ^ GetBYTE(HL)) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xAF: /* XOR A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xAF];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF ^ (AF)) >> 8) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xB0: /* OR B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xB0];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF | (BC)) >> 8) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xB1: /* OR C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xB1];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF >> 8) | BC) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xB2: /* OR D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xB2];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF | (DE)) >> 8) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xB3: /* OR E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xB3];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF >> 8) | DE) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xB4: /* OR H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xB4];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF | (HL)) >> 8) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xB5: /* OR L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xB5];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF >> 8) | HL) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xB6: /* OR (HL) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xB6];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF >> 8) | GetBYTE(HL)) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xB7: /* OR A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xB7];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF | (AF)) >> 8) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xB8: /* CP B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xB8];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(BC);
|
|
|
|
AF = (AF & ~0x28) | (temp & 0x28);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = (AF & ~0xff) | (sum & 0x80) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (temp & 0x28) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0xB9: /* CP C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xB9];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(BC);
|
|
|
|
AF = (AF & ~0x28) | (temp & 0x28);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = (AF & ~0xff) | (sum & 0x80) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (temp & 0x28) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0xBA: /* CP D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xBA];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(DE);
|
|
|
|
AF = (AF & ~0x28) | (temp & 0x28);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = (AF & ~0xff) | (sum & 0x80) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (temp & 0x28) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0xBB: /* CP E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xBB];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(DE);
|
|
|
|
AF = (AF & ~0x28) | (temp & 0x28);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = (AF & ~0xff) | (sum & 0x80) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (temp & 0x28) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0xBC: /* CP H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xBC];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(HL);
|
|
|
|
AF = (AF & ~0x28) | (temp & 0x28);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = (AF & ~0xff) | (sum & 0x80) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (temp & 0x28) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0xBD: /* CP L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xBD];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(HL);
|
|
|
|
AF = (AF & ~0x28) | (temp & 0x28);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = (AF & ~0xff) | (sum & 0x80) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (temp & 0x28) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0xBE: /* CP (HL) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xBE];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetBYTE(HL);
|
|
|
|
AF = (AF & ~0x28) | (temp & 0x28);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = (AF & ~0xff) | (sum & 0x80) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (temp & 0x28) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0xBF: /* CP A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xBF];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(AF);
|
|
|
|
AF = (AF & ~0x28) | (temp & 0x28);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = (AF & ~0xff) | (sum & 0x80) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (temp & 0x28) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0xC0: /* RET NZ */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xC0];
|
2011-07-18 19:48:57 +00:00
|
|
|
if (!TSTFLAG(Z)) POP(pc);
|
|
|
|
break;
|
|
|
|
case 0xC1: /* POP BC */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xC1];
|
2011-07-18 19:48:57 +00:00
|
|
|
POP(BC);
|
|
|
|
break;
|
|
|
|
case 0xC2: /* JP NZ,nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xC2];
|
2011-07-18 19:48:57 +00:00
|
|
|
Jpc(!TSTFLAG(Z));
|
|
|
|
break;
|
|
|
|
case 0xC3: /* JP nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xC3];
|
2011-07-18 19:48:57 +00:00
|
|
|
Jpc(1);
|
|
|
|
break;
|
|
|
|
case 0xC4: /* CALL NZ,nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xC4];
|
2011-07-18 19:48:57 +00:00
|
|
|
CALLC(!TSTFLAG(Z));
|
|
|
|
break;
|
|
|
|
case 0xC5: /* PUSH BC */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xC5];
|
2011-07-18 19:48:57 +00:00
|
|
|
PUSH(BC);
|
|
|
|
break;
|
|
|
|
case 0xC6: /* ADD A,nn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xC6];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetBYTE_pp(pc);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0xC7: /* RST 0 */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xC7];
|
2011-07-18 19:48:57 +00:00
|
|
|
PUSH(pc); pc = 0;
|
|
|
|
break;
|
|
|
|
case 0xC8: /* RET Z */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xC8];
|
2011-07-18 19:48:57 +00:00
|
|
|
if (TSTFLAG(Z)) POP(pc);
|
|
|
|
break;
|
|
|
|
case 0xC9: /* RET */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xC9];
|
2011-07-18 19:48:57 +00:00
|
|
|
POP(pc);
|
|
|
|
break;
|
|
|
|
case 0xCA: /* JP Z,nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xCA];
|
2011-07-18 19:48:57 +00:00
|
|
|
Jpc(TSTFLAG(Z));
|
|
|
|
break;
|
|
|
|
case 0xCB: /* CB prefix */
|
|
|
|
adr = HL;
|
2011-07-26 21:47:59 +00:00
|
|
|
op = GetBYTE(pc);
|
|
|
|
cycles -= cycleTables[1][op];
|
|
|
|
switch (op & 7) {
|
2011-07-18 19:48:57 +00:00
|
|
|
case 0: ++pc; acu = hreg(BC); break;
|
|
|
|
case 1: ++pc; acu = lreg(BC); break;
|
|
|
|
case 2: ++pc; acu = hreg(DE); break;
|
|
|
|
case 3: ++pc; acu = lreg(DE); break;
|
|
|
|
case 4: ++pc; acu = hreg(HL); break;
|
|
|
|
case 5: ++pc; acu = lreg(HL); break;
|
|
|
|
case 6: ++pc; acu = GetBYTE(adr); break;
|
|
|
|
case 7: ++pc; acu = hreg(AF); break;
|
|
|
|
}
|
|
|
|
switch (op & 0xc0) {
|
|
|
|
case 0x00: /* shift/rotate */
|
|
|
|
switch (op & 0x38) {
|
|
|
|
case 0x00: /* RLC */
|
|
|
|
temp = (acu << 1) | (acu >> 7);
|
|
|
|
cbits = temp & 1;
|
|
|
|
goto cbshflg1;
|
|
|
|
case 0x08: /* RRC */
|
|
|
|
temp = (acu >> 1) | (acu << 7);
|
|
|
|
cbits = temp & 0x80;
|
|
|
|
goto cbshflg1;
|
|
|
|
case 0x10: /* RL */
|
|
|
|
temp = (acu << 1) | TSTFLAG(C);
|
|
|
|
cbits = acu & 0x80;
|
|
|
|
goto cbshflg1;
|
|
|
|
case 0x18: /* RR */
|
|
|
|
temp = (acu >> 1) | (TSTFLAG(C) << 7);
|
|
|
|
cbits = acu & 1;
|
|
|
|
goto cbshflg1;
|
|
|
|
case 0x20: /* SLA */
|
|
|
|
temp = acu << 1;
|
|
|
|
cbits = acu & 0x80;
|
|
|
|
goto cbshflg1;
|
|
|
|
case 0x28: /* SRA */
|
|
|
|
temp = (acu >> 1) | (acu & 0x80);
|
|
|
|
cbits = acu & 1;
|
|
|
|
goto cbshflg1;
|
|
|
|
case 0x30: /* SLIA */
|
|
|
|
temp = (acu << 1) | 1;
|
|
|
|
cbits = acu & 0x80;
|
|
|
|
goto cbshflg1;
|
|
|
|
case 0x38: /* SRL */
|
|
|
|
temp = acu >> 1;
|
|
|
|
cbits = acu & 1;
|
|
|
|
cbshflg1:
|
|
|
|
AF = (AF & ~0xff) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
parity(temp) | !!cbits;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x40: /* BIT */
|
|
|
|
if (acu & (1 << ((op >> 3) & 7)))
|
|
|
|
AF = (AF & ~0xfe) | 0x10 |
|
|
|
|
(((op & 0x38) == 0x38) << 7);
|
|
|
|
else
|
|
|
|
AF = (AF & ~0xfe) | 0x54;
|
|
|
|
if ((op&7) != 6)
|
|
|
|
AF |= (acu & 0x28);
|
|
|
|
temp = acu;
|
|
|
|
break;
|
|
|
|
case 0x80: /* RES */
|
|
|
|
temp = acu & ~(1 << ((op >> 3) & 7));
|
|
|
|
break;
|
|
|
|
case 0xc0: /* SET */
|
|
|
|
temp = acu | (1 << ((op >> 3) & 7));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (op & 7) {
|
|
|
|
case 0: Sethreg(BC, temp); break;
|
|
|
|
case 1: Setlreg(BC, temp); break;
|
|
|
|
case 2: Sethreg(DE, temp); break;
|
|
|
|
case 3: Setlreg(DE, temp); break;
|
|
|
|
case 4: Sethreg(HL, temp); break;
|
|
|
|
case 5: Setlreg(HL, temp); break;
|
|
|
|
case 6: PutBYTE(adr, temp); break;
|
|
|
|
case 7: Sethreg(AF, temp); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0xCC: /* CALL Z,nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xCC];
|
2011-07-18 19:48:57 +00:00
|
|
|
CALLC(TSTFLAG(Z));
|
|
|
|
break;
|
|
|
|
case 0xCD: /* CALL nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xCD];
|
2011-07-18 19:48:57 +00:00
|
|
|
CALLC(1);
|
|
|
|
break;
|
|
|
|
case 0xCE: /* ADC A,nn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xCE];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetBYTE_pp(pc);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp + TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0xCF: /* RST 8 */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xCF];
|
2011-07-18 19:48:57 +00:00
|
|
|
PUSH(pc); pc = 8;
|
|
|
|
break;
|
|
|
|
case 0xD0: /* RET NC */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xD0];
|
2011-07-18 19:48:57 +00:00
|
|
|
if (!TSTFLAG(C)) POP(pc);
|
|
|
|
break;
|
|
|
|
case 0xD1: /* POP DE */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xD1];
|
2011-07-18 19:48:57 +00:00
|
|
|
POP(DE);
|
|
|
|
break;
|
|
|
|
case 0xD2: /* JP NC,nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xD2];
|
2011-07-18 19:48:57 +00:00
|
|
|
Jpc(!TSTFLAG(C));
|
|
|
|
break;
|
|
|
|
case 0xD3: /* OUT (nn),A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xD3];
|
2011-07-18 19:48:57 +00:00
|
|
|
OUTPUT(GetBYTE_pp(pc), hreg(AF));
|
|
|
|
break;
|
|
|
|
case 0xD4: /* CALL NC,nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xD4];
|
2011-07-18 19:48:57 +00:00
|
|
|
CALLC(!TSTFLAG(C));
|
|
|
|
break;
|
|
|
|
case 0xD5: /* PUSH DE */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xD5];
|
2011-07-18 19:48:57 +00:00
|
|
|
PUSH(DE);
|
|
|
|
break;
|
|
|
|
case 0xD6: /* SUB nn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xD6];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetBYTE_pp(pc);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0xD7: /* RST 10H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xD7];
|
2011-07-18 19:48:57 +00:00
|
|
|
PUSH(pc); pc = 0x10;
|
|
|
|
break;
|
|
|
|
case 0xD8: /* RET C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xD8];
|
2011-07-18 19:48:57 +00:00
|
|
|
if (TSTFLAG(C)) POP(pc);
|
|
|
|
break;
|
|
|
|
case 0xD9: /* EXX */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xD9];
|
2011-07-18 19:48:57 +00:00
|
|
|
regs[regs_sel].bc = BC;
|
|
|
|
regs[regs_sel].de = DE;
|
|
|
|
regs[regs_sel].hl = HL;
|
|
|
|
regs_sel = 1 - regs_sel;
|
|
|
|
BC = regs[regs_sel].bc;
|
|
|
|
DE = regs[regs_sel].de;
|
|
|
|
HL = regs[regs_sel].hl;
|
|
|
|
break;
|
|
|
|
case 0xDA: /* JP C,nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xDA];
|
2011-07-18 19:48:57 +00:00
|
|
|
Jpc(TSTFLAG(C));
|
|
|
|
break;
|
|
|
|
case 0xDB: /* IN A,(nn) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xDB];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(AF, INPUT(GetBYTE_pp(pc)));
|
|
|
|
break;
|
|
|
|
case 0xDC: /* CALL C,nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xDC];
|
2011-07-18 19:48:57 +00:00
|
|
|
CALLC(TSTFLAG(C));
|
|
|
|
break;
|
|
|
|
case 0xDD: /* DD prefix */
|
2011-07-26 21:47:59 +00:00
|
|
|
op = GetBYTE_pp(pc);
|
|
|
|
switch (op) {
|
2011-07-18 19:48:57 +00:00
|
|
|
case 0x09: /* ADD IX,BC */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x09];
|
2011-07-18 19:48:57 +00:00
|
|
|
IX &= 0xffff;
|
|
|
|
BC &= 0xffff;
|
|
|
|
sum = IX + BC;
|
|
|
|
cbits = (IX ^ BC ^ sum) >> 8;
|
|
|
|
IX = sum;
|
|
|
|
AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x19: /* ADD IX,DE */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x19];
|
2011-07-18 19:48:57 +00:00
|
|
|
IX &= 0xffff;
|
|
|
|
DE &= 0xffff;
|
|
|
|
sum = IX + DE;
|
|
|
|
cbits = (IX ^ DE ^ sum) >> 8;
|
|
|
|
IX = sum;
|
|
|
|
AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x21: /* LD IX,nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x21];
|
2011-07-18 19:48:57 +00:00
|
|
|
IX = GetWORD(pc);
|
|
|
|
pc += 2;
|
|
|
|
break;
|
|
|
|
case 0x22: /* LD (nnnn),IX */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x22];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetWORD(pc);
|
|
|
|
PutWORD(temp, IX);
|
|
|
|
pc += 2;
|
|
|
|
break;
|
|
|
|
case 0x23: /* INC IX */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x23];
|
2011-07-18 19:48:57 +00:00
|
|
|
++IX;
|
|
|
|
break;
|
|
|
|
case 0x24: /* INC IXH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x24];
|
2011-07-18 19:48:57 +00:00
|
|
|
IX += 0x100;
|
|
|
|
temp = hreg(IX);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0) << 4) |
|
|
|
|
((temp == 0x80) << 2);
|
|
|
|
break;
|
|
|
|
case 0x25: /* DEC IXH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x25];
|
2011-07-18 19:48:57 +00:00
|
|
|
IX -= 0x100;
|
|
|
|
temp = hreg(IX);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0xf) << 4) |
|
|
|
|
((temp == 0x7f) << 2) | 2;
|
|
|
|
break;
|
|
|
|
case 0x26: /* LD IXH,nn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x26];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(IX, GetBYTE_pp(pc));
|
|
|
|
break;
|
|
|
|
case 0x29: /* ADD IX,IX */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x29];
|
2011-07-18 19:48:57 +00:00
|
|
|
IX &= 0xffff;
|
|
|
|
sum = IX + IX;
|
|
|
|
cbits = (IX ^ IX ^ sum) >> 8;
|
|
|
|
IX = sum;
|
|
|
|
AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x2A: /* LD IX,(nnnn) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x2A];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetWORD(pc);
|
|
|
|
IX = GetWORD(temp);
|
|
|
|
pc += 2;
|
|
|
|
break;
|
|
|
|
case 0x2B: /* DEC IX */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x2B];
|
2011-07-18 19:48:57 +00:00
|
|
|
--IX;
|
|
|
|
break;
|
|
|
|
case 0x2C: /* INC IXL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x2C];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(IX)+1;
|
|
|
|
Setlreg(IX, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0) << 4) |
|
|
|
|
((temp == 0x80) << 2);
|
|
|
|
break;
|
|
|
|
case 0x2D: /* DEC IXL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x2D];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(IX)-1;
|
|
|
|
Setlreg(IX, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0xf) << 4) |
|
|
|
|
((temp == 0x7f) << 2) | 2;
|
|
|
|
break;
|
|
|
|
case 0x2E: /* LD IXL,nn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x2E];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(IX, GetBYTE_pp(pc));
|
|
|
|
break;
|
|
|
|
case 0x34: /* INC (IX+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x34];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
temp = GetBYTE(adr)+1;
|
|
|
|
PutBYTE(adr, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0) << 4) |
|
|
|
|
((temp == 0x80) << 2);
|
|
|
|
break;
|
|
|
|
case 0x35: /* DEC (IX+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x35];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
temp = GetBYTE(adr)-1;
|
|
|
|
PutBYTE(adr, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0xf) << 4) |
|
|
|
|
((temp == 0x7f) << 2) | 2;
|
|
|
|
break;
|
|
|
|
case 0x36: /* LD (IX+dd),nn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x36];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
PutBYTE(adr, GetBYTE_pp(pc));
|
|
|
|
break;
|
|
|
|
case 0x39: /* ADD IX,SP */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x39];
|
2011-07-18 19:48:57 +00:00
|
|
|
IX &= 0xffff;
|
|
|
|
SP &= 0xffff;
|
|
|
|
sum = IX + SP;
|
|
|
|
cbits = (IX ^ SP ^ sum) >> 8;
|
|
|
|
IX = sum;
|
|
|
|
AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x44: /* LD B,IXH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x44];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(BC, hreg(IX));
|
|
|
|
break;
|
|
|
|
case 0x45: /* LD B,IXL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x45];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(BC, lreg(IX));
|
|
|
|
break;
|
|
|
|
case 0x46: /* LD B,(IX+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x46];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
Sethreg(BC, GetBYTE(adr));
|
|
|
|
break;
|
|
|
|
case 0x4C: /* LD C,IXH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x4C];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(BC, hreg(IX));
|
|
|
|
break;
|
|
|
|
case 0x4D: /* LD C,IXL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x4D];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(BC, lreg(IX));
|
|
|
|
break;
|
|
|
|
case 0x4E: /* LD C,(IX+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x4E];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
Setlreg(BC, GetBYTE(adr));
|
|
|
|
break;
|
|
|
|
case 0x54: /* LD D,IXH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x54];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(DE, hreg(IX));
|
|
|
|
break;
|
|
|
|
case 0x55: /* LD D,IXL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x55];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(DE, lreg(IX));
|
|
|
|
break;
|
|
|
|
case 0x56: /* LD D,(IX+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x56];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
Sethreg(DE, GetBYTE(adr));
|
|
|
|
break;
|
|
|
|
case 0x5C: /* LD E,H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x5C];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(DE, hreg(IX));
|
|
|
|
break;
|
|
|
|
case 0x5D: /* LD E,L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x5D];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(DE, lreg(IX));
|
|
|
|
break;
|
|
|
|
case 0x5E: /* LD E,(IX+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x5E];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
Setlreg(DE, GetBYTE(adr));
|
|
|
|
break;
|
|
|
|
case 0x60: /* LD IXH,B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x60];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(IX, hreg(BC));
|
|
|
|
break;
|
|
|
|
case 0x61: /* LD IXH,C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x61];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(IX, lreg(BC));
|
|
|
|
break;
|
|
|
|
case 0x62: /* LD IXH,D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x62];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(IX, hreg(DE));
|
|
|
|
break;
|
|
|
|
case 0x63: /* LD IXH,E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x63];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(IX, lreg(DE));
|
|
|
|
break;
|
|
|
|
case 0x64: /* LD IXH,IXH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x64];
|
2011-07-18 19:48:57 +00:00
|
|
|
/* nop */
|
|
|
|
break;
|
|
|
|
case 0x65: /* LD IXH,IXL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x65];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(IX, lreg(IX));
|
|
|
|
break;
|
|
|
|
case 0x66: /* LD H,(IX+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x66];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
Sethreg(HL, GetBYTE(adr));
|
|
|
|
break;
|
|
|
|
case 0x67: /* LD IXH,A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x67];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(IX, hreg(AF));
|
|
|
|
break;
|
|
|
|
case 0x68: /* LD IXL,B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x68];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(IX, hreg(BC));
|
|
|
|
break;
|
|
|
|
case 0x69: /* LD IXL,C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x69];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(IX, lreg(BC));
|
|
|
|
break;
|
|
|
|
case 0x6A: /* LD IXL,D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x6A];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(IX, hreg(DE));
|
|
|
|
break;
|
|
|
|
case 0x6B: /* LD IXL,E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x6B];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(IX, lreg(DE));
|
|
|
|
break;
|
|
|
|
case 0x6C: /* LD IXL,IXH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x6C];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(IX, hreg(IX));
|
|
|
|
break;
|
|
|
|
case 0x6D: /* LD IXL,IXL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x6D];
|
2011-07-18 19:48:57 +00:00
|
|
|
/* nop */
|
|
|
|
break;
|
|
|
|
case 0x6E: /* LD L,(IX+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x6E];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
Setlreg(HL, GetBYTE(adr));
|
|
|
|
break;
|
|
|
|
case 0x6F: /* LD IXL,A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x6F];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(IX, hreg(AF));
|
|
|
|
break;
|
|
|
|
case 0x70: /* LD (IX+dd),B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x70];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
PutBYTE(adr, hreg(BC));
|
|
|
|
break;
|
|
|
|
case 0x71: /* LD (IX+dd),C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x71];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
PutBYTE(adr, lreg(BC));
|
|
|
|
break;
|
|
|
|
case 0x72: /* LD (IX+dd),D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x72];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
PutBYTE(adr, hreg(DE));
|
|
|
|
break;
|
|
|
|
case 0x73: /* LD (IX+dd),E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x73];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
PutBYTE(adr, lreg(DE));
|
|
|
|
break;
|
|
|
|
case 0x74: /* LD (IX+dd),H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x74];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
PutBYTE(adr, hreg(HL));
|
|
|
|
break;
|
|
|
|
case 0x75: /* LD (IX+dd),L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x75];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
PutBYTE(adr, lreg(HL));
|
|
|
|
break;
|
|
|
|
case 0x77: /* LD (IX+dd),A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x77];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
PutBYTE(adr, hreg(AF));
|
|
|
|
break;
|
|
|
|
case 0x7C: /* LD A,IXH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x7C];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(AF, hreg(IX));
|
|
|
|
break;
|
|
|
|
case 0x7D: /* LD A,IXL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x7D];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(AF, lreg(IX));
|
|
|
|
break;
|
|
|
|
case 0x7E: /* LD A,(IX+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x7E];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
Sethreg(AF, GetBYTE(adr));
|
|
|
|
break;
|
|
|
|
case 0x84: /* ADD A,IXH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x84];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(IX);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x85: /* ADD A,IXL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x85];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(IX);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x86: /* ADD A,(IX+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x86];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
temp = GetBYTE(adr);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x8C: /* ADC A,IXH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x8C];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(IX);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp + TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x8D: /* ADC A,IXL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x8D];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(IX);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp + TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x8E: /* ADC A,(IX+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x8E];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
temp = GetBYTE(adr);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp + TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x94: /* SUB IXH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x94];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(IX);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x95: /* SUB IXL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x95];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(IX);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x96: /* SUB (IX+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x96];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
temp = GetBYTE(adr);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x9C: /* SBC A,IXH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x9C];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(IX);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp - TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x9D: /* SBC A,IXL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x9D];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(IX);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp - TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x9E: /* SBC A,(IX+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x9E];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
temp = GetBYTE(adr);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp - TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0xA4: /* AND IXH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xA4];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF & (IX)) >> 8) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) |
|
|
|
|
((sum == 0) << 6) | 0x10 | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xA5: /* AND IXL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xA5];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF >> 8) & IX) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | 0x10 |
|
|
|
|
((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xA6: /* AND (IX+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xA6];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
sum = ((AF >> 8) & GetBYTE(adr)) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | 0x10 |
|
|
|
|
((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xAC: /* XOR IXH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xAC];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF ^ (IX)) >> 8) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xAD: /* XOR IXL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xAD];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF >> 8) ^ IX) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xAE: /* XOR (IX+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xAE];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
sum = ((AF >> 8) ^ GetBYTE(adr)) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xB4: /* OR IXH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xB4];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF | (IX)) >> 8) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xB5: /* OR IXL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xB5];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF >> 8) | IX) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xB6: /* OR (IX+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xB6];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
sum = ((AF >> 8) | GetBYTE(adr)) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xBC: /* CP IXH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xBC];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(IX);
|
|
|
|
AF = (AF & ~0x28) | (temp & 0x28);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = (AF & ~0xff) | (sum & 0x80) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (temp & 0x28) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0xBD: /* CP IXL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xBD];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(IX);
|
|
|
|
AF = (AF & ~0x28) | (temp & 0x28);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = (AF & ~0xff) | (sum & 0x80) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (temp & 0x28) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0xBE: /* CP (IX+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xBE];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
temp = GetBYTE(adr);
|
|
|
|
AF = (AF & ~0x28) | (temp & 0x28);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = (AF & ~0xff) | (sum & 0x80) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (temp & 0x28) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0xCB: /* CB prefix */
|
|
|
|
adr = IX + (signed char) GetBYTE_pp(pc);
|
|
|
|
adr = adr;
|
2011-07-26 21:47:59 +00:00
|
|
|
op = GetBYTE(pc);
|
|
|
|
cycles -= cycleTables[4][op];
|
|
|
|
switch (op & 7) {
|
2011-07-18 19:48:57 +00:00
|
|
|
case 0: ++pc; acu = hreg(BC); break;
|
|
|
|
case 1: ++pc; acu = lreg(BC); break;
|
|
|
|
case 2: ++pc; acu = hreg(DE); break;
|
|
|
|
case 3: ++pc; acu = lreg(DE); break;
|
|
|
|
case 4: ++pc; acu = hreg(HL); break;
|
|
|
|
case 5: ++pc; acu = lreg(HL); break;
|
|
|
|
case 6: ++pc; acu = GetBYTE(adr); break;
|
|
|
|
case 7: ++pc; acu = hreg(AF); break;
|
|
|
|
}
|
|
|
|
switch (op & 0xc0) {
|
|
|
|
case 0x00: /* shift/rotate */
|
|
|
|
switch (op & 0x38) {
|
|
|
|
case 0x00: /* RLC */
|
|
|
|
temp = (acu << 1) | (acu >> 7);
|
|
|
|
cbits = temp & 1;
|
|
|
|
goto cbshflg2;
|
|
|
|
case 0x08: /* RRC */
|
|
|
|
temp = (acu >> 1) | (acu << 7);
|
|
|
|
cbits = temp & 0x80;
|
|
|
|
goto cbshflg2;
|
|
|
|
case 0x10: /* RL */
|
|
|
|
temp = (acu << 1) | TSTFLAG(C);
|
|
|
|
cbits = acu & 0x80;
|
|
|
|
goto cbshflg2;
|
|
|
|
case 0x18: /* RR */
|
|
|
|
temp = (acu >> 1) | (TSTFLAG(C) << 7);
|
|
|
|
cbits = acu & 1;
|
|
|
|
goto cbshflg2;
|
|
|
|
case 0x20: /* SLA */
|
|
|
|
temp = acu << 1;
|
|
|
|
cbits = acu & 0x80;
|
|
|
|
goto cbshflg2;
|
|
|
|
case 0x28: /* SRA */
|
|
|
|
temp = (acu >> 1) | (acu & 0x80);
|
|
|
|
cbits = acu & 1;
|
|
|
|
goto cbshflg2;
|
|
|
|
case 0x30: /* SLIA */
|
|
|
|
temp = (acu << 1) | 1;
|
|
|
|
cbits = acu & 0x80;
|
|
|
|
goto cbshflg2;
|
|
|
|
case 0x38: /* SRL */
|
|
|
|
temp = acu >> 1;
|
|
|
|
cbits = acu & 1;
|
|
|
|
cbshflg2:
|
|
|
|
AF = (AF & ~0xff) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
parity(temp) | !!cbits;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x40: /* BIT */
|
|
|
|
if (acu & (1 << ((op >> 3) & 7)))
|
|
|
|
AF = (AF & ~0xfe) | 0x10 |
|
|
|
|
(((op & 0x38) == 0x38) << 7);
|
|
|
|
else
|
|
|
|
AF = (AF & ~0xfe) | 0x54;
|
|
|
|
if ((op&7) != 6)
|
|
|
|
AF |= (acu & 0x28);
|
|
|
|
temp = acu;
|
|
|
|
break;
|
|
|
|
case 0x80: /* RES */
|
|
|
|
temp = acu & ~(1 << ((op >> 3) & 7));
|
|
|
|
break;
|
|
|
|
case 0xc0: /* SET */
|
|
|
|
temp = acu | (1 << ((op >> 3) & 7));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (op & 7) {
|
|
|
|
case 0: Sethreg(BC, temp); break;
|
|
|
|
case 1: Setlreg(BC, temp); break;
|
|
|
|
case 2: Sethreg(DE, temp); break;
|
|
|
|
case 3: Setlreg(DE, temp); break;
|
|
|
|
case 4: Sethreg(HL, temp); break;
|
|
|
|
case 5: Setlreg(HL, temp); break;
|
|
|
|
case 6: PutBYTE(adr, temp); break;
|
|
|
|
case 7: Sethreg(AF, temp); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0xE1: /* POP IX */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xE1];
|
2011-07-18 19:48:57 +00:00
|
|
|
POP(IX);
|
|
|
|
break;
|
|
|
|
case 0xE3: /* EX (SP),IX */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xE3];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = IX; POP(IX); PUSH(temp);
|
|
|
|
break;
|
|
|
|
case 0xE5: /* PUSH IX */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xE5];
|
2011-07-18 19:48:57 +00:00
|
|
|
PUSH(IX);
|
|
|
|
break;
|
|
|
|
case 0xE9: /* JP (IX) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xE9];
|
2011-07-18 19:48:57 +00:00
|
|
|
pc = IX;
|
|
|
|
break;
|
|
|
|
case 0xF9: /* LD SP,IX */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xF9];
|
2011-07-18 19:48:57 +00:00
|
|
|
SP = IX;
|
|
|
|
break;
|
|
|
|
default: pc--; /* ignore DD */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0xDE: /* SBC A,nn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xDE];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetBYTE_pp(pc);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp - TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0xDF: /* RST 18H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xDF];
|
2011-07-18 19:48:57 +00:00
|
|
|
PUSH(pc); pc = 0x18;
|
|
|
|
break;
|
|
|
|
case 0xE0: /* RET PO */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xE0];
|
2011-07-18 19:48:57 +00:00
|
|
|
if (!TSTFLAG(P)) POP(pc);
|
|
|
|
break;
|
|
|
|
case 0xE1: /* POP HL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xE1];
|
2011-07-18 19:48:57 +00:00
|
|
|
POP(HL);
|
|
|
|
break;
|
|
|
|
case 0xE2: /* JP PO,nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xE2];
|
2011-07-18 19:48:57 +00:00
|
|
|
Jpc(!TSTFLAG(P));
|
|
|
|
break;
|
|
|
|
case 0xE3: /* EX (SP),HL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xE3];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = HL; POP(HL); PUSH(temp);
|
|
|
|
break;
|
|
|
|
case 0xE4: /* CALL PO,nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xE4];
|
2011-07-18 19:48:57 +00:00
|
|
|
CALLC(!TSTFLAG(P));
|
|
|
|
break;
|
|
|
|
case 0xE5: /* PUSH HL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xE5];
|
2011-07-18 19:48:57 +00:00
|
|
|
PUSH(HL);
|
|
|
|
break;
|
|
|
|
case 0xE6: /* AND nn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xE6];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF >> 8) & GetBYTE_pp(pc)) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | 0x10 |
|
|
|
|
((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xE7: /* RST 20H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xE7];
|
2011-07-18 19:48:57 +00:00
|
|
|
PUSH(pc); pc = 0x20;
|
|
|
|
break;
|
|
|
|
case 0xE8: /* RET PE */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xE8];
|
2011-07-18 19:48:57 +00:00
|
|
|
if (TSTFLAG(P)) POP(pc);
|
|
|
|
break;
|
|
|
|
case 0xE9: /* JP (HL) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xE9];
|
2011-07-18 19:48:57 +00:00
|
|
|
pc = HL;
|
|
|
|
break;
|
|
|
|
case 0xEA: /* JP PE,nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xEA];
|
2011-07-18 19:48:57 +00:00
|
|
|
Jpc(TSTFLAG(P));
|
|
|
|
break;
|
|
|
|
case 0xEB: /* EX DE,HL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xEB];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = HL; HL = DE; DE = temp;
|
|
|
|
break;
|
|
|
|
case 0xEC: /* CALL PE,nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xEC];
|
2011-07-18 19:48:57 +00:00
|
|
|
CALLC(TSTFLAG(P));
|
|
|
|
break;
|
|
|
|
case 0xED: /* ED prefix */
|
2011-07-26 21:47:59 +00:00
|
|
|
op = GetBYTE_pp(pc);
|
|
|
|
switch (op) {
|
2011-07-18 19:48:57 +00:00
|
|
|
case 0x40: /* IN B,(C) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x40];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = INPUT(lreg(BC));
|
|
|
|
Sethreg(BC, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
parity(temp);
|
|
|
|
break;
|
|
|
|
case 0x41: /* OUT (C),B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x41];
|
2011-07-18 19:48:57 +00:00
|
|
|
OUTPUT(lreg(BC), BC);
|
|
|
|
break;
|
|
|
|
case 0x42: /* SBC HL,BC */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x42];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL &= 0xffff;
|
|
|
|
BC &= 0xffff;
|
|
|
|
sum = HL - BC - TSTFLAG(C);
|
|
|
|
cbits = (HL ^ BC ^ sum) >> 8;
|
|
|
|
HL = sum;
|
|
|
|
AF = (AF & ~0xff) | ((sum >> 8) & 0xa8) |
|
|
|
|
(((sum & 0xffff) == 0) << 6) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
(cbits & 0x10) | 2 | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x43: /* LD (nnnn),BC */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x43];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetWORD(pc);
|
|
|
|
PutWORD(temp, BC);
|
|
|
|
pc += 2;
|
|
|
|
break;
|
|
|
|
case 0x44: /* NEG */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x44];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(AF);
|
|
|
|
AF = (-(AF & 0xff00) & 0xff00);
|
|
|
|
AF |= ((AF >> 8) & 0xa8) | (((AF & 0xff00) == 0) << 6) |
|
|
|
|
(((temp & 0x0f) != 0) << 4) | ((temp == 0x80) << 2) |
|
|
|
|
2 | (temp != 0);
|
|
|
|
break;
|
|
|
|
case 0x45: /* RETN */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x45];
|
2011-07-18 19:48:57 +00:00
|
|
|
iff |= iff >> 1;
|
|
|
|
POP(pc);
|
|
|
|
break;
|
|
|
|
case 0x46: /* IM 0 */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x46];
|
2011-07-18 19:48:57 +00:00
|
|
|
im = 0; // interrupt mode 0
|
|
|
|
break;
|
|
|
|
case 0x47: /* LD I,A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x47];
|
2011-07-18 19:48:57 +00:00
|
|
|
ir = (ir & 255) | (AF & ~255);
|
|
|
|
break;
|
|
|
|
case 0x48: /* IN C,(C) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x48];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = INPUT(lreg(BC));
|
|
|
|
Setlreg(BC, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
parity(temp);
|
|
|
|
break;
|
|
|
|
case 0x49: /* OUT (C),C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x49];
|
2011-07-18 19:48:57 +00:00
|
|
|
OUTPUT(lreg(BC), BC);
|
|
|
|
break;
|
|
|
|
case 0x4A: /* ADC HL,BC */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x4A];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL &= 0xffff;
|
|
|
|
BC &= 0xffff;
|
|
|
|
sum = HL + BC + TSTFLAG(C);
|
|
|
|
cbits = (HL ^ BC ^ sum) >> 8;
|
|
|
|
HL = sum;
|
|
|
|
AF = (AF & ~0xff) | ((sum >> 8) & 0xa8) |
|
|
|
|
(((sum & 0xffff) == 0) << 6) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x4B: /* LD BC,(nnnn) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x4B];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetWORD(pc);
|
|
|
|
BC = GetWORD(temp);
|
|
|
|
pc += 2;
|
|
|
|
break;
|
|
|
|
case 0x4D: /* RETI */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x4D];
|
2011-07-18 19:48:57 +00:00
|
|
|
iff |= iff >> 1;
|
|
|
|
POP(pc);
|
|
|
|
break;
|
|
|
|
case 0x4F: /* LD R,A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x4F];
|
2011-07-18 19:48:57 +00:00
|
|
|
ir = (ir & ~255) | ((AF >> 8) & 255);
|
|
|
|
break;
|
|
|
|
case 0x50: /* IN D,(C) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x50];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = INPUT(lreg(BC));
|
|
|
|
Sethreg(DE, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
parity(temp);
|
|
|
|
break;
|
|
|
|
case 0x51: /* OUT (C),D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x51];
|
2011-07-18 19:48:57 +00:00
|
|
|
OUTPUT(lreg(BC), DE);
|
|
|
|
break;
|
|
|
|
case 0x52: /* SBC HL,DE */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x52];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL &= 0xffff;
|
|
|
|
DE &= 0xffff;
|
|
|
|
sum = HL - DE - TSTFLAG(C);
|
|
|
|
cbits = (HL ^ DE ^ sum) >> 8;
|
|
|
|
HL = sum;
|
|
|
|
AF = (AF & ~0xff) | ((sum >> 8) & 0xa8) |
|
|
|
|
(((sum & 0xffff) == 0) << 6) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
(cbits & 0x10) | 2 | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x53: /* LD (nnnn),DE */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x53];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetWORD(pc);
|
|
|
|
PutWORD(temp, DE);
|
|
|
|
pc += 2;
|
|
|
|
break;
|
|
|
|
case 0x56: /* IM 1 */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x56];
|
2011-07-18 19:48:57 +00:00
|
|
|
im = 1; // interrupt mode 1
|
|
|
|
break;
|
|
|
|
case 0x57: /* LD A,I */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x57];
|
2011-07-18 19:48:57 +00:00
|
|
|
AF = (AF & 0x29) | (ir & ~255) | ((ir >> 8) & 0x80) | (((ir & ~255) == 0) << 6) | ((iff & 2) << 1);
|
|
|
|
break;
|
|
|
|
case 0x58: /* IN E,(C) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x58];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = INPUT(lreg(BC));
|
|
|
|
Setlreg(DE, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
parity(temp);
|
|
|
|
break;
|
|
|
|
case 0x59: /* OUT (C),E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x59];
|
2011-07-18 19:48:57 +00:00
|
|
|
OUTPUT(lreg(BC), DE);
|
|
|
|
break;
|
|
|
|
case 0x5A: /* ADC HL,DE */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x5A];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL &= 0xffff;
|
|
|
|
DE &= 0xffff;
|
|
|
|
sum = HL + DE + TSTFLAG(C);
|
|
|
|
cbits = (HL ^ DE ^ sum) >> 8;
|
|
|
|
HL = sum;
|
|
|
|
AF = (AF & ~0xff) | ((sum >> 8) & 0xa8) |
|
|
|
|
(((sum & 0xffff) == 0) << 6) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x5B: /* LD DE,(nnnn) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x5B];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetWORD(pc);
|
|
|
|
DE = GetWORD(temp);
|
|
|
|
pc += 2;
|
|
|
|
break;
|
|
|
|
case 0x5E: /* IM 2 */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x5E];
|
2011-07-18 19:48:57 +00:00
|
|
|
im = 2; // interrupt mode 2
|
|
|
|
break;
|
|
|
|
case 0x5F: /* LD A,R */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x5F];
|
2011-07-18 19:48:57 +00:00
|
|
|
AF = (AF & 0x29) | ((ir & 255) << 8) | (ir & 0x80) | (((ir & 255) == 0) << 6) | ((iff & 2) << 1);
|
|
|
|
break;
|
|
|
|
case 0x60: /* IN H,(C) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x60];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = INPUT(lreg(BC));
|
|
|
|
Sethreg(HL, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
parity(temp);
|
|
|
|
break;
|
|
|
|
case 0x61: /* OUT (C),H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x61];
|
2011-07-18 19:48:57 +00:00
|
|
|
OUTPUT(lreg(BC), HL);
|
|
|
|
break;
|
|
|
|
case 0x62: /* SBC HL,HL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x62];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL &= 0xffff;
|
|
|
|
sum = HL - HL - TSTFLAG(C);
|
|
|
|
cbits = (HL ^ HL ^ sum) >> 8;
|
|
|
|
HL = sum;
|
|
|
|
AF = (AF & ~0xff) | ((sum >> 8) & 0xa8) |
|
|
|
|
(((sum & 0xffff) == 0) << 6) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
(cbits & 0x10) | 2 | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x63: /* LD (nnnn),HL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x63];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetWORD(pc);
|
|
|
|
PutWORD(temp, HL);
|
|
|
|
pc += 2;
|
|
|
|
break;
|
|
|
|
case 0x67: /* RRD */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x67];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetBYTE(HL);
|
|
|
|
acu = hreg(AF);
|
|
|
|
PutBYTE(HL, hdig(temp) | (ldig(acu) << 4));
|
|
|
|
acu = (acu & 0xf0) | ldig(temp);
|
|
|
|
AF = (acu << 8) | (acu & 0xa8) | (((acu & 0xff) == 0) << 6) |
|
|
|
|
partab[acu] | (AF & 1);
|
|
|
|
break;
|
|
|
|
case 0x68: /* IN L,(C) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x68];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = INPUT(lreg(BC));
|
|
|
|
Setlreg(HL, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
parity(temp);
|
|
|
|
break;
|
|
|
|
case 0x69: /* OUT (C),L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x69];
|
2011-07-18 19:48:57 +00:00
|
|
|
OUTPUT(lreg(BC), HL);
|
|
|
|
break;
|
|
|
|
case 0x6A: /* ADC HL,HL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x6A];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL &= 0xffff;
|
|
|
|
sum = HL + HL + TSTFLAG(C);
|
|
|
|
cbits = (HL ^ HL ^ sum) >> 8;
|
|
|
|
HL = sum;
|
|
|
|
AF = (AF & ~0xff) | ((sum >> 8) & 0xa8) |
|
|
|
|
(((sum & 0xffff) == 0) << 6) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x6B: /* LD HL,(nnnn) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x6B];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetWORD(pc);
|
|
|
|
HL = GetWORD(temp);
|
|
|
|
pc += 2;
|
|
|
|
break;
|
|
|
|
case 0x6F: /* RLD */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x6F];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetBYTE(HL);
|
|
|
|
acu = hreg(AF);
|
|
|
|
PutBYTE(HL, (ldig(temp) << 4) | ldig(acu));
|
|
|
|
acu = (acu & 0xf0) | hdig(temp);
|
|
|
|
AF = (acu << 8) | (acu & 0xa8) | (((acu & 0xff) == 0) << 6) |
|
|
|
|
partab[acu] | (AF & 1);
|
|
|
|
break;
|
|
|
|
case 0x70: /* IN (C) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x70];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = INPUT(lreg(BC));
|
|
|
|
Setlreg(temp, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
parity(temp);
|
|
|
|
break;
|
|
|
|
case 0x71: /* OUT (C),0 */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x71];
|
2011-07-18 19:48:57 +00:00
|
|
|
OUTPUT(lreg(BC), 0);
|
|
|
|
break;
|
|
|
|
case 0x72: /* SBC HL,SP */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x72];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL &= 0xffff;
|
|
|
|
SP &= 0xffff;
|
|
|
|
sum = HL - SP - TSTFLAG(C);
|
|
|
|
cbits = (HL ^ SP ^ sum) >> 8;
|
|
|
|
HL = sum;
|
|
|
|
AF = (AF & ~0xff) | ((sum >> 8) & 0xa8) |
|
|
|
|
(((sum & 0xffff) == 0) << 6) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
(cbits & 0x10) | 2 | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x73: /* LD (nnnn),SP */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x73];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetWORD(pc);
|
|
|
|
PutWORD(temp, SP);
|
|
|
|
pc += 2;
|
|
|
|
break;
|
|
|
|
case 0x78: /* IN A,(C) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x78];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = INPUT(lreg(BC));
|
|
|
|
Sethreg(AF, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
parity(temp);
|
|
|
|
break;
|
|
|
|
case 0x79: /* OUT (C),A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x79];
|
2011-07-18 19:48:57 +00:00
|
|
|
OUTPUT(lreg(BC), AF);
|
|
|
|
break;
|
|
|
|
case 0x7A: /* ADC HL,SP */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x7A];
|
2011-07-18 19:48:57 +00:00
|
|
|
HL &= 0xffff;
|
|
|
|
SP &= 0xffff;
|
|
|
|
sum = HL + SP + TSTFLAG(C);
|
|
|
|
cbits = (HL ^ SP ^ sum) >> 8;
|
|
|
|
HL = sum;
|
|
|
|
AF = (AF & ~0xff) | ((sum >> 8) & 0xa8) |
|
|
|
|
(((sum & 0xffff) == 0) << 6) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x7B: /* LD SP,(nnnn) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0x7B];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetWORD(pc);
|
|
|
|
SP = GetWORD(temp);
|
|
|
|
pc += 2;
|
|
|
|
break;
|
|
|
|
case 0xA0: /* LDI */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0xA0];
|
2011-07-18 19:48:57 +00:00
|
|
|
acu = GetBYTE_pp(HL);
|
|
|
|
PutBYTE_pp(DE, acu);
|
|
|
|
acu += hreg(AF);
|
|
|
|
AF = (AF & ~0x3e) | (acu & 8) | ((acu & 2) << 4) |
|
|
|
|
(((--BC & 0xffff) != 0) << 2);
|
|
|
|
break;
|
|
|
|
case 0xA1: /* CPI */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0xA1];
|
2011-07-18 19:48:57 +00:00
|
|
|
acu = hreg(AF);
|
|
|
|
temp = GetBYTE_pp(HL);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = (AF & ~0xfe) | (sum & 0x80) | (!(sum & 0xff) << 6) |
|
|
|
|
(((sum - ((cbits&16)>>4))&2) << 4) | (cbits & 16) |
|
|
|
|
((sum - ((cbits >> 4) & 1)) & 8) |
|
|
|
|
((--BC & 0xffff) != 0) << 2 | 2;
|
|
|
|
if ((sum & 15) == 8 && (cbits & 16) != 0)
|
|
|
|
AF &= ~8;
|
|
|
|
break;
|
|
|
|
case 0xA2: /* INI */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0xA2];
|
2011-07-18 19:48:57 +00:00
|
|
|
PutBYTE(HL, INPUT(lreg(BC))); ++HL;
|
|
|
|
SETFLAG(N, 1);
|
|
|
|
SETFLAG(P, (--BC & 0xffff) != 0);
|
|
|
|
break;
|
|
|
|
case 0xA3: /* OUTI */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0xA3];
|
2011-07-18 19:48:57 +00:00
|
|
|
OUTPUT(lreg(BC), GetBYTE(HL)); ++HL;
|
|
|
|
SETFLAG(N, 1);
|
|
|
|
Sethreg(BC, hreg(BC) - 1);
|
|
|
|
SETFLAG(Z, hreg(BC) == 0);
|
|
|
|
break;
|
|
|
|
case 0xA8: /* LDD */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0xA8];
|
2011-07-18 19:48:57 +00:00
|
|
|
acu = GetBYTE_mm(HL);
|
|
|
|
PutBYTE_mm(DE, acu);
|
|
|
|
acu += hreg(AF);
|
|
|
|
AF = (AF & ~0x3e) | (acu & 8) | ((acu & 2) << 4) |
|
|
|
|
(((--BC & 0xffff) != 0) << 2);
|
|
|
|
break;
|
|
|
|
case 0xA9: /* CPD */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0xA9];
|
2011-07-18 19:48:57 +00:00
|
|
|
acu = hreg(AF);
|
|
|
|
temp = GetBYTE_mm(HL);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = (AF & ~0xfe) | (sum & 0x80) | (!(sum & 0xff) << 6) |
|
|
|
|
(((sum - ((cbits&16)>>4))&2) << 4) | (cbits & 16) |
|
|
|
|
((sum - ((cbits >> 4) & 1)) & 8) |
|
|
|
|
((--BC & 0xffff) != 0) << 2 | 2;
|
|
|
|
if ((sum & 15) == 8 && (cbits & 16) != 0)
|
|
|
|
AF &= ~8;
|
|
|
|
break;
|
|
|
|
case 0xAA: /* IND */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0xAA];
|
2011-07-18 19:48:57 +00:00
|
|
|
PutBYTE(HL, INPUT(lreg(BC))); --HL;
|
|
|
|
SETFLAG(N, 1);
|
|
|
|
Sethreg(BC, lreg(BC) - 1);
|
|
|
|
SETFLAG(Z, lreg(BC) == 0);
|
|
|
|
break;
|
|
|
|
case 0xAB: /* OUTD */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0xAB];
|
2011-07-18 19:48:57 +00:00
|
|
|
OUTPUT(lreg(BC), GetBYTE(HL)); --HL;
|
|
|
|
SETFLAG(N, 1);
|
|
|
|
Sethreg(BC, hreg(BC) - 1);
|
|
|
|
SETFLAG(Z, hreg(BC) == 0);
|
|
|
|
break;
|
|
|
|
case 0xB0: /* LDIR */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0xB0];
|
2011-07-18 19:48:57 +00:00
|
|
|
acu = hreg(AF);
|
|
|
|
BC &= 0xffff;
|
|
|
|
do {
|
|
|
|
acu = GetBYTE_pp(HL);
|
|
|
|
PutBYTE_pp(DE, acu);
|
|
|
|
} while (--BC);
|
|
|
|
acu += hreg(AF);
|
|
|
|
AF = (AF & ~0x3e) | (acu & 8) | ((acu & 2) << 4);
|
|
|
|
break;
|
|
|
|
case 0xB1: /* CPIR */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0xB1];
|
2011-07-18 19:48:57 +00:00
|
|
|
acu = hreg(AF);
|
|
|
|
BC &= 0xffff;
|
|
|
|
do {
|
|
|
|
temp = GetBYTE_pp(HL);
|
|
|
|
op = --BC != 0;
|
|
|
|
sum = acu - temp;
|
|
|
|
} while (op && sum != 0);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = (AF & ~0xfe) | (sum & 0x80) | (!(sum & 0xff) << 6) |
|
|
|
|
(((sum - ((cbits&16)>>4))&2) << 4) |
|
|
|
|
(cbits & 16) | ((sum - ((cbits >> 4) & 1)) & 8) |
|
|
|
|
op << 2 | 2;
|
|
|
|
if ((sum & 15) == 8 && (cbits & 16) != 0)
|
|
|
|
AF &= ~8;
|
|
|
|
break;
|
|
|
|
case 0xB2: /* INIR */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0xB2];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(BC);
|
|
|
|
do {
|
|
|
|
PutBYTE(HL, INPUT(lreg(BC))); ++HL;
|
|
|
|
} while (--temp);
|
|
|
|
Sethreg(BC, 0);
|
|
|
|
SETFLAG(N, 1);
|
|
|
|
SETFLAG(Z, 1);
|
|
|
|
break;
|
|
|
|
case 0xB3: /* OTIR */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0xB3];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(BC);
|
|
|
|
do {
|
|
|
|
OUTPUT(lreg(BC), GetBYTE(HL)); ++HL;
|
|
|
|
} while (--temp);
|
|
|
|
Sethreg(BC, 0);
|
|
|
|
SETFLAG(N, 1);
|
|
|
|
SETFLAG(Z, 1);
|
|
|
|
break;
|
|
|
|
case 0xB8: /* LDDR */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0xB8];
|
2011-07-18 19:48:57 +00:00
|
|
|
BC &= 0xffff;
|
|
|
|
do {
|
|
|
|
acu = GetBYTE_mm(HL);
|
|
|
|
PutBYTE_mm(DE, acu);
|
|
|
|
} while (--BC);
|
|
|
|
acu += hreg(AF);
|
|
|
|
AF = (AF & ~0x3e) | (acu & 8) | ((acu & 2) << 4);
|
|
|
|
break;
|
|
|
|
case 0xB9: /* CPDR */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0xB9];
|
2011-07-18 19:48:57 +00:00
|
|
|
acu = hreg(AF);
|
|
|
|
BC &= 0xffff;
|
|
|
|
do {
|
|
|
|
temp = GetBYTE_mm(HL);
|
|
|
|
op = --BC != 0;
|
|
|
|
sum = acu - temp;
|
|
|
|
} while (op && sum != 0);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = (AF & ~0xfe) | (sum & 0x80) | (!(sum & 0xff) << 6) |
|
|
|
|
(((sum - ((cbits&16)>>4))&2) << 4) |
|
|
|
|
(cbits & 16) | ((sum - ((cbits >> 4) & 1)) & 8) |
|
|
|
|
op << 2 | 2;
|
|
|
|
if ((sum & 15) == 8 && (cbits & 16) != 0)
|
|
|
|
AF &= ~8;
|
|
|
|
break;
|
|
|
|
case 0xBA: /* INDR */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0xBA];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(BC);
|
|
|
|
do {
|
|
|
|
PutBYTE(HL, INPUT(lreg(BC))); --HL;
|
|
|
|
} while (--temp);
|
|
|
|
Sethreg(BC, 0);
|
|
|
|
SETFLAG(N, 1);
|
|
|
|
SETFLAG(Z, 1);
|
|
|
|
break;
|
|
|
|
case 0xBB: /* OTDR */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[2][0xBB];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(BC);
|
|
|
|
do {
|
|
|
|
OUTPUT(lreg(BC), GetBYTE(HL)); --HL;
|
|
|
|
} while (--temp);
|
|
|
|
Sethreg(BC, 0);
|
|
|
|
SETFLAG(N, 1);
|
|
|
|
SETFLAG(Z, 1);
|
|
|
|
break;
|
|
|
|
default: if (0x40 <= op && op <= 0x7f) pc--; /* ignore ED */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0xEE: /* XOR nn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xEE];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF >> 8) ^ GetBYTE_pp(pc)) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xEF: /* RST 28H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xEF];
|
2011-07-18 19:48:57 +00:00
|
|
|
PUSH(pc); pc = 0x28;
|
|
|
|
break;
|
|
|
|
case 0xF0: /* RET P */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xF0];
|
2011-07-18 19:48:57 +00:00
|
|
|
if (!TSTFLAG(S)) POP(pc);
|
|
|
|
break;
|
|
|
|
case 0xF1: /* POP AF */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xF1];
|
2011-07-18 19:48:57 +00:00
|
|
|
POP(AF);
|
|
|
|
break;
|
|
|
|
case 0xF2: /* JP P,nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xF2];
|
2011-07-18 19:48:57 +00:00
|
|
|
Jpc(!TSTFLAG(S));
|
|
|
|
break;
|
|
|
|
case 0xF3: /* DI */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xF3];
|
2011-07-18 19:48:57 +00:00
|
|
|
iff = 0;
|
|
|
|
break;
|
|
|
|
case 0xF4: /* CALL P,nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xF4];
|
2011-07-18 19:48:57 +00:00
|
|
|
CALLC(!TSTFLAG(S));
|
|
|
|
break;
|
|
|
|
case 0xF5: /* PUSH AF */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xF5];
|
2011-07-18 19:48:57 +00:00
|
|
|
PUSH(AF);
|
|
|
|
break;
|
|
|
|
case 0xF6: /* OR nn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xF6];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF >> 8) | GetBYTE_pp(pc)) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xF7: /* RST 30H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xF7];
|
2011-07-18 19:48:57 +00:00
|
|
|
PUSH(pc); pc = 0x30;
|
|
|
|
break;
|
|
|
|
case 0xF8: /* RET M */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xF8];
|
2011-07-18 19:48:57 +00:00
|
|
|
if (TSTFLAG(S)) POP(pc);
|
|
|
|
break;
|
|
|
|
case 0xF9: /* LD SP,HL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xF9];
|
2011-07-18 19:48:57 +00:00
|
|
|
SP = HL;
|
|
|
|
break;
|
|
|
|
case 0xFA: /* JP M,nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xFA];
|
2011-07-18 19:48:57 +00:00
|
|
|
Jpc(TSTFLAG(S));
|
|
|
|
break;
|
|
|
|
case 0xFB: /* EI */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xFB];
|
2011-07-18 19:48:57 +00:00
|
|
|
iff = 3;
|
|
|
|
break;
|
|
|
|
case 0xFC: /* CALL M,nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xFC];
|
2011-07-18 19:48:57 +00:00
|
|
|
CALLC(TSTFLAG(S));
|
|
|
|
break;
|
|
|
|
case 0xFD: /* FD prefix */
|
2011-07-26 21:47:59 +00:00
|
|
|
op = GetBYTE_pp(pc);
|
|
|
|
switch (op) {
|
2011-07-18 19:48:57 +00:00
|
|
|
case 0x09: /* ADD IY,BC */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x09];
|
2011-07-18 19:48:57 +00:00
|
|
|
IY &= 0xffff;
|
|
|
|
BC &= 0xffff;
|
|
|
|
sum = IY + BC;
|
|
|
|
cbits = (IY ^ BC ^ sum) >> 8;
|
|
|
|
IY = sum;
|
|
|
|
AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x19: /* ADD IY,DE */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x19];
|
2011-07-18 19:48:57 +00:00
|
|
|
IY &= 0xffff;
|
|
|
|
DE &= 0xffff;
|
|
|
|
sum = IY + DE;
|
|
|
|
cbits = (IY ^ DE ^ sum) >> 8;
|
|
|
|
IY = sum;
|
|
|
|
AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x21: /* LD IY,nnnn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x21];
|
2011-07-18 19:48:57 +00:00
|
|
|
IY = GetWORD(pc);
|
|
|
|
pc += 2;
|
|
|
|
break;
|
|
|
|
case 0x22: /* LD (nnnn),IY */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x22];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetWORD(pc);
|
|
|
|
PutWORD(temp, IY);
|
|
|
|
pc += 2;
|
|
|
|
break;
|
|
|
|
case 0x23: /* INC IY */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x23];
|
2011-07-18 19:48:57 +00:00
|
|
|
++IY;
|
|
|
|
break;
|
|
|
|
case 0x24: /* INC IYH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x24];
|
2011-07-18 19:48:57 +00:00
|
|
|
IY += 0x100;
|
|
|
|
temp = hreg(IY);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0) << 4) |
|
|
|
|
((temp == 0x80) << 2);
|
|
|
|
break;
|
|
|
|
case 0x25: /* DEC IYH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x25];
|
2011-07-18 19:48:57 +00:00
|
|
|
IY -= 0x100;
|
|
|
|
temp = hreg(IY);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0xf) << 4) |
|
|
|
|
((temp == 0x7f) << 2) | 2;
|
|
|
|
break;
|
|
|
|
case 0x26: /* LD IYH,nn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x26];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(IY, GetBYTE_pp(pc));
|
|
|
|
break;
|
|
|
|
case 0x29: /* ADD IY,IY */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x29];
|
2011-07-18 19:48:57 +00:00
|
|
|
IY &= 0xffff;
|
|
|
|
sum = IY + IY;
|
|
|
|
cbits = (IY ^ IY ^ sum) >> 8;
|
|
|
|
IY = sum;
|
|
|
|
AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x2A: /* LD IY,(nnnn) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x2A];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetWORD(pc);
|
|
|
|
IY = GetWORD(temp);
|
|
|
|
pc += 2;
|
|
|
|
break;
|
|
|
|
case 0x2B: /* DEC IY */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x2B];
|
2011-07-18 19:48:57 +00:00
|
|
|
--IY;
|
|
|
|
break;
|
|
|
|
case 0x2C: /* INC IYL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x2C];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(IY)+1;
|
|
|
|
Setlreg(IY, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0) << 4) |
|
|
|
|
((temp == 0x80) << 2);
|
|
|
|
break;
|
|
|
|
case 0x2D: /* DEC IYL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x2D];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(IY)-1;
|
|
|
|
Setlreg(IY, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0xf) << 4) |
|
|
|
|
((temp == 0x7f) << 2) | 2;
|
|
|
|
break;
|
|
|
|
case 0x2E: /* LD IYL,nn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x2E];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(IY, GetBYTE_pp(pc));
|
|
|
|
break;
|
|
|
|
case 0x34: /* INC (IY+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x34];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
temp = GetBYTE(adr)+1;
|
|
|
|
PutBYTE(adr, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0) << 4) |
|
|
|
|
((temp == 0x80) << 2);
|
|
|
|
break;
|
|
|
|
case 0x35: /* DEC (IY+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x35];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
temp = GetBYTE(adr)-1;
|
|
|
|
PutBYTE(adr, temp);
|
|
|
|
AF = (AF & ~0xfe) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
(((temp & 0xf) == 0xf) << 4) |
|
|
|
|
((temp == 0x7f) << 2) | 2;
|
|
|
|
break;
|
|
|
|
case 0x36: /* LD (IY+dd),nn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x36];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
PutBYTE(adr, GetBYTE_pp(pc));
|
|
|
|
break;
|
|
|
|
case 0x39: /* ADD IY,SP */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x39];
|
2011-07-18 19:48:57 +00:00
|
|
|
IY &= 0xffff;
|
|
|
|
SP &= 0xffff;
|
|
|
|
sum = IY + SP;
|
|
|
|
cbits = (IY ^ SP ^ sum) >> 8;
|
|
|
|
IY = sum;
|
|
|
|
AF = (AF & ~0x3b) | ((sum >> 8) & 0x28) |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x44: /* LD B,IYH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x44];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(BC, hreg(IY));
|
|
|
|
break;
|
|
|
|
case 0x45: /* LD B,IYL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x45];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(BC, lreg(IY));
|
|
|
|
break;
|
|
|
|
case 0x46: /* LD B,(IY+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x46];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
Sethreg(BC, GetBYTE(adr));
|
|
|
|
break;
|
|
|
|
case 0x4C: /* LD C,IYH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x4C];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(BC, hreg(IY));
|
|
|
|
break;
|
|
|
|
case 0x4D: /* LD C,IYL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x4D];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(BC, lreg(IY));
|
|
|
|
break;
|
|
|
|
case 0x4E: /* LD C,(IY+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x4E];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
Setlreg(BC, GetBYTE(adr));
|
|
|
|
break;
|
|
|
|
case 0x54: /* LD D,IYH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x54];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(DE, hreg(IY));
|
|
|
|
break;
|
|
|
|
case 0x55: /* LD D,IYL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x55];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(DE, lreg(IY));
|
|
|
|
break;
|
|
|
|
case 0x56: /* LD D,(IY+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x56];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
Sethreg(DE, GetBYTE(adr));
|
|
|
|
break;
|
|
|
|
case 0x5C: /* LD E,H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x5C];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(DE, hreg(IY));
|
|
|
|
break;
|
|
|
|
case 0x5D: /* LD E,L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x5D];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(DE, lreg(IY));
|
|
|
|
break;
|
|
|
|
case 0x5E: /* LD E,(IY+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x5E];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
Setlreg(DE, GetBYTE(adr));
|
|
|
|
break;
|
|
|
|
case 0x60: /* LD IYH,B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x60];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(IY, hreg(BC));
|
|
|
|
break;
|
|
|
|
case 0x61: /* LD IYH,C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x61];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(IY, lreg(BC));
|
|
|
|
break;
|
|
|
|
case 0x62: /* LD IYH,D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x62];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(IY, hreg(DE));
|
|
|
|
break;
|
|
|
|
case 0x63: /* LD IYH,E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x63];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(IY, lreg(DE));
|
|
|
|
break;
|
|
|
|
case 0x64: /* LD IYH,IYH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x64];
|
2011-07-18 19:48:57 +00:00
|
|
|
/* nop */
|
|
|
|
break;
|
|
|
|
case 0x65: /* LD IYH,IYL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x65];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(IY, lreg(IY));
|
|
|
|
break;
|
|
|
|
case 0x66: /* LD H,(IY+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x66];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
Sethreg(HL, GetBYTE(adr));
|
|
|
|
break;
|
|
|
|
case 0x67: /* LD IYH,A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x67];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(IY, hreg(AF));
|
|
|
|
break;
|
|
|
|
case 0x68: /* LD IYL,B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x68];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(IY, hreg(BC));
|
|
|
|
break;
|
|
|
|
case 0x69: /* LD IYL,C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x69];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(IY, lreg(BC));
|
|
|
|
break;
|
|
|
|
case 0x6A: /* LD IYL,D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x6A];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(IY, hreg(DE));
|
|
|
|
break;
|
|
|
|
case 0x6B: /* LD IYL,E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x6B];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(IY, lreg(DE));
|
|
|
|
break;
|
|
|
|
case 0x6C: /* LD IYL,IYH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x6C];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(IY, hreg(IY));
|
|
|
|
break;
|
|
|
|
case 0x6D: /* LD IYL,IYL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x6D];
|
2011-07-18 19:48:57 +00:00
|
|
|
/* nop */
|
|
|
|
break;
|
|
|
|
case 0x6E: /* LD L,(IY+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x6E];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
Setlreg(HL, GetBYTE(adr));
|
|
|
|
break;
|
|
|
|
case 0x6F: /* LD IYL,A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x6F];
|
2011-07-18 19:48:57 +00:00
|
|
|
Setlreg(IY, hreg(AF));
|
|
|
|
break;
|
|
|
|
case 0x70: /* LD (IY+dd),B */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x70];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
PutBYTE(adr, hreg(BC));
|
|
|
|
break;
|
|
|
|
case 0x71: /* LD (IY+dd),C */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x71];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
PutBYTE(adr, lreg(BC));
|
|
|
|
break;
|
|
|
|
case 0x72: /* LD (IY+dd),D */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x72];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
PutBYTE(adr, hreg(DE));
|
|
|
|
break;
|
|
|
|
case 0x73: /* LD (IY+dd),E */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x73];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
PutBYTE(adr, lreg(DE));
|
|
|
|
break;
|
|
|
|
case 0x74: /* LD (IY+dd),H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x74];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
PutBYTE(adr, hreg(HL));
|
|
|
|
break;
|
|
|
|
case 0x75: /* LD (IY+dd),L */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x75];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
PutBYTE(adr, lreg(HL));
|
|
|
|
break;
|
|
|
|
case 0x77: /* LD (IY+dd),A */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x77];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
PutBYTE(adr, hreg(AF));
|
|
|
|
break;
|
|
|
|
case 0x7C: /* LD A,IYH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x7C];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(AF, hreg(IY));
|
|
|
|
break;
|
|
|
|
case 0x7D: /* LD A,IYL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x7D];
|
2011-07-18 19:48:57 +00:00
|
|
|
Sethreg(AF, lreg(IY));
|
|
|
|
break;
|
|
|
|
case 0x7E: /* LD A,(IY+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x7E];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
Sethreg(AF, GetBYTE(adr));
|
|
|
|
break;
|
|
|
|
case 0x84: /* ADD A,IYH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x84];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(IY);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x85: /* ADD A,IYL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x85];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(IY);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x86: /* ADD A,(IY+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x86];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
temp = GetBYTE(adr);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x8C: /* ADC A,IYH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x8C];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(IY);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp + TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x8D: /* ADC A,IYL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x8D];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(IY);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp + TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x8E: /* ADC A,(IY+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x8E];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
temp = GetBYTE(adr);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu + temp + TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x94: /* SUB IYH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x94];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(IY);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x95: /* SUB IYL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x95];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(IY);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x96: /* SUB (IY+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x96];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
temp = GetBYTE(adr);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x9C: /* SBC A,IYH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x9C];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(IY);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp - TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x9D: /* SBC A,IYL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x9D];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(IY);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp - TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0x9E: /* SBC A,(IY+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0x9E];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
temp = GetBYTE(adr);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp - TSTFLAG(C);
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = ((sum & 0xff) << 8) | (sum & 0xa8) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (cbits & 0x10) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0xA4: /* AND IYH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xA4];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF & (IY)) >> 8) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) |
|
|
|
|
((sum == 0) << 6) | 0x10 | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xA5: /* AND IYL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xA5];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF >> 8) & IY) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | 0x10 |
|
|
|
|
((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xA6: /* AND (IY+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xA6];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
sum = ((AF >> 8) & GetBYTE(adr)) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | 0x10 |
|
|
|
|
((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xAC: /* XOR IYH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xAC];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF ^ (IY)) >> 8) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xAD: /* XOR IYL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xAD];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF >> 8) ^ IY) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xAE: /* XOR (IY+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xAE];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
sum = ((AF >> 8) ^ GetBYTE(adr)) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xB4: /* OR IYH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xB4];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF | (IY)) >> 8) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xB5: /* OR IYL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xB5];
|
2011-07-18 19:48:57 +00:00
|
|
|
sum = ((AF >> 8) | IY) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xB6: /* OR (IY+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xB6];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
sum = ((AF >> 8) | GetBYTE(adr)) & 0xff;
|
|
|
|
AF = (sum << 8) | (sum & 0xa8) | ((sum == 0) << 6) | partab[sum];
|
|
|
|
break;
|
|
|
|
case 0xBC: /* CP IYH */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xBC];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = hreg(IY);
|
|
|
|
AF = (AF & ~0x28) | (temp & 0x28);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = (AF & ~0xff) | (sum & 0x80) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (temp & 0x28) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0xBD: /* CP IYL */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xBD];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = lreg(IY);
|
|
|
|
AF = (AF & ~0x28) | (temp & 0x28);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = (AF & ~0xff) | (sum & 0x80) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (temp & 0x28) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0xBE: /* CP (IY+dd) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xBE];
|
2011-07-18 19:48:57 +00:00
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
temp = GetBYTE(adr);
|
|
|
|
AF = (AF & ~0x28) | (temp & 0x28);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = (AF & ~0xff) | (sum & 0x80) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (temp & 0x28) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0xCB: /* CB prefix */
|
|
|
|
adr = IY + (signed char) GetBYTE_pp(pc);
|
|
|
|
adr = adr;
|
2011-07-26 21:47:59 +00:00
|
|
|
op = GetBYTE(pc);
|
|
|
|
cycles -= cycleTables[4][op];
|
|
|
|
switch (op & 7) {
|
2011-07-18 19:48:57 +00:00
|
|
|
case 0: ++pc; acu = hreg(BC); break;
|
|
|
|
case 1: ++pc; acu = lreg(BC); break;
|
|
|
|
case 2: ++pc; acu = hreg(DE); break;
|
|
|
|
case 3: ++pc; acu = lreg(DE); break;
|
|
|
|
case 4: ++pc; acu = hreg(HL); break;
|
|
|
|
case 5: ++pc; acu = lreg(HL); break;
|
|
|
|
case 6: ++pc; acu = GetBYTE(adr); break;
|
|
|
|
case 7: ++pc; acu = hreg(AF); break;
|
|
|
|
}
|
|
|
|
switch (op & 0xc0) {
|
|
|
|
case 0x00: /* shift/rotate */
|
|
|
|
switch (op & 0x38) {
|
|
|
|
case 0x00: /* RLC */
|
|
|
|
temp = (acu << 1) | (acu >> 7);
|
|
|
|
cbits = temp & 1;
|
|
|
|
goto cbshflg3;
|
|
|
|
case 0x08: /* RRC */
|
|
|
|
temp = (acu >> 1) | (acu << 7);
|
|
|
|
cbits = temp & 0x80;
|
|
|
|
goto cbshflg3;
|
|
|
|
case 0x10: /* RL */
|
|
|
|
temp = (acu << 1) | TSTFLAG(C);
|
|
|
|
cbits = acu & 0x80;
|
|
|
|
goto cbshflg3;
|
|
|
|
case 0x18: /* RR */
|
|
|
|
temp = (acu >> 1) | (TSTFLAG(C) << 7);
|
|
|
|
cbits = acu & 1;
|
|
|
|
goto cbshflg3;
|
|
|
|
case 0x20: /* SLA */
|
|
|
|
temp = acu << 1;
|
|
|
|
cbits = acu & 0x80;
|
|
|
|
goto cbshflg3;
|
|
|
|
case 0x28: /* SRA */
|
|
|
|
temp = (acu >> 1) | (acu & 0x80);
|
|
|
|
cbits = acu & 1;
|
|
|
|
goto cbshflg3;
|
|
|
|
case 0x30: /* SLIA */
|
|
|
|
temp = (acu << 1) | 1;
|
|
|
|
cbits = acu & 0x80;
|
|
|
|
goto cbshflg3;
|
|
|
|
case 0x38: /* SRL */
|
|
|
|
temp = acu >> 1;
|
|
|
|
cbits = acu & 1;
|
|
|
|
cbshflg3:
|
|
|
|
AF = (AF & ~0xff) | (temp & 0xa8) |
|
|
|
|
(((temp & 0xff) == 0) << 6) |
|
|
|
|
parity(temp) | !!cbits;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x40: /* BIT */
|
|
|
|
if (acu & (1 << ((op >> 3) & 7)))
|
|
|
|
AF = (AF & ~0xfe) | 0x10 |
|
|
|
|
(((op & 0x38) == 0x38) << 7);
|
|
|
|
else
|
|
|
|
AF = (AF & ~0xfe) | 0x54;
|
|
|
|
if ((op&7) != 6)
|
|
|
|
AF |= (acu & 0x28);
|
|
|
|
temp = acu;
|
|
|
|
break;
|
|
|
|
case 0x80: /* RES */
|
|
|
|
temp = acu & ~(1 << ((op >> 3) & 7));
|
|
|
|
break;
|
|
|
|
case 0xc0: /* SET */
|
|
|
|
temp = acu | (1 << ((op >> 3) & 7));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (op & 7) {
|
|
|
|
case 0: Sethreg(BC, temp); break;
|
|
|
|
case 1: Setlreg(BC, temp); break;
|
|
|
|
case 2: Sethreg(DE, temp); break;
|
|
|
|
case 3: Setlreg(DE, temp); break;
|
|
|
|
case 4: Sethreg(HL, temp); break;
|
|
|
|
case 5: Setlreg(HL, temp); break;
|
|
|
|
case 6: PutBYTE(adr, temp); break;
|
|
|
|
case 7: Sethreg(AF, temp); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0xE1: /* POP IY */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xE1];
|
2011-07-18 19:48:57 +00:00
|
|
|
POP(IY);
|
|
|
|
break;
|
|
|
|
case 0xE3: /* EX (SP),IY */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xE3];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = IY; POP(IY); PUSH(temp);
|
|
|
|
break;
|
|
|
|
case 0xE5: /* PUSH IY */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xE5];
|
2011-07-18 19:48:57 +00:00
|
|
|
PUSH(IY);
|
|
|
|
break;
|
|
|
|
case 0xE9: /* JP (IY) */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xE9];
|
2011-07-18 19:48:57 +00:00
|
|
|
pc = IY;
|
|
|
|
break;
|
|
|
|
case 0xF9: /* LD SP,IY */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[3][0xF9];
|
2011-07-18 19:48:57 +00:00
|
|
|
SP = IY;
|
|
|
|
break;
|
|
|
|
default: pc--; /* ignore DD */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0xFE: /* CP nn */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xFE];
|
2011-07-18 19:48:57 +00:00
|
|
|
temp = GetBYTE_pp(pc);
|
|
|
|
AF = (AF & ~0x28) | (temp & 0x28);
|
|
|
|
acu = hreg(AF);
|
|
|
|
sum = acu - temp;
|
|
|
|
cbits = acu ^ temp ^ sum;
|
|
|
|
AF = (AF & ~0xff) | (sum & 0x80) |
|
|
|
|
(((sum & 0xff) == 0) << 6) | (temp & 0x28) |
|
|
|
|
(((cbits >> 6) ^ (cbits >> 5)) & 4) | 2 |
|
|
|
|
(cbits & 0x10) | ((cbits >> 8) & 1);
|
|
|
|
break;
|
|
|
|
case 0xFF: /* RST 38H */
|
2011-07-26 21:47:59 +00:00
|
|
|
cycles -= cycleTables[0][0xFF];
|
2011-07-18 19:48:57 +00:00
|
|
|
PUSH(pc); pc = 0x38;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-07-26 21:47:59 +00:00
|
|
|
// Interrupts
|
2011-07-18 19:48:57 +00:00
|
|
|
|
|
|
|
if (nmiTrigger) // NMI triggered (higher priority than INT)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* NMI sequence:
|
|
|
|
*
|
|
|
|
* - Push pc on stack
|
|
|
|
* - Set pc to NMI vector (0x0066)
|
|
|
|
* - Copy IFF1 to IFF2 (save interrupt enable status)
|
|
|
|
* - Clear IFF1 (disable interrupts)
|
|
|
|
* - Un-halt CPU (if in HALT state)
|
|
|
|
*/
|
2011-09-18 22:21:14 +00:00
|
|
|
|
|
|
|
#ifdef SUPERMODEL_DEBUGGER
|
|
|
|
if (Debug != NULL)
|
|
|
|
Debug->CPUException(Z80_EX_NMI);
|
|
|
|
#endif // SUPERMODEL_DEBUGGER
|
|
|
|
|
2011-07-18 19:48:57 +00:00
|
|
|
PUSH(pc);
|
|
|
|
pc = 0x0066;
|
|
|
|
iff = (iff&~2) | ((iff&1)<<1);
|
|
|
|
iff &= ~1;
|
2011-09-08 06:34:18 +00:00
|
|
|
nmiTrigger = false; // clear NMI
|
2011-07-18 19:48:57 +00:00
|
|
|
// TODO: if in HALTed state, un-halt
|
|
|
|
}
|
|
|
|
else if (intLine) // INT asserted
|
|
|
|
{
|
|
|
|
// If interrupts are enabled (IFF1 != 0)
|
|
|
|
if ((iff&1))
|
|
|
|
{
|
|
|
|
int v;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* INT sequence:
|
|
|
|
*
|
|
|
|
* - Disable interrupts (clear IFF1 and IFF2)
|
|
|
|
* - Push pc on stack
|
|
|
|
* - Un-halt CPU (if in HALT state)
|
|
|
|
* - Set pc to vector (which depends on mode)
|
|
|
|
*
|
|
|
|
* If no callback is provided when required, nothing happens and
|
|
|
|
* the interrupt line is cleared. Otherwise, callbacks are
|
|
|
|
* responsible for clearing the lines themselves.
|
|
|
|
*/
|
|
|
|
// TODO: if in HALTed state, un-halt
|
|
|
|
switch (im) // interrupt mode (0, 1, or 2 only!)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
/*
|
|
|
|
* Mode 0:
|
|
|
|
*
|
|
|
|
* Fetches up 3 bytes from bus and executes them directly.
|
|
|
|
* Usually, this will just be an RST instruction, so this is
|
|
|
|
* all that we accept here.
|
|
|
|
*/
|
|
|
|
if (NULL != INTCallback)
|
|
|
|
{
|
2011-09-18 22:21:14 +00:00
|
|
|
v = INTCallback(this);
|
|
|
|
|
|
|
|
#ifdef SUPERMODEL_DEBUGGER
|
|
|
|
if (Debug != NULL)
|
|
|
|
Debug->CPUException(v);
|
|
|
|
#endif // SUPERMODEL_DEBUGGER
|
|
|
|
|
2011-07-18 19:48:57 +00:00
|
|
|
switch (v)
|
|
|
|
{
|
|
|
|
case Z80_INT_RST_00: v = 0x0000; break;
|
|
|
|
case Z80_INT_RST_08: v = 0x0008; break;
|
|
|
|
case Z80_INT_RST_10: v = 0x0010; break;
|
|
|
|
case Z80_INT_RST_18: v = 0x0018; break;
|
|
|
|
case Z80_INT_RST_20: v = 0x0020; break;
|
|
|
|
case Z80_INT_RST_28: v = 0x0028; break;
|
|
|
|
case Z80_INT_RST_30: v = 0x0030; break;
|
|
|
|
case Z80_INT_RST_38: v = 0x0038; break;
|
|
|
|
default: v = -1; break; // invalid, do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v >= 0) // valid vector
|
|
|
|
{
|
|
|
|
PUSH(pc);
|
|
|
|
pc = (UINT16) v;
|
|
|
|
iff = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // if no callback, do nothing, clear INT line
|
2011-09-08 06:34:18 +00:00
|
|
|
intLine = false;
|
2011-07-18 19:48:57 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
/*
|
|
|
|
* Mode 1:
|
|
|
|
*
|
|
|
|
* Vector is 0x0038.
|
|
|
|
*/
|
2011-09-18 22:21:14 +00:00
|
|
|
|
|
|
|
#ifdef SUPERMODEL_DEBUGGER
|
|
|
|
if (Debug != NULL)
|
|
|
|
Debug->CPUException(Z80_IM1_IRQ);
|
|
|
|
#endif // SUPERMODEL_DEBUGGER
|
|
|
|
|
2011-07-18 19:48:57 +00:00
|
|
|
PUSH(pc);
|
|
|
|
pc = 0x0038;
|
|
|
|
iff = 0;
|
|
|
|
if (NULL != INTCallback)
|
|
|
|
INTCallback(this);
|
|
|
|
else // no callback, clear INT line automatically
|
2011-09-08 06:34:18 +00:00
|
|
|
intLine = false;
|
2011-07-18 19:48:57 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
/*
|
|
|
|
* Mode 2:
|
|
|
|
*
|
|
|
|
* A 16-bit address is formed by concatenating the I register
|
|
|
|
* and 8 bits read from the bus (with bit 0 cleared). The final
|
|
|
|
* 16-bit vector is read from this address.
|
|
|
|
*/
|
2011-09-18 22:21:14 +00:00
|
|
|
|
|
|
|
#ifdef SUPERMODEL_DEBUGGER
|
|
|
|
if (Debug != NULL)
|
|
|
|
Debug->CPUException(Z80_IM2_VECTOR);
|
|
|
|
#endif // SUPERMODEL_DEBUGGER
|
|
|
|
|
2011-07-18 19:48:57 +00:00
|
|
|
if (NULL != INTCallback)
|
|
|
|
{
|
|
|
|
v = INTCallback(this);
|
|
|
|
v = (ir&0xFF00) | (v&0xFE);
|
|
|
|
PUSH(pc);
|
|
|
|
pc = GetWORD(v);
|
|
|
|
iff = 0;
|
|
|
|
}
|
|
|
|
else // if no callback, do nothing, clear INT line
|
2011-09-08 06:34:18 +00:00
|
|
|
intLine = false;
|
2011-07-18 19:48:57 +00:00
|
|
|
break;
|
|
|
|
default: // should never happen (nothing will be done)
|
2011-09-08 06:34:18 +00:00
|
|
|
intLine = false;
|
2011-07-18 19:48:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-26 21:47:59 +00:00
|
|
|
} // end while
|
2011-09-18 22:21:14 +00:00
|
|
|
|
2011-07-18 19:48:57 +00:00
|
|
|
// write registers back to context
|
2011-09-18 22:21:14 +00:00
|
|
|
HALTExit:
|
|
|
|
#ifdef SUPERMODEL_DEBUGGER
|
|
|
|
if (Debug != NULL)
|
|
|
|
{
|
|
|
|
Debug->CPUInactive();
|
2011-09-18 22:31:42 +00:00
|
|
|
lastCycles -= cycles;
|
2011-09-18 22:21:14 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
// Save local copies of Z80 registers back to context
|
|
|
|
af[af_sel] = AF;
|
|
|
|
regs[regs_sel].bc = BC;
|
|
|
|
regs[regs_sel].de = DE;
|
|
|
|
regs[regs_sel].hl = HL;
|
|
|
|
ix = IX;
|
|
|
|
iy = IY;
|
|
|
|
sp = SP;
|
|
|
|
#endif // SUPERMODEL_DEBUGGER
|
2011-07-26 21:47:59 +00:00
|
|
|
|
|
|
|
// Return number of cycles actually executed
|
|
|
|
return numCycles - cycles;
|
2011-07-18 19:48:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CZ80::TriggerNMI(void)
|
|
|
|
{
|
2011-09-08 06:34:18 +00:00
|
|
|
nmiTrigger = true;
|
2011-07-18 19:48:57 +00:00
|
|
|
}
|
|
|
|
|
2011-09-08 06:34:18 +00:00
|
|
|
void CZ80::SetINT(bool state)
|
2011-07-18 19:48:57 +00:00
|
|
|
{
|
|
|
|
intLine = state;
|
|
|
|
}
|
|
|
|
|
2011-09-07 07:36:08 +00:00
|
|
|
UINT16 CZ80::GetPC(void)
|
|
|
|
{
|
|
|
|
return pc;
|
|
|
|
}
|
|
|
|
|
2011-09-18 22:21:14 +00:00
|
|
|
#ifdef SUPERMODEL_DEBUGGER
|
|
|
|
UINT8 CZ80::GetReg8(unsigned reg8)
|
|
|
|
{
|
|
|
|
switch (reg8)
|
|
|
|
{
|
|
|
|
case Z80_REG8_IFF: return iff;
|
|
|
|
case Z80_REG8_IM: return im;
|
|
|
|
case Z80_REG8_I: return ir>>8;
|
|
|
|
case Z80_REG8_R: return ir&0xFF;
|
|
|
|
case Z80_REG8_A: return af[0]>>8;
|
|
|
|
case Z80_REG8_F: return af[0]&0xFF;
|
|
|
|
case Z80_REG8_B: return regs[0].bc>>8;
|
|
|
|
case Z80_REG8_C: return regs[0].bc&0xFF;
|
|
|
|
case Z80_REG8_D: return regs[0].de>>8;
|
|
|
|
case Z80_REG8_E: return regs[0].de&0xFF;
|
|
|
|
case Z80_REG8_H: return regs[0].hl>>8;
|
|
|
|
case Z80_REG8_L: return regs[0].hl&0xFF;
|
|
|
|
default: return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CZ80::SetReg8(unsigned reg8, UINT8 value)
|
|
|
|
{
|
|
|
|
switch (reg8)
|
|
|
|
{
|
|
|
|
case Z80_REG8_IFF: iff = value; return true;
|
|
|
|
case Z80_REG8_IM: im = value; return true;
|
|
|
|
case Z80_REG8_I: ir |= value<<8; return true;
|
|
|
|
case Z80_REG8_R: ir |= value; return true;
|
|
|
|
case Z80_REG8_A: af[0] |= value<<8; return true;
|
|
|
|
case Z80_REG8_F: af[0] |= value; return true;
|
|
|
|
case Z80_REG8_B: regs[0].bc |= value<<8; return true;
|
|
|
|
case Z80_REG8_C: regs[0].bc |= value; return true;
|
|
|
|
case Z80_REG8_D: regs[0].de |= value<<8; return true;
|
|
|
|
case Z80_REG8_E: regs[0].de |= value; return true;
|
|
|
|
case Z80_REG8_H: regs[0].hl |= value<<8; return true;
|
|
|
|
case Z80_REG8_L: regs[0].hl |= value; return true;
|
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT16 CZ80::GetReg16(unsigned reg16)
|
|
|
|
{
|
|
|
|
switch (reg16)
|
|
|
|
{
|
|
|
|
case Z80_REG16_SP: return sp;
|
|
|
|
case Z80_REG16_PC: return pc;
|
|
|
|
case Z80_REG16_IR: return ir;
|
|
|
|
case Z80_REG16_AF: return af[0];
|
|
|
|
case Z80_REG16_BC: return regs[0].bc;
|
|
|
|
case Z80_REG16_DE: return regs[0].de;
|
|
|
|
case Z80_REG16_HL: return regs[0].hl;
|
|
|
|
case Z80_REG16_IX: return ix;
|
|
|
|
case Z80_REG16_IY: return iy;
|
|
|
|
case Z80_REG16_AF_: return af[1];
|
|
|
|
case Z80_REG16_BC_: return regs[1].bc;
|
|
|
|
case Z80_REG16_DE_: return regs[1].de;
|
|
|
|
case Z80_REG16_HL_: return regs[1].hl;
|
|
|
|
default: return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CZ80::SetReg16(unsigned reg16, UINT16 value)
|
|
|
|
{
|
|
|
|
switch (reg16)
|
|
|
|
{
|
|
|
|
case Z80_REG16_SP: sp = value; return true;
|
|
|
|
case Z80_REG16_PC: pc = value; return true;
|
|
|
|
case Z80_REG16_IR: ir = value; return true;
|
|
|
|
case Z80_REG16_AF: af[0] = value; return true;
|
|
|
|
case Z80_REG16_BC: regs[0].bc = value; return true;
|
|
|
|
case Z80_REG16_DE: regs[0].de = value; return true;
|
|
|
|
case Z80_REG16_HL: regs[0].hl = value; return true;
|
|
|
|
case Z80_REG16_IX: ix = value; return true;
|
|
|
|
case Z80_REG16_IY: iy = value; return true;
|
|
|
|
case Z80_REG16_AF_: af[1] = value; return true;
|
|
|
|
case Z80_REG16_BC_: regs[1].bc = value; return true;
|
|
|
|
case Z80_REG16_DE_: regs[1].de = value; return true;
|
|
|
|
case Z80_REG16_HL_: regs[1].hl = value; return true;
|
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // SUPERMODEL_DEBUGGER
|
|
|
|
|
2011-07-18 19:48:57 +00:00
|
|
|
void CZ80::Reset(void)
|
|
|
|
{
|
|
|
|
pc = 0x0000;
|
|
|
|
sp = 0xF000;
|
|
|
|
af[0] = 0x0000;
|
|
|
|
af[1] = 0x0000;
|
|
|
|
regs[0].bc = 0x0000;
|
|
|
|
regs[0].de = 0x0000;
|
|
|
|
regs[0].hl = 0x0000;
|
|
|
|
regs[1].bc = 0x0000;
|
|
|
|
regs[1].de = 0x0000;
|
|
|
|
regs[1].hl = 0x0000;
|
|
|
|
ix = 0x0000;
|
|
|
|
iy = 0x0000;
|
|
|
|
ir = 0x0000;
|
|
|
|
iff = 0;
|
|
|
|
im = 0;
|
|
|
|
|
|
|
|
af_sel = 0;
|
|
|
|
regs_sel = 0;
|
|
|
|
|
2011-09-08 06:34:18 +00:00
|
|
|
intLine = false;
|
|
|
|
nmiTrigger = false;
|
2011-09-18 22:21:14 +00:00
|
|
|
#ifdef SUPERMODEL_DEBUGGER
|
|
|
|
lastCycles = 0;
|
|
|
|
#endif // SUPERMODEL_DEBUGGER
|
2011-07-18 19:48:57 +00:00
|
|
|
}
|
|
|
|
|
2011-08-09 18:36:29 +00:00
|
|
|
void CZ80::SaveState(CBlockFile *StateFile, const char *name)
|
|
|
|
{
|
|
|
|
StateFile->NewBlock(name, __FILE__);
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
StateFile->Write(®s[i].bc, sizeof(regs[i].bc));
|
|
|
|
StateFile->Write(®s[i].de, sizeof(regs[i].de));
|
|
|
|
StateFile->Write(®s[i].hl, sizeof(regs[i].hl));
|
|
|
|
}
|
|
|
|
|
|
|
|
StateFile->Write(af, sizeof(af));
|
|
|
|
StateFile->Write(&ir, sizeof(ir));
|
|
|
|
StateFile->Write(&ix, sizeof(ix));
|
|
|
|
StateFile->Write(&iy, sizeof(iy));
|
|
|
|
StateFile->Write(&sp, sizeof(sp));
|
|
|
|
StateFile->Write(&pc, sizeof(pc));
|
|
|
|
StateFile->Write(&iff, sizeof(iff));
|
|
|
|
StateFile->Write(&im, sizeof(im));
|
|
|
|
StateFile->Write(®s_sel, sizeof(regs_sel));
|
|
|
|
StateFile->Write(&af_sel, sizeof(af_sel));
|
|
|
|
StateFile->Write(&nmiTrigger, sizeof(nmiTrigger));
|
|
|
|
StateFile->Write(&intLine, sizeof(intLine));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CZ80::LoadState(CBlockFile *StateFile, const char *name)
|
|
|
|
{
|
|
|
|
if (OKAY != StateFile->FindBlock(name))
|
|
|
|
{
|
2011-09-22 06:11:47 +00:00
|
|
|
ErrorLog("Unable to load Z80 state. Save state file is corrupt.");
|
2011-08-09 18:36:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
StateFile->Read(®s[i].bc, sizeof(regs[i].bc));
|
|
|
|
StateFile->Read(®s[i].de, sizeof(regs[i].de));
|
|
|
|
StateFile->Read(®s[i].hl, sizeof(regs[i].hl));
|
|
|
|
}
|
|
|
|
|
|
|
|
StateFile->Read(af, sizeof(af));
|
|
|
|
StateFile->Read(&ir, sizeof(ir));
|
|
|
|
StateFile->Read(&ix, sizeof(ix));
|
|
|
|
StateFile->Read(&iy, sizeof(iy));
|
|
|
|
StateFile->Read(&sp, sizeof(sp));
|
|
|
|
StateFile->Read(&pc, sizeof(pc));
|
|
|
|
StateFile->Read(&iff, sizeof(iff));
|
|
|
|
StateFile->Read(&im, sizeof(im));
|
|
|
|
StateFile->Read(®s_sel, sizeof(regs_sel));
|
|
|
|
StateFile->Read(&af_sel, sizeof(af_sel));
|
|
|
|
StateFile->Read(&nmiTrigger, sizeof(nmiTrigger));
|
|
|
|
StateFile->Read(&intLine, sizeof(intLine));
|
|
|
|
}
|
|
|
|
|
2011-07-18 19:48:57 +00:00
|
|
|
void CZ80::Init(CBus *BusPtr, int (*INTF)(CZ80 *Z80))
|
|
|
|
{
|
|
|
|
Bus = BusPtr;
|
|
|
|
INTCallback = INTF;
|
|
|
|
}
|
|
|
|
|
2011-09-18 22:21:14 +00:00
|
|
|
#ifdef SUPERMODEL_DEBUGGER
|
|
|
|
void CZ80::AttachDebugger(Debugger::CZ80Debug *DebugPtr)
|
|
|
|
{
|
|
|
|
if (Debug != NULL)
|
|
|
|
DetachDebugger();
|
|
|
|
Debug = DebugPtr;
|
|
|
|
Bus = Debug->AttachBus(Bus);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CZ80::DetachDebugger()
|
|
|
|
{
|
|
|
|
if (Debug == NULL)
|
|
|
|
return;
|
|
|
|
Bus = Debug->DetachBus();
|
|
|
|
Debug = NULL;
|
|
|
|
}
|
|
|
|
#endif //SUPERMODEL_DEBUGGER
|
|
|
|
|
2011-07-18 19:48:57 +00:00
|
|
|
CZ80::CZ80(void)
|
|
|
|
{
|
|
|
|
INTCallback = NULL; // so we can later check to see if one has been installed
|
|
|
|
Bus = NULL;
|
2011-09-18 22:21:14 +00:00
|
|
|
#ifdef SUPERMODEL_DEBUGGER
|
|
|
|
Debug = NULL;
|
|
|
|
#endif //SUPERMODEL_DEBUGGER
|
2011-07-18 19:48:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CZ80::~CZ80(void)
|
|
|
|
{
|
|
|
|
INTCallback = NULL;
|
|
|
|
Bus = NULL;
|
2011-09-18 22:21:14 +00:00
|
|
|
#ifdef SUPERMODEL_DEBUGGER
|
|
|
|
Debug = NULL;
|
|
|
|
#endif //SUPERMODEL_DEBUGGER
|
|
|
|
}
|