suna8.c: Overhauled the rendering of text sprites, added masking [Luca Elia]

Not perfect yet but improves a few effects compared to PCB videos.
This commit is contained in:
Luca Elia 2015-09-06 15:51:44 +02:00
parent b4a6a32e3b
commit 17d52442ef
3 changed files with 189 additions and 107 deletions

View File

@ -27,8 +27,10 @@ Notes:
- hardhea2: in test mode press P1&P2 button 2 to see a picture of each level
- Rough Ranger default dipswitch settings are based on the settings listed in
the Sharp Image licensed Rough Ranger manaul / NOTICE sheet dated 8-5-88
- starfigh video: http://youtu.be/SIwV7wjvnHM -> missing starfield effect!
the Sharp Image licensed Rough Ranger manual / NOTICE sheet dated 8-5-88
- rranger video: http://www.nicovideo.jp/watch/sm15788808 (not perfect: fireball masking, lev. 5; masking/missing legs, lev. 10)
- hardhead video: https://youtu.be/zamQvXr9_xs
- starfigh video: http://youtu.be/SIwV7wjvnHM (missing starfield effect!)
- brickzn video: http://youtu.be/yfU1C7A3iZI (recorded from v6.0, Joystick version)
***************************************************************************/
@ -1885,7 +1887,7 @@ static MACHINE_CONFIG_START( hardhead, suna8_state )
MCFG_PALETTE_FORMAT(RRRRGGGGBBBBxxxx)
MCFG_PALETTE_ENDIANNESS(ENDIANNESS_BIG)
MCFG_VIDEO_START_OVERRIDE(suna8_state,suna8_textdim12)
MCFG_VIDEO_START_OVERRIDE(suna8_state,suna8_text)
/* sound hardware */
MCFG_SPEAKER_STANDARD_MONO("mono")
@ -1939,7 +1941,7 @@ static MACHINE_CONFIG_START( rranger, suna8_state )
MCFG_PALETTE_FORMAT(RRRRGGGGBBBBxxxx)
MCFG_PALETTE_ENDIANNESS(ENDIANNESS_BIG)
MCFG_VIDEO_START_OVERRIDE(suna8_state,suna8_textdim8)
MCFG_VIDEO_START_OVERRIDE(suna8_state,suna8_text)
/* sound hardware */
MCFG_SPEAKER_STANDARD_MONO("mono")
@ -2921,13 +2923,13 @@ DRIVER_INIT_MEMBER(suna8_state,suna8)
m_bank1->configure_entries(0, 16, memregion("maincpu")->base() + 0x10000, 0x4000);
}
GAME( 1988, sranger, 0, rranger, rranger, suna8_state, suna8, ROT0, "SunA", "Super Ranger (v2.0)", 0 )
GAME( 1988, rranger, sranger, rranger, rranger, suna8_state, suna8, ROT0, "SunA (Sharp Image license)", "Rough Ranger (v2.0)", 0 )
GAME( 1988, rrangerb, sranger, rranger, rranger, suna8_state, suna8, ROT0, "bootleg", "Rough Ranger (v2.0, bootleg)", 0 )
GAME( 1988, srangero, sranger, rranger, rranger, suna8_state, suna8, ROT0, "SunA", "Super Ranger (older)", 0 )
GAME( 1988, srangern, sranger, rranger, rranger, suna8_state, suna8, ROT0, "SunA (NOVA license)", "Super Ranger (older, NOVA license)", 0 )
GAME( 1988, srangerw, sranger, rranger, rranger, suna8_state, suna8, ROT0, "SunA (WDK license)", "Super Ranger (older, WDK license)", 0 )
GAME( 1988, srangerb, sranger, rranger, rranger, suna8_state, suna8, ROT0, "bootleg (NYWA)", "Super Ranger (older, bootleg)", 0 )
GAME( 1988, sranger, 0, rranger, rranger, suna8_state, suna8, ROT0, "SunA", "Super Ranger (v2.0)", MACHINE_IMPERFECT_GRAPHICS )
GAME( 1988, rranger, sranger, rranger, rranger, suna8_state, suna8, ROT0, "SunA (Sharp Image license)", "Rough Ranger (v2.0)", MACHINE_IMPERFECT_GRAPHICS )
GAME( 1988, rrangerb, sranger, rranger, rranger, suna8_state, suna8, ROT0, "bootleg", "Rough Ranger (v2.0, bootleg)", MACHINE_IMPERFECT_GRAPHICS )
GAME( 1988, srangero, sranger, rranger, rranger, suna8_state, suna8, ROT0, "SunA", "Super Ranger (older)", MACHINE_IMPERFECT_GRAPHICS )
GAME( 1988, srangern, sranger, rranger, rranger, suna8_state, suna8, ROT0, "SunA (NOVA license)", "Super Ranger (older, NOVA license)", MACHINE_IMPERFECT_GRAPHICS )
GAME( 1988, srangerw, sranger, rranger, rranger, suna8_state, suna8, ROT0, "SunA (WDK license)", "Super Ranger (older, WDK license)", MACHINE_IMPERFECT_GRAPHICS )
GAME( 1988, srangerb, sranger, rranger, rranger, suna8_state, suna8, ROT0, "bootleg (NYWA)", "Super Ranger (older, bootleg)", MACHINE_IMPERFECT_GRAPHICS )
GAME( 1988, hardhead, 0, hardhead, hardhead, suna8_state, hardhead, ROT0, "SunA", "Hard Head", 0 )
GAME( 1988, hardheadb, hardhead, hardhead, hardhead, suna8_state, hardhedb, ROT0, "bootleg", "Hard Head (bootleg)", 0 )

