diff options
author | Michael Pavone <pavone@retrodev.com> | 2014-04-01 19:43:58 -0700 |
---|---|---|
committer | Michael Pavone <pavone@retrodev.com> | 2014-04-01 19:43:58 -0700 |
commit | c51f057715587f133abe9bfb32d6d453a7af698b (patch) | |
tree | f35a343e06ab8ad3ad4652a97878d0b62402a6d0 | |
parent | 4d15ffc63362410563a49481faf9652c138945ac (diff) |
Initial work on Windows port
-rw-r--r-- | Makefile | 28 | ||||
-rw-r--r-- | config.c | 25 | ||||
-rw-r--r-- | mem_win.c | 15 | ||||
-rw-r--r-- | render.h | 30 | ||||
-rw-r--r-- | runtime_win.S | 74 | ||||
-rw-r--r-- | util.c | 2 |
6 files changed, 155 insertions, 19 deletions
@@ -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 @@ endif 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 @@ 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 $(CC) -o dis dis.o 68kinst.o @@ -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 @@ open_fail: 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 @@ load_in_app_dir: path = alloc_concat(exe_dir, "/default.cfg"); ret = parse_config_file(path); free(path); +#endif success: if (ret) { return ret; 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); +} @@ -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_buttons(int joystick); 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_ 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 + + + @@ -75,6 +75,7 @@ void set_exe_str(char * str) exe_str = str; } +#ifndef _WIN32 char * readlink_alloc(char * path) { char * linktext = NULL; @@ -138,3 +139,4 @@ fallback: } return exe_dir; } +#endif |