📄 cps1.c
字号:
{ code += 0x4000; } if (kludge == 1 && code >= 0x01000) { code += 0x4000; } if (kludge == 2 && code >= 0x02a00) { code += 0x4000; } if (colour & 0xff00 ) { /* handle blocked sprites */ int nx=(colour & 0x0f00) >> 8; int ny=(colour & 0xf000) >> 12; unsigned int nxs,nys,sx,sy; nx++; ny++; if (colour & 0x40) { /* Y flip */ if (colour &0x20){ for (nys=0; nys<ny; nys++) { for (nxs=0; nxs<nx; nxs++) { int code2 = (code+(nx-1)-nxs+0x10*(ny-1-nys)); sx = (x+nxs*16) & 0x1ff; sy = (y+nys*16) & 0x1ff; if (sx < scrwidth && sy < scrheight && code2 <= max_sprites) { MAP_PALETTE_MAPPED_NEW( col, 16, map ); Draw16x16_Trans_Mapped_flip_Rot(&GFX_SPR16[code2<<8],sx, sy, map,3); } } } } else for (nys=0; nys<ny; nys++) { for (nxs=0; nxs<nx; nxs++) { int code2 = (code+nxs+0x10*(ny-1-nys)); sx = (x+nxs*16) & 0x1ff; sy = (y+nys*16) & 0x1ff; if (sx < scrwidth && sy < scrheight && code2 <= max_sprites) { MAP_PALETTE_MAPPED_NEW( col, 16, map ); Draw16x16_Trans_Mapped_flip_Rot(&GFX_SPR16[code2<<8],sx,sy,map,2 ); } } } } else { if (colour &0x20) // flipy !!! { for (nys=0; nys<ny; nys++) { for (nxs=0; nxs<nx; nxs++) { int code2 = (code+(nx-1)-nxs+0x10*nys); sx = (x+nxs*16) & 0x1ff; sy = (y+nys*16) & 0x1ff; if (sx < scrwidth && sy < scrheight && code2 <= max_sprites) { MAP_PALETTE_MAPPED_NEW( col, 16, map ); Draw16x16_Trans_Mapped_flip_Rot(&GFX_SPR16[code2<<8], sx,sy,map,1); } } } } else { for (nys=0; nys<ny; nys++) { for (nxs=0; nxs<nx; nxs++) { int code2 = (code+nxs+0x10*nys); sx = (x+nxs*16) & 0x1ff; sy = (y+nys*16) & 0x1ff; if (sx < scrwidth && sy < scrheight && code2 <= max_sprites) { MAP_PALETTE_MAPPED_NEW( col, 16, map ); Draw16x16_Trans_Mapped_flip_Rot(&GFX_SPR16[code2<<8],sx,sy, map,0); } } } } } } else { /* Simple case... 1 sprite does it happen ??? */ if (x < scrwidth && y < scrheight && code <= max_sprites) { MAP_PALETTE_MAPPED_NEW( col, 16, map ); Draw16x16_Trans_Mapped_flip_Rot(&GFX_SPR16[code<<8], x, y, map,(colour & 0x60)>>5); } } } // if x && y base -= 8; } // for i}static void cps1_render_scroll2_bitmap(int solid) { /* Expect lots of trouble with this layer. Mame renders it via a bitmap, */ /* and we do it directly. It's faster, but there are risks... */ int sx, sy; int ny=(scroll2y>>4); /* Rough Y */ const int startcode=cps1_game_config->start_scroll2; const int endcode=cps1_game_config->end_scroll2; UINT8 *map; if (solid) { for (sx=CPS1_SCROLL2_WIDTH-1; sx>=0; sx--) { int n=ny; for (sy=0x09*2-1; sy>=0; sy--) { int offsy, offsx, offs, colour, code; n&=0x3f; offsy = ((n&0x0f)*4 | ((n&0x30)*0x100))&0x3fff; offsx=(sx*0x040)&0xfff; offs=offsy+offsx; colour=ReadWord(&RAM_SCROLL2[offs+2]); code=ReadWord(&RAM_SCROLL2[offs]); if ( code >= startcode && code <= endcode /* MERCS has an gap in the scroll 2 layout (bad tiles at start of level 2)*/ && !(kludge == 4 && (code >= 0x1e00 && code < 0x5400)) ) { code += base2; if (code < max_sprites) { int myx = 16*sx - scrlx; int myy = 16*n - scrly; // We must warp around the bitmap... What a mess... if (myx < 0) myx += srcwidth; if (myy < 0) myy += srcheight; if (myx > 0 && myx <= scrwidth && myy> 0 && myy <= scrheight) { MAP_PALETTE_MAPPED_NEW( (colour&0x1F) | 0x40, 16, map ); Draw16x16_Mapped_flip_Rot(&GFX_SPR16[code<<8],myx,myy,map,(colour & 0x60)>>5); } } } n++; } } } else { // normal layer for (sx=CPS1_SCROLL2_WIDTH-1; sx>=0; sx--) { int n=ny; for (sy=0x09*2-1; sy>=0; sy--) { int offsy, offsx, offs, colour, code; n&=0x3f; offsy = ((n&0x0f)*4 | ((n&0x30)*0x100))&0x3fff; offsx=(sx*0x040)&0xfff; offs=offsy+offsx; colour=ReadWord(&RAM_SCROLL2[offs+2]); code=ReadWord(&RAM_SCROLL2[offs]); if ( code >= startcode && code <= endcode /* MERCS has an gap in the scroll 2 layout (bad tiles at start of level 2)*/ && !(kludge == 4 && (code >= 0x1e00 && code < 0x5400)) ) { code += base2; if (code < max_sprites && GFX_SPR_SOLID16[code]) { int myx = 16*sx - scrlx; int myy = 16*n - scrly; // We must warp around the bitmap... What a mess... if (myx < 0) myx += srcwidth; if (myy < 0) myy += srcheight; if (myx > 0 && myx <= scrwidth && myy> 0 && myy <= scrheight) { MAP_PALETTE_MAPPED_NEW( (colour&0x1F) | 0x40, 16, map ); if (GFX_SPR_SOLID16[code]==1) // Some pixels transp Draw16x16_Trans_Mapped_flip_Rot(&GFX_SPR16[code<<8],myx,myy,map,(colour & 0x60)>>5); else // all solid Draw16x16_Mapped_flip_Rot(&GFX_SPR16[code<<8],myx,myy,map,(colour & 0x60)>>5); } } } n++; } } } // if (solid)} static void cps1_render_scroll2_low(int solid){ scroll2x=cps1_output[CPS1_SCROLL2_SCROLLX]; scroll2y=cps1_output[CPS1_SCROLL2_SCROLLY]; if (scroll2x != oldx2 || scroll2y != oldy2) { // fprintf(stderr,"scroll2x %x scroll2y %x\n",scroll2x,scroll2y); oldx2 = scroll2x; oldy2 = scroll2y; scrly=-(scroll2y-0x20); scrlx=-(scroll2x+0x40-0x20); if (cps1_flip_screen) { fprintf(stderr,"fliping screen\n"); scrly=(CPS1_SCROLL2_HEIGHT*16)-scrly; } if (scrlx < 0) scrlx = (-scrlx) % srcwidth; else scrlx = srcwidth - scrlx % srcwidth; if (scrly < 0) scrly = (-scrly) % srcheight; else scrly = srcheight - (scrly % srcheight); scrly += 16; } cps1_render_scroll2_bitmap(solid);}static void render_scroll3(int priority,int solid){ int sx,sy; UINT16 scroll3x=cps1_output[CPS1_SCROLL3_SCROLLX]; UINT16 scroll3y=cps1_output[CPS1_SCROLL3_SCROLLY]; UINT8 *map; int nxoffset=scroll3x&0x1f; int nyoffset=scroll3y&0x1f; int nx=(scroll3x>>5)+1; int ny=(scroll3y>>5)-1; const int startcode=cps1_game_config->start_scroll3; const int endcode=cps1_game_config->end_scroll3; if (solid) { // this layer does not render properly when solid... clear_game_screen(0); } for (sx=1; sx<0x32/4+2; sx++) { for (sy=1; sy<0x20/4+2; sy++) { int offsy, offsx, offs, colour, code; int n; n=ny+sy; offsy = ((n&0x07)*4 | ((n&0xf8)*0x0100))&0x3fff; offsx=((nx+sx)*0x020)&0x7ff; offs=offsy+offsx; offs &= 0x3fff; code=ReadWord(&RAM_SCROLL3[offs]); if (code >= startcode && code <= endcode) { code+=base3; if (kludge == 2 && code >= 0x01500) { code -= 0x1000; } else if (kludge == 8 && code >= 0x05800) { code -= 0x4000; } else if (kludge == 9 && code < 0x05600) { code += 0x4000; } colour=ReadWord(&RAM_SCROLL3[(offs+2)]); if (code <= max_sprites32) { if (GFX_SPR_SOLID32[code]) { int myx = 32*sx-nxoffset; int myy = 32*sy-nyoffset-16; if (myx >=0 && myx<=scrwidth && myy>=0 && myy <= scrheight) { //if (code != 0x40ff) //fprintf(stderr,"draw layer2 %x %x %x\n",code,sx*16,n*16); MAP_PALETTE_MAPPED_NEW( (colour&0x1F) | 0x60, 16, map ); // _Rot functions are not ready... yet ! // fprintf(stderr,"draw %x,%x,%x\n",myx,myy,code); if (GFX_SPR_SOLID32[code]==1) // Some pixels transp Draw32x32_Trans_Mapped_flip_Rot(&GFX_SPR32[code<<10],myx,myy,map,(colour & 0x60)>>5); else // all solid Draw32x32_Mapped_flip_Rot(&GFX_SPR32[code<<10],myx,myy,map,(colour & 0x60)>>5); } } } } } }}static int render_layer(int layer,int distort,int solid) { if (cps1_layer_enabled[layer] && check_layer_enabled(layer_id_data[layer])){ switch(layer) { case 0: render_sprites(solid); break; case 1: render_scroll1(solid); break; case 2: #ifdef RAINE_DEBUG /* if (distort) */ /* //cps1_render_scroll2_distort(bitmap); */ /* fprintf(stderr,"distort not supported on layer2\n"); */#endif cps1_render_scroll2_low(solid); break; case 3: render_scroll3(0,solid); break; } return 0; // next layer is NOT solid } return 1;}void draw_cps1(void){ int videocontrol=cps1_output[0x11]; int layercontrol = cps1_output[cps1_game_config->layer_control/2]; int distort_scroll2 = videocontrol & 0x01; int l0 = (layercontrol >> 0x06) & 03, l1 = (layercontrol >> 0x08) & 03, l2 = (layercontrol >> 0x0a) & 03, l3 = (layercontrol >> 0x0c) & 03, solid; cps1_flip_screen=videocontrol&0x8000; if (!RAM_SCROLL1) { if (l0 == l1 || l0==l2 || l0==l3) {#ifdef RAINE_DEBUG fprintf(stderr,"l0 id %x %x %x %x\n",l0,l1,l2,l3);#endif return; } else if (l1 == l2 || l1==l3){#ifdef RAINE_DEBUG fprintf(stderr,"l1 id %x %x %x %x\n",l0,l1,l2,l3);#endif return; } else if (l2 == l3) {#ifdef RAINE_DEBUG fprintf(stderr,"l3 id %x %x %x %x\n",l0,l1,l2,l3);#endif return; } RAM_SCROLL1 = cps1_base(CPS1_SCROLL1_BASE,cps1_scroll1_size); RAM_SCROLL2 = cps1_base(CPS1_SCROLL2_BASE,cps1_scroll2_size); RAM_SCROLL3 = cps1_base(CPS1_SCROLL3_BASE,cps1_scroll3_size); cps1_palette=cps1_base(CPS1_PALETTE_BASE,cps1_palette_size); if (cps1_palette == RAM_SCROLL1 || cps1_palette==RAM_SCROLL2 || cps1_palette == RAM_SCROLL3 || RAM_SCROLL1 == RAM_SCROLL2 || RAM_SCROLL2 == RAM_SCROLL3) { RAM_SCROLL1 = NULL; return; } InitPaletteMap(cps1_palette, 0x80, 0x10, 0x10000); set_colour_mapper(&col_map_nnnn_rrrr_gggg_bbbb); #ifdef RAINE_DEBUG fprintf(stderr,"scroll2 (diff) %x\n",RAM_SCROLL2-cps1_gfxram); fprintf(stderr,"scroll3 (diff) %x\n",RAM_SCROLL3-cps1_gfxram); fprintf(stderr,"scroll1 (diff) %x\n",RAM_SCROLL1-cps1_gfxram); fprintf(stderr,"palette (diff) %x\n",cps1_palette-cps1_gfxram);#endif } cps1_layer_enabled[0]=1; cps1_layer_enabled[1]=layercontrol & cps1_game_config->scrl1_enable_mask; cps1_layer_enabled[2]=layercontrol & cps1_game_config->scrl2_enable_mask; cps1_layer_enabled[3]=layercontrol & cps1_game_config->scrl3_enable_mask; cps1_stars_enabled =layercontrol & cps1_game_config->stars_enable_mask; ClearPaletteMap(); solid = render_layer(l0,distort_scroll2,1); // solid layer solid = render_layer(l1,distort_scroll2,solid); solid = render_layer(l2,distort_scroll2,solid); render_layer(l3,distort_scroll2,solid);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -