📄 ksystem.c
字号:
struct GAME_MAIN game_knight_boy ={ knight_boy_dirs, knight_boy_roms, kiki_kai_kai_inputs, kiki_kai_kai_dsw, NULL, LoadKnightBoy, ClearKSystem, &kiki_kai_kai_video, ExecuteKSystemFrame, "knightb", "Knight Boy", NULL, COMPANY_ID_BOOTLEG, NULL, 1986, kiki_kai_kai_sound, GAME_PLATFORM,};static int romset;static UINT8 *RAM2;static UINT8 *ROM2;static UINT8 *RAM_INPUT;static UINT8 *RAM_COLOUR;static UINT8 *RAM_MCU;static UINT8 *GFX_BG0_SOLID;/*TAITO K-SYSTEM--------------0000-7FFF BASE ROM8000-BFFF BANK ROMD800-EFFF RAMF000-F000 BANK SWITCHF008-F008 MCU ENABLE?F010-F010 INPUT READF018-F018 WATCHDOGC000-FFFF <misc>C500-CCFF SPRITE TILE RAMCD00-D4FF BG0 RAMD500-D501 BG0 SCROLL XD502-D503 BG0 SCROLL Y---0000-7FFF BASE ROM8000-9FFF COMMUNICATE RAMC000-C001 YM2203Supported romsets:0 - B36 - Kiki Kai Kai - 19861 - A87 - Kick and Run - 1985- Hardware info courtesy of Carl/DSC [Antiriad].Todo:- Graphics glitches: Shadows under monsters look like they might be in the wrong priority... hmm..- Player 2 inputs don't work in KKK?? (work in test mode, not in game). Could be do to with writes to 0xffff... Works in 'Table' mode, but using P1 inputs.- I think this H/W has a system to connect 2 boards together...*//******************************************************************************//* K-SYSTEM Z80 ROM BANKING *//******************************************************************************/static UINT8 Z80Bank, gfx_bank;static UINT8 Z80BankCount;static UINT8 bank_map[8] ={ 4,5,6,7,2,3,0,1,};void KSystemBankWrite(UINT16 offset, UINT8 data){ if(bank_map[data&7] != Z80Bank){ Z80Bank = bank_map[data&7]; memcpy(RAM+0x8000, ROM+(Z80Bank<<14), 0x4000); }}static UINT8 *ROM_BANK[8];void KSystemNewBankWrite(UINT16 offset, UINT8 data){ if(bank_map[data&7] != Z80Bank){ Z80Bank = bank_map[data&7]; Z80BSetBank( ROM_BANK[Z80Bank] ); } gfx_bank = (data & 0x20) >> 5;}#if 0// This function is unused !!!static UINT16 KSystemBankRead(UINT16 offset){ return Z80Bank;}#endifstatic void init_bank_rom(UINT8 *src, UINT8 *dst){ int ta; for(ta=0;ta<8;ta++){ ROM_BANK[ta] = dst+(ta*0xC000); memcpy(ROM_BANK[ta]+0x0000,src+0x0000,0x8000); memcpy(ROM_BANK[ta]+0x8000,src+(ta*0x4000),0x4000); }}/******************************************************************************//* K-SYSTEM COMMON RAM *//******************************************************************************/#if 0// Unused functions !static void KSystemCommonRAMWrite(UINT16 offset, UINT8 data){ RAM[0xC000+(offset&0x1FFF)] = data;}static UINT8 KSystemCommonRAMRead(UINT16 offset){ return RAM[0xC000+(offset&0x1FFF)];}#endif/******************************************************************************//* K-SYSTEM MCU *//******************************************************************************/static int mcu_enable;static UINT8 mcu_addr, mcu_latch, mcu_old_data;static void KSystemMCUWrite(UINT16 offset, UINT8 data){ offset&=0xFF; #ifdef RAINE_DEBUG //print_debug("MCU Write: %02x:%02x [%04x]\n", offset, data, z80pc); #endif RAM[offset+0xE800] = data;}static UINT8 KSystemMCURead(UINT16 offset){ offset&=0xFF; #ifdef RAINE_DEBUG //print_debug("MCU Read: %02x:?? [%04x]\n", offset, z80pc); #endif return RAM[offset+0xE800];}void KikiKaiKai_mcu(int bih_count);void KikiKaiKai_mcu_reset(void);void KickRun_mcu(int bih_count);void KickRun_mcu_reset(void);UINT8 KSystem_MCU_RDMEM(int a){ //print_debug("MCU RDMEM(0x%x)=%x\n", a, RAM_MCU[a]); if (a == 0x02) /* Port C - COIN,TILT,etc */ { return RAM_INPUT[5]; } return RAM_MCU[a];}void KSystem_MCU_WRMEM(int a, UINT8 v){ UINT8 rising,falling; //print_debug("MCU WRMEM(0x%x,0x%x)\n", a, v); RAM_MCU[a] = v; if (a == 0x01) /* I/O control */ { rising = (v ^ mcu_old_data) & v; /* only the rising-edge triggers these */ falling = (v ^ mcu_old_data) & mcu_old_data; /* only the falling-edge triggers these */ mcu_old_data = v; if (falling & 0x01) RAM_MCU[0x00] = mcu_latch; if (rising & 0x02) mcu_addr = RAM_MCU[0x00]; if (falling & 0x08) { if (v & 0x10) /* read */ { if (v & 4) /* System RAM */ { mcu_latch = RAM[0xe800 + mcu_addr]; } else { mcu_latch = RAM_INPUT[mcu_addr+1]; } } else { /* write */ if (v & 4) /* System RAM */ { RAM[0xe800 + mcu_addr] = RAM_MCU[0x00]; } else {#ifdef RAINE_DEBUG print_debug("INPUT WRITE!!?! (%x)\n", mcu_addr);#endif } } } //if (falling & 0x20) mz80int(0xff); }}static void KSystemF008Write(UINT16 offset, UINT8 data){ #ifdef RAINE_DEBUG print_debug("MCU control: %04x:%02x [%04x]\n", offset, data, z80pc); #endif // Just a hack for the MCU if(data==0x1E) mcu_enable = 1; else mcu_enable = 0;}/******************************************************************************//* K-SYSTEM INPUT RAM *//******************************************************************************/static void KSystemInputWrite(UINT16 offset, UINT8 data){ #ifdef RAINE_DEBUG print_debug("Input Write: %04x:%02x [%04x]\n", offset, data, z80pc); #endif}static UINT8 KSystemInputRead(UINT16 offset){ return RAM_INPUT[0];}/******************************************************************************//* K-SYSTEM YM2203 AND DSW ACCESS *//******************************************************************************/static UINT8 ksys_ym2203_reg;static UINT8 KSystemYM2203Read(UINT16 offset){ //print_debug("YM2203 RB:%04x/?? [%04x]\n", offset, z80pc); if((offset&1)==0){ return 0; //YM2203_status_port_0_r(0); } else{ switch(ksys_ym2203_reg){ case 0x0e: return get_dsw(0); case 0x0f: return get_dsw(1); default: return 0; //return YM2203_read_port_0_r(0); } }}static void KSystemYM2203Write(UINT16 offset, UINT8 data){ //print_debug("YM2203 WB:%04x/%02x [%04x]\n", offset, data, z80pc); if((offset&1)==0){ ksys_ym2203_reg = data; } else{ YM2203_control_port_0_w(0,ksys_ym2203_reg); YM2203_write_port_0_w(1,data); }}/******************************************************************************/static void DrawNibble0(UINT8 *out, UINT32 plane, UINT8 c){ int count, t; count = 4; do { t = c & 1; *out = t << plane; out++; c >>= 1; } while(--count);}static void DrawNibble(UINT8 *out, UINT32 plane, UINT8 c){ int count, t; count = 4; do { t = c & 1; *out |= t << plane; out++; c >>= 1; } while(--count);}void LoadKikiKaiKai(void){ int ta,tb,tc,td; UINT8 *TMP; romset=0; Z80BankCount=0x20000/0x4000; mcu_enable=0; RAMSize=0x10000+0x10000+0x10+0x200+0x800; if(!(ROM=AllocateMem(0xC000*Z80BankCount))) return; if(!(ROM2=AllocateMem(0x8000))) return; if(!(RAM=AllocateMem(RAMSize))) return; RAM2 = RAM+0x10000; RAM_INPUT = RAM+0x10000+0x10000; RAM_COLOUR = RAM+0x10000+0x10000+0x10; RAM_MCU = RAM+0x10000+0x10000+0x10+0x200; if(!(TMP=AllocateMem(0x20000))) return; if(!load_rom("a85-17.rom",TMP+0x00000,0x10000)) return; // Z80 MAIN ROM if(!load_rom("a85-16.rom",TMP+0x10000,0x10000)) return; // Z80 MAIN ROM // Fix Checksum TMP[0x485a]=0xC9; // RET // Skip Idle Z80 TMP[0x0503]=0x28; // JR Z,#0508 TMP[0x0504]=0x03; // TMP[0x0505]=0xD3; // OUTA (AAh) TMP[0x0506]=0xAA; // SetStopZ80BMode2(0x04FF); init_bank_rom(TMP,ROM); memset(RAM+0x00000, 0x00, RAMSize); memcpy(RAM, ROM, 0x8000+0x4000); AddZ80BROMBase(RAM, 0x0038, 0x0066); AddZ80BReadByte(0x0000, 0xBFFF, NULL, NULL); // Z80 ROM/BANK ROM AddZ80BReadByte(0xC000, 0xE7FF, NULL, RAM+0xC000); // RAM AddZ80BReadByte(0xE800, 0xE8FF, KSystemMCURead, NULL); // MCU COMM AREA AddZ80BReadByte(0xE900, 0xEFFF, NULL, RAM+0xE900); // RAM AddZ80BReadByte(0xF010, 0xF010, KSystemInputRead, NULL); // INPUT AddZ80BReadByte(0x0000, 0xFFFF, DefBadReadZ80, NULL); // <bad reads> AddZ80BReadByte(-1, -1, NULL, NULL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -