snes wip: added another couple of registers to snes_ppu struct and fixed color math to work like docs prescribe

side note: finally video/snes.c do not directly refers to snes_ram anymore (except for debug logging). this will be of use, if I ever get to make a device for the PPU :)
This commit is contained in:
Fabio Priuli 2010-02-10 10:11:22 +00:00
parent f2bb738b9e
commit 493eaf7b78
3 changed files with 201 additions and 211 deletions

View File

@ -450,7 +450,7 @@ struct SNES_PPU_STRUCT /* once all the regs are saved in this structure, it woul
{ {
struct struct
{ {
UINT8 blend; UINT8 color_math;
UINT32 data; UINT32 data;
UINT32 map; UINT32 map;
UINT8 map_size; UINT8 map_size;
@ -477,6 +477,7 @@ struct SNES_PPU_STRUCT /* once all the regs are saved in this structure, it woul
UINT8 window1_enabled, window1_invert; UINT8 window1_enabled, window1_invert;
UINT8 window2_enabled, window2_invert; UINT8 window2_enabled, window2_invert;
UINT8 wlog_mask; UINT8 wlog_mask;
UINT8 color_math;
} colour; // this is for the color (which is 'seen' as a layer by the window masking code) } colour; // this is for the color (which is 'seen' as a layer by the window masking code)
struct struct

View File

@ -1252,14 +1252,13 @@ WRITE8_HANDLER( snes_w_io )
break; break;
case CGADSUB: /* Addition/Subtraction designation for each screen */ case CGADSUB: /* Addition/Subtraction designation for each screen */
snes_ppu.color_modes = data & 0xc0; snes_ppu.color_modes = data & 0xc0;
{ snes_ppu.layer[SNES_BG1].color_math = data & 0x01;
UINT8 sub = (data & 0x80) >> 7; snes_ppu.layer[SNES_BG2].color_math = data & 0x02;
snes_ppu.layer[SNES_BG1].blend = (data & 0x1) << sub; snes_ppu.layer[SNES_BG3].color_math = data & 0x04;
snes_ppu.layer[SNES_BG2].blend = ((data & 0x2) >> 1) << sub; snes_ppu.layer[SNES_BG4].color_math = data & 0x08;
snes_ppu.layer[SNES_BG3].blend = ((data & 0x4) >> 2) << sub; snes_ppu.layer[SNES_OAM].color_math = data & 0x10;
snes_ppu.layer[SNES_BG4].blend = ((data & 0x8) >> 3) << sub; snes_ppu.colour.color_math = data & 0x20;
snes_ppu.layer[SNES_OAM].blend = ((data & 0x10) >> 4) << sub; break;
} break;
case COLDATA: /* Fixed colour data for fixed colour addition/subtraction */ case COLDATA: /* Fixed colour data for fixed colour addition/subtraction */
{ {
/* Store it in the extra space we made in the CGRAM. It doesn't really go there, but it's as good a place as any. */ /* Store it in the extra space we made in the CGRAM. It doesn't really go there, but it's as good a place as any. */

View File

@ -74,11 +74,8 @@
#include "profiler.h" #include "profiler.h"
#include "includes/snes.h" #include "includes/snes.h"
#define MAINSCREEN 0 #define SNES_MAINSCREEN 0
#define SUBSCREEN 1 #define SNES_SUBSCREEN 1
#define SNES_BLEND_NONE 0
#define SNES_BLEND_ADD 1
#define SNES_BLEND_SUB 2
#define SNES_CLIP_ALL 0 #define SNES_CLIP_ALL 0
#define SNES_CLIP_IN 1 #define SNES_CLIP_IN 1
#define SNES_CLIP_OUT 2 #define SNES_CLIP_OUT 2
@ -90,7 +87,7 @@ struct DEBUGOPTS
UINT8 input_count; UINT8 input_count;
UINT8 bg_disabled[6]; UINT8 bg_disabled[6];
UINT8 mode_disabled[8]; UINT8 mode_disabled[8];
UINT8 draw_subscreen; UINT8 draw_SNES_SUBSCREEN;
UINT8 windows_disabled; UINT8 windows_disabled;
UINT8 transparency_disabled; UINT8 transparency_disabled;
}; };
@ -137,7 +134,7 @@ enum
* Routine for additive/subtractive blending * Routine for additive/subtractive blending
* between the main and sub screens. * between the main and sub screens.
*****************************************/ *****************************************/
INLINE void snes_draw_blend(UINT16 offset, UINT16 *colour, UINT8 mode, UINT8 clip, UINT8 black_pen_clip ) INLINE void snes_draw_blend(UINT16 offset, UINT16 *colour, UINT8 clip, UINT8 black_pen_clip )
{ {
if ((black_pen_clip == SNES_CLIP_ALL2) || if ((black_pen_clip == SNES_CLIP_ALL2) ||
(black_pen_clip == SNES_CLIP_IN && snes_ppu.clipmasks[SNES_COLOR][offset]) || (black_pen_clip == SNES_CLIP_IN && snes_ppu.clipmasks[SNES_COLOR][offset]) ||
@ -155,55 +152,29 @@ INLINE void snes_draw_blend(UINT16 offset, UINT16 *colour, UINT8 mode, UINT8 cli
(clip == SNES_CLIP_OUT && snes_ppu.clipmasks[SNES_COLOR][offset])) (clip == SNES_CLIP_OUT && snes_ppu.clipmasks[SNES_COLOR][offset]))
{ {
UINT16 r, g, b; UINT16 r, g, b;
int clip_max = 0; // if add then clip to 0x1f, if sub then clip to 0
if( mode == SNES_BLEND_ADD ) if (snes_ppu.sub_add_mode) /* SNES_SUBSCREEN*/
{ {
if( snes_ppu.sub_add_mode ) /* Subscreen*/ switch (snes_ppu.color_modes & 0x80)
{ {
r = (*colour & 0x1f) + (scanlines[SUBSCREEN].buffer[offset] & 0x1f); case 0x00: /* add */
g = ((*colour & 0x3e0) >> 5) + ((scanlines[SUBSCREEN].buffer[offset] & 0x3e0) >> 5); r = (*colour & 0x1f) + (scanlines[SNES_SUBSCREEN].buffer[offset] & 0x1f);
b = ((*colour & 0x7c00) >> 10) + ((scanlines[SUBSCREEN].buffer[offset] & 0x7c00) >> 10); g = ((*colour & 0x3e0) >> 5) + ((scanlines[SNES_SUBSCREEN].buffer[offset] & 0x3e0) >> 5);
b = ((*colour & 0x7c00) >> 10) + ((scanlines[SNES_SUBSCREEN].buffer[offset] & 0x7c00) >> 10);
/* don't halve for the back colour */ clip_max = 1;
if ((snes_ppu.color_modes & 0x40) && (scanlines[SUBSCREEN].zbuf[offset] || scanlines[SUBSCREEN].buffer[offset] != snes_cgram[FIXED_COLOUR])) break;
{ case 0x80: /* sub */
r >>= 1; r = (*colour & 0x1f) - (scanlines[SNES_SUBSCREEN].buffer[offset] & 0x1f);
g >>= 1; g = ((*colour & 0x3e0) >> 5) - ((scanlines[SNES_SUBSCREEN].buffer[offset] & 0x3e0) >> 5);
b >>= 1; b = ((*colour & 0x7c00) >> 10) - ((scanlines[SNES_SUBSCREEN].buffer[offset] & 0x7c00) >> 10);
}
}
else /* Fixed colour */
{
r = (*colour & 0x1f) + (snes_cgram[FIXED_COLOUR] & 0x1f);
g = ((*colour & 0x3e0) >> 5) + ((snes_cgram[FIXED_COLOUR] & 0x3e0) >> 5);
b = ((*colour & 0x7c00) >> 10) + ((snes_cgram[FIXED_COLOUR] & 0x7c00) >> 10);
/* don't halve for the back colour */
if ((snes_ppu.color_modes & 0x40) && (scanlines[SUBSCREEN].zbuf[offset] || scanlines[SUBSCREEN].buffer[offset] != snes_cgram[FIXED_COLOUR]))
{
r >>= 1;
g >>= 1;
b >>= 1;
}
}
if( r > 0x1f ) r = 0x1f;
if( g > 0x1f ) g = 0x1f;
if( b > 0x1f ) b = 0x1f;
*colour = ((r & 0x1f) | ((g & 0x1f) << 5) | ((b & 0x1f) << 10));
}
else if( mode == SNES_BLEND_SUB )
{
if( snes_ppu.sub_add_mode ) /* Subscreen */
{
r = (*colour & 0x1f) - (scanlines[SUBSCREEN].buffer[offset] & 0x1f);
g = ((*colour & 0x3e0) >> 5) - ((scanlines[SUBSCREEN].buffer[offset] & 0x3e0) >> 5);
b = ((*colour & 0x7c00) >> 10) - ((scanlines[SUBSCREEN].buffer[offset] & 0x7c00) >> 10);
if (r > 0x1f) r = 0; if (r > 0x1f) r = 0;
if (g > 0x1f) g = 0; if (g > 0x1f) g = 0;
if (b > 0x1f) b = 0; if (b > 0x1f) b = 0;
break;
/* don't halve for the back colour */ }
if ((snes_ppu.color_modes & 0x40) && (scanlines[SUBSCREEN].zbuf[offset] || scanlines[SUBSCREEN].buffer[offset] != snes_cgram[FIXED_COLOUR])) /* only halve if the color is not the back colour */
if ((snes_ppu.color_modes & 0x40) && (scanlines[SNES_SUBSCREEN].buffer[offset] != snes_cgram[FIXED_COLOUR]))
{ {
r >>= 1; r >>= 1;
g >>= 1; g >>= 1;
@ -212,23 +183,41 @@ INLINE void snes_draw_blend(UINT16 offset, UINT16 *colour, UINT8 mode, UINT8 cli
} }
else /* Fixed colour */ else /* Fixed colour */
{ {
switch (snes_ppu.color_modes & 0x80)
{
case 0x00: /* add */
r = (*colour & 0x1f) + (snes_cgram[FIXED_COLOUR] & 0x1f);
g = ((*colour & 0x3e0) >> 5) + ((snes_cgram[FIXED_COLOUR] & 0x3e0) >> 5);
b = ((*colour & 0x7c00) >> 10) + ((snes_cgram[FIXED_COLOUR] & 0x7c00) >> 10);
clip_max = 1;
break;
case 0x80: /* sub */
r = (*colour & 0x1f) - (snes_cgram[FIXED_COLOUR] & 0x1f); r = (*colour & 0x1f) - (snes_cgram[FIXED_COLOUR] & 0x1f);
g = ((*colour & 0x3e0) >> 5) - ((snes_cgram[FIXED_COLOUR] & 0x3e0) >> 5); g = ((*colour & 0x3e0) >> 5) - ((snes_cgram[FIXED_COLOUR] & 0x3e0) >> 5);
b = ((*colour & 0x7c00) >> 10) - ((snes_cgram[FIXED_COLOUR] & 0x7c00) >> 10); b = ((*colour & 0x7c00) >> 10) - ((snes_cgram[FIXED_COLOUR] & 0x7c00) >> 10);
if (r > 0x1f) r = 0; if (r > 0x1f) r = 0;
if (g > 0x1f) g = 0; if (g > 0x1f) g = 0;
if (b > 0x1f) b = 0; if (b > 0x1f) b = 0;
break;
/* don't halve for the back colour */ }
if ((snes_ppu.color_modes & 0x40) && (scanlines[SUBSCREEN].zbuf[offset] || scanlines[SUBSCREEN].buffer[offset] != snes_cgram[FIXED_COLOUR])) /* halve if necessary */
if (snes_ppu.color_modes & 0x40)
{ {
r >>= 1; r >>= 1;
g >>= 1; g >>= 1;
b >>= 1; b >>= 1;
} }
} }
*colour = ((r & 0x1f) | ((g & 0x1f) << 5) | ((b & 0x1f) << 10));
/* according to anomie's docs, after addition has been performed, division by 2 happens *before* clipping to max, hence we clip now */
if (clip_max)
{
if (r > 0x1f) r = 0x1f;
if (g > 0x1f) g = 0x1f;
if (b > 0x1f) b = 0x1f;
} }
*colour = ((r & 0x1f) | ((g & 0x1f) << 5) | ((b & 0x1f) << 10));
} }
} }
@ -277,7 +266,7 @@ INLINE void snes_draw_tile(UINT8 screen, UINT8 planes, UINT8 layer, UINT16 tilea
if (!debug_options.windows_disabled) if (!debug_options.windows_disabled)
#endif /* MAME_DEBUG */ #endif /* MAME_DEBUG */
/* Clip to windows */ /* Clip to windows */
window_enabled = (screen == MAINSCREEN) ? snes_ppu.layer[layer].main_window_enabled : snes_ppu.layer[layer].sub_window_enabled; window_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.layer[layer].main_window_enabled : snes_ppu.layer[layer].sub_window_enabled;
if (window_enabled) if (window_enabled)
colour &= snes_ppu.clipmasks[layer][ii]; colour &= snes_ppu.clipmasks[layer][ii];
@ -295,8 +284,9 @@ INLINE void snes_draw_tile(UINT8 screen, UINT8 planes, UINT8 layer, UINT16 tilea
else else
c = snes_cgram[pal + colour]; c = snes_cgram[pal + colour];
if (screen == MAINSCREEN) /* Only blend main screens */ /* Only blend main screens and only if the layer is subject to color_math */
snes_draw_blend(ii/snes_htmult, &c, snes_ppu.layer[layer].blend, snes_ppu.sub_color_mask, snes_ppu.main_color_mask); if (screen == SNES_MAINSCREEN && snes_ppu.layer[layer].color_math)
snes_draw_blend(ii/snes_htmult, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
if (snes_ppu.layer[layer].mosaic_enabled) // handle horizontal mosaic if (snes_ppu.layer[layer].mosaic_enabled) // handle horizontal mosaic
{ {
int x_mos; int x_mos;
@ -385,7 +375,7 @@ INLINE void snes_draw_tile_object(UINT8 screen, UINT16 tileaddr, INT16 x, UINT8
if (!debug_options.windows_disabled) if (!debug_options.windows_disabled)
#endif /* MAME_DEBUG */ #endif /* MAME_DEBUG */
/* Clip to windows */ /* Clip to windows */
window_enabled = (screen == MAINSCREEN) ? snes_ppu.layer[4].main_window_enabled : snes_ppu.layer[SNES_OAM].sub_window_enabled; window_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.layer[4].main_window_enabled : snes_ppu.layer[SNES_OAM].sub_window_enabled;
if (window_enabled) if (window_enabled)
colour &= snes_ppu.clipmasks[SNES_OAM][ii]; colour &= snes_ppu.clipmasks[SNES_OAM][ii];
@ -395,8 +385,8 @@ INLINE void snes_draw_tile_object(UINT8 screen, UINT16 tileaddr, INT16 x, UINT8
if (ii >= 0) if (ii >= 0)
{ {
c = snes_cgram[pal + colour]; c = snes_cgram[pal + colour];
if (blend && screen == MAINSCREEN) /* Only blend main screens */ if (blend && screen == SNES_MAINSCREEN && snes_ppu.layer[SNES_OAM].color_math) /* Only blend main screens */
snes_draw_blend(ii/snes_htmult, &c, snes_ppu.layer[SNES_OAM].blend, snes_ppu.sub_color_mask, snes_ppu.main_color_mask); snes_draw_blend(ii/snes_htmult, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
scanlines[screen].buffer[ii] = c; scanlines[screen].buffer[ii] = c;
scanlines[screen].zbuf[ii] = priority; scanlines[screen].zbuf[ii] = priority;
@ -708,7 +698,7 @@ static void snes_update_line_mode7(UINT8 screen, UINT8 priority_a, UINT8 priorit
colour &= 0x7f; colour &= 0x7f;
} }
window_enabled = (screen == MAINSCREEN) ? snes_ppu.layer[layer].main_window_enabled : snes_ppu.layer[layer].sub_window_enabled; window_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.layer[layer].main_window_enabled : snes_ppu.layer[layer].sub_window_enabled;
if (window_enabled) if (window_enabled)
colour &= snes_ppu.clipmasks[layer][xpos]; colour &= snes_ppu.clipmasks[layer][xpos];
@ -725,8 +715,8 @@ static void snes_update_line_mode7(UINT8 screen, UINT8 priority_a, UINT8 priorit
else else
clr = snes_cgram[colour]; clr = snes_cgram[colour];
/* Only blend main screens */ /* Only blend main screens */
if (screen == MAINSCREEN) if (screen == SNES_MAINSCREEN && snes_ppu.layer[layer].color_math)
snes_draw_blend(xpos, &clr, snes_ppu.layer[layer].blend, snes_ppu.sub_color_mask, snes_ppu.main_color_mask); /* FIXME: Need to support clip mode */ snes_draw_blend(xpos, &clr, snes_ppu.sub_color_mask, snes_ppu.main_color_mask); /* FIXME: Need to support clip mode */
scanlines[screen].buffer[xpos] = clr; scanlines[screen].buffer[xpos] = clr;
scanlines[screen].zbuf[xpos] = priority; scanlines[screen].zbuf[xpos] = priority;
@ -880,7 +870,7 @@ static void snes_update_objects( UINT8 screen, UINT8 priority_tbl, UINT16 curlin
static void snes_update_mode_0( UINT8 screen, UINT16 curline ) static void snes_update_mode_0( UINT8 screen, UINT16 curline )
{ {
UINT8 *bg_enabled; UINT8 *bg_enabled;
bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled; bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
if (bg_enabled[4]) snes_update_objects(screen, 0, curline); if (bg_enabled[4]) snes_update_objects(screen, 0, curline);
if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 7, 10, 0, curline, 0, 0); if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 7, 10, 0, curline, 0, 0);
@ -892,7 +882,7 @@ static void snes_update_mode_0( UINT8 screen, UINT16 curline )
static void snes_update_mode_1( UINT8 screen, UINT16 curline ) static void snes_update_mode_1( UINT8 screen, UINT16 curline )
{ {
UINT8 *bg_enabled; UINT8 *bg_enabled;
bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled; bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
if (!snes_ppu.bg3_priority_bit) if (!snes_ppu.bg3_priority_bit)
{ {
@ -913,7 +903,7 @@ static void snes_update_mode_1( UINT8 screen, UINT16 curline )
static void snes_update_mode_2( UINT8 screen, UINT16 curline ) static void snes_update_mode_2( UINT8 screen, UINT16 curline )
{ {
UINT8 *bg_enabled; UINT8 *bg_enabled;
bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled; bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
if (bg_enabled[4]) snes_update_objects(screen, 2, curline); if (bg_enabled[4]) snes_update_objects(screen, 2, curline);
if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 2, 6, 0, curline, 1, 0); if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 2, 6, 0, curline, 1, 0);
@ -923,7 +913,7 @@ static void snes_update_mode_2( UINT8 screen, UINT16 curline )
static void snes_update_mode_3( UINT8 screen, UINT16 curline ) static void snes_update_mode_3( UINT8 screen, UINT16 curline )
{ {
UINT8 *bg_enabled; UINT8 *bg_enabled;
bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled; bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
if (bg_enabled[4]) snes_update_objects(screen, 3, curline); if (bg_enabled[4]) snes_update_objects(screen, 3, curline);
if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_8BPP, 0, 2, 6, 0, curline, 0, snes_ppu.direct_color); if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_8BPP, 0, 2, 6, 0, curline, 0, snes_ppu.direct_color);
@ -933,7 +923,7 @@ static void snes_update_mode_3( UINT8 screen, UINT16 curline )
static void snes_update_mode_4( UINT8 screen, UINT16 curline ) static void snes_update_mode_4( UINT8 screen, UINT16 curline )
{ {
UINT8 *bg_enabled; UINT8 *bg_enabled;
bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled; bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
if (bg_enabled[4]) snes_update_objects(screen, 4, curline); if (bg_enabled[4]) snes_update_objects(screen, 4, curline);
if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_8BPP, 0, 2, 6, 0, curline, 0, snes_ppu.direct_color); if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_8BPP, 0, 2, 6, 0, curline, 0, snes_ppu.direct_color);
@ -943,7 +933,7 @@ static void snes_update_mode_4( UINT8 screen, UINT16 curline )
static void snes_update_mode_5( UINT8 screen, UINT16 curline ) static void snes_update_mode_5( UINT8 screen, UINT16 curline )
{ {
UINT8 *bg_enabled; UINT8 *bg_enabled;
bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled; bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
if (bg_enabled[4]) snes_update_objects(screen, 5, curline); if (bg_enabled[4]) snes_update_objects(screen, 5, curline);
if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 1, 2, 6, 0, curline, 0, 0); if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 1, 2, 6, 0, curline, 0, 0);
@ -953,7 +943,7 @@ static void snes_update_mode_5( UINT8 screen, UINT16 curline )
static void snes_update_mode_6( UINT8 screen, UINT16 curline ) static void snes_update_mode_6( UINT8 screen, UINT16 curline )
{ {
UINT8 *bg_enabled; UINT8 *bg_enabled;
bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled; bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
if (bg_enabled[4]) snes_update_objects(screen, 6, curline); if (bg_enabled[4]) snes_update_objects(screen, 6, curline);
if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 1, 1, 4, 0, curline, 1, 0); if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 1, 1, 4, 0, curline, 1, 0);
@ -962,7 +952,7 @@ static void snes_update_mode_6( UINT8 screen, UINT16 curline )
static void snes_update_mode_7( UINT8 screen, UINT16 curline ) static void snes_update_mode_7( UINT8 screen, UINT16 curline )
{ {
UINT8 *bg_enabled; UINT8 *bg_enabled;
bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled; bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
if (!snes_ppu.mode7.extbg) if (!snes_ppu.mode7.extbg)
{ {
@ -1171,36 +1161,36 @@ static void snes_refresh_scanline( running_machine *machine, bitmap_t *bitmap, U
snes_update_offsets(); snes_update_offsets();
/* Clear zbuffers */ /* Clear zbuffers */
memset(scanlines[MAINSCREEN].zbuf, 0, SNES_SCR_WIDTH * 2); memset(scanlines[SNES_MAINSCREEN].zbuf, 0, SNES_SCR_WIDTH * 2);
memset(scanlines[SUBSCREEN].zbuf, 0, SNES_SCR_WIDTH * 2); memset(scanlines[SNES_SUBSCREEN].zbuf, 0, SNES_SCR_WIDTH * 2);
/* Clear subscreen and draw back colour */ /* Clear SNES_SUBSCREEN and draw back colour */
for (ii = 0; ii < SNES_SCR_WIDTH * 2; ii++) for (ii = 0; ii < SNES_SCR_WIDTH * 2; ii++)
{ {
/* Not sure if this is correct behaviour, but a few games seem to /* Not sure if this is correct behaviour, but a few games seem to
* require it. (SMW, Zelda etc) */ * require it. (SMW, Zelda etc) */
scanlines[SUBSCREEN].buffer[ii] = snes_cgram[FIXED_COLOUR]; scanlines[SNES_SUBSCREEN].buffer[ii] = snes_cgram[FIXED_COLOUR];
/* Draw back colour */ /* Draw back colour */
scanlines[MAINSCREEN].buffer[ii] = snes_cgram[0]; scanlines[SNES_MAINSCREEN].buffer[ii] = snes_cgram[0];
} }
/* Draw subscreen */ /* Draw SNES_SUBSCREEN */
snes_draw_screen(SUBSCREEN, curline); snes_draw_screen(SNES_SUBSCREEN, curline);
/* Draw the back plane */ /* Draw the back plane */
#ifdef MAME_DEBUG #ifdef MAME_DEBUG
if (!debug_options.bg_disabled[5]) if (!debug_options.bg_disabled[5])
#endif /* MAME_DEBUG */ #endif /* MAME_DEBUG */
if (snes_ram[CGADSUB] & 0x20) if (snes_ppu.colour.color_math)
{ {
for (ii = 0; ii < SNES_SCR_WIDTH * snes_htmult; ii++) for (ii = 0; ii < SNES_SCR_WIDTH * snes_htmult; ii++)
{ {
snes_draw_blend(ii/snes_htmult, &scanlines[MAINSCREEN].buffer[ii], (snes_ppu.color_modes & 0x80) ? SNES_BLEND_SUB : SNES_BLEND_ADD, snes_ppu.sub_color_mask, snes_ppu.main_color_mask); snes_draw_blend(ii/snes_htmult, &scanlines[SNES_MAINSCREEN].buffer[ii], snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
} }
} }
/* Draw mainscreen */ /* Draw SNES_MAINSCREEN */
snes_draw_screen(MAINSCREEN, curline); snes_draw_screen(SNES_MAINSCREEN, curline);
#ifdef MAME_DEBUG #ifdef MAME_DEBUG
if (snes_dbg_video(machine, bitmap, curline)) if (snes_dbg_video(machine, bitmap, curline))
@ -1209,12 +1199,12 @@ static void snes_refresh_scanline( running_machine *machine, bitmap_t *bitmap, U
return; return;
} }
/* Toggle drawing of subscreen or mainscreen */ /* Toggle drawing of SNES_SUBSCREEN or SNES_MAINSCREEN */
if (debug_options.draw_subscreen) if (debug_options.draw_SNES_SUBSCREEN)
scanline = &scanlines[SUBSCREEN]; scanline = &scanlines[SNES_SUBSCREEN];
else else
#endif /* MAME_DEBUG */ #endif /* MAME_DEBUG */
scanline = &scanlines[MAINSCREEN]; scanline = &scanlines[SNES_MAINSCREEN];
/* Phew! Draw the line to screen */ /* Phew! Draw the line to screen */
fade = snes_ppu.screen_brightness; fade = snes_ppu.screen_brightness;
@ -1284,15 +1274,15 @@ static void snes_dbg_draw_maps( bitmap_t *bitmap, UINT32 tmap, UINT8 bpl, UINT16
switch (bpl) switch (bpl)
{ {
case 1: case 1:
snes_draw_tile(MAINSCREEN, 2, layer, snes_ppu.layer[layer].data + (tile << 4) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip, pal, 0); snes_draw_tile(SNES_MAINSCREEN, 2, layer, snes_ppu.layer[layer].data + (tile << 4) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip, pal, 0);
break; break;
case 2: case 2:
pal <<= 2; pal <<= 2;
snes_draw_tile(MAINSCREEN, 4, layer, snes_ppu.layer[layer].data + (tile << 5) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip, pal, 0); snes_draw_tile(SNES_MAINSCREEN, 4, layer, snes_ppu.layer[layer].data + (tile << 5) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip, pal, 0);
break; break;
case 4: case 4:
pal <<= 0; // n/a pal <<= 0; // n/a
snes_draw_tile(MAINSCREEN, 8, layer, snes_ppu.layer[layer].data + (tile << 6) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip, pal, 0); snes_draw_tile(SNES_MAINSCREEN, 8, layer, snes_ppu.layer[layer].data + (tile << 6) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip, pal, 0);
break; break;
} }
} }
@ -1315,27 +1305,27 @@ static void snes_dbg_draw_all_tiles( running_machine *machine, bitmap_t *bitmap,
UINT32 *destline = BITMAP_ADDR32(bitmap, jj * 8 + kk, 0); UINT32 *destline = BITMAP_ADDR32(bitmap, jj * 8 + kk, 0);
/* Clear buffers */ /* Clear buffers */
memset( scanlines[MAINSCREEN].buffer, 0, SNES_SCR_WIDTH * 2 ); memset(scanlines[SNES_MAINSCREEN].buffer, 0, SNES_SCR_WIDTH * 2);
memset( scanlines[MAINSCREEN].zbuf, 0, SNES_SCR_WIDTH * 2 ); memset(scanlines[SNES_MAINSCREEN].zbuf, 0, SNES_SCR_WIDTH * 2);
for (ii = 0; ii < 32; ii++) for (ii = 0; ii < 32; ii++)
{ {
switch (bpl) switch (bpl)
{ {
case 1: case 1:
snes_draw_tile(MAINSCREEN, 2, 0, addr, ii * 8, 255, 0, pal, 0); snes_draw_tile(SNES_MAINSCREEN, 2, 0, addr, ii * 8, 255, 0, pal, 0);
break; break;
case 2: case 2:
snes_draw_tile(MAINSCREEN, 4, 0, addr, ii * 8, 255, 0, pal, 0); snes_draw_tile(SNES_MAINSCREEN, 4, 0, addr, ii * 8, 255, 0, pal, 0);
break; break;
case 4: case 4:
snes_draw_tile(MAINSCREEN, 8, 0, addr, ii * 8, 255, 0, pal, 0); snes_draw_tile(SNES_MAINSCREEN, 8, 0, addr, ii * 8, 255, 0, pal, 0);
break; break;
} }
addr += (bpl * 16); addr += (bpl * 16);
} }
for (ii = 0; ii < SNES_SCR_WIDTH * 2; ii++) for (ii = 0; ii < SNES_SCR_WIDTH * 2; ii++)
{ {
int pixdata = scanlines[MAINSCREEN].buffer[ii]; int pixdata = scanlines[SNES_MAINSCREEN].buffer[ii];
if (pixdata != 200) if (pixdata != 200)
destline[ii] = machine->pens[pixdata]; destline[ii] = machine->pens[pixdata];
} }
@ -1362,18 +1352,18 @@ static UINT8 snes_dbg_video( running_machine *machine, bitmap_t *bitmap, UINT16
if (!debug_options.input_count--) if (!debug_options.input_count--)
{ {
UINT8 toggles = input_port_read_safe(machine, "DEBUG2", 0); UINT8 toggles = input_port_read_safe(machine, "DEBUG2", 0);
if( toggles & 0x1 ) if (toggles & 0x01)
debug_options.bg_disabled[0] = !debug_options.bg_disabled[0]; debug_options.bg_disabled[0] = !debug_options.bg_disabled[0];
if( toggles & 0x2 ) if (toggles & 0x02)
debug_options.bg_disabled[1] = !debug_options.bg_disabled[1]; debug_options.bg_disabled[1] = !debug_options.bg_disabled[1];
if( toggles & 0x4 ) if (toggles & 0x04)
debug_options.bg_disabled[2] = !debug_options.bg_disabled[2]; debug_options.bg_disabled[2] = !debug_options.bg_disabled[2];
if( toggles & 0x8 ) if (toggles & 0x08)
debug_options.bg_disabled[3] = !debug_options.bg_disabled[3]; debug_options.bg_disabled[3] = !debug_options.bg_disabled[3];
if (toggles & 0x10) if (toggles & 0x10)
debug_options.bg_disabled[4] = !debug_options.bg_disabled[4]; debug_options.bg_disabled[4] = !debug_options.bg_disabled[4];
if (toggles & 0x20) if (toggles & 0x20)
debug_options.draw_subscreen = !debug_options.draw_subscreen; debug_options.draw_SNES_SUBSCREEN = !debug_options.draw_SNES_SUBSCREEN;
if (toggles & 0x40) if (toggles & 0x40)
debug_options.bg_disabled[5] = !debug_options.bg_disabled[5]; debug_options.bg_disabled[5] = !debug_options.bg_disabled[5];
if (toggles & 0x80) if (toggles & 0x80)
@ -1526,7 +1516,7 @@ static UINT8 snes_dbg_video( running_machine *machine, bitmap_t *bitmap, UINT16
if (pal > 8) pal = 8; if (pal > 8) pal = 8;
for (ii = 0; ii < SNES_SCR_WIDTH; ii++) for (ii = 0; ii < SNES_SCR_WIDTH; ii++)
{ {
scanlines[MAINSCREEN].buffer[ii] = 0; scanlines[SNES_MAINSCREEN].buffer[ii] = 0;
} }
snes_dbg_draw_all_tiles(machine, bitmap, addr, dt, pal * 16 ); snes_dbg_draw_all_tiles(machine, bitmap, addr, dt, pal * 16 );
} }
@ -1549,14 +1539,14 @@ static UINT8 snes_dbg_video( running_machine *machine, bitmap_t *bitmap, UINT16
if (tmbg > 3) tmbg = 3; if (tmbg > 3) tmbg = 3;
} }
/* Clear zbuffer */ /* Clear zbuffer */
memset( scanlines[MAINSCREEN].zbuf, 0, SNES_SCR_WIDTH ); memset( scanlines[SNES_MAINSCREEN].zbuf, 0, SNES_SCR_WIDTH );
/* Draw back colour */ /* Draw back colour */
for (ii = 0; ii < SNES_SCR_WIDTH; ii++) for (ii = 0; ii < SNES_SCR_WIDTH; ii++)
scanlines[MAINSCREEN].buffer[ii] = machine->pens[0]; scanlines[SNES_MAINSCREEN].buffer[ii] = machine->pens[0];
snes_dbg_draw_maps(bitmap, tmaddr, dm, curline, tmbg ); snes_dbg_draw_maps(bitmap, tmaddr, dm, curline, tmbg );
for (ii = 0; ii < SNES_SCR_WIDTH; ii++) for (ii = 0; ii < SNES_SCR_WIDTH; ii++)
{ {
int pixdata = scanlines[MAINSCREEN].buffer[ii]; int pixdata = scanlines[SNES_MAINSCREEN].buffer[ii];
if (pixdata != 200) if (pixdata != 200)
destline[ii] = machine->pens[pixdata]; destline[ii] = machine->pens[pixdata];
} }
@ -1576,10 +1566,10 @@ static UINT8 snes_dbg_video( running_machine *machine, bitmap_t *bitmap, UINT16
*BITMAP_ADDR32(bitmap, curline, SNES_DBG_HORZ_POS - 9 + ii) = snes_cgram[FIXED_COLOUR]; *BITMAP_ADDR32(bitmap, curline, SNES_DBG_HORZ_POS - 9 + ii) = snes_cgram[FIXED_COLOUR];
} }
/* Draw window positions */ /* Draw window positions */
scanlines[MAINSCREEN].buffer[snes_ram[WH0]] = machine->pens[dbg_mode_colours[0]]; scanlines[SNES_MAINSCREEN].buffer[snes_ram[WH0]] = machine->pens[dbg_mode_colours[0]];
scanlines[MAINSCREEN].buffer[snes_ram[WH1]] = machine->pens[dbg_mode_colours[0]]; scanlines[SNES_MAINSCREEN].buffer[snes_ram[WH1]] = machine->pens[dbg_mode_colours[0]];
scanlines[MAINSCREEN].buffer[snes_ram[WH2]] = machine->pens[dbg_mode_colours[2]]; scanlines[SNES_MAINSCREEN].buffer[snes_ram[WH2]] = machine->pens[dbg_mode_colours[2]];
scanlines[MAINSCREEN].buffer[snes_ram[WH3]] = machine->pens[dbg_mode_colours[2]]; scanlines[SNES_MAINSCREEN].buffer[snes_ram[WH3]] = machine->pens[dbg_mode_colours[2]];
#endif #endif
return 0; return 0;
} }