diff trans.c @ 18:3e7bfde7606e

M68K to x86 translation works for a limited subset of instructions and addressing modes
author Mike Pavone <pavone@retrodev.com>
date Tue, 04 Dec 2012 19:13:12 -0800
parents
children 4717146a7606
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/trans.c	Tue Dec 04 19:13:12 2012 -0800
@@ -0,0 +1,39 @@
+#include "68kinst.h"
+#include "m68k_to_x86.h"
+#include "mem.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char ** argv)
+{
+	long filesize;
+	unsigned short *filebuf;
+	char disbuf[1024];
+	size_t size = 1024 * 1024;
+	uint8_t * transbuf = alloc_code(&size);
+	uint8_t *trans_cur, *end;
+	unsigned short * cur;
+	x86_68k_options opts;
+	m68k_context context;
+	FILE * f = fopen(argv[1], "rb");
+	fseek(f, 0, SEEK_END);
+	filesize = ftell(f);
+	fseek(f, 0, SEEK_SET);
+	filebuf = malloc(filesize);
+	fread(filebuf, 2, filesize/2, f);
+	fclose(f);
+	for(cur = filebuf; cur - filebuf < (filesize/2); ++cur)
+	{
+		*cur = (*cur >> 8) | (*cur << 8);
+	}
+	init_x86_68k_opts(&opts);
+	init_68k_context(&context, opts.native_code_map, &opts);
+	//cartridge ROM
+	context.mem_pointers[0] = filebuf;
+	context.target_cycle = 0x7FFFFFFF;
+	//work RAM
+	context.mem_pointers[1] = malloc(64 * 1024);
+	translate_m68k_stream(transbuf, transbuf + size, 0, &context);
+	start_68k_context(&context, 0);
+	return 0;
+}