This commit is contained in:
Daveo 2000-08-29 16:26:01 +00:00
commit 47aee91ef4
396 changed files with 32003 additions and 0 deletions

591
Utils/MkData/MkData.cpp Normal file
View file

@ -0,0 +1,591 @@
/************************/
/*** DataFile Creator ***/
/************************/
#include <windows.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <io.h>
#include <fstream.h>
#include <conio.h>
#include <vector>
#include "Mkdata.h"
using namespace std;
//***********************************************************************
//***********************************************************************
//***********************************************************************
int DebugFlag=0;
int AlignSize=2048;
char *AlignBuffer;
//***********************************************************************
CBank Banks;
CFileList Files;
char *BaseDir=0;
//***********************************************************************
static void app_debug_msg(const char * pszFmt,va_list args)
{
char szBuf[256];
vsprintf(szBuf,pszFmt,args);
printf("%s\n",szBuf);
}
//******************************************************************
//******************************************************************
void __cdecl DEBUG(const char * pszFmt,...)
{
if (DebugFlag)
if (pszFmt)
{
va_list args;
va_start(args,pszFmt);
app_debug_msg(pszFmt,args);
va_end(args);
}
}
void __cdecl FATAL(const char * pszFmt,...)
{
if (pszFmt)
{
va_list args;
va_start(args,pszFmt);
app_debug_msg(pszFmt,args);
va_end(args);
}
exit(123);
}
//******************************************************************
char *LoadFileInMem(const char * FileName,int *OutSize)
{
FILE *FileHandle;
char *Buffer;
int Size;
FileHandle= fopen( FileName,"rb" );
if(!FileHandle)
{
FATAL("ERROR : Could not open file %s\n",FileName);
}
else
{
fseek(FileHandle,0,SEEK_END);
Size=ftell(FileHandle);
fseek(FileHandle,0,SEEK_SET);
if( (Buffer=(char*)malloc(Size))==NULL ) {printf("Out of memory.\n");exit(123);}
fread(Buffer, 1,Size,FileHandle);
fclose(FileHandle);
}
if (OutSize) *OutSize=Size;
return Buffer;
}
//******************************************************************
static char s_illegalChars[] = "\\/!£$%^&*()+-=-:. ";
static int s_nbChars = sizeof(s_illegalChars);
void convertIllegalChar( char *c )
{
for (int i=0;i<s_nbChars;i++)
{
if (*c == s_illegalChars[i]) *c = '_';
}
}
//******************************************************************
void ConvertString(char *Str)
{
strupr(Str);
while(*Str) convertIllegalChar(Str++);
}
//******************************************************************
void MakeEqName(char *In,char *Out)
{
int StrLen=strlen(In);
int begin0 = 0;
int begin1 = 0;
for (int i=0;i<StrLen;i++)
{
if (In[i] == '/' || In[i] == '\\')
{
begin0 = begin1;
begin1 = i;
}
}
if (In[begin0]=='/' || In[begin0]=='\\') begin0++;
strcpy(Out,In+begin0);
ConvertString(Out);
}
//***********************************************************************
//*** CFileList *********************************************************
//***********************************************************************
CFileList::~CFileList()
{
int ListSize=FileList.size();
for (int i=0;i<ListSize;i++) if (!FileList[i].BankIdx) free(FileList[i].Data);
}
//***********************************************************************
int CFileList::FindFileIdx(char *Filename)
{
int ListSize=FileList.size();
for (int i=0;i<ListSize;i++) if (!strcmp(Filename,FileList[i].Filename)) return(i);
return(-1);
}
//***********************************************************************
int CFileList::AddFile(char *BaseFilename,int BankIdx)
{
int Idx;
sFile File;
File.BankIdx=BankIdx;
strupr(BaseFilename);
sprintf(File.Filename,"%s/%s",BaseDir,BaseFilename);
MakeEqName(File.Filename,File.ShortName);
Idx=FindFileIdx(File.Filename);
if (Idx==-1)
{
Idx=FileList.size();
if (!BankIdx)
{
File.Data=LoadFileInMem(File.Filename,&File.Size);
}
else
{
File.BankIdx=BankIdx;
}
FileList.push_back(File);
}
return(Idx);
}
//***********************************************************************
//*** CBank *************************************************************
//***********************************************************************
void CBank::Start(char *Name,int Align)
{
sBank B;
if (Align==0) Align=AlignSize;
strcpy(B.Name,Name);
B.Align=Align;
CurrentBank=BankList.size();
BankList.push_back(B);
if (CurrentBank) Files.AddFile(Name,CurrentBank);
}
//***********************************************************************
void CBank::End()
{
CurrentBank=0;
}
//***********************************************************************
int CBank::FindEntry(int Idx)
{
sBank &ThisBank=GetBank(CurrentBank);
int ListSize=ThisBank.FileList.size();
for (int i=0;i<ListSize;i++)
{
if (ThisBank.FileList[i].ListIdx==Idx) return(i);
}
return(-1);
}
//***********************************************************************
void CBank::Add(char *Filename)
{
sBankEntry Entry;
if (Filename[0]==CHAR_SKIP) {Files.AddFile(Filename+1); return;}
Entry.ListIdx=Files.AddFile(Filename);
if (FindEntry(Entry.ListIdx)==-1) BankList[CurrentBank].FileList.push_back(Entry);
}
//******************************************************************
//*** Script shite *************************************************
//******************************************************************
int IsWhiteSpace(char c)
{
if (c==' ') return(1);
if (c==CHAR_TAB) return(1);
if (c==0xd) return(1);
if (c==0xa) return(1);
return(0);
}
//******************************************************************
char *SkipWhiteSpace(char *Ptr)
{
while (IsWhiteSpace(*Ptr)) Ptr++;
return(Ptr);
}
//******************************************************************
char *GotoNextLine(char *Ptr)
{
while (*Ptr && *Ptr!=CHAR_EOL ) Ptr++;
return(Ptr+2);
}
//******************************************************************
void Line2Str(char *Ptr,char *EndPtr)
{
int i=0;
while (!IsWhiteSpace(*Ptr) && Ptr<EndPtr) Ptr++;
*Ptr=0;
}
//******************************************************************
char *ScriptComment(char *Ptr,char *EndPtr)
{
return(GotoNextLine(Ptr));
}
//******************************************************************
char *ScriptStartBank(char *Ptr,char *EndPtr)
{
int Align;
char *Name;
Ptr=SkipWhiteSpace(Ptr+1);
Line2Str(Ptr,EndPtr);
Name=Ptr;
Ptr+=strlen(Ptr)+1;
Align=atoi(Ptr);
DEBUG("[%s] (%i)\n\t{",Name,Align);
Banks.Start(Name,Align);
return(GotoNextLine(Ptr));
}
//******************************************************************
char *ScriptEndBank(char *Ptr,char *EndPtr)
{
DEBUG("\t}");
Banks.End();
return(GotoNextLine(Ptr));
}
//******************************************************************
char *ScriptFile(char *Ptr,char *EndPtr)
{
Line2Str(Ptr,EndPtr);
Banks.Add(Ptr);
if (DebugFlag)
{
if (Banks.GetCurrentBankNo()) printf("\t");
printf("%s\n",Ptr);
}
return(GotoNextLine(Ptr));
}
//******************************************************************
void ReadScript(char *Filename)
{
char *Script,*Ptr,*EndPtr;
int Size;
Script = (char *)LoadFileInMem( Filename,&Size);
Ptr=Script;
EndPtr=Ptr+Size;
printf("Reading %s\n",Filename);
while (Ptr<EndPtr)
{
Ptr=SkipWhiteSpace(Ptr);
if (Ptr>=EndPtr) return;
switch (*Ptr)
{
case CHAR_COMMENT:
Ptr=ScriptComment(Ptr,EndPtr);
break;
case CHAR_STARTBANK:
Ptr=ScriptStartBank(Ptr,EndPtr);
break;
case CHAR_ENDBANK:
Ptr=ScriptEndBank(Ptr,EndPtr);
break;
default:
Ptr=ScriptFile(Ptr,EndPtr);
break;
}
}
free(Script);
}
//***********************************************************************
//***********************************************************************
//***********************************************************************
void ResetFAT(std::vector<sFAT> &FAT)
{
int FATSize=Files.GetCount();
int Loop;
FAT.resize(FATSize);
for (Loop=0; Loop<FATSize; Loop++)
{
sFile &F=Files.GetFile(Loop);
FAT[Loop].FilePos=-1;
FAT[Loop].FileSize=F.Size;
}
}
//***********************************************************************
void AlignData(FILE *FileHandle,int Align)
{
int Pos=ftell(FileHandle);
int AlignPad= (Pos & (Align-1));
if (AlignPad) fwrite(AlignBuffer,1,Align-AlignPad,FileHandle);
}
//***********************************************************************
int WriteFAT(FILE *FileHandle,std::vector<sFAT> &FAT,int Align)
{
int Pos=ftell(FileHandle);
int FATSize=Files.GetCount();
for (int Loop=0;Loop<FATSize;Loop++)
{
fwrite(&FAT[Loop],1,sizeof(sFAT),FileHandle);
}
AlignData(FileHandle,Align);
return(Pos);
}
//***********************************************************************
void WriteFileData(FILE *FileHandle,sFile &File,int Align,sFAT &ParentFAT)
{
ParentFAT.FilePos=ftell(FileHandle);
ParentFAT.FileSize=File.Size;
fwrite(File.Data,1,File.Size,FileHandle);
AlignData(FileHandle,Align);
}
//***********************************************************************
void WriteBankData(FILE *FileHandle,int BankIdx,sFAT &ParentFAT)
{
std::vector<sFAT> FAT;
sBank &ThisBank=Banks.GetBank(BankIdx);
int ThisListSize=ThisBank.FileList.size();
int Loop;
long StartFilePos,EndFilePos;
// reset FAT and write dummy FAT
ResetFAT(FAT);
ParentFAT.FilePos=WriteFAT(FileHandle,FAT,ThisBank.Align);
StartFilePos=ftell(FileHandle);;
// Write files
for (Loop=0; Loop<ThisListSize; Loop++)
{
int Idx=ThisBank.FileList[Loop].ListIdx;
sFile &ThisFile=Files.GetFile(Idx);
WriteFileData(FileHandle,ThisFile,ThisBank.Align,FAT[Idx]);
FAT[Idx].FilePos-=ParentFAT.FilePos;
DEBUG("\t %s %i %i",ThisFile.Filename,FAT[Idx].FilePos,FAT[Idx].FileSize);
}
EndFilePos=ftell(FileHandle);
fseek(FileHandle,ParentFAT.FilePos,SEEK_SET);
WriteFAT(FileHandle,FAT,ThisBank.Align);
fseek(FileHandle,EndFilePos,SEEK_SET);
ParentFAT.FileSize=EndFilePos-StartFilePos;
// printf("%i %i\n",BankSize,ParentFAT.FileSize);
}
//***********************************************************************
void WriteData(char *Filename)
{
FILE *FileHandle;
std::vector<sFAT> FAT;
int FATSize=Files.GetCount(),Idx;
FileHandle= fopen( Filename,"wb" );
if(!FileHandle) FATAL( "Could not write %s", Filename);
ResetFAT(FAT);
WriteFAT(FileHandle,FAT,AlignSize);
for (Idx=0; Idx<FATSize; Idx++)
{
sFile &ThisFile=Files.GetFile(Idx);
if (ThisFile.BankIdx)
{ // Databank
DEBUG("Bank %s",ThisFile.Filename);
WriteBankData(FileHandle,ThisFile.BankIdx,FAT[Idx]);
FAT[Idx].FileSize+=FATSize*sizeof(FAT);
// printf("%i\n",(int)FAT[Idx].FileSize);
AlignData(FileHandle,AlignSize);
}
else
{ // Normal File
WriteFileData(FileHandle,ThisFile,AlignSize,FAT[Idx]);
DEBUG("%s %i %i",ThisFile.Filename,FAT[Idx].FilePos,FAT[Idx].FileSize);
}
}
fseek(FileHandle,0,SEEK_SET);
WriteFAT(FileHandle,FAT,AlignSize);
fclose(FileHandle);
}
//***********************************************************************
//***********************************************************************
//***********************************************************************
void WriteFileHeader(FILE *FileHandle,char *Name)
{
static Count=0;
if (!Count)
fprintf( FileHandle, "%s=%i,\n" ,Name,Count);
else
fprintf( FileHandle, "%s,\n" ,Name);
Count++;
}
//***********************************************************************
void WriteBankHeader(FILE *FileHandle,int BankIdx)
{
sBank &ThisBank=Banks.GetBank(BankIdx);
WriteFileHeader(FileHandle,ThisBank.Name);
}
//***********************************************************************
void WriteHeader(char *Filename)
{
FILE *FileHandle;
int FATSize=Files.GetCount(),Idx;
FileHandle= fopen( Filename,"wb" );
if(!FileHandle) FATAL( "Could not write %s", Filename);
fprintf( FileHandle, "#ifndef __FILE_EQUATES_H__\n");
fprintf( FileHandle, "#define __FILE_EQUATES_H__\n\n");
fprintf( FileHandle, "enum FileEquate\n" );
fprintf( FileHandle, "{\n" );
for (Idx=0; Idx<FATSize; Idx++)
{
sFile &ThisFile=Files.GetFile(Idx);
if (ThisFile.BankIdx)
{ // Databank
WriteBankHeader(FileHandle,ThisFile.BankIdx);
}
else
{ // Normal File
WriteFileHeader(FileHandle,ThisFile.ShortName);
}
}
fprintf( FileHandle, "\nFileEquate_MAX,\n");
fprintf( FileHandle, "};\n" );
fprintf( FileHandle, "#endif\n" );
fclose(FileHandle);
}
//***********************************************************************
//***********************************************************************
//***********************************************************************
int main(int argc, char *argv[])
{
char *DataFilename=0;
char *IncludeFilename=0;
std::vector<char*> Scripts;
// Parse Input
for (int Loop=1;Loop<argc;Loop++)
{
char *StrPtr=argv[Loop];
if (StrPtr[0]=='-') StrPtr++;
switch(StrPtr[0])
{
case 'o': // Output
if(*StrPtr=':')StrPtr++;
DataFilename=StrPtr+1;
break;
case 's': // script
if(*StrPtr=':')StrPtr++;
Scripts.push_back(StrPtr+1);
break;
case 'i': // include file
if(*StrPtr=':')StrPtr++;
IncludeFilename=StrPtr+1;
break;
case 'd': // Cache script
DebugFlag=1;
break;
case 'a': // Align Size
if(*StrPtr=':')StrPtr++;
AlignSize=atoi(StrPtr+1);
break;
case 'b': // Base Dir
if(*StrPtr=':')StrPtr++;
BaseDir=StrPtr+1;
break;
default:
printf("Unknown Param [%s]\n",StrPtr);
break;
}
}
if (!AlignSize) FATAL("ERROR: AlignSize is 0");
if(!DataFilename || !Scripts.size() || !BaseDir)
{
printf("Error in command line\n");
printf("Usage : MkData [files] -o:OutFile\n");
printf(" -s\tIn Script\n");
printf(" -i\tHeaderFile\n");
printf(" -a\tAlignSize (Default 2048)\n");
printf(" -d\tDebug Msgs\n");
printf(" -b\tBase Dir\n");
return(0);
}
if( (AlignBuffer=(char*)malloc(AlignSize))==NULL ) {printf("Couldnt Alloc AlignBuffer.\n");exit(123);}
for (int i=0;i<AlignSize;i++) AlignBuffer[i]=0;
strupr(DataFilename);
printf("Creating Data File: %s\n",DataFilename);
Banks.Start("",AlignSize);
for (int Script=0;Script<Scripts.size();Script++)
{
ReadScript(Scripts[Script]);
}
printf("Writing Data File: %s\n",DataFilename);
WriteData(DataFilename);
if (IncludeFilename) WriteHeader(IncludeFilename);
printf("FATSize =%i\n",Files.GetCount()*sizeof(sFAT));
return(0);
}

97
Utils/MkData/MkData.dsp Normal file
View file

@ -0,0 +1,97 @@
# Microsoft Developer Studio Project File - Name="MkData" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=MkData - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "MkData.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "MkData.mak" CFG="MkData - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "MkData - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "MkData - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""$/PRLSR/utils/MkData", BLVAAAAA"
# PROP Scc_LocalPath "."
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "MkData - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x809 /d "NDEBUG"
# ADD RSC /l 0x809 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"../../tools/MkData.exe"
!ELSEIF "$(CFG)" == "MkData - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD BASE RSC /l 0x809 /d "_DEBUG"
# ADD RSC /l 0x809 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "MkData - Win32 Release"
# Name "MkData - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\MkData.cpp
# End Source File
# Begin Source File
SOURCE=.\MkData.h
# End Source File
# End Group
# End Target
# End Project

86
Utils/MkData/MkData.h Normal file
View file

@ -0,0 +1,86 @@
/************************/
/*** DataFile Creator ***/
/************************/
//***********************************************************************
//***********************************************************************
//***********************************************************************
#define CHAR_COMMENT '#'
#define CHAR_TAB 0x09
#define CHAR_EOL 0x0d
#define CHAR_SKIP '-'
#define CHAR_STARTBANK '{'
#define CHAR_ENDBANK '}'
//***********************************************************************
//***********************************************************************
//***********************************************************************
typedef signed char s8;
typedef signed short s16;
typedef signed long s32;
//***********************************************************************
//***********************************************************************
//***********************************************************************
struct sFAT
{
s32 FilePos;
s32 FileSize;
};
struct sBankEntry
{
int ListIdx;
int Pos;
};
struct sBank
{
char Name[256];
int Align;
std::vector<sBankEntry> FileList;
};
struct sFile
{
char Filename[256];
char ShortName[256];
int Size;
char *Data;
int BankIdx;
};
//***********************************************************************
class CFileList
{
public:
CFileList(){};
~CFileList();
int FindFileIdx(char *Filename);
int AddFile(char *Filename,int BankIdx=0);
int GetCount() {return(FileList.size());}
sFile &GetFile(int Idx) {return(FileList[Idx]);}
private:
std::vector<sFile> FileList;
};
//***********************************************************************
class CBank
{
public:
void Start(char *Name,int Align=0);
void End();
int FindEntry(int Idx);
void Add(char *Filename);
int GetCount() {return(BankList.size());}
sBank &GetBank(int Idx) {return(BankList[Idx]);}
int GetCurrentBankNo() {return(CurrentBank);}
private:
int CurrentBank;
std::vector<sBank> BankList;
};
//***********************************************************************

413
Utils/MkSpeech/MkSpeech.cpp Normal file
View file

@ -0,0 +1,413 @@
/***********************/
/*** Speech Compiler ***/
/***********************/
#include <windows.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <io.h>
#include <fstream.h>
#include <conio.h>
#include <vector>
using namespace std;
//************************************************
#define CHUNKSIZE 2336 // XA track size
#define SPACE ' '
#define MINUS '-'
#define COMMENT '#'
#define TAB 0x09
#define EOL 0x0d
#define InFileEXT "Ixa"
#define OutFileEXT "XaB"
#define BANK_SHIFT 16
//************************************************
struct sLang
{
char *Dir;
char Prefix;
};
struct sInFile
{
char Name[32];
int Chunks;
int Offset;
};
//************************************************
char *Script;
char *OutDir="",*ScriptFile=0;
int IncFileSet=0;
char IncludeFilename[256];
int BankNo=0;
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
std::vector<sLang> LangList;
std::vector<sInFile> FileList;
//***********************************************************************
//***********************************************************************
static void app_debug_msg(const char * pszFmt,va_list args)
{
char szBuf[256];
vsprintf(szBuf,pszFmt,args);
printf("%s\n",szBuf);
}
//******************************************************************
//******************************************************************
void __cdecl DEBUG(const char * pszFmt,...)
{
if (pszFmt)
{
va_list args;
va_start(args,pszFmt);
app_debug_msg(pszFmt,args);
va_end(args);
}
}
void __cdecl FATAL(const char * pszFmt,...)
{
if (pszFmt)
{
va_list args;
va_start(args,pszFmt);
app_debug_msg(pszFmt,args);
va_end(args);
}
exit(123);
}
//******************************************************************
char *LoadFileInMem(const char * pszName)
{
HANDLE FileHandle;
DWORD SizeRead;
char *Buffer;
char TName[256];
int Size;
sprintf(TName,pszName);
if( (FileHandle = CreateFile(TName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL)) == INVALID_HANDLE_VALUE )
{
FATAL("ERROR : Could not open file %s.",TName);
return NULL;
}
else
{
Size = GetFileSize(FileHandle,NULL);
if( (Buffer=(char*)malloc(Size))==NULL ) {printf("Out of memory.\n");exit(123);}
ReadFile(FileHandle,(void*)Buffer,Size,&SizeRead,NULL);
CloseHandle(FileHandle);
}
return Buffer;
}
//******************************************************************
int FindFileSize(const char * FileName)
{
HANDLE FileHandle;
DWORD Size;
char TName[256];
sprintf(TName,FileName);
if( (FileHandle = CreateFile(TName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL)) == INVALID_HANDLE_VALUE )
{
FATAL("ERROR : Could not open file %s.",TName);
return (0);
}
else
{
Size = GetFileSize(FileHandle,NULL);
CloseHandle(FileHandle);
}
return (Size);
}
int FindFileSizeAlign(const char * FileName)
{
int Size=FindFileSize(FileName);
Size = ((Size + 3) & 0xfffffffc);
return(Size);
}
//******************************************************************
// Read pre-defined script file
//******************************************************************
int IsWhiteSpace(char c)
{
if (c==' ') return(1);
if (c==TAB) return(1);
if (c==0xd) return(1);
if (c==0xa) return(1);
return(0);
}
//******************************************************************
char *SkipWhiteSpace(char *Ptr)
{
while (IsWhiteSpace(*Ptr)) Ptr++;
return(Ptr);
}
//******************************************************************
char *GotoNextLine(char *Ptr)
{
while (*Ptr!=EOL) Ptr++;
return(Ptr+2);
}
//******************************************************************
void ReadScript()
{
char *Ptr,*EndPtr;
int Size;
sInFile InFile;
Script = (char *)LoadFileInMem( ScriptFile);
Size = FindFileSize(ScriptFile);
Ptr=Script;
EndPtr=Ptr+Size;
while (Ptr<EndPtr)
{
Ptr=SkipWhiteSpace(Ptr);
if (Ptr>=EndPtr) return;
if (*Ptr==COMMENT)
{ // Comment
Ptr=GotoNextLine(Ptr);
}
else
{
int i=0;
InFile.Chunks=0;
while (!IsWhiteSpace(*Ptr) && Ptr<EndPtr) InFile.Name[i++]=*Ptr++;
InFile.Name[i]=0;
FileList.push_back(InFile);
// printf("%s\n",InFile.Name);
}
}
}
//******************************************************************
//*** Get File Sizes ***********************************************
//******************************************************************
void GetFileSizes()
{
int FileCount=FileList.size();
int LangCount=LangList.size();
char FileName[256];
// DEBUG( "Parsing Files");
for (int File=0; File<FileCount; File++)
{
sInFile &ThisFile=FileList[File];
ThisFile.Chunks=0;
for (int Lang=0; Lang<LangCount; Lang++)
{
sLang &ThisLang=LangList[Lang];
int ThisFileSize;
int ThisChunkSize;
sprintf(FileName,"%s\\%c%s.%s", ThisLang.Dir, ThisLang.Prefix, ThisFile.Name, InFileEXT);
ThisFileSize=FindFileSize(FileName);
ThisChunkSize=(ThisFileSize+(CHUNKSIZE-1))/CHUNKSIZE;
if (ThisFile.Chunks<ThisChunkSize) ThisFile.Chunks=ThisChunkSize;
}
}
}
//******************************************************************
//*** Write Data ***************************************************
//******************************************************************
void WriteData(sLang &ThisLang)
{
char *Buffer;
char FileName[256];
FILE *OutFile;
char Blank[CHUNKSIZE];
int FileCount=FileList.size();
memset( Blank, 0xBA, CHUNKSIZE ); // clear Blank Buffer
sprintf(FileName,"%s%c%s.%s",OutDir,ThisLang.Prefix ,fname,OutFileEXT);
OutFile= fopen( FileName,"wb" );
if(!OutFile)
FATAL( "Could not write %s", FileName);
else
DEBUG( "Created File - %s", FileName);
for (int File=0; File<FileCount; File++)
{
sInFile &ThisFile=FileList[File];
int ThisFileSize;
sprintf(FileName,"%s\\%c%s.%s", ThisLang.Dir, ThisLang.Prefix, ThisFile.Name, InFileEXT);
Buffer=LoadFileInMem(FileName);
ThisFileSize=FindFileSize(FileName);
fwrite( Buffer, 1, ThisFileSize, OutFile);
fwrite( Blank, 1, (ThisFile.Chunks*CHUNKSIZE)-ThisFileSize, OutFile); // Write Pad
fwrite( Blank, 1, CHUNKSIZE, OutFile); // Force Pad
ThisFile.Offset=ftell(OutFile);
free(Buffer);
}
fclose(OutFile);
}
//******************************************************************
//*** Write Header File ********************************************
//******************************************************************
static char s_illegalChars[] = "\\/!£$%^&*()+-=-:. ";
static int s_nbChars = sizeof(s_illegalChars);
void convertIllegalChar( char *c )
{
for (int i=0;i<s_nbChars;i++)
{
if (*c == s_illegalChars[i]) *c = '_';
}
}
//******************************************************************
void ConvertString(char *Str) {while(*Str) convertIllegalChar(Str++);}
//******************************************************************
void WriteHeader(sLang &ThisLang)
{
FILE *OutFile;
char HdrStr[256];
char EqStr[256];
int FileCount=FileList.size();
int Offset=0;
sprintf(HdrStr,"__%s_SPEECH_DEFINES_H__",strupr(fname));
sprintf(EqStr,"%s_STR_",strupr(fname));
OutFile= fopen( IncludeFilename,"wt" );
if(!OutFile)
FATAL( "Could not write %s", IncludeFilename);
else
DEBUG( "Created File - %s", IncludeFilename);
fprintf( OutFile, "#ifndef %s\n",HdrStr);
fprintf( OutFile, "#define %s\n\n",HdrStr);
fprintf( OutFile, "enum %sENUMS\n" ,EqStr);
fprintf( OutFile, "{\n" );
for (int File=0; File<FileCount; File++)
{
sInFile &ThisFile=FileList[File];
ConvertString(ThisFile.Name);
fprintf( OutFile, "%s%s = 0x%x,\n", EqStr,ThisFile.Name, Offset+(BankNo<<BANK_SHIFT));
Offset+=ThisFile.Chunks+1; // +1 for pad
}
fprintf( OutFile, "};\n" );
fprintf( OutFile, "#endif\n" );
fclose(OutFile);
}
//***************************************************
//***************************************************
//***************************************************
int main(int argc, char *argv[])
{
int CmdError=0;
// Parse Input
for (int Loop=1;Loop<argc;Loop++)
{
char *StrPtr=argv[Loop];
if (StrPtr[0]!='-') CmdError=1;
StrPtr++;
switch(StrPtr[0])
{
case 'o': // Output
OutDir=StrPtr+1;
break;
case 'd': // Add In Dir
{
sLang Dir;
Dir.Prefix=StrPtr[1];
Dir.Dir=StrPtr+2;
LangList.push_back(Dir);
DEBUG("Added Lang:%s",Dir.Dir);
}
break;
case 's': // script
ScriptFile=StrPtr+1;
break;
case 'i': // script
IncFileSet=1;
strcpy(IncludeFilename,StrPtr+1);
break;
case 'b': // script
BankNo=atoi(StrPtr+1);
break;
default:
printf("Unknown Param [%s]\n",StrPtr);
break;
}
}
if(!ScriptFile || !LangList.size())
{
DEBUG("Error in command line");
DEBUG("Usage : MkSpeech");
DEBUG(" -d\tAdd Dir (Prefix & Dir= -dPddddd)");
DEBUG(" -o\tOut Dir");
DEBUG(" -s\tScript");
DEBUG(" -I\tHeaderFile");
DEBUG(" -B\tBankNo");
return(0);
}
_splitpath( ScriptFile, drive, dir, fname, ext );
if (!IncFileSet) sprintf(IncludeFilename,"%s%s.h",fname,"_Speech",OutFileEXT);
ReadScript();
// DEBUG( "Script Read.");
GetFileSizes();
int LangCount=LangList.size();
for (int Lang=0;Lang<LangCount; Lang++) WriteData(LangList[Lang]);
WriteHeader(LangList[0]);
DEBUG("Success.");
return(0);
}

101
Utils/MkSpeech/MkSpeech.dsp Normal file
View file

@ -0,0 +1,101 @@
# Microsoft Developer Studio Project File - Name="MkSpeech" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=MkSpeech - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "MkSpeech.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "MkSpeech.mak" CFG="MkSpeech - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "MkSpeech - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "MkSpeech - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "MkSpeech - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x809 /d "NDEBUG"
# ADD RSC /l 0x809 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"C:\PRLSR\tools\MkSpeech.exe"
!ELSEIF "$(CFG)" == "MkSpeech - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD BASE RSC /l 0x809 /d "_DEBUG"
# ADD RSC /l 0x809 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "MkSpeech - Win32 Release"
# Name "MkSpeech - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\MkSpeech.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

94
Utils/banker/banker.dsp Normal file
View file

@ -0,0 +1,94 @@
# Microsoft Developer Studio Project File - Name="banker" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=banker - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "banker.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "banker.mak" CFG="banker - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "banker - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "banker - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""$/PRLSR/utils/banker", KJRAAAAA"
# PROP Scc_LocalPath "."
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "banker - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x809 /d "NDEBUG"
# ADD RSC /l 0x809 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"..\..\tools\banker.exe"
!ELSEIF "$(CFG)" == "banker - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD BASE RSC /l 0x809 /d "_DEBUG"
# ADD RSC /l 0x809 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /out:"..\..\tools\banker.exe" /pdbtype:sept
!ENDIF
# Begin Target
# Name "banker - Win32 Release"
# Name "banker - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\main.cpp
# End Source File
# End Group
# End Target
# End Project

399
Utils/banker/main.cpp Normal file
View file

@ -0,0 +1,399 @@
#include <windows.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <io.h>
//#include "SfxList.h"
//************************************************
#define MAX_SFX 1024
//************************************************
char path_buffer[_MAX_PATH];
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
struct bank_entry
{
WORD looped;
WORD pitch;
DWORD offset;
};
typedef struct
{
char Name[ 100 ];
WORD SfxNo;
BYTE Hashed;
BYTE Looped;
WORD LoopPos;
} file_entry;
char ThisDir[256];
file_entry FileList[MAX_SFX];
int NoFiles = 0;
//***********************************************************************
//***********************************************************************
static void app_debug_msg(const char * pszFmt,va_list args)
{
char szBuf[256];
vsprintf(szBuf,pszFmt,args);
printf("\n%s\n",szBuf);
}
//******************************************************************
//******************************************************************
void __cdecl screen_debug_msg(const char * pszFmt,...)
{
if (pszFmt)
{
va_list args;
va_start(args,pszFmt);
app_debug_msg(pszFmt,args);
va_end(args);
}
}
void __cdecl app_assert(const char * pszFmt,...)
{
if (pszFmt)
{
va_list args;
va_start(args,pszFmt);
app_debug_msg(pszFmt,args);
va_end(args);
}
exit(123);
}
//******************************************************************
void FreePtr(void *p)
{
if(p) free(p);
}
//******************************************************************
BYTE* LoadFileInMem(const char * pszName)
{
HANDLE hsFile;
DWORD dwSize = NULL;
DWORD dwSize2 = NULL;
DWORD Temp;
BYTE* Buffer;
if( (hsFile = CreateFile(pszName, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL)) == INVALID_HANDLE_VALUE )
{
screen_debug_msg("LFIM: Could not open file %s",pszName);
return NULL;
}else{
dwSize = GetFileSize(hsFile,NULL);
dwSize2 = dwSize;
if(dwSize&0x7) dwSize2 = (dwSize-(dwSize&0x7))+8;
if( (Buffer=(BYTE*)malloc(dwSize2))==NULL ) {printf("Out of memory.\n");exit(123);}
ReadFile(hsFile,(void*)Buffer,dwSize,&Temp,NULL);
CloseHandle(hsFile);
}
return Buffer;
}
//******************************************************************
DWORD FindFileSize(const char * pszName)
{
HANDLE hsFile;
DWORD dwSize=NULL;
if( (hsFile = CreateFile(pszName, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL)) == INVALID_HANDLE_VALUE )
{
screen_debug_msg("\nFFS: Could not open file %s",pszName);
return NULL;
}else{
dwSize = GetFileSize(hsFile,NULL);
if(dwSize&0x7) dwSize = (dwSize-(dwSize&0x7))+8;
CloseHandle(hsFile);
}
return dwSize;
}
//***************************************************
// Find files in directory
//***************************************************
int CalcHashNum(char* astring)
{
int result = 0;
WORD count;
for (count=0; count<strlen(astring); count++)
{
result^=(int) astring[count];
result++;
}
return result;
}
void FindDirFiles(char * Search)
{
int i;
FILE *fh;
char loop;
/* De-hash table */
for(i=0;i<MAX_SFX;i++)
{
FileList[i].Name[ 0 ] = '\0';
FileList[i].Hashed = false;
FileList[i].Looped = false;
}
// Open source file
if( ( fh = fopen( Search, "rb" ) ) == NULL )
{
printf( "\nCan't find source file!\n" );
return;
}
// Scan source file
while( !feof( fh ) )
{
if( fscanf( fh, "%s %c %d", FileList[NoFiles].Name, &loop, &FileList[NoFiles].LoopPos ) != 3 )
{
return;
}
if( loop == 'y' || loop == 'Y' )
{
FileList[NoFiles].Looped = true;
}
else
{
FileList[NoFiles].Looped = false;
}
FileList[NoFiles].Hashed = true;
NoFiles++;
}
}
//***************************************************
// Write files to bank
//***************************************************
DWORD FlipLongWord(DWORD val)
{
DWORD result;
result = ((val&0x000000ff)<<24) + ((val&0x0000ff00)<<8) + ((val&0x00ff0000)>>8) + ((val&0xff000000)>>24);
return(result);
}
void WriteBankData(char* Bank)
{
FILE* BANKFILE = NULL;
FILE* OFFSETFILE = NULL;
BYTE* Buffer = NULL;
WORD Size;
DWORD filepos = 0;
char file[256];
bank_entry BankInfo;
WORD pitch;
DWORD vagpitch;
sprintf(file,"%s.bnk",Bank);
BANKFILE = fopen(file,"wb");
if(!BANKFILE) {printf("\nBank file error\n\n");return;}
sprintf(file,"%s.bof",Bank);
OFFSETFILE = fopen(file,"wb");
if(!OFFSETFILE) {printf("\nBank offset error\n\n");return;}
for(int i=0;i<NoFiles;i++)
{
if(FileList[i].Hashed)
{
char Name[256];
sprintf(Name, "%s%s", ThisDir, FileList[i].Name);
Buffer = LoadFileInMem(Name);
if (Buffer)
{
Size = (WORD)FindFileSize(Name);
Size -= 48;
printf("%s\t\t", Name);
if( FileList[i].Looped )
{
// Encode vag file as looped
int LoopBlock = (int)( (float)FileList[i].LoopPos / 3.5f );
for(int p=48+16;p<(LoopBlock)-16;p+=16)
{
Buffer[p+1] = 0x0;
}
Buffer[p+1] = 0x6;
for(p=p+16;p<(Size-16);p+=16)
{
Buffer[p+1] = 0x2;
}
Buffer[p+1] = 0x3;
}
else
{
// Encode vag file as non-looped
for(int p=48;p<(Size-16);p+=16)
{
// Buffer[p+1] = 0x2;
}
Buffer[p+1] = 0x1;
}
fwrite(Buffer+48, 1, Size, BANKFILE);
_splitpath(Name, drive, dir, fname, ext);
vagpitch = *(DWORD*)&Buffer[16];
vagpitch = FlipLongWord(vagpitch);
pitch=(int)((float)vagpitch*(1024.0/11025.0));
printf(" pitch %dkhz (%d)\n",vagpitch,pitch);
BankInfo.offset = filepos;
BankInfo.pitch = pitch;
BankInfo.looped = FileList[i].Looped;
fwrite(&BankInfo, 1, sizeof(bank_entry), OFFSETFILE);
filepos += Size;
FreePtr(Buffer);
}
}
}
fclose(BANKFILE);
fclose(OFFSETFILE);
}
static const char BadFileChars[] =
{
'+', '-', '*', '/', '\\', '#', ',',
'.', '(', ')', '!', '"', '£', '$',
'%', '^', '&', '=', '#', ':', ';', '<',
'>', '?', '@', '{', '}', '[', ']', '¬',
};
static const int nbBadFileChars = (sizeof(BadFileChars) / sizeof(char));
void ExportEnums(char * name)
{
FILE * ENUMFILE = NULL;
char file[256];
_splitpath(name, drive, dir, fname, ext);
strupr(fname);
sprintf( file, "%s.h", name );
ENUMFILE = fopen(file,"wt");
if(!ENUMFILE) {printf("\nEnum file error\n\n");return;}
fprintf( ENUMFILE, "enum\n{\n" );
for (int i=0;i<NoFiles;i++)
{
char * ostr = FileList[i].Name;//SFXNameTab[i];
int len = (int)strlen(ostr)+1;
char * nstr = new char[len];
for (int t=len-1;t>=0;t--)
{
if( ostr[ t ] == '\\' )
{
t++;
break;
}
}
int o = 0;
for (;t<len;t++)
{
nstr[o] = ostr[t];
if (nstr[o] == '.') nstr[o] = 0;
for(int c=0;c<nbBadFileChars;c++)
{
if (nstr[o] == BadFileChars[c]) nstr[o] = '_';
}
o++;
}
strupr( nstr );
if( FileList[i].Looped )
{
fprintf( ENUMFILE, "\tSFX_%s_%s,\t\t// Looped at %d\n", fname,nstr, FileList[i].LoopPos );
}
else
{
fprintf( ENUMFILE, "\tSFX_%s_%s,\n", fname,nstr );
}
}
fprintf( ENUMFILE, "};\n" );
}
//***************************************************
//***************************************************
//***************************************************
//***************************************************
int main(int argc, char *argv[])
{
if(argc!=3)
{
printf("\nBanker (C)limax 1997");
printf("\nWritten by Tim Swann");
printf("\nUsage: Banker <Source File> <Output Base>");
printf("\nFor example, 'Banker level0.txt \\data\\snd\\level0' will take");
printf("\n'level0.txt' as its input and produce three files ( \\data\\snd\\level0.bof,");
printf("\n\\data\\snd\\level0.bnk and \\data\\snd\\level0.h ) as output.");
printf("\n\n");
return(0);
}
FindDirFiles(argv[1]);
WriteBankData(argv[2]);
ExportEnums(argv[2]);
printf("\nBank files made\n\n");
return(0);
}

