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

📄 ksystem.c

📁 十七种模拟器源代码 非常有用的作课程设计不可缺少的
💻 C
📖 第 1 页 / 共 4 页
字号:
   AddZ80BReadByte(0xF010, 0xF010, KSystemInputRead,  NULL);   // INPUT   AddZ80BReadByte(0xF800, 0xFFFF, NULL,              RAM+0xF800);   // RAM?   AddZ80BReadByte(0x0000, 0xFFFF, DefBadReadZ80,     NULL);	// <bad reads>   AddZ80BReadByte(-1, -1, NULL, NULL);   AddZ80BWriteByte(0xC000, 0xE7FF, NULL,                RAM+0xC000);   // RAM   AddZ80BWriteByte(0xE800, 0xE8FF, KSystemMCUWrite,     NULL);         // MCU   AddZ80BWriteByte(0xE900, 0xEFFF, NULL,                RAM+0xE900);   // RAM   AddZ80BWriteByte(0xF000, 0xF000, KSystemNewBankWrite, NULL);         // ROM BANK   AddZ80BWriteByte(0xF008, 0xF008, KSystemF008Write,    NULL);         // ?   AddZ80BWriteByte(0xF010, 0xF010, KSystemInputWrite,   NULL);         // INPUT   AddZ80BWriteByte(0xF018, 0xF018, NULL,                RAM+0xF018);   // WATCHDOG   AddZ80BWriteByte(0xF800, 0xFFFF, NULL,                RAM+0xF800);   // RAM?   AddZ80BWriteByte(0x0000, 0xFFFF, DefBadWriteZ80,      NULL);         // <bad writes>   AddZ80BWriteByte(-1, -1, NULL, NULL);   AddZ80BReadPort(0x00, 0xFF, DefBadReadZ80,			NULL);	// <bad reads>   AddZ80BReadPort(-1, -1, NULL, NULL);   AddZ80BWritePort(0xAA, 0xAA, StopZ80BMode2,			NULL);	// Trap Idle Z80   AddZ80BWritePort(0x00, 0xFF, DefBadWriteZ80,			NULL);	// <bad reads>   AddZ80BWritePort(-1, -1, NULL, NULL);   AddZ80BInit();   if(!load_rom("a87-06.bin",ROM2,0x8000)) return;		// Z80 SUB ROM   // Skip Idle Z80   // -------------   ROM2[0x037d]=0xAF;  // XOR A (checksum always succeeds)   ROM2[0x00d7]=0xD3;  // OUTA (AAh)   ROM2[0x00d8]=0xAA;  //   SetStopZ80CMode2(0x00d4);   memset(RAM2+0x00000, 0x00, 0x10000);   memcpy(RAM2, ROM2, 0x8000);   AddZ80CROMBase(RAM2, 0x0038, 0x0066);   AddZ80CReadByte(0x0000, 0x7FFF, NULL,                    RAM2+0x0000);   // Z80 ROM   AddZ80CReadByte(0x8000, 0xA7FF, NULL,                    RAM +0xC000);   // COMMON RAM   AddZ80CReadByte(0xC000, 0xC001, KSystemYM2203Read,       NULL);          // YM2203; INPUT   AddZ80CReadByte(0xA800, 0xC7FF, NULL,                    RAM2+0xA800);   // RAM?   AddZ80CReadByte(0x0000, 0xFFFF, DefBadReadZ80,           NULL);          // <bad reads>   AddZ80CReadByte(-1, -1, NULL, NULL);   AddZ80CWriteByte(0x8000, 0xA7FF, NULL,                   RAM +0xC000);   // COMMON RAM   AddZ80CWriteByte(0xC000, 0xC001, KSystemYM2203Write,     NULL);          // YM2203; INPUT   AddZ80CWriteByte(0xA800, 0xC7FF, NULL,                   RAM2+0xA800);   // RAM?   AddZ80CWriteByte(0x0000, 0xFFFF, DefBadWriteZ80,         NULL);          // <bad writes>   AddZ80CWriteByte(-1, -1, NULL, NULL);   AddZ80CReadPort(0x00, 0xFF, DefBadReadZ80,         NULL);   // <bad reads>   AddZ80CReadPort(-1, -1, NULL, NULL);   AddZ80CWritePort(0xAA, 0xAA, StopZ80CMode2,			NULL);	// Trap Idle Z80   AddZ80CWritePort(0x00, 0xFF, DefBadWriteZ80,			NULL);	// <bad reads>   AddZ80CWritePort(-1, -1, NULL, NULL);   AddZ80CInit();   /* MCU ROM */   if(!load_rom("68_h.bin",RAM_MCU,0x800)) return;   if(!(GFX=AllocateMem(0x080000))) return;   if(!(TMP=AllocateMem(0x040000))) return;   if(!load_rom("a87-05.bin", TMP+0x00000, 0x10000)) return;   if(!load_rom("a87-04.bin", TMP+0x10000, 0x08000)) return;   if(!load_rom("a87-04.bin", TMP+0x18000, 0x08000)) return;   if(!load_rom("a87-03.bin", TMP+0x20000, 0x10000)) return;   if(!load_rom("a87-02.bin", TMP+0x30000, 0x08000)) return;   if(!load_rom("a87-02.bin", TMP+0x38000, 0x08000)) return;   // much annoyingness. we have to swap the upper/lower halves   // of the 64K roms (the 32K ones just get repeated) :-(   for(ta=0;ta<0x8000;ta++)   {      tb = TMP[0x00000+ta];      TMP[0x00000+ta] = TMP[0x08000+ta];      TMP[0x08000+ta] = tb;      tb = TMP[0x20000+ta];      TMP[0x20000+ta] = TMP[0x28000+ta];      TMP[0x28000+ta] = tb;   }   tb=0;   for(ta=0;ta<0x20000;ta+=2,tb+=8){      DrawNibble0(GFX+tb+0, 0, (UINT8) (TMP[ta+0x00000]&15) );      DrawNibble (GFX+tb+0, 1, (UINT8) (TMP[ta+0x00000]>>4) );      DrawNibble (GFX+tb+0, 2, (UINT8) (TMP[ta+0x20000]&15) );      DrawNibble (GFX+tb+0, 3, (UINT8) (TMP[ta+0x20000]>>4) );      DrawNibble0(GFX+tb+4, 0, (UINT8) (TMP[ta+0x00001]&15) );      DrawNibble (GFX+tb+4, 1, (UINT8) (TMP[ta+0x00001]>>4) );      DrawNibble (GFX+tb+4, 2, (UINT8) (TMP[ta+0x20001]&15) );      DrawNibble (GFX+tb+4, 3, (UINT8) (TMP[ta+0x20001]>>4) );   }   tb=0;   if(!load_rom("a87-10.bin", TMP+0x00000, 0x100)) return;   if(!load_rom("a87-12.bin", TMP+0x00100, 0x100)) return;   if(!load_rom("a87-11.bin", TMP+0x00200, 0x100)) return;   for(ta=0;ta<0x100;ta++,tb+=2){      td  = ta ^ 0x0f;      tc  = (TMP[td+0x000]&0x0F)<<8;      tc |= (TMP[td+0x100]&0x0F)<<4;      tc |= (TMP[td+0x200]&0x0F)<<0;      WriteWord(&RAM_COLOUR[tb],tc);   }   FreeMem(TMP);   GFX_BG0_SOLID = make_solid_mask_8x8(GFX, 0x2000);}void ExecuteKSystemFrame(void){   int ta;   if (cpu_get_pc(CPU_Z80_1) == 0x0000)   {      switch (romset) {      case 0: KikiKaiKai_mcu_reset(); break;      case 1: KickRun_mcu_reset(); break;      }   } else if (romset && #ifdef MZ80_V3cpu_get_pc(CPU_Z80_1) == 0x3a4b)#elsecpu_get_pc(CPU_Z80_1) == 0x3a55)#endif     // Dirty hack to force a reset. Don't know why it's necessary !!!     reset_game_hardware();   // ---------------------   if (romset==0)   {      for(ta=0;ta<16;ta++)      {         // probably actually only 6Mhz or so, but MZ80 bug means that...         cpu_execute_cycles(CPU_Z80_1, CPU_FRAME_MHz(16,60)/16);  // Main Z80 (60fps)         if(cpu_get_pc(CPU_Z80_2) != 0x00A6)            cpu_execute_cycles(CPU_Z80_2, CPU_FRAME_MHz(8,60)/16);  // Sub Z80 (60fps)      }      #ifdef RAINE_DEBUG      print_debug("Z80PC_MAIN:%04x\n",cpu_get_pc(CPU_Z80_1));      #endif      cpu_interrupt(CPU_Z80_1, 0x38);      cpu_interrupt(CPU_Z80_2, 0x38);   }   else {      cpu_execute_cycles(CPU_Z80_1, CPU_FRAME_MHz(8,60));   // Main Z80 6MHz (60fps)      #ifdef RAINE_DEBUG      print_debug("Z80PC_MAIN:%04x\n",z80pc);      #endif      cpu_interrupt(CPU_Z80_1, RAM[0xe800]);      cpu_execute_cycles(CPU_Z80_2, CPU_FRAME_MHz(8,60));   // Sub Z80 4MHz (60fps)      #ifdef RAINE_DEBUG      print_debug("Z80PC_SUB:%04x\n",z80pc);      #endif      cpu_interrupt(CPU_Z80_2, 0x38);   }   if (mcu_enable)   {      switch (romset) {      case 0: KikiKaiKai_mcu(1); break;      case 1: KickRun_mcu(1); break;      }   }}void DrawKikiKaiKai(void){   int x,y,ta;   int sx,sy,offs,goffs,gfx_offs,gfx_num,gfx_attr,height,xc,yc;   UINT8 map;   // PALETTE   if (RefreshBuffers)   {      for(x=0;x<0x200;x+=2)      {         ta = ReadWord(&RAM_COLOUR[x]);         pal[x >> 1].r = (ta & 0x0F00) >> 6;         pal[x >> 1].g = (ta & 0x00F0) >> 2;         pal[x >> 1].b = (ta & 0x000F) << 2;      }   }   // No Solid BG0   clear_game_screen(0);   // OBJECT   sx = 0;   for (offs=0;offs<0x300;offs+=4)   {      /* skip empty sprites */      if (*(UINT32 *)(&RAM[offs+0xd500]) == 0) continue;      gfx_num = RAM[0xd500 + offs + 1];      gfx_attr = RAM[0xd500 + offs + 3];      if ((gfx_num & 0x80) == 0)      /* 16x16 sprites */      {         gfx_offs = ((gfx_num & 0x1f) * 0x80) + ((gfx_num & 0x60) >> 1) + 12;         height = 2;      }      else    /* tilemaps (each sprite is a 16x256 column) */      {         gfx_offs = ((gfx_num & 0x3f) * 0x80);         height = 32;      }      if ((gfx_num & 0xc0) == 0xc0)         sx += 16;      else      {         sx = RAM[0xd500 + offs + 2];         if (gfx_attr & 0x40) sx -= 256;      }      sy = 256 - height*8 - (RAM[0xd500 + offs + 0]);      for (xc=0;xc<2;xc++)      {         goffs = gfx_offs;         for (yc=0;yc<height;yc++,goffs+=2)         {            /* this is different to Bubble Bobble */            ta = ReadWord(&RAM[0xc000+goffs]) & 0x1FFF;            if (!GFX_BG0_SOLID[ta]) continue;       // No pixels; skip            map = (RAM[0xc001 + goffs] >> 1) & 0x70;            x = (sx + xc * 8) & 0xff;            y = ((sy + yc * 8) & 0xff) -16;            /* Kiki Kai Kai appears not to have a X/Y flip (eh?) */            if ((x > -8) && (y > -8) && (x < 256) && (y < 224))            {               if (GFX_BG0_SOLID[ta] == 1)       // Some pixels; trans               {                  Draw8x8_Trans_Rot(&GFX[ta<<6], x+8, y+8, map);               } else {                          // all pixels; solid                  Draw8x8_Rot(&GFX[ta<<6], x+8, y+8, map);               }            }         }         gfx_offs += 64;      }   }}void DrawKickRun(void){   int x,y,ta;   int sx,sy,offs,goffs,gfx_offs,gfx_num,gfx_attr,height,xc,yc;   UINT8 map;   // PALETTE   if (RefreshBuffers)   {      for(x=0;x<0x200;x+=2)      {         ta = ReadWord(&RAM_COLOUR[x]);         pal[x >> 1].r = (ta & 0x0F00) >> 6;         pal[x >> 1].g = (ta & 0x00F0) >> 2;         pal[x >> 1].b = (ta & 0x000F) << 2;      }   }   // No Solid BG0   clear_game_screen(0);   // OBJECT   sx = 0;   for (offs=0;offs<0x4c0;offs+=4)   {      // I really give up on this bollocks, I really do.      // MAME says do this. <sigh>      if (offs >= 0x300 && offs < 0x480) continue;      /* skip empty sprites */      if (*(UINT32 *)(&RAM[offs+0xd500]) == 0) continue;      gfx_num = RAM[0xd500 + offs + 1];      gfx_attr = RAM[0xd500 + offs + 3];      if ((gfx_num & 0x80) == 0)      /* 16x16 sprites */      {         gfx_offs = ((gfx_num & 0x1f) * 0x80) + ((gfx_num & 0x60) >> 1) + 12;         height = 2;      }      else    /* tilemaps (each sprite is a 16x256 column) */      {         gfx_offs = ((gfx_num & 0x3f) * 0x80);         height = 32;      }      if ((gfx_num & 0xc0) == 0xc0)         sx += 16;      else      {         sx = RAM[0xd500 + offs + 2];         // not this either (accoring to MAME at least)?         //if (gfx_attr & 0x40) sx -= 256;      }      sy = 256 - height*8 - (RAM[0xd500 + offs + 0]);      for (xc=0;xc<2;xc++)      {         goffs = gfx_offs;         for (yc=0;yc<height;yc++,goffs+=2)         {            /* this is different to both Bubble Bobble and KKK */            ta = ReadWord(&RAM[0xc000+goffs]) & 0x07FF;            ta |= (RAM[0xc001+goffs] & 0x80) << 4;            ta |= gfx_bank << 12;            if (!GFX_BG0_SOLID[ta]) continue;       // No pixels; skip            map = (RAM[0xc001 + goffs] << 1) & 0x70;            map |= (gfx_attr & 0x02) << 6;            x = (sx + xc * 8) & 0xff;            y = ((sy + yc * 8) & 0xff) -16;            if ((x > -8) && (y > -8) && (x < 256) && (y < 224))            {               if (GFX_BG0_SOLID[ta] == 1)       // Some pixels; trans               {                  if (RAM[0xc000+goffs+1] & 0x40)                     Draw8x8_Trans_FlipY_Rot(&GFX[ta<<6], x+8, y+8, map);                  else                     Draw8x8_Trans_Rot(&GFX[ta<<6], x+8, y+8, map);               } else {                          // all pixels; solid                  if (RAM[0xc000+goffs+1] & 0x40)                     Draw8x8_FlipY_Rot(&GFX[ta<<6], x+8, y+8, map);                  else                     Draw8x8_Rot(&GFX[ta<<6], x+8, y+8, map);               }            }         }         gfx_offs += 64;      }   }}

⌨️ 快捷键说明

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