#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>

#include "general.h"
#include "Externals.h"

#pragma -s1

#ifdef PORT16
#define V_AD_PORT (Reg_B<<8)+Reg_C
#define M_AD_PRT2(v) (Reg_A<<8)+(v)
#else
#define V_AD_PORT Reg_C
#define M_AD_PRT2(v) (v)
#endif

void UndefinedInstruction()
{
printf("instruction non definie! on reboot! %x\nInst %x\n",Reg_PC,inst);
puts("Instruction non definie! on reboot!");
Reg_PC= 0;
}

#define ui0 UndefinedInstruction

void UndefinedInstruction1(u_char vx)
{
UndefinedInstruction();
}
#define ui10 UndefinedInstruction1

void UndefinedInstruction2(u_int ad)
{
UndefinedInstruction();
}
#define ui20 UndefinedInstruction2

#define LECMEM(ad) (EmuRead[(ad)>>8] ? (*EmuRead[(ad)>>8])(ad) : Lire_Code(ad)) 

#define ECRMEM(ad,rx) if(EmuWrite[(ad)>>8]) \
	if(!(*EmuWrite[(ad)>>8])(ad, rx)) ;\
if((ad)>= 12288) TRSCode->bytes[ad]= rx

#define POSSZ(rx) \
if(!(rx))\
	Reg_F|= BITZ;\
else	Reg_F&= ~BITZ;\
if(rx & 128)\
	Reg_F|= BITS;\
else	Reg_F&= ~BITS;

#define POSP(rx) \
if(parite[rx])\
	Reg_F|= BITP;\
else	Reg_F&= ~BITP;

#define REL(ox) Reg_PC+(ox)-((ox)>127 ? 256 : 0)

extern BOOL (*EmuWrite[SIZE_CODE>>8])(u_int ax, u_char vx);
extern u_char (*EmuRead[SIZE_CODE>>8])(u_int ax);  

/* Tableau donnant la parite d'un nombre entre 0 et 255
   1 si pair et 0 si impair */
char parite[256] =
	{
	1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
	0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
	0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
	1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
	0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
	1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
	1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
	0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
	0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
	1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
	1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
	0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
	1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,
	0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
	0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,
	1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1
	};

/* Fonctions de gestion de la pile Z80 */
void StoPil(Rx)
u_char Rx;
{
Reg_SP--; Reg_SP &= 0xffff;
ECRMEM(Reg_SP, Rx);
}

u_char ResPil()
{
u_char rx= Lire_Code(Reg_SP);
Reg_SP++; Reg_SP &= 0xffff;
return(rx);
}

u_char mode_inter= 0;

#ifndef FALSE
#define FALSE 0
#endif
void Traite_interrupt(void)
{
#ifdef NMI
if(Reg_NMI)
	{
	Reg_IFF2= Reg_IFF;
	Reg_NMI= Reg_IFF= FALSE;
	StoPil((u_char) (Reg_PC>>8));
	StoPil((u_char) (Reg_PC & 0xff));
	Reg_PC= 0x0066;
	}
#if defined(IM0) || defined(IM1) || defined(IM2)
else	{
#endif
#endif
#if defined(IM0) || defined(IM1) || defined(IM2)
switch(mode_inter)
	{
#ifdef IM0
	case 0:
		break;
#endif
#ifdef IM1
	case 1:
		StoPil((u_char) (Reg_PC>>8));
		StoPil((u_char) (Reg_PC & 0xff));
		Reg_PC= 0x0038; 
		break;
#endif
#ifdef IM2
	case 2:
		break;
#endif
	}
Reg_INT= FALSE;
#ifdef NMI
	}
#endif
#endif
Reg_INT= (u_char) FALSE;
}

static void OpNOP()
{
}

/* Fonctions relatives aux differents codes op */
static void OpLDrr()
{
Glob.r[(inst & 0x3f)>>3]= Glob.r[inst & 7];
}

static void OpLDrn()
{
Glob.r[(inst & 0x3f)>>3]= LRPC;
NEXTPC;
}

static void OpLDrM()
{
u_int ad1= (Reg_H<<8)+Reg_L;
Glob.r[(inst & 0x3f)>>3]= LECMEM(ad1);
}

static void OpLDMr()
{
u_int ad1= (Reg_H<<8)+Reg_L;
ECRMEM(ad1, Glob.r[inst & 7]);
}

static void OpLDMn()
{
u_char vx= LRPC;
u_int ad1= (Reg_H<<8)+Reg_L;
ECRMEM(ad1, vx);
NEXTPC;
}

static void OpLDiBC()
{
u_int ad1 = (Reg_B<<8)+Reg_C;
Reg_A= LECMEM(ad1);
}

static void OpLDiDE()
{
u_int ad1 = (Reg_D<<8)+Reg_E;
Reg_A= LECMEM(ad1);
}

static void OpLDinn()
{
u_int ad1= LRPC;
NEXTPC;
ad1+= (LRPC)<<8;
NEXTPC;
Reg_A= LECMEM(ad1);
}

static void OpLDBCi()
{
u_int ad1= (Reg_B<<8)+Reg_C;
ECRMEM(ad1, Reg_A);
}

static void OpLDDEi()
{
u_int ad1= (Reg_D<<8)+Reg_E;
ECRMEM(ad1, Reg_A);
}

static void OpLDnni()
{
u_int ad1= LRPC;
NEXTPC;
ad1+= (LRPC)<<8;
NEXTPC;
ECRMEM(ad1, Reg_A);
}

static void OpLDssnn()
{
u_int ix= inst>>3;
Glob.r[ix+1]= LRPC;
NEXTPC;
Glob.r[ix]= LRPC;
NEXTPC;
}

static void OpLDSPnn()
{
Reg_SP= LRPC;
NEXTPC;
Reg_SP|= (LRPC)<<8;
NEXTPC;
}

static void OpLDinnHL()
{
u_int ad1= LRPC;
NEXTPC;
ad1+= (LRPC)<<8;
NEXTPC;
ECRMEM(ad1, Reg_L);
ad1= (ad1 + 1) & 0xffff;
ECRMEM(ad1, Reg_H);
}

static void OpLDHLinn()
{
u_int ad1= LRPC;
NEXTPC;
ad1+= (LRPC)<<8;
NEXTPC;
Reg_L= LECMEM(ad1);
Reg_H= LECMEM((ad1+1) & 0xffff);
}

static void OpLDSPHL()
{
Reg_SP= (Reg_H<<8)+Reg_L;
}

static void OpPUSHss()
{
u_int ix= (inst & 0x3f)>>3;
StoPil(Glob.r[ix]);
StoPil(Glob.r[ix+1]);
}

static void OpPUSHAF()
{
StoPil(Reg_A);
StoPil(Reg_F);
}

static void OpPOPss()
{
u_int ix= (inst & 0x3f)>>3;
Glob.r[ix+1]= ResPil();
Glob.r[ix]= ResPil();
}

static void OpPOPAF()
{
Reg_F= ResPil();
Reg_A= ResPil();
}

static void OpDAA()
{
BOOL bgv1= (Reg_F & BITH) || ((Reg_A & 0x0f) > 9);
BOOL bgv2= (Reg_F & BITC) || (Reg_A > 0x9f);
if(Reg_F & BITN)
	{
	/* La derniere operation etait une addition */
	if(bgv1)
		{
		Reg_A+= 6;
		Reg_F|= BITH;
		}
	else	Reg_F&= ~BITH;
	if(bgv2)
		{
		Reg_A+= 0x60;
		Reg_F|= BITC;
		}
	else	Reg_F&= ~BITC;
	}
else	{
	/* La derniere operation etait une soustraction */
	if(bgv1)
		{
		Reg_A-= 6;
		Reg_F|= BITH;
		}
	else	Reg_F&= ~BITH;
	if(bgv2)
		{
		Reg_A-= 0x60;
		Reg_F|= BITC;
		}
	else	Reg_F&= ~BITC;
	}
POSSZ(Reg_A);
POSP(Reg_A);
}

static void OpCPL()
{
Reg_A^= 0xff;
Reg_F |= (BITH | BITN);
}

static void OpCCF()
{
Reg_F ^= BITC;
Reg_F &= ~BITN;
}

static void OpSCF()
{
Reg_F |= BITC;
Reg_F &= ~(BITN | BITH);
}

static void OpRLCA()
{
BOOL bgv2= (Reg_A & 128)!= 0;
if(bgv2)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
Reg_A<<= 1;
if(bgv2) Reg_A|= 1;
Reg_F&= ~(BITN | BITH);
}

static void OpRLA()
{
BOOL bgv2= (Reg_A & 128)!= 0;
Reg_A<<= 1;
if(Reg_F & BITC)
	Reg_A|= 1;
if(bgv2)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
Reg_F&= ~(BITN | BITH);
}

