summaryrefslogtreecommitdiff
path: root/jeu-test/lemmings_level_designer_source/lem2tap.c
diff options
context:
space:
mode:
Diffstat (limited to 'jeu-test/lemmings_level_designer_source/lem2tap.c')
-rw-r--r--jeu-test/lemmings_level_designer_source/lem2tap.c234
1 files changed, 0 insertions, 234 deletions
diff --git a/jeu-test/lemmings_level_designer_source/lem2tap.c b/jeu-test/lemmings_level_designer_source/lem2tap.c
deleted file mode 100644
index 68c858e..0000000
--- a/jeu-test/lemmings_level_designer_source/lem2tap.c
+++ /dev/null
@@ -1,234 +0,0 @@
-/* LEM2TAP.C: for converting a .LEM file and a .BMP file to a .TAP
- file for use with the Spectrum version of Lemmings
- Copyright (c) 1997,9 Philip Kendall
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- Author contact information:
-
- E-mail: pak21@cam.ac.uk (until at least June 2002)
- Postal address: 15 Crescent Road, Wokingham, Berks, RG40 2DB, England
-
-*/
-
-#include <stdio.h> /* standard I/O routines */
-#include <stdlib.h> /* various standard routines */
-#include <string.h> /* string handling routines */
-
-#define BufLen 1024
-#define NameLen 32
-#define SkillNum 8
-#define HazardNum 10
-#define FNameLen 256
-#define BMPLen 8192
-#define LevelLen 8405
-
-int ReadBMP(char *FName,char *BMPData);
-void ReadLine(char *Buffer,FILE *f);
-unsigned int ReadInt(FILE *f);
-unsigned long ReadLong(FILE *f);
-
-int main(int argc, char** argv)
-{FILE *f;
- char Buffer[BufLen],Name[NameLen+1],FName[FNameLen],*BMPData,*LevelData,*ptr;
- unsigned Level,Rating,Number,Save,Rate,Time,Skills[SkillNum],StartX,StartY,
- HomeX,HomeY,Colour,Hazard[HazardNum],HazardX[HazardNum],
- HazardY[HazardNum],i,j;
-
- if(argc<3)
- {fprintf(stderr,"Usage: lem2tap filename.lem filename.tap\n"); return 2;}
-
- f=fopen(argv[1],"rt");
- if(ferror(f))
- {fprintf(stderr,"Error opening %s for input\n",argv[1]); return 1;}
-
- ReadLine(Buffer,f); sscanf(Buffer,"%u,%u",&Level,&Rating);
- ReadLine(Buffer,f); sscanf(Buffer,"%u,%u",&Number,&Save);
- ReadLine(Buffer,f); sscanf(Buffer,"%u",&Rate);
- ReadLine(Buffer,f); sscanf(Buffer,"%u",&Time);
- ReadLine(Buffer,f);
- sscanf(Buffer,"%u,%u,%u,%u,%u,%u,%u,%u",&Skills[0],&Skills[1],&Skills[2],
- &Skills[3],&Skills[4],&Skills[5],&Skills[6],&Skills[7]);
- memset(Buffer,' ',NameLen); /* Fill Buffer with spaces */
- ReadLine(Buffer,f); strncpy(Name,Buffer,NameLen); Name[NameLen]='\0';
- ReadLine(Buffer,f);
- sscanf(Buffer,"%u,%u,%u,%u",&StartX,&StartY,&HomeX,&HomeY);
- ReadLine(Buffer,f); sscanf(Buffer,"%u",&Colour);
- for(i=0;i<HazardNum;i++)
- {ReadLine(Buffer,f);
- sscanf(Buffer,"%u,%u,%u",&Hazard[i],&HazardX[i],&HazardY[i]);
- }
- ReadLine(Buffer,f); sscanf(Buffer,"%s",FName);
-
- fclose(f);
-
- BMPData=(char*)malloc(BMPLen);
- if(!BMPData)
- {fprintf(stderr,"Error allocating memory for BMPData\n"); return 3;}
-
- if(ReadBMP(FName,BMPData)) {free(BMPData); return 6;}
-
- LevelData=(char*)malloc(LevelLen);
- if(!LevelData)
- {fprintf(stderr,"Error allocating memory for LevelData\n");
- free(BMPData); return 5;
- }
-
- f=fopen(argv[2],"ab");
- if(ferror(f))
- {fprintf(stderr,"Error opening %s for output\n",argv[2]);
- free(BMPData); free(LevelData); return 4;
- }
-
- fputc(3,f); fputc(0,f); /* Length of the header */
- fputc(0,f); /* Header ID byte */
- fputc(Level,f); /* Level number */
- fputc(Level,f); /* Checksum */
-
- ptr=LevelData;
- *ptr++=Level; /* Level number */
- *ptr++=Number; /* Number of lemmings */
- *ptr++=Rate; /* Initial/min release rate */
- *ptr++=StartX%0x100; *ptr++=StartX/0x100;
- *ptr++=StartY; /* Trapdoor position */
- *ptr++=(Time-1); /* (Time available/min)-1 */
- for(i=0;i<SkillNum;i++) *ptr++=Skills[i]; /* Skills available */
- *ptr++=Colour; /* Level colours */
- *ptr++=Save; /* Number to be saved */
- *ptr++=HomeX%0x100; *ptr++=HomeX/0x100;
- *ptr++=HomeY; /* Home position */
- *ptr++=Rating; /* Level rating */
- for(i=0;i<NameLen;i++) *ptr++=Name[i]; /* Level name */
- for(i=0;i<HazardNum;i++) /* For each hazard: */
- {*ptr++=Hazard[i]; /* Hazard type */
- *ptr++=HazardX[i]%0x100; *ptr++=HazardX[i]/0x100;
- *ptr++=HazardY[i]; /* and position */
- }
- for(i=0;i<120;i++) *ptr++='\0'; /* blank space */
-
- /* finally, write out the graphics -- remember that the .BMP format has the
- origin at the lower left corner, but we need the origin at the upper left
- */
- for(i=0;i<128;i++)
- for(j=0;j<(512/8);j++)
- *ptr++=BMPData[((127-i)*(512/8))+j];
-
- /* Write out the prelims */
- fputc((LevelLen+2)%0x100,f); fputc((LevelLen+2)/0x100,f); /* Length */
- fputc(0xff,f); /* Datablock ID byte */
-
- /* Calculate the checksum and write the level data out */
- j=0xff; for(i=0;i<LevelLen;i++)
- {j^=LevelData[i]; fputc(LevelData[i],f);}
-
- /* Finally, write out the checksum */
- fputc(j,f);
-
- /* Close the file */
- fclose(f);
-
- /* Release memory */
- free(BMPData); free(LevelData);
-
- /* and go home :-) */
- return 0;
-
-}
-
-int ReadBMP(char *FName,char *BMPData)
-{FILE *f; unsigned i; unsigned long l;
- f=fopen(FName,"rb"); if(ferror(f))
- {fprintf(stderr,"Unable to open %s for input\n",FName); return 1;}
-
- i=ReadInt(f);
- if( i != 'B' + 'M'*0x100 )
- {fprintf(stderr,"Error: ID bytes are not \"BM\"\n");
- fclose(f); return 2;
- }
- l=ReadLong(f);
- if(l!=0x203e)
- {fprintf(stderr,"Error: File size stored in %s is incorrect\n"
- "Expected: 203eh; Found: %lxh\n",FName,l);
- fclose(f); return 3;
- }
- l=ReadLong(f);
- if(l) fprintf(stderr,"Warning: reserved bytes are non-zero\n");
- l=ReadLong(f);
- if(l!=0x3e)
- {fprintf(stderr,"Error: Bitmap offset is incorrect\n"
- "Expected: 3eh; Found: %lxh\n",l); fclose(f); return 4;}
- l=ReadLong(f);
- if(l!=40)
- {fprintf(stderr,"Error: Size of the bitmap information is wrong\n"
- "Expected: 40; Found: %lu\n",l); fclose(f); return 5;}
- l=ReadLong(f);
- if(l!=0x200)
- {fprintf(stderr,"Error: Bitmap width is wrong\n"
- "Expected: 0x200; Found: %lxh\n",l);
- fclose(f); return 6;
- }
- l=ReadLong(f);
- if(l!=0x80)
- {fprintf(stderr,"Error: Bitmap height is wrong\n"
- "Expected: 0x80; Found: %lxh\n",l);
- fclose(f); return 7;
- }
- i=ReadInt(f);
- if(i!=1)
- {fprintf(stderr,"Error: Planes per pixel is wrong\n"
- "Expected: 1; Found: %u\n",i); fclose(f); return 8;}
- i=ReadInt(f);
- if(i!=1)
- {fprintf(stderr,"Error: Bits per pixel is wrong\n"
- "Expected: 1; Found: %u\n",i); fclose(f); return 9;}
- l=ReadLong(f);
- if(l)
- {fprintf(stderr,"Sorry -- Can't handle compressed images!\n");
- fclose(f); return 10;
- }
- l=ReadLong(f);
- if(l!=0x10000)
- {fprintf(stderr,"Error: Number of pixels in image is wrong\n"
- "Expected: 0x10000; Found: %lxh\n",l);
- fclose(f); return 11;
- }
- fseek(f,8,SEEK_CUR); /* Skip pixels per metre */
- l=ReadLong(f);
- if(l!=2)
- {fprintf(stderr,"Error: Number of colours used is wrong\n"
- "Expected: 2; Found: %u\n",l); fclose(f); return 12;}
- l=ReadLong(f);
- if(l!=2)
- {fprintf(stderr,"Error: Number of important colours is wrong\n"
- "Expected: 2; Found: %u\n",l); fclose(f); return 13;}
- fseek(f,8,SEEK_CUR); /* Skip colours */
- fread(BMPData,BMPLen,1,f); /* Finally, actually read the data... */
-
- fclose(f);
-
- return 0;
-}
-
-void ReadLine(char *Buffer,FILE *f)
-{char *ptr=Buffer-1;
- while( !ferror(f) && !feof(f) )
- {*(++ptr)=fgetc(f); if(*ptr=='\n') break;}
- *ptr='\0';
-}
-
-unsigned ReadInt(FILE *f) {return fgetc(f)+fgetc(f)*0x100;}
-
-unsigned long ReadLong(FILE *f)
-{return fgetc(f)+fgetc(f)*0x100+fgetc(f)*0x10000+fgetc(f)*0x1000000;}