diff options
author | Mike Pavone <pavone@retrodev.com> | 2013-10-28 19:37:30 -0700 |
---|---|---|
committer | Mike Pavone <pavone@retrodev.com> | 2013-10-28 19:37:30 -0700 |
commit | da665eb04a793552ed32ed8944dffbeb5220d7ae (patch) | |
tree | 5532dd1d7f8e0d4f43d469f7823a5a3d9ccbfc1c | |
parent | 070b44e5440b966f911ee974490c7c99c91ec3d1 (diff) |
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
-rw-r--r-- | Makefile | 20 | ||||
-rw-r--r-- | config.c | 68 | ||||
-rw-r--r-- | render_sdl.c | 11 | ||||
-rw-r--r-- | util.c | 65 | ||||
-rw-r--r-- | util.h | 18 |
5 files changed, 110 insertions, 72 deletions
@@ -1,4 +1,8 @@ +ifdef NOGL +LIBS=sdl +else LIBS=sdl glew gl +endif LDFLAGS=-lm `pkg-config --libs $(LIBS)` ifdef DEBUG CFLAGS=-ggdb -std=gnu99 `pkg-config --cflags-only-I $(LIBS)` -Wreturn-type -Werror=return-type @@ -10,16 +14,20 @@ ifdef PROFILE CFLAGS+= -pg LDFLAGS+= -pg endif +ifdef NOGL +CFLAGS+= -DDISABLE_OPENGL +endif TRANSOBJS=gen_x86.o x86_backend.o mem.o M68KOBJS=68kinst.o m68k_to_x86.o runtime.o Z80OBJS=z80inst.o z80_to_x86.o zruntime.o AUDIOOBJS=ym2612.o psg.o wave.o +CONFIGOBJS=config.o tern.o util.o all : dis zdis stateview vgmplay blastem -blastem : blastem.o vdp.o render_sdl.o io.o config.o tern.o gst.o $(M68KOBJS) $(Z80OBJS) $(TRANSOBJS) $(AUDIOOBJS) - $(CC) -ggdb -o blastem blastem.o vdp.o render_sdl.o io.o config.o tern.o gst.o $(M68KOBJS) $(Z80OBJS) $(TRANSOBJS) $(AUDIOOBJS) $(LDFLAGS) +blastem : blastem.o vdp.o render_sdl.o io.o $(CONFIGOBJS) gst.o $(M68KOBJS) $(Z80OBJS) $(TRANSOBJS) $(AUDIOOBJS) + $(CC) -ggdb -o blastem blastem.o vdp.o render_sdl.o io.o $(CONFIGOBJS) gst.o $(M68KOBJS) $(Z80OBJS) $(TRANSOBJS) $(AUDIOOBJS) $(LDFLAGS) dis : dis.o 68kinst.o $(CC) -o dis dis.o 68kinst.o @@ -42,11 +50,11 @@ ztestrun : ztestrun.o $(Z80OBJS) $(TRANSOBJS) ztestgen : ztestgen.o z80inst.o $(CC) -o ztestgen ztestgen.o z80inst.o -stateview : stateview.o vdp.o render_sdl.o config.o tern.o gst.o - $(CC) -o stateview stateview.o vdp.o render_sdl.o config.o tern.o gst.o `pkg-config --libs $(LIBS)` +stateview : stateview.o vdp.o render_sdl.o $(CONFIGOBJS) gst.o + $(CC) -o stateview stateview.o vdp.o render_sdl.o $(CONFIGOBJS) gst.o $(LDFLAGS) -vgmplay : vgmplay.o render_sdl.o config.o tern.o $(AUDIOOBJS) - $(CC) -o vgmplay vgmplay.o render_sdl.o config.o tern.o $(AUDIOOBJS) $(LDFLAGS) +vgmplay : vgmplay.o render_sdl.o $(CONFIGOBJS) $(AUDIOOBJS) + $(CC) -o vgmplay vgmplay.o render_sdl.o $(CONFIGOBJS) $(AUDIOOBJS) $(LDFLAGS) testgst : testgst.o gst.o $(CC) -o testgst testgst.o gst.o @@ -1,80 +1,18 @@ /* Copyright 2013 Michael Pavone - This file is part of BlastEm. + 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 "tern.h" +#include "util.h" #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <stdarg.h> -#include <ctype.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> -char * alloc_concat(char * first, char * second) -{ - int flen = strlen(first); - int slen = strlen(second); - char * ret = malloc(flen + slen + 1); - memcpy(ret, first, flen); - memcpy(ret+flen, second, slen+1); - return ret; -} - -char * alloc_concat_m(int num_parts, char ** parts) -{ - int total = 0; - for (int i = 0; i < num_parts; i++) { - total += strlen(parts[i]); - } - char * ret = malloc(total + 1); - *ret = 0; - for (int i = 0; i < num_parts; i++) { - strcat(ret, parts[i]); - } - return ret; -} - -long file_size(FILE * f) -{ - fseek(f, 0, SEEK_END); - long fsize = ftell(f); - fseek(f, 0, SEEK_SET); - return fsize; -} - -char * strip_ws(char * text) -{ - while (*text && (!isprint(*text) || isblank(*text))) - { - text++; - } - char * ret = text; - text = ret + strlen(ret) - 1; - while (text > ret && (!isprint(*text) || isblank(*text))) - { - *text = 0; - text--; - } - return ret; -} - -char * split_keyval(char * text) -{ - while (*text && !isblank(*text)) - { - text++; - } - if (!*text) { - return text; - } - *text = 0; - return text+1; -} - #define MAX_NEST 30 //way more than I'll ever need tern_node * parse_config(char * config_data) @@ -201,7 +139,7 @@ tern_node * load_config(char * expath) } free(path); load_in_app_dir: - + linktext = readlink_alloc("/proc/self/exe"); if (!linktext) { goto link_prob; diff --git a/render_sdl.c b/render_sdl.c index 3c01eeb..f4241fc 100644 --- a/render_sdl.c +++ b/render_sdl.c @@ -97,6 +97,7 @@ uint32_t render_map_color(uint8_t r, uint8_t g, uint8_t b) } } +#ifndef DISABLE_OPENGL GLuint textures[3], buffers[2], vshader, fshader, program, un_textures[2], at_pos; const GLfloat vertex_data[] = { @@ -142,9 +143,11 @@ GLuint load_shader(char * fname, GLenum shader_type) } return ret; } +#endif void render_alloc_surfaces(vdp_context * context) { +#ifndef DISABLE_OPENGL if (render_gl) { context->oddbuf = context->framebuf = malloc(320 * 240 * 4 * 2); memset(context->oddbuf, 0, 320 * 240 * 4 * 2); @@ -185,9 +188,12 @@ void render_alloc_surfaces(vdp_context * context) un_textures[1] = glGetUniformLocation(program, "textures[1]"); at_pos = glGetAttribLocation(program, "pos"); } else { +#endif context->oddbuf = context->framebuf = malloc(320 * 240 * screen->format->BytesPerPixel * 2); context->evenbuf = ((char *)context->oddbuf) + 320 * 240 * screen->format->BytesPerPixel; +#ifndef DISABLE_OPENGL } +#endif } uint8_t render_depth() @@ -320,7 +326,7 @@ void render_init(int width, int height, char * title, uint32_t fps, uint8_t full } SDL_JoystickEventState(SDL_ENABLE); } - +#ifndef DISABLE_OPENGL void render_context_gl(vdp_context * context) { glBindTexture(GL_TEXTURE_2D, textures[context->framebuf == context->oddbuf ? 0 : 1]); @@ -353,6 +359,7 @@ void render_context_gl(vdp_context * context) context->framebuf = context->framebuf == context->oddbuf ? context->evenbuf : context->oddbuf; } } +#endif uint32_t blankbuf[320*240]; @@ -362,11 +369,13 @@ void render_context(vdp_context * context) uint32_t *buf_32; uint8_t b,g,r; last_frame = SDL_GetTicks(); +#ifndef DISABLE_OPENGL if (render_gl) { render_context_gl(context); return; } +#endif if (SDL_MUSTLOCK(screen)) { if (SDL_LockSurface(screen) < 0) { return; @@ -0,0 +1,65 @@ +#include <string.h> +#include <stdlib.h> +#include <stdio.h> +#include <ctype.h> + +char * alloc_concat(char * first, char * second) +{ + int flen = strlen(first); + int slen = strlen(second); + char * ret = malloc(flen + slen + 1); + memcpy(ret, first, flen); + memcpy(ret+flen, second, slen+1); + return ret; +} + +char * alloc_concat_m(int num_parts, char ** parts) +{ + int total = 0; + for (int i = 0; i < num_parts; i++) { + total += strlen(parts[i]); + } + char * ret = malloc(total + 1); + *ret = 0; + for (int i = 0; i < num_parts; i++) { + strcat(ret, parts[i]); + } + return ret; +} + +long file_size(FILE * f) +{ + fseek(f, 0, SEEK_END); + long fsize = ftell(f); + fseek(f, 0, SEEK_SET); + return fsize; +} + +char * strip_ws(char * text) +{ + while (*text && (!isprint(*text) || isblank(*text))) + { + text++; + } + char * ret = text; + text = ret + strlen(ret) - 1; + while (text > ret && (!isprint(*text) || isblank(*text))) + { + *text = 0; + text--; + } + return ret; +} + +char * split_keyval(char * text) +{ + while (*text && !isblank(*text)) + { + text++; + } + if (!*text) { + return text; + } + *text = 0; + return text+1; +} @@ -0,0 +1,18 @@ +#ifndef UTIL_H_ +#define UTIL_H_ + +#include <stdio.h> + +//Utility functions + +//Allocates a new string containing the concatenation of first and second +char * alloc_concat(char * first, char * second); +//Allocates a new string containing the concatenation of the strings pointed to by parts +char * alloc_concat_m(int num_parts, char ** parts); +//Returns the size of a file using fseek and ftell +long file_size(FILE * f); +//Strips whitespace and non-printable characters from the beginning and end of a string +char * strip_ws(char * text); +char * split_keyval(char * text); + +#endif //UTIL_H_ |