static void OpRRCA()
{
BOOL bgv2= (Reg_A & 1)!= 0;
Reg_A>>= 1;
if(bgv2)
	{
	Reg_A|= 128;
	Reg_F|= BITC;
	}
else	Reg_F&= ~BITC;
Reg_F&= ~(BITN | BITH);
}

static void OpRRA()
{
BOOL bgv2= (Reg_A & 1)!= 0;
Reg_A>>= 1;
if(Reg_F & BITC)
	Reg_A|= 128;
if(bgv2)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
Reg_F&= ~(BITN | BITH);
}

static void OpADDHLss()
{
u_char ix= inst>>3;
u_int vHL= (Reg_H<<8)+Reg_L + (Glob.r[ix-1]<<8)+Glob.r[ix];
if(vHL & 0x10000)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
Reg_L= vHL & 0xff;
Reg_H= (vHL>>8) & 0xff;
Reg_F&= ~BITN;
}

static void OpADDHLSP()
{
u_int vHL= (Reg_H<<8)+Reg_L+ Reg_SP;
if(vHL & 0x10000)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
Reg_L= vHL & 0xff;
Reg_H= (vHL>>8) & 0xff;
Reg_F&= ~BITN;
}

static void OpINCss()
{
u_int ix= inst>>3;
if(!++Glob.r[ix+1]) Glob.r[ix]++;
}

static void OpINCSP()
{
Reg_SP++; Reg_SP&= 0xffff;
}

static void OpDECss()
{
u_int ix= inst>>3;
if(!Glob.r[ix]--) Glob.r[ix-1]--;
}

static void OpDECSP()
{
Reg_SP--; Reg_SP&= 0xffff;
}

static void OpEXAF()
{
u_char tampon;
tampon= Reg_A2;
Reg_A2= Reg_A;
Reg_A= tampon;
tampon= Reg_F2;
Reg_F2= Reg_F;
Reg_F= tampon;
}

static void OpEXX(void)
{
u_char tampon;
tampon= Reg_B; Reg_B= Reg_B2; Reg_B2= tampon;
tampon= Reg_C; Reg_B= Reg_C2; Reg_C2= tampon;
tampon= Reg_D; Reg_D= Reg_D2; Reg_D2= tampon;
tampon= Reg_E; Reg_E= Reg_E2; Reg_E2= tampon;
tampon= Reg_H; Reg_H= Reg_H2; Reg_H2= tampon;
tampon= Reg_L; Reg_L= Reg_L2; Reg_L2= tampon;
}

static void OpEXDEHL()
{
u_char tampon;
tampon= Reg_L;
Reg_L= Reg_E;
Reg_E= tampon;
tampon= Reg_H;
Reg_H= Reg_D;
Reg_D= tampon;
}  

static void OpEXSPHL()
{
u_int ad1;
u_char tampon;
ad1= Reg_SP;
tampon= LECMEM(ad1);
ECRMEM(ad1,Reg_L);
Reg_L= tampon;
ad1++; ad1&= 0xffff;
tampon= LECMEM(ad1);
ECRMEM(ad1,Reg_H);
Reg_H= tampon;
}

static void OpANDr()
{
Reg_A&= Glob.r[inst & 7];
Reg_F|= BITH;
POSSZ(Reg_A);
POSP(Reg_A);
Reg_F&= ~BITC;
}

static void OpANDn()
{
Glob.r[inst=6]= LRPC;
NEXTPC;
OpANDr();
}

static void OpANDM()
{
u_int ad1= (Reg_H<<8)+Reg_L;
Reg_A&= LECMEM(ad1);
Reg_F|= BITH;
POSSZ(Reg_A);
POSP(Reg_A);
Reg_F&= ~BITC;
}

static void OpORr()
{
Reg_A|= Glob.r[inst & 7];
POSSZ(Reg_A);
POSP(Reg_A);
Reg_F&= ~(BITC | BITH);
}

static void OpORn()
{
Glob.r[inst=6]= LRPC;
NEXTPC;
OpORr();
}

static void OpORM()
{
u_int ad1= (Reg_H<<8)+Reg_L;
Reg_A|= LECMEM(ad1);
POSSZ(Reg_A);
POSP(Reg_A);
Reg_F&= ~(BITC | BITH);
}

static void OpXORr()
{
Reg_A^= Glob.r[inst & 7];
POSSZ(Reg_A);
POSP(Reg_A);
Reg_F&= ~(BITC | BITH);
}

static void OpXORn()
{
Glob.r[inst=6]= LRPC;
NEXTPC;
OpXORr();
}


static void OpXORM()
{
u_int ad1= (Reg_H<<8)+Reg_L;
Reg_A^= LECMEM(ad1);
POSSZ(Reg_A);
POSP(Reg_A);
Reg_F&= ~(BITC | BITH);
}

static void OpADDr()
{
void OpADCr(void);
Reg_F&= ~BITC;
OpADCr();
}

static void OpADDn()
{
void OpADCr(void);
Reg_F&= ~BITC;
Glob.r[inst=6]= LRPC;
NEXTPC;
OpADCr();
}

static void OpADDM()
{
void OpADCM(void);
Reg_F&= ~BITC;
OpADCM();
}

static void OpADCr()
{
u_char Reg_xA, Reg_yA, v12, v13;
unsigned int v11;
BOOL bgv2;
v12=(u_char) (v11=Glob.r[inst & 7]) & 0x7f;
v13=(u_char) (v13 & 0x0f);
Reg_xA=Reg_A & 0x7f; Reg_yA= Reg_A & 0x0f;
if (Reg_F & BITC) { v11++; v12++; v13++;}
bgv2=((int) (Reg_A+v11)>0xff); Reg_A+=v11;
if(bgv2)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
if (bgv2 ^ ((unsigned int) Reg_xA + v12 > 0x7f))
	Reg_F |= BITV;
else	Reg_F &= ~BITV;
if((Reg_yA + v13) > 0x0f)
	Reg_F|= BITH;
else	Reg_F&= ~BITH; 
Reg_F&= ~BITN;
POSSZ(Reg_A);
}

static void OpADCn()
{
Glob.r[inst= 6]= LRPC;
NEXTPC;
OpADCr();
}

static void OpADCM()
{
u_int ad1= (Reg_H<<8)+Reg_L;
u_char Reg_xA, Reg_yA, v12, v13;
unsigned int v11;
BOOL bgv2;
v12=(u_char) (v11=LECMEM(ad1)) & 0x7f;
v13=(u_char) (v11 & 0x0f);
Reg_xA=Reg_A & 0x7f; Reg_yA= Reg_A & 0x0f;
if (Reg_F & BITC) { v11++; v12++; v13++;}
bgv2=((int) (Reg_A+v11)>0xff); Reg_A+=v11;
if(bgv2)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
if (bgv2 ^ ((unsigned int) Reg_xA + v12 > 0x7f))
	Reg_F |= BITV;
else	Reg_F &= ~BITV;
if((Reg_yA + v13) > 0x0f)
	Reg_F|= BITH;
else	Reg_F&= ~BITH;
Reg_F&= ~BITN;
POSSZ(Reg_A); 
}

void OpSUBr()
{
void OpSBCr(void);
Reg_F&= ~BITC;
OpSBCr();
}

void OpSUBn()
{
void OpSBCr(void);
Glob.r[inst=6]= LRPC;
NEXTPC;
Reg_F&= ~BITC;
OpSBCr();
}

void OpSUBM()
{
void OpSBCM(void);
Reg_F&= ~BITC;
OpSBCM();
}

void OpSBCr()
{
u_char Reg_xA, Reg_yA, v12, v13;
unsigned int v11;
BOOL bgv2;
v12=(v11=(Glob.r[inst & 7] ^ 0xff)) & 0x7f; v13= v11 & 0x0f;
Reg_xA=Reg_A & 0x7f; Reg_yA= Reg_A & 0x0f;
if(!(Reg_F & BITC)) { v11++; v12++; v13++; }
bgv2=((int) (Reg_A+v11)>0xff); Reg_A+=v11;
if(bgv2)
	Reg_F&= ~BITC;
else	Reg_F|= BITC;
if (bgv2 ^ ((unsigned int) Reg_xA + v12 > 0x7f))
	Reg_F|= BITV;
else	Reg_F &= ~BITV;
if((Reg_yA + v13) > 0x0f)
	Reg_F|= BITH;
else	Reg_F&= ~BITH;
POSSZ(Reg_A);
Reg_F|= BITN;
}

void OpSBCn()
{
Glob.r[inst=6]= LRPC;
NEXTPC;
OpSBCr();
}

static void OpSBCM()
{
u_int ad1= (Reg_H<<8)+Reg_L;
u_char Reg_xA, Reg_yA, v12, v13;
unsigned int v11;
BOOL bgv2;
v12=(v11=(LECMEM(ad1) ^ 0xff)) & 0x7f; v13= v11 & 0x0f; 
Reg_xA=Reg_A & 0x7f; Reg_yA= Reg_A & 0x0f;
if(!(Reg_F & BITC)) { v11++; v12++; v13++; }
bgv2=((int) (Reg_A+v11)>0xff); Reg_A+=v11;
if(bgv2)
	Reg_F&= ~BITC;
else	Reg_F|= BITC;
if (bgv2 ^ ((unsigned int) Reg_xA + v12 > 0x7f))
	Reg_F |= BITV;
else	Reg_F &= ~BITV;
if((Reg_yA + v13) > 0x0f)
	Reg_F|= BITH;
else	Reg_F&= ~BITH;
POSSZ(Reg_A);
Reg_F|= BITN;
}

static void OpCPr()
{
u_char Asav= Reg_A;
Reg_F&= ~BITC;
OpSBCr();
Reg_A= Asav;
}

static void OpCPn()
{
u_char Asav= Reg_A;
Glob.r[inst=6]= LRPC;
NEXTPC;
Reg_F&= ~BITC;
OpSBCr();
Reg_A= Asav;
}

static void OpCPM()
{
u_char Asav= Reg_A;
Reg_F&= ~BITC;
OpSBCM();
Reg_A= Asav;
}

static void OpINCr()
{
u_char futurevalue= ++Glob.r[inst>>3] & 0xff;
Reg_F&= ~BITN;
if(!futurevalue)
	Reg_F|= BITZ;
else	Reg_F&= ~BITZ;
if(futurevalue== 0x80)
	Reg_F|= BITV;
else	Reg_F&= ~BITV;
if(!(futurevalue & 0x0f))
	Reg_F|= BITH;
else	Reg_F&= ~BITH;
if(futurevalue & 0x80)
	Reg_F|= BITS;
else	Reg_F&= ~BITS;
}

static void OpINCM()
{
u_int ad1= (Reg_H<<8) + Reg_L;
u_char futurevalue= (LECMEM(ad1) + 1) & 0xff;
ECRMEM(ad1, futurevalue);
Reg_F&= ~BITN;
if(!futurevalue)
	Reg_F|= BITZ;
else	Reg_F&= ~BITZ;
if(futurevalue== 0x80)
	Reg_F|= BITV;
else	Reg_F&= ~BITV;
if(!(futurevalue & 0x0f))
	Reg_F|= BITH;
else	Reg_F&= ~BITH;
if(futurevalue & 0x80)
	Reg_F|= BITS;
else	Reg_F&= ~BITS;
}

static void OpDECr()
{
u_char futurevalue= --Glob.r[inst>>3] & 0xff;
Reg_F|= BITN;
if((futurevalue & 0x0f) == 0x0f)
	Reg_F|= BITH;
else	Reg_F&= ~BITH;
if(futurevalue== 0x7f)
	Reg_F|= BITV;
else	Reg_F&= ~BITV;
POSSZ(futurevalue);
}

static void OpDECM()
{
u_int ad1= (Reg_H<<8) + Reg_L;
u_char futurevalue= (LECMEM(ad1) - 1) & 0xff;
ECRMEM(ad1, futurevalue);
Reg_F|= BITN;
if((futurevalue & 0x0f) == 0x0f)
	Reg_F|= BITH;
else	Reg_F&= ~BITH;
if(futurevalue== 0x7f)
	Reg_F|= BITV;
else	Reg_F&= ~BITV;
POSSZ(futurevalue);
}

static u_char cond_y[4] =
	{
	BITZ, BITC, BITP, BITS
	};

static void OpJP()
{
u_int ad1= LRPC;
NEXTPC;
Reg_PC= (LRPC<<8)+ad1;
}

static void OpJPyc()
{
u_int ad1= LRPC;
NEXTPC;
ad1+= LRPC<<8;
if(Reg_F & cond_y[(inst>>4) & 3])
	Reg_PC= ad1;
else	{
		NEXTPC;
		}
}

static void OpJPnc()
{
u_int ad1= LRPC;
NEXTPC;
ad1+= LRPC<<8;
if(!(Reg_F & cond_y[(inst>>4) & 3]))
	Reg_PC= ad1;
else	{
		NEXTPC;
		}
}

static void OpJPHL()
{
Reg_PC= (Reg_H<<8)+Reg_L;
}

static void OpJR()
{
u_char ox= LRPC;
NEXTPC;
Reg_PC= REL(ox) & 0xffff;
}

static void OpJRNC()
{
u_char ox= LRPC;
NEXTPC;
if(!(Reg_F & BITC))
	Reg_PC= REL(ox) & 0xffff;
}

static void OpJRC()
{
u_char ox= LRPC;
NEXTPC;
if(Reg_F & BITC)
	Reg_PC= REL(ox) & 0xffff;
}

static void OpJRNZ()
{
u_char ox= LRPC;
NEXTPC;
if(!(Reg_F & BITZ))
	Reg_PC= REL(ox) & 0xffff;
}

static void OpJRZ()
{
u_char ox= LRPC;
NEXTPC;
if(Reg_F & BITZ)
	Reg_PC= REL(ox) & 0xffff;
}

static void OpDJNZ()
{
u_char ox= LRPC;
NEXTPC;
if(--Reg_B!= 0)  
	Reg_PC= REL(ox) & 0xffff;
}

static void OpCALL()
{
u_int ad1= LRPC;
NEXTPC;
ad1+= (LRPC)<<8;
NEXTPC;
StoPil((u_char) (Reg_PC>>8));
StoPil((u_char) (Reg_PC & 0xff));
Reg_PC= ad1;
}

static void OpCALLyc()
{
u_int ad1= LRPC;
NEXTPC;
ad1+= (LRPC)<<8;
NEXTPC;
if(Reg_F & cond_y[(inst>>4) & 3])
	{
	StoPil((u_char) (Reg_PC>>8));
	StoPil((u_char) (Reg_PC & 0xff));
	Reg_PC= ad1;
	}
}

static void OpCALLnc()
{
u_int ad1= LRPC;
NEXTPC;
ad1+= (LRPC)<<8;
NEXTPC;
if(!(Reg_F & cond_y[(inst>>4) & 3]))
	{
	StoPil((u_char) (Reg_PC>>8));
	StoPil((u_char) (Reg_PC & 0xff));
	Reg_PC= ad1;
	}
}
 
static void OpRET()
{
Reg_PC= ResPil();
Reg_PC+= (ResPil())<<8;
}

static void OpRETyc()
{
if(Reg_F & cond_y[(inst>>4) & 3])
	OpRET();
}

static void OpRETnc()
{
if(!(Reg_F & cond_y[(inst>>4) & 3]))
	OpRET();
}

static void OpRSTp()
{
StoPil((u_char) (Reg_PC>>8));
StoPil((u_char) (Reg_PC & 0xff));
Reg_PC= inst & 0x38;
}

void (*ModeOpCB[256])(u_char inst);
static void OpHexCB()
{
inst= LRPC; NEXTPC;
(*ModeOpCB[inst])(inst & 0x3f);
}

void (*ModeOpDD[256])(void);
static void OpHexDD()
{
inst= LRPC; NEXTPC;
(*ModeOpDD[inst])();
}

void (*ModeOpED[256])(void);
static void OpHexED()
{
inst= LRPC; NEXTPC;
(*ModeOpED[inst])();
}

void (*ModeOpFD[256])(void);
static void OpHexFD()
{
inst= LRPC; NEXTPC;
(*ModeOpFD[inst])();
}

static void OpIN()
{
extern u_char EmuReadPort(T_NO_PORT port);
u_char v= LRPC;
NEXTPC;
Reg_A= EmuReadPort(M_AD_PRT2(v));
}
 
static void OpOUT()
{
extern void EmuWritePort(T_NO_PORT port, u_char vx);
u_char v= LRPC;
NEXTPC;
EmuWritePort(M_AD_PRT2(v),Reg_A);
}

#ifndef FALSE
#define FALSE 0
#endif
static void OpDI(void)
{
#ifdef NMI
Reg_IFF2= Reg_IFF= FALSE;
#else
extern jmp_buf reprisepoint;
Reg_IFF= FALSE;
longjmp(reprisepoint, FROMDI);
#endif
}

#ifndef TRUE
#define TRUE 1
#endif
static void OpEI(void)
{
#ifdef NMI
Reg_IFF2= Reg_IFF= TRUE;
#else
extern jmp_buf reprisepoint;
Reg_IFF= TRUE;
longjmp(reprisepoint, FROMEI);
#endif
}

