Added driver data struct to bwing.c and slightly simplified the video code (by removing a couple of redundant variables).

More work would be needed to fully clean it up, but I'm not expert enough right now.
This commit is contained in:
Fabio Priuli 2009-11-27 00:42:04 +00:00
parent 792adf6a07
commit 6379e9c903
4 changed files with 306 additions and 164 deletions

1
.gitattributes vendored
View File

@ -2361,6 +2361,7 @@ src/mame/includes/btime.h svneol=native#text/plain
src/mame/includes/btoads.h svneol=native#text/plain src/mame/includes/btoads.h svneol=native#text/plain
src/mame/includes/bublbobl.h svneol=native#text/plain src/mame/includes/bublbobl.h svneol=native#text/plain
src/mame/includes/buggychl.h svneol=native#text/plain src/mame/includes/buggychl.h svneol=native#text/plain
src/mame/includes/bwing.h svneol=native#text/plain
src/mame/includes/bzone.h svneol=native#text/plain src/mame/includes/bzone.h svneol=native#text/plain
src/mame/includes/canyon.h svneol=native#text/plain src/mame/includes/canyon.h svneol=native#text/plain
src/mame/includes/capbowl.h svneol=native#text/plain src/mame/includes/capbowl.h svneol=native#text/plain

View File

