CP/M emulator for Unix - Part 03/03

D'Arcy J.M. Cain darcy at druid.uucp
Thu Jan 17 09:41:08 AEST 1991


Here is my CP/M emulator part 3 as mentioned in comp.os.cpm

#!/bin/sh
# this is cpm.03 (part 3 of a multipart archive)
# do not concatenate these parts, unpack them in order with /bin/sh
# file decode.c continued
#
if test ! -r _shar_seq_.tmp; then
	echo 'Please unpack part 1 first!'
	exit 1
fi
(read Scheck
 if test "$Scheck" != 3; then
	echo Please unpack part "$Scheck" next!
	exit 1
 else
	exit 0
 fi
) < _shar_seq_.tmp || exit 1
sed 's/^X//' << 'SHAR_EOF' >> 'decode.c' &&
X		goto or;
X	case 183:		/* b7 OR A */
X		s = A;
X
or:
X		a = A & 0x0f;
X		s1 = s & 0x0f;
X
X		s |= A;
X		A = s;
X		a |= s;
X		goto set_flags;
X
X	when 184:		/* b8 CP B */
X		s = B;
X		goto cp;
X	when 185:		/* b9 CP C */
X		s = C;
X		goto cp;
X	when 186:		/* ba CP D */
X		s = D;
X		goto cp;
X	when 187:		/* bb CP E */
X		s = E;
X		goto cp;
X	when 188:		/* bc CP H */
X		s = H;
X		goto cp;
X	when 189:		/* bd CP L */
X		s = L;
X		goto cp;
X	when 190:		/* be CP (HL) */
X		s = A;
X		goto cp;
X	when 191:		/* bf CP A */
X		s = ram[HL];
X
cp:
X		a = A & 0x0f;
X		s1 = s & 0x0f;
X		s = A - s;
X		a -= s1;
X		BCD = 1;
X		goto set_flags;
X
X	when 192:		/* c0 RET NZ */
X		if (!ZERO) PC = pop();
X	when 193:		/* c1 POP BC */
X		BC = pop();
X	when 194:		/* c2 JP NZ,nn */
X		if (ZERO) { PC += 2; break;}
X	case 195:		/* c3 JP nn */
X		TEMPL = ram[PC++];
X		TEMPH = ram[PC++];
X		PC = TEMP;
X	when 196:		/* c4 CALL NZ,nn */
X		if (ZERO) PC += 2;
X		else
X		{
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			push(PC);
X			PC = TEMP;
X		}
X	when 197:		/* c5 PUSH BC */
X		push(BC);
X	when 198:		/* c6 ADD A,n */
X		s = ram[PC++];
X		goto add;
X	case 199:		/* c7 RST 0 */
X		push(PC);
X		PC = 0;
X	when 200:		/* c8 RET Z */
X		if (!ZERO) break;
X	case 201:		/* c9 RET */
X		PC = pop();
X	when 202:		/* ca JP Z,nn */
X		if (ZERO)
X		{
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			PC = TEMP;
X		}
X		else PC += 2;
X	when 203:		/* cb oh boy */
X		switch (ram[PC] & 0x03)
X		{
X			case 0: ptr = &B;
X			case 1: ptr = &C;
X			case 2: ptr = &D;
X			case 3: ptr = &E;
X			case 4: ptr = &H;
X			case 5: ptr = &L;
X			case 6: ptr = ram + HL;
X			case 7: ptr = &A;
X			default: ptr = (void *)(0);
X		}
X
cb_stuff:
X		if ((s1 = ((s = ram[PC++]) & 0xc0)) != 0)
X		{
X			a = 1 << ((s & 0x3f) >> 3);
X
X			switch (s1)
X			{
X				case 0x40:		/* BIT */
X					ZERO = *ptr & a;
X					HALF_CARRY = 1;
X					BCD = 0;
X				when 0x80:		/* RES */
X					*ptr &= ~a;
X				when 0xb0:		/* SET */
X					*ptr |= a;
X			}
X		}
X		else
X		{
X			switch (s & 0xf8)
X			{
X				case 0x00:			/* RLC */
X					CARRY= *ptr >> 7;
X					*ptr <<= 1;
X					if (CARRY) ++*ptr;
X				when 0x08:			/* RRC */
X					CARRY = *ptr;
X					*ptr >>= 1;
X					if (CARRY) *ptr |= 0x80;
X				when 0x10:			/* RL */
X					a = CARRY;
X					CARRY = *ptr >> 7;
X					*ptr <<= 1;
X					*ptr += a;
X				when 0x18:			/* RR */
X					a = CARRY;
X					CARRY = *ptr;
X					*ptr >>= 1;
X					if (a) *ptr |= 0x80;
X				when 0x20:			/* SLA */
X					CARRY = *ptr >> 7;
X					*ptr <<= 1;
X				when 0x28:			/* SRA */
X					CARRY = *ptr;
X					*ptr >>= 1;
X					if (*ptr & 0x40) *ptr |= 0x80;
X				when 0x30:			/* SLL ???? Oh well.  It fits */
X					CARRY = *ptr >> 7;
X					*ptr <<= 1;
X					*ptr |= 1;
X				when 0x38:			/* SRL */
X					CARRY = *ptr;
X					*ptr >>= 1;
X			}
X
X			SIGN = *ptr >> 7;
X			ZERO = *ptr == 0;
X			HALF_CARRY = BCD = 0;
X			PARITY = partab[*ptr];
X		}
X	when 204:		/* cc CALL Z,nn */
X		if (ZERO)
X		{
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			push(PC);
X			PC = TEMP;
X		}
X		else PC += 2;
X	when 205:		/* cd CALL nn */
X		TEMPL = ram[PC++];
X		TEMPH = ram[PC++];
X		push(PC);
X		PC = TEMP;
X	when 206:		/* ce ADC A,n */
X		s = ram[PC++];
X		goto adc;
X	when 207:		/* cf RST 08 */
X		push(PC);
X		PC = 8;
X	when 208:		/* d0 RET NC */
X		if (!CARRY)
X			PC = pop();
X	when 209:		/* d1 POP DE */
X		DE = pop();
X	when 210:		/* d2 JP NC,nn */
X		if (CARRY) PC += 2;
X		else
X		{
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			PC = TEMP;
X		}
X	when 211:		/* d3 OUT (n),A */
X		return(211);
X	when 212:		/* d4 CALL NC,nn */
X		if (CARRY) PC += 2;
X		else
X		{
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			push(PC);
X			PC = TEMP;
X		}
X	when 213:		/* d5 PUSH DE */
X		push(DE);
X	when 214:		/* d6 SUB N */
X		s = ram[PC++];
X		goto sub;
X	when 215:		/* d7 RST 10 */
X		push(PC);
X		PC = 16;
X	when 216:		/* d8 RET C */
X		if (CARRY)
X			PC = pop();
X	when 217:		/* d9 EXX */
X		gr_bank = gr_bank ? 0 : 1;
X	when 218:		/* da JP C,nn */
X		if (CARRY)
X		{
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			PC = TEMP;
X		}
X		else PC += 2;
X	when 219:		/* db IN A,(n) */
X		return(219);
X	when 220:		/* dc CALL C,nn */
X		if (CARRY)
X		{
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			push(PC);
X			PC = TEMP;
X		}
X		else PC += 2;
X	when 221:		/* DD instructions - use IX register */
X		opcode = ram[PC++];
X		switch (opcode)
X		{
X			case 0x09:		/* 09 ADD IX,BC */
X				s = BC;
X				a = (IX & 0xfff) + (s & 0xfff);
X				s += IX;
X				IX = s;
X				BCD = 0;
X				CARRY = s >> 16;
X				HALF_CARRY = a >> 12;
X			when 0x19:		/* ADD IX, DE */
X				s = DE;
X				a = (IX & 0xfff) + (s & 0xfff);
X				s += IX;
X				IX = s;
X				BCD = 0;
X				CARRY = s >> 16;
X				HALF_CARRY = a >> 12;
X			when 0x21:		/* LD IX, nn */
X				IXL = ram[PC++];
X				IXH = ram[PC++];
X			when 0x22:		/* LD (nn), IX) */
X				TEMPL = ram[PC++];
X				TEMPH = ram[PC++];
X				ram[TEMP] = IXL;
X				ram[TEMP + 1] = IXH;
X			when 0x23:		/* INC IX */
X				IX++;
X			when 0x29:		/* ADD IX, IX */
X				s = IX;
X				a = (IX & 0xfff) + (s & 0xfff);
X				s += IX;
X				IX = s;
X				BCD = 0;
X				CARRY = s >> 16;
X				HALF_CARRY = a >> 12;
X			when 0x2a:		/* LD IX, (nn) */
X				TEMPL = ram[PC++];
X				TEMPH = ram[PC++];
X				IXL = ram[TEMP];
X				IXH = ram[TEMP + 1];
X			when 0x2b:		/* DEC IX */
X				IX--;
X			when 0x34:		/* INC (IX + d) */
X				ptr = ram + IX + ram[PC++];
X				HALF_CARRY = lonyb(*ptr) == 0xf;
X				++(*ptr);
X				SIGN = *ptr >> 7;
X				ZERO = *ptr == 0;
X				PARITY = *ptr == 0x80;
X				BCD = 0;
X			when 0x35:		/* DEC (IX + d) */
X				ptr = ram + IX + ram[PC++];
X				HALF_CARRY = lonyb(*ptr) != 0;
X				--(*ptr);
X				SIGN = *ptr >> 7;
X				ZERO = *ptr == 0;
X				PARITY = *ptr == 0x7f;
X				BCD = 1;
X			when 0x36:		/* LD (IX + d), n */
X				TEMP = IX + ram[PC++];
X				ram[TEMP] = ram[PC++];
X			when 0x39:		/* ADD IX, SP */
X				s = SP;
X				a = (IX & 0xfff) + (s & 0xfff);
X				s += IX;
X				IX = s;
X				BCD = 0;
X				CARRY = s >> 16;
X				HALF_CARRY = a >> 12;
X			when 0x46:		/* LD B, (IX + d) */
X				B = ram[IX + ram[PC++]];
X			when 0x4e:		/* LD C, (IX + d) */
X				C = ram[IX + ram[PC++]];
X			when 0x56:		/* LD D, (IX + d) */
X				D = ram[IX + ram[PC++]];
X			when 0x5e:		/* LD E, (IX + d) */
X				E = ram[IX + ram[PC++]];
X			when 0x66:		/* LD H, (IX + d) */
X				H = ram[IX + ram[PC++]];
X			when 0x6e:		/* LD L, (IX + d) */
X				L = ram[IX + ram[PC++]];
X			when 0x70:		/* LD (IX + d, B */
X				ram[IX + ram[PC++]] = B;
X			when 0x71:		/* LD (IX + d, C */
X				ram[IX + ram[PC++]] = C;
X			when 0x72:		/* LD (IX + d, D */
X				ram[IX + ram[PC++]] = D;
X			when 0x73:		/* LD (IX + d, E */
X				ram[IX + ram[PC++]] = E;
X			when 0x74:		/* LD (IX + d, H */
X				ram[IX + ram[PC++]] = H;
X			when 0x75:		/* LD (IX + d, L */
X				ram[IX + ram[PC++]] = L;
X			when 0x77:		/* LD (IX + d, A */
X				ram[IX + ram[PC++]] = A;
X			when 0x7e:		/* LD A, (IX + d) */
X				A = ram[IX + ram[PC++]];
X			when 0x86:		/* ADD A, (IX + d) */
X				s = ram[IX + ram[PC++]];
X				goto add;
X			when 0x8e:		/* ADC A, (IX + d) */
X				s = ram[IX + ram[PC++]];
X				goto adc;
X			when 0x96:		/* SUB A, (IX + d) */
X				s = ram[IX + ram[PC++]];
X				goto sub;
X			when 0x9e:		/* SBC A, (IX + d) */
X				s = ram[IX + ram[PC++]];
X				goto sbc;
X			when 0xa6:		/* AND A, (IX + d) */
X				s = ram[IX + ram[PC++]];
X				goto and;
X			when 0xae:		/* XOR A, (IX + d) */
X				s = ram[IX + ram[PC++]];
X				goto xor;
X			when 0xb6:		/* OR A, (IX + d) */
X				s = ram[IX + ram[PC++]];
X				goto or;
X			when 0xbe:		/* CP A, (IX + d) */
X				s = ram[IX + ram[PC++]];
X				goto cp;
X			when 0xcb:
X				ptr = ram + IX + ram[PC++];
X				goto cb_stuff;
X			when 0xe1:		/* POP IX */
X				IX = pop();
X			when 0xe3:		/* EX (SP), IX */
X				s = IX;
X				IX = pop();
X				push(s);
X			when 0xe5:		/* PUSH IX */
X				push(IX);
X			when 0xe9:		/* JP (IX) */
X				PC = IX;
X			when 0xf9:		/* LD SP, IX */
X				SP = IX;
X			break; default: return(-1);
X		}
X	when 222:		/* de SBC A,n */
X		s = ram[PC++];
X		goto sbc;
X	when 223:		/* df RST 18 */
X		push(PC);
X		PC = 0x18;
X	when 224:		/* e0 RET PO */
X		if (!PARITY)
X			PC = pop();
X	when 225:		/* e1 POP HL */
X		HL = pop();
X	when 226:		/* e2 JP PO,nn */
X		if (PARITY) PC += 2;
X		else
X		{
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			PC = TEMP;
X		}
X	when 227:		/* e3 EX (SP),HL */
X		s = HL;
X		HL = pop();
X		push(s);
X	when 228:		/* e4 CALL PO,nn */
X		if (PARITY) PC += 2;
X		else
X		{
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			push(PC);
X			PC = TEMP;
X		}
X	when 229:		/* e5 PUSH HL */
X		push(HL);
X	when 230:		/* e6 AND n */
X		s = ram[PC++];
X		goto and;
X	when 231:		/* e7 RST 20 */
X		push(PC);
X		PC = 0x20;
X	when 232:		/* e8 RET PE */
X		if (PARITY)
X			PC = pop();
X	when 233:		/* e9 JP (HL) */
X		PC = HL;
X	when 234:		/* ea JP PE,nn */
X		if (PARITY)
X		{
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			PC = TEMP;
X		}
X		else PC += 2;
X	when 235:		/* eb EX DE,HL */
X		s = HL;
X		HL = DE;
X		DE = s;
X	when 236:		/* ec CALL PE,nn */
X		if (PARITY)
X		{
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			push(PC);
X			PC = TEMP;
X		}
X	when 237:		/* ed oh boy */
X		a = ram[PC++];
X		switch(a)
X		{
X		case 0x40:		/* IN B,(C) */
X		case 0x41:		/* OUT (C),B */
X		case 0x48:		/* IN C,(C) */
X		case 0x49:		/* OUT (C),C */
X		case 0x50:		/* IN D,(C) */
X		case 0x51:		/* OUT (C),D */
X		case 0x58:		/* IN E,(C) */
X		case 0x59:		/* OUT (C),E */
X		case 0x60:		/* IN H,(C) */
X		case 0x61:		/* OUT (C),H */
X		case 0x68:		/* IN L,(C) */
X		case 0x69:		/* OUT (C),L */
X		when 0x78:		/* IN A,(C) */
X		when 0x79:		/* OUT (C),A */
X		case 0xa2:		/* INI */
X		case 0xa3:		/* OUTI */
X		case 0xaa:		/* IND */
X		case 0xab:		/* OUTD */
X		case 0xb2:		/* INIR */
X		case 0xb3:		/* OTIR */
X		case 0xba:		/* INDR */
X		case 0xbb:		/* OTDR */
X			return(0xed00 + a);
X		when 0x42:		/* SBC HL,BC */
X			TEMP = BC;
X			goto edsbc;
X		when 0x43:		/* LD (nn),BC */
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			ram[TEMP] = C;
X			ram[TEMP + 1] = B;
X		when 0x44:		/* NEG */
X			HALF_CARRY = lonyb(A) != 0;
X			CARRY = A!= 0;
X			PARITY = A == 0x80;
X			A = 0 - A;
X			SIGN = A >> 7;
X			ZERO = A == 0;
X			BCD = 1;
X		when 0x45:		/* RETN */
X
X			/*
X			 * INTERRUPT: Add restore IFF states
X			 */
X
X			PC = pop();
X		when 0x46:		/* IM 0 */
X
X			/*
X			 * INTERRUPT: Set IM 0
X			 */
X			;
X		when 0x47:		/* LD I,A */
X
X			/*
X			 * INTERRUPT: Load I from A
X			 */
X			;
X		when 0x4a:		/* ADC HL,BC */
X			TEMP = BC;
X			goto edadc;
X		when 0x4b:		/* LD BC,(nn) */
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			C = ram[TEMP];
X			B = ram[TEMP + 1];
X		when 0x4d:		/* RETI */
X			PC = pop();
X		when 0x4f:		/* LD R,A */
X			R = A + 1;
X		when 0x52:		/* SBC HL,DE */
X			TEMP = DE;
X			goto edsbc;
X		when 0x53:		/* LD (nn),DE */
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			ram[TEMP] = E;
X			ram[TEMP + 1] = D;
X		when 0x56:		/* IM 1 */
X
X			/*
X			 * INTERRUPT: Set IM 1
X			 */
X			;
X		when 0x57:		/* LD A,I */
X
X			/*
X			 * INTERRUPT: A=I
X			 */
X			;
X		when 0x5a:		/* ADC HL,DE */
X			TEMP = DE;
X			goto edadc;
X		when 0x5b:		/* LD DE,(nn) */
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			E = ram[TEMP];
X			D = ram[TEMP + 1];
X		when 0x5e:		/* IM 2 */
X
X			/*
X			 * INTERRUPT: Set IM 2
X			 */
X			;
X		when 0x5f:		/* LD A,R */
X			A = ++R;
X			SIGN = A >> 7;
X			ZERO = A == 0;
X			HALF_CARRY = BCD = 0;
X
X			/*
X			 * INTERRUPT: Copy IFF2 into PARITY
X			 */
X
X			PARITY = 0;
X		when 0x62:		/* SBC HL,HL */
X			TEMP = HL;
X			goto edsbc;
X		when 0x63:		/* LD (nn),HL */
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			ram[TEMP] = L;
X			ram[TEMP + 1] = H;
X		when 0x67:		/* RRD */
X			s = lonyb(ram[HL]);
X			HL = (ram[HL] >> 4) | (lonyb(A) << 4);
X			A = (A & 0xf0) | s;
X			SIGN = A >> 7;
X			ZERO = A == 0;
X			PARITY = partab[A];
X			HALF_CARRY = BCD = 0;
X		when 0x6a:		/* ADC HL,HL */
X			TEMP = HL;
X			goto edadc;
X		when 0x6b:		/* LD HL,(nn) */
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			L = ram[TEMP];
X			H = ram[TEMP + 1];
X		when 0x6f:		/* RLD */
X			s = hinyb(ram[HL]);
X			ram[HL] = (ram[HL] << 4) | lonyb(A);
X			A = ( A & 0xf0) | s;
X			SIGN = A >> 7;
X			ZERO = A == 0;
X			PARITY = partab[A];
X			HALF_CARRY = BCD = 0;
X		when 0x72:		/* SBC HL,SP */
X			TEMP = SP;
edsbc:
X			s = (HL & 0xfff) - (TEMP & 0xfff);
X			if (CARRY) --s;
X			HALF_CARRY = s < 0;
X			s = (int)(HL - TEMP);
X			if (CARRY) --s;
X			PARITY = s < -32768 || s > 32767;
X			s = (int)(HL - TEMP);
X			if (CARRY) --s;
X			CARRY = s < 0;
X			HL = s;
X			SIGN =HL >> 15;
X			ZERO = HL == 0;
X			BCD = 1;
X		when 0x73:		/* LD (nn),SP */
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			ram[TEMP] = SPL;
X			ram[TEMP + 1] = SPH;
X		when 0x7a:		/* ADC HL,SP */
X			TEMP = SP;
edadc:
X			s = (HL & 0xfff) + (TEMP & 0xfff);
X			if (CARRY) ++s;
X			HALF_CARRY = s > 0xfff;
X			s = (int)(HL + TEMP);
X			if (CARRY) ++s;
X			s1 = s > 0xffff;
X			s = (int)(HL + TEMP);
X			if (CARRY) ++s;
X			PARITY = s < -32768 || s > 32767;
X			HL = s;
X			CARRY = s1;
X			SIGN = HL >> 15;
X			ZERO = HL == 0;
X			BCD = 0;
X		when 0x7b:		/* LD SP,(nn) */
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			SPL = ram[TEMP];
X			SPH = ram[TEMP + 1];
X		when 0xa0:		/* LDI */
X			ram[DE++] = ram[HL++];
X			PARITY = --BC != 0;
X			HALF_CARRY = BCD = 0;
X		when 0xa1:		/* CPI */
X			s = ram[HL++];
X			PARITY= --BC!=0;
X			ZERO = A == s;
X			HALF_CARRY = (int)((A & 0xf) - (s & 0xf)) < 0;
X			s = A - s;
X			SIGN = s >> 7;
X			BCD = 0;
X		when 0xa8:		/* LDD */
X			ram[DE--] = ram[HL--];
X			PARITY = --BC != 0;
X			HALF_CARRY = BCD = 0;
X		when 0xa9:		/* CPD */
X			s = ram[HL--];
X			PARITY = --BC != 0;
X			ZERO = A == s;
X			HALF_CARRY = (int)((A & 0xf) - (s & 0xf)) < 0;
X			s = A - s;
X			SIGN = s >> 7;
X			BCD = 0;
X		when 0xb0:		/* LDIR */
X			do
X				ram[DE++] = ram[HL++];
X			while (--BC);
X			HALF_CARRY = BCD = PARITY = 0;
X
X			/*
X			 * INTERRUPT: Convert for PC-=2
X			 * Also conv CPIR,INIR,OTIR,LDDR,CPDR, etc
X			 */
X
X		when 0xb1:		/* CPIR */
X			do
X			{
X				s = ram[HL++];
X				PARITY = --BC != 0;
X				ZERO = A == s;
X			} while(!ZERO && PARITY);
X			HALF_CARRY = (int)((A & 0xf) - (s & 0xf)) < 0;
X			s = A - s;
X			SIGN = s >> 7;
X			BCD = 0;
X		when 0xb8:		/* LDDR */
X			do
X				ram[DE--] = ram[HL--];
X			while (--BC);
X			HALF_CARRY = BCD = PARITY = 0;
X		when 0xb9:		/* CPDR */
X			do
X			{
X				s = ram[HL--];
X				PARITY = --BC != 0;
X				ZERO = A == s;
X			} while(!ZERO && PARITY);
X			HALF_CARRY = (int)((A & 0xf) - (s & 0xf)) < 0;
X			s = A - s;
X			SIGN = s >> 7;
X			BCD = 0;
X		}
X	when 238:		/* ee XOR n */
X		s = ram[PC++];
X		goto xor;
X	when 239:		/* ef RST 28 */
X		push(PC);
X		PC = 0x28;
X	when 240:		/* f0 RET P */
X		if (!SIGN)
X			PC = pop();
X	when 241:		/* f1 POP AF */
X		AF = pop();
X	when 242:		/* f2 JP P,nn */
X		if (SIGN) PC += 2;
X		else
X		{
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			PC = TEMP;
X		}
X	when 243:		/* f3 DI */
X
X		/*
X		 * INTERRUPT: Disable
X		 */
X		;
X	when 244:		/* f4 CALL P,nn */
X		if (SIGN) PC += 2;
X		else
X		{
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			push(PC);
X			PC = TEMP;
X		}
X	when 245:		/* f5 PUSH AF */
X		push(AF);
X	when 246:		/* f6 OR n */
X		s = ram[PC++];
X		goto or;
X	when 247:		/* f7 RST 30 */
X		push(PC);
X		PC = 0x30;
X	when 248:		/* f8 RET M */
X		if (SIGN)
X			PC = pop();
X	when 249:		/* f9 LD SP,HL */
X		SP = HL;
X	when 250:		/* fa JP M,nn */
X		if (SIGN)
X		{
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			PC = TEMP;
X		}
X		else PC += 2;
X	when 251:		/* fb EI */
X
X		/*
X		 * INTERRUPT: Enable
X		 */
X		;
X	when 252:		/* fc CALL M,nn */
X		if (SIGN)
X		{
X			TEMPL = ram[PC++];
X			TEMPH = ram[PC++];
X			push(PC);
X			PC = TEMP;
X		}
X		else PC += 2;
X	when 253:		/* FD instructions - use IY register */
X		opcode = ram[PC++];
X		switch (opcode)
X		{
X			case 0x09:		/* 09 ADD IY,BC */
X				s = BC;
X				a = (IY & 0xfff) + (s & 0xfff);
X				s += IY;
X				IY = s;
X				BCD = 0;
X				CARRY = s >> 16;
X				HALF_CARRY = a >> 12;
X			when 0x19:		/* ADD IY, DE */
X				s = DE;
X				a = (IY & 0xfff) + (s & 0xfff);
X				s += IY;
X				IY = s;
X				BCD = 0;
X				CARRY = s >> 16;
X				HALF_CARRY = a >> 12;
X			when 0x21:		/* LD IY, nn */
X				IYL = ram[PC++];
X				IYH = ram[PC++];
X			when 0x22:		/* LD (nn), IY) */
X				TEMPL = ram[PC++];
X				TEMPH = ram[PC++];
X				ram[TEMP] = IYL;
X				ram[TEMP + 1] = IYH;
X			when 0x23:		/* INC IY */
X				IY++;
X			when 0x29:		/* ADD IY, IY */
X				s = IY;
X				a = (IY & 0xfff) + (s & 0xfff);
X				s += IY;
X				IY = s;
X				BCD = 0;
X				CARRY = s >> 16;
X				HALF_CARRY = a >> 12;
X			when 0x2a:		/* LD IY, (nn) */
X				TEMPL = ram[PC++];
X				TEMPH = ram[PC++];
X				IYL = ram[TEMP];
X				IYH = ram[TEMP + 1];
X			when 0x2b:		/* DEC IY */
X				IY--;
X			when 0x34:		/* INC (IY + d) */
X				ptr = ram + IY + ram[PC++];
X				HALF_CARRY = lonyb(*ptr) == 0xf;
X				++(*ptr);
X				SIGN = *ptr >> 7;
X				ZERO = *ptr == 0;
X				PARITY = *ptr == 0x80;
X				BCD = 0;
X			when 0x35:		/* DEC (IY + d) */
X				ptr = ram + IY + ram[PC++];
X				HALF_CARRY = lonyb(*ptr) != 0;
X				--(*ptr);
X				SIGN = *ptr >> 7;
X				ZERO = *ptr == 0;
X				PARITY = *ptr == 0x7f;
X				BCD = 1;
X			when 0x36:		/* LD (IY + d), n */
X				TEMP = IY + ram[PC++];
X				ram[TEMP] = ram[PC++];
X			when 0x39:		/* ADD IY, SP */
X				s = SP;
X				a = (IY & 0xfff) + (s & 0xfff);
X				s += IY;
X				IY = s;
X				BCD = 0;
X				CARRY = s >> 16;
X				HALF_CARRY = a >> 12;
X			when 0x46:		/* LD B, (IY + d) */
X				B = ram[IY + ram[PC++]];
X			when 0x4e:		/* LD C, (IY + d) */
X				C = ram[IY + ram[PC++]];
X			when 0x56:		/* LD D, (IY + d) */
X				D = ram[IY + ram[PC++]];
X			when 0x5e:		/* LD E, (IY + d) */
X				E = ram[IY + ram[PC++]];
X			when 0x66:		/* LD H, (IY + d) */
X				H = ram[IY + ram[PC++]];
X			when 0x6e:		/* LD L, (IY + d) */
X				L = ram[IY + ram[PC++]];
X			when 0x70:		/* LD (IY + d, B */
X				ram[IY + ram[PC++]] = B;
X			when 0x71:		/* LD (IY + d, C */
X				ram[IY + ram[PC++]] = C;
X			when 0x72:		/* LD (IY + d, D */
X				ram[IY + ram[PC++]] = D;
X			when 0x73:		/* LD (IY + d, E */
X				ram[IY + ram[PC++]] = E;
X			when 0x74:		/* LD (IY + d, H */
X				ram[IY + ram[PC++]] = H;
X			when 0x75:		/* LD (IY + d, L */
X				ram[IY + ram[PC++]] = L;
X			when 0x77:		/* LD (IY + d, A */
X				ram[IY + ram[PC++]] = A;
X			when 0x7e:		/* LD A, (IY + d) */
X				A = ram[IY + ram[PC++]];
X			when 0x86:		/* ADD A, (IY + d) */
X				s = ram[IY + ram[PC++]];
X				goto add;
X			when 0x8e:		/* ADC A, (IY + d) */
X				s = ram[IY + ram[PC++]];
X				goto adc;
X			when 0x96:		/* SUB A, (IY + d) */
X				s = ram[IY + ram[PC++]];
X				goto sub;
X			when 0x9e:		/* SBC A, (IY + d) */
X				s = ram[IY + ram[PC++]];
X				goto sbc;
X			when 0xa6:		/* AND A, (IY + d) */
X				s = ram[IY + ram[PC++]];
X				goto and;
X			when 0xae:		/* XOR A, (IY + d) */
X				s = ram[IY + ram[PC++]];
X				goto xor;
X			when 0xb6:		/* OR A, (IY + d) */
X				s = ram[IY + ram[PC++]];
X				goto or;
X			when 0xbe:		/* CP A, (IY + d) */
X				s = ram[IY + ram[PC++]];
X				goto cp;
X			when 0xcb:
X				ptr = ram + IY + ram[PC++];
X				goto cb_stuff;
X			when 0xe1:		/* POP IY */
X				IY = pop();
X			when 0xe3:		/* EX (SP), IY */
X				s = IY;
X				IY = pop();
X				push(s);
X			when 0xe5:		/* PUSH IY */
X				push(IY);
X			when 0xe9:		/* JP (IY) */
X				PC = IY;
X			when 0xf9:		/* LD SP, IY */
X				SP = IY;
X			break; default: return(-1);
X		}
X	when 254:		/* fe CP n */
X		s = ram[PC++];
X		goto cp;
X	when 255:		/* ff RST 38 */
X		push(PC);
X		PC = 0x38;
X	default: return(-1);
X	}
X
X	return(0);
}
SHAR_EOF
chmod 0640 decode.c ||
echo 'restore of decode.c failed'
Wc_c="`wc -c < 'decode.c'`"
test 32025 -eq "$Wc_c" ||
	echo 'decode.c: original size 32025, current size' "$Wc_c"
