changeset 559:6b248602ab84

blastem builds and almost works on OS X now
author Mike Pavone <pavone@retrodev.com>
date Tue, 17 Jun 2014 01:50:29 -0400
parents dc9f178085a0
children f9431cb3a39c
files Makefile blastem.c m68k_to_x86.c runtime.S util.c z80_to_x86.c z80_to_x86.h zruntime.S
diffstat 8 files changed, 51 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Mon Feb 24 01:30:16 2014 -0800
+++ b/Makefile	Tue Jun 17 01:50:29 2014 -0400
@@ -1,8 +1,17 @@
+ifndef OS
+OS:=$(shell uname -s)
+endif
+
 ifdef NOGL
 LIBS=sdl
 else
+ifeq ($(OS),Darwin)
+LIBS=sdl glew
+else
 LIBS=sdl glew gl
 endif
+endif
+
 LDFLAGS:=-lm $(shell pkg-config --libs $(LIBS))
 ifdef DEBUG
 CFLAGS:=-ggdb -std=gnu99 $(shell pkg-config --cflags-only-I $(LIBS)) -Wreturn-type -Werror=return-type
@@ -22,7 +31,9 @@
 CPU:=$(shell uname -m)
 endif
 
-
+ifeq ($(OS),Darwin)
+LDFLAGS+= -framework OpenGL
+endif
 
 TRANSOBJS=gen_x86.o backend.o mem.o
 M68KOBJS=68kinst.o m68k_to_x86.o
--- a/blastem.c	Mon Feb 24 01:30:16 2014 -0800
+++ b/blastem.c	Tue Jun 17 01:50:29 2014 -0400
@@ -383,6 +383,7 @@
 	return vdp_port_write(vdp_port, context, vdp_port < 0x10 ? value | value << 8 : ((vdp_port & 1) ? value : 0));
 }
 
+z80_context * z80_vdp_port_write(uint16_t vdp_port, z80_context * context, uint8_t value) asm("z80_vdp_port_write");
 z80_context * z80_vdp_port_write(uint16_t vdp_port, z80_context * context, uint8_t value)
 {
 	genesis_context * gen = context->system;
@@ -674,6 +675,7 @@
 	return value;
 }
 
+extern z80_context * z80_write_ym(uint16_t location, z80_context * context, uint8_t value) asm("z80_write_ym");
 z80_context * z80_write_ym(uint16_t location, z80_context * context, uint8_t value)
 {
 	genesis_context * gen = context->system;
@@ -688,6 +690,7 @@
 	return context;
 }
 
+extern uint8_t z80_read_ym(uint16_t location, z80_context * context) asm("z80_read_ym");
 uint8_t z80_read_ym(uint16_t location, z80_context * context)
 {
 	genesis_context * gen = context->system;
--- a/m68k_to_x86.c	Mon Feb 24 01:30:16 2014 -0800
+++ b/m68k_to_x86.c	Tue Jun 17 01:50:29 2014 -0400
@@ -39,9 +39,14 @@
 
 m68k_context * sync_components(m68k_context * context, uint32_t address);
 
-void m68k_invalid();
-void bcd_add();
-void bcd_sub();
+extern void bcd_add() asm("bcd_add");
+extern void bcd_sub() asm("bcd_sub");
+
+void m68k_invalid(uint32_t address, m68k_context * context)
+{
+	printf("Invalid instruction at %X\n", address);
+	exit(1);
+}
 
 code_ptr cycles(code_ptr dst, uint32_t num)
 {
@@ -2864,7 +2869,11 @@
 		if (inst->src.params.immed == 0x7100) {
 			return retn(dst);
 		}
-		dst = mov_ir(dst, inst->address, SCRATCH1, SZ_D);
+		dst = mov_ir(dst, inst->address, SCRATCH2, SZ_D);
+#ifdef X86_32
+		dst = push_r(dst, CONTEXT);
+		dst = push_r(dst, SCRATCH2);
+#endif
 		return call(dst, (code_ptr)m68k_invalid);
 	} else if(inst->op == M68K_CMP) {
 		return translate_m68k_cmp(dst, inst, opts);
--- a/runtime.S	Mon Feb 24 01:30:16 2014 -0800
+++ b/runtime.S	Tue Jun 17 01:50:29 2014 -0400
@@ -1,17 +1,5 @@
 
 
-invalid_msg:
-	.asciz "Invalid instruction at %X\n"
-
-	.global m68k_invalid
-m68k_invalid:
-	lea invalid_msg(%rip), %rdi
-	mov %ecx, %esi
-	xor %rax, %rax
-	call printf
-	mov $1, %rdi
-	call exit
-
 	.global bcd_add
 bcd_add:
 	xchg %rax, %rdi
--- a/util.c	Mon Feb 24 01:30:16 2014 -0800
+++ b/util.c	Tue Jun 17 01:50:29 2014 -0400
@@ -92,7 +92,7 @@
 		if (linksize == -1) {
 			perror("readlink");
 			free(linktext);
-			linktext = NULL;
+			return NULL;
 		}
 	} while ((linksize+1) > cursize);
 	linktext[linksize] = 0;
--- a/z80_to_x86.c	Mon Feb 24 01:30:16 2014 -0800
+++ b/z80_to_x86.c	Tue Jun 17 01:50:29 2014 -0400
@@ -28,21 +28,21 @@
 #define dprintf
 #endif
 
-void z80_read_byte();
-void z80_read_word();
-void z80_write_byte();
-void z80_write_word_highfirst();
-void z80_write_word_lowfirst();
-void z80_save_context();
-void z80_native_addr();
-void z80_do_sync();
-void z80_handle_cycle_limit_int();
-void z80_retrans_stub();
-void z80_io_read();
-void z80_io_write();
-void z80_halt();
-void z80_save_context();
-void z80_load_context();
+extern void z80_read_byte() asm("z80_read_byte");
+extern void z80_read_word() asm("z80_read_word");
+extern void z80_write_byte() asm("z80_write_byte");
+extern void z80_write_word_highfirst() asm("z80_write_word_highfirst");
+extern void z80_write_word_lowfirst() asm("z80_write_word_lowfirst");
+extern void z80_save_context() asm("z80_save_context");
+extern void z80_native_addr() asm("z80_native_addr");
+extern void z80_do_sync() asm("z80_do_sync");
+extern void z80_handle_cycle_limit_int() asm("z80_handle_cycle_limit_int");
+extern void z80_retrans_stub() asm("z80_retrans_stub");
+extern void z80_io_read() asm("z80_io_read");
+extern void z80_io_write() asm("z80_io_write");
+extern void z80_halt() asm("z80_halt");
+extern void z80_save_context() asm("z80_save_context");
+extern void z80_load_context() asm("z80_load_context");
 
 uint8_t z80_size(z80inst * inst)
 {
@@ -1780,6 +1780,7 @@
 	}
 }
 
