From 54da9f29bd3218827a750af99a3d7e922ba132d8 Mon Sep 17 00:00:00 2001 From: Couriersud Date: Sun, 3 Aug 2008 18:54:39 +0000 Subject: [PATCH] 8257dma and z80dma devices now require device callback handlers instead of machine handlers. Updated affected drivers accordingly. --- src/emu/cpu/s2650/s2650.c | 21 ++++++++++++---- src/emu/machine/8257dma.c | 46 ++++++++++++++++++---------------- src/emu/machine/8257dma.h | 10 ++++---- src/emu/machine/z80dma.c | 52 ++++++++++++++++++++------------------- src/emu/machine/z80dma.h | 12 ++++----- src/mame/drivers/dkong.c | 32 ++++++++++++------------ src/mame/drivers/mario.c | 8 +++--- 7 files changed, 99 insertions(+), 82 deletions(-) diff --git a/src/emu/cpu/s2650/s2650.c b/src/emu/cpu/s2650/s2650.c index 204e0d8fc09..c11a6906c61 100644 --- a/src/emu/cpu/s2650/s2650.c +++ b/src/emu/cpu/s2650/s2650.c @@ -15,6 +15,7 @@ #include "debugger.h" #include "s2650.h" #include "s2650cpu.h" +#include "deprecat.h" /* define this to have some interrupt information logged */ #define VERBOSE 0 @@ -40,6 +41,7 @@ typedef struct { UINT16 ras[8]; /* 8 return address stack entries */ UINT8 irq_state; int (*irq_callback)(int irqline); + read16_machine_func addr_rewrite; } s2650_Regs; static s2650_Regs S; @@ -170,7 +172,7 @@ static void s2650_set_sense(int state); ***************************************************************/ INLINE UINT8 ROP(void) { - UINT8 result = cpu_readop(S.page + S.iar); + UINT8 result = cpu_readop(S.addr_rewrite(Machine, S.page + S.iar, 0)); S.iar = (S.iar + 1) & PMSK; return result; } @@ -181,7 +183,7 @@ INLINE UINT8 ROP(void) ***************************************************************/ INLINE UINT8 ARG(void) { - UINT8 result = cpu_readop_arg(S.page + S.iar); + UINT8 result = cpu_readop_arg(S.addr_rewrite(Machine, S.page + S.iar, 0)); S.iar = (S.iar + 1) & PMSK; return result; } @@ -190,7 +192,8 @@ INLINE UINT8 ARG(void) * RDMEM * read memory byte from addr ***************************************************************/ -#define RDMEM(addr) program_read_byte_8le(addr) +#define RDMEM(addr) program_read_byte_8le(S.addr_rewrite(Machine, addr, 0)) + /*************************************************************** * handy table to build PC relative offsets @@ -507,7 +510,7 @@ static const int S2650_relative[0x100] = * Store source register to memory addr (CC unchanged) ***************************************************************/ #define M_STR(address,source) \ - program_write_byte_8le(address, source) + program_write_byte_8le(S.addr_rewrite(Machine, address, 0), source) /*************************************************************** * M_AND @@ -765,10 +768,16 @@ static void ABS_EA(void) _ABS_EA() static void BRA_EA(void) _BRA_EA() #endif +static READ16_HANDLER( default_rewrite ) +{ + return offset; +} + static void s2650_init(int index, int clock, const void *config, int (*irqcallback)(int)) { S.irq_callback = irqcallback; - + S.addr_rewrite = (config ? config : &default_rewrite ); + state_save_register_item("s2650", index, S.ppc); state_save_register_item("s2650", index, S.page); state_save_register_item("s2650", index, S.iar); @@ -786,8 +795,10 @@ static void s2650_init(int index, int clock, const void *config, int (*irqcallba static void s2650_reset(void) { int (*save_irqcallback)(int) = S.irq_callback; + read16_machine_func save_addr_rewrite = S.addr_rewrite; memset(&S, 0, sizeof(S)); S.irq_callback = save_irqcallback; + S.addr_rewrite = save_addr_rewrite; S.psl = COM | WC; S.psu = 0; } diff --git a/src/emu/machine/8257dma.c b/src/emu/machine/8257dma.c index f47c3e4019e..81b541782d4 100644 --- a/src/emu/machine/8257dma.c +++ b/src/emu/machine/8257dma.c @@ -64,7 +64,7 @@ struct _dma8257_t static TIMER_CALLBACK( dma8257_timerproc ); static TIMER_CALLBACK( dma8257_msbflip_timerproc ); -static void dma8257_update_status(running_machine *machine, dma8257_t *dma8257); +static void dma8257_update_status(const device_config *device); /* ----------------------------------------------------------------------- */ @@ -76,8 +76,9 @@ INLINE dma8257_t *get_safe_token(const device_config *device) { return ( dma8257_t * ) device->token; } -static int dma8257_do_operation(running_machine *machine, dma8257_t *dma8257, int channel) +static int dma8257_do_operation(const device_config *device, int channel) { + dma8257_t *dma8257 = get_safe_token(device); int done; UINT8 data; UINT8 mode; @@ -87,18 +88,18 @@ static int dma8257_do_operation(running_machine *machine, dma8257_t *dma8257, in { dma8257->status |= (0x01 << channel); if (dma8257->intf->out_tc[channel]) - dma8257->intf->out_tc[channel](machine, 0, ASSERT_LINE); + dma8257->intf->out_tc[channel](device, 0, ASSERT_LINE); } switch(mode) { case 1: if (dma8257->intf->memory_read!=NULL) { - data = dma8257->intf->memory_read(machine, dma8257->address[channel]); + data = dma8257->intf->memory_read(device, dma8257->address[channel]); } else { data = 0; logerror("8257: No memory read function defined.\n"); } if (dma8257->intf->channel_write[channel]!=NULL) { - dma8257->intf->channel_write[channel](machine, 0, data); + dma8257->intf->channel_write[channel](device, 0, data); } else { logerror("8257: No channel write function for channel %d defined.\n",channel); } @@ -110,14 +111,14 @@ static int dma8257_do_operation(running_machine *machine, dma8257_t *dma8257, in case 2: if (dma8257->intf->channel_read[channel]!=NULL) { - data = dma8257->intf->channel_read[channel](machine, 0); + data = dma8257->intf->channel_read[channel](device, 0); } else { data = 0; logerror("8257: No channel read function for channel %d defined.\n",channel); } if (dma8257->intf->memory_write!=NULL) { - dma8257->intf->memory_write(machine, dma8257->address[channel], data); + dma8257->intf->memory_write(device, dma8257->address[channel], data); } else { logerror("8257: No memory write function defined.\n"); } @@ -143,7 +144,7 @@ static int dma8257_do_operation(running_machine *machine, dma8257_t *dma8257, in dma8257->registers[5] = dma8257->registers[7]; } if (dma8257->intf->out_tc[channel]) - dma8257->intf->out_tc[channel](machine, 0, CLEAR_LINE); + dma8257->intf->out_tc[channel](device, 0, CLEAR_LINE); } return done; } @@ -152,7 +153,8 @@ static int dma8257_do_operation(running_machine *machine, dma8257_t *dma8257, in static TIMER_CALLBACK( dma8257_timerproc ) { - dma8257_t *dma8257 = ptr; + const device_config *device = ptr; + dma8257_t *dma8257 = get_safe_token(device); int i, channel = 0, rr; int done; @@ -164,14 +166,14 @@ static TIMER_CALLBACK( dma8257_timerproc ) if (dma8257->mode & dma8257->drq & (1 << channel)) break; } - done = dma8257_do_operation(machine, dma8257, channel); + done = dma8257_do_operation(device, channel); dma8257->rr = (channel + 1) & 0x03; if (done) { dma8257->drq &= ~(0x01 << channel); - dma8257_update_status(machine, dma8257); + dma8257_update_status(device); if (!(DMA_MODE_AUTOLOAD(dma8257->mode) && channel==2)) { if (DMA_MODE_TCSTOP(dma8257->mode)) { dma8257->mode &= ~(0x01 << channel); @@ -184,14 +186,16 @@ static TIMER_CALLBACK( dma8257_timerproc ) static TIMER_CALLBACK( dma8257_msbflip_timerproc ) { - dma8257_t *dma8257 = ptr; + const device_config *device = ptr; + dma8257_t *dma8257 = get_safe_token(device); dma8257->msb ^= 1; } -static void dma8257_update_status(running_machine *machine, dma8257_t *dma8257) +static void dma8257_update_status(const device_config *device) { + dma8257_t *dma8257 = get_safe_token(device); UINT16 pending_transfer; attotime next; @@ -216,7 +220,7 @@ static void dma8257_update_status(running_machine *machine, dma8257_t *dma8257) /* set the halt line */ if (dma8257->intf && dma8257->intf->cpunum >= 0) { - cpunum_set_input_line(machine, dma8257->intf->cpunum, INPUT_LINE_HALT, + cpunum_set_input_line(device->machine, dma8257->intf->cpunum, INPUT_LINE_HALT, pending_transfer ? ASSERT_LINE : CLEAR_LINE); } @@ -320,9 +324,10 @@ WRITE8_DEVICE_HANDLER( dma8257_w ) static TIMER_CALLBACK( dma8257_drq_write_callback ) { + const device_config *device = ptr; + dma8257_t *dma8257 = get_safe_token(device); int channel = param >> 1; int state = param & 0x01; - dma8257_t *dma8257 = ptr; /* normalize state */ if (state) @@ -337,17 +342,16 @@ static TIMER_CALLBACK( dma8257_drq_write_callback ) else dma8257->drq &= ~(0x01 << channel); - dma8257_update_status(machine, dma8257); + dma8257_update_status(device); } WRITE8_DEVICE_HANDLER( dma8257_drq_w ) { - dma8257_t *dma8257 = get_safe_token(device); int param = (offset << 1) | (data ? 1 : 0); - timer_call_after_resynch(dma8257, param, dma8257_drq_write_callback); + timer_call_after_resynch((void *) device, param, dma8257_drq_write_callback); } @@ -369,8 +373,8 @@ static DEVICE_START( dma8257 ) dma8257->intf = device->static_config; dma8257->status = 0x0f; - dma8257->timer = timer_alloc(dma8257_timerproc, dma8257); - dma8257->msbflip_timer = timer_alloc(dma8257_msbflip_timerproc, dma8257); + dma8257->timer = timer_alloc(dma8257_timerproc, (void *) device); + dma8257->msbflip_timer = timer_alloc(dma8257_msbflip_timerproc, (void *) device); state_save_combine_module_and_tag(unique_tag, "dma8257", device->tag); @@ -394,7 +398,7 @@ static DEVICE_RESET( dma8257 ) dma8257->status &= 0xf0; dma8257->mode = 0; - dma8257_update_status(device->machine, dma8257 ); + dma8257_update_status(device); } diff --git a/src/emu/machine/8257dma.h b/src/emu/machine/8257dma.h index 4b2aa25fcea..e311c9e6403 100644 --- a/src/emu/machine/8257dma.h +++ b/src/emu/machine/8257dma.h @@ -28,15 +28,15 @@ struct _dma8257_interface int clockhz; /* accessors to main memory */ - read8_machine_func memory_read; - write8_machine_func memory_write; + read8_device_func memory_read; + write8_device_func memory_write; /* channel accesors */ - read8_machine_func channel_read[DMA8257_NUM_CHANNELS]; - write8_machine_func channel_write[DMA8257_NUM_CHANNELS]; + read8_device_func channel_read[DMA8257_NUM_CHANNELS]; + write8_device_func channel_write[DMA8257_NUM_CHANNELS]; /* function to call when DMA completes */ - write8_machine_func out_tc[DMA8257_NUM_CHANNELS]; + write8_device_func out_tc[DMA8257_NUM_CHANNELS]; }; /* device interface */ diff --git a/src/emu/machine/z80dma.c b/src/emu/machine/z80dma.c index 414b05f39e3..15d24b85586 100644 --- a/src/emu/machine/z80dma.c +++ b/src/emu/machine/z80dma.c @@ -88,7 +88,6 @@ typedef struct _z80dma_t z80dma_t; struct _z80dma_t { - running_machine *machine; const z80dma_interface *intf; emu_timer *timer; @@ -111,7 +110,7 @@ struct _z80dma_t }; static TIMER_CALLBACK( z80dma_timerproc ); -static void z80dma_update_status(running_machine *machine, z80dma_t *z80dma); +static void z80dma_update_status(const device_config *device); /* ----------------------------------------------------------------------- */ @@ -122,8 +121,9 @@ INLINE z80dma_t *get_safe_token(const device_config *device) { return ( z80dma_t * ) device->token; } -static void z80dma_do_read(z80dma_t *cntx) +static void z80dma_do_read(const device_config *device) { + z80dma_t *cntx = get_safe_token(device); UINT8 mode; mode = TRANSFER_MODE(cntx); @@ -132,17 +132,17 @@ static void z80dma_do_read(z80dma_t *cntx) if (PORTA_IS_SOURCE(cntx)) { if (PORTA_MEMORY(cntx)) - cntx->latch = cntx->intf->memory_read(cntx->machine, cntx->addressA); + cntx->latch = cntx->intf->memory_read(device, cntx->addressA); else - cntx->latch = cntx->intf->portA_read(cntx->machine, cntx->addressA); + cntx->latch = cntx->intf->portA_read(device, cntx->addressA); cntx->addressA += PORTA_STEP(cntx); } else { if (PORTB_MEMORY(cntx)) - cntx->latch = cntx->intf->memory_read(cntx->machine, cntx->addressB); + cntx->latch = cntx->intf->memory_read(device, cntx->addressB); else - cntx->latch = cntx->intf->portB_read(cntx->machine, cntx->addressB); + cntx->latch = cntx->intf->portB_read(device, cntx->addressB); cntx->addressB += PORTB_STEP(cntx); } break; @@ -153,8 +153,9 @@ static void z80dma_do_read(z80dma_t *cntx) } } -static int z80dma_do_write(z80dma_t *cntx) +static int z80dma_do_write(const device_config *device) { + z80dma_t *cntx = get_safe_token(device); int done; UINT8 mode; @@ -168,17 +169,17 @@ static int z80dma_do_write(z80dma_t *cntx) if (PORTA_IS_SOURCE(cntx)) { if (PORTB_MEMORY(cntx)) - cntx->intf->memory_write(cntx->machine, cntx->addressB, cntx->latch); + cntx->intf->memory_write(device, cntx->addressB, cntx->latch); else - cntx->intf->portB_write(cntx->machine, cntx->addressB, cntx->latch); + cntx->intf->portB_write(device, cntx->addressB, cntx->latch); cntx->addressB += PORTB_STEP(cntx); } else { if (PORTA_MEMORY(cntx)) - cntx->intf->memory_write(cntx->machine, cntx->addressA, cntx->latch); + cntx->intf->memory_write(device, cntx->addressA, cntx->latch); else - cntx->intf->portB_write(cntx->machine, cntx->addressA, cntx->latch); + cntx->intf->portB_write(device, cntx->addressA, cntx->latch); cntx->addressA += PORTA_STEP(cntx); } cntx->count--; @@ -198,7 +199,8 @@ static int z80dma_do_write(z80dma_t *cntx) static TIMER_CALLBACK( z80dma_timerproc ) { - z80dma_t *cntx = ptr; + const device_config *device = ptr; + z80dma_t *cntx = get_safe_token(device); int done; if (--cntx->cur_cycle) @@ -207,26 +209,27 @@ static TIMER_CALLBACK( z80dma_timerproc ) } if (cntx->is_read) { - z80dma_do_read(cntx); + z80dma_do_read(device); done = 0; cntx->is_read = 0; cntx->cur_cycle = (PORTA_IS_SOURCE(cntx) ? PORTA_CYCLE_LEN(cntx) : PORTB_CYCLE_LEN(cntx)); } else { - done = z80dma_do_write(cntx); + done = z80dma_do_write(device); cntx->is_read = 1; cntx->cur_cycle = (PORTB_IS_SOURCE(cntx) ? PORTA_CYCLE_LEN(cntx) : PORTB_CYCLE_LEN(cntx)); } if (done) { cntx->dma_enabled = 0; //FIXME: Correct? - z80dma_update_status(machine, cntx); + z80dma_update_status(device); } } -static void z80dma_update_status(running_machine *machine, z80dma_t *z80dma) +static void z80dma_update_status(const device_config *device) { + z80dma_t *z80dma = get_safe_token(device); UINT16 pending_transfer; attotime next; @@ -254,7 +257,7 @@ static void z80dma_update_status(running_machine *machine, z80dma_t *z80dma) if (z80dma->intf && z80dma->intf->cpunum >= 0) { //FIXME: Synchronization is done by BUSREQ! - cpunum_set_input_line(machine, z80dma->intf->cpunum, INPUT_LINE_HALT, + cpunum_set_input_line(device->machine, z80dma->intf->cpunum, INPUT_LINE_HALT, pending_transfer ? ASSERT_LINE : CLEAR_LINE); } } @@ -385,14 +388,15 @@ WRITE8_DEVICE_HANDLER( z80dma_w ) static TIMER_CALLBACK( z80dma_rdy_write_callback ) { + const device_config *device = ptr; int state = param & 0x01; - z80dma_t *cntx = ptr; + z80dma_t *cntx = get_safe_token(device); /* normalize state */ cntx->rdy = 1 ^ state ^ READY_ACTIVE_HIGH(cntx); cntx->status = (cntx->status & 0xFD) | (cntx->rdy<<1); - z80dma_update_status(machine, cntx); + z80dma_update_status(device); } @@ -405,7 +409,7 @@ WRITE8_DEVICE_HANDLER( z80dma_rdy_w) param = (data ? 1 : 0); LOG(("RDY: %d Active High: %d\n", data, READY_ACTIVE_HIGH(z80dma))); - timer_call_after_resynch(z80dma, param, z80dma_rdy_write_callback); + timer_call_after_resynch((void *) device, param, z80dma_rdy_write_callback); } /* ----------------------------------------------------------------------- */ @@ -422,11 +426,9 @@ static DEVICE_START( z80dma ) assert(device->tag != NULL); assert(strlen(device->tag) < 20); - //z80dma->device_type = device_type; - z80dma->machine = device->machine; z80dma->intf = device->static_config; - z80dma->timer = timer_alloc(z80dma_timerproc, z80dma); + z80dma->timer = timer_alloc(z80dma_timerproc, (void *) device); state_save_combine_module_and_tag(unique_tag, "z80dma", device->tag); @@ -456,7 +458,7 @@ static DEVICE_RESET( z80dma ) z80dma->rdy = 0; z80dma->num_follow = 0; z80dma->dma_enabled = 0; - z80dma_update_status(device->machine, z80dma); + z80dma_update_status(device); } diff --git a/src/emu/machine/z80dma.h b/src/emu/machine/z80dma.h index 6f000187a14..b8b5cad89ec 100644 --- a/src/emu/machine/z80dma.h +++ b/src/emu/machine/z80dma.h @@ -19,14 +19,14 @@ struct _z80dma_interface int clockhz; /* accessors to main memory */ - read8_machine_func memory_read; - write8_machine_func memory_write; + read8_device_func memory_read; + write8_device_func memory_write; /* port accesors */ - read8_machine_func portA_read; - write8_machine_func portA_write; - read8_machine_func portB_read; - write8_machine_func portB_write; + read8_device_func portA_read; + write8_device_func portA_write; + read8_device_func portB_read; + write8_device_func portB_write; /* interrupt callback - not implemented */ /* void (*irqcb)(int state); */ diff --git a/src/mame/drivers/dkong.c b/src/mame/drivers/dkong.c index d610c8fe3ca..5a777b85f27 100644 --- a/src/mame/drivers/dkong.c +++ b/src/mame/drivers/dkong.c @@ -320,12 +320,12 @@ Donkey Kong Junior Notes * *************************************/ -static READ8_HANDLER( hb_dma_read_byte ); -static WRITE8_HANDLER( hb_dma_write_byte ); -static READ8_HANDLER( dk_dma_read_byte ); -static WRITE8_HANDLER( dk_dma_write_byte ); -static READ8_HANDLER( p8257_ctl_r ); -static WRITE8_HANDLER( p8257_ctl_w ); +static READ8_DEVICE_HANDLER( hb_dma_read_byte ); +static WRITE8_DEVICE_HANDLER( hb_dma_write_byte ); +static READ8_DEVICE_HANDLER( dk_dma_read_byte ); +static WRITE8_DEVICE_HANDLER( dk_dma_write_byte ); +static READ8_DEVICE_HANDLER( p8257_ctl_r ); +static WRITE8_DEVICE_HANDLER( p8257_ctl_w ); /************************************* * @@ -477,7 +477,7 @@ static MACHINE_RESET( drakton ) * *************************************/ -static READ8_HANDLER( dk_dma_read_byte ) +static READ8_DEVICE_HANDLER( dk_dma_read_byte ) { UINT8 result; @@ -488,16 +488,16 @@ static READ8_HANDLER( dk_dma_read_byte ) return result; } -static WRITE8_HANDLER( dk_dma_write_byte ) +static WRITE8_DEVICE_HANDLER( dk_dma_write_byte ) { cpuintrf_push_context(0); program_write_byte(offset, data); cpuintrf_pop_context(); } -static READ8_HANDLER( hb_dma_read_byte ) +static READ8_DEVICE_HANDLER( hb_dma_read_byte ) { - dkong_state *state = machine->driver_data; + dkong_state *state = device->machine->driver_data; int bucket = state->rev_map[(offset>>10) & 0x1ff]; int addr; UINT8 data; @@ -514,9 +514,9 @@ static READ8_HANDLER( hb_dma_read_byte ) return data; } -static WRITE8_HANDLER( hb_dma_write_byte ) +static WRITE8_DEVICE_HANDLER( hb_dma_write_byte ) { - dkong_state *state = machine->driver_data; + dkong_state *state = device->machine->driver_data; int bucket = state->rev_map[(offset>>10) & 0x1ff]; int addr; @@ -530,15 +530,15 @@ static WRITE8_HANDLER( hb_dma_write_byte ) cpuintrf_pop_context(); } -static READ8_HANDLER( p8257_ctl_r ) +static READ8_DEVICE_HANDLER( p8257_ctl_r ) { - dkong_state *state = machine->driver_data; + dkong_state *state = device->machine->driver_data; return state->dma_latch; } -static WRITE8_HANDLER( p8257_ctl_w ) +static WRITE8_DEVICE_HANDLER( p8257_ctl_w ) { - dkong_state *state = machine->driver_data; + dkong_state *state = device->machine->driver_data; state->dma_latch = data; } diff --git a/src/mame/drivers/mario.c b/src/mame/drivers/mario.c index e66f0b6a1b9..0705b299da0 100644 --- a/src/mame/drivers/mario.c +++ b/src/mame/drivers/mario.c @@ -94,8 +94,8 @@ write: #include "mario.h" -static READ8_HANDLER(mario_dma_read_byte); -static WRITE8_HANDLER(mario_dma_write_byte); +static READ8_DEVICE_HANDLER(mario_dma_read_byte); +static WRITE8_DEVICE_HANDLER(mario_dma_write_byte); /************************************* * @@ -125,7 +125,7 @@ static const z80dma_interface mario_dma = * *************************************/ -static READ8_HANDLER(mario_dma_read_byte) +static READ8_DEVICE_HANDLER(mario_dma_read_byte) { UINT8 result; @@ -136,7 +136,7 @@ static READ8_HANDLER(mario_dma_read_byte) return result; } -static WRITE8_HANDLER(mario_dma_write_byte) +static WRITE8_DEVICE_HANDLER(mario_dma_write_byte) { cpuintrf_push_context(0); program_write_byte(offset, data);