@ -28,50 +28,25 @@ Known issues:
#include "cpu/m6502/m6502.h" #include "cpu/m6502/m6502.h"
#include "sound/ay8910.h" #include "sound/ay8910.h"
#include "sound/dac.h" #include "sound/dac.h"
#include "bwing.h"
#define BW_DEBUG 0
#define MAX_SOUNDS 16
//****************************************************************************
// Imports
extern const gfx_layout bwing_tilelayout;
extern WRITE8_HANDLER( bwing_paletteram_w );
extern WRITE8_HANDLER( bwing_videoram_w );
extern WRITE8_HANDLER( bwing_spriteram_w );
extern WRITE8_HANDLER( bwing_scrollreg_w );
extern WRITE8_HANDLER( bwing_scrollram_w );
extern READ8_HANDLER( bwing_scrollram_r );
extern VIDEO_START( bwing );
extern VIDEO_UPDATE( bwing );
//****************************************************************************
// Local Vars
static UINT8 sound_fifo[MAX_SOUNDS];
static UINT8 *bwp123_membase[3], *bwp3_rombase;
static UINT8 *bwp1_sharedram1, *bwp2_sharedram1;
static size_t bwp3_romsize;
static int bwp3_nmimask, bwp3_u8F_d, ffcount, ffhead, fftail;
//**************************************************************************** //****************************************************************************
// Interrupt Handlers // Interrupt Handlers
static INTERRUPT_GEN ( bwp1_interrupt ) static INTERRUPT_GEN ( bwp1_interrupt )
{ {
static int coin = 0; bwing_state *state = (bwing_state *)device->machine->driver_data;
UINT8 latch_data; UINT8 latch_data;
switch (cpu_getiloops(device)) switch (cpu_getiloops(device))
{ {
case 0: case 0:
if (ffcount) if (state->ffcount)
{ {
ffcount--; state->ffcount--;
latch_data = sound_fifo[fftail]; latch_data = state->sound_fifo[state->fftail];
fftail = (fftail + 1) & (MAX_SOUNDS - 1); state->fftail = (state->fftail + 1) & (MAX_SOUNDS - 1);
soundlatch_w(cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM), 0, latch_data); soundlatch_w(cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM), 0, latch_data);
cputag_set_input_line(device->machine, "audiocpu", DECO16_IRQ_LINE, HOLD_LINE); // SNDREQ cputag_set_input_line(device->machine, "audiocpu", DECO16_IRQ_LINE, HOLD_LINE); // SNDREQ
} }
@ -79,43 +54,75 @@ static INTERRUPT_GEN ( bwp1_interrupt )
case 1: case 1:
if (~input_port_read(device->machine, "IN2") & 0x03) if (~input_port_read(device->machine, "IN2") & 0x03)
{ if (!coin) { coin = 1; cpu_set_input_line(device, INPUT_LINE_NMI, ASSERT_LINE); } } {
if (!state->coin)
{
state->coin = 1;
cpu_set_input_line(device, INPUT_LINE_NMI, ASSERT_LINE);
}
}
else else
coin = 0; state->coin = 0;
break; break;
case 2: case 2:
if (input_port_read(device->machine, "IN3")) cpu_set_input_line(device, M6809_FIRQ_LINE, ASSERT_LINE); if (input_port_read(device->machine, "IN3"))
cpu_set_input_line(device, M6809_FIRQ_LINE, ASSERT_LINE);
break; break;
} }
} }
static INTERRUPT_GEN ( bwp3_interrupt ) { if (!bwp3_nmimask) cpu_set_input_line(device, INPUT_LINE_NMI, ASSERT_LINE); } static INTERRUPT_GEN ( bwp3_interrupt )
{
bwing_state *state = (bwing_state *)device->machine->driver_data;
if (!state->bwp3_nmimask)
cpu_set_input_line(device, INPUT_LINE_NMI, ASSERT_LINE);
}
//**************************************************************************** //****************************************************************************
// Memory and I/O Handlers // Memory and I/O Handlers
static WRITE8_HANDLER( bwp12_sharedram1_w ) { bwp1_sharedram1[offset] = bwp2_sharedram1[offset] = data; } static WRITE8_HANDLER( bwp12_sharedram1_w )
static WRITE8_HANDLER( bwp3_u8F_w ) { bwp3_u8F_d = data; } // prepares custom chip for various operations {
bwing_state *state = (bwing_state *)space->machine->driver_data;
state->bwp1_sharedram1[offset] = state->bwp2_sharedram1[offset] = data;
}
static WRITE8_HANDLER( bwp3_u8F_w )
{
bwing_state *state = (bwing_state *)space->machine->driver_data;
state->bwp3_u8F_d = data; // prepares custom chip for various operations
}
static WRITE8_HANDLER( bwp3_nmimask_w )
{
bwing_state *state = (bwing_state *)space->machine->driver_data;
state->bwp3_nmimask = data & 0x80;
}
static WRITE8_HANDLER( bwp3_nmiack_w ) { cputag_set_input_line(space->machine, "audiocpu", INPUT_LINE_NMI, CLEAR_LINE); } static WRITE8_HANDLER( bwp3_nmiack_w ) { cputag_set_input_line(space->machine, "audiocpu", INPUT_LINE_NMI, CLEAR_LINE); }
static WRITE8_HANDLER( bwp3_nmimask_w ) { bwp3_nmimask = data & 0x80; }
static READ8_HANDLER( bwp1_io_r ) static READ8_HANDLER( bwp1_io_r )
{ {
bwing_state *state = (bwing_state *)space->machine->driver_data;
if (offset == 0) return(input_port_read(space->machine, "DSW0")); if (offset == 0) return(input_port_read(space->machine, "DSW0"));
if (offset == 1) return(input_port_read(space->machine, "DSW1")); if (offset == 1) return(input_port_read(space->machine, "DSW1"));
if (offset == 2) return(input_port_read(space->machine, "IN0")); if (offset == 2) return(input_port_read(space->machine, "IN0"));
if (offset == 3) return(input_port_read(space->machine, "IN1")); if (offset == 3) return(input_port_read(space->machine, "IN1"));
if (offset == 4) return(input_port_read(space->machine, "IN2")); if (offset == 4) return(input_port_read(space->machine, "IN2"));
return((bwp123_membase[0])[0x1b00 + offset]); return((state->bwp123_membase[0])[0x1b00 + offset]);
} }
static WRITE8_HANDLER( bwp1_ctrl_w ) static WRITE8_HANDLER( bwp1_ctrl_w )
{ {
bwing_state *state = (bwing_state *)space->machine->driver_data;
switch (offset) switch (offset)
{ {
// MSSTB // MSSTB
@ -137,12 +144,11 @@ static WRITE8_HANDLER( bwp1_ctrl_w )
case 5: case 5:
if (data == 0x80) // protection trick to screw CPU1 & 3 if (data == 0x80) // protection trick to screw CPU1 & 3
cputag_set_input_line(space->machine, "sub", INPUT_LINE_NMI, ASSERT_LINE); // SNMI cputag_set_input_line(space->machine, "sub", INPUT_LINE_NMI, ASSERT_LINE); // SNMI
else else if (state->ffcount < MAX_SOUNDS)
if (ffcount < MAX_SOUNDS)
{ {
ffcount++; state->ffcount++;
sound_fifo[ffhead] = data; state->sound_fifo[state->ffhead] = data;
ffhead = (ffhead + 1) & (MAX_SOUNDS - 1); state->ffhead = (state->ffhead + 1) & (MAX_SOUNDS - 1);
} }
break; break;
@ -154,7 +160,7 @@ static WRITE8_HANDLER( bwp1_ctrl_w )
} }
#if BW_DEBUG #if BW_DEBUG
(bwp123_membase[0])[0x1c00 + offset] = data; (state->bwp123_membase[0])[0x1c00 + offset] = data;
#endif #endif
} }
@ -173,7 +179,10 @@ static WRITE8_HANDLER( bwp2_ctrl_w )
} }
#if BW_DEBUG #if BW_DEBUG
(bwp123_membase[1])[0x1800 + offset] = data; {
bwing_state *state = (bwing_state *)space->machine->driver_data;
(state->bwp123_membase[1])[0x1800 + offset] = data;
}
#endif #endif
} }
@ -183,12 +192,12 @@ static WRITE8_HANDLER( bwp2_ctrl_w )
// Main CPU // Main CPU
static ADDRESS_MAP_START( bwp1_map, ADDRESS_SPACE_PROGRAM, 8 ) static ADDRESS_MAP_START( bwp1_map, ADDRESS_SPACE_PROGRAM, 8 )
AM_RANGE(0x1b00, 0x1b07) AM_READ(bwp1_io_r) AM_RANGE(0x1b00, 0x1b07) AM_READ(bwp1_io_r)
AM_RANGE(0x0000, 0x07ff) AM_RAM_WRITE(bwp12_sharedram1_w) AM_BASE(&bwp1_sharedram1) AM_RANGE(0x0000, 0x07ff) AM_RAM_WRITE(bwp12_sharedram1_w) AM_BASE_MEMBER(bwing_state, bwp1_sharedram1)
AM_RANGE(0x0800, 0x0fff) AM_RAM AM_RANGE(0x0800, 0x0fff) AM_RAM
AM_RANGE(0x1000, 0x13ff) AM_RAM_WRITE(bwing_videoram_w) AM_BASE(&videoram) AM_RANGE(0x1000, 0x13ff) AM_RAM_WRITE(bwing_videoram_w) AM_BASE_MEMBER(bwing_state, videoram)
AM_RANGE(0x1400, 0x17ff) AM_RAM AM_RANGE(0x1400, 0x17ff) AM_RAM
AM_RANGE(0x1800, 0x19ff) AM_RAM_WRITE(bwing_spriteram_w) AM_BASE(&buffered_spriteram) AM_RANGE(0x1800, 0x19ff) AM_RAM_WRITE(bwing_spriteram_w) AM_BASE(&buffered_spriteram)
AM_RANGE(0x1a00, 0x1aff) AM_RAM_WRITE(bwing_paletteram_w) AM_BASE(&paletteram) AM_RANGE(0x1a00, 0x1aff) AM_RAM_WRITE(bwing_paletteram_w) AM_BASE_MEMBER(bwing_state, paletteram)
AM_RANGE(0x1b00, 0x1b07) AM_RAM_WRITE(bwing_scrollreg_w) AM_RANGE(0x1b00, 0x1b07) AM_RAM_WRITE(bwing_scrollreg_w)
AM_RANGE(0x1c00, 0x1c07) AM_RAM_WRITE(bwp1_ctrl_w) AM_RANGE(0x1c00, 0x1c07) AM_RAM_WRITE(bwp1_ctrl_w)
AM_RANGE(0x2000, 0x3fff) AM_READWRITE(bwing_scrollram_r, bwing_scrollram_w) AM_RANGE(0x2000, 0x3fff) AM_READWRITE(bwing_scrollram_r, bwing_scrollram_w)
@ -198,7 +207,7 @@ ADDRESS_MAP_END
// Sub CPU // Sub CPU
static ADDRESS_MAP_START( bwp2_map, ADDRESS_SPACE_PROGRAM, 8 ) static ADDRESS_MAP_START( bwp2_map, ADDRESS_SPACE_PROGRAM, 8 )
AM_RANGE(0x0000, 0x07ff) AM_RAM_WRITE(bwp12_sharedram1_w) AM_BASE(&bwp2_sharedram1) AM_RANGE(0x0000, 0x07ff) AM_RAM_WRITE(bwp12_sharedram1_w) AM_BASE_MEMBER(bwing_state, bwp2_sharedram1)
AM_RANGE(0x0800, 0x0fff) AM_RAM AM_RANGE(0x0800, 0x0fff) AM_RAM
AM_RANGE(0x1800, 0x1803) AM_WRITE(bwp2_ctrl_w) AM_RANGE(0x1800, 0x1803) AM_WRITE(bwp2_ctrl_w)
AM_RANGE(0xa000, 0xffff) AM_ROM AM_RANGE(0xa000, 0xffff) AM_ROM
@ -216,7 +225,7 @@ static ADDRESS_MAP_START( bwp3_map, ADDRESS_SPACE_PROGRAM, 8 )
AM_RANGE(0x8000, 0x8000) AM_DEVWRITE("ay2", ay8910_address_w) AM_RANGE(0x8000, 0x8000) AM_DEVWRITE("ay2", ay8910_address_w)
AM_RANGE(0xa000, 0xa000) AM_READ(soundlatch_r) AM_RANGE(0xa000, 0xa000) AM_READ(soundlatch_r)
AM_RANGE(0xd000, 0xd000) AM_WRITE(bwp3_nmimask_w) AM_RANGE(0xd000, 0xd000) AM_WRITE(bwp3_nmimask_w)
AM_RANGE(0xe000, 0xffff) AM_ROM AM_BASE(&bwp3_rombase) AM_SIZE(&bwp3_romsize) AM_RANGE(0xe000, 0xffff) AM_ROM AM_BASE_MEMBER(bwing_state, bwp3_rombase) AM_SIZE_MEMBER(bwing_state, bwp3_romsize)
ADDRESS_MAP_END ADDRESS_MAP_END
@ -359,16 +368,49 @@ GFXDECODE_END
//**************************************************************************** //****************************************************************************
// Hardware Definitions // Hardware Definitions
static MACHINE_RESET( bwing ) static MACHINE_START( bwing )
{ {
bwp3_nmimask = 0; bwing_state *state = (bwing_state *)machine->driver_data;
fftail = ffhead = ffcount = 0;
state_save_register_global(machine, state->coin);
state_save_register_global(machine, state->palatch);
state_save_register_global(machine, state->srbank);
state_save_register_global(machine, state->mapmask);
state_save_register_global(machine, state->mapflip);
state_save_register_global(machine, state->bwp3_nmimask);
state_save_register_global(machine, state->bwp3_u8F_d);
state_save_register_global(machine, state->ffcount);
state_save_register_global(machine, state->ffhead);
state_save_register_global(machine, state->fftail);
state_save_register_global_array(machine, state->sreg);
state_save_register_global_array(machine, state->sound_fifo);
} }
static MACHINE_RESET( bwing )
{
bwing_state *state = (bwing_state *)machine->driver_data;
int i;
state->coin = 0;
state->palatch = 0;
state->srbank = 0;
state->mapmask = 0;
state->mapflip = 0;
for (i = 0; i < MAX_SOUNDS; i++)
state->sound_fifo[i] = 0;
state->bwp3_nmimask = 0;
state->bwp3_u8F_d = 0;
state->fftail = state->ffhead = state->ffcount = 0;
}
static MACHINE_DRIVER_START( bwing ) static MACHINE_DRIVER_START( bwing )
/* driver data */
MDRV_DRIVER_DATA(bwing_state)
// basic machine hardware // basic machine hardware
MDRV_CPU_ADD("maincpu", M6809, 2000000) MDRV_CPU_ADD("maincpu", M6809, 2000000)
MDRV_CPU_PROGRAM_MAP(bwp1_map) MDRV_CPU_PROGRAM_MAP(bwp1_map)
@ -385,6 +427,7 @@ static MACHINE_DRIVER_START( bwing )
MDRV_QUANTUM_TIME(HZ(18000)) // high enough? MDRV_QUANTUM_TIME(HZ(18000)) // high enough?
MDRV_MACHINE_START(bwing)
MDRV_MACHINE_RESET(bwing) MDRV_MACHINE_RESET(bwing)
// video hardware // video hardware
@ -576,28 +619,31 @@ ROM_END
//**************************************************************************** //****************************************************************************
// Initializations // Initializations
static void fix_bwp3(void) static void fix_bwp3( running_machine *machine )
{ {
UINT8 *rom = bwp3_rombase; bwing_state *state = (bwing_state *)machine->driver_data;
int i, j = bwp3_romsize; UINT8 *rom = state->bwp3_rombase;
int i, j = state->bwp3_romsize;
UINT8 ah, al; UINT8 ah, al;
// swap nibbles // swap nibbles
for (i=0; i<j; i++) { ah = al = rom[i]; rom[i] = (ah >> 4) | (al << 4); } for (i = 0; i < j; i++) { ah = al = rom[i]; rom[i] = (ah >> 4) | (al << 4); }
// relocate vectors // relocate vectors
rom[j-(0x10-0x4)] = rom[j-(0x10-0xb)] = rom[j-(0x10-0x6)]; rom[j - (0x10 - 0x4)] = rom[j - (0x10 - 0xb)] = rom[j - (0x10 - 0x6)];
rom[j-(0x10-0x5)] = rom[j-(0x10-0xa)] = rom[j-(0x10-0x7)]; rom[j - (0x10 - 0x5)] = rom[j - (0x10 - 0xa)] = rom[j - (0x10 - 0x7)];
} }
static DRIVER_INIT( bwing ) static DRIVER_INIT( bwing )
{ {
bwp123_membase[0] = memory_region(machine, "maincpu"); bwing_state *state = (bwing_state *)machine->driver_data;
bwp123_membase[1] = memory_region(machine, "sub");
bwp123_membase[2] = memory_region(machine, "audiocpu");
fix_bwp3(); state->bwp123_membase[0] = memory_region(machine, "maincpu");
state->bwp123_membase[1] = memory_region(machine, "sub");
state->bwp123_membase[2] = memory_region(machine, "audiocpu");
fix_bwp3(machine);
} }
//**************************************************************************** //****************************************************************************

