(MESS) Modernized neogeo pocket video. (nw)

This commit is contained in:
Wilbert Pol 2013-05-11 20:24:53 +00:00
parent 5e08cacd1e
commit 9683567f9a
3 changed files with 256 additions and 320 deletions

View File

@ -168,7 +168,7 @@ public:
required_device<dac_device> m_dac_l;
required_device<dac_device> m_dac_r;
required_shared_ptr<UINT8> m_mainram;
required_device<device_t> m_k1ge;
required_device<k1ge_device> m_k1ge;
DECLARE_READ8_MEMBER( ngp_io_r );
DECLARE_WRITE8_MEMBER( ngp_io_w );
@ -183,8 +183,8 @@ public:
DECLARE_WRITE8_MEMBER( ngp_z80_clear_irq );
DECLARE_WRITE8_MEMBER( ngp_vblank_pin_w );
DECLARE_WRITE8_MEMBER( ngp_hblank_pin_w );
DECLARE_WRITE_LINE_MEMBER( ngp_vblank_pin_w );
DECLARE_WRITE_LINE_MEMBER( ngp_hblank_pin_w );
DECLARE_WRITE8_MEMBER( ngp_tlcs900_to3 );
UINT32 screen_update_ngp(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
DECLARE_INPUT_CHANGED_MEMBER(power_callback);
@ -541,7 +541,7 @@ static ADDRESS_MAP_START( ngp_mem, AS_PROGRAM, 8, ngp_state )
AM_RANGE( 0x000080, 0x0000bf ) AM_READWRITE(ngp_io_r, ngp_io_w) /* ngp/c specific i/o */
AM_RANGE( 0x004000, 0x006fff ) AM_RAM AM_SHARE("mainram") /* work ram */
AM_RANGE( 0x007000, 0x007fff ) AM_RAM AM_SHARE("share1") /* shared with sound cpu */
AM_RANGE( 0x008000, 0x0087ff ) AM_DEVREADWRITE_LEGACY("k1ge", k1ge_r, k1ge_w) /* video registers */
AM_RANGE( 0x008000, 0x0087ff ) AM_DEVREADWRITE("k1ge", k1ge_device, read, write) /* video registers */
AM_RANGE( 0x008800, 0x00bfff ) AM_RAM AM_REGION("vram", 0x800 ) /* Video RAM area */
AM_RANGE( 0x200000, 0x3fffff ) AM_ROM AM_WRITE(flash0_w) AM_REGION("cart", 0) /* cart area #1 */
AM_RANGE( 0x800000, 0x9fffff ) AM_ROM AM_WRITE(flash1_w) AM_REGION("cart", 0x200000) /* cart area #2 */
@ -614,15 +614,15 @@ static INPUT_PORTS_START( ngp )
INPUT_PORTS_END
WRITE8_MEMBER( ngp_state::ngp_vblank_pin_w )
WRITE_LINE_MEMBER( ngp_state::ngp_vblank_pin_w )
{
m_tlcs900->set_input_line(TLCS900_INT4, data ? ASSERT_LINE : CLEAR_LINE );
m_tlcs900->set_input_line(TLCS900_INT4, state ? ASSERT_LINE : CLEAR_LINE );
}
WRITE8_MEMBER( ngp_state::ngp_hblank_pin_w )
WRITE_LINE_MEMBER( ngp_state::ngp_hblank_pin_w )
{
m_tlcs900->set_input_line(TLCS900_TIO, data ? ASSERT_LINE : CLEAR_LINE );
m_tlcs900->set_input_line(TLCS900_TIO, state ? ASSERT_LINE : CLEAR_LINE );
}
@ -696,7 +696,7 @@ void ngp_state::machine_reset()
UINT32 ngp_state::screen_update_ngp(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
k1ge_update( m_k1ge, bitmap, cliprect );
m_k1ge->update( bitmap, cliprect );
return 0;
}
@ -787,15 +787,6 @@ void ngp_state::nvram_write(emu_file &file)
}
static const k1ge_interface ngp_k1ge_interface =
{
"screen",
"vram",
DEVCB_DRIVER_MEMBER( ngp_state, ngp_vblank_pin_w ),
DEVCB_DRIVER_MEMBER( ngp_state, ngp_hblank_pin_w )
};
static const tlcs900_interface ngp_tlcs900_interface =
{
DEVCB_NULL,
@ -838,7 +829,7 @@ static MACHINE_CONFIG_DERIVED( ngp, ngp_common )
MCFG_PALETTE_LENGTH( 8 )
MCFG_PALETTE_INIT( k1ge )
MCFG_K1GE_ADD( "k1ge", XTAL_6_144MHz, ngp_k1ge_interface )
MCFG_K1GE_ADD( "k1ge", XTAL_6_144MHz, "screen", "vram", WRITELINE( ngp_state, ngp_vblank_pin_w ), WRITELINE( ngp_state, ngp_hblank_pin_w ) )
MCFG_CARTSLOT_ADD("cart")
MCFG_CARTSLOT_EXTENSION_LIST("bin,ngp,npc,ngc")
@ -858,7 +849,7 @@ static MACHINE_CONFIG_DERIVED( ngpc, ngp_common )
MCFG_PALETTE_LENGTH( 4096 )
MCFG_PALETTE_INIT( k2ge )
MCFG_K2GE_ADD( "k1ge", XTAL_6_144MHz, ngp_k1ge_interface )
MCFG_K2GE_ADD( "k1ge", XTAL_6_144MHz, "screen", "vram", WRITELINE( ngp_state, ngp_vblank_pin_w ), WRITELINE( ngp_state, ngp_hblank_pin_w ) )
MCFG_CARTSLOT_ADD("cart")
MCFG_CARTSLOT_EXTENSION_LIST("bin,ngp,npc,ngc")

View File

@ -10,22 +10,6 @@ used in the Neogeo pocket color.
#include "emu.h"
#include "k1ge.h"
struct k1ge_t
{
const k1ge_interface *intf;
screen_device *screen;
devcb_resolved_write8 vblank_pin_w;
devcb_resolved_write8 hblank_pin_w;
UINT8 *vram;
UINT8 wba_h, wba_v, wsi_h, wsi_v;
void (*draw)( device_t *device, int line );
emu_timer *timer;
emu_timer *hblank_on_timer;
bitmap_ind16 *bitmap;
};
PALETTE_INIT( k1ge )
{
@ -57,42 +41,29 @@ PALETTE_INIT( k2ge )
}
INLINE k1ge_t *get_safe_token( device_t *device )
READ8_MEMBER( k1ge_device::read )
{
assert( device != NULL );
assert( device->type() == K1GE || device->type() == K2GE );
return ( k1ge_t *) downcast<k1ge_device *>(device)->token();
}
READ8_DEVICE_HANDLER( k1ge_r )
{
k1ge_t *k1ge = get_safe_token( device );
UINT8 data = k1ge->vram[offset & 0x7ff];
UINT8 data = m_vram[offset & 0x7ff];
switch( offset )
{
case 0x008: /* RAS.H */
data = k1ge->screen->hpos() >> 2;
data = m_screen->hpos() >> 2;
break;
case 0x009: /* RAS.V */
data = k1ge->screen->vpos();
data = m_screen->vpos();
break;
}
return data;
}
WRITE8_DEVICE_HANDLER( k1ge_w )
WRITE8_MEMBER( k1ge_device::write )
{
k1ge_t *k1ge = get_safe_token( device );
switch( offset )
{
case 0x000:
if (!k1ge->vblank_pin_w.isnull())
k1ge->vblank_pin_w(0, ( data & 0x80 ) ? ( ( k1ge->vram[0x010] & 0x40 ) ? 1 : 0 ) : 0 );
m_vblank_pin_w( ( data & 0x80 ) ? ( ( m_vram[0x010] & 0x40 ) ? 1 : 0 ) : 0 );
break;
case 0x030:
data &= 0x80;
@ -106,7 +77,7 @@ WRITE8_DEVICE_HANDLER( k1ge_w )
data &= 0x07;
break;
case 0x7e2:
if ( k1ge->vram[0x7f0] != 0xAA )
if ( m_vram[0x7f0] != 0xAA )
return;
data &= 0x80;
break;
@ -118,11 +89,11 @@ WRITE8_DEVICE_HANDLER( k1ge_w )
data &= 0x0f;
}
k1ge->vram[offset & 0x7ff] = data;
m_vram[offset & 0x7ff] = data;
}
INLINE void k1ge_draw_scroll_plane( k1ge_t *k1ge, UINT16 *p, UINT16 base, int line, int scroll_x, int scroll_y, int pal_base )
void k1ge_device::draw_scroll_plane( UINT16 *p, UINT16 base, int line, int scroll_x, int scroll_y, int pal_base )
{
int i;
int offset_x = ( scroll_x >> 3 ) * 2;
@ -136,7 +107,7 @@ INLINE void k1ge_draw_scroll_plane( k1ge_t *k1ge, UINT16 *p, UINT16 base, int li
base += ( ( ( ( scroll_y + line ) >> 3 ) * 0x0040 ) & 0x7ff );
/* setup */
map_data = k1ge->vram[ base + offset_x ] | ( k1ge->vram[ base + offset_x + 1 ] << 8 );
map_data = m_vram[ base + offset_x ] | ( m_vram[ base + offset_x + 1 ] << 8 );
hflip = map_data & 0x8000;
pcode = pal_base + ( ( map_data & 0x2000 ) ? 4 : 0 );
tile_addr = 0x2000 + ( ( map_data & 0x1ff ) * 16 );
@ -144,7 +115,7 @@ INLINE void k1ge_draw_scroll_plane( k1ge_t *k1ge, UINT16 *p, UINT16 base, int li
tile_addr += ( 7 - ( ( scroll_y + line ) & 0x07 ) ) * 2;
else
tile_addr += ( ( scroll_y + line ) & 0x07 ) * 2;
tile_data = k1ge->vram[ tile_addr ] | ( k1ge->vram[ tile_addr + 1 ] << 8 );
tile_data = m_vram[ tile_addr ] | ( m_vram[ tile_addr + 1 ] << 8 );
if ( hflip )
tile_data >>= 2 * ( scroll_x & 0x07 );
else
@ -168,14 +139,14 @@ INLINE void k1ge_draw_scroll_plane( k1ge_t *k1ge, UINT16 *p, UINT16 base, int li
if ( col )
{
p[ i ] = k1ge->vram[ pcode + col ];
p[ i ] = m_vram[ pcode + col ];
}
px++;
if ( px >= 8 )
{
offset_x = ( offset_x + 2 ) & 0x3f;
map_data = k1ge->vram[ base + offset_x ] | ( k1ge->vram[ base + offset_x + 1 ] << 8 );
map_data = m_vram[ base + offset_x ] | ( m_vram[ base + offset_x + 1 ] << 8 );
hflip = map_data & 0x8000;
pcode = pal_base + ( ( map_data & 0x2000 ) ? 4 : 0 );
tile_addr = 0x2000 + ( ( map_data & 0x1ff ) * 16 );
@ -183,14 +154,14 @@ INLINE void k1ge_draw_scroll_plane( k1ge_t *k1ge, UINT16 *p, UINT16 base, int li
tile_addr += ( 7 - ( ( scroll_y + line ) & 0x07 ) ) * 2;
else
tile_addr += ( ( scroll_y + line ) & 0x07 ) * 2;
tile_data = k1ge->vram[ tile_addr ] | ( k1ge->vram[ tile_addr + 1 ] << 8 );
tile_data = m_vram[ tile_addr ] | ( m_vram[ tile_addr + 1 ] << 8 );
px = 0;
}
}
}
INLINE void k1ge_draw_sprite_plane( k1ge_t *k1ge, UINT16 *p, UINT16 priority, int line, int scroll_x, int scroll_y )
void k1ge_device::draw_sprite_plane( UINT16 *p, UINT16 priority, int line, int scroll_x, int scroll_y )
{
struct {
UINT16 spr_data;
@ -207,9 +178,9 @@ INLINE void k1ge_draw_sprite_plane( k1ge_t *k1ge, UINT16 *p, UINT16 priority, in
/* Select sprites */
for ( i = 0; i < 256; i += 4 )
{
UINT16 spr_data = k1ge->vram[ 0x800 + i ] | ( k1ge->vram[ 0x801 + i ] << 8 );
UINT8 x = k1ge->vram[ 0x802 + i ];
UINT8 y = k1ge->vram[ 0x803 + i ];
UINT16 spr_data = m_vram[ 0x800 + i ] | ( m_vram[ 0x801 + i ] << 8 );
UINT8 x = m_vram[ 0x802 + i ];
UINT8 y = m_vram[ 0x803 + i ];
spr_x = ( spr_data & 0x0400 ) ? ( spr_x + x ) : ( scroll_x + x );
spr_y = ( spr_data & 0x0200 ) ? ( spr_y + y ) : ( scroll_y + y );
@ -239,7 +210,7 @@ INLINE void k1ge_draw_sprite_plane( k1ge_t *k1ge, UINT16 *p, UINT16 priority, in
tile_addr += ( 7 - ( ( line - spr[i].y ) & 0x07 ) ) * 2;
else
tile_addr += ( ( line - spr[i].y ) & 0x07 ) * 2;
tile_data = k1ge->vram[ tile_addr ] | ( k1ge->vram[ tile_addr + 1 ] << 8 );
tile_data = m_vram[ tile_addr ] | ( m_vram[ tile_addr + 1 ] << 8 );
for ( j = 0; j < 8; j++ )
{
@ -260,21 +231,20 @@ INLINE void k1ge_draw_sprite_plane( k1ge_t *k1ge, UINT16 *p, UINT16 priority, in
if ( spr_x < 160 && col )
{
p[ spr_x ] = k1ge->vram[ pcode + col ];
p[ spr_x ] = m_vram[ pcode + col ];
}
}
}
}
static void k1ge_draw( device_t *device, int line )
void k1ge_device::draw( int line )
{
k1ge_t *k1ge = get_safe_token( device );
UINT16 *p = &k1ge->bitmap->pix16(line);
UINT16 oowcol = k1ge->vram[0x012] & 0x07;
UINT16 *p = &m_bitmap->pix16(line);
UINT16 oowcol = m_vram[0x012] & 0x07;
int i;
if ( line < k1ge->wba_v || line >= k1ge->wba_v + k1ge->wsi_v )
if ( line < m_wba_v || line >= m_wba_v + m_wsi_v )
{
for( i = 0; i < 160; i++ )
{
@ -283,52 +253,52 @@ static void k1ge_draw( device_t *device, int line )
}
else
{
UINT16 col = ( ( k1ge->vram[0x118] & 0xc0 ) == 0x80 ) ? k1ge->vram[0x118] & 0x07 : 0;
UINT16 col = ( ( m_vram[0x118] & 0xc0 ) == 0x80 ) ? m_vram[0x118] & 0x07 : 0;
for ( i = 0; i < 160; i++ )
p[i] = col;
if ( k1ge->vram[0x030] & 0x80 )
if ( m_vram[0x030] & 0x80 )
{
/* Draw sprites with 01 priority */
k1ge_draw_sprite_plane( k1ge, p, 1, line, k1ge->vram[0x020], k1ge->vram[0x021] );
draw_sprite_plane( p, 1, line, m_vram[0x020], m_vram[0x021] );
/* Draw PF1 */
k1ge_draw_scroll_plane( k1ge, p, 0x1000, line, k1ge->vram[0x032], k1ge->vram[0x033], 0x108 );
draw_scroll_plane( p, 0x1000, line, m_vram[0x032], m_vram[0x033], 0x108 );
/* Draw sprites with 10 priority */
k1ge_draw_sprite_plane( k1ge, p, 2, line, k1ge->vram[0x020], k1ge->vram[0x021] );
draw_sprite_plane( p, 2, line, m_vram[0x020], m_vram[0x021] );
/* Draw PF2 */
k1ge_draw_scroll_plane( k1ge, p, 0x1800, line, k1ge->vram[0x034], k1ge->vram[0x035], 0x110 );
draw_scroll_plane( p, 0x1800, line, m_vram[0x034], m_vram[0x035], 0x110 );
/* Draw sprites with 11 priority */
k1ge_draw_sprite_plane( k1ge, p, 3, line, k1ge->vram[0x020], k1ge->vram[0x021] );
draw_sprite_plane( p, 3, line, m_vram[0x020], m_vram[0x021] );
}
else
{
/* Draw sprites with 01 priority */
k1ge_draw_sprite_plane( k1ge, p, 1, line, k1ge->vram[0x020], k1ge->vram[0x021] );
draw_sprite_plane( p, 1, line, m_vram[0x020], m_vram[0x021] );
/* Draw PF2 */
k1ge_draw_scroll_plane( k1ge, p, 0x1800, line, k1ge->vram[0x034], k1ge->vram[0x035], 0x110 );
draw_scroll_plane( p, 0x1800, line, m_vram[0x034], m_vram[0x035], 0x110 );
/* Draw sprites with 10 priority */
k1ge_draw_sprite_plane( k1ge, p, 2, line, k1ge->vram[0x020], k1ge->vram[0x021] );
draw_sprite_plane( p, 2, line, m_vram[0x020], m_vram[0x021] );
/* Draw PF1 */
k1ge_draw_scroll_plane( k1ge, p, 0x1000, line, k1ge->vram[0x032], k1ge->vram[0x033], 0x108 );
draw_scroll_plane( p, 0x1000, line, m_vram[0x032], m_vram[0x033], 0x108 );
/* Draw sprites with 11 priority */
k1ge_draw_sprite_plane( k1ge, p, 3, line, k1ge->vram[0x020], k1ge->vram[0x021] );
draw_sprite_plane( p, 3, line, m_vram[0x020], m_vram[0x021] );
}
for( i = 0; i < k1ge->wba_h; i++ )
for( i = 0; i < m_wba_h; i++ )
{
p[i] = oowcol;
}
for( i = k1ge->wba_h + k1ge->wsi_h; i < 160; i++ )
for( i = m_wba_h + m_wsi_h; i < 160; i++ )
{
p[i] = oowcol;
}
@ -336,7 +306,7 @@ static void k1ge_draw( device_t *device, int line )
}
INLINE void k2ge_draw_scroll_plane( k1ge_t *k1ge, UINT16 *p, UINT16 base, int line, int scroll_x, int scroll_y, UINT16 pal_base )
void k2ge_device::draw_scroll_plane( UINT16 *p, UINT16 base, int line, int scroll_x, int scroll_y, UINT16 pal_base )
{
int i;
int offset_x = ( scroll_x >> 3 ) * 2;
@ -350,7 +320,7 @@ INLINE void k2ge_draw_scroll_plane( k1ge_t *k1ge, UINT16 *p, UINT16 base, int li
base += ( ( ( ( scroll_y + line ) >> 3 ) * 0x0040 ) & 0x7ff );
/* setup */
map_data = k1ge->vram[ base + offset_x ] | ( k1ge->vram[ base + offset_x + 1 ] << 8 );
map_data = m_vram[ base + offset_x ] | ( m_vram[ base + offset_x + 1 ] << 8 );
hflip = map_data & 0x8000;
pcode = pal_base + ( ( map_data & 0x1e00 ) >> 6 );
tile_addr = 0x2000 + ( ( map_data & 0x1ff ) * 16 );
@ -358,7 +328,7 @@ INLINE void k2ge_draw_scroll_plane( k1ge_t *k1ge, UINT16 *p, UINT16 base, int li
tile_addr += ( 7 - ( ( scroll_y + line ) & 0x07 ) ) * 2;
else
tile_addr += ( ( scroll_y + line ) & 0x07 ) * 2;
tile_data = k1ge->vram[ tile_addr ] | ( k1ge->vram[ tile_addr + 1 ] << 8 );
tile_data = m_vram[ tile_addr ] | ( m_vram[ tile_addr + 1 ] << 8 );
if ( hflip )
tile_data >>= 2 * ( scroll_x & 0x07 );
else
@ -382,14 +352,14 @@ INLINE void k2ge_draw_scroll_plane( k1ge_t *k1ge, UINT16 *p, UINT16 base, int li
if ( col )
{
p[ i ] = k1ge->vram[ pcode + col * 2 ] | ( k1ge->vram[ pcode + col * 2 + 1 ] << 8 );
p[ i ] = m_vram[ pcode + col * 2 ] | ( m_vram[ pcode + col * 2 + 1 ] << 8 );
}
px++;
if ( px >= 8 )
{
offset_x = ( offset_x + 2 ) & 0x3f;
map_data = k1ge->vram[ base + offset_x ] | ( k1ge->vram[ base + offset_x + 1 ] << 8 );
map_data = m_vram[ base + offset_x ] | ( m_vram[ base + offset_x + 1 ] << 8 );
hflip = map_data & 0x8000;
pcode = pal_base + ( ( map_data & 0x1e00 ) >> 6 );
tile_addr = 0x2000 + ( ( map_data & 0x1ff ) * 16 );
@ -397,14 +367,14 @@ INLINE void k2ge_draw_scroll_plane( k1ge_t *k1ge, UINT16 *p, UINT16 base, int li
tile_addr += ( 7 - ( ( scroll_y + line ) & 0x07 ) ) * 2;
else
tile_addr += ( ( scroll_y + line ) & 0x07 ) * 2;
tile_data = k1ge->vram[ tile_addr ] | ( k1ge->vram[ tile_addr + 1 ] << 8 );
tile_data = m_vram[ tile_addr ] | ( m_vram[ tile_addr + 1 ] << 8 );
px = 0;
}
}
}
INLINE void k2ge_draw_sprite_plane( k1ge_t *k1ge, UINT16 *p, UINT16 priority, int line, int scroll_x, int scroll_y )
void k2ge_device::draw_sprite_plane( UINT16 *p, UINT16 priority, int line, int scroll_x, int scroll_y )
{
struct {
UINT16 spr_data;
@ -422,9 +392,9 @@ INLINE void k2ge_draw_sprite_plane( k1ge_t *k1ge, UINT16 *p, UINT16 priority, in
/* Select sprites */
for ( i = 0; i < 256; i += 4 )
{
UINT16 spr_data = k1ge->vram[ 0x800 + i ] | ( k1ge->vram[ 0x801 + i ] << 8 );
UINT8 x = k1ge->vram[ 0x802 + i ];
UINT8 y = k1ge->vram[ 0x803 + i ];
UINT16 spr_data = m_vram[ 0x800 + i ] | ( m_vram[ 0x801 + i ] << 8 );
UINT8 x = m_vram[ 0x802 + i ];
UINT8 y = m_vram[ 0x803 + i ];
spr_x = ( spr_data & 0x0400 ) ? ( spr_x + x ) : ( scroll_x + x );
spr_y = ( spr_data & 0x0200 ) ? ( spr_y + y ) : ( scroll_y + y );
@ -448,14 +418,14 @@ INLINE void k2ge_draw_sprite_plane( k1ge_t *k1ge, UINT16 *p, UINT16 priority, in
int j;
UINT16 tile_addr;
UINT16 tile_data;
UINT16 pcode = 0x0200 + ( ( k1ge->vram[0x0c00 + spr[i].index ] & 0x0f ) << 3 );
UINT16 pcode = 0x0200 + ( ( m_vram[0x0c00 + spr[i].index ] & 0x0f ) << 3 );
tile_addr = 0x2000 + ( ( spr[i].spr_data & 0x1ff ) * 16 );
if ( spr[i].spr_data & 0x4000 )
tile_addr += ( 7 - ( ( line - spr[i].y ) & 0x07 ) ) * 2;
else
tile_addr += ( ( line - spr[i].y ) & 0x07 ) * 2;
tile_data = k1ge->vram[ tile_addr ] | ( k1ge->vram[ tile_addr + 1 ] << 8 );
tile_data = m_vram[ tile_addr ] | ( m_vram[ tile_addr + 1 ] << 8 );
for ( j = 0; j < 8; j++ )
{
@ -476,14 +446,14 @@ INLINE void k2ge_draw_sprite_plane( k1ge_t *k1ge, UINT16 *p, UINT16 priority, in
if ( spr_x < 160 && col )
{
p[ spr_x ] = k1ge->vram[ pcode + col * 2 ] | ( k1ge->vram[ pcode + col * 2 + 1 ] << 8 );
p[ spr_x ] = m_vram[ pcode + col * 2 ] | ( m_vram[ pcode + col * 2 + 1 ] << 8 );
}
}
}
}
INLINE void k2ge_k1ge_draw_scroll_plane( k1ge_t *k1ge, UINT16 *p, UINT16 base, int line, int scroll_x, int scroll_y, UINT16 pal_lut_base, UINT16 k2ge_lut_base )
void k2ge_device::k1ge_draw_scroll_plane( UINT16 *p, UINT16 base, int line, int scroll_x, int scroll_y, UINT16 pal_lut_base, UINT16 k2ge_lut_base )
{
int i;
int offset_x = ( scroll_x >> 3 ) * 2;
@ -497,7 +467,7 @@ INLINE void k2ge_k1ge_draw_scroll_plane( k1ge_t *k1ge, UINT16 *p, UINT16 base, i
base += ( ( ( ( scroll_y + line ) >> 3 ) * 0x0040 ) & 0x7ff );
/* setup */
map_data = k1ge->vram[ base + offset_x ] | ( k1ge->vram[ base + offset_x + 1 ] << 8 );
map_data = m_vram[ base + offset_x ] | ( m_vram[ base + offset_x + 1 ] << 8 );
hflip = map_data & 0x8000;
pcode = ( map_data & 0x2000 ) ? 1 : 0;
tile_addr = 0x2000 + ( ( map_data & 0x1ff ) * 16 );
@ -505,7 +475,7 @@ INLINE void k2ge_k1ge_draw_scroll_plane( k1ge_t *k1ge, UINT16 *p, UINT16 base, i
tile_addr += ( 7 - ( ( scroll_y + line ) & 0x07 ) ) * 2;
else
tile_addr += ( ( scroll_y + line ) & 0x07 ) * 2;
tile_data = k1ge->vram[ tile_addr ] | ( k1ge->vram[ tile_addr + 1 ] << 8 );
tile_data = m_vram[ tile_addr ] | ( m_vram[ tile_addr + 1 ] << 8 );
if ( hflip )
tile_data >>= 2 * ( scroll_x & 0x07 );
else
@ -529,15 +499,15 @@ INLINE void k2ge_k1ge_draw_scroll_plane( k1ge_t *k1ge, UINT16 *p, UINT16 base, i
if ( col )
{
UINT16 col2 = 16 * pcode + ( k1ge->vram[ pal_lut_base + 4 * pcode + col ] * 2 );
p[ i ] = k1ge->vram[ k2ge_lut_base + col2 ] | ( k1ge->vram[ k2ge_lut_base + col2 + 1 ] << 8 );
UINT16 col2 = 16 * pcode + ( m_vram[ pal_lut_base + 4 * pcode + col ] * 2 );
p[ i ] = m_vram[ k2ge_lut_base + col2 ] | ( m_vram[ k2ge_lut_base + col2 + 1 ] << 8 );
}
px++;
if ( px >= 8 )
{
offset_x = ( offset_x + 2 ) & 0x3f;
map_data = k1ge->vram[ base + offset_x ] | ( k1ge->vram[ base + offset_x + 1 ] << 8 );
map_data = m_vram[ base + offset_x ] | ( m_vram[ base + offset_x + 1 ] << 8 );
hflip = map_data & 0x8000;
pcode = ( map_data & 0x2000 ) ? 1 : 0;
tile_addr = 0x2000 + ( ( map_data & 0x1ff ) * 16 );
@ -545,14 +515,14 @@ INLINE void k2ge_k1ge_draw_scroll_plane( k1ge_t *k1ge, UINT16 *p, UINT16 base, i
tile_addr += ( 7 - ( ( scroll_y + line ) & 0x07 ) ) * 2;
else
tile_addr += ( ( scroll_y + line ) & 0x07 ) * 2;
tile_data = k1ge->vram[ tile_addr ] | ( k1ge->vram[ tile_addr + 1 ] << 8 );
tile_data = m_vram[ tile_addr ] | ( m_vram[ tile_addr + 1 ] << 8 );
px = 0;
}
}
}
INLINE void k2ge_k1ge_draw_sprite_plane( k1ge_t *k1ge, UINT16 *p, UINT16 priority, int line, int scroll_x, int scroll_y )
void k2ge_device::k1ge_draw_sprite_plane( UINT16 *p, UINT16 priority, int line, int scroll_x, int scroll_y )
{
struct {
UINT16 spr_data;
@ -569,9 +539,9 @@ INLINE void k2ge_k1ge_draw_sprite_plane( k1ge_t *k1ge, UINT16 *p, UINT16 priorit
/* Select sprites */
for ( i = 0; i < 256; i += 4 )
{
UINT16 spr_data = k1ge->vram[ 0x800 + i ] | ( k1ge->vram[ 0x801 + i ] << 8 );
UINT8 x = k1ge->vram[ 0x802 + i ];
UINT8 y = k1ge->vram[ 0x803 + i ];
UINT16 spr_data = m_vram[ 0x800 + i ] | ( m_vram[ 0x801 + i ] << 8 );
UINT8 x = m_vram[ 0x802 + i ];
UINT8 y = m_vram[ 0x803 + i ];
spr_x = ( spr_data & 0x0400 ) ? ( spr_x + x ) : ( scroll_x + x );
spr_y = ( spr_data & 0x0200 ) ? ( spr_y + y ) : ( scroll_y + y );
@ -601,7 +571,7 @@ INLINE void k2ge_k1ge_draw_sprite_plane( k1ge_t *k1ge, UINT16 *p, UINT16 priorit
tile_addr += ( 7 - ( ( line - spr[i].y ) & 0x07 ) ) * 2;
else
tile_addr += ( ( line - spr[i].y ) & 0x07 ) * 2;
tile_data = k1ge->vram[ tile_addr ] | ( k1ge->vram[ tile_addr + 1 ] << 8 );
tile_data = m_vram[ tile_addr ] | ( m_vram[ tile_addr + 1 ] << 8 );
for ( j = 0; j < 8; j++ )
{
@ -622,26 +592,25 @@ INLINE void k2ge_k1ge_draw_sprite_plane( k1ge_t *k1ge, UINT16 *p, UINT16 priorit
if ( spr_x < 160 && col )
{
UINT16 col2 = 16 * pcode + k1ge->vram[ 0x100 + 4 * pcode + col ] * 2;
p[ spr_x ] = k1ge->vram[ 0x380 + col2 ] | ( k1ge->vram[ 0x381 + col2 ] << 8 );
UINT16 col2 = 16 * pcode + m_vram[ 0x100 + 4 * pcode + col ] * 2;
p[ spr_x ] = m_vram[ 0x380 + col2 ] | ( m_vram[ 0x381 + col2 ] << 8 );
}
}
}
}
static void k2ge_draw( device_t *device, int line )
void k2ge_device::draw( int line )
{
k1ge_t *k1ge = get_safe_token( device );
UINT16 *p = &k1ge->bitmap->pix16(line);
UINT16 *p = &m_bitmap->pix16(line);
UINT16 col = 0;
UINT16 oowcol;
int i;
oowcol = ( k1ge->vram[0x012] & 0x07 ) * 2;
oowcol = k1ge->vram[0x3f0 + oowcol ] | ( k1ge->vram[0x3f1 + oowcol ] << 8 );
oowcol = ( m_vram[0x012] & 0x07 ) * 2;
oowcol = m_vram[0x3f0 + oowcol ] | ( m_vram[0x3f1 + oowcol ] << 8 );
if ( line < k1ge->wba_v || line >= k1ge->wba_v + k1ge->wsi_v )
if ( line < m_wba_v || line >= m_wba_v + m_wsi_v )
{
for( i = 0; i < 160; i++ )
{
@ -651,11 +620,11 @@ static void k2ge_draw( device_t *device, int line )
else
{
/* Determine the background color */
if ( ( k1ge->vram[0x118] & 0xc0 ) == 0x80 )
if ( ( m_vram[0x118] & 0xc0 ) == 0x80 )
{
col = ( k1ge->vram[0x118] & 0x07 ) * 2;
col = ( m_vram[0x118] & 0x07 ) * 2;
}
col = k1ge->vram[0x3e0 + col ] | ( k1ge->vram[0x3e1 + col ] << 8 );
col = m_vram[0x3e0 + col ] | ( m_vram[0x3e1 + col ] << 8 );
/* Set the bacground color */
for ( i = 0; i < 160; i++ )
@ -663,89 +632,89 @@ static void k2ge_draw( device_t *device, int line )
p[i] = col;
}
if ( k1ge->vram[0x7e2] & 0x80 )
if ( m_vram[0x7e2] & 0x80 )
{
/* K1GE compatibility mode */
if ( k1ge->vram[0x030] & 0x80 )
if ( m_vram[0x030] & 0x80 )
{
/* Draw sprites with 01 priority */
k2ge_k1ge_draw_sprite_plane( k1ge, p, 1, line, k1ge->vram[0x020], k1ge->vram[0x021] );
k1ge_draw_sprite_plane( p, 1, line, m_vram[0x020], m_vram[0x021] );
/* Draw PF1 */
k2ge_k1ge_draw_scroll_plane( k1ge, p, 0x1000, line, k1ge->vram[0x032], k1ge->vram[0x033], 0x108, 0x3a0 );
k1ge_draw_scroll_plane( p, 0x1000, line, m_vram[0x032], m_vram[0x033], 0x108, 0x3a0 );
/* Draw sprites with 10 priority */
k2ge_k1ge_draw_sprite_plane( k1ge, p, 2, line, k1ge->vram[0x020], k1ge->vram[0x021] );
k1ge_draw_sprite_plane( p, 2, line, m_vram[0x020], m_vram[0x021] );
/* Draw PF2 */
k2ge_k1ge_draw_scroll_plane( k1ge, p, 0x1800, line, k1ge->vram[0x034], k1ge->vram[0x035], 0x110, 0x3c0 );
k1ge_draw_scroll_plane( p, 0x1800, line, m_vram[0x034], m_vram[0x035], 0x110, 0x3c0 );
/* Draw sprites with 11 priority */
k2ge_k1ge_draw_sprite_plane( k1ge, p, 3, line, k1ge->vram[0x020], k1ge->vram[0x021] );
k1ge_draw_sprite_plane( p, 3, line, m_vram[0x020], m_vram[0x021] );
}
else
{
/* Draw sprites with 01 priority */
k2ge_k1ge_draw_sprite_plane( k1ge, p, 1, line, k1ge->vram[0x020], k1ge->vram[0x021] );
k1ge_draw_sprite_plane( p, 1, line, m_vram[0x020], m_vram[0x021] );
/* Draw PF2 */
k2ge_k1ge_draw_scroll_plane( k1ge, p, 0x1800, line, k1ge->vram[0x034], k1ge->vram[0x035], 0x110, 0x3c0 );
k1ge_draw_scroll_plane( p, 0x1800, line, m_vram[0x034], m_vram[0x035], 0x110, 0x3c0 );
/* Draw sprites with 10 priority */
k2ge_k1ge_draw_sprite_plane( k1ge, p, 2, line, k1ge->vram[0x020], k1ge->vram[0x021] );
k1ge_draw_sprite_plane( p, 2, line, m_vram[0x020], m_vram[0x021] );
/* Draw PF1 */
k2ge_k1ge_draw_scroll_plane( k1ge, p, 0x1000, line, k1ge->vram[0x032], k1ge->vram[0x033], 0x108, 0x3a0 );
k1ge_draw_scroll_plane( p, 0x1000, line, m_vram[0x032], m_vram[0x033], 0x108, 0x3a0 );
/* Draw sprites with 11 priority */
k2ge_k1ge_draw_sprite_plane( k1ge, p, 3, line, k1ge->vram[0x020], k1ge->vram[0x021] );
k1ge_draw_sprite_plane( p, 3, line, m_vram[0x020], m_vram[0x021] );
}
}
else
{
/* K2GE mode */
if ( k1ge->vram[0x030] & 0x80 )
if ( m_vram[0x030] & 0x80 )
{
/* Draw sprites with 01 priority */
k2ge_draw_sprite_plane( k1ge, p, 1, line, k1ge->vram[0x020], k1ge->vram[0x021] );
draw_sprite_plane( p, 1, line, m_vram[0x020], m_vram[0x021] );
/* Draw PF1 */
k2ge_draw_scroll_plane( k1ge, p, 0x1000, line, k1ge->vram[0x032], k1ge->vram[0x033], 0x280 );
draw_scroll_plane( p, 0x1000, line, m_vram[0x032], m_vram[0x033], 0x280 );
/* Draw sprites with 10 priority */
k2ge_draw_sprite_plane( k1ge, p, 2, line, k1ge->vram[0x020], k1ge->vram[0x021] );
draw_sprite_plane( p, 2, line, m_vram[0x020], m_vram[0x021] );
/* Draw PF2 */
k2ge_draw_scroll_plane( k1ge, p, 0x1800, line, k1ge->vram[0x034], k1ge->vram[0x035], 0x300 );
draw_scroll_plane( p, 0x1800, line, m_vram[0x034], m_vram[0x035], 0x300 );
/* Draw sprites with 11 priority */
k2ge_draw_sprite_plane( k1ge, p, 3, line, k1ge->vram[0x020], k1ge->vram[0x021] );
draw_sprite_plane( p, 3, line, m_vram[0x020], m_vram[0x021] );
}
else
{
/* Draw sprites with 01 priority */
k2ge_draw_sprite_plane( k1ge, p, 1, line, k1ge->vram[0x020], k1ge->vram[0x021] );
draw_sprite_plane( p, 1, line, m_vram[0x020], m_vram[0x021] );
/* Draw PF2 */
k2ge_draw_scroll_plane( k1ge, p, 0x1800, line, k1ge->vram[0x034], k1ge->vram[0x035], 0x300 );
draw_scroll_plane( p, 0x1800, line, m_vram[0x034], m_vram[0x035], 0x300 );
/* Draw sprites with 10 priority */
k2ge_draw_sprite_plane( k1ge, p, 2, line, k1ge->vram[0x020], k1ge->vram[0x021] );
draw_sprite_plane( p, 2, line, m_vram[0x020], m_vram[0x021] );
/* Draw PF1 */
k2ge_draw_scroll_plane( k1ge, p, 0x1000, line, k1ge->vram[0x032], k1ge->vram[0x033], 0x280 );
draw_scroll_plane( p, 0x1000, line, m_vram[0x032], m_vram[0x033], 0x280 );
/* Draw sprites with 11 priority */
k2ge_draw_sprite_plane( k1ge, p, 3, line, k1ge->vram[0x020], k1ge->vram[0x021] );
draw_sprite_plane( p, 3, line, m_vram[0x020], m_vram[0x021] );
}
}
for ( i = 0; i < k1ge->wba_h; i++ )
for ( i = 0; i < m_wba_h; i++ )
{
p[i] = oowcol;
}
for ( i = k1ge->wba_h + k1ge->wsi_h; i < 160; i++ )
for ( i = m_wba_h + m_wsi_h; i < 160; i++ )
{
p[i] = oowcol;
}
@ -753,184 +722,148 @@ static void k2ge_draw( device_t *device, int line )
}
static TIMER_CALLBACK( k1ge_hblank_on_timer_callback )
TIMER_CALLBACK_MEMBER( k1ge_device::hblank_on_timer_callback )
{
device_t *device = (device_t *)ptr;
k1ge_t *k1ge = get_safe_token( device );
if (!k1ge->hblank_pin_w.isnull())
k1ge->hblank_pin_w(0, 0);
m_hblank_pin_w(0);
}
static TIMER_CALLBACK( k1ge_timer_callback )
TIMER_CALLBACK_MEMBER( k1ge_device::timer_callback )
{
device_t *device = (device_t *)ptr;
k1ge_t *k1ge = get_safe_token( device );
int y = k1ge->screen->vpos();
int y = m_screen->vpos();
/* Check for start of VBlank */
if ( y >= 152 )
{
k1ge->vram[0x010] |= 0x40;
if ((k1ge->vram[0x000] & 0x80 ) && !k1ge->vblank_pin_w.isnull())
k1ge->vblank_pin_w(0, 1);
m_vram[0x010] |= 0x40;
if (m_vram[0x000] & 0x80)
{
m_vblank_pin_w(1);
}
}
/* Check for end of VBlank */
if ( y == 0 )
{
k1ge->wba_h = k1ge->vram[0x002];
k1ge->wba_v = k1ge->vram[0x003];
k1ge->wsi_h = k1ge->vram[0x004];
k1ge->wsi_v = k1ge->vram[0x005];
k1ge->vram[0x010] &= ~ 0x40;
if ((k1ge->vram[0x000] & 0x80 ) && !k1ge->vblank_pin_w.isnull())
k1ge->vblank_pin_w(0, 0);
m_wba_h = m_vram[0x002];
m_wba_v = m_vram[0x003];
m_wsi_h = m_vram[0x004];
m_wsi_v = m_vram[0x005];
m_vram[0x010] &= ~ 0x40;
if (m_vram[0x000] & 0x80)
{
m_vblank_pin_w(0);
}
}
/* Check if Hint should be triggered */
if ( y == K1GE_SCREEN_HEIGHT - 1 || y < 151 )
{
if (!k1ge->hblank_pin_w.isnull())
if (!m_hblank_pin_w.isnull())
{
if ( k1ge->vram[0x000] & 0x40 )
k1ge->hblank_pin_w(0, 1);
k1ge->hblank_on_timer->adjust( k1ge->screen->time_until_pos(y, 480 ) );
if (m_vram[0x000] & 0x40)
{
m_hblank_pin_w(1);
}
m_hblank_on_timer->adjust( m_screen->time_until_pos(y, 480 ) );
}
}
/* Draw a line when inside visible area */
if ( y && y < 153 )
{
k1ge->draw( device, y - 1 );
draw( y - 1 );
}
k1ge->timer->adjust( k1ge->screen->time_until_pos(( y + 1 ) % K1GE_SCREEN_HEIGHT, 0 ) );
m_timer->adjust( m_screen->time_until_pos(( y + 1 ) % K1GE_SCREEN_HEIGHT, 0 ) );
}
void k1ge_update( device_t *device, bitmap_ind16 &bitmap, const rectangle &cliprect )
void k1ge_device::update( bitmap_ind16 &bitmap, const rectangle &cliprect )
{
k1ge_t *k1ge = get_safe_token( device );
copybitmap( bitmap, *k1ge->bitmap, 0, 0, 0, 0, cliprect );
copybitmap( bitmap, *m_bitmap, 0, 0, 0, 0, cliprect );
}
static DEVICE_START( k1ge )
{
k1ge_t *k1ge = get_safe_token( device );
k1ge->intf = (const k1ge_interface*)device->static_config();
k1ge->vblank_pin_w.resolve(k1ge->intf->vblank_pin_w, *device);
k1ge->hblank_pin_w.resolve(k1ge->intf->hblank_pin_w, *device);
k1ge->timer = device->machine().scheduler().timer_alloc(FUNC(k1ge_timer_callback), (void *) device );
k1ge->hblank_on_timer = device->machine().scheduler().timer_alloc(FUNC(k1ge_hblank_on_timer_callback), (void *) device );
k1ge->screen = device->machine().device<screen_device>(k1ge->intf->screen_tag);
k1ge->vram = device->machine().root_device().memregion( k1ge->intf->vram_tag )->base();
k1ge->bitmap = auto_bitmap_ind16_alloc( device->machine(), k1ge->screen->width(), k1ge->screen->height() );
k1ge->draw = k1ge_draw;
}
static DEVICE_START( k2ge )
{
k1ge_t *k1ge = get_safe_token( device );
DEVICE_START_CALL( k1ge );
k1ge->draw = k2ge_draw;
}
static DEVICE_RESET( k1ge )
{
k1ge_t *k1ge = get_safe_token( device );
k1ge->vram[0x000] = 0x00; /* Interrupt enable */
k1ge->vram[0x002] = 0x00; /* WBA.H */
k1ge->vram[0x003] = 0x00; /* WVA.V */
k1ge->vram[0x004] = 0xFF; /* WSI.H */
k1ge->vram[0x005] = 0xFF; /* WSI.V */
k1ge->vram[0x007] = 0xc6; /* REF */
k1ge->vram[0x012] = 0x00; /* 2D control */
k1ge->vram[0x020] = 0x00; /* PO.H */
k1ge->vram[0x021] = 0x00; /* PO.V */
k1ge->vram[0x030] = 0x00; /* PF */
k1ge->vram[0x032] = 0x00; /* S1SO.H */
k1ge->vram[0x033] = 0x00; /* S1SO.V */
k1ge->vram[0x034] = 0x00; /* S2SO.H */
k1ge->vram[0x035] = 0x00; /* S2SO.V */
k1ge->vram[0x101] = 0x07; /* SPPLT01 */
k1ge->vram[0x102] = 0x07; /* SPPLT02 */
k1ge->vram[0x103] = 0x07; /* SPPLT03 */
k1ge->vram[0x105] = 0x07; /* SPPLT11 */
k1ge->vram[0x106] = 0x07; /* SPPLT12 */
k1ge->vram[0x107] = 0x07; /* SPPLT13 */
k1ge->vram[0x109] = 0x07; /* SC1PLT01 */
k1ge->vram[0x10a] = 0x07; /* SC1PLT02 */
k1ge->vram[0x10b] = 0x07; /* SC1PLT03 */
k1ge->vram[0x10d] = 0x07; /* SC1PLT11 */
k1ge->vram[0x10e] = 0x07; /* SC1PLT12 */
k1ge->vram[0x10f] = 0x07; /* SC1PLT13 */
k1ge->vram[0x111] = 0x07; /* SC2PLT01 */
k1ge->vram[0x112] = 0x07; /* SC2PLT02 */
k1ge->vram[0x113] = 0x07; /* SC2PLT03 */
k1ge->vram[0x115] = 0x07; /* SC2PLT11 */
k1ge->vram[0x116] = 0x07; /* SC2PLT12 */
k1ge->vram[0x117] = 0x07; /* SC2PLT13 */
k1ge->vram[0x118] = 0x07; /* BG */
k1ge->vram[0x400] = 0xFF; /* LED control */
k1ge->vram[0x402] = 0x80; /* LEDFREG */
k1ge->vram[0x7e0] = 0x52; /* RESET */
k1ge->vram[0x7e2] = 0x00; /* MODE */
k1ge->timer->adjust( k1ge->screen->time_until_pos(( k1ge->screen->vpos() + 1 ) % K1GE_SCREEN_HEIGHT, 0 ) );
}
const device_type K1GE = &device_creator<k1ge_device>;
k1ge_device::k1ge_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, K1GE, "K1GE Monochrome Graphics + LCD", tag, owner, clock)
{
m_token = global_alloc_clear(k1ge_t);
}
k1ge_device::k1ge_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, type, name, tag, owner, clock)
{
m_token = global_alloc_clear(k1ge_t);
}
//-------------------------------------------------
// device_config_complete - perform any
// operations now that the configuration is
// complete
//-------------------------------------------------
void k1ge_device::device_config_complete()
{
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void k1ge_device::device_start()
{
DEVICE_START_NAME( k1ge )(this);
m_vblank_pin_w.resolve();
m_hblank_pin_w.resolve();
m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(k1ge_device::timer_callback), this));
m_hblank_on_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(k1ge_device::hblank_on_timer_callback), this));
m_screen = machine().device<screen_device>(m_screen_tag);
m_vram = machine().root_device().memregion( m_vram_tag )->base();
m_bitmap = auto_bitmap_ind16_alloc( machine(), m_screen->width(), m_screen->height() );
}
//-------------------------------------------------
// device_reset - device-specific reset
//-------------------------------------------------
void k1ge_device::device_reset()
{
DEVICE_RESET_NAME( k1ge )(this);
m_vram[0x000] = 0x00; /* Interrupt enable */
m_vram[0x002] = 0x00; /* WBA.H */
m_vram[0x003] = 0x00; /* WVA.V */
m_vram[0x004] = 0xFF; /* WSI.H */
m_vram[0x005] = 0xFF; /* WSI.V */
m_vram[0x007] = 0xc6; /* REF */
m_vram[0x012] = 0x00; /* 2D control */
m_vram[0x020] = 0x00; /* PO.H */
m_vram[0x021] = 0x00; /* PO.V */
m_vram[0x030] = 0x00; /* PF */
m_vram[0x032] = 0x00; /* S1SO.H */
m_vram[0x033] = 0x00; /* S1SO.V */
m_vram[0x034] = 0x00; /* S2SO.H */
m_vram[0x035] = 0x00; /* S2SO.V */
m_vram[0x101] = 0x07; /* SPPLT01 */
m_vram[0x102] = 0x07; /* SPPLT02 */
m_vram[0x103] = 0x07; /* SPPLT03 */
m_vram[0x105] = 0x07; /* SPPLT11 */
m_vram[0x106] = 0x07; /* SPPLT12 */
m_vram[0x107] = 0x07; /* SPPLT13 */
m_vram[0x109] = 0x07; /* SC1PLT01 */
m_vram[0x10a] = 0x07; /* SC1PLT02 */
m_vram[0x10b] = 0x07; /* SC1PLT03 */
m_vram[0x10d] = 0x07; /* SC1PLT11 */
m_vram[0x10e] = 0x07; /* SC1PLT12 */
m_vram[0x10f] = 0x07; /* SC1PLT13 */
m_vram[0x111] = 0x07; /* SC2PLT01 */
m_vram[0x112] = 0x07; /* SC2PLT02 */
m_vram[0x113] = 0x07; /* SC2PLT03 */
m_vram[0x115] = 0x07; /* SC2PLT11 */
m_vram[0x116] = 0x07; /* SC2PLT12 */
m_vram[0x117] = 0x07; /* SC2PLT13 */
m_vram[0x118] = 0x07; /* BG */
m_vram[0x400] = 0xFF; /* LED control */
m_vram[0x402] = 0x80; /* LEDFREG */
m_vram[0x7e0] = 0x52; /* RESET */
m_vram[0x7e2] = 0x00; /* MODE */
m_timer->adjust( m_screen->time_until_pos(( m_screen->vpos() + 1 ) % K1GE_SCREEN_HEIGHT, 0 ) );
}
const device_type K1GE = &device_creator<k1ge_device>;
k1ge_device::k1ge_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, K1GE, "K1GE Monochrome Graphics + LCD", tag, owner, clock)
, m_vblank_pin_w(*this)
, m_hblank_pin_w(*this)
{
}
k1ge_device::k1ge_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, type, name, tag, owner, clock)
, m_vblank_pin_w(*this)
, m_hblank_pin_w(*this)
{
}
@ -941,11 +874,3 @@ k2ge_device::k2ge_device(const machine_config &mconfig, const char *tag, device_
{
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void k2ge_device::device_start()
{
DEVICE_START_NAME( k2ge )(this);
}

View File

@ -5,7 +5,19 @@
#include "devcb.h"
#define K1GE_SCREEN_HEIGHT 199
#define MCFG_K1GE_ADD(_tag, _clock, _screen, _vram, _vblank, _hblank ) \
MCFG_DEVICE_ADD( _tag, K1GE, _clock ) \
k1ge_device::static_set_screen( *device, _screen ); \
k1ge_device::static_set_vram( *device, _vram ); \
devcb = &k1ge_device::static_set_vblank_callback( *device, DEVCB2_##_vblank ); \
devcb = &k1ge_device::static_set_hblank_callback( *device, DEVCB2_##_hblank );
#define MCFG_K2GE_ADD(_tag, _clock, _screen, _vram, _vblank, _hblank ) \
MCFG_DEVICE_ADD( _tag, K2GE, _clock ) \
k1ge_device::static_set_screen( *device, _screen ); \
k1ge_device::static_set_vram( *device, _vram ); \
devcb = &k1ge_device::static_set_vblank_callback( *device, DEVCB2_##_vblank ); \
devcb = &k1ge_device::static_set_hblank_callback( *device, DEVCB2_##_hblank );
class k1ge_device : public device_t
@ -13,60 +25,68 @@ class k1ge_device : public device_t
public:
k1ge_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
k1ge_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock);
~k1ge_device() { global_free(m_token); }
// access to legacy token
void *token() const { assert(m_token != NULL); return m_token; }
DECLARE_READ8_MEMBER( read );
DECLARE_WRITE8_MEMBER( write );
void update( bitmap_ind16 &bitmap, const rectangle &cliprect );
// Static methods
static void static_set_screen(device_t &device, const char *screen_name) { downcast<k1ge_device &>(device).m_screen_tag = screen_name; }
static void static_set_vram(device_t &device, const char *vram_name) { downcast<k1ge_device &>(device).m_vram_tag = vram_name; }
template<class _Object> static devcb2_base &static_set_vblank_callback(device_t &device, _Object object) { return downcast<k1ge_device &>(device).m_vblank_pin_w.set_callback(object); }
template<class _Object> static devcb2_base &static_set_hblank_callback(device_t &device, _Object object) { return downcast<k1ge_device &>(device).m_hblank_pin_w.set_callback(object); }
static const int K1GE_SCREEN_HEIGHT = 199;
protected:
// device-level overrides
virtual void device_config_complete();
virtual void device_start();
virtual void device_reset();
private:
// internal state
void *m_token;
const char *m_screen_tag;
const char *m_vram_tag;
screen_device *m_screen;
devcb2_write_line m_vblank_pin_w;
devcb2_write_line m_hblank_pin_w;
UINT8 *m_vram;
UINT8 m_wba_h, m_wba_v, m_wsi_h, m_wsi_v;
emu_timer *m_timer;
emu_timer *m_hblank_on_timer;
bitmap_ind16 *m_bitmap;
virtual void draw(int line);
void draw_scroll_plane( UINT16 *p, UINT16 base, int line, int scroll_x, int scroll_y, int pal_base );
void draw_sprite_plane( UINT16 *p, UINT16 priority, int line, int scroll_x, int scroll_y );
TIMER_CALLBACK_MEMBER( hblank_on_timer_callback );
TIMER_CALLBACK_MEMBER( timer_callback );
};
extern const device_type K1GE;
class k2ge_device : public k1ge_device
{
public:
k2ge_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
protected:
// device-level overrides
virtual void device_start();
};
virtual void draw(int line);
extern const device_type K2GE;
void draw_scroll_plane( UINT16 *p, UINT16 base, int line, int scroll_x, int scroll_y, UINT16 pal_base );
void draw_sprite_plane( UINT16 *p, UINT16 priority, int line, int scroll_x, int scroll_y );
void k1ge_draw_scroll_plane( UINT16 *p, UINT16 base, int line, int scroll_x, int scroll_y, UINT16 pal_lut_base, UINT16 k2ge_lut_base );
void k1ge_draw_sprite_plane( UINT16 *p, UINT16 priority, int line, int scroll_x, int scroll_y );
#define MCFG_K1GE_ADD(_tag, _clock, _config ) \
MCFG_DEVICE_ADD( _tag, K1GE, _clock ) \
MCFG_DEVICE_CONFIG( _config )
#define MCFG_K2GE_ADD(_tag, _clock, _config ) \
MCFG_DEVICE_ADD( _tag, K2GE, _clock ) \
MCFG_DEVICE_CONFIG( _config )
struct k1ge_interface
{
const char *screen_tag; /* screen we are drawing on */
const char *vram_tag; /* memory region we will use for video ram */
devcb_write8 vblank_pin_w; /* called back when VBlank pin may have changed */
devcb_write8 hblank_pin_w; /* called back when HBlank pin may have changed */
};
PALETTE_INIT( k1ge );
PALETTE_INIT( k2ge );
DECLARE_WRITE8_DEVICE_HANDLER( k1ge_w );
DECLARE_READ8_DEVICE_HANDLER( k1ge_r );
void k1ge_update( device_t *device, bitmap_ind16 &bitmap, const rectangle &cliprect );
extern const device_type K1GE;
extern const device_type K2GE;
#endif