View File

@ -64,7 +64,7 @@ public:
} m_gfxbank_type;
UINT8 m_gfxbank;
int m_text_dim; // vertical size of the text layer (0 = no text layer)
bool m_has_text; // has text sprites (older games)
// samples
INT16 *m_samplebuf;
@ -148,9 +148,8 @@ public:
DECLARE_DRIVER_INIT(hardhead);
DECLARE_DRIVER_INIT(suna8);
void suna8_vh_start_common(int text_dim, GFXBANK_TYPE_T gfxbank_type);
DECLARE_VIDEO_START(suna8_textdim8);
DECLARE_VIDEO_START(suna8_textdim12);
void suna8_vh_start_common(bool has_text, GFXBANK_TYPE_T gfxbank_type);
DECLARE_VIDEO_START(suna8_text);
DECLARE_VIDEO_START(suna8_sparkman);
DECLARE_VIDEO_START(suna8_brickzn);
DECLARE_VIDEO_START(suna8_starfigh);
@ -168,7 +167,7 @@ public:
void play_sample(int index);
SAMPLES_START_CB_MEMBER(sh_start);
void draw_normal_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect, int which);
void draw_text_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect);
void draw_sprites (screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int start, int end, int which);
void draw_text_sprites(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int start, int end, int ypos, bool write_mask);
UINT8 *brickzn_decrypt();
};

View File

