⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 z80.c

📁 这个是延伸mame的在wince平台下的游戏模拟器的代码
💻 C
📖 第 1 页 / 共 5 页
字号:
 " orb %%ah,%1          \n"                                     \
 :"=c" (Z80.DR.D), "=g" (Z80.AF.B.l)                            \
 :"0" (Z80.DR.D), "1" (Z80.AF.B.l), "a" (Z80.SR.D)              \
 )
#else
#define ADD16(DR,SR) {                                          \
	UINT32 res = Z80.DR.D + Z80.SR.D;							\
	_F = (_F & (SF | ZF | VF)) |								\
		(((Z80.DR.D ^ res ^ Z80.SR.D) >> 8) & HF) | 			\
		((res >> 16) & CF); 									\
	Z80.DR.W.l = (UINT16)res;									\
}
#endif

/***************************************************************
 * ADC	r16,r16
 ***************************************************************/
#ifdef	X86_ASM
#define ADC16(DR,SR)											\
 asm (                                                          \
 " shrb $1,%%al         \n"                                     \
 " adcb %%dl,%%cl       \n"                                     \
 " adcb %%dh,%%ch       \n"                                     \
 " lahf                 \n"                                     \
 " setob %%al           \n"                                     \
 " andb $0x91,%%ah      \n" /* sign, half carry and carry */    \
 " shlb $2,%%al         \n"                                     \
 " orb %%ah,%%al        \n" /* overflow into P/V */             \
 " orl %%ecx,%%ecx      \n"                                     \
 " lahf                 \n"                                     \
 " andb $0x40,%%ah      \n" /* zero */                          \
 " orb %%ah,%%al        \n"                                     \
 :"=c" (DR), "=a" (Z80.AF.B.l)                                  \
 :"0" (DR), "d" (SR), "a" (Z80.AF.B.l)                          \
 )
#else
#define ADC16(DR,SR) {                                          \
	UINT32 res = DR + SR + (_F & CF);							\
	_F = ( ((DR ^ res ^ SR) >> 8) & HF) |						\
		   ((res >> 16) & CF) | 								\
		   ((res >> 8) & SF) |									\
		   ((res & 0xffff) ? 0 : ZF) |							\
		   (((SR ^ DR ^ 0x8000) & (SR ^ res) & 0x8000) >> 13);	\
	DR = (UINT16)res;											\
}
#endif

/***************************************************************
 * SBC	r16,r16
 ***************************************************************/
#ifdef	X86_ASM
#define SBC16(DR,SR)											\
asm (															\
 " shrb $1,%%al         \n"                                     \
 " sbbb %%dl,%%cl       \n"                                     \
 " sbbb %%dh,%%ch       \n"                                     \
 " lahf                 \n"                                     \
 " setob %%al           \n"                                     \
 " andb $0x91,%%ah      \n" /* sign, half carry and carry */    \
 " shlb $2,%%al         \n"                                     \
 " orb %%ah,%%al        \n" /* overflow into P/V */             \
 " orl %%ecx,%%ecx      \n"                                     \
 " lahf                 \n"                                     \
 " orb $2,%%al          \n"                                     \
 " andb $0x40,%%ah      \n" /* zero */                          \
 " orb %%ah,%%al        \n"                                     \
 :"=c" (DR), "=a" (Z80.AF.B.l)                                  \
 :"0" (DR), "d" (SR),  "a" (Z80.AF.B.l)                         \
 )
#else
#define SBC16(DR,SR) {                                          \
	UINT32 res = DR - SR - (_F & CF);							\
	_F = ( ((DR ^ res ^ SR) >> 8) & HF) |						\
		   ((res >> 16) & CF) | 								\
		   ((res >> 8) & SF) |									\
		   ((res & 0xffff) ? 0 : ZF) |							\
		   (((SR ^ DR) & (DR ^ res) & 0x8000) >> 13);			\
    DR = (UINT16)res;                                           \
}
#endif

/***************************************************************
 * RLC	r8
 ***************************************************************/
INLINE UINT8 RLC(UINT8 Value)
{
	unsigned res = Value;
	unsigned c = (res & 0x80) ? CF : 0;
	res = ((res << 1) | (res >> 7)) & 0xff;
	_F = SZP[res] | c;
	return res;
}

/***************************************************************
 * RRC	r8
 ***************************************************************/
INLINE UINT8 RRC(UINT8 Value)
{
	unsigned res = Value;
	unsigned c = (res & 0x01) ? CF : 0;
	res = ((res >> 1) | (res << 7)) & 0xff;
	_F = SZP[res] | c;
	return res;
}

/***************************************************************
 * RL	r8
 ***************************************************************/
INLINE UINT8 RL(UINT8 Value)
{
	unsigned res = Value;
	unsigned c = (res & 0x80) ? CF : 0;
	res = ((res << 1) | (_F & CF)) & 0xff;
	_F = SZP[res] | c;
	return res;
}

/***************************************************************
 * RR	r8
 ***************************************************************/
INLINE UINT8 RR(UINT8 Value)
{
	unsigned res = Value;
	unsigned c = (res & 0x01) ? CF : 0;
	res = ((res >> 1) | (_F << 7)) & 0xff;
	_F = SZP[res] | c;
	return res;
}

