m14.cpp: Revised PT Reach Mahjong, making it actually working [Angelo Salese]

* Added ball and paddle screen drawing;
* Added green background as per flyer pics;
* Added reach button and updated input labels;
This commit is contained in:
angelosa 2017-05-18 03:29:19 +02:00
parent 90d6fe79ce
commit ee71c6abe3

View File

@ -14,14 +14,11 @@ TODO:
- I'm not sure about the hopper hook-up, it could also be that the player should press
start + button 1 + ron buttons (= 0x43) instead of being "automatic";
- Inputs are grossly mapped;
- ball and paddle drawing are a guesswork;
Notes:
- Unlike most Arcade games, if you call a ron but you don't have a legit hand you'll automatically
lose the match. This is commonly named chombo in rii'chi mahjong rules;
- If you make the timer to run out, you'll lose the turn but you don't get any visible message
(presumably signaled by a sound effect);
- As you could expect, the cpu hands are actually pre-determined, so you actually play alone
against a variable number of available tiles;
==============================================================================================
@ -65,7 +62,10 @@ public:
m_video_ram(*this, "video_ram"),
m_color_ram(*this, "color_ram"),
m_maincpu(*this, "maincpu"),
m_gfxdecode(*this, "gfxdecode") { }
m_screen(*this, "screen"),
m_gfxdecode(*this, "gfxdecode"),
m_palette(*this, "palette")
{ }
/* video-related */
tilemap_t *m_m14_tilemap;
@ -74,19 +74,29 @@ public:
/* input-related */
uint8_t m_hop_mux;
uint8_t m_ballx,m_bally;
uint8_t m_paddlex;
/* devices */
required_device<cpu_device> m_maincpu;
required_device<screen_device> m_screen;
required_device<gfxdecode_device> m_gfxdecode;
required_device<palette_device> m_palette;
DECLARE_WRITE8_MEMBER(m14_vram_w);
DECLARE_WRITE8_MEMBER(m14_cram_w);
DECLARE_READ8_MEMBER(m14_rng_r);
DECLARE_READ8_MEMBER(input_buttons_r);
DECLARE_WRITE8_MEMBER(hopper_w);
DECLARE_WRITE8_MEMBER(ball_x_w);
DECLARE_WRITE8_MEMBER(ball_y_w);
DECLARE_WRITE8_MEMBER(paddle_x_w);
DECLARE_INPUT_CHANGED_MEMBER(left_coin_inserted);
DECLARE_INPUT_CHANGED_MEMBER(right_coin_inserted);
TILE_GET_INFO_MEMBER(m14_get_tile_info);
void draw_ball_and_paddle(bitmap_ind16 &bitmap, const rectangle &cliprect);
virtual void machine_start() override;
virtual void machine_reset() override;
virtual void video_start() override;
@ -102,10 +112,10 @@ public:
*
*************************************/
/* guess, might not be 100% accurate. */
PALETTE_INIT_MEMBER(m14_state, m14)
{
int i;
const rgb_t green_pen = rgb_t(pal1bit(0), pal1bit(1), pal1bit(0));
for (i = 0; i < 0x20; i++)
{
@ -114,7 +124,7 @@ PALETTE_INIT_MEMBER(m14_state, m14)
if (i & 0x01)
color = rgb_t(pal1bit(i >> 1), pal1bit(i >> 2), pal1bit(i >> 3));
else
color = (i & 0x10) ? rgb_t::white() : rgb_t::black();
color = (i & 0x10) ? rgb_t::white() : green_pen;
palette.set_pen_color(i, color);
}
@ -126,7 +136,7 @@ TILE_GET_INFO_MEMBER(m14_state::m14_get_tile_info)
int color = m_color_ram[tile_index] & 0x0f;
/* colorram & 0xf0 used but unknown purpose*/
SET_TILE_INFO_MEMBER(0,
code,
color,
@ -136,11 +146,35 @@ TILE_GET_INFO_MEMBER(m14_state::m14_get_tile_info)
void m14_state::video_start()
{
m_m14_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(FUNC(m14_state::m14_get_tile_info),this), TILEMAP_SCAN_ROWS, 8, 8, 32, 32);
}
void m14_state::draw_ball_and_paddle(bitmap_ind16 &bitmap, const rectangle &cliprect)
{
int xi,yi;
//const rgb_t white_pen = rgb_t::white();
const uint8_t white_pen = 0x1f;
const int xoffs = -8; // matches left-right wall bounces
const int p_ybase = 184; // matches ball bounce to paddle
// draw ball
for(xi=0;xi<4;xi++)
for(yi=0;yi<4;yi++)
bitmap.pix16(m_bally+yi, m_ballx+xi+xoffs) = m_palette->pen(white_pen);
// draw paddle
for(xi=0;xi<16;xi++)
for(yi=0;yi<4;yi++)
bitmap.pix16(p_ybase+yi, m_paddlex+xi+xoffs) = m_palette->pen(white_pen);
}
uint32_t m14_state::screen_update_m14(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
m_m14_tilemap->draw(screen, bitmap, cliprect, 0, 0);
draw_ball_and_paddle(bitmap,cliprect);
return 0;
}
@ -166,7 +200,8 @@ WRITE8_MEMBER(m14_state::m14_cram_w)
READ8_MEMBER(m14_state::m14_rng_r)
{
/* graphic artifacts happens if this doesn't return random values. */
return (machine().rand() & 0x0f) | 0xf0; /* | (ioport("IN1")->read() & 0x80)*/;
/* guess directly tied to screen frame number */
return (m_screen->frame_number() & 0x7f) | (ioport("IN1")->read() & 0x80);
}
/* Here routes the hopper & the inputs */
@ -181,17 +216,6 @@ READ8_MEMBER(m14_state::input_buttons_r)
return ioport("IN0")->read();
}
#if 0
WRITE8_MEMBER(m14_state::test_w)
{
static uint8_t x[5];
x[offset] = data;
popmessage("%02x %02x %02x %02x %02x",x[0],x[1],x[2],x[3],x[4]);
}
#endif
WRITE8_MEMBER(m14_state::hopper_w)
{
/* ---- x--- coin out */
@ -200,6 +224,21 @@ WRITE8_MEMBER(m14_state::hopper_w)
//popmessage("%02x",data);
}
WRITE8_MEMBER(m14_state::ball_x_w)
{
m_ballx = data;
}
WRITE8_MEMBER(m14_state::ball_y_w)
{
m_bally = data;
}
WRITE8_MEMBER(m14_state::paddle_x_w)
{
m_paddlex = data;
}
/*************************************
*
* Memory Map
@ -215,11 +254,11 @@ ADDRESS_MAP_END
static ADDRESS_MAP_START( m14_io_map, AS_IO, 8, m14_state )
ADDRESS_MAP_GLOBAL_MASK(0xff)
AM_RANGE(0xf8, 0xf8) AM_READ_PORT("AN_PADDLE") AM_WRITENOP
AM_RANGE(0xf9, 0xf9) AM_READ(input_buttons_r) AM_WRITENOP
AM_RANGE(0xfa, 0xfa) AM_READ(m14_rng_r) AM_WRITENOP
AM_RANGE(0xf8, 0xf8) AM_READ_PORT("AN_PADDLE") AM_WRITE(ball_x_w)
AM_RANGE(0xf9, 0xf9) AM_READ(input_buttons_r) AM_WRITE(ball_y_w)
AM_RANGE(0xfa, 0xfa) AM_READ(m14_rng_r) AM_WRITE(paddle_x_w)
AM_RANGE(0xfb, 0xfb) AM_READ_PORT("DSW") AM_WRITE(hopper_w)
AM_RANGE(0xf8, 0xfc) AM_WRITENOP
AM_RANGE(0xfc, 0xfc) AM_WRITENOP // sound
ADDRESS_MAP_END
/*************************************
@ -247,11 +286,11 @@ static INPUT_PORTS_START( m14 )
PORT_BIT( 0xff, 0x00, IPT_PADDLE ) PORT_MINMAX(0,0xff) PORT_SENSITIVITY(5) PORT_KEYDELTA(1) PORT_CENTERDELTA(0) PORT_REVERSE
PORT_START("IN0")
PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 )
PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_MAHJONG_RON ) //could be reach too
PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) ) //affects medal settings?
PORT_DIPSETTING( 0x04, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P1 Fire / Discard")
PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P1 Ron")
PORT_DIPNAME( 0x04, 0x04, DEF_STR( Coinage ) )
PORT_DIPSETTING( 0x04, "Coin A 5\u30de\u30a4 Coin B 1\u30de\u30a4" )
PORT_DIPSETTING( 0x00, "Coin A & B 1\u30de\u30a4" )
PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
PORT_DIPSETTING( 0x08, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
@ -265,9 +304,12 @@ static INPUT_PORTS_START( m14 )
PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
PORT_DIPSETTING( 0x80, DEF_STR( Off ) )
PORT_DIPSETTING( 0x00, DEF_STR( On ) )
PORT_START("IN1")
PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("P1 Reach")
PORT_START("DSW") //this whole port is stored at work ram $2112.
PORT_DIPNAME( 0x01, 0x00, "Show available tiles" ) // debug mode for the rng?
PORT_DIPNAME( 0x01, 0x01, "Show available tiles" )
PORT_DIPSETTING( 0x00, DEF_STR( No ) )
PORT_DIPSETTING( 0x01, DEF_STR( Yes ) )
PORT_DIPNAME( 0x02, 0x00, DEF_STR( Unknown ) )
@ -321,6 +363,9 @@ INTERRUPT_GEN_MEMBER(m14_state::m14_irq)
void m14_state::machine_start()
{
save_item(NAME(m_hop_mux));
save_item(NAME(m_ballx));
save_item(NAME(m_bally));
save_item(NAME(m_paddlex));
}
void m14_state::machine_reset()
@ -332,12 +377,11 @@ void m14_state::machine_reset()
static MACHINE_CONFIG_START( m14 )
/* basic machine hardware */
MCFG_CPU_ADD("maincpu",I8085A,6000000/2) //guess: 6 Mhz internally divided by 2
MCFG_CPU_ADD("maincpu",I8085A,6000000) //guess: 6 Mhz internally divided by 2
MCFG_CPU_PROGRAM_MAP(m14_map)
MCFG_CPU_IO_MAP(m14_io_map)
MCFG_CPU_VBLANK_INT_DRIVER("screen", m14_state, m14_irq)
/* video hardware */
MCFG_SCREEN_ADD("screen", RASTER)
MCFG_SCREEN_REFRESH_RATE(60)
@ -383,4 +427,4 @@ ROM_START( ptrmj )
ROM_LOAD( "mgpa10.bin", 0x0400, 0x0400, CRC(e1a4ebdc) SHA1(d9df42424ede17f0634d8d0a56c0374a33c55333) )
ROM_END
GAME( 1979, ptrmj, 0, m14, m14, m14_state, 0, ROT0, "Irem", "PT Reach Mahjong (Japan)", MACHINE_NO_SOUND | MACHINE_SUPPORTS_SAVE ) // IPM or Irem?
GAME( 1979, ptrmj, 0, m14, m14, m14_state, 0, ROT0, "Irem", "PT Reach Mahjong (Japan)", MACHINE_NO_SOUND | MACHINE_SUPPORTS_SAVE ) // was already Irem according to the official flyer