diff --git a/src/boards/228.cpp b/src/boards/228.cpp new file mode 100644 index 00000000..be8b9482 --- /dev/null +++ b/src/boards/228.cpp @@ -0,0 +1,84 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "mapinc.h" + +static uint8 mram[4], vreg; +static uint16 areg; + +static SFORMAT StateRegs[] = +{ + { mram, 4, "MRAM" }, + { &areg, 2, "AREG" }, + { &vreg, 1, "VREG" }, + { 0 } +}; + +static void Sync(void) { + uint32 prgl, prgh, page = (areg >> 7) & 0x3F; + if ((page & 0x30) == 0x30) + page -= 0x10; + prgl = prgh = (page << 1) + (((areg >> 6) & 1) & ((areg >> 5) & 1)); + prgh += ((areg >> 5) & 1) ^ 1; + + setmirror(((areg >> 13) & 1) ^ 1); + setprg16(0x8000,prgl); + setprg16(0xc000,prgh); + setchr8(((vreg & 0x3) | ((areg & 0xF) << 2))); +} + +static DECLFW(M228RamWrite) { + mram[A & 3] = V & 0x0F; +} + +static DECLFR(M228RamRead) { + return mram[A & 3]; +} + +static DECLFW(M228Write) { + areg = A; + vreg = V; + Sync(); +} + +static void M228Reset(void) { + areg = 0x8000; + vreg = 0; + Sync(); +} + +static void M228Power(void) { + M228Reset(); + SetReadHandler(0x5000,0x5FFF,M228RamRead); + SetWriteHandler(0x5000,0x5FFF,M228RamWrite); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M228Write); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper228_Init(CartInfo *info) { + info->Reset = M228Reset; + info->Power = M228Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/230.cpp b/src/boards/230.cpp new file mode 100644 index 00000000..0da975dd --- /dev/null +++ b/src/boards/230.cpp @@ -0,0 +1,78 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * Copyright (C) 2009 qeed + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * 22 + Contra Reset based custom mapper... + * + */ + +#include "mapinc.h" + +static uint8 latche, reset; +static SFORMAT StateRegs[] = +{ + { &reset, 1, "RST" }, + { &latche, 1, "LATC" }, + { 0 } +}; + +static void Sync(void) { + if(reset) { + setprg16(0x8000, latche & 7); + setprg16(0xC000, 7); + setmirror(MI_V); + } else { + uint32 bank = (latche & 0x1F) + 8; + if (latche & 0x20) { + setprg16(0x8000, bank); + setprg16(0xC000, bank); + } else + setprg32(0x8000, bank >> 1); + setmirror((latche >> 6) & 1); + } + setchr8(0); +} + +static DECLFW(M230Write) { + latche = V; + Sync(); +} + +static void M230Reset(void) { + reset ^= 1; + Sync(); +} + +static void M230Power(void) { + latche = reset = 0; + Sync(); + SetWriteHandler(0x8000, 0xFFFF, M230Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper230_Init(CartInfo *info) { + info->Power = M230Power; + info->Reset = M230Reset; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/src/boards/232.cpp b/src/boards/232.cpp new file mode 100644 index 00000000..5f1df089 --- /dev/null +++ b/src/boards/232.cpp @@ -0,0 +1,68 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "mapinc.h" + +static uint8 bank, preg; +static SFORMAT StateRegs[] = +{ + { &bank, 1, "BANK" }, + { &preg, 1, "PREG" }, + { 0 } +}; + +static void Sync(void) { +// uint32 bbank = (bank & 0x18) >> 1; + uint32 bbank = ((bank & 0x10) >> 2) | (bank & 8); // some dumps have bbanks swapped, if swap commands, + // then all roms can be played, but with some swapped + // games in menu. if not, some dumps are unplayable + // make hard dump for both cart types to check + setprg16(0x8000, bbank | (preg & 3)); + setprg16(0xC000, bbank | 3); + setchr8(0); +} + +static DECLFW(M232WriteBank) { + bank = V; + Sync(); +} + +static DECLFW(M232WritePreg) { + preg = V; + Sync(); +} + +static void M232Power(void) { + bank = preg = 0; + Sync(); + SetWriteHandler(0x8000, 0xBFFF, M232WriteBank); + SetWriteHandler(0xC000, 0xFFFF, M232WritePreg); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper232_Init(CartInfo *info) { + info->Power = M232Power; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/src/boards/234.cpp b/src/boards/234.cpp new file mode 100644 index 00000000..ef471238 --- /dev/null +++ b/src/boards/234.cpp @@ -0,0 +1,79 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "mapinc.h" + +static uint8 bank, preg; +static SFORMAT StateRegs[] = +{ + { &bank, 1, "BANK" }, + { &preg, 1, "PREG" }, + { 0 } +}; + +static void Sync(void) { + if (bank & 0x40) { + setprg32(0x8000, (bank & 0xE) | (preg & 1)); + setchr8(((bank & 0xE) << 2) | ((preg >> 4) & 7)); + } else { + setprg32(0x8000, bank & 0xF); + setchr8(((bank & 0xF) << 2) | ((preg >> 4) & 3)); + } + setmirror((bank >> 7) ^ 1); +} + +DECLFR(M234ReadBank) { + uint8 r = CartBR(A); + if (!bank) { + bank = r; + Sync(); + } + return r; +} + +DECLFR(M234ReadPreg) { + uint8 r = CartBR(A); + preg = r; + Sync(); + return r; +} + +static void M234Reset(void) { + bank = preg = 0; + Sync(); +} + +static void M234Power(void) { + M234Reset(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetReadHandler(0xFF80, 0xFF9F, M234ReadBank); + SetReadHandler(0xFFE8, 0xFFF7, M234ReadPreg); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper234_Init(CartInfo *info) { + info->Power = M234Power; + info->Reset = M234Reset; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/src/boards/244.cpp b/src/boards/244.cpp new file mode 100644 index 00000000..67c33694 --- /dev/null +++ b/src/boards/244.cpp @@ -0,0 +1,77 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "mapinc.h" + +static uint8 preg, creg; +static SFORMAT StateRegs[] = +{ + { &preg, 1, "PREG" }, + { &creg, 1, "CREG" }, + { 0 } +}; + +static uint8 prg_perm[4][4] = { + { 0, 1, 2, 3, }, + { 3, 2, 1, 0, }, + { 0, 2, 1, 3, }, + { 3, 1, 2, 0, }, +}; + +static uint8 chr_perm[8][8] = { + { 0, 1, 2, 3, 4, 5, 6, 7, }, + { 0, 2, 1, 3, 4, 6, 5, 7, }, + { 0, 1, 4, 5, 2, 3, 6, 7, }, + { 0, 4, 1, 5, 2, 6, 3, 7, }, + { 0, 4, 2, 6, 1, 5, 3, 7, }, + { 0, 2, 4, 6, 1, 3, 5, 7, }, + { 7, 6, 5, 4, 3, 2, 1, 0, }, + { 7, 6, 5, 4, 3, 2, 1, 0, }, +}; + +static void Sync(void) { + setprg32(0x8000, preg); + setchr8(creg); +} + +static DECLFW(M244Write) { + if (V & 8) + creg = chr_perm[(V >> 4) & 7][V & 7]; + else + preg = prg_perm[(V >> 4) & 3][V & 3]; + Sync(); +} + +static void M244Power(void) { + preg = creg = 0; + Sync(); + SetWriteHandler(0x8000, 0xFFFF, M244Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper244_Init(CartInfo *info) { + info->Power = M244Power; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; +} diff --git a/src/boards/246.cpp b/src/boards/246.cpp new file mode 100644 index 00000000..726a97ed --- /dev/null +++ b/src/boards/246.cpp @@ -0,0 +1,86 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "mapinc.h" + +static uint8 regs[8]; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { regs, 8, "REGS" }, + { 0 } +}; + +static void Sync(void) { + setprg2r(0x10, 0x6800, 0); + setprg8(0x8000, regs[0]); + setprg8(0xA000, regs[1]); + setprg8(0xC000, regs[2]); + setprg8(0xE000, regs[3]); + setchr2(0x0000, regs[4]); + setchr2(0x0800, regs[5]); + setchr2(0x1000, regs[6]); + setchr2(0x1800, regs[7]); +} + +static DECLFW(M246Write) { + regs[A & 7] = V; + Sync(); +} + +static void M246Power(void) { + regs[0] = regs[1] = regs[2] = regs[3] = ~0; + Sync(); + SetWriteHandler(0x6000, 0x67FF, M246Write); + SetReadHandler(0x6800, 0x6FFF, CartBR); + SetWriteHandler(0x6800, 0x6FFF, CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void M246Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper246_Init(CartInfo *info) { + info->Power = M246Power; + info->Close = M246Close; + GameStateRestore = StateRestore; + + WRAMSIZE = 2048; + 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); +} diff --git a/src/boards/32.cpp b/src/boards/32.cpp new file mode 100644 index 00000000..3d2973c6 --- /dev/null +++ b/src/boards/32.cpp @@ -0,0 +1,102 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "mapinc.h" + +static uint8 preg[2], creg[8], mirr; + +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[] = +{ + { preg, 4, "PREG" }, + { creg, 8, "CREG" }, + { &mirr, 1, "MIRR" }, + { 0 } +}; + +static void Sync(void) { + uint16 swap = ((mirr & 2) << 13); + setmirror((mirr & 1) ^ 1); + setprg8r(0x10, 0x6000, 0); + setprg8(0x8000 ^ swap, preg[0]); + setprg8(0xA000, preg[1]); + setprg8(0xC000 ^ swap, ~1); + setprg8(0xE000, ~0); + uint8 i; + for (i = 0; i < 8; i++) + setchr1(i << 10, creg[i]); +} + +static DECLFW(M32Write0) { + preg[0] = V; + Sync(); +} + +static DECLFW(M32Write1) { + mirr = V; + Sync(); +} + +static DECLFW(M32Write2) { + preg[1] = V; + Sync(); +} + +static DECLFW(M32Write3) { + creg[A & 7] = V; + Sync(); +} + +static void M32Power(void) { + Sync(); + SetReadHandler(0x6000,0x7fff,CartBR); + SetWriteHandler(0x6000,0x7fff,CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0x8FFF, M32Write0); + SetWriteHandler(0x9000, 0x9FFF, M32Write1); + SetWriteHandler(0xA000, 0xAFFF, M32Write2); + SetWriteHandler(0xB000, 0xBFFF, M32Write3); +} + +static void M32Close(void) +{ + if (WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper32_Init(CartInfo *info) { + info->Power = M32Power; + info->Close = M32Close; + GameStateRestore = StateRestore; + + WRAMSIZE = 8192; + WRAM = (uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10, WRAM, WRAMSIZE, 1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/33.cpp b/src/boards/33.cpp new file mode 100644 index 00000000..daa6a773 --- /dev/null +++ b/src/boards/33.cpp @@ -0,0 +1,117 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "mapinc.h" + +static uint8 is48; +static uint8 regs[8], mirr; +static uint8 IRQa; +static int16 IRQCount, IRQLatch; + +static SFORMAT StateRegs[] = +{ + { regs, 8, "PREG" }, + { &mirr, 1, "MIRR" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 2, "IRQC" }, + { &IRQLatch, 2, "IRQL" }, + { 0 } +}; + +static void Sync(void) { + setmirror(mirr); + setprg8(0x8000, regs[0]); + setprg8(0xA000, regs[1]); + setprg8(0xC000, ~1); + setprg8(0xE000, ~0); + setchr2(0x0000, regs[2]); + setchr2(0x0800, regs[3]); + setchr1(0x1000, regs[4]); + setchr1(0x1400, regs[5]); + setchr1(0x1800, regs[6]); + setchr1(0x1C00, regs[7]); +} + +static DECLFW(M33Write) { + A &= 0xF003; + switch(A) { + case 0x8000: regs[0] = V & 0x3F; if(!is48) mirr = ((V >> 6) & 1) ^ 1; Sync(); break; + case 0x8001: regs[1] = V & 0x3F; Sync(); break; + case 0x8002: regs[2] = V; Sync(); break; + case 0x8003: regs[3] = V; Sync(); break; + case 0xA000: regs[4] = V; Sync(); break; + case 0xA001: regs[5] = V; Sync(); break; + case 0xA002: regs[6] = V; Sync(); break; + case 0xA003: regs[7] = V; Sync(); break; + } +} + +static DECLFW(M48Write) { + switch (A & 0xF003) { + case 0xC000: IRQLatch = V; break; + case 0xC001: IRQCount = IRQLatch; break; + case 0xC003: IRQa = 0; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xC002: IRQa = 1; break; + case 0xE000: mirr = ((V >> 6) & 1) ^ 1; Sync(); break; + } +} + +static void M33Power(void) { + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, M33Write); +} + +static void M48Power(void) { + Sync(); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xBFFF, M33Write); + SetWriteHandler(0xC000, 0xFFFF, M48Write); +} + +static void M48IRQ(void) { + if (IRQa) { + IRQCount++; + if (IRQCount == 0x100) { + X6502_IRQBegin(FCEU_IQEXT); + IRQa = 0; + } + } +} + +static void StateRestore(int version) { + Sync(); +} + +void Mapper33_Init(CartInfo *info) { + is48 = 0; + info->Power = M33Power; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper48_Init(CartInfo *info) { + is48 = 1; + info->Power = M48Power; + GameHBIRQHook = M48IRQ; + GameStateRestore = StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/src/boards/SConscript b/src/boards/SConscript index 10cd3aad..85d2e508 100644 --- a/src/boards/SConscript +++ b/src/boards/SConscript @@ -32,8 +32,16 @@ my_list = Split(""" 208.cpp 222.cpp 225.cpp +228.cpp +230.cpp +232.cpp +234.cpp 235.cpp +244.cpp +246.cpp 253.cpp +32.cpp +33.cpp 34.cpp 3d-block.cpp 411120-c.cpp diff --git a/src/boards/__dummy_mapper.cpp b/src/boards/__dummy_mapper.cpp index 5a150342..48f527b1 100644 --- a/src/boards/__dummy_mapper.cpp +++ b/src/boards/__dummy_mapper.cpp @@ -1,7 +1,7 @@ /* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: - * Copyright (C) 2009 CaH4e3 + * Copyright (C) 2012 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 @@ -21,6 +21,8 @@ #include "mapinc.h" static uint8 reg[8]; +static uint8 IRQa; +static int16 IRQCount, IRQLatch; /* static uint8 *WRAM=NULL; static uint32 WRAMSIZE; @@ -28,76 +30,71 @@ static uint8 *CHRRAM=NULL; static uint32 CHRRAMSIZE; */ -static SFORMAT StateRegs[]= +static SFORMAT StateRegs[] = { - {reg, 8, "REGS"}, - {0} + { reg, 8, "REGS" }, + { &IRQa, 1, "IRQA" }, + { &IRQCount, 2, "IRQC" }, + { &IRQLatch, 2, "IRQL" }, + { 0 } }; -static void Sync(void) -{ +static void Sync(void) { } -static DECLFW(MNNNWrite) -{ +static DECLFW(MNNNWrite) { } -static void MNNNPower(void) -{ +static void MNNNPower(void) { // SetReadHandler(0x6000,0x7fff,CartBR); -// SetWriteHandler(0x6000,0x7fff,CartBW); - SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x8000,0xFFFF,MNNNWrite); +// SetWriteHandler(0x6000,0x7fff,CartBW); + SetReadHandler(0x8000, 0xFFFF, CartBR); + SetWriteHandler(0x8000, 0xFFFF, MNNNWrite); } -static void MNNNReset(void) -{ +static void MNNNReset(void) { } /* static void MNNNClose(void) { - if(WRAM) - FCEU_gfree(WRAM); - if(CHRRAM) - FCEU_gfree(CHRRAM); - WRAM=CHRRAM=NULL; + if (WRAM) + FCEU_gfree(WRAM); + if (CHRRAM) + FCEU_gfree(CHRRAM); + WRAM = CHRRAM = NULL; } */ -static void MNNNIRQHook(void) -{ - X6502_IRQBegin(FCEU_IQEXT); +static void MNNNIRQHook() { + X6502_IRQBegin(FCEU_IQEXT); } -static void StateRestore(int version) -{ - Sync(); +static void StateRestore(int version) { + Sync(); } -void MapperNNN_Init(CartInfo *info) -{ - info->Reset=MNNNReset; - info->Power=MNNNPower; -// info->Close=MNNNClose; - GameHBIRQHook=MNNNIRQHook; - GameStateRestore=StateRestore; +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); - SetupCartCHRMapping(0x10,CHRRAM,CHRRAMSIZE,1); - AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); + CHRRAMSIZE = 8192; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); */ /* - 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; - } + 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); + AddExState(&StateRegs, ~0, 0, 0); } diff --git a/src/boards/bmc42in1r.cpp b/src/boards/bmc42in1r.cpp index b596ddd1..06d851ae 100644 --- a/src/boards/bmc42in1r.cpp +++ b/src/boards/bmc42in1r.cpp @@ -26,69 +26,61 @@ static uint8 isresetbased = 0; static uint8 latche[2], reset; -static SFORMAT StateRegs[]= +static SFORMAT StateRegs[] = { - {&reset, 1, "RST"}, - {latche, 2, "LATC"}, - {0} + { &reset, 1, "RST" }, + { latche, 2, "LATC" }, + { 0 } }; -static void Sync(void) -{ - uint8 bank; - if(isresetbased) - bank = (latche[0]&0x1f)|(reset<<5)|((latche[1]&1)<<6); - else - bank = (latche[0]&0x1f)|((latche[0]&0x80)>>2)|((latche[1]&1)<<6); - if(!(latche[0] & 0x20)) - setprg32(0x8000,bank >> 1); - else - { - setprg16(0x8000,bank); - setprg16(0xC000,bank); - } - setmirror((latche[0]>>6)&1); - setchr8(0); +static void Sync(void) { + uint8 bank; + if (isresetbased) + bank = (latche[0] & 0x1f) | (reset << 5) | ((latche[1] & 1) << 6); + else + bank = (latche[0] & 0x1f) | ((latche[0] & 0x80) >> 2) | ((latche[1] & 1) << 6); + if (!(latche[0] & 0x20)) + setprg32(0x8000, bank >> 1); + else{ + setprg16(0x8000, bank); + setprg16(0xC000, bank); + } + setmirror((latche[0] >> 6) & 1); + setchr8(0); } -static DECLFW(M226Write) -{ - latche[A & 1] = V; - Sync(); +static DECLFW(M226Write) { + latche[A & 1] = V; + Sync(); } -static void M226Power(void) -{ - latche[0] = latche[1] = reset = 0; - Sync(); - SetWriteHandler(0x8000,0xFFFF,M226Write); - SetReadHandler(0x8000,0xFFFF,CartBR); +static void M226Power(void) { + latche[0] = latche[1] = reset = 0; + Sync(); + SetWriteHandler(0x8000, 0xFFFF, M226Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); } -static void StateRestore(int version) -{ - Sync(); +static void StateRestore(int version) { + Sync(); } -void Mapper226_Init(CartInfo *info) -{ - isresetbased = 0; - info->Power=M226Power; - AddExState(&StateRegs, ~0, 0, 0); - GameStateRestore=StateRestore; +void Mapper226_Init(CartInfo *info) { + isresetbased = 0; + info->Power = M226Power; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; } -static void BMC42in1Reset(void) -{ - reset ^= 1; - Sync(); +static void M233Reset(void) { + reset ^= 1; + Sync(); } -void BMC42in1r_Init(CartInfo *info) -{ - isresetbased = 1; - info->Power=M226Power; - info->Reset=BMC42in1Reset; - AddExState(&StateRegs, ~0, 0, 0); - GameStateRestore=StateRestore; +void Mapper233_Init(CartInfo *info) { + isresetbased = 1; + info->Power = M226Power; + info->Reset = M233Reset; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore = StateRestore; } diff --git a/src/boards/vrc2and4.cpp b/src/boards/vrc2and4.cpp index fe10670f..0183d934 100644 --- a/src/boards/vrc2and4.cpp +++ b/src/boards/vrc2and4.cpp @@ -23,10 +23,11 @@ static uint8 isPirate, is22; static uint16 IRQCount; static uint8 IRQLatch, IRQa; -static uint8 prgreg[2]; -static uint8 chrreg[8]; +static uint8 prgreg[2], chrreg[8]; +static uint16 chrhi[8]; static uint8 regcmd, irqcmd, mirr, big_bank; static uint16 acount = 0; +static uint16 weirdo = 0; static uint8 *WRAM = NULL; static uint32 WRAMSIZE; @@ -35,6 +36,7 @@ static SFORMAT StateRegs[] = { { prgreg, 2, "PREG" }, { chrreg, 8, "CREG" }, + { chrhi, 16, "CRGH" }, { ®cmd, 1, "CMDR" }, { &irqcmd, 1, "CMDI" }, { &mirr, 1, "MIRR" }, @@ -49,7 +51,7 @@ static void Sync(void) { if (regcmd & 2) { setprg8(0xC000, prgreg[0] | big_bank); setprg8(0x8000, ((~1) & 0x1F) | big_bank); - }else { + } else { setprg8(0x8000, prgreg[0] | big_bank); setprg8(0xC000, ((~1) & 0x1F) | big_bank); } @@ -59,8 +61,15 @@ static void Sync(void) { setchr8(0); else{ uint8 i; - for (i = 0; i < 8; i++) - setchr1(i << 10, chrreg[i] >> is22); + if(!weirdo) + for (i = 0; i < 8; i++) + setchr1(i << 10, (chrhi[i] | chrreg[i]) >> is22); + else { + setchr1(0x0000, 0xFC); + setchr1(0x0400, 0xFD); + setchr1(0x0800, 0xFF); + weirdo--; + } } switch (mirr & 0x3) { case 0: setmirror(MI_V); break; @@ -77,11 +86,14 @@ static DECLFW(VRC24Write) { 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); + uint16 nibble = ((A & 1) << 2); + chrreg[i] &= (0xF0) >> nibble; + chrreg[i] |= (V & 0xF) << nibble; + if(nibble) + chrhi[i] = (V & 0x10) << 4; // another one many in one feature from pirate carts } Sync(); - }else + } else switch (A & 0xF003) { case 0x8000: case 0x8001: @@ -99,8 +111,8 @@ static DECLFW(VRC24Write) { if (!isPirate) prgreg[1] = V & 0x1F; else{ - prgreg[0] = (V << 1) & 0x1F; - prgreg[1] = ((V << 1) & 0x1F) | 1; + prgreg[0] = (V & 0x1F) << 1; + prgreg[1] = ((V & 0x1F) << 1) | 1; } Sync(); break; @@ -122,7 +134,11 @@ static DECLFW(M21Write) { } static DECLFW(M22Write) { - A |= ((A >> 2) & 0x3); // It's just swapped lines from 21 mapper + if (A == 0xC007) { // Ganbare Goemon Gaiden does strange things!!! at the end credits + weirdo = 8; // quick dirty hack, seems there is no other games with such PCB, so + // we never know if it will not work for something else lol + } + A |= ((A >> 2) & 0x3); // It's just swapped lines from 21 mapper // VRC24Write((A & 0xF000) | ((A >> 1) & 1) | ((A << 1) & 2), V); } @@ -212,10 +228,7 @@ void Mapper22_Init(CartInfo *info) { AddExState(&StateRegs, ~0, 0, 0); } -void Mapper23_Init(CartInfo *info) { - isPirate = 0; - is22 = 0; - info->Power = M23Power; +void VRC24_Init(CartInfo *info) { info->Close = VRC24Close; MapIRQHook = VRC24IRQHook; GameStateRestore = StateRestore; @@ -233,29 +246,23 @@ void Mapper23_Init(CartInfo *info) { AddExState(&StateRegs, ~0, 0, 0); } +void Mapper23_Init(CartInfo *info) { + isPirate = 0; + is22 = 0; + info->Power = M23Power; + VRC24_Init(info); +} + void Mapper25_Init(CartInfo *info) { isPirate = 0; is22 = 0; info->Power = M25Power; - info->Close = VRC24Close; - MapIRQHook = VRC24IRQHook; - 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); + VRC24_Init(info); } void UNLT230_Init(CartInfo *info) { isPirate = 1; is22 = 0; - Mapper23_Init(info); + info->Power = M23Power; + VRC24_Init(info); } diff --git a/src/ines-bad.h b/src/ines-bad.h index 0373eb37..179ab016 100644 --- a/src/ines-bad.h +++ b/src/ines-bad.h @@ -35,4 +35,6 @@ { 0x3716c4bebf885344LL, "Super Mario Bros.", INESB_HACKED }, { 0xfffda4407d80885aLL, "Sweet Home", INESB_CORRUPT }, { 0x103fc85d978b861bLL, "Sweet Home", INESB_CORRUPT }, +{ 0x7979dc51da86f19fLL, "110-in-1", INESB_CORRUPT }, +{ 0x001c0bb9c358252aLL, "110-in-1", INESB_CORRUPT }, { 0, 0, 0 } diff --git a/src/ines-correct.h b/src/ines-correct.h index 4bd6a3fb..010967b7 100644 --- a/src/ines-correct.h +++ b/src/ines-correct.h @@ -81,7 +81,9 @@ {0x6e68e31a, 16, 8}, /* Dragon Ball 3*/ {0x183859d2, 16, -1}, {0x33b899c9, 16, -1}, /* Dragon Ball - Dai Maou Fukkatsu (J) [!] */ - {0x286fcd20, 23, -1}, /* Ganbare Goemon Gaiden 2 - Tenka no Zaihou (J) [!] */ + {0x286fcd20, 23, -1}, /* Ganbare Goemon Gaiden 2 - Tenka no Zaihou (J) [!] */ + {0xe4a291ce, 23, -1}, /* World Hero (Unl) [!] */ + {0x51e9cd33, 23, -1}, /* World Hero (Unl) [b1] */ {0x5555fca3, 32, 8}, {0x283ad224, 32, 8}, /* Ai Sensei no Oshiete */ {0x243a8735, 32, 0x10|4}, /* Major League */ @@ -91,6 +93,7 @@ {0xf46ef39a, 37, -1}, /* Super Mario Bros. + Tetris + Nintendo World Cup (E) [!] */ {0x7ccb12a3, 43, -1}, /* SMB2j */ {0x6c71feae, 45, -1}, /* Kunio 8-in-1 */ + {0xe2c94bc2, 48, -1}, /* Super Bros 8 (Unl) [!] */ {0xaebd6549, 48, 8}, /* Bakushou!! Jinsei Gekijou 3 */ {0x6cdc0cd9, 48, 8}, /* Bubble Bobble 2 */ {0x99c395f9, 48, 8}, /* Captain Saver */ diff --git a/src/ines.cpp b/src/ines.cpp index d96d8a68..1d84e0b8 100644 --- a/src/ines.cpp +++ b/src/ines.cpp @@ -547,16 +547,16 @@ static BMAPPINGLocal bmap[] = { {"Konami VRC2/VRC4", 21, Mapper21_Init}, {"Konami VRC2/VRC4", 22, Mapper22_Init}, {"Konami VRC2/VRC4", 23, Mapper23_Init}, -// {"Konami VRC6", 24, Mapper24_Init}, +// {"", 24, Mapper24_Init}, {"Konami VRC2/VRC4", 25, Mapper25_Init}, // {"", 26, Mapper26_Init}, -// {"", 27, Mapper27_Init}, +// {"", 27, Mapper27_Init}, // Deprecated, dupe for VRC2/VRC4 mapper // {"", 28, Mapper28_Init}, // {"", 29, Mapper29_Init}, // {"", 30, Mapper30_Init}, // {"", 31, Mapper31_Init}, -// {"", 32, Mapper32_Init}, -// {"", 33, Mapper33_Init}, + {"IREM G-101", 32, Mapper32_Init}, + {"TC0190FMC/TC0350FMR", 33, Mapper33_Init}, {"", 34, Mapper34_Init}, {"Wario Land 2", 35, UNLSC127_Init}, // Wario Land 2 {"TXC Policeman", 36, Mapper36_Init}, // TXC Policeman @@ -571,7 +571,7 @@ static BMAPPINGLocal bmap[] = { {"", 45, Mapper45_Init}, // {"", 46, Mapper46_Init}, {"", 47, Mapper47_Init}, -// {"", 48, Mapper48_Init}, + {"TAITO TCxxx", 48, Mapper48_Init}, {"", 49, Mapper49_Init}, // {"", 50, Mapper50_Init}, // {"", 51, Mapper51_Init}, @@ -749,15 +749,15 @@ static BMAPPINGLocal bmap[] = { // {"", 223, Mapper223_Init}, // {"", 224, Mapper224_Init}, {"", 225, Mapper225_Init}, - {"", 226, Mapper226_Init}, + {"BMC 22+20-in-1", 226, Mapper226_Init}, {"", 227, Mapper227_Init}, -// {"", 228, Mapper228_Init}, + {"", 228, Mapper228_Init}, {"", 229, Mapper229_Init}, -// {"", 230, Mapper230_Init}, + {"BMC 22-in-1+Contra", 230, Mapper230_Init}, {"", 231, Mapper231_Init}, -// {"", 232, Mapper232_Init}, - {"", 233, BMC42in1r_Init}, -// {"", 234, Mapper234_Init}, + {"BMC QUATTRO", 232, Mapper232_Init}, + {"BMC 22+20-in-1 RST", 233, Mapper233_Init}, + {"BMC MAXI", 234, Mapper234_Init}, {"", 235, Mapper235_Init}, // {"", 236, Mapper236_Init}, // {"", 237, Mapper237_Init}, @@ -767,9 +767,9 @@ static BMAPPINGLocal bmap[] = { {"", 241, Mapper241_Init}, {"", 242, Mapper242_Init}, {"S74LS374NA", 243, S74LS374NA_Init}, -// {"", 244, Mapper244_Init}, + {"DECATHLON", 244, Mapper244_Init}, {"", 245, Mapper245_Init}, -// {"", 246, Mapper246_Init}, + {"FONG SHEN BANG", 246, Mapper246_Init}, // {"", 247, Mapper247_Init}, // {"", 248, Mapper248_Init}, {"", 249, Mapper249_Init}, @@ -778,8 +778,8 @@ static BMAPPINGLocal bmap[] = { // {"", 252, Mapper252_Init}, {"", 253, Mapper253_Init}, {"", 254, Mapper254_Init}, -// {"", 255, Mapper255_Init}, - {"", 0, NULL} +// {"", 255, Mapper255_Init}, // doesn't have any good dump for this mapper + {"", 0, NULL} }; @@ -1197,13 +1197,13 @@ void (*MapInitTab[256])(void)= Mapper24_init, 0, //Mapper25_init, Mapper26_init, - Mapper27_init, + 0, //Mapper27_init, 0, 0, 0, 0, - Mapper32_init, - Mapper33_init, + 0, //Mapper32_init, + 0, //Mapper33_init, 0, //Mapper34_init, 0, 0, @@ -1218,7 +1218,7 @@ void (*MapInitTab[256])(void)= 0, Mapper46_init, 0, - Mapper48_init, + 0, //Mapper48_init, 0, Mapper50_init, Mapper51_init, @@ -1398,13 +1398,13 @@ void (*MapInitTab[256])(void)= 0, //Mapper225_init, 0, //Mapper226_init, 0, //Mapper227_init, - Mapper228_init, + 0, //Mapper228_init, 0, //Mapper229_init, - Mapper230_init, + 0, //Mapper230_init, 0, //Mapper231_init, - Mapper232_init, + 0, //Mapper232_init, 0, - Mapper234_init, + 0, //Mapper234_init, 0, //Mapper235_init, 0, 0, @@ -1414,9 +1414,9 @@ void (*MapInitTab[256])(void)= 0, //Mapper241_init, 0, //Mapper242_init, 0, - Mapper244_init, + 0, //Mapper244_init, 0, - Mapper246_init, + 0, //Mapper246_init, 0, 0, 0, @@ -1425,7 +1425,7 @@ void (*MapInitTab[256])(void)= 0, 0, 0, - Mapper255_init + 0, //Mapper255_init }; static DECLFW(BWRAM) diff --git a/src/ines.h b/src/ines.h index 29e22cb8..b60e52df 100644 --- a/src/ines.h +++ b/src/ines.h @@ -172,13 +172,13 @@ void Mapper20_init(void); void Mapper24_init(void); //void Mapper25_init(void); void Mapper26_init(void); -void Mapper27_init(void); +//void Mapper27_init(void); void Mapper28_init(void); void Mapper29_init(void); void Mapper30_init(void); void Mapper31_init(void); -void Mapper32_init(void); -void Mapper33_init(void); +//void Mapper32_init(void); +//void Mapper33_init(void); //void Mapper34_init(void); void Mapper35_init(void); void Mapper36_init(void); @@ -193,7 +193,7 @@ void Mapper44_init(void); void Mapper45_init(void); void Mapper46_init(void); void Mapper47_init(void); -void Mapper48_init(void); +//void Mapper48_init(void); void Mapper49_init(void); void Mapper50_init(void); void Mapper51_init(void); @@ -335,13 +335,13 @@ void Mapper224_init(void); //void Mapper225_init(void); //void Mapper226_init(void); //void Mapper227_init(void); -void Mapper228_init(void); +//void Mapper228_init(void); //void Mapper229_init(void); -void Mapper230_init(void); +//void Mapper230_init(void); //void Mapper231_init(void); -void Mapper232_init(void); +//void Mapper232_init(void); //void Mapper233_init(void); -void Mapper234_init(void); +//void Mapper234_init(void); //void Mapper235_init(void); void Mapper236_init(void); void Mapper237_init(void); @@ -350,15 +350,15 @@ void Mapper239_init(void); void Mapper240_init(void); //void Mapper241_init(void); //void Mapper242_init(void); -void Mapper244_init(void); +//void Mapper244_init(void); void Mapper245_init(void); -void Mapper246_init(void); +//void Mapper246_init(void); void Mapper247_init(void); void Mapper249_init(void); void Mapper251_init(void); void Mapper252_init(void); //void Mapper253_init(void); -void Mapper255_init(void); +//void Mapper255_init(void); void NSFVRC6_Init(void); void NSFMMC5_Init(void); @@ -382,6 +382,8 @@ void Mapper21_Init(CartInfo *); void Mapper22_Init(CartInfo *); void Mapper23_Init(CartInfo *); void Mapper25_Init(CartInfo *); +void Mapper32_Init(CartInfo *); +void Mapper33_Init(CartInfo *); void Mapper34_Init(CartInfo *); void Mapper36_Init(CartInfo *); void Mapper37_Init(CartInfo *); @@ -390,6 +392,7 @@ void Mapper43_Init(CartInfo *); void Mapper44_Init(CartInfo *); void Mapper45_Init(CartInfo *); void Mapper47_Init(CartInfo *); +void Mapper48_Init(CartInfo *); void Mapper49_Init(CartInfo *); void Mapper52_Init(CartInfo *); void Mapper57_Init(CartInfo *); @@ -486,15 +489,22 @@ void Mapper222_Init(CartInfo *); void Mapper225_Init(CartInfo *); void Mapper226_Init(CartInfo *); void Mapper227_Init(CartInfo *); +void Mapper228_Init(CartInfo *); void Mapper229_Init(CartInfo *); +void Mapper230_Init(CartInfo *); void Mapper231_Init(CartInfo *); +void Mapper232_Init(CartInfo *); +void Mapper233_Init(CartInfo *); +void Mapper234_Init(CartInfo *); void Mapper235_Init(CartInfo *); void Mapper236_Init(CartInfo *); void Mapper237_Init(CartInfo *); void Mapper240_Init(CartInfo *); void Mapper241_Init(CartInfo *); void Mapper242_Init(CartInfo *); +void Mapper244_Init(CartInfo *); void Mapper245_Init(CartInfo *); +void Mapper246_Init(CartInfo *); void Mapper249_Init(CartInfo *); void Mapper250_Init(CartInfo *); void Mapper253_Init(CartInfo *); diff --git a/src/mappers/228.cpp b/src/mappers/228.cpp deleted file mode 100644 index 681fc1fa..00000000 --- a/src/mappers/228.cpp +++ /dev/null @@ -1,76 +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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - -//16 bits of ram in total -//only use bottom 4 bits as ram though -static uint8 mapper228_ram[4]; - -static SFORMAT StateRegs[]= -{ - { mapper228_ram, 4, "MRAM" }, - { 0 } -}; - -static DECLFR(Mapper228_read) -{ - return mapper228_ram[A & 3] & 0xF; -} - -static DECLFW(Mapper228_write) -{ - uint32 page, pagel, pageh; - - //write to ram - if (A < 0x6000) - { - mapper228_ram[A & 3] = V; - return; - } - MIRROR_SET((A >> 13) & 1); - page = (A >> 7) & 0x3F; - - if( (page & 0x30) == 0x30) - page -= 0x10; - - pagel = pageh = (page << 1) + (((A >> 6) & 1) & ((A >> 5) & 1)); - pageh += ((A >> 5) & 1) ^ 1; - - ROM_BANK16(0x8000,pagel); - ROM_BANK16(0xC000,pageh); - VROM_BANK8( (V&0x3) | ((A&0xF)<<2) ); -} - -static void A52Reset(void) -{ - Mapper228_write(0x8000, 0); -} - -void Mapper228_init(void) -{ - MapperReset=A52Reset; - A52Reset(); - SetWriteHandler(0x8000, 0xFFFF, Mapper228_write); - SetWriteHandler(0x4020, 0x5FFF, Mapper228_write); - SetReadHandler (0x4020, 0x5FFF, Mapper228_read); - AddExState(StateRegs, ~0, 0, 0); -} - diff --git a/src/mappers/230.cpp b/src/mappers/230.cpp deleted file mode 100644 index 32550e5e..00000000 --- a/src/mappers/230.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2003 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - -#define rom_sw mapbyte1[0] - -void Mapper230_Reset(void) -{ - rom_sw ^= 1; //1 - rom_sw; - - if( rom_sw ) { - ROM_BANK16(0x8000,0); - ROM_BANK16(0xc000,7); - } else { - ROM_BANK16(0x8000,8); - ROM_BANK16(0xc000,39); - } - MIRROR_SET2(1); -} - -static DECLFW(Mapper230_write) -{ - if( rom_sw ) { - ROM_BANK16( 0x8000, V&0x07 ); - } else { - if( V & 0x20 ) { - ROM_BANK16( 0x8000, (V&0x1F)+8 ); - ROM_BANK16( 0xc000, (V&0x1F)+8 ); - } else { - ROM_BANK32( ((V&0x1E) >> 1) + 4 ); - } - MIRROR_SET2( ((V & 0x40) >> 6) ); - } -} - -void Mapper230_init(void) -{ - ROM_BANK16(0x8000,0); - ROM_BANK16(0xc000,7); - SetWriteHandler(0x8000, 0xffff, Mapper230_write); - MapperReset = Mapper230_Reset; - rom_sw = 1; -} - diff --git a/src/mappers/232.cpp b/src/mappers/232.cpp deleted file mode 100644 index 6beafb25..00000000 --- a/src/mappers/232.cpp +++ /dev/null @@ -1,50 +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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - -static void DoIt(void) -{ - ROM_BANK16(0x8000,(mapbyte1[1]&3) | ((mapbyte1[0]&0x18)>>1)); - ROM_BANK16(0xc000,3|(((mapbyte1[0])&0x18)>>1)); -} - -DECLFW(Mapper232_write) -{ - if(A<=0x9FFF) - mapbyte1[0]=V; - else - mapbyte1[1]=V; - DoIt(); -} - -static void QuattroReset(void) -{ - mapbyte1[0]=0x18; - DoIt(); -} - -void Mapper232_init(void) -{ - SetWriteHandler(0x6000,0xffff,Mapper232_write); - MapperReset=QuattroReset; - QuattroReset(); -} - diff --git a/src/mappers/234.cpp b/src/mappers/234.cpp deleted file mode 100644 index 1835d577..00000000 --- a/src/mappers/234.cpp +++ /dev/null @@ -1,107 +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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - -#define r1 mapbyte1[0] -#define r2 mapbyte1[1] - -static void DoBS(void) -{ - if(r1&0x40) - { - ROM_BANK32((r1&0xE)|(r2&1)); - VROM_BANK8( ((r1&0xE)<<2) | ((r2>>4)&7) ); - } - else - { - ROM_BANK32(r1&0xF); - VROM_BANK8( ((r1&0xF)<<2) | ((r2>>4)&3) ); - } -} - -static void R1Set(uint8 V) -{ - if(r1) return; - r1=V; - MIRROR_SET(V>>7); - DoBS(); -} - -static void R2Set(uint8 V) -{ - r2=V; - DoBS(); -} - -DECLFW(R1W) -{ - R1Set(V); -} - -DECLFR(R1R) -{ - uint8 r=CartBR(A); - R1Set(r); - return r; -} - -DECLFW(R2W) -{ - R2Set(V); -} - -DECLFR(R2R) -{ - uint8 r=CartBR(A); - R2Set(r); - return r; -} - -static void M15Restore(int version) -{ - DoBS(); - MIRROR_SET(r1>>7); -} - -static void M15Reset(void) -{ - r1=r2=0; - DoBS(); - MIRROR_SET(0); -} - -void Mapper234_init(void) -{ - SetWriteHandler(0xff80,0xff9f,R1W); - SetReadHandler(0xff80,0xff9f,R1R); - - SetWriteHandler(0xffe8,0xfff7,R2W); - SetReadHandler(0xffe8,0xfff7,R2R); - - SetReadHandler(0x6000,0x7FFF,0); - SetWriteHandler(0x6000,0x7FFF,0); - - M15Reset(); - - GameStateRestore=M15Restore; - MapperReset=M15Reset; -} - diff --git a/src/mappers/244.cpp b/src/mappers/244.cpp deleted file mode 100644 index f9076df8..00000000 --- a/src/mappers/244.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - -static uint8 prg_perm[4][4] = { - {0, 1, 2, 3,}, - {3, 2, 1, 0,}, - {0, 2, 1, 3,}, - {3, 1, 2, 0,}, -}; - -static uint8 chr_perm[8][8] = { - {0, 1, 2, 3, 4, 5, 6, 7,}, - {0, 2, 1, 3, 4, 6, 5, 7,}, - {0, 1, 4, 5, 2, 3, 6, 7,}, - {0, 4, 1, 5, 2, 6, 3, 7,}, - {0, 4, 2, 6, 1, 5, 3, 7,}, - {0, 2, 4, 6, 1, 3, 5, 7,}, - {7, 6, 5, 4, 3, 2, 1, 0,}, - {7, 6, 5, 4, 3, 2, 1, 0,}, -}; - -static DECLFW(Mapper244_write) -{ - if(V&8) - VROM_BANK8(chr_perm[(V>>4)&7][V&7]); - else - ROM_BANK32(prg_perm[(V>>4)&3][V&3]); -} - -void Mapper244_init(void) -{ - ROM_BANK32(0); - SetWriteHandler(0x8000,0xffff,Mapper244_write); -} diff --git a/src/mappers/246.cpp b/src/mappers/246.cpp deleted file mode 100644 index 4ae017ea..00000000 --- a/src/mappers/246.cpp +++ /dev/null @@ -1,44 +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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - - -DECLFW(Mapper246_write) -{ - switch(A&0xF007) - { - case 0x6000:ROM_BANK8(0x8000,V);break; - case 0x6001:ROM_BANK8(0xA000,V);break; - case 0x6002:ROM_BANK8(0xC000,V);break; - case 0x6003:ROM_BANK8(0xE000,V);break; - case 0x6004:VROM_BANK2(0x0000,V);break; - case 0x6005:VROM_BANK2(0x0800,V);break; - case 0x6006:VROM_BANK2(0x1000,V);break; - case 0x6007:VROM_BANK2(0x1800,V);break; - } -} - -void Mapper246_init(void) -{ - SetWriteHandler(0x4020,0x67ff,Mapper246_write); - SetWriteHandler(0x8000,0xffff,Mapper246_write); -} - diff --git a/src/mappers/255.cpp b/src/mappers/255.cpp deleted file mode 100644 index 405340ed..00000000 --- a/src/mappers/255.cpp +++ /dev/null @@ -1,67 +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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - - - -static DECLFW(Mapper255_write) -{ - uint32 pbank=(A>>7)&0x1F; - uint32 cbank=A&0x3F; - uint32 rbank=(A>>14)&1; - -// printf("$%04x:$%02x\n",A,V); -// printf("%2x:%2x:%2x,%2x\n",pbank,cbank,rbank,(A&0x40)>>6); - - if(A&0x1000) - { - ROM_BANK16(0x8000,((pbank|(rbank<<5))<<1)|((A&0x40)>>6)); - ROM_BANK16(0xc000,((pbank|(rbank<<5))<<1)|((A&0x40)>>6)); - } - else - { - ROM_BANK32(pbank|(rbank<<5)); - } - MIRROR_SET((A>>13)&1); - VROM_BANK8((rbank<<6)|cbank); -} - -static DECLFW(Mapper255_wl) -{ -// printf("Wr: $%04x:$%02x\n",A,V); - mapbyte1[A&3]=V&0xF; -} - -static DECLFR(Mapper255_read) -{ - //printf("Rd: $%04x\n",A); - return(mapbyte1[A&3]); //|(X.DB&0xF0)); -} - -void Mapper255_init(void) -{ - mapbyte1[0]=mapbyte1[1]=0xF; - ROM_BANK32(0); - VROM_BANK8(0); - SetWriteHandler(0x5800,0x5FF0,Mapper255_wl); - SetWriteHandler(0x8000,0xffff,Mapper255_write); - SetReadHandler(0x5800,0x5FFF,Mapper255_read); -} diff --git a/src/mappers/27.cpp b/src/mappers/27.cpp deleted file mode 100644 index e1afc229..00000000 --- a/src/mappers/27.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "mapinc.h" - -static uint32 regchr[9]; - -static DECLFW(Mapper27_write) -{ - int regnum; - A&=0xF00F; - if((A>=0xB000) && (A<=0xE003)) { - regnum=((((A>>12)+1)&0x03)<<1)|((A&0x02)>>1); - if(A&1) - regchr[regnum]=(regchr[regnum]&0x00F)|(V<<4); - else - regchr[regnum]=(regchr[regnum]&0x1F0)|(V&0xF); - VROM_BANK1(regnum<<10,regchr[regnum]); - } - switch(A) - { - case 0x8000: ROM_BANK8(0x8000|((regchr[8]&2)<<13),V); break; - case 0xA000: ROM_BANK8(0xa000,V); break; - case 0x9000: 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; - } - case 0x9002: regchr[8]=V; break; - case 0xF000: //X6502_IRQEnd(FCEU_IQEXT); - IRQLatch=(IRQLatch&0xF0)|(V&0x0F); - break; - case 0xF001: //X6502_IRQEnd(FCEU_IQEXT); - IRQLatch=(IRQLatch&0x0F)|((V&0xF)<<4); - break; - case 0xF003: IRQa=((IRQa&0x1)<<1)|(IRQa&0x1); - X6502_IRQEnd(FCEU_IQEXT); - break; - case 0xF002: IRQa=V&3; - if(IRQa&0x02) IRQCount=IRQLatch-1; -// X6502_IRQEnd(FCEU_IQEXT); - break; - } -// if((A&0xF000)==0xF000) FCEU_printf("$%04x:$%02x, %d\n",A,V, scanline); -} - -static void Mapper27_hb(void) -{ -// FCEU_printf("%02x-%d,%d,%d\n",scanline,IRQa,IRQCount,IRQLatch); - if(IRQa&0x2){ - if(IRQCount==0xFF){ - X6502_IRQBegin(FCEU_IQEXT); - IRQCount=IRQLatch+1; - } else { - IRQCount++; - } - } -} - -void Mapper27_init(void) -{ - int i; - for (i=0; i<9; i++) { - regchr[i]=0; - } - IRQa=0; - IRQCount=IRQLatch=0; - SetWriteHandler(0x8000,0xffff,Mapper27_write); - GameHBIRQHook=Mapper27_hb; -} - diff --git a/src/mappers/32.cpp b/src/mappers/32.cpp deleted file mode 100644 index b5389474..00000000 --- a/src/mappers/32.cpp +++ /dev/null @@ -1,53 +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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - - -#define IREMCon mapbyte1[0] - -static DECLFW(Mapper32_write) -{ - switch(A>>12) - { - case 0x8: - mapbyte1[1]=V; - if(IREMCon) {ROM_BANK8(0xc000,V);ROM_BANK8(0x8000,~1);} - else {ROM_BANK8(0x8000,V);ROM_BANK8(0xc000,~1);} - break; - case 0x9:IREMCon=(V>>1)&1; - if(IREMCon) {ROM_BANK8(0xc000,mapbyte1[1]);ROM_BANK8(0x8000,~1);} - else {ROM_BANK8(0x8000,mapbyte1[1]); ROM_BANK8(0xc000,~1);} - MIRROR_SET(V&1); - break; - case 0xa:ROM_BANK8(0xA000,V); - break; - } - - if((A&0xF000)==0xb000) - VROM_BANK1((A&0x7)<<10,V); -} - -void Mapper32_init(void) -{ - ROM_BANK16(0x8000,0); - ROM_BANK16(0xc000,~0); - SetWriteHandler(0x8000,0xffff,Mapper32_write); -} diff --git a/src/mappers/33.cpp b/src/mappers/33.cpp deleted file mode 100644 index 2040c47a..00000000 --- a/src/mappers/33.cpp +++ /dev/null @@ -1,80 +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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - -static int is48; - -static DECLFW(Mapper33_write) -{ - //printf("%04x:%02x, %d\n",A,V,scanline); - - A&=0xF003; - if(A>=0xA000 && A<=0xA003) - VROM_BANK1(0x1000+((A&3)<<10),V); - else switch(A) - { - case 0x8000:if(!is48) MIRROR_SET((V>>6)&1); - ROM_BANK8(0x8000,V); - break; - case 0x8001:ROM_BANK8(0xA000,V); break; - case 0x8002:VROM_BANK2(0x0000,V);break; - case 0x8003:VROM_BANK2(0x0800,V);break; - } -} - -static DECLFW(Mapper48_HiWrite) -{ - switch(A&0xF003) - { - case 0xc000:IRQLatch=V;break; - case 0xc001:IRQCount=IRQLatch;break; - case 0xc003:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break; - case 0xc002:IRQa=1;break; - case 0xe000:MIRROR_SET((V>>6)&1);break; - } -} - -static void heho(void) -{ - if(IRQa) - { - IRQCount++; - if(IRQCount==0x100) - { - X6502_IRQBegin(FCEU_IQEXT); - IRQa=0; - } - } -} - -void Mapper33_init(void) -{ - SetWriteHandler(0x8000,0xffff,Mapper33_write); - is48=0; -} - -void Mapper48_init(void) -{ - SetWriteHandler(0x8000,0xbfff,Mapper33_write); - SetWriteHandler(0xc000,0xffff,Mapper48_HiWrite); - GameHBIRQHook=heho; - is48=1; -} diff --git a/src/mappers/SConscript b/src/mappers/SConscript index f0249aee..4368ecbd 100644 --- a/src/mappers/SConscript +++ b/src/mappers/SConscript @@ -1,15 +1,5 @@ my_list = Split(""" -228.cpp -230.cpp -232.cpp -234.cpp -244.cpp -246.cpp 24and26.cpp -255.cpp -27.cpp -32.cpp -33.cpp 40.cpp 41.cpp 42.cpp @@ -35,12 +25,9 @@ emu2413.c mmc2and4.cpp """) # -# vrc7tone.h -# # emu2413.h # mapinc.h # -# emutypes.h for x in range(len(my_list)): my_list[x] = 'mappers/' + my_list[x] Return('my_list') diff --git a/src/mappers/emu2413.c b/src/mappers/emu2413.c index 49aa3396..e4f4e47a 100644 --- a/src/mappers/emu2413.c +++ b/src/mappers/emu2413.c @@ -53,44 +53,59 @@ #include "emu2413.h" static const unsigned char default_inst[15][8] = { - #include "vrc7tone.h" + /* VRC7 instruments, January 17, 2004 update -Xodnizel */ + { 0x03, 0x21, 0x04, 0x06, 0x8D, 0xF2, 0x42, 0x17 }, + { 0x13, 0x41, 0x05, 0x0E, 0x99, 0x96, 0x63, 0x12 }, + { 0x31, 0x11, 0x10, 0x0A, 0xF0, 0x9C, 0x32, 0x02 }, + { 0x21, 0x61, 0x1D, 0x07, 0x9F, 0x64, 0x20, 0x27 }, + { 0x22, 0x21, 0x1E, 0x06, 0xF0, 0x76, 0x08, 0x28 }, + { 0x02, 0x01, 0x06, 0x00, 0xF0, 0xF2, 0x03, 0x95 }, + { 0x21, 0x61, 0x1C, 0x07, 0x82, 0x81, 0x16, 0x07 }, + { 0x23, 0x21, 0x1A, 0x17, 0xEF, 0x82, 0x25, 0x15 }, + { 0x25, 0x11, 0x1F, 0x00, 0x86, 0x41, 0x20, 0x11 }, + { 0x85, 0x01, 0x1F, 0x0F, 0xE4, 0xA2, 0x11, 0x12 }, + { 0x07, 0xC1, 0x2B, 0x45, 0xB4, 0xF1, 0x24, 0xF4 }, + { 0x61, 0x23, 0x11, 0x06, 0x96, 0x96, 0x13, 0x16 }, + { 0x01, 0x02, 0xD3, 0x05, 0x82, 0xA2, 0x31, 0x51 }, + { 0x61, 0x22, 0x0D, 0x02, 0xC3, 0x7F, 0x24, 0x05 }, + { 0x21, 0x62, 0x0E, 0x00, 0xA1, 0xA0, 0x44, 0x17 }, }; /* Size of Sintable ( 8 -- 18 can be used. 9 recommended.)*/ #define PG_BITS 9 -#define PG_WIDTH (1<>(b)) +#define HIGHBITS(c, b) ((c) >> (b)) /* Leave the lower b bit(s). */ -#define LOWBITS(c,b) ((c)&((1<<(b))-1)) +#define LOWBITS(c, b) ((c) & ((1 << (b)) - 1)) /* Expand x which is s bits to d bits. */ -#define EXPAND_BITS(x,s,d) ((x)<<((d)-(s))) +#define EXPAND_BITS(x, s, d) ((x) << ((d) - (s))) /* Expand x which is s bits to d bits and fill expanded bits '1' */ -#define EXPAND_BITS_X(x,s,d) (((x)<<((d)-(s)))|((1<<((d)-(s)))-1)) +#define EXPAND_BITS_X(x, s, d) (((x) << ((d) - (s))) | ((1 << ((d) - (s))) - 1)) /* Adjust envelope speed which depends on sampling rate. */ -#define rate_adjust(x) (rate==49716?x:(e_uint32)((double)(x)*clk/72/rate + 0.5)) /* added 0.5 to round the value*/ +#define rate_adjust(x) (rate == 49716 ? x : (uint32)((double)(x) * clk / 72 / rate + 0.5)) /* added 0.5 to round the value*/ -#define MOD(o,x) (&(o)->slot[(x)<<1]) -#define CAR(o,x) (&(o)->slot[((x)<<1)|1]) +#define MOD(o, x) (&(o)->slot[(x) << 1]) +#define CAR(o, x) (&(o)->slot[((x) << 1) | 1]) -#define BIT(s,b) (((s)>>(b))&1) +#define BIT(s, b) (((s) >> (b)) & 1) /* Input clock */ -static e_uint32 clk = 844451141; +static uint32 clk = 844451141; /* Sampling rate */ -static e_uint32 rate = 3354932; +static uint32 rate = 3354932; /* WaveTable for each envelope amp */ -static e_uint16 fullsintable[PG_WIDTH]; -static e_uint16 halfsintable[PG_WIDTH]; +static uint16 fullsintable[PG_WIDTH]; +static uint16 halfsintable[PG_WIDTH]; -static e_uint16 *waveform[2] = { fullsintable, halfsintable }; +static uint16 *waveform[2] = { fullsintable, halfsintable }; /* LFO Table */ -static e_int32 pmtable[PM_PG_WIDTH]; -static e_int32 amtable[AM_PG_WIDTH]; +static int32 pmtable[PM_PG_WIDTH]; +static int32 amtable[AM_PG_WIDTH]; /* Phase delta for LFO */ -static e_uint32 pm_dphase; -static e_uint32 am_dphase; +static uint32 pm_dphase; +static uint32 am_dphase; /* dB to Liner table */ -static e_int16 DB2LIN_TABLE[(DB_MUTE + DB_MUTE) * 2]; +static int16 DB2LIN_TABLE[(DB_MUTE + DB_MUTE) * 2]; /* Liner to Log curve conversion table (for Attack rate). */ -static e_uint16 AR_ADJUST_TABLE[1 << EG_BITS]; +static uint16 AR_ADJUST_TABLE[1 << EG_BITS]; /* Definition of envelope mode */ enum { SETTLE, ATTACK, DECAY, SUSHOLD, SUSTINE, RELEASE, FINISH }; /* Phase incr table for Attack */ -static e_uint32 dphaseARTable[16][16]; +static uint32 dphaseARTable[16][16]; /* Phase incr table for Decay and Release */ -static e_uint32 dphaseDRTable[16][16]; +static uint32 dphaseDRTable[16][16]; /* KSL + TL Table */ -static e_uint32 tllTable[16][8][1 << TL_BITS][4]; -static e_int32 rksTable[2][8][2]; +static uint32 tllTable[16][8][1 << TL_BITS][4]; +static int32 rksTable[2][8][2]; /* Phase incr table for PG */ -static e_uint32 dphaseTable[512][8][16]; +static uint32 dphaseTable[512][8][16]; /*************************************************** - Create tables + Create tables ****************************************************/ -INLINE static e_int32 -Min (e_int32 i, e_int32 j) -{ - if(i < j) - return i; - else - return j; +INLINE static int32 Min(int32 i, int32 j) { + if (i < j) + return i; + else + return j; } /* Table for AR to LogCurve. */ -static void -makeAdjustTable (void) -{ - e_int32 i; +static void makeAdjustTable(void) { + int32 i; - AR_ADJUST_TABLE[0] = (1 << EG_BITS); - for (i = 1; i < 128; i++) - AR_ADJUST_TABLE[i] = (e_uint16) ((double) (1 << EG_BITS) - 1 - (1 << EG_BITS) * log (i) / log (128)); + AR_ADJUST_TABLE[0] = (1 << EG_BITS); + for (i = 1; i < 128; i++) + AR_ADJUST_TABLE[i] = (uint16)((double)(1 << EG_BITS) - 1 - (1 << EG_BITS) * log(i) / log(128)); } /* Table for dB(0 -- (1<= DB_MUTE) DB2LIN_TABLE[i] = 0; - DB2LIN_TABLE[i + DB_MUTE + DB_MUTE] = (e_int16) (-DB2LIN_TABLE[i]); - } + for (i = 0; i < DB_MUTE + DB_MUTE; i++) { + DB2LIN_TABLE[i] = (int16)((double)((1 << DB2LIN_AMP_BITS) - 1) * pow(10, -(double)i * DB_STEP / 20)); + if (i >= DB_MUTE) DB2LIN_TABLE[i] = 0; + DB2LIN_TABLE[i + DB_MUTE + DB_MUTE] = (int16)(-DB2LIN_TABLE[i]); + } } /* Liner(+0.0 - +1.0) to dB((1<> (20 - DP_BITS)); + for (fnum = 0; fnum < 512; fnum++) + for (block = 0; block < 8; block++) + for (ML = 0; ML < 16; ML++) + dphaseTable[fnum][block][ML] = rate_adjust(((fnum * mltable[ML]) << block) >> (20 - DP_BITS)); } -static void -makeTllTable (void) -{ -#define dB2(x) ((x)*2) +static void makeTllTable(void) { +#define dB2(x) ((x) * 2) - static double kltable[16] = { - dB2 (0.000), dB2 (9.000), dB2 (12.000), dB2 (13.875), dB2 (15.000), dB2 (16.125), dB2 (16.875), dB2 (17.625), - dB2 (18.000), dB2 (18.750), dB2 (19.125), dB2 (19.500), dB2 (19.875), dB2 (20.250), dB2 (20.625), dB2 (21.000) - }; + static double kltable[16] = { + dB2(0.000), dB2(9.000), dB2(12.000), dB2(13.875), dB2(15.000), dB2(16.125), dB2(16.875), dB2(17.625), + dB2(18.000), dB2(18.750), dB2(19.125), dB2(19.500), dB2(19.875), dB2(20.250), dB2(20.625), dB2(21.000) + }; - e_int32 tmp; - e_int32 fnum, block, TL, KL; + int32 tmp; + int32 fnum, block, TL, KL; - for (fnum = 0; fnum < 16; fnum++) - for (block = 0; block < 8; block++) - for (TL = 0; TL < 64; TL++) - for (KL = 0; KL < 4; KL++) - { - if(KL == 0) - { - tllTable[fnum][block][TL][KL] = TL2EG (TL); - } - else - { - tmp = (e_int32) (kltable[fnum] - dB2 (3.000) * (7 - block)); - if(tmp <= 0) - tllTable[fnum][block][TL][KL] = TL2EG (TL); - else - tllTable[fnum][block][TL][KL] = (e_uint32) ((tmp >> (3 - KL)) / EG_STEP) + TL2EG (TL); - } - } + for (fnum = 0; fnum < 16; fnum++) + for (block = 0; block < 8; block++) + for (TL = 0; TL < 64; TL++) + for (KL = 0; KL < 4; KL++) { + if (KL == 0) { + tllTable[fnum][block][TL][KL] = TL2EG(TL); + } else { + tmp = (int32)(kltable[fnum] - dB2(3.000) * (7 - block)); + if (tmp <= 0) + tllTable[fnum][block][TL][KL] = TL2EG(TL); + else + tllTable[fnum][block][TL][KL] = (uint32)((tmp >> (3 - KL)) / EG_STEP) + TL2EG(TL); + } + } } -#ifdef USE_SPEC_ENV_SPEED -static double attacktime[16][4] = { - {0, 0, 0, 0}, - {1730.15, 1400.60, 1153.43, 988.66}, - {865.08, 700.30, 576.72, 494.33}, - {432.54, 350.15, 288.36, 247.16}, - {216.27, 175.07, 144.18, 123.58}, - {108.13, 87.54, 72.09, 61.79}, - {54.07, 43.77, 36.04, 30.90}, - {27.03, 21.88, 18.02, 15.45}, - {13.52, 10.94, 9.01, 7.72}, - {6.76, 5.47, 4.51, 3.86}, - {3.38, 2.74, 2.25, 1.93}, - {1.69, 1.37, 1.13, 0.97}, - {0.84, 0.70, 0.60, 0.54}, - {0.50, 0.42, 0.34, 0.30}, - {0.28, 0.22, 0.18, 0.14}, - {0.00, 0.00, 0.00, 0.00} -}; - -static double decaytime[16][4] = { - {0, 0, 0, 0}, - {20926.60, 16807.20, 14006.00, 12028.60}, - {10463.30, 8403.58, 7002.98, 6014.32}, - {5231.64, 4201.79, 3501.49, 3007.16}, - {2615.82, 2100.89, 1750.75, 1503.58}, - {1307.91, 1050.45, 875.37, 751.79}, - {653.95, 525.22, 437.69, 375.90}, - {326.98, 262.61, 218.84, 187.95}, - {163.49, 131.31, 109.42, 93.97}, - {81.74, 65.65, 54.71, 46.99}, - {40.87, 32.83, 27.36, 23.49}, - {20.44, 16.41, 13.68, 11.75}, - {10.22, 8.21, 6.84, 5.87}, - {5.11, 4.10, 3.42, 2.94}, - {2.55, 2.05, 1.71, 1.47}, - {1.27, 1.27, 1.27, 1.27} -}; -#endif - /* Rate Table for Attack */ -static void -makeDphaseARTable (void) -{ - e_int32 AR, Rks, RM, RL; -#ifdef USE_SPEC_ENV_SPEED - e_uint32 attacktable[16][4]; - - for (RM = 0; RM < 16; RM++) - for (RL = 0; RL < 4; RL++) - { - if(RM == 0) - attacktable[RM][RL] = 0; - else if(RM == 15) - attacktable[RM][RL] = EG_DP_WIDTH; - else - attacktable[RM][RL] = (e_uint32) ((double) (1 << EG_DP_BITS) / (attacktime[RM][RL] * 3579545 / 72000)); - - } -#endif - - for (AR = 0; AR < 16; AR++) - for (Rks = 0; Rks < 16; Rks++) - { - RM = AR + (Rks >> 2); - RL = Rks & 3; - if(RM > 15) - RM = 15; - switch (AR) - { - case 0: - dphaseARTable[AR][Rks] = 0; - break; - case 15: - dphaseARTable[AR][Rks] = 0;/*EG_DP_WIDTH;*/ - break; - default: -#ifdef USE_SPEC_ENV_SPEED - dphaseARTable[AR][Rks] = rate_adjust (attacktable[RM][RL]); -#else - dphaseARTable[AR][Rks] = rate_adjust ((3 * (RL + 4) << (RM + 1))); -#endif - break; - } - } +static void makeDphaseARTable(void) { + int32 AR, Rks, RM, RL; + for (AR = 0; AR < 16; AR++) + for (Rks = 0; Rks < 16; Rks++) { + RM = AR + (Rks >> 2); + RL = Rks & 3; + if (RM > 15) + RM = 15; + switch (AR) { + case 0: + dphaseARTable[AR][Rks] = 0; + break; + case 15: + dphaseARTable[AR][Rks] = 0; /*EG_DP_WIDTH;*/ + break; + default: + dphaseARTable[AR][Rks] = rate_adjust((3 * (RL + 4) << (RM + 1))); + break; + } + } } /* Rate Table for Decay and Release */ -static void -makeDphaseDRTable (void) -{ - e_int32 DR, Rks, RM, RL; +static void makeDphaseDRTable(void) { + int32 DR, Rks, RM, RL; -#ifdef USE_SPEC_ENV_SPEED - e_uint32 decaytable[16][4]; - - for (RM = 0; RM < 16; RM++) - for (RL = 0; RL < 4; RL++) - if(RM == 0) - decaytable[RM][RL] = 0; - else - decaytable[RM][RL] = (e_uint32) ((double) (1 << EG_DP_BITS) / (decaytime[RM][RL] * 3579545 / 72000)); -#endif - - for (DR = 0; DR < 16; DR++) - for (Rks = 0; Rks < 16; Rks++) - { - RM = DR + (Rks >> 2); - RL = Rks & 3; - if(RM > 15) - RM = 15; - switch (DR) - { - case 0: - dphaseDRTable[DR][Rks] = 0; - break; - default: -#ifdef USE_SPEC_ENV_SPEED - dphaseDRTable[DR][Rks] = rate_adjust (decaytable[RM][RL]); -#else - dphaseDRTable[DR][Rks] = rate_adjust ((RL + 4) << (RM - 1)); -#endif - break; - } - } + for (DR = 0; DR < 16; DR++) + for (Rks = 0; Rks < 16; Rks++) { + RM = DR + (Rks >> 2); + RL = Rks & 3; + if (RM > 15) + RM = 15; + switch (DR) { + case 0: + dphaseDRTable[DR][Rks] = 0; + break; + default: + dphaseDRTable[DR][Rks] = rate_adjust((RL + 4) << (RM - 1)); + break; + } + } } -static void -makeRksTable (void) -{ +static void makeRksTable(void) { + int32 fnum8, block, KR; - e_int32 fnum8, block, KR; - - for (fnum8 = 0; fnum8 < 2; fnum8++) - for (block = 0; block < 8; block++) - for (KR = 0; KR < 2; KR++) - { - if(KR != 0) - rksTable[fnum8][block][KR] = (block << 1) + fnum8; - else - rksTable[fnum8][block][KR] = block >> 1; - } + for (fnum8 = 0; fnum8 < 2; fnum8++) + for (block = 0; block < 8; block++) + for (KR = 0; KR < 2; KR++) { + if (KR != 0) + rksTable[fnum8][block][KR] = (block << 1) + fnum8; + else + rksTable[fnum8][block][KR] = block >> 1; + } } /************************************************************ - Calc Parameters + Calc Parameters ************************************************************/ -INLINE static e_uint32 -calc_eg_dphase (OPLL_SLOT * slot) -{ +INLINE static uint32 calc_eg_dphase(OPLL_SLOT * slot) { + switch (slot->eg_mode) { + case ATTACK: + return dphaseARTable[slot->patch.AR][slot->rks]; - switch (slot->eg_mode) - { - case ATTACK: - return dphaseARTable[slot->patch.AR][slot->rks]; + case DECAY: + return dphaseDRTable[slot->patch.DR][slot->rks]; - case DECAY: - return dphaseDRTable[slot->patch.DR][slot->rks]; + case SUSHOLD: + return 0; - case SUSHOLD: - return 0; + case SUSTINE: + return dphaseDRTable[slot->patch.RR][slot->rks]; - case SUSTINE: - return dphaseDRTable[slot->patch.RR][slot->rks]; + case RELEASE: + if (slot->sustine) + return dphaseDRTable[5][slot->rks]; + else if (slot->patch.EG) + return dphaseDRTable[slot->patch.RR][slot->rks]; + else + return dphaseDRTable[7][slot->rks]; - case RELEASE: - if(slot->sustine) - return dphaseDRTable[5][slot->rks]; - else if(slot->patch.EG) - return dphaseDRTable[slot->patch.RR][slot->rks]; - else - return dphaseDRTable[7][slot->rks]; + case FINISH: + return 0; - case FINISH: - return 0; - - default: - return 0; - } + default: + return 0; + } } /************************************************************* - OPLL internal interfaces + OPLL internal interfaces *************************************************************/ #define UPDATE_PG(S) (S)->dphase = dphaseTable[(S)->fnum][(S)->block][(S)->patch.ML] -#define UPDATE_TLL(S)\ -(((S)->type==0)?\ -((S)->tll = tllTable[((S)->fnum)>>5][(S)->block][(S)->patch.TL][(S)->patch.KL]):\ -((S)->tll = tllTable[((S)->fnum)>>5][(S)->block][(S)->volume][(S)->patch.KL])) -#define UPDATE_RKS(S) (S)->rks = rksTable[((S)->fnum)>>8][(S)->block][(S)->patch.KR] +#define UPDATE_TLL(S) \ + (((S)->type == 0) ? \ + ((S)->tll = tllTable[((S)->fnum) >> 5][(S)->block][(S)->patch.TL][(S)->patch.KL]) : \ + ((S)->tll = tllTable[((S)->fnum) >> 5][(S)->block][(S)->volume][(S)->patch.KL])) +#define UPDATE_RKS(S) (S)->rks = rksTable[((S)->fnum) >> 8][(S)->block][(S)->patch.KR] #define UPDATE_WF(S) (S)->sintbl = waveform[(S)->patch.WF] #define UPDATE_EG(S) (S)->eg_dphase = calc_eg_dphase(S) -#define UPDATE_ALL(S)\ - UPDATE_PG(S);\ - UPDATE_TLL(S);\ - UPDATE_RKS(S);\ - UPDATE_WF(S); \ - UPDATE_EG(S) /* EG should be updated last. */ +#define UPDATE_ALL(S) \ + UPDATE_PG(S); \ + UPDATE_TLL(S); \ + UPDATE_RKS(S); \ + UPDATE_WF(S); \ + UPDATE_EG(S) /* EG should be updated last. */ /* Slot key on */ -INLINE static void -slotOn (OPLL_SLOT * slot) -{ - slot->eg_mode = ATTACK; - slot->eg_phase = 0; - slot->phase = 0; +INLINE static void slotOn(OPLL_SLOT * slot) { + slot->eg_mode = ATTACK; + slot->eg_phase = 0; + slot->phase = 0; } /* Slot key on without reseting the phase */ -INLINE static void -slotOn2 (OPLL_SLOT * slot) -{ - slot->eg_mode = ATTACK; - slot->eg_phase = 0; +INLINE static void slotOn2(OPLL_SLOT * slot) { + slot->eg_mode = ATTACK; + slot->eg_phase = 0; } /* Slot key off */ -INLINE static void -slotOff (OPLL_SLOT * slot) -{ - if(slot->eg_mode == ATTACK) - slot->eg_phase = EXPAND_BITS (AR_ADJUST_TABLE[HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS)], EG_BITS, EG_DP_BITS); - slot->eg_mode = RELEASE; +INLINE static void slotOff(OPLL_SLOT * slot) { + if (slot->eg_mode == ATTACK) + slot->eg_phase = EXPAND_BITS(AR_ADJUST_TABLE[HIGHBITS(slot->eg_phase, EG_DP_BITS - EG_BITS)], EG_BITS, EG_DP_BITS); + slot->eg_mode = RELEASE; } /* Channel key on */ -INLINE static void -keyOn (OPLL * opll, e_int32 i) -{ - if(!opll->slot_on_flag[i * 2]) - slotOn (MOD(opll,i)); - if(!opll->slot_on_flag[i * 2 + 1]) - slotOn (CAR(opll,i)); - opll->key_status[i] = 1; +INLINE static void keyOn(OPLL * opll, int32 i) { + if (!opll->slot_on_flag[i * 2]) + slotOn(MOD(opll, i)); + if (!opll->slot_on_flag[i * 2 + 1]) + slotOn(CAR(opll, i)); + opll->key_status[i] = 1; } /* Channel key off */ -INLINE static void -keyOff (OPLL * opll, e_int32 i) -{ - if(opll->slot_on_flag[i * 2 + 1]) - slotOff (CAR(opll,i)); - opll->key_status[i] = 0; +INLINE static void keyOff(OPLL * opll, int32 i) { + if (opll->slot_on_flag[i * 2 + 1]) + slotOff(CAR(opll, i)); + opll->key_status[i] = 0; } /* Set sustine parameter */ -INLINE static void -setSustine (OPLL * opll, e_int32 c, e_int32 sustine) -{ - CAR(opll,c)->sustine = sustine; - if(MOD(opll,c)->type) - MOD(opll,c)->sustine = sustine; +INLINE static void setSustine(OPLL * opll, int32 c, int32 sustine) { + CAR(opll, c)->sustine = sustine; + if (MOD(opll, c)->type) + MOD(opll, c)->sustine = sustine; } /* Volume : 6bit ( Volume register << 2 ) */ -INLINE static void -setVolume (OPLL * opll, e_int32 c, e_int32 volume) -{ - CAR(opll,c)->volume = volume; +INLINE static void setVolume(OPLL * opll, int32 c, int32 volume) { + CAR(opll, c)->volume = volume; } -INLINE static void -setSlotVolume (OPLL_SLOT * slot, e_int32 volume) -{ - slot->volume = volume; +INLINE static void setSlotVolume(OPLL_SLOT * slot, int32 volume) { + slot->volume = volume; } /* Set F-Number ( fnum : 9bit ) */ -INLINE static void -setFnumber (OPLL * opll, e_int32 c, e_int32 fnum) -{ - CAR(opll,c)->fnum = fnum; - MOD(opll,c)->fnum = fnum; +INLINE static void setFnumber(OPLL * opll, int32 c, int32 fnum) { + CAR(opll, c)->fnum = fnum; + MOD(opll, c)->fnum = fnum; } /* Set Block data (block : 3bit ) */ -INLINE static void -setBlock (OPLL * opll, e_int32 c, e_int32 block) -{ - CAR(opll,c)->block = block; - MOD(opll,c)->block = block; +INLINE static void setBlock(OPLL * opll, int32 c, int32 block) { + CAR(opll, c)->block = block; + MOD(opll, c)->block = block; } -INLINE static void update_key_status (OPLL * opll) -{ - int ch; +INLINE static void update_key_status(OPLL * opll) { int ch; - for (ch = 0; ch < 6; ch++) - opll->slot_on_flag[ch * 2] = opll->slot_on_flag[ch * 2 + 1] = (opll->HiFreq[ch]) & 0x10; + for (ch = 0; ch < 6; ch++) + opll->slot_on_flag[ch * 2] = opll->slot_on_flag[ch * 2 + 1] = (opll->HiFreq[ch]) & 0x10; } /*********************************************************** - Initializing + Initializing ***********************************************************/ -static void -OPLL_SLOT_reset (OPLL_SLOT * slot, int type) -{ - slot->type = type; - slot->sintbl = waveform[0]; - slot->phase = 0; - slot->dphase = 0; - slot->output[0] = 0; - slot->output[1] = 0; - slot->feedback = 0; - slot->eg_mode = SETTLE; - slot->eg_phase = EG_DP_WIDTH; - slot->eg_dphase = 0; - slot->rks = 0; - slot->tll = 0; - slot->sustine = 0; - slot->fnum = 0; - slot->block = 0; - slot->volume = 0; - slot->pgout = 0; - slot->egout = 0; +static void OPLL_SLOT_reset(OPLL_SLOT * slot, int type) { + slot->type = type; + slot->sintbl = waveform[0]; + slot->phase = 0; + slot->dphase = 0; + slot->output[0] = 0; + slot->output[1] = 0; + slot->feedback = 0; + slot->eg_mode = SETTLE; + slot->eg_phase = EG_DP_WIDTH; + slot->eg_dphase = 0; + slot->rks = 0; + slot->tll = 0; + slot->sustine = 0; + slot->fnum = 0; + slot->block = 0; + slot->volume = 0; + slot->pgout = 0; + slot->egout = 0; } -static void -internal_refresh (void) -{ - makeDphaseTable (); - makeDphaseARTable (); - makeDphaseDRTable (); - pm_dphase = (e_uint32) rate_adjust (PM_SPEED * PM_DP_WIDTH / (clk / 72)); - am_dphase = (e_uint32) rate_adjust (AM_SPEED * AM_DP_WIDTH / (clk / 72)); +static void internal_refresh(void) { + makeDphaseTable(); + makeDphaseARTable(); + makeDphaseDRTable(); + pm_dphase = (uint32)rate_adjust(PM_SPEED * PM_DP_WIDTH / (clk / 72)); + am_dphase = (uint32)rate_adjust(AM_SPEED * AM_DP_WIDTH / (clk / 72)); } -static void -maketables (e_uint32 c, e_uint32 r) -{ - if(c != clk) - { - clk = c; - makePmTable (); - makeAmTable (); - makeDB2LinTable (); - makeAdjustTable (); - makeTllTable (); - makeRksTable (); - makeSinTable (); - //makeDefaultPatch (); - } +static void maketables(uint32 c, uint32 r) { + if (c != clk) { + clk = c; + makePmTable(); + makeAmTable(); + makeDB2LinTable(); + makeAdjustTable(); + makeTllTable(); + makeRksTable(); + makeSinTable(); + //makeDefaultPatch (); + } - if(r != rate) - { - rate = r; - internal_refresh (); - } + if (r != rate) { + rate = r; + internal_refresh(); + } } -OPLL *OPLL_new (e_uint32 clk, e_uint32 rate) -{ - OPLL *opll; +OPLL *OPLL_new(uint32 clk, uint32 rate) { + OPLL *opll; - maketables (clk, rate); + maketables(clk, rate); - opll = (OPLL *) calloc (sizeof (OPLL), 1); - if(opll == NULL) - return NULL; + opll = (OPLL*)calloc(sizeof(OPLL), 1); + if (opll == NULL) + return NULL; - opll->mask = 0; + opll->mask = 0; - OPLL_reset (opll); + OPLL_reset(opll); - return opll; + return opll; } -void -OPLL_delete (OPLL * opll) -{ - free (opll); +void OPLL_delete(OPLL * opll) { + free(opll); } /* Reset whole of OPLL except patch datas. */ -void -OPLL_reset (OPLL * opll) -{ - e_int32 i; +void OPLL_reset(OPLL * opll) { + int32 i; - if(!opll) - return; + if (!opll) + return; - opll->adr = 0; - opll->out = 0; + opll->adr = 0; + opll->out = 0; - opll->pm_phase = 0; - opll->am_phase = 0; + opll->pm_phase = 0; + opll->am_phase = 0; - opll->mask = 0; + opll->mask = 0; - for (i = 0; i < 12; i++) - OPLL_SLOT_reset(&opll->slot[i], i%2); + for (i = 0; i < 12; i++) + OPLL_SLOT_reset(&opll->slot[i], i % 2); - for (i = 0; i < 6; i++) - { - opll->key_status[i] = 0; - //setPatch (opll, i, 0); - } + for (i = 0; i < 6; i++) { + opll->key_status[i] = 0; + //setPatch (opll, i, 0); + } - for (i = 0; i < 0x40; i++) - OPLL_writeReg (opll, i, 0); + for (i = 0; i < 0x40; i++) + OPLL_writeReg(opll, i, 0); -#ifndef EMU2413_COMPACTION - opll->realstep = (e_uint32) ((1 << 31) / rate); - opll->opllstep = (e_uint32) ((1 << 31) / (clk / 72)); - opll->oplltime = 0; -#endif + opll->realstep = (uint32)((1 << 31) / rate); + opll->opllstep = (uint32)((1 << 31) / (clk / 72)); + opll->oplltime = 0; } /* Force Refresh (When external program changes some parameters). */ -void -OPLL_forceRefresh (OPLL * opll) -{ - e_int32 i; +void OPLL_forceRefresh(OPLL * opll) { + int32 i; - if(opll == NULL) - return; + if (opll == NULL) + return; - for (i = 0; i < 12; i++) - { - UPDATE_PG (&opll->slot[i]); - UPDATE_RKS (&opll->slot[i]); - UPDATE_TLL (&opll->slot[i]); - UPDATE_WF (&opll->slot[i]); - UPDATE_EG (&opll->slot[i]); - } + for (i = 0; i < 12; i++) { + UPDATE_PG(&opll->slot[i]); + UPDATE_RKS(&opll->slot[i]); + UPDATE_TLL(&opll->slot[i]); + UPDATE_WF(&opll->slot[i]); + UPDATE_EG(&opll->slot[i]); + } } -void -OPLL_set_rate (OPLL * opll, e_uint32 r) -{ - if(opll->quality) - rate = 49716; - else - rate = r; - internal_refresh (); - rate = r; +void OPLL_set_rate(OPLL * opll, uint32 r) { + if (opll->quality) + rate = 49716; + else + rate = r; + internal_refresh(); + rate = r; } -void -OPLL_set_quality (OPLL * opll, e_uint32 q) -{ - opll->quality = q; - OPLL_set_rate (opll, rate); +void OPLL_set_quality(OPLL * opll, uint32 q) { + opll->quality = q; + OPLL_set_rate(opll, rate); } /********************************************************* - Generate wave data + Generate wave data *********************************************************/ /* Convert Amp(0 to EG_HEIGHT) to Phase(0 to 2PI). */ -#if( SLOT_AMP_BITS - PG_BITS ) > 0 -#define wave2_2pi(e) ( (e) >> ( SLOT_AMP_BITS - PG_BITS )) +#if (SLOT_AMP_BITS - PG_BITS) > 0 +#define wave2_2pi(e) ((e) >> (SLOT_AMP_BITS - PG_BITS)) #else -#define wave2_2pi(e) ( (e) << ( PG_BITS - SLOT_AMP_BITS )) +#define wave2_2pi(e) ((e) << (PG_BITS - SLOT_AMP_BITS)) #endif /* Convert Amp(0 to EG_HEIGHT) to Phase(0 to 4PI). */ -#if( SLOT_AMP_BITS - PG_BITS - 1 ) == 0 +#if (SLOT_AMP_BITS - PG_BITS - 1) == 0 #define wave2_4pi(e) (e) -#elif( SLOT_AMP_BITS - PG_BITS - 1 ) > 0 -#define wave2_4pi(e) ( (e) >> ( SLOT_AMP_BITS - PG_BITS - 1 )) +#elif (SLOT_AMP_BITS - PG_BITS - 1) > 0 +#define wave2_4pi(e) ((e) >> (SLOT_AMP_BITS - PG_BITS - 1)) #else -#define wave2_4pi(e) ( (e) << ( 1 + PG_BITS - SLOT_AMP_BITS )) +#define wave2_4pi(e) ((e) << (1 + PG_BITS - SLOT_AMP_BITS)) #endif /* Convert Amp(0 to EG_HEIGHT) to Phase(0 to 8PI). */ -#if( SLOT_AMP_BITS - PG_BITS - 2 ) == 0 +#if (SLOT_AMP_BITS - PG_BITS - 2) == 0 #define wave2_8pi(e) (e) -#elif( SLOT_AMP_BITS - PG_BITS - 2 ) > 0 -#define wave2_8pi(e) ( (e) >> ( SLOT_AMP_BITS - PG_BITS - 2 )) +#elif (SLOT_AMP_BITS - PG_BITS - 2) > 0 +#define wave2_8pi(e) ((e) >> (SLOT_AMP_BITS - PG_BITS - 2)) #else -#define wave2_8pi(e) ( (e) << ( 2 + PG_BITS - SLOT_AMP_BITS )) +#define wave2_8pi(e) ((e) << (2 + PG_BITS - SLOT_AMP_BITS)) #endif /* Update AM, PM unit */ -static void -update_ampm (OPLL * opll) -{ - opll->pm_phase = (opll->pm_phase + pm_dphase) & (PM_DP_WIDTH - 1); - opll->am_phase = (opll->am_phase + am_dphase) & (AM_DP_WIDTH - 1); - opll->lfo_am = amtable[HIGHBITS (opll->am_phase, AM_DP_BITS - AM_PG_BITS)]; - opll->lfo_pm = pmtable[HIGHBITS (opll->pm_phase, PM_DP_BITS - PM_PG_BITS)]; +static void update_ampm(OPLL * opll) { + opll->pm_phase = (opll->pm_phase + pm_dphase) & (PM_DP_WIDTH - 1); + opll->am_phase = (opll->am_phase + am_dphase) & (AM_DP_WIDTH - 1); + opll->lfo_am = amtable[HIGHBITS(opll->am_phase, AM_DP_BITS - AM_PG_BITS)]; + opll->lfo_pm = pmtable[HIGHBITS(opll->pm_phase, PM_DP_BITS - PM_PG_BITS)]; } /* PG */ -INLINE static void -calc_phase (OPLL_SLOT * slot, e_int32 lfo) -{ - if(slot->patch.PM) - slot->phase += (slot->dphase * lfo) >> PM_AMP_BITS; - else - slot->phase += slot->dphase; +INLINE static void calc_phase(OPLL_SLOT * slot, int32 lfo) { + if (slot->patch.PM) + slot->phase += (slot->dphase * lfo) >> PM_AMP_BITS; + else + slot->phase += slot->dphase; - slot->phase &= (DP_WIDTH - 1); + slot->phase &= (DP_WIDTH - 1); - slot->pgout = HIGHBITS (slot->phase, DP_BASE_BITS); + slot->pgout = HIGHBITS(slot->phase, DP_BASE_BITS); } /* EG */ -static void -calc_envelope (OPLL_SLOT * slot, e_int32 lfo) -{ -#define S2E(x) (SL2EG((e_int32)(x/SL_STEP))<<(EG_DP_BITS-EG_BITS)) +static void calc_envelope(OPLL_SLOT * slot, int32 lfo) { +#define S2E(x) (SL2EG((int32)(x / SL_STEP)) << (EG_DP_BITS - EG_BITS)) - static e_uint32 SL[16] = { - S2E (0.0), S2E (3.0), S2E (6.0), S2E (9.0), S2E (12.0), S2E (15.0), S2E (18.0), S2E (21.0), - S2E (24.0), S2E (27.0), S2E (30.0), S2E (33.0), S2E (36.0), S2E (39.0), S2E (42.0), S2E (48.0) - }; + static uint32 SL[16] = { + S2E(0.0), S2E(3.0), S2E(6.0), S2E(9.0), S2E(12.0), S2E(15.0), S2E(18.0), S2E(21.0), + S2E(24.0), S2E(27.0), S2E(30.0), S2E(33.0), S2E(36.0), S2E(39.0), S2E(42.0), S2E(48.0) + }; - e_uint32 egout; + uint32 egout; - switch (slot->eg_mode) - { + switch (slot->eg_mode) { + case ATTACK: + egout = AR_ADJUST_TABLE[HIGHBITS(slot->eg_phase, EG_DP_BITS - EG_BITS)]; + slot->eg_phase += slot->eg_dphase; + if ((EG_DP_WIDTH & slot->eg_phase) || (slot->patch.AR == 15)) { + egout = 0; + slot->eg_phase = 0; + slot->eg_mode = DECAY; + UPDATE_EG(slot); + } + break; - case ATTACK: - egout = AR_ADJUST_TABLE[HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS)]; - slot->eg_phase += slot->eg_dphase; - if((EG_DP_WIDTH & slot->eg_phase)||(slot->patch.AR==15)) - { - egout = 0; - slot->eg_phase = 0; - slot->eg_mode = DECAY; - UPDATE_EG (slot); - } - break; + case DECAY: + egout = HIGHBITS(slot->eg_phase, EG_DP_BITS - EG_BITS); + slot->eg_phase += slot->eg_dphase; + if (slot->eg_phase >= SL[slot->patch.SL]) { + if (slot->patch.EG) { + slot->eg_phase = SL[slot->patch.SL]; + slot->eg_mode = SUSHOLD; + UPDATE_EG(slot); + } else { + slot->eg_phase = SL[slot->patch.SL]; + slot->eg_mode = SUSTINE; + UPDATE_EG(slot); + } + } + break; - case DECAY: - egout = HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS); - slot->eg_phase += slot->eg_dphase; - if(slot->eg_phase >= SL[slot->patch.SL]) - { - if(slot->patch.EG) - { - slot->eg_phase = SL[slot->patch.SL]; - slot->eg_mode = SUSHOLD; - UPDATE_EG (slot); - } - else - { - slot->eg_phase = SL[slot->patch.SL]; - slot->eg_mode = SUSTINE; - UPDATE_EG (slot); - } - } - break; + case SUSHOLD: + egout = HIGHBITS(slot->eg_phase, EG_DP_BITS - EG_BITS); + if (slot->patch.EG == 0) { + slot->eg_mode = SUSTINE; + UPDATE_EG(slot); + } + break; - case SUSHOLD: - egout = HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS); - if(slot->patch.EG == 0) - { - slot->eg_mode = SUSTINE; - UPDATE_EG (slot); - } - break; + case SUSTINE: + case RELEASE: + egout = HIGHBITS(slot->eg_phase, EG_DP_BITS - EG_BITS); + slot->eg_phase += slot->eg_dphase; + if (egout >= (1 << EG_BITS)) { + slot->eg_mode = FINISH; + egout = (1 << EG_BITS) - 1; + } + break; - case SUSTINE: - case RELEASE: - egout = HIGHBITS (slot->eg_phase, EG_DP_BITS - EG_BITS); - slot->eg_phase += slot->eg_dphase; - if(egout >= (1 << EG_BITS)) - { - slot->eg_mode = FINISH; - egout = (1 << EG_BITS) - 1; - } - break; + case FINISH: + egout = (1 << EG_BITS) - 1; + break; - case FINISH: - egout = (1 << EG_BITS) - 1; - break; + default: + egout = (1 << EG_BITS) - 1; + break; + } - default: - egout = (1 << EG_BITS) - 1; - break; - } + if (slot->patch.AM) + egout = EG2DB(egout + slot->tll) + lfo; + else + egout = EG2DB(egout + slot->tll); - if(slot->patch.AM) - egout = EG2DB (egout + slot->tll) + lfo; - else - egout = EG2DB (egout + slot->tll); + if (egout >= DB_MUTE) + egout = DB_MUTE - 1; - if(egout >= DB_MUTE) - egout = DB_MUTE - 1; - - slot->egout = egout; + slot->egout = egout; } /* CARRIOR */ -INLINE static e_int32 -calc_slot_car (OPLL_SLOT * slot, e_int32 fm) -{ - slot->output[1] = slot->output[0]; +INLINE static int32 calc_slot_car(OPLL_SLOT * slot, int32 fm) { + slot->output[1] = slot->output[0]; - if(slot->egout >= (DB_MUTE - 1)) - { - slot->output[0] = 0; - } - else - { - slot->output[0] = DB2LIN_TABLE[slot->sintbl[(slot->pgout+wave2_8pi(fm))&(PG_WIDTH-1)] + slot->egout]; - } + if (slot->egout >= (DB_MUTE - 1)) { + slot->output[0] = 0; + } else { + slot->output[0] = DB2LIN_TABLE[slot->sintbl[(slot->pgout + wave2_8pi(fm)) & (PG_WIDTH - 1)] + slot->egout]; + } - return (slot->output[1] + slot->output[0]) >> 1; + return (slot->output[1] + slot->output[0]) >> 1; } /* MODULATOR */ -INLINE static e_int32 -calc_slot_mod (OPLL_SLOT * slot) -{ - e_int32 fm; +INLINE static int32 calc_slot_mod(OPLL_SLOT * slot) { + int32 fm; - slot->output[1] = slot->output[0]; + slot->output[1] = slot->output[0]; - if(slot->egout >= (DB_MUTE - 1)) - { - slot->output[0] = 0; - } - else if(slot->patch.FB != 0) - { - fm = wave2_4pi (slot->feedback) >> (7 - slot->patch.FB); - slot->output[0] = DB2LIN_TABLE[slot->sintbl[(slot->pgout + fm)&(PG_WIDTH-1)] + slot->egout]; - } - else - { - slot->output[0] = DB2LIN_TABLE[slot->sintbl[slot->pgout] + slot->egout]; - } + if (slot->egout >= (DB_MUTE - 1)) { + slot->output[0] = 0; + } else if (slot->patch.FB != 0) { + fm = wave2_4pi(slot->feedback) >> (7 - slot->patch.FB); + slot->output[0] = DB2LIN_TABLE[slot->sintbl[(slot->pgout + fm) & (PG_WIDTH - 1)] + slot->egout]; + } else { + slot->output[0] = DB2LIN_TABLE[slot->sintbl[slot->pgout] + slot->egout]; + } - slot->feedback = (slot->output[1] + slot->output[0]) >> 1; - - return slot->feedback; + slot->feedback = (slot->output[1] + slot->output[0]) >> 1; + return slot->feedback; } -static INLINE e_int16 calc (OPLL * opll) -{ - e_int32 inst = 0, out = 0; - e_int32 i; +static INLINE int16 calc(OPLL * opll) { + int32 inst = 0, out = 0; + int32 i; - update_ampm (opll); + update_ampm(opll); - for (i = 0; i < 12; i++) - { - calc_phase(&opll->slot[i],opll->lfo_pm); - calc_envelope(&opll->slot[i],opll->lfo_am); - } + for (i = 0; i < 12; i++) { + calc_phase(&opll->slot[i], opll->lfo_pm); + calc_envelope(&opll->slot[i], opll->lfo_am); + } - for (i = 0; i < 6; i++) - if(!(opll->mask & OPLL_MASK_CH (i)) && (CAR(opll,i)->eg_mode != FINISH)) - inst += calc_slot_car (CAR(opll,i), calc_slot_mod(MOD(opll,i))); + for (i = 0; i < 6; i++) + if (!(opll->mask & OPLL_MASK_CH(i)) && (CAR(opll, i)->eg_mode != FINISH)) + inst += calc_slot_car(CAR(opll, i), calc_slot_mod(MOD(opll, i))); - out = inst; - return (e_int16) out; + out = inst; + return (int16)out; } -void moocow(OPLL* opll, e_int32 *buf, e_int32 len, int shift) -{ - while(len > 0) - { - *buf+=(calc(opll)+32768)< 0) { + *buf += (calc(opll) + 32768) << shift; + buf++; + len--; + } } -#ifdef EMU2413_COMPACTION -e_int16 -OPLL_calc (OPLL * opll) -{ - return calc (opll); -} -#else -e_int16 -OPLL_calc (OPLL * opll) -{ - if(!opll->quality) - return calc (opll); +int16 OPLL_calc(OPLL * opll) { + if (!opll->quality) + return calc(opll); - while (opll->realstep > opll->oplltime) - { - opll->oplltime += opll->opllstep; - opll->prev = opll->next; - opll->next = calc (opll); - } + while (opll->realstep > opll->oplltime) { + opll->oplltime += opll->opllstep; + opll->prev = opll->next; + opll->next = calc(opll); + } - opll->oplltime -= opll->realstep; - opll->out = (e_int16) (((double) opll->next * (opll->opllstep - opll->oplltime) - + (double) opll->prev * opll->oplltime) / opll->opllstep); + opll->oplltime -= opll->realstep; + opll->out = (int16)(((double)opll->next * (opll->opllstep - opll->oplltime) + + (double)opll->prev * opll->oplltime) / opll->opllstep); - return (e_int16) opll->out; -} -#endif - -e_uint32 -OPLL_setMask (OPLL * opll, e_uint32 mask) -{ - e_uint32 ret; - - if(opll) - { - ret = opll->mask; - opll->mask = mask; - return ret; - } - else - return 0; + return (int16)opll->out; } -e_uint32 -OPLL_toggleMask (OPLL * opll, e_uint32 mask) -{ - e_uint32 ret; +uint32 OPLL_setMask(OPLL * opll, uint32 mask) { + uint32 ret; - if(opll) - { - ret = opll->mask; - opll->mask ^= mask; - return ret; - } - else - return 0; + if (opll) { + ret = opll->mask; + opll->mask = mask; + return ret; + } else + return 0; +} + +uint32 OPLL_toggleMask(OPLL * opll, uint32 mask) { + uint32 ret; + + if (opll) { + ret = opll->mask; + opll->mask ^= mask; + return ret; + } else + return 0; } /**************************************************** - I/O Ctrl + I/O Ctrl *****************************************************/ -static void setInstrument(OPLL * opll, e_uint i, e_uint inst) -{ - const e_uint8 *src; - OPLL_PATCH *modp, *carp; +static void setInstrument(OPLL * opll, uint32 i, uint32 inst) { + const uint8 *src; + OPLL_PATCH *modp, *carp; - opll->patch_number[i]=inst; + opll->patch_number[i] = inst; - if(inst) - src=default_inst[inst-1]; - else - src=opll->CustInst; + if (inst) + src = default_inst[inst - 1]; + else + src = opll->CustInst; - modp=&MOD(opll,i)->patch; - carp=&CAR(opll,i)->patch; + modp = &MOD(opll, i)->patch; + carp = &CAR(opll, i)->patch; - modp->AM=(src[0]>>7)&1; - modp->PM=(src[0]>>6)&1; - modp->EG=(src[0]>>5)&1; - modp->KR=(src[0]>>4)&1; - modp->ML=(src[0]&0xF); + modp->AM = (src[0] >> 7) & 1; + modp->PM = (src[0] >> 6) & 1; + modp->EG = (src[0] >> 5) & 1; + modp->KR = (src[0] >> 4) & 1; + modp->ML = (src[0] & 0xF); - carp->AM=(src[1]>>7)&1; - carp->PM=(src[1]>>6)&1; - carp->EG=(src[1]>>5)&1; - carp->KR=(src[1]>>4)&1; - carp->ML=(src[1]&0xF); + carp->AM = (src[1] >> 7) & 1; + carp->PM = (src[1] >> 6) & 1; + carp->EG = (src[1] >> 5) & 1; + carp->KR = (src[1] >> 4) & 1; + carp->ML = (src[1] & 0xF); - modp->KL=(src[2]>>6)&3; - modp->TL=(src[2]&0x3F); + modp->KL = (src[2] >> 6) & 3; + modp->TL = (src[2] & 0x3F); - carp->KL = (src[3] >> 6) & 3; - carp->WF = (src[3] >> 4) & 1; + carp->KL = (src[3] >> 6) & 3; + carp->WF = (src[3] >> 4) & 1; - modp->WF = (src[3] >> 3) & 1; + modp->WF = (src[3] >> 3) & 1; - modp->FB = (src[3]) & 7; + modp->FB = (src[3]) & 7; - modp->AR = (src[4]>>4)&0xF; - modp->DR = (src[4]&0xF); + modp->AR = (src[4] >> 4) & 0xF; + modp->DR = (src[4] & 0xF); - carp->AR = (src[5]>>4)&0xF; - carp->DR = (src[5]&0xF); + carp->AR = (src[5] >> 4) & 0xF; + carp->DR = (src[5] & 0xF); - modp->SL = (src[6]>>4)&0xF; - modp->RR = (src[6]&0xF); + modp->SL = (src[6] >> 4) & 0xF; + modp->RR = (src[6] & 0xF); - carp->SL = (src[7]>>4)&0xF; - carp->RR = (src[7]&0xF); + carp->SL = (src[7] >> 4) & 0xF; + carp->RR = (src[7] & 0xF); } -void -OPLL_writeReg (OPLL * opll, e_uint32 reg, e_uint32 data) -{ +void OPLL_writeReg(OPLL * opll, uint32 reg, uint32 data) { + int32 i, v, ch; - e_int32 i, v, ch; + data = data & 0xff; + reg = reg & 0x3f; - data = data & 0xff; - reg = reg & 0x3f; + switch (reg) { + case 0x00: + opll->CustInst[0] = data; + for (i = 0; i < 6; i++) { + if (opll->patch_number[i] == 0) { + setInstrument(opll, i, 0); + UPDATE_PG(MOD(opll, i)); + UPDATE_RKS(MOD(opll, i)); + UPDATE_EG(MOD(opll, i)); + } + } + break; - switch (reg) - { - case 0x00: - opll->CustInst[0]=data; - for (i = 0; i < 6; i++) - { - if(opll->patch_number[i] == 0) - { - setInstrument(opll, i, 0); - UPDATE_PG (MOD(opll,i)); - UPDATE_RKS (MOD(opll,i)); - UPDATE_EG (MOD(opll,i)); - } - } - break; + case 0x01: + opll->CustInst[1] = data; + for (i = 0; i < 6; i++) { + if (opll->patch_number[i] == 0) { + setInstrument(opll, i, 0); + UPDATE_PG(CAR(opll, i)); + UPDATE_RKS(CAR(opll, i)); + UPDATE_EG(CAR(opll, i)); + } + } + break; - case 0x01: - opll->CustInst[1]=data; - for (i = 0; i < 6; i++) - { - if(opll->patch_number[i] == 0) - { - setInstrument(opll, i, 0); - UPDATE_PG (CAR(opll,i)); - UPDATE_RKS (CAR(opll,i)); - UPDATE_EG (CAR(opll,i)); - } - } - break; + case 0x02: + opll->CustInst[2] = data; + for (i = 0; i < 6; i++) { + if (opll->patch_number[i] == 0) { + setInstrument(opll, i, 0); + UPDATE_TLL(MOD(opll, i)); + } + } + break; - case 0x02: - opll->CustInst[2]=data; - for (i = 0; i < 6; i++) - { - if(opll->patch_number[i] == 0) - { - setInstrument(opll, i, 0); - UPDATE_TLL(MOD(opll,i)); - } - } - break; + case 0x03: + opll->CustInst[3] = data; + for (i = 0; i < 6; i++) { + if (opll->patch_number[i] == 0) { + setInstrument(opll, i, 0); + UPDATE_WF(MOD(opll, i)); + UPDATE_WF(CAR(opll, i)); + } + } + break; - case 0x03: - opll->CustInst[3]=data; - for (i = 0; i < 6; i++) - { - if(opll->patch_number[i] == 0) - { - setInstrument(opll, i, 0); - UPDATE_WF(MOD(opll,i)); - UPDATE_WF(CAR(opll,i)); - } - } - break; + case 0x04: + opll->CustInst[4] = data; + for (i = 0; i < 6; i++) { + if (opll->patch_number[i] == 0) { + setInstrument(opll, i, 0); + UPDATE_EG(MOD(opll, i)); + } + } + break; - case 0x04: - opll->CustInst[4]=data; - for (i = 0; i < 6; i++) - { - if(opll->patch_number[i] == 0) - { - setInstrument(opll, i, 0); - UPDATE_EG (MOD(opll,i)); - } - } - break; + case 0x05: + opll->CustInst[5] = data; + for (i = 0; i < 6; i++) { + if (opll->patch_number[i] == 0) { + setInstrument(opll, i, 0); + UPDATE_EG(CAR(opll, i)); + } + } + break; - case 0x05: - opll->CustInst[5]=data; - for (i = 0; i < 6; i++) - { - if(opll->patch_number[i] == 0) - { - setInstrument(opll, i, 0); - UPDATE_EG(CAR(opll,i)); - } - } - break; + case 0x06: + opll->CustInst[6] = data; + for (i = 0; i < 6; i++) { + if (opll->patch_number[i] == 0) { + setInstrument(opll, i, 0); + UPDATE_EG(MOD(opll, i)); + } + } + break; - case 0x06: - opll->CustInst[6]=data; - for (i = 0; i < 6; i++) - { - if(opll->patch_number[i] == 0) - { - setInstrument(opll, i, 0); - UPDATE_EG (MOD(opll,i)); - } - } - break; + case 0x07: + opll->CustInst[7] = data; + for (i = 0; i < 6; i++) { + if (opll->patch_number[i] == 0) { + setInstrument(opll, i, 0); + UPDATE_EG(CAR(opll, i)); + } + } + break; - case 0x07: - opll->CustInst[7]=data; - for (i = 0; i < 6; i++) - { - if(opll->patch_number[i] == 0) - { - setInstrument(opll, i, 0); - UPDATE_EG (CAR(opll,i)); - } - } - break; + case 0x10: + case 0x11: + case 0x12: + case 0x13: + case 0x14: + case 0x15: + ch = reg - 0x10; + opll->LowFreq[ch] = data; + setFnumber(opll, ch, data + ((opll->HiFreq[ch] & 1) << 8)); + UPDATE_ALL(MOD(opll, ch)); + UPDATE_ALL(CAR(opll, ch)); + break; - case 0x10: - case 0x11: - case 0x12: - case 0x13: - case 0x14: - case 0x15: - ch = reg - 0x10; - opll->LowFreq[ch]=data; - setFnumber (opll, ch, data + ((opll->HiFreq[ch] & 1) << 8)); - UPDATE_ALL (MOD(opll,ch)); - UPDATE_ALL (CAR(opll,ch)); - break; + case 0x20: + case 0x21: + case 0x22: + case 0x23: + case 0x24: + case 0x25: + ch = reg - 0x20; + opll->HiFreq[ch] = data; - case 0x20: - case 0x21: - case 0x22: - case 0x23: - case 0x24: - case 0x25: - ch = reg - 0x20; - opll->HiFreq[ch]=data; + setFnumber(opll, ch, ((data & 1) << 8) + opll->LowFreq[ch]); + setBlock(opll, ch, (data >> 1) & 7); + setSustine(opll, ch, (data >> 5) & 1); + if (data & 0x10) + keyOn(opll, ch); + else + keyOff(opll, ch); + UPDATE_ALL(MOD(opll, ch)); + UPDATE_ALL(CAR(opll, ch)); + update_key_status(opll); + break; - setFnumber (opll, ch, ((data & 1) << 8) + opll->LowFreq[ch]); - setBlock (opll, ch, (data >> 1) & 7); - setSustine (opll, ch, (data >> 5) & 1); - if(data & 0x10) - keyOn (opll, ch); - else - keyOff (opll, ch); - UPDATE_ALL (MOD(opll,ch)); - UPDATE_ALL (CAR(opll,ch)); - update_key_status (opll); - break; + case 0x30: + case 0x31: + case 0x32: + case 0x33: + case 0x34: + case 0x35: + opll->InstVol[reg - 0x30] = data; + i = (data >> 4) & 15; + v = data & 15; + setInstrument(opll, reg - 0x30, i); + setVolume(opll, reg - 0x30, v << 2); + UPDATE_ALL(MOD(opll, reg - 0x30)); + UPDATE_ALL(CAR(opll, reg - 0x30)); + break; - case 0x30: - case 0x31: - case 0x32: - case 0x33: - case 0x34: - case 0x35: - opll->InstVol[reg-0x30]=data; - i = (data >> 4) & 15; - v = data & 15; - setInstrument(opll, reg-0x30, i); - setVolume (opll, reg - 0x30, v << 2); - UPDATE_ALL (MOD(opll,reg - 0x30)); - UPDATE_ALL (CAR(opll,reg - 0x30)); - break; - - default: - break; - - } + default: + break; + } } -void -OPLL_writeIO (OPLL * opll, e_uint32 adr, e_uint32 val) -{ - if(adr & 1) - OPLL_writeReg (opll, opll->adr, val); - else - opll->adr = val; +void OPLL_writeIO(OPLL * opll, uint32 adr, uint32 val) { + if (adr & 1) + OPLL_writeReg(opll, opll->adr, val); + else + opll->adr = val; } diff --git a/src/mappers/emu2413.h b/src/mappers/emu2413.h index 906b4c5a..20e0e7d2 100644 --- a/src/mappers/emu2413.h +++ b/src/mappers/emu2413.h @@ -1,131 +1,136 @@ #ifndef _EMU2413_H_ #define _EMU2413_H_ -#include "emutypes.h" - -#ifdef EMU2413_DLL_EXPORTS - #define EMU2413_API __declspec(dllexport) -#elif defined(EMU2413_DLL_IMPORTS) - #define EMU2413_API __declspec(dllimport) -#else - #define EMU2413_API -#endif - +#ifndef INLINE +#if defined(_MSC_VER) +#define INLINE __forceinline +#elif defined(__GNUC__) +#define INLINE __inline__ +#elif defined(_MWERKS_) +#define INLINE inline +#else +#define INLINE +#endif +#endif + #ifdef __cplusplus extern "C" { #endif +typedef unsigned char uint8 ; +typedef signed char int8 ; + +typedef unsigned short uint16 ; +typedef signed short int16 ; + +typedef unsigned int uint32 ; +typedef signed int int32 ; + #define PI 3.14159265358979323846 -enum {OPLL_VRC7_TONE=0} ; +enum { OPLL_VRC7_TONE=0 }; /* voice data */ typedef struct { - e_uint32 TL,FB,EG,ML,AR,DR,SL,RR,KR,KL,AM,PM,WF ; -} OPLL_PATCH ; + uint32 TL, FB, EG, ML, AR, DR, SL, RR, KR, KL, AM, PM, WF; +} OPLL_PATCH; /* slot */ typedef struct { + OPLL_PATCH patch; - OPLL_PATCH patch; + int32 type; /* 0 : modulator 1 : carrier */ - e_int32 type ; /* 0 : modulator 1 : carrier */ + /* OUTPUT */ + int32 feedback; + int32 output[2]; /* Output value of slot */ - /* OUTPUT */ - e_int32 feedback ; - e_int32 output[2] ; /* Output value of slot */ + /* for Phase Generator (PG) */ + uint16 *sintbl; /* Wavetable */ + uint32 phase; /* Phase */ + uint32 dphase; /* Phase increment amount */ + uint32 pgout; /* output */ - /* for Phase Generator (PG) */ - e_uint16 *sintbl ; /* Wavetable */ - e_uint32 phase ; /* Phase */ - e_uint32 dphase ; /* Phase increment amount */ - e_uint32 pgout ; /* output */ - - /* for Envelope Generator (EG) */ - e_int32 fnum ; /* F-Number */ - e_int32 block ; /* Block */ - e_int32 volume ; /* Current volume */ - e_int32 sustine ; /* Sustine 1 = ON, 0 = OFF */ - e_uint32 tll ; /* Total Level + Key scale level*/ - e_uint32 rks ; /* Key scale offset (Rks) */ - e_int32 eg_mode ; /* Current state */ - e_uint32 eg_phase ; /* Phase */ - e_uint32 eg_dphase ; /* Phase increment amount */ - e_uint32 egout ; /* output */ - -} OPLL_SLOT ; + /* for Envelope Generator (EG) */ + int32 fnum; /* F-Number */ + int32 block; /* Block */ + int32 volume; /* Current volume */ + int32 sustine; /* Sustine 1 = ON, 0 = OFF */ + uint32 tll; /* Total Level + Key scale level*/ + uint32 rks; /* Key scale offset (Rks) */ + int32 eg_mode; /* Current state */ + uint32 eg_phase; /* Phase */ + uint32 eg_dphase; /* Phase increment amount */ + uint32 egout; /* output */ +} OPLL_SLOT; /* Mask */ -#define OPLL_MASK_CH(x) (1<<(x)) +#define OPLL_MASK_CH(x) (1 << (x)) /* opll */ typedef struct { + uint32 adr; + int32 out; - e_uint32 adr ; - e_int32 out ; + uint32 realstep; + uint32 oplltime; + uint32 opllstep; + int32 prev, next; -#ifndef EMU2413_COMPACTION - e_uint32 realstep ; - e_uint32 oplltime ; - e_uint32 opllstep ; - e_int32 prev, next ; -#endif + /* Register */ + uint8 LowFreq[6]; + uint8 HiFreq[6]; + uint8 InstVol[6]; - /* Register */ - e_uint8 LowFreq[6]; - e_uint8 HiFreq[6]; - e_uint8 InstVol[6]; + uint8 CustInst[8]; - e_uint8 CustInst[8]; + int32 slot_on_flag[6 * 2]; - e_int32 slot_on_flag[6 * 2] ; + /* Pitch Modulator */ + uint32 pm_phase; + int32 lfo_pm; - /* Pitch Modulator */ - e_uint32 pm_phase ; - e_int32 lfo_pm ; + /* Amp Modulator */ + int32 am_phase; + int32 lfo_am; - /* Amp Modulator */ - e_int32 am_phase ; - e_int32 lfo_am ; + uint32 quality; - e_uint32 quality; + /* Channel Data */ + int32 patch_number[6]; + int32 key_status[6]; - /* Channel Data */ - e_int32 patch_number[6]; - e_int32 key_status[6] ; + /* Slot */ + OPLL_SLOT slot[6 * 2]; - /* Slot */ - OPLL_SLOT slot[6 * 2] ; - - e_uint32 mask ; - -} OPLL ; + uint32 mask; +} OPLL; /* Create Object */ -EMU2413_API OPLL *OPLL_new(e_uint32 clk, e_uint32 rate) ; -EMU2413_API void OPLL_delete(OPLL *) ; +OPLL *OPLL_new(uint32 clk, uint32 rate); +void OPLL_delete(OPLL *); /* Setup */ -EMU2413_API void OPLL_reset(OPLL *) ; -EMU2413_API void OPLL_set_rate(OPLL *opll, e_uint32 r) ; -EMU2413_API void OPLL_set_quality(OPLL *opll, e_uint32 q) ; +void OPLL_reset(OPLL *); +void OPLL_set_rate(OPLL *opll, uint32 r); +void OPLL_set_quality(OPLL *opll, uint32 q); /* Port/Register access */ -EMU2413_API void OPLL_writeIO(OPLL *, e_uint32 reg, e_uint32 val) ; -EMU2413_API void OPLL_writeReg(OPLL *, e_uint32 reg, e_uint32 val) ; +void OPLL_writeIO(OPLL *, uint32 reg, uint32 val); +void OPLL_writeReg(OPLL *, uint32 reg, uint32 val); /* Synthsize */ -EMU2413_API e_int16 OPLL_calc(OPLL *) ; +int16 OPLL_calc(OPLL *); /* Misc */ -EMU2413_API void OPLL_forceRefresh(OPLL *) ; +void OPLL_forceRefresh(OPLL *); /* Channel Mask */ -EMU2413_API e_uint32 OPLL_setMask(OPLL *, e_uint32 mask) ; -EMU2413_API e_uint32 OPLL_toggleMask(OPLL *, e_uint32 mask) ; +uint32 OPLL_setMask(OPLL *, uint32 mask); +uint32 OPLL_toggleMask(OPLL *, uint32 mask); -void moocow(OPLL* opll, e_int32 *buf, e_int32 len, int shift); +void moocow(OPLL* opll, int32 *buf, int32 len, int shift); #ifdef __cplusplus } diff --git a/src/mappers/emutypes.h b/src/mappers/emutypes.h deleted file mode 100644 index fdef420f..00000000 --- a/src/mappers/emutypes.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef _EMUTYPES_H_ -#define _EMUTYPES_H_ - -#ifndef INLINE - -#if defined(_MSC_VER) -#define INLINE __forceinline -#elif defined(__GNUC__) -#define INLINE __inline__ -#elif defined(_MWERKS_) -#define INLINE inline -#else -#define INLINE -#endif -#endif - -#if defined(EMU_DLL_IMPORTS) -#define EMU2149_DLL_IMPORTS -#define EMU2212_DLL_IMPORTS -#define EMU2413_DLL_IMPORTS -#define EMU8950_DLL_IMPORTS -#define EMU76489_DLL_IMPORTS -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -typedef unsigned int e_uint; -typedef signed int e_int; - -typedef unsigned char e_uint8 ; -typedef signed char e_int8 ; - -typedef unsigned short e_uint16 ; -typedef signed short e_int16 ; - -typedef unsigned int e_uint32 ; -typedef signed int e_int32 ; - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/mappers/vrc7tone.h b/src/mappers/vrc7tone.h deleted file mode 100644 index d1363073..00000000 --- a/src/mappers/vrc7tone.h +++ /dev/null @@ -1,17 +0,0 @@ -/* VRC7 instruments, January 17, 2004 update -Xodnizel */ - {0x03, 0x21, 0x04, 0x06, 0x8D, 0xF2, 0x42, 0x17}, - {0x13, 0x41, 0x05, 0x0E, 0x99, 0x96, 0x63, 0x12}, - {0x31, 0x11, 0x10, 0x0A, 0xF0, 0x9C, 0x32, 0x02}, - {0x21, 0x61, 0x1D, 0x07, 0x9F, 0x64, 0x20, 0x27}, - {0x22, 0x21, 0x1E, 0x06, 0xF0, 0x76, 0x08, 0x28}, - {0x02, 0x01, 0x06, 0x00, 0xF0, 0xF2, 0x03, 0x95}, - {0x21, 0x61, 0x1C, 0x07, 0x82, 0x81, 0x16, 0x07}, - {0x23, 0x21, 0x1A, 0x17, 0xEF, 0x82, 0x25, 0x15}, - {0x25, 0x11, 0x1F, 0x00, 0x86, 0x41, 0x20, 0x11}, - {0x85, 0x01, 0x1F, 0x0F, 0xE4, 0xA2, 0x11, 0x12}, - {0x07, 0xC1, 0x2B, 0x45, 0xB4, 0xF1, 0x24, 0xF4}, - {0x61, 0x23, 0x11, 0x06, 0x96, 0x96, 0x13, 0x16}, - {0x01, 0x02, 0xD3, 0x05, 0x82, 0xA2, 0x31, 0x51}, - {0x61, 0x22, 0x0D, 0x02, 0xC3, 0x7F, 0x24, 0x05}, - {0x21, 0x62, 0x0E, 0x00, 0xA1, 0xA0, 0x44, 0x17}, - diff --git a/src/unif.h b/src/unif.h index c45350d4..e68aeb16 100644 --- a/src/unif.h +++ b/src/unif.h @@ -24,7 +24,6 @@ void BMC12IN1_Init(CartInfo *info); void BMC13in1JY110_Init(CartInfo *info); void BMC190in1_Init(CartInfo *info); void BMC411120C_Init(CartInfo *info); -void BMC42in1r_Init(CartInfo *info); void BMC64in1nr_Init(CartInfo *info); void BMC70in1B_Init(CartInfo *info); void BMC70in1_Init(CartInfo *info); @@ -142,5 +141,5 @@ void UNLVRC7_Init(CartInfo *info); void UNLYOKO_Init(CartInfo *info); void UNROM_Init(CartInfo *info); -extern uint8 *UNIFchrrama; // Meh. So I can stop CHR RAM - // bank switcherooing with certain boards... +extern uint8 *UNIFchrrama; // Meh. So I can stop CHR RAM + // bank switcherooing with certain boards... diff --git a/vc/vc10_fceux.vcxproj b/vc/vc10_fceux.vcxproj index cf6c4f7c..b6fc10d8 100644 --- a/vc/vc10_fceux.vcxproj +++ b/vc/vc10_fceux.vcxproj @@ -259,8 +259,16 @@ + + + + + + + + @@ -569,17 +577,7 @@ - - - - - - - - - - @@ -829,9 +827,7 @@ - - diff --git a/vc/vc10_fceux.vcxproj.filters b/vc/vc10_fceux.vcxproj.filters index b17a3a86..9edfb4d4 100644 --- a/vc/vc10_fceux.vcxproj.filters +++ b/vc/vc10_fceux.vcxproj.filters @@ -644,39 +644,9 @@ drivers\win\lua - - mappers - - - mappers - - - mappers - - - mappers - - - mappers - - - mappers - mappers - - mappers - - - mappers - - - mappers - - - mappers - mappers @@ -967,6 +937,30 @@ boards + + boards + + + boards + + + boards + + + boards + + + boards + + + boards + + + boards + + + boards + @@ -1290,15 +1284,9 @@ mappers - - mappers - mappers - - mappers - include files diff --git a/vc/vc8_fceux.vcproj b/vc/vc8_fceux.vcproj index 864f0bfb..14dc91dc 100644 --- a/vc/vc8_fceux.vcproj +++ b/vc/vc8_fceux.vcproj @@ -681,6 +681,38 @@ RelativePath="..\src\boards\225.cpp" > + + + + + + + + + + + + + + + + @@ -4132,50 +4164,10 @@ RelativePath="..\src\mappers\217.cpp" > - - - - - - - - - - - - - - - - - - - - @@ -4329,10 +4321,6 @@ RelativePath="..\src\mappers\emu2413.h" > - - @@ -4341,10 +4329,6 @@ RelativePath="..\src\mappers\mmc2and4.cpp" > - - - - @@ -2519,14 +2515,6 @@ RelativePath="..\src\mappers\mmc2and4.cpp" > - - - -