/***************************************************************
 * SLA	r8
 ***************************************************************/
INLINE UINT8 SLA(UINT8 Value)
{
	unsigned res = Value;
	unsigned c = (res & 0x80) ? CF : 0;
	res = (res << 1) & 0xff;
	_F = SZP[res] | c;
	return res;
}

/***************************************************************
 * SRA	r8
 ***************************************************************/
INLINE UINT8 SRA(UINT8 Value)
{
	unsigned res = Value;
	unsigned c = (res & 0x01) ? CF : 0;
	res = ((res >> 1) | (res & 0x80)) & 0xff;
	_F = SZP[res] | c;
	return res;
}

/***************************************************************
 * SLL	r8
 ***************************************************************/
INLINE UINT8 SLL(UINT8 Value)
{
	unsigned res = Value;
	unsigned c = (res & 0x80) ? CF : 0;
	res = ((res << 1) | 0x01) & 0xff;
	_F = SZP[res] | c;
	return res;
}

/***************************************************************
 * SRL	r8
 ***************************************************************/
INLINE UINT8 SRL(UINT8 Value)
{
	unsigned res = Value;
	unsigned c = (res & 0x01) ? CF : 0;
	res = (res >> 1) & 0xff;
	_F = SZP[res] | c;
	return res;
}

/***************************************************************
 * BIT  bit,r8
 ***************************************************************/
#define BIT(bit,reg)                                            \
	_F = (_F & CF) | HF | SZ[reg & (1<<bit)]

/***************************************************************
 * RES	bit,r8
 ***************************************************************/
INLINE UINT8 RES(UINT8 bit, UINT8 Value)
{
	return Value & ~(1<<bit);
}

/***************************************************************
 * SET  bit,r8
 ***************************************************************/
INLINE UINT8 SET(UINT8 bit, UINT8 Value)
{
	return Value | (1<<bit);
}

/***************************************************************
 * LDI
 ***************************************************************/
#define LDI {													\
	WM( _DE, RM(_HL) ); 										\
	_HL++; _DE++; _BC--;										\
	_F &= SF | ZF | YF | XF | CF;								\
	if (_BC) _F |= VF;											\
}

/***************************************************************
 * CPI
 ***************************************************************/
#define CPI {													\
	UINT8 val = RM(_HL);										\
	UINT8 res = _A - val;										\
	_HL++; _BC--;												\
	_F = (_F & CF) | SZ[res] | ((_A ^ val ^ res) & HF) | NF;	\
	if (_BC) _F |= VF;											\
}

/***************************************************************
 * INI
 ***************************************************************/
#define INI {													\
	WM( _HL, IN(_BC) ); 										\
	_HL++; _B--;												\
	_F = (_B) ? NF : NF | ZF;									\
}

/***************************************************************
 * OUTI
 ***************************************************************/
#define OUTI {													\
	OUT( _BC, RM(_HL) );										\
	_HL++; _B--;												\
	_F = (_B) ? NF : NF | ZF;									\
}

/***************************************************************
 * LDD
 ***************************************************************/
#define LDD {													\
	WM( _DE, RM(_HL) ); 										\
	_HL--; _DE--; _BC--;										\
	_F &= SF | ZF | YF | XF | CF;								\
	if (_BC) _F |= VF;											\
}

/***************************************************************
 * CPD
 ***************************************************************/
#define CPD {													\
	UINT8 val = RM(_HL);										\
	UINT8 res = _A - val;										\
	_HL--; _BC--;												\
	_F = (_F & CF) | SZ[res] | ((_A ^ val ^ res) & HF) | NF;	\
	if (_BC) _F |= VF;											\
}

/***************************************************************
 * IND
 ***************************************************************/
#define IND {													\
	WM( _HL, IN(_BC) ); 										\
	_HL--; _B--;												\
	_F = (_B) ? NF : NF | ZF;									\
}

/***************************************************************
 * OUTD
 ***************************************************************/
#define OUTD {													\
	OUT( _BC, RM(_HL) );										\
	_HL--; _B--;												\
	_F = (_B) ? NF : NF | ZF;									\
}

/***************************************************************
 * LDIR
 ***************************************************************/
#define LDIR	LDI; if (_BC) { _PC -= 2; CY(5); }

/***************************************************************
 * CPIR
 ***************************************************************/
#define CPIR	CPI; if (_BC && !(_F & ZF)) { _PC -= 2; CY(5); }

/***************************************************************
 * INIR
 ***************************************************************/
#define INIR	INI; if (_B) { _PC -= 2; CY( 5); }

/***************************************************************
 * OTIR
 ***************************************************************/
#define OTIR	OUTI; if (_B) { _PC -= 2; CY( 5); }

/***************************************************************
 * LDDR
 ***************************************************************/
#define LDDR	LDD; if (_BC) { _PC -= 2; CY(5); }

/***************************************************************
 * CPDR
 ***************************************************************/
#define CPDR	CPD; if (_BC && !(_F & ZF)) { _PC -= 2; CY( 5); }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -