# HG changeset patch # User Michael Pavone # Date 1396411920 25200 # Node ID 2e1b3b2585232af5698add24de290613b6ce7e5e # Parent 80a67be1770bd7f6a793387c8c45a4a3dd958044 Make Windows port a little less half-assed diff -r 80a67be1770b -r 2e1b3b258523 Makefile --- a/Makefile Tue Apr 01 19:43:58 2014 -0700 +++ b/Makefile Tue Apr 01 21:12:00 2014 -0700 @@ -6,8 +6,12 @@ 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 +CFLAGS:=-O2 -std=gnu99 -Wreturn-type -Werror=return-type -Werror=implicit-function-declaration -I"C:/MinGW/usr/include/SDL" -DGLEW_STATIC +LDFLAGS:= -L"C:/MinGW/usr/lib" -lm -lmingw32 -lSDLmain -lSDL +ifndef NOGL +LDFLAGS+= -lopengl32 -lglu32 +endif +LDFLAGS+= -mwindows CPU:=i686 else @@ -76,6 +80,11 @@ MAINOBJS+= $(Z80OBJS) endif +ifdef WINDOWS +ifndef NOGL +MAINOBJS+= glew.o +endif +endif all : dis zdis stateview vgmplay blastem diff -r 80a67be1770b -r 2e1b3b258523 config.c --- a/config.c Tue Apr 01 19:43:58 2014 -0700 +++ b/config.c Tue Apr 01 21:12:00 2014 -0700 @@ -121,11 +121,8 @@ tern_node * load_config() { -#ifdef _WIN32 - tern_node * ret = parse_config_file("default.cfg"); -#else char * exe_dir; - char * home = getenv("HOME"); + char * home = get_home_dir(); if (!home) { goto load_in_app_dir; } @@ -143,7 +140,6 @@ path = alloc_concat(exe_dir, "/default.cfg"); ret = parse_config_file(path); free(path); -#endif success: if (ret) { return ret; diff -r 80a67be1770b -r 2e1b3b258523 render_sdl.c --- a/render_sdl.c Tue Apr 01 19:43:58 2014 -0700 +++ b/render_sdl.c Tue Apr 01 21:12:00 2014 -0700 @@ -113,14 +113,22 @@ 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); + printf("Trying to find shader at %s\n", shader_path); FILE * f = fopen(shader_path, "r"); free(shader_path); if (!f) { +#ifdef _WIN32 + parts[0] = "shaders/"; + parts[1] = fname; + shader_path = alloc_concat_m(2, parts); +#else parts[0] = get_exe_dir(); parts[1] = "/shaders/"; shader_path = alloc_concat_m(3, parts); +#endif + printf("Trying to find shader at %s\n", shader_path); f = fopen(shader_path, "r"); free(shader_path); if (!f) { @@ -128,6 +136,7 @@ return 0; } } + puts("reading shader"); long fsize = file_size(f); GLchar * text = malloc(fsize); if (fread(text, 1, fsize, f) != fsize) { @@ -138,6 +147,7 @@ GLuint ret = glCreateShader(shader_type); glShaderSource(ret, 1, (const GLchar **)&text, (const GLint *)&fsize); free(text); + puts("compiling shader"); glCompileShader(ret); GLint compile_status, loglen; glGetShaderiv(ret, GL_COMPILE_STATUS, &compile_status); @@ -162,6 +172,7 @@ context->oddbuf = context->framebuf = malloc(512 * 256 * 4 * 2); memset(context->oddbuf, 0, 512 * 256 * 4 * 2); context->evenbuf = ((char *)context->oddbuf) + 512 * 256 * 4; + puts("generating textures"); glGenTextures(3, textures); for (int i = 0; i < 3; i++) { @@ -182,11 +193,15 @@ glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(element_data), element_data, GL_STATIC_DRAW); + puts("Loading vertex shader"); vshader = load_shader(tern_find_ptr_default(config, "videovertex_shader", "default.v.glsl"), GL_VERTEX_SHADER); + puts("loading fragment shader"); fshader = load_shader(tern_find_ptr_default(config, "videofragment_shader", "default.f.glsl"), GL_FRAGMENT_SHADER); + puts("creating program"); program = glCreateProgram(); glAttachShader(program, vshader); glAttachShader(program, fshader); + puts("linking program"); glLinkProgram(program); GLint link_status; glGetProgramiv(program, GL_LINK_STATUS, &link_status); @@ -205,6 +220,7 @@ #ifndef DISABLE_OPENGL } #endif + puts("alloc surfaces done"); } uint8_t render_depth() diff -r 80a67be1770b -r 2e1b3b258523 util.c --- a/util.c Tue Apr 01 19:43:58 2014 -0700 +++ b/util.c Tue Apr 01 21:12:00 2014 -0700 @@ -75,7 +75,41 @@ exe_str = str; } -#ifndef _WIN32 +#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; @@ -139,4 +173,5 @@ } return exe_dir; } + #endif diff -r 80a67be1770b -r 2e1b3b258523 util.h --- a/util.h Tue Apr 01 19:43:58 2014 -0700 +++ b/util.h Tue Apr 01 21:12:00 2014 -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);