tb1_linux: compile warning free on modern compiler

also unwisely mix in some "fromdos" conversions and some other
whitespace fixes
This commit is contained in:
Vince Weaver 2019-09-01 23:50:31 -04:00
parent f0fc207ce7
commit 78c92961dc
13 changed files with 4716 additions and 4721 deletions

View File

@ -18,58 +18,58 @@ tb1: tb1.o ./svmwgraph/libsvmwgraph.a about.o credits.o graphic_tools.o \
cd svmwgraph && make cd svmwgraph && make
tb1.o: tb1.c tb1.o: tb1.c
$(CC) -c tb1.c $(INCLUDE) $(CC) $(CFLAGS) -c tb1.c $(INCLUDE)
about.o: about.c about.o: about.c
$(CC) -c about.c $(INCLUDE) $(CC) $(CFLAGS) -c about.c $(INCLUDE)
credits.o: credits.c credits.o: credits.c
$(CC) -c credits.c $(INCLUDE) $(CC) $(CFLAGS) -c credits.c $(INCLUDE)
graphic_tools.o: graphic_tools.c graphic_tools.o: graphic_tools.c
$(CC) -c graphic_tools.c $(INCLUDE) $(CC) $(CFLAGS) -c graphic_tools.c $(INCLUDE)
help.o: help.c help.o: help.c
$(CC) -c help.c $(INCLUDE) $(CC) $(CFLAGS) -c help.c $(INCLUDE)
hiscore.o: hiscore.c hiscore.o: hiscore.c
$(CC) -c hiscore.c $(INCLUDE) $(CC) $(CFLAGS) -c hiscore.c $(INCLUDE)
level_1.o: level_1.c level_1.o: level_1.c
$(CC) -c level_1.c $(INCLUDE) $(CC) $(CFLAGS) -c level_1.c $(INCLUDE)
level2_engine.o: level2_engine.c level2_engine.o: level2_engine.c
$(CC) -c level2_engine.c $(INCLUDE) $(CC) $(CFLAGS) -c level2_engine.c $(INCLUDE)
#level_2.o: level_2.c #level_2.o: level_2.c
# $(CC) -c level_2.c $(INCLUDE) # $(CC) -c level_2.c $(INCLUDE)
level_3.o: level_3.c level_3.o: level_3.c
$(CC) -c level_3.c $(INCLUDE) $(CC) $(CFLAGS) -c level_3.c $(INCLUDE)
loadsave.o: loadsave.c loadsave.o: loadsave.c
$(CC) -c loadsave.c $(INCLUDE) $(CC) $(CFLAGS) -c loadsave.c $(INCLUDE)
options.o: options.c options.o: options.c
$(CC) -c options.c $(INCLUDE) $(CC) $(CFLAGS) -c options.c $(INCLUDE)
playgame.o: playgame.c playgame.o: playgame.c
$(CC) -c playgame.c $(INCLUDE) $(CC) $(CFLAGS) -c playgame.c $(INCLUDE)
quit.o: quit.c quit.o: quit.c
$(CC) -c quit.c $(INCLUDE) $(CC) $(CFLAGS) -c quit.c $(INCLUDE)
sidebar.o: sidebar.c sidebar.o: sidebar.c
$(CC) -c sidebar.c $(INCLUDE) $(CC) $(CFLAGS) -c sidebar.c $(INCLUDE)
sound.o: sound.c sound.o: sound.c
$(CC) -c sound.c $(INCLUDE) $(SDL_MIXER_FLAGS) $(CC) $(CFLAGS) -c sound.c $(INCLUDE) $(SDL_MIXER_FLAGS)
story.o: story.c story.o: story.c
$(CC) -c story.c $(INCLUDE) $(CC) $(CFLAGS) -c story.c $(INCLUDE)
tblib.o: tblib.c tblib.o: tblib.c
$(CC) -c tblib.c $(INCLUDE) $(CC) $(CFLAGS) -c tblib.c $(INCLUDE)
clean: clean:
rm -f tb1 *.o *~ rm -f tb1 *.o *~

View File

@ -8,6 +8,8 @@
# #
CC= gcc CC= gcc
CFLAGS = -O2 -Wall -g
# #
# Uncomment the following for SDL_mixer sound # Uncomment the following for SDL_mixer sound
# #
@ -26,9 +28,9 @@ SDL_INCLUDE= `sdl-config --cflags`
# #
# Uncomment the following for ncurses # Uncomment the following for ncurses
# #
#CURSES_TARGET= curses_svmwgraph.o CURSES_TARGET= curses_svmwgraph.o
#CURSES_FLAGS= -DCURSES_TARGET=1 CURSES_FLAGS= -DCURSES_TARGET=1
#CURSES_LIBS= -lncurses CURSES_LIBS= -lncurses
# #
# On machines w/ curses instead of ncurses [i.e. solaris, Irix, etc] # On machines w/ curses instead of ncurses [i.e. solaris, Irix, etc]
@ -42,14 +44,14 @@ SDL_INCLUDE= `sdl-config --cflags`
# #
# Uncomment the following for opengGL # Uncomment the following for opengGL
# #
#OPENGL_TARGET= opengl_svmwgraph.o OPENGL_TARGET= opengl_svmwgraph.o
#OPENGL_FLAGS=-DOPENGL_TARGET OPENGL_FLAGS=-DOPENGL_TARGET
#OPENGL_LIBS= -L/usr/X11R6/lib -lX11 -lICE -lXmu -lGL -lGLU OPENGL_LIBS= -lX11 -lICE -lGL -lGLU
############################## ##############################
# DO NOT EDIT BELOW THIS LINE # DO NOT EDIT BELOW THIS LINE
############################## ##############################
INCLUDE_GLOBAL= -Wall -O2 $(SDL_INCLUDE) INCLUDE_GLOBAL= $(SDL_INCLUDE)
LIBS_GLOBAL= -lm $(SDL_MIXER_LIBS) $(SDL_LIBS) $(CURSES_LIBS) $(OPENGL_LIBS) LIBS_GLOBAL= -lm $(SDL_MIXER_LIBS) $(SDL_LIBS) $(CURSES_LIBS) $(OPENGL_LIBS)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -4,49 +4,49 @@ INCLUDE= $(INCLUDE_GLOBAL)
LIBS= $(LIBS_GLOBAL) LIBS= $(LIBS_GLOBAL)
all: libsvmwgraph.a all: libsvmwgraph.a
libsvmwgraph.a: vmw_core.o vmw_dialogs.o vmw_flip.o vmw_font.o vmw_paintpro.o vmw_palette.o vmw_pcx.o vmw_setup.o vmw_sprite.o $(CURSES_TARGET) null_svmwgraph.o $(OPENGL_TARGET) $(SDL_TARGET) libsvmwgraph.a: vmw_core.o vmw_dialogs.o vmw_flip.o vmw_font.o vmw_paintpro.o vmw_palette.o vmw_pcx.o vmw_setup.o vmw_sprite.o $(CURSES_TARGET) null_svmwgraph.o $(OPENGL_TARGET) $(SDL_TARGET)
ar cru libsvmwgraph.a vmw_core.o vmw_dialogs.o vmw_flip.o vmw_font.o vmw_paintpro.o vmw_palette.o vmw_pcx.o vmw_setup.o vmw_sprite.o $(CURSES_TARGET) null_svmwgraph.o $(OPENGL_TARGET) $(SDL_TARGET) ar cru libsvmwgraph.a vmw_core.o vmw_dialogs.o vmw_flip.o vmw_font.o vmw_paintpro.o vmw_palette.o vmw_pcx.o vmw_setup.o vmw_sprite.o $(CURSES_TARGET) null_svmwgraph.o $(OPENGL_TARGET) $(SDL_TARGET)
ranlib libsvmwgraph.a ranlib libsvmwgraph.a
vmw_core.o: vmw_core.c vmw_core.o: vmw_core.c
$(CC) $(INCLUDE) -c vmw_core.c $(CC) $(CFLAGS) $(INCLUDE) -c vmw_core.c
vmw_dialogs.o: vmw_dialogs.c vmw_dialogs.o: vmw_dialogs.c
$(CC) $(INCLUDE) -c vmw_dialogs.c $(CC) $(CFLAGS) $(INCLUDE) -c vmw_dialogs.c
vmw_flip.o: vmw_flip.c vmw_flip.o: vmw_flip.c
$(CC) $(INCLUDE) -c vmw_flip.c $(CC) $(CFLAGS) $(INCLUDE) -c vmw_flip.c
vmw_font.o: vmw_font.c vmw_font.o: vmw_font.c
$(CC) $(INCLUDE) -c vmw_font.c $(CC) $(CFLAGS) $(INCLUDE) -c vmw_font.c
vmw_paintpro.o: vmw_paintpro.c vmw_paintpro.o: vmw_paintpro.c
$(CC) $(INCLUDE) -c vmw_paintpro.c $(CC) $(CFLAGS) $(INCLUDE) -c vmw_paintpro.c
vmw_palette.o: vmw_palette.c vmw_palette.o: vmw_palette.c
$(CC) $(INCLUDE) -c vmw_palette.c $(CC) $(CFLAGS) $(INCLUDE) -c vmw_palette.c
vmw_pcx.o: vmw_pcx.c vmw_pcx.o: vmw_pcx.c
$(CC) $(INCLUDE) -c vmw_pcx.c $(CC) $(CFLAGS) $(INCLUDE) -c vmw_pcx.c
vmw_setup.o: vmw_setup.c
$(CC) $(INCLUDE) $(SDL_FLAGS) $(CURSES_FLAGS) $(OPENGL_FLAGS) -c vmw_setup.c
vmw_sprite.o: vmw_sprite.c
$(CC) $(INCLUDE) -c vmw_sprite.c
curses_svmwgraph.o: curses_svmwgraph.c vmw_setup.o: vmw_setup.c
$(CC) $(INCLUDE) -c curses_svmwgraph.c $(CURSES_FLAGS) $(CC) $(CFLAGS) $(INCLUDE) $(SDL_FLAGS) $(CURSES_FLAGS) $(OPENGL_FLAGS) -c vmw_setup.c
vmw_sprite.o: vmw_sprite.c
$(CC) $(CFLAGS) $(INCLUDE) -c vmw_sprite.c
curses_svmwgraph.o: curses_svmwgraph.c
$(CC) $(CFLAGS) $(INCLUDE) -c curses_svmwgraph.c $(CURSES_FLAGS)
null_svmwgraph.o: null_svmwgraph.c null_svmwgraph.o: null_svmwgraph.c
$(CC) $(INCLUDE) -c null_svmwgraph.c $(CC) $(CFLAGS) $(INCLUDE) -c null_svmwgraph.c
opengl_svmwgraph.o: opengl_svmwgraph.c opengl_svmwgraph.o: opengl_svmwgraph.c
$(CC) $(INCLUDE) -c opengl_svmwgraph.c $(CC) $(CFLAGS) $(INCLUDE) -c opengl_svmwgraph.c
sdl_svmwgraph.o: sdl_svmwgraph.c sdl_svmwgraph.o: sdl_svmwgraph.c
$(CC) $(INCLUDE) -c sdl_svmwgraph.c $(CC) $(CFLAGS) $(INCLUDE) -c sdl_svmwgraph.c
clean: clean:
rm -f libsvmwgraph.a *.o *~ rm -f libsvmwgraph.a *.o *~

View File

@ -1,352 +1,349 @@
/* The OpenGL hooks for the Super VMW graphics library */ /* The OpenGL hooks for the Super VMW graphics library */
#include <SDL/SDL.h> #include <SDL/SDL.h>
#include <GL/gl.h> #include <GL/gl.h>
#include <GL/glu.h> #include <GL/glu.h>
#include "svmwgraph.h" #include "svmwgraph.h"
#include <stdlib.h> /* For atexit() */ #include <stdlib.h> /* For atexit() */
#include <stdio.h> #include <stdio.h>
static float rotation=0.0; static float rotation=0.0;
unsigned char palette[256][4]; unsigned char palette[256][4];
#define TEXTURE_SIZE 64 #define TEXTURE_SIZE 64
int texture_grid[5][4]; int texture_grid[5][4];
GLubyte *texture_data[5][4]; GLubyte *texture_data[5][4];
typedef struct { typedef struct {
GLubyte *texture_data; GLubyte *texture_data;
GLuint texture_name; GLuint texture_name;
GLfloat x1,y1,x2,y2; GLfloat x1,y1,x2,y2;
} texture_block; } texture_block;
texture_block *current_texture; texture_block *current_texture;
GLuint temp_texture_name; GLuint temp_texture_name;
int texnumx,texnumy; int texnumx,texnumy;
void reshape(int w,int h) { void reshape(int w,int h) {
glViewport(0,0,(GLsizei)w,(GLsizei)h); glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
gluPerspective(60.0,(GLfloat)w/(GLfloat)h,1.0,100.0); gluPerspective(60.0,(GLfloat)w/(GLfloat)h,1.0,100.0);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
//glTranslatef(0.0,0.0,-3.6); //glTranslatef(0.0,0.0,-3.6);
} }
/* Setup the Graphics */ /* Setup the Graphics */
/* Pass '0' to auto-detect bpp */ /* Pass '0' to auto-detect bpp */
void *openGL_setupGraphics(int *xsize,int *ysize,int *bpp, void *openGL_setupGraphics(int *xsize,int *ysize,int *bpp,
int fullscreen,int verbose) { int fullscreen,int verbose) {
SDL_Surface *sdl_screen=NULL; SDL_Surface *sdl_screen=NULL;
SDL_Joystick *joy; SDL_Joystick *joy;
int mode,x,y; int mode,x,y;
/* Initialize SDL */ /* Initialize SDL */
if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK)<0) { if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK)<0) {
printf("Error trying to init SDL: %s\n",SDL_GetError()); printf("Error trying to init SDL: %s\n",SDL_GetError());
return NULL; return NULL;
} }
if (fullscreen) mode=SDL_OPENGL | SDL_FULLSCREEN; if (fullscreen) mode=SDL_OPENGL | SDL_FULLSCREEN;
else mode=SDL_OPENGL; else mode=SDL_OPENGL;
/* Create the OpenGL screen */ /* Create the OpenGL screen */
if ( (sdl_screen=SDL_SetVideoMode(*xsize, *ysize, 0, mode)) == NULL ) { if ( (sdl_screen=SDL_SetVideoMode(*xsize, *ysize, 0, mode)) == NULL ) {
printf("Unable to create OpenGL screen: %s\n", SDL_GetError()); printf("Unable to create OpenGL screen: %s\n", SDL_GetError());
SDL_Quit(); SDL_Quit();
return NULL; return NULL;
} }
atexit(SDL_Quit); atexit(SDL_Quit);
SDL_WM_SetCaption("Tom Bombem...",NULL); SDL_WM_SetCaption("Tom Bombem...",NULL);
/* Try to init Joysticks */ /* Try to init Joysticks */
if (SDL_NumJoysticks()>0){ if (SDL_NumJoysticks()>0){
/* Open joystick */ /* Open joystick */
joy=SDL_JoystickOpen(0); joy=SDL_JoystickOpen(0);
if (joy) { if (joy) {
printf("Opened Joystick 0\n"); printf("Opened Joystick 0\n");
printf("Name: %s\n", SDL_JoystickName(0)); printf("Name: %s\n", SDL_JoystickName(0));
SDL_JoystickEventState(SDL_ENABLE); SDL_JoystickEventState(SDL_ENABLE);
} }
} }
printf(" GL_VERSION: %s\n", glGetString(GL_VERSION)); printf(" GL_VERSION: %s\n", glGetString(GL_VERSION));
printf(" GL_VENDOR: %s\n", glGetString(GL_VENDOR)); printf(" GL_VENDOR: %s\n", glGetString(GL_VENDOR));
printf(" GL_RENDERER: %s\n", glGetString(GL_RENDERER)); printf(" GL_RENDERER: %s\n", glGetString(GL_RENDERER));
glPixelStorei(GL_UNPACK_ALIGNMENT,1); glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glClearColor(0.0,0.0,0.0,0.0); glClearColor(0.0,0.0,0.0,0.0);
glClearDepth(1.0); glClearDepth(1.0);
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glLoadIdentity(); glLoadIdentity();
reshape(*xsize,*ysize); reshape(*xsize,*ysize);
printf("Init!\n"); fflush(stdout); printf("Init!\n"); fflush(stdout);
// Initializing Textures!! // Initializing Textures!!
// //
for(x=0;x<5;x++) { for(x=0;x<5;x++) {
for(y=0;y<4;y++) { for(y=0;y<4;y++) {
texture_data[x][y]=calloc(64*64,sizeof(char)*4); texture_data[x][y]=calloc(64*64,sizeof(char)*4);
glBindTexture(GL_TEXTURE_2D,texture_grid[x][y]); glBindTexture(GL_TEXTURE_2D,texture_grid[x][y]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64,
64 ,0,GL_RGBA,GL_UNSIGNED_BYTE,texture_data[x][y]); 64 ,0,GL_RGBA,GL_UNSIGNED_BYTE,texture_data[x][y]);
} }
} }
#if 0 #if 0
texnumx=320/TEXTURE_SIZE; texnumx=320/TEXTURE_SIZE;
if (320%TEXTURE_SIZE) texnumx++; if (320%TEXTURE_SIZE) texnumx++;
texnumy=200/TEXTURE_SIZE; texnumy=200/TEXTURE_SIZE;
if (200%TEXTURE_SIZE) texnumy++; if (200%TEXTURE_SIZE) texnumy++;
texture_grid=calloc(texnumx*texnumy,sizeof(texture_block)); texture_grid=calloc(texnumx*texnumy,sizeof(texture_block));
for(x=0;x<texnumx;x++) { for(x=0;x<texnumx;x++) {
for(y=0;y<texnumy;y++) { for(y=0;y<texnumy;y++) {
current_texture=texture_grid+y*texnumx+x; current_texture=texture_grid+y*texnumx+x;
printf("%p\n",current_texture); printf("%p\n",current_texture);
current_texture->texture_data=malloc(TEXTURE_SIZE*TEXTURE_SIZE); current_texture->texture_data=malloc(TEXTURE_SIZE*TEXTURE_SIZE);
current_texture->x1=x*TEXTURE_SIZE; current_texture->x1=x*TEXTURE_SIZE;
current_texture->y1=y*TEXTURE_SIZE; current_texture->y1=y*TEXTURE_SIZE;
current_texture->x2=(x+1)*TEXTURE_SIZE; current_texture->x2=(x+1)*TEXTURE_SIZE;
if (current_texture->x2>320) current_texture->x2=320; if (current_texture->x2>320) current_texture->x2=320;
current_texture->y2=(y+1)*TEXTURE_SIZE; current_texture->y2=(y+1)*TEXTURE_SIZE;
if (current_texture->y2>200) current_texture->y2=200; if (current_texture->y2>200) current_texture->y2=200;
glGenTextures(1,&temp_texture_name); glGenTextures(1,&temp_texture_name);
current_texture->texture_name=temp_texture_name; current_texture->texture_name=temp_texture_name;
glBindTexture(GL_TEXTURE_2D, temp_texture_name); glBindTexture(GL_TEXTURE_2D, temp_texture_name);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,TEXTURE_SIZE, glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,TEXTURE_SIZE,
TEXTURE_SIZE,0,GL_RGBA,GL_UNSIGNED_BYTE, TEXTURE_SIZE,0,GL_RGBA,GL_UNSIGNED_BYTE,
current_texture->texture_data); current_texture->texture_data);
// glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); // glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
} }
} }
glOrtho(-20,340,-20,220,-100,100); glOrtho(-20,340,-20,220,-100,100);
// gluPerspective(60,1.6,-10,10); // gluPerspective(60,1.6,-10,10);
#endif #endif
return sdl_screen; return sdl_screen;
} }
void openGL_flushPalette(vmwSVMWGraphState *state) { void openGL_flushPalette(vmwSVMWGraphState *state) {
int i; int i;
for(i=0;i<256;i++) { for(i=0;i<256;i++) {
palette[i][0]=((state->palette[i]>>11)<<3); palette[i][0]=((state->palette[i]>>11)<<3);
palette[i][1]=( ((state->palette[i]>>5)&0x3f)<<2); palette[i][1]=( ((state->palette[i]>>5)&0x3f)<<2);
palette[i][2]=((state->palette[i]&0x1f)<<3); palette[i][2]=((state->palette[i]&0x1f)<<3);
palette[i][3]=255; palette[i][3]=255;
} }
} }
void openGL_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) { void openGL_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
int x=0,y=0,temp_col,i,j,ending_j,ending_i; int x=0,y=0,i,j;//temp_col,ending_j,ending_i;
unsigned char *s_pointer; unsigned char *s_pointer;
GLubyte temp_data[64*64*4]; GLubyte temp_data[64*64*4];
GLubyte *t_pointer; // GLubyte *t_pointer;
GLfloat light_position[]={0.0,0.0,25.0,0.0}; GLfloat light_position[]={0.0,0.0,25.0,0.0};
GLfloat light_ambient[]={0.65,0.65,0.65,1.0}; // GLfloat light_ambient[]={0.65,0.65,0.65,1.0};
GLfloat lmodel_ambient[]={0.4,0.4,0.4,1.0}; GLfloat lmodel_ambient[]={0.4,0.4,0.4,1.0};
GLfloat white_light[]={1.0,1.0,1.0,1.0}; GLfloat white_light[]={1.0,1.0,1.0,1.0};
glLoadIdentity();
glLoadIdentity();
gluLookAt(0.0,0.0,20.0,
gluLookAt(0.0,0.0,20.0, 0.0,0.0,0.0,
0.0,0.0,0.0, 0.0,1.0,1.0);
0.0,1.0,1.0);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);
glLightfv(GL_LIGHT0, GL_SPECULAR,white_light);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
glLightfv(GL_LIGHT0, GL_SPECULAR,white_light);
glEnable(GL_LIGHTING);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glEnable(GL_LIGHT0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0); glColor3f(1,0,0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); {
GLfloat default_a[]={0.6,0.6,0.6,1.0
glColor3f(1,0,0); };
{ GLfloat default_d[]={ 0.8,0.8,0.8,1.0
GLfloat default_a[]={0.6,0.6,0.6,1.0 };
}; GLfloat default_s[]={0.0,0.0,0.0,1.0
GLfloat default_d[]={ 0.8,0.8,0.8,1.0 };
}; GLfloat default_e[]={0.0,0.0,0.0,1.0
GLfloat default_s[]={0.0,0.0,0.0,1.0 };
};
GLfloat default_e[]={0.0,0.0,0.0,1.0 glMaterialfv(GL_FRONT,GL_AMBIENT,default_a);
}; glMaterialfv(GL_FRONT,GL_DIFFUSE,default_d);
glMaterialfv(GL_FRONT,GL_SPECULAR,default_s);
glMaterialfv(GL_FRONT,GL_AMBIENT,default_a); glMaterialfv(GL_FRONT,GL_EMISSION,default_e);
glMaterialfv(GL_FRONT,GL_DIFFUSE,default_d); }
glMaterialfv(GL_FRONT,GL_SPECULAR,default_s); #if 0
glMaterialfv(GL_FRONT,GL_EMISSION,default_e); for (x=0;x<source->xsize;x++)
} for (y=0;y<source->ysize;y++) {
#if 0 *((Uint16 *)(t_pointer))=target_p->palette[*(s_pointer)];
for (x=0;x<source->xsize;x++) s_pointer++; t_pointer+=2;
for (y=0;y<source->ysize;y++) { }
*((Uint16 *)(t_pointer))=target_p->palette[*(s_pointer)]; #endif
s_pointer++; t_pointer+=2;
}
#endif glRotatef(rotation,1,1,1);
rotation+=1.0;
glEnable(GL_TEXTURE_2D);
glRotatef(rotation,1,1,1); glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
rotation+=1.0;
glEnable(GL_TEXTURE_2D); for(i=0;i<5;i++) {
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE); for(j=0;j<3;j++) { /* make it 4, but fix so no out of bounds */
s_pointer=(source->memory)+(((j*64*320)+(i*64)));
for(i=0;i<5;i++) {
for(j=0;j<3;j++) { /* make it 4, but fix so no out of bounds */ for(y=0;y<64;y++) {
s_pointer=(source->memory)+(((j*64*320)+(i*64))); for(x=0;x<64;x++) {
temp_data[ ((y*64)+x)*4] =palette[*(s_pointer)][0];
for(y=0;y<64;y++) { temp_data[ ((y*64)+x)*4+1] =palette[*(s_pointer)][1];
for(x=0;x<64;x++) { temp_data[ ((y*64)+x)*4+2] =palette[*(s_pointer)][2];
temp_data[ ((y*64)+x)*4] =palette[*(s_pointer)][0]; temp_data[ ((y*64)+x)*4+3] =palette[*(s_pointer)][3];
temp_data[ ((y*64)+x)*4+1] =palette[*(s_pointer)][1]; s_pointer++;
temp_data[ ((y*64)+x)*4+2] =palette[*(s_pointer)][2]; }
temp_data[ ((y*64)+x)*4+3] =palette[*(s_pointer)][3]; s_pointer+=(320-64);
s_pointer++; }
}
s_pointer+=(320-64); glBindTexture(GL_TEXTURE_2D,texture_grid[i][j]);
}
glTexSubImage2D(GL_TEXTURE_2D,0,0,0,64,64,GL_RGBA,GL_UNSIGNED_BYTE,
glBindTexture(GL_TEXTURE_2D,texture_grid[i][j]); &temp_data);
glTexSubImage2D(GL_TEXTURE_2D,0,0,0,64,64,GL_RGBA,GL_UNSIGNED_BYTE, glPushMatrix();
&temp_data); glTranslatef( i*4,-(j*4),0);
glPushMatrix(); glBegin(GL_QUADS);
glTranslatef( i*4,-(j*4),0); glNormal3f(0.0,0.0,1.0);
glTexCoord2f(0,0);
glBegin(GL_QUADS); glVertex3f(-2,2,0);
glNormal3f(0.0,0.0,1.0); glTexCoord2f(1,0);
glTexCoord2f(0,0); glVertex3f(2,2,0);
glVertex3f(-2,2,0); glTexCoord2f(1,1);
glTexCoord2f(1,0); glVertex3f(2,-2,0);
glVertex3f(2,2,0); glTexCoord2f(0,1);
glTexCoord2f(1,1); glVertex3f(-2,-2,0);
glVertex3f(2,-2,0); glEnd();
glTexCoord2f(0,1); glPopMatrix();
glVertex3f(-2,-2,0); }
glEnd(); }
glPopMatrix(); glDisable(GL_TEXTURE_2D);
} #if 0
}
glDisable(GL_TEXTURE_2D); // glEnable(GL_DEPTH_TEST);
#if 0 glEnable(GL_TEXTURE_2D);
// glEnable(GL_DEPTH_TEST); for(y=0;y<texnumy;y++) {
glEnable(GL_TEXTURE_2D); for(x=0;x<texnumx;x++) {
current_texture=texture_grid+y*texnumx+x;
for(y=0;y<texnumy;y++) {
for(x=0;x<texnumx;x++) { glBindTexture(GL_TEXTURE_2D,current_texture->texture_name);
current_texture=texture_grid+y*texnumx+x;
s_pointer=source->memory+((y*TEXTURE_SIZE)*320)+(x*TEXTURE_SIZE);
glBindTexture(GL_TEXTURE_2D,current_texture->texture_name);
t_pointer=(current_texture->texture_data);
s_pointer=source->memory+((y*TEXTURE_SIZE)*320)+(x*TEXTURE_SIZE);
ending_j=TEXTURE_SIZE;
t_pointer=(current_texture->texture_data); if (((y*TEXTURE_SIZE)+TEXTURE_SIZE)>200)
ending_j=200%TEXTURE_SIZE;
ending_j=TEXTURE_SIZE;
if (((y*TEXTURE_SIZE)+TEXTURE_SIZE)>200) ending_i=TEXTURE_SIZE;
ending_j=200%TEXTURE_SIZE; if (((y*TEXTURE_SIZE)+TEXTURE_SIZE)>320)
ending_i=320%TEXTURE_SIZE;
ending_i=TEXTURE_SIZE; // printf("==>%i %i %p\n",x,y,current_texture); fflush(stdout);
if (((y*TEXTURE_SIZE)+TEXTURE_SIZE)>320)
ending_i=320%TEXTURE_SIZE;
// printf("==>%i %i %p\n",x,y,current_texture); fflush(stdout); for(j=0;j<ending_j;j++) {
for(i=0;i<ending_i;i++) {
temp_col=*(s_pointer);
for(j=0;j<ending_j;j++) { // printf(">>>%p %p=%i\n",t_pointer,s_pointer,temp_col); fflush(stdout);
for(i=0;i<ending_i;i++) { memcpy(t_pointer,palette[temp_col],3);
temp_col=*(s_pointer); s_pointer++;
// printf(">>>%p %p=%i\n",t_pointer,s_pointer,temp_col); fflush(stdout); t_pointer+=4;
memcpy(t_pointer,palette[temp_col],3); }
s_pointer++; s_pointer+=(320-TEXTURE_SIZE);
t_pointer+=4; }
}
s_pointer+=(320-TEXTURE_SIZE); glTexSubImage2D(GL_TEXTURE_2D,
} 0,0,0,TEXTURE_SIZE,TEXTURE_SIZE,
GL_RGBA,
glTexSubImage2D(GL_TEXTURE_2D, GL_UNSIGNED_BYTE,
0,0,0,TEXTURE_SIZE,TEXTURE_SIZE, current_texture->texture_data);
GL_RGBA,
GL_UNSIGNED_BYTE, glBegin(GL_QUADS);
current_texture->texture_data); glTexCoord2f(0.0,0.0); glVertex3f(current_texture->x1,current_texture->y1,0.0);
glTexCoord2f(1.0,0.0); glVertex3f(current_texture->x2,current_texture->y1,0.0);
glBegin(GL_QUADS); glTexCoord2f(1.0,1.0); glVertex3f(current_texture->x2,current_texture->y2,0.0);
glTexCoord2f(0.0,0.0); glVertex3f(current_texture->x1,current_texture->y1,0.0); glTexCoord2f(0.0,1.0); glVertex3f(current_texture->x1,current_texture->y2,0.0);
glTexCoord2f(1.0,0.0); glVertex3f(current_texture->x2,current_texture->y1,0.0); glEnd();
glTexCoord2f(1.0,1.0); glVertex3f(current_texture->x2,current_texture->y2,0.0); }
glTexCoord2f(0.0,1.0); glVertex3f(current_texture->x1,current_texture->y2,0.0);
glEnd(); }
} glFlush();
} glDisable(GL_TEXTURE_2D);
glFlush(); glDisable(GL_DEPTH_TEST);
glPopMatrix();
glDisable(GL_TEXTURE_2D); #endif
glDisable(GL_DEPTH_TEST); glFlush();
glPopMatrix(); SDL_GL_SwapBuffers();
#endif glDisable(GL_LIGHTING);
glFlush(); }
SDL_GL_SwapBuffers();
glDisable(GL_LIGHTING);
} void openGL_closeGraphics() {
}
void openGL_closeGraphics() {
}

View File

