mirror of
https://github.com/deater/tb1.git
synced 2025-03-15 18:29:32 +00:00
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:
parent
f0fc207ce7
commit
78c92961dc
@ -18,58 +18,58 @@ tb1: tb1.o ./svmwgraph/libsvmwgraph.a about.o credits.o graphic_tools.o \
|
||||
cd svmwgraph && make
|
||||
|
||||
tb1.o: tb1.c
|
||||
$(CC) -c tb1.c $(INCLUDE)
|
||||
$(CC) $(CFLAGS) -c tb1.c $(INCLUDE)
|
||||
|
||||
about.o: about.c
|
||||
$(CC) -c about.c $(INCLUDE)
|
||||
|
||||
$(CC) $(CFLAGS) -c about.c $(INCLUDE)
|
||||
|
||||
credits.o: credits.c
|
||||
$(CC) -c credits.c $(INCLUDE)
|
||||
$(CC) $(CFLAGS) -c credits.c $(INCLUDE)
|
||||
|
||||
graphic_tools.o: graphic_tools.c
|
||||
$(CC) -c graphic_tools.c $(INCLUDE)
|
||||
$(CC) $(CFLAGS) -c graphic_tools.c $(INCLUDE)
|
||||
|
||||
help.o: help.c
|
||||
$(CC) -c help.c $(INCLUDE)
|
||||
$(CC) $(CFLAGS) -c help.c $(INCLUDE)
|
||||
|
||||
hiscore.o: hiscore.c
|
||||
$(CC) -c hiscore.c $(INCLUDE)
|
||||
$(CC) $(CFLAGS) -c hiscore.c $(INCLUDE)
|
||||
|
||||
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
|
||||
$(CC) -c level2_engine.c $(INCLUDE)
|
||||
$(CC) $(CFLAGS) -c level2_engine.c $(INCLUDE)
|
||||
|
||||
#level_2.o: level_2.c
|
||||
# $(CC) -c level_2.c $(INCLUDE)
|
||||
|
||||
level_3.o: level_3.c
|
||||
$(CC) -c level_3.c $(INCLUDE)
|
||||
$(CC) $(CFLAGS) -c level_3.c $(INCLUDE)
|
||||
|
||||
loadsave.o: loadsave.c
|
||||
$(CC) -c loadsave.c $(INCLUDE)
|
||||
$(CC) $(CFLAGS) -c loadsave.c $(INCLUDE)
|
||||
|
||||
options.o: options.c
|
||||
$(CC) -c options.c $(INCLUDE)
|
||||
$(CC) $(CFLAGS) -c options.c $(INCLUDE)
|
||||
|
||||
playgame.o: playgame.c
|
||||
$(CC) -c playgame.c $(INCLUDE)
|
||||
$(CC) $(CFLAGS) -c playgame.c $(INCLUDE)
|
||||
|
||||
quit.o: quit.c
|
||||
$(CC) -c quit.c $(INCLUDE)
|
||||
$(CC) $(CFLAGS) -c quit.c $(INCLUDE)
|
||||
|
||||
sidebar.o: sidebar.c
|
||||
$(CC) -c sidebar.c $(INCLUDE)
|
||||
$(CC) $(CFLAGS) -c sidebar.c $(INCLUDE)
|
||||
|
||||
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
|
||||
$(CC) -c story.c $(INCLUDE)
|
||||
$(CC) $(CFLAGS) -c story.c $(INCLUDE)
|
||||
|
||||
tblib.o: tblib.c
|
||||
$(CC) -c tblib.c $(INCLUDE)
|
||||
$(CC) $(CFLAGS) -c tblib.c $(INCLUDE)
|
||||
|
||||
clean:
|
||||
rm -f tb1 *.o *~
|
||||
|
@ -8,6 +8,8 @@
|
||||
#
|
||||
CC= gcc
|
||||
|
||||
CFLAGS = -O2 -Wall -g
|
||||
|
||||
#
|
||||
# Uncomment the following for SDL_mixer sound
|
||||
#
|
||||
@ -26,9 +28,9 @@ SDL_INCLUDE= `sdl-config --cflags`
|
||||
#
|
||||
# Uncomment the following for ncurses
|
||||
#
|
||||
#CURSES_TARGET= curses_svmwgraph.o
|
||||
#CURSES_FLAGS= -DCURSES_TARGET=1
|
||||
#CURSES_LIBS= -lncurses
|
||||
CURSES_TARGET= curses_svmwgraph.o
|
||||
CURSES_FLAGS= -DCURSES_TARGET=1
|
||||
CURSES_LIBS= -lncurses
|
||||
|
||||
#
|
||||
# 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
|
||||
#
|
||||
#OPENGL_TARGET= opengl_svmwgraph.o
|
||||
#OPENGL_FLAGS=-DOPENGL_TARGET
|
||||
#OPENGL_LIBS= -L/usr/X11R6/lib -lX11 -lICE -lXmu -lGL -lGLU
|
||||
OPENGL_TARGET= opengl_svmwgraph.o
|
||||
OPENGL_FLAGS=-DOPENGL_TARGET
|
||||
OPENGL_LIBS= -lX11 -lICE -lGL -lGLU
|
||||
|
||||
|
||||
##############################
|
||||
# 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)
|
||||
|
File diff suppressed because it is too large
Load Diff
1673
tb1_linux/level_1.c
1673
tb1_linux/level_1.c
File diff suppressed because it is too large
Load Diff
1815
tb1_linux/level_3.c
1815
tb1_linux/level_3.c
File diff suppressed because it is too large
Load Diff
@ -4,49 +4,49 @@ INCLUDE= $(INCLUDE_GLOBAL)
|
||||
LIBS= $(LIBS_GLOBAL)
|
||||
|
||||
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)
|
||||
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
|
||||
|
||||
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
|
||||
$(CC) $(INCLUDE) -c vmw_dialogs.c
|
||||
$(CC) $(CFLAGS) $(INCLUDE) -c vmw_dialogs.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
|
||||
$(CC) $(INCLUDE) -c vmw_font.c
|
||||
$(CC) $(CFLAGS) $(INCLUDE) -c vmw_font.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
|
||||
$(CC) $(INCLUDE) -c vmw_palette.c
|
||||
$(CC) $(CFLAGS) $(INCLUDE) -c vmw_palette.c
|
||||
|
||||
vmw_pcx.o: vmw_pcx.c
|
||||
$(CC) $(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
|
||||
$(CC) $(CFLAGS) $(INCLUDE) -c vmw_pcx.c
|
||||
|
||||
curses_svmwgraph.o: curses_svmwgraph.c
|
||||
$(CC) $(INCLUDE) -c curses_svmwgraph.c $(CURSES_FLAGS)
|
||||
vmw_setup.o: vmw_setup.c
|
||||
$(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
|
||||
$(CC) $(INCLUDE) -c null_svmwgraph.c
|
||||
|
||||
$(CC) $(CFLAGS) $(INCLUDE) -c null_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
|
||||
$(CC) $(INCLUDE) -c sdl_svmwgraph.c
|
||||
$(CC) $(CFLAGS) $(INCLUDE) -c sdl_svmwgraph.c
|
||||
|
||||
clean:
|
||||
rm -f libsvmwgraph.a *.o *~
|
||||
|
@ -1,352 +1,349 @@
|
||||
/* The OpenGL hooks for the Super VMW graphics library */
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
|
||||
#include "svmwgraph.h"
|
||||
#include <stdlib.h> /* For atexit() */
|
||||
#include <stdio.h>
|
||||
|
||||
static float rotation=0.0;
|
||||
|
||||
unsigned char palette[256][4];
|
||||
|
||||
#define TEXTURE_SIZE 64
|
||||
|
||||
int texture_grid[5][4];
|
||||
GLubyte *texture_data[5][4];
|
||||
|
||||
|
||||
typedef struct {
|
||||
GLubyte *texture_data;
|
||||
GLuint texture_name;
|
||||
GLfloat x1,y1,x2,y2;
|
||||
} texture_block;
|
||||
|
||||
|
||||
texture_block *current_texture;
|
||||
|
||||
GLuint temp_texture_name;
|
||||
int texnumx,texnumy;
|
||||
|
||||
|
||||
|
||||
void reshape(int w,int h) {
|
||||
glViewport(0,0,(GLsizei)w,(GLsizei)h);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(60.0,(GLfloat)w/(GLfloat)h,1.0,100.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
//glTranslatef(0.0,0.0,-3.6);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Setup the Graphics */
|
||||
/* Pass '0' to auto-detect bpp */
|
||||
void *openGL_setupGraphics(int *xsize,int *ysize,int *bpp,
|
||||
int fullscreen,int verbose) {
|
||||
|
||||
SDL_Surface *sdl_screen=NULL;
|
||||
SDL_Joystick *joy;
|
||||
int mode,x,y;
|
||||
|
||||
/* Initialize SDL */
|
||||
if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK)<0) {
|
||||
printf("Error trying to init SDL: %s\n",SDL_GetError());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fullscreen) mode=SDL_OPENGL | SDL_FULLSCREEN;
|
||||
else mode=SDL_OPENGL;
|
||||
|
||||
/* Create the OpenGL screen */
|
||||
if ( (sdl_screen=SDL_SetVideoMode(*xsize, *ysize, 0, mode)) == NULL ) {
|
||||
printf("Unable to create OpenGL screen: %s\n", SDL_GetError());
|
||||
SDL_Quit();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
atexit(SDL_Quit);
|
||||
|
||||
SDL_WM_SetCaption("Tom Bombem...",NULL);
|
||||
|
||||
/* Try to init Joysticks */
|
||||
if (SDL_NumJoysticks()>0){
|
||||
/* Open joystick */
|
||||
joy=SDL_JoystickOpen(0);
|
||||
if (joy) {
|
||||
printf("Opened Joystick 0\n");
|
||||
printf("Name: %s\n", SDL_JoystickName(0));
|
||||
SDL_JoystickEventState(SDL_ENABLE);
|
||||
}
|
||||
}
|
||||
|
||||
printf(" GL_VERSION: %s\n", glGetString(GL_VERSION));
|
||||
printf(" GL_VENDOR: %s\n", glGetString(GL_VENDOR));
|
||||
printf(" GL_RENDERER: %s\n", glGetString(GL_RENDERER));
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
|
||||
glClearColor(0.0,0.0,0.0,0.0);
|
||||
glClearDepth(1.0);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
||||
glLoadIdentity();
|
||||
|
||||
reshape(*xsize,*ysize);
|
||||
|
||||
printf("Init!\n"); fflush(stdout);
|
||||
|
||||
// Initializing Textures!!
|
||||
//
|
||||
|
||||
|
||||
for(x=0;x<5;x++) {
|
||||
for(y=0;y<4;y++) {
|
||||
texture_data[x][y]=calloc(64*64,sizeof(char)*4);
|
||||
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_T, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64,
|
||||
64 ,0,GL_RGBA,GL_UNSIGNED_BYTE,texture_data[x][y]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
texnumx=320/TEXTURE_SIZE;
|
||||
if (320%TEXTURE_SIZE) texnumx++;
|
||||
texnumy=200/TEXTURE_SIZE;
|
||||
if (200%TEXTURE_SIZE) texnumy++;
|
||||
|
||||
texture_grid=calloc(texnumx*texnumy,sizeof(texture_block));
|
||||
|
||||
for(x=0;x<texnumx;x++) {
|
||||
for(y=0;y<texnumy;y++) {
|
||||
current_texture=texture_grid+y*texnumx+x;
|
||||
printf("%p\n",current_texture);
|
||||
current_texture->texture_data=malloc(TEXTURE_SIZE*TEXTURE_SIZE);
|
||||
|
||||
current_texture->x1=x*TEXTURE_SIZE;
|
||||
current_texture->y1=y*TEXTURE_SIZE;
|
||||
current_texture->x2=(x+1)*TEXTURE_SIZE;
|
||||
if (current_texture->x2>320) current_texture->x2=320;
|
||||
current_texture->y2=(y+1)*TEXTURE_SIZE;
|
||||
if (current_texture->y2>200) current_texture->y2=200;
|
||||
|
||||
glGenTextures(1,&temp_texture_name);
|
||||
|
||||
current_texture->texture_name=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_T, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,TEXTURE_SIZE,
|
||||
TEXTURE_SIZE,0,GL_RGBA,GL_UNSIGNED_BYTE,
|
||||
current_texture->texture_data);
|
||||
// glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
glOrtho(-20,340,-20,220,-100,100);
|
||||
|
||||
// gluPerspective(60,1.6,-10,10);
|
||||
#endif
|
||||
return sdl_screen;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void openGL_flushPalette(vmwSVMWGraphState *state) {
|
||||
|
||||
int i;
|
||||
|
||||
for(i=0;i<256;i++) {
|
||||
palette[i][0]=((state->palette[i]>>11)<<3);
|
||||
palette[i][1]=( ((state->palette[i]>>5)&0x3f)<<2);
|
||||
palette[i][2]=((state->palette[i]&0x1f)<<3);
|
||||
palette[i][3]=255;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void openGL_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
|
||||
|
||||
|
||||
int x=0,y=0,temp_col,i,j,ending_j,ending_i;
|
||||
unsigned char *s_pointer;
|
||||
|
||||
GLubyte temp_data[64*64*4];
|
||||
|
||||
GLubyte *t_pointer;
|
||||
|
||||
GLfloat light_position[]={0.0,0.0,25.0,0.0};
|
||||
GLfloat light_ambient[]={0.65,0.65,0.65,1.0};
|
||||
GLfloat lmodel_ambient[]={0.4,0.4,0.4,1.0};
|
||||
GLfloat white_light[]={1.0,1.0,1.0,1.0};
|
||||
|
||||
|
||||
glLoadIdentity();
|
||||
|
||||
gluLookAt(0.0,0.0,20.0,
|
||||
0.0,0.0,0.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);
|
||||
|
||||
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glColor3f(1,0,0);
|
||||
{
|
||||
GLfloat default_a[]={0.6,0.6,0.6,1.0
|
||||
};
|
||||
GLfloat default_d[]={ 0.8,0.8,0.8,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_EMISSION,default_e);
|
||||
}
|
||||
#if 0
|
||||
for (x=0;x<source->xsize;x++)
|
||||
for (y=0;y<source->ysize;y++) {
|
||||
*((Uint16 *)(t_pointer))=target_p->palette[*(s_pointer)];
|
||||
s_pointer++; t_pointer+=2;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
glRotatef(rotation,1,1,1);
|
||||
rotation+=1.0;
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
|
||||
|
||||
for(i=0;i<5;i++) {
|
||||
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(y=0;y<64;y++) {
|
||||
for(x=0;x<64;x++) {
|
||||
temp_data[ ((y*64)+x)*4] =palette[*(s_pointer)][0];
|
||||
temp_data[ ((y*64)+x)*4+1] =palette[*(s_pointer)][1];
|
||||
temp_data[ ((y*64)+x)*4+2] =palette[*(s_pointer)][2];
|
||||
temp_data[ ((y*64)+x)*4+3] =palette[*(s_pointer)][3];
|
||||
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,
|
||||
&temp_data);
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef( i*4,-(j*4),0);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glNormal3f(0.0,0.0,1.0);
|
||||
glTexCoord2f(0,0);
|
||||
glVertex3f(-2,2,0);
|
||||
glTexCoord2f(1,0);
|
||||
glVertex3f(2,2,0);
|
||||
glTexCoord2f(1,1);
|
||||
glVertex3f(2,-2,0);
|
||||
glTexCoord2f(0,1);
|
||||
glVertex3f(-2,-2,0);
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
#if 0
|
||||
|
||||
// glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
for(y=0;y<texnumy;y++) {
|
||||
for(x=0;x<texnumx;x++) {
|
||||
current_texture=texture_grid+y*texnumx+x;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D,current_texture->texture_name);
|
||||
|
||||
s_pointer=source->memory+((y*TEXTURE_SIZE)*320)+(x*TEXTURE_SIZE);
|
||||
|
||||
t_pointer=(current_texture->texture_data);
|
||||
|
||||
ending_j=TEXTURE_SIZE;
|
||||
if (((y*TEXTURE_SIZE)+TEXTURE_SIZE)>200)
|
||||
ending_j=200%TEXTURE_SIZE;
|
||||
|
||||
ending_i=TEXTURE_SIZE;
|
||||
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);
|
||||
// printf(">>>%p %p=%i\n",t_pointer,s_pointer,temp_col); fflush(stdout);
|
||||
memcpy(t_pointer,palette[temp_col],3);
|
||||
s_pointer++;
|
||||
t_pointer+=4;
|
||||
}
|
||||
s_pointer+=(320-TEXTURE_SIZE);
|
||||
}
|
||||
|
||||
glTexSubImage2D(GL_TEXTURE_2D,
|
||||
0,0,0,TEXTURE_SIZE,TEXTURE_SIZE,
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
current_texture->texture_data);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
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);
|
||||
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);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glPopMatrix();
|
||||
#endif
|
||||
glFlush();
|
||||
SDL_GL_SwapBuffers();
|
||||
glDisable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
|
||||
void openGL_closeGraphics() {
|
||||
}
|
||||
/* The OpenGL hooks for the Super VMW graphics library */
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
|
||||
#include "svmwgraph.h"
|
||||
#include <stdlib.h> /* For atexit() */
|
||||
#include <stdio.h>
|
||||
|
||||
static float rotation=0.0;
|
||||
|
||||
unsigned char palette[256][4];
|
||||
|
||||
#define TEXTURE_SIZE 64
|
||||
|
||||
int texture_grid[5][4];
|
||||
GLubyte *texture_data[5][4];
|
||||
|
||||
|
||||
typedef struct {
|
||||
GLubyte *texture_data;
|
||||
GLuint texture_name;
|
||||
GLfloat x1,y1,x2,y2;
|
||||
} texture_block;
|
||||
|
||||
|
||||
texture_block *current_texture;
|
||||
|
||||
GLuint temp_texture_name;
|
||||
int texnumx,texnumy;
|
||||
|
||||
|
||||
|
||||
void reshape(int w,int h) {
|
||||
glViewport(0,0,(GLsizei)w,(GLsizei)h);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(60.0,(GLfloat)w/(GLfloat)h,1.0,100.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
//glTranslatef(0.0,0.0,-3.6);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Setup the Graphics */
|
||||
/* Pass '0' to auto-detect bpp */
|
||||
void *openGL_setupGraphics(int *xsize,int *ysize,int *bpp,
|
||||
int fullscreen,int verbose) {
|
||||
|
||||
SDL_Surface *sdl_screen=NULL;
|
||||
SDL_Joystick *joy;
|
||||
int mode,x,y;
|
||||
|
||||
/* Initialize SDL */
|
||||
if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK)<0) {
|
||||
printf("Error trying to init SDL: %s\n",SDL_GetError());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fullscreen) mode=SDL_OPENGL | SDL_FULLSCREEN;
|
||||
else mode=SDL_OPENGL;
|
||||
|
||||
/* Create the OpenGL screen */
|
||||
if ( (sdl_screen=SDL_SetVideoMode(*xsize, *ysize, 0, mode)) == NULL ) {
|
||||
printf("Unable to create OpenGL screen: %s\n", SDL_GetError());
|
||||
SDL_Quit();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
atexit(SDL_Quit);
|
||||
|
||||
SDL_WM_SetCaption("Tom Bombem...",NULL);
|
||||
|
||||
/* Try to init Joysticks */
|
||||
if (SDL_NumJoysticks()>0){
|
||||
/* Open joystick */
|
||||
joy=SDL_JoystickOpen(0);
|
||||
if (joy) {
|
||||
printf("Opened Joystick 0\n");
|
||||
printf("Name: %s\n", SDL_JoystickName(0));
|
||||
SDL_JoystickEventState(SDL_ENABLE);
|
||||
}
|
||||
}
|
||||
|
||||
printf(" GL_VERSION: %s\n", glGetString(GL_VERSION));
|
||||
printf(" GL_VENDOR: %s\n", glGetString(GL_VENDOR));
|
||||
printf(" GL_RENDERER: %s\n", glGetString(GL_RENDERER));
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
|
||||
glClearColor(0.0,0.0,0.0,0.0);
|
||||
glClearDepth(1.0);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
||||
glLoadIdentity();
|
||||
|
||||
reshape(*xsize,*ysize);
|
||||
|
||||
printf("Init!\n"); fflush(stdout);
|
||||
|
||||
// Initializing Textures!!
|
||||
//
|
||||
|
||||
|
||||
for(x=0;x<5;x++) {
|
||||
for(y=0;y<4;y++) {
|
||||
texture_data[x][y]=calloc(64*64,sizeof(char)*4);
|
||||
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_T, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64,
|
||||
64 ,0,GL_RGBA,GL_UNSIGNED_BYTE,texture_data[x][y]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
texnumx=320/TEXTURE_SIZE;
|
||||
if (320%TEXTURE_SIZE) texnumx++;
|
||||
texnumy=200/TEXTURE_SIZE;
|
||||
if (200%TEXTURE_SIZE) texnumy++;
|
||||
|
||||
texture_grid=calloc(texnumx*texnumy,sizeof(texture_block));
|
||||
|
||||
for(x=0;x<texnumx;x++) {
|
||||
for(y=0;y<texnumy;y++) {
|
||||
current_texture=texture_grid+y*texnumx+x;
|
||||
printf("%p\n",current_texture);
|
||||
current_texture->texture_data=malloc(TEXTURE_SIZE*TEXTURE_SIZE);
|
||||
|
||||
current_texture->x1=x*TEXTURE_SIZE;
|
||||
current_texture->y1=y*TEXTURE_SIZE;
|
||||
current_texture->x2=(x+1)*TEXTURE_SIZE;
|
||||
if (current_texture->x2>320) current_texture->x2=320;
|
||||
current_texture->y2=(y+1)*TEXTURE_SIZE;
|
||||
if (current_texture->y2>200) current_texture->y2=200;
|
||||
|
||||
glGenTextures(1,&temp_texture_name);
|
||||
|
||||
current_texture->texture_name=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_T, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,TEXTURE_SIZE,
|
||||
TEXTURE_SIZE,0,GL_RGBA,GL_UNSIGNED_BYTE,
|
||||
current_texture->texture_data);
|
||||
// glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
glOrtho(-20,340,-20,220,-100,100);
|
||||
|
||||
// gluPerspective(60,1.6,-10,10);
|
||||
#endif
|
||||
return sdl_screen;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void openGL_flushPalette(vmwSVMWGraphState *state) {
|
||||
|
||||
int i;
|
||||
|
||||
for(i=0;i<256;i++) {
|
||||
palette[i][0]=((state->palette[i]>>11)<<3);
|
||||
palette[i][1]=( ((state->palette[i]>>5)&0x3f)<<2);
|
||||
palette[i][2]=((state->palette[i]&0x1f)<<3);
|
||||
palette[i][3]=255;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void openGL_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
|
||||
|
||||
|
||||
int x=0,y=0,i,j;//temp_col,ending_j,ending_i;
|
||||
unsigned char *s_pointer;
|
||||
|
||||
GLubyte temp_data[64*64*4];
|
||||
|
||||
// GLubyte *t_pointer;
|
||||
|
||||
GLfloat light_position[]={0.0,0.0,25.0,0.0};
|
||||
// GLfloat light_ambient[]={0.65,0.65,0.65,1.0};
|
||||
GLfloat lmodel_ambient[]={0.4,0.4,0.4,1.0};
|
||||
GLfloat white_light[]={1.0,1.0,1.0,1.0};
|
||||
|
||||
glLoadIdentity();
|
||||
|
||||
gluLookAt(0.0,0.0,20.0,
|
||||
0.0,0.0,0.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);
|
||||
|
||||
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glColor3f(1,0,0);
|
||||
{
|
||||
GLfloat default_a[]={0.6,0.6,0.6,1.0
|
||||
};
|
||||
GLfloat default_d[]={ 0.8,0.8,0.8,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_EMISSION,default_e);
|
||||
}
|
||||
#if 0
|
||||
for (x=0;x<source->xsize;x++)
|
||||
for (y=0;y<source->ysize;y++) {
|
||||
*((Uint16 *)(t_pointer))=target_p->palette[*(s_pointer)];
|
||||
s_pointer++; t_pointer+=2;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
glRotatef(rotation,1,1,1);
|
||||
rotation+=1.0;
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
|
||||
|
||||
for(i=0;i<5;i++) {
|
||||
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(y=0;y<64;y++) {
|
||||
for(x=0;x<64;x++) {
|
||||
temp_data[ ((y*64)+x)*4] =palette[*(s_pointer)][0];
|
||||
temp_data[ ((y*64)+x)*4+1] =palette[*(s_pointer)][1];
|
||||
temp_data[ ((y*64)+x)*4+2] =palette[*(s_pointer)][2];
|
||||
temp_data[ ((y*64)+x)*4+3] =palette[*(s_pointer)][3];
|
||||
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,
|
||||
&temp_data);
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef( i*4,-(j*4),0);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glNormal3f(0.0,0.0,1.0);
|
||||
glTexCoord2f(0,0);
|
||||
glVertex3f(-2,2,0);
|
||||
glTexCoord2f(1,0);
|
||||
glVertex3f(2,2,0);
|
||||
glTexCoord2f(1,1);
|
||||
glVertex3f(2,-2,0);
|
||||
glTexCoord2f(0,1);
|
||||
glVertex3f(-2,-2,0);
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
#if 0
|
||||
|
||||
// glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
for(y=0;y<texnumy;y++) {
|
||||
for(x=0;x<texnumx;x++) {
|
||||
current_texture=texture_grid+y*texnumx+x;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D,current_texture->texture_name);
|
||||
|
||||
s_pointer=source->memory+((y*TEXTURE_SIZE)*320)+(x*TEXTURE_SIZE);
|
||||
|
||||
t_pointer=(current_texture->texture_data);
|
||||
|
||||
ending_j=TEXTURE_SIZE;
|
||||
if (((y*TEXTURE_SIZE)+TEXTURE_SIZE)>200)
|
||||
ending_j=200%TEXTURE_SIZE;
|
||||
|
||||
ending_i=TEXTURE_SIZE;
|
||||
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);
|
||||
// printf(">>>%p %p=%i\n",t_pointer,s_pointer,temp_col); fflush(stdout);
|
||||
memcpy(t_pointer,palette[temp_col],3);
|
||||
s_pointer++;
|
||||
t_pointer+=4;
|
||||
}
|
||||
s_pointer+=(320-TEXTURE_SIZE);
|
||||
}
|
||||
|
||||
glTexSubImage2D(GL_TEXTURE_2D,
|
||||
0,0,0,TEXTURE_SIZE,TEXTURE_SIZE,
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
current_texture->texture_data);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
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);
|
||||
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);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glPopMatrix();
|
||||
#endif
|
||||
glFlush();
|
||||
SDL_GL_SwapBuffers();
|
||||
glDisable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
|
||||
void openGL_closeGraphics() {
|
||||
}
|
||||
|
@ -1,450 +1,444 @@
|
||||
/* The SDL hooks for the Super VMW graphics library */
|
||||
|
||||
#include <SDL.h>
|
||||
#include "svmwgraph.h"
|
||||
#include <stdlib.h> /* For atexit() */
|
||||
|
||||
/* Setup the Graphics */
|
||||
/* Pass '0' to auto-detect bpp */
|
||||
void *SDL_setupGraphics(int *xsize,int *ysize,int *bpp,
|
||||
int fullscreen,int verbose)
|
||||
{
|
||||
SDL_Surface *sdl_screen=NULL;
|
||||
int mode;
|
||||
SDL_Joystick *joy;
|
||||
|
||||
mode=SDL_SWSURFACE|SDL_HWPALETTE|SDL_HWSURFACE;
|
||||
if (fullscreen) mode|=SDL_FULLSCREEN;
|
||||
|
||||
/* Initialize the SDL library */
|
||||
if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0 ) {
|
||||
fprintf(stderr,
|
||||
"Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Clean up on exit */
|
||||
atexit(SDL_Quit);
|
||||
|
||||
/* Detect Joystick */
|
||||
if (SDL_NumJoysticks()>0){
|
||||
/* Open joystick */
|
||||
joy=SDL_JoystickOpen(0);
|
||||
if (joy) {
|
||||
printf("Opened Joystick 0\n");
|
||||
printf("Name: %s\n", SDL_JoystickName(0));
|
||||
SDL_JoystickEventState(SDL_ENABLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (*bpp!=0) {
|
||||
|
||||
/* Initialize the display */
|
||||
sdl_screen = SDL_SetVideoMode(*xsize, *ysize, *bpp, mode);
|
||||
}
|
||||
else {
|
||||
sdl_screen=SDL_SetVideoMode(*xsize,*ysize,0,mode);
|
||||
}
|
||||
|
||||
|
||||
if ( sdl_screen == NULL ) {
|
||||
fprintf(stderr, "ERROR! Couldn't set %dx%d video mode: %s\n",
|
||||
*xsize,*ysize,SDL_GetError());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (*bpp==0) *bpp=sdl_screen->format->BytesPerPixel*8;
|
||||
if (verbose) {
|
||||
printf(" + SDL Graphics Initialization successful...\n");
|
||||
printf(" + Using %dx%dx%dbpp Visual...\n",*xsize,*ysize,*bpp);
|
||||
#if BYTE_ORDER==LITTLE_ENDIAN
|
||||
printf(" + Little-endian byte-order detected\n");
|
||||
#else
|
||||
printf(" + Big-endian byte-order detected\n");
|
||||
#endif
|
||||
printf(" + Red: %x Green: %x Blue: %x Alpha: %x\n",
|
||||
sdl_screen->format->Rmask,
|
||||
sdl_screen->format->Gmask,
|
||||
sdl_screen->format->Bmask,
|
||||
sdl_screen->format->Amask);
|
||||
}
|
||||
return sdl_screen;
|
||||
}
|
||||
|
||||
|
||||
void SDL_flushPalette(vmwSVMWGraphState *state) {
|
||||
|
||||
SDL_Surface *target;
|
||||
SDL_Color temp_col[256];
|
||||
int i;
|
||||
|
||||
if (state->bpp==8) {
|
||||
for(i=0;i<256;i++) {
|
||||
temp_col[i].r=(state->palette[i]>>11)<<3;
|
||||
temp_col[i].g=((state->palette[i]>>5)&0x3f)<<2;
|
||||
temp_col[i].b=(state->palette[i]&0x1f)<<3;
|
||||
}
|
||||
|
||||
target=(SDL_Surface *)state->output_screen;
|
||||
|
||||
SDL_SetColors(target,temp_col,0,256);
|
||||
}
|
||||
}
|
||||
|
||||
void SDL_NoScale32bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
|
||||
|
||||
int x,y,color;
|
||||
|
||||
unsigned char *s_pointer,*t_pointer;
|
||||
|
||||
SDL_Surface *target;
|
||||
|
||||
target=(SDL_Surface *)target_p->output_screen;
|
||||
|
||||
if ( SDL_MUSTLOCK(target) ) {
|
||||
if ( SDL_LockSurface(target) < 0 )
|
||||
return;
|
||||
}
|
||||
|
||||
s_pointer=source->memory;
|
||||
t_pointer=((Uint8 *)target->pixels);
|
||||
|
||||
// printf("%i %i\n",source->xsize,source->ysize);
|
||||
|
||||
for (x=0;x<source->xsize;x++)
|
||||
for (y=0;y<source->ysize;y++) {
|
||||
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)].b);
|
||||
|
||||
*((Uint32 *)(t_pointer))=color;
|
||||
s_pointer++; t_pointer+=4;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Update the display */
|
||||
if ( SDL_MUSTLOCK(target) ) {
|
||||
SDL_UnlockSurface(target);
|
||||
}
|
||||
|
||||
/* Write this out to the screen */
|
||||
SDL_UpdateRect(target, 0, 0, source->xsize, source->ysize);
|
||||
}
|
||||
|
||||
|
||||
void SDL_Double32bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
|
||||
|
||||
int x,y,scale,color;
|
||||
|
||||
unsigned char *s_pointer,*t_pointer;
|
||||
|
||||
SDL_Surface *target;
|
||||
|
||||
target=(SDL_Surface *)target_p->output_screen;
|
||||
|
||||
scale=target_p->scale;
|
||||
|
||||
if ( SDL_MUSTLOCK(target) ) {
|
||||
if ( SDL_LockSurface(target) < 0 )
|
||||
return;
|
||||
}
|
||||
|
||||
s_pointer=source->memory;
|
||||
t_pointer=((Uint8 *)target->pixels);
|
||||
|
||||
for(y=0;y<source->ysize;y++) {
|
||||
for(x=0;x<source->xsize;x++) {
|
||||
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)].b);
|
||||
|
||||
/* i=0, j=0 */
|
||||
*((Uint32 *) ( (t_pointer)))=color;
|
||||
|
||||
/* i=1, j=0 */
|
||||
*((Uint32 *) ( (t_pointer+(4*target_p->xsize) )))=color;
|
||||
|
||||
/* i=0, j=1 */
|
||||
*((Uint32 *) ( (t_pointer+4) ))=color;
|
||||
|
||||
/* i=1 j=1 */
|
||||
*((Uint32 *) ( (t_pointer+4+(4*target_p->xsize) )))=color;
|
||||
|
||||
s_pointer++; t_pointer+=8;
|
||||
}
|
||||
t_pointer+=4*target_p->xsize;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
|
||||
void SDL_NoScale16bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
|
||||
|
||||
int x,y;
|
||||
|
||||
unsigned char *s_pointer,*t_pointer;
|
||||
|
||||
SDL_Surface *target;
|
||||
|
||||
target=(SDL_Surface *)target_p->output_screen;
|
||||
|
||||
if ( SDL_MUSTLOCK(target) ) {
|
||||
if ( SDL_LockSurface(target) < 0 )
|
||||
return;
|
||||
}
|
||||
|
||||
s_pointer=source->memory;
|
||||
t_pointer=((Uint8 *)target->pixels);
|
||||
|
||||
// printf("%i %i\n",source->xsize,source->ysize);
|
||||
|
||||
for (x=0;x<source->xsize;x++)
|
||||
for (y=0;y<source->ysize;y++) {
|
||||
*((Uint16 *)(t_pointer))=target_p->palette[*(s_pointer)];
|
||||
s_pointer++; t_pointer+=2;
|
||||
}
|
||||
|
||||
|
||||
/* Update the display */
|
||||
if ( SDL_MUSTLOCK(target) ) {
|
||||
SDL_UnlockSurface(target);
|
||||
}
|
||||
|
||||
/* Write this out to the screen */
|
||||
SDL_UpdateRect(target, 0, 0, source->xsize, source->ysize);
|
||||
|
||||
}
|
||||
|
||||
/* I should make this generic, but it makes it really slow */
|
||||
void SDL_Double16bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
|
||||
|
||||
int x,y,scale;
|
||||
|
||||
unsigned char *s_pointer,*t_pointer;
|
||||
|
||||
SDL_Surface *target;
|
||||
|
||||
target=(SDL_Surface *)target_p->output_screen;
|
||||
|
||||
scale=target_p->scale;
|
||||
|
||||
if ( SDL_MUSTLOCK(target) ) {
|
||||
if ( SDL_LockSurface(target) < 0 )
|
||||
return;
|
||||
}
|
||||
|
||||
s_pointer=source->memory;
|
||||
t_pointer=((Uint8 *)target->pixels);
|
||||
|
||||
for (y=0;y<source->ysize;y++) {
|
||||
for (x=0;x<source->xsize;x++) {
|
||||
|
||||
/* i=0, j=0 */
|
||||
*((Uint16 *) ( (t_pointer)))=
|
||||
target_p->palette[*(s_pointer)];
|
||||
|
||||
/* i=1, j=0 */
|
||||
*((Uint16 *) ( (t_pointer+(2*target_p->xsize) )))=
|
||||
target_p->palette[*(s_pointer)];
|
||||
/* i=0, j=1 */
|
||||
*((Uint16 *) ( (t_pointer+2) ))=
|
||||
target_p->palette[*(s_pointer)];
|
||||
|
||||
/* i=1 j=1 */
|
||||
*((Uint16 *) ( (t_pointer+2+(2*target_p->xsize) )))=
|
||||
target_p->palette[*(s_pointer)];
|
||||
|
||||
|
||||
s_pointer++; t_pointer+=4;
|
||||
}
|
||||
t_pointer+=2*target_p->xsize;
|
||||
}
|
||||
|
||||
|
||||
/* 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);
|
||||
|
||||
}
|
||||
|
||||
void SDL_NoScale8bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
|
||||
|
||||
int x,y;
|
||||
|
||||
unsigned char *s_pointer,*t_pointer;
|
||||
|
||||
SDL_Surface *target;
|
||||
|
||||
target=(SDL_Surface *)target_p->output_screen;
|
||||
|
||||
if ( SDL_MUSTLOCK(target) ) {
|
||||
if ( SDL_LockSurface(target) < 0 )
|
||||
return;
|
||||
}
|
||||
|
||||
s_pointer=source->memory;
|
||||
t_pointer=((Uint8 *)target->pixels);
|
||||
|
||||
for (x=0;x<source->xsize;x++)
|
||||
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);
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
unsigned char *s_pointer,*t_pointer;
|
||||
|
||||
SDL_Surface *target;
|
||||
|
||||
target=(SDL_Surface *)target_p->output_screen;
|
||||
|
||||
if ( SDL_MUSTLOCK(target) ) {
|
||||
if ( SDL_LockSurface(target) < 0 )
|
||||
return;
|
||||
}
|
||||
|
||||
s_pointer=source->memory;
|
||||
t_pointer=((Uint8 *)target->pixels);
|
||||
|
||||
for (y=0;y<source->ysize;y++) {
|
||||
for (x=0;x<source->xsize;x++) {
|
||||
/* i=0, j=0 */
|
||||
*((Uint8 *)(t_pointer))=*(s_pointer);
|
||||
/* i=1, j=0 */
|
||||
*((Uint8 *)(t_pointer+(target_p->xsize)))=*(s_pointer);
|
||||
/* i=0, j=1 */
|
||||
*((Uint8 *)(t_pointer+1))=*(s_pointer);
|
||||
/* i=1, j=1 */
|
||||
*((Uint8 *)(t_pointer+1+target_p->xsize))=*(s_pointer);
|
||||
s_pointer++; t_pointer+=2;
|
||||
}
|
||||
t_pointer+=target_p->xsize;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SDL_clearKeyboardBuffer() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int SDL_getInput() {
|
||||
|
||||
SDL_Event event;
|
||||
int keypressed,button;
|
||||
int axis,direction;
|
||||
|
||||
static int going_right=0;
|
||||
static int going_left=0;
|
||||
|
||||
while ( SDL_PollEvent(&event)) {
|
||||
|
||||
switch(event.type) {
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
button=event.jbutton.button;
|
||||
// printf("BUTTON %i\n",button);
|
||||
switch(button) {
|
||||
case 0: return ' ';
|
||||
case 1: return VMW_ENTER;
|
||||
}
|
||||
break;
|
||||
case SDL_JOYAXISMOTION:
|
||||
axis=event.jaxis.axis;
|
||||
direction=event.jaxis.value;
|
||||
// printf("%i %i\n",axis,direction);
|
||||
if (axis==0) { /* X */
|
||||
|
||||
if (direction>5000) {
|
||||
if (!going_right) {
|
||||
going_right=1;
|
||||
return VMW_RIGHT;
|
||||
}
|
||||
}
|
||||
else if (direction<-5000) {
|
||||
if (!going_left) {
|
||||
going_left=1;
|
||||
return VMW_LEFT;
|
||||
}
|
||||
}
|
||||
else {
|
||||
going_left=0;
|
||||
going_right=0;
|
||||
}
|
||||
}
|
||||
// if (axis==1) { /* Y */
|
||||
// if (direction>0) return VMW_UP;
|
||||
// if (direction<0) return VMW_DOWN;
|
||||
// }
|
||||
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
keypressed=event.key.keysym.sym;
|
||||
switch (keypressed) {
|
||||
case SDLK_BACKSPACE: return VMW_BACKSPACE;
|
||||
case SDLK_ESCAPE : return VMW_ESCAPE;
|
||||
case SDLK_RETURN : return VMW_ENTER;
|
||||
case SDLK_UP : return VMW_UP;
|
||||
case SDLK_DOWN : return VMW_DOWN;
|
||||
case SDLK_RIGHT : return VMW_RIGHT;
|
||||
case SDLK_LEFT : return VMW_LEFT;
|
||||
case SDLK_F1 : return VMW_F1;
|
||||
case SDLK_F2 : return VMW_F2;
|
||||
case SDLK_PAGEUP : return VMW_PGUP;
|
||||
case SDLK_PAGEDOWN : return VMW_PGDN;
|
||||
case SDLK_HOME : return VMW_HOME;
|
||||
case SDLK_END : return VMW_END;
|
||||
case SDLK_INSERT : return VMW_INS;
|
||||
case SDLK_DELETE : return VMW_DEL;
|
||||
default: if ((keypressed>='a') && (keypressed<='z')
|
||||
&& (event.key.keysym.mod & KMOD_SHIFT) )
|
||||
return keypressed-32;
|
||||
else return keypressed;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SDL_closeGraphics() {
|
||||
}
|
||||
/* The SDL hooks for the Super VMW graphics library */
|
||||
|
||||
#include <SDL.h>
|
||||
#include "svmwgraph.h"
|
||||
#include <stdlib.h> /* For atexit() */
|
||||
|
||||
/* Setup the Graphics */
|
||||
/* Pass '0' to auto-detect bpp */
|
||||
void *SDL_setupGraphics(int *xsize,int *ysize,int *bpp,
|
||||
int fullscreen,int verbose)
|
||||
{
|
||||
SDL_Surface *sdl_screen=NULL;
|
||||
int mode;
|
||||
SDL_Joystick *joy;
|
||||
|
||||
mode=SDL_SWSURFACE|SDL_HWPALETTE|SDL_HWSURFACE;
|
||||
if (fullscreen) mode|=SDL_FULLSCREEN;
|
||||
|
||||
/* Initialize the SDL library */
|
||||
if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0 ) {
|
||||
fprintf(stderr,
|
||||
"Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Clean up on exit */
|
||||
atexit(SDL_Quit);
|
||||
|
||||
/* Detect Joystick */
|
||||
if (SDL_NumJoysticks()>0){
|
||||
/* Open joystick */
|
||||
joy=SDL_JoystickOpen(0);
|
||||
if (joy) {
|
||||
printf("Opened Joystick 0\n");
|
||||
printf("Name: %s\n", SDL_JoystickName(0));
|
||||
SDL_JoystickEventState(SDL_ENABLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (*bpp!=0) {
|
||||
|
||||
/* Initialize the display */
|
||||
sdl_screen = SDL_SetVideoMode(*xsize, *ysize, *bpp, mode);
|
||||
}
|
||||
else {
|
||||
sdl_screen=SDL_SetVideoMode(*xsize,*ysize,0,mode);
|
||||
}
|
||||
|
||||
|
||||
if ( sdl_screen == NULL ) {
|
||||
fprintf(stderr, "ERROR! Couldn't set %dx%d video mode: %s\n",
|
||||
*xsize,*ysize,SDL_GetError());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (*bpp==0) *bpp=sdl_screen->format->BytesPerPixel*8;
|
||||
if (verbose) {
|
||||
printf(" + SDL Graphics Initialization successful...\n");
|
||||
printf(" + Using %dx%dx%dbpp Visual...\n",*xsize,*ysize,*bpp);
|
||||
#if BYTE_ORDER==LITTLE_ENDIAN
|
||||
printf(" + Little-endian byte-order detected\n");
|
||||
#else
|
||||
printf(" + Big-endian byte-order detected\n");
|
||||
#endif
|
||||
printf(" + Red: %x Green: %x Blue: %x Alpha: %x\n",
|
||||
sdl_screen->format->Rmask,
|
||||
sdl_screen->format->Gmask,
|
||||
sdl_screen->format->Bmask,
|
||||
sdl_screen->format->Amask);
|
||||
}
|
||||
return sdl_screen;
|
||||
}
|
||||
|
||||
|
||||
void SDL_flushPalette(vmwSVMWGraphState *state) {
|
||||
|
||||
SDL_Surface *target;
|
||||
SDL_Color temp_col[256];
|
||||
int i;
|
||||
|
||||
if (state->bpp==8) {
|
||||
for(i=0;i<256;i++) {
|
||||
temp_col[i].r=(state->palette[i]>>11)<<3;
|
||||
temp_col[i].g=((state->palette[i]>>5)&0x3f)<<2;
|
||||
temp_col[i].b=(state->palette[i]&0x1f)<<3;
|
||||
}
|
||||
|
||||
target=(SDL_Surface *)state->output_screen;
|
||||
|
||||
SDL_SetColors(target,temp_col,0,256);
|
||||
}
|
||||
}
|
||||
|
||||
void SDL_NoScale32bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
|
||||
|
||||
int x,y,color;
|
||||
|
||||
unsigned char *s_pointer,*t_pointer;
|
||||
|
||||
SDL_Surface *target;
|
||||
|
||||
target=(SDL_Surface *)target_p->output_screen;
|
||||
|
||||
if ( SDL_MUSTLOCK(target) ) {
|
||||
if ( SDL_LockSurface(target) < 0 )
|
||||
return;
|
||||
}
|
||||
|
||||
s_pointer=source->memory;
|
||||
t_pointer=((Uint8 *)target->pixels);
|
||||
|
||||
// printf("%i %i\n",source->xsize,source->ysize);
|
||||
|
||||
for (x=0;x<source->xsize;x++)
|
||||
for (y=0;y<source->ysize;y++) {
|
||||
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)].b);
|
||||
|
||||
*((Uint32 *)(t_pointer))=color;
|
||||
s_pointer++; t_pointer+=4;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Update the display */
|
||||
if ( SDL_MUSTLOCK(target) ) {
|
||||
SDL_UnlockSurface(target);
|
||||
}
|
||||
|
||||
/* Write this out to the screen */
|
||||
SDL_UpdateRect(target, 0, 0, source->xsize, source->ysize);
|
||||
}
|
||||
|
||||
|
||||
void SDL_Double32bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
|
||||
|
||||
int x,y,color;//,scale;
|
||||
|
||||
unsigned char *s_pointer,*t_pointer;
|
||||
|
||||
SDL_Surface *target;
|
||||
|
||||
target=(SDL_Surface *)target_p->output_screen;
|
||||
|
||||
// scale=target_p->scale;
|
||||
|
||||
if ( SDL_MUSTLOCK(target) ) {
|
||||
if ( SDL_LockSurface(target) < 0 )
|
||||
return;
|
||||
}
|
||||
|
||||
s_pointer=source->memory;
|
||||
t_pointer=((Uint8 *)target->pixels);
|
||||
|
||||
for(y=0;y<source->ysize;y++) {
|
||||
for(x=0;x<source->xsize;x++) {
|
||||
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)].b);
|
||||
|
||||
/* i=0, j=0 */
|
||||
*((Uint32 *) ( (t_pointer)))=color;
|
||||
|
||||
/* i=1, j=0 */
|
||||
*((Uint32 *) ( (t_pointer+(4*target_p->xsize) )))=color;
|
||||
|
||||
/* i=0, j=1 */
|
||||
*((Uint32 *) ( (t_pointer+4) ))=color;
|
||||
|
||||
/* i=1 j=1 */
|
||||
*((Uint32 *) ( (t_pointer+4+(4*target_p->xsize) )))=color;
|
||||
|
||||
s_pointer++; t_pointer+=8;
|
||||
}
|
||||
t_pointer+=4*target_p->xsize;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
|
||||
void SDL_NoScale16bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
|
||||
|
||||
int x,y;
|
||||
|
||||
unsigned char *s_pointer,*t_pointer;
|
||||
|
||||
SDL_Surface *target;
|
||||
|
||||
target=(SDL_Surface *)target_p->output_screen;
|
||||
|
||||
if ( SDL_MUSTLOCK(target) ) {
|
||||
if ( SDL_LockSurface(target) < 0 )
|
||||
return;
|
||||
}
|
||||
|
||||
s_pointer=source->memory;
|
||||
t_pointer=((Uint8 *)target->pixels);
|
||||
|
||||
// printf("%i %i\n",source->xsize,source->ysize);
|
||||
|
||||
for (x=0;x<source->xsize;x++)
|
||||
for (y=0;y<source->ysize;y++) {
|
||||
*((Uint16 *)(t_pointer))=target_p->palette[*(s_pointer)];
|
||||
s_pointer++; t_pointer+=2;
|
||||
}
|
||||
|
||||
/* Update the display */
|
||||
if ( SDL_MUSTLOCK(target) ) {
|
||||
SDL_UnlockSurface(target);
|
||||
}
|
||||
|
||||
/* Write this out to the screen */
|
||||
SDL_UpdateRect(target, 0, 0, source->xsize, source->ysize);
|
||||
|
||||
}
|
||||
|
||||
/* I should make this generic, but it makes it really slow */
|
||||
void SDL_Double16bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
|
||||
|
||||
int x,y;
|
||||
|
||||
unsigned char *s_pointer,*t_pointer;
|
||||
|
||||
SDL_Surface *target;
|
||||
|
||||
target=(SDL_Surface *)target_p->output_screen;
|
||||
|
||||
//scale=target_p->scale;
|
||||
|
||||
if ( SDL_MUSTLOCK(target) ) {
|
||||
if ( SDL_LockSurface(target) < 0 )
|
||||
return;
|
||||
}
|
||||
|
||||
s_pointer=source->memory;
|
||||
t_pointer=((Uint8 *)target->pixels);
|
||||
|
||||
for (y=0;y<source->ysize;y++) {
|
||||
for (x=0;x<source->xsize;x++) {
|
||||
|
||||
/* i=0, j=0 */
|
||||
*((Uint16 *) ( (t_pointer)))=
|
||||
target_p->palette[*(s_pointer)];
|
||||
|
||||
/* i=1, j=0 */
|
||||
*((Uint16 *) ( (t_pointer+(2*target_p->xsize) )))=
|
||||
target_p->palette[*(s_pointer)];
|
||||
/* i=0, j=1 */
|
||||
*((Uint16 *) ( (t_pointer+2) ))=
|
||||
target_p->palette[*(s_pointer)];
|
||||
|
||||
/* i=1 j=1 */
|
||||
*((Uint16 *) ( (t_pointer+2+(2*target_p->xsize) )))=
|
||||
target_p->palette[*(s_pointer)];
|
||||
|
||||
s_pointer++; t_pointer+=4;
|
||||
}
|
||||
t_pointer+=2*target_p->xsize;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
|
||||
}
|
||||
|
||||
void SDL_NoScale8bpp_BlitMem(vmwSVMWGraphState *target_p, vmwVisual *source) {
|
||||
|
||||
int x,y;
|
||||
|
||||
unsigned char *s_pointer,*t_pointer;
|
||||
|
||||
SDL_Surface *target;
|
||||
|
||||
target=(SDL_Surface *)target_p->output_screen;
|
||||
|
||||
if ( SDL_MUSTLOCK(target) ) {
|
||||
if ( SDL_LockSurface(target) < 0 )
|
||||
return;
|
||||
}
|
||||
|
||||
s_pointer=source->memory;
|
||||
t_pointer=((Uint8 *)target->pixels);
|
||||
|
||||
for (x=0;x<source->xsize;x++)
|
||||
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);
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
unsigned char *s_pointer,*t_pointer;
|
||||
|
||||
SDL_Surface *target;
|
||||
|
||||
target=(SDL_Surface *)target_p->output_screen;
|
||||
|
||||
if ( SDL_MUSTLOCK(target) ) {
|
||||
if ( SDL_LockSurface(target) < 0 )
|
||||
return;
|
||||
}
|
||||
|
||||
s_pointer=source->memory;
|
||||
t_pointer=((Uint8 *)target->pixels);
|
||||
|
||||
for (y=0;y<source->ysize;y++) {
|
||||
for (x=0;x<source->xsize;x++) {
|
||||
/* i=0, j=0 */
|
||||
*((Uint8 *)(t_pointer))=*(s_pointer);
|
||||
/* i=1, j=0 */
|
||||
*((Uint8 *)(t_pointer+(target_p->xsize)))=*(s_pointer);
|
||||
/* i=0, j=1 */
|
||||
*((Uint8 *)(t_pointer+1))=*(s_pointer);
|
||||
/* i=1, j=1 */
|
||||
*((Uint8 *)(t_pointer+1+target_p->xsize))=*(s_pointer);
|
||||
s_pointer++; t_pointer+=2;
|
||||
}
|
||||
t_pointer+=target_p->xsize;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
|
||||
void SDL_clearKeyboardBuffer(void) {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
}
|
||||
}
|
||||
|
||||
int SDL_getInput(void) {
|
||||
|
||||
SDL_Event event;
|
||||
int keypressed,button;
|
||||
int axis,direction;
|
||||
|
||||
static int going_right=0;
|
||||
static int going_left=0;
|
||||
|
||||
while ( SDL_PollEvent(&event)) {
|
||||
|
||||
switch(event.type) {
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
button=event.jbutton.button;
|
||||
// printf("BUTTON %i\n",button);
|
||||
switch(button) {
|
||||
case 0: return ' ';
|
||||
case 1: return VMW_ENTER;
|
||||
}
|
||||
break;
|
||||
case SDL_JOYAXISMOTION:
|
||||
axis=event.jaxis.axis;
|
||||
direction=event.jaxis.value;
|
||||
// printf("%i %i\n",axis,direction);
|
||||
if (axis==0) { /* X */
|
||||
|
||||
if (direction>5000) {
|
||||
if (!going_right) {
|
||||
going_right=1;
|
||||
return VMW_RIGHT;
|
||||
}
|
||||
}
|
||||
else if (direction<-5000) {
|
||||
if (!going_left) {
|
||||
going_left=1;
|
||||
return VMW_LEFT;
|
||||
}
|
||||
}
|
||||
else {
|
||||
going_left=0;
|
||||
going_right=0;
|
||||
}
|
||||
}
|
||||
// if (axis==1) { /* Y */
|
||||
// if (direction>0) return VMW_UP;
|
||||
// if (direction<0) return VMW_DOWN;
|
||||
// }
|
||||
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
keypressed=event.key.keysym.sym;
|
||||
switch (keypressed) {
|
||||
case SDLK_BACKSPACE: return VMW_BACKSPACE;
|
||||
case SDLK_ESCAPE : return VMW_ESCAPE;
|
||||
case SDLK_RETURN : return VMW_ENTER;
|
||||
case SDLK_UP : return VMW_UP;
|
||||
case SDLK_DOWN : return VMW_DOWN;
|
||||
case SDLK_RIGHT : return VMW_RIGHT;
|
||||
case SDLK_LEFT : return VMW_LEFT;
|
||||
case SDLK_F1 : return VMW_F1;
|
||||
case SDLK_F2 : return VMW_F2;
|
||||
case SDLK_PAGEUP : return VMW_PGUP;
|
||||
case SDLK_PAGEDOWN : return VMW_PGDN;
|
||||
case SDLK_HOME : return VMW_HOME;
|
||||
case SDLK_END : return VMW_END;
|
||||
case SDLK_INSERT : return VMW_INS;
|
||||
case SDLK_DELETE : return VMW_DEL;
|
||||
default: if ((keypressed>='a') && (keypressed<='z')
|
||||
&& (event.key.keysym.mod & KMOD_SHIFT) )
|
||||
return keypressed-32;
|
||||
else return keypressed;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SDL_closeGraphics() {
|
||||
}
|
||||
|
@ -1,334 +1,335 @@
|
||||
/* An implementation of my own legacy "PaintPro[gram] graphics format */
|
||||
|
||||
/* The format is seemingly very random, but it was sort of OK for */
|
||||
/* my skill level at the time */
|
||||
|
||||
/* 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]
|
||||
* Compression scheme [which I thought up on my own] */
|
||||
|
||||
/* Later versions supported 256 color mode, and made sure the BASIC
|
||||
* loader worked */
|
||||
|
||||
/* There was an actual "PaintPro program, written in TurboPascal
|
||||
* that was fairly decent considering. It would edit in
|
||||
* the EGA and VGA 16 color modes, and later mode13 320x200x256 */
|
||||
|
||||
/* The files were still pretty large, so Version 5 implemented
|
||||
* "Packing", basically shoving the color and numacross into
|
||||
* a 24 bit value. This, along with block-reading rapidly
|
||||
* reduced load times */
|
||||
|
||||
/* Version 6 added a fancy header, along with palette saving, and
|
||||
* an optimization of storing multiple 1-pixel runs in half the size.
|
||||
* Before this palette files were stored separately. */
|
||||
|
||||
/* The resulting file format is very similar [quite accidentally] to
|
||||
* the PCX file format. Why don't I make paintpro files obsolete?
|
||||
* nostalgia mostly. */
|
||||
|
||||
/* Paintpro files usually have the extension .AMG [AMazing Graphics,
|
||||
* an inside joke], .PPP [Paint Pro Packed], .PRO, or .TB1 [from
|
||||
* Tom Bombem */
|
||||
|
||||
|
||||
|
||||
|
||||
#include "svmwgraph.h"
|
||||
|
||||
#include <stdio.h> /* For FILE I/O */
|
||||
#include <string.h> /* For strncmp */
|
||||
#include <fcntl.h> /* for open() */
|
||||
#include <unistd.h> /* for lseek() */
|
||||
#include <sys/stat.h> /* for file modes */
|
||||
|
||||
|
||||
/* Take a 24bit value [3 bytes] and split the top and bottom */
|
||||
/* 12 bits into 2 integers */
|
||||
#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 */
|
||||
|
||||
#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) {
|
||||
|
||||
FILE *fff;
|
||||
static vmwPaintProHeader *header=NULL;
|
||||
unsigned char buffer[18];
|
||||
int i;
|
||||
|
||||
if ( (fff=fopen(filename,"rb"))==NULL) { /* b for w32 stupidity */
|
||||
printf("Error! %s does not exist!\n",filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fread(buffer,1,18,fff)!=18) {
|
||||
printf("Error! Corrupted paintpro header!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fclose(fff);
|
||||
|
||||
if (header==NULL) {
|
||||
if (( header=calloc(1,sizeof(vmwPaintProHeader)))==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];
|
||||
for(i=0;i<4;i++) header->version[i]=buffer[i+8];
|
||||
header->xsize=THREE_BYTES_INT1(buffer[12],buffer[13]);
|
||||
header->ysize=THREE_BYTES_INT2(buffer[13],buffer[14]);
|
||||
header->num_colors=THREE_BYTES_INT1(buffer[15],buffer[16]);
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------*\
|
||||
| vmwLoadPicPacked |
|
||||
| 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,
|
||||
vmwSVMWGraphState *graph_state)
|
||||
|
||||
/* Retro comments */
|
||||
/*{ Loads a paintpro image, filename, at location x1,y1 *\
|
||||
\* 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 color,numacross;
|
||||
int read_status;
|
||||
vmwPaintProHeader *ppro_header;
|
||||
unsigned char three_bytes[3];
|
||||
int broken=0;
|
||||
|
||||
if ( (ppro_header=vmwGetPaintProHeader(FileName))==NULL) {
|
||||
printf("ERROR! Invalid Header in %s!\n",FileName);
|
||||
return VMW_ERROR_FILE;
|
||||
}
|
||||
|
||||
/* Open the file */
|
||||
ppro_fd=open(FileName,O_RDONLY);
|
||||
|
||||
if (ppro_fd<0) {
|
||||
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)) {
|
||||
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)) {
|
||||
if (!strncmp(ppro_header->version,"V6.0",4)) {
|
||||
printf("Warning! Broken 6.0 file! Please convert.\n");
|
||||
broken=1;
|
||||
}
|
||||
else {
|
||||
printf("ERROR! %s unsupported, must be >=6.0\n",
|
||||
ppro_header->version);
|
||||
return VMW_ERROR_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
/*Load Palette*/
|
||||
if (ppro_header->num_colors>256)
|
||||
printf("More than 256 colors not supported yet (%d)\n",
|
||||
ppro_header->num_colors);
|
||||
|
||||
/* 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 */
|
||||
|
||||
if (!LoadPal) {
|
||||
/* 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++) {
|
||||
read_status=read(ppro_fd,&three_bytes,3);
|
||||
vmwLoadPalette(graph_state,
|
||||
three_bytes[0],
|
||||
three_bytes[1],
|
||||
three_bytes[2],i);
|
||||
}
|
||||
vmwFlushPalette(graph_state);
|
||||
}
|
||||
|
||||
if (!LoadPic) {
|
||||
close(ppro_fd);
|
||||
return 0; /* We already loaded the palette */
|
||||
}
|
||||
|
||||
x=x1;
|
||||
y=y1;
|
||||
|
||||
while (y<y1+ppro_header->ysize) {
|
||||
/* 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) {
|
||||
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]);
|
||||
|
||||
/* If int1 greater than 2047, we have two single pixels */
|
||||
/* of color int1-2048 and int2-2048 */
|
||||
if (color>2047) {
|
||||
vmwPutPixel(x,y,color-2048,target);
|
||||
x++;
|
||||
if (x>=ppro_header->xsize+x1) {
|
||||
x=x1; y++;
|
||||
}
|
||||
vmwPutPixel(x,y,numacross-2048,target);
|
||||
x++;
|
||||
if (x>=ppro_header->xsize+x1){
|
||||
x=x1;y++;
|
||||
}
|
||||
}
|
||||
else { /* Standard paintpro format */
|
||||
/* Wrap if numacross is bigger than width */
|
||||
while ((x+numacross)>=(ppro_header->xsize+x1)) {
|
||||
vmwDrawHLine(x,y,((ppro_header->xsize+x1)-x),color,target);
|
||||
/* Old versions of paintro created broken */
|
||||
/* Files which need an extra +1 after xsize */
|
||||
/* In the following line */
|
||||
numacross=numacross-((ppro_header->xsize+broken)-x);
|
||||
x=x1;
|
||||
y++;
|
||||
}
|
||||
|
||||
if (numacross!=0) {
|
||||
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);
|
||||
}
|
||||
vmwDrawHLine(x,y,numacross,color,target);
|
||||
}
|
||||
x=x+numacross;
|
||||
}
|
||||
}
|
||||
close(ppro_fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vmwSavePicPacked(int x1,int y1,int xsize,int ysize,
|
||||
vmwVisual *source,
|
||||
int num_colors,
|
||||
vmw24BitPal *palette,
|
||||
char *FileName) {
|
||||
|
||||
int ppro_fd,i,x,y,color=0,oldcolor=-1,numacross=0;
|
||||
int already_have_single_pixel=0;
|
||||
int save_pixel=0;
|
||||
char ppro_string[]="PAINTPRO";
|
||||
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) {
|
||||
printf("Error opening \"%s\" for writing!\n",FileName);
|
||||
return VMW_ERROR_FILE;
|
||||
}
|
||||
|
||||
/* 8 bytes, "PAINTPRO" */
|
||||
write(ppro_fd,ppro_string,8);
|
||||
/* 4 bytes, "V6.0" */
|
||||
write(ppro_fd,ppro_version,4);
|
||||
|
||||
/* xsize, ysize */
|
||||
TWO_INTS_THREE_BYTES(xsize,ysize);
|
||||
write(ppro_fd,three_bytes,3);
|
||||
/* num_colors, 0 */
|
||||
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++) {
|
||||
three_bytes[0]=palette[i].r;
|
||||
three_bytes[1]=palette[i].g;
|
||||
three_bytes[2]=palette[i].b;
|
||||
write(ppro_fd,three_bytes,3);
|
||||
}
|
||||
|
||||
y=y1;
|
||||
x=x1;
|
||||
|
||||
/* Set up initial conditions */
|
||||
oldcolor=vmwGetPixel(x,y,source);
|
||||
|
||||
while (y<y1+ysize) {
|
||||
color=vmwGetPixel(x,y,source);
|
||||
if ((color==oldcolor)&&(numacross<2046)) numacross++;
|
||||
else { /* This pixel not the same color as previous */
|
||||
if (numacross==1) {
|
||||
/* Special case for 1 pixel value */
|
||||
if (!already_have_single_pixel) {
|
||||
/* We are the first, so save it in hopes of a 2nd */
|
||||
save_pixel=oldcolor;
|
||||
already_have_single_pixel=1;
|
||||
}
|
||||
else {
|
||||
/* We got a second. Pack the two together */
|
||||
TWO_INTS_THREE_BYTES(save_pixel+2048,oldcolor+2048);
|
||||
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) {
|
||||
/* Oops.. wanted to pack, but we can't */
|
||||
TWO_INTS_THREE_BYTES(save_pixel,1);
|
||||
write(ppro_fd,three_bytes,3);
|
||||
already_have_single_pixel=0;
|
||||
}
|
||||
/* Write out color, and numacross */
|
||||
TWO_INTS_THREE_BYTES(oldcolor,numacross);
|
||||
write(ppro_fd,three_bytes,3);
|
||||
}
|
||||
oldcolor=color;
|
||||
numacross=1;
|
||||
}
|
||||
x++;
|
||||
if (x>=x1+xsize) {
|
||||
x=x1;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
/* Write out data left */
|
||||
if (already_have_single_pixel) {
|
||||
/* Oops.. wanted to pack, but we can't */
|
||||
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(ppro_fd,three_bytes,3);
|
||||
|
||||
close(ppro_fd);
|
||||
return 0;
|
||||
|
||||
}
|
||||
/* An implementation of my own legacy "PaintPro[gram] graphics format */
|
||||
|
||||
/* The format is seemingly very random, but it was sort of OK for */
|
||||
/* my skill level at the time */
|
||||
|
||||
/* 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]
|
||||
* Compression scheme [which I thought up on my own] */
|
||||
|
||||
/* Later versions supported 256 color mode, and made sure the BASIC
|
||||
* loader worked */
|
||||
|
||||
/* There was an actual "PaintPro program, written in TurboPascal
|
||||
* that was fairly decent considering. It would edit in
|
||||
* the EGA and VGA 16 color modes, and later mode13 320x200x256 */
|
||||
|
||||
/* The files were still pretty large, so Version 5 implemented
|
||||
* "Packing", basically shoving the color and numacross into
|
||||
* a 24 bit value. This, along with block-reading rapidly
|
||||
* reduced load times */
|
||||
|
||||
/* Version 6 added a fancy header, along with palette saving, and
|
||||
* an optimization of storing multiple 1-pixel runs in half the size.
|
||||
* Before this palette files were stored separately. */
|
||||
|
||||
/* The resulting file format is very similar [quite accidentally] to
|
||||
* the PCX file format. Why don't I make paintpro files obsolete?
|
||||
* nostalgia mostly. */
|
||||
|
||||
/* Paintpro files usually have the extension .AMG [AMazing Graphics,
|
||||
* an inside joke], .PPP [Paint Pro Packed], .PRO, or .TB1 [from
|
||||
* Tom Bombem */
|
||||
|
||||
|
||||
|
||||
|
||||
#include "svmwgraph.h"
|
||||
|
||||
#include <stdio.h> /* For FILE I/O */
|
||||
#include <string.h> /* For strncmp */
|
||||
#include <fcntl.h> /* for open() */
|
||||
#include <unistd.h> /* for lseek() */
|
||||
#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 */
|
||||
#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 */
|
||||
|
||||
#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) {
|
||||
|
||||
FILE *fff;
|
||||
static vmwPaintProHeader *header=NULL;
|
||||
unsigned char buffer[18];
|
||||
int i;
|
||||
|
||||
if ( (fff=fopen(filename,"rb"))==NULL) { /* b for w32 stupidity */
|
||||
printf("Error! %s does not exist!\n",filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fread(buffer,1,18,fff)!=18) {
|
||||
printf("Error! Corrupted paintpro header!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fclose(fff);
|
||||
|
||||
if (header==NULL) {
|
||||
if (( header=calloc(1,sizeof(vmwPaintProHeader)))==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];
|
||||
for(i=0;i<4;i++) header->version[i]=buffer[i+8];
|
||||
header->xsize=THREE_BYTES_INT1(buffer[12],buffer[13]);
|
||||
header->ysize=THREE_BYTES_INT2(buffer[13],buffer[14]);
|
||||
header->num_colors=THREE_BYTES_INT1(buffer[15],buffer[16]);
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------*\
|
||||
| vmwLoadPicPacked |
|
||||
| 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,
|
||||
vmwSVMWGraphState *graph_state)
|
||||
|
||||
/* Retro comments */
|
||||
/*{ Loads a paintpro image, filename, at location x1,y1 *\
|
||||
\* 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 color,numacross;
|
||||
int read_status;
|
||||
vmwPaintProHeader *ppro_header;
|
||||
unsigned char three_bytes[3];
|
||||
int broken=0;
|
||||
|
||||
if ( (ppro_header=vmwGetPaintProHeader(FileName))==NULL) {
|
||||
printf("ERROR! Invalid Header in %s!\n",FileName);
|
||||
return VMW_ERROR_FILE;
|
||||
}
|
||||
|
||||
/* Open the file */
|
||||
ppro_fd=open(FileName,O_RDONLY);
|
||||
|
||||
if (ppro_fd<0) {
|
||||
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)) {
|
||||
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)) {
|
||||
if (!strncmp(ppro_header->version,"V6.0",4)) {
|
||||
printf("Warning! Broken 6.0 file! Please convert.\n");
|
||||
broken=1;
|
||||
}
|
||||
else {
|
||||
printf("ERROR! %s unsupported, must be >=6.0\n",
|
||||
ppro_header->version);
|
||||
return VMW_ERROR_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
/*Load Palette*/
|
||||
if (ppro_header->num_colors>256)
|
||||
printf("More than 256 colors not supported yet (%d)\n",
|
||||
ppro_header->num_colors);
|
||||
|
||||
/* 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 */
|
||||
|
||||
if (!LoadPal) {
|
||||
/* 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++) {
|
||||
read_status=read(ppro_fd,&three_bytes,3);
|
||||
vmwLoadPalette(graph_state,
|
||||
three_bytes[0],
|
||||
three_bytes[1],
|
||||
three_bytes[2],i);
|
||||
}
|
||||
vmwFlushPalette(graph_state);
|
||||
}
|
||||
|
||||
if (!LoadPic) {
|
||||
close(ppro_fd);
|
||||
return 0; /* We already loaded the palette */
|
||||
}
|
||||
|
||||
x=x1;
|
||||
y=y1;
|
||||
|
||||
while (y<y1+ppro_header->ysize) {
|
||||
/* 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) {
|
||||
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]);
|
||||
|
||||
/* If int1 greater than 2047, we have two single pixels */
|
||||
/* of color int1-2048 and int2-2048 */
|
||||
if (color>2047) {
|
||||
vmwPutPixel(x,y,color-2048,target);
|
||||
x++;
|
||||
if (x>=ppro_header->xsize+x1) {
|
||||
x=x1; y++;
|
||||
}
|
||||
vmwPutPixel(x,y,numacross-2048,target);
|
||||
x++;
|
||||
if (x>=ppro_header->xsize+x1){
|
||||
x=x1;y++;
|
||||
}
|
||||
}
|
||||
else { /* Standard paintpro format */
|
||||
/* Wrap if numacross is bigger than width */
|
||||
while ((x+numacross)>=(ppro_header->xsize+x1)) {
|
||||
vmwDrawHLine(x,y,((ppro_header->xsize+x1)-x),color,target);
|
||||
/* Old versions of paintro created broken */
|
||||
/* Files which need an extra +1 after xsize */
|
||||
/* In the following line */
|
||||
numacross=numacross-((ppro_header->xsize+broken)-x);
|
||||
x=x1;
|
||||
y++;
|
||||
}
|
||||
|
||||
if (numacross!=0) {
|
||||
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);
|
||||
}
|
||||
vmwDrawHLine(x,y,numacross,color,target);
|
||||
}
|
||||
x=x+numacross;
|
||||
}
|
||||
}
|
||||
close(ppro_fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vmwSavePicPacked(int x1,int y1,int xsize,int ysize,
|
||||
vmwVisual *source,
|
||||
int num_colors,
|
||||
vmw24BitPal *palette,
|
||||
char *FileName) {
|
||||
|
||||
int ppro_fd,i,x,y,color=0,oldcolor=-1,numacross=0;
|
||||
int already_have_single_pixel=0;
|
||||
int save_pixel=0;
|
||||
char ppro_string[]="PAINTPRO";
|
||||
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) {
|
||||
printf("Error opening \"%s\" for writing!\n",FileName);
|
||||
return VMW_ERROR_FILE;
|
||||
}
|
||||
|
||||
/* 8 bytes, "PAINTPRO" */
|
||||
write(ppro_fd,ppro_string,8);
|
||||
/* 4 bytes, "V6.0" */
|
||||
write(ppro_fd,ppro_version,4);
|
||||
|
||||
/* xsize, ysize */
|
||||
TWO_INTS_THREE_BYTES(xsize,ysize);
|
||||
write(ppro_fd,three_bytes,3);
|
||||
/* num_colors, 0 */
|
||||
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++) {
|
||||
three_bytes[0]=palette[i].r;
|
||||
three_bytes[1]=palette[i].g;
|
||||
three_bytes[2]=palette[i].b;
|
||||
write(ppro_fd,three_bytes,3);
|
||||
}
|
||||
|
||||
y=y1;
|
||||
x=x1;
|
||||
|
||||
/* Set up initial conditions */
|
||||
oldcolor=vmwGetPixel(x,y,source);
|
||||
|
||||
while (y<y1+ysize) {
|
||||
color=vmwGetPixel(x,y,source);
|
||||
if ((color==oldcolor)&&(numacross<2046)) numacross++;
|
||||
else { /* This pixel not the same color as previous */
|
||||
if (numacross==1) {
|
||||
/* Special case for 1 pixel value */
|
||||
if (!already_have_single_pixel) {
|
||||
/* We are the first, so save it in hopes of a 2nd */
|
||||
save_pixel=oldcolor;
|
||||
already_have_single_pixel=1;
|
||||
}
|
||||
else {
|
||||
/* We got a second. Pack the two together */
|
||||
TWO_INTS_THREE_BYTES(save_pixel+2048,oldcolor+2048);
|
||||
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) {
|
||||
/* Oops.. wanted to pack, but we can't */
|
||||
TWO_INTS_THREE_BYTES(save_pixel,1);
|
||||
write(ppro_fd,three_bytes,3);
|
||||
already_have_single_pixel=0;
|
||||
}
|
||||
/* Write out color, and numacross */
|
||||
TWO_INTS_THREE_BYTES(oldcolor,numacross);
|
||||
write(ppro_fd,three_bytes,3);
|
||||
}
|
||||
oldcolor=color;
|
||||
numacross=1;
|
||||
}
|
||||
x++;
|
||||
if (x>=x1+xsize) {
|
||||
x=x1;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
/* Write out data left */
|
||||
if (already_have_single_pixel) {
|
||||
/* Oops.. wanted to pack, but we can't */
|
||||
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(ppro_fd,three_bytes,3);
|
||||
|
||||
close(ppro_fd);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
@ -1,306 +1,303 @@
|
||||
/* WARNING! These functions only work at 320x200x8bpp right now */
|
||||
|
||||
/* 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 */
|
||||
/* To do it right now ;) */
|
||||
|
||||
/* Routines to Load/Save PCX graphics files. */
|
||||
|
||||
#include "svmwgraph.h"
|
||||
|
||||
#include <stdio.h> /* For FILE I/O */
|
||||
#include <string.h> /* For strncmp */
|
||||
#include <fcntl.h> /* for open() */
|
||||
#include <unistd.h> /* for lseek() */
|
||||
#include <sys/stat.h> /* for file modes */
|
||||
|
||||
|
||||
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;
|
||||
|
||||
/* Open the file */
|
||||
pcx_fd=open(FileName,O_RDONLY);
|
||||
|
||||
if (pcx_fd<0) {
|
||||
printf("ERROR! File \"%s\" not found!\n",FileName);
|
||||
return VMW_ERROR_FILE;
|
||||
}
|
||||
|
||||
lseek(pcx_fd,0,SEEK_SET);
|
||||
|
||||
read(pcx_fd,&pcx_header,128);
|
||||
|
||||
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];
|
||||
|
||||
version=pcx_header[1];
|
||||
bpp=pcx_header[3];
|
||||
|
||||
if (debug) {
|
||||
|
||||
printf("Manufacturer: ");
|
||||
if (pcx_header[0]==10) printf("Zsoft\n");
|
||||
else printf("Unknown %i\n",pcx_header[0]);
|
||||
|
||||
printf("Version: ");
|
||||
|
||||
switch(version) {
|
||||
case 0: printf("2.5\n"); break;
|
||||
case 2: printf("2.8 w palette\n"); break;
|
||||
case 3: printf("2.8 w/o palette\n"); break;
|
||||
case 4: printf("Paintbrush for Windows\n"); break;
|
||||
case 5: printf("3.0+\n"); break;
|
||||
default: printf("Unknown %i\n",version);
|
||||
}
|
||||
printf("Encoding: ");
|
||||
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("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("Palette Type: %i\n",(pcx_header[69]<<8)+pcx_header[68]);
|
||||
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);
|
||||
*ysize=(ymax-ymin+1);
|
||||
|
||||
if ((version==5) && (bpp==8) && (pcx_header[65]==3)) *type=PCX_24BIT;
|
||||
else if (version==5) *type=PCX_8BITPAL;
|
||||
else *type=PCX_UNKNOWN;
|
||||
|
||||
close(pcx_fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vmwLoadPCX(int x1,int y1,vmwVisual *target,
|
||||
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 bpp,planes,bpl,xmax,ymax,version;
|
||||
unsigned char pcx_header[128];
|
||||
unsigned char temp_byte;
|
||||
|
||||
/* Open the file */
|
||||
pcx_fd=open(FileName,O_RDONLY);
|
||||
|
||||
if (pcx_fd<0) {
|
||||
printf("ERROR! File \"%s\" not found!\n",FileName);
|
||||
return VMW_ERROR_FILE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*************** DECODE THE HEADER *************************/
|
||||
read(pcx_fd,&pcx_header,128);
|
||||
|
||||
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];
|
||||
|
||||
version=pcx_header[1];
|
||||
bpp=pcx_header[3];
|
||||
planes=pcx_header[65];
|
||||
bpl=(pcx_header[67]<<8)+pcx_header[66];
|
||||
|
||||
xsize=((xmax-xmin)+1);
|
||||
ysize=((ymax-ymin)+1);
|
||||
|
||||
/* Possibly add some sanity checking in the header at some point... */
|
||||
/* Or actually even get the proper VALUES from the header. Some day... */
|
||||
|
||||
if (LoadPic) {
|
||||
|
||||
|
||||
unsigned char *pointer=target->memory;
|
||||
|
||||
x=0; y=0;
|
||||
|
||||
while (x<xsize*ysize) {
|
||||
read(pcx_fd,&temp_byte,1);
|
||||
if (0xc0 == (temp_byte&0xc0)) {
|
||||
numacross=temp_byte&0x3f;
|
||||
read(pcx_fd,&temp_byte,1);
|
||||
// y++; if (y%2) temp_byte=0xff;
|
||||
// temp_byte=0xff;
|
||||
// printf("%i pixels of %i\n",numacross,temp_byte);
|
||||
for(i=0;i<numacross;i++) {
|
||||
*pointer=temp_byte;
|
||||
pointer++;
|
||||
x++;
|
||||
}
|
||||
|
||||
|
||||
//printf("Color=%i Across=%i\n",temp_byte,numacross);
|
||||
//vmwDrawHLine(x,y,numacross,temp_byte,target);
|
||||
//x+=numacross;
|
||||
}
|
||||
else {
|
||||
//vmwPutPixel(x,y,temp_byte,target);
|
||||
//printf("%i, %i Color=%i\n",x,y,temp_byte);
|
||||
|
||||
*pointer=temp_byte;
|
||||
// if (temp_byte!=0) printf("COLOR=%i\n",temp_byte);
|
||||
pointer++;
|
||||
x++;
|
||||
}
|
||||
/* why is this needed? */
|
||||
// if (x%xsize==0) {
|
||||
// pointer++;
|
||||
// }
|
||||
|
||||
//printf("WARNING! X=%i\n",x);
|
||||
// x=0;
|
||||
// y++;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
/*Load Palette*/
|
||||
if (LoadPal) {
|
||||
|
||||
lseek(pcx_fd,-769,SEEK_END);
|
||||
|
||||
read(pcx_fd,&temp_byte,1);
|
||||
if (temp_byte!=12) {
|
||||
printf("Error! No palette found!\n");
|
||||
}
|
||||
else
|
||||
|
||||
for(i=0;i<255;i++) {
|
||||
read(pcx_fd,&temp_byte,1);
|
||||
r=temp_byte;
|
||||
read(pcx_fd,&temp_byte,1);
|
||||
g=temp_byte;
|
||||
read(pcx_fd,&temp_byte,1);
|
||||
b=temp_byte;
|
||||
vmwLoadPalette(graph_state,
|
||||
r,
|
||||
g,
|
||||
b,i);
|
||||
// printf("%i: 0x%x %x %x\n",i,r,g,b);
|
||||
}
|
||||
vmwFlushPalette(graph_state);
|
||||
}
|
||||
|
||||
close(pcx_fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vmwSavePCX(int x1,int y1,int xsize,int ysize,
|
||||
vmwVisual *source,
|
||||
int num_colors,
|
||||
vmw24BitPal *palette,
|
||||
char *FileName) {
|
||||
|
||||
|
||||
int pcx_fd,x,y,oldcolor,color,numacross,i;
|
||||
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);
|
||||
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' */
|
||||
/* Values verified from PCGPE .pcx documentation */
|
||||
pcx_header[0]=0x0a; /* Manufacturer ID-- A=ZSoft .pcx */
|
||||
pcx_header[1]=0x05; /* Version # */
|
||||
pcx_header[2]=0x01; /* Encoding. 1=RLE */
|
||||
pcx_header[3]=0x08; /* Bits Per Pixel */
|
||||
pcx_header[8]=0x3f; /* 4-11 Window. XminXmin YminYmin XmaxXmax YmaxYmax*/
|
||||
pcx_header[9]=0x01; /* Little Endian, so 0000 0000 013f 00c7= 319x199 */
|
||||
pcx_header[10]=0xc7; /* " */
|
||||
pcx_header[12]=0x2c; /* Horizontal DPI */
|
||||
pcx_header[13]=0x01; /* " .. so 0x12c=300dpi */
|
||||
pcx_header[14]=0x2c; /* Vertical DPI */
|
||||
pcx_header[15]=0x01; /* " .. so 0x12c=300dpi */
|
||||
pcx_header[65]=0x01; /* Number of color planes */
|
||||
pcx_header[66]=0x40; /* bytes per line. */
|
||||
pcx_header[67]=0x01; /* "" .. so 0x140=320 */
|
||||
pcx_header[68]=0x01; /* Color Palette */
|
||||
|
||||
/* 128 byte PCX Header */
|
||||
write(pcx_fd,pcx_header,128);
|
||||
|
||||
/* All we support right now */
|
||||
xsize=320;
|
||||
ysize=200;
|
||||
|
||||
y=y1;
|
||||
x=x1;
|
||||
numacross=1;
|
||||
|
||||
/* Set up initial conditions */
|
||||
oldcolor=vmwGetPixel(x,y,source);
|
||||
|
||||
while (y<y1+ysize) {
|
||||
color=vmwGetPixel(x,y,source);
|
||||
if ( (color==oldcolor)&&(numacross<63)&&(x<(x1+xsize-1)) ) numacross++;
|
||||
else { /* This pixel not the same color as previous */
|
||||
// printf("G: %i,%i N=%i C=%i\n",x,y,numacross,color);
|
||||
if ((numacross==1) && (oldcolor<192)) {
|
||||
write(pcx_fd,&oldcolor,1);
|
||||
}
|
||||
else {
|
||||
temp_byte=numacross+192;
|
||||
write(pcx_fd,&temp_byte,1);
|
||||
write(pcx_fd,&oldcolor,1);
|
||||
numacross=1;
|
||||
}
|
||||
}
|
||||
oldcolor=color;
|
||||
x++;
|
||||
if (x>=x1+xsize) {
|
||||
x=0;
|
||||
y++;
|
||||
numacross=1;
|
||||
// printf("%i %i %i\n",x,y,numacross);
|
||||
// fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
/* Urgh obscure */
|
||||
temp_byte=12;
|
||||
write(pcx_fd,&temp_byte,1);
|
||||
|
||||
/* Write num_colors r,g,b */
|
||||
for(i=0;i<256;i++) {
|
||||
temp_byte=palette[i].r;
|
||||
write(pcx_fd,&temp_byte,1);
|
||||
temp_byte=palette[i].g;
|
||||
write(pcx_fd,&temp_byte,1);
|
||||
temp_byte=palette[i].b;
|
||||
write(pcx_fd,&temp_byte,1);
|
||||
}
|
||||
|
||||
close(pcx_fd);
|
||||
return 0;
|
||||
}
|
||||
/* WARNING! These functions only work at 320x200x8bpp right now */
|
||||
|
||||
/* 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 */
|
||||
/* To do it right now ;) */
|
||||
|
||||
/* Routines to Load/Save PCX graphics files. */
|
||||
|
||||
#include "svmwgraph.h"
|
||||
|
||||
#include <stdio.h> /* For FILE I/O */
|
||||
#include <string.h> /* For strncmp */
|
||||
#include <fcntl.h> /* for open() */
|
||||
#include <unistd.h> /* for lseek() */
|
||||
#include <stdlib.h> /* for calloc() */
|
||||
#include <sys/stat.h> /* for file modes */
|
||||
|
||||
|
||||
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;
|
||||
|
||||
/* Open the file */
|
||||
pcx_fd=open(FileName,O_RDONLY);
|
||||
|
||||
if (pcx_fd<0) {
|
||||
printf("ERROR! File \"%s\" not found!\n",FileName);
|
||||
return VMW_ERROR_FILE;
|
||||
}
|
||||
|
||||
lseek(pcx_fd,0,SEEK_SET);
|
||||
|
||||
read(pcx_fd,&pcx_header,128);
|
||||
|
||||
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];
|
||||
|
||||
version=pcx_header[1];
|
||||
bpp=pcx_header[3];
|
||||
|
||||
if (debug) {
|
||||
|
||||
printf("Manufacturer: ");
|
||||
if (pcx_header[0]==10) printf("Zsoft\n");
|
||||
else printf("Unknown %i\n",pcx_header[0]);
|
||||
|
||||
printf("Version: ");
|
||||
|
||||
switch(version) {
|
||||
case 0: printf("2.5\n"); break;
|
||||
case 2: printf("2.8 w palette\n"); break;
|
||||
case 3: printf("2.8 w/o palette\n"); break;
|
||||
case 4: printf("Paintbrush for Windows\n"); break;
|
||||
case 5: printf("3.0+\n"); break;
|
||||
default: printf("Unknown %i\n",version);
|
||||
}
|
||||
printf("Encoding: ");
|
||||
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("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("Palette Type: %i\n",(pcx_header[69]<<8)+pcx_header[68]);
|
||||
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);
|
||||
*ysize=(ymax-ymin+1);
|
||||
|
||||
if ((version==5) && (bpp==8) && (pcx_header[65]==3)) *type=PCX_24BIT;
|
||||
else if (version==5) *type=PCX_8BITPAL;
|
||||
else *type=PCX_UNKNOWN;
|
||||
|
||||
close(pcx_fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vmwLoadPCX(int x1,int y1,vmwVisual *target,
|
||||
int LoadPal,int LoadPic,char *FileName,
|
||||
vmwSVMWGraphState *graph_state)
|
||||
|
||||
{
|
||||
|
||||
int pcx_fd,x,i,numacross,xsize,ysize,xmin,ymin;//y;
|
||||
unsigned int r,g,b;
|
||||
int xmax,ymax;//bpl,bpp,planes,version;
|
||||
unsigned char pcx_header[128];
|
||||
unsigned char temp_byte;
|
||||
|
||||
/* Open the file */
|
||||
pcx_fd=open(FileName,O_RDONLY);
|
||||
|
||||
if (pcx_fd<0) {
|
||||
printf("ERROR! File \"%s\" not found!\n",FileName);
|
||||
return VMW_ERROR_FILE;
|
||||
}
|
||||
|
||||
|
||||
/*************** DECODE THE HEADER *************************/
|
||||
read(pcx_fd,&pcx_header,128);
|
||||
|
||||
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];
|
||||
|
||||
//version=pcx_header[1];
|
||||
//bpp=pcx_header[3];
|
||||
//planes=pcx_header[65];
|
||||
//bpl=(pcx_header[67]<<8)+pcx_header[66];
|
||||
|
||||
xsize=((xmax-xmin)+1);
|
||||
ysize=((ymax-ymin)+1);
|
||||
|
||||
/* Possibly add some sanity checking in the header at some point... */
|
||||
/* Or actually even get the proper VALUES from the header. Some day... */
|
||||
|
||||
if (LoadPic) {
|
||||
|
||||
|
||||
unsigned char *pointer=target->memory;
|
||||
|
||||
x=0; //y=0;
|
||||
|
||||
while (x<xsize*ysize) {
|
||||
read(pcx_fd,&temp_byte,1);
|
||||
if (0xc0 == (temp_byte&0xc0)) {
|
||||
numacross=temp_byte&0x3f;
|
||||
read(pcx_fd,&temp_byte,1);
|
||||
// y++; if (y%2) temp_byte=0xff;
|
||||
// temp_byte=0xff;
|
||||
// printf("%i pixels of %i\n",numacross,temp_byte);
|
||||
for(i=0;i<numacross;i++) {
|
||||
*pointer=temp_byte;
|
||||
pointer++;
|
||||
x++;
|
||||
}
|
||||
|
||||
//printf("Color=%i Across=%i\n",temp_byte,numacross);
|
||||
//vmwDrawHLine(x,y,numacross,temp_byte,target);
|
||||
//x+=numacross;
|
||||
}
|
||||
else {
|
||||
//vmwPutPixel(x,y,temp_byte,target);
|
||||
//printf("%i, %i Color=%i\n",x,y,temp_byte);
|
||||
|
||||
*pointer=temp_byte;
|
||||
// if (temp_byte!=0) printf("COLOR=%i\n",temp_byte);
|
||||
pointer++;
|
||||
x++;
|
||||
}
|
||||
/* why is this needed? */
|
||||
// if (x%xsize==0) {
|
||||
// pointer++;
|
||||
// }
|
||||
|
||||
//printf("WARNING! X=%i\n",x);
|
||||
// x=0;
|
||||
// y++;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
/*Load Palette*/
|
||||
if (LoadPal) {
|
||||
|
||||
lseek(pcx_fd,-769,SEEK_END);
|
||||
|
||||
read(pcx_fd,&temp_byte,1);
|
||||
if (temp_byte!=12) {
|
||||
printf("Error! No palette found!\n");
|
||||
}
|
||||
else
|
||||
|
||||
for(i=0;i<255;i++) {
|
||||
read(pcx_fd,&temp_byte,1);
|
||||
r=temp_byte;
|
||||
read(pcx_fd,&temp_byte,1);
|
||||
g=temp_byte;
|
||||
read(pcx_fd,&temp_byte,1);
|
||||
b=temp_byte;
|
||||
vmwLoadPalette(graph_state,
|
||||
r,
|
||||
g,
|
||||
b,i);
|
||||
// printf("%i: 0x%x %x %x\n",i,r,g,b);
|
||||
}
|
||||
vmwFlushPalette(graph_state);
|
||||
}
|
||||
|
||||
close(pcx_fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vmwSavePCX(int x1,int y1,int xsize,int ysize,
|
||||
vmwVisual *source,
|
||||
int num_colors,
|
||||
vmw24BitPal *palette,
|
||||
char *FileName) {
|
||||
|
||||
int pcx_fd,x,y,oldcolor,color,numacross,i;
|
||||
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);
|
||||
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' */
|
||||
/* Values verified from PCGPE .pcx documentation */
|
||||
pcx_header[0]=0x0a; /* Manufacturer ID-- A=ZSoft .pcx */
|
||||
pcx_header[1]=0x05; /* Version # */
|
||||
pcx_header[2]=0x01; /* Encoding. 1=RLE */
|
||||
pcx_header[3]=0x08; /* Bits Per Pixel */
|
||||
pcx_header[8]=0x3f; /* 4-11 Window. XminXmin YminYmin XmaxXmax YmaxYmax*/
|
||||
pcx_header[9]=0x01; /* Little Endian, so 0000 0000 013f 00c7= 319x199 */
|
||||
pcx_header[10]=0xc7; /* " */
|
||||
pcx_header[12]=0x2c; /* Horizontal DPI */
|
||||
pcx_header[13]=0x01; /* " .. so 0x12c=300dpi */
|
||||
pcx_header[14]=0x2c; /* Vertical DPI */
|
||||
pcx_header[15]=0x01; /* " .. so 0x12c=300dpi */
|
||||
pcx_header[65]=0x01; /* Number of color planes */
|
||||
pcx_header[66]=0x40; /* bytes per line. */
|
||||
pcx_header[67]=0x01; /* "" .. so 0x140=320 */
|
||||
pcx_header[68]=0x01; /* Color Palette */
|
||||
|
||||
/* 128 byte PCX Header */
|
||||
write(pcx_fd,pcx_header,128);
|
||||
|
||||
/* All we support right now */
|
||||
xsize=320;
|
||||
ysize=200;
|
||||
|
||||
y=y1;
|
||||
x=x1;
|
||||
numacross=1;
|
||||
|
||||
/* Set up initial conditions */
|
||||
oldcolor=vmwGetPixel(x,y,source);
|
||||
|
||||
while (y<y1+ysize) {
|
||||
color=vmwGetPixel(x,y,source);
|
||||
if ( (color==oldcolor)&&(numacross<63)&&(x<(x1+xsize-1)) ) numacross++;
|
||||
else { /* This pixel not the same color as previous */
|
||||
// printf("G: %i,%i N=%i C=%i\n",x,y,numacross,color);
|
||||
if ((numacross==1) && (oldcolor<192)) {
|
||||
write(pcx_fd,&oldcolor,1);
|
||||
}
|
||||
else {
|
||||
temp_byte=numacross+192;
|
||||
write(pcx_fd,&temp_byte,1);
|
||||
write(pcx_fd,&oldcolor,1);
|
||||
numacross=1;
|
||||
}
|
||||
}
|
||||
oldcolor=color;
|
||||
x++;
|
||||
if (x>=x1+xsize) {
|
||||
x=0;
|
||||
y++;
|
||||
numacross=1;
|
||||
// printf("%i %i %i\n",x,y,numacross);
|
||||
// fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
/* Urgh obscure */
|
||||
temp_byte=12;
|
||||
write(pcx_fd,&temp_byte,1);
|
||||
|
||||
/* Write num_colors r,g,b */
|
||||
for(i=0;i<256;i++) {
|
||||
temp_byte=palette[i].r;
|
||||
write(pcx_fd,&temp_byte,1);
|
||||
temp_byte=palette[i].g;
|
||||
write(pcx_fd,&temp_byte,1);
|
||||
temp_byte=palette[i].b;
|
||||
write(pcx_fd,&temp_byte,1);
|
||||
}
|
||||
|
||||
close(pcx_fd);
|
||||
return 0;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include <stdio.h> /* For printf */
|
||||
#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);
|
||||
void (*vmwBlitMemToDisplay)(vmwSVMWGraphState *display, vmwVisual *source);
|
||||
void (*vmwFlushPalette)(vmwSVMWGraphState *state);
|
||||
@ -21,29 +21,29 @@ void (*vmwCloseGraphics)(void);
|
||||
vmwSVMWGraphState *vmwSetupSVMWGraph(int display_type,int xsize,int ysize,
|
||||
int bpp,int scale,int fullscreen,
|
||||
int verbose) {
|
||||
|
||||
|
||||
vmwSVMWGraphState *temp_state;
|
||||
|
||||
|
||||
if ( (temp_state=calloc(1,sizeof(vmwSVMWGraphState)) )==NULL) {
|
||||
printf("Error allocating memory!\n");
|
||||
return NULL;
|
||||
}
|
||||
/* Setup Setup routines */
|
||||
switch (display_type) {
|
||||
case VMW_NULLTARGET:
|
||||
case VMW_NULLTARGET:
|
||||
vmwSetupGraphics=null_setupGraphics;
|
||||
break;
|
||||
case VMW_CURSESTARGET:
|
||||
case VMW_CURSESTARGET:
|
||||
#ifdef CURSES_TARGET
|
||||
vmwSetupGraphics=curses_setupGraphics;
|
||||
#endif
|
||||
break;
|
||||
case VMW_OPENGLTARGET:
|
||||
case VMW_OPENGLTARGET:
|
||||
#ifdef OPENGL_TARGET
|
||||
vmwSetupGraphics=openGL_setupGraphics;
|
||||
#endif
|
||||
break;
|
||||
case VMW_SDLTARGET:
|
||||
case VMW_SDLTARGET:
|
||||
#ifdef SDL_TARGET
|
||||
vmwSetupGraphics=SDL_setupGraphics;
|
||||
#endif
|
||||
@ -51,14 +51,14 @@ vmwSVMWGraphState *vmwSetupSVMWGraph(int display_type,int xsize,int ysize,
|
||||
default: printf("ERROR! Unknown Display Target %i.\n",display_type);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
temp_state->bpp=bpp;
|
||||
temp_state->xsize=xsize;
|
||||
temp_state->ysize=ysize;
|
||||
temp_state->scale=scale;
|
||||
temp_state->default_font=NULL;
|
||||
temp_state->palette_size=256;
|
||||
|
||||
|
||||
if ( (temp_state->palette=calloc(temp_state->palette_size,sizeof(int)) )==NULL) {
|
||||
printf("Error allocating palette of size %i!\n",temp_state->palette_size);
|
||||
return NULL;
|
||||
@ -69,6 +69,10 @@ vmwSVMWGraphState *vmwSetupSVMWGraph(int display_type,int xsize,int ysize,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (vmwSetupGraphics==NULL) {
|
||||
fprintf(stderr,"Unsupported graphics target!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Attempt to get desired graphics state */
|
||||
temp_state->output_screen=vmwSetupGraphics(&temp_state->xsize,
|
||||
@ -76,7 +80,7 @@ vmwSVMWGraphState *vmwSetupSVMWGraph(int display_type,int xsize,int ysize,
|
||||
&temp_state->bpp,
|
||||
fullscreen,verbose);
|
||||
if (temp_state->output_screen==NULL) return NULL;
|
||||
/* Setup proper blitter and others*/
|
||||
/* Setup proper blitter and others*/
|
||||
switch (display_type) {
|
||||
case VMW_NULLTARGET:
|
||||
vmwFlushPalette=null_flushPalette;
|
||||
|
951
tb1_linux/tb1.c
951
tb1_linux/tb1.c
@ -1,474 +1,477 @@
|
||||
/****************************************************************\
|
||||
\* TOM BOMBEM AND THE INVASION OF THE INANIMATE_OBJECTS */
|
||||
/* version 2.9.16 26 December 2009 *\
|
||||
\* by Vince Weaver vince@deater.net */
|
||||
/* *\
|
||||
\* Originally written in Pascal and x86 assembly for DOS */
|
||||
/* using the PCGPE code as an example in 1994 *\
|
||||
\* Ported to Linux, C, and ggi late 1997-early 1998 */
|
||||
/* Port continued to SDL in June of 2000 *\
|
||||
\* This source is released under the GPL */
|
||||
/****************************************************************/
|
||||
|
||||
#define TB1_VERSION "2.9.16"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> /* for calloc */
|
||||
#include <string.h> /* for strncpy */
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "svmwgraph/svmwgraph.h"
|
||||
#include "tb1_state.h"
|
||||
#include "tblib.h"
|
||||
#include "sound.h"
|
||||
|
||||
#include "graphic_tools.h"
|
||||
#include "help.h"
|
||||
#include "quit.h"
|
||||
#include "story.h"
|
||||
#include "credits.h"
|
||||
#include "about.h"
|
||||
#include "loadsave.h"
|
||||
#include "options.h"
|
||||
#include "playgame.h"
|
||||
|
||||
int command_line_help(int show_version,char *runas) {
|
||||
|
||||
if (!show_version) {
|
||||
printf("Usage: %s [-curses] [-double] [-fullscreen] [-nosound]"
|
||||
" [-version] [-?]\n\n",runas);
|
||||
printf(" -curses : play in color text-mode\n");
|
||||
printf(" -double : play in 640x480 mode\n");
|
||||
printf(" -fullscreen : play in fullscreen mode (if available)\n");
|
||||
printf(" -nosound : disables sound within game\n");
|
||||
printf(" -opengl : play in openGL mode\n");
|
||||
printf(" -version : print version\n");
|
||||
printf(" -? : print this help message\n");
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void vmw_opener(tb1_state *game_state, vmwVisual *virtual_1) {
|
||||
|
||||
int x;
|
||||
|
||||
for(x=0;x<256;x++) {
|
||||
vmwLoadPalette(game_state->graph_state,0,0,0,x); /* 0=black */
|
||||
}
|
||||
|
||||
/* Do the VMW Software Production Logo */
|
||||
for(x=0;x<=40;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, ( (x+20)*4),0,182+x);
|
||||
}
|
||||
|
||||
/* Set the white color */
|
||||
vmwLoadPalette(game_state->graph_state,0xff,0xff,0xff,15);
|
||||
|
||||
vmwFlushPalette(game_state->graph_state);
|
||||
|
||||
/* Actually draw the stylized VMW */
|
||||
for(x=0;x<=40;x++) {
|
||||
vmwDrawVLine(x+40,45,2*x,100+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+80,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--){
|
||||
vmwDrawVLine(x+80,45,80-(2*x),140-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+120,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,
|
||||
15,15,0,game_state->graph_state->default_font,virtual_1);
|
||||
|
||||
if ((game_state->sound_possible) && (game_state->music_enabled)) {
|
||||
playSound();
|
||||
}
|
||||
|
||||
vmwBlitMemToDisplay(game_state->graph_state,virtual_1);
|
||||
pauseawhile(5);
|
||||
vmwFadeToBlack(game_state->graph_state,virtual_1,0);
|
||||
}
|
||||
|
||||
int main(int argc,char **argv) {
|
||||
|
||||
int i,grapherror,reloadpic=0;
|
||||
int ch,barpos,time_sec;
|
||||
int graphics_target=VMW_SDLTARGET;
|
||||
FILE *fff;
|
||||
char *dir_name,options_file[BUFSIZ];
|
||||
vmwVisual *virtual_1,*virtual_2,*virtual_3;
|
||||
|
||||
tb1_state *game_state;
|
||||
|
||||
vmwFont *tb1_font;
|
||||
|
||||
struct timeval time_info;
|
||||
struct timezone dontcare;
|
||||
|
||||
printf("\nTom Bombem v%s by Vince Weaver vince@deater.net\n",TB1_VERSION);
|
||||
printf(" http://www.deater.net/weave/vmwprod/tb1\n\n");
|
||||
|
||||
/* Setup the game state */
|
||||
if ( (game_state=calloc(1,sizeof(tb1_state)))==NULL) {
|
||||
printf("You are seriously low on RAM!\n");
|
||||
return 3;
|
||||
}
|
||||
|
||||
/* Some sane defaults */
|
||||
game_state->level=0;
|
||||
game_state->shields=0;
|
||||
game_state->score=0;
|
||||
game_state->virtual_1=NULL;
|
||||
game_state->virtual_2=NULL;
|
||||
game_state->virtual_3=NULL;
|
||||
game_state->sound_possible=1;
|
||||
game_state->music_enabled=1;
|
||||
game_state->sound_enabled=1;
|
||||
game_state->sound_volume=5;
|
||||
game_state->music_volume=5;
|
||||
game_state->default_double_size=0;
|
||||
game_state->default_fullscreen=0;
|
||||
|
||||
/* Load saved defaults, if any */
|
||||
dir_name=check_for_tb1_directory(game_state,0);
|
||||
if (dir_name==NULL) {
|
||||
printf(" + No ~/.tb1 directory. Using default options.\n");
|
||||
}
|
||||
else {
|
||||
sprintf(options_file,"%s/options.tb1",dir_name);
|
||||
fff=fopen(options_file,"r");
|
||||
if (fff==NULL) {
|
||||
printf(" + No ~/.tb1/options.tb1 file. Using defaults.\n");
|
||||
}
|
||||
else {
|
||||
printf(" + Reading options from ~/.tb1/options.tb1\n");
|
||||
fscanf(fff,"%i %i %i %i %i %i",
|
||||
&game_state->sound_enabled,
|
||||
&game_state->music_enabled,
|
||||
&game_state->sound_volume,
|
||||
&game_state->music_volume,
|
||||
&game_state->default_double_size,
|
||||
&game_state->default_fullscreen);
|
||||
fclose(fff);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Parse Command Line Arguments */
|
||||
i=1;
|
||||
while(i<argc) {
|
||||
if (argv[i][0]=='-') {
|
||||
switch (argv[i][1]) {
|
||||
case 'h':
|
||||
case '?':
|
||||
command_line_help(0,argv[0]);
|
||||
return 5;
|
||||
break;
|
||||
case 'v':
|
||||
command_line_help(1,argv[0]);
|
||||
return 5;
|
||||
break;
|
||||
case 'f':
|
||||
game_state->default_fullscreen=1;
|
||||
break;
|
||||
case 'c':
|
||||
graphics_target=VMW_CURSESTARGET;
|
||||
break;
|
||||
case 'd':
|
||||
game_state->default_double_size=1;
|
||||
break;
|
||||
case 'n':
|
||||
game_state->sound_possible=0;
|
||||
printf(" + Sound totally disabled\n");
|
||||
break;
|
||||
case 'o':
|
||||
graphics_target=VMW_OPENGLTARGET;
|
||||
break;
|
||||
default :
|
||||
command_line_help(0,argv[0]);
|
||||
printf("Unknown Option: %s\n\n",argv[i]);
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
else {
|
||||
command_line_help(0,argv[0]);
|
||||
printf("Unknown Option: %s\n\n",argv[i]);
|
||||
return 5;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
/* Find the Data */
|
||||
/* FIXME : User Defined Path Info*/
|
||||
if ( (fff=fopen("./data/tb1_data_files_here","r"))!=NULL) {
|
||||
strncpy(game_state->path_to_data,"./data/",20);
|
||||
}
|
||||
else if ( (fff=fopen("/usr/local/games/tb1/data/tb1_data_files_here","r"))
|
||||
!=NULL) {
|
||||
strncpy(game_state->path_to_data,"/usr/local/games/tb1/data/",40);
|
||||
}
|
||||
else {
|
||||
char tempst[200];
|
||||
|
||||
sprintf(tempst,"%s/.tb1/data/tb1_data_files_here",getenv("HOME"));
|
||||
if ( (fff=fopen(tempst,"r"))!=NULL) {
|
||||
sprintf(game_state->path_to_data,"%s/.tb1/data/",getenv("HOME"));
|
||||
}
|
||||
else {
|
||||
printf("ERROR! Could not find tb1 data!\n");
|
||||
printf(" Checked ./data, /usr/local/games/tb1/data\n");
|
||||
printf(" and %s/.tb1/data\n\n",getenv("HOME"));
|
||||
return 9;
|
||||
}
|
||||
}
|
||||
printf(" + Found tb1 data in %s\n",game_state->path_to_data);
|
||||
|
||||
/* LEGACY OPERATION BOTTLECAP STUFF---> *\
|
||||
\* --> You are not meant to understand this <-- */
|
||||
/* No 9-22-94 Back to yes 10-6-94 uh_oh 2-21-95 *\
|
||||
\* gone for real long time 10-12-95 */
|
||||
/* 11-95 not AMG, but AAT *\
|
||||
\* 3-96 oh well... gave up on AAT finally */
|
||||
/* 5-11-96 Now MLP... *\
|
||||
\* 9-22-2000 :( */
|
||||
/* 3-25-2002 Now KRG ;) */
|
||||
|
||||
/* Randomize random number generator */
|
||||
srandom(time(NULL));
|
||||
printf(" + Seeding random number generator...\n");
|
||||
|
||||
/* Load/Detect sound */
|
||||
if (game_state->sound_possible) {
|
||||
if (initSound(game_state->path_to_data)<0) {
|
||||
game_state->sound_possible=0;
|
||||
}
|
||||
/* Load fanfare Music */
|
||||
if (game_state->sound_possible) {
|
||||
loadSound(tb1_data_file("music/vmwfan.mod",game_state->path_to_data));
|
||||
}
|
||||
printf(" + Loaded sounds...\n");
|
||||
}
|
||||
|
||||
/* Setup Graphics */
|
||||
if (!game_state->default_double_size) {
|
||||
if ( (game_state->graph_state=
|
||||
vmwSetupSVMWGraph(graphics_target,
|
||||
320,200,
|
||||
0,1,
|
||||
game_state->default_fullscreen,
|
||||
1))==NULL) {
|
||||
fprintf(stderr,"ERROR: Couldn't get display set up properly.\n");
|
||||
return VMW_ERROR_DISPLAY;
|
||||
}
|
||||
}
|
||||
else { /* We are double-sized */
|
||||
if ( (game_state->graph_state=
|
||||
vmwSetupSVMWGraph(graphics_target,
|
||||
640,480,
|
||||
0,2,
|
||||
game_state->default_fullscreen,
|
||||
1))==NULL) {
|
||||
fprintf(stderr,"ERROR: Couldn't get display set up properly.\n");
|
||||
return VMW_ERROR_DISPLAY;
|
||||
}
|
||||
}
|
||||
|
||||
/* Load the tom bombem font */
|
||||
game_state->graph_state->default_font=
|
||||
vmwLoadFont(tb1_data_file("tbfont.tb1",
|
||||
game_state->path_to_data),8,16,256);
|
||||
printf(" + Loaded tb1 font...\n");
|
||||
|
||||
/* Allocate the 3 virtual screens */
|
||||
if ((game_state->virtual_1=vmwSetupVisual(320,200))==NULL) {
|
||||
fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 1!\n");
|
||||
return VMW_ERROR_MEM;
|
||||
}
|
||||
|
||||
if ((game_state->virtual_2=vmwSetupVisual(320,400))==NULL) {
|
||||
fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 2!\n");
|
||||
return VMW_ERROR_MEM;
|
||||
}
|
||||
|
||||
if ((game_state->virtual_3=vmwSetupVisual(320,200))==NULL) {
|
||||
fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 3!\n");
|
||||
return VMW_ERROR_MEM;
|
||||
}
|
||||
|
||||
printf(" + Allocated virtual screens...\n");
|
||||
|
||||
/* To ease typing burden */
|
||||
virtual_1=game_state->virtual_1;
|
||||
virtual_2=game_state->virtual_2;
|
||||
virtual_3=game_state->virtual_3;
|
||||
tb1_font=game_state->graph_state->default_font;
|
||||
|
||||
/* The "fancy" opener */
|
||||
vmw_opener(game_state,virtual_1);
|
||||
|
||||
/* Load menu music */
|
||||
if (game_state->sound_possible) {
|
||||
stopSound();
|
||||
loadSound(tb1_data_file("music/weave1.mod",game_state->path_to_data));
|
||||
}
|
||||
|
||||
/* Load palette */
|
||||
grapherror=vmwLoadPicPacked(0,0,virtual_1,1,0,
|
||||
tb1_data_file("tbomb1.tb1",
|
||||
game_state->path_to_data),
|
||||
game_state->graph_state);
|
||||
|
||||
/* Bit of a hack to load proper unfade colors */
|
||||
vmwFadeToBlack(game_state->graph_state,virtual_1,1);
|
||||
|
||||
/* Load Title Picture */
|
||||
grapherror=vmwLoadPicPacked(0,0,virtual_1,1,1,
|
||||
tb1_data_file("tbomb1.tb1",
|
||||
game_state->path_to_data),
|
||||
game_state->graph_state);
|
||||
|
||||
/* Copy the picture over */
|
||||
vmwFlipVirtual(virtual_3,virtual_1,320,200);
|
||||
|
||||
vmwUnFade(game_state->graph_state,virtual_1);
|
||||
|
||||
/* Main Menu Loop */
|
||||
while(1) {
|
||||
/* If virtual_3 was over-written, re-load it */
|
||||
if (reloadpic) {
|
||||
if ((game_state->sound_possible) && (game_state->music_enabled)) {
|
||||
loadSound(tb1_data_file("music/weave1.mod",
|
||||
game_state->path_to_data));
|
||||
}
|
||||
grapherror=vmwLoadPicPacked(0,0,virtual_3,1,1,
|
||||
tb1_data_file("tbomb1.tb1",
|
||||
game_state->path_to_data),
|
||||
game_state->graph_state);
|
||||
reloadpic=0;
|
||||
}
|
||||
|
||||
vmwFlipVirtual(virtual_1,virtual_3,320,200);
|
||||
|
||||
/* Play the menu-music */
|
||||
if ((game_state->sound_possible) && (game_state->music_enabled)) {
|
||||
playSound();
|
||||
}
|
||||
vmwBlitMemToDisplay(game_state->graph_state,virtual_1);
|
||||
|
||||
/* Don't show the menu until keypress/15s */
|
||||
pauseawhile(15);
|
||||
|
||||
barpos=0;
|
||||
vmwTextXY("F1 HELP",0,190,9,7,0,tb1_font,virtual_1);
|
||||
coolbox(117,61,199,140,1,virtual_1);
|
||||
|
||||
vmwBlitMemToDisplay(game_state->graph_state,virtual_1);
|
||||
ch=0;
|
||||
|
||||
while(ch!=VMW_ENTER){
|
||||
if (barpos==0) {
|
||||
vmwTextXY("NEW GAME",123,67,32,0,1,tb1_font,virtual_1);
|
||||
}
|
||||
else {
|
||||
vmwTextXY("NEW GAME",123,67,32,7,1,tb1_font,virtual_1);
|
||||
}
|
||||
if (barpos==1) {
|
||||
vmwTextXY("OPTIONS",123,77,32,0,1,tb1_font,virtual_1);
|
||||
}
|
||||
else {
|
||||
vmwTextXY("OPTIONS",123,77,32,7,1,tb1_font,virtual_1);
|
||||
}
|
||||
if (barpos==2) {
|
||||
vmwTextXY("ABOUT",123,87,32,0,1,tb1_font,virtual_1);
|
||||
}
|
||||
else {
|
||||
vmwTextXY("ABOUT",123,87,32,7,1,tb1_font,virtual_1);
|
||||
}
|
||||
if (barpos==3) {
|
||||
vmwTextXY("LOAD GAME",123,97,32,0,1,tb1_font,virtual_1);
|
||||
}
|
||||
else {
|
||||
vmwTextXY("LOAD GAME",123,97,32,7,1,tb1_font,virtual_1);
|
||||
}
|
||||
if (barpos==4) {
|
||||
vmwTextXY("STORY",123,107,32,0,1,tb1_font,virtual_1);
|
||||
}
|
||||
else {
|
||||
vmwTextXY("STORY",123,107,32,7,1,tb1_font,virtual_1);
|
||||
}
|
||||
if (barpos==5) {
|
||||
vmwTextXY("CREDITS",123,117,32,0,1,tb1_font,virtual_1);
|
||||
}
|
||||
else {
|
||||
vmwTextXY("CREDITS",123,117,32,7,1,tb1_font,virtual_1);
|
||||
}
|
||||
if (barpos==6) {
|
||||
vmwTextXY("QUIT",123,127,32,0,1,tb1_font,virtual_1);
|
||||
}
|
||||
else {
|
||||
vmwTextXY("QUIT",123,127,32,7,1,tb1_font,virtual_1);
|
||||
}
|
||||
|
||||
vmwBlitMemToDisplay(game_state->graph_state,virtual_1);
|
||||
|
||||
/* If at title screen too long, run credits */
|
||||
gettimeofday(&time_info,&dontcare);
|
||||
time_sec=time_info.tv_sec;
|
||||
|
||||
while( ((ch=vmwGetInput())==0)) {
|
||||
usleep(30);
|
||||
gettimeofday(&time_info,&dontcare);
|
||||
if (time_info.tv_sec-time_sec>40) {
|
||||
if (game_state->sound_possible) stopSound();
|
||||
credits(game_state);
|
||||
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*/
|
||||
if (ch=='n') barpos=0; /*N*/
|
||||
if (ch=='o') barpos=1; /*O*/
|
||||
if (ch=='a') barpos=2; /*A*/
|
||||
if (ch=='l') barpos=3; /*L*/
|
||||
if (ch=='s') barpos=4; /*S*/
|
||||
if (ch=='c') barpos=5; /*C*/
|
||||
if (ch=='q') barpos=6; /*Q*/
|
||||
if (ch==VMW_ESCAPE){ /* escape */
|
||||
barpos=6;
|
||||
ch=VMW_ENTER;
|
||||
}
|
||||
if(barpos==7) barpos=0;
|
||||
if(barpos<0) barpos=6;
|
||||
}
|
||||
if (game_state->sound_possible) stopSound();
|
||||
|
||||
/* Run whatever it was that the person pressed */
|
||||
switch (barpos) {
|
||||
case 0: playthegame(game_state); reloadpic=1; break;
|
||||
case 1: options(game_state); reloadpic=1; break;
|
||||
case 2: about(game_state); reloadpic=1; break;
|
||||
case 3: loadgame(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
/****************************************************************\
|
||||
\* TOM BOMBEM AND THE INVASION OF THE INANIMATE_OBJECTS */
|
||||
/* version 2.9.16 26 December 2009 *\
|
||||
\* by Vince Weaver vince@deater.net */
|
||||
/* *\
|
||||
\* Originally written in Pascal and x86 assembly for DOS */
|
||||
/* using the PCGPE code as an example in 1994 *\
|
||||
\* Ported to Linux, C, and ggi late 1997-early 1998 */
|
||||
/* Port continued to SDL in June of 2000 *\
|
||||
\* This source is released under the GPL */
|
||||
/****************************************************************/
|
||||
|
||||
#define TB1_VERSION "2.9.16"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> /* for calloc */
|
||||
#include <string.h> /* for strncpy */
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "svmwgraph/svmwgraph.h"
|
||||
#include "tb1_state.h"
|
||||
#include "tblib.h"
|
||||
#include "sound.h"
|
||||
|
||||
#include "graphic_tools.h"
|
||||
#include "help.h"
|
||||
#include "quit.h"
|
||||
#include "story.h"
|
||||
#include "credits.h"
|
||||
#include "about.h"
|
||||
#include "loadsave.h"
|
||||
#include "options.h"
|
||||
#include "playgame.h"
|
||||
|
||||
int command_line_help(int show_version,char *runas) {
|
||||
|
||||
if (!show_version) {
|
||||
printf("Usage: %s [-curses] [-double] [-fullscreen] [-nosound]"
|
||||
" [-version] [-?]\n\n",runas);
|
||||
printf(" -curses : play in color text-mode\n");
|
||||
printf(" -double : play in 640x480 mode\n");
|
||||
printf(" -fullscreen : play in fullscreen mode (if available)\n");
|
||||
printf(" -nosound : disables sound within game\n");
|
||||
printf(" -opengl : play in openGL mode\n");
|
||||
printf(" -version : print version\n");
|
||||
printf(" -? : print this help message\n");
|
||||
printf("\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void vmw_opener(tb1_state *game_state, vmwVisual *virtual_1) {
|
||||
|
||||
int x;
|
||||
|
||||
for(x=0;x<256;x++) {
|
||||
vmwLoadPalette(game_state->graph_state,0,0,0,x); /* 0=black */
|
||||
}
|
||||
|
||||
/* Do the VMW Software Production Logo */
|
||||
for(x=0;x<=40;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, ( (x+20)*4),0,182+x);
|
||||
}
|
||||
|
||||
/* Set the white color */
|
||||
vmwLoadPalette(game_state->graph_state,0xff,0xff,0xff,15);
|
||||
|
||||
vmwFlushPalette(game_state->graph_state);
|
||||
|
||||
/* Actually draw the stylized VMW */
|
||||
for(x=0;x<=40;x++) {
|
||||
vmwDrawVLine(x+40,45,2*x,100+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+80,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--){
|
||||
vmwDrawVLine(x+80,45,80-(2*x),140-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+120,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,
|
||||
15,15,0,game_state->graph_state->default_font,virtual_1);
|
||||
|
||||
if ((game_state->sound_possible) && (game_state->music_enabled)) {
|
||||
playSound();
|
||||
}
|
||||
|
||||
vmwBlitMemToDisplay(game_state->graph_state,virtual_1);
|
||||
pauseawhile(5);
|
||||
vmwFadeToBlack(game_state->graph_state,virtual_1,0);
|
||||
}
|
||||
|
||||
int main(int argc,char **argv) {
|
||||
|
||||
int i,grapherror,reloadpic=0;
|
||||
int ch,barpos,time_sec;
|
||||
int graphics_target=VMW_SDLTARGET;
|
||||
FILE *fff;
|
||||
char *dir_name,options_file[BUFSIZ];
|
||||
vmwVisual *virtual_1,*virtual_3;//*virtual_2
|
||||
|
||||
tb1_state *game_state;
|
||||
|
||||
vmwFont *tb1_font;
|
||||
|
||||
struct timeval time_info;
|
||||
struct timezone dontcare;
|
||||
|
||||
printf("\nTom Bombem v%s by Vince Weaver vince@deater.net\n",TB1_VERSION);
|
||||
printf(" http://www.deater.net/weave/vmwprod/tb1\n\n");
|
||||
|
||||
/* Setup the game state */
|
||||
if ( (game_state=calloc(1,sizeof(tb1_state)))==NULL) {
|
||||
printf("You are seriously low on RAM!\n");
|
||||
return 3;
|
||||
}
|
||||
|
||||
/* Some sane defaults */
|
||||
game_state->level=0;
|
||||
game_state->shields=0;
|
||||
game_state->score=0;
|
||||
game_state->virtual_1=NULL;
|
||||
//game_state->virtual_2=NULL;
|
||||
game_state->virtual_3=NULL;
|
||||
game_state->sound_possible=1;
|
||||
game_state->music_enabled=1;
|
||||
game_state->sound_enabled=1;
|
||||
game_state->sound_volume=5;
|
||||
game_state->music_volume=5;
|
||||
game_state->default_double_size=0;
|
||||
game_state->default_fullscreen=0;
|
||||
|
||||
/* Load saved defaults, if any */
|
||||
dir_name=check_for_tb1_directory(game_state,0);
|
||||
if (dir_name==NULL) {
|
||||
printf(" + No ~/.tb1 directory. Using default options.\n");
|
||||
}
|
||||
else {
|
||||
sprintf(options_file,"%s/options.tb1",dir_name);
|
||||
fff=fopen(options_file,"r");
|
||||
if (fff==NULL) {
|
||||
printf(" + No ~/.tb1/options.tb1 file. Using defaults.\n");
|
||||
}
|
||||
else {
|
||||
printf(" + Reading options from ~/.tb1/options.tb1\n");
|
||||
fscanf(fff,"%i %i %i %i %i %i",
|
||||
&game_state->sound_enabled,
|
||||
&game_state->music_enabled,
|
||||
&game_state->sound_volume,
|
||||
&game_state->music_volume,
|
||||
&game_state->default_double_size,
|
||||
&game_state->default_fullscreen);
|
||||
fclose(fff);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Parse Command Line Arguments */
|
||||
i=1;
|
||||
while(i<argc) {
|
||||
if (argv[i][0]=='-') {
|
||||
switch (argv[i][1]) {
|
||||
case 'h':
|
||||
case '?':
|
||||
command_line_help(0,argv[0]);
|
||||
return 5;
|
||||
break;
|
||||
case 'v':
|
||||
command_line_help(1,argv[0]);
|
||||
return 5;
|
||||
break;
|
||||
case 'f':
|
||||
game_state->default_fullscreen=1;
|
||||
break;
|
||||
case 'c':
|
||||
graphics_target=VMW_CURSESTARGET;
|
||||
break;
|
||||
case 'd':
|
||||
game_state->default_double_size=1;
|
||||
break;
|
||||
case 'n':
|
||||
game_state->sound_possible=0;
|
||||
printf(" + Sound totally disabled\n");
|
||||
break;
|
||||
case 'o':
|
||||
graphics_target=VMW_OPENGLTARGET;
|
||||
break;
|
||||
default :
|
||||
command_line_help(0,argv[0]);
|
||||
printf("Unknown Option: %s\n\n",argv[i]);
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
else {
|
||||
command_line_help(0,argv[0]);
|
||||
printf("Unknown Option: %s\n\n",argv[i]);
|
||||
return 5;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
/* Find the Data */
|
||||
/* FIXME : User Defined Path Info*/
|
||||
if ( (fff=fopen("./data/tb1_data_files_here","r"))!=NULL) {
|
||||
strncpy(game_state->path_to_data,"./data/",20);
|
||||
}
|
||||
else if ( (fff=fopen("/usr/local/games/tb1/data/tb1_data_files_here","r"))
|
||||
!=NULL) {
|
||||
strncpy(game_state->path_to_data,"/usr/local/games/tb1/data/",40);
|
||||
}
|
||||
else {
|
||||
char tempst[200];
|
||||
|
||||
sprintf(tempst,"%s/.tb1/data/tb1_data_files_here",getenv("HOME"));
|
||||
if ( (fff=fopen(tempst,"r"))!=NULL) {
|
||||
sprintf(game_state->path_to_data,"%s/.tb1/data/",getenv("HOME"));
|
||||
}
|
||||
else {
|
||||
printf("ERROR! Could not find tb1 data!\n");
|
||||
printf(" Checked ./data, /usr/local/games/tb1/data\n");
|
||||
printf(" and %s/.tb1/data\n\n",getenv("HOME"));
|
||||
return 9;
|
||||
}
|
||||
}
|
||||
printf(" + Found tb1 data in %s\n",game_state->path_to_data);
|
||||
|
||||
/* LEGACY OPERATION BOTTLECAP STUFF---> *\
|
||||
\* --> You are not meant to understand this <-- */
|
||||
/* No 9-22-94 Back to yes 10-6-94 uh_oh 2-21-95 *\
|
||||
\* gone for real long time 10-12-95 */
|
||||
/* 11-95 not AMG, but AAT *\
|
||||
\* 3-96 oh well... gave up on AAT finally */
|
||||
/* 5-11-96 Now MLP... *\
|
||||
\* 9-22-2000 :( */
|
||||
/* 3-25-2002 Now KRG ;) */
|
||||
|
||||
/* Randomize random number generator */
|
||||
srandom(time(NULL));
|
||||
printf(" + Seeding random number generator...\n");
|
||||
|
||||
/* Load/Detect sound */
|
||||
if (game_state->sound_possible) {
|
||||
if (initSound(game_state->path_to_data)<0) {
|
||||
game_state->sound_possible=0;
|
||||
}
|
||||
/* Load fanfare Music */
|
||||
if (game_state->sound_possible) {
|
||||
loadSound(tb1_data_file("music/vmwfan.mod",game_state->path_to_data));
|
||||
}
|
||||
printf(" + Loaded sounds...\n");
|
||||
}
|
||||
|
||||
/* Setup Graphics */
|
||||
if (!game_state->default_double_size) {
|
||||
if ( (game_state->graph_state=
|
||||
vmwSetupSVMWGraph(graphics_target,
|
||||
320,200,
|
||||
0,1,
|
||||
game_state->default_fullscreen,
|
||||
1))==NULL) {
|
||||
fprintf(stderr,"ERROR: Couldn't get display set up properly.\n");
|
||||
return VMW_ERROR_DISPLAY;
|
||||
}
|
||||
}
|
||||
else { /* We are double-sized */
|
||||
if ( (game_state->graph_state=
|
||||
vmwSetupSVMWGraph(graphics_target,
|
||||
640,480,
|
||||
0,2,
|
||||
game_state->default_fullscreen,
|
||||
1))==NULL) {
|
||||
fprintf(stderr,"ERROR: Couldn't get display set up properly.\n");
|
||||
return VMW_ERROR_DISPLAY;
|
||||
}
|
||||
}
|
||||
|
||||
/* Load the tom bombem font */
|
||||
game_state->graph_state->default_font=
|
||||
vmwLoadFont(tb1_data_file("tbfont.tb1",
|
||||
game_state->path_to_data),8,16,256);
|
||||
printf(" + Loaded tb1 font...\n");
|
||||
|
||||
/* Allocate the 3 virtual screens */
|
||||
if ((game_state->virtual_1=vmwSetupVisual(320,200))==NULL) {
|
||||
fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 1!\n");
|
||||
return VMW_ERROR_MEM;
|
||||
}
|
||||
|
||||
if ((game_state->virtual_2=vmwSetupVisual(320,400))==NULL) {
|
||||
fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 2!\n");
|
||||
return VMW_ERROR_MEM;
|
||||
}
|
||||
|
||||
if ((game_state->virtual_3=vmwSetupVisual(320,200))==NULL) {
|
||||
fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 3!\n");
|
||||
return VMW_ERROR_MEM;
|
||||
}
|
||||
|
||||
printf(" + Allocated virtual screens...\n");
|
||||
|
||||
/* To ease typing burden */
|
||||
virtual_1=game_state->virtual_1;
|
||||
//virtual_2=game_state->virtual_2;
|
||||
virtual_3=game_state->virtual_3;
|
||||
tb1_font=game_state->graph_state->default_font;
|
||||
|
||||
/* The "fancy" opener */
|
||||
vmw_opener(game_state,virtual_1);
|
||||
|
||||
/* Load menu music */
|
||||
if (game_state->sound_possible) {
|
||||
stopSound();
|
||||
loadSound(tb1_data_file("music/weave1.mod",game_state->path_to_data));
|
||||
}
|
||||
|
||||
/* Load palette */
|
||||
grapherror=vmwLoadPicPacked(0,0,virtual_1,1,0,
|
||||
tb1_data_file("tbomb1.tb1",
|
||||
game_state->path_to_data),
|
||||
game_state->graph_state);
|
||||
if (grapherror) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Bit of a hack to load proper unfade colors */
|
||||
vmwFadeToBlack(game_state->graph_state,virtual_1,1);
|
||||
|
||||
/* Load Title Picture */
|
||||
grapherror=vmwLoadPicPacked(0,0,virtual_1,1,1,
|
||||
tb1_data_file("tbomb1.tb1",
|
||||
game_state->path_to_data),
|
||||
game_state->graph_state);
|
||||
|
||||
/* Copy the picture over */
|
||||
vmwFlipVirtual(virtual_3,virtual_1,320,200);
|
||||
|
||||
vmwUnFade(game_state->graph_state,virtual_1);
|
||||
|
||||
/* Main Menu Loop */
|
||||
while(1) {
|
||||
/* If virtual_3 was over-written, re-load it */
|
||||
if (reloadpic) {
|
||||
if ((game_state->sound_possible) && (game_state->music_enabled)) {
|
||||
loadSound(tb1_data_file("music/weave1.mod",
|
||||
game_state->path_to_data));
|
||||
}
|
||||
grapherror=vmwLoadPicPacked(0,0,virtual_3,1,1,
|
||||
tb1_data_file("tbomb1.tb1",
|
||||
game_state->path_to_data),
|
||||
game_state->graph_state);
|
||||
reloadpic=0;
|
||||
}
|
||||
|
||||
vmwFlipVirtual(virtual_1,virtual_3,320,200);
|
||||
|
||||
/* Play the menu-music */
|
||||
if ((game_state->sound_possible) && (game_state->music_enabled)) {
|
||||
playSound();
|
||||
}
|
||||
vmwBlitMemToDisplay(game_state->graph_state,virtual_1);
|
||||
|
||||
/* Don't show the menu until keypress/15s */
|
||||
pauseawhile(15);
|
||||
|
||||
barpos=0;
|
||||
vmwTextXY("F1 HELP",0,190,9,7,0,tb1_font,virtual_1);
|
||||
coolbox(117,61,199,140,1,virtual_1);
|
||||
|
||||
vmwBlitMemToDisplay(game_state->graph_state,virtual_1);
|
||||
ch=0;
|
||||
|
||||
while(ch!=VMW_ENTER){
|
||||
if (barpos==0) {
|
||||
vmwTextXY("NEW GAME",123,67,32,0,1,tb1_font,virtual_1);
|
||||
}
|
||||
else {
|
||||
vmwTextXY("NEW GAME",123,67,32,7,1,tb1_font,virtual_1);
|
||||
}
|
||||
if (barpos==1) {
|
||||
vmwTextXY("OPTIONS",123,77,32,0,1,tb1_font,virtual_1);
|
||||
}
|
||||
else {
|
||||
vmwTextXY("OPTIONS",123,77,32,7,1,tb1_font,virtual_1);
|
||||
}
|
||||
if (barpos==2) {
|
||||
vmwTextXY("ABOUT",123,87,32,0,1,tb1_font,virtual_1);
|
||||
}
|
||||
else {
|
||||
vmwTextXY("ABOUT",123,87,32,7,1,tb1_font,virtual_1);
|
||||
}
|
||||
if (barpos==3) {
|
||||
vmwTextXY("LOAD GAME",123,97,32,0,1,tb1_font,virtual_1);
|
||||
}
|
||||
else {
|
||||
vmwTextXY("LOAD GAME",123,97,32,7,1,tb1_font,virtual_1);
|
||||
}
|
||||
if (barpos==4) {
|
||||
vmwTextXY("STORY",123,107,32,0,1,tb1_font,virtual_1);
|
||||
}
|
||||
else {
|
||||
vmwTextXY("STORY",123,107,32,7,1,tb1_font,virtual_1);
|
||||
}
|
||||
if (barpos==5) {
|
||||
vmwTextXY("CREDITS",123,117,32,0,1,tb1_font,virtual_1);
|
||||
}
|
||||
else {
|
||||
vmwTextXY("CREDITS",123,117,32,7,1,tb1_font,virtual_1);
|
||||
}
|
||||
if (barpos==6) {
|
||||
vmwTextXY("QUIT",123,127,32,0,1,tb1_font,virtual_1);
|
||||
}
|
||||
else {
|
||||
vmwTextXY("QUIT",123,127,32,7,1,tb1_font,virtual_1);
|
||||
}
|
||||
|
||||
vmwBlitMemToDisplay(game_state->graph_state,virtual_1);
|
||||
|
||||
/* If at title screen too long, run credits */
|
||||
gettimeofday(&time_info,&dontcare);
|
||||
time_sec=time_info.tv_sec;
|
||||
|
||||
while( ((ch=vmwGetInput())==0)) {
|
||||
usleep(30);
|
||||
gettimeofday(&time_info,&dontcare);
|
||||
if (time_info.tv_sec-time_sec>40) {
|
||||
if (game_state->sound_possible) stopSound();
|
||||
credits(game_state);
|
||||
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*/
|
||||
if (ch=='n') barpos=0; /*N*/
|
||||
if (ch=='o') barpos=1; /*O*/
|
||||
if (ch=='a') barpos=2; /*A*/
|
||||
if (ch=='l') barpos=3; /*L*/
|
||||
if (ch=='s') barpos=4; /*S*/
|
||||
if (ch=='c') barpos=5; /*C*/
|
||||
if (ch=='q') barpos=6; /*Q*/
|
||||
if (ch==VMW_ESCAPE){ /* escape */
|
||||
barpos=6;
|
||||
ch=VMW_ENTER;
|
||||
}
|
||||
if(barpos==7) barpos=0;
|
||||
if(barpos<0) barpos=6;
|
||||
}
|
||||
if (game_state->sound_possible) stopSound();
|
||||
|
||||
/* Run whatever it was that the person pressed */
|
||||
switch (barpos) {
|
||||
case 0: playthegame(game_state); reloadpic=1; break;
|
||||
case 1: options(game_state); reloadpic=1; break;
|
||||
case 2: about(game_state); reloadpic=1; break;
|
||||
case 3: loadgame(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,69 +1,69 @@
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h> /* abs */
|
||||
#include "svmwgraph/svmwgraph.h"
|
||||
#include "tb1_state.h"
|
||||
#include "graphic_tools.h"
|
||||
|
||||
void pauseawhile(int howlong) {
|
||||
|
||||
struct timeval bob;
|
||||
struct timezone mree;
|
||||
long begin_s,begin_u;
|
||||
|
||||
vmwClearKeyboardBuffer();
|
||||
gettimeofday(&bob,&mree);
|
||||
begin_s=bob.tv_sec; begin_u=bob.tv_usec;
|
||||
while ((bob.tv_sec-begin_s)<howlong) {
|
||||
if (vmwGetInput()) return;
|
||||
usleep(30);
|
||||
gettimeofday(&bob,&mree);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* The collision detection routine. Optimize? */
|
||||
/* Detects if x1,y1 is within x2,y2 */
|
||||
int collision(int x1,int y1,int xsize,int ysize,
|
||||
int x2,int y2,int x2size,int y2size)
|
||||
{
|
||||
if (abs((y1+ysize)-(y2+y2size))<(ysize+y2size)){
|
||||
if (abs((x1+xsize)-(x2+x2size))<(xsize+x2size)) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Now memory-leak friendly */
|
||||
char *tb1_data_file(char *name,char *path)
|
||||
{
|
||||
static int initialized=0;
|
||||
static char *tempst;
|
||||
|
||||
if (!initialized) {
|
||||
tempst=(char *)calloc(BUFSIZ,sizeof(char));
|
||||
initialized=1;
|
||||
}
|
||||
snprintf(tempst,BUFSIZ,"%s/%s",path,name);
|
||||
return tempst;
|
||||
}
|
||||
|
||||
int are_you_sure(tb1_state *game_state,
|
||||
char *warning_1,
|
||||
char *warning_2,
|
||||
char *yes_option,
|
||||
char *no_option) {
|
||||
|
||||
|
||||
return vmwAreYouSure(game_state->graph_state,
|
||||
game_state->graph_state->default_font,
|
||||
game_state->virtual_1,
|
||||
warning_1,
|
||||
warning_2,
|
||||
yes_option,
|
||||
no_option);
|
||||
|
||||
|
||||
}
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h> /* abs */
|
||||
#include "svmwgraph/svmwgraph.h"
|
||||
#include "tb1_state.h"
|
||||
#include "graphic_tools.h"
|
||||
|
||||
void pauseawhile(int howlong) {
|
||||
|
||||
struct timeval bob;
|
||||
struct timezone mree;
|
||||
long begin_s;
|
||||
|
||||
vmwClearKeyboardBuffer();
|
||||
gettimeofday(&bob,&mree);
|
||||
begin_s=bob.tv_sec;
|
||||
while ((bob.tv_sec-begin_s)<howlong) {
|
||||
if (vmwGetInput()) return;
|
||||
usleep(30);
|
||||
gettimeofday(&bob,&mree);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* The collision detection routine. Optimize? */
|
||||
/* Detects if x1,y1 is within x2,y2 */
|
||||
int collision(int x1,int y1,int xsize,int ysize,
|
||||
int x2,int y2,int x2size,int y2size)
|
||||
{
|
||||
if (abs((y1+ysize)-(y2+y2size))<(ysize+y2size)){
|
||||
if (abs((x1+xsize)-(x2+x2size))<(xsize+x2size)) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Now memory-leak friendly */
|
||||
char *tb1_data_file(char *name,char *path)
|
||||
{
|
||||
static int initialized=0;
|
||||
static char *tempst;
|
||||
|
||||
if (!initialized) {
|
||||
tempst=(char *)calloc(BUFSIZ,sizeof(char));
|
||||
initialized=1;
|
||||
}
|
||||
snprintf(tempst,BUFSIZ,"%s/%s",path,name);
|
||||
return tempst;
|
||||
}
|
||||
|
||||
int are_you_sure(tb1_state *game_state,
|
||||
char *warning_1,
|
||||
char *warning_2,
|
||||
char *yes_option,
|
||||
char *no_option) {
|
||||
|
||||
|
||||
return vmwAreYouSure(game_state->graph_state,
|
||||
game_state->graph_state->default_font,
|
||||
game_state->virtual_1,
|
||||
warning_1,
|
||||
warning_2,
|
||||
yes_option,
|
||||
no_option);
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user