changeset 1094:1dba006bad47

Get Jaguar disassembler more or less working. Dump gpu program to file when GPU GO bit is set
author Michael Pavone <pavone@retrodev.com>
date Mon, 31 Oct 2016 09:23:25 -0700
parents 4987fddd42a0
children 920d796ea6a2
files jagcpu.c jaguar.c
diffstat 2 files changed, 16 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/jagcpu.c	Sun Oct 30 19:42:48 2016 -0700
+++ b/jagcpu.c	Mon Oct 31 09:23:25 2016 -0700
@@ -95,7 +95,7 @@
 
 uint16_t jag_opcode(uint16_t inst, uint8_t is_gpu)
 {
-	uint16_t opcode = inst >> 11;
+	uint16_t opcode = inst >> 10;
 	if (is_gpu && opcode == GPU_PACK && (inst & 0x20)) {
 		return GPU_UNPACK;
 	}
@@ -188,13 +188,13 @@
 	if (rel & 0x10) {
 		rel |= 0xFFFFFFE0;
 	}
-	return address + 2 + rel;
+	return address + 2 + rel*2;
 }
 
 int jag_cpu_disasm(uint16_t **stream, uint32_t address, char *dst, uint8_t is_gpu, uint8_t labels)
 {
 	uint16_t inst = **stream;
-	*stream++;
+	(*stream)++;
 	uint16_t opcode = jag_opcode(inst, is_gpu);
 	char **mnemonics;
 	if (is_gpu) {
@@ -207,25 +207,25 @@
 	{
 	case JAG_MOVEI: {
 		uint32_t immed = **stream;
-		*stream++;
+		(*stream)++;
 		immed |= **stream << 16;
-		*stream++;
-		return sprintf("%s $%X, r%d", mnemonics[opcode], immed, jag_reg2(inst));
+		(*stream)++;
+		return sprintf(dst, "%s $%X, r%d", mnemonics[opcode], immed, jag_reg2(inst));
 	}
 	case JAG_JR:
-		return sprintf(
+		return sprintf(dst,
 			labels ? "%s %s, ADR_%X" : "%s %s, $W%X",
 			mnemonics[opcode], jag_cc(inst), jag_jr_dest(inst, address)
 		);
 	case JAG_JUMP:
-		return sprintf("%s %s, (r%d)", mnemonics[opcode], jag_cc(inst), jag_reg1(inst));
+		return sprintf(dst, "%s %s, (r%d)", mnemonics[opcode], jag_cc(inst), jag_reg1(inst));
 	default:
 		if (is_quick_1_32_opcode(opcode, is_gpu)) {
-			return sprintf("%s %d, r%d", mnemonics[opcode], jag_quick(inst), jag_reg2(inst));
+			return sprintf(dst, "%s %d, r%d", mnemonics[opcode], jag_quick(inst), jag_reg2(inst));
 		} else if (is_quick_0_31_opcode(opcode)) {
-			return sprintf("%s %d, r%d", mnemonics[opcode], jag_reg1(inst), jag_reg2(inst));
+			return sprintf(dst, "%s %d, r%d", mnemonics[opcode], jag_reg1(inst), jag_reg2(inst));
 		} else {
-			return sprintf("%s r%d, r%d", mnemonics[opcode], jag_reg1(inst), jag_reg2(inst));
+			return sprintf(dst, "%s r%d, r%d", mnemonics[opcode], jag_reg1(inst), jag_reg2(inst));
 		}
 	}
 }
--- a/jaguar.c	Sun Oct 30 19:42:48 2016 -0700
+++ b/jaguar.c	Mon Oct 31 09:23:25 2016 -0700
@@ -142,6 +142,11 @@
 			//GPU/Blitter registers
 			if (address < 0x102200) {
 				fprintf(stderr, "Unhandled write to GPU registers %X: %X\n", address, value);
+				if (address == 0x102116 && (value & 1)) {
+					FILE *f = fopen("gpu.bin", "wb");
+					fwrite(system->gpu_local, 1, sizeof(system->gpu_local), f);
+					fclose(f);
+				}
 			} else {
 				fprintf(stderr, "Unhandled write to Blitter registers %X: %X\n", address, value);
 			}