changeset 741:80a67be1770b

Initial work on Windows port
author Michael Pavone <pavone@retrodev.com>
date Tue, 01 Apr 2014 19:43:58 -0700
parents 2dde38c1744f
children 2e1b3b258523
files Makefile config.c mem_win.c render.h runtime_win.S util.c
diffstat 6 files changed, 155 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Tue Mar 11 09:44:47 2014 -0700
+++ b/Makefile	Tue Apr 01 19:43:58 2014 -0700
@@ -1,3 +1,21 @@
+
+ifdef WINDOWS
+
+MEM:=mem_win.o
+BLASTEM:=blastem.exe
+RUNTIME32:=runtime_win.S
+
+CC:=wine gcc.exe
+CFLAGS:=-O2 -std=gnu99 -Wreturn-type -Werror=return-type -Werror=implicit-function-declaration -DDISABLE_OPENGL -I"C:/MinGW/usr/include/SDL"
+LDFLAGS:= -L"C:/MinGW/usr/lib" -lm -lmingw32 -lSDLmain -lSDL -mwindows
+CPU:=i686
+
+else
+
+MEM:=mem.o
+BLASTEM:=blastem
+RUNTIME32:=runtime_32.S
+
 ifdef NOGL
 LIBS=sdl
 else
@@ -22,17 +40,17 @@
 ifndef CPU
 CPU:=$(shell uname -m)
 endif
+endif
 
 
-
-TRANSOBJS=gen.o backend.o mem.o
+TRANSOBJS=gen.o backend.o $(MEM)
 M68KOBJS=68kinst.o m68k_core.o
 ifeq ($(CPU),x86_64)
 M68KOBJS+= runtime.o m68k_core_x86.o
 TRANSOBJS+= gen_x86.o backend_x86.o
 else
 ifeq ($(CPU),i686)
-M68KOBJS+= runtime_32.o m68k_core_x86.o
+M68KOBJS+= $(RUNTIME32) m68k_core_x86.o
 TRANSOBJS+= gen_x86.o backend_x86.o
 NOZ80:=1
 endif
@@ -61,8 +79,8 @@
 
 all : dis zdis stateview vgmplay blastem
 
-blastem : $(MAINOBJS)
-	$(CC) -o blastem $(MAINOBJS) $(LDFLAGS)
+$(BLASTEM) : $(MAINOBJS)
+	$(CC) -o $(BLASTEM) $(MAINOBJS) $(LDFLAGS)
 
 dis : dis.o 68kinst.o
 	$(CC) -o dis dis.o 68kinst.o
--- a/config.c	Tue Mar 11 09:44:47 2014 -0700
+++ b/config.c	Tue Apr 01 19:43:58 2014 -0700
@@ -11,6 +11,27 @@
 
 #define MAX_NEST 30 //way more than I'll ever need
 
+#ifdef _WIN32
+char * strtok_r(char * input, char * sep, char ** state)
+{
+	if (input) {
+		*state = input;
+	}
+	char * ret = *state;
+	while (**state && **state != *sep)
+	{
+		++*state;
+	}
+	if (**state)
+	{
+		**state = 0;
+		++*state;
+		return ret;
+	}
+	return NULL;
+}
+#endif
+
 tern_node * parse_config(char * config_data)
 {
 	char *state, *curline;
@@ -100,6 +121,9 @@
 
 tern_node * load_config()
 {
+#ifdef _WIN32
+	tern_node * ret = parse_config_file("default.cfg");
+#else
 	char * exe_dir;
 	char * home = getenv("HOME");
 	if (!home) {
@@ -119,6 +143,7 @@
 	path = alloc_concat(exe_dir, "/default.cfg");
 	ret = parse_config_file(path);
 	free(path);
+#endif
 success:
 	if (ret) {
 		return ret;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mem_win.c	Tue Apr 01 19:43:58 2014 -0700
@@ -0,0 +1,15 @@
+/*
+ Copyright 2013 Michael Pavone
+ This file is part of BlastEm.
+ BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
+*/
+
+#include "mem.h"
+#include <Windows.h>
+
+void * alloc_code(size_t *size)
+{
+	*size += PAGE_SIZE - (*size & (PAGE_SIZE - 1));
+
+	return VirtualAlloc(NULL, *size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
+}
--- a/render.h	Tue Mar 11 09:44:47 2014 -0700
+++ b/render.h	Tue Apr 01 19:43:58 2014 -0700
@@ -6,6 +6,22 @@
 #ifndef RENDER_H_
 #define RENDER_H_
 
+//TODO: Throw an ifdef in here once there's more than one renderer
+#include <SDL.h>
+#define RENDERKEY_UP      SDLK_UP
+#define RENDERKEY_DOWN    SDLK_DOWN
+#define RENDERKEY_LEFT    SDLK_LEFT
+#define RENDERKEY_RIGHT   SDLK_RIGHT
+#define RENDERKEY_ESC     SDLK_ESCAPE
+#define RENDERKEY_LSHIFT  SDLK_LSHIFT
+#define RENDERKEY_RSHIFT  SDLK_RSHIFT
+#define RENDER_DPAD_UP    SDL_HAT_UP
+#define RENDER_DPAD_DOWN  SDL_HAT_DOWN
+#define RENDER_DPAD_LEFT  SDL_HAT_LEFT
+#define RENDER_DPAD_RIGHT SDL_HAT_RIGHT
+
+#define MAX_JOYSTICKS 8
+
 #include "vdp.h"
 #include "psg.h"
 #include "ym2612.h"
@@ -35,21 +51,7 @@
 int render_joystick_num_hats(int joystick);
 int render_num_joysticks();
 
-//TODO: Throw an ifdef in here once there's more than one renderer
-#include <SDL.h>
-#define RENDERKEY_UP      SDLK_UP
-#define RENDERKEY_DOWN    SDLK_DOWN
-#define RENDERKEY_LEFT    SDLK_LEFT
-#define RENDERKEY_RIGHT   SDLK_RIGHT
-#define RENDERKEY_ESC     SDLK_ESCAPE
-#define RENDERKEY_LSHIFT  SDLK_LSHIFT
-#define RENDERKEY_RSHIFT  SDLK_RSHIFT
-#define RENDER_DPAD_UP    SDL_HAT_UP
-#define RENDER_DPAD_DOWN  SDL_HAT_DOWN
-#define RENDER_DPAD_LEFT  SDL_HAT_LEFT
-#define RENDER_DPAD_RIGHT SDL_HAT_RIGHT
 
-#define MAX_JOYSTICKS 8
 
 #endif //RENDER_H_
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/runtime_win.S	Tue Apr 01 19:43:58 2014 -0700
@@ -0,0 +1,74 @@
+
+
+invalid_msg:
+	.asciz "Invalid instruction at %X\n"
+
+	.global _m68k_invalid
+_m68k_invalid:
+	push %ecx
+	push invalid_msg
+	xor %eax, %eax
+	call _printf
+	push $1
+	call _exit
+
+	.global _bcd_add
+_bcd_add:
+	xchg %eax, %edi
+
+	mov %cl, %ch
+	mov %al, %ah
+	and $0xF, %ch
+	and $0xF, %ah
+	and $0xF0, %cl
+	and $0xF0, %al
+	add %ah, %ch
+	cmp $10, %ch
+	jb no_adjust
+	add $6, %ch
+no_adjust:
+	add %ch, %al
+	add %al, %cl
+	mov $0, %ch
+	jc def_adjust
+	cmp $0xA0, %cl
+	jb no_adjust_h
+def_adjust:
+	add $0x60, %cl
+	mov $1, %ch
+no_adjust_h:
+
+	mov %edi, %eax
+	ret
+
+	.global _bcd_sub
+_bcd_sub:
+	xchg %eax, %edi
+
+	mov %cl, %ch
+	mov %al, %ah
+	and $0xF, %ch
+	and $0xF, %ah
+	and $0xF0, %cl
+	and $0xF0, %al
+	sub %ah, %ch
+	cmp $10, %ch
+	jb no_adjusts
+	sub $6, %ch
+no_adjusts:
+	add %ch, %cl
+	sub %al, %cl
+	mov $0, %ch
+	jc def_adjusts
+	cmp $0xA0, %cl
+	jb no_adjust_hs
+def_adjusts:
+	sub $0x60, %cl
+	mov $1, %ch
+no_adjust_hs:
+
+	mov %edi, %eax
+	ret
+
+
+
--- a/util.c	Tue Mar 11 09:44:47 2014 -0700
+++ b/util.c	Tue Apr 01 19:43:58 2014 -0700
@@ -75,6 +75,7 @@
 	exe_str = str;
 }
 
+#ifndef _WIN32
 char * readlink_alloc(char * path)
 {
 	char * linktext = NULL;
@@ -138,3 +139,4 @@
 	}
 	return exe_dir;
 }
+#endif