| 1 | /* FCE Ultra - NES/Famicom Emulator\r |
| 2 | *\r |
| 3 | * Copyright notice for this file:\r |
| 4 | * Copyright (C) 2002 CaH4e3\r |
| 5 | *\r |
| 6 | * This program is free software; you can redistribute it and/or modify\r |
| 7 | * it under the terms of the GNU General Public License as published by\r |
| 8 | * the Free Software Foundation; either version 2 of the License, or\r |
| 9 | * (at your option) any later version.\r |
| 10 | *\r |
| 11 | * This program is distributed in the hope that it will be useful,\r |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of\r |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r |
| 14 | * GNU General Public License for more details.\r |
| 15 | *\r |
| 16 | * You should have received a copy of the GNU General Public License\r |
| 17 | * along with this program; if not, write to the Free Software\r |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\r |
| 19 | */\r |
| 20 | \r |
| 21 | #include "mapinc.h"\r |
| 22 | \r |
| 23 | #define CARD_EXTERNAL_INSERED 0x80\r |
| 24 | \r |
| 25 | static uint8 prg_reg;\r |
| 26 | static uint8 chr_reg;\r |
| 27 | static SFORMAT StateRegs[]=\r |
| 28 | {\r |
| 29 | {&prg_reg, 1, "PREG"},\r |
| 30 | {&chr_reg, 1, "CREG"},\r |
| 31 | {0}\r |
| 32 | };\r |
| 33 | \r |
| 34 | /*\r |
| 35 | \r |
| 36 | _GET_CHALLENGE: .BYTE 0,$B4, 0, 0,$62\r |
| 37 | \r |
| 38 | _SELECT_FILE_1_0200: .BYTE 0,$A4, 1, 0, 2, 2, 0\r |
| 39 | _SELECT_FILE_2_0201: .BYTE 0,$A4, 2, 0, 2, 2, 1\r |
| 40 | _SELECT_FILE_2_0203: .BYTE 0,$A4, 2, 0, 2, 2, 3\r |
| 41 | _SELECT_FILE_2_0204: .BYTE 0,$A4, 2, 0, 2, 2, 4\r |
| 42 | _SELECT_FILE_2_0205: .BYTE 0,$A4, 2, 0, 2, 2, 5\r |
| 43 | _SELECT_FILE_2_3F04: .BYTE 0,$A4, 2, 0, 2,$3F, 4\r |
| 44 | _SELECT_FILE_2_4F00: .BYTE 0,$A4, 2, 0, 2,$4F, 0\r |
| 45 | \r |
| 46 | _READ_BINARY_5: .BYTE 0,$B0,$85, 0, 2\r |
| 47 | _READ_BINARY_6: .BYTE 0,$B0,$86, 0, 4\r |
| 48 | _READ_BINARY_6_0: .BYTE 0,$B0,$86, 0,$18\r |
| 49 | _READ_BINARY_0: .BYTE 0,$B0, 0, 2, 3\r |
| 50 | _READ_BINARY_0_0: .BYTE 0,$B0, 0, 0, 4\r |
| 51 | _READ_BINARY_0_1: .BYTE 0,$B0, 0, 0, $C\r |
| 52 | _READ_BINARY_0_2: .BYTE 0,$B0, 0, 0,$10\r |
| 53 | \r |
| 54 | _UPDATE_BINARY: .BYTE 0,$D6, 0, 0, 4\r |
| 55 | _UPDATE_BINARY_0: .BYTE 0,$D6, 0, 0,$10\r |
| 56 | \r |
| 57 | _GET_RESPONSE: .BYTE $80,$C0, 2,$A1, 8\r |
| 58 | _GET_RESPONSE_0: .BYTE 0,$C0, 0, 0, 2\r |
| 59 | _GET_RESPONSE_1: .BYTE 0,$C0, 0, 0, 6\r |
| 60 | _GET_RESPONSE_2: .BYTE 0,$C0, 0, 0, 8\r |
| 61 | _GET_RESPONSE_3: .BYTE 0,$C0, 0, 0, $C\r |
| 62 | _GET_RESPONSE_4: .BYTE 0,$C0, 0, 0,$10\r |
| 63 | \r |
| 64 | byte_8C0B: .BYTE $80,$30, 0, 2, $A, 0, 1\r |
| 65 | byte_8C48: .BYTE $80,$32, 0, 1, 4\r |
| 66 | byte_8C89: .BYTE $80,$34, 0, 0, 8, 0, 0\r |
| 67 | byte_8D01: .BYTE $80,$36, 0, 0, $C\r |
| 68 | byte_8CA7: .BYTE $80,$38, 0, 2, 4\r |
| 69 | byte_8BEC: .BYTE $80,$3A, 0, 3, 0\r |
| 70 | \r |
| 71 | byte_89A0: .BYTE 0,$48, 0, 0, 6\r |
| 72 | byte_8808: .BYTE 0,$54, 0, 0,$1C\r |
| 73 | byte_89BF: .BYTE 0,$58, 0, 0,$1C\r |
| 74 | \r |
| 75 | _MANAGE_CHANNEL: .BYTE 0,$70, 0, 0, 8\r |
| 76 | byte_8CE5: .BYTE 0,$74, 0, 0,$12\r |
| 77 | byte_8C29: .BYTE 0,$76, 0, 0, 8\r |
| 78 | byte_8CC6: .BYTE 0,$78, 0, 0,$12\r |
| 79 | */\r |
| 80 | \r |
| 81 | static uint8 sim0reset[0x1F] = { 0x3B, 0xE9, 0x00, 0xFF, 0xC1, 0x10, 0x31, 0xFE,\r |
| 82 | 0x55, 0xC8, 0x10, 0x20, 0x55, 0x47, 0x4F, 0x53,\r |
| 83 | 0x56, 0x53, 0x43, 0xAD, 0x10, 0x10, 0x10, 0x10,\r |
| 84 | 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 }; \r |
| 85 | \r |
| 86 | static void Sync(void)\r |
| 87 | {\r |
| 88 | setprg32(0x8000, prg_reg);\r |
| 89 | setchr8(chr_reg);\r |
| 90 | }\r |
| 91 | \r |
| 92 | static void StateRestore(int version)\r |
| 93 | {\r |
| 94 | Sync();\r |
| 95 | }\r |
| 96 | \r |
| 97 | static DECLFW(M216WriteHi)\r |
| 98 | {\r |
| 99 | prg_reg=A&1;\r |
| 100 | chr_reg=(A&0x0E)>>1;\r |
| 101 | Sync();\r |
| 102 | }\r |
| 103 | \r |
| 104 | static DECLFW(M216Write5000)\r |
| 105 | {\r |
| 106 | // FCEU_printf("WRITE: %04x:%04x (PC=%02x cnt=%02x)\n",A,V,X.PC,sim0bcnt);\r |
| 107 | }\r |
| 108 | \r |
| 109 | static DECLFR(M216Read5000)\r |
| 110 | {\r |
| 111 | // FCEU_printf("READ: %04x PC=%04x out=%02x byte=%02x cnt=%02x bit=%02x\n",A,X.PC,sim0out,sim0byte,sim0bcnt,sim0bit);\r |
| 112 | return 0;\r |
| 113 | }\r |
| 114 | \r |
| 115 | static void Power(void)\r |
| 116 | {\r |
| 117 | prg_reg = 0;\r |
| 118 | chr_reg = 0;\r |
| 119 | Sync();\r |
| 120 | SetReadHandler(0x8000,0xFFFF,CartBR);\r |
| 121 | SetWriteHandler(0x8000,0xFFFF,M216WriteHi);\r |
| 122 | SetWriteHandler(0x5000,0x5000,M216Write5000);\r |
| 123 | SetReadHandler(0x5000,0x5000,M216Read5000);\r |
| 124 | }\r |
| 125 | \r |
| 126 | \r |
| 127 | void Mapper216_Init(CartInfo *info)\r |
| 128 | {\r |
| 129 | info->Power=Power;\r |
| 130 | GameStateRestore=StateRestore;\r |
| 131 | AddExState(&StateRegs, ~0, 0, 0);\r |
| 132 | }\r |