summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2015-05-28 23:05:32 -0700
committerMichael Pavone <pavone@retrodev.com>2015-05-28 23:05:32 -0700
commitd597043be9f8d1c22ac6a2365e5cbb9f82e7ea46 (patch)
tree131c7ea0f3ec03882bb8183a734f04c757918180
parent391656eca9eb35b7e3937b2af1316460d5639306 (diff)
parent66aedc9c1a87c8811be4dba263dbcd7ec026cc70 (diff)
Merge
-rw-r--r--Makefile32
-rw-r--r--config.c23
-rw-r--r--debug.c8
-rw-r--r--io.c15
-rw-r--r--mem_win.c15
-rw-r--r--render.h30
-rw-r--r--render_sdl.c3
-rw-r--r--runtime_win.S74
-rw-r--r--util.c37
-rw-r--r--util.h2
10 files changed, 215 insertions, 24 deletions
diff --git a/Makefile b/Makefile
index ca09d69..eed9d6d 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=implicit-function-declaration -I"C:/MinGW/usr/include/SDL2" -DGLEW_STATIC
+LDFLAGS:= -L"C:/MinGW/usr/lib" -lm -lmingw32 -lSDL2main -lSDL2 -lopengl32 -lglu32 -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
@@ -46,7 +63,7 @@ ifeq ($(OS),Darwin)
LDFLAGS+= -framework OpenGL
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+= m68k_core_x86.o
@@ -80,11 +97,14 @@ else
MAINOBJS+= $(Z80OBJS)
endif
+ifeq ($(OS),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/debug.c b/debug.c
index e121277..74e076b 100644
--- a/debug.c
+++ b/debug.c
@@ -3,7 +3,9 @@
#include "68kinst.h"
#include <stdlib.h>
#include <string.h>
+#ifndef _WIN32
#include <sys/select.h>
+#endif
#include "render.h"
static bp_def * breakpoints = NULL;
@@ -510,16 +512,21 @@ m68k_context * debugger(m68k_context * context, uint32_t address)
printf("%X: %s\n", address, input_buf);
uint32_t after = address + (after_pc-pc)*2;
int debugging = 1;
+#ifdef _WIN32
+#define prompt 1
+#else
int prompt = 1;
fd_set read_fds;
FD_ZERO(&read_fds);
struct timeval timeout;
+#endif
while (debugging) {
if (prompt) {
fputs(">", stdout);
fflush(stdout);
}
process_events();
+#ifndef _WIN32
timeout.tv_sec = 0;
timeout.tv_usec = 16667;
FD_SET(fileno(stdin), &read_fds);
@@ -529,6 +536,7 @@ m68k_context * debugger(m68k_context * context, uint32_t address)
} else {
prompt = 1;
}
+#endif
if (!fgets(input_buf, sizeof(input_buf), stdin)) {
fputs("fgets failed", stderr);
break;
diff --git a/io.c b/io.c
index d50133d..d6d55c7 100644
--- a/io.c
+++ b/io.c
@@ -3,6 +3,7 @@
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.
*/
+#ifndef _WIN32
#include <unistd.h>
#include <fcntl.h>
#include <sys/socket.h>
@@ -10,7 +11,9 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
+#endif
#include <string.h>
+#include <stdlib.h>
#include "io.h"
#include "blastem.h"
@@ -544,7 +547,7 @@ void setup_io_devices(tern_node * config, io_port * ports)
for (int i = 0; i < 3; i++)
{
-
+#ifndef _WIN32
if (ports[i].device_type == IO_SEGA_PARALLEL)
{
char *pipe_name = tern_find_ptr(config, "ioparallel_pipe");
@@ -606,7 +609,9 @@ cleanup_sock:
close(ports[i].device.stream.listen_fd);
ports[i].device_type = IO_NONE;
}
- } else if (ports[i].device_type == IO_GAMEPAD3 || ports[i].device_type == IO_GAMEPAD6) {
+ } else
+#endif
+ if (ports[i].device_type == IO_GAMEPAD3 || ports[i].device_type == IO_GAMEPAD6) {
printf("IO port %s connected to gamepad #%d with type '%s'\n", io_name(i), ports[i].device.pad.gamepad_num + 1, device_type_names[ports[i].device_type]);
} else {
printf("IO port %s connected to device '%s'\n", io_name(i), device_type_names[ports[i].device_type]);
@@ -770,6 +775,7 @@ void io_adjust_cycles(io_port * port, uint32_t current_cycle, uint32_t deduction
}
}
+#ifndef _WIN32
static void wait_for_connection(io_port * port)
{
if (port->device.stream.data_fd == -1)
@@ -869,6 +875,7 @@ static void service_socket(io_port *port)
}
}
}
+#endif
void io_data_write(io_port * port, uint8_t value, uint32_t current_cycle)
{
@@ -889,12 +896,14 @@ void io_data_write(io_port * port, uint8_t value, uint32_t current_cycle)
}
port->output = value;
break;
+#ifndef _WIN32
case IO_GENERIC:
wait_for_connection(port);
port->input[IO_STATE] = IO_WRITE_PENDING;
port->output = value;
service_socket(port);
break;
+#endif
default:
port->output = value;
}
@@ -938,6 +947,7 @@ uint8_t io_data_read(io_port * port, uint32_t current_cycle)
}
break;
}
+#ifndef _WIN32
case IO_SEGA_PARALLEL:
if (!th)
{
@@ -954,6 +964,7 @@ uint8_t io_data_read(io_port * port, uint32_t current_cycle)
service_socket(port);
input = ~port->input[IO_TH0];
break;
+#endif
default:
input = 0;
break;
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/render_sdl.c b/render_sdl.c
index 53a0e2f..9de86dd 100644
--- a/render_sdl.c
+++ b/render_sdl.c
@@ -5,6 +5,7 @@
*/
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include <math.h>
#include "render.h"
#include "blastem.h"
@@ -106,7 +107,7 @@ const GLushort element_data[] = {0, 1, 2, 3};
GLuint load_shader(char * fname, GLenum shader_type)
{
- char * parts[] = {getenv("HOME"), "/.config/blastem/shaders/", fname};
+ char * parts[] = {get_home_dir(), "/.config/blastem/shaders/", fname};
char * shader_path = alloc_concat_m(3, parts);
FILE * f = fopen(shader_path, "r");
free(shader_path);
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);