Previous 15994 Revisions Next

r3831 Saturday 13th December, 2008 at 14:27:16 UTC by R. Belmont
[SATURN] Synced to MAME u5 ST-V, works again.
[src/mess/drivers]saturn.c

src/mess/drivers/saturn.c
r3830r3831
257257int minit_boost,sinit_boost;
258258attotime minit_boost_timeslice, sinit_boost_timeslice;
259259
260static int scanline;
260//static int scanline;
261261
262/*A-Bus IRQ checks,where they could be located these?*/
263#define ABUSIRQ(_irq_,_vector_) \
264   { cpu_set_input_line_and_vector(device->machine->cpu[0], _irq_, HOLD_LINE , _vector_); }
262265#if 0
263/*A-Bus IRQ checks,where they could be located these?*/
264#define ABUSIRQ(_irq_,_vector_,_mask_) \
265   if(!(stv_scu[40] & _mask_)) { cpu_set_input_line_and_vector(Machine->cpu[0], _irq_, HOLD_LINE , _vector_); }
266
267266if(stv_scu[42] & 1)//IRQ ACK
268267{
269268   ABUSIRQ(7,0x50,0x00010000);
r3830r3831
629628      if(EXLE1 || EXLE2)
630629         if(!(stv_scu[40] & 0x0100)) /*Pad irq*/
631630         {
632            if(LOG_SMPC) logerror ("Interrupt: PAD irq at scanline %04x, Vector 0x48 Level 0x08\n",scanline);
631            if(LOG_SMPC) logerror ("Interrupt: PAD irq, Vector 0x48 Level 0x08\n");
633632            cpu_set_input_line_and_vector(machine->cpu[0], 8, HOLD_LINE , 0x48);
634633         }
635634   }
r3830r3831
836835
837836
838837/*
839(Preliminary) explaination about this:
840VBLANK-OUT is used at the start of the vblank period.It also sets the timer zero
841variable to 0.
842If the Timer Compare register is zero too,the Timer 0 irq is triggered.
843838
844HBLANK-IN is used at the end of each scanline except when in VBLANK-IN/OUT periods.
845
846The timer 0 is also incremented by one at each HBLANK and checked with the value
847of the Timer Compare register;if equal,the timer 0 irq is triggered here too.
848Notice that the timer 0 compare register can be more than the VBLANK maximum range,in
849this case the timer 0 irq is simply never triggered.This is a known Sega Saturn/ST-V "bug".
850
851VBLANK-IN is used at the end of the vblank period.
852
853SCU register[36] is the timer zero compare register.
854SCU register[40] is for IRQ masking.
855*/
856
857/* to do, update bios idle skips so they work better with this arrangement.. */
858
859static emu_timer *vblank_in_timer,*scan_timer,*t1_timer;
860static int h_sync,v_sync;
861static int cur_scan;
862
863#define VBLANK_OUT_IRQ   \
864timer_0 = 0; \
865{ \
866   /*if(LOG_IRQ) logerror ("Interrupt: VBlank-OUT Vector 0x41 Level 0x0e\n");*/ \
867   cpu_set_input_line_and_vector(device->machine->cpu[0], 0xe, (stv_irq.vblank_out) ? HOLD_LINE : CLEAR_LINE , 0x41); \
868} \
869
870#define VBLANK_IN_IRQ \
871{ \
872   /*if(LOG_IRQ) logerror ("Interrupt: VBlank IN Vector 0x40 Level 0x0f\n");*/ \
873   cpu_set_input_line_and_vector(machine->cpu[0], 0xf, (stv_irq.vblank_in) ? HOLD_LINE : CLEAR_LINE , 0x40); \
874} \
875
876#define HBLANK_IN_IRQ \
877timer_1 = stv_scu[37] & 0x1ff; \
878{ \
879   /*if(LOG_IRQ) logerror ("Interrupt: HBlank-In at scanline %04x, Vector 0x42 Level 0x0d\n",scanline);*/ \
880   cpu_set_input_line_and_vector(machine->cpu[0], 0xd, (stv_irq.hblank_in) ? HOLD_LINE : CLEAR_LINE, 0x42); \
881} \
882
883#define TIMER_0_IRQ \
884if(timer_0 == (stv_scu[36] & 0x3ff)) \
885{ \
886   /*if(LOG_IRQ) logerror ("Interrupt: Timer 0 at scanline %04x, Vector 0x43 Level 0x0c\n",scanline);*/ \
887   cpu_set_input_line_and_vector(machine->cpu[0], 0xc, (stv_irq.timer_0) ? HOLD_LINE : CLEAR_LINE, 0x43 ); \
888} \
889
890#define TIMER_1_IRQ   \
891if((stv_scu[38] & 1)) \
892{ \
893   if(!(stv_scu[38] & 0x80)) \
894   { \
895      /*if(LOG_IRQ) logerror ("Interrupt: Timer 1 at point %04x, Vector 0x44 Level 0x0b\n",point);*/ \
896      cpu_set_input_line_and_vector(machine->cpu[0], 0xb, (stv_irq.timer_1) ? HOLD_LINE : CLEAR_LINE, 0x44 ); \
897   } \
898   else \
899   { \
900      if((timer_0) == (stv_scu[36] & 0x3ff)) \
901      { \
902         /*if(LOG_IRQ) logerror ("Interrupt: Timer 1 at point %04x, Vector 0x44 Level 0x0b\n",point);*/ \
903         cpu_set_input_line_and_vector(machine->cpu[0], 0xb, (stv_irq.timer_1) ? HOLD_LINE : CLEAR_LINE, 0x44 ); \
904      } \
905   } \
906} \
907
908#define VDP1_IRQ \
909{ \
910   cpu_set_input_line_and_vector(machine->cpu[0], 2, (stv_irq.vdp1_end) ? HOLD_LINE : CLEAR_LINE, 0x4d); \
911} \
912
913static TIMER_CALLBACK( hblank_in_irq )
914{
915   int scanline = param;
916
917//  h = video_screen_get_height(machine->primary_screen);
918//  w = video_screen_get_width(machine->primary_screen);
919
920   TIMER_0_IRQ;
921   HBLANK_IN_IRQ;
922
923   if((scanline+1) < v_sync)
924   {
925      timer_adjust_oneshot(scan_timer, video_screen_get_time_until_pos(machine->primary_screen, scanline+1, h_sync), scanline+1);
926      /*set the first Timer-1 event*/
927      cur_scan = scanline+1;
928      timer_adjust_oneshot(t1_timer, video_screen_get_time_until_pos(machine->primary_screen, scanline+1, 0), 0);
929   }
930
931   timer_0++;
932}
933
934static TIMER_CALLBACK( timer1_irq )
935{
936   int cur_point = param;
937
938   TIMER_1_IRQ;
939
940   if((cur_point+1) < h_sync)
941   {
942      timer_adjust_oneshot(t1_timer, video_screen_get_time_until_pos(machine->primary_screen, cur_scan, cur_point+1), cur_point+1);
943   }
944
945   if(timer_1 > 0) timer_1--;
946}
947
948static TIMER_CALLBACK( vdp1_irq )
949{
950   VDP1_IRQ;
951}
952
953static TIMER_CALLBACK( vblank_in_irq )
954{
955   VBLANK_IN_IRQ;
956}
957
958/*V-Blank-OUT event*/
959static INTERRUPT_GEN( stv_interrupt )
960{
961//  scanline = 0;
962   h_sync = video_screen_get_height(device->machine->primary_screen)/2;//horz
963   v_sync = video_screen_get_width(device->machine->primary_screen)-2;//vert
964
965   VBLANK_OUT_IRQ;
966
967   /*Next V-Blank-IN event*/
968   timer_adjust_oneshot(vblank_in_timer,video_screen_get_time_until_pos(device->machine->primary_screen, 0, 0), 0);
969   /*Set the first Hblank-IN event*/
970   timer_adjust_oneshot(scan_timer, video_screen_get_time_until_pos(device->machine->primary_screen, 0, h_sync), 0);
971
972   /*TODO: timing of this one (related to the VDP1 speed)*/
973   /*      (NOTE: value shouldn't be at h_sync/v_sync position (will break shienryu))*/
974   timer_set(device->machine, video_screen_get_time_until_pos(device->machine->primary_screen,0,0), NULL, 0, vdp1_irq);
975}
976
977static UINT8 port_sel,mux_data;
978
979#define HI_WORD_ACCESS (~mem_mask & 0x00ff0000) == 0
980#define LO_WORD_ACCESS (~mem_mask & 0x000000ff) == 0
981
982/*
983
984839SCU Handling
985840
986841*/
r3830r3831
1113968      if(LOG_SCU) logerror("(PC=%08x) DMA status reg read\n",cpu_get_pc(space->cpu));
1114969      return stv_scu[offset];
1115970   }
971   // Saturn BIOS needs this (need to investigate further)
972   else if (offset == 32)
973   {
974      return 0x00100000;
975   }
1116976   else if ( offset == 35 )
1117977   {
1118978        if(LOG_SCU) logerror( "DSP mem read at %08X\n", stv_scu[34]);
r3830r3831
13661226      stv_irq.sound_req =  (((stv_scu[40] & 0x0040)>>6) ^ 1);
13671227      stv_irq.smpc =       (((stv_scu[40] & 0x0080)>>7)); //NOTE: SCU bug
13681228      stv_irq.pad =        (((stv_scu[40] & 0x0100)>>8) ^ 1);
1369      stv_irq.dma_end[0] = (((stv_scu[40] & 0x0200)>>9) ^ 1);
1229      stv_irq.dma_end[2] = (((stv_scu[40] & 0x0200)>>9) ^ 1);
13701230      stv_irq.dma_end[1] = (((stv_scu[40] & 0x0400)>>10) ^ 1);
1371      stv_irq.dma_end[2] = (((stv_scu[40] & 0x0800)>>11) ^ 1);
1231      stv_irq.dma_end[0] = (((stv_scu[40] & 0x0800)>>11) ^ 1);
13721232      stv_irq.dma_ill =    (((stv_scu[40] & 0x1000)>>12) ^ 1);
13731233      stv_irq.vdp1_end =   (((stv_scu[40] & 0x2000)>>13) ^ 1);
13741234      stv_irq.abus =       (((stv_scu[40] & 0x8000)>>15) ^ 1);
r3830r3831
14131273      stv_irq.sound_req =  ((stv_scu[41] & 0x0040)>>6);
14141274      stv_irq.smpc =       ((stv_scu[41] & 0x0080)>>7);
14151275      stv_irq.pad =        ((stv_scu[41] & 0x0100)>>8);
1416      stv_irq.dma_end[0] = ((stv_scu[41] & 0x0200)>>9);
1276      stv_irq.dma_end[2] = ((stv_scu[41] & 0x0200)>>9);
14171277      stv_irq.dma_end[1] = ((stv_scu[41] & 0x0400)>>10);
1418      stv_irq.dma_end[2] = ((stv_scu[41] & 0x0800)>>11);
1278      stv_irq.dma_end[0] = ((stv_scu[41] & 0x0800)>>11);
14191279      stv_irq.dma_ill =    ((stv_scu[41] & 0x1000)>>12);
14201280      stv_irq.vdp1_end =   ((stv_scu[41] & 0x2000)>>13);
14211281      stv_irq.abus =       ((stv_scu[41] & 0x8000)>>15);
r3830r3831
21742034   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_NAME("P2 R") PORT_PLAYER(2)   // R
21752035INPUT_PORTS_END
21762036
2037/*
2038(Preliminary) explaination about this:
2039VBLANK-OUT is used at the start of the vblank period.It also sets the timer zero
2040variable to 0.
2041If the Timer Compare register is zero too,the Timer 0 irq is triggered.
2042
2043HBLANK-IN is used at the end of each scanline except when in VBLANK-IN/OUT periods.
2044
2045The timer 0 is also incremented by one at each HBLANK and checked with the value
2046of the Timer Compare register;if equal,the timer 0 irq is triggered here too.
2047Notice that the timer 0 compare register can be more than the VBLANK maximum range,in
2048this case the timer 0 irq is simply never triggered.This is a known Sega Saturn/ST-V "bug".
2049
2050VBLANK-IN is used at the end of the vblank period.
2051
2052SCU register[36] is the timer zero compare register.
2053SCU register[40] is for IRQ masking.
2054*/
2055
2056/* to do, update bios idle skips so they work better with this arrangement.. */
2057
2058static emu_timer *vblank_out_timer,*scan_timer,*t1_timer;
2059static int h_sync,v_sync;
2060static int cur_scan;
2061
2062#define VBLANK_OUT_IRQ   \
2063timer_0 = 0; \
2064{ \
2065   /*if(LOG_IRQ) logerror ("Interrupt: VBlank-OUT Vector 0x41 Level 0x0e\n");*/ \
2066   cpu_set_input_line_and_vector(machine->cpu[0], 0xe, (stv_irq.vblank_out) ? HOLD_LINE : CLEAR_LINE , 0x41); \
2067} \
2068
2069#define VBLANK_IN_IRQ \
2070{ \
2071   /*if(LOG_IRQ) logerror ("Interrupt: VBlank IN Vector 0x40 Level 0x0f\n");*/ \
2072   cpu_set_input_line_and_vector(device->machine->cpu[0], 0xf, (stv_irq.vblank_in) ? HOLD_LINE : CLEAR_LINE , 0x40); \
2073} \
2074
2075#define HBLANK_IN_IRQ \
2076timer_1 = stv_scu[37] & 0x1ff; \
2077{ \
2078   /*if(LOG_IRQ) logerror ("Interrupt: HBlank-In at scanline %04x, Vector 0x42 Level 0x0d\n",scanline);*/ \
2079   cpu_set_input_line_and_vector(machine->cpu[0], 0xd, (stv_irq.hblank_in) ? HOLD_LINE : CLEAR_LINE, 0x42); \
2080} \
2081
2082#define TIMER_0_IRQ \
2083if(timer_0 == (stv_scu[36] & 0x3ff)) \
2084{ \
2085   /*if(LOG_IRQ) logerror ("Interrupt: Timer 0 at scanline %04x, Vector 0x43 Level 0x0c\n",scanline);*/ \
2086   cpu_set_input_line_and_vector(machine->cpu[0], 0xc, (stv_irq.timer_0) ? HOLD_LINE : CLEAR_LINE, 0x43 ); \
2087} \
2088
2089#define TIMER_1_IRQ   \
2090if((stv_scu[38] & 1)) \
2091{ \
2092   if(!(stv_scu[38] & 0x80)) \
2093   { \
2094      /*if(LOG_IRQ) logerror ("Interrupt: Timer 1 at point %04x, Vector 0x44 Level 0x0b\n",point);*/ \
2095      cpu_set_input_line_and_vector(machine->cpu[0], 0xb, (stv_irq.timer_1) ? HOLD_LINE : CLEAR_LINE, 0x44 ); \
2096   } \
2097   else \
2098   { \
2099      if((timer_0) == (stv_scu[36] & 0x3ff)) \
2100      { \
2101         /*if(LOG_IRQ) logerror ("Interrupt: Timer 1 at point %04x, Vector 0x44 Level 0x0b\n",point);*/ \
2102         cpu_set_input_line_and_vector(machine->cpu[0], 0xb, (stv_irq.timer_1) ? HOLD_LINE : CLEAR_LINE, 0x44 ); \
2103      } \
2104   } \
2105} \
2106
2107#define VDP1_IRQ \
2108{ \
2109   cpu_set_input_line_and_vector(machine->cpu[0], 2, (stv_irq.vdp1_end) ? HOLD_LINE : CLEAR_LINE, 0x4d); \
2110} \
2111
2112static TIMER_CALLBACK( hblank_in_irq )
2113{
2114   int scanline = param;
2115
2116//  h = video_screen_get_height(machine->primary_screen);
2117//  w = video_screen_get_width(machine->primary_screen);
2118
2119   HBLANK_IN_IRQ;
2120   TIMER_0_IRQ;
2121
2122   if(scanline+1 < v_sync)
2123   {
2124      if(stv_irq.hblank_in || stv_irq.timer_0)
2125         timer_adjust_oneshot(scan_timer, video_screen_get_time_until_pos(machine->primary_screen, scanline+1, h_sync), scanline+1);
2126      /*set the first Timer-1 event*/
2127      cur_scan = scanline+1;
2128      if(stv_irq.timer_1)
2129         timer_adjust_oneshot(t1_timer, video_screen_get_time_until_pos(machine->primary_screen, scanline+1, 0), 0);
2130   }
2131
2132   timer_0++;
2133}
2134
2135static TIMER_CALLBACK( timer1_irq )
2136{
2137   int cur_point = param;
2138
2139   TIMER_1_IRQ;
2140
2141   if((cur_point+1) < h_sync && stv_irq.timer_1)
2142   {
2143      timer_adjust_oneshot(t1_timer, video_screen_get_time_until_pos(machine->primary_screen, cur_scan, cur_point+1), cur_point+1);
2144   }
2145
2146   if(timer_1 > 0) timer_1--;
2147}
2148
2149static TIMER_CALLBACK( vdp1_irq )
2150{
2151   VDP1_IRQ;
2152}
2153
2154static TIMER_CALLBACK( vblank_out_irq )
2155{
2156   VBLANK_OUT_IRQ;
2157}
2158
2159/*V-Blank-IN event*/
2160static INTERRUPT_GEN( stv_interrupt )
2161{
2162//  scanline = 0;
2163   rectangle visarea = *video_screen_get_visible_area(device->machine->primary_screen);
2164
2165   h_sync = visarea.max_x+1;//horz
2166   v_sync = visarea.max_y+1;//vert
2167
2168   VBLANK_IN_IRQ;
2169
2170   /*Next V-Blank-OUT event*/
2171   if(stv_irq.vblank_out)
2172      timer_adjust_oneshot(vblank_out_timer,video_screen_get_time_until_pos(device->machine->primary_screen, 0, 0), 0);
2173   /*Set the first Hblank-IN event*/
2174   if(stv_irq.hblank_in || stv_irq.timer_0 || stv_irq.timer_1)
2175      timer_adjust_oneshot(scan_timer, video_screen_get_time_until_pos(device->machine->primary_screen, 0, h_sync), 0);
2176
2177   /*TODO: timing of this one (related to the VDP1 speed)*/
2178   /*      (NOTE: value shouldn't be at h_sync/v_sync position (will break shienryu))*/
2179   timer_set(device->machine, video_screen_get_time_until_pos(device->machine->primary_screen,0,0), NULL, 0, vdp1_irq);
2180}
2181
21772182static void saturn_init_driver(running_machine *machine, int rgn)
21782183{
21792184   mame_system_time systime;
r3830r3831
22422247   state_save_register_global(machine, en_68k);
22432248   state_save_register_global(machine, timer_0);
22442249   state_save_register_global(machine, timer_1);
2245   state_save_register_global(machine, scanline);
22462250   state_save_register_global(machine, IOSEL1);
22472251   state_save_register_global(machine, IOSEL2);
22482252   state_save_register_global(machine, EXLE1);
22492253   state_save_register_global(machine, EXLE2);
22502254   state_save_register_global(machine, PDR1);
22512255   state_save_register_global(machine, PDR2);
2252   state_save_register_global(machine, port_sel);
2253   state_save_register_global(machine, mux_data);
2256//   state_save_register_global(machine, port_sel);
2257//   state_save_register_global(machine, mux_data);
22542258   state_save_register_global(machine, scsp_last_line);
22552259   state_save_register_global(machine, intback_stage);
22562260   state_save_register_global(machine, pmode);
r3830r3831
22892293   /* set the first scanline 0 timer to go off */
22902294   scan_timer = timer_alloc(machine, hblank_in_irq, NULL);
22912295   t1_timer = timer_alloc(machine, timer1_irq,NULL);
2292   vblank_in_timer = timer_alloc(machine, vblank_in_irq,NULL);
2293   timer_adjust_oneshot(vblank_in_timer,video_screen_get_time_until_pos(machine->primary_screen, 0, 0), 0);
2296   vblank_out_timer = timer_alloc(machine, vblank_out_irq,NULL);
2297   timer_adjust_oneshot(vblank_out_timer,video_screen_get_time_until_pos(machine->primary_screen, 0, 0), 0);
22942298   timer_adjust_oneshot(scan_timer, video_screen_get_time_until_pos(machine->primary_screen, 224, 352), 0);
22952299}
22962300
r3830r3831
24022406   /* basic machine hardware */
24032407   MDRV_CPU_ADD("main", SH2, MASTER_CLOCK_352/2) // 28.6364 MHz
24042408   MDRV_CPU_PROGRAM_MAP(saturn_mem, 0)
2405   MDRV_CPU_VBLANK_INT_HACK(stv_interrupt, 264)/*264 lines,224 display lines*/
2409   MDRV_CPU_VBLANK_INT("main",stv_interrupt)
24062410   MDRV_CPU_CONFIG(sh2_conf_master)
24072411
24082412   MDRV_CPU_ADD("slave", SH2, MASTER_CLOCK_352/2) // 28.6364 MHz
r3830r3831
24232427
24242428   /* video hardware */
24252429   MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB15)
2426   MDRV_SCREEN_SIZE(1024, 1024)
2427   MDRV_SCREEN_VISIBLE_AREA(0*8, 703, 0*8, 512) // we need to use a resolution as high as the max size it can change to
2430   MDRV_SCREEN_SIZE(704*2, 512*2)
2431   MDRV_SCREEN_VISIBLE_AREA(0*8, 703, 0*8, 511) // we need to use a resolution as high as the max size it can change to
24282432   MDRV_PALETTE_LENGTH(2048+(2048*2))//standard palette + extra memory for rgb brightness.
24292433   MDRV_GFXDECODE(saturn)
24302434

Previous 15994 Revisions Next


© 1998-2018 The MESS Team