@ -1,450 +1,444 @@
/* The SDL hooks for the Super VMW graphics library */ /* The SDL hooks for the Super VMW graphics library */
#include <SDL.h> #include <SDL.h>
#include "svmwgraph.h" #include "svmwgraph.h"
#include <stdlib.h> /* For atexit() */ #include <stdlib.h> /* For atexit() */
/* Setup the Graphics */ /* Setup the Graphics */
/* Pass '0' to auto-detect bpp */ /* Pass '0' to auto-detect bpp */
void *SDL_setupGraphics(int *xsize,int *ysize,int *bpp, void *SDL_setupGraphics(int *xsize,int *ysize,int *bpp,
int fullscreen,int verbose) int fullscreen,int verbose)
{ {
SDL_Surface *sdl_screen=NULL; SDL_Surface *sdl_screen=NULL;
int mode; int mode;
SDL_Joystick *joy; SDL_Joystick *joy;
mode=SDL_SWSURFACE|SDL_HWPALETTE|SDL_HWSURFACE; mode=SDL_SWSURFACE|SDL_HWPALETTE|SDL_HWSURFACE;
if (fullscreen) mode|=SDL_FULLSCREEN; if (fullscreen) mode|=SDL_FULLSCREEN;
/* Initialize the SDL library */ /* Initialize the SDL library */
if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0 ) { if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0 ) {
fprintf(stderr, fprintf(stderr,
"Couldn't initialize SDL: %s\n", SDL_GetError()); "Couldn't initialize SDL: %s\n", SDL_GetError());
return NULL; return NULL;
} }
/* Clean up on exit */ /* Clean up on exit */
atexit(SDL_Quit); atexit(SDL_Quit);
/* Detect Joystick */ /* Detect Joystick */
if (SDL_NumJoysticks()>0){ if (SDL_NumJoysticks()>0){
/* Open joystick */ /* Open joystick */
joy=SDL_JoystickOpen(0); joy=SDL_JoystickOpen(0);
if (joy) { if (joy) {
printf("Opened Joystick 0\n"); printf("Opened Joystick 0\n");
printf("Name: %s\n", SDL_JoystickName(0)); printf("Name: %s\n", SDL_JoystickName(0));
SDL_JoystickEventState(SDL_ENABLE); SDL_JoystickEventState(SDL_ENABLE);
} }
} }
if (*bpp!=0) { if (*bpp!=0) {
/* Initialize the display */ /* Initialize the display */
sdl_screen = SDL_SetVideoMode(*xsize, *ysize, *bpp, mode); sdl_screen = SDL_SetVideoMode(*xsize, *ysize, *bpp, mode);
} }
else { else {
sdl_screen=SDL_SetVideoMode(*xsize,*ysize,0,mode); sdl_screen=SDL_SetVideoMode(*xsize,*ysize,0,mode);
} }
if ( sdl_screen == NULL ) { if ( sdl_screen == NULL ) {
fprintf(stderr, "ERROR! Couldn't set %dx%d video mode: %s\n", fprintf(stderr, "ERROR! Couldn't set %dx%d video mode: %s\n",
*xsize,*ysize,SDL_GetError()); *xsize,*ysize,SDL_GetError());
return NULL; return NULL;
} }
if (*bpp==0) *bpp=sdl_screen->format->BytesPerPixel*8; if (*bpp==0) *bpp=sdl_screen->format->BytesPerPixel*8;
if (verbose) { if (verbose) {
printf(" + SDL Graphics Initialization successful...\n"); printf(" + SDL Graphics Initialization successful...\n");
printf(" + Using %dx%dx%dbpp Visual...\n",*xsize,*ysize,*bpp); printf(" + Using %dx%dx%dbpp Visual...\n",*xsize,*ysize,*bpp);
#if BYTE_ORDER==LITTLE_ENDIAN #if BYTE_ORDER==LITTLE_ENDIAN
printf(" + Little-endian byte-order detected\n"); printf(" + Little-endian byte-order detected\n");
#else #else
printf(" + Big-endian byte-order detected\n"); printf(" + Big-endian byte-order detected\n");
#endif #endif
printf(" + Red: %x Green: %x Blue: %x Alpha: %x\n", printf(" + Red: %x Green: %x Blue: %x Alpha: %x\n",
sdl_screen->format->Rmask, sdl_screen->format->Rmask,
sdl_screen->format->Gmask, sdl_screen->format->Gmask,
sdl_screen->format->Bmask, sdl_screen->format->Bmask,
sdl_screen->format->Amask); sdl_screen->format->Amask);
} }
return sdl_screen; return sdl_screen;
} }
void SDL_flushPalette(vmwSVMWGraphState *state) { void SDL_flushPalette(vmwSVMWGraphState *state) {
SDL_Surface *target; SDL_Surface *target;
SDL_Color temp_col[256]; SDL_Color temp_col[256];
int i; int i;
if (state->bpp==8) { if (state->bpp==8) {
for(i=0;i<256;i++) { for(i=0;i<256;i++) {
temp_col[i].r=(state->palette[i]>>11)<<3; temp_col[i].r=(state->palette[i]>>11)<<3;
temp_col[i].g=((state->palette[i]>>5)&0x3f)<<2; temp_col[i].g=((state->palette[i]>>5)&0x3f)<<2;
temp_col[i].b=(state->palette[i]&0x1f)<<3; temp_col[i].b=(state->palette[i]&0x1f)<<3;
} }
target=(SDL_Surface *)state->output_screen; target=(SDL_Surface *)state->output_screen;
SDL_SetColors(target,temp_col,0,256); SDL_SetColors(target,temp_col,0,256);
} }
} }
void SDL_NoScale32bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) { void SDL_NoScale32bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
int x,y,color; int x,y,color;
unsigned char *s_pointer,*t_pointer; unsigned char *s_pointer,*t_pointer;
SDL_Surface *target; SDL_Surface *target;
target=(SDL_Surface *)target_p->output_screen; target=(SDL_Surface *)target_p->output_screen;
if ( SDL_MUSTLOCK(target) ) { if ( SDL_MUSTLOCK(target) ) {
if ( SDL_LockSurface(target) < 0 ) if ( SDL_LockSurface(target) < 0 )
return; return;
} }
s_pointer=source->memory; s_pointer=source->memory;
t_pointer=((Uint8 *)target->pixels); t_pointer=((Uint8 *)target->pixels);
// printf("%i %i\n",source->xsize,source->ysize); // printf("%i %i\n",source->xsize,source->ysize);
for (x=0;x<source->xsize;x++) for (x=0;x<source->xsize;x++)
for (y=0;y<source->ysize;y++) { for (y=0;y<source->ysize;y++) {
color=SDL_MapRGB(target->format,target_p->actual_pal[*(s_pointer)].r, color=SDL_MapRGB(target->format,target_p->actual_pal[*(s_pointer)].r,
target_p->actual_pal[*(s_pointer)].g, target_p->actual_pal[*(s_pointer)].g,
target_p->actual_pal[*(s_pointer)].b); target_p->actual_pal[*(s_pointer)].b);
*((Uint32 *)(t_pointer))=color; *((Uint32 *)(t_pointer))=color;
s_pointer++; t_pointer+=4; s_pointer++; t_pointer+=4;
} }
/* Update the display */ /* Update the display */
if ( SDL_MUSTLOCK(target) ) { if ( SDL_MUSTLOCK(target) ) {
SDL_UnlockSurface(target); SDL_UnlockSurface(target);
} }
/* Write this out to the screen */ /* Write this out to the screen */
SDL_UpdateRect(target, 0, 0, source->xsize, source->ysize); SDL_UpdateRect(target, 0, 0, source->xsize, source->ysize);
} }
void SDL_Double32bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) { void SDL_Double32bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
int x,y,scale,color; int x,y,color;//,scale;
unsigned char *s_pointer,*t_pointer; unsigned char *s_pointer,*t_pointer;
SDL_Surface *target; SDL_Surface *target;
target=(SDL_Surface *)target_p->output_screen; target=(SDL_Surface *)target_p->output_screen;
scale=target_p->scale; // scale=target_p->scale;
if ( SDL_MUSTLOCK(target) ) { if ( SDL_MUSTLOCK(target) ) {
if ( SDL_LockSurface(target) < 0 ) if ( SDL_LockSurface(target) < 0 )
return; return;
} }
s_pointer=source->memory; s_pointer=source->memory;
t_pointer=((Uint8 *)target->pixels); t_pointer=((Uint8 *)target->pixels);
for(y=0;y<source->ysize;y++) { for(y=0;y<source->ysize;y++) {
for(x=0;x<source->xsize;x++) { for(x=0;x<source->xsize;x++) {
color=SDL_MapRGB(target->format, color=SDL_MapRGB(target->format,
target_p->actual_pal[*(s_pointer)].r, target_p->actual_pal[*(s_pointer)].r,
target_p->actual_pal[*(s_pointer)].g, target_p->actual_pal[*(s_pointer)].g,
target_p->actual_pal[*(s_pointer)].b); target_p->actual_pal[*(s_pointer)].b);
/* i=0, j=0 */ /* i=0, j=0 */
*((Uint32 *) ( (t_pointer)))=color; *((Uint32 *) ( (t_pointer)))=color;
/* i=1, j=0 */ /* i=1, j=0 */
*((Uint32 *) ( (t_pointer+(4*target_p->xsize) )))=color; *((Uint32 *) ( (t_pointer+(4*target_p->xsize) )))=color;
/* i=0, j=1 */ /* i=0, j=1 */
*((Uint32 *) ( (t_pointer+4) ))=color; *((Uint32 *) ( (t_pointer+4) ))=color;
/* i=1 j=1 */ /* i=1 j=1 */
*((Uint32 *) ( (t_pointer+4+(4*target_p->xsize) )))=color; *((Uint32 *) ( (t_pointer+4+(4*target_p->xsize) )))=color;
s_pointer++; t_pointer+=8; s_pointer++; t_pointer+=8;
} }
t_pointer+=4*target_p->xsize; t_pointer+=4*target_p->xsize;
} }
/* Update the display */ /* Update the display */
if ( SDL_MUSTLOCK(target) ) { if ( SDL_MUSTLOCK(target) ) {
SDL_UnlockSurface(target); SDL_UnlockSurface(target);
} }
/* Write this out to the screen */ /* Write this out to the screen */
SDL_UpdateRect(target, 0, 0, target_p->xsize, target_p->ysize); SDL_UpdateRect(target, 0, 0, target_p->xsize, target_p->ysize);
} }
void SDL_NoScale16bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) { void SDL_NoScale16bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
int x,y; int x,y;
unsigned char *s_pointer,*t_pointer; unsigned char *s_pointer,*t_pointer;
SDL_Surface *target; SDL_Surface *target;
target=(SDL_Surface *)target_p->output_screen; target=(SDL_Surface *)target_p->output_screen;
if ( SDL_MUSTLOCK(target) ) { if ( SDL_MUSTLOCK(target) ) {
if ( SDL_LockSurface(target) < 0 ) if ( SDL_LockSurface(target) < 0 )
return; return;
} }
s_pointer=source->memory; s_pointer=source->memory;
t_pointer=((Uint8 *)target->pixels); t_pointer=((Uint8 *)target->pixels);
// printf("%i %i\n",source->xsize,source->ysize); // printf("%i %i\n",source->xsize,source->ysize);
for (x=0;x<source->xsize;x++) for (x=0;x<source->xsize;x++)
for (y=0;y<source->ysize;y++) { for (y=0;y<source->ysize;y++) {
*((Uint16 *)(t_pointer))=target_p->palette[*(s_pointer)]; *((Uint16 *)(t_pointer))=target_p->palette[*(s_pointer)];
s_pointer++; t_pointer+=2; s_pointer++; t_pointer+=2;
} }
/* Update the display */
/* Update the display */ if ( SDL_MUSTLOCK(target) ) {
if ( SDL_MUSTLOCK(target) ) { SDL_UnlockSurface(target);
SDL_UnlockSurface(target); }
}
/* Write this out to the screen */
/* Write this out to the screen */ SDL_UpdateRect(target, 0, 0, source->xsize, source->ysize);
SDL_UpdateRect(target, 0, 0, source->xsize, source->ysize);
}
}
/* I should make this generic, but it makes it really slow */
/* I should make this generic, but it makes it really slow */ void SDL_Double16bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
void SDL_Double16bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
int x,y;
int x,y,scale;
unsigned char *s_pointer,*t_pointer;
unsigned char *s_pointer,*t_pointer;
SDL_Surface *target;
SDL_Surface *target;
target=(SDL_Surface *)target_p->output_screen;
target=(SDL_Surface *)target_p->output_screen;
//scale=target_p->scale;
scale=target_p->scale;
if ( SDL_MUSTLOCK(target) ) {
if ( SDL_MUSTLOCK(target) ) { if ( SDL_LockSurface(target) < 0 )
if ( SDL_LockSurface(target) < 0 ) return;
return; }
}
s_pointer=source->memory;
s_pointer=source->memory; t_pointer=((Uint8 *)target->pixels);
t_pointer=((Uint8 *)target->pixels);
for (y=0;y<source->ysize;y++) {
for (y=0;y<source->ysize;y++) { for (x=0;x<source->xsize;x++) {
for (x=0;x<source->xsize;x++) {
/* i=0, j=0 */
/* i=0, j=0 */ *((Uint16 *) ( (t_pointer)))=
*((Uint16 *) ( (t_pointer)))= target_p->palette[*(s_pointer)];
target_p->palette[*(s_pointer)];
/* i=1, j=0 */
/* i=1, j=0 */ *((Uint16 *) ( (t_pointer+(2*target_p->xsize) )))=
*((Uint16 *) ( (t_pointer+(2*target_p->xsize) )))= target_p->palette[*(s_pointer)];
target_p->palette[*(s_pointer)]; /* i=0, j=1 */
/* i=0, j=1 */ *((Uint16 *) ( (t_pointer+2) ))=
*((Uint16 *) ( (t_pointer+2) ))= target_p->palette[*(s_pointer)];
target_p->palette[*(s_pointer)];
/* i=1 j=1 */
/* i=1 j=1 */ *((Uint16 *) ( (t_pointer+2+(2*target_p->xsize) )))=
*((Uint16 *) ( (t_pointer+2+(2*target_p->xsize) )))= target_p->palette[*(s_pointer)];
target_p->palette[*(s_pointer)];
s_pointer++; t_pointer+=4;
}
s_pointer++; t_pointer+=4; t_pointer+=2*target_p->xsize;
} }
t_pointer+=2*target_p->xsize;
} /* Update the display */
if ( SDL_MUSTLOCK(target) ) {
SDL_UnlockSurface(target);
/* Update the display */ }
if ( SDL_MUSTLOCK(target) ) {
SDL_UnlockSurface(target); /* Write this out to the screen */
} SDL_UpdateRect(target, 0, 0, target_p->xsize, target_p->ysize);
/* Write this out to the screen */ }
SDL_UpdateRect(target, 0, 0, target_p->xsize, target_p->ysize);
void SDL_NoScale8bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
}
int x,y;
void SDL_NoScale8bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
unsigned char *s_pointer,*t_pointer;
int x,y;
SDL_Surface *target;
unsigned char *s_pointer,*t_pointer;
target=(SDL_Surface *)target_p->output_screen;
SDL_Surface *target;
if ( SDL_MUSTLOCK(target) ) {
target=(SDL_Surface *)target_p->output_screen; if ( SDL_LockSurface(target) < 0 )
return;
if ( SDL_MUSTLOCK(target) ) { }
if ( SDL_LockSurface(target) < 0 )
return; s_pointer=source->memory;
} t_pointer=((Uint8 *)target->pixels);
s_pointer=source->memory; for (x=0;x<source->xsize;x++)
t_pointer=((Uint8 *)target->pixels); for (y=0;y<source->ysize;y++) {
*((Uint8 *)(t_pointer))=*(s_pointer);
for (x=0;x<source->xsize;x++) s_pointer++; t_pointer++;
for (y=0;y<source->ysize;y++) { }
*((Uint8 *)(t_pointer))=*(s_pointer);
s_pointer++; t_pointer++; /* Update the display */
} if ( SDL_MUSTLOCK(target) ) {
SDL_UnlockSurface(target);
}
/* Update the display */
if ( SDL_MUSTLOCK(target) ) { /* Write this out to the screen */
SDL_UnlockSurface(target); SDL_UpdateRect(target, 0, 0, source->xsize, source->ysize);
}
}
/* Write this out to the screen */
SDL_UpdateRect(target, 0, 0, source->xsize, source->ysize);
void SDL_Double8bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
}
int x,y;
void SDL_Double8bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) { unsigned char *s_pointer,*t_pointer;
int x,y; SDL_Surface *target;
unsigned char *s_pointer,*t_pointer; target=(SDL_Surface *)target_p->output_screen;
SDL_Surface *target; if ( SDL_MUSTLOCK(target) ) {
if ( SDL_LockSurface(target) < 0 )
target=(SDL_Surface *)target_p->output_screen; return;
}
if ( SDL_MUSTLOCK(target) ) {
if ( SDL_LockSurface(target) < 0 ) s_pointer=source->memory;
return; t_pointer=((Uint8 *)target->pixels);
}
for (y=0;y<source->ysize;y++) {
s_pointer=source->memory; for (x=0;x<source->xsize;x++) {
t_pointer=((Uint8 *)target->pixels); /* i=0, j=0 */
*((Uint8 *)(t_pointer))=*(s_pointer);
for (y=0;y<source->ysize;y++) { /* i=1, j=0 */
for (x=0;x<source->xsize;x++) { *((Uint8 *)(t_pointer+(target_p->xsize)))=*(s_pointer);
/* i=0, j=0 */ /* i=0, j=1 */
*((Uint8 *)(t_pointer))=*(s_pointer); *((Uint8 *)(t_pointer+1))=*(s_pointer);
/* i=1, j=0 */ /* i=1, j=1 */
*((Uint8 *)(t_pointer+(target_p->xsize)))=*(s_pointer); *((Uint8 *)(t_pointer+1+target_p->xsize))=*(s_pointer);
/* i=0, j=1 */ s_pointer++; t_pointer+=2;
*((Uint8 *)(t_pointer+1))=*(s_pointer); }
/* i=1, j=1 */ t_pointer+=target_p->xsize;
*((Uint8 *)(t_pointer+1+target_p->xsize))=*(s_pointer); }
s_pointer++; t_pointer+=2;
} /* Update the display */
t_pointer+=target_p->xsize; if ( SDL_MUSTLOCK(target) ) {
} SDL_UnlockSurface(target);
}
/* Update the display */
if ( SDL_MUSTLOCK(target) ) { /* Write this out to the screen */
SDL_UnlockSurface(target); SDL_UpdateRect(target, 0, 0, target_p->xsize, target_p->ysize);
} }
/* Write this out to the screen */
SDL_UpdateRect(target, 0, 0, target_p->xsize, target_p->ysize); void SDL_clearKeyboardBuffer(void) {
SDL_Event event;
} while (SDL_PollEvent(&event)) {
}
}
void SDL_clearKeyboardBuffer() {
SDL_Event event; int SDL_getInput(void) {
while (SDL_PollEvent(&event)) {
SDL_Event event;
} int keypressed,button;
} int axis,direction;
int SDL_getInput() { static int going_right=0;
static int going_left=0;
SDL_Event event;
int keypressed,button; while ( SDL_PollEvent(&event)) {
int axis,direction;
switch(event.type) {
static int going_right=0; case SDL_JOYBUTTONDOWN:
static int going_left=0; button=event.jbutton.button;
// printf("BUTTON %i\n",button);
while ( SDL_PollEvent(&event)) { switch(button) {
case 0: return ' ';
switch(event.type) { case 1: return VMW_ENTER;
case SDL_JOYBUTTONDOWN: }
button=event.jbutton.button; break;
// printf("BUTTON %i\n",button); case SDL_JOYAXISMOTION:
switch(button) { axis=event.jaxis.axis;
case 0: return ' '; direction=event.jaxis.value;
case 1: return VMW_ENTER; // printf("%i %i\n",axis,direction);
} if (axis==0) { /* X */
break;
case SDL_JOYAXISMOTION: if (direction>5000) {
axis=event.jaxis.axis; if (!going_right) {
direction=event.jaxis.value; going_right=1;
// printf("%i %i\n",axis,direction); return VMW_RIGHT;
if (axis==0) { /* X */ }
}
if (direction>5000) { else if (direction<-5000) {
if (!going_right) { if (!going_left) {
going_right=1; going_left=1;
return VMW_RIGHT; return VMW_LEFT;
} }
} }
else if (direction<-5000) { else {
if (!going_left) { going_left=0;
going_left=1; going_right=0;
return VMW_LEFT; }
} }
} // if (axis==1) { /* Y */
else { // if (direction>0) return VMW_UP;
going_left=0; // if (direction<0) return VMW_DOWN;
going_right=0; // }
}
} break;
// if (axis==1) { /* Y */ case SDL_KEYDOWN:
// if (direction>0) return VMW_UP; keypressed=event.key.keysym.sym;
// if (direction<0) return VMW_DOWN; switch (keypressed) {
// } case SDLK_BACKSPACE: return VMW_BACKSPACE;
case SDLK_ESCAPE : return VMW_ESCAPE;
break; case SDLK_RETURN : return VMW_ENTER;
case SDL_KEYDOWN: case SDLK_UP : return VMW_UP;
keypressed=event.key.keysym.sym; case SDLK_DOWN : return VMW_DOWN;
switch (keypressed) { case SDLK_RIGHT : return VMW_RIGHT;
case SDLK_BACKSPACE: return VMW_BACKSPACE; case SDLK_LEFT : return VMW_LEFT;
case SDLK_ESCAPE : return VMW_ESCAPE; case SDLK_F1 : return VMW_F1;
case SDLK_RETURN : return VMW_ENTER; case SDLK_F2 : return VMW_F2;
case SDLK_UP : return VMW_UP; case SDLK_PAGEUP : return VMW_PGUP;
case SDLK_DOWN : return VMW_DOWN; case SDLK_PAGEDOWN : return VMW_PGDN;
case SDLK_RIGHT : return VMW_RIGHT; case SDLK_HOME : return VMW_HOME;
case SDLK_LEFT : return VMW_LEFT; case SDLK_END : return VMW_END;
case SDLK_F1 : return VMW_F1; case SDLK_INSERT : return VMW_INS;
case SDLK_F2 : return VMW_F2; case SDLK_DELETE : return VMW_DEL;
case SDLK_PAGEUP : return VMW_PGUP; default: if ((keypressed>='a') && (keypressed<='z')
case SDLK_PAGEDOWN : return VMW_PGDN; && (event.key.keysym.mod & KMOD_SHIFT) )
case SDLK_HOME : return VMW_HOME; return keypressed-32;
case SDLK_END : return VMW_END; else return keypressed;
case SDLK_INSERT : return VMW_INS; }
case SDLK_DELETE : return VMW_DEL; default: break;
default: if ((keypressed>='a') && (keypressed<='z') }
&& (event.key.keysym.mod & KMOD_SHIFT) ) }
return keypressed-32; return 0;
else return keypressed; }
}
default: break; void SDL_closeGraphics() {
} }
}
return 0;
}
void SDL_closeGraphics() {
}

