› Foros › PC › Software libre
unsigned char *rom1;
unsigned int length;
typedef union {
short W; /* Acceso a Word */
struct /* Acceso a Byte... */
{
#ifdef LOW_ENDIAN
unsigned char l,h; /* ...en arquitectura low-endian */
#else
unsigned char h,l; /* ...en arquitectura high-endian */
#endif
} B;
} word;
typedef struct {
unsigned char entry_point[4],
logo[47],
titulo[16],
manuf[4],
gbcf[1];
word nlicence[2];
unsigned char sgbf[1],
cart_type[1],
rom_size[1],
ram_size[1],
destination[1],
olicence[1],
maskrom_nver[1],
header_chk[1];
word global_chk[2];
}Header;
Header *rom;
word check_sum;
//-----------------------------------------------------------------------------------------------------------------
// 0134-0143 - Title 16 Bytes titulo
if (argc==2) printf("\nTitle : ");
if (argc!=2) printf("\"");
if ((rom->gbcf[0]==0x80)||(rom->gbcf[0]==0xC0)) a=15;
if ((rom->olicence[0]==0x33)) a=11;
for (i=0;i<a;i++)
{
printf("%c",rom->titulo[i]);
}
if (argc!=2) printf("\" ");
/**********************************************************************************/
// 013F-0142 - Manufacturer Code 4 Bytes manuf
if (argc==2) printf("\nManufacturer Code : ");
i=0;
for (i=0;i<4;i++)
{
printf("%c",rom->manuf[i]);
}
if (argc!=2) printf(" ");
/**********************************************************************************/
// 0143 - CGB Flag 1 Byte gbcf
if (rom->gbcf[0] == 0x80) {if (argc==2)
printf("\nCGB Flag : %02X : Game supports CGB functions, but works on old gameboys also.",rom->gbcf[0]);
}else printf("%02X ",rom->gbcf[0]);
if (rom->gbcf[0] == 0xC0) {if (argc==2)
printf("\nCGB Flag : %02X : Game works on CGB only (physically the same as 80h).",rom->gbcf[0]);
}else printf("%02X ",rom->gbcf[0]);
salida simple
./gb_fix wl3.gbc n
00C35001 ALL "WARIOLAND3" AW8A C0 01 00 1B 06 03 01 33 00 89
-----------------------------^ aqui sale bien
salida extendida
./gb_fix wl3.gbc
Archivo : wl3.gbc
Entry Point : 00C35001 : NOP JP 0150
Nintendo logo check: ALL : SGB/GBC/GB
Title : WARIOLAND3
Manufacturer Code : AW8AC0 <--siempre imprime el byte de mas, CGB Flag...tendria salir(4char) y sale (4char1hex)
CGB Flag : C0 : Game works on CGB only (physically the same as 80h).
New Licensee Code : 01
SGB Flag : 00 : No SGB functions (Normal Gameboy or CGB only game)
Cartridge Type : 1B : MBC5+RAM+BATTERY
ROM Size : 06 : 2 MByte (128 banks) - only 125 banks used by MBC1
RAM Size : 03 : 32 KBytes (4 banks de 8 KBytes cada uno)
Destination Code : 01 : Non-Japanese
Old Licensee Code : 33 : New License Code used. Required for SGB.
Mask ROM Ver.Num. : 00 : Specifies the version number of the game. That is usually 00.
Header Checksum : 89 : Checksum is correct.
Global Checksum : 7C15 : Error (The Gameboy doesn't verify this checksum.)
/*
* gbhead.c
* Game Boy header
* Copyright 2015 lok <lok@lok-net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
#include <stdio.h>
#include <stdlib.h>
/*----------------------------------------------------------------------------*/
#define EXIT(text) { printf(text); exit(EXIT_FAILURE); }
//#define EXIT(text) printf(text)
unsigned char *rom1;
unsigned int length;
typedef union {
short W; /* Acceso a Word */
struct /* Acceso a Byte... */
{
#ifdef LOW_ENDIAN
unsigned char l,h; /* ...en arquitectura low-endian */
#else
unsigned char h,l; /* ...en arquitectura high-endian */
#endif
} B;
} word;
typedef struct {
unsigned char entry_point[4],
logo[47],
titulo[16],
manuf[4],
gbcf[1];
word nlicence[2];
unsigned char sgbf[1],
cart_type[1],
rom_size[1],
ram_size[1],
destination[1],
olicence[1],
maskrom_nver[1],
header_chk[1];
word global_chk[2];
}Header;
Header *rom;
word check_sum;
int cmp_str( char *p, char s[])
{
int dif,i=0;
if (sizeof(p)<sizeof(s)) return(-1);
if (sizeof(p)>sizeof(s)) return(1);
while((p[i]!='\0')||(s[i]!='\0'))
{
dif=(p[i]-s[i]);
if(dif!=0)
break;
i++;
}
if(dif>0)
return(1);
else
{
if(dif<0)
return(-1);
else
return(0);
}
}
/*----------------------------------------------------------------------------*/
void logo_chk(Header *rom,int num){
unsigned char logo_inf[]={0xCE,0xED,0x66,0x66,0xCC,0x0D,0x00,0x0B,0x03,0x73,0x00,0x83,0x00,0x0C,0x00,0x0D,
0x00,0x08,0x11,0x1F,0x88,0x89,0x00,0x0E,0xDC,0xCC,0x6E,0xE6,0xDD,0xDD,0xD9,0x99,
0xBB,0xBB,0x67,0x63,0x6E,0x0E,0xEC,0xCC,0xDD,0xDC,0x99,0x9F,0xBB,0xB9,0x33,0x3E};
int i;
for (i=0;i<48;i++)
{
if (rom->logo[i] != logo_inf[i]) break;
}
if (num!=0)
{
if (i == 47) printf("ALL : SGB/GBC/GB");
if ((i < 47)&&(i>=24)) printf("CGB : CGB/GB");
if (i < 24) printf("GB : GB");
}else
{
if (i == 47) printf("ALL ");
if ((i < 47)&&(i>=24)) printf("CGB ");
if (i < 24) printf("GB ");
}
/*A CGB verifies only the first 18h bytes of the bitmap
but others (for example a pocket gameboy)
verify all 30h bytes. */
}
void cargar(char *archivo)
{
FILE *fp;
if ((fp = fopen(archivo, "r+b")) == NULL) EXIT("File open error\n");
fseek(fp, 0, SEEK_END);
length = ftell(fp);
if (length < 0x000200) EXIT("File too short\n");
if (length > 0x800000) EXIT("File too big\n");
if ((rom = calloc(1, sizeof(Header))) == NULL) EXIT("Memory error\n");
if ((rom1 = calloc(length, sizeof(char))) == NULL) EXIT("Memory error\n");
fseek(fp, 0, SEEK_SET);
if (fread(rom1, 1, length, fp) != length) EXIT("Backup error\n");
/* 0100-0103 - Entry Point 4 Bytes
After displaying the Nintendo Logo, the built-in boot procedure jumps to this
address (100h), which should then jump to the actual main program in the
cartridge. Usually this 4 byte area contains a NOP instruction, followed by a JP
0150h instruction. But not always: 00 C3 50 01 */
fseek(fp, 0x0100, SEEK_SET);
if (fread(rom->entry_point, 1, 4, fp) != 4) EXIT("entry_point error\n");
/* 0104-0133 - Nintendo Logo 47 Bytes
These bytes define the bitmap of the Nintendo logo that is displayed when the
gameboy gets turned on. The hexdump of this bitmap is:
CE ED 66 66 CC 0D 00 0B 03 73 00 83 00 0C 00 0D
00 08 11 1F 88 89 00 0E DC CC 6E E6 DD DD D9 99
BB BB 67 63 6E 0E EC CC DD DC 99 9F BB B9 33 3E
The gameboys boot procedure verifies the content of this bitmap (after it has
displayed it), and LOCKS ITSELF UP if these bytes are incorrect. A CGB verifies
only the first 18h bytes of the bitmap, but others (for example a pocket gameboy)
verify all 30h bytes. */
fseek(fp, 0x0104, SEEK_SET);
if (fread(rom->logo, 1, 47, fp) != 47) EXIT("logo error\n");
/* 0134-0143 - Title 16 Bytes
Title of the game in UPPER CASE ASCII. If it is less than 16 characters then the
remaining bytes are filled with 00's. When inventing the CGB, Nintendo has
reduced the length of this area to 15 characters, and some months later they had
the fantastic idea to reduce it to 11 characters only. The new meaning of the
ex-title bytes is described below. */
fseek(fp, 0x0134, SEEK_SET);
if (fread(rom->titulo, 1, 16, fp) != 16) EXIT("titulo error\n");
/* 013F-0142 - Manufacturer Code 4 Bytes
In older cartridges this area has been part of the Title (see above), in newer
cartridges this area contains an 4 character uppercase manufacturer code.
Purpose and Deeper Meaning unknown. */
fseek(fp, 0x013F, SEEK_SET);
if (fread(rom->manuf, 1, 4, fp) != 4) EXIT("manuf error\n");
/* 0143 - CGB Flag 1 Byte
In older cartridges this byte has been part of the Title (see above). In CGB
cartridges the upper bit is used to enable CGB functions. This is required,
otherwise the CGB switches itself into Non-CGB-Mode. Typical values are:
80h - Game supports CGB functions, but works on old gameboys also.
C0h - Game works on CGB only (physically the same as 80h).
Values with Bit 7 set, and either Bit 2 or 3 set, will switch the gameboy into a
special non-CGB-mode with uninitialized palettes. Purpose unknown, eventually
this has been supposed to be used to colorize monochrome games that include
fixed palette data at a special location in ROM. */
fseek(fp, 0x0143, SEEK_SET);
if (fread(rom->gbcf, 1, 1, fp) != 1) EXIT("gbcf error\n");
/* 0144-0145 - New Licensee Code 2 Bytes
Specifies a two character ASCII licensee code, indicating the company or
publisher of the game. These two bytes are used in newer games only (games that
have been released after the SGB has been invented). Older games are using the
header entry at 014B instead. */
fseek(fp, 0x0144, SEEK_SET);
if (fread(rom->nlicence, 1, 2, fp) != 2) EXIT("nlicence error\n");
/* 0146 - SGB Flag 1 Byte
Specifies whether the game supports SGB functions, common values are:
00h = No SGB functions (Normal Gameboy or CGB only game)
03h = Game supports SGB functions
The SGB disables its SGB functions if this byte is set to another value than 03h.*/
fseek(fp, 0x0146, SEEK_SET);
if (fread(rom->sgbf, 1, 1, fp) != 1) EXIT("sgbf error\n");
/* 0147 - Cartridge Type 1 Byte
Specifies which Memory Bank Controller (if any) is used in the cartridge, and if
further external hardware exists in the cartridge.
00h ROM ONLY
01h MBC1
02h MBC1+RAM
03h MBC1+RAM+BATTERY
05h MBC2
06h MBC2+BATTERY
08h ROM+RAM
09h ROM+RAM+BATTERY
0Bh MMM01
0Ch MMM01+RAM
0Dh MMM01+RAM+BATTERY
0Fh MBC3+TIMER+BATTERY
10h MBC3+TIMER+RAM+BATTERY
11h MBC3
12h MBC3+RAM
13h MBC3+RAM+BATTERY
15h MBC4
16h MBC4+RAM
17h MBC4+RAM+BATTERY
19h MBC5
1Ah MBC5+RAM
1Bh MBC5+RAM+BATTERY
1Ch MBC5+RUMBLE
1Dh MBC5+RUMBLE+RAM
1Eh MBC5+RUMBLE+RAM+BATTERY
FCh POKET CAMERA
FDh BANDAI TAMA5
FEh HuC3
FFh HuC1+RAM+BATTERY */
fseek(fp, 0x0147, SEEK_SET);
if (fread(rom->cart_type, 1, 1, fp) != 1) EXIT("cart_type error\n");
/* 0148 - ROM Size 1 Byte
Specifies the ROM Size of the cartridge. Typically calculated as "32KB shl N".
00h - 32KByte (no ROM banking)
01h - 64KByte (4 banks)
02h - 128KByte (8 banks)
03h - 256KByte (16 banks)
04h - 512KByte (32 banks)
05h - 1MByte (64 banks) - only 63 banks used by MBC1
06h - 2MByte (128 banks) - only 125 banks used by MBC1
07h - 4MByte (256 banks)
52h - 1.1MByte (72 banks)
53h - 1.2MByte (80 banks)
54h - 1.5MByte (96 banks) */
fseek(fp, 0x0148, SEEK_SET);
if (fread(rom->rom_size, 1, 1, fp) != 1) EXIT("rom_size error\n");
/* 0149 - RAM Size 1 Byte
Specifies the size of the external RAM in the cartridge (if any).
00h - None
01h - 2 KBytes
02h - 8 KBytes
03h - 32 KBytes (4 banks de 8 KBytes cada uno)
When using a MBC2 chip 00h must be specified in this entry, even though the
MBC2 includes a built-in RAM of 512 x 4 bits. */
fseek(fp, 0x0149, SEEK_SET);
if (fread(rom->ram_size, 1, 1, fp) != 1) EXIT("ram_size error\n");
/* 014A - Destination Code 1 Byte
Specifies if this version of the game is supposed to be sold in japan, or anywhere
else. Only two values are defined.
00h - Japanese
01h - Non-Japanese */
fseek(fp, 0x014A, SEEK_SET);
if (fread(rom->destination, 1, 1, fp) != 1) EXIT("destination error\n");
/* 014B - Old Licensee Code 1 Byte
Specifies the games company/publisher code in range 00-FFh. A value of 33h
signalizes that the New License Code in header bytes 0144-0145 is used instead.
(Super GameBoy functions won't work if <> $33.) */
fseek(fp, 0x014B, SEEK_SET);
if (fread(rom->olicence, 1, 1, fp) != 1) EXIT("olicence error\n");
/* 014C - Mask ROM Version number 1 Byte
Specifies the version number of the game. That is usually 00h. */
fseek(fp, 0x014C, SEEK_SET);
if (fread(rom->maskrom_nver, 1, 1, fp) != 1) EXIT("maskrom_nvererror\n");
/* 014D - Header Checksum 1 Byte
Contains an 8 bit checksum across the cartridge header bytes 0134-014C. The
checksum is calculated as follows:
x=0:FOR i=0134h TO 014Ch:x=x-MEM[i]-1:NEXT
The lower 8 bits of the result must be the same than the value in this entry. The
GAME WON'T WORK if this checksum is incorrect. */
fseek(fp, 0x014D, SEEK_SET);
if (fread(rom->header_chk, 1, 1, fp) != 1) EXIT("header_chk error\n");
/* 014E-014F - Global Checksum 2 Bytes
Contains a 16 bit checksum (upper byte first) across the whole cartridge ROM.
Produced by adding all bytes of the cartridge (except for the two checksum
bytes). The Gameboy doesn't verify this checksum. */
fseek(fp, 0x014E, SEEK_SET);
if (fread(rom->global_chk, 1, 2, fp) != 2) EXIT("global_chk error\n");
if (fclose(fp) == EOF) EXIT("File close error\n");
}
int main(int argc, char **argv) {
unsigned char checksum0;
unsigned int i;
int a;
i=0;
if (argc == 2) i=1;//EXIT("Sintax: gb-fix romname\n");
if (argc == 3) i=1;//EXIT("Game Boy Header Sintax: gb-head romname [optional]\n");
if(i==0) {printf("Game Boy Header Sintax: %s romname [optional]\n",argv[0]);exit(EXIT_FAILURE);}
cargar(argv[1]);
if (argc==2) printf("\nArchivo : %s",argv[1]);
// 0100-0103 - Entry Point 4 Bytes entry_point
if (argc==2) printf("\nEntry Point : ");
for (i=0;i<4;i++)
{
printf("%02X",rom->entry_point[i]);
}
if ((rom->entry_point[0] == 0x00) && (rom->entry_point[1] == 0xC3))
{ if (argc==2)
{printf(" : NOP JP %02X%02X",rom->entry_point[3],rom->entry_point[2]);}
else printf(" ");}
// 0104-0133 - Nintendo Logo 47 Bytes logo
if (argc==2)
{ printf("\nNintendo logo check: ");
logo_chk(rom,1);
}else{
logo_chk(rom,0);
}
// 0134-0143 - Title 16 Bytes titulo
if (argc==2) printf("\nTitle : ");//%s",rom->titulo);
if (argc!=2) printf("\"");
if ((rom->gbcf[0]==0x80)||(rom->gbcf[0]==0xC0)) a=15;
if ((rom->olicence[0]==0x33)) a=11;
for (i=0;i<a;i++)
{
printf("%c",rom->titulo[i]);
}
if (argc!=2) printf("\" ");
// 013F-0142 - Manufacturer Code 4 Bytes manuf
if (argc==2) printf("\nManufacturer Code : ");
i=0;
for (i=0;i<4;i++)
{
printf("%c",rom->manuf[i]);
}
if (argc!=2) printf(" ");
// 0143 - CGB Flag 1 Byte gbcf
if (rom->gbcf[0] == 0x80) {if (argc==2)
printf("\nCGB Flag : %02X : Game supports CGB functions, but works on old gameboys also.",rom->gbcf[0]);}else printf("%02X ",rom->gbcf[0]);
if (rom->gbcf[0] == 0xC0) {if (argc==2)
printf("\nCGB Flag : %02X : Game works on CGB only (physically the same as 80h).",rom->gbcf[0]);}else printf("%02X ",rom->gbcf[0]);
// 0144-0145 - New Licensee Code 2 Bytes nlicence
// printf("\nNew Licensee Code : ");
// printf("%s",rom->nlicence);
if (argc==2) printf("\nNew Licensee Code : ");
printf("%c",rom->nlicence->B.h);
printf("%c",rom->nlicence->B.l);
if (argc!=2) printf(" ");
//for (i=0;i<2;i++)
//{
// printf("%u",rom->nlicence.B);
//}//*/
// 0146 - SGB Flag 1 Byte sgbf
if (argc==2)
{
if (rom->sgbf[0] == 0x00) printf("\nSGB Flag : %02X : No SGB functions (Normal Gameboy or CGB only game)",rom->sgbf[0]);
if (rom->sgbf[0] == 0x03) printf("\nSGB Flag : %02X : Game supports SGB functions",rom->sgbf[0]);
if ((rom->sgbf[0] != 0x00) && (rom->sgbf[0] != 0x03)) printf("\nSGB Flag : %02X : unknown",rom->sgbf[0]);
}else printf("%02X ",rom->sgbf[0]);
// 0147 - Cartridge Type 1 Byte cart_type
if (argc!=2) printf("%02X ",rom->cart_type[0]);
else
{
printf("\nCartridge Type : %02X",rom->cart_type[0]);
switch ((int)rom->cart_type[0])
{
case 0x00:
printf(" : ROM ONLY");
break;
case 0x01:
printf(" : MBC1");
break;
case 0x02:
printf(" : MBC1+RAM");
break;
case 0x03:
printf(" : MBC1+RAM+BATTERY");
break;
case 0x05:
printf(" : MBC2");
break;
case 0x06:
printf(" : MBC2+BATTERY");
break;
case 0x08:
printf(" : ROM+RAM");
break;
case 0x09:
printf(" : ROM+RAM+BATTERY");
break;
case 0x0B:
printf(" : MMM01");
break;
case 0x0C:
printf(" : MMM01+RAM");
break;
case 0x0D:
printf(" : MMM01+RAM+BATTERY");
break;
case 0x0F:
printf(" : MBC3+TIMER+BATTERY");
break;
case 0x10:
printf(" : MBC3+TIMER+RAM+BATTERY");
break;
case 0x11:
printf(" : MBC3");
break;
case 0x12:
printf(" : MBC3+RAM");
break;
case 0x13:
printf(" : MBC3+RAM+BATTERY");
break;
case 0x15:
printf(" : MBC4");
break;
case 0x16:
printf(" : MBC4+RAM");
break;
case 0x17:
printf(" : MBC4+RAM+BATTERY");
break;
case 0x19:
printf(" : MBC5");
break;
case 0x1A:
printf(" : MBC5+RAM");
break;
case 0x1B:
printf(" : MBC5+RAM+BATTERY");
break;
case 0x1C:
printf(" : MBC5+RUMBLE");
break;
case 0x1D:
printf(" : MBC5+RUMBLE+RAM");
break;
case 0x1E:
printf(" : MBC5+RUMBLE+RAM+BATTERY");
break;
case 0xFC:
printf(" : POKET CAMERA");
break;
case 0xFD:
printf(" : BANDAI TAMA5");
break;
case 0xFE:
printf(" : HuC3");
break;
case 0xFF:
printf(" : HuC1+RAM+BATTERY");
break;
}
}
// 0148 - ROM Size 1 Byte rom_size
if (argc!=2) printf("%02X ",rom->rom_size[0]);
else
{
printf("\nROM Size : %02X",rom->rom_size[0]);
switch ((int)rom->rom_size[0])
{
case 0x00:
printf(" : 32 KByte (no ROM banking)");
break;
case 0x01:
printf(" : 64 KByte (4 banks)");
break;
case 0x02:
printf(" : 128 KByte (8 banks)");
break;
case 0x03:
printf(" : 256 KByte (16 banks)");
break;
case 0x04:
printf(" : 512 KByte (32 banks)");
break;
case 0x05:
printf(" : 1 MByte (64 banks) - only 63 banks used by MBC1");
break;
case 0x06:
printf(" : 2 MByte (128 banks) - only 125 banks used by MBC1");
break;
case 0x07:
printf(" : 4 MByte (256 banks)");
break;
case 0x52:
printf(" : 1.1 MByte (72 banks)");
break;
case 0x53:
printf(" : 1.2 MByte (80 banks)");
break;
case 0x54:
printf(" : 1.5 MByte (96 banks)");
break;
}}
// 0149 - RAM Size 1 Byte ram_size
if (argc!=2) printf("%02X ",rom->ram_size[0]);
else
{
printf("\nRAM Size : %02X",rom->ram_size[0]);
switch ((int)rom->ram_size[0])
{
case 0x00:
printf(" : None");
break;
case 0x01:
printf(" : 2 KBytes");
break;
case 0x02:
printf(" : 8 KBytes");
break;
case 0x03:
printf(" : 32 KBytes (4 banks de 8 KBytes cada uno)");
break;
}}
// 014A - Destination Code 1 Byte destination
if (argc!=2) printf("%02X ",rom->destination[0]);
else
{
if (rom->destination[0] == 0x00) printf("\nDestination Code : %02X : Japanese",rom->destination[0]);
if (rom->destination[0] == 0x01) printf("\nDestination Code : %02X : Non-Japanese",rom->destination[0]);
if ((rom->destination[0] != 0x00) && (rom->destination[0] != 0x01)) printf("\nDestination Code : %02X : unknown",rom->destination[0]);
}
// 014B - Old Licensee Code 1 Byte olicence
if (argc!=2) printf("%02X ",rom->olicence[0]);
else
{
if (rom->olicence[0] == 0x33) printf("\nOld Licensee Code : %02X : New License Code used. Required for SGB.",rom->olicence[0]);
if (rom->olicence[0] != 0x33) printf("\nOld Licensee Code : %02X : New License Code required for SGB(33)",rom->olicence[0]);
}
// 014C - Mask ROM Version number 1 Byte maskrom_nver
if (argc!=2) printf("%02X ",rom->maskrom_nver[0]);
else printf("\nMask ROM Ver.Num. : %02X : Specifies the version number of the game. That is usually 00.",rom->maskrom_nver[0]);
// 014D - Header Checksum 1 Byte header_chk
if (argc!=2) printf("%02X ",rom->header_chk[0]);
else
{ checksum0 = 0;
for (i = 0x134; i < 0x14D; i++) checksum0 += ~rom1[i];
if (checksum0 == rom->header_chk[0]) {printf("\nHeader Checksum : %X : Checksum is correct.",checksum0);}
else printf("\nHeader Checksum : %X : Error - Checksum is incorrect.",checksum0);}
//int x=0
//FOR ()i=0134h TO 014Ch:x=x-MEM[i]-1:NEXT
/*Contains an 8 bit checksum across the cartridge header bytes 0134-014C. The
checksum is calculated as follows:
x=0:FOR i=0134h TO 014Ch:x=x-MEM[i]-1:NEXT
The lower 8 bits of the result must be the same than the value in this entry. The
GAME WON'T WORK if this checksum is incorrect. */
// 014E-014F - Global Checksum 2 Bytes global_chk
if (argc!=2) ;//printf("%02X ",rom->global_chk[0]);
else
{
check_sum.W=0;
for (i = 0; i < length; i++){
if (i==0x014E) continue;
if (i==0x014F) continue;
check_sum.W += ~rom1[i];
}
if (check_sum.W == rom->header_chk[0]) {printf("\nGlobal Checksum : %X : Checksum is correct.\n",check_sum.W);}
else printf("\nGlobal Checksum : %04X : Error (The Gameboy doesn't verify this checksum.)\n",check_sum.W);}
/*Contains a 16 bit checksum (upper byte first) across the whole cartridge ROM.
Produced by adding all bytes of the cartridge (except for the two checksum
bytes). The Gameboy doesn't verify this checksum.*/
free(rom);
free(rom1);
printf("\n");
exit(EXIT_SUCCESS);
}