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

📄 cps1.c

📁 十七种模拟器源代码 非常有用的作课程设计不可缺少的
💻 C
📖 第 1 页 / 共 4 页
字号:
   }   base2 = cps1_game_config->bank_scroll2*0x04000;   base1 = cps1_game_config->bank_scroll1*0x08000;   base3 = cps1_game_config->bank_scroll3*0x01000;   /* knights; the real space is 0x8820 */   if (kludge == 3)     spacechar = 0xf020;   else spacechar = 0x20;   spacechar += base1;   /* The spacechar case is a weird case of lazyness : scroll1 is sometimes */   /* filled with a sprite not drawn : spacechar. For most games, this */   /* sprite is empty and is detected by GFX_SPR_SOLID. But for some like */   /* strider, it really contains something !!! */   scrwidth = current_game->video_info->screen_x+32;   scrheight= current_game->video_info->screen_y+32;   /* Put in some defaults */   /* Apparently some games do not initialise completely and need these */   /* defaults (captcomm)  */   cps1_output[CPS1_OBJ_BASE]     = 0x9200;   cps1_output[CPS1_SCROLL1_BASE] = 0x9000;   cps1_output[CPS1_SCROLL2_BASE] = 0x9040;   cps1_output[CPS1_SCROLL3_BASE] = 0x9080;   cps1_output[CPS1_OTHER_BASE]   = 0x9100;   cps1_output[CPS1_PALETTE_BASE] = 0x90c0;}static UINT16 protection_rw(UINT32 offset){#if VERBOSE  if (offset >= 0x18/2) logerror("PC %06x: read output port %02x\n",cpu_get_pc(),offset*2);#endif  /* Some games interrogate a couple of registers on bootup. */  /* These are CPS1 board B self test checks. They wander from game to */  /* game. */    if (offset && offset == cps1_game_config->cpsb_addr/2)    return cps1_game_config->cpsb_value;   /* some games use as a protection check the ability to do 16-bit multiplies */   /* with a 32-bit result, by writing the factors to two ports and reading the */   /* result from two other ports. */   if (offset && offset == cps1_game_config->mult_result_lo/2)      return (cps1_output[cps1_game_config->mult_factor1/2] *            cps1_output[cps1_game_config->mult_factor2/2]) & 0xffff;   if (offset && offset == cps1_game_config->mult_result_hi/2)      return (cps1_output[cps1_game_config->mult_factor1/2] *            cps1_output[cps1_game_config->mult_factor2/2]) >> 16;   /* Pang 3 EEPROM interface */   if (kludge == 5 && offset == 0x7a/2)      return cps1_eeprom_port_r(0);   return cps1_output[offset];}static void protection_ww(UINT32 offset, UINT16 data){   /* Pang 3 EEPROM interface */   if (kludge == 5 && offset == 0x7a/2)   {      cps1_eeprom_port_w(0,data);      return;   }   cps1_output[offset] = data;   //data = COMBINE_DATA(&cps1_output[offset]);#ifdef MAME_DEBUGif (cps1_game_config->control_reg && offset == cps1_game_config->control_reg/2 && data != 0x3f)   usrintf_showmessage("control_reg = %04x",data);#endif#if VERBOSEif (offset >= 0x22/2 &&      offset != cps1_game_config->layer_control/2 &&      offset != cps1_game_config->priority0/2 &&      offset != cps1_game_config->priority1/2 &&      offset != cps1_game_config->priority2/2 &&      offset != cps1_game_config->priority3/2 &&      offset != cps1_game_config->control_reg/2)   logerror("PC %06x: write %02x to output port %02x\n",cpu_get_pc(),data,offset*2);#ifdef MAME_DEBUGif (offset == 0x22/2 && (data & ~0x8001) != 0x0e)   usrintf_showmessage("port 22 = %02x",data);if (cps1_game_config->priority0 && offset == cps1_game_config->priority0/2 && data != 0x00)   usrintf_showmessage("priority0 %04x",data);#endif#endif}static int dial[2]; // forgottn stuffstatic void cps1_ioc_wb(UINT32 offset, UINT8 data){   offset &= 0x1FF;   if (offset == 0x189) {     //fprintf(stderr,"sound_fade time %x\n",data);     cps1_sound_fade_timer = data;   } else if (offset == 0x181) {     //fprintf(stderr,"latch %x\n",data);     latch = data;   }}static void cps1_ioc_ww(UINT32 offset, UINT16 data){   offset &= 0x1FF;   if (offset == 0x188) {     cps1_sound_fade_timer = data & 0xff;   } else if (offset == 0x180) {     //fprintf(stderr,"latch %x\n",data);     latch = data & 0xff;   } else if (offset >= 0x100)      protection_ww((offset - 0x100)>>1, data);   else if (offset == 0x40)      dial[0] = input_buffer[5*2];   else if (offset == 0x48)     dial[1] = input_buffer[6*2];#ifdef RAINE_DEBUG   else     print_debug("cps1_ioc_ww unmapped %x\n",offset);#endif}static UINT16 cps1_input2_r(UINT32 offset) {  int buttons=input_buffer[5*2];    return buttons << 8 | buttons;}static UINT8 cps1_input2_rb(UINT32 offset) {  return input_buffer[5*2];}static UINT16 cps1_input3_r(UINT32 offset) {  int buttons=input_buffer[6*2];  return buttons << 8 | buttons;}static UINT8 cps1_input3_rb(UINT32 offset) {  return input_buffer[6*2];}static UINT8 cps1_ioc_rb(UINT32 offset){   offset &= 0x1FF;   if (offset >= 0x18 && offset <= 0x22) {     UINT8 input;     offset = (offset - 0x18) & 0xfe;     input = input_buffer[offset];     //fprintf(stderr,"read input %x,%x\n",offset,input);          return input;   } else if (offset == 0x177 || offset == 0x1fd)     return input_buffer[10];   else if (offset >= 0x100) {     int ret = protection_rw((offset - 0x100)>>1);     if (offset & 1) return ret>>8;     else return ret & 0xff;#ifdef RAINE_DEBUG   } else {     print_debug("cps1_ioc_rb unmapped %x\n",offset);#endif        }   return 0xFF;}static UINT16 cps1_ioc_rw(UINT32 offset){   offset &= 0x1FF;   if(offset < 0x100) {     if (offset >= 0x18 && offset<=0x22) {       UINT8 input;       offset = (offset - 0x18) & 0xfe;       input = input_buffer[offset];       return input | (input << 8);     } else if (offset == 0 || offset == 0x10)       fprintf(stderr,"port0_rw\n");     else if (offset == 0x52)	return (ReadWord(&input_buffer[5*2]) - dial[0]) & 0xff;     else if (offset == 0x54)	return ((ReadWord(&input_buffer[5*2]) - dial[0]) >> 8) & 0xff;     #ifdef RAINE_DEBUG   else     print_debug("cps1_ioc_rw unmapped %x\n",offset);#endif          return 0xFFFF;   } else      return protection_rw((offset - 0x100)>>1);}void cps1_reset_handler(void){#ifdef RAINE_DEBUG   print_debug("cps1_reset_handler()\n");#endif}static UINT8 *RAM_SCROLL1,*RAM_SCROLL2,*RAM_SCROLL3;static int layer_id_data[4];static char *layer_id_name[4] ={   "OBJECT", "SCROLL1", "SCROLL2", "SCROLL3",};void finish_conf_cps1(){   AddZ80AInit();   cps1_set_bank(0,0);   AddMemFetch(-1, -1, NULL);   AddReadByte(0x000000, 0xFFFFFF, DefBadReadByte, NULL);               // <Bad Reads>   AddReadWord(0x000000, 0xFFFFFF, DefBadReadWord, NULL);               // <Bad Reads>   AddWriteByte(0x000000, 0xFFFFFF, DefBadWriteByte, NULL);             // <Bad Writes>   AddWriteByte(0x000000, 0xFFFFFF, DefBadWriteWord, NULL);             // <Bad Writes>   AddRWBW(-1, -1, NULL, NULL);   AddInitMemory();     // Set Starscream mem pointers...   RAM_SCROLL1 = NULL; // Init after the 1st frame...}static void cps1_set_z80() {   AddZ80AROMBase(Z80ROM, 0x0038, 0x0066);   init_banks(Z80ROM);      AddZ80AReadByte(0x0000, 0xbfFF, NULL, NULL); // Z80 ROM + BANKS   AddZ80AReadByte(0xd000, 0xd7ff, NULL, Z80RAM);   AddZ80AReadByte(0xf001, 0xf001, YM2151_status_port_0_r, NULL);   AddZ80AReadByte(0xf002, 0xf002, OKIM6295_status_0_r, NULL);   AddZ80AReadByte(0xf008, 0xf008, NULL, &latch);   AddZ80AReadByte(0xf00a, 0xf00a, NULL, &cps1_sound_fade_timer);   AddZ80AReadByte(0x0000, 0xFFFF, DefBadReadZ80,               NULL);   AddZ80AReadByte(    -1,     -1, NULL,                        NULL);   AddZ80AWriteByte(0xd000, 0xd7FF, NULL,                       Z80RAM);   //   if (kludge != 7) { // forgottn has a broken music which crashes raine !     AddZ80AWriteByte(0xf000, 0xf000, YM2151_register_port_0_w,   NULL);     AddZ80AWriteByte(0xf001, 0xf001, YM2151_data_port_0_w,   NULL);     //}      AddZ80AWriteByte(0xf002, 0xf002, OKIM6295_data_0_w,   NULL);   AddZ80AWriteByte(0xf004, 0xf004, cps1_set_bank,   NULL);   AddZ80AWriteByte(0x0000, 0xFFFF, DefBadWriteZ80,             NULL);   AddZ80AWriteByte(    -1,     -1, NULL,                       NULL);}static void qsound_set_z80() {  qsound_sharedram1 = Z80RAM;  qsound_sharedram2 = Z80RAM + 0x1000;    init_banks(qsound_decode);     AddZ80AROMBase(qsound_decode, 0x0038, 0x0066);   AddZ80AReadByte(0x0000, 0xbfFF, NULL, NULL); // Z80 ROM/RAM   AddZ80AReadByte(0xc000, 0xcfff, NULL, Z80RAM);   AddZ80AReadByte(0xd007, 0xd007, qsound_status_r, NULL);   AddZ80AReadByte(0xf000, 0xffff, NULL, Z80RAM+0x1000);   AddZ80AReadByte(0x0000, 0xFFFF, DefBadReadZ80,               NULL);   AddZ80AReadByte(    -1,     -1, NULL,                        NULL);   AddZ80AWriteByte(0xc000, 0xcfFF, NULL, Z80RAM);   AddZ80AWriteByte(0xd000, 0xd000, qsound_data_h_w,   NULL);   AddZ80AWriteByte(0xd001, 0xd001, qsound_data_l_w,   NULL);   AddZ80AWriteByte(0xd002, 0xd002, qsound_cmd_w,   NULL);   AddZ80AWriteByte(0xd003, 0xd003, qsound_banksw_w,   NULL);   AddZ80AWriteByte(0xf000, 0xffff, NULL,   Z80RAM+0x1000);   AddZ80AWriteByte(0x0000, 0xFFFF, DefBadWriteZ80,             NULL);   AddZ80AWriteByte(    -1,     -1, NULL,                       NULL);}void load_common(void){   UINT32 ta,size;   UINT32 *dest;   int i,j,size_code;   UINT8 *cps1_gfx;      RAMSize=0x80000+0x10000;      if(!(RAM=AllocateMem(RAMSize))) return;        cps1_gfxram = RAM+0x010000;   Z80ROM=load_region[REGION_ROM2];   Z80RAM=RAM+0x70000;   memset(Z80RAM, 0x00, 0x10000);   /*      AddTaitoSoundBanking(load_region[REGION_ROM2], *//*         get_region_size(REGION_ROM2)); *//*      TaitoSoundSetBank(0,0); */   // No ports !   AddZ80AReadPort(0x00, 0xFF, DefBadReadZ80,           NULL);   AddZ80AReadPort(  -1,   -1, NULL,                    NULL);   AddZ80AWritePort(0xAA, 0xAA, StopZ80Mode2,           NULL);   AddZ80AWritePort(0x00, 0xFF, DefBadWriteZ80,         NULL);   AddZ80AWritePort(  -1,   -1, NULL,                   NULL);   RAM_SPR = RAM+0x004000;   GFX_SPR = load_region[REGION_GFX1];   size = get_region_size(REGION_GFX1); // size of packed region      cps1_gfx = GFX_SPR;   	for (i = 0;i < size/4;i++)	{		UINT32 src = cps1_gfx[4*i] + (cps1_gfx[4*i+1]<<8) + (cps1_gfx[4*i+2]<<16) + (cps1_gfx[4*i+3]<<24);		UINT32 dwval = 0;		int penusage = 0;		for (j = 0;j < 8;j++)		{			int n = 0;			UINT32 mask = (0x80808080 >> j) & src;			if (mask & 0x000000ff) n |= 1;			if (mask & 0x0000ff00) n |= 2;			if (mask & 0x00ff0000) n |= 4;			if (mask & 0xff000000) n |= 8;			dwval |= n << (j * 4);			penusage |= 1 << n;		}		cps1_gfx[4*i  ] = dwval>>0;		cps1_gfx[4*i+1] = dwval>>8;		cps1_gfx[4*i+2] = dwval>>16;		cps1_gfx[4*i+3] = dwval>>24;			}	   GFX_SPR16 = AllocateMem(size*2);   if (!GFX_SPR16) return;      for(ta=0;ta<size;ta++)   {      GFX_SPR[ta] ^= 0xff;   // Unpack 16x16 sprites (and 32x32)	  GFX_SPR16[(ta<<1)] = GFX_SPR[ta] & 0xf;	  GFX_SPR16[(ta<<1)+1] = GFX_SPR[ta] >> 4;   }   /* Need to separate 32x32 sprites for rotation... */   /* This is a terrible waste of memory, but at least it allows more speed */   GFX_SPR32 = AllocateMem(size*2);   /* We could avoid copying the whole buffer if we knew where the 32x32 */   /* sprites are in the buffer. But we know that only once the game has */   /* started... */   if (!GFX_SPR32) return;   memcpy(GFX_SPR32,GFX_SPR16,size*2);      /* rebuild 8x8 sprites */   GFX_SPR = AllocateMem(size);   dest= (UINT32*)GFX_SPR;      for (ta=8; ta <size*2; ta+=16) {     *dest++ = ReadLong(&GFX_SPR16[ta]);     *dest++ = ReadLong(&GFX_SPR16[ta+4]);   }      max_sprites = size*2 / 0x100;   max_sprites8= size / 0x40;   max_sprites32=max_sprites/4;      GFX_SPR_SOLID = make_solid_mask_8x8(GFX_SPR, max_sprites8);   GFX_SPR_SOLID16 = make_solid_mask_16x16(GFX_SPR16, max_sprites);   GFX_SPR_SOLID32 = make_solid_mask_32x32(GFX_SPR32, max_sprites32);          layer_id_data[0] = add_layer_info(layer_id_name[0]);   layer_id_data[1] = add_layer_info(layer_id_name[1]);   layer_id_data[2] = add_layer_info(layer_id_name[2]);   layer_id_data[3] = add_layer_info(layer_id_name[3]);   memset(RAM+0x00000,0x00,0x80000);   cps1_init_machine();/* *  StarScream Main 68000 Setup */   size_code = get_region_size(REGION_ROM1);      ByteSwap(ROM, size_code );   ByteSwap(RAM,0x070000);   AddResetHandler(&cps1_reset_handler);   AddMemFetch(0x000000, size_code-1, ROM+0x000000-0x000000);   AddReadBW(0x000000, size_code-1, NULL, ROM+0x000000);                 // 68000 ROM   AddReadBW(0x800000, 0x800001, NULL, &input_buffer[4*2]); // port 4 (ctrl)   AddReadBW(0x800010, 0x800011, NULL, &input_buffer[4*2]); // port 4 (ctrl)   AddReadWord(0x800176, 0x800177, cps1_input2_r, NULL);   AddReadWord(0x8001fc, 0x8001fd, cps1_input2_r, NULL);   AddReadWord(0xf1c000, 0xf1c001, cps1_input2_r, NULL);   AddReadByte(0xf1c001, 0xf1c001, cps1_input2_rb, NULL);   AddReadWord(0xf1c002, 0xf1c003, cps1_input3_r, NULL);   AddReadByte(0xf1c003, 0xf1c003, cps1_input3_rb, NULL);      AddRWBW(0xFF0000, 0xFFFFFF, NULL, RAM+0x000000);                 // 68000 RAM   AddReadByte(0x800000, 0x8001FF, cps1_ioc_rb, NULL);                  // IOC   AddReadWord(0x800000, 0x8001FF, cps1_ioc_rw, NULL);                  // IOC   AddReadWord(0xf1c006, 0xf1c007, cps1_eeprom_port_r, NULL); // eeprom   AddWriteByte(0x800000, 0x8001FF, cps1_ioc_wb, NULL);                 // IOC   AddWriteByte(0xAA0000, 0xAA0001, Stop68000, NULL);                   // Trap Idle 68000   AddWriteWord(0x800000, 0x8001FF, cps1_ioc_ww, NULL);                 // IOC   AddWriteWord(0xf1c006, 0xf1c007, cps1_eeprom_port_w, NULL);}extern int (*cpupos)(int len);extern int cputick, onef_cycle, calc_temp,cpu_calc(int);void load_cps1() {   cpupos=cpu_calc;   onef_cycle=300000; // 2151 freq   if (is_current_game("pang3") || is_current_game("pang3j")) {     // pang3 arrives in a wrong format because of the rom_continue...     // luckily it's a little rom, we can fix it here with no big overhead...     UINT8 *tmp;     int n;     int size = get_region_size(REGION_GFX1);     GFX_SPR = load_region[REGION_GFX1];     tmp = AllocateMem(size);

⌨️ 快捷键说明

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