src/mame/machine/snes.c
| r6828 | r6829 | |
| 36 | 36 | static emu_timer *snes_hblank_timer; |
| 37 | 37 | static emu_timer *snes_nmi_timer; |
| 38 | 38 | static emu_timer *snes_hirq_timer; |
| 39 | static emu_timer *snes_div_timer; |
| 40 | static emu_timer *snes_mult_timer; |
| 39 | 41 | static UINT16 hblank_offset; |
| 40 | 42 | UINT16 snes_htmult; /* in 512 wide, we run HTOTAL double and halve it on latching */ |
| 41 | 43 | UINT8 snes_has_addon_chip; |
| r6828 | r6829 | |
| 294 | 296 | } |
| 295 | 297 | |
| 296 | 298 | |
| 299 | static TIMER_CALLBACK(snes_div_callback) |
| 300 | { |
| 301 | UINT16 value, dividend, remainder; |
| 302 | dividend = remainder = 0; |
| 303 | value = (snes_ram[WRDIVH] << 8) + snes_ram[WRDIVL]; |
| 304 | if( snes_ram[WRDVDD] > 0 ) |
| 305 | { |
| 306 | dividend = value / snes_ram[WRDVDD]; |
| 307 | remainder = value % snes_ram[WRDVDD]; |
| 308 | } |
| 309 | else |
| 310 | { |
| 311 | dividend = 0xffff; |
| 312 | remainder = value; |
| 313 | } |
| 314 | snes_ram[RDDIVL] = dividend & 0xff; |
| 315 | snes_ram[RDDIVH] = (dividend >> 8) & 0xff; |
| 316 | snes_ram[RDMPYL] = remainder & 0xff; |
| 317 | snes_ram[RDMPYH] = (remainder >> 8) & 0xff; |
| 318 | } |
| 319 | |
| 320 | |
| 321 | static TIMER_CALLBACK(snes_mult_callback) |
| 322 | { |
| 323 | UINT32 c = snes_ram[WRMPYA] * snes_ram[WRMPYB]; |
| 324 | snes_ram[RDMPYL] = c & 0xff; |
| 325 | snes_ram[RDMPYH] = (c >> 8) & 0xff; |
| 326 | } |
| 327 | |
| 328 | |
| 297 | 329 | /************************************* |
| 298 | 330 | |
| 299 | 331 | Input Handlers |
| r6828 | r6829 | |
| 1291 | 1323 | case WRMPYA: /* Multiplier A */ |
| 1292 | 1324 | break; |
| 1293 | 1325 | case WRMPYB: /* Multiplier B */ |
| 1294 | | { |
| 1295 | | UINT32 c = snes_ram[WRMPYA] * data; |
| 1296 | | snes_ram[RDMPYL] = c & 0xff; |
| 1297 | | snes_ram[RDMPYH] = (c >> 8) & 0xff; |
| 1298 | | } break; |
| 1326 | timer_adjust_oneshot(snes_mult_timer, cputag_clocks_to_attotime(space->machine, "maincpu", 8), 0); |
| 1327 | break; |
| 1299 | 1328 | case WRDIVL: /* Dividend (low) */ |
| 1300 | 1329 | case WRDIVH: /* Dividend (high) */ |
| 1301 | 1330 | break; |
| 1302 | 1331 | case WRDVDD: /* Divisor */ |
| 1303 | | { |
| 1304 | | UINT16 value, dividend, remainder; |
| 1305 | | dividend = remainder = 0; |
| 1306 | | value = (snes_ram[WRDIVH] << 8) + snes_ram[WRDIVL]; |
| 1307 | | if( data > 0 ) |
| 1308 | | { |
| 1309 | | dividend = value / data; |
| 1310 | | remainder = value % data; |
| 1311 | | } |
| 1312 | | else |
| 1313 | | { |
| 1314 | | dividend = 0xffff; |
| 1315 | | remainder = value; |
| 1316 | | } |
| 1317 | | snes_ram[RDDIVL] = dividend & 0xff; |
| 1318 | | snes_ram[RDDIVH] = (dividend >> 8) & 0xff; |
| 1319 | | snes_ram[RDMPYL] = remainder & 0xff; |
| 1320 | | snes_ram[RDMPYH] = (remainder >> 8) & 0xff; |
| 1321 | | } break; |
| 1332 | timer_adjust_oneshot(snes_div_timer, cputag_clocks_to_attotime(space->machine, "maincpu", 8), 0); |
| 1333 | break; |
| 1322 | 1334 | case HTIMEL: /* H-Count timer settings (low) */ |
| 1323 | 1335 | case HTIMEH: /* H-Count timer settings (high) */ |
| 1324 | 1336 | case VTIMEL: /* V-Count timer settings (low) */ |
| r6828 | r6829 | |
| 1983 | 1995 | timer_adjust_oneshot(snes_nmi_timer, attotime_never, 0); |
| 1984 | 1996 | snes_hirq_timer = timer_alloc(machine, snes_hirq_tick_callback, NULL); |
| 1985 | 1997 | timer_adjust_oneshot(snes_hirq_timer, attotime_never, 0); |
| 1998 | snes_div_timer = timer_alloc(machine, snes_div_callback, NULL); |
| 1999 | timer_adjust_oneshot(snes_div_timer, attotime_never, 0); |
| 2000 | snes_mult_timer = timer_alloc(machine, snes_mult_callback, NULL); |
| 2001 | timer_adjust_oneshot(snes_mult_timer, attotime_never, 0); |
| 1986 | 2002 | |
| 1987 | 2003 | // SNES hcounter has a 0-339 range. hblank starts at counter 260. |
| 1988 | 2004 | // clayfighter sets an HIRQ at 260, apparently it wants it to be before hdma kicks off, so we'll delay 2 pixels. |