Previous 15994 Revisions Next

r9287 Thursday 30th September, 2010 at 04:56:50 UTC by Angelo Salese
[32x]: Hooked up one word FIFO for PWM (still not right, but most games uses now the right frequency)
[src/mame/drivers]megadriv.c

src/mame/drivers/megadriv.c
r9286r9287
27622762/**********************************************************************************************/
27632763
27642764static UINT16 pwm_ctrl,pwm_cycle,pwm_tm_reg;
2765static UINT16 cur_lch,cur_rch;
27652766static UINT16 pwm_cycle_reg; //used for latching
2767static UINT8 pwm_timer_tick;
2768static UINT16 lch_fifo_state,rch_fifo_state;
2769
27662770static emu_timer *_32x_pwm_timer;
27672771
2772
27682773static void calculate_pwm_timer(void)
27692774{
27702775   if(pwm_tm_reg == 0) { pwm_tm_reg = 16; } // zero gives max range
r9286r9287
27742779   if(pwm_cycle == 1 || ((pwm_ctrl & 0xf) == 0))
27752780      timer_adjust_oneshot(_32x_pwm_timer, attotime_never, 0);
27762781   else
2777      timer_adjust_oneshot(_32x_pwm_timer, ATTOTIME_IN_HZ(((MASTER_CLOCK_NTSC*3 / 7) / (pwm_cycle - 1)) * pwm_tm_reg), 0);
2782   {
2783      pwm_timer_tick = 0;
2784      lch_fifo_state = rch_fifo_state = 0x4000;
2785      timer_adjust_oneshot(_32x_pwm_timer, ATTOTIME_IN_HZ(((MASTER_CLOCK_NTSC*3 / 7) / (pwm_cycle - 1))), 0);
2786   }
27782787}
27792788
27802789static TIMER_CALLBACK( _32x_pwm_callback )
27812790{
2782   // ...
2791   if(lch_fifo_state == 0x8000)
2792   {
2793      lch_fifo_state = 0x4000;
2794      dac_data_16_w(machine->device("lch_pwm"), cur_lch);
2795   }
2796   if(rch_fifo_state == 0x8000)
2797   {
2798      rch_fifo_state = 0x4000;
2799      dac_data_16_w(machine->device("rch_pwm"), cur_rch);
2800   }
27832801
2784   if(sh2_master_pwmint_enable) { cpu_set_input_line(_32x_master_cpu, SH2_PINT_IRQ_LEVEL,ASSERT_LINE); }
2802   pwm_timer_tick++;
27852803
2786   if(sh2_slave_pwmint_enable) { cpu_set_input_line(_32x_slave_cpu, SH2_PINT_IRQ_LEVEL,ASSERT_LINE); }
2804   if(pwm_timer_tick == pwm_tm_reg)
2805   {
2806      pwm_timer_tick = 0;
2807      if(sh2_master_pwmint_enable) { cpu_set_input_line(_32x_master_cpu, SH2_PINT_IRQ_LEVEL,ASSERT_LINE); }
2808      if(sh2_slave_pwmint_enable) { cpu_set_input_line(_32x_slave_cpu, SH2_PINT_IRQ_LEVEL,ASSERT_LINE); }
2809   }
27872810
2788   timer_adjust_oneshot(_32x_pwm_timer, ATTOTIME_IN_HZ(((MASTER_CLOCK_NTSC*3 / 7) / (pwm_cycle - 1)) * pwm_tm_reg), 0);
2811   timer_adjust_oneshot(_32x_pwm_timer, ATTOTIME_IN_HZ(((MASTER_CLOCK_NTSC*3 / 7) / (pwm_cycle - 1))), 0);
27892812}
27902813
27912814static READ16_HANDLER( _32x_pwm_r )
r9286r9287
27942817   {
27952818      case 0x00/2: return pwm_ctrl; //control register
27962819      case 0x02/2: return pwm_cycle_reg; // cycle register
2797      case 0x04/2: return mame_rand(space->machine) & 0xc000; // l ch TODO
2798      case 0x06/2: return mame_rand(space->machine) & 0xc000; // r ch TODO
2799      case 0x08/2: return mame_rand(space->machine) & 0xc000; // mono ch TODO
2820      case 0x04/2: return lch_fifo_state; // l ch
2821      case 0x06/2: return rch_fifo_state; // r ch
2822      case 0x08/2: return lch_fifo_state & rch_fifo_state; // mono ch
28002823   }
28012824
28022825   printf("Read at undefined PWM register %02x\n",offset);
r9286r9287
28172840         calculate_pwm_timer();
28182841         break;
28192842      case 0x04/2:
2820         dac_data_16_w(space->machine->device("lch_pwm"), ((data & 0xfff) << 4));
2843         cur_lch = ((data & 0xfff) << 4);
2844         lch_fifo_state = 0x8000;
28212845         break;
28222846      case 0x06/2:
2823         dac_data_16_w(space->machine->device("rch_pwm"), ((data & 0xfff) << 4));
2847         cur_rch = ((data & 0xfff) << 4);
2848         rch_fifo_state = 0x8000;
28242849         break;
28252850      case 0x08/2:
2826         dac_data_16_w(space->machine->device("lch_pwm"), ((data & 0xfff) << 4));
2827         dac_data_16_w(space->machine->device("rch_pwm"), ((data & 0xfff) << 4));
2851         cur_lch = ((data & 0xfff) << 4);
2852         cur_rch = ((data & 0xfff) << 4);
2853         lch_fifo_state = rch_fifo_state = 0x8000;
28282854         break;
28292855      default:
28302856         printf("Write at undefined PWM register %02x %04x\n",offset,data);

Previous 15994 Revisions Next


© 1998-2018 The MESS Team