diff --git a/src/mame/video/cloak.c b/src/mame/video/cloak.c index 39979855ed4..445ffede982 100644 --- a/src/mame/video/cloak.c +++ b/src/mame/video/cloak.c @@ -5,12 +5,20 @@ ***************************************************************************/ #include "driver.h" -#include "deprecat.h" +#include "video/resnet.h" #include "cloak.h" -static mame_bitmap *tmpbitmap2; -static UINT8 x,y,bmap; -static UINT8 *tmpvideoram,*tmpvideoram2; + +#define NUM_PENS (0x40) + +static UINT8 bitmap_videoram_selected; +static UINT8 bitmap_videoram_address_x; +static UINT8 bitmap_videoram_address_y; +static UINT8 *bitmap_videoram1; +static UINT8 *bitmap_videoram2; +static UINT8 *current_bitmap_videoram_accessed; +static UINT8 *current_bitmap_videoram_displayed; +static UINT16 *palette_ram; static tilemap *bg_tilemap; @@ -19,11 +27,11 @@ static tilemap *bg_tilemap; CLOAK & DAGGER uses RAM to dynamically create the palette. The resolution is 9 bit (3 bits per gun). The palette contains 64 entries, but it is accessed through a memory windows 128 bytes - long: writing to the first 64 bytes sets the msb of the red component to 0, + long: writing to the first 64 bytes sets the MSB of the red component to 0, while writing to the last 64 bytes sets it to 1. Colors 0-15 Character mapped graphics - Colors 16-31 Bitmapped graphics (maybe 8 colors per bitmap?) + Colors 16-31 Bitmapped graphics (2 palettes selected by 128H) Colors 32-47 Sprites Colors 48-63 not used @@ -40,80 +48,85 @@ static tilemap *bg_tilemap; bit 0 -- diode |< -- pullup 1 kohm -- 10 kohm resistor -- pulldown 100 pf -- BLUE ***************************************************************************/ + WRITE8_HANDLER( cloak_paletteram_w ) { - int r,g,b; - int bit0,bit1,bit2; + palette_ram[offset & 0x3f] = ((offset & 0x40) << 2) | data; +} - /* a write to offset 64-127 means to set the msb of the red component */ - int color = data | ((offset & 0x40) << 2); - r = (~color & 0x1c0) >> 6; - g = (~color & 0x038) >> 3; - b = (~color & 0x007); +static void set_pens(running_machine *machine) +{ + static const int resistances[3] = { 10000, 4700, 2200 }; + double weights[3]; + int i; - // the following is WRONG! fix it + /* compute the color output resistor weights */ + compute_resistor_weights(0, 255, -1.0, + 3, resistances, weights, 0, 1000, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0); - bit0 = (r >> 0) & 0x01; - bit1 = (r >> 1) & 0x01; - bit2 = (r >> 2) & 0x01; - r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; - bit0 = (g >> 0) & 0x01; - bit1 = (g >> 1) & 0x01; - bit2 = (g >> 2) & 0x01; - g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; - bit0 = (b >> 0) & 0x01; - bit1 = (b >> 1) & 0x01; - bit2 = (b >> 2) & 0x01; - b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; + for (i = 0; i < NUM_PENS; i++) + { + int r, g, b; + int bit0, bit1, bit2; - palette_set_color(Machine,offset & 0x3f,MAKE_RGB(r,g,b)); + /* red component */ + bit0 = (~palette_ram[i] >> 6) & 0x01; + bit1 = (~palette_ram[i] >> 7) & 0x01; + bit2 = (~palette_ram[i] >> 8) & 0x01; + r = combine_3_weights(weights, bit0, bit1, bit2); + + /* green component */ + bit0 = (~palette_ram[i] >> 3) & 0x01; + bit1 = (~palette_ram[i] >> 4) & 0x01; + bit2 = (~palette_ram[i] >> 5) & 0x01; + g = combine_3_weights(weights, bit0, bit1, bit2); + + /* blue component */ + bit0 = (~palette_ram[i] >> 0) & 0x01; + bit1 = (~palette_ram[i] >> 1) & 0x01; + bit2 = (~palette_ram[i] >> 2) & 0x01; + b = combine_3_weights(weights, bit0, bit1, bit2); + + palette_set_color(machine, i, MAKE_RGB(r, g, b)); + } +} + + +static void set_current_bitmap_videoram_pointer(void) +{ + current_bitmap_videoram_accessed = bitmap_videoram_selected ? bitmap_videoram1 : bitmap_videoram2; + current_bitmap_videoram_displayed = bitmap_videoram_selected ? bitmap_videoram2 : bitmap_videoram1; } WRITE8_HANDLER( cloak_clearbmp_w ) { - bmap = data & 0x01; + video_screen_update_now(0); + bitmap_videoram_selected = data & 0x01; + set_current_bitmap_videoram_pointer(); if (data & 0x02) /* clear */ - { - if (bmap) - { - fillbitmap(tmpbitmap, 16, &Machine->screen[0].visarea); - memset(tmpvideoram, 0, 256*256); - } - else - { - fillbitmap(tmpbitmap2, 16, &Machine->screen[0].visarea); - memset(tmpvideoram2, 0, 256*256); - } - } + memset(current_bitmap_videoram_accessed, 0, 256*256); } static void adjust_xy(int offset) { - switch(offset) + switch (offset) { - case 0x00: x--; y++; break; - case 0x01: y--; break; - case 0x02: x--; break; - case 0x04: x++; y++; break; - case 0x05: y++; break; - case 0x06: x++; break; + case 0x00: bitmap_videoram_address_x--; bitmap_videoram_address_y++; break; + case 0x01: bitmap_videoram_address_y--; break; + case 0x02: bitmap_videoram_address_x--; break; + case 0x04: bitmap_videoram_address_x++; bitmap_videoram_address_y++; break; + case 0x05: bitmap_videoram_address_y++; break; + case 0x06: bitmap_videoram_address_x++; break; } } READ8_HANDLER( graph_processor_r ) { - int ret; - - if (bmap) - { - ret = tmpvideoram2[y * 256 + x]; - } - else - { - ret = tmpvideoram[y * 256 + x]; - } + UINT8 ret = current_bitmap_videoram_accessed[(bitmap_videoram_address_y << 8) | bitmap_videoram_address_x]; adjust_xy(offset); @@ -122,25 +135,12 @@ READ8_HANDLER( graph_processor_r ) WRITE8_HANDLER( graph_processor_w ) { - int color; - switch (offset) { - case 0x03: x = data; break; - case 0x07: y = data; break; + case 0x03: bitmap_videoram_address_x = data; break; + case 0x07: bitmap_videoram_address_y = data; break; default: - color = data & 0x07; - - if (bmap) - { - *BITMAP_ADDR16(tmpbitmap, y, (x-6)&0xff) = 16 + color; - tmpvideoram[y*256+x] = color; - } - else - { - *BITMAP_ADDR16(tmpbitmap2, y, (x-6)&0xff) = 16 + color; - tmpvideoram2[y*256+x] = color; - } + current_bitmap_videoram_accessed[(bitmap_videoram_address_y << 8) | bitmap_videoram_address_x] = data & 0x07; adjust_xy(offset); break; @@ -165,37 +165,37 @@ static TILE_GET_INFO( get_bg_tile_info ) SET_TILE_INFO(0, code, 0, 0); } -static void refresh_bitmaps(void) -{ - int lx,ly; - - for (ly = 0; ly < 256; ly++) - { - for (lx = 0; lx < 256; lx++) - { - *BITMAP_ADDR16(tmpbitmap, ly, (lx-6)&0xff) = 16 + tmpvideoram[ly*256+lx]; - *BITMAP_ADDR16(tmpbitmap2, ly, (lx-6)&0xff) = 16 + tmpvideoram2[ly*256+lx]; - } - } -} - VIDEO_START( cloak ) { - bg_tilemap = tilemap_create(get_bg_tile_info, tilemap_scan_rows, - 8, 8, 32, 32); + bg_tilemap = tilemap_create(get_bg_tile_info, tilemap_scan_rows, 8, 8, 32, 32); - tmpbitmap = auto_bitmap_alloc(machine->screen[0].width,machine->screen[0].height,machine->screen[0].format); - tmpbitmap2 = auto_bitmap_alloc(machine->screen[0].width,machine->screen[0].height,machine->screen[0].format); + bitmap_videoram1 = auto_malloc(256*256); + bitmap_videoram2 = auto_malloc(256*256); + palette_ram = auto_malloc(NUM_PENS * sizeof(palette_ram[0])); - tmpvideoram = auto_malloc(256*256); - tmpvideoram2 = auto_malloc(256*256); + set_current_bitmap_videoram_pointer(); - state_save_register_global(x); - state_save_register_global(y); - state_save_register_global(bmap); - state_save_register_global_pointer(tmpvideoram, 256*256); - state_save_register_global_pointer(tmpvideoram2, 256*256); - state_save_register_func_postload(refresh_bitmaps); + state_save_register_global(bitmap_videoram_address_x); + state_save_register_global(bitmap_videoram_address_y); + state_save_register_global(bitmap_videoram_selected); + state_save_register_global_pointer(bitmap_videoram1, 256*256); + state_save_register_global_pointer(bitmap_videoram2, 256*256); + state_save_register_global_pointer(palette_ram, NUM_PENS); + state_save_register_func_postload(set_current_bitmap_videoram_pointer); +} + +static void draw_bitmap(mame_bitmap *bitmap, const rectangle *cliprect) +{ + int x, y; + + for (y = cliprect->min_y; y <= cliprect->max_y; y++) + for (x = cliprect->min_x; x <= cliprect->max_x; x++) + { + pen_t pen = current_bitmap_videoram_displayed[(y << 8) | x]; + + if (pen) + *BITMAP_ADDR16(bitmap, y, (x - 6) & 0xff) = 0x10 | ((x & 0x80) >> 4) | pen; + } } static void draw_sprites(running_machine *machine, mame_bitmap *bitmap, const rectangle *cliprect) @@ -218,15 +218,15 @@ static void draw_sprites(running_machine *machine, mame_bitmap *bitmap, const re flipy = !flipy; } - drawgfx(bitmap, machine->gfx[1], code, 0, flipx, flipy, - sx, sy, cliprect, TRANSPARENCY_PEN, 0); + drawgfx(bitmap, machine->gfx[1], code, 0, flipx, flipy, sx, sy, cliprect, TRANSPARENCY_PEN, 0); } } VIDEO_UPDATE( cloak ) { + set_pens(machine); tilemap_draw(bitmap, cliprect, bg_tilemap, 0, 0); - copybitmap_trans(bitmap, (bmap ? tmpbitmap2 : tmpbitmap),flip_screen,flip_screen,0,0,cliprect,machine->pens[16]); + draw_bitmap(bitmap, cliprect); draw_sprites(machine, bitmap, cliprect); return 0; }