fcombat.cpp : Updates

Simplify handlers, Reduce runtime tag lookups, Unnecessary lines, Fix namings, Spacings, Use shorter / correct type values
This commit is contained in:
cam900 2019-05-23 10:34:34 +09:00
parent 6f91e0a2f4
commit 06587bad72
3 changed files with 92 additions and 94 deletions

View File

@ -48,9 +48,8 @@ INPUT_CHANGED_MEMBER(fcombat_state::coin_inserted)
}
/* is it protection? */
READ8_MEMBER(fcombat_state::fcombat_protection_r)
u8 fcombat_state::protection_r()
{
/* Must match ONE of these values after a "and $3E" intruction :
@ -64,26 +63,26 @@ READ8_MEMBER(fcombat_state::fcombat_protection_r)
/* same as exerion again */
READ8_MEMBER(fcombat_state::fcombat_port01_r)
u8 fcombat_state::port01_r()
{
/* the cocktail flip bit muxes between ports 0 and 1 */
return ioport(m_cocktail_flip ? "IN1" : "IN0")->read();
return m_io_in[m_cocktail_flip ? 1 : 0]->read();
}
//bg scrolls
WRITE8_MEMBER(fcombat_state::e900_w)
void fcombat_state::e900_w(u8 data)
{
m_fcombat_sh = data;
}
WRITE8_MEMBER(fcombat_state::ea00_w)
void fcombat_state::ea00_w(u8 data)
{
m_fcombat_sv = (m_fcombat_sv & 0xff00) | data;
}
WRITE8_MEMBER(fcombat_state::eb00_w)
void fcombat_state::eb00_w(u8 data)
{
m_fcombat_sv = (m_fcombat_sv & 0xff) | (data << 8);
}
@ -91,25 +90,25 @@ WRITE8_MEMBER(fcombat_state::eb00_w)
// terrain info (ec00=x, ed00=y, return val in e300
WRITE8_MEMBER(fcombat_state::ec00_w)
void fcombat_state::ec00_w(u8 data)
{
m_tx = data;
}
WRITE8_MEMBER(fcombat_state::ed00_w)
void fcombat_state::ed00_w(u8 data)
{
m_ty = data;
}
READ8_MEMBER(fcombat_state::e300_r)
u8 fcombat_state::e300_r()
{
int wx = (m_tx + m_fcombat_sh) / 16;
int wy = (m_ty * 2 + m_fcombat_sv) / 16;
const int wx = (m_tx + m_fcombat_sh) / 16;
const int wy = (m_ty * 2 + m_fcombat_sv) / 16;
return memregion("user2")->base()[wx * 32 * 16 + wy];
return m_user2_region[wx * 32 * 16 + wy];
}
WRITE8_MEMBER(fcombat_state::ee00_w)
void fcombat_state::ee00_w(u8 data)
{
}
@ -119,12 +118,12 @@ void fcombat_state::main_map(address_map &map)
map(0xc000, 0xc7ff).ram();
map(0xd000, 0xd7ff).ram().share("videoram");
map(0xd800, 0xd8ff).ram().share("spriteram");
map(0xe000, 0xe000).r(FUNC(fcombat_state::fcombat_port01_r));
map(0xe000, 0xe000).r(FUNC(fcombat_state::port01_r));
map(0xe100, 0xe100).portr("DSW0");
map(0xe200, 0xe200).portr("DSW1");
map(0xe300, 0xe300).r(FUNC(fcombat_state::e300_r));
map(0xe400, 0xe400).r(FUNC(fcombat_state::fcombat_protection_r)); // protection?
map(0xe800, 0xe800).w(FUNC(fcombat_state::fcombat_videoreg_w)); // at least bit 0 for flip screen and joystick input multiplexor
map(0xe400, 0xe400).r(FUNC(fcombat_state::protection_r)); // protection?
map(0xe800, 0xe800).w(FUNC(fcombat_state::videoreg_w)); // at least bit 0 for flip screen and joystick input multiplexor
map(0xe900, 0xe900).w(FUNC(fcombat_state::e900_w));
map(0xea00, 0xea00).w(FUNC(fcombat_state::ea00_w));
map(0xeb00, 0xeb00).w(FUNC(fcombat_state::eb00_w));
@ -149,7 +148,6 @@ void fcombat_state::audio_map(address_map &map)
}
/*************************************
*
* Input ports
@ -228,24 +226,22 @@ static const gfx_layout charlayout =
8,8,
RGN_FRAC(1,1),
2,
{ 0, 4 },
{ 3, 2, 1, 0, 8+3, 8+2, 8+1, 8+0 },
{ 16*0, 16*1, 16*2, 16*3, 16*4, 16*5, 16*6, 16*7 },
{ STEP2(0,4) },
{ STEP4(3,-1), STEP4(4*2+3,-1) },
{ STEP8(0,4*4) },
16*8
};
/* 16 x 16 sprites -- requires reorganizing characters in init_exerion() */
/* 16 x 16 sprites -- requires reorganizing characters in init_fcombat() */
static const gfx_layout spritelayout =
{
16,16,
RGN_FRAC(1,1),
2,
{ 0, 4 },
{ 3, 2, 1, 0, 8+3, 8+2, 8+1, 8+0,
16+3, 16+2, 16+1, 16+0, 24+3, 24+2, 24+1, 24+0 },
{ 32*0, 32*1, 32*2, 32*3, 32*4, 32*5, 32*6, 32*7,
32*8, 32*9, 32*10, 32*11, 32*12, 32*13, 32*14, 32*15 },
{ STEP2(0,4) },
{ STEP4(3,-1), STEP4(4*2+3,-1), STEP4(4*4+3,-1), STEP4(4*6+3,-1) },
{ STEP16(0,4*8) },
64*8
};
@ -300,7 +296,7 @@ void fcombat_state::fcombat(machine_config &config)
/* video hardware */
screen_device &screen(SCREEN(config, "screen", SCREEN_TYPE_RASTER));
screen.set_raw(FCOMBAT_PIXEL_CLOCK, FCOMBAT_HTOTAL, FCOMBAT_HBEND, FCOMBAT_HBSTART, FCOMBAT_VTOTAL, FCOMBAT_VBEND, FCOMBAT_VBSTART);
screen.set_screen_update(FUNC(fcombat_state::screen_update_fcombat));
screen.set_screen_update(FUNC(fcombat_state::screen_update));
screen.set_palette(m_palette);
GFXDECODE(config, m_gfxdecode, m_palette, gfx_fcombat);
@ -327,23 +323,23 @@ void fcombat_state::fcombat(machine_config &config)
void fcombat_state::init_fcombat()
{
/* allocate some temporary space */
std::vector<uint8_t> temp(0x10000);
std::vector<u8> temp(0x10000);
/* make a temporary copy of the character data */
uint8_t *src = &temp[0];
uint8_t *dst = memregion("gfx1")->base();
uint32_t length = memregion("gfx1")->bytes();
u8 *src = &temp[0];
u8 *dst = memregion("gfx1")->base();
u32 length = memregion("gfx1")->bytes();
memcpy(src, dst, length);
/* decode the characters */
/* the bits in the ROM are ordered: n8-n7 n6 n5 n4-v2 v1 v0 n3-n2 n1 n0 h2 */
/* we want them ordered like this: n8-n7 n6 n5 n4-n3 n2 n1 n0-v2 v1 v0 h2 */
for (uint32_t oldaddr = 0; oldaddr < length; oldaddr++)
for (u32 oldaddr = 0; oldaddr < length; oldaddr++)
{
uint32_t newaddr = ((oldaddr ) & 0x1f00) | /* keep n8-n4 */
((oldaddr << 3) & 0x00f0) | /* move n3-n0 */
((oldaddr >> 4) & 0x000e) | /* move v2-v0 */
((oldaddr ) & 0x0001); /* keep h2 */
u32 newaddr = ((oldaddr ) & 0x1f00) | /* keep n8-n4 */
((oldaddr << 3) & 0x00f0) | /* move n3-n0 */
((oldaddr >> 4) & 0x000e) | /* move v2-v0 */
((oldaddr ) & 0x0001); /* keep h2 */
dst[newaddr] = src[oldaddr];
}
@ -357,13 +353,13 @@ void fcombat_state::init_fcombat()
/* the bits in the ROMs are ordered: n9 n8 n3 n7-n6 n5 n4 v3-v2 v1 v0 n2-n1 n0 h3 h2 */
/* we want them ordered like this: n9 n8 n7 n6-n5 n4 n3 n2-n1 n0 v3 v2-v1 v0 h3 h2 */
for (uint32_t oldaddr = 0; oldaddr < length; oldaddr++)
for (u32 oldaddr = 0; oldaddr < length; oldaddr++)
{
uint32_t newaddr = ((oldaddr << 1) & 0x3c00) | /* move n7-n4 */
((oldaddr >> 4) & 0x0200) | /* move n3 */
((oldaddr << 4) & 0x01c0) | /* move n2-n0 */
((oldaddr >> 3) & 0x003c) | /* move v3-v0 */
((oldaddr ) & 0xc003); /* keep n9-n8 h3-h2 */
u32 newaddr = ((oldaddr << 1) & 0x3c00) | /* move n7-n4 */
((oldaddr >> 4) & 0x0200) | /* move n3 */
((oldaddr << 4) & 0x01c0) | /* move n2-n0 */
((oldaddr >> 3) & 0x003c) | /* move v3-v0 */
((oldaddr ) & 0xc003); /* keep n9-n8 h3-h2 */
dst[newaddr] = src[oldaddr];
}
@ -378,22 +374,22 @@ void fcombat_state::init_fcombat()
/* the bits in the ROM are ordered: n8-n7 n6 n5 n4-v2 v1 v0 n3-n2 n1 n0 h2 */
/* we want them ordered like this: n8-n7 n6 n5 n4-n3 n2 n1 n0-v2 v1 v0 h2 */
for (uint32_t oldaddr = 0; oldaddr < length; oldaddr++)
for (u32 oldaddr = 0; oldaddr < length; oldaddr++)
{
uint32_t newaddr = ((oldaddr << 1) & 0x3c00) | /* move n7-n4 */
((oldaddr >> 4) & 0x0200) | /* move n3 */
((oldaddr << 4) & 0x01c0) | /* move n2-n0 */
((oldaddr >> 3) & 0x003c) | /* move v3-v0 */
((oldaddr ) & 0xc003); /* keep n9-n8 h3-h2 */
u32 newaddr = ((oldaddr << 1) & 0x3c00) | /* move n7-n4 */
((oldaddr >> 4) & 0x0200) | /* move n3 */
((oldaddr << 4) & 0x01c0) | /* move n2-n0 */
((oldaddr >> 3) & 0x003c) | /* move v3-v0 */
((oldaddr ) & 0xc003); /* keep n9-n8 h3-h2 */
dst[newaddr] = src[oldaddr];
}
src = &temp[0];
dst = memregion("user1")->base();
length = memregion("user1")->bytes();
dst = memregion("bgdata")->base();
length = memregion("bgdata")->bytes();
memcpy(src, dst, length);
for (uint32_t oldaddr = 0; oldaddr < 32; oldaddr++)
for (u32 oldaddr = 0; oldaddr < 32; oldaddr++)
{
memcpy(&dst[oldaddr * 32 * 8 * 2], &src[oldaddr * 32 * 8], 32 * 8);
memcpy(&dst[oldaddr * 32 * 8 * 2 + 32 * 8], &src[oldaddr * 32 * 8 + 0x2000], 32 * 8);
@ -405,7 +401,7 @@ void fcombat_state::init_fcombat()
length = memregion("user2")->bytes();
memcpy(src, dst, length);
for (uint32_t oldaddr = 0; oldaddr < 32; oldaddr++)
for (u32 oldaddr = 0; oldaddr < 32; oldaddr++)
{
memcpy(&dst[oldaddr * 32 * 8 * 2], &src[oldaddr * 32 * 8], 32 * 8);
memcpy(&dst[oldaddr * 32 * 8 * 2 + 32 * 8], &src[oldaddr * 32 * 8 + 0x2000], 32 * 8);
@ -431,7 +427,7 @@ ROM_START( fcombat )
ROM_REGION( 0x04000, "gfx3", 0 )
ROM_LOAD( "fcombat6.f3", 0x00000, 0x4000, CRC(97282729) SHA1(72db0593551c2d15631341bf621b96013b46ce72) )
ROM_REGION( 0x04000, "user1", 0 )
ROM_REGION( 0x04000, "bgdata", 0 )
ROM_LOAD( "fcombat5.l3", 0x00000, 0x4000, CRC(96194ca7) SHA1(087d6ac8f93f087cb5e378dbe9a8cfcffa2cdddc) ) /* bg data */
ROM_REGION( 0x04000, "user2", 0 )

View File

@ -37,6 +37,9 @@ public:
driver_device(mconfig, type, tag),
m_videoram(*this, "videoram"),
m_spriteram(*this, "spriteram"),
m_bgdata_rom(*this, "bgdata"),
m_user2_region(*this, "user2"),
m_io_in(*this, "IN%u", 0U),
m_maincpu(*this, "maincpu"),
m_gfxdecode(*this, "gfxdecode"),
m_palette(*this, "palette")
@ -50,15 +53,19 @@ public:
private:
/* memory pointers */
required_shared_ptr<uint8_t> m_videoram;
required_shared_ptr<uint8_t> m_spriteram;
required_shared_ptr<u8> m_videoram;
required_shared_ptr<u8> m_spriteram;
required_region_ptr<u8> m_bgdata_rom;
required_region_ptr<u8> m_user2_region;
required_ioport_array<2> m_io_in;
/* video-related */
tilemap_t *m_bgmap;
uint8_t m_cocktail_flip;
uint8_t m_char_palette;
uint8_t m_sprite_palette;
uint8_t m_char_bank;
u8 m_cocktail_flip;
u8 m_char_palette;
u8 m_sprite_palette;
u8 m_char_bank;
/* misc */
int m_fcombat_sh;
@ -71,22 +78,22 @@ private:
required_device<gfxdecode_device> m_gfxdecode;
required_device<palette_device> m_palette;
DECLARE_READ8_MEMBER(fcombat_protection_r);
DECLARE_READ8_MEMBER(fcombat_port01_r);
DECLARE_WRITE8_MEMBER(e900_w);
DECLARE_WRITE8_MEMBER(ea00_w);
DECLARE_WRITE8_MEMBER(eb00_w);
DECLARE_WRITE8_MEMBER(ec00_w);
DECLARE_WRITE8_MEMBER(ed00_w);
DECLARE_READ8_MEMBER(e300_r);
DECLARE_WRITE8_MEMBER(ee00_w);
DECLARE_WRITE8_MEMBER(fcombat_videoreg_w);
u8 protection_r();
u8 port01_r();
void e900_w(u8 data);
void ea00_w(u8 data);
void eb00_w(u8 data);
void ec00_w(u8 data);
void ed00_w(u8 data);
u8 e300_r();
void ee00_w(u8 data);
void videoreg_w(u8 data);
TILE_GET_INFO_MEMBER(get_bg_tile_info);
virtual void machine_start() override;
virtual void machine_reset() override;
virtual void video_start() override;
void fcombat_palette(palette_device &palette) const;
uint32_t screen_update_fcombat(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
u32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
void audio_map(address_map &map);
void main_map(address_map &map);
};

View File

@ -16,8 +16,8 @@ TILE_GET_INFO_MEMBER(fcombat_state::get_bg_tile_info)
//palno = (tile_index - (tile_index / 32 * 16) * 32 * 16) / 32;
tileno = memregion("user1")->base()[tile_index];
palno = 0x18; //memregion("user2")->base()[tile_index] >> 3;
tileno = m_bgdata_rom[tile_index];
palno = 0x18; //m_user2_region[tile_index] >> 3;
SET_TILE_INFO_MEMBER(2, tileno, palno, 0);
}
@ -41,7 +41,7 @@ TILE_GET_INFO_MEMBER(fcombat_state::get_bg_tile_info)
void fcombat_state::fcombat_palette(palette_device &palette) const
{
const uint8_t *color_prom = memregion("proms")->base();
const u8 *color_prom = memregion("proms")->base();
// create a lookup table for the palette
for (int i = 0; i < 0x20; i++)
@ -52,19 +52,19 @@ void fcombat_state::fcombat_palette(palette_device &palette) const
bit0 = BIT(color_prom[i], 0);
bit1 = BIT(color_prom[i], 1);
bit2 = BIT(color_prom[i], 2);
int const r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
const u8 r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
// green component
bit0 = BIT(color_prom[i], 3);
bit1 = BIT(color_prom[i], 4);
bit2 = BIT(color_prom[i], 5);
int const g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
const u8 g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
// blue component
bit0 = 0;
bit1 = BIT(color_prom[i], 6);
bit2 = BIT(color_prom[i], 7);
int const b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
const u8 b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
palette.set_indirect_color(i, rgb_t(r, g, b));
}
@ -75,20 +75,19 @@ void fcombat_state::fcombat_palette(palette_device &palette) const
// fg chars/sprites
for (int i = 0; i < 0x200; i++)
{
uint8_t const ctabentry = (color_prom[(i & 0x1c0) | ((i & 3) << 4) | ((i >> 2) & 0x0f)] & 0x0f) | 0x10;
const u8 ctabentry = (color_prom[(i & 0x1c0) | ((i & 3) << 4) | ((i >> 2) & 0x0f)] & 0x0f) | 0x10;
palette.set_pen_indirect(i, ctabentry);
}
// bg chars (this is not the full story... there are four layers mixed using another PROM
for (int i = 0x200; i < 0x300; i++)
{
uint8_t const ctabentry = color_prom[i] & 0x0f;
const u8 ctabentry = color_prom[i] & 0x0f;
palette.set_pen_indirect(i, ctabentry);
}
}
/*************************************
*
* Video system startup
@ -101,14 +100,13 @@ void fcombat_state::video_start()
}
/*************************************
*
* Video register I/O
*
*************************************/
WRITE8_MEMBER(fcombat_state::fcombat_videoreg_w)
void fcombat_state::videoreg_w(u8 data)
{
/* bit 0 = flip screen and joystick input multiplexor */
m_cocktail_flip = data & 1;
@ -127,11 +125,8 @@ WRITE8_MEMBER(fcombat_state::fcombat_videoreg_w)
}
uint32_t fcombat_state::screen_update_fcombat(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
u32 fcombat_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
int sx, sy, offs, i;
/* draw background */
m_bgmap->set_scrolly(0, m_fcombat_sh);
m_bgmap->set_scrollx(0, m_fcombat_sv - 24);
@ -141,7 +136,7 @@ uint32_t fcombat_state::screen_update_fcombat(screen_device &screen, bitmap_ind1
//draw_background(bitmap, cliprect);
/* draw sprites */
for (i = 0; i < m_spriteram.bytes(); i += 4)
for (int i = 0; i < m_spriteram.bytes(); i += 4)
{
int flags = m_spriteram[i + 0];
int y = m_spriteram[i + 1] ^ 255;
@ -150,12 +145,12 @@ uint32_t fcombat_state::screen_update_fcombat(screen_device &screen, bitmap_ind1
int xflip = flags & 0x80;
int yflip = flags & 0x40;
int doubled =0;// flags & 0x10;
int wide = flags & 0x08;
bool doubled = false;// flags & 0x10;
const bool wide = flags & 0x08;
int code2 = code;
int color = ((flags >> 1) & 0x03) | ((code >> 5) & 0x04) | (code & 0x08) | (m_sprite_palette * 16);
gfx_element *gfx = m_gfxdecode->gfx(1);
gfx_element *gfx = m_gfxdecode->gfx(1);
if (m_cocktail_flip)
{
@ -176,7 +171,7 @@ uint32_t fcombat_state::screen_update_fcombat(screen_device &screen, bitmap_ind1
gfx->transpen(bitmap,cliprect, code2, color, xflip, yflip, x, y + gfx->height(), 0);
}
if(flags&0x10)
if (flags & 0x10)
{
gfx->transpen(bitmap,cliprect, code2 + 16, color, xflip, yflip, x, y + gfx->height(), 0);
gfx->transpen(bitmap,cliprect, code2 + 16 * 2, color, xflip, yflip, x, y + 2 * gfx->height(), 0);
@ -190,13 +185,13 @@ uint32_t fcombat_state::screen_update_fcombat(screen_device &screen, bitmap_ind1
}
/* draw the visible text layer */
for (sy = VISIBLE_Y_MIN/8; sy < VISIBLE_Y_MAX/8; sy++)
for (sx = VISIBLE_X_MIN/8; sx < VISIBLE_X_MAX/8; sx++)
for (int sy = VISIBLE_Y_MIN/8; sy < VISIBLE_Y_MAX/8; sy++)
for (int sx = VISIBLE_X_MIN/8; sx < VISIBLE_X_MAX/8; sx++)
{
int x = m_cocktail_flip ? (63 * 8 - 8 * sx) : 8 * sx;
int y = m_cocktail_flip ? (31 * 8 - 8 * sy) : 8 * sy;
offs = sx + sy * 64;
const int offs = sx + sy * 64;
m_gfxdecode->gfx(0)->transpen(bitmap,cliprect,
m_videoram[offs] + 256 * m_char_bank,
((m_videoram[offs] & 0xf0) >> 4) + m_char_palette * 16,