View File

@ -1,334 +1,335 @@
/* An implementation of my own legacy "PaintPro[gram] graphics format */ /* An implementation of my own legacy "PaintPro[gram] graphics format */
/* The format is seemingly very random, but it was sort of OK for */ /* The format is seemingly very random, but it was sort of OK for */
/* my skill level at the time */ /* my skill level at the time */
/* Version 1 was just, in text ASCII, a list of COLOR followed on a /* Version 1 was just, in text ASCII, a list of COLOR followed on a
* new line by num-across, a very primitive RLE [Run-Length-Encoding] * new line by num-across, a very primitive RLE [Run-Length-Encoding]
* Compression scheme [which I thought up on my own] */ * Compression scheme [which I thought up on my own] */
/* Later versions supported 256 color mode, and made sure the BASIC /* Later versions supported 256 color mode, and made sure the BASIC
* loader worked */ * loader worked */
/* There was an actual "PaintPro program, written in TurboPascal /* There was an actual "PaintPro program, written in TurboPascal
* that was fairly decent considering. It would edit in * that was fairly decent considering. It would edit in
* the EGA and VGA 16 color modes, and later mode13 320x200x256 */ * the EGA and VGA 16 color modes, and later mode13 320x200x256 */
/* The files were still pretty large, so Version 5 implemented /* The files were still pretty large, so Version 5 implemented
* "Packing", basically shoving the color and numacross into * "Packing", basically shoving the color and numacross into
* a 24 bit value. This, along with block-reading rapidly * a 24 bit value. This, along with block-reading rapidly
* reduced load times */ * reduced load times */
/* Version 6 added a fancy header, along with palette saving, and /* Version 6 added a fancy header, along with palette saving, and
* an optimization of storing multiple 1-pixel runs in half the size. * an optimization of storing multiple 1-pixel runs in half the size.
* Before this palette files were stored separately. */ * Before this palette files were stored separately. */
/* The resulting file format is very similar [quite accidentally] to /* The resulting file format is very similar [quite accidentally] to
* the PCX file format. Why don't I make paintpro files obsolete? * the PCX file format. Why don't I make paintpro files obsolete?
* nostalgia mostly. */ * nostalgia mostly. */
/* Paintpro files usually have the extension .AMG [AMazing Graphics, /* Paintpro files usually have the extension .AMG [AMazing Graphics,
* an inside joke], .PPP [Paint Pro Packed], .PRO, or .TB1 [from * an inside joke], .PPP [Paint Pro Packed], .PRO, or .TB1 [from
* Tom Bombem */ * Tom Bombem */
#include "svmwgraph.h" #include "svmwgraph.h"
#include <stdio.h> /* For FILE I/O */ #include <stdio.h> /* For FILE I/O */
#include <string.h> /* For strncmp */ #include <string.h> /* For strncmp */
#include <fcntl.h> /* for open() */ #include <fcntl.h> /* for open() */
#include <unistd.h> /* for lseek() */ #include <unistd.h> /* for lseek() */
#include <sys/stat.h> /* for file modes */ #include <stdlib.h> /* for calloc() */
#include <sys/stat.h> /* for file modes */
/* Take a 24bit value [3 bytes] and split the top and bottom */
/* 12 bits into 2 integers */ /* Take a 24bit value [3 bytes] and split the top and bottom */
#define THREE_BYTES_INT1(a,b) ( ( ( (int)(a))<<4)+ ((b)>>4) ) /* 12 bits into 2 integers */
#define THREE_BYTES_INT2(b,c) ( ( ( ( (int)(b))&0x0f)<<8)+ (c)) #define THREE_BYTES_INT1(a,b) ( ( ( (int)(a))<<4)+ ((b)>>4) )
#define THREE_BYTES_INT2(b,c) ( ( ( ( (int)(b))&0x0f)<<8)+ (c))
/* Do the opposite. Take 2 ints and make 3 bytes */
/* Do the opposite. Take 2 ints and make 3 bytes */
#define TWO_INTS_THREE_BYTES(a,b) three_bytes[0]=((unsigned char)(((a)>>4)&0xff)); three_bytes[1]=((unsigned char) ( (((a)&0x0f)<<4)+(((b)>>8)&0x0f))); three_bytes[2]=((unsigned char)((b)&0xff));
#define TWO_INTS_THREE_BYTES(a,b) three_bytes[0]=((unsigned char)(((a)>>4)&0xff)); three_bytes[1]=((unsigned char) ( (((a)&0x0f)<<4)+(((b)>>8)&0x0f))); three_bytes[2]=((unsigned char)((b)&0xff));
vmwPaintProHeader *vmwGetPaintProHeader(char *filename) {
vmwPaintProHeader *vmwGetPaintProHeader(char *filename) {
FILE *fff;
static vmwPaintProHeader *header=NULL; FILE *fff;
unsigned char buffer[18]; static vmwPaintProHeader *header=NULL;
int i; unsigned char buffer[18];
int i;
if ( (fff=fopen(filename,"rb"))==NULL) { /* b for w32 stupidity */
printf("Error! %s does not exist!\n",filename); if ( (fff=fopen(filename,"rb"))==NULL) { /* b for w32 stupidity */
return NULL; printf("Error! %s does not exist!\n",filename);
} return NULL;
}
if (fread(buffer,1,18,fff)!=18) {
printf("Error! Corrupted paintpro header!\n"); if (fread(buffer,1,18,fff)!=18) {
return NULL; printf("Error! Corrupted paintpro header!\n");
} return NULL;
}
fclose(fff);
fclose(fff);
if (header==NULL) {
if (( header=calloc(1,sizeof(vmwPaintProHeader)))==NULL) { if (header==NULL) {
printf("Error! Seriously low on memory!\n"); if (( header=calloc(1,sizeof(vmwPaintProHeader)))==NULL) {
return NULL; printf("Error! Seriously low on memory!\n");
} return NULL;
} }
}
/* Load PAINTPRO string */
for(i=0;i<8;i++) header->ppro_string[i]=buffer[i]; /* Load PAINTPRO string */
for(i=0;i<4;i++) header->version[i]=buffer[i+8]; for(i=0;i<8;i++) header->ppro_string[i]=buffer[i];
header->xsize=THREE_BYTES_INT1(buffer[12],buffer[13]); for(i=0;i<4;i++) header->version[i]=buffer[i+8];
header->ysize=THREE_BYTES_INT2(buffer[13],buffer[14]); header->xsize=THREE_BYTES_INT1(buffer[12],buffer[13]);
header->num_colors=THREE_BYTES_INT1(buffer[15],buffer[16]); header->ysize=THREE_BYTES_INT2(buffer[13],buffer[14]);
header->num_colors=THREE_BYTES_INT1(buffer[15],buffer[16]);
return header;
} return header;
}
/*---------------------------------------------------------------*\
| vmwLoadPicPacked | /*---------------------------------------------------------------*\
| There is so much history in this function, I won't get into | | vmwLoadPicPacked |
| it here. See the paintpro documentation found elsewhere | | There is so much history in this function, I won't get into |
\*---------------------------------------------------------------*/ | it here. See the paintpro documentation found elsewhere |
\*---------------------------------------------------------------*/
int vmwLoadPicPacked(int x1,int y1,vmwVisual *target,
int LoadPal,int LoadPic,char *FileName, int vmwLoadPicPacked(int x1,int y1,vmwVisual *target,
vmwSVMWGraphState *graph_state) int LoadPal,int LoadPic,char *FileName,
vmwSVMWGraphState *graph_state)
/* Retro comments */
/*{ Loads a paintpro image, filename, at location x1,y1 *\ /* Retro comments */
\* to offset where (vga=$A000) and loadspal if LOADPAL=true */ /*{ Loads a paintpro image, filename, at location x1,y1 *\
/* Loadsapicture if Loadpic=true and returns error} */ \* to offset where (vga=$A000) and loadspal if LOADPAL=true */
/* Loadsapicture if Loadpic=true and returns error} */
{
int x,y,i; {
int ppro_fd; int x,y,i;
int color,numacross; int ppro_fd;
int read_status; int color,numacross;
vmwPaintProHeader *ppro_header; int read_status;
unsigned char three_bytes[3]; vmwPaintProHeader *ppro_header;
int broken=0; unsigned char three_bytes[3];
int broken=0;
if ( (ppro_header=vmwGetPaintProHeader(FileName))==NULL) {
printf("ERROR! Invalid Header in %s!\n",FileName); if ( (ppro_header=vmwGetPaintProHeader(FileName))==NULL) {
return VMW_ERROR_FILE; printf("ERROR! Invalid Header in %s!\n",FileName);
} return VMW_ERROR_FILE;
}
/* Open the file */
ppro_fd=open(FileName,O_RDONLY); /* Open the file */
ppro_fd=open(FileName,O_RDONLY);
if (ppro_fd<0) {
printf("ERROR! File \"%s\" not found!\n",FileName); if (ppro_fd<0) {
return VMW_ERROR_FILE; printf("ERROR! File \"%s\" not found!\n",FileName);
} return VMW_ERROR_FILE;
}
/* Check to see if its really a Paintpro File */
if (strncmp(ppro_header->ppro_string,"PAINTPRO",8)) { /* Check to see if its really a Paintpro File */
printf("ERROR! %s is NOT a paintpro file!\n",FileName); if (strncmp(ppro_header->ppro_string,"PAINTPRO",8)) {
return VMW_ERROR_INVALID; printf("ERROR! %s is NOT a paintpro file!\n",FileName);
} return VMW_ERROR_INVALID;
}
/* Check to see if it is the proper version (currently 6.0) */
if (strncmp(ppro_header->version,"V6.1",4)) { /* Check to see if it is the proper version (currently 6.0) */
if (!strncmp(ppro_header->version,"V6.0",4)) { if (strncmp(ppro_header->version,"V6.1",4)) {
printf("Warning! Broken 6.0 file! Please convert.\n"); if (!strncmp(ppro_header->version,"V6.0",4)) {
broken=1; printf("Warning! Broken 6.0 file! Please convert.\n");
} broken=1;
else { }
printf("ERROR! %s unsupported, must be >=6.0\n", else {
ppro_header->version); printf("ERROR! %s unsupported, must be >=6.0\n",
return VMW_ERROR_INVALID; ppro_header->version);
} return VMW_ERROR_INVALID;
} }
}
/*Load Palette*/
if (ppro_header->num_colors>256) /*Load Palette*/
printf("More than 256 colors not supported yet (%d)\n", if (ppro_header->num_colors>256)
ppro_header->num_colors); printf("More than 256 colors not supported yet (%d)\n",
ppro_header->num_colors);
/* Seek past the header */
lseek(ppro_fd,18,SEEK_SET); /* Seek past the header */
lseek(ppro_fd,18,SEEK_SET);
/* Fun and games to convert the 24 bit color in paintpro to */
/* 565 packed 16bit RGB */ /* Fun and games to convert the 24 bit color in paintpro to */
/* 565 packed 16bit RGB */
if (!LoadPal) {
/* Skip past palette if not loading it */ if (!LoadPal) {
lseek(ppro_fd,3*ppro_header->num_colors,SEEK_CUR); /* Skip past palette if not loading it */
} lseek(ppro_fd,3*ppro_header->num_colors,SEEK_CUR);
else { }
for(i=0;i<ppro_header->num_colors;i++) { else {
read_status=read(ppro_fd,&three_bytes,3); for(i=0;i<ppro_header->num_colors;i++) {
vmwLoadPalette(graph_state, read_status=read(ppro_fd,&three_bytes,3);
three_bytes[0], vmwLoadPalette(graph_state,
three_bytes[1], three_bytes[0],
three_bytes[2],i); three_bytes[1],
} three_bytes[2],i);
vmwFlushPalette(graph_state); }
} vmwFlushPalette(graph_state);
}
if (!LoadPic) {
close(ppro_fd); if (!LoadPic) {
return 0; /* We already loaded the palette */ close(ppro_fd);
} return 0; /* We already loaded the palette */
}
x=x1;
y=y1; x=x1;
y=y1;
while (y<y1+ppro_header->ysize) {
/* Read in next 3 bytes */ while (y<y1+ppro_header->ysize) {
read_status=read(ppro_fd,&three_bytes,3); /* Read in next 3 bytes */
read_status=read(ppro_fd,&three_bytes,3);
/* If we read less than 3, something is wrong */
if (read_status<3) { /* If we read less than 3, something is wrong */
printf("Ran out of data too soon!\n"); if (read_status<3) {
break; printf("Ran out of data too soon!\n");
} break;
}
color=THREE_BYTES_INT1(three_bytes[0],three_bytes[1]);
numacross=THREE_BYTES_INT2(three_bytes[1],three_bytes[2]); color=THREE_BYTES_INT1(three_bytes[0],three_bytes[1]);
numacross=THREE_BYTES_INT2(three_bytes[1],three_bytes[2]);
/* If int1 greater than 2047, we have two single pixels */
/* of color int1-2048 and int2-2048 */ /* If int1 greater than 2047, we have two single pixels */
if (color>2047) { /* of color int1-2048 and int2-2048 */
vmwPutPixel(x,y,color-2048,target); if (color>2047) {
x++; vmwPutPixel(x,y,color-2048,target);
if (x>=ppro_header->xsize+x1) { x++;
x=x1; y++; if (x>=ppro_header->xsize+x1) {
} x=x1; y++;
vmwPutPixel(x,y,numacross-2048,target); }
x++; vmwPutPixel(x,y,numacross-2048,target);
if (x>=ppro_header->xsize+x1){ x++;
x=x1;y++; if (x>=ppro_header->xsize+x1){
} x=x1;y++;
} }
else { /* Standard paintpro format */ }
/* Wrap if numacross is bigger than width */ else { /* Standard paintpro format */
while ((x+numacross)>=(ppro_header->xsize+x1)) { /* Wrap if numacross is bigger than width */
vmwDrawHLine(x,y,((ppro_header->xsize+x1)-x),color,target); while ((x+numacross)>=(ppro_header->xsize+x1)) {
/* Old versions of paintro created broken */ vmwDrawHLine(x,y,((ppro_header->xsize+x1)-x),color,target);
/* Files which need an extra +1 after xsize */ /* Old versions of paintro created broken */
/* In the following line */ /* Files which need an extra +1 after xsize */
numacross=numacross-((ppro_header->xsize+broken)-x); /* In the following line */
x=x1; numacross=numacross-((ppro_header->xsize+broken)-x);
y++; x=x1;
} y++;
}
if (numacross!=0) {
if (y>=y1+ppro_header->ysize) { if (numacross!=0) {
printf("Trying to draw past end of screen %d\n",y); if (y>=y1+ppro_header->ysize) {
} printf("Trying to draw past end of screen %d\n",y);
if (numacross > ppro_header->xsize-1) { }
printf("X too big?%d\n",numacross); if (numacross > ppro_header->xsize-1) {
} printf("X too big?%d\n",numacross);
vmwDrawHLine(x,y,numacross,color,target); }
} vmwDrawHLine(x,y,numacross,color,target);
x=x+numacross; }
} x=x+numacross;
} }
close(ppro_fd); }
return 0; close(ppro_fd);
} return 0;
}
int vmwSavePicPacked(int x1,int y1,int xsize,int ysize,
vmwVisual *source, int vmwSavePicPacked(int x1,int y1,int xsize,int ysize,
int num_colors, vmwVisual *source,
vmw24BitPal *palette, int num_colors,
char *FileName) { vmw24BitPal *palette,
char *FileName) {
int ppro_fd,i,x,y,color=0,oldcolor=-1,numacross=0;
int already_have_single_pixel=0; int ppro_fd,i,x,y,color=0,oldcolor=-1,numacross=0;
int save_pixel=0; int already_have_single_pixel=0;
char ppro_string[]="PAINTPRO"; int save_pixel=0;
char ppro_version[]="V6.1"; char ppro_string[]="PAINTPRO";
unsigned char three_bytes[3]; char ppro_version[]="V6.1";
unsigned char three_bytes[3];
ppro_fd=open(FileName,O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR);
if (ppro_fd<0) { ppro_fd=open(FileName,O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR);
printf("Error opening \"%s\" for writing!\n",FileName); if (ppro_fd<0) {
return VMW_ERROR_FILE; printf("Error opening \"%s\" for writing!\n",FileName);
} return VMW_ERROR_FILE;
}
/* 8 bytes, "PAINTPRO" */
write(ppro_fd,ppro_string,8); /* 8 bytes, "PAINTPRO" */
/* 4 bytes, "V6.0" */ write(ppro_fd,ppro_string,8);
write(ppro_fd,ppro_version,4); /* 4 bytes, "V6.0" */
write(ppro_fd,ppro_version,4);
/* xsize, ysize */
TWO_INTS_THREE_BYTES(xsize,ysize); /* xsize, ysize */
write(ppro_fd,three_bytes,3); TWO_INTS_THREE_BYTES(xsize,ysize);
/* num_colors, 0 */ write(ppro_fd,three_bytes,3);
TWO_INTS_THREE_BYTES(num_colors,0); /* num_colors, 0 */
write(ppro_fd,three_bytes,3); TWO_INTS_THREE_BYTES(num_colors,0);
write(ppro_fd,three_bytes,3);
/* Write num_colors r,g,b */
for(i=0;i<num_colors;i++) { /* Write num_colors r,g,b */
three_bytes[0]=palette[i].r; for(i=0;i<num_colors;i++) {
three_bytes[1]=palette[i].g; three_bytes[0]=palette[i].r;
three_bytes[2]=palette[i].b; three_bytes[1]=palette[i].g;
write(ppro_fd,three_bytes,3); three_bytes[2]=palette[i].b;
} write(ppro_fd,three_bytes,3);
}
y=y1;
x=x1; y=y1;
x=x1;
/* Set up initial conditions */
oldcolor=vmwGetPixel(x,y,source); /* Set up initial conditions */
oldcolor=vmwGetPixel(x,y,source);
while (y<y1+ysize) {
color=vmwGetPixel(x,y,source); while (y<y1+ysize) {
if ((color==oldcolor)&&(numacross<2046)) numacross++; color=vmwGetPixel(x,y,source);
else { /* This pixel not the same color as previous */ if ((color==oldcolor)&&(numacross<2046)) numacross++;
if (numacross==1) { else { /* This pixel not the same color as previous */
/* Special case for 1 pixel value */ if (numacross==1) {
if (!already_have_single_pixel) { /* Special case for 1 pixel value */
/* We are the first, so save it in hopes of a 2nd */ if (!already_have_single_pixel) {
save_pixel=oldcolor; /* We are the first, so save it in hopes of a 2nd */
already_have_single_pixel=1; save_pixel=oldcolor;
} already_have_single_pixel=1;
else { }
/* We got a second. Pack the two together */ else {
TWO_INTS_THREE_BYTES(save_pixel+2048,oldcolor+2048); /* We got a second. Pack the two together */
write(ppro_fd,three_bytes,3); TWO_INTS_THREE_BYTES(save_pixel+2048,oldcolor+2048);
already_have_single_pixel=0; write(ppro_fd,three_bytes,3);
} already_have_single_pixel=0;
} }
else { /* We are more than 1 pixel in a row */ }
if (already_have_single_pixel) { else { /* We are more than 1 pixel in a row */
/* Oops.. wanted to pack, but we can't */ if (already_have_single_pixel) {
TWO_INTS_THREE_BYTES(save_pixel,1); /* Oops.. wanted to pack, but we can't */
write(ppro_fd,three_bytes,3); TWO_INTS_THREE_BYTES(save_pixel,1);
already_have_single_pixel=0; write(ppro_fd,three_bytes,3);
} already_have_single_pixel=0;
/* Write out color, and numacross */ }
TWO_INTS_THREE_BYTES(oldcolor,numacross); /* Write out color, and numacross */
write(ppro_fd,three_bytes,3); TWO_INTS_THREE_BYTES(oldcolor,numacross);
} write(ppro_fd,three_bytes,3);
oldcolor=color; }
numacross=1; oldcolor=color;
} numacross=1;
x++; }
if (x>=x1+xsize) { x++;
x=x1; if (x>=x1+xsize) {
y++; x=x1;
} y++;
} }
/* Write out data left */ }
if (already_have_single_pixel) { /* Write out data left */
/* Oops.. wanted to pack, but we can't */ if (already_have_single_pixel) {
TWO_INTS_THREE_BYTES(save_pixel,1); /* Oops.. wanted to pack, but we can't */
write(ppro_fd,three_bytes,3); TWO_INTS_THREE_BYTES(save_pixel,1);
} write(ppro_fd,three_bytes,3);
}
/* Write out the last run */
TWO_INTS_THREE_BYTES(color,numacross); /* Write out the last run */
write(ppro_fd,three_bytes,3); TWO_INTS_THREE_BYTES(color,numacross);
write(ppro_fd,three_bytes,3);
close(ppro_fd);
return 0; close(ppro_fd);
return 0;
}
}

