diff --git a/src/emu/cpu/h83002/h83002.c b/src/emu/cpu/h83002/h83002.c index 1394ed6ee0a..c625b170018 100644 --- a/src/emu/cpu/h83002/h83002.c +++ b/src/emu/cpu/h83002/h83002.c @@ -336,11 +336,7 @@ static void h8_init(int index, int clock, const void *config, int (*irqcallback) state_save_register_item_array("H8/3002", index, h8.per_regs); state_save_register_item("H8/3002", index, h8.h8TSTR); - state_save_register_item("H8/3002", index, h8.h8TCNT0); - state_save_register_item("H8/3002", index, h8.h8TCNT1); - state_save_register_item("H8/3002", index, h8.h8TCNT2); - state_save_register_item("H8/3002", index, h8.h8TCNT3); - state_save_register_item("H8/3002", index, h8.h8TCNT4); + state_save_register_item_array("H8/3002", index, h8.h8TCNT); state_save_register_postload(Machine, h8_onstateload, NULL); diff --git a/src/emu/cpu/h83002/h8periph.c b/src/emu/cpu/h83002/h8periph.c index 1016ba030be..08edc6053d1 100644 --- a/src/emu/cpu/h83002/h8periph.c +++ b/src/emu/cpu/h83002/h8periph.c @@ -32,63 +32,22 @@ #define TCR3 (0x82) #define TCR4 (0x92) -static TIMER_CALLBACK( h8itu_timer_0_cb ) -{ - timer_adjust_oneshot(h8.timer[0], attotime_never, 0); - h8.h8TCNT0 = 0; - h8.per_regs[TSR0] |= 4; - // interrupt on overflow ? - if(h8.per_regs[TIER0] & 4) - { - h8_3002_InterruptRequest(26); - } -} +static const UINT8 tsr[5] = { TSR0, TSR1, TSR2, TSR3, TSR4 }; +static const UINT8 tier[5] = { TIER0, TIER1, TIER2, TIER3, TIER4 }; +static const UINT8 tcr[5] = { TCR0, TCR1, TCR2, TCR3, TCR4 }; +static const int tscales[4] = { 1, 2, 4, 8 }; -static TIMER_CALLBACK( h8itu_timer_1_cb ) +static TIMER_CALLBACK( h8itu_timer_cb ) { - timer_adjust_oneshot(h8.timer[1], attotime_never, 0); - h8.h8TCNT1 = 0; - h8.per_regs[TSR1] |= 4; - // interrupt on overflow ? - if(h8.per_regs[TIER1] & 4) - { - h8_3002_InterruptRequest(30); - } -} -static TIMER_CALLBACK( h8itu_timer_2_cb ) -{ - timer_adjust_oneshot(h8.timer[2], attotime_never, 0); - h8.h8TCNT2 = 0; - h8.per_regs[TSR2] |= 4; + int which = (int)ptr; + timer_adjust_oneshot(h8.timer[which], attotime_never, 0); + h8.h8TCNT[which] = 0; + h8.per_regs[tsr[which]] |= 4; // interrupt on overflow ? - if(h8.per_regs[TIER2] & 4) + if(h8.per_regs[tier[which]] & 4) { - h8_3002_InterruptRequest(34); - } -} - -static TIMER_CALLBACK( h8itu_timer_3_cb ) -{ - timer_adjust_oneshot(h8.timer[3], attotime_never, 0); - h8.h8TCNT3 = 0; - h8.per_regs[TSR3] |= 4; - // interrupt on overflow ? - if(h8.per_regs[TIER3] & 4) - { - h8_3002_InterruptRequest(38); - } -} - -static TIMER_CALLBACK( h8itu_timer_4_cb ) -{ - timer_adjust_oneshot(h8.timer[4], attotime_never, 0); - h8.h8TCNT4 = 0; - h8.per_regs[TSR4] |= 4; - // interrupt on overflow ? - if(h8.per_regs[TIER4] & 4) - { - h8_3002_InterruptRequest(42); + h8_3002_InterruptRequest(26 + 4*which); } } @@ -97,31 +56,9 @@ static void h8_itu_refresh_timer(int tnum) int ourTCR = 0; int ourTVAL = 0; attotime period; - static const int tscales[4] = { 1, 2, 4, 8 }; - switch (tnum) - { - case 0: - ourTCR = h8.per_regs[TCR0]; - ourTVAL = h8.h8TCNT0; - break; - case 1: - ourTCR = h8.per_regs[TCR1]; - ourTVAL = h8.h8TCNT1; - break; - case 2: - ourTCR = h8.per_regs[TCR2]; - ourTVAL = h8.h8TCNT2; - break; - case 3: - ourTCR = h8.per_regs[TCR3]; - ourTVAL = h8.h8TCNT3; - break; - case 4: - ourTCR = h8.per_regs[TCR4]; - ourTVAL = h8.h8TCNT4; - break; - } + ourTCR = h8.per_regs[tcr[tnum]]; + ourTVAL = h8.h8TCNT[tnum]; period = attotime_mul(ATTOTIME_IN_HZ(cpunum_get_clock(h8.cpu_number)), tscales[ourTCR & 3] * (65536 - ourTVAL)); @@ -138,26 +75,8 @@ static void h8_itu_sync_timers(int tnum) int ourTCR = 0; attotime cycle_time, cur; UINT16 ratio; - static const int tscales[4] = { 1, 2, 4, 8 }; - switch (tnum) - { - case 0: - ourTCR = h8.per_regs[TCR0]; - break; - case 1: - ourTCR = h8.per_regs[TCR1]; - break; - case 2: - ourTCR = h8.per_regs[TCR2]; - break; - case 3: - ourTCR = h8.per_regs[TCR3]; - break; - case 4: - ourTCR = h8.per_regs[TCR4]; - break; - } + ourTCR = h8.per_regs[tcr[tnum]]; // get the time per unit cycle_time = attotime_mul(ATTOTIME_IN_HZ(cpunum_get_clock(h8.cpu_number)), tscales[ourTCR & 3]); @@ -165,24 +84,7 @@ static void h8_itu_sync_timers(int tnum) ratio = attotime_to_double(cur) / attotime_to_double(cycle_time); - switch (tnum) - { - case 0: - h8.h8TCNT0 = ratio; - break; - case 1: - h8.h8TCNT1 = ratio; - break; - case 2: - h8.h8TCNT2 = ratio; - break; - case 3: - h8.h8TCNT3 = ratio; - break; - case 4: - h8.h8TCNT4 = ratio; - break; - } + h8.h8TCNT[tnum] = ratio; } UINT8 h8_itu_read8(UINT8 reg) @@ -196,35 +98,35 @@ UINT8 h8_itu_read8(UINT8 reg) break; case 0x68: h8_itu_sync_timers(0); - val = h8.h8TCNT0>>8; + val = h8.h8TCNT[0]>>8; break; case 0x69: h8_itu_sync_timers(0); - val = h8.h8TCNT0&0xff; + val = h8.h8TCNT[0]&0xff; break; case 0x72: h8_itu_sync_timers(1); - val = h8.h8TCNT1>>8; + val = h8.h8TCNT[1]>>8; break; case 0x73: h8_itu_sync_timers(1); - val = h8.h8TCNT1&0xff; + val = h8.h8TCNT[1]&0xff; break; case 0x7c: h8_itu_sync_timers(2); - val = h8.h8TCNT2>>8; + val = h8.h8TCNT[2]>>8; break; case 0x7d: h8_itu_sync_timers(2); - val = h8.h8TCNT2&0xff; + val = h8.h8TCNT[2]&0xff; break; case 0x86: h8_itu_sync_timers(3); - val = h8.h8TCNT3>>8; + val = h8.h8TCNT[3]>>8; break; case 0x87: h8_itu_sync_timers(3); - val = h8.h8TCNT3&0xff; + val = h8.h8TCNT[3]&0xff; break; default: val = h8.per_regs[reg]; @@ -264,70 +166,70 @@ void h8_itu_write8(UINT8 reg, UINT8 val) h8.h8TSTR = val; break; case 0x68: - h8.h8TCNT0 = (val<<8) | (h8.h8TCNT0 & 0xff); + h8.h8TCNT[0] = (val<<8) | (h8.h8TCNT[0] & 0xff); if (h8.h8TSTR & 1) { h8_itu_refresh_timer(0); } break; case 0x69: - h8.h8TCNT0 = (val) | (h8.h8TCNT0 & 0xff00); + h8.h8TCNT[0] = (val) | (h8.h8TCNT[0] & 0xff00); if (h8.h8TSTR & 1) { h8_itu_refresh_timer(0); } break; case 0x72: - h8.h8TCNT1 = (val<<8) | (h8.h8TCNT1 & 0xff); + h8.h8TCNT[1] = (val<<8) | (h8.h8TCNT[1] & 0xff); if (h8.h8TSTR & 2) { h8_itu_refresh_timer(1); } break; case 0x73: - h8.h8TCNT1 = (val) | (h8.h8TCNT1 & 0xff00); + h8.h8TCNT[1] = (val) | (h8.h8TCNT[1] & 0xff00); if (h8.h8TSTR & 2) { h8_itu_refresh_timer(1); } break; case 0x7c: - h8.h8TCNT2 = (val<<8) | (h8.h8TCNT2 & 0xff); + h8.h8TCNT[2] = (val<<8) | (h8.h8TCNT[2] & 0xff); if (h8.h8TSTR & 4) { h8_itu_refresh_timer(2); } break; case 0x7d: - h8.h8TCNT2 = (val) | (h8.h8TCNT2 & 0xff00); + h8.h8TCNT[2] = (val) | (h8.h8TCNT[2] & 0xff00); if (h8.h8TSTR & 4) { h8_itu_refresh_timer(2); } break; case 0x86: - h8.h8TCNT3 = (val<<8) | (h8.h8TCNT3 & 0xff); + h8.h8TCNT[3] = (val<<8) | (h8.h8TCNT[3] & 0xff); if (h8.h8TSTR & 8) { h8_itu_refresh_timer(3); } break; case 0x87: - h8.h8TCNT3 = (val) | (h8.h8TCNT3 & 0xff00); + h8.h8TCNT[3] = (val) | (h8.h8TCNT[3] & 0xff00); if (h8.h8TSTR & 8) { h8_itu_refresh_timer(3); } break; case 0x96: - h8.h8TCNT4 = (val<<8) | (h8.h8TCNT4 & 0xff); + h8.h8TCNT[4] = (val<<8) | (h8.h8TCNT[4] & 0xff); if (h8.h8TSTR & 0x10) { h8_itu_refresh_timer(4); } break; case 0x97: - h8.h8TCNT4 = (val) | (h8.h8TCNT4 & 0xff00); + h8.h8TCNT[4] = (val) | (h8.h8TCNT[4] & 0xff00); if (h8.h8TSTR & 0x10) { h8_itu_refresh_timer(4); @@ -513,7 +415,6 @@ void h8_register_write8(UINT32 address, UINT8 val) static void h8_3007_itu_refresh_timer(int tnum) { attotime period; - static const int tscales[4] = { 1, 2, 4, 8 }; int ourTCR = h8.per_regs[0x68+(tnum*8)]; period = attotime_mul(ATTOTIME_IN_HZ(cpunum_get_clock(h8.cpu_number)), tscales[ourTCR & 3]); @@ -526,33 +427,34 @@ static void h8_3007_itu_refresh_timer(int tnum) timer_adjust_oneshot(h8.timer[tnum], period, 0); } -INLINE void h8itu_3007_timer_cb(int tnum) +static TIMER_CALLBACK( h8itu_3007_timer_cb ) { + int tnum = (int)ptr; int base = 0x68 + (tnum*8); UINT16 count = (h8.per_regs[base + 0x2]<<8) | h8.per_regs[base + 0x3]; count++; -// logerror("h8/3007 timer %d count = %04x\n",tnum,count); + //logerror("h8/3007 timer %d count = %04x\n",tnum,count); - // GRA match + // GRA match if ((h8.per_regs[base + 0x1] & 0x03) && (count == ((h8.per_regs[base + 0x4]<<8) | h8.per_regs[base + 0x5]))) { if ((h8.per_regs[base + 0x0] & 0x60) == 0x20) { -// logerror("h8/3007 timer %d GRA match, restarting\n",tnum); + //logerror("h8/3007 timer %d GRA match, restarting\n",tnum); count = 0; h8_3007_itu_refresh_timer(tnum); } else { -// logerror("h8/3007 timer %d GRA match, stopping\n",tnum); + //logerror("h8/3007 timer %d GRA match, stopping\n",tnum); timer_adjust_oneshot(h8.timer[tnum], attotime_never, 0); } h8.per_regs[0x64] |= 1<lsb_buffer); state_save_register_item("6840ptm", which, currptr->msb_buffer); @@ -672,9 +669,7 @@ static void ptm6840_timeout(running_machine *machine, int which, int idx) reload_count(machine, which, idx); } -static TIMER_CALLBACK( ptm6840_t1_timeout ) { ptm6840_timeout(machine, param, 0); } -static TIMER_CALLBACK( ptm6840_t2_timeout ) { ptm6840_timeout(machine, param, 1); } -static TIMER_CALLBACK( ptm6840_t3_timeout ) { ptm6840_timeout(machine, param, 2); } +static TIMER_CALLBACK( ptm6840_timer_cb ) { ptm6840_timeout(machine, param, (int)ptr); } /////////////////////////////////////////////////////////////////////////// // // diff --git a/src/emu/sound/pokey.c b/src/emu/sound/pokey.c index f84ecf0d554..a26a45c312c 100644 --- a/src/emu/sound/pokey.c +++ b/src/emu/sound/pokey.c @@ -610,6 +610,7 @@ static void *pokey_start(const char *tag, int sndindex, int clock, const void *c { struct POKEYregisters *chip; int sample_rate = clock; + int i; chip = auto_malloc(sizeof(*chip)); memset(chip, 0, sizeof(*chip)); @@ -653,23 +654,11 @@ static void *pokey_start(const char *tag, int sndindex, int clock, const void *c chip->timer[1] = timer_alloc(pokey_timer_expire, chip); chip->timer[2] = timer_alloc(pokey_timer_expire, chip); - chip->ptimer[0] = timer_alloc(pokey_pot_trigger, chip); - chip->ptimer[1] = timer_alloc(pokey_pot_trigger, chip); - chip->ptimer[2] = timer_alloc(pokey_pot_trigger, chip); - chip->ptimer[3] = timer_alloc(pokey_pot_trigger, chip); - chip->ptimer[4] = timer_alloc(pokey_pot_trigger, chip); - chip->ptimer[5] = timer_alloc(pokey_pot_trigger, chip); - chip->ptimer[6] = timer_alloc(pokey_pot_trigger, chip); - chip->ptimer[7] = timer_alloc(pokey_pot_trigger, chip); - - chip->pot_r[0] = chip->intf.pot_r[0]; - chip->pot_r[1] = chip->intf.pot_r[1]; - chip->pot_r[2] = chip->intf.pot_r[2]; - chip->pot_r[3] = chip->intf.pot_r[3]; - chip->pot_r[4] = chip->intf.pot_r[4]; - chip->pot_r[5] = chip->intf.pot_r[5]; - chip->pot_r[6] = chip->intf.pot_r[6]; - chip->pot_r[7] = chip->intf.pot_r[7]; + for (i=0; i<8; i++) + { + chip->ptimer[i] = timer_alloc(pokey_pot_trigger, chip); + chip->pot_r[i] = chip->intf.pot_r[i]; + } chip->allpot_r = chip->intf.allpot_r; chip->serin_r = chip->intf.serin_r; chip->serout_w = chip->intf.serout_w; diff --git a/src/mame/drivers/crystal.c b/src/mame/drivers/crystal.c index ad7eeefdc16..d47a07842b9 100644 --- a/src/mame/drivers/crystal.c +++ b/src/mame/drivers/crystal.c @@ -132,10 +132,10 @@ static UINT32 *workram,*textureram,*frameram; static UINT32 *sysregs,*vidregs; static UINT32 Bank; static UINT8 FlipCount,IntHigh; -static UINT32 Timer0ctrl,Timer1ctrl,Timer2ctrl,Timer3ctrl; -static void *Timer0,*Timer1,*Timer2,*Timer3; +static UINT32 Timerctrl[4]; +static emu_timer *Timer[4]; static UINT32 FlashCmd,PIO; -static UINT32 DMA0ctrl,DMA1ctrl; +static UINT32 DMActrl[2]; static UINT8 OldPort4; static UINT32 *ResetPatch; @@ -235,116 +235,70 @@ static WRITE32_HANDLER(Banksw_w) memory_set_bankptr(1,memory_region(machine, "user2")); } -static TIMER_CALLBACK( Timer0cb ) +static TIMER_CALLBACK( Timercb ) { - if(!(Timer0ctrl&2)) - Timer0ctrl&=~1; - IntReq(machine, 0); + int which = (int)ptr; + static const int num[] = { 0, 1, 9, 10 }; + + if(!(Timerctrl[which]&2)) + Timerctrl[which]&=~1; + IntReq(machine, num[which]); +} + +INLINE void Timer_w(int which, UINT32 data, UINT32 mem_mask) +{ + if(((data^Timerctrl[which])&1) && (data&1)) //Timer activate + { + int PD=(data>>8)&0xff; + int TCV=program_read_dword_32le(0x01801404+which*8); + attotime period = attotime_mul(ATTOTIME_IN_HZ(43000000), (PD + 1) * (TCV + 1)); + + if(Timerctrl[which]&2) + timer_adjust_periodic(Timer[which],period,0,period); + else + timer_adjust_oneshot(Timer[which],period,0); + } + COMBINE_DATA(&Timerctrl[which]); } static WRITE32_HANDLER(Timer0_w) { - if(((data^Timer0ctrl)&1) && (data&1)) //Timer activate - { - int PD=(data>>8)&0xff; - int TCV=program_read_dword_32le(0x01801404); - attotime period = attotime_mul(ATTOTIME_IN_HZ(43000000), (PD + 1) * (TCV + 1)); - - if(Timer0ctrl&2) - timer_adjust_periodic(Timer0,period,0,period); - else - timer_adjust_oneshot(Timer0,period,0); - } - COMBINE_DATA(&Timer0ctrl); + Timer_w(0, data, mem_mask); } static READ32_HANDLER(Timer0_r) { - return Timer0ctrl; -} - -static TIMER_CALLBACK( Timer1cb ) -{ - if(!(Timer1ctrl&2)) - Timer1ctrl&=~1; - IntReq(machine, 1); + return Timerctrl[0]; } static WRITE32_HANDLER(Timer1_w) { - if(((data^Timer1ctrl)&1) && (data&1)) //Timer activate - { - int PD=(data>>8)&0xff; - int TCV=program_read_dword_32le(0x0180140C); - attotime period = attotime_mul(ATTOTIME_IN_HZ(43000000), (PD + 1) * (TCV + 1)); - - if(Timer1ctrl&2) - timer_adjust_periodic(Timer1,period,0,period); - else - timer_adjust_oneshot(Timer1,period,0); - } - COMBINE_DATA(&Timer1ctrl); + Timer_w(1, data, mem_mask); } static READ32_HANDLER(Timer1_r) { - return Timer1ctrl; -} - -static TIMER_CALLBACK( Timer2cb ) -{ - if(!(Timer2ctrl&2)) - Timer2ctrl&=~1; - IntReq(machine, 9); + return Timerctrl[1]; } static WRITE32_HANDLER(Timer2_w) { - if(((data^Timer2ctrl)&1) && (data&1)) //Timer activate - { - int PD=(data>>8)&0xff; - int TCV=program_read_dword_32le(0x01801414); - attotime period = attotime_mul(ATTOTIME_IN_HZ(43000000), (PD + 1) * (TCV + 1)); - - if(Timer2ctrl&2) - timer_adjust_periodic(Timer2,period,0,period); - else - timer_adjust_oneshot(Timer2,period,0); - } - COMBINE_DATA(&Timer2ctrl); + Timer_w(2, data, mem_mask); } static READ32_HANDLER(Timer2_r) { - return Timer2ctrl; -} - -static TIMER_CALLBACK( Timer3cb ) -{ - if(!(Timer3ctrl&2)) - Timer3ctrl&=~1; - IntReq(machine, 10); + return Timerctrl[2]; } static WRITE32_HANDLER(Timer3_w) { - if(((data^Timer3ctrl)&1) && (data&1)) //Timer activate - { - int PD=(data>>8)&0xff; - int TCV=program_read_dword_32le(0x0180141C); - attotime period = attotime_mul(ATTOTIME_IN_HZ(43000000), (PD + 1) * (TCV + 1)); - - if(Timer3ctrl&2) - timer_adjust_periodic(Timer3,period,0,period); - else - timer_adjust_oneshot(Timer3,period,0); - } - COMBINE_DATA(&Timer3ctrl); + Timer_w(3, data, mem_mask); } static READ32_HANDLER(Timer3_r) { - return Timer3ctrl; + return Timerctrl[3]; } static READ32_HANDLER(FlashCmd_r) @@ -397,96 +351,65 @@ static WRITE32_HANDLER(PIO_w) COMBINE_DATA(&PIO); } +INLINE void DMA_w(running_machine *machine, int which, UINT32 data, UINT32 mem_mask) +{ + if(((data^DMActrl[which])&(1<<10)) && (data&(1<<10))) //DMAOn + { + UINT32 CTR=data; + UINT32 SRC=program_read_dword_32le(0x01800804+which*0x10); + UINT32 DST=program_read_dword_32le(0x01800808+which*0x10); + UINT32 CNT=program_read_dword_32le(0x0180080C+which*0x10); + int i; + + if(CTR&0x2) //32 bits + { + for(i=0;i