Please do not remove this header or the credits from this file.

This document and some code by IQ_132. Please follow the steps carefully.

This small driver *should be bug free*




src/burn/neogeo/d_neogeo.cpp


Add this driver: Kof2003


src/burn/neogeo/


Copy k2k3fix.cpp to this directory.




MAKEFILE



Find this:
	   neogeo.o neo_run.o neo_decrypt.o neo_text.o neo_sprite.o neo_palette.o neo_upd4990a.o \
Replace with this:
	   neogeo.o neo_run.o neo_decrypt.o neo_text.o neo_sprite.o neo_palette.o neo_upd4990a.o k2k3fix.o \




src/burn/neogeo/neo_run.cpp



Find this:
#include "neogeo.h"
#include "burn_ym2610.h"
Add this after:
#include "bitswap.h"


Find this:
int nNeoSRAMProtection = -1;
Add this after:
int nNeoPCM2PLAYMOREByteswap = 0; // PCM2 PLAYMORE (version 2) chip
int nNeoTextROMFixType = 0; // Text fix for games that have encrypted/scrambled text


Find this:
	Neo68KBIOS		= Next; Next += 0x020000;			// 68K boardROM

Replace with this:
	Neo68KBIOS		= Next; Next += 0x040000;			// 68K boardROM


Find this:
	// Check if we need to load a new BIOS
	if (nNewBIOS == nBIOS) {
		return 0;
	}

	nBIOS = nNewBIOS;
Note: This code is optional (you don't have to add it).
Add this after:
	// Load 271-bios.bin
	if (!strcmp(BurnDrvText(0), "kof2003")) {
		BurnLoadRom(Neo68KBIOS, 11, 1);
	}
End optional stuff

Find this:
	if ((BurnDrvGetHardwareCode() & HARDWARE_SNK_CONTROLMASK) != HARDWARE_SNK_GAMBLING) {
			nNeo68KROMBank = -1U;
			Bankswitch(0);
	}
Replace with this:
	if ((BurnDrvGetHardwareCode() & HARDWARE_SNK_CONTROLMASK) != HARDWARE_SNK_GAMBLING) {
		if (!(BurnDrvGetHardwareCode() & HARDWARE_SNK_NEWBANKSYSTEM)) {
			nNeo68KROMBank = -1U;
			Bankswitch(0);
		}
	}


Find this:
		if (pInfo->nTextOffset != -1) {
			// Load S ROM data
			BurnLoadRom(NeoTextROM + 0x020000, pInfo->nTextOffset, 1);
		} else {
			// Extract data from the end of C ROMS
			BurnUpdateProgress(0.0, "Generating text layer graphics...", 0);
			NeoExtractSData(NeoSpriteROM, NeoTextROM + 0x020000, nSpriteSize, nNeoTextROMSize);
		}
Add this after:
		/* Original code for MAME by fataku */
		if (nNeoTextROMFixType == 1) {
		        unsigned char* srom = NeoTextROM+0x20000;
		        for (int i=0;i < 0x20000;i++) {
		        	srom[i]=BITSWAP08(srom[i],3,2,4,5,1,6,0,7);
		        }
		}
		/* Original code from mame traduced by FerchogtX */
		if (nNeoTextROMFixType == 2) {
			/* Descrambling S1 by FerchogtX, bassed on DorriGa's code */
			unsigned char* srom = NeoTextROM+0x20000;
			unsigned char* dst = (unsigned char*)malloc(0x20000);
			memcpy( dst+0x00000, srom+0x10000, 0x10000 );
			memcpy( dst+0x10000, srom+0x00000, 0x10000 );
			memcpy( srom, dst, 0x20000 );
			free(dst);
		}
		/* Thanks also to HappyASR for the info */
		if (nNeoTextROMFixType == 3) {
			unsigned char* srom = NeoTextROM+0x20000;
			unsigned char* dst = (unsigned char*)malloc(0x20000);
			if (dst)
			{
				memcpy(dst,srom,0x20000);
				// descrambling the S1 by dorriGa
				for (int j=0;j < 0x20000 ; j+=0x000010)
				{
					memcpy(srom+j, dst+j+0x000008,8);
					memcpy(srom+j+0x000008, dst+j,8);
				}
			}
			free(dst);
		}
		/* Thanks to Badzou for the info */
		if (nNeoTextROMFixType == 4) {
			/* Descrambling S1 by dorriga */
			unsigned char* srom = NeoTextROM+0x20000;
			unsigned char* dst = (unsigned char*)malloc(0x80000);
			memcpy( dst+0x00000, srom+0x60000, 0x20000 );
			memcpy( dst+0x20000, srom+0x40000, 0x20000 );
			memcpy( dst+0x40000, srom+0x20000, 0x20000 );
			memcpy( dst+0x60000, srom+0x00000, 0x20000 );
			memcpy( srom, dst, 0x80000 );
			free(dst);
		}
		// Converted by Jimmy_Page (www.neofighters.com)
		if (nNeoTextROMFixType == 5) {
		        unsigned char* srom = NeoTextROM+0x20000;
		        for (int i=0;i < 0x20000;i++) {
		        	srom[i]=BITSWAP08(srom[i],7,6,0,4,3,2,1,5);
		        }
		}
		// Original conversion by IQ_132 (This is for svcchaos, kof2003, and clones)
		if (nNeoTextROMFixType == 6) {
			unsigned char* srom = NeoTextROM+0x20000;
			for( int i=0;i < nNeoTextROMSize;i++ ){
				srom[i]=BITSWAP08(srom[i]^0xd2,4,0,7,2,5,1,6,3);
			}
		}


Find this:
		if (BurnDrvGetHardwareCode() & HARDWARE_SNK_SWAPV) {
			for (int i = 0; i < 0x00200000; i++) {
				unsigned char n = YM2610ADPCMAROM[i];
				YM2610ADPCMAROM[i] = YM2610ADPCMAROM[0x00200000 + i];
				YM2610ADPCMAROM[0x00200000 + i] = n;
			}
		}
	}