View File

@ -1,306 +1,303 @@
/* WARNING! These functions only work at 320x200x8bpp right now */ /* WARNING! These functions only work at 320x200x8bpp right now */
/* It is easy to obtain the docs to make this load/save arbitrary */ /* It is easy to obtain the docs to make this load/save arbitrary */
/* PCX files. However, I don't have the time nor the inclination */ /* PCX files. However, I don't have the time nor the inclination */
/* To do it right now ;) */ /* To do it right now ;) */
/* Routines to Load/Save PCX graphics files. */ /* Routines to Load/Save PCX graphics files. */
#include "svmwgraph.h" #include "svmwgraph.h"
#include <stdio.h> /* For FILE I/O */ #include <stdio.h> /* For FILE I/O */
#include <string.h> /* For strncmp */ #include <string.h> /* For strncmp */
#include <fcntl.h> /* for open() */ #include <fcntl.h> /* for open() */
#include <unistd.h> /* for lseek() */ #include <unistd.h> /* for lseek() */
#include <sys/stat.h> /* for file modes */ #include <stdlib.h> /* for calloc() */
#include <sys/stat.h> /* for file modes */
int vmwGetPCXInfo(char *FileName, int *xsize, int *ysize, int *type) {
int vmwGetPCXInfo(char *FileName, int *xsize, int *ysize, int *type) {
unsigned char pcx_header[128];
int xmin,ymin,xmax,ymax,version=PCX_UNKNOWN,bpp,debug=1,pcx_fd; unsigned char pcx_header[128];
int xmin,ymin,xmax,ymax,version=PCX_UNKNOWN,bpp,debug=1,pcx_fd;
/* Open the file */
pcx_fd=open(FileName,O_RDONLY); /* Open the file */
pcx_fd=open(FileName,O_RDONLY);
if (pcx_fd<0) {
printf("ERROR! File \"%s\" not found!\n",FileName); if (pcx_fd<0) {
return VMW_ERROR_FILE; printf("ERROR! File \"%s\" not found!\n",FileName);
} return VMW_ERROR_FILE;
}
lseek(pcx_fd,0,SEEK_SET);
lseek(pcx_fd,0,SEEK_SET);
read(pcx_fd,&pcx_header,128);
read(pcx_fd,&pcx_header,128);
xmin=(pcx_header[5]<<8)+pcx_header[4];
ymin=(pcx_header[7]<<8)+pcx_header[6]; xmin=(pcx_header[5]<<8)+pcx_header[4];
ymin=(pcx_header[7]<<8)+pcx_header[6];
xmax=(pcx_header[9]<<8)+pcx_header[8];
ymax=(pcx_header[11]<<8)+pcx_header[10]; xmax=(pcx_header[9]<<8)+pcx_header[8];
ymax=(pcx_header[11]<<8)+pcx_header[10];
version=pcx_header[1];
bpp=pcx_header[3]; version=pcx_header[1];
bpp=pcx_header[3];
if (debug) {
if (debug) {
printf("Manufacturer: ");
if (pcx_header[0]==10) printf("Zsoft\n"); printf("Manufacturer: ");
else printf("Unknown %i\n",pcx_header[0]); if (pcx_header[0]==10) printf("Zsoft\n");
else printf("Unknown %i\n",pcx_header[0]);
printf("Version: ");
printf("Version: ");
switch(version) {
case 0: printf("2.5\n"); break; switch(version) {
case 2: printf("2.8 w palette\n"); break; case 0: printf("2.5\n"); break;
case 3: printf("2.8 w/o palette\n"); break; case 2: printf("2.8 w palette\n"); break;
case 4: printf("Paintbrush for Windows\n"); break; case 3: printf("2.8 w/o palette\n"); break;
case 5: printf("3.0+\n"); break; case 4: printf("Paintbrush for Windows\n"); break;
default: printf("Unknown %i\n",version); case 5: printf("3.0+\n"); break;
} default: printf("Unknown %i\n",version);
printf("Encoding: "); }
if (pcx_header[2]==1) printf("RLE\n"); printf("Encoding: ");
else printf("Unknown %i\n",pcx_header[2]); if (pcx_header[2]==1) printf("RLE\n");
else printf("Unknown %i\n",pcx_header[2]);
printf("BitsPerPixelPerPlane: %i\n",bpp);
printf("File goes from %i,%i to %i,%i\n",xmin,ymin,xmax,ymax); printf("BitsPerPixelPerPlane: %i\n",bpp);
printf("File goes from %i,%i to %i,%i\n",xmin,ymin,xmax,ymax);
printf("Horizontal DPI: %i\n",(pcx_header[13]<<8)+pcx_header[12]);
printf("Vertical DPI: %i\n",(pcx_header[15]<<8)+pcx_header[14]); printf("Horizontal DPI: %i\n",(pcx_header[13]<<8)+pcx_header[12]);
printf("Vertical DPI: %i\n",(pcx_header[15]<<8)+pcx_header[14]);
printf("Number of colored planes: %i\n",pcx_header[65]);
printf("Bytes per line: %i\n",(pcx_header[67]<<8)+pcx_header[66]); printf("Number of colored planes: %i\n",pcx_header[65]);
printf("Palette Type: %i\n",(pcx_header[69]<<8)+pcx_header[68]); printf("Bytes per line: %i\n",(pcx_header[67]<<8)+pcx_header[66]);
printf("Hscreen Size: %i\n",(pcx_header[71]<<8)+pcx_header[70]); printf("Palette Type: %i\n",(pcx_header[69]<<8)+pcx_header[68]);
printf("Vscreen Size: %i\n",(pcx_header[73]<<8)+pcx_header[72]); printf("Hscreen Size: %i\n",(pcx_header[71]<<8)+pcx_header[70]);
printf("Vscreen Size: %i\n",(pcx_header[73]<<8)+pcx_header[72]);
}
}
// *xsize=(xmax-xmin+1);
// *ysize=(ymax-ymin+1); // *xsize=(xmax-xmin+1);
*xsize=(xmax-xmin+1); // *ysize=(ymax-ymin+1);
*ysize=(ymax-ymin+1); *xsize=(xmax-xmin+1);
*ysize=(ymax-ymin+1);
if ((version==5) && (bpp==8) && (pcx_header[65]==3)) *type=PCX_24BIT;
else if (version==5) *type=PCX_8BITPAL; if ((version==5) && (bpp==8) && (pcx_header[65]==3)) *type=PCX_24BIT;
else *type=PCX_UNKNOWN; else if (version==5) *type=PCX_8BITPAL;
else *type=PCX_UNKNOWN;
close(pcx_fd);
close(pcx_fd);
return 0;
} return 0;
}
int vmwLoadPCX(int x1,int y1,vmwVisual *target,
int LoadPal,int LoadPic,char *FileName, int vmwLoadPCX(int x1,int y1,vmwVisual *target,
vmwSVMWGraphState *graph_state) int LoadPal,int LoadPic,char *FileName,
vmwSVMWGraphState *graph_state)
{
{
int pcx_fd,x,y,i,numacross,xsize,ysize,xmin,ymin;
unsigned int r,g,b; int pcx_fd,x,i,numacross,xsize,ysize,xmin,ymin;//y;
int bpp,planes,bpl,xmax,ymax,version; unsigned int r,g,b;
unsigned char pcx_header[128]; int xmax,ymax;//bpl,bpp,planes,version;
unsigned char temp_byte; unsigned char pcx_header[128];
unsigned char temp_byte;
/* Open the file */
pcx_fd=open(FileName,O_RDONLY); /* Open the file */
pcx_fd=open(FileName,O_RDONLY);
if (pcx_fd<0) {
printf("ERROR! File \"%s\" not found!\n",FileName); if (pcx_fd<0) {
return VMW_ERROR_FILE; printf("ERROR! File \"%s\" not found!\n",FileName);
} return VMW_ERROR_FILE;
}
/*************** DECODE THE HEADER *************************/ /*************** DECODE THE HEADER *************************/
read(pcx_fd,&pcx_header,128); read(pcx_fd,&pcx_header,128);
xmin=(pcx_header[5]<<8)+pcx_header[4]; xmin=(pcx_header[5]<<8)+pcx_header[4];
ymin=(pcx_header[7]<<8)+pcx_header[6]; ymin=(pcx_header[7]<<8)+pcx_header[6];
xmax=(pcx_header[9]<<8)+pcx_header[8]; xmax=(pcx_header[9]<<8)+pcx_header[8];
ymax=(pcx_header[11]<<8)+pcx_header[10]; ymax=(pcx_header[11]<<8)+pcx_header[10];
version=pcx_header[1]; //version=pcx_header[1];
bpp=pcx_header[3]; //bpp=pcx_header[3];
planes=pcx_header[65]; //planes=pcx_header[65];
bpl=(pcx_header[67]<<8)+pcx_header[66]; //bpl=(pcx_header[67]<<8)+pcx_header[66];
xsize=((xmax-xmin)+1); xsize=((xmax-xmin)+1);
ysize=((ymax-ymin)+1); ysize=((ymax-ymin)+1);
/* Possibly add some sanity checking in the header at some point... */ /* Possibly add some sanity checking in the header at some point... */
/* Or actually even get the proper VALUES from the header. Some day... */ /* Or actually even get the proper VALUES from the header. Some day... */
if (LoadPic) { if (LoadPic) {
unsigned char *pointer=target->memory; unsigned char *pointer=target->memory;
x=0; y=0; x=0; //y=0;
while (x<xsize*ysize) { while (x<xsize*ysize) {
read(pcx_fd,&temp_byte,1); read(pcx_fd,&temp_byte,1);
if (0xc0 == (temp_byte&0xc0)) { if (0xc0 == (temp_byte&0xc0)) {
numacross=temp_byte&0x3f; numacross=temp_byte&0x3f;
read(pcx_fd,&temp_byte,1); read(pcx_fd,&temp_byte,1);
// y++; if (y%2) temp_byte=0xff; // y++; if (y%2) temp_byte=0xff;
// temp_byte=0xff; // temp_byte=0xff;
// printf("%i pixels of %i\n",numacross,temp_byte); // printf("%i pixels of %i\n",numacross,temp_byte);
for(i=0;i<numacross;i++) { for(i=0;i<numacross;i++) {
*pointer=temp_byte; *pointer=temp_byte;
pointer++; pointer++;
x++; x++;
} }
//printf("Color=%i Across=%i\n",temp_byte,numacross);
//printf("Color=%i Across=%i\n",temp_byte,numacross); //vmwDrawHLine(x,y,numacross,temp_byte,target);
//vmwDrawHLine(x,y,numacross,temp_byte,target); //x+=numacross;
//x+=numacross; }
} else {
else { //vmwPutPixel(x,y,temp_byte,target);
//vmwPutPixel(x,y,temp_byte,target); //printf("%i, %i Color=%i\n",x,y,temp_byte);
//printf("%i, %i Color=%i\n",x,y,temp_byte);
*pointer=temp_byte;
*pointer=temp_byte; // if (temp_byte!=0) printf("COLOR=%i\n",temp_byte);
// if (temp_byte!=0) printf("COLOR=%i\n",temp_byte); pointer++;
pointer++; x++;
x++; }
} /* why is this needed? */
/* why is this needed? */ // if (x%xsize==0) {
// if (x%xsize==0) { // pointer++;
// pointer++; // }
// }
//printf("WARNING! X=%i\n",x);
//printf("WARNING! X=%i\n",x); // x=0;
// x=0; // y++;
// y++; // }
// } }
} }
}
/*Load Palette*/
/*Load Palette*/ if (LoadPal) {
if (LoadPal) {
lseek(pcx_fd,-769,SEEK_END);
lseek(pcx_fd,-769,SEEK_END);
read(pcx_fd,&temp_byte,1);
read(pcx_fd,&temp_byte,1); if (temp_byte!=12) {
if (temp_byte!=12) { printf("Error! No palette found!\n");
printf("Error! No palette found!\n"); }
} else
else
for(i=0;i<255;i++) {
for(i=0;i<255;i++) { read(pcx_fd,&temp_byte,1);
read(pcx_fd,&temp_byte,1); r=temp_byte;
r=temp_byte; read(pcx_fd,&temp_byte,1);
read(pcx_fd,&temp_byte,1); g=temp_byte;
g=temp_byte; read(pcx_fd,&temp_byte,1);
read(pcx_fd,&temp_byte,1); b=temp_byte;
b=temp_byte; vmwLoadPalette(graph_state,
vmwLoadPalette(graph_state, r,
r, g,
g, b,i);
b,i); // printf("%i: 0x%x %x %x\n",i,r,g,b);
// printf("%i: 0x%x %x %x\n",i,r,g,b); }
} vmwFlushPalette(graph_state);
vmwFlushPalette(graph_state); }
}
close(pcx_fd);
close(pcx_fd); return 0;
return 0; }
}
int vmwSavePCX(int x1,int y1,int xsize,int ysize,
int vmwSavePCX(int x1,int y1,int xsize,int ysize, vmwVisual *source,
vmwVisual *source, int num_colors,
int num_colors, vmw24BitPal *palette,
vmw24BitPal *palette, char *FileName) {
char *FileName) {
int pcx_fd,x,y,oldcolor,color,numacross,i;
unsigned char *pcx_header;
int pcx_fd,x,y,oldcolor,color,numacross,i; unsigned char temp_byte;
unsigned char *pcx_header;
unsigned char temp_byte; pcx_fd=open(FileName,O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR);
if (pcx_fd<0) {
printf("Error opening \"%s\" for writing!\n",FileName);
pcx_fd=open(FileName,O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR); return VMW_ERROR_FILE;
if (pcx_fd<0) { }
printf("Error opening \"%s\" for writing!\n",FileName);
return VMW_ERROR_FILE; pcx_header=calloc(1,128);
} /* Faked from a proper 320x200x256 pcx created with TheGIMP */
/* and read with 'od -t x1 -N 128' */
pcx_header=calloc(1,128); /* Values verified from PCGPE .pcx documentation */
/* Faked from a proper 320x200x256 pcx created with TheGIMP */ pcx_header[0]=0x0a; /* Manufacturer ID-- A=ZSoft .pcx */
/* and read with 'od -t x1 -N 128' */ pcx_header[1]=0x05; /* Version # */
/* Values verified from PCGPE .pcx documentation */ pcx_header[2]=0x01; /* Encoding. 1=RLE */
pcx_header[0]=0x0a; /* Manufacturer ID-- A=ZSoft .pcx */ pcx_header[3]=0x08; /* Bits Per Pixel */
pcx_header[1]=0x05; /* Version # */ pcx_header[8]=0x3f; /* 4-11 Window. XminXmin YminYmin XmaxXmax YmaxYmax*/
pcx_header[2]=0x01; /* Encoding. 1=RLE */ pcx_header[9]=0x01; /* Little Endian, so 0000 0000 013f 00c7= 319x199 */
pcx_header[3]=0x08; /* Bits Per Pixel */ pcx_header[10]=0xc7; /* " */
pcx_header[8]=0x3f; /* 4-11 Window. XminXmin YminYmin XmaxXmax YmaxYmax*/ pcx_header[12]=0x2c; /* Horizontal DPI */
pcx_header[9]=0x01; /* Little Endian, so 0000 0000 013f 00c7= 319x199 */ pcx_header[13]=0x01; /* " .. so 0x12c=300dpi */
pcx_header[10]=0xc7; /* " */ pcx_header[14]=0x2c; /* Vertical DPI */
pcx_header[12]=0x2c; /* Horizontal DPI */ pcx_header[15]=0x01; /* " .. so 0x12c=300dpi */
pcx_header[13]=0x01; /* " .. so 0x12c=300dpi */ pcx_header[65]=0x01; /* Number of color planes */
pcx_header[14]=0x2c; /* Vertical DPI */ pcx_header[66]=0x40; /* bytes per line. */
pcx_header[15]=0x01; /* " .. so 0x12c=300dpi */ pcx_header[67]=0x01; /* "" .. so 0x140=320 */
pcx_header[65]=0x01; /* Number of color planes */ pcx_header[68]=0x01; /* Color Palette */
pcx_header[66]=0x40; /* bytes per line. */
pcx_header[67]=0x01; /* "" .. so 0x140=320 */ /* 128 byte PCX Header */
pcx_header[68]=0x01; /* Color Palette */ write(pcx_fd,pcx_header,128);
/* 128 byte PCX Header */ /* All we support right now */
write(pcx_fd,pcx_header,128); xsize=320;
ysize=200;
/* All we support right now */
xsize=320; y=y1;
ysize=200; x=x1;
numacross=1;
y=y1;
x=x1; /* Set up initial conditions */
numacross=1; oldcolor=vmwGetPixel(x,y,source);
/* Set up initial conditions */ while (y<y1+ysize) {
oldcolor=vmwGetPixel(x,y,source); color=vmwGetPixel(x,y,source);
if ( (color==oldcolor)&&(numacross<63)&&(x<(x1+xsize-1)) ) numacross++;
while (y<y1+ysize) { else { /* This pixel not the same color as previous */
color=vmwGetPixel(x,y,source); // printf("G: %i,%i N=%i C=%i\n",x,y,numacross,color);
if ( (color==oldcolor)&&(numacross<63)&&(x<(x1+xsize-1)) ) numacross++; if ((numacross==1) && (oldcolor<192)) {
else { /* This pixel not the same color as previous */ write(pcx_fd,&oldcolor,1);
// printf("G: %i,%i N=%i C=%i\n",x,y,numacross,color); }
if ((numacross==1) && (oldcolor<192)) { else {
write(pcx_fd,&oldcolor,1); temp_byte=numacross+192;
} write(pcx_fd,&temp_byte,1);
else { write(pcx_fd,&oldcolor,1);
temp_byte=numacross+192; numacross=1;
write(pcx_fd,&temp_byte,1); }
write(pcx_fd,&oldcolor,1); }
numacross=1; oldcolor=color;
} x++;
} if (x>=x1+xsize) {
oldcolor=color; x=0;
x++; y++;
if (x>=x1+xsize) { numacross=1;
x=0; // printf("%i %i %i\n",x,y,numacross);
y++; // fflush(stdout);
numacross=1; }
// printf("%i %i %i\n",x,y,numacross); }
// fflush(stdout);
} /* Urgh obscure */
} temp_byte=12;
write(pcx_fd,&temp_byte,1);
/* Urgh obscure */
temp_byte=12; /* Write num_colors r,g,b */
write(pcx_fd,&temp_byte,1); for(i=0;i<256;i++) {
temp_byte=palette[i].r;
/* Write num_colors r,g,b */ write(pcx_fd,&temp_byte,1);
for(i=0;i<256;i++) { temp_byte=palette[i].g;
temp_byte=palette[i].r; write(pcx_fd,&temp_byte,1);
write(pcx_fd,&temp_byte,1); temp_byte=palette[i].b;
temp_byte=palette[i].g; write(pcx_fd,&temp_byte,1);
write(pcx_fd,&temp_byte,1); }
temp_byte=palette[i].b;
write(pcx_fd,&temp_byte,1); close(pcx_fd);
} return 0;
}
close(pcx_fd);
return 0;
}

View File

@ -9,7 +9,7 @@
#include <stdio.h> /* For printf */ #include <stdio.h> /* For printf */
#include <stdlib.h> /* For Memory Allocation */ #include <stdlib.h> /* For Memory Allocation */
void *(*vmwSetupGraphics)(int *xsize,int *ysize, int *bpp, void *(*vmwSetupGraphics)(int *xsize,int *ysize, int *bpp,
int fullscreen,int verbose); int fullscreen,int verbose);
void (*vmwBlitMemToDisplay)(vmwSVMWGraphState *display, vmwVisual *source); void (*vmwBlitMemToDisplay)(vmwSVMWGraphState *display, vmwVisual *source);
void (*vmwFlushPalette)(vmwSVMWGraphState *state); void (*vmwFlushPalette)(vmwSVMWGraphState *state);
@ -21,29 +21,29 @@ void (*vmwCloseGraphics)(void);
vmwSVMWGraphState *vmwSetupSVMWGraph(int display_type,int xsize,int ysize, vmwSVMWGraphState *vmwSetupSVMWGraph(int display_type,int xsize,int ysize,
int bpp,int scale,int fullscreen, int bpp,int scale,int fullscreen,
int verbose) { int verbose) {
vmwSVMWGraphState *temp_state; vmwSVMWGraphState *temp_state;
if ( (temp_state=calloc(1,sizeof(vmwSVMWGraphState)) )==NULL) { if ( (temp_state=calloc(1,sizeof(vmwSVMWGraphState)) )==NULL) {
printf("Error allocating memory!\n"); printf("Error allocating memory!\n");
return NULL; return NULL;
} }
/* Setup Setup routines */ /* Setup Setup routines */
switch (display_type) { switch (display_type) {
case VMW_NULLTARGET: case VMW_NULLTARGET:
vmwSetupGraphics=null_setupGraphics; vmwSetupGraphics=null_setupGraphics;
break; break;
case VMW_CURSESTARGET: case VMW_CURSESTARGET:
#ifdef CURSES_TARGET #ifdef CURSES_TARGET
vmwSetupGraphics=curses_setupGraphics; vmwSetupGraphics=curses_setupGraphics;
#endif #endif
break; break;
case VMW_OPENGLTARGET: case VMW_OPENGLTARGET:
#ifdef OPENGL_TARGET #ifdef OPENGL_TARGET
vmwSetupGraphics=openGL_setupGraphics; vmwSetupGraphics=openGL_setupGraphics;
#endif #endif
break; break;
case VMW_SDLTARGET: case VMW_SDLTARGET:
#ifdef SDL_TARGET #ifdef SDL_TARGET
vmwSetupGraphics=SDL_setupGraphics; vmwSetupGraphics=SDL_setupGraphics;
#endif #endif
@ -51,14 +51,14 @@ vmwSVMWGraphState *vmwSetupSVMWGraph(int display_type,int xsize,int ysize,
default: printf("ERROR! Unknown Display Target %i.\n",display_type); default: printf("ERROR! Unknown Display Target %i.\n",display_type);
return NULL; return NULL;
} }
temp_state->bpp=bpp; temp_state->bpp=bpp;
temp_state->xsize=xsize; temp_state->xsize=xsize;
temp_state->ysize=ysize; temp_state->ysize=ysize;
temp_state->scale=scale; temp_state->scale=scale;
temp_state->default_font=NULL; temp_state->default_font=NULL;
temp_state->palette_size=256; temp_state->palette_size=256;
if ( (temp_state->palette=calloc(temp_state->palette_size,sizeof(int)) )==NULL) { if ( (temp_state->palette=calloc(temp_state->palette_size,sizeof(int)) )==NULL) {
printf("Error allocating palette of size %i!\n",temp_state->palette_size); printf("Error allocating palette of size %i!\n",temp_state->palette_size);
return NULL; return NULL;
@ -69,6 +69,10 @@ vmwSVMWGraphState *vmwSetupSVMWGraph(int display_type,int xsize,int ysize,
return NULL; return NULL;
} }
if (vmwSetupGraphics==NULL) {
fprintf(stderr,"Unsupported graphics target!\n");
return NULL;
}
/* Attempt to get desired graphics state */ /* Attempt to get desired graphics state */
temp_state->output_screen=vmwSetupGraphics(&temp_state->xsize, temp_state->output_screen=vmwSetupGraphics(&temp_state->xsize,
@ -76,7 +80,7 @@ vmwSVMWGraphState *vmwSetupSVMWGraph(int display_type,int xsize,int ysize,
&temp_state->bpp, &temp_state->bpp,
fullscreen,verbose); fullscreen,verbose);
if (temp_state->output_screen==NULL) return NULL; if (temp_state->output_screen==NULL) return NULL;
/* Setup proper blitter and others*/ /* Setup proper blitter and others*/
switch (display_type) { switch (display_type) {
case VMW_NULLTARGET: case VMW_NULLTARGET:
vmwFlushPalette=null_flushPalette; vmwFlushPalette=null_flushPalette;

View File

@ -1,474 +1,477 @@
/****************************************************************\ /****************************************************************\
\* TOM BOMBEM AND THE INVASION OF THE INANIMATE_OBJECTS */ \* TOM BOMBEM AND THE INVASION OF THE INANIMATE_OBJECTS */
/* version 2.9.16 26 December 2009 *\ /* version 2.9.16 26 December 2009 *\
\* by Vince Weaver vince@deater.net */ \* by Vince Weaver vince@deater.net */
/* *\ /* *\
\* Originally written in Pascal and x86 assembly for DOS */ \* Originally written in Pascal and x86 assembly for DOS */
/* using the PCGPE code as an example in 1994 *\ /* using the PCGPE code as an example in 1994 *\
\* Ported to Linux, C, and ggi late 1997-early 1998 */ \* Ported to Linux, C, and ggi late 1997-early 1998 */
/* Port continued to SDL in June of 2000 *\ /* Port continued to SDL in June of 2000 *\
\* This source is released under the GPL */ \* This source is released under the GPL */
/****************************************************************/ /****************************************************************/
#define TB1_VERSION "2.9.16" #define TB1_VERSION "2.9.16"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> /* for calloc */ #include <stdlib.h> /* for calloc */
#include <string.h> /* for strncpy */ #include <string.h> /* for strncpy */
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
#include <sys/time.h> #include <sys/time.h>
#include "svmwgraph/svmwgraph.h" #include "svmwgraph/svmwgraph.h"
#include "tb1_state.h" #include "tb1_state.h"
#include "tblib.h" #include "tblib.h"
#include "sound.h" #include "sound.h"
#include "graphic_tools.h" #include "graphic_tools.h"
#include "help.h" #include "help.h"
#include "quit.h" #include "quit.h"
#include "story.h" #include "story.h"
#include "credits.h" #include "credits.h"
#include "about.h" #include "about.h"
#include "loadsave.h" #include "loadsave.h"
#include "options.h" #include "options.h"
#include "playgame.h" #include "playgame.h"
int command_line_help(int show_version,char *runas) { int command_line_help(int show_version,char *runas) {
if (!show_version) { if (!show_version) {
printf("Usage: %s [-curses] [-double] [-fullscreen] [-nosound]" printf("Usage: %s [-curses] [-double] [-fullscreen] [-nosound]"
" [-version] [-?]\n\n",runas); " [-version] [-?]\n\n",runas);
printf(" -curses : play in color text-mode\n"); printf(" -curses : play in color text-mode\n");
printf(" -double : play in 640x480 mode\n"); printf(" -double : play in 640x480 mode\n");
printf(" -fullscreen : play in fullscreen mode (if available)\n"); printf(" -fullscreen : play in fullscreen mode (if available)\n");
printf(" -nosound : disables sound within game\n"); printf(" -nosound : disables sound within game\n");
printf(" -opengl : play in openGL mode\n"); printf(" -opengl : play in openGL mode\n");
printf(" -version : print version\n"); printf(" -version : print version\n");
printf(" -? : print this help message\n"); printf(" -? : print this help message\n");
printf("\n"); printf("\n");
} }
return 0; return 0;
} }
void vmw_opener(tb1_state *game_state, vmwVisual *virtual_1) { void vmw_opener(tb1_state *game_state, vmwVisual *virtual_1) {
int x; int x;
for(x=0;x<256;x++) { for(x=0;x<256;x++) {
vmwLoadPalette(game_state->graph_state,0,0,0,x); /* 0=black */ vmwLoadPalette(game_state->graph_state,0,0,0,x); /* 0=black */
} }
/* Do the VMW Software Production Logo */ /* Do the VMW Software Production Logo */
for(x=0;x<=40;x++) { for(x=0;x<=40;x++) {
vmwLoadPalette(game_state->graph_state, ((x+20)*4),0,0,100+x); vmwLoadPalette(game_state->graph_state, ((x+20)*4),0,0,100+x);
vmwLoadPalette(game_state->graph_state,0,0, ( (x+20)*4 ),141+x); vmwLoadPalette(game_state->graph_state,0,0, ( (x+20)*4 ),141+x);
vmwLoadPalette(game_state->graph_state,0, ( (x+20)*4),0,182+x); vmwLoadPalette(game_state->graph_state,0, ( (x+20)*4),0,182+x);
} }
/* Set the white color */ /* Set the white color */
vmwLoadPalette(game_state->graph_state,0xff,0xff,0xff,15); vmwLoadPalette(game_state->graph_state,0xff,0xff,0xff,15);
vmwFlushPalette(game_state->graph_state); vmwFlushPalette(game_state->graph_state);
/* Actually draw the stylized VMW */ /* Actually draw the stylized VMW */
for(x=0;x<=40;x++) { for(x=0;x<=40;x++) {
vmwDrawVLine(x+40,45,2*x,100+x,virtual_1); vmwDrawVLine(x+40,45,2*x,100+x,virtual_1);
vmwDrawVLine(x+120,45,2*x,141+x,virtual_1); vmwDrawVLine(x+120,45,2*x,141+x,virtual_1);
vmwDrawVLine(x+200,45,2*x,141+x,virtual_1); vmwDrawVLine(x+200,45,2*x,141+x,virtual_1);
vmwDrawVLine(x+80,125-(2*x),2*x,182+x,virtual_1); vmwDrawVLine(x+80,125-(2*x),2*x,182+x,virtual_1);
vmwDrawVLine(x+160,125-(2*x),2*x,182+x,virtual_1); vmwDrawVLine(x+160,125-(2*x),2*x,182+x,virtual_1);
} }
for(x=40;x>0;x--){ for(x=40;x>0;x--){
vmwDrawVLine(x+80,45,80-(2*x),140-x,virtual_1); vmwDrawVLine(x+80,45,80-(2*x),140-x,virtual_1);
vmwDrawVLine(x+160,45,80-(2*x),181-x,virtual_1); vmwDrawVLine(x+160,45,80-(2*x),181-x,virtual_1);
vmwDrawVLine(x+240,45,80-(2*x),181-x,virtual_1); vmwDrawVLine(x+240,45,80-(2*x),181-x,virtual_1);
vmwDrawVLine(x+120,45+(2*x),80-(2*x),222-x,virtual_1); vmwDrawVLine(x+120,45+(2*x),80-(2*x),222-x,virtual_1);
vmwDrawVLine(x+200,45+(2*x),80-(2*x),222-x,virtual_1); vmwDrawVLine(x+200,45+(2*x),80-(2*x),222-x,virtual_1);
} }
vmwTextXY("A VMW SOFTWARE PRODUCTION",60,140, vmwTextXY("A VMW SOFTWARE PRODUCTION",60,140,
15,15,0,game_state->graph_state->default_font,virtual_1); 15,15,0,game_state->graph_state->default_font,virtual_1);
if ((game_state->sound_possible) && (game_state->music_enabled)) { if ((game_state->sound_possible) && (game_state->music_enabled)) {
playSound(); playSound();
} }
vmwBlitMemToDisplay(game_state->graph_state,virtual_1); vmwBlitMemToDisplay(game_state->graph_state,virtual_1);
pauseawhile(5); pauseawhile(5);
vmwFadeToBlack(game_state->graph_state,virtual_1,0); vmwFadeToBlack(game_state->graph_state,virtual_1,0);
} }
int main(int argc,char **argv) { int main(int argc,char **argv) {
int i,grapherror,reloadpic=0; int i,grapherror,reloadpic=0;
int ch,barpos,time_sec; int ch,barpos,time_sec;
int graphics_target=VMW_SDLTARGET; int graphics_target=VMW_SDLTARGET;
FILE *fff; FILE *fff;
char *dir_name,options_file[BUFSIZ]; char *dir_name,options_file[BUFSIZ];
vmwVisual *virtual_1,*virtual_2,*virtual_3; vmwVisual *virtual_1,*virtual_3;//*virtual_2
tb1_state *game_state; tb1_state *game_state;
vmwFont *tb1_font; vmwFont *tb1_font;
struct timeval time_info; struct timeval time_info;
struct timezone dontcare; struct timezone dontcare;
printf("\nTom Bombem v%s by Vince Weaver vince@deater.net\n",TB1_VERSION); printf("\nTom Bombem v%s by Vince Weaver vince@deater.net\n",TB1_VERSION);
printf(" http://www.deater.net/weave/vmwprod/tb1\n\n"); printf(" http://www.deater.net/weave/vmwprod/tb1\n\n");
/* Setup the game state */ /* Setup the game state */
if ( (game_state=calloc(1,sizeof(tb1_state)))==NULL) { if ( (game_state=calloc(1,sizeof(tb1_state)))==NULL) {
printf("You are seriously low on RAM!\n"); printf("You are seriously low on RAM!\n");
return 3; return 3;
} }
/* Some sane defaults */ /* Some sane defaults */
game_state->level=0; game_state->level=0;
game_state->shields=0; game_state->shields=0;
game_state->score=0; game_state->score=0;
game_state->virtual_1=NULL; game_state->virtual_1=NULL;
game_state->virtual_2=NULL; //game_state->virtual_2=NULL;
game_state->virtual_3=NULL; game_state->virtual_3=NULL;
game_state->sound_possible=1; game_state->sound_possible=1;
game_state->music_enabled=1; game_state->music_enabled=1;
game_state->sound_enabled=1; game_state->sound_enabled=1;
game_state->sound_volume=5; game_state->sound_volume=5;
game_state->music_volume=5; game_state->music_volume=5;
game_state->default_double_size=0; game_state->default_double_size=0;
game_state->default_fullscreen=0; game_state->default_fullscreen=0;
/* Load saved defaults, if any */ /* Load saved defaults, if any */
dir_name=check_for_tb1_directory(game_state,0); dir_name=check_for_tb1_directory(game_state,0);
if (dir_name==NULL) { if (dir_name==NULL) {
printf(" + No ~/.tb1 directory. Using default options.\n"); printf(" + No ~/.tb1 directory. Using default options.\n");
} }
else { else {
sprintf(options_file,"%s/options.tb1",dir_name); sprintf(options_file,"%s/options.tb1",dir_name);
fff=fopen(options_file,"r"); fff=fopen(options_file,"r");
if (fff==NULL) { if (fff==NULL) {
printf(" + No ~/.tb1/options.tb1 file. Using defaults.\n"); printf(" + No ~/.tb1/options.tb1 file. Using defaults.\n");
} }
else { else {
printf(" + Reading options from ~/.tb1/options.tb1\n"); printf(" + Reading options from ~/.tb1/options.tb1\n");
fscanf(fff,"%i %i %i %i %i %i", fscanf(fff,"%i %i %i %i %i %i",
&game_state->sound_enabled, &game_state->sound_enabled,
&game_state->music_enabled, &game_state->music_enabled,
&game_state->sound_volume, &game_state->sound_volume,
&game_state->music_volume, &game_state->music_volume,
&game_state->default_double_size, &game_state->default_double_size,
&game_state->default_fullscreen); &game_state->default_fullscreen);
fclose(fff); fclose(fff);
} }
} }
/* Parse Command Line Arguments */ /* Parse Command Line Arguments */
i=1; i=1;
while(i<argc) { while(i<argc) {
if (argv[i][0]=='-') { if (argv[i][0]=='-') {
switch (argv[i][1]) { switch (argv[i][1]) {
case 'h': case 'h':
case '?': case '?':
command_line_help(0,argv[0]); command_line_help(0,argv[0]);
return 5; return 5;
break; break;
case 'v': case 'v':
command_line_help(1,argv[0]); command_line_help(1,argv[0]);
return 5; return 5;
break; break;
case 'f': case 'f':
game_state->default_fullscreen=1; game_state->default_fullscreen=1;
break; break;
case 'c': case 'c':
graphics_target=VMW_CURSESTARGET; graphics_target=VMW_CURSESTARGET;
break; break;
case 'd': case 'd':
game_state->default_double_size=1; game_state->default_double_size=1;
break; break;
case 'n': case 'n':
game_state->sound_possible=0; game_state->sound_possible=0;
printf(" + Sound totally disabled\n"); printf(" + Sound totally disabled\n");
break; break;
case 'o': case 'o':
graphics_target=VMW_OPENGLTARGET; graphics_target=VMW_OPENGLTARGET;
break; break;
default : default :
command_line_help(0,argv[0]); command_line_help(0,argv[0]);
printf("Unknown Option: %s\n\n",argv[i]); printf("Unknown Option: %s\n\n",argv[i]);
return 5; return 5;
} }
} }
else { else {
command_line_help(0,argv[0]); command_line_help(0,argv[0]);
printf("Unknown Option: %s\n\n",argv[i]); printf("Unknown Option: %s\n\n",argv[i]);
return 5; return 5;
} }
i++; i++;
} }
/* Find the Data */ /* Find the Data */
/* FIXME : User Defined Path Info*/ /* FIXME : User Defined Path Info*/
if ( (fff=fopen("./data/tb1_data_files_here","r"))!=NULL) { if ( (fff=fopen("./data/tb1_data_files_here","r"))!=NULL) {
strncpy(game_state->path_to_data,"./data/",20); strncpy(game_state->path_to_data,"./data/",20);
} }
else if ( (fff=fopen("/usr/local/games/tb1/data/tb1_data_files_here","r")) else if ( (fff=fopen("/usr/local/games/tb1/data/tb1_data_files_here","r"))
!=NULL) { !=NULL) {
strncpy(game_state->path_to_data,"/usr/local/games/tb1/data/",40); strncpy(game_state->path_to_data,"/usr/local/games/tb1/data/",40);
} }
else { else {
char tempst[200]; char tempst[200];
sprintf(tempst,"%s/.tb1/data/tb1_data_files_here",getenv("HOME")); sprintf(tempst,"%s/.tb1/data/tb1_data_files_here",getenv("HOME"));
if ( (fff=fopen(tempst,"r"))!=NULL) { if ( (fff=fopen(tempst,"r"))!=NULL) {
sprintf(game_state->path_to_data,"%s/.tb1/data/",getenv("HOME")); sprintf(game_state->path_to_data,"%s/.tb1/data/",getenv("HOME"));
} }
else { else {
printf("ERROR! Could not find tb1 data!\n"); printf("ERROR! Could not find tb1 data!\n");
printf(" Checked ./data, /usr/local/games/tb1/data\n"); printf(" Checked ./data, /usr/local/games/tb1/data\n");
printf(" and %s/.tb1/data\n\n",getenv("HOME")); printf(" and %s/.tb1/data\n\n",getenv("HOME"));
return 9; return 9;
} }
} }
printf(" + Found tb1 data in %s\n",game_state->path_to_data); printf(" + Found tb1 data in %s\n",game_state->path_to_data);
/* LEGACY OPERATION BOTTLECAP STUFF---> *\ /* LEGACY OPERATION BOTTLECAP STUFF---> *\
\* --> You are not meant to understand this <-- */ \* --> You are not meant to understand this <-- */
/* No 9-22-94 Back to yes 10-6-94 uh_oh 2-21-95 *\ /* No 9-22-94 Back to yes 10-6-94 uh_oh 2-21-95 *\
\* gone for real long time 10-12-95 */ \* gone for real long time 10-12-95 */
/* 11-95 not AMG, but AAT *\ /* 11-95 not AMG, but AAT *\
\* 3-96 oh well... gave up on AAT finally */ \* 3-96 oh well... gave up on AAT finally */
/* 5-11-96 Now MLP... *\ /* 5-11-96 Now MLP... *\
\* 9-22-2000 :( */ \* 9-22-2000 :( */
/* 3-25-2002 Now KRG ;) */ /* 3-25-2002 Now KRG ;) */
/* Randomize random number generator */ /* Randomize random number generator */
srandom(time(NULL)); srandom(time(NULL));
printf(" + Seeding random number generator...\n"); printf(" + Seeding random number generator...\n");
/* Load/Detect sound */ /* Load/Detect sound */
if (game_state->sound_possible) { if (game_state->sound_possible) {
if (initSound(game_state->path_to_data)<0) { if (initSound(game_state->path_to_data)<0) {
game_state->sound_possible=0; game_state->sound_possible=0;
} }
/* Load fanfare Music */ /* Load fanfare Music */
if (game_state->sound_possible) { if (game_state->sound_possible) {
loadSound(tb1_data_file("music/vmwfan.mod",game_state->path_to_data)); loadSound(tb1_data_file("music/vmwfan.mod",game_state->path_to_data));
} }
printf(" + Loaded sounds...\n"); printf(" + Loaded sounds...\n");
} }
/* Setup Graphics */ /* Setup Graphics */
if (!game_state->default_double_size) { if (!game_state->default_double_size) {
if ( (game_state->graph_state= if ( (game_state->graph_state=
vmwSetupSVMWGraph(graphics_target, vmwSetupSVMWGraph(graphics_target,
320,200, 320,200,
0,1, 0,1,
game_state->default_fullscreen, game_state->default_fullscreen,
1))==NULL) { 1))==NULL) {
fprintf(stderr,"ERROR: Couldn't get display set up properly.\n"); fprintf(stderr,"ERROR: Couldn't get display set up properly.\n");
return VMW_ERROR_DISPLAY; return VMW_ERROR_DISPLAY;
} }
} }
else { /* We are double-sized */ else { /* We are double-sized */
if ( (game_state->graph_state= if ( (game_state->graph_state=
vmwSetupSVMWGraph(graphics_target, vmwSetupSVMWGraph(graphics_target,
640,480, 640,480,
0,2, 0,2,
game_state->default_fullscreen, game_state->default_fullscreen,
1))==NULL) { 1))==NULL) {
fprintf(stderr,"ERROR: Couldn't get display set up properly.\n"); fprintf(stderr,"ERROR: Couldn't get display set up properly.\n");
return VMW_ERROR_DISPLAY; return VMW_ERROR_DISPLAY;
} }
} }
/* Load the tom bombem font */ /* Load the tom bombem font */
game_state->graph_state->default_font= game_state->graph_state->default_font=
vmwLoadFont(tb1_data_file("tbfont.tb1", vmwLoadFont(tb1_data_file("tbfont.tb1",
game_state->path_to_data),8,16,256); game_state->path_to_data),8,16,256);
printf(" + Loaded tb1 font...\n"); printf(" + Loaded tb1 font...\n");
/* Allocate the 3 virtual screens */ /* Allocate the 3 virtual screens */
if ((game_state->virtual_1=vmwSetupVisual(320,200))==NULL) { if ((game_state->virtual_1=vmwSetupVisual(320,200))==NULL) {
fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 1!\n"); fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 1!\n");
return VMW_ERROR_MEM; return VMW_ERROR_MEM;
} }
if ((game_state->virtual_2=vmwSetupVisual(320,400))==NULL) { if ((game_state->virtual_2=vmwSetupVisual(320,400))==NULL) {
fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 2!\n"); fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 2!\n");
return VMW_ERROR_MEM; return VMW_ERROR_MEM;
} }
if ((game_state->virtual_3=vmwSetupVisual(320,200))==NULL) { if ((game_state->virtual_3=vmwSetupVisual(320,200))==NULL) {
fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 3!\n"); fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 3!\n");
return VMW_ERROR_MEM; return VMW_ERROR_MEM;
} }
printf(" + Allocated virtual screens...\n"); printf(" + Allocated virtual screens...\n");
/* To ease typing burden */ /* To ease typing burden */
virtual_1=game_state->virtual_1; virtual_1=game_state->virtual_1;
virtual_2=game_state->virtual_2; //virtual_2=game_state->virtual_2;
virtual_3=game_state->virtual_3; virtual_3=game_state->virtual_3;
tb1_font=game_state->graph_state->default_font; tb1_font=game_state->graph_state->default_font;
/* The "fancy" opener */ /* The "fancy" opener */
vmw_opener(game_state,virtual_1); vmw_opener(game_state,virtual_1);
/* Load menu music */ /* Load menu music */
if (game_state->sound_possible) { if (game_state->sound_possible) {
stopSound(); stopSound();
loadSound(tb1_data_file("music/weave1.mod",game_state->path_to_data)); loadSound(tb1_data_file("music/weave1.mod",game_state->path_to_data));
} }
/* Load palette */ /* Load palette */
grapherror=vmwLoadPicPacked(0,0,virtual_1,1,0, grapherror=vmwLoadPicPacked(0,0,virtual_1,1,0,
tb1_data_file("tbomb1.tb1", tb1_data_file("tbomb1.tb1",
game_state->path_to_data), game_state->path_to_data),
game_state->graph_state); game_state->graph_state);
if (grapherror) {
/* Bit of a hack to load proper unfade colors */ return -1;
vmwFadeToBlack(game_state->graph_state,virtual_1,1); }
/* Load Title Picture */ /* Bit of a hack to load proper unfade colors */
grapherror=vmwLoadPicPacked(0,0,virtual_1,1,1, vmwFadeToBlack(game_state->graph_state,virtual_1,1);
tb1_data_file("tbomb1.tb1",
game_state->path_to_data), /* Load Title Picture */
game_state->graph_state); grapherror=vmwLoadPicPacked(0,0,virtual_1,1,1,
tb1_data_file("tbomb1.tb1",
/* Copy the picture over */ game_state->path_to_data),
vmwFlipVirtual(virtual_3,virtual_1,320,200); game_state->graph_state);
vmwUnFade(game_state->graph_state,virtual_1); /* Copy the picture over */
vmwFlipVirtual(virtual_3,virtual_1,320,200);
/* Main Menu Loop */
while(1) { vmwUnFade(game_state->graph_state,virtual_1);
/* If virtual_3 was over-written, re-load it */
if (reloadpic) { /* Main Menu Loop */
if ((game_state->sound_possible) && (game_state->music_enabled)) { while(1) {
loadSound(tb1_data_file("music/weave1.mod", /* If virtual_3 was over-written, re-load it */
game_state->path_to_data)); if (reloadpic) {
} if ((game_state->sound_possible) && (game_state->music_enabled)) {
grapherror=vmwLoadPicPacked(0,0,virtual_3,1,1, loadSound(tb1_data_file("music/weave1.mod",
tb1_data_file("tbomb1.tb1", game_state->path_to_data));
game_state->path_to_data), }
game_state->graph_state); grapherror=vmwLoadPicPacked(0,0,virtual_3,1,1,
reloadpic=0; tb1_data_file("tbomb1.tb1",
} game_state->path_to_data),
game_state->graph_state);
vmwFlipVirtual(virtual_1,virtual_3,320,200); reloadpic=0;
}
/* Play the menu-music */
if ((game_state->sound_possible) && (game_state->music_enabled)) { vmwFlipVirtual(virtual_1,virtual_3,320,200);
playSound();
} /* Play the menu-music */
vmwBlitMemToDisplay(game_state->graph_state,virtual_1); if ((game_state->sound_possible) && (game_state->music_enabled)) {
playSound();
/* Don't show the menu until keypress/15s */ }
pauseawhile(15); vmwBlitMemToDisplay(game_state->graph_state,virtual_1);
barpos=0; /* Don't show the menu until keypress/15s */
vmwTextXY("F1 HELP",0,190,9,7,0,tb1_font,virtual_1); pauseawhile(15);
coolbox(117,61,199,140,1,virtual_1);
barpos=0;
vmwBlitMemToDisplay(game_state->graph_state,virtual_1); vmwTextXY("F1 HELP",0,190,9,7,0,tb1_font,virtual_1);
ch=0; coolbox(117,61,199,140,1,virtual_1);
while(ch!=VMW_ENTER){ vmwBlitMemToDisplay(game_state->graph_state,virtual_1);
if (barpos==0) { ch=0;
vmwTextXY("NEW GAME",123,67,32,0,1,tb1_font,virtual_1);
} while(ch!=VMW_ENTER){
else { if (barpos==0) {
vmwTextXY("NEW GAME",123,67,32,7,1,tb1_font,virtual_1); vmwTextXY("NEW GAME",123,67,32,0,1,tb1_font,virtual_1);
} }
if (barpos==1) { else {
vmwTextXY("OPTIONS",123,77,32,0,1,tb1_font,virtual_1); vmwTextXY("NEW GAME",123,67,32,7,1,tb1_font,virtual_1);
} }
else { if (barpos==1) {
vmwTextXY("OPTIONS",123,77,32,7,1,tb1_font,virtual_1); vmwTextXY("OPTIONS",123,77,32,0,1,tb1_font,virtual_1);
} }
if (barpos==2) { else {
vmwTextXY("ABOUT",123,87,32,0,1,tb1_font,virtual_1); vmwTextXY("OPTIONS",123,77,32,7,1,tb1_font,virtual_1);
} }
else { if (barpos==2) {
vmwTextXY("ABOUT",123,87,32,7,1,tb1_font,virtual_1); vmwTextXY("ABOUT",123,87,32,0,1,tb1_font,virtual_1);
} }
if (barpos==3) { else {
vmwTextXY("LOAD GAME",123,97,32,0,1,tb1_font,virtual_1); vmwTextXY("ABOUT",123,87,32,7,1,tb1_font,virtual_1);
} }
else { if (barpos==3) {
vmwTextXY("LOAD GAME",123,97,32,7,1,tb1_font,virtual_1); vmwTextXY("LOAD GAME",123,97,32,0,1,tb1_font,virtual_1);
} }
if (barpos==4) { else {
vmwTextXY("STORY",123,107,32,0,1,tb1_font,virtual_1); vmwTextXY("LOAD GAME",123,97,32,7,1,tb1_font,virtual_1);
} }
else { if (barpos==4) {
vmwTextXY("STORY",123,107,32,7,1,tb1_font,virtual_1); vmwTextXY("STORY",123,107,32,0,1,tb1_font,virtual_1);
} }
if (barpos==5) { else {
vmwTextXY("CREDITS",123,117,32,0,1,tb1_font,virtual_1); vmwTextXY("STORY",123,107,32,7,1,tb1_font,virtual_1);
} }
else { if (barpos==5) {
vmwTextXY("CREDITS",123,117,32,7,1,tb1_font,virtual_1); vmwTextXY("CREDITS",123,117,32,0,1,tb1_font,virtual_1);
} }
if (barpos==6) { else {
vmwTextXY("QUIT",123,127,32,0,1,tb1_font,virtual_1); vmwTextXY("CREDITS",123,117,32,7,1,tb1_font,virtual_1);
} }
else { if (barpos==6) {
vmwTextXY("QUIT",123,127,32,7,1,tb1_font,virtual_1); vmwTextXY("QUIT",123,127,32,0,1,tb1_font,virtual_1);
} }
else {
vmwBlitMemToDisplay(game_state->graph_state,virtual_1); vmwTextXY("QUIT",123,127,32,7,1,tb1_font,virtual_1);
}
/* If at title screen too long, run credits */
gettimeofday(&time_info,&dontcare); vmwBlitMemToDisplay(game_state->graph_state,virtual_1);
time_sec=time_info.tv_sec;
/* If at title screen too long, run credits */
while( ((ch=vmwGetInput())==0)) { gettimeofday(&time_info,&dontcare);
usleep(30); time_sec=time_info.tv_sec;
gettimeofday(&time_info,&dontcare);
if (time_info.tv_sec-time_sec>40) { while( ((ch=vmwGetInput())==0)) {
if (game_state->sound_possible) stopSound(); usleep(30);
credits(game_state); gettimeofday(&time_info,&dontcare);
ch=VMW_ENTER; if (time_info.tv_sec-time_sec>40) {
barpos=9; if (game_state->sound_possible) stopSound();
reloadpic=1; credits(game_state);
break; ch=VMW_ENTER;
} barpos=9;
} reloadpic=1;
break;
/* Change menu position based on key pressed */ }
if ((ch==VMW_DOWN)||(ch==VMW_RIGHT)) barpos++; }
if ((ch==VMW_UP) || (ch==VMW_LEFT)) barpos--;
if (ch==VMW_F1) {barpos=10; ch=VMW_ENTER;} /*F1*/ /* Change menu position based on key pressed */
if (ch=='n') barpos=0; /*N*/ if ((ch==VMW_DOWN)||(ch==VMW_RIGHT)) barpos++;
if (ch=='o') barpos=1; /*O*/ if ((ch==VMW_UP) || (ch==VMW_LEFT)) barpos--;
if (ch=='a') barpos=2; /*A*/ if (ch==VMW_F1) {barpos=10; ch=VMW_ENTER;} /*F1*/
if (ch=='l') barpos=3; /*L*/ if (ch=='n') barpos=0; /*N*/
if (ch=='s') barpos=4; /*S*/ if (ch=='o') barpos=1; /*O*/
if (ch=='c') barpos=5; /*C*/ if (ch=='a') barpos=2; /*A*/
if (ch=='q') barpos=6; /*Q*/ if (ch=='l') barpos=3; /*L*/
if (ch==VMW_ESCAPE){ /* escape */ if (ch=='s') barpos=4; /*S*/
barpos=6; if (ch=='c') barpos=5; /*C*/
ch=VMW_ENTER; if (ch=='q') barpos=6; /*Q*/
} if (ch==VMW_ESCAPE){ /* escape */
if(barpos==7) barpos=0; barpos=6;
if(barpos<0) barpos=6; ch=VMW_ENTER;
} }
if (game_state->sound_possible) stopSound(); if(barpos==7) barpos=0;
if(barpos<0) barpos=6;
/* Run whatever it was that the person pressed */ }
switch (barpos) { if (game_state->sound_possible) stopSound();
case 0: playthegame(game_state); reloadpic=1; break;
case 1: options(game_state); reloadpic=1; break; /* Run whatever it was that the person pressed */
case 2: about(game_state); reloadpic=1; break; switch (barpos) {
case 3: loadgame(game_state); reloadpic=1; break; case 0: playthegame(game_state); reloadpic=1; break;
case 4: story(game_state); reloadpic=1; break; case 1: options(game_state); reloadpic=1; break;
case 5: credits(game_state); break; case 2: about(game_state); reloadpic=1; break;
case 6: barpos=quit(game_state); break; case 3: loadgame(game_state); reloadpic=1; break;
case 10: help(game_state); reloadpic=1; break; case 4: story(game_state); reloadpic=1; break;
} case 5: credits(game_state); break;
} case 6: barpos=quit(game_state); break;
} case 10: help(game_state); reloadpic=1; break;
}
}
}

View File

@ -1,69 +1,69 @@
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> /* abs */ #include <stdlib.h> /* abs */
#include "svmwgraph/svmwgraph.h" #include "svmwgraph/svmwgraph.h"
#include "tb1_state.h" #include "tb1_state.h"
#include "graphic_tools.h" #include "graphic_tools.h"
void pauseawhile(int howlong) { void pauseawhile(int howlong) {
struct timeval bob; struct timeval bob;
struct timezone mree; struct timezone mree;
long begin_s,begin_u; long begin_s;
vmwClearKeyboardBuffer(); vmwClearKeyboardBuffer();
gettimeofday(&bob,&mree); gettimeofday(&bob,&mree);
begin_s=bob.tv_sec; begin_u=bob.tv_usec; begin_s=bob.tv_sec;
while ((bob.tv_sec-begin_s)<howlong) { while ((bob.tv_sec-begin_s)<howlong) {
if (vmwGetInput()) return; if (vmwGetInput()) return;
usleep(30); usleep(30);
gettimeofday(&bob,&mree); gettimeofday(&bob,&mree);
} }
} }
/* The collision detection routine. Optimize? */ /* The collision detection routine. Optimize? */
/* Detects if x1,y1 is within x2,y2 */ /* Detects if x1,y1 is within x2,y2 */
int collision(int x1,int y1,int xsize,int ysize, int collision(int x1,int y1,int xsize,int ysize,
int x2,int y2,int x2size,int y2size) int x2,int y2,int x2size,int y2size)
{ {
if (abs((y1+ysize)-(y2+y2size))<(ysize+y2size)){ if (abs((y1+ysize)-(y2+y2size))<(ysize+y2size)){
if (abs((x1+xsize)-(x2+x2size))<(xsize+x2size)) return 1; if (abs((x1+xsize)-(x2+x2size))<(xsize+x2size)) return 1;
} }
return 0; return 0;
} }
/* Now memory-leak friendly */ /* Now memory-leak friendly */
char *tb1_data_file(char *name,char *path) char *tb1_data_file(char *name,char *path)
{ {
static int initialized=0; static int initialized=0;
static char *tempst; static char *tempst;
if (!initialized) { if (!initialized) {
tempst=(char *)calloc(BUFSIZ,sizeof(char)); tempst=(char *)calloc(BUFSIZ,sizeof(char));
initialized=1; initialized=1;
} }
snprintf(tempst,BUFSIZ,"%s/%s",path,name); snprintf(tempst,BUFSIZ,"%s/%s",path,name);
return tempst; return tempst;
} }
int are_you_sure(tb1_state *game_state, int are_you_sure(tb1_state *game_state,
char *warning_1, char *warning_1,
char *warning_2, char *warning_2,
char *yes_option, char *yes_option,
char *no_option) { char *no_option) {
return vmwAreYouSure(game_state->graph_state, return vmwAreYouSure(game_state->graph_state,
game_state->graph_state->default_font, game_state->graph_state->default_font,
game_state->virtual_1, game_state->virtual_1,
warning_1, warning_1,
warning_2, warning_2,
yes_option, yes_option,
no_option); no_option);
} }