Previous 15994 Revisions Next

r7954 Saturday 1st May, 2010 at 10:45:50 UTC by Fabio Priuli
[NES] moved some more variables to driver data class
[src/mess/includes]nes.h
[src/mess/machine]nes.c nes_ines.c nes_mmc.c
[src/mess/video]nes.c

src/mess/video/nes.c
r7953r7954
1111#include "includes/nes.h"
1212#include "machine/nes_mmc.h"
1313
14int nes_vram_sprite[8]; /* Used only by mmc5 for now */
15static int last_frame_flip = 0;
16static double nes_scanlines_per_frame;
17
1814static void nes_vh_reset( running_machine *machine )
1915{
2016   nes_state *state = (nes_state *)machine->driver_data;
2117   ppu2c0x_set_vidaccess_callback(devtag_get_device(machine,"ppu"), nes_ppu_vidaccess);
22   ppu2c0x_set_scanlines_per_frame(devtag_get_device(machine,"ppu"), ceil(nes_scanlines_per_frame));
18   ppu2c0x_set_scanlines_per_frame(devtag_get_device(machine,"ppu"), ceil(state->scanlines_per_frame));
2319
2420   if (state->four_screen_vram)
2521      set_nt_mirroring(machine, PPU_MIRROR_4SCREEN);
r7953r7954
4238
4339static void nes_vh_start(running_machine *machine, double scanlines_per_frame)
4440{
45   last_frame_flip =  0;
46   nes_scanlines_per_frame = scanlines_per_frame;
41   nes_state *state = (nes_state *)machine->driver_data;
4742
43   state->last_frame_flip =  0;
44   state->scanlines_per_frame = scanlines_per_frame;
45
4846   add_reset_callback(machine, nes_vh_reset);
4947}
5048
51
52
5349VIDEO_START( nes_ntsc )
5450{
5551   nes_vh_start(machine, PPU_NTSC_SCANLINES_PER_FRAME);
r7953r7954
8379   if (state->mapper == 20)
8480   {
8581      // latch this input so it doesn't go at warp speed
86      if ((input_port_read(screen->machine, "FLIPDISK") & 0x01) && (!last_frame_flip))
82      if ((input_port_read(screen->machine, "FLIPDISK") & 0x01) && (!state->last_frame_flip))
8783      {
88         last_frame_flip = 1;
84         state->last_frame_flip = 1;
8985         state->fds_current_side++;
9086         if (state->fds_current_side > state->fds_sides)
9187            state->fds_current_side = 0;
r7953r7954
9793      }
9894
9995      if (!(input_port_read(screen->machine, "FLIPDISK") & 0x01))
100         last_frame_flip = 0;
96         state->last_frame_flip = 0;
10197   }
10298   return 0;
10399}
src/mess/includes/nes.h
r7953r7954
1717#define NTSC_CLOCK           N2A03_DEFAULTCLOCK     /* 1.789772 MHz */
1818#define PAL_CLOCK              (26601712.0/16)        /* 1.662607 MHz */
1919
20#define NES_BATTERY_SIZE 0x2000
2021
22
2123/***************************************************************************
2224    TYPE DEFINITIONS
2325***************************************************************************/
2426
27struct nes_input
28{
29   UINT32 shift;
30   UINT32 i0, i1, i2;
31};
32
2533class nes_state
2634{
2735public:
r7953r7954
2937
3038   nes_state(running_machine &machine) { }
3139
40   /* input_related - this part has to be cleaned up (e.g. in_2 and in_3 are not really necessary here...) */
41   nes_input in_0, in_1, in_2, in_3;
42
43   /* video-related */
44   int nes_vram_sprite[8]; /* Used only by mmc5 for now */
45   int last_frame_flip;
46   double scanlines_per_frame;
47   
3248   /* devices */
3349   running_device *ppu;
3450   running_device *sound;
3551   running_device *cart;
36   
37   /***** NES-related *****/
3852
53   /* misc region to be allocated at init */
54   // variables which don't change at run-time
55   UINT8 *rom;
56   UINT8 *vrom;
57   UINT8 *vram;
58   UINT8 *wram;
59   UINT8 *ciram; //PPU nametable RAM - external to PPU!
60   // Variables which can change
61   UINT8 mid_ram_enable;
62
63   /* SRAM-related (we have two elements due to the init order, but it would be better to verify they both are still needed) */
64   UINT8 *battery_ram;
65   UINT8 battery_data[NES_BATTERY_SIZE];
66
67   /***** NES-cart related *****/
68
3969   /* load-time cart variables which remain constant */
4070   UINT8 trainer;
4171   UINT8 battery;
r7953r7954
5282   UINT8 slow_banking;
5383   UINT8 crc_hack;   // this is needed to detect different boards sharing the same Mappers (shame on .nes format)
5484   
55   UINT8 *rom;
56   UINT8 *vrom;
57   UINT8 *vram;
58   UINT8 *wram;
59   UINT8 *ciram; //PPU nametable RAM - external to PPU!
6085   
61   /* Variables which can change */
62   UINT8 mid_ram_enable;
63   
64   
65   
66   /***** FDS-related *****/
86   /***** FDS-floppy related *****/
6787
6888   UINT8 *fds_data;
6989   UINT8 fds_sides;
src/mess/machine/nes.c
r7953r7954
2323#define SPLIT_PRG   0
2424#define SPLIT_CHR   0
2525
26#define BATTERY_SIZE 0x2000
27
2826/***************************************************************************
29    TYPE DEFINITIONS
30***************************************************************************/
31
32typedef struct _nes_input nes_input;
33struct _nes_input
34{
35   UINT32 shift;
36   UINT32 i0, i1, i2;
37};
38
39/***************************************************************************
40    GLOBAL VARIABLES
41***************************************************************************/
42
43unsigned char *nes_battery_ram;
44static UINT8 battery_data[BATTERY_SIZE];
45
46static nes_input in_0;
47static nes_input in_1;
48
49/***************************************************************************
5027    FUNCTION PROTOTYPES
5128***************************************************************************/
5229
r7953r7954
7754
7855   memory_set_bankptr(machine, "bank10", state->rom);
7956
80   nes_battery_ram = state->wram;
57   state->battery_ram = state->wram;
8158
8259   /* Set up the memory handlers for the mapper */
8360   switch (state->mapper)
r7953r7954
174151   /* memory subsystem is set up. When this routine is called */
175152   /* everything is ready, so we can just copy over the data */
176153   /* we loaded before. */
177   memcpy(nes_battery_ram, battery_data, BATTERY_SIZE);
154   memcpy(state->battery_ram, state->battery_data, NES_BATTERY_SIZE);
178155}
179156
180157int nes_ppu_vidaccess( running_device *device, int address, int data )
r7953r7954
211188      nes_unif_reset(machine, state->board);
212189
213190   /* Reset the serial input ports */
214   in_0.shift = 0;
215   in_1.shift = 0;
191   state->in_0.shift = 0;
192   state->in_1.shift = 0;
216193
217194   devtag_get_device(machine, "maincpu")->reset();
218195}
r7953r7954
239216   
240217   /* Write out the battery file if necessary */
241218   if (state->battery)
242      image_battery_save(state->cart, nes_battery_ram, BATTERY_SIZE);
219      image_battery_save(state->cart, state->battery_ram, NES_BATTERY_SIZE);
243220}
244221
245222
r7953r7954
253230   /* in the unused upper 3 bits, so typically a read from $4016 leaves 0x40 there. */
254231   ret = 0x40;
255232
256   ret |= ((in_0.i0 >> in_0.shift) & 0x01);
233   ret |= ((state->in_0.i0 >> state->in_0.shift) & 0x01);
257234
258235   /* zapper */
259236   if ((input_port_read(space->machine, "CTRLSEL") & 0x000f) == 0x0002)
260237   {
261      int x = in_0.i1;   /* read Zapper x-position */
262      int y = in_0.i2;   /* read Zapper y-position */
238      int x = state->in_0.i1;   /* read Zapper x-position */
239      int y = state->in_0.i2;   /* read Zapper y-position */
263240      UINT32 pix, color_base;
264241
265242      /* get the pixel at the gun position */
r7953r7954
278255         ret |= 0x08;  /* no sprite hit */
279256
280257      /* If button 1 is pressed, indicate the light gun trigger is pressed */
281      ret |= ((in_0.i0 & 0x01) << 4);
258      ret |= ((state->in_0.i0 & 0x01) << 4);
282259   }
283260
284261   if (LOG_JOY)
285      logerror("joy 0 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", ret, cpu_get_pc(space->cpu), in_0.shift, in_0.i0);
262      logerror("joy 0 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", ret, cpu_get_pc(space->cpu), state->in_0.shift, state->in_0.i0);
286263
287   in_0.shift++;
264   state->in_0.shift++;
288265   return ret;
289266}
290267
r7953r7954
298275   ret = 0x40;
299276
300277   /* Handle data line 0's serial output */
301   ret |= ((in_1.i0 >> in_1.shift) & 0x01);
278   ret |= ((state->in_1.i0 >> state->in_1.shift) & 0x01);
302279
303280   /* zapper */
304281   if ((input_port_read(space->machine, "CTRLSEL") & 0x00f0) == 0x0030)
305282   {
306      int x = in_1.i1;   /* read Zapper x-position */
307      int y = in_1.i2;   /* read Zapper y-position */
283      int x = state->in_1.i1;   /* read Zapper x-position */
284      int y = state->in_1.i2;   /* read Zapper y-position */
308285      UINT32 pix, color_base;
309286
310287      /* get the pixel at the gun position */
r7953r7954
323300         ret |= 0x08;  /* no sprite hit */
324301
325302      /* If button 1 is pressed, indicate the light gun trigger is pressed */
326      ret |= ((in_1.i0 & 0x01) << 4);
303      ret |= ((state->in_1.i0 & 0x01) << 4);
327304   }
328305
329306   /* arkanoid dial */
330307   else if ((input_port_read(space->machine, "CTRLSEL") & 0x00f0) == 0x0040)
331308   {
332309      /* Handle data line 2's serial output */
333      ret |= ((in_1.i2 >> in_1.shift) & 0x01) << 3;
310      ret |= ((state->in_1.i2 >> state->in_1.shift) & 0x01) << 3;
334311
335312      /* Handle data line 3's serial output - bits are reversed */
336313      /* NPW 27-Nov-2007 - there is no third subscript! commenting out */
337      /* ret |= ((in_1[3] >> in_1.shift) & 0x01) << 4; */
338      /* ret |= ((in_1[3] << in_1.shift) & 0x80) >> 3; */
314      /* ret |= ((state->in_1[3] >> state->in_1.shift) & 0x01) << 4; */
315      /* ret |= ((state->in_1[3] << state->in_1.shift) & 0x80) >> 3; */
339316   }
340317
341318   if (LOG_JOY)
342      logerror("joy 1 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", ret, cpu_get_pc(space->cpu), in_1.shift, in_1.i0);
319      logerror("joy 1 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", ret, cpu_get_pc(space->cpu), state->in_1.shift, state->in_1.i0);
343320
344   in_1.shift++;
321   state->in_1.shift++;
345322   return ret;
346323}
347324
r7953r7954
415392
416393WRITE8_HANDLER( nes_IN0_w )
417394{
395   nes_state *state = (nes_state *)space->machine->driver_data;
418396   int cfg;
419   nes_input in_2;
420   nes_input in_3;
421397
422398   if (data & 0x01)
423399      return;
424400
425401   if (LOG_JOY)
426      logerror("joy 0 bits read: %d\n", in_0.shift);
402      logerror("joy 0 bits read: %d\n", state->in_0.shift);
427403
428404   /* Toggling bit 0 high then low resets both controllers */
429   in_0.shift = 0;
430   in_1.shift = 0;
405   state->in_0.shift = 0;
406   state->in_1.shift = 0;
431407
432408   /* Check if lightgun has been chosen as input: if so, enable crosshair */
433409   timer_set(space->machine, attotime_zero, NULL, 0, lightgun_tick);
r7953r7954
436412   cfg = input_port_read(space->machine, "CTRLSEL");
437413
438414   /* Read the input devices */
439   nes_read_input_device(space->machine, cfg >>  0, &in_0, 0,  TRUE, -1);
440   nes_read_input_device(space->machine, cfg >>  4, &in_1, 1,  TRUE,  1);
441   nes_read_input_device(space->machine, cfg >>  8, &in_2, 2, FALSE, -1);
442   nes_read_input_device(space->machine, cfg >> 12, &in_3, 3, FALSE, -1);
415   nes_read_input_device(space->machine, cfg >>  0, &state->in_0, 0,  TRUE, -1);
416   nes_read_input_device(space->machine, cfg >>  4, &state->in_1, 1,  TRUE,  1);
417   nes_read_input_device(space->machine, cfg >>  8, &state->in_2, 2, FALSE, -1);
418   nes_read_input_device(space->machine, cfg >> 12, &state->in_3, 3, FALSE, -1);
443419
444420   if (cfg & 0x0f00)
445      in_0.i0 |= (in_2.i0 << 8) | (0x08 << 16);
421      state->in_0.i0 |= (state->in_2.i0 << 8) | (0x08 << 16);
446422   if (cfg & 0xf000)
447      in_1.i0 |= (in_3.i0 << 8) | (0x04 << 16);
423      state->in_1.i0 |= (state->in_3.i0 << 8) | (0x04 << 16);
448424}
449425
450426
r7953r7954
638614      /* Attempt to load a battery file for this ROM. If successful, we */
639615      /* must wait until later to move it to the system memory. */
640616      if (state->battery)
641         image_battery_load(image, battery_data, BATTERY_SIZE, 0x00);
617         image_battery_load(image, state->battery_data, NES_BATTERY_SIZE, 0x00);
642618
643619   }
644620   else if ((magic[0] == 'U') && (magic[1] == 'N') && (magic[2] == 'I') && (magic[3] == 'F')) /* If header starts with 'UNIF' it is UNIF */
src/mess/machine/nes_mmc.c
r7953r7954
356356   if (mmc_write_mid)
357357      (*mmc_write_mid)(space, offset, data);
358358   else if (state->mid_ram_enable)
359      nes_battery_ram[offset] = data;
359      state->battery_ram[offset] = data;
360360   else
361361   {
362362      logerror("Unimplemented MID mapper write, offset: %04x, data: %02x\n", offset, data);
r7953r7954
375375   nes_state *state = (nes_state *)space->machine->driver_data;
376376
377377   if ((state->mid_ram_enable) || (state->mapper == 5))
378      return nes_battery_ram[offset];
378      return state->battery_ram[offset];
379379   else
380380      return 0;
381381}
src/mess/machine/nes_ines.c
r7953r7954
507507         LOG_MMC(("MMC5 mid RAM bank select: %02x\n", data & 0x07));
508508         memory_set_bankptr(space->machine, "bank5", &state->wram[data * 0x2000]);
509509         /* The & 4 is a hack that'll tide us over for now */
510         nes_battery_ram = &state->wram[(data & 4) * 0x2000];
510         state->battery_ram = &state->wram[(data & 4) * 0x2000];
511511         break;
512512
513513      case 0x1014: /* $5114 */
r7953r7954
623623               vrom_bank[0] = data;
624624//                  mapper5_sync_vrom(0);
625625               chr1_0(space->machine, vrom_bank[0], CHRROM);
626//                  nes_vram_sprite[0] = vrom_bank[0] * 64;
626//                  state->nes_vram_sprite[0] = vrom_bank[0] * 64;
627627//                  vrom_next[0] = 4;
628628//                  vrom_page_a = 1;
629629//                  vrom_page_b = 0;
r7953r7954
643643               vrom_bank[1] = data;
644644//                  mapper5_sync_vrom(0);
645645               chr1_1(space->machine, vrom_bank[1], CHRROM);
646//                  nes_vram_sprite[1] = vrom_bank[0] * 64;
646//                  state->nes_vram_sprite[1] = vrom_bank[0] * 64;
647647//                  vrom_next[1] = 5;
648648//                  vrom_page_a = 1;
649649//                  vrom_page_b = 0;
r7953r7954
659659               vrom_bank[2] = data;
660660//                  mapper5_sync_vrom(0);
661661               chr1_2(space->machine, vrom_bank[2], CHRROM);
662//                  nes_vram_sprite[2] = vrom_bank[0] * 64;
662//                  state->nes_vram_sprite[2] = vrom_bank[0] * 64;
663663//                  vrom_next[2] = 6;
664664//                  vrom_page_a = 1;
665665//                  vrom_page_b = 0;
r7953r7954
682682               vrom_bank[3] = data;
683683//                  mapper5_sync_vrom(0);
684684               chr1_3(space->machine, vrom_bank[3], CHRROM);
685//                  nes_vram_sprite[3] = vrom_bank[0] * 64;
685//                  state->nes_vram_sprite[3] = vrom_bank[0] * 64;
686686//                  vrom_next[3] = 7;
687687//                  vrom_page_a = 1;
688688//                  vrom_page_b = 0;
r7953r7954
698698               vrom_bank[4] = data;
699699//                  mapper5_sync_vrom(0);
700700               chr1_4(space->machine, vrom_bank[4], CHRROM);
701//                  nes_vram_sprite[4] = vrom_bank[0] * 64;
701//                  state->nes_vram_sprite[4] = vrom_bank[0] * 64;
702702//                  vrom_next[0] = 0;
703703//                  vrom_page_a = 0;
704704//                  vrom_page_b = 0;
r7953r7954
718718               vrom_bank[5] = data;
719719//                  mapper5_sync_vrom(0);
720720               chr1_5(space->machine, vrom_bank[5], CHRROM);
721//                  nes_vram_sprite[5] = vrom_bank[0] * 64;
721//                  state->nes_vram_sprite[5] = vrom_bank[0] * 64;
722722//                  vrom_next[1] = 1;
723723//                  vrom_page_a = 0;
724724//                  vrom_page_b = 0;
r7953r7954
734734               vrom_bank[6] = data;
735735//                  mapper5_sync_vrom(0);
736736               chr1_6(space->machine, vrom_bank[6], CHRROM);
737//                  nes_vram_sprite[6] = vrom_bank[0] * 64;
737//                  state->nes_vram_sprite[6] = vrom_bank[0] * 64;
738738//                  vrom_next[2] = 2;
739739//                  vrom_page_a = 0;
740740//                  vrom_page_b = 0;
r7953r7954
762762               vrom_bank[7] = data;
763763//                  mapper5_sync_vrom(0);
764764               chr1_7(space->machine, vrom_bank[7], CHRROM);
765//                  nes_vram_sprite[7] = vrom_bank[0] * 64;
765//                  state->nes_vram_sprite[7] = vrom_bank[0] * 64;
766766//                  vrom_next[3] = 3;
767767//                  vrom_page_a = 0;
768768//                  vrom_page_b = 0;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team