From ecb080f0065539888e7bd65027442f42c2dc2f70 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Sun, 28 Aug 2022 09:06:57 +1000 Subject: bus/mononcol: Get rid of a pile of copy/pasted crud. --- src/devices/bus/mononcol/rom.cpp | 25 ++-- src/devices/bus/mononcol/rom.h | 23 +--- src/devices/bus/mononcol/slot.cpp | 106 +++++----------- src/devices/bus/mononcol/slot.h | 42 +------ src/devices/bus/psx/gamebooster.cpp | 40 +----- src/devices/bus/psx/gamebooster.h | 6 +- src/devices/bus/snes/sgb.cpp | 18 ++- src/devices/bus/snes/sgb.h | 2 - src/mame/mame.lst | 2 +- src/mame/mess.flt | 2 +- src/mame/misc/micom_mahjong.cpp | 236 ------------------------------------ src/mame/tvgames/micom_mahjong.cpp | 236 ++++++++++++++++++++++++++++++++++++ 12 files changed, 304 insertions(+), 434 deletions(-) delete mode 100644 src/mame/misc/micom_mahjong.cpp create mode 100644 src/mame/tvgames/micom_mahjong.cpp diff --git a/src/devices/bus/mononcol/rom.cpp b/src/devices/bus/mononcol/rom.cpp index 4bf78b9731d..d3e82f34d24 100644 --- a/src/devices/bus/mononcol/rom.cpp +++ b/src/devices/bus/mononcol/rom.cpp @@ -5,33 +5,34 @@ #include "rom.h" //------------------------------------------------- -// constructor +// device type definitions //------------------------------------------------- DEFINE_DEVICE_TYPE(MONONCOL_ROM_PLAIN, mononcol_rom_plain_device, "mononcol_rom_plain", "Monon Color ROM cartridge") -void mononcol_rom_device::device_start() -{ -} -mononcol_rom_device::mononcol_rom_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) - : device_t(mconfig, type, tag, owner, clock), device_mononcol_cart_interface(mconfig, *this) +//------------------------------------------------- +// constructor +//------------------------------------------------- + +mononcol_rom_plain_device::mononcol_rom_plain_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) + : mononcol_rom_plain_device(mconfig, MONONCOL_ROM_PLAIN, tag, owner, clock) { } mononcol_rom_plain_device::mononcol_rom_plain_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) - : mononcol_rom_device(mconfig, type, tag, owner, clock) + : device_t(mconfig, type, tag, owner, clock) + , device_mononcol_cart_interface(mconfig, *this) , m_spi(*this, "spi") { } -mononcol_rom_plain_device::mononcol_rom_plain_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) - : mononcol_rom_plain_device(mconfig, MONONCOL_ROM_PLAIN, tag, owner, clock) -{ -} - void mononcol_rom_plain_device::device_add_mconfig(machine_config &config) { GENERIC_SPI_FLASH(config, m_spi, 0); } + +void mononcol_rom_plain_device::device_start() +{ +} diff --git a/src/devices/bus/mononcol/rom.h b/src/devices/bus/mononcol/rom.h index 008e2d98988..b9693b54adb 100644 --- a/src/devices/bus/mononcol/rom.h +++ b/src/devices/bus/mononcol/rom.h @@ -9,22 +9,10 @@ #include "machine/generic_spi_flash.h" -// ======================> mononcol_rom_device - -class mononcol_rom_device : public device_t, public device_mononcol_cart_interface -{ -protected: - // construction/destruction - mononcol_rom_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock); - - // device-level overrides - virtual void device_start() override; -}; - // ======================> mononcol_rom_plain_device -class mononcol_rom_plain_device : public mononcol_rom_device +class mononcol_rom_plain_device : public device_t, public device_mononcol_cart_interface { public: // construction/destruction @@ -34,22 +22,23 @@ public: DECLARE_WRITE_LINE_MEMBER(dir_w) override { m_spi->dir_w(state); } void write(uint8_t data) override { m_spi->write(data); } void set_ready() override { m_spi->set_ready(); } - void set_spi_region(uint8_t* region) override { m_spi->set_rom_ptr(region); } - void set_spi_size(size_t size) override { m_spi->set_rom_size(size); } + void set_spi_region(uint8_t *region, size_t size) override { m_spi->set_rom_ptr(region); m_spi->set_rom_size(size); } protected: mononcol_rom_plain_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock); + // device_t implementation virtual void device_add_mconfig(machine_config &config) override; + virtual void device_start() override; private: required_device m_spi; }; -// device type definition -DECLARE_DEVICE_TYPE(MONONCOL_ROM_PLAIN, mononcol_rom_plain_device) +// device type declarations +DECLARE_DEVICE_TYPE(MONONCOL_ROM_PLAIN, mononcol_rom_plain_device) #endif // MAME_BUS_MONONCOL_ROM_H diff --git a/src/devices/bus/mononcol/slot.cpp b/src/devices/bus/mononcol/slot.cpp index 4fc194d6376..c0129f0f1cc 100644 --- a/src/devices/bus/mononcol/slot.cpp +++ b/src/devices/bus/mononcol/slot.cpp @@ -20,9 +20,7 @@ DEFINE_DEVICE_TYPE(MONONCOL_CARTSLOT, mononcol_cartslot_device, "mononcol_cartsl //************************************************************************** device_mononcol_cart_interface::device_mononcol_cart_interface(machine_config const &mconfig, device_t &device) : - device_interface(device, "genslot"), - m_rom(nullptr), - m_rom_size(0) + device_interface(device, "mononcart") { } @@ -30,29 +28,6 @@ device_mononcol_cart_interface::~device_mononcol_cart_interface() { } -void device_mononcol_cart_interface::rom_alloc(u32 size, int width, endianness_t endian) -{ - if (m_rom) - { - throw emu_fatalerror( - "%s: Request to allocate ROM when already allocated (allocated size %u, requested size %u)\n", - device().tag(), - m_rom_size, - size); - } - - std::string fulltag = device().subtag("^cart:rom"); - - device().logerror("Allocating %u byte ROM region with tag '%s' (width %d)\n", size, fulltag, width); - m_rom = device().machine().memory().region_alloc(fulltag, size, width, endian)->base(); - m_rom_size = size; - - if (!(m_rom_size && !(m_rom_size & (m_rom_size - 1)))) - { - fatalerror("m_rom_size is NOT a power of 2"); - } -} - //************************************************************************** @@ -61,7 +36,7 @@ void device_mononcol_cart_interface::rom_alloc(u32 size, int width, endianness_t mononcol_cartslot_device::mononcol_cartslot_device(machine_config const &mconfig, device_type type, char const *tag, device_t *owner, u32 clock) : device_t(mconfig, type, tag, owner, clock), - device_rom_image_interface(mconfig, *this), + device_cartrom_image_interface(mconfig, *this), device_single_card_slot_interface(mconfig, *this), m_cart(nullptr) { @@ -91,17 +66,34 @@ image_init_result mononcol_cartslot_device::call_load() { if (m_cart) { - u32 len = common_get_size("rom"); - - rom_alloc(len, 1, ENDIANNESS_LITTLE); - common_load_rom(get_rom_base(), len, "rom"); - - m_cart->set_spi_region(get_rom_base()); - m_cart->set_spi_size(get_rom_size()); - - return image_init_result::PASS; + memory_region *romregion(loaded_through_softlist() ? memregion("rom") : nullptr); + if (loaded_through_softlist() && !romregion) + { + seterror(image_error::INVALIDIMAGE, "Software list item has no 'rom' data area"); + return image_init_result::FAIL; + } + + const u32 len = loaded_through_softlist() ? get_software_region_length("rom") : length(); + if (!len || ((len - 1) & len)) + { + seterror(image_error::INVALIDIMAGE, "Cartridge ROM size is not a power of 2"); + return image_init_result::FAIL; + } + + if (!loaded_through_softlist()) + { + LOG("Allocating %u byte cartridge ROM region\n", len); + romregion = machine().memory().region_alloc(subtag("rom"), len, 4, ENDIANNESS_LITTLE); + const u32 cnt = fread(romregion->base(), len); + if (cnt != len) + { + seterror(image_error::UNSPECIFIED, "Error reading cartridge file"); + return image_init_result::FAIL; + } + } + + m_cart->set_spi_region(romregion->base(), romregion->bytes()); } - return image_init_result::PASS; } @@ -115,43 +107,3 @@ std::string mononcol_cartslot_device::get_default_card_software(get_default_card { return software_get_default_slot("rom"); } - - -/************************************************** - - Implementation - - **************************************************/ - - -/*------------------------------------------------- - common_get_size - it gets image file size both - for fullpath and for softlist - -------------------------------------------------*/ - -u32 mononcol_cartslot_device::common_get_size(char const *region) -{ - // if we are loading from softlist, you have to specify a region - assert(!loaded_through_softlist() || (region != nullptr)); - - return !loaded_through_softlist() ? length() : get_software_region_length(region); -} - -/*------------------------------------------------- - common_load_rom - it loads from image file both - for fullpath and for softlist - -------------------------------------------------*/ - -void mononcol_cartslot_device::common_load_rom(u8 *ROM, u32 len, char const *region) -{ - // basic sanity check - assert((ROM != nullptr) && (len > 0)); - - // if we are loading from softlist, you have to specify a region - assert(!loaded_through_softlist() || (region != nullptr)); - - if (!loaded_through_softlist()) - fread(ROM, len); - else - memcpy(ROM, get_software_region(region), len); -} diff --git a/src/devices/bus/mononcol/slot.h b/src/devices/bus/mononcol/slot.h index 43cd23709df..aa44b74b7a4 100644 --- a/src/devices/bus/mononcol/slot.h +++ b/src/devices/bus/mononcol/slot.h @@ -21,30 +21,21 @@ public: virtual ~device_mononcol_cart_interface(); // reading and writing - virtual void rom_alloc(u32 size, int width, endianness_t end); - - u8 *get_rom_base() { return m_rom; } - u32 get_rom_size() { return m_rom_size; } - virtual uint8_t read() = 0; virtual DECLARE_WRITE_LINE_MEMBER(dir_w) = 0; virtual void write(uint8_t data) = 0; virtual void set_ready() = 0; - virtual void set_spi_region(uint8_t* region) = 0; - virtual void set_spi_size(size_t size) = 0; + // configuration + virtual void set_spi_region(uint8_t *region, size_t size) = 0; protected: device_mononcol_cart_interface(machine_config const &mconfig, device_t &device); - - // internal state - u8 *m_rom; - u32 m_rom_size; }; class mononcol_cartslot_device : public device_t, - public device_rom_image_interface, + public device_cartrom_image_interface, public device_single_card_slot_interface { public: @@ -69,26 +60,6 @@ public: // slot interface overrides virtual std::string get_default_card_software(get_default_card_software_hook &hook) const override; - u32 common_get_size(char const *region); - void common_load_rom(u8 *ROM, u32 len, char const *region); - - virtual void rom_alloc(u32 size, int width, endianness_t end) { if (m_cart) m_cart->rom_alloc(size, width, end); } - - u8* get_rom_base() - { - if (!m_cart) - return nullptr; - - return m_cart->get_rom_base(); - } - u32 get_rom_size() - { - if (!m_cart) - return 0U; - - return m_cart->get_rom_size(); - } - uint8_t read() { return m_cart->read(); @@ -109,9 +80,6 @@ public: m_cart->write(data); } - void set_spi_region(uint8_t* region) { m_cart->set_spi_region(region); } - void set_spi_size(size_t size) { m_cart->set_spi_size(size); } - protected: mononcol_cartslot_device(machine_config const &mconfig, device_type type, char const *tag, device_t *owner, u32 clock); @@ -120,10 +88,6 @@ protected: virtual void device_start() override ATTR_COLD; device_mononcol_cart_interface *m_cart; - - virtual const char *image_type_name() const noexcept override { return "cartridge"; } - virtual const char *image_brief_type_name() const noexcept override { return "cart"; } - }; diff --git a/src/devices/bus/psx/gamebooster.cpp b/src/devices/bus/psx/gamebooster.cpp index 87dee3d9530..1d2f6529dca 100644 --- a/src/devices/bus/psx/gamebooster.cpp +++ b/src/devices/bus/psx/gamebooster.cpp @@ -11,8 +11,11 @@ #include "emu.h" #include "gamebooster.h" +#include "bus/gameboy/carts.h" + #include "softlist_dev.h" + //************************************************************************** // DEVICE DEFINITIONS //************************************************************************** @@ -119,43 +122,10 @@ void psx_gamebooster_device::exp_w(offs_t offset, uint16_t data, uint16_t mem_ma } } -static void gb_cart(device_slot_interface &device) -{ - device.option_add_internal("rom", GB_STD_ROM); - device.option_add_internal("rom_mbc1", GB_ROM_MBC1); - device.option_add_internal("rom_mbc1col", GB_ROM_MBC1); - device.option_add_internal("rom_mbc2", GB_ROM_MBC2); - device.option_add_internal("rom_mbc3", GB_ROM_MBC3); - device.option_add_internal("rom_huc1", GB_ROM_MBC3); - device.option_add_internal("rom_huc3", GB_ROM_MBC3); - device.option_add_internal("rom_mbc5", GB_ROM_MBC5); - device.option_add_internal("rom_mbc6", GB_ROM_MBC6); - device.option_add_internal("rom_mbc7", GB_ROM_MBC7); - device.option_add_internal("rom_tama5", GB_ROM_TAMA5); - device.option_add_internal("rom_mmm01", GB_ROM_MMM01); - device.option_add_internal("rom_m161", GB_ROM_M161); - device.option_add_internal("rom_sachen1", GB_ROM_SACHEN1); - device.option_add_internal("rom_sachen2", GB_ROM_SACHEN2); - device.option_add_internal("rom_wisdom", GB_ROM_WISDOM); - device.option_add_internal("rom_yong", GB_ROM_YONG); - device.option_add_internal("rom_lasama", GB_ROM_LASAMA); - device.option_add_internal("rom_atvrac", GB_ROM_ATVRAC); - device.option_add_internal("rom_camera", GB_STD_ROM); - device.option_add_internal("rom_188in1", GB_ROM_188IN1); - device.option_add_internal("rom_sintax", GB_ROM_SINTAX); - device.option_add_internal("rom_chong", GB_ROM_CHONGWU); - device.option_add_internal("rom_licheng", GB_ROM_LICHENG); - device.option_add_internal("rom_digimon", GB_ROM_DIGIMON); - device.option_add_internal("rom_rock8", GB_ROM_ROCKMAN8); - device.option_add_internal("rom_sm3sp", GB_ROM_SM3SP); -// device.option_add_internal("rom_dkong5", GB_ROM_DKONG5); -// device.option_add_internal("rom_unk01", GB_ROM_UNK01); -} - void psx_gamebooster_device::device_add_mconfig(machine_config &config) { - /* cartslot */ - GB_CART_SLOT(config, m_cartslot, gb_cart, nullptr); + // cartslot + GB_CART_SLOT(config, m_cartslot, gameboy_cartridges, nullptr); SOFTWARE_LIST(config, "cart_list").set_original("gameboy"); SOFTWARE_LIST(config, "gbc_list").set_compatible("gbcolor"); diff --git a/src/devices/bus/psx/gamebooster.h b/src/devices/bus/psx/gamebooster.h index 808f05061f0..e023c9983ad 100644 --- a/src/devices/bus/psx/gamebooster.h +++ b/src/devices/bus/psx/gamebooster.h @@ -6,10 +6,10 @@ #pragma once - #include "parallel.h" -#include "bus/gameboy/rom.h" -#include "bus/gameboy/mbc.h" + +#include "bus/gameboy/gb_slot.h" + //************************************************************************** // TYPE DEFINITIONS diff --git a/src/devices/bus/snes/sgb.cpp b/src/devices/bus/snes/sgb.cpp index 6c790a1c773..56da7025c66 100644 --- a/src/devices/bus/snes/sgb.cpp +++ b/src/devices/bus/snes/sgb.cpp @@ -15,6 +15,9 @@ #include "emu.h" #include "sgb.h" +#include "bus/gameboy/carts.h" + + //------------------------------------------------- // sns_rom_sgb_device - constructor //------------------------------------------------- @@ -23,8 +26,8 @@ DEFINE_DEVICE_TYPE(SNS_LOROM_SUPERGB, sns_rom_sgb1_device, "sns_rom_sgb", "SNE DEFINE_DEVICE_TYPE(SNS_LOROM_SUPERGB2, sns_rom_sgb2_device, "sns_rom_sgb2", "SNES Super Game Boy 2 Cart") -sns_rom_sgb_device::sns_rom_sgb_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) - : sns_rom_device(mconfig, type, tag, owner, clock), +sns_rom_sgb_device::sns_rom_sgb_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) : + sns_rom_device(mconfig, type, tag, owner, clock), m_sgb_cpu(*this, "sgb_cpu"), m_sgb_apu(*this, "sgb_apu"), m_sgb_ppu(*this, "sgb_ppu"), @@ -154,13 +157,6 @@ void sns_rom_sgb_device::gb_timer_callback(uint8_t data) } -static void supergb_cart(device_slot_interface &device) -{ - device.option_add_internal("rom", GB_STD_ROM); - device.option_add_internal("rom_mbc1", GB_ROM_MBC1); -} - - void sns_rom_sgb1_device::device_add_mconfig(machine_config &config) { LR35902(config, m_sgb_cpu, 4295454); /* 4.295454 MHz */ @@ -172,7 +168,7 @@ void sns_rom_sgb1_device::device_add_mconfig(machine_config &config) DMG_APU(config, m_sgb_apu, 4295454); - GB_CART_SLOT(config, m_cartslot, supergb_cart, nullptr); + GB_CART_SLOT(config, m_cartslot, gameboy_cartridges, nullptr); } @@ -199,7 +195,7 @@ void sns_rom_sgb2_device::device_add_mconfig(machine_config &config) DMG_APU(config, m_sgb_apu, XTAL(4'194'304)); - GB_CART_SLOT(config, m_cartslot, supergb_cart, nullptr); + GB_CART_SLOT(config, m_cartslot, gameboy_cartridges, nullptr); } diff --git a/src/devices/bus/snes/sgb.h b/src/devices/bus/snes/sgb.h index db6782ddb98..f73cc42cacb 100644 --- a/src/devices/bus/snes/sgb.h +++ b/src/devices/bus/snes/sgb.h @@ -10,8 +10,6 @@ #include "cpu/lr35902/lr35902.h" #include "bus/gameboy/gb_slot.h" -#include "bus/gameboy/rom.h" -#include "bus/gameboy/mbc.h" #include "video/gb_lcd.h" #include "sound/gb.h" diff --git a/src/mame/mame.lst b/src/mame/mame.lst index 5045c1dffc1..683fcc8cfeb 100644 --- a/src/mame/mame.lst +++ b/src/mame/mame.lst @@ -23764,7 +23764,7 @@ tankbatl // (c) 1992 Microprose Games Inc. @source:beehive/microb.cpp dm3270 // -@source:misc/micom_mahjong.cpp +@source:tvgames/micom_mahjong.cpp mmahjong @source:misc/microdar.cpp diff --git a/src/mame/mess.flt b/src/mame/mess.flt index 6048468830d..0833caea983 100644 --- a/src/mame/mess.flt +++ b/src/mame/mess.flt @@ -479,7 +479,6 @@ miltonbradley/vectrex.cpp mips/mips.cpp misc/3do.cpp misc/eva.cpp -misc/micom_mahjong.cpp misc/monon_color.cpp mit/tx0.cpp mits/altair.cpp @@ -1112,6 +1111,7 @@ tvgames/generalplus_gpl16250_spi_direct.cpp tvgames/generalplus_gpl162xx_lcdtype.cpp tvgames/generalplus_gpl32612.cpp tvgames/magiceyes_pollux_vr3520f.cpp +tvgames/micom_mahjong.cpp tvgames/monkey_king_3b.cpp tvgames/pubint_storyreader.cpp tvgames/spg110.cpp diff --git a/src/mame/misc/micom_mahjong.cpp b/src/mame/misc/micom_mahjong.cpp deleted file mode 100644 index a7d2566f5cc..00000000000 --- a/src/mame/misc/micom_mahjong.cpp +++ /dev/null @@ -1,236 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:hap -/****************************************************************************** - -マイコン麻雀 - Micom Mahjong, mail-order Mahjong console. - -Two models are known, a grey one and a white one, hardware is presumed to be -the same. It's not known who developed/manufactured it. Probably not the -mail order house, but they can be considered the publisher. - -The options at the start of the game: -Option 1: 1: 3 minutes play time, 2: 5 minutes -Option 2: 1: advanced difficulty, 2: beginner - -Hardware notes: -- PCB label: IFVC-3224A -- Zilog Z8400A or Sharp LH0080A, 11.0592MHz XTAL -- 16KB ROM (4*2732), 1KB RAM (2*MSM2114L) -- 2KB ROM (2716) for tiles, 1KB VRAM (2*MSM2114L), 1bpp video -- 1-bit sound - -TODO: -- video timing, maybe 11059200 / 2 / (262*352)? - -******************************************************************************/ - -#include "emu.h" -#include "cpu/z80/z80.h" -#include "sound/dac.h" - -#include "emupal.h" -#include "screen.h" -#include "speaker.h" -#include "tilemap.h" - - -namespace { - -class mmahjong_state : public driver_device -{ -public: - mmahjong_state(const machine_config &mconfig, device_type type, const char *tag) : - driver_device(mconfig, type, tag), - m_maincpu(*this, "maincpu"), - m_vram(*this, "vram"), - m_tilemap(*this, "tilemap"), - m_screen(*this, "screen"), - m_dac(*this, "dac"), - m_inputs(*this, "IN.%u", 0) - { } - - void mmahjong(machine_config &config); - -protected: - virtual void machine_start() override; - -private: - required_device m_maincpu; - required_shared_ptr m_vram; - required_device m_tilemap; - required_device m_screen; - required_device m_dac; - required_ioport_array<3> m_inputs; - - TILE_GET_INFO_MEMBER(get_tile_info) { tileinfo.set(0, m_vram[tile_index], 0, 0); } - u32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); - - void main_map(address_map &map); - - void vram_w(offs_t offset, u8 data); - void input_w(u8 data); - u8 input_r(); - void sound_w(u8 data); - - u8 m_inp_matrix = 0; -}; - -void mmahjong_state::machine_start() -{ - save_item(NAME(m_inp_matrix)); -} - - - -/****************************************************************************** - I/O -******************************************************************************/ - -u32 mmahjong_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) -{ - m_tilemap->draw(screen, bitmap, cliprect); - return 0; -} - -void mmahjong_state::vram_w(offs_t offset, u8 data) -{ - m_vram[offset] = data; - m_tilemap->mark_tile_dirty(offset); -} - -void mmahjong_state::input_w(u8 data) -{ - // d0-d2: input matrix - // d3 is also written, but unused - m_inp_matrix = ~data; -} - -u8 mmahjong_state::input_r() -{ - u8 data = 0; - - // read keypad - for (int i = 0; i < 3; i++) - if (BIT(m_inp_matrix, i)) - data |= m_inputs[i]->read(); - - return ~data; -} - -void mmahjong_state::sound_w(u8 data) -{ - // d0: speaker out - m_dac->write(data & 1); -} - - - -/****************************************************************************** - Address Maps -******************************************************************************/ - -void mmahjong_state::main_map(address_map &map) -{ - map(0x0000, 0x3fff).rom(); - map(0x5000, 0x53ff).ram(); - map(0x6000, 0x63ff).w(FUNC(mmahjong_state::vram_w)).share("vram"); - map(0x7001, 0x7001).r(FUNC(mmahjong_state::input_r)); - map(0x7002, 0x7002).w(FUNC(mmahjong_state::input_w)); - map(0x7004, 0x7004).w(FUNC(mmahjong_state::sound_w)); -} - - - -/****************************************************************************** - Input Ports -******************************************************************************/ - -static INPUT_PORTS_START( mmahjong ) - PORT_START("IN.0") - PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_MAHJONG_A) // 1 - PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_MAHJONG_B) // 2 - PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_MAHJONG_C) // 3 - PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_MAHJONG_D) // 4 - PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_MAHJONG_E) // 5 - PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_MAHJONG_F) // 6 - - PORT_START("IN.1") - PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_MAHJONG_G) // 7 - PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_MAHJONG_H) // 8 - PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_MAHJONG_I) // 9 - PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_MAHJONG_J) // 10 - PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_MAHJONG_K) // 11 - PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_MAHJONG_L) // 12 - - PORT_START("IN.2") - PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_MAHJONG_M) // 13 - PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_MAHJONG_N) // 0 (Tsumo) - PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_MAHJONG_PON) - PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_MAHJONG_CHI) - PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_MAHJONG_KAN) - PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_MAHJONG_REACH) - PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_MAHJONG_RON) -INPUT_PORTS_END - - - -/****************************************************************************** - Machine Configs -******************************************************************************/ - -static GFXDECODE_START( gfx_mmahjong ) - GFXDECODE_ENTRY( "tiles", 0, gfx_8x8x1, 0, 1 ) -GFXDECODE_END - -void mmahjong_state::mmahjong(machine_config &config) -{ - // basic machine hardware - Z80(config, m_maincpu, 11.0592_MHz_XTAL / 4); - m_maincpu->set_addrmap(AS_PROGRAM, &mmahjong_state::main_map); - - // video hardware - GFXDECODE(config, "gfxdecode", "palette", gfx_mmahjong); - - PALETTE(config, "palette", palette_device::MONOCHROME); - - TILEMAP(config, m_tilemap, "gfxdecode", 0, 8, 8, TILEMAP_SCAN_ROWS, 32, 32).set_info_callback(FUNC(mmahjong_state::get_tile_info)); - - SCREEN(config, m_screen, SCREEN_TYPE_RASTER); - m_screen->set_refresh_hz(60); - m_screen->set_size(8*32, 8*32); - m_screen->set_visarea(0, 8*32-1, 0, 8*24-1); - m_screen->set_screen_update(FUNC(mmahjong_state::screen_update)); - m_screen->set_palette("palette"); - - // sound hardware - SPEAKER(config, "speaker").front_center(); - DAC_1BIT(config, m_dac).add_route(ALL_OUTPUTS, "speaker", 0.25); -} - - - -/****************************************************************************** - ROM Definitions -******************************************************************************/ - -ROM_START( mmahjong ) - ROM_REGION( 0x4000, "maincpu", 0 ) - ROM_LOAD( "ms_1.10", 0x0000, 0x1000, CRC(a1607ac8) SHA1(4e0d7a0482c7619ef25b12a7e02f5d03bea8ce6f) ) - ROM_LOAD( "ms_2.9", 0x1000, 0x1000, CRC(cb1cab68) SHA1(88dc4808126528a269edf742062fa12e902be324) ) - ROM_LOAD( "ms_3.8", 0x2000, 0x1000, CRC(2fdd4f55) SHA1(a9246239144c41fd38bd42015552b5afab40e55a) ) - ROM_LOAD( "ms_4.7", 0x3000, 0x1000, CRC(cc550e36) SHA1(d66750ce6ddf6e4db4e5bd46a639494d8335a590) ) - - ROM_REGION( 0x800, "tiles", 0 ) - ROM_LOAD( "ms_a.2", 0x000, 0x800, CRC(d1dfe5c1) SHA1(5042b89555867db418f4aeef6b520619d8f533f2) ) -ROM_END - -} // anonymous namespace - - - -/****************************************************************************** - Drivers -******************************************************************************/ - -// YEAR NAME PARENT CMP MACHINE INPUT STATE INIT COMPANY, FULLNAME, FLAGS -CONS( 1982, mmahjong, 0, 0, mmahjong, mmahjong, mmahjong_state, empty_init, "Nippon Mail Service", "Micom Mahjong", MACHINE_SUPPORTS_SAVE ) diff --git a/src/mame/tvgames/micom_mahjong.cpp b/src/mame/tvgames/micom_mahjong.cpp new file mode 100644 index 00000000000..a7d2566f5cc --- /dev/null +++ b/src/mame/tvgames/micom_mahjong.cpp @@ -0,0 +1,236 @@ +// license:BSD-3-Clause +// copyright-holders:hap +/****************************************************************************** + +マイコン麻雀 - Micom Mahjong, mail-order Mahjong console. + +Two models are known, a grey one and a white one, hardware is presumed to be +the same. It's not known who developed/manufactured it. Probably not the +mail order house, but they can be considered the publisher. + +The options at the start of the game: +Option 1: 1: 3 minutes play time, 2: 5 minutes +Option 2: 1: advanced difficulty, 2: beginner + +Hardware notes: +- PCB label: IFVC-3224A +- Zilog Z8400A or Sharp LH0080A, 11.0592MHz XTAL +- 16KB ROM (4*2732), 1KB RAM (2*MSM2114L) +- 2KB ROM (2716) for tiles, 1KB VRAM (2*MSM2114L), 1bpp video +- 1-bit sound + +TODO: +- video timing, maybe 11059200 / 2 / (262*352)? + +******************************************************************************/ + +#include "emu.h" +#include "cpu/z80/z80.h" +#include "sound/dac.h" + +#include "emupal.h" +#include "screen.h" +#include "speaker.h" +#include "tilemap.h" + + +namespace { + +class mmahjong_state : public driver_device +{ +public: + mmahjong_state(const machine_config &mconfig, device_type type, const char *tag) : + driver_device(mconfig, type, tag), + m_maincpu(*this, "maincpu"), + m_vram(*this, "vram"), + m_tilemap(*this, "tilemap"), + m_screen(*this, "screen"), + m_dac(*this, "dac"), + m_inputs(*this, "IN.%u", 0) + { } + + void mmahjong(machine_config &config); + +protected: + virtual void machine_start() override; + +private: + required_device m_maincpu; + required_shared_ptr m_vram; + required_device m_tilemap; + required_device m_screen; + required_device m_dac; + required_ioport_array<3> m_inputs; + + TILE_GET_INFO_MEMBER(get_tile_info) { tileinfo.set(0, m_vram[tile_index], 0, 0); } + u32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); + + void main_map(address_map &map); + + void vram_w(offs_t offset, u8 data); + void input_w(u8 data); + u8 input_r(); + void sound_w(u8 data); + + u8 m_inp_matrix = 0; +}; + +void mmahjong_state::machine_start() +{ + save_item(NAME(m_inp_matrix)); +} + + + +/****************************************************************************** + I/O +******************************************************************************/ + +u32 mmahjong_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) +{ + m_tilemap->draw(screen, bitmap, cliprect); + return 0; +} + +void mmahjong_state::vram_w(offs_t offset, u8 data) +{ + m_vram[offset] = data; + m_tilemap->mark_tile_dirty(offset); +} + +void mmahjong_state::input_w(u8 data) +{ + // d0-d2: input matrix + // d3 is also written, but unused + m_inp_matrix = ~data; +} + +u8 mmahjong_state::input_r() +{ + u8 data = 0; + + // read keypad + for (int i = 0; i < 3; i++) + if (BIT(m_inp_matrix, i)) + data |= m_inputs[i]->read(); + + return ~data; +} + +void mmahjong_state::sound_w(u8 data) +{ + // d0: speaker out + m_dac->write(data & 1); +} + + + +/****************************************************************************** + Address Maps +******************************************************************************/ + +void mmahjong_state::main_map(address_map &map) +{ + map(0x0000, 0x3fff).rom(); + map(0x5000, 0x53ff).ram(); + map(0x6000, 0x63ff).w(FUNC(mmahjong_state::vram_w)).share("vram"); + map(0x7001, 0x7001).r(FUNC(mmahjong_state::input_r)); + map(0x7002, 0x7002).w(FUNC(mmahjong_state::input_w)); + map(0x7004, 0x7004).w(FUNC(mmahjong_state::sound_w)); +} + + + +/****************************************************************************** + Input Ports +******************************************************************************/ + +static INPUT_PORTS_START( mmahjong ) + PORT_START("IN.0") + PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_MAHJONG_A) // 1 + PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_MAHJONG_B) // 2 + PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_MAHJONG_C) // 3 + PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_MAHJONG_D) // 4 + PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_MAHJONG_E) // 5 + PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_MAHJONG_F) // 6 + + PORT_START("IN.1") + PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_MAHJONG_G) // 7 + PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_MAHJONG_H) // 8 + PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_MAHJONG_I) // 9 + PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_MAHJONG_J) // 10 + PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_MAHJONG_K) // 11 + PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_MAHJONG_L) // 12 + + PORT_START("IN.2") + PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_MAHJONG_M) // 13 + PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_MAHJONG_N) // 0 (Tsumo) + PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_MAHJONG_PON) + PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_MAHJONG_CHI) + PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_MAHJONG_KAN) + PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_MAHJONG_REACH) + PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_MAHJONG_RON) +INPUT_PORTS_END + + + +/****************************************************************************** + Machine Configs +******************************************************************************/ + +static GFXDECODE_START( gfx_mmahjong ) + GFXDECODE_ENTRY( "tiles", 0, gfx_8x8x1, 0, 1 ) +GFXDECODE_END + +void mmahjong_state::mmahjong(machine_config &config) +{ + // basic machine hardware + Z80(config, m_maincpu, 11.0592_MHz_XTAL / 4); + m_maincpu->set_addrmap(AS_PROGRAM, &mmahjong_state::main_map); + + // video hardware + GFXDECODE(config, "gfxdecode", "palette", gfx_mmahjong); + + PALETTE(config, "palette", palette_device::MONOCHROME); + + TILEMAP(config, m_tilemap, "gfxdecode", 0, 8, 8, TILEMAP_SCAN_ROWS, 32, 32).set_info_callback(FUNC(mmahjong_state::get_tile_info)); + + SCREEN(config, m_screen, SCREEN_TYPE_RASTER); + m_screen->set_refresh_hz(60); + m_screen->set_size(8*32, 8*32); + m_screen->set_visarea(0, 8*32-1, 0, 8*24-1); + m_screen->set_screen_update(FUNC(mmahjong_state::screen_update)); + m_screen->set_palette("palette"); + + // sound hardware + SPEAKER(config, "speaker").front_center(); + DAC_1BIT(config, m_dac).add_route(ALL_OUTPUTS, "speaker", 0.25); +} + + + +/****************************************************************************** + ROM Definitions +******************************************************************************/ + +ROM_START( mmahjong ) + ROM_REGION( 0x4000, "maincpu", 0 ) + ROM_LOAD( "ms_1.10", 0x0000, 0x1000, CRC(a1607ac8) SHA1(4e0d7a0482c7619ef25b12a7e02f5d03bea8ce6f) ) + ROM_LOAD( "ms_2.9", 0x1000, 0x1000, CRC(cb1cab68) SHA1(88dc4808126528a269edf742062fa12e902be324) ) + ROM_LOAD( "ms_3.8", 0x2000, 0x1000, CRC(2fdd4f55) SHA1(a9246239144c41fd38bd42015552b5afab40e55a) ) + ROM_LOAD( "ms_4.7", 0x3000, 0x1000, CRC(cc550e36) SHA1(d66750ce6ddf6e4db4e5bd46a639494d8335a590) ) + + ROM_REGION( 0x800, "tiles", 0 ) + ROM_LOAD( "ms_a.2", 0x000, 0x800, CRC(d1dfe5c1) SHA1(5042b89555867db418f4aeef6b520619d8f533f2) ) +ROM_END + +} // anonymous namespace + + + +/****************************************************************************** + Drivers +******************************************************************************/ + +// YEAR NAME PARENT CMP MACHINE INPUT STATE INIT COMPANY, FULLNAME, FLAGS +CONS( 1982, mmahjong, 0, 0, mmahjong, mmahjong, mmahjong_state, empty_init, "Nippon Mail Service", "Micom Mahjong", MACHINE_SUPPORTS_SAVE ) -- cgit v1.2.3