Previous 15994 Revisions Next

r3672 Thursday 27th November, 2008 at 18:55:31 UTC by R. Belmont
More sega.a fixups.
[src/mame/video]stvvdp1.c stvvdp2.c
[src/mess/drivers]dc.c saturn.c sg1000.c
[src/mess/includes]sms.h
[src/mess/machine]sms.c
[src/mess/video]smsvdp.c

src/mame/video/stvvdp1.c
r3671r3672
194194
195195//  x ^= 0x00020000;
196196
197   logerror ("cpu #%d (PC=%08X) VDP1: Read from Registers, Offset %04x\n",cpunum_get_active(), cpu_get_pc(space->cpu), offset);
197   logerror ("cpu %s (PC=%08X) VDP1: Read from Registers, Offset %04x\n", space->cpu->tag, cpu_get_pc(space->cpu), offset);
198198//  if (offset == 0x04) return x;
199199
200200   return stv_vdp1_regs[offset];
r3671r3672
350350
351351//  if (((offset * 4) > 0xdf) && ((offset * 4) < 0x140))
352352//  {
353//      logerror("cpu #%d (PC=%08X): VRAM dword write to %08X = %08X & %08X\n", cpunum_get_active(), cpu_get_pc(space->cpu), offset*4, data, mem_mask);
353//      logerror("cpu %s (PC=%08X): VRAM dword write to %08X = %08X & %08X\n", space->cpu->tag, cpu_get_pc(space->cpu), offset*4, data, mem_mask);
354354//  }
355355
356356   data = stv_vdp1_vram[offset];
src/mame/video/stvvdp2.c
r3671r3672
53235323      /*H/V Counter Register*/
53245324                             /*H-Counter                               V-Counter                                         */
53255325         stv_vdp2_regs[offset] = (((video_screen_get_visible_area(space->machine->primary_screen)->max_x - 1)<<16)&0x3ff0000)|(((video_screen_get_visible_area(space->machine->primary_screen)->max_y - 1)<<0)& ((STV_VDP2_LSMD == 3) ? 0x7ff : 0x3ff));
5326         if(LOG_VDP2) logerror("CPU #%d PC(%08x) = VDP2: H/V counter read : %08x\n",cpunum_get_active(),cpu_get_pc(space->cpu),stv_vdp2_regs[offset]);
5326         if(LOG_VDP2) logerror("CPU %s PC(%08x) = VDP2: H/V counter read : %08x\n", space->cpu->tag, cpu_get_pc(space->cpu),stv_vdp2_regs[offset]);
53275327         stv_vdp2_regs[offset] = 0;
53285328      break;
53295329   }
src/mess/video/smsvdp.c
r3671r3672
167167}
168168
169169 READ8_HANDLER(sms_vdp_vcount_r) {
170   return ( smsvdp.sms_frame_timing[ INIT_VCOUNT ] + video_screen_get_vpos(machine->primary_screen) ) & 0xFF;
170   return ( smsvdp.sms_frame_timing[ INIT_VCOUNT ] + video_screen_get_vpos(space->machine->primary_screen) ) & 0xFF;
171171}
172172
173173READ8_HANDLER(sms_vdp_hcount_r) {
174   return video_screen_get_hpos(machine->primary_screen) >> 1;
174   return video_screen_get_hpos(space->machine->primary_screen) >> 1;
175175}
176176
177177void sms_set_ggsmsmode( int mode ) {
r3671r3672
240240
241241   /* Check if we're on the last line of a frame */
242242   if ( vpos == vpos_limit - 1 ) {
243      sms_check_pause_button( machine );
243      sms_check_pause_button( cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM) );
244244      return;
245245   }
246246
r3671r3672
390390   if (smsvdp.irq_state == 1) {
391391      smsvdp.irq_state = 0;
392392      if ( smsvdp.int_callback ) {
393         smsvdp.int_callback( machine, CLEAR_LINE );
393         smsvdp.int_callback( space->machine, CLEAR_LINE );
394394      }
395395   }
396396
r3671r3672
454454            logerror("overscan enabled.\n");
455455         }
456456         if ( regNum == 0 || regNum == 1 ) {
457            set_display_settings( machine );
457            set_display_settings( space->machine );
458458         }
459459         if ( ( regNum == 1 ) && ( smsvdp.reg[0x01] & 0x20 ) && ( smsvdp.status & STATUS_VINT ) ) {
460460            smsvdp.irq_state = 1;
461            smsvdp.int_callback( machine, ASSERT_LINE );
461            smsvdp.int_callback( space->machine, ASSERT_LINE );
462462         }
463463         smsvdp.addrmode = 0;
464464         break;
src/mess/includes/sms.h
r3671r3672
2323#define FLAG_FM            0x00100000
2424#define FLAG_REGION_JAPAN      0x00200000
2525
26#define IS_GAMEGEAR         ( machine->gamedrv->flags & FLAG_GAMEGEAR )
27#define HAS_BIOS_0400         ( machine->gamedrv->flags & FLAG_BIOS_0400 )
28#define HAS_BIOS_2000         ( machine->gamedrv->flags & FLAG_BIOS_2000 )
29#define HAS_BIOS_FULL         ( machine->gamedrv->flags & FLAG_BIOS_FULL )
30#define HAS_BIOS         ( machine->gamedrv->flags & ( FLAG_BIOS_0400 | FLAG_BIOS_2000 | FLAG_BIOS_FULL ) )
31#define HAS_FM            ( machine->gamedrv->flags & FLAG_FM )
32#define IS_REGION_JAPAN         ( machine->gamedrv->flags & FLAG_REGION_JAPAN )
26#define IS_GAMEGEAR         ( space->machine->gamedrv->flags & FLAG_GAMEGEAR )
27#define HAS_BIOS_0400         ( space->machine->gamedrv->flags & FLAG_BIOS_0400 )
28#define HAS_BIOS_2000         ( space->machine->gamedrv->flags & FLAG_BIOS_2000 )
29#define HAS_BIOS_FULL         ( space->machine->gamedrv->flags & FLAG_BIOS_FULL )
30#define HAS_BIOS         ( space->machine->gamedrv->flags & ( FLAG_BIOS_0400 | FLAG_BIOS_2000 | FLAG_BIOS_FULL ) )
31#define HAS_FM            ( space->machine->gamedrv->flags & FLAG_FM )
32#define IS_REGION_JAPAN         ( space->machine->gamedrv->flags & FLAG_REGION_JAPAN )
3333
3434
3535/*----------- defined in machine/sms.c -----------*/
r3671r3672
5454WRITE8_HANDLER(gg_psg_w);
5555 READ8_HANDLER(gg_input_port_2_r);
5656
57void setup_rom(running_machine *machine);
57void setup_rom(const address_space *space);
5858
59void sms_check_pause_button( running_machine *machine );
59void sms_check_pause_button(const address_space *space);
6060
6161DEVICE_START( sms_cart );
6262DEVICE_IMAGE_LOAD( sms_cart );
src/mess/machine/sms.c
r3671r3672
7676static WRITE8_HANDLER( sms_input_write ) {
7777   switch( offset ) {
7878   case 0:
79      switch( input_port_read(machine, "CTRLSEL") & 0x0F ) {
79      switch( input_port_read(space->machine, "CTRLSEL") & 0x0F ) {
8080      case 0x03:   /* Sports Pad */
8181         if ( data != sports_pad_last_data_1 ) {
82            UINT32 cpu_cycles = activecpu_gettotalcycles();
82            UINT32 cpu_cycles = cpu_get_total_cycles(space->cpu);
8383
8484            sports_pad_last_data_1 = data;
8585            if ( cpu_cycles - last_sports_pad_time_1 > 512 ) {
8686               sports_pad_state_1 = 3;
87               sports_pad_1_x = input_port_read(machine, "SPORT0");
88               sports_pad_1_y = input_port_read(machine, "SPORT1");
87               sports_pad_1_x = input_port_read(space->machine, "SPORT0");
88               sports_pad_1_y = input_port_read(space->machine, "SPORT1");
8989            }
9090            last_sports_pad_time_1 = cpu_cycles;
9191            sports_pad_state_1 = ( sports_pad_state_1 + 1 ) & 3;
r3671r3672
9494      }
9595      break;
9696   case 1:
97      switch( input_port_read(machine, "CTRLSEL") >> 4 ) {
97      switch( input_port_read(space->machine, "CTRLSEL") >> 4 ) {
9898      case 0x03:   /* Sports Pad */
9999         if ( data != sports_pad_last_data_2 ) {
100            UINT32 cpu_cycles = activecpu_gettotalcycles();
100            UINT32 cpu_cycles = cpu_get_total_cycles(space->cpu);
101101
102102            sports_pad_last_data_2 = data;
103103            if ( cpu_cycles - last_sports_pad_time_2 > 2048 ) {
104104               sports_pad_state_2 = 3;
105               sports_pad_2_x = input_port_read(machine, "SPORT2");
106               sports_pad_2_y = input_port_read(machine, "SPORT3");
105               sports_pad_2_x = input_port_read(space->machine, "SPORT2");
106               sports_pad_2_y = input_port_read(space->machine, "SPORT3");
107107            }
108108            last_sports_pad_time_2 = cpu_cycles;
109109            sports_pad_state_2 = ( sports_pad_state_2 + 1 ) & 3;
r3671r3672
114114   }
115115}
116116
117static void sms_get_inputs(running_machine *machine) {
117static void sms_get_inputs(const address_space *space) {
118118   UINT8 data = 0x00;
119   UINT32 cpu_cycles = activecpu_gettotalcycles();
119   UINT32 cpu_cycles = cpu_get_total_cycles(space->cpu);
120   running_machine *machine = space->machine;
120121
121122   sms_input_port0 = 0xFF;
122123   sms_input_port1 = 0xFF;
r3671r3672
229230      if ( biosPort & IO_CHIP ) {
230231         return 0xFF;
231232      } else {
232         sms_get_inputs(machine);
233         sms_get_inputs(space);
233234         return sms_input_port0;
234235      }
235236   }
r3671r3672
240241      smsVersion = (data & 0xA0);
241242   }
242243   if ( data & 0x08 ) {
243      sms_input_write( machine, 0, ( data & 0x20 ) >> 5 );
244      sms_input_write( space, 0, ( data & 0x20 ) >> 5 );
244245   }
245246   if ( data & 0x02 ) {
246      sms_input_write( machine, 1, ( data & 0x80 ) >> 7 );
247      sms_input_write( space, 1, ( data & 0x80 ) >> 7 );
247248   }
248249}
249250
r3671r3672
263264   }
264265
265266   /* Merge version data with input port #2 data */
266   sms_get_inputs(machine);
267   sms_get_inputs(space);
267268   temp = (temp & 0xC0) | (sms_input_port1 & 0x3F);
268269
269270   return (temp);
r3671r3672
271272
272273READ8_HANDLER(sms_count_r) {
273274   if ( offset & 0x01 ) {
274      return sms_vdp_hcount_r(machine, offset);
275      return sms_vdp_hcount_r(space, offset);
275276   } else {
276277      /* VCount read */
277      return sms_vdp_vcount_r(machine, offset);
278      return sms_vdp_vcount_r(space, offset);
278279   }
279280}
280281
281void sms_check_pause_button( running_machine *machine ) {
282void sms_check_pause_button(const address_space *space) {
282283   if ( ! IS_GAMEGEAR ) {
283      if ( ! (input_port_read(machine, "PAUSE") & 0x80) ) {
284      if ( ! (input_port_read(space->machine, "PAUSE") & 0x80) ) {
284285         if ( ! smsPaused ) {
285            cpu_set_input_line(machine->cpu[0], INPUT_LINE_NMI, ASSERT_LINE );
286            cpu_set_input_line(machine->cpu[0], INPUT_LINE_NMI, CLEAR_LINE );
286            cpu_set_input_line(space->machine->cpu[0], INPUT_LINE_NMI, ASSERT_LINE );
287            cpu_set_input_line(space->machine->cpu[0], INPUT_LINE_NMI, CLEAR_LINE );
287288         }
288289         smsPaused = 1;
289290      } else {
r3671r3672
296297   if (biosPort & IO_CHIP) {
297298      return (0xFF);
298299   } else {
299      sms_get_inputs(machine);
300      sms_get_inputs(space);
300301      return sms_input_port0;
301302   }
302303}
303304
304305WRITE8_HANDLER(sms_ym2413_register_port_0_w) {
305306   if ( HAS_FM ) {
306      ym2413_register_port_0_w(machine, offset, (data & 0x3F));
307      ym2413_register_port_0_w(space, offset, (data & 0x3F));
307308   }
308309}
309310
310311WRITE8_HANDLER(sms_ym2413_data_port_0_w) {
311312   if ( HAS_FM ) {
312313      logerror("data_port_0_w %x %x\n", offset, data);
313      ym2413_data_port_0_w(machine, offset, data);
314      ym2413_data_port_0_w(space, offset, data);
314315   }
315316}
316317
317318 READ8_HANDLER(gg_input_port_2_r) {
318319   //logerror("joy 2 read, val: %02x, pc: %04x\n", (( IS_REGION_JAPAN ? 0x00 : 0x40) | (input_port_read(machine, "START") & 0x80)), activecpu_get_pc());
319   return (( IS_REGION_JAPAN ? 0x00 : 0x40 ) | (input_port_read(machine, "START") & 0x80));
320   return (( IS_REGION_JAPAN ? 0x00 : 0x40 ) | (input_port_read(space->machine, "START") & 0x80));
320321}
321322
322323 READ8_HANDLER(sms_mapper_r)
r3671r3672
383384               LOG(("ram 0 paged.\n"));
384385               SOURCE = sms_cartridge[sms_current_cartridge].cartSRAM;
385386            }
386            memory_set_bankptr( 4, SOURCE );
387            memory_set_bankptr( 5, SOURCE + 0x2000 );
387            memory_set_bankptr(space->machine,  4, SOURCE );
388            memory_set_bankptr(space->machine,  5, SOURCE + 0x2000 );
388389         } else { /* it's rom */
389390            if ( biosPort & IO_BIOS_ROM || ! HAS_BIOS ) {
390391               page = ( rom_page_count > 0) ? sms_mapper[3] % rom_page_count : 0;
r3671r3672
394395               SOURCE = sms_banking_bios[4];
395396            }
396397            LOG(("rom 2 paged in %x.\n", page));
397            memory_set_bankptr( 4, SOURCE );
398            memory_set_bankptr( 5, SOURCE + 0x2000 );
398            memory_set_bankptr(space->machine,  4, SOURCE );
399            memory_set_bankptr(space->machine,  5, SOURCE + 0x2000 );
399400         }
400401         break;
401402      case 1: /* Select 16k ROM bank for 0400-3FFF */
r3671r3672
405406         if ( IS_GAMEGEAR ) {
406407            SOURCE = SOURCE_CART;
407408         }
408         memory_set_bankptr( 2, SOURCE + 0x0400 );
409         memory_set_bankptr(space->machine, 2, SOURCE + 0x0400 );
409410         break;
410411      case 2: /* Select 16k ROM bank for 4000-7FFF */
411412         LOG(("rom 1 paged in %x.\n", page));
r3671r3672
414415         if ( IS_GAMEGEAR ) {
415416            SOURCE = SOURCE_CART;
416417         }
417         memory_set_bankptr( 3, SOURCE );
418         memory_set_bankptr(space->machine, 3, SOURCE );
418419         break;
419420      case 3: /* Select 16k ROM bank for 8000-BFFF */
420421         sms_banking_bios[4] = SOURCE_BIOS;
r3671r3672
430431         }
431432         if ( ! ( sms_mapper[0] & 0x08 ) ) { /* is RAM disabled? */
432433            LOG(("rom 2 paged in %x.\n", page));
433            memory_set_bankptr( 4, SOURCE );
434            memory_set_bankptr( 5, SOURCE + 0x2000 );
434            memory_set_bankptr(space->machine,  4, SOURCE );
435            memory_set_bankptr(space->machine,  5, SOURCE + 0x2000 );
435436         }
436437         break;
437438   }
r3671r3672
442443      UINT8 rom_page_count = sms_cartridge[sms_current_cartridge].size / 0x4000;
443444      sms_banking_cart[1] = sms_cartridge[sms_current_cartridge].ROM + ( ( rom_page_count > 0) ? data % rom_page_count : 0 ) * 0x4000;
444445      sms_banking_cart[2] = sms_banking_cart[1] + 0x0400;
445      memory_set_bankptr( 1, sms_banking_cart[1] );
446      memory_set_bankptr( 2, sms_banking_cart[2] );
446      memory_set_bankptr(space->machine, 1, sms_banking_cart[1] );
447      memory_set_bankptr(space->machine,  2, sms_banking_cart[2] );
447448   }
448449}
449450
r3671r3672
452453      /* Check if we need to switch in some RAM */
453454      if ( data & 0x80 ) {
454455         sms_cartridge[sms_current_cartridge].ram_page = data & 0x07;
455         memory_set_bankptr( 5, sms_cartridge[sms_current_cartridge].cartRAM + sms_cartridge[sms_current_cartridge].ram_page * 0x2000 );
456         memory_set_bankptr(space->machine, 5, sms_cartridge[sms_current_cartridge].cartRAM + sms_cartridge[sms_current_cartridge].ram_page * 0x2000 );
456457      } else {
457458         UINT8 rom_page_count = sms_cartridge[sms_current_cartridge].size / 0x4000;
458459         sms_banking_cart[3] = sms_cartridge[sms_current_cartridge].ROM + ( ( rom_page_count > 0) ? data % rom_page_count : 0 ) * 0x4000;
459         memory_set_bankptr( 3, sms_banking_cart[3] );
460         memory_set_bankptr( 5, sms_banking_cart[4] + 0x2000 );
460         memory_set_bankptr(space->machine,  3, sms_banking_cart[3] );
461         memory_set_bankptr(space->machine,  5, sms_banking_cart[4] + 0x2000 );
461462      }
462463   }
463464}
r3671r3672
465466WRITE8_HANDLER(sms_bios_w) {
466467   biosPort = data;
467468
468   logerror("bios write %02x, pc: %04x\n", data, activecpu_get_pc());
469   logerror("bios write %02x, pc: %04x\n", data, cpu_get_pc(space->cpu));
469470
470   setup_rom(machine);
471   setup_rom(space);
471472}
472473
473474WRITE8_HANDLER(sms_cartram2_w) {
r3671r3672
488489      if ( ! sms_cartridge[sms_current_cartridge].ROM )
489490         return;
490491      sms_banking_cart[4] = sms_cartridge[sms_current_cartridge].ROM + page * 0x4000;
491      memory_set_bankptr( 4, sms_banking_cart[4] );
492      memory_set_bankptr( 5, sms_banking_cart[4] + 0x2000 );
492      memory_set_bankptr(space->machine,  4, sms_banking_cart[4] );
493      memory_set_bankptr(space->machine,  5, sms_banking_cart[4] + 0x2000 );
493494      LOG(("rom 2 paged in %x dodgeball king.\n", page));
494495   }
495496}
r3671r3672
511512         if ( ! sms_cartridge[sms_current_cartridge].ROM )
512513            return;
513514         sms_banking_cart[4] = sms_cartridge[sms_current_cartridge].ROM + page * 0x4000;
514         memory_set_bankptr( 4, sms_banking_cart[4] );
515         memory_set_bankptr( 5, sms_banking_cart[4] + 0x2000 );
515         memory_set_bankptr(space->machine,  4, sms_banking_cart[4] );
516         memory_set_bankptr(space->machine,  5, sms_banking_cart[4] + 0x2000 );
516517         LOG(("rom 2 paged in %x codemasters.\n", page));
517518      } else if ( sms_cartridge[sms_current_cartridge].features & CF_ONCART_RAM ) {
518519         sms_cartridge[sms_current_cartridge].cartRAM[offset & ( sms_cartridge[sms_current_cartridge].ram_size - 1 ) ] = data;
r3671r3672
584585   }
585586}
586587
587void setup_rom(running_machine *machine)
588void setup_rom(const address_space *space)
588589{
590   running_machine *machine = space->machine;
591
589592   /* 1. set up bank pointers to point to nothing */
590   memory_set_bankptr( 1, sms_banking_none[1] );
591   memory_set_bankptr( 2, sms_banking_none[2] );
592   memory_set_bankptr( 3, sms_banking_none[3] );
593   memory_set_bankptr( 4, sms_banking_none[4] );
594   memory_set_bankptr( 5, sms_banking_none[4] + 0x2000 );
593   memory_set_bankptr(machine,  1, sms_banking_none[1] );
594   memory_set_bankptr(machine,  2, sms_banking_none[2] );
595   memory_set_bankptr(machine,  3, sms_banking_none[3] );
596   memory_set_bankptr(machine,  4, sms_banking_none[4] );
597   memory_set_bankptr(machine,  5, sms_banking_none[4] + 0x2000 );
595598
596599   /* 2. check and set up expansion port */
597600   if (!(biosPort & IO_EXPANSION) && (biosPort & IO_CARTRIDGE) && (biosPort & IO_CARD)) {
r3671r3672
609612   /* if ( ( !(biosPort & IO_CARTRIDGE) && (biosPort & IO_EXPANSION) && (biosPort & IO_CARD) ) || IS_GAMEGEAR ) { */
610613   /* Out Run Europa initially writes a value to port 3E where IO_CARTRIDGE, IO_EXPANSION and IO_CARD are reset */
611614   if ( ( ! ( biosPort & IO_CARTRIDGE ) ) || IS_GAMEGEAR ) {
612      memory_set_bankptr( 1, sms_banking_cart[1] );
613      memory_set_bankptr( 2, sms_banking_cart[2] );
614      memory_set_bankptr( 3, sms_banking_cart[3] );
615      memory_set_bankptr( 4, sms_banking_cart[4] );
616      memory_set_bankptr( 5, sms_banking_cart[4] + 0x2000 );
615      memory_set_bankptr(machine,  1, sms_banking_cart[1] );
616      memory_set_bankptr(machine,  2, sms_banking_cart[2] );
617      memory_set_bankptr(machine,  3, sms_banking_cart[3] );
618      memory_set_bankptr(machine,  4, sms_banking_cart[4] );
619      memory_set_bankptr(machine,  5, sms_banking_cart[4] + 0x2000 );
617620      logerror( "Switched in cartridge rom.\n" );
618621   }
619622
r3671r3672
621624   if ( !(biosPort & IO_BIOS_ROM) ) {
622625      /* 0x0400 bioses */
623626      if ( HAS_BIOS_0400 ) {
624         memory_set_bankptr( 1, sms_banking_bios[1] );
627         memory_set_bankptr(machine, 1, sms_banking_bios[1] );
625628         logerror( "Switched in 0x0400 bios.\n" );
626629      }
627630      /* 0x2000 bioses */
628631      if ( HAS_BIOS_2000 ) {
629         memory_set_bankptr( 1, sms_banking_bios[1] );
630         memory_set_bankptr( 2, sms_banking_bios[2] );
632         memory_set_bankptr(machine,  1, sms_banking_bios[1] );
633         memory_set_bankptr(machine,  2, sms_banking_bios[2] );
631634         logerror( "Switched in 0x2000 bios.\n" );
632635      }
633636      if ( HAS_BIOS_FULL ) {
634         memory_set_bankptr( 1, sms_banking_bios[1] );
635         memory_set_bankptr( 2, sms_banking_bios[2] );
636         memory_set_bankptr( 3, sms_banking_bios[3] );
637         memory_set_bankptr( 4, sms_banking_bios[4] );
638         memory_set_bankptr( 5, sms_banking_bios[4] + 0x2000 );
637         memory_set_bankptr(machine,  1, sms_banking_bios[1] );
638         memory_set_bankptr(machine,  2, sms_banking_bios[2] );
639         memory_set_bankptr(machine,  3, sms_banking_bios[3] );
640         memory_set_bankptr(machine,  4, sms_banking_bios[4] );
641         memory_set_bankptr(machine,  5, sms_banking_bios[4] + 0x2000 );
639642         logerror( "Switched in full bios.\n" );
640643      }
641644   }
642645
643646   if ( sms_cartridge[sms_current_cartridge].features & CF_ONCART_RAM ) {
644      memory_set_bankptr( 4, sms_cartridge[sms_current_cartridge].cartRAM );
645      memory_set_bankptr( 5, sms_cartridge[sms_current_cartridge].cartRAM );
647      memory_set_bankptr(machine,  4, sms_cartridge[sms_current_cartridge].cartRAM );
648      memory_set_bankptr(machine,  5, sms_cartridge[sms_current_cartridge].cartRAM );
646649   }
647650}
648651
r3671r3672
737740
738741DEVICE_START( sms_cart ) {
739742   running_machine *machine = device->machine;
743   const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM);
740744   int i;
741745
742746   for ( i = 0; i < MAX_CARTRIDGES; i++ ) {
r3671r3672
770774   const char *fname = image_filename( image );
771775   int fname_len = fname ? strlen( fname ) : 0;
772776   const char *extrainfo = image_extrainfo( image );
777   const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM);
773778
774779   /* Check for 512-byte header */
775780   if ((size / 512) & 1)
r3671r3672
915920
916921MACHINE_RESET(sms)
917922{
923   const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM);
924
918925   smsVersion = 0x00;
919926   if ( HAS_FM ) {
920927      smsFMDetect = 0x01;
921928   }
922929
923   sms_mapper_ram = memory_get_write_ptr( 0, ADDRESS_SPACE_PROGRAM, 0xDFFC );
930   sms_mapper_ram = memory_get_write_ptr( space, 0xDFFC );
924931
925932   if ( sms_cartridge[sms_current_cartridge].features & CF_CODEMASTERS_MAPPER ) {
926933      /* Install special memory handlers */
927      memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x0000, 0x0000, 0, 0, sms_codemasters_page0_w );
928      memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x4000, 0x4000, 0, 0, sms_codemasters_page1_w );
934      memory_install_write8_handler(space, 0x0000, 0x0000, 0, 0, sms_codemasters_page0_w );
935      memory_install_write8_handler(space, 0x4000, 0x4000, 0, 0, sms_codemasters_page1_w );
929936   }
930937
931938   /* Initialize SIO stuff for GG */
r3671r3672
939946
940947   setup_banks(machine);
941948
942   setup_rom(machine);
949   setup_rom(space);
943950
944951   rapid_fire_state_1 = 0;
945952   rapid_fire_state_2 = 0;
r3671r3672
975982      sms_current_cartridge = slot;
976983   }
977984   setup_cart_banks();
978   memory_set_bankptr( 10, sms_banking_cart[3] + 0x2000 );
979   setup_rom(machine);
985   memory_set_bankptr(space->machine,  10, sms_banking_cart[3] + 0x2000 );
986   setup_rom(space);
980987}
981988
982989READ8_HANDLER(sms_store_select1) {
r3671r3672
992999}
9931000
9941001WRITE8_HANDLER(sms_store_control_w) {
995   logerror( "0x%04X: sms_store_control write 0x%02X\n", activecpu_get_pc(), data );
1002   logerror( "0x%04X: sms_store_control write 0x%02X\n", cpu_get_pc(space->cpu), data );
9961003   if ( data & 0x02 ) {
997      cpunum_resume( 0, SUSPEND_REASON_HALT );
1004      cpu_resume( space->machine->cpu[0], SUSPEND_REASON_HALT );
9981005   } else {
9991006      /* Pull reset line of CPU #0 low */
1000      cpunum_suspend( 0, SUSPEND_REASON_HALT, 1 );
1001      cpu_reset(machine->cpu[0]);
1007      cpu_suspend( space->machine->cpu[0], SUSPEND_REASON_HALT, 1 );
1008      cpu_reset(space->machine->cpu[0]);
10021009   }
10031010   sms_store_control = data;
10041011}
r3671r3672
10081015}
10091016
10101017void sms_store_int_callback( running_machine *machine, int state ) {
1011   cpunum_set_input_line(machine, sms_store_control & 0x01 ? 1 : 0, 0, state );
1018   cpu_set_input_line(machine->cpu[0], sms_store_control & 0x01 ? 1 : 0, state );
10121019}
10131020
src/mess/drivers/dc.c
r3671r3672
130130
131131static INTERRUPT_GEN( dc_dispatch_vblank )
132132{
133   dc_vblank(machine);
133   dc_vblank(device->machine);
134134}
135135
136136static const struct sh4_config sh4cpu_config = {  1,  0,  1,  0,  0,  0,  1,  1,  0, CPU_CLOCK };
src/mess/drivers/sg1000.c
r3671r3672
104104{
105105   if (data & 0x01)
106106   {
107      tvdraw_data = input_port_read(machine, "TVDRAW_X");
107      tvdraw_data = input_port_read(space->machine, "TVDRAW_X");
108108
109109      if (tvdraw_data < 4) tvdraw_data = 4;
110110      if (tvdraw_data > 251) tvdraw_data = 251;
111111   }
112112   else
113113   {
114      tvdraw_data = input_port_read(machine, "TVDRAW_Y") + 32;
114      tvdraw_data = input_port_read(space->machine, "TVDRAW_Y") + 32;
115115   }
116116}
117117
118118static READ8_HANDLER( tvdraw_status_r )
119119{
120   return input_port_read(machine, "TVDRAW_PEN");
120   return input_port_read(space->machine, "TVDRAW_PEN");
121121}
122122
123123static READ8_HANDLER( tvdraw_data_r )
r3671r3672
433433
434434static INTERRUPT_GEN( sg1000_int )
435435{
436    TMS9928A_interrupt(machine);
436    TMS9928A_interrupt(device->machine);
437437}
438438
439439static void sg1000_vdp_interrupt(running_machine *machine, int state)
r3671r3672
658658   }
659659
660660   /* ROM selection */
661   memory_set_bank(machine, 1, (data & 0x40) >> 6);
661   memory_set_bank(device->machine, 1, (data & 0x40) >> 6);
662662
663663   /* printer strobe */
664664   centronics_write_handshake(1, (data & 0x80) ? 0 : CENTRONICS_STROBE, CENTRONICS_STROBE);
r3671r3672
881881
882882static void sg1000_map_cartridge_memory(running_machine *machine, UINT8 *ptr, int size)
883883{
884   const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM);
885
884886   switch (size)
885887   {
886888   case 40 * 1024:
887      memory_install_readwrite8_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x8000, 0x9fff, 0, 0, SMH_BANK1, SMH_UNMAP);
889      memory_install_readwrite8_handler(space, 0x8000, 0x9fff, 0, 0, SMH_BANK1, SMH_UNMAP);
888890      memory_configure_bank(machine, 1, 0, 1, memory_region(machine, "main") + 0x8000, 0);
889891      memory_set_bank(machine, 1, 0);
890892      break;
891893
892894   case 48 * 1024:
893      memory_install_readwrite8_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x8000, 0xbfff, 0, 0, SMH_BANK1, SMH_UNMAP);
895      memory_install_readwrite8_handler(space, 0x8000, 0xbfff, 0, 0, SMH_BANK1, SMH_UNMAP);
894896      memory_configure_bank(machine, 1, 0, 1, memory_region(machine, "main") + 0x8000, 0);
895897      memory_set_bank(machine, 1, 0);
896898      break;
r3671r3672
899901      if (!strncmp("annakmn", (const char *)&ptr[0x13b3], 7))
900902      {
901903         /* Terebi Oekaki */
902         memory_install_write8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x6000, 0x6000, 0, 0, &tvdraw_axis_w);
903         memory_install_read8_handler(machine, 0, ADDRESS_SPACE_PROGRAM, 0x8000, 0x8000, 0, 0, &tvdraw_status_r);
904         memory_install_readwrite8_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa000, 0xa000, 0, 0, &tvdraw_data_r, SMH_NOP);
904         memory_install_write8_handler(space, 0x6000, 0x6000, 0, 0, &tvdraw_axis_w);
905         memory_install_read8_handler(space, 0x8000, 0x8000, 0, 0, &tvdraw_status_r);
906         memory_install_readwrite8_handler(space, 0xa000, 0xa000, 0, 0, &tvdraw_data_r, SMH_NOP);
905907      }
906908      else if (!strncmp("ASCII 1986", (const char *)&ptr[0x1cc3], 10))
907909      {
908910         /* The Castle */
909         memory_install_readwrite8_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x8000, 0x9fff, 0, 0, SMH_BANK1, SMH_BANK1);
911         memory_install_readwrite8_handler(space, 0x8000, 0x9fff, 0, 0, SMH_BANK1, SMH_BANK1);
910912      }
911913      break;
912914   }
r3671r3672
926928   sg1000_map_cartridge_memory(image->machine, ptr, size);
927929
928930   /* work RAM banking */
929   memory_install_readwrite8_handler(image->machine, 0, ADDRESS_SPACE_PROGRAM, 0xc000, 0xc3ff, 0, 0x3c00, SMH_BANK2, SMH_BANK2);
931   memory_install_readwrite8_handler(cpu_get_address_space(image->machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xc000, 0xc3ff, 0, 0x3c00, SMH_BANK2, SMH_BANK2);
930932
931933   return INIT_PASS;
932934}
src/mess/drivers/saturn.c
r3671r3672
203203
204204static int saturn_region;
205205
206int stv_vblank,stv_hblank;
206extern int stv_vblank,stv_hblank;
207207int stv_enable_slave_sh2;
208208/*SMPC stuff*/
209209static UINT8 NMI_reset;
r3671r3672
229229           scu_size_1,      /* lv 1*/
230230           scu_size_2;      /* lv 2*/
231231
232static void dma_direct_lv0(running_machine *machine);   /*DMA level 0 direct transfer function*/
233static void dma_direct_lv1(running_machine *machine);   /*DMA level 1 direct transfer function*/
234static void dma_direct_lv2(running_machine *machine);   /*DMA level 2 direct transfer function*/
235static void dma_indirect_lv0(running_machine *machine); /*DMA level 0 indirect transfer function*/
236static void dma_indirect_lv1(running_machine *machine); /*DMA level 1 indirect transfer function*/
237static void dma_indirect_lv2(running_machine *machine); /*DMA level 2 indirect transfer function*/
232struct
233{
234   UINT8 vblank_out;
235   UINT8 vblank_in;
236   UINT8 hblank_in;
237   UINT8 timer_0;
238   UINT8 timer_1;
239   UINT8 dsp_end;
240   UINT8 sound_req;
241   UINT8 smpc;
242   UINT8 pad;
243   UINT8 dma_end[3];
244   UINT8 dma_ill;
245   UINT8 vdp1_end;
246   UINT8 abus;
247}stv_irq;
238248
249static void dma_direct_lv0(const address_space *space);   /*DMA level 0 direct transfer function*/
250static void dma_direct_lv1(const address_space *space);   /*DMA level 1 direct transfer function*/
251static void dma_direct_lv2(const address_space *space);   /*DMA level 2 direct transfer function*/
252static void dma_indirect_lv0(const address_space *space); /*DMA level 0 indirect transfer function*/
253static void dma_indirect_lv1(const address_space *space); /*DMA level 1 indirect transfer function*/
254static void dma_indirect_lv2(const address_space *space); /*DMA level 2 indirect transfer function*/
239255
256
240257int minit_boost,sinit_boost;
241258attotime minit_boost_timeslice, sinit_boost_timeslice;
242259
r3671r3672
490507   intback_stage++;
491508}
492509
493static UINT8 stv_SMPC_r8 (int offset)
510static UINT8 stv_SMPC_r8(const address_space *space, int offset)
494511{
495512   int return_data;
496513
r3671r3672
541558
542559   if (offset == 0x33) return_data = saturn_region;
543560
544   if (LOG_SMPC) logerror ("cpu #%d (PC=%08X) SMPC: Read from Byte Offset %02x (%d) Returns %02x\n", cpu_getactivecpu(), cpu_get_pc(space->cpu), offset, offset>>1, return_data);
561   if (LOG_SMPC) logerror ("cpu %s (PC=%08X) SMPC: Read from Byte Offset %02x (%d) Returns %02x\n", space->cpu->tag, cpu_get_pc(space->cpu), offset, offset>>1, return_data);
545562
546563
547564   return return_data;
548565}
549566
550static void stv_SMPC_w8 (running_machine *machine, int offset, UINT8 data)
567static void stv_SMPC_w8(const address_space *space, int offset, UINT8 data)
551568{
552569   mame_system_time systime;
553570   UINT8 last;
571   running_machine *machine = space->machine;
554572
555573   /* get the current date/time from the core */
556574   mame_get_current_datetime(machine, &systime);
r3671r3672
635653            if(LOG_SMPC) logerror ("SMPC: Slave OFF\n");
636654            smpc_ram[0x5f]=0x03;
637655            stv_enable_slave_sh2 = 0;
638            cpu_trigger(machine, 1000);
656            cpuexec_trigger(machine, 1000);
639657            cpu_set_input_line(machine->cpu[1], INPUT_LINE_RESET, ASSERT_LINE);
640658            break;
641659         case 0x06:
642660            if(LOG_SMPC) logerror ("SMPC: Sound ON\n");
643661            /* wrong? */
644662            smpc_ram[0x5f]=0x06;
645            cpunum_set_input_line(machine, 2, INPUT_LINE_RESET, CLEAR_LINE);
663            cpu_set_input_line(machine->cpu[2], INPUT_LINE_RESET, CLEAR_LINE);
646664            en_68k = 1;
647665            break;
648666         case 0x07:
649667            if(LOG_SMPC) logerror ("SMPC: Sound OFF\n");
650            cpunum_set_input_line(machine, 2, INPUT_LINE_RESET, ASSERT_LINE);
668            cpu_set_input_line(machine->cpu[2], INPUT_LINE_RESET, ASSERT_LINE);
651669            en_68k = 0;
652670            smpc_ram[0x5f]=0x07;
653671            break;
r3671r3672
663681         case 0x0e:
664682            if(LOG_SMPC) logerror ("SMPC: Change Clock to 352\n");
665683            smpc_ram[0x5f]=0x0e;
666            cpunum_set_clock(machine, 0, MASTER_CLOCK_352/2);
667            cpunum_set_clock(machine, 1, MASTER_CLOCK_352/2);
668            cpunum_set_clock(machine, 2, MASTER_CLOCK_352/5);
684            cpu_set_clock(machine->cpu[0], MASTER_CLOCK_352/2);
685            cpu_set_clock(machine->cpu[1], MASTER_CLOCK_352/2);
686            cpu_set_clock(machine->cpu[2], MASTER_CLOCK_352/5);
669687            cpu_set_input_line(machine->cpu[0], INPUT_LINE_NMI, PULSE_LINE); // ff said this causes nmi, should we set a timer then nmi?
670688            break;
671689         case 0x0f:
672690            if(LOG_SMPC) logerror ("SMPC: Change Clock to 320\n");
673691            smpc_ram[0x5f]=0x0f;
674            cpunum_set_clock(machine, 0, MASTER_CLOCK_320/2);
675            cpunum_set_clock(machine, 1, MASTER_CLOCK_320/2);
676            cpunum_set_clock(machine, 2, MASTER_CLOCK_320/5);
692            cpu_set_clock(machine->cpu[0], MASTER_CLOCK_320/2);
693            cpu_set_clock(machine->cpu[1], MASTER_CLOCK_320/2);
694            cpu_set_clock(machine->cpu[2], MASTER_CLOCK_320/5);
677695            cpu_set_input_line(machine->cpu[0], INPUT_LINE_NMI, PULSE_LINE); // ff said this causes nmi, should we set a timer then nmi?
678696            break;
679697         /*"Interrupt Back"*/
r3671r3672
771789
772790            break;
773791         default:
774            if(LOG_SMPC) logerror ("cpu #%d (PC=%08X) SMPC: undocumented Command %02x\n", cpu_getactivecpu(), cpu_get_pc(space->cpu), data);
792            if(LOG_SMPC) logerror ("cpu %s (PC=%08X) SMPC: undocumented Command %02x\n", space->cpu->tag, cpu_get_pc(space->cpu), data);
775793      }
776794
777795      // we've processed the command, clear status flag
r3671r3672
788806   /* registers are all byte accesses, convert here */
789807   offset = offset << 2; // multiply offset by 4
790808
791   if (!(~mem_mask & 0xff000000))   { byte = 0; readdata = stv_SMPC_r8(offset+byte) << 24; }
792   if (!(~mem_mask & 0x00ff0000))   { byte = 1; readdata = stv_SMPC_r8(offset+byte) << 16; }
793   if (!(~mem_mask & 0x0000ff00))   { byte = 2; readdata = stv_SMPC_r8(offset+byte) << 8;  }
794   if (!(~mem_mask & 0x000000ff))   { byte = 3; readdata = stv_SMPC_r8(offset+byte) << 0;  }
809   if (!(~mem_mask & 0xff000000))   { byte = 0; readdata = stv_SMPC_r8(space, offset+byte) << 24; }
810   if (!(~mem_mask & 0x00ff0000))   { byte = 1; readdata = stv_SMPC_r8(space, offset+byte) << 16; }
811   if (!(~mem_mask & 0x0000ff00))   { byte = 2; readdata = stv_SMPC_r8(space, offset+byte) << 8;  }
812   if (!(~mem_mask & 0x000000ff))   { byte = 3; readdata = stv_SMPC_r8(space, offset+byte) << 0;  }
795813
796814   return readdata;
797815}
r3671r3672
813831
814832   offset += byte;
815833
816   stv_SMPC_w8(machine, offset,writedata);
834   stv_SMPC_w8(space, offset,writedata);
817835}
818836
819837
r3671r3672
838856
839857/* to do, update bios idle skips so they work better with this arrangement.. */
840858
859static emu_timer *vblank_in_timer,*scan_timer,*t1_timer;
860static int h_sync,v_sync;
861static int cur_scan;
841862
842static INTERRUPT_GEN( stv_interrupt )
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 )
843914{
844   scanline = 261-cpu_getiloops();
915   int scanline = param;
845916
846   stv_hblank = 0;
917//  h = video_screen_get_height(machine->primary_screen);
918//  w = video_screen_get_width(machine->primary_screen);
847919
848   if(scanline == 0)
920   TIMER_0_IRQ;
921   HBLANK_IN_IRQ;
922
923   if((scanline+1) < v_sync)
849924   {
850      if(!(stv_scu[40] & 2))/*VBLANK-OUT*/
851      {
852         if(LOG_IRQ) logerror ("Interrupt: VBlank-OUT at scanline %04x, Vector 0x41 Level 0x0e\n",scanline);
853         cpu_set_input_line_and_vector(machine->cpu[0], 0xe, HOLD_LINE , 0x41);
854      }
855      stv_vblank = 0;
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);
856929   }
857   else if(scanline <= 223 && scanline >= 1)/*Correct?*/
858   {
859      timer_0++;
860      timer_1++;
861      stv_hblank = 1;
862      /*TODO: check this...*/
863      /*Timer 1 handling*/
864      if((stv_scu[38] & 1))
865      {
866         if((!(stv_scu[40] & 0x10)) && (!(stv_scu[38] & 0x80)))
867         {
868            if(LOG_IRQ) logerror ("Interrupt: Timer 1 at scanline %04x, Vector 0x44 Level 0x0b\n",scanline);
869            cpu_set_input_line_and_vector(machine->cpu[0], 0xb, HOLD_LINE, 0x44 );
870         }
871         else if((!(stv_scu[40] & 0x10)) && (stv_scu[38] & 0x80))
872         {
873            if(timer_1 == (stv_scu[36] & 0x1ff))
874            {
875               if(LOG_IRQ) logerror ("Interrupt: Timer 1 at scanline %04x, Vector 0x44 Level 0x0b\n",scanline);
876               cpu_set_input_line_and_vector(machine->cpu[0], 0xb, HOLD_LINE, 0x44 );
877            }
878         }
879      }
880      if(timer_0 == (stv_scu[36] & 0x1ff))
881      {
882         if(!(stv_scu[40] & 8))/*Timer 0*/
883         {
884            if(LOG_IRQ) logerror ("Interrupt: Timer 0 at scanline %04x, Vector 0x43 Level 0x0c\n",scanline);
885            cpu_set_input_line_and_vector(machine->cpu[0], 0xc, HOLD_LINE, 0x43 );
886         }
887      }
888930
889      /*TODO:use this *at the end* of the draw line.*/
890      if(!(stv_scu[40] & 4))/*HBLANK-IN*/
891      {
892         if(LOG_IRQ) logerror ("Interrupt: HBlank-In at scanline %04x, Vector 0x42 Level 0x0d\n",scanline);
893         cpu_set_input_line_and_vector(machine->cpu[0], 0xd, HOLD_LINE , 0x42);
894      }
895   }
896   else if(scanline == 224)
897   {
898      timer_0 = 0;
899      timer_1 = 0;
931   timer_0++;
932}
900933
901      if(!(stv_scu[40] & 1))/*VBLANK-IN*/
902      {
903         if(LOG_IRQ) logerror ("Interrupt: VBlank IN at scanline %04x, Vector 0x40 Level 0x0f\n",scanline);
904         cpu_set_input_line_and_vector(machine->cpu[0], 0xf, HOLD_LINE , 0x40);
905      }
906      stv_vblank = 1;
934static TIMER_CALLBACK( timer1_irq )
935{
936   int cur_point = param;
907937
908      if(timer_0 == (stv_scu[36] & 0x1ff))
909      {
910         if(!(stv_scu[40] & 8))/*Timer 0*/
911         {
912            if(LOG_IRQ) logerror ("Interrupt: Timer 0 at scanline %04x, Vector 0x43 Level 0x0c\n",scanline);
913            cpu_set_input_line_and_vector(machine->cpu[0], 0xc, HOLD_LINE, 0x43 );
914         }
915      }
916      if(!(stv_scu[40] & 0x2000)) /*Sprite draw end irq*/
917         cpu_set_input_line_and_vector(machine->cpu[0], 2, HOLD_LINE , 0x4d);
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);
918943   }
944
945   if(timer_1 > 0) timer_1--;
919946}
920947
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(video_screen_get_time_until_pos(device->machine->primary_screen,0,0), NULL, 0, vdp1_irq);
975}
976
921977static UINT8 port_sel,mux_data;
922978
923979#define HI_WORD_ACCESS (~mem_mask & 0x00ff0000) == 0
r3671r3672
10521108   //{
10531109      //Super Major League reads here???
10541110   //}
1055
1056   // Saturn BIOS needs this (need to investigate further)
1057   if (offset == 32)
1058   {
1059      return 0x00100000;
1060   }
1061
10621111   if (offset == 31)
10631112   {
10641113      if(LOG_SCU) logerror("(PC=%08x) DMA status reg read\n",cpu_get_pc(space->cpu));
1065         return stv_scu[offset];
1114      return stv_scu[offset];
10661115   }
10671116   else if ( offset == 35 )
10681117   {
10691118        if(LOG_SCU) logerror( "DSP mem read at %08X\n", stv_scu[34]);
10701119        return dsp_ram_addr_r();
10711120    }
1072    else if( offset == 41)
1121    else if( offset == 41) /*IRQ reg status read*/
10731122    {
1074      logerror("(PC=%08x) IRQ status reg read\n",cpu_get_pc(space->cpu));
1075      /*TODO:for now we're activating everything here,but we need to return the proper active irqs*/
1076      return 0xffffffff;
1123      if(LOG_SCU) logerror("(PC=%08x) IRQ status reg read %08x\n",cpu_get_pc(space->cpu),mem_mask);
1124
1125      stv_scu[41] = (stv_irq.vblank_in & 1)<<0;
1126      stv_scu[41]|= (stv_irq.vblank_out & 1)<<1;
1127      stv_scu[41]|= (stv_irq.hblank_in & 1)<<2;
1128      stv_scu[41]|= (stv_irq.timer_0 & 1)<<3;
1129      stv_scu[41]|= (stv_irq.timer_1 & 1)<<4;
1130      stv_scu[41]|= (stv_irq.dsp_end & 1)<<5;
1131      stv_scu[41]|= (stv_irq.sound_req & 1)<<6;
1132      stv_scu[41]|= (stv_irq.smpc & 1)<<7;
1133      stv_scu[41]|= (stv_irq.pad & 1)<<8;
1134      stv_scu[41]|= (stv_irq.dma_end[0] & 1)<<9;
1135      stv_scu[41]|= (stv_irq.dma_end[1] & 1)<<10;
1136      stv_scu[41]|= (stv_irq.dma_end[2] & 1)<<11;
1137      stv_scu[41]|= (stv_irq.dma_ill & 1)<<12;
1138      stv_scu[41]|= (stv_irq.vdp1_end & 1)<<13;
1139      stv_scu[41]|= (stv_irq.abus & 1)<<15;
1140
1141      return stv_scu[41] ^ 0xffffffff;
10771142   }
10781143   else if( offset == 50 )
10791144   {
r3671r3672
11291194*/
11301195      if(stv_scu[4] & 1 && ((stv_scu[5] & 7) == 7) && stv_scu[4] & 0x100)
11311196      {
1132         if(DIRECT_MODE(0)) { dma_direct_lv0(machine); }
1133         else            { dma_indirect_lv0(machine); }
1197         if(DIRECT_MODE(0)) { dma_direct_lv0(space); }
1198         else            { dma_indirect_lv0(space); }
11341199
11351200         stv_scu[4]^=1;//disable starting bit.
11361201
11371202         /*Sound IRQ*/
11381203         if(/*(!(stv_scu[40] & 0x40)) &&*/ scsp_to_main_irq == 1)
11391204         {
1140            //cpu_set_input_line_and_vector(machine->cpu[0], 9, HOLD_LINE , 0x46);
1205            //cpu_set_input_line_and_vector(space->machine->cpu[0], 9, HOLD_LINE , 0x46);
11411206            logerror("SCSP: Main CPU interrupt\n");
11421207            #if 0
11431208            if((scu_dst_0 & 0x7ffffff) != 0x05a00000)
11441209            {
11451210               if(!(stv_scu[40] & 0x1000))
11461211               {
1147                  cpu_set_input_line_and_vector(machine->cpu[0], 3, HOLD_LINE, 0x4c);
1212                  cpu_set_input_line_and_vector(space->machine->cpu[0], 3, HOLD_LINE, 0x4c);
11481213                  logerror("SCU: Illegal DMA interrupt\n");
11491214               }
11501215            }
r3671r3672
11901255      case 12:
11911256      if(stv_scu[12] & 1 && ((stv_scu[13] & 7) == 7) && stv_scu[12] & 0x100)
11921257      {
1193         if(DIRECT_MODE(1)) { dma_direct_lv1(machine); }
1194         else            { dma_indirect_lv1(machine); }
1258         if(DIRECT_MODE(1)) { dma_direct_lv1(space); }
1259         else            { dma_indirect_lv1(space); }
11951260
11961261         stv_scu[12]^=1;
11971262
11981263         /*Sound IRQ*/
11991264         if(/*(!(stv_scu[40] & 0x40)) &&*/ scsp_to_main_irq == 1)
12001265         {
1201            //cpu_set_input_line_and_vector(machine->cpu[0], 9, HOLD_LINE , 0x46);
1266            //cpu_set_input_line_and_vector(space->machine->cpu[0], 9, HOLD_LINE , 0x46);
12021267            logerror("SCSP: Main CPU interrupt\n");
12031268         }
12041269      }
r3671r3672
12401305      case 20:
12411306      if(stv_scu[20] & 1 && ((stv_scu[21] & 7) == 7) && stv_scu[20] & 0x100)
12421307      {
1243         if(DIRECT_MODE(2)) { dma_direct_lv2(machine); }
1244         else            { dma_indirect_lv2(machine); }
1308         if(DIRECT_MODE(2)) { dma_direct_lv2(space); }
1309         else            { dma_indirect_lv2(space); }
12451310
12461311         stv_scu[20]^=1;
12471312
12481313         /*Sound IRQ*/
12491314         if(/*(!(stv_scu[40] & 0x40)) &&*/ scsp_to_main_irq == 1)
12501315         {
1251            //cpu_set_input_line_and_vector(machine->cpu[0], 9, HOLD_LINE , 0x46);
1316            //cpu_set_input_line_and_vector(space->machine->cpu[0], 9, HOLD_LINE , 0x46);
12521317            logerror("SCSP: Main CPU interrupt\n");
12531318         }
12541319      }
r3671r3672
12701335      /*DSP section*/
12711336      /*Use functions so it is easier to work out*/
12721337      case 32:
1273      dsp_prg_ctrl(machine, data);
1338      dsp_prg_ctrl(space, data);
12741339      if(LOG_SCU) logerror("SCU DSP: Program Control Port Access %08x\n",data);
12751340      break;
12761341      case 33:
r3671r3672
12911356      case 40:
12921357      /*An interrupt is masked when his specific bit is 1.*/
12931358      /*Are bit 16-bit 31 for External A-Bus irq mask like the status register?*/
1294      /*What is 0x00000080 setting?Is it valid?*/
12951359
1360      stv_irq.vblank_in =  (((stv_scu[40] & 0x0001)>>0) ^ 1);
1361      stv_irq.vblank_out = (((stv_scu[40] & 0x0002)>>1) ^ 1);
1362      stv_irq.hblank_in =  (((stv_scu[40] & 0x0004)>>2) ^ 1);
1363      stv_irq.timer_0 =     (((stv_scu[40] & 0x0008)>>3) ^ 1);
1364      stv_irq.timer_1 =    (((stv_scu[40] & 0x0010)>>4) ^ 1);
1365      stv_irq.dsp_end =    (((stv_scu[40] & 0x0020)>>5) ^ 1);
1366      stv_irq.sound_req =  (((stv_scu[40] & 0x0040)>>6) ^ 1);
1367      stv_irq.smpc =       (((stv_scu[40] & 0x0080)>>7)); //NOTE: SCU bug
1368      stv_irq.pad =        (((stv_scu[40] & 0x0100)>>8) ^ 1);
1369      stv_irq.dma_end[0] = (((stv_scu[40] & 0x0200)>>9) ^ 1);
1370      stv_irq.dma_end[1] = (((stv_scu[40] & 0x0400)>>10) ^ 1);
1371      stv_irq.dma_end[2] = (((stv_scu[40] & 0x0800)>>11) ^ 1);
1372      stv_irq.dma_ill =    (((stv_scu[40] & 0x1000)>>12) ^ 1);
1373      stv_irq.vdp1_end =   (((stv_scu[40] & 0x2000)>>13) ^ 1);
1374      stv_irq.abus =       (((stv_scu[40] & 0x8000)>>15) ^ 1);
1375
12961376      /*Take out the common settings to keep logging quiet.*/
12971377      if(stv_scu[40] != 0xfffffffe &&
12981378         stv_scu[40] != 0xfffffffc &&
12991379         stv_scu[40] != 0xffffffff)
13001380      {
1301         if(LOG_SCU) logerror("cpu #%d (PC=%08X) IRQ mask reg set %08x = %d%d%d%d|%d%d%d%d|%d%d%d%d|%d%d%d%d\n",
1302         cpu_getactivecpu(), cpu_get_pc(space->cpu),
1381         if(LOG_SCU) logerror("cpu %s (PC=%08X) IRQ mask reg set %08x = %d%d%d%d|%d%d%d%d|%d%d%d%d|%d%d%d%d\n",
1382         space->cpu->tag, cpu_get_pc(space->cpu),
13031383         stv_scu[offset],
13041384         stv_scu[offset] & 0x8000 ? 1 : 0, /*A-Bus irq*/
13051385         stv_scu[offset] & 0x4000 ? 1 : 0, /*<reserved>*/
r3671r3672
13191399         stv_scu[offset] & 0x0001 ? 1 : 0);/*VBlank-IN*/
13201400      }
13211401      break;
1402      /*Interrupt Control reg Set*/
13221403      case 41:
13231404      /*This is r/w by introdon...*/
1324      if(LOG_SCU) logerror("IRQ status reg set:%08x\n",stv_scu[41]);
1405      if(LOG_SCU) logerror("IRQ status reg set:%08x %08x\n",stv_scu[41],mem_mask);
1406
1407      stv_irq.vblank_in =  ((stv_scu[41] & 0x0001)>>0);
1408      stv_irq.vblank_out = ((stv_scu[41] & 0x0002)>>1);
1409      stv_irq.hblank_in =  ((stv_scu[41] & 0x0004)>>2);
1410      stv_irq.timer_0 =    ((stv_scu[41] & 0x0008)>>3);
1411      stv_irq.timer_1 =    ((stv_scu[41] & 0x0010)>>4);
1412      stv_irq.dsp_end =    ((stv_scu[41] & 0x0020)>>5);
1413      stv_irq.sound_req =  ((stv_scu[41] & 0x0040)>>6);
1414      stv_irq.smpc =       ((stv_scu[41] & 0x0080)>>7);
1415      stv_irq.pad =        ((stv_scu[41] & 0x0100)>>8);
1416      stv_irq.dma_end[0] = ((stv_scu[41] & 0x0200)>>9);
1417      stv_irq.dma_end[1] = ((stv_scu[41] & 0x0400)>>10);
1418      stv_irq.dma_end[2] = ((stv_scu[41] & 0x0800)>>11);
1419      stv_irq.dma_ill =    ((stv_scu[41] & 0x1000)>>12);
1420      stv_irq.vdp1_end =   ((stv_scu[41] & 0x2000)>>13);
1421      stv_irq.abus =       ((stv_scu[41] & 0x8000)>>15);
1422
13251423      break;
13261424      case 42: if(LOG_SCU) logerror("A-Bus IRQ ACK %08x\n",stv_scu[42]); break;
13271425      case 49: if(LOG_SCU) logerror("SCU SDRAM set: %02x\n",stv_scu[49]); break;
r3671r3672
13291427   }
13301428}
13311429
1332static void dma_direct_lv0(running_machine *machine)
1430/*Lv 0 DMA end irq*/
1431static TIMER_CALLBACK( dma_lv0_ended )
13331432{
1433   cpu_set_input_line_and_vector(machine->cpu[0], 5, (stv_irq.dma_end[0]) ? HOLD_LINE : CLEAR_LINE, 0x4b);
1434
1435   D0MV_0;
1436}
1437
1438/*Lv 1 DMA end irq*/
1439static TIMER_CALLBACK( dma_lv1_ended )
1440{
1441   cpu_set_input_line_and_vector(machine->cpu[0], 6, (stv_irq.dma_end[1]) ? HOLD_LINE : CLEAR_LINE, 0x4a);
1442
1443   D1MV_0;
1444}
1445
1446/*Lv 2 DMA end irq*/
1447static TIMER_CALLBACK( dma_lv2_ended )
1448{
1449   cpu_set_input_line_and_vector(machine->cpu[0], 6, (stv_irq.dma_end[2]) ? HOLD_LINE : CLEAR_LINE, 0x49);
1450
1451   D2MV_0;
1452}
1453
1454static void dma_direct_lv0(const address_space *space)
1455{
13341456   static UINT32 tmp_src,tmp_dst,tmp_size;
13351457   if(LOG_SCU) logerror("DMA lv 0 transfer START\n"
13361458                      "Start %08x End %08x Size %04x\n",scu_src_0,scu_dst_0,scu_size_0);
r3671r3672
14031525   for (; scu_size_0 > 0; scu_size_0-=scu_dst_add_0)
14041526   {
14051527      if(scu_dst_add_0 == 2)
1406         program_write_word(scu_dst_0,program_read_word(scu_src_0));
1528         memory_write_word(space,scu_dst_0,memory_read_word(space,scu_src_0));
14071529      else if(scu_dst_add_0 == 8)
14081530      {
1409         program_write_word(scu_dst_0,program_read_word(scu_src_0));
1410         program_write_word(scu_dst_0+2,program_read_word(scu_src_0));
1411         program_write_word(scu_dst_0+4,program_read_word(scu_src_0+2));
1412         program_write_word(scu_dst_0+6,program_read_word(scu_src_0+2));
1531         memory_write_word(space,scu_dst_0,memory_read_word(space,scu_src_0));
1532         memory_write_word(space,scu_dst_0+2,memory_read_word(space,scu_src_0));
1533         memory_write_word(space,scu_dst_0+4,memory_read_word(space,scu_src_0+2));
1534         memory_write_word(space,scu_dst_0+6,memory_read_word(space,scu_src_0+2));
14131535      }
14141536      else
14151537      {
1416         program_write_word(scu_dst_0,program_read_word(scu_src_0));
1417         program_write_word(scu_dst_0+2,program_read_word(scu_src_0+2));
1538         memory_write_word(space,scu_dst_0,memory_read_word(space,scu_src_0));
1539         memory_write_word(space,scu_dst_0+2,memory_read_word(space,scu_src_0+2));
14181540      }
14191541
14201542      scu_dst_0+=scu_dst_add_0;
r3671r3672
14261548   if(!(DWUP(0))) scu_dst_0 = tmp_dst;
14271549
14281550   if(LOG_SCU) logerror("DMA transfer END\n");
1429   if(!(stv_scu[40] & 0x800))/*Lv 0 DMA end irq*/
1430      cpu_set_input_line_and_vector(machine->cpu[0], 5, HOLD_LINE , 0x4b);
14311551
1552   /*TODO: timing of this*/
1553   timer_set(ATTOTIME_IN_USEC(300), NULL, 0, dma_lv0_ended);
1554
14321555   if(scu_add_tmp & 0x80000000)
14331556   {
14341557      scu_dst_add_0 = (scu_add_tmp & 0xff00) >> 8;
14351558      scu_src_add_0 = (scu_add_tmp & 0x00ff) >> 0;
14361559      scu_add_tmp^=0x80000000;
14371560   }
1438
1439   D0MV_0;
14401561}
14411562
1442static void dma_direct_lv1(running_machine *machine)
1563static void dma_direct_lv1(const address_space *space)
14431564{
14441565   static UINT32 tmp_src,tmp_dst,tmp_size;
14451566   if(LOG_SCU) logerror("DMA lv 1 transfer START\n"
r3671r3672
15131634   for (; scu_size_1 > 0; scu_size_1-=scu_dst_add_1)
15141635   {
15151636      if(scu_dst_add_1 == 2)
1516         program_write_word(scu_dst_1,program_read_word(scu_src_1));
1637         memory_write_word(space,scu_dst_1,memory_read_word(space,scu_src_1));
15171638      else
15181639      {
1519         program_write_word(scu_dst_1,program_read_word(scu_src_1));
1520         program_write_word(scu_dst_1+2,program_read_word(scu_src_1+2));
1640         memory_write_word(space,scu_dst_1,memory_read_word(space,scu_src_1));
1641         memory_write_word(space,scu_dst_1+2,memory_read_word(space,scu_src_1+2));
15211642      }
15221643
15231644      scu_dst_1+=scu_dst_add_1;
r3671r3672
15291650   if(!(DWUP(1))) scu_dst_1 = tmp_dst;
15301651
15311652   if(LOG_SCU) logerror("DMA transfer END\n");
1532   if(!(stv_scu[40] & 0x400))/*Lv 1 DMA end irq*/
1533      cpu_set_input_line_and_vector(machine->cpu[0], 6, HOLD_LINE , 0x4a);
15341653
1654   timer_set(ATTOTIME_IN_USEC(300), NULL, 0, dma_lv1_ended);
1655
15351656   if(scu_add_tmp & 0x80000000)
15361657   {
15371658      scu_dst_add_1 = (scu_add_tmp & 0xff00) >> 8;
15381659      scu_src_add_1 = (scu_add_tmp & 0x00ff) >> 0;
15391660      scu_add_tmp^=0x80000000;
15401661   }
1541
1542   D1MV_0;
15431662}
15441663
1545static void dma_direct_lv2(running_machine *machine)
1664static void dma_direct_lv2(const address_space *space)
15461665{
15471666   static UINT32 tmp_src,tmp_dst,tmp_size;
15481667   if(LOG_SCU) logerror("DMA lv 2 transfer START\n"
r3671r3672
16161735   for (; scu_size_2 > 0; scu_size_2-=scu_dst_add_2)
16171736   {
16181737      if(scu_dst_add_2 == 2)
1619         program_write_word(scu_dst_2,program_read_word(scu_src_2));
1738         memory_write_word(space,scu_dst_2,memory_read_word(space,scu_src_2));
16201739      else
16211740      {
1622         program_write_word(scu_dst_2,program_read_word(scu_src_2));
1623         program_write_word(scu_dst_2+2,program_read_word(scu_src_2+2));
1741         memory_write_word(space,scu_dst_2,memory_read_word(space,scu_src_2));
1742         memory_write_word(space,scu_dst_2+2,memory_read_word(space,scu_src_2+2));
16241743      }
16251744
16261745      scu_dst_2+=scu_dst_add_2;
r3671r3672
16321751   if(!(DWUP(2))) scu_dst_2 = tmp_dst;
16331752
16341753   if(LOG_SCU) logerror("DMA transfer END\n");
1635   if(!(stv_scu[40] & 0x200))/*Lv 2 DMA end irq*/
1636      cpu_set_input_line_and_vector(machine->cpu[0], 6, HOLD_LINE , 0x49);
16371754
1755   timer_set(ATTOTIME_IN_USEC(300), NULL, 0, dma_lv2_ended);
1756
16381757   if(scu_add_tmp & 0x80000000)
16391758   {
16401759      scu_dst_add_2 = (scu_add_tmp & 0xff00) >> 8;
16411760      scu_src_add_2 = (scu_add_tmp & 0x00ff) >> 0;
16421761      scu_add_tmp^=0x80000000;
16431762   }
1644
1645   D2MV_0;
16461763}
16471764
1648static void dma_indirect_lv0(running_machine *machine)
1765static void dma_indirect_lv0(const address_space *space)
16491766{
16501767   /*Helper to get out of the cycle*/
16511768   UINT8 job_done = 0;
r3671r3672
16621779      tmp_src = scu_index_0;
16631780
16641781      /*Thanks for Runik of Saturnin for pointing this out...*/
1665      scu_size_0 = program_read_dword(scu_index_0);
1666      scu_src_0 =  program_read_dword(scu_index_0+8);
1667      scu_dst_0 =  program_read_dword(scu_index_0+4);
1782      scu_size_0 = memory_read_dword(space,scu_index_0);
1783      scu_src_0 =  memory_read_dword(space,scu_index_0+8);
1784      scu_dst_0 =  memory_read_dword(space,scu_index_0+4);
16681785
16691786      /*Indirect Mode end factor*/
16701787      if(scu_src_0 & 0x80000000)
r3671r3672
16881805      for (; scu_size_0 > 0; scu_size_0-=scu_dst_add_0)
16891806      {
16901807         if(scu_dst_add_0 == 2)
1691            program_write_word(scu_dst_0,program_read_word(scu_src_0));
1808            memory_write_word(space,scu_dst_0,memory_read_word(space,scu_src_0));
16921809         else
16931810         {
16941811            /* some games, eg columns97 are a bit weird, I'm not sure this is correct
r3671r3672
16961813                  can't access 2 byte boundaries, and the end of the sprite list never gets marked,
16971814                  the length of the transfer is also set to a 2 byte boundary, maybe the add values
16981815                  should be different, I don't know */
1699            program_write_word(scu_dst_0,program_read_word(scu_src_0));
1700            program_write_word(scu_dst_0+2,program_read_word(scu_src_0+2));
1816            memory_write_word(space,scu_dst_0,memory_read_word(space,scu_src_0));
1817            memory_write_word(space,scu_dst_0+2,memory_read_word(space,scu_src_0+2));
17011818         }
17021819         scu_dst_0+=scu_dst_add_0;
17031820         scu_src_0+=scu_src_add_0;
17041821      }
17051822
1706      //if(DRUP(0))   program_write_dword(tmp_src+8,scu_src_0|job_done ? 0x80000000 : 0);
1707      //if(DWUP(0)) program_write_dword(tmp_src+4,scu_dst_0);
1823      //if(DRUP(0))   memory_write_dword(space,tmp_src+8,scu_src_0|job_done ? 0x80000000 : 0);
1824      //if(DWUP(0)) memory_write_dword(space,tmp_src+4,scu_dst_0);
17081825
17091826      scu_index_0 = tmp_src+0xc;
17101827
17111828   }while(job_done == 0);
17121829
1713   if(!(stv_scu[40] & 0x800))/*Lv 0 DMA end irq*/
1714      cpu_set_input_line_and_vector(machine->cpu[0], 5, HOLD_LINE , 0x4b);
1715
1716   D0MV_0;
1830   timer_set(ATTOTIME_IN_USEC(300), NULL, 0, dma_lv0_ended);
17171831}
17181832
1719static void dma_indirect_lv1(running_machine *machine)
1833static void dma_indirect_lv1(const address_space *space)
17201834{
17211835   /*Helper to get out of the cycle*/
17221836   UINT8 job_done = 0;
r3671r3672
17321846   do{
17331847      tmp_src = scu_index_1;
17341848
1735      scu_size_1 = program_read_dword(scu_index_1);
1736      scu_src_1 =  program_read_dword(scu_index_1+8);
1737      scu_dst_1 =  program_read_dword(scu_index_1+4);
1849      scu_size_1 = memory_read_dword(space,scu_index_1);
1850      scu_src_1 =  memory_read_dword(space,scu_index_1+8);
1851      scu_dst_1 =  memory_read_dword(space,scu_index_1+4);
17381852
17391853      /*Indirect Mode end factor*/
17401854      if(scu_src_1 & 0x80000000)
r3671r3672
17601874      {
17611875
17621876         if(scu_dst_add_1 == 2)
1763            program_write_word(scu_dst_1,program_read_word(scu_src_1));
1877            memory_write_word(space,scu_dst_1,memory_read_word(space,scu_src_1));
17641878         else
17651879         {
17661880            /* some games, eg columns97 are a bit weird, I'm not sure this is correct
r3671r3672
17681882                  can't access 2 byte boundaries, and the end of the sprite list never gets marked,
17691883                  the length of the transfer is also set to a 2 byte boundary, maybe the add values
17701884                  should be different, I don't know */
1771            program_write_word(scu_dst_1,program_read_word(scu_src_1));
1772            program_write_word(scu_dst_1+2,program_read_word(scu_src_1+2));
1885            memory_write_word(space,scu_dst_1,memory_read_word(space,scu_src_1));
1886            memory_write_word(space,scu_dst_1+2,memory_read_word(space,scu_src_1+2));
17731887         }
17741888         scu_dst_1+=scu_dst_add_1;
17751889         scu_src_1+=scu_src_add_1;
17761890      }
17771891
1778      //if(DRUP(1))   program_write_dword(tmp_src+8,scu_src_1|job_done ? 0x80000000 : 0);
1779      //if(DWUP(1)) program_write_dword(tmp_src+4,scu_dst_1);
1892      //if(DRUP(1))   memory_write_dword(space,tmp_src+8,scu_src_1|job_done ? 0x80000000 : 0);
1893      //if(DWUP(1)) memory_write_dword(space,tmp_src+4,scu_dst_1);
17801894
17811895      scu_index_1 = tmp_src+0xc;
17821896
17831897   }while(job_done == 0);
17841898
1785   if(!(stv_scu[40] & 0x400))/*Lv 1 DMA end irq*/
1786      cpu_set_input_line_and_vector(machine->cpu[0], 6, HOLD_LINE , 0x4a);
1787
1788   D1MV_0;
1899   timer_set(ATTOTIME_IN_USEC(300), NULL, 0, dma_lv1_ended);
17891900}
17901901
1791static void dma_indirect_lv2(running_machine *machine)
1902static void dma_indirect_lv2(const address_space *space)
17921903{
17931904   /*Helper to get out of the cycle*/
17941905   UINT8 job_done = 0;
r3671r3672
18041915   do{
18051916      tmp_src = scu_index_2;
18061917
1807      scu_size_2 = program_read_dword(scu_index_2);
1808      scu_src_2 =  program_read_dword(scu_index_2+8);
1809      scu_dst_2 =  program_read_dword(scu_index_2+4);
1918      scu_size_2 = memory_read_dword(space,scu_index_2);
1919      scu_src_2 =  memory_read_dword(space,scu_index_2+8);
1920      scu_dst_2 =  memory_read_dword(space,scu_index_2+4);
18101921
18111922      /*Indirect Mode end factor*/
18121923      if(scu_src_2 & 0x80000000)
r3671r3672
18301941      for (; scu_size_2 > 0; scu_size_2-=scu_dst_add_2)
18311942      {
18321943         if(scu_dst_add_2 == 2)
1833            program_write_word(scu_dst_2,program_read_word(scu_src_2));
1944            memory_write_word(space,scu_dst_2,memory_read_word(space,scu_src_2));
18341945         else
18351946         {
18361947            /* some games, eg columns97 are a bit weird, I'm not sure this is correct
r3671r3672
18381949                  can't access 2 byte boundaries, and the end of the sprite list never gets marked,
18391950                  the length of the transfer is also set to a 2 byte boundary, maybe the add values
18401951                  should be different, I don't know */
1841            program_write_word(scu_dst_2,program_read_word(scu_src_2));
1842            program_write_word(scu_dst_2+2,program_read_word(scu_src_2+2));
1952            memory_write_word(space,scu_dst_2,memory_read_word(space,scu_src_2));
1953            memory_write_word(space,scu_dst_2+2,memory_read_word(space,scu_src_2+2));
18431954         }
18441955
18451956         scu_dst_2+=scu_dst_add_2;
18461957         scu_src_2+=scu_src_add_2;
18471958      }
18481959
1849      //if(DRUP(2))   program_write_dword(tmp_src+8,scu_src_2|job_done ? 0x80000000 : 0);
1850      //if(DWUP(2)) program_write_dword(tmp_src+4,scu_dst_2);
1960      //if(DRUP(2))   memory_write_dword(space,tmp_src+8,scu_src_2|job_done ? 0x80000000 : 0);
1961      //if(DWUP(2)) memory_write_dword(space,tmp_src+4,scu_dst_2);
18511962
18521963      scu_index_2 = tmp_src+0xc;
18531964
18541965   }while(job_done == 0);
18551966
1856   if(!(stv_scu[40] & 0x200))/*Lv 2 DMA end irq*/
1857      cpu_set_input_line_and_vector(machine->cpu[0], 6, HOLD_LINE , 0x49);
1858
1859   D2MV_0;
1967   timer_set(ATTOTIME_IN_USEC(300), NULL, 0, dma_lv2_ended);
18601968}
18611969
18621970
r3671r3672
18781986static READ32_HANDLER( stv_scsp_regs_r32 )
18791987{
18801988   offset <<= 1;
1881   return (scsp_0_r(machine, offset+1, 0xffff) | (scsp_0_r(machine, offset, 0xffff)<<16));
1989   return (scsp_0_r(space, offset+1, 0xffff) | (scsp_0_r(space, offset, 0xffff)<<16));
18821990}
18831991
18841992static WRITE32_HANDLER( stv_scsp_regs_w32 )
18851993{
18861994   offset <<= 1;
1887   scsp_0_w(machine, offset + 0, data >> 16, mem_mask >> 16);
1888   scsp_0_w(machine, offset + 1, data >>  0, mem_mask);
1995   scsp_0_w(space, offset, data>>16, mem_mask >> 16);
1996   scsp_0_w(space, offset+1, data, mem_mask);
18891997}
18901998
18911999/* communication,SLAVE CPU acquires data from the MASTER CPU and triggers an irq.  *
18922000 * Enter into Radiant Silver Gun specific menu for a test...                       */
18932001static WRITE32_HANDLER( minit_w )
18942002{
1895   logerror("cpu #%d (PC=%08X) MINIT write = %08x\n",cpu_getactivecpu(), cpu_get_pc(space->cpu),data);
1896   cpu_boost_interleave(machine, minit_boost_timeslice, ATTOTIME_IN_USEC(minit_boost));
1897   cpu_trigger(machine, 1000);
1898   cpunum_set_info_int(1, CPUINFO_INT_SH2_FRT_INPUT, PULSE_LINE);
2003   logerror("cpu %s (PC=%08X) MINIT write = %08x\n", space->cpu->tag, cpu_get_pc(space->cpu),data);
2004   cpuexec_boost_interleave(space->machine, minit_boost_timeslice, ATTOTIME_IN_USEC(minit_boost));
2005   cpuexec_trigger(space->machine, 1000);
2006   cpu_set_info_int(space->machine->cpu[1], CPUINFO_INT_SH2_FRT_INPUT, PULSE_LINE);
18992007}
19002008
19012009static WRITE32_HANDLER( sinit_w )
19022010{
1903   logerror("cpu #%d (PC=%08X) SINIT write = %08x\n",cpu_getactivecpu(), cpu_get_pc(space->cpu),data);
1904   cpu_boost_interleave(machine, sinit_boost_timeslice, ATTOTIME_IN_USEC(sinit_boost));
1905   cpunum_set_info_int(0, CPUINFO_INT_SH2_FRT_INPUT, PULSE_LINE);
2011   logerror("cpu %s (PC=%08X) SINIT write = %08x\n", space->cpu->tag, cpu_get_pc(space->cpu),data);
2012   cpuexec_boost_interleave(space->machine, sinit_boost_timeslice, ATTOTIME_IN_USEC(sinit_boost));
2013   cpu_set_info_int(space->machine->cpu[0], CPUINFO_INT_SH2_FRT_INPUT, PULSE_LINE);
19062014}
19072015
19082016static UINT32 backup[64*1024/4];
r3671r3672
20732181   saturn_region = rgn;
20742182
20752183   // set compatible options
2076   cpunum_set_info_int(0, CPUINFO_INT_SH2_DRC_OPTIONS, SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
2077   cpunum_set_info_int(1, CPUINFO_INT_SH2_DRC_OPTIONS, SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
2184   cpu_set_info_int(machine->cpu[0], CPUINFO_INT_SH2_DRC_OPTIONS, SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
2185   cpu_set_info_int(machine->cpu[1], CPUINFO_INT_SH2_DRC_OPTIONS, SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL);
20782186
20792187   /* get the current date/time from the core */
20802188   mame_get_current_datetime(machine, &systime);
r3671r3672
20892197   stv_scu = auto_malloc (0x100);
20902198   scsp_regs = auto_malloc (0x1000);
20912199
2092     smpc_ram[0x23] = DectoBCD(systime.local_time.year / 100);
2093    smpc_ram[0x25] = DectoBCD(systime.local_time.year % 100);
2094    smpc_ram[0x27] = (systime.local_time.weekday << 4) | (systime.local_time.month + 1);
2095    smpc_ram[0x29] = DectoBCD(systime.local_time.mday);
2096    smpc_ram[0x2b] = DectoBCD(systime.local_time.hour);
2097    smpc_ram[0x2d] = DectoBCD(systime.local_time.minute);
2098    smpc_ram[0x2f] = DectoBCD(systime.local_time.second);
2099    smpc_ram[0x31] = 0x00; //CTG1=0 CTG0=0 (correct??)
2100//  smpc_ram[0x33] = input_port_read(machine, "???");
2200   smpc_ram[0x23] = DectoBCD(systime.local_time.year / 100);
2201   smpc_ram[0x25] = DectoBCD(systime.local_time.year % 100);
2202   smpc_ram[0x27] = (systime.local_time.weekday << 4) | (systime.local_time.month + 1);
2203   smpc_ram[0x29] = DectoBCD(systime.local_time.mday);
2204   smpc_ram[0x2b] = DectoBCD(systime.local_time.hour);
2205   smpc_ram[0x2d] = DectoBCD(systime.local_time.minute);
2206   smpc_ram[0x2f] = DectoBCD(systime.local_time.second);
2207   smpc_ram[0x31] = 0x00; //CTG1=0 CTG0=0 (correct??)
2208//   smpc_ram[0x33] = input_port_read(machine, "???");
21012209    smpc_ram[0x5f] = 0x10;
21022210}
21032211
2104#ifdef UNUSED_FUNCTION
2105DRIVER_INIT( saturn )
2106{
2107   saturn_init_driver(machine, 0);
2108}
2109#endif
2110
21112212static DRIVER_INIT( saturnus )
21122213{
21132214   saturn_init_driver(machine, 4);
r3671r3672
21642265   // don't let the slave cpu and the 68k go anywhere
21652266   cpu_set_input_line(machine->cpu[1], INPUT_LINE_RESET, ASSERT_LINE);
21662267   stv_enable_slave_sh2 = 0;
2167   cpunum_set_input_line(machine, 2, INPUT_LINE_RESET, ASSERT_LINE);
2268   cpu_set_input_line(machine->cpu[2], INPUT_LINE_RESET, ASSERT_LINE);
21682269
21692270   smpcSR = 0x40;   // this bit is always on according to docs
21702271
r3671r3672
21792280   memset(stv_workram_l, 0, 0x100000);
21802281   memset(stv_workram_h, 0, 0x100000);
21812282
2182   cpunum_set_clock(machine, 0, MASTER_CLOCK_320/2);
2183   cpunum_set_clock(machine, 1, MASTER_CLOCK_320/2);
2184   cpunum_set_clock(machine, 2, MASTER_CLOCK_320/5);
2283   cpu_set_clock(machine->cpu[0], MASTER_CLOCK_320/2);
2284   cpu_set_clock(machine->cpu[1], MASTER_CLOCK_320/2);
2285   cpu_set_clock(machine->cpu[2], MASTER_CLOCK_320/5);
21852286
21862287   stvcd_reset( machine );
2288
2289   /* set the first scanline 0 timer to go off */
2290   scan_timer = timer_alloc(hblank_in_irq, NULL);
2291   t1_timer = timer_alloc(timer1_irq,NULL);
2292   vblank_in_timer = timer_alloc(vblank_in_irq,NULL);
2293   timer_adjust_oneshot(vblank_in_timer,video_screen_get_time_until_pos(machine->primary_screen, 0, 0), 0);
2294   timer_adjust_oneshot(scan_timer, video_screen_get_time_until_pos(machine->primary_screen, 224, 352), 0);
21872295}
21882296
21892297static const gfx_layout tiles8x8x4_layout =
r3671r3672
22712379   if (irq > 0)
22722380   {
22732381      scsp_last_line = irq;
2274      cpunum_set_input_line(machine, 2, irq, ASSERT_LINE);
2382      cpu_set_input_line(machine->cpu[2], irq, ASSERT_LINE);
22752383   }
22762384   else if (irq < 0)
22772385   {
2278      cpunum_set_input_line(machine, 2, -irq, CLEAR_LINE);
2386      cpu_set_input_line(machine->cpu[2], -irq, CLEAR_LINE);
22792387   }
22802388   else
22812389   {
2282      cpunum_set_input_line(machine, 2, scsp_last_line, CLEAR_LINE);
2390      cpu_set_input_line(machine->cpu[2], scsp_last_line, CLEAR_LINE);
22832391   }
22842392}
22852393

Previous 15994 Revisions Next


© 1998-2018 The MESS Team