msx/msx.cpp: Merged msx_m.cpp and msx.h into msx.cpp and minor cleanups. (#10193)

This commit is contained in:
wilbertpol 2022-08-08 21:11:31 +02:00 committed by GitHub
parent 10a34202ee
commit 4d3305cb73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2647 additions and 3224 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,516 +0,0 @@
// license:BSD-3-Clause
// copyright-holders:Wilbert Pol
/*****************************************************************************
*
* includes/msx.h
*
****************************************************************************/
#ifndef MAME_INCLUDES_MSX_H
#define MAME_INCLUDES_MSX_H
#include "cpu/z80/z80.h"
#include "machine/i8255.h"
#include "machine/rp5c01.h"
#include "machine/buffer.h"
#include "machine/input_merger.h"
#include "bus/centronics/ctronics.h"
#include "sound/ay8910.h"
#include "sound/dac.h"
#include "sound/ymopl.h"
#include "video/v9938.h"
#include "video/tms9928a.h"
#include "imagedev/cassette.h"
#include "formats/fmsx_cas.h"
#include "formats/msx_dsk.h"
#include "hashfile.h"
#include "machine/wd_fdc.h"
#include "imagedev/floppy.h"
#include "bus/msx_slot/slot.h"
#include "bus/msx_slot/rom.h"
#include "bus/msx_slot/ram.h"
#include "bus/msx_slot/cartridge.h"
#include "bus/msx_slot/ram_mm.h"
#include "bus/msx_slot/disk.h"
#include "bus/msx_slot/music.h"
#include "bus/msx_slot/bunsetsu.h"
#include "bus/msx_slot/fs4600.h"
#include "bus/msx_slot/panasonic08.h"
#include "bus/msx_slot/sony08.h"
#include "msx_switched.h"
#define TC8521_TAG "rtc"
class msx_state : public driver_device
{
public:
msx_state(const machine_config &mconfig, device_type type, const char *tag)
: driver_device(mconfig, type, tag)
, m_maincpu(*this, "maincpu")
, m_cassette(*this, "cassette")
, m_ay8910(*this, "ay8910")
, m_dac(*this, "dac")
, m_region_maincpu(*this, "maincpu")
, m_region_kanji(*this, "kanji")
, m_io_joy(*this, "JOY%u", 0U)
, m_io_dsw(*this, "DSW")
, m_io_mouse(*this, "MOUSE%u", 0U)
, m_io_key(*this, "KEY%u", 0U)
, m_leds(*this, "led%u", 1U)
, m_psg_b(0)
, m_kanji_latch(0)
, m_empty_slot(mconfig, *this)
, m_primary_slot(0)
, m_port_c_old(0)
, m_keylatch(0)
{
for (int prim = 0; prim < 4; prim++ )
{
m_slot_expanded[prim] = false;
m_secondary_slot[prim] = 0;
for (int sec = 0; sec < 4; sec++ )
{
for (int page = 0; page < 4; page++ )
{
m_all_slots[prim][sec][page] = nullptr;
}
}
}
m_mouse[0] = m_mouse[1] = 0;
m_mouse_stat[0] = m_mouse_stat[1] = 0;
m_empty_slot.set_memory_space(m_maincpu, AS_PROGRAM);
m_empty_slot.set_io_space(m_maincpu, AS_IO);
}
void hc6(machine_config &config);
void hb75d(machine_config &config);
void dpc100(machine_config &config);
void hb55p(machine_config &config);
void hotbi13p(machine_config &config);
void fspc800(machine_config &config);
void mpc200(machine_config &config);
void hb201p(machine_config &config);
void hx22i(machine_config &config);
void svi738dk(machine_config &config);
void gfc1080a(machine_config &config);
void svi738pl(machine_config &config);
void hx10dp(machine_config &config);
void perfect1(machine_config &config);
void mlf110(machine_config &config);
void cf1200(machine_config &config);
void hx20(machine_config &config);
void cf3000(machine_config &config);
void mpc100(machine_config &config);
void vg8020f(machine_config &config);
void hx10f(machine_config &config);
void cf2000(machine_config &config);
void expertpl(machine_config &config);
void fs4000a(machine_config &config);
void mpc10(machine_config &config);
void pv16(machine_config &config);
void jvchc7gb(machine_config &config);
void phc28(machine_config &config);
void hx10sa(machine_config &config);
void cx5m128(machine_config &config);
void expert10(machine_config &config);
void mbh50(machine_config &config);
void hc7(machine_config &config);
void gfc1080(machine_config &config);
void cpc51(machine_config &config);
void ax150(machine_config &config);
void phc28s(machine_config &config);
void mlfx1(machine_config &config);
void tadpc200(machine_config &config);
void gsfc200(machine_config &config);
void hx10d(machine_config &config);
void expertdp(machine_config &config);
void yis303(machine_config &config);
void canonv25(machine_config &config);
void svi738sp(machine_config &config);
void fmx(machine_config &config);
void phc2(machine_config &config);
void pv7(machine_config &config);
void hx10(machine_config &config);
void mlf48(machine_config &config);
void cpc50b(machine_config &config);
void hb10p(machine_config &config);
void hx20i(machine_config &config);
void mx10(machine_config &config);
void mx15(machine_config &config);
void expert13(machine_config &config);
void bruc100(machine_config &config);
void hx21(machine_config &config);
void cf3300(machine_config &config);
void cx5f1(machine_config &config);
void hx10e(machine_config &config);
void dpc200(machine_config &config);
void svi738(machine_config &config);
void dpc200e(machine_config &config);
void canonv10(machine_config &config);
void yis503(machine_config &config);
void mpc200sp(machine_config &config);
void svi738sw(machine_config &config);
void vg8010f(machine_config &config);
void dpc180(machine_config &config);
void mlf120(machine_config &config);
void hb201(machine_config &config);
void piopxv60(machine_config &config);
void hb10(machine_config &config);
void hb501p(machine_config &config);
void cx5m(machine_config &config);
void mx101(machine_config &config);
void mx64(machine_config &config);
void hb55d(machine_config &config);
void nms801(machine_config &config);
void svi728(machine_config &config);
void hotbi13b(machine_config &config);
void hotbit12(machine_config &config);
void hotbit11(machine_config &config);
void vg8010(machine_config &config);
void cf2700(machine_config &config);
void hx21i(machine_config &config);
void mbh2(machine_config &config);
void cx5f(machine_config &config);
void mpc64(machine_config &config);
void yc64(machine_config &config);
void yis503m(machine_config &config);
void gsfc80u(machine_config &config);
void cf2700g(machine_config &config);
void ax170(machine_config &config);
void y503iir(machine_config &config);
void svi738ar(machine_config &config);
void yis503ii(machine_config &config);
void yis503f(machine_config &config);
void cx5m2(machine_config &config);
void spc800(machine_config &config);
void canonv20(machine_config &config);
void hb20p(machine_config &config);
void mbh25(machine_config &config);
void fs4000(machine_config &config);
void hx10s(machine_config &config);
void piopx7uk(machine_config &config);
void hc5(machine_config &config);
void dgnmsx(machine_config &config);
void fdpc200(machine_config &config);
void hx22(machine_config &config);
void fs1300(machine_config &config);
void phc28l(machine_config &config);
void hb101p(machine_config &config);
void expert11(machine_config &config);
void vg802020(machine_config &config);
void tadpc20a(machine_config &config);
void hb75p(machine_config &config);
void piopx7(machine_config &config);
void canonv8(machine_config &config);
void cpc88(machine_config &config);
void vg802000(machine_config &config);
void mlf80(machine_config &config);
void cpc50a(machine_config &config);
void hb701fd(machine_config &config);
void vg8000(machine_config &config);
void hb55(machine_config &config);
void y503iir2(machine_config &config);
void fpc500(machine_config &config);
protected:
void msx(machine_config &config);
template<typename VDPType> void msx1(VDPType &vdp_type, machine_config &config);
void msx1_cartlist(machine_config &config);
void msx1_floplist(machine_config &config);
void msx_fd1793(machine_config &config);
void msx_wd2793_force_ready(machine_config &config);
void msx_wd2793(machine_config &config);
void msx_mb8877a(machine_config &config);
void msx_tc8566af(machine_config &config);
void msx_microsol(machine_config &config);
void msx_1_35_ssdd_drive(machine_config &config);
void msx_1_35_dd_drive(machine_config &config);
void msx_2_35_dd_drive(machine_config &config);
// static configuration helpers
void install_slot_pages(uint8_t prim, uint8_t sec, uint8_t page, uint8_t numpages, msx_internal_slot_interface &device);
template <typename T, typename U>
auto &add_internal_slot(machine_config &config, T &&type, U &&tag, uint8_t prim, uint8_t sec, uint8_t page, uint8_t numpages)
{
auto &device(std::forward<T>(type)(config, std::forward<U>(tag), 0U));
device.set_memory_space(m_maincpu, AS_PROGRAM);
device.set_io_space(m_maincpu, AS_IO);
device.set_start_address(page * 0x4000);
device.set_size(numpages * 0x4000);
install_slot_pages(prim, sec, page, numpages, device);
return device;
}
template <typename T, typename U>
auto &add_internal_slot(machine_config &config, T &&type, U &&tag, uint8_t prim, uint8_t sec, uint8_t page, uint8_t numpages, const char *region, uint32_t offset)
{
auto &device(std::forward<T>(type)(config, std::forward<U>(tag), 0U));
device.set_memory_space(m_maincpu, AS_PROGRAM);
device.set_io_space(m_maincpu, AS_IO);
device.set_start_address(page * 0x4000);
device.set_size(numpages * 0x4000);
device.set_rom_start(region, offset);
install_slot_pages(prim, sec, page, numpages, device);
return device;
}
template <typename T, typename U>
auto &add_internal_slot_mirrored(machine_config &config, T &&type, U &&tag, uint8_t prim, uint8_t sec, uint8_t page, uint8_t numpages, const char *region, uint32_t offset)
{
// Memory mapped FDC registers are also accessible through page 2
auto &device(type(config, std::forward<U>(tag), 0U));
device.set_memory_space(m_maincpu, AS_PROGRAM);
device.set_io_space(m_maincpu, AS_IO);
device.set_start_address(page * 0x4000);
device.set_size(0x4000);
device.set_rom_start(region, offset);
install_slot_pages(prim, sec, page, numpages, device);
return device;
}
template <int N, typename T, typename U, typename V>
auto &add_cartridge_slot(machine_config &config, T &&type, U &&tag, uint8_t prim, uint8_t sec, V &&intf, const char *deft)
{
auto &device(type(config, std::forward<U>(tag), 0U));
device.set_memory_space(m_maincpu, AS_PROGRAM);
device.set_io_space(m_maincpu, AS_IO);
device.option_reset();
intf(device);
device.set_default_option(deft);
device.set_fixed(false);
device.irq_handler().set("mainirq", FUNC(input_merger_device::in_w<N>));
install_slot_pages(prim, sec, 0, 4, device);
return device;
}
virtual void driver_start() override;
virtual void machine_start() override;
virtual void machine_reset() override;
virtual void device_post_load() override;
void msx_sec_slot_w(uint8_t data);
uint8_t msx_sec_slot_r();
uint8_t msx_kanji_r(offs_t offset);
void msx_kanji_w(offs_t offset, uint8_t data);
void msx_ppi_port_a_w(uint8_t data);
void msx_ppi_port_c_w(uint8_t data);
uint8_t msx_ppi_port_b_r();
uint8_t msx_mem_read(offs_t offset);
void msx_mem_write(offs_t offset, uint8_t data);
uint8_t msx_psg_port_a_r();
uint8_t msx_psg_port_b_r();
void msx_psg_port_a_w(uint8_t data);
void msx_psg_port_b_w(uint8_t data);
private:
void msx_memory_map_all();
void msx_memory_map_page(uint8_t page);
void msx_memory_reset();
void msx_memory_init();
static void floppy_formats(format_registration &fr);
INTERRUPT_GEN_MEMBER(msx_interrupt);
protected:
void msx_io_map(address_map &map);
void msx_memory_map(address_map &map);
required_device<z80_device> m_maincpu;
required_device<cassette_image_device> m_cassette;
required_device<ay8910_device> m_ay8910;
required_device<dac_bit_interface> m_dac;
required_memory_region m_region_maincpu;
optional_memory_region m_region_kanji;
required_ioport_array<2> m_io_joy;
required_ioport m_io_dsw;
required_ioport_array<2> m_io_mouse;
required_ioport_array<6> m_io_key;
output_finder<2> m_leds;
private:
/* PSG */
int m_psg_b = 0;
/* mouse */
uint16_t m_mouse[2]{};
int m_mouse_stat[2]{};
/* kanji */
int m_kanji_latch = 0;
/* memory */
msx_internal_slot_interface m_empty_slot;
msx_internal_slot_interface *m_all_slots[4][4][4]{};
msx_internal_slot_interface *m_current_page[4]{};
bool m_slot_expanded[4]{};
uint8_t m_primary_slot = 0;
uint8_t m_secondary_slot[4]{};
int m_port_c_old = 0;
int m_keylatch = 0;
};
class msx2_state : public msx_state
{
public:
msx2_state(const machine_config &mconfig, device_type type, const char *tag)
: msx_state(mconfig, type, tag)
, m_v9938(*this, "v9938")
, m_v9958(*this, "v9958")
, m_rtc(*this, TC8521_TAG)
, m_rtc_latch(0)
{
}
void ax350(machine_config &config);
void ax370(machine_config &config);
void canonv25(machine_config &config);
void canonv30(machine_config &config);
void canonv30f(machine_config &config);
void cpc300(machine_config &config);
void cpc300e(machine_config &config);
void cpc330k(machine_config &config);
void cpc400(machine_config &config);
void cpc400s(machine_config &config);
void cpc61(machine_config &config);
void cpg120(machine_config &config);
void fpc900(machine_config &config);
void expert20(machine_config &config);
void mbh70(machine_config &config);
void kmc5000(machine_config &config);
void mlg1(machine_config &config);
void mlg3(machine_config &config);
void mlg10(machine_config &config);
void mlg30(machine_config &config);
void fs4500(machine_config &config);
void fs4600(machine_config &config);
void fs4700(machine_config &config);
void fs5000(machine_config &config);
void fs5500f1(machine_config &config);
void fs5500f2(machine_config &config);
void fsa1(machine_config &config);
void fsa1a(machine_config &config);
void fsa1f(machine_config &config);
void fsa1fm(machine_config &config);
void fsa1mk2(machine_config &config);
void nms8220(machine_config &config);
void nms8220a(machine_config &config);
void nms8245(machine_config &config);
void nms8245f(machine_config &config);
void nms8250(machine_config &config);
void nms8250f(machine_config &config);
void nms8250j(machine_config &config);
void nms8255(machine_config &config);
void nms8255f(machine_config &config);
void nms8260(machine_config &config);
void nms8280(machine_config &config);
void nms8280f(machine_config &config);
void nms8280g(machine_config &config);
void vg8230(machine_config &config);
void vg8230j(machine_config &config);
void vg8235(machine_config &config);
void vg8235f(machine_config &config);
void vg8240(machine_config &config);
void mpc2300(machine_config &config);
void mpc2500f(machine_config &config);
void mpc25fd(machine_config &config);
void mpc27(machine_config &config);
void phc23(machine_config &config);
void phc55fd2(machine_config &config);
void phc77(machine_config &config);
void hotbit20(machine_config &config);
void hbf1(machine_config &config);
void hbf12(machine_config &config);
void hbf1xd(machine_config &config);
void hbf1xdm2(machine_config &config);
void hbf5(machine_config &config);
void hbf500(machine_config &config);
void hbf500f(machine_config &config);
void hbf500p(machine_config &config);
void hbf700d(machine_config &config);
void hbf700f(machine_config &config);
void hbf700p(machine_config &config);
void hbf700s(machine_config &config);
void hbf900(machine_config &config);
void hbf900a(machine_config &config);
void hbf9p(machine_config &config);
void hbf9pr(machine_config &config);
void hbf9s(machine_config &config);
void hbg900ap(machine_config &config);
void hbg900p(machine_config &config);
void tpc310(machine_config &config);
void tpp311(machine_config &config);
void tps312(machine_config &config);
void hx23(machine_config &config);
void hx23f(machine_config &config);
void hx23i(machine_config &config);
void hx33(machine_config &config);
void hx34(machine_config &config);
void hx34i(machine_config &config);
void fstm1(machine_config &config);
void victhc90(machine_config &config);
void victhc95(machine_config &config);
void victhc95a(machine_config &config);
void cx7m(machine_config &config);
void cx7m128(machine_config &config);
void y503iiir(machine_config &config);
void y503iiire(machine_config &config);
void yis60464(machine_config &config);
void yis604(machine_config &config);
void y805128(machine_config &config);
void y805128r2(machine_config &config);
void y805128r2e(machine_config &config);
void y805256(machine_config &config);
void expert3i(machine_config &config);
void expert3t(machine_config &config);
void expertac(machine_config &config);
void expertdx(machine_config &config);
void fsa1fx(machine_config &config);
void fsa1wsx(machine_config &config);
void fsa1wx(machine_config &config);
void fsa1wxa(machine_config &config);
void phc35j(machine_config &config);
void phc70fd(machine_config &config);
void phc70fd2(machine_config &config);
void hbf1xdj(machine_config &config);
void hbf1xv(machine_config &config);
void hbf9sp(machine_config &config);
void fsa1gt(machine_config &config);
void fsa1st(machine_config &config);
protected:
virtual void machine_start() override;
private:
void msx2(machine_config &config);
void msx2p(machine_config &config);
void msx2_pal(machine_config &config);
void turbor(machine_config &config);
void msx2_cartlist(machine_config &config);
void msx2_floplist(machine_config &config);
void msx2p_floplist(machine_config &config);
void msxr_floplist(machine_config &config);
void msx_ym2413(machine_config &config);
void msx2_64kb_vram(machine_config &config);
uint8_t msx_rtc_reg_r();
void msx_rtc_reg_w(uint8_t data);
void msx_rtc_latch_w(uint8_t data);
uint8_t msx_switched_r(offs_t offset);
void msx_switched_w(offs_t offset, uint8_t data);
DECLARE_WRITE_LINE_MEMBER(turbo_w);
void msx2_io_map(address_map &map);
void msx2p_io_map(address_map &map);
std::vector<msx_switched_interface *> m_switched;
optional_device<v9938_device> m_v9938;
optional_device<v9958_device> m_v9958;
required_device<rp5c01_device> m_rtc;
/* rtc */
int m_rtc_latch = 0;
};
#endif // MAME_INCLUDES_MSX_H

View File

@ -1,485 +0,0 @@
// license:BSD-3-Clause
// copyright-holders:Wilbert Pol
/*
* msx.c: MSX emulation
*
* Copyright (C) 2004 Sean Young
*
* Todo:
*
* - fix mouse support
* - cassette support doesn't work
* - Ensure changing cartridge after boot works
* - wd2793, nms8255
*/
#include "emu.h"
#include "msx.h"
#define VERBOSE 0
void msx_state::machine_reset()
{
msx_memory_reset ();
msx_memory_map_all ();
}
void msx_state::machine_start()
{
m_leds.resolve();
m_port_c_old = 0xff;
}
void msx2_state::machine_start()
{
msx_state::machine_start();
for (msx_switched_interface &switched : device_interface_enumerator<msx_switched_interface>(*this))
m_switched.push_back(&switched);
save_item(NAME(m_rtc_latch));
}
/* A hack to add 1 wait cycle in each opcode fetch.
Possibly worth not to use custom table at all but adjust desired icount
directly in m_opcodes.read_byte handler. */
static const uint8_t cc_op[0x100] = {
4+1,10+1, 7+1, 6+1, 4+1, 4+1, 7+1, 4+1, 4+1,11+1, 7+1, 6+1, 4+1, 4+1, 7+1, 4+1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4+1, 4+1, 4+1, 4+1, 4+1,15+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1,15+1, 4+1,
4+1, 4+1, 4+1, 4+1, 4+1, 4+1,15+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1,15+1, 4+1,
15+1,15+1,15+1,15+1,15+1,15+1, 4+1,15+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1,15+1, 4+1,
4+1, 4+1, 4+1, 4+1, 4+1, 4+1,15+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1,15+1, 4+1,
4+1, 4+1, 4+1, 4+1, 4+1, 4+1,15+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1,15+1, 4+1,
4+1, 4+1, 4+1, 4+1, 4+1, 4+1,15+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1,15+1, 4+1,
4+1, 4+1, 4+1, 4+1, 4+1, 4+1,15+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1, 4+1,15+1, 4+1,
5+1,10+1,10+1,10+1,10+1,11+1, 7+1,11+1, 5+1,10+1,10+1, 7+1,10+1,17+1, 7+1,11+1,
5+1,10+1,10+1,11+1,10+1,11+1, 7+1,11+1, 5+1, 4+1,10+1,11+1,10+1, 4+1, 7+1,11+1,
5+1,10+1,10+1,19+1,10+1,11+1, 7+1,11+1, 5+1, 4+1,10+1, 4+1,10+1, 4+1, 7+1,11+1,
5+1,10+1,10+1, 4+1,10+1,11+1, 7+1,11+1, 5+1, 6+1,10+1, 4+1,10+1, 4+1, 7+1,11+1
};
/* extra cycles if jr/jp/call taken and 'interrupt latency' on rst 0-7 */
static const uint8_t cc_ex[0x100] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* DJNZ */
5, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, /* JR NZ/JR Z */
5, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, /* JR NC/JR C */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5, 5, 5, 5, 0, 0, 0, 0, 5, 5, 5, 5, 0, 0, 0, 0, /* LDIR/CPIR/INIR/OTIR LDDR/CPDR/INDR/OTDR */
6, 0, 0, 0, 7, 0, 0, 2, 6, 0, 0, 0, 7, 0, 0, 2,
6, 0, 0, 0, 7, 0, 0, 2, 6, 0, 0, 0, 7, 0, 0, 2,
6, 0, 0, 0, 7, 0, 0, 2, 6, 0, 0, 0, 7, 0, 0, 2,
6, 0, 0, 0, 7, 0, 0, 2, 6, 0, 0, 0, 7, 0, 0, 2+1
};
void msx_state::driver_start()
{
m_maincpu->set_input_line_vector(0, 0xff); // Z80
msx_memory_init();
m_maincpu->z80_set_cycle_tables(cc_op, cc_cb, cc_ed, cc_xy, nullptr, cc_ex);
save_item(NAME(m_psg_b));
save_item(NAME(m_mouse));
save_item(NAME(m_mouse_stat));
save_item(NAME(m_kanji_latch));
save_item(NAME(m_slot_expanded));
save_item(NAME(m_primary_slot));
save_item(NAME(m_secondary_slot));
save_item(NAME(m_port_c_old));
save_item(NAME(m_keylatch));
}
void msx_state::device_post_load()
{
for (int page = 0; page < 4; page++)
{
int slot_primary = (m_primary_slot >> (page * 2)) & 3;
int slot_secondary = (m_secondary_slot[slot_primary] >> (page * 2)) & 3;
m_current_page[page] = m_all_slots[slot_primary][slot_secondary][page];
}
}
INTERRUPT_GEN_MEMBER(msx_state::msx_interrupt)
{
m_mouse[0] = m_io_mouse[0]->read();
m_mouse_stat[0] = -1;
m_mouse[1] = m_io_mouse[1]->read();
m_mouse_stat[1] = -1;
}
/*
** The I/O functions
*/
uint8_t msx_state::msx_psg_port_a_r()
{
uint8_t data = (m_cassette->input() > 0.0038 ? 0x80 : 0);
if ( (m_psg_b ^ m_io_dsw->read() ) & 0x40)
{
/* game port 2 */
uint8_t inp = m_io_joy[1]->read();
if ( !(inp & 0x80) )
{
/* joystick */
data |= ( inp & 0x7f );
}
else
{
/* mouse */
data |= ( inp & 0x70 );
if (m_mouse_stat[1] < 0)
data |= 0xf;
else
data |= ~(m_mouse[1] >> (4*m_mouse_stat[1]) ) & 15;
}
}
else
{
/* game port 1 */
uint8_t inp = m_io_joy[0]->read();
if ( !(inp & 0x80) )
{
/* joystick */
data |= ( inp & 0x7f );
}
else
{
/* mouse */
data |= ( inp & 0x70 );
if (m_mouse_stat[0] < 0)
data |= 0xf;
else
data |= ~(m_mouse[0] >> (4*m_mouse_stat[0]) ) & 15;
}
}
return data;
}
uint8_t msx_state::msx_psg_port_b_r()
{
return m_psg_b;
}
void msx_state::msx_psg_port_a_w(uint8_t data)
{
}
void msx_state::msx_psg_port_b_w(uint8_t data)
{
/* Arabic or kana mode led */
if ( (data ^ m_psg_b) & 0x80)
m_leds[1] = BIT(~data, 7);
if ( (m_psg_b ^ data) & 0x10)
{
if (++m_mouse_stat[0] > 3) m_mouse_stat[0] = -1;
}
if ( (m_psg_b ^ data) & 0x20)
{
if (++m_mouse_stat[1] > 3) m_mouse_stat[1] = -1;
}
m_psg_b = data;
}
/*
** RTC functions
*/
void msx2_state::msx_rtc_latch_w(uint8_t data)
{
m_rtc_latch = data & 15;
}
void msx2_state::msx_rtc_reg_w(uint8_t data)
{
m_rtc->write(m_rtc_latch, data);
}
uint8_t msx2_state::msx_rtc_reg_r()
{
return m_rtc->read(m_rtc_latch);
}
/*
** The PPI functions
*/
void msx_state::msx_ppi_port_a_w(uint8_t data)
{
m_primary_slot = data;
if (VERBOSE)
logerror ("write to primary slot select: %02x\n", m_primary_slot);
msx_memory_map_all ();
}
void msx_state::msx_ppi_port_c_w(uint8_t data)
{
m_keylatch = data & 0x0f;
/* caps lock */
if ( BIT(m_port_c_old ^ data, 6) )
m_leds[0] = BIT(~data, 6);
/* key click */
if ( BIT(m_port_c_old ^ data, 7) )
m_dac->write(BIT(data, 7));
/* cassette motor on/off */
if ( BIT(m_port_c_old ^ data, 4) )
m_cassette->change_state(BIT(data, 4) ? CASSETTE_MOTOR_DISABLED : CASSETTE_MOTOR_ENABLED, CASSETTE_MASK_MOTOR);
/* cassette signal write */
if ( BIT(m_port_c_old ^ data, 5) )
m_cassette->output(BIT(data, 5) ? -1.0 : 1.0);
m_port_c_old = data;
}
uint8_t msx_state::msx_ppi_port_b_r()
{
uint8_t result = 0xff;
int row, data;
row = m_keylatch;
if (row <= 10)
{
data = m_io_key[row / 2]->read();
if (BIT(row, 0))
data >>= 8;
result = data & 0xff;
}
return result;
}
/************************************************************************
*
* New memory emulation !!
*
***********************************************************************/
void msx_state::install_slot_pages(uint8_t prim, uint8_t sec, uint8_t page, uint8_t numpages, msx_internal_slot_interface &device)
{
for ( int i = page; i < std::min(page + numpages, 4); i++ )
{
m_all_slots[prim][sec][i] = &device;
}
if ( sec )
{
m_slot_expanded[prim] = true;
}
}
void msx_state::msx_memory_init()
{
int count_populated_pages = 0;
// Populate all unpopulated slots with the dummy interface
for (auto & elem : m_all_slots)
{
for ( int sec = 0; sec < 4; sec++ )
{
for ( int page = 0; page < 4; page++ )
{
if ( elem[sec][page] == nullptr )
{
elem[sec][page] = &m_empty_slot;
}
else
{
count_populated_pages++;
}
}
}
}
if ( count_populated_pages == 0 ) {
fatalerror("No msx slot layout defined for this system!\n");
}
}
void msx_state::msx_memory_reset ()
{
m_primary_slot = 0;
for (auto & elem : m_secondary_slot)
{
elem = 0;
}
}
void msx_state::msx_memory_map_page (uint8_t page)
{
int slot_primary = (m_primary_slot >> (page * 2)) & 3;
int slot_secondary = (m_secondary_slot[slot_primary] >> (page * 2)) & 3;
m_current_page[page] = m_all_slots[slot_primary][slot_secondary][page];
}
void msx_state::msx_memory_map_all ()
{
for (uint8_t i=0; i<4; i++)
msx_memory_map_page (i);
}
uint8_t msx_state::msx_mem_read(offs_t offset)
{
return m_current_page[offset >> 14]->read(offset);
}
void msx_state::msx_mem_write(offs_t offset, uint8_t data)
{
m_current_page[offset >> 14]->write(offset, data);
}
void msx_state::msx_sec_slot_w(uint8_t data)
{
int slot = m_primary_slot >> 6;
if (m_slot_expanded[slot])
{
if (VERBOSE)
logerror ("write to secondary slot %d select: %02x\n", slot, data);
m_secondary_slot[slot] = data;
msx_memory_map_all ();
}
else
m_current_page[3]->write(0xffff, data);
}
uint8_t msx_state::msx_sec_slot_r()
{
int slot = m_primary_slot >> 6;
if (m_slot_expanded[slot])
{
return ~m_secondary_slot[slot];
}
else
{
return m_current_page[3]->read(0xffff);
}
}
uint8_t msx_state::msx_kanji_r(offs_t offset)
{
uint8_t result = 0xff;
if (offset && m_region_kanji)
{
int latch = m_kanji_latch;
result = m_region_kanji->as_u8(latch++);
m_kanji_latch &= ~0x1f;
m_kanji_latch |= latch & 0x1f;
}
return result;
}
void msx_state::msx_kanji_w(offs_t offset, uint8_t data)
{
if (offset)
m_kanji_latch = (m_kanji_latch & 0x007E0) | ((data & 0x3f) << 11);
else
m_kanji_latch = (m_kanji_latch & 0x1f800) | ((data & 0x3f) << 5);
}
uint8_t msx2_state::msx_switched_r(offs_t offset)
{
uint8_t data = 0xff;
for (int i = 0; i < m_switched.size(); i++)
{
data &= m_switched[i]->switched_read(offset);
}
return data;
}
void msx2_state::msx_switched_w(offs_t offset, uint8_t data)
{
for (int i = 0; i < m_switched.size(); i++)
{
m_switched[i]->switched_write(offset, data);
}
}