Previous 15994 Revisions Next

r8218 Friday 4th June, 2010 at 18:57:42 UTC by Fabio Priuli
[NES] some more refactoring. main change: converted PRG banking to use memory_configure_bank in place of memory_set_bankptr
[src/mess/includes]nes.h
[src/mess/machine]nes.c nes_mmc.c
[src/mess/video]nes.c

src/mess/video/nes.c
r8217r8218
1515{
1616   nes_state *state = (nes_state *)machine->driver_data;
1717   ppu2c0x_set_vidaccess_callback(devtag_get_device(machine,"ppu"), nes_ppu_vidaccess);
18   ppu2c0x_set_scanlines_per_frame(devtag_get_device(machine,"ppu"), ceil(state->scanlines_per_frame));
1918
2019   if (state->four_screen_vram)
2120      set_nt_mirroring(machine, PPU_MIRROR_4SCREEN);
r8217r8218
3635   }
3736}
3837
39static void nes_vh_start(running_machine *machine, double scanlines_per_frame)
38VIDEO_START( nes )
4039{
4140   nes_state *state = (nes_state *)machine->driver_data;
42
41   
4342   state->last_frame_flip =  0;
44   state->scanlines_per_frame = scanlines_per_frame;
45
43   
4644   add_reset_callback(machine, nes_vh_reset);
4745}
4846
49VIDEO_START( nes_ntsc )
50{
51   nes_vh_start(machine, PPU_NTSC_SCANLINES_PER_FRAME);
52}
53
54VIDEO_START( nes_pal )
55{
56   nes_vh_start(machine, PPU_PAL_SCANLINES_PER_FRAME);
57}
58
5947PALETTE_INIT( nes )
6048{
6149   ppu2c0x_init_palette(machine, 0);
src/mess/includes/nes.h
r8217r8218
6969   /* input_related - this part has to be cleaned up (e.g. in_2 and in_3 are not really necessary here...) */
7070   nes_input in_0, in_1, in_2, in_3;
7171
72   int           prg_bank[5];
7273   chr_bank      chr_map[8];  //quick banking structure, because some of this changes multiple times per scanline!
7374   name_table    nt_page[4];  //quick banking structure for a maximum of 4K of RAM/ROM/ExRAM
7475
r8217r8218
8182   /* video-related */
8283   int nes_vram_sprite[8]; /* Used only by mmc5 for now */
8384   int last_frame_flip;
84   double scanlines_per_frame;
8585
8686   /* misc */
8787   write8_space_func   mmc_write_low;
r8217r8218
207207extern int nes_vram_sprite[8];
208208
209209PALETTE_INIT( nes );
210VIDEO_START( nes_ntsc );
211VIDEO_START( nes_pal );
210VIDEO_START( nes );
212211VIDEO_UPDATE( nes );
213212
214213
src/mess/machine/nes.c
r8217r8218
3434{
3535   nes_state *state = (nes_state *)machine->driver_data;
3636   const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM);
37   static const char *const bank_names[] = { "bank1", "bank2", "bank3", "bank4" };
38   int prg_banks = (state->prg_chunks == 1) ? (2 * 2) : (state->prg_chunks * 2);
39   int i;
3740
3841   /* We set these here in case they weren't set in the cart loader */
3942   state->rom = memory_region(machine, "maincpu");
r8217r8218
8992         memory_install_read_bank(space, 0xa000, 0xbfff, 0, 0, "bank2");
9093         memory_install_read_bank(space, 0xc000, 0xdfff, 0, 0, "bank3");
9194         memory_install_read_bank(space, 0xe000, 0xffff, 0, 0, "bank4");
92         memory_set_bankptr(machine, "bank1", memory_region(machine, "maincpu") + 0x6000);
93         memory_set_bankptr(machine, "bank2", memory_region(machine, "maincpu") + 0x8000);
94         memory_set_bankptr(machine, "bank3", memory_region(machine, "maincpu") + 0xa000);
95         memory_set_bankptr(machine, "bank4", memory_region(machine, "maincpu") + 0xc000);
96         memory_set_bankptr(machine, "bank5", memory_region(machine, "maincpu") + 0xe000);
9795
96         // initially setup banks to maincpu 0x8000-0xffff
97         for (i = 0; i < 4; i++)
98         {
99            memory_configure_bank(machine, bank_names[i], 0, prg_banks, memory_region(machine, "maincpu") + 0x10000, 0x2000);
100            memory_set_bank(machine, bank_names[i], i);
101            state->prg_bank[i] = i;
102         }
103
104         memory_configure_bank(machine, "bank5", 0, 1, memory_region(machine, "maincpu") + 0x6000, 0x2000);
105         memory_configure_bank(machine, "bank5", 1, prg_banks, memory_region(machine, "maincpu") + 0x10000, 0x2000);
106         memory_set_bank(machine, "bank5", 0);
107         state->prg_bank[4] = 0;
108
98109         memory_install_write8_handler(space, 0x6000, 0x7fff, 0, 0, nes_mid_mapper_w);
99110//         memory_install_read8_handler(space, 0x6000, 0x7fff, 0, 0, nes_mid_mapper_r);
100111         memory_install_write8_handler(space, 0x8000, 0xffff, 0, 0, nes_mapper_w);
r8217r8218
168179
169180int nes_ppu_vidaccess( running_device *device, int address, int data )
170181{
171   nes_state *state = (nes_state *)device->machine->driver_data;
182//   nes_state *state = (nes_state *)device->machine->driver_data;
172183
173184   /* TODO: this is a bit of a hack, needed to get Argus, ASO, etc to work */
174185   /* but, B-Wings, submath (j) seem to use this location differently... */
175   if (state->chr_chunks && (address & 0x3fff) < 0x2000)
176   {
186//   if (state->chr_chunks && (address & 0x3fff) < 0x2000)
187//   {
177188//      int vrom_loc;
178189//      vrom_loc = (nes_vram[(address & 0x1fff) >> 10] * 16) + (address & 0x3ff);
179190//      data = state->vrom [vrom_loc];
180   }
191//   }
181192   return data;
182193}
183194
r8217r8218
209220   timer_adjust_oneshot(state->irq_timer, attotime_never, 0);
210221}
211222
223static STATE_POSTLOAD( nes_banks_restore )
224{
225   nes_state *state = (nes_state *)machine->driver_data;
226
227   memory_set_bank(machine, "bank1", state->prg_bank[0]);
228   memory_set_bank(machine, "bank2", state->prg_bank[1]);
229   memory_set_bank(machine, "bank3", state->prg_bank[2]);
230   memory_set_bank(machine, "bank4", state->prg_bank[3]);
231   memory_set_bank(machine, "bank5", state->prg_bank[4]);
232}
233
212234static void nes_state_register( running_machine *machine )
213235{
214236   nes_state *state = (nes_state *)machine->driver_data;
215237
238   state_save_register_global_array(machine, state->prg_bank);
239
216240   state_save_register_global(machine, state->MMC5_floodtile);
217241   state_save_register_global(machine, state->MMC5_floodattr);
218242   state_save_register_global_array(machine, state->mmc5_vram);
r8217r8218
220244
221245   state_save_register_global_array(machine, state->nes_vram_sprite);
222246   state_save_register_global(machine, state->last_frame_flip);
223   state_save_register_global(machine, state->scanlines_per_frame);
224247   state_save_register_global(machine, state->mid_ram_enable);
225248
226249   // shared mapper variables
r8217r8218
255278   state_save_register_global(machine, state->fds_write_reg);
256279   state_save_register_global(machine, state->fds_last_side);
257280   state_save_register_global(machine, state->fds_count);
281
282   state_save_register_postload(machine, nes_banks_restore, NULL);
258283}
259284
260285MACHINE_START( nes )
src/mess/machine/nes_mmc.c
r8217r8218
322322
323323*************************************************************/
324324
325INLINE void prg_bank_refresh( running_machine *machine )
326{
327   nes_state *state = (nes_state *)machine->driver_data;
328   memory_set_bank(machine, "bank1", state->prg_bank[0]);
329   memory_set_bank(machine, "bank2", state->prg_bank[1]);
330   memory_set_bank(machine, "bank3", state->prg_bank[2]);
331   memory_set_bank(machine, "bank4", state->prg_bank[3]);
332}
333
325334/* PRG ROM in 8K, 16K or 32K blocks */
326335
327336static void prg32( running_machine *machine, int bank )
r8217r8218
334343      memcpy(&state->rom[0x8000], &state->rom[bank * 0x8000 + 0x10000], 0x8000);
335344   else
336345   {
337      memory_set_bankptr(machine, "bank1", &state->rom[bank * 0x8000 + 0x10000]);
338      memory_set_bankptr(machine, "bank2", &state->rom[bank * 0x8000 + 0x12000]);
339      memory_set_bankptr(machine, "bank3", &state->rom[bank * 0x8000 + 0x14000]);
340      memory_set_bankptr(machine, "bank4", &state->rom[bank * 0x8000 + 0x16000]);
346      state->prg_bank[0] = bank * 4 + 0;
347      state->prg_bank[1] = bank * 4 + 1;
348      state->prg_bank[2] = bank * 4 + 2;
349      state->prg_bank[3] = bank * 4 + 3;
350      prg_bank_refresh(machine);
341351   }
342352}
343353
r8217r8218
351361      memcpy(&state->rom[0x8000], &state->rom[bank * 0x4000 + 0x10000], 0x4000);
352362   else
353363   {
354      memory_set_bankptr(machine, "bank1", &state->rom[bank * 0x4000 + 0x10000]);
355      memory_set_bankptr(machine, "bank2", &state->rom[bank * 0x4000 + 0x12000]);
364      state->prg_bank[0] = bank * 2 + 0;
365      state->prg_bank[1] = bank * 2 + 1;
366      prg_bank_refresh(machine);
356367   }
357368}
358369
r8217r8218
366377      memcpy(&state->rom[0xc000], &state->rom[bank * 0x4000 + 0x10000], 0x4000);
367378   else
368379   {
369      memory_set_bankptr(machine, "bank3", &state->rom[bank * 0x4000 + 0x10000]);
370      memory_set_bankptr(machine, "bank4", &state->rom[bank * 0x4000 + 0x12000]);
380      state->prg_bank[2] = bank * 2 + 0;
381      state->prg_bank[3] = bank * 2 + 1;
382      prg_bank_refresh(machine);
371383   }
372384}
373385
r8217r8218
380392   if (state->slow_banking)
381393      memcpy(&state->rom[0x8000], &state->rom[bank * 0x2000 + 0x10000], 0x2000);
382394   else
383      memory_set_bankptr(machine, "bank1", &state->rom[bank * 0x2000 + 0x10000]);
395   {
396      state->prg_bank[0] = bank;
397      prg_bank_refresh(machine);
398   }
384399}
385400
386401static void prg8_ab( running_machine *machine, int bank )
r8217r8218
392407   if (state->slow_banking)
393408      memcpy(&state->rom[0xa000], &state->rom[bank * 0x2000 + 0x10000], 0x2000);
394409   else
395      memory_set_bankptr(machine, "bank2", &state->rom[bank * 0x2000 + 0x10000]);
410   {
411      state->prg_bank[1] = bank;
412      prg_bank_refresh(machine);
413   }
396414}
397415
398416static void prg8_cd( running_machine *machine, int bank )
r8217r8218
404422   if (state->slow_banking)
405423      memcpy(&state->rom[0xc000], &state->rom[bank * 0x2000 + 0x10000], 0x2000);
406424   else
407      memory_set_bankptr(machine, "bank3", &state->rom[bank * 0x2000 + 0x10000]);
425   {
426      state->prg_bank[2] = bank;
427      prg_bank_refresh(machine);
428   }
408429}
409430
410431static void prg8_ef( running_machine *machine, int bank )
r8217r8218
416437   if (state->slow_banking)
417438      memcpy(&state->rom[0xe000], &state->rom[bank * 0x2000 + 0x10000], 0x2000);
418439   else
419      memory_set_bankptr(machine, "bank4", &state->rom[bank * 0x2000 + 0x10000]);
440   {
441      state->prg_bank[3] = bank;
442      prg_bank_refresh(machine);
443   }
420444}
421445
422446/* We define an additional helper to map PRG-ROM to 0x6000-0x7000 */
r8217r8218
428452
429453   /* assumes that bank references an 8k chunk */
430454   bank &= ((state->prg_chunks << 1) - 1);
431   memory_set_bankptr(machine, "bank5", &state->rom[bank * 0x2000 + 0x10000]);
455   state->prg_bank[4] = bank + 1;   // we have an additional 0x2000 bank at start (pointing to 0x6000), followed by usual banks
456   memory_set_bank(machine, "bank5", state->prg_bank[4]);
432457}
433458
434459/* CHR ROM in 1K, 2K, 4K or 8K blocks */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team