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

📄 makez80.c

📁 十七种模拟器源代码 非常有用的作课程设计不可缺少的
💻 C
📖 第 1 页 / 共 5 页
字号:
			else				fprintf(fp, "		js	near noMoreExec2\n");		}		if ((FALSE == bNoTiming) && (FALSE == bSingleStep))		{			fprintf(fp, "		add	dword [dwElapsedTicks], byte %ld\n", Timing(bCurrentMode, dwOpcode));		}	}}void SetOverflow(void){	fprintf(fp, "		o16	pushf\n");	fprintf(fp, "		and	ah, 0fbh	;	Knock out parity/overflow\n");	fprintf(fp, "		pop	dx\n");	fprintf(fp, "		and	dh, 08h ; Just the overflow\n");	fprintf(fp, "		shr	dh, 1	; Shift it into position\n");	fprintf(fp, "		or	ah, dh	; OR It in with the real flags\n");	CLEAR_DH();}void FetchNextInstruction(void){	fprintf(fp, "		mov	dl, byte [esi]	; Get our next instruction\n");	fprintf(fp, "		inc	esi		; Increment PC\n");	fprintf(fp, "		jmp	dword [z80regular+edx*4]\n\n");}#ifdef NEW_WRITE// value can come from any memory or reg// if value comes from [esi], inc esi (pc).// address can come from bx, cx, dx or [_memory]// preserved: ax// trashed: edi, dxvoid WriteValueToMemory(UINT8 *pszAddress, UINT8 *pszValue){    UINT8 addr_reg[32];	fprintf(fp, "		mov	[_z80af], ax		; Store AF\n");	if (strcmp(pszValue, "al") != 0)	{	fprintf(fp, "		mov	al, %s			; And our data to write\n", pszValue);	}	if (strcmp(pszAddress, "[_z80de]") == 0 || strcmp(pszAddress, "[_orgval]") == 0 ||	 strcmp(pszAddress, "[_z80ix]") == 0 || strcmp(pszAddress, "[_z80iy]") == 0)	{	fprintf(fp, "		mov	dx, %s			\n", pszAddress);	sprintf(addr_reg,"dx");	}	else	{	sprintf(addr_reg,"%s",pszAddress);	}	fprintf(fp, "		mov	edi, [_z80MemWrite]	; Point to the write array\n\n", cpubasename);	if (strcmp(pszValue, "[esi]") == 0)	{	fprintf(fp, "		inc	esi			; Increment our program counter\n");	}	fprintf(fp, "checkLoop%ld:				\n", dwGlobalLabel);	fprintf(fp, "		cmp	%s, [edi]		; Are we smaller?\n", addr_reg);	fprintf(fp, "		jb	nextAddr%ld		; Yes... go to the next addr\n", dwGlobalLabel);	fprintf(fp, "		cmp	%s, [edi+4]		; Are we smaller?\n", addr_reg);	fprintf(fp, "		jbe	callRoutine%ld		; If not, go call it!\n\n", dwGlobalLabel);	fprintf(fp, "		cmp	[edi], word 0ffffh 	; End of our list?\n");	fprintf(fp, "		je	memoryWrite%ld		; Yes - go write it!\n", dwGlobalLabel);	fprintf(fp, "nextAddr%ld:				\n", dwGlobalLabel);	fprintf(fp, "		add	edi, 10h		; Next structure, please\n");	fprintf(fp, "		jmp	short checkLoop%ld	\n\n", dwGlobalLabel);	// ---- Check internal/external write ----------------------------------	fprintf(fp, "callRoutine%ld:				\n", dwGlobalLabel);	fprintf(fp, "		cmp	dword[edi+8],byte 0 	; [J3d!] Use internal write?\n");	fprintf(fp, "		jne	short callWrite%ld	\n", dwGlobalLabel);	// ---- Internal write -------------------------------------------------	fprintf(fp, "memoryWrite%ld:\n", dwGlobalLabel);	fprintf(fp, "		mov	edi, [edi+12] 		; [J3d!] Get offset\n");	fprintf(fp, "		mov	[edi + e%s], al		; Store our direct value\n", addr_reg);	fprintf(fp, "		mov	ax, [_z80af]		; Get our accumulator and flags\n");	fprintf(fp, "		jmp	short WriteMacroExit%ld	\n", dwGlobalLabel);	// ---- External write -------------------------------------------------	fprintf(fp, "callWrite%ld:\n", dwGlobalLabel);	if (strcmp(addr_reg, "dx") != 0)	{	fprintf(fp, "		mov	dx, %s			\n", addr_reg);	}	fprintf(fp, "		call	WriteMemoryByte		; Go write the data!\n");	// ---- Exit -----------------------------------------------------------	fprintf(fp, "WriteMacroExit%ld:\n", dwGlobalLabel);	dwGlobalLabel++;}#elsevoid WriteValueToMemory(UINT8 *pszAddress, UINT8 *pszValue){	fprintf(fp, "		mov	[_z80af], ax	; Store AF\n");	// First off, load our byte to write into al after we've saved AF	if (strcmp(pszValue, "al") != 0)		fprintf(fp, "		mov	al, %s	; And our data to write\n", pszValue);	if (strcmp(pszValue, "[esi]") == 0)	// Immediate value?		fprintf(fp, "		inc	esi	; Increment our program counter\n");	// Now get the address in DX - regardless of what it is	if (strcmp(pszAddress, "[_z80de]") == 0 ||		 strcmp(pszAddress, "[_orgval]") == 0 ||		 strcmp(pszAddress, "[_z80ix]") == 0 ||		 strcmp(pszAddress, "[_z80iy]") == 0)		fprintf(fp, "		mov	dx, %s\n", pszAddress);	fprintf(fp, "		mov	edi, [_z80MemWrite]	; Point to the write array\n\n");	fprintf(fp, "checkLoop%ld:\n", dwGlobalLabel);	if (strcmp(pszAddress, "[_z80de]") == 0 ||		 strcmp(pszAddress, "[_orgval]") == 0 ||		 strcmp(pszAddress, "[_z80ix]") == 0 ||		 strcmp(pszAddress, "[_z80iy]") == 0)		fprintf(fp, "		cmp	dx, [edi]	; Are we smaller?\n");	else		fprintf(fp, "		cmp	%s, [edi]	; Are we smaller?\n", pszAddress);	fprintf(fp, "		jb	nextAddr%ld	; Yes... go to the next addr\n", dwGlobalLabel);	if (strcmp(pszAddress, "[_z80de]") == 0 ||		 strcmp(pszAddress, "[_orgval]") == 0 ||		 strcmp(pszAddress, "[_z80ix]") == 0 ||		 strcmp(pszAddress, "[_z80iy]") == 0)		fprintf(fp, "		cmp	dx, [edi+4]	; Are we smaller?\n");	else		fprintf(fp, "		cmp	%s, [edi+4]	; Are we smaller?\n", pszAddress);	fprintf(fp, "		jbe	callRoutine%ld	; If not, go call it!\n\n", dwGlobalLabel);	fprintf(fp, "		cmp	[edi], word 0ffffh ; End of our list?\n");	fprintf(fp, "		je	memoryWrite%ld	; Yes - go write it!\n", dwGlobalLabel);	fprintf(fp, "nextAddr%ld:\n", dwGlobalLabel);	fprintf(fp, "		add	edi, 10h		; Next structure, please\n");	fprintf(fp, "		jmp	short checkLoop%ld\n\n", dwGlobalLabel);	fprintf(fp, "callRoutine%ld:\n", dwGlobalLabel);	// Check internal/external write	fprintf(fp, "		cmp	dword[edi+8],byte 0 	; [J3d!] Use internal write?\n");	fprintf(fp, "		jne	short callWrite%ld\n", dwGlobalLabel);	// ---- Internal write -------------------------------------------------	fprintf(fp, "memoryWrite%ld:\n", dwGlobalLabel);	fprintf(fp, "		mov	edi, [edi+12] 		; [J3d!] Get offset\n");	if (strcmp(pszValue, "[esi]") == 0)		fprintf(fp, "		mov	[edi + e%s], al		; Store our direct value\n", pszAddress);	else	{		if (pszValue[0] == 'b' && pszValue[1] == 'y' && pszValue[2] == 't')		{			fprintf(fp, "		push	edx\n");			assert(strcmp(pszValue, "dl") != 0);			if (strcmp(pszAddress, "dx") == 0){				fprintf(fp, "		add	edi, edx\n");				fprintf(fp, "		mov	dl, %s\n", pszValue);				fprintf(fp, "		mov	[edi], dl\n");			}			else{				fprintf(fp, "		mov	dl, %s\n", pszValue);				fprintf(fp, "		mov	[edi + e%s], dl\n", pszAddress);			}			fprintf(fp, "		pop	edx\n");		}		else		{			if (strcmp(pszAddress, "[_z80de]") != 0 &&				 strcmp(pszAddress, "[_orgval]") != 0 &&				 strcmp(pszAddress, "[_z80ix]") != 0 &&				 strcmp(pszAddress, "[_z80iy]") != 0)				fprintf(fp, "		mov	[edi + e%s], %s\n", pszAddress, pszValue);			else				fprintf(fp, "		mov	[edi + edx], al\n");		}	}	fprintf(fp, "		mov	ax, [_z80af] ; Get our accumulator and flags\n");	fprintf(fp, "		jmp	short WriteMacroExit%ld\n", dwGlobalLabel);	// ---- External write -------------------------------------------------	fprintf(fp, "callWrite%ld:\n", dwGlobalLabel);	if ((strcmp(pszAddress, "dx") != 0) && (strcmp(pszAddress, "[_z80de]") != 0) &&		 (strcmp(pszAddress, "[_z80ix]") != 0) &&		 (strcmp(pszAddress, "[_orgval]") != 0) &&		 (strcmp(pszAddress, "[_z80iy]") != 0))		fprintf(fp, "		mov	dx, %s	; Get our address to target\n", pszAddress);	fprintf(fp, "		call	WriteMemoryByte	; Go write the data!\n");	// Exit	fprintf(fp, "WriteMacroExit%ld:\n", dwGlobalLabel);	++dwGlobalLabel;}#endif#ifdef WORD_ACCESS// address is always dx//void WriteWordToMemory(UINT8 *pszAddress, UINT8 *pszTarget){	if (strcmp(pszTarget, "di") == 0)	{	fprintf(fp, "		; ERROR !!\n");	}	fprintf(fp, "		mov	edi, [_z80MemWrite]	; Point to the write array\n\n", cpubasename);	fprintf(fp, "checkLoop%ld:				\n", dwGlobalLabel);	fprintf(fp, "		cmp	%s, [edi]		; Are we smaller?\n", pszAddress);	fprintf(fp, "		jb	nextAddr%ld		; Yes, go to the next address\n", dwGlobalLabel);	fprintf(fp, "		cmp	%s, [edi+4]		; Are we bigger?\n", pszAddress);	fprintf(fp, "		jbe	callRoutine%ld		\n\n", dwGlobalLabel);	fprintf(fp, "		cmp	[edi], word 0ffffh 	; End of the list?\n");	fprintf(fp, "		je	memoryWrite%ld		\n", dwGlobalLabel);	fprintf(fp, "nextAddr%ld:				\n", dwGlobalLabel);	fprintf(fp, "		add	edi, 10h		; Next structure!\n");	fprintf(fp, "		jmp	short checkLoop%ld	\n\n", dwGlobalLabel);	fprintf(fp, "callRoutine%ld:				\n", dwGlobalLabel);	// Check internal/external write	fprintf(fp, "		cmp	dword[edi+8],byte 0 	; [J3d!] Use internal write?\n");	fprintf(fp, "		jne	short callWrite%ld	\n", dwGlobalLabel);	// ---- Internal write -------------------------------------------------	fprintf(fp, "memoryWrite%ld:				\n", dwGlobalLabel);	if (strlen(pszTarget) != 2)				// It's not a register	{	fprintf(fp, "		push	eax			\n");	fprintf(fp, "		mov	edi, [edi+12] 		; Get offset\n");	fprintf(fp, "		mov	ax, %s			\n", pszTarget);	fprintf(fp, "		mov	[edi + e%s], ax		; Store our word\n", pszAddress);	fprintf(fp, "		pop	eax			\n");	}	else							// It's a register	{	fprintf(fp, "		mov	edi, [edi+12] 		; Get offset\n");	if (strcmp(pszTarget, "ax") != 0)			// not ax	{	fprintf(fp, "		mov	[edi + e%s], %s		; Store our word\n", pszAddress, pszTarget);	}	else							// ax	{	fprintf(fp, "		xchg	ah, al			; Swap for later\n");	fprintf(fp, "		mov	[edi + e%s], ax		; Store our word\n", pszAddress);	fprintf(fp, "		xchg	ah, al			; Restore\n");	}	}	fprintf(fp, "		jmp	short WriteExit%ld	\n", dwGlobalLabel);	// ---- External write -------------------------------------------------	fprintf(fp, "callWrite%ld:				\n", dwGlobalLabel);	fprintf(fp, "		push	ax			; Save this for later\n");	fprintf(fp, "		push	dx			\n");	if (strcmp(pszTarget, "ax") != 0)	{	fprintf(fp, "		mov	ax, %s			\n", pszTarget);	}	else	{	fprintf(fp, "		xchg	ah, al			\n");	}	fprintf(fp, "		call	WriteMemoryByte		\n");	fprintf(fp, "		pop	dx			\n");	fprintf(fp, "		pop	ax			\n");	//fprintf(fp, "		inc	dx			\n");	fprintf(fp, "		push	ax			\n");	fprintf(fp, "		push	dx			\n");	if (strcmp(pszTarget, "ax") != 0)	{	fprintf(fp, "		mov	ax, %s			\n", pszTarget);	fprintf(fp, "		xchg	ah, al			\n");	}	fprintf(fp, "		inc	dx			\n");	// Here?	fprintf(fp, "		call	WriteMemoryByte		\n");	fprintf(fp, "		pop	dx			\n");	fprintf(fp, "		pop	ax			; Restore us!\n");	// ---- Exit -----------------------------------------------------------	fprintf(fp, "WriteExit%ld:				\n", dwGlobalLabel);	dwGlobalLabel++;}#endifvoid WriteValueToIo(UINT8 *pszIoAddress, UINT8 *pszValue){	fprintf(fp, "		mov	[_z80af], ax	; Store AF\n");	if (strcmp(pszValue, "al") != 0)		fprintf(fp, "		mov	al, %s	; And our data to write\n", pszValue);	if (strcmp(pszValue, "[esi]") == 0)	// Immediate value?		fprintf(fp, "		inc	esi	; Increment our program counter\n");	fprintf(fp, "		mov	edi, [_z80IoWrite]	; Point to the I/O write array\n\n");	fprintf(fp, "checkLoop%ld:\n", dwGlobalLabel);	fprintf(fp, "		cmp	[edi], word 0ffffh ; End of our list?\n");	fprintf(fp, "		je	WriteMacroExit%ld	; Yes - ignore it!\n", dwGlobalLabel);	fprintf(fp, "		cmp	%s, [edi]	; Are we smaller?\n", pszIoAddress);	fprintf(fp, "		jb	nextAddr%ld	; Yes... go to the next addr\n", dwGlobalLabel);	fprintf(fp, "		cmp	%s, [edi+2]	; Are we bigger?\n", pszIoAddress);	fprintf(fp, "		jbe	callRoutine%ld	; If not, go call it!\n\n", dwGlobalLabel);	fprintf(fp, "nextAddr%ld:\n", dwGlobalLabel);	fprintf(fp, "		add	edi, 0ch		; Next structure, please\n");	fprintf(fp, "		jmp	short checkLoop%ld\n\n", dwGlobalLabel);	fprintf(fp, "callRoutine%ld:\n", dwGlobalLabel);	// Save off our registers!	if (strcmp(pszIoAddress, "dx") != 0)		fprintf(fp, "		mov	dx, %s	; Get our address to target\n", pszIoAddress);	fprintf(fp, "		call	WriteIOByte	; Go write the data!\n");	fprintf(fp, "WriteMacroExit%ld:\n", dwGlobalLabel);	++dwGlobalLabel;}#ifdef NEW_READvoid ReadValueFromMemory(UINT8 *pszAddress, UINT8 *pszTarget){	fprintf(fp, "		mov	edi, [_z80MemRead]	; Point to the read array\n\n", cpubasename);	fprintf(fp, "checkLoop%ld:				\n", dwGlobalLabel);	fprintf(fp, "		cmp	%s, [edi]		; Are we smaller?\n", pszAddress);	fprintf(fp, "		jb	nextAddr%ld		; Yes, go to the next address\n", dwGlobalLabel);	fprintf(fp, "		cmp	%s, [edi+4]		; Are we bigger?\n", pszAddress);	fprintf(fp, "		jbe	callRoutine%ld		\n\n", dwGlobalLabel);	fprintf(fp, "		cmp	[edi], word 0ffffh	; End of the list?\n");	fprintf(fp, "		je	memoryRead%ld		\n", dwGlobalLabel);	fprintf(fp, "nextAddr%ld:				\n", dwGlobalLabel);	fprintf(fp, "		add	edi, 10h		; Next structure!\n");	fprintf(fp, "		jmp	short checkLoop%ld	\n\n", dwGlobalLabel);	// ---- Check internal/external read -----------------------------------	fprintf(fp, "callRoutine%ld:				\n", dwGlobalLabel);	fprintf(fp, "		cmp	dword[edi+8],byte 0 	; [J3d!] Use internal read?\n");	fprintf(fp, "		jne	short callRead%ld	\n", dwGlobalLabel);	// ---- Internal read --------------------------------------------------	fprintf(fp, "memoryRead%ld:				\n", dwGlobalLabel);	fprintf(fp, "		mov	edi, [edi+12] 		; [J3d!] Get offset\n");	if (pszTarget[0] == 'b' && pszTarget[1] == 'y' && pszTarget[2] == 't')	{	fprintf(fp, "		push	edx			\n");	fprintf(fp, "		mov	dl, [edi + e%s]		\n", pszAddress);	fprintf(fp, "		mov	%s, dl			\n", pszTarget);	fprintf(fp, "		pop	edx			\n");	}	else	{	fprintf(fp, "		mov	%s, [edi + e%s]		; Get our data\n", pszTarget, pszAddress);	}	fprintf(fp, "		jmp	short readExit%ld	\n\n", dwGlobalLabel);	// ---- External read --------------------------------------------------	fprintf(fp, "callRead%ld:				\n", dwGlobalLabel);	if (strcmp(pszAddress, "dx") != 0)	{	fprintf(fp, "		mov	dx, %s			; Get our address\n", pszAddress);	}	fprintf(fp, "		call	ReadMemoryByte		; Standard read routine\n");	if (strcmp(pszTarget, "al") == 0)	{	fprintf(fp, "		mov	[_z80af], al		; Save our new accumulator\n");	}	else	{	if (strcmp(pszTarget, "ah") == 0)	{	fprintf(fp, "		mov	[_z80af + 1], al	; Save our new flags\n");	}	else	{	fprintf(fp, "		mov	%s, al			; Put our returned value here\n", pszTarget);	}	}	fprintf(fp, "		mov	ax, [_z80af]		; Get our AF back\n");

⌨️ 快捷键说明

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