Skip to content

Commit

Permalink
pv1000: put joystick read in a separate function, remove an unneeded …
Browse files Browse the repository at this point in the history
…tag lookup
  • Loading branch information
happppp committed Aug 23, 2024
1 parent 1725703 commit a8fb827
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 56 deletions.
99 changes: 50 additions & 49 deletions src/mame/casio/pv1000.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,20 @@ void pv1000_sound_device::voice_w(offs_t offset, uint8_t data)
case 0x03:
m_ctrl = data;
break;
default:
{
const uint8_t per = ~data & 0x3f;

if ((per == 0) && (m_voice[offset].period != 0))
{
// flip output once and stall there!
m_voice[offset].val = !m_voice[offset].val;
}
default:
{
const uint8_t per = ~data & 0x3f;

m_voice[offset].period = per;
if ((per == 0) && (m_voice[offset].period != 0))
{
// flip output once and stall there!
m_voice[offset].val = !m_voice[offset].val;
}
break;

m_voice[offset].period = per;
}
break;
}
}

Expand Down Expand Up @@ -121,7 +122,7 @@ void pv1000_sound_device::sound_stream_update(sound_stream &stream, std::vector<
auto &buffer = outputs[0];

// 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++)
{
Expand Down Expand Up @@ -175,7 +176,7 @@ class pv1000_state : public driver_device
m_maincpu(*this, "maincpu"),
m_sound(*this, "pv1000_sound"),
m_cart(*this, "cartslot"),
m_p_videoram(*this, "videoram"),
m_videoram(*this, "videoram"),
m_gfxdecode(*this, "gfxdecode"),
m_screen(*this, "screen"),
m_palette(*this, "palette"),
Expand All @@ -192,6 +193,7 @@ class pv1000_state : public driver_device
void io_w(offs_t offset, uint8_t data);
uint8_t io_r(offs_t offset);
void gfxram_w(offs_t offset, uint8_t data);
uint8_t joystick_r();
uint8_t m_io_regs[8]{};

emu_timer *m_irq_on_timer = nullptr;
Expand All @@ -210,16 +212,17 @@ class pv1000_state : public driver_device
required_device<cpu_device> m_maincpu;
required_device<pv1000_sound_device> m_sound;
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);
TIMER_CALLBACK_MEMBER(d65010_irq_on_cb);
TIMER_CALLBACK_MEMBER(d65010_busrq_on_cb);
TIMER_CALLBACK_MEMBER(d65010_busrq_off_cb);
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_io(address_map &map);
Expand All @@ -228,8 +231,8 @@ class pv1000_state : public driver_device

void pv1000_state::pv1000_mem(address_map &map)
{
//map(0x0000, 0x7fff) // mapped by the cartslot
map(0xb800, 0xbbff).ram().share("videoram");
//map(0x0000, 0x7fff) // mapped by the cartslot
map(0xb800, 0xbbff).ram().share(m_videoram);
map(0xbc00, 0xbfff).ram().w(FUNC(pv1000_state::gfxram_w)).region("gfxram", 0);
}

Expand All @@ -243,10 +246,8 @@ void pv1000_state::pv1000_io(address_map &map)

void pv1000_state::gfxram_w(offs_t offset, uint8_t data)
{
uint8_t *gfxram = memregion("gfxram")->base();

gfxram[offset] = data;
m_gfxdecode->gfx(1)->mark_dirty(offset/32);
m_gfxram[offset] = data;
m_gfxdecode->gfx(1)->mark_dirty(offset / 32);
}


Expand All @@ -273,7 +274,7 @@ void pv1000_state::io_w(offs_t offset, uint8_t data)
break;

case 0x05:
/* Acknowledge Prerender IRQ */
// Acknowledge Prerender IRQ
if (m_irq_active & 1)
{
m_irq_active &= ~1;
Expand Down Expand Up @@ -315,29 +316,17 @@ uint8_t pv1000_state::io_r(offs_t offset)
weak pull-ups on the data bus */
switch (offset)
{
case 4: // port $FC returns player 2 joystick and interrupt status
return 0x80
| (((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
if (!machine().side_effects_disabled())
case 0x04: // port $FC returns player 2 joystick and interrupt status
return 0x80 | (joystick_r() & 0x0c) | (m_irq_active & 3); // Bit 1 = Matrix IRQ, Bit 0 = Prerender IRQ

case 0x05: // port $FD returns both joysticks and acknowledges matrix scan IRQ
if (!machine().side_effects_disabled() && (m_irq_active & 2))
{
if (m_irq_active & 2)
{
m_irq_active &= ~2;
if (m_irq_active == 0)
m_maincpu->set_input_line(INPUT_LINE_IRQ0, CLEAR_LINE);
}
m_irq_active &= ~2;
if (m_irq_active == 0)
m_maincpu->set_input_line(INPUT_LINE_IRQ0, CLEAR_LINE);
}
return 0x80
| (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);
return 0x80 | joystick_r();

default:
/* Ports $F8-$FB, $FE, and $FF are undriven, and pulled high by the
Expand All @@ -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 )
PORT_START("IN0")
Expand Down Expand Up @@ -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
{
uint16_t tile = m_p_videoram[y * 32 + x];
uint16_t tile = m_videoram[y * 32 + x];

if (tile < 0xe0 || m_force_pattern)
{
Expand Down Expand Up @@ -459,18 +459,19 @@ TIMER_CALLBACK_MEMBER(pv1000_state::d65010_busrq_on_cb)
int vpos = m_screen->vpos();
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);
}

// 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)
{
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)
Expand Down
2 changes: 1 addition & 1 deletion src/mame/konami/tgtpanic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ INPUT_PORTS_END
void tgtpanic_state::tgtpanic(machine_config &config)
{
// 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_IO, &tgtpanic_state::io_map);

Expand Down
19 changes: 13 additions & 6 deletions src/mame/tvgames/micom_mahjong.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Hardware notes:
*******************************************************************************/

#include "emu.h"

#include "cpu/z80/z80.h"
#include "sound/dac.h"

Expand Down Expand Up @@ -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)
Expand All @@ -92,6 +93,16 @@ u32 mmahjong_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, c
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)
{
m_vram[offset] = data;
Expand Down Expand Up @@ -133,7 +144,7 @@ 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(0x6000, 0x63ff).w(FUNC(mmahjong_state::vram_w)).share(m_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));
Expand Down Expand Up @@ -181,10 +192,6 @@ 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
Expand Down

0 comments on commit a8fb827

Please sign in to comment.