src/mame/drivers/megadriv.c
| r9251 | r9252 | |
| 2372 | 2372 | else |
| 2373 | 2373 | { |
| 2374 | 2374 | fifo_block_b_full = 1; |
| 2375 | | |
| 2375 | |
| 2376 | 2376 | if (!fifo_block_a_full) |
| 2377 | 2377 | { |
| 2378 | 2378 | current_fifo_block = fifo_block_a; |
| 2379 | 2379 | current_fifo_readblock = fifo_block_b; |
| 2380 | 2380 | } |
| 2381 | | |
| 2381 | |
| 2382 | 2382 | current_fifo_write_pos = 0; |
| 2383 | 2383 | } |
| 2384 | 2384 | } |
| r9251 | r9252 | |
| 2600 | 2600 | } |
| 2601 | 2601 | |
| 2602 | 2602 | /**********************************************************************************************/ |
| 2603 | // 68k side a15130 - a1513f |
| 2604 | // PWM registers |
| 2605 | // access from the SH2 via 4030 - 403f |
| 2606 | /**********************************************************************************************/ |
| 2607 | |
| 2608 | static UINT16 pwm_ctrl,pwm_cycle,pwm_tm_reg; |
| 2609 | static emu_timer *_32x_pwm_timer; |
| 2610 | |
| 2611 | static void calculate_pwm_timer(void) |
| 2612 | { |
| 2613 | if(pwm_tm_reg == 0) { pwm_tm_reg = 16; } // zero gives max range |
| 2614 | if(pwm_cycle == 0) { pwm_cycle = 4095; } // zero gives max range |
| 2615 | |
| 2616 | /* if both RMD and LMD are set to OFF or pwm cycle register is one, then PWM timer ticks doesn't occur */ |
| 2617 | if(pwm_cycle == 1 || ((pwm_ctrl & 0xf) == 0)) |
| 2618 | timer_adjust_oneshot(_32x_pwm_timer, attotime_never, 0); |
| 2619 | else |
| 2620 | timer_adjust_oneshot(_32x_pwm_timer, ATTOTIME_IN_HZ(((MASTER_CLOCK_NTSC*3 / 7) / (pwm_cycle - 1)) * pwm_tm_reg), 0); |
| 2621 | } |
| 2622 | |
| 2623 | static TIMER_CALLBACK( _32x_pwm_callback ) |
| 2624 | { |
| 2625 | // ... |
| 2626 | |
| 2627 | /* disabled, we need PWM FIFO support first! */ |
| 2628 | // if(sh2_master_pwmint_enable) { cpu_set_input_line(_32x_master_cpu, SH2_PINT_IRQ_LEVEL,ASSERT_LINE); } |
| 2629 | |
| 2630 | // if(sh2_slave_pwmint_enable) { cpu_set_input_line(_32x_slave_cpu, SH2_PINT_IRQ_LEVEL,ASSERT_LINE); } |
| 2631 | |
| 2632 | timer_adjust_oneshot(_32x_pwm_timer, ATTOTIME_IN_HZ(((MASTER_CLOCK_NTSC*3 / 7) / (pwm_cycle - 1)) * pwm_tm_reg), 0); |
| 2633 | } |
| 2634 | |
| 2635 | static READ16_HANDLER( _32x_68k_pwm_control_reg_r ) |
| 2636 | { |
| 2637 | return pwm_ctrl; |
| 2638 | } |
| 2639 | |
| 2640 | static WRITE16_HANDLER( _32x_68k_pwm_control_reg_w ) |
| 2641 | { |
| 2642 | pwm_ctrl = (data & 0x7f) | (pwm_ctrl & 0xff80); |
| 2643 | |
| 2644 | calculate_pwm_timer(); |
| 2645 | } |
| 2646 | |
| 2647 | static WRITE16_HANDLER( _32x_sh2_pwm_control_reg_w ) |
| 2648 | { |
| 2649 | pwm_ctrl = data & 0xffff; |
| 2650 | |
| 2651 | pwm_tm_reg = (pwm_ctrl & 0xf00) >> 8; |
| 2652 | |
| 2653 | calculate_pwm_timer(); |
| 2654 | } |
| 2655 | |
| 2656 | static READ16_HANDLER( _32x_68k_pwm_cycle_reg_r ) |
| 2657 | { |
| 2658 | return pwm_cycle; |
| 2659 | } |
| 2660 | |
| 2661 | static WRITE16_HANDLER( _32x_68k_pwm_cycle_reg_w ) |
| 2662 | { |
| 2663 | pwm_cycle = data & 0xfff; |
| 2664 | |
| 2665 | calculate_pwm_timer(); |
| 2666 | } |
| 2667 | |
| 2668 | /**********************************************************************************************/ |
| 2603 | 2669 | // 68k side a15180 |
| 2604 | 2670 | // framebuffer control |
| 2605 | 2671 | // also accessed from the SH2 @ 4100 |
| r9251 | r9252 | |
| 2854 | 2920 | sh2_master_pwmint_enable = data & 0x1; |
| 2855 | 2921 | |
| 2856 | 2922 | if (sh2_master_hint_enable) printf("sh2_master_hint_enable enable!\n"); |
| 2857 | | if (sh2_master_pwmint_enable) printf("sh2_master_pwn_enable enable!\n"); |
| 2923 | //if (sh2_master_pwmint_enable) printf("sh2_master_pwn_enable enable!\n"); |
| 2858 | 2924 | |
| 2859 | 2925 | } |
| 2860 | 2926 | } |
| r9251 | r9252 | |
| 2892 | 2958 | sh2_slave_pwmint_enable = data & 0x1; |
| 2893 | 2959 | |
| 2894 | 2960 | if (sh2_slave_hint_enable) printf("sh2_slave_hint_enable enable!\n"); |
| 2895 | | if (sh2_slave_pwmint_enable) printf("sh2_slave_pwm_enable enable!\n"); |
| 2961 | //if (sh2_slave_pwmint_enable) printf("sh2_slave_pwm_enable enable!\n"); |
| 2896 | 2962 | |
| 2897 | 2963 | } |
| 2898 | 2964 | } |
| r9251 | r9252 | |
| 2983 | 3049 | if (current_fifo_readblock == fifo_block_a) |
| 2984 | 3050 | { |
| 2985 | 3051 | fifo_block_a_full = 0; |
| 2986 | | |
| 3052 | |
| 2987 | 3053 | if (fifo_block_b_full) |
| 2988 | 3054 | { |
| 2989 | 3055 | current_fifo_readblock = fifo_block_b; |
| r9251 | r9252 | |
| 2995 | 3061 | else if (current_fifo_readblock == fifo_block_b) |
| 2996 | 3062 | { |
| 2997 | 3063 | fifo_block_b_full = 0; |
| 2998 | | |
| 3064 | |
| 2999 | 3065 | if (fifo_block_a_full) |
| 3000 | 3066 | { |
| 3001 | 3067 | current_fifo_readblock = fifo_block_a; |
| r9251 | r9252 | |
| 3005 | 3071 | current_fifo_read_pos = 0; |
| 3006 | 3072 | } |
| 3007 | 3073 | } |
| 3008 | | |
| 3074 | |
| 3009 | 3075 | return retdat; |
| 3010 | 3076 | } |
| 3011 | 3077 | |
| r9251 | r9252 | |
| 3081 | 3147 | // PWM Control Register |
| 3082 | 3148 | /**********************************************************************************************/ |
| 3083 | 3149 | |
| 3150 | static READ16_HANDLER( _32x_sh2_pwm_control_reg_r ) { return _32x_68k_pwm_control_reg_r(space, offset, mem_mask); } |
| 3151 | //static WRITE16_HANDLER( _32x_sh2_pwm_control_reg_w ) { _32x_sh2_pwm_control_reg_w(space, offset, data, mem_mask); } |
| 3152 | |
| 3084 | 3153 | /**********************************************************************************************/ |
| 3085 | 3154 | // SH2 side 4032 |
| 3086 | 3155 | // Cycle Register |
| 3087 | 3156 | /**********************************************************************************************/ |
| 3088 | 3157 | |
| 3158 | static READ16_HANDLER( _32x_sh2_pwm_cycle_reg_r ) { return _32x_68k_pwm_cycle_reg_r(space, offset, mem_mask); } |
| 3159 | static WRITE16_HANDLER( _32x_sh2_pwm_cycle_reg_w ) { _32x_68k_pwm_cycle_reg_w(space, offset, data, mem_mask); } |
| 3160 | |
| 3161 | |
| 3089 | 3162 | /**********************************************************************************************/ |
| 3090 | 3163 | // SH2 side 4034 |
| 3091 | 3164 | // LCH Pulse Width Register |
| r9251 | r9252 | |
| 3280 | 3353 | _32X_MAP_RAM_READHANDLERS(commsram) // _32x_sh2_commsram_r |
| 3281 | 3354 | _32X_MAP_RAM_WRITEHANDLERS(commsram) // _32x_sh2_commsram_w |
| 3282 | 3355 | |
| 3356 | _32X_MAP_READHANDLERS(pwm_control_reg,pwm_cycle_reg) |
| 3357 | _32X_MAP_WRITEHANDLERS(pwm_control_reg,pwm_cycle_reg) |
| 3358 | |
| 3283 | 3359 | _32X_MAP_READHANDLERS(common_4010,common_4012) |
| 3284 | 3360 | |
| 3285 | 3361 | _32X_MAP_READHANDLERS(common_4100,common_4102) // _32x_sh2_common_4100_common_4102_r |
| r9251 | r9252 | |
| 3319 | 3395 | AM_RANGE(0x0000401c, 0x0000401f) AM_WRITE( _32x_sh2_master_401c_master_401e_w ) // IRQ clear |
| 3320 | 3396 | |
| 3321 | 3397 | AM_RANGE(0x00004020, 0x0000402f) AM_READWRITE( _32x_sh2_commsram_r, _32x_sh2_commsram_w ) |
| 3398 | AM_RANGE(0x00004030, 0x00004033) AM_READWRITE( _32x_sh2_pwm_control_reg_pwm_cycle_reg_r, _32x_sh2_pwm_control_reg_pwm_cycle_reg_w ) |
| 3399 | AM_RANGE(0x00004034, 0x0000403f) AM_NOP |
| 3400 | |
| 3322 | 3401 | AM_RANGE(0x00004100, 0x00004103) AM_READWRITE( _32x_sh2_common_4100_common_4102_r, _32x_sh2_common_4100_common_4102_w ) |
| 3323 | 3402 | AM_RANGE(0x00004104, 0x00004107) AM_READWRITE( _32x_sh2_common_4104_common_4106_r, _32x_sh2_common_4104_common_4106_w ) |
| 3324 | 3403 | AM_RANGE(0x00004108, 0x0000410b) AM_READWRITE( _32x_sh2_common_4108_common_410a_r, _32x_sh2_common_4108_common_410a_w ) |
| 3325 | | AM_RANGE(0x00004200, 0x000043ff) AM_READWRITE(_32x_sh2_paletteram_r, _32x_sh2_paletteram_w) |
| 3404 | AM_RANGE(0x00004200, 0x000043ff) AM_READWRITE( _32x_sh2_paletteram_r, _32x_sh2_paletteram_w) |
| 3326 | 3405 | |
| 3327 | 3406 | AM_RANGE(0x04000000, 0x0401ffff) AM_READWRITE(_32x_sh2_framebuffer_dram_r, _32x_sh2_framebuffer_dram_w) |
| 3328 | 3407 | AM_RANGE(0x04020000, 0x0403ffff) AM_READWRITE(_32x_sh2_framebuffer_overwrite_dram_r, _32x_sh2_framebuffer_overwrite_dram_w) |
| r9251 | r9252 | |
| 3345 | 3424 | AM_RANGE(0x0000401c, 0x0000401f) AM_WRITE( _32x_sh2_slave_401c_slave_401e_w ) // IRQ clear |
| 3346 | 3425 | |
| 3347 | 3426 | AM_RANGE(0x00004020, 0x0000402f) AM_READWRITE( _32x_sh2_commsram_r, _32x_sh2_commsram_w ) |
| 3427 | AM_RANGE(0x00004030, 0x00004033) AM_READWRITE( _32x_sh2_pwm_control_reg_pwm_cycle_reg_r, _32x_sh2_pwm_control_reg_pwm_cycle_reg_w ) |
| 3428 | AM_RANGE(0x00004034, 0x0000403f) AM_NOP |
| 3429 | |
| 3348 | 3430 | AM_RANGE(0x00004100, 0x00004103) AM_READWRITE( _32x_sh2_common_4100_common_4102_r, _32x_sh2_common_4100_common_4102_w ) |
| 3349 | 3431 | AM_RANGE(0x00004104, 0x00004107) AM_READWRITE( _32x_sh2_common_4104_common_4106_r, _32x_sh2_common_4104_common_4106_w ) |
| 3350 | 3432 | AM_RANGE(0x00004108, 0x0000410b) AM_READWRITE( _32x_sh2_common_4108_common_410a_r, _32x_sh2_common_4108_common_410a_w ) |
| r9251 | r9252 | |
| 6185 | 6267 | |
| 6186 | 6268 | return 0; |
| 6187 | 6269 | } |
| 6188 | | |
| 6270 | |
| 6189 | 6271 | return 1; |
| 6190 | 6272 | } |
| 6191 | 6273 | |
| r9251 | r9252 | |
| 6296 | 6378 | _32x_is_connected = 0; |
| 6297 | 6379 | } |
| 6298 | 6380 | |
| 6381 | if(_32x_is_connected) |
| 6382 | { |
| 6383 | _32x_pwm_timer = timer_alloc(machine, _32x_pwm_callback, 0); |
| 6384 | timer_adjust_oneshot(_32x_pwm_timer, attotime_never, 0); |
| 6385 | } |
| 6386 | |
| 6299 | 6387 | _segacd_68k_cpu = machine->device<cpu_device>("segacd_68k"); |
| 6300 | 6388 | if (_segacd_68k_cpu != NULL) |
| 6301 | 6389 | { |
| r9251 | r9252 | |
| 6507 | 6595 | |
| 6508 | 6596 | memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa15112, 0xa15113, 0, 0, _32x_68k_a15112_r, _32x_68k_a15112_w); // fifo |
| 6509 | 6597 | |
| 6510 | | |
| 6511 | 6598 | memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa15120, 0xa1512f, 0, 0, _32x_68k_commsram_r, _32x_68k_commsram_w); // comms reg 0-7 |
| 6599 | memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa15130, 0xa15131, 0, 0, _32x_68k_pwm_control_reg_r, _32x_68k_pwm_control_reg_w); |
| 6600 | memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa15132, 0xa15133, 0, 0, _32x_68k_pwm_cycle_reg_r, _32x_68k_pwm_cycle_reg_w); |
| 6512 | 6601 | |
| 6513 | 6602 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x0a130ec, 0x0a130ef, 0, 0, _32x_68k_MARS_r); // system ID |
| 6514 | 6603 | |