50
src/mame/includes/bwing.h Normal file
View File

@ -0,0 +1,50 @@
/***************************************************************************
B-Wings
***************************************************************************/
#define BW_DEBUG 0
#define MAX_SOUNDS 16
typedef struct _bwing_state bwing_state;
struct _bwing_state
{
/* memory pointers */
UINT8 * videoram;
UINT8 * spriteram;
UINT8 * paletteram;
UINT8 * bwp1_sharedram1;
UINT8 * bwp2_sharedram1;
UINT8 * bwp3_rombase;
size_t bwp3_romsize;
/* video-related */
tilemap *charmap, *fgmap, *bgmap;
UINT8 *srbase[4], *fgdata, *bgdata;
int *srxlat;
unsigned sreg[8], palatch, srbank, mapmask, mapflip;
/* sound-related */
UINT8 sound_fifo[MAX_SOUNDS];
int bwp3_nmimask, bwp3_u8F_d, ffcount, ffhead, fftail;
/* misc */
UINT8 *bwp123_membase[3];
int coin;
};
/*----------- defined in video/bwing.c -----------*/
extern const gfx_layout bwing_tilelayout;
WRITE8_HANDLER( bwing_paletteram_w );
WRITE8_HANDLER( bwing_videoram_w );
WRITE8_HANDLER( bwing_spriteram_w );
WRITE8_HANDLER( bwing_scrollreg_w );
WRITE8_HANDLER( bwing_scrollram_w );
READ8_HANDLER( bwing_scrollram_r );
VIDEO_START( bwing );
VIDEO_UPDATE( bwing );

