⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cps1.c

📁 十七种模拟器源代码 非常有用的作课程设计不可缺少的
💻 C
📖 第 1 页 / 共 4 页
字号:
     for (n=0; n<0x100000/2; n++){       WriteWord(&tmp[n<<3],ReadWord(&GFX_SPR[n<<1]));       WriteWord(&tmp[(n<<3)+2],ReadWord(&GFX_SPR[(n<<1)+0x200000]));       WriteWord(&tmp[(n<<3)+4],ReadWord(&GFX_SPR[(n<<1)+0x100000]));       WriteWord(&tmp[(n<<3)+6],ReadWord(&GFX_SPR[(n<<1)+0x300000]));     }     memcpy(GFX_SPR,tmp,size);          FreeMem(tmp);     EEPROM_init(&pang3_eeprom_interface);     load_eeprom();   }  load_common();  cps1_set_z80();    AddMemFetch(0x910000, 0x92ffff, cps1_gfxram+0x010000-0x000000);  AddRWBW(0x900000, 0x92FFFF, NULL, cps1_gfxram);  finish_conf_cps1();}// Deocding stuff for qsound... Thanks mame team !static int bitswap1(int src,int key,int select){  if (select & (1 << ((key >> 0) & 7)))    src = (src & 0xfc) | ((src & 0x01) << 1) | ((src & 0x02) >> 1);  if (select & (1 << ((key >> 4) & 7)))    src = (src & 0xf3) | ((src & 0x04) << 1) | ((src & 0x08) >> 1);  if (select & (1 << ((key >> 8) & 7)))    src = (src & 0xcf) | ((src & 0x10) << 1) | ((src & 0x20) >> 1);  if (select & (1 << ((key >>12) & 7)))    src = (src & 0x3f) | ((src & 0x40) << 1) | ((src & 0x80) >> 1);    return src;}static int bitswap2(int src,int key,int select){  if (select & (1 << ((key >>12) & 7)))    src = (src & 0xfc) | ((src & 0x01) << 1) | ((src & 0x02) >> 1);  if (select & (1 << ((key >> 8) & 7)))    src = (src & 0xf3) | ((src & 0x04) << 1) | ((src & 0x08) >> 1);  if (select & (1 << ((key >> 4) & 7)))    src = (src & 0xcf) | ((src & 0x10) << 1) | ((src & 0x20) >> 1);  if (select & (1 << ((key >> 0) & 7)))    src = (src & 0x3f) | ((src & 0x40) << 1) | ((src & 0x80) >> 1);    return src;}static int bytedecode(int src,int swap_key1,int swap_key2,int xor_key,int select){  src = bitswap1(src,swap_key1 & 0xffff,select & 0xff);  src = ((src & 0x7f) << 1) | ((src & 0x80) >> 7);  src = bitswap2(src,swap_key1 >> 16,select & 0xff);  src ^= xor_key;  src = ((src & 0x7f) << 1) | ((src & 0x80) >> 7);  src = bitswap2(src,swap_key2 & 0xffff,select >> 8);  src = ((src & 0x7f) << 1) | ((src & 0x80) >> 7);  src = bitswap1(src,swap_key2 >> 16,select >> 8);  return src;}static void kabuki_decode(unsigned char *src,unsigned char *dest_op,unsigned char *dest_data,		int base_addr,int length,int swap_key1,int swap_key2,int addr_key,int xor_key){  int A;  int select;  for (A = 0;A < length;A++)    {      /* decode opcodes */      select = (A + base_addr) + addr_key;      dest_op[A] = bytedecode(src[A],swap_key1,swap_key2,xor_key,select);            /* decode data */      select = ((A + base_addr) ^ 0x1fc0) + addr_key + 1;      dest_data[A] = bytedecode(src[A],swap_key1,swap_key2,xor_key,select);    }}static void cps1_decode(int swap_key1,int swap_key2,int addr_key,int xor_key){  unsigned char *rom = load_region[REGION_ROM2];  unsigned char *backup = qsound_rom;    /* the main CPU can read the ROM and checksum it to verify that it hasn't been */  /* replaced with a decrypted one. */  if (backup)      memcpy(backup,rom,0x8000);    kabuki_decode(rom,qsound_decode,rom,0x0000,0x8000, swap_key1,swap_key2,addr_key,xor_key);}static UINT16 qsound_rom_r(UINT32 offset) {  offset -= 0xf00000;    return ReadByte(qsound_rom+(offset>>1)) | 0xff00;}static UINT16 qsound_sharedram1_r(UINT32 offset){  int ret;  offset &= 0x1fff;    ret  = qsound_sharedram1[offset>>1] | 0xff00;  return ret;}static UINT8 qsound_sharedram1_rb(UINT32 offset){  int ret;  offset &= 0x1fff;/*    if (offset != 0x1fff) *//*      fprintf(stderr,"rb %x\n",offset); */  ret = qsound_sharedram1[offset>>1];  return ret;}static void qsound_sharedram1_w(UINT32 offset, UINT16 data){  offset &= 0x1fff;  //fprintf(stderr,"sound cmd %x\n",data);  qsound_sharedram1[offset>>1] = data & 0xff;}static void qsound_sharedram1_wb(UINT32 offset, UINT8 data){  offset &= 0x1fff;/*    if (data != 0xff)  *//*      fprintf(stderr,"sound cmdb %x\n",data); */  qsound_sharedram1[offset>>1] = data;}static UINT16 qsound_sharedram2_r(UINT32 offset){  offset &= 0x1fff;  //fprintf(stderr,"rw2\n");    return qsound_sharedram2[offset>>1] | 0xff00;}static UINT8 qsound_sharedram2_rb(UINT32 offset){  offset &= 0x1fff;  return qsound_sharedram2[offset>>1];}static void qsound_sharedram2_w(UINT32 offset, UINT16 data){  offset &= 0x1fff;  //fprintf(stderr,"sound cmd %x\n",data);    qsound_sharedram2[offset>>1] = data & 0xff;}static void qsound_sharedram2_wb(UINT32 offset, UINT8 data){  offset &= 0x1fff;  //fprintf(stderr,"sound cmdb %x\n",data);  qsound_sharedram2[offset>>1] = data;}void load_qsound() {  load_common();  if (!strncmp(current_game->main_name,"wof",3))     cps1_decode(0x01234567,0x54163072,0x5151,0x51);  else if (!strncmp(current_game->main_name,"dino",4))     cps1_decode(0x76543210,0x24601357,0x4343,0x43);  else if (!strncmp(current_game->main_name,"slammas",7))    cps1_decode(0x54321076,0x65432107,0x3131,0x19);  else if (!strncmp(current_game->main_name,"punish",6))     cps1_decode(0x67452103,0x75316024,0x2222,0x22);  qsound_set_z80();  EEPROM_init(&qsound_eeprom_interface);  load_eeprom();  AddRWBW(0x900000, 0x92FFFF, NULL, cps1_gfxram);  AddReadWord(0xf00000, 0xf0ffff, qsound_rom_r, NULL);  AddReadWord(0xf18000, 0xf19fff, qsound_sharedram1_r, NULL);  AddReadByte(0xf18000, 0xf19fff, qsound_sharedram1_rb, NULL);  AddWriteWord(0xf18000, 0xf19fff, qsound_sharedram1_w, NULL);  AddWriteByte(0xf18000, 0xf19fff, qsound_sharedram1_wb, NULL);  AddReadWord(0xf1e000, 0xf1ffff, qsound_sharedram2_r, NULL);  AddReadByte(0xf1e000, 0xf1ffff, qsound_sharedram2_rb, NULL);  AddWriteWord(0xf1e000, 0xf1ffff, qsound_sharedram2_w, NULL);  AddWriteByte(0xf1e000, 0xf1ffff, qsound_sharedram2_wb, NULL);    finish_conf_cps1();}void clear_cps1(void){   if (is_current_game("pang3") || is_current_game("pang3j")) {     save_eeprom();   }   #ifdef RAINE_DEBUG      save_debug("ROM.bin",ROM,get_region_size(REGION_ROM1),1);      save_debug("RAM.bin",RAM,0x080000,1);   #endif}void clear_qsound() {  save_eeprom();}#define SLICES 4#define Z80_FRAME CPU_FRAME_MHz(4,60)/SLICESvoid execute_cps1_frame(void){  int n,mx,my;    if (GameMouse) {    get_mouse_mickeys(&mx,&my);    WriteWord(&input_buffer[5*2],mx & 0xfff);    if (mouse_b & 1) input_buffer[8] &= 0xef;    if (mouse_b & 2) input_buffer[8] &= 0xdf;  }    cpu_execute_cycles(CPU_68K_0, CPU_FRAME_MHz(10,60));       // Main 68000   #ifdef RAINE_DEBUG      print_debug("PC:%06x SR:%04x\n", s68000context.pc, s68000context.sr);   #endif         cpu_interrupt(CPU_68K_0, 2);   if (RaineSoundCard) {     for (n=0; n< SLICES; n++) {       cpu_execute_cycles(CPU_Z80_0, Z80_FRAME );        // Sound Z80#ifdef RAINE_DEBUG       print_debug("Z80:%04x\n",z80pc);#endif       cpu_interrupt(CPU_Z80_0, 0x38);     }   }}void execute_sf2_frame(void){  int n;  cpu_execute_cycles(CPU_68K_0, CPU_FRAME_MHz(12,60));       // Main 68000   #ifdef RAINE_DEBUG      print_debug("PC:%06x SR:%04x\n", s68000context.pc, s68000context.sr);   #endif      if (s68000context.pc > 0x900000){	//ByteSwap(cps1_gfxram,0x20000);	save_file("RAM.bin",cps1_gfxram+(s68000context.pc-0x900000),0x100);	exit(1);      }   cpu_interrupt(CPU_68K_0, 2);   if (RaineSoundCard) {     for (n=0; n< SLICES; n++) {       cpu_execute_cycles(CPU_Z80_0, Z80_FRAME );        // Sound Z80#ifdef RAINE_DEBUG       print_debug("Z80:%04x\n",z80pc);#endif       cpu_interrupt(CPU_Z80_0, 0x38);     }   }}#undef SLICES#undef Z80_FRAME#define SLICES 4#define Z80_FRAME CPU_FRAME_MHz(4,60)/SLICESvoid execute_qsound_frame(void){  cpu_execute_cycles(CPU_68K_0, CPU_FRAME_MHz(10,60));       // Main 68000   #ifdef RAINE_DEBUG      print_debug("PC:%06x SR:%04x\n", s68000context.pc, s68000context.sr);   #endif         cpu_interrupt(CPU_68K_0, 2);      qsound_sharedram1[0xfff] = 0x77;   //fprintf(stderr,"%x\n",qsound_sharedram1[0xfff]);   #if 0   for (n=0; n< SLICES; n++) {     cpu_execute_cycles(CPU_Z80_0, Z80_FRAME );        // Sound Z80     cpu_interrupt(CPU_Z80_0, 0x38);   }#ifdef RAINE_DEBUG   print_debug("Z80:%04x\n",z80pc);#endif#endif}static void render_scroll1(int solid) {   int offs,offsy,offsx,sx,sy,code,n,x,y;   static int scrlxrough,scrlyrough,ytop;   UINT16 scroll1x = cps1_output[CPS1_SCROLL1_SCROLLX],     scroll1y = cps1_output[CPS1_SCROLL1_SCROLLY], colour;   UINT8 *map;   if (oldx != scroll1x || oldy != scroll1y) {     scrlxrough=(scroll1x>>3)+4;     scrlyrough=(scroll1y>>3);     ytop=-(scroll1y&0x07)+16;     //fprintf(stderr,"scroll1x %x %x\n",scroll1x,scroll1y);     oldx = scroll1x;     oldy = scroll1y;   }      /* After a bit of fight with the MAKE_SCROLL_xxx macros, I gave up and took the mame method : */   /* the good old for loops. At least you know where you are everytime !!! */   /* Here is SCROLL1. Maybe the sprites should be before ? */   sx=-(scroll1x&0x07);      if (solid) {     for (x=0; x<0x35; x++)       {	 sy=ytop;	 offsx=((scrlxrough+x)*0x80)&0x1fff;	 n=scrlyrough;	 for (y=0; y<0x20; y++,n++)	   {	     	     offsy=( (n&0x1f)*4 | ((n&0x20)*0x100)) & 0x3fff;	     offs=offsy+offsx;	     offs &= 0x3fff;	     	     code  =ReadWord(&RAM_SCROLL1[offs]) + base1;	     colour=ReadWord(&RAM_SCROLL1[(offs+2)]);	     if (code < max_sprites8 &&	       code != spacechar) {	       	       //if (code != 0x5420)	       //fprintf(stderr,"%d,%d,%x\n",sx,sy,code);	       MAP_PALETTE_MAPPED_NEW(				      (colour&0x1F) | 0x20,				      16,				      map				      );	       	       Draw8x8_Mapped_flip_Rot(&GFX_SPR[code<<6],sx,sy,map,(colour & 0x60)>>5);	     } 	     sy+=8;	   }	 sx+=8;       }   } else { // normal layer (not solid)     for (x=0; x<0x35; x++)       {	 sy=ytop;	 offsx=((scrlxrough+x)*0x80)&0x1fff;	 n=scrlyrough;	 for (y=0; y<0x20; y++,n++)	   {	   	     offsy=( (n&0x1f)*4 | ((n&0x20)*0x100)) & 0x3fff;	     offs=offsy+offsx;	     offs &= 0x3fff;			     code  =ReadWord(&RAM_SCROLL1[offs]) + base1;	     colour=ReadWord(&RAM_SCROLL1[(offs+2)]);	     if (code < max_sprites8 && GFX_SPR_SOLID[code] &&		 code != spacechar) {	       	       //if (code != 0x5420)	       //fprintf(stderr,"%d,%d,%x\n",sx,sy,code);	       MAP_PALETTE_MAPPED_NEW(				      (colour&0x1F) | 0x20,				      16,				      map				      );	     	       if (GFX_SPR_SOLID[code]==1) // Some pixels transp		 Draw8x8_Trans_Mapped_flip_Rot(&GFX_SPR[code<<6],sx,sy,map,(colour & 0x60)>>5);	       else // all solid		 Draw8x8_Mapped_flip_Rot(&GFX_SPR[code<<6],sx,sy,map,(colour & 0x60)>>5);	     } 	     sy+=8;	   }	 sx+=8;       }   } // if solid}static void render_sprites(int solid) {   /* Draw the sprites */  int i;  UINT8 *base,*map;  if (solid) {    // Sprites layer CAN'T be solid... That's the only case where we must    // clear the screen explicitly...    clear_game_screen(0);  }  cps1_buffered_obj = cps1_base(CPS1_OBJ_BASE, cps1_obj_size);  cps1_find_last_sprite();   base = cps1_buffered_obj + (cps1_last_sprite_offset/8)*8; // Not buffered yet... Is it really necessary?   /* Why are the sprites in the wrong order ??? */   /* mame draws them from 0 to the end, and I must do the contrary !!! */      //fprintf(stderr,"render_sprites %x\n",cps1_last_sprite_offset);      for (i=cps1_last_sprite_offset; i>=0; i-=8)     {       unsigned int x=ReadWord(base);       unsigned int y=ReadWord(base+2);       if (x && y)	 {	   unsigned int code=ReadWord(base+4);	   int colour=ReadWord(base+6);	   int col=colour&0x1f;	   // fprintf(stderr,"x %x y %x code %x i %x (%x)\n",x,y,code,i,cps1_last_sprite_offset);	   //fprintf(stderr,"%d,%d,%x,%x\n",x,y,code,colour);	   	   y &= 0x1ff;	   //if (y > 450) y -= 0x200;	   	   /* in cawing, skyscrapers parts on level 2 have all the top bits of the */	   /* x coordinate set. Does this have a special meaning? */	   x &= 0x1ff;	   //if (x > 450) x -= 0x200;	   	   x-=0x20;	   y+=0x10;	   	   if (kludge == 7)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -