Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/mame/seibu/airraid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ Stephh's notes (based on the game Z80 code and some tests) :

#include "emu.h"
#include "airraid_dev.h"
#include "sei80bu.h"

#include "seibusound.h"

Expand Down Expand Up @@ -454,7 +455,7 @@ void airraid_state::airraid(machine_config &config)
m_seibu_sound->ym_read_callback().set("ymsnd", FUNC(ym2151_device::read));
m_seibu_sound->ym_write_callback().set("ymsnd", FUNC(ym2151_device::write));

SEI80BU(config, "sei80bu", 0).set_device_rom_tag("audiocpu");
SEI80BU(config, "sei80bu", XTAL(14'318'181) / 4).set_device_rom_tag("audiocpu");
}

void airraid_state::airraide(machine_config &config)
Expand Down
4 changes: 3 additions & 1 deletion src/mame/seibu/cabal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ TAD-8710-MAIN (I) J426

#include "emu.h"

#include "sei80bu.h"

#include "seibusound.h"

#include "cpu/m68000/m68000.h"
Expand Down Expand Up @@ -853,7 +855,7 @@ void cabal_state::cabal(machine_config &config)
m_audiocpu->set_addrmap(AS_OPCODES, &cabal_state::sound_decrypted_opcodes_map);
m_audiocpu->set_irq_acknowledge_callback("seibu_sound", FUNC(seibu_sound_device::im0_vector_cb));

SEI80BU(config, "sei80bu", 0).set_device_rom_tag("audiocpu");
SEI80BU(config, "sei80bu", XTAL(3'579'545)).set_device_rom_tag("audiocpu");

// video hardware
screen_device &screen(SCREEN(config, "screen", SCREEN_TYPE_RASTER));
Expand Down
4 changes: 3 additions & 1 deletion src/mame/seibu/deadang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Dip locations and factory settings verified with US manual

#include "emu.h"

#include "sei80bu.h"

#include "seibusound.h"

#include "cpu/nec/nec.h"
Expand Down Expand Up @@ -799,7 +801,7 @@ void deadang_state::deadang(machine_config &config)
m_audiocpu->set_addrmap(AS_OPCODES, &deadang_state::sound_decrypted_opcodes_map);
m_audiocpu->set_irq_acknowledge_callback("seibu_sound", FUNC(seibu_sound_device::im0_vector_cb));

SEI80BU(config, "sei80bu", 0).set_device_rom_tag("audiocpu");
SEI80BU(config, "sei80bu", XTAL(14'318'181) / 4).set_device_rom_tag("audiocpu");

config.set_maximum_quantum(attotime::from_hz(60)); // the game stops working with higher interleave rates..

Expand Down
4 changes: 3 additions & 1 deletion src/mame/seibu/dynduke.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@

#include "emu.h"

#include "sei80bu.h"

#include "seibusound.h"

#include "cpu/nec/nec.h"
Expand Down Expand Up @@ -638,7 +640,7 @@ void dynduke_state::dynduke(machine_config &config)
audiocpu.set_addrmap(AS_OPCODES, &dynduke_state::sound_decrypted_opcodes_map);
audiocpu.set_irq_acknowledge_callback("seibu_sound", FUNC(seibu_sound_device::im0_vector_cb));

sei80bu_device &sei80bu(SEI80BU(config, "sei80bu", 0));
sei80bu_device &sei80bu(SEI80BU(config, "sei80bu", 14.318181_MHz_XTAL / 4));
sei80bu.set_addrmap(AS_PROGRAM, &dynduke_state::sei80bu_encrypted_full_map);

config.set_maximum_quantum(attotime::from_hz(3600));
Expand Down
6 changes: 3 additions & 3 deletions src/mame/seibu/mustache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Measured freq:

#include "emu.h"

#include "seibusound.h" // for seibu_sound_decrypt on the MAIN cpu (not sound)
#include "sei80bu.h"
#include "t5182.h"

#include "cpu/z80/z80.h"
Expand Down Expand Up @@ -199,7 +199,7 @@ uint32_t mustache_state::screen_update(screen_device &screen, bitmap_ind16 &bitm
void mustache_state::memmap(address_map &map)
{
map(0x0000, 0x7fff).r("sei80bu", FUNC(sei80bu_device::data_r));
map(0x8000, 0xbfff).rom();
map(0x8000, 0xbfff).rom().region("maincpu", 0x8000);
map(0xc000, 0xcfff).ram().w(FUNC(mustache_state::videoram_w)).share(m_videoram);
map(0xd000, 0xd000).w("t5182", FUNC(t5182_device::sound_irq_w));
map(0xd001, 0xd001).r("t5182", FUNC(t5182_device::sharedram_semaphore_snd_r));
Expand Down Expand Up @@ -325,7 +325,7 @@ void mustache_state::mustache(machine_config &config)
m_maincpu->set_addrmap(AS_PROGRAM, &mustache_state::memmap);
m_maincpu->set_addrmap(AS_OPCODES, &mustache_state::decrypted_opcodes_map);

SEI80BU(config, "sei80bu", 0).set_device_rom_tag("maincpu");
SEI80BU(config, "sei80bu", 12_MHz_XTAL / 2).set_device_rom_tag("maincpu");

t5182_device &t5182(T5182(config, "t5182", 14.318181_MHz_XTAL / 4));
t5182.ym_read_callback().set("ymsnd", FUNC(ym2151_device::read));
Expand Down
4 changes: 3 additions & 1 deletion src/mame/seibu/raiden.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@

#include "emu.h"

#include "sei80bu.h"
#include "seibu_crtc.h"

#include "seibusound.h"

#include "cpu/nec/nec.h"
Expand Down Expand Up @@ -766,7 +768,7 @@ void raiden_state::raidene(machine_config &config)
subdevice<z80_device>("audiocpu")->set_addrmap(AS_PROGRAM, &raiden_state::raiden_sound_map);
subdevice<z80_device>("audiocpu")->set_addrmap(AS_OPCODES, &raiden_state::raiden_sound_decrypted_opcodes_map);

sei80bu_device &sei80bu(SEI80BU(config, "sei80bu", 0));
sei80bu_device &sei80bu(SEI80BU(config, "sei80bu", 14.318181_MHz_XTAL / 4));
sei80bu.set_addrmap(AS_PROGRAM, &raiden_state::sei80bu_encrypted_full_map);
}

Expand Down
91 changes: 91 additions & 0 deletions src/mame/seibu/sei80bu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// license:BSD-3-Clause
// copyright-holders:Bryan McPhail, R. Belmont
/***************************************************************************

SEI80BU Z80 ROM decryptor

Its clock is synced to Z80 CPU that has encrypted ROM, and
has separated opcode/data decryption method determined by M1 signal.

Mainly used for decrypt sound Z80 ROM, but seibu/mustache.cpp is
used it for decrypt main Z80 ROM.

***************************************************************************/

#include "emu.h"
#include "sei80bu.h"


/*
Games using encrypted sound cpu:

Air Raid 1987 "START UP PROGRAM V1.02 (C)1986 SEIBU KAIHATSU INC."
Cabal 1988 "Michel/Seibu sound 11/04/88"
Dead Angle 1988? "START UP PROGRAM V1.02 (C)1986 SEIBU KAIHATSU INC."
Dynamite Duke 1989 "START UP PROGRAM V1.02 (C)1986 SEIBU KAIHATSU INC."
Toki 1989 "START UP PROGRAM V1.02 (C)1986 SEIBU KAIHATSU INC."
Raiden (alt) 1990 "START UP PROGRAM V1.02 (C)1986 SEIBU KAIHATSU INC."

raiden and the decrypted raidena are not identical, there are vast sections of different data.
However, there are a few different bytes in the middle of identical data, suggesting a possible
error in the decryption scheme: they all require an additional XOR with 0x20 and are located at
similar addresses.
00002422: 03 23
000024A1: 00 20
000024A2: 09 29
00002822: 48 68
000028A1: 06 26
00002A21: 17 37
00002A22: 00 20
00002AA1: 12 32
00002C21: 02 22
00002CA1: 02 22
00002CA2: 17 37
*/

DEFINE_DEVICE_TYPE(SEI80BU, sei80bu_device, "sei80bu", "SEI80BU Encrypted Z80 Interface")

sei80bu_device::sei80bu_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
: device_t(mconfig, SEI80BU, tag, owner, clock)
, device_rom_interface(mconfig, *this)
{
}

u8 sei80bu_device::data_r(offs_t offset)
{
u16 const a = offset;
u8 src = read_byte(offset);

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 = bitswap<8>(src,7,6,5,4,3,2,0,1);
if (BIT(a, 8) & BIT(a,4)) src = bitswap<8>(src,7,6,5,4,2,3,1,0);

return src;
}

u8 sei80bu_device::opcode_r(offs_t offset)
{
u16 const a = offset;
u8 src = read_byte(offset);

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 = bitswap<8>(src,7,6,5,4,3,2,0,1);
if (BIT(a, 8) & BIT(a,4)) src = bitswap<8>(src,7,6,5,4,2,3,1,0);
if (BIT(a,12) & BIT(a,9)) src = bitswap<8>(src,7,6,4,5,3,2,1,0);
if (BIT(a,11) & ~BIT(a,6)) src = bitswap<8>(src,6,7,5,4,3,2,1,0);

return src;
}
31 changes: 31 additions & 0 deletions src/mame/seibu/sei80bu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// license:BSD-3-Clause
// copyright-holders:Bryan McPhail, R. Belmont
/***************************************************************************

SEI80BU Z80 ROM decryptor

***************************************************************************/
#ifndef MAME_SEIBU_SEI80BU_H
#define MAME_SEIBU_SEI80BU_H

#pragma once

#include "dirom.h"


class sei80bu_device : public device_t, public device_rom_interface<16>
{
public:
sei80bu_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock);

u8 data_r(offs_t offset);
u8 opcode_r(offs_t offset);

protected:
// device-level overrides
virtual void device_start() override { }
};

DECLARE_DEVICE_TYPE(SEI80BU, sei80bu_device)

#endif // MAME_SEIBU_SEI80BU_H
4 changes: 3 additions & 1 deletion src/mame/seibu/toki.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ TOKI-TM 1989 TAD CORPORATION

#include "emu.h"

#include "sei80bu.h"

#include "seibusound.h"

#include "cpu/m68000/m68000.h"
Expand Down Expand Up @@ -893,7 +895,7 @@ void toki_state::toki(machine_config &config)
m_audiocpu->set_addrmap(AS_OPCODES, &toki_state::toki_audio_opcodes_map);
m_audiocpu->set_irq_acknowledge_callback("seibu_sound", FUNC(seibu_sound_device::im0_vector_cb));

SEI80BU(config, "sei80bu", 0).set_device_rom_tag("audiocpu");
SEI80BU(config, "sei80bu", XTAL(14'318'181) / 4).set_device_rom_tag("audiocpu");

// video hardware
BUFFERED_SPRITERAM16(config, m_spriteram);
Expand Down
78 changes: 17 additions & 61 deletions src/mame/shared/seibusound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,21 @@
DEFINE_DEVICE_TYPE(SEIBU_SOUND, seibu_sound_device, "seibu_sound", "Seibu Sound System")

seibu_sound_device::seibu_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
: device_t(mconfig, SEIBU_SOUND, tag, owner, clock),
m_int_cb(*this),
m_coin_io_cb(*this, 0),
m_ym_read_cb(*this, 0),
m_ym_write_cb(*this),
m_sound_rom(*this, finder_base::DUMMY_TAG),
m_rom_bank(*this, finder_base::DUMMY_TAG),
m_main2sub_pending(false),
m_sub2main_pending(false),
m_rst10_irq(false),
m_rst18_irq(false),
m_rst10_service(false),
m_rst18_service(false)
: device_t(mconfig, SEIBU_SOUND, tag, owner, clock)
, m_int_cb(*this)
, m_coin_io_cb(*this, 0)
, m_ym_read_cb(*this, 0)
, m_ym_write_cb(*this)
, m_sound_rom(*this, finder_base::DUMMY_TAG)
, m_rom_bank(*this, finder_base::DUMMY_TAG)
, m_main2sub{0}
, m_sub2main{0}
, m_main2sub_pending(false)
, m_sub2main_pending(false)
, m_rst10_irq(false)
, m_rst18_irq(false)
, m_rst10_service(false)
, m_rst18_service(false)
{
}

Expand All @@ -105,7 +107,8 @@ void seibu_sound_device::device_start()

/* Denjin Makai definitely needs this at start-up, it never writes to the bankswitch */
m_rom_bank->set_entry(0);
} else
}
else
m_rom_bank->set_base(&m_sound_rom[0x8000]);
}

Expand Down Expand Up @@ -348,53 +351,6 @@ void seibu_sound_common::seibu_sound_map(address_map &map)

/***************************************************************************/

DEFINE_DEVICE_TYPE(SEI80BU, sei80bu_device, "sei80bu", "SEI80BU Encrypted Z80 Interface")

sei80bu_device::sei80bu_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
: device_t(mconfig, SEI80BU, tag, owner, clock),
device_rom_interface(mconfig, *this)
{
}

u8 sei80bu_device::data_r(offs_t offset)
{
u16 const a = offset;
u8 src = read_byte(offset);

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 = bitswap<8>(src,7,6,5,4,3,2,0,1);
if (BIT(a, 8) & BIT(a,4)) src = bitswap<8>(src,7,6,5,4,2,3,1,0);

return src;
}

u8 sei80bu_device::opcode_r(offs_t offset)
{
u16 const a = offset;
u8 src = read_byte(offset);

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 = bitswap<8>(src,7,6,5,4,3,2,0,1);
if (BIT(a, 8) & BIT(a,4)) src = bitswap<8>(src,7,6,5,4,2,3,1,0);
if (BIT(a,12) & BIT(a,9)) src = bitswap<8>(src,7,6,4,5,3,2,1,0);
if (BIT(a,11) & ~BIT(a,6)) src = bitswap<8>(src,6,7,5,4,3,2,1,0);

return src;
}

/***************************************************************************
Seibu ADPCM device
(MSM5205 with interface to sample ROM provided by YM3931)
Expand Down
Loading
Loading