static void OpHALT(void)
{
while(!Reg_INT);
}

void (*ModOp[256])(void)=
	{
	OpNOP,OpLDssnn,OpLDBCi,OpINCss,OpINCr,OpDECr,OpLDrn,OpRLCA,OpEXAF,OpADDHLss,OpLDiBC,OpDECss,OpINCr,OpDECr,OpLDrn, OpRRCA,
	OpDJNZ,OpLDssnn,OpLDDEi,OpINCss,OpINCr,OpDECr,OpLDrn,OpRLA,OpJR,OpADDHLss,OpLDiDE,OpDECss,OpINCr,OpDECr,OpLDrn,OpRRA,
	OpJRNZ,OpLDssnn,OpLDinnHL,OpINCss,OpINCr,OpDECr,OpLDrn,OpDAA,OpJRZ,OpADDHLss,OpLDHLinn,OpDECss,OpINCr,OpDECr,OpLDrn, OpCPL,
	OpJRNC,OpLDSPnn,OpLDnni,OpINCSP,OpINCM,OpDECM,OpLDMn,OpSCF,OpJRC,OpADDHLSP,OpLDinn,OpDECSP,OpINCr,OpDECr,OpLDrn,OpCCF,
	/* LD B,r|(HL) */
	OpLDrr,OpLDrr,OpLDrr,OpLDrr,OpLDrr,OpLDrr,OpLDrM,OpLDrr,
	/* LD C,r|(HL) */
	OpLDrr,OpLDrr,OpLDrr,OpLDrr,OpLDrr,OpLDrr,OpLDrM,OpLDrr,
	/* LD D,r|(HL) */
	OpLDrr,OpLDrr,OpLDrr,OpLDrr,OpLDrr,OpLDrr,OpLDrM,OpLDrr,
	/* LD E,r|(HL) */
	OpLDrr,OpLDrr,OpLDrr,OpLDrr,OpLDrr,OpLDrr,OpLDrM,OpLDrr,
	/* LD H,r|(HL) */
	OpLDrr,OpLDrr,OpLDrr,OpLDrr,OpLDrr,OpLDrr,OpLDrM,OpLDrr,
	/* LD L,r|(HL) */
	OpLDrr,OpLDrr,OpLDrr,OpLDrr,OpLDrr,OpLDrr,OpLDrM,OpLDrr,
	/* LD (HL),r + HALT */
	OpLDMr,OpLDMr,OpLDMr,OpLDMr,OpLDMr,OpLDMr,OpHALT,OpLDMr,
	/* LD A,r|(HL) */
	OpLDrr,OpLDrr,OpLDrr,OpLDrr,OpLDrr,OpLDrr,OpLDrM,OpLDrr,
	OpADDr,OpADDr,OpADDr,OpADDr,OpADDr,OpADDr,OpADDM,OpADDr,OpADCr,OpADCr,OpADCr,OpADCr,OpADCr,OpADCr,OpADCM,OpADCr,
	OpSUBr,OpSUBr,OpSUBr,OpSUBr,OpSUBr,OpSUBr,OpSUBM,OpSUBr,OpSBCr,OpSBCr,OpSBCr,OpSBCr,OpSBCr,OpSBCr,OpSBCM,OpSBCr,
	OpANDr,OpANDr,OpANDr,OpANDr,OpANDr,OpANDr,OpANDM,OpANDr,OpXORr,OpXORr,OpXORr,OpXORr,OpXORr,OpXORr,OpXORM,OpXORr,
	OpORr,OpORr,OpORr,OpORr,OpORr,OpORr,OpORM,OpORr,OpCPr,OpCPr,OpCPr,OpCPr,OpCPr,OpCPr,OpCPM,OpCPr,
	OpRETnc,OpPOPss,OpJPnc,OpJP,OpCALLnc,OpPUSHss,OpADDn,OpRSTp,OpRETyc,OpRET,OpJPyc,OpHexCB,OpCALLyc,OpCALL,OpADCn,OpRSTp,
	OpRETnc,OpPOPss,OpJPnc,OpOUT,OpCALLnc,OpPUSHss,OpSUBn,OpRSTp,OpRETyc,OpEXX,OpJPyc,OpIN,OpCALLyc,OpHexDD,OpSBCn,OpRSTp,
	OpRETnc,OpPOPss,OpJPnc,OpEXSPHL,OpCALLnc,OpPUSHss,OpANDn,OpRSTp,OpRETyc,OpJPHL,OpJPyc,OpEXDEHL,OpCALLyc,OpHexED,OpXORn,OpRSTp,
	OpRETnc,OpPOPAF,OpJPnc,OpDI,OpCALLnc,OpPUSHAF,OpORn,OpRSTp,OpRETyc,OpLDSPHL,OpJPyc,OpEI,OpCALLyc,OpHexFD,OpCPn,OpRSTp
	};

static void OpRLCr(u_char inst)
{
u_char bgv1= Glob.r[inst & 7]; 
BOOL bgv2= (bgv1 & 128)!= 0;
if(bgv2)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
bgv1<<= 1;
if(bgv2) bgv1|= 1;
Reg_F&= ~(BITN | BITH);
POSSZ(bgv1);
POSP(bgv1);
Glob.r[inst & 7]= bgv1;
}

static void GenRLCm(u_int ad)
{
u_char bgv1= LECMEM(ad); 
BOOL bgv2= (bgv1 & 128)!= 0;
if(bgv2)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
bgv1<<= 1;
if(bgv2) bgv1|= 1;
Reg_F&= ~(BITN | BITH);
POSSZ(bgv1);
POSP(bgv1);
ECRMEM(ad, bgv1);
}

static void OpRLCM(u_char inst)
{
GenRLCm((Reg_H<<8) + Reg_L); 
}

static void OpRRCr(u_char inst)
{
u_char bgv1= Glob.r[inst & 7];
BOOL bgv2= (bgv1 & 1)!= 0;
bgv1>>= 1;
if(bgv2)
	{
	bgv1|= 128;
	Reg_F|= BITC;
	}
else	Reg_F&= ~BITC;
Reg_F&= ~(BITN | BITH);
POSSZ(bgv1);
POSP(bgv1);
Glob.r[inst & 7]= bgv1;
}

static void GenRRCm(u_int ad)
{
u_char bgv1= LECMEM(ad);
BOOL bgv2= (bgv1 & 1)!= 0;
bgv1>>= 1;
if(bgv2)
	{
	bgv1|= 128;
	Reg_F|= BITC;
	}
else	Reg_F&= ~BITC;
Reg_F&= ~(BITN | BITH);
POSSZ(bgv1);
POSP(bgv1);
ECRMEM(ad, bgv1);
}

static void OpRRCM(u_char inst)
{
GenRRCm((Reg_H<<8)+Reg_L);
}

static void OpRLr(u_char inst)
{
u_char bgv1= Glob.r[inst & 7];
BOOL bgv2= (bgv1 & 128)!= 0;
bgv1<<= 1;
if(Reg_F & BITC)
	bgv1|= 1;
if(bgv2)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
Reg_F&= ~(BITN | BITH);
POSSZ(bgv1);
POSP(bgv1);
Glob.r[inst & 7]= bgv1;
}

static void GenRLm(u_int ad)
{
u_char bgv1= LECMEM(ad);
BOOL bgv2= (bgv1 & 128)!= 0;
bgv1<<= 1;
if(Reg_F & BITC)
	bgv1|= 1;
if(bgv2)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
Reg_F&= ~(BITN | BITH);
POSSZ(bgv1);
POSP(bgv1);
ECRMEM(ad, bgv1);
}

static void OpRLM(u_char inst)
{
GenRLm((Reg_H<<8) + Reg_L);
}

static void OpRRr(u_char inst)
{
u_char bgv1= Glob.r[inst & 7];
BOOL bgv2= (bgv1 & 1)!= 0;
bgv1>>= 1;
if(Reg_F & BITC)
	bgv1|= 128;
if(bgv2)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
Reg_F&= ~(BITN | BITH);
POSSZ(bgv1);
POSP(bgv1);
Glob.r[inst & 7]= bgv1;
}

static void GenRRm(u_int ad)
{
u_char bgv1= LECMEM(ad);
BOOL bgv2= (bgv1 & 1)!= 0;
bgv1>>= 1;
if(Reg_F & BITC)
	bgv1|= 128;
if(bgv2)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
Reg_F&= ~(BITN | BITH);
POSSZ(bgv1);
POSP(bgv1);
ECRMEM(ad, bgv1);
}

static void OpRRM(u_char inst)
{
GenRRm((Reg_H<<8) + Reg_L); 
}