+extern void * z80_retranslate_inst(uint32_t address, z80_context * context, uint8_t * orig_start) asm("z80_retranslate_inst");
 void * z80_retranslate_inst(uint32_t address, z80_context * context, uint8_t * orig_start)
 {
 	char disbuf[80];
--- a/z80_to_x86.h	Mon Feb 24 01:30:16 2014 -0800
+++ b/z80_to_x86.h	Tue Jun 17 01:50:29 2014 -0400
@@ -62,9 +62,9 @@
 void init_x86_z80_opts(x86_z80_options * options);
 void init_z80_context(z80_context * context, x86_z80_options * options);
 uint8_t * z80_get_native_address(z80_context * context, uint32_t address);
-uint8_t * z80_get_native_address_trans(z80_context * context, uint32_t address);
-z80_context * z80_handle_code_write(uint32_t address, z80_context * context);
-void z80_run(z80_context * context);
+extern uint8_t * z80_get_native_address_trans(z80_context * context, uint32_t address) asm("z80_get_native_address_trans");
+z80_context * z80_handle_code_write(uint32_t address, z80_context * context) asm("z80_handle_code_write");
+extern void z80_run(z80_context * context) asm("z80_run");
 void z80_reset(z80_context * context);
 void zinsert_breakpoint(z80_context * context, uint16_t address, uint8_t * bp_handler);
 void zremove_breakpoint(z80_context * context, uint16_t address);
--- a/zruntime.S	Mon Feb 24 01:30:16 2014 -0800
+++ b/zruntime.S	Tue Jun 17 01:50:29 2014 -0400
@@ -125,7 +125,7 @@
 	add $3, %ebp
 	push %rsi
 	mov 144(%rsi), %rsi /* get system context pointer */
-	cmp $0, 120(%rsi) /* check bus busy flag */
+	cmpb $0, 120(%rsi) /* check bus busy flag */
 	pop %rsi
 	jne bus_busy
 z80_read_bank_cont:
@@ -243,7 +243,7 @@
 	add $3, %ebp /* first read typically has 3 wait states */
 	push %rsi
 	mov 144(%rsi), %rsi /* get system context pointer */
-	cmp $0, 120(%rsi) /* check bus busy flag */
+	cmpb $0, 120(%rsi) /* check bus busy flag */
 	pop %rsi
 	jne bus_busy_word
 z80_read_bank_word_cont:
@@ -256,7 +256,7 @@
 	add $4, %ebp /* second read typically has 4 wait states */
 	push %rsi
 	mov 144(%rsi), %rsi /* get system context pointer */
-	cmp $0, 120(%rsi) /* check bus busy flag */
+	cmpb $0, 120(%rsi) /* check bus busy flag */
 	pop %rsi
 	jne bus_busy_word2
 z80_read_bank_word_cont2: