git » fp-git.git » commit 59f014e

o Ported the source to other platforms

author ecalot
2003-10-22 16:52:48 UTC
committer ecalot
2003-10-22 16:52:48 UTC
parent 12b766fd035bc6b2f32e6c2df43a87d5bc246828

o Ported the source to other platforms
o Removed a bug in RLE compression

PR/src/console/main.c +7 -3
PR/src/lib/actions/classify.c +15 -9
PR/src/lib/actions/export.c +16 -17
PR/src/lib/actions/import.c +31 -27
PR/src/lib/compression/rle_compress.c +41 -34
PR/src/lib/compression/rle_decompress.c +41 -34
PR/src/lib/compression/rlev_decompress.c +41 -34
PR/src/lib/layers/autodetect.c +19 -8
PR/src/lib/layers/idlist.c +19 -8
PR/src/lib/object/image/image16.c +41 -34
PR/src/lib/object/image/image2.c +41 -34
PR/src/lib/object/image/image256.c +41 -34
PR/src/lib/object/image/image_common.c +41 -34
PR/src/lib/pr.c +7 -3
PR/src/lib/xml/tree.c +19 -8
PR/src/lib/xml/unknown.c +19 -8
PR/src/parser.c +0 -2

diff --git a/PR/src/console/main.c b/PR/src/console/main.c
index eddc1b7..d9c048a 100644
--- a/PR/src/console/main.c
+++ b/PR/src/console/main.c
@@ -54,6 +54,9 @@ pr.c: Main source file for Princed Resources
 #include "compile.h"
 #include "tasks.h"
 
+#include "bmp.h"
+#include "memory.h"
+
 //functions
 
 int prExportDat(char* vDatFile, char* vDirName, char* vResFile) {
@@ -80,9 +83,10 @@ int prExportDatOpt(char* vDatFile, char* vDirName, char* vResFile,char opt) {
 	tResource* r[65536];
 	int a;
 	parseFile (vResFile,r);
-	//printf("kkkkkkkkkkk: %x\n",opt);
 	a=extract(vDatFile, vDirName,r,opt);
+	printf("termine B %d\n",a);
 	if (!(opt&8)) generateFile(vResFile,r);
+	printf("termine C %d\n",a);
 	return a;
 }
 
@@ -177,7 +181,7 @@ int main(int argc, char* argv[]) {
 				}
 			}
 			printf("Extracting '%s' to '%s' with %d\r\n",argv[1],dir,option);
-			printf("Result: %d\r\n",returnValue=prExportDatOpt(argv[1],dir,"resources.txt",option));
+			printf("Result: %d\r\n",returnValue=prExportDatOpt(argv[1],dir,"resources.txt",(char)option));
 			break;
 		case 'd': // get type of file.dat
 			printf("Classifing '%s'\r\n",argv[1]);
@@ -193,7 +197,7 @@ int main(int argc, char* argv[]) {
 					}
 				}
 			printf("Compiling '%s' from '%s' with %d\r\n",argv[1],dir,option);
-			printf("Result: %d\r\n",returnValue=prImportDatOpt(argv[1],dir,"resources.txt",option));
+			printf("Result: %d\r\n",returnValue=prImportDatOpt(argv[1],dir,"resources.txt",(char)option));
 			break;
 		case 't': // none --> resource.txt (destroy resource table)
 			printf("Clearing 'resources.txt'\r\n");
diff --git a/PR/src/lib/actions/classify.c b/PR/src/lib/actions/classify.c
index 56feb81..592d3da 100644
--- a/PR/src/lib/actions/classify.c
+++ b/PR/src/lib/actions/classify.c
@@ -2,24 +2,30 @@
 #include <stdio.h>
 #include "tasks.h"
 #include "memory.h"
+#include "resources.h"
+
+/***************************************************************\
+|                    Get the type of a DAT file                 |
+\***************************************************************/
 
 int prVerifyDatType(char* vFiledat) {
 
 	//Variables
-	FILE*         fp;
-  char          ok;
-  int 					k;
+	FILE*              fp;
+  char               ok;
+  int 					     k;
 
-	//if header ok, new variables
+	//variables in case header is ok
 	unsigned short int offset;
-	unsigned long int  size;
+	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;
+	unsigned long  int indexOffset;
+	unsigned short int indexSize;
+	unsigned short int numberOfItems;
+	unsigned char*     index;
 
 
 	if (ok=((fp=fopen(vFiledat,"rb"))!=NULL)) {
@@ -38,7 +44,7 @@ int prVerifyDatType(char* vFiledat) {
 			indexOffset+=indexSize;
 			fseek(fp,0,SEEK_END);
 			printf("jaaaj %d %d\r\n",indexOffset,ftell(fp));
-			ok=(ftell(fp)==indexOffset)?11:0; //see if it is a pop2 file
+			ok=(((unsigned long)ftell(fp))==indexOffset)?11:0; //see if it is a pop2 file
 			fclose(fp);
 			return ok; //this is a pop2 dat file or invalid
 		}
diff --git a/PR/src/lib/actions/export.c b/PR/src/lib/actions/export.c
index 380b096..456639d 100644
--- a/PR/src/lib/actions/export.c
+++ b/PR/src/lib/actions/export.c
@@ -1,7 +1,3 @@
-/***************************************************************\
-|                  I M P L E M E N T A T I O N                  |
-\***************************************************************/
-
 #include <stdio.h>
 #include "extract.h"
 #include "memory.h"
@@ -10,6 +6,10 @@
 #include "pal.h"
 #include "mid.h"
 
+/***************************************************************\
+|                  I M P L E M E N T A T I O N                  |
+\***************************************************************/
+
 char writeData(unsigned char* data, int ignoreChars, char* vFileext, int size) {
 	FILE*              target;
 	char ok;
@@ -53,13 +53,13 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) {
 		unsigned short int id;
 		unsigned long int  size,offset;
 		unsigned char*     data;
-		FILE*              target;
+//		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);
+	////printf("kkkkkkkkkkk: %x\n",task);
 
 		//verify dat format
 		ok    = fread(&indexOffset,4,1,fp);
@@ -71,7 +71,7 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) {
 		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);
+////printf("verificando pop2: numberOfItems=%d, indexSize=%d\r\n",numberOfItems,indexSize);
 		}
 		recordSize=pop1?8:11;
 		if (!ok) {
@@ -91,21 +91,19 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) {
 		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("verificando pop2: %d, k=%d, record size=%d\r\n",size,k,recordSize);
+				//printf("jajaA %d\r\n",ok);
 				ok=ok&&(index[ofk+k*recordSize+8]==0x40)&&(!index[ofk+k*recordSize+9])&&(!index[ofk+k*recordSize+10]);
-				printf("jajaB %d\r\n",ok);
+				//printf("jajaB %d\r\n",ok);
 			}
 			ok=ok&&((data=getMemory(size))!=NULL);
-				printf("jajaC %d offset=%d\r\n",ok,offset);
+				//printf("jajaC %d offset=%d\r\n",ok,offset);
 			ok=ok&&(!fseek(fp,offset,SEEK_SET));
-				printf("jajaD %d\r\n",ok);
+				//printf("jajaD %d\r\n",ok);
 			ok=ok&&fread(data,size,1,fp);
-				printf("jajaE %d\r\n",ok);
+				//printf("jajaEd %d\r\n",ok);
 			if (!ok) return -3;
 
 			//For the moment rebuilt option will be mandatory:
@@ -122,7 +120,7 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) {
 			if (r[id]==NULL) {
 				r[id]=(tResource*)malloc(sizeof(tResource));
 				(*(r[id])).size=(unsigned short int)size;
-				(*(r[id])).offset=offset;
+				(*(r[id])).offset=(unsigned short)offset;
 				sprintf((*(r[id])).file,aux);
 				(*(r[id])).desc=NULL;
 				(*(r[id])).coms=NULL;
@@ -134,7 +132,6 @@ int extract(char* vFiledat,char* vDirExt, tResource* r[], char task) {
 				if (task&4) (*(r[id])).type=0;
 				//save file
 				getFileName(vFileext,vDirExt,(*(r[id])).type,id);
-printf("voy por %s\n",vFileext);
 				switch ((*(r[id])).type) {
 					case 1:
 					case 5:
@@ -147,7 +144,6 @@ printf("voy por %s\n",vFileext);
 							mLoadPalette(data,&image);
 							isntImageSet=0;
 						}
-printf("paso el load palette\n");
 						ok=ok&&mFormatExtractPal(&data,vFileext,size);
 						break;
 					case 4:	//save midi file
@@ -158,12 +154,15 @@ printf("paso el load palette\n");
 						break;
 					case 2: //save image
 						ok=ok&&mFormatExtractBmp(data,vFileext,size,image);
+						//printf("sali\n");
 						break;
 				}
 			}
 			if (data!=NULL) free(data);
+			//printf("libere data que no era nula\n");
 		}
 		fclose(fp);
+		//printf("termine A %d\n",ok);
 		return ok;
 	} else {
 		return -1; //file could not be open
diff --git a/PR/src/lib/actions/import.c b/PR/src/lib/actions/import.c
index 1f0e1b9..88d9041 100644
--- a/PR/src/lib/actions/import.c
+++ b/PR/src/lib/actions/import.c
@@ -32,11 +32,11 @@ void mAddFileToDatFile(FILE* fp, char* data, int size) {
 	int k;
 	for (k=0;k<size;k++) checksum+=data[k];
 	checksum=~checksum;
-printf("llega X1\n");
+printf("mAddFileToDatFile: llega X1 size=%d\n",size);
 	//writes the header and the midi sound
 	fwrite(&checksum,1,1,fp);
 	fwrite(data,size,1,fp);
-printf("llega X2\n");
+printf("mAddFileToDatFile: llega X2\n");
 
 }
 
@@ -58,10 +58,10 @@ int mCreateIndexInDatFile(FILE* fp, tResource* r[], char* vUpperFile) {
 	int k=2;
 	unsigned short int tot=0;
 	unsigned short int junk=0;
+	unsigned short int i=0;
 	int pos=ftell(fp);
 
 	fwrite(&tot,2,1,fp);
-	unsigned short int i=0;
 	for (;i!=65535;i++) {
 		if (r[i]!=NULL) {
 			if (equals((*r[i]).file,vUpperFile)) {
@@ -81,34 +81,39 @@ int mCreateIndexInDatFile(FILE* fp, tResource* r[], char* vUpperFile) {
 }
 
 //Format detection function
-void mAddCompiledFileToDatFile(FILE* fp,unsigned char* data, tResource *res) {
+void mAddCompiledFileToDatFile(FILE* fp,unsigned char** data, tResource *res) {
+			printf("llega G size=%d\n",res->size);
+
 	switch ((*res).type) {
 		case 2: //compile bitmap
-			//printf("llega 1\n");
-			if (!mFormatCompileBmp(data,fp,res)) {
+			printf("llega 1\n");
+			printf("bitmap size in=%d\n",res->size);
+			if (!mFormatCompileBmp(*data,fp,res)) {
 				printf("Error!!\n");
 			}
+			printf("bitmap size out=%d\n",res->size);
 			break;
 		case 3: //compile wave
-			mFormatCompileWav(data,fp,res);
+			mFormatCompileWav(*data,fp,res);
 			break;
 		case 4: //compile midi
 			//send to mid
 			{
 			unsigned char* file;
-			file=getMemory(++(*res).size);
+			file=getMemory((*res).size);
 			file[0]=(*res).type-2;
-			memcpy(file+1,data,(*res).size-1);
+			memcpy(file+1,*data,(*res).size);
+			(*res).size++;
 			mAddFileToDatFile(fp,file,(*res).size);
 			free(file);
 			}
 			break;
 		case 6:
-			mImportPalette(&data,&((*res).size));
+			mImportPalette(data,&((*res).size));
 		case 1:
 		case 5:
 		default:
-			mAddFileToDatFile(fp,data,(*res).size);
+			mAddFileToDatFile(fp,*data,(*res).size);
 			break;
 	}
 }
@@ -139,39 +144,38 @@ char mSaveFile(char* vFile,unsigned char *d, int s) {
 */
 int compile(char* vFiledat, char* vDirExt, tResource* r[], char opt) {
 	FILE* fp;
+	char vUpperFile[200];
+	char vFileext[200];
+	unsigned char* data;
+	int ok=0;
+	unsigned short int i=0;
 
 	if (!mBeginDatFile(&fp,vFiledat)) {
 		printf("Error opening the file.\r\n");
 		return -1;
 	}
 
-	char vUpperFile[200];
-	char vFileext[200];
-	unsigned char* data;
-	int ok=0;
-
 	getUpperFolder(vUpperFile,vFiledat);
 
-	unsigned short int i=0;
 	for (;i!=65535;i++) {
 		if (r[i]!=NULL) {
 			if (equals((*r[i]).file,vUpperFile)) {
-				getFileName(vFileext,vDirExt,(opt&1)?(*(r[i])).type:0,i);
+				getFileName(vFileext,vDirExt,(char)((opt&1)?((*(r[i])).type):0),i);
 				//the file is in the archive, so I'll add it to the main dat body
 				if ((*r[i]).size=mLoadFileArray(vFileext,&data)) {
-					(*r[i]).offset=ftell(fp);
-					mAddCompiledFileToDatFile(fp,data,r[i]);
-
+					(*r[i]).offset=(unsigned short)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);
+					{
+						char sss[300];
+						sprintf(sss,"r1\\bmp%05d.raw",i);
+printf("size: id=%d size=%d %02x %02x %02x %02x %02x %02x %02x\n",i,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);
+					printf("libere ok\n");
 				} else {
 					ok++;
 				}
diff --git a/PR/src/lib/compression/rle_compress.c b/PR/src/lib/compression/rle_compress.c
index 921cef9..7f7d781 100644
--- a/PR/src/lib/compression/rle_compress.c
+++ b/PR/src/lib/compression/rle_compress.c
@@ -30,22 +30,23 @@ unsigned char popBit(unsigned char *byte) {
 
 //Expands B3/B4 algorithm
 void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) {
-printf("expandLzx %d %d \n",virtualSize,cursor);
 	int pos,h;
 	char k;
 	unsigned char maskbyte,rep;
-	for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos++]=0); //clean output garbage
+//printf("expandLzx %d %d \n",virtualSize,cursor);
+
+	for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos]=0,pos++); //clean output garbage
 	while (cursor<virtualSize) {
-		maskbyte=array[(*i)++];
+		maskbyte=array[*i];(*i)++;
 		for (k=8;k&&(cursor<virtualSize);k--) {
 			if (popBit(&maskbyte)) {
-				(*img).pix[cursor++]=array[(*i)++];
+				(*img).pix[cursor]=array[*i];(*i)++;cursor++;
 			} else {
-				pos=66+((0x100)*((rep=array[(*i)++])&3))+(unsigned char)array[(*i)++];
+				pos=66+((0x100)*((rep=array[*i])&3))+(unsigned char)array[(*i)+1];(*i)+=2;
 				rep=(rep>>2)+3;
 				while (rep--) { //Be careful in big images
 					h=cursor/MAX_MXD_SIZE_IN_LZX-(pos%MAX_MXD_SIZE_IN_LZX>cursor%MAX_MXD_SIZE_IN_LZX);
-					(*img).pix[cursor++]=(*img).pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZX+pos++%MAX_MXD_SIZE_IN_LZX];
+					(*img).pix[cursor]=(*img).pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZX+pos%MAX_MXD_SIZE_IN_LZX];cursor++;pos++;
 				}
 			}
 		}
@@ -54,36 +55,43 @@ printf("expandLzx %d %d \n",virtualSize,cursor);
 
 //Compress B1/B2 algorithm
 void compressRle(unsigned char* data,tImage* img,int *dataSize) {
-	printf("llega 3.51\n");
+//	//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");
+	//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)) {
+
+		while ((cursorPix<imgEnd)&&(*cursorPix!=*(cursorPix+1))&&((*counter)!=127)) {
+			cursorPix++;
 			(*counter)++;
-			*(cursorData++)=*(cursorPix-1);
+			*(cursorData)=*(cursorPix-1);
+			cursorData++;
 		}
-//printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd);
+////printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd);
 
-		cursorPix--;
+		//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
+			while ((cursorPix<imgEnd)&&(*cursorPix==(*(cursorPix+1)))&&((*counter)!=-128)) {
+				cursorPix++;
+				(*counter)--;
+			}
+			cursorPix++; //TODO poner esta linea abajo
+			*(cursorData)=*(cursorPix-1); //Print repeated char
+			cursorData++;
 		}
 	}
 	*(cursorData++)=0;
 	*(cursorData++)=*(cursorPix);
-//	printf("llega 3.59\n");
-
+//	//printf("compressRle: cursorData=%d data=%d cursorPix=%d imgEnd=%d\n",(int)cursorData,(int)data,(int)((*img).pix),(int)imgEnd);
 	*dataSize=(int)cursorData-(int)data;
 }
 
@@ -103,7 +111,7 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) {
 		 normaly: (* ignored types)
 		 checksum* - height - 00 - width - 00 - 00* - compression type
 	*/
-printf("expand graphic le ejecuta %d\n",virtualSize);
+////printf("expand graphic le ejecuta %d\n",virtualSize);
 
   int cursor=0;
   int i=1;
@@ -114,11 +122,11 @@ i=i+2;
 	image->width =((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]);
 i=i+2;
 	(*image).size  =(*image).height*(*image).width;
-printf("h=%d, w=%d %x %x %x %x   \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]);
+//printf("h=%d, w=%d %x %x %x %x   \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]);
 	virtualSize=(((*image).height*((*image).width+((*image).width&1)))>>1);
 	i++;
 
-printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize);
+//printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize);
   switch ((unsigned char)array[i++]) {
 		case PG_COMP_RAW: //No Compression Algorithm
 		  if (((*image).pix=getMemory(virtualSize))==NULL) return -1;
@@ -155,18 +163,18 @@ printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize);
 			}
 			break;
 		case PG_COMP_LZX_LR: //LZ Groody Up to Down Version Compression Algorithm
-		printf("llega b4\n");
+		//printf("llega b4\n");
 		  if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1;
 			expandLzx(array,image,&i,cursor,virtualSize);
 			break;
 		case PG_COMP_LZX_UD: //LZ Groody Left to Right Version Compression Algorithm
-printf("hi\n");
+//printf("hi\n");
 		  if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1;
 			{
 			unsigned char* outputaux=getMemory(virtualSize);
-			printf("antes\n");
+			//printf("antes\n");
 			expandLzx(array,image,&i,cursor,virtualSize);
-			printf("despues\n");
+			//printf("despues\n");
 			//Transpose
 		  while (cursor<virtualSize) outputaux[transpose(cursor,(*image).width,(*image).height)]=(*image).pix[cursor++];
 			free((*image).pix);
@@ -182,9 +190,9 @@ printf("hi\n");
 //Compress an image into an array in the most quick & dirty way
 int mCompressGraphic(unsigned char* data,tImage i, int* size) {
 	int dataSize;
-//	unsigned char* data;
+	//unsigned char* a;
+/*
 
-	/*
 	*size=(i.size/2)+6;
 	a=getMemory(*size);
 	//height - 00 - width - 00 - 00 - compression type
@@ -197,15 +205,16 @@ int mCompressGraphic(unsigned char* data,tImage i, int* size) {
 	a[4]=0;
 	a[5]=0xB0; // how q&d I am :)
 
-	memcpy(i.pix,a+6,*size); //TODO it should be a+6,i.pix
+	memcpy(a+6,i.pix,*size); //TODO it should be a+6,i.pix
 	*/
-//printf("llega 3\n");
+////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");
+////printf("llega 3.3\n");
+#if 1
 	compressRle(data+6,&i,&dataSize);
-//printf("llega 3.6\n");
+//printf("mCompressGraphic: size=%d\n",dataSize);
 	//a=getMemory(*size=(dataSize+6));
-//printf("llega 4\n");
+////printf("llega 4\n");
 	/*
 		Header Settings:
 		height - 00 - width - 00 - 00 - compression type
@@ -219,12 +228,10 @@ int mCompressGraphic(unsigned char* data,tImage i, int* size) {
 	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]);
-
+////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]);
 
+#endif
 	return 1;
 }
 
diff --git a/PR/src/lib/compression/rle_decompress.c b/PR/src/lib/compression/rle_decompress.c
index 921cef9..7f7d781 100644
--- a/PR/src/lib/compression/rle_decompress.c
+++ b/PR/src/lib/compression/rle_decompress.c
@@ -30,22 +30,23 @@ unsigned char popBit(unsigned char *byte) {
 
 //Expands B3/B4 algorithm
 void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) {
-printf("expandLzx %d %d \n",virtualSize,cursor);
 	int pos,h;
 	char k;
 	unsigned char maskbyte,rep;
-	for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos++]=0); //clean output garbage
+//printf("expandLzx %d %d \n",virtualSize,cursor);
+
+	for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos]=0,pos++); //clean output garbage
 	while (cursor<virtualSize) {
-		maskbyte=array[(*i)++];
+		maskbyte=array[*i];(*i)++;
 		for (k=8;k&&(cursor<virtualSize);k--) {
 			if (popBit(&maskbyte)) {
-				(*img).pix[cursor++]=array[(*i)++];
+				(*img).pix[cursor]=array[*i];(*i)++;cursor++;
 			} else {
-				pos=66+((0x100)*((rep=array[(*i)++])&3))+(unsigned char)array[(*i)++];
+				pos=66+((0x100)*((rep=array[*i])&3))+(unsigned char)array[(*i)+1];(*i)+=2;
 				rep=(rep>>2)+3;
 				while (rep--) { //Be careful in big images
 					h=cursor/MAX_MXD_SIZE_IN_LZX-(pos%MAX_MXD_SIZE_IN_LZX>cursor%MAX_MXD_SIZE_IN_LZX);
-					(*img).pix[cursor++]=(*img).pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZX+pos++%MAX_MXD_SIZE_IN_LZX];
+					(*img).pix[cursor]=(*img).pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZX+pos%MAX_MXD_SIZE_IN_LZX];cursor++;pos++;
 				}
 			}
 		}
@@ -54,36 +55,43 @@ printf("expandLzx %d %d \n",virtualSize,cursor);
 
 //Compress B1/B2 algorithm
 void compressRle(unsigned char* data,tImage* img,int *dataSize) {
-	printf("llega 3.51\n");
+//	//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");
+	//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)) {
+
+		while ((cursorPix<imgEnd)&&(*cursorPix!=*(cursorPix+1))&&((*counter)!=127)) {
+			cursorPix++;
 			(*counter)++;
-			*(cursorData++)=*(cursorPix-1);
+			*(cursorData)=*(cursorPix-1);
+			cursorData++;
 		}
-//printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd);
+////printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd);
 
-		cursorPix--;
+		//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
+			while ((cursorPix<imgEnd)&&(*cursorPix==(*(cursorPix+1)))&&((*counter)!=-128)) {
+				cursorPix++;
+				(*counter)--;
+			}
+			cursorPix++; //TODO poner esta linea abajo
+			*(cursorData)=*(cursorPix-1); //Print repeated char
+			cursorData++;
 		}
 	}
 	*(cursorData++)=0;
 	*(cursorData++)=*(cursorPix);
-//	printf("llega 3.59\n");
-
+//	//printf("compressRle: cursorData=%d data=%d cursorPix=%d imgEnd=%d\n",(int)cursorData,(int)data,(int)((*img).pix),(int)imgEnd);
 	*dataSize=(int)cursorData-(int)data;
 }
 
@@ -103,7 +111,7 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) {
 		 normaly: (* ignored types)
 		 checksum* - height - 00 - width - 00 - 00* - compression type
 	*/
-printf("expand graphic le ejecuta %d\n",virtualSize);
+////printf("expand graphic le ejecuta %d\n",virtualSize);
 
   int cursor=0;
   int i=1;
@@ -114,11 +122,11 @@ i=i+2;
 	image->width =((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]);
 i=i+2;
 	(*image).size  =(*image).height*(*image).width;
-printf("h=%d, w=%d %x %x %x %x   \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]);
+//printf("h=%d, w=%d %x %x %x %x   \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]);
 	virtualSize=(((*image).height*((*image).width+((*image).width&1)))>>1);
 	i++;
 
-printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize);
+//printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize);
   switch ((unsigned char)array[i++]) {
 		case PG_COMP_RAW: //No Compression Algorithm
 		  if (((*image).pix=getMemory(virtualSize))==NULL) return -1;
@@ -155,18 +163,18 @@ printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize);
 			}
 			break;
 		case PG_COMP_LZX_LR: //LZ Groody Up to Down Version Compression Algorithm
-		printf("llega b4\n");
+		//printf("llega b4\n");
 		  if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1;
 			expandLzx(array,image,&i,cursor,virtualSize);
 			break;
 		case PG_COMP_LZX_UD: //LZ Groody Left to Right Version Compression Algorithm
-printf("hi\n");
+//printf("hi\n");
 		  if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1;
 			{
 			unsigned char* outputaux=getMemory(virtualSize);
-			printf("antes\n");
+			//printf("antes\n");
 			expandLzx(array,image,&i,cursor,virtualSize);
-			printf("despues\n");
+			//printf("despues\n");
 			//Transpose
 		  while (cursor<virtualSize) outputaux[transpose(cursor,(*image).width,(*image).height)]=(*image).pix[cursor++];
 			free((*image).pix);
@@ -182,9 +190,9 @@ printf("hi\n");
 //Compress an image into an array in the most quick & dirty way
 int mCompressGraphic(unsigned char* data,tImage i, int* size) {
 	int dataSize;
-//	unsigned char* data;
+	//unsigned char* a;
+/*
 
-	/*
 	*size=(i.size/2)+6;
 	a=getMemory(*size);
 	//height - 00 - width - 00 - 00 - compression type
@@ -197,15 +205,16 @@ int mCompressGraphic(unsigned char* data,tImage i, int* size) {
 	a[4]=0;
 	a[5]=0xB0; // how q&d I am :)
 
-	memcpy(i.pix,a+6,*size); //TODO it should be a+6,i.pix
+	memcpy(a+6,i.pix,*size); //TODO it should be a+6,i.pix
 	*/
-//printf("llega 3\n");
+////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");
+////printf("llega 3.3\n");
+#if 1
 	compressRle(data+6,&i,&dataSize);
-//printf("llega 3.6\n");
+//printf("mCompressGraphic: size=%d\n",dataSize);
 	//a=getMemory(*size=(dataSize+6));
-//printf("llega 4\n");
+////printf("llega 4\n");
 	/*
 		Header Settings:
 		height - 00 - width - 00 - 00 - compression type
@@ -219,12 +228,10 @@ int mCompressGraphic(unsigned char* data,tImage i, int* size) {
 	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]);
-
+////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]);
 
+#endif
 	return 1;
 }
 
diff --git a/PR/src/lib/compression/rlev_decompress.c b/PR/src/lib/compression/rlev_decompress.c
index 921cef9..7f7d781 100644
--- a/PR/src/lib/compression/rlev_decompress.c
+++ b/PR/src/lib/compression/rlev_decompress.c
@@ -30,22 +30,23 @@ unsigned char popBit(unsigned char *byte) {
 
 //Expands B3/B4 algorithm
 void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) {
-printf("expandLzx %d %d \n",virtualSize,cursor);
 	int pos,h;
 	char k;
 	unsigned char maskbyte,rep;
-	for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos++]=0); //clean output garbage
+//printf("expandLzx %d %d \n",virtualSize,cursor);
+
+	for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos]=0,pos++); //clean output garbage
 	while (cursor<virtualSize) {
-		maskbyte=array[(*i)++];
+		maskbyte=array[*i];(*i)++;
 		for (k=8;k&&(cursor<virtualSize);k--) {
 			if (popBit(&maskbyte)) {
-				(*img).pix[cursor++]=array[(*i)++];
+				(*img).pix[cursor]=array[*i];(*i)++;cursor++;
 			} else {
-				pos=66+((0x100)*((rep=array[(*i)++])&3))+(unsigned char)array[(*i)++];
+				pos=66+((0x100)*((rep=array[*i])&3))+(unsigned char)array[(*i)+1];(*i)+=2;
 				rep=(rep>>2)+3;
 				while (rep--) { //Be careful in big images
 					h=cursor/MAX_MXD_SIZE_IN_LZX-(pos%MAX_MXD_SIZE_IN_LZX>cursor%MAX_MXD_SIZE_IN_LZX);
-					(*img).pix[cursor++]=(*img).pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZX+pos++%MAX_MXD_SIZE_IN_LZX];
+					(*img).pix[cursor]=(*img).pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZX+pos%MAX_MXD_SIZE_IN_LZX];cursor++;pos++;
 				}
 			}
 		}
@@ -54,36 +55,43 @@ printf("expandLzx %d %d \n",virtualSize,cursor);
 
 //Compress B1/B2 algorithm
 void compressRle(unsigned char* data,tImage* img,int *dataSize) {
-	printf("llega 3.51\n");
+//	//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");
+	//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)) {
+
+		while ((cursorPix<imgEnd)&&(*cursorPix!=*(cursorPix+1))&&((*counter)!=127)) {
+			cursorPix++;
 			(*counter)++;
-			*(cursorData++)=*(cursorPix-1);
+			*(cursorData)=*(cursorPix-1);
+			cursorData++;
 		}
-//printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd);
+////printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd);
 
-		cursorPix--;
+		//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
+			while ((cursorPix<imgEnd)&&(*cursorPix==(*(cursorPix+1)))&&((*counter)!=-128)) {
+				cursorPix++;
+				(*counter)--;
+			}
+			cursorPix++; //TODO poner esta linea abajo
+			*(cursorData)=*(cursorPix-1); //Print repeated char
+			cursorData++;
 		}
 	}
 	*(cursorData++)=0;
 	*(cursorData++)=*(cursorPix);
-//	printf("llega 3.59\n");
-
+//	//printf("compressRle: cursorData=%d data=%d cursorPix=%d imgEnd=%d\n",(int)cursorData,(int)data,(int)((*img).pix),(int)imgEnd);
 	*dataSize=(int)cursorData-(int)data;
 }
 
@@ -103,7 +111,7 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) {
 		 normaly: (* ignored types)
 		 checksum* - height - 00 - width - 00 - 00* - compression type
 	*/
-printf("expand graphic le ejecuta %d\n",virtualSize);
+////printf("expand graphic le ejecuta %d\n",virtualSize);
 
   int cursor=0;
   int i=1;
@@ -114,11 +122,11 @@ i=i+2;
 	image->width =((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]);
 i=i+2;
 	(*image).size  =(*image).height*(*image).width;
-printf("h=%d, w=%d %x %x %x %x   \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]);
+//printf("h=%d, w=%d %x %x %x %x   \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]);
 	virtualSize=(((*image).height*((*image).width+((*image).width&1)))>>1);
 	i++;
 
-printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize);
+//printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize);
   switch ((unsigned char)array[i++]) {
 		case PG_COMP_RAW: //No Compression Algorithm
 		  if (((*image).pix=getMemory(virtualSize))==NULL) return -1;
@@ -155,18 +163,18 @@ printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize);
 			}
 			break;
 		case PG_COMP_LZX_LR: //LZ Groody Up to Down Version Compression Algorithm
-		printf("llega b4\n");
+		//printf("llega b4\n");
 		  if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1;
 			expandLzx(array,image,&i,cursor,virtualSize);
 			break;
 		case PG_COMP_LZX_UD: //LZ Groody Left to Right Version Compression Algorithm
-printf("hi\n");
+//printf("hi\n");
 		  if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1;
 			{
 			unsigned char* outputaux=getMemory(virtualSize);
-			printf("antes\n");
+			//printf("antes\n");
 			expandLzx(array,image,&i,cursor,virtualSize);
-			printf("despues\n");
+			//printf("despues\n");
 			//Transpose
 		  while (cursor<virtualSize) outputaux[transpose(cursor,(*image).width,(*image).height)]=(*image).pix[cursor++];
 			free((*image).pix);
@@ -182,9 +190,9 @@ printf("hi\n");
 //Compress an image into an array in the most quick & dirty way
 int mCompressGraphic(unsigned char* data,tImage i, int* size) {
 	int dataSize;
-//	unsigned char* data;
+	//unsigned char* a;
+/*
 
-	/*
 	*size=(i.size/2)+6;
 	a=getMemory(*size);
 	//height - 00 - width - 00 - 00 - compression type
@@ -197,15 +205,16 @@ int mCompressGraphic(unsigned char* data,tImage i, int* size) {
 	a[4]=0;
 	a[5]=0xB0; // how q&d I am :)
 
-	memcpy(i.pix,a+6,*size); //TODO it should be a+6,i.pix
+	memcpy(a+6,i.pix,*size); //TODO it should be a+6,i.pix
 	*/
-//printf("llega 3\n");
+////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");
+////printf("llega 3.3\n");
+#if 1
 	compressRle(data+6,&i,&dataSize);
-//printf("llega 3.6\n");
+//printf("mCompressGraphic: size=%d\n",dataSize);
 	//a=getMemory(*size=(dataSize+6));
-//printf("llega 4\n");
+////printf("llega 4\n");
 	/*
 		Header Settings:
 		height - 00 - width - 00 - 00 - compression type
@@ -219,12 +228,10 @@ int mCompressGraphic(unsigned char* data,tImage i, int* size) {
 	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]);
-
+////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]);
 
+#endif
 	return 1;
 }
 
diff --git a/PR/src/lib/layers/autodetect.c b/PR/src/lib/layers/autodetect.c
index fd30a5f..3b9dec3 100644
--- a/PR/src/lib/layers/autodetect.c
+++ b/PR/src/lib/layers/autodetect.c
@@ -1,6 +1,6 @@
 
 
-//Needed files
+//Includes
 #include <stdio.h>
 #include <stdlib.h>
 #include "pr.h"
@@ -62,12 +62,11 @@ char verifyHeader(char* array, int size) {
 //Parse line
 void parseResource(tResource* r[], char* line) {
 	//declare variables
-	int i=0;
+	int                i=0;
+	int                k=0;
 	unsigned short int id,ty;
-	int k=0;
 
 	//Begin parsing
-
 	for (;!(line[k]=='\r'||line[k]=='\n'||(!line[k]));k++);
 	line[k]=0;
 
@@ -88,7 +87,7 @@ void parseResource(tResource* r[], char* line) {
 		} else {
 			(*(r[id])).desc=NULL;
 		}
-		(*(r[id])).type=ty;
+		(*(r[id])).type=(char)ty;
 	}
 }
 
@@ -102,7 +101,6 @@ char parseFile(char* vFile,tResource* r[]) {
 	//declare variables
 	char parsing=0;
 	char line[MAX_LINE_SIZE];
-	char token[MAX_LINE_SIZE];
 	char B[]=BEGIN_TABLE;
 	char E[]=END_TABLE;
 	FILE* fp;
@@ -141,6 +139,9 @@ char generateFile(char* vFile,tResource* r[]) {
 	char none[]="";
 	FILE* fp;
 	FILE* source;
+	int id=0;
+
+//printf("hola vengo a generar el archivo\n");
 
 	if ((fp=fopen("res.tmp","wt"))!=NULL) {
 		//insert headers
@@ -160,19 +161,26 @@ char generateFile(char* vFile,tResource* r[]) {
 			}
 		}
 
+//printf("se abrio res.tmp y se parse\xf3 el principio\n");
+
 		//insert main body file
 		fputs(B,fp);
 		fputs("\n",fp);
-		int id=0;
+////printf("r -> A\n");
+
 		for (;id<65536;id++) {
+////printf("r -> B %d %p\n",id,r[id]);
+
 			if (r[id]!=NULL) {
-				if ((*(r[id])).desc==NULL) {
+				if (1||((*(r[id])).desc==NULL)) { //todo see this line
+////printf("r -> G %d %p\n",id,r[id]);
 					if ((*(r[id])).coms==NULL) {
 						sprintf(coms,none);
 					} else {
 						sprintf(coms," #",(*(r[id])).coms);
 					}
 				} else {
+////printf("r -> E %d %p\n",id,r[id]);
 					if ((*(r[id])).coms==NULL) {
 						sprintf(coms," %s",(*(r[id])).desc);
 					} else {
@@ -192,6 +200,8 @@ char generateFile(char* vFile,tResource* r[]) {
 		fputs("\n",fp);
 		fputs(E,fp);
 
+//printf("se inserto el cuerpo de los recursos\n");
+
 		//insert footers
 		if (source!=NULL) {
 			while ((parsing==2) && (fgets(line,MAX_LINE_SIZE,source)!=NULL)) {
@@ -283,6 +293,7 @@ int mLoadFileArray(char* vFile,unsigned char** array) {
 			//if the filewas succesfully open
 			fseek(fp,0,SEEK_SET);
 			aux=fread (*array,1,aux,fp);
+			//printf("que me decis a mi, yo devolvi %d\n",aux);
 			fclose(fp);
 			return aux;
 		}
diff --git a/PR/src/lib/layers/idlist.c b/PR/src/lib/layers/idlist.c
index fd30a5f..3b9dec3 100644
--- a/PR/src/lib/layers/idlist.c
+++ b/PR/src/lib/layers/idlist.c
@@ -1,6 +1,6 @@
 
 
-//Needed files
+//Includes
 #include <stdio.h>
 #include <stdlib.h>
 #include "pr.h"
@@ -62,12 +62,11 @@ char verifyHeader(char* array, int size) {
 //Parse line
 void parseResource(tResource* r[], char* line) {
 	//declare variables
-	int i=0;
+	int                i=0;
+	int                k=0;
 	unsigned short int id,ty;
-	int k=0;
 
 	//Begin parsing
-
 	for (;!(line[k]=='\r'||line[k]=='\n'||(!line[k]));k++);
 	line[k]=0;
 
@@ -88,7 +87,7 @@ void parseResource(tResource* r[], char* line) {
 		} else {
 			(*(r[id])).desc=NULL;
 		}
-		(*(r[id])).type=ty;
+		(*(r[id])).type=(char)ty;
 	}
 }
 
@@ -102,7 +101,6 @@ char parseFile(char* vFile,tResource* r[]) {
 	//declare variables
 	char parsing=0;
 	char line[MAX_LINE_SIZE];
-	char token[MAX_LINE_SIZE];
 	char B[]=BEGIN_TABLE;
 	char E[]=END_TABLE;
 	FILE* fp;
@@ -141,6 +139,9 @@ char generateFile(char* vFile,tResource* r[]) {
 	char none[]="";
 	FILE* fp;
 	FILE* source;
+	int id=0;
+
+//printf("hola vengo a generar el archivo\n");
 
 	if ((fp=fopen("res.tmp","wt"))!=NULL) {
 		//insert headers
@@ -160,19 +161,26 @@ char generateFile(char* vFile,tResource* r[]) {
 			}
 		}
 
+//printf("se abrio res.tmp y se parse\xf3 el principio\n");
+
 		//insert main body file
 		fputs(B,fp);
 		fputs("\n",fp);
-		int id=0;
+////printf("r -> A\n");
+
 		for (;id<65536;id++) {
+////printf("r -> B %d %p\n",id,r[id]);
+
 			if (r[id]!=NULL) {
-				if ((*(r[id])).desc==NULL) {
+				if (1||((*(r[id])).desc==NULL)) { //todo see this line
+////printf("r -> G %d %p\n",id,r[id]);
 					if ((*(r[id])).coms==NULL) {
 						sprintf(coms,none);
 					} else {
 						sprintf(coms," #",(*(r[id])).coms);
 					}
 				} else {
+////printf("r -> E %d %p\n",id,r[id]);
 					if ((*(r[id])).coms==NULL) {
 						sprintf(coms," %s",(*(r[id])).desc);
 					} else {
@@ -192,6 +200,8 @@ char generateFile(char* vFile,tResource* r[]) {
 		fputs("\n",fp);
 		fputs(E,fp);
 
+//printf("se inserto el cuerpo de los recursos\n");
+
 		//insert footers
 		if (source!=NULL) {
 			while ((parsing==2) && (fgets(line,MAX_LINE_SIZE,source)!=NULL)) {
@@ -283,6 +293,7 @@ int mLoadFileArray(char* vFile,unsigned char** array) {
 			//if the filewas succesfully open
 			fseek(fp,0,SEEK_SET);
 			aux=fread (*array,1,aux,fp);
+			//printf("que me decis a mi, yo devolvi %d\n",aux);
 			fclose(fp);
 			return aux;
 		}
diff --git a/PR/src/lib/object/image/image16.c b/PR/src/lib/object/image/image16.c
index 921cef9..7f7d781 100644
--- a/PR/src/lib/object/image/image16.c
+++ b/PR/src/lib/object/image/image16.c
@@ -30,22 +30,23 @@ unsigned char popBit(unsigned char *byte) {
 
 //Expands B3/B4 algorithm
 void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) {
-printf("expandLzx %d %d \n",virtualSize,cursor);
 	int pos,h;
 	char k;
 	unsigned char maskbyte,rep;
-	for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos++]=0); //clean output garbage
+//printf("expandLzx %d %d \n",virtualSize,cursor);
+
+	for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos]=0,pos++); //clean output garbage
 	while (cursor<virtualSize) {
-		maskbyte=array[(*i)++];
+		maskbyte=array[*i];(*i)++;
 		for (k=8;k&&(cursor<virtualSize);k--) {
 			if (popBit(&maskbyte)) {
-				(*img).pix[cursor++]=array[(*i)++];
+				(*img).pix[cursor]=array[*i];(*i)++;cursor++;
 			} else {
-				pos=66+((0x100)*((rep=array[(*i)++])&3))+(unsigned char)array[(*i)++];
+				pos=66+((0x100)*((rep=array[*i])&3))+(unsigned char)array[(*i)+1];(*i)+=2;
 				rep=(rep>>2)+3;
 				while (rep--) { //Be careful in big images
 					h=cursor/MAX_MXD_SIZE_IN_LZX-(pos%MAX_MXD_SIZE_IN_LZX>cursor%MAX_MXD_SIZE_IN_LZX);
-					(*img).pix[cursor++]=(*img).pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZX+pos++%MAX_MXD_SIZE_IN_LZX];
+					(*img).pix[cursor]=(*img).pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZX+pos%MAX_MXD_SIZE_IN_LZX];cursor++;pos++;
 				}
 			}
 		}
@@ -54,36 +55,43 @@ printf("expandLzx %d %d \n",virtualSize,cursor);
 
 //Compress B1/B2 algorithm
 void compressRle(unsigned char* data,tImage* img,int *dataSize) {
-	printf("llega 3.51\n");
+//	//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");
+	//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)) {
+
+		while ((cursorPix<imgEnd)&&(*cursorPix!=*(cursorPix+1))&&((*counter)!=127)) {
+			cursorPix++;
 			(*counter)++;
-			*(cursorData++)=*(cursorPix-1);
+			*(cursorData)=*(cursorPix-1);
+			cursorData++;
 		}
-//printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd);
+////printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd);
 
-		cursorPix--;
+		//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
+			while ((cursorPix<imgEnd)&&(*cursorPix==(*(cursorPix+1)))&&((*counter)!=-128)) {
+				cursorPix++;
+				(*counter)--;
+			}
+			cursorPix++; //TODO poner esta linea abajo
+			*(cursorData)=*(cursorPix-1); //Print repeated char
+			cursorData++;
 		}
 	}
 	*(cursorData++)=0;
 	*(cursorData++)=*(cursorPix);
-//	printf("llega 3.59\n");
-
+//	//printf("compressRle: cursorData=%d data=%d cursorPix=%d imgEnd=%d\n",(int)cursorData,(int)data,(int)((*img).pix),(int)imgEnd);
 	*dataSize=(int)cursorData-(int)data;
 }
 
@@ -103,7 +111,7 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) {
 		 normaly: (* ignored types)
 		 checksum* - height - 00 - width - 00 - 00* - compression type
 	*/
-printf("expand graphic le ejecuta %d\n",virtualSize);
+////printf("expand graphic le ejecuta %d\n",virtualSize);
 
   int cursor=0;
   int i=1;
@@ -114,11 +122,11 @@ i=i+2;
 	image->width =((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]);
 i=i+2;
 	(*image).size  =(*image).height*(*image).width;
-printf("h=%d, w=%d %x %x %x %x   \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]);
+//printf("h=%d, w=%d %x %x %x %x   \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]);
 	virtualSize=(((*image).height*((*image).width+((*image).width&1)))>>1);
 	i++;
 
-printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize);
+//printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize);
   switch ((unsigned char)array[i++]) {
 		case PG_COMP_RAW: //No Compression Algorithm
 		  if (((*image).pix=getMemory(virtualSize))==NULL) return -1;
@@ -155,18 +163,18 @@ printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize);
 			}
 			break;
 		case PG_COMP_LZX_LR: //LZ Groody Up to Down Version Compression Algorithm
-		printf("llega b4\n");
+		//printf("llega b4\n");
 		  if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1;
 			expandLzx(array,image,&i,cursor,virtualSize);
 			break;
 		case PG_COMP_LZX_UD: //LZ Groody Left to Right Version Compression Algorithm
-printf("hi\n");
+//printf("hi\n");
 		  if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1;
 			{
 			unsigned char* outputaux=getMemory(virtualSize);
-			printf("antes\n");
+			//printf("antes\n");
 			expandLzx(array,image,&i,cursor,virtualSize);
-			printf("despues\n");
+			//printf("despues\n");
 			//Transpose
 		  while (cursor<virtualSize) outputaux[transpose(cursor,(*image).width,(*image).height)]=(*image).pix[cursor++];
 			free((*image).pix);
@@ -182,9 +190,9 @@ printf("hi\n");
 //Compress an image into an array in the most quick & dirty way
 int mCompressGraphic(unsigned char* data,tImage i, int* size) {
 	int dataSize;
-//	unsigned char* data;
+	//unsigned char* a;
+/*
 
-	/*
 	*size=(i.size/2)+6;
 	a=getMemory(*size);
 	//height - 00 - width - 00 - 00 - compression type
@@ -197,15 +205,16 @@ int mCompressGraphic(unsigned char* data,tImage i, int* size) {
 	a[4]=0;
 	a[5]=0xB0; // how q&d I am :)
 
-	memcpy(i.pix,a+6,*size); //TODO it should be a+6,i.pix
+	memcpy(a+6,i.pix,*size); //TODO it should be a+6,i.pix
 	*/
-//printf("llega 3\n");
+////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");
+////printf("llega 3.3\n");
+#if 1
 	compressRle(data+6,&i,&dataSize);
-//printf("llega 3.6\n");
+//printf("mCompressGraphic: size=%d\n",dataSize);
 	//a=getMemory(*size=(dataSize+6));
-//printf("llega 4\n");
+////printf("llega 4\n");
 	/*
 		Header Settings:
 		height - 00 - width - 00 - 00 - compression type
@@ -219,12 +228,10 @@ int mCompressGraphic(unsigned char* data,tImage i, int* size) {
 	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]);
-
+////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]);
 
+#endif
 	return 1;
 }
 
diff --git a/PR/src/lib/object/image/image2.c b/PR/src/lib/object/image/image2.c
index 921cef9..7f7d781 100644
--- a/PR/src/lib/object/image/image2.c
+++ b/PR/src/lib/object/image/image2.c
@@ -30,22 +30,23 @@ unsigned char popBit(unsigned char *byte) {
 
 //Expands B3/B4 algorithm
 void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) {
-printf("expandLzx %d %d \n",virtualSize,cursor);
 	int pos,h;
 	char k;
 	unsigned char maskbyte,rep;
-	for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos++]=0); //clean output garbage
+//printf("expandLzx %d %d \n",virtualSize,cursor);
+
+	for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos]=0,pos++); //clean output garbage
 	while (cursor<virtualSize) {
-		maskbyte=array[(*i)++];
+		maskbyte=array[*i];(*i)++;
 		for (k=8;k&&(cursor<virtualSize);k--) {
 			if (popBit(&maskbyte)) {
-				(*img).pix[cursor++]=array[(*i)++];
+				(*img).pix[cursor]=array[*i];(*i)++;cursor++;
 			} else {
-				pos=66+((0x100)*((rep=array[(*i)++])&3))+(unsigned char)array[(*i)++];
+				pos=66+((0x100)*((rep=array[*i])&3))+(unsigned char)array[(*i)+1];(*i)+=2;
 				rep=(rep>>2)+3;
 				while (rep--) { //Be careful in big images
 					h=cursor/MAX_MXD_SIZE_IN_LZX-(pos%MAX_MXD_SIZE_IN_LZX>cursor%MAX_MXD_SIZE_IN_LZX);
-					(*img).pix[cursor++]=(*img).pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZX+pos++%MAX_MXD_SIZE_IN_LZX];
+					(*img).pix[cursor]=(*img).pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZX+pos%MAX_MXD_SIZE_IN_LZX];cursor++;pos++;
 				}
 			}
 		}
@@ -54,36 +55,43 @@ printf("expandLzx %d %d \n",virtualSize,cursor);
 
 //Compress B1/B2 algorithm
 void compressRle(unsigned char* data,tImage* img,int *dataSize) {
-	printf("llega 3.51\n");
+//	//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");
+	//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)) {
+
+		while ((cursorPix<imgEnd)&&(*cursorPix!=*(cursorPix+1))&&((*counter)!=127)) {
+			cursorPix++;
 			(*counter)++;
-			*(cursorData++)=*(cursorPix-1);
+			*(cursorData)=*(cursorPix-1);
+			cursorData++;
 		}
-//printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd);
+////printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd);
 
-		cursorPix--;
+		//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
+			while ((cursorPix<imgEnd)&&(*cursorPix==(*(cursorPix+1)))&&((*counter)!=-128)) {
+				cursorPix++;
+				(*counter)--;
+			}
+			cursorPix++; //TODO poner esta linea abajo
+			*(cursorData)=*(cursorPix-1); //Print repeated char
+			cursorData++;
 		}
 	}
 	*(cursorData++)=0;
 	*(cursorData++)=*(cursorPix);
-//	printf("llega 3.59\n");
-
+//	//printf("compressRle: cursorData=%d data=%d cursorPix=%d imgEnd=%d\n",(int)cursorData,(int)data,(int)((*img).pix),(int)imgEnd);
 	*dataSize=(int)cursorData-(int)data;
 }
 
@@ -103,7 +111,7 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) {
 		 normaly: (* ignored types)
 		 checksum* - height - 00 - width - 00 - 00* - compression type
 	*/
-printf("expand graphic le ejecuta %d\n",virtualSize);
+////printf("expand graphic le ejecuta %d\n",virtualSize);
 
   int cursor=0;
   int i=1;
@@ -114,11 +122,11 @@ i=i+2;
 	image->width =((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]);
 i=i+2;
 	(*image).size  =(*image).height*(*image).width;
-printf("h=%d, w=%d %x %x %x %x   \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]);
+//printf("h=%d, w=%d %x %x %x %x   \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]);
 	virtualSize=(((*image).height*((*image).width+((*image).width&1)))>>1);
 	i++;
 
-printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize);
+//printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize);
   switch ((unsigned char)array[i++]) {
 		case PG_COMP_RAW: //No Compression Algorithm
 		  if (((*image).pix=getMemory(virtualSize))==NULL) return -1;
@@ -155,18 +163,18 @@ printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize);
 			}
 			break;
 		case PG_COMP_LZX_LR: //LZ Groody Up to Down Version Compression Algorithm
-		printf("llega b4\n");
+		//printf("llega b4\n");
 		  if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1;
 			expandLzx(array,image,&i,cursor,virtualSize);
 			break;
 		case PG_COMP_LZX_UD: //LZ Groody Left to Right Version Compression Algorithm
-printf("hi\n");
+//printf("hi\n");
 		  if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1;
 			{
 			unsigned char* outputaux=getMemory(virtualSize);
-			printf("antes\n");
+			//printf("antes\n");
 			expandLzx(array,image,&i,cursor,virtualSize);
-			printf("despues\n");
+			//printf("despues\n");
 			//Transpose
 		  while (cursor<virtualSize) outputaux[transpose(cursor,(*image).width,(*image).height)]=(*image).pix[cursor++];
 			free((*image).pix);
@@ -182,9 +190,9 @@ printf("hi\n");
 //Compress an image into an array in the most quick & dirty way
 int mCompressGraphic(unsigned char* data,tImage i, int* size) {
 	int dataSize;
-//	unsigned char* data;
+	//unsigned char* a;
+/*
 
-	/*
 	*size=(i.size/2)+6;
 	a=getMemory(*size);
 	//height - 00 - width - 00 - 00 - compression type
@@ -197,15 +205,16 @@ int mCompressGraphic(unsigned char* data,tImage i, int* size) {
 	a[4]=0;
 	a[5]=0xB0; // how q&d I am :)
 
-	memcpy(i.pix,a+6,*size); //TODO it should be a+6,i.pix
+	memcpy(a+6,i.pix,*size); //TODO it should be a+6,i.pix
 	*/
-//printf("llega 3\n");
+////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");
+////printf("llega 3.3\n");
+#if 1
 	compressRle(data+6,&i,&dataSize);
-//printf("llega 3.6\n");
+//printf("mCompressGraphic: size=%d\n",dataSize);
 	//a=getMemory(*size=(dataSize+6));
-//printf("llega 4\n");
+////printf("llega 4\n");
 	/*
 		Header Settings:
 		height - 00 - width - 00 - 00 - compression type
@@ -219,12 +228,10 @@ int mCompressGraphic(unsigned char* data,tImage i, int* size) {
 	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]);
-
+////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]);
 
+#endif
 	return 1;
 }
 
diff --git a/PR/src/lib/object/image/image256.c b/PR/src/lib/object/image/image256.c
index 921cef9..7f7d781 100644
--- a/PR/src/lib/object/image/image256.c
+++ b/PR/src/lib/object/image/image256.c
@@ -30,22 +30,23 @@ unsigned char popBit(unsigned char *byte) {
 
 //Expands B3/B4 algorithm
 void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) {
-printf("expandLzx %d %d \n",virtualSize,cursor);
 	int pos,h;
 	char k;
 	unsigned char maskbyte,rep;
-	for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos++]=0); //clean output garbage
+//printf("expandLzx %d %d \n",virtualSize,cursor);
+
+	for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos]=0,pos++); //clean output garbage
 	while (cursor<virtualSize) {
-		maskbyte=array[(*i)++];
+		maskbyte=array[*i];(*i)++;
 		for (k=8;k&&(cursor<virtualSize);k--) {
 			if (popBit(&maskbyte)) {
-				(*img).pix[cursor++]=array[(*i)++];
+				(*img).pix[cursor]=array[*i];(*i)++;cursor++;
 			} else {
-				pos=66+((0x100)*((rep=array[(*i)++])&3))+(unsigned char)array[(*i)++];
+				pos=66+((0x100)*((rep=array[*i])&3))+(unsigned char)array[(*i)+1];(*i)+=2;
 				rep=(rep>>2)+3;
 				while (rep--) { //Be careful in big images
 					h=cursor/MAX_MXD_SIZE_IN_LZX-(pos%MAX_MXD_SIZE_IN_LZX>cursor%MAX_MXD_SIZE_IN_LZX);
-					(*img).pix[cursor++]=(*img).pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZX+pos++%MAX_MXD_SIZE_IN_LZX];
+					(*img).pix[cursor]=(*img).pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZX+pos%MAX_MXD_SIZE_IN_LZX];cursor++;pos++;
 				}
 			}
 		}
@@ -54,36 +55,43 @@ printf("expandLzx %d %d \n",virtualSize,cursor);
 
 //Compress B1/B2 algorithm
 void compressRle(unsigned char* data,tImage* img,int *dataSize) {
-	printf("llega 3.51\n");
+//	//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");
+	//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)) {
+
+		while ((cursorPix<imgEnd)&&(*cursorPix!=*(cursorPix+1))&&((*counter)!=127)) {
+			cursorPix++;
 			(*counter)++;
-			*(cursorData++)=*(cursorPix-1);
+			*(cursorData)=*(cursorPix-1);
+			cursorData++;
 		}
-//printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd);
+////printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd);
 
-		cursorPix--;
+		//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
+			while ((cursorPix<imgEnd)&&(*cursorPix==(*(cursorPix+1)))&&((*counter)!=-128)) {
+				cursorPix++;
+				(*counter)--;
+			}
+			cursorPix++; //TODO poner esta linea abajo
+			*(cursorData)=*(cursorPix-1); //Print repeated char
+			cursorData++;
 		}
 	}
 	*(cursorData++)=0;
 	*(cursorData++)=*(cursorPix);
-//	printf("llega 3.59\n");
-
+//	//printf("compressRle: cursorData=%d data=%d cursorPix=%d imgEnd=%d\n",(int)cursorData,(int)data,(int)((*img).pix),(int)imgEnd);
 	*dataSize=(int)cursorData-(int)data;
 }
 
@@ -103,7 +111,7 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) {
 		 normaly: (* ignored types)
 		 checksum* - height - 00 - width - 00 - 00* - compression type
 	*/
-printf("expand graphic le ejecuta %d\n",virtualSize);
+////printf("expand graphic le ejecuta %d\n",virtualSize);
 
   int cursor=0;
   int i=1;
@@ -114,11 +122,11 @@ i=i+2;
 	image->width =((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]);
 i=i+2;
 	(*image).size  =(*image).height*(*image).width;
-printf("h=%d, w=%d %x %x %x %x   \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]);
+//printf("h=%d, w=%d %x %x %x %x   \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]);
 	virtualSize=(((*image).height*((*image).width+((*image).width&1)))>>1);
 	i++;
 
-printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize);
+//printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize);
   switch ((unsigned char)array[i++]) {
 		case PG_COMP_RAW: //No Compression Algorithm
 		  if (((*image).pix=getMemory(virtualSize))==NULL) return -1;
@@ -155,18 +163,18 @@ printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize);
 			}
 			break;
 		case PG_COMP_LZX_LR: //LZ Groody Up to Down Version Compression Algorithm
-		printf("llega b4\n");
+		//printf("llega b4\n");
 		  if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1;
 			expandLzx(array,image,&i,cursor,virtualSize);
 			break;
 		case PG_COMP_LZX_UD: //LZ Groody Left to Right Version Compression Algorithm
-printf("hi\n");
+//printf("hi\n");
 		  if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1;
 			{
 			unsigned char* outputaux=getMemory(virtualSize);
-			printf("antes\n");
+			//printf("antes\n");
 			expandLzx(array,image,&i,cursor,virtualSize);
-			printf("despues\n");
+			//printf("despues\n");
 			//Transpose
 		  while (cursor<virtualSize) outputaux[transpose(cursor,(*image).width,(*image).height)]=(*image).pix[cursor++];
 			free((*image).pix);
@@ -182,9 +190,9 @@ printf("hi\n");
 //Compress an image into an array in the most quick & dirty way
 int mCompressGraphic(unsigned char* data,tImage i, int* size) {
 	int dataSize;
-//	unsigned char* data;
+	//unsigned char* a;
+/*
 
-	/*
 	*size=(i.size/2)+6;
 	a=getMemory(*size);
 	//height - 00 - width - 00 - 00 - compression type
@@ -197,15 +205,16 @@ int mCompressGraphic(unsigned char* data,tImage i, int* size) {
 	a[4]=0;
 	a[5]=0xB0; // how q&d I am :)
 
-	memcpy(i.pix,a+6,*size); //TODO it should be a+6,i.pix
+	memcpy(a+6,i.pix,*size); //TODO it should be a+6,i.pix
 	*/
-//printf("llega 3\n");
+////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");
+////printf("llega 3.3\n");
+#if 1
 	compressRle(data+6,&i,&dataSize);
-//printf("llega 3.6\n");
+//printf("mCompressGraphic: size=%d\n",dataSize);
 	//a=getMemory(*size=(dataSize+6));
-//printf("llega 4\n");
+////printf("llega 4\n");
 	/*
 		Header Settings:
 		height - 00 - width - 00 - 00 - compression type
@@ -219,12 +228,10 @@ int mCompressGraphic(unsigned char* data,tImage i, int* size) {
 	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]);
-
+////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]);
 
+#endif
 	return 1;
 }
 
diff --git a/PR/src/lib/object/image/image_common.c b/PR/src/lib/object/image/image_common.c
index 921cef9..7f7d781 100644
--- a/PR/src/lib/object/image/image_common.c
+++ b/PR/src/lib/object/image/image_common.c
@@ -30,22 +30,23 @@ unsigned char popBit(unsigned char *byte) {
 
 //Expands B3/B4 algorithm
 void expandLzx(char* array,tImage* img, int *i,int cursor, int virtualSize) {
-printf("expandLzx %d %d \n",virtualSize,cursor);
 	int pos,h;
 	char k;
 	unsigned char maskbyte,rep;
-	for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos++]=0); //clean output garbage
+//printf("expandLzx %d %d \n",virtualSize,cursor);
+
+	for(pos=0;pos<MAX_MXD_SIZE_IN_LZX;(*img).pix[pos]=0,pos++); //clean output garbage
 	while (cursor<virtualSize) {
-		maskbyte=array[(*i)++];
+		maskbyte=array[*i];(*i)++;
 		for (k=8;k&&(cursor<virtualSize);k--) {
 			if (popBit(&maskbyte)) {
-				(*img).pix[cursor++]=array[(*i)++];
+				(*img).pix[cursor]=array[*i];(*i)++;cursor++;
 			} else {
-				pos=66+((0x100)*((rep=array[(*i)++])&3))+(unsigned char)array[(*i)++];
+				pos=66+((0x100)*((rep=array[*i])&3))+(unsigned char)array[(*i)+1];(*i)+=2;
 				rep=(rep>>2)+3;
 				while (rep--) { //Be careful in big images
 					h=cursor/MAX_MXD_SIZE_IN_LZX-(pos%MAX_MXD_SIZE_IN_LZX>cursor%MAX_MXD_SIZE_IN_LZX);
-					(*img).pix[cursor++]=(*img).pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZX+pos++%MAX_MXD_SIZE_IN_LZX];
+					(*img).pix[cursor]=(*img).pix[((h<0)?0:h)*MAX_MXD_SIZE_IN_LZX+pos%MAX_MXD_SIZE_IN_LZX];cursor++;pos++;
 				}
 			}
 		}
@@ -54,36 +55,43 @@ printf("expandLzx %d %d \n",virtualSize,cursor);
 
 //Compress B1/B2 algorithm
 void compressRle(unsigned char* data,tImage* img,int *dataSize) {
-	printf("llega 3.51\n");
+//	//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");
+	//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)) {
+
+		while ((cursorPix<imgEnd)&&(*cursorPix!=*(cursorPix+1))&&((*counter)!=127)) {
+			cursorPix++;
 			(*counter)++;
-			*(cursorData++)=*(cursorPix-1);
+			*(cursorData)=*(cursorPix-1);
+			cursorData++;
 		}
-//printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd);
+////printf("llega 3.55 cd=%d cp=%d ie=%d\n",cursorData-data,cursorPix,imgEnd);
 
-		cursorPix--;
+		//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
+			while ((cursorPix<imgEnd)&&(*cursorPix==(*(cursorPix+1)))&&((*counter)!=-128)) {
+				cursorPix++;
+				(*counter)--;
+			}
+			cursorPix++; //TODO poner esta linea abajo
+			*(cursorData)=*(cursorPix-1); //Print repeated char
+			cursorData++;
 		}
 	}
 	*(cursorData++)=0;
 	*(cursorData++)=*(cursorPix);
-//	printf("llega 3.59\n");
-
+//	//printf("compressRle: cursorData=%d data=%d cursorPix=%d imgEnd=%d\n",(int)cursorData,(int)data,(int)((*img).pix),(int)imgEnd);
 	*dataSize=(int)cursorData-(int)data;
 }
 
@@ -103,7 +111,7 @@ int mExpandGraphic(char* array,tImage *image, int virtualSize) {
 		 normaly: (* ignored types)
 		 checksum* - height - 00 - width - 00 - 00* - compression type
 	*/
-printf("expand graphic le ejecuta %d\n",virtualSize);
+////printf("expand graphic le ejecuta %d\n",virtualSize);
 
   int cursor=0;
   int i=1;
@@ -114,11 +122,11 @@ i=i+2;
 	image->width =((unsigned char)array[(i)])+256*((unsigned char)array[(i+1)]);
 i=i+2;
 	(*image).size  =(*image).height*(*image).width;
-printf("h=%d, w=%d %x %x %x %x   \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]);
+//printf("h=%d, w=%d %x %x %x %x   \n",(*image).height,image->width,(unsigned char)array[1],(unsigned char)array[2],(unsigned char)array[3],(unsigned char)array[4]);
 	virtualSize=(((*image).height*((*image).width+((*image).width&1)))>>1);
 	i++;
 
-printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize);
+//printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize);
   switch ((unsigned char)array[i++]) {
 		case PG_COMP_RAW: //No Compression Algorithm
 		  if (((*image).pix=getMemory(virtualSize))==NULL) return -1;
@@ -155,18 +163,18 @@ printf("geteo memoria %x %d\n",(unsigned char)array[i],virtualSize);
 			}
 			break;
 		case PG_COMP_LZX_LR: //LZ Groody Up to Down Version Compression Algorithm
-		printf("llega b4\n");
+		//printf("llega b4\n");
 		  if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1;
 			expandLzx(array,image,&i,cursor,virtualSize);
 			break;
 		case PG_COMP_LZX_UD: //LZ Groody Left to Right Version Compression Algorithm
-printf("hi\n");
+//printf("hi\n");
 		  if (((*image).pix=getMemory(MAX_MOD_SIZE_IN_LZX))==NULL) return -1;
 			{
 			unsigned char* outputaux=getMemory(virtualSize);
-			printf("antes\n");
+			//printf("antes\n");
 			expandLzx(array,image,&i,cursor,virtualSize);
-			printf("despues\n");
+			//printf("despues\n");
 			//Transpose
 		  while (cursor<virtualSize) outputaux[transpose(cursor,(*image).width,(*image).height)]=(*image).pix[cursor++];
 			free((*image).pix);
@@ -182,9 +190,9 @@ printf("hi\n");
 //Compress an image into an array in the most quick & dirty way
 int mCompressGraphic(unsigned char* data,tImage i, int* size) {
 	int dataSize;
-//	unsigned char* data;
+	//unsigned char* a;
+/*
 
-	/*
 	*size=(i.size/2)+6;
 	a=getMemory(*size);
 	//height - 00 - width - 00 - 00 - compression type
@@ -197,15 +205,16 @@ int mCompressGraphic(unsigned char* data,tImage i, int* size) {
 	a[4]=0;
 	a[5]=0xB0; // how q&d I am :)
 
-	memcpy(i.pix,a+6,*size); //TODO it should be a+6,i.pix
+	memcpy(a+6,i.pix,*size); //TODO it should be a+6,i.pix
 	*/
-//printf("llega 3\n");
+////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");
+////printf("llega 3.3\n");
+#if 1
 	compressRle(data+6,&i,&dataSize);
-//printf("llega 3.6\n");
+//printf("mCompressGraphic: size=%d\n",dataSize);
 	//a=getMemory(*size=(dataSize+6));
-//printf("llega 4\n");
+////printf("llega 4\n");
 	/*
 		Header Settings:
 		height - 00 - width - 00 - 00 - compression type
@@ -219,12 +228,10 @@ int mCompressGraphic(unsigned char* data,tImage i, int* size) {
 	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]);
-
+////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]);
 
+#endif
 	return 1;
 }
 
diff --git a/PR/src/lib/pr.c b/PR/src/lib/pr.c
index eddc1b7..d9c048a 100644
--- a/PR/src/lib/pr.c
+++ b/PR/src/lib/pr.c
@@ -54,6 +54,9 @@ pr.c: Main source file for Princed Resources
 #include "compile.h"
 #include "tasks.h"
 
+#include "bmp.h"
+#include "memory.h"
+
 //functions
 
 int prExportDat(char* vDatFile, char* vDirName, char* vResFile) {
@@ -80,9 +83,10 @@ int prExportDatOpt(char* vDatFile, char* vDirName, char* vResFile,char opt) {
 	tResource* r[65536];
 	int a;
 	parseFile (vResFile,r);
-	//printf("kkkkkkkkkkk: %x\n",opt);
 	a=extract(vDatFile, vDirName,r,opt);
+	printf("termine B %d\n",a);
 	if (!(opt&8)) generateFile(vResFile,r);
+	printf("termine C %d\n",a);
 	return a;
 }
 
@@ -177,7 +181,7 @@ int main(int argc, char* argv[]) {
 				}
 			}
 			printf("Extracting '%s' to '%s' with %d\r\n",argv[1],dir,option);
-			printf("Result: %d\r\n",returnValue=prExportDatOpt(argv[1],dir,"resources.txt",option));
+			printf("Result: %d\r\n",returnValue=prExportDatOpt(argv[1],dir,"resources.txt",(char)option));
 			break;
 		case 'd': // get type of file.dat
 			printf("Classifing '%s'\r\n",argv[1]);
@@ -193,7 +197,7 @@ int main(int argc, char* argv[]) {
 					}
 				}
 			printf("Compiling '%s' from '%s' with %d\r\n",argv[1],dir,option);
-			printf("Result: %d\r\n",returnValue=prImportDatOpt(argv[1],dir,"resources.txt",option));
+			printf("Result: %d\r\n",returnValue=prImportDatOpt(argv[1],dir,"resources.txt",(char)option));
 			break;
 		case 't': // none --> resource.txt (destroy resource table)
 			printf("Clearing 'resources.txt'\r\n");
diff --git a/PR/src/lib/xml/tree.c b/PR/src/lib/xml/tree.c
index fd30a5f..3b9dec3 100644
--- a/PR/src/lib/xml/tree.c
+++ b/PR/src/lib/xml/tree.c
@@ -1,6 +1,6 @@
 
 
-//Needed files
+//Includes
 #include <stdio.h>
 #include <stdlib.h>
 #include "pr.h"
@@ -62,12 +62,11 @@ char verifyHeader(char* array, int size) {
 //Parse line
 void parseResource(tResource* r[], char* line) {
 	//declare variables
-	int i=0;
+	int                i=0;
+	int                k=0;
 	unsigned short int id,ty;
-	int k=0;
 
 	//Begin parsing
-
 	for (;!(line[k]=='\r'||line[k]=='\n'||(!line[k]));k++);
 	line[k]=0;
 
@@ -88,7 +87,7 @@ void parseResource(tResource* r[], char* line) {
 		} else {
 			(*(r[id])).desc=NULL;
 		}
-		(*(r[id])).type=ty;
+		(*(r[id])).type=(char)ty;
 	}
 }
 
@@ -102,7 +101,6 @@ char parseFile(char* vFile,tResource* r[]) {
 	//declare variables
 	char parsing=0;
 	char line[MAX_LINE_SIZE];
-	char token[MAX_LINE_SIZE];
 	char B[]=BEGIN_TABLE;
 	char E[]=END_TABLE;
 	FILE* fp;
@@ -141,6 +139,9 @@ char generateFile(char* vFile,tResource* r[]) {
 	char none[]="";
 	FILE* fp;
 	FILE* source;
+	int id=0;
+
+//printf("hola vengo a generar el archivo\n");
 
 	if ((fp=fopen("res.tmp","wt"))!=NULL) {
 		//insert headers
@@ -160,19 +161,26 @@ char generateFile(char* vFile,tResource* r[]) {
 			}
 		}
 
+//printf("se abrio res.tmp y se parse\xf3 el principio\n");
+
 		//insert main body file
 		fputs(B,fp);
 		fputs("\n",fp);
-		int id=0;
+////printf("r -> A\n");
+
 		for (;id<65536;id++) {
+////printf("r -> B %d %p\n",id,r[id]);
+
 			if (r[id]!=NULL) {
-				if ((*(r[id])).desc==NULL) {
+				if (1||((*(r[id])).desc==NULL)) { //todo see this line
+////printf("r -> G %d %p\n",id,r[id]);
 					if ((*(r[id])).coms==NULL) {
 						sprintf(coms,none);
 					} else {
 						sprintf(coms," #",(*(r[id])).coms);
 					}
 				} else {
+////printf("r -> E %d %p\n",id,r[id]);
 					if ((*(r[id])).coms==NULL) {
 						sprintf(coms," %s",(*(r[id])).desc);
 					} else {
@@ -192,6 +200,8 @@ char generateFile(char* vFile,tResource* r[]) {
 		fputs("\n",fp);
 		fputs(E,fp);
 
+//printf("se inserto el cuerpo de los recursos\n");
+
 		//insert footers
 		if (source!=NULL) {
 			while ((parsing==2) && (fgets(line,MAX_LINE_SIZE,source)!=NULL)) {
@@ -283,6 +293,7 @@ int mLoadFileArray(char* vFile,unsigned char** array) {
 			//if the filewas succesfully open
 			fseek(fp,0,SEEK_SET);
 			aux=fread (*array,1,aux,fp);
+			//printf("que me decis a mi, yo devolvi %d\n",aux);
 			fclose(fp);
 			return aux;
 		}
diff --git a/PR/src/lib/xml/unknown.c b/PR/src/lib/xml/unknown.c
index fd30a5f..3b9dec3 100644
--- a/PR/src/lib/xml/unknown.c
+++ b/PR/src/lib/xml/unknown.c
@@ -1,6 +1,6 @@
 
 
-//Needed files
+//Includes
 #include <stdio.h>
 #include <stdlib.h>
 #include "pr.h"
@@ -62,12 +62,11 @@ char verifyHeader(char* array, int size) {
 //Parse line
 void parseResource(tResource* r[], char* line) {
 	//declare variables
-	int i=0;
+	int                i=0;
+	int                k=0;
 	unsigned short int id,ty;
-	int k=0;
 
 	//Begin parsing
-
 	for (;!(line[k]=='\r'||line[k]=='\n'||(!line[k]));k++);
 	line[k]=0;
 
@@ -88,7 +87,7 @@ void parseResource(tResource* r[], char* line) {
 		} else {
 			(*(r[id])).desc=NULL;
 		}
-		(*(r[id])).type=ty;
+		(*(r[id])).type=(char)ty;
 	}
 }
 
@@ -102,7 +101,6 @@ char parseFile(char* vFile,tResource* r[]) {
 	//declare variables
 	char parsing=0;
 	char line[MAX_LINE_SIZE];
-	char token[MAX_LINE_SIZE];
 	char B[]=BEGIN_TABLE;
 	char E[]=END_TABLE;
 	FILE* fp;
@@ -141,6 +139,9 @@ char generateFile(char* vFile,tResource* r[]) {
 	char none[]="";
 	FILE* fp;
 	FILE* source;
+	int id=0;
+
+//printf("hola vengo a generar el archivo\n");
 
 	if ((fp=fopen("res.tmp","wt"))!=NULL) {
 		//insert headers
@@ -160,19 +161,26 @@ char generateFile(char* vFile,tResource* r[]) {
 			}
 		}
 
+//printf("se abrio res.tmp y se parse\xf3 el principio\n");
+
 		//insert main body file
 		fputs(B,fp);
 		fputs("\n",fp);
-		int id=0;
+////printf("r -> A\n");
+
 		for (;id<65536;id++) {
+////printf("r -> B %d %p\n",id,r[id]);
+
 			if (r[id]!=NULL) {
-				if ((*(r[id])).desc==NULL) {
+				if (1||((*(r[id])).desc==NULL)) { //todo see this line
+////printf("r -> G %d %p\n",id,r[id]);
 					if ((*(r[id])).coms==NULL) {
 						sprintf(coms,none);
 					} else {
 						sprintf(coms," #",(*(r[id])).coms);
 					}
 				} else {
+////printf("r -> E %d %p\n",id,r[id]);
 					if ((*(r[id])).coms==NULL) {
 						sprintf(coms," %s",(*(r[id])).desc);
 					} else {
@@ -192,6 +200,8 @@ char generateFile(char* vFile,tResource* r[]) {
 		fputs("\n",fp);
 		fputs(E,fp);
 
+//printf("se inserto el cuerpo de los recursos\n");
+
 		//insert footers
 		if (source!=NULL) {
 			while ((parsing==2) && (fgets(line,MAX_LINE_SIZE,source)!=NULL)) {
@@ -283,6 +293,7 @@ int mLoadFileArray(char* vFile,unsigned char** array) {
 			//if the filewas succesfully open
 			fseek(fp,0,SEEK_SET);
 			aux=fread (*array,1,aux,fp);
+			//printf("que me decis a mi, yo devolvi %d\n",aux);
 			fclose(fp);
 			return aux;
 		}
diff --git a/PR/src/parser.c b/PR/src/parser.c
index 1a2f683..539b45b 100644
--- a/PR/src/parser.c
+++ b/PR/src/parser.c
@@ -3,7 +3,6 @@
 \****************************************************************/
 
 #ifndef PARSER_DEFINED
-
 #define PARSER_DEFINED
 
 #include "parser.h"
@@ -136,4 +135,3 @@ char matchesIn(char* text,char* mask) {
 
 #endif
 
-