diff --git a/CHANGES b/CHANGES index 8a163c0..05c590d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,18 @@ +6 October 2000 ++ Fixed off-by-one error in paintpro 6.0 format, making a new 6.1 release ++ Made sure backwards compatability available + +30 September 2000 ++ Rewrote vmw_paintpro.c vmwLoadPicPacked from scratch just about ++ Implemented vmwSavePicPacked ++ Wrote "ppro_view" in tools directory + +25 September 2000 ++ Closed most of the memory leaks + +18 September 2000 ++ Just about everything works now. + 16 September 2000 + Re-wrote completely libsvmwgraph... making it an actual lib, removing all sdl dependencies, added hooks so that any arbitrary diff --git a/TODO b/TODO index a4de814..4307df3 100644 --- a/TODO +++ b/TODO @@ -4,9 +4,9 @@ Requires: Finish Story Other aspirations: + Audit all the code + Better Options Menu Free RAM instead of leaking it. - 8bpp, 24bpp, 32bpp displays - Double and Quad sized displays Re-implement fading in/out Implement level editor diff --git a/about.c b/about.c index 3f2b9b7..7fd950a 100644 --- a/about.c +++ b/about.c @@ -1,5 +1,6 @@ #include +#include /* for usleep */ #include "svmwgraph/svmwgraph.h" #include "tb1_state.h" @@ -8,36 +9,38 @@ void about(tb1_state *game_state) { - int pagenum=1,firstime=0,oldpagenum=0,numpages=4,ch=0; - char tempst[300]; + int pagenum=1,oldpagenum=0,numpages=4,ch=0; + char tempst[40]; vmwFont *tb1_font; vmwVisual *target1,*target2; + /* For convenience */ tb1_font=game_state->graph_state->default_font; target1=game_state->virtual_1; target2=game_state->virtual_2; vmwClearScreen(target1,0); + /* Load the really old picture */ vmwLoadPicPacked(0,0,target2,1,1, tb1_data_file("./about/register.tb1",game_state->path_to_data), game_state->graph_state); -// vmwLoadPicPacked(0,0,target1,1,0, /* Load Palette */ -// tb1_data_file("./about/register.tb1",game_state->path_to_data)); - - while ((ch!=VMW_ESCAPE)&&(ch!='q')){ - while(( (ch=vmwGetInput())==0) && (firstime)); - if(!firstime) firstime=1; - if ((ch==' ') || (ch==VMW_ENTER)) pagenum++; - if ((ch==VMW_RIGHT) || (ch==VMW_DOWN) || (ch==VMW_PGDN)) pagenum++; - if ((ch==VMW_LEFT) || (ch==VMW_UP) || (ch==VMW_PGUP)) pagenum--; - if (pagenum>4) pagenum=1; - if (pagenum<1) pagenum=4; - if (oldpagenum!=pagenum){ - if (pagenum==1) { - vmwFlipVirtual(target1,target2,320,200); - coolbox(0,0,319,199,0,target1); + + /* And repeat until we want to quit */ + while (1) { + + /* If page one, copy my pic over. Otherwise, clear to white */ + if (pagenum==1) { + vmwFlipVirtual(target1,target2,320,200); + coolbox(0,0,319,199,0,target1); + } + else { + coolbox(0,0,319,199,1,target1); + } + + switch(pagenum) { + case 1: shadowrite(" INFORMATION",10,10,9,1,tb1_font,target1); shadowrite("I STARTED THIS GAME IN LATE",70,30,9,1,tb1_font,target1); shadowrite(" 1994, WHEN I WAS 16.",70,40,9,1,tb1_font,target1); @@ -50,9 +53,8 @@ void about(tb1_state *game_state) shadowrite(" HAVE PORTED IT TO LINUX AND SDL.",10,120,12,4,tb1_font,target1); shadowrite(" IN THAT SPIRIT I HAVE NOW GPL'ED",10,130,12,4,tb1_font,target1); shadowrite(" THE CODE.",10,140,12,4,tb1_font,target1); - } else coolbox(0,0,319,199,1,target1); - - if (pagenum==2){ + break; + case 2: shadowrite("MY NAME IS VINCE WEAVER",10,10,10,2,tb1_font,target1); shadowrite(" VISIT MY TALKER",10,20,10,2,tb1_font,target1); shadowrite(" DERANGED.STUDENT.UMD.EDU 7000",10,30,10,2,tb1_font,target1); @@ -66,9 +68,8 @@ void about(tb1_state *game_state) shadowrite("I CAN BE CONTACTED VIA E-MAIL AT:",10,140,12,4,tb1_font,target1); shadowrite(" WEAVE@ENG.UMD.EDU",10,150,9,1,tb1_font,target1); shadowrite("FEEL FREE TO SEND COMMENTS.",10,160,12,4,tb1_font,target1); - } - - if (pagenum==3){ + break; + case 3: shadowrite("OTHER VMW SOFTWARE PRODUCTIONS:",10,10,15,7,tb1_font,target1); shadowrite(" PAINTPRO:",10,30,13,5,tb1_font,target1); shadowrite(" LOAD AND SAVE GRAPHICS PICTURES",10,40,13,5,tb1_font,target1); @@ -83,9 +84,8 @@ void about(tb1_state *game_state) shadowrite(" PRINT VGA FONTS IN DOS AND LINUX",10,130,9,1,tb1_font,target1); shadowrite(" SEABATTLE:",10,140,13,5,tb1_font,target1); shadowrite(" A BATTLESHIP CLONE CODED IN C",10,150,13,5,tb1_font,target1); - } - - if (pagenum==4){ + break; + case 4: shadowrite("DISCLAIMER:",10,10,12,14,tb1_font,target1); shadowrite("* MY PROGRAMS SHOULD NOT DAMAGE YOUR *",8,30,12,4,tb1_font,target1); shadowrite("* COMPUTER IN ANY WAY. PLEASE DON'T *",8,40,12,4,tb1_font,target1); @@ -94,13 +94,23 @@ void about(tb1_state *game_state) shadowrite("* EQUIPMENT, DEFLECTOR SHIELDS, OR *",8,70,12,4,tb1_font,target1); shadowrite("* AUTOMOBILE ENGINES. *",8,80,12,4,tb1_font,target1); shadowrite("* LINUX FOREVER! THE OS FOR EVERYONE *",8,90,12,4,tb1_font,target1); - shadowrite("% WARRANTY ESPECIALLY VOID IF USED %",8,110,11,3,tb1_font,target1); - shadowrite("% ON ANY MICROSOFT(tm) OS (YUCK) %",8,120,11,3,tb1_font,target1); - } - sprintf(tempst,"Page %d of %d: ESC QUITS",pagenum,numpages); - shadowrite(tempst,50,180,15,7,tb1_font,target1); - vmwBlitMemToDisplay(game_state->graph_state,target1); - oldpagenum=pagenum; + break; + default: /* This better not happen */ break; + } + + snprintf(tempst,35,"Page %d of %d: ESC QUITS",pagenum,numpages); + shadowrite(tempst,50,180,15,7,tb1_font,target1); + vmwBlitMemToDisplay(game_state->graph_state,target1); + oldpagenum=pagenum; + + while (pagenum==oldpagenum) { + while ( (ch=vmwGetInput() ) == 0) usleep(100); + if ((ch==VMW_ESCAPE) || (ch=='q')) return; + if ((ch==' ') || (ch==VMW_ENTER)) pagenum++; + if ((ch==VMW_RIGHT) || (ch==VMW_DOWN) || (ch==VMW_PGDN)) pagenum++; + if ((ch==VMW_LEFT) || (ch==VMW_UP) || (ch==VMW_PGUP)) pagenum--; + if (pagenum>4) pagenum=1; + if (pagenum<1) pagenum=4; } } } diff --git a/data/about/register.tb1 b/data/about/register.tb1 index 020df1a..4313a11 100644 Binary files a/data/about/register.tb1 and b/data/about/register.tb1 differ diff --git a/data/level1/moon2.tb1 b/data/level1/moon2.tb1 index 2d393b1..5d17af4 100644 Binary files a/data/level1/moon2.tb1 and b/data/level1/moon2.tb1 differ diff --git a/data/level1/ships.tb1 b/data/level1/ships.tb1 index 8902406..db60542 100644 Binary files a/data/level1/ships.tb1 and b/data/level1/ships.tb1 differ diff --git a/data/level1/tbshapes.tb1 b/data/level1/tbshapes.tb1 index 5276f5b..82a7383 100644 Binary files a/data/level1/tbshapes.tb1 and b/data/level1/tbshapes.tb1 differ diff --git a/data/level1/viewscr.tb1 b/data/level1/viewscr.tb1 index 7d4d01a..fb3f1f1 100644 Binary files a/data/level1/viewscr.tb1 and b/data/level1/viewscr.tb1 differ diff --git a/data/level2/tbaship.tb1 b/data/level2/tbaship.tb1 index f6d2512..1f94d97 100644 Binary files a/data/level2/tbaship.tb1 and b/data/level2/tbaship.tb1 differ diff --git a/data/level2/tbl2ship.tb1 b/data/level2/tbl2ship.tb1 index 2cacedb..99a8faa 100644 Binary files a/data/level2/tbl2ship.tb1 and b/data/level2/tbl2ship.tb1 differ diff --git a/data/level3/tbash.tb1 b/data/level3/tbash.tb1 index 6a1b9fd..2638fab 100644 Binary files a/data/level3/tbash.tb1 and b/data/level3/tbash.tb1 differ diff --git a/data/level3/tbconsol.tb1 b/data/level3/tbconsol.tb1 index f8e0209..59f8e66 100644 Binary files a/data/level3/tbconsol.tb1 and b/data/level3/tbconsol.tb1 differ diff --git a/data/level3/tbl3intr.tb1 b/data/level3/tbl3intr.tb1 index cf2c594..58c0f78 100644 Binary files a/data/level3/tbl3intr.tb1 and b/data/level3/tbl3intr.tb1 differ diff --git a/data/level3/tbpit.tb1 b/data/level3/tbpit.tb1 index ee5f72b..5cc1802 100644 Binary files a/data/level3/tbpit.tb1 and b/data/level3/tbpit.tb1 differ diff --git a/data/level4/tbeerm.tb1 b/data/level4/tbeerm.tb1 index cb0c8e1..1426e90 100644 Binary files a/data/level4/tbeerm.tb1 and b/data/level4/tbeerm.tb1 differ diff --git a/data/story/tbchief.tb1 b/data/story/tbchief.tb1 index 1642ca0..d05b06c 100644 Binary files a/data/story/tbchief.tb1 and b/data/story/tbchief.tb1 differ diff --git a/data/story/tbcobj.tb1 b/data/story/tbcobj.tb1 index b9b7188..f644f97 100644 Binary files a/data/story/tbcobj.tb1 and b/data/story/tbcobj.tb1 differ diff --git a/data/story/tbcrash.tb1 b/data/story/tbcrash.tb1 index df78ab9..7214a6f 100644 Binary files a/data/story/tbcrash.tb1 and b/data/story/tbcrash.tb1 differ diff --git a/data/story/tbgorg.tb1 b/data/story/tbgorg.tb1 index 9c5ca90..ca0f3e8 100644 Binary files a/data/story/tbgorg.tb1 and b/data/story/tbgorg.tb1 differ diff --git a/data/story/tbma1.tb1 b/data/story/tbma1.tb1 index 8fc5c50..dde32e5 100644 Binary files a/data/story/tbma1.tb1 and b/data/story/tbma1.tb1 differ diff --git a/data/story/tbsobj.tb1 b/data/story/tbsobj.tb1 index 2102225..a0e6d3a 100644 Binary files a/data/story/tbsobj.tb1 and b/data/story/tbsobj.tb1 differ diff --git a/data/tbomb1.tb1 b/data/tbomb1.tb1 index a459058..f519798 100644 Binary files a/data/tbomb1.tb1 and b/data/tbomb1.tb1 differ diff --git a/graphic_tools.c b/graphic_tools.c index 7e4afa8..1b23364 100644 --- a/graphic_tools.c +++ b/graphic_tools.c @@ -37,12 +37,16 @@ char *check_for_tb1_directory(tb1_state *game_state,int try_to_create) char ch; struct stat buf; - char *dir_name; vmwFont *tb1_font; vmwVisual *vis; + static int initialized=0; + static char *dir_name; - dir_name=calloc(300,sizeof(char)); /* Hope their home directory path */ - /* is not huge */ + /* Plug up a memory leak */ + if (!initialized) { + dir_name=calloc(BUFSIZ,sizeof(char)); + initialized=1; + } tb1_font=game_state->graph_state->default_font; vis=game_state->virtual_3; diff --git a/sidebar.c b/sidebar.c index e2de7ef..954d03b 100644 --- a/sidebar.c +++ b/sidebar.c @@ -88,8 +88,7 @@ void setupsidebar(tb1_state *game_state,vmwVisual *vaddr2) vmwTextXY(it,250+(8*(8-strlen(it))),11,12,0,1,tb1_font,vaddr2); hiscore=showhiscore(game_state,0,1); - printf("show high done\n"); fflush(stdout); - + vmwTextXY("HI-SCORE",241,21,127,0,0,tb1_font,vaddr2); vmwTextXY("HI-SCORE",242,22,143,0,0,tb1_font,vaddr2); sprintf(it,"%d",hiscore); diff --git a/sound.c b/sound.c index bb3a2fa..7bcb32b 100644 --- a/sound.c +++ b/sound.c @@ -29,10 +29,8 @@ void loadFX(char *path_to_data) { for(i = 0; i < NUM_GAME_FX; i++) { path=tb1_data_file(game_fx_names[i],path_to_data); - if(path) { game_fx[i] = Mix_LoadWAV(path); - free(path); } } } diff --git a/story.c b/story.c index 267a22e..95eb8c3 100644 --- a/story.c +++ b/story.c @@ -44,7 +44,7 @@ void story(tb1_state *game_state) { int i; int xtemp,ytemp; - int thrustcol; + int thrustcol=0; float thrust; char tempch; int cycles,to_clear; @@ -162,7 +162,7 @@ void story(tb1_state *game_state) vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); pauseawhile(5); - vmwTextXY("No? Well watch the screen. ",1,1,15,0,1,tb1_font,game_state->virtual_1); + vmwTextXY("No? Well watch the screen. ",1,1,15,0,1,tb1_font,game_state->virtual_1); vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); pauseawhile(5); @@ -195,6 +195,8 @@ void story(tb1_state *game_state) vmwFlipVirtual(game_state->virtual_1,game_state->virtual_2,320,200); + vmwLoadPalette(game_state->graph_state,thrustcol*4,0,0,250); + vmwPutSprite(barge,141,157,game_state->virtual_1); @@ -232,7 +234,6 @@ void story(tb1_state *game_state) vmwFlipVirtual(game_state->virtual_1,game_state->virtual_2,320,200); vmwPutSprite(barge,141,157,game_state->virtual_1); - thrustcol=0; ytemp=157; to_clear=0; thrust=0; @@ -301,6 +302,7 @@ void story(tb1_state *game_state) game_state->path_to_data),game_state->graph_state); + vmwLoadPalette(game_state->graph_state,thrustcol*4,0,0,250); vmwFlipVirtual(game_state->virtual_2,game_state->virtual_1,320,200); // flipd320(vaddr,vga); vmwPutSprite(barge,97,180,game_state->virtual_1); @@ -345,11 +347,11 @@ void story(tb1_state *game_state) vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); cycles=0; - while ( ((tempch=vmwGetInput())==0) && cycles<12) { + while ( ((tempch=vmwGetInput())==0) && cycles<120) { doflames(game_state); vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); cycles++; - usleep(500000); + usleep(80000); } /****ALIEN MESSAGE*****/ @@ -421,5 +423,17 @@ void story(tb1_state *game_state) vmwTextXY(" ",1,1,9,0,1,tb1_font,game_state->virtual_1); vmwBlitMemToDisplay(game_state->graph_state,game_state->virtual_1); pauseawhile(10); + + /* Free the sprites! End memory leaks! */ + vmwFreeSprite(bigFlame1); + vmwFreeSprite(bigFlame2); + vmwFreeSprite(smallFlame1); + vmwFreeSprite(smallFlame2); + vmwFreeSprite(rent); + vmwFreeSprite(truck1); + vmwFreeSprite(truck2); + vmwFreeSprite(barge); + vmwFreeSprite(explosion1); + vmwFreeSprite(explosion2); } diff --git a/svmwgraph/svmwgraph.h b/svmwgraph/svmwgraph.h index 7e3266a..d43772e 100644 --- a/svmwgraph/svmwgraph.h +++ b/svmwgraph/svmwgraph.h @@ -22,6 +22,17 @@ typedef struct { unsigned char *spritedata; } vmwSprite; +typedef struct { + char ppro_string[8]; + char version[4]; + int xsize; + int ysize; + int num_colors; +} vmwPaintProHeader; + +typedef struct { + char r,g,b; +} vmw24BitPal; typedef struct { int xsize; @@ -30,6 +41,7 @@ typedef struct { int scale; int *palette; int palette_size; + vmw24BitPal *actual_pal; void *output_screen; vmwFont *default_font; } vmwSVMWGraphState; @@ -45,6 +57,7 @@ typedef struct { #define VMW_ERROR_FILE 2 #define VMW_ERROR_SIZE 3 #define VMW_ERROR_MEM 4 +#define VMW_ERROR_INVALID 5 /* Keypress Constants */ #define VMW_BACKSPACE 1024 @@ -92,19 +105,23 @@ void vmwSmallTextXY(char *st,int x,int y,int col,int background,int overwrite, /* From vmw_paintpro.c */ +vmwPaintProHeader *vmwGetPaintProHeader(char *filename); + int vmwLoadPicPacked(int x1,int y1,vmwVisual *target, int LoadPal,int LoadPic,char *FileName, vmwSVMWGraphState *graph_state); int vmwSavePicPacked(int x1,int y1,int xsize,int ysize, - vmwVisual *source,char *FileName); - + vmwVisual *source, + int num_colors, + vmw24BitPal *palette, + char *FileName); /* From vmw_palette.c */ void vmwLoadPalette(vmwSVMWGraphState *state,unsigned char r, unsigned char g,unsigned char b,int color); -void vmwFadeToBlack(vmwVisual *source); -void vmwUnFade(vmwVisual *source); +void vmwFadeToBlack(vmwSVMWGraphState *state,vmwVisual *source,int justLoadPal); +void vmwUnFade(vmwSVMWGraphState *state,vmwVisual *source); /* From vmw_setup.c */ @@ -125,6 +142,7 @@ vmwVisual *vmwSetupVisual(int xsize,int ysize); vmwSprite *vmwGetSprite(int x, int y, int xsize, int ysize,vmwVisual *screen); +void vmwFreeSprite(vmwSprite *sprite); void vmwPutSprite(vmwSprite *sprite,int x,int y, vmwVisual *screen); diff --git a/svmwgraph/vmw_paintpro.c b/svmwgraph/vmw_paintpro.c index dbe6b6b..2304a9b 100644 --- a/svmwgraph/vmw_paintpro.c +++ b/svmwgraph/vmw_paintpro.c @@ -1,9 +1,93 @@ /* 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 /* For FILE I/O */ #include /* For strncmp */ +#include /* for open() */ +#include /* for lseek() */ +#include /* 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 | @@ -21,170 +105,230 @@ int vmwLoadPicPacked(int x1,int y1,vmwVisual *target, /* Loadsapicture if Loadpic=true and returns error} */ { - unsigned char temp1,temp2,temp3; - int errorlev; - int int1,int2,i,x,y; - char buffer[300]; - int lastread=0; - int buffpointer=0; - int picwidth,picheight; - FILE *fff; - char header[10]; - int xsize; - int ysize; - int numcolors; - int col,numacross; + 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 */ - fff=fopen(FileName,"rb"); /* Windows chokes if no "b" */ - if (fff==NULL){ - printf("PPRO error... File \"%s\" not found.\n",FileName); - return 1; + ppro_fd=open(FileName,O_RDONLY); + + if (ppro_fd<0) { + printf("ERROR! File \"%s\" not found!\n",FileName); + return VMW_ERROR_FILE; } - errorlev=fread(buffer,1,300,fff); /* Check to see if its really a Paintpro File */ - for (i=0;i<9;i++) { - header[i]=buffer[i]; - } - header[9]='\0'; - if (strncmp(header,"PAINTPROV",9)) { - printf("PPRO error... %s is NOT a paintpro file!\n",FileName); - return 2; + 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) */ - header[0]=buffer[9]; - header[1]=buffer[10]; - header[2]=buffer[11]; - header[3]='\0'; - if (strncmp(header,"6.0",3)) { - printf("PPRO error... Version %s unsupported, must be >6\n",header); - return 3; - } - - buffpointer=12; - /* Read X and Y sizes */ - temp1=buffer[buffpointer]; - temp2=buffer[buffpointer+1]; - temp3=buffer[buffpointer+2]; - buffpointer+=3; - if (buffpointer>=errorlev) { - printf("PPRO error... Early end of file.\n"); - return 4; - } - - /* Split 48 bits into two 32 bit values */ - xsize=(temp2>>4)+(temp1<<4); - ysize=((temp2-((temp2>>4)<<4))<<16)+temp3; - - temp1=buffer[buffpointer]; - temp2=buffer[buffpointer+1]; - temp3=buffer[buffpointer+2]; - buffpointer+=3; - if (buffpointer>=errorlev) { - printf("PPRO error... Early end of file.\n"); - return 4; + 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; + } } - numcolors=(temp2>>4)+(temp1<<4); - - picwidth=xsize+1; - picheight=ysize+1; /*Load Palette*/ - if (numcolors!=256) printf("%d colors is not supported yet.\n",numcolors); + 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 */ - - for(i=0;i<256;i++) { - if (LoadPal) - vmwLoadPalette(graph_state, - buffer[buffpointer], - buffer[buffpointer+1], - buffer[buffpointer+2],i); - buffpointer+=3; - if (buffpointer>=errorlev) { - if (errorlev==300) { - errorlev=fread(buffer,1,300,fff); - buffpointer=0; - } - else { - lastread=1; - } - } + + if (!LoadPal) { + /* Skip past palette if not loading it */ + lseek(ppro_fd,3*ppro_header->num_colors,SEEK_CUR); + } + else { + for(i=0;inum_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 */ } - if (LoadPal) vmwFlushPalette(graph_state); - x=x1; y=y1; - - while ((!lastread)&&(LoadPic)&&(y=errorlev) { - if (errorlev==300) { - errorlev=fread(buffer,1,300,fff); - buffpointer=0; - } - else lastread=1; + + while (yysize) { + /* 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; } - int1=(temp2>>4)+(temp1<<4); - int2=((temp2-((temp2>>4)<<4))*256)+temp3; + color=THREE_BYTES_INT1(three_bytes[0],three_bytes[1]); + numacross=THREE_BYTES_INT2(three_bytes[1],three_bytes[2]); - /* If greater than 2047, we have two single pixels */ - /* of color int1-2048 and int2-2048 */ - if (int1>2047) { - vmwPutPixel(x,y,int1-2048,target); + /* 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>xsize+x1) { + if (x>=ppro_header->xsize+x1) { x=x1; y++; -// if (y>ysize-1) { -// printf("Blargh 1\n"); y--; -// } } - vmwPutPixel(x,y,int2-2048,target); + vmwPutPixel(x,y,numacross-2048,target); x++; - if (x>xsize+x1){ + if (x>=ppro_header->xsize+x1){ x=x1;y++; -// if (y>ysize) { -// printf("Blargh 2\n"); -// y--; -// } } } else { /* Standard paintpro format */ - col=int1; - numacross=int2; - while ((x+numacross)>(xsize+x1)) { - vmwDrawHLine(x,y,((xsize+x1)-x),col,target); - numacross=numacross-((xsize+1)-x); + /* 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 (y>y1+ysize-1) { - printf("Blrgh 3\n"); + } + + if (numacross!=0) { + if (y>=y1+ppro_header->ysize) { + printf("Trying to draw past end of screen %d\n",y); } - } - if ((numacross!=0) && (yxsize+x-1) numacross--; /* Stupid x overflow */ - vmwDrawHLine(x,y,numacross,col,target); - } + if (numacross > ppro_header->xsize-1) { + printf("X too big?%d\n",numacross); + } + vmwDrawHLine(x,y,numacross,color,target); + } x=x+numacross; } } - - if (fff!=NULL) fclose(fff); + close(ppro_fd); return 0; } int vmwSavePicPacked(int x1,int y1,int xsize,int ysize, - vmwVisual *source,char *FileName) { - return 0; + 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=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; } - - diff --git a/svmwgraph/vmw_palette.c b/svmwgraph/vmw_palette.c index ed298be..f1b6321 100644 --- a/svmwgraph/vmw_palette.c +++ b/svmwgraph/vmw_palette.c @@ -1,12 +1,19 @@ /* Palette handling part of the Super VMW Graphics Library */ #include "svmwgraph.h" +#include /* for printf */ +#include /* for usleep */ void vmwLoadPalette(vmwSVMWGraphState *state,unsigned char r, unsigned char g, unsigned char b,int color) { + + state->actual_pal[color].r=r; + state->actual_pal[color].g=g; + state->actual_pal[color].b=b; + /* 565 color cube */ /* which can be LESS colorful than 8bpp. Imagine that */ @@ -18,16 +25,78 @@ void vmwLoadPalette(vmwSVMWGraphState *state,unsigned char r, } +int faded_pal[256]; +int already_faded=0; + -void vmwFadeToBlack(vmwVisual *source) { -// int temp_pal[256]; - // temp_pal=real_pal - // for (i=0;i<256;i++) { - // temp_pal[i]--; - // vmwBlitMemToDisplay() - // pauseawhile() - // +void vmwFadeToBlack(vmwSVMWGraphState *state, vmwVisual *source, + int justLoadPal) { + + int i,j; + int r[256],g[256],b[256]; + + for (i=0;i<256;i++) faded_pal[i]=state->palette[i]; + + if (justLoadPal) { + already_faded=1; + return; + } + + if (already_faded) printf("Warning! Fading already faded screen!\n"); + + for(i=0;i<256;i++) { + r[i]=(state->palette[i])>>11; + g[i]=(state->palette[i]>>5)&0x3f; + b[i]=(state->palette[i]&0x1f); + } + + for(i=0;i<32;i++) { + for(j=0;j<256;j++) { + r[j]-=2; + if (r[j]<0) r[j]=0; + b[j]-=2; + if (b[j]<0) b[j]=0; + g[j]-=4; /* g has an extra bit */ + if (g[j]<0) g[j]=0; + + state->palette[j]=(r[j]<<11)+(g[j]<<5)+b[j]; + } + vmwFlushPalette(state); + vmwBlitMemToDisplay(state,source); + usleep(10000); + } + already_faded=1; } -void vmwUnFade(vmwVisual *source) { +void vmwUnFade(vmwSVMWGraphState *state,vmwVisual *source) { + + int i,j; + + unsigned char r_max[256],g_max[256],b_max[256], + r[256],g[256],b[256]; + + if (!already_faded) printf("Warning! Unfading random palette!\n"); + + for(i=0;i<256;i++) { + r_max[i]=(faded_pal[i])>>11; + g_max[i]=(faded_pal[i]>>5)&0x3f; + b_max[i]=(faded_pal[i]&0x1f); + r[i]=g[i]=b[i]=0; + } + + for(i=0;i<32;i++) { + for(j=0;j<256;j++) { + r[j]+=2; + if (r[j]>r_max[j]) r[j]=r_max[j]; + b[j]+=2; + if (b[j]>b_max[j]) b[j]=b_max[j]; + g[j]+=4; /* g has an extra bit */ + if (g[j]>g_max[j]) g[j]=g_max[j]; + + state->palette[j]=(r[j]<<11)+(g[j]<<5)+b[j]; + } + vmwFlushPalette(state); + vmwBlitMemToDisplay(state,source); + usleep(10000); + } } diff --git a/svmwgraph/vmw_setup.c b/svmwgraph/vmw_setup.c index 94dde5f..dc11b0f 100644 --- a/svmwgraph/vmw_setup.c +++ b/svmwgraph/vmw_setup.c @@ -44,6 +44,11 @@ vmwSVMWGraphState *vmwSetupSVMWGraph(int display_type,int xsize,int ysize, return NULL; } + if ( (temp_state->actual_pal=calloc(temp_state->palette_size,sizeof(vmw24BitPal)) )==NULL) { + printf("Error allocating actual palette of size %i!\n",temp_state->palette_size); + return NULL; + } + /* Attempt to get desired graphics state */ temp_state->output_screen=vmwSetupGraphics(&temp_state->xsize, diff --git a/svmwgraph/vmw_sprite.c b/svmwgraph/vmw_sprite.c index d603fd0..c03721f 100644 --- a/svmwgraph/vmw_sprite.c +++ b/svmwgraph/vmw_sprite.c @@ -24,6 +24,13 @@ vmwSprite *vmwGetSprite(int x, int y, return temp_sprite; } +void vmwFreeSprite(vmwSprite *sprite) { + + free(sprite->spritedata); + free(sprite); + +} + void vmwPutSprite(vmwSprite *sprite,int x,int y, vmwVisual *screen) { diff --git a/tb1-2.9.0.lsm b/tb1-2.9.9.lsm similarity index 57% rename from tb1-2.9.0.lsm rename to tb1-2.9.9.lsm index 3f0a78b..1523725 100644 --- a/tb1-2.9.0.lsm +++ b/tb1-2.9.9.lsm @@ -1,16 +1,16 @@ Begin3 Title: tb1 -Version: 2.9.0 -Entered-date: 28FEB98 -Description: A really cool arcade game. +Version: 2.9.9 +Entered-date: 23SEP00 +Description: A 2d, sci-fi arcade game. Shoot the aliens, save the world. Keywords: tom bombem alien game arcade ggi Author: weave@eng.umd.edu (Vince Weaver) Maintained-by: weave@eng.umd.edu (Vince Weaver) -Primary-site: sunsite.unc.edu /pub/Linux/games/arcade - 100kB tb1-2.9.0.tar.gz +Primary-site: metalab.unc.edu /pub/Linux/games/arcade + 350kB tb1-2.9.9.tar.gz Alternate-site: http://www.glue.umd.edu/~weave/tb1 Original-site: -Platforms: Any that have gcc and support ggi +Platforms: Linux Copying-policy: GPL End diff --git a/tb1.c b/tb1.c index f008240..fb4e20b 100644 --- a/tb1.c +++ b/tb1.c @@ -1,6 +1,6 @@ /****************************************************************\ \* TOM BOMBEM AND THE INVASION OF THE INANIMATE_OBJECTS */ -/* version 2.9.5 16 September 2000 *\ +/* version 2.9.9 23 September 2000 *\ \* by Vince Weaver weave@eng.umd.edu */ /* *\ \* Originally written in Pascal and x86 assembly for DOS */ @@ -10,7 +10,7 @@ \* This source is released under the GPL */ /****************************************************************/ -#define TB1_VERSION "2.9.7" +#define TB1_VERSION "2.9.9" #include #include /* for calloc */ @@ -36,13 +36,11 @@ int command_line_help(int show_version,char *runas) { if (!show_version) { - printf("Usage: %s [-8bpp] [-double] [-fullscreen] [-nosound] [-readonly]" + printf("Usage: %s [-double] [-fullscreen] [-nosound]" " [-version] [-?]\n\n",runas); - printf(" -8bpp : force to run in 8bpp 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(" -readonly : don't try to write files to disk\n"); printf(" -version : print version\n"); printf(" -? : print this help message\n"); printf("\n"); @@ -51,10 +49,55 @@ int command_line_help(int show_version,char *runas) } +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,x,barpos,time_sec; + int ch,barpos,time_sec; int scale=1,fullscreen=0; FILE *fff; vmwVisual *virtual_1,*virtual_2,*virtual_3; @@ -70,11 +113,11 @@ int main(int argc,char **argv) printf(" http://www.glue.umd.edu/~weave/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; @@ -100,13 +143,9 @@ int main(int argc,char **argv) case 'd': scale=2; break; case 'n': - game_state->sound_enabled=0; + game_state->sound_possible=0; printf(" + Sound totally disabled\n"); break; - case 'r': -// read_only_mode=1; - printf(" + Read Only mode enabled\n"); - break; default : command_line_help(0,argv[0]); printf("Unknown Option: %s\n\n",argv[i]); return 5; @@ -144,24 +183,29 @@ int main(int argc,char **argv) } } printf(" + Found tb1 data in %s\n",game_state->path_to_data); - -/* FIXME : find where writing info out to */ + + /* FIXME -- read in options */ - /* REMNANT OPERATION BOTTLECAP STUFF---> *\ - \* 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 Amy anymore, but Gus */ - /* 3-96 oh well... gave up on Gus finally *\ - \* 5-11-96 Now Marie... what fun life is */ +/* 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 Amy anymore, but Gus *\ +\* 3-96 oh well... gave up on Gus finally */ +/* 5-11-96 Now Marie... *\ +\* 9-22-2000 :( */ + /* Randomize random number generator */ srandom(time(NULL)); printf(" + Seeding random number generator...\n"); - /* Load sounds */ - if (initSound(game_state->path_to_data)<0) game_state->sound_possible=0; - + /* 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)); } @@ -171,20 +215,21 @@ int main(int argc,char **argv) /* Setup Graphics */ if (scale==1) { - - if ( (game_state->graph_state=vmwSetupSVMWGraph(VMW_SDLTARGET, - 320,200, - 0,scale,fullscreen,1))==NULL) { - fprintf(stderr,"ERROR: Couldn't get display set up properly.\n"); - return VMW_ERROR_DISPLAY; + if ( (game_state->graph_state= + vmwSetupSVMWGraph(VMW_SDLTARGET, + 320,200, + 0,scale,fullscreen,1))==NULL) { + fprintf(stderr,"ERROR: Couldn't get display set up properly.\n"); + return VMW_ERROR_DISPLAY; + } } - } - else { - if ( (game_state->graph_state=vmwSetupSVMWGraph(VMW_SDLTARGET, - 640,480, - 0,scale,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(VMW_SDLTARGET, + 640,480, + 0,scale,fullscreen,1))==NULL) { + fprintf(stderr,"ERROR: Couldn't get display set up properly.\n"); + return VMW_ERROR_DISPLAY; } } @@ -194,6 +239,7 @@ int main(int argc,char **argv) 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; @@ -214,88 +260,53 @@ int main(int argc,char **argv) virtual_2=game_state->virtual_2; virtual_3=game_state->virtual_3; tb1_font=game_state->graph_state->default_font; - - 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); + /* The "fancy" opener */ + vmw_opener(game_state,virtual_1); - /* 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,tb1_font,virtual_1); - - if ((game_state->sound_possible) && (game_state->music_enabled)) - playSound(); - - vmwBlitMemToDisplay(game_state->graph_state,virtual_1); - pauseawhile(5); - + /* Load menu music */ if (game_state->sound_possible) { stopSound(); loadSound(tb1_data_file("music/weave1.mod",game_state->path_to_data)); } - - /* Clear the Screen and get ready for the Menu */ - vmwClearScreen(virtual_1,0); + + /* 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 the title screen */ - /* this is a bit of overkill. vmwflip() ? */ + /* 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); - - grapherror=vmwLoadPicPacked(0,0,virtual_2,1,1, tb1_data_file("tbomb1.tb1",game_state->path_to_data), game_state->graph_state); - grapherror=vmwLoadPicPacked(0,0,game_state->virtual_3,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); - vmwBlitMemToDisplay(game_state->graph_state,virtual_1); + vmwUnFade(game_state->graph_state,virtual_1); /* Main Menu Loop */ while (1) { + /* If virtual_3 was over-written, re-load it */ if (reloadpic) { grapherror=vmwLoadPicPacked(0,0,virtual_3,1,1, - tb1_data_file("tbomb1.tb1",game_state->path_to_data), - game_state->graph_state); -// grapherror=vmwLoadPicPacked(0,0,virtual_1,1,0, -// tb1_data_file("tbomb1.tb1",game_state->path_to_data)); - + tb1_data_file("tbomb1.tb1", + game_state->path_to_data), + game_state->graph_state); reloadpic=0; } vmwFlipVirtual(virtual_1,virtual_3,320,200); - if ((game_state->sound_possible) &&(game_state->music_enabled)) + + /* Play the menu-music */ + if ((game_state->sound_possible) && (game_state->music_enabled)) playSound(); vmwBlitMemToDisplay(game_state->graph_state,virtual_1); - while (!vmwGetInput()) usleep(300); + /* Don't show the menu until keypress/15s */ + pauseawhile(15); barpos=0; vmwTextXY("F1 HELP",0,190,9,7,0,tb1_font,virtual_1); @@ -327,7 +338,7 @@ int main(int argc,char **argv) time_sec=time_info.tv_sec; while( ((ch=vmwGetInput())==0)) { - usleep(10); + usleep(30); gettimeofday(&time_info,&dontcare); if (time_info.tv_sec-time_sec>40) { if (game_state->sound_possible) stopSound(); @@ -335,8 +346,7 @@ int main(int argc,char **argv) ch=VMW_ENTER; barpos=9; reloadpic=1; - gettimeofday(&time_info,&dontcare); - time_sec=time_info.tv_sec; + break; } } diff --git a/tblib.c b/tblib.c index f7883d0..b756dd8 100644 --- a/tblib.c +++ b/tblib.c @@ -32,11 +32,17 @@ int collision(int x1,int y1,int xsize,int ysize, return 0; } + + /* Now memory-leak friendly */ char *tb1_data_file(char *name,char *path) -{ +{ + static int initialized=0; + static char *tempst; - char tempst[BUFSIZ]; - - sprintf(tempst,"%s/%s",path,name); - return strdup(tempst); + if (!initialized) { + tempst=(char *)calloc(BUFSIZ,sizeof(char)); + initialized=1; + } + snprintf(tempst,BUFSIZ,"%s/%s",path,name); + return tempst; } diff --git a/tools/Makefile b/tools/Makefile new file mode 100644 index 0000000..cc3f1f5 --- /dev/null +++ b/tools/Makefile @@ -0,0 +1,18 @@ + + +INCLUDE= -O2 -Wall -I/usr/local/include/SDL -I/usr/local/include -I.. +LIBS= -lSDL -L/usr/X11R6/lib -lX11 -lpthread + +all: ppro_view + +ppro_view: ppro_view.o ../svmwgraph/libsvmwgraph.a + gcc -o ppro_view ppro_view.o ../svmwgraph/libsvmwgraph.a $(LIBS) + +../svmwgraph/libsvmwgraph.a: + cd ../svmwgraph && make + +ppro_view.o: ppro_view.c + gcc -c ppro_view.c $(INCLUDE) + +clean: + rm -f ppro_view *.o *~ diff --git a/tools/ppro_view.c b/tools/ppro_view.c new file mode 100644 index 0000000..10a90a4 --- /dev/null +++ b/tools/ppro_view.c @@ -0,0 +1,89 @@ +/* Views paintpro files */ +/* Also will re-save them */ + +#include +#include "svmwgraph/svmwgraph.h" +#include /* for strdup */ +#include /* for usleep() */ + +int main(int argc,char **argv) +{ + int grapherror; + int scale=1,fullscreen=0; + vmwVisual *virtual_1; + vmwPaintProHeader *ppro_header; + char *filename; + char ch=0; + char save_string[BUFSIZ]; + + vmwSVMWGraphState *graph_state; + + if (argc<2) { + printf("\nUsage: %s filename\n\n",argv[0]); + return -1; + } + + filename=strdup(argv[1]); + + ppro_header=vmwGetPaintProHeader(filename); + + printf("\nLoading file: %s\n",filename); + if (strncmp(ppro_header->ppro_string,"PAINTPRO",8)) { + printf("ERROR! Not in paintpro format!\n"); + return 0; + } + if (strncmp(ppro_header->version,"V6.",3)) { + printf("ERROR! Not a version 6.x file!\n"); + return 0; + } + printf(" + Verified PaintPro v%c.%c file.\n",ppro_header->version[1], + ppro_header->version[3]); + printf(" + Picture is %ix%i with %i colors.\n", + ppro_header->xsize,ppro_header->ysize,ppro_header->num_colors); + + + if (ppro_header->version[3]=='0') { + /* broken ppro 6.0 files sometimes were saved as 319x199 */ + ppro_header->xsize=320; + ppro_header->ysize=205; + } + + /* Setup Graphics */ + + if ( (graph_state=vmwSetupSVMWGraph(VMW_SDLTARGET, + ppro_header->xsize, + ppro_header->ysize, + 0,scale,fullscreen,1))==NULL) { + fprintf(stderr,"ERROR: Couldn't get display set up properly.\n"); + return VMW_ERROR_DISPLAY; + } + + /* Allocate Virtual screen */ + if ((virtual_1=vmwSetupVisual(ppro_header->xsize, + ppro_header->ysize))==NULL) { + fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 1!\n"); + return VMW_ERROR_MEM; + } + + /* Load palette */ + grapherror=vmwLoadPicPacked(0,0,virtual_1,1,1, + filename, + graph_state); + + vmwBlitMemToDisplay(graph_state,virtual_1); + + while ((ch!='Q') && (ch!='q') && (ch!=VMW_ESCAPE)) { + while ( (ch=vmwGetInput())==0) usleep(100); + + if (ch=='s') { + printf("\nEnter file name to save as:\n"); + scanf("%s",save_string); + vmwSavePicPacked(0,0,320,200,virtual_1, + graph_state->palette_size, + graph_state->actual_pal,save_string); + + } + } + + return 0; +} diff --git a/tools/view_ppro.c b/tools/view_ppro.c deleted file mode 100644 index 8cff7ab..0000000 --- a/tools/view_ppro.c +++ /dev/null @@ -1,180 +0,0 @@ -#include -#include -#include -#include -#include "svmwgrap.h" - -ggi_visual_t vis,vaddr; -uint white; -ggi_color eight_bit_pal[256]; -ggi_pixel tb1_pal[256]; -ggi_directbuffer_t dbuf; -ggi_directbuffer_t dbuf2; -ggi_pixellinearbuffer *plb = NULL; -ggi_pixellinearbuffer *plb2= NULL; -char *dest,*src; - -int ch; - -int get_input() { - - int evmask; - ggi_event ev; - struct timeval t={0,0}; - - evmask=emKeyPress|emKeyRelease|emPointer; - - while (ggiEventPoll(vis,evmask,&t)) - { - /*ggiEventPoll(vis,evmask,NULL);*/ - - do { - ggiEventRead(vis,&ev,evmask); - } while(! ( (1 << ev.any.type) & evmask ) ); - - if (ev.any.type==evKeyPress) { - switch(KTYP(U(ev.key.sym))) { - case KT_LATIN: - case KT_LETTER: - switch(KVAL(U(ev.key.sym))) { - case ' ': /* space */ - printf("Space\n");exit (1); break; - case '\x1b': /* esc */ - printf("escape\n");break; - case ',': - printf("Comma\n");break; - case '.': - printf("Period\n");break; - case '0':break; - case '1':break; - case '2':break; - case '3':break; - case '4':break; - case '5':break; - case '6':break; - case '7':break; - case '8':break; - case '9':printf("9\n");break; - default: printf("latin sym=%4x code=%4x (%c)\n",ev.key.sym,ev.key.code,KVAL(U(ev.key.sym)));break; - } - break; - default: - switch(U(ev.key.sym)) { - case K_UP: /* CrSr up */ - case K_P8: /* Keypad 8 */ - printf("Up\n");break; - case K_DOWN: /* CrSr down */ - case K_P2: /* Keypad 2 */ - printf("Down\n");break; - case K_RIGHT: /* CrSr right */ - case K_P6: /* CrSr right */ - printf("Right\n");break; - case K_LEFT: /* CrSr left */ - case K_P4: /* CrSr left */ - printf("Left\n");break; - case K_ENTER: /* enter */ - printf("Enter\n");break; - case K_P9: - case K_P7: - break; - case K_P3: - case K_P1: - break; - default: printf("sym=%4x code=%4x\n",ev.key.sym,ev.key.code);break; - } - } - } - else if (ev.any.type==evKeyRelease){ - switch(KTYP(U(ev.key.sym))) { - case KT_LATIN: - case KT_LETTER: - switch(KVAL(U(ev.key.sym))) { - case ' ': /* space */ - printf("Sp2\n");break; - case '\x1b': /* esc */ - printf("Escape2\n");break; - case ',': - case '.': - break; - case '0':break; - case '1':break; - case '2':break; - case '3':break; - case '4':break; - case '5':break; - case '6':break; - case '7':break; - case '8':break; - case '9':break; - } - break; - default: - switch(U(ev.key.sym)) { - case K_UP: /* CrSr up */ - case K_P8: /* Keypad 8 */ - case K_DOWN: /* CrSr down */ - case K_P2: /* Keypad 2 */ - printf("What is this?\n");break; - case K_RIGHT: /* CrSr right */ - case K_P6: /* CrSr right */ - case K_LEFT: /* CrSr left */ - case K_P4: /* CrSr left */ - printf("Hmmmmmmm\n");;break; - case K_ENTER: /* enter */ - printf("Boom\n");break; - case K_P9: - case K_P7: - case K_P3: - case K_P1: - break; - } - } - - } - - } - return 4; - } - - - - - - -int setup_graphics() -{ - int err; - - ggiInit(); - - vis=ggiOpen(NULL); - - err=ggiSetGraphMode(vis,320,200,320,200,GT_8BIT); - - if (err) { - printf("Problem opening 320x200x8 vis\n"); - return 2; - } - - printf("GGI Graphics Initialization OK...\n"); - return 0; -} - - -int main(int argc,char **argv) -{ - - if(argc!=2) - printf("\n\nUsage: %s filename\n\n",argv[0]); - else { - setup_graphics(); - GGILoadPicPacked(0,0,vis,1,1,argv[1], - (ggi_color *)&eight_bit_pal, - (ggi_pixel *)&tb1_pal,16); - - ggiFlush(vis); - sleep(5); - while( ((ch=get_input())!=0)); - while( ((ch=get_input())==0)) usleep(30); - } -}