mirror of
https://github.com/holub/mame
synced 2025-05-18 19:49:35 +03:00
starfire.c: Improved color emulation and added driver data [Qwi Jibo]
This commit is contained in:
parent
dfdc249c0d
commit
59939fe8c0
@ -49,12 +49,6 @@ starfira has one less rom in total than starfire but everything passes as
|
||||
#include "includes/starfire.h"
|
||||
|
||||
|
||||
|
||||
static UINT8 fireone_select;
|
||||
static read8_space_func input_read;
|
||||
|
||||
|
||||
|
||||
/*************************************
|
||||
*
|
||||
* Scratch RAM, mapped into video RAM
|
||||
@ -63,35 +57,39 @@ static read8_space_func input_read;
|
||||
|
||||
static WRITE8_HANDLER( starfire_scratch_w )
|
||||
{
|
||||
starfire_state *state = space->machine->driver_data<starfire_state>();
|
||||
|
||||
/* A12 and A3 select video control registers */
|
||||
if ((offset & 0x1008) == 0x1000)
|
||||
{
|
||||
switch (offset & 7)
|
||||
{
|
||||
case 0: starfire_vidctrl_w(space, 0, data); break;
|
||||
case 1: starfire_vidctrl1_w(space, 0, data); break;
|
||||
case 0: state->starfire_vidctrl = data; break;
|
||||
case 1: state->starfire_vidctrl1 = data; break;
|
||||
case 2:
|
||||
/* Sounds */
|
||||
fireone_select = (data & 0x8) ? 0 : 1;
|
||||
state->fireone_select = (data & 0x8) ? 0 : 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* convert to a videoram offset */
|
||||
offset = (offset & 0x31f) | ((offset & 0xe0) << 5);
|
||||
starfire_videoram[offset] = data;
|
||||
state->starfire_videoram[offset] = data;
|
||||
}
|
||||
|
||||
|
||||
static READ8_HANDLER( starfire_scratch_r )
|
||||
{
|
||||
starfire_state *state = space->machine->driver_data<starfire_state>();
|
||||
|
||||
/* A11 selects input ports */
|
||||
if (offset & 0x800)
|
||||
return (*input_read)(space, offset);
|
||||
return (*state->input_read)(space, offset);
|
||||
|
||||
/* convert to a videoram offset */
|
||||
offset = (offset & 0x31f) | ((offset & 0xe0) << 5);
|
||||
return starfire_videoram[offset];
|
||||
return state->starfire_videoram[offset];
|
||||
}
|
||||
|
||||
|
||||
@ -131,12 +129,14 @@ static READ8_HANDLER( fireone_input_r )
|
||||
};
|
||||
int temp;
|
||||
|
||||
starfire_state *state = space->machine->driver_data<starfire_state>();
|
||||
|
||||
switch (offset & 15)
|
||||
{
|
||||
case 0: return input_port_read(space->machine, "DSW");
|
||||
case 1: return input_port_read(space->machine, "SYSTEM");
|
||||
case 2:
|
||||
temp = fireone_select ? input_port_read(space->machine, "P1") : input_port_read(space->machine, "P2");
|
||||
temp = state->fireone_select ? input_port_read(space->machine, "P1") : input_port_read(space->machine, "P2");
|
||||
temp = (temp & 0xc0) | fireone_paddle_map[temp & 0x3f];
|
||||
return temp;
|
||||
default: return 0xff;
|
||||
@ -154,8 +154,8 @@ static READ8_HANDLER( fireone_input_r )
|
||||
static ADDRESS_MAP_START( main_map, ADDRESS_SPACE_PROGRAM, 8 )
|
||||
AM_RANGE(0x0000, 0x7fff) AM_ROM
|
||||
AM_RANGE(0x8000, 0x9fff) AM_READWRITE(starfire_scratch_r, starfire_scratch_w)
|
||||
AM_RANGE(0xa000, 0xbfff) AM_RAM_WRITE(starfire_colorram_w) AM_BASE(&starfire_colorram)
|
||||
AM_RANGE(0xc000, 0xffff) AM_READWRITE(starfire_videoram_r, starfire_videoram_w) AM_BASE(&starfire_videoram)
|
||||
AM_RANGE(0xa000, 0xbfff) AM_READWRITE(starfire_colorram_r, starfire_colorram_w) AM_BASE_MEMBER(starfire_state, starfire_colorram)
|
||||
AM_RANGE(0xc000, 0xffff) AM_READWRITE(starfire_videoram_r, starfire_videoram_w) AM_BASE_MEMBER(starfire_state, starfire_videoram)
|
||||
ADDRESS_MAP_END
|
||||
|
||||
|
||||
@ -261,7 +261,7 @@ INPUT_PORTS_END
|
||||
*
|
||||
*************************************/
|
||||
|
||||
static MACHINE_CONFIG_START( starfire, driver_device )
|
||||
static MACHINE_CONFIG_START( starfire, starfire_state )
|
||||
|
||||
/* basic machine hardware */
|
||||
MCFG_CPU_ADD("maincpu", Z80, STARFIRE_CPU_CLOCK)
|
||||
@ -376,15 +376,19 @@ ROM_END
|
||||
|
||||
static DRIVER_INIT( starfire )
|
||||
{
|
||||
input_read = starfire_input_r;
|
||||
starfire_state *state = machine->driver_data<starfire_state>();
|
||||
|
||||
state->input_read = starfire_input_r;
|
||||
}
|
||||
|
||||
static DRIVER_INIT( fireone )
|
||||
{
|
||||
input_read = fireone_input_r;
|
||||
starfire_state *state = machine->driver_data<starfire_state>();
|
||||
|
||||
state->input_read = fireone_input_r;
|
||||
|
||||
/* register for state saving */
|
||||
state_save_register_global(machine, fireone_select);
|
||||
state_save_register_global(machine, state->fireone_select);
|
||||
}
|
||||
|
||||
|
||||
|
@ -8,19 +8,37 @@
|
||||
#define STARFIRE_VTOTAL (0x106)
|
||||
#define STARFIRE_VBEND (0x020)
|
||||
#define STARFIRE_VBSTART (0x100)
|
||||
#define STARFIRE_NUM_PENS (0x40)
|
||||
|
||||
class starfire_state : public driver_device
|
||||
{
|
||||
public:
|
||||
starfire_state(running_machine &machine, const driver_device_config_base &config)
|
||||
: driver_device(machine, config) { }
|
||||
|
||||
read8_space_func input_read;
|
||||
|
||||
UINT8 fireone_select;
|
||||
|
||||
UINT8 starfire_vidctrl;
|
||||
UINT8 starfire_vidctrl1;
|
||||
UINT8 starfire_color;
|
||||
UINT16 starfire_colors[STARFIRE_NUM_PENS];
|
||||
|
||||
UINT8 *starfire_videoram;
|
||||
UINT8 *starfire_colorram;
|
||||
|
||||
emu_timer* scanline_timer;
|
||||
bitmap_t *starfire_screen;
|
||||
};
|
||||
|
||||
/*----------- defined in video/starfire.c -----------*/
|
||||
|
||||
extern UINT8 *starfire_videoram;
|
||||
extern UINT8 *starfire_colorram;
|
||||
|
||||
VIDEO_UPDATE( starfire );
|
||||
VIDEO_START( starfire );
|
||||
|
||||
WRITE8_HANDLER( starfire_videoram_w );
|
||||
READ8_HANDLER( starfire_videoram_r );
|
||||
WRITE8_HANDLER( starfire_colorram_w );
|
||||
WRITE8_HANDLER( starfire_vidctrl_w );
|
||||
WRITE8_HANDLER( starfire_vidctrl1_w );
|
||||
READ8_HANDLER( starfire_colorram_r );
|
||||
|
||||
|
@ -7,20 +7,7 @@
|
||||
#include "emu.h"
|
||||
#include "includes/starfire.h"
|
||||
|
||||
|
||||
#define NUM_PENS (0x40)
|
||||
|
||||
|
||||
UINT8 *starfire_videoram;
|
||||
UINT8 *starfire_colorram;
|
||||
|
||||
/* local allocated storage */
|
||||
static UINT8 starfire_vidctrl;
|
||||
static UINT8 starfire_vidctrl1;
|
||||
static UINT8 starfire_color;
|
||||
static UINT16 starfire_colors[NUM_PENS];
|
||||
|
||||
|
||||
static TIMER_CALLBACK( starfire_scanline_callback );
|
||||
|
||||
/*************************************
|
||||
*
|
||||
@ -30,33 +17,20 @@ static UINT16 starfire_colors[NUM_PENS];
|
||||
|
||||
VIDEO_START( starfire )
|
||||
{
|
||||
starfire_state *state = machine->driver_data<starfire_state>();
|
||||
|
||||
state->starfire_screen = machine->primary_screen->alloc_compatible_bitmap();
|
||||
state->scanline_timer = timer_alloc(machine, starfire_scanline_callback, NULL);
|
||||
timer_adjust_oneshot(state->scanline_timer, machine->primary_screen->time_until_pos(STARFIRE_VBEND), STARFIRE_VBEND);
|
||||
|
||||
/* register for state saving */
|
||||
state_save_register_global(machine, starfire_vidctrl);
|
||||
state_save_register_global(machine, starfire_vidctrl1);
|
||||
state_save_register_global(machine, starfire_color);
|
||||
state_save_register_global_array(machine, starfire_colors);
|
||||
state_save_register_global(machine, state->starfire_vidctrl);
|
||||
state_save_register_global(machine, state->starfire_vidctrl1);
|
||||
state_save_register_global(machine, state->starfire_color);
|
||||
state_save_register_global_array(machine, state->starfire_colors);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*************************************
|
||||
*
|
||||
* Video control writes
|
||||
*
|
||||
*************************************/
|
||||
|
||||
WRITE8_HANDLER( starfire_vidctrl_w )
|
||||
{
|
||||
starfire_vidctrl = data;
|
||||
}
|
||||
|
||||
WRITE8_HANDLER( starfire_vidctrl1_w )
|
||||
{
|
||||
starfire_vidctrl1 = data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*************************************
|
||||
*
|
||||
* Color RAM read/writes
|
||||
@ -65,25 +39,27 @@ WRITE8_HANDLER( starfire_vidctrl1_w )
|
||||
|
||||
WRITE8_HANDLER( starfire_colorram_w )
|
||||
{
|
||||
starfire_state *state = space->machine->driver_data<starfire_state>();
|
||||
|
||||
/* handle writes to the pseudo-color RAM */
|
||||
if ((offset & 0xe0) == 0)
|
||||
{
|
||||
int palette_index = (offset & 0x1f) | ((offset & 0x200) >> 4);
|
||||
|
||||
/* set RAM regardless */
|
||||
starfire_colorram[offset & ~0x100] = data;
|
||||
starfire_colorram[offset | 0x100] = data;
|
||||
int cl = (state->starfire_vidctrl1 & 0x80) ? state->starfire_color : (data & 0x1f);
|
||||
int cr = (data >> 5) | ((offset & 0x100) >> 5);
|
||||
cr |= (state->starfire_vidctrl1 & 0x80) ? (state->starfire_color & 0x10) : (data & 0x10);
|
||||
|
||||
starfire_color = data & 0x1f;
|
||||
state->starfire_colorram[offset & ~0x100] = cl;
|
||||
state->starfire_colorram[offset | 0x100] = cr;
|
||||
|
||||
state->starfire_color = cl;
|
||||
|
||||
/* don't modify the palette unless the TRANS bit is set */
|
||||
if (starfire_vidctrl1 & 0x40)
|
||||
if (state->starfire_vidctrl1 & 0x40)
|
||||
{
|
||||
space->machine->primary_screen->update_partial(space->machine->primary_screen->vpos());
|
||||
|
||||
starfire_colors[palette_index] = ((((data << 1) & 0x06) | ((offset >> 8) & 0x01)) << 6) |
|
||||
(((data >> 5) & 0x07) << 3) |
|
||||
((data >> 2) & 0x07);
|
||||
state->starfire_colors[palette_index] = ((cl & 0x3) << 7) | ((cr & 0xf) << 3) | ((cl & 0x1c) >> 2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,12 +67,33 @@ WRITE8_HANDLER( starfire_colorram_w )
|
||||
else
|
||||
{
|
||||
/* set RAM based on CDRM */
|
||||
starfire_colorram[offset] = (starfire_vidctrl1 & 0x80) ? starfire_color : (data & 0x1f);
|
||||
starfire_color = data & 0x1f;
|
||||
state->starfire_colorram[offset] = (state->starfire_vidctrl1 & 0x80) ? state->starfire_color : (data & 0x1f);
|
||||
state->starfire_color = (state->starfire_vidctrl1 & 0x80) ? state->starfire_color : (data & 0x1f);
|
||||
}
|
||||
}
|
||||
|
||||
READ8_HANDLER( starfire_colorram_r )
|
||||
{
|
||||
starfire_state *state = space->machine->driver_data<starfire_state>();
|
||||
|
||||
/* handle writes to the pseudo-color RAM, which also happen on reads */
|
||||
if ((offset & 0xe0) == 0)
|
||||
{
|
||||
int palette_index = (offset & 0x1f) | ((offset & 0x200) >> 4);
|
||||
int cl = state->starfire_colorram[offset & ~0x100];
|
||||
int cr = state->starfire_colorram[offset | 0x100];
|
||||
|
||||
/* don't modify the palette unless the TRANS bit is set */
|
||||
if (state->starfire_vidctrl1 & 0x40)
|
||||
{
|
||||
state->starfire_colors[palette_index] = ((cl & 0x3) << 7) | ((cr & 0xf) << 3) | ((cl & 0x1c) >> 2);
|
||||
}
|
||||
|
||||
return cl | ((cr & 0x7) << 5);
|
||||
}
|
||||
|
||||
return state->starfire_colorram[offset];
|
||||
}
|
||||
|
||||
/*************************************
|
||||
*
|
||||
@ -109,21 +106,22 @@ WRITE8_HANDLER( starfire_videoram_w )
|
||||
int sh, lr, dm, ds, mask, d0, dalu;
|
||||
int offset1 = offset & 0x1fff;
|
||||
int offset2 = (offset + 0x100) & 0x1fff;
|
||||
starfire_state *state = space->machine->driver_data<starfire_state>();
|
||||
|
||||
/* PROT */
|
||||
if (!(offset & 0xe0) && !(starfire_vidctrl1 & 0x20))
|
||||
if (!(offset & 0xe0) && !(state->starfire_vidctrl1 & 0x20))
|
||||
return;
|
||||
|
||||
/* selector 6A */
|
||||
if (offset & 0x2000)
|
||||
{
|
||||
sh = (starfire_vidctrl >> 1) & 0x07;
|
||||
lr = starfire_vidctrl & 0x01;
|
||||
sh = (state->starfire_vidctrl >> 1) & 0x07;
|
||||
lr = state->starfire_vidctrl & 0x01;
|
||||
}
|
||||
else
|
||||
{
|
||||
sh = (starfire_vidctrl >> 5) & 0x07;
|
||||
lr = (starfire_vidctrl >> 4) & 0x01;
|
||||
sh = (state->starfire_vidctrl >> 5) & 0x07;
|
||||
lr = (state->starfire_vidctrl >> 4) & 0x01;
|
||||
}
|
||||
|
||||
/* mirror bits 5B/5C/5D/5E */
|
||||
@ -139,18 +137,18 @@ WRITE8_HANDLER( starfire_videoram_w )
|
||||
/* ROLL */
|
||||
if ((offset & 0x1f00) == 0x1f00)
|
||||
{
|
||||
if (starfire_vidctrl1 & 0x10)
|
||||
if (state->starfire_vidctrl1 & 0x10)
|
||||
mask &= 0x00ff;
|
||||
else
|
||||
mask &= 0xff00;
|
||||
}
|
||||
|
||||
/* ALU 8B/8D */
|
||||
d0 = (starfire_videoram[offset1] << 8) | starfire_videoram[offset2];
|
||||
d0 = (state->starfire_videoram[offset1] << 8) | state->starfire_videoram[offset2];
|
||||
dalu = d0 & ~mask;
|
||||
d0 &= mask;
|
||||
ds &= mask;
|
||||
switch (~starfire_vidctrl1 & 15)
|
||||
switch (~state->starfire_vidctrl1 & 15)
|
||||
{
|
||||
case 0: dalu |= ds ^ mask; break;
|
||||
case 1: dalu |= (ds | d0) ^ mask; break;
|
||||
@ -171,16 +169,16 @@ WRITE8_HANDLER( starfire_videoram_w )
|
||||
}
|
||||
|
||||
/* final output */
|
||||
starfire_videoram[offset1] = dalu >> 8;
|
||||
starfire_videoram[offset2] = dalu;
|
||||
state->starfire_videoram[offset1] = dalu >> 8;
|
||||
state->starfire_videoram[offset2] = dalu;
|
||||
|
||||
/* color output */
|
||||
if (!(offset & 0x2000) && !(starfire_vidctrl1 & 0x80))
|
||||
if (!(offset & 0x2000) && !(state->starfire_vidctrl1 & 0x80))
|
||||
{
|
||||
if (mask & 0xff00)
|
||||
starfire_colorram[offset1] = starfire_color;
|
||||
state->starfire_colorram[offset1] = state->starfire_color;
|
||||
if (mask & 0x00ff)
|
||||
starfire_colorram[offset2] = starfire_color;
|
||||
state->starfire_colorram[offset2] = state->starfire_color;
|
||||
}
|
||||
}
|
||||
|
||||
@ -189,12 +187,13 @@ READ8_HANDLER( starfire_videoram_r )
|
||||
int sh, mask, d0;
|
||||
int offset1 = offset & 0x1fff;
|
||||
int offset2 = (offset + 0x100) & 0x1fff;
|
||||
starfire_state *state = space->machine->driver_data<starfire_state>();
|
||||
|
||||
/* selector 6A */
|
||||
if (offset & 0x2000)
|
||||
sh = (starfire_vidctrl >> 1) & 0x07;
|
||||
sh = (state->starfire_vidctrl >> 1) & 0x07;
|
||||
else
|
||||
sh = (starfire_vidctrl >> 5) & 0x07;
|
||||
sh = (state->starfire_vidctrl >> 5) & 0x07;
|
||||
|
||||
/* shifters 6D/6E */
|
||||
mask = 0xff00 >> sh;
|
||||
@ -202,14 +201,14 @@ READ8_HANDLER( starfire_videoram_r )
|
||||
/* ROLL */
|
||||
if ((offset & 0x1f00) == 0x1f00)
|
||||
{
|
||||
if (starfire_vidctrl1 & 0x10)
|
||||
if (state->starfire_vidctrl1 & 0x10)
|
||||
mask &= 0x00ff;
|
||||
else
|
||||
mask &= 0xff00;
|
||||
}
|
||||
|
||||
/* munge the results */
|
||||
d0 = (starfire_videoram[offset1] & (mask >> 8)) | (starfire_videoram[offset2] & mask);
|
||||
d0 = (state->starfire_videoram[offset1] & (mask >> 8)) | (state->starfire_videoram[offset2] & mask);
|
||||
d0 = (d0 << sh) | (d0 >> (8 - sh));
|
||||
return d0 & 0xff;
|
||||
}
|
||||
@ -222,49 +221,57 @@ READ8_HANDLER( starfire_videoram_r )
|
||||
*
|
||||
*************************************/
|
||||
|
||||
static void get_pens(pen_t *pens)
|
||||
static void get_pens(running_machine *machine, pen_t *pens)
|
||||
{
|
||||
offs_t offs;
|
||||
starfire_state *state = machine->driver_data<starfire_state>();
|
||||
|
||||
for (offs = 0; offs < NUM_PENS; offs++)
|
||||
for (offs = 0; offs < STARFIRE_NUM_PENS; offs++)
|
||||
{
|
||||
UINT16 color = starfire_colors[offs];
|
||||
UINT16 color = state->starfire_colors[offs];
|
||||
|
||||
pens[offs] = MAKE_RGB(pal3bit(color >> 6), pal3bit(color >> 3), pal3bit(color >> 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VIDEO_UPDATE( starfire )
|
||||
static TIMER_CALLBACK( starfire_scanline_callback )
|
||||
{
|
||||
pen_t pens[NUM_PENS];
|
||||
starfire_state *state = machine->driver_data<starfire_state>();
|
||||
pen_t pens[STARFIRE_NUM_PENS];
|
||||
int y = param;
|
||||
|
||||
UINT8 *pix = &starfire_videoram[cliprect->min_y - 32];
|
||||
UINT8 *col = &starfire_colorram[cliprect->min_y - 32];
|
||||
int x, y;
|
||||
get_pens(machine, pens);
|
||||
|
||||
get_pens(pens);
|
||||
UINT8 *pix = &state->starfire_videoram[y];
|
||||
UINT8 *col = &state->starfire_colorram[y];
|
||||
|
||||
for (x = 0; x < 256; x += 8)
|
||||
for (int x = 0; x < 256; x += 8)
|
||||
{
|
||||
for (y = cliprect->min_y; y <= cliprect->max_y ; y++)
|
||||
{
|
||||
int data = pix[y];
|
||||
int color = col[y];
|
||||
int data = pix[0];
|
||||
int color = col[0];
|
||||
|
||||
*BITMAP_ADDR32(bitmap, y, x + 0) = pens[color | ((data >> 2) & 0x20)];
|
||||
*BITMAP_ADDR32(bitmap, y, x + 1) = pens[color | ((data >> 1) & 0x20)];
|
||||
*BITMAP_ADDR32(bitmap, y, x + 2) = pens[color | ((data >> 0) & 0x20)];
|
||||
*BITMAP_ADDR32(bitmap, y, x + 3) = pens[color | ((data << 1) & 0x20)];
|
||||
*BITMAP_ADDR32(bitmap, y, x + 4) = pens[color | ((data << 2) & 0x20)];
|
||||
*BITMAP_ADDR32(bitmap, y, x + 5) = pens[color | ((data << 3) & 0x20)];
|
||||
*BITMAP_ADDR32(bitmap, y, x + 6) = pens[color | ((data << 4) & 0x20)];
|
||||
*BITMAP_ADDR32(bitmap, y, x + 7) = pens[color | ((data << 5) & 0x20)];
|
||||
}
|
||||
*BITMAP_ADDR32(state->starfire_screen, y, x + 0) = pens[color | ((data >> 2) & 0x20)];
|
||||
*BITMAP_ADDR32(state->starfire_screen, y, x + 1) = pens[color | ((data >> 1) & 0x20)];
|
||||
*BITMAP_ADDR32(state->starfire_screen, y, x + 2) = pens[color | ((data >> 0) & 0x20)];
|
||||
*BITMAP_ADDR32(state->starfire_screen, y, x + 3) = pens[color | ((data << 1) & 0x20)];
|
||||
*BITMAP_ADDR32(state->starfire_screen, y, x + 4) = pens[color | ((data << 2) & 0x20)];
|
||||
*BITMAP_ADDR32(state->starfire_screen, y, x + 5) = pens[color | ((data << 3) & 0x20)];
|
||||
*BITMAP_ADDR32(state->starfire_screen, y, x + 6) = pens[color | ((data << 4) & 0x20)];
|
||||
*BITMAP_ADDR32(state->starfire_screen, y, x + 7) = pens[color | ((data << 5) & 0x20)];
|
||||
|
||||
pix += 256;
|
||||
col += 256;
|
||||
}
|
||||
|
||||
y++;
|
||||
if (y >= STARFIRE_VBSTART) y = STARFIRE_VBEND;
|
||||
timer_adjust_oneshot(state->scanline_timer, machine->primary_screen->time_until_pos(y), y);
|
||||
}
|
||||
|
||||
VIDEO_UPDATE( starfire )
|
||||
{
|
||||
starfire_state *state = screen->machine->driver_data<starfire_state>();
|
||||
copybitmap(bitmap, state->starfire_screen, 0, 0, 0, 0, cliprect);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user