# HG changeset patch # User Michael Pavone # Date 1432879532 25200 # Node ID 85c98a222fea56346b58a6fbd7b91dbf854da280 # Parent 25c9e9d39997c29a94844c1cd7e18ed6443c6322# Parent 9d4d40f833d0a340bd6ea02de3e2e72c93cec079 Merge diff -r 25c9e9d39997 -r 85c98a222fea Makefile --- a/Makefile Thu May 28 00:11:15 2015 -0700 +++ b/Makefile Thu May 28 23:05:32 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=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 @@ 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 @@ 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 -r 25c9e9d39997 -r 85c98a222fea config.c --- a/config.c Thu May 28 00:11:15 2015 -0700 +++ b/config.c Thu May 28 23:05:32 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 25c9e9d39997 -r 85c98a222fea debug.c --- a/debug.c Thu May 28 00:11:15 2015 -0700 +++ b/debug.c Thu May 28 23:05:32 2015 -0700 @@ -3,7 +3,9 @@ #include "68kinst.h" #include #include +#ifndef _WIN32 #include +#endif #include "render.h" static bp_def * breakpoints = NULL; @@ -510,16 +512,21 @@ 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 @@ } else { prompt = 1; } +#endif if (!fgets(input_buf, sizeof(input_buf), stdin)) { fputs("fgets failed", stderr); break; diff -r 25c9e9d39997 -r 85c98a222fea io.c --- a/io.c Thu May 28 00:11:15 2015 -0700 +++ b/io.c Thu May 28 23:05:32 2015 -0700 @@ -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 #include #include @@ -10,7 +11,9 @@ #include #include #include +#endif #include +#include #include "io.h" #include "blastem.h" @@ -544,7 +547,7 @@ 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 @@ 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 @@ } } +#ifndef _WIN32 static void wait_for_connection(io_port * port) { if (port->device.stream.data_fd == -1) @@ -869,6 +875,7 @@ } } } +#endif void io_data_write(io_port * port, uint8_t value, uint32_t current_cycle) { @@ -889,12 +896,14 @@ } 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 @@ } break; } +#ifndef _WIN32 case IO_SEGA_PARALLEL: if (!th) { @@ -954,6 +964,7 @@ service_socket(port); input = ~port->input[IO_TH0]; break; +#endif default: input = 0; break; diff -r 25c9e9d39997 -r 85c98a222fea mem_win.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mem_win.c Thu May 28 23:05:32 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 25c9e9d39997 -r 85c98a222fea render.h --- a/render.h Thu May 28 00:11:15 2015 -0700 +++ b/render.h Thu May 28 23:05:32 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 25c9e9d39997 -r 85c98a222fea render_sdl.c --- a/render_sdl.c Thu May 28 00:11:15 2015 -0700 +++ b/render_sdl.c Thu May 28 23:05:32 2015 -0700 @@ -5,6 +5,7 @@ */ #include #include +#include #include #include "render.h" #include "blastem.h" @@ -106,7 +107,7 @@ 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 -r 25c9e9d39997 -r 85c98a222fea runtime_win.S --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/runtime_win.S Thu May 28 23:05:32 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 25c9e9d39997 -r 85c98a222fea util.c --- a/util.c Thu May 28 00:11:15 2015 -0700 +++ b/util.c Thu May 28 23:05:32 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 25c9e9d39997 -r 85c98a222fea util.h --- a/util.h Thu May 28 00:11:15 2015 -0700 +++ b/util.h Thu May 28 23:05:32 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);