~rabbits/gyo

f7584eb23534151d5554a61bca3c51c39e4fe05d — neauoire 1 year, 27 days ago c0edd3e
LIT & JMP opcodes take balanced ternary flags
3 files changed, 10 insertions(+), 10 deletions(-)

M src/gyo.c
M src/gyoasm.c
M src/gyoemu.c
M src/gyo.c => src/gyo.c +3 -3
@@ 26,9 26,9 @@ gyo_eval(uc15 *rom, uc3 *ram, uc15 pc)
		case BCZ:
			/* JSR,JCN,JMP */
			switch((inst >> 2) & 0x3) {
			case 0: rst[++rsp] = pc, pc = inst >> 0x4; break;
			case 1: pc = dst[dsp--] & 0x2 ? (inst >> 0x4) : pc; break;
			case 2: pc = inst >> 0x4; break;
			case BCZ: rst[++rsp] = pc, pc = inst >> 0x4; break;
			case BCP: pc = dst[dsp--] & 0x2 ? (inst >> 0x4) : pc; break;
			case BCN: pc = inst >> 0x4; break;
			}
			break;
		/* OPC */

M src/gyoasm.c => src/gyoasm.c +4 -4
@@ 83,12 83,12 @@ asmtoken(char *token)
	Label *l;
	uc15 opc;
	/* word */
	if((l = findlabel(token))) return (intuc15(l->addr) << 4) | (0 << 2) | BCZ;
	if((l = findlabel(token))) return (intuc15(l->addr) << 4) | (BCZ << 2) | BCZ;
	/* jump */
	switch(token[0]) {
	case '#': /* LIT */ return (hepuc15(token) << 2) | BCP;
	case '>': /* JMP */ return (l = findlabel(token + 1)) ? (intuc15(l->addr) << 4) | (2 << 2) | BCZ : error("Missing label", token);
	case '?': /* JCN */ return (l = findlabel(token + 1)) ? (intuc15(l->addr) << 4) | (1 << 2) | BCZ : error("Missing label", token);
	case '>': /* JMP */ return (l = findlabel(token + 1)) ? (intuc15(l->addr) << 4) | (BCN << 2) | BCZ : error("Missing label", token);
	case '?': /* JCN */ return (l = findlabel(token + 1)) ? (intuc15(l->addr) << 4) | (BCP << 2) | BCZ : error("Missing label", token);
	}
	/* opcode */
	opc = hepuc15("00MIL") | BCN; // 00 00 00 00 00 00 01 01 01 01 00 00 01 01 00


@@ 154,7 154,7 @@ assemble(FILE *f)
	}
	if(!(main = findlabel("main")))
		return error("Missing label", "main");
	rom[0] = (intuc15(main->addr) << 4) | 0x8 | BCZ;
	rom[0] = (intuc15(main->addr) << 4) | (BCN << 2) | BCZ;
	return 1;
}


M src/gyoemu.c => src/gyoemu.c +3 -3
@@ 35,9 35,9 @@ void
disjmp(uc15 inst)
{
	switch((inst >> 2) & 0x3) {
	case 0: /* JCN */ putchar('?'), phep(inst >> 4, 5); return;
	case 1: /* JMP */ putchar('>'), phep(inst >> 4, 5); return;
	case 2: /* JSR */ putchar(':'), phep(inst >> 4, 5); return;
	case BCZ: /* JCN */ putchar('?'), phep(inst >> 4, 5); return;
	case BCP: /* JMP */ putchar('>'), phep(inst >> 4, 5); return;
	case BCN: /* JSR */ putchar(':'), phep(inst >> 4, 5); return;
	}
}