summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/ppu2c0x.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mame/video/ppu2c0x.c')
-rw-r--r--src/mame/video/ppu2c0x.c78
1 files changed, 35 insertions, 43 deletions
diff --git a/src/mame/video/ppu2c0x.c b/src/mame/video/ppu2c0x.c
index d44e0752cf8..9f5d3c8e06f 100644
--- a/src/mame/video/ppu2c0x.c
+++ b/src/mame/video/ppu2c0x.c
@@ -41,11 +41,6 @@
#define SPRITERAM_MASK (0x100-1) /* spriteram size */
#define CHARGEN_NUM_CHARS 512 /* max number of characters handled by the chargen */
-enum
-{
- PPU2C0XINFO_INT_SCANLINES_PER_FRAME = DEVINFO_INT_DEVICE_SPECIFIC
-};
-
/* default monochromatic colortable */
static const pen_t default_colortable_mono[] =
{
@@ -81,6 +76,7 @@ static const pen_t default_colortable[] =
typedef struct _ppu2c0x_state ppu2c0x_state;
struct _ppu2c0x_state
{
+ const address_space *space; /* memory space */
bitmap_t *bitmap; /* target bitmap */
UINT8 *spriteram; /* sprite ram */
pen_t *colortable; /* color table modified at run time */
@@ -114,6 +110,7 @@ struct _ppu2c0x_state
int security_value; /* 2C05 protection */
};
+
/***************************************************************************
PROTOTYPES
***************************************************************************/
@@ -138,22 +135,22 @@ static READ8_HANDLER( ppu2c0x_palette_read );
INLINE ppu2c0x_state *get_token( running_device *device )
{
assert(device != NULL);
- assert((device->type == PPU_2C02) || (device->type == PPU_2C03B)
- || (device->type == PPU_2C04) || (device->type == PPU_2C05_01)
- || (device->type == PPU_2C05_02) || (device->type == PPU_2C05_03)
- || (device->type == PPU_2C05_04) || (device->type == PPU_2C07));
- return (ppu2c0x_state *) device->token;
+ assert((device->type() == PPU_2C02) || (device->type() == PPU_2C03B)
+ || (device->type() == PPU_2C04) || (device->type() == PPU_2C05_01)
+ || (device->type() == PPU_2C05_02) || (device->type() == PPU_2C05_03)
+ || (device->type() == PPU_2C05_04) || (device->type() == PPU_2C07));
+ return (ppu2c0x_state *) downcast<legacy_device_base *>(device)->token();
}
INLINE const ppu2c0x_interface *get_interface( running_device *device )
{
assert(device != NULL);
- assert((device->type == PPU_2C02) || (device->type == PPU_2C03B)
- || (device->type == PPU_2C04) || (device->type == PPU_2C05_01)
- || (device->type == PPU_2C05_02) || (device->type == PPU_2C05_03)
- || (device->type == PPU_2C05_04) || (device->type == PPU_2C07));
- return (const ppu2c0x_interface *) device->baseconfig().static_config;
+ assert((device->type() == PPU_2C02) || (device->type() == PPU_2C03B)
+ || (device->type() == PPU_2C04) || (device->type() == PPU_2C05_01)
+ || (device->type() == PPU_2C05_02) || (device->type() == PPU_2C05_03)
+ || (device->type() == PPU_2C05_04) || (device->type() == PPU_2C07));
+ return (const ppu2c0x_interface *) device->baseconfig().static_config();
}
@@ -429,14 +426,14 @@ static void draw_background( running_device *device, UINT8 *line_priority )
pos = ((index1 & 0x380) >> 4) | ((index1 & 0x1f) >> 2);
page = (index1 & 0x0c00) >> 10;
address = 0x3c0 + pos;
- color_byte = memory_read_byte(device->space(), (((page * 0x400) + address) & 0xfff) + 0x2000);
+ color_byte = memory_read_byte(ppu2c0x->space, (((page * 0x400) + address) & 0xfff) + 0x2000);
/* figure out which bits in the color table to use */
color_bits = ((index1 & 0x40) >> 4) + (index1 & 0x02);
// page2 is the output of the nametable read (this section is the FIRST read per tile!)
address = index1 & 0x3ff;
- page2 = memory_read_byte(device->space(), index1);
+ page2 = memory_read_byte(ppu2c0x->space, index1);
// 27/12/2002
if (ppu_latch)
@@ -454,8 +451,8 @@ static void draw_background( running_device *device, UINT8 *line_priority )
// plus something that accounts for y
address += scroll_y_fine;
- plane1 = memory_read_byte(device->space(), (address & 0x1fff));
- plane2 = memory_read_byte(device->space(), (address + 8) & 0x1fff);
+ plane1 = memory_read_byte(ppu2c0x->space, (address & 0x1fff));
+ plane2 = memory_read_byte(ppu2c0x->space, (address + 8) & 0x1fff);
/* render the pixel */
for (i = 0; i < 8; i++)
@@ -601,8 +598,8 @@ static void draw_sprites( running_device *device, UINT8 *line_priority )
if (size == 8)
index1 += ((sprite_page == 0) ? 0 : 0x1000);
- plane1 = memory_read_byte(device->space(), (index1 + sprite_line + 0) & 0x1fff);
- plane2 = memory_read_byte(device->space(), (index1 + sprite_line + 8) & 0x1fff);
+ plane1 = memory_read_byte(ppu2c0x->space, (index1 + sprite_line + 0) & 0x1fff);
+ plane2 = memory_read_byte(ppu2c0x->space, (index1 + sprite_line + 8) & 0x1fff);
/* if there are more than 8 sprites on this line, set the flag */
if (sprite_count == 8)
@@ -854,7 +851,7 @@ static TIMER_CALLBACK( scanline_callback )
/* increment our scanline count */
ppu2c0x->scanline++;
-// logerror("starting scanline %d (MAME %d, beam %d)\n", ppu2c0x->scanline, video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen));
+// logerror("starting scanline %d (MAME %d, beam %d)\n", ppu2c0x->scanline, device->machine->primary_screen->vpos(), device->machine->primary_screen->hpos());
/* Note: this is called at the _end_ of each scanline */
if (ppu2c0x->scanline == PPU_VBLANK_FIRST_SCANLINE)
@@ -901,7 +898,7 @@ static TIMER_CALLBACK( scanline_callback )
timer_adjust_oneshot(ppu2c0x->hblank_timer, cputag_clocks_to_attotime(device->machine, "maincpu", 86.67), 0); // ??? FIXME - hardcoding NTSC, need better calculation
// trigger again at the start of the next scanline
- timer_adjust_oneshot(ppu2c0x->scanline_timer, video_screen_get_time_until_pos(device->machine->primary_screen, next_scanline * ppu2c0x->scan_scale, 0), 0);
+ timer_adjust_oneshot(ppu2c0x->scanline_timer, device->machine->primary_screen->time_until_pos(next_scanline * ppu2c0x->scan_scale), 0);
}
/*************************************
@@ -999,14 +996,14 @@ READ8_DEVICE_HANDLER( ppu2c0x_r )
if (ppu2c0x->videomem_addr >= 0x3f00)
{
- ppu2c0x->data_latch = memory_read_byte(device->space(), ppu2c0x->videomem_addr);
+ ppu2c0x->data_latch = memory_read_byte(ppu2c0x->space, ppu2c0x->videomem_addr);
// buffer the mirrored NT data
- ppu2c0x->buffered_data = memory_read_byte(device->space(), ppu2c0x->videomem_addr & 0x2fff);
+ ppu2c0x->buffered_data = memory_read_byte(ppu2c0x->space, ppu2c0x->videomem_addr & 0x2fff);
}
else
{
ppu2c0x->data_latch = ppu2c0x->buffered_data;
- ppu2c0x->buffered_data = memory_read_byte(device->space(), ppu2c0x->videomem_addr);
+ ppu2c0x->buffered_data = memory_read_byte(ppu2c0x->space, ppu2c0x->videomem_addr);
}
ppu2c0x->videomem_addr += ppu2c0x->add;
@@ -1042,8 +1039,8 @@ WRITE8_DEVICE_HANDLER( ppu2c0x_w )
#ifdef MAME_DEBUG
if (ppu2c0x->scanline <= PPU_BOTTOM_VISIBLE_SCANLINE)
{
- running_device *screen = device->machine->primary_screen;
- logerror("PPU register %d write %02x during non-vblank scanline %d (MAME %d, beam pos: %d)\n", offset, data, ppu2c0x->scanline, video_screen_get_vpos(screen), video_screen_get_hpos(screen));
+ screen_device *screen = device->machine->primary_screen;
+ logerror("PPU register %d write %02x during non-vblank scanline %d (MAME %d, beam pos: %d)\n", offset, data, ppu2c0x->scanline, screen->vpos(), screen->hpos());
}
#endif
@@ -1156,12 +1153,12 @@ WRITE8_DEVICE_HANDLER( ppu2c0x_w )
if (tempAddr < 0x2000)
{
/* store the data */
- memory_write_byte(device->space(), tempAddr, data);
+ memory_write_byte(ppu2c0x->space, tempAddr, data);
}
else
{
- memory_write_byte(device->space(), tempAddr, data);
+ memory_write_byte(ppu2c0x->space, tempAddr, data);
}
/* increment the address */
ppu2c0x->videomem_addr += ppu2c0x->add;
@@ -1277,27 +1274,28 @@ static DEVICE_START( ppu2c0x )
const ppu2c0x_interface *intf = get_interface(device);
memset(ppu2c0x, 0, sizeof(*ppu2c0x));
- ppu2c0x->scanlines_per_frame = (int) device->get_config_int(PPU2C0XINFO_INT_SCANLINES_PER_FRAME);
+ ppu2c0x->space = device_get_space(device, 0);
+ ppu2c0x->scanlines_per_frame = (device->type() != PPU_2C07) ? PPU_NTSC_SCANLINES_PER_FRAME : PPU_PAL_SCANLINES_PER_FRAME;
/* usually, no security value... */
ppu2c0x->security_value = 0;
/* ...except for VS. games which specific PPU types */
- if (device->type == PPU_2C05_01)
+ if (device->type() == PPU_2C05_01)
ppu2c0x->security_value = 0x1b; // game (jajamaru) doesn't seem to ever actually check it
- if (device->type == PPU_2C05_02)
+ if (device->type() == PPU_2C05_02)
ppu2c0x->security_value = 0x3d;
- if (device->type == PPU_2C05_03)
+ if (device->type() == PPU_2C05_03)
ppu2c0x->security_value = 0x1c;
- if (device->type == PPU_2C05_04)
+ if (device->type() == PPU_2C05_04)
ppu2c0x->security_value = 0x1b;
/* initialize the scanline handling portion */
ppu2c0x->scanline_timer = timer_alloc(device->machine, scanline_callback, (void *) device);
- timer_adjust_oneshot(ppu2c0x->scanline_timer, video_screen_get_time_until_pos(device->machine->primary_screen, 1, 0), 0);
+ timer_adjust_oneshot(ppu2c0x->scanline_timer, device->machine->primary_screen->time_until_pos(1), 0);
ppu2c0x->hblank_timer = timer_alloc(device->machine, hblank_callback, (void *) device);
timer_adjust_oneshot(ppu2c0x->hblank_timer, cputag_clocks_to_attotime(device->machine, "maincpu", 86.67), 0); // ??? FIXME - hardcoding NTSC, need better calculation
@@ -1309,7 +1307,7 @@ static DEVICE_START( ppu2c0x )
ppu2c0x->color_base = intf->color_base;
/* allocate a screen bitmap, videomem and spriteram, a dirtychar array and the monochromatic colortable */
- ppu2c0x->bitmap = auto_bitmap_alloc(device->machine, VISIBLE_SCREEN_WIDTH, VISIBLE_SCREEN_HEIGHT, video_screen_get_format(device->machine->primary_screen));
+ ppu2c0x->bitmap = auto_bitmap_alloc(device->machine, VISIBLE_SCREEN_WIDTH, VISIBLE_SCREEN_HEIGHT, device->machine->primary_screen->format());
ppu2c0x->spriteram = auto_alloc_array_clear(device->machine, UINT8, SPRITERAM_SIZE);
ppu2c0x->colortable = auto_alloc_array(device->machine, pen_t, ARRAY_LENGTH(default_colortable));
ppu2c0x->colortable_mono = auto_alloc_array(device->machine, pen_t, ARRAY_LENGTH(default_colortable_mono));
@@ -1404,8 +1402,6 @@ DEVICE_GET_INFO(ppu2c02)
/* --- the following bits of info are returned as 64-bit signed integers --- */
case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(ppu2c0x_state); break;
case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break;
- case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break;
- case PPU2C0XINFO_INT_SCANLINES_PER_FRAME: info->i = PPU_NTSC_SCANLINES_PER_FRAME; break;
case DEVINFO_INT_DATABUS_WIDTH_0: info->i = 8; break;
case DEVINFO_INT_ADDRBUS_WIDTH_0: info->i = 14; break;
case DEVINFO_INT_ADDRBUS_SHIFT_0: info->i = 0; break;
@@ -1434,7 +1430,6 @@ DEVICE_GET_INFO(ppu2c03b)
switch (state)
{
case DEVINFO_STR_NAME: strcpy(info->s, "2C02B PPU"); break;
- case PPU2C0XINFO_INT_SCANLINES_PER_FRAME: info->i = PPU_NTSC_SCANLINES_PER_FRAME; break;
default: DEVICE_GET_INFO_CALL(ppu2c02); break;
}
}
@@ -1444,7 +1439,6 @@ DEVICE_GET_INFO(ppu2c04)
switch (state)
{
case DEVINFO_STR_NAME: strcpy(info->s, "2C04 PPU"); break;
- case PPU2C0XINFO_INT_SCANLINES_PER_FRAME: info->i = PPU_NTSC_SCANLINES_PER_FRAME; break;
default: DEVICE_GET_INFO_CALL(ppu2c02); break;
}
}
@@ -1454,7 +1448,6 @@ DEVICE_GET_INFO(ppu2c05_01)
switch (state)
{
case DEVINFO_STR_NAME: strcpy(info->s, "2C05 PPU"); break;
- case PPU2C0XINFO_INT_SCANLINES_PER_FRAME: info->i = PPU_NTSC_SCANLINES_PER_FRAME; break;
default: DEVICE_GET_INFO_CALL(ppu2c02); break;
}
}
@@ -1479,7 +1472,6 @@ DEVICE_GET_INFO(ppu2c07)
switch (state)
{
case DEVINFO_STR_NAME: strcpy(info->s, "2C07 PPU"); break;
- case PPU2C0XINFO_INT_SCANLINES_PER_FRAME: info->i = PPU_PAL_SCANLINES_PER_FRAME; break;
default: DEVICE_GET_INFO_CALL(ppu2c02); break;
}
}