From 0a3395d8eb059b019cc0a961325eb67e2f12ea1c Mon Sep 17 00:00:00 2001 From: Angelo Salese Date: Wed, 17 Aug 2011 20:33:35 +0000 Subject: [PATCH] Moved change clock inside a timer and worked on NMI generation for SMPC, fixes most instances of 2 credits at start-up for ST-V games [Angelo Salese] --- src/mame/drivers/saturn.c | 13 ++++---- src/mame/drivers/stv.c | 10 ++++-- src/mame/machine/smpc.c | 65 +++++++++++++++++++++++++++++++-------- src/mame/video/stvvdp1.c | 6 ++-- src/mame/video/stvvdp2.c | 4 +-- 5 files changed, 71 insertions(+), 27 deletions(-) diff --git a/src/mame/drivers/saturn.c b/src/mame/drivers/saturn.c index aa1fa231f7d..63135cb1f6f 100644 --- a/src/mame/drivers/saturn.c +++ b/src/mame/drivers/saturn.c @@ -176,7 +176,7 @@ static READ32_HANDLER ( stv_io_r32 ) // if(LOG_IOGA) logerror("(PC=%08X): I/O r %08X & %08X\n", cpu_get_pc(&space->device()), offset*4, mem_mask); // popmessage("SEL: %02x MUX: %02x OFF: %02x",port_sel,mux_data,offset*4); -// printf("(PC=%08X): I/O r %08X & %08X\n", cpu_get_pc(&space->device()), offset*4, mem_mask); +// printf("(PC=%08X): I/O r %08X & %08X\n", cpu_get_pc(&space->device()), offset*4, mem_mask); switch(offset) { @@ -292,7 +292,8 @@ static WRITE32_HANDLER ( stv_io_w32 ) saturn_state *state = space->machine().driver_data(); // if(LOG_IOGA) logerror("(PC=%08X): I/O w %08X = %08X & %08X\n", cpu_get_pc(&space->device()), offset*4, data, mem_mask); -// printf("(PC=%08X): I/O w %08X = %08X & %08X\n", cpu_get_pc(&space->device()), offset*4, data, mem_mask); +// if(data != 0x0c) +// printf("(PC=%08X): I/O w %08X = %08X & %08X\n", cpu_get_pc(&space->device()), offset*4, data, mem_mask); switch(offset) { @@ -1693,7 +1694,7 @@ DRIVER_INIT ( stv ) state->m_scu_regs = auto_alloc_array(machine, UINT32, 0x100/4); state->m_scsp_regs = auto_alloc_array(machine, UINT16, 0x1000/2); - state->m_backupram = auto_alloc_array(machine, UINT8, 0x10000); + state->m_backupram = auto_alloc_array_clear(machine, UINT8, 0x8000); install_stvbios_speedups(machine); @@ -2202,7 +2203,7 @@ static MACHINE_RESET( saturn ) state->m_smpc.SR = 0x40; // this bit is always on according to docs state->m_en_68k = 0; - state->m_NMI_reset = 1; + state->m_NMI_reset = 0; DMA_STATUS = 0; @@ -2281,7 +2282,7 @@ static MACHINE_RESET( stv ) cputag_set_input_line(machine, "audiocpu", INPUT_LINE_RESET, ASSERT_LINE); state->m_en_68k = 0; - state->m_NMI_reset = 1; + state->m_NMI_reset = 0; port_sel = mux_data = 0; port_i = -1; @@ -2514,7 +2515,7 @@ static void saturn_init_driver(running_machine &machine, int rgn) state->m_scu_regs = auto_alloc_array(machine, UINT32, 0x100/4); state->m_scsp_regs = auto_alloc_array(machine, UINT16, 0x1000/2); state->m_cart_dram = auto_alloc_array(machine, UINT32, 0x400000/4); - state->m_backupram = auto_alloc_array(machine, UINT8, 0x10000); + state->m_backupram = auto_alloc_array(machine, UINT8, 0x8000); state->m_cart_backupram = auto_alloc_array(machine, UINT8, 0x400000); } diff --git a/src/mame/drivers/stv.c b/src/mame/drivers/stv.c index 40a3511a60c..e0b34a80034 100644 --- a/src/mame/drivers/stv.c +++ b/src/mame/drivers/stv.c @@ -308,7 +308,11 @@ DRIVER_INIT( danchih ) TODO: understand where it gets 0x02020000,it must be 0x0000000 -wpset 60cf888,4,r +bp 6001d5a +bp 6001d22 (60ffef0) + + +(?) wpset 60cf888,4,r */ @@ -1804,8 +1808,8 @@ GAME( 1998, cottonbm, stvbios, stv, stv, cottonbm, ROT0, "Success", GAME( 1995, critcrsh, stvbios, stv, critcrsh, stv, ROT0, "Sega", "Critter Crusher (EA 951204 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS ) GAME( 1999, danchih, stvbios, stv, stvmp, danchih, ROT0, "Altron (Tecmo license)", "Danchi de Hanafuda (J 990607 V1.400)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS ) GAME( 2000, danchiq, stvbios, stv, stv, danchih, ROT0, "Altron", "Danchi de Quiz Okusan Yontaku Desuyo! (J 001128 V1.200)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS ) -GAME( 1996, diehard, stvbios, stv, stv, diehard, ROT0, "Sega", "Die Hard Arcade (UET 960515 V1.000)", GAME_IMPERFECT_SOUND ) -GAME( 1996, dnmtdeka, diehard, stv, stv, dnmtdeka, ROT0, "Sega", "Dynamite Deka (J 960515 V1.000)", GAME_IMPERFECT_SOUND ) +GAME( 1996, diehard, stvbios, stv, stv, diehard, ROT0, "Sega", "Die Hard Arcade (UET 960515 V1.000)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) +GAME( 1996, dnmtdeka, diehard, stv, stv, dnmtdeka, ROT0, "Sega", "Dynamite Deka (J 960515 V1.000)", GAME_IMPERFECT_GRAPHICS | GAME_IMPERFECT_SOUND ) GAME( 1995, ejihon, stvbios, stv, stv, stv, ROT0, "Sega", "Ejihon Tantei Jimusyo (J 950613 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS ) GAME( 1995, fhboxers, stvbios, stv, stv, fhboxers, ROT0, "Sega", "Funky Head Boxers (JUETBKAL 951218 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS ) GAME( 1994, gaxeduel, stvbios, stv, stv, gaxeduel, ROT0, "Sega", "Golden Axe - The Duel (JUETL 950117 V1.000)", GAME_IMPERFECT_SOUND | GAME_IMPERFECT_GRAPHICS) diff --git a/src/mame/machine/smpc.c b/src/mame/machine/smpc.c index 63175cdb84b..352e073b874 100644 --- a/src/mame/machine/smpc.c +++ b/src/mame/machine/smpc.c @@ -155,6 +155,25 @@ TODO: #define LOG_SMPC 0 #define LOG_PAD_CMD 0 +#if 0 +/* TODO: move this into video functions */ +static int vblank_line(running_machine &machine) +{ + saturn_state *state = machine.driver_data(); + int max_y = machine.primary_screen->height(); + int y_step,vblank_line; + + y_step = 2; + + if((max_y == 263 && state->m_vdp2.pal == 0) || (max_y == 313 && state->m_vdp2.pal == 1)) + y_step = 1; + + vblank_line = (state->m_vdp2.pal) ? 288 : 240; + + return vblank_line*y_step; +} +#endif + static TIMER_CALLBACK( stv_bankswitch_state ) { saturn_state *state = machine.driver_data(); @@ -224,22 +243,31 @@ static void smpc_system_reset(running_machine &machine) device_set_input_line(state->m_maincpu, INPUT_LINE_RESET, PULSE_LINE); } -static void smpc_change_clock(running_machine &machine, UINT8 cmd) +static TIMER_CALLBACK( smpc_change_clock ) { saturn_state *state = machine.driver_data(); UINT32 xtal; - xtal = cmd ? MASTER_CLOCK_320 : MASTER_CLOCK_352; + if(LOG_SMPC) printf ("Clock change execute at (%d %d)\n",machine.primary_screen->hpos(),machine.primary_screen->vpos()); + + xtal = param ? MASTER_CLOCK_320 : MASTER_CLOCK_352; machine.device("maincpu")->set_unscaled_clock(xtal/2); machine.device("slave")->set_unscaled_clock(xtal/2); - state->m_vdp2.dotsel = cmd ^ 1; + state->m_vdp2.dotsel = param ^ 1; stv_vdp2_dynamic_res_change(machine); - device_set_input_line(state->m_maincpu, INPUT_LINE_NMI, PULSE_LINE); // ff said this causes nmi, should we set a timer then nmi? + if(state->m_NMI_reset) + device_set_input_line(state->m_maincpu, INPUT_LINE_NMI, PULSE_LINE); device_set_input_line(state->m_slave, INPUT_LINE_RESET, ASSERT_LINE); // command also asserts slave cpu - /* TODO: VDP1 / VDP2 / SCU / SCSP default power ON values */ + + /* put issued command in OREG31 */ + state->m_smpc.OREG[31] = 0x0e + param; + /* clear hand-shake flag */ + state->m_smpc.SF = 0x00; + + /* TODO: VDP1 / VDP2 / SCU / SCSP default power ON values? */ } static TIMER_CALLBACK( stv_smpc_intback ) @@ -567,7 +595,7 @@ static void smpc_nmi_req(running_machine &machine) { saturn_state *state = machine.driver_data(); - /*NMI is unconditionally requested?*/ + /*NMI is unconditionally requested */ device_set_input_line(state->m_maincpu, INPUT_LINE_NMI, PULSE_LINE); } @@ -638,13 +666,24 @@ static void stv_comreg_exec(address_space *space,UINT8 data) break; case 0x0e: case 0x0f: - if(LOG_SMPC) printf ("SMPC: Change Clock to %s\n",data & 1 ? "320" : "352"); - smpc_change_clock(space->machine(),data & 1); + if(LOG_SMPC) printf ("SMPC: Change Clock to %s (%d %d)\n",data & 1 ? "320" : "352",space->machine().primary_screen->hpos(),space->machine().primary_screen->vpos()); + + /* on ST-V timing of this is pretty fussy, you get 2 credits at start-up otherwise + sokyugurentai threshold is 74 lines + shanhigw threshold is 90 lines + I assume that it needs ~100 lines, so 6666,(6) usecs. Obviously needs HW tests ... */ + + space->machine().scheduler().timer_set(attotime::from_usec(6666), FUNC(smpc_change_clock),data & 1); break; /*"Interrupt Back"*/ case 0x10: - if(LOG_SMPC) printf ("SMPC: Status Acquire\n"); - space->machine().scheduler().timer_set(attotime::from_msec(16), FUNC(stv_smpc_intback),0); //TODO: variable time + if(LOG_SMPC) + { + saturn_state *state = space->machine().driver_data(); + printf ("SMPC: Status Acquire %02x %02x %02x %d\n",state->m_smpc.IREG[0],state->m_smpc.IREG[1],state->m_smpc.IREG[2],space->machine().primary_screen->vpos()); + } + + space->machine().scheduler().timer_set(attotime::from_usec(700), FUNC(stv_smpc_intback),0); //TODO: variable time break; /* RTC write*/ case 0x16: @@ -687,7 +726,7 @@ WRITE8_HANDLER( stv_SMPC_w ) stv_comreg_exec(space,data); // we've processed the command, clear status flag - if(data != 0x10 && data != 0x02 && data != 0x03) + if(data != 0x10 && data != 0x02 && data != 0x03 && data != 0xe && data != 0xf) { state->m_smpc.OREG[31] = data; //read-back command state->m_smpc.SF = 0x00; @@ -838,7 +877,7 @@ static void saturn_comreg_exec(address_space *space,UINT8 data) case 0x0e: case 0x0f: if(LOG_SMPC) printf ("SMPC: Change Clock to %s\n",data & 1 ? "320" : "352"); - smpc_change_clock(space->machine(),data & 1); + space->machine().scheduler().timer_set(attotime::from_usec(6666), FUNC(smpc_change_clock),data & 1); break; /*"Interrupt Back"*/ case 0x10: @@ -919,7 +958,7 @@ WRITE8_HANDLER( saturn_SMPC_w ) saturn_comreg_exec(space,data); // we've processed the command, clear status flag - if(data != 0x10 && data != 2 && data != 3 && data != 6 && data != 7) + if(data != 0x10 && data != 2 && data != 3 && data != 6 && data != 7 && data != 0x0e && data != 0x0f) { state->m_smpc.OREG[31] = data; //read-back for last command issued state->m_smpc.SF = 0x00; //clear hand-shake flag diff --git a/src/mame/video/stvvdp1.c b/src/mame/video/stvvdp1.c index b1e79325297..586d05f68b9 100644 --- a/src/mame/video/stvvdp1.c +++ b/src/mame/video/stvvdp1.c @@ -1944,9 +1944,9 @@ static void stv_vdp1_process_list(running_machine &machine) { if ( stv2_current_sprite.CMDPMOD & 0x0400 ) { - if(stv2_current_sprite.CMDPMOD & 0x0200) /* TODO: Bio Hazard inventory screen uses outside cliprect */ - cliprect = &state->m_vdp1.system_cliprect; - else + //if(stv2_current_sprite.CMDPMOD & 0x0200) /* TODO: Bio Hazard inventory screen uses outside cliprect */ + // cliprect = &state->m_vdp1.system_cliprect; + //else cliprect = &state->m_vdp1.user_cliprect; } else diff --git a/src/mame/video/stvvdp2.c b/src/mame/video/stvvdp2.c index 112801ce8d0..f0ee7b42f08 100644 --- a/src/mame/video/stvvdp2.c +++ b/src/mame/video/stvvdp2.c @@ -4321,8 +4321,8 @@ static void stv_vdp2_check_tilemap(running_machine &machine, bitmap_t *bitmap, c { /* Pukunpa */ - if(STV_VDP2_SPWINEN) - popmessage("Sprite Window enabled"); + //if(STV_VDP2_SPWINEN) + // popmessage("Sprite Window enabled"); /* Capcom Collection Dai 2 - Choh Makaimura (Duh!) */ if(STV_VDP2_MZCTL & 0x1f && 0)