static void OpSLAr(u_char inst)
{
u_char bgv1= Glob.r[inst & 7];
if(bgv1 & 0x80)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
bgv1<<=1;
Reg_F&= ~(BITN | BITH);
POSSZ(bgv1);
POSP(bgv1);
Glob.r[inst & 7]= bgv1;
}

static void GenSLAm(u_int ad)
{
u_char bgv1= LECMEM(ad);
if(bgv1 & 0x80)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
bgv1<<=1;
Reg_F&= ~(BITN | BITH);
POSSZ(bgv1);
POSP(bgv1);
ECRMEM(ad, bgv1);
}

static void OpSLAM(u_char inst)
{
GenSLAm((Reg_H<<8) + Reg_L);
}

static void OpSRAr(u_char inst)
{
u_char bgv1= Glob.r[inst & 7];
if(bgv1 & 1)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
bgv1= (bgv1>>1) | (bgv1 & 0x80);
Reg_F&= ~(BITN | BITH);
POSSZ(bgv1);
POSP(bgv1);
Glob.r[inst & 7]= bgv1;
}

static void GenSRAm(u_int ad)
{
u_char bgv1= LECMEM(ad);
if(bgv1 & 1)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
bgv1= (bgv1>>1) | (bgv1 & 0x80);
Reg_F&= ~(BITN | BITH);
POSSZ(bgv1);
POSP(bgv1);
ECRMEM(ad, bgv1);
}

static void OpSRAM(u_char inst)
{
GenSRAm((Reg_H<<8) + Reg_L);
}

static void OpSRLr(u_char inst)
{
u_char bgv1= Glob.r[inst & 7];
if(bgv1 & 1)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
bgv1= (bgv1>>1) & 0x7f;
Reg_F&= ~(BITN | BITH);
POSSZ(bgv1);
POSP(bgv1);
Glob.r[inst & 7]= bgv1;
}

static void GenSRLm(u_int ad)
{
u_char bgv1= LECMEM(ad);
if(bgv1 & 1)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
bgv1= (bgv1>>1) & 0x7f;
Reg_F&= ~(BITN | BITH);
POSSZ(bgv1);
POSP(bgv1);
ECRMEM(ad, bgv1);
}

static void OpSRLM(u_char inst)
{
GenSRLm((Reg_H<<8) + Reg_L);
}

static void OpRLD(void)
{
u_int ad= (Reg_H<<8)+Reg_L;
u_char vx= LECMEM(ad);
u_char vy= (vx<<4) | (Reg_A & 0x0f);
Reg_A= (Reg_A & 0xf0) | ((vx & 0xf0)>>4);
ECRMEM(ad, vy);
POSSZ(vy);
Reg_F&= ~(BITN | BITH);
}

static void OpRRD(void)
{
u_int ad= (Reg_H<<8)+Reg_L;
u_char vx= LECMEM(ad);
u_char vy= (vx>>4) | ((Reg_A & 0x0f)<<4);
Reg_A= (Reg_A & 0xf0) | (vx & 0x0f);
ECRMEM(ad, vy);
POSSZ(vy);
Reg_F&= ~(BITN | BITH);
}

static void OpBITbr(u_char inst)
{
u_char bgv1= Glob.r[inst & 7];
u_char mask= 1<< (inst>>3);
if(bgv1 & mask)
	Reg_F&= ~BITZ;
else	Reg_F|= BITZ;
Reg_F&= ~BITN;
Reg_F|= BITH;
}

static void GenBITbm(u_int ad)
{
u_char bgv1= LECMEM(ad);
u_char mask= 1<< (inst>>3);
if(bgv1 & mask)
	Reg_F&= ~BITZ;
else	Reg_F|= BITZ;
Reg_F&= ~BITN;
Reg_F|= BITH;
}

static void OpBITbM(u_char inst)
{
u_int ad1= (Reg_H<<8) + Reg_L;
u_char bgv1= LECMEM(ad1);
u_char mask= 1<< (inst>>3);
if(bgv1 & mask)
	Reg_F&= ~BITZ;
else	Reg_F|= BITZ;
Reg_F&= ~BITN;
Reg_F|= BITH;
}

static void OpRESbr(u_char inst)
{
Glob.r[inst & 7]&= ~(1<< (inst>>3));
}

static void GenRESbm(u_int ad)
{
u_char bgv1= LECMEM(ad);
bgv1&= ~(1<< (inst>>3));
ECRMEM(ad, bgv1);
}

static void OpRESbM(u_char inst)
{
GenRESbm((Reg_H<<8) + Reg_L);
}

static void OpSETbr(u_char inst)
{
Glob.r[inst & 7]|= 1<< (inst>>3);
}

static void GenSETbm(u_int ad)
{
u_char bgv1= LECMEM(ad);
bgv1|= 1<< (inst>>3);
ECRMEM(ad, bgv1);
}

static void OpSETbM(u_char inst)
{
GenSETbm((Reg_H<<8) + Reg_L);
}

void (*ModeOpCB[256])(u_char inst) =
	{
	OpRLCr,OpRLCr,OpRLCr,OpRLCr,OpRLCr,OpRLCr,OpRLCM,OpRLCr,OpRRCr,OpRRCr,OpRRCr,OpRRCr,OpRRCr,OpRRCr,OpRRCM,OpRRCr,
	OpRLr,OpRLr,OpRLr,OpRLr,OpRLr,OpRLr,OpRLM,OpRLr,OpRRr,OpRRr,OpRRr,OpRRr,OpRRr,OpRRr,OpRRM,OpRRr,
	OpSLAr,OpSLAr,OpSLAr,OpSLAr,OpSLAr,OpSLAr,OpSLAM,OpSLAr,OpSRAr,OpSRAr,OpSRAr,OpSRAr,OpSRAr,OpSRAr,OpSRAM,OpSRAr,
	ui10,ui10,ui10,ui10,ui10,ui10,ui10,ui10,OpSRLr,OpSRLr,OpSRLr,OpSRLr,OpSRLr,OpSRLr,OpSRLM,OpSRLr,
	OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbM,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbM,OpBITbr,
	OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbM,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbM,OpBITbr,
	OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbM,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbM,OpBITbr,
	OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbM,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbr,OpBITbM,OpBITbr,
	OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbM,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbM,OpRESbr,
	OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbM,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbM,OpRESbr,
	OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbM,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbM,OpRESbr,
	OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbM,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbr,OpRESbM,OpRESbr,
	OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbM,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbM,OpSETbr,
	OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbM,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbM,OpSETbr,
	OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbM,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbM,OpSETbr,
	OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbM,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbr,OpSETbM,OpSETbr,
	};

#define SAVEIX u_char sH= Reg_H, sL= Reg_L; \
Reg_L= Reg_IX & 0xff; Reg_H= Reg_IX>>8

#define RESTORIX Reg_IX= (Reg_H<<8)+Reg_L; \
Reg_L= sL; Reg_H= sH

static void OpADDIXss()
{
SAVEIX;
OpADDHLss();
RESTORIX;
}

static void OpADDIXSP()
{
SAVEIX;
OpADDHLSP();
RESTORIX;
}

static void OpLDIXnn()
{
SAVEIX;
OpLDssnn();
RESTORIX;
}

static void OpLDinnIX()
{
SAVEIX;
OpLDinnHL();
RESTORIX;
}

static void OpLDIXinn()
{
SAVEIX;
OpLDHLinn();
RESTORIX;
}

static void OpINCIX()
{
SAVEIX;
OpINCss();
RESTORIX;
}

static void OpDECIX()
{
SAVEIX;
OpDECss();
RESTORIX;
}

static void OpPOPIX()
{
SAVEIX;
OpPOPss();
RESTORIX;
}

static void OpEXSPIX()
{
SAVEIX;
OpEXSPHL();
RESTORIX;
}

static void OpPUSHIX()
{
SAVEIX;
OpPUSHss();
RESTORIX;
}

static void OpJPIX()
{
SAVEIX;
OpJPHL();
RESTORIX;
}

static void OpLDSPIX()
{
SAVEIX;
OpLDSPHL();
RESTORIX;
}

static void OpLDrIXd()
{
u_int ad1= Reg_IX + (signed char) LRPC;
NEXTPC;
Glob.r[(inst & 0x3f)>>3]= LECMEM(ad1);
}

static void OpLDIXdr()
{
u_int ad1= Reg_IX + (signed char) LRPC;
NEXTPC;
ECRMEM(ad1, Glob.r[inst & 7]);
}

#define PRELIX u_int ad1= Reg_IX + (signed char) LRPC; \
	NEXTPC; \
	Glob.r[inst=6]= LECMEM(ad1)

static void OpADDIXd()
{
PRELIX;
Reg_F&= ~BITC;
OpADCr();
}