Add this after:
	/* Neo-PCM2 PLAYMORE(c) 2002 Sound Chip Emulation */
	// some code by Fataku & some by the vconv (from 2ch) - FBA conversion by iq_132
	if (nNeoPCM2PLAYMOREByteswap != 0)
	{
		unsigned int addrs[7][2]={
			{0x000000,0xA5000}, //kof2002
			{0xFFCE20,0x01000}, //matrimelee
			{0xFE2CF6,0x4E001}, //mslug5
			{0xFEB2C0,0x0A000}, //samsho5
			{0xFFAC28,0xC2000}, //svcchaos
			{0xFF14EA,0xA7001}, //kof2003
			{0xFFB440,0x02000}, //samsh5sp
		};
		unsigned int xordata[7][8]={
			{0xF9,0xE0,0x5D,0xF3,0xEA,0x92,0xBE,0xEF}, //kof2002
			{0xC4,0x83,0xA8,0x5F,0x21,0x27,0x64,0xAF}, //matrimelee
			{0xC3,0xFD,0x81,0xAC,0x6D,0xE7,0xBF,0x9E}, //mslug5
			{0xCB,0x29,0x7D,0x43,0xD2,0x3A,0xC2,0xB4}, //samsho5
			{0xC3,0xFD,0x81,0xAC,0x6D,0xE7,0xBF,0x9E}, //svcchaos
			{0x4B,0xA4,0x63,0x46,0xF0,0x91,0xEA,0x62}, //kof2003
			{0x4B,0xA4,0x63,0x46,0xF0,0x91,0xEA,0x62}, //samsh5sp
		};

		int value = (nNeoPCM2PLAYMOREByteswap-1);	
		UINT8 *rom = YM2610ADPCMAROM;
		UINT8 *buf = (UINT8*)malloc(0x1000000);
		int ofst;

		memcpy(buf,rom,0x1000000);

		for(int i=0; i<0x1000000; i++)
		{
			ofst = (i & 0xfefffe) | ((i & 0x010000) >> 16) | ((i & 0x000001) << 16);
			ofst ^= addrs[value][1];
			rom[ofst] = (buf[((i + addrs[value][0]) & 0xffffff)] ^ xordata[value][(ofst & 0x07)]);
		}

		free(buf);
	}


Find this:
int NeoExit()
{
Add this after:
	nNeoTextROMFixType = -1;	// Turns off text fix when you quit a game
	nNeoPCM2PLAYMOREByteswap = 0; 	// Turns off Neo-PCM2 Version 2




src/burn/neogeo/neo_decrypt.cpp



Find this:
void NeoExtractSData(unsigned char* rom, unsigned char* sdata, int rom_size, int sdata_size)
{
	/* the S data comes from the end fo the C data */
	rom += rom_size - sdata_size;

	for (int i = 0; i < sdata_size; i++) {
		sdata[i] = rom[(i & ~0x1F) + ((i & 7) << 2) + ((~i & 8) >> 2) + ((i & 0x10) >> 4)];
	}
}
Replace with this:
void NeoExtractSData(unsigned char* rom, unsigned char* sdata, int rom_size, int sdata_size)
{
	int i;
	if (sdata_size != 0x100000)
	{	
		/* the S data comes from the end fo the C data */
		rom += rom_size - sdata_size;
	
		for (i = 0; i < sdata_size; i++) {
			sdata[i] = rom[(i & ~0x1F) + ((i & 7) << 2) + ((~i & 8) >> 2) + ((i & 0x10) >> 4)];
 		}
	} else {
		rom += rom_size - 0x1000000 - 0x80000; 

		for (i = 0; i < sdata_size / 2; i++) {
			sdata[i] = rom[(i & ~0x1F) + ((i & 7) << 2) + ((~i & 8) >> 2) + ((i & 0x10) >> 4)];
 		}
	 
		rom += 0x1000000; 

		for (i = 0; i < sdata_size / 2; i++) {
			sdata[i+0x80000] = rom[(i & ~0x1F) + ((i & 7) << 2) + ((~i & 8) >> 2) + ((i & 0x10) >> 4)];
 		} 
	}
}




src/burn/neogeo/neogeo.h



Find this:
// neo_run.cpp
Add this after:
#define HARDWARE_SNK_NEWBANKSYSTEM 0x0200
extern int nNeoPCM2PLAYMOREByteswap;
extern int nNeoTextROMFixType;





Big thanks to FerchogtX, Jimmy_Page, Halrin, fataku, and dorriga

Thanks to Ferchogtx for the nNeoPCM2PLAYMOREByteswap and nNeoTextROMFixType code & layout.
Thanks to Halrin for the P decryption code, S decryption code, and nfos.
Thanks to Jimmy_Page for beta testing and some S decryption code.
Thanks to fataku for the V decryption code and some S decryption code.
Thanks to dorriga for some S decryption code.