From f2c32190ea7eee238f13728d0f56a6d0d310bbbf Mon Sep 17 00:00:00 2001 From: Nathan Woods Date: Sun, 14 Dec 2008 01:08:14 +0000 Subject: [PATCH] Changed the 6522 VIA implementation to be a device --- src/emu/machine/6522via.c | 704 +++++++++++++++++------------------ src/emu/machine/6522via.h | 191 +++------- src/mame/drivers/atarisy1.c | 26 +- src/mame/drivers/beezer.c | 6 +- src/mame/drivers/bmcbowl.c | 30 +- src/mame/drivers/gameplan.c | 57 +-- src/mame/drivers/itech32.c | 35 +- src/mame/drivers/itech8.c | 27 +- src/mame/drivers/trvquest.c | 43 ++- src/mame/includes/beezer.h | 3 + src/mame/includes/gameplan.h | 5 + src/mame/machine/beezer.c | 104 ++++-- src/mame/video/beezer.c | 4 +- src/mame/video/gameplan.c | 50 ++- 14 files changed, 617 insertions(+), 668 deletions(-) diff --git a/src/emu/machine/6522via.c b/src/emu/machine/6522via.c index 230a98d78e8..d4820b8b554 100644 --- a/src/emu/machine/6522via.c +++ b/src/emu/machine/6522via.c @@ -23,7 +23,6 @@ */ #include "driver.h" -#include "deprecat.h" #include "6522via.h" @@ -43,8 +42,6 @@ typedef struct _via6522_t via6522_t; struct _via6522_t { - const via6522_interface *intf; - UINT8 in_a; UINT8 in_ca1; UINT8 in_ca2; @@ -80,6 +77,8 @@ struct _via6522_t emu_timer *t2; attotime time2; UINT8 t2_active; + + emu_timer *shift_timer; UINT8 shift_counter; int clock; @@ -148,50 +147,74 @@ struct _via6522_t #define INT_T1 0x40 #define INT_ANY 0x80 -#define CLR_PA_INT(v, which) via_clear_int (machine, which, INT_CA1 | ((!CA2_IND_IRQ(v->pcr)) ? INT_CA2: 0)) -#define CLR_PB_INT(v, which) via_clear_int (machine, which, INT_CB1 | ((!CB2_IND_IRQ(v->pcr)) ? INT_CB2: 0)) +#define CLR_PA_INT(device) via_clear_int (device, INT_CA1 | ((!CA2_IND_IRQ(get_token(device)->pcr)) ? INT_CA2: 0)) +#define CLR_PB_INT(device) via_clear_int (device, INT_CB1 | ((!CB2_IND_IRQ(get_token(device)->pcr)) ? INT_CB2: 0)) #define IFR_DELAY 3 #define TIMER1_VALUE(v) (v->t1ll+(v->t1lh<<8)) #define TIMER2_VALUE(v) (v->t2ll+(v->t2lh<<8)) -/******************* static variables *******************/ - -static via6522_t via[MAX_VIA]; - - /*************************************************************************** PROTOTYPES ***************************************************************************/ static TIMER_CALLBACK( via_shift_callback ); +static TIMER_CALLBACK( via_t1_timeout ); +static TIMER_CALLBACK( via_t2_timeout ); /*************************************************************************** INLINE FUNCTIONS ***************************************************************************/ -INLINE attotime v_cycles_to_time(via6522_t *v, int c) +INLINE via6522_t *get_token(const device_config *device) { + assert(device != NULL); + assert((device->type == VIA6522)); + return (via6522_t *) device->token; +} + + +INLINE const via6522_interface *get_interface(const device_config *device) +{ + assert(device != NULL); + assert((device->type == VIA6522)); + return (const via6522_interface *) device->static_config; +} + + +INLINE const via6522_inline_config *get_inline_config(const device_config *device) +{ + assert(device != NULL); + assert((device->type == VIA6522)); + return (const via6522_inline_config *) device->inline_config; +} + + +INLINE attotime v_cycles_to_time(const device_config *device, int c) +{ + via6522_t *v = get_token(device); return attotime_mul(ATTOTIME_IN_HZ(v->clock), c); } -INLINE UINT32 v_time_to_cycles(via6522_t *v, attotime t) +INLINE UINT32 v_time_to_cycles(const device_config *device, attotime t) { + via6522_t *v = get_token(device); return attotime_to_double(attotime_mul(t, v->clock)); } -INLINE UINT16 v_get_counter1_value(via6522_t *v) +INLINE UINT16 v_get_counter1_value(const device_config *device) { + via6522_t *v = get_token(device); UINT16 val; if (v->t1_active) { - val = v_time_to_cycles(v, timer_timeleft(v->t1)) - IFR_DELAY; + val = v_time_to_cycles(device, timer_timeleft(v->t1)) - IFR_DELAY; } else { - val = 0xFFFF - v_time_to_cycles(v, attotime_sub(timer_get_time(Machine), v->time1)); + val = 0xFFFF - v_time_to_cycles(device, attotime_sub(timer_get_time(device->machine), v->time1)); } return val; } @@ -202,32 +225,29 @@ INLINE UINT16 v_get_counter1_value(via6522_t *v) ***************************************************************************/ /*------------------------------------------------- - via_set_clock + DEVICE_START( via6522 ) -------------------------------------------------*/ -void via_set_clock(int which,int clock) +static DEVICE_START( via6522 ) { - via[which].clock = clock; -} + via6522_t *v = get_token(device); + const via6522_inline_config *inline_config = get_inline_config(device); - -/*------------------------------------------------- - via_config --------------------------------------------------*/ - -void via_config(int which, const via6522_interface *intf) -{ - assert(which < MAX_VIA); - - via[which].intf = intf; - via[which].t1ll = 0xf3; /* via at 0x9110 in vic20 show these values */ - via[which].t1lh = 0xb5; /* ports are not written by kernel! */ - via[which].t2ll = 0xff; /* taken from vice */ - via[which].t2lh = 0xff; - via[which].time2 = via[which].time1 = timer_get_time(Machine); + memset(v, 0, sizeof(*v)); + v->t1ll = 0xf3; /* via at 0x9110 in vic20 show these values */ + v->t1lh = 0xb5; /* ports are not written by kernel! */ + v->t2ll = 0xff; /* taken from vice */ + v->t2lh = 0xff; + v->time2 = v->time1 = timer_get_time(device->machine); + v->t1 = timer_alloc(device->machine, via_t1_timeout, (void *) device); + v->t2 = timer_alloc(device->machine, via_t2_timeout, (void *) device); + v->shift_timer = timer_alloc(device->machine, via_shift_callback, (void *) device); /* Default clock is from CPU1 */ - via_set_clock (which, cpu_get_clock(Machine->cpu[0])); + v->clock = (inline_config != NULL) && (inline_config->clck != 0) + ? inline_config->clck + : cpu_get_clock(device->machine->cpu[0]); + return DEVICE_START_OK; } @@ -235,22 +255,22 @@ void via_config(int which, const via6522_interface *intf) via_set_int - external interrupt check -------------------------------------------------*/ -static void via_set_int (running_machine *machine, int which, int data) +static void via_set_int (const device_config *device, int data) { - via6522_t *v = via + which; - + via6522_t *v = get_token(device); + const via6522_interface *intf = get_interface(device); v->ifr |= data; if (TRACE_VIA) - logerror("%s:6522VIA chip %d: IFR = %02X\n", cpuexec_describe_context(machine), which, v->ifr); + logerror("%s:6522VIA chip %s: IFR = %02X\n", cpuexec_describe_context(device->machine), device->tag, v->ifr); if (v->ier & v->ifr) { v->ifr |= INT_ANY; - if (v->intf->irq_func) - (*v->intf->irq_func)(machine, ASSERT_LINE); + if (intf->irq_func) + (*intf->irq_func)(device, ASSERT_LINE); else - logerror("%s:6522VIA chip %d: Interrupt is asserted but there is no callback function\n", cpuexec_describe_context(machine), which); + logerror("%s:6522VIA chip %s: Interrupt is asserted but there is no callback function\n", cpuexec_describe_context(device->machine), device->tag); } } @@ -259,24 +279,24 @@ static void via_set_int (running_machine *machine, int which, int data) via_clear_int - external interrupt check -------------------------------------------------*/ -static void via_clear_int (running_machine *machine, int which, int data) +static void via_clear_int (const device_config *device, int data) { - via6522_t *v = via + which; - + via6522_t *v = get_token(device); + const via6522_interface *intf = get_interface(device); v->ifr = (v->ifr & ~data) & 0x7f; if (TRACE_VIA) - logerror("%s:6522VIA chip %d: IFR = %02X\n", cpuexec_describe_context(machine), which, v->ifr); + logerror("%s:6522VIA chip %s: IFR = %02X\n", cpuexec_describe_context(device->machine), device->tag, v->ifr); if (v->ifr & v->ier) v->ifr |= INT_ANY; else { - if (v->intf->irq_func) - (*v->intf->irq_func)(machine, CLEAR_LINE); + if (intf->irq_func) + (*intf->irq_func)(device, CLEAR_LINE); // else -// logerror("%s:6522VIA chip %d: Interrupt is cleared but there is no callback function\n", cpuexec_describe_context(machine), which); +// logerror("%s:6522VIA chip %s: Interrupt is cleared but there is no callback function\n", cpuexec_describe_context(device->machine), device->tag); } } @@ -285,36 +305,35 @@ static void via_clear_int (running_machine *machine, int which, int data) via_shift -------------------------------------------------*/ -static void via_shift(running_machine *machine, int which) +static void via_shift(const device_config *device) { - /* temporary hack until this is converted to a device */ - const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM); - via6522_t *v = via + which; + via6522_t *v = get_token(device); + const via6522_interface *intf = get_interface(device); if (SO_O2_CONTROL(v->acr)) { v->out_cb2 = (v->sr >> 7) & 1; v->sr = (v->sr << 1) | v->out_cb2; - if (v->intf->out_cb2_func) - v->intf->out_cb2_func(space, 0, v->out_cb2); + if (intf->out_cb2_func) + (*intf->out_cb2_func)(device, 0, v->out_cb2); v->in_cb1=1; - if (v->intf->out_cb1_func) + if (intf->out_cb1_func) { /* this should be one cycle wide */ - v->intf->out_cb1_func(space, 0, 0); - v->intf->out_cb1_func(space, 0, 1); + (*intf->out_cb1_func)(device, 0, 0); + (*intf->out_cb1_func)(device, 0, 1); } v->shift_counter = (v->shift_counter + 1) % 8; if (v->shift_counter) - timer_set(machine, v_cycles_to_time(v, 2), NULL, which, via_shift_callback); + timer_adjust_oneshot(v->shift_timer, v_cycles_to_time(device, 2), 0); else { if (!(v->ifr & INT_SR)) - via_set_int(machine, which, INT_SR); + via_set_int(device, INT_SR); } } if (SO_EXT_CONTROL(v->acr)) @@ -322,21 +341,21 @@ static void via_shift(running_machine *machine, int which) v->out_cb2 = (v->sr >> 7) & 1; v->sr = (v->sr << 1) | v->out_cb2; - if (v->intf->out_cb2_func) - v->intf->out_cb2_func(space, 0, v->out_cb2); + if (intf->out_cb2_func) + (*intf->out_cb2_func)(device, 0, v->out_cb2); v->shift_counter = (v->shift_counter + 1) % 8; if (v->shift_counter == 0) { if (!(v->ifr & INT_SR)) - via_set_int(machine, which, INT_SR); + via_set_int(device, INT_SR); } } if (SI_EXT_CONTROL(v->acr)) { - if (v->intf->in_cb2_func) - v->in_cb2 = v->intf->in_cb2_func(space, 0); + if (intf->in_cb2_func) + v->in_cb2 = (*intf->in_cb2_func)(device, 0); v->sr = (v->sr << 1) | (v->in_cb2 & 1); @@ -346,7 +365,7 @@ static void via_shift(running_machine *machine, int which) { if (!(v->ifr & INT_SR)) { - via_set_int(machine, which, INT_SR); + via_set_int(device, INT_SR); } } } @@ -359,7 +378,8 @@ static void via_shift(running_machine *machine, int which) static TIMER_CALLBACK( via_shift_callback ) { - via_shift(machine, param); + const device_config *device = ptr; + via_shift(device); } @@ -369,37 +389,35 @@ static TIMER_CALLBACK( via_shift_callback ) static TIMER_CALLBACK( via_t1_timeout ) { - /* temporary hack until this is converted to a device */ - const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM); - int which = param; - via6522_t *v = via + which; - + const device_config *device = ptr; + via6522_t *v = get_token(device); + const via6522_interface *intf = get_interface(device); if (T1_CONTINUOUS (v->acr)) { if (T1_SET_PB7(v->acr)) v->out_b ^= 0x80; - timer_adjust_oneshot(v->t1, v_cycles_to_time(v, TIMER1_VALUE(v) + IFR_DELAY), which); + timer_adjust_oneshot(v->t1, v_cycles_to_time(device, TIMER1_VALUE(v) + IFR_DELAY), 0); } else { if (T1_SET_PB7(v->acr)) v->out_b |= 0x80; v->t1_active = 0; - v->time1 = timer_get_time(machine); + v->time1 = timer_get_time(device->machine); } if (v->ddr_b) { UINT8 write_data = (v->out_b & v->ddr_b) | (v->ddr_b ^ 0xff); - if (v->intf->out_b_func) - v->intf->out_b_func(space, 0, write_data); + if (intf->out_b_func) + (*intf->out_b_func)(device, 0, write_data); else - logerror("%s:6522VIA chip %d: Port B is being written to but has no handler. %02X\n", cpuexec_describe_context(machine), which, write_data); + logerror("%s:6522VIA chip %s: Port B is being written to but has no handler. %02X\n", cpuexec_describe_context(device->machine), device->tag, write_data); } if (!(v->ifr & INT_T1)) - via_set_int (machine, which, INT_T1); + via_set_int (device, INT_T1); } @@ -409,58 +427,61 @@ static TIMER_CALLBACK( via_t1_timeout ) static TIMER_CALLBACK( via_t2_timeout ) { - int which = param; - via6522_t *v = via + which; + const device_config *device = ptr; + via6522_t *v = get_token(device); v->t2_active = 0; - v->time2 = timer_get_time(machine); + v->time2 = timer_get_time(device->machine); if (!(v->ifr & INT_T2)) - via_set_int (machine, which, INT_T2); + via_set_int (device, INT_T2); } /*------------------------------------------------- - via_reset + DEVICE_RESET( via6522 ) -------------------------------------------------*/ -void via_reset(void) +static DEVICE_RESET( via6522 ) { - int i; - via6522_t v; + via6522_t *v = get_token(device); + v->in_a = 0; + v->in_ca1 = 0; + v->in_ca2 = 0; + v->out_a = 0; + v->out_ca2 = 0; + v->ddr_a = 0; + v->in_b = 0; + v->in_cb1 = 0; + v->in_cb2 = 0; + v->out_b = 0; + v->out_cb2 = 0; + v->ddr_b = 0; - memset(&v, 0, sizeof(v)); + v->t1cl = 0; + v->t1ch = 0; + v->t2cl = 0; + v->t2ch = 0; - for (i = 0; i < MAX_VIA; i++) - { - v.intf = via[i].intf; - v.t1ll = via[i].t1ll; - v.t1lh = via[i].t1lh; - v.t2ll = via[i].t2ll; - v.t2lh = via[i].t2lh; - v.time1 = via[i].time1; - v.time2 = via[i].time2; - v.clock = via[i].clock; - - v.t1 = timer_alloc(Machine, via_t1_timeout, NULL); - v.t1_active = 0; - v.t2 = timer_alloc(Machine, via_t2_timeout, NULL); - v.t2_active = 0; - - via[i] = v; - } + v->sr = 0; + v->pcr = 0; + v->acr = 0; + v->ier = 0; + v->ifr = 0; + v->t1_active = 0; + v->t2_active = 0; + v->shift_counter = 0; } /*------------------------------------------------- - via_read - CPU interface for VIA read + via_r - CPU interface for VIA read -------------------------------------------------*/ -int via_read(running_machine *machine, int which, int offset) +READ8_DEVICE_HANDLER(via_r) { - /* temporary hack until this is converted to a device */ - const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM); - via6522_t *v = via + which; + via6522_t *v = get_token(device); + const via6522_interface *intf = get_interface(device); int val = 0; offset &= 0xf; @@ -471,13 +492,13 @@ int via_read(running_machine *machine, int which, int offset) /* update the input */ if (PB_LATCH_ENABLE(v->acr) == 0) { - if (v->intf->in_b_func) - v->in_b = v->intf->in_b_func(space, 0); + if (intf->in_b_func) + v->in_b = (*intf->in_b_func)(device, 0); else - logerror("%s:6522VIA chip %d: Port B is being read but has no handler\n", cpuexec_describe_context(machine), which); + logerror("%s:6522VIA chip %s: Port B is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag); } - CLR_PB_INT(v, which); + CLR_PB_INT(device); /* combine input and output values, hold DDRB bit 7 high if T1_SET_PB7 */ if (T1_SET_PB7(v->acr)) @@ -490,16 +511,16 @@ int via_read(running_machine *machine, int which, int offset) /* update the input */ if (PA_LATCH_ENABLE(v->acr) == 0) { - if (v->intf->in_a_func) - v->in_a = v->intf->in_a_func(space, 0); + if (intf->in_a_func) + v->in_a = (*intf->in_a_func)(device, 0); else - logerror("%s:6522VIA chip %d: Port A is being read but has no handler\n", cpuexec_describe_context(machine), which); + logerror("%s:6522VIA chip %s: Port A is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag); } /* combine input and output values */ val = (v->out_a & v->ddr_a) + (v->in_a & ~v->ddr_a); - CLR_PA_INT(v, which); + CLR_PA_INT(device); /* If CA2 is configured as output and in pulse or handshake mode, CA2 is set now */ @@ -511,10 +532,10 @@ int via_read(running_machine *machine, int which, int offset) v->out_ca2 = 0; /* call the CA2 output function */ - if (v->intf->out_ca2_func) - v->intf->out_ca2_func(space, 0, 0); + if (intf->out_ca2_func) + (*intf->out_ca2_func)(device, 0, 0); else - logerror("%s:6522VIA chip %d: Port CA2 is being written to but has no handler - %02X\n", cpuexec_describe_context(machine), which, 0); + logerror("%s:6522VIA chip %s: Port CA2 is being written to but has no handler - %02X\n", cpuexec_describe_context(device->machine), device->tag, 0); } } @@ -524,10 +545,10 @@ int via_read(running_machine *machine, int which, int offset) /* update the input */ if (PA_LATCH_ENABLE(v->acr) == 0) { - if (v->intf->in_a_func) - v->in_a = v->intf->in_a_func(space, 0); + if (intf->in_a_func) + v->in_a = (*intf->in_a_func)(device, 0); else - logerror("%s:6522VIA chip %d: Port A is being read but has no handler\n", cpuexec_describe_context(machine), which); + logerror("%s:6522VIA chip %s: Port A is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag); } /* combine input and output values */ @@ -543,12 +564,12 @@ int via_read(running_machine *machine, int which, int offset) break; case VIA_T1CL: - via_clear_int (machine, which, INT_T1); - val = v_get_counter1_value(v) & 0xFF; + via_clear_int (device, INT_T1); + val = v_get_counter1_value(device) & 0xFF; break; case VIA_T1CH: - val = v_get_counter1_value(v) >> 8; + val = v_get_counter1_value(device) >> 8; break; case VIA_T1LL: @@ -560,37 +581,37 @@ int via_read(running_machine *machine, int which, int offset) break; case VIA_T2CL: - via_clear_int (machine, which, INT_T2); + via_clear_int (device, INT_T2); if (v->t2_active) - val = v_time_to_cycles(v, timer_timeleft(v->t2)) & 0xff; + val = v_time_to_cycles(device, timer_timeleft(v->t2)) & 0xff; else { if (T2_COUNT_PB6(v->acr)) val = v->t2cl; else - val = (0x10000- (v_time_to_cycles(v, attotime_sub(timer_get_time(machine), v->time2)) & 0xffff) - 1) & 0xff; + val = (0x10000- (v_time_to_cycles(device, attotime_sub(timer_get_time(device->machine), v->time2)) & 0xffff) - 1) & 0xff; } break; case VIA_T2CH: if (v->t2_active) - val = v_time_to_cycles(v, timer_timeleft(v->t2)) >> 8; + val = v_time_to_cycles(device, timer_timeleft(v->t2)) >> 8; else { if (T2_COUNT_PB6(v->acr)) val = v->t2ch; else - val = (0x10000- (v_time_to_cycles(v, attotime_sub(timer_get_time(machine), v->time2)) & 0xffff) - 1) >> 8; + val = (0x10000- (v_time_to_cycles(device, attotime_sub(timer_get_time(device->machine), v->time2)) & 0xffff) - 1) >> 8; } break; case VIA_SR: val = v->sr; - via_clear_int(machine, which, INT_SR); + via_clear_int(device, INT_SR); if (SO_O2_CONTROL(v->acr)) { v->shift_counter=0; - timer_set(machine, v_cycles_to_time(v, 2), NULL, which,via_shift_callback); + timer_adjust_oneshot(v->shift_timer, v_cycles_to_time(device, 2), 0); } break; @@ -615,14 +636,13 @@ int via_read(running_machine *machine, int which, int offset) /*------------------------------------------------- - via_write - CPU interface for VIA write + via_w - CPU interface for VIA write -------------------------------------------------*/ -void via_write(running_machine *machine, int which, int offset, int data) +WRITE8_DEVICE_HANDLER(via_w) { - /* temporary hack until this is converted to a device */ - const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM); - via6522_t *v = via + which; + via6522_t *v = get_token(device); + const via6522_interface *intf = get_interface(device); offset &=0x0f; @@ -638,13 +658,13 @@ void via_write(running_machine *machine, int which, int offset, int data) { UINT8 write_data = (v->out_b & v->ddr_b) | (v->ddr_b ^ 0xff); - if (v->intf->out_b_func) - v->intf->out_b_func(space, 0, write_data); + if (intf->out_b_func) + (*intf->out_b_func)(device, 0, write_data); else - logerror("%s:6522VIA chip %d: Port B is being written to but has no handler - %02X\n", cpuexec_describe_context(machine), which, write_data); + logerror("%s:6522VIA chip %s: Port B is being written to but has no handler - %02X\n", cpuexec_describe_context(device->machine), device->tag, write_data); } - CLR_PB_INT(v, which); + CLR_PB_INT(device); /* If CB2 is configured as output and in pulse or handshake mode, CB2 is set now */ @@ -656,10 +676,10 @@ void via_write(running_machine *machine, int which, int offset, int data) v->out_cb2 = 0; /* call the CB2 output function */ - if (v->intf->out_cb2_func) - v->intf->out_cb2_func(space, 0, 0); + if (intf->out_cb2_func) + (*intf->out_cb2_func)(device, 0, 0); else - logerror("%s:6522VIA chip %d: Port CB2 is being written to but has no handler - %02X\n", cpuexec_describe_context(machine), which, 0); + logerror("%s:6522VIA chip %s: Port CB2 is being written to but has no handler - %02X\n", cpuexec_describe_context(device->machine), device->tag, 0); } } break; @@ -671,26 +691,26 @@ void via_write(running_machine *machine, int which, int offset, int data) { UINT8 write_data = (v->out_a & v->ddr_a) | (v->ddr_a ^ 0xff); - if (v->intf->out_a_func) - v->intf->out_a_func(space, 0, write_data); + if (intf->out_a_func) + (*intf->out_a_func)(device, 0, write_data); else - logerror("%s:6522VIA chip %d: Port A is being written to but has no handler - %02X\n", cpuexec_describe_context(machine), which, write_data); + logerror("%s:6522VIA chip %s: Port A is being written to but has no handler - %02X\n", cpuexec_describe_context(device->machine), device->tag, write_data); } - CLR_PA_INT(v, which); + CLR_PA_INT(device); /* If CA2 is configured as output and in pulse or handshake mode, CA2 is set now */ if (CA2_PULSE_OUTPUT(v->pcr)) { /* call the CA2 output function */ - if (v->intf->out_ca2_func) + if (intf->out_ca2_func) { - v->intf->out_ca2_func(space, 0, 0); - v->intf->out_ca2_func(space, 0, 1); + (*intf->out_ca2_func)(device, 0, 0); + (*intf->out_ca2_func)(device, 0, 1); } else - logerror("%s:6522VIA chip %d: Port CA2 is being pulsed but has no handler\n", cpuexec_describe_context(machine), which); + logerror("%s:6522VIA chip %s: Port CA2 is being pulsed but has no handler\n", cpuexec_describe_context(device->machine), device->tag); /* set CA2 (shouldn't be needed) */ v->out_ca2 = 1; @@ -703,10 +723,10 @@ void via_write(running_machine *machine, int which, int offset, int data) v->out_ca2 = 0; /* call the CA2 output function */ - if (v->intf->out_ca2_func) - v->intf->out_ca2_func(space, 0, 0); + if (intf->out_ca2_func) + (*intf->out_ca2_func)(device, 0, 0); else - logerror("%s:6522VIA chip %d: Port CA2 is being written to but has no handler - %02X\n", cpuexec_describe_context(machine), which, 0); + logerror("%s:6522VIA chip %s: Port CA2 is being written to but has no handler - %02X\n", cpuexec_describe_context(device->machine), device->tag, 0); } } @@ -719,10 +739,10 @@ void via_write(running_machine *machine, int which, int offset, int data) { UINT8 write_data = (v->out_a & v->ddr_a) | (v->ddr_a ^ 0xff); - if (v->intf->out_a_func) - v->intf->out_a_func(space, 0, write_data); + if (intf->out_a_func) + (*intf->out_a_func)(device, 0, write_data); else - logerror("%s:6522VIA chip %d: Port A is being written to but has no handler - %02X\n", cpuexec_describe_context(machine), which, write_data); + logerror("%s:6522VIA chip %s: Port A is being written to but has no handler - %02X\n", cpuexec_describe_context(device->machine), device->tag, write_data); } break; @@ -737,10 +757,10 @@ void via_write(running_machine *machine, int which, int offset, int data) { UINT8 write_data = (v->out_b & v->ddr_b) | (v->ddr_b ^ 0xff); - if (v->intf->out_b_func) - v->intf->out_b_func(space, 0, write_data); + if (intf->out_b_func) + (*intf->out_b_func)(device, 0, write_data); else - logerror("%s:6522VIA chip %d: Port B is being written to but has no handler - %02X\n", cpuexec_describe_context(machine), which, write_data); + logerror("%s:6522VIA chip %s: Port B is being written to but has no handler - %02X\n", cpuexec_describe_context(device->machine), device->tag, write_data); } } break; @@ -755,10 +775,10 @@ void via_write(running_machine *machine, int which, int offset, int data) { UINT8 write_data = (v->out_a & v->ddr_a) | (v->ddr_a ^ 0xff); - if (v->intf->out_a_func) - v->intf->out_a_func(space, 0, write_data); + if (intf->out_a_func) + (*intf->out_a_func)(device, 0, write_data); else - logerror("%s:6522VIA chip %d: Port A is being written to but has no handler - %02X\n", cpuexec_describe_context(machine), which, write_data); + logerror("%s:6522VIA chip %s: Port A is being written to but has no handler - %02X\n", cpuexec_describe_context(device->machine), device->tag, write_data); } } break; @@ -770,14 +790,14 @@ void via_write(running_machine *machine, int which, int offset, int data) case VIA_T1LH: v->t1lh = data; - via_clear_int (machine, which, INT_T1); + via_clear_int (device, INT_T1); break; case VIA_T1CH: v->t1ch = v->t1lh = data; v->t1cl = v->t1ll; - via_clear_int (machine, which, INT_T1); + via_clear_int (device, INT_T1); if (T1_SET_PB7(v->acr)) { @@ -787,13 +807,13 @@ void via_write(running_machine *machine, int which, int offset, int data) { UINT8 write_data = (v->out_b & v->ddr_b) | (v->ddr_b ^ 0xff); - if (v->intf->out_b_func) - v->intf->out_b_func(space, 0, write_data); + if (intf->out_b_func) + (*intf->out_b_func)(device, 0, write_data); else - logerror("%s:6522VIA chip %d: Port B is being written to but has no handler - %02X\n", cpuexec_describe_context(machine), which, write_data); + logerror("%s:6522VIA chip %s: Port B is being written to but has no handler - %02X\n", cpuexec_describe_context(device->machine), device->tag, write_data); } } - timer_adjust_oneshot(v->t1, v_cycles_to_time(v, TIMER1_VALUE(v) + IFR_DELAY), which); + timer_adjust_oneshot(v->t1, v_cycles_to_time(device, TIMER1_VALUE(v) + IFR_DELAY), 0); v->t1_active = 1; break; @@ -805,26 +825,26 @@ void via_write(running_machine *machine, int which, int offset, int data) v->t2ch = v->t2lh = data; v->t2cl = v->t2ll; - via_clear_int (machine, which, INT_T2); + via_clear_int (device, INT_T2); if (!T2_COUNT_PB6(v->acr)) { - timer_adjust_oneshot(v->t2, v_cycles_to_time(v, TIMER2_VALUE(v) + IFR_DELAY), which); + timer_adjust_oneshot(v->t2, v_cycles_to_time(device, TIMER2_VALUE(v) + IFR_DELAY), 0); v->t2_active = 1; } else { - v->time2 = timer_get_time(machine); + v->time2 = timer_get_time(device->machine); } break; case VIA_SR: v->sr = data; v->shift_counter=0; - via_clear_int(machine, which, INT_SR); + via_clear_int(device, INT_SR); if (SO_O2_CONTROL(v->acr)) { - timer_set(machine, v_cycles_to_time(v, 2), NULL, which, via_shift_callback); + timer_set(device->machine, v_cycles_to_time(device, 2), (void *) device, 0, via_shift_callback); } break; @@ -832,30 +852,30 @@ void via_write(running_machine *machine, int which, int offset, int data) v->pcr = data; if (TRACE_VIA) - logerror("%s:6522VIA chip %d: PCR = %02X\n", cpuexec_describe_context(machine), which, data); + logerror("%s:6522VIA chip %s: PCR = %02X\n", cpuexec_describe_context(device->machine), device->tag, data); if (CA2_FIX_OUTPUT(data) && CA2_OUTPUT_LEVEL(data) ^ v->out_ca2) { v->out_ca2 = CA2_OUTPUT_LEVEL(data); - if (v->intf->out_ca2_func) - v->intf->out_ca2_func(space, 0, v->out_ca2); + if (intf->out_ca2_func) + (*intf->out_ca2_func)(device, 0, v->out_ca2); else - logerror("%s:6522VIA chip %d: Port CA2 is being written to but has no handler - %02X\n", cpuexec_describe_context(machine), which, v->out_ca2); + logerror("%s:6522VIA chip %s: Port CA2 is being written to but has no handler - %02X\n", cpuexec_describe_context(device->machine), device->tag, v->out_ca2); } if (CB2_FIX_OUTPUT(data) && CB2_OUTPUT_LEVEL(data) ^ v->out_cb2) { v->out_cb2 = CB2_OUTPUT_LEVEL(data); - if (v->intf->out_cb2_func) - v->intf->out_cb2_func(space, 0, v->out_cb2); + if (intf->out_cb2_func) + (*intf->out_cb2_func)(device, 0, v->out_cb2); else - logerror("%s:6522VIA chip %d: Port CB2 is being written to but has no handler - %02X\n", cpuexec_describe_context(machine), which, v->out_cb2); + logerror("%s:6522VIA chip %s: Port CB2 is being written to but has no handler - %02X\n", cpuexec_describe_context(device->machine), device->tag, v->out_cb2); } break; case VIA_ACR: { - UINT16 counter1 = v_get_counter1_value(v); + UINT16 counter1 = v_get_counter1_value(device); v->acr = data; if (T1_SET_PB7(v->acr)) { @@ -868,15 +888,15 @@ void via_write(running_machine *machine, int which, int offset, int data) { UINT8 write_data = (v->out_b & v->ddr_b) | (v->ddr_b ^ 0xff); - if (v->intf->out_b_func) - v->intf->out_b_func(space, 0, write_data); + if (intf->out_b_func) + (*intf->out_b_func)(device, 0, write_data); else - logerror("%s:6522VIA chip %d: Port B is being written to but has no handler - %02X\n", cpuexec_describe_context(machine), which, write_data); + logerror("%s:6522VIA chip %s: Port B is being written to but has no handler - %02X\n", cpuexec_describe_context(device->machine), device->tag, write_data); } } if (T1_CONTINUOUS(data)) { - timer_adjust_oneshot(v->t1, v_cycles_to_time(v, counter1 + IFR_DELAY), which); + timer_adjust_oneshot(v->t1, v_cycles_to_time(device, counter1 + IFR_DELAY), 0); v->t1_active = 1; } } @@ -893,10 +913,10 @@ void via_write(running_machine *machine, int which, int offset, int data) if (((v->ifr & v->ier) & 0x7f) == 0) { v->ifr &= ~INT_ANY; - if (v->intf->irq_func) - (*v->intf->irq_func)(machine, CLEAR_LINE); + if (intf->irq_func) + (*intf->irq_func)(device, CLEAR_LINE); // else -// logerror("%s:6522VIA chip %d: Interrupt is cleared but there is no callback function\n", cpuexec_describe_context(machine), which); +// logerror("%s:6522VIA chip %s: Interrupt is cleared but there is no callback function\n", cpuexec_describe_context(device->machine), device->tag); } } else @@ -904,10 +924,10 @@ void via_write(running_machine *machine, int which, int offset, int data) if ((v->ier & v->ifr) & 0x7f) { v->ifr |= INT_ANY; - if (v->intf->irq_func) - (*v->intf->irq_func)(machine, ASSERT_LINE); + if (intf->irq_func) + (*intf->irq_func)(device, ASSERT_LINE); else - logerror("%s:6522VIA chip %d: Interrupt is asserted but there is no callback function\n", cpuexec_describe_context(machine), which); + logerror("%s:6522VIA chip %s: Interrupt is asserted but there is no callback function\n", cpuexec_describe_context(device->machine), device->tag); } } break; @@ -915,20 +935,20 @@ void via_write(running_machine *machine, int which, int offset, int data) case VIA_IFR: if (data & INT_ANY) data = 0x7f; - via_clear_int (machine, which, data); + via_clear_int (device, data); break; } } /*------------------------------------------------- - via_set_input_a - interface setting VIA port + via_porta_w - interface setting VIA port A input -------------------------------------------------*/ -void via_set_input_a(int which, int data) +WRITE8_DEVICE_HANDLER(via_porta_w) { - via6522_t *v = via + which; + via6522_t *v = get_token(device); /* set the input, what could be easier? */ v->in_a = data; @@ -936,15 +956,26 @@ void via_set_input_a(int which, int data) /*------------------------------------------------- - via_set_input_ca1 - interface setting VIA port + via_ca1_r - interface retrieving VIA port CA1 input -------------------------------------------------*/ -void via_set_input_ca1(running_machine *machine, int which, int data) +READ8_DEVICE_HANDLER(via_ca1_r) { - /* temporary hack until this is converted to a device */ - const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM); - via6522_t *v = via + which; + via6522_t *v = get_token(device); + return v->in_ca1; +} + + +/*------------------------------------------------- + via_ca1_w - interface setting VIA port + CA1 input +-------------------------------------------------*/ + +WRITE8_DEVICE_HANDLER(via_ca1_w) +{ + via6522_t *v = get_token(device); + const via6522_interface *intf = get_interface(device); /* limit the data to 0 or 1 */ data = data ? 1 : 0; @@ -953,19 +984,19 @@ void via_set_input_ca1(running_machine *machine, int which, int data) if (data != v->in_ca1) { if (TRACE_VIA) - logerror("%s:6522VIA chip %d: CA1 = %02X\n", cpuexec_describe_context(machine), which, data); + logerror("%s:6522VIA chip %s: CA1 = %02X\n", cpuexec_describe_context(device->machine), device->tag, data); if ((CA1_LOW_TO_HIGH(v->pcr) && data) || (CA1_HIGH_TO_LOW(v->pcr) && !data)) { if (PA_LATCH_ENABLE(v->acr)) { - if (v->intf->in_a_func) - v->in_a = v->intf->in_a_func(space, 0); + if (intf->in_a_func) + v->in_a = (*intf->in_a_func)(device, 0); else - logerror("%s:6522VIA chip %d: Port A is being read but has no handler\n", cpuexec_describe_context(machine), which); + logerror("%s:6522VIA chip %s: Port A is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag); } - via_set_int (machine, which, INT_CA1); + via_set_int (device, INT_CA1); /* CA2 is configured as output and in pulse or handshake mode, CA2 is cleared now */ @@ -977,10 +1008,10 @@ void via_set_input_ca1(running_machine *machine, int which, int data) v->out_ca2 = 1; /* call the CA2 output function */ - if (v->intf->out_ca2_func) - v->intf->out_ca2_func(space, 0, 1); + if (intf->out_ca2_func) + (*intf->out_ca2_func)(device, 0, 1); else - logerror("%s:6522VIA chip %d: Port CA2 is being written to but has no handler - %02X\n", cpuexec_describe_context(machine), which, 1); + logerror("%s:6522VIA chip %s: Port CA2 is being written to but has no handler - %02X\n", cpuexec_describe_context(device->machine), device->tag, 1); } } } @@ -991,13 +1022,25 @@ void via_set_input_ca1(running_machine *machine, int which, int data) /*------------------------------------------------- - via_set_input_ca2 - interface setting VIA port + via_ca2_r - interface retrieving VIA port CA2 input -------------------------------------------------*/ -void via_set_input_ca2(running_machine *machine, int which, int data) +READ8_DEVICE_HANDLER(via_ca2_r) { - via6522_t *v = via + which; + via6522_t *v = get_token(device); + return v->in_ca2; +} + + +/*------------------------------------------------- + via_ca2_w - interface setting VIA port + CA2 input +-------------------------------------------------*/ + +WRITE8_DEVICE_HANDLER(via_ca2_w) +{ + via6522_t *v = get_token(device); /* limit the data to 0 or 1 */ data = data ? 1 : 0; @@ -1012,7 +1055,7 @@ void via_set_input_ca2(running_machine *machine, int which, int data) if ((data && CA2_LOW_TO_HIGH(v->pcr)) || (!data && CA2_HIGH_TO_LOW(v->pcr))) { /* mark the IRQ */ - via_set_int (machine, which, INT_CA2); + via_set_int (device, INT_CA2); } /* set the new value for CA2 */ v->in_ca2 = data; @@ -1024,13 +1067,25 @@ void via_set_input_ca2(running_machine *machine, int which, int data) /*------------------------------------------------- - via_set_input_b - interface setting VIA port + via_portb_r - interface retrieving VIA port B input -------------------------------------------------*/ -void via_set_input_b(int which, int data) +READ8_DEVICE_HANDLER(via_portb_r) { - via6522_t *v = via + which; + via6522_t *v = get_token(device); + return v->in_b; +} + + +/*------------------------------------------------- + via_portb_w - interface setting VIA port + B input +-------------------------------------------------*/ + +WRITE8_DEVICE_HANDLER(via_portb_w) +{ + via6522_t *v = get_token(device); /* set the input, what could be easier? */ v->in_b = data; @@ -1038,15 +1093,26 @@ void via_set_input_b(int which, int data) /*------------------------------------------------- - via_set_input_cb1 - interface setting VIA port + via_cb1_r - interface retrieving VIA port CB1 input -------------------------------------------------*/ -void via_set_input_cb1(running_machine *machine, int which, int data) +READ8_DEVICE_HANDLER(via_cb1_r) { - /* temporary hack until this is converted to a device */ - const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM); - via6522_t *v = via + which; + via6522_t *v = get_token(device); + return v->in_cb1; +} + + +/*------------------------------------------------- + via_cb1_w - interface setting VIA port + CB1 input +-------------------------------------------------*/ + +WRITE8_DEVICE_HANDLER(via_cb1_w) +{ + via6522_t *v = get_token(device); + const via6522_interface *intf = get_interface(device); /* limit the data to 0 or 1 */ data = data ? 1 : 0; @@ -1058,15 +1124,15 @@ void via_set_input_cb1(running_machine *machine, int which, int data) { if (PB_LATCH_ENABLE(v->acr)) { - if (v->intf->in_b_func) - v->in_b = v->intf->in_b_func(space, 0); + if (intf->in_b_func) + v->in_b = (*intf->in_b_func)(device, 0); else - logerror("%s:6522VIA chip %d: Port B is being read but has no handler\n", cpuexec_describe_context(machine), which); + logerror("%s:6522VIA chip %s: Port B is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag); } if (SO_EXT_CONTROL(v->acr) || SI_EXT_CONTROL(v->acr)) - via_shift (machine, which); + via_shift (device); - via_set_int (machine, which, INT_CB1); + via_set_int (device, INT_CB1); /* CB2 is configured as output and in pulse or handshake mode, CB2 is cleared now */ @@ -1078,10 +1144,10 @@ void via_set_input_cb1(running_machine *machine, int which, int data) v->out_cb2 = 1; /* call the CB2 output function */ - if (v->intf->out_cb2_func) - v->intf->out_cb2_func(space, 0, 1); + if (intf->out_cb2_func) + (*intf->out_cb2_func)(device, 0, 1); else - logerror("%s:6522VIA chip %d: Port CB2 is being written to but has no handler - %02X\n", cpuexec_describe_context(machine), which, 1); + logerror("%s:6522VIA chip %s: Port CB2 is being written to but has no handler - %02X\n", cpuexec_describe_context(device->machine), device->tag, 1); } } } @@ -1091,13 +1157,25 @@ void via_set_input_cb1(running_machine *machine, int which, int data) /*------------------------------------------------- - via_set_input_cb2 - interface setting VIA port + via_cb2_r - interface retrieving VIA port CB2 input -------------------------------------------------*/ -void via_set_input_cb2(running_machine *machine, int which, int data) +READ8_DEVICE_HANDLER(via_cb2_r) { - via6522_t *v = via + which; + via6522_t *v = get_token(device); + return v->in_cb2; +} + + +/*------------------------------------------------- + via_cb2_w - interface setting VIA port + CB2 input +-------------------------------------------------*/ + +WRITE8_DEVICE_HANDLER(via_cb2_w) +{ + via6522_t *v = get_token(device); /* limit the data to 0 or 1 */ data = data ? 1 : 0; @@ -1112,7 +1190,7 @@ void via_set_input_cb2(running_machine *machine, int which, int data) if ((data && CB2_LOW_TO_HIGH(v->pcr)) || (!data && CB2_HIGH_TO_LOW(v->pcr))) { /* mark the IRQ */ - via_set_int (machine, which, INT_CB2); + via_set_int (device, INT_CB2); } /* set the new value for CB2 */ v->in_cb2 = data; @@ -1120,130 +1198,44 @@ void via_set_input_cb2(running_machine *machine, int which, int data) } } -/******************* Standard 8-bit CPU interfaces, D0-D7 *******************/ -READ8_HANDLER( via_0_r) { return via_read(space->machine, 0, offset); } -READ8_HANDLER( via_1_r) { return via_read(space->machine, 1, offset); } -READ8_HANDLER( via_2_r) { return via_read(space->machine, 2, offset); } -READ8_HANDLER( via_3_r) { return via_read(space->machine, 3, offset); } -READ8_HANDLER( via_4_r) { return via_read(space->machine, 4, offset); } -READ8_HANDLER( via_5_r) { return via_read(space->machine, 5, offset); } -READ8_HANDLER( via_6_r) { return via_read(space->machine, 6, offset); } -READ8_HANDLER( via_7_r) { return via_read(space->machine, 7, offset); } +/*------------------------------------------------- + DEVICE_SET_INFO( via6522 ) +-------------------------------------------------*/ -WRITE8_HANDLER( via_0_w) { via_write(space->machine, 0, offset, data); } -WRITE8_HANDLER( via_1_w) { via_write(space->machine, 1, offset, data); } -WRITE8_HANDLER( via_2_w) { via_write(space->machine, 2, offset, data); } -WRITE8_HANDLER( via_3_w) { via_write(space->machine, 3, offset, data); } -WRITE8_HANDLER( via_4_w) { via_write(space->machine, 4, offset, data); } -WRITE8_HANDLER( via_5_w) { via_write(space->machine, 5, offset, data); } -WRITE8_HANDLER( via_6_w) { via_write(space->machine, 6, offset, data); } -WRITE8_HANDLER( via_7_w) { via_write(space->machine, 7, offset, data); } +static DEVICE_SET_INFO( via6522 ) +{ + switch (state) + { + /* no parameters to set */ + } +} -/******************* 8-bit A/B port interfaces *******************/ -WRITE8_HANDLER( via_0_porta_w) { via_set_input_a(0, data); } -WRITE8_HANDLER( via_1_porta_w) { via_set_input_a(1, data); } -WRITE8_HANDLER( via_2_porta_w) { via_set_input_a(2, data); } -WRITE8_HANDLER( via_3_porta_w) { via_set_input_a(3, data); } -WRITE8_HANDLER( via_4_porta_w) { via_set_input_a(4, data); } -WRITE8_HANDLER( via_5_porta_w) { via_set_input_a(5, data); } -WRITE8_HANDLER( via_6_porta_w) { via_set_input_a(6, data); } -WRITE8_HANDLER( via_7_porta_w) { via_set_input_a(7, data); } +/*------------------------------------------------- + DEVICE_GET_INFO( via6522 ) +-------------------------------------------------*/ -WRITE8_HANDLER( via_0_portb_w) { via_set_input_b(0, data); } -WRITE8_HANDLER( via_1_portb_w) { via_set_input_b(1, data); } -WRITE8_HANDLER( via_2_portb_w) { via_set_input_b(2, data); } -WRITE8_HANDLER( via_3_portb_w) { via_set_input_b(3, data); } -WRITE8_HANDLER( via_4_portb_w) { via_set_input_b(4, data); } -WRITE8_HANDLER( via_5_portb_w) { via_set_input_b(5, data); } -WRITE8_HANDLER( via_6_portb_w) { via_set_input_b(6, data); } -WRITE8_HANDLER( via_7_portb_w) { via_set_input_b(7, data); } +DEVICE_GET_INFO(via6522) +{ + switch (state) + { + /* --- the following bits of info are returned as 64-bit signed integers --- */ + case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(via6522_t); break; + case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = sizeof(via6522_inline_config); break; + case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; -READ8_HANDLER( via_0_porta_r) { return via[0].in_a; } -READ8_HANDLER( via_1_porta_r) { return via[1].in_a; } -READ8_HANDLER( via_2_porta_r) { return via[2].in_a; } -READ8_HANDLER( via_3_porta_r) { return via[3].in_a; } -READ8_HANDLER( via_4_porta_r) { return via[4].in_a; } -READ8_HANDLER( via_5_porta_r) { return via[5].in_a; } -READ8_HANDLER( via_6_porta_r) { return via[6].in_a; } -READ8_HANDLER( via_7_porta_r) { return via[7].in_a; } + /* --- the following bits of info are returned as pointers to data or functions --- */ + case DEVINFO_FCT_SET_INFO: info->set_info = DEVICE_SET_INFO_NAME(via6522); break; + case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(via6522); break; + case DEVINFO_FCT_STOP: /* Nothing */ break; + case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(via6522); break; -READ8_HANDLER( via_0_portb_r) { return via[0].in_b; } -READ8_HANDLER( via_1_portb_r) { return via[1].in_b; } -READ8_HANDLER( via_2_portb_r) { return via[2].in_b; } -READ8_HANDLER( via_3_portb_r) { return via[3].in_b; } -READ8_HANDLER( via_4_portb_r) { return via[4].in_b; } -READ8_HANDLER( via_5_portb_r) { return via[5].in_b; } -READ8_HANDLER( via_6_portb_r) { return via[6].in_b; } -READ8_HANDLER( via_7_portb_r) { return via[7].in_b; } - -/******************* 1-bit CA1/CA2/CB1/CB2 port interfaces *******************/ - -WRITE8_HANDLER( via_0_ca1_w) { via_set_input_ca1(space->machine, 0, data); } -WRITE8_HANDLER( via_1_ca1_w) { via_set_input_ca1(space->machine, 1, data); } -WRITE8_HANDLER( via_2_ca1_w) { via_set_input_ca1(space->machine, 2, data); } -WRITE8_HANDLER( via_3_ca1_w) { via_set_input_ca1(space->machine, 3, data); } -WRITE8_HANDLER( via_4_ca1_w) { via_set_input_ca1(space->machine, 4, data); } -WRITE8_HANDLER( via_5_ca1_w) { via_set_input_ca1(space->machine, 5, data); } -WRITE8_HANDLER( via_6_ca1_w) { via_set_input_ca1(space->machine, 6, data); } -WRITE8_HANDLER( via_7_ca1_w) { via_set_input_ca1(space->machine, 7, data); } -WRITE8_HANDLER( via_0_ca2_w) { via_set_input_ca2(space->machine, 0, data); } -WRITE8_HANDLER( via_1_ca2_w) { via_set_input_ca2(space->machine, 1, data); } -WRITE8_HANDLER( via_2_ca2_w) { via_set_input_ca2(space->machine, 2, data); } -WRITE8_HANDLER( via_3_ca2_w) { via_set_input_ca2(space->machine, 3, data); } -WRITE8_HANDLER( via_4_ca2_w) { via_set_input_ca2(space->machine, 4, data); } -WRITE8_HANDLER( via_5_ca2_w) { via_set_input_ca2(space->machine, 5, data); } -WRITE8_HANDLER( via_6_ca2_w) { via_set_input_ca2(space->machine, 6, data); } -WRITE8_HANDLER( via_7_ca2_w) { via_set_input_ca2(space->machine, 7, data); } - -WRITE8_HANDLER( via_0_cb1_w) { via_set_input_cb1(space->machine, 0, data); } -WRITE8_HANDLER( via_1_cb1_w) { via_set_input_cb1(space->machine, 1, data); } -WRITE8_HANDLER( via_2_cb1_w) { via_set_input_cb1(space->machine, 2, data); } -WRITE8_HANDLER( via_3_cb1_w) { via_set_input_cb1(space->machine, 3, data); } -WRITE8_HANDLER( via_4_cb1_w) { via_set_input_cb1(space->machine, 4, data); } -WRITE8_HANDLER( via_5_cb1_w) { via_set_input_cb1(space->machine, 5, data); } -WRITE8_HANDLER( via_6_cb1_w) { via_set_input_cb1(space->machine, 6, data); } -WRITE8_HANDLER( via_7_cb1_w) { via_set_input_cb1(space->machine, 7, data); } -WRITE8_HANDLER( via_0_cb2_w) { via_set_input_cb2(space->machine, 0, data); } -WRITE8_HANDLER( via_1_cb2_w) { via_set_input_cb2(space->machine, 1, data); } -WRITE8_HANDLER( via_2_cb2_w) { via_set_input_cb2(space->machine, 2, data); } -WRITE8_HANDLER( via_3_cb2_w) { via_set_input_cb2(space->machine, 3, data); } -WRITE8_HANDLER( via_4_cb2_w) { via_set_input_cb2(space->machine, 4, data); } -WRITE8_HANDLER( via_5_cb2_w) { via_set_input_cb2(space->machine, 5, data); } -WRITE8_HANDLER( via_6_cb2_w) { via_set_input_cb2(space->machine, 6, data); } -WRITE8_HANDLER( via_7_cb2_w) { via_set_input_cb2(space->machine, 7, data); } - -READ8_HANDLER( via_0_ca1_r) { return via[0].in_ca1; } -READ8_HANDLER( via_1_ca1_r) { return via[1].in_ca1; } -READ8_HANDLER( via_2_ca1_r) { return via[2].in_ca1; } -READ8_HANDLER( via_3_ca1_r) { return via[3].in_ca1; } -READ8_HANDLER( via_4_ca1_r) { return via[4].in_ca1; } -READ8_HANDLER( via_5_ca1_r) { return via[5].in_ca1; } -READ8_HANDLER( via_6_ca1_r) { return via[6].in_ca1; } -READ8_HANDLER( via_7_ca1_r) { return via[7].in_ca1; } -READ8_HANDLER( via_0_ca2_r) { return via[0].in_ca2; } -READ8_HANDLER( via_1_ca2_r) { return via[1].in_ca2; } -READ8_HANDLER( via_2_ca2_r) { return via[2].in_ca2; } -READ8_HANDLER( via_3_ca2_r) { return via[3].in_ca2; } -READ8_HANDLER( via_4_ca2_r) { return via[4].in_ca2; } -READ8_HANDLER( via_5_ca2_r) { return via[5].in_ca2; } -READ8_HANDLER( via_6_ca2_r) { return via[6].in_ca2; } -READ8_HANDLER( via_7_ca2_r) { return via[7].in_ca2; } - -READ8_HANDLER( via_0_cb1_r) { return via[0].in_cb1; } -READ8_HANDLER( via_1_cb1_r) { return via[1].in_cb1; } -READ8_HANDLER( via_2_cb1_r) { return via[2].in_cb1; } -READ8_HANDLER( via_3_cb1_r) { return via[3].in_cb1; } -READ8_HANDLER( via_4_cb1_r) { return via[4].in_cb1; } -READ8_HANDLER( via_5_cb1_r) { return via[5].in_cb1; } -READ8_HANDLER( via_6_cb1_r) { return via[6].in_cb1; } -READ8_HANDLER( via_7_cb1_r) { return via[7].in_cb1; } -READ8_HANDLER( via_0_cb2_r) { return via[0].in_cb2; } -READ8_HANDLER( via_1_cb2_r) { return via[1].in_cb2; } -READ8_HANDLER( via_2_cb2_r) { return via[2].in_cb2; } -READ8_HANDLER( via_3_cb2_r) { return via[3].in_cb2; } -READ8_HANDLER( via_4_cb2_r) { return via[4].in_cb2; } -READ8_HANDLER( via_5_cb2_r) { return via[5].in_cb2; } -READ8_HANDLER( via_6_cb2_r) { return via[6].in_cb2; } -READ8_HANDLER( via_7_cb2_r) { return via[7].in_cb2; } + /* --- the following bits of info are returned as NULL-terminated strings --- */ + case DEVINFO_STR_NAME: info->s = "6522 VIA"; break; + case DEVINFO_STR_FAMILY: info->s = "6522 VIA"; break; + case DEVINFO_STR_VERSION: info->s = "1.0"; break; + case DEVINFO_STR_SOURCE_FILE: info->s = __FILE__; break; + case DEVINFO_STR_CREDITS: /* Nothing */ break; + } +} diff --git a/src/emu/machine/6522via.h b/src/emu/machine/6522via.h index 9ba5739c694..bdcfe641a4a 100644 --- a/src/emu/machine/6522via.h +++ b/src/emu/machine/6522via.h @@ -2,7 +2,7 @@ Rockwell 6522 VIA interface and emulation - This function emulates all the functionality of up to 8 6522 + This function emulates all the functionality of 6522 versatile interface adapters. This is based on the M6821 emulation in MAME. @@ -19,7 +19,15 @@ MACROS / CONSTANTS ***************************************************************************/ -#define MAX_VIA 8 +#define VIA6522 DEVICE_GET_INFO_NAME(via6522) + +#define MDRV_VIA6522_ADD(_tag, _clock, _intrf) \ + MDRV_DEVICE_ADD(_tag, VIA6522) \ + MDRV_DEVICE_CONFIG_DATA32(via6522_inline_config, clck, _clock) \ + MDRV_DEVICE_CONFIG(_intrf) + +#define MDRV_VIA6522_REMOVE(_tag) \ + MDRV_DEVICE_REMOVE(_tag, VIA6522) #define VIA_PB 0 #define VIA_PA 1 @@ -46,19 +54,25 @@ typedef struct _via6522_interface via6522_interface; struct _via6522_interface { - read8_space_func in_a_func; - read8_space_func in_b_func; - read8_space_func in_ca1_func; - read8_space_func in_cb1_func; - read8_space_func in_ca2_func; - read8_space_func in_cb2_func; - write8_space_func out_a_func; - write8_space_func out_b_func; - write8_space_func out_ca1_func; - write8_space_func out_cb1_func; - write8_space_func out_ca2_func; - write8_space_func out_cb2_func; - void (*irq_func)(running_machine *machine, int state); + read8_device_func in_a_func; + read8_device_func in_b_func; + read8_device_func in_ca1_func; + read8_device_func in_cb1_func; + read8_device_func in_ca2_func; + read8_device_func in_cb2_func; + write8_device_func out_a_func; + write8_device_func out_b_func; + write8_device_func out_ca1_func; + write8_device_func out_cb1_func; + write8_device_func out_ca2_func; + write8_device_func out_cb2_func; + void (*irq_func)(const device_config *device, int state); +}; + +typedef struct _via6522_inline_config via6522_inline_config; +struct _via6522_inline_config +{ + int clck; }; @@ -66,144 +80,27 @@ struct _via6522_interface PROTOTYPES ***************************************************************************/ -void via_set_clock(int which,int clck); -void via_config(int which, const via6522_interface *intf); -void via_reset(void); -int via_read(running_machine *machine, int which, int offset); -void via_write(running_machine *machine, int which, int offset, int data); -void via_set_input_a(int which, int data); -void via_set_input_ca1(running_machine *machine, int which, int data); -void via_set_input_ca2(running_machine *machine, int which, int data); -void via_set_input_b(int which, int data); -void via_set_input_cb1(running_machine *machine, int which, int data); -void via_set_input_cb2(running_machine *machine, int which, int data); +DEVICE_GET_INFO(via6522); -/******************* Standard 8-bit CPU interfaces, D0-D7 *******************/ +READ8_DEVICE_HANDLER(via_r); +WRITE8_DEVICE_HANDLER(via_w); -READ8_HANDLER( via_0_r ); -READ8_HANDLER( via_1_r ); -READ8_HANDLER( via_2_r ); -READ8_HANDLER( via_3_r ); -READ8_HANDLER( via_4_r ); -READ8_HANDLER( via_5_r ); -READ8_HANDLER( via_6_r ); -READ8_HANDLER( via_7_r ); +READ8_DEVICE_HANDLER(via_porta_r); +WRITE8_DEVICE_HANDLER(via_porta_w); -WRITE8_HANDLER( via_0_w ); -WRITE8_HANDLER( via_1_w ); -WRITE8_HANDLER( via_2_w ); -WRITE8_HANDLER( via_3_w ); -WRITE8_HANDLER( via_4_w ); -WRITE8_HANDLER( via_5_w ); -WRITE8_HANDLER( via_6_w ); -WRITE8_HANDLER( via_7_w ); +READ8_DEVICE_HANDLER(via_portb_r); +WRITE8_DEVICE_HANDLER(via_portb_w); -/******************* 8-bit A/B port interfaces *******************/ +READ8_DEVICE_HANDLER(via_ca1_r); +WRITE8_DEVICE_HANDLER(via_ca1_w); -WRITE8_HANDLER( via_0_porta_w ); -WRITE8_HANDLER( via_1_porta_w ); -WRITE8_HANDLER( via_2_porta_w ); -WRITE8_HANDLER( via_3_porta_w ); -WRITE8_HANDLER( via_4_porta_w ); -WRITE8_HANDLER( via_5_porta_w ); -WRITE8_HANDLER( via_6_porta_w ); -WRITE8_HANDLER( via_7_porta_w ); +READ8_DEVICE_HANDLER(via_ca2_r); +WRITE8_DEVICE_HANDLER(via_ca2_w); -WRITE8_HANDLER( via_0_portb_w ); -WRITE8_HANDLER( via_1_portb_w ); -WRITE8_HANDLER( via_2_portb_w ); -WRITE8_HANDLER( via_3_portb_w ); -WRITE8_HANDLER( via_4_portb_w ); -WRITE8_HANDLER( via_5_portb_w ); -WRITE8_HANDLER( via_6_portb_w ); -WRITE8_HANDLER( via_7_portb_w ); +READ8_DEVICE_HANDLER(via_cb1_r); +WRITE8_DEVICE_HANDLER(via_cb1_w); -READ8_HANDLER( via_0_porta_r ); -READ8_HANDLER( via_1_porta_r ); -READ8_HANDLER( via_2_porta_r ); -READ8_HANDLER( via_3_porta_r ); -READ8_HANDLER( via_4_porta_r ); -READ8_HANDLER( via_5_porta_r ); -READ8_HANDLER( via_6_porta_r ); -READ8_HANDLER( via_7_porta_r ); - -READ8_HANDLER( via_0_portb_r ); -READ8_HANDLER( via_1_portb_r ); -READ8_HANDLER( via_2_portb_r ); -READ8_HANDLER( via_3_portb_r ); -READ8_HANDLER( via_4_portb_r ); -READ8_HANDLER( via_5_portb_r ); -READ8_HANDLER( via_6_portb_r ); -READ8_HANDLER( via_7_portb_r ); - -/******************* 1-bit CA1/CA2/CB1/CB2 port interfaces *******************/ - -WRITE8_HANDLER( via_0_ca1_w ); -WRITE8_HANDLER( via_1_ca1_w ); -WRITE8_HANDLER( via_2_ca1_w ); -WRITE8_HANDLER( via_3_ca1_w ); -WRITE8_HANDLER( via_4_ca1_w ); -WRITE8_HANDLER( via_5_ca1_w ); -WRITE8_HANDLER( via_6_ca1_w ); -WRITE8_HANDLER( via_7_ca1_w ); -WRITE8_HANDLER( via_0_ca2_w ); -WRITE8_HANDLER( via_1_ca2_w ); -WRITE8_HANDLER( via_2_ca2_w ); -WRITE8_HANDLER( via_3_ca2_w ); -WRITE8_HANDLER( via_4_ca2_w ); -WRITE8_HANDLER( via_5_ca2_w ); -WRITE8_HANDLER( via_6_ca2_w ); -WRITE8_HANDLER( via_7_ca2_w ); - -WRITE8_HANDLER( via_0_cb1_w ); -WRITE8_HANDLER( via_1_cb1_w ); -WRITE8_HANDLER( via_2_cb1_w ); -WRITE8_HANDLER( via_3_cb1_w ); -WRITE8_HANDLER( via_4_cb1_w ); -WRITE8_HANDLER( via_5_cb1_w ); -WRITE8_HANDLER( via_6_cb1_w ); -WRITE8_HANDLER( via_7_cb1_w ); -WRITE8_HANDLER( via_0_cb2_w ); -WRITE8_HANDLER( via_1_cb2_w ); -WRITE8_HANDLER( via_2_cb2_w ); -WRITE8_HANDLER( via_3_cb2_w ); -WRITE8_HANDLER( via_4_cb2_w ); -WRITE8_HANDLER( via_5_cb2_w ); -WRITE8_HANDLER( via_6_cb2_w ); -WRITE8_HANDLER( via_7_cb2_w ); - -READ8_HANDLER( via_0_ca1_r ); -READ8_HANDLER( via_1_ca1_r ); -READ8_HANDLER( via_2_ca1_r ); -READ8_HANDLER( via_3_ca1_r ); -READ8_HANDLER( via_4_ca1_r ); -READ8_HANDLER( via_5_ca1_r ); -READ8_HANDLER( via_6_ca1_r ); -READ8_HANDLER( via_7_ca1_r ); -READ8_HANDLER( via_0_ca2_r ); -READ8_HANDLER( via_1_ca2_r ); -READ8_HANDLER( via_2_ca2_r ); -READ8_HANDLER( via_3_ca2_r ); -READ8_HANDLER( via_4_ca2_r ); -READ8_HANDLER( via_5_ca2_r ); -READ8_HANDLER( via_6_ca2_r ); -READ8_HANDLER( via_7_ca2_r ); - -READ8_HANDLER( via_0_cb1_r ); -READ8_HANDLER( via_1_cb1_r ); -READ8_HANDLER( via_2_cb1_r ); -READ8_HANDLER( via_3_cb1_r ); -READ8_HANDLER( via_4_cb1_r ); -READ8_HANDLER( via_5_cb1_r ); -READ8_HANDLER( via_6_cb1_r ); -READ8_HANDLER( via_7_cb1_r ); -READ8_HANDLER( via_0_cb2_r ); -READ8_HANDLER( via_1_cb2_r ); -READ8_HANDLER( via_2_cb2_r ); -READ8_HANDLER( via_3_cb2_r ); -READ8_HANDLER( via_4_cb2_r ); -READ8_HANDLER( via_5_cb2_r ); -READ8_HANDLER( via_6_cb2_r ); -READ8_HANDLER( via_7_cb2_r ); +READ8_DEVICE_HANDLER(via_cb2_r); +WRITE8_DEVICE_HANDLER(via_cb2_w); #endif /* __6522VIA_H__ */ diff --git a/src/mame/drivers/atarisy1.c b/src/mame/drivers/atarisy1.c index 1c4368db0ec..646180cef15 100644 --- a/src/mame/drivers/atarisy1.c +++ b/src/mame/drivers/atarisy1.c @@ -336,20 +336,21 @@ static READ8_HANDLER( switch_6502_r ) * D5 = LED (out) */ -static WRITE8_HANDLER( via_pa_w ) +static WRITE8_DEVICE_HANDLER( via_pa_w ) { tms5220_out_data = data; } -static READ8_HANDLER( via_pa_r ) +static READ8_DEVICE_HANDLER( via_pa_r ) { return tms5220_in_data; } -static WRITE8_HANDLER( via_pb_w ) +static WRITE8_DEVICE_HANDLER( via_pb_w ) { + const address_space *space = cpu_get_address_space(device->machine->cpu[0], ADDRESS_SPACE_PROGRAM); UINT8 old = tms5220_ctl; tms5220_ctl = data; @@ -367,7 +368,7 @@ static WRITE8_HANDLER( via_pb_w ) } -static READ8_HANDLER( via_pb_r ) +static READ8_DEVICE_HANDLER( via_pb_r ) { return (!tms5220_ready_r() << 2) | (!tms5220_int_r() << 3); } @@ -439,7 +440,7 @@ ADDRESS_MAP_END static ADDRESS_MAP_START( sound_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x0fff) AM_RAM - AM_RANGE(0x1000, 0x100f) AM_READWRITE(via_0_r, via_0_w) + AM_RANGE(0x1000, 0x100f) AM_DEVREADWRITE(VIA6522, "via6522_0", via_r, via_w) AM_RANGE(0x1800, 0x1800) AM_WRITE(ym2151_register_port_0_w) AM_RANGE(0x1800, 0x1801) AM_READWRITE(ym2151_status_port_0_r, ym2151_data_port_0_w) AM_RANGE(0x1810, 0x1810) AM_READWRITE(atarigen_6502_sound_r, atarigen_6502_sound_w) @@ -738,6 +739,9 @@ static MACHINE_DRIVER_START( atarisy1 ) MDRV_SOUND_ADD("tms", TMS5220, ATARI_CLOCK_14MHz/2/11) MDRV_SOUND_ROUTE(ALL_OUTPUTS, "left", 1.0) MDRV_SOUND_ROUTE(ALL_OUTPUTS, "right", 1.0) + + /* via */ + MDRV_VIA6522_ADD("via6522_0", 0, via_interface) MACHINE_DRIVER_END @@ -2141,8 +2145,6 @@ ROM_END static DRIVER_INIT( marble ) { - via_config(0, &via_interface); - atarigen_eeprom_default = NULL; atarigen_slapstic_init(machine, 0, 0x080000, 0, 103); @@ -2153,8 +2155,6 @@ static DRIVER_INIT( marble ) static DRIVER_INIT( peterpak ) { - via_config(0, &via_interface); - atarigen_eeprom_default = NULL; atarigen_slapstic_init(machine, 0, 0x080000, 0, 107); @@ -2165,8 +2165,6 @@ static DRIVER_INIT( peterpak ) static DRIVER_INIT( indytemp ) { - via_config(0, &via_interface); - atarigen_eeprom_default = NULL; atarigen_slapstic_init(machine, 0, 0x080000, 0, 105); @@ -2177,8 +2175,6 @@ static DRIVER_INIT( indytemp ) static DRIVER_INIT( roadrunn ) { - via_config(0, &via_interface); - atarigen_eeprom_default = NULL; atarigen_slapstic_init(machine, 0, 0x080000, 0, 108); @@ -2189,8 +2185,6 @@ static DRIVER_INIT( roadrunn ) static DRIVER_INIT( roadb109 ) { - via_config(0, &via_interface); - atarigen_eeprom_default = NULL; atarigen_slapstic_init(machine, 0, 0x080000, 0, 109); @@ -2201,8 +2195,6 @@ static DRIVER_INIT( roadb109 ) static DRIVER_INIT( roadb110 ) { - via_config(0, &via_interface); - atarigen_eeprom_default = NULL; atarigen_slapstic_init(machine, 0, 0x080000, 0, 110); diff --git a/src/mame/drivers/beezer.c b/src/mame/drivers/beezer.c index 53527a2a8ac..767e80e77a3 100644 --- a/src/mame/drivers/beezer.c +++ b/src/mame/drivers/beezer.c @@ -23,7 +23,7 @@ ADDRESS_MAP_END static ADDRESS_MAP_START( sound_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x07ff) AM_RAM // AM_RANGE(0x1000, 0x10ff) AM_READWRITE(beezer_6840_r, beezer_6840_w) - AM_RANGE(0x1800, 0x18ff) AM_READWRITE(via_1_r, via_1_w) + AM_RANGE(0x1800, 0x18ff) AM_DEVREADWRITE(VIA6522, "via6522_1", via_r, via_w) // AM_RANGE(0x8000, 0x9fff) AM_WRITE(beezer_dac_w) AM_RANGE(0xe000, 0xffff) AM_ROM ADDRESS_MAP_END @@ -98,6 +98,10 @@ static MACHINE_DRIVER_START( beezer ) MDRV_SOUND_ADD("dac", DAC, 0) MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0) + + /* via */ + MDRV_VIA6522_ADD("via6522_0", 0, b_via_0_interface) + MDRV_VIA6522_ADD("via6522_1", 0, b_via_1_interface) MACHINE_DRIVER_END /*************************************************************************** diff --git a/src/mame/drivers/bmcbowl.c b/src/mame/drivers/bmcbowl.c index bb4287c534f..5225b0101a4 100644 --- a/src/mame/drivers/bmcbowl.c +++ b/src/mame/drivers/bmcbowl.c @@ -213,39 +213,41 @@ static WRITE16_HANDLER( scroll_w ) } -static READ16_HANDLER(via_r) +static READ16_HANDLER(bmcbowl_via_r) { - return via_0_r(space,offset); + const device_config *via_0 = device_list_find_by_tag(space->machine->config->devicelist, VIA6522, "via6522_0"); + return via_r(via_0, offset); } -static WRITE16_HANDLER(via_w) +static WRITE16_HANDLER(bmcbowl_via_w) { - via_0_w(space,offset,data); + const device_config *via_0 = device_list_find_by_tag(space->machine->config->devicelist, VIA6522, "via6522_0"); + via_w(via_0, offset, data); } -static READ8_HANDLER(via_b_in) +static READ8_DEVICE_HANDLER(via_b_in) { - return input_port_read(space->machine, "IN3"); + return input_port_read(device->machine, "IN3"); } -static WRITE8_HANDLER(via_a_out) +static WRITE8_DEVICE_HANDLER(via_a_out) { // related to video hw ? BG scroll ? } -static WRITE8_HANDLER(via_b_out) +static WRITE8_DEVICE_HANDLER(via_b_out) { //used } -static WRITE8_HANDLER(via_ca2_out) +static WRITE8_DEVICE_HANDLER(via_ca2_out) { //used } -static void via_irq(running_machine *machine, int state) +static void via_irq(const device_config *device, int state) { //used } @@ -333,7 +335,7 @@ static ADDRESS_MAP_START( bmcbowl_mem, ADDRESS_SPACE_PROGRAM, 16 ) AM_RANGE(0x091000, 0x091001) AM_WRITE(SMH_NOP) AM_RANGE(0x091800, 0x091801) AM_WRITE(scroll_w) - AM_RANGE(0x092000, 0x09201f) AM_READWRITE(via_r,via_w) + AM_RANGE(0x092000, 0x09201f) AM_READWRITE(bmcbowl_via_r, bmcbowl_via_w) AM_RANGE(0x093000, 0x093003) AM_WRITE(SMH_NOP) // related to music AM_RANGE(0x092800, 0x092801) AM_WRITE(ay8910_write_port_0_msb_w ) @@ -482,7 +484,6 @@ static const via6522_interface via_interface = static MACHINE_RESET( bmcbowl ) { - via_reset(); } static INTERRUPT_GEN( bmc_interrupt ) @@ -525,6 +526,9 @@ static MACHINE_DRIVER_START( bmcbowl ) MDRV_SOUND_CONFIG(okim6295_interface_pin7high) // clock frequency & pin 7 not verified MDRV_SOUND_ROUTE(ALL_OUTPUTS, "left", 0.50) MDRV_SOUND_ROUTE(ALL_OUTPUTS, "right", 0.50) + + /* via */ + MDRV_VIA6522_ADD("via6522_0", 1000000, via_interface) MACHINE_DRIVER_END ROM_START( bmcbowl ) @@ -547,8 +551,6 @@ ROM_END static DRIVER_INIT(bmcbowl) { - via_config(0, &via_interface); - via_set_clock(0, 1000000);//1 MHz ? colorram=auto_malloc(768); } diff --git a/src/mame/drivers/gameplan.c b/src/mame/drivers/gameplan.c index 404e99c5ac0..e58943da2e4 100644 --- a/src/mame/drivers/gameplan.c +++ b/src/mame/drivers/gameplan.c @@ -77,9 +77,9 @@ TODO: * *************************************/ -static WRITE8_HANDLER( io_select_w ) +static WRITE8_DEVICE_HANDLER( io_select_w ) { - gameplan_state *state = space->machine->driver_data; + gameplan_state *state = device->machine->driver_data; switch (data) { @@ -93,16 +93,16 @@ static WRITE8_HANDLER( io_select_w ) } -static READ8_HANDLER( io_port_r ) +static READ8_DEVICE_HANDLER( io_port_r ) { static const char *const portnames[] = { "IN0", "IN1", "IN2", "IN3", "DSW0", "DSW1" }; - gameplan_state *state = space->machine->driver_data; + gameplan_state *state = device->machine->driver_data; - return input_port_read(space->machine, portnames[state->current_port]); + return input_port_read(device->machine, portnames[state->current_port]); } -static WRITE8_HANDLER( coin_w ) +static WRITE8_DEVICE_HANDLER( coin_w ) { coin_counter_w(0, ~data & 1); } @@ -125,35 +125,42 @@ static const via6522_interface via_1_interface = * *************************************/ -static WRITE8_HANDLER( audio_reset_w ) +static WRITE8_DEVICE_HANDLER( audio_reset_w ) { - gameplan_state *state = space->machine->driver_data; - cpu_set_input_line(space->machine->cpu[1], INPUT_LINE_RESET, data ? CLEAR_LINE : ASSERT_LINE); + gameplan_state *state = device->machine->driver_data; + cpu_set_input_line(device->machine->cpu[1], INPUT_LINE_RESET, data ? CLEAR_LINE : ASSERT_LINE); if (data == 0) { device_reset(state->riot); - cpuexec_boost_interleave(space->machine, attotime_zero, ATTOTIME_IN_USEC(10)); + cpuexec_boost_interleave(device->machine, attotime_zero, ATTOTIME_IN_USEC(10)); } } -static WRITE8_HANDLER( audio_cmd_w ) +static WRITE8_DEVICE_HANDLER( audio_cmd_w ) { - gameplan_state *state = space->machine->driver_data; + gameplan_state *state = device->machine->driver_data; riot6532_porta_in_set(state->riot, data, 0x7f); } -static WRITE8_HANDLER( audio_trigger_w ) +static WRITE8_DEVICE_HANDLER( audio_trigger_w ) { - gameplan_state *state = space->machine->driver_data; + gameplan_state *state = device->machine->driver_data; riot6532_porta_in_set(state->riot, data << 7, 0x80); } +static READ8_DEVICE_HANDLER( via_soundlatch_r ) +{ + const address_space *space = cpu_get_address_space(device->machine->cpu[0], ADDRESS_SPACE_PROGRAM); + return soundlatch_r(space, offset); +} + + static const via6522_interface via_2_interface = { - 0, soundlatch_r, /*inputs : A/B */ + 0, via_soundlatch_r, /*inputs : A/B */ 0, 0, 0, 0, /*inputs : CA/B1,CA/B2 */ audio_cmd_w, 0, /*outputs: A/B */ 0, 0, audio_trigger_w, audio_reset_w, /*outputs: CA/B1,CA/B2 */ @@ -179,7 +186,6 @@ static void r6532_irq(const device_config *device, int state) static void r6532_soundlatch_w(const device_config *device, UINT8 newdata, UINT8 olddata) { const address_space *space = cpu_get_address_space(device->machine->cpu[0], ADDRESS_SPACE_PROGRAM); - soundlatch_w(space, 0, newdata); } @@ -207,9 +213,6 @@ static MACHINE_START( gameplan ) state->riot = device_list_find_by_tag(machine->config->devicelist, RIOT6532, "riot"); - via_config(1, &via_1_interface); - via_config(2, &via_2_interface); - /* register for save states */ state_save_register_global(machine, state->current_port); } @@ -224,7 +227,6 @@ static MACHINE_START( gameplan ) static MACHINE_RESET( gameplan ) { - via_reset(); } @@ -237,9 +239,9 @@ static MACHINE_RESET( gameplan ) static ADDRESS_MAP_START( gameplan_main_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x03ff) AM_MIRROR(0x1c00) AM_RAM - AM_RANGE(0x2000, 0x200f) AM_MIRROR(0x07f0) AM_READWRITE(via_0_r, via_0_w) /* VIA 1 */ - AM_RANGE(0x2800, 0x280f) AM_MIRROR(0x07f0) AM_READWRITE(via_1_r, via_1_w) /* VIA 2 */ - AM_RANGE(0x3000, 0x300f) AM_MIRROR(0x07f0) AM_READWRITE(via_2_r, via_2_w) /* VIA 3 */ + AM_RANGE(0x2000, 0x200f) AM_MIRROR(0x07f0) AM_DEVREADWRITE(VIA6522, "via6522_0", via_r, via_w) /* VIA 1 */ + AM_RANGE(0x2800, 0x280f) AM_MIRROR(0x07f0) AM_DEVREADWRITE(VIA6522, "via6522_1", via_r, via_w) /* VIA 2 */ + AM_RANGE(0x3000, 0x300f) AM_MIRROR(0x07f0) AM_DEVREADWRITE(VIA6522, "via6522_2", via_r, via_w) /* VIA 3 */ AM_RANGE(0x8000, 0xffff) AM_ROM ADDRESS_MAP_END @@ -1192,6 +1194,11 @@ static MACHINE_DRIVER_START( gameplan ) MDRV_SOUND_ADD("ay", AY8910, GAMEPLAN_AY8910_CLOCK) MDRV_SOUND_CONFIG(ay8910_config) MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.33) + + /* via */ + MDRV_VIA6522_ADD("via6522_0", 0, gameplan_via_0_interface) + MDRV_VIA6522_ADD("via6522_1", 0, via_1_interface) + MDRV_VIA6522_ADD("via6522_2", 0, via_2_interface) MACHINE_DRIVER_END @@ -1205,6 +1212,10 @@ static MACHINE_DRIVER_START( leprechn ) /* video hardware */ MDRV_IMPORT_FROM(leprechn_video) + + /* via */ + MDRV_VIA6522_REMOVE("via6522_0") + MDRV_VIA6522_ADD("via6522_0", 0, leprechn_via_0_interface) MACHINE_DRIVER_END diff --git a/src/mame/drivers/itech32.c b/src/mame/drivers/itech32.c index 88e7f74189b..757215e55f4 100644 --- a/src/mame/drivers/itech32.c +++ b/src/mame/drivers/itech32.c @@ -412,9 +412,6 @@ static MACHINE_RESET( itech32 ) sound_return = 0; sound_int_state = 0; - /* reset the VIA chip (if used) */ - via_reset(); - /* reset the ticket dispenser */ ticket_dispenser_init(machine, 200, TICKET_MOTOR_ACTIVE_HIGH, TICKET_STATUS_ACTIVE_HIGH); } @@ -667,8 +664,9 @@ static READ8_HANDLER( sound_data_buffer_r ) * *************************************/ -static WRITE8_HANDLER( drivedge_portb_out ) +static WRITE8_DEVICE_HANDLER( drivedge_portb_out ) { + const address_space *space = cpu_get_address_space(device->machine->cpu[0], ADDRESS_SPACE_PROGRAM); // logerror("PIA port B write = %02x\n", data); /* bit 0 controls the fan light */ @@ -685,14 +683,15 @@ static WRITE8_HANDLER( drivedge_portb_out ) } -static WRITE8_HANDLER( drivedge_turbo_light ) +static WRITE8_DEVICE_HANDLER( drivedge_turbo_light ) { set_led_status(0, data); } -static WRITE8_HANDLER( pia_portb_out ) +static WRITE8_DEVICE_HANDLER( pia_portb_out ) { + const address_space *space = cpu_get_address_space(device->machine->cpu[0], ADDRESS_SPACE_PROGRAM); // logerror("PIA port B write = %02x\n", data); /* bit 4 controls the ticket dispenser */ @@ -710,12 +709,12 @@ static WRITE8_HANDLER( pia_portb_out ) * *************************************/ -static void via_irq(running_machine *machine, int state) +static void via_irq(const device_config *device, int state) { if (state) - cpu_set_input_line(machine->cpu[1], M6809_FIRQ_LINE, ASSERT_LINE); + cpu_set_input_line(device->machine->cpu[1], M6809_FIRQ_LINE, ASSERT_LINE); else - cpu_set_input_line(machine->cpu[1], M6809_FIRQ_LINE, CLEAR_LINE); + cpu_set_input_line(device->machine->cpu[1], M6809_FIRQ_LINE, CLEAR_LINE); } @@ -1060,7 +1059,7 @@ static ADDRESS_MAP_START( sound_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0880, 0x08bf) AM_READ(es5506_data_0_r) AM_RANGE(0x0c00, 0x0c00) AM_WRITE(sound_bank_w) AM_RANGE(0x1000, 0x1000) AM_WRITENOP /* noisy */ - AM_RANGE(0x1400, 0x140f) AM_READWRITE(via_0_r, via_0_w) + AM_RANGE(0x1400, 0x140f) AM_DEVREADWRITE(VIA6522, "via6522_0", via_r, via_w) AM_RANGE(0x2000, 0x3fff) AM_RAM AM_RANGE(0x4000, 0x7fff) AM_ROMBANK(1) AM_RANGE(0x8000, 0xffff) AM_ROM @@ -1709,6 +1708,9 @@ static MACHINE_DRIVER_START( timekill ) MDRV_SOUND_ADD("ensoniq", ES5506, SOUND_CLOCK) MDRV_SOUND_CONFIG(es5506_config) MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0) + + /* via */ + MDRV_VIA6522_ADD("via6522_0", SOUND_CLOCK/8, via_interface) MACHINE_DRIVER_END @@ -1760,6 +1762,9 @@ static MACHINE_DRIVER_START( sftm ) MDRV_CPU_VBLANK_INT_HACK(irq1_line_assert,4) MDRV_NVRAM_HANDLER(itech020) + + /* via */ + MDRV_VIA6522_REMOVE("via6522_0") MACHINE_DRIVER_END @@ -3837,8 +3842,6 @@ static void init_program_rom(running_machine *machine) static DRIVER_INIT( timekill ) { init_program_rom(machine); - via_config(0, &via_interface); - via_set_clock(0, SOUND_CLOCK/8); itech32_vram_height = 512; itech32_planes = 2; is_drivedge = 0; @@ -3848,8 +3851,6 @@ static DRIVER_INIT( timekill ) static DRIVER_INIT( hardyard ) { init_program_rom(machine); - via_config(0, &via_interface); - via_set_clock(0, SOUND_CLOCK/8); itech32_vram_height = 1024; itech32_planes = 1; is_drivedge = 0; @@ -3859,8 +3860,6 @@ static DRIVER_INIT( hardyard ) static DRIVER_INIT( bloodstm ) { init_program_rom(machine); - via_config(0, &via_interface); - via_set_clock(0, SOUND_CLOCK/8); itech32_vram_height = 1024; itech32_planes = 1; is_drivedge = 0; @@ -3870,8 +3869,6 @@ static DRIVER_INIT( bloodstm ) static DRIVER_INIT( drivedge ) { init_program_rom(machine); - via_config(0, &drivedge_via_interface); - via_set_clock(0, SOUND_CLOCK/8); itech32_vram_height = 1024; itech32_planes = 1; is_drivedge = 1; @@ -3890,8 +3887,6 @@ static DRIVER_INIT( wcbowl ) Sound P/N 1060 Rev 0 (see Hot Memory PCB layout above) */ init_program_rom(machine); - via_config(0, &via_interface); - via_set_clock(0, SOUND_CLOCK/8); itech32_vram_height = 1024; itech32_planes = 1; diff --git a/src/mame/drivers/itech8.c b/src/mame/drivers/itech8.c index eadf5102afd..167e64d4d81 100644 --- a/src/mame/drivers/itech8.c +++ b/src/mame/drivers/itech8.c @@ -561,13 +561,20 @@ static const pia6821_interface pia_interface = * *************************************/ -static void via_irq(running_machine *machine, int state); +static void via_irq(const device_config *device, int state); + +static WRITE8_DEVICE_HANDLER( via_pia_portb_out ) +{ + const address_space *space = cpu_get_address_space(device->machine->cpu[0], ADDRESS_SPACE_PROGRAM); + pia_portb_out(space, offset, data); +} + static const via6522_interface via_interface = { /*inputs : A/B */ 0, 0, /*inputs : CA/B1,CA/B2 */ 0, 0, 0, 0, - /*outputs: A/B */ 0, pia_portb_out, + /*outputs: A/B */ 0, via_pia_portb_out, /*outputs: CA/B1,CA/B2 */ 0, 0, 0, 0, /*irq */ via_irq }; @@ -676,11 +683,6 @@ static MACHINE_RESET( itech8 ) /* reset the PIA (if used) */ pia_reset(); - /* reset the VIA chip (if used) */ - via_config(0, &via_interface); - via_set_clock(0, CLOCK_8MHz/4); - via_reset(); - /* reset the ticket dispenser */ ticket_dispenser_init(machine, 200, TICKET_MOTOR_ACTIVE_HIGH, TICKET_STATUS_ACTIVE_LOW); @@ -844,12 +846,12 @@ static READ8_HANDLER( sound_data_r ) * *************************************/ -static void via_irq(running_machine *machine, int state) +static void via_irq(const device_config *device, int state) { if (state) - cpu_set_input_line(machine->cpu[1], M6809_FIRQ_LINE, ASSERT_LINE); + cpu_set_input_line(device->machine->cpu[1], M6809_FIRQ_LINE, ASSERT_LINE); else - cpu_set_input_line(machine->cpu[1], M6809_FIRQ_LINE, CLEAR_LINE); + cpu_set_input_line(device->machine->cpu[1], M6809_FIRQ_LINE, CLEAR_LINE); } @@ -1026,7 +1028,7 @@ static ADDRESS_MAP_START( sound3812_external_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x2001, 0x2001) AM_WRITE(ym3812_write_port_0_w) AM_RANGE(0x3000, 0x37ff) AM_RAM AM_RANGE(0x4000, 0x4000) AM_READWRITE(okim6295_status_0_r, okim6295_data_0_w) - AM_RANGE(0x5000, 0x500f) AM_READWRITE(via_0_r, via_0_w) + AM_RANGE(0x5000, 0x500f) AM_DEVREADWRITE(VIA6522, "via6522_0", via_r, via_w) AM_RANGE(0x8000, 0xffff) AM_ROM ADDRESS_MAP_END @@ -1765,6 +1767,9 @@ static MACHINE_DRIVER_START( itech8_core_lo ) /* sound hardware */ MDRV_SPEAKER_STANDARD_MONO("mono") + + /* via */ + MDRV_VIA6522_ADD("via6522_0", CLOCK_8MHz/4, via_interface) MACHINE_DRIVER_END diff --git a/src/mame/drivers/trvquest.c b/src/mame/drivers/trvquest.c index bfcbe34db47..2ab5032841f 100644 --- a/src/mame/drivers/trvquest.c +++ b/src/mame/drivers/trvquest.c @@ -46,12 +46,12 @@ static READ8_HANDLER( trvquest_question_r ) return memory_region(space->machine, "questions")[*state->trvquest_question * 0x2000 + offset]; } -static WRITE8_HANDLER( trvquest_coin_w ) +static WRITE8_DEVICE_HANDLER( trvquest_coin_w ) { coin_counter_w(0,~data & 1); } -static WRITE8_HANDLER( trvquest_misc_w ) +static WRITE8_DEVICE_HANDLER( trvquest_misc_w ) { // data & 1 -> led on/off ? } @@ -59,9 +59,9 @@ static WRITE8_HANDLER( trvquest_misc_w ) static ADDRESS_MAP_START( cpu_map, ADDRESS_SPACE_PROGRAM, 8 ) AM_RANGE(0x0000, 0x1fff) AM_RAM AM_BASE(&generic_nvram) AM_SIZE(&generic_nvram_size) // cmos ram AM_RANGE(0x2000, 0x27ff) AM_RAM // main ram - AM_RANGE(0x3800, 0x380f) AM_READWRITE(via_1_r, via_1_w) - AM_RANGE(0x3810, 0x381f) AM_READWRITE(via_2_r, via_2_w) - AM_RANGE(0x3820, 0x382f) AM_READWRITE(via_0_r, via_0_w) + AM_RANGE(0x3800, 0x380f) AM_DEVREADWRITE(VIA6522, "via6522_1", via_r, via_w) + AM_RANGE(0x3810, 0x381f) AM_DEVREADWRITE(VIA6522, "via6522_2", via_r, via_w) + AM_RANGE(0x3820, 0x382f) AM_DEVREADWRITE(VIA6522, "via6522_0", via_r, via_w) AM_RANGE(0x3830, 0x3830) AM_WRITE(ay8910_control_port_0_w) AM_RANGE(0x3831, 0x3831) AM_WRITE(ay8910_write_port_0_w) AM_RANGE(0x3840, 0x3840) AM_WRITE(ay8910_control_port_1_w) @@ -152,20 +152,31 @@ static TIMER_CALLBACK( via_irq_delayed ) cpu_set_input_line(machine->cpu[0], 0, param); } -static void via_irq(running_machine *machine, int state) +static void via_irq(const device_config *device, int state) { // from gameplan.c /* Kaos sits in a tight loop polling the VIA irq flags register, but that register is cleared by the irq handler. Therefore, I wait a bit before triggering the irq to leave time for the program to see the flag change. */ - timer_set(machine, ATTOTIME_IN_USEC(50), NULL, state, via_irq_delayed); + timer_set(device->machine, ATTOTIME_IN_USEC(50), NULL, state, via_irq_delayed); } +static input_port_value input_port_read_indexed(running_machine *machine, int portnum) +{ + const input_port_config *port = input_port_by_index(machine->portconfig, portnum); + return input_port_read_direct(port); +} + +static READ8_DEVICE_HANDLER( via_input_port_0_r ) { return input_port_read_indexed(device->machine, 0); } +static READ8_DEVICE_HANDLER( via_input_port_1_r ) { return input_port_read_indexed(device->machine, 1); } +static READ8_DEVICE_HANDLER( via_input_port_2_r ) { return input_port_read_indexed(device->machine, 2); } +static READ8_DEVICE_HANDLER( via_input_port_3_r ) { return input_port_read_indexed(device->machine, 3); } + static const via6522_interface via_1_interface = { - /*inputs : A/B */ input_port_0_r, input_port_1_r, + /*inputs : A/B */ via_input_port_0_r, via_input_port_1_r, /*inputs : CA/B1,CA/B2 */ NULL, NULL, NULL, NULL, /*outputs: A/B */ NULL, NULL, /*outputs: CA/B1,CA/B2 */ NULL, NULL, trvquest_coin_w, NULL, @@ -174,7 +185,7 @@ static const via6522_interface via_1_interface = static const via6522_interface via_2_interface = { - /*inputs : A/B */ input_port_2_r, input_port_3_r, + /*inputs : A/B */ via_input_port_2_r, via_input_port_3_r, /*inputs : CA/B1,CA/B2 */ NULL, NULL, NULL, NULL, /*outputs: A/B */ NULL, NULL, /*outputs: CA/B1,CA/B2 */ NULL, NULL, trvquest_misc_w, NULL, @@ -184,20 +195,17 @@ static const via6522_interface via_2_interface = static MACHINE_START( trvquest ) { - via_config(1, &via_1_interface); - via_config(2, &via_2_interface); } static MACHINE_RESET( trvquest ) { - via_reset(); } static INTERRUPT_GEN( trvquest_interrupt ) { - const address_space *space = cpu_get_address_space(device, ADDRESS_SPACE_PROGRAM); - via_2_ca1_w(space,0,1); - via_2_ca1_w(space,0,0); + const device_config *via_2 = device_list_find_by_tag(device->machine->config->devicelist, VIA6522, "via6522_2"); + via_ca1_w(via_2, 0, 1); + via_ca1_w(via_2, 0, 0); } static MACHINE_DRIVER_START( trvquest ) @@ -223,6 +231,11 @@ static MACHINE_DRIVER_START( trvquest ) MDRV_SOUND_ADD("ay2", AY8910, XTAL_6MHz/2) MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.25) + + /* via */ + MDRV_VIA6522_ADD("via6522_0", 0, trvquest_via_0_interface) + MDRV_VIA6522_ADD("via6522_1", 0, via_1_interface) + MDRV_VIA6522_ADD("via6522_2", 0, via_2_interface) MACHINE_DRIVER_END ROM_START( trvquest ) diff --git a/src/mame/includes/beezer.h b/src/mame/includes/beezer.h index c7aec292fed..b06a62c1733 100644 --- a/src/mame/includes/beezer.h +++ b/src/mame/includes/beezer.h @@ -1,5 +1,8 @@ /*----------- defined in machine/beezer.c -----------*/ +extern const via6522_interface b_via_0_interface; +extern const via6522_interface b_via_1_interface; + DRIVER_INIT( beezer ); WRITE8_HANDLER( beezer_bankswitch_w ); diff --git a/src/mame/includes/gameplan.h b/src/mame/includes/gameplan.h index 6bfc311437f..eeaff6ea703 100644 --- a/src/mame/includes/gameplan.h +++ b/src/mame/includes/gameplan.h @@ -6,6 +6,7 @@ driver by Chris Moore ***************************************************************************/ +#include "machine/6522via.h" #define GAMEPLAN_MAIN_MASTER_CLOCK (XTAL_3_579545MHz) #define GAMEPLAN_AUDIO_MASTER_CLOCK (XTAL_3_579545MHz) @@ -36,6 +37,10 @@ struct _gameplan_state /*----------- defined in video/gameplan.c -----------*/ +extern const via6522_interface gameplan_via_0_interface; +extern const via6522_interface leprechn_via_0_interface; +extern const via6522_interface trvquest_via_0_interface; + MACHINE_DRIVER_EXTERN( gameplan_video ); MACHINE_DRIVER_EXTERN( leprechn_video ); MACHINE_DRIVER_EXTERN( trvquest_video ); diff --git a/src/mame/machine/beezer.c b/src/mame/machine/beezer.c index 83bf7122a84..d521bf28d1f 100644 --- a/src/mame/machine/beezer.c +++ b/src/mame/machine/beezer.c @@ -5,20 +5,56 @@ static int pbus; -static READ8_HANDLER( b_via_0_pb_r ); -static WRITE8_HANDLER( b_via_0_pa_w ); -static WRITE8_HANDLER( b_via_0_pb_w ); -static READ8_HANDLER( b_via_0_ca2_r ); -static WRITE8_HANDLER( b_via_0_ca2_w ); -static void b_via_0_irq (running_machine *machine, int level); +static READ8_DEVICE_HANDLER( b_via_0_pb_r ); +static WRITE8_DEVICE_HANDLER( b_via_0_pa_w ); +static WRITE8_DEVICE_HANDLER( b_via_0_pb_w ); +static READ8_DEVICE_HANDLER( b_via_0_ca2_r ); +static WRITE8_DEVICE_HANDLER( b_via_0_ca2_w ); +static void b_via_0_irq (const device_config *device, int level); -static READ8_HANDLER( b_via_1_pa_r ); -static READ8_HANDLER( b_via_1_pb_r ); -static WRITE8_HANDLER( b_via_1_pa_w ); -static WRITE8_HANDLER( b_via_1_pb_w ); -static void b_via_1_irq (running_machine *machine, int level); +static READ8_DEVICE_HANDLER( b_via_1_pa_r ); +static READ8_DEVICE_HANDLER( b_via_1_pb_r ); +static WRITE8_DEVICE_HANDLER( b_via_1_pa_w ); +static WRITE8_DEVICE_HANDLER( b_via_1_pb_w ); +static void b_via_1_irq (const device_config *device, int level); -static const via6522_interface b_via_0_interface = +static READ8_DEVICE_HANDLER( via_0_cb1_r ) +{ + const device_config *via_0 = device_list_find_by_tag(device->machine->config->devicelist, VIA6522, "via6522_0"); + return via_cb1_r(via_0, offset); +} + +static WRITE8_DEVICE_HANDLER( via_0_cb1_w ) +{ + const device_config *via_0 = device_list_find_by_tag(device->machine->config->devicelist, VIA6522, "via6522_0"); + via_cb1_w(via_0, offset, data); +} + +static READ8_DEVICE_HANDLER( via_0_cb2_r ) +{ + const device_config *via_0 = device_list_find_by_tag(device->machine->config->devicelist, VIA6522, "via6522_0"); + return via_cb2_r(via_0, offset); +} + +static READ8_DEVICE_HANDLER( via_1_ca1_r ) +{ + const device_config *via_1 = device_list_find_by_tag(device->machine->config->devicelist, VIA6522, "via6522_1"); + return via_ca1_r(via_1, offset); +} + +static WRITE8_DEVICE_HANDLER( via_1_ca1_w ) +{ + const device_config *via_1 = device_list_find_by_tag(device->machine->config->devicelist, VIA6522, "via6522_1"); + via_ca1_w(via_1, offset, data); +} + +static READ8_DEVICE_HANDLER( via_1_ca2_r ) +{ + const device_config *via_1 = device_list_find_by_tag(device->machine->config->devicelist, VIA6522, "via6522_1"); + return via_ca2_r(via_1, offset); +} + +const via6522_interface b_via_0_interface = { /*inputs : A/B */ 0, b_via_0_pb_r, /*inputs : CA/B1,CA/B2 */ 0, via_1_ca2_r, b_via_0_ca2_r, via_1_ca1_r, @@ -27,7 +63,7 @@ static const via6522_interface b_via_0_interface = /*irq */ b_via_0_irq }; -static const via6522_interface b_via_1_interface = +const via6522_interface b_via_1_interface = { /*inputs : A/B */ b_via_1_pa_r, b_via_1_pb_r, /*inputs : CA/B1,CA/B2 */ via_0_cb2_r, 0, via_0_cb1_r, 0, @@ -36,44 +72,44 @@ static const via6522_interface b_via_1_interface = /*irq */ b_via_1_irq }; -static READ8_HANDLER( b_via_0_ca2_r ) +static READ8_DEVICE_HANDLER( b_via_0_ca2_r ) { return 0; } -static WRITE8_HANDLER( b_via_0_ca2_w ) +static WRITE8_DEVICE_HANDLER( b_via_0_ca2_w ) { } -static void b_via_0_irq (running_machine *machine, int level) +static void b_via_0_irq (const device_config *device, int level) { - cpu_set_input_line(machine->cpu[0], M6809_IRQ_LINE, level); + cpu_set_input_line(device->machine->cpu[0], M6809_IRQ_LINE, level); } -static READ8_HANDLER( b_via_0_pb_r ) +static READ8_DEVICE_HANDLER( b_via_0_pb_r ) { return pbus; } -static WRITE8_HANDLER( b_via_0_pa_w ) +static WRITE8_DEVICE_HANDLER( b_via_0_pa_w ) { if ((data & 0x08) == 0) - cpu_set_input_line(space->machine->cpu[1], INPUT_LINE_RESET, ASSERT_LINE); + cpu_set_input_line(device->machine->cpu[1], INPUT_LINE_RESET, ASSERT_LINE); else - cpu_set_input_line(space->machine->cpu[1], INPUT_LINE_RESET, CLEAR_LINE); + cpu_set_input_line(device->machine->cpu[1], INPUT_LINE_RESET, CLEAR_LINE); if ((data & 0x04) == 0) { switch (data & 0x03) { case 0: - pbus = input_port_read(space->machine, "IN0"); + pbus = input_port_read(device->machine, "IN0"); break; case 1: - pbus = input_port_read(space->machine, "IN1") | (input_port_read(space->machine, "IN2") << 4); + pbus = input_port_read(device->machine, "IN1") | (input_port_read(device->machine, "IN2") << 4); break; case 2: - pbus = input_port_read(space->machine, "DSWB"); + pbus = input_port_read(device->machine, "DSWB"); break; case 3: pbus = 0xff; @@ -82,40 +118,37 @@ static WRITE8_HANDLER( b_via_0_pa_w ) } } -static WRITE8_HANDLER( b_via_0_pb_w ) +static WRITE8_DEVICE_HANDLER( b_via_0_pb_w ) { pbus = data; } -static void b_via_1_irq (running_machine *machine, int level) +static void b_via_1_irq (const device_config *device, int level) { - cpu_set_input_line(machine->cpu[1], M6809_IRQ_LINE, level); + cpu_set_input_line(device->machine->cpu[1], M6809_IRQ_LINE, level); } -static READ8_HANDLER( b_via_1_pa_r ) +static READ8_DEVICE_HANDLER( b_via_1_pa_r ) { return pbus; } -static READ8_HANDLER( b_via_1_pb_r ) +static READ8_DEVICE_HANDLER( b_via_1_pb_r ) { return 0xff; } -static WRITE8_HANDLER( b_via_1_pa_w ) +static WRITE8_DEVICE_HANDLER( b_via_1_pa_w ) { pbus = data; } -static WRITE8_HANDLER( b_via_1_pb_w ) +static WRITE8_DEVICE_HANDLER( b_via_1_pb_w ) { } DRIVER_INIT( beezer ) { - via_config(0, &b_via_0_interface); - via_config(1, &b_via_1_interface); - via_reset(); pbus = 0; } @@ -123,10 +156,11 @@ WRITE8_HANDLER( beezer_bankswitch_w ) { if ((data & 0x07) == 0) { + const device_config *via_0 = device_list_find_by_tag(space->machine->config->devicelist, VIA6522, "via6522_0"); memory_install_write8_handler(space, 0xc600, 0xc7ff, 0, 0, watchdog_reset_w); memory_install_write8_handler(space, 0xc800, 0xc9ff, 0, 0, beezer_map_w); memory_install_read8_handler(space, 0xca00, 0xcbff, 0, 0, beezer_line_r); - memory_install_readwrite8_handler(space, 0xce00, 0xcfff, 0, 0, via_0_r, via_0_w); + memory_install_readwrite8_device_handler(space, via_0, 0xce00, 0xcfff, 0, 0, via_r, via_w); } else { diff --git a/src/mame/video/beezer.c b/src/mame/video/beezer.c index 3592372bf11..64b67fef2c7 100644 --- a/src/mame/video/beezer.c +++ b/src/mame/video/beezer.c @@ -7,10 +7,10 @@ static int scanline=0; INTERRUPT_GEN( beezer_interrupt ) { - const address_space *space = cpu_get_address_space(device->machine->cpu[0], ADDRESS_SPACE_PROGRAM); + const device_config *via_0 = device_list_find_by_tag(device->machine->config->devicelist, VIA6522, "via6522_0"); scanline = (scanline + 1) % 0x80; - via_0_ca2_w (space, 0, scanline & 0x10); + via_ca2_w (via_0, 0, scanline & 0x10); if ((scanline & 0x78) == 0x78) cpu_set_input_line(device, M6809_FIRQ_LINE, ASSERT_LINE); else diff --git a/src/mame/video/gameplan.c b/src/mame/video/gameplan.c index 849f6ce588d..4b97e244dd0 100644 --- a/src/mame/video/gameplan.c +++ b/src/mame/video/gameplan.c @@ -116,25 +116,25 @@ static VIDEO_UPDATE( leprechn ) * *************************************/ -static WRITE8_HANDLER( video_data_w ) +static WRITE8_DEVICE_HANDLER( video_data_w ) { - gameplan_state *state = space->machine->driver_data; + gameplan_state *state = device->machine->driver_data; state->video_data = data; } -static WRITE8_HANDLER( gameplan_video_command_w ) +static WRITE8_DEVICE_HANDLER( gameplan_video_command_w ) { - gameplan_state *state = space->machine->driver_data; + gameplan_state *state = device->machine->driver_data; state->video_command = data & 0x07; } -static WRITE8_HANDLER( leprechn_video_command_w ) +static WRITE8_DEVICE_HANDLER( leprechn_video_command_w ) { - gameplan_state *state = space->machine->driver_data; + gameplan_state *state = device->machine->driver_data; state->video_command = (data >> 3) & 0x07; } @@ -142,16 +142,16 @@ static WRITE8_HANDLER( leprechn_video_command_w ) static TIMER_CALLBACK( clear_screen_done_callback ) { - const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM); + const device_config *via = device_list_find_by_tag(machine->config->devicelist, VIA6522, "via6522_0"); /* indicate that the we are done clearing the screen */ - via_0_ca1_w(space, 0, 0); + via_ca1_w(via, 0, 0); } -static WRITE8_HANDLER( video_command_trigger_w ) +static WRITE8_DEVICE_HANDLER( video_command_trigger_w ) { - gameplan_state *state = space->machine->driver_data; + gameplan_state *state = device->machine->driver_data; if (data == 0) { @@ -194,14 +194,17 @@ static WRITE8_HANDLER( video_command_trigger_w ) /* clear screen */ case 3: /* indicate that the we are busy */ - via_0_ca1_w(space, 0, 1); + { + const device_config *via = device_list_find_by_tag(device->machine->config->devicelist, VIA6522, "via6522_0"); + via_ca1_w(via, 0, 1); + } memset(state->videoram, state->video_data & 0x0f, state->videoram_size); /* set a timer for an arbitrarily short period. The real time it takes to clear to screen is not important to the software */ - timer_call_after_resynch(space->machine, NULL, 0, clear_screen_done_callback); + timer_call_after_resynch(device->machine, NULL, 0, clear_screen_done_callback); break; } @@ -215,23 +218,23 @@ static TIMER_CALLBACK( via_irq_delayed ) } -static void via_irq(running_machine *machine, int state) +static void via_irq(const device_config *device, int state) { /* Kaos sits in a tight loop polling the VIA irq flags register, but that register is cleared by the irq handler. Therefore, I wait a bit before triggering the irq to leave time for the program to see the flag change. */ - timer_set(machine, ATTOTIME_IN_USEC(50), NULL, state, via_irq_delayed); + timer_set(device->machine, ATTOTIME_IN_USEC(50), NULL, state, via_irq_delayed); } -static READ8_HANDLER( vblank_r ) +static READ8_DEVICE_HANDLER( vblank_r ) { /* this is needed for trivia quest */ return 0x20; } -static const via6522_interface gameplan_via_0_interface = +const via6522_interface gameplan_via_0_interface = { 0, vblank_r, /*inputs : A/B */ 0, 0, 0, 0, /*inputs : CA/B1,CA/B2 */ @@ -241,7 +244,7 @@ static const via6522_interface gameplan_via_0_interface = }; -static const via6522_interface leprechn_via_0_interface = +const via6522_interface leprechn_via_0_interface = { 0, vblank_r, /*inputs : A/B */ 0, 0, 0, 0, /*inputs : CA/B1,CA/B2 */ @@ -251,7 +254,7 @@ static const via6522_interface leprechn_via_0_interface = }; -static const via6522_interface trvquest_via_0_interface = +const via6522_interface trvquest_via_0_interface = { 0, vblank_r, /*inputs : A/B */ 0, 0, 0, 0, /*inputs : CA/B1,CA/B2 */ @@ -264,10 +267,10 @@ static const via6522_interface trvquest_via_0_interface = static TIMER_CALLBACK( via_0_ca1_timer_callback ) { gameplan_state *state = machine->driver_data; - const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM); + const device_config *via = device_list_find_by_tag(machine->config->devicelist, VIA6522, "via6522_0"); /* !VBLANK is connected to CA1 */ - via_0_ca1_w(space, 0, (UINT8)param); + via_ca1_w(via, 0, (UINT8)param); if (param) timer_adjust_oneshot(state->via_0_ca1_timer, video_screen_get_time_until_pos(machine->primary_screen, VBSTART, 0), 0); @@ -315,24 +318,18 @@ static VIDEO_START( common ) static VIDEO_START( gameplan ) { - via_config(0, &gameplan_via_0_interface); - VIDEO_START_CALL(common); } static VIDEO_START( leprechn ) { - via_config(0, &leprechn_via_0_interface); - VIDEO_START_CALL(common); } static VIDEO_START( trvquest ) { - via_config(0, &trvquest_via_0_interface); - VIDEO_START_CALL(common); } @@ -346,7 +343,6 @@ static VIDEO_START( trvquest ) static VIDEO_RESET( gameplan ) { - via_reset(); start_via_0_timer(machine, machine->driver_data); }