summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile30
-rw-r--r--config.c23
-rw-r--r--mem_win.c15
-rw-r--r--render.h30
-rw-r--r--runtime_win.S74
-rw-r--r--util.c37
-rw-r--r--util.h2
7 files changed, 191 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index ca09d69..b3e966b 100644
--- a/Makefile
+++ b/Makefile
@@ -2,19 +2,36 @@ ifndef OS
OS:=$(shell uname -s)
endif
+ifeq ($(OS),Windows)
+CC:=wine gcc.exe
+
+MEM:=mem_win.o
+BLASTEM:=blastem.exe
+
+CC:=wine gcc.exe
+CFLAGS:=-O2 -std=gnu99 -Wreturn-type -Werror=return-type -Werror=
+LDFLAGS:= -L"C:/MinGW/usr/lib" -lm -lmingw32 -lSDLmain -lSDL -mwindows
+CPU:=i686
+
+else
+
+MEM:=mem.o
+BLASTEM:=blastem
+
ifeq ($(OS),Darwin)
LIBS=sdl2 glew
else
LIBS=sdl2 glew gl
-endif
+endif #Darwin
-ifdef DEBUG
+ifdef DEBUGW
CFLAGS:=-ggdb -std=gnu99 $(shell pkg-config --cflags-only-I $(LIBS)) -Wreturn-type -Werror=return-type -Werror=implicit-function-declaration
LDFLAGS:=-ggdb -lm $(shell pkg-config --libs $(LIBS))
else
CFLAGS:=-O2 -flto -std=gnu99 $(shell pkg-config --cflags-only-I $(LIBS)) -Wreturn-type -Werror=return-type -Werror=implicit-function-declaration
LDFLAGS:=-O2 -flto -lm $(shell pkg-config --libs $(LIBS))
-endif
+endif #DEBUG
+endif #Windows
ifdef Z80_LOG_ADDRESS
CFLAGS+= -DZ80_LOG_ADDRESS
@@ -80,11 +97,14 @@ else
MAINOBJS+= $(Z80OBJS)
endif
+ifdef WINDOWS
+MAINOBJS+= glew32s.lib
+endif
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 tern.o vos_program_module.o
$(CC) -o dis dis.o 68kinst.o tern.o vos_program_module.o
diff --git a/config.c b/config.c
index d1efc87..eab0308 100644
--- a/config.c
+++ b/config.c
@@ -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;
@@ -101,7 +122,7 @@ open_fail:
tern_node * load_config()
{
char * exe_dir;
- char * home = getenv("HOME");
+ char * home = get_home_dir();
if (!home) {
goto load_in_app_dir;
}
diff --git a/mem_win.c b/mem_win.c
new file mode 100644
index 0000000..8a76712
--- /dev/null
+++ b/mem_win.c
@@ -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);
+}
diff --git a/render.h b/render.h
index 79f05ca..9445448 100644
--- a/render.h
+++ b/render.h
@@ -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();
void process_events();
-//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_
diff --git a/runtime_win.S b/runtime_win.S
new file mode 100644
index 0000000..c107030
--- /dev/null
+++ b/runtime_win.S
@@ -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
+
+
+
diff --git a/util.c b/util.c
index 5367cd5..fc95011 100644
--- a/util.c
+++ b/util.c
@@ -75,6 +75,41 @@ void set_exe_str(char * str)
exe_str = str;
}
+#ifdef _WIN32
+#include "Shlobj.h"
+#include "Windows.h"
+
+char * get_home_dir()
+{
+ static char path[MAX_PATH];
+ SHGetFolderPathA(NULL, CSIDL_PROFILE, NULL, 0, path);
+ return path;
+}
+
+char * get_exe_dir()
+{
+ static char path[MAX_PATH];
+ HMODULE module = GetModuleHandleA(NULL);
+ GetModuleFileNameA(module, path, MAX_PATH);
+
+ int pathsize = strlen(path);
+ for(char * cur = path + pathsize - 1; cur != path; cur--)
+ {
+ if (*cur == '\\') {
+ *cur = 0;
+ break;
+ }
+ }
+ return path;
+}
+
+#else
+
+char * get_home_dir()
+{
+ return getenv("HOME");
+}
+
char * readlink_alloc(char * path)
{
char * linktext = NULL;
@@ -138,3 +173,5 @@ fallback:
}
return exe_dir;
}
+
+#endif
diff --git a/util.h b/util.h
index d82ac50..780f538 100644
--- a/util.h
+++ b/util.h
@@ -19,6 +19,8 @@ char * split_keyval(char * text);
void set_exe_str(char * str);
//Returns the directory the executable is in
char * get_exe_dir();
+//Returns the user's home directory
+char * get_home_dir();
//Returns the contents of a symlink in a newly allocated string
char * readlink_alloc(char * path);