Fixed newline issue (mostly for my own sanity)

This commit is contained in:
n-a-c-h
2003-10-05 08:34:06 +00:00
parent ec5ccb6655
commit 98347b677f

View File

@@ -1,352 +1,353 @@
/* /*
Copyright (C) 2003 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) Copyright (C) 2003 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com )
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version 2 of the License, or (at your option) any later
version. version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
//C++ style code in C
#define bool unsigned char
#define true 1 //C++ style code in C
#define false 0 #define bool unsigned char
#define true 1
#define Lo 0x7FC0 #define false 0
#define Hi 0xFFC0
#define EHi 0x40FFC0
#define Lo 0x7FC0
#define MB_bytes 0x100000 #define Hi 0xFFC0
#define Mbit_bytes 0x20000 #define EHi 0x40FFC0
#define MB_bytes 0x100000
//I want to port over the more complicated #define Mbit_bytes 0x20000
//functions from init.asm, or replace with
//better versions from NSRT. -Nach
//I want to port over the more complicated
//functions from init.asm, or replace with
//init.asm goodness //better versions from NSRT. -Nach
extern unsigned int NumofBanks;
extern unsigned int NumofBytes; //init.asm goodness
extern unsigned int *romdata; extern unsigned int NumofBanks;
extern unsigned char romtype; extern unsigned int NumofBytes;
extern unsigned char Interleaved; extern unsigned int *romdata;
extern unsigned char romtype;
extern unsigned char Interleaved;
unsigned int maxromspace; unsigned int maxromspace;
unsigned int curromspace; unsigned int curromspace;
unsigned int infoloc; unsigned int infoloc;
//Deinterleave functions //Deinterleave functions
bool validChecksum(unsigned char *ROM, int BankLoc) bool validChecksum(unsigned char *ROM, int BankLoc)
{ {
if (ROM[BankLoc + 28] + (ROM[BankLoc + 29] << 8) + if (ROM[BankLoc + 28] + (ROM[BankLoc + 29] << 8) +
ROM[BankLoc + 30] + (ROM[BankLoc + 31] << 8) == 0xFFFF) ROM[BankLoc + 30] + (ROM[BankLoc + 31] << 8) == 0xFFFF)
{ {
return(true); return(true);
} }
return(false); return(false);
} }
bool EHiHeader(unsigned char *ROM, int BankLoc) bool EHiHeader(unsigned char *ROM, int BankLoc)
{ {
if (validChecksum(ROM, BankLoc) && ROM[BankLoc+21] == 53) if (validChecksum(ROM, BankLoc) && ROM[BankLoc+21] == 53)
{ {
return(true); return(true);
} }
return(false); return(false);
} }
void swapBlocks(char *blocks) void swapBlocks(char *blocks)
{ {
unsigned int i,j,k; unsigned int i,j,k;
for (i = 0; i < NumofBanks; i++) for (i = 0; i < NumofBanks; i++)
{ {
for (j = 0; j < NumofBanks; j++) for (j = 0; j < NumofBanks; j++)
{ {
if (blocks[j] == (char)i) if (blocks[j] == (char)i)
{ {
char b; char b;
unsigned int temp, unsigned int temp,
*loc1 = romdata + blocks[i]*0x2000, *loc1 = romdata + blocks[i]*0x2000,
*loc2 = romdata + blocks[j]*0x2000; *loc2 = romdata + blocks[j]*0x2000;
for (k = 0; k < 0x2000; k++) for (k = 0; k < 0x2000; k++)
{ {
temp = loc1[k]; temp = loc1[k];
loc1[k] = loc2[k]; loc1[k] = loc2[k];
loc2[k] = temp; loc2[k] = temp;
} }
b = blocks[j]; b = blocks[j];
blocks[j] = blocks[i]; blocks[j] = blocks[i];
blocks[i] = b; blocks[i] = b;
break; break;
} }
} }
} }
} }
void deintlv1() void deintlv1()
{ {
char blocks[256]; char blocks[256];
int i, numblocks = NumofBanks/2; int i, numblocks = NumofBanks/2;
for (i = 0; i < numblocks; i++) for (i = 0; i < numblocks; i++)
{ {
blocks[i * 2] = i + numblocks; blocks[i * 2] = i + numblocks;
blocks[i * 2 + 1] = i; blocks[i * 2 + 1] = i;
} }
swapBlocks(blocks); swapBlocks(blocks);
} }
void CheckIntl1(unsigned char *ROM) void CheckIntl1(unsigned char *ROM)
{ {
unsigned int ROMmidPoint = NumofBytes / 2; unsigned int ROMmidPoint = NumofBytes / 2;
if (validChecksum(ROM, ROMmidPoint + Lo) && if (validChecksum(ROM, ROMmidPoint + Lo) &&
!validChecksum(ROM, Lo) && !validChecksum(ROM, Lo) &&
ROM[ROMmidPoint+Lo+25] < 14) //Country Code ROM[ROMmidPoint+Lo+25] < 14) //Country Code
{ {
deintlv1(); deintlv1();
Interleaved = true; Interleaved = true;
} }
else if (validChecksum(ROM, Lo) && !validChecksum(ROM, Hi) && else if (validChecksum(ROM, Lo) && !validChecksum(ROM, Hi) &&
ROM[Lo+25] < 14 && //Country code ROM[Lo+25] < 14 && //Country code
//Rom make up //Rom make up
(ROM[Lo+21] == 33 || ROM[Lo+21] == 49 || (ROM[Lo+21] == 33 || ROM[Lo+21] == 49 ||
ROM[Lo+21] == 53 || ROM[Lo+21] == 58)) ROM[Lo+21] == 53 || ROM[Lo+21] == 58))
{ {
if (ROM[Lo+20] == 32 ||//Check that Header name did not overflow if (ROM[Lo+20] == 32 ||//Check that Header name did not overflow
!(ROM[Lo+21] == ROM[Lo+20] || ROM[Lo+21] == ROM[Lo+19] || !(ROM[Lo+21] == ROM[Lo+20] || ROM[Lo+21] == ROM[Lo+19] ||
ROM[Lo+21] == ROM[Lo+18] || ROM[Lo+21] == ROM[Lo+17])) ROM[Lo+21] == ROM[Lo+18] || ROM[Lo+21] == ROM[Lo+17]))
{ {
deintlv1(); deintlv1();
Interleaved = true; Interleaved = true;
} }
} }
} }
void CheckIntlEHi(unsigned char *ROM) void CheckIntlEHi(unsigned char *ROM)
{ {
if (EHiHeader(ROM, Lo)) if (EHiHeader(ROM, Lo))
{ {
unsigned int temp, i, oldNumBanks = NumofBanks, unsigned int temp, i, oldNumBanks = NumofBanks,
*loc1 = romdata, *loc1 = romdata,
*loc2 = romdata + ((NumofBytes - 0x400000)/4); *loc2 = romdata + ((NumofBytes - 0x400000)/4);
//Swap 4MB ROM with the other one //Swap 4MB ROM with the other one
for (i = 0; i < 0x100000; i++) for (i = 0; i < 0x100000; i++)
{ {
temp = loc1[i]; temp = loc1[i];
loc1[i] = loc2[i]; loc1[i] = loc2[i];
loc2[i] = temp; loc2[i] = temp;
} }
//Deinterleave the 4MB ROM first //Deinterleave the 4MB ROM first
NumofBanks = 128; NumofBanks = 128;
deintlv1(); deintlv1();
//Now the other one //Now the other one
NumofBanks = oldNumBanks - 128; NumofBanks = oldNumBanks - 128;
romdata += 0x100000; //Ofset pointer romdata += 0x100000; //Ofset pointer
deintlv1(); deintlv1();
//Now fix the data and we're done //Now fix the data and we're done
NumofBanks = oldNumBanks; NumofBanks = oldNumBanks;
romdata -= 0x100000; romdata -= 0x100000;
Interleaved = true; Interleaved = true;
} }
} }
//ROM loading functions, which some strangly enough were in guiload.inc //ROM loading functions, which some strangly enough were in guiload.inc
bool AllASCII(unsigned char *b, int size) bool AllASCII(unsigned char *b, int size)
{ {
int i; int i;
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
if (b[i] < 32 || b[i] > 126) if (b[i] < 32 || b[i] > 126)
{ {
return(false); return(false);
} }
} }
return(true); return(true);
} }
int InfoScore(unsigned char *Buffer) int InfoScore(unsigned char *Buffer)
{ {
int score = 0; int score = 0;
if (validChecksum(Buffer, 0)) { score += 4; } if (validChecksum(Buffer, 0)) { score += 4; }
if (Buffer[26] == 0x33) { score += 2; } if (Buffer[26] == 0x33) { score += 2; }
if (!(Buffer[61] & 0x80)) { score -= 4; } if (!(Buffer[61] & 0x80)) { score -= 4; }
if ((1 << (Buffer[23] - 7)) > 48) { score -= 1; } if ((1 << (Buffer[23] - 7)) > 48) { score -= 1; }
if (Buffer[25] < 14) { score += 1; } if (Buffer[25] < 14) { score += 1; }
if (!AllASCII(Buffer, 20)) { score -= 1; } if (!AllASCII(Buffer, 20)) { score -= 1; }
return(score); return(score);
} }
extern unsigned char ForceHiLoROM; extern unsigned char ForceHiLoROM;
extern unsigned char forceromtype; extern unsigned char forceromtype;
void BankCheck() void BankCheck()
{ {
unsigned char *ROM = (unsigned char *)romdata; unsigned char *ROM = (unsigned char *)romdata;
infoloc = 0; infoloc = 0;
Interleaved = false; Interleaved = false;
if (NumofBytes >= 0x500000) if (NumofBytes >= 0x500000)
{ {
//Deinterleave if neccesary //Deinterleave if neccesary
CheckIntlEHi(ROM); CheckIntlEHi(ROM);
if (EHiHeader(ROM, EHi)) if (EHiHeader(ROM, EHi))
{ {
romtype = 2; romtype = 2;
infoloc = EHi; infoloc = EHi;
} }
} }
if (!infoloc) if (!infoloc)
{ {
static bool CommandLineForce2 = false; static bool CommandLineForce2 = false;
int loscore, hiscore; int loscore, hiscore;
//Deinterleave if neccesary //Deinterleave if neccesary
CheckIntl1(ROM); CheckIntl1(ROM);
loscore = InfoScore(ROM+Lo); loscore = InfoScore(ROM+Lo);
hiscore = InfoScore(ROM+Hi); hiscore = InfoScore(ROM+Hi);
switch(ROM[Lo + 21]) switch(ROM[Lo + 21])
{ {
case 32: case 35: case 48: case 50: case 32: case 35: case 48: case 50:
loscore += 2; loscore += 2;
case 128: case 156: case 176: case 188: case 252: //BS case 128: case 156: case 176: case 188: case 252: //BS
loscore += 1; loscore += 1;
break; break;
} }
switch(ROM[Hi + 21]) switch(ROM[Hi + 21])
{ {
case 33: case 49: case 53: case 58: case 33: case 49: case 53: case 58:
hiscore += 2; hiscore += 2;
case 128: case 156: case 176: case 188: case 252: //BS case 128: case 156: case 176: case 188: case 252: //BS
hiscore += 1; hiscore += 1;
break; break;
} }
/* /*
Force code. Force code.
ForceHiLoROM is from the GUI. ForceHiLoROM is from the GUI.
forceromtype is from Command line, we have a static var forceromtype is from Command line, we have a static var
to prevent forcing a secong game loaded from the GUI when to prevent forcing a secong game loaded from the GUI when
the first was loaded from the command line with forcing. the first was loaded from the command line with forcing.
*/ */
if (ForceHiLoROM == 1 || if (ForceHiLoROM == 1 ||
(forceromtype == 1 && !CommandLineForce2)) (forceromtype == 1 && !CommandLineForce2))
{ {
CommandLineForce2 = true; CommandLineForce2 = true;
loscore += 50; loscore += 50;
} }
else if (ForceHiLoROM == 2 || else if (ForceHiLoROM == 2 ||
(forceromtype == 2 && !CommandLineForce2)) (forceromtype == 2 && !CommandLineForce2))
{ {
CommandLineForce2 = true; CommandLineForce2 = true;
hiscore += 50; hiscore += 50;
} }
if (hiscore > loscore) if (hiscore > loscore)
{ {
romtype = 2; romtype = 2;
infoloc = Hi; infoloc = Hi;
} }
else else
{ {
romtype = 1; romtype = 1;
infoloc = Lo; infoloc = Lo;
} }
} }
} }
//Checksum functions //Checksum functions
unsigned short sum(unsigned char *array, unsigned int size) unsigned short sum(unsigned char *array, unsigned int size)
{ {
unsigned short theSum = 0; unsigned short theSum = 0;
unsigned int i; unsigned int i;
//Prevent crashing by reading too far (needed for messed up ROMs) //Prevent crashing by reading too far (needed for messed up ROMs)
if (array + size > (unsigned char *)romdata + maxromspace) if (array + size > (unsigned char *)romdata + maxromspace)
{ {
return(0xFFFF); return(0xFFFF);
} }
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
{ {
theSum += array[i]; theSum += array[i];
} }
return(theSum); return(theSum);
} }
extern unsigned char SPC7110Enable; extern unsigned char SPC7110Enable;
extern unsigned char BSEnable; extern unsigned char BSEnable;
extern unsigned short Checksumvalue; extern unsigned short Checksumvalue;
void CalcChecksum() void CalcChecksum()
{ {
unsigned char *ROM = (unsigned char *)romdata; unsigned char *ROM = (unsigned char *)romdata;
if (SPC7110Enable) if (SPC7110Enable)
{ {
Checksumvalue = sum(ROM, NumofBytes); Checksumvalue = sum(ROM, NumofBytes);
if (NumofBanks == 96) if (NumofBanks == 96)
{ {
Checksumvalue += Checksumvalue; //Fix for 24Mb SPC7110 ROMs Checksumvalue += Checksumvalue; //Fix for 24Mb SPC7110 ROMs
} }
} }
else else
{ {
Checksumvalue = sum(ROM, curromspace); Checksumvalue = sum(ROM, curromspace);
if (NumofBanks > 128 && maxromspace == 6*MB_bytes) if (NumofBanks > 128 && maxromspace == 6*MB_bytes)
{ {
Checksumvalue += sum(ROM+4*MB_bytes, 2*MB_bytes); Checksumvalue += sum(ROM+4*MB_bytes, 2*MB_bytes);
} }
if (BSEnable) if (BSEnable)
{ {
Checksumvalue -= sum(&ROM[infoloc - 16], 48); //Fix for BS Dumps Checksumvalue -= sum(&ROM[infoloc - 16], 48); //Fix for BS Dumps
} }
} }
} }
//Misc functions //Misc functions
void MirrorROM() void MirrorROM()
{ {
unsigned char *ROM = (unsigned char *)romdata; unsigned char *ROM = (unsigned char *)romdata;
unsigned int size, StartMirror = 0, ROMSize = curromspace; unsigned int size, StartMirror = 0, ROMSize = curromspace;
//This will mirror up non power of two ROMs to powers of two //This will mirror up non power of two ROMs to powers of two
for (size = 1; size <= 64; size +=size) for (size = 1; size <= 64; size +=size)
{ {
unsigned int fullSize = size * Mbit_bytes, unsigned int fullSize = size * Mbit_bytes,
halfSize = fullSize >> 1; halfSize = fullSize >> 1;
if ((ROMSize > halfSize) && (ROMSize < fullSize)) if ((ROMSize > halfSize) && (ROMSize < fullSize))
{ {
for (StartMirror = halfSize; for (StartMirror = halfSize;
ROMSize < fullSize && ROMSize < maxromspace;) ROMSize < fullSize && ROMSize < maxromspace;)
{ {
ROM[ROMSize++] = ROM[StartMirror++]; ROM[ROMSize++] = ROM[StartMirror++];
} }
curromspace = ROMSize; curromspace = ROMSize;
break; break;
} }
} }
//This will mirror (now) full sized ROMs through the ROM buffer //This will mirror (now) full sized ROMs through the ROM buffer
for (StartMirror = 0; ROMSize < maxromspace;) for (StartMirror = 0; ROMSize < maxromspace;)
{ {
ROM[ROMSize++] = ROM[StartMirror++]; ROM[ROMSize++] = ROM[StartMirror++];
} }
} }