📄 galaxian.c
字号:
/*************************************************************************** vidhrdw.c Functions to emulate the video hardware of the machine. This is the driver for the "Galaxian" style board, used, with small variations, by an incredible amount of games in the early 80s. This video driver is used by the following drivers: - galaxian.c - mooncrst.c - moonqsr.c - scramble.c - scobra.c - ckongs.c TODO: cocktail support hasn't been implemented properly yet***************************************************************************/#include "driver.h"#include "vidhrdw/generic.h"static struct rectangle spritevisiblearea ={ 2*8+1, 32*8-1, 2*8, 30*8-1};static struct rectangle spritevisibleareaflipx ={ 0*8, 30*8-2, 2*8, 30*8-1};#define MAX_STARS 250#define STARS_COLOR_BASE 32unsigned char *galaxian_attributesram;unsigned char *galaxian_bulletsram;int galaxian_bulletsram_size;static int stars_on,stars_blink;static int stars_type; /* 0 = Galaxian stars */ /* 1 = Scramble stars */ /* 2 = Rescue stars (same as Scramble, but only half screen) */static unsigned int stars_scroll;struct star{ int x,y,code,col;};static struct star stars[MAX_STARS];static int total_stars;static int gfx_bank; /* used by Pisces and "japirem" only */static int gfx_extend; /* used by Moon Cresta only */static int bank_mask; /* different games have different gfx bank switching */static int char_bank; /* used by Moon Quasar only */static int sprite_bank; /* used by Calipso only */static int flipscreen[2];static int BackGround; /* MJC 051297 */static unsigned char backcolour[256]; /* MJC 220198 *//*************************************************************************** Convert the color PROMs into a more useable format. Moon Cresta has one 32 bytes palette PROM, 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 output of the background star generator is connected this way: bit 5 -- 100 ohm resistor -- BLUE -- 150 ohm resistor -- BLUE -- 100 ohm resistor -- GREEN -- 150 ohm resistor -- GREEN -- 100 ohm resistor -- RED bit 0 -- 150 ohm resistor -- RED The blue background in Scramble and other games goes through a 390 ohm resistor.***************************************************************************/void galaxian_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom){ int i; unsigned char *opalette; #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity) #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs]) opalette = palette; /* first, the char acter/sprite palette */ for (i = 0;i < 32;i++) { int bit0,bit1,bit2; /* red component */ bit0 = (*color_prom >> 0) & 0x01; bit1 = (*color_prom >> 1) & 0x01; bit2 = (*color_prom >> 2) & 0x01; *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; /* green component */ bit0 = (*color_prom >> 3) & 0x01; bit1 = (*color_prom >> 4) & 0x01; bit2 = (*color_prom >> 5) & 0x01; *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; /* blue component */ bit0 = 0; bit1 = (*color_prom >> 6) & 0x01; bit2 = (*color_prom >> 7) & 0x01; *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2; color_prom++; } /* now the stars */ for (i = 0;i < 64;i++) { int bits; int map[4] = { 0x00, 0x88, 0xcc, 0xff }; bits = (i >> 0) & 0x03; *(palette++) = map[bits]; bits = (i >> 2) & 0x03; *(palette++) = map[bits]; bits = (i >> 4) & 0x03; *(palette++) = map[bits]; } /* characters and sprites use the same palette */ for (i = 0;i < TOTAL_COLORS(0);i++) { if (i & 3) COLOR(0,i) = i; else COLOR(0,i) = 0; /* 00 is always black, regardless of the contents of the PROM */ } /* colours for alternate background */ if (Machine->drv->total_colors == 224) { /* Graduated Blue */ for (i=0;i<64;i++) { opalette[64*3 + i*3 + 0] = 0; opalette[64*3 + i*3 + 1] = i * 2; opalette[64*3 + i*3 + 2] = i * 4; } /* Graduated Brown */ for (i=0;i<64;i++) { opalette[128*3 + i*3 + 0] = i * 3; opalette[128*3 + i*3 + 1] = i * 1.5; opalette[128*3 + i*3 + 2] = i; } } else { /* use an otherwise unused pen for the standard blue background */ opalette[3*4] = 0; opalette[3*4 + 1] = 0; opalette[3*4 + 2] = 0x55; } /* bullets can be either white or yellow */ COLOR(2,0) = 0; COLOR(2,1) = 0x0f + STARS_COLOR_BASE; /* yellow */ COLOR(2,2) = 0; COLOR(2,3) = 0x3f + STARS_COLOR_BASE; /* white */}void scramble_background_w(int offset, int data) /* MJC 051297 */{ if (BackGround != data) { BackGround = data; memset(dirtybuffer,1,videoram_size); }}/*************************************************************************** Start the video hardware emulation.***************************************************************************/static int common_vh_start(void){ int generator; int x,y; gfx_bank = 0; gfx_extend = 0; stars_on = 0; flipscreen[0] = 0; flipscreen[1] = 0; if (generic_vh_start() != 0) return 1; /* Default alternate background - Solid Blue - MJC 220198 */ for(x=0;x<256;x++) backcolour[x] = Machine->pens[4]; BackGround=0; /* precalculate the star background */ total_stars = 0; generator = 0; for (y = 255;y >= 0;y--) { for (x = 511;x >= 0;x--) { int bit1,bit2; generator <<= 1; bit1 = (~generator >> 17) & 1; bit2 = (generator >> 5) & 1; if (bit1 ^ bit2) generator |= 1; if (y >= Machine->drv->visible_area.min_y && y <= Machine->drv->visible_area.max_y && ((~generator >> 16) & 1) && (generator & 0xff) == 0xff) { int color; color = (~(generator >> 8)) & 0x3f; if (color && total_stars < MAX_STARS) { stars[total_stars].x = x; stars[total_stars].y = y; stars[total_stars].code = color; stars[total_stars].col = Machine->pens[color + STARS_COLOR_BASE]; total_stars++; } } } } return 0;}int galaxian_vh_start(void){ bank_mask = 0; stars_type = 0; char_bank = 0; sprite_bank = 0; return common_vh_start();}int moonqsr_vh_start(void){ bank_mask = 0x20; stars_type = 0; char_bank = 1; sprite_bank = 0; return common_vh_start();}int scramble_vh_start(void){ bank_mask = 0; stars_type = 1; char_bank = 0; sprite_bank = 0; return common_vh_start();}int rescue_vh_start(void){ int ans,x; bank_mask = 0; stars_type = 2; char_bank = 0; sprite_bank = 0; ans = common_vh_start(); /* Setup background colour array (blue sky, blue sea, black bottom line) */ for (x=0;x<64;x++) { backcolour[x*2] = Machine->pens[64+x]; backcolour[x*2+1] = Machine->pens[64+x]; } for (x=0;x<60;x++) { backcolour[128+x*2] = Machine->pens[68+x]; backcolour[128+x*2+1] = Machine->pens[68+x]; } for (x=248;x<256;x++) backcolour[x] = Machine->pens[0]; return ans;}int minefield_vh_start(void){ int ans,x; bank_mask = 0; stars_type = 2; char_bank = 0; sprite_bank = 0; ans = common_vh_start(); /* Setup background colour array (blue sky, brown earth, black bottom line) */ for (x=0;x<64;x++) { backcolour[x*2] = Machine->pens[64+x]; backcolour[x*2+1] = Machine->pens[64+x]; } for (x=0;x<60;x++) { backcolour[128+x*2] = Machine->pens[128+x]; backcolour[128+x*2+1] = Machine->pens[128+x]; } for (x=248;x<256;x++) backcolour[x] = Machine->pens[0]; return ans;}int ckongs_vh_start(void){ bank_mask = 0x10; stars_type = 1; char_bank = 0; sprite_bank = 0; return common_vh_start();}int calipso_vh_start(void){ bank_mask = 0; stars_type = 1; char_bank = 0; sprite_bank = 1; return common_vh_start();}void galaxian_flipx_w(int offset,int data){ if (flipscreen[0] != (data & 1)) { flipscreen[0] = data & 1; memset(dirtybuffer,1,videoram_size); }}void galaxian_flipy_w(int offset,int data){ if (flipscreen[1] != (data & 1)) { flipscreen[1] = data & 1; memset(dirtybuffer,1,videoram_size); }}void galaxian_attributes_w(int offset,int data){ if ((offset & 1) && galaxian_attributesram[offset] != data) { int i; for (i = offset / 2;i < videoram_size;i += 32) dirtybuffer[i] = 1; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -