From 09802006a1a7afd6ed8d45625827ea4afd3e7bdc Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Tue, 1 Apr 2014 08:08:59 +0000 Subject: [PATCH] converted tait8741 mcu hack to a device, kept it as 4 pack since driver anyway have to use real mcu in future (nw) --- src/mame/drivers/gladiatr.c | 44 +++-- src/mame/drivers/gsword.c | 56 +++--- src/mame/includes/gladiatr.h | 7 +- src/mame/includes/gsword.h | 4 +- src/mame/machine/tait8741.c | 324 +++++++++++++++-------------------- src/mame/machine/tait8741.h | 188 +++++++++++++++++--- 6 files changed, 350 insertions(+), 273 deletions(-) diff --git a/src/mame/drivers/gladiatr.c b/src/mame/drivers/gladiatr.c index bd72b55fe97..0c828b2c2f9 100644 --- a/src/mame/drivers/gladiatr.c +++ b/src/mame/drivers/gladiatr.c @@ -200,60 +200,51 @@ WRITE8_MEMBER(gladiatr_state::gladiatr_bankswitch_w) } -static READ8_HANDLER( gladiator_dsw1_r ) +READ8_MEMBER(gladiatr_state::gladiator_dsw1_r ) { - int orig = space.machine().root_device().ioport("DSW1")->read()^0xff; + int orig = ioport("DSW1")->read()^0xff; return BITSWAP8(orig, 0,1,2,3,4,5,6,7); } -static READ8_HANDLER( gladiator_dsw2_r ) +READ8_MEMBER(gladiatr_state::gladiator_dsw2_r ) { - int orig = space.machine().root_device().ioport("DSW2")->read()^0xff; + int orig = ioport("DSW2")->read()^0xff; return BITSWAP8(orig, 2,3,4,5,6,7,1,0); } -static READ8_HANDLER( gladiator_controls_r ) +READ8_MEMBER(gladiatr_state::gladiator_controls_r ) { int coins = 0; - if( space.machine().root_device().ioport("COINS")->read() & 0xc0 ) coins = 0x80; + if(ioport("COINS")->read() & 0xc0 ) coins = 0x80; switch(offset) { case 0x01: /* start button , coins */ - return space.machine().root_device().ioport("IN0")->read() | coins; + return ioport("IN0")->read() | coins; case 0x02: /* Player 1 Controller , coins */ - return space.machine().root_device().ioport("IN1")->read() | coins; + return ioport("IN1")->read() | coins; case 0x04: /* Player 2 Controller , coins */ - return space.machine().root_device().ioport("IN2")->read() | coins; + return ioport("IN2")->read() | coins; } /* unknown */ return 0; } -static READ8_HANDLER( gladiator_button3_r ) +READ8_MEMBER(gladiatr_state::gladiator_button3_r ) { switch(offset) { case 0x01: /* button 3 */ - return space.machine().root_device().ioport("IN3")->read(); + return ioport("IN3")->read(); } /* unknown */ return 0; } -static const struct TAITO8741interface gladiator_8741interface= -{ - 4, /* 4 chips */ - {TAITO8741_MASTER,TAITO8741_SLAVE,TAITO8741_PORT,TAITO8741_PORT},/* program mode */ - {1,0,0,0}, /* serial port connection */ - {gladiator_dsw1_r,gladiator_dsw2_r,gladiator_button3_r,gladiator_controls_r} /* port handler */ -}; - MACHINE_RESET_MEMBER(gladiatr_state,gladiator) { - TAITO8741_start(&gladiator_8741interface); /* 6809 bank memory set */ { UINT8 *rom = memregion("audiocpu")->base() + 0x10000; @@ -437,17 +428,17 @@ static ADDRESS_MAP_START( gladiatr_cpu1_io, AS_IO, 8, gladiatr_state ) AM_RANGE(0xc002, 0xc002) AM_WRITE(gladiatr_bankswitch_w) AM_RANGE(0xc004, 0xc004) AM_WRITE(gladiatr_irq_patch_w) /* !!! patch to 2nd CPU IRQ !!! */ AM_RANGE(0xc007, 0xc007) AM_WRITE(gladiatr_flipscreen_w) - AM_RANGE(0xc09e, 0xc09f) AM_READWRITE_LEGACY(TAITO8741_0_r, TAITO8741_0_w) + AM_RANGE(0xc09e, 0xc09f) AM_DEVREADWRITE("taito8741", taito8741_4pack_device, read_0, write_0) AM_RANGE(0xc0bf, 0xc0bf) AM_NOP // watchdog_reset_w doesn't work ADDRESS_MAP_END static ADDRESS_MAP_START( gladiatr_cpu2_io, AS_IO, 8, gladiatr_state ) ADDRESS_MAP_GLOBAL_MASK(0xff) AM_RANGE(0x00, 0x01) AM_DEVREADWRITE("ymsnd", ym2203_device, read, write) - AM_RANGE(0x20, 0x21) AM_READWRITE_LEGACY(TAITO8741_1_r, TAITO8741_1_w) + AM_RANGE(0x20, 0x21) AM_DEVREADWRITE("taito8741", taito8741_4pack_device, read_1, write_1) AM_RANGE(0x40, 0x40) AM_NOP // WRITE(sub_irq_ack_w) - AM_RANGE(0x60, 0x61) AM_READWRITE_LEGACY(TAITO8741_2_r, TAITO8741_2_w) - AM_RANGE(0x80, 0x81) AM_READWRITE_LEGACY(TAITO8741_3_r, TAITO8741_3_w) + AM_RANGE(0x60, 0x61) AM_DEVREADWRITE("taito8741", taito8741_4pack_device, read_2, write_2) + AM_RANGE(0x80, 0x81) AM_DEVREADWRITE("taito8741", taito8741_4pack_device, read_3, write_3) AM_RANGE(0xa0, 0xa7) AM_NOP // filters on sound output AM_RANGE(0xe0, 0xe0) AM_WRITE(glad_cpu_sound_command_w) ADDRESS_MAP_END @@ -716,6 +707,11 @@ static MACHINE_CONFIG_START( gladiatr, gladiatr_state ) MCFG_MACHINE_RESET_OVERRIDE(gladiatr_state,gladiator) MCFG_NVRAM_ADD_0FILL("nvram") + MCFG_TAITO8741_ADD("taito8741") + MCFG_TAITO8741_MODES(TAITO8741_MASTER,TAITO8741_SLAVE,TAITO8741_PORT,TAITO8741_PORT) + MCFG_TAITO8741_CONNECT(1,0,0,0) + MCFG_TAITO8741_PORT_HANDLERS(READ8(gladiatr_state,gladiator_dsw1_r),READ8(gladiatr_state,gladiator_dsw2_r),READ8(gladiatr_state,gladiator_button3_r),READ8(gladiatr_state,gladiator_controls_r)) + /* video hardware */ MCFG_SCREEN_ADD("screen", RASTER) MCFG_SCREEN_REFRESH_RATE(60) diff --git a/src/mame/drivers/gsword.c b/src/mame/drivers/gsword.c index 24468e29f87..f131dba361c 100644 --- a/src/mame/drivers/gsword.c +++ b/src/mame/drivers/gsword.c @@ -150,7 +150,7 @@ reg: 0->1 (main->2nd) / : (1->0) 2nd->main : #if 0 -int ::gsword_coins_in(void) +int gsword_state::gsword_coins_in(void) { /* emulate 8741 coin slot */ if (ioport("IN4")->read() & 0xc0) @@ -186,16 +186,16 @@ READ8_MEMBER(gsword_state::gsword_hack_r) return data; } -static READ8_HANDLER( gsword_8741_2_r ) +READ8_MEMBER(gsword_state::gsword_8741_2_r ) { switch (offset) { case 0x01: /* start button , coins */ - return space.machine().root_device().ioport("IN0")->read(); + return ioport("IN0")->read(); case 0x02: /* Player 1 Controller */ - return space.machine().root_device().ioport("IN1")->read(); + return ioport("IN1")->read(); case 0x04: /* Player 2 Controller */ - return space.machine().root_device().ioport("IN3")->read(); + return ioport("IN3")->read(); // default: // logerror("8741-2 unknown read %d PC=%04x\n",offset,space.device().safe_pc()); } @@ -203,48 +203,33 @@ static READ8_HANDLER( gsword_8741_2_r ) return 0; } -static READ8_HANDLER( gsword_8741_3_r ) +READ8_MEMBER(gsword_state::gsword_8741_3_r ) { switch (offset) { case 0x01: /* start button */ - return space.machine().root_device().ioport("IN2")->read(); + return ioport("IN2")->read(); case 0x02: /* Player 1 Controller? */ - return space.machine().root_device().ioport("IN1")->read(); + return ioport("IN1")->read(); case 0x04: /* Player 2 Controller? */ - return space.machine().root_device().ioport("IN3")->read(); + return ioport("IN3")->read(); } /* unknown */ // logerror("8741-3 unknown read %d PC=%04x\n",offset,space.device().safe_pc()); return 0; } -static const struct TAITO8741interface gsword_8741interface= -{ - 4, /* 4 chips */ - { TAITO8741_MASTER,TAITO8741_SLAVE,TAITO8741_PORT,TAITO8741_PORT }, /* program mode */ - { 1,0,0,0 }, /* serial port connection */ - { NULL,NULL,gsword_8741_2_r,gsword_8741_3_r }, /* port handler */ - { "DSW2","DSW1",NULL,NULL } -}; - MACHINE_RESET_MEMBER(gsword_state,gsword) { - int i; - - for(i=0;i<4;i++) TAITO8741_reset(i); m_coins = 0; /* snd CPU mask NMI during reset phase */ m_nmi_enable = 0; m_protect_hack = 0; - - TAITO8741_start(&gsword_8741interface); } MACHINE_RESET_MEMBER(gsword_state,josvolly) { - josvolly_8741_reset(); } INTERRUPT_GEN_MEMBER(gsword_state::gsword_snd_interrupt) @@ -339,12 +324,12 @@ ADDRESS_MAP_END static ADDRESS_MAP_START( cpu1_io_map, AS_IO, 8, gsword_state ) ADDRESS_MAP_GLOBAL_MASK(0xff) - AM_RANGE(0x7e, 0x7f) AM_WRITE_LEGACY(TAITO8741_0_w) AM_READ_LEGACY(TAITO8741_0_r) + AM_RANGE(0x7e, 0x7f) AM_DEVREADWRITE("taito8741", taito8741_4pack_device, read_0, write_0) ADDRESS_MAP_END static ADDRESS_MAP_START( josvolly_cpu1_io_map, AS_IO, 8, gsword_state ) ADDRESS_MAP_GLOBAL_MASK(0xff) - AM_RANGE(0x7e, 0x7f) AM_WRITE_LEGACY(josvolly_8741_0_w) AM_READ_LEGACY(josvolly_8741_0_r) + AM_RANGE(0x7e, 0x7f) AM_DEVREADWRITE("josvolly_8741", josvolly8741_4pack_device, read_0, write_0) ADDRESS_MAP_END // @@ -356,9 +341,9 @@ ADDRESS_MAP_END static ADDRESS_MAP_START( cpu2_io_map, AS_IO, 8, gsword_state ) ADDRESS_MAP_GLOBAL_MASK(0xff) - AM_RANGE(0x00, 0x01) AM_READWRITE_LEGACY(TAITO8741_2_r,TAITO8741_2_w) - AM_RANGE(0x20, 0x21) AM_READWRITE_LEGACY(TAITO8741_3_r,TAITO8741_3_w) - AM_RANGE(0x40, 0x41) AM_READWRITE_LEGACY(TAITO8741_1_r,TAITO8741_1_w) + AM_RANGE(0x00, 0x01) AM_DEVREADWRITE("taito8741", taito8741_4pack_device, read_2, write_2) + AM_RANGE(0x20, 0x21) AM_DEVREADWRITE("taito8741", taito8741_4pack_device, read_3, write_3) + AM_RANGE(0x40, 0x41) AM_DEVREADWRITE("taito8741", taito8741_4pack_device, read_1, write_1) AM_RANGE(0x60, 0x60) AM_READWRITE(gsword_fake_0_r, gsword_AY8910_control_port_0_w) AM_RANGE(0x61, 0x61) AM_DEVREADWRITE("ay1", ay8910_device, data_r, data_w) AM_RANGE(0x80, 0x80) AM_READWRITE(gsword_fake_1_r, gsword_AY8910_control_port_1_w) @@ -388,7 +373,7 @@ static ADDRESS_MAP_START( josvolly_cpu2_map, AS_PROGRAM, 8, gsword_state ) AM_RANGE(0x8002, 0x8002) AM_READ_PORT("IN0") // START // AM_RANGE(0x6000, 0x6000) AM_WRITE(adpcm_soundcommand_w) - AM_RANGE(0xA000, 0xA001) AM_WRITE_LEGACY(josvolly_8741_1_w) AM_READ_LEGACY(josvolly_8741_1_r) + AM_RANGE(0xA000, 0xA001) AM_DEVREADWRITE("josvolly_8741", josvolly8741_4pack_device, read_1, write_1) ADDRESS_MAP_END static ADDRESS_MAP_START( josvolly_cpu2_io_map, AS_IO, 8, gsword_state ) @@ -398,7 +383,7 @@ static ADDRESS_MAP_START( josvolly_cpu2_io_map, AS_IO, 8, gsword_state ) AM_RANGE(0x40, 0x40) AM_READWRITE(gsword_fake_1_r, gsword_AY8910_control_port_1_w) AM_RANGE(0x41, 0x41) AM_DEVREADWRITE("ay2", ay8910_device, data_r, data_w) - AM_RANGE(0x81, 0x81) AM_WRITE_LEGACY(josvolly_nmi_enable_w) + AM_RANGE(0x81, 0x81) AM_DEVWRITE("josvolly_8741", josvolly8741_4pack_device, nmi_enable_w) AM_RANGE(0xC1, 0xC1) AM_NOP // irq clear ADDRESS_MAP_END @@ -666,6 +651,10 @@ static MACHINE_CONFIG_START( gsword, gsword_state ) MCFG_MACHINE_RESET_OVERRIDE(gsword_state,gsword) + MCFG_TAITO8741_ADD("taito8741") + MCFG_TAITO8741_MODES(TAITO8741_MASTER,TAITO8741_SLAVE,TAITO8741_PORT,TAITO8741_PORT) + MCFG_TAITO8741_CONNECT(1,0,0,0) + MCFG_TAITO8741_PORT_HANDLERS(IOPORT("DSW2"),IOPORT("DSW1"),READ8(gsword_state,gsword_8741_2_r),READ8(gsword_state,gsword_8741_3_r)) #if 1 /* to MCU timeout champbbj */ MCFG_QUANTUM_TIME(attotime::from_hz(6000)) @@ -714,6 +703,11 @@ static MACHINE_CONFIG_START( josvolly, gsword_state ) MCFG_CPU_VBLANK_INT_DRIVER("screen", gsword_state, irq0_line_hold) MCFG_MACHINE_RESET_OVERRIDE(gsword_state,josvolly) + + MCFG_JOSVOLLY8741_ADD("josvolly_8741") + MCFG_JOSVOLLY8741_CONNECT(1,0,0,0) + MCFG_JOSVOLLY8741_PORT_HANDLERS(IOPORT("DSW1"),IOPORT("DSW2"),IOPORT("DSW1"),IOPORT("DSW2")) + /* video hardware */ MCFG_SCREEN_ADD("screen", RASTER) diff --git a/src/mame/includes/gladiatr.h b/src/mame/includes/gladiatr.h index 4087132757a..af3a16902c5 100644 --- a/src/mame/includes/gladiatr.h +++ b/src/mame/includes/gladiatr.h @@ -39,6 +39,11 @@ public: int m_fg_tile_bank; int m_bg_tile_bank; + + DECLARE_READ8_MEMBER( gladiator_dsw1_r ); + DECLARE_READ8_MEMBER( gladiator_dsw2_r ); + DECLARE_READ8_MEMBER( gladiator_controls_r ); + DECLARE_READ8_MEMBER( gladiator_button3_r ); DECLARE_WRITE8_MEMBER(gladiatr_videoram_w); DECLARE_WRITE8_MEMBER(gladiatr_colorram_w); DECLARE_WRITE8_MEMBER(gladiatr_textram_w); @@ -65,7 +70,7 @@ public: DECLARE_WRITE8_MEMBER(glad_adpcm_w); DECLARE_READ8_MEMBER(f1_r); DECLARE_DRIVER_INIT(gladiatr); - DECLARE_DRIVER_INIT(ppking); + DECLARE_DRIVER_INIT(ppking); TILE_GET_INFO_MEMBER(bg_get_tile_info); TILE_GET_INFO_MEMBER(fg_get_tile_info); DECLARE_MACHINE_RESET(ppking); diff --git a/src/mame/includes/gsword.h b/src/mame/includes/gsword.h index 3f51737bb7e..788528a7afd 100644 --- a/src/mame/includes/gsword.h +++ b/src/mame/includes/gsword.h @@ -44,9 +44,11 @@ public: DECLARE_WRITE8_MEMBER(gsword_AY8910_control_port_1_w); DECLARE_READ8_MEMBER(gsword_fake_0_r); DECLARE_READ8_MEMBER(gsword_fake_1_r); + DECLARE_READ8_MEMBER( gsword_8741_2_r ); + DECLARE_READ8_MEMBER( gsword_8741_3_r ); DECLARE_WRITE8_MEMBER(gsword_adpcm_data_w); DECLARE_DRIVER_INIT(gsword); - DECLARE_DRIVER_INIT(gsword2); + DECLARE_DRIVER_INIT(gsword2); TILE_GET_INFO_MEMBER(get_bg_tile_info); virtual void video_start(); DECLARE_MACHINE_RESET(gsword); diff --git a/src/mame/machine/tait8741.c b/src/mame/machine/tait8741.c index 372381145d8..3016c803fc6 100644 --- a/src/mame/machine/tait8741.c +++ b/src/mame/machine/tait8741.c @@ -31,38 +31,26 @@ gladiatr and Great Swordsman set. #define CMD_08 1 #define CMD_4a 2 -struct I8741 { - UINT8 toData; /* to host data */ - UINT8 fromData; /* from host data */ - UINT8 fromCmd; /* from host command */ - UINT8 status; /* b0 = rd ready,b1 = wd full,b2 = cmd ?? */ - UINT8 mode; - UINT8 phase; - UINT8 txd[8]; - UINT8 rxd[8]; - UINT8 parallelselect; - UINT8 txpoint; - int connect; - UINT8 pending4a; - int serial_out; - int coins; - read8_space_func portHandler; - const char *portName; -}; +const device_type TAITO8741_4PACK = &device_creator; -static const struct TAITO8741interface *intf; -//static I8741 *taito8741; -static I8741 taito8741[MAX_TAITO8741]; +taito8741_4pack_device::taito8741_4pack_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, TAITO8741_4PACK, "Taito 8741 MCU 4 pack", tag, owner, clock, "taito8741_4pack", __FILE__), + m_port_handler_0_r(*this), + m_port_handler_1_r(*this), + m_port_handler_2_r(*this), + m_port_handler_3_r(*this) +{ +} /* for host data , write */ -static void taito8741_hostdata_w(I8741 *st,int data) +void taito8741_4pack_device::hostdata_w(I8741 *st,int data) { st->toData = data; st->status |= 0x01; } /* from host data , read */ -static int taito8741_hostdata_r(I8741 *st) +int taito8741_4pack_device::hostdata_r(I8741 *st) { if( !(st->status & 0x02) ) return -1; st->status &= 0xfd; @@ -70,7 +58,7 @@ static int taito8741_hostdata_r(I8741 *st) } /* from host command , read */ -static int taito8741_hostcmd_r(I8741 *st) +int taito8741_4pack_device::hostcmd_r(I8741 *st) { if(!(st->status & 0x04)) return -1; st->status &= 0xfb; @@ -80,16 +68,16 @@ static int taito8741_hostcmd_r(I8741 *st) /* TAITO8741 I8741 emulation */ -static void taito8741_serial_rx(I8741 *st,UINT8 *data) +void taito8741_4pack_device::serial_rx(I8741 *st,UINT8 *data) { memcpy(st->rxd,data,8); } /* timer callback of serial tx finish */ -static TIMER_CALLBACK( taito8741_serial_tx ) +TIMER_CALLBACK_MEMBER( taito8741_4pack_device::serial_tx ) { int num = param; - I8741 *st = &taito8741[num]; + I8741 *st = &m_taito8741[num]; I8741 *sst; if( st->mode==TAITO8741_MASTER) @@ -98,31 +86,35 @@ static TIMER_CALLBACK( taito8741_serial_tx ) st->txpoint = 1; if(st->connect >= 0 ) { - sst = &taito8741[st->connect]; + sst = &m_taito8741[st->connect]; /* transfer data */ - taito8741_serial_rx(sst,st->txd); + serial_rx(sst,st->txd); LOG(("8741-%d Serial data TX to %d\n",num,st->connect)); if( sst->mode==TAITO8741_SLAVE) sst->serial_out = 1; } } -void TAITO8741_reset(int num) +void taito8741_4pack_device::device_reset() { - I8741 *st = &taito8741[num]; - st->status = 0x00; - st->phase = 0; - st->parallelselect = 0; - st->txpoint = 1; - st->pending4a = 0; - st->serial_out = 0; - st->coins = 0; - memset(st->rxd,0,8); - memset(st->txd,0,8); + for (int i=0;i<4;i++) + { + I8741 *st = &m_taito8741[i]; + st->number = i; + st->status = 0x00; + st->phase = 0; + st->parallelselect = 0; + st->txpoint = 1; + st->pending4a = 0; + st->serial_out = 0; + st->coins = 0; + memset(st->rxd,0,8); + memset(st->txd,0,8); + } } /* 8741 update */ -static void taito8741_update(address_space &space, int num) +void taito8741_4pack_device::update(int num) { I8741 *st,*sst; int next = num; @@ -130,9 +122,9 @@ static void taito8741_update(address_space &space, int num) do{ num = next; - st = &taito8741[num]; + st = &m_taito8741[num]; if( st->connect != -1 ) - sst = &taito8741[st->connect]; + sst = &m_taito8741[st->connect]; else sst = 0; next = -1; /* check pending command */ @@ -149,14 +141,14 @@ static void taito8741_update(address_space &space, int num) case CMD_4a: /* wait for syncronus ? */ if(!st->pending4a) { - taito8741_hostdata_w(st,0); + hostdata_w(st,0); st->phase = CMD_IDLE; next = num; /* continue this chip */ } break; case CMD_IDLE: /* ----- data in port check ----- */ - data = taito8741_hostdata_r(st); + data = hostdata_r(st); if( data != -1 ) { switch(st->mode) @@ -177,18 +169,18 @@ static void taito8741_update(address_space &space, int num) else { /* port select */ st->parallelselect = data & 0x07; - taito8741_hostdata_w(st,st->portHandler ? st->portHandler(space,st->parallelselect,0xff) : st->portName ? space.machine().root_device().ioport(st->portName)->read() : 0); + hostdata_w(st,port_read(st->number,st->parallelselect)); } } } /* ----- new command fetch ----- */ - data = taito8741_hostcmd_r(st); + data = hostcmd_r(st); switch( data ) { case -1: /* no command data */ break; case 0x00: /* read from parallel port */ - taito8741_hostdata_w(st,st->portHandler ? st->portHandler(space,0,0xff) : st->portName ? space.machine().root_device().ioport(st->portName)->read() : 0 ); + hostdata_w(st,port_read(st->number,0)); break; case 0x01: /* read receive buffer 0 */ case 0x02: /* read receive buffer 1 */ @@ -198,13 +190,13 @@ static void taito8741_update(address_space &space, int num) case 0x06: /* read receive buffer 5 */ case 0x07: /* read receive buffer 6 */ //if (data == 2 && num==0 && st->rxd[data-1]&0x80) logerror("Coin Get\n"); - taito8741_hostdata_w(st,st->rxd[data-1]); + hostdata_w(st,st->rxd[data-1]); break; case 0x08: /* latch received serial data */ - st->txd[0] = st->portHandler ? st->portHandler(space,0,0xff) : st->portName ? space.machine().root_device().ioport(st->portName)->read() : 0; + st->txd[0] = port_read(st->number,0); if( sst ) { - space.machine().scheduler().synchronize(FUNC(taito8741_serial_tx), num); + machine().scheduler().synchronize(timer_expired_delegate(FUNC(taito8741_4pack_device::serial_tx),this), num); st->serial_out = 0; st->status |= 0x04; st->phase = CMD_08; @@ -230,17 +222,17 @@ static void taito8741_update(address_space &space, int num) if(sst->pending4a) { sst->pending4a = 0; /* syncronus */ - taito8741_hostdata_w(st,0); /* return for host */ + hostdata_w(st,0); /* return for host */ next = st->connect; } else st->phase = CMD_4a; } break; case 0x80: /* 8741-3 : return check code */ - taito8741_hostdata_w(st,0x66); + hostdata_w(st,0x66); break; case 0x81: /* 8741-2 : return check code */ - taito8741_hostdata_w(st,0x48); + hostdata_w(st,0x48); break; case 0xf0: /* GSWORD 8741-1 : initialize ?? */ break; @@ -252,120 +244,77 @@ static void taito8741_update(address_space &space, int num) }while(next>=0); } -int TAITO8741_start(const struct TAITO8741interface *taito8741intf) +void taito8741_4pack_device::device_start() { - int i; - - intf = taito8741intf; - - //taito8741 = (I8741 *)malloc(intf->num*sizeof(I8741)); - //if( taito8741 == 0 ) return 1; - - for(i=0;inum;i++) - { - taito8741[i].connect = intf->serial_connect[i]; - taito8741[i].portHandler = intf->portHandler_r[i]; - taito8741[i].portName = intf->portName_r[i]; - taito8741[i].mode = intf->mode[i]; - TAITO8741_reset(i); - } - return 0; + m_port_handler_0_r.resolve_safe(0); + m_port_handler_1_r.resolve_safe(0); + m_port_handler_2_r.resolve_safe(0); + m_port_handler_3_r.resolve_safe(0); } /* read status port */ -static int I8741_status_r(address_space &space, int num) +int taito8741_4pack_device::status_r(int num) { - I8741 *st = &taito8741[num]; - taito8741_update(space, num); - LOG(("%s:8741-%d ST Read %02x\n",space.machine().describe_context(),num,st->status)); + I8741 *st = &m_taito8741[num]; + update(num); + LOG(("%s:8741-%d ST Read %02x\n",machine().describe_context(),num,st->status)); return st->status; } /* read data port */ -static int I8741_data_r(address_space &space, int num) +int taito8741_4pack_device::data_r(int num) { - I8741 *st = &taito8741[num]; + I8741 *st = &m_taito8741[num]; int ret = st->toData; st->status &= 0xfe; - LOG(("%s:8741-%d DATA Read %02x\n",space.machine().describe_context(),num,ret)); + LOG(("%s:8741-%d DATA Read %02x\n",machine().describe_context(),num,ret)); /* update chip */ - taito8741_update(space, num); + update(num); switch( st->mode ) { case TAITO8741_PORT: /* parallel data */ - taito8741_hostdata_w(st,st->portHandler ? st->portHandler(space, st->parallelselect, 0xff) : st->portName ? space.machine().root_device().ioport(st->portName)->read() : 0); + hostdata_w(st,port_read(st->number,st->parallelselect)); break; } return ret; } /* Write data port */ -static void I8741_data_w(address_space &space, int num, int data) +void taito8741_4pack_device::data_w(int num, int data) { - I8741 *st = &taito8741[num]; - LOG(("%s:8741-%d DATA Write %02x\n",space.machine().describe_context(),num,data)); + I8741 *st = &m_taito8741[num]; + LOG(("%s:8741-%d DATA Write %02x\n",machine().describe_context(),num,data)); st->fromData = data; st->status |= 0x02; /* update chip */ - taito8741_update(space, num); + update(num); } /* Write command port */ -static void I8741_command_w(address_space &space, int num, int data) +void taito8741_4pack_device::command_w(int num, int data) { - I8741 *st = &taito8741[num]; - LOG(("%s:8741-%d CMD Write %02x\n",space.machine().describe_context(),num,data)); + I8741 *st = &m_taito8741[num]; + LOG(("%s:8741-%d CMD Write %02x\n",machine().describe_context(),num,data)); st->fromCmd = data; st->status |= 0x04; /* update chip */ - taito8741_update(space,num); + update(num); } -/* Write port handler */ -WRITE8_HANDLER( TAITO8741_0_w ) +UINT8 taito8741_4pack_device::port_read(int num, int offset) { - if(offset&1) I8741_command_w(space,0,data); - else I8741_data_w(space,0,data); -} -WRITE8_HANDLER( TAITO8741_1_w ) -{ - if(offset&1) I8741_command_w(space,1,data); - else I8741_data_w(space,1,data); -} -WRITE8_HANDLER( TAITO8741_2_w ) -{ - if(offset&1) I8741_command_w(space,2,data); - else I8741_data_w(space,2,data); -} -WRITE8_HANDLER( TAITO8741_3_w ) -{ - if(offset&1) I8741_command_w(space,3,data); - else I8741_data_w(space,3,data); + switch(num) + { + case 0 : return m_port_handler_0_r(offset); + case 1 : return m_port_handler_1_r(offset); + case 2 : return m_port_handler_2_r(offset); + case 3 : return m_port_handler_3_r(offset); + default : return 0; + } } -/* Read port handler */ -READ8_HANDLER( TAITO8741_0_r ) -{ - if(offset&1) return I8741_status_r(space,0); - return I8741_data_r(space,0); -} -READ8_HANDLER( TAITO8741_1_r ) -{ - if(offset&1) return I8741_status_r(space,1); - return I8741_data_r(space,1); -} -READ8_HANDLER( TAITO8741_2_r ) -{ - if(offset&1) return I8741_status_r(space,2); - return I8741_data_r(space,2); -} -READ8_HANDLER( TAITO8741_3_r ) -{ - if(offset&1) return I8741_status_r(space,3); - return I8741_data_r(space,3); -} /**************************************************************************** joshi Vollyball set. @@ -378,56 +327,48 @@ joshi Vollyball set. ****************************************************************************/ -static int josvolly_nmi_enable; +const device_type JOSVOLLY8741_4PACK = &device_creator; -struct JV8741 { - UINT8 cmd; - UINT8 sts; - UINT8 txd; - UINT8 outport; - UINT8 rxd; - UINT8 connect; - - UINT8 rst; - - const char *initReadPort; -}; - -static JV8741 i8741[4]; - -void josvolly_8741_reset(void) +josvolly8741_4pack_device::josvolly8741_4pack_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, JOSVOLLY8741_4PACK, "joshi Vollyball 8741 MCU 4 pack", tag, owner, clock, "josvolly8741_4pack", __FILE__), + m_port_handler_0_r(*this), + m_port_handler_1_r(*this), + m_port_handler_2_r(*this), + m_port_handler_3_r(*this) { - int i; +} - josvolly_nmi_enable = 0; +void josvolly8741_4pack_device::device_start() +{ + m_port_handler_0_r.resolve_safe(0); + m_port_handler_1_r.resolve_safe(0); + m_port_handler_2_r.resolve_safe(0); + m_port_handler_3_r.resolve_safe(0); +} - for(i=0;i<4;i++) + +void josvolly8741_4pack_device::device_reset() +{ + m_nmi_enable = 0; + + for(int i=0;i<4;i++) { - i8741[i].cmd = 0; - i8741[i].sts = 0; // 0xf0; /* init flag */ - i8741[i].txd = 0; - i8741[i].outport = 0xff; - i8741[i].rxd = 0; - - i8741[i].rst = 1; + m_i8741[i].cmd = 0; + m_i8741[i].sts = 0; // 0xf0; /* init flag */ + m_i8741[i].txd = 0; + m_i8741[i].outport = 0xff; + m_i8741[i].rxd = 0; + m_i8741[i].rst = 1; } - i8741[0].connect = 1; - i8741[1].connect = 0; - - i8741[0].initReadPort = "DSW1"; /* DSW1 */ - i8741[1].initReadPort = "DSW2"; /* DSW2 */ - i8741[2].initReadPort = "DSW1"; /* DUMMY */ - i8741[3].initReadPort = "DSW2"; /* DUMMY */ - } /* transmit data finish callback */ -static TIMER_CALLBACK( josvolly_8741_tx ) +TIMER_CALLBACK_MEMBER( josvolly8741_4pack_device::tx ) { int num = param; - JV8741 *src = &i8741[num]; - JV8741 *dst = &i8741[src->connect]; + JV8741 *src = &m_i8741[num]; + JV8741 *dst = &m_i8741[src->connect]; dst->rxd = src->txd; @@ -435,22 +376,22 @@ static TIMER_CALLBACK( josvolly_8741_tx ) dst->sts |= 0x01; /* RX ready ? */ } -static void josvolly_8741_do(running_machine &machine, int num) +void josvolly8741_4pack_device::update(int num) { - if( (i8741[num].sts & 0x02) ) + if( (m_i8741[num].sts & 0x02) ) { /* transmit data */ - machine.scheduler().timer_set (attotime::from_usec(1), FUNC(josvolly_8741_tx), num); + machine().scheduler().timer_set (attotime::from_usec(1), timer_expired_delegate(FUNC(josvolly8741_4pack_device::tx),this), num); } } -static void josvolly_8741_w(address_space &space, int num, int offset, int data) +void josvolly8741_4pack_device::write(int num, int offset, int data) { - JV8741 *mcu = &i8741[num]; + JV8741 *mcu = &m_i8741[num]; if(offset==1) { - LOG(("%s:8741[%d] CW %02X\n", space.machine().describe_context(), num, data)); + LOG(("%s:8741[%d] CW %02X\n", machine().describe_context(), num, data)); /* read pointer */ mcu->cmd = data; @@ -472,7 +413,7 @@ static void josvolly_8741_w(address_space &space, int num, int offset, int data) break; case 2: #if 1 - mcu->rxd = space.machine().root_device().ioport("DSW2")->read(); + mcu->rxd = port_read(1); mcu->sts |= 0x01; /* RD ready */ #endif break; @@ -488,7 +429,7 @@ static void josvolly_8741_w(address_space &space, int num, int offset, int data) else { /* data */ - LOG(("%s:8741[%d] DW %02X\n", space.machine().describe_context(), num, data)); + LOG(("%s:8741[%d] DW %02X\n", machine().describe_context(), num, data)); mcu->txd = data ^ 0x40; /* parity reverce ? */ mcu->sts |= 0x02; /* TXD busy */ @@ -496,46 +437,49 @@ static void josvolly_8741_w(address_space &space, int num, int offset, int data) /* interrupt ? */ if(num == 0) { - if(josvolly_nmi_enable) + if(m_nmi_enable) { - space.machine().device("audiocpu")->execute().set_input_line(INPUT_LINE_NMI, PULSE_LINE); - josvolly_nmi_enable = 0; + machine().device("audiocpu")->execute().set_input_line(INPUT_LINE_NMI, PULSE_LINE); + m_nmi_enable = 0; } } #endif } - josvolly_8741_do(space.machine(), num); + update(num); } -static INT8 josvolly_8741_r(address_space &space,int num,int offset) +UINT8 josvolly8741_4pack_device::read(int num,int offset) { - JV8741 *mcu = &i8741[num]; + JV8741 *mcu = &m_i8741[num]; int ret; if(offset==1) { if(mcu->rst) - mcu->rxd = space.machine().root_device().ioport(mcu->initReadPort)->read(); /* port in */ + mcu->rxd = port_read(num); /* port in */ ret = mcu->sts; - LOG(("%s:8741[%d] SR %02X\n",space.machine().describe_context(),num,ret)); + LOG(("%s:8741[%d] SR %02X\n",machine().describe_context(),num,ret)); } else { /* clear status port */ mcu->sts &= ~0x01; /* RD ready */ ret = mcu->rxd; - LOG(("%s:8741[%d] DR %02X\n",space.machine().describe_context(),num,ret)); + LOG(("%s:8741[%d] DR %02X\n",machine().describe_context(),num,ret)); mcu->rst = 0; } return ret; } -WRITE8_HANDLER( josvolly_8741_0_w ){ josvolly_8741_w(space,0,offset,data); } -READ8_HANDLER( josvolly_8741_0_r ) { return josvolly_8741_r(space,0,offset); } -WRITE8_HANDLER( josvolly_8741_1_w ) { josvolly_8741_w(space,1,offset,data); } -READ8_HANDLER( josvolly_8741_1_r ) { return josvolly_8741_r(space,1,offset); } - -WRITE8_HANDLER( josvolly_nmi_enable_w ) +UINT8 josvolly8741_4pack_device::port_read(int num) { - josvolly_nmi_enable = 1; + switch(num) + { + case 0 : return m_port_handler_0_r(0); + case 1 : return m_port_handler_1_r(0); + case 2 : return m_port_handler_2_r(0); + case 3 : return m_port_handler_3_r(0); + default : return 0; + } } + diff --git a/src/mame/machine/tait8741.h b/src/mame/machine/tait8741.h index 71b89bafa98..7be855fc8c2 100644 --- a/src/mame/machine/tait8741.h +++ b/src/mame/machine/tait8741.h @@ -6,46 +6,182 @@ gladiatr and Great Swordsman set. ****************************************************************************/ -#define MAX_TAITO8741 4 - /* NEC 8741 program mode */ #define TAITO8741_MASTER 0 #define TAITO8741_SLAVE 1 #define TAITO8741_PORT 2 -struct TAITO8741interface +#define MCFG_TAITO8741_ADD(_tag) \ + MCFG_DEVICE_ADD(_tag, TAITO8741_4PACK, 0) + +#define MCFG_TAITO8741_PORT_HANDLERS(_devcb0, _devcb1, _devcb2, _devcb3) \ + devcb = &taito8741_4pack_device::set_port_handler_0_callback(*device, DEVCB2_##_devcb0); \ + devcb = &taito8741_4pack_device::set_port_handler_1_callback(*device, DEVCB2_##_devcb1); \ + devcb = &taito8741_4pack_device::set_port_handler_2_callback(*device, DEVCB2_##_devcb2); \ + devcb = &taito8741_4pack_device::set_port_handler_3_callback(*device, DEVCB2_##_devcb3); + +#define MCFG_TAITO8741_MODES(_mode0, _mode1, _mode2, _mode3) \ + taito8741_4pack_device::static_set_mode(*device, 0, _mode0); \ + taito8741_4pack_device::static_set_mode(*device, 1, _mode1); \ + taito8741_4pack_device::static_set_mode(*device, 2, _mode2); \ + taito8741_4pack_device::static_set_mode(*device, 3, _mode3); + + +#define MCFG_TAITO8741_CONNECT(_con0, _con1, _con2, _con3) \ + taito8741_4pack_device::static_set_connect(*device, 0, _con0); \ + taito8741_4pack_device::static_set_connect(*device, 1, _con1); \ + taito8741_4pack_device::static_set_connect(*device, 2, _con2); \ + taito8741_4pack_device::static_set_connect(*device, 3, _con3); + + +class taito8741_4pack_device : public device_t { - int num; - int mode[MAX_TAITO8741]; /* program select */ - int serial_connect[MAX_TAITO8741]; /* serial port connection */ - read8_space_func portHandler_r[MAX_TAITO8741]; /* parallel port handler */ - const char *portName_r[MAX_TAITO8741]; + struct I8741 { + int number; + UINT8 toData; /* to host data */ + UINT8 fromData; /* from host data */ + UINT8 fromCmd; /* from host command */ + UINT8 status; /* b0 = rd ready,b1 = wd full,b2 = cmd ?? */ + UINT8 mode; + UINT8 phase; + UINT8 txd[8]; + UINT8 rxd[8]; + UINT8 parallelselect; + UINT8 txpoint; + int connect; + UINT8 pending4a; + int serial_out; + int coins; + }; + +public: + taito8741_4pack_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); + ~taito8741_4pack_device() {} + + template static devcb2_base &set_port_handler_0_callback(device_t &device, _Object object) { return downcast(device).m_port_handler_0_r.set_callback(object); } + template static devcb2_base &set_port_handler_1_callback(device_t &device, _Object object) { return downcast(device).m_port_handler_1_r.set_callback(object); } + template static devcb2_base &set_port_handler_2_callback(device_t &device, _Object object) { return downcast(device).m_port_handler_2_r.set_callback(object); } + template static devcb2_base &set_port_handler_3_callback(device_t &device, _Object object) { return downcast(device).m_port_handler_3_r.set_callback(object); } + + static void static_set_mode(device_t &device, int num, UINT8 mode) { downcast(device).m_taito8741[num].mode = mode; } + static void static_set_connect(device_t &device, int num, int conn) { downcast(device).m_taito8741[num].connect = conn; } + + DECLARE_READ8_MEMBER( read_0 ) { if(offset&1) return status_r(0); else return data_r(0); } + DECLARE_WRITE8_MEMBER( write_0 ) { if(offset&1) command_w(0,data); else data_w(0,data); } + DECLARE_READ8_MEMBER( read_1 ) { if(offset&1) return status_r(1); else return data_r(1); } + DECLARE_WRITE8_MEMBER( write_1 ) { if(offset&1) command_w(1,data); else data_w(1,data); } + DECLARE_READ8_MEMBER( read_2 ) { if(offset&1) return status_r(2); else return data_r(2); } + DECLARE_WRITE8_MEMBER( write_2 ) { if(offset&1) command_w(2,data); else data_w(2,data); } + DECLARE_READ8_MEMBER( read_3 ) { if(offset&1) return status_r(3); else return data_r(3); } + DECLARE_WRITE8_MEMBER( write_3 ) { if(offset&1) command_w(3,data); else data_w(3,data); } + + TIMER_CALLBACK_MEMBER( serial_tx ); + void update(int num); + int status_r(int num); + int data_r(int num); + void data_w(int num, int data); + void command_w(int num, int data); + + UINT8 port_read(int num, int offset); + +protected: + // device-level overrides + virtual void device_start(); + virtual void device_reset(); + +private: + void hostdata_w(I8741 *st,int data); + int hostdata_r(I8741 *st); + int hostcmd_r(I8741 *st); + void serial_rx(I8741 *st,UINT8 *data); + + // internal state + I8741 m_taito8741[4]; + + devcb2_read8 m_port_handler_0_r; + devcb2_read8 m_port_handler_1_r; + devcb2_read8 m_port_handler_2_r; + devcb2_read8 m_port_handler_3_r; }; -int TAITO8741_start(const struct TAITO8741interface *taito8741intf); -void TAITO8741_reset(int num); +extern const device_type TAITO8741_4PACK; -/* write handler */ -DECLARE_WRITE8_HANDLER( TAITO8741_0_w ); -DECLARE_WRITE8_HANDLER( TAITO8741_1_w ); -DECLARE_WRITE8_HANDLER( TAITO8741_2_w ); -DECLARE_WRITE8_HANDLER( TAITO8741_3_w ); -/* read handler */ -DECLARE_READ8_HANDLER( TAITO8741_0_r ); -DECLARE_READ8_HANDLER( TAITO8741_1_r ); -DECLARE_READ8_HANDLER( TAITO8741_2_r ); -DECLARE_READ8_HANDLER( TAITO8741_3_r ); /**************************************************************************** joshi Volleyball set. ****************************************************************************/ -void josvolly_8741_reset(void); -DECLARE_WRITE8_HANDLER( josvolly_8741_0_w ); -DECLARE_WRITE8_HANDLER( josvolly_8741_1_w ); -DECLARE_READ8_HANDLER( josvolly_8741_0_r ); -DECLARE_READ8_HANDLER( josvolly_8741_1_r ); -DECLARE_WRITE8_HANDLER( josvolly_nmi_enable_w ); +#define MCFG_JOSVOLLY8741_ADD(_tag) \ + MCFG_DEVICE_ADD(_tag, JOSVOLLY8741_4PACK, 0) + +#define MCFG_JOSVOLLY8741_PORT_HANDLERS(_devcb0, _devcb1, _devcb2, _devcb3) \ + devcb = &josvolly8741_4pack_device::set_port_handler_0_callback(*device, DEVCB2_##_devcb0); \ + devcb = &josvolly8741_4pack_device::set_port_handler_1_callback(*device, DEVCB2_##_devcb1); \ + devcb = &josvolly8741_4pack_device::set_port_handler_2_callback(*device, DEVCB2_##_devcb2); \ + devcb = &josvolly8741_4pack_device::set_port_handler_3_callback(*device, DEVCB2_##_devcb3); + +#define MCFG_JOSVOLLY8741_CONNECT(_con0, _con1, _con2, _con3) \ + josvolly8741_4pack_device::static_set_connect(*device, 0, _con0); \ + josvolly8741_4pack_device::static_set_connect(*device, 1, _con1); \ + josvolly8741_4pack_device::static_set_connect(*device, 2, _con2); \ + josvolly8741_4pack_device::static_set_connect(*device, 3, _con3); + + +class josvolly8741_4pack_device : public device_t +{ + struct JV8741 { + UINT8 cmd; + UINT8 sts; + UINT8 txd; + UINT8 outport; + UINT8 rxd; + UINT8 connect; + UINT8 rst; + }; + +public: + josvolly8741_4pack_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); + ~josvolly8741_4pack_device() {} + + template static devcb2_base &set_port_handler_0_callback(device_t &device, _Object object) { return downcast(device).m_port_handler_0_r.set_callback(object); } + template static devcb2_base &set_port_handler_1_callback(device_t &device, _Object object) { return downcast(device).m_port_handler_1_r.set_callback(object); } + template static devcb2_base &set_port_handler_2_callback(device_t &device, _Object object) { return downcast(device).m_port_handler_2_r.set_callback(object); } + template static devcb2_base &set_port_handler_3_callback(device_t &device, _Object object) { return downcast(device).m_port_handler_3_r.set_callback(object); } + + static void static_set_connect(device_t &device, int num, int conn) { downcast(device).m_i8741[num].connect = conn; } + + DECLARE_READ8_MEMBER( read_0 ) { return read(0,offset); } + DECLARE_WRITE8_MEMBER( write_0 ) { write(0,offset,data); } + DECLARE_READ8_MEMBER( read_1 ) { return read(1,offset); } + DECLARE_WRITE8_MEMBER( write_1 ) { write(1,offset,data); } + + DECLARE_WRITE8_HANDLER( nmi_enable_w ) { m_nmi_enable = 1; } + + TIMER_CALLBACK_MEMBER( tx ); +protected: + // device-level overrides + virtual void device_start(); + virtual void device_reset(); + +private: + void update(int num); + void write(int num, int offset, int data); + UINT8 read(int num,int offset); + UINT8 port_read(int num); + + // internal state + JV8741 m_i8741[4]; + int m_nmi_enable; + + devcb2_read8 m_port_handler_0_r; + devcb2_read8 m_port_handler_1_r; + devcb2_read8 m_port_handler_2_r; + devcb2_read8 m_port_handler_3_r; +}; + + +extern const device_type JOSVOLLY8741_4PACK; + #endif