update core to FCEUX 2.1.0a

This commit is contained in:
dborth 2009-07-17 17:27:04 +00:00
parent fe266601bd
commit 6cd1e80ef1
351 changed files with 50038 additions and 33037 deletions

View File

@ -21,7 +21,7 @@ BUILD := build_gc
SOURCES := source/ngc/images source/ngc/sounds source/ngc/fonts \
source/ngc/gui source/ngc \
source/fceultra source/fceultra/boards source/fceultra/input \
source/fceultra/mappers source/fceultra/mbshare \
source/fceultra/utils source/fceultra/mappers source/fceultra/mbshare \
source/sz source/unzip
INCLUDES := source/fceultra source/ngc source/unzip
@ -29,7 +29,7 @@ INCLUDES := source/fceultra source/ngc source/unzip
# options for code generation
#---------------------------------------------------------------------------------
CFLAGS = -g -O3 -Wall $(MACHDEP) $(INCLUDE) -DNGC -DNO_SOUND \
-DFCEU_VERSION_NUMERIC=9812 -DFRAMESKIP \
-DFRAMESKIP -DPSS_STYLE=1 -DPATH_MAX=1024 -DHAVE_ASPRINTF \
-D_SZ_ONE_DIRECTORY -D_LZMA_IN_CB -D_LZMA_OUT_READ \
-fomit-frame-pointer \
-Wno-unused-parameter -Wno-strict-aliasing

View File

@ -21,7 +21,7 @@ BUILD := build_wii
SOURCES := source/ngc/images source/ngc/sounds source/ngc/fonts \
source/ngc/gui source/ngc \
source/fceultra source/fceultra/boards source/fceultra/input \
source/fceultra/mappers source/fceultra/mbshare \
source/fceultra/utils source/fceultra/mappers source/fceultra/mbshare \
source/sz source/unzip
INCLUDES := source/fceultra source/ngc source/unzip
@ -29,7 +29,7 @@ INCLUDES := source/fceultra source/ngc source/unzip
# options for code generation
#---------------------------------------------------------------------------------
CFLAGS = -g -O3 -Wall $(MACHDEP) $(INCLUDE) -DNGC \
-DFCEU_VERSION_NUMERIC=9812 -DFRAMESKIP \
-DFRAMESKIP -DPSS_STYLE=1 -DPATH_MAX=1024 -DHAVE_ASPRINTF \
-D_SZ_ONE_DIRECTORY -D_LZMA_IN_CB -D_LZMA_OUT_READ \
-fomit-frame-pointer \
-Wno-unused-parameter -Wno-strict-aliasing

522
source/fceultra/asm.cpp Normal file
View File

@ -0,0 +1,522 @@
/// \file
/// \brief 6502 assembler and disassembler
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "types.h"
#include "utils/xstring.h"
#include "debug.h"
#include "asm.h"
#include "x6502.h"
///assembles the string to an instruction located at addr, storing opcodes in output buffer
int Assemble(unsigned char *output, int addr, char *str) {
//unsigned char opcode[3] = { 0,0,0 };
output[0] = output[1] = output[2] = 0;
char astr[128],ins[4];
if ((!strlen(str)) || (strlen(str) > 0x127)) return 1;
strcpy(astr,str);
str_ucase(astr);
sscanf(astr,"%3s",ins); //get instruction
if (strlen(ins) != 3) return 1;
strcpy(astr,strstr(astr,ins)+3); //heheh, this is probably a bad idea, but let's do it anyway!
if ((astr[0] != ' ') && (astr[0] != 0)) return 1;
//remove all whitespace
str_strip(astr,STRIP_SP|STRIP_TAB|STRIP_CR|STRIP_LF);
//repair syntax
chr_replace(astr,'[','('); //brackets
chr_replace(astr,']',')');
chr_replace(astr,'{','(');
chr_replace(astr,'}',')');
chr_replace(astr,';',0); //comments
str_replace(astr,"0X","$"); //miscellaneous
//This does the following:
// 1) Sets opcode[0] on success, else returns 1.
// 2) Parses text in *astr to build the rest of the assembled
// data in 'opcode', else returns 1 on error.
if (!strlen(astr)) {
//Implied instructions
if (!strcmp(ins,"BRK")) output[0] = 0x00;
else if (!strcmp(ins,"PHP")) output[0] = 0x08;
else if (!strcmp(ins,"ASL")) output[0] = 0x0A;
else if (!strcmp(ins,"CLC")) output[0] = 0x18;
else if (!strcmp(ins,"PLP")) output[0] = 0x28;
else if (!strcmp(ins,"ROL")) output[0] = 0x2A;
else if (!strcmp(ins,"SEC")) output[0] = 0x38;
else if (!strcmp(ins,"RTI")) output[0] = 0x40;
else if (!strcmp(ins,"PHA")) output[0] = 0x48;
else if (!strcmp(ins,"LSR")) output[0] = 0x4A;
else if (!strcmp(ins,"CLI")) output[0] = 0x58;
else if (!strcmp(ins,"RTS")) output[0] = 0x60;
else if (!strcmp(ins,"PLA")) output[0] = 0x68;
else if (!strcmp(ins,"ROR")) output[0] = 0x6A;
else if (!strcmp(ins,"SEI")) output[0] = 0x78;
else if (!strcmp(ins,"DEY")) output[0] = 0x88;
else if (!strcmp(ins,"TXA")) output[0] = 0x8A;
else if (!strcmp(ins,"TYA")) output[0] = 0x98;
else if (!strcmp(ins,"TXS")) output[0] = 0x9A;
else if (!strcmp(ins,"TAY")) output[0] = 0xA8;
else if (!strcmp(ins,"TAX")) output[0] = 0xAA;
else if (!strcmp(ins,"CLV")) output[0] = 0xB8;
else if (!strcmp(ins,"TSX")) output[0] = 0xBA;
else if (!strcmp(ins,"INY")) output[0] = 0xC8;
else if (!strcmp(ins,"DEX")) output[0] = 0xCA;
else if (!strcmp(ins,"CLD")) output[0] = 0xD8;
else if (!strcmp(ins,"INX")) output[0] = 0xE8;
else if (!strcmp(ins,"NOP")) output[0] = 0xEA;
else if (!strcmp(ins,"SED")) output[0] = 0xF8;
else return 1;
}
else {
//Instructions with Operands
if (!strcmp(ins,"ORA")) output[0] = 0x01;
else if (!strcmp(ins,"ASL")) output[0] = 0x06;
else if (!strcmp(ins,"BPL")) output[0] = 0x10;
else if (!strcmp(ins,"JSR")) output[0] = 0x20;
else if (!strcmp(ins,"AND")) output[0] = 0x21;
else if (!strcmp(ins,"BIT")) output[0] = 0x24;
else if (!strcmp(ins,"ROL")) output[0] = 0x26;
else if (!strcmp(ins,"BMI")) output[0] = 0x30;
else if (!strcmp(ins,"EOR")) output[0] = 0x41;
else if (!strcmp(ins,"LSR")) output[0] = 0x46;
else if (!strcmp(ins,"JMP")) output[0] = 0x4C;
else if (!strcmp(ins,"BVC")) output[0] = 0x50;
else if (!strcmp(ins,"ADC")) output[0] = 0x61;
else if (!strcmp(ins,"ROR")) output[0] = 0x66;
else if (!strcmp(ins,"BVS")) output[0] = 0x70;
else if (!strcmp(ins,"STA")) output[0] = 0x81;
else if (!strcmp(ins,"STY")) output[0] = 0x84;
else if (!strcmp(ins,"STX")) output[0] = 0x86;
else if (!strcmp(ins,"BCC")) output[0] = 0x90;
else if (!strcmp(ins,"LDY")) output[0] = 0xA0;
else if (!strcmp(ins,"LDA")) output[0] = 0xA1;
else if (!strcmp(ins,"LDX")) output[0] = 0xA2;
else if (!strcmp(ins,"BCS")) output[0] = 0xB0;
else if (!strcmp(ins,"CPY")) output[0] = 0xC0;
else if (!strcmp(ins,"CMP")) output[0] = 0xC1;
else if (!strcmp(ins,"DEC")) output[0] = 0xC6;
else if (!strcmp(ins,"BNE")) output[0] = 0xD0;
else if (!strcmp(ins,"CPX")) output[0] = 0xE0;
else if (!strcmp(ins,"SBC")) output[0] = 0xE1;
else if (!strcmp(ins,"INC")) output[0] = 0xE6;
else if (!strcmp(ins,"BEQ")) output[0] = 0xF0;
else return 1;
{
//Parse Operands
// It's not the sexiest thing ever, but it works well enough!
//TODO:
// Add branches.
// Fix certain instructions. (Setting bits is not 100% perfect.)
// Fix instruction/operand matching. (Instructions like "jmp ($94),Y" are no good!)
// Optimizations?
int tmpint;
char tmpchr,tmpstr[20];
if (sscanf(astr,"#$%2X%c",&tmpint,&tmpchr) == 1) { //#Immediate
switch (output[0]) {
case 0x20: case 0x4C: //Jumps
case 0x10: case 0x30: case 0x50: case 0x70: //Branches
case 0x90: case 0xB0: case 0xD0: case 0xF0:
case 0x06: case 0x24: case 0x26: case 0x46: //Other instructions incapable of #Immediate
case 0x66: case 0x81: case 0x84: case 0x86:
case 0xC6: case 0xE6:
return 1;
default:
//cheap hack for certain instructions
switch (output[0]) {
case 0xA0: case 0xA2: case 0xC0: case 0xE0:
break;
default:
output[0] |= 0x08;
break;
}
output[1] = tmpint;
break;
}
}
else if (sscanf(astr,"$%4X%c",&tmpint,&tmpchr) == 1) { //Absolute, Zero Page, Branch, or Jump
switch (output[0]) {
case 0x20: case 0x4C: //Jumps
output[1] = (tmpint & 0xFF);
output[2] = (tmpint >> 8);
break;
case 0x10: case 0x30: case 0x50: case 0x70: //Branches
case 0x90: case 0xB0: case 0xD0: case 0xF0:
tmpint -= (addr+2);
if ((tmpint < -128) || (tmpint > 127)) return 1;
output[1] = (tmpint & 0xFF);
break;
//return 1; //FIX ME
default:
if (tmpint > 0xFF) { //Absolute
output[0] |= 0x0C;
output[1] = (tmpint & 0xFF);
output[2] = (tmpint >> 8);
}
else { //Zero Page
output[0] |= 0x04;
output[1] = (tmpint & 0xFF);
}
break;
}
}
else if (sscanf(astr,"$%4X%s",&tmpint,tmpstr) == 2) { //Absolute,X, Zero Page,X, Absolute,Y or Zero Page,Y
if (!strcmp(tmpstr,",X")) { //Absolute,X or Zero Page,X
switch (output[0]) {
case 0x20: case 0x4C: //Jumps
case 0x10: case 0x30: case 0x50: case 0x70: //Branches
case 0x90: case 0xB0: case 0xD0: case 0xF0:
case 0x24: case 0x86: case 0xA2: case 0xC0: //Other instructions incapable of Absolute,X or Zero Page,X
case 0xE0:
return 1;
default:
if (tmpint > 0xFF) { //Absolute
if (output[0] == 0x84) return 1; //No STY Absolute,X!
output[0] |= 0x1C;
output[1] = (tmpint & 0xFF);
output[2] = (tmpint >> 8);
}
else { //Zero Page
output[0] |= 0x14;
output[1] = (tmpint & 0xFF);
}
break;
}
}
else if (!strcmp(tmpstr,",Y")) { //Absolute,Y or Zero Page,Y
switch (output[0]) {
case 0x20: case 0x4C: //Jumps
case 0x10: case 0x30: case 0x50: case 0x70: //Branches
case 0x90: case 0xB0: case 0xD0: case 0xF0:
case 0x06: case 0x24: case 0x26: case 0x46: //Other instructions incapable of Absolute,Y or Zero Page,Y
case 0x66: case 0x84: case 0x86: case 0xA0:
case 0xC0: case 0xC6: case 0xE0: case 0xE6:
return 1;
case 0xA2: //cheap hack for LDX
output[0] |= 0x04;
default:
if (tmpint > 0xFF) { //Absolute
if (output[0] == 0x86) return 1; //No STX Absolute,Y!
output[0] |= 0x18;
output[1] = (tmpint & 0xFF);
output[2] = (tmpint >> 8);
}
else { //Zero Page
if ((output[0] != 0x86) || (output[0] != 0xA2)) return 1; //only STX and LDX Absolute,Y!
output[0] |= 0x10;
output[1] = (tmpint & 0xFF);
}
break;
}
}
else return 1;
}
else if (sscanf(astr,"($%4X%s",&tmpint,tmpstr) == 2) { //Jump (Indirect), (Indirect,X) or (Indirect),Y
switch (output[0]) {
case 0x20: //Jumps
case 0x10: case 0x30: case 0x50: case 0x70: //Branches
case 0x90: case 0xB0: case 0xD0: case 0xF0:
case 0x06: case 0x24: case 0x26: case 0x46: //Other instructions incapable of Jump (Indirect), (Indirect,X) or (Indirect),Y
case 0x66: case 0x84: case 0x86: case 0xA0:
case 0xA2: case 0xC0: case 0xC6: case 0xE0:
case 0xE6:
return 1;
default:
if ((!strcmp(tmpstr,")")) && (output[0] == 0x4C)) { //Jump (Indirect)
output[0] = 0x6C;
output[1] = (tmpint & 0xFF);
output[2] = (tmpint >> 8);
}
else if ((!strcmp(tmpstr,",X)")) && (tmpint <= 0xFF) && (output[0] != 0x4C)) { //(Indirect,X)
output[1] = (tmpint & 0xFF);
}
else if ((!strcmp(tmpstr,"),Y")) && (tmpint <= 0xFF) && (output[0] != 0x4C)) { //(Indirect),Y
output[0] |= 0x10;
output[1] = (tmpint & 0xFF);
}
else return 1;
break;
}
}
else return 1;
}
}
return 0;
}
///disassembles the opcodes in the buffer assuming the provided address. Uses GetMem() and 6502 current registers to query referenced values. returns a static string buffer.
char *Disassemble(int addr, uint8 *opcode) {
static char str[64]={0},chr[5]={0};
uint16 tmp,tmp2;
//these may be replaced later with passed-in values to make a lighter-weight disassembly mode that may not query the referenced values
#define RX (X.X)
#define RY (X.Y)
switch (opcode[0]) {
#define relative(a) { \
if (((a)=opcode[1])&0x80) (a) = addr-(((a)-1)^0xFF); \
else (a)+=addr; \
}
#define absolute(a) { \
(a) = opcode[1] | opcode[2]<<8; \
}
#define zpIndex(a,i) { \
(a) = opcode[1]+(i); \
}
#define indirectX(a) { \
(a) = (opcode[1]+RX)&0xFF; \
(a) = GetMem((a)) | (GetMem((a)+1))<<8; \
}
#define indirectY(a) { \
(a) = GetMem(opcode[1]) | (GetMem(opcode[1]+1))<<8; \
(a) += RY; \
}
//odd, 1-byte opcodes
case 0x00: strcpy(str,"BRK"); break;
case 0x08: strcpy(str,"PHP"); break;
case 0x0A: strcpy(str,"ASL"); break;
case 0x18: strcpy(str,"CLC"); break;
case 0x28: strcpy(str,"PLP"); break;
case 0x2A: strcpy(str,"ROL"); break;
case 0x38: strcpy(str,"SEC"); break;
case 0x40: strcpy(str,"RTI"); break;
case 0x48: strcpy(str,"PHA"); break;
case 0x4A: strcpy(str,"LSR"); break;
case 0x58: strcpy(str,"CLI"); break;
case 0x60: strcpy(str,"RTS"); break;
case 0x68: strcpy(str,"PLA"); break;
case 0x6A: strcpy(str,"ROR"); break;
case 0x78: strcpy(str,"SEI"); break;
case 0x88: strcpy(str,"DEY"); break;
case 0x8A: strcpy(str,"TXA"); break;
case 0x98: strcpy(str,"TYA"); break;
case 0x9A: strcpy(str,"TXS"); break;
case 0xA8: strcpy(str,"TAY"); break;
case 0xAA: strcpy(str,"TAX"); break;
case 0xB8: strcpy(str,"CLV"); break;
case 0xBA: strcpy(str,"TSX"); break;
case 0xC8: strcpy(str,"INY"); break;
case 0xCA: strcpy(str,"DEX"); break;
case 0xD8: strcpy(str,"CLD"); break;
case 0xE8: strcpy(str,"INX"); break;
case 0xEA: strcpy(str,"NOP"); break;
case 0xF8: strcpy(str,"SED"); break;
//(Indirect,X)
case 0x01: strcpy(chr,"ORA"); goto _indirectx;
case 0x21: strcpy(chr,"AND"); goto _indirectx;
case 0x41: strcpy(chr,"EOR"); goto _indirectx;
case 0x61: strcpy(chr,"ADC"); goto _indirectx;
case 0x81: strcpy(chr,"STA"); goto _indirectx;
case 0xA1: strcpy(chr,"LDA"); goto _indirectx;
case 0xC1: strcpy(chr,"CMP"); goto _indirectx;
case 0xE1: strcpy(chr,"SBC"); goto _indirectx;
_indirectx:
indirectX(tmp);
sprintf(str,"%s ($%02X,X) @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp));
break;
//Zero Page
case 0x05: strcpy(chr,"ORA"); goto _zeropage;
case 0x06: strcpy(chr,"ASL"); goto _zeropage;
case 0x24: strcpy(chr,"BIT"); goto _zeropage;
case 0x25: strcpy(chr,"AND"); goto _zeropage;
case 0x26: strcpy(chr,"ROL"); goto _zeropage;
case 0x45: strcpy(chr,"EOR"); goto _zeropage;
case 0x46: strcpy(chr,"LSR"); goto _zeropage;
case 0x65: strcpy(chr,"ADC"); goto _zeropage;
case 0x66: strcpy(chr,"ROR"); goto _zeropage;
case 0x84: strcpy(chr,"STY"); goto _zeropage;
case 0x85: strcpy(chr,"STA"); goto _zeropage;
case 0x86: strcpy(chr,"STX"); goto _zeropage;
case 0xA4: strcpy(chr,"LDY"); goto _zeropage;
case 0xA5: strcpy(chr,"LDA"); goto _zeropage;
case 0xA6: strcpy(chr,"LDX"); goto _zeropage;
case 0xC4: strcpy(chr,"CPY"); goto _zeropage;
case 0xC5: strcpy(chr,"CMP"); goto _zeropage;
case 0xC6: strcpy(chr,"DEC"); goto _zeropage;
case 0xE4: strcpy(chr,"CPX"); goto _zeropage;
case 0xE5: strcpy(chr,"SBC"); goto _zeropage;
case 0xE6: strcpy(chr,"INC"); goto _zeropage;
_zeropage:
// ################################## Start of SP CODE ###########################
// Change width to %04X
sprintf(str,"%s $%04X = #$%02X", chr,opcode[1],GetMem(opcode[1]));
// ################################## End of SP CODE ###########################
break;
//#Immediate
case 0x09: strcpy(chr,"ORA"); goto _immediate;
case 0x29: strcpy(chr,"AND"); goto _immediate;
case 0x49: strcpy(chr,"EOR"); goto _immediate;
case 0x69: strcpy(chr,"ADC"); goto _immediate;
//case 0x89: strcpy(chr,"STA"); goto _immediate; //baka, no STA #imm!!
case 0xA0: strcpy(chr,"LDY"); goto _immediate;
case 0xA2: strcpy(chr,"LDX"); goto _immediate;
case 0xA9: strcpy(chr,"LDA"); goto _immediate;
case 0xC0: strcpy(chr,"CPY"); goto _immediate;
case 0xC9: strcpy(chr,"CMP"); goto _immediate;
case 0xE0: strcpy(chr,"CPX"); goto _immediate;
case 0xE9: strcpy(chr,"SBC"); goto _immediate;
_immediate:
sprintf(str,"%s #$%02X", chr,opcode[1]);
break;
//Absolute
case 0x0D: strcpy(chr,"ORA"); goto _absolute;
case 0x0E: strcpy(chr,"ASL"); goto _absolute;
case 0x2C: strcpy(chr,"BIT"); goto _absolute;
case 0x2D: strcpy(chr,"AND"); goto _absolute;
case 0x2E: strcpy(chr,"ROL"); goto _absolute;
case 0x4D: strcpy(chr,"EOR"); goto _absolute;
case 0x4E: strcpy(chr,"LSR"); goto _absolute;
case 0x6D: strcpy(chr,"ADC"); goto _absolute;
case 0x6E: strcpy(chr,"ROR"); goto _absolute;
case 0x8C: strcpy(chr,"STY"); goto _absolute;
case 0x8D: strcpy(chr,"STA"); goto _absolute;
case 0x8E: strcpy(chr,"STX"); goto _absolute;
case 0xAC: strcpy(chr,"LDY"); goto _absolute;
case 0xAD: strcpy(chr,"LDA"); goto _absolute;
case 0xAE: strcpy(chr,"LDX"); goto _absolute;
case 0xCC: strcpy(chr,"CPY"); goto _absolute;
case 0xCD: strcpy(chr,"CMP"); goto _absolute;
case 0xCE: strcpy(chr,"DEC"); goto _absolute;
case 0xEC: strcpy(chr,"CPX"); goto _absolute;
case 0xED: strcpy(chr,"SBC"); goto _absolute;
case 0xEE: strcpy(chr,"INC"); goto _absolute;
_absolute:
absolute(tmp);
sprintf(str,"%s $%04X = #$%02X", chr,tmp,GetMem(tmp));
break;
//branches
case 0x10: strcpy(chr,"BPL"); goto _branch;
case 0x30: strcpy(chr,"BMI"); goto _branch;
case 0x50: strcpy(chr,"BVC"); goto _branch;
case 0x70: strcpy(chr,"BVS"); goto _branch;
case 0x90: strcpy(chr,"BCC"); goto _branch;
case 0xB0: strcpy(chr,"BCS"); goto _branch;
case 0xD0: strcpy(chr,"BNE"); goto _branch;
case 0xF0: strcpy(chr,"BEQ"); goto _branch;
_branch:
relative(tmp);
sprintf(str,"%s $%04X", chr,tmp);
break;
//(Indirect),Y
case 0x11: strcpy(chr,"ORA"); goto _indirecty;
case 0x31: strcpy(chr,"AND"); goto _indirecty;
case 0x51: strcpy(chr,"EOR"); goto _indirecty;
case 0x71: strcpy(chr,"ADC"); goto _indirecty;
case 0x91: strcpy(chr,"STA"); goto _indirecty;
case 0xB1: strcpy(chr,"LDA"); goto _indirecty;
case 0xD1: strcpy(chr,"CMP"); goto _indirecty;
case 0xF1: strcpy(chr,"SBC"); goto _indirecty;
_indirecty:
indirectY(tmp);
sprintf(str,"%s ($%02X),Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp));
break;
//Zero Page,X
case 0x15: strcpy(chr,"ORA"); goto _zeropagex;
case 0x16: strcpy(chr,"ASL"); goto _zeropagex;
case 0x35: strcpy(chr,"AND"); goto _zeropagex;
case 0x36: strcpy(chr,"ROL"); goto _zeropagex;
case 0x55: strcpy(chr,"EOR"); goto _zeropagex;
case 0x56: strcpy(chr,"LSR"); goto _zeropagex;
case 0x75: strcpy(chr,"ADC"); goto _zeropagex;
case 0x76: strcpy(chr,"ROR"); goto _zeropagex;
case 0x94: strcpy(chr,"STY"); goto _zeropagex;
case 0x95: strcpy(chr,"STA"); goto _zeropagex;
case 0xB4: strcpy(chr,"LDY"); goto _zeropagex;
case 0xB5: strcpy(chr,"LDA"); goto _zeropagex;
case 0xD5: strcpy(chr,"CMP"); goto _zeropagex;
case 0xD6: strcpy(chr,"DEC"); goto _zeropagex;
case 0xF5: strcpy(chr,"SBC"); goto _zeropagex;
case 0xF6: strcpy(chr,"INC"); goto _zeropagex;
_zeropagex:
zpIndex(tmp,RX);
// ################################## Start of SP CODE ###########################
// Change width to %04X
sprintf(str,"%s $%02X,X @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp));
// ################################## End of SP CODE ###########################
break;
//Absolute,Y
case 0x19: strcpy(chr,"ORA"); goto _absolutey;
case 0x39: strcpy(chr,"AND"); goto _absolutey;
case 0x59: strcpy(chr,"EOR"); goto _absolutey;
case 0x79: strcpy(chr,"ADC"); goto _absolutey;
case 0x99: strcpy(chr,"STA"); goto _absolutey;
case 0xB9: strcpy(chr,"LDA"); goto _absolutey;
case 0xBE: strcpy(chr,"LDX"); goto _absolutey;
case 0xD9: strcpy(chr,"CMP"); goto _absolutey;
case 0xF9: strcpy(chr,"SBC"); goto _absolutey;
_absolutey:
absolute(tmp);
tmp2=(tmp+RY);
sprintf(str,"%s $%04X,Y @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2));
break;
//Absolute,X
case 0x1D: strcpy(chr,"ORA"); goto _absolutex;
case 0x1E: strcpy(chr,"ASL"); goto _absolutex;
case 0x3D: strcpy(chr,"AND"); goto _absolutex;
case 0x3E: strcpy(chr,"ROL"); goto _absolutex;
case 0x5D: strcpy(chr,"EOR"); goto _absolutex;
case 0x5E: strcpy(chr,"LSR"); goto _absolutex;
case 0x7D: strcpy(chr,"ADC"); goto _absolutex;
case 0x7E: strcpy(chr,"ROR"); goto _absolutex;
case 0x9D: strcpy(chr,"STA"); goto _absolutex;
case 0xBC: strcpy(chr,"LDY"); goto _absolutex;
case 0xBD: strcpy(chr,"LDA"); goto _absolutex;
case 0xDD: strcpy(chr,"CMP"); goto _absolutex;
case 0xDE: strcpy(chr,"DEC"); goto _absolutex;
case 0xFD: strcpy(chr,"SBC"); goto _absolutex;
case 0xFE: strcpy(chr,"INC"); goto _absolutex;
_absolutex:
absolute(tmp);
tmp2=(tmp+RX);
sprintf(str,"%s $%04X,X @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2));
break;
//jumps
case 0x20: strcpy(chr,"JSR"); goto _jump;
case 0x4C: strcpy(chr,"JMP"); goto _jump;
case 0x6C: absolute(tmp); sprintf(str,"JMP ($%04X) = $%04X", tmp,GetMem(tmp)|GetMem(tmp+1)<<8); break;
_jump:
absolute(tmp);
sprintf(str,"%s $%04X", chr,tmp);
break;
//Zero Page,Y
case 0x96: strcpy(chr,"STX"); goto _zeropagey;
case 0xB6: strcpy(chr,"LDX"); goto _zeropagey;
_zeropagey:
zpIndex(tmp,RY);
// ################################## Start of SP CODE ###########################
// Change width to %04X
sprintf(str,"%s $%04X,Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp));
// ################################## End of SP CODE ###########################
break;
//UNDEFINED
default: strcpy(str,"ERROR"); break;
}
return str;
}

2
source/fceultra/asm.h Normal file
View File

@ -0,0 +1,2 @@
int Assemble(unsigned char *output, int addr, char *str);
char *Disassemble(int addr, uint8 *opcode);

View File

@ -0,0 +1,103 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2006 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* TXC mappers
*/
#include "mapinc.h"
static uint8 reg[4], cmd, is172, is173;
static SFORMAT StateRegs[]=
{
{reg, 4, "REGS"},
{&cmd, 1, "CMD"},
{0}
};
static void Sync(void)
{
setprg32(0x8000,(reg[2]>>2)&1);
if(is172)
setchr8((((cmd^reg[2])>>3)&2)|(((cmd^reg[2])>>5)&1)); // 1991 DU MA Racing probably CHR bank sequence is WRONG, so it is possible to
// rearrange CHR banks for normal UNIF board and mapper 172 is unneccessary
else
setchr8(reg[2]&3);
}
static DECLFW(UNL22211WriteLo)
{
// FCEU_printf("bs %04x %02x\n",A,V);
reg[A&3]=V;
}
static DECLFW(UNL22211WriteHi)
{
// FCEU_printf("bs %04x %02x\n",A,V);
cmd=V;
Sync();
}
static DECLFR(UNL22211ReadLo)
{
return (reg[1]^reg[2])|(is173?0x01:0x40);
// if(reg[3])
// return reg[2];
// else
// return X.DB;
}
static void UNL22211Power(void)
{
Sync();
SetReadHandler(0x8000,0xFFFF,CartBR);
SetReadHandler(0x4100,0x4100,UNL22211ReadLo);
SetWriteHandler(0x4100,0x4103,UNL22211WriteLo);
SetWriteHandler(0x8000,0xFFFF,UNL22211WriteHi);
}
static void StateRestore(int version)
{
Sync();
}
void UNL22211_Init(CartInfo *info)
{
is172=0;
is173=0;
info->Power=UNL22211Power;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
void Mapper172_Init(CartInfo *info)
{
is172=1;
is173=0;
info->Power=UNL22211Power;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
void Mapper173_Init(CartInfo *info)
{
is172=0;
is173=1;
info->Power=UNL22211Power;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,115 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 reg0, reg1, reg2;
static uint8 *WRAM=NULL;
static uint32 WRAMSIZE;
static SFORMAT StateRegs[]=
{
{&reg0, 1, "REG0"},
{&reg1, 1, "REG1"},
{&reg2, 1, "REG2"},
{0}
};
static void Sync(void)
{
setchr8(0);
setprg8(0x8000,0xc);
setprg8(0xe000,0xf);
if(reg2&0x10)
{
setprg8(0x6000,reg0);
setprg8(0xa000,0xd);
setprg8(0xc000,0xe);
}
else
{
setprg8r(0x10,0x6000,0);
setprg4(0xa000,(0xd<<1));
setprg2(0xb000,(0xd<<2)+2);
setprg2r(0x10,0xb800,4);
setprg2r(0x10,0xc000,5);
setprg2r(0x10,0xc800,6);
setprg2r(0x10,0xd000,7);
setprg2(0xd800,(0xe<<2)+3);
}
setmirror(reg1);
}
static DECLFW(M103Write0)
{
reg0=V&0xf;
Sync();
}
static DECLFW(M103Write1)
{
reg1=(V>>3)&1;
Sync();
}
static DECLFW(M103Write2)
{
reg2=V;
Sync();
}
static void M103Power(void)
{
reg0=reg1=0; reg2=0;
Sync();
SetReadHandler(0x6000,0x7FFF,CartBR);
SetWriteHandler(0x6000,0x7FFF,CartBW);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0xB800,0xD7FF,CartBW);
SetWriteHandler(0x8000,0x8FFF,M103Write0);
SetWriteHandler(0xE000,0xEFFF,M103Write1);
SetWriteHandler(0xF000,0xFFFF,M103Write2);
}
static void M103Close(void)
{
if(WRAM)
FCEU_gfree(WRAM);
WRAM=NULL;
}
static void StateRestore(int version)
{
Sync();
}
void Mapper103_Init(CartInfo *info)
{
info->Power=M103Power;
info->Close=M103Close;
GameStateRestore=StateRestore;
WRAMSIZE=16384;
WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,119 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 reg[16], IRQa;
static uint32 IRQCount;
static uint8 *WRAM=NULL;
static uint32 WRAMSIZE;
static SFORMAT StateRegs[]=
{
{&IRQa, 1, "IRQA"},
{&IRQCount, 4, "IRQCOUNT"},
{reg, 16, "REGS"},
{0}
};
static void Sync(void)
{
setchr1(0x0000,reg[0]&0xfe);
setchr1(0x0400,reg[1]|1);
setchr1(0x0800,reg[2]&0xfe);
setchr1(0x0c00,reg[3]|1);
setchr1(0x1000,reg[4]);
setchr1(0x1400,reg[5]);
setchr1(0x1800,reg[6]);
setchr1(0x1c00,reg[7]);
setprg8r(0x10,0x6000,0);
setprg8(0x8000,(reg[0x8]&0xf)|0x10);
setprg8(0xA000,(reg[0x9]&0x1f));
setprg8(0xC000,(reg[0xa]&0x1f));
setprg8(0xE000,(reg[0xb]&0xf)|0x10);
setmirror((reg[0xc]&1)^1);
}
static DECLFW(M106Write)
{
A&=0xF;
switch(A)
{
case 0xD: IRQa=0; IRQCount=0; X6502_IRQEnd(FCEU_IQEXT); break;
case 0xE: IRQCount=(IRQCount&0xFF00)|V; break;
case 0xF: IRQCount=(IRQCount&0x00FF)|(V<<8); IRQa=1; break;
default: reg[A]=V; Sync(); break;
}
}
static void M106Power(void)
{
reg[8]=reg[9]=reg[0xa]=reg[0xb]=-1;
Sync();
SetReadHandler(0x6000,0x7FFF,CartBR);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x6000,0x7FFF,CartBW);
SetWriteHandler(0x8000,0xFFFF,M106Write);
}
static void M106Reset(void)
{
}
static void M106Close(void)
{
if(WRAM)
FCEU_gfree(WRAM);
WRAM=NULL;
}
void M106CpuHook(int a)
{
if(IRQa)
{
IRQCount+=a;
if(IRQCount>0x10000)
{
X6502_IRQBegin(FCEU_IQEXT);
IRQa=0;
}
}
}
static void StateRestore(int version)
{
Sync();
}
void Mapper106_Init(CartInfo *info)
{
info->Reset=M106Reset;
info->Power=M106Power;
info->Close=M106Close;
MapIRQHook=M106CpuHook;
GameStateRestore=StateRestore;
WRAMSIZE=8192;
WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,62 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 reg;
static SFORMAT StateRegs[]=
{
{&reg, 1, "REG"},
{0}
};
static void Sync(void)
{
setprg8(0x6000,reg);
setprg32(0x8000,~0);
setchr8(0);
}
static DECLFW(M108Write)
{
reg=V;
Sync();
}
static void M108Power(void)
{
Sync();
SetReadHandler(0x6000,0x7FFF,CartBR);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8FFF,0x8FFF,M108Write);
}
static void StateRestore(int version)
{
Sync();
}
void Mapper108_Init(CartInfo *info)
{
info->Power=M108Power;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,94 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* NTDEC, ASDER games
*/
#include "mapinc.h"
static uint8 reg[8];
static uint8 mirror, cmd, bank;
static uint8 *WRAM=NULL;
static SFORMAT StateRegs[]=
{
{&cmd, 1, "CMD"},
{&mirror, 1, "MIRR"},
{&bank, 1, "BANK"},
{reg, 8, "REGS"},
{0}
};
static void Sync(void)
{
setmirror(mirror^1);
setprg8(0x8000,reg[0]);
setprg8(0xA000,reg[1]);
setchr2(0x0000,(reg[2]>>1));
setchr2(0x0800,(reg[3]>>1));
setchr1(0x1000,((bank&0x10)<<4)|reg[4]);
setchr1(0x1400,((bank&0x20)<<3)|reg[5]);
setchr1(0x1800,((bank&0x40)<<2)|reg[6]);
setchr1(0x1C00,((bank&0x80)<<1)|reg[7]);
}
static DECLFW(M112Write)
{
switch(A)
{
case 0xe000: mirror=V&1; Sync(); ;break;
case 0x8000: cmd=V&7; break;
case 0xa000: reg[cmd]=V; Sync(); break;
case 0xc000: bank=V; Sync(); break;
}
}
static void M112Close(void)
{
if(WRAM)
FCEU_gfree(WRAM);
WRAM = NULL;
}
static void M112Power(void)
{
bank=0;
setprg16(0xC000,~0);
setprg8r(0x10,0x6000,0);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,M112Write);
SetWriteHandler(0x4020,0x5FFF,M112Write);
SetReadHandler(0x6000,0x7FFF,CartBR);
SetWriteHandler(0x6000,0x7FFF,CartBW);
}
static void StateRestore(int version)
{
Sync();
}
void Mapper112_Init(CartInfo *info)
{
info->Power=M112Power;
info->Close=M112Close;
GameStateRestore=StateRestore;
WRAM=(uint8*)FCEU_gmalloc(8192);
SetupCartPRGMapping(0x10,WRAM,8192,1);
AddExState(WRAM, 8192, 0, "WRAM");
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,104 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2002 Xodnizel
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 prgreg[4], chrreg[8], mirror;
static uint8 IRQa, IRQCount, IRQLatch;
static SFORMAT StateRegs[]=
{
{&IRQa, 1, "IRQA"},
{&IRQCount, 1, "IRQC"},
{&IRQLatch, 1, "IRQL"},
{prgreg, 4, "PREGS"},
{chrreg, 8, "CREGS"},
{&mirror, 1, "MREG"},
{0}
};
static void Sync(void)
{
int i;
setprg8(0x8000,prgreg[0]);
setprg8(0xa000,prgreg[1]);
setprg8(0xc000,prgreg[2]);
setprg8(0xe000,prgreg[3]);
for(i=0; i<8; i++)
setchr1(i<<10,chrreg[i]);
setmirror(mirror^1);
}
static DECLFW(M117Write)
{
if(A<0x8004)
{
prgreg[A&3]=V;
Sync();
}
else if((A>=0xA000)&&(A<=0xA007))
{
chrreg[A&7]=V;
Sync();
}
else switch(A)
{
case 0xc001: IRQLatch=V; break;
case 0xc003: IRQCount=IRQLatch; IRQa|=2; break;
case 0xe000: IRQa&=~1; IRQa|=V&1; X6502_IRQEnd(FCEU_IQEXT); break;
case 0xc002: X6502_IRQEnd(FCEU_IQEXT); break;
case 0xd000: mirror=V&1;
}
}
static void M117Power(void)
{
prgreg[0]=~3; prgreg[1]=~2; prgreg[2]=~1; prgreg[3]=~0;
Sync();
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,M117Write);
}
static void M117IRQHook(void)
{
if(IRQa==3&&IRQCount)
{
IRQCount--;
if(!IRQCount)
{
IRQa&=1;
X6502_IRQBegin(FCEU_IQEXT);
}
}
}
static void StateRestore(int version)
{
Sync();
}
void Mapper117_Init(CartInfo *info)
{
info->Power=M117Power;
GameHBIRQHook=M117IRQHook;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -1,53 +1,66 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2002 Xodnizel
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static DECLFW(Mapper235_write)
{
uint32 m;
int z;
if(A&0x400)
onemir(0);
else
setmirror(((A>>13)&1)^1);
m=A&0x1f;
z=(A>>8)&3;
if(A&0x800)
{
setprg16r(0x10|z,0x8000,(m<<1)|((A>>12)&1));
setprg16r(0x10|z,0xC000,(m<<1)|((A>>12)&1));
}
else
setprg32r(0x10|z,0x8000,m);
}
void Mapper235_init(void)
{
/* Fixme: Possible crashy bug if header is bad. */
SetupCartPRGMapping(0x10,PRGptr[0],1024*1024,0);
SetupCartPRGMapping(0x12,PRGptr[0]+1024*1024,1024,0);
setprg32r(0x10,0x8000,0);
SetReadHandler(0x8000,0xffff,CartBROB);
SetWriteHandler(0x8000,0xffff,Mapper235_write);
}
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 reg;
static SFORMAT StateRegs[]=
{
{&reg, 1, "REG"},
{0}
};
static void Sync(void)
{
setprg8(0x6000,reg);
setprg32(0x8000,2);
setchr8(0);
}
static DECLFW(M120Write)
{
if(A==0x41FF)
{
reg=V&7;
Sync();
}
}
static void M120Power(void)
{
reg=0;
Sync();
SetReadHandler(0x6000,0x7FFF,CartBR);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x4100,0x5FFF,M120Write);
}
static void StateRestore(int version)
{
Sync();
}
void Mapper120_Init(CartInfo *info)
{
info->Power=M120Power;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,91 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007-2008 Mad Dumper, CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* Panda prince pirate.
* MK4, MK6, A9711 board, MAPPER 187 the same!
* UNL6035052_Init seems to be the same too, but with prot array in reverse
*/
#include "mapinc.h"
#include "mmc3.h"
static uint8 readbyte = 0;
static DECLFW(M121Write)
{
// FCEU_printf("write: %04x:%04x\n",A&0xE003,V);
if((A&0xF003)==0x8003)
{
// FCEU_printf(" prot write");
// FCEU_printf("write: %04x:%04x\n",A,V);
if (V==0xAB) setprg8(0xE000,7);
else if(V==0x26) setprg8(0xE000,8);
// else if(V==0x26) setprg8(0xE000,1); // MK3
// else if(V==0x26) setprg8(0xE000,0x15); // sonic 3D blast, 8003 - command (0x26), 8001 - data 0x2A (<<1 = 0x15)
else if(V==0xFF) setprg8(0xE000,9);
else if(V==0x28) setprg8(0xC000,0xC);
else if(V==0xEC) setprg8(0xE000,0xD);
// else if(V==0xEC) setprg8(0xE000,0xC);//MK3
else if(V==0xEF) setprg8(0xE000,0xD); // damn mess, need real hardware to figure out bankswitching
else if(V==0x2A) setprg8(0xA000,0x0E);
// else if(V==0x2A) setprg8(0xE000,0x0C); // MK3
else if(V==0x20) setprg8(0xE000,0x13);
else if(V==0x29) setprg8(0xE000,0x1B);
else
{
// FCEU_printf(" unknown");
FixMMC3PRG(MMC3_cmd);
MMC3_CMDWrite(A,V);
}
// FCEU_printf("\n");
}
else
{
// FixMMC3PRG(MMC3_cmd);
MMC3_CMDWrite(A,V);
}
}
static uint8 prot_array[16] = { 0x83, 0x83, 0x42, 0x00 };
static DECLFW(M121LoWrite)
{
EXPREGS[0] = prot_array[V&3]; // 0x100 bit in address seems to be switch arrays 0, 2, 2, 3 (Contra Fighter)
// FCEU_printf("write: %04x:%04x\n",A,V);
}
static DECLFR(M121Read)
{
// FCEU_printf("read: %04x\n",A);
return EXPREGS[0];
}
static void M121Power(void)
{
GenMMC3Power();
// Write_IRQFM(0x4017,0x40);
SetReadHandler(0x5000,0x5FFF,M121Read);
SetWriteHandler(0x5000,0x5FFF,M121LoWrite);
SetWriteHandler(0x8000,0x9FFF,M121Write);
}
void Mapper121_Init(CartInfo *info)
{
GenMMC3_Init(info, 128, 256, 8, 0);
info->Power=M121Power;
AddExState(EXPREGS, 2, 0, "EXPR");
}

View File

@ -0,0 +1,119 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2006 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "mapinc.h"
static uint16 latchea;
static uint8 latched;
static uint8 *WRAM=NULL;
static uint32 WRAMSIZE;
static SFORMAT StateRegs[]=
{
{&latchea, 2, "LATCHEA"},
{&latched, 1, "LATCHED"},
{0}
};
static void Sync(void)
{
int i;
setmirror(((latched>>6)&1)^1);
switch(latchea)
{
case 0x8000:
for(i=0;i<4;i++)
setprg8(0x8000+(i<<13),(((latched&0x7F)<<1)+i)^(latched>>7));
break;
case 0x8002:
for(i=0;i<4;i++)
setprg8(0x8000+(i<<13),((latched&0x7F)<<1)+(latched>>7));
break;
case 0x8001:
case 0x8003:
for(i=0;i<4;i++)
{
unsigned int b;
b=latched&0x7F;
if(i>=2 && !(latchea&0x2))
i=0x7F;
setprg8(0x8000+(i<<13),(i&1)+((b<<1)^(latched>>7)));
}
break;
}
}
static DECLFW(M15Write)
{
latchea=A;
latched=V;
Sync();
}
static void StateRestore(int version)
{
Sync();
}
static void M15Power(void)
{
latchea=0x8000;
latched=0;
setchr8(0);
setprg8r(0x10,0x6000,0);
SetReadHandler(0x6000,0x7FFF,CartBR);
SetWriteHandler(0x6000,0x7FFF,CartBW);
SetWriteHandler(0x8000,0xFFFF,M15Write);
SetReadHandler(0x8000,0xFFFF,CartBR);
Sync();
}
static void M15Reset(void)
{
latchea=0x8000;
latched=0;
Sync();
}
static void M15Close(void)
{
if(WRAM)
FCEU_gfree(WRAM);
WRAM=NULL;
}
void Mapper15_Init(CartInfo *info)
{
info->Power=M15Power;
info->Reset=M15Reset;
info->Close=M15Close;
GameStateRestore=StateRestore;
WRAMSIZE=8192;
WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
if(info->battery)
{
info->SaveGame[0]=WRAM;
info->SaveGameLen[0]=WRAMSIZE;
}
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -1,7 +1,7 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2002 Xodnizel
* Copyright (C) 2002 Xodnizel 2006 CaH4e3
*
* 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
@ -20,11 +20,13 @@
#include "mapinc.h"
static uint8 cmd;
static uint8 cmd, laststrobe, trigger;
static uint8 DRegs[8];
static SFORMAT StateRegs[]=
{
{&cmd, 1, "CMD"},
{&laststrobe, 1, "STB"},
{&trigger, 1, "TRG"},
{DRegs, 8, "DREG"},
{0}
};
@ -32,7 +34,6 @@ static SFORMAT StateRegs[]=
static void Sync(void)
{
setprg32(0x8000,(DRegs[0]<<4)|(DRegs[1]&0xF));
setchr8(0);
}
static void StateRestore(int version)
@ -40,22 +41,46 @@ static void StateRestore(int version)
Sync();
}
static DECLFR(ReadLow)
{
switch (A&0x7700)
{
case 0x5100: return DRegs[2]; break;
case 0x5500: if(trigger)
return DRegs[2];
else
return 0;
}
return 4;
}
static DECLFW(Write)
{
switch (A&0x7300)
{
case 0x5100: DRegs[0]=V; Sync(); break;
case 0x5000: DRegs[1]=V; Sync(); break;
case 0x5300: DRegs[2]=V; break;
}
}
static DECLFW(Write2)
{
// FCEU_printf("bs %04x %02x\n",A,V);
if(A==0x5101)
{
if(laststrobe&&!V)
{
trigger^=1;
}
laststrobe=V;
}else if(A==0x5100&&V==6) //damn thoose protected games
setprg32(0x8000,3);
else
switch (A&0x7300)
{
case 0x5200: DRegs[0]=V; Sync(); break;
case 0x5000: DRegs[1]=V; Sync(); break;
case 0x5000: DRegs[1]=V; Sync(); if(!(DRegs[1]&0x80)&&(scanline<128)) setchr8(0); break;
case 0x5300: DRegs[2]=V; break;
}
}
@ -79,25 +104,39 @@ static void Power(void)
SetWriteHandler(0x4020,0x5FFF,Write);
SetReadHandler(0x6000,0x7FFF,AWRAM);
SetWriteHandler(0x6000,0x7FFF,BWRAM);
setchr8(0);
Sync();
}
static void M163HB(void)
{
if(scanline==127&&DRegs[1]&0x80)
setchr4(0x0000,1);
if(DRegs[1]&0x80)
{
if(scanline==239)
{
setchr4(0x0000,0);
setchr4(0x1000,0);
}
else if(scanline==127)
{
setchr4(0x0000,1);
setchr4(0x1000,1);
}
}
}
static void Power2(void)
{
memset(DRegs,0,8);
DRegs[1]=0xFF;
laststrobe=1;
cmd=0;
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x4020,0x5FFF,Write2);
SetReadHandler(0x6000,0x7FFF,AWRAM);
SetWriteHandler(0x6000,0x7FFF,BWRAM);
SetReadHandler(0x5000,0x5FFF,ReadLow);
setchr8(0);
Sync();
}
@ -114,4 +153,5 @@ void Mapper163_Init(CartInfo *info)
GameHBIRQHook=M163HB;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
AddExState(WRAM, 8192, 0, "WRAM");
}

View File

@ -0,0 +1,88 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 reg, delay, mirr;
static SFORMAT StateRegs[]=
{
{&reg, 1, "REG"},
{&mirr, 1, "MIRR"},
{0}
};
static void Sync(void)
{
setchr8(reg);
if(!delay)
{
setprg16(0x8000,reg);
setprg8(0xC000,reg << 1);
}
setprg8(0xE000,(reg << 1) + 1);
setmirror(((mirr&4)>>2)^1);
}
static DECLFW(M175Write1)
{
mirr = V;
delay = 1;
Sync();
}
static DECLFW(M175Write2)
{
reg = V & 0x0F;
delay = 1;
Sync();
}
static DECLFR(M175Read)
{
if(A==0xFFFC)
{
delay = 0;
Sync();
}
return CartBR(A);
}
static void M175Power(void)
{
reg = mirr = delay = 0;
SetReadHandler(0x8000,0xFFFF,M175Read);
SetWriteHandler(0x8000,0x8000,M175Write1);
SetWriteHandler(0xA000,0xA000,M175Write2);
Sync();
}
static void StateRestore(int version)
{
Sync();
}
void Mapper175_Init(CartInfo *info)
{
info->Power=M175Power;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,89 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 prg, chr;
static uint8 *WRAM=NULL;
static uint32 WRAMSIZE;
static SFORMAT StateRegs[]=
{
{&prg, 1, "PRG"},
{&chr, 1, "CHR"},
{0}
};
static void Sync(void)
{
setprg8r(0x10,0x6000,0);
setprg32(0x8000,prg>>1);
setchr8(chr);
}
static DECLFW(M176Write1)
{
prg = V;
Sync();
}
static DECLFW(M176Write2)
{
chr = V;
Sync();
}
static void M176Power(void)
{
prg = ~0;
SetReadHandler(0x6000,0x7fff,CartBR);
SetWriteHandler(0x6000,0x7fff,CartBW);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x5ff1,0x5ff1,M176Write1);
SetWriteHandler(0x5ff2,0x5ff2,M176Write2);
Sync();
}
static void M176Close(void)
{
if(WRAM)
FCEU_gfree(WRAM);
WRAM=NULL;
}
static void StateRestore(int version)
{
Sync();
}
void Mapper176_Init(CartInfo *info)
{
info->Power=M176Power;
info->Close=M176Close;
GameStateRestore=StateRestore;
WRAMSIZE=8192;
WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,87 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 reg;
static uint8 *WRAM=NULL;
static uint32 WRAMSIZE;
static SFORMAT StateRegs[]=
{
{&reg, 1, "REG"},
{0}
};
static void Sync(void)
{
setchr8(0);
setprg8r(0x10,0x6000,0);
setprg32(0x8000,reg&0x1f);
setmirror(((reg&0x20)>>5)^1);
}
static DECLFW(M177Write)
{
reg=V;
Sync();
}
static void M177Power(void)
{
reg=0;
Sync();
SetReadHandler(0x6000,0x7fff,CartBR);
SetWriteHandler(0x6000,0x7fff,CartBW);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,M177Write);
}
static void M177Close(void)
{
if(WRAM)
FCEU_gfree(WRAM);
WRAM=NULL;
}
static void StateRestore(int version)
{
Sync();
}
void Mapper177_Init(CartInfo *info)
{
info->Power=M177Power;
info->Close=M177Close;
GameStateRestore=StateRestore;
WRAMSIZE=8192;
WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if(info->battery)
{
info->SaveGame[0]=WRAM;
info->SaveGameLen[0]=WRAMSIZE;
}
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,101 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 reg[3];
static uint8 *WRAM=NULL;
static uint32 WRAMSIZE;
static SFORMAT StateRegs[]=
{
{reg, 3, "REGS"},
{0}
};
static void Sync(void)
{
setmirror(reg[0]);
setprg8r(0x10,0x6000,0);
setchr8(0);
setprg32(0x8000,(reg[1]+reg[2])&0xf);
}
static DECLFW(M178Write0)
{
reg[0]=(V&1)^1;
Sync();
}
static DECLFW(M178Write1)
{
reg[1]=(V>>1)&0xf;
Sync();
}
static DECLFW(M178Write2)
{
reg[2]=(V<<2)&0xf;
Sync();
}
static void M178Power(void)
{
reg[0]=1; reg[1]=0; reg[2]=0;
Sync();
SetReadHandler(0x6000,0x7FFF,CartBR);
SetWriteHandler(0x6000,0x7FFF,CartBW);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x4800,0x4800,M178Write0);
SetWriteHandler(0x4801,0x4801,M178Write1);
SetWriteHandler(0x4802,0x4802,M178Write2);
}
static void M178Close(void)
{
if(WRAM)
FCEU_gfree(WRAM);
WRAM=NULL;
}
static void StateRestore(int version)
{
Sync();
}
void Mapper178_Init(CartInfo *info)
{
info->Power=M178Power;
info->Close=M178Close;
GameStateRestore=StateRestore;
WRAMSIZE=8192;
WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
if(info->battery)
{
info->SaveGame[0]=WRAM;
info->SaveGameLen[0]=WRAMSIZE;
}
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,94 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 reg[2];
static uint8 *WRAM=NULL;
static uint32 WRAMSIZE;
static SFORMAT StateRegs[]=
{
{reg, 2, "REG"},
{0}
};
static void Sync(void)
{
setchr8(0);
setprg8r(0x10,0x6000,0);
setprg32(0x8000,reg[1]>>1);
setmirror((reg[0]&1)^1);
}
static DECLFW(M179Write)
{
if(A==0xa000) reg[0]=V;
Sync();
}
static DECLFW(M179WriteLo)
{
if(A==0x5ff1) reg[1]=V;
Sync();
}
static void M179Power(void)
{
reg[0]=reg[1]=0;
Sync();
SetWriteHandler(0x4020,0x5fff,M179WriteLo);
SetReadHandler(0x6000,0x7fff,CartBR);
SetWriteHandler(0x6000,0x7fff,CartBW);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,M179Write);
}
static void M179Close(void)
{
if(WRAM)
FCEU_gfree(WRAM);
WRAM=NULL;
}
static void StateRestore(int version)
{
Sync();
}
void Mapper179_Init(CartInfo *info)
{
info->Power=M179Power;
info->Close=M179Close;
GameStateRestore=StateRestore;
WRAMSIZE=8192;
WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if(info->battery)
{
info->SaveGame[0]=WRAM;
info->SaveGameLen[0]=WRAMSIZE;
}
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,117 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Gimmick Bootleg (VRC4 mapper)
*/
#include "mapinc.h"
static uint8 prg[4];
static uint8 chr[8];
static uint8 IRQCount;
static uint8 IRQPre;
static uint8 IRQa;
static SFORMAT StateRegs[]=
{
{prg, 4, "PRG"},
{chr, 8, "CHR"},
{&IRQCount, 1, "IRQCOUNT"},
{&IRQPre, 1, "IRQPRE"},
{&IRQa, 1, "IRQA"},
{0}
};
static void SyncPrg(void)
{
setprg8(0x6000,0);
setprg8(0x8000,prg[0]);
setprg8(0xA000,prg[1]);
setprg8(0xC000,prg[2]);
setprg8(0xE000,~0);
}
static void SyncChr(void)
{
int i;
for(i=0; i<8; i++)
setchr1(i<<10,chr[i]);
}
static void StateRestore(int version)
{
SyncPrg();
SyncChr();
}
static DECLFW(M183Write)
{
if(((A&0xF80C)>=0xB000)&&((A&0xF80C)<=0xE00C))
{
uint8 index=(((A>>11)-6)|(A>>3))&7;
chr[index]=(chr[index]&(0xF0>>(A&4)))|((V&0x0F)<<(A&4));
SyncChr();
}
else switch (A&0xF80C)
{
case 0x8800: prg[0]=V; SyncPrg(); break;
case 0xA800: prg[1]=V; SyncPrg(); break;
case 0xA000: prg[2]=V; SyncPrg(); break;
case 0x9800: switch (V&3)
{
case 0: setmirror(MI_V); break;
case 1: setmirror(MI_H); break;
case 2: setmirror(MI_0); break;
case 3: setmirror(MI_1); break;
}
break;
case 0xF000: IRQCount=((IRQCount&0xF0)|(V&0xF)); break;
case 0xF004: IRQCount=((IRQCount&0x0F)|((V&0xF)<<4)); break;
case 0xF008: IRQa=V; if(!V)IRQPre=0; X6502_IRQEnd(FCEU_IQEXT); break;
case 0xF00C: IRQPre=16; break;
}
}
static void M183IRQCounter(void)
{
if(IRQa)
{
IRQCount++;
if((IRQCount-IRQPre)==238)
X6502_IRQBegin(FCEU_IQEXT);
}
}
static void M183Power(void)
{
IRQPre=IRQCount=IRQa=0;
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,M183Write);
SetReadHandler(0x6000,0x7FFF,CartBR);
SyncPrg();
SyncChr();
}
void Mapper183_Init(CartInfo *info)
{
info->Power=M183Power;
GameHBIRQHook=M183IRQCounter;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,115 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "mapinc.h"
static uint8 *DummyCHR=NULL;
static uint8 datareg;
static void(*Sync)(void);
static SFORMAT StateRegs[]=
{
{&datareg, 1, "DREG"},
{0}
};
// on off
//1 0x0F, 0xF0 - Bird Week
//2 0x33, 0x00 - B-Wings
//3 0x11, 0x00 - Mighty Bomb Jack
//4 0x22, 0x20 - Sansuu 1 Nen, Sansuu 2 Nen
//5 0xFF, 0x00 - Sansuu 3 Nen
//6 0x21, 0x13 - Spy vs Spy
//7 0x20, 0x21 - Seicross
static void Sync185(void)
{
// little dirty eh? ;_)
if((datareg&3)&&(datareg!=0x13)) // 1, 2, 3, 4, 5, 6
setchr8(0);
else
setchr8r(0x10,0);
}
static void Sync181(void)
{
if(!(datareg&1)) // 7
setchr8(0);
else
setchr8r(0x10,0);
}
static DECLFW(MWrite)
{
datareg=V;
Sync();
}
static void MPower(void)
{
datareg=0;
Sync();
setprg16(0x8000,0);
setprg16(0xC000,~0);
SetWriteHandler(0x8000,0xFFFF,MWrite);
SetReadHandler(0x8000,0xFFFF,CartBR);
}
static void MClose(void)
{
if(DummyCHR)
FCEU_gfree(DummyCHR);
DummyCHR=NULL;
}
static void MRestore(int version)
{
Sync();
}
void Mapper185_Init(CartInfo *info)
{
int x;
Sync=Sync185;
info->Power=MPower;
info->Close=MClose;
GameStateRestore=MRestore;
DummyCHR=(uint8*)FCEU_gmalloc(8192);
for(x=0;x<8192;x++)
DummyCHR[x]=0xff;
SetupCartCHRMapping(0x10,DummyCHR,8192,0);
AddExState(StateRegs, ~0, 0, 0);
}
void Mapper181_Init(CartInfo *info)
{
int x;
Sync=Sync181;
info->Power=MPower;
info->Close=MClose;
GameStateRestore=MRestore;
DummyCHR=(uint8*)FCEU_gmalloc(8192);
for(x=0;x<8192;x++)
DummyCHR[x]=0xff;
SetupCartCHRMapping(0x10,DummyCHR,8192,0);
AddExState(StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,104 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Family Study Box by Fukutake Shoten
*/
#include "mapinc.h"
static uint8 SWRAM[2816];
static uint8 *WRAM=NULL;
static uint8 regs[4];
static SFORMAT StateRegs[]=
{
{regs, 4, "DREG"},
{SWRAM, 2816, "SWRAM"},
{0}
};
static void Sync(void)
{
setprg8r(0x10,0x6000,regs[0]>>6);
setprg16(0x8000,regs[1]);
setprg16(0xc000,0);
}
static DECLFW(M186Write)
{
if(A&0x4203) regs[A&3]=V;
Sync();
}
static DECLFR(M186Read)
{
switch(A)
{
case 0x4200: return 0x00; break;
case 0x4201: return 0x00; break;
case 0x4202: return 0x40; break;
case 0x4203: return 0x00; break;
}
return 0xFF;
}
static DECLFR(ASWRAM)
{
return(SWRAM[A-0x4400]);
}
static DECLFW(BSWRAM)
{
SWRAM[A-0x4400]=V;
}
static void M186Power(void)
{
setchr8(0);
SetReadHandler(0x6000,0xFFFF,CartBR);
SetWriteHandler(0x6000,0xFFFF,CartBW);
SetReadHandler(0x4200,0x43FF,M186Read);
SetWriteHandler(0x4200,0x43FF,M186Write);
SetReadHandler(0x4400,0x4EFF,ASWRAM);
SetWriteHandler(0x4400,0x4EFF,BSWRAM);
regs[0]=regs[1]=regs[2]=regs[3];
Sync();
}
static void M186Close(void)
{
if(WRAM)
FCEU_gfree(WRAM);
WRAM=NULL;
}
static void M186Restore(int version)
{
Sync();
}
void Mapper186_Init(CartInfo *info)
{
info->Power=M186Power;
info->Close=M186Close;
GameStateRestore=M186Restore;
WRAM=(uint8*)FCEU_gmalloc(32768);
SetupCartPRGMapping(0x10,WRAM,32768,1);
AddExState(WRAM, 32768, 0, "WRAM");
AddExState(StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,103 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
#include "mmc3.h"
static void M187CW(uint32 A, uint8 V)
{
if((A&0x1000)==((MMC3_cmd&0x80)<<5))
setchr1(A,V|0x100);
else
setchr1(A,V);
}
static void M187PW(uint32 A, uint8 V)
{
if(EXPREGS[0]&0x80)
{
uint8 bank=EXPREGS[0]&0x1F;
if(EXPREGS[0]&0x20)
setprg32(0x8000,bank>>2);
else
{
setprg16(0x8000,bank);
setprg16(0xC000,bank);
}
}
else
setprg8(A,V&0x3F);
}
static DECLFW(M187Write8000)
{
EXPREGS[2]=1;
MMC3_CMDWrite(A,V);
}
static DECLFW(M187Write8001)
{
if(EXPREGS[2])
MMC3_CMDWrite(A,V);
}
static DECLFW(M187Write8003)
{
EXPREGS[2]=0;
if(V==0x28)setprg8(0xC000,0x17);
else if(V==0x2A)setprg8(0xA000,0x0F);
}
static DECLFW(M187WriteLo)
{
EXPREGS[1]=V;
if(A==0x5000)
{
EXPREGS[0]=V;
FixMMC3PRG(MMC3_cmd);
}
}
static uint8 prot_data[4] = { 0x83, 0x83, 0x42, 0x00 };
static DECLFR(M187Read)
{
return prot_data[EXPREGS[1]&3];
}
static void M187Power(void)
{
EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=0;
GenMMC3Power();
SetReadHandler(0x5000,0x5FFF,M187Read);
SetWriteHandler(0x5000,0x5FFF,M187WriteLo);
SetWriteHandler(0x8000,0x8000,M187Write8000);
SetWriteHandler(0x8001,0x8001,M187Write8001);
SetWriteHandler(0x8003,0x8003,M187Write8003);
}
void Mapper187_Init(CartInfo *info)
{
GenMMC3_Init(info, 256, 256, 0, 0);
pwrap=M187PW;
cwrap=M187CW;
info->Power=M187Power;
AddExState(EXPREGS, 3, 0, "EXPR");
}

View File

@ -0,0 +1,48 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
#include "mmc3.h"
static void M189PW(uint32 A, uint8 V)
{
setprg32(0x8000,EXPREGS[0]&3);
}
static DECLFW(M189Write)
{
EXPREGS[0]=V|(V>>4); //actually, there is a two versions of 189 mapper with hi or lo bits bankswitching.
FixMMC3PRG(MMC3_cmd);
}
static void M189Power(void)
{
EXPREGS[0]=EXPREGS[1]=0;
GenMMC3Power();
SetWriteHandler(0x4120,0x7FFF,M189Write);
}
void Mapper189_Init(CartInfo *info)
{
GenMMC3_Init(info, 256, 256, 0, 0);
pwrap=M189PW;
info->Power=M189Power;
AddExState(EXPREGS, 2, 0, "EXPR");
}

View File

@ -26,6 +26,8 @@
#include "mapinc.h"
#include "mmc3.h"
static uint8 *CHRRAM=NULL; // and here too
static void M199PW(uint32 A, uint8 V)
{
setprg8(A,V);
@ -82,13 +84,13 @@ static void M199Power(void)
void Mapper199_Init(CartInfo *info)
{
int CHRRAMSize=1024*8;
GenMMC3_Init(info, 512, 256, 8, info->battery);
cwrap=M199CW;
pwrap=M199PW;
mwrap=M199MW;
info->Power=M199Power;
int CHRRAMSize=1024*8;
CHRRAM=(uint8*)malloc(CHRRAMSize);
CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
AddExState(EXPREGS, 4, 0, "EXPR");

View File

@ -1,139 +1,83 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2003 Xodnizel
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 PRGSel;
static uint8 PBuf[4],PSel;
static uint8 cmd;
static uint8 DRegs[8];
static uint32 count=0;
static uint32 last=0;
static DECLFW(M208Write1)
{
PRGSel=(V&0x1)|((V>>3)&0x2);
setprg32(0x8000,PRGSel);
}
static DECLFW(M208Write2)
{
static uint8 lut[256]={
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09,
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01,
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09,
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01,
0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08,
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00,
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08,
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00,
0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
if(A<=0x57FF) PSel=V;
else
PBuf[(A&0x03)]=V^lut[PSel];
}
static DECLFR(M208Read)
{
return(PBuf[(A&0x3)]);
}
static void Sync(void)
{
int x;
setchr2(0x0000,DRegs[0]>>1);
setchr2(0x0800,DRegs[1]>>1);
for(x=0;x<4;x++)
setchr1(0x1000+x*0x400,DRegs[2+x]);
}
static DECLFW(M208HWrite)
{
switch(A&0xe001)
{
case 0xc000:IRQLatch=IRQCount=V;break;
case 0xc001:IRQCount=IRQLatch;last=count=0;break;
case 0xe000:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break;
case 0xe001:IRQa=1;break;
case 0x8000:cmd=V;break;
case 0x8001:DRegs[cmd&7]=V;
Sync();
break;
}
}
static void M208Power(void)
{
PRGSel=3;
setprg32(0x8000,3);
SetWriteHandler(0x4800,0x4FFF,M208Write1);
SetWriteHandler(0x5000,0x5fff,M208Write2);
SetWriteHandler(0x8000,0xFFFF,M208HWrite);
SetReadHandler(0x5800,0x5FFF,M208Read);
SetReadHandler(0x8000,0xffff,CartBR);
}
static void sl(void)
{
if(IRQa)
{
if(IRQCount>=0)
{
IRQCount--;
if(IRQCount<0)
{
X6502_IRQBegin(FCEU_IQEXT);
}
}
}
}
static void FP_FASTAPASS(1) foo(uint32 A)
{
if((A&0x2000) && !(last&0x2000))
{
count++;
if(count==42)
{
sl();
count=0;
}
}
last=A;
}
void Mapper208_Init(CartInfo *info)
{
info->Power=M208Power;
//GameHBIRQHook=sl;
PPU_hook=foo;
}
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
#include "mmc3.h"
static uint8 lut[256]={
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09,
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01,
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09,
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01,
0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08,
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00,
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08,
0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00,
0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static void M208PW(uint32 A, uint8 V)
{
setprg32(0x8000,EXPREGS[5]);
}
static DECLFW(M208Write)
{
EXPREGS[5]=(V&0x1)|((V>>3)&0x2);
FixMMC3PRG(MMC3_cmd);
}
static DECLFW(M208ProtWrite)
{
if(A<=0x57FF)
EXPREGS[4]=V;
else
EXPREGS[(A&0x03)]=V^lut[EXPREGS[4]];
}
static DECLFR(M208ProtRead)
{
return(EXPREGS[(A&0x3)]);
}
static void M208Power(void)
{
EXPREGS[5]=3;
GenMMC3Power();
SetWriteHandler(0x4800,0x4FFF,M208Write);
SetWriteHandler(0x5000,0x5fff,M208ProtWrite);
SetReadHandler(0x5800,0x5FFF,M208ProtRead);
SetReadHandler(0x8000,0xffff,CartBR);
}
void Mapper208_Init(CartInfo *info)
{
GenMMC3_Init(info, 128, 256, 0, 0);
pwrap=M208PW;
info->Power=M208Power;
AddExState(EXPREGS, 6, 0, "EXPR");
}

View File

@ -0,0 +1,106 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* (VRC4 mapper)
*/
#include "mapinc.h"
static uint8 IRQCount;
static uint8 IRQa;
static uint8 prg_reg[2];
static uint8 chr_reg[8];
static uint8 mirr;
static SFORMAT StateRegs[]=
{
{&IRQCount, 1, "IRQC"},
{&IRQa, 1, "IRQA"},
{prg_reg, 2, "PRG"},
{chr_reg, 8, "CHR"},
{&mirr, 1, "MIRR"},
{0}
};
static void M222IRQ(void)
{
if(IRQa)
{
IRQCount++;
if(IRQCount>=238)
{
X6502_IRQBegin(FCEU_IQEXT);
// IRQa=0;
}
}
}
static void Sync(void)
{
int i;
setprg8(0x8000,prg_reg[0]);
setprg8(0xA000,prg_reg[1]);
for(i=0; i<8; i++)
setchr1(i<<10,chr_reg[i]);
setmirror(mirr^1);
}
static DECLFW(M222Write)
{
switch(A&0xF003)
{
case 0x8000: prg_reg[0]=V; break;
case 0x9000: mirr=V&1; break;
case 0xA000: prg_reg[1]=V; break;
case 0xB000: chr_reg[0]=V; break;
case 0xB002: chr_reg[1]=V; break;
case 0xC000: chr_reg[2]=V; break;
case 0xC002: chr_reg[3]=V; break;
case 0xD000: chr_reg[4]=V; break;
case 0xD002: chr_reg[5]=V; break;
case 0xE000: chr_reg[6]=V; break;
case 0xE002: chr_reg[7]=V; break;
// case 0xF000: FCEU_printf("%04x:%02x %d\n",A,V,scanline); IRQa=V; if(!V)IRQPre=0; X6502_IRQEnd(FCEU_IQEXT); break;
// / case 0xF001: FCEU_printf("%04x:%02x %d\n",A,V,scanline); IRQCount=V; break;
// case 0xF002: FCEU_printf("%04x:%02x %d\n",A,V,scanline); break;
// case 0xD001: IRQa=V; X6502_IRQEnd(FCEU_IQEXT); FCEU_printf("%04x:%02x %d\n",A,V,scanline); break;
// case 0xC001: IRQPre=16; FCEU_printf("%04x:%02x %d\n",A,V,scanline); break;
case 0xF000: IRQa=IRQCount=V; if(scanline<240) IRQCount-=8; else IRQCount+=4; X6502_IRQEnd(FCEU_IQEXT); break;
}
Sync();
}
static void M222Power(void)
{
setprg16(0xC000,~0);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,M222Write);
}
static void StateRestore(int version)
{
Sync();
}
void Mapper222_Init(CartInfo *info)
{
info->Power=M222Power;
GameHBIRQHook=M222IRQ;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,208 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 is23;
static uint16 IRQCount;
static uint8 IRQLatch,IRQa;
static uint8 prgreg[2];
static uint8 chrreg[8];
static uint8 regcmd, irqcmd, mirr, big_bank;
static uint16 acount=0;
static uint8 *WRAM=NULL;
static uint32 WRAMSIZE;
static SFORMAT StateRegs[]=
{
{prgreg, 2, "PRGREGS"},
{chrreg, 8, "CHRREGS"},
{&regcmd, 1, "REGCMD"},
{&irqcmd, 1, "IRQCMD"},
{&mirr, 1, "MIRR"},
{&big_bank, 1, "MIRR"},
{&IRQCount, 2, "IRQC"},
{&IRQLatch, 1, "IRQL"},
{&IRQa, 1, "IRQA"},
{0}
};
static void Sync(void)
{
if(regcmd&2)
{
setprg8(0xC000,prgreg[0]|big_bank);
setprg8(0x8000,((~1)&0x1F)|big_bank);
}
else
{
setprg8(0x8000,prgreg[0]|big_bank);
setprg8(0xC000,((~1)&0x1F)|big_bank);
}
setprg8(0xA000,prgreg[1]|big_bank);
setprg8(0xE000,((~0)&0x1F)|big_bank);
if(UNIFchrrama)
setchr8(0);
else
{
uint8 i;
for(i=0; i<8; i++)
setchr1(i<<10, chrreg[i]);
}
switch(mirr&0x3)
{
case 0: setmirror(MI_V); break;
case 1: setmirror(MI_H); break;
case 2: setmirror(MI_0); break;
case 3: setmirror(MI_1); break;
}
}
static DECLFW(M23Write)
{
// FCEU_printf("%04x:%04x\n",A,V);
A|=((A>>2)&0x3)|((A>>4)&0x3)|((A>>6)&0x3); // actually there is many-in-one mapper source, some pirate or
// licensed games use various address bits for registers
A&=0xF003;
if((A>=0xB000)&&(A<=0xE003))
{
if(UNIFchrrama)
big_bank=(V&8)<<2; // my personally many-in-one feature ;) just for support pirate cart 2-in-1
else
{
uint16 i=((A>>1)&1)|((A-0xB000)>>11);
chrreg[i]&=(0xF0)>>((A&1)<<2);
chrreg[i]|=(V&0xF)<<((A&1)<<2);
}
Sync();
}
else
switch(A&0xF003)
{
case 0x8000:
case 0x8001:
case 0x8002:
case 0x8003: if(is23)
prgreg[0]=V&0x1F;
Sync();
break;
case 0xA000:
case 0xA001:
case 0xA002:
case 0xA003: if(is23)
prgreg[1]=V&0x1F;
else
{
prgreg[0]=(V<<1)&0x1F;
prgreg[1]=((V<<1)&0x1F)|1;
}
Sync();
break;
case 0x9000:
case 0x9001: if(V!=0xFF) mirr=V; Sync(); break;
case 0x9002:
case 0x9003: regcmd=V; Sync(); break;
case 0xF000: X6502_IRQEnd(FCEU_IQEXT); IRQLatch&=0xF0; IRQLatch|=V&0xF; break;
case 0xF001: X6502_IRQEnd(FCEU_IQEXT); IRQLatch&=0x0F; IRQLatch|=V<<4; break;
case 0xF002: X6502_IRQEnd(FCEU_IQEXT); acount=0; IRQCount=IRQLatch; IRQa=V&2; irqcmd=V&1; break;
case 0xF003: X6502_IRQEnd(FCEU_IQEXT); IRQa=irqcmd; break;
}
}
static void M23Power(void)
{
big_bank=0x20;
Sync();
setprg8r(0x10,0x6000,0); // another many-in-one code, WRAM actually contain only WaiWaiWorld game
SetReadHandler(0x6000,0x7FFF,CartBR);
SetWriteHandler(0x6000,0x7FFF,CartBW);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,M23Write);
}
static void M23Reset(void)
{
}
void M23IRQHook(int a)
{
#define LCYCS 341
if(IRQa)
{
acount+=a*3;
if(acount>=LCYCS)
{
while(acount>=LCYCS)
{
acount-=LCYCS;
IRQCount++;
if(IRQCount&0x100)
{
X6502_IRQBegin(FCEU_IQEXT);
IRQCount=IRQLatch;
}
}
}
}
}
static void StateRestore(int version)
{
Sync();
}
static void M23Close(void)
{
if(WRAM)
FCEU_gfree(WRAM);
}
void Mapper23_Init(CartInfo *info)
{
is23=1;
info->Power=M23Power;
info->Close=M23Close;
MapIRQHook=M23IRQHook;
GameStateRestore=StateRestore;
WRAMSIZE=8192;
WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
AddExState(&StateRegs, ~0, 0, 0);
}
void UNLT230_Init(CartInfo *info)
{
is23=0;
info->Power=M23Power;
info->Close=M23Close;
MapIRQHook=M23IRQHook;
GameStateRestore=StateRestore;
WRAMSIZE=8192;
WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,70 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint16 cmdreg;
static SFORMAT StateRegs[]=
{
{&cmdreg, 2, "CMDREG"},
{0}
};
static void Sync(void)
{
if(cmdreg&0x400)
setmirror(MI_0);
else
setmirror(((cmdreg>>13)&1)^1);
if(cmdreg&0x800)
{
setprg16(0x8000,((cmdreg&0x300)>>3)|((cmdreg&0x1F)<<1)|((cmdreg>>12)&1));
setprg16(0xC000,((cmdreg&0x300)>>3)|((cmdreg&0x1F)<<1)|((cmdreg>>12)&1));
}
else
setprg32(0x8000,((cmdreg&0x300)>>4)|(cmdreg&0x1F));
}
static DECLFW(M235Write)
{
cmdreg=A;
Sync();
}
static void M235Power(void)
{
setchr8(0);
SetWriteHandler(0x8000,0xFFFF,M235Write);
SetReadHandler(0x8000,0xFFFF,CartBR);
cmdreg=0;
Sync();
}
static void M235Restore(int version)
{
Sync();
}
void Mapper235_Init(CartInfo *info)
{
info->Power=M235Power;
GameStateRestore=M235Restore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,110 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 reg[4], IRQa;
static int16 IRQCount, IRQPause;
static int16 Count = 0x0000;
static SFORMAT StateRegs[]=
{
{reg, 4, "REGS"},
{&IRQa, 1, "IRQA"},
{&IRQCount, 2, "IRQC"},
{0}
};
static void Sync(void)
{
setprg32(0x8000,0);
setchr8(0);
}
//#define Count 0x1800
#define Pause 0x010
static DECLFW(UNL3DBlockWrite)
{
switch(A)
{
//4800 32
//4900 37
//4a00 01
//4e00 18
case 0x4800: reg[0]=V; break;
case 0x4900: reg[1]=V; break;
case 0x4a00: reg[2]=V; break;
case 0x4e00: reg[3]=V; IRQCount=Count; IRQPause=Pause; IRQa=1; X6502_IRQEnd(FCEU_IQEXT); break;
}
}
static void UNL3DBlockPower(void)
{
Sync();
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x4800,0x4E00,UNL3DBlockWrite);
}
static void UNL3DBlockReset(void)
{
Count+=0x10;
FCEU_printf("Count=%04x\n",Count);
}
static void UNL3DBlockIRQHook(int a)
{
if(IRQa)
{
if(IRQCount>0)
{
IRQCount-=a;
}
else
{
if(IRQPause>0)
{
IRQPause-=a;
X6502_IRQBegin(FCEU_IQEXT);
}
else
{
IRQCount=Count;
IRQPause=Pause;
X6502_IRQEnd(FCEU_IQEXT);
}
}
}
}
static void StateRestore(int version)
{
Sync();
}
void UNL3DBlock_Init(CartInfo *info)
{
info->Power=UNL3DBlockPower;
info->Reset=UNL3DBlockReset;
MapIRQHook=UNL3DBlockIRQHook;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,70 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2008 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// actually cart ID is 811120-C, sorry ;) K-3094 - another ID
#include "mapinc.h"
#include "mmc3.h"
static uint8 reset_flag = 0;
static void BMC411120CCW(uint32 A, uint8 V)
{
setchr1(A,V|((EXPREGS[0]&3)<<7));
}
static void BMC411120CPW(uint32 A, uint8 V)
{
if(EXPREGS[0]&(8|reset_flag))
setprg32(0x8000,((EXPREGS[0]>>4)&3)|(0x0C));
else
setprg8(A,(V&0x0F)|((EXPREGS[0]&3)<<4));
}
static DECLFW(BMC411120CLoWrite)
{
EXPREGS[0] = A;
FixMMC3PRG(MMC3_cmd);
FixMMC3CHR(MMC3_cmd);
}
static void BMC411120CReset(void)
{
EXPREGS[0]=0;
reset_flag ^=4;
MMC3RegReset();
}
static void BMC411120CPower(void)
{
EXPREGS[0] = 0;
GenMMC3Power();
SetWriteHandler(0x6000,0x7FFF,BMC411120CLoWrite);
}
void BMC411120C_Init(CartInfo *info)
{
GenMMC3_Init(info, 128, 128, 8, 0);
pwrap=BMC411120CPW;
cwrap=BMC411120CCW;
info->Power=BMC411120CPower;
info->Reset=BMC411120CReset;
AddExState(EXPREGS, 1, 0, "EXPR");
}

View File

@ -0,0 +1,91 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2006 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 reg;
static uint8 IRQCount, IRQa;
static SFORMAT StateRegs[]=
{
{&IRQCount, 1, "IRQC"},
{&IRQa, 1, "IRQA"},
{&reg, 1, "REG"},
{0}
};
static void Sync(void)
{
setprg4(0x5000,16);
setprg8(0x6000,2);
setprg8(0x8000,1);
setprg8(0xa000,0);
setprg8(0xc000,reg);
setprg8(0xe000,9);
setchr8(0);
}
static DECLFW(M43Write)
{
int transo[8]={4,3,4,4,4,7,5,6};
switch(A&0xf1ff)
{
case 0x4022: reg=transo[V&7]; Sync(); break;
case 0x8122: IRQa=V&1; IRQCount=0; break;
}
}
static void M43Power(void)
{
reg=0;
Sync();
// SetReadHandler(0x5000,0x5fff,CartBR);
SetReadHandler(0x5000,0xffff,CartBR);
SetWriteHandler(0x4020,0xffff,M43Write);
}
static void M43Reset(void)
{
}
static void M43IRQHook(int a)
{
IRQCount+=a;
if(IRQa)
if(IRQCount>=4096)
{
IRQa=0;
X6502_IRQBegin(FCEU_IQEXT);
}
}
static void StateRestore(int version)
{
Sync();
}
void Mapper43_Init(CartInfo *info)
{
info->Reset=M43Reset;
info->Power=M43Power;
MapIRQHook=M43IRQHook;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,92 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "mapinc.h"
static uint8 prg_reg;
static uint8 chr_reg;
static uint8 hrd_flag;
static SFORMAT StateRegs[]=
{
{&hrd_flag, 1, "DIPSW"},
{&prg_reg, 1, "PRG"},
{&chr_reg, 1, "CHR"},
{0}
};
static void Sync(void)
{
if(prg_reg&0x80)
setprg32(0x8000,prg_reg>>6);
else
{
setprg16(0x8000,(prg_reg>>5)&3);
setprg16(0xC000,(prg_reg>>5)&3);
}
setmirror((prg_reg&8)>>3);
setchr8((chr_reg&3)|(prg_reg&7)|((prg_reg&0x10)>>1));
}
static DECLFR(M57Read)
{
return hrd_flag;
}
static DECLFW(M57Write)
{
if((A&0x8800)==0x8800)
prg_reg=V;
else
chr_reg=V;
Sync();
}
static void M57Power(void)
{
prg_reg=0;
chr_reg=0;
hrd_flag=0;
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,M57Write);
SetReadHandler(0x6000,0x6000,M57Read);
Sync();
}
static void M57Reset()
{
hrd_flag++;
hrd_flag&=3;
FCEU_printf("Select Register = %02x\n",hrd_flag);
}
static void StateRestore(int version)
{
Sync();
}
void Mapper57_Init(CartInfo *info)
{
info->Power=M57Power;
info->Reset=M57Reset;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,48 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
#include "mmc3.h"
static uint8 lut[4] = { 0x00, 0x02, 0x02, 0x03 };
static DECLFW(UNL6035052ProtWrite)
{
EXPREGS[0]=lut[V&3];
}
static DECLFR(UNL6035052ProtRead)
{
return EXPREGS[0];
}
static void UNL6035052Power(void)
{
GenMMC3Power();
SetWriteHandler(0x4020,0x7FFF,UNL6035052ProtWrite);
SetReadHandler(0x4020,0x7FFF,UNL6035052ProtRead);
}
void UNL6035052_Init(CartInfo *info)
{
GenMMC3_Init(info, 128, 256, 0, 0);
info->Power=UNL6035052Power;
AddExState(EXPREGS, 6, 0, "EXPR");
}

View File

@ -0,0 +1,178 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2006 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 chr_reg[4];
static uint8 kogame, prg_reg, nt1, nt2, mirr;
static uint8 *WRAM=NULL;
static uint32 WRAMSIZE, count;
static SFORMAT StateRegs[]=
{
{&nt1, 1, "NT1"},
{&nt2, 1, "NT2"},
{&mirr, 1, "MIRR"},
{&prg_reg, 1, "PRG"},
{&kogame, 1, "KOGAME"},
{&count, 4, "COUNT"},
{chr_reg, 4, "CHR"},
{0}
};
static void M68NTfix(void)
{
if((!UNIFchrrama)&&(mirr&0x10))
{
PPUNTARAM = 0;
switch(mirr&3)
{
case 0: vnapage[0]=vnapage[2]=CHRptr[0]+(((nt1|128)&CHRmask1[0])<<10);
vnapage[1]=vnapage[3]=CHRptr[0]+(((nt2|128)&CHRmask1[0])<<10);
break;
case 1: vnapage[0]=vnapage[1]=CHRptr[0]+(((nt1|128)&CHRmask1[0])<<10);
vnapage[2]=vnapage[3]=CHRptr[0]+(((nt2|128)&CHRmask1[0])<<10);
break;
case 2: vnapage[0]=vnapage[1]=vnapage[2]=vnapage[3]=CHRptr[0]+(((nt1|128)&CHRmask1[0])<<10);
break;
case 3: vnapage[0]=vnapage[1]=vnapage[2]=vnapage[3]=CHRptr[0]+(((nt2|128)&CHRmask1[0])<<10);
break;
}
}
else
switch(mirr&3)
{
case 0: setmirror(MI_V); break;
case 1: setmirror(MI_H); break;
case 2: setmirror(MI_0); break;
case 3: setmirror(MI_1); break;
}
}
static void Sync(void)
{
setchr2(0x0000,chr_reg[0]);
setchr2(0x0800,chr_reg[1]);
setchr2(0x1000,chr_reg[2]);
setchr2(0x1800,chr_reg[3]);
setprg8r(0x10,0x6000,0);
setprg16r((PRGptr[1])?kogame:0,0x8000,prg_reg);
setprg16(0xC000,~0);
}
static DECLFR(M68Read)
{
if(!(kogame&8))
{
count++;
if(count==1784)
setprg16r(0,0x8000,prg_reg);
}
return CartBR(A);
}
static DECLFW(M68WriteLo)
{
if(!V)
{
count = 0;
setprg16r((PRGptr[1])?kogame:0,0x8000,prg_reg);
}
}
static DECLFW(M68WriteCHR)
{
chr_reg[(A>>12)&3]=V;
Sync();
}
static DECLFW(M68WriteNT1)
{
nt1 = V;
M68NTfix();
}
static DECLFW(M68WriteNT2)
{
nt2 = V;
M68NTfix();
}
static DECLFW(M68WriteMIR)
{
mirr = V;
M68NTfix();
}
static DECLFW(M68WriteROM)
{
prg_reg = V&7;
kogame = ((V>>3)&1)^1;
Sync();
}
static void M68Power(void)
{
prg_reg = 0;
kogame = 0;
Sync();
M68NTfix();
SetReadHandler(0x6000,0x7FFF,CartBR);
SetReadHandler(0x8000,0xBFFF,M68Read);
SetReadHandler(0xC000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xBFFF,M68WriteCHR);
SetWriteHandler(0xC000,0xCFFF,M68WriteNT1);
SetWriteHandler(0xD000,0xDFFF,M68WriteNT2);
SetWriteHandler(0xE000,0xEFFF,M68WriteMIR);
SetWriteHandler(0xF000,0xFFFF,M68WriteROM);
SetWriteHandler(0x6000,0x6000,M68WriteLo);
SetWriteHandler(0x6001,0x7FFF,CartBW);
}
static void M68Close(void)
{
if(WRAM)
FCEU_gfree(WRAM);
WRAM=NULL;
}
static void StateRestore(int version)
{
Sync();
M68NTfix();
}
void Mapper68_Init(CartInfo *info)
{
info->Power=M68Power;
info->Close=M68Close;
GameStateRestore=StateRestore;
WRAMSIZE=8192;
WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
if(info->battery)
{
info->SaveGame[0]=WRAM;
info->SaveGameLen[0]=WRAMSIZE;
}
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,81 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint16 cmdreg;
static uint8 invalid_data;
static SFORMAT StateRegs[]=
{
{&invalid_data, 1, "INVD"},
{&cmdreg, 2, "CMDREG"},
{0}
};
static void Sync(void)
{
setprg16r((cmdreg&0x060)>>5,0x8000,(cmdreg&0x01C)>>2);
setprg16r((cmdreg&0x060)>>5,0xC000,(cmdreg&0x200)?(~0):0);
setmirror(((cmdreg&2)>>1)^1);
}
static DECLFR(UNL8157Read)
{
if(invalid_data&&cmdreg&0x100)
return 0xFF;
else
return CartBR(A);
}
static DECLFW(UNL8157Write)
{
cmdreg=A;
Sync();
}
static void UNL8157Power(void)
{
setchr8(0);
SetWriteHandler(0x8000,0xFFFF,UNL8157Write);
SetReadHandler(0x8000,0xFFFF,UNL8157Read);
cmdreg=0x200;
invalid_data=1;
Sync();
}
static void UNL8157Reset(void)
{
cmdreg=0;
invalid_data^=1;
Sync();
}
static void UNL8157Restore(int version)
{
Sync();
}
void UNL8157_Init(CartInfo *info)
{
info->Power=UNL8157Power;
info->Reset=UNL8157Reset;
GameStateRestore=UNL8157Restore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -1,153 +0,0 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2002 Xodnizel
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 cmdin;
static uint8 cmd;
static uint8 regs[8];
static uint8 master,chrm;
static int32 IRQCount,IRQa;
static void DoPRG(void)
{
if(master&0x80)
{
if(master&0x20)
{
setprg32(0x8000,(master&0xF)>>1);
}
else
{
setprg16(0x8000,master&0xF);
setprg16(0xC000,master&0xF);
}
}
else
{
setprg8(0xA000,regs[4]);
setprg8(0xE000,~0);
if(cmd&0x40)
{
setprg8(0xC000,regs[2]);
setprg8(0x8000,~1);
}
else
{
setprg8(0x8000,regs[2]);
setprg8(0xC000,~1);
}
}
}
static void DoCHR(void)
{
uint32 base=(cmd&0x80)<<5;
int orie=(chrm&0x4)<<6;
setchr2(0x0000^base,(orie|regs[0])>>1); //K
setchr2(0x0800^base,(orie|regs[3])>>1); //43
setchr1(0x1000,orie|regs[1]);
setchr1(0x1400,orie|regs[5]);
setchr1(0x1800,orie|regs[6]);
setchr1(0x1c00,orie|regs[7]);
}
static DECLFW(UNL8237Write)
{
switch(A&0xF000)
{
case 0xf000:IRQCount=V;break;
case 0xE000:X6502_IRQEnd(FCEU_IQEXT);break;
}
// if(A<0x8000)
// printf("$%04x:$%02x, %d\n",A&0xFFFF,V,scanline);
if(A==0x5000)
{
master=V;
DoPRG();
DoCHR();
}
else if(A==0x5001)
{
chrm=V;
DoCHR();
}
else
switch(A&0xE000)
{
case 0x8000:setmirror(((V|(V>>7))&1)^1);break;
case 0xa000:cmd=V;cmdin=1;DoPRG();DoCHR();break;
case 0xC000:if(!cmdin) break;
regs[cmd&7]=V;
DoPRG();
DoCHR();
cmdin=0;
break;
}
}
static void UNL8237Reset(void)
{
int x;
for(x=0;x<8;x++) regs[x]=0;
master=chrm=cmd=cmdin=IRQCount=IRQa=0;
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x5000,0xFFFF,UNL8237Write);
DoPRG();
DoCHR();
}
static void hooko(void)
{
if(IRQCount)
{
IRQCount--;
if(!IRQCount)
{
X6502_IRQBegin(FCEU_IQEXT);
//printf("IRQ: %d\n",scanline);
}
}
}
static void restoreo(int version)
{
DoPRG();
DoCHR();
}
void UNL8237_Init(CartInfo *info)
{
GameStateRestore=restoreo;
GameHBIRQHook=hooko;
info->Power=UNL8237Reset;
AddExState(regs, 8, 0, "REGS");
AddExState(&IRQCount, 4, 1, "IRQC");
AddExState(&IRQa, 1, 0, "IRQA");
AddExState(&master, 1, 0, "MAST");
AddExState(&chrm,1,0,"CHRM");
AddExState(&cmd,1,0,"CMD");
AddExState(&cmdin,1,0,"CMDI");
}

View File

@ -0,0 +1,93 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
#include "mmc3.h"
static uint8 cmdin;
static uint8 UNL8237_perm[8] = {0, 2, 6, 1, 7, 3, 4, 5};
static void UNL8237CW(uint32 A, uint8 V)
{
setchr1(A,((EXPREGS[1]&4)<<6)|V);
}
static void UNL8237PW(uint32 A, uint8 V)
{
if(EXPREGS[0]&0x80)
{
if(EXPREGS[0]&0x20)
setprg32(0x8000,(EXPREGS[0]&0xF)>>1);
else
{
setprg16(0x8000,(EXPREGS[0]&0x1F));
setprg16(0xC000,(EXPREGS[0]&0x1F));
}
}
else
setprg8(A,V&0x3F);
}
static DECLFW(UNL8237Write)
{
if((A&0xF000)==0xF000)
IRQCount=V;
else if((A&0xF000)==0xE000)
X6502_IRQEnd(FCEU_IQEXT);
else switch(A&0xE001)
{
case 0x8000: setmirror(((V|(V>>7))&1)^1); break;
case 0xA000: MMC3_CMDWrite(0x8000,(V&0xC0)|(UNL8237_perm[V&7])); cmdin=1; break;
case 0xC000: if(cmdin)
{
MMC3_CMDWrite(0x8001,V);
cmdin=0;
}
break;
}
}
static DECLFW(UNL8237ExWrite)
{
switch(A)
{
case 0x5000: EXPREGS[0]=V; FixMMC3PRG(MMC3_cmd); break;
case 0x5001: EXPREGS[1]=V; FixMMC3CHR(MMC3_cmd); break;
}
}
static void UNL8237Power(void)
{
IRQa=1;
EXPREGS[0]=EXPREGS[1]=0;
GenMMC3Power();
SetWriteHandler(0x8000,0xFFFF,UNL8237Write);
SetWriteHandler(0x5000,0x7FFF,UNL8237ExWrite);
}
void UNL8237_Init(CartInfo *info)
{
GenMMC3_Init(info, 256, 256, 0, 0);
cwrap=UNL8237CW;
pwrap=UNL8237PW;
info->Power=UNL8237Power;
AddExState(EXPREGS, 3, 0, "EXPR");
AddExState(&cmdin, 1, 0, "CMDIN");
}

View File

@ -0,0 +1,82 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2008 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// M-022 MMC3 based 830118C T-106 4M + 4M
#include "mapinc.h"
#include "mmc3.h"
static uint8 reset_flag = 0;
static void BMC830118CCW(uint32 A, uint8 V)
{
setchr1(A,(V&0x7F)|((EXPREGS[0]&0x0c)<<5));
}
static void BMC830118CPW(uint32 A, uint8 V)
{
if((EXPREGS[0]&0x0C)==0x0C)
{
if(A==0x8000)
{
setprg8(A,(V&0x0F)|((EXPREGS[0]&0x0c)<<2));
setprg8(0xC000,(V&0x0F)|0x32);
}
else if(A==0xA000)
{
setprg8(A,(V&0x0F)|((EXPREGS[0]&0x0c)<<2));
setprg8(0xE000,(V&0x0F)|0x32);
}
}
else
{
setprg8(A,(V&0x0F)|((EXPREGS[0]&0x0c)<<2));
}
}
static DECLFW(BMC830118CLoWrite)
{
EXPREGS[0] = V;
FixMMC3PRG(MMC3_cmd);
FixMMC3CHR(MMC3_cmd);
}
static void BMC830118CReset(void)
{
EXPREGS[0]=0;
MMC3RegReset();
}
static void BMC830118CPower(void)
{
EXPREGS[0] = 0;
GenMMC3Power();
SetWriteHandler(0x6800,0x68FF,BMC830118CLoWrite);
}
void BMC830118C_Init(CartInfo *info)
{
GenMMC3_Init(info, 128, 128, 8, 0);
pwrap=BMC830118CPW;
cwrap=BMC830118CCW;
info->Power=BMC830118CPower;
info->Reset=BMC830118CReset;
AddExState(EXPREGS, 1, 0, "EXPR");
}

View File

@ -0,0 +1,87 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 reg[8];
static uint8 mirror, cmd, is154;
static SFORMAT StateRegs[]=
{
{&cmd, 1, "CMD"},
{&mirror, 1, "MIRR"},
{reg, 8, "REGS"},
{0}
};
static void Sync(void)
{
setchr2(0x0000,reg[0]>>1);
setchr2(0x0800,reg[1]>>1);
setchr1(0x1000,reg[2]|0x40);
setchr1(0x1400,reg[3]|0x40);
setchr1(0x1800,reg[4]|0x40);
setchr1(0x1C00,reg[5]|0x40);
setprg8(0x8000,reg[6]);
setprg8(0xA000,reg[7]);
}
static void MSync(void)
{
if(is154)setmirror(MI_0+(mirror&1));
}
static DECLFW(M88Write)
{
switch(A&0x8001)
{
case 0x8000: cmd=V&7; mirror=V>>6; MSync(); break;
case 0x8001: reg[cmd]=V; Sync(); break;
}
}
static void M88Power(void)
{
setprg16(0xC000,~0);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,M88Write);
}
static void StateRestore(int version)
{
Sync();
MSync();
}
void Mapper88_Init(CartInfo *info)
{
is154=0;
info->Power=M88Power;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
void Mapper154_Init(CartInfo *info)
{
is154=1;
info->Power=M88Power;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,507 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2002 Xodnizel
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
//#define DEBUG90
// Mapper 090 is simpliest mapper hardware and have not extended nametable control and latched chr banks in 4k mode
// Mapper 209 much compicated hardware with decribed above features disabled by default and switchable by command
// Mapper 211 the same mapper 209 but with forced nametable control
static int is209;
static int is211;
static uint8 IRQMode; // from $c001
static uint8 IRQPre; // from $c004
static uint8 IRQPreSize; // from $c007
static uint8 IRQCount; // from $c005
static uint8 IRQXOR; // Loaded from $C006
static uint8 IRQa; // $c002, $c003, and $c000
static uint8 mul[2];
static uint8 regie;
static uint8 tkcom[4];
static uint8 prgb[4];
static uint8 chrlow[8];
static uint8 chrhigh[8];
static uint8 chr[2];
static uint16 names[4];
static uint8 tekker;
static SFORMAT Tek_StateRegs[]={
{&IRQMode, 1, "IRQMODE"},
{&IRQPre, 1, "IRQPRE"},
{&IRQPreSize, 1, "IRQPRESIZE"},
{&IRQCount, 1, "IRQC"},
{&IRQXOR, 1, "IRQXOR"},
{&IRQa, 1, "IRQa"},
{mul, 2, "MUL"},
{&regie, 1, "REGI"},
{tkcom, 4, "TKCO"},
{prgb, 4, "PRGB"},
{chr, 2, "CHRLATCH"},
{chrlow, 4, "CHRL"},
{chrhigh, 8, "CHRH"},
{&names[0], 2|FCEUSTATE_RLSB, "NMS0"},
{&names[1], 2|FCEUSTATE_RLSB, "NMS1"},
{&names[2], 2|FCEUSTATE_RLSB, "NMS2"},
{&names[3], 2|FCEUSTATE_RLSB, "NMS3"},
{&tekker, 1, "TEKR"},
{0}
};
static void mira(void)
{
if((tkcom[0]&0x20&&is209)||is211)
{
int x;
if(tkcom[0]&0x40) // Name tables are ROM-only
{
for(x=0;x<4;x++)
setntamem(CHRptr[0]+(((names[x])&CHRmask1[0])<<10),0,x);
}
else // Name tables can be RAM or ROM.
{
for(x=0;x<4;x++)
{
if((tkcom[1]&0x80)==(names[x]&0x80)) // RAM selected.
setntamem(NTARAM+((names[x]&0x1)<<10),1,x);
else
setntamem(CHRptr[0]+(((names[x])&CHRmask1[0])<<10),0,x);
}
}
}
else
{
switch(tkcom[1]&3)
{
case 0: setmirror(MI_V); break;
case 1: setmirror(MI_H); break;
case 2: setmirror(MI_0); break;
case 3: setmirror(MI_1); break;
}
}
}
static void tekprom(void)
{
uint32 bankmode=((tkcom[3]&6)<<5);
switch(tkcom[0]&7)
{
case 00: if(tkcom[0]&0x80)
setprg8(0x6000,(((prgb[3]<<2)+3)&0x3F)|bankmode);
setprg32(0x8000,0x0F|((tkcom[3]&6)<<3));
break;
case 01: if(tkcom[0]&0x80)
setprg8(0x6000,(((prgb[3]<<1)+1)&0x3F)|bankmode);
setprg16(0x8000,(prgb[1]&0x1F)|((tkcom[3]&6)<<4));
setprg16(0xC000,0x1F|((tkcom[3]&6)<<4));
break;
case 03: // bit reversion
case 02: if(tkcom[0]&0x80)
setprg8(0x6000,(prgb[3]&0x3F)|bankmode);
setprg8(0x8000,(prgb[0]&0x3F)|bankmode);
setprg8(0xa000,(prgb[1]&0x3F)|bankmode);
setprg8(0xc000,(prgb[2]&0x3F)|bankmode);
setprg8(0xe000,0x3F|bankmode);
break;
case 04: if(tkcom[0]&0x80)
setprg8(0x6000,(((prgb[3]<<2)+3)&0x3F)|bankmode);
setprg32(0x8000,(prgb[3]&0x0F)|((tkcom[3]&6)<<3));
break;
case 05: if(tkcom[0]&0x80)
setprg8(0x6000,(((prgb[3]<<1)+1)&0x3F)|bankmode);
setprg16(0x8000,(prgb[1]&0x1F)|((tkcom[3]&6)<<4));
setprg16(0xC000,(prgb[3]&0x1F)|((tkcom[3]&6)<<4));
break;
case 07: // bit reversion
case 06: if(tkcom[0]&0x80)
setprg8(0x6000,(prgb[3]&0x3F)|bankmode);
setprg8(0x8000,(prgb[0]&0x3F)|bankmode);
setprg8(0xa000,(prgb[1]&0x3F)|bankmode);
setprg8(0xc000,(prgb[2]&0x3F)|bankmode);
setprg8(0xe000,(prgb[3]&0x3F)|bankmode);
break;
}
}
static void tekvrom(void)
{
int x, bank=0, mask=0xFFFF;
if(!(tkcom[3]&0x20))
{
bank=(tkcom[3]&1)|((tkcom[3]&0x18)>>2);
switch (tkcom[0]&0x18)
{
case 0x00: bank<<=5; mask=0x1F; break;
case 0x08: bank<<=6; mask=0x3F; break;
case 0x10: bank<<=7; mask=0x7F; break;
case 0x18: bank<<=8; mask=0xFF; break;
}
}
switch(tkcom[0]&0x18)
{
case 0x00: // 8KB
setchr8(((chrlow[0]|(chrhigh[0]<<8))&mask)|bank);
break;
case 0x08: // 4KB
// for(x=0;x<8;x+=4)
// setchr4(x<<10,((chrlow[x]|(chrhigh[x]<<8))&mask)|bank);
setchr4(0x0000,((chrlow[chr[0]]|(chrhigh[chr[0]]<<8))&mask)|bank);
setchr4(0x1000,((chrlow[chr[1]]|(chrhigh[chr[1]]<<8))&mask)|bank);
break;
case 0x10: // 2KB
for(x=0;x<8;x+=2)
setchr2(x<<10,((chrlow[x]|(chrhigh[x]<<8))&mask)|bank);
break;
case 0x18: // 1KB
for(x=0;x<8;x++)
setchr1(x<<10,((chrlow[x]|(chrhigh[x]<<8))&mask)|bank);
break;
}
}
static DECLFW(M90TekWrite)
{
switch(A&0x5C03)
{
case 0x5800: mul[0]=V; break;
case 0x5801: mul[1]=V; break;
case 0x5803: regie=V; break;
}
}
static DECLFR(M90TekRead)
{
switch(A&0x5C03)
{
case 0x5800: return (mul[0]*mul[1]);
case 0x5801: return((mul[0]*mul[1])>>8);
case 0x5803: return (regie);
default: return tekker;
}
return(0xff);
}
static DECLFW(M90PRGWrite)
{
// FCEU_printf("bs %04x %02x\n",A,V);
prgb[A&3]=V;
tekprom();
}
static DECLFW(M90CHRlowWrite)
{
// FCEU_printf("bs %04x %02x\n",A,V);
chrlow[A&7]=V;
tekvrom();
}
static DECLFW(M90CHRhiWrite)
{
// FCEU_printf("bs %04x %02x\n",A,V);
chrhigh[A&7]=V;
tekvrom();
}
static DECLFW(M90NTWrite)
{
// FCEU_printf("bs %04x %02x\n",A,V);
if(A&4)
{
names[A&3]&=0x00FF;
names[A&3]|=V<<8;
}
else
{
names[A&3]&=0xFF00;
names[A&3]|=V;
}
mira();
}
static DECLFW(M90IRQWrite)
{
// FCEU_printf("bs %04x %02x\n",A,V);
switch(A&7)
{
case 00: //FCEU_printf("%s IRQ (C000)\n",V&1?"Enable":"Disable");
IRQa=V&1;if(!(V&1)) X6502_IRQEnd(FCEU_IQEXT);break;
case 02: //FCEU_printf("Disable IRQ (C002) scanline=%d\n", scanline);
IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break;
case 03: //FCEU_printf("Enable IRQ (C003) scanline=%d\n", scanline);
IRQa=1;break;
case 01: IRQMode=V;
// FCEU_printf("IRQ Count method: ");
// switch (IRQMode&3)
// {
// case 00: FCEU_printf("M2 cycles\n");break;
// case 01: FCEU_printf("PPU A12 toggles\n");break;
// case 02: FCEU_printf("PPU reads\n");break;
// case 03: FCEU_printf("Writes to CPU space\n");break;
// }
// FCEU_printf("Counter prescaler size: %s\n",(IRQMode&4)?"3 bits":"8 bits");
// FCEU_printf("Counter prescaler size adjust: %s\n",(IRQMode&8)?"Used C007":"Normal Operation");
// if((IRQMode>>6)==2) FCEU_printf("Counter Down\n");
// else if((IRQMode>>6)==1) FCEU_printf("Counter Up\n");
// else FCEU_printf("Counter Stopped\n");
break;
case 04: //FCEU_printf("Pre Counter Loaded and Xored wiht C006: %d\n",V^IRQXOR);
IRQPre=V^IRQXOR;break;
case 05: //FCEU_printf("Main Counter Loaded and Xored wiht C006: %d\n",V^IRQXOR);
IRQCount=V^IRQXOR;break;
case 06: //FCEU_printf("Xor Value: %d\n",V);
IRQXOR=V;break;
case 07: //if(!(IRQMode&8)) FCEU_printf("C001 is clear, no effect applied\n");
// else if(V==0xFF) FCEU_printf("Prescaler is changed for 12bits\n");
// else FCEU_printf("Counter Stopped\n");
IRQPreSize=V;break;
}
}
static DECLFW(M90ModeWrite)
{
// FCEU_printf("bs %04x %02x\n",A,V);
tkcom[A&3]=V;
tekprom();
tekvrom();
mira();
#ifdef DEBUG90
switch (A&3)
{
case 00: FCEU_printf("Main Control Register:\n");
FCEU_printf(" PGR Banking mode: %d\n",V&7);
FCEU_printf(" CHR Banking mode: %d\n",(V>>3)&3);
FCEU_printf(" 6000-7FFF addresses mapping: %s\n",(V&0x80)?"Yes":"No");
FCEU_printf(" Nametable control: %s\n",(V&0x20)?"Enabled":"Disabled");
if(V&0x20)
FCEU_printf(" Nametable can be: %s\n",(V&0x40)?"ROM Only":"RAM or ROM");
break;
case 01: FCEU_printf("Mirroring mode: ");
switch (V&3)
{
case 0: FCEU_printf("Vertical\n");break;
case 1: FCEU_printf("Horizontal\n");break;
case 2: FCEU_printf("Nametable 0 only\n");break;
case 3: FCEU_printf("Nametable 1 only\n");break;
}
FCEU_printf("Mirroring flag: %s\n",(V&0x80)?"On":"Off");
break;
case 02: if((((tkcom[0])>>5)&3)==1)
FCEU_printf("Nametable ROM/RAM select mode: %d\n",V>>7);
break;
case 03:
FCEU_printf("CHR Banking mode: %s\n",(V&0x20)?"Entire CHR ROM":"256Kb Switching mode");
if(!(V&0x20)) FCEU_printf("256K CHR bank number: %02x\n",(V&1)|((V&0x18)>>2));
FCEU_printf("512K PRG bank number: %d\n",(V&6)>>1);
FCEU_printf("CHR Bank mirroring: %s\n",(V&0x80)?"Swapped":"Normal operate");
}
#endif
}
static DECLFW(M90DummyWrite)
{
// FCEU_printf("bs %04x %02x\n",A,V);
}
static void CCL(void)
{
if((IRQMode>>6) == 1) // Count Up
{
IRQCount++;
if((IRQCount == 0) && IRQa)
{
X6502_IRQBegin(FCEU_IQEXT);
}
}
else if((IRQMode>>6) == 2) // Count down
{
IRQCount--;
if((IRQCount == 0xFF) && IRQa)
{
X6502_IRQBegin(FCEU_IQEXT);
}
}
}
static void ClockCounter(void)
{
uint8 premask;
if(IRQMode & 0x4)
premask = 0x7;
else
premask = 0xFF;
if((IRQMode>>6) == 1) // Count up
{
IRQPre++;
if((IRQPre & premask) == 0) CCL();
}
else if((IRQMode>>6) == 2) // Count down
{
IRQPre--;
if((IRQPre & premask) == premask) CCL();
}
}
void CPUWrap(int a)
{
int x;
if((IRQMode&3)==0) for(x=0;x<a;x++) ClockCounter();
}
static void SLWrap(void)
{
int x;
if((IRQMode&3)==1) for(x=0;x<8;x++) ClockCounter();
}
static uint32 lastread;
static void M90PPU(uint32 A)
{
if((IRQMode&3)==2)
{
if(lastread!=A)
{
ClockCounter();
ClockCounter();
}
lastread=A;
}
if(is209)
{
uint8 l,h;
h=A>>8;
if(h<0x20&&((h&0x0F)==0xF))
{
l=A&0xF0;
if(l==0xD0)
{
chr[(h&0x10)>>4]=((h&0x10)>>2);
tekvrom();
}
else if(l==0xE0)
{
chr[(h&0x10)>>4]=((h&0x10)>>2)|2;
tekvrom();
}
}
}
else
{
chr[0]=0;
chr[1]=4;
}
}
static void togglie()
{
tekker+=0x40;
tekker&=0xC0;
FCEU_printf("tekker=%02x\n",tekker);
memset(tkcom,0x00,sizeof(tkcom));
memset(prgb,0xff,sizeof(prgb));
tekprom();
tekvrom();
}
static void M90Restore(int version)
{
tekprom();
tekvrom();
mira();
}
static void M90Power(void)
{
SetWriteHandler(0x5000,0x5fff,M90TekWrite);
SetWriteHandler(0x8000,0x8ff0,M90PRGWrite);
SetWriteHandler(0x9000,0x9fff,M90CHRlowWrite);
SetWriteHandler(0xA000,0xAfff,M90CHRhiWrite);
SetWriteHandler(0xB000,0xBfff,M90NTWrite);
SetWriteHandler(0xC000,0xCfff,M90IRQWrite);
SetWriteHandler(0xD000,0xD5ff,M90ModeWrite);
SetWriteHandler(0xE000,0xFfff,M90DummyWrite);
SetReadHandler(0x5000,0x5fff,M90TekRead);
SetReadHandler(0x6000,0xffff,CartBR);
mul[0]=mul[1]=regie=0xFF;
memset(tkcom,0x00,sizeof(tkcom));
memset(prgb,0xff,sizeof(prgb));
memset(chrlow,0xff,sizeof(chrlow));
memset(chrhigh,0xff,sizeof(chrhigh));
memset(names,0x00,sizeof(names));
if(is211)
tekker=0xC0;
else
tekker=0x00;
tekprom();
tekvrom();
}
void Mapper90_Init(CartInfo *info)
{
is211=0;
is209=0;
info->Reset=togglie;
info->Power=M90Power;
PPU_hook=M90PPU;
MapIRQHook=CPUWrap;
GameHBIRQHook2=SLWrap;
GameStateRestore=M90Restore;
AddExState(Tek_StateRegs, ~0, 0, 0);
}
void Mapper209_Init(CartInfo *info)
{
is211=0;
is209=1;
info->Reset=togglie;
info->Power=M90Power;
PPU_hook=M90PPU;
MapIRQHook=CPUWrap;
GameHBIRQHook2=SLWrap;
GameStateRestore=M90Restore;
AddExState(Tek_StateRegs, ~0, 0, 0);
}
void Mapper211_Init(CartInfo *info)
{
is211=1;
info->Reset=togglie;
info->Power=M90Power;
PPU_hook=M90PPU;
MapIRQHook=CPUWrap;
GameHBIRQHook2=SLWrap;
GameStateRestore=M90Restore;
AddExState(Tek_StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,125 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2002 Xodnizel
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
#include "../ines.h"
static uint8 lastA;
static uint8 DRegs[8];
static uint8 cmd;
static uint8 MirCache[8];
static SFORMAT DB_StateRegs[]={
{DRegs, 8, "DREG"},
{&cmd, 1, "CMD"},
{&lastA, 1, "LAST"},
{0}
};
static void toot(void)
{
int x;
MirCache[0]=MirCache[1]=(DRegs[0]>>4)&1;
MirCache[2]=MirCache[3]=(DRegs[1]>>4)&1;
for(x=0;x<4;x++)
MirCache[4+x]=(DRegs[2+x]>>5)&1;
onemir(MirCache[lastA]);
}
static void Sync()
{
setchr2(0x0000,DRegs[0]&0x1F);
setchr2(0x0800,DRegs[1]&0x1F);
setchr1(0x1000,DRegs[2]&0x1F);
setchr1(0x1400,DRegs[3]&0x1F);
setchr1(0x1800,DRegs[4]&0x1F);
setchr1(0x1C00,DRegs[5]&0x1F);
setprg8(0x8000,DRegs[6]&0x1F);
setprg8(0xa000,DRegs[7]&0x1F);
toot();
}
static DECLFW(Mapper95_write)
{
switch(A&0xF001)
{
case 0x8000: cmd = V; break;
case 0x8001:
switch(cmd&0x07)
{
case 0: DRegs[0]=(V&0x3F)>>1; break;
case 1: DRegs[1]=(V&0x3F)>>1; break;
case 2: DRegs[2]=V&0x3F; break;
case 3: DRegs[3]=V&0x3F; break;
case 4: DRegs[4]=V&0x3F; break;
case 5: DRegs[5]=V&0x3F; break;
case 6: DRegs[6]=V&0x3F; break;
case 7: DRegs[7]=V&0x3F; break;
}
Sync();
}
}
static void dragonbust_ppu(uint32 A)
{
static int last=-1;
static uint8 z;
if(A>=0x2000) return;
A>>=10;
lastA=A;
z=MirCache[A];
if(z!=last)
{
onemir(z);
last=z;
}
}
static void DBPower(void)
{
memset(DRegs,0x3F,8);
DRegs[0]=DRegs[1]=0x1F;
Sync();
setprg8(0xc000,0x3E);
setprg8(0xe000,0x3F);
SetReadHandler(0x8000,0xffff,CartBR);
SetWriteHandler(0x8000,0xffff,Mapper95_write);
}
static void StateRestore(int version)
{
Sync();
}
void Mapper95_Init(CartInfo *info)
{
info->Power=DBPower;
AddExState(DB_StateRegs, ~0, 0, 0);
PPU_hook=dragonbust_ppu;
GameStateRestore=StateRestore;
}

View File

@ -0,0 +1,90 @@
my_list = Split("""
01-222.cpp
103.cpp
106.cpp
108.cpp
112.cpp
117.cpp
120.cpp
121.cpp
15.cpp
164.cpp
175.cpp
176.cpp
177.cpp
178.cpp
179.cpp
183.cpp
185.cpp
186.cpp
187.cpp
189.cpp
199.cpp
208.cpp
222.cpp
23.cpp
235.cpp
3d-block.cpp
411120-c.cpp
43.cpp
57.cpp
603-5052.cpp
68.cpp
8157.cpp
8237.cpp
830118C.cpp
88.cpp
90.cpp
95.cpp
a9711.cpp
a9746.cpp
addrlatch.cpp
ax5705.cpp
bandai.cpp
bmc13in1jy110.cpp
bmc42in1r.cpp
bmc64in1nr.cpp
bmc70in1.cpp
bonza.cpp
bs-5.cpp
copyfami_mmc3.cpp
dance.cpp
datalatch.cpp
deirom.cpp
dream.cpp
__dummy_mapper.cpp
edu2000.cpp
fk23c.cpp
ghostbusters63in1.cpp
gs-2004.cpp
gs-2013.cpp
h2288.cpp
karaoke.cpp
kof97.cpp
konami-qtai.cpp
ks7032.cpp
malee.cpp
mmc1.cpp
mmc3.cpp
mmc5.cpp
n-c22m.cpp
n106.cpp
n625092.cpp
novel.cpp
sachen.cpp
sc-127.cpp
sheroes.cpp
sl1632.cpp
smb2j.cpp
subor.cpp
super24.cpp
supervision.cpp
t-227-1.cpp
t-262.cpp
tengen.cpp
tf-1201.cpp
""")
for x in range(len(my_list)):
my_list[x] = 'boards/' + my_list[x]
Return('my_list')

View File

@ -0,0 +1,103 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2009 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 reg[8];
/*
static uint8 *WRAM=NULL;
static uint32 WRAMSIZE;
static uint8 *CHRRAM=NULL;
static uint32 CHRRAMSIZE;
*/
static SFORMAT StateRegs[]=
{
{reg, 8, "REGS"},
{0}
};
static void Sync(void)
{
}
static DECLFW(MNNNWrite)
{
}
static void MNNNPower(void)
{
// SetReadHandler(0x6000,0x7fff,CartBR);
// SetWriteHandler(0x6000,0x7fff,CartBW);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,MNNNWrite);
}
static void MNNNReset(void)
{
}
/*
static void MNNNClose(void)
{
if(WRAM)
FCEU_gfree(WRAM);
if(CHRRAM)
FCEU_gfree(CHRRAM);
WRAM=CHRRAM=NULL;
}
*/
static void MNNNIRQHook(void)
{
X6502_IRQBegin(FCEU_IQEXT);
}
static void StateRestore(int version)
{
Sync();
}
void MapperNNN_Init(CartInfo *info)
{
info->Reset=MNNNReset;
info->Power=MNNNPower;
// info->Close=MNNNClose;
GameHBIRQHook=MNNNIRQHook;
GameStateRestore=StateRestore;
/*
CHRRAMSIZE=8192;
CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSIZE);
SetupCartPRGMapping(0x10,CHRRAM,CHRRAMSIZE,1);
AddExState(CHRRAM, CHRRAMSIZE, 0, "WRAM");
*/
/*
WRAMSIZE=8192;
WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if(info->battery)
{
info->SaveGame[0]=WRAM;
info->SaveGameLen[0]=WRAMSIZE;
}
*/
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,78 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
#include "mmc3.h"
//static uint8 m_perm[8] = {0, 1, 0, 3, 0, 5, 6, 7};
static void UNLA9711PW(uint32 A, uint8 V)
{
if((EXPREGS[0]&0xFF) == 0x37)
{
setprg8(0x8000, 0x13);
setprg8(0xA000, 0x13);
setprg8(0xC000, 0x13);
setprg8(0xE000, 0x0);
// uint8 bank=EXPREGS[0]&0x1F;
// if(EXPREGS[0]&0x20)
// setprg32(0x8000,bank>>2);
// else
// {
// setprg16(0x8000,bank);
// setprg16(0xC000,bank);
// }
}
else
setprg8(A,V&0x3F);
}
//static DECLFW(UNLA9711Write8000)
//{
// FCEU_printf("bs %04x %02x\n",A,V);
// if(V&0x80)
// MMC3_CMDWrite(A,V);
// else
// MMC3_CMDWrite(A,m_perm[V&7]);
// if(V!=0x86) MMC3_CMDWrite(A,V);
//}
static DECLFW(UNLA9711WriteLo)
{
FCEU_printf("bs %04x %02x\n",A,V);
EXPREGS[0]=V;
FixMMC3PRG(MMC3_cmd);
}
static void UNLA9711Power(void)
{
EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=0;
GenMMC3Power();
SetWriteHandler(0x5000,0x5FFF,UNLA9711WriteLo);
// SetWriteHandler(0x8000,0xbfff,UNLA9711Write8000);
}
void UNLA9711_Init(CartInfo *info)
{
GenMMC3_Init(info, 256, 256, 0, 0);
pwrap=UNLA9711PW;
info->Power=UNLA9711Power;
AddExState(EXPREGS, 3, 0, "EXPR");
}

View File

@ -0,0 +1,186 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
#include "mapinc.h"
static uint8 chr_cmd, prg_cmd, mirror;
static uint8 chr_reg[6], prg_reg[4];
static SFORMAT StateRegs[]=
{
{&chr_cmd, 1, "CHRCMD"},
{&prg_cmd, 1, "PRGCMD"},
{&mirror, 1, "MIRR"},
{chr_reg, 6, "CREGS"},
{prg_reg, 4, "PREGS"},
{0}
};
static void Sync(void)
{
setprg8(0x8000, prg_reg[0]);
setprg8(0xA000, prg_reg[1]);
setprg8(0xC000, prg_reg[2]);
setprg8(0xE000, prg_reg[3]);
setchr2(0x0000, chr_reg[0]);
setchr2(0x0800, chr_reg[1]);
setchr1(0x1000, chr_reg[2]);
setchr1(0x1400, chr_reg[3]);
setchr1(0x1800, chr_reg[4]);
setchr1(0x1c00, chr_reg[5]);
setmirror(mirror);
}
static DECLFW(UNLA9746Write)
{
uint8 bits_rev;
// FCEU_printf("write raw %04x:%02x\n",A,V);
switch (A&0xE003)
{
// case 0xA000: mirror = V; break;
case 0x8000: chr_cmd = V; prg_cmd = 0; break;
case 0x8002: prg_cmd = V; chr_cmd = 0; break;
case 0x8001: bits_rev = ((V&0x20)>>5)|((V&0x10)>>3)|((V&0x08)>>1)|((V&0x04)<<1);
// if(prg_cmd>0x23)
// prg_reg[(0x26-prg_cmd)&3] = bits_rev;
switch(chr_cmd)
{
case 0x08: chr_reg[0] = (V << 3); break;
case 0x09: chr_reg[0] = chr_reg[0]|(V >> 2); break;
case 0x0e: chr_reg[1] = (V << 3); break;
case 0x0d: chr_reg[1] = chr_reg[1]|(V >> 2); break;
case 0x12: chr_reg[2] = (V << 4); break;
case 0x11: chr_reg[2] = chr_reg[2]|(V >> 1); FCEU_printf("Sync CHR 0x1000:%02x\n",chr_reg[2]); break;
case 0x16: chr_reg[3] = (V << 4); break;
case 0x15: chr_reg[3] = chr_reg[3]|(V >> 1); break;
case 0x1a: chr_reg[4] = (V << 4); break;
case 0x19: chr_reg[4] = chr_reg[4]|(V >> 1); break;
case 0x1e: chr_reg[5] = (V << 4); break;
case 0x1d: chr_reg[5] = chr_reg[5]|(V >> 1); break;
}
Sync();
break;
}
}
static void UNLA9746Power(void)
{
prg_reg[2]=~1;
prg_reg[3]=~0;
Sync();
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xbfff,UNLA9746Write);
}
static void StateRestore(int version)
{
Sync();
}
void UNLA9746_Init(CartInfo *info)
{
info->Power=UNLA9746Power;
AddExState(&StateRegs, ~0, 0, 0);
}
/**/
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
#include "mmc3.h"
static DECLFW(UNLA9746Write)
{
// FCEU_printf("write raw %04x:%02x\n",A,V);
switch (A&0xE003)
{
case 0x8000: EXPREGS[1]=V; EXPREGS[0]=0; break;
case 0x8002: EXPREGS[0]=V; EXPREGS[1]=0; break;
case 0x8001: {
uint8 bits_rev = ((V&0x20)>>5)|((V&0x10)>>3)|((V&0x08)>>1)|((V&0x04)<<1);
switch(EXPREGS[0])
{
case 0x26: setprg8(0x8000, bits_rev); break;
case 0x25: setprg8(0xA000, bits_rev); break;
case 0x24: setprg8(0xC000, bits_rev); break;
case 0x23: setprg8(0xE000, bits_rev); break;
}
switch(EXPREGS[1])
{
case 0x0a:
case 0x08: EXPREGS[2] = (V << 4); break;
case 0x09: setchr1(0x0000, EXPREGS[2]|(V >> 1)); break;
case 0x0b: setchr1(0x0400, EXPREGS[2]|(V >> 1)|1); break;
case 0x0c:
case 0x0e: EXPREGS[2] = (V << 4); break;
case 0x0d: setchr1(0x0800, EXPREGS[2]|(V >> 1)); break;
case 0x0f: setchr1(0x0c00, EXPREGS[2]|(V >> 1)|1); break;
case 0x10:
case 0x12: EXPREGS[2] = (V << 4); break;
case 0x11: setchr1(0x1000, EXPREGS[2]|(V >> 1)); break;
case 0x14:
case 0x16: EXPREGS[2] = (V << 4); break;
case 0x15: setchr1(0x1400, EXPREGS[2]|(V >> 1)); break;
case 0x18:
case 0x1a: EXPREGS[2] = (V << 4); break;
case 0x19: setchr1(0x1800, EXPREGS[2]|(V >> 1)); break;
case 0x1c:
case 0x1e: EXPREGS[2] = (V << 4); break;
case 0x1d: setchr1(0x1c00, EXPREGS[2]|(V >> 1)); break;
}
}
break;
}
}
static void UNLA9746Power(void)
{
GenMMC3Power();
SetWriteHandler(0x8000,0xbfff,UNLA9746Write);
}
void UNLA9746_Init(CartInfo *info)
{
GenMMC3_Init(info, 128, 256, 0, 0);
info->Power=UNLA9746Power;
AddExState(EXPREGS, 6, 0, "EXPR");
}
/**/

View File

@ -0,0 +1,172 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2006 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint16 latche, latcheinit;
static uint16 addrreg0, addrreg1;
static void(*WSync)(void);
static readfunc defread;
static DECLFW(LatchWrite)
{
FCEU_printf("%04x:%02x\n",A,V);
latche=A;
WSync();
}
static void LatchReset(void)
{
latche=latcheinit;
WSync();
}
static void LatchPower(void)
{
latche=latcheinit;
WSync();
SetReadHandler(0x8000,0xFFFF,defread);
SetWriteHandler(addrreg0,addrreg1,LatchWrite);
}
static void StateRestore(int version)
{
WSync();
}
static void Latch_Init(CartInfo *info, void (*proc)(void), readfunc func, uint16 init, uint16 adr0, uint16 adr1)
{
latcheinit=init;
addrreg0=adr0;
addrreg1=adr1;
WSync=proc;
if(func)
defread=func;
else
defread=CartBR;
info->Power=LatchPower;
info->Reset=LatchReset;
GameStateRestore=StateRestore;
AddExState(&latche, 2, 0, "LATC");
}
//------------------ UNLCC21 ---------------------------
static void UNLCC21Sync(void)
{
setprg32(0x8000,0);
setchr8(latche&1);
setmirror(MI_0+((latche&2)>>1));
}
void UNLCC21_Init(CartInfo *info)
{
Latch_Init(info, UNLCC21Sync, 0, 0, 0x8000, 0xFFFF);
}
//------------------ BMCD1038 ---------------------------
static uint8 dipswitch;
static void BMCD1038Sync(void)
{
if(latche&0x80)
{
setprg16(0x8000,(latche&0x70)>>4);
setprg16(0xC000,(latche&0x70)>>4);
}
else
setprg32(0x8000,(latche&0x60)>>5);
setchr8(latche&7);
setmirror(((latche&8)>>3)^1);
}
static DECLFR(BMCD1038Read)
{
if(latche&0x100)
return dipswitch;
else
return CartBR(A);
}
static void BMCD1038Reset(void)
{
dipswitch++;
dipswitch&=3;
}
void BMCD1038_Init(CartInfo *info)
{
Latch_Init(info, BMCD1038Sync, BMCD1038Read, 0, 0x8000, 0xFFFF);
info->Reset=BMCD1038Reset;
AddExState(&dipswitch, 1, 0, "DIPSW");
}
//------------------ Map 058 ---------------------------
static void BMCGK192Sync(void)
{
if(latche&0x40)
{
setprg16(0x8000,latche&7);
setprg16(0xC000,latche&7);
}
else
setprg32(0x8000,(latche>>1)&3);
setchr8((latche>>3)&7);
setmirror(((latche&0x80)>>7)^1);
}
void BMCGK192_Init(CartInfo *info)
{
Latch_Init(info, BMCGK192Sync, 0, 0, 0x8000, 0xFFFF);
}
//------------------ Map 200 ---------------------------
static void M200Sync(void)
{
// FCEU_printf("A\n");
setprg16(0x8000,latche&7);
setprg16(0xC000,latche&7);
setchr8(latche&7);
setmirror((latche&8)>>3);
}
void Mapper200_Init(CartInfo *info)
{
Latch_Init(info, M200Sync, 0, 0xff, 0x8000, 0xFFFF);
}
//------------------ 190in1 ---------------------------
static void BMC190in1Sync(void)
{
setprg16(0x8000,(latche>>2)&0x07);
setprg16(0xC000,(latche>>2)&0x07);
setchr8((latche>>2)&0x07);
setmirror((latche&1)^1);
}
void BMC190in1_Init(CartInfo *info)
{
Latch_Init(info, BMC190in1Sync, 0, 0, 0x8000, 0xFFFF);
}

View File

@ -0,0 +1,122 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Super Bros. Pocker Mali (VRC4 mapper)
*/
#include "mapinc.h"
static uint8 IRQCount;//, IRQPre;
static uint8 IRQa;
static uint8 prg_reg[2];
static uint8 chr_reg[8];
static uint8 mirr;
static SFORMAT StateRegs[]=
{
{&IRQCount, 1, "IRQC"},
{&IRQa, 1, "IRQA"},
{prg_reg, 2, "PRG"},
{chr_reg, 8, "CHR"},
{&mirr, 1, "MIRR"},
{0}
};
/*
static void UNLAX5705IRQ(void)
{
if(IRQa)
{
IRQCount++;
if(IRQCount>=238)
{
X6502_IRQBegin(FCEU_IQEXT);
// IRQa=0;
}
}
}*/
static void Sync(void)
{
int i;
setprg8(0x8000,prg_reg[0]);
setprg8(0xA000,prg_reg[1]);
setprg8(0xC000,~1);
setprg8(0xE000,~0);
for(i=0; i<8; i++)
setchr1(i<<10,chr_reg[i]);
setmirror(mirr^1);
}
static DECLFW(UNLAX5705Write)
{
// if((A>=0xA008)&&(A<=0xE003))
// {
// int ind=(((A>>11)-6)|(A&1))&7;
// int sar=((A&2)<<1);
// chr_reg[ind]=(chr_reg[ind]&(0xF0>>sar))|((V&0x0F)<<sar);
// SyncChr();
// }
// else
switch(A&0xF00F)
{
case 0x8000: prg_reg[0]=((V&2)<<2)|((V&8)>>2)|(V&5); break; // EPROM dump have mixed PRG and CHR banks, data lines to mapper seems to be mixed
case 0x8008: mirr=V&1; break;
case 0xA000: prg_reg[1]=((V&2)<<2)|((V&8)>>2)|(V&5); break;
case 0xA008: chr_reg[0]=(chr_reg[0]&0xF0)|(V&0x0F); break;
case 0xA009: chr_reg[0]=(chr_reg[0]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;
case 0xA00A: chr_reg[1]=(chr_reg[1]&0xF0)|(V&0x0F); break;
case 0xA00B: chr_reg[1]=(chr_reg[1]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;
case 0xC000: chr_reg[2]=(chr_reg[2]&0xF0)|(V&0x0F); break;
case 0xC001: chr_reg[2]=(chr_reg[2]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;
case 0xC002: chr_reg[3]=(chr_reg[3]&0xF0)|(V&0x0F); break;
case 0xC003: chr_reg[3]=(chr_reg[3]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;
case 0xC008: chr_reg[4]=(chr_reg[4]&0xF0)|(V&0x0F); break;
case 0xC009: chr_reg[4]=(chr_reg[4]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;
case 0xC00A: chr_reg[5]=(chr_reg[5]&0xF0)|(V&0x0F); break;
case 0xC00B: chr_reg[5]=(chr_reg[5]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;
case 0xE000: chr_reg[6]=(chr_reg[6]&0xF0)|(V&0x0F); break;
case 0xE001: chr_reg[6]=(chr_reg[6]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;
case 0xE002: chr_reg[7]=(chr_reg[7]&0xF0)|(V&0x0F); break;
case 0xE003: chr_reg[7]=(chr_reg[7]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;
// case 0x800A: X6502_IRQEnd(FCEU_IQEXT); IRQa=0; break;
// case 0xE00B: X6502_IRQEnd(FCEU_IQEXT); IRQa=IRQCount=V; /*if(scanline<240) IRQCount-=8; else IRQCount+=4;*/ break;
}
Sync();
}
static void UNLAX5705Power(void)
{
Sync();
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,UNLAX5705Write);
}
static void StateRestore(int version)
{
Sync();
}
void UNLAX5705_Init(CartInfo *info)
{
info->Power=UNLAX5705Power;
// GameHBIRQHook=UNLAX5705IRQ;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,164 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Bandai mappers
*
*/
#include "mapinc.h"
static uint8 reg[16], is153;
static uint8 IRQa;
static uint16 IRQCount, IRQLatch;
static uint8 *WRAM=NULL;
static uint32 WRAMSIZE;
static SFORMAT StateRegs[]=
{
{reg, 16, "REGS"},
{&IRQa, 1, "IRQA"},
{&IRQCount, 2, "IRQC"},
{&IRQLatch, 2, "IRQL"},
{0}
};
static void BandaiIRQHook(int a)
{
if(IRQa)
{
IRQCount -= a;
if(IRQCount<0)
{
X6502_IRQBegin(FCEU_IQEXT);
IRQa = 0;
IRQCount = 0xFFFF;
}
}
}
static void BandaiSync(void)
{
if(is153)
{
int base=(reg[0]&1)<<4;
if(!UNIFchrrama) // SD Gundam Gaiden - Knight Gundam Monogatari 2 - Hikari no Kishi (J) uses WRAM but have CHRROM too
{
int i;
for(i=0; i<8; i++) setchr1(i<<10,reg[i]);
}
else
setchr8(0);
setprg16(0x8000,(reg[8]&0x0F)|base);
setprg16(0xC000,0x0F|base);
}
else
{
int i;
for(i=0; i<8; i++) setchr1(i<<10,reg[i]);
setprg16(0x8000,reg[8]);
setprg16(0xC000,~0);
}
switch(reg[9])
{
case 0: setmirror(MI_V); break;
case 1: setmirror(MI_H); break;
case 2: setmirror(MI_0); break;
case 3: setmirror(MI_1); break;
}
}
static DECLFW(BandaiWrite)
{
A&=0x0F;
if(A<0x0A)
{
reg[A&0x0F]=V;
BandaiSync();
}
else
switch(A)
{
case 0x0A: X6502_IRQEnd(FCEU_IQEXT); IRQa=V&1; IRQCount=IRQLatch; break;
case 0x0B: IRQLatch&=0xFF00; IRQLatch|=V; break;
case 0x0C: IRQLatch&=0xFF; IRQLatch|=V<<8; break;
case 0x0D: break;// Serial EEPROM control port
}
}
static void BandaiPower(void)
{
BandaiSync();
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x6000,0xFFFF,BandaiWrite);
}
static void M153Power(void)
{
BandaiSync();
setprg8r(0x10,0x6000,0);
SetReadHandler(0x6000,0x7FFF,CartBR);
SetWriteHandler(0x6000,0x7FFF,CartBW);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,BandaiWrite);
}
static void M153Close(void)
{
if(WRAM)
FCEU_gfree(WRAM);
WRAM=NULL;
}
static void StateRestore(int version)
{
BandaiSync();
}
void Mapper16_Init(CartInfo *info)
{
is153=0;
info->Power=BandaiPower;
MapIRQHook=BandaiIRQHook;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
void Mapper153_Init(CartInfo *info)
{
is153=1;
info->Power=M153Power;
info->Close=M153Close;
MapIRQHook=BandaiIRQHook;
WRAMSIZE=8192;
WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if(info->battery)
{
info->SaveGame[0]=WRAM;
info->SaveGameLen[0]=WRAMSIZE;
}
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,103 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* BMC 42-in-1 reset switch
*/
#include "mapinc.h"
static uint8 bank_mode;
static uint8 bank_value;
static uint8 prgb[4];
static SFORMAT StateRegs[]=
{
{0}
};
static void Sync(void)
{
FCEU_printf("%02x: %02x %02x\n", bank_mode, bank_value, prgb[0]);
switch(bank_mode&7)
{
case 0:
setprg32(0x8000,bank_value&7); break;
case 1:
setprg16(0x8000,((8+(bank_value&7))>>1)+prgb[1]);
setprg16(0xC000,(bank_value&7)>>1);
case 4:
setprg32(0x8000,8+(bank_value&7)); break;
case 5:
setprg16(0x8000,((8+(bank_value&7))>>1)+prgb[1]);
setprg16(0xC000,((8+(bank_value&7))>>1)+prgb[3]);
case 2:
setprg8(0x8000,prgb[0]>>2);
setprg8(0xa000,prgb[1]);
setprg8(0xc000,prgb[2]);
setprg8(0xe000,~0);
break;
case 3:
setprg8(0x8000,prgb[0]);
setprg8(0xa000,prgb[1]);
setprg8(0xc000,prgb[2]);
setprg8(0xe000,prgb[3]);
break;
}
}
static DECLFW(BMC13in1JY110Write)
{
FCEU_printf("%04x:%04x\n",A,V);
switch(A)
{
case 0x8000:
case 0x8001:
case 0x8002:
case 0x8003: prgb[A&3]=V; break;
case 0xD000: bank_mode=V; break;
case 0xD001: setmirror(V&3);
case 0xD002: break;
case 0xD003: bank_value=V; break;
}
Sync();
}
static void BMC13in1JY110Power(void)
{
prgb[0]=prgb[1]=prgb[2]=prgb[3]=0;
bank_mode=0;
bank_value=0;
setprg32(0x8000,0);
setchr8(0);
SetWriteHandler(0x8000,0xFFFF,BMC13in1JY110Write);
SetReadHandler(0x8000,0xFFFF,CartBR);
}
static void StateRestore(int version)
{
Sync();
}
void BMC13in1JY110_Init(CartInfo *info)
{
info->Power=BMC13in1JY110Power;
AddExState(&StateRegs, ~0, 0, 0);
GameStateRestore=StateRestore;
}

View File

@ -0,0 +1,110 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* BMC 42-in-1 reset switch
*/
#include "mapinc.h"
extern uint32 ROM_size;
static uint8 hrd_sw;
static uint8 latche;
static SFORMAT StateRegs[]=
{
{&hrd_sw, 1, "DIPSW"},
{&latche, 1, "LATCHE"},
{&hrd_sw, 1, "HRDSW"},
{0}
};
static void Sync(void)
{
/* if(!(latche&0x02))
setprg32r(0,0x8000,(latche&0x3F)>>1);
else
{
setprg16r(0,0x8000,latche&0x3f);
setprg16r(0,0xC000,latche&0x3f);
}
*/
if(!(latche&0x20))
setprg32r(hrd_sw,0x8000,(latche>>1)&0x0f);
else
{
setprg16r(hrd_sw,0x8000,latche&0x1f);
setprg16r(hrd_sw,0xC000,latche&0x1f);
}
setmirror((latche>>6)&1);
}
static DECLFW(BMC42in1rWrite)
{
latche=V;
Sync();
}
static void BMC42in1rReset(void)
{
hrd_sw^=1;
Sync();
}
static void BMC42in1rPower(void)
{
latche=0;
hrd_sw=0;
setchr8(0);
Sync();
SetWriteHandler(0x8000,0xFFFF,BMC42in1rWrite);
SetReadHandler(0x8000,0xFFFF,CartBR);
}
static void StateRestore(int version)
{
Sync();
}
void BMC42in1r_Init(CartInfo *info)
{
info->Power=BMC42in1rPower;
info->Reset=BMC42in1rReset;
AddExState(&StateRegs, ~0, 0, 0);
GameStateRestore=StateRestore;
}
static void M226Power(void)
{
if(ROM_size==64)
SetupCartPRGMapping(1,PRGptr[0]+512*1024,512,0);
latche=0;
hrd_sw=0;
setchr8(0);
Sync();
SetWriteHandler(0x8000,0xFFFF,BMC42in1rWrite);
SetReadHandler(0x8000,0xFFFF,CartBR);
}
void Mapper226_Init(CartInfo *info)
{
info->Power=M226Power;
info->Reset=BMC42in1rReset;
AddExState(&StateRegs, ~0, 0, 0);
GameStateRestore=StateRestore;
}

View File

@ -0,0 +1,93 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* BMC 42-in-1 reset switch
*/
#include "mapinc.h"
static uint8 regs[4];
static SFORMAT StateRegs[]=
{
{regs, 4, "REGS"},
{0}
};
static void Sync(void)
{
if(regs[0]&0x80)
{
if(regs[1]&0x80)
setprg32(0x8000,regs[1]&0x1F);
else
{
int bank=((regs[1]&0x1f)<<1)|((regs[1]>>6)&1);
setprg16(0x8000,bank);
setprg16(0xC000,bank);
}
}
else
{
int bank=((regs[1]&0x1f)<<1)|((regs[1]>>6)&1);
setprg16(0xC000,bank);
}
if(regs[0]&0x20)
setmirror(MI_H);
else
setmirror(MI_V);
setchr8((regs[2]<<2)|((regs[0]>>1)&3));
}
static DECLFW(BMC64in1nrWriteLo)
{
regs[A&3]=V;
Sync();
}
static DECLFW(BMC64in1nrWriteHi)
{
regs[3]=V;
Sync();
}
static void BMC64in1nrPower(void)
{
regs[0]=0x80;
regs[1]=0x43;
regs[2]=regs[3]=0;
Sync();
SetWriteHandler(0x5000,0x5003,BMC64in1nrWriteLo);
SetWriteHandler(0x8000,0xFFFF,BMC64in1nrWriteHi);
SetReadHandler(0x8000,0xFFFF,CartBR);
}
static void StateRestore(int version)
{
Sync();
}
void BMC64in1nr_Init(CartInfo *info)
{
info->Power=BMC64in1nrPower;
AddExState(&StateRegs, ~0, 0, 0);
GameStateRestore=StateRestore;
}

View File

@ -0,0 +1,130 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 is_large_banks, hw_switch;
static uint8 large_bank;
static uint8 prg_bank;
static uint8 chr_bank;
static uint8 bank_mode;
static uint8 mirroring;
static SFORMAT StateRegs[]=
{
{&large_bank, 1, "LB"},
{&hw_switch, 1, "DIPSW"},
{&prg_bank, 1, "PRG"},
{&chr_bank, 1, "CHR"},
{&bank_mode, 1, "BM"},
{&mirroring, 1, "MIRR"},
{0}
};
static void Sync(void)
{
switch (bank_mode)
{
case 0x00:
case 0x10: setprg16(0x8000,large_bank|prg_bank);
setprg16(0xC000,large_bank|7);
break;
case 0x20: setprg32(0x8000,(large_bank|prg_bank)>>1);
break;
case 0x30: setprg16(0x8000,large_bank|prg_bank);
setprg16(0xC000,large_bank|prg_bank);
break;
}
setmirror(mirroring);
if(!is_large_banks)
setchr8(chr_bank);
}
static DECLFR(BMC70in1Read)
{
if(bank_mode==0x10)
// if(is_large_banks)
return CartBR((A&0xFFF0)|hw_switch);
// else
// return CartBR((A&0xFFF0)|hw_switch);
else
return CartBR(A);
}
static DECLFW(BMC70in1Write)
{
if(A&0x4000)
{
bank_mode=A&0x30;
prg_bank=A&7;
}
else
{
mirroring=((A&0x20)>>5)^1;
if(is_large_banks)
large_bank=(A&3)<<3;
else
chr_bank=A&7;
}
Sync();
}
static void BMC70in1Reset(void)
{
bank_mode=0;
large_bank=0;
Sync();
hw_switch++;
hw_switch&=0xf;
}
static void BMC70in1Power(void)
{
setchr8(0);
bank_mode=0;
large_bank=0;
Sync();
SetReadHandler(0x8000,0xFFFF,BMC70in1Read);
SetWriteHandler(0x8000,0xffff,BMC70in1Write);
}
static void StateRestore(int version)
{
Sync();
}
void BMC70in1_Init(CartInfo *info)
{
is_large_banks=0;
hw_switch=0xd;
info->Power=BMC70in1Power;
info->Reset=BMC70in1Reset;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}
void BMC70in1B_Init(CartInfo *info)
{
is_large_banks=1;
hw_switch=0x6;
info->Power=BMC70in1Power;
info->Reset=BMC70in1Reset;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,132 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2002 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
#define CARD_EXTERNAL_INSERED 0x80
static uint8 prg_reg;
static uint8 chr_reg;
static SFORMAT StateRegs[]=
{
{&prg_reg, 1, "PREG"},
{&chr_reg, 1, "CREG"},
{0}
};
/*
_GET_CHALLENGE: .BYTE 0,$B4, 0, 0,$62
_SELECT_FILE_1_0200: .BYTE 0,$A4, 1, 0, 2, 2, 0
_SELECT_FILE_2_0201: .BYTE 0,$A4, 2, 0, 2, 2, 1
_SELECT_FILE_2_0203: .BYTE 0,$A4, 2, 0, 2, 2, 3
_SELECT_FILE_2_0204: .BYTE 0,$A4, 2, 0, 2, 2, 4
_SELECT_FILE_2_0205: .BYTE 0,$A4, 2, 0, 2, 2, 5
_SELECT_FILE_2_3F04: .BYTE 0,$A4, 2, 0, 2,$3F, 4
_SELECT_FILE_2_4F00: .BYTE 0,$A4, 2, 0, 2,$4F, 0
_READ_BINARY_5: .BYTE 0,$B0,$85, 0, 2
_READ_BINARY_6: .BYTE 0,$B0,$86, 0, 4
_READ_BINARY_6_0: .BYTE 0,$B0,$86, 0,$18
_READ_BINARY_0: .BYTE 0,$B0, 0, 2, 3
_READ_BINARY_0_0: .BYTE 0,$B0, 0, 0, 4
_READ_BINARY_0_1: .BYTE 0,$B0, 0, 0, $C
_READ_BINARY_0_2: .BYTE 0,$B0, 0, 0,$10
_UPDATE_BINARY: .BYTE 0,$D6, 0, 0, 4
_UPDATE_BINARY_0: .BYTE 0,$D6, 0, 0,$10
_GET_RESPONSE: .BYTE $80,$C0, 2,$A1, 8
_GET_RESPONSE_0: .BYTE 0,$C0, 0, 0, 2
_GET_RESPONSE_1: .BYTE 0,$C0, 0, 0, 6
_GET_RESPONSE_2: .BYTE 0,$C0, 0, 0, 8
_GET_RESPONSE_3: .BYTE 0,$C0, 0, 0, $C
_GET_RESPONSE_4: .BYTE 0,$C0, 0, 0,$10
byte_8C0B: .BYTE $80,$30, 0, 2, $A, 0, 1
byte_8C48: .BYTE $80,$32, 0, 1, 4
byte_8C89: .BYTE $80,$34, 0, 0, 8, 0, 0
byte_8D01: .BYTE $80,$36, 0, 0, $C
byte_8CA7: .BYTE $80,$38, 0, 2, 4
byte_8BEC: .BYTE $80,$3A, 0, 3, 0
byte_89A0: .BYTE 0,$48, 0, 0, 6
byte_8808: .BYTE 0,$54, 0, 0,$1C
byte_89BF: .BYTE 0,$58, 0, 0,$1C
_MANAGE_CHANNEL: .BYTE 0,$70, 0, 0, 8
byte_8CE5: .BYTE 0,$74, 0, 0,$12
byte_8C29: .BYTE 0,$76, 0, 0, 8
byte_8CC6: .BYTE 0,$78, 0, 0,$12
*/
static uint8 sim0reset[0x1F] = { 0x3B, 0xE9, 0x00, 0xFF, 0xC1, 0x10, 0x31, 0xFE,
0x55, 0xC8, 0x10, 0x20, 0x55, 0x47, 0x4F, 0x53,
0x56, 0x53, 0x43, 0xAD, 0x10, 0x10, 0x10, 0x10,
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 };
static void Sync(void)
{
setprg32(0x8000, prg_reg);
setchr8(chr_reg);
}
static void StateRestore(int version)
{
Sync();
}
static DECLFW(M216WriteHi)
{
prg_reg=A&1;
chr_reg=(A&0x0E)>>1;
Sync();
}
static DECLFW(M216Write5000)
{
// FCEU_printf("WRITE: %04x:%04x (PC=%02x cnt=%02x)\n",A,V,X.PC,sim0bcnt);
}
static DECLFR(M216Read5000)
{
// FCEU_printf("READ: %04x PC=%04x out=%02x byte=%02x cnt=%02x bit=%02x\n",A,X.PC,sim0out,sim0byte,sim0bcnt,sim0bit);
return 0;
}
static void Power(void)
{
prg_reg = 0;
chr_reg = 0;
Sync();
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,M216WriteHi);
SetWriteHandler(0x5000,0x5000,M216Write5000);
SetReadHandler(0x5000,0x5000,M216Read5000);
}
void Mapper216_Init(CartInfo *info)
{
info->Power=Power;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,91 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 reg_prg[4];
static uint8 reg_chr[4];
static uint8 dip_switch;
static SFORMAT StateRegs[]=
{
{reg_prg, 4, "PREGS"},
{reg_chr, 4, "CREGS"},
{0}
};
static void Sync(void)
{
setprg8(0x8000,reg_prg[0]);
setprg8(0xa000,reg_prg[1]);
setprg8(0xc000,reg_prg[2]);
setprg8(0xe000,reg_prg[3]);
setchr2(0x0000,reg_chr[0]);
setchr2(0x0800,reg_chr[1]);
setchr2(0x1000,reg_chr[2]);
setchr2(0x1800,reg_chr[3]);
setmirror(MI_V);
}
static DECLFW(MBS5Write)
{
int bank_sel = (A&0xC00)>>10;
switch (A&0xF000)
{
case 0x8000:
reg_chr[bank_sel]=A&0x1F;
break;
case 0xA000:
if(A&(1<<(dip_switch+4)))
reg_prg[bank_sel]=A&0x0F;
break;
}
Sync();
}
static void MBS5Reset(void)
{
dip_switch++;
dip_switch&=3;
reg_prg[0]=reg_prg[1]=reg_prg[2]=reg_prg[3]=~0;
Sync();
}
static void MBS5Power(void)
{
dip_switch=0;
reg_prg[0]=reg_prg[1]=reg_prg[2]=reg_prg[3]=~0;
Sync();
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,MBS5Write);
}
static void StateRestore(int version)
{
Sync();
}
void BMCBS5_Init(CartInfo *info)
{
info->Power=MBS5Power;
info->Reset=MBS5Reset;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,148 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
0000 - 1FFF - RAM
2000 - 23FF - PPU
2400 - 27FF - Write: "PAG" / Read: --
2800 - 2BFF - Write: "BNK" / Read: "STS"
2C00 - 2FFF - Write: "UWR" / Read: "URD"
3000 - 3FFF - Small Flash Page (â ðåãèñòðå BNK)
4000 - 7FFF - Free
8000 - FFFF - Cart/Big Flash Page (ñìîòðè ðåãèñòð PAG)
Áèòû:
Ðåãèñòð [PAG], ïî ñáðîñó äîëæåí áûòü = $00.
D3-D0 - Big Page High Address (D3,D2,D1,D0,A14,A13,A12,A11,A10,A9,A8,A7,A6,A5,A4,A3,A2,A1,A0)
D4 - VMD áèò. Åñëè =0, òî ê PPU ïîäêëþ÷åíî âíóòðåíåå ÎÇó íà 8Êá, åñëè =1 - òî êàðòðèäæ.
D5 - STR áèò. Åñëè =0, òî âìåñòî êàðòà ïî àäðåñàì 8000-FFFF âíóòðåííÿÿ ôëýø, =1 - êàðò.
Ðåãèñòð [BNK], íå ïðåäóñòàíàâëèâàåòñÿ
D6-D0 - Small Page High Address (D6,D5,D4,D3,D2,D1,D0,A11,A10,A9,A8,A7,A6,A5,A4,A3,A2,A1,A0)
D7 - S/W áèò. Óïðàâëÿåò USB ìîñòîì, â ýìóëå ðåàëèçîâûâàòü íå íàäî.
Ðåãèñòðû [UWR]/[URD], íå ïðåäóñòàíàâëèâàþòñÿ, â ýìóëå ðåàëèçîâûâàòü íå íàäî.
[UWR] - Ðåãèñòð çàïèñè äàííûõ â USB ìîñò.
[URD] - Ðåãèñòð ÷òåíèÿ èç USB ìîñòà.
*/
#include "mapinc.h"
#include "mmc3.h"
static uint8 reg[3];
static uint8 *CHRRAM=NULL; // there is no more extern CHRRAM in mmc3.h
// I need chrram here and local static == local
static uint32 CHRRAMSIZE;
static SFORMAT StateRegs[]=
{
{reg, 3, "REGS"},
{0}
};
static void Sync(void)
{
setprg4r(1,0x3000,reg[1]&0x7F);
FixMMC3PRG(MMC3_cmd);
FixMMC3CHR(MMC3_cmd);
}
static void MCopyFamiMMC3PW(uint32 A, uint8 V)
{
if(reg[0]&0x20)
setprg8r(0,A,V);
else
setprg32r(1,0x8000,reg[0]&0x0F);
}
static void MCopyFamiMMC3CW(uint32 A, uint8 V)
{
if(reg[0]&0x20)
setchr1r(0,A,V);
else
setchr8r(0x10,0);
}
static DECLFW(MCopyFamiMMC3WritePAG)
{
reg[0]=V;
Sync();
}
static DECLFW(MCopyFamiMMC3WriteBNK)
{
reg[1]=V;
Sync();
}
static DECLFW(MCopyFamiMMC3WriteUSB)
{
reg[2]=V;
}
static void MCopyFamiMMC3Power(void)
{
reg[0] = 0;
GenMMC3Power();
Sync();
SetReadHandler(0x3000,0x3FFF,CartBR);
SetWriteHandler(0x3000,0x3FFF,CartBW);
SetWriteHandler(0x2400,0x27FF,MCopyFamiMMC3WritePAG);
SetWriteHandler(0x2800,0x2BFF,MCopyFamiMMC3WriteBNK);
SetWriteHandler(0x2C00,0x2FFF,MCopyFamiMMC3WriteUSB);
}
static void MCopyFamiMMC3Reset(void)
{
reg[0] = 0;
MMC3RegReset();
Sync();
}
static void MCopyFamiMMC3Close(void)
{
if(CHRRAM)
FCEU_gfree(CHRRAM);
CHRRAM=NULL;
}
static void StateRestore(int version)
{
Sync();
}
void MapperCopyFamiMMC3_Init(CartInfo *info)
{
GenMMC3_Init(info, 512, 512, 0, 0);
cwrap=MCopyFamiMMC3CW;
pwrap=MCopyFamiMMC3PW;
info->Reset=MCopyFamiMMC3Reset;
info->Power=MCopyFamiMMC3Power;
info->Close=MCopyFamiMMC3Close;
GameStateRestore=StateRestore;
CHRRAMSIZE=8192;
CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSIZE);
SetupCartPRGMapping(0x10,CHRRAM,CHRRAMSIZE,1);
AddExState(CHRRAM, CHRRAMSIZE, 0, "SRAM");
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,205 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Street Dance (Dance pad) (Unl)
*/
#include "mapinc.h"
static uint8 reg4[16];
static uint8 regc[6];
static uint8 reg2000, mmc3cmd, pcm_enable = 0, pcm_irq = 0;
static int16 pcm_addr, pcm_size, pcm_latch, pcm_clock = 0xF6;
static writefunc old4011write, old4012write, old4013write, old4015write;
static readfunc old4015read;
static SFORMAT StateRegs[]=
{
{reg4, 16, "reg4"},
{regc, 6, "REGSC"},
{&reg2000, 1, "REGS2"},
{&pcm_enable, 1, "PCME"},
{&pcm_irq, 1, "PCMIRQ"},
{&pcm_addr, 2, "PCMADDR"},
{&pcm_size, 2, "PCMSIZE"},
{&pcm_latch, 2, "PCMLATCH"},
{&pcm_clock, 2, "PCMCLOCK"},
{&mmc3cmd, 1, "MMC3CMD"},
{0}
};
static void Sync(void)
{
uint8 cbase = reg2000 - ((reg4[0x0B]&4)?6:0);
uint8 pbase = reg4[0x09] & 0xC0;
setchr1(0x0000,cbase|(regc[0]&(~1)));
setchr1(0x0400,cbase|(regc[0]|1));
setchr1(0x0800,cbase|(regc[1]&(-1)));
setchr1(0x0c00,cbase|(regc[1]|1));
setchr1(0x1000,cbase|regc[2]);
setchr1(0x1400,cbase|regc[3]);
setchr1(0x1800,cbase|regc[4]);
setchr1(0x1c00,cbase|regc[5]);
if(reg4[0x0B]&1)
{
setprg8(0x8000,reg4[0x07] + 0x20);
setprg8(0xA000,reg4[0x08] + 0x20);
}
else
{
setprg8(0x8000,reg4[0x07] + pbase);
setprg8(0xA000,reg4[0x08] + pbase);
}
setprg8(0xC000,reg4[0x09]);
setprg8(0xE000,reg4[0x0A]);
}
static DECLFW(UNLDANCEWrite2)
{
reg2000 = V;
Sync();
//FCEU_printf("write %04x:%04x\n",A,V);
}
static DECLFW(UNLDANCEWrite4)
{
reg4[A & 0x0F] = V;
Sync();
//FCEU_printf("write %04x:%04x\n",A,V);
}
static DECLFW(UNLDANCEWrite8)
{
if(A&1)
{
if(mmc3cmd<6)
regc[mmc3cmd] = V;
else
reg4[0x07 + mmc3cmd - 6] = V;
}
else
mmc3cmd = V & 7;
Sync();
//FCEU_printf("write %04x:%04x\n",A,V);
}
static DECLFW(UNLDANCEWrite4012)
{
pcm_addr = V << 6;
old4012write(A,V);
}
static DECLFW(UNLDANCEWrite4013)
{
pcm_size = (V << 4) + 1;
old4013write(A,V);
}
static DECLFW(UNLDANCEWrite4015)
{
pcm_enable = V&0x10;
if(pcm_irq)
{
X6502_IRQEnd(FCEU_IQEXT);
pcm_irq = 0;
}
if(pcm_enable)
pcm_latch = pcm_clock;
old4015write(A,V&0xEF);
}
static DECLFR(UNLDANCERead4015)
{
return (old4015read(A) & 0x7F) | pcm_irq;
}
static void UNLDANCECpuHook(int a)
{
if(pcm_enable)
{
pcm_latch-=a;
if(pcm_latch<=0)
{
pcm_latch+=pcm_clock;
pcm_size--;
if(pcm_size<0)
{
pcm_irq = 0x80;
pcm_enable = 0;
X6502_IRQBegin(FCEU_IQEXT);
}
else
{
uint8 raw_pcm = ARead[pcm_addr](pcm_addr) >> 1;
old4011write(0x4011,raw_pcm);
pcm_addr++;
pcm_addr&=0x7FFF;
}
}
}
}
static void UNLDANCEPower(void)
{
reg4[0x09]=0x3E;
reg4[0x0A]=0x3F;
SetupCartCHRMapping(0,PRGptr[0],512 * 1024,0);
old4015read=GetReadHandler(0x4015);
SetReadHandler(0x4015,0x4015,UNLDANCERead4015);
SetReadHandler(0x8000,0xFFFF,CartBR);
old4011write=GetWriteHandler(0x4011);
old4012write=GetWriteHandler(0x4012);
SetWriteHandler(0x4012,0x4012,UNLDANCEWrite4012);
old4013write=GetWriteHandler(0x4013);
SetWriteHandler(0x4013,0x4013,UNLDANCEWrite4013);
old4015write=GetWriteHandler(0x4015);
SetWriteHandler(0x4015,0x4015,UNLDANCEWrite4015);
SetWriteHandler(0x201A,0x201A,UNLDANCEWrite2);
SetWriteHandler(0x4100,0x410F,UNLDANCEWrite4);
SetWriteHandler(0x8000,0x8001,UNLDANCEWrite8);
Sync();
}
static void UNLDANCEReset(void)
{
reg4[0x09]=0x3E;
reg4[0x0A]=0x3F;
Sync();
}
static void StateRestore(int version)
{
Sync();
}
void UNLDANCE_Init(CartInfo *info)
{
info->Power=UNLDANCEPower;
info->Reset=UNLDANCEReset;
MapIRQHook=UNLDANCECpuHook;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -89,9 +89,11 @@ void Mapper184_Init(CartInfo *info)
static void CNROMSync(void)
{
setchr8(latche&3);
setprg16(0x8000,0);
setprg16(0xC000,1);
//mbg 8/10/08 - fixed this so that large homebrew roms would work.
//setchr8(latche&3);
setchr8(latche);
setprg16(0x8000,0);
setprg16(0xC000,1);
}
void CNROM_Init(CartInfo *info)
@ -187,7 +189,8 @@ static void M87Sync(void)
{
setprg16(0x8000,0);
setprg16(0xC000,1);
setchr8(latche>>1);
setchr8(((latche>>1)&1)|((latche<<1)&2));
// setchr8(latche);
}
void Mapper87_Init(CartInfo *info)
@ -195,6 +198,20 @@ void Mapper87_Init(CartInfo *info)
Latch_Init(info, M87Sync, ~0, 0x6000, 0xFFFF);
}
//------------------ Map 101 ---------------------------
static void M101Sync(void)
{
setprg16(0x8000,0);
setprg16(0xC000,1);
setchr8(latche);
}
void Mapper101_Init(CartInfo *info)
{
Latch_Init(info, M101Sync, ~0, 0x6000, 0x7FFF);
}
//------------------ Map 11 ---------------------------
static void M11Sync(void)
@ -213,6 +230,31 @@ void Mapper144_Init(CartInfo *info)
Latch_Init(info, M11Sync, 0, 0x8001, 0xFFFF);
}
//------------------ Map 38 ---------------------------
static void M38Sync(void)
{
setprg32(0x8000,latche&3);
setchr8(latche>>2);
}
void Mapper38_Init(CartInfo *info)
{
Latch_Init(info, M38Sync, 0, 0x7000, 0x7FFF);
}
//------------------ Map 36 ---------------------------
static void M36Sync(void)
{
setprg32(0x8000,latche>>4);
setchr8((latche)&0xF);
}
void Mapper36_Init(CartInfo *info)
{
Latch_Init(info, M36Sync, 0, 0x8400, 0xfffe);
}
//------------------ UNROM ---------------------------
static void UNROMSync(void)

View File

@ -25,61 +25,58 @@ static uint8 DRegs[8];
static SFORMAT DEI_StateRegs[]=
{
{&cmd, 1, "CMD"},
{DRegs, 8, "DREG"},
{0}
{&cmd, 1, "CMD"},
{DRegs, 8, "DREG"},
{0}
};
static void Sync(void)
{
int x;
setchr2(0x0000,DRegs[0]);
setchr2(0x0800,DRegs[1]);
for(x=0;x<4;x++)
setchr1(0x1000+(x<<10),DRegs[2+x]);
setprg8(0x8000,DRegs[6]);
setprg8(0xa000,DRegs[7]);
int x;
setchr2(0x0000,DRegs[0]);
setchr2(0x0800,DRegs[1]);
for(x=0;x<4;x++)
setchr1(0x1000+(x<<10),DRegs[2+x]);
setprg8(0x8000,DRegs[6]);
setprg8(0xa000,DRegs[7]);
}
static void StateRestore(int version)
{
Sync();
Sync();
}
static DECLFW(DEIWrite)
{
switch(A&0x8001)
{
case 0x8000:cmd=V&0x07;break;
case 0x8001:if(cmd<=0x05) V&=0x3F;
else V&=0x0F;
if(cmd<=0x01) V>>=1;
DRegs[cmd&0x07]=V;
Sync();
break;
}
switch(A&0x8001)
{
case 0x8000: cmd=V&0x07; break;
case 0x8001: if(cmd<=0x05)
V&=0x3F;
else
V&=0x0F;
if(cmd<=0x01) V>>=1;
DRegs[cmd&0x07]=V;
Sync();
break;
}
}
static void DEIPower(void)
{
setprg8(0xc000,0xE);
setprg8(0xe000,0xF);
cmd=0;
memset(DRegs,0,8);
Sync();
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,DEIWrite);
setprg8(0xc000,0xE);
setprg8(0xe000,0xF);
cmd=0;
memset(DRegs,0,8);
Sync();
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,DEIWrite);
}
void DEIROM_Init(CartInfo *info)
{
info->Power=DEIPower;
GameStateRestore=StateRestore;
AddExState(&DEI_StateRegs, ~0, 0, 0);
}
void Mapper206_Init(CartInfo *info)
{
DEIROM_Init(info);
info->Power=DEIPower;
GameStateRestore=StateRestore;
AddExState(&DEI_StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,56 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 latche;
static void Sync(void)
{
setprg16(0x8000,latche);
setprg16(0xC000,8);
}
static DECLFW(DREAMWrite)
{
latche=V&7;
Sync();
}
static void DREAMPower(void)
{
latche=0;
Sync();
setchr8(0);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x5020,0x5020,DREAMWrite);
}
static void Restore(int version)
{
Sync();
}
void DreamTech01_Init(CartInfo *info)
{
GameStateRestore=Restore;
info->Power=DREAMPower;
AddExState(&latche, 1, 0, "LATCH");
}

View File

@ -0,0 +1,84 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2006 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "mapinc.h"
static uint8 *WRAM=NULL;
static uint8 reg;
static SFORMAT StateRegs[]=
{
{&reg, 1, "REG"},
{0}
};
static void Sync(void)
{
setchr8(0);
setprg8r(0x10,0x6000,(reg&0xC0)>>6);
setprg32(0x8000,reg&0x1F);
// setmirror(((reg&0x20)>>5));
}
static DECLFW(UNLEDU2000HiWrite)
{
// FCEU_printf("%04x:%02x\n",A,V);
reg=V;
Sync();
}
static void UNLEDU2000Power(void)
{
setmirror(MI_0);
SetReadHandler(0x6000,0xFFFF,CartBR);
SetWriteHandler(0x6000,0xFFFF,CartBW);
SetWriteHandler(0x8000,0xFFFF,UNLEDU2000HiWrite);
reg=0;
Sync();
}
static void UNLEDU2000Close(void)
{
if(WRAM)
FCEU_gfree(WRAM);
WRAM=NULL;
}
static void UNLEDU2000Restore(int version)
{
Sync();
}
void UNLEDU2000_Init(CartInfo *info)
{
info->Power=UNLEDU2000Power;
info->Close=UNLEDU2000Close;
GameStateRestore=UNLEDU2000Restore;
WRAM=(uint8*)FCEU_gmalloc(32768);
SetupCartPRGMapping(0x10,WRAM,32768,1);
if(info->battery)
{
info->SaveGame[0]=WRAM;
info->SaveGameLen[0]=32768;
}
AddExState(WRAM, 32768, 0, "WRAM");
AddExState(StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,137 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2006 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
#include "mmc3.h"
static uint8 unromchr;
static uint32 dipswitch;
static void BMCFK23CCW(uint32 A, uint8 V)
{
if(EXPREGS[0]&0x40)
setchr8(EXPREGS[2]|unromchr);
else
{
uint16 base=(EXPREGS[2]&0x7F)<<3;
setchr1(A,V|base);
if(EXPREGS[3]&2)
{
setchr1(0x0400,EXPREGS[6]|base);
setchr1(0x0C00,EXPREGS[7]|base);
}
}
}
static void BMCFK23CPW(uint32 A, uint8 V)
{
if((EXPREGS[0]&7)==4)
setprg32(0x8000,EXPREGS[1]>>1);
else if ((EXPREGS[0]&7)==3)
{
setprg16(0x8000,EXPREGS[1]);
setprg16(0xC000,EXPREGS[1]);
}
else
{
if(EXPREGS[0]&3)
setprg8(A,(V&(0x3F>>(EXPREGS[0]&3)))|(EXPREGS[1]<<1));
else
setprg8(A,V);
if(EXPREGS[3]&2)
{
setprg8(0xC000,EXPREGS[4]);
setprg8(0xE000,EXPREGS[5]);
}
}
}
static DECLFW(BMCFK23CHiWrite)
{
if(EXPREGS[0]&0x40)
{
if(EXPREGS[0]&0x30)
unromchr=0;
else
{
unromchr=V&3;
FixMMC3CHR(MMC3_cmd);
}
}
else
{
if((A==0x8001)&&(EXPREGS[3]&2&&MMC3_cmd&8))
{
EXPREGS[4|(MMC3_cmd&3)]=V;
FixMMC3PRG(MMC3_cmd);
FixMMC3CHR(MMC3_cmd);
}
else
if(A<0xC000)
MMC3_CMDWrite(A,V);
else
MMC3_IRQWrite(A,V);
}
}
static DECLFW(BMCFK23CWrite)
{
if(A&(1<<(dipswitch+4)))
{
EXPREGS[A&3]=V;
FixMMC3PRG(MMC3_cmd);
FixMMC3CHR(MMC3_cmd);
}
}
static void BMCFK23CReset(void)
{
dipswitch++;
dipswitch&=7;
EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=0;
EXPREGS[4]=EXPREGS[5]=EXPREGS[6]=EXPREGS[7]=0xFF;
MMC3RegReset();
FixMMC3PRG(MMC3_cmd);
FixMMC3CHR(MMC3_cmd);
}
static void BMCFK23CPower(void)
{
GenMMC3Power();
EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=0;
EXPREGS[4]=EXPREGS[5]=EXPREGS[6]=EXPREGS[7]=0xFF;
GenMMC3Power();
SetWriteHandler(0x5000,0x5fff,BMCFK23CWrite);
SetWriteHandler(0x8000,0xFFFF,BMCFK23CHiWrite);
FixMMC3PRG(MMC3_cmd);
FixMMC3CHR(MMC3_cmd);
}
void BMCFK23C_Init(CartInfo *info)
{
GenMMC3_Init(info, 512, 256, 8, 0);
cwrap=BMCFK23CCW;
pwrap=BMCFK23CPW;
info->Power=BMCFK23CPower;
info->Reset=BMCFK23CReset;
AddExState(EXPREGS, 8, 0, "EXPR");
AddExState(&unromchr, 1, 0, "UNCHR");
AddExState(&dipswitch, 1, 0, "DIPSW");
}

View File

@ -0,0 +1,106 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 63in1 ghostbusters
*/
#include "mapinc.h"
static uint8 reg[2], bank;
static uint8 banks[4] = {0, 0, 1, 2};
static uint8 *CHRROM=NULL;
static uint32 CHRROMSIZE;
static SFORMAT StateRegs[]=
{
{reg, 2, "REGS"},
{&bank, 1, "BANK"},
{0}
};
static void Sync(void)
{
if(reg[0]&0x20)
{
setprg16r(banks[bank],0x8000,reg[0]&0x1F);
setprg16r(banks[bank],0xC000,reg[0]&0x1F);
}
else
setprg32r(banks[bank],0x8000,(reg[0]>>1)&0x0F);
if(reg[1]&2)
setchr8r(0x10,0);
else
setchr8(0);
setmirror((reg[0]&0x40)>>6);
}
static DECLFW(BMCGhostbusters63in1Write)
{
reg[A&1]=V;
bank=((reg[0]&0x80)>>7)|((reg[1]&1)<<1);
// FCEU_printf("reg[0]=%02x, reg[1]=%02x, bank=%02x\n",reg[0],reg[1],bank);
Sync();
}
static DECLFR(BMCGhostbusters63in1Read)
{
if(bank==1)
return X.DB;
else
return CartBR(A);
}
static void BMCGhostbusters63in1Power(void)
{
reg[0]=reg[1]=0;
Sync();
SetReadHandler(0x8000,0xFFFF,BMCGhostbusters63in1Read);
SetWriteHandler(0x8000,0xFFFF,BMCGhostbusters63in1Write);
}
static void BMCGhostbusters63in1Reset(void)
{
reg[0]=reg[1]=0;
}
static void StateRestore(int version)
{
Sync();
}
static void BMCGhostbusters63in1Close(void)
{
if(CHRROM)
FCEU_gfree(CHRROM);
CHRROM=NULL;
}
void BMCGhostbusters63in1_Init(CartInfo *info)
{
info->Reset=BMCGhostbusters63in1Reset;
info->Power=BMCGhostbusters63in1Power;
info->Close=BMCGhostbusters63in1Close;
CHRROMSIZE=8192; // dummy CHRROM, VRAM disable
CHRROM=(uint8*)FCEU_gmalloc(CHRROMSIZE);
SetupCartPRGMapping(0x10,CHRROM,CHRROMSIZE,0);
AddExState(CHRROM, CHRROMSIZE, 0, "CHRROM");
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -1,73 +1,69 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2003 Xodnizel
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static void Sync(void)
{
int x;
setmirror(((mapbyte1[0]>>6)&1)^1);
switch(mapbyte1[1]&0x3)
{
case 0x0:
for(x=0;x<4;x++)
setprg8(0x8000+x*8192,(((mapbyte1[0]&0x7F)<<1)+x)^(mapbyte1[0]>>7));
break;
case 0x2:
for(x=0;x<4;x++)
setprg8(0x8000+x*8192,((mapbyte1[0]&0x7F)<<1)+(mapbyte1[0]>>7));
break;
case 0x1:
case 0x3:
for(x=0;x<4;x++)
{
unsigned int b;
b=mapbyte1[0]&0x7F;
if(x>=2 && !(mapbyte1[1]&0x2))
b=0x7F;
setprg8(0x8000+x*8192,(x&1)+((b<<1)^(mapbyte1[0]>>7)));
}
break;
}
}
static DECLFW(Mapper15_write)
{
mapbyte1[0]=V;
mapbyte1[1]=A&3;
Sync();
}
static void StateRestore(int version)
{
Sync();
}
void Mapper15_init(void)
{
mapbyte1[0]=mapbyte1[1]=0;
Sync();
GameStateRestore=StateRestore;
SetWriteHandler(0x8000,0xFFFF,Mapper15_write);
}
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 reg, mirr;
static SFORMAT StateRegs[]=
{
{&reg, 1, "REGS"},
{&mirr, 1, "MIRR"},
{0}
};
static void Sync(void)
{
setprg8r(1,0x6000,0);
setprg32(0x8000,reg);
setchr8(0);
}
static DECLFW(BMCGS2004Write)
{
reg=V;
Sync();
}
static void BMCGS2004Power(void)
{
reg=~0;
Sync();
SetReadHandler(0x6000,0x7FFF,CartBR);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,BMCGS2004Write);
}
static void BMCGS2004Reset(void)
{
reg=~0;
}
static void StateRestore(int version)
{
Sync();
}
void BMCGS2004_Init(CartInfo *info)
{
info->Reset=BMCGS2004Reset;
info->Power=BMCGS2004Power;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,69 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 reg, mirr;
static SFORMAT StateRegs[]=
{
{&reg, 1, "REGS"},
{&mirr, 1, "MIRR"},
{0}
};
static void Sync(void)
{
setprg8r(0,0x6000,~0);
setprg32r((reg&8)>>3,0x8000,reg);
setchr8(0);
}
static DECLFW(BMCGS2013Write)
{
reg=V;
Sync();
}
static void BMCGS2013Power(void)
{
reg=~0;
Sync();
SetReadHandler(0x6000,0x7FFF,CartBR);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,BMCGS2013Write);
}
static void BMCGS2013Reset(void)
{
reg=~0;
}
static void StateRestore(int version)
{
Sync();
}
void BMCGS2013_Init(CartInfo *info)
{
info->Reset=BMCGS2013Reset;
info->Power=BMCGS2013Power;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -1,113 +0,0 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2003 Xodnizel
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Not finished. Darn evil game... *Mumble*... */
#include "mapinc.h"
static uint8 cmd;
static uint8 regs[8];
static void DoPRG(void)
{
if(cmd&0x40)
{
setprg8(0xC000,regs[4]);
setprg8(0xA000,regs[5]);
setprg8(0x8000,~1);
setprg8(0xE000,~0);
}
else
{
setprg8(0x8000,regs[4]);
setprg8(0xA000,regs[5]);
setprg8(0xC000,~1);
setprg8(0xE000,~0);
}
}
static void DoCHR(void)
{
uint32 base=(cmd&0x80)<<5;
setchr2(0x0000^base,regs[0]);
setchr2(0x0800^base,regs[2]);
setchr1(0x1000^base,regs[6]);
setchr1(0x1400^base,regs[1]);
setchr1(0x1800^base,regs[7]);
setchr1(0x1c00^base,regs[3]);
}
static DECLFW(PWrite)
{
//printf("$%04x:$%02x\n",A,V);
}
static DECLFW(H2288Write)
{
//printf("$%04x:$%02x, $%04x\n",A,V,X.PC);
//FCEUI_DumpMem("dmp",0xc000,0xffff);
switch(A&0xE001)
{
case 0xa000:setmirror((V&1)^1);break;
case 0x8000:
cmd=V;DoPRG();DoCHR();break;
case 0x8001:regs[cmd&7]=V;
if((cmd&7)==4 || (cmd&7)==5)
DoPRG();
else
DoCHR();
break;
}
}
static DECLFR(H2288Read)
{
int bit;
//printf("Read: $%04x, $%04x\n",A,X.PC);
//DumpMem("out",0x8000,0xFFFF);
bit=(A&1)^1;
bit&=((A>>8)&1);
bit^=1;
return((X.DB&0xFE)|bit);
}
static void H2288Reset(void)
{
int x;
SetReadHandler(0x5000,0x5FFF,H2288Read);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x5000,0x5FFF,PWrite);
SetWriteHandler(0x8000,0xFFFF,H2288Write);
for(x=0;x<8;x++) regs[x]=0;
regs[4]=0;
regs[5]=1;
cmd=0;
DoPRG();
DoCHR();
}
void H2288_Init(CartInfo *info)
{
info->Power=H2288Reset;
}

View File

@ -0,0 +1,89 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
#include "mmc3.h"
extern uint8 m114_perm[8];
static void H2288PW(uint32 A, uint8 V)
{
if(EXPREGS[0]&0x40)
{
uint8 bank=(EXPREGS[0]&5)|((EXPREGS[0]&8)>>2)|((EXPREGS[0]&0x20)>>2);
if(EXPREGS[0]&2)
setprg32(0x8000,bank>>1);
else
{
setprg16(0x8000,bank);
setprg16(0xC000,bank);
}
}
else
setprg8(A,V&0x3F);
}
static DECLFW(H2288WriteHi)
{
switch (A&0x8001)
{
case 0x8000: MMC3_CMDWrite(0x8000,(V&0xC0)|(m114_perm[V&7])); break;
case 0x8001: MMC3_CMDWrite(0x8001,V); break;
}
}
static DECLFW(H2288WriteLo)
{
if(A&0x800)
{
if(A&1)
EXPREGS[1]=V;
else
EXPREGS[0]=V;
FixMMC3PRG(MMC3_cmd);
}
}
static DECLFR(H2288Read)
{
int bit;
bit=(A&1)^1;
bit&=((A>>8)&1);
bit^=1;
return((X.DB&0xFE)|bit);
}
static void H2288Power(void)
{
EXPREGS[0]=EXPREGS[1]=0;
GenMMC3Power();
SetReadHandler(0x5000,0x5FFF,H2288Read);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x5000,0x5FFF,H2288WriteLo);
SetWriteHandler(0x8000,0x8FFF,H2288WriteHi);
}
void UNLH2288_Init(CartInfo *info)
{
GenMMC3_Init(info, 256, 256, 0, 0);
pwrap=H2288PW;
info->Power=H2288Power;
AddExState(EXPREGS, 2, 0, "EXPR");
}

View File

@ -20,30 +20,52 @@
#include "mapinc.h"
extern uint32 ROM_size;
static uint8 latche;
static DECLFW(Mapper57_write)
static void Sync(void)
{
A&=0x8800;
if(A==0x8800)
{
mapbyte1[0]=V;
if(V&0x80)
ROM_BANK32(2|(V>>6));
else
if(latche)
{
ROM_BANK16(0x8000,(V>>5)&3);
ROM_BANK16(0xc000,(V>>5)&3);
if(latche&0x10)
setprg16(0x8000,(latche&7));
else
setprg16(0x8000,(latche&7)|8);
}
MIRROR_SET((V&0x8)>>3);
}
else
mapbyte1[1]=V;
VROM_BANK8((mapbyte1[1]&3)|(mapbyte1[0]&7)|((mapbyte1[0]&0x10)>>1));
//printf("$%04x:$%02x\n",A,V);
else
setprg16(0x8000,7+(ROM_size>>4));
}
void Mapper57_init(void)
static DECLFW(M188Write)
{
SetWriteHandler(0x8000,0xffff,Mapper57_write);
latche=V;
Sync();
}
static DECLFR(ExtDev)
{
return(3);
}
static void Power(void)
{
latche=0;
Sync();
setchr8(0);
setprg16(0xc000,0x7);
SetReadHandler(0x6000,0x7FFF,ExtDev);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,M188Write);
}
static void StateRestore(int version)
{
Sync();
}
void Mapper188_Init(CartInfo *info)
{
info->Power=Power;
GameStateRestore=StateRestore;
AddExState(&latche, 1, 0, "LATCH");
}

View File

@ -0,0 +1,50 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
#include "mmc3.h"
static DECLFW(UNLKOF97CMDWrite)
{
V=(V&0xD8)|((V&0x20)>>4)|((V&4)<<3)|((V&2)>>1)|((V&1)<<2); //76143502
if(A==0x9000) A=0x8001;
MMC3_CMDWrite(A,V);
}
static DECLFW(UNLKOF97IRQWrite)
{
V=(V&0xD8)|((V&0x20)>>4)|((V&4)<<3)|((V&2)>>1)|((V&1)<<2);
if(A==0xD000) A=0xC001;
else if(A==0xF000) A=0xE001;
MMC3_IRQWrite(A,V);
}
static void UNLKOF97Power(void)
{
GenMMC3Power();
SetWriteHandler(0x8000,0xA000,UNLKOF97CMDWrite);
SetWriteHandler(0xC000,0xF000,UNLKOF97IRQWrite);
}
void UNLKOF97_Init(CartInfo *info)
{
GenMMC3_Init(info, 128, 256, 0, 0);
info->Power=UNLKOF97Power;
}

View File

@ -0,0 +1,242 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005-2008 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* CAI Shogakko no Sansu
*/
#include "mapinc.h"
static uint8 QTAINTRAM[2048];
static writefunc old2007wrap;
static uint16 CHRSIZE = 8192;
static uint16 WRAMSIZE = 8192 + 4096;
static uint8 *CHRRAM=NULL;
static uint8 *WRAM = NULL;
static uint8 IRQa, K4IRQ;
static uint32 IRQLatch, IRQCount;
static uint8 regs[16];
//static uint8 test[8];
static SFORMAT StateRegs[]=
{
{&IRQCount, 1, "IRQC"},
{&IRQLatch, 1, "IRQL"},
{&IRQa, 1, "IRQA"},
{&K4IRQ, 1, "K4IRQ"},
{regs, 16, "REGS"},
{0}
};
static void chrSync(void)
{
setchr4r(0x10,0x0000,regs[5]&1);
setchr4r(0x10,0x1000,0);
}
static void Sync(void)
{
chrSync();
// if(regs[0xA]&0x10)
// {
/* setchr1r(0x10,0x0000,(((regs[5]&1))<<2)+0);
setchr1r(0x10,0x0400,(((regs[5]&1))<<2)+1);
setchr1r(0x10,0x0800,(((regs[5]&1))<<2)+2);
setchr1r(0x10,0x0c00,(((regs[5]&1))<<2)+3);
setchr1r(0x10,0x1000,0);
setchr1r(0x10,0x1400,1);
setchr1r(0x10,0x1800,2);
setchr1r(0x10,0x1c00,3);*/
/* setchr1r(0x10,0x0000,(((regs[5]&1))<<2)+0);
setchr1r(0x10,0x0400,(((regs[5]&1))<<2)+1);
setchr1r(0x10,0x0800,(((regs[5]&1))<<2)+2);
setchr1r(0x10,0x0c00,(((regs[5]&1))<<2)+3);
setchr1r(0x10,0x1000,(((regs[5]&1)^1)<<2)+4);
setchr1r(0x10,0x1400,(((regs[5]&1)^1)<<2)+5);
setchr1r(0x10,0x1800,(((regs[5]&1)^1)<<2)+6);
setchr1r(0x10,0x1c00,(((regs[5]&1)^1)<<2)+7);
*/
// }
// else
// {
/*
setchr1r(0x10,0x0000,(((regs[5]&1)^1)<<2)+0);
setchr1r(0x10,0x0400,(((regs[5]&1)^1)<<2)+1);
setchr1r(0x10,0x0800,(((regs[5]&1)^1)<<2)+2);
setchr1r(0x10,0x0c00,(((regs[5]&1)^1)<<2)+3);
setchr1r(0x10,0x1000,(((regs[5]&1))<<2)+4);
setchr1r(0x10,0x1400,(((regs[5]&1))<<2)+5);
setchr1r(0x10,0x1800,(((regs[5]&1))<<2)+6);
setchr1r(0x10,0x1c00,(((regs[5]&1))<<2)+7);
// }
//*/
/* setchr1r(1,0x0000,test[0]);
setchr1r(1,0x0400,test[1]);
setchr1r(1,0x0800,test[2]);
setchr1r(1,0x0c00,test[3]);
setchr1r(1,0x1000,test[4]);
setchr1r(1,0x1400,test[5]);
setchr1r(1,0x1800,test[6]);
setchr1r(1,0x1c00,test[7]);
*/
setprg4r(0x10,0x6000,regs[0]&1);
if(regs[2]>=0x40)
setprg8r(1,0x8000,(regs[2]-0x40));
else
setprg8r(0,0x8000,(regs[2]&0x3F));
if(regs[3]>=0x40)
setprg8r(1,0xA000,(regs[3]-0x40));
else
setprg8r(0,0xA000,(regs[3]&0x3F));
if(regs[4]>=0x40)
setprg8r(1,0xC000,(regs[4]-0x40));
else
setprg8r(0,0xC000,(regs[4]&0x3F));
setprg8r(1,0xE000,~0);
setmirror(MI_V);
}
/*static DECLFW(TestWrite)
{
test[A&7] = V;
Sync();
}*/
static DECLFW(M190Write)
{
// FCEU_printf("write %04x:%04x %d, %d\n",A,V,scanline,timestamp);
regs[(A&0x0F00)>>8]=V;
switch(A)
{
case 0xd600:IRQLatch&=0xFF00;IRQLatch|=V;break;
case 0xd700:IRQLatch&=0x00FF;IRQLatch|=V<<8;break;
case 0xd900:IRQCount=IRQLatch;IRQa=V&2;K4IRQ=V&1;X6502_IRQEnd(FCEU_IQEXT);break;
case 0xd800:IRQa=K4IRQ;X6502_IRQEnd(FCEU_IQEXT);break;
}
Sync();
}
static DECLFR(M190Read)
{
// FCEU_printf("read %04x:%04x %d, %d\n",A,regs[(A&0x0F00)>>8],scanline,timestamp);
return regs[(A&0x0F00)>>8]+regs[0x0B];
}
static void VRC5IRQ(int a)
{
if(IRQa)
{
IRQCount+=a;
if(IRQCount&0x10000)
{
X6502_IRQBegin(FCEU_IQEXT);
// IRQCount=IRQLatch;
}
}
}
static void Mapper190_PPU(uint32 A)
{
if(A>=0x2000)
{
setchr4r(0x10,0x0000,QTAINTRAM[A&0x1FFF]&1);
setchr4r(0x10,0x1000,QTAINTRAM[A&0x1FFF]&1);
}
// else
// chrSync();
}
static DECLFW(M1902007Wrap)
{
if(A>=0x2000)
{
if(regs[0xA]&1)
QTAINTRAM[A&0x1FFF]=V;
else
old2007wrap(A,V);
}
}
static void M190Power(void)
{
/* test[0]=0;
test[1]=1;
test[2]=2;
test[3]=3;
test[4]=4;
test[5]=5;
test[6]=6;
test[7]=7;
*/
setprg4r(0x10,0x7000,2);
old2007wrap=GetWriteHandler(0x2007);
SetWriteHandler(0x2007,0x2007,M1902007Wrap);
SetReadHandler(0x6000,0xFFFF,CartBR);
// SetWriteHandler(0x5000,0x5007,TestWrite);
SetWriteHandler(0x6000,0x7FFF,CartBW);
SetWriteHandler(0x8000,0xFFFF,M190Write);
SetReadHandler(0xDC00,0xDC00,M190Read);
SetReadHandler(0xDD00,0xDD00,M190Read);
Sync();
}
static void M190Close(void)
{
if(CHRRAM)
FCEU_gfree(CHRRAM);
CHRRAM=NULL;
if(WRAM)
FCEU_gfree(WRAM);
WRAM=NULL;
}
static void StateRestore(int version)
{
Sync();
}
void Mapper190_Init(CartInfo *info)
{
info->Power=M190Power;
info->Close=M190Close;
GameStateRestore=StateRestore;
MapIRQHook=VRC5IRQ;
//PPU_hook=Mapper190_PPU;
CHRRAM=(uint8*)FCEU_gmalloc(CHRSIZE);
SetupCartCHRMapping(0x10,CHRRAM,CHRSIZE,1);
AddExState(CHRRAM, CHRSIZE, 0, "CHRRAM");
WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
if(info->battery)
{
info->SaveGame[0] = WRAM;
info->SaveGameLen[0] = WRAMSIZE - 4096;
}
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,94 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 reg[8], cmd, IRQa;
static int32 IRQCount;
static SFORMAT StateRegs[]=
{
{&cmd, 1, "CMD"},
{reg, 8, "REGS"},
{&IRQa, 1, "IRQA"},
{&IRQCount, 4, "IRQC"},
{0}
};
static void Sync(void)
{
setprg8(0x6000,reg[4]);
setprg8(0x8000,reg[1]);
setprg8(0xA000,reg[2]);
setprg8(0xC000,reg[3]);
setprg8(0xE000,~0);
setchr8(0);
}
static DECLFW(UNLKS7032Write)
{
// FCEU_printf("bs %04x %02x\n",A,V);
switch(A)
{
// case 0x8FFF: reg[4]=V; Sync(); break;
case 0x8000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x000F)|(V&0x0F); break;
case 0x9000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x00F0)|((V&0x0F)<<4); break;
case 0xA000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x0F00)|((V&0x0F)<<8); break;
case 0xB000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0xF000)|(V<<12); break;
case 0xC000: X6502_IRQEnd(FCEU_IQEXT); IRQa=1; break;
case 0xE000: cmd=V&7; break;
case 0xF000: reg[cmd]=V; Sync(); break;
}
}
static void UNLSMB2JIRQHook(int a)
{
if(IRQa)
{
IRQCount+=a;
if(IRQCount>=0xFFFF)
{
IRQa=0;
IRQCount=0;
X6502_IRQBegin(FCEU_IQEXT);
}
}
}
static void UNLKS7032Power(void)
{
Sync();
SetReadHandler(0x6000,0x7FFF,CartBR);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x4020,0xFFFF,UNLKS7032Write);
}
static void StateRestore(int version)
{
Sync();
}
void UNLKS7032_Init(CartInfo *info)
{
info->Power=UNLKS7032Power;
MapIRQHook=UNLSMB2JIRQHook;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -20,18 +20,15 @@
#include "mapinc.h"
DECLFW(MWrite)
{
(GameMemBlock-0x7000)[A]=V;
}
static uint8 WRAM[2048];
static void MALEEReset(void)
static void MALEEPower(void)
{
setprg2r(0x10,0x7000,0);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetReadHandler(0x6000,0x67ff,CartBR);
SetReadHandler(0x6000,0x67FF,CartBR);
SetReadHandler(0x7000,0x77FF,CartBR);
SetWriteHandler(0x7000,0x77FF,MWrite);
SetWriteHandler(0x7000,0x77FF,CartBW);
setprg2r(1,0x6000,0);
setprg32(0x8000,0);
setchr8(0);
@ -39,7 +36,7 @@ static void MALEEReset(void)
void MALEE_Init(CartInfo *info)
{
AddExState(GameMemBlock, 2048, 0,"RAM");
SetupCartPRGMapping(0x10,GameMemBlock,2048,1);
info->Power=MALEEReset;
info->Power=MALEEPower;
SetupCartPRGMapping(0x10, WRAM, 2048, 1);
AddExState(WRAM, 2048, 0,"RAM");
}

View File

@ -1,9 +1,12 @@
#include "../types.h"
#include "../x6502.h"
#include "../fceu.h"
#include "../ppu.h"
#include "../memory.h"
#include "../sound.h"
#include "../state.h"
#include "../cart.h"
#include "../unif.h"
#include "../types.h"
#include "../utils/memory.h"
#include "../x6502.h"
#include "../fceu.h"
#include "../ppu.h"
#include "../sound.h"
#include "../state.h"
#include "../cart.h"
#include "../cheat.h"
#include "../unif.h"
#include <stdio.h>
#include <string.h>

View File

@ -0,0 +1,451 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 1998 BERO
* Copyright (C) 2002 Xodnizel
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static void GenMMC1Power(void);
static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery);
static uint8 DRegs[4];
static uint8 Buffer,BufferShift;
static int mmc1opts;
static void (*MMC1CHRHook4)(uint32 A, uint8 V);
static void (*MMC1PRGHook16)(uint32 A, uint8 V);
static uint8 *WRAM=NULL;
static uint8 *CHRRAM=NULL;
static int is155, is171;
static DECLFW(MBWRAM)
{
if(!(DRegs[3]&0x10)||is155)
Page[A>>11][A]=V; // WRAM is enabled.
}
static DECLFR(MAWRAM)
{
if((DRegs[3]&0x10)&&!is155)
return X.DB; // WRAM is disabled
return(Page[A>>11][A]);
}
static void MMC1CHR(void)
{
if(mmc1opts&4)
{
if(DRegs[0]&0x10)
setprg8r(0x10,0x6000,(DRegs[1]>>4)&1);
else
setprg8r(0x10,0x6000,(DRegs[1]>>3)&1);
}
if(MMC1CHRHook4)
{
if(DRegs[0]&0x10)
{
MMC1CHRHook4(0x0000,DRegs[1]);
MMC1CHRHook4(0x1000,DRegs[2]);
}
else
{
MMC1CHRHook4(0x0000,(DRegs[1]&0xFE));
MMC1CHRHook4(0x1000,DRegs[1]|1);
}
}
else
{
if(DRegs[0]&0x10)
{
setchr4(0x0000,DRegs[1]);
setchr4(0x1000,DRegs[2]);
}
else
setchr8(DRegs[1]>>1);
}
}
static void MMC1PRG(void)
{
uint8 offs=DRegs[1]&0x10;
if(MMC1PRGHook16)
{
switch(DRegs[0]&0xC)
{
case 0xC: MMC1PRGHook16(0x8000,(DRegs[3]+offs));
MMC1PRGHook16(0xC000,0xF+offs);
break;
case 0x8: MMC1PRGHook16(0xC000,(DRegs[3]+offs));
MMC1PRGHook16(0x8000,offs);
break;
case 0x0:
case 0x4:
MMC1PRGHook16(0x8000,((DRegs[3]&~1)+offs));
MMC1PRGHook16(0xc000,((DRegs[3]&~1)+offs+1));
break;
}
}
else
{
switch(DRegs[0]&0xC)
{
case 0xC: setprg16(0x8000,(DRegs[3]+offs));
setprg16(0xC000,0xF+offs);
break;
case 0x8: setprg16(0xC000,(DRegs[3]+offs));
setprg16(0x8000,offs);
break;
case 0x0:
case 0x4:
setprg16(0x8000,((DRegs[3]&~1)+offs));
setprg16(0xc000,((DRegs[3]&~1)+offs+1));
break;
}
}
}
static void MMC1MIRROR(void)
{
if(!is171)
switch(DRegs[0]&3)
{
case 2: setmirror(MI_V); break;
case 3: setmirror(MI_H); break;
case 0: setmirror(MI_0); break;
case 1: setmirror(MI_1); break;
}
}
static uint64 lreset;
static DECLFW(MMC1_write)
{
int n=(A>>13)-4;
//FCEU_DispMessage("%016x",timestampbase+timestamp);
// FCEU_printf("$%04x:$%02x, $%04x\n",A,V,X.PC);
//DumpMem("out",0xe000,0xffff);
/* The MMC1 is busy so ignore the write. */
/* As of version FCE Ultra 0.81, the timestamp is only
increased before each instruction is executed(in other words
precision isn't that great), but this should still work to
deal with 2 writes in a row from a single RMW instruction.
*/
if((timestampbase+timestamp)<(lreset+2))
return;
// FCEU_printf("Write %04x:%02x\n",A,V);
if(V&0x80)
{
DRegs[0]|=0xC;
BufferShift=Buffer=0;
MMC1PRG();
lreset=timestampbase+timestamp;
return;
}
Buffer|=(V&1)<<(BufferShift++);
if(BufferShift==5)
{
DRegs[n] = Buffer;
BufferShift = Buffer = 0;
switch(n)
{
case 0: MMC1MIRROR(); MMC1CHR(); MMC1PRG(); break;
case 1: MMC1CHR(); MMC1PRG(); break;
case 2: MMC1CHR(); break;
case 3: MMC1PRG(); break;
}
}
}
static void MMC1_Restore(int version)
{
MMC1MIRROR();
MMC1CHR();
MMC1PRG();
lreset=0; /* timestamp(base) is not stored in save states. */
}
static void MMC1CMReset(void)
{
int i;
for(i=0;i<4;i++)
DRegs[i]=0;
Buffer = BufferShift = 0;
DRegs[0]=0x1F;
DRegs[1]=0;
DRegs[2]=0; // Should this be something other than 0?
DRegs[3]=0;
MMC1MIRROR();
MMC1CHR();
MMC1PRG();
}
static int DetectMMC1WRAMSize(uint32 crc32)
{
switch(crc32)
{
case 0xc6182024: /* Romance of the 3 Kingdoms */
case 0x2225c20f: /* Genghis Khan */
case 0x4642dda6: /* Nobunaga's Ambition */
case 0x29449ba9: /* "" "" (J) */
case 0x2b11e0b0: /* "" "" (J) */
case 0xb8747abf: /* Best Play Pro Yakyuu Special (J) */
case 0xc9556b36: /* Final Fantasy I & II (J) [!] */
FCEU_printf(" >8KB external WRAM present. Use UNIF if you hack the ROM image.\n");
return(16);
break;
default:return(8);
}
}
static uint32 NWCIRQCount;
static uint8 NWCRec;
#define NWCDIP 0xE
static void NWCIRQHook(int a)
{
if(!(NWCRec&0x10))
{
NWCIRQCount+=a;
if((NWCIRQCount|(NWCDIP<<25))>=0x3e000000)
{
NWCIRQCount=0;
X6502_IRQBegin(FCEU_IQEXT);
}
}
}
static void NWCCHRHook(uint32 A, uint8 V)
{
if((V&0x10)) // && !(NWCRec&0x10))
{
NWCIRQCount=0;
X6502_IRQEnd(FCEU_IQEXT);
}
NWCRec=V;
if(V&0x08)
MMC1PRG();
else
setprg32(0x8000,(V>>1)&3);
}
static void NWCPRGHook(uint32 A, uint8 V)
{
if(NWCRec&0x8)
setprg16(A,8|(V&0x7));
else
setprg32(0x8000,(NWCRec>>1)&3);
}
static void NWCPower(void)
{
GenMMC1Power();
setchr8r(0,0);
}
void Mapper105_Init(CartInfo *info)
{
GenMMC1Init(info, 256, 256, 8, 0);
MMC1CHRHook4=NWCCHRHook;
MMC1PRGHook16=NWCPRGHook;
MapIRQHook=NWCIRQHook;
info->Power=NWCPower;
}
static void GenMMC1Power(void)
{
lreset=0;
if(mmc1opts&1)
{
FCEU_CheatAddRAM(8,0x6000,WRAM);
if(mmc1opts&4)
FCEU_dwmemset(WRAM,0,8192)
else if(!(mmc1opts&2))
FCEU_dwmemset(WRAM,0,8192);
}
SetWriteHandler(0x8000,0xFFFF,MMC1_write);
SetReadHandler(0x8000,0xFFFF,CartBR);
if(mmc1opts&1)
{
SetReadHandler(0x6000,0x7FFF,MAWRAM);
SetWriteHandler(0x6000,0x7FFF,MBWRAM);
setprg8r(0x10,0x6000,0);
}
MMC1CMReset();
}
static void GenMMC1Close(void)
{
if(CHRRAM)
FCEU_gfree(CHRRAM);
if(WRAM)
FCEU_gfree(WRAM);
CHRRAM=WRAM=NULL;
}
static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery)
{
is155=0;
info->Close=GenMMC1Close;
MMC1PRGHook16=MMC1CHRHook4=0;
mmc1opts=0;
PRGmask16[0]&=(prg>>14)-1;
CHRmask4[0]&=(chr>>12)-1;
CHRmask8[0]&=(chr>>13)-1;
if(wram)
{
WRAM=(uint8*)FCEU_gmalloc(wram*1024);
//mbg 17-jun-08 - this shouldve been cleared to re-initialize save ram
//ch4 10-dec-08 - nope, this souldn't
//mbg 29-mar-09 - no time to debate this, we need to keep from breaking some old stuff.
//we really need to make up a policy for how compatibility and accuracy can be resolved.
memset(WRAM,0,wram*1024);
mmc1opts|=1;
if(wram>8) mmc1opts|=4;
SetupCartPRGMapping(0x10,WRAM,wram*1024,1);
AddExState(WRAM, wram*1024, 0, "WRAM");
if(battery)
{
mmc1opts|=2;
info->SaveGame[0]=WRAM+((mmc1opts&4)?8192:0);
info->SaveGameLen[0]=8192;
}
}
if(!chr)
{
CHRRAM=(uint8*)FCEU_gmalloc(8192);
SetupCartCHRMapping(0, CHRRAM, 8192, 1);
AddExState(CHRRAM, 8192, 0, "CHRR");
}
AddExState(DRegs, 4, 0, "DREG");
info->Power=GenMMC1Power;
GameStateRestore=MMC1_Restore;
AddExState(&lreset, 8, 1, "LRST");
AddExState(&Buffer, 1, 1, "BFFR");
AddExState(&BufferShift, 1, 1, "BFRS");
}
void Mapper1_Init(CartInfo *info)
{
int ws=DetectMMC1WRAMSize(info->CRC32);
GenMMC1Init(info, 512, 256, ws, info->battery);
}
/* Same as mapper 1, without respect for WRAM enable bit. */
void Mapper155_Init(CartInfo *info)
{
GenMMC1Init(info,512,256,8,info->battery);
is155=1;
}
/* Same as mapper 1, with different (or without) mirroring control. */
/* Kaiser KS7058 board, KS203 custom chip */
void Mapper171_Init(CartInfo *info)
{
GenMMC1Init(info,32,32,0,0);
is171=1;
}
void SAROM_Init(CartInfo *info)
{
GenMMC1Init(info, 128, 64, 8, info->battery);
}
void SBROM_Init(CartInfo *info)
{
GenMMC1Init(info, 128, 64, 0, 0);
}
void SCROM_Init(CartInfo *info)
{
GenMMC1Init(info, 128, 128, 0, 0);
}
void SEROM_Init(CartInfo *info)
{
GenMMC1Init(info, 32, 64, 0, 0);
}
void SGROM_Init(CartInfo *info)
{
GenMMC1Init(info, 256, 0, 0, 0);
}
void SKROM_Init(CartInfo *info)
{
GenMMC1Init(info, 256, 64, 8, info->battery);
}
void SLROM_Init(CartInfo *info)
{
GenMMC1Init(info, 256, 128, 0, 0);
}
void SL1ROM_Init(CartInfo *info)
{
GenMMC1Init(info, 128, 128, 0, 0);
}
/* Begin unknown - may be wrong - perhaps they use different MMC1s from the
similarly functioning boards?
*/
void SL2ROM_Init(CartInfo *info)
{
GenMMC1Init(info, 256, 256, 0, 0);
}
void SFROM_Init(CartInfo *info)
{
GenMMC1Init(info, 256, 256, 0, 0);
}
void SHROM_Init(CartInfo *info)
{
GenMMC1Init(info, 256, 256, 0, 0);
}
/* End unknown */
/* */
/* */
void SNROM_Init(CartInfo *info)
{
GenMMC1Init(info, 256, 0, 8, info->battery);
}
void SOROM_Init(CartInfo *info)
{
GenMMC1Init(info, 256, 0, 16, info->battery);
}

View File

@ -21,19 +21,19 @@
*/
/* Code for emulating iNES mappers 4,12,44,45,47,49,52,74,114,115,116,118,
119,148,165,205,214,215,245,249,250,254
119,165,205,214,215,245,249,250,254
*/
#include "mapinc.h"
#include "mmc3.h"
uint8 MMC3_cmd;
uint8 *WRAM;
uint8 *CHRRAM;
uint32 CHRRAMSize;
uint8 DRegBuf[8];
uint8 EXPREGS[8]; /* For bootleg games, mostly. */
static uint8 *WRAM;
static uint8 *CHRRAM;
static uint8 A000B,A001B;
#undef IRQCount
@ -128,7 +128,9 @@ DECLFW(MMC3_CMDWrite)
{
case 0x8000:
if((V&0x40) != (MMC3_cmd&0x40))
{
FixMMC3PRG(V);
}
if((V&0x80) != (MMC3_cmd&0x80))
FixMMC3CHR(V);
MMC3_cmd = V;
@ -170,7 +172,6 @@ DECLFW(MMC3_CMDWrite)
break;
case 0xA001:
A001B=V;
Write_IRQFM(0x4017,0x40);
break;
}
}
@ -232,7 +233,8 @@ void GenMMC3Restore(int version)
static void GENCWRAP(uint32 A, uint8 V)
{
setchr1(A,V);
// if(!UNIFchrrama) // Yong Zhe Dou E Long - Dragon Quest VI (As).nes NEEDS THIS
setchr1(A,V); // Business Wars NEEDS THIS
}
static void GENPWRAP(uint32 A, uint8 V)
@ -273,6 +275,8 @@ static DECLFR(MAWRAMMMC6)
void GenMMC3Power(void)
{
if(UNIFchrrama) setchr8(0);
SetWriteHandler(0x8000,0xBFFF,MMC3_CMDWrite);
SetWriteHandler(0xC000,0xFFFF,MMC3_IRQWrite);
SetReadHandler(0x8000,0xFFFF,CartBR);
@ -303,14 +307,14 @@ void GenMMC3Power(void)
static void GenMMC3Close(void)
{
if(CHRRAM)
free(CHRRAM);
FCEU_gfree(CHRRAM);
if(WRAM)
free(WRAM);
FCEU_gfree(WRAM);
CHRRAM=WRAM=NULL;
}
//static uint16 _a12;
//static void FP_FASTAPASS(1) MMC3_PPU(uint32 A)
//static void MMC3_PPU(uint32 A)
//{
// if(A&0x2000)return;
// if((!_a12)&&(A&0x1000))
@ -333,7 +337,7 @@ void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery)
if(wram)
{
mmc3opts|=1;
WRAM=(uint8*)malloc(wrams);
WRAM=(uint8*)FCEU_gmalloc(wrams);
AddExState(WRAM, wrams, 0, "WRAM");
}
@ -528,15 +532,17 @@ void Mapper44_Init(CartInfo *info)
static void M45CW(uint32 A, uint8 V)
{
if(!UNIFchrrama)
{
uint32 NV=V;
if(EXPREGS[2]&8)
NV&=(1<<((EXPREGS[2]&7)+1))-1;
// else
// NV&=0;
else
if(EXPREGS[2])
NV&=0; // hack ;( don't know exactly how it should be
NV|=EXPREGS[0]|((EXPREGS[2]&0xF0)<<4);
setchr1(A,NV);
}
}
static void M45PW(uint32 A, uint8 V)
@ -625,7 +631,7 @@ static void M47Power(void)
void Mapper47_Init(CartInfo *info)
{
GenMMC3_Init(info, 512, 256, 8, info->battery);
GenMMC3_Init(info, 512, 256, 8, 0);
pwrap=M47PW;
cwrap=M47CW;
info->Power=M47Power;
@ -757,7 +763,7 @@ void Mapper74_Init(CartInfo *info)
GenMMC3_Init(info, 512, 256, 8, info->battery);
cwrap=M74CW;
CHRRAMSize=2048;
CHRRAM=(uint8*)malloc(CHRRAMSize);
CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
}
@ -851,6 +857,8 @@ static void M115CW(uint32 A, uint8 V)
static DECLFW(M115Write)
{
// FCEU_printf("%04x:%04x\n",A,V);
if(A==0x5080) EXPREGS[2]=V;
if(A==0x6000)
EXPREGS[0]=V;
else if(A==0x6001)
@ -858,11 +866,16 @@ static DECLFW(M115Write)
FixMMC3PRG(MMC3_cmd);
}
static DECLFR(M115Read)
{
return EXPREGS[2];
}
static void M115Power(void)
{
GenMMC3Power();
SetWriteHandler(0x4100,0x7FFF,M115Write);
SetReadHandler(0x4100,0x7FFF,0);
SetReadHandler(0x5000,0x5FFF,M115Read);
}
void Mapper115_Init(CartInfo *info)
@ -902,7 +915,7 @@ void Mapper116_Init(CartInfo *info)
GenMMC3_Init(info, 128, 512, 0, 0);
cwrap=M116CW;
info->Power=M116Power;
CHRRAM = (uint8*)malloc(8192);
CHRRAM = (uint8*)FCEU_gmalloc(8192);
SetupCartCHRMapping(0x10, CHRRAM, 8192, 1);
AddExState(EXPREGS, 4, 0, "EXPR");
}
@ -912,7 +925,7 @@ void Mapper116_Init(CartInfo *info)
static uint8 PPUCHRBus;
static uint8 TKSMIR[8];
static void FP_FASTAPASS(1) TKSPPU(uint32 A)
static void TKSPPU(uint32 A)
{
A&=0x1FFF;
A>>=10;
@ -928,14 +941,14 @@ static void TKSWRAP(uint32 A, uint8 V)
setmirror(MI_0+(V>>7));
}
void Mapper118_Init(CartInfo *info)
{
GenMMC3_Init(info, 512, 256, 8, info->battery);
cwrap=TKSWRAP;
mwrap=GENNOMWRAP;
PPU_hook=TKSPPU;
AddExState(&PPUCHRBus, 1, 0, "PPUC");
}
//void Mapper118_Init(CartInfo *info)
//{
// GenMMC3_Init(info, 512, 256, 8, info->battery);
// cwrap=TKSWRAP;
// mwrap=GENNOMWRAP;
// PPU_hook=TKSPPU;
// AddExState(&PPUCHRBus, 1, 0, "PPUC");
//}
// ---------------------------- Mapper 119 ------------------------------
@ -949,10 +962,52 @@ void Mapper119_Init(CartInfo *info)
GenMMC3_Init(info, 512, 64, 0, 0);
cwrap=TQWRAP;
CHRRAMSize=8192;
CHRRAM=(uint8*)malloc(CHRRAMSize);
CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
}
// ---------------------------- Mapper 134 ------------------------------
static void M134PW(uint32 A, uint8 V)
{
setprg8(A,(V&0x1F)|((EXPREGS[0]&2)<<4));
}
static void M134CW(uint32 A, uint8 V)
{
setchr1(A,(V&0xFF)|((EXPREGS[0]&0x20)<<3));
}
static DECLFW(M134Write)
{
EXPREGS[0]=V;
FixMMC3CHR(MMC3_cmd);
FixMMC3PRG(MMC3_cmd);
}
static void M134Power(void)
{
EXPREGS[0]=0;
GenMMC3Power();
SetWriteHandler(0x6001,0x6001,M134Write);
}
static void M134Reset(void)
{
EXPREGS[0]=0;
MMC3RegReset();
}
void Mapper134_Init(CartInfo *info)
{
GenMMC3_Init(info, 256, 256, 0, 0);
pwrap=M134PW;
cwrap=M134CW;
info->Power=M134Power;
info->Reset=M134Reset;
AddExState(EXPREGS, 4, 0, "EXPR");
}
// ---------------------------- Mapper 165 ------------------------------
static void M165CW(uint32 A, uint8 V)
@ -989,7 +1044,7 @@ static void M165CWM(uint32 A, uint8 V)
M165PPUFE();
}
static void FP_FASTAPASS(1) M165PPU(uint32 A)
static void M165PPU(uint32 A)
{
if((A&0x1FF0)==0x1FD0)
{
@ -1015,7 +1070,7 @@ void Mapper165_Init(CartInfo *info)
PPU_hook=M165PPU;
info->Power=M165Power;
CHRRAMSize = 4096;
CHRRAM = (uint8*)malloc(CHRRAMSize);
CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSize);
SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
AddExState(EXPREGS, 4, 0, "EXPR");
@ -1068,7 +1123,7 @@ void Mapper191_Init(CartInfo *info)
GenMMC3_Init(info, 256, 256, 8, info->battery);
cwrap=M191CW;
CHRRAMSize=2048;
CHRRAM=(uint8*)malloc(CHRRAMSize);
CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
}
@ -1088,7 +1143,7 @@ void Mapper192_Init(CartInfo *info)
GenMMC3_Init(info, 512, 256, 8, info->battery);
cwrap=M192CW;
CHRRAMSize=4096;
CHRRAM=(uint8*)malloc(CHRRAMSize);
CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
}
@ -1108,7 +1163,7 @@ void Mapper194_Init(CartInfo *info)
GenMMC3_Init(info, 512, 256, 8, info->battery);
cwrap=M194CW;
CHRRAMSize=2048;
CHRRAM=(uint8*)malloc(CHRRAMSize);
CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
}
@ -1136,7 +1191,7 @@ static void M195Power(void)
static void M195Close(void)
{
if(wramtw)
free(wramtw);
FCEU_gfree(wramtw);
wramtw=NULL;
}
@ -1147,15 +1202,56 @@ void Mapper195_Init(CartInfo *info)
info->Power=M195Power;
info->Close=M195Close;
CHRRAMSize=4096;
CHRRAM=(uint8*)malloc(CHRRAMSize);
CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
wramsize=4096;
wramtw=(uint8*)malloc(wramsize);
wramtw=(uint8*)FCEU_gmalloc(wramsize);
SetupCartPRGMapping(0x10, wramtw, wramsize, 1);
AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
AddExState(wramtw, wramsize, 0, "WRAMTW");
}
// ---------------------------- Mapper 196 -------------------------------
static DECLFW(Mapper196Write)
{
A=(A&0xFFFE)|((A>>2)&1)|((A>>3)&1)|((A>>1)&1);
if(A >= 0xC000)
MMC3_IRQWrite(A,V);
else
MMC3_CMDWrite(A,V);
}
static void Mapper196Power(void)
{
GenMMC3Power();
SetWriteHandler(0x8000,0xFFFF,Mapper196Write);
}
void Mapper196_Init(CartInfo *info)
{
GenMMC3_Init(info, 128, 128, 0, 0);
info->Power=Mapper196Power;
}
// ---------------------------- Mapper 197 -------------------------------
static void M197CW(uint32 A, uint8 V)
{
if(A==0x0000)
setchr4(0x0000,V>>1);
else if(A==0x1000)
setchr2(0x1000,V);
else if(A==0x1400)
setchr2(0x1800,V);
}
void Mapper197_Init(CartInfo *info)
{
GenMMC3_Init(info, 128, 512, 8, 0);
cwrap=M197CW;
}
// ---------------------------- Mapper 198 -------------------------------
static void M198PW(uint32 A, uint8 V)
@ -1166,25 +1262,14 @@ static void M198PW(uint32 A, uint8 V)
setprg8(A,V);
}
static void M198CW(uint32 A, uint8 V)
{
if(A==0x0000)
setchr4(0x0000,V>>1);
else if(A==0x1000)
setchr2(0x1000,V);
else if(A==0x1400)
setchr2(0x1800,V);
}
void Mapper198_Init(CartInfo *info)
{
GenMMC3_Init(info, 1024, 256, 8, info->battery);
pwrap=M198PW;
cwrap=M198CW;
info->Power=M195Power;
info->Close=M195Close;
wramsize=4096;
wramtw=(uint8*)malloc(wramsize);
wramtw=(uint8*)FCEU_gmalloc(wramsize);
SetupCartPRGMapping(0x10, wramtw, wramsize, 1);
AddExState(wramtw, wramsize, 0, "WRAMTW");
}
@ -1289,17 +1374,17 @@ static DECLFW(M215ExWrite)
// FCEU_printf("bs %04x %02x (%04x)\n",A,V,A&0x5007);
switch(A)
{
case 0x6000:
// case 0x6000:
case 0x5000:
EXPREGS[0]=V;
FixMMC3PRG(MMC3_cmd);
break;
case 0x6001:
// case 0x6001:
case 0x5001:
EXPREGS[1]=V;
FixMMC3CHR(MMC3_cmd);
break;
case 0x6007:
// case 0x6007:
case 0x5007:
EXPREGS[2]=V;
MMC3RegReset();
@ -1550,6 +1635,11 @@ void Mapper254_Init(CartInfo *info)
// ---------------------------- UNIF Boards -----------------------------
void TBROM_Init(CartInfo *info)
{
GenMMC3_Init(info, 64, 64, 0, 0);
}
void TEROM_Init(CartInfo *info)
{
GenMMC3_Init(info, 32, 32, 0, 0);
@ -1603,7 +1693,7 @@ void TQROM_Init(CartInfo *info)
GenMMC3_Init(info, 512, 64, 0, 0);
cwrap=TQWRAP;
CHRRAMSize=8192;
CHRRAM=(uint8*)malloc(CHRRAMSize);
CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
}

View File

@ -1,6 +1,4 @@
extern uint8 MMC3_cmd;
extern uint8 *WRAM;
extern uint8 *CHRRAM;
extern uint8 EXPREGS[8];
extern uint8 DRegBuf[8];

View File

@ -0,0 +1,103 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2006 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* Mortal Kombat 2 YOKO */
#include "mapinc.h"
#include "mmc3.h"
static uint8 reg[8];
static SFORMAT StateRegs[]=
{
{reg, 8, "REGS"},
{0}
};
static void Sync(void)
{
// FCEU_printf("(%02x, %02x)\n",reg[3],reg[4]);
setprg8(0x8000,reg[0]);
setprg8(0xA000,reg[1]);
setprg8(0xC000,reg[2]);
setprg8(0xE000,~0);
// setchr2(0x0000,reg[3]);
// setchr2(0x0800,reg[4]);
// setchr2(0x1000,reg[5]);
// setchr2(0x1800,reg[6]);
setchr2(0x0000,reg[3]);
setchr2(0x0800,reg[4]);
setchr2(0x1000,reg[5]);
setchr2(0x1800,reg[6]);
}
static DECLFW(MCN22MWrite)
{
//FCEU_printf("bs %04x %02x\n",A,V);
switch(A)
{
case 0x8c00:
case 0x8c01:
case 0x8c02: reg[A&3]=V; break;
case 0x8d10: reg[3]=V; break;
case 0x8d11: reg[4]=V; break;
case 0x8d16: reg[5]=V; break;
case 0x8d17: reg[6]=V; break;
}
Sync();
}
static void MCN22MPower(void)
{
reg[0]=reg[1]=reg[2]=0;
Sync();
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,MCN22MWrite);
}
/*
static void MCN22MIRQHook(void)
{
int count = IRQCount;
if(!count || IRQReload)
{
IRQCount = IRQLatch;
IRQReload = 0;
}
else
IRQCount--;
if(!IRQCount)
{
if(IRQa)
{
X6502_IRQBegin(FCEU_IQEXT);
}
}
}
*/
static void StateRestore(int version)
{
Sync();
}
void UNLCN22M_Init(CartInfo *info)
{
info->Power=MCN22MPower;
// GameHBIRQHook=MCN22MIRQHook;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,470 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2002 Xodnizel
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint16 IRQCount;
static uint8 IRQa;
static uint8 WRAM[8192];
static uint8 IRAM[128];
static DECLFR(AWRAM)
{
return(WRAM[A-0x6000]);
}
static DECLFW(BWRAM)
{
WRAM[A-0x6000]=V;
}
void Mapper19_ESI(void);
static uint8 NTAPage[4];
static uint8 dopol;
static uint8 gorfus;
static uint8 gorko;
static void NamcoSound(int Count);
static void NamcoSoundHack(void);
static void DoNamcoSound(int32 *Wave, int Count);
static void DoNamcoSoundHQ(void);
static void SyncHQ(int32 ts);
static int is210; /* Lesser mapper. */
static uint8 PRG[3];
static uint8 CHR[8];
static SFORMAT N106_StateRegs[]={
{PRG,3,"PRG"},
{CHR,8,"CHR"},
{NTAPage,4,"NTA"},
{0}
};
static void SyncPRG(void)
{
setprg8(0x8000,PRG[0]);
setprg8(0xa000,PRG[1]);
setprg8(0xc000,PRG[2]);
setprg8(0xe000,0x3F);
}
static void NamcoIRQHook(int a)
{
if(IRQa)
{
IRQCount+=a;
if(IRQCount>=0x7FFF)
{
X6502_IRQBegin(FCEU_IQEXT);
IRQa=0;
IRQCount=0x7FFF; //7FFF;
}
}
}
static DECLFR(Namco_Read4800)
{
uint8 ret=IRAM[dopol&0x7f];
/* Maybe I should call NamcoSoundHack() here? */
if(!fceuindbg)
if(dopol&0x80)
dopol=(dopol&0x80)|((dopol+1)&0x7f);
return ret;
}
static DECLFR(Namco_Read5000)
{
return(IRQCount);
}
static DECLFR(Namco_Read5800)
{
return(IRQCount>>8);
}
static void DoNTARAMROM(int w, uint8 V)
{
NTAPage[w]=V;
if(V>=0xE0)
setntamem(NTARAM+((V&1)<<10), 1, w);
else
{
V&=CHRmask1[0];
setntamem(CHRptr[0]+(V<<10), 0, w);
}
}
static void FixNTAR(void)
{
int x;
for(x=0;x<4;x++)
DoNTARAMROM(x,NTAPage[x]);
}
static void DoCHRRAMROM(int x, uint8 V)
{
CHR[x]=V;
if(!is210 && !((gorfus>>((x>>2)+6))&1) && (V>=0xE0))
{
// printf("BLAHAHA: %d, %02x\n",x,V);
//setchr1r(0x10,x<<10,V&7);
}
else
setchr1(x<<10,V);
}
static void FixCRR(void)
{
int x;
for(x=0;x<8;x++)
DoCHRRAMROM(x,CHR[x]);
}
static DECLFW(Mapper19C0D8_write)
{
DoNTARAMROM((A-0xC000)>>11,V);
}
static uint32 FreqCache[8];
static uint32 EnvCache[8];
static uint32 LengthCache[8];
static void FixCache(int a,int V)
{
int w=(a>>3)&0x7;
switch(a&0x07)
{
case 0x00:FreqCache[w]&=~0x000000FF;FreqCache[w]|=V;break;
case 0x02:FreqCache[w]&=~0x0000FF00;FreqCache[w]|=V<<8;break;
case 0x04:FreqCache[w]&=~0x00030000;FreqCache[w]|=(V&3)<<16;
LengthCache[w]=(8-((V>>2)&7))<<2;
break;
case 0x07:EnvCache[w]=(double)(V&0xF)*576716;break;
}
}
static DECLFW(Mapper19_write)
{
A&=0xF800;
if(A>=0x8000 && A<=0xb800)
DoCHRRAMROM((A-0x8000)>>11,V);
else switch(A)
{
case 0x4800:
if(dopol&0x40)
{
if(FSettings.SndRate)
{
NamcoSoundHack();
GameExpSound.Fill=NamcoSound;
GameExpSound.HiFill=DoNamcoSoundHQ;
GameExpSound.HiSync=SyncHQ;
}
FixCache(dopol,V);
}
IRAM[dopol&0x7f]=V;
if(dopol&0x80)
dopol=(dopol&0x80)|((dopol+1)&0x7f);
break;
case 0xf800:
dopol=V;break;
case 0x5000:
IRQCount&=0xFF00;IRQCount|=V;X6502_IRQEnd(FCEU_IQEXT);break;
case 0x5800:
IRQCount&=0x00ff;IRQCount|=(V&0x7F)<<8;
IRQa=V&0x80;
X6502_IRQEnd(FCEU_IQEXT);
break;
case 0xE000:
gorko=V&0xC0;
PRG[0]=V&0x3F;
SyncPRG();
break;
case 0xE800:
gorfus=V&0xC0;
FixCRR();
PRG[1]=V&0x3F;
SyncPRG();
break;
case 0xF000:
PRG[2]=V&0x3F;
SyncPRG();
break;
}
}
static int dwave=0;
static void NamcoSoundHack(void)
{
int32 z,a;
if(FSettings.soundq>=1)
{
DoNamcoSoundHQ();
return;
}
z=((SOUNDTS<<16)/soundtsinc)>>4;
a=z-dwave;
if(a) DoNamcoSound(&Wave[dwave], a);
dwave+=a;
}
static void NamcoSound(int Count)
{
int32 z,a;
z=((SOUNDTS<<16)/soundtsinc)>>4;
a=z-dwave;
if(a) DoNamcoSound(&Wave[dwave], a);
dwave=0;
}
static uint32 PlayIndex[8];
static int32 vcount[8];
static int32 CVBC;
#define TOINDEX (16+1)
// 16:15
static void SyncHQ(int32 ts)
{
CVBC=ts;
}
/* Things to do:
1 Read freq low
2 Read freq mid
3 Read freq high
4 Read envelope
...?
*/
static INLINE uint32 FetchDuff(uint32 P, uint32 envelope)
{
uint32 duff;
duff=IRAM[((IRAM[0x46+(P<<3)]+(PlayIndex[P]>>TOINDEX))&0xFF)>>1];
if((IRAM[0x46+(P<<3)]+(PlayIndex[P]>>TOINDEX))&1)
duff>>=4;
duff&=0xF;
duff=(duff*envelope)>>16;
return(duff);
}
static void DoNamcoSoundHQ(void)
{
uint32 V; //mbg merge 7/17/06 made uint32
int32 P;
int32 cyclesuck=(((IRAM[0x7F]>>4)&7)+1)*15;
for(P=7;P>=(7-((IRAM[0x7F]>>4)&7));P--)
{
if((IRAM[0x44+(P<<3)]&0xE0) && (IRAM[0x47+(P<<3)]&0xF))
{
uint32 freq;
int32 vco;
uint32 duff2,lengo,envelope;
vco=vcount[P];
freq=FreqCache[P];
envelope=EnvCache[P];
lengo=LengthCache[P];
duff2=FetchDuff(P,envelope);
for(V=CVBC<<1;V<SOUNDTS<<1;V++)
{
WaveHi[V>>1]+=duff2;
if(!vco)
{
PlayIndex[P]+=freq;
while((PlayIndex[P]>>TOINDEX)>=lengo) PlayIndex[P]-=lengo<<TOINDEX;
duff2=FetchDuff(P,envelope);
vco=cyclesuck;
}
vco--;
}
vcount[P]=vco;
}
}
CVBC=SOUNDTS;
}
static void DoNamcoSound(int32 *Wave, int Count)
{
int P,V;
for(P=7;P>=7-((IRAM[0x7F]>>4)&7);P--)
{
if((IRAM[0x44+(P<<3)]&0xE0) && (IRAM[0x47+(P<<3)]&0xF))
{
int32 inc;
uint32 freq;
int32 vco;
uint32 duff,duff2,lengo,envelope;
vco=vcount[P];
freq=FreqCache[P];
envelope=EnvCache[P];
lengo=LengthCache[P];
if(!freq) {/*printf("Ack");*/ continue;}
{
int c=((IRAM[0x7F]>>4)&7)+1;
inc=(long double)(FSettings.SndRate<<15)/((long double)freq*21477272/((long double)0x400000*c*45));
}
duff=IRAM[(((IRAM[0x46+(P<<3)]+PlayIndex[P])&0xFF)>>1)];
if((IRAM[0x46+(P<<3)]+PlayIndex[P])&1)
duff>>=4;
duff&=0xF;
duff2=(duff*envelope)>>19;
for(V=0;V<Count*16;V++)
{
if(vco>=inc)
{
PlayIndex[P]++;
if(PlayIndex[P]>=lengo)
PlayIndex[P]=0;
vco-=inc;
duff=IRAM[(((IRAM[0x46+(P<<3)]+PlayIndex[P])&0xFF)>>1)];
if((IRAM[0x46+(P<<3)]+PlayIndex[P])&1)
duff>>=4;
duff&=0xF;
duff2=(duff*envelope)>>19;
}
Wave[V>>4]+=duff2;
vco+=0x8000;
}
vcount[P]=vco;
}
}
}
static void Mapper19_StateRestore(int version)
{
int x;
SyncPRG();
FixNTAR();
FixCRR();
for(x=0x40;x<0x80;x++)
FixCache(x,IRAM[x]);
}
static void M19SC(void)
{
if(FSettings.SndRate)
Mapper19_ESI();
}
void Mapper19_ESI(void)
{
GameExpSound.RChange=M19SC;
memset(vcount,0,sizeof(vcount));
memset(PlayIndex,0,sizeof(PlayIndex));
CVBC=0;
}
void NSFN106_Init(void)
{
SetWriteHandler(0xf800,0xffff,Mapper19_write);
SetWriteHandler(0x4800,0x4fff,Mapper19_write);
SetReadHandler(0x4800,0x4fff,Namco_Read4800);
Mapper19_ESI();
}
static int battery=0;
static void N106_Power(void)
{
int x;
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xffff,Mapper19_write);
SetWriteHandler(0x4020,0x5fff,Mapper19_write);
if(!is210)
{
SetWriteHandler(0xc000,0xdfff,Mapper19C0D8_write);
SetReadHandler(0x4800,0x4fff,Namco_Read4800);
SetReadHandler(0x5000,0x57ff,Namco_Read5000);
SetReadHandler(0x5800,0x5fff,Namco_Read5800);
NTAPage[0]=NTAPage[1]=NTAPage[2]=NTAPage[3]=0xFF;
FixNTAR();
}
SetReadHandler(0x6000,0x7FFF,AWRAM);
SetWriteHandler(0x6000,0x7FFF,BWRAM);
FCEU_CheatAddRAM(8,0x6000,WRAM);
gorfus=0xFF;
SyncPRG();
FixCRR();
if(!battery)
{
FCEU_dwmemset(WRAM,0,8192);
FCEU_dwmemset(IRAM,0,128);
}
for(x=0x40;x<0x80;x++)
FixCache(x,IRAM[x]);
}
void Mapper19_Init(CartInfo *info)
{
is210=0;
battery=info->battery;
info->Power=N106_Power;
MapIRQHook=NamcoIRQHook;
GameStateRestore=Mapper19_StateRestore;
GameExpSound.RChange=M19SC;
if(FSettings.SndRate)
Mapper19_ESI();
AddExState(WRAM, 8192, 0, "WRAM");
AddExState(IRAM, 128, 0, "IRAM");
AddExState(N106_StateRegs, ~0, 0, 0);
if(info->battery)
{
info->SaveGame[0]=WRAM;
info->SaveGameLen[0]=8192;
info->SaveGame[1]=IRAM;
info->SaveGameLen[1]=128;
}
}
static void Mapper210_StateRestore(int version)
{
SyncPRG();
FixCRR();
}
void Mapper210_Init(CartInfo *info)
{
is210=1;
GameStateRestore=Mapper210_StateRestore;
info->Power=N106_Power;
AddExState(WRAM, 8192, 0, "WRAM");
}

View File

@ -0,0 +1,97 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2006 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 700in1 and 400in1 carts
*/
#include "mapinc.h"
static uint16 cmd, bank;
static SFORMAT StateRegs[]=
{
{&cmd, 2, "CMD"},
{&bank, 2, "BANK"},
{0}
};
static void Sync(void)
{
setmirror((cmd&1)^1);
setchr8(0);
if(cmd&2)
{
if(cmd&0x100)
{
setprg16(0x8000,((cmd&0xe0)>>2)|bank);
setprg16(0xC000,((cmd&0xe0)>>2)|7);
}
else
{
setprg16(0x8000,((cmd&0xe0)>>2)|(bank&6));
setprg16(0xC000,((cmd&0xe0)>>2)|((bank&6)|1));
}
}
else
{
setprg16(0x8000,((cmd&0xe0)>>2)|bank);
setprg16(0xC000,((cmd&0xe0)>>2)|bank);
}
}
static DECLFW(UNLN625092WriteCommand)
{
cmd=A;
Sync();
}
static DECLFW(UNLN625092WriteBank)
{
bank=A&7;
Sync();
}
static void UNLN625092Power(void)
{
cmd=0;
bank=0;
Sync();
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xBFFF,UNLN625092WriteCommand);
SetWriteHandler(0xC000,0xFFFF,UNLN625092WriteBank);
}
static void UNLN625092Reset(void)
{
cmd=0;
bank=0;
}
static void StateRestore(int version)
{
Sync();
}
void UNLN625092_Init(CartInfo *info)
{
info->Reset=UNLN625092Reset;
info->Power=UNLN625092Power;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -20,16 +20,18 @@
#include "mapinc.h"
static uint8 latch;
static void DoNovel(void)
{
setprg32(0x8000,GameMemBlock[0]&3);
setchr8(GameMemBlock[0]&7);
setprg32(0x8000,latch&3);
setchr8(latch&7);
}
static DECLFW(NovelWrite)
{
GameMemBlock[0]=A&0xFF;
DoNovel();
latch=A&0xFF;
DoNovel();
}
static void NovelReset(void)
@ -42,12 +44,12 @@ static void NovelReset(void)
static void NovelRestore(int version)
{
DoNovel();
DoNovel();
}
void Novel_Init(CartInfo *info)
{
AddExState(&GameMemBlock[0], 1, 0,"L1");
AddExState(&latch, 1, 0,"L1");
info->Power=NovelReset;
GameStateRestore=NovelRestore;
}

View File

@ -1,319 +0,0 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2002 Xodnizel
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 cmd;
static uint8 latch[8];
#define CHRRAM (GameMemBlock)
static void S74LS374NSynco(void)
{
setprg32(0x8000,latch[0]);
setchr8(latch[1]);
setmirror(latch[2]&1);
// setchr8(6);
}
static DECLFW(S74LS374NWrite)
{
//printf("$%04x:$%02x\n",A,V);
A&=0x4101;
if(A==0x4100)
cmd=V&7;
else
{
switch(cmd)
{
case 0:latch[0]=0;latch[1]=3;break;
case 4:latch[1]&=3;latch[1]|=(V<<2);break;
case 5:latch[0]=V&0x7;break;
case 6:latch[1]&=0x1C;latch[1]|=V&3;break;
case 7:latch[2]=V&1;break;
}
S74LS374NSynco();
}
}
static void S74LS374NReset(void)
{
latch[0]=latch[2]=0;
latch[1]=3;
S74LS374NSynco();
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x4100,0x7FFF,S74LS374NWrite);
}
static void S74LS374NRestore(int version)
{
S74LS374NSynco();
}
void S74LS374N_Init(CartInfo *info)
{
info->Power=S74LS374NReset;
GameStateRestore=S74LS374NRestore;
AddExState(latch, 3, 0, "LATC");
AddExState(&cmd, 1, 0, "CMD");
}
static int type;
static void S8259Synco(void)
{
int x;
setprg32(0x8000,latch[5]&7);
if(!UNIFchrrama) // No CHR RAM? Then BS'ing is ok.
{
if(!type)
{
for(x=0;x<4;x++)
setchr2(0x800*x,(x&1)|((latch[x]&7)<<1)|((latch[4]&7)<<4));
}
else
{
for(x=0;x<4;x++)
setchr2(0x800*x,(latch[x]&0x7)|((latch[4]&7)<<3));
}
}
switch((latch[7]>>1)&3)
{
case 0:setmirrorw(0,0,0,1);break;
case 1:setmirror(MI_H);break;
case 2:setmirror(MI_V);break;
case 3:setmirror(MI_0);break;
}
}
static DECLFW(S8259Write)
{
A&=0x4101;
if(A==0x4100) cmd=V;
else
{
latch[cmd&7]=V;
S8259Synco();
}
}
static void S8259Reset(void)
{
int x;
cmd=0;
for(x=0;x<8;x++) latch[x]=0;
if(UNIFchrrama) setchr8(0);
S8259Synco();
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x4100,0x7FFF,S8259Write);
}
static void S8259Restore(int version)
{
S8259Synco();
}
void S8259A_Init(CartInfo *info)
{
info->Power=S8259Reset;
GameStateRestore=S8259Restore;
AddExState(latch, 8, 0, "LATC");
AddExState(&cmd, 1, 0, "CMD");
type=0;
//if(!CHRsize[0])
//{
// SetupCartCHRMapping(0,CHRRAM,8192,1);
// AddExState(CHRRAM, 8192, 0, "CHRR");
//}
}
void S8259B_Init(CartInfo *info)
{
info->Power=S8259Reset;
GameStateRestore=S8259Restore;
AddExState(latch, 8, 0, "LATC");
AddExState(&cmd, 1, 0, "CMD");
type=1;
}
static void(*WSync)(void);
static void SA0161MSynco()
{
setprg32(0x8000,(latch[0]>>3)&1);
setchr8(latch[0]&7);
}
static DECLFW(SAWrite)
{
if(A&0x100)
{
latch[0]=V;
WSync();
}
}
static void SAReset(void)
{
latch[0]=0;
WSync();
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x4100,0x5FFF,SAWrite);
}
static void SA0161MRestore(int version)
{
SA0161MSynco();
}
void SA0161M_Init(CartInfo *info)
{
WSync=SA0161MSynco;
GameStateRestore=SA0161MRestore;
info->Power=SAReset;
AddExState(&latch[0], 1, 0, "LATC");
}
static void SA72007Synco()
{
setprg32(0x8000,0);
setchr8(latch[0]>>7);
}
static void SA72007Restore(int version)
{
SA72007Synco();
}
void SA72007_Init(CartInfo *info)
{
WSync=SA72007Synco;
GameStateRestore=SA72007Restore;
info->Power=SAReset;
AddExState(&latch[0], 1, 0, "LATC");
}
static void SA72008Synco()
{
setprg32(0x8000,(latch[0]>>2)&1);
setchr8(latch[0]&3);
}
static void SA72008Restore(int version)
{
SA72008Synco();
}
void SA72008_Init(CartInfo *info)
{
WSync=SA72008Synco;
GameStateRestore=SA72008Restore;
info->Power=SAReset;
AddExState(&latch[0], 1, 0, "LATC");
}
static DECLFW(SADWrite)
{
latch[0]=V;
WSync();
}
static void SADReset(void)
{
latch[0]=0;
WSync();
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,SADWrite);
}
static void SA0036Synco()
{
setprg32(0x8000,0);
setchr8(latch[0]>>7);
}
static void SA0036Restore(int version)
{
SA0036Synco();
}
static void SA0037Synco()
{
setprg32(0x8000,(latch[0]>>3)&1);
setchr8(latch[0]&7);
}
static void SA0037Restore(int version)
{
SA0037Synco();
}
void SA0036_Init(CartInfo *info)
{
WSync=SA0036Synco;
GameStateRestore=SA0036Restore;
info->Power=SADReset;
AddExState(&latch[0], 1, 0, "LATC");
}
void SA0037_Init(CartInfo *info)
{
WSync=SA0037Synco;
GameStateRestore=SA0037Restore;
info->Power=SADReset;
AddExState(&latch[0], 1, 0, "LATC");
}
static void TCU01Synco()
{
setprg32(0x8000,(latch[0]>>2)&1);
setchr8((latch[0]>>3)&0xF);
}
static DECLFW(TCWrite)
{
if((A&0x103)==0x102)
latch[0]=V;
TCU01Synco();
}
static void TCU01Reset(void)
{
latch[0]=0;
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x4100,0xFFFF,TCWrite);
TCU01Synco();
}
static void TCU01Restore(int version)
{
TCU01Synco();
}
void TCU01_Init(CartInfo *info)
{
GameStateRestore=TCU01Restore;
info->Power=TCU01Reset;
AddExState(&latch[0], 1, 0, "LATC");
}

View File

@ -0,0 +1,470 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2002 Xodnizel
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 cmd, dip;
static uint8 latch[8];
static void S74LS374MSync(uint8 mirr)
{
switch(mirr&3)
{
case 0:setmirror(MI_V);break;
case 1:setmirror(MI_H);break;
case 2:setmirrorw(0,1,1,1);break;
case 3:setmirror(MI_0);break;
}
}
static void S74LS374NSynco(void)
{
setprg32(0x8000,latch[0]);
setchr8(latch[1]|latch[3]|latch[4]);
S74LS374MSync(latch[2]);
}
static DECLFW(S74LS374NWrite)
{
A&=0x4101;
if(A==0x4100)
cmd=V&7;
else
{
switch(cmd)
{
case 2:latch[0]=V&1; latch[3]=(V&1)<<3;break;
case 4:latch[4]=(V&1)<<2;break;
case 5:latch[0]=V&7;break;
case 6:latch[1]=V&3;break;
case 7:latch[2]=V>>1;break;
}
S74LS374NSynco();
}
}
static DECLFR(S74LS374NRead)
{
uint8 ret;
if((A&0x4100)==0x4100)
// ret=(X.DB&0xC0)|((~cmd)&0x3F);
ret=((~cmd)&0x3F)^dip;
else
ret=X.DB;
return ret;
}
static void S74LS374NPower(void)
{
dip=0;
latch[0]=latch[1]=latch[2]=latch[3]=latch[4]=0;
S74LS374NSynco();
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x4100,0x7FFF,S74LS374NWrite);
SetReadHandler(0x4100,0x5fff,S74LS374NRead);
}
static void S74LS374NReset(void)
{
dip^=1;
latch[0]=latch[1]=latch[2]=latch[3]=latch[4]=0;
S74LS374NSynco();
}
static void S74LS374NRestore(int version)
{
S74LS374NSynco();
}
void S74LS374N_Init(CartInfo *info)
{
info->Power=S74LS374NPower;
info->Reset=S74LS374NReset;
GameStateRestore=S74LS374NRestore;
AddExState(latch, 5, 0, "LATC");
AddExState(&cmd, 1, 0, "CMD");
AddExState(&dip, 1, 0, "DIP");
}
static void S74LS374NASynco(void)
{
setprg32(0x8000,latch[0]);
setchr8(latch[1]);
S74LS374MSync(latch[2]);
}
static DECLFW(S74LS374NAWrite)
{
A&=0x4101;
if(A==0x4100)
cmd=V&7;
else
{
switch(cmd)
{
case 0:latch[0]=0;latch[1]=3;break;
case 2:latch[3]=(V&1)<<3;break;
case 4:latch[1]=(latch[1]&6)|(V&3);break;
case 5:latch[0]=V&1;break;
case 6:latch[1]=(latch[1]&1)|latch[3]|((V&3)<<1);break;
case 7:latch[2]=V&1;break;
}
S74LS374NASynco();
}
}
static void S74LS374NAPower(void)
{
latch[0]=latch[2]=latch[3]=latch[4]=0;
latch[1]=3;
S74LS374NASynco();
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x4100,0x7FFF,S74LS374NAWrite);
}
void S74LS374NA_Init(CartInfo *info)
{
info->Power=S74LS374NAPower;
GameStateRestore=S74LS374NRestore;
AddExState(latch, 5, 0, "LATC");
AddExState(&cmd, 1, 0, "CMD");
}
static int type;
static void S8259Synco(void)
{
int x;
setprg32(0x8000,latch[5]&7);
if(!UNIFchrrama) // No CHR RAM? Then BS'ing is ok.
{
for(x=0;x<4;x++)
{
int bank;
if(latch[7]&1)
bank=(latch[0]&0x7)|((latch[4]&7)<<3);
else
bank=(latch[x]&0x7)|((latch[4]&7)<<3);
switch (type)
{
case 00: bank=(bank<<1)|(x&1); setchr2(0x800*x,bank); break;
case 01: setchr2(0x800*x,bank); break;
case 02: bank=(bank<<2)|(x&3); setchr2(0x800*x,bank); break;
case 03: bank=latch[x]&7;
switch (x&3)
{
case 01: bank|=(latch[4]&1)<<4;break;
case 02: bank|=(latch[4]&2)<<3;break;
case 03: bank|=((latch[4]&4)<<2)|((latch[6]&1)<<3);break;
}
setchr1(0x400*x,bank);
setchr4(0x1000,~0);
break;
}
}
}
if(!(latch[7]&1))
S74LS374MSync(latch[7]>>1);
else
setmirror(MI_V);
}
static DECLFW(S8259Write)
{
A&=0x4101;
if(A==0x4100)
cmd=V;
else
{
latch[cmd&7]=V;
S8259Synco();
}
}
static void S8259Reset(void)
{
int x;
cmd=0;
for(x=0;x<8;x++) latch[x]=0;
setchr8(0);
S8259Synco();
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x4100,0x7FFF,S8259Write);
}
static void S8259Restore(int version)
{
S8259Synco();
}
void S8259A_Init(CartInfo *info) // Kevin's Horton 141 mapper
{
info->Power=S8259Reset;
GameStateRestore=S8259Restore;
AddExState(latch, 8, 0, "LATC");
AddExState(&cmd, 1, 0, "CMD");
type=0;
}
void S8259B_Init(CartInfo *info) // Kevin's Horton 138 mapper
{
info->Power=S8259Reset;
GameStateRestore=S8259Restore;
AddExState(latch, 8, 0, "LATC");
AddExState(&cmd, 1, 0, "CMD");
type=1;
}
void S8259C_Init(CartInfo *info) // Kevin's Horton 139 mapper
{
info->Power=S8259Reset;
GameStateRestore=S8259Restore;
AddExState(latch, 8, 0, "LATC");
AddExState(&cmd, 1, 0, "CMD");
type=2;
}
void S8259D_Init(CartInfo *info) // Kevin's Horton 137 mapper
{
info->Power=S8259Reset;
GameStateRestore=S8259Restore;
AddExState(latch, 8, 0, "LATC");
AddExState(&cmd, 1, 0, "CMD");
type=3;
}
static void(*WSync)(void);
static DECLFW(SAWrite)
{
if(A&0x100)
{
latch[0]=V;
WSync();
}
}
static void SAPower(void)
{
latch[0]=0;
WSync();
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x4100,0x5FFF,SAWrite);
}
static void SARestore(int version)
{
WSync();
}
static DECLFW(SADWrite)
{
latch[0]=V;
WSync();
}
static void SADPower(void)
{
latch[0]=0;
WSync();
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,SADWrite);
}
static void SA0161MSynco()
{
setprg32(0x8000,(latch[0]>>3)&1);
setchr8(latch[0]&7);
}
static void SA72007Synco()
{
setprg32(0x8000,0);
setchr8(latch[0]>>7);
}
static void SA009Synco()
{
setprg32(0x8000,0);
setchr8(latch[0]&1);
}
static void SA72008Synco()
{
setprg32(0x8000,(latch[0]>>2)&1);
setchr8(latch[0]&3);
}
void SA0161M_Init(CartInfo *info)
{
WSync=SA0161MSynco;
GameStateRestore=SARestore;
info->Power=SAPower;
AddExState(&latch[0], 1, 0, "LATC");
}
void SA72007_Init(CartInfo *info)
{
WSync=SA72007Synco;
GameStateRestore=SARestore;
info->Power=SAPower;
AddExState(&latch[0], 1, 0, "LATC");
}
void SA72008_Init(CartInfo *info)
{
WSync=SA72008Synco;
GameStateRestore=SARestore;
info->Power=SAPower;
AddExState(&latch[0], 1, 0, "LATC");
}
void SA009_Init(CartInfo *info)
{
WSync=SA009Synco;
GameStateRestore=SARestore;
info->Power=SAPower;
AddExState(&latch[0], 1, 0, "LATC");
}
void SA0036_Init(CartInfo *info)
{
WSync=SA72007Synco;
GameStateRestore=SARestore;
info->Power=SADPower;
AddExState(&latch[0], 1, 0, "LATC");
}
void SA0037_Init(CartInfo *info)
{
WSync=SA0161MSynco;
GameStateRestore=SARestore;
info->Power=SADPower;
AddExState(&latch[0], 1, 0, "LATC");
}
// -----------------------------------------------
static void TCU01Synco()
{
setprg32(0x8000,((latch[0]&0x80)>>6)|((latch[0]>>2)&1));
setchr8((latch[0]>>3)&0xF);
}
static DECLFW(TCU01Write)
{
if((A&0x103)==0x102)
{
latch[0]=V;
TCU01Synco();
}
}
static void TCU01Power(void)
{
latch[0]=0;
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x4100,0xFFFF,TCU01Write);
TCU01Synco();
}
static void TCU01Restore(int version)
{
TCU01Synco();
}
void TCU01_Init(CartInfo *info)
{
GameStateRestore=TCU01Restore;
info->Power=TCU01Power;
AddExState(&latch[0], 1, 0, "LATC");
}
//-----------------------------------------------
static void TCU02Synco()
{
setprg32(0x8000,0);
setchr8(latch[0]&3);
}
static DECLFW(TCU02Write)
{
if((A&0x103)==0x102)
{
latch[0]=V+3;
TCU02Synco();
}
}
static DECLFR(TCU02Read)
{
return (latch[0]&0x3F)|(X.DB&0xC0);
}
static void TCU02Power(void)
{
latch[0]=0;
SetReadHandler(0x8000,0xFFFF,CartBR);
SetReadHandler(0x4100,0x4100,TCU02Read);
SetWriteHandler(0x4100,0xFFFF,TCU02Write);
TCU02Synco();
}
static void TCU02Restore(int version)
{
TCU02Synco();
}
void TCU02_Init(CartInfo *info)
{
GameStateRestore=TCU02Restore;
info->Power=TCU02Power;
AddExState(&latch[0], 1, 0, "LATC");
}
// ---------------------------------------------
static DECLFR(TCA01Read)
{
uint8 ret;
if((A&0x4100)==0x4100)
ret=(X.DB&0xC0)|((~A)&0x3F);
else
ret=X.DB;
return ret;
}
static void TCA01Power(void)
{
setprg16(0x8000,0);
setprg16(0xC000,1);
setchr8(0);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetReadHandler(0x4100,0x5FFF,TCA01Read);
}
void TCA01_Init(CartInfo *info)
{
info->Power=TCA01Power;
}

View File

@ -0,0 +1,125 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2009 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Wario Land II (Kirby hack)
*/
#include "mapinc.h"
static uint8 reg[8], chr[8];
static uint8 *WRAM=NULL;
static uint32 WRAMSIZE;
static uint16 IRQCount, IRQa;
static SFORMAT StateRegs[]=
{
{reg, 8, "REGS"},
{chr, 8, "CHRS"},
{&IRQCount, 16, "IRQc"},
{&IRQa, 16, "IRQa"},
{0}
};
static void Sync(void)
{
int i;
setprg8(0x8000,reg[0]);
setprg8(0xA000,reg[1]);
setprg8(0xC000,reg[2]);
for(i=0; i<8; i++)
setchr1(i << 10,chr[i]);
setmirror(reg[3]^1);
}
static DECLFW(UNLSC127Write)
{
switch(A)
{
case 0x8000: reg[0] = V; break;
case 0x8001: reg[1] = V; break;
case 0x8002: reg[2] = V; break;
case 0x9000: chr[0] = V; break;
case 0x9001: chr[1] = V; break;
case 0x9002: chr[2] = V; break;
case 0x9003: chr[3] = V; break;
case 0x9004: chr[4] = V; break;
case 0x9005: chr[5] = V; break;
case 0x9006: chr[6] = V; break;
case 0x9007: chr[7] = V; break;
case 0xC002: IRQa=0; X6502_IRQEnd(FCEU_IQEXT); break;
case 0xC005: IRQCount=V; break;
case 0xC003: IRQa=1; break;
case 0xD001: reg[3] = V; break;
}
Sync();
}
static void UNLSC127Power(void)
{
Sync();
setprg8r(0x10,0x6000,0);
setprg8(0xE000,~0);
SetReadHandler(0x6000,0x7fff,CartBR);
SetWriteHandler(0x6000,0x7fff,CartBW);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,UNLSC127Write);
}
static void UNLSC127IRQ(void)
{
if(IRQa)
{
IRQCount--;
if(IRQCount==0)
{
X6502_IRQBegin(FCEU_IQEXT);
IRQa=0;
}
}
}
static void UNLSC127Reset(void)
{
}
static void UNLSC127Close(void)
{
if(WRAM)
FCEU_gfree(WRAM);
WRAM=NULL;
}
static void StateRestore(int version)
{
Sync();
}
void UNLSC127_Init(CartInfo *info)
{
info->Reset=UNLSC127Reset;
info->Power=UNLSC127Power;
info->Close=UNLSC127Close;
GameHBIRQHook=UNLSC127IRQ;
GameStateRestore=StateRestore;
WRAMSIZE=8192;
WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE);
SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1);
AddExState(WRAM, WRAMSIZE, 0, "WRAM");
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,88 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2006 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
#include "mmc3.h"
static uint8 *CHRRAM; // there is no more extern CHRRAM in mmc3.h
// I need chrram here and local static == local
static uint8 tekker;
static void MSHCW(uint32 A, uint8 V)
{
if(EXPREGS[0]&0x40)
setchr8r(0x10,0);
else
{
if(A<0x800)
setchr1(A,V|((EXPREGS[0]&8)<<5));
else if(A<0x1000)
setchr1(A,V|((EXPREGS[0]&4)<<6));
else if(A<0x1800)
setchr1(A,V|((EXPREGS[0]&1)<<8));
else
setchr1(A,V|((EXPREGS[0]&2)<<7));
}
}
static DECLFW(MSHWrite)
{
EXPREGS[0]=V;
FixMMC3CHR(MMC3_cmd);
}
static DECLFR(MSHRead)
{
return(tekker);
}
static void MSHReset(void)
{
MMC3RegReset();
tekker^=0xFF;
}
static void MSHPower(void)
{
tekker=0x00;
GenMMC3Power();
SetWriteHandler(0x4100,0x4100,MSHWrite);
SetReadHandler(0x4100,0x4100,MSHRead);
}
static void MSHClose(void)
{
if(CHRRAM)
FCEU_gfree(CHRRAM);
CHRRAM=NULL;
}
void UNLSHeroes_Init(CartInfo *info)
{
GenMMC3_Init(info, 256, 512, 0, 0);
cwrap=MSHCW;
info->Power=MSHPower;
info->Reset=MSHReset;
info->Close=MSHClose;
CHRRAM = (uint8*)FCEU_gmalloc(8192);
SetupCartCHRMapping(0x10, CHRRAM, 8192, 1);
AddExState(EXPREGS, 4, 0, "EXPR");
AddExState(&tekker, 1, 0, "DIPSW");
}

View File

@ -0,0 +1,124 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
#include "mmc3.h"
// brk is a system call in *nix, and is an illegal variable name - soules
static uint8 chrcmd[8], prg0, prg1, bbrk, mirr, swap;
static SFORMAT StateRegs[]=
{
{chrcmd, 8, "CHRCMD"},
{&prg0, 1, "PRG0"},
{&prg1, 1, "PRG1"},
{&bbrk, 1, "BRK"},
{&mirr, 1, "MIRR"},
{&swap, 1, "SWAP"},
{0}
};
static void Sync(void)
{
int i;
setprg8(0x8000,prg0);
setprg8(0xA000,prg1);
setprg8(0xC000,~1);
setprg8(0xE000,~0);
for(i=0; i<8; i++)
setchr1(i<<10,chrcmd[i]);
setmirror(mirr^1);
}
static void UNLSL1632CW(uint32 A, uint8 V)
{
int cbase=(MMC3_cmd&0x80)<<5;
int page0=(bbrk&0x08)<<5;
int page1=(bbrk&0x20)<<3;
int page2=(bbrk&0x80)<<1;
setchr1(cbase^0x0000,page0|(DRegBuf[0]&(~1)));
setchr1(cbase^0x0400,page0|DRegBuf[0]|1);
setchr1(cbase^0x0800,page0|(DRegBuf[1]&(~1)));
setchr1(cbase^0x0C00,page0|DRegBuf[1]|1);
setchr1(cbase^0x1000,page1|DRegBuf[2]);
setchr1(cbase^0x1400,page1|DRegBuf[3]);
setchr1(cbase^0x1800,page2|DRegBuf[4]);
setchr1(cbase^0x1c00,page2|DRegBuf[5]);
}
static DECLFW(UNLSL1632CMDWrite)
{
if(A==0xA131)
{
bbrk=V;
}
if(bbrk&2)
{
FixMMC3PRG(MMC3_cmd);
FixMMC3CHR(MMC3_cmd);
if(A<0xC000)
MMC3_CMDWrite(A,V);
else
MMC3_IRQWrite(A,V);
}
else
{
if((A>=0xB000)&&(A<=0xE003))
{
int ind=((((A&2)|(A>>10))>>1)+2)&7;
int sar=((A&1)<<2);
chrcmd[ind]=(chrcmd[ind]&(0xF0>>sar))|((V&0x0F)<<sar);
}
else
switch(A&0xF003)
{
case 0x8000: prg0=V; break;
case 0xA000: prg1=V; break;
case 0x9000: mirr=V&1; break;
}
Sync();
}
}
static void StateRestore(int version)
{
if(bbrk&2)
{
FixMMC3PRG(MMC3_cmd);
FixMMC3CHR(MMC3_cmd);
}
else
Sync();
}
static void UNLSL1632Power(void)
{
GenMMC3Power();
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x4100,0xFFFF,UNLSL1632CMDWrite);
}
void UNLSL1632_Init(CartInfo *info)
{
GenMMC3_Init(info, 256, 512, 0, 0);
cwrap=UNLSL1632CW;
info->Power=UNLSL1632Power;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,96 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2007 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* Super Mario Bros 2 J alt version
* as well as "Voleyball" FDS conversion, bank layot is similar but no bankswitching and CHR ROM present
*/
#include "mapinc.h"
static uint8 prg, IRQa;
static uint16 IRQCount;
static SFORMAT StateRegs[]=
{
{&prg, 1, "PRG"},
{&IRQa, 1, "IRQA"},
{&IRQCount, 2, "IRQC"},
{0}
};
static void Sync(void)
{
setprg4r(1,0x5000,1);
setprg8r(1,0x6000,1);
setprg32(0x8000,prg);
setchr8(0);
}
static DECLFW(UNLSMB2JWrite)
{
if(A==0x4022)
{
prg=V&1;
Sync();
}
if(A==0x4122)
{
IRQa=V;
IRQCount=0;
X6502_IRQEnd(FCEU_IQEXT);
}
}
static void UNLSMB2JPower(void)
{
prg=~0;
Sync();
SetReadHandler(0x5000,0x7FFF,CartBR);
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x4020,0xffff,UNLSMB2JWrite);
}
static void UNLSMB2JReset(void)
{
prg=~0;
Sync();
}
static void UNLSMB2JIRQHook(int a)
{
if(IRQa)
{
IRQCount+=a*3;
if((IRQCount>>12)==IRQa)
X6502_IRQBegin(FCEU_IQEXT);
}
}
static void StateRestore(int version)
{
Sync();
}
void UNLSMB2J_Init(CartInfo *info)
{
info->Reset=UNLSMB2JReset;
info->Power=UNLSMB2JPower;
MapIRQHook=UNLSMB2JIRQHook;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -1,235 +0,0 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2002 Xodnizel
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static int32 IRQCount,IRQLatch;
static uint8 IRQa,resetmode,mbia;
static uint8 sizer,bigbank,bigbank2;
static uint8 DRegBuf[8],MMC3_cmd;
static int masko8[8]={63,31,15,1,3,0,0,0};
//static int masko1[8]={511,255,127,7,7,0,0,0};
static void swsetprg8(uint32 A, uint32 V)
{
V&=masko8[sizer&7];
V|=(bigbank*2);
setprg8r((V/64)&15,A,V);
}
static void swsetchr1(uint32 A, uint32 V)
{
if(sizer&0x20)
setchr1r(0x10,A,V);
else
{
// V&=masko1[sizer&7];
V|=bigbank2*8;
setchr1r((V/512)&15,A,V);
}
}
static void swsetchr2(uint32 A, uint32 V)
{
if(sizer&0x20)
setchr2r(0x10,A,V);
else
{
//V&=masko1[sizer&7]>>1;
V|=bigbank2*4;
setchr2r((V/256)&15,A,V);
}
}
static void Sup24_hb(void)
{
resetmode=0;
if(scanline==238) X6502_IRQBegin(FCEU_IQEXT);
if(IRQCount>=0)
{
IRQCount--;
if(IRQCount<0)
{
if(IRQa)
{
resetmode = 1;
X6502_IRQBegin(FCEU_IQEXT);
//printf("IRQ: %d,%d\n",scanline,timestamp);
}
}
}
}
static DECLFW(Sup24IRQWrite)
{
//printf("%04x, $%02x, %d, %d\n",A,V,scanline,timestamp);
switch(A&0xE001)
{
case 0xc000:IRQLatch=V;
if(resetmode==1)
IRQCount=IRQLatch;
break;
case 0xc001:resetmode=1;
IRQCount=IRQLatch;
break;
case 0xE000:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);
if(resetmode==1)
{IRQCount=IRQLatch;}
break;
case 0xE001:IRQa=1;
if(resetmode==1)
{IRQCount=IRQLatch;}
break;
}
}
static INLINE void FixMMC3PRG(int V)
{
swsetprg8(0xA000,DRegBuf[7]);
swsetprg8(0xE000,~0);
if(V&0x40)
{
swsetprg8(0xC000,DRegBuf[6]);
swsetprg8(0x8000,~1);
}
else
{
swsetprg8(0x8000,DRegBuf[6]);
swsetprg8(0xC000,~1);
}
}
static INLINE void FixMMC3CHR(int V)
{
int cbase=(V&0x80)<<5;
swsetchr2((cbase^0x000),DRegBuf[0]>>1);
swsetchr2((cbase^0x800),DRegBuf[1]>>1);
swsetchr1(cbase^0x1000,DRegBuf[2]);
swsetchr1(cbase^0x1400,DRegBuf[3]);
swsetchr1(cbase^0x1800,DRegBuf[4]);
swsetchr1(cbase^0x1c00,DRegBuf[5]);
}
static DECLFW(Super24hiwrite)
{
//printf("$%04x:$%02x, %d\n",A,V,scanline);
switch(A&0xE001)
{
case 0x8000:
if((V&0x40) != (MMC3_cmd&0x40))
FixMMC3PRG(V);
if((V&0x80) != (MMC3_cmd&0x80))
FixMMC3CHR(V);
MMC3_cmd = V;
break;
case 0x8001:
{
int cbase=(MMC3_cmd&0x80)<<5;
DRegBuf[MMC3_cmd&0x7]=V;
switch(MMC3_cmd&0x07)
{
case 0: V>>=1;swsetchr2((cbase^0x000),V);break;
case 1: V>>=1;swsetchr2((cbase^0x800),V);break;
case 2: swsetchr1(cbase^0x1000,V); break;
case 3: swsetchr1(cbase^0x1400,V); break;
case 4: swsetchr1(cbase^0x1800,V); break;
case 5: swsetchr1(cbase^0x1C00,V); break;
case 6: if (MMC3_cmd&0x40) swsetprg8(0xC000,V);
else swsetprg8(0x8000,V);
break;
case 7: swsetprg8(0xA000,V);
break;
}
}
break;
case 0xA000:
mbia=V;
setmirror((V&1)^1);
break;
}
}
static DECLFW(Super24Write)
{
//printf("$%04x:$%02x\n",A,V);
switch(A)
{
case 0x5ff0:sizer=V;
FixMMC3PRG(MMC3_cmd);
FixMMC3CHR(MMC3_cmd);
break;
case 0x5FF1:
bigbank=V;
FixMMC3PRG(MMC3_cmd);
break;
case 0x5FF2:
bigbank2=V;
FixMMC3CHR(MMC3_cmd);
break;
}
}
static void Super24Reset(void)
{
SetWriteHandler(0x8000,0xBFFF,Super24hiwrite);
SetWriteHandler(0x5000,0x7FFF,Super24Write);
SetWriteHandler(0xC000,0xFFFF,Sup24IRQWrite);
SetReadHandler(0x8000,0xFFFF,CartBR);
GameHBIRQHook=Sup24_hb;
IRQCount=IRQLatch=IRQa=resetmode=0;
sizer=0x24;
bigbank=159;
bigbank2=0;
MMC3_cmd=0;
DRegBuf[6]=0;
DRegBuf[7]=1;
FixMMC3PRG(0);
FixMMC3CHR(0);
}
static void MrRestore(int version)
{
FixMMC3PRG(MMC3_cmd);
FixMMC3CHR(MMC3_cmd);
setmirror((mbia&1)^1);
}
void Super24_Init(CartInfo *info)
{
info->Power=Super24Reset;
SetupCartCHRMapping(0x10, GameMemBlock, 8192, 1);
GameStateRestore=MrRestore;
AddExState(GameMemBlock, 8192, 0, "CHRR");
AddExState(DRegBuf, 8, 0, "DREG");
AddExState(&IRQCount, 4, 1, "IRQC");
AddExState(&IRQLatch, 4, 1, "IQL1");
AddExState(&IRQa, 1, 0, "IRQA");
AddExState(&sizer, 1, 0, "SIZA");
AddExState(&bigbank, 1, 0, "BIG1");
AddExState(&bigbank2, 1, 0, "BIG2");
}

View File

@ -0,0 +1,100 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
#include "mmc3.h"
static uint8 *CHRRAM = NULL; // there is no more extern CHRRAM in mmc3.h
// I need chrram here and local static == local
static int masko8[8]={63,31,15,1,3,0,0,0};
static void Super24PW(uint32 A, uint8 V)
{
uint32 NV=V&masko8[EXPREGS[0]&7];
NV|=(EXPREGS[1]<<1);
setprg8r((NV>>6)&0xF,A,NV);
}
static void Super24CW(uint32 A, uint8 V)
{
if(EXPREGS[0]&0x20)
setchr1r(0x10,A,V);
else
{
uint32 NV=V|(EXPREGS[2]<<3);
setchr1r((NV>>9)&0xF,A,NV);
}
}
static DECLFW(Super24Write)
{
switch(A)
{
case 0x5FF0: EXPREGS[0]=V;
FixMMC3PRG(MMC3_cmd);
FixMMC3CHR(MMC3_cmd);
break;
case 0x5FF1: EXPREGS[1]=V;
FixMMC3PRG(MMC3_cmd);
break;
case 0x5FF2: EXPREGS[2]=V;
FixMMC3CHR(MMC3_cmd);
break;
}
}
static void Super24Power(void)
{
EXPREGS[0]=0x24;
EXPREGS[1]=159;
EXPREGS[2]=0;
GenMMC3Power();
SetWriteHandler(0x5000,0x7FFF,Super24Write);
SetReadHandler(0x8000,0xFFFF,CartBR);
}
static void Super24Reset(void)
{
EXPREGS[0]=0x24;
EXPREGS[1]=159;
EXPREGS[2]=0;
MMC3RegReset();
}
static void Super24Close(void)
{
if(CHRRAM)
FCEU_gfree(CHRRAM);
CHRRAM = NULL;
}
void Super24_Init(CartInfo *info)
{
GenMMC3_Init(info, 128, 256, 0, 0);
info->Power=Super24Power;
info->Reset=Super24Reset;
info->Close=Super24Close;
cwrap=Super24CW;
pwrap=Super24PW;
CHRRAM=(uint8*)FCEU_gmalloc(8192);
SetupCartCHRMapping(0x10, CHRRAM, 8192, 1);
AddExState(CHRRAM, 8192, 0, "CHRR");
AddExState(EXPREGS, 3, 0, "BIG2");
}

View File

@ -20,35 +20,34 @@
#include "mapinc.h"
#define CHRRAM (GameMemBlock+16)
static uint8 cmd0, cmd1;
static void DoSuper(void)
{
setprg8r((GameMemBlock[0]&0xC)>>2,0x6000,((GameMemBlock[0]&0x3)<<4)|0xF);
if(GameMemBlock[0]&0x10)
{
setprg16r((GameMemBlock[0]&0xC)>>2,0x8000,((GameMemBlock[0]&0x3)<<3)|(GameMemBlock[1]&7));
setprg16r((GameMemBlock[0]&0xC)>>2,0xc000,((GameMemBlock[0]&0x3)<<3)|7);
}
else
setprg32r(4,0x8000,0);
setmirror(((GameMemBlock[0]&0x20)>>5)^1);
setprg8r((cmd0&0xC)>>2,0x6000,((cmd0&0x3)<<4)|0xF);
if(cmd0&0x10)
{
setprg16r((cmd0&0xC)>>2,0x8000,((cmd0&0x3)<<3)|(cmd1&7));
setprg16r((cmd0&0xC)>>2,0xc000,((cmd0&0x3)<<3)|7);
}
else
setprg32r(4,0x8000,0);
setmirror(((cmd0&0x20)>>5)^1);
}
static DECLFW(SuperWrite)
{
if(!(GameMemBlock[0]&0x10))
{
GameMemBlock[0]=V;
DoSuper();
}
if(!(cmd0&0x10))
{
cmd0=V;
DoSuper();
}
}
static DECLFW(SuperHi)
{
GameMemBlock[1]=V;
DoSuper();
cmd1=V;
DoSuper();
}
static void SuperReset(void)
@ -56,22 +55,20 @@ static void SuperReset(void)
SetWriteHandler(0x6000,0x7FFF,SuperWrite);
SetWriteHandler(0x8000,0xFFFF,SuperHi);
SetReadHandler(0x6000,0xFFFF,CartBR);
GameMemBlock[0]=GameMemBlock[1]=0;
cmd0=cmd1=0;
setprg32r(4,0x8000,0);
setvram8(CHRRAM);
FCEU_dwmemset(CHRRAM,0,8192);
setchr8(0);
}
static void SuperRestore(int version)
{
DoSuper();
DoSuper();
}
void Supervision16_Init(CartInfo *info)
{
AddExState(&GameMemBlock[0], 1, 0,"L1");
AddExState(&GameMemBlock[1], 1, 0,"L2");
AddExState(CHRRAM, 8192, 0, "CHRR");
AddExState(&cmd0, 1, 0,"L1");
AddExState(&cmd1, 1, 0,"L2");
info->Power=SuperReset;
GameStateRestore=SuperRestore;
}

View File

@ -0,0 +1,116 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2008 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// T-227-1, 820632, MMC3 based, multimenu, 60000in1 (0010) dip switches
#include "mapinc.h"
#include "mmc3.h"
static uint8 reset_flag = 0x07;
static void BMCT2271CW(uint32 A, uint8 V)
{
uint32 va = V;
if(EXPREGS[0]&0x20)
{
va|=0x200;
va|=(EXPREGS[0]&0x10)<<4;
}
else
{
va&=0x7F;
va|=(EXPREGS[0]&0x18)<<4;
}
setchr1(A,va);
}
static void BMCT2271PW(uint32 A, uint8 V)
{
uint32 va = V & 0x3F;
if(EXPREGS[0]&0x20)
{
va&=0x1F;
va|=0x40;
va|=(EXPREGS[0]&0x10)<<1;
}
else
{
va&=0x0F;
va|=(EXPREGS[0]&0x18)<<1;
}
switch(EXPREGS[0]&3)
{
case 0x00: setprg8(A,va); break;
case 0x02:
{
va=(va&0xFD)|((EXPREGS[0]&4)>>1);
if(A<0xC000)
{
setprg16(0x8000,va >> 1);
setprg16(0xC000,va >> 1);
}
break;
}
case 0x01:
case 0x03: if(A<0xC000) setprg32(0x8000,va >> 2); break;
}
}
static DECLFW(BMCT2271LoWrite)
{
if(!(EXPREGS[0]&0x80))
EXPREGS[0] = A & 0xFF;
FixMMC3PRG(MMC3_cmd);
FixMMC3CHR(MMC3_cmd);
}
static DECLFR(BMCT2271HiRead)
{
uint32 av = A;
if(EXPREGS[0]&0x40) av = (av & 0xFFF0)|reset_flag;
return CartBR(av);
}
static void BMCT2271Reset(void)
{
EXPREGS[0] = 0x00;
reset_flag++;
reset_flag&=0x0F;
MMC3RegReset();
}
static void BMCT2271Power(void)
{
EXPREGS[0] = 0x00;
GenMMC3Power();
SetWriteHandler(0x6000,0x7FFF,BMCT2271LoWrite);
SetReadHandler(0x8000,0xFFFF,BMCT2271HiRead);
}
void BMCT2271_Init(CartInfo *info)
{
GenMMC3_Init(info, 128, 128, 8, 0);
pwrap=BMCT2271PW;
cwrap=BMCT2271CW;
info->Power=BMCT2271Power;
info->Reset=BMCT2271Reset;
AddExState(EXPREGS, 1, 0, "EXPR");
}

View File

@ -0,0 +1,84 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2006 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint16 addrreg;
static uint8 datareg;
static uint8 busy;
static SFORMAT StateRegs[]=
{
{&addrreg, 2, "ADDRREG"},
{&datareg, 1, "DATAREG"},
{&busy, 1, "BUSY"},
{0}
};
static void Sync(void)
{
uint16 base=((addrreg&0x60)>>2)|((addrreg&0x100)>>3);
setprg16(0x8000,(datareg&7)|base);
setprg16(0xC000,7|base);
setmirror(((addrreg&2)>>1)^1);
}
static DECLFW(BMCT262Write)
{
if(busy||(A==0x8000))
datareg=V;
else
{
addrreg=A;
busy=1;
}
Sync();
}
static void BMCT262Power(void)
{
setchr8(0);
SetWriteHandler(0x8000,0xFFFF,BMCT262Write);
SetReadHandler(0x8000,0xFFFF,CartBR);
busy=0;
addrreg=0;
datareg=0xff;
Sync();
}
static void BMCT262Reset(void)
{
busy=0;
addrreg=0;
datareg=0;
Sync();
}
static void BMCT262Restore(int version)
{
Sync();
}
void BMCT262_Init(CartInfo *info)
{
info->Power=BMCT262Power;
info->Reset=BMCT262Reset;
GameStateRestore=BMCT262Restore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -0,0 +1,200 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2002 Xodnizel
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "mapinc.h"
static uint8 cmd,mir,rmode,IRQmode;
static uint8 DRegs[11];
static uint8 IRQCount,IRQa,IRQLatch;
static SFORMAT Rambo_StateRegs[]={
{&cmd, 1, "CMD"},
{&mir, 1, "MIR"},
{&rmode, 1, "RMOD"},
{&IRQmode, 1, "IRQM"},
{&IRQCount, 1, "IRQC"},
{&IRQa, 1, "IRQA"},
{&IRQLatch, 1, "IRQL"},
{DRegs, 11, "DREG"},
{0}
};
static void (*setchr1wrap)(unsigned int A, unsigned int V);
//static int nomirror;
static void RAMBO1_IRQHook(int a)
{
static int smallcount;
if(!IRQmode) return;
smallcount+=a;
while(smallcount>=4)
{
smallcount-=4;
IRQCount--;
if(IRQCount==0xFF)
if(IRQa) X6502_IRQBegin(FCEU_IQEXT);
}
}
static void RAMBO1_hb(void)
{
if(IRQmode) return;
if(scanline==240) return; /* hmm. Maybe that should be an mmc3-only call in fce.c. */
rmode=0;
IRQCount--;
if(IRQCount==0xFF)
{
if(IRQa)
{
rmode = 1;
X6502_IRQBegin(FCEU_IQEXT);
}
}
}
static void Synco(void)
{
int x;
if(cmd&0x20)
{
setchr1wrap(0x0000,DRegs[0]);
setchr1wrap(0x0800,DRegs[1]);
setchr1wrap(0x0400,DRegs[8]);
setchr1wrap(0x0c00,DRegs[9]);
}
else
{
setchr1wrap(0x0000,(DRegs[0]&0xFE));
setchr1wrap(0x0400,(DRegs[0]&0xFE)|1);
setchr1wrap(0x0800,(DRegs[1]&0xFE));
setchr1wrap(0x0C00,(DRegs[1]&0xFE)|1);
}
for(x=0;x<4;x++)
setchr1wrap(0x1000+x*0x400,DRegs[2+x]);
setprg8(0x8000,DRegs[6]);
setprg8(0xA000,DRegs[7]);
setprg8(0xC000,DRegs[10]);
}
static DECLFW(RAMBO1_write)
{
switch(A&0xF001)
{
case 0xa000: mir=V&1;
// if(!nomirror)
setmirror(mir^1);
break;
case 0x8000: cmd = V;
break;
case 0x8001: if((cmd&0xF)<10)
DRegs[cmd&0xF]=V;
else if((cmd&0xF)==0xF)
DRegs[10]=V;
Synco();
break;
case 0xc000: IRQLatch=V;
if(rmode==1)
IRQCount=IRQLatch;
break;
case 0xc001: rmode=1;
IRQCount=IRQLatch;
IRQmode=V&1;
break;
case 0xE000: IRQa=0;
X6502_IRQEnd(FCEU_IQEXT);
if(rmode==1)
IRQCount=IRQLatch;
break;
case 0xE001: IRQa=1;
if(rmode==1)
IRQCount=IRQLatch;
break;
}
}
static void RAMBO1_Restore(int version)
{
Synco();
// if(!nomirror)
setmirror(mir^1);
}
static void RAMBO1_init(void)
{
int x;
for(x=0;x<11;x++)
DRegs[x]=~0;
cmd=mir=0;
// if(!nomirror)
setmirror(1);
Synco();
GameHBIRQHook=RAMBO1_hb;
MapIRQHook=RAMBO1_IRQHook;
GameStateRestore=RAMBO1_Restore;
SetWriteHandler(0x8000,0xffff,RAMBO1_write);
AddExState(Rambo_StateRegs, ~0, 0, 0);
}
static void CHRWrap(unsigned int A, unsigned int V)
{
setchr1(A,V);
}
void Mapper64_init(void)
{
setchr1wrap=CHRWrap;
// nomirror=0;
RAMBO1_init();
}
/*
static int MirCache[8];
static unsigned int PPUCHRBus;
static void MirWrap(unsigned int A, unsigned int V)
{
MirCache[A>>10]=(V>>7)&1;
if(PPUCHRBus==(A>>10))
setmirror(MI_0+((V>>7)&1));
setchr1(A,V);
}
static void MirrorFear(uint32 A)
{
A&=0x1FFF;
A>>=10;
PPUCHRBus=A;
setmirror(MI_0+MirCache[A]);
}
void Mapper158_init(void)
{
setchr1wrap=MirWrap;
PPU_hook=MirrorFear;
nomirror=1;
RAMBO1_init();
}
*/

View File

@ -0,0 +1,124 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2005 CaH4e3
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Lethal Weapon (VRC4 mapper)
*/
#include "mapinc.h"
static uint8 prg0, prg1, mirr, swap;
static uint8 chr[8];
static uint8 IRQCount;
static uint8 IRQPre;
static uint8 IRQa;
static SFORMAT StateRegs[]=
{
{&prg0, 1, "PRG0"},
{&prg0, 1, "PRG1"},
{&mirr, 1, "MIRR"},
{&swap, 1, "SWAP"},
{chr, 8, "CHR"},
{&IRQCount, 1, "IRQCOUNT"},
{&IRQPre, 1, "IRQPRE"},
{&IRQa, 1, "IRQA"},
{0}
};
static void SyncPrg(void)
{
if(swap&3)
{
setprg8(0x8000,~1);
setprg8(0xC000,prg0);
}
else
{
setprg8(0x8000,prg0);
setprg8(0xC000,~1);
}
setprg8(0xA000,prg1);
setprg8(0xE000,~0);
}
static void SyncChr(void)
{
int i;
for(i=0; i<8; i++)
setchr1(i<<10,chr[i]);
setmirror(mirr^1);
}
static void StateRestore(int version)
{
SyncPrg();
SyncChr();
}
static DECLFW(UNLTF1201Write)
{
A=(A&0xF003)|((A&0xC)>>2);
if((A>=0xB000)&&(A<=0xE003))
{
int ind=(((A>>11)-6)|(A&1))&7;
int sar=((A&2)<<1);
chr[ind]=(chr[ind]&(0xF0>>sar))|((V&0x0F)<<sar);
SyncChr();
}
else switch (A&0xF003)
{
case 0x8000: prg0=V; SyncPrg(); break;
case 0xA000: prg1=V; SyncPrg(); break;
case 0x9000: mirr=V&1; SyncChr(); break;
case 0x9001: swap=V&3; SyncPrg(); break;
case 0xF000: IRQCount=((IRQCount&0xF0)|(V&0xF)); break;
case 0xF002: IRQCount=((IRQCount&0x0F)|((V&0xF)<<4)); break;
case 0xF001:
case 0xF003: IRQa=V&2; X6502_IRQEnd(FCEU_IQEXT); if(scanline<240) IRQCount-=8; break;
}
}
static void UNLTF1201IRQCounter(void)
{
if(IRQa)
{
IRQCount++;
if(IRQCount==237)
{
X6502_IRQBegin(FCEU_IQEXT);
}
}
}
static void UNLTF1201Power(void)
{
IRQPre=IRQCount=IRQa=0;
SetReadHandler(0x8000,0xFFFF,CartBR);
SetWriteHandler(0x8000,0xFFFF,UNLTF1201Write);
SyncPrg();
SyncChr();
}
void UNLTF1201_Init(CartInfo *info)
{
info->Power=UNLTF1201Power;
GameHBIRQHook=UNLTF1201IRQCounter;
GameStateRestore=StateRestore;
AddExState(&StateRegs, ~0, 0, 0);
}

View File

@ -1,678 +0,0 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2002 Xodnizel
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "types.h"
#include "fceu.h"
#include "ppu.h"
#include "cart.h"
#include "x6502.h"
#include "general.h"
/*
This file contains all code for coordinating the mapping in of the
address space external to the NES.
It's also (ab)used by the NSF code.
*/
uint8 *Page[32],*VPage[8];
uint8 **VPageR=VPage;
uint8 *VPageG[8];
uint8 *MMC5SPRVPage[8];
uint8 *MMC5BGVPage[8];
static uint8 PRGIsRAM[32]; /* This page is/is not PRG RAM. */
/* 16 are (sort of) reserved for UNIF/iNES and 16 to map other stuff. */
static int CHRram[32];
static int PRGram[32];
uint8 *PRGptr[32];
uint8 *CHRptr[32];
uint32 PRGsize[32];
uint32 CHRsize[32];
uint32 PRGmask2[32];
uint32 PRGmask4[32];
uint32 PRGmask8[32];
uint32 PRGmask16[32];
uint32 PRGmask32[32];
uint32 CHRmask1[32];
uint32 CHRmask2[32];
uint32 CHRmask4[32];
uint32 CHRmask8[32];
int geniestage=0;
int modcon;
uint8 genieval[3];
uint8 geniech[3];
uint32 genieaddr[3];
static INLINE void setpageptr(int s, uint32 A, uint8 *p, int ram)
{
uint32 AB=A>>11;
int x;
if(p)
for(x=(s>>1)-1;x>=0;x--)
{
PRGIsRAM[AB+x]=ram;
Page[AB+x]=p-A;
}
else
for(x=(s>>1)-1;x>=0;x--)
{
PRGIsRAM[AB+x]=0;
Page[AB+x]=0;
}
}
static uint8 nothing[8192];
void ResetCartMapping(void)
{
int x;
for(x=0;x<32;x++)
{
Page[x]=nothing-x*2048;
PRGptr[x]=CHRptr[x]=0;
PRGsize[x]=CHRsize[x]=0;
}
for(x=0;x<8;x++)
{
MMC5SPRVPage[x]=MMC5BGVPage[x]=VPageR[x]=nothing-0x400*x;
}
}
void SetupCartPRGMapping(int chip, uint8 *p, uint32 size, int ram)
{
PRGptr[chip]=p;
PRGsize[chip]=size;
PRGmask2[chip]=(size>>11)-1;
PRGmask4[chip]=(size>>12)-1;
PRGmask8[chip]=(size>>13)-1;
PRGmask16[chip]=(size>>14)-1;
PRGmask32[chip]=(size>>15)-1;
PRGram[chip]=ram?1:0;
}
void SetupCartCHRMapping(int chip, uint8 *p, uint32 size, int ram)
{
CHRptr[chip]=p;
CHRsize[chip]=size;
CHRmask1[chip]=(size>>10)-1;
CHRmask2[chip]=(size>>11)-1;
CHRmask4[chip]=(size>>12)-1;
CHRmask8[chip]=(size>>13)-1;
CHRram[chip]=ram;
}
DECLFR(CartBR)
{
return Page[A>>11][A];
}
DECLFW(CartBW)
{
//printf("Ok: %04x:%02x, %d\n",A,V,PRGIsRAM[A>>11]);
if(PRGIsRAM[A>>11] && Page[A>>11])
Page[A>>11][A]=V;
}
DECLFR(CartBROB)
{
if(!Page[A>>11]) return(X.DB);
return Page[A>>11][A];
}
void FASTAPASS(3) setprg2r(int r, unsigned int A, unsigned int V)
{
V&=PRGmask2[r];
setpageptr(2,A,PRGptr[r]?(&PRGptr[r][V<<11]):0,PRGram[r]);
}
void FASTAPASS(2) setprg2(uint32 A, uint32 V)
{
setprg2r(0,A,V);
}
void FASTAPASS(3) setprg4r(int r, unsigned int A, unsigned int V)
{
V&=PRGmask4[r];
setpageptr(4,A,PRGptr[r]?(&PRGptr[r][V<<12]):0,PRGram[r]);
}
void FASTAPASS(2) setprg4(uint32 A, uint32 V)
{
setprg4r(0,A,V);
}
void FASTAPASS(3) setprg8r(int r, unsigned int A, unsigned int V)
{
if(PRGsize[r]>=8192)
{
V&=PRGmask8[r];
setpageptr(8,A,PRGptr[r]?(&PRGptr[r][V<<13]):0,PRGram[r]);
}
else
{
uint32 VA=V<<2;
int x;
for(x=0;x<4;x++)
setpageptr(2,A+(x<<11),PRGptr[r]?(&PRGptr[r][((VA+x)&PRGmask2[r])<<11]):0,PRGram[r]);
}
}
void FASTAPASS(2) setprg8(uint32 A, uint32 V)
{
setprg8r(0,A,V);
}
void FASTAPASS(3) setprg16r(int r, unsigned int A, unsigned int V)
{
if(PRGsize[r]>=16384)
{
V&=PRGmask16[r];
setpageptr(16,A,PRGptr[r]?(&PRGptr[r][V<<14]):0,PRGram[r]);
}
else
{
uint32 VA=V<<3;
int x;
for(x=0;x<8;x++)
setpageptr(2,A+(x<<11),PRGptr[r]?(&PRGptr[r][((VA+x)&PRGmask2[r])<<11]):0,PRGram[r]);
}
}
void FASTAPASS(2) setprg16(uint32 A, uint32 V)
{
setprg16r(0,A,V);
}
void FASTAPASS(3) setprg32r(int r,unsigned int A, unsigned int V)
{
if(PRGsize[r]>=32768)
{
V&=PRGmask32[r];
setpageptr(32,A,PRGptr[r]?(&PRGptr[r][V<<15]):0,PRGram[r]);
}
else
{
uint32 VA=V<<4;
int x;
for(x=0;x<16;x++)
setpageptr(2,A+(x<<11),PRGptr[r]?(&PRGptr[r][((VA+x)&PRGmask2[r])<<11]):0,PRGram[r]);
}
}
void FASTAPASS(2) setprg32(uint32 A, uint32 V)
{
setprg32r(0,A,V);
}
void FASTAPASS(3) setchr1r(int r, unsigned int A, unsigned int V)
{
if(!CHRptr[r]) return;
FCEUPPU_LineUpdate();
V&=CHRmask1[r];
if(CHRram[r])
PPUCHRRAM|=(1<<(A>>10));
else
PPUCHRRAM&=~(1<<(A>>10));
VPageR[(A)>>10]=&CHRptr[r][(V)<<10]-(A);
}
void FASTAPASS(3) setchr2r(int r, unsigned int A, unsigned int V)
{
if(!CHRptr[r]) return;
FCEUPPU_LineUpdate();
V&=CHRmask2[r];
VPageR[(A)>>10]=VPageR[((A)>>10)+1]=&CHRptr[r][(V)<<11]-(A);
if(CHRram[r])
PPUCHRRAM|=(3<<(A>>10));
else
PPUCHRRAM&=~(3<<(A>>10));
}
void FASTAPASS(3) setchr4r(int r, unsigned int A, unsigned int V)
{
if(!CHRptr[r]) return;
FCEUPPU_LineUpdate();
V&=CHRmask4[r];
VPageR[(A)>>10]=VPageR[((A)>>10)+1]=
VPageR[((A)>>10)+2]=VPageR[((A)>>10)+3]=&CHRptr[r][(V)<<12]-(A);
if(CHRram[r])
PPUCHRRAM|=(15<<(A>>10));
else
PPUCHRRAM&=~(15<<(A>>10));
}
void FASTAPASS(2) setchr8r(int r, unsigned int V)
{
int x;
if(!CHRptr[r]) return;
FCEUPPU_LineUpdate();
V&=CHRmask8[r];
for(x=7;x>=0;x--)
VPageR[x]=&CHRptr[r][V<<13];
if(CHRram[r])
PPUCHRRAM|=(255);
else
PPUCHRRAM&=~(255);
}
void FASTAPASS(2) setchr1(unsigned int A, unsigned int V)
{
setchr1r(0,A,V);
}
void FASTAPASS(2) setchr2(unsigned int A, unsigned int V)
{
setchr2r(0,A,V);
}
void FASTAPASS(2) setchr4(unsigned int A, unsigned int V)
{
setchr4r(0,A,V);
}
void FASTAPASS(1) setchr8(unsigned int V)
{
setchr8r(0,V);
}
void FASTAPASS(1) setvram8(uint8 *p)
{
int x;
for(x=7;x>=0;x--)
VPageR[x]=p;
PPUCHRRAM|=255;
}
void FASTAPASS(2) setvram4(uint32 A, uint8 *p)
{
int x;
for(x=3;x>=0;x--)
VPageR[(A>>10)+x]=p-A;
PPUCHRRAM|=(15<<(A>>10));
}
void FASTAPASS(3) setvramb1(uint8 *p, uint32 A, uint32 b)
{
FCEUPPU_LineUpdate();
VPageR[A>>10]=p-A+(b<<10);
PPUCHRRAM|=(1<<(A>>10));
}
void FASTAPASS(3) setvramb2(uint8 *p, uint32 A, uint32 b)
{
FCEUPPU_LineUpdate();
VPageR[(A>>10)]=VPageR[(A>>10)+1]=p-A+(b<<11);
PPUCHRRAM|=(3<<(A>>10));
}
void FASTAPASS(3) setvramb4(uint8 *p, uint32 A, uint32 b)
{
int x;
FCEUPPU_LineUpdate();
for(x=3;x>=0;x--)
VPageR[(A>>10)+x]=p-A+(b<<12);
PPUCHRRAM|=(15<<(A>>10));
}
void FASTAPASS(2) setvramb8(uint8 *p, uint32 b)
{
int x;
FCEUPPU_LineUpdate();
for(x=7;x>=0;x--)
VPageR[x]=p+(b<<13);
PPUCHRRAM|=255;
}
/* This function can be called without calling SetupCartMirroring(). */
void FASTAPASS(3) setntamem(uint8 *p, int ram, uint32 b)
{
FCEUPPU_LineUpdate();
vnapage[b]=p;
PPUNTARAM&=~(1<<b);
if(ram)
PPUNTARAM|=1<<b;
}
static int mirrorhard=0;
void setmirrorw(int a, int b, int c, int d)
{
FCEUPPU_LineUpdate();
vnapage[0]=NTARAM+a*0x400;
vnapage[1]=NTARAM+b*0x400;
vnapage[2]=NTARAM+c*0x400;
vnapage[3]=NTARAM+d*0x400;
}
void FASTAPASS(1) setmirror(int t)
{
FCEUPPU_LineUpdate();
if(!mirrorhard)
{
switch(t)
{
case MI_H:
vnapage[0]=vnapage[1]=NTARAM;vnapage[2]=vnapage[3]=NTARAM+0x400;
break;
case MI_V:
vnapage[0]=vnapage[2]=NTARAM;vnapage[1]=vnapage[3]=NTARAM+0x400;
break;
case MI_0:
vnapage[0]=vnapage[1]=vnapage[2]=vnapage[3]=NTARAM;
break;
case MI_1:
vnapage[0]=vnapage[1]=vnapage[2]=vnapage[3]=NTARAM+0x400;
break;
}
PPUNTARAM=0xF;
}
}
void SetupCartMirroring(int m, int hard, uint8 *extra)
{
if(m<4)
setmirror(m);
else
{
vnapage[0]=NTARAM;
vnapage[1]=NTARAM+0x400;
vnapage[2]=extra;
vnapage[3]=extra+0x400;
PPUNTARAM=0xF;
}
mirrorhard=hard;
}
static uint8 *GENIEROM=0;
void FixGenieMap(void);
/* Called when a game(file) is opened successfully. */
void OpenGenie(void)
{
FILE *fp;
int x;
if(!GENIEROM)
{
char *fn;
if(!(GENIEROM=(uint8 *)malloc(4096+1024))) return;
fn=FCEU_MakeFName(FCEUMKF_GGROM,0,0);
fp=FCEUD_UTF8fopen(fn,"rb");
if(!fp)
{
FCEU_PrintError("Error opening Game Genie ROM image!");
free(GENIEROM);
GENIEROM=0;
return;
}
if(fread(GENIEROM,1,16,fp)!=16)
{
grerr:
FCEU_PrintError("Error reading from Game Genie ROM image!");
free(GENIEROM);
GENIEROM=0;
fclose(fp);
return;
}
if(GENIEROM[0]==0x4E) /* iNES ROM image */
{
if(fread(GENIEROM,1,4096,fp)!=4096)
goto grerr;
if(fseek(fp,16384-4096,SEEK_CUR))
goto grerr;
if(fread(GENIEROM+4096,1,256,fp)!=256)
goto grerr;
}
else
{
if(fread(GENIEROM+16,1,4352-16,fp)!=(4352-16))
goto grerr;
}
fclose(fp);
/* Workaround for the FCE Ultra CHR page size only being 1KB */
for(x=0;x<4;x++)
memcpy(GENIEROM+4096+(x<<8),GENIEROM+4096,256);
}
geniestage=1;
}
/* Called when a game is closed. */
void CloseGenie(void)
{
/* No good reason to free() the Game Genie ROM image data. */
geniestage=0;
FlushGenieRW();
VPageR=VPage;
}
void FCEU_KillGenie(void)
{
if(GENIEROM)
{
free(GENIEROM);
GENIEROM=0;
}
}
static DECLFR(GenieRead)
{
return GENIEROM[A&4095];
}
static DECLFW(GenieWrite)
{
switch(A)
{
case 0x800c:
case 0x8008:
case 0x8004:genieval[((A-4)&0xF)>>2]=V;break;
case 0x800b:
case 0x8007:
case 0x8003:geniech[((A-3)&0xF)>>2]=V;break;
case 0x800a:
case 0x8006:
case 0x8002:genieaddr[((A-2)&0xF)>>2]&=0xFF00;genieaddr[((A-2)&0xF)>>2]|=V;break;
case 0x8009:
case 0x8005:
case 0x8001:genieaddr[((A-1)&0xF)>>2]&=0xFF;genieaddr[((A-1)&0xF)>>2]|=(V|0x80)<<8;break;
case 0x8000:if(!V)
FixGenieMap();
else
{
modcon=V^0xFF;
if(V==0x71)
modcon=0;
}
break;
}
}
static readfunc GenieBackup[3];
static DECLFR(GenieFix1)
{
uint8 r=GenieBackup[0](A);
if((modcon>>1)&1) // No check
return genieval[0];
else if(r==geniech[0])
return genieval[0];
return r;
}
static DECLFR(GenieFix2)
{
uint8 r=GenieBackup[1](A);
if((modcon>>2)&1) // No check
return genieval[1];
else if(r==geniech[1])
return genieval[1];
return r;
}
static DECLFR(GenieFix3)
{
uint8 r=GenieBackup[2](A);
if((modcon>>3)&1) // No check
return genieval[2];
else if(r==geniech[2])
return genieval[2];
return r;
}
void FixGenieMap(void)
{
int x;
geniestage=2;
for(x=0;x<8;x++)
VPage[x]=VPageG[x];
VPageR=VPage;
FlushGenieRW();
//printf("Rightyo\n");
for(x=0;x<3;x++)
if((modcon>>(4+x))&1)
{
readfunc tmp[3]={GenieFix1,GenieFix2,GenieFix3};
GenieBackup[x]=GetReadHandler(genieaddr[x]);
SetReadHandler(genieaddr[x],genieaddr[x],tmp[x]);
}
}
void GeniePower(void)
{
uint32 x;
if(!geniestage)
return;
geniestage=1;
for(x=0;x<3;x++)
{
genieval[x]=0xFF;
geniech[x]=0xFF;
genieaddr[x]=0xFFFF;
}
modcon=0;
SetWriteHandler(0x8000,0xFFFF,GenieWrite);
SetReadHandler(0x8000,0xFFFF,GenieRead);
for(x=0;x<8;x++)
VPage[x]=GENIEROM+4096-0x400*x;
if(AllocGenieRW())
VPageR=VPageG;
else
geniestage=2;
}
void FCEU_SaveGameSave(CartInfo *LocalHWInfo)
{
if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0])
{
FILE *sp;
char *soot;
soot=FCEU_MakeFName(FCEUMKF_SAV,0,"sav");
if((sp=FCEUD_UTF8fopen(soot,"wb"))==NULL)
{
FCEU_PrintError("WRAM file \"%s\" cannot be written to.\n",soot);
}
else
{
int x;
for(x=0;x<4;x++)
if(LocalHWInfo->SaveGame[x])
{
fwrite(LocalHWInfo->SaveGame[x],1,
LocalHWInfo->SaveGameLen[x],sp);
}
}
free(soot);
}
}
void FCEU_LoadGameSave(CartInfo *LocalHWInfo)
{
if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0])
{
FILE *sp;
char *soot;
soot=FCEU_MakeFName(FCEUMKF_SAV,0,"sav");
sp=FCEUD_UTF8fopen(soot,"rb");
if(sp!=NULL)
{
int x;
for(x=0;x<4;x++)
if(LocalHWInfo->SaveGame[x])
fread(LocalHWInfo->SaveGame[x],1,LocalHWInfo->SaveGameLen[x],sp);
}
free(soot);
}
}

686
source/fceultra/cart.cpp Normal file
View File

@ -0,0 +1,686 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2002 Xodnizel
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/// \file
/// \brief This file contains all code for coordinating the mapping in of the address space external to the NES.
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "types.h"
#include "fceu.h"
#include "ppu.h"
#include "driver.h"
#include "cart.h"
#include "x6502.h"
#include "file.h"
#include "utils/memory.h"
uint8 *Page[32],*VPage[8];
uint8 **VPageR=VPage;
uint8 *VPageG[8];
uint8 *MMC5SPRVPage[8];
uint8 *MMC5BGVPage[8];
static uint8 PRGIsRAM[32]; /* This page is/is not PRG RAM. */
/* 16 are (sort of) reserved for UNIF/iNES and 16 to map other stuff. */
static int CHRram[32];
static int PRGram[32];
uint8 *PRGptr[32];
uint8 *CHRptr[32];
uint32 PRGsize[32];
uint32 CHRsize[32];
uint32 PRGmask2[32];
uint32 PRGmask4[32];
uint32 PRGmask8[32];
uint32 PRGmask16[32];
uint32 PRGmask32[32];
uint32 CHRmask1[32];
uint32 CHRmask2[32];
uint32 CHRmask4[32];
uint32 CHRmask8[32];
int geniestage=0;
int modcon;
uint8 genieval[3];
uint8 geniech[3];
uint32 genieaddr[3];
static INLINE void setpageptr(int s, uint32 A, uint8 *p, int ram)
{
uint32 AB=A>>11;
int x;
if(p)
for(x=(s>>1)-1;x>=0;x--)
{
PRGIsRAM[AB+x]=ram;
Page[AB+x]=p-A;
}
else
for(x=(s>>1)-1;x>=0;x--)
{
PRGIsRAM[AB+x]=0;
Page[AB+x]=0;
}
}
static uint8 nothing[8192];
void ResetCartMapping(void)
{
int x;
for(x=0;x<32;x++)
{
Page[x]=nothing-x*2048;
PRGptr[x]=CHRptr[x]=0;
PRGsize[x]=CHRsize[x]=0;
}
for(x=0;x<8;x++)
{
MMC5SPRVPage[x]=MMC5BGVPage[x]=VPageR[x]=nothing-0x400*x;
}
}
void SetupCartPRGMapping(int chip, uint8 *p, uint32 size, int ram)
{
PRGptr[chip]=p;
PRGsize[chip]=size;
PRGmask2[chip]=(size>>11)-1;
PRGmask4[chip]=(size>>12)-1;
PRGmask8[chip]=(size>>13)-1;
PRGmask16[chip]=(size>>14)-1;
PRGmask32[chip]=(size>>15)-1;
PRGram[chip]=ram?1:0;
}
void SetupCartCHRMapping(int chip, uint8 *p, uint32 size, int ram)
{
CHRptr[chip]=p;
CHRsize[chip]=size;
CHRmask1[chip]=(size>>10)-1;
CHRmask2[chip]=(size>>11)-1;
CHRmask4[chip]=(size>>12)-1;
CHRmask8[chip]=(size>>13)-1;
CHRram[chip]=ram;
}
DECLFR(CartBR)
{
return Page[A>>11][A];
}
DECLFW(CartBW)
{
//printf("Ok: %04x:%02x, %d\n",A,V,PRGIsRAM[A>>11]);
if(PRGIsRAM[A>>11] && Page[A>>11])
Page[A>>11][A]=V;
}
DECLFR(CartBROB)
{
if(!Page[A>>11]) return(X.DB);
return Page[A>>11][A];
}
void setprg2r(int r, unsigned int A, unsigned int V)
{
V&=PRGmask2[r];
setpageptr(2,A,PRGptr[r]?(&PRGptr[r][V<<11]):0,PRGram[r]);
}
void setprg2(uint32 A, uint32 V)
{
setprg2r(0,A,V);
}
void setprg4r(int r, unsigned int A, unsigned int V)
{
V&=PRGmask4[r];
setpageptr(4,A,PRGptr[r]?(&PRGptr[r][V<<12]):0,PRGram[r]);
}
void setprg4(uint32 A, uint32 V)
{
setprg4r(0,A,V);
}
void setprg8r(int r, unsigned int A, unsigned int V)
{
if(PRGsize[r]>=8192)
{
V&=PRGmask8[r];
setpageptr(8,A,PRGptr[r]?(&PRGptr[r][V<<13]):0,PRGram[r]);
}
else
{
uint32 VA=V<<2;
int x;
for(x=0;x<4;x++)
setpageptr(2,A+(x<<11),PRGptr[r]?(&PRGptr[r][((VA+x)&PRGmask2[r])<<11]):0,PRGram[r]);
}
}
void setprg8(uint32 A, uint32 V)
{
setprg8r(0,A,V);
}
void setprg16r(int r, unsigned int A, unsigned int V)
{
if(PRGsize[r]>=16384)
{
V&=PRGmask16[r];
setpageptr(16,A,PRGptr[r]?(&PRGptr[r][V<<14]):0,PRGram[r]);
}
else
{
uint32 VA=V<<3;
int x;
for(x=0;x<8;x++)
setpageptr(2,A+(x<<11),PRGptr[r]?(&PRGptr[r][((VA+x)&PRGmask2[r])<<11]):0,PRGram[r]);
}
}
void setprg16(uint32 A, uint32 V)
{
setprg16r(0,A,V);
}
void setprg32r(int r,unsigned int A, unsigned int V)
{
if(PRGsize[r]>=32768)
{
V&=PRGmask32[r];
setpageptr(32,A,PRGptr[r]?(&PRGptr[r][V<<15]):0,PRGram[r]);
}
else
{
uint32 VA=V<<4;
int x;
for(x=0;x<16;x++)
setpageptr(2,A+(x<<11),PRGptr[r]?(&PRGptr[r][((VA+x)&PRGmask2[r])<<11]):0,PRGram[r]);
}
}
void setprg32(uint32 A, uint32 V)
{
setprg32r(0,A,V);
}
void setchr1r(int r, unsigned int A, unsigned int V)
{
if(!CHRptr[r]) return;
FCEUPPU_LineUpdate();
V&=CHRmask1[r];
if(CHRram[r])
PPUCHRRAM|=(1<<(A>>10));
else
PPUCHRRAM&=~(1<<(A>>10));
VPageR[(A)>>10]=&CHRptr[r][(V)<<10]-(A);
}
void setchr2r(int r, unsigned int A, unsigned int V)
{
if(!CHRptr[r]) return;
FCEUPPU_LineUpdate();
V&=CHRmask2[r];
VPageR[(A)>>10]=VPageR[((A)>>10)+1]=&CHRptr[r][(V)<<11]-(A);
if(CHRram[r])
PPUCHRRAM|=(3<<(A>>10));
else
PPUCHRRAM&=~(3<<(A>>10));
}
void setchr4r(int r, unsigned int A, unsigned int V)
{
if(!CHRptr[r]) return;
FCEUPPU_LineUpdate();
V&=CHRmask4[r];
VPageR[(A)>>10]=VPageR[((A)>>10)+1]=
VPageR[((A)>>10)+2]=VPageR[((A)>>10)+3]=&CHRptr[r][(V)<<12]-(A);
if(CHRram[r])
PPUCHRRAM|=(15<<(A>>10));
else
PPUCHRRAM&=~(15<<(A>>10));
}
void setchr8r(int r, unsigned int V)
{
int x;
if(!CHRptr[r]) return;
FCEUPPU_LineUpdate();
V&=CHRmask8[r];
for(x=7;x>=0;x--)
VPageR[x]=&CHRptr[r][V<<13];
if(CHRram[r])
PPUCHRRAM|=(255);
else
PPUCHRRAM&=~(255);
}
void setchr1(unsigned int A, unsigned int V)
{
setchr1r(0,A,V);
}
void setchr2(unsigned int A, unsigned int V)
{
setchr2r(0,A,V);
}
void setchr4(unsigned int A, unsigned int V)
{
setchr4r(0,A,V);
}
void setchr8(unsigned int V)
{
setchr8r(0,V);
}
void setvram8(uint8 *p)
{
int x;
for(x=7;x>=0;x--)
VPageR[x]=p;
PPUCHRRAM|=255;
}
void setvram4(uint32 A, uint8 *p)
{
int x;
for(x=3;x>=0;x--)
VPageR[(A>>10)+x]=p-A;
PPUCHRRAM|=(15<<(A>>10));
}
void setvramb1(uint8 *p, uint32 A, uint32 b)
{
FCEUPPU_LineUpdate();
VPageR[A>>10]=p-A+(b<<10);
PPUCHRRAM|=(1<<(A>>10));
}
void setvramb2(uint8 *p, uint32 A, uint32 b)
{
FCEUPPU_LineUpdate();
VPageR[(A>>10)]=VPageR[(A>>10)+1]=p-A+(b<<11);
PPUCHRRAM|=(3<<(A>>10));
}
void setvramb4(uint8 *p, uint32 A, uint32 b)
{
int x;
FCEUPPU_LineUpdate();
for(x=3;x>=0;x--)
VPageR[(A>>10)+x]=p-A+(b<<12);
PPUCHRRAM|=(15<<(A>>10));
}
void setvramb8(uint8 *p, uint32 b)
{
int x;
FCEUPPU_LineUpdate();
for(x=7;x>=0;x--)
VPageR[x]=p+(b<<13);
PPUCHRRAM|=255;
}
/* This function can be called without calling SetupCartMirroring(). */
void setntamem(uint8 *p, int ram, uint32 b)
{
FCEUPPU_LineUpdate();
vnapage[b]=p;
PPUNTARAM&=~(1<<b);
if(ram)
PPUNTARAM|=1<<b;
}
static int mirrorhard=0;
void setmirrorw(int a, int b, int c, int d)
{
FCEUPPU_LineUpdate();
vnapage[0]=NTARAM+a*0x400;
vnapage[1]=NTARAM+b*0x400;
vnapage[2]=NTARAM+c*0x400;
vnapage[3]=NTARAM+d*0x400;
}
void setmirror(int t)
{
FCEUPPU_LineUpdate();
if(!mirrorhard)
{
switch(t)
{
case MI_H:
vnapage[0]=vnapage[1]=NTARAM;vnapage[2]=vnapage[3]=NTARAM+0x400;
break;
case MI_V:
vnapage[0]=vnapage[2]=NTARAM;vnapage[1]=vnapage[3]=NTARAM+0x400;
break;
case MI_0:
vnapage[0]=vnapage[1]=vnapage[2]=vnapage[3]=NTARAM;
break;
case MI_1:
vnapage[0]=vnapage[1]=vnapage[2]=vnapage[3]=NTARAM+0x400;
break;
}
PPUNTARAM=0xF;
}
}
void SetupCartMirroring(int m, int hard, uint8 *extra)
{
if(m<4)
{
mirrorhard = 0;
setmirror(m);
}
else
{
vnapage[0]=NTARAM;
vnapage[1]=NTARAM+0x400;
vnapage[2]=extra;
vnapage[3]=extra+0x400;
PPUNTARAM=0xF;
}
mirrorhard=hard;
}
static uint8 *GENIEROM=0;
void FixGenieMap(void);
// Called when a game(file) is opened successfully.
void OpenGenie(void)
{
FILE *fp;
int x;
if(!GENIEROM)
{
char *fn;
if(!(GENIEROM=(uint8 *)FCEU_malloc(4096+1024))) return;
fn=strdup(FCEU_MakeFName(FCEUMKF_GGROM,0,0).c_str());
fp=FCEUD_UTF8fopen(fn,"rb");
if(!fp)
{
FCEU_PrintError("Error opening Game Genie ROM image!");
free(GENIEROM);
GENIEROM=0;
return;
}
if(fread(GENIEROM,1,16,fp)!=16)
{
grerr:
FCEU_PrintError("Error reading from Game Genie ROM image!");
free(GENIEROM);
GENIEROM=0;
fclose(fp);
return;
}
if(GENIEROM[0]==0x4E) /* iNES ROM image */
{
if(fread(GENIEROM,1,4096,fp)!=4096)
goto grerr;
if(fseek(fp,16384-4096,SEEK_CUR))
goto grerr;
if(fread(GENIEROM+4096,1,256,fp)!=256)
goto grerr;
}
else
{
if(fread(GENIEROM+16,1,4352-16,fp)!=(4352-16))
goto grerr;
}
fclose(fp);
/* Workaround for the FCE Ultra CHR page size only being 1KB */
for(x=0;x<4;x++)
memcpy(GENIEROM+4096+(x<<8),GENIEROM+4096,256);
}
geniestage=1;
}
/* Called when a game is closed. */
void CloseGenie(void)
{
/* No good reason to free() the Game Genie ROM image data. */
geniestage=0;
FlushGenieRW();
VPageR=VPage;
}
void FCEU_KillGenie(void)
{
if(GENIEROM)
{
free(GENIEROM);
GENIEROM=0;
}
}
static DECLFR(GenieRead)
{
return GENIEROM[A&4095];
}
static DECLFW(GenieWrite)
{
switch(A)
{
case 0x800c:
case 0x8008:
case 0x8004:genieval[((A-4)&0xF)>>2]=V;break;
case 0x800b:
case 0x8007:
case 0x8003:geniech[((A-3)&0xF)>>2]=V;break;
case 0x800a:
case 0x8006:
case 0x8002:genieaddr[((A-2)&0xF)>>2]&=0xFF00;genieaddr[((A-2)&0xF)>>2]|=V;break;
case 0x8009:
case 0x8005:
case 0x8001:genieaddr[((A-1)&0xF)>>2]&=0xFF;genieaddr[((A-1)&0xF)>>2]|=(V|0x80)<<8;break;
case 0x8000:if(!V)
FixGenieMap();
else
{
modcon=V^0xFF;
if(V==0x71)
modcon=0;
}
break;
}
}
static readfunc GenieBackup[3];
static DECLFR(GenieFix1)
{
uint8 r=GenieBackup[0](A);
if((modcon>>1)&1) // No check
return genieval[0];
else if(r==geniech[0])
return genieval[0];
return r;
}
static DECLFR(GenieFix2)
{
uint8 r=GenieBackup[1](A);
if((modcon>>2)&1) // No check
return genieval[1];
else if(r==geniech[1])
return genieval[1];
return r;
}
static DECLFR(GenieFix3)
{
uint8 r=GenieBackup[2](A);
if((modcon>>3)&1) // No check
return genieval[2];
else if(r==geniech[2])
return genieval[2];
return r;
}
void FixGenieMap(void)
{
int x;
geniestage=2;
for(x=0;x<8;x++)
VPage[x]=VPageG[x];
VPageR=VPage;
FlushGenieRW();
//printf("Rightyo\n");
for(x=0;x<3;x++)
if((modcon>>(4+x))&1)
{
readfunc tmp[3]={GenieFix1,GenieFix2,GenieFix3};
GenieBackup[x]=GetReadHandler(genieaddr[x]);
SetReadHandler(genieaddr[x],genieaddr[x],tmp[x]);
}
}
void GeniePower(void)
{
uint32 x;
if(!geniestage)
return;
geniestage=1;
for(x=0;x<3;x++)
{
genieval[x]=0xFF;
geniech[x]=0xFF;
genieaddr[x]=0xFFFF;
}
modcon=0;
SetWriteHandler(0x8000,0xFFFF,GenieWrite);
SetReadHandler(0x8000,0xFFFF,GenieRead);
for(x=0;x<8;x++)
VPage[x]=GENIEROM+4096-0x400*x;
if(AllocGenieRW())
VPageR=VPageG;
else
geniestage=2;
}
void FCEU_SaveGameSave(CartInfo *LocalHWInfo)
{
if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0])
{
FILE *sp;
std::string soot = FCEU_MakeFName(FCEUMKF_SAV,0,"sav");
if((sp=FCEUD_UTF8fopen(soot,"wb"))==NULL)
{
FCEU_PrintError("WRAM file \"%s\" cannot be written to.\n",soot);
}
else
{
for(int x=0;x<4;x++)
if(LocalHWInfo->SaveGame[x])
{
fwrite(LocalHWInfo->SaveGame[x],1,
LocalHWInfo->SaveGameLen[x],sp);
}
}
}
}
// hack, movie.cpp has to communicate with this function somehow
int disableBatteryLoading=0;
void FCEU_LoadGameSave(CartInfo *LocalHWInfo)
{
if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0] && !disableBatteryLoading)
{
FILE *sp;
std::string soot = FCEU_MakeFName(FCEUMKF_SAV,0,"sav");
sp=FCEUD_UTF8fopen(soot,"rb");
if(sp!=NULL)
{
for(int x=0;x<4;x++)
if(LocalHWInfo->SaveGame[x])
fread(LocalHWInfo->SaveGame[x],1,LocalHWInfo->SaveGameLen[x],sp);
}
}
}
//clears all save memory. call this if you want to pretend the saveram has been reset (it doesnt touch what is on disk though)
void FCEU_ClearGameSave(CartInfo *LocalHWInfo)
{
if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0])
{
for(int x=0;x<4;x++)
if(LocalHWInfo->SaveGame[x])
memset(LocalHWInfo->SaveGame[x],0,LocalHWInfo->SaveGameLen[x]);
}
}

View File

@ -1,28 +1,29 @@
typedef struct {
/* Set by mapper/board code: */
void (*Power)(void);
void (*Reset)(void);
void (*Close)(void);
uint8 *SaveGame[4]; /* Pointers to memory to save/load. */
uint32 SaveGameLen[4]; /* How much memory to save/load. */
/* Set by mapper/board code: */
void (*Power)(void);
void (*Reset)(void);
void (*Close)(void);
uint8 *SaveGame[4]; /* Pointers to memory to save/load. */
uint32 SaveGameLen[4]; /* How much memory to save/load. */
/* Set by iNES/UNIF loading code. */
int mirror; /* As set in the header or chunk.
iNES/UNIF specific. Intended
to help support games like "Karnov"
that are not really MMC3 but are
set to mapper 4.
*/
int battery; /* Presence of an actual battery. */
uint8 MD5[16];
uint32 CRC32; /* Should be set by the iNES/UNIF loading
code, used by mapper/board code, maybe
other code in the future.
*/
/* Set by iNES/UNIF loading code. */
int mirror; /* As set in the header or chunk.
iNES/UNIF specific. Intended
to help support games like "Karnov"
that are not really MMC3 but are
set to mapper 4.
*/
int battery; /* Presence of an actual battery. */
uint8 MD5[16];
uint32 CRC32; /* Should be set by the iNES/UNIF loading
code, used by mapper/board code, maybe
other code in the future.
*/
} CartInfo;
void FCEU_SaveGameSave(CartInfo *LocalHWInfo);
void FCEU_LoadGameSave(CartInfo *LocalHWInfo);
void FCEU_ClearGameSave(CartInfo *LocalHWInfo);
extern uint8 *Page[32],*VPage[8],*MMC5SPRVPage[8],*MMC5BGVPage[8];
@ -52,39 +53,39 @@ extern uint32 CHRmask2[32];
extern uint32 CHRmask4[32];
extern uint32 CHRmask8[32];
void FASTAPASS(2) setprg2(uint32 A, uint32 V);
void FASTAPASS(2) setprg4(uint32 A, uint32 V);
void FASTAPASS(2) setprg8(uint32 A, uint32 V);
void FASTAPASS(2) setprg16(uint32 A, uint32 V);
void FASTAPASS(2) setprg32(uint32 A, uint32 V);
void setprg2(uint32 A, uint32 V);
void setprg4(uint32 A, uint32 V);
void setprg8(uint32 A, uint32 V);
void setprg16(uint32 A, uint32 V);
void setprg32(uint32 A, uint32 V);
void FASTAPASS(3) setprg2r(int r, unsigned int A, unsigned int V);
void FASTAPASS(3) setprg4r(int r, unsigned int A, unsigned int V);
void FASTAPASS(3) setprg8r(int r, unsigned int A, unsigned int V);
void FASTAPASS(3) setprg16r(int r, unsigned int A, unsigned int V);
void FASTAPASS(3) setprg32r(int r, unsigned int A, unsigned int V);
void setprg2r(int r, unsigned int A, unsigned int V);
void setprg4r(int r, unsigned int A, unsigned int V);
void setprg8r(int r, unsigned int A, unsigned int V);
void setprg16r(int r, unsigned int A, unsigned int V);
void setprg32r(int r, unsigned int A, unsigned int V);
void FASTAPASS(3) setchr1r(int r, unsigned int A, unsigned int V);
void FASTAPASS(3) setchr2r(int r, unsigned int A, unsigned int V);
void FASTAPASS(3) setchr4r(int r, unsigned int A, unsigned int V);
void FASTAPASS(2) setchr8r(int r, unsigned int V);
void setchr1r(int r, unsigned int A, unsigned int V);
void setchr2r(int r, unsigned int A, unsigned int V);
void setchr4r(int r, unsigned int A, unsigned int V);
void setchr8r(int r, unsigned int V);
void FASTAPASS(2) setchr1(unsigned int A, unsigned int V);
void FASTAPASS(2) setchr2(unsigned int A, unsigned int V);
void FASTAPASS(2) setchr4(unsigned int A, unsigned int V);
void FASTAPASS(1) setchr8(unsigned int V);
void setchr1(unsigned int A, unsigned int V);
void setchr2(unsigned int A, unsigned int V);
void setchr4(unsigned int A, unsigned int V);
void setchr8(unsigned int V);
void FASTAPASS(2) setvram4(uint32 A, uint8 *p);
void FASTAPASS(1) setvram8(uint8 *p);
void setvram4(uint32 A, uint8 *p);
void setvram8(uint8 *p);
void FASTAPASS(3) setvramb1(uint8 *p, uint32 A, uint32 b);
void FASTAPASS(3) setvramb2(uint8 *p, uint32 A, uint32 b);
void FASTAPASS(3) setvramb4(uint8 *p, uint32 A, uint32 b);
void FASTAPASS(2) setvramb8(uint8 *p, uint32 b);
void setvramb1(uint8 *p, uint32 A, uint32 b);
void setvramb2(uint8 *p, uint32 A, uint32 b);
void setvramb4(uint8 *p, uint32 A, uint32 b);
void setvramb8(uint8 *p, uint32 b);
void FASTAPASS(1) setmirror(int t);
void setmirror(int t);
void setmirrorw(int a, int b, int c, int d);
void FASTAPASS(3) setntamem(uint8 *p, int ram, uint32 b);
void setntamem(uint8 *p, int ram, uint32 b);
#define MI_H 0
#define MI_V 1

View File

@ -1,854 +0,0 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2002 Xodnizel
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include "types.h"
#include "x6502.h"
#include "cheat.h"
#include "fceu.h"
#include "general.h"
#include "cart.h"
static uint8 *CheatRPtrs[64];
void FCEU_CheatResetRAM(void)
{
int x;
for(x=0;x<64;x++)
CheatRPtrs[x]=0;
}
void FCEU_CheatAddRAM(int s, uint32 A, uint8 *p)
{
uint32 AB=A>>10;
int x;
for(x=s-1;x>=0;x--)
CheatRPtrs[AB+x]=p-A;
}
struct CHEATF {
struct CHEATF *next;
char *name;
uint16 addr;
uint8 val;
int compare; /* -1 for no compare. */
int type; /* 0 for replace, 1 for substitute(GG). */
int status;
};
typedef struct {
uint16 addr;
uint8 val;
int compare;
readfunc PrevRead;
} CHEATF_SUBFAST;
static CHEATF_SUBFAST SubCheats[256];
static int numsubcheats=0;
struct CHEATF *cheats=0,*cheatsl=0;
#define CHEATC_NONE 0x8000
#define CHEATC_EXCLUDED 0x4000
#define CHEATC_NOSHOW 0xC000
static uint16 *CheatComp=0;
static int savecheats;
static DECLFR(SubCheatsRead)
{
CHEATF_SUBFAST *s=SubCheats;
int x=numsubcheats;
do
{
if(s->addr==A)
{
if(s->compare>=0)
{
uint8 pv=s->PrevRead(A);
if(pv==s->compare)
return(s->val);
else return(pv);
}
else return(s->val);
}
s++;
} while(--x);
return(0); /* We should never get here. */
}
void RebuildSubCheats(void)
{
int x;
struct CHEATF *c=cheats;
for(x=0;x<numsubcheats;x++)
SetReadHandler(SubCheats[x].addr,SubCheats[x].addr,SubCheats[x].PrevRead);
numsubcheats=0;
while(c)
{
if(c->type==1 && c->status)
{
if(GetReadHandler(c->addr)==SubCheatsRead)
{
/* Prevent a catastrophe by this check. */
//FCEU_DispMessage("oops");
}
else
{
SubCheats[numsubcheats].PrevRead=GetReadHandler(c->addr);
SubCheats[numsubcheats].addr=c->addr;
SubCheats[numsubcheats].val=c->val;
SubCheats[numsubcheats].compare=c->compare;
SetReadHandler(c->addr,c->addr,SubCheatsRead);
numsubcheats++;
}
}
c=c->next;
}
}
void FCEU_PowerCheats()
{
numsubcheats=0; /* Quick hack to prevent setting of ancient read addresses. */
RebuildSubCheats();
}
static int AddCheatEntry(char *name, uint32 addr, uint8 val, int compare, int status, int type);
static void CheatMemErr(void)
{
FCEUD_PrintError("Error allocating memory for cheat data.");
}
/* This function doesn't allocate any memory for "name" */
static int AddCheatEntry(char *name, uint32 addr, uint8 val, int compare, int status, int type)
{
struct CHEATF *temp;
if(!(temp=(struct CHEATF *)malloc(sizeof(struct CHEATF))))
{
CheatMemErr();
return(0);
}
temp->name=name;
temp->addr=addr;
temp->val=val;
temp->status=status;
temp->compare=compare;
temp->type=type;
temp->next=0;
if(cheats)
{
cheatsl->next=temp;
cheatsl=temp;
}
else
cheats=cheatsl=temp;
return(1);
}
void FCEU_LoadGameCheats(FILE *override)
{
FILE *fp;
unsigned int addr;
unsigned int val;
unsigned int status;
unsigned int type;
unsigned int compare;
int x;
char linebuf[2048];
char *namebuf;
int tc=0;
char *fn;
numsubcheats=savecheats=0;
if(override)
fp = override;
else
{
fn=FCEU_MakeFName(FCEUMKF_CHEAT,0,0);
fp=FCEUD_UTF8fopen(fn,"rb");
free(fn);
if(!fp) return;
}
while(fgets(linebuf,2048,fp)>0)
{
char *tbuf=linebuf;
int doc=0;
addr=val=compare=status=type=0;
if(tbuf[0]=='S')
{
tbuf++;
type=1;
}
else type=0;
if(tbuf[0]=='C')
{
tbuf++;
doc=1;
}
if(tbuf[0]==':')
{
tbuf++;
status=0;
}
else status=1;
if(doc)
{
char *neo=&tbuf[4+2+2+1+1+1];
if(sscanf(tbuf,"%04x%*[:]%02x%*[:]%02x",&addr,&val,&compare)!=3)
continue;
namebuf=malloc(strlen(neo)+1);
strcpy(namebuf,neo);
}
else
{
char *neo=&tbuf[4+2+1+1];
if(sscanf(tbuf,"%04x%*[:]%02x",&addr,&val)!=2)
continue;
namebuf=malloc(strlen(neo)+1);
strcpy(namebuf,neo);
}
for(x=0;x<strlen(namebuf);x++)
{
if(namebuf[x]==10 || namebuf[x]==13)
{
namebuf[x]=0;
break;
}
else if(namebuf[x]<0x20) namebuf[x]=' ';
}
AddCheatEntry(namebuf,addr,val,doc?compare:-1,status,type);
tc++;
}
RebuildSubCheats();
if(!override)
fclose(fp);
}
void FCEU_FlushGameCheats(FILE *override, int nosave)
{
if(CheatComp)
{
free(CheatComp);
CheatComp=0;
}
if((!savecheats || nosave) && !override) /* Always save cheats if we're being overridden. */
{
if(cheats)
{
struct CHEATF *next=cheats;
for(;;)
{
struct CHEATF *last=next;
next=next->next;
free(last->name);
free(last);
if(!next) break;
}
cheats=cheatsl=0;
}
}
else
{
char *fn = 0;
if(!override)
fn = FCEU_MakeFName(FCEUMKF_CHEAT,0,0);
if(cheats)
{
struct CHEATF *next=cheats;
FILE *fp;
if(override)
fp = override;
else
fp=FCEUD_UTF8fopen(fn,"wb");
if(fp)
{
for(;;)
{
struct CHEATF *t;
if(next->type)
fputc('S',fp);
if(next->compare>=0)
fputc('C',fp);
if(!next->status)
fputc(':',fp);
if(next->compare>=0)
fprintf(fp,"%04x:%02x:%02x:%s\n",next->addr,next->val,next->compare,next->name);
else
fprintf(fp,"%04x:%02x:%s\n",next->addr,next->val,next->name);
free(next->name);
t=next;
next=next->next;
free(t);
if(!next) break;
}
if(!override)
fclose(fp);
}
else
FCEUD_PrintError("Error saving cheats.");
cheats=cheatsl=0;
}
//else if(!override)
// remove(fn);
if(!override)
free(fn);
}
RebuildSubCheats(); /* Remove memory handlers. */
}
int FCEUI_AddCheat(const char *name, uint32 addr, uint8 val, int compare, int type)
{
char *t;
if(!(t=(char *)malloc(strlen(name)+1)))
{
CheatMemErr();
return(0);
}
strcpy(t,name);
if(!AddCheatEntry(t,addr,val,compare,1,type))
{
free(t);
return(0);
}
savecheats=1;
RebuildSubCheats();
return(1);
}
int FCEUI_DelCheat(uint32 which)
{
struct CHEATF *prev;
struct CHEATF *cur;
uint32 x=0;
for(prev=0,cur=cheats;;)
{
if(x==which) // Remove this cheat.
{
if(prev) // Update pointer to this cheat.
{
if(cur->next) // More cheats.
prev->next=cur->next;
else // No more.
{
prev->next=0;
cheatsl=prev; // Set the previous cheat as the last cheat.
}
}
else // This is the first cheat.
{
if(cur->next) // More cheats
cheats=cur->next;
else
cheats=cheatsl=0; // No (more) cheats.
}
free(cur->name); // Now that all references to this cheat are removed,
free(cur); // free the memory.
break;
} // *END REMOVE THIS CHEAT*
if(!cur->next) // No more cheats to go through(this shouldn't ever happen...)
return(0);
prev=cur;
cur=prev->next;
x++;
}
savecheats=1;
RebuildSubCheats();
return(1);
}
void FCEU_ApplyPeriodicCheats(void)
{
struct CHEATF *cur=cheats;
if(!cur) return;
for(;;)
{
if(cur->status && !(cur->type))
if(CheatRPtrs[cur->addr>>10])
CheatRPtrs[cur->addr>>10][cur->addr]=cur->val;
if(cur->next)
cur=cur->next;
else
break;
}
}
void FCEUI_ListCheats(int (*callb)(char *name, uint32 a, uint8 v, int compare, int s, int type, void *data), void *data)
{
struct CHEATF *next=cheats;
while(next)
{
if(!callb(next->name,next->addr,next->val,next->compare,next->status,next->type,data)) break;
next=next->next;
}
}
int FCEUI_GetCheat(uint32 which, char **name, uint32 *a, uint8 *v, int *compare, int *s, int *type)
{
struct CHEATF *next=cheats;
uint32 x=0;
while(next)
{
if(x==which)
{
if(name)
*name=next->name;
if(a)
*a=next->addr;
if(v)
*v=next->val;
if(s)
*s=next->status;
if(compare)
*compare=next->compare;
if(type)
*type=next->type;
return(1);
}
next=next->next;
x++;
}
return(0);
}
static int GGtobin(char c)
{
static char lets[16]={'A','P','Z','L','G','I','T','Y','E','O','X','U','K','S','V','N'};
int x;
for(x=0;x<16;x++)
if(lets[x] == toupper(c)) return(x);
return(0);
}
/* Returns 1 on success, 0 on failure. Sets *a,*v,*c. */
int FCEUI_DecodeGG(const char *str, uint16 *a, uint8 *v, int *c)
{
uint16 A;
uint8 V,C;
uint8 t;
int s;
A=0x8000;
V=0;
C=0;
s=strlen(str);
if(s!=6 && s!=8) return(0);
t=GGtobin(*str++);
V|=(t&0x07);
V|=(t&0x08)<<4;
t=GGtobin(*str++);
V|=(t&0x07)<<4;
A|=(t&0x08)<<4;
t=GGtobin(*str++);
A|=(t&0x07)<<4;
//if(t&0x08) return(0); /* 8-character code?! */
t=GGtobin(*str++);
A|=(t&0x07)<<12;
A|=(t&0x08);
t=GGtobin(*str++);
A|=(t&0x07);
A|=(t&0x08)<<8;
if(s==6)
{
t=GGtobin(*str++);
A|=(t&0x07)<<8;
V|=(t&0x08);
*a=A;
*v=V;
*c=-1;
return(1);
}
else
{
t=GGtobin(*str++);
A|=(t&0x07)<<8;
C|=(t&0x08);
t=GGtobin(*str++);
C|=(t&0x07);
C|=(t&0x08)<<4;
t=GGtobin(*str++);
C|=(t&0x07)<<4;
V|=(t&0x08);
*a=A;
*v=V;
*c=C;
return(1);
}
return(0);
}
int FCEUI_DecodePAR(const char *str, uint16 *a, uint8 *v, int *c, int *type)
{
int boo[4];
if(strlen(str)!=8) return(0);
sscanf(str,"%02x%02x%02x%02x",boo,boo+1,boo+2,boo+3);
*c=-1;
if(1)
{
*a=(boo[3]<<8)|(boo[2]+0x7F);
*v=0;
}
else
{
*v=boo[3];
*a=boo[2]|(boo[1]<<8);
}
/* Zero-page addressing modes don't go through the normal read/write handlers in FCEU, so
we must do the old hacky method of RAM cheats.
*/
if(*a<0x0100)
*type=0;
else
*type=1;
return(1);
}
/* name can be NULL if the name isn't going to be changed. */
/* same goes for a, v, and s(except the values of each one must be <0) */
int FCEUI_SetCheat(uint32 which, const char *name, int32 a, int32 v, int compare,int s, int type)
{
struct CHEATF *next=cheats;
uint32 x=0;
while(next)
{
if(x==which)
{
if(name)
{
char *t;
if((t=(char *)realloc(next->name,strlen(name+1))))
{
next->name=t;
strcpy(next->name,name);
}
else
return(0);
}
if(a>=0)
next->addr=a;
if(v>=0)
next->val=v;
if(s>=0)
next->status=s;
next->compare=compare;
next->type=type;
savecheats=1;
RebuildSubCheats();
return(1);
}
next=next->next;
x++;
}
return(0);
}
/* Convenience function. */
int FCEUI_ToggleCheat(uint32 which)
{
struct CHEATF *next=cheats;
uint32 x=0;
while(next)
{
if(x==which)
{
next->status=!next->status;
savecheats=1;
RebuildSubCheats();
return(next->status);
}
next=next->next;
x++;
}
return(-1);
}
static int InitCheatComp(void)
{
uint32 x;
CheatComp=(uint16*)malloc(65536*sizeof(uint16));
if(!CheatComp)
{
CheatMemErr();
return(0);
}
for(x=0;x<65536;x++)
CheatComp[x]=CHEATC_NONE;
return(1);
}
void FCEUI_CheatSearchSetCurrentAsOriginal(void)
{
uint32 x;
for(x=0x000;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW))
{
if(CheatRPtrs[x>>10])
CheatComp[x]=CheatRPtrs[x>>10][x];
else
CheatComp[x]|=CHEATC_NONE;
}
}
void FCEUI_CheatSearchShowExcluded(void)
{
uint32 x;
for(x=0x000;x<0x10000;x++)
CheatComp[x]&=~CHEATC_EXCLUDED;
}
int32 FCEUI_CheatSearchGetCount(void)
{
uint32 x,c=0;
if(CheatComp)
{
for(x=0x0000;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW) && CheatRPtrs[x>>10])
c++;
}
return c;
}
/* This function will give the initial value of the search and the current value at a location. */
void FCEUI_CheatSearchGet(int (*callb)(uint32 a, uint8 last, uint8 current, void *data),void *data)
{
uint32 x;
if(!CheatComp)
{
if(!InitCheatComp())
CheatMemErr();
return;
}
for(x=0;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW) && CheatRPtrs[x>>10])
if(!callb(x,CheatComp[x],CheatRPtrs[x>>10][x],data))
break;
}
void FCEUI_CheatSearchGetRange(uint32 first, uint32 last, int (*callb)(uint32 a, uint8 last, uint8 current))
{
uint32 x;
uint32 in=0;
if(!CheatComp)
{
if(!InitCheatComp())
CheatMemErr();
return;
}
for(x=0;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW) && CheatRPtrs[x>>10])
{
if(in>=first)
if(!callb(x,CheatComp[x],CheatRPtrs[x>>10][x]))
break;
in++;
if(in>last) return;
}
}
void FCEUI_CheatSearchBegin(void)
{
uint32 x;
if(!CheatComp)
{
if(!InitCheatComp())
{
CheatMemErr();
return;
}
}
for(x=0;x<0x10000;x++)
{
if(CheatRPtrs[x>>10])
CheatComp[x]=CheatRPtrs[x>>10][x];
else
CheatComp[x]=CHEATC_NONE;
}
}
static int INLINE CAbs(int x)
{
if(x<0)
return(0-x);
return x;
}
void FCEUI_CheatSearchEnd(int type, uint8 v1, uint8 v2)
{
uint32 x;
if(!CheatComp)
{
if(!InitCheatComp())
{
CheatMemErr();
return;
}
}
if(!type) // Change to a specific value.
{
for(x=0;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW))
{
if(CheatComp[x]==v1 && CheatRPtrs[x>>10][x]==v2)
{
}
else
CheatComp[x]|=CHEATC_EXCLUDED;
}
}
else if(type==1) // Search for relative change(between values).
{
for(x=0;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW))
{
if(CheatComp[x]==v1 && CAbs(CheatComp[x]-CheatRPtrs[x>>10][x])==v2)
{
}
else
CheatComp[x]|=CHEATC_EXCLUDED;
}
}
else if(type==2) // Purely relative change.
{
for(x=0x000;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW))
{
if(CAbs(CheatComp[x]-CheatRPtrs[x>>10][x])==v2)
{
}
else
CheatComp[x]|=CHEATC_EXCLUDED;
}
}
else if(type==3) // Any change.
{
for(x=0;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW))
{
if(CheatComp[x]!=CheatRPtrs[x>>10][x])
{
}
else
CheatComp[x]|=CHEATC_EXCLUDED;
}
}
else if(type==4) // Value decreased.
{
for(x=0;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW))
{
if(!(CheatRPtrs[x>>10][x]<CheatComp[x]))
CheatComp[x]|=CHEATC_EXCLUDED;
}
}
else if(type==5) // Value increased.
{
for(x=0;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW))
{
if(!(CheatRPtrs[x>>10][x]>CheatComp[x]))
CheatComp[x]|=CHEATC_EXCLUDED;
}
}
if(type>4)
FCEUI_CheatSearchSetCurrentAsOriginal();
}

956
source/fceultra/cheat.cpp Normal file
View File

@ -0,0 +1,956 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2002 Xodnizel
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <string>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include "types.h"
#include "x6502.h"
#include "cheat.h"
#include "fceu.h"
#include "file.h"
#include "cart.h"
#ifdef GEKKO
#include <string.h>
#else
#include "memory.h"
#endif
#include "driver.h"
using namespace std;
static uint8 *CheatRPtrs[64];
vector<uint16> FrozenAddresses; //List of addresses that are currently frozen
void UpdateFrozenList(void); //Function that populates the list of frozen addresses
unsigned int FrozenAddressCount=0; //Keeps up with the Frozen address count, necessary for using in other dialogs (such as hex editor)
void FCEU_CheatResetRAM(void)
{
int x;
for(x=0;x<64;x++)
CheatRPtrs[x]=0;
}
void FCEU_CheatAddRAM(int s, uint32 A, uint8 *p)
{
uint32 AB=A>>10;
int x;
for(x=s-1;x>=0;x--)
CheatRPtrs[AB+x]=p-A;
}
struct CHEATF {
struct CHEATF *next;
char *name;
uint16 addr;
uint8 val;
int compare; /* -1 for no compare. */
int type; /* 0 for replace, 1 for substitute(GG). */
int status;
};
typedef struct {
uint16 addr;
uint8 val;
int compare;
readfunc PrevRead;
} CHEATF_SUBFAST;
static CHEATF_SUBFAST SubCheats[256];
static int numsubcheats=0;
struct CHEATF *cheats=0,*cheatsl=0;
#define CHEATC_NONE 0x8000
#define CHEATC_EXCLUDED 0x4000
#define CHEATC_NOSHOW 0xC000
static uint16 *CheatComp=0;
static int savecheats;
static DECLFR(SubCheatsRead)
{
CHEATF_SUBFAST *s=SubCheats;
int x=numsubcheats;
do
{
if(s->addr==A)
{
if(s->compare>=0)
{
uint8 pv=s->PrevRead(A);
if(pv==s->compare)
return(s->val);
else return(pv);
}
else return(s->val);
}
s++;
} while(--x);
return(0); /* We should never get here. */
}
void RebuildSubCheats(void)
{
int x;
struct CHEATF *c=cheats;
for(x=0;x<numsubcheats;x++)
SetReadHandler(SubCheats[x].addr,SubCheats[x].addr,SubCheats[x].PrevRead);
numsubcheats=0;
while(c)
{
if(c->type==1 && c->status)
{
if(GetReadHandler(c->addr)==SubCheatsRead)
{
/* Prevent a catastrophe by this check. */
//FCEU_DispMessage("oops");
}
else
{
SubCheats[numsubcheats].PrevRead=GetReadHandler(c->addr);
SubCheats[numsubcheats].addr=c->addr;
SubCheats[numsubcheats].val=c->val;
SubCheats[numsubcheats].compare=c->compare;
SetReadHandler(c->addr,c->addr,SubCheatsRead);
numsubcheats++;
}
}
c=c->next;
}
FrozenAddressCount = numsubcheats; //Update the frozen address list
UpdateFrozenList();
//FCEUI_DispMessage("Active Cheats: %d", FrozenAddresses.size()/*FrozenAddressCount*/); //Debug
}
void FCEU_PowerCheats()
{
numsubcheats=0; /* Quick hack to prevent setting of ancient read addresses. */
RebuildSubCheats();
}
static int AddCheatEntry(char *name, uint32 addr, uint8 val, int compare, int status, int type);
static void CheatMemErr(void)
{
FCEUD_PrintError("Error allocating memory for cheat data.");
}
/* This function doesn't allocate any memory for "name" */
static int AddCheatEntry(char *name, uint32 addr, uint8 val, int compare, int status, int type)
{
struct CHEATF *temp;
if(!(temp=(struct CHEATF *)malloc(sizeof(struct CHEATF))))
{
CheatMemErr();
return(0);
}
temp->name=name;
temp->addr=addr;
temp->val=val;
temp->status=status;
temp->compare=compare;
temp->type=type;
temp->next=0;
if(cheats)
{
cheatsl->next=temp;
cheatsl=temp;
}
else
cheats=cheatsl=temp;
return(1);
}
void FCEU_LoadGameCheats(FILE *override)
{
FILE *fp;
unsigned int addr;
unsigned int val;
unsigned int status;
unsigned int type;
unsigned int compare;
int x;
char linebuf[2048];
char *namebuf;
int tc=0;
char *fn;
numsubcheats=savecheats=0;
if(override)
fp = override;
else
{
fn=strdup(FCEU_MakeFName(FCEUMKF_CHEAT,0,0).c_str());
fp=FCEUD_UTF8fopen(fn,"rb");
free(fn);
if(!fp) return;
}
FCEU_DispMessage("Cheats file loaded."); //Tells user a cheats file was loaded.
FCEU_printf("Cheats file loaded.\n"); //Sends message to message log.
while(fgets(linebuf,2048,fp)>0)
{
char *tbuf=linebuf;
int doc=0;
addr=val=compare=status=type=0;
if(tbuf[0]=='S')
{
tbuf++;
type=1;
}
else type=0;
if(tbuf[0]=='C')
{
tbuf++;
doc=1;
}
if(tbuf[0]==':')
{
tbuf++;
status=0;
}
else status=1;
if(doc)
{
char *neo=&tbuf[4+2+2+1+1+1];
if(sscanf(tbuf,"%04x%*[:]%02x%*[:]%02x",&addr,&val,&compare)!=3)
continue;
namebuf=(char *)malloc(strlen(neo)+1);
strcpy(namebuf,neo);
}
else
{
char *neo=&tbuf[4+2+1+1];
if(sscanf(tbuf,"%04x%*[:]%02x",&addr,&val)!=2)
continue;
namebuf=(char *)malloc(strlen(neo)+1);
strcpy(namebuf,neo);
}
for(x=0;x<(int)strlen(namebuf);x++)
{
if(namebuf[x]==10 || namebuf[x]==13)
{
namebuf[x]=0;
break;
}
else if(namebuf[x]<0x20) namebuf[x]=' ';
}
AddCheatEntry(namebuf,addr,val,doc?compare:-1,status,type);
tc++;
}
RebuildSubCheats();
if(!override)
fclose(fp);
}
void FCEU_FlushGameCheats(FILE *override, int nosave)
{
if(CheatComp)
{
free(CheatComp);
CheatComp=0;
}
if((!savecheats || nosave) && !override) /* Always save cheats if we're being overridden. */
{
if(cheats)
{
struct CHEATF *next=cheats;
for(;;)
{
struct CHEATF *last=next;
next=next->next;
free(last->name);
free(last);
if(!next) break;
}
cheats=cheatsl=0;
}
}
else
{
char *fn = 0;
if(!override)
fn = strdup(FCEU_MakeFName(FCEUMKF_CHEAT,0,0).c_str());
if(cheats)
{
struct CHEATF *next=cheats;
FILE *fp;
if(override)
fp = override;
else
fp=FCEUD_UTF8fopen(fn,"wb");
if(fp)
{
for(;;)
{
struct CHEATF *t;
if(next->type)
fputc('S',fp);
if(next->compare>=0)
fputc('C',fp);
if(!next->status)
fputc(':',fp);
if(next->compare>=0)
fprintf(fp,"%04x:%02x:%02x:%s\n",next->addr,next->val,next->compare,next->name);
else
fprintf(fp,"%04x:%02x:%s\n",next->addr,next->val,next->name);
free(next->name);
t=next;
next=next->next;
free(t);
if(!next) break;
}
if(!override)
fclose(fp);
}
else
FCEUD_PrintError("Error saving cheats.");
cheats=cheatsl=0;
}
else if(!override)
remove(fn);
if(!override)
free(fn);
}
RebuildSubCheats(); /* Remove memory handlers. */
}
int FCEUI_AddCheat(const char *name, uint32 addr, uint8 val, int compare, int type)
{
char *t;
if(!(t=(char *)malloc(strlen(name)+1)))
{
CheatMemErr();
return(0);
}
strcpy(t,name);
if(!AddCheatEntry(t,addr,val,compare,1,type))
{
free(t);
return(0);
}
savecheats=1;
RebuildSubCheats();
return(1);
}
int FCEUI_DelCheat(uint32 which)
{
struct CHEATF *prev;
struct CHEATF *cur;
uint32 x=0;
for(prev=0,cur=cheats;;)
{
if(x==which) // Remove this cheat.
{
if(prev) // Update pointer to this cheat.
{
if(cur->next) // More cheats.
prev->next=cur->next;
else // No more.
{
prev->next=0;
cheatsl=prev; // Set the previous cheat as the last cheat.
}
}
else // This is the first cheat.
{
if(cur->next) // More cheats
cheats=cur->next;
else
cheats=cheatsl=0; // No (more) cheats.
}
free(cur->name); // Now that all references to this cheat are removed,
free(cur); // free the memory.
break;
} // *END REMOVE THIS CHEAT*
if(!cur->next) // No more cheats to go through(this shouldn't ever happen...)
return(0);
prev=cur;
cur=prev->next;
x++;
}
savecheats=1;
RebuildSubCheats();
return(1);
}
void FCEU_ApplyPeriodicCheats(void)
{
struct CHEATF *cur=cheats;
if(!cur) return;
for(;;)
{
if(cur->status && !(cur->type))
if(CheatRPtrs[cur->addr>>10])
CheatRPtrs[cur->addr>>10][cur->addr]=cur->val;
if(cur->next)
cur=cur->next;
else
break;
}
}
void FCEUI_ListCheats(int (*callb)(char *name, uint32 a, uint8 v, int compare, int s, int type, void *data), void *data)
{
struct CHEATF *next=cheats;
while(next)
{
if(!callb(next->name,next->addr,next->val,next->compare,next->status,next->type,data)) break;
next=next->next;
}
}
int FCEUI_GetCheat(uint32 which, char **name, uint32 *a, uint8 *v, int *compare, int *s, int *type)
{
struct CHEATF *next=cheats;
uint32 x=0;
while(next)
{
if(x==which)
{
if(name)
*name=next->name;
if(a)
*a=next->addr;
if(v)
*v=next->val;
if(s)
*s=next->status;
if(compare)
*compare=next->compare;
if(type)
*type=next->type;
return(1);
}
next=next->next;
x++;
}
return(0);
}
static int GGtobin(char c)
{
static char lets[16]={'A','P','Z','L','G','I','T','Y','E','O','X','U','K','S','V','N'};
int x;
for(x=0;x<16;x++)
if(lets[x] == toupper(c)) return(x);
return(0);
}
/* Returns 1 on success, 0 on failure. Sets *a,*v,*c. */
int FCEUI_DecodeGG(const char *str, int *a, int *v, int *c)
{
uint16 A;
uint8 V,C;
uint8 t;
int s;
A=0x8000;
V=0;
C=0;
s=strlen(str);
if(s!=6 && s!=8) return(0);
t=GGtobin(*str++);
V|=(t&0x07);
V|=(t&0x08)<<4;
t=GGtobin(*str++);
V|=(t&0x07)<<4;
A|=(t&0x08)<<4;
t=GGtobin(*str++);
A|=(t&0x07)<<4;
//if(t&0x08) return(0); /* 8-character code?! */
t=GGtobin(*str++);
A|=(t&0x07)<<12;
A|=(t&0x08);
t=GGtobin(*str++);
A|=(t&0x07);
A|=(t&0x08)<<8;
if(s==6)
{
t=GGtobin(*str++);
A|=(t&0x07)<<8;
V|=(t&0x08);
*a=A;
*v=V;
*c=-1;
return(1);
}
else
{
t=GGtobin(*str++);
A|=(t&0x07)<<8;
C|=(t&0x08);
t=GGtobin(*str++);
C|=(t&0x07);
C|=(t&0x08)<<4;
t=GGtobin(*str++);
C|=(t&0x07)<<4;
V|=(t&0x08);
*a=A;
*v=V;
*c=C;
return(1);
}
return(0);
}
int FCEUI_DecodePAR(const char *str, int *a, int *v, int *c, int *type)
{
int boo[4];
if(strlen(str)!=8) return(0);
sscanf(str,"%02x%02x%02x%02x",boo,boo+1,boo+2,boo+3);
*c=-1;
if(1)
{
*a=(boo[3]<<8)|(boo[2]+0x7F);
*v=0;
}
else
{
*v=boo[3];
*a=boo[2]|(boo[1]<<8);
}
/* Zero-page addressing modes don't go through the normal read/write handlers in FCEU, so
we must do the old hacky method of RAM cheats.
*/
if(*a<0x0100)
*type=0;
else
*type=1;
return(1);
}
/* name can be NULL if the name isn't going to be changed. */
/* same goes for a, v, and s(except the values of each one must be <0) */
int FCEUI_SetCheat(uint32 which, const char *name, int32 a, int32 v, int compare,int s, int type)
{
struct CHEATF *next=cheats;
uint32 x=0;
while(next)
{
if(x==which)
{
if(name)
{
char *t;
if((t=(char *)realloc(next->name,strlen(name+1))))
{
next->name=t;
strcpy(next->name,name);
}
else
return(0);
}
if(a>=0)
next->addr=a;
if(v>=0)
next->val=v;
if(s>=0)
next->status=s;
next->compare=compare;
next->type=type;
savecheats=1;
RebuildSubCheats();
return(1);
}
next=next->next;
x++;
}
return(0);
}
/* Convenience function. */
int FCEUI_ToggleCheat(uint32 which)
{
struct CHEATF *next=cheats;
uint32 x=0;
while(next)
{
if(x==which)
{
next->status=!next->status;
savecheats=1;
RebuildSubCheats();
return(next->status);
}
next=next->next;
x++;
}
return(-1);
}
static int InitCheatComp(void)
{
uint32 x;
CheatComp=(uint16*)malloc(65536*sizeof(uint16));
if(!CheatComp)
{
CheatMemErr();
return(0);
}
for(x=0;x<65536;x++)
CheatComp[x]=CHEATC_NONE;
return(1);
}
void FCEUI_CheatSearchSetCurrentAsOriginal(void)
{
uint32 x;
for(x=0x000;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW))
{
if(CheatRPtrs[x>>10])
CheatComp[x]=CheatRPtrs[x>>10][x];
else
CheatComp[x]|=CHEATC_NONE;
}
}
void FCEUI_CheatSearchShowExcluded(void)
{
uint32 x;
for(x=0x000;x<0x10000;x++)
CheatComp[x]&=~CHEATC_EXCLUDED;
}
int32 FCEUI_CheatSearchGetCount(void)
{
uint32 x,c=0;
if(CheatComp)
{
for(x=0x0000;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW) && CheatRPtrs[x>>10])
c++;
}
return c;
}
/* This function will give the initial value of the search and the current value at a location. */
void FCEUI_CheatSearchGet(int (*callb)(uint32 a, uint8 last, uint8 current, void *data),void *data)
{
uint32 x;
if(!CheatComp)
{
if(!InitCheatComp())
CheatMemErr();
return;
}
for(x=0;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW) && CheatRPtrs[x>>10])
if(!callb(x,CheatComp[x],CheatRPtrs[x>>10][x],data))
break;
}
void FCEUI_CheatSearchGetRange(uint32 first, uint32 last, int (*callb)(uint32 a, uint8 last, uint8 current))
{
uint32 x;
uint32 in=0;
if(!CheatComp)
{
if(!InitCheatComp())
CheatMemErr();
return;
}
for(x=0;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW) && CheatRPtrs[x>>10])
{
if(in>=first)
if(!callb(x,CheatComp[x],CheatRPtrs[x>>10][x]))
break;
in++;
if(in>last) return;
}
}
void FCEUI_CheatSearchBegin(void)
{
uint32 x;
if(!CheatComp)
{
if(!InitCheatComp())
{
CheatMemErr();
return;
}
}
for(x=0;x<0x10000;x++)
{
if(CheatRPtrs[x>>10])
CheatComp[x]=CheatRPtrs[x>>10][x];
else
CheatComp[x]=CHEATC_NONE;
}
}
static int INLINE CAbs(int x)
{
if(x<0)
return(0-x);
return x;
}
void FCEUI_CheatSearchEnd(int type, uint8 v1, uint8 v2)
{
uint32 x;
if(!CheatComp)
{
if(!InitCheatComp())
{
CheatMemErr();
return;
}
}
if(!type) // Change to a specific value.
{
for(x=0;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW))
{
if(CheatComp[x]==v1 && CheatRPtrs[x>>10][x]==v2)
{
}
else
CheatComp[x]|=CHEATC_EXCLUDED;
}
}
else if(type==1) // Search for relative change(between values).
{
for(x=0;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW))
{
if(CheatComp[x]==v1 && CAbs(CheatComp[x]-CheatRPtrs[x>>10][x])==v2)
{
}
else
CheatComp[x]|=CHEATC_EXCLUDED;
}
}
else if(type==2) // Purely relative change.
{
for(x=0x000;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW))
{
if(CAbs(CheatComp[x]-CheatRPtrs[x>>10][x])==v2)
{
}
else
CheatComp[x]|=CHEATC_EXCLUDED;
}
}
else if(type==3) // Any change.
{
for(x=0x000;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW))
{
if(CheatComp[x]!=CheatRPtrs[x>>10][x])
{
}
else
CheatComp[x]|=CHEATC_EXCLUDED;
}
}
else if(type==4) // new value = known
{
for(x=0x000;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW))
{
if(CheatRPtrs[x>>10][x]==v1)
{
}
else
CheatComp[x]|=CHEATC_EXCLUDED;
}
}
else if(type==5) // new value greater than
{
for(x=0x000;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW))
{
if(CheatComp[x]<CheatRPtrs[x>>10][x])
{
}
else
CheatComp[x]|=CHEATC_EXCLUDED;
}
}
else if(type==6) // new value less than
{
for(x=0x000;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW))
{
if(CheatComp[x]>CheatRPtrs[x>>10][x])
{
}
else
CheatComp[x]|=CHEATC_EXCLUDED;
}
}
else if(type==7) // new value greater than by known value
{
for(x=0x000;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW))
{
if((CheatRPtrs[x>>10][x]-CheatComp[x])==v2)
{
}
else
CheatComp[x]|=CHEATC_EXCLUDED;
}
}
else if(type==8) // new value less than by known value
{
for(x=0x000;x<0x10000;x++)
if(!(CheatComp[x]&CHEATC_NOSHOW))
{
if((CheatComp[x]-CheatRPtrs[x>>10][x])==v2)
{
}
else
CheatComp[x]|=CHEATC_EXCLUDED;
}
}
}
int FCEU_CheatGetByte(uint32 A)
{
// if(CheatRPtrs[A>>10])
// return CheatRPtrs[A>>10][A]; //adelikat-commenting this stuff out so that lua can see frozen addresses, I hope this doesn't bork stuff.
/*else*/ if(A < 0x10000)
return ARead[A](A);
else
return 0;
}
void FCEU_CheatSetByte(uint32 A, uint8 V)
{
if(CheatRPtrs[A>>10])
CheatRPtrs[A>>10][A]=V;
else if(A < 0x10000)
BWrite[A](A, V);
}
void UpdateFrozenList(void)
{
//The purpose of this function is to keep an up to date list of addresses that are currently frozen
//and make these accessible to other dialogs that deal with memory addresses such as
//memwatch, hex editor, ramfilter, etc.
int x;
FrozenAddresses.clear(); //Clear vector and repopulate
for(x=0;x<numsubcheats;x++)
{
FrozenAddresses.push_back(SubCheats[x].addr);
//FCEU_printf("Address %d: %d \n",x,FrozenAddresses[x]); //Debug
}
//FCEUI_DispMessage("FrozenCount: %d",FrozenAddressCount);//Debug
}

Some files were not shown because too many files have changed in this diff Show More