Previous 199869 Revisions Next

r21560 Monday 4th March, 2013 at 10:23:47 UTC by Fabio Priuli
let's try to untangle a bit the knots between machine and PPU (part 2) + some cleanups... nw.
[src/mame/includes]snes.h
[src/mame/machine]snes.c
[src/mame/video]snes.c

trunk/src/mame/machine/snes.c
r21559r21560
9595   state->m_upd96050->dataram_w(addr/2, temp);
9696}
9797
98
99VIDEO_START( snes )
100{
101   snes_state *state = machine.driver_data<snes_state>();
102   state->m_ppu.ppu_start(machine);
103}
104
105UINT32 snes_state::snes_screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
106{
107   /* NTSC SNES draw range is 1-225. */
108   for (int y = cliprect.min_y; y <= cliprect.max_y; y++)
109      m_ppu.refresh_scanline(machine(), bitmap, y + 1);
110
111   return 0;
112}
113
114
98115/*************************************
99116
100117    Timers
r21559r21560
116133
117134   // latch the counters and pull IRQ
118135   // (don't need to switch to the 65816 context, we don't do anything dependant on it)
119   state->m_ppu.snes_latch_counters(machine, snes_ram);
136   state->m_ppu.latch_counters(machine, snes_ram);
120137   snes_ram[TIMEUP] = 0x80;    /* Indicate that irq occurred */
121138   state->m_maincpu->set_input_line(G65816_LINE_IRQ, ASSERT_LINE);
122139
r21559r21560
172189      {
173190         snes_ram[TIMEUP] = 0x80;    /* Indicate that irq occurred */
174191         // IRQ latches the counters, do it now
175         m_ppu.snes_latch_counters(machine(), snes_ram);
192         m_ppu.latch_counters(machine(), snes_ram);
176193         m_maincpu->set_input_line(G65816_LINE_IRQ, ASSERT_LINE );
177194      }
178195   }
r21559r21560
193210
194211      if (setirq)
195212      {
196//          printf("HIRQ @ %d, %d\n", pixel * m_htmult, m_ppu.m_beam.current_vert);
213//          printf("HIRQ @ %d, %d\n", pixel * m_ppu.m_htmult, m_ppu.m_beam.current_vert);
197214         if (pixel == 0)
198215         {
199216            snes_hirq_tick(machine());
200217         }
201218         else
202219         {
203            m_hirq_timer->adjust(machine().primary_screen->time_until_pos(m_ppu.m_beam.current_vert, pixel * m_htmult));
220            m_hirq_timer->adjust(machine().primary_screen->time_until_pos(m_ppu.m_beam.current_vert, pixel * m_ppu.m_htmult));
204221         }
205222      }
206223   }
r21559r21560
220237      }
221238
222239      /* three lines after start of vblank we update the controllers (value from snes9x) */
223      m_io_timer->adjust(machine().primary_screen->time_until_pos(m_ppu.m_beam.current_vert + 2, m_hblank_offset * m_htmult));
240      m_io_timer->adjust(machine().primary_screen->time_until_pos(m_ppu.m_beam.current_vert + 2, m_hblank_offset * m_ppu.m_htmult));
224241   }
225242
226243   // hdma reset happens at scanline 0, H=~6
r21559r21560
241258   }
242259
243260   m_scanline_timer->adjust(attotime::never);
244   m_hblank_timer->adjust(machine().primary_screen->time_until_pos(m_ppu.m_beam.current_vert, m_hblank_offset * m_htmult));
261   m_hblank_timer->adjust(machine().primary_screen->time_until_pos(m_ppu.m_beam.current_vert, m_hblank_offset * m_ppu.m_htmult));
245262
246263//  printf("%02x %d\n",snes_ram[HVBJOY],m_ppu.m_beam.current_vert);
247264}
r21559r21560
428445   // PPU accesses are from 2100 to 213f
429446   if (offset >= INIDISP && offset < APU00)
430447   {
431      return state->m_ppu.snes_ppu_read(space, offset, snes_ram);
448      return state->m_ppu.read(space, offset, snes_ram);
432449   }
433450
434451   // APU is mirrored from 2140 to 217f
r21559r21560
589606   // PPU accesses are from 2100 to 213f
590607   if (offset >= INIDISP && offset < APU00)
591608   {
592      state->m_ppu.snes_ppu_write(space, offset, data, snes_ram);
609      state->m_ppu.write(space, offset, data, snes_ram);
593610      return;
594611   }
595612
r21559r21560
690707         if (!(snes_ram[WRIO] & 0x80) && (data & 0x80))
691708         {
692709            // external latch
693            state->m_ppu.snes_latch_counters(space.machine(), snes_ram);
710            state->m_ppu.latch_counters(space.machine(), snes_ram);
694711         }
695712         break;
696713      case HTIMEL:    /* H-Count timer settings (low)  */
r21559r21560
15741591   }
15751592
15761593   /* Inititialize registers/variables */
1577   state->m_cgram_address = 0;
1578   state->m_vram_read_offset = 2;
1579   state->m_read_ophct = 0;
1580   state->m_read_opvct = 0;
1581
15821594   state->m_joy1l = state->m_joy1h = state->m_joy2l = state->m_joy2h = state->m_joy3l = state->m_joy3h = 0;
15831595   state->m_data1[0] = state->m_data2[0] = state->m_data1[1] = state->m_data2[1] = 0;
15841596
r21559r21560
16781690MACHINE_START( snes )
16791691{
16801692   snes_state *state = machine.driver_data<snes_state>();
1681   int i;
16821693
16831694   state->m_maincpu = machine.device<_5a22_device>("maincpu");
16841695   state->m_soundcpu = machine.device<spc700_device>("soundcpu");
r21559r21560
17121723
17131724   snes_init_timers(machine);
17141725
1715   for (i = 0; i < 6; i++)
1726   for (int i = 0; i < 6; i++)
17161727   {
17171728      state_save_register_item(machine, "snes_dma", NULL, i, state->m_dma_channel[i].dmap);
17181729      state_save_register_item(machine, "snes_dma", NULL, i, state->m_dma_channel[i].dest_addr);
r21559r21560
17271738      state_save_register_item(machine, "snes_dma", NULL, i, state->m_dma_channel[i].dma_disabled);
17281739   }
17291740
1730   state->save_item(NAME(state->m_htmult));
1731   state->save_item(NAME(state->m_cgram_address));
1732   state->save_item(NAME(state->m_vram_read_offset));
1733   state->save_item(NAME(state->m_read_ophct));
1734   state->save_item(NAME(state->m_read_opvct));
17351741   state->save_item(NAME(state->m_hblank_offset));
1736   state->save_item(NAME(state->m_vram_fgr_high));
1737   state->save_item(NAME(state->m_vram_fgr_increment));
1738   state->save_item(NAME(state->m_vram_fgr_count));
1739   state->save_item(NAME(state->m_vram_fgr_mask));
1740   state->save_item(NAME(state->m_vram_fgr_shift));
1741   state->save_item(NAME(state->m_vram_read_buffer));
17421742   state->save_item(NAME(state->m_wram_address));
17431743   state->save_item(NAME(state->m_htime));
17441744   state->save_item(NAME(state->m_vtime));
1745   state->save_item(NAME(state->m_vmadd));
17461745   state->save_item(NAME(state->m_hdmaen));
17471746   state->save_item(NAME(state->m_joy1l));
17481747   state->save_item(NAME(state->m_joy1h));
r21559r21560
17561755   state->save_item(NAME(state->m_data2));
17571756   state->save_item(NAME(state->m_read_idx));
17581757
1759   for (i = 0; i < 2; i++)
1758   for (int i = 0; i < 2; i++)
17601759   {
17611760      state_save_register_item(machine, "snes_dma", NULL, i, state->m_joypad[i].buttons);
17621761      state_save_register_item(machine, "snes_dma", NULL, i, state->m_mouse[i].x);
r21559r21560
18121811   state->m_htime = 0x1ff;
18131812   state->m_vtime = 0x1ff;
18141813
1815   state->m_htmult = 1;
1814   state->m_ppu.m_htmult = 1;
18161815   state->m_ppu.m_interlace = 1;
18171816   state->m_ppu.m_obj_interlace = 1;
18181817}
trunk/src/mame/video/snes.c
r21559r21560
130130};
131131
132132/*****************************************
133 * snes_get_bgcolor()
133 * get_bgcolor()
134134 *
135135 * Get the proper color (direct or from cgram)
136136 *****************************************/
137137
138inline UINT16 snes_ppu_class::snes_get_bgcolor( UINT8 direct_colors, UINT16 palette, UINT8 color )
138inline UINT16 snes_ppu_class::get_bgcolor( UINT8 direct_colors, UINT16 palette, UINT8 color )
139139{
140140   UINT16 c = 0;
141141
r21559r21560
152152}
153153
154154/*****************************************
155 * snes_set_scanline_pixel()
155 * set_scanline_pixel()
156156 *
157157 * Store pixel color, priority, layer and
158158 * color math exception (for OAM) in the
159159 * proper scanline
160160 *****************************************/
161161
162inline void snes_ppu_class::snes_set_scanline_pixel( int screen, INT16 x, UINT16 color, UINT8 priority, UINT8 layer, int blend )
162inline void snes_ppu_class::set_scanline_pixel( int screen, INT16 x, UINT16 color, UINT8 priority, UINT8 layer, int blend )
163163{
164164   scanlines[screen].buffer[x] = color;
165165   scanlines[screen].priority[x] = priority;
r21559r21560
178178 *************************************************************************************************/
179179
180180/*****************************************
181 * snes_draw_bgtile_lores()
182 * snes_draw_bgtile_hires()
183 * snes_draw_oamtile_()
181 * draw_bgtile_lores()
182 * draw_bgtile_hires()
183 * draw_oamtile_()
184184 *
185185 * Check if a pixel is clipped or not, and
186186 * copy it to the scanline buffer when
r21559r21560
190190 * or lores)
191191 *****************************************/
192192
193inline void snes_ppu_class::snes_draw_bgtile_lores( UINT8 layer, INT16 ii, UINT8 colour, UINT16 pal, UINT8 direct_colors, UINT8 priority )
193inline void snes_ppu_class::draw_bgtile_lores( UINT8 layer, INT16 ii, UINT8 colour, UINT16 pal, UINT8 direct_colors, UINT8 priority )
194194{
195195   int screen;
196196   UINT16 c;
r21559r21560
216216            /* Only draw if we have a colour (0 == transparent) */
217217            if (clr)
218218            {
219               c = snes_get_bgcolor(direct_colors, pal, clr);
220               snes_set_scanline_pixel(screen, ii, c, priority, layer, 0);
219               c = get_bgcolor(direct_colors, pal, clr);
220               set_scanline_pixel(screen, ii, c, priority, layer, 0);
221221            }
222222         }
223223      }
224224   }
225225}
226226
227inline void snes_ppu_class::snes_draw_bgtile_hires( UINT8 layer, INT16 ii, UINT8 colour, UINT16 pal, UINT8 direct_colors, UINT8 priority )
227inline void snes_ppu_class::draw_bgtile_hires( UINT8 layer, INT16 ii, UINT8 colour, UINT16 pal, UINT8 direct_colors, UINT8 priority )
228228{
229229   int screen;
230230   UINT16 c;
r21559r21560
251251            /* Only draw if we have a colour (0 == transparent) */
252252            if (clr)
253253            {
254               c = snes_get_bgcolor(direct_colors, pal, clr);
255               snes_set_scanline_pixel(screen, ii >> 1, c, priority, layer, 0);
254               c = get_bgcolor(direct_colors, pal, clr);
255               set_scanline_pixel(screen, ii >> 1, c, priority, layer, 0);
256256            }
257257         }
258258      }
259259   }
260260}
261261
262inline void snes_ppu_class::snes_draw_oamtile( INT16 ii, UINT8 colour, UINT16 pal, UINT8 priority )
262inline void snes_ppu_class::draw_oamtile( INT16 ii, UINT8 colour, UINT16 pal, UINT8 priority )
263263{
264264   int screen;
265265   int blend;
r21559r21560
287287         {
288288            c = m_cgram[(pal + clr) % FIXED_COLOUR];
289289            blend = (pal + clr < 192) ? 1 : 0;
290            snes_set_scanline_pixel(screen, pos, c, priority, SNES_OAM, blend);
290            set_scanline_pixel(screen, pos, c, priority, SNES_OAM, blend);
291291         }
292292      }
293293   }
294294}
295295
296296/*****************************************
297 * snes_draw_tile()
297 * draw_tile()
298298 *
299299 * Draw 8 pixels from the expected tile
300300 * by reading the color planes from vram
r21559r21560
302302 * (depending on layer and resolution)
303303 *****************************************/
304304
305inline void snes_ppu_class::snes_draw_tile( UINT8 planes, UINT8 layer, UINT32 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT8 direct_colors, UINT16 pal, UINT8 hires )
305inline void snes_ppu_class::draw_tile( UINT8 planes, UINT8 layer, UINT32 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT8 direct_colors, UINT16 pal, UINT8 hires )
306306{
307307   UINT8 plane[8];
308308   INT16 ii, jj;
r21559r21560
336336      }
337337
338338      if (layer == SNES_OAM)
339         snes_draw_oamtile(ii, colour, pal, priority);
339         draw_oamtile(ii, colour, pal, priority);
340340      else if (!hires)
341341      {
342342         if (mosaic)
343343         {
344344            for (x_mos = 0; x_mos < (m_mosaic_size + 1); x_mos++)
345               snes_draw_bgtile_lores(layer, ii + x_mos, colour, pal, direct_colors, priority);
345               draw_bgtile_lores(layer, ii + x_mos, colour, pal, direct_colors, priority);
346346            ii += x_mos - 1;
347347         }
348348         else
349            snes_draw_bgtile_lores(layer, ii, colour, pal, direct_colors, priority);
349            draw_bgtile_lores(layer, ii, colour, pal, direct_colors, priority);
350350      }
351351      else /* hires */
352352      {
353353         if (mosaic)
354354         {
355355            for (x_mos = 0; x_mos < (m_mosaic_size + 1); x_mos++)
356               snes_draw_bgtile_hires(layer, ii + x_mos, colour, pal, direct_colors, priority);
356               draw_bgtile_hires(layer, ii + x_mos, colour, pal, direct_colors, priority);
357357            ii += x_mos - 1;
358358         }
359359         else
360            snes_draw_bgtile_hires(layer, ii, colour, pal, direct_colors, priority);
360            draw_bgtile_hires(layer, ii, colour, pal, direct_colors, priority);
361361      }
362362   }
363363}
r21559r21560
368368 * BG drawing theory of each scanline is quite easy: depending on the graphics Mode (0-7), there
369369 * are up to 4 background layers. Pixels for each BG layer can have two different priorities.
370370 * Depending on the line and on the BGHOFS and BGVOFS PPU registers, we first determine the tile
371 * address in m_vram (by determining x,y coord and tile size and by calling snes_get_tmap_addr).
371 * address in m_vram (by determining x,y coord and tile size and by calling get_tmap_addr).
372372 * Then, we load the correspondent data and we determine the tile properties: which priority to
373373 * use, which palette etc. Finally, for each pixel of the tile appearing on screen, we check if
374374 * the tile priority is higher than the BG/OAM already stored in that pixel for that line. If so
r21559r21560
380380 *************************************************************************************************/
381381
382382/*********************************************
383 * snes_get_tmap_addr()
383 * get_tmap_addr()
384384 *
385385 * Find the address in VRAM of the tile (x,y)
386386 *********************************************/
387387
388inline UINT32 snes_ppu_class::snes_get_tmap_addr( UINT8 layer, UINT8 tile_size, UINT32 base, UINT32 x, UINT32 y )
388inline UINT32 snes_ppu_class::get_tmap_addr( UINT8 layer, UINT8 tile_size, UINT32 base, UINT32 x, UINT32 y )
389389{
390390   UINT32 res = base;
391391   x  >>= (3 + tile_size);
r21559r21560
403403}
404404
405405/*********************************************
406 * snes_update_line()
406 * update_line()
407407 *
408408 * Update an entire line of tiles.
409409 *********************************************/
410410
411inline void snes_ppu_class::snes_update_line( UINT16 curline, UINT8 layer, UINT8 priority_b, UINT8 priority_a, UINT8 color_depth, UINT8 hires, UINT8 offset_per_tile, UINT8 direct_colors )
411inline void snes_ppu_class::update_line( UINT16 curline, UINT8 layer, UINT8 priority_b, UINT8 priority_a, UINT8 color_depth, UINT8 hires, UINT8 offset_per_tile, UINT8 direct_colors )
412412{
413413   UINT32 tmap, tile, xoff, yoff, charaddr, addr;
414414   UINT16 ii = 0, vflip, hflip, pal, pal_direct, tilemap;
r21559r21560
473473            {
474474            case SNES_OPT_MODE2:
475475            case SNES_OPT_MODE6:
476               haddr = snes_get_tmap_addr(SNES_BG3, m_layer[SNES_BG3].tile_size, m_layer[SNES_BG3].tilemap << 9, (opt_x - 8) + ((m_layer[SNES_BG3].hoffs & 0x3ff) & ~7), (m_layer[SNES_BG3].voffs & 0x3ff));
477               vaddr = snes_get_tmap_addr(SNES_BG3, m_layer[SNES_BG3].tile_size, m_layer[SNES_BG3].tilemap << 9, (opt_x - 8) + ((m_layer[SNES_BG3].hoffs & 0x3ff) & ~7), (m_layer[SNES_BG3].voffs & 0x3ff) + 8);
476               haddr = get_tmap_addr(SNES_BG3, m_layer[SNES_BG3].tile_size, m_layer[SNES_BG3].tilemap << 9, (opt_x - 8) + ((m_layer[SNES_BG3].hoffs & 0x3ff) & ~7), (m_layer[SNES_BG3].voffs & 0x3ff));
477               vaddr = get_tmap_addr(SNES_BG3, m_layer[SNES_BG3].tile_size, m_layer[SNES_BG3].tilemap << 9, (opt_x - 8) + ((m_layer[SNES_BG3].hoffs & 0x3ff) & ~7), (m_layer[SNES_BG3].voffs & 0x3ff) + 8);
478478               hval = m_vram[haddr % SNES_VRAM_SIZE] | (m_vram[(haddr + 1) % SNES_VRAM_SIZE] << 8);
479479               vval = m_vram[vaddr % SNES_VRAM_SIZE] | (m_vram[(vaddr + 1) % SNES_VRAM_SIZE] << 8);
480480               if (BIT(hval, opt_bit))
r21559r21560
483483                  ypos = curline + vval;
484484               break;
485485            case SNES_OPT_MODE4:
486               haddr = snes_get_tmap_addr(SNES_BG3, m_layer[SNES_BG3].tile_size, m_layer[SNES_BG3].tilemap << 9, (opt_x - 8) + ((m_layer[SNES_BG3].hoffs & 0x3ff) & ~7), (m_layer[SNES_BG3].voffs & 0x3ff));
486               haddr = get_tmap_addr(SNES_BG3, m_layer[SNES_BG3].tile_size, m_layer[SNES_BG3].tilemap << 9, (opt_x - 8) + ((m_layer[SNES_BG3].hoffs & 0x3ff) & ~7), (m_layer[SNES_BG3].voffs & 0x3ff));
487487               hval = m_vram[haddr % SNES_VRAM_SIZE] | (m_vram[(haddr + 1) % SNES_VRAM_SIZE] << 8);
488488               if (BIT(hval, opt_bit))
489489               {
r21559r21560
497497         }
498498      }
499499
500      addr = snes_get_tmap_addr(layer, tile_size, tmap, xpos, ypos);
500      addr = get_tmap_addr(layer, tile_size, tmap, xpos, ypos);
501501
502502      /*
503503      Tilemap format
r21559r21560
566566      if (hires)
567567      {
568568         /* draw 16 pixels (the routine will automatically send half of them to the mainscreen scanline and half to the subscreen one) */
569         snes_draw_tile(color_planes, layer, charaddr + (((tile + 0)         & 0x3ff) * 8 * color_planes) + yscroll, (ii - xscroll) * 2,     priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires);
570         snes_draw_tile(color_planes, layer, charaddr + (((tile + tile_incr) & 0x3ff) * 8 * color_planes) + yscroll, (ii - xscroll) * 2 + 8, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires);
569         draw_tile(color_planes, layer, charaddr + (((tile + 0)         & 0x3ff) * 8 * color_planes) + yscroll, (ii - xscroll) * 2,     priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires);
570         draw_tile(color_planes, layer, charaddr + (((tile + tile_incr) & 0x3ff) * 8 * color_planes) + yscroll, (ii - xscroll) * 2 + 8, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires);
571571         ii += 8;
572572      }
573573      else
574574      {
575         snes_draw_tile(color_planes, layer, charaddr + ((tile & 0x3ff) * 8 * color_planes) + yscroll, ii - xscroll, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires);
575         draw_tile(color_planes, layer, charaddr + ((tile & 0x3ff) * 8 * color_planes) + yscroll, ii - xscroll, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires);
576576         ii += 8;
577577
578578         if (tile_size)
579579         {
580            snes_draw_tile(color_planes, layer, charaddr + (((tile + tile_incr) & 0x3ff) * 8 * color_planes) + yscroll, ii - xscroll, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires);
580            draw_tile(color_planes, layer, charaddr + (((tile + tile_incr) & 0x3ff) * 8 * color_planes) + yscroll, ii - xscroll, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires);
581581            ii += 8;
582582         }
583583      }
r21559r21560
586586
587587
588588/*********************************************
589 * snes_update_line_mode7()
589 * update_line_mode7()
590590 *
591591 * Update an entire line of mode7 tiles.
592592 *********************************************/
593593
594594#define MODE7_CLIP(x) (((x) & 0x2000) ? ((x) | ~0x03ff) : ((x) & 0x03ff))
595595
596void snes_ppu_class::snes_update_line_mode7( UINT16 curline, UINT8 layer, UINT8 priority_b, UINT8 priority_a )
596void snes_ppu_class::update_line_mode7( UINT16 curline, UINT8 layer, UINT8 priority_b, UINT8 priority_a )
597597{
598598   UINT32 tiled;
599599   INT16 ma, mb, mc, md;
r21559r21560
748748               /* Direct select, but only outside EXTBG! */
749749               // Direct color format is: 0 | BB000 | GGG00 | RRR00, HW confirms that the data is zero padded.
750750               // In other words, like normal direct color, with pal = 0
751               c = snes_get_bgcolor(m_direct_color && layer == SNES_BG1, 0, clr);
752               snes_set_scanline_pixel(screen, xpos, c, priority, layer, 0);
751               c = get_bgcolor(m_direct_color && layer == SNES_BG1, 0, clr);
752               set_scanline_pixel(screen, xpos, c, priority, layer, 0);
753753            }
754754         }
755755      }
r21559r21560
761761 *
762762 * 1. First of all: sprites are drawn one line in advance. We emulate this by caching the
763763 * starting vram address, the sprite size and the "name select" at each line, and by using
764 * them the next line to output the proper sprites - see snes_update_obsel.
764 * them the next line to output the proper sprites - see update_obsel.
765765 *
766766 * 2. Each line can select its sprites among 128 available ones in oam_ram, hence we start
767767 * by creating a list of the available objects (each one with its x,y coordinate, its size,
768 * its tile address, etc.) - see snes_oam_list_build.
768 * its tile address, etc.) - see oam_list_build.
769769 *
770770 * 3. Next, we start finding out which sprites will appear in the line: starting from
771771 * FirstSprite, we count 32 OBJs which intersect our line and we store their indexes in the
r21559r21560
778778 * item which intersects the scanline), towards oam_itemlist[0], i.e. the higher tiles (say
779779 * oam_tilelist[34], or the last tile which appear on screen) will contain FirstSprite object,
780780 * or the sprites with closer index to FirstSprite which get displayed. This will play an
781 * important role for sprite priority - see snes_update_objects_rto.
781 * important role for sprite priority - see update_objects_rto.
782782 *
783783 * 4. All the above happens at the beginning of each VIDEO_UPDATE. When we finally draw the
784784 * scanline, we pass through the oam_tilelist and we store the displayed pixels in our scanline
r21559r21560
789789 * priorities are (differently from what we did with BGs): in the end, we will have in each pixel z
790790 * its topmost sprite and scanline.priority[z] will be the topmost sprite priority as expected.
791791 * Of course, sprite drawing must happen before BG drawing, so that afterwords BG pixels properly
792 * test their priority with the one of the correct sprite - see snes_update_objects.
792 * test their priority with the one of the correct sprite - see update_objects.
793793 *************************************************************************************************/
794794
795795struct OAM
r21559r21560
813813static struct TILELIST oam_tilelist[34];
814814
815815/*********************************************
816 * snes_update_obsel()
816 * update_obsel()
817817 *
818818 * Update sprite settings for next line.
819819 *********************************************/
820820
821void snes_ppu_class::snes_update_obsel( void )
821void snes_ppu_class::update_obsel( void )
822822{
823823   m_layer[SNES_OAM].charmap = m_oam.next_charmap;
824824   m_oam.name_select = m_oam.next_name_select;
r21559r21560
831831}
832832
833833/*********************************************
834 * snes_oam_list_build()
834 * oam_list_build()
835835 *
836836 * Build a list of the available obj in OAM ram.
837837 *********************************************/
838838
839void snes_ppu_class::snes_oam_list_build( void )
839void snes_ppu_class::oam_list_build( void )
840840{
841841   UINT8 *oamram = (UINT8 *)m_oam_ram;
842842   INT16 oam = 0x1ff;
r21559r21560
942942}
943943
944944/*********************************************
945 * snes_update_objects_rto()
945 * update_objects_rto()
946946 *
947947 * Determine which OBJs will be drawn on this
948948 * scanline.
949949 *********************************************/
950950
951void snes_ppu_class::snes_update_objects_rto( UINT16 curline )
951void snes_ppu_class::update_objects_rto( UINT16 curline )
952952{
953953   int ii, jj, active_sprite;
954954   UINT8 range_over, time_over;
r21559r21560
959959   INT16 x, y;
960960   UINT32 name_sel = 0;
961961
962   snes_oam_list_build();
962   oam_list_build();
963963
964964   /* initialize counters */
965965   range_over = 0;
r21559r21560
10571057}
10581058
10591059/*********************************************
1060 * snes_update_objects()
1060 * update_objects()
10611061 *
10621062 * Update an entire line of sprites.
10631063 *********************************************/
10641064
1065void snes_ppu_class::snes_update_objects( UINT8 priority_oam0, UINT8 priority_oam1, UINT8 priority_oam2, UINT8 priority_oam3 )
1065void snes_ppu_class::update_objects( UINT8 priority_oam0, UINT8 priority_oam1, UINT8 priority_oam2, UINT8 priority_oam3 )
10661066{
10671067   UINT8 pri, priority[4];
10681068   UINT32 charaddr;
r21559r21560
11121112#endif /* SNES_LAYER_DEBUG */
11131113
11141114      /* OAM tiles have fixed planes (4), no direct color and no hires, but otherwise work the same as BG ones */
1115      snes_draw_tile(4, SNES_OAM, charaddr + oam_tilelist[tile].tileaddr, oam_tilelist[tile].x, pri, oam_tilelist[tile].hflip, 0, oam_tilelist[tile].pal, 0);
1115      draw_tile(4, SNES_OAM, charaddr + oam_tilelist[tile].tileaddr, oam_tilelist[tile].x, pri, oam_tilelist[tile].hflip, 0, oam_tilelist[tile].pal, 0);
11161116   }
11171117}
11181118
r21559r21560
11231123 * Update Mode X line.
11241124 *********************************************/
11251125
1126void snes_ppu_class::snes_update_mode_0( UINT16 curline )
1126void snes_ppu_class::update_mode_0( UINT16 curline )
11271127{
11281128#if SNES_LAYER_DEBUG
11291129   if (debug_options.mode_disabled[0])
11301130      return;
11311131#endif /* SNES_LAYER_DEBUG */
11321132
1133   snes_update_objects(3, 6, 9, 12);
1134   snes_update_line(curline, SNES_BG1, 8, 11, SNES_COLOR_DEPTH_2BPP, 0, SNES_OPT_NONE, 0);
1135   snes_update_line(curline, SNES_BG2, 7, 10, SNES_COLOR_DEPTH_2BPP, 0, SNES_OPT_NONE, 0);
1136   snes_update_line(curline, SNES_BG3, 2, 5,  SNES_COLOR_DEPTH_2BPP, 0, SNES_OPT_NONE, 0);
1137   snes_update_line(curline, SNES_BG4, 1, 4,  SNES_COLOR_DEPTH_2BPP, 0, SNES_OPT_NONE, 0);
1133   update_objects(3, 6, 9, 12);
1134   update_line(curline, SNES_BG1, 8, 11, SNES_COLOR_DEPTH_2BPP, 0, SNES_OPT_NONE, 0);
1135   update_line(curline, SNES_BG2, 7, 10, SNES_COLOR_DEPTH_2BPP, 0, SNES_OPT_NONE, 0);
1136   update_line(curline, SNES_BG3, 2, 5,  SNES_COLOR_DEPTH_2BPP, 0, SNES_OPT_NONE, 0);
1137   update_line(curline, SNES_BG4, 1, 4,  SNES_COLOR_DEPTH_2BPP, 0, SNES_OPT_NONE, 0);
11381138}
11391139
1140void snes_ppu_class::snes_update_mode_1( UINT16 curline )
1140void snes_ppu_class::update_mode_1( UINT16 curline )
11411141{
11421142#if SNES_LAYER_DEBUG
11431143   if (debug_options.mode_disabled[1])
r21559r21560
11461146
11471147   if (!m_bg3_priority_bit)
11481148   {
1149      snes_update_objects(2, 4, 7, 10);
1150      snes_update_line(curline, SNES_BG1, 6, 9, SNES_COLOR_DEPTH_4BPP, 0, SNES_OPT_NONE, 0);
1151      snes_update_line(curline, SNES_BG2, 5, 8, SNES_COLOR_DEPTH_4BPP, 0, SNES_OPT_NONE, 0);
1152      snes_update_line(curline, SNES_BG3, 1, 3, SNES_COLOR_DEPTH_2BPP, 0, SNES_OPT_NONE, 0);
1149      update_objects(2, 4, 7, 10);
1150      update_line(curline, SNES_BG1, 6, 9, SNES_COLOR_DEPTH_4BPP, 0, SNES_OPT_NONE, 0);
1151      update_line(curline, SNES_BG2, 5, 8, SNES_COLOR_DEPTH_4BPP, 0, SNES_OPT_NONE, 0);
1152      update_line(curline, SNES_BG3, 1, 3, SNES_COLOR_DEPTH_2BPP, 0, SNES_OPT_NONE, 0);
11531153   }
11541154   else
11551155   {
1156      snes_update_objects(2, 3, 6, 9);
1157      snes_update_line(curline, SNES_BG1, 5, 8,  SNES_COLOR_DEPTH_4BPP, 0, SNES_OPT_NONE, 0);
1158      snes_update_line(curline, SNES_BG2, 4, 7,  SNES_COLOR_DEPTH_4BPP, 0, SNES_OPT_NONE, 0);
1159      snes_update_line(curline, SNES_BG3, 1, 10, SNES_COLOR_DEPTH_2BPP, 0, SNES_OPT_NONE, 0);
1156      update_objects(2, 3, 6, 9);
1157      update_line(curline, SNES_BG1, 5, 8,  SNES_COLOR_DEPTH_4BPP, 0, SNES_OPT_NONE, 0);
1158      update_line(curline, SNES_BG2, 4, 7,  SNES_COLOR_DEPTH_4BPP, 0, SNES_OPT_NONE, 0);
1159      update_line(curline, SNES_BG3, 1, 10, SNES_COLOR_DEPTH_2BPP, 0, SNES_OPT_NONE, 0);
11601160   }
11611161}
11621162
1163void snes_ppu_class::snes_update_mode_2( UINT16 curline )
1163void snes_ppu_class::update_mode_2( UINT16 curline )
11641164{
11651165#if SNES_LAYER_DEBUG
11661166   if (debug_options.mode_disabled[2])
11671167      return;
11681168#endif /* SNES_LAYER_DEBUG */
11691169
1170   snes_update_objects(2, 4, 6, 8);
1171   snes_update_line(curline, SNES_BG1, 3, 7, SNES_COLOR_DEPTH_4BPP, 0, SNES_OPT_MODE2, 0);
1172   snes_update_line(curline, SNES_BG2, 1, 5, SNES_COLOR_DEPTH_4BPP, 0, SNES_OPT_MODE2, 0);
1170   update_objects(2, 4, 6, 8);
1171   update_line(curline, SNES_BG1, 3, 7, SNES_COLOR_DEPTH_4BPP, 0, SNES_OPT_MODE2, 0);
1172   update_line(curline, SNES_BG2, 1, 5, SNES_COLOR_DEPTH_4BPP, 0, SNES_OPT_MODE2, 0);
11731173}
11741174
1175void snes_ppu_class::snes_update_mode_3( UINT16 curline )
1175void snes_ppu_class::update_mode_3( UINT16 curline )
11761176{
11771177#if SNES_LAYER_DEBUG
11781178   if (debug_options.mode_disabled[3])
11791179      return;
11801180#endif /* SNES_LAYER_DEBUG */
11811181
1182   snes_update_objects(2, 4, 6, 8);
1183   snes_update_line(curline, SNES_BG1, 3, 7, SNES_COLOR_DEPTH_8BPP, 0, SNES_OPT_NONE, m_direct_color);
1184   snes_update_line(curline, SNES_BG2, 1, 5, SNES_COLOR_DEPTH_4BPP, 0, SNES_OPT_NONE, 0);
1182   update_objects(2, 4, 6, 8);
1183   update_line(curline, SNES_BG1, 3, 7, SNES_COLOR_DEPTH_8BPP, 0, SNES_OPT_NONE, m_direct_color);
1184   update_line(curline, SNES_BG2, 1, 5, SNES_COLOR_DEPTH_4BPP, 0, SNES_OPT_NONE, 0);
11851185}
11861186
1187void snes_ppu_class::snes_update_mode_4( UINT16 curline )
1187void snes_ppu_class::update_mode_4( UINT16 curline )
11881188{
11891189#if SNES_LAYER_DEBUG
11901190   if (debug_options.mode_disabled[4])
11911191      return;
11921192#endif /* SNES_LAYER_DEBUG */
11931193
1194   snes_update_objects(2, 4, 6, 8);
1195   snes_update_line(curline, SNES_BG1, 3, 7, SNES_COLOR_DEPTH_8BPP, 0, SNES_OPT_MODE4, m_direct_color);
1196   snes_update_line(curline, SNES_BG2, 1, 5, SNES_COLOR_DEPTH_2BPP, 0, SNES_OPT_MODE4, 0);
1194   update_objects(2, 4, 6, 8);
1195   update_line(curline, SNES_BG1, 3, 7, SNES_COLOR_DEPTH_8BPP, 0, SNES_OPT_MODE4, m_direct_color);
1196   update_line(curline, SNES_BG2, 1, 5, SNES_COLOR_DEPTH_2BPP, 0, SNES_OPT_MODE4, 0);
11971197}
11981198
1199void snes_ppu_class::snes_update_mode_5( UINT16 curline )
1199void snes_ppu_class::update_mode_5( UINT16 curline )
12001200{
12011201#if SNES_LAYER_DEBUG
12021202   if (debug_options.mode_disabled[5])
12031203      return;
12041204#endif /* SNES_LAYER_DEBUG */
12051205
1206   snes_update_objects(2, 4, 6, 8);
1207   snes_update_line(curline, SNES_BG1, 3, 7, SNES_COLOR_DEPTH_4BPP, 1, SNES_OPT_NONE, 0);
1208   snes_update_line(curline, SNES_BG2, 1, 5, SNES_COLOR_DEPTH_2BPP, 1, SNES_OPT_NONE, 0);
1206   update_objects(2, 4, 6, 8);
1207   update_line(curline, SNES_BG1, 3, 7, SNES_COLOR_DEPTH_4BPP, 1, SNES_OPT_NONE, 0);
1208   update_line(curline, SNES_BG2, 1, 5, SNES_COLOR_DEPTH_2BPP, 1, SNES_OPT_NONE, 0);
12091209}
12101210
1211void snes_ppu_class::snes_update_mode_6( UINT16 curline )
1211void snes_ppu_class::update_mode_6( UINT16 curline )
12121212{
12131213#if SNES_LAYER_DEBUG
12141214   if (debug_options.mode_disabled[6])
12151215      return;
12161216#endif /* SNES_LAYER_DEBUG */
12171217
1218   snes_update_objects(1, 3, 4, 6);
1219   snes_update_line(curline, SNES_BG1, 2, 5, SNES_COLOR_DEPTH_4BPP, 1, SNES_OPT_MODE6, 0);
1218   update_objects(1, 3, 4, 6);
1219   update_line(curline, SNES_BG1, 2, 5, SNES_COLOR_DEPTH_4BPP, 1, SNES_OPT_MODE6, 0);
12201220}
12211221
1222void snes_ppu_class::snes_update_mode_7( UINT16 curline )
1222void snes_ppu_class::update_mode_7( UINT16 curline )
12231223{
12241224#if SNES_LAYER_DEBUG
12251225   if (debug_options.mode_disabled[7])
r21559r21560
12281228
12291229   if (!m_mode7.extbg)
12301230   {
1231      snes_update_objects(1, 3, 4, 5);
1232      snes_update_line_mode7(curline, SNES_BG1, 2, 2);
1231      update_objects(1, 3, 4, 5);
1232      update_line_mode7(curline, SNES_BG1, 2, 2);
12331233   }
12341234   else
12351235   {
1236      snes_update_objects(2, 4, 6, 7);
1237      snes_update_line_mode7(curline, SNES_BG1, 3, 3);
1238      snes_update_line_mode7(curline, SNES_BG2, 1, 5);
1236      update_objects(2, 4, 6, 7);
1237      update_line_mode7(curline, SNES_BG1, 3, 3);
1238      update_line_mode7(curline, SNES_BG2, 1, 5);
12391239   }
12401240}
12411241
r21559r21560
12451245 * Draw the whole screen (Mode 0 -> 7).
12461246 *********************************************/
12471247
1248void snes_ppu_class::snes_draw_screens( UINT16 curline )
1248void snes_ppu_class::draw_screens( UINT16 curline )
12491249{
12501250   switch (m_mode)
12511251   {
1252      case 0: snes_update_mode_0(curline); break;     /* Mode 0 */
1253      case 1: snes_update_mode_1(curline); break;     /* Mode 1 */
1254      case 2: snes_update_mode_2(curline); break;     /* Mode 2 - Supports offset per tile */
1255      case 3: snes_update_mode_3(curline); break;     /* Mode 3 - Supports direct colour */
1256      case 4: snes_update_mode_4(curline); break;     /* Mode 4 - Supports offset per tile and direct colour */
1257      case 5: snes_update_mode_5(curline); break;     /* Mode 5 - Supports hires */
1258      case 6: snes_update_mode_6(curline); break;     /* Mode 6 - Supports offset per tile and hires */
1259      case 7: snes_update_mode_7(curline); break;     /* Mode 7 - Supports direct colour */
1252      case 0: update_mode_0(curline); break;     /* Mode 0 */
1253      case 1: update_mode_1(curline); break;     /* Mode 1 */
1254      case 2: update_mode_2(curline); break;     /* Mode 2 - Supports offset per tile */
1255      case 3: update_mode_3(curline); break;     /* Mode 3 - Supports direct colour */
1256      case 4: update_mode_4(curline); break;     /* Mode 4 - Supports offset per tile and direct colour */
1257      case 5: update_mode_5(curline); break;     /* Mode 5 - Supports hires */
1258      case 6: update_mode_6(curline); break;     /* Mode 6 - Supports offset per tile and hires */
1259      case 7: update_mode_7(curline); break;     /* Mode 7 - Supports direct colour */
12601260   }
12611261}
12621262
12631263/*********************************************
1264 * snes_update_windowmasks()
1264 * update_windowmasks()
12651265 *
12661266 * An example of how windows work:
12671267 * Win1: ...#####......
r21559r21560
12731273 * XNOR: ###...##...###     ...###..###...
12741274 *********************************************/
12751275
1276void snes_ppu_class::snes_update_windowmasks( void )
1276void snes_ppu_class::update_windowmasks( void )
12771277{
12781278   UINT16 ii, jj;
12791279   INT8 w1, w2;
r21559r21560
13401340}
13411341
13421342/*********************************************
1343 * snes_update_offsets()
1343 * update_offsets()
13441344 *
13451345 * Update the offsets with the latest changes.
13461346 * This is currently unused, but it could
13471347 * possibly be handy for some minor optimization
13481348 *********************************************/
13491349
1350void snes_ppu_class::snes_update_offsets( void )
1350void snes_ppu_class::update_offsets( void )
13511351{
13521352   int ii;
13531353   for (ii = 0; ii < 4; ii++)
r21559r21560
13571357}
13581358
13591359/*****************************************
1360 * snes_draw_blend()
1360 * draw_blend()
13611361 *
13621362 * Routine for additive/subtractive blending
13631363 * between the main and sub screens, i.e.
13641364 * color math.
13651365 *****************************************/
13661366
1367inline void snes_ppu_class::snes_draw_blend( UINT16 offset, UINT16 *colour, UINT8 prevent_color_math, UINT8 black_pen_clip, int switch_screens )
1367inline void snes_ppu_class::draw_blend( UINT16 offset, UINT16 *colour, UINT8 prevent_color_math, UINT8 black_pen_clip, int switch_screens )
13681368{
13691369#if SNES_LAYER_DEBUG
13701370   if (debug_options.colormath_disabled)
r21559r21560
13721372#endif /* SNES_LAYER_DEBUG */
13731373
13741374   /* when color math is applied to subscreen pixels, the blending depends on the blending used by the previous mainscreen
1375   pixel, except for subscreen pixel 0 which has no previous mainscreen pixel, see comments in snes_refresh_scanline */
1375   pixel, except for subscreen pixel 0 which has no previous mainscreen pixel, see comments in refresh_scanline */
13761376   if (switch_screens && offset > 0)
13771377      offset -= 1;
13781378
r21559r21560
14741474}
14751475
14761476/*********************************************
1477 * snes_refresh_scanline()
1477 * refresh_scanline()
14781478 *
14791479 * Redraw the current line.
14801480 *********************************************/
r21559r21560
14921492 * the optimized averaging algorithm.
14931493 *********************************************/
14941494
1495void snes_ppu_class::snes_refresh_scanline( running_machine &machine, bitmap_rgb32 &bitmap, UINT16 curline )
1495void snes_ppu_class::refresh_scanline( running_machine &machine, bitmap_rgb32 &bitmap, UINT16 curline )
14961496{
14971497   UINT16 ii;
14981498   int x;
r21559r21560
15111511   {
15121512      /* Update clip window masks if necessary */
15131513      if (m_update_windows)
1514         snes_update_windowmasks();
1514         update_windowmasks();
15151515      /* Update the offsets if necessary */
15161516      if (m_update_offsets)
1517         snes_update_offsets();
1517         update_offsets();
15181518
15191519      /* Clear priority */
15201520      memset(scanlines[SNES_MAINSCREEN].priority, 0, SNES_SCR_WIDTH);
r21559r21560
15401540      }
15411541
15421542      /* Prepare OAM for this scanline */
1543      snes_update_objects_rto(curline);
1543      update_objects_rto(curline);
15441544
15451545      /* Draw scanline */
1546      snes_draw_screens(curline);
1546      draw_screens(curline);
15471547
1548      snes_update_obsel();
1548      update_obsel();
15491549
15501550#if SNES_LAYER_DEBUG
1551      if (snes_dbg_video(machine, curline, snes_ram))
1551      if (dbg_video(machine, curline, snes_ram))
15521552      {
15531553         g_profiler.stop();
15541554         return;
r21559r21560
15841584
15851585            /* perform color math if the layer wants it (except if it's an object > 192) */
15861586            if (!scanline1->blend_exception[x] && m_layer[scanline1->layer[x]].color_math)
1587               snes_draw_blend(x, &c, m_prevent_color_math, m_clip_to_black, 0);
1587               draw_blend(x, &c, m_prevent_color_math, m_clip_to_black, 0);
15881588
15891589            r = ((c & 0x1f) * fade) >> 4;
15901590            g = (((c & 0x3e0) >> 5) * fade) >> 4;
r21559r21560
16001600
16011601            /* perform color math if the layer wants it (except if it's an object > 192) */
16021602            if (!scanline1->blend_exception[x] && m_layer[scanline1->layer[x]].color_math)
1603               snes_draw_blend(x, &c, m_prevent_color_math, m_clip_to_black, 0);
1603               draw_blend(x, &c, m_prevent_color_math, m_clip_to_black, 0);
16041604
16051605            tmp_col[1] = c;
16061606
r21559r21560
16131613            apply to it the same color math as the *next* mainscreen pixel (i.e. mainscreen pixel 0), which seems as good as
16141614            any other choice */
16151615            if (x == 0 && !scanline1->blend_exception[0] && m_layer[scanline1->layer[0]].color_math)
1616               snes_draw_blend(0, &c, m_prevent_color_math, m_clip_to_black, 1);
1616               draw_blend(0, &c, m_prevent_color_math, m_clip_to_black, 1);
16171617            else if (x > 0  && !scanline1->blend_exception[x - 1] && m_layer[scanline1->layer[x - 1]].color_math)
1618               snes_draw_blend(x, &c, m_prevent_color_math, m_clip_to_black, 1);
1618               draw_blend(x, &c, m_prevent_color_math, m_clip_to_black, 1);
16191619
16201620            tmp_col[0] = c;
16211621
r21559r21560
16521652}
16531653
16541654void snes_ppu_class::ppu_start(running_machine &machine)
1655{
1655{   
1656#if SNES_LAYER_DEBUG
1657   memset(&debug_options, 0, sizeof(debug_options));
1658#endif
1659
16561660   m_vram = auto_alloc_array(machine, UINT8, SNES_VRAM_SIZE);
16571661   m_cgram = auto_alloc_array(machine, UINT16, SNES_CGRAM_SIZE/2);
16581662   m_oam_ram = auto_alloc_array(machine, UINT16, SNES_OAM_SIZE/2);
r21559r21560
16681672   m_ppu1_version = 1;  // 5C77 chip version number, read by STAT77, only '1' is known
16691673   m_ppu2_version = 3;  // 5C78 chip version number, read by STAT78, only '2' & '3' encountered so far.
16701674   
1671   
1675   m_cgram_address = 0;
1676   m_read_ophct = 0;
1677   m_read_opvct = 0;
1678
16721679   /* Inititialize mosaic table */
16731680   for (int j = 0; j < 16; j++)
16741681   {
r21559r21560
17721779   state_save_register_global(machine, m_pseudo_hires);
17731780   state_save_register_global(machine, m_color_modes);
17741781   state_save_register_global(machine, m_stat77_flags);
1782
1783   state_save_register_global(machine, m_htmult);
1784   state_save_register_global(machine, m_cgram_address);
1785   state_save_register_global(machine, m_read_ophct);
1786   state_save_register_global(machine, m_read_opvct);
1787   state_save_register_global(machine, m_vram_fgr_high);
1788   state_save_register_global(machine, m_vram_fgr_increment);
1789   state_save_register_global(machine, m_vram_fgr_count);
1790   state_save_register_global(machine, m_vram_fgr_mask);
1791   state_save_register_global(machine, m_vram_fgr_shift);
1792   state_save_register_global(machine, m_vram_read_buffer);
1793   state_save_register_global(machine, m_vmadd);
17751794   
17761795   state_save_register_global_pointer(machine, m_vram, SNES_VRAM_SIZE);
17771796   state_save_register_global_pointer(machine, m_cgram, SNES_CGRAM_SIZE/2);
17781797   state_save_register_global_pointer(machine, m_oam_ram, SNES_OAM_SIZE/2);   
17791798}
17801799
1781VIDEO_START( snes )
1782{
1783   snes_state *state = machine.driver_data<snes_state>();
17841800
1785#if SNES_LAYER_DEBUG
1786   memset(&debug_options, 0, sizeof(debug_options));
1787#endif
1788
1789   state->m_ppu.ppu_start(machine);
1790}
1791
1792UINT32 snes_state::snes_screen_update( screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
1793{
1794   snes_state *state = machine().driver_data<snes_state>();
1795   int y;
1796
1797   /*NTSC SNES draw range is 1-225. */
1798   for (y = cliprect.min_y; y <= cliprect.max_y; y++)
1799   {
1800      state->m_ppu.snes_refresh_scanline(machine(), bitmap, y + 1);
1801   }
1802   return 0;
1803}
1804
1805
18061801/* CPU <-> PPU comms */
18071802
18081803// full graphic variables
r21559r21560
18111806static const UINT16 vram_fgr_shiftab[4] = { 0, 5, 6, 7 };
18121807
18131808// utility function - latches the H/V counters.  Used by IRQ, writes to WRIO, etc.
1814void snes_ppu_class::snes_latch_counters( running_machine &machine, UINT8 *ram_ptr )
1809void snes_ppu_class::latch_counters( running_machine &machine, UINT8 *ram_ptr )
18151810{
1816   snes_state *state = machine.driver_data<snes_state>();
1817
1818   m_beam.current_horz = machine.primary_screen->hpos() / state->m_htmult;
1811   m_beam.current_horz = machine.primary_screen->hpos() / m_htmult;
18191812   m_beam.latch_vert = machine.primary_screen->vpos();
18201813   m_beam.latch_horz = m_beam.current_horz;
18211814   ram_ptr[STAT78] |= 0x40;   // indicate we latched
1822//  state->m_read_ophct = state->m_read_opvct = 0;    // clear read flags - 2009-08: I think we must clear these when STAT78 is read...
1815//  m_read_ophct = m_read_opvct = 0;    // clear read flags - 2009-08: I think we must clear these when STAT78 is read...
18231816
18241817//  printf("latched @ H %d V %d\n", m_beam.latch_horz, m_beam.latch_vert);
18251818}
18261819
1827void snes_ppu_class::snes_dynamic_res_change( running_machine &machine, UINT8 *ram_ptr )
1820void snes_ppu_class::dynamic_res_change( running_machine &machine, UINT8 *ram_ptr )
18281821{
1829   snes_state *state = machine.driver_data<snes_state>();
18301822   rectangle visarea = machine.primary_screen->visible_area();
18311823   attoseconds_t refresh;
18321824
r21559r21560
18361828
18371829   // fixme: should compensate for SNES_DBG_VIDEO
18381830   if (m_mode == 5 || m_mode == 6 || m_pseudo_hires)
1839      state->m_htmult = 2;
1831      m_htmult = 2;
18401832   else
1841      state->m_htmult = 1;
1833      m_htmult = 1;
18421834
18431835   /* FIXME: does the timing changes when the gfx mode is equal to 5 or 6? */
18441836   if ((ram_ptr[STAT78] & 0x10) == SNES_NTSC)
r21559r21560
18681860 when interlace is active.
18691861*************************************************/
18701862
1871inline UINT32 snes_ppu_class::snes_get_vram_address( running_machine &machine )
1863inline UINT32 snes_ppu_class::get_vram_address( running_machine &machine )
18721864{
1873   snes_state *state = machine.driver_data<snes_state>();
1874   UINT32 addr = state->m_vmadd;
1865   UINT32 addr = m_vmadd;
18751866
1876   if (state->m_vram_fgr_count)
1867   if (m_vram_fgr_count)
18771868   {
1878      UINT32 rem = addr & state->m_vram_fgr_mask;
1879      UINT32 faddr = (addr & ~state->m_vram_fgr_mask) + (rem >> state->m_vram_fgr_shift) + ((rem & (state->m_vram_fgr_count - 1)) << 3);
1869      UINT32 rem = addr & m_vram_fgr_mask;
1870      UINT32 faddr = (addr & ~m_vram_fgr_mask) + (rem >> m_vram_fgr_shift) + ((rem & (m_vram_fgr_count - 1)) << 3);
18801871      return faddr << 1;
18811872   }
18821873
18831874   return addr << 1;
18841875}
18851876
1886READ8_MEMBER( snes_ppu_class::snes_vram_read )
1877READ8_MEMBER( snes_ppu_class::vram_read )
18871878{
18881879   UINT8 res = 0;
18891880   offset &= 0xffff; // only 64KB are present on SNES
r21559r21560
19191910   return res;
19201911}
19211912
1922WRITE8_MEMBER( snes_ppu_class::snes_vram_write )
1913WRITE8_MEMBER( snes_ppu_class::vram_write )
19231914{
19241915   offset &= 0xffff; // only 64KB are present on SNES, Robocop 3 relies on this
19251916
r21559r21560
19841975 to choose the high/low byte of the snes_oam word.
19851976*************************************************/
19861977
1987READ8_MEMBER( snes_ppu_class::snes_oam_read )
1978READ8_MEMBER( snes_ppu_class::oam_read )
19881979{
19891980   offset &= 0x1ff;
19901981
r21559r21560
20021993   return (m_oam_ram[offset] >> (snes_ram[OAMDATA] << 3)) & 0xff;
20031994}
20041995
2005WRITE8_MEMBER( snes_ppu_class::snes_oam_write )
1996WRITE8_MEMBER( snes_ppu_class::oam_write )
20061997{
20071998   offset &= 0x1ff;
20081999
r21559r21560
20442035 solution adopted by BSNES without enabling it.
20452036*************************************************/
20462037
2047READ8_MEMBER( snes_ppu_class::snes_cgram_read )
2038READ8_MEMBER( snes_ppu_class::cgram_read )
20482039{
20492040   UINT8 res = 0;
20502041   offset &= 0x1ff;
r21559r21560
20702061   return res;
20712062}
20722063
2073WRITE8_MEMBER( snes_ppu_class::snes_cgram_write )
2064WRITE8_MEMBER( snes_ppu_class::cgram_write )
20742065{
20752066   offset &= 0x1ff;
20762067
r21559r21560
20962087   ((UINT8 *)m_cgram)[offset] = data;
20972088}
20982089
2099UINT8 snes_ppu_class::snes_ppu_read(address_space &space, UINT32 offset, UINT8 *ram_ptr)
2090UINT8 snes_ppu_class::read(address_space &space, UINT32 offset, UINT8 *ram_ptr)
21002091{
2101   snes_state *state = space.machine().driver_data<snes_state>();
21022092   UINT8 value;
21032093
21042094   switch (offset)
r21559r21560
21452135            return m_ppu1_open_bus;
21462136         }
21472137      case SLHV:      /* Software latch for H/V counter */
2148         snes_latch_counters(space.machine(), ram_ptr);
2138         latch_counters(space.machine(), ram_ptr);
21492139         return snes_open_bus_r(space, 0);       /* Return value is meaningless */
21502140      case ROAMDATA:  /* Read data from OAM (DR) */
2151         m_ppu1_open_bus = snes_oam_read(space, m_oam.address);
2141         m_ppu1_open_bus = oam_read(space, m_oam.address);
21522142         ram_ptr[OAMDATA] = (ram_ptr[OAMDATA] + 1) % 2;
21532143         if (!ram_ptr[OAMDATA])
21542144         {
r21559r21560
21592149         return m_ppu1_open_bus;
21602150      case RVMDATAL:  /* Read data from VRAM (low) */
21612151         {
2162            UINT32 addr = snes_get_vram_address(space.machine());
2163            m_ppu1_open_bus = state->m_vram_read_buffer & 0xff;
2152            UINT32 addr = get_vram_address(space.machine());
2153            m_ppu1_open_bus = m_vram_read_buffer & 0xff;
21642154
2165            if (!state->m_vram_fgr_high)
2155            if (!m_vram_fgr_high)
21662156            {
2167               state->m_vram_read_buffer = snes_vram_read(space, addr);
2168               state->m_vram_read_buffer |= (snes_vram_read(space, addr + 1) << 8);
2157               m_vram_read_buffer = vram_read(space, addr);
2158               m_vram_read_buffer |= (vram_read(space, addr + 1) << 8);
21692159
2170               state->m_vmadd = (state->m_vmadd + state->m_vram_fgr_increment) & 0xffff;
2160               m_vmadd = (m_vmadd + m_vram_fgr_increment) & 0xffff;
21712161            }
21722162
21732163            return m_ppu1_open_bus;
21742164         }
21752165      case RVMDATAH:  /* Read data from VRAM (high) */
21762166         {
2177            UINT32 addr = snes_get_vram_address(space.machine());
2178            m_ppu1_open_bus = (state->m_vram_read_buffer >> 8) & 0xff;
2167            UINT32 addr = get_vram_address(space.machine());
2168            m_ppu1_open_bus = (m_vram_read_buffer >> 8) & 0xff;
21792169
2180            if (state->m_vram_fgr_high)
2170            if (m_vram_fgr_high)
21812171            {
2182               state->m_vram_read_buffer = snes_vram_read(space, addr);
2183               state->m_vram_read_buffer |= (snes_vram_read(space, addr + 1) << 8);
2172               m_vram_read_buffer = vram_read(space, addr);
2173               m_vram_read_buffer |= (vram_read(space, addr + 1) << 8);
21842174
2185               state->m_vmadd = (state->m_vmadd + state->m_vram_fgr_increment) & 0xffff;
2175               m_vmadd = (m_vmadd + m_vram_fgr_increment) & 0xffff;
21862176            }
21872177
21882178            return m_ppu1_open_bus;
21892179         }
21902180      case RCGDATA:   /* Read data from CGRAM */
2191         if (!(state->m_cgram_address & 0x01))
2192            m_ppu2_open_bus = snes_cgram_read(space, state->m_cgram_address);
2181         if (!(m_cgram_address & 0x01))
2182            m_ppu2_open_bus = cgram_read(space, m_cgram_address);
21932183         else
21942184         {
21952185            m_ppu2_open_bus &= 0x80;
2196            m_ppu2_open_bus |= snes_cgram_read(space, state->m_cgram_address) & 0x7f;
2186            m_ppu2_open_bus |= cgram_read(space, m_cgram_address) & 0x7f;
21972187         }
21982188
2199         state->m_cgram_address = (state->m_cgram_address + 1) % (SNES_CGRAM_SIZE - 2);
2189         m_cgram_address = (m_cgram_address + 1) % (SNES_CGRAM_SIZE - 2);
22002190         return m_ppu2_open_bus;
22012191      case OPHCT:     /* Horizontal counter data by ext/soft latch */
2202         if (state->m_read_ophct)
2192         if (m_read_ophct)
22032193         {
22042194            m_ppu2_open_bus &= 0xfe;
22052195            m_ppu2_open_bus |= (m_beam.latch_horz >> 8) & 0x01;
r21559r21560
22082198         {
22092199            m_ppu2_open_bus = m_beam.latch_horz & 0xff;
22102200         }
2211         state->m_read_ophct ^= 1;
2201         m_read_ophct ^= 1;
22122202         return m_ppu2_open_bus;
22132203      case OPVCT:     /* Vertical counter data by ext/soft latch */
2214         if (state->m_read_opvct)
2204         if (m_read_opvct)
22152205         {
22162206            m_ppu2_open_bus &= 0xfe;
22172207            m_ppu2_open_bus |= (m_beam.latch_vert >> 8) & 0x01;
r21559r21560
22202210         {
22212211            m_ppu2_open_bus = m_beam.latch_vert & 0xff;
22222212         }
2223         state->m_read_opvct ^= 1;
2213         m_read_opvct ^= 1;
22242214         return m_ppu2_open_bus;
22252215      case STAT77:    /* PPU status flag and version number */
22262216         value = m_stat77_flags & 0xc0; // 0x80 & 0x40 are Time Over / Range Over Sprite flags, set by the video code
r21559r21560
22312221         m_ppu1_open_bus = value;
22322222         return m_ppu1_open_bus;
22332223      case STAT78:    /* PPU status flag and version number */
2234         state->m_read_ophct = 0;
2235         state->m_read_opvct = 0;
2224         m_read_ophct = 0;
2225         m_read_opvct = 0;
22362226         if(ram_ptr[WRIO] & 0x80)
22372227            ram_ptr[STAT78] &= ~0x40; //clear ext latch if bit 7 of WRIO is set
22382228         ram_ptr[STAT78] = (ram_ptr[STAT78] & ~0x2f) | (m_ppu2_open_bus & 0x20) | (m_ppu2_version & 0x0f);
r21559r21560
22452235}
22462236
22472237
2248void snes_ppu_class::snes_ppu_write(address_space &space, UINT32 offset, UINT8 data, UINT8 *ram_ptr)
2238void snes_ppu_class::write(address_space &space, UINT32 offset, UINT8 data, UINT8 *ram_ptr)
22492239{
2250   snes_state *state = space.machine().driver_data<snes_state>();
2251
22522240   switch (offset)
22532241   {
22542242      case INIDISP:   /* Initial settings for screen */
r21559r21560
22812269         break;
22822270      case OAMDATA:   /* Data for OAM write (DW) */
22832271         if (m_oam.address >= 0x100)
2284            snes_oam_write(space, m_oam.address, data);
2272            oam_write(space, m_oam.address, data);
22852273         else
22862274         {
22872275            if (!ram_ptr[OAMDATA])
r21559r21560
22912279               // in this case, we not only write data to the upper byte of the word,
22922280               // but also m_oam.write_latch to the lower byte (recall that
22932281               // ram_ptr[OAMDATA] is used to select high/low byte)
2294               snes_oam_write(space, m_oam.address, data);
2282               oam_write(space, m_oam.address, data);
22952283               ram_ptr[OAMDATA] = 0;
2296               snes_oam_write(space, m_oam.address, m_oam.write_latch);
2284               oam_write(space, m_oam.address, m_oam.write_latch);
22972285               ram_ptr[OAMDATA] = 1;
22982286            }
22992287         }
r21559r21560
23072295         return;
23082296      case BGMODE:    /* BG mode and character size settings */
23092297         m_mode = data & 0x07;
2310         snes_dynamic_res_change(space.machine(), ram_ptr);
2298         dynamic_res_change(space.machine(), ram_ptr);
23112299         m_bg3_priority_bit = BIT(data, 3);
23122300         m_layer[SNES_BG1].tile_size = BIT(data, 4);
23132301         m_layer[SNES_BG2].tile_size = BIT(data, 5);
r21559r21560
23882376         m_update_offsets = 1;
23892377         return;
23902378      case VMAIN:     /* VRAM address increment value designation */
2391         state->m_vram_fgr_high = (data & 0x80);
2392         state->m_vram_fgr_increment = vram_fgr_inctab[data & 3];
2379         m_vram_fgr_high = (data & 0x80);
2380         m_vram_fgr_increment = vram_fgr_inctab[data & 3];
23932381
23942382         if (data & 0xc)
23952383         {
23962384            int md = (data & 0xc) >> 2;
23972385
2398            state->m_vram_fgr_count = vram_fgr_inccnts[md];         // 0x20, 0x40, 0x80
2399            state->m_vram_fgr_mask = (state->m_vram_fgr_count * 8) - 1; // 0xff, 0x1ff, 0x2ff
2400            state->m_vram_fgr_shift = vram_fgr_shiftab[md];         // 5, 6, 7
2386            m_vram_fgr_count = vram_fgr_inccnts[md];         // 0x20, 0x40, 0x80
2387            m_vram_fgr_mask = (m_vram_fgr_count * 8) - 1; // 0xff, 0x1ff, 0x2ff
2388            m_vram_fgr_shift = vram_fgr_shiftab[md];         // 5, 6, 7
24012389         }
24022390         else
24032391         {
2404            state->m_vram_fgr_count = 0;
2392            m_vram_fgr_count = 0;
24052393         }
2406//          printf("VMAIN: high %x inc %x count %x mask %x shift %x\n", state->m_vram_fgr_high, state->m_vram_fgr_increment, state->m_vram_fgr_count, state->m_vram_fgr_mask, state->m_vram_fgr_shift);
2394//          printf("VMAIN: high %x inc %x count %x mask %x shift %x\n", m_vram_fgr_high, m_vram_fgr_increment, m_vram_fgr_count, m_vram_fgr_mask, m_vram_fgr_shift);
24072395         break;
24082396      case VMADDL:    /* Address for VRAM read/write (low) */
24092397         {
24102398            UINT32 addr;
2411            state->m_vmadd = (state->m_vmadd & 0xff00) | (data << 0);
2412            addr = snes_get_vram_address(space.machine());
2413            state->m_vram_read_buffer = snes_vram_read(space, addr);
2414            state->m_vram_read_buffer |= (snes_vram_read(space, addr + 1) << 8);
2399            m_vmadd = (m_vmadd & 0xff00) | (data << 0);
2400            addr = get_vram_address(space.machine());
2401            m_vram_read_buffer = vram_read(space, addr);
2402            m_vram_read_buffer |= (vram_read(space, addr + 1) << 8);
24152403         }
24162404         break;
24172405      case VMADDH:    /* Address for VRAM read/write (high) */
24182406         {
24192407            UINT32 addr;
2420            state->m_vmadd = (state->m_vmadd & 0x00ff) | (data << 8);
2421            addr = snes_get_vram_address(space.machine());
2422            state->m_vram_read_buffer = snes_vram_read(space, addr);
2423            state->m_vram_read_buffer |= (snes_vram_read(space, addr + 1) << 8);
2408            m_vmadd = (m_vmadd & 0x00ff) | (data << 8);
2409            addr = get_vram_address(space.machine());
2410            m_vram_read_buffer = vram_read(space, addr);
2411            m_vram_read_buffer |= (vram_read(space, addr + 1) << 8);
24242412         }
24252413         break;
24262414      case VMDATAL:   /* 2118: Data for VRAM write (low) */
24272415         {
2428            UINT32 addr = snes_get_vram_address(space.machine());
2429            snes_vram_write(space, addr, data);
2416            UINT32 addr = get_vram_address(space.machine());
2417            vram_write(space, addr, data);
24302418
2431            if (!state->m_vram_fgr_high)
2432               state->m_vmadd = (state->m_vmadd + state->m_vram_fgr_increment) & 0xffff;
2419            if (!m_vram_fgr_high)
2420               m_vmadd = (m_vmadd + m_vram_fgr_increment) & 0xffff;
24332421         }
24342422         return;
24352423      case VMDATAH:   /* 2119: Data for VRAM write (high) */
24362424         {
2437            UINT32 addr = snes_get_vram_address(space.machine());
2438            snes_vram_write(space, addr + 1, data);
2425            UINT32 addr = get_vram_address(space.machine());
2426            vram_write(space, addr + 1, data);
24392427
2440            if (state->m_vram_fgr_high)
2441               state->m_vmadd = (state->m_vmadd + state->m_vram_fgr_increment) & 0xffff;
2428            if (m_vram_fgr_high)
2429               m_vmadd = (m_vmadd + m_vram_fgr_increment) & 0xffff;
24422430         }
24432431         return;
24442432      case M7SEL:     /* Mode 7 initial settings */
r21559r21560
24732461         break;
24742462      case CGADD:     /* Initial address for colour RAM writing */
24752463         /* CGRAM is 16-bit, but when reading/writing we treat it as 8-bit, so we need to double the address */
2476         state->m_cgram_address = data << 1;
2464         m_cgram_address = data << 1;
24772465         break;
24782466      case CGDATA:    /* Data for colour RAM */
2479         snes_cgram_write(space, state->m_cgram_address, data);
2480         state->m_cgram_address = (state->m_cgram_address + 1) % (SNES_CGRAM_SIZE - 2);
2467         cgram_write(space, m_cgram_address, data);
2468         m_cgram_address = (m_cgram_address + 1) % (SNES_CGRAM_SIZE - 2);
24812469         break;
24822470      case W12SEL:    /* Window mask settings for BG1-2 */
24832471         if (data != ram_ptr[offset])
r21559r21560
26382626         m_beam.last_visible_line = (data & 0x04) ? 240 : 225;
26392627         m_pseudo_hires = BIT(data, 3);
26402628         m_mode7.extbg = BIT(data, 6);
2641         snes_dynamic_res_change(space.machine(), ram_ptr);
2629         dynamic_res_change(space.machine(), ram_ptr);
26422630#ifdef SNES_DBG_REG_W
26432631         if ((data & 0x8) != (ram_ptr[SETINI] & 0x8))
26442632            mame_printf_debug("Pseudo 512 mode: %s\n", (data & 0x8) ? "on" : "off");
r21559r21560
26652653      popmessage MSG2;                          \
26662654   }
26672655
2668static UINT8 snes_dbg_video( running_machine &machine, UINT16 curline, UINT8 *ram_ptr )
2656static UINT8 dbg_video( running_machine &machine, UINT16 curline, UINT8 *ram_ptr )
26692657{
26702658   int i;
26712659   UINT8 toggles = machine.root_device().ioport("DEBUG1")->read_safe(0);
trunk/src/mame/includes/snes.h
r21559r21560
475475   UINT8 m_color_modes;
476476   UINT8 m_stat77_flags;
477477
478   inline UINT16 snes_get_bgcolor(UINT8 direct_colors, UINT16 palette, UINT8 color);
479   inline void snes_set_scanline_pixel(int screen, INT16 x, UINT16 color, UINT8 priority, UINT8 layer, int blend);
480   inline void snes_draw_bgtile_lores(UINT8 layer, INT16 ii, UINT8 colour, UINT16 pal, UINT8 direct_colors, UINT8 priority);
481   inline void snes_draw_bgtile_hires(UINT8 layer, INT16 ii, UINT8 colour, UINT16 pal, UINT8 direct_colors, UINT8 priority);
482   inline void snes_draw_oamtile(INT16 ii, UINT8 colour, UINT16 pal, UINT8 priority);
483   inline void snes_draw_tile(UINT8 planes, UINT8 layer, UINT32 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT8 direct_colors, UINT16 pal, UINT8 hires);
484   inline UINT32 snes_get_tmap_addr(UINT8 layer, UINT8 tile_size, UINT32 base, UINT32 x, UINT32 y);
485   inline void snes_update_line(UINT16 curline, UINT8 layer, UINT8 priority_b, UINT8 priority_a, UINT8 color_depth, UINT8 hires, UINT8 offset_per_tile, UINT8 direct_colors);
486   void snes_update_line_mode7(UINT16 curline, UINT8 layer, UINT8 priority_b, UINT8 priority_a);
487   void snes_update_obsel(void);
488   void snes_oam_list_build(void);
478   UINT16                m_htmult;     /* in 512 wide, we run HTOTAL double and halve it on latching */
479   UINT16                m_cgram_address;  /* CGRAM address */
480   UINT8                 m_read_ophct;
481   UINT8                 m_read_opvct;
482   UINT16                m_vram_fgr_high;
483   UINT16                m_vram_fgr_increment;
484   UINT16                m_vram_fgr_count;
485   UINT16                m_vram_fgr_mask;
486   UINT16                m_vram_fgr_shift;
487   UINT16                m_vram_read_buffer;
488   UINT16                m_vmadd;
489   
490   inline UINT16 get_bgcolor(UINT8 direct_colors, UINT16 palette, UINT8 color);
491   inline void set_scanline_pixel(int screen, INT16 x, UINT16 color, UINT8 priority, UINT8 layer, int blend);
492   inline void draw_bgtile_lores(UINT8 layer, INT16 ii, UINT8 colour, UINT16 pal, UINT8 direct_colors, UINT8 priority);
493   inline void draw_bgtile_hires(UINT8 layer, INT16 ii, UINT8 colour, UINT16 pal, UINT8 direct_colors, UINT8 priority);
494   inline void draw_oamtile(INT16 ii, UINT8 colour, UINT16 pal, UINT8 priority);
495   inline void draw_tile(UINT8 planes, UINT8 layer, UINT32 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT8 direct_colors, UINT16 pal, UINT8 hires);
496   inline UINT32 get_tmap_addr(UINT8 layer, UINT8 tile_size, UINT32 base, UINT32 x, UINT32 y);
497   inline void update_line(UINT16 curline, UINT8 layer, UINT8 priority_b, UINT8 priority_a, UINT8 color_depth, UINT8 hires, UINT8 offset_per_tile, UINT8 direct_colors);
498   void update_line_mode7(UINT16 curline, UINT8 layer, UINT8 priority_b, UINT8 priority_a);
499   void update_obsel(void);
500   void oam_list_build(void);
489501   int is_sprite_on_scanline(UINT16 curline, UINT8 sprite);
490   void snes_update_objects_rto(UINT16 curline);
491   void snes_update_objects(UINT8 priority_oam0, UINT8 priority_oam1, UINT8 priority_oam2, UINT8 priority_oam3);
492   void snes_update_mode_0(UINT16 curline);
493   void snes_update_mode_1(UINT16 curline);
494   void snes_update_mode_2(UINT16 curline);
495   void snes_update_mode_3(UINT16 curline);
496   void snes_update_mode_4(UINT16 curline);
497   void snes_update_mode_5(UINT16 curline);
498   void snes_update_mode_6(UINT16 curline);
499   void snes_update_mode_7(UINT16 curline);
500   void snes_draw_screens(UINT16 curline);
501   void snes_update_windowmasks(void);
502   void snes_update_offsets(void);
503   inline void snes_draw_blend(UINT16 offset, UINT16 *colour, UINT8 prevent_color_math, UINT8 black_pen_clip, int switch_screens);
504   void snes_refresh_scanline(running_machine &machine, bitmap_rgb32 &bitmap, UINT16 curline);
505   
506   UINT8 snes_ppu_read(address_space &space, UINT32 offset, UINT8 *ram_ptr);
507   void snes_ppu_write(address_space &space, UINT32 offset, UINT8 data, UINT8 *ram_ptr);
508   void snes_latch_counters(running_machine &machine, UINT8 *ram_ptr);
509   void snes_dynamic_res_change(running_machine &machine, UINT8 *ram_ptr);
510   inline UINT32 snes_get_vram_address(running_machine &machine);
511   UINT8 snes_dbg_video(running_machine &machine, UINT16 curline, UINT8 *ram_ptr);
502   void update_objects_rto(UINT16 curline);
503   void update_objects(UINT8 priority_oam0, UINT8 priority_oam1, UINT8 priority_oam2, UINT8 priority_oam3);
504   void update_mode_0(UINT16 curline);
505   void update_mode_1(UINT16 curline);
506   void update_mode_2(UINT16 curline);
507   void update_mode_3(UINT16 curline);
508   void update_mode_4(UINT16 curline);
509   void update_mode_5(UINT16 curline);
510   void update_mode_6(UINT16 curline);
511   void update_mode_7(UINT16 curline);
512   void draw_screens(UINT16 curline);
513   void update_windowmasks(void);
514   void update_offsets(void);
515   inline void draw_blend(UINT16 offset, UINT16 *colour, UINT8 prevent_color_math, UINT8 black_pen_clip, int switch_screens);
516   void refresh_scanline(running_machine &machine, bitmap_rgb32 &bitmap, UINT16 curline);
512517
518   void latch_counters(running_machine &machine, UINT8 *ram_ptr);
519   void dynamic_res_change(running_machine &machine, UINT8 *ram_ptr);
520   inline UINT32 get_vram_address(running_machine &machine);
521   UINT8 dbg_video(running_machine &machine, UINT16 curline, UINT8 *ram_ptr);
522
513523   void ppu_start(running_machine &machine);
514   DECLARE_READ8_MEMBER( snes_oam_read );
515   DECLARE_WRITE8_MEMBER( snes_oam_write );
516   DECLARE_READ8_MEMBER( snes_cgram_read );
517   DECLARE_WRITE8_MEMBER( snes_cgram_write );
518   DECLARE_READ8_MEMBER( snes_vram_read );
519   DECLARE_WRITE8_MEMBER( snes_vram_write );
524   UINT8 read(address_space &space, UINT32 offset, UINT8 *ram_ptr);
525   void write(address_space &space, UINT32 offset, UINT8 data, UINT8 *ram_ptr);
526   
527   DECLARE_READ8_MEMBER( oam_read );
528   DECLARE_WRITE8_MEMBER( oam_write );
529   DECLARE_READ8_MEMBER( cgram_read );
530   DECLARE_WRITE8_MEMBER( cgram_write );
531   DECLARE_READ8_MEMBER( vram_read );
532   DECLARE_WRITE8_MEMBER( vram_write );
520533   UINT16 *m_oam_ram;     /* Object Attribute Memory */
521534   UINT16 *m_cgram;   /* Palette RAM */
522535   UINT8  *m_vram;    /* Video RAM (TODO: Should be 16-bit, but it's easier this way) */
r21559r21560
563576      { }
564577
565578   /* misc */
566   UINT16                m_htmult;     /* in 512 wide, we run HTOTAL double and halve it on latching */
567   UINT16                m_cgram_address;  /* CGRAM address */
568   UINT8                 m_vram_read_offset;   /* VRAM read offset */
569   UINT8                 m_read_ophct;
570   UINT8                 m_read_opvct;
571579   UINT16                m_hblank_offset;
572   UINT16                m_vram_fgr_high;
573   UINT16                m_vram_fgr_increment;
574   UINT16                m_vram_fgr_count;
575   UINT16                m_vram_fgr_mask;
576   UINT16                m_vram_fgr_shift;
577   UINT16                m_vram_read_buffer;
578580   UINT32                m_wram_address;
579581   UINT16                m_htime;
580582   UINT16                m_vtime;
581   UINT16                m_vmadd;
582583
583584   /* non-SNES HW-specific flags / variables */
584585   UINT8                 m_is_nss;

Previous 199869 Revisions Next


© 1997-2024 The MAME Team