File:  [RetroPC.NET] / xmil / z80x / z80x.c
Revision 1.2: download - view: text, annotated - select for diffs
Sat Aug 21 08:01:16 2004 JST (21 years, 2 months ago) by yui
Branches: MAIN
CVS tags: HEAD
fix...

#include	"compiler.h"
#include	"parts.h"
#include	"z80core.h"
#include	"z80x.h"


	Z80CORE	z80core;
	UINT8	mainmem[0x10000];

	UINT8	ZSPtable[256];
	UINT8 	z80inc_flag[256];
	UINT8	z80dec_flag[256];
	UINT8	z80szc_flag[512];

	const UINT8 cycles_main[256] = {
					 4,10, 7, 6, 4, 4, 7, 4, 4,11, 7, 6, 4, 4, 7, 4,
					 8,10, 7, 6, 4, 4, 7, 4, 7,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, 4,10, 0,10,10, 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};

	const UINT8 cycles_xx[256] = {
					 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};

	const UINT8 cycles_ed[256] = {
					 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, 8, 8, 9,12,12,15,20, 8, 8, 8, 9,
					12,12,15,20, 8, 8, 8, 9,12,12,15,20, 8, 8, 8, 9,
					12,12,15,20, 8, 8, 8,18,12,12,15,20, 8, 8, 8,18,
					12,12,15,20, 8, 8, 8, 0,12,12,15,20, 8, 8, 8, 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,
					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};


void z80x_initialize(void) {

	int		i;
	BYTE	f;
	BYTE	c;

	for (i=0; i<256; i++) {
		f = V_FLAG;
		if (!i) {
			f |= Z_FLAG;
		}
		if (i & 0x80) {
			f |= S_FLAG;
		}
		for (c=0x80; c; c>>=1) {
			if (i & c) {
				f ^= V_FLAG;
			}
		}

		ZSPtable[i] = f;

		z80inc_flag[i] = (BYTE)(f & (~V_FLAG));
		if (!(i & 0x0f)) {
			z80inc_flag[i] |= H_FLAG;
		}
		z80dec_flag[i] = (BYTE)(f & (~V_FLAG)) | N_FLAG;
		if ((i & 0x0f) == 0x0f) {
			z80dec_flag[i] |= H_FLAG;
		}

		z80szc_flag[i] = (BYTE)(f & (~V_FLAG));
		z80szc_flag[i+256] = (BYTE)(f & (~V_FLAG)) | C_FLAG;
	}
	z80inc_flag[0x80] |= V_FLAG;
	z80dec_flag[0x7f] |= V_FLAG;
}

void z80x_reset(void) {

	ZeroMemory(&z80core.s, sizeof(z80core.s));
	z80core.s.r1 = rand_get();
}


RetroPC.NET-CVS <cvs@retropc.net>