static void OpADCIXd()
{
PRELIX;
OpADCr();
}

static void OpSUBIXd()
{
PRELIX;
Reg_F&= ~BITC;
OpSBCr();
}

static void OpSBCIXd()
{
PRELIX;
OpSBCr();
}

static void OpANDIXd()
{
PRELIX;
OpANDr();
}

static void OpXORIXd()
{
PRELIX;
OpXORr();
}

static void OpORIXd()
{
PRELIX;
OpORr();
}

static void OpCPIXd()
{
PRELIX;
OpCPr();
}

void (*MoDDFDCB[256])(u_int ad);
static void OpHexDDCB(void)
{
u_int ad1= Reg_IX + (signed char) LRPC;
NEXTPC;
inst= LRPC; NEXTPC;
(*MoDDFDCB[inst])(ad1);
}

void (*ModeOpDD[256])(void) =
	{
	ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpADDIXss,ui0,ui0,ui0,ui0,ui0,ui0,
	ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpADDIXss,ui0,ui0,ui0,ui0,ui0,ui0,
	ui0,OpLDIXnn,OpLDinnIX,OpINCIX,ui0,ui0,ui0,ui0,ui0,OpADDIXss,OpLDIXinn,OpDECIX,ui0,ui0,ui0,ui0,
	ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpADDIXSP,ui0,ui0,ui0,ui0,ui0,ui0,
	ui0,ui0,ui0,ui0,ui0,ui0,OpLDrIXd,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpLDrIXd,ui0,
	ui0,ui0,ui0,ui0,ui0,ui0,OpLDrIXd,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpLDrIXd,ui0,
	ui0,ui0,ui0,ui0,ui0,ui0,OpLDrIXd,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpLDrIXd,ui0,
	OpLDIXdr,OpLDIXdr,OpLDIXdr,OpLDIXdr,OpLDIXdr,OpLDIXdr,ui0,OpLDIXdr,ui0,ui0,ui0,ui0,ui0,ui0,OpLDrIXd,ui0,
	ui0,ui0,ui0,ui0,ui0,OpADDIXd,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpADCIXd,ui0,
	ui0,ui0,ui0,ui0,ui0,OpSUBIXd,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpSBCIXd,ui0,
	ui0,ui0,ui0,ui0,ui0,OpANDIXd,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpXORIXd,ui0,
	ui0,ui0,ui0,ui0,ui0,OpORIXd,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpCPIXd,ui0,
	ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpHexDDCB,ui0,ui0,ui0,ui0,ui0,
	ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,
	ui0,OpPOPIX,ui0,OpEXSPIX,ui0,OpPUSHIX,ui0,ui0,ui0,OpJPIX,ui0,ui0,ui0,ui0,ui0,ui0,
	ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpLDSPIX,ui0,ui0,ui0,ui0,ui0,ui0
	};

static void OpNEG()
{
u_char rA = Reg_A;
Reg_A= 0;
Glob.r[inst= 6]= rA;
OpSUBr();
}

static void OpADCHLss()
{
u_int rHL= (Reg_H<<8) + Reg_L;
u_int rxHL= rHL & 0x7ffff;
u_char ix= (inst>>3) & 7;
u_int vx= Glob.r[ix] + (Glob.r[ix-1]<<8);
u_int v12= vx & 0x7fff;
BOOL bgv2;
if (Reg_F & BITC) { vx++; v12++;}
bgv2= (rHL+= vx) >= 0x10000; Reg_L= rHL & 0xff; Reg_H= (rHL>>8) & 0xff;
if(bgv2)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
if(bgv2 ^ (rxHL + v12 >= 0x8000))
	Reg_F |= BITV;
else	Reg_F &= ~BITV;
Reg_F&= ~BITN;
}

static void OpADCHLSP()
{
u_int rHL= (Reg_H<<8) + Reg_L;
u_int rxHL= rHL & 0x7ffff;
u_int vx= Reg_SP;
u_int v12= vx & 0x7fff;
BOOL bgv2;
if (Reg_F & BITC) { vx++; v12++;}
bgv2= (rHL+= vx) >= 0x10000; Reg_L= rHL & 0xff; Reg_H= (rHL>>8) & 0xff;
if(bgv2)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
if(bgv2 ^ (rxHL + v12 >= 0x8000))
	Reg_F |= BITV;
else	Reg_F &= ~BITV;
Reg_F&= ~BITN;
}

static void OpINiCr()
{
extern u_char EmuReadPort(T_NO_PORT port);
u_char vz= EmuReadPort(V_AD_PORT);
Glob.r[(inst>>3) & 7]= vz;
POSP(vz);
POSSZ(vz);
Reg_F&= ~BITN;
}

static void OpOUTiCr()
{
extern void EmuWritePort(T_NO_PORT port, u_char vx);
EmuWritePort(V_AD_PORT,Glob.r[(inst>>3) & 7]);
}

static void OpLDinnss()
{
u_char ix= (inst>>3) & 7;
u_int ad1= LRPC;
NEXTPC;
ad1+= (LRPC<<8); NEXTPC;
ECRMEM(ad1, Glob.r[ix+1]);
ad1= (ad1 + 1) & 0xffff;
ECRMEM(ad1, Glob.r[ix]);
}

static void OpLDinnSP()
{
u_int ad1= LRPC;
NEXTPC;
ad1+= (LRPC<<8); NEXTPC;
ECRMEM(ad1,Reg_SP & 0xff);
ad1= (ad1 + 1) & 0xffff;
ECRMEM(ad1, Reg_SP>>8);
}

static void OpLDssinn()
{
u_char ix= (inst>>3) & 7;
u_int ad1= LRPC;
NEXTPC;
ad1+= (LRPC<<8); NEXTPC;
Glob.r[ix]= LECMEM(ad1);
ad1= (ad1+1) & 0xffff;
Glob.r[ix-1]= LECMEM(ad1);
}

static void OpLDSPinn()
{
u_int ad1= LRPC;
NEXTPC;
ad1+= (LRPC<<8); NEXTPC;
Reg_SP= LECMEM(ad1);
ad1= (ad1+1) & 0xffff;
Reg_SP|= (LECMEM(ad1)<<8);
}

static void OpSBCHLss()
{
u_int rHL= (Reg_H<<8) + Reg_L;
u_int rxHL= rHL & 0x7fff;
u_int v11, v12;
BOOL bgv2;
{
u_char ix= (inst>>3) & 7;
v11= ((Glob.r[ix]<<8) + Glob.r[ix+1]) ^ 0xffff;
}
v12= v11 & 0x7fff;
if(!(Reg_F & BITC)) { v11++; v12 ++; }
bgv2= !(((rHL+= v11) & 0x10000)!= 0);
if(bgv2)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
if(!bgv2 ^ ((rxHL + v12) & 0x8000)!= 0)
	Reg_F|= BITV;
else	Reg_F &= ~BITV;
Reg_L= rHL & 0xff; Reg_H= (rHL>>8) & 0xff;
POSSZ(Reg_H);
}

static void OpSBCHLSP()
{
u_int rHL= (Reg_H<<8) + Reg_L;
u_int rxHL= rHL & 0x7fff;
u_int v11= Reg_SP;
u_int v12= v11 & 0x7fff;
BOOL bgv2;
if(!(Reg_F & BITC)) { v11++; v12 ++; }
bgv2= ((rHL+= v11) & 0x10000);
if(bgv2)
	Reg_F|= BITC;
else	Reg_F&= ~BITC;
if(bgv2 ^ ((rxHL + v12) & 0x8000)!= 0)
	Reg_F|= BITV;
else	Reg_F &= ~BITV;
Reg_L= rHL & 0xff; Reg_H= (rHL>>8) & 0xff;
POSSZ(Reg_H);
}

#define BCM1    if(!Reg_C--) Reg_B--;\
	if(!(Reg_B | Reg_C)) \
		Reg_F&= ~BITV; \
	else	Reg_F|= BITV

static void OpLDI()
{
u_int adsource= (Reg_H<<8) + Reg_L;
u_int addestin= (Reg_D<<8) + Reg_E;
u_char vx= LECMEM(adsource); adsource++;
ECRMEM(addestin, vx); addestin++;
Reg_L= adsource & 0xff; Reg_H= (adsource>>8) & 0xff;
Reg_E= addestin & 0xff; Reg_D= (addestin>>8) & 0xff;
BCM1;
Reg_F&= ~BITN;
}

static void OpCPI()
{
u_int ad1= (Reg_H<<8) + Reg_L;
OpCPM();
ad1++; 
Reg_L= ad1 & 0xff; Reg_H= (ad1>>8) & 0xff;
BCM1;
Reg_F|= BITN;
}

static void OpINI()
{
extern u_char EmuReadPort(T_NO_PORT port);
u_int ad1= (Reg_H<<8) + Reg_L;
u_char vz= EmuReadPort(V_AD_PORT);
ECRMEM(ad1, vz);
ad1++; Reg_L= ad1 & 0xff; Reg_H= (ad1>>8) & 0xff;
if(--Reg_B)
	Reg_F&= ~BITZ;
else	Reg_F|= BITZ;
Reg_F|= BITN;
}

static void OpOUTI()
{
extern void EmuWritePort(T_NO_PORT port, u_char vz);
u_int ad1= (Reg_H<<8) + Reg_L;
u_char vz= LECMEM(ad1);
EmuWritePort(V_AD_PORT, vz);
ad1++; Reg_L= ad1 & 0xff; Reg_H= (ad1>>8) & 0xff;
if(--Reg_B)
	Reg_F&= ~BITZ;
else	Reg_F|= BITZ;
}

static void OpLDD()
{
u_int adsource= (Reg_H<<8) + Reg_L;
u_int addestin= (Reg_D<<8) + Reg_E;
u_char vx= LECMEM(adsource); adsource--;
ECRMEM(addestin, vx); addestin--;
Reg_L= adsource & 0xff; Reg_H= (adsource>>8) & 0xff;
Reg_E= addestin & 0xff; Reg_D= (addestin>>8) & 0xff;
BCM1;
Reg_F&= ~BITN;
}

static void OpCPD()
{
u_int ad1= (Reg_H<<8) + Reg_L;
OpCPM();
ad1--; 
Reg_L= ad1 & 0xff; Reg_H= (ad1>>8) & 0xff;
BCM1;
Reg_F|= BITN;
}

static void OpIND()
{
extern u_char EmuReadPort(T_NO_PORT port);
u_int ad1= (Reg_H<<8) + Reg_L;
u_char vz= EmuReadPort(V_AD_PORT);
ECRMEM(ad1, vz);
ad1--; Reg_L= ad1 & 0xff; Reg_H= (ad1>>8) & 0xff;
if(--Reg_B)
	Reg_F&= ~BITZ;
else	Reg_F|= BITZ;
Reg_F|= BITN;
}

static void OpOUTD()
{
extern void EmuWritePort(T_NO_PORT port, u_char vz);
u_int ad1= (Reg_H<<8) + Reg_L;
u_char vz= LECMEM(ad1);
EmuWritePort(V_AD_PORT, vz);
ad1--; Reg_L= ad1 & 0xff; Reg_H= (ad1>>8) & 0xff;
if(--Reg_B)
	Reg_F&= ~BITZ;
else	Reg_F|= BITZ;
}

static void OpLDIR()
{
u_int adsource= (Reg_H<<8) + Reg_L;
u_int addestin= (Reg_D<<8) + Reg_E;
u_int count= (Reg_B<<8) + Reg_C;
do	{
	u_char vx= LECMEM(adsource);
	adsource++;
	ECRMEM(addestin, vx); addestin++;
	}
while(--count);
Reg_B= Reg_C= 0;
Reg_L= adsource & 0xff; Reg_H= (adsource>>8) & 0xff;
Reg_E= addestin & 0xff; Reg_D= (addestin>>8) & 0xff;
Reg_F&= ~(BITN | BITV);
}

static void OpCPIR()
{
u_int adsource= (Reg_H<<8) + Reg_L;
u_int count= (Reg_B<<8) + Reg_C;
do	{
	u_char vx= LECMEM(adsource);
	if((Reg_A == vx)) break;
	adsource++;
	}
while(--count);
Reg_L= adsource & 0xff; Reg_H= (adsource>>8) & 0xff;
Reg_C= count & 0xff; Reg_C= (count>>8) & 0xff;
OpCPM();
if(!count)
	Reg_F|= BITV;
else	Reg_F&= ~BITV;
}

static void OpINIR()
{
u_int addestination= (Reg_H<<8) + Reg_L;
u_int count= Reg_B;
do	{
	extern u_char EmuReadPort(T_NO_PORT port);
	u_char vz= EmuReadPort(V_AD_PORT);
	ECRMEM(addestination, vz);
	addestination++;
	}
while(--count);
Reg_L= addestination & 0xff; Reg_H= (addestination>>8) & 0xff;
Reg_B= count;
Reg_F|= BITZ | BITN;
}

static void OpOUTIR()
{
u_int adsource= (Reg_H<<8) + Reg_L;
u_int count= Reg_B;
do	{
	extern void EmuWritePort(T_NO_PORT port, u_char vz);
	u_char vx= LECMEM(adsource);
	adsource++;
	EmuWritePort(V_AD_PORT, vx);
	}
while(--count);
Reg_B= 0;
Reg_F|= BITZ | BITN;
}

static void OpLDDR()
{
u_int adsource= (Reg_H<<8) + Reg_L;
u_int addestin= (Reg_D<<8) + Reg_E;
u_int count= (Reg_B<<8) + Reg_C;
do	{
	u_char vx= LECMEM(adsource);
	adsource--;
	ECRMEM(addestin, vx); addestin--;
	}
while(--count);
Reg_B= Reg_C= 0;
Reg_L= adsource & 0xff; Reg_H= (adsource>>8) & 0xff;
Reg_E= addestin & 0xff; Reg_D= (addestin>>8) & 0xff;
Reg_F&= ~(BITN | BITV);
}

static void OpCPDR()
{
u_int adsource= (Reg_H<<8) + Reg_L;
u_int count= (Reg_B<<8) + Reg_C;
do	{
	u_char vx= LECMEM(adsource);
	if((Reg_A == vx)) break;
	adsource--;
	}
while(--count);
Reg_L= adsource & 0xff; Reg_H= (adsource>>8) & 0xff;
Reg_C= count & 0xff; Reg_C= (count>>8) & 0xff;
OpCPM();
if(!count)
	Reg_F|= BITV;
else	Reg_F&= ~BITV;
}

static void OpINDR()
{
u_int addestination= (Reg_H<<8) + Reg_L;
u_int count= Reg_B;
do	{
	extern u_char EmuReadPort(u_char port);
	u_char vz= EmuReadPort(Reg_C);
	ECRMEM(addestination, vz);
	addestination--;
	}
while(--count);
Reg_L= addestination & 0xff; Reg_H= (addestination>>8) & 0xff;
Reg_B= count;
Reg_F|= BITZ | BITN;
}

static void OpOUTDR()
{
u_int adsource= (Reg_H<<8) + Reg_L;
u_int count= Reg_B;
do	{
	extern void EmuWritePort(u_char port, u_char vz);
	u_char vx= LECMEM(adsource);
	adsource--;
	EmuWritePort(Reg_C, vx);
	}
while(--count);
Reg_B= 0;
Reg_F|= BITZ | BITN;
}

#ifdef IM0
static void OpIM0(void)
{
mode_inter= 0;
}
#else
#define OpIM0  OpNOP
#endif
#ifdef IM1
static void OpIM1(void)
{
mode_inter= 1;
}
#else
#define OpIM1  OpNOP
#endif
#ifdef IM2
static void OpIM2(void)
{
mode_inter= 2;
}
#else
#define OpIM2  OpNOP
#endif

static void OpLDAR()
{
Reg_A= (u_char) rand();
if(Reg_IFF)
	Reg_F|= BITV;
else	Reg_F&= ~BITV;
POSSZ(Reg_A);
Reg_F&= ~(BITN | BITH);
}

static void OpLDAI()
{
Reg_A= Reg_I;
if(Reg_IFF)
	Reg_F|= BITV;
else	Reg_F&= ~BITV;
POSSZ(Reg_A);
Reg_F&= ~(BITN | BITH);
}

static void OpLDIA()
{
Reg_I= Reg_A;
}

#define OpLDRA OpNOP
#define OpRETI OpRET
#ifdef NMI
static void OpRETN(void)
{
Reg_IFF= Reg_IFF2;
OpRET();
}
#else
#define OpRETN OpRET
#endif

