Previous 15994 Revisions Next

r14139 Monday 23rd January, 2012 at 12:29:16 UTC by Fabio Priuli
ppu2c0x: converted NES PPU to be a modern device. [Fabio Priuli]
[src/mame/video]ppu2c0x.c ppu2c0x.h
[src/mess/drivers]nes.c
[src/mess/includes]nes.h
[src/mess/machine]nes.c nes_pcb.c
[src/mess/video]nes.c

src/mame/video/ppu2c0x.c
r14138r14139
2323
2424******************************************************************************/
2525
26#define ADDRESS_MAP_MODERN
2627#include "emu.h"
2728#include "profiler.h"
2829#include "video/ppu2c0x.h"
r14138r14139
6768   0,29,30,31,
6869};
6970
71//**************************************************************************
72//  GLOBAL VARIABLES
73//**************************************************************************
7074
71/***************************************************************************
72    TYPE DEFINITIONS
73***************************************************************************/
75// devices
76const device_type PPU_2C02 = &device_creator<ppu2c02_device>;
77const device_type PPU_2C03B = &device_creator<ppu2c03b_device>;
78const device_type PPU_2C04 = &device_creator<ppu2c04_device>;
79const device_type PPU_2C07 = &device_creator<ppu2c07_device>;
80const device_type PPU_2C05_01 = &device_creator<ppu2c05_01_device>;
81const device_type PPU_2C05_02 = &device_creator<ppu2c05_02_device>;
82const device_type PPU_2C05_03 = &device_creator<ppu2c05_03_device>;
83const device_type PPU_2C05_04 = &device_creator<ppu2c05_04_device>;
7484
7585
76typedef struct _ppu2c0x_state  ppu2c0x_state;
77struct _ppu2c0x_state
86// default address map
87static ADDRESS_MAP_START( ppu2c0x, AS_0, 8, ppu2c0x_device )
88   AM_RANGE(0x0000, 0x3eff) AM_RAM
89   AM_RANGE(0x3f00, 0x3fff) AM_READWRITE(palette_read, palette_write)
90//   AM_RANGE(0x0000, 0x3fff) AM_RAM
91ADDRESS_MAP_END
92
93//-------------------------------------------------
94//  memory_space_config - return a description of
95//  any address spaces owned by this device
96//-------------------------------------------------
97
98const address_space_config *ppu2c0x_device::memory_space_config(address_spacenum spacenum) const
7899{
79   address_space            *space;               /* memory space */
80   bitmap_ind16         *bitmap;         /* target bitmap */
81   UINT8                       *spriteram;         /* sprite ram */
82   pen_t                       *colortable;         /* color table modified at run time */
83   pen_t                       *colortable_mono;      /* monochromatic color table modified at run time */
84   emu_timer                   *scanline_timer;      /* scanline timer */
85   emu_timer                   *hblank_timer;      /* hblank period at end of each scanline */
86   emu_timer                   *nmi_timer;         /* NMI timer */
87   int                         scanline;         /* scanline count */
88   ppu2c0x_scanline_cb         scanline_callback_proc;   /* optional scanline callback */
89   ppu2c0x_hblank_cb           hblank_callback_proc;   /* optional hblank callback */
90   ppu2c0x_vidaccess_cb        vidaccess_callback_proc;   /* optional video access callback */
91   ppu2c0x_nmi_cb              nmi_callback_proc;      /* nmi access callback from interface */
92   int                         regs[PPU_MAX_REG];      /* registers */
93   int                         refresh_data;         /* refresh-related */
94   int                         refresh_latch;      /* refresh-related */
95   int                         x_fine;            /* refresh-related */
96   int                         toggle;            /* used to latch hi-lo scroll */
97   int                         add;            /* vram increment amount */
98   int                         videomem_addr;      /* videomem address pointer */
99   int                         addr_latch;         /* videomem address latch */
100   int                         data_latch;         /* latched videomem data */
101   int                         buffered_data;
102   int                         tile_page;         /* current tile page */
103   int                         sprite_page;         /* current sprite page */
104   int                         back_color;         /* background color */
105   int                         color_base;
106   UINT8                       palette_ram[0x20];      /* shouldn't be in main memory! */
107   int                         scan_scale;         /* scan scale */
108   int                         scanlines_per_frame;   /* number of scanlines per frame */
109   rgb_t                       palette[64*4];      /* palette for this chip */
110   int                         security_value;      /* 2C05 protection */
111   void (*latch)( device_t *device, offs_t offset );
112};
100   return (spacenum == AS_0) ? &m_space_config : NULL;
101}
113102
114103
115/***************************************************************************
116    PROTOTYPES
117***************************************************************************/
104//-------------------------------------------------
105//  ppu2c0x_device - constructor
106//-------------------------------------------------
118107
119static void update_scanline( device_t *device );
108void ppu2c0x_device::device_config_complete()
109{
110   const ppu2c0x_interface *config = reinterpret_cast<const ppu2c0x_interface *>(static_config());
111   assert(config);
112   
113   /* reset the callbacks */
114   m_latch = NULL;
115   m_scanline_callback_proc = NULL;
116   m_hblank_callback_proc = NULL;
117   m_vidaccess_callback_proc = NULL;
120118
121static TIMER_CALLBACK( scanline_callback );
122static TIMER_CALLBACK( hblank_callback );
123static TIMER_CALLBACK( nmi_callback );
119   m_nmi_callback_proc = config->nmi_handler;
120   m_color_base = config->color_base;
124121
122   m_cpu_tag = config->cpu_tag;
123   m_screen_tag = config->screen_tag;
124}
125125
126/* palette handlers */
127static WRITE8_HANDLER( ppu2c0x_palette_write );
128static READ8_HANDLER( ppu2c0x_palette_read );
126ppu2c0x_device::ppu2c0x_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock)
127            : device_t(mconfig, type, name, tag, owner, clock),
128              device_memory_interface(mconfig, *this),
129              m_space_config("videoram", ENDIANNESS_LITTLE, 8, 17, 0, NULL, *ADDRESS_MAP_NAME(ppu2c0x)),
130              m_scanline(0),   // reset the scanline count
131              m_refresh_data(0),
132              m_refresh_latch(0),
133              m_x_fine(0),
134              m_toggle(0),
135              m_add(1),
136              m_videomem_addr(0),
137              m_data_latch(0),
138              m_buffered_data(0),
139              m_tile_page(0),
140              m_sprite_page(0),
141              m_back_color(0),
142              m_scan_scale(1)   // set the scan scale (this is for dual monitor vertical setups)
143{
144   for (int i = 0; i < PPU_MAX_REG; i++)
145      m_regs[i] = 0;
146   
147   memset(m_palette_ram, 0, ARRAY_LENGTH(m_palette_ram));
148   
149   m_scanlines_per_frame = PPU_NTSC_SCANLINES_PER_FRAME;
150   
151   /* usually, no security value... */
152   m_security_value = 0;
153}
129154
130155
131/***************************************************************************
132    INLINE FUNCTIONS
133***************************************************************************/
156// NTSC NES
157ppu2c02_device::ppu2c02_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : ppu2c0x_device(mconfig, PPU_2C02, "2C02 PPU", tag, owner, clock)
158{
159}
134160
135INLINE ppu2c0x_state *get_token( device_t *device )
161// Playchoice 10
162ppu2c03b_device::ppu2c03b_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : ppu2c0x_device(mconfig, PPU_2C03B, "2C03B PPU PPU", tag, owner, clock)
136163{
137   assert(device != NULL);
138   assert((device->type() == PPU_2C02) || (device->type() == PPU_2C03B)
139       || (device->type() == PPU_2C04) || (device->type() == PPU_2C05_01)
140       || (device->type() == PPU_2C05_02) || (device->type() == PPU_2C05_03)
141       || (device->type() == PPU_2C05_04) || (device->type() == PPU_2C07));
142   return (ppu2c0x_state *) downcast<legacy_device_base *>(device)->token();
143164}
144165
166// Vs. Unisystem
167ppu2c04_device::ppu2c04_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : ppu2c0x_device(mconfig, PPU_2C04, "2C04 PPU", tag, owner, clock)
168{
169}
145170
146INLINE const ppu2c0x_interface *get_interface( device_t *device )
171// PAL NES
172ppu2c07_device::ppu2c07_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : ppu2c0x_device(mconfig, PPU_2C07, "2C07 PPU", tag, owner, clock)
147173{
148   assert(device != NULL);
149   assert((device->type() == PPU_2C02) || (device->type() == PPU_2C03B)
150       || (device->type() == PPU_2C04) || (device->type() == PPU_2C05_01)
151       || (device->type() == PPU_2C05_02) || (device->type() == PPU_2C05_03)
152       || (device->type() == PPU_2C05_04) || (device->type() == PPU_2C07));
153   return (const ppu2c0x_interface *) device->static_config();
174   m_scanlines_per_frame = PPU_PAL_SCANLINES_PER_FRAME;
154175}
155176
177// The PPU_2C05 variants have different protection value, set at DEVICE_START, but otherwise are all the same...
178// Vs. Unisystem (Ninja Jajamaru Kun)
179ppu2c05_01_device::ppu2c05_01_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : ppu2c0x_device(mconfig, PPU_2C05_01, "2C05 PPU", tag, owner, clock)
180{
181   m_security_value = 0x1b;   // game (jajamaru) doesn't seem to ever actually check it
182}
183// Vs. Unisystem (Mighty Bomb Jack)
184ppu2c05_02_device::ppu2c05_02_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : ppu2c0x_device(mconfig, PPU_2C05_02, "2C05 PPU", tag, owner, clock)
185{
186   m_security_value = 0x3d;
187}
188// Vs. Unisystem (Gumshoe)
189ppu2c05_03_device::ppu2c05_03_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : ppu2c0x_device(mconfig, PPU_2C05_03, "2C05 PPU", tag, owner, clock)
190{
191   m_security_value = 0x1c;
192}
193// Vs. Unisystem (Top Gun)
194ppu2c05_04_device::ppu2c05_04_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : ppu2c0x_device(mconfig, PPU_2C05_04, "2C05 PPU", tag, owner, clock)
195{
196   m_security_value = 0x1b;
197}
156198
199
200//-------------------------------------------------
201//  device_start - device-specific startup
202//-------------------------------------------------
203
204void ppu2c0x_device::device_start()
205{
206   m_screen = machine().device<screen_device>( m_screen_tag );
207   m_cpu = machine().device<cpu_device>( m_cpu_tag );
208
209   assert(m_screen && m_cpu);
210   
211   // allocate timers
212   m_hblank_timer = timer_alloc(TIMER_HBLANK);
213   m_nmi_timer = timer_alloc(TIMER_NMI);
214   m_scanline_timer = timer_alloc(TIMER_SCANLINE);
215   
216   /* initialize the scanline handling portion */
217   m_scanline_timer->adjust(m_screen->time_until_pos(1));
218   m_hblank_timer->adjust(m_cpu->cycles_to_attotime(86.67)); // ??? FIXME - hardcoding NTSC, need better calculation
219   m_nmi_timer->adjust(attotime::never);
220
221   /* allocate a screen bitmap, videomem and spriteram, a dirtychar array and the monochromatic colortable */
222   m_bitmap = auto_bitmap_ind16_alloc(machine(), VISIBLE_SCREEN_WIDTH, VISIBLE_SCREEN_HEIGHT);
223   m_spriteram = auto_alloc_array_clear(machine(), UINT8, SPRITERAM_SIZE);
224   m_colortable = auto_alloc_array(machine(), pen_t, ARRAY_LENGTH(default_colortable));
225   m_colortable_mono = auto_alloc_array(machine(), pen_t, ARRAY_LENGTH(default_colortable_mono));
226
227   /* initialize the color tables */
228   for (int i = 0; i < ARRAY_LENGTH(default_colortable_mono); i++)
229   {
230      /* monochromatic table */
231      m_colortable_mono[i] = default_colortable_mono[i] + m_color_base;
232     
233      /* color table */
234      m_colortable[i] = default_colortable[i] + m_color_base;
235   }
236
237   // register for state saving
238   save_item(NAME(m_scanline));
239   save_item(NAME(m_refresh_data));
240   save_item(NAME(m_refresh_latch));
241   save_item(NAME(m_x_fine));
242   save_item(NAME(m_toggle));
243   save_item(NAME(m_add));
244   save_item(NAME(m_videomem_addr));
245   save_item(NAME(m_data_latch));
246   save_item(NAME(m_buffered_data));
247   save_item(NAME(m_tile_page));
248   save_item(NAME(m_sprite_page));
249   save_item(NAME(m_back_color));
250   save_item(NAME(m_scan_scale));
251   save_item(NAME(m_scanlines_per_frame));
252   save_item(NAME(m_regs));
253   save_item(NAME(m_palette_ram));
254   save_pointer(NAME(m_spriteram), SPRITERAM_SIZE);
255   save_pointer(NAME(m_colortable), ARRAY_LENGTH(default_colortable));
256   save_pointer(NAME(m_colortable_mono), ARRAY_LENGTH(default_colortable_mono));
257   save_item(NAME(*m_bitmap));
258}
259
260//**************************************************************************
261//  INLINE HELPERS
262//**************************************************************************
263
264//-------------------------------------------------
265//  readbyte - read a byte at the given address
266//-------------------------------------------------
267
268inline UINT8 ppu2c0x_device::readbyte(offs_t address)
269{
270   return space()->read_byte(address);
271}
272
273
274//-------------------------------------------------
275//  writebyte - write a byte at the given address
276//-------------------------------------------------
277
278inline void ppu2c0x_device::writebyte(offs_t address, UINT8 data)
279{
280   space()->write_byte(address, data);
281}
282
283
157284/***************************************************************************
158285    IMPLEMENTATION
159286***************************************************************************/
r14138r14139
164291 *
165292 *************************************/
166293
167/* default address map */
168// make this INTERNAL, default should just be enough to avoid compile errors, print error messages!
169static ADDRESS_MAP_START( ppu2c0x, AS_0, 8 )
170   AM_RANGE(0x3f00, 0x3fff) AM_READWRITE(ppu2c0x_palette_read, ppu2c0x_palette_write)
171ADDRESS_MAP_END
172
173void ppu2c0x_init_palette( running_machine &machine, int first_entry )
294void ppu2c0x_device::init_palette( running_machine &machine, int first_entry )
174295{
175296
176297   /* This routine builds a palette using a transformation from */
r14138r14139
285406   /* color tables are modified at run-time, and are initialized on 'ppu2c0x_reset' */
286407}
287408
288void ppu2c0x_init_palette_rgb( running_machine &machine, int first_entry )
409void ppu2c0x_device::init_palette_rgb( running_machine &machine, int first_entry )
289410{
290411   int color_emphasis, color_num;
291412
r14138r14139
327448 *
328449 *************************************/
329450
330void ppu2c0x_set_latch( device_t *device, void (*latch)(device_t *device, offs_t offset))
451void ppu2c0x_device::set_latch( void (*latch)(device_t *device, offs_t offset) )
331452{
332   ppu2c0x_state *ppu2c0x = get_token(device);
333   ppu2c0x->latch = latch;
453   if (latch)
454      m_latch = latch;
334455}
335456
336static TIMER_CALLBACK( hblank_callback )
337{
338   device_t *device = (device_t *)ptr;
339   ppu2c0x_state *ppu2c0x = get_token(device);
340   int *ppu_regs = &ppu2c0x->regs[0];
457//-------------------------------------------------
458//  device_timer - handle timer events
459//-------------------------------------------------
341460
342   int blanked = (ppu_regs[PPU_CONTROL1] & (PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES)) == 0;
343   int vblank = ((ppu2c0x->scanline >= PPU_VBLANK_FIRST_SCANLINE - 1) && (ppu2c0x->scanline < ppu2c0x->scanlines_per_frame - 1)) ? 1 : 0;
344
345//  update_scanline(device);
346
347   if (ppu2c0x->hblank_callback_proc)
348      (*ppu2c0x->hblank_callback_proc) (device, ppu2c0x->scanline, vblank, blanked);
349
350   ppu2c0x->hblank_timer->adjust(attotime::never);
351}
352
353static TIMER_CALLBACK( nmi_callback )
461void ppu2c0x_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
354462{
355   device_t *device = (device_t *)ptr;
356   ppu2c0x_state *ppu2c0x = get_token(device);
357   int *ppu_regs = &ppu2c0x->regs[0];
463   int blanked, vblank;
464   int *regs = &m_regs[0];
358465
359   // Actually fire the VMI
360   if (ppu2c0x->nmi_callback_proc != NULL)
361      (*ppu2c0x->nmi_callback_proc) (device, ppu_regs);
362
363   ppu2c0x->nmi_timer->adjust(attotime::never);
466   switch (id)
467   {
468      case TIMER_HBLANK:
469         blanked = (m_regs[PPU_CONTROL1] & (PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES)) == 0;
470         vblank = ((m_scanline >= PPU_VBLANK_FIRST_SCANLINE - 1) && (m_scanline < m_scanlines_per_frame - 1)) ? 1 : 0;
471         
472         //update_scanline();
473         
474         if (m_hblank_callback_proc)
475            (*m_hblank_callback_proc) (this, m_scanline, vblank, blanked);
476         
477         m_hblank_timer->adjust(attotime::never);
478         break;
479         
480      case TIMER_NMI:         
481         // Actually fire the VMI
482         if (m_nmi_callback_proc)
483            (*m_nmi_callback_proc) (this, regs);
484         
485         m_nmi_timer->adjust(attotime::never);
486         break;
487         
488      case TIMER_SCANLINE:
489         blanked = (m_regs[PPU_CONTROL1] & (PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES)) == 0;
490         vblank = ((m_scanline >= PPU_VBLANK_FIRST_SCANLINE - 1) && (m_scanline < m_scanlines_per_frame - 1)) ? 1 : 0;
491         int next_scanline;
492         
493         /* if a callback is available, call it */
494         if (m_scanline_callback_proc)
495            (*m_scanline_callback_proc)(this, m_scanline, vblank, blanked);
496         
497         /* update the scanline that just went by */
498         update_scanline();
499         
500         /* increment our scanline count */
501         m_scanline++;
502         
503         //  logerror("starting scanline %d (MAME %d, beam %d)\n", m_scanline, device->machine().primary_screen->vpos(), device->machine().primary_screen->hpos());
504         
505         /* Note: this is called at the _end_ of each scanline */
506         if (m_scanline == PPU_VBLANK_FIRST_SCANLINE)
507         {
508            // logerror("vblank starting\n");
509            /* We just entered VBLANK */
510            m_regs[PPU_STATUS] |= PPU_STATUS_VBLANK;
511           
512            /* If NMI's are set to be triggered, go for it */
513            if (m_regs[PPU_CONTROL0] & PPU_CONTROL0_NMI)
514            {
515               // We need an ever-so-slight delay between entering vblank and firing an NMI - enough so that
516               // a game can read the high bit of $2002 before the NMI is called (potentially resetting the bit
517               // via a read from $2002 in the NMI handler).
518               // B-Wings is an example game that needs this.
519               m_nmi_timer->adjust(m_cpu->cycles_to_attotime(4));
520            }
521         }
522         
523         if (m_scanline == m_scanlines_per_frame - 1)
524         {
525            // logerror("vblank ending\n");
526            /* clear the vblank & sprite hit flag */
527            m_regs[PPU_STATUS] &= ~(PPU_STATUS_VBLANK | PPU_STATUS_SPRITE0_HIT | PPU_STATUS_8SPRITES);
528         }
529         
530         /* see if we rolled */
531         else if (m_scanline == m_scanlines_per_frame)
532         {
533            /* if background or sprites are enabled, copy the ppu address latch */
534            if (!blanked)
535               m_refresh_data = m_refresh_latch;
536           
537            /* reset the scanline count */
538            m_scanline = 0;
539            //logerror("sprite 0 x: %d y: %d num: %d\n", m_spriteram[3], m_spriteram[0] + 1, m_spriteram[1]);
540         }
541         
542         next_scanline = m_scanline + 1;
543         if (next_scanline == m_scanlines_per_frame)
544            next_scanline = 0;
545         
546         // Call us back when the hblank starts for this scanline
547         m_hblank_timer->adjust(m_cpu->cycles_to_attotime(86.67)); // ??? FIXME - hardcoding NTSC, need better calculation
548         
549         // trigger again at the start of the next scanline
550         m_scanline_timer->adjust(m_screen->time_until_pos(next_scanline * m_scan_scale));
551         break;
552   }
364553}
365554
366static void draw_background( device_t *device, UINT8 *line_priority )
555void ppu2c0x_device::draw_background( UINT8 *line_priority )
367556{
368   ppu2c0x_state *ppu2c0x = get_token(device);
369
370   /* cache some values locally */
371   bitmap_ind16 &bitmap = *ppu2c0x->bitmap;
372   const int *ppu_regs = &ppu2c0x->regs[0];
373   const int scanline = ppu2c0x->scanline;
374   const int refresh_data = ppu2c0x->refresh_data;
375   const int tile_page = ppu2c0x->tile_page;
376
377   int   start_x = (ppu2c0x->x_fine ^ 0x07) - 7;
557   bitmap_ind16 &bitmap = *m_bitmap;
558   int   start_x = (m_x_fine ^ 0x07) - 7;
378559   UINT16 back_pen;
379560   UINT16 *dest;
380561
r14138r14139
387568   int tilecount = 0;
388569
389570   /* setup the color mask and colortable to use */
390   if (ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO)
571   if (m_regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO)
391572   {
392573      color_mask = 0xf0;
393      color_table = ppu2c0x->colortable_mono;
574      color_table = m_colortable_mono;
394575   }
395576   else
396577   {
397578      color_mask = 0xff;
398      color_table = ppu2c0x->colortable;
579      color_table = m_colortable;
399580   }
400581
401582   /* cache the background pen */
402   back_pen = (ppu2c0x->back_color & color_mask) + ppu2c0x->color_base;
583   back_pen = (m_back_color & color_mask) + m_color_base;
403584
404585   /* determine where in the nametable to start drawing from */
405586   /* based on the current scanline and scroll regs */
406   scroll_x_coarse = refresh_data & 0x1f;
407   scroll_y_coarse = (refresh_data & 0x3e0) >> 5;
408   scroll_y_fine = (refresh_data & 0x7000) >> 12;
587   scroll_x_coarse =  m_refresh_data & 0x1f;
588   scroll_y_coarse = (m_refresh_data & 0x3e0) >> 5;
589   scroll_y_fine   = (m_refresh_data & 0x7000) >> 12;
409590
410591   x = scroll_x_coarse;
411592
412593   /* get the tile index */
413   tile_index = ((refresh_data & 0xc00) | 0x2000) + scroll_y_coarse * 32;
594   tile_index = ((m_refresh_data & 0xc00) | 0x2000) + scroll_y_coarse * 32;
414595
415596   /* set up dest */
416   dest = &bitmap.pix16(scanline, start_x);
597   dest = &bitmap.pix16(m_scanline, start_x);
417598
418599   /* draw the 32 or 33 tiles that make up a line */
419600   while (tilecount < 34)
r14138r14139
432613      pos = ((index1 & 0x380) >> 4) | ((index1 & 0x1f) >> 2);
433614      page = (index1 & 0x0c00) >> 10;
434615      address = 0x3c0 + pos;
435      color_byte = ppu2c0x->space->read_byte((((page * 0x400) + address) & 0xfff) + 0x2000);
616      color_byte = readbyte((((page * 0x400) + address) & 0xfff) + 0x2000);
436617
437618      /* figure out which bits in the color table to use */
438619      color_bits = ((index1 & 0x40) >> 4) + (index1 & 0x02);
439620
440621      // page2 is the output of the nametable read (this section is the FIRST read per tile!)
441622      address = index1 & 0x3ff;
442      page2 = ppu2c0x->space->read_byte(index1);
623      page2 = readbyte(index1);
443624
444625      // 27/12/2002
445      if (ppu2c0x->latch)
446      {
447         (*ppu2c0x->latch)(device, (tile_page << 10) | (page2 << 4));
448      }
626      if (m_latch)
627         (*m_latch)(this, (m_tile_page << 10) | (page2 << 4));
449628
450629      if (start_x < VISIBLE_SCREEN_WIDTH)
451630      {
r14138r14139
453632         paldata = &color_table[4 * (((color_byte >> color_bits) & 0x03))];
454633
455634         // need to read 0x0000 or 0x1000 + 16*nametable data
456         address = ((ppu2c0x->tile_page) ? 0x1000 : 0) + (page2 * 16);
635         address = ((m_tile_page) ? 0x1000 : 0) + (page2 * 16);
457636         // plus something that accounts for y
458637         address += scroll_y_fine;
459638
460         plane1 = ppu2c0x->space->read_byte((address & 0x1fff));
461         plane2 = ppu2c0x->space->read_byte((address + 8) & 0x1fff);
639         plane1 = readbyte((address & 0x1fff));
640         plane2 = readbyte((address + 8) & 0x1fff);
462641
463642         /* render the pixel */
464643         for (i = 0; i < 8; i++)
r14138r14139
498677   }
499678
500679   /* if the left 8 pixels for the background are off, blank 'em */
501   if (!(ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_BACKGROUND_L8))
680   if (!(m_regs[PPU_CONTROL1] & PPU_CONTROL1_BACKGROUND_L8))
502681   {
503      dest = &bitmap.pix16(scanline);
682      dest = &bitmap.pix16(m_scanline);
504683      for (i = 0; i < 8; i++)
505684      {
506685         *(dest++) = back_pen;
r14138r14139
509688   }
510689}
511690
512static void draw_sprites( device_t *device, UINT8 *line_priority )
691void ppu2c0x_device::draw_sprites( UINT8 *line_priority )
513692{
514   ppu2c0x_state *ppu2c0x = get_token(device);
693   bitmap_ind16 &bitmap = *m_bitmap;
515694
516   /* cache some values locally */
517   bitmap_ind16 &bitmap = *ppu2c0x->bitmap;
518   const int scanline = ppu2c0x->scanline;
519   const int sprite_page = ppu2c0x->sprite_page;
520   const UINT8 *sprite_ram = ppu2c0x->spriteram;
521   pen_t *color_table = ppu2c0x->colortable;
522   int *ppu_regs = &ppu2c0x->regs[0];
523
524695   int sprite_xpos, sprite_ypos, sprite_index;
525696   int tile, index1;
526697   int pri;
r14138r14139
536707   int pixel;
537708
538709   /* determine if the sprites are 8x8 or 8x16 */
539   size = (ppu_regs[PPU_CONTROL0] & PPU_CONTROL0_SPRITE_SIZE) ? 16 : 8;
710   size = (m_regs[PPU_CONTROL0] & PPU_CONTROL0_SPRITE_SIZE) ? 16 : 8;
540711
541   first_pixel = (ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_SPRITES_L8)? 0: 8;
712   first_pixel = (m_regs[PPU_CONTROL1] & PPU_CONTROL1_SPRITES_L8)? 0: 8;
542713
543714   for (sprite_index = 0; sprite_index < SPRITERAM_SIZE; sprite_index += 4)
544715   {
545716      UINT8 plane1;
546717      UINT8 plane2;
547718
548      sprite_ypos = sprite_ram[sprite_index] + 1;
549      sprite_xpos = sprite_ram[sprite_index + 3];
719      sprite_ypos = m_spriteram[sprite_index] + 1;
720      sprite_xpos = m_spriteram[sprite_index + 3];
550721
551722      // The sprite collision acts funny on the last pixel of a scanline.
552723      // The various scanline latches update while the last few pixels
r14138r14139
560731         sprite_ypos--;
561732         /* set the "sprite 0 hit" flag if appropriate */
562733         if (line_priority[sprite_xpos] & 0x02)
563            ppu_regs[PPU_STATUS] |= PPU_STATUS_SPRITE0_HIT;
734            m_regs[PPU_STATUS] |= PPU_STATUS_SPRITE0_HIT;
564735      }
565736
566737      /* if the sprite isn't visible, skip it */
567      if ((sprite_ypos + size <= scanline) || (sprite_ypos > scanline))
738      if ((sprite_ypos + size <= m_scanline) || (sprite_ypos > m_scanline))
568739         continue;
569740
570      tile  =  sprite_ram[sprite_index + 1];
571      color = (sprite_ram[sprite_index + 2] & 0x03) + 4;
572      pri   =  sprite_ram[sprite_index + 2] & 0x20;
573      flipx =  sprite_ram[sprite_index + 2] & 0x40;
574      flipy =  sprite_ram[sprite_index + 2] & 0x80;
741      tile  =  m_spriteram[sprite_index + 1];
742      color = (m_spriteram[sprite_index + 2] & 0x03) + 4;
743      pri   =  m_spriteram[sprite_index + 2] & 0x20;
744      flipx =  m_spriteram[sprite_index + 2] & 0x40;
745      flipy =  m_spriteram[sprite_index + 2] & 0x80;
575746
576747      if (size == 16)
577748      {
r14138r14139
583754         }
584755      }
585756
586      if (ppu2c0x->latch)
587         (*ppu2c0x->latch)(device, (sprite_page << 10) | ((tile & 0xff) << 4));
757      if (m_latch)
758         (*m_latch)(this, (m_sprite_page << 10) | ((tile & 0xff) << 4));
588759
589760      /* compute the character's line to draw */
590      sprite_line = scanline - sprite_ypos;
761      sprite_line = m_scanline - sprite_ypos;
591762
592763      if (flipy)
593764         sprite_line = (size - 1) - sprite_line;
594765
595      paldata = &color_table[4 * color];
766      paldata = &m_colortable[4 * color];
596767
597768      if (size == 16 && sprite_line > 7)
598769      {
r14138r14139
602773
603774      index1 = tile * 16;
604775      if (size == 8)
605         index1 += ((sprite_page == 0) ? 0 : 0x1000);
776         index1 += ((m_sprite_page == 0) ? 0 : 0x1000);
606777
607      plane1 = ppu2c0x->space->read_byte((index1 + sprite_line + 0) & 0x1fff);
608      plane2 = ppu2c0x->space->read_byte((index1 + sprite_line + 8) & 0x1fff);
778      plane1 = readbyte((index1 + sprite_line + 0) & 0x1fff);
779      plane2 = readbyte((index1 + sprite_line + 8) & 0x1fff);
609780
610781      /* if there are more than 8 sprites on this line, set the flag */
611782      if (sprite_count == 8)
612783      {
613         ppu_regs[PPU_STATUS] |= PPU_STATUS_8SPRITES;
614//          logerror ("> 8 sprites, scanline: %d\n", scanline);
784         m_regs[PPU_STATUS] |= PPU_STATUS_8SPRITES;
785//          logerror ("> 8 sprites, scanline: %d\n", m_scanline);
615786
616787         /* the real NES only draws up to 8 sprites - the rest should be invisible */
617788         break;
r14138r14139
620791      sprite_count++;
621792
622793      /* abort drawing if sprites aren't rendered */
623      if (!(ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_SPRITES))
794      if (!(m_regs[PPU_CONTROL1] & PPU_CONTROL1_SPRITES))
624795         continue;
625796
626797      if (pri)
r14138r14139
652823                  {
653824                     /* no, draw */
654825                     if ((sprite_xpos + pixel) < VISIBLE_SCREEN_WIDTH)
655                        bitmap.pix16(scanline, sprite_xpos + pixel) = paldata[pixel_data];
826                        bitmap.pix16(m_scanline, sprite_xpos + pixel) = paldata[pixel_data];
656827                  }
657828                  /* indicate that a sprite was drawn at this location, even if it's not seen */
658829                  if ((sprite_xpos + pixel) < VISIBLE_SCREEN_WIDTH)
r14138r14139
661832
662833               /* set the "sprite 0 hit" flag if appropriate */
663834               if (sprite_index == 0 && (pixel_data & 0x03) && ((sprite_xpos + pixel) < 255) && (line_priority[sprite_xpos + pixel] & 0x02))
664                  ppu_regs[PPU_STATUS] |= PPU_STATUS_SPRITE0_HIT;
835                  m_regs[PPU_STATUS] |= PPU_STATUS_SPRITE0_HIT;
665836            }
666837         }
667838      }
r14138r14139
695866                     /* no, draw */
696867                     if ((sprite_xpos + pixel) < VISIBLE_SCREEN_WIDTH)
697868                     {
698                        bitmap.pix16(scanline, sprite_xpos + pixel) = paldata[pixel_data];
869                        bitmap.pix16(m_scanline, sprite_xpos + pixel) = paldata[pixel_data];
699870                        line_priority[sprite_xpos + pixel] |= 0x01;
700871                     }
701872                  }
r14138r14139
703874
704875               /* set the "sprite 0 hit" flag if appropriate */
705876               if (sprite_index == 0 && (pixel_data & 0x03) && ((sprite_xpos + pixel) < 255) && (line_priority[sprite_xpos + pixel] & 0x02))
706                  ppu_regs[PPU_STATUS] |= PPU_STATUS_SPRITE0_HIT;
877                  m_regs[PPU_STATUS] |= PPU_STATUS_SPRITE0_HIT;
707878            }
708879         }
709880      }
r14138r14139
716887 *
717888 *************************************/
718889
719static void render_scanline( device_t *device )
890void ppu2c0x_device::render_scanline( void )
720891{
721   ppu2c0x_state *ppu2c0x = get_token(device);
722892   UINT8 line_priority[VISIBLE_SCREEN_WIDTH];
723   int *ppu_regs = &ppu2c0x->regs[0];
724893
725894   /* lets see how long it takes */
726895   g_profiler.start(PROFILER_USER1);
r14138r14139
729898   memset(line_priority, 0, VISIBLE_SCREEN_WIDTH);
730899
731900   /* see if we need to render the background */
732   if (ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_BACKGROUND)
733      draw_background(device, line_priority);
901   if (m_regs[PPU_CONTROL1] & PPU_CONTROL1_BACKGROUND)
902      draw_background(line_priority);
734903   else
735904   {
736      bitmap_ind16 &bitmap = *ppu2c0x->bitmap;
737      const int scanline = ppu2c0x->scanline;
905      bitmap_ind16 &bitmap = *m_bitmap;
738906      UINT8 color_mask;
739907      UINT16 back_pen;
740908      int i;
741909
742910      /* setup the color mask and colortable to use */
743      if (ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO)
911      if (m_regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO)
744912         color_mask = 0xf0;
745913      else
746914         color_mask = 0xff;
747915
748916      /* cache the background pen */
749      back_pen = (ppu2c0x->back_color & color_mask) + ppu2c0x->color_base;
917      back_pen = (m_back_color & color_mask) + m_color_base;
750918
751919      // Fill this scanline with the background pen.
752920      for (i = 0; i < bitmap.width(); i++)
753         bitmap.pix16(scanline, i) = back_pen;
921         bitmap.pix16(m_scanline, i) = back_pen;
754922   }
755923
756924   /* if sprites are on, draw them, but we call always to process them */
757   draw_sprites(device, line_priority);
925   draw_sprites(line_priority);
758926
759927   /* done updating, whew */
760928   g_profiler.stop();
761929}
762930
763static void update_scanline( device_t *device )
931void ppu2c0x_device::update_scanline( void )
764932{
765   ppu2c0x_state *ppu2c0x = get_token(device);
766   const int scanline = ppu2c0x->scanline;
767   int *ppu_regs = &ppu2c0x->regs[0];
768
769   if (scanline <= PPU_BOTTOM_VISIBLE_SCANLINE)
933   if (m_scanline <= PPU_BOTTOM_VISIBLE_SCANLINE)
770934   {
771935      /* Render this scanline if appropriate */
772      if (ppu_regs[PPU_CONTROL1] & (PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES))
936      if (m_regs[PPU_CONTROL1] & (PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES))
773937      {
774938         /* If background or sprites are enabled, copy the ppu address latch */
775939         /* Copy only the scroll x-coarse and the x-overflow bit */
776         ppu2c0x->refresh_data &= ~0x041f;
777         ppu2c0x->refresh_data |= (ppu2c0x->refresh_latch & 0x041f);
940         m_refresh_data &= ~0x041f;
941         m_refresh_data |= (m_refresh_latch & 0x041f);
778942
779//          logerror("updating refresh_data: %04x (scanline: %d)\n", ppu2c0x->refresh_data, ppu2c0x->scanline);
780         render_scanline(device);
943//          logerror("updating refresh_data: %04x (scanline: %d)\n", m_refresh_data, m_scanline);
944         render_scanline();
781945      }
782946      else
783947      {
784         bitmap_ind16 &bitmap = *ppu2c0x->bitmap;
948         bitmap_ind16 &bitmap = *m_bitmap;
785949         UINT8 color_mask;
786950         UINT16 back_pen;
787951         int i;
788952
789953         /* setup the color mask and colortable to use */
790         if (ppu_regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO)
954         if (m_regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO)
791955            color_mask = 0xf0;
792956         else
793957            color_mask = 0xff;
794958
795959         /* cache the background pen */
796         if (ppu2c0x->videomem_addr >= 0x3f00)
960         if (m_videomem_addr >= 0x3f00)
797961         {
798962            // If the PPU's VRAM address happens to point into palette ram space while
799963            // both the sprites and background are disabled, the PPU paints the scanline
r14138r14139
801965            // pen. Micro Machines makes use of this feature.
802966            int pen_num;
803967
804            if (ppu2c0x->videomem_addr & 0x03)
805               pen_num = ppu2c0x->palette_ram[ppu2c0x->videomem_addr & 0x1f];
968            if (m_videomem_addr & 0x03)
969               pen_num = m_palette_ram[m_videomem_addr & 0x1f];
806970            else
807               pen_num = ppu2c0x->palette_ram[0];
971               pen_num = m_palette_ram[0];
808972
809            back_pen = pen_num + ppu2c0x->color_base;
973            back_pen = pen_num + m_color_base;
810974         }
811975         else
812            back_pen = (ppu2c0x->back_color & color_mask) + ppu2c0x->color_base;
976            back_pen = (m_back_color & color_mask) + m_color_base;
813977
814978         // Fill this scanline with the background pen.
815979         for (i = 0; i < bitmap.width(); i++)
816            bitmap.pix16(scanline, i) = back_pen;
980            bitmap.pix16(m_scanline, i) = back_pen;
817981      }
818982
819983      /* increment the fine y-scroll */
820      ppu2c0x->refresh_data += 0x1000;
984      m_refresh_data += 0x1000;
821985
822986      /* if it's rolled, increment the coarse y-scroll */
823      if (ppu2c0x->refresh_data & 0x8000)
987      if (m_refresh_data & 0x8000)
824988      {
825989         UINT16 tmp;
826         tmp = (ppu2c0x->refresh_data & 0x03e0) + 0x20;
827         ppu2c0x->refresh_data &= 0x7c1f;
990         tmp = (m_refresh_data & 0x03e0) + 0x20;
991         m_refresh_data &= 0x7c1f;
828992
829993         /* handle bizarro scrolling rollover at the 30th (not 32nd) vertical tile */
830994         if (tmp == 0x03c0)
831            ppu2c0x->refresh_data ^= 0x0800;
995            m_refresh_data ^= 0x0800;
832996         else
833            ppu2c0x->refresh_data |= (tmp & 0x03e0);
997            m_refresh_data |= (tmp & 0x03e0);
834998
835//          logerror("updating refresh_data: %04x\n", ppu2c0x->refresh_data);
999//          logerror("updating refresh_data: %04x\n", m_refresh_data);
8361000      }
8371001   }
8381002
8391003}
8401004
841static TIMER_CALLBACK( scanline_callback )
842{
843   device_t *device = (device_t *)ptr;
844   ppu2c0x_state *ppu2c0x = get_token(device);
845   int *ppu_regs = &ppu2c0x->regs[0];
846   int blanked = (ppu_regs[PPU_CONTROL1] & (PPU_CONTROL1_BACKGROUND | PPU_CONTROL1_SPRITES)) == 0;
847   int vblank = ((ppu2c0x->scanline >= PPU_VBLANK_FIRST_SCANLINE - 1) && (ppu2c0x->scanline < ppu2c0x->scanlines_per_frame - 1)) ? 1 : 0;
848   int next_scanline;
849
850   /* if a callback is available, call it */
851   if (ppu2c0x->scanline_callback_proc != NULL)
852      (*ppu2c0x->scanline_callback_proc)(device, ppu2c0x->scanline, vblank, blanked);
853
854   /* update the scanline that just went by */
855   update_scanline(device);
856
857   /* increment our scanline count */
858   ppu2c0x->scanline++;
859
860//  logerror("starting scanline %d (MAME %d, beam %d)\n", ppu2c0x->scanline, device->machine().primary_screen->vpos(), device->machine().primary_screen->hpos());
861
862   /* Note: this is called at the _end_ of each scanline */
863   if (ppu2c0x->scanline == PPU_VBLANK_FIRST_SCANLINE)
864   {
865      // logerror("vblank starting\n");
866      /* We just entered VBLANK */
867      ppu_regs[PPU_STATUS] |= PPU_STATUS_VBLANK;
868
869      /* If NMI's are set to be triggered, go for it */
870      if (ppu_regs[PPU_CONTROL0] & PPU_CONTROL0_NMI)
871      {
872         // We need an ever-so-slight delay between entering vblank and firing an NMI - enough so that
873         // a game can read the high bit of $2002 before the NMI is called (potentially resetting the bit
874         // via a read from $2002 in the NMI handler).
875         // B-Wings is an example game that needs this.
876         ppu2c0x->nmi_timer->adjust(device->machine().device<cpu_device>("maincpu")->cycles_to_attotime(4));
877      }
878   }
879
880   if (ppu2c0x->scanline == ppu2c0x->scanlines_per_frame - 1)
881   {
882      // logerror("vblank ending\n");
883      /* clear the vblank & sprite hit flag */
884      ppu_regs[PPU_STATUS] &= ~(PPU_STATUS_VBLANK | PPU_STATUS_SPRITE0_HIT | PPU_STATUS_8SPRITES);
885   }
886
887   /* see if we rolled */
888   else if (ppu2c0x->scanline == ppu2c0x->scanlines_per_frame)
889   {
890      /* if background or sprites are enabled, copy the ppu address latch */
891      if (!blanked)
892         ppu2c0x->refresh_data = ppu2c0x->refresh_latch;
893
894      /* reset the scanline count */
895      ppu2c0x->scanline = 0;
896//      logerror("sprite 0 x: %d y: %d num: %d\n", ppu2c0x->spriteram[3], ppu2c0x->spriteram[0] + 1, ppu2c0x->spriteram[1]);
897   }
898
899   next_scanline = ppu2c0x->scanline + 1;
900   if (next_scanline == ppu2c0x->scanlines_per_frame)
901      next_scanline = 0;
902
903   // Call us back when the hblank starts for this scanline
904   ppu2c0x->hblank_timer->adjust(device->machine().device<cpu_device>("maincpu")->cycles_to_attotime(86.67)); // ??? FIXME - hardcoding NTSC, need better calculation
905
906   // trigger again at the start of the next scanline
907   ppu2c0x->scanline_timer->adjust(device->machine().primary_screen->time_until_pos(next_scanline * ppu2c0x->scan_scale));
908}
909
9101005/*************************************
9111006*
9121007*   PPU Memory functions
9131008*
9141009*************************************/
9151010
916static WRITE8_HANDLER( ppu2c0x_palette_write )
1011WRITE8_MEMBER( ppu2c0x_device::palette_write )
9171012{
918   ppu2c0x_state *ppu2c0x = get_token(&space->device());
919   int color_base = ppu2c0x->color_base;
920   int color_emphasis = (ppu2c0x->regs[PPU_CONTROL1] & PPU_CONTROL1_COLOR_EMPHASIS) * 2;
1013   int color_base = m_color_base;
1014   int color_emphasis = (m_regs[PPU_CONTROL1] & PPU_CONTROL1_COLOR_EMPHASIS) * 2;
9211015
9221016   // palette RAM is only 6 bits wide
9231017   data &= 0x3f;
r14138r14139
9251019   // transparent pens are mirrored!
9261020   if (offset & 0x3)
9271021   {
928      ppu2c0x->palette_ram[offset & 0x1f] = data;
929      ppu2c0x->colortable[offset & 0x1f] = color_base + data + color_emphasis;
930      ppu2c0x->colortable_mono[offset & 0x1f] = color_base + (data & 0xf0) + color_emphasis;
1022      m_palette_ram[offset & 0x1f] = data;
1023      m_colortable[offset & 0x1f] = color_base + data + color_emphasis;
1024      m_colortable_mono[offset & 0x1f] = color_base + (data & 0xf0) + color_emphasis;
9311025   }
9321026   else
9331027   {
9341028      int i;
9351029      if (0 == (offset & 0xf))
9361030      {
937         ppu2c0x->back_color = data;
1031         m_back_color = data;
9381032         for (i = 0; i < 32; i += 4)
9391033         {
940            ppu2c0x->colortable[i] = color_base + data + color_emphasis;
941            ppu2c0x->colortable_mono[i] = color_base + (data & 0xf0) + color_emphasis;
1034            m_colortable[i] = color_base + data + color_emphasis;
1035            m_colortable_mono[i] = color_base + (data & 0xf0) + color_emphasis;
9421036         }
9431037      }
944      ppu2c0x->palette_ram[offset & 0xf] = ppu2c0x->palette_ram[(offset & 0xf) + 0x10] = data;
1038      m_palette_ram[offset & 0xf] = m_palette_ram[(offset & 0xf) + 0x10] = data;
9451039   }
9461040}
9471041
948static READ8_HANDLER( ppu2c0x_palette_read )
1042READ8_MEMBER( ppu2c0x_device::palette_read )
9491043{
950   ppu2c0x_state *ppu2c0x = get_token(&space->device());
951   {
952      if (ppu2c0x->regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO)
953         return (ppu2c0x->palette_ram[offset & 0x1f] & 0x30);
954
955      else
956         return (ppu2c0x->palette_ram[offset & 0x1f]);
957   }
1044   if (m_regs[PPU_CONTROL1] & PPU_CONTROL1_DISPLAY_MONO)
1045      return (m_palette_ram[offset & 0x1f] & 0x30);
1046   
1047   else
1048      return (m_palette_ram[offset & 0x1f]);
9581049}
9591050
9601051/*************************************
r14138r14139
9631054 *
9641055 *************************************/
9651056
966READ8_DEVICE_HANDLER( ppu2c0x_r )
1057READ8_MEMBER( ppu2c0x_device::read )
9671058{
968   ppu2c0x_state *ppu2c0x = get_token(device);
9691059
9701060   if (offset >= PPU_MAX_REG)
9711061   {
972      logerror("PPU %s: Attempting to read past the chip: offset %x\n", device->tag(), offset);
1062      logerror("PPU %s: Attempting to read past the chip: offset %x\n", this->tag(), offset);
9731063      offset &= PPU_MAX_REG - 1;
9741064   }
9751065
r14138r14139
9791069      case PPU_STATUS: /* 2 */
9801070         // The top 3 bits of the status register are the only ones that report data. The
9811071         // remainder contain whatever was last in the PPU data latch, except on the RC2C05 (protection)
982         if (ppu2c0x->security_value)
983            ppu2c0x->data_latch = (ppu2c0x->regs[PPU_STATUS] & 0xc0) | ppu2c0x->security_value;
1072         if (m_security_value)
1073            m_data_latch = (m_regs[PPU_STATUS] & 0xc0) | m_security_value;
9841074         else
985            ppu2c0x->data_latch = ppu2c0x->regs[PPU_STATUS] | (ppu2c0x->data_latch & 0x1f);
1075            m_data_latch = m_regs[PPU_STATUS] | (m_data_latch & 0x1f);
9861076
9871077         // Reset hi/lo scroll toggle
988         ppu2c0x->toggle = 0;
1078         m_toggle = 0;
9891079
9901080         // If the vblank bit is set, clear all status bits but the 2 sprite flags
991         if (ppu2c0x->data_latch & PPU_STATUS_VBLANK)
992            ppu2c0x->regs[PPU_STATUS] &= 0x60;
1081         if (m_data_latch & PPU_STATUS_VBLANK)
1082            m_regs[PPU_STATUS] &= 0x60;
9931083         break;
9941084
9951085      case PPU_SPRITE_DATA: /* 4 */
996         ppu2c0x->data_latch = ppu2c0x->spriteram[ppu2c0x->regs[PPU_SPRITE_ADDRESS]];
1086         m_data_latch = m_spriteram[m_regs[PPU_SPRITE_ADDRESS]];
9971087         break;
9981088
9991089      case PPU_DATA: /* 7 */
1000         if (ppu2c0x->latch)
1001            (*ppu2c0x->latch)(device, ppu2c0x->videomem_addr & 0x3fff);
1090         if (m_latch)
1091            (*m_latch)(this, m_videomem_addr & 0x3fff);
10021092
1003         if (ppu2c0x->videomem_addr >= 0x3f00)
1093         if (m_videomem_addr >= 0x3f00)
10041094         {
1005            ppu2c0x->data_latch = ppu2c0x->space->read_byte(ppu2c0x->videomem_addr);
1095            m_data_latch = readbyte(m_videomem_addr);
10061096            // buffer the mirrored NT data
1007            ppu2c0x->buffered_data = ppu2c0x->space->read_byte(ppu2c0x->videomem_addr & 0x2fff);
1097            m_buffered_data = readbyte(m_videomem_addr & 0x2fff);
10081098         }
10091099         else
10101100         {
1011            ppu2c0x->data_latch = ppu2c0x->buffered_data;
1012            ppu2c0x->buffered_data = ppu2c0x->space->read_byte(ppu2c0x->videomem_addr);
1101            m_data_latch = m_buffered_data;
1102            m_buffered_data = readbyte(m_videomem_addr);
10131103         }
10141104
1015         ppu2c0x->videomem_addr += ppu2c0x->add;
1105         m_videomem_addr += m_add;
10161106         break;
10171107
10181108      default:
10191109         break;
10201110   }
10211111
1022   return ppu2c0x->data_latch;
1112   return m_data_latch;
10231113}
10241114
10251115
r14138r14139
10291119 *
10301120 *************************************/
10311121
1032WRITE8_DEVICE_HANDLER( ppu2c0x_w )
1122WRITE8_MEMBER( ppu2c0x_device::write )
10331123{
1034   ppu2c0x_state *ppu2c0x = get_token(device);
10351124   int color_base;
10361125
1037   color_base = ppu2c0x->color_base;
1126   color_base = m_color_base;
10381127
10391128   if (offset >= PPU_MAX_REG)
10401129   {
1041      logerror("PPU %s: Attempting to write past the chip: offset %x, data %x\n", device->tag(), offset, data);
1130      logerror("PPU %s: Attempting to write past the chip: offset %x, data %x\n", this->tag(), offset, data);
10421131      offset &= PPU_MAX_REG - 1;
10431132   }
10441133
10451134#ifdef MAME_DEBUG
1046   if (ppu2c0x->scanline <= PPU_BOTTOM_VISIBLE_SCANLINE)
1135   if (m_scanline <= PPU_BOTTOM_VISIBLE_SCANLINE)
10471136   {
10481137      screen_device *screen = device->machine().primary_screen;
1049      logerror("PPU register %d write %02x during non-vblank scanline %d (MAME %d, beam pos: %d)\n", offset, data, ppu2c0x->scanline, screen->vpos(), screen->hpos());
1138      logerror("PPU register %d write %02x during non-vblank scanline %d (MAME %d, beam pos: %d)\n", offset, data, m_scanline, m_screen->vpos(), m_screen->hpos());
10501139   }
10511140#endif
10521141
10531142   /* on the RC2C05, PPU_CONTROL0 and PPU_CONTROL1 are swapped (protection) */
1054   if ((ppu2c0x->security_value) && !(offset & 6))
1143   if ((m_security_value) && !(offset & 6))
10551144      offset ^= 1;
10561145
10571146   switch (offset & 7)
10581147   {
10591148      case PPU_CONTROL0: /* 0 */
1060         ppu2c0x->regs[PPU_CONTROL0] = data;
1149         m_regs[PPU_CONTROL0] = data;
10611150
10621151         /* update the name table number on our refresh latches */
1063         ppu2c0x->refresh_latch &= 0x73ff;
1064         ppu2c0x->refresh_latch |= (data & 3) << 10;
1152         m_refresh_latch &= 0x73ff;
1153         m_refresh_latch |= (data & 3) << 10;
10651154
10661155         /* the char ram bank points either 0x0000 or 0x1000 (page 0 or page 4) */
1067         ppu2c0x->tile_page = (data & PPU_CONTROL0_CHR_SELECT) >> 2;
1068         ppu2c0x->sprite_page = (data & PPU_CONTROL0_SPR_SELECT) >> 1;
1156         m_tile_page = (data & PPU_CONTROL0_CHR_SELECT) >> 2;
1157         m_sprite_page = (data & PPU_CONTROL0_SPR_SELECT) >> 1;
10691158
1070         ppu2c0x->add = (data & PPU_CONTROL0_INC) ? 32 : 1;
1071//          logerror("control0 write: %02x (scanline: %d)\n", data, ppu2c0x->scanline);
1159         m_add = (data & PPU_CONTROL0_INC) ? 32 : 1;
1160//          logerror("control0 write: %02x (scanline: %d)\n", data, m_scanline);
10721161         break;
10731162
10741163      case PPU_CONTROL1: /* 1 */
10751164         /* if color intensity has changed, change all the color tables to reflect them */
1076         if ((data & PPU_CONTROL1_COLOR_EMPHASIS) != (ppu2c0x->regs[PPU_CONTROL1] & PPU_CONTROL1_COLOR_EMPHASIS))
1165         if ((data & PPU_CONTROL1_COLOR_EMPHASIS) != (m_regs[PPU_CONTROL1] & PPU_CONTROL1_COLOR_EMPHASIS))
10771166         {
10781167            int i;
10791168            for (i = 0; i <= 0x1f; i++)
10801169            {
1081               UINT8 oldColor = ppu2c0x->palette_ram[i];
1170               UINT8 oldColor = m_palette_ram[i];
10821171
1083               ppu2c0x->colortable[i] = color_base + oldColor + (data & PPU_CONTROL1_COLOR_EMPHASIS) * 2;
1172               m_colortable[i] = color_base + oldColor + (data & PPU_CONTROL1_COLOR_EMPHASIS) * 2;
10841173            }
10851174         }
10861175
1087//          logerror("control1 write: %02x (scanline: %d)\n", data, ppu2c0x->scanline);
1088         ppu2c0x->regs[PPU_CONTROL1] = data;
1176//          logerror("control1 write: %02x (scanline: %d)\n", data, m_scanline);
1177         m_regs[PPU_CONTROL1] = data;
10891178         break;
10901179
10911180      case PPU_SPRITE_ADDRESS: /* 3 */
1092         ppu2c0x->regs[PPU_SPRITE_ADDRESS] = data;
1181         m_regs[PPU_SPRITE_ADDRESS] = data;
10931182         break;
10941183
10951184      case PPU_SPRITE_DATA: /* 4 */
10961185         // If the PPU is currently rendering the screen, 0xff is written instead of the desired data.
1097         if (ppu2c0x->scanline <= PPU_BOTTOM_VISIBLE_SCANLINE)
1186         if (m_scanline <= PPU_BOTTOM_VISIBLE_SCANLINE)
10981187            data = 0xff;
1099         ppu2c0x->spriteram[ppu2c0x->regs[PPU_SPRITE_ADDRESS]] = data;
1100         ppu2c0x->regs[PPU_SPRITE_ADDRESS] = (ppu2c0x->regs[PPU_SPRITE_ADDRESS] + 1) & 0xff;
1188         m_spriteram[m_regs[PPU_SPRITE_ADDRESS]] = data;
1189         m_regs[PPU_SPRITE_ADDRESS] = (m_regs[PPU_SPRITE_ADDRESS] + 1) & 0xff;
11011190         break;
11021191
11031192      case PPU_SCROLL: /* 5 */
1104         if (ppu2c0x->toggle)
1193         if (m_toggle)
11051194         {
11061195            /* second write */
1107            ppu2c0x->refresh_latch &= 0x0c1f;
1108            ppu2c0x->refresh_latch |= (data & 0xf8) << 2;
1109            ppu2c0x->refresh_latch |= (data & 0x07) << 12;
1110//              logerror("scroll write 2: %d, %04x (scanline: %d)\n", data, ppu2c0x->refresh_latch, ppu2c0x->scanline);
1196            m_refresh_latch &= 0x0c1f;
1197            m_refresh_latch |= (data & 0xf8) << 2;
1198            m_refresh_latch |= (data & 0x07) << 12;
1199//              logerror("scroll write 2: %d, %04x (scanline: %d)\n", data, m_refresh_latch, m_scanline);
11111200         }
11121201         else
11131202         {
11141203            /* first write */
1115            ppu2c0x->refresh_latch &= 0x7fe0;
1116            ppu2c0x->refresh_latch |= (data & 0xf8) >> 3;
1204            m_refresh_latch &= 0x7fe0;
1205            m_refresh_latch |= (data & 0xf8) >> 3;
11171206
1118            ppu2c0x->x_fine = data & 7;
1119//              logerror("scroll write 1: %d, %04x (scanline: %d)\n", data, ppu2c0x->refresh_latch, ppu2c0x->scanline);
1207            m_x_fine = data & 7;
1208//              logerror("scroll write 1: %d, %04x (scanline: %d)\n", data, m_refresh_latch, m_scanline);
11201209         }
11211210
1122         ppu2c0x->toggle ^= 1;
1211         m_toggle ^= 1;
11231212         break;
11241213
11251214      case PPU_ADDRESS: /* 6 */
1126         if (ppu2c0x->toggle)
1215         if (m_toggle)
11271216         {
11281217            /* second write */
1129            ppu2c0x->refresh_latch &= 0x7f00;
1130            ppu2c0x->refresh_latch |= data;
1131            ppu2c0x->refresh_data = ppu2c0x->refresh_latch;
1218            m_refresh_latch &= 0x7f00;
1219            m_refresh_latch |= data;
1220            m_refresh_data = m_refresh_latch;
11321221
1133            ppu2c0x->videomem_addr = ppu2c0x->refresh_latch;
1134//              logerror("vram addr write 2: %02x, %04x (scanline: %d)\n", data, ppu2c0x->refresh_latch, ppu2c0x->scanline);
1222            m_videomem_addr = m_refresh_latch;
1223//              logerror("vram addr write 2: %02x, %04x (scanline: %d)\n", data, m_refresh_latch, m_scanline);
11351224         }
11361225         else
11371226         {
11381227            /* first write */
1139            ppu2c0x->refresh_latch &= 0x00ff;
1140            ppu2c0x->refresh_latch |= (data & 0x3f) << 8;
1141//              logerror("vram addr write 1: %02x, %04x (scanline: %d)\n", data, ppu2c0x->refresh_latch, ppu2c0x->scanline);
1228            m_refresh_latch &= 0x00ff;
1229            m_refresh_latch |= (data & 0x3f) << 8;
1230//              logerror("vram addr write 1: %02x, %04x (scanline: %d)\n", data, m_refresh_latch, m_scanline);
11421231         }
11431232
1144         ppu2c0x->toggle ^= 1;
1233         m_toggle ^= 1;
11451234         break;
11461235
11471236      case PPU_DATA: /* 7 */
11481237         {
1149            int tempAddr = ppu2c0x->videomem_addr & 0x3fff;
1238            int tempAddr = m_videomem_addr & 0x3fff;
11501239
1151            if (ppu2c0x->latch)
1152               (*ppu2c0x->latch)(device, tempAddr);
1240            if (m_latch)
1241               (*m_latch)(this, tempAddr);
11531242
11541243            /* if there's a callback, call it now */
1155            if (ppu2c0x->vidaccess_callback_proc)
1156               data = (*ppu2c0x->vidaccess_callback_proc)(device, tempAddr, data);
1244            if (m_vidaccess_callback_proc)
1245               data = (*m_vidaccess_callback_proc)(this, tempAddr, data);
11571246
11581247            /* see if it's on the chargen portion */
11591248            if (tempAddr < 0x2000)
11601249            {
11611250               /* store the data */
1162               ppu2c0x->space->write_byte(tempAddr, data);
1251               writebyte(tempAddr, data);
11631252            }
11641253
11651254            else
11661255            {
1167               ppu2c0x->space->write_byte(tempAddr, data);
1256               writebyte(tempAddr, data);
11681257            }
11691258            /* increment the address */
1170            ppu2c0x->videomem_addr += ppu2c0x->add;
1259            m_videomem_addr += m_add;
11711260         }
11721261         break;
11731262
r14138r14139
11761265         break;
11771266   }
11781267
1179   ppu2c0x->data_latch = data;
1268   m_data_latch = data;
11801269}
11811270
11821271/*************************************
r14138r14139
11851274 *
11861275 *************************************/
11871276
1188void ppu2c0x_spriteram_dma( address_space *space, device_t *device, const UINT8 page )
1277void ppu2c0x_device::spriteram_dma( address_space *space, const UINT8 page )
11891278{
11901279   int i;
11911280   int address = page << 8;
r14138r14139
12061295 *
12071296 *************************************/
12081297
1209void ppu2c0x_render( device_t *device, bitmap_ind16 &bitmap, int flipx, int flipy, int sx, int sy )
1298void ppu2c0x_device::render( bitmap_ind16 &bitmap, int flipx, int flipy, int sx, int sy )
12101299{
1211   ppu2c0x_state *ppu2c0x = get_token(device);
1212   copybitmap(bitmap, *ppu2c0x->bitmap, flipx, flipy, sx, sy, bitmap.cliprect());
1300   copybitmap(bitmap, *m_bitmap, flipx, flipy, sx, sy, bitmap.cliprect());
12131301}
12141302
12151303/*************************************
r14138r14139
12181306 *
12191307 *************************************/
12201308
1221int ppu2c0x_get_pixel( device_t *device, int x, int y )
1309int ppu2c0x_device::get_pixel( int x, int y )
12221310{
1223   ppu2c0x_state *ppu2c0x = get_token(device);
12241311
12251312   if (x >= VISIBLE_SCREEN_WIDTH)
12261313      x = VISIBLE_SCREEN_WIDTH - 1;
r14138r14139
12281315   if (y >= VISIBLE_SCREEN_HEIGHT)
12291316      y = VISIBLE_SCREEN_HEIGHT - 1;
12301317
1231   return ppu2c0x->bitmap->pix16(y, x);
1318   return m_bitmap->pix16(y, x);
12321319}
12331320
1234int ppu2c0x_get_colorbase( device_t *device )
1235{
1236   ppu2c0x_state *ppu2c0x = get_token(device);
1237   return ppu2c0x->color_base;
1238}
1239
1240int ppu2c0x_get_current_scanline( device_t *device )
1241{
1242   ppu2c0x_state *ppu2c0x = get_token(device);
1243   return ppu2c0x->scanline;
1244}
1245
1246// MMC5 has to be able to check this
1247int ppu2c0x_is_sprite_8x16( device_t *device )
1248{
1249   ppu2c0x_state *ppu2c0x = get_token(device);
1250   return BIT(ppu2c0x->regs[0], 5);
1251}
1252
1253void ppu2c0x_set_scanline_callback( device_t *device, ppu2c0x_scanline_cb cb )
1254{
1255   ppu2c0x_state *ppu2c0x = get_token(device);
1256   ppu2c0x->scanline_callback_proc = cb;
1257}
1258
1259void ppu2c0x_set_hblank_callback( device_t *device, ppu2c0x_hblank_cb cb )
1260{
1261   ppu2c0x_state *ppu2c0x = get_token(device);
1262   ppu2c0x->hblank_callback_proc = cb;
1263}
1264
1265void ppu2c0x_set_vidaccess_callback( device_t *device, ppu2c0x_vidaccess_cb cb )
1266{
1267   ppu2c0x_state *ppu2c0x = get_token(device);
1268   ppu2c0x->vidaccess_callback_proc = cb;
1269}
1270
1271void ppu2c0x_set_scanlines_per_frame( device_t *device, int scanlines )
1272{
1273   ppu2c0x_state *ppu2c0x = get_token(device);
1274   ppu2c0x->scanlines_per_frame = scanlines;
1275}
1276
1277
1278/*************************************
1279 *
1280 *  PPU Start
1281 *
1282 *************************************/
1283
1284static DEVICE_START( ppu2c0x )
1285{
1286   ppu2c0x_state *ppu2c0x = get_token(device);
1287   const ppu2c0x_interface *intf = get_interface(device);
1288
1289   memset(ppu2c0x, 0, sizeof(*ppu2c0x));
1290   ppu2c0x->space = device->memory().space();
1291   ppu2c0x->scanlines_per_frame = (device->type() != PPU_2C07) ? PPU_NTSC_SCANLINES_PER_FRAME : PPU_PAL_SCANLINES_PER_FRAME;
1292
1293   /* usually, no security value... */
1294   ppu2c0x->security_value = 0;
1295
1296   /* ...except for VS. games which specific PPU types */
1297   if (device->type() == PPU_2C05_01)
1298      ppu2c0x->security_value = 0x1b;   // game (jajamaru) doesn't seem to ever actually check it
1299
1300   if (device->type() == PPU_2C05_02)
1301      ppu2c0x->security_value = 0x3d;
1302
1303   if (device->type() == PPU_2C05_03)
1304      ppu2c0x->security_value = 0x1c;
1305
1306   if (device->type() == PPU_2C05_04)
1307      ppu2c0x->security_value = 0x1b;
1308
1309   /* initialize the scanline handling portion */
1310   ppu2c0x->scanline_timer = device->machine().scheduler().timer_alloc(FUNC(scanline_callback), (void *) device);
1311   ppu2c0x->scanline_timer->adjust(device->machine().primary_screen->time_until_pos(1));
1312
1313   ppu2c0x->hblank_timer = device->machine().scheduler().timer_alloc(FUNC(hblank_callback), (void *) device);
1314   ppu2c0x->hblank_timer->adjust(device->machine().device<cpu_device>("maincpu")->cycles_to_attotime(86.67)); // ??? FIXME - hardcoding NTSC, need better calculation
1315
1316   ppu2c0x->nmi_timer = device->machine().scheduler().timer_alloc(FUNC(nmi_callback), (void *) device);
1317   ppu2c0x->nmi_timer->adjust(attotime::never);
1318
1319   ppu2c0x->nmi_callback_proc = intf->nmi_handler;
1320   ppu2c0x->color_base = intf->color_base;
1321
1322   /* allocate a screen bitmap, videomem and spriteram, a dirtychar array and the monochromatic colortable */
1323   ppu2c0x->bitmap = auto_bitmap_ind16_alloc(device->machine(), VISIBLE_SCREEN_WIDTH, VISIBLE_SCREEN_HEIGHT);
1324   ppu2c0x->spriteram = auto_alloc_array_clear(device->machine(), UINT8, SPRITERAM_SIZE);
1325   ppu2c0x->colortable = auto_alloc_array(device->machine(), pen_t, ARRAY_LENGTH(default_colortable));
1326   ppu2c0x->colortable_mono = auto_alloc_array(device->machine(), pen_t, ARRAY_LENGTH(default_colortable_mono));
1327
1328   device->save_item(NAME(ppu2c0x->scanline));
1329   device->save_item(NAME(ppu2c0x->refresh_data));
1330   device->save_item(NAME(ppu2c0x->refresh_latch));
1331   device->save_item(NAME(ppu2c0x->x_fine));
1332   device->save_item(NAME(ppu2c0x->toggle));
1333   device->save_item(NAME(ppu2c0x->add));
1334   device->save_item(NAME(ppu2c0x->videomem_addr));
1335   device->save_item(NAME(ppu2c0x->addr_latch));
1336   device->save_item(NAME(ppu2c0x->data_latch));
1337   device->save_item(NAME(ppu2c0x->buffered_data));
1338   device->save_item(NAME(ppu2c0x->tile_page));
1339   device->save_item(NAME(ppu2c0x->sprite_page));
1340   device->save_item(NAME(ppu2c0x->back_color));
1341   device->save_item(NAME(ppu2c0x->scan_scale));
1342   device->save_item(NAME(ppu2c0x->scanlines_per_frame));
1343   device->save_item(NAME(ppu2c0x->regs));
1344   device->save_item(NAME(ppu2c0x->palette_ram));
1345   device->save_pointer(NAME(ppu2c0x->spriteram), SPRITERAM_SIZE);
1346   device->save_pointer(NAME(ppu2c0x->colortable), ARRAY_LENGTH(default_colortable));
1347   device->save_pointer(NAME(ppu2c0x->colortable_mono), ARRAY_LENGTH(default_colortable_mono));
1348   device->save_item(NAME(*ppu2c0x->bitmap));
1349}
1350
1351/*************************************
1352 *
1353 *  PPU Reset
1354 *
1355 *************************************/
1356
1357static DEVICE_RESET( ppu2c0x )
1358{
1359   ppu2c0x_state *ppu2c0x = get_token(device);
1360   const ppu2c0x_interface *intf = get_interface(device);
1361   int i;
1362
1363   /* reset the scanline count */
1364   ppu2c0x->scanline = 0;
1365
1366   /* set the scan scale (this is for dual monitor vertical setups) */
1367   ppu2c0x->scan_scale = 1;
1368
1369   /* reset the callbacks */
1370   ppu2c0x->scanline_callback_proc = NULL;
1371   ppu2c0x->vidaccess_callback_proc = NULL;
1372
1373   for (i = 0; i < PPU_MAX_REG; i++)
1374      ppu2c0x->regs[i] = 0;
1375
1376   memset(ppu2c0x->palette_ram, 0, ARRAY_LENGTH(ppu2c0x->palette_ram));
1377
1378   /* initialize the rest of the members */
1379   ppu2c0x->refresh_data = 0;
1380   ppu2c0x->refresh_latch = 0;
1381   ppu2c0x->x_fine = 0;
1382   ppu2c0x->toggle = 0;
1383   ppu2c0x->add = 1;
1384   ppu2c0x->videomem_addr = 0;
1385   ppu2c0x->addr_latch = 0;
1386   ppu2c0x->data_latch = 0;
1387   ppu2c0x->tile_page = 0;
1388   ppu2c0x->sprite_page = 0;
1389   ppu2c0x->back_color = 0;
1390   ppu2c0x->buffered_data = 0;
1391
1392   /* initialize the color tables */
1393   {
1394      int color_base = intf->color_base;
1395
1396      for (i = 0; i < ARRAY_LENGTH(default_colortable_mono); i++)
1397      {
1398         /* monochromatic table */
1399         ppu2c0x->colortable_mono[i] = default_colortable_mono[i] + color_base;
1400
1401         /* color table */
1402         ppu2c0x->colortable[i] = default_colortable[i] + color_base;
1403      }
1404   }
1405}
1406
1407/***************************************************************************
1408    GET INFO FUNCTIONS
1409***************************************************************************/
1410
1411DEVICE_GET_INFO(ppu2c02)
1412{
1413   switch (state)
1414   {
1415      /* --- the following bits of info are returned as 64-bit signed integers --- */
1416      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(ppu2c0x_state);            break;
1417      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                        break;
1418      case DEVINFO_INT_DATABUS_WIDTH_0:            info->i = 8;                        break;
1419      case DEVINFO_INT_ADDRBUS_WIDTH_0:            info->i = 14;                        break;
1420      case DEVINFO_INT_ADDRBUS_SHIFT_0:            info->i = 0;                        break;
1421
1422
1423      /* --- the following bits of info are returned as pointers to data --- */
1424      case DEVINFO_PTR_DEFAULT_MEMORY_MAP_0:      info->default_map8 = ADDRESS_MAP_NAME(ppu2c0x);break;
1425
1426
1427      /* --- the following bits of info are returned as pointers to data or functions --- */
1428      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(ppu2c0x);   break;
1429      case DEVINFO_FCT_STOP:                     /* Nothing */                        break;
1430      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(ppu2c0x);   break;
1431
1432      /* --- the following bits of info are returned as NULL-terminated strings --- */
1433      case DEVINFO_STR_NAME:                     strcpy(info->s, "2C02 PPU");            break;
1434      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "2C0X PPU");            break;
1435      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                  break;
1436      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);               break;
1437      case DEVINFO_STR_CREDITS:                  /* Nothing */                        break;
1438   }
1439}
1440
1441DEVICE_GET_INFO(ppu2c03b)
1442{
1443   switch (state)
1444   {
1445      case DEVINFO_STR_NAME:                     strcpy(info->s, "2C02B PPU");            break;
1446      default:                              DEVICE_GET_INFO_CALL(ppu2c02);            break;
1447   }
1448}
1449
1450DEVICE_GET_INFO(ppu2c04)
1451{
1452   switch (state)
1453   {
1454      case DEVINFO_STR_NAME:                     strcpy(info->s, "2C04 PPU");            break;
1455      default:                              DEVICE_GET_INFO_CALL(ppu2c02);            break;
1456   }
1457}
1458
1459DEVICE_GET_INFO(ppu2c05_01)
1460{
1461   switch (state)
1462   {
1463      case DEVINFO_STR_NAME:                     strcpy(info->s, "2C05 PPU");            break;
1464      default:                              DEVICE_GET_INFO_CALL(ppu2c02);            break;
1465   }
1466}
1467
1468DEVICE_GET_INFO(ppu2c05_02)
1469{
1470   DEVICE_GET_INFO_CALL(ppu2c05_01);
1471}
1472
1473DEVICE_GET_INFO(ppu2c05_03)
1474{
1475   DEVICE_GET_INFO_CALL(ppu2c05_01);
1476}
1477
1478DEVICE_GET_INFO(ppu2c05_04)
1479{
1480   DEVICE_GET_INFO_CALL(ppu2c05_01);
1481}
1482
1483DEVICE_GET_INFO(ppu2c07)
1484{
1485   switch (state)
1486   {
1487      case DEVINFO_STR_NAME:                     strcpy(info->s, "2C07 PPU");            break;
1488      default:                              DEVICE_GET_INFO_CALL(ppu2c02);            break;
1489   }
1490}
1491
1492
1493DEFINE_LEGACY_MEMORY_DEVICE(PPU_2C02, ppu2c02);      // NTSC NES
1494DEFINE_LEGACY_MEMORY_DEVICE(PPU_2C03B, ppu2c03b);      // Playchoice 10
1495DEFINE_LEGACY_MEMORY_DEVICE(PPU_2C04, ppu2c04);      // Vs. Unisystem
1496// The PPU_2C05 variants have different protection value, set at DEVICE_START, but otherwise are all the same...
1497DEFINE_LEGACY_MEMORY_DEVICE(PPU_2C05_01, ppu2c05_01);   // Vs. Unisystem (Ninja Jajamaru Kun)
1498DEFINE_LEGACY_MEMORY_DEVICE(PPU_2C05_02, ppu2c05_02);   // Vs. Unisystem (Mighty Bomb Jack)
1499DEFINE_LEGACY_MEMORY_DEVICE(PPU_2C05_03, ppu2c05_03);   // Vs. Unisystem (Gumshoe)
1500DEFINE_LEGACY_MEMORY_DEVICE(PPU_2C05_04, ppu2c05_04);   // Vs. Unisystem (Top Gun)
1501DEFINE_LEGACY_MEMORY_DEVICE(PPU_2C07, ppu2c07);      // PAL NES
src/mame/video/ppu2c0x.h
r14138r14139
77
88******************************************************************************/
99
10#pragma once
11
1012#ifndef __PPU_2C03B_H__
1113#define __PPU_2C03B_H__
1214
1315#include "devlegcy.h"
1416
1517
16/***************************************************************************
17    CONSTANTS
18***************************************************************************/
18///*************************************************************************
19//  MACROS / CONSTANTS
20///*************************************************************************
1921
20/* mirroring types */
22// mirroring types
2123#define PPU_MIRROR_NONE       0
2224#define PPU_MIRROR_VERT       1
2325#define PPU_MIRROR_HORZ       2
r14138r14139
2527#define PPU_MIRROR_LOW        4
2628#define PPU_MIRROR_4SCREEN    5   // Same effect as NONE, but signals that we should never mirror
2729
28/* registers definition */
30// registers definition
2931enum
3032{
3133   PPU_CONTROL0 = 0,
r14138r14139
3941   PPU_MAX_REG
4042};
4143
42/* bit definitions for (some of) the registers */
44// bit definitions for (some of) the registers
4345enum
4446{
4547   PPU_CONTROL0_INC              = 0x04,
r14138r14139
7476   // are non-rendering and non-vblank.
7577};
7678
77/* callback datatypes */
79/*----------- defined in video/ppu2c0x.c -----------*/
80
81///*************************************************************************
82//  INTERFACE CONFIGURATION MACROS
83///*************************************************************************
84
85#define MCFG_PPU2C0X_ADD(_tag, _type, _intrf)   \
86   MCFG_DEVICE_ADD(_tag, _type, 0) \
87   MCFG_DEVICE_CONFIG(_intrf)
88
89#define MCFG_PPU2C02_ADD(_tag, _intrf)   \
90   MCFG_PPU2C0X_ADD(_tag, PPU_2C02, _intrf) \
91
92#define MCFG_PPU2C03B_ADD(_tag, _intrf)   \
93   MCFG_PPU2C0X_ADD(_tag, PPU_2C03B, _intrf) \
94
95#define MCFG_PPU2C04_ADD(_tag, _intrf)   \
96   MCFG_PPU2C0X_ADD(_tag, PPU_2C04, _intrf) \
97
98#define MCFG_PPU2C07_ADD(_tag, _intrf)   \
99   MCFG_PPU2C0X_ADD(_tag, PPU_2C07, _intrf) \
100
101#define MCFG_PPU2C05_01_ADD(_tag, _intrf)   \
102   MCFG_PPU2C0X_ADD(_tag, PPU_2C05_01, _intrf) \
103
104#define MCFG_PPU2C05_02_ADD(_tag, _intrf)   \
105   MCFG_PPU2C0X_ADD(_tag, PPU_2C05_02, _intrf) \
106
107#define MCFG_PPU2C05_03_ADD(_tag, _intrf)   \
108   MCFG_PPU2C0X_ADD(_tag, PPU_2C05_03, _intrf) \
109
110#define MCFG_PPU2C05_04_ADD(_tag, _intrf)   \
111   MCFG_PPU2C0X_ADD(_tag, PPU_2C05_04, _intrf) \
112
113
114///*************************************************************************
115//  TYPE DEFINITIONS
116///*************************************************************************
117
118// callback datatypes
78119typedef void (*ppu2c0x_scanline_cb)( device_t *device, int scanline, int vblank, int blanked );
79120typedef void (*ppu2c0x_hblank_cb)( device_t *device, int scanline, int vblank, int blanked );
80121typedef void (*ppu2c0x_nmi_cb)( device_t *device, int *ppu_regs );
81122typedef int  (*ppu2c0x_vidaccess_cb)( device_t *device, int address, int data );
82123
83typedef struct _ppu2c0x_interface ppu2c0x_interface;
84struct _ppu2c0x_interface
124
125// ======================> ppu2c0x_interface
126
127struct ppu2c0x_interface
85128{
129   const char        *cpu_tag;
130   const char        *screen_tag;
86131   int               gfx_layout_number;      /* gfx layout number used by each chip */
87132   int               color_base;            /* color base to use per ppu */
88133   int               mirroring;            /* mirroring options (PPU_MIRROR_* flag) */
r14138r14139
90135};
91136
92137
93/***************************************************************************
94    PROTOTYPES
95***************************************************************************/
138// ======================> ppu2c0x_device
96139
97DECLARE_LEGACY_MEMORY_DEVICE(PPU_2C02, ppu2c02);      // NTSC NES
98DECLARE_LEGACY_MEMORY_DEVICE(PPU_2C03B, ppu2c03b);      // Playchoice 10
99DECLARE_LEGACY_MEMORY_DEVICE(PPU_2C04, ppu2c04);      // Vs. Unisystem
100// The PPU_2C05 variants have different protection value, set at DEVICE_START, but otherwise are all the same...
101DECLARE_LEGACY_MEMORY_DEVICE(PPU_2C05_01, ppu2c05_01);   // Vs. Unisystem (Ninja Jajamaru Kun)
102DECLARE_LEGACY_MEMORY_DEVICE(PPU_2C05_02, ppu2c05_02);   // Vs. Unisystem (Mighty Bomb Jack)
103DECLARE_LEGACY_MEMORY_DEVICE(PPU_2C05_03, ppu2c05_03);   // Vs. Unisystem (Gumshoe)
104DECLARE_LEGACY_MEMORY_DEVICE(PPU_2C05_04, ppu2c05_04);   // Vs. Unisystem (Top Gun)
105DECLARE_LEGACY_MEMORY_DEVICE(PPU_2C07, ppu2c07);      // PAL NES
140class ppu2c0x_device :   public device_t,
141                  public device_memory_interface,
142                  public ppu2c0x_interface
143{
144public:
145    // construction/destruction
146   ppu2c0x_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock);
147   
148   DECLARE_READ8_MEMBER( read );
149   DECLARE_WRITE8_MEMBER( write );
150   DECLARE_READ8_MEMBER( palette_read );
151   DECLARE_WRITE8_MEMBER( palette_write );
106152
107/* routines */
108void ppu2c0x_init_palette(running_machine &machine, int first_entry );
109void ppu2c0x_init_palette_rgb(running_machine &machine, int first_entry );
153   virtual void device_start();
154   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
155   virtual void device_config_complete();
156   // device_config_memory_interface overrides
157   virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const;
158   // address space configurations
159   const address_space_config      m_space_config;
160   
161   
162   /* routines */
163   void init_palette( running_machine &machine, int first_entry );
164   void init_palette_rgb( running_machine &machine, int first_entry );
165   
166   void draw_background( UINT8 *line_priority );
167   void draw_sprites( UINT8 *line_priority );
168   void render_scanline();
169   void update_scanline();
110170
111void ppu2c0x_spriteram_dma(address_space *space, device_t *device, const UINT8 page ) ATTR_NONNULL(1);
112void ppu2c0x_render( device_t *device, bitmap_ind16 &bitmap, int flipx, int flipy, int sx, int sy ) ATTR_NONNULL(1);
113int ppu2c0x_get_pixel( device_t *device, int x, int y ) ATTR_NONNULL(1);
114int ppu2c0x_get_colorbase( device_t *device ) ATTR_NONNULL(1);
115int ppu2c0x_get_current_scanline( device_t *device ) ATTR_NONNULL(1);
116int ppu2c0x_is_sprite_8x16( device_t *device ) ATTR_NONNULL(1);
117void ppu2c0x_set_scanline_callback( device_t *device, ppu2c0x_scanline_cb cb ) ATTR_NONNULL(1);
118void ppu2c0x_set_hblank_callback( device_t *device, ppu2c0x_scanline_cb cb ) ATTR_NONNULL(1);
119void ppu2c0x_set_vidaccess_callback( device_t *device, ppu2c0x_vidaccess_cb cb ) ATTR_NONNULL(1);
120void ppu2c0x_set_scanlines_per_frame( device_t *device, int scanlines ) ATTR_NONNULL(1);
171   void spriteram_dma(address_space *space, const UINT8 page ) ATTR_NONNULL(1);
172   void render( bitmap_ind16 &bitmap, int flipx, int flipy, int sx, int sy ) ATTR_NONNULL(1);
173   int get_pixel( int x, int y ) ATTR_NONNULL(1);
121174
122//27/12/2002 (HACK!)
123void ppu2c0x_set_latch( device_t *device, void (*ppu_latch_t)( device_t *device, offs_t offset ));
124WRITE8_DEVICE_HANDLER( ppu2c0x_w );
125READ8_DEVICE_HANDLER( ppu2c0x_r );
175   int get_colorbase() { return m_color_base; };
176   int get_current_scanline() { return m_scanline; };
177   int is_sprite_8x16() { return BIT(m_regs[0], 5); };   // MMC5 has to be able to check this
178   void set_scanline_callback( ppu2c0x_scanline_cb cb ) { if (cb != NULL) m_scanline_callback_proc = cb; };
179   void set_hblank_callback( ppu2c0x_scanline_cb cb ) { if (cb != NULL) m_hblank_callback_proc = cb; };
180   void set_vidaccess_callback( ppu2c0x_vidaccess_cb cb ) { if (cb != NULL) m_vidaccess_callback_proc = cb; };
181   void set_scanlines_per_frame( int scanlines ) { m_scanlines_per_frame = scanlines; };
182   
183   //27/12/2002 (HACK!)
184   void set_latch( void (*ppu_latch_t)( device_t *device, offs_t offset ) );
185   
186   //   void update_screen(bitmap_t &bitmap, const rectangle &cliprect);
187   
188   cpu_device               *m_cpu;
189   screen_device            *m_screen;
190   bitmap_ind16             *m_bitmap;         /* target bitmap */
191   UINT8                       *m_spriteram;         /* sprite ram */
192   pen_t                       *m_colortable;         /* color table modified at run time */
193   pen_t                       *m_colortable_mono;      /* monochromatic color table modified at run time */
194   int                         m_scanline;         /* scanline count */
195   ppu2c0x_scanline_cb         m_scanline_callback_proc;   /* optional scanline callback */
196   ppu2c0x_hblank_cb           m_hblank_callback_proc;   /* optional hblank callback */
197   ppu2c0x_vidaccess_cb        m_vidaccess_callback_proc;   /* optional video access callback */
198   ppu2c0x_nmi_cb              m_nmi_callback_proc;      /* nmi access callback from interface */
199   int                         m_regs[PPU_MAX_REG];      /* registers */
200   int                         m_refresh_data;         /* refresh-related */
201   int                         m_refresh_latch;      /* refresh-related */
202   int                         m_x_fine;            /* refresh-related */
203   int                         m_toggle;            /* used to latch hi-lo scroll */
204   int                         m_add;            /* vram increment amount */
205   int                         m_videomem_addr;      /* videomem address pointer */
206   int                         m_data_latch;         /* latched videomem data */
207   int                         m_buffered_data;
208   int                         m_tile_page;         /* current tile page */
209   int                         m_sprite_page;         /* current sprite page */
210   int                         m_back_color;         /* background color */
211   int                         m_color_base;
212   UINT8                       m_palette_ram[0x20];      /* shouldn't be in main memory! */
213   int                         m_scan_scale;         /* scan scale */
214   int                         m_scanlines_per_frame;   /* number of scanlines per frame */
215   int                         m_security_value;      /* 2C05 protection */
216   void (*m_latch)( device_t *device, offs_t offset );
217   
218   // timers
219   emu_timer                   *m_hblank_timer;      /* hblank period at end of each scanline */
220   emu_timer                   *m_nmi_timer;         /* NMI timer */
221   emu_timer                   *m_scanline_timer;      /* scanline timer */
126222
223   const char        *m_cpu_tag;
224   const char        *m_screen_tag;
127225
128/***************************************************************************
129    DEVICE CONFIGURATION MACROS
130***************************************************************************/
226private:
227   static const device_timer_id TIMER_HBLANK = 0;
228   static const device_timer_id TIMER_NMI = 1;
229   static const device_timer_id TIMER_SCANLINE = 2;
131230
132#define MCFG_PPU2C02_ADD(_tag, _intrf)   \
133   MCFG_DEVICE_ADD(_tag, PPU_2C02, 0) \
134   MCFG_DEVICE_CONFIG(_intrf)
231   inline UINT8 readbyte(offs_t address);
232   inline void writebyte(offs_t address, UINT8 data);
233};
135234
136#define MCFG_PPU2C03B_ADD(_tag, _intrf)   \
137   MCFG_DEVICE_ADD(_tag, PPU_2C03B, 0) \
138   MCFG_DEVICE_CONFIG(_intrf)
235class ppu2c02_device : public ppu2c0x_device {
236public:
237   ppu2c02_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
238};
139239
140#define MCFG_PPU2C04_ADD(_tag, _intrf)   \
141   MCFG_DEVICE_ADD(_tag, PPU_2C04, 0) \
142   MCFG_DEVICE_CONFIG(_intrf)
240class ppu2c03b_device : public ppu2c0x_device {
241public:
242   ppu2c03b_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
243};
143244
144#define MCFG_PPU2C05_01_ADD(_tag, _intrf) \
145   MCFG_DEVICE_ADD(_tag, PPU_2C05_01, 0) \
146   MCFG_DEVICE_CONFIG(_intrf)
245class ppu2c04_device : public ppu2c0x_device {
246public:
247   ppu2c04_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
248};
147249
148#define MCFG_PPU2C05_02_ADD(_tag, _intrf) \
149   MCFG_DEVICE_ADD(_tag, PPU_2C05_02, 0) \
150   MCFG_DEVICE_CONFIG(_intrf)
250class ppu2c07_device : public ppu2c0x_device {
251public:
252   ppu2c07_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
253};
151254
152#define MCFG_PPU2C05_03_ADD(_tag, _intrf) \
153   MCFG_DEVICE_ADD(_tag, PPU_2C05_03, 0) \
154   MCFG_DEVICE_CONFIG(_intrf)
255class ppu2c05_01_device : public ppu2c0x_device {
256public:
257   ppu2c05_01_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
258};
155259
156#define MCFG_PPU2C05_04_ADD(_tag, _intrf) \
157   MCFG_DEVICE_ADD(_tag, PPU_2C05_04, 0) \
158   MCFG_DEVICE_CONFIG(_intrf)
260class ppu2c05_02_device : public ppu2c0x_device {
261public:
262   ppu2c05_02_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
263};
159264
160#define MCFG_PPU2C07_ADD(_tag, _intrf)   \
161   MCFG_DEVICE_ADD(_tag, PPU_2C07, 0) \
162   MCFG_DEVICE_CONFIG(_intrf)
265class ppu2c05_03_device : public ppu2c0x_device {
266public:
267   ppu2c05_03_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
268};
163269
164#endif /* __PPU_2C0X_H__ */
270class ppu2c05_04_device : public ppu2c0x_device {
271public:
272   ppu2c05_04_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
273};
274
275
276// device type definition
277//extern const device_type PPU_2C0X;
278extern const device_type PPU_2C02;   // NTSC NES
279extern const device_type PPU_2C03B;   // Playchoice 10
280extern const device_type PPU_2C04;   // Vs. Unisystem
281extern const device_type PPU_2C07;   // PAL NES
282extern const device_type PPU_2C05_01;   // Vs. Unisystem (Ninja Jajamaru Kun)
283extern const device_type PPU_2C05_02;   // Vs. Unisystem (Mighty Bomb Jack)
284extern const device_type PPU_2C05_03;   // Vs. Unisystem (Gumshoe)
285extern const device_type PPU_2C05_04;   // Vs. Unisystem (Top Gun)
286
287
288#endif
src/mess/machine/nes_pcb.c
r14138r14139
20032003         {
20042004            state->m_mmc5_vrom_regA[offset & 0x07] = data;
20052005            state->m_mmc5_last_chr_a = 1;
2006            if (ppu2c0x_get_current_scanline(state->m_ppu) == 240 || !ppu2c0x_is_sprite_8x16(state->m_ppu))
2006            if (state->m_ppu->get_current_scanline() == 240 || !state->m_ppu->is_sprite_8x16())
20072007               mmc5_update_chr_a(space->machine());
20082008         }
20092009         break;
r14138r14139
20162016         data |= (state->m_mmc5_chr_high << 8);
20172017         state->m_mmc5_vrom_regB[offset & 0x03] = data;
20182018         state->m_mmc5_last_chr_a = 0;
2019         if (ppu2c0x_get_current_scanline(state->m_ppu) == 240 || !ppu2c0x_is_sprite_8x16(state->m_ppu))
2019         if (state->m_ppu->get_current_scanline() == 240 || !state->m_ppu->is_sprite_8x16())
20202020            mmc5_update_chr_b(space->machine());
20212021         break;
20222022
r14138r14139
58115811      case 0x000:
58125812      case 0x200:
58135813         state->m_mmc_reg[BIT(offset, 9)] = data;
5814         if (!BIT(state->m_mmc_reg[0], 7) && ppu2c0x_get_current_scanline(state->m_ppu) <= 127)
5814         if (!BIT(state->m_mmc_reg[0], 7) && state->m_ppu->get_current_scanline() <= 127)
58155815            chr8(space->machine(), 0, CHRRAM);
58165816         break;
58175817      case 0x300:
r14138r14139
1198311983{
1198411984   nes_state *state = machine.driver_data<nes_state>();
1198511985   const nes_pcb_intf *intf = nes_pcb_intf_lookup(state->m_pcb_id);
11986   device_t *ppu = machine.device("ppu");
1198711986
1198811987   if (intf == NULL)
1198911988      fatalerror("Missing PCB interface\n");
r14138r14139
1200212001      state->m_mmc_read_mid_name = intf->mmc_m.read_name;
1200312002      state->m_mmc_read = intf->mmc_h.read;   // in progress
1200412003      state->m_mmc_read_name = intf->mmc_h.read_name;
12005      ppu2c0x_set_latch(ppu, intf->mmc_ppu_latch);
12004      state->m_ppu->set_latch(intf->mmc_ppu_latch);
1200612005   }
1200712006   else
1200812007   {
r14138r14139
1201312012      state->m_mmc_read_low = NULL;
1201412013      state->m_mmc_read_mid = NULL;   // in progress
1201512014      state->m_mmc_read = NULL;   // in progress
12016      ppu2c0x_set_latch(ppu, NULL);
12015      state->m_ppu->set_latch(NULL);
1201712016   }
1201812017
1201912018   state->m_mmc3_prg_cb = prg8_x;
r14138r14139
1302413023      fatalerror("Missing PCB interface\n");
1302513024
1302613025   /* Set the mapper irq callback */
13027   ppu2c0x_set_scanline_callback(state->m_ppu, intf ? intf->mmc_scanline : NULL);
13028   ppu2c0x_set_hblank_callback(state->m_ppu, intf ? intf->mmc_hblank : NULL);
13026   state->m_ppu->set_scanline_callback(intf ? intf->mmc_scanline : NULL);
13027   state->m_ppu->set_hblank_callback(intf ? intf->mmc_hblank : NULL);
1302913028
1303013029   err = pcb_initialize(machine, state->m_pcb_id);
1303113030
src/mess/machine/nes.c
r14138r14139
211211
212212   /* Reset the mapper variables. Will also mark the char-gen ram as dirty */
213213   if (state->m_disk_expansion && state->m_pcb_id == NO_BOARD)
214      ppu2c0x_set_hblank_callback(state->m_ppu, fds_irq);
214      state->m_ppu->set_hblank_callback(fds_irq);
215215   else
216216      nes_pcb_reset(machine);
217217
r14138r14139
299299   machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(nes_machine_stop),&machine));
300300
301301   state->m_maincpu = machine.device("maincpu");
302   state->m_ppu = machine.device("ppu");
302   state->m_ppu = machine.device<ppu2c0x_device>("ppu");
303303   state->m_sound = machine.device("nessound");
304304   state->m_cart = machine.device("cart");
305305
r14138r14139
348348         UINT32 pix, color_base;
349349
350350         /* get the pixel at the gun position */
351         pix = ppu2c0x_get_pixel(state->m_ppu, x, y);
351         pix = state->m_ppu->get_pixel(x, y);
352352
353353         /* get the color base from the ppu */
354         color_base = ppu2c0x_get_colorbase(state->m_ppu);
354         color_base = state->m_ppu->get_colorbase();
355355
356356         /* look at the screen and see if the cursor is over a bright pixel */
357357         if ((pix == color_base + 0x20) || (pix == color_base + 0x30) ||
r14138r14139
426426         UINT32 pix, color_base;
427427
428428         /* get the pixel at the gun position */
429         pix = ppu2c0x_get_pixel(state->m_ppu, x, y);
429         pix = state->m_ppu->get_pixel(x, y);
430430
431431         /* get the color base from the ppu */
432         color_base = ppu2c0x_get_colorbase(state->m_ppu);
432         color_base = state->m_ppu->get_colorbase();
433433
434434         /* look at the screen and see if the cursor is over a bright pixel */
435435         if ((pix == color_base + 0x20) || (pix == color_base + 0x30) ||
src/mess/video/nes.c
r14138r14139
1313
1414static void nes_vh_reset( running_machine &machine )
1515{
16   ppu2c0x_set_vidaccess_callback(machine.device("ppu"), nes_ppu_vidaccess);
16   nes_state *state = machine.driver_data<nes_state>();
17   state->m_ppu->set_vidaccess_callback(nes_ppu_vidaccess);
1718}
1819
1920VIDEO_START( nes )
r14138r14139
2728
2829PALETTE_INIT( nes )
2930{
30   ppu2c0x_init_palette(machine, 0);
31   nes_state *state = machine.driver_data<nes_state>();
32   state->m_ppu->init_palette(machine, 0);
3133}
3234
3335
r14138r14139
4244   nes_state *state = screen.machine().driver_data<nes_state>();
4345
4446   /* render the ppu */
45   ppu2c0x_render(state->m_ppu, bitmap, 0, 0, 0, 0);
47   state->m_ppu->render(bitmap, 0, 0, 0, 0);
4648
4749   /* if this is a disk system game, check for the flip-disk key */
4850   if (state->m_disk_expansion && state->m_pcb_id == NO_BOARD)
src/mess/includes/nes.h
r14138r14139
127127
128128   /* devices */
129129   device_t      *m_maincpu;
130   device_t      *m_ppu;
130   ppu2c0x_device      *m_ppu;
131131   device_t      *m_sound;
132132   device_t      *m_cart;
133133
src/mess/drivers/nes.c
r14138r14139
3939static WRITE8_HANDLER(nes_vh_sprite_dma_w)
4040{
4141   nes_state *state = space->machine().driver_data<nes_state>();
42   ppu2c0x_spriteram_dma(space, state->m_ppu, data);
42   state->m_ppu->spriteram_dma(space, data);
4343}
4444
4545static ADDRESS_MAP_START( nes_map, AS_PROGRAM, 8 )
4646   AM_RANGE(0x0000, 0x07ff) AM_RAM AM_MIRROR(0x1800)               /* RAM */
47   AM_RANGE(0x2000, 0x3fff) AM_DEVREADWRITE("ppu", ppu2c0x_r, ppu2c0x_w)      /* PPU registers */
47   AM_RANGE(0x2000, 0x3fff) AM_DEVREADWRITE_MODERN("ppu", ppu2c0x_device, read, write)      /* PPU registers */
4848   AM_RANGE(0x4000, 0x4013) AM_DEVREADWRITE("nessound", nes_psg_r, nes_psg_w)      /* PSG primary registers */
4949   AM_RANGE(0x4014, 0x4014) AM_WRITE(nes_vh_sprite_dma_w)            /* stupid address space hole */
5050   AM_RANGE(0x4015, 0x4015) AM_DEVREADWRITE("nessound", psg_4015_r, psg_4015_w)      /* PSG status / first control register */
r14138r14139
432432
433433static const ppu2c0x_interface nes_ppu_interface =
434434{
435   "maincpu",
436   "screen",
435437   0,
436438   0,
437439   PPU_MIRROR_NONE,

Previous 15994 Revisions Next


© 1998-2018 The MESS Team