~rabbits/gyo

70ecb52788bcb23a0a90bdc9d7b7a4b964d6f86e — neauoire 1 year, 27 days ago 247ff76 master
Added helper in gyoasm
2 files changed, 15 insertions(+), 6 deletions(-)

M src/gyoasm.c
M src/gyoemu.c
M src/gyoasm.c => src/gyoasm.c +14 -5
@@ 76,6 76,15 @@ makelabel(char *name, int ptr)
	return 1;
}

static int
needlabel(char *name)
{
	Label *l = findlabel(name);
	if(!l)
		error("Missing label", name);
	return l->addr;
}

static uc15
asmtoken(char *token)
{


@@ 83,12 92,12 @@ asmtoken(char *token)
	Label *l;
	uc15 opc;
	/* word */
	if((l = findlabel(token))) return (intuc15(l->addr) << 4) | (BCZ << 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 '?': /* JCN */ return (l = findlabel(token + 1)) ? (intuc15(l->addr) << 4) | (BCP << 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 '#': /* LIT */ return hepuc15(token) << 2 | BCP;
	case '?': /* JCN */ return intuc15(needlabel(token + 1)) << 4 | BCP << 2 | BCZ;
	case '>': /* JMP */ return intuc15(needlabel(token + 1)) << 4 | BCN << 2 | BCZ;
	}
	/* opcode */
	opc = hepuc15("00MIL") | BCN; // 00 00 00 00 00 00 01 01 01 01 00 00 01 01 00


@@ 163,7 172,7 @@ main(int argc, char **argv)
{
	FILE *src, *dst;
	if(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v')
		return !fprintf(stdout, "Gyoasm - Gyo Assembler, 7 Nov 2023.\n");
		return !fprintf(stdout, "Gyoasm - Gyo Assembler, 9 Nov 2023.\n");
	if(argc != 3)
		return error("usage", "gyoasm [-v] input.gyo output.rom");
	if(!(src = fopen(argv[1], "r")))

M src/gyoemu.c => src/gyoemu.c +1 -1
@@ 149,7 149,7 @@ main(int argc, char **argv)
		return emu_error("usage", "gyoemu [-v] file.rom");
	/* Read flags */
	if(argv[i][0] == '-' && argv[i][1] == 'v')
		return emu_error("Gyoemu - Terminal Gyo Emulator", "7 Nov 2023");
		return emu_error("Gyoemu - Terminal Gyo Emulator", "9 Nov 2023");
	if(!emu_init())
		return emu_error("Init", "Failed to initialize Gyoemu.");
	if(!emu_load(ROM, argv[i++]))