src/mame/machine/snes.c
| r9420 | r9421 | |
| 48 | 48 | #include "machine/snesst10.c" |
| 49 | 49 | #include "machine/snesbsx.c" |
| 50 | 50 | |
| 51 | #define USE_CYCLE_STEAL 1 |
| 52 | |
| 51 | 53 | /************************************* |
| 52 | 54 | |
| 53 | 55 | Timers |
| r9420 | r9421 | |
| 844 | 846 | |
| 845 | 847 | */ |
| 846 | 848 | |
| 849 | #if USE_CYCLE_STEAL |
| 847 | 850 | /*FIXME: missing work RAM access steal / we need to do this less "aggressive" otherwise we lose too much CPU horsepower, why? */ |
| 848 | 851 | static int snes_bank_0x00_0x3f_cycles(running_machine *machine,UINT32 offset) |
| 849 | 852 | { |
| r9420 | r9421 | |
| 905 | 908 | |
| 906 | 909 | return 0; //TODO: 6 |
| 907 | 910 | } |
| 911 | #endif |
| 908 | 912 | |
| 909 | 913 | /* 0x000000 - 0x2fffff */ |
| 910 | 914 | READ8_HANDLER( snes_r_bank1 ) |
| r9420 | r9421 | |
| 957 | 961 | else |
| 958 | 962 | value = snes_ram[offset]; |
| 959 | 963 | |
| 964 | #if USE_CYCLE_STEAL |
| 960 | 965 | if(!space->debugger_access()) |
| 961 | 966 | cpu_adjust_icount(space->cpu, -snes_bank_0x00_0x3f_cycles(space->machine, offset)); |
| 967 | #endif |
| 962 | 968 | |
| 963 | 969 | return value; |
| 964 | 970 | } |
| r9420 | r9421 | |
| 1020 | 1026 | else |
| 1021 | 1027 | value = snes_ram[0x300000 + offset]; |
| 1022 | 1028 | |
| 1029 | #if USE_CYCLE_STEAL |
| 1023 | 1030 | if(!space->debugger_access()) |
| 1024 | 1031 | cpu_adjust_icount(space->cpu, -snes_bank_0x00_0x3f_cycles(space->machine, offset)); |
| 1032 | #endif |
| 1025 | 1033 | |
| 1026 | 1034 | return value; |
| 1027 | 1035 | } |
| r9420 | r9421 | |
| 1061 | 1069 | else /* Mode 21 & 25 + SuperFX games */ |
| 1062 | 1070 | value = snes_ram[0x400000 + offset]; |
| 1063 | 1071 | |
| 1072 | #if USE_CYCLE_STEAL |
| 1064 | 1073 | if(!space->debugger_access()) |
| 1065 | 1074 | cpu_adjust_icount(space->cpu, -8); |
| 1075 | #endif |
| 1066 | 1076 | |
| 1067 | 1077 | return value; |
| 1068 | 1078 | } |
| r9420 | r9421 | |
| 1099 | 1109 | else if (state->cart[0].mode & 0x0a) /* Mode 21 & 25 */ |
| 1100 | 1110 | value = snes_ram[0x600000 + offset]; |
| 1101 | 1111 | |
| 1112 | #if USE_CYCLE_STEAL |
| 1102 | 1113 | if(!space->debugger_access()) |
| 1103 | 1114 | cpu_adjust_icount(space->cpu, -8); |
| 1115 | #endif |
| 1104 | 1116 | |
| 1105 | 1117 | return value; |
| 1106 | 1118 | } |
| r9420 | r9421 | |
| 1135 | 1147 | else |
| 1136 | 1148 | value = snes_ram[0x700000 + offset]; |
| 1137 | 1149 | |
| 1150 | #if USE_CYCLE_STEAL |
| 1138 | 1151 | if(!space->debugger_access()) |
| 1139 | 1152 | cpu_adjust_icount(space->cpu, -8); |
| 1153 | #endif |
| 1140 | 1154 | |
| 1141 | 1155 | return value; |
| 1142 | 1156 | } |
| r9420 | r9421 | |
| 1183 | 1197 | else |
| 1184 | 1198 | value = snes_ram[0x800000 + offset]; |
| 1185 | 1199 | |
| 1200 | #if USE_CYCLE_STEAL |
| 1186 | 1201 | if(!space->debugger_access()) |
| 1187 | 1202 | cpu_adjust_icount(space->cpu, -snes_bank_0x80_0xbf_cycles(space->machine, offset)); |
| 1203 | #endif |
| 1188 | 1204 | |
| 1189 | 1205 | return value; |
| 1190 | 1206 | } |
| r9420 | r9421 | |
| 1236 | 1252 | else /* Mode 21 & 25 + SuperFX Games */ |
| 1237 | 1253 | value = snes_ram[0xc00000 + offset]; |
| 1238 | 1254 | |
| 1255 | #if USE_CYCLE_STEAL |
| 1239 | 1256 | if(!space->debugger_access()) |
| 1240 | 1257 | cpu_adjust_icount(space->cpu, -((snes_ram[MEMSEL] & 1) ? 6 : 8)); |
| 1258 | #endif |
| 1241 | 1259 | |
| 1242 | 1260 | return value; |
| 1243 | 1261 | } |
| r9420 | r9421 | |
| 1290 | 1308 | else |
| 1291 | 1309 | logerror( "(PC=%06x) Attempt to write to ROM address: %X\n",cpu_get_pc(space->cpu),offset ); |
| 1292 | 1310 | |
| 1311 | #if USE_CYCLE_STEAL |
| 1293 | 1312 | if(!space->debugger_access()) |
| 1294 | 1313 | cpu_adjust_icount(space->cpu, -snes_bank_0x00_0x3f_cycles(space->machine, offset)); |
| 1314 | #endif |
| 1295 | 1315 | } |
| 1296 | 1316 | |
| 1297 | 1317 | /* 0x300000 - 0x3fffff */ |
| r9420 | r9421 | |
| 1347 | 1367 | else |
| 1348 | 1368 | logerror("(PC=%06x) Attempt to write to ROM address: %X\n",cpu_get_pc(space->cpu),offset + 0x300000); |
| 1349 | 1369 | |
| 1370 | #if USE_CYCLE_STEAL |
| 1350 | 1371 | if(!space->debugger_access()) |
| 1351 | 1372 | cpu_adjust_icount(space->cpu, -snes_bank_0x00_0x3f_cycles(space->machine, offset)); |
| 1373 | #endif |
| 1352 | 1374 | } |
| 1353 | 1375 | |
| 1354 | 1376 | /* 0x600000 - 0x6fffff */ |
| r9420 | r9421 | |
| 1373 | 1395 | else if (state->cart[0].mode & 0x0a) |
| 1374 | 1396 | logerror("(PC=%06x) Attempt to write to ROM address: %X\n",cpu_get_pc(space->cpu),offset + 0x600000); |
| 1375 | 1397 | |
| 1398 | #if USE_CYCLE_STEAL |
| 1376 | 1399 | if(!space->debugger_access()) |
| 1377 | 1400 | cpu_adjust_icount(space->cpu, -8); |
| 1401 | #endif |
| 1378 | 1402 | } |
| 1379 | 1403 | |
| 1380 | 1404 | /* 0x700000 - 0x7dffff */ |
| r9420 | r9421 | |
| 1398 | 1422 | else if (state->cart[0].mode & 0x0a) |
| 1399 | 1423 | logerror("(PC=%06x) Attempt to write to ROM address: %X\n",cpu_get_pc(space->cpu),offset + 0x700000); |
| 1400 | 1424 | |
| 1425 | #if USE_CYCLE_STEAL |
| 1401 | 1426 | if(!space->debugger_access()) |
| 1402 | 1427 | cpu_adjust_icount(space->cpu, -8); |
| 1428 | #endif |
| 1403 | 1429 | } |
| 1404 | 1430 | |
| 1405 | 1431 | |
| r9420 | r9421 | |
| 1446 | 1472 | else |
| 1447 | 1473 | logerror("(PC=%06x) Attempt to write to ROM address: %X\n",cpu_get_pc(space->cpu),offset + 0x800000); |
| 1448 | 1474 | |
| 1475 | #if USE_CYCLE_STEAL |
| 1449 | 1476 | if(!space->debugger_access()) |
| 1450 | 1477 | cpu_adjust_icount(space->cpu, -snes_bank_0x80_0xbf_cycles(space->machine, offset)); |
| 1478 | #endif |
| 1451 | 1479 | } |
| 1452 | 1480 | |
| 1453 | 1481 | |
| r9420 | r9421 | |
| 1486 | 1514 | else if (state->cart[0].mode & 0x0a) |
| 1487 | 1515 | logerror("(PC=%06x) Attempt to write to ROM address: %X\n",cpu_get_pc(space->cpu),offset + 0xc00000); |
| 1488 | 1516 | |
| 1517 | #if USE_CYCLE_STEAL |
| 1489 | 1518 | if(!space->debugger_access()) |
| 1490 | 1519 | cpu_adjust_icount(space->cpu, -((snes_ram[MEMSEL] & 1) ? 6 : 8)); |
| 1520 | #endif |
| 1491 | 1521 | } |
| 1492 | 1522 | |
| 1493 | 1523 | |
| r9420 | r9421 | |
| 1597 | 1627 | |
| 1598 | 1628 | // SNES hcounter has a 0-339 range. hblank starts at counter 260. |
| 1599 | 1629 | // clayfighter sets an HIRQ at 260, apparently it wants it to be before hdma kicks off, so we'll delay 2 pixels. |
| 1600 | | state->hblank_offset = 268; |
| 1630 | state->hblank_offset = 274; |
| 1601 | 1631 | timer_adjust_oneshot(state->hblank_timer, machine->primary_screen->time_until_pos(((snes_ram[STAT78] & 0x10) == SNES_NTSC) ? SNES_VTOTAL_NTSC - 1 : SNES_VTOTAL_PAL - 1, state->hblank_offset), 0); |
| 1602 | 1632 | } |
| 1603 | 1633 | |
| r9420 | r9421 | |
| 1988 | 2018 | { |
| 1989 | 2019 | snes_state *state = space->machine->driver_data<snes_state>(); |
| 1990 | 2020 | |
| 2021 | #if USE_CYCLE_STEAL |
| 1991 | 2022 | /* every byte transfer takes 8 master cycles */ |
| 1992 | 2023 | cpu_adjust_icount(space->cpu,-8); |
| 2024 | #endif |
| 1993 | 2025 | |
| 1994 | 2026 | if (state->dma_channel[dma].dmap & 0x80) /* PPU->CPU */ |
| 1995 | 2027 | { |
| r9420 | r9421 | |
| 2197 | 2229 | |
| 2198 | 2230 | /* FIXME: we also need to round to the nearest 8 master cycles */ |
| 2199 | 2231 | |
| 2232 | #if USE_CYCLE_STEAL |
| 2200 | 2233 | /* overhead steals 8 master cycles, correct? */ |
| 2201 | 2234 | cpu_adjust_icount(space->cpu,-8); |
| 2235 | #endif |
| 2202 | 2236 | |
| 2203 | 2237 | /* Assume priority of the 8 DMA channels is 0-7 */ |
| 2204 | 2238 | for (i = 0; i < 8; i++) |
| r9420 | r9421 | |
| 2309 | 2343 | state->dma_channel[i].src_addr = abus; |
| 2310 | 2344 | state->dma_channel[i].trans_size = 0; |
| 2311 | 2345 | |
| 2346 | #if USE_CYCLE_STEAL |
| 2312 | 2347 | /* active channel takes 8 master cycles */ |
| 2313 | 2348 | cpu_adjust_icount(space->cpu,-8); |
| 2349 | #endif |
| 2314 | 2350 | } |
| 2315 | 2351 | } |
| 2316 | 2352 | |
| 2317 | 2353 | /* finally, take yet another 8 master cycles for the aforementioned overhead */ |
| 2354 | #if USE_CYCLE_STEAL |
| 2318 | 2355 | cpu_adjust_icount(space->cpu,-8); |
| 2356 | #endif |
| 2319 | 2357 | } |
| 2320 | 2358 | |
| 2321 | 2359 | READ8_HANDLER( superfx_r_bank1 ) |