changeset 495:39cad98d2789

Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
author Mike Pavone <pavone@retrodev.com>
date Mon, 28 Oct 2013 19:37:30 -0700
parents dffc07104b09
children 6fc71114d145
files Makefile config.c render_sdl.c util.c util.h
diffstat 5 files changed, 110 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Sun Oct 27 22:08:02 2013 -0700
+++ b/Makefile	Mon Oct 28 19:37:30 2013 -0700
@@ -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 @@
 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 @@
 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
--- a/config.c	Sun Oct 27 22:08:02 2013 -0700
+++ b/config.c	Mon Oct 28 19:37:30 2013 -0700
@@ -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 @@
 	}
 	free(path);
 load_in_app_dir:
-	
+
 	linktext = readlink_alloc("/proc/self/exe");
 	if (!linktext) {
 		goto link_prob;
--- a/render_sdl.c	Sun Oct 27 22:08:02 2013 -0700
+++ b/render_sdl.c	Mon Oct 28 19:37:30 2013 -0700
@@ -97,6 +97,7 @@
 	}
 }
 
+#ifndef DISABLE_OPENGL
 GLuint textures[3], buffers[2], vshader, fshader, program, un_textures[2], at_pos;
 
 const GLfloat vertex_data[] = {
@@ -142,9 +143,11 @@
 	}
 	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 @@
 		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 @@
 	}
 	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 @@
 		context->framebuf = context->framebuf == context->oddbuf ? context->evenbuf : context->oddbuf;
 	}
 }
+#endif
 
 uint32_t blankbuf[320*240];
 
@@ -362,11 +369,13 @@
 	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;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/util.c	Mon Oct 28 19:37:30 2013 -0700
@@ -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;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/util.h	Mon Oct 28 19:37:30 2013 -0700
@@ -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_