View File

@ -9,38 +9,32 @@ drivers by Acho A. Tang
// Directives // Directives
#include "driver.h" #include "driver.h"
#include "bwing.h"
#define BW_DEBUG 0 #define BW_DEBUG 0
#define BW_NTILES_L2 7 #define BW_NTILES_L2 7
#define BW_NTILES (1<<BW_NTILES_L2) #define BW_NTILES (1<<BW_NTILES_L2)
//****************************************************************************
// Local Vars
static tilemap *scrollmap[2], *charmap, *fgmap, *bgmap;
static gfx_element *fgfx, *bgfx;
static UINT8 *srbase[4], *fgdata, *bgdata;
static int *srxlat;
static unsigned sreg[8], palatch=0, srbank=0, mapmask=0, mapflip=0;
//**************************************************************************** //****************************************************************************
// Local Functions // Local Functions
static void fill_srxlat(int *xlat) static void fill_srxlat( int *xlat )
{ {
unsigned base, offset, i; unsigned base, offset, i;
for(base=0; base<0x2000; base+=0x400) for (base = 0; base < 0x2000; base += 0x400)
{ {
for(i=0; i<0x100; i++) for(i = 0; i < 0x100; i++)
{ {
offset = base + (i<<2 & ~0x3f) + (i & 0x0f); offset = base + (i<<2 & ~0x3f) + (i & 0x0f);
xlat[base+i] = offset; xlat[base + i] = offset;
xlat[base+i+0x100] = offset + 0x10; xlat[base + i + 0x100] = offset + 0x10;
xlat[base+i+0x200] = offset + 0x20; xlat[base + i + 0x200] = offset + 0x20;
xlat[base+i+0x300] = offset + 0x30; xlat[base + i + 0x300] = offset + 0x30;
} }
} }
} }
@ -48,7 +42,6 @@ static void fill_srxlat(int *xlat)
//**************************************************************************** //****************************************************************************
// Exports // Exports
extern const gfx_layout bwing_tilelayout;
const gfx_layout bwing_tilelayout = const gfx_layout bwing_tilelayout =
{ {
16, 16, 16, 16,
@ -62,53 +55,75 @@ const gfx_layout bwing_tilelayout =
}; };
WRITE8_HANDLER( bwing_spriteram_w ) { buffered_spriteram[offset] = data; } WRITE8_HANDLER( bwing_spriteram_w )
WRITE8_HANDLER( bwing_videoram_w ) { videoram[offset] = data; tilemap_mark_tile_dirty(charmap, offset); } {
buffered_spriteram[offset] = data;
}
WRITE8_HANDLER( bwing_videoram_w )
{
bwing_state *state = (bwing_state *)space->machine->driver_data;
state->videoram[offset] = data;
tilemap_mark_tile_dirty(state->charmap, offset);
}
READ8_HANDLER ( bwing_scrollram_r ) READ8_HANDLER ( bwing_scrollram_r )
{ {
if (!srbank) offset = srxlat[offset]; bwing_state *state = (bwing_state *)space->machine->driver_data;
int offs;
return((srbase[srbank])[offset]); if (!state->srbank)
offs = state->srxlat[offset];
else
offs = offset;
return ((state->srbase[state->srbank])[offs]);
} }
WRITE8_HANDLER( bwing_scrollram_w ) WRITE8_HANDLER( bwing_scrollram_w )
{ {
if (!srbank) bwing_state *state = (bwing_state *)space->machine->driver_data;
{ int offs;
offset = srxlat[offset];
tilemap_mark_tile_dirty(scrollmap[offset>>12], offset & 0xfff); if (!state->srbank)
{
offs = state->srxlat[offset];
if (offs >> 12)
tilemap_mark_tile_dirty(state->bgmap, offs & 0xfff);
else
tilemap_mark_tile_dirty(state->fgmap, offs & 0xfff);
} }
else else
{ {
offs = offset;
if (offset < 0x1000) if (offset < 0x1000)
gfx_element_mark_dirty(fgfx, offset/32); gfx_element_mark_dirty(space->machine->gfx[2], offset / 32);
else else
gfx_element_mark_dirty(bgfx, offset/32); gfx_element_mark_dirty(space->machine->gfx[3], offset / 32);
} }
(srbase[srbank])[offset] = data; (state->srbase[state->srbank])[offs] = data;
} }
WRITE8_HANDLER( bwing_scrollreg_w ) WRITE8_HANDLER( bwing_scrollreg_w )
{ {
sreg[offset] = data; bwing_state *state = (bwing_state *)space->machine->driver_data;
state->sreg[offset] = data;
switch (offset) switch (offset)
{ {
case 6: palatch = data; break; // one of the palette components is latched through I/O(yike) case 6: state->palatch = data; break; // one of the palette components is latched through I/O(yike)
case 7: case 7:
// tile graphics are decoded in RAM on the fly and tile codes are banked + interleaved(ouch) // tile graphics are decoded in RAM on the fly and tile codes are banked + interleaved(ouch)
mapmask = data; state->mapmask = data;
srbank = data >> 6; state->srbank = data >> 6;
#if BW_DEBUG #if BW_DEBUG
logerror("(%s)%04x: w=%02x a=%04x f=%d\n", space->cpu->tag, cpu_get_pc(space->cpu),data,0x1b00+offset,video_screen_get_frame_number(space->machine->primary_screen)); logerror("(%s)%04x: w=%02x a=%04x f=%d\n", space->cpu->tag, cpu_get_pc(space->cpu), data, 0x1b00 + offset, video_screen_get_frame_number(space->machine->primary_screen));
#endif #endif
break; break;
} }
@ -121,18 +136,22 @@ WRITE8_HANDLER( bwing_scrollreg_w )
WRITE8_HANDLER( bwing_paletteram_w ) WRITE8_HANDLER( bwing_paletteram_w )
{ {
static const float rgb[4][3]={{0.85f,0.95f,1.00f},{0.90f,1.00f,1.00f},{0.80f,1.00f,1.00f},{0.75f,0.90f,1.10f}}; bwing_state *state = (bwing_state *)space->machine->driver_data;
static const float rgb[4][3] = {{0.85f, 0.95f, 1.00f},
{0.90f, 1.00f, 1.00f},
{0.80f, 1.00f, 1.00f},
{0.75f, 0.90f, 1.10f}};
int r, g, b, i; int r, g, b, i;
paletteram[offset] = data; state->paletteram[offset] = data;
r = ~data & 7; r = ~data & 7;
g = ~data>>4 & 7; g = ~(data >> 4) & 7;
b = ~palatch & 7; b = ~state->palatch & 7;
r = ((r<<5) + (r<<2) + (r>>1)); r = ((r << 5) + (r << 2) + (r >> 1));
g = ((g<<5) + (g<<2) + (g>>1)); g = ((g << 5) + (g << 2) + (g >> 1));
b = ((b<<5) + (b<<2) + (b>>1)); b = ((b << 5) + (b << 2) + (b >> 1));
if ((i = input_port_read(space->machine, "EXTRA")) < 4) if ((i = input_port_read(space->machine, "EXTRA")) < 4)
{ {
@ -147,96 +166,116 @@ WRITE8_HANDLER( bwing_paletteram_w )
palette_set_color(space->machine, offset, MAKE_RGB(r, g, b)); palette_set_color(space->machine, offset, MAKE_RGB(r, g, b));
#if BW_DEBUG #if BW_DEBUG
paletteram[offset+0x40] = palatch; state->paletteram[offset + 0x40] = state->palatch;
#endif #endif
} }
//**************************************************************************** //****************************************************************************
// Initializations // Initializations
#define BW_SET_TILE_INFO(GFX, CODE, COLOR) { \
tileinfo->pen_data = gfx_element_get_data(GFX, CODE); \
tileinfo->palette_base = GFX->color_base + ((COLOR) << 3); \
}
static TILE_GET_INFO( get_fgtileinfo ) static TILE_GET_INFO( get_fgtileinfo )
{ {
unsigned code = fgdata[tile_index]; bwing_state *state = (bwing_state *)machine->driver_data;
BW_SET_TILE_INFO(fgfx, code & (BW_NTILES-1), code >> 7); tileinfo->pen_data = gfx_element_get_data(machine->gfx[2], state->fgdata[tile_index] & (BW_NTILES - 1));
tileinfo->palette_base = machine->gfx[2]->color_base + ((state->fgdata[tile_index] >> 7) << 3);
} }
static TILE_GET_INFO( get_bgtileinfo ) static TILE_GET_INFO( get_bgtileinfo )
{ {
unsigned code = bgdata[tile_index]; bwing_state *state = (bwing_state *)machine->driver_data;
BW_SET_TILE_INFO(bgfx, code & (BW_NTILES-1), code >> 7); tileinfo->pen_data = gfx_element_get_data(machine->gfx[3], state->bgdata[tile_index] & (BW_NTILES - 1));
tileinfo->palette_base = machine->gfx[3]->color_base + ((state->bgdata[tile_index] >> 7) << 3);
} }
static TILE_GET_INFO( get_charinfo ) static TILE_GET_INFO( get_charinfo )
{ {
SET_TILE_INFO(0, videoram[tile_index], 0, 0); bwing_state *state = (bwing_state *)machine->driver_data;
SET_TILE_INFO(0, state->videoram[tile_index], 0, 0);
} }
static TILEMAP_MAPPER( bwing_scan_cols ) static TILEMAP_MAPPER( bwing_scan_cols )
{ {
return((col<<6) + row); return ((col << 6) + row);
} }
VIDEO_START( bwing ) VIDEO_START( bwing )
{ {
bwing_state *state = (bwing_state *)machine->driver_data;
UINT32 *dwptr; UINT32 *dwptr;
int i; int i;
charmap = tilemap_create(machine, get_charinfo,tilemap_scan_cols, 8, 8,32,32); state->charmap = tilemap_create(machine, get_charinfo, tilemap_scan_cols, 8, 8, 32, 32);
fgmap = tilemap_create(machine, get_fgtileinfo,bwing_scan_cols,16,16,64,64); state->fgmap = tilemap_create(machine, get_fgtileinfo, bwing_scan_cols, 16, 16, 64, 64);
bgmap = tilemap_create(machine, get_bgtileinfo,bwing_scan_cols,16,16,64,64); state->bgmap = tilemap_create(machine, get_bgtileinfo, bwing_scan_cols, 16, 16, 64, 64);
srxlat = auto_alloc_array(machine, int, 0x2000);
scrollmap[0] = fgmap; tilemap_set_transparent_pen(state->charmap, 0);
scrollmap[1] = bgmap; tilemap_set_transparent_pen(state->fgmap, 0);
tilemap_set_transparent_pen(charmap, 0);
tilemap_set_transparent_pen(fgmap, 0);
fill_srxlat(srxlat); state->srxlat = auto_alloc_array(machine, int, 0x2000);
state_save_register_global_pointer(machine, state->srxlat, 0x2000);
fgdata = memory_region(machine, "gpu"); fill_srxlat(state->srxlat);
bgdata = fgdata + 0x1000;
for (i=0; i<4; i++) srbase[i] = fgdata + i * 0x2000; state->fgdata = memory_region(machine, "gpu");
for (i=0; i<8; i++) sreg[i] = 0; state->bgdata = state->fgdata + 0x1000;
fgfx = machine->gfx[2]; for (i = 0; i < 4; i++)
gfx_element_set_source(fgfx, srbase[1]); state->srbase[i] = state->fgdata + i * 0x2000;
bgfx = machine->gfx[3];
gfx_element_set_source(bgfx, srbase[1] + 0x1000);
dwptr = fgfx->pen_usage; for (i = 0; i < 8; i++)
state->sreg[i] = 0;
// state->fgfx = machine->gfx[2];
gfx_element_set_source(machine->gfx[2], state->srbase[1]);
// state->bgfx = machine->gfx[3];
gfx_element_set_source(machine->gfx[3], state->srbase[1] + 0x1000);
dwptr = machine->gfx[2]->pen_usage;
if (dwptr) if (dwptr)
{ {
dwptr[0] = 0; dwptr[0] = 0;
for(i=1; i<BW_NTILES; i++) dwptr[i] = -1; for(i = 1; i < BW_NTILES; i++)
dwptr[i] = -1;
} }
} }
//**************************************************************************** //****************************************************************************
// Realtime // Realtime
static void draw_sprites(running_machine *machine, bitmap_t *bmp, const rectangle *clip, UINT8 *ram, int pri) static void draw_sprites( running_machine *machine, bitmap_t *bmp, const rectangle *clip, UINT8 *ram, int pri )
{ {
bwing_state *state = (bwing_state *)machine->driver_data;
int attrib, fx, fy, code, x, y, color, i; int attrib, fx, fy, code, x, y, color, i;
gfx_element *gfx = machine->gfx[1]; gfx_element *gfx = machine->gfx[1];
for (i=0; i<0x200; i+=4) for (i = 0; i < 0x200; i += 4)
{ {
attrib = ram[i]; if (!(attrib & 1) || (color = attrib>>3 & 1) != pri) continue; attrib = ram[i];
code = ram[i+1]; code += attrib<<3 & 0x100; code = ram[i + 1];
y = ram[i+2]; y -= attrib<<1 & 0x100; y = ram[i + 2];
x = ram[i+3]; x -= attrib<<2 & 0x100; x = ram[i + 3];
color = (attrib >> 3) & 1;
if (!(attrib & 1) || color != pri)
continue;
code += (attrib << 3) & 0x100;
y -= (attrib << 1) & 0x100;
x -= (attrib << 2) & 0x100;
fx = attrib & 0x04; fx = attrib & 0x04;
fy = ~attrib & 0x02; fy = ~attrib & 0x02;
// normal/cocktail // normal/cocktail
if (mapmask & 0x20) { fx = !fx; fy = !fy; x = 240 - x; y = 240 - y; } if (state->mapmask & 0x20)
{
fx = !fx;
fy = !fy;
x = 240 - x;
y = 240 - y;
}
// single/double // single/double
if (!(attrib & 0x10)) if (!(attrib & 0x10))
@ -249,22 +288,29 @@ static void draw_sprites(running_machine *machine, bitmap_t *bmp, const rectangl
VIDEO_UPDATE( bwing ) VIDEO_UPDATE( bwing )
{ {
bwing_state *state = (bwing_state *)screen->machine->driver_data;
unsigned x, y, shiftx; unsigned x, y, shiftx;
if (mapmask & 0x20) if (state->mapmask & 0x20)
{ mapflip = TILEMAP_FLIPX; shiftx = -8; } {
state->mapflip = TILEMAP_FLIPX;
shiftx = -8;
}
else else
{ mapflip = TILEMAP_FLIPY; shiftx = 8; } {
state->mapflip = TILEMAP_FLIPY;
shiftx = 8;
}
// draw background // draw background
if (!(mapmask & 1)) if (!(state->mapmask & 1))
{ {
tilemap_set_flip(bgmap, mapflip); tilemap_set_flip(state->bgmap, state->mapflip);
x = ((sreg[1]<<2 & 0x300) + sreg[2] + shiftx) & 0x3ff; x = ((state->sreg[1]<<2 & 0x300) + state->sreg[2] + shiftx) & 0x3ff;
tilemap_set_scrollx(bgmap, 0, x); tilemap_set_scrollx(state->bgmap, 0, x);
y = (sreg[1]<<4 & 0x300) + sreg[3]; y = (state->sreg[1]<<4 & 0x300) + state->sreg[3];
tilemap_set_scrolly(bgmap, 0, y); tilemap_set_scrolly(state->bgmap, 0, y);
tilemap_draw(bitmap, cliprect, bgmap, 0, 0); tilemap_draw(bitmap, cliprect, state->bgmap, 0, 0);
} }
else else
bitmap_fill(bitmap, cliprect, get_black_pen(screen->machine)); bitmap_fill(bitmap, cliprect, get_black_pen(screen->machine));
@ -273,26 +319,25 @@ VIDEO_UPDATE( bwing )
draw_sprites(screen->machine, bitmap, cliprect, buffered_spriteram, 0); draw_sprites(screen->machine, bitmap, cliprect, buffered_spriteram, 0);
// draw foreground // draw foreground
if (!(mapmask & 2)) if (!(state->mapmask & 2))
{ {
tilemap_set_flip(fgmap, mapflip); tilemap_set_flip(state->fgmap, state->mapflip);
x = ((sreg[1]<<6 & 0x300) + sreg[4] + shiftx) & 0x3ff; x = ((state->sreg[1] << 6 & 0x300) + state->sreg[4] + shiftx) & 0x3ff;
tilemap_set_scrollx(fgmap, 0, x); tilemap_set_scrollx(state->fgmap, 0, x);
y = (sreg[1]<<8 & 0x300) + sreg[5]; y = (state->sreg[1] << 8 & 0x300) + state->sreg[5];
tilemap_set_scrolly(fgmap, 0, y); tilemap_set_scrolly(state->fgmap, 0, y);
tilemap_draw(bitmap, cliprect, fgmap, 0, 0); tilemap_draw(bitmap, cliprect, state->fgmap, 0, 0);
} }
// draw high priority sprites // draw high priority sprites
draw_sprites(screen->machine, bitmap, cliprect, buffered_spriteram, 1); draw_sprites(screen->machine, bitmap, cliprect, buffered_spriteram, 1);
// draw text layer // draw text layer
// if (mapmask & 4) // if (state->mapmask & 4)
{ {
tilemap_set_flip(charmap, mapflip); tilemap_set_flip(state->charmap, state->mapflip);
tilemap_draw(bitmap, cliprect, charmap, 0, 0); tilemap_draw(bitmap, cliprect, state->charmap, 0, 0);
} }
return 0; return 0;
} }
//****************************************************************************