src/mame/drivers/megadriv.c
| r9286 | r9287 | |
| 2762 | 2762 | /**********************************************************************************************/ |
| 2763 | 2763 | |
| 2764 | 2764 | static UINT16 pwm_ctrl,pwm_cycle,pwm_tm_reg; |
| 2765 | static UINT16 cur_lch,cur_rch; |
| 2765 | 2766 | static UINT16 pwm_cycle_reg; //used for latching |
| 2767 | static UINT8 pwm_timer_tick; |
| 2768 | static UINT16 lch_fifo_state,rch_fifo_state; |
| 2769 | |
| 2766 | 2770 | static emu_timer *_32x_pwm_timer; |
| 2767 | 2771 | |
| 2772 | |
| 2768 | 2773 | static void calculate_pwm_timer(void) |
| 2769 | 2774 | { |
| 2770 | 2775 | if(pwm_tm_reg == 0) { pwm_tm_reg = 16; } // zero gives max range |
| r9286 | r9287 | |
| 2774 | 2779 | if(pwm_cycle == 1 || ((pwm_ctrl & 0xf) == 0)) |
| 2775 | 2780 | timer_adjust_oneshot(_32x_pwm_timer, attotime_never, 0); |
| 2776 | 2781 | 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 | } |
| 2778 | 2787 | } |
| 2779 | 2788 | |
| 2780 | 2789 | static TIMER_CALLBACK( _32x_pwm_callback ) |
| 2781 | 2790 | { |
| 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 | } |
| 2783 | 2801 | |
| 2784 | | if(sh2_master_pwmint_enable) { cpu_set_input_line(_32x_master_cpu, SH2_PINT_IRQ_LEVEL,ASSERT_LINE); } |
| 2802 | pwm_timer_tick++; |
| 2785 | 2803 | |
| 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 | } |
| 2787 | 2810 | |
| 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); |
| 2789 | 2812 | } |
| 2790 | 2813 | |
| 2791 | 2814 | static READ16_HANDLER( _32x_pwm_r ) |
| r9286 | r9287 | |
| 2794 | 2817 | { |
| 2795 | 2818 | case 0x00/2: return pwm_ctrl; //control register |
| 2796 | 2819 | 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 |
| 2800 | 2823 | } |
| 2801 | 2824 | |
| 2802 | 2825 | printf("Read at undefined PWM register %02x\n",offset); |
| r9286 | r9287 | |
| 2817 | 2840 | calculate_pwm_timer(); |
| 2818 | 2841 | break; |
| 2819 | 2842 | 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; |
| 2821 | 2845 | break; |
| 2822 | 2846 | 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; |
| 2824 | 2849 | break; |
| 2825 | 2850 | 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; |
| 2828 | 2854 | break; |
| 2829 | 2855 | default: |
| 2830 | 2856 | printf("Write at undefined PWM register %02x %04x\n",offset,data); |