(MESS) intv: converted the STIC video chip emulation to be a device. [Fabio Priuli]

This commit is contained in:
Fabio Priuli 2013-05-26 04:59:28 +00:00
parent f98015dc7f
commit 307e42b64c
6 changed files with 992 additions and 842 deletions

View File

@ -51,7 +51,6 @@ RO-3-9506 = 8KiB (4Kiw) self decoding address mask rom with external address dec
#include "emu.h"
#include "cpu/m6502/m6502.h"
#include "cpu/cp1610/cp1610.h"
#include "video/stic.h"
#include "includes/intv.h"
#include "imagedev/cartslot.h"
#include "sound/ay8910.h"
@ -88,31 +87,32 @@ static const unsigned char intv_colors[] =
void intv_state::palette_init()
{
int k = 0;
UINT8 i, j, r, g, b;
UINT8 r, g, b;
/* Two copies of everything (why?) */
machine().colortable = colortable_alloc(machine(), 32);
for ( i = 0; i < 16; i++ )
for (int i = 0; i < 16; i++)
{
r = intv_colors[i*3]; g = intv_colors[i*3+1]; b = intv_colors[i*3+2];
r = intv_colors[i * 3 + 0];
g = intv_colors[i * 3 + 1];
b = intv_colors[i * 3 + 2];
colortable_palette_set_color(machine().colortable, i, MAKE_RGB(r, g, b));
colortable_palette_set_color(machine().colortable, i + 16, MAKE_RGB(r, g, b));
}
for(i=0;i<16;i++)
for (int i = 0; i < 16; i++)
{
for(j=0;j<16;j++)
for (int j = 0; j < 16; j++)
{
colortable_entry_set_value(machine().colortable, k++, i);
colortable_entry_set_value(machine().colortable, k++, j);
colortable_entry_set_value(machine().colortable, k++, i);
colortable_entry_set_value(machine().colortable, k++, j);
}
}
for(i=0;i<16;i++)
for (int i = 0; i < 16; i++)
{
for(j=16;j<32;j++)
for (int j = 16; j < 32; j++)
{
colortable_entry_set_value(machine().colortable, k++, i);
colortable_entry_set_value(machine().colortable, k++, j);
@ -159,18 +159,6 @@ static const cassette_interface ecs_cassette_interface =
/* graphics output */
static const gfx_layout intv_gromlayout =
{
16, 16,
256,
1,
{ 0 },
{ 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7},
{ 0*16, 0*16, 1*16, 1*16, 2*16, 2*16, 3*16, 3*16,
4*16, 4*16, 5*16, 5*16, 6*16, 6*16, 7*16, 7*16 },
8 * 16
};
static const gfx_layout intvkbd_charlayout =
{
8, 8,
@ -182,12 +170,7 @@ static const gfx_layout intvkbd_charlayout =
8 * 8
};
static GFXDECODE_START( intv )
GFXDECODE_ENTRY( "maincpu", 0x3000<<1, intv_gromlayout, 0, 256 )
GFXDECODE_END
static GFXDECODE_START( intvkbd )
GFXDECODE_ENTRY( "maincpu", 0x3000<<1, intv_gromlayout, 0, 256 )
GFXDECODE_ENTRY( "gfx1", 0x0000, intvkbd_charlayout, 0, 256 )
GFXDECODE_END
@ -717,7 +700,7 @@ static ADDRESS_MAP_START(intv_mem, AS_PROGRAM, 16, intv_state)
AM_RANGE(0x01f0, 0x01ff) AM_DEVREADWRITE8("ay8914.1", ay8914_device, read, write, 0x00ff )
AM_RANGE(0x0200, 0x035f) AM_READWRITE( intv_ram16_r, intv_ram16_w )
AM_RANGE(0x1000, 0x1fff) AM_ROM AM_REGION("maincpu", 0x1000<<1) /* Exec ROM, 10-bits wide */
AM_RANGE(0x3000, 0x37ff) AM_ROM AM_REGION("maincpu", 0x3000<<1) /* GROM, 8-bits wide */
AM_RANGE(0x3000, 0x37ff) AM_DEVREAD("stic", stic_device, grom_read) /* GROM, 8-bits wide */
AM_RANGE(0x3800, 0x39ff) AM_READWRITE( intv_gram_r, intv_gram_w ) /* GRAM, 8-bits wide */
AM_RANGE(0x3a00, 0x3bff) AM_READWRITE( intv_gram_r, intv_gram_w ) /* GRAM Alias, 8-bits wide */
AM_RANGE(0x4800, 0x7fff) AM_ROM AM_REGION("maincpu", 0x4800<<1)
@ -735,7 +718,7 @@ static ADDRESS_MAP_START( intv2_mem , AS_PROGRAM, 16, intv_state)
AM_RANGE(0x0200, 0x035f) AM_READWRITE( intv_ram16_r, intv_ram16_w )
AM_RANGE(0x0400, 0x04ff) AM_ROM AM_REGION("maincpu", 0x400<<1) /* Exec ROM, 10-bits wide */
AM_RANGE(0x1000, 0x1fff) AM_ROM AM_REGION("maincpu", 0x1000<<1) /* Exec ROM, 10-bits wide */
AM_RANGE(0x3000, 0x37ff) AM_ROM AM_REGION("maincpu", 0x3000<<1) /* GROM, 8-bits wide */
AM_RANGE(0x3000, 0x37ff) AM_DEVREAD("stic", stic_device, grom_read) /* GROM, 8-bits wide */
AM_RANGE(0x3800, 0x39ff) AM_READWRITE( intv_gram_r, intv_gram_w ) /* GRAM, 8-bits wide */
AM_RANGE(0x3a00, 0x3bff) AM_READWRITE( intv_gram_r, intv_gram_w ) /* GRAM Alias, 8-bits wide */
AM_RANGE(0x4800, 0x7fff) AM_ROM AM_REGION("maincpu", 0x4800<<1)
@ -755,7 +738,7 @@ static ADDRESS_MAP_START( intvecs_mem , AS_PROGRAM, 16, intv_state)
AM_RANGE(0x0200, 0x035f) AM_READWRITE( intv_ram16_r, intv_ram16_w )
AM_RANGE(0x1000, 0x1fff) AM_ROM AM_REGION("maincpu", 0x1000<<1) /* Exec ROM, 10-bits wide */
AM_RANGE(0x2000, 0x2fff) AM_READ_BANK("bank1") AM_WRITE( ecs_bank1_page_select );
AM_RANGE(0x3000, 0x37ff) AM_ROM AM_REGION("maincpu", 0x3000<<1) /* GROM, 8-bits wide */
AM_RANGE(0x3000, 0x37ff) AM_DEVREAD("stic", stic_device, grom_read) /* GROM, 8-bits wide */
AM_RANGE(0x3800, 0x39ff) AM_READWRITE( intv_gram_r, intv_gram_w ) /* GRAM, 8-bits wide */
AM_RANGE(0x3a00, 0x3bff) AM_READWRITE( intv_gram_r, intv_gram_w ) /* GRAM Alias, 8-bits wide */
AM_RANGE(0x4000, 0x47ff) AM_READWRITE( intv_ecs_ram8_r, intv_ecs_ram8_w )
@ -776,7 +759,7 @@ static ADDRESS_MAP_START( intvkbd_mem , AS_PROGRAM, 16, intv_state)
AM_RANGE(0x01f0, 0x01ff) AM_DEVREADWRITE8("ay8914.1", ay8914_device, read, write, 0x00ff )
AM_RANGE(0x0200, 0x035f) AM_READWRITE( intv_ram16_r, intv_ram16_w )
AM_RANGE(0x1000, 0x1fff) AM_ROM AM_REGION("maincpu", 0x1000<<1) /* Exec ROM, 10-bits wide */
AM_RANGE(0x3000, 0x37ff) AM_ROM AM_REGION("maincpu", 0x3000<<1) /* GROM, 8-bits wide */
AM_RANGE(0x3000, 0x37ff) AM_DEVREAD("stic", stic_device, grom_read) /* GROM, 8-bits wide */
AM_RANGE(0x3800, 0x39ff) AM_READWRITE( intv_gram_r, intv_gram_w ) /* GRAM, 8-bits wide */
AM_RANGE(0x3a00, 0x3bff) AM_READWRITE( intv_gram_r, intv_gram_w ) /* GRAM Alias, 8-bits wide */
AM_RANGE(0x4800, 0x6fff) AM_ROM /* Cartridges? */
@ -833,8 +816,9 @@ static MACHINE_CONFIG_START( intv, intv_state )
MCFG_CPU_VBLANK_INT_DRIVER("screen", intv_state, intv_interrupt)
MCFG_QUANTUM_TIME(attotime::from_hz(60))
/* video hardware */
MCFG_STIC_ADD("stic")
MCFG_SCREEN_ADD("screen", RASTER)
MCFG_SCREEN_REFRESH_RATE(59.92)
//MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2400)) /* not accurate */
@ -842,10 +826,8 @@ static MACHINE_CONFIG_START( intv, intv_state )
MCFG_SCREEN_SIZE((STIC_OVERSCAN_LEFT_WIDTH+STIC_BACKTAB_WIDTH*STIC_CARD_WIDTH-1+STIC_OVERSCAN_RIGHT_WIDTH)*STIC_X_SCALE*INTV_X_SCALE, (STIC_OVERSCAN_TOP_HEIGHT+STIC_BACKTAB_HEIGHT*STIC_CARD_HEIGHT+STIC_OVERSCAN_BOTTOM_HEIGHT)*STIC_Y_SCALE*INTV_Y_SCALE)
MCFG_SCREEN_VISIBLE_AREA(0, (STIC_OVERSCAN_LEFT_WIDTH+STIC_BACKTAB_WIDTH*STIC_CARD_WIDTH-1+STIC_OVERSCAN_RIGHT_WIDTH)*STIC_X_SCALE*INTV_X_SCALE-1, 0, (STIC_OVERSCAN_TOP_HEIGHT+STIC_BACKTAB_HEIGHT*STIC_CARD_HEIGHT+STIC_OVERSCAN_BOTTOM_HEIGHT)*STIC_Y_SCALE*INTV_Y_SCALE-1)
MCFG_GFXDECODE( intv )
MCFG_PALETTE_LENGTH(0x400)
/* sound hardware */
MCFG_SPEAKER_STANDARD_MONO("mono")
MCFG_SOUND_ADD("ay8914.1", AY8914, XTAL_3_579545MHz/2)
@ -922,7 +904,6 @@ MACHINE_CONFIG_END
ROM_START(intv) // the intv1 exec rom should be two roms: RO-3-9502-011.U5 and RO-3-9504-021.U6
ROM_REGION(0x10000<<1,"maincpu", ROMREGION_ERASEFF)
ROM_LOAD16_WORD( "exec.bin", (0x1000<<1)+0, 0x2000, CRC(cbce86f7) SHA1(5a65b922b562cb1f57dab51b73151283f0e20c7a))
ROM_LOAD16_BYTE( "ro-3-9503-003.u21", (0x3000<<1)+1, 0x0800, CRC(683a4158) SHA1(f9608bb4ad1cfe3640d02844c7ad8e0bcd974917))
ROM_REGION( 0x10000<<1, "sp0256_speech", 0 )
/* SP0256-012 Speech chip w/2KiB mask rom */
@ -934,7 +915,6 @@ ROM_START(intv2)
ROM_REGION(0x10000<<1,"maincpu", ROMREGION_ERASEFF)
ROM_LOAD16_WORD_SWAP( "ro-3-9506-010.ic6", (0x400<<1)+0, 0x200, CRC(DD7E1237) SHA1(FB821A643B7714ED4C812553CD3F668766FD44AB))
ROM_CONTINUE( (0x1000<<1)+0, 0x2000 )
ROM_LOAD16_BYTE( "ro-3-9503-003.u5", (0x3000<<1)+1, 0x0800, CRC(683a4158) SHA1(f9608bb4ad1cfe3640d02844c7ad8e0bcd974917)) // needs verification
ROM_REGION( 0x10000<<1, "sp0256_speech", 0 )
/* SP0256-012 Speech chip w/2KiB mask rom */
@ -944,7 +924,6 @@ ROM_END
ROM_START(intvsrs) // the intv1 sears exec rom should be two roms: RO-3-9502-???.U5 and RO-3-9504-???.U6 but the correct names are unknown as of yet
ROM_REGION(0x10000<<1,"maincpu", ROMREGION_ERASEFF)
ROM_LOAD16_WORD( "searsexc.bin", (0x1000<<1)+0, 0x2000, CRC(ea552a22) SHA1(834339de056d42a35571cae7fd5b04d1344001e9))
ROM_LOAD16_BYTE( "ro-3-9503-003.u21", (0x3000<<1)+1, 0x0800, CRC(683a4158) SHA1(f9608bb4ad1cfe3640d02844c7ad8e0bcd974917))
ROM_REGION( 0x10000<<1, "sp0256_speech", 0 )
/* SP0256-012 Speech chip w/2KiB mask rom */
@ -954,7 +933,6 @@ ROM_END
ROM_START(intvecs) // the intv1 exec rom should be two roms: RO-3-9502-011.U5 and RO-3-9504-021.U6
ROM_REGION(0x10000<<1,"maincpu", ROMREGION_ERASEFF)
ROM_LOAD16_WORD( "exec.bin", (0x1000<<1)+0, 0x2000, CRC(cbce86f7) SHA1(5a65b922b562cb1f57dab51b73151283f0e20c7a))
ROM_LOAD16_BYTE( "ro-3-9503-003.u21", (0x3000<<1)+1, 0x0800, CRC(683a4158) SHA1(f9608bb4ad1cfe3640d02844c7ad8e0bcd974917))
ROM_REGION( 0x10000<<1, "sp0256_speech", 0 )
/* SP0256-012 Speech chip w/2KiB mask rom */
@ -969,7 +947,6 @@ ROM_END
ROM_START(intvkbd) // the intv1 exec rom should be two roms: RO-3-9502-011.U5 and RO-3-9504-021.U6
ROM_REGION(0x10000<<1,"maincpu", ROMREGION_ERASEFF)
ROM_LOAD16_WORD( "exec.bin", 0x1000<<1, 0x2000, CRC(cbce86f7) SHA1(5a65b922b562cb1f57dab51b73151283f0e20c7a))
ROM_LOAD16_BYTE( "ro-3-9503-003.u21", (0x3000<<1)+1, 0x0800, CRC(683a4158) SHA1(f9608bb4ad1cfe3640d02844c7ad8e0bcd974917))
ROM_LOAD16_WORD( "024.u60", 0x7000<<1, 0x1000, CRC(4f7998ec) SHA1(ec006d0ae9002e9d56d83a71f5f2eddd6a456a40))
ROM_LOAD16_BYTE( "4d72.u62", 0x7800<<1, 0x0800, CRC(aa57c594) SHA1(741860d489d90f5882ca53daa3169b6abacdf130))
ROM_LOAD16_BYTE( "4d71.u63", (0x7800<<1)+1, 0x0800, CRC(069b2f0b) SHA1(070850bb32f8474107cc52c5183cfaa32d640f9a))
@ -986,14 +963,14 @@ ROM_END
DRIVER_INIT_MEMBER(intv_state,intv)
{
m_x_scale = INTV_X_SCALE;
m_y_scale = INTV_Y_SCALE;
m_stic->set_x_scale(INTV_X_SCALE);
m_stic->set_y_scale(INTV_Y_SCALE);
}
DRIVER_INIT_MEMBER(intv_state,intvkbd)
{
m_x_scale = INTVKBD_X_SCALE;
m_y_scale = INTVKBD_Y_SCALE;
m_stic->set_x_scale(INTVKBD_X_SCALE);
m_stic->set_y_scale(INTVKBD_Y_SCALE);
}
/***************************************************************************

View File

@ -9,26 +9,7 @@
#include "sound/ay8910.h"
#include "sound/sp0256.h"
struct intv_sprite_type
{
int visible;
int xpos;
int ypos;
int coll;
int collision;
int doublex;
int doubley;
int quady;
int xflip;
int yflip;
int behind_foreground;
int grom;
int card;
int color;
int doubleyres;
int dirty;
};
#include "video/stic.h"
class intv_state : public driver_device
{
@ -46,6 +27,7 @@ public:
m_intellivoice(*this, "sp0256_speech"),
m_sound(*this, "ay8914.1"),
m_ecs_sound(*this, "ay8914.2"),
m_stic(*this, "stic"),
m_intvkbd_dualport_ram(*this, "dualport_ram"),
m_videoram(*this, "videoram"),
m_keyboard(*this, "keyboard"),
@ -104,6 +86,7 @@ public:
required_device<sp0256_device> m_intellivoice;
required_device<ay8914_device> m_sound;
optional_device<ay8914_device> m_ecs_sound;
required_device<stic_device> m_stic;
optional_shared_ptr<UINT16> m_intvkbd_dualport_ram;
optional_shared_ptr<UINT8> m_videoram;
@ -123,28 +106,9 @@ public:
DECLARE_READ8_MEMBER( intv_right_control_r );
DECLARE_READ8_MEMBER( intv_left_control_r );
bitmap_ind16 m_bitmap;
intv_sprite_type m_sprite[STIC_MOBS];
UINT8 m_sprite_buffers[STIC_MOBS][STIC_CARD_WIDTH*2][STIC_CARD_HEIGHT*4*2*2];
UINT16 m_backtab_buffer[STIC_BACKTAB_HEIGHT][STIC_BACKTAB_WIDTH];
UINT8 m_backtab_row;
UINT8 m_bus_copy_mode;
int m_color_stack_mode;
int m_stic_registers[STIC_REGISTERS];
int m_color_stack_offset;
int m_stic_handshake;
int m_border_color;
int m_col_delay;
int m_row_delay;
int m_left_edge_inhibit;
int m_top_edge_inhibit;
UINT8 m_gramdirty;
UINT8 m_gram[512];
UINT8 m_gramdirtybytes[512];
UINT8 m_backtab_row;
UINT16 m_ram16[0x160];
int m_x_scale;
int m_y_scale;
int m_sr1_int_pending;
UINT8 m_ram8[256];
UINT8 m_cart_ram8[2048];

View File

@ -264,29 +264,37 @@ WRITE8_MEMBER( intv_state::intvkbd_dualport8_msb_w )
}
}
READ16_MEMBER( intv_state::intv_stic_r )
{
if (m_bus_copy_mode || !m_stic->read_stic_handshake())
return m_stic->read(space, offset, mem_mask);
else
return offset;
}
WRITE16_MEMBER( intv_state::intv_stic_w )
{
if (m_bus_copy_mode || !m_stic->read_stic_handshake())
m_stic->write(space, offset, data, mem_mask);
}
READ16_MEMBER( intv_state::intv_gram_r )
{
//logerror("read: %d = GRAM(%d)\n",state->m_gram[offset],offset);
if (m_bus_copy_mode || !m_stic_handshake)
{
return (int)m_gram[offset];
}
else {return offset;}
if (m_bus_copy_mode || !m_stic->read_stic_handshake())
return m_stic->gram_read(space, offset, mem_mask);
else
return offset;
}
WRITE16_MEMBER( intv_state::intv_gram_w )
{
data &= 0xFF;
if(m_bus_copy_mode || !m_stic_handshake)
{
m_gram[offset] = data;
m_gramdirtybytes[offset] = 1;
m_gramdirty = 1;
}
if (m_bus_copy_mode || !m_stic->read_stic_handshake())
m_stic->gram_write(space, offset, data, mem_mask);
}
READ16_MEMBER( intv_state::intv_ram8_r )
{
//logerror("%x = ram8_r(%x)\n",state->m_ram8[offset],offset);
@ -379,7 +387,7 @@ WRITE16_MEMBER( intv_state::ecs_bank3_page_select )
WRITE16_MEMBER( intv_state::wsmlb_bank_page_select )
{
logerror("offset %x data %x\n",offset,data);
logerror("offset %x data %x\n", offset, data);
if (offset == 0xFFF)
{
if (data == 0xFA50)
@ -656,19 +664,18 @@ TIMER_CALLBACK_MEMBER(intv_state::intv_interrupt_complete)
TIMER_CALLBACK_MEMBER(intv_state::intv_btb_fill)
{
UINT8 column;
UINT8 row = m_backtab_row;
//m_maincpu->adjust_icount(-STIC_ROW_FETCH);
for(column=0; column < STIC_BACKTAB_WIDTH; column++)
{
m_backtab_buffer[row][column] = m_ram16[column + row * STIC_BACKTAB_WIDTH];
}
for (int column = 0; column < STIC_BACKTAB_WIDTH; column++)
m_stic->write_to_btb(row, column, m_ram16[column + row * STIC_BACKTAB_WIDTH]);
m_backtab_row += 1;
}
INTERRUPT_GEN_MEMBER(intv_state::intv_interrupt)
{
int delay = m_stic->read_row_delay();
m_maincpu->set_input_line(CP1610_INT_INTRM, ASSERT_LINE);
m_sr1_int_pending = 1;
m_bus_copy_mode = 1;
@ -678,15 +685,15 @@ INTERRUPT_GEN_MEMBER(intv_state::intv_interrupt)
timer_set(m_maincpu->cycles_to_attotime(STIC_VBLANK_END), TIMER_INTV_INTERRUPT_COMPLETE);
for (row=0; row < STIC_BACKTAB_HEIGHT; row++)
{
timer_set(m_maincpu->cycles_to_attotime(STIC_FIRST_FETCH-STIC_FRAME_BUSRQ+STIC_CYCLES_PER_SCANLINE*STIC_Y_SCALE*m_row_delay + (STIC_CYCLES_PER_SCANLINE*STIC_Y_SCALE*STIC_CARD_HEIGHT - STIC_ROW_BUSRQ)*row), TIMER_INTV_BTB_FILL);
timer_set(m_maincpu->cycles_to_attotime(STIC_FIRST_FETCH-STIC_FRAME_BUSRQ+STIC_CYCLES_PER_SCANLINE*STIC_Y_SCALE*delay + (STIC_CYCLES_PER_SCANLINE*STIC_Y_SCALE*STIC_CARD_HEIGHT - STIC_ROW_BUSRQ)*row), TIMER_INTV_BTB_FILL);
}
if (m_row_delay == 0)
if (delay == 0)
{
m_maincpu->adjust_icount(-STIC_ROW_BUSRQ); // extra row fetch occurs if vertical delay == 0
}
intv_stic_screenrefresh();
m_stic->screenrefresh();
}
/* hand 0 == left, 1 == right, 2 == ECS hand controller 1, 3 == ECS hand controller 2 */
@ -841,7 +848,7 @@ DEVICE_IMAGE_LOAD_MEMBER( intv_state,intvkbd_cart )
UINT8 *memory = m_region_keyboard->base();
/* Assume an 8K cart, like BASIC */
image.fread( &memory[0xe000], 0x2000);
image.fread(&memory[0xe000], 0x2000);
}
return IMAGE_INIT_PASS;

View File

@ -1,718 +1,16 @@
#include "emu.h"
#include "video/stic.h"
#include "includes/intv.h"
#define FOREGROUND_BIT 0x0010
// conversion from Intellivision color to internal representation
#define SET_COLOR(c) ((c * 2) + 1)
#define GET_COLOR(c) ((c - 1) / 2)
/* initialized to non-zero, because we divide by it */
void intv_state::intv_set_pixel(bitmap_ind16 &bitmap, int x, int y, UINT32 color)
{
int w, h;
// output scaling
x *= m_x_scale;
y *= m_y_scale;
color = SET_COLOR(color);
for (h = 0; h < m_y_scale; h++)
for (w = 0; w < m_x_scale; w++)
bitmap.pix16(y + h, x + w) = color;
}
UINT32 intv_state::intv_get_pixel(bitmap_ind16 &bitmap, int x, int y)
{
return GET_COLOR(bitmap.pix16(y * m_y_scale, x * m_x_scale));
}
void intv_state::intv_plot_box(bitmap_ind16 &bm, int x, int y, int w, int h, int color)
{
bm.plot_box(x * m_x_scale, y * m_y_scale, w * m_x_scale, h * m_y_scale, SET_COLOR(color));
}
void intv_state::video_start()
{
//int i,j,k;
m_tms9927_num_rows = 25;
machine().primary_screen->register_screen_bitmap(m_bitmap);
#if 0
for (i = 0; i < STIC_MOBS; i++)
{
intv_sprite_type* s = &m_sprite[i];
s->visible = 0;
s->xpos = 0;
s->ypos = 0;
s->coll = 0;
s->collision = 0;
s->doublex = 0;
s->doubley = 0;
s->quady = 0;
s->xflip = 0;
s->yflip = 0;
s->behind_foreground = 0;
s->grom = 0;
s->card = 0;
s->color = 0;
s->doubleyres = 0;
s->dirty = 1;
for (j = 0; j < 16; j++)
{
for (k = 0; k < 128; k++)
{
m_sprite_buffers[i][j][k] = 0;
}
}
}
for(i = 0; i < STIC_REGISTERS; i++)
{
m_stic_registers[i] = 0;
}
m_color_stack_mode = 0;
m_color_stack_offset = 0;
m_stic_handshake = 0;
m_border_color = 0;
m_col_delay = 0;
m_row_delay = 0;
m_left_edge_inhibit = 0;
m_top_edge_inhibit = 0;
m_gramdirty = 1;
for(i=0;i<64;i++)
{
m_gram[i] = 0;
m_gramdirtybytes[i] = 1;
}
#endif
}
int intv_state::sprites_collide(int spriteNum1, int spriteNum2)
{
INT16 x0, y0, w0, h0, x1, y1, w1, h1, x2, y2, w2, h2;
intv_sprite_type* s1 = &m_sprite[spriteNum1];
intv_sprite_type* s2 = &m_sprite[spriteNum2];
x0 = STIC_OVERSCAN_LEFT_WIDTH + m_col_delay - STIC_CARD_WIDTH;
y0 = STIC_OVERSCAN_TOP_HEIGHT + m_row_delay - STIC_CARD_HEIGHT;
x1 = (s1->xpos + x0) * STIC_X_SCALE; y1 = (s1->ypos + y0) * STIC_Y_SCALE;
x2 = (s2->xpos + x0) * STIC_X_SCALE; y2 = (s2->ypos + y0) * STIC_Y_SCALE;
w1 = (s1->doublex ? 2 : 1) * STIC_CARD_WIDTH;
w2 = (s2->doublex ? 2 : 1) * STIC_CARD_WIDTH;
h1 = (s1->quady ? 4 : 1) * (s1->doubley ? 2 : 1) * (s1->doubleyres ? 2 : 1) * STIC_CARD_HEIGHT;
h2 = (s2->quady ? 4 : 1) * (s2->doubley ? 2 : 1) * (s2->doubleyres ? 2 : 1) * STIC_CARD_HEIGHT;
if ((x1 >= x2 + w2) || (y1 >= y2 + h2) ||
(x2 >= x1 + w1) || (y2 >= y1 + h1))
return FALSE;
// iterate over the intersecting bits to see if any touch
x0 = MAX(x1, x2);
y0 = MAX(y1, y2);
w0 = MIN(x1 + w1, x2 + w2) - x0;
h0 = MIN(y1 + h1, y2 + h2) - y0;
x1 = x0 - x1;
y1 = y0 - y1;
x2 = x0 - x2;
y2 = y0 - y2;
for (x0 = 0; x0 < w0; x0++)
{
for (y0 = 0; y0 < h0; y0++)
{
if (m_sprite_buffers[spriteNum1][x0 + x1][y0 + y1] &&
m_sprite_buffers[spriteNum2][x0 + x2][y0 + y2])
return TRUE;
}
}
return FALSE;
}
void intv_state::determine_sprite_collisions()
{
// check sprite to sprite collisions
int i, j;
for (i = 0; i < STIC_MOBS - 1; i++)
{
intv_sprite_type* s1 = &m_sprite[i];
if (s1->xpos == 0 || !s1->coll)
continue;
for (j = i + 1; j < STIC_MOBS; j++)
{
intv_sprite_type* s2 = &m_sprite[j];
if (s2->xpos == 0 || !s2->coll)
continue;
if (sprites_collide(i, j))
{
s1->collision |= (1 << j);
s2->collision |= (1 << i);
}
}
}
}
void intv_state::render_sprites()
{
INT32 cardMemoryLocation, pixelSize;
INT32 spritePixelHeight;
INT32 nextMemoryLocation;
INT32 nextData;
INT32 nextX;
INT32 nextY;
INT32 xInc;
INT32 i, j, k;
UINT8* memory = m_region_maincpu->base();
for (i = 0; i < STIC_MOBS; i++)
{
intv_sprite_type* s = &m_sprite[i];
if (s->grom)
cardMemoryLocation = (s->card * STIC_CARD_HEIGHT);
else
cardMemoryLocation = ((s->card & 0x003F) * STIC_CARD_HEIGHT);
pixelSize = (s->quady ? 4 : 1) * (s->doubley ? 2 : 1);
spritePixelHeight = pixelSize * (s->doubleyres ? 2 : 1) * STIC_CARD_HEIGHT;
for (j = 0; j < spritePixelHeight; j++)
{
nextMemoryLocation = (cardMemoryLocation + (j/pixelSize));
if (s->grom)
nextData = memory[(0x3000+nextMemoryLocation)<<1];
else if (nextMemoryLocation < 0x200)
nextData = m_gram[nextMemoryLocation];
else
nextData = 0xFFFF;
nextX = (s->xflip ? ((s->doublex ? 2 : 1) * STIC_CARD_WIDTH - 1) : 0);
nextY = (s->yflip ? (spritePixelHeight - j - 1) : j);
xInc = (s->xflip ? -1: 1);
for (k = 0; k < STIC_CARD_WIDTH * (1 + s->doublex); k++)
{
m_sprite_buffers[i][nextX + k * xInc][nextY] = (nextData & (1 << ((STIC_CARD_WIDTH - 1) - k / (1 + s->doublex)))) != 0;
}
}
}
}
void intv_state::render_line(bitmap_ind16 &bitmap, UINT8 nextByte, UINT16 x, UINT16 y, UINT8 fgcolor, UINT8 bgcolor)
{
UINT32 color;
UINT8 i;
for (i = 0; i < STIC_CARD_WIDTH; i++)
{
color = (nextByte & (1 << ((STIC_CARD_WIDTH - 1) - i)) ? fgcolor : bgcolor);
intv_set_pixel(bitmap, x+i, y, color);
intv_set_pixel(bitmap, x+i, y+1, color);
}
}
void intv_state::render_colored_squares(bitmap_ind16 &bitmap, UINT16 x, UINT16 y, UINT8 color0, UINT8 color1, UINT8 color2, UINT8 color3)
{
intv_plot_box(bitmap, x, y, STIC_CSQM_WIDTH * STIC_X_SCALE, STIC_CSQM_HEIGHT * STIC_Y_SCALE, color0);
intv_plot_box(bitmap, x + STIC_CSQM_WIDTH * STIC_X_SCALE, y, STIC_CSQM_WIDTH * STIC_X_SCALE, STIC_CSQM_HEIGHT * STIC_Y_SCALE, color1);
intv_plot_box(bitmap, x, y + STIC_CSQM_HEIGHT * STIC_Y_SCALE, STIC_CSQM_WIDTH * STIC_X_SCALE, STIC_CSQM_HEIGHT * STIC_Y_SCALE, color2);
intv_plot_box(bitmap, x + STIC_CSQM_WIDTH * STIC_X_SCALE, y + STIC_CSQM_HEIGHT * STIC_Y_SCALE, STIC_CSQM_WIDTH * STIC_X_SCALE, STIC_CSQM_HEIGHT * STIC_Y_SCALE, color3);
}
void intv_state::render_color_stack_mode(bitmap_ind16 &bitmap)
{
INT16 w, h, nextx, nexty;
UINT8 csPtr = 0;
UINT16 nextCard;
UINT8 *ram = m_region_maincpu->base();
for (h = 0, nexty = (STIC_OVERSCAN_TOP_HEIGHT + m_row_delay) * STIC_Y_SCALE;
h < STIC_BACKTAB_HEIGHT;
h++, nexty += STIC_CARD_HEIGHT * STIC_Y_SCALE)
{
for (w = 0, nextx = (STIC_OVERSCAN_LEFT_WIDTH + m_col_delay) * STIC_X_SCALE;
w < STIC_BACKTAB_WIDTH;
w++, nextx += STIC_CARD_WIDTH * STIC_X_SCALE)
{
nextCard = m_backtab_buffer[h][w];
// colored squares mode
if ((nextCard & (STIC_CSTM_FG3|STIC_CSTM_SEL)) == STIC_CSTM_FG3)
{
UINT8 csColor = m_stic_registers[STIC_CSR + csPtr];
UINT8 color0 = nextCard & STIC_CSQM_A;
UINT8 color1 = (nextCard & STIC_CSQM_B) >> 3;
UINT8 color2 = (nextCard & STIC_CSQM_C) >> 6;
UINT8 color3 = ((nextCard & STIC_CSQM_D2) >> 11) |
((nextCard & (STIC_CSQM_D10)) >> 9);
render_colored_squares(bitmap, nextx, nexty,
(color0 == 7 ? csColor : (color0 | FOREGROUND_BIT)),
(color1 == 7 ? csColor : (color1 | FOREGROUND_BIT)),
(color2 == 7 ? csColor : (color2 | FOREGROUND_BIT)),
(color3 == 7 ? csColor : (color3 | FOREGROUND_BIT)));
}
//color stack mode
else
{
UINT8 isGrom, j;
UINT16 memoryLocation, fgcolor, bgcolor;
UINT8* memory;
//advance the color pointer, if necessary
if (nextCard & STIC_CSTM_ADV)
csPtr = (csPtr+1) & (STIC_CSRS - 1);
fgcolor = ((nextCard & STIC_CSTM_FG3) >> 9) |
(nextCard & (STIC_CSTM_FG20)) | FOREGROUND_BIT;
bgcolor = m_stic_registers[STIC_CSR + csPtr] & STIC_CSR_BG;
isGrom = !(nextCard & STIC_CSTM_SEL);
if (isGrom)
{
memoryLocation = 0x3000 + (nextCard & STIC_CSTM_C);
memory = ram;
for (j = 0; j < STIC_CARD_HEIGHT; j++)
render_line(bitmap, memory[(memoryLocation + j) * 2],
nextx, nexty + j * STIC_Y_SCALE, fgcolor, bgcolor);
}
else
{
memoryLocation = (nextCard & STIC_CSTM_C50);
memory = m_gram;
for (j = 0; j < STIC_CARD_HEIGHT; j++)
render_line(bitmap, memory[memoryLocation + j],
nextx, nexty + j * STIC_Y_SCALE, fgcolor, bgcolor);
}
}
}
}
}
void intv_state::render_fg_bg_mode(bitmap_ind16 &bitmap)
{
INT16 w, h, nextx, nexty;
UINT8 j, isGrom, fgcolor, bgcolor;
UINT16 nextCard, memoryLocation;
UINT8* memory;
UINT8* ram = m_region_maincpu->base();
for (h = 0, nexty = (STIC_OVERSCAN_TOP_HEIGHT + m_row_delay) * STIC_Y_SCALE;
h < STIC_BACKTAB_HEIGHT;
h++, nexty += STIC_CARD_HEIGHT * STIC_Y_SCALE)
{
for (w = 0, nextx = (STIC_OVERSCAN_LEFT_WIDTH + m_col_delay) * STIC_X_SCALE;
w < STIC_BACKTAB_WIDTH;
w++, nextx += STIC_CARD_WIDTH * STIC_X_SCALE)
{
nextCard = m_backtab_buffer[h][w];
fgcolor = (nextCard & STIC_FBM_FG) | FOREGROUND_BIT;
bgcolor = ((nextCard & STIC_FBM_BG2) >> 11) |
((nextCard & STIC_FBM_BG310) >> 9);
isGrom = !(nextCard & STIC_FBM_SEL);
if (isGrom)
{
memoryLocation = 0x3000 + (nextCard & STIC_FBM_C);
memory = ram;
for (j = 0; j < STIC_CARD_HEIGHT; j++)
render_line(bitmap, memory[(memoryLocation + j) * 2],
nextx, nexty + j * STIC_Y_SCALE, fgcolor, bgcolor);
}
else
{
memoryLocation = (nextCard & STIC_FBM_C);
memory = m_gram;
for (j = 0; j < STIC_CARD_HEIGHT; j++)
render_line(bitmap, memory[memoryLocation + j],
nextx, nexty + j * STIC_Y_SCALE, fgcolor, bgcolor);
}
}
}
}
void intv_state::copy_sprites_to_background(bitmap_ind16 &bitmap)
{
UINT8 width, currentPixel;
UINT8 borderCollision, foregroundCollision;
UINT8 spritePixelHeight, x, y;
INT16 leftX, nextY, i;
INT16 leftBorder, rightBorder, topBorder, bottomBorder;
INT32 nextX;
for (i = STIC_MOBS - 1; i >= 0; i--)
{
intv_sprite_type *s = &m_sprite[i];
if (s->xpos == 0 || (!s->coll && !s->visible))
continue;
borderCollision = FALSE;
foregroundCollision = FALSE;
spritePixelHeight = (s->quady ? 4 : 1) * (s->doubley ? 2 : 1) * (s->doubleyres ? 2 : 1) * STIC_CARD_HEIGHT;
width = (s->doublex ? 2 : 1) * STIC_CARD_WIDTH;
leftX = (s->xpos - STIC_CARD_WIDTH + STIC_OVERSCAN_LEFT_WIDTH + m_col_delay) * STIC_X_SCALE;
nextY = (s->ypos - STIC_CARD_HEIGHT + STIC_OVERSCAN_TOP_HEIGHT + m_row_delay) * STIC_Y_SCALE;
leftBorder = (STIC_OVERSCAN_LEFT_WIDTH + (m_left_edge_inhibit ? STIC_CARD_WIDTH : 0)) * STIC_X_SCALE;
rightBorder = (STIC_OVERSCAN_LEFT_WIDTH + STIC_BACKTAB_WIDTH * STIC_CARD_WIDTH - 1 - 1) * STIC_X_SCALE;
topBorder = (STIC_OVERSCAN_TOP_HEIGHT + (m_top_edge_inhibit ? STIC_CARD_HEIGHT : 0)) * STIC_Y_SCALE;
bottomBorder = (STIC_OVERSCAN_TOP_HEIGHT + STIC_BACKTAB_HEIGHT * STIC_CARD_HEIGHT) * STIC_Y_SCALE - 1;
for (y = 0; y < spritePixelHeight; y++)
{
for (x = 0; x < width; x++)
{
//if this sprite pixel is not on, then don't paint it
if (!m_sprite_buffers[i][x][y])
continue;
nextX = leftX + x;
//if the next pixel location is on the border, then we
//have a border collision and we can ignore painting it
if ((nextX < leftBorder) || (nextX > rightBorder) ||
(nextY < topBorder) || (nextY > bottomBorder))
{
borderCollision = TRUE;
continue;
}
currentPixel = intv_get_pixel(bitmap, nextX, nextY);
//check for foreground collision
if (currentPixel & FOREGROUND_BIT)
{
foregroundCollision = TRUE;
if (s->behind_foreground)
continue;
}
if (s->visible)
{
intv_set_pixel(bitmap, nextX, nextY, s->color | (currentPixel & FOREGROUND_BIT));
}
}
nextY++;
}
//update the collision bits
if (s->coll)
{
if (foregroundCollision)
s->collision |= STIC_MCR_BKGD;
if (borderCollision)
s->collision |= STIC_MCR_BRDR;
}
}
}
void intv_state::render_background(bitmap_ind16 &bitmap)
{
if (m_color_stack_mode)
render_color_stack_mode(bitmap);
else
render_fg_bg_mode(bitmap);
}
#ifdef UNUSED_CODE
void intv_state::draw_background(bitmap_ind16 &bitmap, int transparency)
{
// First, draw the background
int offs = 0;
int value = 0;
int row,col;
int fgcolor,bgcolor = 0;
int code;
int colora, colorb, colorc, colord;
int n_bit;
int p_bit;
int g_bit;
int j;
int x0 = STIC_OVERSCAN_LEFT_WIDTH + m_col_delay;
int y0 = STIC_OVERSCAN_TOP_HEIGHT + m_row_delay;
if (m_color_stack_mode == 1)
{
m_color_stack_offset = 0;
for(row = 0; row < STIC_BACKTAB_HEIGHT; row++)
{
for(col = 0; col < STIC_BACKTAB_WIDTH; col++)
{
value = m_ram16[offs];
n_bit = value & STIC_CSTM_ADV;
p_bit = value & STIC_CSTM_FG3;
g_bit = value & STIC_CSTM_SEL;
if (p_bit && (!g_bit)) // colored squares mode
{
colora = value & STIC_CSQM_A;
colorb = (value & STIC_CSQM_B) >> 3;
colorc = (value & STIC_CSQM_C) >> 6;
colord = ((n_bit & STIC_CSQM_D2) >> 11) + ((value & STIC_CSQM_D10) >> 9);
// color 7 if the top of the color stack in this mode
if (colora == 7) colora = m_stic_registers[STIC_CSR + STIC_CSR3];
if (colorb == 7) colorb = m_stic_registers[STIC_CSR + STIC_CSR3];
if (colorc == 7) colorc = m_stic_registers[STIC_CSR + STIC_CSR3];
if (colord == 7) colord = m_stic_registers[STIC_CSR + STIC_CSR3];
intv_plot_box(bitmap, (x0 + col * STIC_CARD_WIDTH) * STIC_X_SCALE, (y0 + row * STIC_CARD_HEIGHT) * STIC_Y_SCALE, STIC_CSQM_WIDTH * STIC_X_SCALE, STIC_CSQM_HEIGHT * STIC_Y_SCALE, colora);
intv_plot_box(bitmap, (x0 + col * STIC_CARD_WIDTH + STIC_CSQM_WIDTH)) * STIC_X_SCALE, (y0 + row * STIC_CARD_HEIGHT) * STIC_Y_SCALE, STIC_CSQM_WIDTH * STIC_X_SCALE, STIC_CSQM_HEIGHT * STIC_Y_SCALE, colorb);
intv_plot_box(bitmap, (x0 + col * STIC_CARD_WIDTH) * STIC_X_SCALE, (y0 + row * STIC_CARD_HEIGHT + STIC_CSQM_HEIGHT) * STIC_Y_SCALE, STIC_CSQM_WIDTH * STIC_X_SCALE, STIC_CSQM_HEIGHT * STIC_Y_SCALE, colorc);
intv_plot_box(bitmap, (x0 + col * STIC_CARD_WIDTH + STIC_CSQM_WIDTH) * STIC_X_SCALE, (y0 + row * STIC_CARD_HEIGHT + STIC_CSQM_HEIGHT) * STIC_Y_SCALE, STIC_CSQM_WIDTH * STIC_X_SCALE, STIC_CSQM_HEIGHT * STIC_Y_SCALE, colord);
}
else // normal color stack mode
{
if (n_bit) // next color
{
m_color_stack_offset += 1;
m_color_stack_offset &= (STIC_CSRS - 1);
}
if (p_bit) // pastel color set
fgcolor = (value & STIC_CSTM_FG20) + 8;
else
fgcolor = value & STIC_CSTM_FG20;
bgcolor = m_stic_registers[STIC_CSR + m_color_stack_offset];
code = (value & STIC_CSTM_C)>>3;
if (g_bit) // read from gram
{
code &= (STIC_CSTM_C50 >> 3); // keep from going outside the array
//if (m_gramdirtybytes[code] == 1)
{
decodechar(machine().gfx[1],
code,
m_gram,
machine().config()->gfxdecodeinfo[1].gfxlayout);
m_gramdirtybytes[code] = 0;
}
// Draw GRAM char
drawgfx(bitmap,machine().gfx[1],
code,
bgcolor*16+fgcolor,
0,0, (x0 + col * STIC_CARD_WIDTH) * STIC_X_SCALE, (y0 + row * STIC_CARD_HEIGHT) * STIC_Y_SCALE,
0,transparency,bgcolor);
for(j=0;j<8;j++)
{
//intv_set_pixel(bitmap, (x0 + col * STIC_CARD_WIDTH + j) * STIC_X_SCALE, (y0 + row * STIC_CARD_HEIGHT + 7) * STIC_Y_SCALE + 1, 1);
}
}
else // read from grom
{
drawgfx(bitmap,machine().gfx[0],
code,
bgcolor*16+fgcolor,
0,0, (x0 + col * STIC_CARD_WIDTH) * STIC_X_SCALE, (y0 + row * STIC_CARD_HEIGHT) * STIC_Y_SCALE,
0,transparency,bgcolor);
for(j=0;j<8;j++)
{
//intv_set_pixel(bitmap, (x0 + col * STIC_CARD_WIDTH + j) * STIC_X_SCALE, (y0 + row * STIC_CARD_HEIGHT + 7) * STIC_Y_SCALE + 1, 2);
}
}
}
offs++;
} // next col
} // next row
}
else
{
// fg/bg mode goes here
for(row = 0; row < STIC_BACKTAB_HEIGHT; row++)
{
for(col = 0; col < STIC_BACKTAB_WIDTH; col++)
{
value = m_ram16[offs];
fgcolor = value & STIC_FBM_FG;
bgcolor = ((value & STIC_FBM_BG2) >> 11) + ((value & STIC_FBM_BG310) >> 9);
code = (value & STIC_FBM_C) >> 3;
if (value & STIC_FBM_SEL) // read for GRAM
{
//if (m_gramdirtybytes[code] == 1)
{
decodechar(machine().gfx[1],
code,
m_gram,
machine().config()->gfxdecodeinfo[1].gfxlayout);
m_gramdirtybytes[code] = 0;
}
// Draw GRAM char
drawgfx(bitmap,machine().gfx[1],
code,
bgcolor*16+fgcolor,
0,0, (x0 + col * STIC_CARD_WIDTH) * STIC_X_SCALE, (y0 + row * STIC_CARD_HEIGHT) * STIC_Y_SCALE,
0,transparency,bgcolor);
}
else // read from GROM
{
drawgfx(bitmap,machine().gfx[0],
code,
bgcolor*16+fgcolor,
0,0, (x0 + col * STIC_CARD_WIDTH) * STIC_X_SCALE, (y0 + row * STIC_CARD_HEIGHT) * STIC_Y_SCALE,
0,transparency,bgcolor);
}
offs++;
} // next col
} // next row
}
}
#endif
/* TBD: need to handle sprites behind foreground? */
#ifdef UNUSED_FUNCTION
void intv_state::draw_sprites(bitmap_ind16 &bitmap, int behind_foreground)
{
int i;
int code;
int x0 = STIC_OVERSCAN_LEFT_WIDTH + m_col_delay - STIC_CARD_WIDTH;
int y0 = STIC_OVERSCAN_TOP_HEIGHT + m_row_delay - STIC_CARD_HEIGHT;
for(i = STIC_MOBS - 1; i >= 0; --i)
{
intv_sprite_type *s = &m_sprite[i];
if (s->visible && (s->behind_foreground == behind_foreground))
{
code = s->card;
if (!s->grom)
{
code %= 64; // keep from going outside the array
if (s->yres == 1)
{
//if (m_gramdirtybytes[code] == 1)
{
decodechar(machine().gfx[1],
code,
m_gram,
machine().config()->gfxdecodeinfo[1].gfxlayout);
m_gramdirtybytes[code] = 0;
}
// Draw GRAM char
drawgfxzoom_transpen(bitmap,&machine().screen[0].visarea,machine().gfx[1],
code,
s->color,
s->xflip,s->yflip,
(s->xpos + x0) * STIC_X_SCALE, (s->ypos + y0) * STIC_Y_SCALE,
0x8000 * s->xsize, 0x8000 * s->ysize,0);
}
else
{
//if ((m_gramdirtybytes[code] == 1) || (m_gramdirtybytes[code+1] == 1))
{
decodechar(machine().gfx[1],
code,
m_gram,
machine().config()->gfxdecodeinfo[1].gfxlayout);
decodechar(machine().gfx[1],
code+1,
m_gram,
machine().config()->gfxdecodeinfo[1].gfxlayout);
m_gramdirtybytes[code] = 0;
m_gramdirtybytes[code+1] = 0;
}
// Draw GRAM char
drawgfxzoom_transpen(bitmap,&machine().screen[0].visarea,machine().gfx[1],
code,
s->color,
s->xflip,s->yflip,
(s->xpos + x0) * STIC_X_SCALE, (s->ypos + y0) * STIC_Y_SCALE + s->yflip * s->ysize * STIC_CARD_HEIGHT,
0x8000*s->xsize, 0x8000*s->ysize,0);
drawgfxzoom_transpen(bitmap,&machine().screen[0].visarea,machine().gfx[1],
code+1,
s->color,
s->xflip,s->yflip,
(s->xpos + x0) * STIC_X_SCALE, (s->ypos + y0) * STIC_Y_SCALE + (1 - s->yflip) * s->ysize * STIC_CARD_HEIGHT,
0x8000*s->xsize, 0x8000*s->ysize,0);
}
}
else
{
if (s->yres == 1)
{
// Draw GROM char
drawgfxzoom_transpen(bitmap,&machine().screen[0].visarea,machine().gfx[0],
code,
s->color,
s->xflip,s->yflip,
(s->xpos + x0) * STIC_X_SCALE, (s->ypos + y0) * STIC_Y_SCALE,
0x8000*s->xsize, 0x8000*s->ysize,0);
}
else
{
drawgfxzoom_transpen(bitmap,&machine().screen[0].visarea,machine().gfx[0],
code,
s->color,
s->xflip,s->yflip,
(s->xpos + x0) * STIC_X_SCALE, (s->ypos + y0) * STIC_Y_SCALE + s->yflip * s->ysize * STIC_CARD_HEIGHT,
0x8000*s->xsize, 0x8000*s->ysize,0);
drawgfxzoom_transpen(bitmap,&machine().screen[0].visarea,machine().gfx[0],
code+1,
s->color,
s->xflip,s->yflip,
(s->xpos + x0) * STIC_X_SCALE, (s->ypos + y0) * STIC_Y_SCALE + (1 - s->yflip) * s->ysize * STIC_CARD_HEIGHT,
0x8000*s->xsize, 0x8000*s->ysize,0);
}
}
}
}
}
#endif
void intv_state::draw_borders(bitmap_ind16 &bm)
{
intv_plot_box(bm, 0, 0, (STIC_OVERSCAN_LEFT_WIDTH + (m_left_edge_inhibit ? STIC_CARD_WIDTH : m_col_delay)) * STIC_X_SCALE, (STIC_OVERSCAN_TOP_HEIGHT + STIC_BACKTAB_HEIGHT * STIC_CARD_HEIGHT + STIC_OVERSCAN_BOTTOM_HEIGHT) * STIC_Y_SCALE, m_border_color);
intv_plot_box(bm, (STIC_OVERSCAN_LEFT_WIDTH + STIC_BACKTAB_WIDTH * STIC_CARD_WIDTH - 1) * STIC_X_SCALE, 0, STIC_OVERSCAN_RIGHT_WIDTH, (STIC_OVERSCAN_TOP_HEIGHT + STIC_BACKTAB_HEIGHT * STIC_CARD_HEIGHT + STIC_OVERSCAN_BOTTOM_HEIGHT) * STIC_Y_SCALE, m_border_color);
intv_plot_box(bm, 0, 0, (STIC_OVERSCAN_LEFT_WIDTH + STIC_BACKTAB_WIDTH * STIC_CARD_WIDTH - 1 + STIC_OVERSCAN_RIGHT_WIDTH) * STIC_X_SCALE, (STIC_OVERSCAN_TOP_HEIGHT + (m_top_edge_inhibit ? STIC_CARD_HEIGHT : m_row_delay)) * STIC_Y_SCALE, m_border_color);
intv_plot_box(bm, 0, (STIC_OVERSCAN_TOP_HEIGHT + STIC_BACKTAB_HEIGHT * STIC_CARD_HEIGHT) * STIC_Y_SCALE, (STIC_OVERSCAN_LEFT_WIDTH + STIC_BACKTAB_WIDTH * STIC_CARD_WIDTH - 1 + STIC_OVERSCAN_RIGHT_WIDTH) * STIC_X_SCALE, STIC_OVERSCAN_BOTTOM_HEIGHT * STIC_Y_SCALE, m_border_color);
}
void intv_state::intv_stic_screenrefresh()
{
int i;
if (m_stic_handshake != 0)
{
m_stic_handshake = 0;
// Render the background
render_background(m_bitmap);
// Render the sprites into their buffers
render_sprites();
for (i = 0; i < STIC_MOBS; i++) m_sprite[i].collision = 0;
// Copy the sprites to the background
copy_sprites_to_background(m_bitmap);
determine_sprite_collisions();
for (i = 0; i < STIC_MOBS; i++) m_stic_registers[STIC_MCR + i] |= m_sprite[i].collision;
/* draw the screen borders if enabled */
draw_borders(m_bitmap);
}
else
{
/* STIC disabled, just fill with border color */
m_bitmap.fill(SET_COLOR(m_border_color));
}
}
/* very rudimentary support for the tms9927 character generator IC */
READ8_MEMBER( intv_state::intvkbd_tms9927_r )
READ8_MEMBER( intv_state::intvkbd_tms9927_r )
{
UINT8 rv;
switch (offset)
@ -757,12 +55,14 @@ WRITE8_MEMBER( intv_state::intvkbd_tms9927_w )
}
}
UINT32 intv_state::screen_update_intv(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
copybitmap(bitmap, m_bitmap, 0, 0, 0, 0, cliprect);
m_stic->screen_update(screen, bitmap, cliprect);
return 0;
}
UINT32 intv_state::screen_update_intvkbd(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
UINT8 *videoram = m_videoram;
@ -771,7 +71,7 @@ UINT32 intv_state::screen_update_intvkbd(screen_device &screen, bitmap_ind16 &bi
// char c;
/* Draw the underlying INTV screen first */
copybitmap(bitmap, m_bitmap, 0, 0, 0, 0, cliprect);
m_stic->screen_update(screen, bitmap, cliprect);
/* if the intvkbd text is not blanked, overlay it */
if (!m_intvkbd_text_blanked)
@ -783,7 +83,7 @@ UINT32 intv_state::screen_update_intvkbd(screen_device &screen, bitmap_ind16 &bi
{
offs = current_row*64+x;
drawgfx_transpen(bitmap, cliprect,
machine().gfx[1],
machine().gfx[0],
videoram[offs],
7, /* white */
0,0,
@ -794,7 +94,7 @@ UINT32 intv_state::screen_update_intvkbd(screen_device &screen, bitmap_ind16 &bi
/* draw the cursor as a solid white block */
/* (should use a filled rect here!) */
drawgfx_transpen(bitmap, cliprect,
machine().gfx[1],
machine().gfx[0],
191, /* a block */
7, /* white */
0,0,
@ -807,25 +107,25 @@ UINT32 intv_state::screen_update_intvkbd(screen_device &screen, bitmap_ind16 &bi
#if 0
// debugging
c = tape_motor_mode_desc[m_tape_motor_mode][0];
drawgfx_transpen(bitmap,&machine().screen[0].visarea, machine().gfx[1],
drawgfx_transpen(bitmap,&machine().screen[0].visarea, machine().gfx[0],
c,
1,
0,0,
0*8,0*8, 0);
for(y=0;y<5;y++)
{
drawgfx_transpen(bitmap,&machine().screen[0].visarea, machine().gfx[1],
drawgfx_transpen(bitmap,&machine().screen[0].visarea, machine().gfx[0],
m_tape_unknown_write[y]+'0',
1,
0,0,
0*8,(y+2)*8, 0);
}
drawgfx_transpen(bitmap,&machine().screen[0].visarea, machine().gfx[1],
drawgfx_transpen(bitmap,&machine().screen[0].visarea, machine().gfx[0],
m_tape_unknown_write[5]+'0',
1,
0,0,
0*8,8*8, 0);
drawgfx_transpen(bitmap,&machine().screen[0].visarea, machine().gfx[1],
drawgfx_transpen(bitmap,&machine().screen[0].visarea, machine().gfx[0],
m_tape_interrupts_enabled+'0',
1,
0,0,

View File

@ -1,15 +1,792 @@
/**********************************************************************
General Instruments AY-3-8900-1 a.k.a. Standard Television Interface Chip
(STIC) emulation for Mattel Intellivision
Copyright MESS Team.
Visit http://mamedev.org for licensing and usage restrictions.
*********************************************************************/
#include "emu.h"
#include "video/stic.h"
#include "includes/intv.h"
/* STIC variables */
READ16_MEMBER( intv_state::intv_stic_r )
const device_type STIC = &device_creator<stic_device>;
//-------------------------------------------------
// stic_device - constructor
//-------------------------------------------------
stic_device::stic_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
device_t(mconfig, STIC, "STIC (Standard Television Interface Chip) Video Chip", tag, owner, clock, "stic", __FILE__),
m_grom_region(*this, "grom"),
m_x_scale(1),
m_y_scale(1)
{
// intv_state *state = space.machine().driver_data<intv_state>();
//logerror("%x = stic_r(%x)\n",0,offset);
if (m_bus_copy_mode || !m_stic_handshake)
}
//-------------------------------------------------
// ~stic_device - destructor
//-------------------------------------------------
stic_device::~stic_device()
{
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void stic_device::device_start()
{
machine().primary_screen->register_screen_bitmap(m_bitmap);
save_item(NAME(m_stic_registers));
save_item(NAME(m_gramdirty));
save_item(NAME(m_gram));
save_item(NAME(m_gramdirtybytes));
save_item(NAME(m_color_stack_mode));
save_item(NAME(m_color_stack_offset));
save_item(NAME(m_stic_handshake));
save_item(NAME(m_border_color));
save_item(NAME(m_col_delay));
save_item(NAME(m_row_delay));
save_item(NAME(m_left_edge_inhibit));
save_item(NAME(m_top_edge_inhibit));
save_item(NAME(m_backtab_buffer));
for (int sp = 0; sp < STIC_MOBS; sp++)
{
state_save_register_item(machine(), "STIC sprite", NULL, sp, m_sprite[sp].visible);
state_save_register_item(machine(), "STIC sprite", NULL, sp, m_sprite[sp].xpos);
state_save_register_item(machine(), "STIC sprite", NULL, sp, m_sprite[sp].ypos);
state_save_register_item(machine(), "STIC sprite", NULL, sp, m_sprite[sp].coll);
state_save_register_item(machine(), "STIC sprite", NULL, sp, m_sprite[sp].collision);
state_save_register_item(machine(), "STIC sprite", NULL, sp, m_sprite[sp].doublex);
state_save_register_item(machine(), "STIC sprite", NULL, sp, m_sprite[sp].doubley);
state_save_register_item(machine(), "STIC sprite", NULL, sp, m_sprite[sp].quady);
state_save_register_item(machine(), "STIC sprite", NULL, sp, m_sprite[sp].xflip);
state_save_register_item(machine(), "STIC sprite", NULL, sp, m_sprite[sp].yflip);
state_save_register_item(machine(), "STIC sprite", NULL, sp, m_sprite[sp].behind_foreground);
state_save_register_item(machine(), "STIC sprite", NULL, sp, m_sprite[sp].grom);
state_save_register_item(machine(), "STIC sprite", NULL, sp, m_sprite[sp].card);
state_save_register_item(machine(), "STIC sprite", NULL, sp, m_sprite[sp].color);
state_save_register_item(machine(), "STIC sprite", NULL, sp, m_sprite[sp].doubleyres);
state_save_register_item(machine(), "STIC sprite", NULL, sp, m_sprite[sp].dirty);
state_save_register_item(machine(), "STIC sprite", NULL, sp, m_sprite_buffers[sp]);
}
}
void stic_device::device_reset()
{
for (int i = 0; i < STIC_MOBS; i++)
{
intv_sprite_type* s = &m_sprite[i];
s->visible = 0;
s->xpos = 0;
s->ypos = 0;
s->coll = 0;
s->collision = 0;
s->doublex = 0;
s->doubley = 0;
s->quady = 0;
s->xflip = 0;
s->yflip = 0;
s->behind_foreground = 0;
s->grom = 0;
s->card = 0;
s->color = 0;
s->doubleyres = 0;
s->dirty = 1;
for (int j = 0; j < 16; j++)
{
for (int k = 0; k < 128; k++)
{
m_sprite_buffers[i][j][k] = 0;
}
}
}
memset(m_stic_registers, 0, sizeof(m_stic_registers));
m_gramdirty = 1;
for (int i = 0; i < 64; i++)
{
m_gram[i] = 0;
m_gramdirtybytes[i] = 1;
}
m_color_stack_mode = 0;
m_color_stack_offset = 0;
m_stic_handshake = 0;
m_border_color = 0;
m_col_delay = 0;
m_row_delay = 0;
m_left_edge_inhibit = 0;
m_top_edge_inhibit = 0;
}
ROM_START( stic_grom )
ROM_REGION( 0x800, "grom", ROMREGION_ERASEFF )
ROM_LOAD( "ro-3-9503-003.u21", 0, 0x0800, CRC(683a4158) SHA1(f9608bb4ad1cfe3640d02844c7ad8e0bcd974917))
ROM_END
const rom_entry *stic_device::device_rom_region() const
{
return ROM_NAME( stic_grom );
}
#define FOREGROUND_BIT 0x0010
// conversion from Intellivision color to internal representation
#define SET_COLOR(c) ((c * 2) + 1)
#define GET_COLOR(c) ((c - 1) / 2)
/* initialized to non-zero, because we divide by it */
void stic_device::intv_set_pixel(bitmap_ind16 &bitmap, int x, int y, UINT32 color)
{
int w, h;
// output scaling
x *= m_x_scale;
y *= m_y_scale;
color = SET_COLOR(color);
for (h = 0; h < m_y_scale; h++)
for (w = 0; w < m_x_scale; w++)
bitmap.pix16(y + h, x + w) = color;
}
UINT32 stic_device::intv_get_pixel(bitmap_ind16 &bitmap, int x, int y)
{
return GET_COLOR(bitmap.pix16(y * m_y_scale, x * m_x_scale));
}
void stic_device::intv_plot_box(bitmap_ind16 &bitmap, int x, int y, int w, int h, int color)
{
bitmap.plot_box(x * m_x_scale, y * m_y_scale, w * m_x_scale, h * m_y_scale, SET_COLOR(color));
}
int stic_device::sprites_collide(int spriteNum1, int spriteNum2)
{
INT16 x0, y0, w0, h0, x1, y1, w1, h1, x2, y2, w2, h2;
intv_sprite_type* s1 = &m_sprite[spriteNum1];
intv_sprite_type* s2 = &m_sprite[spriteNum2];
x0 = STIC_OVERSCAN_LEFT_WIDTH + m_col_delay - STIC_CARD_WIDTH;
y0 = STIC_OVERSCAN_TOP_HEIGHT + m_row_delay - STIC_CARD_HEIGHT;
x1 = (s1->xpos + x0) * STIC_X_SCALE; y1 = (s1->ypos + y0) * STIC_Y_SCALE;
x2 = (s2->xpos + x0) * STIC_X_SCALE; y2 = (s2->ypos + y0) * STIC_Y_SCALE;
w1 = (s1->doublex ? 2 : 1) * STIC_CARD_WIDTH;
w2 = (s2->doublex ? 2 : 1) * STIC_CARD_WIDTH;
h1 = (s1->quady ? 4 : 1) * (s1->doubley ? 2 : 1) * (s1->doubleyres ? 2 : 1) * STIC_CARD_HEIGHT;
h2 = (s2->quady ? 4 : 1) * (s2->doubley ? 2 : 1) * (s2->doubleyres ? 2 : 1) * STIC_CARD_HEIGHT;
if ((x1 >= x2 + w2) || (y1 >= y2 + h2) ||
(x2 >= x1 + w1) || (y2 >= y1 + h1))
return FALSE;
// iterate over the intersecting bits to see if any touch
x0 = MAX(x1, x2);
y0 = MAX(y1, y2);
w0 = MIN(x1 + w1, x2 + w2) - x0;
h0 = MIN(y1 + h1, y2 + h2) - y0;
x1 = x0 - x1;
y1 = y0 - y1;
x2 = x0 - x2;
y2 = y0 - y2;
for (x0 = 0; x0 < w0; x0++)
{
for (y0 = 0; y0 < h0; y0++)
{
if (m_sprite_buffers[spriteNum1][x0 + x1][y0 + y1] &&
m_sprite_buffers[spriteNum2][x0 + x2][y0 + y2])
return TRUE;
}
}
return FALSE;
}
void stic_device::determine_sprite_collisions()
{
// check sprite to sprite collisions
for (int i = 0; i < STIC_MOBS - 1; i++)
{
intv_sprite_type* s1 = &m_sprite[i];
if (s1->xpos == 0 || !s1->coll)
continue;
for (int j = i + 1; j < STIC_MOBS; j++)
{
intv_sprite_type* s2 = &m_sprite[j];
if (s2->xpos == 0 || !s2->coll)
continue;
if (sprites_collide(i, j))
{
s1->collision |= (1 << j);
s2->collision |= (1 << i);
}
}
}
}
void stic_device::render_sprites()
{
INT32 cardMemoryLocation, pixelSize;
INT32 spritePixelHeight;
INT32 nextMemoryLocation;
INT32 nextData;
INT32 nextX;
INT32 nextY;
INT32 xInc;
UINT8* memory = m_grom_region->base();
for (int i = 0; i < STIC_MOBS; i++)
{
intv_sprite_type* s = &m_sprite[i];
if (s->grom)
cardMemoryLocation = (s->card * STIC_CARD_HEIGHT);
else
cardMemoryLocation = ((s->card & 0x003F) * STIC_CARD_HEIGHT);
pixelSize = (s->quady ? 4 : 1) * (s->doubley ? 2 : 1);
spritePixelHeight = pixelSize * (s->doubleyres ? 2 : 1) * STIC_CARD_HEIGHT;
for (int j = 0; j < spritePixelHeight; j++)
{
nextMemoryLocation = (cardMemoryLocation + (j/pixelSize));
if (s->grom)
nextData = memory[nextMemoryLocation];
else if (nextMemoryLocation < 0x200)
nextData = m_gram[nextMemoryLocation];
else
nextData = 0xFFFF;
nextX = (s->xflip ? ((s->doublex ? 2 : 1) * STIC_CARD_WIDTH - 1) : 0);
nextY = (s->yflip ? (spritePixelHeight - j - 1) : j);
xInc = (s->xflip ? -1: 1);
for (int k = 0; k < STIC_CARD_WIDTH * (1 + s->doublex); k++)
{
m_sprite_buffers[i][nextX + k * xInc][nextY] = (nextData & (1 << ((STIC_CARD_WIDTH - 1) - k / (1 + s->doublex)))) != 0;
}
}
}
}
void stic_device::render_line(bitmap_ind16 &bitmap, UINT8 nextByte, UINT16 x, UINT16 y, UINT8 fgcolor, UINT8 bgcolor)
{
UINT32 color;
for (int i = 0; i < STIC_CARD_WIDTH; i++)
{
color = (nextByte & (1 << ((STIC_CARD_WIDTH - 1) - i)) ? fgcolor : bgcolor);
intv_set_pixel(bitmap, x+i, y, color);
intv_set_pixel(bitmap, x+i, y+1, color);
}
}
void stic_device::render_colored_squares(bitmap_ind16 &bitmap, UINT16 x, UINT16 y, UINT8 color0, UINT8 color1, UINT8 color2, UINT8 color3)
{
intv_plot_box(bitmap, x, y, STIC_CSQM_WIDTH * STIC_X_SCALE, STIC_CSQM_HEIGHT * STIC_Y_SCALE, color0);
intv_plot_box(bitmap, x + STIC_CSQM_WIDTH * STIC_X_SCALE, y, STIC_CSQM_WIDTH * STIC_X_SCALE, STIC_CSQM_HEIGHT * STIC_Y_SCALE, color1);
intv_plot_box(bitmap, x, y + STIC_CSQM_HEIGHT * STIC_Y_SCALE, STIC_CSQM_WIDTH * STIC_X_SCALE, STIC_CSQM_HEIGHT * STIC_Y_SCALE, color2);
intv_plot_box(bitmap, x + STIC_CSQM_WIDTH * STIC_X_SCALE, y + STIC_CSQM_HEIGHT * STIC_Y_SCALE, STIC_CSQM_WIDTH * STIC_X_SCALE, STIC_CSQM_HEIGHT * STIC_Y_SCALE, color3);
}
void stic_device::render_color_stack_mode(bitmap_ind16 &bitmap)
{
INT16 w, h, nextx, nexty;
UINT8 csPtr = 0;
UINT16 nextCard;
UINT8 *ram = m_grom_region->base();
for (h = 0, nexty = (STIC_OVERSCAN_TOP_HEIGHT + m_row_delay) * STIC_Y_SCALE;
h < STIC_BACKTAB_HEIGHT;
h++, nexty += STIC_CARD_HEIGHT * STIC_Y_SCALE)
{
for (w = 0, nextx = (STIC_OVERSCAN_LEFT_WIDTH + m_col_delay) * STIC_X_SCALE;
w < STIC_BACKTAB_WIDTH;
w++, nextx += STIC_CARD_WIDTH * STIC_X_SCALE)
{
nextCard = m_backtab_buffer[h][w];
// colored squares mode
if ((nextCard & (STIC_CSTM_FG3|STIC_CSTM_SEL)) == STIC_CSTM_FG3)
{
UINT8 csColor = m_stic_registers[STIC_CSR + csPtr];
UINT8 color0 = nextCard & STIC_CSQM_A;
UINT8 color1 = (nextCard & STIC_CSQM_B) >> 3;
UINT8 color2 = (nextCard & STIC_CSQM_C) >> 6;
UINT8 color3 = ((nextCard & STIC_CSQM_D2) >> 11) |
((nextCard & (STIC_CSQM_D10)) >> 9);
render_colored_squares(bitmap, nextx, nexty,
(color0 == 7 ? csColor : (color0 | FOREGROUND_BIT)),
(color1 == 7 ? csColor : (color1 | FOREGROUND_BIT)),
(color2 == 7 ? csColor : (color2 | FOREGROUND_BIT)),
(color3 == 7 ? csColor : (color3 | FOREGROUND_BIT)));
}
//color stack mode
else
{
UINT8 isGrom;
UINT16 memoryLocation, fgcolor, bgcolor;
UINT8* memory;
//advance the color pointer, if necessary
if (nextCard & STIC_CSTM_ADV)
csPtr = (csPtr+1) & (STIC_CSRS - 1);
fgcolor = ((nextCard & STIC_CSTM_FG3) >> 9) |
(nextCard & (STIC_CSTM_FG20)) | FOREGROUND_BIT;
bgcolor = m_stic_registers[STIC_CSR + csPtr] & STIC_CSR_BG;
isGrom = !(nextCard & STIC_CSTM_SEL);
if (isGrom)
{
memoryLocation = nextCard & STIC_CSTM_C;
memory = ram;
for (int j = 0; j < STIC_CARD_HEIGHT; j++)
render_line(bitmap, memory[memoryLocation + j],
nextx, nexty + j * STIC_Y_SCALE, fgcolor, bgcolor);
}
else
{
memoryLocation = nextCard & STIC_CSTM_C50;
memory = m_gram;
for (int j = 0; j < STIC_CARD_HEIGHT; j++)
render_line(bitmap, memory[memoryLocation + j],
nextx, nexty + j * STIC_Y_SCALE, fgcolor, bgcolor);
}
}
}
}
}
void stic_device::render_fg_bg_mode(bitmap_ind16 &bitmap)
{
INT16 w, h, nextx, nexty;
UINT8 isGrom, fgcolor, bgcolor;
UINT16 nextCard, memoryLocation;
UINT8* memory;
UINT8* ram = m_grom_region->base();
for (h = 0, nexty = (STIC_OVERSCAN_TOP_HEIGHT + m_row_delay) * STIC_Y_SCALE;
h < STIC_BACKTAB_HEIGHT;
h++, nexty += STIC_CARD_HEIGHT * STIC_Y_SCALE)
{
for (w = 0, nextx = (STIC_OVERSCAN_LEFT_WIDTH + m_col_delay) * STIC_X_SCALE;
w < STIC_BACKTAB_WIDTH;
w++, nextx += STIC_CARD_WIDTH * STIC_X_SCALE)
{
nextCard = m_backtab_buffer[h][w];
fgcolor = (nextCard & STIC_FBM_FG) | FOREGROUND_BIT;
bgcolor = ((nextCard & STIC_FBM_BG2) >> 11) |
((nextCard & STIC_FBM_BG310) >> 9);
isGrom = !(nextCard & STIC_FBM_SEL);
if (isGrom)
{
memoryLocation = nextCard & STIC_FBM_C;
memory = ram;
for (int j = 0; j < STIC_CARD_HEIGHT; j++)
render_line(bitmap, memory[memoryLocation + j],
nextx, nexty + j * STIC_Y_SCALE, fgcolor, bgcolor);
}
else
{
memoryLocation = nextCard & STIC_FBM_C;
memory = m_gram;
for (int j = 0; j < STIC_CARD_HEIGHT; j++)
render_line(bitmap, memory[memoryLocation + j],
nextx, nexty + j * STIC_Y_SCALE, fgcolor, bgcolor);
}
}
}
}
void stic_device::copy_sprites_to_background(bitmap_ind16 &bitmap)
{
UINT8 width, currentPixel;
UINT8 borderCollision, foregroundCollision;
UINT8 spritePixelHeight, x, y;
INT16 leftX, nextY;
INT16 leftBorder, rightBorder, topBorder, bottomBorder;
INT32 nextX;
for (int i = STIC_MOBS - 1; i >= 0; i--)
{
intv_sprite_type *s = &m_sprite[i];
if (s->xpos == 0 || (!s->coll && !s->visible))
continue;
borderCollision = FALSE;
foregroundCollision = FALSE;
spritePixelHeight = (s->quady ? 4 : 1) * (s->doubley ? 2 : 1) * (s->doubleyres ? 2 : 1) * STIC_CARD_HEIGHT;
width = (s->doublex ? 2 : 1) * STIC_CARD_WIDTH;
leftX = (s->xpos - STIC_CARD_WIDTH + STIC_OVERSCAN_LEFT_WIDTH + m_col_delay) * STIC_X_SCALE;
nextY = (s->ypos - STIC_CARD_HEIGHT + STIC_OVERSCAN_TOP_HEIGHT + m_row_delay) * STIC_Y_SCALE;
leftBorder = (STIC_OVERSCAN_LEFT_WIDTH + (m_left_edge_inhibit ? STIC_CARD_WIDTH : 0)) * STIC_X_SCALE;
rightBorder = (STIC_OVERSCAN_LEFT_WIDTH + STIC_BACKTAB_WIDTH * STIC_CARD_WIDTH - 1 - 1) * STIC_X_SCALE;
topBorder = (STIC_OVERSCAN_TOP_HEIGHT + (m_top_edge_inhibit ? STIC_CARD_HEIGHT : 0)) * STIC_Y_SCALE;
bottomBorder = (STIC_OVERSCAN_TOP_HEIGHT + STIC_BACKTAB_HEIGHT * STIC_CARD_HEIGHT) * STIC_Y_SCALE - 1;
for (y = 0; y < spritePixelHeight; y++)
{
for (x = 0; x < width; x++)
{
//if this sprite pixel is not on, then don't paint it
if (!m_sprite_buffers[i][x][y])
continue;
nextX = leftX + x;
//if the next pixel location is on the border, then we
//have a border collision and we can ignore painting it
if ((nextX < leftBorder) || (nextX > rightBorder) ||
(nextY < topBorder) || (nextY > bottomBorder))
{
borderCollision = TRUE;
continue;
}
currentPixel = intv_get_pixel(bitmap, nextX, nextY);
//check for foreground collision
if (currentPixel & FOREGROUND_BIT)
{
foregroundCollision = TRUE;
if (s->behind_foreground)
continue;
}
if (s->visible)
{
intv_set_pixel(bitmap, nextX, nextY, s->color | (currentPixel & FOREGROUND_BIT));
}
}
nextY++;
}
//update the collision bits
if (s->coll)
{
if (foregroundCollision)
s->collision |= STIC_MCR_BKGD;
if (borderCollision)
s->collision |= STIC_MCR_BRDR;
}
}
}
void stic_device::render_background(bitmap_ind16 &bitmap)
{
if (m_color_stack_mode)
render_color_stack_mode(bitmap);
else
render_fg_bg_mode(bitmap);
}
#ifdef UNUSED_CODE
void stic_device::draw_background(bitmap_ind16 &bitmap, int transparency)
{
// First, draw the background
int offs = 0;
int value = 0;
int row,col;
int fgcolor,bgcolor = 0;
int code;
int colora, colorb, colorc, colord;
int n_bit;
int p_bit;
int g_bit;
int j;
int x0 = STIC_OVERSCAN_LEFT_WIDTH + m_col_delay;
int y0 = STIC_OVERSCAN_TOP_HEIGHT + m_row_delay;
if (m_color_stack_mode == 1)
{
m_color_stack_offset = 0;
for(row = 0; row < STIC_BACKTAB_HEIGHT; row++)
{
for(col = 0; col < STIC_BACKTAB_WIDTH; col++)
{
value = m_ram16[offs];
n_bit = value & STIC_CSTM_ADV;
p_bit = value & STIC_CSTM_FG3;
g_bit = value & STIC_CSTM_SEL;
if (p_bit && (!g_bit)) // colored squares mode
{
colora = value & STIC_CSQM_A;
colorb = (value & STIC_CSQM_B) >> 3;
colorc = (value & STIC_CSQM_C) >> 6;
colord = ((n_bit & STIC_CSQM_D2) >> 11) + ((value & STIC_CSQM_D10) >> 9);
// color 7 if the top of the color stack in this mode
if (colora == 7) colora = m_stic_registers[STIC_CSR + STIC_CSR3];
if (colorb == 7) colorb = m_stic_registers[STIC_CSR + STIC_CSR3];
if (colorc == 7) colorc = m_stic_registers[STIC_CSR + STIC_CSR3];
if (colord == 7) colord = m_stic_registers[STIC_CSR + STIC_CSR3];
intv_plot_box(bitmap, (x0 + col * STIC_CARD_WIDTH) * STIC_X_SCALE, (y0 + row * STIC_CARD_HEIGHT) * STIC_Y_SCALE, STIC_CSQM_WIDTH * STIC_X_SCALE, STIC_CSQM_HEIGHT * STIC_Y_SCALE, colora);
intv_plot_box(bitmap, (x0 + col * STIC_CARD_WIDTH + STIC_CSQM_WIDTH)) * STIC_X_SCALE, (y0 + row * STIC_CARD_HEIGHT) * STIC_Y_SCALE, STIC_CSQM_WIDTH * STIC_X_SCALE, STIC_CSQM_HEIGHT * STIC_Y_SCALE, colorb);
intv_plot_box(bitmap, (x0 + col * STIC_CARD_WIDTH) * STIC_X_SCALE, (y0 + row * STIC_CARD_HEIGHT + STIC_CSQM_HEIGHT) * STIC_Y_SCALE, STIC_CSQM_WIDTH * STIC_X_SCALE, STIC_CSQM_HEIGHT * STIC_Y_SCALE, colorc);
intv_plot_box(bitmap, (x0 + col * STIC_CARD_WIDTH + STIC_CSQM_WIDTH) * STIC_X_SCALE, (y0 + row * STIC_CARD_HEIGHT + STIC_CSQM_HEIGHT) * STIC_Y_SCALE, STIC_CSQM_WIDTH * STIC_X_SCALE, STIC_CSQM_HEIGHT * STIC_Y_SCALE, colord);
}
else // normal color stack mode
{
if (n_bit) // next color
{
m_color_stack_offset += 1;
m_color_stack_offset &= (STIC_CSRS - 1);
}
if (p_bit) // pastel color set
fgcolor = (value & STIC_CSTM_FG20) + 8;
else
fgcolor = value & STIC_CSTM_FG20;
bgcolor = m_stic_registers[STIC_CSR + m_color_stack_offset];
code = (value & STIC_CSTM_C)>>3;
if (g_bit) // read from gram
{
code &= (STIC_CSTM_C50 >> 3); // keep from going outside the array
//if (m_gramdirtybytes[code] == 1)
{
decodechar(machine().gfx[1],
code,
m_gram,
machine().config()->gfxdecodeinfo[1].gfxlayout);
m_gramdirtybytes[code] = 0;
}
// Draw GRAM char
drawgfx(bitmap,machine().gfx[1],
code,
bgcolor*16+fgcolor,
0,0, (x0 + col * STIC_CARD_WIDTH) * STIC_X_SCALE, (y0 + row * STIC_CARD_HEIGHT) * STIC_Y_SCALE,
0,transparency,bgcolor);
for(j=0;j<8;j++)
{
//intv_set_pixel(bitmap, (x0 + col * STIC_CARD_WIDTH + j) * STIC_X_SCALE, (y0 + row * STIC_CARD_HEIGHT + 7) * STIC_Y_SCALE + 1, 1);
}
}
else // read from grom
{
drawgfx(bitmap,machine().gfx[0],
code,
bgcolor*16+fgcolor,
0,0, (x0 + col * STIC_CARD_WIDTH) * STIC_X_SCALE, (y0 + row * STIC_CARD_HEIGHT) * STIC_Y_SCALE,
0,transparency,bgcolor);
for(j=0;j<8;j++)
{
//intv_set_pixel(bitmap, (x0 + col * STIC_CARD_WIDTH + j) * STIC_X_SCALE, (y0 + row * STIC_CARD_HEIGHT + 7) * STIC_Y_SCALE + 1, 2);
}
}
}
offs++;
} // next col
} // next row
}
else
{
// fg/bg mode goes here
for(row = 0; row < STIC_BACKTAB_HEIGHT; row++)
{
for(col = 0; col < STIC_BACKTAB_WIDTH; col++)
{
value = m_ram16[offs];
fgcolor = value & STIC_FBM_FG;
bgcolor = ((value & STIC_FBM_BG2) >> 11) + ((value & STIC_FBM_BG310) >> 9);
code = (value & STIC_FBM_C) >> 3;
if (value & STIC_FBM_SEL) // read for GRAM
{
//if (m_gramdirtybytes[code] == 1)
{
decodechar(machine().gfx[1],
code,
m_gram,
machine().config()->gfxdecodeinfo[1].gfxlayout);
m_gramdirtybytes[code] = 0;
}
// Draw GRAM char
drawgfx(bitmap,machine().gfx[1],
code,
bgcolor*16+fgcolor,
0,0, (x0 + col * STIC_CARD_WIDTH) * STIC_X_SCALE, (y0 + row * STIC_CARD_HEIGHT) * STIC_Y_SCALE,
0,transparency,bgcolor);
}
else // read from GROM
{
drawgfx(bitmap,machine().gfx[0],
code,
bgcolor*16+fgcolor,
0,0, (x0 + col * STIC_CARD_WIDTH) * STIC_X_SCALE, (y0 + row * STIC_CARD_HEIGHT) * STIC_Y_SCALE,
0,transparency,bgcolor);
}
offs++;
} // next col
} // next row
}
}
#endif
/* TBD: need to handle sprites behind foreground? */
#ifdef UNUSED_FUNCTION
void stic_device::draw_sprites(bitmap_ind16 &bitmap, int behind_foreground)
{
int code;
int x0 = STIC_OVERSCAN_LEFT_WIDTH + m_col_delay - STIC_CARD_WIDTH;
int y0 = STIC_OVERSCAN_TOP_HEIGHT + m_row_delay - STIC_CARD_HEIGHT;
for (int i = STIC_MOBS - 1; i >= 0; --i)
{
intv_sprite_type *s = &m_sprite[i];
if (s->visible && (s->behind_foreground == behind_foreground))
{
code = s->card;
if (!s->grom)
{
code %= 64; // keep from going outside the array
if (s->yres == 1)
{
//if (m_gramdirtybytes[code] == 1)
{
decodechar(machine().gfx[1],
code,
m_gram,
machine().config()->gfxdecodeinfo[1].gfxlayout);
m_gramdirtybytes[code] = 0;
}
// Draw GRAM char
drawgfxzoom_transpen(bitmap,&machine().screen[0].visarea,machine().gfx[1],
code,
s->color,
s->xflip,s->yflip,
(s->xpos + x0) * STIC_X_SCALE, (s->ypos + y0) * STIC_Y_SCALE,
0x8000 * s->xsize, 0x8000 * s->ysize,0);
}
else
{
//if ((m_gramdirtybytes[code] == 1) || (m_gramdirtybytes[code+1] == 1))
{
decodechar(machine().gfx[1],
code,
m_gram,
machine().config()->gfxdecodeinfo[1].gfxlayout);
decodechar(machine().gfx[1],
code+1,
m_gram,
machine().config()->gfxdecodeinfo[1].gfxlayout);
m_gramdirtybytes[code] = 0;
m_gramdirtybytes[code+1] = 0;
}
// Draw GRAM char
drawgfxzoom_transpen(bitmap,&machine().screen[0].visarea,machine().gfx[1],
code,
s->color,
s->xflip,s->yflip,
(s->xpos + x0) * STIC_X_SCALE, (s->ypos + y0) * STIC_Y_SCALE + s->yflip * s->ysize * STIC_CARD_HEIGHT,
0x8000*s->xsize, 0x8000*s->ysize,0);
drawgfxzoom_transpen(bitmap,&machine().screen[0].visarea,machine().gfx[1],
code+1,
s->color,
s->xflip,s->yflip,
(s->xpos + x0) * STIC_X_SCALE, (s->ypos + y0) * STIC_Y_SCALE + (1 - s->yflip) * s->ysize * STIC_CARD_HEIGHT,
0x8000*s->xsize, 0x8000*s->ysize,0);
}
}
else
{
if (s->yres == 1)
{
// Draw GROM char
drawgfxzoom_transpen(bitmap,&machine().screen[0].visarea,machine().gfx[0],
code,
s->color,
s->xflip,s->yflip,
(s->xpos + x0) * STIC_X_SCALE, (s->ypos + y0) * STIC_Y_SCALE,
0x8000*s->xsize, 0x8000*s->ysize,0);
}
else
{
drawgfxzoom_transpen(bitmap,&machine().screen[0].visarea,machine().gfx[0],
code,
s->color,
s->xflip,s->yflip,
(s->xpos + x0) * STIC_X_SCALE, (s->ypos + y0) * STIC_Y_SCALE + s->yflip * s->ysize * STIC_CARD_HEIGHT,
0x8000*s->xsize, 0x8000*s->ysize,0);
drawgfxzoom_transpen(bitmap,&machine().screen[0].visarea,machine().gfx[0],
code+1,
s->color,
s->xflip,s->yflip,
(s->xpos + x0) * STIC_X_SCALE, (s->ypos + y0) * STIC_Y_SCALE + (1 - s->yflip) * s->ysize * STIC_CARD_HEIGHT,
0x8000*s->xsize, 0x8000*s->ysize,0);
}
}
}
}
}
#endif
void stic_device::draw_borders(bitmap_ind16 &bitmap)
{
intv_plot_box(bitmap, 0, 0, (STIC_OVERSCAN_LEFT_WIDTH + (m_left_edge_inhibit ? STIC_CARD_WIDTH : m_col_delay)) * STIC_X_SCALE, (STIC_OVERSCAN_TOP_HEIGHT + STIC_BACKTAB_HEIGHT * STIC_CARD_HEIGHT + STIC_OVERSCAN_BOTTOM_HEIGHT) * STIC_Y_SCALE, m_border_color);
intv_plot_box(bitmap, (STIC_OVERSCAN_LEFT_WIDTH + STIC_BACKTAB_WIDTH * STIC_CARD_WIDTH - 1) * STIC_X_SCALE, 0, STIC_OVERSCAN_RIGHT_WIDTH, (STIC_OVERSCAN_TOP_HEIGHT + STIC_BACKTAB_HEIGHT * STIC_CARD_HEIGHT + STIC_OVERSCAN_BOTTOM_HEIGHT) * STIC_Y_SCALE, m_border_color);
intv_plot_box(bitmap, 0, 0, (STIC_OVERSCAN_LEFT_WIDTH + STIC_BACKTAB_WIDTH * STIC_CARD_WIDTH - 1 + STIC_OVERSCAN_RIGHT_WIDTH) * STIC_X_SCALE, (STIC_OVERSCAN_TOP_HEIGHT + (m_top_edge_inhibit ? STIC_CARD_HEIGHT : m_row_delay)) * STIC_Y_SCALE, m_border_color);
intv_plot_box(bitmap, 0, (STIC_OVERSCAN_TOP_HEIGHT + STIC_BACKTAB_HEIGHT * STIC_CARD_HEIGHT) * STIC_Y_SCALE, (STIC_OVERSCAN_LEFT_WIDTH + STIC_BACKTAB_WIDTH * STIC_CARD_WIDTH - 1 + STIC_OVERSCAN_RIGHT_WIDTH) * STIC_X_SCALE, STIC_OVERSCAN_BOTTOM_HEIGHT * STIC_Y_SCALE, m_border_color);
}
void stic_device::screenrefresh()
{
if (m_stic_handshake != 0)
{
m_stic_handshake = 0;
// Render the background
render_background(m_bitmap);
// Render the sprites into their buffers
render_sprites();
for (int i = 0; i < STIC_MOBS; i++)
m_sprite[i].collision = 0;
// Copy the sprites to the background
copy_sprites_to_background(m_bitmap);
determine_sprite_collisions();
for (int i = 0; i < STIC_MOBS; i++)
m_stic_registers[STIC_MCR + i] |= m_sprite[i].collision;
/* draw the screen borders if enabled */
draw_borders(m_bitmap);
}
else
{
/* STIC disabled, just fill with border color */
m_bitmap.fill(SET_COLOR(m_border_color));
}
}
READ16_MEMBER( stic_device::read )
{
//logerror("%x = stic_r(%x)\n",0,offset);
switch (offset)
{
case STIC_MXR + STIC_MOB0:
@ -69,21 +846,16 @@ READ16_MEMBER( intv_state::intv_stic_r )
//logerror("unmapped read from STIC register %02X\n", offset);
return 0x3FFF;
}
}
else { return (offset); }
}
WRITE16_MEMBER( intv_state::intv_stic_w )
WRITE16_MEMBER( stic_device::write )
{
//intv_state *state = space.machine().driver_data<intv_state>();
intv_sprite_type *s;
//logerror("stic_w(%x) = %x\n",offset,data);
if (m_bus_copy_mode || !m_stic_handshake)
{
switch (offset)
{
/* X Positions */
// X Positions
case STIC_MXR + STIC_MOB0:
case STIC_MXR + STIC_MOB1:
case STIC_MXR + STIC_MOB2:
@ -98,7 +870,7 @@ WRITE16_MEMBER( intv_state::intv_stic_w )
s->coll = !!(data & STIC_MXR_COL);
s->xpos = (data & STIC_MXR_X);
break;
/* Y Positions */
// Y Positions
case STIC_MYR + STIC_MOB0:
case STIC_MYR + STIC_MOB1:
case STIC_MYR + STIC_MOB2:
@ -115,7 +887,7 @@ WRITE16_MEMBER( intv_state::intv_stic_w )
s->doubleyres = !!(data & STIC_MYR_YRES);
s->ypos = (data & STIC_MYR_Y);
break;
/* Attributes */
// Attributes
case STIC_MAR + STIC_MOB0:
case STIC_MAR + STIC_MOB1:
case STIC_MAR + STIC_MOB2:
@ -130,7 +902,7 @@ WRITE16_MEMBER( intv_state::intv_stic_w )
s->card = ((data & STIC_MAR_C) >> 3);
s->color = ((data & STIC_MAR_FG3) >> 9) | (data & STIC_MAR_FG20);
break;
/* Collision Detection - TBD */
// Collision Detection - TBD
case STIC_MCR + STIC_MOB0:
case STIC_MCR + STIC_MOB1:
case STIC_MCR + STIC_MOB2:
@ -143,28 +915,28 @@ WRITE16_MEMBER( intv_state::intv_stic_w )
// one is poked into it
data &= ~(1 << (offset & (STIC_MOBS - 1)));
break;
/* Display enable */
// Display enable
case STIC_DER:
//logerror("***Writing a %x to the STIC handshake\n",data);
m_stic_handshake = 1;
break;
/* Graphics Mode */
// Graphics Mode
case STIC_GMR:
m_color_stack_mode = 0;
break;
/* Color Stack */
// Color Stack
case STIC_CSR + STIC_CSR0:
case STIC_CSR + STIC_CSR1:
case STIC_CSR + STIC_CSR2:
case STIC_CSR + STIC_CSR3:
logerror("Setting color_stack[%x] = %x (%x)\n", offset & (STIC_CSRS - 1),data & STIC_CSR_BG, space.device().safe_pc());
break;
/* Border Color */
// Border Color
case STIC_BCR:
//logerror("***Writing a %x to the border color\n",data);
m_border_color = data & STIC_BCR_BC;
break;
/* Framing */
// Framing
case STIC_HDR:
m_col_delay = data & STIC_HDR_DEL;
break;
@ -179,8 +951,29 @@ WRITE16_MEMBER( intv_state::intv_stic_w )
//logerror("unmapped write to STIC register %02X: %04X\n", offset, data);
break;
}
if (offset < sizeof(m_stic_registers) / sizeof(m_stic_registers[0]))
m_stic_registers[offset] = data;
}
}
READ16_MEMBER( stic_device::gram_read )
{
return m_gram[offset];
}
WRITE16_MEMBER( stic_device::gram_write )
{
data &= 0xff;
m_gram[offset] = data;
m_gramdirtybytes[offset] = 1;
m_gramdirty = 1;
}
UINT32 stic_device::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
copybitmap(bitmap, m_bitmap, 0, 0, 0, 0, cliprect);
return 0;
}

View File

@ -445,4 +445,113 @@ enum
#define STIC_CSQM_WIDTH (STIC_CARD_WIDTH / 2)
#define STIC_CSQM_HEIGHT (STIC_CARD_HEIGHT / 2)
struct intv_sprite_type
{
int visible;
int xpos;
int ypos;
int coll;
int collision;
int doublex;
int doubley;
int quady;
int xflip;
int yflip;
int behind_foreground;
int grom;
int card;
int color;
int doubleyres;
int dirty;
};
// ======================> stic_device
class stic_device : public device_t
{
public:
// construction/destruction
stic_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
virtual ~stic_device();
DECLARE_READ16_MEMBER(read);
DECLARE_READ16_MEMBER(gram_read);
DECLARE_READ16_MEMBER(grom_read) { if (offset > 0x800) printf("help! %X\n", offset); return (0xff00 | m_grom_region->base()[offset]); }
DECLARE_WRITE16_MEMBER(write);
DECLARE_WRITE16_MEMBER(gram_write);
void write_to_btb(int h, int w, UINT16 data) { m_backtab_buffer[h][w] = data; }
int read_row_delay() { return m_row_delay; }
int read_stic_handshake() { return m_stic_handshake; }
void set_x_scale(int val) { m_x_scale = val; }
void set_y_scale(int val) { m_y_scale = val; }
// device-level overrides
virtual void device_start();
virtual const rom_entry *device_rom_region() const;
virtual void device_reset();
void screenrefresh();
UINT32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
private:
required_memory_region m_grom_region;
void intv_set_pixel(bitmap_ind16 &bitmap, int x, int y, UINT32 color);
UINT32 intv_get_pixel(bitmap_ind16 &bitmap, int x, int y);
void intv_plot_box(bitmap_ind16 &bm, int x, int y, int w, int h, int color);
int sprites_collide(int spriteNum1, int spriteNum2);
void determine_sprite_collisions();
void render_sprites();
void render_line(bitmap_ind16 &bitmap, UINT8 nextByte, UINT16 x, UINT16 y, UINT8 fgcolor, UINT8 bgcolor);
void render_colored_squares(bitmap_ind16 &bitmap, UINT16 x, UINT16 y, UINT8 color0, UINT8 color1, UINT8 color2, UINT8 color3);
void render_color_stack_mode(bitmap_ind16 &bitmap);
void render_fg_bg_mode(bitmap_ind16 &bitmap);
void copy_sprites_to_background(bitmap_ind16 &bitmap);
void render_background(bitmap_ind16 &bitmap);
void draw_borders(bitmap_ind16 &bitmap);
#ifdef UNUSED_CODE
void draw_background(bitmap_ind16 &bitmap, int transparency);
void draw_sprites(bitmap_ind16 &bitmap, int behind_foreground);
#endif
bitmap_ind16 m_bitmap;
intv_sprite_type m_sprite[STIC_MOBS];
UINT8 m_sprite_buffers[STIC_MOBS][STIC_CARD_WIDTH * 2][STIC_CARD_HEIGHT * 4 * 2 * 2];
UINT16 m_backtab_buffer[STIC_BACKTAB_HEIGHT][STIC_BACKTAB_WIDTH];
int m_color_stack_mode;
int m_stic_registers[STIC_REGISTERS];
int m_color_stack_offset;
int m_stic_handshake;
int m_border_color;
int m_col_delay;
int m_row_delay;
int m_left_edge_inhibit;
int m_top_edge_inhibit;
int m_x_scale;
int m_y_scale;
UINT8 m_gramdirty;
UINT8 m_gram[512];
UINT8 m_gramdirtybytes[512];
};
// device type definition
extern const device_type STIC;
/***************************************************************************
DEVICE CONFIGURATION MACROS
***************************************************************************/
#define MCFG_STIC_ADD(_tag) \
MCFG_DEVICE_ADD(_tag, STIC, 0)
#endif /* STIC_H_ */