pv1000: put joystick read in a separate function, remove an unneeded tag lookup

This commit is contained in:
hap 2024-08-23 21:25:11 +02:00
parent 1725703539
commit a8fb827abc
3 changed files with 63 additions and 55 deletions

View File

@ -78,19 +78,20 @@ void pv1000_sound_device::voice_w(offs_t offset, uint8_t data)
case 0x03: case 0x03:
m_ctrl = data; m_ctrl = data;
break; break;
default: default:
{
const uint8_t per = ~data & 0x3f;
if ((per == 0) && (m_voice[offset].period != 0))
{ {
const uint8_t per = ~data & 0x3f; // flip output once and stall there!
m_voice[offset].val = !m_voice[offset].val;
if ((per == 0) && (m_voice[offset].period != 0))
{
// flip output once and stall there!
m_voice[offset].val = !m_voice[offset].val;
}
m_voice[offset].period = per;
} }
break;
m_voice[offset].period = per;
}
break;
} }
} }
@ -121,7 +122,7 @@ void pv1000_sound_device::sound_stream_update(sound_stream &stream, std::vector<
auto &buffer = outputs[0]; auto &buffer = outputs[0];
// Each channel has a different volume via resistor mixing which correspond to -6dB, -3dB, 0dB drops // Each channel has a different volume via resistor mixing which correspond to -6dB, -3dB, 0dB drops
static const int volumes[3] = {0x1000, 0x1800, 0x2000}; static const int volumes[3] = { 0x1000, 0x1800, 0x2000 };
for (int index = 0; index < buffer.samples(); index++) for (int index = 0; index < buffer.samples(); index++)
{ {
@ -175,7 +176,7 @@ public:
m_maincpu(*this, "maincpu"), m_maincpu(*this, "maincpu"),
m_sound(*this, "pv1000_sound"), m_sound(*this, "pv1000_sound"),
m_cart(*this, "cartslot"), m_cart(*this, "cartslot"),
m_p_videoram(*this, "videoram"), m_videoram(*this, "videoram"),
m_gfxdecode(*this, "gfxdecode"), m_gfxdecode(*this, "gfxdecode"),
m_screen(*this, "screen"), m_screen(*this, "screen"),
m_palette(*this, "palette"), m_palette(*this, "palette"),
@ -192,6 +193,7 @@ private:
void io_w(offs_t offset, uint8_t data); void io_w(offs_t offset, uint8_t data);
uint8_t io_r(offs_t offset); uint8_t io_r(offs_t offset);
void gfxram_w(offs_t offset, uint8_t data); void gfxram_w(offs_t offset, uint8_t data);
uint8_t joystick_r();
uint8_t m_io_regs[8]{}; uint8_t m_io_regs[8]{};
emu_timer *m_irq_on_timer = nullptr; emu_timer *m_irq_on_timer = nullptr;
@ -210,16 +212,17 @@ private:
required_device<cpu_device> m_maincpu; required_device<cpu_device> m_maincpu;
required_device<pv1000_sound_device> m_sound; required_device<pv1000_sound_device> m_sound;
required_device<generic_slot_device> m_cart; required_device<generic_slot_device> m_cart;
required_shared_ptr<uint8_t> m_p_videoram; required_shared_ptr<uint8_t> m_videoram;
required_device<gfxdecode_device> m_gfxdecode;
required_device<screen_device> m_screen;
required_device<palette_device> m_palette;
required_ioport_array<4> m_joysticks;
uint32_t screen_update_pv1000(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); uint32_t screen_update_pv1000(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
TIMER_CALLBACK_MEMBER(d65010_irq_on_cb); TIMER_CALLBACK_MEMBER(d65010_irq_on_cb);
TIMER_CALLBACK_MEMBER(d65010_busrq_on_cb); TIMER_CALLBACK_MEMBER(d65010_busrq_on_cb);
TIMER_CALLBACK_MEMBER(d65010_busrq_off_cb); TIMER_CALLBACK_MEMBER(d65010_busrq_off_cb);
DECLARE_DEVICE_IMAGE_LOAD_MEMBER(cart_load); DECLARE_DEVICE_IMAGE_LOAD_MEMBER(cart_load);
required_device<gfxdecode_device> m_gfxdecode;
required_device<screen_device> m_screen;
required_device<palette_device> m_palette;
required_ioport_array<4> m_joysticks;
void pv1000_mem(address_map &map); void pv1000_mem(address_map &map);
void pv1000_io(address_map &map); void pv1000_io(address_map &map);
@ -228,8 +231,8 @@ private:
void pv1000_state::pv1000_mem(address_map &map) void pv1000_state::pv1000_mem(address_map &map)
{ {
//map(0x0000, 0x7fff) // mapped by the cartslot //map(0x0000, 0x7fff) // mapped by the cartslot
map(0xb800, 0xbbff).ram().share("videoram"); map(0xb800, 0xbbff).ram().share(m_videoram);
map(0xbc00, 0xbfff).ram().w(FUNC(pv1000_state::gfxram_w)).region("gfxram", 0); map(0xbc00, 0xbfff).ram().w(FUNC(pv1000_state::gfxram_w)).region("gfxram", 0);
} }
@ -243,10 +246,8 @@ void pv1000_state::pv1000_io(address_map &map)
void pv1000_state::gfxram_w(offs_t offset, uint8_t data) void pv1000_state::gfxram_w(offs_t offset, uint8_t data)
{ {
uint8_t *gfxram = memregion("gfxram")->base(); m_gfxram[offset] = data;
m_gfxdecode->gfx(1)->mark_dirty(offset / 32);
gfxram[offset] = data;
m_gfxdecode->gfx(1)->mark_dirty(offset/32);
} }
@ -273,7 +274,7 @@ void pv1000_state::io_w(offs_t offset, uint8_t data)
break; break;
case 0x05: case 0x05:
/* Acknowledge Prerender IRQ */ // Acknowledge Prerender IRQ
if (m_irq_active & 1) if (m_irq_active & 1)
{ {
m_irq_active &= ~1; m_irq_active &= ~1;
@ -315,29 +316,17 @@ uint8_t pv1000_state::io_r(offs_t offset)
weak pull-ups on the data bus */ weak pull-ups on the data bus */
switch (offset) switch (offset)
{ {
case 4: // port $FC returns player 2 joystick and interrupt status case 0x04: // port $FC returns player 2 joystick and interrupt status
return 0x80 return 0x80 | (joystick_r() & 0x0c) | (m_irq_active & 3); // Bit 1 = Matrix IRQ, Bit 0 = Prerender IRQ
| (((BIT(m_io_regs[5], 3) ? m_joysticks[3]->read() : 0)
| (BIT(m_io_regs[5], 2) ? m_joysticks[2]->read() : 0)
| (BIT(m_io_regs[5], 1) ? m_joysticks[1]->read() : 0)
| (BIT(m_io_regs[5], 0) ? m_joysticks[0]->read() : 0)) & 0x0c)
| (m_irq_active & 3); // Bit 1 = Matrix IRQ, Bit 0 = Prerender IRQ
case 5: // port $FD returns both joysticks and acknowledges matrix scan IRQ case 0x05: // port $FD returns both joysticks and acknowledges matrix scan IRQ
if (!machine().side_effects_disabled()) if (!machine().side_effects_disabled() && (m_irq_active & 2))
{ {
if (m_irq_active & 2) m_irq_active &= ~2;
{ if (m_irq_active == 0)
m_irq_active &= ~2; m_maincpu->set_input_line(INPUT_LINE_IRQ0, CLEAR_LINE);
if (m_irq_active == 0)
m_maincpu->set_input_line(INPUT_LINE_IRQ0, CLEAR_LINE);
}
} }
return 0x80 return 0x80 | joystick_r();
| (BIT(m_io_regs[5], 3) ? m_joysticks[3]->read() : 0)
| (BIT(m_io_regs[5], 2) ? m_joysticks[2]->read() : 0)
| (BIT(m_io_regs[5], 1) ? m_joysticks[1]->read() : 0)
| (BIT(m_io_regs[5], 0) ? m_joysticks[0]->read() : 0);
default: default:
/* Ports $F8-$FB, $FE, and $FF are undriven, and pulled high by the /* Ports $F8-$FB, $FE, and $FF are undriven, and pulled high by the
@ -346,6 +335,17 @@ uint8_t pv1000_state::io_r(offs_t offset)
} }
} }
uint8_t pv1000_state::joystick_r()
{
uint8_t data = 0;
for (int i = 0; i < 4; i++)
if (BIT(m_io_regs[5], i))
data |= m_joysticks[i]->read();
return data & 0x0f;
}
static INPUT_PORTS_START( pv1000 ) static INPUT_PORTS_START( pv1000 )
PORT_START("IN0") PORT_START("IN0")
@ -399,7 +399,7 @@ uint32_t pv1000_state::screen_update_pv1000(screen_device &screen, bitmap_ind16
{ {
for (int x = 2; x < 30; x++) // left-right most columns never even drawn, black instead for (int x = 2; x < 30; x++) // left-right most columns never even drawn, black instead
{ {
uint16_t tile = m_p_videoram[y * 32 + x]; uint16_t tile = m_videoram[y * 32 + x];
if (tile < 0xe0 || m_force_pattern) if (tile < 0xe0 || m_force_pattern)
{ {
@ -459,18 +459,19 @@ TIMER_CALLBACK_MEMBER(pv1000_state::d65010_busrq_on_cb)
int vpos = m_screen->vpos(); int vpos = m_screen->vpos();
int next_vpos = vpos + 1; int next_vpos = vpos + 1;
if (m_render_disable == 0) { if (m_render_disable == 0)
{
m_maincpu->set_input_line(Z80_INPUT_LINE_BUSRQ, ASSERT_LINE); m_maincpu->set_input_line(Z80_INPUT_LINE_BUSRQ, ASSERT_LINE);
} }
// schedule the de-assertion of Busreq that corresponds to the current assertion // schedule the de-assertion of Busreq that corresponds to the current assertion
m_busrq_off_timer->adjust(m_screen->time_until_pos(vpos,248)); m_busrq_off_timer->adjust(m_screen->time_until_pos(vpos, 248));
if (vpos >= 192 + 26) if (vpos >= 192 + 26)
{ {
next_vpos = 26; next_vpos = 26;
} }
m_busrq_on_timer->adjust(m_screen->time_until_pos(next_vpos,0)); m_busrq_on_timer->adjust(m_screen->time_until_pos(next_vpos, 0));
} }
TIMER_CALLBACK_MEMBER(pv1000_state::d65010_busrq_off_cb) TIMER_CALLBACK_MEMBER(pv1000_state::d65010_busrq_off_cb)

View File

@ -155,7 +155,7 @@ INPUT_PORTS_END
void tgtpanic_state::tgtpanic(machine_config &config) void tgtpanic_state::tgtpanic(machine_config &config)
{ {
// basic machine hardware // basic machine hardware
Z80(config,m_maincpu, XTAL(4'000'000)); Z80(config,m_maincpu, 4_MHz_XTAL);
m_maincpu->set_addrmap(AS_PROGRAM, &tgtpanic_state::prg_map); m_maincpu->set_addrmap(AS_PROGRAM, &tgtpanic_state::prg_map);
m_maincpu->set_addrmap(AS_IO, &tgtpanic_state::io_map); m_maincpu->set_addrmap(AS_IO, &tgtpanic_state::io_map);

View File

@ -25,6 +25,7 @@ TODO:
*******************************************************************************/ *******************************************************************************/
#include "emu.h" #include "emu.h"
#include "cpu/z80/z80.h" #include "cpu/z80/z80.h"
#include "sound/dac.h" #include "sound/dac.h"
@ -83,7 +84,7 @@ void mmahjong_state::machine_start()
/******************************************************************************* /*******************************************************************************
I/O Video
*******************************************************************************/ *******************************************************************************/
u32 mmahjong_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) u32 mmahjong_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
@ -92,6 +93,16 @@ u32 mmahjong_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, c
return 0; return 0;
} }
static GFXDECODE_START( gfx_mmahjong )
GFXDECODE_ENTRY( "tiles", 0, gfx_8x8x1, 0, 1 )
GFXDECODE_END
/*******************************************************************************
I/O
*******************************************************************************/
void mmahjong_state::vram_w(offs_t offset, u8 data) void mmahjong_state::vram_w(offs_t offset, u8 data)
{ {
m_vram[offset] = data; m_vram[offset] = data;
@ -133,7 +144,7 @@ void mmahjong_state::main_map(address_map &map)
{ {
map(0x0000, 0x3fff).rom(); map(0x0000, 0x3fff).rom();
map(0x5000, 0x53ff).ram(); map(0x5000, 0x53ff).ram();
map(0x6000, 0x63ff).w(FUNC(mmahjong_state::vram_w)).share("vram"); map(0x6000, 0x63ff).w(FUNC(mmahjong_state::vram_w)).share(m_vram);
map(0x7001, 0x7001).r(FUNC(mmahjong_state::input_r)); map(0x7001, 0x7001).r(FUNC(mmahjong_state::input_r));
map(0x7002, 0x7002).w(FUNC(mmahjong_state::input_w)); map(0x7002, 0x7002).w(FUNC(mmahjong_state::input_w));
map(0x7004, 0x7004).w(FUNC(mmahjong_state::sound_w)); map(0x7004, 0x7004).w(FUNC(mmahjong_state::sound_w));
@ -181,10 +192,6 @@ INPUT_PORTS_END
Machine Configs Machine Configs
*******************************************************************************/ *******************************************************************************/
static GFXDECODE_START( gfx_mmahjong )
GFXDECODE_ENTRY( "tiles", 0, gfx_8x8x1, 0, 1 )
GFXDECODE_END
void mmahjong_state::mmahjong(machine_config &config) void mmahjong_state::mmahjong(machine_config &config)
{ {
// basic machine hardware // basic machine hardware