src/mess/machine/nes_pcb.c
| r8291 | r8292 | |
| 320 | 320 | { "IREM-H-3001", IREM_H3001 }, |
| 321 | 321 | { "IREM-HOLYDIVER", IREM_HOLYDIV }, |
| 322 | 322 | { "IREM-TAM-S1", IREM_TAM_S1 }, |
| 323 | | /* FIXME: Made up boards the different mirroring handling */ |
| 324 | | { "IREM-G101-A", IREM_G101_A }, |
| 325 | 323 | // |
| 326 | 324 | { "JALECO-JF-23", JALECO_SS88006 }, |
| 327 | 325 | { "JALECO-JF-24", JALECO_SS88006 }, |
| r8291 | r8292 | |
| 832 | 830 | |
| 833 | 831 | switch (board) |
| 834 | 832 | { |
| 835 | | case STD_SOROM: // there are 2 WRAM banks only and battery is bank 2 for the cart (hence, we invert bank, because we have battery first) |
| 836 | | if (!BIT(state->mmc_reg[3], 4)) |
| 837 | | memory_install_readwrite_bank(space, 0x6000, 0x7fff, 0, 0, "bank5"); |
| 838 | | else |
| 839 | | memory_unmap_readwrite(space, 0x6000, 0x7fff, 0, 0); |
| 840 | | wram_bank(machine, 0, bank ? NES_BATTERY : NES_WRAM); |
| 841 | | break; |
| 842 | 833 | case STD_SXROM: // here also reads are disabled! |
| 843 | 834 | if (!BIT(state->mmc_reg[3], 4)) |
| 844 | 835 | memory_install_readwrite_bank(space, 0x6000, 0x7fff, 0, 0, "bank5"); |
| 845 | 836 | else |
| 837 | { |
| 846 | 838 | memory_unmap_readwrite(space, 0x6000, 0x7fff, 0, 0); |
| 839 | break; |
| 840 | } |
| 847 | 841 | case STD_SXROM_A: // ignore WRAM enable bit |
| 848 | 842 | if (state->battery_size > 0x2000) |
| 849 | 843 | wram_bank(machine, ((state->mmc_reg[1] & 3) >> 2), NES_BATTERY); |
| 850 | 844 | else |
| 851 | 845 | wram_bank(machine, 0, NES_BATTERY); |
| 852 | 846 | break; |
| 847 | case STD_SOROM: // there are 2 WRAM banks only and battery is bank 2 for the cart (hence, we invert bank, because we have battery first) |
| 848 | if (!BIT(state->mmc_reg[3], 4)) |
| 849 | memory_install_readwrite_bank(space, 0x6000, 0x7fff, 0, 0, "bank5"); |
| 850 | else |
| 851 | { |
| 852 | memory_unmap_readwrite(space, 0x6000, 0x7fff, 0, 0); |
| 853 | break; |
| 854 | } |
| 855 | case STD_SOROM_A: // ignore WRAM enable bit |
| 856 | wram_bank(machine, 0, bank ? NES_BATTERY : NES_WRAM); |
| 857 | break; |
| 853 | 858 | } |
| 854 | 859 | } |
| 855 | 860 | |
| r8291 | r8292 | |
| 973 | 978 | |
| 974 | 979 | static WRITE8_HANDLER( sxrom_w ) |
| 975 | 980 | { |
| 981 | nes_state *state = (nes_state *)space->machine->driver_data; |
| 982 | |
| 976 | 983 | LOG_MMC(("sxrom_w, offset: %04x, data: %02x\n", offset, data)); |
| 977 | | common_sxrom_write_handler(space, offset, data, STD_SXROM); |
| 984 | common_sxrom_write_handler(space, offset, data, state->pcb_id); |
| 978 | 985 | } |
| 979 | 986 | |
| 980 | | static WRITE8_HANDLER( sxrom_a_w ) |
| 981 | | { |
| 982 | | LOG_MMC(("sxrom_a_w, offset: %04x, data: %02x\n", offset, data)); |
| 983 | | common_sxrom_write_handler(space, offset, data, STD_SXROM_A); |
| 984 | | } |
| 985 | | |
| 986 | | static WRITE8_HANDLER( sorom_w ) |
| 987 | | { |
| 988 | | LOG_MMC(("sorom_w, offset: %04x, data: %02x\n", offset, data)); |
| 989 | | common_sxrom_write_handler(space, offset, data, STD_SOROM); |
| 990 | | } |
| 991 | | |
| 992 | 987 | /************************************************************* |
| 993 | 988 | |
| 994 | 989 | PxROM (MMC2 based) board emulation |
| r8291 | r8292 | |
| 1094 | 1089 | |
| 1095 | 1090 | *************************************************************/ |
| 1096 | 1091 | |
| 1092 | static void mmc3_set_wram( const address_space *space ) |
| 1093 | { |
| 1094 | running_machine *machine = space->machine; |
| 1095 | nes_state *state = (nes_state *)machine->driver_data; |
| 1096 | |
| 1097 | if (BIT(state->mmc_latch2, 7)) |
| 1098 | memory_install_readwrite_bank(space, 0x6000, 0x7fff, 0, 0, "bank5"); |
| 1099 | else |
| 1100 | { |
| 1101 | memory_unmap_readwrite(space, 0x6000, 0x7fff, 0, 0); |
| 1102 | return; |
| 1103 | } |
| 1104 | |
| 1105 | if (BIT(state->mmc_latch2, 6)) |
| 1106 | memory_install_write_bank(space, 0x6000, 0x7fff, 0, 0, "bank5"); |
| 1107 | else |
| 1108 | { |
| 1109 | memory_unmap_write(space, 0x6000, 0x7fff, 0, 0); |
| 1110 | return; |
| 1111 | } |
| 1112 | |
| 1113 | wram_bank(machine, 0, state->battery_size ? NES_BATTERY : NES_WRAM); |
| 1114 | } |
| 1115 | |
| 1097 | 1116 | static void mmc3_set_prg( running_machine *machine, int prg_base, int prg_mask ) |
| 1098 | 1117 | { |
| 1099 | 1118 | nes_state *state = (nes_state *)machine->driver_data; |
| r8291 | r8292 | |
| 1128 | 1147 | if (scanline < PPU_BOTTOM_VISIBLE_SCANLINE) |
| 1129 | 1148 | { |
| 1130 | 1149 | int priorCount = state->IRQ_count; |
| 1131 | | if ((state->IRQ_count == 0)) |
| 1132 | | { |
| 1150 | if ((state->IRQ_count == 0) || state->IRQ_clear) |
| 1133 | 1151 | state->IRQ_count = state->IRQ_count_latch; |
| 1134 | | } |
| 1135 | 1152 | else |
| 1136 | 1153 | state->IRQ_count--; |
| 1137 | 1154 | |
| 1138 | | if (state->IRQ_enable && !blanked && (state->IRQ_count == 0) && priorCount) |
| 1155 | if (state->IRQ_enable && !blanked && (state->IRQ_count == 0) && (priorCount || state->IRQ_clear || !state->mmc3_alt_irq)) |
| 1139 | 1156 | { |
| 1140 | 1157 | LOG_MMC(("irq fired, scanline: %d (MAME %d, beam pos: %d)\n", scanline, |
| 1141 | 1158 | video_screen_get_vpos(device->machine->primary_screen), video_screen_get_hpos(device->machine->primary_screen))); |
| 1142 | 1159 | cpu_set_input_line(state->maincpu, M6502_IRQ_LINE, HOLD_LINE); |
| 1143 | 1160 | } |
| 1144 | 1161 | } |
| 1162 | state->IRQ_clear = 0; |
| 1145 | 1163 | } |
| 1146 | 1164 | |
| 1147 | 1165 | static WRITE8_HANDLER( txrom_w ) |
| 1148 | 1166 | { |
| 1149 | 1167 | nes_state *state = (nes_state *)space->machine->driver_data; |
| 1150 | | UINT8 MMC3_helper, cmd; |
| 1168 | UINT8 mmc3_helper, cmd; |
| 1151 | 1169 | |
| 1152 | 1170 | LOG_MMC(("txrom_w, offset: %04x, data: %02x\n", offset, data)); |
| 1153 | 1171 | |
| 1154 | 1172 | switch (offset & 0x6001) |
| 1155 | 1173 | { |
| 1156 | 1174 | case 0x0000: |
| 1157 | | MMC3_helper = state->mmc_latch1 ^ data; |
| 1175 | mmc3_helper = state->mmc_latch1 ^ data; |
| 1158 | 1176 | state->mmc_latch1 = data; |
| 1159 | 1177 | |
| 1160 | 1178 | /* Has PRG Mode changed? */ |
| 1161 | | if (MMC3_helper & 0x40) |
| 1179 | if (mmc3_helper & 0x40) |
| 1162 | 1180 | mmc3_set_prg(space->machine, state->mmc_prg_base, state->mmc_prg_mask); |
| 1163 | 1181 | |
| 1164 | 1182 | /* Has CHR Mode changed? */ |
| 1165 | | if (MMC3_helper & 0x80) |
| 1183 | if (mmc3_helper & 0x80) |
| 1166 | 1184 | mmc3_set_chr(space->machine, state->mmc_chr_source, state->mmc_chr_base, state->mmc_chr_mask); |
| 1167 | 1185 | break; |
| 1168 | 1186 | |
| r8291 | r8292 | |
| 1187 | 1205 | set_nt_mirroring(space->machine, BIT(data, 0) ? PPU_MIRROR_HORZ : PPU_MIRROR_VERT); |
| 1188 | 1206 | break; |
| 1189 | 1207 | |
| 1190 | | case 0x2001: /* extra RAM enable/disable */ |
| 1191 | | state->mmc_latch2 = data; /* This actually is made of two parts: data&0x80 = WRAM enabled and data&0x40 = WRAM readonly! */ |
| 1192 | | if (data) |
| 1193 | | memory_install_write_bank(space, 0x6000, 0x7fff, 0, 0, "bank5"); |
| 1194 | | else |
| 1195 | | memory_unmap_write(space, 0x6000, 0x7fff, 0, 0); |
| 1208 | case 0x2001: |
| 1209 | state->mmc_latch2 = data; |
| 1210 | mmc3_set_wram(space); |
| 1196 | 1211 | break; |
| 1197 | 1212 | |
| 1198 | 1213 | case 0x4000: |
| 1199 | 1214 | state->IRQ_count_latch = data; |
| 1200 | 1215 | break; |
| 1201 | 1216 | |
| 1202 | | case 0x4001: /* some sources state that here we must have state->IRQ_count = state->IRQ_count_latch */ |
| 1217 | case 0x4001: |
| 1203 | 1218 | state->IRQ_count = 0; |
| 1204 | 1219 | break; |
| 1205 | 1220 | |
| r8291 | r8292 | |
| 1225 | 1240 | |
| 1226 | 1241 | *************************************************************/ |
| 1227 | 1242 | |
| 1243 | static WRITE8_HANDLER( hkrom_m_w ) |
| 1244 | { |
| 1245 | nes_state *state = (nes_state *)space->machine->driver_data; |
| 1246 | UINT8 write_hi, write_lo; |
| 1247 | LOG_MMC(("hkrom_m_w, offset: %04x, data: %02x\n", offset, data)); |
| 1248 | |
| 1249 | if (offset < 0x1000) |
| 1250 | return; |
| 1251 | |
| 1252 | offset &= 0x3ff; |
| 1253 | // banks can be written only if both read & write is enabled! |
| 1254 | write_hi = ((state->mmc6_reg & 0xc0) == 0xc0); |
| 1255 | write_lo = ((state->mmc6_reg & 0x60) == 0x60); |
| 1256 | |
| 1257 | if (BIT(offset, 9) && write_hi) // access to upper 1k |
| 1258 | state->battery_ram[offset] = data; |
| 1259 | |
| 1260 | if (!BIT(offset, 9) && write_lo) // access to lower 1k |
| 1261 | state->battery_ram[offset] = data; |
| 1262 | } |
| 1263 | |
| 1264 | static READ8_HANDLER( hkrom_m_r ) |
| 1265 | { |
| 1266 | nes_state *state = (nes_state *)space->machine->driver_data; |
| 1267 | LOG_MMC(("hkrom_m_r, offset: %04x\n", offset)); |
| 1268 | |
| 1269 | if (offset < 0x1000) |
| 1270 | return 0xff; // here it should be open bus |
| 1271 | |
| 1272 | if (!(state->mmc6_reg & 0xa0)) |
| 1273 | return 0xff; // here it should be open bus |
| 1274 | |
| 1275 | offset &= 0x3ff; |
| 1276 | |
| 1277 | if (BIT(offset, 9) && BIT(state->mmc6_reg, 7)) // access to upper 1k when upper read is enabled |
| 1278 | return state->battery_ram[offset]; |
| 1279 | |
| 1280 | if (!BIT(offset, 9) && BIT(state->mmc6_reg, 5)) // access to lower 1k when lower read is enabled |
| 1281 | return state->battery_ram[offset]; |
| 1282 | |
| 1283 | // If only one bank is enabled for reading, the other reads back as zero |
| 1284 | return 0x00; |
| 1285 | } |
| 1286 | |
| 1228 | 1287 | static WRITE8_HANDLER( hkrom_w ) |
| 1229 | 1288 | { |
| 1289 | nes_state *state = (nes_state *)space->machine->driver_data; |
| 1290 | UINT8 mmc6_helper; |
| 1230 | 1291 | LOG_MMC(("hkrom_w, offset: %04x, data: %02x\n", offset, data)); |
| 1231 | | /* what are the differences MMC6 vs. MMC3? */ |
| 1232 | | txrom_w(space, offset, data); |
| 1292 | |
| 1293 | switch (offset & 0x6001) |
| 1294 | { |
| 1295 | case 0x0000: |
| 1296 | mmc6_helper = state->mmc_cmd1 ^ data; |
| 1297 | state->mmc_latch1 = data; |
| 1298 | |
| 1299 | if (!state->mmc_latch2 && BIT(data, 5)) // if WRAM is disabled and has to be enabled, write |
| 1300 | state->mmc_latch2 = BIT(data, 5); // (once WRAM has been enabled, it cannot be disabled without resetting the game) |
| 1301 | |
| 1302 | /* Has PRG Mode changed? */ |
| 1303 | if (BIT(mmc6_helper, 6)) |
| 1304 | mmc3_set_prg(space->machine, state->mmc_prg_base, state->mmc_prg_mask); |
| 1305 | |
| 1306 | /* Has CHR Mode changed? */ |
| 1307 | if (BIT(mmc6_helper, 7)) |
| 1308 | mmc3_set_chr(space->machine, state->mmc_chr_source, state->mmc_chr_base, state->mmc_chr_mask); |
| 1309 | break; |
| 1310 | |
| 1311 | case 0x2001: |
| 1312 | if (state->mmc_latch2) |
| 1313 | state->mmc6_reg = data; |
| 1314 | break; |
| 1315 | |
| 1316 | case 0x4001: |
| 1317 | state->IRQ_count = 0; |
| 1318 | state->IRQ_clear = 1; |
| 1319 | break; |
| 1320 | |
| 1321 | default: |
| 1322 | txrom_w(space, offset, data); |
| 1323 | break; |
| 1324 | } |
| 1233 | 1325 | } |
| 1234 | 1326 | |
| 1235 | 1327 | /************************************************************* |
| r8291 | r8292 | |
| 1286 | 1378 | case 0x0001: |
| 1287 | 1379 | cmd = state->mmc_latch1 & 0x07; |
| 1288 | 1380 | switch (cmd) |
| 1289 | | { |
| 1381 | { |
| 1290 | 1382 | case 0: case 1: |
| 1291 | 1383 | case 2: case 3: case 4: case 5: |
| 1292 | 1384 | state->mmc_vrom_bank[cmd] = data; |
| r8291 | r8292 | |
| 1298 | 1390 | state->mmc_prg_bank[cmd - 6] = data; |
| 1299 | 1391 | mmc3_set_prg(space->machine, state->mmc_prg_base, state->mmc_prg_mask); |
| 1300 | 1392 | break; |
| 1301 | | } |
| 1393 | } |
| 1302 | 1394 | break; |
| 1303 | 1395 | |
| 1304 | 1396 | case 0x2000: |
| r8291 | r8292 | |
| 10258 | 10350 | { SUNSOFT_DCS, NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(ntbrom_w), NULL, NULL, NULL }, |
| 10259 | 10351 | { STD_JXROM, NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(jxrom_w), NULL, NULL, jxrom_irq }, |
| 10260 | 10352 | { STD_SXROM, NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sxrom_w), NULL, NULL, NULL }, |
| 10261 | | { STD_SXROM_A, NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sxrom_a_w), NULL, NULL, NULL }, |
| 10262 | | { STD_SOROM, NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sorom_w), NULL, NULL, NULL }, |
| 10353 | { STD_SOROM, NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sxrom_w), NULL, NULL, NULL }, |
| 10354 | { STD_SXROM_A, NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sxrom_w), NULL, NULL, NULL }, |
| 10355 | { STD_SOROM_A, NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(sxrom_w), NULL, NULL, NULL }, |
| 10263 | 10356 | { STD_TXROM, NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(txrom_w), NULL, NULL, mmc3_irq }, |
| 10264 | | { STD_HKROM, NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(hkrom_w), NULL, NULL, mmc3_irq }, |
| 10357 | { STD_HKROM, NES_NOACCESS, {hkrom_m_w, hkrom_m_r}, NES_WRITEONLY(hkrom_w), NULL, NULL, mmc3_irq }, |
| 10265 | 10358 | { STD_TQROM, NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(tqrom_w), NULL, NULL, mmc3_irq }, |
| 10266 | 10359 | { STD_TXSROM, NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(txsrom_w), NULL, NULL, mmc3_irq }, |
| 10267 | 10360 | { STD_DXROM, NES_NOACCESS, NES_NOACCESS, NES_WRITEONLY(dxrom_w), NULL, NULL, NULL }, |
src/mess/machine/nes.c
| r8291 | r8292 | |
| 149 | 149 | |
| 150 | 150 | // there are still some quirk about writes to bank5... I hope to fix them soon. (mappers 34,45,52,246 have both mid_w and WRAM-->check) |
| 151 | 151 | if (state->mmc_write_mid) |
| 152 | | memory_install_write8_handler(space, 0x6000, 0x7fff, 0, 0, nes_mid_mapper_w); |
| 153 | | // memory_install_read8_handler(space, 0x6000, 0x7fff, 0, 0, nes_mid_mapper_r); |
| 154 | | memory_install_write8_handler(space, 0x8000, 0xffff, 0, 0, nes_mapper_w); |
| 155 | | // memory_install_read8_handler(space, 0x8000, 0xffff, 0, 0, nes_mapper_r); |
| 152 | memory_install_write8_handler(space, 0x6000, 0x7fff, 0, 0, state->mmc_write_mid); |
| 153 | if (state->mmc_write) |
| 154 | memory_install_write8_handler(space, 0x8000, 0xffff, 0, 0, state->mmc_write); |
| 155 | |
| 156 | // In fact, we also allow single pcbs to overwrite the bank read handlers defined above, |
| 157 | // because some pcbs (mainly pirate ones) require protection values to be read instead of |
| 158 | // the expected ROM banks: these handlers, though, must take care of the ROM access as well |
| 159 | if (state->mmc_read_mid) |
| 160 | memory_install_read8_handler(space, 0x6000, 0x7fff, 0, 0, state->mmc_read_mid); |
| 161 | if (state->mmc_read) |
| 162 | memory_install_read8_handler(space, 0x8000, 0xffff, 0, 0, state->mmc_read); |
| 156 | 163 | break; |
| 157 | 164 | } |
| 158 | 165 | |
| r8291 | r8292 | |
| 680 | 687 | logerror("NES: No extrainfo found\n"); |
| 681 | 688 | } |
| 682 | 689 | |
| 683 | | state->hard_mirroring = local_options & 0x01; |
| 690 | state->hard_mirroring = (local_options & 0x01) ? PPU_MIRROR_VERT : PPU_MIRROR_HORZ; |
| 684 | 691 | // printf("%d\n", state->hard_mirroring); |
| 685 | 692 | state->battery = local_options & 0x02; |
| 686 | 693 | state->trainer = local_options & 0x04; |
| r8291 | r8292 | |
| 1158 | 1165 | if (image_get_feature(image, "mirroring") != NULL) |
| 1159 | 1166 | { |
| 1160 | 1167 | const char *mirroring = image_get_feature(image, "mirroring"); |
| 1161 | | if (strcmp(mirroring, "horizontal") == 0) |
| 1162 | | state->hard_mirroring = 0; |
| 1163 | | if (strcmp(mirroring, "vertical") == 0) |
| 1164 | | state->hard_mirroring = 1; |
| 1168 | if (!strcmp(mirroring, "horizontal")) |
| 1169 | state->hard_mirroring = PPU_MIRROR_HORZ; |
| 1170 | if (!strcmp(mirroring, "vertical")) |
| 1171 | state->hard_mirroring = PPU_MIRROR_VERT; |
| 1172 | if (!strcmp(mirroring, "high")) |
| 1173 | state->hard_mirroring = PPU_MIRROR_HIGH; |
| 1174 | if (!strcmp(mirroring, "low")) |
| 1175 | state->hard_mirroring = PPU_MIRROR_LOW; |
| 1165 | 1176 | } |
| 1166 | 1177 | |
| 1167 | 1178 | state->chr_open_bus = 0; |
| r8291 | r8292 | |
| 1215 | 1226 | } |
| 1216 | 1227 | |
| 1217 | 1228 | /* Check for other misc board variants */ |
| 1218 | | if (state->pcb_id == STD_SXROM || state->pcb_id == STD_SOROM) |
| 1219 | | { |
| 1220 | | if (!strcmp(image_get_feature(image, "mmc1_type"), "MMC1A")) // in MMC1-A PRG RAM is always enabled |
| 1221 | | state->pcb_id = STD_SXROM_A; |
| 1222 | | } |
| 1229 | if (state->pcb_id == STD_SOROM && !strcmp(image_get_feature(image, "mmc1_type"), "MMC1A")) |
| 1230 | state->pcb_id = STD_SOROM_A; // in MMC1-A PRG RAM is always enabled |
| 1223 | 1231 | |
| 1232 | if (state->pcb_id == STD_SXROM && !strcmp(image_get_feature(image, "mmc1_type"), "MMC1A")) |
| 1233 | state->pcb_id = STD_SXROM_A; // in MMC1-A PRG RAM is always enabled |
| 1234 | |
| 1235 | if (state->pcb_id == IREM_G101 && !strcmp(image_get_feature(image, "mirroring"), "high")) |
| 1236 | state->pcb_id = IREM_G101_A; |
| 1237 | |
| 1224 | 1238 | if (state->pcb_id == STD_NXROM || state->pcb_id == SUNSOFT_DCS) |
| 1225 | 1239 | { |
| 1226 | 1240 | if (image_get_software_region(image, "minicart") != NULL) // check for dual minicart |
| r8291 | r8292 | |
| 1230 | 1244 | } |
| 1231 | 1245 | } |
| 1232 | 1246 | |
| 1233 | | |
| 1234 | 1247 | #if 1 |
| 1235 | 1248 | printf("PCB Feature: %s\n", image_get_feature(image, "pcb")); |
| 1236 | 1249 | printf("PRG chunks: %d\n", state->prg_chunks); |