Previous 15994 Revisions Next

r6829 Wednesday 30th December, 2009 at 18:34:28 UTC by Wilbert Pol
[SNES] Hardware multiplication and division takes 8 machine cycles to complete.
[src/mame/machine]snes.c

src/mame/machine/snes.c
r6828r6829
3636static emu_timer *snes_hblank_timer;
3737static emu_timer *snes_nmi_timer;
3838static emu_timer *snes_hirq_timer;
39static emu_timer *snes_div_timer;
40static emu_timer *snes_mult_timer;
3941static UINT16 hblank_offset;
4042UINT16 snes_htmult;   /* in 512 wide, we run HTOTAL double and halve it on latching */
4143UINT8 snes_has_addon_chip;
r6828r6829
294296}
295297
296298
299static 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
321static 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
297329/*************************************
298330
299331    Input Handlers
r6828r6829
12911323      case WRMPYA:   /* Multiplier A */
12921324         break;
12931325      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;
12991328      case WRDIVL:   /* Dividend (low) */
13001329      case WRDIVH:   /* Dividend (high) */
13011330         break;
13021331      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;
13221334      case HTIMEL:   /* H-Count timer settings (low)  */
13231335      case HTIMEH:   /* H-Count timer settings (high) */
13241336      case VTIMEL:   /* V-Count timer settings (low)  */
r6828r6829
19831995   timer_adjust_oneshot(snes_nmi_timer, attotime_never, 0);
19841996   snes_hirq_timer = timer_alloc(machine, snes_hirq_tick_callback, NULL);
19851997   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);
19862002
19872003   // SNES hcounter has a 0-339 range.  hblank starts at counter 260.
19882004   // clayfighter sets an HIRQ at 260, apparently it wants it to be before hdma kicks off, so we'll delay 2 pixels.

Previous 15994 Revisions Next


© 1998-2018 The MESS Team