snk/munchmo.cpp: Cleaned up graphics decoding layouts and other improvements: (#13442)

* Cleanup graphics decoding layouts, use scale factors rather than duplicating pixels.
* Split graphics ROM and look-up table ROM regions.
* Improved save state support and cleaned up code.
This commit is contained in:
cam900 2025-03-05 17:07:01 +09:00 committed by GitHub
parent b4af482f19
commit 30d05e20cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -51,7 +51,7 @@ public:
, m_videoram(*this, "videoram") , m_videoram(*this, "videoram")
, m_status_vram(*this, "status_vram") , m_status_vram(*this, "status_vram")
, m_vreg(*this, "vreg") , m_vreg(*this, "vreg")
, m_tiles_rom(*this, "tiles") , m_tiles_rom(*this, "tilelut")
, m_maincpu(*this, "maincpu") , m_maincpu(*this, "maincpu")
, m_audiocpu(*this, "audiocpu") , m_audiocpu(*this, "audiocpu")
, m_mainlatch(*this, "mainlatch") , m_mainlatch(*this, "mainlatch")
@ -82,7 +82,7 @@ private:
void palette(palette_device &palette) const; void palette(palette_device &palette) const;
void vblank_irq(int state); void vblank_irq(int state);
IRQ_CALLBACK_MEMBER(generic_irq_ack); IRQ_CALLBACK_MEMBER(irq_ack);
uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
void draw_status(bitmap_ind16 &bitmap, const rectangle &cliprect); void draw_status(bitmap_ind16 &bitmap, const rectangle &cliprect);
@ -102,12 +102,12 @@ private:
required_region_ptr<u8> m_tiles_rom; required_region_ptr<u8> m_tiles_rom;
// video-related // video-related
std::unique_ptr<bitmap_ind16> m_tmpbitmap; bitmap_ind16 m_tmpbitmap;
u8 m_palette_bank = 0U; u8 m_palette_bank = 0U;
u8 m_flipscreen = 0U; bool m_flipscreen = false;
// misc // misc
u8 m_nmi_enable = 0U; bool m_nmi_enable = false;
// devices // devices
required_device<cpu_device> m_maincpu; required_device<cpu_device> m_maincpu;
@ -173,7 +173,11 @@ void munchmo_state::flipscreen_w(int state)
void munchmo_state::video_start() void munchmo_state::video_start()
{ {
m_tmpbitmap = std::make_unique<bitmap_ind16>(512, 512); m_tmpbitmap.allocate(512, 512);
save_item(NAME(m_tmpbitmap));
save_item(NAME(m_palette_bank));
save_item(NAME(m_flipscreen));
} }
void munchmo_state::draw_status(bitmap_ind16 &bitmap, const rectangle &cliprect) void munchmo_state::draw_status(bitmap_ind16 &bitmap, const rectangle &cliprect)
@ -208,15 +212,15 @@ void munchmo_state::draw_background(bitmap_ind16 &bitmap, const rectangle &clipr
for (int offs = 0; offs < 0x100; offs++) for (int offs = 0; offs < 0x100; offs++)
{ {
int const sy = (offs % 16) * 32; int const sy = (offs & 0xf) * 32;
int const sx = (offs / 16) * 32; int const sx = (offs >> 4) * 32;
int const tile_number = m_videoram[offs]; int const tile_number = m_videoram[offs];
for (int row = 0; row < 4; row++) for (int row = 0; row < 4; row++)
{ {
for (int col = 0; col < 4; col++) for (int col = 0; col < 4; col++)
{ {
gfx->opaque(*m_tmpbitmap, m_tmpbitmap->cliprect(), gfx->opaque(m_tmpbitmap, m_tmpbitmap.cliprect(),
m_tiles_rom[col + tile_number * 4 + row * 0x400], m_tiles_rom[col + tile_number * 4 + row * 0x400],
m_palette_bank, m_palette_bank,
0, 0, // flip 0, 0, // flip
@ -228,15 +232,15 @@ void munchmo_state::draw_background(bitmap_ind16 &bitmap, const rectangle &clipr
int const scrollx = -(m_vreg[2] *2 + (m_vreg[3] >> 7)) - 64 - 128 - 16; int const scrollx = -(m_vreg[2] *2 + (m_vreg[3] >> 7)) - 64 - 128 - 16;
int const scrolly = 0; int const scrolly = 0;
copyscrollbitmap(bitmap, *m_tmpbitmap, 1, &scrollx, 1, &scrolly, cliprect); copyscrollbitmap(bitmap, m_tmpbitmap, 1, &scrollx, 1, &scrolly, cliprect);
} }
void munchmo_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect) void munchmo_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect)
{ {
int const scroll = m_vreg[2]; int const scroll = m_vreg[2];
int const flags = m_vreg[3]; // XB?????? int const flags = m_vreg[3]; // XB??????
int const xadjust = - 128 - 16 - ((flags & 0x80) ? 1 : 0); int const xadjust = - 128 - 16 - BIT(flags, 7);
int const bank = (flags & 0x40) ? 1 : 0; int const bank = BIT(flags, 6);
gfx_element *const gfx = m_gfxdecode->gfx(2 + bank); gfx_element *const gfx = m_gfxdecode->gfx(2 + bank);
int const color_base = m_palette_bank * 4 + 3; int const color_base = m_palette_bank * 4 + 3;
int const firstsprite = m_vreg[0] & 0x3f; int const firstsprite = m_vreg[0] & 0x3f;
@ -252,7 +256,7 @@ void munchmo_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect
int sy = (offs >> 6) << 5; // Y YY------ int sy = (offs >> 6) << 5; // Y YY------
sy += (attributes >> 2) & 0x1f; sy += (attributes >> 2) & 0x1f;
if (attributes & 0x80) if (BIT(attributes, 7))
{ {
sx = (sx >> 1) | (tile_number & 0x80); sx = (sx >> 1) | (tile_number & 0x80);
sx = 2 * ((-32 - scroll - sx) & 0xff) + xadjust; sx = 2 * ((-32 - scroll - sx) & 0xff) + xadjust;
@ -300,7 +304,7 @@ void munchmo_state::vblank_irq(int state)
} }
} }
IRQ_CALLBACK_MEMBER(munchmo_state::generic_irq_ack) IRQ_CALLBACK_MEMBER(munchmo_state::irq_ack)
{ {
device.execute().set_input_line(0, CLEAR_LINE); device.execute().set_input_line(0, CLEAR_LINE);
return 0xff; return 0xff;
@ -473,70 +477,52 @@ INPUT_PORTS_END
static const gfx_layout char_layout = static const gfx_layout char_layout =
{ {
8,8, 8,8,
256, RGN_FRAC(1,2),
4, 4,
{ 0, 8, 256*128,256*128+8 }, { 0, 8, RGN_FRAC(1,2), RGN_FRAC(1,2)+8 },
{ 7,6,5,4,3,2,1,0 }, { STEP8(7,-1) },
{ 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16 }, { STEP8(0,8*2) },
128 128
}; };
static const gfx_layout tile_layout = static const gfx_layout tile_layout =
{ {
8,8, 4,8,
0x100, RGN_FRAC(1,1),
4, 4,
{ 8,12,0,4 }, { STEP4(0,4) },
{ 0,0,1,1,2,2,3,3 }, { STEP4(0,1) },
{ 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16 }, { STEP8(0,4*4) },
128 128
}; };
static const gfx_layout sprite_layout1 = static const gfx_layout sprite_layout1 =
{ {
32,32, 16,32,
128, 128,
3, 3,
{ 0x4000*8, 0x2000*8, 0 }, { 0x4000*8, 0x2000*8, 0 },
{ { STEP8(7,-1),STEP8(0x8000+7,-1) },
7,7,6,6,5,5,4,4,3,3,2,2,1,1,0,0, { STEP32(0,8) },
0x8000+7,0x8000+7,0x8000+6,0x8000+6,0x8000+5,0x8000+5,0x8000+4,0x8000+4,
0x8000+3,0x8000+3,0x8000+2,0x8000+2,0x8000+1,0x8000+1,0x8000+0,0x8000+0
},
{
0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8,
8*8, 9*8, 10*8,11*8,12*8,13*8,14*8,15*8,
16*8,17*8,18*8,19*8,20*8,21*8,22*8,23*8,
24*8,25*8,26*8,27*8,28*8,29*8,30*8,31*8
},
256 256
}; };
static const gfx_layout sprite_layout2 = static const gfx_layout sprite_layout2 =
{ {
32,32, 16,32,
128, 128,
3, 3,
{ 0, 0, 0 }, { 0, 0, 0 },
{ { STEP8(7,-1),STEP8(0x8000+7,-1) },
7,7,6,6,5,5,4,4,3,3,2,2,1,1,0,0, { STEP32(0,8) },
0x8000+7,0x8000+7,0x8000+6,0x8000+6,0x8000+5,0x8000+5,0x8000+4,0x8000+4,
0x8000+3,0x8000+3,0x8000+2,0x8000+2,0x8000+1,0x8000+1,0x8000+0,0x8000+0
},
{
0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8,
8*8, 9*8, 10*8,11*8,12*8,13*8,14*8,15*8,
16*8,17*8,18*8,19*8,20*8,21*8,22*8,23*8,
24*8,25*8,26*8,27*8,28*8,29*8,30*8,31*8
},
256 256
}; };
static GFXDECODE_START( gfx_mnchmobl ) static GFXDECODE_START( gfx_mnchmobl )
GFXDECODE_ENTRY( "chars", 0, char_layout, 0, 4 ) // colors 0- 63 GFXDECODE_ENTRY( "chars", 0, char_layout, 0, 4 ) // colors 0- 63
GFXDECODE_ENTRY( "tiles", 0x1000, tile_layout, 64, 4 ) // colors 64-127 GFXDECODE_SCALE( "tiles", 0, tile_layout, 64, 4, 2, 1 ) // colors 64-127
GFXDECODE_ENTRY( "sprites", 0, sprite_layout1, 128, 16 ) // colors 128-255 GFXDECODE_SCALE( "sprites", 0, sprite_layout1, 128, 16, 2, 1 ) // colors 128-255
GFXDECODE_ENTRY( "monochrome_sprites", 0, sprite_layout2, 128, 16 ) // colors 128-255 GFXDECODE_SCALE( "monochrome_sprites", 0, sprite_layout2, 128, 16, 2, 1 ) // colors 128-255
GFXDECODE_END GFXDECODE_END
@ -548,8 +534,6 @@ GFXDECODE_END
void munchmo_state::machine_start() void munchmo_state::machine_start()
{ {
save_item(NAME(m_palette_bank));
save_item(NAME(m_flipscreen));
save_item(NAME(m_nmi_enable)); save_item(NAME(m_nmi_enable));
} }
@ -558,11 +542,11 @@ void munchmo_state::mnchmobl(machine_config &config)
// basic machine hardware // basic machine hardware
Z80(config, m_maincpu, XTAL(15'000'000) / 4); // from pin 13 of XTAL-driven 163 Z80(config, m_maincpu, XTAL(15'000'000) / 4); // from pin 13 of XTAL-driven 163
m_maincpu->set_addrmap(AS_PROGRAM, &munchmo_state::main_map); m_maincpu->set_addrmap(AS_PROGRAM, &munchmo_state::main_map);
m_maincpu->set_irq_acknowledge_callback(FUNC(munchmo_state::generic_irq_ack)); // IORQ clears flip-flop at 1-2C m_maincpu->set_irq_acknowledge_callback(FUNC(munchmo_state::irq_ack)); // IORQ clears flip-flop at 1-2C
Z80(config, m_audiocpu, XTAL(15'000'000) / 8); // from pin 12 of XTAL-driven 163 Z80(config, m_audiocpu, XTAL(15'000'000) / 8); // from pin 12 of XTAL-driven 163
m_audiocpu->set_addrmap(AS_PROGRAM, &munchmo_state::sound_map); m_audiocpu->set_addrmap(AS_PROGRAM, &munchmo_state::sound_map);
m_audiocpu->set_irq_acknowledge_callback(FUNC(munchmo_state::generic_irq_ack)); // IORQ clears flip-flop at 1-7H m_audiocpu->set_irq_acknowledge_callback(FUNC(munchmo_state::irq_ack)); // IORQ clears flip-flop at 1-7H
LS259(config, m_mainlatch, 0); // 12E LS259(config, m_mainlatch, 0); // 12E
m_mainlatch->q_out_cb<0>().set(FUNC(munchmo_state::palette_bank_0_w)); // BCL0 2-11E m_mainlatch->q_out_cb<0>().set(FUNC(munchmo_state::palette_bank_0_w)); // BCL0 2-11E
@ -620,9 +604,11 @@ ROM_START( joyfulr )
ROM_LOAD( "s1.10a", 0x0000, 0x1000, CRC(c0bcc301) SHA1(b8961e7bbced4dfe9c72f839ea9b89d3f2e629b2) ) ROM_LOAD( "s1.10a", 0x0000, 0x1000, CRC(c0bcc301) SHA1(b8961e7bbced4dfe9c72f839ea9b89d3f2e629b2) )
ROM_LOAD( "s2.10b", 0x1000, 0x1000, CRC(96aa11ca) SHA1(84438d6b27d520e95b8706c91c5c20de1785604c) ) ROM_LOAD( "s2.10b", 0x1000, 0x1000, CRC(96aa11ca) SHA1(84438d6b27d520e95b8706c91c5c20de1785604c) )
ROM_REGION( 0x2000, "tiles", 0 ) // 4x8 ROM_REGION( 0x1000, "tilelut", 0 )
ROM_LOAD( "b1.2c", 0x0000, 0x1000, CRC(8ce3a403) SHA1(eec5813076c31bb8534f7d1f83f2a397e552ed69) ) ROM_LOAD( "b1.2c", 0x0000, 0x1000, CRC(8ce3a403) SHA1(eec5813076c31bb8534f7d1f83f2a397e552ed69) )
ROM_LOAD( "b2.2b", 0x1000, 0x1000, CRC(0df28913) SHA1(485700d3b7f2bfcb970e8f9edb7d18ed9a708bd2) )
ROM_REGION( 0x1000, "tiles", 0 ) // 4x8
ROM_LOAD16_WORD_SWAP( "b2.2b", 0x0000, 0x1000, CRC(0df28913) SHA1(485700d3b7f2bfcb970e8f9edb7d18ed9a708bd2) )
ROM_REGION( 0x6000, "sprites", 0 ) ROM_REGION( 0x6000, "sprites", 0 )
ROM_LOAD( "f1j.1g", 0x0000, 0x2000, CRC(93c3c17e) SHA1(902f458c4efe74187a58a3c1ecd146e343657977) ) ROM_LOAD( "f1j.1g", 0x0000, 0x2000, CRC(93c3c17e) SHA1(902f458c4efe74187a58a3c1ecd146e343657977) )
@ -648,9 +634,11 @@ ROM_START( mnchmobl )
ROM_LOAD( "s1.10a", 0x0000, 0x1000, CRC(c0bcc301) SHA1(b8961e7bbced4dfe9c72f839ea9b89d3f2e629b2) ) ROM_LOAD( "s1.10a", 0x0000, 0x1000, CRC(c0bcc301) SHA1(b8961e7bbced4dfe9c72f839ea9b89d3f2e629b2) )
ROM_LOAD( "s2.10b", 0x1000, 0x1000, CRC(96aa11ca) SHA1(84438d6b27d520e95b8706c91c5c20de1785604c) ) ROM_LOAD( "s2.10b", 0x1000, 0x1000, CRC(96aa11ca) SHA1(84438d6b27d520e95b8706c91c5c20de1785604c) )
ROM_REGION( 0x2000, "tiles", 0 ) // 4x8 ROM_REGION( 0x1000, "tilelut", 0 )
ROM_LOAD( "b1.2c", 0x0000, 0x1000, CRC(8ce3a403) SHA1(eec5813076c31bb8534f7d1f83f2a397e552ed69) ) ROM_LOAD( "b1.2c", 0x0000, 0x1000, CRC(8ce3a403) SHA1(eec5813076c31bb8534f7d1f83f2a397e552ed69) )
ROM_LOAD( "b2.2b", 0x1000, 0x1000, CRC(0df28913) SHA1(485700d3b7f2bfcb970e8f9edb7d18ed9a708bd2) )
ROM_REGION( 0x1000, "tiles", 0 ) // 4x8
ROM_LOAD16_WORD_SWAP( "b2.2b", 0x0000, 0x1000, CRC(0df28913) SHA1(485700d3b7f2bfcb970e8f9edb7d18ed9a708bd2) )
ROM_REGION( 0x6000, "sprites", 0 ) ROM_REGION( 0x6000, "sprites", 0 )
ROM_LOAD( "f1.1g", 0x0000, 0x2000, CRC(b75411d4) SHA1(d058a6c219676f8ba4e498215f5716c630bb1d20) ) ROM_LOAD( "f1.1g", 0x0000, 0x2000, CRC(b75411d4) SHA1(d058a6c219676f8ba4e498215f5716c630bb1d20) )