# HG changeset patch # User Michael Pavone # Date 1432873195 25200 # Node ID fc68992cf18de59698cb51d662f758ba017ae1e6 # Parent cf78cb045fa491b2a5f98bf34164b18b2389ffc7# Parent 8972378e314fe1e53e8554d5490f039886767308 Merge windows branch with latest changes diff -r 8972378e314f -r fc68992cf18d Makefile --- a/Makefile Tue May 26 22:22:30 2015 -0700 +++ b/Makefile Thu May 28 21:19:55 2015 -0700 @@ -2,19 +2,36 @@ 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 @@ 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 -r 8972378e314f -r fc68992cf18d config.c --- a/config.c Tue May 26 22:22:30 2015 -0700 +++ b/config.c Thu May 28 21:19:55 2015 -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; @@ -101,7 +122,7 @@ tern_node * load_config() { char * exe_dir; - char * home = getenv("HOME"); + char * home = get_home_dir(); if (!home) { goto load_in_app_dir; } diff -r 8972378e314f -r fc68992cf18d mem_win.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mem_win.c Thu May 28 21:19:55 2015 -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 + +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 -r 8972378e314f -r fc68992cf18d render.h --- a/render.h Tue May 26 22:22:30 2015 -0700 +++ b/render.h Thu May 28 21:19:55 2015 -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 +#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_num_joysticks(); void process_events(); -//TODO: Throw an ifdef in here once there's more than one renderer -#include -#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 -r 8972378e314f -r fc68992cf18d render_sdl.c diff -r 8972378e314f -r fc68992cf18d runtime_win.S --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/runtime_win.S Thu May 28 21:19:55 2015 -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 + + + diff -r 8972378e314f -r fc68992cf18d util.c --- a/util.c Tue May 26 22:22:30 2015 -0700 +++ b/util.c Thu May 28 21:19:55 2015 -0700 @@ -75,6 +75,41 @@ 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 @@ } return exe_dir; } + +#endif diff -r 8972378e314f -r fc68992cf18d util.h --- a/util.h Tue May 26 22:22:30 2015 -0700 +++ b/util.h Thu May 28 21:19:55 2015 -0700 @@ -19,6 +19,8 @@ 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);