From a1e1f436b48756e351d1bd212c09b6ca3b8ed31f Mon Sep 17 00:00:00 2001 From: Aaron Giles Date: Fri, 1 Feb 2008 06:30:30 +0000 Subject: [PATCH] Updated mpatrol to use resnet for colors. --- src/mame/video/m52.c | 183 +++++++++++++++++++++---------------------- 1 file changed, 91 insertions(+), 92 deletions(-) diff --git a/src/mame/video/m52.c b/src/mame/video/m52.c index 90745327ac7..d7b4de8e386 100644 --- a/src/mame/video/m52.c +++ b/src/mame/video/m52.c @@ -6,6 +6,7 @@ #include "driver.h" #include "m52.h" +#include "video/resnet.h" #define BGHEIGHT 64 @@ -18,130 +19,75 @@ static UINT8 bgcontrol; static tilemap* bg_tilemap; -/*************************************************************************** +/************************************* + * + * Palette configuration + * + *************************************/ - Convert the color PROMs into a more useable format. - - Moon Patrol has one 256x8 character palette PROM, one 32x8 background - palette PROM, one 32x8 sprite palette PROM and one 256x4 sprite lookup - table PROM. - - The character and background palette PROMs are connected to the RGB output - this way: - - bit 7 -- 220 ohm resistor -- BLUE - -- 470 ohm resistor -- BLUE - -- 220 ohm resistor -- GREEN - -- 470 ohm resistor -- GREEN - -- 1 kohm resistor -- GREEN - -- 220 ohm resistor -- RED - -- 470 ohm resistor -- RED - bit 0 -- 1 kohm resistor -- RED - - The sprite palette PROM is connected to the RGB output this way. Note that - RED and BLUE are swapped wrt the usual configuration. - - bit 7 -- 220 ohm resistor -- RED - -- 470 ohm resistor -- RED - -- 220 ohm resistor -- GREEN - -- 470 ohm resistor -- GREEN - -- 1 kohm resistor -- GREEN - -- 220 ohm resistor -- BLUE - -- 470 ohm resistor -- BLUE - bit 0 -- 1 kohm resistor -- BLUE - -***************************************************************************/ PALETTE_INIT( m52 ) { + static const int resistances_3[3] = { 1000, 470, 220 }; + static const int resistances_2[2] = { 470, 220 }; + double weights_r[3], weights_g[3], weights_b[3]; int i; machine->colortable = colortable_alloc(machine, 512+32+32); + /* compute palette information for characters/backgrounds */ + compute_resistor_weights(0, 255, -1.0, + 3, resistances_3, weights_r, 0, 0, + 3, resistances_3, weights_g, 0, 0, + 2, resistances_2, weights_b, 0, 0); + /* character palette */ for (i = 0;i < 512;i++) { - int bit0,bit1,bit2,r,g,b; - - /* red component */ - bit0 = (*color_prom >> 0) & 0x01; - bit1 = (*color_prom >> 1) & 0x01; - bit2 = (*color_prom >> 2) & 0x01; - r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; - /* green component */ - bit0 = (*color_prom >> 3) & 0x01; - bit1 = (*color_prom >> 4) & 0x01; - bit2 = (*color_prom >> 5) & 0x01; - g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; - /* blue component */ - bit0 = 0; - bit1 = (*color_prom >> 6) & 0x01; - bit2 = (*color_prom >> 7) & 0x01; - b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; + UINT8 promval = color_prom[i]; + int r = combine_3_weights(weights_r, BIT(promval,0), BIT(promval,1), BIT(promval,2)); + int g = combine_3_weights(weights_g, BIT(promval,3), BIT(promval,4), BIT(promval,5)); + int b = combine_2_weights(weights_b, BIT(promval,6), BIT(promval,7)); colortable_palette_set_color(machine->colortable,i,MAKE_RGB(r,g,b)); - colortable_entry_set_value(machine->colortable,i,i); - color_prom++; } /* background palette */ for (i = 0;i < 32;i++) { - int bit0,bit1,bit2,r,g,b; - - /* red component */ - bit0 = (*color_prom >> 0) & 0x01; - bit1 = (*color_prom >> 1) & 0x01; - bit2 = (*color_prom >> 2) & 0x01; - r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; - /* green component */ - bit0 = (*color_prom >> 3) & 0x01; - bit1 = (*color_prom >> 4) & 0x01; - bit2 = (*color_prom >> 5) & 0x01; - g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; - /* blue component */ - bit0 = 0; - bit1 = (*color_prom >> 6) & 0x01; - bit2 = (*color_prom >> 7) & 0x01; - b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; + UINT8 promval = color_prom[512+i]; + int r = combine_3_weights(weights_r, BIT(promval,0), BIT(promval,1), BIT(promval,2)); + int g = combine_3_weights(weights_g, BIT(promval,3), BIT(promval,4), BIT(promval,5)); + int b = combine_2_weights(weights_b, BIT(promval,6), BIT(promval,7)); colortable_palette_set_color(machine->colortable,i+512,MAKE_RGB(r,g,b)); - color_prom++; } - /* color_prom now points to the beginning of the sprite palette */ + /* compute palette information for sprites */ + compute_resistor_weights(0, 255, -1.0, + 2, resistances_2, weights_r, 470, 0, + 3, resistances_3, weights_g, 470, 0, + 3, resistances_3, weights_b, 470, 0); /* sprite palette */ for (i = 0;i < 32;i++) { - int bit0,bit1,bit2,r,g,b; - - /* red component */ - bit0 = 0; - bit1 = (*color_prom >> 6) & 0x01; - bit2 = (*color_prom >> 7) & 0x01; - r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; - /* green component */ - bit0 = (*color_prom >> 3) & 0x01; - bit1 = (*color_prom >> 4) & 0x01; - bit2 = (*color_prom >> 5) & 0x01; - g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; - /* blue component */ - bit0 = (*color_prom >> 0) & 0x01; - bit1 = (*color_prom >> 1) & 0x01; - bit2 = (*color_prom >> 2) & 0x01; - b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; + UINT8 promval = color_prom[512+32+i]; + int r = combine_2_weights(weights_r, BIT(promval,6), BIT(promval,7)); + int g = combine_3_weights(weights_g, BIT(promval,3), BIT(promval,4), BIT(promval,5)); + int b = combine_3_weights(weights_b, BIT(promval,0), BIT(promval,1), BIT(promval,2)); colortable_palette_set_color(machine->colortable,i+512+32,MAKE_RGB(r,g,b)); - color_prom++; } - /* color_prom now points to the beginning of the sprite lookup table */ + /* character lookup table */ + for (i = 0;i < 512;i++) + colortable_entry_set_value(machine->colortable,i,i); /* sprite lookup table */ for (i = 0;i < 16*4;i++) { - colortable_entry_set_value(machine->colortable, 512+i, 512+32+(*color_prom++)); - if (i % 4 == 3) color_prom += 4; /* half of the PROM is unused */ + UINT8 promval = color_prom[512+32+32+((i & 3) | ((i & ~3) << 1))]; + colortable_entry_set_value(machine->colortable, 512+i, 512+32+promval); } /* background */ @@ -166,6 +112,12 @@ PALETTE_INIT( m52 ) +/************************************* + * + * Tilemap info callback + * + *************************************/ + static TILE_GET_INFO( get_tile_info ) { UINT8 video = videoram[tile_index]; @@ -191,6 +143,12 @@ static TILE_GET_INFO( get_tile_info ) +/************************************* + * + * Video startup + * + *************************************/ + VIDEO_START( m52 ) { bg_tilemap = tilemap_create(get_tile_info, tilemap_scan_rows, TILEMAP_TYPE_PEN, 8, 8, 32, 32); @@ -209,6 +167,12 @@ VIDEO_START( m52 ) +/************************************* + * + * Scroll registers + * + *************************************/ + WRITE8_HANDLER( m52_scroll_w ) { @@ -227,6 +191,12 @@ WRITE8_HANDLER( m52_scroll_w ) +/************************************* + * + * Video RAM write handlers + * + *************************************/ + WRITE8_HANDLER( m52_videoram_w ) { videoram[offset] = data; @@ -234,7 +204,6 @@ WRITE8_HANDLER( m52_videoram_w ) } - WRITE8_HANDLER( m52_colorram_w ) { colorram[offset] = data; @@ -242,6 +211,13 @@ WRITE8_HANDLER( m52_colorram_w ) } + +/************************************* + * + * Custom protection + * + *************************************/ + /* This looks like some kind of protection implemented by a custom chip on the scroll board. It mangles the value written to the port m52_bg1xpos_w, as follows: result = popcount(value & 0x7f) ^ (value >> 7) */ @@ -256,22 +232,33 @@ READ8_HANDLER( m52_protection_r ) } + +/************************************* + * + * Background control write handlers + * + *************************************/ + WRITE8_HANDLER( m52_bg1ypos_w ) { bg1ypos = data; } + WRITE8_HANDLER( m52_bg1xpos_w ) { bg1xpos = data; } + WRITE8_HANDLER( m52_bg2xpos_w ) { bg2xpos = data; } + WRITE8_HANDLER( m52_bg2ypos_w ) { bg2ypos = data; } + WRITE8_HANDLER( m52_bgcontrol_w ) { bgcontrol = data; @@ -291,6 +278,12 @@ WRITE8_HANDLER( m52_flipscreen_w ) +/************************************* + * + * Background rendering + * + *************************************/ + static void draw_background(running_machine *machine, mame_bitmap *bitmap, const rectangle *cliprect, int xpos, int ypos, int image) { rectangle rect; @@ -340,6 +333,12 @@ static void draw_background(running_machine *machine, mame_bitmap *bitmap, const +/************************************* + * + * Video render + * + *************************************/ + VIDEO_UPDATE( m52 ) { int offs;