Add proper seibu sound support to Toki and add a few notes.

This commit is contained in:
iq_132 2014-10-17 04:13:42 +00:00
parent e439f06158
commit 3f8f7d1b7d
1 changed files with 235 additions and 521 deletions

View File

@ -1,8 +1,11 @@
// Why isn't sound working for jujuba?
// Title screen only correct with asm 68k core... :|
// needs cleaned up badly!
#include "tiles_generic.h"
#include "m68000_intf.h"
#include "z80_intf.h"
#include "burn_ym3812.h"
#include "msm6295.h"
#include "seibusnd.h"
#include "msm5205.h"
#include "bitswap.h"
@ -42,9 +45,6 @@ static UINT8 DrvRecalc;
static UINT8 *soundlatch;
static UINT8 main2sub[2],sub2main[2];
static INT32 main2sub_pending,sub2main_pending;
static INT32 is_bootleg = 0;
static UINT8 TokibMSM5205Next = 0;
@ -251,8 +251,6 @@ static void palette_write(INT32 offset)
UINT8 r, g, b;
// 4b4g4r handler
r = (data & 0x0f);
r |= r << 4;
@ -266,91 +264,6 @@ static void palette_write(INT32 offset)
DrvPalette[offset >> 1] = BurnHighCol(r, g, b, 0);
}
enum
{
VECTOR_INIT,
RST10_ASSERT,
RST10_CLEAR,
RST18_ASSERT,
RST18_CLEAR
};
static void update_irq_lines(INT32 param)
{
static INT32 irq1,irq2;
switch(param)
{
case VECTOR_INIT:
irq1 = irq2 = 0xff;
break;
case RST10_ASSERT:
irq1 = 0xd7;
break;
case RST10_CLEAR:
irq1 = 0xff;
break;
case RST18_ASSERT:
irq2 = 0xdf;
break;
case RST18_CLEAR:
irq2 = 0xff;
break;
}
if ((irq1 & irq2) == 0xff) {
ZetSetIRQLine(0, ZET_IRQSTATUS_NONE);
} else {
if (irq2 == 0xdf) { // this shouldn't be required - Raiden needs it too though???
ZetSetVector(irq1 & irq2);
ZetSetIRQLine(0, ZET_IRQSTATUS_ACK);
}
}
}
UINT8 seibu_main_word_r(INT32 offset)
{
offset = (offset >> 1) & 7;
switch (offset)
{
case 2:
case 3:
return sub2main[offset-2];
case 5:
return main2sub_pending ? 1 : 0;
default:
return 0xff;
}
}
void seibu_main_word_w(INT32 offset, UINT8 data)
{
offset = (offset >> 1) & 7;
switch (offset)
{
case 0:
case 1:
main2sub[offset] = data;
break;
case 4:
if (!is_bootleg) update_irq_lines(RST18_ASSERT);
break;
case 6:
/* just a guess */
sub2main_pending = 0;
main2sub_pending = 1;
break;
default:
break;
}
}
void __fastcall tokib_write_byte(UINT32 address, UINT8 data)
{
if ((address & 0xff800) == 0x6e000) {
@ -414,7 +327,7 @@ void __fastcall tokib_write_byte(UINT32 address, UINT8 data)
case 0x8000b:
case 0x8000c:
case 0x8000d: {
seibu_main_word_w(address, data);
seibu_main_word_write(address & 0xf, data);
return;
}
}
@ -477,7 +390,7 @@ void __fastcall tokib_write_word(UINT32 address, UINT16 data)
case 0x8000b:
case 0x8000c:
case 0x8000d: {
seibu_main_word_w(address, data);
seibu_main_word_write(address & 0xf, data);
return;
}
@ -508,7 +421,7 @@ UINT8 __fastcall tokib_read_byte(UINT32 address)
case 0x8000b:
case 0x8000c:
case 0x8000d: {
return seibu_main_word_r(address);
return seibu_main_word_read(address & 0x0f);
}
case 0xc0000:
@ -550,7 +463,7 @@ UINT16 __fastcall tokib_read_word(UINT32 address)
case 0x8000b:
case 0x8000c:
case 0x8000d: {
return seibu_main_word_r(address);
return seibu_main_word_read(address & 0x0f);
}
case 0xc0000:
@ -569,113 +482,18 @@ UINT16 __fastcall tokib_read_word(UINT32 address)
return 0;
}
static void seibu_z80_bank(INT32 bank)
{
INT32 nBank = bank & 1;
ZetMapArea(0x8000, 0xffff, 0, DrvZ80ROM + 0x10000 + nBank * 0x8000);
ZetMapArea(0x8000, 0xffff, 2, DrvZ80ROM + 0x10000 + nBank * 0x8000);
}
void __fastcall toki_seibu_sound_write(UINT16 address, UINT8 data)
{
switch (address)
{
case 0x4000:
main2sub_pending = 0;
sub2main_pending = 1;
return;
case 0x4001:
update_irq_lines(VECTOR_INIT);
return;
case 0x4002:
//seibu_rst10_ack_w - unused
return;
case 0x4003:
update_irq_lines(RST18_CLEAR);
return;
case 0x4007:
seibu_z80_bank(data);
return;
case 0x4008:
BurnYM3812Write(0, data);
return;
case 0x4009:
BurnYM3812Write(1, data);
return;
case 0x4018:
case 0x4019:
sub2main[address & 1] = data;
return;
case 0x401b:
//seibu_coin_w
return;
case 0x6000:
MSM6295Command(0, data);
return;
}
bprintf (PRINT_NORMAL, _T("%4.4x, %2.2x\n"), address, data);
}
UINT8 __fastcall toki_seibu_sound_read(UINT16 address)
{
switch (address)
{
case 0x4008:
return BurnYM3812Read(0);
case 0x4010:
case 0x4011:
return main2sub[address & 1];
case 0x4012:
return sub2main_pending ? 1 : 0;
case 0x4013:
return (DrvJoy3[1] << 1) | DrvJoy3[0]; // COIN
case 0x6000:
return MSM6295ReadStatus(0);
}
bprintf (PRINT_NORMAL, _T("%4.4x,\n"), address);
return 0;
}
static void toki_adpcm_control_w(INT32 data)
{
INT32 bankaddress = data & 1;
UINT8 *RAM = DrvZ80ROM + 0x8000 + bankaddress * 0x4000;
/* the code writes either 2 or 3 in the bottom two bits */
// bankaddress = 0x10000 + (data & 0x01) * 0x4000;
// memory_set_bankptr(1,&RAM[bankaddress]);
ZetMapArea(0x8000, 0xbfff, 0, RAM);
ZetMapArea(0x8000, 0xbfff, 2, RAM);
MSM5205ResetWrite(0, data & 0x08);
}
void __fastcall tokib_sound_write(UINT16 address, UINT8 data)
{
switch (address)
@ -725,13 +543,17 @@ static INT32 DrvDoReset()
SekReset();
SekClose();
ZetOpen(0);
ZetReset();
if (!is_bootleg) update_irq_lines(VECTOR_INIT);
ZetClose();
if (is_bootleg) {
ZetOpen(0);
ZetReset();
ZetClose();
BurnYM3812Reset();
if (!is_bootleg) MSM6295Reset(0);
BurnYM3812Reset();
}
else
{
seibu_sound_reset();
}
return 0;
}
@ -746,7 +568,6 @@ static INT32 TokibDoReset()
return DrvDoReset();
}
static void tokib_rom_decode()
{
UINT8 *temp = (UINT8*)malloc(65536 * 2);
@ -796,11 +617,6 @@ static void tokib_rom_decode()
}
static INT32 TokibGfxDecode()
{
INT32 Plane0[4] = { 4096*8*8*3, 4096*8*8*2, 4096*8*8*1, 4096*8*8*0 }; // char
@ -846,15 +662,15 @@ static INT32 TokibGfxDecode()
return 0;
}
static INT32 MemIndex()
{
UINT8 *Next; Next = AllMem;
Drv68KROM = Next; Next += 0x060000;
SeibuZ80ROM = Next;
DrvZ80ROM = Next; Next += 0x020000;
SeibuZ80DecROM = Next;
DrvZ80DecROM = Next; Next += 0x010000;
DrvGfxROM0 = Next; Next += 0x040000;
@ -862,7 +678,8 @@ static INT32 MemIndex()
DrvGfxROM2 = Next; Next += 0x100000;
DrvGfxROM3 = Next; Next += 0x100000;
DrvSndROM = Next; Next += 0x020000;
MSM6295ROM = Next;
DrvSndROM = Next; Next += 0x040000;
DrvPalette = (UINT32*)Next; Next += 0x400 * sizeof(UINT32);
@ -872,6 +689,7 @@ static INT32 MemIndex()
DrvBg2RAM = Next; Next += 0x000800;
DrvFgRAM = Next; Next += 0x000800;
Drv68KRAM = Next; Next += 0x00e000;
SeibuZ80RAM = Next;
DrvZ80RAM = Next; Next += 0x000800;
DrvPalRAM = Next; Next += 0x000800;
DrvSprRAM = Next; Next += 0x000800;
@ -890,18 +708,207 @@ static INT32 MemIndex()
return 0;
}
static INT32 DrvSynchroniseStream(INT32 nSoundRate)
static INT32 DrvGfxDecode()
{
return (INT64)ZetTotalCycles() * nSoundRate / 3579545;
INT32 Plane0[4] = { 4096*16*8+0, 4096*16*8+4, 0, 4 }; // char
INT32 Plane1[4] = { 2*4, 3*4, 0*4, 1*4 }; // spr, tile
INT32 XOffs0[8] = { 3, 2, 1, 0, 8+3, 8+2, 8+1, 8+0 }; // char
INT32 YOffs0[16] = { 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16 };
// tiles
INT32 XOffs1[16] = { 3, 2, 1, 0, 16+3, 16+2, 16+1, 16+0,
64*8+3, 64*8+2, 64*8+1, 64*8+0, 64*8+16+3, 64*8+16+2, 64*8+16+1, 64*8+16+0 };
INT32 YOffs1[32] = { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32,
8*32, 9*32, 10*32, 11*32, 12*32, 13*32, 14*32, 15*32 };
UINT8 *tmp = (UINT8*)BurnMalloc(0x100000);
if (tmp == NULL) {
return 1;
}
memcpy (tmp, DrvGfxROM0, 0x020000);
GfxDecode(4096, 4, 8, 8, Plane0, XOffs0, YOffs0, 0x080, tmp, DrvGfxROM0);
memcpy (tmp, DrvGfxROM1, 0x100000);
GfxDecode(8192, 4, 16, 16, Plane1, XOffs1, YOffs1, 0x400, tmp, DrvGfxROM1);
memcpy (tmp, DrvGfxROM2, 0x080000);
GfxDecode(4096, 4, 16, 16, Plane1, XOffs1, YOffs1, 0x400, tmp, DrvGfxROM2);
memcpy (tmp, DrvGfxROM3, 0x080000);
GfxDecode(4096, 4, 16, 16, Plane1, XOffs1, YOffs1, 0x400, tmp, DrvGfxROM3);
BurnFree (tmp);
return 0;
}
static void DrvFMIRQHandler(INT32, INT32 nStatus)
static INT32 DrvInit()
{
if (nStatus) {
update_irq_lines(RST10_ASSERT);
} else {
update_irq_lines(RST10_CLEAR);
is_bootleg = 0;
AllMem = NULL;
MemIndex();
INT32 nLen = MemEnd - (UINT8 *)0;
if ((AllMem = (UINT8 *)BurnMalloc(nLen)) == NULL) return 1;
memset(AllMem, 0, nLen);
MemIndex();
if (BurnLoadRom(Drv68KROM + 0x00001, 0, 2)) return 1;
if (BurnLoadRom(Drv68KROM + 0x00000, 1, 2)) return 1;
if (BurnLoadRom(Drv68KROM + 0x40001, 2, 2)) return 1;
if (BurnLoadRom(Drv68KROM + 0x40000, 3, 2)) return 1;
if (BurnLoadRom(DrvZ80ROM + 0x00000, 4, 1)) return 1;
if (BurnLoadRom(DrvZ80ROM + 0x10000, 5, 1)) return 1;
if (BurnLoadRom(DrvGfxROM0 + 0x00000, 6, 1)) return 1;
if (BurnLoadRom(DrvGfxROM0 + 0x10000, 7, 1)) return 1;
if (BurnLoadRom(DrvGfxROM1 + 0x00000, 8, 1)) return 1;
if (BurnLoadRom(DrvGfxROM1 + 0x80000, 9, 1)) return 1;
if (BurnLoadRom(DrvGfxROM2 + 0x00000, 10, 1)) return 1;
if (BurnLoadRom(DrvGfxROM3 + 0x00000, 11, 1)) return 1;
if (BurnLoadRom(DrvSndROM + 0x00000, 12, 1)) return 1;
DrvGfxDecode();
SekInit(0, 0x68000);
SekOpen(0);
SekMapMemory(Drv68KROM, 0x000000, 0x05ffff, SM_ROM);
SekMapMemory(Drv68KRAM, 0x060000, 0x06d7ff, SM_RAM);
SekMapMemory(DrvSprRAM, 0x06d800, 0x06dfff, SM_RAM);
SekMapMemory(DrvPalRAM, 0x06e000, 0x06e7ff, SM_ROM); // 4b4g4r handler
SekMapMemory(DrvBg1RAM, 0x06e800, 0x06efff, SM_RAM);
SekMapMemory(DrvBg2RAM, 0x06f000, 0x06f7ff, SM_RAM);
SekMapMemory(DrvFgRAM, 0x06f800, 0x06ffff, SM_RAM);
SekMapMemory(DrvScrollRAM, 0x0a0000, 0x0a0057, SM_ROM); // a03ff
SekSetWriteByteHandler(0, tokib_write_byte);
SekSetWriteWordHandler(0, tokib_write_word);
SekSetReadByteHandler(0, tokib_read_byte);
SekSetReadWordHandler(0, tokib_read_word);
SekClose();
seibu_sound_init(0, 0x2000, 3579545, 3579545, 1000000 / 132);
GenericTilesInit();
DrvDoReset();
return 0;
}
static INT32 JujubaInit()
{
is_bootleg = 0;
AllMem = NULL;
MemIndex();
INT32 nLen = MemEnd - (UINT8 *)0;
if ((AllMem = (UINT8 *)BurnMalloc(nLen)) == NULL) return 1;
memset(AllMem, 0, nLen);
MemIndex();
if (BurnLoadRom(Drv68KROM + 0x20001, 0, 2)) return 1;
if (BurnLoadRom(Drv68KROM + 0x20000, 1, 2)) return 1;
if (BurnLoadRom(Drv68KROM + 0x00001, 2, 2)) return 1;
if (BurnLoadRom(Drv68KROM + 0x00000, 3, 2)) return 1;
if (BurnLoadRom(Drv68KROM + 0x40001, 4, 2)) return 1;
if (BurnLoadRom(Drv68KROM + 0x40000, 5, 2)) return 1;
if (BurnLoadRom(DrvZ80ROM + 0x00000, 6, 1)) return 1;
if (BurnLoadRom(DrvZ80ROM + 0x10000, 7, 1)) return 1;
memcpy(DrvZ80ROM, DrvZ80ROM + 0x2000, 0x2000);
if (BurnLoadRom(DrvGfxROM0 + 0x00000, 8, 1)) return 1;
if (BurnLoadRom(DrvGfxROM0 + 0x10000, 9, 1)) return 1;
if (BurnLoadRom(DrvGfxROM1 + 0x00000, 10, 2)) return 1;
if (BurnLoadRom(DrvGfxROM1 + 0x00001, 11, 2)) return 1;
if (BurnLoadRom(DrvGfxROM1 + 0x40000, 12, 2)) return 1;
if (BurnLoadRom(DrvGfxROM1 + 0x40001, 13, 2)) return 1;
if (BurnLoadRom(DrvGfxROM1 + 0x80000, 14, 2)) return 1;
if (BurnLoadRom(DrvGfxROM1 + 0x80001, 15, 2)) return 1;
if (BurnLoadRom(DrvGfxROM1 + 0xc0000, 16, 2)) return 1;
if (BurnLoadRom(DrvGfxROM1 + 0xc0001, 17, 2)) return 1;
if (BurnLoadRom(DrvGfxROM2 + 0x00001, 18, 2)) return 1;
if (BurnLoadRom(DrvGfxROM2 + 0x20001, 19, 2)) return 1;
if (BurnLoadRom(DrvGfxROM2 + 0x40001, 20, 2)) return 1;
if (BurnLoadRom(DrvGfxROM2 + 0x60001, 21, 2)) return 1;
if (BurnLoadRom(DrvGfxROM2 + 0x00000, 22, 2)) return 1;
if (BurnLoadRom(DrvGfxROM2 + 0x20000, 23, 2)) return 1;
if (BurnLoadRom(DrvGfxROM2 + 0x40000, 24, 2)) return 1;
if (BurnLoadRom(DrvGfxROM2 + 0x60000, 25, 2)) return 1;
if (BurnLoadRom(DrvGfxROM3 + 0x00001, 26, 2)) return 1;
if (BurnLoadRom(DrvGfxROM3 + 0x20001, 27, 2)) return 1;
if (BurnLoadRom(DrvGfxROM3 + 0x40001, 28, 2)) return 1;
if (BurnLoadRom(DrvGfxROM3 + 0x60001, 29, 2)) return 1;
if (BurnLoadRom(DrvGfxROM3 + 0x00000, 30, 2)) return 1;
if (BurnLoadRom(DrvGfxROM3 + 0x20000, 31, 2)) return 1;
if (BurnLoadRom(DrvGfxROM3 + 0x40000, 32, 2)) return 1;
if (BurnLoadRom(DrvGfxROM3 + 0x60000, 33, 2)) return 1;
if (BurnLoadRom(DrvSndROM + 0x00000, 34, 1)) return 1;
if (BurnLoadRom(DrvSndROM + 0x10000, 35, 1)) return 1;
UINT16 *PrgRom = (UINT16*)Drv68KROM;
for (INT32 i = 0; i < 0x30000; i++) {
PrgRom[i] = BITSWAP16(PrgRom[i], 15, 12, 13, 14, 11, 10, 9, 8, 7, 6, 5, 3, 4, 2, 1, 0);
}
UINT8 *Decrypt = DrvZ80DecROM;
UINT8 *Rom = DrvZ80ROM;
memcpy(Decrypt, Rom, 0x2000);
for (INT32 i = 0;i < 0x2000; i++) {
UINT8 Src = Decrypt[i];
Rom[i] = Src ^ 0x55;
}
DrvGfxDecode();
UINT8 *Temp = (UINT8*)BurnMalloc(0x20000);
memcpy(Temp, DrvSndROM, 0x20000);
for (INT32 i = 0; i < 0x20000; i++ ) {
DrvSndROM[i] = Temp[BITSWAP24(i, 23, 22, 21, 20, 19, 18, 17, 16, 13, 14, 15, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)];
}
BurnFree(Temp);
SekInit(0, 0x68000);
SekOpen(0);
SekMapMemory(Drv68KROM, 0x000000, 0x05ffff, SM_ROM);
SekMapMemory(Drv68KRAM, 0x060000, 0x06d7ff, SM_RAM);
SekMapMemory(DrvSprRAM, 0x06d800, 0x06dfff, SM_RAM);
SekMapMemory(DrvPalRAM, 0x06e000, 0x06e7ff, SM_ROM); // 4b4g4r handler
SekMapMemory(DrvBg1RAM, 0x06e800, 0x06efff, SM_RAM);
SekMapMemory(DrvBg2RAM, 0x06f000, 0x06f7ff, SM_RAM);
SekMapMemory(DrvFgRAM, 0x06f800, 0x06ffff, SM_RAM);
SekMapMemory(DrvScrollRAM, 0x0a0000, 0x0a0057, SM_ROM); // a03ff
SekSetWriteByteHandler(0, tokib_write_byte);
SekSetWriteWordHandler(0, tokib_write_word);
SekSetReadByteHandler(0, tokib_read_byte);
SekSetReadWordHandler(0, tokib_read_word);
SekClose();
seibu_sound_init(0, 0x2000, 3579545, 3579545, 1000000 / 132);
ZetOpen(0);
ZetMapArea(0x0000, 0x1fff, 2, DrvZ80DecROM, DrvZ80ROM );
ZetClose();
GenericTilesInit();
DrvDoReset();
return 0;
}
inline static INT32 TokibSynchroniseStream(INT32 nSoundRate)
@ -993,301 +1000,19 @@ static INT32 TokibInit()
return 0;
}
static INT32 DrvGfxDecode()
{
INT32 Plane0[4] = { 4096*16*8+0, 4096*16*8+4, 0, 4 }; // char
INT32 Plane1[4] = { 2*4, 3*4, 0*4, 1*4 }; // spr, tile
INT32 XOffs0[8] = { 3, 2, 1, 0, 8+3, 8+2, 8+1, 8+0 }; // char
INT32 YOffs0[16] = { 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16 };
// tiles
INT32 XOffs1[16] = { 3, 2, 1, 0, 16+3, 16+2, 16+1, 16+0,
64*8+3, 64*8+2, 64*8+1, 64*8+0, 64*8+16+3, 64*8+16+2, 64*8+16+1, 64*8+16+0 };
INT32 YOffs1[32] = { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32,
8*32, 9*32, 10*32, 11*32, 12*32, 13*32, 14*32, 15*32 };
UINT8 *tmp = (UINT8*)BurnMalloc(0x100000);
if (tmp == NULL) {
return 1;
}
memcpy (tmp, DrvGfxROM0, 0x020000);
GfxDecode(4096, 4, 8, 8, Plane0, XOffs0, YOffs0, 0x080, tmp, DrvGfxROM0);
memcpy (tmp, DrvGfxROM1, 0x100000);
GfxDecode(8192, 4, 16, 16, Plane1, XOffs1, YOffs1, 0x400, tmp, DrvGfxROM1);
memcpy (tmp, DrvGfxROM2, 0x080000);
GfxDecode(4096, 4, 16, 16, Plane1, XOffs1, YOffs1, 0x400, tmp, DrvGfxROM2);
memcpy (tmp, DrvGfxROM3, 0x080000);
GfxDecode(4096, 4, 16, 16, Plane1, XOffs1, YOffs1, 0x400, tmp, DrvGfxROM3);
BurnFree (tmp);
return 0;
}
static UINT8 decrypt_data(INT32 a,INT32 src)
{
if ( BIT(a,9) & BIT(a,8)) src ^= 0x80;
if ( BIT(a,11) & BIT(a,4) & BIT(a,1)) src ^= 0x40;
if ( BIT(a,11) & ~BIT(a,8) & BIT(a,1)) src ^= 0x04;
if ( BIT(a,13) & ~BIT(a,6) & BIT(a,4)) src ^= 0x02;
if (~BIT(a,11) & BIT(a,9) & BIT(a,2)) src ^= 0x01;
if (BIT(a,13) & BIT(a,4)) src = BITSWAP08(src,7,6,5,4,3,2,0,1);
if (BIT(a, 8) & BIT(a,4)) src = BITSWAP08(src,7,6,5,4,2,3,1,0);
return src;
}
static UINT8 decrypt_opcode(INT32 a,INT32 src)
{
if ( BIT(a,9) & BIT(a,8)) src ^= 0x80;
if ( BIT(a,11) & BIT(a,4) & BIT(a,1)) src ^= 0x40;
if (~BIT(a,13) & BIT(a,12)) src ^= 0x20;
if (~BIT(a,6) & BIT(a,1)) src ^= 0x10;
if (~BIT(a,12) & BIT(a,2)) src ^= 0x08;
if ( BIT(a,11) & ~BIT(a,8) & BIT(a,1)) src ^= 0x04;
if ( BIT(a,13) & ~BIT(a,6) & BIT(a,4)) src ^= 0x02;
if (~BIT(a,11) & BIT(a,9) & BIT(a,2)) src ^= 0x01;
if (BIT(a,13) & BIT(a,4)) src = BITSWAP08(src,7,6,5,4,3,2,0,1);
if (BIT(a, 8) & BIT(a,4)) src = BITSWAP08(src,7,6,5,4,2,3,1,0);
if (BIT(a,12) & BIT(a,9)) src = BITSWAP08(src,7,6,4,5,3,2,1,0);
if (BIT(a,11) & ~BIT(a,6)) src = BITSWAP08(src,6,7,5,4,3,2,1,0);
return src;
}
static void seibu_sound_decrypt(INT32 length)
{
UINT8 *decrypt = DrvZ80DecROM;
UINT8 *rom = DrvZ80ROM;
INT32 i;
for (i = 0;i < length;i++)
{
UINT8 src = rom[i];
rom[i] = decrypt_data(i,src);
decrypt[i] = decrypt_opcode(i,src);
}
}
static INT32 DrvInit()
{
is_bootleg = 0;
AllMem = NULL;
MemIndex();
INT32 nLen = MemEnd - (UINT8 *)0;
if ((AllMem = (UINT8 *)BurnMalloc(nLen)) == NULL) return 1;
memset(AllMem, 0, nLen);
MemIndex();
if (BurnLoadRom(Drv68KROM + 0x00001, 0, 2)) return 1;
if (BurnLoadRom(Drv68KROM + 0x00000, 1, 2)) return 1;
if (BurnLoadRom(Drv68KROM + 0x40001, 2, 2)) return 1;
if (BurnLoadRom(Drv68KROM + 0x40000, 3, 2)) return 1;
if (BurnLoadRom(DrvZ80ROM + 0x00000, 4, 1)) return 1;
if (BurnLoadRom(DrvZ80ROM + 0x10000, 5, 1)) return 1;
if (BurnLoadRom(DrvGfxROM0 + 0x00000, 6, 1)) return 1;
if (BurnLoadRom(DrvGfxROM0 + 0x10000, 7, 1)) return 1;
if (BurnLoadRom(DrvGfxROM1 + 0x00000, 8, 1)) return 1;
if (BurnLoadRom(DrvGfxROM1 + 0x80000, 9, 1)) return 1;
if (BurnLoadRom(DrvGfxROM2 + 0x00000, 10, 1)) return 1;
if (BurnLoadRom(DrvGfxROM3 + 0x00000, 11, 1)) return 1;
if (BurnLoadRom(DrvSndROM + 0x00000, 12, 1)) return 1;
seibu_sound_decrypt(0x2000);
DrvGfxDecode();
SekInit(0, 0x68000);
SekOpen(0);
SekMapMemory(Drv68KROM, 0x000000, 0x05ffff, SM_ROM);
SekMapMemory(Drv68KRAM, 0x060000, 0x06d7ff, SM_RAM);
SekMapMemory(DrvSprRAM, 0x06d800, 0x06dfff, SM_RAM);
SekMapMemory(DrvPalRAM, 0x06e000, 0x06e7ff, SM_ROM); // 4b4g4r handler
SekMapMemory(DrvBg1RAM, 0x06e800, 0x06efff, SM_RAM);
SekMapMemory(DrvBg2RAM, 0x06f000, 0x06f7ff, SM_RAM);
SekMapMemory(DrvFgRAM, 0x06f800, 0x06ffff, SM_RAM);
SekMapMemory(DrvScrollRAM, 0x0a0000, 0x0a0057, SM_ROM); // a03ff
SekSetWriteByteHandler(0, tokib_write_byte);
SekSetWriteWordHandler(0, tokib_write_word);
SekSetReadByteHandler(0, tokib_read_byte);
SekSetReadWordHandler(0, tokib_read_word);
SekClose();
ZetInit(0);
ZetOpen(0);
ZetMapArea(0x0000, 0x1fff, 0, DrvZ80ROM);
ZetMapArea(0x0000, 0x1fff, 2, DrvZ80DecROM, DrvZ80ROM );
ZetMapArea(0x2000, 0x27ff, 0, DrvZ80RAM);
ZetMapArea(0x2000, 0x27ff, 1, DrvZ80RAM);
ZetMapArea(0x2000, 0x27ff, 2, DrvZ80RAM);
ZetSetWriteHandler(toki_seibu_sound_write);
ZetSetReadHandler(toki_seibu_sound_read);
ZetClose();
BurnYM3812Init(3579545, &DrvFMIRQHandler, &DrvSynchroniseStream, 0);
BurnTimerAttachZetYM3812(3579545);
BurnYM3812SetRoute(BURN_SND_YM3812_ROUTE, 1.00, BURN_SND_ROUTE_BOTH);
MSM6295Init(0, 1000000 / 132, 1);
MSM6295SetRoute(0, 0.40, BURN_SND_ROUTE_BOTH);
MSM6295ROM = DrvSndROM;
GenericTilesInit();
DrvDoReset();
return 0;
}
static INT32 JujubaInit()
{
is_bootleg = 0;
AllMem = NULL;
MemIndex();
INT32 nLen = MemEnd - (UINT8 *)0;
if ((AllMem = (UINT8 *)BurnMalloc(nLen)) == NULL) return 1;
memset(AllMem, 0, nLen);
MemIndex();
if (BurnLoadRom(Drv68KROM + 0x20001, 0, 2)) return 1;
if (BurnLoadRom(Drv68KROM + 0x20000, 1, 2)) return 1;
if (BurnLoadRom(Drv68KROM + 0x00001, 2, 2)) return 1;
if (BurnLoadRom(Drv68KROM + 0x00000, 3, 2)) return 1;
if (BurnLoadRom(Drv68KROM + 0x40001, 4, 2)) return 1;
if (BurnLoadRom(Drv68KROM + 0x40000, 5, 2)) return 1;
if (BurnLoadRom(DrvZ80ROM + 0x00000, 6, 1)) return 1;
if (BurnLoadRom(DrvZ80ROM + 0x10000, 7, 1)) return 1;
memcpy(DrvZ80ROM, DrvZ80ROM + 0x2000, 0x6000);
if (BurnLoadRom(DrvGfxROM0 + 0x00000, 8, 1)) return 1;
if (BurnLoadRom(DrvGfxROM0 + 0x10000, 9, 1)) return 1;
if (BurnLoadRom(DrvGfxROM1 + 0x00000, 10, 2)) return 1;
if (BurnLoadRom(DrvGfxROM1 + 0x00001, 11, 2)) return 1;
if (BurnLoadRom(DrvGfxROM1 + 0x40000, 12, 2)) return 1;
if (BurnLoadRom(DrvGfxROM1 + 0x40001, 13, 2)) return 1;
if (BurnLoadRom(DrvGfxROM1 + 0x80000, 14, 2)) return 1;
if (BurnLoadRom(DrvGfxROM1 + 0x80001, 15, 2)) return 1;
if (BurnLoadRom(DrvGfxROM1 + 0xc0000, 16, 2)) return 1;
if (BurnLoadRom(DrvGfxROM1 + 0xc0001, 17, 2)) return 1;
if (BurnLoadRom(DrvGfxROM2 + 0x00001, 18, 2)) return 1;
if (BurnLoadRom(DrvGfxROM2 + 0x20001, 19, 2)) return 1;
if (BurnLoadRom(DrvGfxROM2 + 0x40001, 20, 2)) return 1;
if (BurnLoadRom(DrvGfxROM2 + 0x60001, 21, 2)) return 1;
if (BurnLoadRom(DrvGfxROM2 + 0x00000, 22, 2)) return 1;
if (BurnLoadRom(DrvGfxROM2 + 0x20000, 23, 2)) return 1;
if (BurnLoadRom(DrvGfxROM2 + 0x40000, 24, 2)) return 1;
if (BurnLoadRom(DrvGfxROM2 + 0x60000, 25, 2)) return 1;
if (BurnLoadRom(DrvGfxROM3 + 0x00001, 26, 2)) return 1;
if (BurnLoadRom(DrvGfxROM3 + 0x20001, 27, 2)) return 1;
if (BurnLoadRom(DrvGfxROM3 + 0x40001, 28, 2)) return 1;
if (BurnLoadRom(DrvGfxROM3 + 0x60001, 29, 2)) return 1;
if (BurnLoadRom(DrvGfxROM3 + 0x00000, 30, 2)) return 1;
if (BurnLoadRom(DrvGfxROM3 + 0x20000, 31, 2)) return 1;
if (BurnLoadRom(DrvGfxROM3 + 0x40000, 32, 2)) return 1;
if (BurnLoadRom(DrvGfxROM3 + 0x60000, 33, 2)) return 1;
if (BurnLoadRom(DrvSndROM + 0x00000, 34, 1)) return 1;
if (BurnLoadRom(DrvSndROM + 0x10000, 35, 1)) return 1;
UINT16 *PrgRom = (UINT16*)Drv68KROM;
for (INT32 i = 0; i < 0x30000; i++) {
PrgRom[i] = BITSWAP16(PrgRom[i], 15, 12, 13, 14, 11, 10, 9, 8, 7, 6, 5, 3, 4, 2, 1, 0);
}
UINT8 *Decrypt = DrvZ80DecROM;
UINT8 *Rom = DrvZ80ROM;
memcpy(Decrypt, Rom, 0x2000);
for (INT32 i = 0;i < 0x2000; i++) {
UINT8 Src = Decrypt[i];
Rom[i] = Src ^ 0x55;
}
DrvGfxDecode();
UINT8 *Temp = (UINT8*)BurnMalloc(0x20000);
memcpy(Temp, DrvSndROM, 0x20000);
for (INT32 i = 0; i < 0x20000; i++ ) {
DrvSndROM[i] = Temp[BITSWAP24(i, 23, 22, 21, 20, 19, 18, 17, 16, 13, 14, 15, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)];
}
BurnFree(Temp);
SekInit(0, 0x68000);
SekOpen(0);
SekMapMemory(Drv68KROM, 0x000000, 0x05ffff, SM_ROM);
SekMapMemory(Drv68KRAM, 0x060000, 0x06d7ff, SM_RAM);
SekMapMemory(DrvSprRAM, 0x06d800, 0x06dfff, SM_RAM);
SekMapMemory(DrvPalRAM, 0x06e000, 0x06e7ff, SM_ROM); // 4b4g4r handler
SekMapMemory(DrvBg1RAM, 0x06e800, 0x06efff, SM_RAM);
SekMapMemory(DrvBg2RAM, 0x06f000, 0x06f7ff, SM_RAM);
SekMapMemory(DrvFgRAM, 0x06f800, 0x06ffff, SM_RAM);
SekMapMemory(DrvScrollRAM, 0x0a0000, 0x0a0057, SM_ROM); // a03ff
SekSetWriteByteHandler(0, tokib_write_byte);
SekSetWriteWordHandler(0, tokib_write_word);
SekSetReadByteHandler(0, tokib_read_byte);
SekSetReadWordHandler(0, tokib_read_word);
SekClose();
ZetInit(0);
ZetOpen(0);
ZetMapArea(0x0000, 0x1fff, 0, DrvZ80ROM);
ZetMapArea(0x0000, 0x1fff, 2, DrvZ80DecROM, DrvZ80ROM );
ZetMapArea(0x2000, 0x27ff, 0, DrvZ80RAM);
ZetMapArea(0x2000, 0x27ff, 1, DrvZ80RAM);
ZetMapArea(0x2000, 0x27ff, 2, DrvZ80RAM);
ZetSetWriteHandler(toki_seibu_sound_write);
ZetSetReadHandler(toki_seibu_sound_read);
ZetClose();
BurnYM3812Init(3579545, &DrvFMIRQHandler, &DrvSynchroniseStream, 0);
BurnTimerAttachZetYM3812(3579545);
BurnYM3812SetRoute(BURN_SND_YM3812_ROUTE, 1.00, BURN_SND_ROUTE_BOTH);
MSM6295Init(0, 1000000 / 132, 1);
MSM6295SetRoute(0, 0.60, BURN_SND_ROUTE_BOTH);
MSM6295ROM = DrvSndROM;
GenericTilesInit();
DrvDoReset();
return 0;
}
static INT32 DrvExit()
{
GenericTilesExit();
BurnYM3812Exit();
if (is_bootleg) {
BurnYM3812Exit();
MSM5205Exit();
ZetExit();
} else {
MSM6295Exit(0);
seibu_sound_exit();
}
SekExit();
ZetExit();
BurnFree (AllMem);
@ -1522,6 +1247,8 @@ void assemble_inputs(UINT16 in0base, UINT16 in1base)
DrvInps[0] ^= (DrvJoy1[i] & 1) << i;
DrvInps[1] ^= (DrvJoy2[i] & 1) << i;
}
seibu_coin_input = ((DrvJoy3[1]&1)<<1)|(DrvJoy3[0]&1);
}
static INT32 TokibFrame()
@ -1666,10 +1393,8 @@ static INT32 DrvFrame()
nCyclesTotal[1] = 3579545 / 60 ;
INT32 nCyclesDone[2] = { 0, 0 };
SekOpen(0);
ZetOpen(0);
//bprintf (PRINT_NORMAL, _T("before run\n"));
for (INT32 i = 0; i < nInterleave; i++)
{
@ -1689,26 +1414,20 @@ static INT32 DrvFrame()
BurnTimerEndFrameYM3812(nCyclesTotal[1]);
if (pBurnSoundOut) {
seibu_sound_update(pBurnSoundOut, nBurnSoundLen);
}
ZetClose();
SekClose();
//bprintf (PRINT_NORMAL, _T("before sprites\n"));
if (pBurnDraw) {
toki_draw_sprites();
draw_text_layer();
BurnTransferCopy(DrvPalette);
}
if (pBurnSoundOut) {
ZetOpen(0);
BurnYM3812Update(pBurnSoundOut, nBurnSoundLen);
ZetClose();
MSM6295Render(0, pBurnSoundOut, nBurnSoundLen);
}
memcpy (DrvSprBuf, DrvSprRAM, 0x800);
//bprintf (PRINT_NORMAL, _T("end\n"));
return 0;
}
@ -1730,21 +1449,16 @@ static INT32 DrvScan(INT32 nAction, INT32 *pnMin)
}
if (nAction & ACB_DRIVER_DATA) {
BurnYM3812Scan(nAction, pnMin);
if (is_bootleg) {
BurnYM3812Scan(nAction, pnMin);
MSM5205Scan(nAction, pnMin);
ZetScan(nAction);
} else {
MSM6295Scan(0, nAction);
seibu_sound_scan(pnMin, nAction);
}
SekScan(nAction);
ZetScan(nAction);
SCAN_VAR(main2sub);
SCAN_VAR(sub2main);
SCAN_VAR(main2sub_pending);
SCAN_VAR(sub2main_pending);
SCAN_VAR(is_bootleg);
SCAN_VAR(TokibMSM5205Next);
SCAN_VAR(TokibMSM5205Toggle);
@ -2055,11 +1769,11 @@ static struct BurnRomInfo jujubaRomDesc[] = {
STD_ROM_PICK(jujuba)
STD_ROM_FN(jujuba)
struct BurnDriver BurnDrvJujuba = {
struct BurnDriverD BurnDrvJujuba = {
"jujuba", "toki", NULL, NULL, "1989",
"JuJu Densetsu (Japan, bootleg)\0", NULL, "bootleg", "Miscellaneous",
NULL, NULL, NULL, NULL,
BDF_GAME_WORKING | BDF_CLONE, 2, HARDWARE_MISC_PRE90S, GBF_PLATFORM, 0,
BDF_CLONE, 2, HARDWARE_MISC_PRE90S, GBF_PLATFORM, 0,
NULL, jujubaRomInfo, jujubaRomName, NULL, NULL, TokiInputInfo, TokiDIPInfo,
JujubaInit, DrvExit, DrvFrame, DrvDraw, DrvScan, NULL, 0x400,
256, 224, 4, 3