472
Utils/parkgrab/VImage.cpp Normal file
View file

@ -0,0 +1,472 @@
/*=========================================================================
FILENAME.CPP
Author: Gary Liddon @
Created:
Project:
Purpose:
Copyright (c) 1998 G R Liddon
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
/* Glib
---- */
#include "pak.h"
/* Local
----- */
#include "vimage.h"
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
using namespace std;
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
/*----------------------------------------------------------------------
Data
---- */
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
VRAMImage::VRAMImage(int NewWidthInTpages,int NewHeightInPixels) : VRAMData(NULL)
{
WidthInTpages=NewWidthInTpages;
HeightInPixels=NewHeightInPixels;
HeightInTPages=NewHeightInPixels / 256;
if (!HeightInTPages)
{
aTPageHeight = 128;
HeightInTPages = 1;
}
else
{
aTPageHeight = HeightInTPages * 256;
}
TPageSizeInBytes = 128 * aTPageHeight;
WidthInBytes=WidthInTpages*128;
VramAreaBytes=WidthInBytes * HeightInPixels;
VRAMData=new u8[VramAreaBytes];
lbmData = new u8[WidthInTpages*256*HeightInPixels];
if (!lbmData)
Error(ERM_OUTOFMEM);
if (!VRAMData)
Error(ERM_OUTOFMEM);
memset(VRAMData,0,VramAreaBytes);
m_doCompress=false;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
VRAMImage::~VRAMImage(void)
{
if (lbmData)
delete lbmData;
if (VRAMData)
delete VRAMData;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void VRAMImage::getTpData(unsigned int tp,std::vector<u8> & dest) const
{
const int TPAGES_IN_ALL =WidthInTpages * HeightInTPages;
if (tp >= TPAGES_IN_ALL)
Error(ERR_FATAL,"illegal tpage number");
int tpX,tpY;
u8 const * srcTpData;
dest.resize(TPageSizeInBytes);
tpX=(tp%WidthInTpages)*128;
tpY=(tp/WidthInTpages)*aTPageHeight;
srcTpData=&VRAMData[tpX+tpY*WidthInBytes];
for (int x=0;x<128;x++)
for (int y=0;y<aTPageHeight;y++)
dest[x+y*128]=srcTpData[x+y*WidthInBytes];
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CompressMem(char const * CmdLine,std::vector<u8> & Body)
{
try
{
GString Com;
char TmpName[100];
char CompTmpName[100];
tmpnam(TmpName);
tmpnam(CompTmpName);
GString ComStr(CmdLine);
ComStr.Replace("%1",TmpName);
ComStr.Replace("%2",CompTmpName);
ofstream Out;
Out.open(TmpName,ios::binary|ios::trunc);
if (Out)
{
int CompSize;
Out.write((char const *)&Body[0],Body.size());
Out.close();
cout<<(char const *)ComStr<<"from "<<CmdLine<<endl;
system(ComStr);
CompSize=FileSize(CompTmpName);
Body.resize(CompSize);
ifstream In;
In.open(CompTmpName,ios::binary);
if (In)
{
In.read((char *)&Body[0],CompSize);
In.close();
}
else
throw("Can't open compressed out file");
}
else
throw("Can't open uncompressed out file");
remove(TmpName);
remove(CompTmpName);
}
catch (const char * Err)
{
GObject::Error(ERR_FATAL,"%s im CompressMem",Err);
}
}
void VRAMImage::WriteInTpageChunks(ofstream & str)
{
const int TPAGES_IN_ALL =WidthInTpages * HeightInTPages;
vector<u8> tpageData;
tpageData.resize(TPageSizeInBytes);
for (int f=0;f<TPAGES_IN_ALL;f++)
{
getTpData(f,tpageData);
str.write((char*)&tpageData[0],TPageSizeInBytes);
}
}
void VRAMImage::Write(ofstream & Str)
{
if (m_doCompress)
{
printf("Packing TPage\n");
const int TPAGES_IN_ALL =WidthInTpages * HeightInTPages;
const int NUM_OF_WINDOWS = TPAGES_IN_ALL*4;
vector<u8> tpageData;
vector<u8> dataToWrite;
tpageData.resize(TPageSizeInBytes);
dataToWrite.resize(TPageSizeInBytes);
for (int f=0;f<NUM_OF_WINDOWS;f++)
{
int dataWriteSize;
const u8 * srcData;
if ((f&3) == 0)
getTpData(f/4,tpageData);
srcData=&tpageData[(f%4)*128*64];
if (f != 0)
{
vector<u8> myData;
myData.resize(128*64);
memcpy(&myData[0],srcData,128*64);
#ifdef __USE_LZNP__
CompressMem("lznp %1 %2",myData);
dataWriteSize=myData.size();
memcpy(&dataToWrite[0],&myData[0],dataWriteSize);
#else
dataWriteSize=PAK_findPakSize(&myData[0],128*64);
PAK_doPak(&dataToWrite[0],&myData[0],128*64);
#endif
}
else
{
dataWriteSize=128*64;
memcpy(&dataToWrite[0],srcData,128*64);
}
for (int a=0;a<16;a++) printf("%i, ",(int)dataToWrite[a]);
printf("\n");
Str.write((char *)(&dataToWrite[0]),dataWriteSize);
}
}
else
Str.write((char *)(VRAMData),VramAreaBytes);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void VRAMImage::PlotPal(SprPal const & PalToPlot)
{
TPRect Tp=PalToPlot.GetTPRect();
int W=WidthInTpages*256;
W/=2;
u16 * Addr=(u16 *)&VRAMData[Tp.Y*W+Tp.X/2];
std::vector<u16> OutWords;
PalToPlot.MakePSXPal(OutWords);
int f;
for (f=0;f<OutWords.size();f++)
Addr[f]=OutWords[f];
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void VRAMImage::PlotFrame(SprFrame const & FrameToPlot)
{
SprFrame::BDEPTH ThisDepth;
ThisDepth=FrameToPlot.GetBitDepth();
switch(ThisDepth)
{
case SprFrame::BITS_4:
PlotFrame4(FrameToPlot);
break;
case SprFrame::BITS_8:
PlotFrame8(FrameToPlot);
break;
};
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void VRAMImage::SaveAs16ColLbm(const char * Name)
{
Palette GazPalette;
GazPalette[0].SetR(0);
GazPalette[0].SetG(0);
GazPalette[0].SetB(255);
int W=WidthInTpages*256;
int H=HeightInPixels;
Frame ThisFr;
for (int f=1;f<15;f++)
{
int Col=f*17;
GazPalette[1+f].SetR(Col);
GazPalette[1+f].SetG(Col);
GazPalette[1+f].SetB(Col);
}
for (int y=0;y<H;y++)
for (int x=0;x<W;x++)
{
if ((x&1))
lbmData[x+y*W]=(VRAMData[ (y*(W/2))+(x/2)]&0xf0) >> 4;
else
lbmData[x+y*W]=VRAMData[(y*(W/2))+(x/2)]&0x0f;
}
ThisFr.SetFrame(lbmData,W,H,GazPalette);
ThisFr.SaveLbm(Name);
cout<<"Written "<<Name<<endl;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void VRAMImage::PlotFrame4(SprFrame const & Fr)
{
TPRect Tp=Fr.GetTPRect();
int W=WidthInTpages*256;
W=W/2; /* we're plotting nibbles */
if (!Tp.GetRotate())
{
for (int y=Tp.Y;y<Tp.Y+Tp.H;y++)
for (int x=Tp.X;x<Tp.X+Tp.W;x++)
{
int FrX=x-Tp.X;
int FrY=y-Tp.Y;
u8 ScrNib=Fr.SeeData()[FrY*Tp.W+FrX]&0xf;
u8 * PixAddr=&VRAMData[y*W+x/2];
if ((x&1))
{
*PixAddr&=0x0f;
*PixAddr|=ScrNib<<4;
}
else
{
*PixAddr&=0xf0;
*PixAddr|=ScrNib;
}
}
}
else
{
for (int y=Tp.Y;y<Tp.Y+Tp.H;y++)
for (int x=Tp.X;x<Tp.X+Tp.W;x++)
{
int FrX=x-Tp.X;
int FrY=y-Tp.Y;
u8 ScrNib=Fr.SeeData()[FrX*Tp.H+(Tp.H-FrY-1)]&0xf;
u8 * PixAddr=&VRAMData[y*W+x/2];
if ((x&1))
{
*PixAddr&=0x0f;
*PixAddr|=ScrNib<<4;
}
else
{
*PixAddr&=0xf0;
*PixAddr|=ScrNib;
}
}
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void VRAMImage::PlotFrame8(SprFrame const & Fr)
{
const TPRect & Tp=Fr.GetTPRect();
int W=WidthInTpages*256;
W/=2;
u8 * Addr=&VRAMData[Tp.Y*W+Tp.X/2];
if (!Fr.IsRotated())
{
for (int y=0;y<Fr.GetHeight();y++)
for (int x=0;x<Fr.GetWidth();x++)
Addr[y*W+x]=Fr.SeeData()[x+y*Fr.GetWidth()];
}
else
{
for (int y=0;y<Fr.GetWidth();y++)
for (int x=0;x<Fr.GetHeight();x++)
Addr[y*W+x]=Fr.SeeData()[x*Fr.GetWidth()+(Fr.GetWidth()-y-1)];
}
}
/*===========================================================================
end */

View file

@ -0,0 +1,669 @@
/*=========================================================================
FILENAME.CPP
Author: Gary Liddon @
Created:
Project:
Purpose:
Copyright (c) 1998 G R Liddon
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
/* Glib
---- */
#include <frame.hpp>
#include <misc.hpp>
/* Local
----- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
using namespace std;
/*----------------------------------------------------------------------
Vars
---- */
/*----------------------------------------------------------------------
Data
---- */
struct RGB
{
u8 r,g,b;
};
class BITMAP
{
public:
BITMAP(void)
{
m_width=0;
m_height=0;
}
void setSize(int width,int height)
{
bitMap.resize(width*height);
m_width=width;
m_height=height;
}
void clear(void)
{
if (m_width && m_height)
memset(&bitMap[0],0,m_width*m_height);
}
void line(unsigned int y,unsigned int x,u8 pix)
{
if (x >= m_width)
{
GObject::Error(ERR_WARNING,"Out of X boundary - %d %d\n", x, m_width);
x = m_width-1;
}
if (y >= m_height)
{
GObject::Error(ERR_WARNING,"Out of Y boundary - %d %d\n", y, m_height);
y = m_height-1;
}
bitMap[y*m_width+x]=pix;
}
u8 const * getBitMap(void) const
{return(&bitMap[0]);}
protected:
int m_width;
int m_height;
vector<u8> bitMap;
};
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <limits.h>
#define BI_RGB 0
#define BI_RLE8 1
#define BI_RLE4 2
#define BI_BITFIELDS 3
#define OS2INFOHEADERSIZE 12
#define WININFOHEADERSIZE 40
typedef struct BITMAPFILEHEADER
{
unsigned long bfType;
unsigned long bfSize;
unsigned short bfReserved1;
unsigned short bfReserved2;
unsigned long bfOffBits;
} BITMAPFILEHEADER;
/* Used for both OS/2 and Windows BMP.
* Contains only the parameters needed to load the image
*/
typedef struct BITMAPINFOHEADER
{
unsigned long biWidth;
unsigned long biHeight;
unsigned short biBitCount;
unsigned long biCompression;
} BITMAPINFOHEADER;
typedef struct WINBMPINFOHEADER /* size: 40 */
{
unsigned long biWidth;
unsigned long biHeight;
unsigned short biPlanes;
unsigned short biBitCount;
unsigned long biCompression;
unsigned long biSizeImage;
unsigned long biXPelsPerMeter;
unsigned long biYPelsPerMeter;
unsigned long biClrUsed;
unsigned long biClrImportant;
} WINBMPINFOHEADER;
typedef struct OS2BMPINFOHEADER /* size: 12 */
{
unsigned short biWidth;
unsigned short biHeight;
unsigned short biPlanes;
unsigned short biBitCount;
} OS2BMPINFOHEADER;
/* read_bmfileheader:
* Reads a BMP file header and check that it has the BMP magic number.
*/
static int read_bmfileheader(Gifstream & f, BITMAPFILEHEADER *fileheader)
{
fileheader->bfType = f.Get16();
fileheader->bfSize= f.Get32();
fileheader->bfReserved1= f.Get16();
fileheader->bfReserved2= f.Get16();
fileheader->bfOffBits= f.Get32();
if (fileheader->bfType != 19778)
return -1;
return 0;
}
/* read_win_bminfoheader:
* Reads information from a BMP file header.
*/
static int read_win_bminfoheader(Gifstream & f, BITMAPINFOHEADER *infoheader)
{
WINBMPINFOHEADER win_infoheader;
win_infoheader.biWidth = f.Get32();
win_infoheader.biHeight = f.Get32();
win_infoheader.biPlanes = f.Get16();
win_infoheader.biBitCount = f.Get16();
win_infoheader.biCompression = f.Get32();
win_infoheader.biSizeImage = f.Get32();
win_infoheader.biXPelsPerMeter = f.Get32();
win_infoheader.biYPelsPerMeter = f.Get32();
win_infoheader.biClrUsed = f.Get32();
win_infoheader.biClrImportant = f.Get32();
infoheader->biWidth = win_infoheader.biWidth;
infoheader->biHeight = win_infoheader.biHeight;
infoheader->biBitCount = win_infoheader.biBitCount;
infoheader->biCompression = win_infoheader.biCompression;
return 0;
}
/* read_os2_bminfoheader:
* Reads information from an OS/2 format BMP file header.
*/
static int read_os2_bminfoheader(Gifstream & f, BITMAPINFOHEADER *infoheader)
{
OS2BMPINFOHEADER os2_infoheader;
os2_infoheader.biWidth = f.Get16();
os2_infoheader.biHeight = f.Get32();
os2_infoheader.biPlanes = f.Get32();
os2_infoheader.biBitCount = f.Get32();
infoheader->biWidth = os2_infoheader.biWidth;
infoheader->biHeight = os2_infoheader.biHeight;
infoheader->biBitCount = os2_infoheader.biBitCount;
infoheader->biCompression = 0;
return 0;
}
/* read_bmicolors:
* Loads the color pallete for 1,4,8 bit formats.
*/
static void read_bmicolors(int ncols, RGB *pal, Gifstream & f,int win_flag)
{
int i;
for (i=0; i<ncols; i++)
{
pal[i].b = f.get();
pal[i].g = f.get();
pal[i].r = f.get();
if (win_flag)
f.get();
}
}
/* read_1bit_line:
* Support function for reading the 1 bit bitmap file format.
*/
static void read_1bit_line(int length, Gifstream & f, BITMAP *bmp, int line)
{
unsigned char b[32];
unsigned long n;
int i, j, k;
int pix;
for (i=0; i<length; i++)
{
j = i % 32;
if (j == 0)
{
n = f.Get32();
for (k=0; k<32; k++)
{
b[31-k] = n & 1;
n = n >> 1;
}
}
pix = b[j];
bmp->line(line,i,pix);
}
}
/* read_4bit_line:
* Support function for reading the 4 bit bitmap file format.
*/
static void read_4bit_line(int length, Gifstream & f, BITMAP *bmp, int line)
{
unsigned char b[8];
unsigned long n;
int i, j, k;
int temp;
int pix;
for (i=0; i<length; i++)
{
j = i % 8;
if (j == 0)
{
n = f.Get32();
for (k=0; k<4; k++)
{
temp = n & 255;
b[k*2+1] = temp & 15;
temp = temp >> 4;
b[k*2] = temp & 15;
n = n >> 8;
}
}
pix = b[j];
bmp->line(line,i,pix);
}
}
/* read_8bit_line:
* Support function for reading the 8 bit bitmap file format.
*/
static void read_8bit_line(int length, Gifstream & f, BITMAP *bmp, int line)
{
unsigned char b[4];
unsigned long n;
int i, j, k;
int pix;
for (i=0; i<length; i++)
{
j = i % 4;
if (j == 0)
{
n = f.Get32();
for (k=0; k<4; k++)
{
b[k] = n & 255;
n = n >> 8;
}
}
pix = b[j];
bmp->line(line,i,pix);
}
}
/* read_24bit_line:
* Support function for reading the 24 bit bitmap file format, doing
* our best to convert it down to a 256 color pallete.
*/
static void read_24bit_line(int length, Gifstream & f, BITMAP *bmp, int line)
{
#if 0
int i, nbytes;
RGB c;
nbytes=0;
for (i=0; i<length; i++) {
c.b = f.get();
c.g = f.get();
c.r = f.get();
bmp->line[line][i*3+_rgb_r_shift_24/8] = c.r;
bmp->line[line][i*3+_rgb_g_shift_24/8] = c.g;
bmp->line[line][i*3+_rgb_b_shift_24/8] = c.b;
nbytes += 3;
}
nbytes = nbytes % 4;
if (nbytes != 0)
for (i=nbytes; i<4; i++)
f.get();;
#endif
}
/* read_image:
* For reading the noncompressed BMP image format.
*/
static void read_image(Gifstream & f, BITMAP *bmp, BITMAPINFOHEADER *infoheader)
{
int i, line;
for (i=0; i<(int)infoheader->biHeight; i++) {
line = i;
switch (infoheader->biBitCount) {
case 1:
read_1bit_line(infoheader->biWidth, f, bmp, infoheader->biHeight-i-1);
break;
case 4:
read_4bit_line(infoheader->biWidth, f, bmp, infoheader->biHeight-i-1);
break;
case 8:
read_8bit_line(infoheader->biWidth, f, bmp, infoheader->biHeight-i-1);
break;
case 24:
read_24bit_line(infoheader->biWidth, f, bmp, infoheader->biHeight-i-1);
break;
}
}
}
/* read_RLE8_compressed_image:
* For reading the 8 bit RLE compressed BMP image format.
*/
static void read_RLE8_compressed_image(Gifstream & f, BITMAP *bmp, BITMAPINFOHEADER *infoheader)
{
unsigned char count, val, val0;
int j, pos, line;
int eolflag, eopicflag;
eopicflag = 0;
line = infoheader->biHeight - 1;
while (eopicflag == 0) {
pos = 0; /* x position in bitmap */
eolflag = 0; /* end of line flag */
while ((eolflag == 0) && (eopicflag == 0)) {
count = f.get();
val = f.get();
if (count > 0) { /* repeat pixel count times */
for (j=0;j<count;j++) {
bmp->line(line,pos,val);
pos++;
}
}
else {
switch (val) {
case 0: /* end of line flag */
eolflag=1;
break;
case 1: /* end of picture flag */
eopicflag=1;
break;
case 2: /* displace picture */
count = f.get();
val = f.get();
pos += count;
line -= val;
break;
default: /* read in absolute mode */
for (j=0; j<val; j++) {
val0 = f.get();
bmp->line(line,pos,val0);
pos++;
}
if (j%2 == 1)
val0 = f.get(); /* align on word boundary */
break;
}
}
if (pos > (int)infoheader->biWidth)
eolflag=1;
}
line--;
if (line < 0)
eopicflag = 1;
}
}
/* read_RLE4_compressed_image:
* For reading the 4 bit RLE compressed BMP image format.
*/
static void read_RLE4_compressed_image(Gifstream & f, BITMAP *bmp, BITMAPINFOHEADER *infoheader)
{
unsigned char b[8];
unsigned char count;
unsigned short val0, val;
int j, k, pos, line;
int eolflag, eopicflag;
eopicflag = 0; /* end of picture flag */
line = infoheader->biHeight - 1;
while (eopicflag == 0) {
pos = 0;
eolflag = 0; /* end of line flag */
while ((eolflag == 0) && (eopicflag == 0)) {
count = f.get();
val = f.get();
if (count > 0) { /* repeat pixels count times */
b[1] = val & 15;
b[0] = (val >> 4) & 15;
for (j=0; j<count; j++) {
bmp->line(line,pos,b[j%2]);
pos++;
}
}
else {
switch (val) {
case 0: /* end of line */
eolflag=1;
break;
case 1: /* end of picture */
eopicflag=1;
break;
case 2: /* displace image */
count = f.get();
val = f.get();
pos += count;
line -= val;
break;
default: /* read in absolute mode */
for (j=0; j<val; j++) {
if ((j%4) == 0) {
val0 = f.Get16();
for (k=0; k<2; k++) {
b[2*k+1] = val0 & 15;
val0 = val0 >> 4;
b[2*k] = val0 & 15;
val0 = val0 >> 4;
}
}
bmp->line(line,pos,b[j%4]);
pos++;
}
break;
}
}
if (pos > (int)infoheader->biWidth)
eolflag=1;
}
line--;
if (line < 0)
eopicflag = 1;
}
}
/* load_bmp:
* Loads a Windows BMP file, returning a bitmap structure and storing
* the pallete data in the specified pallete (this should be an array of
* at least 256 RGB structures).
*
* Thanks to Seymour Shlien for contributing this function.
*/
void load_bmp(Frame & frm,char const *filename)
{
BITMAPFILEHEADER fileheader;
BITMAPINFOHEADER infoheader;
RGB pal[256];
BITMAP bmp;
Gifstream f(Gifstream::LITTLE_ENDIAN);
int ncol;
unsigned long biSize;
f.open(filename,ios::in|ios::binary);
if (!f)
GObject::Error(ERR_FATAL,"couldn't open file %s",filename);
if (read_bmfileheader(f, &fileheader) != 0)
{
GObject::Error(ERR_FATAL,"error reading bmp hdr for %s",filename);
}
biSize = f.Get32();
if (biSize == WININFOHEADERSIZE)
{
if (read_win_bminfoheader(f, &infoheader) != 0)
GObject::Error(ERR_FATAL,"error reading windows bmp info hdr for %s",filename);
/* compute number of colors recorded */
ncol = (fileheader.bfOffBits - 54) / 4;
read_bmicolors(ncol, pal, f, 1);
}
else if (biSize == OS2INFOHEADERSIZE)
{
if (read_os2_bminfoheader(f, &infoheader) != 0)
GObject::Error(ERR_FATAL,"error reading os2 bmp info hdr for %s",filename);
/* compute number of colors recorded */
ncol = (fileheader.bfOffBits - 26) / 3;
read_bmicolors(ncol, pal, f, 0);
}
else
{
GObject::Error(ERR_FATAL,"error finding correct hdr for bmp %s",filename);
}
if (infoheader.biBitCount != 4 && infoheader.biBitCount != 8)
GObject::Error(ERR_FATAL,"only handles 4 && 8 bit bmps not %d : %s",infoheader.biBitCount,filename);
bmp.setSize(infoheader.biWidth, infoheader.biHeight);
bmp.clear();
switch (infoheader.biCompression)
{
case BI_RGB:
read_image(f, &bmp, &infoheader);
break;
case BI_RLE8:
read_RLE8_compressed_image(f, &bmp, &infoheader);
break;
case BI_RLE4:
read_RLE4_compressed_image(f, &bmp, &infoheader);
break;
default:
GObject::Error(ERR_FATAL,"unknown compression foramt for %s",filename);
break;
}
f.close();
{
Palette palObj;
for (int f=0;f<ncol;f++)
{
Colour & col = palObj[f];
col.SetRGB(pal[f].r,pal[f].g,pal[f].b);
}
frm.SetFrame(bmp.getBitMap(),infoheader.biWidth,infoheader.biHeight,palObj);
}
}
/*===========================================================================
end */

View file

@ -0,0 +1,58 @@
/*=========================================================================
FILENAME.CPP
Author: Gary Liddon @
Created:
Project:
Purpose:
Copyright (c) 1998 G R Liddon
===========================================================================*/
#ifndef __BMPLOADER_H__
#define __BMPLOADER_H__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
/* Glib
---- */
#include <frame.hpp>
/* Local
----- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Globals
------- */
/* Vars
---- */
/* Data
---- */
/* Functions
--------- */
void load_bmp(Frame & frm,char const *filename);
/*---------------------------------------------------------------------- */
#endif /* __BMPLOADER_H__ */
/*===========================================================================
end */

158
Utils/parkgrab/cross.cpp Normal file
View file

@ -0,0 +1,158 @@
/*=========================================================================
CROSS.CPP
Author: Gary Liddon @ Climax
Created:
Project: Diablo Playstation Conversion
Purpose: Find A Crosshair on a frame
Copyright (c) 1996 Director's Cut Ltd.
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
/* STL
--- */
/* Glib
---- */
/* Local
----- */
#include "cross.h"
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
using namespace std;
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
/*----------------------------------------------------------------------
Classes
------- */
/*----------------------------------------------------------------------
Description:
Find a cross hair in this frame for animation offset and store it
into member vars x and y.
Returns:
True if a cross hair is found
---------------------------------------------------------------------- */
bool CROSS_RES::FindCrossHair(
Frame const & Fr, /* Frame we're looking for a cross-hair in */
u8 CrossCol /* Pixel value of cross hair we're looking for */
)
{
u8 const * FrmData;
int * CountCol=NULL;
int * CountRow=NULL;
int Width;
int Height;
bool RetVal;
RetVal=false;
Width=Fr.GetWidth();
Height=Fr.GetHeight();
if (Width && Height)
{
int Col;
int Row;
if (!(CountCol=new int[Width]))
{
cout<<"Width is "<<Width<<endl;
GObject::Error(ERM_OUTOFMEM);
}
if (!(CountRow=new int[Height]))
{
cout<<"Height is "<<Width<<endl;
GObject::Error(ERM_OUTOFMEM);
}
memset(CountRow,0,sizeof(int)*Height);
memset(CountCol,0,sizeof(int)*Width);
FrmData=Fr.SeeData();
for (int yy=0;yy<Height;yy++)
{
u8 const * ThisRow=&FrmData[yy*Width];
for (int xx=0;xx<Width;xx++)
{
if (ThisRow[xx] == CrossCol)
{
CountRow[yy]++;
CountCol[xx]++;
}
}
}
Col=FindLargestIndex(CountCol,Width);
Row=FindLargestIndex(CountRow,Height);
if ((Col != -1) && (Row != -1))
{
x=Col;
y=Row;
RetVal=true;
}
}
if (CountCol)
delete CountCol;
if (CountRow)
delete CountRow;
return(RetVal);
}
/*----------------------------------------------------------------------
Description:
Returns:
---------------------------------------------------------------------- */
int CROSS_RES::FindLargestIndex(int * CountCol,int Width)
{
int LargestIndex=-1;
int Largest=0;
for (int f=0;f<Width;f++)
{
if (CountCol[f] > Largest)
{
Largest=CountCol[f];
LargestIndex=f;
}
}
return(LargestIndex);
}
/*===========================================================================
end */

67
Utils/parkgrab/cross.h Normal file
View file

@ -0,0 +1,67 @@
/*=========================================================================
CROSS.CPP
Author: Gary Liddon @ Climax
Created:
Project: Diablo Playstation Conversion
Purpose: Find A Crosshair on a frame
Copyright (c) 1996 Director's Cut Ltd.
===========================================================================*/
#ifndef __CROSS_HPP__
#define __CROSS_HPP__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
/* STL
--- */
/* Glib
---- */
#include <gobject.hpp>
#include <frame.hpp>
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Description:
This structure is used to find centering cross hairs
in frame objects using the FindCrossHair method.
If a cross hair is found, the results are put in
the x and y member vars.
---------------------------------------------------------------------- */
struct CROSS_RES
{
int x; /* x co-ord of cross found */
int y; /* y co-ord of cross found */
bool FindCrossHair(Frame const & Fr,u8 CrossCol);
private:
int FindLargestIndex(int * CountCol,int Width);
};
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*---------------------------------------------------------------------- */
#endif /* __CROSS_HPP__ */
/*===========================================================================
end */

138
Utils/parkgrab/grect.cpp Normal file
View file

@ -0,0 +1,138 @@
/*=========================================================================
GRECT.CPP
Author: Gary Liddon @ Climax
Created:
Project:
Purpose:
Copyright (c) 1997 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <algorithm>
/* Glib
---- */
#include <frame.hpp>
/* Local
----- */
#include "grect.h"
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
using namespace std;
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Positional Vars
--------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
static Rect & AddAnotherRect(RectVec & Result);
static void AddRectMessage(Rect const & T);
/*----------------------------------------------------------------------
Vars
---- */
/*----------------------------------------------------------------------
Data
---- */
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
Rect & AddAnotherRect(RectVec & Result)
{
Result.resize(Result.size()+1);
return(Result[Result.size()-1]);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CutRect(Rect const & ToBeCut,Rect const & TheCutter,RectVec & Result)
{
Rect Cutter=TheCutter;
ToBeCut.ClipRect(Cutter);
if (Cutter)
{
/* Is there a top rectangle hanging about? */
if (ToBeCut.Y != Cutter.Y)
{
Rect & TopRect=AddAnotherRect(Result);
TopRect=ToBeCut;
TopRect.H=Cutter.Y-TopRect.Y;
AddRectMessage(TopRect);
}
/* Is there a bottom rectangle hanging about? */
if ((ToBeCut.Y+ToBeCut.H) != (Cutter.Y+Cutter.H))
{
Rect & TopRect=AddAnotherRect(Result);
TopRect=ToBeCut;
TopRect.Y=Cutter.Y+Cutter.H;
TopRect.H=(ToBeCut.Y+ToBeCut.H)-(Cutter.Y+Cutter.H);
AddRectMessage(TopRect);
}
/* Is there a left rectangle hanging about? */
if (ToBeCut.X != Cutter.X)
{
Rect & TopRect=AddAnotherRect(Result);
TopRect=Cutter;
TopRect.X=ToBeCut.X;
TopRect.W=Cutter.X-ToBeCut.X;
AddRectMessage(TopRect);
}
/* Is there a right rectangle hanging about? */
if ((ToBeCut.X+ToBeCut.W) != (Cutter.X+Cutter.W))
{
Rect & TopRect=AddAnotherRect(Result);
TopRect=Cutter;
TopRect.X=Cutter.X+Cutter.W;
TopRect.W=(ToBeCut.X+ToBeCut.W)-(Cutter.X+Cutter.W);
AddRectMessage(TopRect);
}
}
}
void AddRectMessage(Rect const & T)
{
}
/*===========================================================================
end */

63
Utils/parkgrab/grect.h Normal file
View file

@ -0,0 +1,63 @@
/*=========================================================================
GRECT.CPP
Author: Gary Liddon @ Climax
Created:
Project:
Purpose:
Copyright (c) 1997 Climax Development Ltd
===========================================================================*/
#ifndef __GRECT_H__
#define __GRECT_H__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <vector>
/* Glib
---- */
#include <frame.hpp>
/* Local
----- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
typedef std::vector<Rect> RectVec;
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Globals
------- */
/* Vars
---- */
/* Data
---- */
/* Functions
--------- */
void CutRect(Rect const & ToBeCut,Rect const & TheCutter,RectVec & Result);
void ReportRectVec(RectVec & Result);
void GRectTest(void);
/*---------------------------------------------------------------------- */
#endif /* __GRECT_H__ */
/*===========================================================================
end */

703
Utils/parkgrab/main.cpp Normal file
View file

@ -0,0 +1,703 @@
/*=========================================================================
MAIN.CPP
Author: Gary Liddon @ Fareham
Created: 28th September 1998
Project: Theme Park World PSX
Purpose: Main file for tpw sprite grabber (it's sprgrab II!)
Copyright (c) 1998 G R Liddon
===========================================================================*/
/*----------------------------------------------------------------------
Version info
1.0 - 1.1 Various changes by various authors
1.2 GL Added -r switch to allow \ disallow sprite rotation
1.3 GL Added -x option to allow saving out of non VRAM sprs
1.31 GL Added -f option so you can force offsets to a value
1.4 TS Added replacement of bad characters in filenames
1.5 GL Added support for BMP files
1.6 GL Made all out files lower case
Checked for errrors when writing files (Doh!)
1.7 GL Added -q (turn on\of grabbers shrink to fit routine)
Also Added -k option to report where each texture has gone in the VRAM,
This will be read by mikes gin -> ars program for deciding what to do about shared
textures
1.71 GL Added widths and heights of textures to report file
1.72 GL Actually made the -q switch do what it was supposed to. Doh!
1.8 GL Added -i switch to set output dir for inc files
1.81 GL Corrected bug in 1.8 that meant no .h was written
1.9 GL -e to set maximum size for textures
1.91 GL Changed so that files prefixed with a "+" have col zero as see-through
2.0 GL Added reading of gin files and import of rep files
2.1 GL Added spare tpage space defintions
2.11 GL Added the rather excellent -j option
2.12 GL Fixed a bug, stopped -j textures from being reduced
2.13 GL Removed the -j option and changed it so that all textures starting with ! are auto -j'd ;)
2.14 GL Replaced bit map loader, will move this code into Frame at some point
2.15 GL Restricted it so that only images up to 254x254 are allowed
2.16 GL Fixed bug that meant 256 col images were often shagged
2.17 TS Added '@' filename pre-fix to denote scrolling and transparent textures
2.2 GL Changed the autocropping so that if the image is blank it allocates a 1x1 texture instead of a
texture the size of the input lbm
2.21 GL added -twisting_my_melon_man siwtch (don't ask)
2.3 GL added -y command to give us tpage compression
2.31 GL -y didn't work (not even a little bit) but it does now ;)
2.4 GL Added -~ switch to write out a raw tpage chunked version of the VRAM file
2.41 GL Added -^ switch to stop any tpages being written
2.5 TS Added -h half a tpage flag
2.6 DO Added -w only output animated texture frame headers
Added -b dont output spare boxes
Added -a align headers to 2k
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <vector>
#include <conio.h>
/* Glib
---- */
#include <gtypes.h>
#include <gstring.hpp>
#include <misc.hpp>
#include <gfname.hpp>
#include <pcre.h>
/* TP Lib
------- */
#include <ginio.h>
#include <repread.h>
/* Local
----- */
#include "sprset.h"
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
using namespace std;
/*----------------------------------------------------------------------
Class defintions
---------------- */
/* Hold's a list of all the files to be processed on along with the options that apply to them
------------------------------------------------------------------------------------------- */
class AllFiles : protected FileCycler
{
public:
AllFiles(void)
{
RecurseFiles=false;
CrossHair=false;
ZeroColZero=false;
MoveUVs=false;
AllowRotate=true;
ForceOffsets=false;
ShrinkToFit=true;
m_allocateAs16bit=false;
MaxSize=0;
m_noSort=false;
}
void SetFileRecursion(bool NewRecurseFiles)
{RecurseFiles=NewRecurseFiles;}
void SetCrossHair(bool NewCrossHair)
{CrossHair=NewCrossHair;}
void SetZeroColZero(bool NewColZero)
{ZeroColZero=NewColZero;}
void SetMoveUVs(bool NewMoveUVs)
{MoveUVs=NewMoveUVs;}
void SetAllowRotate(bool NewAllowRotate)
{AllowRotate=NewAllowRotate;}
void SetForceOffsets(bool NewForceOffsets)
{ForceOffsets=NewForceOffsets;}
void SetShrinkToFit(bool NewSetShrinkToFit)
{ShrinkToFit=NewSetShrinkToFit;}
void SetXOff(int NewXOff)
{XOff=NewXOff;}
void SetYOff(int NewYOff)
{YOff=NewYOff;}
void SetMaxSize(int New)
{MaxSize=New;}
int GetMaxSize(void) const
{return(MaxSize);}
void AddFile(const char * Name);
FIVec const & GetFileInfoVector(void) const
{return(AllFileInfos);}
void SortOrder();
void ReadRepFile(char const * Name)
{
vector<RepItem> MyItems;
::readRepFile(Name,MyItems);
for (int f=0;f<MyItems.size();f++)
AllExternalSharedTextures.push_back(MyItems[f].m_texName);
cout<<"Read report file "<<Name<<endl;
}
void setAllocateAs16Bit(bool newVal)
{m_allocateAs16bit=newVal;}
void setNoSort(void)
{
m_noSort=true;
}
protected:
vector<GString> UniqueTexturesSoFar;
vector<GString> AllExternalSharedTextures;
void FileCallback(char const * FName,int FileNum);
bool ShrinkToFit;
bool RecurseFiles;
bool CrossHair;
bool ZeroColZero;
bool MoveUVs;
bool AllowRotate;
bool ForceOffsets;
bool m_allocateAs16bit;
bool m_noSort;
int XOff,YOff;
FIVec AllFileInfos;
int MaxSize;
};
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
static char * CycleCommands(char *String,int Num);
static void Usage(void);
static bool CheckPlusMinus(const char * Str);
static GString CheckFileString(const char * Str);
static GString OutFile;
static GString OutLbm;
static GString SprFile;
static GString ReportFile;
static GString IncOutFile;
static int PageBase;
static int WidthPages;
static int HeightPages;
static bool PagePlacements=false;
static bool s_compressTpages=false;
static bool s_noWriteTpages=false;
static bool s_useHalfTpage=false;
static bool s_AnimatedHeadersOnly=false;
static bool s_DontOutputBoxes=false;
static bool s_AlignHeaders=false;
static GString s_rawTpageFile;
/*----------------------------------------------------------------------
Vars
---- */
static AllFiles MyFiles;
/*----------------------------------------------------------------------
Data
---- */
static const float Version = 2.6;
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int main(int argc,char ** argv)
{
cerr<<"GRLiddon() PARKGRAB TPW Spr Grabber "<<Version<<endl;
cerr<<"Copyright (c) 1998/1999G R Liddon. All rights reserved"<<endl<<endl;
if (argc==1)
Usage();
else
{
/* TODO:
Don't like this command line stuff, will change in glib at some point
*/
CommandLine(argc,argv,CycleCommands);
SprSet MySprSet;
MySprSet.setHalfTpage(s_useHalfTpage);
MySprSet.setAnimatedHeader(s_AnimatedHeadersOnly);
MySprSet.setDontOutputBoxes(s_DontOutputBoxes);
MySprSet.setAlignHeaders(s_AlignHeaders);
MySprSet.setCompressTpages(s_compressTpages);
MySprSet.setNoWriteTpages(s_noWriteTpages);
MyFiles.SortOrder();
if (MyFiles.GetMaxSize())
MySprSet.SetMaxSize(MyFiles.GetMaxSize());
MySprSet.AddFiles(MyFiles.GetFileInfoVector());
if (IncOutFile)
MySprSet.SetIncOutFile(IncOutFile);
if (SprFile)
MySprSet.WriteSprFile(SprFile);
if (OutFile)
{
if (PagePlacements)
{
MySprSet.Write(OutFile,PageBase,WidthPages,HeightPages);
if (OutLbm)
MySprSet.WriteLBM(OutLbm);
if (ReportFile)
MySprSet.WriteReport(ReportFile);
if (s_rawTpageFile)
MySprSet.writeRawTPage(s_rawTpageFile);
}
else
GObject::Error(ERR_FATAL,"-t option hasn't been specified");
}
}
return(0);
}
/*----------------------------------------------------------------------
Function: int CountCommas(char const * Str)
Purpose: Count how many commas there are in this str
Returns: Number of commas
---------------------------------------------------------------------- */
int CountCommas(char const * Str)
{
int Len=strlen(Str);
int NumOfCommas=0;
for (int f=0;f<Len;f++)
{
if (Str[f]==',')
NumOfCommas++;
}
return(NumOfCommas);
}
/*----------------------------------------------------------------------
Function: int ZeroAndCountCommas(char * Str)
Purpose: Count how many commas there are in this str
and change each one to a zero
Returns: Number of commas
---------------------------------------------------------------------- */
int ZeroAndCountCommas(char * Str)
{
int Len=strlen(Str);
int NumOfCommas=0;
for (int f=0;f<Len;f++)
{
if (Str[f]==',')
{
NumOfCommas++;
Str[f]=0;
}
}
return(NumOfCommas);
}
/*----------------------------------------------------------------------
Function: char *CycleCommands(char *String,int Num)
Purpose: Callback to cycle through command line items
Params: String = Text of item
Num = Item number
---------------------------------------------------------------------- */
char * CycleCommands(char *String,int Num)
{
if (GString(String)=="-twisting_my_melon_man")
{
MyFiles.setNoSort();
}
else
{
if (String[0]=='-' || String[0]=='/')
{
int NumOfCommas;
char TpText[100];
GString TpStr;
char * MyText;
switch (String[1])
{
/* Switches */
case 'w':
s_AnimatedHeadersOnly=CheckPlusMinus(String);
break;
case 'b':
s_DontOutputBoxes=CheckPlusMinus(String);
break;
case 'a':
s_AlignHeaders=CheckPlusMinus(String);
break;
case 'h':
s_useHalfTpage=CheckPlusMinus(String);
break;
case 'y':
s_compressTpages=CheckPlusMinus(String);
break;
case '^':
s_noWriteTpages=CheckPlusMinus(String);
break;
case 'p':
MyFiles.ReadRepFile(CheckFileString(String));
break;
case 'r':
MyFiles.SetAllowRotate(CheckPlusMinus(String));
break;
case 's':
MyFiles.SetFileRecursion(CheckPlusMinus(String));
break;
case 'c':
MyFiles.SetCrossHair(CheckPlusMinus(String));
break;
case 'z':
MyFiles.SetZeroColZero(CheckPlusMinus(String));
break;
case 'm':
MyFiles.SetMoveUVs(CheckPlusMinus(String));
break;
case 'q':
MyFiles.SetShrinkToFit(CheckPlusMinus(String));
break;
/* Options that set output files */
case 'o':
OutFile=CheckFileString(String);
break;
case 'x':
SprFile=CheckFileString(String);
break;
case 'l':
OutLbm=CheckFileString(String);
break;
case 'k':
ReportFile=CheckFileString(String);
break;
case 'i':
IncOutFile=CheckFileString(String);
break;
case 'e':
{
GString MaxSize;
MaxSize=CheckFileString(String);
MyFiles.SetMaxSize(atoi(MaxSize));
}
break;
/* More complex options */
case 't':
TpStr=CheckFileString(String);
strcpy(TpText,TpStr);
NumOfCommas=ZeroAndCountCommas(TpText);
if (NumOfCommas != 2)
GObject::Error(ERR_FATAL,"Problem with option %s",String);
MyText=TpText;
PageBase=atoi(MyText);
MyText+=strlen(MyText)+1;
WidthPages=atoi(MyText);
MyText+=strlen(MyText)+1;
HeightPages=atoi(MyText);
PagePlacements=true;
break;
case 'f':
TpStr=CheckFileString(String);
strcpy(TpText,TpStr);
NumOfCommas=ZeroAndCountCommas(TpText);
if (NumOfCommas != 1)
GObject::Error(ERR_FATAL,"Problem with option %s",String);
MyText=TpText;
MyFiles.SetXOff(atoi(MyText));
MyText+=strlen(MyText)+1;
MyFiles.SetYOff(atoi(MyText));
MyText+=strlen(MyText)+1;
MyFiles.SetForceOffsets(true);;
break;
case '~':
s_rawTpageFile=CheckFileString(String);
break;
default:
GObject::Error(ERR_FATAL,"Unknown switch %s",String);
break;
}
}
else
{
GString UpperName(String);
UpperName.Upper();
MyFiles.AddFile(UpperName);
}
}
return(String);
}
/*----------------------------------------------------------------------
Function: void CheckPlusMinus(const char * Str)
Purpose: Check to see if this cmd line item is of the type
-<char>+|-. Aborts out of there was a problem.
Params: Str = Text of item
Returns: true if a plus option
---------------------------------------------------------------------- */
bool CheckPlusMinus(const char * Str)
{
if (strlen(Str)==3 && (Str[0]=='-' || Str[0]=='/') && (Str[2]=='-' || Str[2]=='+'))
{
}
else
GObject::Error(ERR_FATAL,"Problem with cmd line option %s",Str);
return(Str[2]=='+');
}
/*----------------------------------------------------------------------
Function: void CheckPlusMinus(const char * Str)
Purpose: Check to see if this cmd line item is of the type
-<char>+|-. Aborts out of there was a problem.
Params: Str = Text of item
Returns: true if a plus option
---------------------------------------------------------------------- */
GString CheckFileString(const char * Str)
{
GString RetStr;
if (strlen(Str)>3 && (Str[0]=='-' || Str[0]=='/') && (Str[2]==':' || Str[2]==':'))
RetStr=&Str[3];
else
GObject::Error(ERR_FATAL,"Problem with cmd line option %s",Str);
return(RetStr);
}
/*----------------------------------------------------------------------
Function: void Usage(void)
Notes: Usage of the util
---------------------------------------------------------------------- */
void Usage(void)
{
cout<<"Usage: PARKGRAB <file> [ <file>.. ] [ switches.. ]\n";
cout<<"Switches:\n"<<endl;
cout<<"-s<+|->\t\t\tSet recurse sub dirs (default off)"<<endl;
cout<<"-c<+|->\t\t\tSet cross hair offset detection (default off)"<<endl;
cout<<"-z<+|->\t\t\tSet colour zero trans (default off)"<<endl;
cout<<"-m<+|->\t\t\tSet move in u/v coords (default off)"<<endl;
cout<<"-r<+|->\t\t\tSet if spr rotation allowed (default on)"<<endl;
cout<<"-q<+|->\t\t\tShrink to bounds of lbm (default on)"<<endl;
cout<<"-y<+|->\t\t\tCompress tpages (default off)"<<endl;
cout<<"-^<+|->\t\t\tDo not write a tpage (default off)"<<endl;
cout<<"-h<+|->\t\t\tForce tpage height to half (default off)"<<endl;
cout<<"-w<+|->\t\t\tOnly write animated headers (default off)"<<endl;
cout<<"-b<+|->\t\t\tDo not write spare boxes (default off)"<<endl;
cout<<"-a<+|->\t\t\tAlign headers to 2k chunk (default off)"<<endl;
cout<<endl;
cout<<"-f:x,y\t\t\tForce offsets for sprs to x,y"<<endl;
cout<<"-t:b,w,h\t\tt=base tp,x=# tps wide,h=# tps high"<<endl;
cout<<"-e:<maxsize>\t\tSet maximum size for textures"<<endl;
cout<<"-p:<rep file>\t\tRead in a shared texture file for gin files"<<endl;
cout<<endl;
cout<<"-o:<filename>\t\tOutput Vram filename"<<endl;
cout<<"-x:<filename>\t\tOutput Sprfile filename"<<endl;
cout<<"-l:<tplbmname>\t\tWrite out an lbm of the tpage "<<endl;
cout<<"-k:<repname>\t\tWrite out a vram report"<<endl;
cout<<"-~:<filename>\t\tWrite out raw VRAM image"<<endl;
cout<<endl;
cout<<"-twisting_my_melon_man"<<endl;
cout<<endl;
}
/*----------------------------------------------------------------------
Function: void AllFiles::AddFile(const char * Name)
Purpose: Add a file to the list, it takes all the current
properties that the AllFiles object has.
Params: Name of file to add
---------------------------------------------------------------------- */
void AllFiles::AddFile(const char * Name)
{
DoCycle(Name,RecurseFiles);
}
/*----------------------------------------------------------------------
Function: void AllFiles::FileCallback(char const * FName,int FileNum)
---------------------------------------------------------------------- */
#include <gintex.h>
#include <algorithm>
void AllFiles::FileCallback(char const * FName,int FileNum)
{
FileInfo MyInfo;
bool ThisZeroColZero;
GFName FileName(FName);
GString Ext(FileName.Ext());
Ext.Lower();
if (Ext=="gin")
{
vector<GString> NonSharedTextures;
// Gin4File MyFile;
CScene MyFile;
MyFile.Load(FName);
MyFile.GetNonSharedTextures(AllExternalSharedTextures,NonSharedTextures);
vector<GString> NewEntrys;
for (int f=0;f<NonSharedTextures.size();f++)
{
if (find(UniqueTexturesSoFar.begin(),UniqueTexturesSoFar.end(),NonSharedTextures[f]) == UniqueTexturesSoFar.end())
{
NewEntrys.push_back(NonSharedTextures[f]);
UniqueTexturesSoFar.push_back(NonSharedTextures[f]);
}
}
for (f=0;f<NewEntrys.size();f++)
FileCallback(NewEntrys[f],0);
cout<<"Read gin file *"<<FName<<"*"<<endl;
}
else
{
GFName Name(FName);
if (Name.File()[0]=='+')
ThisZeroColZero=true;
else
ThisZeroColZero=ZeroColZero;
if (Name.File()[0]=='!')
m_allocateAs16bit=true;
else
m_allocateAs16bit=false;
if (Name.File()[0] == '@')
{
ThisZeroColZero = true;
m_allocateAs16bit = true;
}
GString TheFile(FName);
TheFile.Lower();
MyInfo.SetInfo(TheFile,CrossHair,ThisZeroColZero,MoveUVs,AllowRotate,ShrinkToFit,m_allocateAs16bit);
cout<<"Add image file "<<TheFile<<endl;
if (ForceOffsets)
MyInfo.SetForceOffsets(XOff,YOff);
AllFileInfos.resize(AllFileInfos.size()+1);
AllFileInfos[AllFileInfos.size()-1]=MyInfo;
}
}
/*----------------------------------------------------------------------
Function: void AllFiles::FileCallback(char const * FName,int FileNum)
---------------------------------------------------------------------- */
void AllFiles::SortOrder()
{
if (!m_noSort)
{
int i,j;
FileInfo MyInfo;
int count = AllFileInfos.size();
for (i=0; i<count; i++)
{
for (j=0; j<count; j++)
{
if (strcmp(AllFileInfos[i].GetFileName(), AllFileInfos[j].GetFileName())<0)
{
MyInfo = AllFileInfos[i];
AllFileInfos[i] = AllFileInfos[j];
AllFileInfos[j] = MyInfo;
}
}
}
}
}
/*===========================================================================
end */

359
Utils/parkgrab/pak.cpp Normal file
View file

@ -0,0 +1,359 @@
/*=========================================================================
PAK.CPP
Author: Gary Liddon @ Climax (from work by Nick Pelling && Carl Muller)
Created:
Project: Diablo PSX
Purpose: PAK decompress \ compress code
Copyright (c) 1997 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
/* Glib
---- */
/* Local
----- */
#include <string.h>
#include "pak.h"
/* Graphics
-------- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
#define UNPAKBUFFERSIZE 4096
#define STRMAX 80
#define BUFFERSIZE 30000
#define TRIGGER 20000
#define MAXUNIQUE 127
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
struct Block
{
int data[128];
BOOL blockrep;
int blocksize;
int blockoffset;
u8 * Dest;
int outsize;
virtual void fputc(u8 Val)
{
*Dest=Val;
Dest++;
outsize++;
}
void writeBlock(void);
};
struct CountBlock : Block
{
virtual void fputc(u8 Val)
{
Dest++;
outsize++;
}
};
/*----------------------------------------------------------------------
Vars
---- */
static int s_lastAmountOfCompressedData;
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
static void writeblock(struct block *theblock);
/*----------------------------------------------------------------------
Vars
---- */
/*----------------------------------------------------------------------
Data
---- */
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void Block::writeBlock(void)
{
if ((blockrep) && (blocksize == 0))
{
/* Terminator */
fputc(128);
fputc(0);
}
else if (blockrep)
{
fputc(blockoffset);
fputc(blocksize);
}
else /* Unique bytes */
{
fputc(blocksize & 127);
for (int i = 0; i <= blocksize; i++)
fputc(data[i]);
}
// Get ready for next block
blockrep = FALSE;
blockoffset = 0;
blocksize = -1;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
static bool memequ(u8 const * p1,u8 const * p2,int size)
{
bool same;
same=true;
for (int f=0;f<size && same;f++)
same=p1[f]==p2[f];
return(same);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int lowLevelPak(u8 * Dest,u8 const * buffer,int insize,Block & theblock)
{
long begin, end, bestlength;
int offset, bestoffset;
unsigned char const * theptr;
unsigned char const * ptr1;
unsigned char const * ptr2;
unsigned char const * ptr3;
long BACKDIST, FORWARDDIST, MINBLOCK;
theblock.Dest=Dest;
theblock.outsize=0;
theblock.blockrep=FALSE;
BACKDIST = -128;
FORWARDDIST = 255;
MINBLOCK = 3;
int inpos = 0;
theblock.blocksize = -1;
theblock.data[++theblock.blocksize] = buffer[inpos++];
theblock.data[++theblock.blocksize] = buffer[inpos++];
while (inpos < insize)
{
/* See if we should load new data into the buffer */
begin = -inpos;
end = insize - inpos;
if (begin < BACKDIST)
begin = BACKDIST;
if (end > FORWARDDIST)
end = FORWARDDIST;
bestoffset = begin;
bestlength = 1;
theptr = buffer + (inpos);
ptr1 = buffer + (inpos + begin);
for (offset = begin; offset < 0; offset++)
{
if (*ptr1 == *theptr)
{
if (memequ(ptr1, theptr, bestlength + 1))
{
bestlength++;
bestoffset = offset;
ptr2 = ptr1 + bestlength;
ptr3 = theptr + bestlength;
while (*ptr2 == *ptr3)
{
ptr2++;
ptr3++;
bestlength++;
if (bestlength >= end)
break;
}
}
}
if (bestlength >= end)
{
bestlength = end;
break;
}
ptr1++;
}
if (bestlength < MINBLOCK)
{
/* See if last block is unique */
if (theblock.blockrep) /* Flush previous special block */
{
theblock.writeBlock();
theblock.data[++theblock.blocksize] = buffer[inpos++];
}
else
{
/* Add to it */
if (theblock.blocksize >= MAXUNIQUE)
theblock.writeBlock();
theblock.data[++theblock.blocksize] = buffer[inpos++];
}
}
else
{
/* We have found a match */
theblock.writeBlock();
theblock.blockrep = TRUE;
theblock.blocksize = bestlength;
theblock.blockoffset = bestoffset;
inpos += bestlength;
}
}
/* Flush buffer */
theblock.writeBlock();
/* Terminate file */
theblock.blockrep = TRUE;
theblock.blocksize = 0;
theblock.blockoffset = 0;
theblock.writeBlock();
return(theblock.outsize);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int PAK_doPak(u8 * Dest,u8 const * buffer,int insize)
{
Block outBlock;
return(lowLevelPak(Dest,buffer,insize,outBlock));
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int PAK_findPakSize(u8 const * buffer,int insize)
{
CountBlock outBlock;
return(lowLevelPak(NULL,buffer,insize,outBlock));
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int PAK_doUnpak(u8 * Dest,u8 const * Source)
{
int outsize = 0;
u8 const * originalSource;
originalSource=Source;
while (1) /* ie, continue until end mark */
{
u8 const * From;
int size;
int ch;
ch = *Source++;
if (ch < 128) /* if it is in range {0..127} then */
{
size = (ch + 1);
From=Source;
Source+=size;
}
else
{
size = *Source++;
if (size == 0) /* distance == 0 => end of file */
break;
From=Dest+(s8)ch;
}
u8 * endAddr;
endAddr=(u8*)(u32(From)+size);
outsize += size;
while (From!=endAddr)
{
*Dest=*From;
Dest++;
From++;
}
}
s_lastAmountOfCompressedData=Source-originalSource;
return(outsize);
}
int PAK_getLastAmountOfDataRead(void)
{
return(s_lastAmountOfCompressedData);
}
/*===========================================================================
end */

61
Utils/parkgrab/pak.h Normal file
View file

@ -0,0 +1,61 @@
/*=========================================================================
PAK.H
Author: Carl Muller (algorithm Nick Pelling && Carl Muller)
Created:
Project:
Purpose:
Copyright (c) 1997 Climax Development Ltd
===========================================================================*/
#ifndef __PAK_PAK_H__
#define __PAK_PAK_H__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
/* Glib
---- */
#include <gtypes.h>
/* Local
----- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Globals
------- */
/* Vars
---- */
/* Data
---- */
/* Functions
--------- */
int PAK_doPak(u8 * Dest,u8 const * source,int insize);
int PAK_doUnpak(u8 * Dest,u8 const * Source);
int PAK_findPakSize(u8 const * souce,int insize);
int PAK_getLastAmountOfDataRead(void);
/*---------------------------------------------------------------------- */
#endif /* __PAK_PAK_H__ */
/*===========================================================================
end */

154
Utils/parkgrab/parkgrab.dsp Normal file
View file

@ -0,0 +1,154 @@
# Microsoft Developer Studio Project File - Name="parkgrab" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=parkgrab - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "parkgrab.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "parkgrab.mak" CFG="parkgrab - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "parkgrab - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "parkgrab - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""$/tp2psx/utils/parkgrab", IXNAAAAA"
# PROP Scc_LocalPath "."
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "parkgrab - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\glibdev\glib\include" /I "..\glibdev\glib\include\pc" /I "..\ginutils\tplib" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c
# ADD BASE RSC /l 0x809 /d "NDEBUG"
# ADD RSC /l 0x809 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib win32lib.lib tplib.lib /nologo /subsystem:console /machine:I386 /out:"../../tools/parkgrab.exe" /libpath:"..\glibdev\glib\lib\win32lib\release" /libpath:"..\ginutils\tplib\release"
!ELSEIF "$(CFG)" == "parkgrab - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /G5 /MDd /W3 /Gm /GX /ZI /Od /I "..\glibdev\glib\include" /I "..\glibdev\glib\include\pc" /I "..\ginutils\tplib" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c
# ADD BASE RSC /l 0x809 /d "_DEBUG"
# ADD RSC /l 0x809 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib win32lib.lib tplib.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\glibdev\glib\lib\win32lib\debug" /libpath:"..\ginutils\tplib\debug"
!ENDIF
# Begin Target
# Name "parkgrab - Win32 Release"
# Name "parkgrab - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\bmploader.cpp
# End Source File
# Begin Source File
SOURCE=.\cross.cpp
# End Source File
# Begin Source File
SOURCE=.\grect.cpp
# End Source File
# Begin Source File
SOURCE=.\main.cpp
# End Source File
# Begin Source File
SOURCE=.\pak.cpp
# End Source File
# Begin Source File
SOURCE=.\sprset.cpp
# End Source File
# Begin Source File
SOURCE=.\tpage.cpp
# End Source File
# Begin Source File
SOURCE=.\VImage.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h"
# Begin Source File
SOURCE=.\bmploader.h
# End Source File
# Begin Source File
SOURCE=.\cross.h
# End Source File
# Begin Source File
SOURCE=.\grect.h
# End Source File
# Begin Source File
SOURCE=.\pak.h
# End Source File
# Begin Source File
SOURCE=.\sprset.h
# End Source File
# Begin Source File
SOURCE=.\tpage.h
# End Source File
# Begin Source File
SOURCE=.\vimage.h
# End Source File
# End Group
# End Target
# End Project

View file

@ -0,0 +1,33 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "parkgrab"=.\parkgrab.dsp - Package Owner=<4>
Package=<5>
{{{
begin source code control
"$/PRLSR/utils/parkgrab", TCEAAAAA
.
end source code control
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

BIN
Utils/parkgrab/parkgrab.ncb Normal file

Binary file not shown.

1314
Utils/parkgrab/sprset.cpp Normal file

File diff suppressed because it is too large Load diff

569
Utils/parkgrab/sprset.h Normal file
View file

@ -0,0 +1,569 @@
/*=========================================================================
SPRSET.CPP
Author: Gary Liddon @ Farehame
Created:
Project: TPW Parkgrab
Purpose: Object that reads in all the frames for sprites
processes them into tpages and spits it all out to
disk
Copyright (c) 1998 G R Liddon
===========================================================================*/
#ifndef __SPRSET_H__
#define __SPRSET_H__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <vector>
/* Glib
---- */
#include <gobject.hpp>
#include <gstring.hpp>
#include <frame.hpp>
#include <misc.hpp>
/* Local
----- */
#include "tpage.h"
#include "vimage.h"
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/* Encapsulates a file and all the infomation parkgrab needs to process it
----------------------------------------------------------------------- */
class FileInfo
{
public:
FileInfo(void)
{
CrossHair=false;
ForceOffsets=false;
}
FileInfo(FileInfo const & Fi)
{
operator=(Fi);
}
void operator=(FileInfo const & Fi)
{
FileName = Fi.FileName;
strcpy(ActualFileName,Fi.ActualFileName);
CrossHair=Fi.CrossHair;
ZeroColZero = Fi.ZeroColZero;
PlusColZero = Fi.PlusColZero;
MoveUVs = Fi.MoveUVs;
AllowRotate=Fi.AllowRotate;
ForceOffsets=Fi.ForceOffsets;
XOff=Fi.XOff;
YOff=Fi.YOff;
ShrinkToFit=Fi.ShrinkToFit;
m_allocateAs16Bit=Fi.m_allocateAs16Bit;
}
void SetForceOffsets(int x,int y)
{
ForceOffsets=true;
XOff=x;
YOff=y;
}
GString CheckForPlus(GString s)
{
GString out;
const char *textin = (const char*)s;
char *textout = new char[s.Len()+1];
memset(textout, 0, s.Len()+1);
int p;
bool plus;
p=0;
if (textin[0] == '+') plus = true;
else plus = false;
/* for (i=0; i<s.Len(); i++)
{
textout[i]=textin[i];
if (textout[i] == '+') plus = true;
// p++;
// else p++;
}
*/ PlusColZero = plus;
out = textin;
delete textout;
return out;
}
void SetInfo(const char * NewFileName,bool NewCrossHair,bool NewZeroColZero, bool NewMoveUVs,bool NewAllowRotate,bool NewShrinkToFit,bool allocateAs16Bit)
{
CrossHair=NewCrossHair;
ZeroColZero=NewZeroColZero;
MoveUVs =NewMoveUVs;
AllowRotate=NewAllowRotate;
SetName(NewFileName);
ShrinkToFit=NewShrinkToFit;
m_allocateAs16Bit=allocateAs16Bit;
/*
if we're allocating on a 16 bit pixel boundary then
we don't want the texture to be rotated
*/
if (allocateAs16Bit)
AllowRotate=false;
}
const char * GetFileName(void) const
{return(FileName);}
const char * GetActualFileName(void) const
{return(ActualFileName);}
void SetName(const char * NewName)
{
if (NewName) strcpy(ActualFileName,NewName);
FileName = CheckForPlus(ActualFileName);
}
bool GetCrossHair(void) const
{return(CrossHair);}
bool GetZeroColZero(void) const
{return(ZeroColZero);}
bool GetPlusColZero(void) const
{return(PlusColZero);}
bool GetMoveUVs(void) const
{return(MoveUVs);}
bool GetAllowRotate(void) const
{return(AllowRotate);}
bool GetForceOffsets(void) const
{
return(ForceOffsets);
}
int GetXOff(void) const
{
return(XOff);
}
int GetYOff(void) const
{
return(YOff);
}
bool getAllocateAs16Bit(void) const
{return(m_allocateAs16Bit);}
char const * GetActualName(void) const
{return(ActualFileName);}
bool GetShrinkToFit(void) const
{return(ShrinkToFit);}
protected:
GString FileName;
char ActualFileName[256];
bool CrossHair;
bool ZeroColZero;
bool PlusColZero;
bool MoveUVs;
bool AllowRotate;
bool ForceOffsets;
bool ShrinkToFit;
bool m_allocateAs16Bit;
int XOff,YOff;
};
typedef std::vector<FileInfo> FIVec;
typedef std::vector<FileInfo>::iterator FIVecIt;
typedef std::vector<FileInfo>::const_iterator FIVecConstIt;
/* A Palette of graphics with sprset specific stuff
---------------------------------------------- */
class SprPal : public Palette
{
public:
SprPal(void)
{}
SprPal(SprPal const & Pal)
{MakeCopy(Pal);}
void operator=(SprPal const & Pal)
{MakeCopy(Pal);}
void operator=(Palette const & Pal)
{Palette::CopyPal(Pal);}
bool operator==(Palette const & Pal)
{return(Palette::operator==(Pal));}
bool operator<(SprPal const & Pal)
{return(GetNumOfCols() < Pal.GetNumOfCols());}
void SetPalIndex(int NewPalIndex)
{PalIndex=NewPalIndex;}
int GetPalIndex(void) const
{return(PalIndex);}
void SetVRAMPos(TPRect & NewRect)
{
MyRect=NewRect;
}
void SetTpBase(int NewTpBase)
{
TpBase=NewTpBase;
BaseTpX=((TpBase&0xf)*64);
BaseTpY=(TpBase>>4)*256;
}
u16 GetClut(void)
{
int x=(MyRect.X/4)+BaseTpX;
int y=MyRect.Y+BaseTpY;
return((y<<6)|((x>>4)&0x3f));
}
TPRect const & GetTPRect(void) const
{return(MyRect);}
char const * GetName(void) const
{return(Name);}
void SetName(char const * NewName)
{Name=NewName;}
void SetZeroColZero(bool New)
{ZeroColZero=New;}
bool GetZeroColZero(void) const
{return(ZeroColZero);}
void SetPlusColZero(bool New)
{PlusColZero=New;}
bool GetPlusColZero(void) const
{return(PlusColZero);}
void Write(Gofstream & Out) const;
void MakePSXPal(std::vector<u16> & OutWord) const;
u16 GetPsxCol(Colour const & Col) const;
protected:
int PalIndex;
int TpBase;
int BaseTpX;
int BaseTpY;
bool ZeroColZero;
bool PlusColZero;
TPRect MyRect;
GString Name;
void MakeCopy(SprPal const & NewPal)
{
Palette::CopyPal(NewPal);
PalIndex=NewPal.PalIndex;
TpBase=NewPal.TpBase;
BaseTpX=NewPal.BaseTpX;
BaseTpY=NewPal.BaseTpY;
MyRect=NewPal.MyRect;
Name=NewPal.Name;
ZeroColZero=NewPal.ZeroColZero;
PlusColZero=NewPal.PlusColZero;
}
};
/* A Frame of graphics with sprset specific stuff
---------------------------------------------- */
class SprFrame : public Frame
{
public:
enum BDEPTH
{
BITS_4,
BITS_8,
};
SprFrame(void);
SprFrame(SprFrame const & NewFrame)
{MakeCopy(NewFrame);}
void operator=(SprFrame const & NewFrame)
{MakeCopy(NewFrame);}
void SetFrameAndInfo(Frame const & Fr,FileInfo const & MyFileInfo,int MaxSize);
FileInfo * GetFileInfo(void)
{
return (&MyFileInfo);
}
void Process(void);
void SetPalIndex(int NewPalIndex)
{PalIndex=NewPalIndex;}
int GetPalIndex(void) const
{return(PalIndex);}
void SetVRAMPos(TPRect const & Rect);
BDEPTH GetBitDepth(void) const
{
BDEPTH RetDepth;
int NumOfCols;
NumOfCols=MyPal.GetNumOfCols();
if (NumOfCols<=16)
RetDepth=BITS_4;
else
RetDepth=BITS_8;
return(RetDepth);
}
TPRect const & GetTPRect(void) const
{return(MyRect);}
bool IsRotated(void) const
{return(MyRect.GetRotate());}
void SetTpBase(int NewTpBase)
{
TpBase=NewTpBase;
BaseTpX=((TpBase&0xf)*64);
BaseTpY=(TpBase>>4)*256;
}
void SetClut(u16 NewClut)
{Clut=NewClut;}
u16 GetClut(void) const
{return(Clut);}
void WriteHeader(Gofstream & Out);
bool GetZeroColZero(void) const
{return(MyFileInfo.GetZeroColZero());}
bool GetPlusColZero(void) const
{return(MyFileInfo.GetPlusColZero());}
bool GetAllowRotate(void) const
{return(MyFileInfo.GetAllowRotate());}
void Write(Gofstream & Out) const;
void WriteHeaderNotInVram(Gofstream & Out);
int getV(void)
{return(MyRect.X&0xff);}
int getU(void)
{
u16 tpage;
int u;
int pageX;
tpage=GetTpage();
pageX=(tpage&0xf)*256;
u=MyRect.X-pageX;
switch(GetBitDepth())
{
case BITS_8:
u/=2;
break;
}
return(u);
}
u16 GetTpage(void)
{
int tp;
BDEPTH RetDepth;
RetDepth=GetBitDepth();
int abr=0;
int x=BaseTpX + (MyRect.X/4); //MA
int y=BaseTpY + MyRect.Y; //MA
switch(RetDepth)
{
case BITS_4:
tp=0;
break;
case BITS_8:
tp=1;
break;
}
return((((tp)&0x3)<<7)|(((abr)&0x3)<<5)|(((y)&0x100)>>4)|(((x)&0x3ff)>>6)| (((y)&0x200)<<2));
}
bool IsAnimated()
{
return(MyFileInfo.getAllocateAs16Bit());
}
protected:
void ResizeAndReduce(Frame & Frm,int TargCols,float XPerc,float YPerc,bool ZeroSeeThrough);
void MakeCopy(SprFrame const & NewFrame)
{
Frame::CopyFrame(NewFrame);
Clut=NewFrame.Clut;
TpBase=NewFrame.TpBase;
BaseTpX=NewFrame.BaseTpX;
BaseTpY=NewFrame.BaseTpY;
PalIndex=NewFrame.PalIndex;
MyFileInfo=NewFrame.MyFileInfo;
MyRect=NewFrame.MyRect;
}
u16 Clut;
int TpBase;
int BaseTpX;
int BaseTpY;
GString loadFileName;
int PalIndex;
FileInfo MyFileInfo;
TPRect MyRect;
};
/* A collection of sprites
----------------------- */
class SprSet : protected GObject
{
public:
SprSet(void)
{
Vi=NULL;
MaxSize=0;
}
void SetMaxSize(int New)
{MaxSize=New;}
void AddFiles(FIVec const & FileList);
void Write(char const * FileName,int TpNumber,int WidthInTpages,int HeightInTpages);
void WriteLBM(char const * FileName);
void WriteSprFile(char const * Name);
void WriteReport(char const * Name);
void writeRawTPage(char const * File);
void SetIncOutFile(char const * NewIncOutFile)
{IncOutFile=NewIncOutFile;IncOutFile.Lower();}
void setAnimatedHeader(bool newVal)
{m_AnimatedHeadersOnly=newVal;}
void setDontOutputBoxes(bool newVal)
{m_DontOutputBoxes=newVal;}
void setAlignHeaders(bool newVal)
{m_AlignHeaders=newVal;}
void setHalfTpage(bool newVal)
{m_halfTpage=newVal;}
void setCompressTpages(bool newVal)
{m_compressTpages=newVal;}
void setNoWriteTpages(bool newVal)
{m_noWriteTpages=newVal;}
protected:
void WriteHeaderFile(char const * HName);
void ProcessPals(void);
void AddFile(FileInfo const & ThisInfo);
void AddAnm(FileInfo const & ThisInfo);
void AddLbm(FileInfo const & ThisInfo);
void AddFrame(Frame const & Fr,FileInfo const & ThisInfo);
void AddFramesAndPalsToVRAM(VRAM & Vr,int TpNumber,int WidthInTpages,int HeightInPixels);
GString GetHeaderFileName(char const * File);
typedef std::vector<SprFrame> SprFrVec;
typedef std::vector<SprFrame>::iterator SprFrIt;
typedef std::vector<SprPal> SprPalVec;
typedef std::vector<SprPal>::iterator SprPalVecIt;
GString IncOutFile;
bool m_AnimatedHeadersOnly;
bool m_DontOutputBoxes;
bool m_AlignHeaders;
bool m_halfTpage;
bool m_compressTpages;
bool m_noWriteTpages;
SprFrVec AllSprFrames;
SprPalVec AllSprPals;
VRAMImage * Vi;
int MaxSize;
};
/*----------------------------------------------------------------------
Globals
------- */
/* Vars
---- */
/* Data
---- */
/* Functions
--------- */
/*---------------------------------------------------------------------- */
#else /* __SPRSET_H__ */
class SprPal;
class SprFrame;
#endif
/*===========================================================================
end */

857
Utils/parkgrab/tpage.cpp Normal file
View file

@ -0,0 +1,857 @@
/*=========================================================================
FILENAME.CPP
Author: Gary Liddon @
Created:
Project:
Purpose:
Copyright (c) 1997 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <algorithm>
#include "conio.h"
/* Glib
---- */
#include "gutils.h"
/* Local
----- */
#include "tpage.h"
#include "grect.h"
/* Graphics
-------- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
using namespace std;
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
struct TPInfo
{
int XAlign;
int TpWidth;
int BorderX;
int BorderY;
};
/* Information about where I can place this frame in the Tpage
----------------------------------------------------------- */
/*----------------------------------------------------------------------
Vars
---- */
static TPInfo const InfStruct[TP_NUM_OF_TP_TYPES]=
{
{1,256,1,1}, /* TP_4 */
{2,512,2,1}, /* TP_8 */
{4,256,4,1}, /* TP_16 */
{0,0,0,0}, /* TP_SCREEN */
{16*4,1024*4,0,0}, /* TP_PAL */
};
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
int TPRect::W2Alloc=1;
int TPRect::H2Alloc=1;
/*----------------------------------------------------------------------
Data
---- */
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
VRAM::VRAM(int nTpWidth,int nTpHeightInPixels)
{
Big2Little=false;
RotateEveryEmpty=false;
TpWidth=-1;
TpHeightInPixels=-1;
Clear(nTpWidth,nTpHeightInPixels);
}
void VRAM::Clear(int nTpWidth,int nTpHeightInPixels)
{
if (nTpWidth >= 0 )
TpWidth=nTpWidth;
if (nTpHeightInPixels >= 0)
TpHeightInPixels=nTpHeightInPixels;
InitEmpty(0,0,TpWidth*256,TpHeightInPixels);
}
/*----------------------------------------------------------------------
Function: void VRAM::InitEmpty(void)
Purpose: Initialise the VRAM as empty
Params:
Returns:
---------------------------------------------------------------------- */
void VRAM::InitEmpty(int vX,int vY,int nW,int nH)
{
const int Width16=256;
const int Height16=256;
W=nW;
H=nH;
X=vX;
Y=vY;
VRAMWidthPages=W/Width16;
VRAMHeightPages=H/Height16;
if (!VRAMHeightPages)
{
VRAMHeightPages = 1;
}
NumOfTPages=VRAMWidthPages*VRAMHeightPages;
VecOfPages.resize(NumOfTPages,TPRectList());
Unused.reserve(4000);
Used.reserve(2000);
Unused.resize(0);
Used.resize(0);
for (int f=0;f<NumOfTPages;f++)
VecOfPages[f].resize(0);
for (int y=0;y<VRAMHeightPages;y++)
for (int x=0;x<VRAMWidthPages;x++)
AddEmpty((x*Width16)+vX,(y*Height16)+vY,Width16,Height16);
}
/*----------------------------------------------------------------------
Function: bool TryNFit(TPRectList & TpList)
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
bool VRAM::TryNFit(TPRectList & TpList,TPRect & ThisRect)
{
bool Done=false;
TPRectList::iterator f;
for (f=TpList.begin();f!=TpList.end();f++)
{
TPRect & BlankRect = *f;
if (TryRect(BlankRect,ThisRect))
return(true);
else
{
if (RotateEveryEmpty && CanRotate(ThisRect))
{
ThisRect.SetRotate(!ThisRect.GetRotate());
if (TryRect(BlankRect,ThisRect))
return(true);
else
ThisRect.SetRotate(!ThisRect.GetRotate());
}
}
}
return(false);
}
void VRAM::PosFromTPrect(TPRect & ThisRect,POS_INFO & Pi)
{
TPInfo const * Tpi;
int WorkingWidth;
Tpi=&InfStruct[ThisRect.TypeOfPage];
Pi.XAlign=Tpi->XAlign;
WorkingWidth=GU_AlignVal(ThisRect.W,Pi.XAlign);
Pi.MinX=Tpi->BorderX;
Pi.MinY=Tpi->BorderY;
Pi.MaxX=W-Tpi->BorderX-WorkingWidth;
Pi.MaxY=H-Tpi->BorderY-ThisRect.H;
Pi.TpWidthPix=Tpi->TpWidth;
Pi.MinXTp=Tpi->BorderX;
Pi.MaxXTp=Tpi->TpWidth-Tpi->BorderX-WorkingWidth;
Pi.MinYTp=Tpi->BorderY;
Pi.MaxYTp=(256-Tpi->BorderY)-ThisRect.H;
}
bool VRAM::TryRect(TPRect & BlankRect,TPRect & ThisRect)
{
POS_INFO Pi;
PosFromTPrect(ThisRect,Pi);
int MinTpX=Pi.MinXTp+(BlankRect.X/Pi.TpWidthPix)*Pi.TpWidthPix;
int MaxTpX=Pi.MaxXTp+(BlankRect.X/Pi.TpWidthPix)*Pi.TpWidthPix;
int MinTpY=Pi.MinYTp+(BlankRect.Y/256)*256;
int MaxTpY=Pi.MaxYTp+(BlankRect.Y/256)*256;
/* Move to avoid edges of the map */
int MinX = MinTpX > Pi.MinX ? MinTpX : Pi.MinX;
int MaxX = MaxTpX < Pi.MaxX ? MaxTpX : Pi.MaxX;
int MinY = MinTpY > Pi.MinY ? MinTpY : Pi.MinY;
int MaxY = MaxTpY < Pi.MaxY ? MaxTpY : Pi.MaxY;
int ThisX=GU_AlignVal(BlankRect.X,Pi.XAlign);
int ThisY=BlankRect.Y;
if (ThisX<MinX)
ThisX=MinX;
if (ThisX>MaxX)
return(false);
if (ThisY<MinY)
ThisY=MinY;
if (ThisY>MaxY)
return(false);
ThisRect.SetXY(ThisX,ThisY);
if (!InColisionWithUsed(ThisRect))
{
RemovedFromUnused(ThisRect);
AddToUsed(ThisRect);
return(true);
}
return(false);
}
/*----------------------------------------------------------------------
Function: TPRect VRAM::AllocVRAM(TPageType nType,int nW,int nH,bool Rotated)
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
class Predicate
{
public:
bool operator()(TPRect const & R1,TPRect const & R2) const
{
u32 R1Val=(R1.H<<16)|(R1.W);
u32 R2Val=(R2.H<<16)|(R2.W);
return (R1Val<R2Val);
}
};
class Predicate2
{
public:
bool operator()(TPRect const & R1,TPRect const & R2) const
{
u32 R1Val=(R1.H<<16)|(R1.W);
u32 R2Val=(R2.H<<16)|(R2.W);
return (R1Val>R2Val);
}
};
/*----------------------------------------------------------------------
Function: TPRect VRAM::AllocVRAM(TpRectVec & RectVec)
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
bool VRAM::AllocVRAM(TPRectVec & RectVec,bool nRotateEveryEmpty,bool nBig2Little,bool nWiderThanHigher)
{
int f;
RotateEveryEmpty=nRotateEveryEmpty;
Big2Little=nBig2Little;
WiderThanHigher=nWiderThanHigher;
if (WiderThanHigher)
{
for (f=0;f<RectVec.size();f++)
{
if ((RectVec[f].H > RectVec[f].W) && CanRotate(RectVec[f]))
RectVec[f].SetRotate(!RectVec[f].GetRotate());
}
}
if (!Big2Little)
std::sort(RectVec.begin(),RectVec.end(),Predicate());
else
std::sort(RectVec.begin(),RectVec.end(),Predicate2());
bool AllocedEverything=true;
for (f=0;f<RectVec.size();f++)
{
if (!AllocVRAM(RectVec[f]))
{
AllocedEverything=false;
cout<<"Couldn't alloc "<<RectVec[f].W<<","<<RectVec[f].H<<endl;
}
}
return(AllocedEverything);
}
/*----------------------------------------------------------------------
Function: void VRAM::AllocVRAM(TPageType nType,int nW,int nH)
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
bool VRAM::AllocVRAM(TPRect & OriginalRect)
{
bool Done;
TPRect ThisRect;
ThisRect=OriginalRect;
Done=false;
for (int Page=0;Page<NumOfTPages && !Done;Page++)
{
VecOfPages[Page].sort();
TPRect::SetAllocWH(ThisRect.W,ThisRect.H);
if (!TryNFit(VecOfPages[Page],ThisRect))
{
if (CanRotate(ThisRect))
{
ThisRect.SetRotate(!ThisRect.GetRotate());
VecOfPages[Page].sort();
TPRect::SetAllocWH(ThisRect.W,ThisRect.H);
if (!TryNFit(VecOfPages[Page],ThisRect))
ThisRect.SetRotate(!ThisRect.GetRotate());
else
Done=true;
}
}
else
Done=true;
}
if (Done)
{
OriginalRect=ThisRect;
OriginalRect.SetAlloced(true);
return(true);
}
else
{
OriginalRect.SetAlloced(false);
return(false);
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
bool VRAM::CanRotate(TPRect & ThisRect)
{
if (ThisRect.GetDontRotate())
return(false);
switch (ThisRect.TypeOfPage)
{
case TP_PAL:
return(false);
case TP_4:
case TP_8:
case TP_16:
return(true);
case TP_SCREEN:
case TP_NUM_OF_TP_TYPES:
default:
Error(ERR_FATAL,"Not catered for");
return(false);
}
}
/*----------------------------------------------------------------------
Function: void VRAM::AllocVRAM(TPageType nType,int nW,int nH)
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void VRAM::RectFromTpRect(Rect & R,TPRect const & ThisRect)
{
R.W=ThisRect.W;
R.H=ThisRect.H;
R.X=ThisRect.X;
R.Y=ThisRect.Y;
}
void VRAM::RemovedFromUnused(TPRect const & ThisRect)
{
RectVec Result;
Rect NewRect;
int f;
RectFromTpRect(NewRect,ThisRect);
int ColidedWith=0;
for ( f=0;f<Unused.size();f++)
{
Rect UnusedRect;
RectFromTpRect(UnusedRect,Unused[f]);
if (UnusedRect.IsColiding(ThisRect) )
{
CutRect(UnusedRect,ThisRect,Result);
ColidedWith++;
}
else
Result.push_back(UnusedRect);
}
Unused.resize(0);
for (f=0;f<NumOfTPages;f++)
VecOfPages[f].resize(0);
for (f=0;f<Result.size();f++)
AddEmpty(Result[f].X,Result[f].Y,Result[f].W,Result[f].H);
}
void VRAM::AddEmpty(int x,int y,int w,int h)
{
Unused.resize(Unused.size()+1);
TPRect & ThisRect=(Unused[Unused.size()-1]);
ThisRect.TypeOfPage=TP_4;
ThisRect.W=w;
ThisRect.H=h;
ThisRect.X=x;
ThisRect.Y=y;
int TpNum=(x/256)+((y/256)*VRAMWidthPages);
VecOfPages[TpNum].insert(VecOfPages[TpNum].end(),ThisRect);
}
void VRAM::AddToUsed(TPRect const & ThisRect)
{
Used.push_back(ThisRect);
}
bool VRAM::InColisionWithUsed(TPRect const & R)
{
for (int f=0;f<Used.size();f++)
{
if (R.IsColiding(Used[f]))
return(true);
}
return(false);
}
/*----------------------------------------------------------------------
Function: bool VRAM::CheckValidAlloc(TPageType nType,int nW,int nH)
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
bool VRAM::CheckValidAlloc(TPageType nType,int nW,int nH)
{
return(true);
}
/*----------------------------------------------------------------------
Function: int VRAM::GetMaxWidthTp(TPageType nType)
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int VRAM::GetMaxWidthTp(TPageType nType)
{
int RetVal;
switch (nType)
{
case TP_4:
RetVal=1;
break;
case TP_8:
RetVal=2;
break;
case TP_16:
RetVal=4;
break;
case TP_SCREEN:
RetVal=256;
break;
default:
RetVal=-1;
Error(ERR_FATAL,"Illegal tpage type");
break;
}
return(RetVal);
}
/*----------------------------------------------------------------------
Function: int VRAM::GetXAlign(TPageType nType)
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int VRAM::GetXAlign(TPageType nType)
{
int RetVal;
switch (nType)
{
case TP_4:
RetVal=1;
break;
case TP_8:
RetVal=2;
break;
case TP_16:
RetVal=4;
break;
case TP_PAL:
RetVal=16*4;
break;
case TP_SCREEN:
RetVal=4;
break;
default:
RetVal=-1;
Error(ERR_FATAL,"Illegal tpage type");
break;
}
return(RetVal);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
TPRect & VRAM::NewItem(TPRectVec & TPRects)
{
TPRects.resize(TPRects.size()+1);
return(TPRects[TPRects.size()-1]);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
TPRect::TPRect(void)
{
InitRect();
}
void TPRect::InitRect(void)
{
X=0;
Y=0;
W=0;
H=0;
TypeOfPage=TP_4;
Rotated=false;
Alloced=false;
DontRotate=false;
}
TPRect::TPRect(TPageType nType,int nW,int nH)
{
int WidthMul;
InitRect();
WidthMul=GetWidthMul(nType);
W=nW*WidthMul;
H=nH;
TypeOfPage=nType;
}
int TPRect::GetWidthMul(TPageType nType)
{
int WidthMul;
switch (nType)
{
case TP_4:
WidthMul=1;
break;
case TP_8:
WidthMul=2;
break;
case TP_16:
case TP_SCREEN:
case TP_PAL:
WidthMul=4;
break;
case TP_NUM_OF_TP_TYPES:
default:
Error(ERR_FATAL,"Can't alloc type TP_NUM_OF_TP_TYPES");
break;
}
return (WidthMul);
}
void TPRect::Set(TPageType nType,int nX,int nY,int nW,int nH)
{
TypeOfPage=nType;
X=nX;
Y=nY;
W=nW*GetWidthMul(nType);
H=nH;
}
void TPRect::SetXY(int nX,int nY)
{
X=nX;
Y=nY;
}
u32 TPRect::GetId(void) const
{
int Colis=0;
int PageNum=(X/256)+((Y/256)*16);
if ((X/256) != ((X+W2Alloc-1)/256))
Colis|=1;
if ((Y/256) != ((Y+H2Alloc-1)/256))
Colis|=2;
return ((Colis<<24)|(PageNum<<16)|((Y&0xff)<<8)|(X&0xff));
}
bool TPRect::SetRotate(bool Rot)
{
bool RetBool=Rotated;
if (Rot != RetBool)
{
W/=GetWidthMul(TypeOfPage);
int Temp=W;
W=H;
H=Temp;
W*=GetWidthMul(TypeOfPage);
}
Rotated=Rot;
return(RetBool);
}
void VRAM::getUnusedSpace(TPRectVec & unusedBoxes)
{
int vX=X;
int vY=Y;
const int Width16=256;
const int Height16=256;
for (int y=0;y<VRAMHeightPages;y++)
for (int x=0;x<VRAMWidthPages;x++)
{
TPRect thisRect;
bool foundRect;
foundRect=false;
for (int f=1;f<255 && !foundRect;f++)
{
int boxBaseY;
int boxHeight;
boxBaseY=f;
boxHeight=255-f;
thisRect.X=(x*Width16)+vX;
thisRect.Y=(y*Height16)+vY+boxBaseY;
thisRect.W=Width16;
thisRect.H=boxHeight;
if (!InColisionWithUsed(thisRect))
foundRect=true;
}
if (foundRect)
unusedBoxes.push_back(thisRect);
}
}
int VRAM::GetNumOfUsedPages()
{
int Used=0;
int vX=X;
int vY=Y;
const int Width16=256;
const int Height16=256;
for (int y=0;y<VRAMHeightPages;y++)
for (int x=0;x<VRAMWidthPages;x++)
{
TPRect ThisRect;
ThisRect.X=(x*Width16)+vX;
ThisRect.Y=(y*Height16)+vY;
ThisRect.W=Width16;
ThisRect.H=Height16;
if (InColisionWithUsed(ThisRect))
Used++;
}
return(Used);
}
bool TPRect::IsAlloced(void) const
{
return(Alloced);
}
void TPRect::SetAlloced(bool nAlloced)
{
Alloced=nAlloced;
}
int VRAM::GetNumOfItems()
{
return(Used.size());
}
void TPRect::InitFromFrame(Frame const & Fr)
{
/* !!!!! Make this support other bit widths */
W=Fr.GetWidth();
H=Fr.GetHeight();
if (Fr.GetNumOfCols() <= 16)
TypeOfPage=TP_4;
else if (Fr.GetNumOfCols() <= 256)
TypeOfPage=TP_8;
else
Error(ERR_FATAL,"Only 4 & 8 bit supported right now");
W*=GetWidthMul(TypeOfPage);
}
TPageType TPRect::convertTo16Bit(void)
{
TPageType oldType;
switch (TypeOfPage)
{
case TP_4:
// W=GU_AlignVal(W,4)/4;
break;
case TP_8:
// W=GU_AlignVal(W,2)/2;
break;
default:
Error(ERR_FATAL,"Only 4 & 8 bit supported right now");
break;
}
oldType=TypeOfPage;
TypeOfPage=TP_16;
return(oldType);
}
void TPRect::convertFrom16Bit(TPageType newType)
{
switch (newType)
{
case TP_4:
// W=W*4;
break;
case TP_8:
// W=W*2;
break;
default:
Error(ERR_FATAL,"Only 4 & 8 bit supported right now");
break;
}
TypeOfPage=newType;
}
/*===========================================================================
end */

260
Utils/parkgrab/tpage.h Normal file
View file

@ -0,0 +1,260 @@
/*=========================================================================
FILENAME.CPP
Author: Gary Liddon @
Created:
Project:
Purpose:
Copyright (c) 1997 Climax Development Ltd
===========================================================================*/
#ifndef __TPAGE_HPP__
#define __TPAGE_HPP__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <list>
/* Glib
---- */
#include <frame.hpp>
/* Local
----- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
struct POS_INFO
{
int MinXTp; /* Minimum x placeable within a Tpage */
int MaxXTp; /* Maximum x placeable within a Tpage */
int MinYTp; /* Minimum y placeable within a Tpage */
int MaxYTp; /* Maximum y placeable within a Tpage */
int MinX; /* Minimum global x */
int MaxX; /* Maximum global x */
int MinY; /* Minimum global y */
int MaxY; /* Maximum global y */
int XAlign; /* X Alignment */
int TpWidthPix; /* Width of each tpages for this rect */
};
/* Different Tpage Types
--------------------- */
enum TPageType
{
TP_4= 0,
TP_8,
TP_16,
TP_SCREEN,
TP_PAL,
TP_NUM_OF_TP_TYPES,
};
/* A Rectangle in the Tpage
------------------------ */
class TPRect : public Rect
{
public:
TPRect(void);
TPRect(TPageType nType,int nW,int nH);
TPRect(TPRect const & NewR) {MakeCopy(NewR);}
void InitFromFrame(Frame const & Fr);
void SetAlloced(bool nAlloced=true);
bool SetRotate(bool Rot=true);
void operator=(TPRect const & NewR) {MakeCopy(NewR);}
bool operator< (TPRect const & R) const {return(GetId()<R.GetId());}
void SetWH(int nW,int nH)
{W=nW;H=nH;}
void SetXY(int nX,int nY);
void Set(TPageType nType,int nX,int nY,int nW,int nH);
void SetTpType(TPageType nType) {TypeOfPage=nType;}
bool GetRotate(void) const {return(Rotated);}
bool IsAlloced(void) const;
int GetTpageIn(void) const;
u32 GetId(void) const;
bool GetAlloced(void){return(Alloced);}
static void SetAllocWH(int nW,int nH) {W2Alloc=nW; H2Alloc=nH;}
TPageType convertTo16Bit(void);
void convertFrom16Bit(TPageType newType);
void SetId(int NewId)
{Id=NewId;}
int GetId(void)
{return(Id);}
TPageType TypeOfPage;
void SetDontRotate(bool NewVal=true) {DontRotate=NewVal;}
bool GetDontRotate(void) const {return(DontRotate);}
protected:
int GetWidthMul(TPageType nType);
void InitRect(void);
bool Rotated;
int Id;
void MakeCopy(TPRect const & NewR)
{
W=NewR.W;
H=NewR.H;
X=NewR.X;
Y=NewR.Y;
TypeOfPage=NewR.TypeOfPage;
Rotated=NewR.Rotated;
Id=NewR.Id;
Alloced=NewR.Alloced;
DontRotate=NewR.DontRotate;
}
static int W2Alloc;
static int H2Alloc;
bool Alloced;
bool DontRotate;
};
/* VRAM Alloc handle
----------------- */
typedef int VHND;
typedef std::vector<TPRect> TPRectVec;
/* VRAM
---- */
typedef std::list<TPRect> TPRectList;
typedef std::vector<TPRectList> TPRectListVec;
class VRAM : public GObject
{
public:
VRAM(int nTpWidth=16,int nTpHeightInPixels=512);
int GetNumOfItems(void);
int GetNumOfUsedPages();
bool AllocVRAM(TPRect & OriginalRect);
bool AllocVRAM(TPRectVec & RectVec,bool nRotateEveryEmpty,bool nBig2Little,bool nWiderThanHigher);
TPRect const & GetVRAM(VHND hnd) const;
TPRectVec & GetUsed(void)
{return(Used);}
TPRectVec & GetUnused(void)
{return(Unused);}
void Clear(int nTpWidth=-1,int nTpHeight=-1);
void SetBig2Little(bool Val=true)
{ Big2Little=Val;}
void SetRotateEveryEmpty(bool Val=true)
{ RotateEveryEmpty=Val;}
bool CanRotate(TPRect & ThisRect);
void getUnusedSpace(TPRectVec & unusedBoxes);
protected:
void PosFromTPrect(TPRect & ThisRect,POS_INFO & Pi);
bool TryRect(TPRect & BlankRect,TPRect & ThisRect);
TPRectListVec VecOfPages;
bool TryNFit(TPRectList & TpList,TPRect & ThisRect);
void AddEmpty(int x,int y,int w,int h);
bool InColisionWithUsed(TPRect const & R);
void InitEmpty(int vX,int vY,int W,int H);
bool CheckValidAlloc(TPageType nType,int nW,int nH);
int GetXAlign(TPageType nType);
int GetMaxWidthTp(TPageType nType);
void RemovedFromUnused(TPRect const & ThisRect);
void AddToUsed(TPRect const & ThisRect);
void RectFromTpRect(Rect & R,TPRect const & ThisRect);
TPRect & NewItem(TPRectVec & TPRects);
TPRect & NewUnused(void)
{ return(NewItem(Unused)); }
TPRect & NewUsed(void)
{ return(NewItem(Used)); }
TPRectVec Unused;
TPRectVec Used;
TPRect ErrorRect;
int X,Y,W,H;
int NumOfTPages;
int TpWidth;
int TpHeightInPixels;
int VRAMWidthPages;
int VRAMHeightPages;
bool Big2Little;
bool RotateEveryEmpty;
bool WiderThanHigher;
};
/* Error codes for VHND
-------------------- */
enum
{
VHND_NULL = -1,
};
/*----------------------------------------------------------------------
Globals
------- */
/* Vars
---- */
/* Data
---- */
/* Functions
--------- */
void TestTPageStuff(void);
/*---------------------------------------------------------------------- */
#endif /* __TPAGE_HPP__ */
/*===========================================================================
end */

103
Utils/parkgrab/vimage.h Normal file
View file

@ -0,0 +1,103 @@
/*=========================================================================
VIMAGE.CPP
Author: Gary Liddon @ Climax
Created:
Project: TPW Parkgrab
Purpose: An object that represents a bit of VRAM
Copyright (c) 1998 G R Liddon
===========================================================================*/
#ifndef __VIMAGE_H__
#define __VIMAGE_H__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
/* Glib
---- */
#include <gobject.hpp>
#include <fstream>
/* Local
----- */
#include "sprset.h"
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
class VRAMImage : protected GObject
{
public:
VRAMImage(int NewWidthInTpages,int NewHeightInPixels);
~VRAMImage(void);
void WriteInTpageChunks(std::ofstream & Str);
void Write(std::ofstream & Str);
void PlotPal(SprPal const & PalToPlot);
void PlotFrame(SprFrame const & FrameToPlot);
void SaveAs16ColLbm(const char * Name);
void setDoCompress(bool newVal)
{m_doCompress=newVal;}
bool getDoCompress(void) const
{return(m_doCompress);}
void getTpData(unsigned int tp,std::vector<u8> & dest) const;
protected:
void PlotFrame4(SprFrame const & Fr);
void PlotFrame8(SprFrame const & Fr);
u16 GetPsxCol(Colour const & Col) const;
int WidthInBytes;
int WidthInTpages;
int HeightInTPages;
int HeightInPixels;
int aTPageHeight;
int TPageSizeInBytes;
int VramAreaBytes;
bool m_doCompress;
u8 * lbmData;
u8 * VRAMData;
};
/*----------------------------------------------------------------------
Globals
------- */
/* Vars
---- */
/* Data
---- */
/* Functions
--------- */
/*---------------------------------------------------------------------- */
#else /* __VIMAGE_H__ */
class VRAMImage;
#endif
/*===========================================================================
end */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,97 @@
/*=========================================================================
KANJICLASS.CPP
Author: Gary Liddon @
Created:
Project:
Purpose:
Copyright (c) 1998 G R Liddon
===========================================================================*/
#ifndef __KANJI_CLASS__
#define __KANJI_CLASS__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <vector>
/* Glib
---- */
#include <gtypes.h>
#include <gobject.hpp>
/* Local
----- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
class KanjiClass : GObject
{
public:
enum KanjiFontSize
{
FONT_SIZE_11,
FONT_SIZE_13,
FONT_SIZE_15,
};
private:
std::vector<u8> m_kanjiHit;
void initialise(void);
void addKanjiHit(uint hi,uint lo);
bool getKanjiHit(uint hi,uint lo);
void clearKanjiHit(uint hi,uint lo);
int findKanjiIndex(u16 kan) const;
static void saveKanjiLbm(char const * fileName,KanjiFontSize k,u16 kan);
public:
KanjiClass(void);
void addStr(u8 const * newStr);
int howManyKanjiChars(void);
void saveKanjiLbms(char const * dir,KanjiFontSize k = KanjiClass::FONT_SIZE_11);
void saveKanjiLbmNames(char const * dir,char const *name);
void saveKanjiTable(char const *name);
static void writeEnglishFontLbms(char const * dir,KanjiFontSize k = KanjiClass::FONT_SIZE_11,char const * repFile= NULL);
};
/*----------------------------------------------------------------------
Globals
------- */
/* Vars
---- */
/* Data
---- */
/* Functions
--------- */
/*---------------------------------------------------------------------- */
#endif /* XYZ */
/*===========================================================================
end */

299
Utils/transtext/main.cpp Normal file
View file

@ -0,0 +1,299 @@
/*=========================================================================
MAIN.CPP
Author: Gary Liddon @ Fareham
Created: 3rd March 1999
Project: Theme Park World Playstation
Purpose: Main module for Folio
Copyright (c) 1998 G R Liddon
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <vector>
#include <conio.h>
#include <sys/stat.h>
#include <sys/utime.h>
#include <fcntl.h>
#include <io.h>
/* Glib
---- */
#include <misc.hpp>
#include <gfname.hpp>
#include <gstring.hpp>
#include <pcre.h>
/* tplib
---- */
#include <trans.h>
#include <lang.h>
#include <script.h>
/* local
---- */
#include "kanjiclass.h"
/*----------------------------------------------------------------------
Version info
1.0 - 1.2 GL Initial working version
1.3 GL Longer line length (now 4096)
1.4 GL Added comments to file
1.5 GL Changed it so that \n are now returns
1.6 GL Added a slew of stuff to handle kanji
1.7 GL Chganged format of kanji table
1.8 GL Removed bug with kanji frame lookup
1.9 GL added -s so user can specify the size of output font
1.91 GL Transtext also writes out an ID text file (id.dat)
1.92 GL fixed bug with output kanji table being too short
/*----------------------------------------------------------------------
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
using namespace std;
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
static void usage(void);
static char * cycleCommands(char *String,int Num);
/*----------------------------------------------------------------------
Vars
---- */
static const float version=1.92f;
static GString fileWithTranslations;
static GString headerFile;
static GString outDir;
static GString g_japKanjiFile;
static GString g_japLbmDir;
static GString g_englishLbmsDir;
static GString g_japLbmListFile;
static int g_fontSize=0;
/*----------------------------------------------------------------------
Data
---- */
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int main(int argc, char ** argv)
{
cerr<<"GRLiddon() TRANSTEXT text translation stuphh "<<version<<endl;
cerr<<"Copyright (c) 1999 G R Liddon. All rights reserved"<<endl<<endl;
if (argc==1)
usage();
else
{
CommandLine(argc,argv,cycleCommands);
if (g_englishLbmsDir)
{
KanjiClass::writeEnglishFontLbms(g_englishLbmsDir,KanjiClass::KanjiFontSize(g_fontSize));
}
if (fileWithTranslations)
{
AllTextDatabases myDatabases;
myDatabases.readTranslationFile(fileWithTranslations);
if (outDir)
myDatabases.write(outDir);
if (headerFile)
myDatabases.writeHeaderFile(headerFile);
/* Do some kanji jiggery pokery */
if (g_japKanjiFile || g_japLbmDir || g_japLbmListFile)
{
TextDatabase * jDataBase;
int numOfStrings;
KanjiClass kClass;
jDataBase=myDatabases.getTextDataBase(JAPANESE);
numOfStrings=jDataBase->getNumOfStrings();
for (int f=0;f<numOfStrings;f++)
kClass.addStr((u8 const*)jDataBase->getText(f));
if (g_japLbmDir)
{
if (g_fontSize >=0 && g_fontSize < 3)
kClass.saveKanjiLbms(g_japLbmDir,KanjiClass::KanjiFontSize(g_fontSize));
else
GObject::Error(ERR_FATAL,"illegal font size parameter");
}
if (g_japKanjiFile)
kClass.saveKanjiTable(g_japKanjiFile);
if (g_japLbmListFile && g_japLbmDir)
kClass.saveKanjiLbmNames(g_japLbmDir,g_japLbmListFile);
cout<<"text uses "<<kClass.howManyKanjiChars()<<endl;
}
}
else
GObject::Error(ERR_FATAL,"you must define a translation file");
}
return(0);
}
/*----------------------------------------------------------------------
Function: void Usage(void)
Notes: Usage of the util
---------------------------------------------------------------------- */
void usage(void)
{
cout<<"Usage: TRANSTEXT <in file> [ switches.. ]\n";
cout<<"Switches:\n"<<endl;
cout<<"-o:<dir> Dir to save translation strings to"<<endl;
cout<<"-e:<dir> Dir write ascii images to"<<endl;
cout<<"-h:<file> File to save lang enums to"<<endl;
cout<<endl;
cout<<"-d:<dir> Dir to save kanji lbms to"<<endl;
cout<<"-j:<file> File to save kanji table to"<<endl;
cout<<"-p:<file> File to save list of saved lbms to"<<endl;
cout<<endl;
cout<<"-s:<0|1|2> Set the size of the output font"<<endl;
cout<<endl;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
---------------------------------------------------------------------- */
GString getFileString(char const * Switch)
{
pcre * MyPattern;
int Matches;
const int NumOfOffsets=20;
int Offsets[NumOfOffsets];
char const * ErrTxt;
int ErrNum;
char SwitchText[100];
MyPattern=pcre_compile("^-.:(.*)",0,&ErrTxt,&ErrNum,NULL);
Matches=pcre_exec(MyPattern,NULL,Switch,strlen(Switch),0,Offsets,NumOfOffsets);
if (Matches != 2)
GObject::Error(ERR_FATAL,"Ill formatted switch %s",Switch);
memcpy(SwitchText,&Switch[Offsets[2]],Offsets[3]-Offsets[2]);
SwitchText[Offsets[3]-Offsets[2]]=0;
return(GString(SwitchText));
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
---------------------------------------------------------------------- */
bool getPlusMinus(char const * Switch)
{
pcre * MyPattern;
int Matches;
const int NumOfOffsets=20;
int Offsets[NumOfOffsets];
char const * ErrTxt;
int ErrNum;
MyPattern=pcre_compile("^-.([+|-])",0,&ErrTxt,&ErrNum,NULL);
Matches=pcre_exec(MyPattern,NULL,Switch,strlen(Switch),0,Offsets,NumOfOffsets);
if (Matches != 2)
GObject::Error(ERR_FATAL,"Ill formatted switch %s",Switch);
return(Switch[Offsets[2]]=='+');
}
/*----------------------------------------------------------------------
Function: char *CycleCommands(char *String,int Num)
Purpose: Callback to cycle through command line items
Params: String = Text of item
Num = Item number
---------------------------------------------------------------------- */
char * cycleCommands(char * cmdString,int num)
{
if (cmdString[0]=='-' || cmdString[0]=='/')
{
switch (cmdString[1])
{
case 'e':
g_englishLbmsDir=getFileString(cmdString);
break;
case 'h':
headerFile=getFileString(cmdString);
break;
case 'o':
outDir=getFileString(cmdString);
break;
case 'j':
g_japKanjiFile=getFileString(cmdString);
break;
case 'd':
g_japLbmDir=getFileString(cmdString);
break;
case 'p':
g_japLbmListFile=getFileString(cmdString);
break;
case 's':
g_fontSize=atoi(getFileString(cmdString));
break;
default:
GObject::Error(ERR_FATAL,"unknown switch %s",cmdString);
break;
}
}
else
{
if (fileWithTranslations)
GObject::Error(ERR_FATAL,"translation file already defined as %s",(char const *)fileWithTranslations);
else
fileWithTranslations=cmdString;
}
return(cmdString);
}
/*===========================================================================
end */

336
Utils/transtext/script.cpp Normal file
View file

@ -0,0 +1,336 @@
/*=========================================================================
FILENAME.CPP
Author: Gary Liddon @
Created:
Project:
Purpose:
Copyright (c) 1998 G R Liddon
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
#include "script.h"
/* Std Lib
------- */
/* Glib
---- */
/* Local
----- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
using namespace std;
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
const int DEFAULT_LINE_LENGTH=8192;
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
/*----------------------------------------------------------------------
Data
---- */
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
ScriptFile::ScriptFile(void)
{
m_isOpen=false;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
ScriptFile::~ScriptFile(void)
{
close();
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void ScriptFile::close(void)
{
if (m_isOpen)
m_inStream.close();
m_isOpen=false;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void ScriptFile::open(char const * fileName)
{
if (m_isOpen)
close();
m_inStream.open(fileName,ios::binary|ios::in);
if (m_inStream)
{
m_fileName=fileName;
}
else
GObject::Error(ERR_FATAL,"unable to open script file %s",fileName);
m_isOpen=true;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void ScriptFile::scriptError(void)
{
GObject::Error(ERR_FATAL,"Ill formatted script file %s, line %d",(char const *)m_fileName,m_lineCount);
}
/*----------------------------------------------------------------------
Function: ak
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void ScriptFile::checkIsOpen(void)
{
if (!m_isOpen)
GObject::Error(ERR_FATAL,"file operation needed by ScriptFile but no file is open");
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
bool ScriptFile::getNextNonBlankLine(char * line,int lineLen)
{
checkIsOpen();
do
{
if (m_inStream.eof())
return(false);
m_inStream.getline(line,lineLen);
int lineLength;
lineLength=strlen(line);
for (int f=0;f<lineLength;f++)
{
if (line[f] == ';')
line[f]=0;
}
if (strlen(line))
line[strlen(line)-1]=0;
m_lineCount++;
// stripTrailingSpace(line);
}
while (!strlen(line));
return(true);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
bool ScriptFile::nextLineIsCommand(void)
{
checkIsOpen();
bool retVal;
streampos thisPos;
const int lineLength=DEFAULT_LINE_LENGTH;
char line[lineLength];
int oldLineCount;
oldLineCount=m_lineCount;
retVal=false;
thisPos=m_inStream.tellg();
if (getNextNonBlankLine(line,lineLength))
{
stripTrailingSpace(line);
retVal=isCommand(line);
}
m_inStream.seekg(thisPos);
m_lineCount=oldLineCount;
return(retVal);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
GString ScriptFile::peekNextCommand(void)
{
checkIsOpen();
GString retStr;
if (nextLineIsCommand())
{
const int lineLength=DEFAULT_LINE_LENGTH;
char line[lineLength];
int oldLineCount;
streampos thisPos;
oldLineCount=m_lineCount;
thisPos=m_inStream.tellg();
getNextNonBlankLine(line,lineLength);
stripTrailingSpace(line);
retStr=getCommandString(line);
m_inStream.seekg(thisPos);
m_lineCount=oldLineCount;
}
return(retStr);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void ScriptFile::stripTrailingSpace(char * line)
{
if (strlen(line))
{
bool done=false;
for (int f=strlen(line)-1;f<=0 && !done ;f--)
{
if ((!isspace(line[f])) )
done=true;
else
line[f]=0;
}
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
GString ScriptFile::getCommandString(char * com)
{
char * newStr;
newStr=strdup(com);
newStr[strlen(newStr)-1]=0;
GString retStr(&newStr[1]);
free(newStr);
return(retStr);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
bool ScriptFile::isCommand(char * line)
{
return ((line[0]=='[') && (line[strlen(line)-1]==']'));
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
GString ScriptFile::getNextLine(void)
{
const int lineLength=DEFAULT_LINE_LENGTH;
char line[lineLength];
getNextNonBlankLine(line,lineLength);
return(line);
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
bool ScriptFile::eof(void)
{
checkIsOpen();
return(m_inStream.eof());
}
/*===========================================================================
end */

95
Utils/transtext/script.h Normal file
View file

@ -0,0 +1,95 @@
/*=========================================================================
FILENAME.CPP
Author: Gary Liddon @
Created:
Project:
Purpose:
Copyright (c) 1998 G R Liddon
===========================================================================*/
#ifndef __SCRIPT_H__
#define __SCRIPT_H__
/*----------------------------------------------------------------------
Includes
-------- */
/* Std Lib
------- */
#include <fstream>
/* Glib
---- */
#include <gstring.hpp>
/* Local
----- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
class ScriptFile
{
private:
std::ifstream m_inStream;
bool m_isOpen;
GString m_fileName;
int m_lineCount;
void scriptError(void);
bool getNextNonBlankLine(char * Line,int LineLen);
void stripTrailingSpace(char * Line);
GString getCommandString(char * Com);
bool isCommand(char * Line);
void checkIsOpen(void);
protected:
bool eof(void);
GString peekNextCommand(void);
bool nextLineIsCommand(void);
GString getNextLine(void);
void open(char const * fileName);
void close(void);
public:
ScriptFile(void);
~ScriptFile(void);
};
/*----------------------------------------------------------------------
Globals
------- */
/* Vars
---- */
/* Data
---- */
/* Functions
--------- */
/*---------------------------------------------------------------------- */
#endif /* __SCRIPT_H__ */
/*===========================================================================
end */

View file

@ -0,0 +1,108 @@
# Microsoft Developer Studio Project File - Name="transtext" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=transtext - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "transtext.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "transtext.mak" CFG="transtext - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "transtext - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "transtext - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""$/TP2psx/utils/transtext", JNXBAAAA"
# PROP Scc_LocalPath "."
CPP=xicl6.exe
RSC=rc.exe
!IF "$(CFG)" == "transtext - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\glibdev\glib\include" /I "..\..\glibdev\glib\include\pc" /I "..\tplib" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x809 /d "NDEBUG"
# ADD RSC /l 0x809 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=xilink6.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib win32lib.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\glibdev\glib\lib\win32lib\release" /libpath:"..\tplib\release"
!ELSEIF "$(CFG)" == "transtext - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\..\glibdev\glib\include" /I "..\..\glibdev\glib\include\pc" /I "..\tplib" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c
# ADD BASE RSC /l 0x809 /d "_DEBUG"
# ADD RSC /l 0x809 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=xilink6.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib win32lib.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\glibdev\glib\lib\win32lib\debug" /libpath:"..\tplib\debug"
!ENDIF
# Begin Target
# Name "transtext - Win32 Release"
# Name "transtext - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\kanjiclass.cpp
# End Source File
# Begin Source File
SOURCE=.\main.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\kanjiclass.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

View file

@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "transtext"=.\transtext.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################