git » fp-git.git » commit 3c8ab49

o Added full bitmap import feature

author ecalot
2003-10-17 13:52:52 UTC
committer ecalot
2003-10-17 13:52:52 UTC
parent 2560bbca6d9ada7e6f2820382039a9835952285e

o Added full bitmap import feature
o Solved palette import bug
o Some files were made ANSI

PR/compile.c +31 -3
PR/doc/readme.coders.txt +37 -2
PR/doc/readme.txt +4 -81
PR/extract.c +30 -18
PR/parser.c +2 -1
PR/pg.c +60 -42
PR/pr.c +51 -25
PR/pr.exe +0 -0
PR/pr.obj +0 -0
PR/resources.txt +218 -252
PR/src/lib/formats/Attic/bmp.c +28 -58
PR/src/lib/formats/Attic/pal.c +10 -8
PR/src/lib/formats/pal.h +1 -1
PR/tasks.c +16 -13

diff --git a/PR/compile.c b/PR/compile.c
index 9ae666a..884e3a7 100644
--- a/PR/compile.c
+++ b/PR/compile.c
@@ -23,12 +23,15 @@ void mAddFileToDatFile(FILE* fp, char* data, int size) {
 	//calculates the checksum of a file
 	//unsigned char sndHeader[]={0,2};
 	unsigned char checksum=0;
-	for (int k=0;k<size;k++) checksum+=data[k];
+	int k;
+	for (k=0;k<size;k++) checksum+=data[k];
 	checksum=~checksum;
-
+printf("llega X1\n");
 	//writes the header and the midi sound
 	fwrite(&checksum,1,1,fp);
 	fwrite(data,size,1,fp);
+printf("llega X2\n");
+
 }
 
 void mSetEndFile(FILE* fp,int sizeOfIndex) {
@@ -74,7 +77,10 @@ int mCreateIndexInDatFile(FILE* fp, tResource* r[], char* vUpperFile) {
 void mAddCompiledFileToDatFile(FILE* fp,unsigned char* data, tResource *res) {
 	switch ((*res).type) {
 		case 2: //compile bitmap
-			mFormatCompileBmp(data,fp,res);
+			//printf("llega 1\n");
+			if (!mFormatCompileBmp(data,fp,res)) {
+				printf("Error!!\n");
+			}
 			break;
 		case 3: //compile wave
 			mFormatCompileWav(data,fp,res);
@@ -103,6 +109,18 @@ void mAddCompiledFileToDatFile(FILE* fp,unsigned char* data, tResource *res) {
 /***************************************************************\
 |                    M A I N   F U N C T I O N                  |
 \***************************************************************/
+//TODO: delete this function
+char mSaveFile(char* vFile,unsigned char *d, int s) {
+	FILE *fp;
+
+	if ((fp=fopen(vFile,"wb"))==NULL) {
+		return 0;
+	} else {
+		fwrite (d,s,1,fp);
+		fclose(fp);
+		return 1;
+	}
+}
 
 /*
 	Return values:
@@ -135,6 +153,16 @@ int compile(char* vFiledat, char* vDirExt, tResource* r[], char opt) {
 				if ((*r[i]).size=mLoadFileArray(vFileext,&data)) {
 					(*r[i]).offset=ftell(fp);
 					mAddCompiledFileToDatFile(fp,data,r[i]);
+
+
+						//char sss[300];
+						//sprintf(sss,"bmp%05d.raw",i);
+/*if ((r[i]->type==2)&&(r[i]->size>10)) {
+printf("size: %d %02x %02x %02x %02x %02x %02x %02x\n",r[i]->size,data[0],data[1],data[2],data[3],data[4],data[5],data[6]);
+}*/
+					//mSaveFile(sss,data,r[i]->size);
+
+
 					free(data);
 				} else {
 					ok++;
diff --git a/PR/doc/readme.coders.txt b/PR/doc/readme.coders.txt
index 00275f2..c96b68b 100644
--- a/PR/doc/readme.coders.txt
+++ b/PR/doc/readme.coders.txt
@@ -1,6 +1,7 @@
-Princed Resources Handler V0.5 beta
+Princed Resources Handler V0.6 beta
 (c) Copyright 2003 - Princed Development Team
 http://www.princed.com.ar
+This program is open source under the GNU General Public License terms
 
 1) Unix-based OS compiling:
 
@@ -29,4 +30,38 @@ Valid options:
 
 2) Dos/Win32 Console compiling
 
-LCC will work
\ No newline at end of file
+LCC will work
+
+3) CVS download
+
+Anonymous CVS access to SourceForge.net will work. Just type:
+
+ cvs -d:pserver:anonymous@cvs.princed.com.ar:/cvsroot/princed login
+Hit enter when prompted for password
+ cvs -d:pserver:anonymous@cvs.princed.com.ar:/cvsroot/princed co PR
+
+Sample:
+
+-shell-2.05b$ cvs -d:pserver:anonymous@cvs.princed.com.ar:/cvsroot/princed login
+Logging in to :pserver:anonymous@cvs.princed.com.ar:2401/cvsroot/princed
+CVS password:
+-shell-2.05b$ cvs -d:pserver:anonymous@cvs.princed.com.ar:/cvsroot/princed co PR
+cvs server: Updating PR
+U PR/compile.bat
+(..)
+U PR/zip/pr06.zip
+U PR/zip/prlib.zip
+U PR/zip/prvbdll.zip
+-shell-2.05b$
+
+4) Need assistanse?
+ Just ask here http://sourceforge.net/tracker/?func=add&group_id=91915&atid=598846
+
+5) Bug reporting?
+ http://sourceforge.net/tracker/?func=add&group_id=91915&atid=598845
+
+6) Feature requests?
+ http://sourceforge.net/tracker/?func=add&group_id=91915&atid=598848
+
+7) SourceForge project home page
+ http://project.princed.com.ar
diff --git a/PR/doc/readme.txt b/PR/doc/readme.txt
index e85ed8e..2cd1af1 100644
--- a/PR/doc/readme.txt
+++ b/PR/doc/readme.txt
@@ -1,6 +1,7 @@
 Princed Resources Editor V0.6 beta
 (c) Copyright 2003 - Princed Development Team
 http://www.princed.com.ar
+This program is open source under the GNU General Public License terms
 
 Please read this readme file throughly before starting to use Princed Resource Editor.
 
@@ -61,7 +62,7 @@ Type 06:
  Recommended editor: Paint Shop Pro.
 
 2) Bugs:
- As Princed Resource Editor is still an Alpha version, bugs are very common, 
+ As Princed Resource Editor Releases are still unestable versions, bugs are very common, 
  and we are attempting to fix as many as possible.  After that we will release 
  the beta version and after that the final version.
  This program was published because lots of people asked for it in this
@@ -124,87 +125,9 @@ Type 06:
  Note: c:\princed\pr\compiled must exist.
  
 4) New versions
- It's strongly recommended that you download a newer stable version of this   program as soon as it comes available in the official url (http:://www.princed.com.ar)
+ It's strongly recommended that you download a newer stable version of this  program as soon as it comes available in the official url (http://www.princed.com.ar)
 
-5) ToDo List
- i)   Fix bug in palette compiling
- ii)  Improve support of bitmap compiling
- iii) Codify the compression algorithms (B1 to B4) to optimize the bitmap compiled dat files
- iv)  Move PG to bmp.c (only when all bitmaps are Ok)
- v)   Add full pop2 support
- vi)  Add resources tree in resources.txt with the following format:
-  [Prince of Persia 1]
-   [Sounds]
-    [Wave]
-     DIGISND1.DAT 10058 Door close
-    [Midi]
-    [Speaker]
-   [Images]
-    [Animations]
-     [Jaffar walking to princess] Palette: TITLE.DAT 11022
-      TITLE.DAT 11023 Frame 1
-      TITLE.DAT 11024 Frame 2
-      TITLE.DAT 11025 Frame 3
-      TITLE.DAT 11026 Frame 4     
-    [Titles] Palette: TITLE.DAT 200
-     TITLE.DAT 203 Outside palace presentation
-    [Eviornment]
-     [Dungeon]
-     [Palace]
-    [Others]
-  [Prince of Persia 2]
-
-5.5) Versions:
-  PR v0.6 beta: unestable, added ii, iv, first full working version
-  PR v0.7:      tested & stable
-  PR v0.8 beta: added i,iii,vi
-  PR v0.9:      tested and stable
-  PR v1.0:      First optimized & stable version for win32 and linux
-
-6) Change Log
- * PG
-  - Added support to export .bmp files
-  - Added bitmap decompression
-  - Added static palette extraction
- * PS
-  - Added support to .mid files
-  - Added support to indexed dat files
- * PR 0.1 Alpha
-  - Merged PS and PG into one extractor.
-  - Added resource.txt parser.
-  - Solved several bugs.
-  - Coded type header verification
-  - Added dynamic palette extraction
-  - Added support to export JASC palette for .pal files.
-  - Added support to .wav files.
- * PR 0.2 Alpha
-  - Added support to import .bmp files
-  - Source files were abstracted
-  - Added classifing dat type feature
-  - Implemented CGI output support for UNIX versions
- * PR 0.3 beta
-  - Added pr.dll compiling
-  - Added modifiers -x[rnu] -c[r]
-  - Solved bugs in bitmap format
-  - Solved segmentation fault in title.dat
-  - Images bigger than 256 pixels lenght or width now are recognized
-  - Improved decompression algorithm in bigger images
-  - Optimized bitmap handling
-  - Bitmaps aren't upside down anymore 
- * PR 0.4 beta
-  - Fixed a memory bug since v0.3
-  - Pop2 DAT files detected (file type 11)
- * PR 0.5 beta
-  - Optimized bmp saving algorithm
-  - Abstracted format handling
-  - Solved and optimized decompression for big images
-  - Some Pop2 graphics are extracted (palettes aren't supported yet)
- * PR 0.6 beta
-  - Optimized PG algorithms and reserved memory sizes
-  - Completed and tested bmp reading algorithm
- 
-
-7) Platforms
+5) Platforms
  Binary files are compiled in DOS/Win32 console (v0.5) and in Unix/Alpha versions (v0.5). The DOS executable is pr.exe and the Unix executable is prunix. The Unix version will be used to automate the classification of server uploaded files in our unix-based web server.
 
 
diff --git a/PR/extract.c b/PR/extract.c
index 23e2c2e..4be245a 100644
--- a/PR/extract.c
+++ b/PR/extract.c
@@ -30,6 +30,21 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) {
 		unsigned long int indexOffset;
 		unsigned short int indexSize,numberOfItems;
 		unsigned char* index;
+		int                ofk=0;
+		int k;
+
+		//if header ok, new variables
+		unsigned short int id;
+		unsigned long int  size,offset;
+		unsigned char*     data;
+		FILE*              target;
+		char               type=0;
+		char               recordSize;
+		char               aux[260];
+		tImage             image; //this is used to make a persistent palette
+		char               isntImageSet=1;
+	//printf("kkkkkkkkkkk: %x\n",task);
+
 		//verify dat format
 		ok    = fread(&indexOffset,4,1,fp);
 		//ok=ok&& fread(&val,2,1,fp);
@@ -38,13 +53,13 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) {
 		ok=ok&& !fseek(fp,indexOffset,SEEK_SET);
 		ok=ok&& fread(&numberOfItems,2,1,fp);
 		pop1=((numberOfItems*8+2)==indexSize);
-		int                ofk=0;
 
 		if (!pop1) { //verify if pop2
 			ofk=numberOfItems*6+2+(numberOfItems-2)*13;
 			numberOfItems=((indexSize-6-(numberOfItems*6)-((numberOfItems-2)*13))/11);
 			//printf("verificando pop2: numberOfItems=%d, indexSize=%d\r\n",numberOfItems,indexSize);
 		}
+		recordSize=pop1?8:11;
 		if (!ok) {
 			fclose(fp);
 			return -3; //this is not a valid prince dat file
@@ -55,39 +70,33 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) {
 		}
 		ok=fread(index,indexSize-2,1,fp);
 
-		//if header ok, new variables
-		unsigned short int id;
-		unsigned long int  size,offset;
-		unsigned char*     data;
-		FILE*              target;
-		char               type=0;
-		char               recordSize=pop1?8:11;
-		char               aux[260];
-		tImage             image; //this is used to make a persistent palette
-		char               isntImageSet=1;
 		//parse folder and take dat filename in caps
 		getUpperFolder(aux,vFiledat);
 
 		//main loop
-		for (int k=0;ok&&(k<numberOfItems);k++) {
+		for (k=0;ok&&(k<numberOfItems);k++) {
 			//for each archived file
 			id=index[ofk+k*recordSize]+256*index[ofk+k*recordSize+1];
+			//printf("jajaK %d %d %d %d\n",index[ofk+k*recordSize+2],index[ofk+k*recordSize+3],index[ofk+k*recordSize+4],index[ofk+k*recordSize+5]);
 			offset=index[ofk+k*recordSize+2]+256*index[ofk+k*recordSize+3]+256*256*index[ofk+k*recordSize+4]+256*256*256*index[ofk+k*recordSize+5];
 			size=index[ofk+k*recordSize+6]+256*index[ofk+k*recordSize+7]+1;
 			if (!pop1) {
-//				printf("jajaA %d\r\n",ok);
+				printf("jajaA %d\r\n",ok);
 //printf("verificando pop2: %d, k=%d, record size=%d\r\n",size,k,recordSize);
 				ok=ok&&(index[ofk+k*recordSize+8]==0x40)&&(!index[ofk+k*recordSize+9])&&(!index[ofk+k*recordSize+10]);
 //				printf("jajaB %d\r\n",ok);
 			}
 			ok=ok&&((data=getMemory(size))!=NULL);
-//				printf("jajaB %d\r\n",ok);
+//				printf("jajaC %d offset=%d\r\n",ok,offset);
 			ok=ok&&(!fseek(fp,offset,SEEK_SET));
-//				printf("jajaB %d\r\n",ok);
+//				printf("jajaD %d\r\n",ok);
 			ok=ok&&fread(data,size,1,fp);
-//				printf("jajaB %d\r\n",ok);
+//				printf("jajaE %d\r\n",ok);
 			if (!ok) return -3;
 
+			//For the moment rebuilt option will be mandatory:
+			task|=2;
+
 			//If rebuild option has been chosen, destroy previous declaration
 			if ((r[id]!=NULL)&&(task&2)) {
 				if ((*(r[id])).coms!=NULL) free ((*(r[id])).coms);
@@ -104,14 +113,19 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) {
 				(*(r[id])).desc=NULL;
 				(*(r[id])).coms=NULL;
 				(*(r[id])).type=verifyHeader(data,(unsigned short int)size);
+				//printf("%d: %d %d %d\n",id,(*(r[id])).type,(*(r[id])).offset,(*(r[id])).size);
 			}
 
 			if (task&1) {
 				//select type
+					//printf("kkkkkkk: %x -> %d\n",task,(*(r[id])).type);
+
 				if (task&4) (*(r[id])).type=0;
 				//save file
 				getFileName(vFileext,vDirExt,(*(r[id])).type,id);
 				switch ((*(r[id])).type) {
+					case 1:
+					case 5:
 					case 0:
 						ok=ok&&((target=fopen(vFileext,"wb"))!=NULL);
 						ok=ok&&fwrite(data+1,size-1,1,target); //Ignore checksum
@@ -132,8 +146,6 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) {
 
 						//until here
 						break;
-					case 1:
-					case 5:
 					case 4:
 						//save file
 
diff --git a/PR/parser.c b/PR/parser.c
index 41a0259..76b6f49 100644
--- a/PR/parser.c
+++ b/PR/parser.c
@@ -94,6 +94,8 @@ char matches1(char* text,char* mask,char ptext, char pmask) {
 
 		Devuelve 1 en caso de que el caracter coincida y 0 en caso contrario.
 	*/
+	char aux;
+
 	while (text[ptext]||mask[pmask]) {
 		if (mask[pmask]=='"') {
 			pmask++;
@@ -105,7 +107,6 @@ char matches1(char* text,char* mask,char ptext, char pmask) {
 			while (mask[pmask++]=='*');
 			pmask--;
 			if (!mask[pmask]) return 1; //acelera un poco el proceso para el caso particular de que termine en *
-			char aux;
 			while ((text[ptext]) && !(aux=matches1(text,mask,ptext++,pmask)));
 			return aux;
 		} else {
diff --git a/PR/pg.c b/PR/pg.c
index f73e76c..57592b5 100644
--- a/PR/pg.c
+++ b/PR/pg.c
@@ -48,50 +48,37 @@ void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) {
 
 //Compress B1/B2 algorithm
 void compressRle(unsigned char* data,tImage* img,int *dataSize) {
-  int cursorPix=0;
-  int cursorData=0;
-
-  int imgSize=((*img).size>>1)-1;
-  char enthropyBlock=1;
-  int  count=0;
-
-  while (cursorPix<imgSize) {
-		//Count different pixels
-		if (data[cursorPix++]==data[cursorPix]) {
-			if (enthropyBlock) { //TODO: add ||count>127
-				enthropyBlock=0;
-				//Print count . enthropy block (data[cursorPix-count..cursorPix])
-
-				count=0;
-			} else {
-				count++;
-			}
-		} else {
-			if (enthropyBlock) {  //TODO: add ||count>128
-				count++;
-			} else {
-				enthropyBlock=1;
-				//Print -count . unenthropy byte (data[cursorPix-1])
+	printf("llega 3.51\n");
+	//Declare pointers
+  char* cursorData  = data;
+  char* counter;
+  char* cursorPix   = (*img).pix;
+  char* imgEnd      = (*img).pix+((*img).size>>1)-1;
+	printf("llega 3.52\n");
+
+  while (cursorPix<imgEnd) {
+		//Step 1: Create counter
+		*(counter=(cursorData++))=-1;
+
+		//Step 2: Look and copy the string until a repeated byte is found
+		while ((cursorPix<=imgEnd)&&(*cursorPix!=*(++cursorPix))&&((*counter)!=127)) {
+			(*counter)++;
+			*(cursorData++)=*(cursorPix-1);
+		}
+printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd);
 
-				count=0;
-			}
+		cursorPix--;
+		//Step 3: If there was a repeated string, let's ignore it and add the cursor with the repetitions
+		if (*counter==-1) {
+			while ((cursorPix<imgEnd)&&(*cursorPix==(*(++cursorPix)))) (*counter)--;
+			*(cursorData++)=*(cursorPix-1); //Print repeated char
 		}
 	}
+	*(cursorData++)=0;
+	*(cursorData++)=*(cursorPix);
+	printf("llega 3.59\n");
 
-
-/*
-
-		if ((signed char)array[i]<0) {
-					//negative
-					while (array[i]++) (*image).pix[(cursor++)%((*image).size)]=array[i+1];
-					i+=2;
-				} else {
-					//Positive
-					char cx=array[i++]+1;
-					while (cx--) (*image).pix[(cursor++)%((*image).size)]=array[i++];
-				}
-			}
-			*/
+	*dataSize=(int)(cursorData-data);
 }
 
 
@@ -178,7 +165,11 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) {
 }
 
 //Compress an image into an array in the most quick & dirty way
-int mCompressGraphic(unsigned char* a,tImage i, int* size) {
+int mCompressGraphic(unsigned char* data,tImage i, int* size) {
+	int dataSize;
+//	unsigned char* data;
+
+	/*
 	*size=(i.size/2)+6;
 	a=getMemory(*size);
 	//height - 00 - width - 00 - 00 - compression type
@@ -191,7 +182,34 @@ int mCompressGraphic(unsigned char* a,tImage i, int* size) {
 	a[4]=0;
 	a[5]=0xB0; // how q&d I am :)
 
-	memcpy(i.pix,a+6,*size);
+	memcpy(i.pix,a+6,*size); //TODO it should be a+6,i.pix
+	*/
+//printf("llega 3\n");
+	//=getMemory(10*i.size+50); //This will reserve 10*2*(image size)+50 bytes, to allocate the compressed file
+//printf("llega 3.3\n");
+	compressRle(data+6,&i,&dataSize);
+//printf("llega 3.6\n");
+	//a=getMemory(*size=(dataSize+6));
+//printf("llega 4\n");
+	/*
+		Header Settings:
+		height - 00 - width - 00 - 00 - compression type
+	*/
+	data[2]=i.width;
+	data[3]=i.width>>8;
+
+	data[0]=i.height;
+	data[1]=i.height>>8;
+
+	data[4]=0;
+	data[5]=0xB1;
+
+	//memcpy(a+6,data,dataSize);
+	//free(data);
+*size=(dataSize+6);
+//printf("Tize: %d %02x %02x %02x %02x %02x %02x %02x\n",*size,a[0],a[1],a[2],a[3],a[4],a[5],a[6]);
+
+
 	return 1;
 }
 
diff --git a/PR/pr.c b/PR/pr.c
index b8f325b..d35c677 100644
--- a/PR/pr.c
+++ b/PR/pr.c
@@ -1,12 +1,34 @@
+/*  Princed V3 - Prince of Persia Level Editor for PC Version
+    Copyright (C) 2003 Princed Development Team
+
+    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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+    The authors of this program may be contacted at http://forum.princed.com.ar
+*/
+
 /*
+pr.c: Main source file for Princed Resources
+\xaf\xaf\xaf\xaf
 	Princed Resources library V1 beta
 	(c) Copyright 2003, Princed Development Team
 
 	Authors
-	 Main routines
+	 Coding & main routines
 	  Enrique Calot
 
-	 Graphic compression algorithm
+	 Graphic compression algorithms
     Tammo Jan Dijkema
     Enrique Calot
 
@@ -17,13 +39,15 @@
    MID Sound format development
     Christian Lundheim
 
+ Note:
+  DO NOT remove this copyright notice
 */
 
 //Compilation options
 
 //#define UNIX
 //#define DLL
-#define PR_ABOUT "Princed resources (PR) V0.5 beta.\r\n(c) Copyright 2003 - Princed Development Team\r\nhttp://www.princed.com.ar\r\n\r\n"
+#define PR_ABOUT "Princed resources (PR) V0.6 beta.\r\n(c) Copyright 2003 - Princed Development Team\r\nhttp://www.princed.com.ar\r\n\r\n"
 
 //Headers
 
@@ -65,10 +89,13 @@ int prExportDatOpt(char* vDatFile, char* vDirName, char* vResFile,char opt) {
 			00 Ok
 			-1 Error accesing the file
 			-2 Memory error
+			-3 Invalid DAT file
 	*/
 	tResource* r[65536];
+	int a;
 	parseFile (vResFile,r);
-	int a=extract(vDatFile, vDirName,r,opt);
+	printf("kkkkkkkkkkk: %x\n",opt);
+	a=extract(vDatFile, vDirName,r,opt);
 	if (!(opt&8)) generateFile(vResFile,r);
 	return a;
 }
@@ -89,8 +116,9 @@ int prImportDatOpt(char* vDatFile, char* vDirName, char* vResFile,char opt) {
 			positive number: number of missing files
 	*/
 	tResource*    r[65536];
+	int a;
 	parseFile     (vResFile,r);
-	int a=compile (vDatFile, vDirName,r,opt);
+	a=compile (vDatFile, vDirName,r,opt);
 	generateFile  (vResFile,r);
 	return a;
 }
@@ -111,25 +139,32 @@ int prClearRes(char* vResFile) {
 //Main program
 #ifndef DLL
 void syntax() {
-	printf("Syntax:\r\n pr datfile option [extract dir]\r\n\r\nValid options:\r\n -x[rnus] for extract\r\n  r: raw extraction\r\n  n: don't extract\r\n  u: update res file in case there were records\r\n  s: don't save res file\r\n -c for compile\r\n  r: raw compiling\r\n -d for type\r\n -t to clear the resource file.\r\n");
+	printf("Syntax:\r\n pr datfile option [extract dir]\r\n\r\nValid options:\r\n -x[rnus] for extract\r\n  r: raw extraction\r\n  n: don't extract\r\n  u: update res file in case there were records\r\n  s: don't save res file\r\n -c[r] for compile\r\n  r: raw compiling\r\n -d for type\r\n -t to clear the resource file.\r\n");
 }
 
 int main(int argc, char* argv[]) {
 
+	//declare variables
+	char dir[260]=".";
+	int returnValue=1;
+	int option;
+	int i;
+
+	//bmp vars
+	char vFileraw[100];
+	char vFilebmp[100];
+	unsigned char* data;
+	tImage img;
+	int size;
+
 #ifdef UNIX
 	if (argc==2) {
 		printf("Content-Type:text/html\n\nRunning as a cgi\n");
-		printf("Result: %d type\r\n",prVerifyDatType(argv[1]));
+		printf("Result: %02d type\r\n",prVerifyDatType(argv[1]));
 		return 1;
 	}
 #endif
 
-	//declare variables
-	char dir[260]=".";
-	int returnValue=1;
-	int option;
-
-	//TODO: send to defines
 	printf(PR_ABOUT);
 
 	//Verify syntax
@@ -146,7 +181,7 @@ int main(int argc, char* argv[]) {
 		case 'e':
 		case 'x': // file.dat --> files.ext + resource.txt
 			option=1;
-			for (int i=2;argv[2][i];i++) {
+			for (i=2;argv[2][i];i++) {
 				switch (argv[2][i]) {
 					case 'n':option&=0xFE;break;
 					case 'r':option|=0x04;break;
@@ -165,7 +200,7 @@ int main(int argc, char* argv[]) {
 		case 'i':
 		case 'c': // files.ext + resource.txt --> files.dat
 			option=1;
-				for (int i=2;argv[2][i];i++) {
+				for (i=2;argv[2][i];i++) {
 					switch (argv[2][i]) {
 						case 'r':option&=0xFE;break;
 						default:printf("Found invalid option '%c', skiping . . .\r\n",argv[2][i]);break;
@@ -179,30 +214,21 @@ int main(int argc, char* argv[]) {
 			printf("Result: %d\r\n",returnValue=prClearRes("resources.txt"));
 			break;
 		case 'b': // img.bmp --> img.ext
-			{
-			char vFileraw[100];
-			char vFilebmp[100];
-			unsigned char* data;
-			tImage img;
-
 			sprintf(vFileraw,"%s%cres%s.raw",dir,DIR_SEPARATOR,argv[1]);
 			sprintf(vFilebmp,"%s%cres%s.bmp",dir,DIR_SEPARATOR,argv[1]);
 
 			printf("Converting '%s' into '%s'\r\n",vFilebmp,vFileraw);
-			int size=mLoadFileArray(vFilebmp,&data);
+			size=mLoadFileArray(vFilebmp,&data);
 			if (size && mReadBitMap(&img,data,size)) {
 				free(data);
 				mCompressGraphic(data,img,&size);
 				free(img.pix);
 				mSaveRaw(vFileraw,data,size);
 				free(data);
-
 			} else {
 				printf("No access to the file\r\n");
 				break;
 			}
-
-			}
 			break;
 		default:
 			syntax();
diff --git a/PR/pr.exe b/PR/pr.exe
index 0302730..55f991d 100755
Binary files a/PR/pr.exe and b/PR/pr.exe differ
diff --git a/PR/pr.obj b/PR/pr.obj
index db76701..ac34d50 100644
Binary files a/PR/pr.obj and b/PR/pr.obj differ
diff --git a/PR/resources.txt b/PR/resources.txt
index 37a18dd..8300ef9 100644
--- a/PR/resources.txt
+++ b/PR/resources.txt
@@ -1,256 +1,222 @@
-Princed V3.0 alpha game resources list
-(c) Copyright 2003 - Princed Development Team
-http://www.princed.com.ar
-
-*** Game resources table
-
-Syntax:
-Id    Size  Offset    File    Type Description       Comments
-XXXXX YYYYY ZZZZZ SSSSSSSS.DAT TT Ddddddddddddd...  #cccccccc....
-
-Comments are optional
-
-Note:
- You can edit description and commets here in the file and
- they will be saved in the dat files.
- 
-Resource Types:
- 01 Levels
- 02 Bitmaps
- 03 Waves
- 04 Midis
- 05 Undefined
- 06 Palette
- 07 to 10 reserved
-
 BEGIN resources table
 
-00200 00100 00006 VDUNGEON.DAT 00
-00201 00002 00107 VDUNGEON.DAT 00
-00202 00002 00110 VDUNGEON.DAT 00
-00203 00002 00113 VDUNGEON.DAT 00
-00204 00002 00116 VDUNGEON.DAT 00
-00205 00002 00119 VDUNGEON.DAT 00
-00206 00002 00122 VDUNGEON.DAT 00
-00207 00002 00125 VDUNGEON.DAT 00
-00208 00002 00128 VDUNGEON.DAT 00
-00209 00002 00131 VDUNGEON.DAT 00
-00210 00002 00134 VDUNGEON.DAT 00
-00211 00002 00137 VDUNGEON.DAT 00
-00212 00002 00140 VDUNGEON.DAT 00
-00213 00002 00143 VDUNGEON.DAT 00
-00214 00002 00146 VDUNGEON.DAT 00
-00215 00002 00149 VDUNGEON.DAT 00
-00216 00002 00152 VDUNGEON.DAT 00
-00217 00002 00155 VDUNGEON.DAT 00
-00218 00002 00158 VDUNGEON.DAT 00
-00219 00002 00161 VDUNGEON.DAT 00
-00220 00002 00164 VDUNGEON.DAT 00
-00221 00002 00167 VDUNGEON.DAT 00
-00222 00002 00170 VDUNGEON.DAT 00
-00223 00002 00173 VDUNGEON.DAT 00
-00224 00002 00176 VDUNGEON.DAT 00
-00225 00002 00179 VDUNGEON.DAT 00
-00226 00002 00182 VDUNGEON.DAT 00
-00227 00002 00185 VDUNGEON.DAT 00
-00228 00002 00188 VDUNGEON.DAT 00
-00229 00002 00191 VDUNGEON.DAT 00
-00230 00002 00194 VDUNGEON.DAT 00
-00231 00002 00197 VDUNGEON.DAT 00
-00232 00039 00200 VDUNGEON.DAT 00
-00233 00088 00240 VDUNGEON.DAT 00
-00234 00082 00329 VDUNGEON.DAT 00
-00235 00082 00412 VDUNGEON.DAT 00
-00236 00015 00495 VDUNGEON.DAT 00
-00237 00086 00511 VDUNGEON.DAT 00
-00238 00065 00598 VDUNGEON.DAT 00
-00239 00102 00664 VDUNGEON.DAT 00
-00240 00059 00767 VDUNGEON.DAT 00
-00241 00101 00827 VDUNGEON.DAT 00
-00242 00112 00929 VDUNGEON.DAT 00
-00243 00018 01042 VDUNGEON.DAT 00
-00244 00129 01061 VDUNGEON.DAT 00
-00245 00098 01191 VDUNGEON.DAT 00
-00246 00100 01290 VDUNGEON.DAT 00
-00247 00125 01391 VDUNGEON.DAT 00
-00248 00022 01517 VDUNGEON.DAT 00
-00249 00018 01540 VDUNGEON.DAT 00
-00250 00051 01559 VDUNGEON.DAT 00
-00251 00041 01611 VDUNGEON.DAT 00
-00252 00073 01653 VDUNGEON.DAT 00
-00253 00066 01727 VDUNGEON.DAT 00
-00254 00060 01794 VDUNGEON.DAT 00
-00255 00051 01855 VDUNGEON.DAT 00
-00256 00047 01907 VDUNGEON.DAT 00
-00257 00035 01955 VDUNGEON.DAT 00
-00258 00030 01991 VDUNGEON.DAT 00
-00259 00018 02022 VDUNGEON.DAT 00
-00260 00061 02041 VDUNGEON.DAT 00
-00261 00056 02103 VDUNGEON.DAT 00
-00262 00037 02160 VDUNGEON.DAT 00
-00263 00043 02198 VDUNGEON.DAT 00
-00264 00049 02242 VDUNGEON.DAT 00
-00265 00047 02292 VDUNGEON.DAT 00
-00266 00054 02340 VDUNGEON.DAT 00
-00267 00060 02395 VDUNGEON.DAT 00
-00268 00024 02456 VDUNGEON.DAT 00
-00269 00107 02481 VDUNGEON.DAT 00
-00270 00087 02589 VDUNGEON.DAT 00
-00271 00116 02677 VDUNGEON.DAT 00
-00272 00116 02794 VDUNGEON.DAT 00
-00273 00026 02911 VDUNGEON.DAT 00
-00274 00024 02938 VDUNGEON.DAT 00
-00275 00002 02963 VDUNGEON.DAT 00
-00276 00002 02966 VDUNGEON.DAT 00
-00277 00002 02969 VDUNGEON.DAT 00
-00278 00002 02972 VDUNGEON.DAT 00
-00279 00002 02975 VDUNGEON.DAT 00
-00280 00002 02978 VDUNGEON.DAT 00
-00281 00002 02981 VDUNGEON.DAT 00
-00282 00002 02984 VDUNGEON.DAT 00
-00283 00002 02987 VDUNGEON.DAT 00
-00284 00002 02990 VDUNGEON.DAT 00
-00285 00016 02993 VDUNGEON.DAT 00
-00286 00002 03010 VDUNGEON.DAT 00
-00287 00002 03013 VDUNGEON.DAT 00
-00288 00002 03016 VDUNGEON.DAT 00
-00289 00002 03019 VDUNGEON.DAT 00
-00290 00002 03022 VDUNGEON.DAT 00
-00291 00002 03025 VDUNGEON.DAT 00
-00292 00239 03028 VDUNGEON.DAT 00
-00293 00386 03268 VDUNGEON.DAT 00
-00294 00030 03655 VDUNGEON.DAT 00
-00295 00180 03686 VDUNGEON.DAT 00
-00296 00016 03867 VDUNGEON.DAT 00
-00297 00169 03884 VDUNGEON.DAT 00
-00298 00152 04054 VDUNGEON.DAT 00
-00299 00020 04207 VDUNGEON.DAT 00
-00300 00123 04228 VDUNGEON.DAT 00
-00301 00002 04352 VDUNGEON.DAT 00
-00302 00002 04355 VDUNGEON.DAT 00
-00303 00002 04358 VDUNGEON.DAT 00
-00304 00002 04361 VDUNGEON.DAT 00
-00305 00002 04364 VDUNGEON.DAT 00
-00306 00002 04367 VDUNGEON.DAT 00
-00307 00002 04370 VDUNGEON.DAT 00
-00308 00002 04373 VDUNGEON.DAT 00
-00309 00002 04376 VDUNGEON.DAT 00
-00310 00002 04379 VDUNGEON.DAT 00
-00311 00002 04382 VDUNGEON.DAT 00
-00312 00002 04385 VDUNGEON.DAT 00
-00313 00002 04388 VDUNGEON.DAT 00
-00314 00002 04391 VDUNGEON.DAT 00
-00315 00002 04394 VDUNGEON.DAT 00
-00316 00002 04397 VDUNGEON.DAT 00
-00317 00002 04400 VDUNGEON.DAT 00
-00318 00002 04403 VDUNGEON.DAT 00
-00319 00002 04406 VDUNGEON.DAT 00
-00320 00002 04409 VDUNGEON.DAT 00
-00321 00002 04412 VDUNGEON.DAT 00
-00322 00002 04415 VDUNGEON.DAT 00
-00323 00002 04418 VDUNGEON.DAT 00
-00324 00104 04421 VDUNGEON.DAT 00
-00325 00116 04526 VDUNGEON.DAT 00
-00326 00516 04643 VDUNGEON.DAT 00
-00327 00002 05160 VDUNGEON.DAT 00
-00328 00002 05163 VDUNGEON.DAT 00
-00329 00002 05166 VDUNGEON.DAT 00
-00330 00002 05169 VDUNGEON.DAT 00
-00331 00002 05172 VDUNGEON.DAT 00
-00332 00002 05175 VDUNGEON.DAT 00
-00333 00002 05178 VDUNGEON.DAT 00
-00334 00002 05181 VDUNGEON.DAT 00
-00335 00002 05184 VDUNGEON.DAT 00
-00336 00002 05187 VDUNGEON.DAT 00
-00337 00002 05190 VDUNGEON.DAT 00
-00338 00002 05193 VDUNGEON.DAT 00
-00339 00002 05196 VDUNGEON.DAT 00
-00340 00002 05199 VDUNGEON.DAT 00
-00341 00002 05202 VDUNGEON.DAT 00
-00342 00002 05205 VDUNGEON.DAT 00
-00343 00002 05208 VDUNGEON.DAT 00
-00344 00085 05211 VDUNGEON.DAT 00
-00345 00002 05297 VDUNGEON.DAT 00
-00346 00038 05300 VDUNGEON.DAT 00
-00347 00105 05339 VDUNGEON.DAT 00
-00348 00105 05445 VDUNGEON.DAT 00
-00349 00016 05551 VDUNGEON.DAT 00
-00350 00048 05568 VDUNGEON.DAT 00
-00351 00046 05617 VDUNGEON.DAT 00
-00360 00100 05664 VDUNGEON.DAT 00
-00361 00204 05765 VDUNGEON.DAT 00
-00362 00066 05970 VDUNGEON.DAT 00
-00363 00010 06037 VDUNGEON.DAT 00
-00364 00251 06048 VDUNGEON.DAT 00
-00365 00016 06300 VDUNGEON.DAT 00
-00366 00348 06317 VDUNGEON.DAT 00
-00367 00022 06666 VDUNGEON.DAT 00
-00368 00344 06689 VDUNGEON.DAT 00
-00369 00026 07034 VDUNGEON.DAT 00
-00370 00328 07061 VDUNGEON.DAT 00
-00371 00047 07390 VDUNGEON.DAT 00
-00372 00040 07438 VDUNGEON.DAT 00
-00373 00108 07479 VDUNGEON.DAT 00
-00374 00040 07588 VDUNGEON.DAT 00
-00375 00040 07629 VDUNGEON.DAT 00
-00376 00041 07670 VDUNGEON.DAT 00
-00377 00041 07712 VDUNGEON.DAT 00
-01230 00154 07754 VDUNGEON.DAT 00
-01231 00132 07909 VDUNGEON.DAT 00
-01286 00217 08042 VDUNGEON.DAT 00
-01287 00262 08260 VDUNGEON.DAT 00
-01288 00183 08523 VDUNGEON.DAT 00
-01289 00113 08707 VDUNGEON.DAT 00
-01290 00039 08821 VDUNGEON.DAT 00
-01291 00147 08861 VDUNGEON.DAT 00
-01301 00436 09009 VDUNGEON.DAT 00
-01302 00421 09446 VDUNGEON.DAT 00
-01303 00202 09868 VDUNGEON.DAT 00
-01304 00154 10071 VDUNGEON.DAT 00
-01305 00130 10226 VDUNGEON.DAT 00
-01306 00131 10357 VDUNGEON.DAT 00
-01307 00134 10489 VDUNGEON.DAT 00
-01308 00129 10624 VDUNGEON.DAT 00
-01309 00091 10754 VDUNGEON.DAT 00
-01310 00071 10846 VDUNGEON.DAT 00
-01311 00163 10918 VDUNGEON.DAT 00
-01312 00091 11082 VDUNGEON.DAT 00
-01313 00068 11174 VDUNGEON.DAT 00
-01314 00034 11243 VDUNGEON.DAT 00
-01315 00031 11278 VDUNGEON.DAT 00
-01316 00024 11310 VDUNGEON.DAT 00
-01317 00015 11335 VDUNGEON.DAT 00
-01318 00011 11351 VDUNGEON.DAT 00
-01319 00018 11363 VDUNGEON.DAT 00
-01320 00022 11382 VDUNGEON.DAT 00
-01321 00022 11405 VDUNGEON.DAT 00
-01322 00013 11428 VDUNGEON.DAT 00
-01323 00010 11442 VDUNGEON.DAT 00
-01327 00107 11453 VDUNGEON.DAT 00
-01328 00019 11561 VDUNGEON.DAT 00
-01329 00054 11581 VDUNGEON.DAT 00
-01330 00081 11636 VDUNGEON.DAT 00
-01331 00079 11718 VDUNGEON.DAT 00
-01332 00068 11798 VDUNGEON.DAT 00
-01333 00120 11867 VDUNGEON.DAT 00
-01334 00014 11988 VDUNGEON.DAT 00
-01335 00038 12003 VDUNGEON.DAT 00
-01336 00047 12042 VDUNGEON.DAT 00
-01337 00047 12090 VDUNGEON.DAT 00
-01338 00047 12138 VDUNGEON.DAT 00
-01339 00016 12186 VDUNGEON.DAT 00
-01340 00046 12203 VDUNGEON.DAT 00
-01341 00073 12250 VDUNGEON.DAT 00
-01342 00070 12324 VDUNGEON.DAT 00
-01343 00057 12395 VDUNGEON.DAT 00
+00200 00101 00006 VDO.DAT 06
+00201 00003 00107 VDO.DAT 05
+00202 00003 00110 VDO.DAT 05
+00203 00003 00113 VDO.DAT 05
+00204 00003 00116 VDO.DAT 05
+00205 00003 00119 VDO.DAT 05
+00206 00003 00122 VDO.DAT 05
+00207 00003 00125 VDO.DAT 05
+00208 00003 00128 VDO.DAT 05
+00209 00003 00131 VDO.DAT 05
+00210 00003 00134 VDO.DAT 05
+00211 00003 00137 VDO.DAT 05
+00212 00003 00140 VDO.DAT 05
+00213 00003 00143 VDO.DAT 05
+00214 00003 00146 VDO.DAT 05
+00215 00003 00149 VDO.DAT 05
+00216 00003 00152 VDO.DAT 05
+00217 00003 00155 VDO.DAT 05
+00218 00003 00158 VDO.DAT 05
+00219 00003 00161 VDO.DAT 05
+00220 00003 00164 VDO.DAT 05
+00221 00003 00167 VDO.DAT 05
+00222 00003 00170 VDO.DAT 05
+00223 00003 00173 VDO.DAT 05
+00224 00003 00176 VDO.DAT 05
+00225 00003 00179 VDO.DAT 05
+00226 00003 00182 VDO.DAT 05
+00227 00003 00185 VDO.DAT 05
+00228 00003 00188 VDO.DAT 05
+00229 00003 00191 VDO.DAT 05
+00230 00003 00194 VDO.DAT 05
+00231 00003 00197 VDO.DAT 05
+00232 00057 00200 VDO.DAT 02
+00233 00089 00257 VDO.DAT 02
+00234 00083 00346 VDO.DAT 02
+00235 00085 00429 VDO.DAT 02
+00236 00019 00514 VDO.DAT 02
+00237 00415 00533 VDO.DAT 02
+00238 00184 00948 VDO.DAT 02
+00239 00491 01132 VDO.DAT 02
+00240 00160 01623 VDO.DAT 02
+00241 00104 01783 VDO.DAT 02
+00242 00115 01887 VDO.DAT 02
+00243 00019 02002 VDO.DAT 02
+00244 00142 02021 VDO.DAT 02
+00245 00129 02163 VDO.DAT 02
+00246 00473 02292 VDO.DAT 02
+00247 00447 02765 VDO.DAT 02
+00248 00089 03212 VDO.DAT 02
+00249 00251 03301 VDO.DAT 02
+00250 00137 03552 VDO.DAT 02
+00251 00085 03689 VDO.DAT 02
+00252 00116 03774 VDO.DAT 02
+00253 00103 03890 VDO.DAT 02
+00254 00089 03993 VDO.DAT 02
+00255 00075 04082 VDO.DAT 02
+00256 00062 04157 VDO.DAT 02
+00257 00049 04219 VDO.DAT 02
+00258 00036 04268 VDO.DAT 02
+00259 00023 04304 VDO.DAT 02
+00260 00082 04327 VDO.DAT 02
+00261 00084 04409 VDO.DAT 02
+00262 00077 04493 VDO.DAT 02
+00263 00076 04570 VDO.DAT 02
+00264 00075 04646 VDO.DAT 02
+00265 00074 04721 VDO.DAT 02
+00266 00073 04795 VDO.DAT 02
+00267 00076 04868 VDO.DAT 02
+00268 00025 04944 VDO.DAT 05
+00269 00110 04969 VDO.DAT 02
+00270 00109 05079 VDO.DAT 02
+00271 00121 05188 VDO.DAT 02
+00272 00119 05309 VDO.DAT 02
+00273 00027 05428 VDO.DAT 02
+00274 00027 05455 VDO.DAT 02
+00275 00003 05482 VDO.DAT 05
+00276 00003 05485 VDO.DAT 05
+00277 00003 05488 VDO.DAT 05
+00278 00003 05491 VDO.DAT 05
+00279 00003 05494 VDO.DAT 05
+00280 00003 05497 VDO.DAT 05
+00281 00003 05500 VDO.DAT 05
+00282 00003 05503 VDO.DAT 05
+00283 00003 05506 VDO.DAT 05
+00284 00003 05509 VDO.DAT 05
+00285 00037 05512 VDO.DAT 02
+00286 00003 05549 VDO.DAT 05
+00287 00003 05552 VDO.DAT 05
+00288 00003 05555 VDO.DAT 05
+00289 00003 05558 VDO.DAT 05
+00290 00003 05561 VDO.DAT 05
+00291 00003 05564 VDO.DAT 05
+00292 00774 05567 VDO.DAT 02
+00293 00514 06341 VDO.DAT 02
+00294 00042 06855 VDO.DAT 02
+00295 00438 06897 VDO.DAT 02
+00296 00019 07335 VDO.DAT 02
+00297 00172 07354 VDO.DAT 02
+00298 00155 07526 VDO.DAT 02
+00299 00030 07681 VDO.DAT 02
+00300 00126 07711 VDO.DAT 02
+00301 00003 07837 VDO.DAT 05
+00302 00003 07840 VDO.DAT 05
+00303 00003 07843 VDO.DAT 05
+00304 00003 07846 VDO.DAT 05
+00305 00003 07849 VDO.DAT 05
+00306 00003 07852 VDO.DAT 05
+00307 00003 07855 VDO.DAT 05
+00308 00003 07858 VDO.DAT 05
+00309 00003 07861 VDO.DAT 05
+00310 00003 07864 VDO.DAT 05
+00311 00003 07867 VDO.DAT 05
+00312 00003 07870 VDO.DAT 05
+00313 00003 07873 VDO.DAT 05
+00314 00003 07876 VDO.DAT 05
+00315 00003 07879 VDO.DAT 05
+00316 00003 07882 VDO.DAT 05
+00317 00003 07885 VDO.DAT 05
+00318 00003 07888 VDO.DAT 05
+00319 00003 07891 VDO.DAT 05
+00320 00003 07894 VDO.DAT 05
+00321 00003 07897 VDO.DAT 05
+00322 00003 07900 VDO.DAT 05
+00323 00003 07903 VDO.DAT 05
+00324 00115 07906 VDO.DAT 02
+00325 00137 08021 VDO.DAT 02
+00326 00760 08158 VDO.DAT 02
+00327 00003 08918 VDO.DAT 05
+00328 00003 08921 VDO.DAT 05
+00329 00003 08924 VDO.DAT 05
+00330 00003 08927 VDO.DAT 05
+00331 00003 08930 VDO.DAT 05
+00332 00003 08933 VDO.DAT 05
+00333 00003 08936 VDO.DAT 05
+00334 00003 08939 VDO.DAT 05
+00335 00003 08942 VDO.DAT 05
+00336 00003 08945 VDO.DAT 05
+00337 00003 08948 VDO.DAT 05
+00338 00003 08951 VDO.DAT 05
+00339 00003 08954 VDO.DAT 05
+00340 00003 08957 VDO.DAT 05
+00341 00003 08960 VDO.DAT 05
+00342 00003 08963 VDO.DAT 05
+00343 00003 08966 VDO.DAT 05
+00344 00252 08969 VDO.DAT 02
+00345 00003 09221 VDO.DAT 05
+00346 00083 09224 VDO.DAT 02
+00347 00106 09307 VDO.DAT 02
+00348 00106 09413 VDO.DAT 02
+00349 00019 09519 VDO.DAT 02
+00350 00071 09538 VDO.DAT 02
+00351 00069 09609 VDO.DAT 02
+00360 00101 09678 VDO.DAT 06
+00361 00552 09779 VDO.DAT 02
+00362 00109 10331 VDO.DAT 02
+00363 00013 10440 VDO.DAT 02
+00364 00250 10453 VDO.DAT 02
+00365 00017 10703 VDO.DAT 02
+00366 00366 10720 VDO.DAT 02
+00367 00023 11086 VDO.DAT 02
+00368 00349 11109 VDO.DAT 02
+00369 00029 11458 VDO.DAT 02
+00370 00331 11487 VDO.DAT 02
+00371 00119 11818 VDO.DAT 02
+00372 00108 11937 VDO.DAT 02
+00373 00135 12045 VDO.DAT 02
+00374 00043 12180 VDO.DAT 02
+00375 00043 12223 VDO.DAT 02
+00376 00047 12266 VDO.DAT 02
+00377 00049 12313 VDO.DAT 02
+01230 00194 12362 VDO.DAT 02
+01231 00188 12556 VDO.DAT 02
+01286 00636 12744 VDO.DAT 02
+01287 00622 13380 VDO.DAT 02
+01288 00572 14002 VDO.DAT 02
+01289 00532 14574 VDO.DAT 02
+01290 00063 15106 VDO.DAT 02
+01291 00584 15169 VDO.DAT 02
+01301 00816 15753 VDO.DAT 02
+01302 00758 16569 VDO.DAT 02
+01303 00324 17327 VDO.DAT 02
+01304 00212 17651 VDO.DAT 02
+01305 00155 17863 VDO.DAT 02
+01306 00421 18018 VDO.DAT 02
+01307 00411 18439 VDO.DAT 02
+01308 00313 18850 VDO.DAT 02
+01309 00186 19163 VDO.DAT 02
+01310 00142 19349 VDO.DAT 02
+01311 00249 19491 VDO.DAT 02
+01312 00129 19740 VDO.DAT 02
+01313 00098 19869 VDO.DAT 02
+01314 00035 19967 VDO.DAT 05
+01315 00032 20002 VDO.DAT 05
+01316 00025 20034 VDO.DAT 05
+01317 00016 20059 VDO.DAT 05
+01318 00012 20075 VDO.DAT 05
+01319 00019 20087 VDO.DAT 05
+01320 00023 20106 VDO.DAT 05
+01321 00023 20129 VDO.DAT 05
+01322 00014 20152 VDO.DAT 05
+01323 00011 20166 VDO.DAT 05
+01327 00113 20177 VDO.DAT 02
+01328 00057 20290 VDO.DAT 02
+01329 00180 20347 VDO.DAT 02
+01330 00300 20527 VDO.DAT 02
+01331 00286 20827 VDO.DAT 02
+01332 00273 21113 VDO.DAT 02
+01333 00123 21386 VDO.DAT 02
+01334 00017 21509 VDO.DAT 02
+01335 00091 21526 VDO.DAT 02
+01336 00118 21617 VDO.DAT 02
+01337 00135 21735 VDO.DAT 02
+01338 00130 21870 VDO.DAT 02
+01339 00032 22000 VDO.DAT 02
+01340 00121 22032 VDO.DAT 02
+01341 00210 22153 VDO.DAT 02
+01342 00199 22363 VDO.DAT 02
+01343 00186 22562 VDO.DAT 02
 
 END resources table
-
-BEGIN palette table
-END palette table
-
-BEGIN block table
-END block table
-
-
-You can write notes here
diff --git a/PR/src/lib/formats/Attic/bmp.c b/PR/src/lib/formats/Attic/bmp.c
index 6ff45a4..06f2f96 100644
--- a/PR/src/lib/formats/Attic/bmp.c
+++ b/PR/src/lib/formats/Attic/bmp.c
@@ -7,11 +7,17 @@
 char mFormatCompileBmp(unsigned char* data, FILE* fp, tResource *res) {
 	int size;
 	tImage img;
+	unsigned char aux[10000];
 	if (!mReadBitMap(&img,data,(*res).size)) return 0;
-	free(data);
-	mCompressGraphic(data,img,&size);
+	//free(data);
+			//printf("llega 2\n");
+	mCompressGraphic(aux,img,&size);
+	printf("llega ssss2\n");
 	free(img.pix);
-	mAddFileToDatFile(fp,data,size);
+	printf("llega ssss3\n");
+	mAddFileToDatFile(fp,aux,size);
+	printf("llega ssss4\n");
+	(*res).size=size; //TODO: delete this bug (added to debug ;) ironic, don't you think
 	return 1;
 }
 
@@ -103,76 +109,40 @@ char mWriteBitMap(tImage img,char* vFile) {
 
 
 char mReadBitMap(tImage* img,char* data, int size) {
-	//add validations
-	//printf("tllego 1\r\n");
-
 	char ok;
 	unsigned short int width;
 	unsigned short int height;
 
+	//Validate if there is header and if it starts in BM
 	ok    = size>118;
 	ok=ok&& data[0]=='B' && data[1]=='M';
 
-	width=data[18];
-	width+=data[19]<<8;
-
-	height=data[22];
-	height+=data[23]<<8;
+	//Read sizes from header
+	width=data[18]+(data[19]<<8);
+	height=data[22]+(data[23]<<8);
 
-	(*img).width=width;
+	//Save sizes into image
+	(*img).width=width;            //width in pixels
 	(*img).height=height;
-	(*img).size=height*width;
-	ok=ok&& (((((*img).size))/2)==(size-118));
-	ok=ok&& (
-		(
-			(*img).pix=getMemory(
-				(((*img).size))/2
-			)
-		)!=NULL
-	);
+	(*img).size=height*width;      //total of pixels
+
+	//Calculate serialized widths
+	width=(width+1)>>1;            //raw serialized width
+	int width2=width+((-width)&3); //bmp serialized width
 
+	//Validate image and file size; get memory to allocate the image
+	ok=ok&& ( ((*img).height*width2)                == (size-118));
+	ok=ok&& (	((*img).pix=getMemory((*img).size/2)) != NULL	);
+
+	//if validations==wrong
 	if (!ok) {
 		if ((*img).pix!=NULL) free((*img).pix);
-		return 0; //this is not a valid bmp file format
+		return 0; //this is not a valid bmp file format or memory too low
 	}
 
-	width=(width+1)>>1;
-	int width2=width+((-width)&3);
-
-/*	while (img.height--) {
-		for (int x=0;x<width;x++) {
-			*(6+img.pix+height*img.width)=data+118+height*width2
-		fwrite(img.pix+img.height*img.width,img.width,1,bitmap);
-		fwrite(junk,(-img.width)&3,1,bitmap);
-	}
-*/
+	//Serialize bitmap-->raw array
 	int x=0;
-	while (height--) {
-		memcpy(6+(*img).pix+(x++)*(*img).width,data+118+height*width2,width);
-	}
-
-
-
-//	printf("tllego 4 %d %d %d\r\n",((*img).size)/2,size-118,(*img).pix);
-//	memcpy(data+118,(*img).pix,(((*img).size)/2));
-/*
-img.width=img.width+(img.width&1);
-for (int h=img.height-1;h>=0;--h) {
-	for (int w=0;w<img.width;w++) {
-		mBmpWritePixel(bitmap,mBmpGetPixel(img,w,h),&i,&j);
-	}
-	//align by 4
-	for (int w=img.width;w&7;w++) {
-		mBmpWritePixel(bitmap,5,&i,&j);
-	}
-
-}
-
-*/
-
-
-//	printf("tllego 5\r\n");
-
+	while (height--) memcpy((*img).pix+(x++)*width,data+118+height*width2,width);
 
 	return 1;
 }
diff --git a/PR/src/lib/formats/Attic/pal.c b/PR/src/lib/formats/Attic/pal.c
index c455b97..3c6d038 100644
--- a/PR/src/lib/formats/Attic/pal.c
+++ b/PR/src/lib/formats/Attic/pal.c
@@ -16,30 +16,32 @@ char mImportPalette(unsigned char** data, unsigned short *size) {
 	//declare variables
 	unsigned char palh[]=PAL_HEADER;
 	unsigned char pals[]=PAL_SAMPLE;
-	unsigned char* pal=getMemory(101);
+	unsigned char* pal=getMemory(100);
 	unsigned short int parsed;
 	int i=0;
 
 	//set palette with sample
-	memcpy(pal,pals,101);
+	memcpy(pal,pals,100);
 
-	//set current values
+	//verify jasc pal header
 	while (palh[i]==(*data)[i++]);
 	if (i!=sizeof(palh)) return 0;
+
+	//set current values
 	for (int k=0;k<16;k++) {
 		getNumberToken((*data),&parsed,' ',&i,4);
-		pal[(k*3)+5]=(parsed+2)>>2;
+		pal[(k*3)+4]=(parsed+2)>>2;
 		getNumberToken((*data),&parsed,' ',&i,4);
-		pal[(k*3)+6]=(parsed+2)>>2;
+		pal[(k*3)+5]=(parsed+2)>>2;
 		getNumberToken((*data),&parsed,'\r',&i,4);
-		pal[(k*3)+7]=(parsed+2)>>2;
-		i++;
+		pal[(k*3)+6]=(parsed+2)>>2;
+		i++; //Jump \n
 	}
 
 	//free old data and set new
 	free(*data);
 	*data=pal;
-	*size=101;
+	*size=100;
 	return 1;
 }
 
diff --git a/PR/src/lib/formats/pal.h b/PR/src/lib/formats/pal.h
index 3ca6b80..e5ae074 100644
--- a/PR/src/lib/formats/pal.h
+++ b/PR/src/lib/formats/pal.h
@@ -13,7 +13,7 @@
 #endif
 
 #define PAL_HEADER "JASC-PAL\r\n0100\r\n16\r\n"
-#define PAL_SAMPLE {0xB4, 0x97, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x08, 0x0F, 0x07, 0x0C, 0x13, 0x0C, 0x11, 0x16, 0x11, 0x17, 0x1C, 0x1E, 0x21, 0x25, 0x2F, 0x31, 0x33, 0x3F, 0x3F, 0x3F, 0x2A, 0x2A, 0x2A, 0x15, 0x15, 0x15, 0x17, 0x1C, 0x20, 0x07, 0x0C, 0x13, 0x0C, 0x12, 0x17, 0x15, 0x1A, 0x1F, 0x00, 0x1D, 0x13, 0x00, 0x29, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
+#define PAL_SAMPLE {0x97, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x08, 0x0F, 0x07, 0x0C, 0x13, 0x0C, 0x11, 0x16, 0x11, 0x17, 0x1C, 0x1E, 0x21, 0x25, 0x2F, 0x31, 0x33, 0x3F, 0x3F, 0x3F, 0x2A, 0x2A, 0x2A, 0x15, 0x15, 0x15, 0x17, 0x1C, 0x20, 0x07, 0x0C, 0x13, 0x0C, 0x12, 0x17, 0x15, 0x1A, 0x1F, 0x00, 0x1D, 0x13, 0x00, 0x29, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
 
 char mImportPalette(unsigned char** data, unsigned short *size);
 void mExportPalette(unsigned char** data, unsigned long int *size);
diff --git a/PR/tasks.c b/PR/tasks.c
index 09ad553..16b22b3 100644
--- a/PR/tasks.c
+++ b/PR/tasks.c
@@ -6,12 +6,21 @@ int prVerifyDatType(char* vFiledat) {
 	//Variables
 	FILE*         fp;
   char          ok;
+  int 					k;
+
+	//if header ok, new variables
+	unsigned short int offset;
+	unsigned long int  size;
+	unsigned char*     data;
+	unsigned char      type=5;
+
+	//loop variables
+	unsigned long int indexOffset;
+	unsigned short int indexSize,val,numberOfItems;
+	unsigned char* index;
+
 
 	if (ok=((fp=fopen(vFiledat,"rb"))!=NULL)) {
-		//loop variables
-		unsigned long int indexOffset;
-		unsigned short int indexSize,val,numberOfItems;
-		unsigned char* index;
 		//verify dat format
 		ok    = fread(&indexOffset,4,1,fp);
 		ok=ok&& fread(&indexSize,2,1,fp);
@@ -27,9 +36,9 @@ int prVerifyDatType(char* vFiledat) {
 			indexOffset+=indexSize;
 			fseek(fp,0,SEEK_END);
 			printf("jaaaj %d %d\r\n",indexOffset,ftell(fp));
-			char res=(ftell(fp)==indexOffset)?11:0; //see if it is a pop2 file
+			ok=(ftell(fp)==indexOffset)?11:0; //see if it is a pop2 file
 			fclose(fp);
-			return res; //this is a pop2 dat file or invalid
+			return ok; //this is a pop2 dat file or invalid
 		}
 		if ((index=getMemory(indexSize-2))==NULL) {
 			fclose(fp);
@@ -37,14 +46,8 @@ int prVerifyDatType(char* vFiledat) {
 		}
 		ok=fread(index,indexSize-2,1,fp);
 
-		//if header ok, new variables
-		unsigned short int offset;
-		unsigned long int  size;
-		unsigned char*     data;
-		unsigned char      type=5;
-
 		//main loop
-		for (int k=0;ok&&(k<numberOfItems)&&(type==5);k++) {
+		for (k=0;ok&&(k<numberOfItems)&&(type==5);k++) {
 			//for each archived file
 			ok=ok&&!(index[k*8+4]||index[k*8+5]);
 			offset=index[k*8+2]+256*index[k*8+3];