void (*ModeOpED[256])(void) =
	{
	ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,
	ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,
	ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,
	ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,
	OpINiCr,OpOUTiCr,OpSBCHLss,OpLDinnss,OpNEG,OpRETN,OpIM0,OpLDIA,OpINiCr,OpOUTiCr,OpADCHLss,OpLDssinn,ui0,OpRETI,ui0,OpLDRA,
	OpINiCr,OpOUTiCr,OpSBCHLss,OpLDinnss,ui0,ui0,OpIM1,OpLDAI,OpINiCr,OpOUTiCr,OpADCHLss,OpLDssinn,ui0,ui0,OpIM2,OpLDAR,
	OpINiCr,OpOUTiCr,OpSBCHLss,OpLDinnss,ui0,ui0,ui0,OpRRD,OpINiCr,OpOUTiCr,OpADCHLss,OpLDssinn,ui0,ui0,ui0,OpRLD,
	OpINiCr,ui0,OpSBCHLSP,OpLDinnSP,ui0,ui0,ui0,ui0,OpINiCr,OpOUTiCr,OpADCHLSP,OpLDSPinn,ui0,ui0,ui0,ui0,
	ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,
	ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,
	OpLDI,OpCPI,OpINI,OpOUTI,ui0,ui0,ui0,ui0,OpLDD,OpCPD,OpIND,OpOUTD,ui0,ui0,ui0,ui0,
	OpLDIR,OpCPIR,OpINIR,OpOUTIR,ui0,ui0,ui0,OpLDDR,OpCPDR,OpINDR,OpOUTDR,ui0,ui0,ui0,ui0,ui0,
	ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,
	ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,
	ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,
	ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0
	};

#define SAVEIY u_char sH= Reg_H, sL= Reg_L; \
Reg_L= Reg_IY & 0xff; Reg_H= Reg_IY>>8

#define RESTORIY Reg_IY= (Reg_H<<8)+Reg_L; \
Reg_L= sL; Reg_H= sH

static void OpADDIYss()
{
SAVEIY;
OpADDHLss();
RESTORIY;
}

static void OpADDIYSP()
{
SAVEIY;
OpADDHLSP();
RESTORIY;
}

static void OpLDIYnn()
{
SAVEIY;
OpLDssnn();
RESTORIY;
}

static void OpLDinnIY()
{
SAVEIY;
OpLDinnHL();
RESTORIY;
}

static void OpLDIYinn()
{
SAVEIY;
OpLDHLinn();
RESTORIY;
}

static void OpINCIY()
{
SAVEIY;
OpINCss();
RESTORIY;
}

static void OpDECIY()
{
SAVEIY;
OpDECss();
RESTORIY;
}

static void OpPOPIY()
{
SAVEIY;
OpPOPss();
RESTORIY;
}

static void OpEXSPIY()
{
SAVEIY;
OpEXSPHL();
RESTORIY;
}

static void OpPUSHIY()
{
SAVEIY;
OpPUSHss();
RESTORIY;
}

static void OpJPIY()
{
SAVEIY;
OpJPHL();
RESTORIY;
}

static void OpLDSPIY()
{
SAVEIY;
OpLDSPHL();
RESTORIY;
}
static void OpLDrIYd()
{
u_int ad1= Reg_IY + (signed char) LRPC;
NEXTPC;
Glob.r[(inst & 0x3f)>>3]= LECMEM(ad1);
}

static void OpLDIYdr()
{
u_int ad1= Reg_IY + (signed char) LRPC;
NEXTPC;
ECRMEM(ad1, Glob.r[inst & 7]);
}

#define PRELIY u_int ad1= Reg_IY + (signed char) LRPC; \
	NEXTPC; \
	Glob.r[inst=6]= LECMEM(ad1)

static void OpADDIYd()
{
PRELIY;
Reg_F&= ~BITC;
OpADCr();
}

static void OpADCIYd()
{
PRELIY;
OpADCr();
}

static void OpSUBIYd()
{
PRELIY;
Reg_F&= ~BITC;
OpSBCr();
}

static void OpSBCIYd()
{
PRELIY;
OpSBCr();
}

static void OpANDIYd()
{
PRELIY;
OpANDr();
}

static void OpXORIYd()
{
PRELIY;
OpXORr();
}

static void OpORIYd()
{
PRELIY;
OpORr();
}

static void OpCPIYd()
{
PRELIY;
OpCPr();
}

void (*MoDDFDCB[256])(u_int ad);
static void OpHexFDCB(void)
{
u_int ad1= Reg_IY + (signed char) LRPC;
NEXTPC;
inst= LRPC; NEXTPC;
(*MoDDFDCB[inst])(ad1);
}

void (*ModeOpFD[256])(void) =
	{
	ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpADDIYss,ui0,ui0,ui0,ui0,ui0,ui0,
	ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpADDIYss,ui0,ui0,ui0,ui0,ui0,ui0,
	ui0,OpLDIYnn,OpLDinnIY,OpINCIY,ui0,ui0,ui0,ui0,ui0,OpADDIYss,OpLDIYinn,OpDECIY,ui0,ui0,ui0,ui0,
	ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpADDIYSP,ui0,ui0,ui0,ui0,ui0,ui0,
	ui0,ui0,ui0,ui0,ui0,0,OpLDrIYd,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpLDrIYd,ui0,
	ui0,ui0,ui0,ui0,ui0,0,OpLDrIYd,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpLDrIYd,ui0,
	ui0,ui0,ui0,ui0,ui0,0,OpLDrIYd,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpLDrIYd,ui0,
	OpLDIYdr,OpLDIYdr,OpLDIYdr,OpLDIYdr,OpLDIYdr,OpLDIYdr,ui0,OpLDIYdr,ui0,ui0,ui0,ui0,ui0,ui0,OpLDrIYd,ui0,
	ui0,ui0,ui0,ui0,ui0,OpADDIYd,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpADCIYd,ui0,
	ui0,ui0,ui0,ui0,ui0,OpSUBIYd,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpSBCIYd,ui0,
	ui0,ui0,ui0,ui0,ui0,OpANDIYd,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpXORIYd,ui0,
	ui0,ui0,ui0,ui0,ui0,OpORIYd,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpCPIYd,ui0,
	ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpHexFDCB,ui0,ui0,ui0,ui0,
	ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,
	ui0,OpPOPIY,ui0,OpEXSPIY,ui0,OpPUSHIY,ui0,ui0,ui0,OpJPIY,ui0,ui0,ui0,ui0,ui0,ui0,
	ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,ui0,OpLDSPIY,ui0,ui0,ui0,ui0,ui0,ui0
	};
 
void (*MoDDFDCB[256])(u_int ad) =
	{
	ui20,ui20,ui20,ui20,ui20,GenRLCm,ui20,ui20,ui20,ui20,ui20,ui20,ui20,ui20,GenRRCm,ui20,
	ui20,ui20,ui20,ui20,ui20,GenRLm,ui20,ui20,ui20,ui20,ui20,ui20,ui20,ui20,GenRRm,ui20,
	ui20,ui20,ui20,ui20,ui20,GenSLAm,ui20,ui20,ui20,ui20,ui20,ui20,ui20,ui20,GenSRAm,ui20,
	ui20,ui20,ui20,ui20,ui20,ui20,ui20,ui20,ui20,ui20,ui20,ui20,ui20,ui20,GenSRLm,ui20,
	ui20,ui20,ui20,ui20,ui20,GenBITbm,ui20,ui20,ui20,ui20,ui20,ui20,ui20,ui20,GenBITbm,ui20,
	ui20,ui20,ui20,ui20,ui20,GenBITbm,ui20,ui20,ui20,ui20,ui20,ui20,ui20,ui20,GenBITbm,ui20,
	ui20,ui20,ui20,ui20,ui20,GenBITbm,ui20,ui20,ui20,ui20,ui20,ui20,ui20,ui20,GenBITbm,ui20,
	ui20,ui20,ui20,ui20,ui20,GenBITbm,ui20,ui20,ui20,ui20,ui20,ui20,ui20,ui20,GenBITbm,ui20,
	ui20,ui20,ui20,ui20,ui20,GenRESbm,ui20,ui20,ui20,ui20,ui20,ui20,ui20,ui20,GenRESbm,ui20,
	ui20,ui20,ui20,ui20,ui20,GenRESbm,ui20,ui20,ui20,ui20,ui20,ui20,ui20,ui20,GenRESbm,ui20,
	ui20,ui20,ui20,ui20,ui20,GenRESbm,ui20,ui20,ui20,ui20,ui20,ui20,ui20,ui20,GenRESbm,ui20,
	ui20,ui20,ui20,ui20,ui20,GenRESbm,ui20,ui20,ui20,ui20,ui20,ui20,ui20,ui20,GenRESbm,ui20,
	ui20,ui20,ui20,ui20,ui20,GenSETbm,ui20,ui20,ui20,ui20,ui20,ui20,ui20,ui20,GenSETbm,ui20,
	ui20,ui20,ui20,ui20,ui20,GenSETbm,ui20,ui20,ui20,ui20,ui20,ui20,ui20,ui20,GenSETbm,ui20,
	ui20,ui20,ui20,ui20,ui20,GenSETbm,ui20,ui20,ui20,ui20,ui20,ui20,ui20,ui20,GenSETbm,ui20,
	ui20,ui20,ui20,ui20,ui20,GenSETbm,ui20,ui20,ui20,ui20,ui20,ui20,ui20,ui20,GenSETbm,ui20
	};