# ============= mk_tests.c ==============
sed 's/^X//' << 'SHAR_EOF' > 'mk_tests.c' &&
#include	<stdio.h>
#include	<unistd.h>
X
unsigned char	prg[] = { 0x00, 0x00, 0x00, 0xc3, 0x00, 0x00, 0x00 };
X
void	main(void)
{
X	int		k;
X	char	fn[16];
X	FILE	*fp;
X
X	for (k = 0; k < 256; k++)
X	{
X		sprintf(fn, "%02.2X.COM", k);
X
X		if ((fp = fopen(fn, "wb")) == NULL)
X		{
X			perror("Can't open file");
X			exit(0);
X		}
X
X		*prg = k;
X		fwrite(prg, sizeof(prg), 1, fp);
X		fclose(fp);
X	}
}
X
SHAR_EOF
chmod 0640 mk_tests.c ||
echo 'restore of mk_tests.c failed'
Wc_c="`wc -c < 'mk_tests.c'`"
test 381 -eq "$Wc_c" ||
	echo 'mk_tests.c: original size 381, current size' "$Wc_c"
# ============= mkbin.c ==============
sed 's/^X//' << 'SHAR_EOF' > 'mkbin.c' &&
#include	<stdio.h>
#include	<unistd.h>
X
main()
{
X	char	entry[32];
X
X	while (*gets(entry))
X		putchar(strtol(entry, NULL, 0));
}
X
SHAR_EOF
chmod 0640 mkbin.c ||
echo 'restore of mkbin.c failed'
Wc_c="`wc -c < 'mkbin.c'`"
test 127 -eq "$Wc_c" ||
	echo 'mkbin.c: original size 127, current size' "$Wc_c"
rm -f _shar_seq_.tmp
echo You have unpacked the last part
exit 0
-- 
D'Arcy J.M. Cain (darcy at druid)     |
D'Arcy Cain Consulting             |   There's no government
West Hill, Ontario, Canada         |   like no government!
+1 416 281 6094                    |



More information about the Alt.sources mailing list