@ -17,49 +17,6 @@
sent to the screen. Each sprite uses 4 bytes, held within the last
page of tiles.
* Note: later games use a more complex format than the following,
which is yet to be completely understood.
[ Sprites Format ]
Offset: Bits: Value:
0.b Y (Bottom up)
1.b 7--- ---- Sprite Size (1 = 2x32 tiles; 0 = 2x2)
2x2 Sprites:
-65- ---- Tiles Row (height = 8 tiles)
---4 ---- Page
2x32 Sprites:
-6-- ---- Ignore X (Multisprite)
--54 ---- Page
---- 3210 Tiles Column (width = 2 tiles)
2.b X
3.b 7--- ----
-6-- ---- X (Sign Bit)
--54 3---
---- -210 Tiles Bank
[ Sprite's Tiles Format ]
Offset: Bits: Value:
0.b Code (Low Bits)
1.b 7--- ---- Flip Y
-6-- ---- Flip X
--54 32-- Color
---- --10 Code (High Bits)
Set TILEMAPS to 1 to debug.
Press Z (you see the "tilemaps" in RAM) or
Press X (you see the "tilemaps" in ROM) then
@ -72,6 +29,7 @@
#include "emu.h"
#include "includes/suna8.h"
#include "drawgfxm.h"
/***************************************************************************
For Debug: there's no tilemap, just sprites.
@ -180,15 +138,15 @@ WRITE8_MEMBER( suna8_state::brickzn_banked_paletteram_w )
void suna8_state::suna8_vh_start_common(int text_dim, GFXBANK_TYPE_T gfxbank_type)
void suna8_state::suna8_vh_start_common(bool has_text, GFXBANK_TYPE_T gfxbank_type)
{
m_text_dim = text_dim;
m_has_text = has_text;
m_spritebank = 0;
m_gfxbank = 0;
m_gfxbank_type = gfxbank_type;
m_palettebank = 0;
if (!m_text_dim)
if (!m_has_text)
{
m_banked_paletteram.allocate(0x200 * 2);
@ -199,17 +157,16 @@ void suna8_state::suna8_vh_start_common(int text_dim, GFXBANK_TYPE_T gfxbank_typ
#if TILEMAPS
m_bg_tilemap = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(suna8_state::get_tile_info),this), TILEMAP_SCAN_COLS,
8, 8, 0x20*(m_text_dim ? 4 : 16), 0x20);
8, 8, 0x20*(m_has_text ? 4 : 16), 0x20);
m_bg_tilemap->set_transparent_pen(15);
#endif
}
VIDEO_START_MEMBER(suna8_state,suna8_textdim8) { suna8_vh_start_common( 8, GFXBANK_TYPE_SPARKMAN); }
VIDEO_START_MEMBER(suna8_state,suna8_textdim12) { suna8_vh_start_common( 12, GFXBANK_TYPE_SPARKMAN); }
VIDEO_START_MEMBER(suna8_state,suna8_sparkman) { suna8_vh_start_common( 0, GFXBANK_TYPE_SPARKMAN); }
VIDEO_START_MEMBER(suna8_state,suna8_brickzn) { suna8_vh_start_common( 0, GFXBANK_TYPE_BRICKZN); }
VIDEO_START_MEMBER(suna8_state,suna8_starfigh) { suna8_vh_start_common( 0, GFXBANK_TYPE_STARFIGH); }
VIDEO_START_MEMBER(suna8_state,suna8_text) { suna8_vh_start_common( true, GFXBANK_TYPE_SPARKMAN); }
VIDEO_START_MEMBER(suna8_state,suna8_sparkman) { suna8_vh_start_common( false, GFXBANK_TYPE_SPARKMAN); }
VIDEO_START_MEMBER(suna8_state,suna8_brickzn) { suna8_vh_start_common( false, GFXBANK_TYPE_BRICKZN); }
VIDEO_START_MEMBER(suna8_state,suna8_starfigh) { suna8_vh_start_common( false, GFXBANK_TYPE_STARFIGH); }
/***************************************************************************
@ -219,17 +176,87 @@ VIDEO_START_MEMBER(suna8_state,suna8_starfigh) { suna8_vh_start_common(
***************************************************************************/
void suna8_state::draw_normal_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect, int which)
#define PIXEL_OP_REBASE_TRANSPEN_PRIORITY_MASK(DEST, PRIORITY, SOURCE) \
do \
{ \
UINT32 srcdata = (SOURCE); \
if (srcdata != trans_pen) \
{ \
if ((PRIORITY) == 0) \
(DEST) = color + srcdata; \
} \
} \
while (0)
class mygfx_element : public gfx_element
{
public:
void prio_mask_transpen(bitmap_ind16 &dest, const rectangle &cliprect,
UINT32 code, UINT32 color, int flipx, int flipy, INT32 destx, INT32 desty,
bitmap_ind8 &priority, UINT32 trans_pen)
{
color = colorbase() + granularity() * (color % colors());
code %= elements();
DRAWGFX_CORE(UINT16, PIXEL_OP_REBASE_TRANSPEN_PRIORITY_MASK, UINT8);
}
};
/***************************************************************************
[ Sprites Format ]
* Note: later games use a more complex format than the following
Offset: Bits: Value:
0.b Y (Bottom up)
1.b 7--- ---- Sprite Size (1 = 2x32 tiles; 0 = 2x2)
2x2 Sprites:
-65- ---- Tiles Row (height = 8 tiles)
---4 ---- Page
2x32 Sprites:
-6-- ---- Ignore X (Multisprite)
--54 ---- Page
---- 3210 Tiles Column (width = 2 tiles)
2.b X
3.b 7--- ---- Text Sprite
-6-- ---- X (Sign Bit) <- Also Set For Text Sprites
--54 3210 Tiles Bank ($400 tiles each)
[ Sprite's Tiles Format ]
Offset: Bits: Value:
0.b Code (Low Bits)
1.b 7--- ---- Flip Y
-6-- ---- Flip X
--54 32-- Color
---- --10 Code (High Bits)
***************************************************************************/
void suna8_state::draw_sprites(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int start, int end, int which)
{
UINT8 *spriteram = m_spriteram + which * 0x2000 * 2;
int i;
int mx = 0; // multisprite x counter
int max_x = m_screen->width() - 8;
int max_y = m_screen->height() - 8;
for (i = 0x1d00; i < 0x2000; i += 4)
if (m_has_text)
screen.priority().fill(0, cliprect);
for (int i = start; i < end; i += 4)
{
int srcpg, srcx,srcy, dimx,dimy, tx, ty;
int gfxbank, colorbank = 0, flipx,flipy, multisprite;
@ -239,9 +266,33 @@ void suna8_state::draw_normal_sprites(bitmap_ind16 &bitmap,const rectangle &clip
int x = spriteram[i + 2];
int bank = spriteram[i + 3];
if (m_text_dim)
bool read_mask = false;
if (m_has_text)
{
// Older, simpler hardware: hardhead, rranger
// rranger (20:18):
// fireball (fe00: 19 00 28 07) not masked by text (fd48: e0 00 00 c0, fd4c: 10 00 00 c0), fire (fdb0: 30 00 00 c0, fdb4: 20 00 00 c0)
// fireball (fe00: 20 00 ba 07) is masked!? But only by fire?
// rranger (33:04, 35:17):
// generally no masking by fire, but there are missing legs on some enemies.
// Could be a sprite limit hit, as there are many sprites on that line, and it's affected by the horizontal (dead) player
read_mask = true;
if ((bank & 0xc0) == 0xc0)
{
// hardhead: fd88/8c/90 -> f994..f9c0
// rranger: fd48/4c -> f980..f9ac
// fdb0/b4 -> f9c0..f9fc
// note: fireballs in level 5 (fe20/40) should go above flames and score (text sprites)
int text_list = (i - start) & 0x20;
int text_start = text_list ? 0x19c0 : 0x1980;
bool write_mask = (text_list == 0); // hack?
draw_text_sprites(screen, bitmap, cliprect, text_start, text_start + 0x80, y, write_mask);
continue;
}
flipx = 0;
flipy = 0;
gfxbank = bank & 0x3f;
@ -263,7 +314,7 @@ void suna8_state::draw_normal_sprites(bitmap_ind16 &bitmap,const rectangle &clip
}
else
{
// Newer, more complex hardware: brickzn, hardhea2, sparkman?, starfigh
// Newer, more complex hardware: brickzn, hardhea2, sparkman, starfigh
switch( code & 0xc0 )
{
case 0xc0:
@ -282,8 +333,8 @@ void suna8_state::draw_normal_sprites(bitmap_ind16 &bitmap,const rectangle &clip
gfxbank = bank & 0x1f;
srcpg = (code >> 4) & 3;
break;
// hardhea2: fire code=52/54 bank=a4; player code=02/04/06 bank=08; arrow:code=16 bank=27
case 0x40:
// hardhea2: fire code=52/54 bank=a4; player code=02/04/06 bank=08; arrow:code=16 bank=27
dimx = 4; dimy = 4;
srcx = (code & 0xe) * 2;
flipx = code & 0x01;
@ -347,7 +398,7 @@ void suna8_state::draw_normal_sprites(bitmap_ind16 &bitmap,const rectangle &clip
x = x - ((bank & 0x40) ? 0x100 : 0);
y = (0x100 - y - dimy*8 ) & 0xff;
/* Multi Sprite */
// Multi Sprite
if ( multisprite ) { mx += dimx*8; x = mx; }
else mx = x;
@ -379,26 +430,52 @@ void suna8_state::draw_normal_sprites(bitmap_ind16 &bitmap,const rectangle &clip
sy = max_y - sy; tile_flipy = !tile_flipy;
}
m_gfxdecode->gfx(which)->transpen(bitmap,cliprect,
tile + (attr & 0x3)*0x100 + gfxbank,
(((attr >> 2) & 0xf) ^ colorbank) + 0x10 * m_palettebank, // player2 in hardhea2 and sparkman
tile_flipx, tile_flipy,
sx, sy, 0xf);
int code = tile + (attr & 0x3)*0x100 + gfxbank;
int color = (((attr >> 2) & 0xf) ^ colorbank) + 0x10 * m_palettebank; // player2 in hardhea2 and sparkman
if (read_mask)
((mygfx_element*)(m_gfxdecode->gfx(which)))->prio_mask_transpen(bitmap, cliprect,
code, color, tile_flipx, tile_flipy, sx, sy, screen.priority(), 0xf);
else
m_gfxdecode->gfx(which)->transpen(bitmap, cliprect,
code, color, tile_flipx, tile_flipy, sx, sy, 0xf);
}
}
}
}
void suna8_state::draw_text_sprites(bitmap_ind16 &bitmap,const rectangle &cliprect)
/***************************************************************************
[ Text Sprites Format ]
Offset: Bits: Value:
0.b Tiles Y (height = 2 tiles)
1.b 7--- ---- 0 = Skip Sprite
-6-- ----
--54 ---- Page
---- 3210 Tiles Column (width = 2 tiles)
2.b X
3.b 7--- ---- 0 = Last Sprite
-6-- ---- X (Sign Bit)
--54 3210 Tiles Bank ($400 tiles each)
Each text sprite is 2x2 tiles
***************************************************************************/
void suna8_state::draw_text_sprites(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int start, int end, int ypos, bool write_mask)
{
UINT8 *spriteram = m_spriteram;
int i;
int max_x = m_screen->width() - 8;
int max_y = m_screen->height() - 8;
for (i = 0x1900; i < 0x19ff; i += 4)
bool last = false;
for (int i = start; i < end && !last; i += 4)
{
int srcpg, srcx,srcy, dimx,dimy, tx, ty;
@ -408,13 +485,13 @@ void suna8_state::draw_text_sprites(bitmap_ind16 &bitmap,const rectangle &clipre
int bank = spriteram[i + 3];
if (~code & 0x80) continue;
last = !(bank & 0x80);
dimx = 2; dimy = m_text_dim;
srcx = (code & 0xf) * 2; srcy = (y & 0xf0) / 8;
dimx = 2; dimy = 2;
srcx = (code & 0xf) * 2; srcy = ((y & 0xf8) - (ypos & 0xf8) - 0x10) / 8;
srcpg = (code >> 4) & 3;
x = x - ((bank & 0x40) ? 0x100 : 0);
y = 0;
bank = (bank & 0x3f) * 0x400;
@ -422,11 +499,9 @@ void suna8_state::draw_text_sprites(bitmap_ind16 &bitmap,const rectangle &clipre
{
for (tx = 0; tx < dimx; tx ++)
{
int real_ty = (ty < (dimy/2)) ? ty : (ty + 0x20 - dimy);
int addr = (srcpg * 0x20 * 0x20) +
((srcx + tx) & 0x1f) * 0x20 +
((srcy + real_ty) & 0x1f);
((srcy + ty) & 0x1f);
int tile = spriteram[addr*2 + 0];
int attr = spriteram[addr*2 + 1];
@ -435,7 +510,7 @@ void suna8_state::draw_text_sprites(bitmap_ind16 &bitmap,const rectangle &clipre
int flipy = attr & 0x80;
int sx = x + tx * 8;
int sy = (y + real_ty * 8) & 0xff;
int sy = (0xf0 - ypos + ty * 8) & 0xff;
if (flip_screen())
{
@ -443,14 +518,24 @@ void suna8_state::draw_text_sprites(bitmap_ind16 &bitmap,const rectangle &clipre
sy = max_y - sy; flipy = !flipy;
}
m_gfxdecode->gfx(0)->transpen(bitmap,cliprect,
m_gfxdecode->gfx(0)->transpen(bitmap, cliprect,
tile + (attr & 0x3)*0x100 + bank,
(attr >> 2) & 0xf,
flipx, flipy,
sx, sy, 0xf);
sx, sy, 0xf );
}
}
}
if (write_mask)
{
// Fill the text sprites row with high priority for masking
int sy = (0xf0 - ypos) & 0xff;
if (flip_screen())
sy = max_y - sy - 8;
rectangle text_clip(cliprect.min_x, cliprect.max_x, sy, sy + 0x10 - 1);
text_clip &= cliprect;
screen.priority().fill(1, text_clip);
}
}
@ -464,7 +549,7 @@ void suna8_state::draw_text_sprites(bitmap_ind16 &bitmap,const rectangle &clipre
UINT32 suna8_state::screen_update_suna8(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
/* see hardhead, hardhea2 test mode (press button 2 for both players) */
// see hardhead, hardhea2 test mode (press button 2 for both players)
bitmap.fill(0xff, cliprect);
#ifdef MAME_DEBUG
@ -481,7 +566,7 @@ UINT32 suna8_state::screen_update_suna8(screen_device &screen, bitmap_ind16 &bit
if (machine().input().code_pressed_once(KEYCODE_S)) { m_trombank++; machine().tilemap().mark_all_dirty(); }
m_trombank &= 0xf;
m_page &= m_text_dim ? 3 : (m_gfxdecode->gfx(1) ? 15 : 7);
m_page &= m_has_text ? 3 : (m_gfxdecode->gfx(1) ? 15 : 7);
m_tiles %= max_tiles;
if (m_tiles < 0) m_tiles += max_tiles;
@ -493,21 +578,17 @@ UINT32 suna8_state::screen_update_suna8(screen_device &screen, bitmap_ind16 &bit
m_rombank, m_palettebank, m_spritebank,
m_page, m_tiles, m_trombank);
#endif
return 0;
}
else
#endif
#endif
{
// Normal sprites
draw_normal_sprites(bitmap,cliprect, 0);
// More normal sprites (second sprite "chip" in sparkman)
if (m_gfxdecode->gfx(1))
draw_normal_sprites(bitmap,cliprect, 1);
// Sprites
draw_sprites(screen, bitmap, cliprect, 0x1d00, 0x2000, 0);
// More sprites (second sprite "chip" in sparkman)
if (m_gfxdecode->gfx(1))
draw_sprites(screen, bitmap, cliprect, 0x1d00, 0x2000, 1);
// Text sprites (earlier games only)
if (m_text_dim)
draw_text_sprites(bitmap,cliprect);
}
return 0;
}