Previous 199869 Revisions Next

r20791 Thursday 7th February, 2013 at 04:55:02 UTC by Angelo Salese
State-ized Sega Saturn VDP1 & 2 [Angelo Salese]
[src/mame/drivers]saturn.c
[src/mame/includes]stv.h
[src/mame/machine]smpc.c
[src/mame/video]stvvdp1.c stvvdp2.c

trunk/src/mame/drivers/saturn.c
r20790r20791
786786   AM_RANGE(0x05a00000, 0x05a7ffff) AM_READWRITE16(saturn_soundram_r, saturn_soundram_w,0xffffffff)
787787   AM_RANGE(0x05b00000, 0x05b00fff) AM_DEVREADWRITE16_LEGACY("scsp", scsp_r, scsp_w, 0xffffffff)
788788   /* VDP1 */
789   AM_RANGE(0x05c00000, 0x05c7ffff) AM_READWRITE_LEGACY(saturn_vdp1_vram_r, saturn_vdp1_vram_w)
790   AM_RANGE(0x05c80000, 0x05cbffff) AM_READWRITE_LEGACY(saturn_vdp1_framebuffer0_r, saturn_vdp1_framebuffer0_w)
791   AM_RANGE(0x05d00000, 0x05d0001f) AM_READWRITE16_LEGACY(saturn_vdp1_regs_r, saturn_vdp1_regs_w,0xffffffff)
792   AM_RANGE(0x05e00000, 0x05e7ffff) AM_MIRROR(0x80000) AM_READWRITE_LEGACY(saturn_vdp2_vram_r, saturn_vdp2_vram_w)
793   AM_RANGE(0x05f00000, 0x05f7ffff) AM_READWRITE_LEGACY(saturn_vdp2_cram_r, saturn_vdp2_cram_w)
794   AM_RANGE(0x05f80000, 0x05fbffff) AM_READWRITE16_LEGACY(saturn_vdp2_regs_r, saturn_vdp2_regs_w,0xffffffff)
789   AM_RANGE(0x05c00000, 0x05c7ffff) AM_READWRITE(saturn_vdp1_vram_r, saturn_vdp1_vram_w)
790   AM_RANGE(0x05c80000, 0x05cbffff) AM_READWRITE(saturn_vdp1_framebuffer0_r, saturn_vdp1_framebuffer0_w)
791   AM_RANGE(0x05d00000, 0x05d0001f) AM_READWRITE16(saturn_vdp1_regs_r, saturn_vdp1_regs_w,0xffffffff)
792   AM_RANGE(0x05e00000, 0x05e7ffff) AM_MIRROR(0x80000) AM_READWRITE(saturn_vdp2_vram_r, saturn_vdp2_vram_w)
793   AM_RANGE(0x05f00000, 0x05f7ffff) AM_READWRITE(saturn_vdp2_cram_r, saturn_vdp2_cram_w)
794   AM_RANGE(0x05f80000, 0x05fbffff) AM_READWRITE16(saturn_vdp2_regs_r, saturn_vdp2_regs_w,0xffffffff)
795795   AM_RANGE(0x05fe0000, 0x05fe00cf) AM_READWRITE(saturn_scu_r, saturn_scu_w)
796796   AM_RANGE(0x06000000, 0x060fffff) AM_RAM AM_MIRROR(0x21f00000) AM_SHARE("workram_h")
797797   AM_RANGE(0x20000000, 0x2007ffff) AM_ROM AM_SHARE("share6")  // bios mirror
r20790r20791
815815   AM_RANGE(0x05a00000, 0x05afffff) AM_READWRITE16(saturn_soundram_r, saturn_soundram_w,0xffffffff)
816816   AM_RANGE(0x05b00000, 0x05b00fff) AM_DEVREADWRITE16_LEGACY("scsp", scsp_r, scsp_w, 0xffffffff)
817817   /* VDP1 */
818   AM_RANGE(0x05c00000, 0x05c7ffff) AM_READWRITE_LEGACY(saturn_vdp1_vram_r, saturn_vdp1_vram_w)
819   AM_RANGE(0x05c80000, 0x05cbffff) AM_READWRITE_LEGACY(saturn_vdp1_framebuffer0_r, saturn_vdp1_framebuffer0_w)
820   AM_RANGE(0x05d00000, 0x05d0001f) AM_READWRITE16_LEGACY(saturn_vdp1_regs_r, saturn_vdp1_regs_w,0xffffffff)
821   AM_RANGE(0x05e00000, 0x05e7ffff) AM_MIRROR(0x80000) AM_READWRITE_LEGACY(saturn_vdp2_vram_r, saturn_vdp2_vram_w)
822   AM_RANGE(0x05f00000, 0x05f7ffff) AM_READWRITE_LEGACY(saturn_vdp2_cram_r, saturn_vdp2_cram_w)
823   AM_RANGE(0x05f80000, 0x05fbffff) AM_READWRITE16_LEGACY(saturn_vdp2_regs_r, saturn_vdp2_regs_w,0xffffffff)
818   AM_RANGE(0x05c00000, 0x05c7ffff) AM_READWRITE(saturn_vdp1_vram_r, saturn_vdp1_vram_w)
819   AM_RANGE(0x05c80000, 0x05cbffff) AM_READWRITE(saturn_vdp1_framebuffer0_r, saturn_vdp1_framebuffer0_w)
820   AM_RANGE(0x05d00000, 0x05d0001f) AM_READWRITE16(saturn_vdp1_regs_r, saturn_vdp1_regs_w,0xffffffff)
821   AM_RANGE(0x05e00000, 0x05e7ffff) AM_MIRROR(0x80000) AM_READWRITE(saturn_vdp2_vram_r, saturn_vdp2_vram_w)
822   AM_RANGE(0x05f00000, 0x05f7ffff) AM_READWRITE(saturn_vdp2_cram_r, saturn_vdp2_cram_w)
823   AM_RANGE(0x05f80000, 0x05fbffff) AM_READWRITE16(saturn_vdp2_regs_r, saturn_vdp2_regs_w,0xffffffff)
824824   AM_RANGE(0x05fe0000, 0x05fe00cf) AM_READWRITE(saturn_scu_r, saturn_scu_w)
825825   AM_RANGE(0x06000000, 0x060fffff) AM_RAM AM_MIRROR(0x21f00000) AM_SHARE("workram_h")
826826   AM_RANGE(0x20000000, 0x2007ffff) AM_ROM AM_SHARE("share6")  // bios mirror
r20790r20791
18811881
18821882TIMER_DEVICE_CALLBACK_MEMBER(saturn_state::saturn_scanline)
18831883{
1884   saturn_state *state = machine().driver_data<saturn_state>();
18851884   int scanline = param;
18861885   int max_y = machine().primary_screen->height();
18871886   int y_step,vblank_line;
r20790r20791
18971896
18981897   if(scanline == (0)*y_step)
18991898   {
1900      video_update_vdp1(machine());
1899      video_update_vdp1();
19011900
19021901      if(STV_VDP1_VBE)
19031902         m_vdp1.framebuffer_clear_on_next_frame = 1;
trunk/src/mame/machine/smpc.c
r20790r20791
271271   machine.device("slave")->set_unscaled_clock(xtal/2);
272272
273273   state->m_vdp2.dotsel = param ^ 1;
274   stv_vdp2_dynamic_res_change(machine);
274   state->stv_vdp2_dynamic_res_change();
275275
276276   if(!state->m_NMI_reset)
277277      state->m_maincpu->set_input_line(INPUT_LINE_NMI, PULSE_LINE);
trunk/src/mame/includes/stv.h
r20790r20791
249249
250250   DECLARE_DEVICE_IMAGE_LOAD_MEMBER( sat_cart );
251251   DECLARE_DEVICE_IMAGE_LOAD_MEMBER( stv_cart );
252
253   DECLARE_READ16_MEMBER ( saturn_vdp1_regs_r );
254   DECLARE_READ32_MEMBER ( saturn_vdp1_vram_r );
255   DECLARE_READ32_MEMBER ( saturn_vdp1_framebuffer0_r );
256
257   DECLARE_WRITE16_MEMBER ( saturn_vdp1_regs_w );
258   DECLARE_WRITE32_MEMBER ( saturn_vdp1_vram_w );
259   DECLARE_WRITE32_MEMBER ( saturn_vdp1_framebuffer0_w );
260
261   DECLARE_READ32_MEMBER ( saturn_vdp2_vram_r );
262   DECLARE_READ32_MEMBER ( saturn_vdp2_cram_r );
263   DECLARE_READ16_MEMBER ( saturn_vdp2_regs_r );
264
265   DECLARE_WRITE32_MEMBER ( saturn_vdp2_vram_w );
266   DECLARE_WRITE32_MEMBER ( saturn_vdp2_cram_w );
267   DECLARE_WRITE16_MEMBER ( saturn_vdp2_regs_w );
268
269
270   /* VDP1 */
271   void stv_set_framebuffer_config( void );
272   void stv_prepare_framebuffers( void );
273   void stv_vdp1_change_framebuffers( void );
274   void video_update_vdp1( void );
275   void stv_vdp1_process_list( void );
276   void stv_vdp1_set_drawpixel( void );
277
278   void stv_vdp1_draw_normal_sprite(const rectangle &cliprect, int sprite_type);
279   void stv_vdp1_draw_scaled_sprite(const rectangle &cliprect);
280   void stv_vdp1_draw_distorted_sprite(const rectangle &cliprect);
281   void stv_vdp1_draw_poly_line(const rectangle &cliprect);
282   void stv_vdp1_draw_line(const rectangle &cliprect);
283   int x2s(int v);
284   int y2s(int v);
285   void vdp1_fill_quad(const rectangle &cliprect, int patterndata, int xsize, const struct spoint *q);
286   void vdp1_fill_line(const rectangle &cliprect, int patterndata, int xsize, INT32 y, INT32 x1, INT32 x2, INT32 u1, INT32 u2, INT32 v1, INT32 v2);
287//   void (*drawpixel)(int x, int y, int patterndata, int offsetcnt);
288//   void drawpixel_poly(int x, int y, int patterndata, int offsetcnt);
289//   void drawpixel_8bpp_trans(int x, int y, int patterndata, int offsetcnt);
290//   void drawpixel_4bpp_notrans(int x, int y, int patterndata, int offsetcnt);
291//   void drawpixel_4bpp_trans(int x, int y, int patterndata, int offsetcnt);
292//   void drawpixel_generic(int x, int y, int patterndata, int offsetcnt);
293   void vdp1_fill_slope(const rectangle &cliprect, int patterndata, int xsize,
294                          INT32 x1, INT32 x2, INT32 sl1, INT32 sl2, INT32 *nx1, INT32 *nx2,
295                     INT32 u1, INT32 u2, INT32 slu1, INT32 slu2, INT32 *nu1, INT32 *nu2,
296                     INT32 v1, INT32 v2, INT32 slv1, INT32 slv2, INT32 *nv1, INT32 *nv2,
297                     INT32 _y1, INT32 y2);
298   void stv_vdp1_setup_shading(const struct spoint* q, const rectangle &cliprect);
299   UINT8 stv_read_gouraud_table( void );
300   void stv_clear_framebuffer( int which_framebuffer );
301   void stv_vdp1_state_save_postload( void );
302   int stv_vdp1_start ( void );
303
304
305   /* VDP2 */
306
307   UINT8 get_vblank( void );
308   UINT8 get_hblank( void );
309   int get_vblank_duration( void );
310   int get_hblank_duration( void );
311   int get_pixel_clock( void );
312   UINT8 get_odd_bit( void );
313   void stv_vdp2_dynamic_res_change( void );
314
315   void refresh_palette_data( void );
316   int stv_vdp2_window_process(int x,int y);
317   void stv_vdp2_get_window0_coordinates(UINT16 *s_x, UINT16 *e_x, UINT16 *s_y, UINT16 *e_y);
318   void stv_vdp2_get_window1_coordinates(UINT16 *s_x, UINT16 *e_x, UINT16 *s_y, UINT16 *e_y);
319   int get_window_pixel(UINT16 s_x,UINT16 e_x,UINT16 s_y,UINT16 e_y,int x, int y,UINT8 win_num);
320   int stv_vdp2_apply_window_on_layer(rectangle &cliprect);
321
322   void stv_vdp2_draw_basic_tilemap(bitmap_rgb32 &bitmap, const rectangle &cliprect);
323   void stv_vdp2_draw_basic_bitmap(bitmap_rgb32 &bitmap, const rectangle &cliprect);
324
325   void stv_vdp2_drawgfxzoom(bitmap_rgb32 &dest_bmp,const rectangle &clip,gfx_element *gfx, UINT32 code,UINT32 color,int flipx,int flipy,int sx,int sy,int transparency,int transparent_color,int scalex, int scaley,int sprite_screen_width, int sprite_screen_height, int alpha);
326   void stv_vdp2_drawgfxzoom_rgb555(bitmap_rgb32 &dest_bmp,const rectangle &clip,UINT32 code,UINT32 color,int flipx,int flipy,int sx,int sy,int transparency,int transparent_color,int scalex, int scaley,int sprite_screen_width, int sprite_screen_height, int alpha);
327   void stv_vdp2_drawgfx_rgb555( bitmap_rgb32 &dest_bmp, const rectangle &clip, UINT32 code, int flipx, int flipy, int sx, int sy, int transparency, int alpha);
328   void stv_vdp2_drawgfx_rgb888( bitmap_rgb32 &dest_bmp, const rectangle &clip, UINT32 code, int flipx, int flipy, int sx, int sy, int transparency, int alpha);
329
330   void stv_vdp2_draw_rotation_screen(bitmap_rgb32 &bitmap, const rectangle &cliprect, int iRP);
331   void stv_vdp2_check_tilemap_with_linescroll(bitmap_rgb32 &bitmap, const rectangle &cliprect);
332   void stv_vdp2_check_tilemap(bitmap_rgb32 &bitmap, const rectangle &cliprect);
333   void stv_vdp2_copy_roz_bitmap(bitmap_rgb32 &bitmap, bitmap_rgb32 &roz_bitmap, const rectangle &cliprect, int iRP, int planesizex, int planesizey, int planerenderedsizex, int planerenderedsizey);
334   void stv_vdp2_fill_rotation_parameter_table( UINT8 rot_parameter );
335   UINT8 stv_vdp2_check_vram_cycle_pattern_registers( UINT8 access_command_pnmdr, UINT8 access_command_cpdr, UINT8 bitmap_enable );
336   void stv_vdp2_draw_mosaic(bitmap_rgb32 &bitmap, const rectangle &cliprect, UINT8 is_roz);
337
338   void stv_vdp2_fade_effects( void );
339   void stv_vdp2_compute_color_offset( int *r, int *g, int *b, int cor );
340   void stv_vdp2_compute_color_offset_UINT32(UINT32 *rgb, int cor);
341   void stv_vdp2_check_fade_control_for_layer( void );
342
343   void stv_vdp2_draw_line(bitmap_rgb32 &bitmap, const rectangle &cliprect);
344   void stv_vdp2_draw_back(bitmap_rgb32 &bitmap, const rectangle &cliprect);
345   void stv_vdp2_draw_NBG0(bitmap_rgb32 &bitmap, const rectangle &cliprect);
346   void stv_vdp2_draw_NBG1(bitmap_rgb32 &bitmap, const rectangle &cliprect);
347   void stv_vdp2_draw_NBG2(bitmap_rgb32 &bitmap, const rectangle &cliprect);
348   void stv_vdp2_draw_NBG3(bitmap_rgb32 &bitmap, const rectangle &cliprect);
349   void stv_vdp2_draw_RBG0(bitmap_rgb32 &bitmap, const rectangle &cliprect);
350   void draw_sprites(bitmap_rgb32 &bitmap, const rectangle &cliprect, UINT8 pri);
351
352   void stv_vdp2_state_save_postload( void );
353   void stv_vdp2_exit ( void );
354   int stv_vdp2_start ( void );
252355};
253356
254357#define MASTER_CLOCK_352 57272720
255358#define MASTER_CLOCK_320 53693174
256#define CEF_1   state->m_vdp1_regs[0x010/2]|=0x0002
257#define CEF_0   state->m_vdp1_regs[0x010/2]&=~0x0002
258#define BEF_1   state->m_vdp1_regs[0x010/2]|=0x0001
259#define BEF_0   state->m_vdp1_regs[0x010/2]&=~0x0001
260#define STV_VDP1_TVMR ((state->m_vdp1_regs[0x000/2])&0xffff)
359#define CEF_1   m_vdp1_regs[0x010/2]|=0x0002
360#define CEF_0   m_vdp1_regs[0x010/2]&=~0x0002
361#define BEF_1   m_vdp1_regs[0x010/2]|=0x0001
362#define BEF_0   m_vdp1_regs[0x010/2]&=~0x0001
363#define STV_VDP1_TVMR ((m_vdp1_regs[0x000/2])&0xffff)
261364#define STV_VDP1_VBE  ((STV_VDP1_TVMR & 0x0008) >> 3)
262365#define STV_VDP1_TVM  ((STV_VDP1_TVMR & 0x0007) >> 0)
263366
r20790r20791
294397void video_update_vdp1(running_machine &machine);
295398void stv_vdp2_dynamic_res_change(running_machine &machine);
296399
297DECLARE_READ16_HANDLER ( saturn_vdp1_regs_r );
298DECLARE_READ32_HANDLER ( saturn_vdp1_vram_r );
299DECLARE_READ32_HANDLER ( saturn_vdp1_framebuffer0_r );
300
301DECLARE_WRITE16_HANDLER ( saturn_vdp1_regs_w );
302DECLARE_WRITE32_HANDLER ( saturn_vdp1_vram_w );
303DECLARE_WRITE32_HANDLER ( saturn_vdp1_framebuffer0_w );
304
305/*----------- defined in video/stvvdp2.c -----------*/
306
307DECLARE_READ32_HANDLER ( saturn_vdp2_vram_r );
308DECLARE_READ32_HANDLER ( saturn_vdp2_cram_r );
309DECLARE_READ16_HANDLER ( saturn_vdp2_regs_r );
310
311DECLARE_WRITE32_HANDLER ( saturn_vdp2_vram_w );
312DECLARE_WRITE32_HANDLER ( saturn_vdp2_cram_w );
313DECLARE_WRITE16_HANDLER ( saturn_vdp2_regs_w );
314
trunk/src/mame/video/stvvdp1.c
r20790r20791
100100   ---- ---- ---- --x- | Frame Buffer Change Trigger (FCM)
101101   ---- ---- ---- ---x | Frame Buffer Change Mode (FCT)
102102*/
103#define STV_VDP1_FBCR ((state->m_vdp1_regs[0x002/2] >> 0)&0xffff)
103#define STV_VDP1_FBCR ((m_vdp1_regs[0x002/2] >> 0)&0xffff)
104104#define STV_VDP1_EOS ((STV_VDP1_FBCR & 0x0010) >> 4)
105105#define STV_VDP1_DIE ((STV_VDP1_FBCR & 0x0008) >> 3)
106106#define STV_VDP1_DIL ((STV_VDP1_FBCR & 0x0004) >> 2)
r20790r20791
118118   1 VDP1 draw by request
119119   0 VDP1 Idle (no access)
120120*/
121#define STV_VDP1_PTMR ((state->m_vdp1_regs[0x004/2])&0xffff)
121#define STV_VDP1_PTMR ((m_vdp1_regs[0x004/2])&0xffff)
122122#define STV_VDP1_PTM  ((STV_VDP1_PTMR & 0x0003) >> 0)
123#define PTM_0         state->m_vdp1_regs[0x004/2]&=~0x0001
123#define PTM_0         m_vdp1_regs[0x004/2]&=~0x0001
124124
125125/*
126126    Erase/Write Data Register
127127    16 bpp = data
128128    8 bpp = erase/write data for even/odd X coordinates
129129*/
130#define STV_VDP1_EWDR ((state->m_vdp1_regs[0x006/2])&0xffff)
130#define STV_VDP1_EWDR ((m_vdp1_regs[0x006/2])&0xffff)
131131
132132/*Erase/Write Upper-Left register*/
133133/*
r20790r20791
136136   ---- ---x xxxx xxxx | Y1 register
137137
138138*/
139#define STV_VDP1_EWLR ((state->m_vdp1_regs[0x008/2])&0xffff)
139#define STV_VDP1_EWLR ((m_vdp1_regs[0x008/2])&0xffff)
140140#define STV_VDP1_EWLR_X1 ((STV_VDP1_EWLR & 0x7e00) >> 9)
141141#define STV_VDP1_EWLR_Y1 ((STV_VDP1_EWLR & 0x01ff) >> 0)
142142/*Erase/Write Lower-Right register*/
r20790r20791
145145   ---- ---x xxxx xxxx | Y3 register
146146
147147*/
148#define STV_VDP1_EWRR ((state->m_vdp1_regs[0x00a/2])&0xffff)
148#define STV_VDP1_EWRR ((m_vdp1_regs[0x00a/2])&0xffff)
149149#define STV_VDP1_EWRR_X3 ((STV_VDP1_EWRR & 0xfe00) >> 9)
150150#define STV_VDP1_EWRR_Y3 ((STV_VDP1_EWRR & 0x01ff) >> 0)
151151/*Transfer End Status Register*/
r20790r20791
155155   ---- ---- ---- ---x | BEF
156156
157157*/
158#define STV_VDP1_EDSR ((state->m_vdp1_regs[0x010/2])&0xffff)
158#define STV_VDP1_EDSR ((m_vdp1_regs[0x010/2])&0xffff)
159159#define STV_VDP1_CEF  (STV_VDP1_EDSR & 2)
160160#define STV_VDP1_BEF  (STV_VDP1_EDSR & 1)
161161/**/
162162
163163
164164
165static void stv_vdp1_process_list(running_machine &machine);
166
167READ16_HANDLER( saturn_vdp1_regs_r )
165READ16_MEMBER( saturn_state::saturn_vdp1_regs_r )
168166{
169   saturn_state *state = space.machine().driver_data<saturn_state>();
170
171167   //logerror ("cpu %s (PC=%08X) VDP1: Read from Registers, Offset %04x\n", space.device().tag(), space.device().safe_pc(), offset);
172168
173169   switch(offset)
r20790r20791
176172         return 0;
177173      case 0x10/2:
178174         break;
179      case 0x12/2: return state->m_vdp1.lopr;
180      case 0x14/2: return state->m_vdp1.copr;
175      case 0x12/2: return m_vdp1.lopr;
176      case 0x14/2: return m_vdp1.copr;
181177      /* MODR register, read register for the other VDP1 regs
182178         (Shienryu SS version abuses of this during intro) */
183179      case 0x16/2:
r20790r20791
195191         return modr;
196192      default:
197193         if(!space.debugger_access())
198         printf ("cpu %s (PC=%08X) VDP1: Read from Registers, Offset %04x\n", space.device().tag(), space.device().safe_pc(), offset*2);
194            printf ("cpu %s (PC=%08X) VDP1: Read from Registers, Offset %04x\n", space.device().tag(), space.device().safe_pc(), offset*2);
199195         break;
200196   }
201197
202   return state->m_vdp1_regs[offset]; //TODO: write-only regs should return open bus or zero
198   return m_vdp1_regs[offset]; //TODO: write-only regs should return open bus or zero
203199}
204200
205static void stv_clear_framebuffer( running_machine &machine, int which_framebuffer )
201void saturn_state::stv_clear_framebuffer( int which_framebuffer )
206202{
207   saturn_state *state = machine.driver_data<saturn_state>();
208
209   if ( VDP1_LOG ) logerror( "Clearing %d framebuffer\n", state->m_vdp1.framebuffer_current_draw );
210   memset( state->m_vdp1.framebuffer[ which_framebuffer ], state->m_vdp1.ewdr, 1024 * 256 * sizeof(UINT16) * 2 );
203   if ( VDP1_LOG ) logerror( "Clearing %d framebuffer\n", m_vdp1.framebuffer_current_draw );
204   memset( m_vdp1.framebuffer[ which_framebuffer ], m_vdp1.ewdr, 1024 * 256 * sizeof(UINT16) * 2 );
211205}
212206
213207
214static void stv_prepare_framebuffers( running_machine &machine )
208void saturn_state::stv_prepare_framebuffers( void )
215209{
216   saturn_state *state = machine.driver_data<saturn_state>();
217210   int i,rowsize;
218211
219   rowsize = state->m_vdp1.framebuffer_width;
220   if ( state->m_vdp1.framebuffer_current_draw == 0 )
212   rowsize = m_vdp1.framebuffer_width;
213   if ( m_vdp1.framebuffer_current_draw == 0 )
221214   {
222      for ( i = 0; i < state->m_vdp1.framebuffer_height; i++ )
215      for ( i = 0; i < m_vdp1.framebuffer_height; i++ )
223216      {
224         state->m_vdp1.framebuffer_draw_lines[i] = &state->m_vdp1.framebuffer[0][ i * rowsize ];
225         state->m_vdp1.framebuffer_display_lines[i] = &state->m_vdp1.framebuffer[1][ i * rowsize ];
217         m_vdp1.framebuffer_draw_lines[i] = &m_vdp1.framebuffer[0][ i * rowsize ];
218         m_vdp1.framebuffer_display_lines[i] = &m_vdp1.framebuffer[1][ i * rowsize ];
226219      }
227220      for ( ; i < 512; i++ )
228221      {
229         state->m_vdp1.framebuffer_draw_lines[i] = &state->m_vdp1.framebuffer[0][0];
230         state->m_vdp1.framebuffer_display_lines[i] = &state->m_vdp1.framebuffer[1][0];
222         m_vdp1.framebuffer_draw_lines[i] = &m_vdp1.framebuffer[0][0];
223         m_vdp1.framebuffer_display_lines[i] = &m_vdp1.framebuffer[1][0];
231224      }
232225   }
233226   else
234227   {
235      for ( i = 0; i < state->m_vdp1.framebuffer_height; i++ )
228      for ( i = 0; i < m_vdp1.framebuffer_height; i++ )
236229      {
237         state->m_vdp1.framebuffer_draw_lines[i] = &state->m_vdp1.framebuffer[1][ i * rowsize ];
238         state->m_vdp1.framebuffer_display_lines[i] = &state->m_vdp1.framebuffer[0][ i * rowsize ];
230         m_vdp1.framebuffer_draw_lines[i] = &m_vdp1.framebuffer[1][ i * rowsize ];
231         m_vdp1.framebuffer_display_lines[i] = &m_vdp1.framebuffer[0][ i * rowsize ];
239232      }
240233      for ( ; i < 512; i++ )
241234      {
242         state->m_vdp1.framebuffer_draw_lines[i] = &state->m_vdp1.framebuffer[1][0];
243         state->m_vdp1.framebuffer_display_lines[i] = &state->m_vdp1.framebuffer[0][0];
235         m_vdp1.framebuffer_draw_lines[i] = &m_vdp1.framebuffer[1][0];
236         m_vdp1.framebuffer_display_lines[i] = &m_vdp1.framebuffer[0][0];
244237      }
245238
246239   }
247240
248241   for ( ; i < 512; i++ )
249242   {
250      state->m_vdp1.framebuffer_draw_lines[i] = &state->m_vdp1.framebuffer[0][0];
251      state->m_vdp1.framebuffer_display_lines[i] = &state->m_vdp1.framebuffer[1][0];
243      m_vdp1.framebuffer_draw_lines[i] = &m_vdp1.framebuffer[0][0];
244      m_vdp1.framebuffer_display_lines[i] = &m_vdp1.framebuffer[1][0];
252245   }
253246
254247}
255248
256static void stv_vdp1_change_framebuffers( running_machine &machine )
249void saturn_state::stv_vdp1_change_framebuffers( void )
257250{
258   saturn_state *state = machine.driver_data<saturn_state>();
259   state->m_vdp1.framebuffer_current_display ^= 1;
260   state->m_vdp1.framebuffer_current_draw ^= 1;
261   if ( VDP1_LOG ) logerror( "Changing framebuffers: %d - draw, %d - display\n", state->m_vdp1.framebuffer_current_draw, state->m_vdp1.framebuffer_current_display );
262   stv_prepare_framebuffers(machine);
251   m_vdp1.framebuffer_current_display ^= 1;
252   m_vdp1.framebuffer_current_draw ^= 1;
253   if ( VDP1_LOG ) logerror( "Changing framebuffers: %d - draw, %d - display\n", m_vdp1.framebuffer_current_draw, m_vdp1.framebuffer_current_display );
254   stv_prepare_framebuffers();
263255}
264256
265static void stv_set_framebuffer_config( running_machine &machine )
257void saturn_state::stv_set_framebuffer_config( void )
266258{
267   saturn_state *state = machine.driver_data<saturn_state>();
268   if ( state->m_vdp1.framebuffer_mode == STV_VDP1_TVM &&
269         state->m_vdp1.framebuffer_double_interlace == STV_VDP1_DIE ) return;
259   if ( m_vdp1.framebuffer_mode == STV_VDP1_TVM &&
260       m_vdp1.framebuffer_double_interlace == STV_VDP1_DIE ) return;
270261
271262   if ( VDP1_LOG ) logerror( "Setting framebuffer config\n" );
272   state->m_vdp1.framebuffer_mode = STV_VDP1_TVM;
273   state->m_vdp1.framebuffer_double_interlace = STV_VDP1_DIE;
274   switch( state->m_vdp1.framebuffer_mode )
263   m_vdp1.framebuffer_mode = STV_VDP1_TVM;
264   m_vdp1.framebuffer_double_interlace = STV_VDP1_DIE;
265   switch( m_vdp1.framebuffer_mode )
275266   {
276      case 0: state->m_vdp1.framebuffer_width = 512; state->m_vdp1.framebuffer_height = 256; break;
277      case 1: state->m_vdp1.framebuffer_width = 1024; state->m_vdp1.framebuffer_height = 256; break;
278      case 2: state->m_vdp1.framebuffer_width = 512; state->m_vdp1.framebuffer_height = 256; break;
279      case 3: state->m_vdp1.framebuffer_width = 512; state->m_vdp1.framebuffer_height = 512; break;
280      case 4: state->m_vdp1.framebuffer_width = 512; state->m_vdp1.framebuffer_height = 256; break;
281      default: logerror( "Invalid framebuffer config %x\n", STV_VDP1_TVM ); state->m_vdp1.framebuffer_width = 512; state->m_vdp1.framebuffer_height = 256; break;
267      case 0: m_vdp1.framebuffer_width = 512; m_vdp1.framebuffer_height = 256; break;
268      case 1: m_vdp1.framebuffer_width = 1024; m_vdp1.framebuffer_height = 256; break;
269      case 2: m_vdp1.framebuffer_width = 512; m_vdp1.framebuffer_height = 256; break;
270      case 3: m_vdp1.framebuffer_width = 512; m_vdp1.framebuffer_height = 512; break;
271      case 4: m_vdp1.framebuffer_width = 512; m_vdp1.framebuffer_height = 256; break;
272      default: logerror( "Invalid framebuffer config %x\n", STV_VDP1_TVM ); m_vdp1.framebuffer_width = 512; m_vdp1.framebuffer_height = 256; break;
282273   }
283   if ( STV_VDP1_DIE ) state->m_vdp1.framebuffer_height *= 2; /* double interlace */
274   if ( STV_VDP1_DIE ) m_vdp1.framebuffer_height *= 2; /* double interlace */
284275
285   state->m_vdp1.framebuffer_current_draw = 0;
286   state->m_vdp1.framebuffer_current_display = 1;
287   stv_prepare_framebuffers(machine);
276   m_vdp1.framebuffer_current_draw = 0;
277   m_vdp1.framebuffer_current_display = 1;
278   stv_prepare_framebuffers();
288279}
289280
290WRITE16_HANDLER( saturn_vdp1_regs_w )
281WRITE16_MEMBER( saturn_state::saturn_vdp1_regs_w )
291282{
292   saturn_state *state = space.machine().driver_data<saturn_state>();
293   COMBINE_DATA(&state->m_vdp1_regs[offset]);
283   COMBINE_DATA(&m_vdp1_regs[offset]);
294284
295285   switch(offset)
296286   {
297287      case 0x00/2:
298         stv_set_framebuffer_config(space.machine());
288         stv_set_framebuffer_config();
299289         if ( VDP1_LOG ) logerror( "VDP1: Access to register TVMR = %1X\n", STV_VDP1_TVMR );
300290
301291         break;
302292      case 0x02/2:
303         stv_set_framebuffer_config(space.machine());
293         stv_set_framebuffer_config();
304294         if ( VDP1_LOG ) logerror( "VDP1: Access to register FBCR = %1X\n", STV_VDP1_FBCR );
305         state->m_vdp1.fbcr_accessed = 1;
295         m_vdp1.fbcr_accessed = 1;
306296         break;
307297      case 0x04/2:
308298         if ( VDP1_LOG ) logerror( "VDP1: Access to register PTMR = %1X\n", STV_VDP1_PTM );
309299         if ( STV_VDP1_PTMR == 1 )
310            stv_vdp1_process_list( space.machine() );
300            stv_vdp1_process_list();
311301
312302         break;
313303      case 0x06/2:
314304         if ( VDP1_LOG ) logerror( "VDP1: Erase data set %08X\n", data );
315305
316         state->m_vdp1.ewdr = STV_VDP1_EWDR;
306         m_vdp1.ewdr = STV_VDP1_EWDR;
317307         break;
318308      case 0x08/2:
319309         if ( VDP1_LOG ) logerror( "VDP1: Erase upper-left coord set: %08X\n", data );
r20790r20791
331321
332322}
333323
334READ32_HANDLER ( saturn_vdp1_vram_r )
324READ32_MEMBER ( saturn_state::saturn_vdp1_vram_r )
335325{
336   saturn_state *state = space.machine().driver_data<saturn_state>();
337   return state->m_vdp1_vram[offset];
326   return m_vdp1_vram[offset];
338327}
339328
340329
341WRITE32_HANDLER ( saturn_vdp1_vram_w )
330WRITE32_MEMBER ( saturn_state::saturn_vdp1_vram_w )
342331{
343   saturn_state *state = space.machine().driver_data<saturn_state>();
344   UINT8 *vdp1 = state->m_vdp1.gfx_decode;
332   UINT8 *vdp1 = m_vdp1.gfx_decode;
345333
346   COMBINE_DATA (&state->m_vdp1_vram[offset]);
334   COMBINE_DATA (&m_vdp1_vram[offset]);
347335
348336//  if (((offset * 4) > 0xdf) && ((offset * 4) < 0x140))
349337//  {
350338//      logerror("cpu %s (PC=%08X): VRAM dword write to %08X = %08X & %08X\n", space.device().tag(), space.device().safe_pc(), offset*4, data, mem_mask);
351339//  }
352340
353   data = state->m_vdp1_vram[offset];
341   data = m_vdp1_vram[offset];
354342   /* put in gfx region for easy decoding */
355343   vdp1[offset*4+0] = (data & 0xff000000) >> 24;
356344   vdp1[offset*4+1] = (data & 0x00ff0000) >> 16;
r20790r20791
358346   vdp1[offset*4+3] = (data & 0x000000ff) >> 0;
359347}
360348
361WRITE32_HANDLER ( saturn_vdp1_framebuffer0_w )
349WRITE32_MEMBER ( saturn_state::saturn_vdp1_framebuffer0_w )
362350{
363   saturn_state *state = space.machine().driver_data<saturn_state>();
364351   //popmessage ("STV VDP1 Framebuffer 0 WRITE offset %08x data %08x",offset, data);
365352   if ( STV_VDP1_TVM & 1 )
366353   {
r20790r20791
368355      //printf("VDP1 8-bit mode %08x %02x\n",offset,data);
369356      if ( ACCESSING_BITS_24_31 )
370357      {
371         state->m_vdp1.framebuffer[state->m_vdp1.framebuffer_current_draw][offset*2] &= 0x00ff;
372         state->m_vdp1.framebuffer[state->m_vdp1.framebuffer_current_draw][offset*2] |= data & 0xff00;
358         m_vdp1.framebuffer[m_vdp1.framebuffer_current_draw][offset*2] &= 0x00ff;
359         m_vdp1.framebuffer[m_vdp1.framebuffer_current_draw][offset*2] |= data & 0xff00;
373360      }
374361      if ( ACCESSING_BITS_16_23 )
375362      {
376         state->m_vdp1.framebuffer[state->m_vdp1.framebuffer_current_draw][offset*2] &= 0xff00;
377         state->m_vdp1.framebuffer[state->m_vdp1.framebuffer_current_draw][offset*2] |= data & 0x00ff;
363         m_vdp1.framebuffer[m_vdp1.framebuffer_current_draw][offset*2] &= 0xff00;
364         m_vdp1.framebuffer[m_vdp1.framebuffer_current_draw][offset*2] |= data & 0x00ff;
378365      }
379366      if ( ACCESSING_BITS_8_15 )
380367      {
381         state->m_vdp1.framebuffer[state->m_vdp1.framebuffer_current_draw][offset*2+1] &= 0x00ff;
382         state->m_vdp1.framebuffer[state->m_vdp1.framebuffer_current_draw][offset*2+1] |= data & 0xff00;
368         m_vdp1.framebuffer[m_vdp1.framebuffer_current_draw][offset*2+1] &= 0x00ff;
369         m_vdp1.framebuffer[m_vdp1.framebuffer_current_draw][offset*2+1] |= data & 0xff00;
383370      }
384371      if ( ACCESSING_BITS_0_7 )
385372      {
386         state->m_vdp1.framebuffer[state->m_vdp1.framebuffer_current_draw][offset*2+1] &= 0xff00;
387         state->m_vdp1.framebuffer[state->m_vdp1.framebuffer_current_draw][offset*2+1] |= data & 0x00ff;
373         m_vdp1.framebuffer[m_vdp1.framebuffer_current_draw][offset*2+1] &= 0xff00;
374         m_vdp1.framebuffer[m_vdp1.framebuffer_current_draw][offset*2+1] |= data & 0x00ff;
388375      }
389376   }
390377   else
r20790r20791
392379      /* 16-bit mode */
393380      if ( ACCESSING_BITS_16_31 )
394381      {
395         state->m_vdp1.framebuffer[state->m_vdp1.framebuffer_current_draw][offset*2] = (data >> 16) & 0xffff;
382         m_vdp1.framebuffer[m_vdp1.framebuffer_current_draw][offset*2] = (data >> 16) & 0xffff;
396383      }
397384      if ( ACCESSING_BITS_0_15 )
398385      {
399         state->m_vdp1.framebuffer[state->m_vdp1.framebuffer_current_draw][offset*2+1] = data & 0xffff;
386         m_vdp1.framebuffer[m_vdp1.framebuffer_current_draw][offset*2+1] = data & 0xffff;
400387      }
401388   }
402389}
403390
404READ32_HANDLER ( saturn_vdp1_framebuffer0_r )
391READ32_MEMBER ( saturn_state::saturn_vdp1_framebuffer0_r )
405392{
406   saturn_state *state = space.machine().driver_data<saturn_state>();
407393   UINT32 result = 0;
408394   //popmessage ("STV VDP1 Framebuffer 0 READ offset %08x",offset);
409395   if ( STV_VDP1_TVM & 1 )
r20790r20791
411397      /* 8-bit mode */
412398      //printf("VDP1 8-bit mode %08x\n",offset);
413399      if ( ACCESSING_BITS_24_31 )
414         result |= ((state->m_vdp1.framebuffer[state->m_vdp1.framebuffer_current_draw][offset*2] & 0xff00) << 16);
400         result |= ((m_vdp1.framebuffer[m_vdp1.framebuffer_current_draw][offset*2] & 0xff00) << 16);
415401      if ( ACCESSING_BITS_16_23 )
416         result |= ((state->m_vdp1.framebuffer[state->m_vdp1.framebuffer_current_draw][offset*2] & 0x00ff) << 16);
402         result |= ((m_vdp1.framebuffer[m_vdp1.framebuffer_current_draw][offset*2] & 0x00ff) << 16);
417403      if ( ACCESSING_BITS_8_15 )
418         result |= ((state->m_vdp1.framebuffer[state->m_vdp1.framebuffer_current_draw][offset*2+1] & 0xff00));
404         result |= ((m_vdp1.framebuffer[m_vdp1.framebuffer_current_draw][offset*2+1] & 0xff00));
419405      if ( ACCESSING_BITS_0_7 )
420         result |= ((state->m_vdp1.framebuffer[state->m_vdp1.framebuffer_current_draw][offset*2+1] & 0x00ff));
406         result |= ((m_vdp1.framebuffer[m_vdp1.framebuffer_current_draw][offset*2+1] & 0x00ff));
421407   }
422408   else
423409   {
424410      /* 16-bit mode */
425411      if ( ACCESSING_BITS_16_31 )
426412      {
427         result |= (state->m_vdp1.framebuffer[state->m_vdp1.framebuffer_current_draw][offset*2] << 16);
413         result |= (m_vdp1.framebuffer[m_vdp1.framebuffer_current_draw][offset*2] << 16);
428414      }
429415      if ( ACCESSING_BITS_0_15 )
430416      {
431         result |= (state->m_vdp1.framebuffer[state->m_vdp1.framebuffer_current_draw][offset*2+1]);
417         result |= (m_vdp1.framebuffer[m_vdp1.framebuffer_current_draw][offset*2+1]);
432418      }
433419
434420   }
r20790r20791
543529   memset( &stv_gouraud_shading, 0, sizeof( stv_gouraud_shading ) );
544530}
545531
546static UINT8 stv_read_gouraud_table(running_machine &machine)
532UINT8 saturn_state::stv_read_gouraud_table( void )
547533{
548   saturn_state *state = machine.driver_data<saturn_state>();
549534   int gaddr;
550535
551536   if ( (stv2_current_sprite.CMDPMOD & 0x7) == 4 )
552537   {
553538      gaddr = stv2_current_sprite.CMDGRDA * 8;
554      stv_gouraud_shading.GA = (state->m_vdp1_vram[gaddr/4] >> 16) & 0xffff;
555      stv_gouraud_shading.GB = (state->m_vdp1_vram[gaddr/4] >> 0) & 0xffff;
556      stv_gouraud_shading.GC = (state->m_vdp1_vram[gaddr/4 + 1] >> 16) & 0xffff;
557      stv_gouraud_shading.GD = (state->m_vdp1_vram[gaddr/4 + 1] >> 0) & 0xffff;
539      stv_gouraud_shading.GA = (m_vdp1_vram[gaddr/4] >> 16) & 0xffff;
540      stv_gouraud_shading.GB = (m_vdp1_vram[gaddr/4] >> 0) & 0xffff;
541      stv_gouraud_shading.GC = (m_vdp1_vram[gaddr/4 + 1] >> 16) & 0xffff;
542      stv_gouraud_shading.GD = (m_vdp1_vram[gaddr/4 + 1] >> 0) & 0xffff;
558543      return 1;
559544   }
560545   else
r20790r20791
705690   *ng2 = g2;
706691}
707692
708static void stv_vdp1_setup_shading(running_machine &machine,const struct spoint* q, const rectangle &cliprect)
693void saturn_state::stv_vdp1_setup_shading(const struct spoint* q, const rectangle &cliprect)
709694{
710695   INT32 x1, x2, delta, cury, limy;
711696   INT32 r1, g1, b1, r2, g2, b2;
r20790r20791
715700   struct shaded_point p[8];
716701   UINT16 gd[4];
717702
718   if ( stv_read_gouraud_table(machine) == 0 ) return;
703   if ( stv_read_gouraud_table() == 0 ) return;
719704
720705   gd[0] = stv_gouraud_shading.GA;
721706   gd[1] = stv_gouraud_shading.GB;
r20790r20791
10801065}
10811066
10821067
1083static void stv_vdp1_set_drawpixel(running_machine &machine)
1068void saturn_state::stv_vdp1_set_drawpixel( void )
10841069{
1085   saturn_state *state = machine.driver_data<saturn_state>();
10861070   int sprite_type = stv2_current_sprite.CMDCTRL & 0x000f;
10871071   int sprite_mode = stv2_current_sprite.CMDPMOD&0x0038;
10881072   int spd = stv2_current_sprite.CMDPMOD & 0x40;
10891073   int mesh = stv2_current_sprite.CMDPMOD & 0x100;
10901074   int ecd = stv2_current_sprite.CMDPMOD & 0x80;
10911075
1092   gfxdata = state->m_vdp1.gfx_decode;
1076   gfxdata = m_vdp1.gfx_decode;
10931077
10941078   if ( mesh || !ecd || ((stv2_current_sprite.CMDPMOD & 0x7) != 0) )
10951079   {
r20790r20791
11231107}
11241108
11251109
1126static void vdp1_fill_slope(running_machine &machine, const rectangle &cliprect, int patterndata, int xsize,
1110void saturn_state::vdp1_fill_slope(const rectangle &cliprect, int patterndata, int xsize,
11271111                     INT32 x1, INT32 x2, INT32 sl1, INT32 sl2, INT32 *nx1, INT32 *nx2,
11281112                     INT32 u1, INT32 u2, INT32 slu1, INT32 slu2, INT32 *nu1, INT32 *nu2,
11291113                     INT32 v1, INT32 v2, INT32 slv1, INT32 slv2, INT32 *nv1, INT32 *nv2,
r20790r20791
12131197               xx2 = cliprect.max_x;
12141198
12151199            while(xx1 <= xx2) {
1216               drawpixel(machine,xx1,_y1,
1200               drawpixel(machine(),xx1,_y1,
12171201                        patterndata,
12181202                        (v>>FRAC_SHIFT)*xsize+(u>>FRAC_SHIFT));
12191203               xx1++;
r20790r20791
12391223   *nv2 = v2;
12401224}
12411225
1242static void vdp1_fill_line(running_machine &machine, const rectangle &cliprect, int patterndata, int xsize, INT32 y,
1226void saturn_state::vdp1_fill_line(const rectangle &cliprect, int patterndata, int xsize, INT32 y,
12431227                     INT32 x1, INT32 x2, INT32 u1, INT32 u2, INT32 v1, INT32 v2)
12441228{
12451229   int xx1 = x1>>FRAC_SHIFT;
r20790r20791
12671251         xx2 = cliprect.max_x;
12681252
12691253      while(xx1 <= xx2) {
1270         drawpixel(machine,xx1,y,
1254         drawpixel(machine(), xx1,y,
12711255                  patterndata,
12721256                  (v>>FRAC_SHIFT)*xsize+(u>>FRAC_SHIFT));
12731257         xx1++;
r20790r20791
12771261   }
12781262}
12791263
1280static void vdp1_fill_quad(running_machine &machine, const rectangle &cliprect, int patterndata, int xsize, const struct spoint *q)
1264void saturn_state::vdp1_fill_quad(const rectangle &cliprect, int patterndata, int xsize, const struct spoint *q)
12811265{
12821266   INT32 sl1, sl2, slu1, slu2, slv1, slv2, cury, limy, x1, x2, u1, u2, v1, v2, delta;
12831267   int pmin, pmax, i, ps1, ps2;
r20790r20791
13171301            v2 = p[i].v;
13181302         }
13191303      }
1320      vdp1_fill_line(machine, cliprect, patterndata, xsize, cury, x1, x2, u1, u2, v1, v2);
1304      vdp1_fill_line(cliprect, patterndata, xsize, cury, x1, x2, u1, u2, v1, v2);
13211305      return;
13221306   }
13231307
r20790r20791
13361320
13371321   for(;;) {
13381322      if(p[ps1-1].y == p[ps2+1].y) {
1339         vdp1_fill_slope(machine, cliprect, patterndata, xsize,
1323         vdp1_fill_slope(cliprect, patterndata, xsize,
13401324                     x1, x2, sl1, sl2, &x1, &x2,
13411325                     u1, u2, slu1, slu2, &u1, &u2,
13421326                     v1, v2, slv1, slv2, &v1, &v2,
r20790r20791
13691353         slu2 = (u2-p[ps2+1].u)/delta;
13701354         slv2 = (v2-p[ps2+1].v)/delta;
13711355      } else if(p[ps1-1].y < p[ps2+1].y) {
1372         vdp1_fill_slope(machine, cliprect, patterndata, xsize,
1356         vdp1_fill_slope(cliprect, patterndata, xsize,
13731357                     x1, x2, sl1, sl2, &x1, &x2,
13741358                     u1, u2, slu1, slu2, &u1, &u2,
13751359                     v1, v2, slv1, slv2, &v1, &v2,
r20790r20791
13891373         slu1 = (u1-p[ps1-1].u)/delta;
13901374         slv1 = (v1-p[ps1-1].v)/delta;
13911375      } else {
1392         vdp1_fill_slope(machine, cliprect, patterndata, xsize,
1376         vdp1_fill_slope(cliprect, patterndata, xsize,
13931377                     x1, x2, sl1, sl2, &x1, &x2,
13941378                     u1, u2, slu1, slu2, &u1, &u2,
13951379                     v1, v2, slv1, slv2, &v1, &v2,
r20790r20791
14111395      }
14121396   }
14131397   if(cury == limy)
1414      vdp1_fill_line(machine, cliprect, patterndata, xsize, cury, x1, x2, u1, u2, v1, v2);
1398      vdp1_fill_line(cliprect, patterndata, xsize, cury, x1, x2, u1, u2, v1, v2);
14151399}
14161400
1417static int x2s(running_machine &machine,int v)
1401int saturn_state::x2s(int v)
14181402{
1419   saturn_state *state = machine.driver_data<saturn_state>();
1420
1421   return (INT32)(INT16)v + state->m_vdp1.local_x;
1403   return (INT32)(INT16)v + m_vdp1.local_x;
14221404}
14231405
1424static int y2s(running_machine &machine, int v)
1406int saturn_state::y2s(int v)
14251407{
1426   saturn_state *state = machine.driver_data<saturn_state>();
1427
1428   return (INT32)(INT16)v + state->m_vdp1.local_y;
1408   return (INT32)(INT16)v + m_vdp1.local_y;
14291409}
14301410
1431static void stv_vdp1_draw_line(running_machine &machine, const rectangle &cliprect)
1411void saturn_state::stv_vdp1_draw_line(const rectangle &cliprect)
14321412{
14331413   struct spoint q[4];
14341414
1435   q[0].x = x2s(machine, stv2_current_sprite.CMDXA);
1436   q[0].y = y2s(machine, stv2_current_sprite.CMDYA);
1437   q[1].x = x2s(machine, stv2_current_sprite.CMDXB);
1438   q[1].y = y2s(machine, stv2_current_sprite.CMDYB);
1439   q[2].x = x2s(machine, stv2_current_sprite.CMDXA);
1440   q[2].y = y2s(machine, stv2_current_sprite.CMDYA);
1441   q[3].x = x2s(machine, stv2_current_sprite.CMDXB);
1442   q[3].y = y2s(machine, stv2_current_sprite.CMDYB);
1415   q[0].x = x2s(stv2_current_sprite.CMDXA);
1416   q[0].y = y2s(stv2_current_sprite.CMDYA);
1417   q[1].x = x2s(stv2_current_sprite.CMDXB);
1418   q[1].y = y2s(stv2_current_sprite.CMDYB);
1419   q[2].x = x2s(stv2_current_sprite.CMDXA);
1420   q[2].y = y2s(stv2_current_sprite.CMDYA);
1421   q[3].x = x2s(stv2_current_sprite.CMDXB);
1422   q[3].y = y2s(stv2_current_sprite.CMDYB);
14431423
14441424   q[0].u = q[3].u = q[1].u = q[2].u = 0;
14451425   q[0].v = q[1].v = q[2].v = q[3].v = 0;
14461426
1447   vdp1_fill_quad(machine, cliprect, 0, 1, q);
1427   vdp1_fill_quad(cliprect, 0, 1, q);
14481428}
14491429
1450static void stv_vdp1_draw_poly_line(running_machine &machine, const rectangle &cliprect)
1430void saturn_state::stv_vdp1_draw_poly_line(const rectangle &cliprect)
14511431{
14521432   struct spoint q[4];
14531433
1454   q[0].x = x2s(machine, stv2_current_sprite.CMDXA);
1455   q[0].y = y2s(machine, stv2_current_sprite.CMDYA);
1456   q[1].x = x2s(machine, stv2_current_sprite.CMDXB);
1457   q[1].y = y2s(machine, stv2_current_sprite.CMDYB);
1458   q[2].x = x2s(machine, stv2_current_sprite.CMDXA);
1459   q[2].y = y2s(machine, stv2_current_sprite.CMDYA);
1460   q[3].x = x2s(machine, stv2_current_sprite.CMDXB);
1461   q[3].y = y2s(machine, stv2_current_sprite.CMDYB);
1434   q[0].x = x2s(stv2_current_sprite.CMDXA);
1435   q[0].y = y2s(stv2_current_sprite.CMDYA);
1436   q[1].x = x2s(stv2_current_sprite.CMDXB);
1437   q[1].y = y2s(stv2_current_sprite.CMDYB);
1438   q[2].x = x2s(stv2_current_sprite.CMDXA);
1439   q[2].y = y2s(stv2_current_sprite.CMDYA);
1440   q[3].x = x2s(stv2_current_sprite.CMDXB);
1441   q[3].y = y2s(stv2_current_sprite.CMDYB);
14621442
14631443   q[0].u = q[3].u = q[1].u = q[2].u = 0;
14641444   q[0].v = q[1].v = q[2].v = q[3].v = 0;
14651445
1466   vdp1_fill_quad(machine, cliprect, 0, 1, q);
1446   vdp1_fill_quad(cliprect, 0, 1, q);
14671447
1468   q[0].x = x2s(machine, stv2_current_sprite.CMDXB);
1469   q[0].y = y2s(machine, stv2_current_sprite.CMDYB);
1470   q[1].x = x2s(machine, stv2_current_sprite.CMDXC);
1471   q[1].y = y2s(machine, stv2_current_sprite.CMDYC);
1472   q[2].x = x2s(machine, stv2_current_sprite.CMDXB);
1473   q[2].y = y2s(machine, stv2_current_sprite.CMDYB);
1474   q[3].x = x2s(machine, stv2_current_sprite.CMDXC);
1475   q[3].y = y2s(machine, stv2_current_sprite.CMDYC);
1448   q[0].x = x2s(stv2_current_sprite.CMDXB);
1449   q[0].y = y2s(stv2_current_sprite.CMDYB);
1450   q[1].x = x2s(stv2_current_sprite.CMDXC);
1451   q[1].y = y2s(stv2_current_sprite.CMDYC);
1452   q[2].x = x2s(stv2_current_sprite.CMDXB);
1453   q[2].y = y2s(stv2_current_sprite.CMDYB);
1454   q[3].x = x2s(stv2_current_sprite.CMDXC);
1455   q[3].y = y2s(stv2_current_sprite.CMDYC);
14761456
14771457   q[0].u = q[3].u = q[1].u = q[2].u = 0;
14781458   q[0].v = q[1].v = q[2].v = q[3].v = 0;
14791459
1480   vdp1_fill_quad(machine, cliprect, 0, 1, q);
1460   vdp1_fill_quad(cliprect, 0, 1, q);
14811461
1482   q[0].x = x2s(machine, stv2_current_sprite.CMDXC);
1483   q[0].y = y2s(machine, stv2_current_sprite.CMDYC);
1484   q[1].x = x2s(machine, stv2_current_sprite.CMDXD);
1485   q[1].y = y2s(machine, stv2_current_sprite.CMDYD);
1486   q[2].x = x2s(machine, stv2_current_sprite.CMDXC);
1487   q[2].y = y2s(machine, stv2_current_sprite.CMDYC);
1488   q[3].x = x2s(machine, stv2_current_sprite.CMDXD);
1489   q[3].y = y2s(machine, stv2_current_sprite.CMDYD);
1462   q[0].x = x2s(stv2_current_sprite.CMDXC);
1463   q[0].y = y2s(stv2_current_sprite.CMDYC);
1464   q[1].x = x2s(stv2_current_sprite.CMDXD);
1465   q[1].y = y2s(stv2_current_sprite.CMDYD);
1466   q[2].x = x2s(stv2_current_sprite.CMDXC);
1467   q[2].y = y2s(stv2_current_sprite.CMDYC);
1468   q[3].x = x2s(stv2_current_sprite.CMDXD);
1469   q[3].y = y2s(stv2_current_sprite.CMDYD);
14901470
14911471   q[0].u = q[3].u = q[1].u = q[2].u = 0;
14921472   q[0].v = q[1].v = q[2].v = q[3].v = 0;
14931473
1494   vdp1_fill_quad(machine, cliprect, 0, 1, q);
1474   vdp1_fill_quad(cliprect, 0, 1, q);
14951475
1496   q[0].x = x2s(machine, stv2_current_sprite.CMDXD);
1497   q[0].y = y2s(machine, stv2_current_sprite.CMDYD);
1498   q[1].x = x2s(machine, stv2_current_sprite.CMDXA);
1499   q[1].y = y2s(machine, stv2_current_sprite.CMDYA);
1500   q[2].x = x2s(machine, stv2_current_sprite.CMDXD);
1501   q[2].y = y2s(machine, stv2_current_sprite.CMDYD);
1502   q[3].x = x2s(machine, stv2_current_sprite.CMDXA);
1503   q[3].y = y2s(machine, stv2_current_sprite.CMDYA);
1476   q[0].x = x2s(stv2_current_sprite.CMDXD);
1477   q[0].y = y2s(stv2_current_sprite.CMDYD);
1478   q[1].x = x2s(stv2_current_sprite.CMDXA);
1479   q[1].y = y2s(stv2_current_sprite.CMDYA);
1480   q[2].x = x2s(stv2_current_sprite.CMDXD);
1481   q[2].y = y2s(stv2_current_sprite.CMDYD);
1482   q[3].x = x2s(stv2_current_sprite.CMDXA);
1483   q[3].y = y2s(stv2_current_sprite.CMDYA);
15041484
15051485   q[0].u = q[3].u = q[1].u = q[2].u = 0;
15061486   q[0].v = q[1].v = q[2].v = q[3].v = 0;
15071487
1508   stv_vdp1_setup_shading(machine, q, cliprect);
1509   vdp1_fill_quad(machine, cliprect, 0, 1, q);
1488   stv_vdp1_setup_shading(q, cliprect);
1489   vdp1_fill_quad(cliprect, 0, 1, q);
15101490
15111491}
15121492
1513static void stv_vpd1_draw_distorted_sprite(running_machine &machine, const rectangle &cliprect)
1493void saturn_state::stv_vdp1_draw_distorted_sprite(const rectangle &cliprect)
15141494{
15151495   struct spoint q[4];
15161496
r20790r20791
15401520   }
15411521
15421522
1543   q[0].x = x2s(machine, stv2_current_sprite.CMDXA);
1544   q[0].y = y2s(machine, stv2_current_sprite.CMDYA);
1545   q[1].x = x2s(machine, stv2_current_sprite.CMDXB);
1546   q[1].y = y2s(machine, stv2_current_sprite.CMDYB);
1547   q[2].x = x2s(machine, stv2_current_sprite.CMDXC);
1548   q[2].y = y2s(machine, stv2_current_sprite.CMDYC);
1549   q[3].x = x2s(machine, stv2_current_sprite.CMDXD);
1550   q[3].y = y2s(machine, stv2_current_sprite.CMDYD);
1523   q[0].x = x2s(stv2_current_sprite.CMDXA);
1524   q[0].y = y2s(stv2_current_sprite.CMDYA);
1525   q[1].x = x2s(stv2_current_sprite.CMDXB);
1526   q[1].y = y2s(stv2_current_sprite.CMDYB);
1527   q[2].x = x2s(stv2_current_sprite.CMDXC);
1528   q[2].y = y2s(stv2_current_sprite.CMDYC);
1529   q[3].x = x2s(stv2_current_sprite.CMDXD);
1530   q[3].y = y2s(stv2_current_sprite.CMDYD);
15511531
15521532   if(direction & 1) { // xflip
15531533      q[0].u = q[3].u = xsize-1;
r20790r20791
15641544      q[2].v = q[3].v = ysize-1;
15651545   }
15661546
1567   stv_vdp1_setup_shading(machine, q, cliprect);
1568   vdp1_fill_quad(machine, cliprect, patterndata, xsize, q);
1547   stv_vdp1_setup_shading(q, cliprect);
1548   vdp1_fill_quad(cliprect, patterndata, xsize, q);
15691549}
15701550
1571static void stv_vpd1_draw_scaled_sprite(running_machine &machine, const rectangle &cliprect)
1551void saturn_state::stv_vdp1_draw_scaled_sprite(const rectangle &cliprect)
15721552{
15731553   struct spoint q[4];
15741554
r20790r20791
16661646
16671647   if (zoompoint)
16681648   {
1669      q[0].x = x2s(machine, x);
1670      q[0].y = y2s(machine, y);
1671      q[1].x = x2s(machine, x)+screen_width;
1672      q[1].y = y2s(machine, y);
1673      q[2].x = x2s(machine, x)+screen_width;
1674      q[2].y = y2s(machine, y)+screen_height;
1675      q[3].x = x2s(machine, x);
1676      q[3].y = y2s(machine, y)+screen_height;
1649      q[0].x = x2s(x);
1650      q[0].y = y2s(y);
1651      q[1].x = x2s(x)+screen_width;
1652      q[1].y = y2s(y);
1653      q[2].x = x2s(x)+screen_width;
1654      q[2].y = y2s(y)+screen_height;
1655      q[3].x = x2s(x);
1656      q[3].y = y2s(y)+screen_height;
16771657
16781658      if ( screen_height_negative )
16791659      {
r20790r20791
16851665   }
16861666   else
16871667   {
1688      q[0].x = x2s(machine, x);
1689      q[0].y = y2s(machine, y);
1690      q[1].x = x2s(machine, x2);
1691      q[1].y = y2s(machine, y);
1692      q[2].x = x2s(machine, x2);
1693      q[2].y = y2s(machine, y2);
1694      q[3].x = x2s(machine, x);
1695      q[3].y = y2s(machine, y2);
1668      q[0].x = x2s(x);
1669      q[0].y = y2s(y);
1670      q[1].x = x2s(x2);
1671      q[1].y = y2s(y);
1672      q[2].x = x2s(x2);
1673      q[2].y = y2s(y2);
1674      q[3].x = x2s(x);
1675      q[3].y = y2s(y2);
16961676   }
16971677
16981678
r20790r20791
17111691      q[2].v = q[3].v = ysize-1;
17121692   }
17131693
1714   stv_vdp1_setup_shading(machine, q, cliprect);
1715   vdp1_fill_quad(machine, cliprect, patterndata, xsize, q);
1694   stv_vdp1_setup_shading(q, cliprect);
1695   vdp1_fill_quad(cliprect, patterndata, xsize, q);
17161696}
17171697
17181698
1719static void stv_vpd1_draw_normal_sprite(running_machine &machine, const rectangle &cliprect, int sprite_type)
1699void saturn_state::stv_vdp1_draw_normal_sprite(const rectangle &cliprect, int sprite_type)
17201700{
17211701   //UINT16 *destline;
17221702   //saturn_state *state = machine.driver_data<saturn_state>();
r20790r20791
17281708   int su, u, dux, duy;
17291709   int maxdrawypos, maxdrawxpos;
17301710
1731   x = x2s(machine, stv2_current_sprite.CMDXA);
1732   y = y2s(machine, stv2_current_sprite.CMDYA);
1711   x = x2s(stv2_current_sprite.CMDXA);
1712   y = y2s(stv2_current_sprite.CMDYA);
17331713
17341714   direction = (stv2_current_sprite.CMDCTRL & 0x0030)>>4;
17351715
r20790r20791
17461726   if ( x > cliprect.max_x ) return;
17471727   if ( y > cliprect.max_y ) return;
17481728
1749   shading = stv_read_gouraud_table(machine);
1729   shading = stv_read_gouraud_table();
17501730   if ( shading )
17511731   {
17521732      struct spoint q[4];
r20790r20791
17551735      q[2].x = x + xsize; q[2].y = y + ysize;
17561736      q[3].x = x; q[3].y = y + ysize;
17571737
1758      stv_vdp1_setup_shading( machine, q, cliprect );
1738      stv_vdp1_setup_shading( q, cliprect );
17591739   }
17601740
17611741   u = 0;
r20790r20791
17871767   maxdrawxpos = MIN(x+xsize-1,cliprect.max_x);
17881768   for (drawypos = y; drawypos <= maxdrawypos; drawypos++ )
17891769   {
1790      //destline = state->m_vdp1.framebuffer_draw_lines[drawypos];
1770      //destline = m_vdp1.framebuffer_draw_lines[drawypos];
17911771      su = u;
17921772      for (drawxpos = x; drawxpos <= maxdrawxpos; drawxpos++ )
17931773      {
1794         drawpixel( machine, drawxpos, drawypos, patterndata, u );
1774         drawpixel( machine(), drawxpos, drawypos, patterndata, u );
17951775         u += dux;
17961776      }
17971777      u = su + duy;
17981778   }
17991779}
18001780
1801static void stv_vdp1_process_list(running_machine &machine)
1781void saturn_state::stv_vdp1_process_list( void )
18021782{
1803   saturn_state *state = machine.driver_data<saturn_state>();
18041783   int position;
18051784   int spritecount;
18061785   int vdp1_nest;
r20790r20791
18301809   //      position = 0;
18311810   //  }
18321811
1833      stv2_current_sprite.CMDCTRL = (state->m_vdp1_vram[position * (0x20/4)+0] & 0xffff0000) >> 16;
1812      stv2_current_sprite.CMDCTRL = (m_vdp1_vram[position * (0x20/4)+0] & 0xffff0000) >> 16;
18341813
18351814      if (stv2_current_sprite.CMDCTRL == 0x8000)
18361815      {
r20790r20791
18381817         goto end; // end of list
18391818      }
18401819
1841      stv2_current_sprite.CMDLINK = (state->m_vdp1_vram[position * (0x20/4)+0] & 0x0000ffff) >> 0;
1842      stv2_current_sprite.CMDPMOD = (state->m_vdp1_vram[position * (0x20/4)+1] & 0xffff0000) >> 16;
1843      stv2_current_sprite.CMDCOLR = (state->m_vdp1_vram[position * (0x20/4)+1] & 0x0000ffff) >> 0;
1844      stv2_current_sprite.CMDSRCA = (state->m_vdp1_vram[position * (0x20/4)+2] & 0xffff0000) >> 16;
1845      stv2_current_sprite.CMDSIZE = (state->m_vdp1_vram[position * (0x20/4)+2] & 0x0000ffff) >> 0;
1846      stv2_current_sprite.CMDXA   = (state->m_vdp1_vram[position * (0x20/4)+3] & 0xffff0000) >> 16;
1847      stv2_current_sprite.CMDYA   = (state->m_vdp1_vram[position * (0x20/4)+3] & 0x0000ffff) >> 0;
1848      stv2_current_sprite.CMDXB   = (state->m_vdp1_vram[position * (0x20/4)+4] & 0xffff0000) >> 16;
1849      stv2_current_sprite.CMDYB   = (state->m_vdp1_vram[position * (0x20/4)+4] & 0x0000ffff) >> 0;
1850      stv2_current_sprite.CMDXC   = (state->m_vdp1_vram[position * (0x20/4)+5] & 0xffff0000) >> 16;
1851      stv2_current_sprite.CMDYC   = (state->m_vdp1_vram[position * (0x20/4)+5] & 0x0000ffff) >> 0;
1852      stv2_current_sprite.CMDXD   = (state->m_vdp1_vram[position * (0x20/4)+6] & 0xffff0000) >> 16;
1853      stv2_current_sprite.CMDYD   = (state->m_vdp1_vram[position * (0x20/4)+6] & 0x0000ffff) >> 0;
1854      stv2_current_sprite.CMDGRDA = (state->m_vdp1_vram[position * (0x20/4)+7] & 0xffff0000) >> 16;
1855//      stv2_current_sprite.UNUSED  = (state->m_vdp1_vram[position * (0x20/4)+7] & 0x0000ffff) >> 0;
1820      stv2_current_sprite.CMDLINK = (m_vdp1_vram[position * (0x20/4)+0] & 0x0000ffff) >> 0;
1821      stv2_current_sprite.CMDPMOD = (m_vdp1_vram[position * (0x20/4)+1] & 0xffff0000) >> 16;
1822      stv2_current_sprite.CMDCOLR = (m_vdp1_vram[position * (0x20/4)+1] & 0x0000ffff) >> 0;
1823      stv2_current_sprite.CMDSRCA = (m_vdp1_vram[position * (0x20/4)+2] & 0xffff0000) >> 16;
1824      stv2_current_sprite.CMDSIZE = (m_vdp1_vram[position * (0x20/4)+2] & 0x0000ffff) >> 0;
1825      stv2_current_sprite.CMDXA   = (m_vdp1_vram[position * (0x20/4)+3] & 0xffff0000) >> 16;
1826      stv2_current_sprite.CMDYA   = (m_vdp1_vram[position * (0x20/4)+3] & 0x0000ffff) >> 0;
1827      stv2_current_sprite.CMDXB   = (m_vdp1_vram[position * (0x20/4)+4] & 0xffff0000) >> 16;
1828      stv2_current_sprite.CMDYB   = (m_vdp1_vram[position * (0x20/4)+4] & 0x0000ffff) >> 0;
1829      stv2_current_sprite.CMDXC   = (m_vdp1_vram[position * (0x20/4)+5] & 0xffff0000) >> 16;
1830      stv2_current_sprite.CMDYC   = (m_vdp1_vram[position * (0x20/4)+5] & 0x0000ffff) >> 0;
1831      stv2_current_sprite.CMDXD   = (m_vdp1_vram[position * (0x20/4)+6] & 0xffff0000) >> 16;
1832      stv2_current_sprite.CMDYD   = (m_vdp1_vram[position * (0x20/4)+6] & 0x0000ffff) >> 0;
1833      stv2_current_sprite.CMDGRDA = (m_vdp1_vram[position * (0x20/4)+7] & 0xffff0000) >> 16;
1834//      stv2_current_sprite.UNUSED  = (m_vdp1_vram[position * (0x20/4)+7] & 0x0000ffff) >> 0;
18561835
18571836      /* proecess jump / skip commands, set position for next sprite */
18581837      switch (stv2_current_sprite.CMDCTRL & 0x7000)
r20790r20791
19411920         if ( stv2_current_sprite.CMDPMOD & 0x0400 )
19421921         {
19431922            //if(stv2_current_sprite.CMDPMOD & 0x0200) /* TODO: Bio Hazard inventory screen uses outside cliprect */
1944            //  cliprect = &state->m_vdp1.system_cliprect;
1923            //  cliprect = &m_vdp1.system_cliprect;
19451924            //else
1946               cliprect = &state->m_vdp1.user_cliprect;
1925               cliprect = &m_vdp1.user_cliprect;
19471926         }
19481927         else
19491928         {
1950            cliprect = &state->m_vdp1.system_cliprect;
1929            cliprect = &m_vdp1.system_cliprect;
19511930         }
19521931
1953         stv_vdp1_set_drawpixel(machine);
1932         stv_vdp1_set_drawpixel();
19541933
19551934         switch (stv2_current_sprite.CMDCTRL & 0x000f)
19561935         {
19571936            case 0x0000:
19581937               if (VDP1_LOG) logerror ("Sprite List Normal Sprite (%d %d)\n",stv2_current_sprite.CMDXA,stv2_current_sprite.CMDYA);
19591938               stv2_current_sprite.ispoly = 0;
1960               stv_vpd1_draw_normal_sprite(machine, *cliprect, 0);
1939               stv_vdp1_draw_normal_sprite(*cliprect, 0);
19611940               break;
19621941
19631942            case 0x0001:
19641943               if (VDP1_LOG) logerror ("Sprite List Scaled Sprite (%d %d)\n",stv2_current_sprite.CMDXA,stv2_current_sprite.CMDYA);
19651944               stv2_current_sprite.ispoly = 0;
1966               stv_vpd1_draw_scaled_sprite(machine, *cliprect);
1945               stv_vdp1_draw_scaled_sprite(*cliprect);
19671946               break;
19681947
19691948            case 0x0002:
r20790r20791
19761955               if (VDP1_LOG) logerror ("CMDPMOD = %04x\n",stv2_current_sprite.CMDPMOD);
19771956
19781957               stv2_current_sprite.ispoly = 0;
1979               stv_vpd1_draw_distorted_sprite(machine, *cliprect);
1958               stv_vdp1_draw_distorted_sprite(*cliprect);
19801959               break;
19811960
19821961            case 0x0004:
19831962               if (VDP1_LOG) logerror ("Sprite List Polygon\n");
19841963               stv2_current_sprite.ispoly = 1;
1985               stv_vpd1_draw_distorted_sprite(machine, *cliprect);
1964               stv_vdp1_draw_distorted_sprite(*cliprect);
19861965               break;
19871966
19881967            case 0x0005:
19891968//            case 0x0007: // mirror? Baroque uses it, crashes for whatever reason
19901969               if (VDP1_LOG) logerror ("Sprite List Polyline\n");
19911970               stv2_current_sprite.ispoly = 1;
1992               stv_vdp1_draw_poly_line(machine, *cliprect);
1971               stv_vdp1_draw_poly_line(*cliprect);
19931972               break;
19941973
19951974            case 0x0006:
19961975               if (VDP1_LOG) logerror ("Sprite List Line\n");
19971976               stv2_current_sprite.ispoly = 1;
1998               stv_vdp1_draw_line(machine, *cliprect);
1977               stv_vdp1_draw_line(*cliprect);
19991978               break;
20001979
20011980            case 0x0008:
20021981//            case 0x000b: // mirror? Bug 2
20031982               if (VDP1_LOG) logerror ("Sprite List Set Command for User Clipping (%d,%d),(%d,%d)\n", stv2_current_sprite.CMDXA, stv2_current_sprite.CMDYA, stv2_current_sprite.CMDXC, stv2_current_sprite.CMDYC);
2004               state->m_vdp1.user_cliprect.set(stv2_current_sprite.CMDXA, stv2_current_sprite.CMDXC, stv2_current_sprite.CMDYA, stv2_current_sprite.CMDYC);
1983               m_vdp1.user_cliprect.set(stv2_current_sprite.CMDXA, stv2_current_sprite.CMDXC, stv2_current_sprite.CMDYA, stv2_current_sprite.CMDYC);
20051984               break;
20061985
20071986            case 0x0009:
20081987               if (VDP1_LOG) logerror ("Sprite List Set Command for System Clipping (0,0),(%d,%d)\n", stv2_current_sprite.CMDXC, stv2_current_sprite.CMDYC);
2009               state->m_vdp1.system_cliprect.set(0, stv2_current_sprite.CMDXC, 0, stv2_current_sprite.CMDYC);
1988               m_vdp1.system_cliprect.set(0, stv2_current_sprite.CMDXC, 0, stv2_current_sprite.CMDYC);
20101989               break;
20111990
20121991            case 0x000a:
20131992               if (VDP1_LOG) logerror ("Sprite List Local Co-Ordinate Set (%d %d)\n",(INT16)stv2_current_sprite.CMDXA,(INT16)stv2_current_sprite.CMDYA);
2014               state->m_vdp1.local_x = (INT16)stv2_current_sprite.CMDXA;
2015               state->m_vdp1.local_y = (INT16)stv2_current_sprite.CMDYA;
1993               m_vdp1.local_x = (INT16)stv2_current_sprite.CMDXA;
1994               m_vdp1.local_y = (INT16)stv2_current_sprite.CMDYA;
20161995               break;
20171996
20181997            default:
20191998               popmessage ("VDP1: Sprite List Illegal %02x, contact MAMEdev",stv2_current_sprite.CMDCTRL & 0xf);
2020               state->m_vdp1.lopr = (position * 0x20) >> 3;
2021               state->m_vdp1.copr = (position * 0x20) >> 3;
1999               m_vdp1.lopr = (position * 0x20) >> 3;
2000               m_vdp1.copr = (position * 0x20) >> 3;
20222001               return;
20232002         }
20242003      }
r20790r20791
20312010   end:
20322011   /* set CEF to 1*/
20332012   CEF_1;
2034   state->m_vdp1.copr = (position * 0x20) >> 3;
2013   m_vdp1.copr = (position * 0x20) >> 3;
20352014
20362015   if (VDP1_LOG) logerror ("End of list processing!\n");
20372016}
20382017
2039void video_update_vdp1(running_machine &machine)
2018void saturn_state::video_update_vdp1( void )
20402019{
2041   saturn_state *state = machine.driver_data<saturn_state>();
20422020   int framebuffer_changed = 0;
20432021
20442022//  int enable;
r20790r20791
20572035//      }
20582036//  }
20592037   if (VDP1_LOG) logerror("video_update_vdp1 called\n");
2060   if (VDP1_LOG) logerror( "FBCR = %0x, accessed = %d\n", STV_VDP1_FBCR, state->m_vdp1.fbcr_accessed );
2038   if (VDP1_LOG) logerror( "FBCR = %0x, accessed = %d\n", STV_VDP1_FBCR, m_vdp1.fbcr_accessed );
20612039
20622040   if(STV_VDP1_CEF)
20632041      BEF_1;
20642042   else
20652043      BEF_0;
20662044
2067   if ( state->m_vdp1.framebuffer_clear_on_next_frame )
2045   if ( m_vdp1.framebuffer_clear_on_next_frame )
20682046   {
20692047      if ( ((STV_VDP1_FBCR & 0x3) == 3) &&
2070         state->m_vdp1.fbcr_accessed )
2048         m_vdp1.fbcr_accessed )
20712049      {
2072         stv_clear_framebuffer(machine, state->m_vdp1.framebuffer_current_display);
2073         state->m_vdp1.framebuffer_clear_on_next_frame = 0;
2050         stv_clear_framebuffer(m_vdp1.framebuffer_current_display);
2051         m_vdp1.framebuffer_clear_on_next_frame = 0;
20742052      }
20752053   }
20762054
20772055   switch( STV_VDP1_FBCR & 0x3 )
20782056   {
20792057      case 0: /* Automatic mode */
2080         stv_vdp1_change_framebuffers(machine);
2081         stv_clear_framebuffer(machine, state->m_vdp1.framebuffer_current_draw);
2058         stv_vdp1_change_framebuffers();
2059         stv_clear_framebuffer(m_vdp1.framebuffer_current_draw);
20822060         framebuffer_changed = 1;
20832061         break;
20842062      case 1: /* Setting prohibited */
20852063         break;
20862064      case 2: /* Manual mode - erase */
2087         if ( state->m_vdp1.fbcr_accessed )
2065         if ( m_vdp1.fbcr_accessed )
20882066         {
2089            state->m_vdp1.framebuffer_clear_on_next_frame = 1;
2067            m_vdp1.framebuffer_clear_on_next_frame = 1;
20902068         }
20912069         break;
20922070      case 3: /* Manual mode - change */
2093         if ( state->m_vdp1.fbcr_accessed )
2071         if ( m_vdp1.fbcr_accessed )
20942072         {
2095            stv_vdp1_change_framebuffers(machine);
2073            stv_vdp1_change_framebuffers();
20962074            if ( STV_VDP1_VBE )
20972075            {
2098               stv_clear_framebuffer(machine, state->m_vdp1.framebuffer_current_draw);
2076               stv_clear_framebuffer(m_vdp1.framebuffer_current_draw);
20992077            }
21002078            /* TODO: Slam n Jam 96 & Cross Romance doesn't like this, investigate. */
21012079//            framebuffer_changed = 1;
r20790r20791
21032081         framebuffer_changed = 1;
21042082         break;
21052083   }
2106   state->m_vdp1.fbcr_accessed = 0;
2084   m_vdp1.fbcr_accessed = 0;
21072085
21082086   if (VDP1_LOG) logerror( "PTM = %0x, TVM = %x\n", STV_VDP1_PTM, STV_VDP1_TVM );
21092087   switch(STV_VDP1_PTM & 3)
r20790r20791
21162094         if ( framebuffer_changed || VDP1_LOG )
21172095         {
21182096            /*set CEF to 1*/
2119            stv_vdp1_process_list(machine);
2097            stv_vdp1_process_list();
21202098         }
21212099         break;
21222100      case 3: /*<invalid>*/
r20790r20791
21262104   //popmessage("%04x %04x",STV_VDP1_EWRR_X3,STV_VDP1_EWRR_Y3);
21272105}
21282106
2129static void stv_vdp1_state_save_postload(running_machine &machine)
2107void saturn_state::stv_vdp1_state_save_postload( void )
21302108{
2131   saturn_state *state = machine.driver_data<saturn_state>();
2132   UINT8 *vdp1 = state->m_vdp1.gfx_decode;
2109   UINT8 *vdp1 = m_vdp1.gfx_decode;
21332110   int offset;
21342111   UINT32 data;
21352112
2136   state->m_vdp1.framebuffer_mode = -1;
2137   state->m_vdp1.framebuffer_double_interlace = -1;
2113   m_vdp1.framebuffer_mode = -1;
2114   m_vdp1.framebuffer_double_interlace = -1;
21382115
2139   stv_set_framebuffer_config(machine);
2116   stv_set_framebuffer_config();
21402117
21412118   for (offset = 0; offset < 0x80000/4; offset++ )
21422119   {
2143      data = state->m_vdp1_vram[offset];
2120      data = m_vdp1_vram[offset];
21442121      /* put in gfx region for easy decoding */
21452122      vdp1[offset*4+0] = (data & 0xff000000) >> 24;
21462123      vdp1[offset*4+1] = (data & 0x00ff0000) >> 16;
r20790r20791
21492126   }
21502127}
21512128
2152int stv_vdp1_start ( running_machine &machine )
2129int saturn_state::stv_vdp1_start ( void )
21532130{
2154   saturn_state *state = machine.driver_data<saturn_state>();
2155   state->m_vdp1_regs = auto_alloc_array_clear(machine, UINT16, 0x020/2 );
2156   state->m_vdp1_vram = auto_alloc_array_clear(machine, UINT32, 0x100000/4 );
2157   state->m_vdp1.gfx_decode = auto_alloc_array(machine, UINT8, 0x100000 );
2131   m_vdp1_regs = auto_alloc_array_clear(machine(), UINT16, 0x020/2 );
2132   m_vdp1_vram = auto_alloc_array_clear(machine(), UINT32, 0x100000/4 );
2133   m_vdp1.gfx_decode = auto_alloc_array(machine(), UINT8, 0x100000 );
21582134
2159   stv_vdp1_shading_data = auto_alloc(machine, struct stv_vdp1_poly_scanline_data);
2135   stv_vdp1_shading_data = auto_alloc(machine(), struct stv_vdp1_poly_scanline_data);
21602136
2161   state->m_vdp1.framebuffer[0] = auto_alloc_array(machine, UINT16, 1024 * 256 * 2 ); /* *2 is for double interlace */
2162   state->m_vdp1.framebuffer[1] = auto_alloc_array(machine, UINT16, 1024 * 256 * 2 );
2137   m_vdp1.framebuffer[0] = auto_alloc_array(machine(), UINT16, 1024 * 256 * 2 ); /* *2 is for double interlace */
2138   m_vdp1.framebuffer[1] = auto_alloc_array(machine(), UINT16, 1024 * 256 * 2 );
21632139
2164   state->m_vdp1.framebuffer_display_lines = auto_alloc_array(machine, UINT16 *, 512);
2165   state->m_vdp1.framebuffer_draw_lines = auto_alloc_array(machine, UINT16 *, 512);
2140   m_vdp1.framebuffer_display_lines = auto_alloc_array(machine(), UINT16 *, 512);
2141   m_vdp1.framebuffer_draw_lines = auto_alloc_array(machine(), UINT16 *, 512);
21662142
2167   state->m_vdp1.framebuffer_width = state->m_vdp1.framebuffer_height = 0;
2168   state->m_vdp1.framebuffer_mode = -1;
2169   state->m_vdp1.framebuffer_double_interlace = -1;
2170   state->m_vdp1.fbcr_accessed = 0;
2171   state->m_vdp1.framebuffer_current_display = 0;
2172   state->m_vdp1.framebuffer_current_draw = 1;
2173   stv_clear_framebuffer(machine, state->m_vdp1.framebuffer_current_draw);
2174   state->m_vdp1.framebuffer_clear_on_next_frame = 0;
2143   m_vdp1.framebuffer_width = m_vdp1.framebuffer_height = 0;
2144   m_vdp1.framebuffer_mode = -1;
2145   m_vdp1.framebuffer_double_interlace = -1;
2146   m_vdp1.fbcr_accessed = 0;
2147   m_vdp1.framebuffer_current_display = 0;
2148   m_vdp1.framebuffer_current_draw = 1;
2149   stv_clear_framebuffer(m_vdp1.framebuffer_current_draw);
2150   m_vdp1.framebuffer_clear_on_next_frame = 0;
21752151
2176   state->m_vdp1.system_cliprect.set(0, 0, 0, 0);
2152   m_vdp1.system_cliprect.set(0, 0, 0, 0);
21772153   /* Kidou Senshi Z Gundam - Zenpen Zeta no Kodou loves to use the user cliprect vars in an undefined state ... */
2178   state->m_vdp1.user_cliprect.set(0, 512, 0, 256);
2154   m_vdp1.user_cliprect.set(0, 512, 0, 256);
21792155
21802156   // save state
2181   state_save_register_global_pointer(machine, state->m_vdp1_regs, 0x020/2);
2182   state_save_register_global_pointer(machine, state->m_vdp1_vram, 0x100000/4);
2183   state_save_register_global(machine, state->m_vdp1.fbcr_accessed);
2184   state_save_register_global(machine, state->m_vdp1.framebuffer_current_display);
2185   state_save_register_global(machine, state->m_vdp1.framebuffer_current_draw);
2186   state_save_register_global(machine, state->m_vdp1.framebuffer_clear_on_next_frame);
2187   state_save_register_global(machine, state->m_vdp1.local_x);
2188   state_save_register_global(machine, state->m_vdp1.local_y);
2189   machine.save().register_postload(save_prepost_delegate(FUNC(stv_vdp1_state_save_postload), &machine));
2157   state_save_register_global_pointer(machine(), m_vdp1_regs, 0x020/2);
2158   state_save_register_global_pointer(machine(), m_vdp1_vram, 0x100000/4);
2159   state_save_register_global(machine(), m_vdp1.fbcr_accessed);
2160   state_save_register_global(machine(), m_vdp1.framebuffer_current_display);
2161   state_save_register_global(machine(), m_vdp1.framebuffer_current_draw);
2162   state_save_register_global(machine(), m_vdp1.framebuffer_clear_on_next_frame);
2163   state_save_register_global(machine(), m_vdp1.local_x);
2164   state_save_register_global(machine(), m_vdp1.local_y);
2165   machine().save().register_postload(save_prepost_delegate(FUNC(saturn_state::stv_vdp1_state_save_postload), this));
21902166   return 0;
21912167}
trunk/src/mame/video/stvvdp2.c
r20790r20791
104104#include "emu.h"
105105#include "includes/stv.h"
106106
107static UINT8 get_vblank(running_machine &machine);
108static UINT8 get_hblank(running_machine &machine);
109static int get_vblank_duration(running_machine &machine);
110static int get_hblank_duration(running_machine &machine);
111static int get_pixel_clock(running_machine &machine);
112static UINT8 get_odd_bit(running_machine &machine);
113
114static void refresh_palette_data(running_machine &machine);
115static int stv_vdp2_window_process(running_machine &machine,int x,int y);
116static int stv_vdp2_apply_window_on_layer(running_machine &machine,rectangle &cliprect);
117static void stv_vdp2_get_window0_coordinates(running_machine &machine,UINT16 *s_x, UINT16 *e_x, UINT16 *s_y, UINT16 *e_y);
118static void stv_vdp2_check_tilemap(running_machine &machine, bitmap_rgb32 &bitmap, const rectangle &cliprect);
119
120107enum
121108{
122109   STV_TRANSPARENCY_NONE,
r20790r20791
182169       | LSMD1    | LSMD0    | VRESO1   | VRESO0   |    --    | HRESO2   | HRESO1   | HRESO0   |
183170       \----------|----------|----------|----------|----------|----------|----------|---------*/
184171
185   #define STV_VDP2_TVMD   (state->m_vdp2_regs[0x000/2])
172   #define STV_VDP2_TVMD   (m_vdp2_regs[0x000/2])
186173
187174   #define STV_VDP2_DISP   ((STV_VDP2_TVMD & 0x8000) >> 15)
188175   #define STV_VDP2_BDCLMD ((STV_VDP2_TVMD & 0x0100) >> 8)
r20790r20791
197184       |    --    |    --    |    --    |    --    |    --    |    --    | DASEL    | EXBGEN   |
198185       \----------|----------|----------|----------|----------|----------|----------|---------*/
199186
200   #define STV_VDP2_EXTEN  (state->m_vdp2_regs[0x002/2])
187   #define STV_VDP2_EXTEN  (m_vdp2_regs[0x002/2])
201188
202189   #define STV_VDP2_EXLTEN ((STV_VDP2_EXTEN & 0x0200) >> 9)
203190
r20790r20791
215202       |    --    |    --    |    --    |    --    | VER3     | VER2     | VER1     | VER0     |
216203       \----------|----------|----------|----------|----------|----------|----------|---------*/
217204
218   #define STV_VDP2_VRSIZE (state->m_vdp2_regs[0x006/2])
205   #define STV_VDP2_VRSIZE (m_vdp2_regs[0x006/2])
219206
220207   #define STV_VDP2_VRAMSZ ((STV_VDP2_VRSIZE & 0x8000) >> 15)
221208
r20790r20791
226213       | HCT7     | HCT6     | HCT5     | HCT4     | HCT3     | HCT2     | HCT1     | HCT0     |
227214       \----------|----------|----------|----------|----------|----------|----------|---------*/
228215
229   #define STV_VDP2_HCNT (state->m_vdp2_regs[0x008/2])
216   #define STV_VDP2_HCNT (m_vdp2_regs[0x008/2])
230217
231218/* 18000A - r/o - VCNT - V-Counter
232219 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
235222       | VCT7     | VCT6     | VCT5     | VCT4     | VCT3     | VCT2     | VCT1     | VCT0     |
236223       \----------|----------|----------|----------|----------|----------|----------|---------*/
237224
238   #define STV_VDP2_VCNT (state->m_vdp2_regs[0x00a/2])
225   #define STV_VDP2_VCNT (m_vdp2_regs[0x00a/2])
239226
240227/* 18000C - RESERVED
241228 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
251238       | RDBSB11  | RDBSB10  | RDBSB01  | RDBSB00  | RDBSA11  | RDBSA10  | RDBSA01  | RDBSA00  |
252239       \----------|----------|----------|----------|----------|----------|----------|---------*/
253240
254   #define STV_VDP2_RAMCTL (state->m_vdp2_regs[0x00e/2])
241   #define STV_VDP2_RAMCTL (m_vdp2_regs[0x00e/2])
255242
256243   #define STV_VDP2_CRKTE ((STV_VDP2_RAMCTL & 0x8000) >> 15)
257244   #define STV_VDP2_CRMD  ((STV_VDP2_RAMCTL & 0x3000) >> 12)
r20790r20791
268255       | VCP2A03  | VCP2A02  | VCP2A01  | VCP2A00  | VCP3A03  | VCP3A02  | VCP3A01  | VCP3A00  |
269256       \----------|----------|----------|----------|----------|----------|----------|---------*/
270257
271   #define STV_VDP2_CYCA0L (state->m_vdp2_regs[0x010/2])
258   #define STV_VDP2_CYCA0L (m_vdp2_regs[0x010/2])
272259
273260/* 180012 - r/w - -CYCA0U - VRAM CYCLE PATTERN (BANK A0)
274261 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
277264       | VCP6A03  | VCP6A02  | VCP6A01  | VCP6A00  | VCP7A03  | VCP7A02  | VCP7A01  | VCP7A00  |
278265       \----------|----------|----------|----------|----------|----------|----------|---------*/
279266
280   #define STV_VDP2_CYCA0U (state->m_vdp2_regs[0x012/2])
267   #define STV_VDP2_CYCA0U (m_vdp2_regs[0x012/2])
281268
282269/* 180014 - r/w - -CYCA1L - VRAM CYCLE PATTERN (BANK A1)
283270 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
286273       | VCP2A13  | VCP2A12  | VCP2A11  | VCP2A10  | VCP3A13  | VCP3A12  | VCP3A11  | VCP3A10  |
287274       \----------|----------|----------|----------|----------|----------|----------|---------*/
288275
289   #define STV_VDP2_CYCA1L (state->m_vdp2_regs[0x014/2])
276   #define STV_VDP2_CYCA1L (m_vdp2_regs[0x014/2])
290277
291278/* 180016 - r/w - -CYCA1U - VRAM CYCLE PATTERN (BANK A1)
292279 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
295282       | VCP6A13  | VCP6A12  | VCP6A11  | VCP6A10  | VCP7A13  | VCP7A12  | VCP7A11  | VCP7A10  |
296283       \----------|----------|----------|----------|----------|----------|----------|---------*/
297284
298   #define STV_VDP2_CYCA1U (state->m_vdp2_regs[0x016/2])
285   #define STV_VDP2_CYCA1U (m_vdp2_regs[0x016/2])
299286
300287/* 180018 - r/w - -CYCB0L - VRAM CYCLE PATTERN (BANK B0)
301288 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
304291       | VCP2B03  | VCP2B02  | VCP2B01  | VCP2B00  | VCP3B03  | VCP3B02  | VCP3B01  | VCP3B00  |
305292       \----------|----------|----------|----------|----------|----------|----------|---------*/
306293
307   #define STV_VDP2_CYCA2L (state->m_vdp2_regs[0x018/2])
294   #define STV_VDP2_CYCA2L (m_vdp2_regs[0x018/2])
308295
309296/* 18001A - r/w - -CYCB0U - VRAM CYCLE PATTERN (BANK B0)
310297 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
313300       | VCP6B03  | VCP6B02  | VCP6B01  | VCP6B00  | VCP7B03  | VCP7B02  | VCP7B01  | VCP7B00  |
314301       \----------|----------|----------|----------|----------|----------|----------|---------*/
315302
316   #define STV_VDP2_CYCA2U (state->m_vdp2_regs[0x01a/2])
303   #define STV_VDP2_CYCA2U (m_vdp2_regs[0x01a/2])
317304
318305/* 18001C - r/w - -CYCB1L - VRAM CYCLE PATTERN (BANK B1)
319306 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
322309       | VCP2B13  | VCP2B12  | VCP2B11  | VCP2B10  | VCP3B13  | VCP3B12  | VCP3B11  | VCP3B10  |
323310       \----------|----------|----------|----------|----------|----------|----------|---------*/
324311
325   #define STV_VDP2_CYCA3L (state->m_vdp2_regs[0x01c/2])
312   #define STV_VDP2_CYCA3L (m_vdp2_regs[0x01c/2])
326313
327314/* 18001E - r/w - -CYCB1U - VRAM CYCLE PATTERN (BANK B1)
328315 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
331318       | VCP6B13  | VCP6B12  | VCP6B11  | VCP6B10  | VCP7B13  | VCP7B12  | VCP7B11  | VCP7B10  |
332319       \----------|----------|----------|----------|----------|----------|----------|---------*/
333320
334   #define STV_VDP2_CYCA3U (state->m_vdp2_regs[0x01e/2])
321   #define STV_VDP2_CYCA3U (m_vdp2_regs[0x01e/2])
335322
336323/* 180020 - r/w - BGON - SCREEN DISPLAY ENABLE
337324
r20790r20791
343330       |    --    |    --    | R1ON     | R0ON     | N3ON     | N2ON     | N1ON     | N0ON     |
344331       \----------|----------|----------|----------|----------|----------|----------|---------*/
345332
346   #define STV_VDP2_BGON (state->m_vdp2_regs[0x020/2])
333   #define STV_VDP2_BGON (m_vdp2_regs[0x020/2])
347334
348335   // NxOn - Layer Enable Register
349336   #define STV_VDP2_xxON ((STV_VDP2_BGON & 0x001f) >> 0) /* to see if anything is enabled */
r20790r20791
370357       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
371358       \----------|----------|----------|----------|----------|----------|----------|---------*/
372359
373   #define STV_VDP2_MZCTL (state->m_vdp2_regs[0x022/2])
360   #define STV_VDP2_MZCTL (m_vdp2_regs[0x022/2])
374361
375362   #define STV_VDP2_MZSZV ((STV_VDP2_MZCTL & 0xf000) >> 12)
376363   #define STV_VDP2_MZSZH ((STV_VDP2_MZCTL & 0x0f00) >> 8)
r20790r20791
384371
385372*/
386373
387   #define STV_VDP2_SFSEL (state->m_vdp2_regs[0x024/2])
374   #define STV_VDP2_SFSEL (m_vdp2_regs[0x024/2])
388375
389376/*180026 - Special Function Code
390377
391378*/
392379
393   #define STV_VDP2_SFCODE (state->m_vdp2_regs[0x026/2])
380   #define STV_VDP2_SFCODE (m_vdp2_regs[0x026/2])
394381
395382
396383/*
r20790r20791
401388       |    --    | N0CHCN2  | N0CHCN1  | N0CHCN0  | N0BMSZ1  | N0BMSZ0  | N0BMEN   | N0CHSZ   |
402389       \----------|----------|----------|----------|----------|----------|----------|---------*/
403390
404   #define STV_VDP2_CHCTLA (state->m_vdp2_regs[0x028/2])
391   #define STV_VDP2_CHCTLA (m_vdp2_regs[0x028/2])
405392
406393/* -------------------------- NBG0 Character Control Registers -------------------------- */
407394
r20790r20791
467454       |    --    |    --    | N3CHCN   | N3CHSZ   |    --    |    --    | N2CHCN   | N2CHSZ   |
468455       \----------|----------|----------|----------|----------|----------|----------|---------*/
469456
470   #define STV_VDP2_CHCTLB (state->m_vdp2_regs[0x02a/2])
457   #define STV_VDP2_CHCTLB (m_vdp2_regs[0x02a/2])
471458
472459/* -------------------------- RBG0 Character Control Registers -------------------------- */
473460
r20790r20791
512499       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
513500       \----------|----------|----------|----------|----------|----------|----------|---------*/
514501
515   #define STV_VDP2_BMPNA (state->m_vdp2_regs[0x02c/2])
502   #define STV_VDP2_BMPNA (m_vdp2_regs[0x02c/2])
516503
517504   #define STV_VDP2_N1BMP ((STV_VDP2_BMPNA & 0x0700) >> 8)
518505   #define STV_VDP2_N0BMP ((STV_VDP2_BMPNA & 0x0007) >> 0)
r20790r20791
524511       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
525512       \----------|----------|----------|----------|----------|----------|----------|---------*/
526513
527   #define STV_VDP2_BMPNB (state->m_vdp2_regs[0x02e/2])
514   #define STV_VDP2_BMPNB (m_vdp2_regs[0x02e/2])
528515
529516   #define STV_VDP2_R0BMP ((STV_VDP2_BMPNB & 0x0007) >> 0)
530517
r20790r20791
535522       | N0SPLT6  | N0SPLT5  | N0SPLT4  | N0SPCN4  | N0SPCN3  | N0SPCN2  | N0SPCN1  | N0SPCN0  |
536523       \----------|----------|----------|----------|----------|----------|----------|---------*/
537524
538   #define STV_VDP2_PNCN0 (state->m_vdp2_regs[0x030/2])
525   #define STV_VDP2_PNCN0 (m_vdp2_regs[0x030/2])
539526
540527/*  Pattern Data Size
541528    0 = 2 bytes
r20790r20791
566553       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
567554       \----------|----------|----------|----------|----------|----------|----------|---------*/
568555
569   #define STV_VDP2_PNCN1 (state->m_vdp2_regs[0x032/2])
556   #define STV_VDP2_PNCN1 (m_vdp2_regs[0x032/2])
570557
571558/*  Pattern Data Size
572559    0 = 2 bytes
r20790r20791
598585       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
599586       \----------|----------|----------|----------|----------|----------|----------|---------*/
600587
601   #define STV_VDP2_PNCN2 (state->m_vdp2_regs[0x034/2])
588   #define STV_VDP2_PNCN2 (m_vdp2_regs[0x034/2])
602589
603590/*  Pattern Data Size
604591    0 = 2 bytes
r20790r20791
630617       | N3SPLT6  | N3SPLT5  | N3SPLT4  | N3SPCN4  | N3SPCN3  | N3SPCN2  | N3SPCN1  | N3SPCN0  |
631618       \----------|----------|----------|----------|----------|----------|----------|---------*/
632619
633   #define STV_VDP2_PNCN3 (state->m_vdp2_regs[0x036/2])
620   #define STV_VDP2_PNCN3 (m_vdp2_regs[0x036/2])
634621
635622/*  Pattern Data Size
636623    0 = 2 bytes
r20790r20791
662649       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
663650       \----------|----------|----------|----------|----------|----------|----------|---------*/
664651
665   #define STV_VDP2_PNCR (state->m_vdp2_regs[0x038/2])
652   #define STV_VDP2_PNCR (m_vdp2_regs[0x038/2])
666653
667654/*  Pattern Data Size
668655    0 = 2 bytes
r20790r20791
693680       | N3PLSZ1  | N3PLSZ0  |    --    |    --    | N1PLSZ1  | N1PLSZ0  | N0PLSZ1  | N0PLSZ0  |
694681       \----------|----------|----------|----------|----------|----------|----------|---------*/
695682
696   #define STV_VDP2_PLSZ (state->m_vdp2_regs[0x03a/2])
683   #define STV_VDP2_PLSZ (m_vdp2_regs[0x03a/2])
697684
698685   /* NBG0 Plane Size
699686   00 1H Page x 1V Page
r20790r20791
716703       |    --    | N1MP8    | N1MP7    | N1MP6    |    --    | N0MP8    | N0MP7    | N0MP6    |
717704       \----------|----------|----------|----------|----------|----------|----------|---------*/
718705
719   #define STV_VDP2_MPOFN_ (state->m_vdp2_regs[0x03c/2])
706   #define STV_VDP2_MPOFN_ (m_vdp2_regs[0x03c/2])
720707
721708   /* Higher 3 bits of the map offset for each layer */
722709   #define STV_VDP2_N3MP_ ((STV_VDP2_MPOFN_ & 0x3000) >> 12)
r20790r20791
734721       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
735722       \----------|----------|----------|----------|----------|----------|----------|---------*/
736723
737   #define STV_VDP2_MPOFR_ (state->m_vdp2_regs[0x03e/2])
724   #define STV_VDP2_MPOFR_ (m_vdp2_regs[0x03e/2])
738725
739726   #define STV_VDP2_RBMP_ ((STV_VDP2_MPOFR_ & 0x0030) >> 4)
740727   #define STV_VDP2_RAMP_ ((STV_VDP2_MPOFR_ & 0x0003) >> 0)
r20790r20791
746733       |    --    |    --    | N0MPA5   | N0MPA4   | N0MPA3   | N0MPA2   | N0MPA1   | N0MPA0   |
747734       \----------|----------|----------|----------|----------|----------|----------|---------*/
748735
749   #define STV_VDP2_MPABN0 (state->m_vdp2_regs[0x040/2])
736   #define STV_VDP2_MPABN0 (m_vdp2_regs[0x040/2])
750737
751738   /* N0MPB5 = lower 6 bits of Map Address of Plane B of Tilemap NBG0 */
752739   #define STV_VDP2_N0MPB ((STV_VDP2_MPABN0 & 0x3f00) >> 8)
r20790r20791
762749       |    --    |    --    | N0MPC5   | N0MPC4   | N0MPC3   | N0MPC2   | N0MPC1   | N0MPC0   |
763750       \----------|----------|----------|----------|----------|----------|----------|---------*/
764751
765   #define STV_VDP2_MPCDN0 (state->m_vdp2_regs[0x042/2])
752   #define STV_VDP2_MPCDN0 (m_vdp2_regs[0x042/2])
766753
767754   /* N0MPB5 = lower 6 bits of Map Address of Plane D of Tilemap NBG0 */
768755   #define STV_VDP2_N0MPD ((STV_VDP2_MPCDN0 & 0x3f00) >> 8)
r20790r20791
778765       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
779766       \----------|----------|----------|----------|----------|----------|----------|---------*/
780767
781   #define STV_VDP2_MPABN1 (state->m_vdp2_regs[0x044/2])
768   #define STV_VDP2_MPABN1 (m_vdp2_regs[0x044/2])
782769
783770   /* N0MPB5 = lower 6 bits of Map Address of Plane B of Tilemap NBG1 */
784771   #define STV_VDP2_N1MPB ((STV_VDP2_MPABN1 & 0x3f00) >> 8)
r20790r20791
793780       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
794781       \----------|----------|----------|----------|----------|----------|----------|---------*/
795782
796   #define STV_VDP2_MPCDN1 (state->m_vdp2_regs[0x046/2])
783   #define STV_VDP2_MPCDN1 (m_vdp2_regs[0x046/2])
797784
798785   /* N0MPB5 = lower 6 bits of Map Address of Plane D of Tilemap NBG0 */
799786   #define STV_VDP2_N1MPD ((STV_VDP2_MPCDN1 & 0x3f00) >> 8)
r20790r20791
809796       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
810797       \----------|----------|----------|----------|----------|----------|----------|---------*/
811798
812   #define STV_VDP2_MPABN2 (state->m_vdp2_regs[0x048/2])
799   #define STV_VDP2_MPABN2 (m_vdp2_regs[0x048/2])
813800
814801   /* N0MPB5 = lower 6 bits of Map Address of Plane B of Tilemap NBG2 */
815802   #define STV_VDP2_N2MPB ((STV_VDP2_MPABN2 & 0x3f00) >> 8)
r20790r20791
824811       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
825812       \----------|----------|----------|----------|----------|----------|----------|---------*/
826813
827   #define STV_VDP2_MPCDN2 (state->m_vdp2_regs[0x04a/2])
814   #define STV_VDP2_MPCDN2 (m_vdp2_regs[0x04a/2])
828815
829816   /* N0MPB5 = lower 6 bits of Map Address of Plane D of Tilemap NBG2 */
830817   #define STV_VDP2_N2MPD ((STV_VDP2_MPCDN2 & 0x3f00) >> 8)
r20790r20791
839826       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
840827       \----------|----------|----------|----------|----------|----------|----------|---------*/
841828
842   #define STV_VDP2_MPABN3 (state->m_vdp2_regs[0x04c/2])
829   #define STV_VDP2_MPABN3 (m_vdp2_regs[0x04c/2])
843830
844831   /* N0MPB5 = lower 6 bits of Map Address of Plane B of Tilemap NBG1 */
845832   #define STV_VDP2_N3MPB ((STV_VDP2_MPABN3 & 0x3f00) >> 8)
r20790r20791
855842       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
856843       \----------|----------|----------|----------|----------|----------|----------|---------*/
857844
858   #define STV_VDP2_MPCDN3 (state->m_vdp2_regs[0x04e/2])
845   #define STV_VDP2_MPCDN3 (m_vdp2_regs[0x04e/2])
859846
860847   /* N0MPB5 = lower 6 bits of Map Address of Plane B of Tilemap NBG0 */
861848   #define STV_VDP2_N3MPD ((STV_VDP2_MPCDN3 & 0x3f00) >> 8)
r20790r20791
870857       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
871858       \----------|----------|----------|----------|----------|----------|----------|---------*/
872859
873   #define STV_VDP2_MPABRA (state->m_vdp2_regs[0x050/2])
860   #define STV_VDP2_MPABRA (m_vdp2_regs[0x050/2])
874861
875862   /* R0MPB5 = lower 6 bits of Map Address of Plane B of Tilemap RBG0 */
876863   #define STV_VDP2_RAMPB ((STV_VDP2_MPABRA & 0x3f00) >> 8)
r20790r20791
886873       |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
887874       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
888875       \----------|----------|----------|----------|----------|----------|----------|---------*/
889   #define STV_VDP2_MPCDRA (state->m_vdp2_regs[0x052/2])
876   #define STV_VDP2_MPCDRA (m_vdp2_regs[0x052/2])
890877
891878   /* R0MPB5 = lower 6 bits of Map Address of Plane D of Tilemap RBG0 */
892879   #define STV_VDP2_RAMPD ((STV_VDP2_MPCDRA & 0x3f00) >> 8)
r20790r20791
900887       |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
901888       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
902889       \----------|----------|----------|----------|----------|----------|----------|---------*/
903   #define STV_VDP2_MPEFRA (state->m_vdp2_regs[0x054/2])
890   #define STV_VDP2_MPEFRA (m_vdp2_regs[0x054/2])
904891
905892   /* R0MPB5 = lower 6 bits of Map Address of Plane F of Tilemap RBG0 */
906893   #define STV_VDP2_RAMPF ((STV_VDP2_MPEFRA & 0x3f00) >> 8)
r20790r20791
914901       |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
915902       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
916903       \----------|----------|----------|----------|----------|----------|----------|---------*/
917   #define STV_VDP2_MPGHRA (state->m_vdp2_regs[0x056/2])
904   #define STV_VDP2_MPGHRA (m_vdp2_regs[0x056/2])
918905
919906   /* R0MPB5 = lower 6 bits of Map Address of Plane H of Tilemap RBG0 */
920907   #define STV_VDP2_RAMPH ((STV_VDP2_MPGHRA & 0x3f00) >> 8)
r20790r20791
928915       |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
929916       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
930917       \----------|----------|----------|----------|----------|----------|----------|---------*/
931   #define STV_VDP2_MPIJRA (state->m_vdp2_regs[0x058/2])
918   #define STV_VDP2_MPIJRA (m_vdp2_regs[0x058/2])
932919
933920   /* R0MPB5 = lower 6 bits of Map Address of Plane J of Tilemap RBG0 */
934921   #define STV_VDP2_RAMPJ ((STV_VDP2_MPIJRA & 0x3f00) >> 8)
r20790r20791
942929       |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
943930       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
944931       \----------|----------|----------|----------|----------|----------|----------|---------*/
945   #define STV_VDP2_MPKLRA (state->m_vdp2_regs[0x05a/2])
932   #define STV_VDP2_MPKLRA (m_vdp2_regs[0x05a/2])
946933
947934   /* R0MPB5 = lower 6 bits of Map Address of Plane L of Tilemap RBG0 */
948935   #define STV_VDP2_RAMPL ((STV_VDP2_MPKLRA & 0x3f00) >> 8)
r20790r20791
956943       |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
957944       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
958945       \----------|----------|----------|----------|----------|----------|----------|---------*/
959   #define STV_VDP2_MPMNRA (state->m_vdp2_regs[0x05c/2])
946   #define STV_VDP2_MPMNRA (m_vdp2_regs[0x05c/2])
960947
961948   /* R0MPB5 = lower 6 bits of Map Address of Plane N of Tilemap RBG0 */
962949   #define STV_VDP2_RAMPN ((STV_VDP2_MPMNRA & 0x3f00) >> 8)
r20790r20791
970957       |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
971958       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
972959       \----------|----------|----------|----------|----------|----------|----------|---------*/
973   #define STV_VDP2_MPOPRA (state->m_vdp2_regs[0x05e/2])
960   #define STV_VDP2_MPOPRA (m_vdp2_regs[0x05e/2])
974961
975962   /* R0MPB5 = lower 6 bits of Map Address of Plane P of Tilemap RBG0 */
976963   #define STV_VDP2_RAMPP ((STV_VDP2_MPOPRA & 0x3f00) >> 8)
r20790r20791
985972       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
986973       \----------|----------|----------|----------|----------|----------|----------|---------*/
987974
988   #define STV_VDP2_MPABRB (state->m_vdp2_regs[0x060/2])
975   #define STV_VDP2_MPABRB (m_vdp2_regs[0x060/2])
989976
990977   /* R0MPB5 = lower 6 bits of Map Address of Plane B of Tilemap RBG0 */
991978   #define STV_VDP2_RBMPB ((STV_VDP2_MPABRB & 0x3f00) >> 8)
r20790r20791
1001988       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
1002989       \----------|----------|----------|----------|----------|----------|----------|---------*/
1003990
1004   #define STV_VDP2_MPCDRB (state->m_vdp2_regs[0x062/2])
991   #define STV_VDP2_MPCDRB (m_vdp2_regs[0x062/2])
1005992
1006993   /* R0MPD5 = lower 6 bits of Map Address of Plane D of Tilemap RBG0 */
1007994   #define STV_VDP2_RBMPD ((STV_VDP2_MPCDRB & 0x3f00) >> 8)
r20790r20791
10161003       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
10171004       \----------|----------|----------|----------|----------|----------|----------|---------*/
10181005
1019   #define STV_VDP2_MPEFRB (state->m_vdp2_regs[0x064/2])
1006   #define STV_VDP2_MPEFRB (m_vdp2_regs[0x064/2])
10201007
10211008   /* R0MPF5 = lower 6 bits of Map Address of Plane F of Tilemap RBG0 */
10221009   #define STV_VDP2_RBMPF ((STV_VDP2_MPEFRB & 0x3f00) >> 8)
r20790r20791
10311018       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
10321019       \----------|----------|----------|----------|----------|----------|----------|---------*/
10331020
1034   #define STV_VDP2_MPGHRB (state->m_vdp2_regs[0x066/2])
1021   #define STV_VDP2_MPGHRB (m_vdp2_regs[0x066/2])
10351022
10361023   /* R0MPH5 = lower 6 bits of Map Address of Plane H of Tilemap RBG0 */
10371024   #define STV_VDP2_RBMPH ((STV_VDP2_MPGHRB & 0x3f00) >> 8)
r20790r20791
10461033       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
10471034       \----------|----------|----------|----------|----------|----------|----------|---------*/
10481035
1049   #define STV_VDP2_MPIJRB (state->m_vdp2_regs[0x068/2])
1036   #define STV_VDP2_MPIJRB (m_vdp2_regs[0x068/2])
10501037
10511038   /* R0MPJ5 = lower 6 bits of Map Address of Plane J of Tilemap RBG0 */
10521039   #define STV_VDP2_RBMPJ ((STV_VDP2_MPIJRB & 0x3f00) >> 8)
r20790r20791
10611048       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
10621049       \----------|----------|----------|----------|----------|----------|----------|---------*/
10631050
1064   #define STV_VDP2_MPKLRB (state->m_vdp2_regs[0x06a/2])
1051   #define STV_VDP2_MPKLRB (m_vdp2_regs[0x06a/2])
10651052
10661053   /* R0MPL5 = lower 6 bits of Map Address of Plane L of Tilemap RBG0 */
10671054   #define STV_VDP2_RBMPL ((STV_VDP2_MPKLRB & 0x3f00) >> 8)
r20790r20791
10761063       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
10771064       \----------|----------|----------|----------|----------|----------|----------|---------*/
10781065
1079   #define STV_VDP2_MPMNRB (state->m_vdp2_regs[0x06c/2])
1066   #define STV_VDP2_MPMNRB (m_vdp2_regs[0x06c/2])
10801067
10811068   /* R0MPN5 = lower 6 bits of Map Address of Plane N of Tilemap RBG0 */
10821069   #define STV_VDP2_RBMPN ((STV_VDP2_MPMNRB & 0x3f00) >> 8)
r20790r20791
10911078       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
10921079       \----------|----------|----------|----------|----------|----------|----------|---------*/
10931080
1094   #define STV_VDP2_MPOPRB (state->m_vdp2_regs[0x06e/2])
1081   #define STV_VDP2_MPOPRB (m_vdp2_regs[0x06e/2])
10951082
10961083   /* R0MPP5 = lower 6 bits of Map Address of Plane P of Tilemap RBG0 */
10971084   #define STV_VDP2_RBMPP ((STV_VDP2_MPOPRB & 0x3f00) >> 8)
r20790r20791
11061093       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
11071094       \----------|----------|----------|----------|----------|----------|----------|---------*/
11081095
1109   #define STV_VDP2_SCXIN0 (state->m_vdp2_regs[0x070/2])
1096   #define STV_VDP2_SCXIN0 (m_vdp2_regs[0x070/2])
11101097
11111098
11121099/* 180072 - Screen Scroll (NBG0, Horizontal Fractional Part)
r20790r20791
11221109       |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
11231110       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
11241111       \----------|----------|----------|----------|----------|----------|----------|---------*/
1125   #define STV_VDP2_SCYIN0 (state->m_vdp2_regs[0x074/2])
1112   #define STV_VDP2_SCYIN0 (m_vdp2_regs[0x074/2])
11261113
11271114
11281115/* 180076 - Screen Scroll (NBG0, Vertical Fractional Part)
r20790r20791
11391126       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
11401127       \----------|----------|----------|----------|----------|----------|----------|---------*/
11411128
1142   #define STV_VDP2_ZMXIN0 (state->m_vdp2_regs[0x078/2])
1129   #define STV_VDP2_ZMXIN0 (m_vdp2_regs[0x078/2])
11431130
11441131   #define STV_VDP2_N0ZMXI ((STV_VDP2_ZMXIN0 & 0x0007) >> 0)
11451132
r20790r20791
11501137       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
11511138       \----------|----------|----------|----------|----------|----------|----------|---------*/
11521139
1153   #define STV_VDP2_ZMXDN0 (state->m_vdp2_regs[0x07a/2])
1140   #define STV_VDP2_ZMXDN0 (m_vdp2_regs[0x07a/2])
11541141
11551142   #define STV_VDP2_N0ZMXD ((STV_VDP2_ZMXDN0 >> 8)& 0xff)
11561143   #define STV_VDP2_ZMXN0  (((STV_VDP2_N0ZMXI<<16) | (STV_VDP2_N0ZMXD<<8))  & 0x0007ff00)
r20790r20791
11631150       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
11641151       \----------|----------|----------|----------|----------|----------|----------|---------*/
11651152
1166   #define STV_VDP2_ZMYIN0 (state->m_vdp2_regs[0x07c/2])
1153   #define STV_VDP2_ZMYIN0 (m_vdp2_regs[0x07c/2])
11671154
11681155   #define STV_VDP2_N0ZMYI ((STV_VDP2_ZMYIN0 & 0x0007) >> 0)
11691156
r20790r20791
11741161       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
11751162       \----------|----------|----------|----------|----------|----------|----------|---------*/
11761163
1177   #define STV_VDP2_ZMYDN0 (state->m_vdp2_regs[0x07e/2])
1164   #define STV_VDP2_ZMYDN0 (m_vdp2_regs[0x07e/2])
11781165
11791166   #define STV_VDP2_N0ZMYD ((STV_VDP2_ZMYDN0 >> 8)& 0xff)
11801167   #define STV_VDP2_ZMYN0  (((STV_VDP2_N0ZMYI<<16) | (STV_VDP2_N0ZMYD<<8))  & 0x0007ff00)
r20790r20791
11861173       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
11871174       \----------|----------|----------|----------|----------|----------|----------|---------*/
11881175
1189   #define STV_VDP2_SCXIN1 (state->m_vdp2_regs[0x080/2])
1176   #define STV_VDP2_SCXIN1 (m_vdp2_regs[0x080/2])
11901177
11911178/* 180082 - Screen Scroll (NBG1, Horizontal Fractional Part)
11921179 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
12021189       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
12031190       \----------|----------|----------|----------|----------|----------|----------|---------*/
12041191
1205   #define STV_VDP2_SCYIN1 (state->m_vdp2_regs[0x084/2])
1192   #define STV_VDP2_SCYIN1 (m_vdp2_regs[0x084/2])
12061193
12071194/* 180086 - Screen Scroll (NBG1, Vertical Fractional Part)
12081195 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
12181205       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
12191206       \----------|----------|----------|----------|----------|----------|----------|---------*/
12201207
1221   #define STV_VDP2_ZMXIN1 (state->m_vdp2_regs[0x088/2])
1208   #define STV_VDP2_ZMXIN1 (m_vdp2_regs[0x088/2])
12221209
12231210   #define STV_VDP2_N1ZMXI ((STV_VDP2_ZMXIN1 & 0x0007) >> 0)
12241211
r20790r20791
12291216       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
12301217       \----------|----------|----------|----------|----------|----------|----------|---------*/
12311218
1232   #define STV_VDP2_ZMXDN1 (state->m_vdp2_regs[0x08a/2])
1219   #define STV_VDP2_ZMXDN1 (m_vdp2_regs[0x08a/2])
12331220
12341221   #define STV_VDP2_N1ZMXD ((STV_VDP2_ZMXDN1 >> 8)& 0xff)
12351222   #define STV_VDP2_ZMXN1  (((STV_VDP2_N1ZMXI<<16) | (STV_VDP2_N1ZMXD<<8)) & 0x0007ff00)
r20790r20791
12411228       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
12421229       \----------|----------|----------|----------|----------|----------|----------|---------*/
12431230
1244   #define STV_VDP2_ZMYIN1 (state->m_vdp2_regs[0x08c/2])
1231   #define STV_VDP2_ZMYIN1 (m_vdp2_regs[0x08c/2])
12451232
12461233   #define STV_VDP2_N1ZMYI ((STV_VDP2_ZMYIN1 & 0x0007) >> 0)
12471234
r20790r20791
12521239       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
12531240       \----------|----------|----------|----------|----------|----------|----------|---------*/
12541241
1255   #define STV_VDP2_ZMYDN1 (state->m_vdp2_regs[0x08e/2])
1242   #define STV_VDP2_ZMYDN1 (m_vdp2_regs[0x08e/2])
12561243
12571244   #define STV_VDP2_N1ZMYD ((STV_VDP2_ZMYDN1 >> 8)& 0xff)
12581245   #define STV_VDP2_ZMYN1  (((STV_VDP2_N1ZMYI<<16) | (STV_VDP2_N1ZMYD<<8)) & 0x007ff00)
r20790r20791
12641251       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
12651252       \----------|----------|----------|----------|----------|----------|----------|---------*/
12661253
1267   #define STV_VDP2_SCXN2 (state->m_vdp2_regs[0x090/2])
1254   #define STV_VDP2_SCXN2 (m_vdp2_regs[0x090/2])
12681255
12691256/* 180092 - SCYN2 - Screen Scroll (NBG2, Vertical)
12701257 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
12731260       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
12741261       \----------|----------|----------|----------|----------|----------|----------|---------*/
12751262
1276   #define STV_VDP2_SCYN2 (state->m_vdp2_regs[0x092/2])
1263   #define STV_VDP2_SCYN2 (m_vdp2_regs[0x092/2])
12771264
12781265/* 180094 - SCXN3 - Screen Scroll (NBG3, Horizontal)
12791266 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
12821269       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
12831270       \----------|----------|----------|----------|----------|----------|----------|---------*/
12841271
1285   #define STV_VDP2_SCXN3 (state->m_vdp2_regs[0x094/2])
1272   #define STV_VDP2_SCXN3 (m_vdp2_regs[0x094/2])
12861273
12871274/* 180096 - SCYN3 - Screen Scroll (NBG3, Vertical)
12881275 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
12911278       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
12921279       \----------|----------|----------|----------|----------|----------|----------|---------*/
12931280
1294   #define STV_VDP2_SCYN3 (state->m_vdp2_regs[0x096/2])
1281   #define STV_VDP2_SCYN3 (m_vdp2_regs[0x096/2])
12951282
12961283/* 180098 - Reduction Enable
12971284 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
13001287       |    --    |    --    |    --    |    --    |    --    |    --    | N0ZMQT   | N0ZMHF   |
13011288       \----------|----------|----------|----------|----------|----------|----------|---------*/
13021289
1303   #define STV_VDP2_ZMCTL (state->m_vdp2_regs[0x098/2])
1290   #define STV_VDP2_ZMCTL (m_vdp2_regs[0x098/2])
13041291
13051292   #define STV_VDP2_N1ZMQT  ((STV_VDP2_ZMCTL & 0x0200) >> 9)
13061293   #define STV_VDP2_N1ZMHF  ((STV_VDP2_ZMCTL & 0x0100) >> 8)
r20790r20791
13141301       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
13151302       \----------|----------|----------|----------|----------|----------|----------|---------*/
13161303
1317   #define STV_VDP2_SCRCTL (state->m_vdp2_regs[0x09a/2])
1304   #define STV_VDP2_SCRCTL (m_vdp2_regs[0x09a/2])
13181305
13191306   #define STV_VDP2_N1LSS  ((STV_VDP2_SCRCTL & 0x3000) >> 12)
13201307   #define STV_VDP2_N1LZMX ((STV_VDP2_SCRCTL & 0x0800) >> 11)
r20790r20791
13341321       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
13351322       \----------|----------|----------|----------|----------|----------|----------|---------*/
13361323
1337   #define STV_VDP2_VCSTAU (state->m_vdp2_regs[0x09c/2] & 7)
1324   #define STV_VDP2_VCSTAU (m_vdp2_regs[0x09c/2] & 7)
13381325
13391326
13401327/* 18009e - Vertical Cell Table Address (NBG0, NBG1)
r20790r20791
13441331       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
13451332       \----------|----------|----------|----------|----------|----------|----------|---------*/
13461333
1347   #define STV_VDP2_VCSTAL (state->m_vdp2_regs[0x09e/2])
1334   #define STV_VDP2_VCSTAL (m_vdp2_regs[0x09e/2])
13481335
13491336
13501337/* 1800a0 - LSTA0U - Line Scroll Table Address (NBG0)
r20790r20791
13551342       \----------|----------|----------|----------|----------|----------|----------|---------*/
13561343
13571344   /*bit 2 unused when VRAM = 4 Mbits*/
1358   #define STV_VDP2_LSTA0U (state->m_vdp2_regs[0x0a0/2] & 7)
1345   #define STV_VDP2_LSTA0U (m_vdp2_regs[0x0a0/2] & 7)
13591346
13601347/* 1800a2 - LSTA0L - Line Scroll Table Address (NBG0)
13611348 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
13641351       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
13651352       \----------|----------|----------|----------|----------|----------|----------|---------*/
13661353
1367   #define STV_VDP2_LSTA0L (state->m_vdp2_regs[0x0a2/2])
1354   #define STV_VDP2_LSTA0L (m_vdp2_regs[0x0a2/2])
13681355
13691356/* 1800a4 - LSTA1U - Line Scroll Table Address (NBG1)
13701357 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
13741361       \----------|----------|----------|----------|----------|----------|----------|---------*/
13751362
13761363   /*bit 2 unused when VRAM = 4 Mbits*/
1377   #define STV_VDP2_LSTA1U (state->m_vdp2_regs[0x0a4/2] & 7)
1364   #define STV_VDP2_LSTA1U (m_vdp2_regs[0x0a4/2] & 7)
13781365
13791366/* 1800a6 - LSTA1L - Line Scroll Table Address (NBG1)
13801367 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
13831370       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
13841371       \----------|----------|----------|----------|----------|----------|----------|---------*/
13851372
1386   #define STV_VDP2_LSTA1L (state->m_vdp2_regs[0x0a6/2])
1373   #define STV_VDP2_LSTA1L (m_vdp2_regs[0x0a6/2])
13871374
13881375/* 1800a8 - LCTAU - Line Colour Screen Table Address
13891376 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
13921379       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
13931380       \----------|----------|----------|----------|----------|----------|----------|---------*/
13941381
1395   #define STV_VDP2_LCTAU  (state->m_vdp2_regs[0x0a8/2])
1382   #define STV_VDP2_LCTAU  (m_vdp2_regs[0x0a8/2])
13961383   #define STV_VDP2_LCCLMD ((STV_VDP2_LCTAU & 0x8000) >> 15)
13971384
13981385/* 1800aa - LCTAL - Line Colour Screen Table Address
r20790r20791
14011388       |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
14021389       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
14031390       \----------|----------|----------|----------|----------|----------|----------|---------*/
1404   #define STV_VDP2_LCTAL  (state->m_vdp2_regs[0x0aa/2])
1391   #define STV_VDP2_LCTAL  (m_vdp2_regs[0x0aa/2])
14051392
14061393   #define STV_VDP2_LCTA   (((STV_VDP2_LCTAU & 0x0007) << 16) | (STV_VDP2_LCTAL & 0xffff))
14071394
r20790r20791
14121399       |    --    |    --    |    --    |    --    |    --    |  BKTA18  |  BKTA17  |  BKTA16  |
14131400       \----------|----------|----------|----------|----------|----------|----------|---------*/
14141401
1415   #define STV_VDP2_BKTAU  (state->m_vdp2_regs[0x0ac/2])
1402   #define STV_VDP2_BKTAU  (m_vdp2_regs[0x0ac/2])
14161403
14171404   #define STV_VDP2_BKCLMD ((STV_VDP2_BKTAU & 0x8000) >> 15)
14181405
r20790r20791
14241411       |  BKTA7   |  BKTA7   |  BKTA6   |  BKTA5   |  BKTA4   |  BKTA3   |  BKTA2   |  BKTA0   |
14251412       \----------|----------|----------|----------|----------|----------|----------|---------*/
14261413
1427   #define STV_VDP2_BKTAL  (state->m_vdp2_regs[0x0ae/2])
1414   #define STV_VDP2_BKTAL  (m_vdp2_regs[0x0ae/2])
14281415
14291416   #define STV_VDP2_BKTA   (((STV_VDP2_BKTAU & 0x0007) << 16) | (STV_VDP2_BKTAL & 0xffff))
14301417
r20790r20791
14351422       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
14361423       \----------|----------|----------|----------|----------|----------|----------|---------*/
14371424
1438   #define STV_VDP2_RPMD   ((state->m_vdp2_regs[0x0b0/2]) & 0x0003)
1425   #define STV_VDP2_RPMD   ((m_vdp2_regs[0x0b0/2]) & 0x0003)
14391426
14401427/* 1800b2 - RPRCTL - Rotation Parameter Read Control
14411428 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
14441431       |    --    |    --    |    --    |    --    |    --    | RAKASTRE | RAYSTRE  | RBXSTRE  |
14451432       \----------|----------|----------|----------|----------|----------|----------|---------*/
14461433
1447   #define STV_VDP2_RPRCTL     (state->m_vdp2_regs[0x0b2/2])
1434   #define STV_VDP2_RPRCTL     (m_vdp2_regs[0x0b2/2])
14481435   #define STV_VDP2_RBKASTRE   ((STV_VDP2_RPRCTL & 0x0400) >> 10)
14491436   #define STV_VDP2_RBYSTRE    ((STV_VDP2_RPRCTL & 0x0200) >> 9)
14501437   #define STV_VDP2_RBXSTRE    ((STV_VDP2_RPRCTL & 0x0100) >> 8)
r20790r20791
14591446       |    --    |    --    |    --    |  RAKLCE  |  RAKMD1  |  RAKMD0  |  RAKDBS  |   RAKTE  |
14601447       \----------|----------|----------|----------|----------|----------|----------|---------*/
14611448
1462   #define STV_VDP2_KTCTL  (state->m_vdp2_regs[0x0b4/2])
1449   #define STV_VDP2_KTCTL  (m_vdp2_regs[0x0b4/2])
14631450   #define STV_VDP2_RBKLCE ((STV_VDP2_KTCTL & 0x1000) >> 12)
14641451   #define STV_VDP2_RBKMD  ((STV_VDP2_KTCTL & 0x0c00) >> 10)
14651452   #define STV_VDP2_RBKDBS ((STV_VDP2_KTCTL & 0x0200) >> 9)
r20790r20791
14761463       |    --    |    --    |    --    |    --    |    --    | RAKTAOS2 | RAKTAOS1 | RAKTAOS0 |
14771464       \----------|----------|----------|----------|----------|----------|----------|---------*/
14781465
1479   #define STV_VDP2_KTAOF  (state->m_vdp2_regs[0x0b6/2])
1466   #define STV_VDP2_KTAOF  (m_vdp2_regs[0x0b6/2])
14801467   #define STV_VDP2_RBKTAOS ((STV_VDP2_KTAOF & 0x0700) >> 8)
14811468   #define STV_VDP2_RAKTAOS ((STV_VDP2_KTAOF & 0x0007) >> 0)
14821469
r20790r20791
14871474       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
14881475       \----------|----------|----------|----------|----------|----------|----------|---------*/
14891476
1490   #define STV_VDP2_OVPNRA (state->m_vdp2_regs[0x0b8/2])
1477   #define STV_VDP2_OVPNRA (m_vdp2_regs[0x0b8/2])
14911478
14921479/* 1800ba - Screen Over Pattern Name (Rotation Parameter B)
14931480 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
14961483       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
14971484       \----------|----------|----------|----------|----------|----------|----------|---------*/
14981485
1499   #define STV_VDP2_OVPNRB (state->m_vdp2_regs[0x0ba/2])
1486   #define STV_VDP2_OVPNRB (m_vdp2_regs[0x0ba/2])
15001487
15011488/* 1800bc - RPTAU - Rotation Parameter Table Address (Rotation Parameter A,B)
15021489 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
15041491       |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
15051492       |    --    |    --    |    --    |    --    |    --    |  RPTA18  |  RPTA17  |  RPTA16  |
15061493       \----------|----------|----------|----------|----------|----------|----------|---------*/
1507   #define STV_VDP2_RPTAU  (state->m_vdp2_regs[0x0bc/2] & 7)
1494   #define STV_VDP2_RPTAU  (m_vdp2_regs[0x0bc/2] & 7)
15081495
15091496/* 1800be - RPTAL - Rotation Parameter Table Address (Rotation Parameter A,B)
15101497 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
15131500       |   RPTA7  |   RPTA6  |   RPTA5  |   RPTA4  |   RPTA3  |   RPTA2  |   RPTA1  |    --    |
15141501       \----------|----------|----------|----------|----------|----------|----------|---------*/
15151502
1516   #define STV_VDP2_RPTAL  (state->m_vdp2_regs[0x0be/2] & 0x0000ffff)
1503   #define STV_VDP2_RPTAL  (m_vdp2_regs[0x0be/2] & 0x0000ffff)
15171504
15181505/* 1800c0 - Window Position (W0, Horizontal Start Point)
15191506 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
15221509       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
15231510       \----------|----------|----------|----------|----------|----------|----------|---------*/
15241511
1525   #define STV_VDP2_WPSX0 (state->m_vdp2_regs[0x0c0/2])
1512   #define STV_VDP2_WPSX0 (m_vdp2_regs[0x0c0/2])
15261513
15271514   #define STV_VDP2_W0SX ((STV_VDP2_WPSX0 & 0x03ff) >> 0)
15281515
r20790r20791
15331520       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
15341521       \----------|----------|----------|----------|----------|----------|----------|---------*/
15351522
1536   #define STV_VDP2_WPSY0 (state->m_vdp2_regs[0x0c2/2])
1523   #define STV_VDP2_WPSY0 (m_vdp2_regs[0x0c2/2])
15371524
15381525   #define STV_VDP2_W0SY ((STV_VDP2_WPSY0 & 0x03ff) >> 0)
15391526
r20790r20791
15441531       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
15451532       \----------|----------|----------|----------|----------|----------|----------|---------*/
15461533
1547   #define STV_VDP2_WPEX0 (state->m_vdp2_regs[0x0c4/2])
1534   #define STV_VDP2_WPEX0 (m_vdp2_regs[0x0c4/2])
15481535
15491536   #define STV_VDP2_W0EX ((STV_VDP2_WPEX0 & 0x03ff) >> 0)
15501537
r20790r20791
15551542       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
15561543       \----------|----------|----------|----------|----------|----------|----------|---------*/
15571544
1558   #define STV_VDP2_WPEY0 (state->m_vdp2_regs[0x0c6/2])
1545   #define STV_VDP2_WPEY0 (m_vdp2_regs[0x0c6/2])
15591546
15601547   #define STV_VDP2_W0EY ((STV_VDP2_WPEY0 & 0x03ff) >> 0)
15611548
r20790r20791
15661553       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
15671554       \----------|----------|----------|----------|----------|----------|----------|---------*/
15681555
1569   #define STV_VDP2_WPSX1 (state->m_vdp2_regs[0x0c8/2])
1556   #define STV_VDP2_WPSX1 (m_vdp2_regs[0x0c8/2])
15701557
15711558   #define STV_VDP2_W1SX ((STV_VDP2_WPSX1 & 0x03ff) >> 0)
15721559
r20790r20791
15771564       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
15781565       \----------|----------|----------|----------|----------|----------|----------|---------*/
15791566
1580   #define STV_VDP2_WPSY1 (state->m_vdp2_regs[0x0ca/2])
1567   #define STV_VDP2_WPSY1 (m_vdp2_regs[0x0ca/2])
15811568
15821569   #define STV_VDP2_W1SY ((STV_VDP2_WPSY1 & 0x03ff) >> 0)
15831570
r20790r20791
15881575       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
15891576       \----------|----------|----------|----------|----------|----------|----------|---------*/
15901577
1591   #define STV_VDP2_WPEX1 (state->m_vdp2_regs[0x0cc/2])
1578   #define STV_VDP2_WPEX1 (m_vdp2_regs[0x0cc/2])
15921579
15931580   #define STV_VDP2_W1EX ((STV_VDP2_WPEX1 & 0x03ff) >> 0)
15941581
r20790r20791
15991586       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
16001587       \----------|----------|----------|----------|----------|----------|----------|---------*/
16011588
1602   #define STV_VDP2_WPEY1 (state->m_vdp2_regs[0x0ce/2])
1589   #define STV_VDP2_WPEY1 (m_vdp2_regs[0x0ce/2])
16031590
16041591   #define STV_VDP2_W1EY ((STV_VDP2_WPEY1 & 0x03ff) >> 0)
16051592
r20790r20791
16101597       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
16111598       \----------|----------|----------|----------|----------|----------|----------|---------*/
16121599
1613   #define STV_VDP2_WCTLA (state->m_vdp2_regs[0x0d0/2])
1600   #define STV_VDP2_WCTLA (m_vdp2_regs[0x0d0/2])
16141601   #define STV_VDP2_N1LOG ((STV_VDP2_WCTLA & 0x8000) >> 15)
16151602   #define STV_VDP2_N1SWE ((STV_VDP2_WCTLA & 0x2000) >> 13)
16161603   #define STV_VDP2_N1SWA ((STV_VDP2_WCTLA & 0x1000) >> 12)
r20790r20791
16331620       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
16341621       \----------|----------|----------|----------|----------|----------|----------|---------*/
16351622
1636   #define STV_VDP2_WCTLB (state->m_vdp2_regs[0x0d2/2])
1623   #define STV_VDP2_WCTLB (m_vdp2_regs[0x0d2/2])
16371624   #define STV_VDP2_N3LOG ((STV_VDP2_WCTLB & 0x8000) >> 15)
16381625   #define STV_VDP2_N3SWE ((STV_VDP2_WCTLB & 0x2000) >> 13)
16391626   #define STV_VDP2_N3SWA ((STV_VDP2_WCTLB & 0x1000) >> 12)
r20790r20791
16561643       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
16571644       \----------|----------|----------|----------|----------|----------|----------|---------*/
16581645
1659   #define STV_VDP2_WCTLC (state->m_vdp2_regs[0x0d4/2])
1646   #define STV_VDP2_WCTLC (m_vdp2_regs[0x0d4/2])
16601647   #define STV_VDP2_SPLOG ((STV_VDP2_WCTLC & 0x8000) >> 15)
16611648   #define STV_VDP2_SPSWE ((STV_VDP2_WCTLC & 0x2000) >> 13)
16621649   #define STV_VDP2_SPSWA ((STV_VDP2_WCTLC & 0x1000) >> 12)
r20790r20791
16791666       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
16801667       \----------|----------|----------|----------|----------|----------|----------|---------*/
16811668
1682   #define STV_VDP2_WCTLD (state->m_vdp2_regs[0x0d6/2])
1669   #define STV_VDP2_WCTLD (m_vdp2_regs[0x0d6/2])
16831670   #define STV_VDP2_CCLOG ((STV_VDP2_WCTLD & 0x8000) >> 15)
16841671   #define STV_VDP2_CCSWE ((STV_VDP2_WCTLD & 0x2000) >> 13)
16851672   #define STV_VDP2_CCSWA ((STV_VDP2_WCTLD & 0x1000) >> 12)
r20790r20791
17001687       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
17011688       \----------|----------|----------|----------|----------|----------|----------|---------*/
17021689
1703   #define STV_VDP2_LWTA0U (state->m_vdp2_regs[0x0d8/2])
1690   #define STV_VDP2_LWTA0U (m_vdp2_regs[0x0d8/2])
17041691
17051692   #define STV_VDP2_W0LWE  ((STV_VDP2_LWTA0U & 0x8000) >> 15)
17061693
r20790r20791
17111698       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
17121699       \----------|----------|----------|----------|----------|----------|----------|---------*/
17131700
1714   #define STV_VDP2_LWTA0L (state->m_vdp2_regs[0x0da/2])
1701   #define STV_VDP2_LWTA0L (m_vdp2_regs[0x0da/2])
17151702
17161703   /* bit 19 isn't used when VRAM = 4 Mbit */
17171704   #define STV_VDP2_W0LWTA (((STV_VDP2_LWTA0U & 0x0007) << 16) | (STV_VDP2_LWTA0L & 0xfffe))
r20790r20791
17241711       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
17251712       \----------|----------|----------|----------|----------|----------|----------|---------*/
17261713
1727   #define STV_VDP2_LWTA1U (state->m_vdp2_regs[0x0dc/2])
1714   #define STV_VDP2_LWTA1U (m_vdp2_regs[0x0dc/2])
17281715
17291716   #define STV_VDP2_W1LWE  ((STV_VDP2_LWTA0U & 0x8000) >> 15)
17301717
r20790r20791
17361723       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
17371724       \----------|----------|----------|----------|----------|----------|----------|---------*/
17381725
1739   #define STV_VDP2_LWTA1L (state->m_vdp2_regs[0x0de/2])
1726   #define STV_VDP2_LWTA1L (m_vdp2_regs[0x0de/2])
17401727
17411728   /* bit 19 isn't used when VRAM = 4 Mbit */
17421729   #define STV_VDP2_W1LWTA (((STV_VDP2_LWTA1U & 0x0007) << 16) | (STV_VDP2_LWTA1L & 0xfffe))
r20790r20791
17491736       |    --    |    --    |  SPCLMD  | SPWINEN  |  SPTYPE3 |  SPTYPE2 |  SPTYPE1 |  SPTYPE0 |
17501737       \----------|----------|----------|----------|----------|----------|----------|---------*/
17511738
1752   #define STV_VDP2_SPCTL  (state->m_vdp2_regs[0xe0/2])
1739   #define STV_VDP2_SPCTL  (m_vdp2_regs[0xe0/2])
17531740   #define STV_VDP2_SPCCCS     ((STV_VDP2_SPCTL & 0x3000) >> 12)
17541741   #define STV_VDP2_SPCCN      ((STV_VDP2_SPCTL & 0x700) >> 8)
17551742   #define STV_VDP2_SPCLMD     ((STV_VDP2_SPCTL & 0x20) >> 5)
r20790r20791
17631750       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
17641751       \----------|----------|----------|----------|----------|----------|----------|---------*/
17651752
1766   #define STV_VDP2_SDCTL  (state->m_vdp2_regs[0x0e2/2])
1753   #define STV_VDP2_SDCTL  (m_vdp2_regs[0x0e2/2])
17671754
17681755/* 1800e4 - CRAOFA - Colour Ram Address Offset (NBG0 - NBG3)
17691756 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
17721759       |    --    | N1CAOS2  | N1CAOS1  | N1CAOS0  |    --    | N0CAOS2  | N0CAOS1  | N0CAOS0  |
17731760       \----------|----------|----------|----------|----------|----------|----------|---------*/
17741761
1775   #define STV_VDP2_CRAOFA (state->m_vdp2_regs[0x0e4/2])
1762   #define STV_VDP2_CRAOFA (m_vdp2_regs[0x0e4/2])
17761763
17771764   /* NxCAOS =  */
17781765   #define STV_VDP2_N0CAOS ((STV_VDP2_CRAOFA & 0x0007) >> 0)
r20790r20791
17871774       |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
17881775       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
17891776       \----------|----------|----------|----------|----------|----------|----------|---------*/
1790   #define STV_VDP2_CRAOFB (state->m_vdp2_regs[0x0e6/2])
1777   #define STV_VDP2_CRAOFB (m_vdp2_regs[0x0e6/2])
17911778   #define STV_VDP2_R0CAOS ((STV_VDP2_CRAOFB & 0x0007) >> 0)
17921779   #define STV_VDP2_SPCAOS ((STV_VDP2_CRAOFB & 0x0070) >> 4)
17931780
r20790r20791
17981785       |    --    |    --    |  SPLCEN  |  R0LCEN  |  N3LCEN  |  N2LCEN  |  N1LCEN  | N0LCEN   |
17991786       \----------|----------|----------|----------|----------|----------|----------|---------*/
18001787
1801   #define STV_VDP2_LNCLEN (state->m_vdp2_regs[0x0e8/2])
1788   #define STV_VDP2_LNCLEN (m_vdp2_regs[0x0e8/2])
18021789   #define STV_VDP2_SPLCEN ((STV_VDP2_LNCLEN & 0x0020) >> 5)
18031790   #define STV_VDP2_R0LCEN ((STV_VDP2_LNCLEN & 0x0010) >> 4)
18041791   #define STV_VDP2_N3LCEN ((STV_VDP2_LNCLEN & 0x0008) >> 3)
r20790r20791
18131800       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
18141801       \----------|----------|----------|----------|----------|----------|----------|---------*/
18151802
1816   #define STV_VDP2_SFPRMD (state->m_vdp2_regs[0x0ea/2])
1803   #define STV_VDP2_SFPRMD (m_vdp2_regs[0x0ea/2])
18171804
18181805
18191806/* 1800ec - Colour Calculation Control
r20790r20791
18231810       |    --    |  SPCCEN  |  LCCCEN  |  R0CCEN  |  N3CCEN  |  N2CCEN  |  N1CCEN  |  N0CCEN  |
18241811       \----------|----------|----------|----------|----------|----------|----------|---------*/
18251812
1826   #define STV_VDP2_CCCR       (state->m_vdp2_regs[0x0ec/2])
1813   #define STV_VDP2_CCCR       (m_vdp2_regs[0x0ec/2])
18271814   #define STV_VDP2_CCMD       ((STV_VDP2_CCCR & 0x100) >> 8)
18281815   #define STV_VDP2_SPCCEN     ((STV_VDP2_CCCR & 0x40) >> 6)
18291816   #define STV_VDP2_LCCCEN     ((STV_VDP2_CCCR & 0x20) >> 5)
r20790r20791
18411828       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
18421829       \----------|----------|----------|----------|----------|----------|----------|---------*/
18431830
1844   #define STV_VDP2_SFCCMD     (state->m_vdp2_regs[0x0ee/2])
1831   #define STV_VDP2_SFCCMD     (m_vdp2_regs[0x0ee/2])
18451832
18461833/* 1800f0 - Priority Number (Sprite 0,1)
18471834 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
18501837       |    --    |    --    |    --    |    --    |    --    |  S0PRIN2 |  S0PRIN1 |  S0PRIN0 |
18511838       \----------|----------|----------|----------|----------|----------|----------|---------*/
18521839
1853   #define STV_VDP2_PRISA      (state->m_vdp2_regs[0x0f0/2])
1840   #define STV_VDP2_PRISA      (m_vdp2_regs[0x0f0/2])
18541841   #define STV_VDP2_S1PRIN     ((STV_VDP2_PRISA & 0x0700) >> 8)
18551842   #define STV_VDP2_S0PRIN     ((STV_VDP2_PRISA & 0x0007) >> 0)
18561843
r20790r20791
18611848       |    --    |    --    |    --    |    --    |    --    |  S2PRIN2 |  S2PRIN1 |  S2PRIN0 |
18621849       \----------|----------|----------|----------|----------|----------|----------|---------*/
18631850
1864   #define STV_VDP2_PRISB      (state->m_vdp2_regs[0x0f2/2])
1851   #define STV_VDP2_PRISB      (m_vdp2_regs[0x0f2/2])
18651852   #define STV_VDP2_S3PRIN     ((STV_VDP2_PRISB & 0x0700) >> 8)
18661853   #define STV_VDP2_S2PRIN     ((STV_VDP2_PRISB & 0x0007) >> 0)
18671854
r20790r20791
18721859       |    --    |    --    |    --    |    --    |    --    |  S4PRIN2 |  S4PRIN1 |  S4PRIN0 |
18731860       \----------|----------|----------|----------|----------|----------|----------|---------*/
18741861
1875   #define STV_VDP2_PRISC      (state->m_vdp2_regs[0x0f4/2])
1862   #define STV_VDP2_PRISC      (m_vdp2_regs[0x0f4/2])
18761863   #define STV_VDP2_S5PRIN     ((STV_VDP2_PRISC & 0x0700) >> 8)
18771864   #define STV_VDP2_S4PRIN     ((STV_VDP2_PRISC & 0x0007) >> 0)
18781865
r20790r20791
18831870       |    --    |    --    |    --    |    --    |    --    |  S6PRIN2 |  S6PRIN1 |  S6PRIN0 |
18841871       \----------|----------|----------|----------|----------|----------|----------|---------*/
18851872
1886   #define STV_VDP2_PRISD      (state->m_vdp2_regs[0x0f6/2])
1873   #define STV_VDP2_PRISD      (m_vdp2_regs[0x0f6/2])
18871874   #define STV_VDP2_S7PRIN     ((STV_VDP2_PRISD & 0x0700) >> 8)
18881875   #define STV_VDP2_S6PRIN     ((STV_VDP2_PRISD & 0x0007) >> 0)
18891876
r20790r20791
18951882       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
18961883       \----------|----------|----------|----------|----------|----------|----------|---------*/
18971884
1898   #define STV_VDP2_PRINA (state->m_vdp2_regs[0x0f8/2])
1885   #define STV_VDP2_PRINA (m_vdp2_regs[0x0f8/2])
18991886
19001887   #define STV_VDP2_N1PRIN ((STV_VDP2_PRINA & 0x0700) >> 8)
19011888   #define STV_VDP2_N0PRIN ((STV_VDP2_PRINA & 0x0007) >> 0)
r20790r20791
19071894       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
19081895       \----------|----------|----------|----------|----------|----------|----------|---------*/
19091896
1910   #define STV_VDP2_PRINB (state->m_vdp2_regs[0x0fa/2])
1897   #define STV_VDP2_PRINB (m_vdp2_regs[0x0fa/2])
19111898
19121899   #define STV_VDP2_N3PRIN ((STV_VDP2_PRINB & 0x0700) >> 8)
19131900   #define STV_VDP2_N2PRIN ((STV_VDP2_PRINB & 0x0007) >> 0)
r20790r20791
19181905       |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
19191906       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
19201907       \----------|----------|----------|----------|----------|----------|----------|---------*/
1921   #define STV_VDP2_PRIR (state->m_vdp2_regs[0x0fc/2])
1908   #define STV_VDP2_PRIR (m_vdp2_regs[0x0fc/2])
19221909
19231910   #define STV_VDP2_R0PRIN ((STV_VDP2_PRIR & 0x0007) >> 0)
19241911
r20790r20791
19361923       |    --    |    --    |    --    |  S0CCRT4 |  S0CCRT3 |  S0CCRT2 |  S0CCRT1 |  S0CCRT0 |
19371924       \----------|----------|----------|----------|----------|----------|----------|---------*/
19381925
1939   #define STV_VDP2_CCRSA      (state->m_vdp2_regs[0x100/2])
1926   #define STV_VDP2_CCRSA      (m_vdp2_regs[0x100/2])
19401927   #define STV_VDP2_S1CCRT     ((STV_VDP2_CCRSA & 0x1f00) >> 8)
19411928   #define STV_VDP2_S0CCRT     ((STV_VDP2_CCRSA & 0x001f) >> 0)
19421929
r20790r20791
19471934       |    --    |    --    |    --    |  S2CCRT4 |  S2CCRT3 |  S2CCRT2 |  S2CCRT1 |  S2CCRT0 |
19481935       \----------|----------|----------|----------|----------|----------|----------|---------*/
19491936
1950   #define STV_VDP2_CCRSB      (state->m_vdp2_regs[0x102/2])
1937   #define STV_VDP2_CCRSB      (m_vdp2_regs[0x102/2])
19511938   #define STV_VDP2_S3CCRT     ((STV_VDP2_CCRSB & 0x1f00) >> 8)
19521939   #define STV_VDP2_S2CCRT     ((STV_VDP2_CCRSB & 0x001f) >> 0)
19531940
r20790r20791
19581945       |    --    |    --    |    --    |  S4CCRT4 |  S4CCRT3 |  S4CCRT2 |  S4CCRT1 |  S4CCRT0 |
19591946       \----------|----------|----------|----------|----------|----------|----------|---------*/
19601947
1961   #define STV_VDP2_CCRSC      (state->m_vdp2_regs[0x104/2])
1948   #define STV_VDP2_CCRSC      (m_vdp2_regs[0x104/2])
19621949   #define STV_VDP2_S5CCRT     ((STV_VDP2_CCRSC & 0x1f00) >> 8)
19631950   #define STV_VDP2_S4CCRT     ((STV_VDP2_CCRSC & 0x001f) >> 0)
19641951
r20790r20791
19691956       |    --    |    --    |    --    |  S6CCRT4 |  S6CCRT3 |  S6CCRT2 |  S6CCRT1 |  S6CCRT0 |
19701957       \----------|----------|----------|----------|----------|----------|----------|---------*/
19711958
1972   #define STV_VDP2_CCRSD      (state->m_vdp2_regs[0x106/2])
1959   #define STV_VDP2_CCRSD      (m_vdp2_regs[0x106/2])
19731960   #define STV_VDP2_S7CCRT     ((STV_VDP2_CCRSD & 0x1f00) >> 8)
19741961   #define STV_VDP2_S6CCRT     ((STV_VDP2_CCRSD & 0x001f) >> 0)
19751962
r20790r20791
19801967       |    --    |    --    |    --    | N0CCRT4  | N0CCRT3  | N0CCRT2  | N0CCRT1  | N0CCRT0  |
19811968       \----------|----------|----------|----------|----------|----------|----------|---------*/
19821969
1983   #define STV_VDP2_CCRNA  (state->m_vdp2_regs[0x108/2])
1970   #define STV_VDP2_CCRNA  (m_vdp2_regs[0x108/2])
19841971   #define STV_VDP2_N1CCRT ((STV_VDP2_CCRNA & 0x1f00) >> 8)
19851972   #define STV_VDP2_N0CCRT (STV_VDP2_CCRNA & 0x1f)
19861973
r20790r20791
19911978       |    --    |    --    |    --    | N2CCRT4  | N2CCRT3  | N2CCRT2  | N2CCRT1  | N2CCRT0  |
19921979       \----------|----------|----------|----------|----------|----------|----------|---------*/
19931980
1994   #define STV_VDP2_CCRNB  (state->m_vdp2_regs[0x10a/2])
1981   #define STV_VDP2_CCRNB  (m_vdp2_regs[0x10a/2])
19951982   #define STV_VDP2_N3CCRT ((STV_VDP2_CCRNB & 0x1f00) >> 8)
19961983   #define STV_VDP2_N2CCRT (STV_VDP2_CCRNB & 0x1f)
19971984
r20790r20791
20021989       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
20031990       \----------|----------|----------|----------|----------|----------|----------|---------*/
20041991
2005   #define STV_VDP2_CCRR   (state->m_vdp2_regs[0x10c/2])
1992   #define STV_VDP2_CCRR   (m_vdp2_regs[0x10c/2])
20061993   #define STV_VDP2_R0CCRT (STV_VDP2_CCRR & 0x1f)
20071994
20081995/* 18010e - Colour Calculation Ratio (Line Colour Screen, Back Colour Screen)
r20790r20791
20192006       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
20202007       \----------|----------|----------|----------|----------|----------|----------|---------*/
20212008
2022   #define STV_VDP2_CLOFEN (state->m_vdp2_regs[0x110/2])
2009   #define STV_VDP2_CLOFEN (m_vdp2_regs[0x110/2])
20232010   #define STV_VDP2_N0COEN ((STV_VDP2_CLOFEN & 0x01) >> 0)
20242011   #define STV_VDP2_N1COEN ((STV_VDP2_CLOFEN & 0x02) >> 1)
20252012   #define STV_VDP2_N2COEN ((STV_VDP2_CLOFEN & 0x04) >> 2)
r20790r20791
20352022       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
20362023       \----------|----------|----------|----------|----------|----------|----------|---------*/
20372024
2038   #define STV_VDP2_CLOFSL (state->m_vdp2_regs[0x112/2])
2025   #define STV_VDP2_CLOFSL (m_vdp2_regs[0x112/2])
20392026   #define STV_VDP2_N0COSL ((STV_VDP2_CLOFSL & 0x01) >> 0)
20402027   #define STV_VDP2_N1COSL ((STV_VDP2_CLOFSL & 0x02) >> 1)
20412028   #define STV_VDP2_N2COSL ((STV_VDP2_CLOFSL & 0x04) >> 2)
r20790r20791
20512038       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
20522039       \----------|----------|----------|----------|----------|----------|----------|---------*/
20532040
2054   #define STV_VDP2_COAR (state->m_vdp2_regs[0x114/2])
2041   #define STV_VDP2_COAR (m_vdp2_regs[0x114/2])
20552042
20562043/* 180116 - Colour Offset A (Green)
20572044 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
20592046       |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
20602047       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
20612048       \----------|----------|----------|----------|----------|----------|----------|---------*/
2062   #define STV_VDP2_COAG (state->m_vdp2_regs[0x116/2])
2049   #define STV_VDP2_COAG (m_vdp2_regs[0x116/2])
20632050
20642051/* 180118 - Colour Offset A (Blue)
20652052 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
20682055       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
20692056       \----------|----------|----------|----------|----------|----------|----------|---------*/
20702057
2071   #define STV_VDP2_COAB (state->m_vdp2_regs[0x118/2])
2058   #define STV_VDP2_COAB (m_vdp2_regs[0x118/2])
20722059
20732060/* 18011a - Colour Offset B (Red)
20742061 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
20762063       |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
20772064       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
20782065       \----------|----------|----------|----------|----------|----------|----------|---------*/
2079   #define STV_VDP2_COBR (state->m_vdp2_regs[0x11a/2])
2066   #define STV_VDP2_COBR (m_vdp2_regs[0x11a/2])
20802067
20812068/* 18011c - Colour Offset B (Green)
20822069 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
20842071       |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
20852072       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
20862073       \----------|----------|----------|----------|----------|----------|----------|---------*/
2087   #define STV_VDP2_COBG (state->m_vdp2_regs[0x11c/2])
2074   #define STV_VDP2_COBG (m_vdp2_regs[0x11c/2])
20882075
20892076/* 18011e - Colour Offset B (Blue)
20902077 bit-> /----15----|----14----|----13----|----12----|----11----|----10----|----09----|----08----\
r20790r20791
20922079       |----07----|----06----|----05----|----04----|----03----|----02----|----01----|----00----|
20932080       |    --    |    --    |    --    |    --    |    --    |    --    |    --    |    --    |
20942081       \----------|----------|----------|----------|----------|----------|----------|---------*/
2095   #define STV_VDP2_COBB (state->m_vdp2_regs[0x11e/2])
2082   #define STV_VDP2_COBB (m_vdp2_regs[0x11e/2])
20962083
20972084/*For Debug purposes only*/
20982085static struct stv_vdp2_debugging
r20790r20791
22072194
22082195#define mul_fixed32( a, b ) mul_32x32_shift( a, b, 16 )
22092196
2210static void stv_vdp2_fill_rotation_parameter_table( running_machine &machine, UINT8 rot_parameter )
2197void saturn_state::stv_vdp2_fill_rotation_parameter_table( UINT8 rot_parameter )
22112198{
2212   saturn_state *state = machine.driver_data<saturn_state>();
22132199   UINT32 address = 0;
22142200
22152201   address = (((STV_VDP2_RPTAU << 16) | STV_VDP2_RPTAL) << 1);
r20790r20791
22222208      address |= 0x00000080;
22232209   }
22242210
2225   stv_current_rotation_parameter_table.xst  = (state->m_vdp2_vram[address/4] & 0x1fffffc0) | ((state->m_vdp2_vram[address/4] & 0x10000000) ? 0xe0000000 : 0x00000000 );
2226   stv_current_rotation_parameter_table.yst  = (state->m_vdp2_vram[address/4 + 1] & 0x1fffffc0) | ((state->m_vdp2_vram[address/4 + 1] & 0x10000000) ? 0xe0000000 : 0x00000000 );
2227   stv_current_rotation_parameter_table.zst  = (state->m_vdp2_vram[address/4 + 2] & 0x1fffffc0) | ((state->m_vdp2_vram[address/4 + 2] & 0x10000000) ? 0xe0000000 : 0x00000000 );
2228   stv_current_rotation_parameter_table.dxst = (state->m_vdp2_vram[address/4 + 3] & 0x0007ffc0) | ((state->m_vdp2_vram[address/4 + 3] & 0x00040000) ? 0xfff80000 : 0x00000000 );
2229   stv_current_rotation_parameter_table.dyst = (state->m_vdp2_vram[address/4 + 4] & 0x0007ffc0) | ((state->m_vdp2_vram[address/4 + 4] & 0x00040000) ? 0xfff80000 : 0x00000000 );
2230   stv_current_rotation_parameter_table.dx   = (state->m_vdp2_vram[address/4 + 5] & 0x0007ffc0) | ((state->m_vdp2_vram[address/4 + 5] & 0x00040000) ? 0xfff80000 : 0x00000000 );
2231   stv_current_rotation_parameter_table.dy   = (state->m_vdp2_vram[address/4 + 6] & 0x0007ffc0) | ((state->m_vdp2_vram[address/4 + 6] & 0x00040000) ? 0xfff80000 : 0x00000000 );
2232   stv_current_rotation_parameter_table.A    = (state->m_vdp2_vram[address/4 + 7] & 0x000fffc0) | ((state->m_vdp2_vram[address/4 + 7] & 0x00080000) ? 0xfff00000 : 0x00000000 );
2233   stv_current_rotation_parameter_table.B    = (state->m_vdp2_vram[address/4 + 8] & 0x000fffc0) | ((state->m_vdp2_vram[address/4 + 8] & 0x00080000) ? 0xfff00000 : 0x00000000 );
2234   stv_current_rotation_parameter_table.C    = (state->m_vdp2_vram[address/4 + 9] & 0x000fffc0) | ((state->m_vdp2_vram[address/4 + 9] & 0x00080000) ? 0xfff00000 : 0x00000000 );
2235   stv_current_rotation_parameter_table.D    = (state->m_vdp2_vram[address/4 + 10] & 0x000fffc0) | ((state->m_vdp2_vram[address/4 + 10] & 0x00080000) ? 0xfff00000 : 0x00000000 );
2236   stv_current_rotation_parameter_table.E    = (state->m_vdp2_vram[address/4 + 11] & 0x000fffc0) | ((state->m_vdp2_vram[address/4 + 11] & 0x00080000) ? 0xfff00000 : 0x00000000 );
2237   stv_current_rotation_parameter_table.F    = (state->m_vdp2_vram[address/4 + 12] & 0x000fffc0) | ((state->m_vdp2_vram[address/4 + 12] & 0x00080000) ? 0xfff00000 : 0x00000000 );
2238   stv_current_rotation_parameter_table.px   = (state->m_vdp2_vram[address/4 + 13] & 0x3fff0000) | ((state->m_vdp2_vram[address/4 + 13] & 0x30000000) ? 0xc0000000 : 0x00000000 );
2239   stv_current_rotation_parameter_table.py   = (state->m_vdp2_vram[address/4 + 13] & 0x00003fff) << 16;
2211   stv_current_rotation_parameter_table.xst  = (m_vdp2_vram[address/4] & 0x1fffffc0) | ((m_vdp2_vram[address/4] & 0x10000000) ? 0xe0000000 : 0x00000000 );
2212   stv_current_rotation_parameter_table.yst  = (m_vdp2_vram[address/4 + 1] & 0x1fffffc0) | ((m_vdp2_vram[address/4 + 1] & 0x10000000) ? 0xe0000000 : 0x00000000 );
2213   stv_current_rotation_parameter_table.zst  = (m_vdp2_vram[address/4 + 2] & 0x1fffffc0) | ((m_vdp2_vram[address/4 + 2] & 0x10000000) ? 0xe0000000 : 0x00000000 );
2214   stv_current_rotation_parameter_table.dxst = (m_vdp2_vram[address/4 + 3] & 0x0007ffc0) | ((m_vdp2_vram[address/4 + 3] & 0x00040000) ? 0xfff80000 : 0x00000000 );
2215   stv_current_rotation_parameter_table.dyst = (m_vdp2_vram[address/4 + 4] & 0x0007ffc0) | ((m_vdp2_vram[address/4 + 4] & 0x00040000) ? 0xfff80000 : 0x00000000 );
2216   stv_current_rotation_parameter_table.dx   = (m_vdp2_vram[address/4 + 5] & 0x0007ffc0) | ((m_vdp2_vram[address/4 + 5] & 0x00040000) ? 0xfff80000 : 0x00000000 );
2217   stv_current_rotation_parameter_table.dy   = (m_vdp2_vram[address/4 + 6] & 0x0007ffc0) | ((m_vdp2_vram[address/4 + 6] & 0x00040000) ? 0xfff80000 : 0x00000000 );
2218   stv_current_rotation_parameter_table.A    = (m_vdp2_vram[address/4 + 7] & 0x000fffc0) | ((m_vdp2_vram[address/4 + 7] & 0x00080000) ? 0xfff00000 : 0x00000000 );
2219   stv_current_rotation_parameter_table.B    = (m_vdp2_vram[address/4 + 8] & 0x000fffc0) | ((m_vdp2_vram[address/4 + 8] & 0x00080000) ? 0xfff00000 : 0x00000000 );
2220   stv_current_rotation_parameter_table.C    = (m_vdp2_vram[address/4 + 9] & 0x000fffc0) | ((m_vdp2_vram[address/4 + 9] & 0x00080000) ? 0xfff00000 : 0x00000000 );
2221   stv_current_rotation_parameter_table.D    = (m_vdp2_vram[address/4 + 10] & 0x000fffc0) | ((m_vdp2_vram[address/4 + 10] & 0x00080000) ? 0xfff00000 : 0x00000000 );
2222   stv_current_rotation_parameter_table.E    = (m_vdp2_vram[address/4 + 11] & 0x000fffc0) | ((m_vdp2_vram[address/4 + 11] & 0x00080000) ? 0xfff00000 : 0x00000000 );
2223   stv_current_rotation_parameter_table.F    = (m_vdp2_vram[address/4 + 12] & 0x000fffc0) | ((m_vdp2_vram[address/4 + 12] & 0x00080000) ? 0xfff00000 : 0x00000000 );
2224   stv_current_rotation_parameter_table.px   = (m_vdp2_vram[address/4 + 13] & 0x3fff0000) | ((m_vdp2_vram[address/4 + 13] & 0x30000000) ? 0xc0000000 : 0x00000000 );
2225   stv_current_rotation_parameter_table.py   = (m_vdp2_vram[address/4 + 13] & 0x00003fff) << 16;
22402226   if ( stv_current_rotation_parameter_table.py & 0x20000000 ) stv_current_rotation_parameter_table.py |= 0xc0000000;
2241   stv_current_rotation_parameter_table.pz   = (state->m_vdp2_vram[address/4 + 14] & 0x3fff0000) | ((state->m_vdp2_vram[address/4 + 14] & 0x20000000) ? 0xc0000000 : 0x00000000 );
2242   stv_current_rotation_parameter_table.cx   = (state->m_vdp2_vram[address/4 + 15] & 0x3fff0000) | ((state->m_vdp2_vram[address/4 + 15] & 0x20000000) ? 0xc0000000 : 0x00000000 );
2243   stv_current_rotation_parameter_table.cy   = (state->m_vdp2_vram[address/4 + 15] & 0x00003fff) << 16;
2227   stv_current_rotation_parameter_table.pz   = (m_vdp2_vram[address/4 + 14] & 0x3fff0000) | ((m_vdp2_vram[address/4 + 14] & 0x20000000) ? 0xc0000000 : 0x00000000 );
2228   stv_current_rotation_parameter_table.cx   = (m_vdp2_vram[address/4 + 15] & 0x3fff0000) | ((m_vdp2_vram[address/4 + 15] & 0x20000000) ? 0xc0000000 : 0x00000000 );
2229   stv_current_rotation_parameter_table.cy   = (m_vdp2_vram[address/4 + 15] & 0x00003fff) << 16;
22442230   if ( stv_current_rotation_parameter_table.cy & 0x20000000 ) stv_current_rotation_parameter_table.cy |= 0xc0000000;
2245   stv_current_rotation_parameter_table.cz   = (state->m_vdp2_vram[address/4 + 16] & 0x3fff0000) | ((state->m_vdp2_vram[address/4 + 16] & 0x20000000) ? 0xc0000000 : 0x00000000 );
2246   stv_current_rotation_parameter_table.mx   = (state->m_vdp2_vram[address/4 + 17] & 0x3fffffc0) | ((state->m_vdp2_vram[address/4 + 17] & 0x20000000) ? 0xc0000000 : 0x00000000 );
2247   stv_current_rotation_parameter_table.my   = (state->m_vdp2_vram[address/4 + 18] & 0x3fffffc0) | ((state->m_vdp2_vram[address/4 + 18] & 0x20000000) ? 0xc0000000 : 0x00000000 );
2248   stv_current_rotation_parameter_table.kx   = (state->m_vdp2_vram[address/4 + 19] & 0x00ffffff) | ((state->m_vdp2_vram[address/4 + 19] & 0x00800000) ? 0xff000000 : 0x00000000 );
2249   stv_current_rotation_parameter_table.ky   = (state->m_vdp2_vram[address/4 + 20] & 0x00ffffff) | ((state->m_vdp2_vram[address/4 + 20] & 0x00800000) ? 0xff000000 : 0x00000000 );
2250   stv_current_rotation_parameter_table.kast = (state->m_vdp2_vram[address/4 + 21] & 0xffffffc0);
2251   stv_current_rotation_parameter_table.dkast= (state->m_vdp2_vram[address/4 + 22] & 0x03ffffc0) | ((state->m_vdp2_vram[address/4 + 22] & 0x02000000) ? 0xfc000000 : 0x00000000 );
2252   stv_current_rotation_parameter_table.dkax = (state->m_vdp2_vram[address/4 + 23] & 0x03ffffc0) | ((state->m_vdp2_vram[address/4 + 23] & 0x02000000) ? 0xfc000000 : 0x00000000 );
2231   stv_current_rotation_parameter_table.cz   = (m_vdp2_vram[address/4 + 16] & 0x3fff0000) | ((m_vdp2_vram[address/4 + 16] & 0x20000000) ? 0xc0000000 : 0x00000000 );
2232   stv_current_rotation_parameter_table.mx   = (m_vdp2_vram[address/4 + 17] & 0x3fffffc0) | ((m_vdp2_vram[address/4 + 17] & 0x20000000) ? 0xc0000000 : 0x00000000 );
2233   stv_current_rotation_parameter_table.my   = (m_vdp2_vram[address/4 + 18] & 0x3fffffc0) | ((m_vdp2_vram[address/4 + 18] & 0x20000000) ? 0xc0000000 : 0x00000000 );
2234   stv_current_rotation_parameter_table.kx   = (m_vdp2_vram[address/4 + 19] & 0x00ffffff) | ((m_vdp2_vram[address/4 + 19] & 0x00800000) ? 0xff000000 : 0x00000000 );
2235   stv_current_rotation_parameter_table.ky   = (m_vdp2_vram[address/4 + 20] & 0x00ffffff) | ((m_vdp2_vram[address/4 + 20] & 0x00800000) ? 0xff000000 : 0x00000000 );
2236   stv_current_rotation_parameter_table.kast = (m_vdp2_vram[address/4 + 21] & 0xffffffc0);
2237   stv_current_rotation_parameter_table.dkast= (m_vdp2_vram[address/4 + 22] & 0x03ffffc0) | ((m_vdp2_vram[address/4 + 22] & 0x02000000) ? 0xfc000000 : 0x00000000 );
2238   stv_current_rotation_parameter_table.dkax = (m_vdp2_vram[address/4 + 23] & 0x03ffffc0) | ((m_vdp2_vram[address/4 + 23] & 0x02000000) ? 0xfc000000 : 0x00000000 );
22532239
22542240#define RP  stv_current_rotation_parameter_table
22552241
r20790r20791
22672253   /*Attempt to show on screen the rotation table*/
22682254   if(LOG_ROZ == 2)
22692255   {
2270      if(machine.input().code_pressed_once(JOYCODE_Y_UP_SWITCH))
2256      if(machine().input().code_pressed_once(JOYCODE_Y_UP_SWITCH))
22712257         vdpdebug.roz++;
22722258
2273      if(machine.input().code_pressed_once(JOYCODE_Y_DOWN_SWITCH))
2259      if(machine().input().code_pressed_once(JOYCODE_Y_DOWN_SWITCH))
22742260         vdpdebug.roz--;
22752261
22762262      if(vdpdebug.roz > 10)
r20790r20791
23342320   return 1;
23352321}
23362322
2337static void stv_vdp2_check_fade_control_for_layer(running_machine &machine)
2323void saturn_state::stv_vdp2_check_fade_control_for_layer( void )
23382324{
2339   saturn_state *state = machine.driver_data<saturn_state>();
23402325   if ( stv2_current_tilemap.fade_control & 1 )
23412326   {
23422327      if ( stv2_current_tilemap.fade_control & 2 )
r20790r20791
23692354#define STV_VDP2_CP_NBG2_CPDR       0x6
23702355#define STV_VDP2_CP_NBG3_CPDR       0x7
23712356
2372static UINT8 stv_vdp2_check_vram_cycle_pattern_registers(
2373                        running_machine &machine,
2374                        UINT8 access_command_pnmdr,
2375                        UINT8 access_command_cpdr,
2376                        UINT8 bitmap_enable )
2357UINT8 saturn_state::stv_vdp2_check_vram_cycle_pattern_registers( UINT8 access_command_pnmdr, UINT8 access_command_cpdr, UINT8 bitmap_enable )
23772358{
2378   saturn_state *state = machine.driver_data<saturn_state>();
23792359   int i;
23802360   UINT8  access_command_ok = 0;
23812361   UINT16 cp_regs[8];
r20790r20791
24392419}
24402420
24412421
2442static void stv_vdp2_compute_color_offset( running_machine &machine,int *r, int *g, int *b, int cor )
2422void saturn_state::stv_vdp2_compute_color_offset( int *r, int *g, int *b, int cor )
24432423{
2444   saturn_state *state = machine.driver_data<saturn_state>();
24452424   if ( cor == 0 )
24462425   {
24472426      *r = (STV_VDP2_COAR & 0x100) ? (*r - (0x100 - (STV_VDP2_COAR & 0xff))) : ((STV_VDP2_COAR & 0xff) + *r);
r20790r20791
24622441   if(*b > 0xff)   { *b = 0xff; }
24632442}
24642443
2465static void stv_vdp2_compute_color_offset_UINT32(running_machine &machine,UINT32 *rgb, int cor)
2444void saturn_state::stv_vdp2_compute_color_offset_UINT32(UINT32 *rgb, int cor)
24662445{
2467   saturn_state *state = machine.driver_data<saturn_state>();
24682446   int _r = RGB_RED(*rgb);
24692447   int _g = RGB_GREEN(*rgb);
24702448   int _b = RGB_BLUE(*rgb);
r20790r20791
24902468   *rgb = MAKE_RGB(_r, _g, _b);
24912469}
24922470
2493static void stv_vdp2_drawgfxzoom(
2471void saturn_state::stv_vdp2_drawgfxzoom(
24942472      bitmap_rgb32 &dest_bmp,const rectangle &clip,gfx_element *gfx,
24952473      UINT32 code,UINT32 color,int flipx,int flipy,int sx,int sy,
24962474      int transparency,int transparent_color,int scalex, int scaley,
r20790r20791
26812659
26822660}
26832661
2684static void stv_vdp2_drawgfxzoom_rgb555(
2685      bitmap_rgb32 &dest_bmp,const rectangle &clip,running_machine &machine,
2662void saturn_state::stv_vdp2_drawgfxzoom_rgb555(
2663      bitmap_rgb32 &dest_bmp,const rectangle &clip,
26862664      UINT32 code,UINT32 color,int flipx,int flipy,int sx,int sy,
26872665      int transparency,int transparent_color,int scalex, int scaley,
26882666      int sprite_screen_width, int sprite_screen_height, int alpha)
26892667{
2690   saturn_state *state = machine.driver_data<saturn_state>();
26912668   rectangle myclip;
26922669   UINT8* gfxdata;
26932670
2694   gfxdata = state->m_vdp2.gfx_decode + code * 0x20;
2671   gfxdata = m_vdp2.gfx_decode + code * 0x20;
26952672
26962673   if (!scalex || !scaley) return;
26972674
r20790r20791
28092786                     g = pal5bit((data & 0x03e0) >> 5);
28102787                     r = pal5bit( data & 0x001f);
28112788                     if(stv2_current_tilemap.fade_control & 1)
2812                        stv_vdp2_compute_color_offset(machine,&r,&g,&b,stv2_current_tilemap.fade_control & 2);
2789                        stv_vdp2_compute_color_offset(&r,&g,&b,stv2_current_tilemap.fade_control & 2);
28132790
28142791                     dest[x] = MAKE_RGB(r, g, b);
28152792                     x_index += dx;
r20790r20791
28362813                     g = pal5bit((data & 0x03e0) >> 5);
28372814                     r = pal5bit( data & 0x001f);
28382815                     if(stv2_current_tilemap.fade_control & 1)
2839                        stv_vdp2_compute_color_offset(machine,&r,&g,&b,stv2_current_tilemap.fade_control & 2);
2816                        stv_vdp2_compute_color_offset(&r,&g,&b,stv2_current_tilemap.fade_control & 2);
28402817
28412818                     if( data ) dest[x] = MAKE_RGB(r, g, b);
28422819                     x_index += dx;
r20790r20791
28632840                     g = pal5bit((data & 0x03e0) >> 5);
28642841                     r = pal5bit( data & 0x001f);
28652842                     if(stv2_current_tilemap.fade_control & 1)
2866                        stv_vdp2_compute_color_offset(machine,&r,&g,&b,stv2_current_tilemap.fade_control & 2);
2843                        stv_vdp2_compute_color_offset(&r,&g,&b,stv2_current_tilemap.fade_control & 2);
28672844
28682845                     if( data ) dest[x] = alpha_blend_r32(dest[x], MAKE_RGB(r, g, b), alpha);
28692846                     x_index += dx;
r20790r20791
28902867                     g = pal5bit((data & 0x03e0) >> 5);
28912868                     r = pal5bit( data & 0x001f);
28922869                     if(stv2_current_tilemap.fade_control & 1)
2893                        stv_vdp2_compute_color_offset(machine,&r,&g,&b,stv2_current_tilemap.fade_control & 2);
2870                        stv_vdp2_compute_color_offset(&r,&g,&b,stv2_current_tilemap.fade_control & 2);
28942871
28952872                     if( data ) dest[x] = stv_add_blend(dest[x], MAKE_RGB(r, g, b));
28962873                     x_index += dx;
r20790r20791
29072884}
29082885
29092886
2910static void stv_vdp2_drawgfx_rgb555( bitmap_rgb32 &dest_bmp, const rectangle &clip, running_machine &machine, UINT32 code, int flipx, int flipy,
2911                              int sx, int sy, int transparency, int alpha)
2887void saturn_state::stv_vdp2_drawgfx_rgb555( bitmap_rgb32 &dest_bmp, const rectangle &clip, UINT32 code, int flipx, int flipy, int sx, int sy, int transparency, int alpha)
29122888{
2913   saturn_state *state = machine.driver_data<saturn_state>();
29142889   rectangle myclip;
29152890   UINT8* gfxdata;
29162891   int sprite_screen_width, sprite_screen_height;
29172892
2918   gfxdata = state->m_vdp2.gfx_decode + code * 0x20;
2893   gfxdata = m_vdp2.gfx_decode + code * 0x20;
29192894   sprite_screen_width = sprite_screen_height = 8;
29202895
29212896   /* KW 991012 -- Added code to force clip to bitmap boundary */
r20790r20791
29982973                  g = pal5bit((data & 0x03e0) >> 5);
29992974                  r = pal5bit( data & 0x001f);
30002975                  if(stv2_current_tilemap.fade_control & 1)
3001                     stv_vdp2_compute_color_offset(machine,&r,&g,&b,stv2_current_tilemap.fade_control & 2);
2976                     stv_vdp2_compute_color_offset(&r,&g,&b,stv2_current_tilemap.fade_control & 2);
30022977
30032978                  if ( transparency == STV_TRANSPARENCY_ALPHA )
30042979                     dest[x] = alpha_blend_r32( dest[x], MAKE_RGB(r, g, b), alpha );
r20790r20791
30182993}
30192994
30202995
3021static void stv_vdp2_drawgfx_rgb888( bitmap_rgb32 &dest_bmp, const rectangle &clip, running_machine &machine, UINT32 code, int flipx, int flipy,
2996void saturn_state::stv_vdp2_drawgfx_rgb888( bitmap_rgb32 &dest_bmp, const rectangle &clip, UINT32 code, int flipx, int flipy,
30222997                              int sx, int sy, int transparency, int alpha)
30232998{
3024   saturn_state *state = machine.driver_data<saturn_state>();
30252999   rectangle myclip;
30263000   UINT8* gfxdata;
30273001   int sprite_screen_width, sprite_screen_height;
30283002
3029   gfxdata = state->m_vdp2.gfx_decode + code * 0x20;
3003   gfxdata = m_vdp2.gfx_decode + code * 0x20;
30303004   sprite_screen_width = sprite_screen_height = 8;
30313005
30323006   /* KW 991012 -- Added code to force clip to bitmap boundary */
r20790r20791
31103084                  r = (data & 0x0000ff);
31113085
31123086                  if(stv2_current_tilemap.fade_control & 1)
3113                     stv_vdp2_compute_color_offset(machine,&r,&g,&b,stv2_current_tilemap.fade_control & 2);
3087                     stv_vdp2_compute_color_offset(&r,&g,&b,stv2_current_tilemap.fade_control & 2);
31143088
31153089                  if ( transparency == STV_TRANSPARENCY_ALPHA )
31163090                     dest[x] = alpha_blend_r32( dest[x], MAKE_RGB(r, g, b), alpha );
r20790r20791
31293103
31303104}
31313105
3132static void stv_vdp2_draw_basic_bitmap(running_machine &machine, bitmap_rgb32 &bitmap, const rectangle &cliprect)
3106void saturn_state::stv_vdp2_draw_basic_bitmap(bitmap_rgb32 &bitmap, const rectangle &cliprect)
31333107{
3134   saturn_state *state = machine.driver_data<saturn_state>();
3135
31363108//  if(LOG_VDP2) logerror ("bitmap enable %02x size %08x depth %08x\n", stv2_current_tilemap.layer_name, stv2_current_tilemap.bitmap_size, stv2_current_tilemap.colour_depth);
31373109//  popmessage ("bitmap enable %02x size %08x depth %08x number %02x", stv2_current_tilemap.layer_name, stv2_current_tilemap.bitmap_size, stv2_current_tilemap.colour_depth,stv2_current_tilemap.bitmap_palette_number);
31383110   //popmessage("%04x",STV_VDP2_SCRCTL);
r20790r20791
31413113   int ysize = 0/*, ysizemask = 0*/;
31423114   int xlinesize = 0/*, xpixelsize = 0*/;
31433115   int xcnt,ycnt;
3144   UINT8* gfxdata = state->m_vdp2.gfx_decode;
3116   UINT8* gfxdata = m_vdp2.gfx_decode;
31453117   UINT32 *destline;
31463118   UINT16 pal_color_offset = 0;
31473119   UINT8* gfxdatalow, *gfxdatahigh;
r20790r20791
31953167   stv2_current_tilemap.bitmap_palette_number+=stv2_current_tilemap.colour_ram_address_offset;
31963168   stv2_current_tilemap.bitmap_palette_number&=7;//safety check
31973169
3198   screen_x = machine.primary_screen->visible_area().max_x;
3199   screen_y = machine.primary_screen->visible_area().max_y;
3170   screen_x = machine().primary_screen->visible_area().max_x;
3171   screen_y = machine().primary_screen->visible_area().max_y;
32003172
32013173   switch(stv2_current_tilemap.colour_depth)
32023174   {
r20790r20791
32063178         {
32073179            for (xcnt = 0; xcnt <xsize;xcnt+=2)
32083180            {
3209               if (!stv_vdp2_window_process(machine,xcnt+1,ycnt))
3181               if (!stv_vdp2_window_process(xcnt+1,ycnt))
32103182               {
32113183                  if ((gfxdata[0] & 0x0f) || (stv2_current_tilemap.transparency == STV_TRANSPARENCY_NONE))
32123184                  {
32133185                     if (((xcnt + 1) <= screen_x) && (ycnt <= screen_y))
32143186                     {
32153187                        if ( stv2_current_tilemap.colour_calculation_enabled == 0 )
3216                           bitmap.pix32(ycnt, xcnt+1) = machine.pens[((gfxdata[0] & 0x0f) >> 0) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset];
3188                           bitmap.pix32(ycnt, xcnt+1) = machine().pens[((gfxdata[0] & 0x0f) >> 0) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset];
32173189                        else
3218                           bitmap.pix32(ycnt, xcnt+1) = alpha_blend_r32(bitmap.pix32(ycnt, xcnt+1), machine.pens[((gfxdata[0] & 0x0f) >> 0) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset], stv2_current_tilemap.alpha);
3190                           bitmap.pix32(ycnt, xcnt+1) = alpha_blend_r32(bitmap.pix32(ycnt, xcnt+1), machine().pens[((gfxdata[0] & 0x0f) >> 0) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset], stv2_current_tilemap.alpha);
32193191                     }
32203192                  }
32213193               }
3222               if (!stv_vdp2_window_process(machine,xcnt,ycnt))
3194               if (!stv_vdp2_window_process(xcnt,ycnt))
32233195               {
32243196                  if ((gfxdata[0] & 0xf0) || (stv2_current_tilemap.transparency == STV_TRANSPARENCY_NONE))
32253197                  {
32263198                     if (((xcnt + 0) <= screen_x) && (ycnt <= screen_y))
32273199                     {
32283200                        if ( stv2_current_tilemap.colour_calculation_enabled == 0 )
3229                           bitmap.pix32(ycnt, xcnt) = machine.pens[((gfxdata[0] & 0xf0) >> 4) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset];
3201                           bitmap.pix32(ycnt, xcnt) = machine().pens[((gfxdata[0] & 0xf0) >> 4) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset];
32303202                        else
3231                           bitmap.pix32(ycnt, xcnt) = alpha_blend_r32(bitmap.pix32(ycnt, xcnt), machine.pens[((gfxdata[0] & 0xf0) >> 4) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset], stv2_current_tilemap.alpha);
3203                           bitmap.pix32(ycnt, xcnt) = alpha_blend_r32(bitmap.pix32(ycnt, xcnt), machine().pens[((gfxdata[0] & 0xf0) >> 4) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset], stv2_current_tilemap.alpha);
32323204                     }
32333205                  }
32343206               }
r20790r20791
32503222               {
32513223                  int xs = xcnt & xsizemask;
32523224
3253                  if (!stv_vdp2_window_process(machine,xcnt,ycnt))
3225                  if (!stv_vdp2_window_process(xcnt,ycnt))
32543226                  {
32553227                     //60aee2c = $0013 at @605d838
32563228                     if ((gfxdata[xs] & 0xff) || (stv2_current_tilemap.transparency == STV_TRANSPARENCY_NONE))
r20790r20791
32583230                        if (((xcnt + 0) <= screen_x) && (ycnt <= screen_y))
32593231                        {
32603232                           if ( stv2_current_tilemap.colour_calculation_enabled == 0 )
3261                              bitmap.pix32(ycnt, xcnt) = machine.pens[(gfxdata[xs] & 0xff) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset];
3233                              bitmap.pix32(ycnt, xcnt) = machine().pens[(gfxdata[xs] & 0xff) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset];
32623234                           else
3263                              bitmap.pix32(ycnt, xcnt) = alpha_blend_r32(bitmap.pix32(ycnt, xcnt), machine.pens[(gfxdata[xs] & 0xff) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset], stv2_current_tilemap.alpha);
3235                              bitmap.pix32(ycnt, xcnt) = alpha_blend_r32(bitmap.pix32(ycnt, xcnt), machine().pens[(gfxdata[xs] & 0xff) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset], stv2_current_tilemap.alpha);
32643236                        }
32653237                     }
32663238                  }
r20790r20791
32933265               for (xcnt = cliprect.min_x; xcnt <= cliprect.max_x; xx+=stv2_current_tilemap.incx, xcnt++)
32943266               {
32953267                  xs = xx >> 16;
3296                  if (!stv_vdp2_window_process(machine,xcnt,ycnt))
3268                  if (!stv_vdp2_window_process(xcnt,ycnt))
32973269                  {
32983270                     if ((gfxdata[xs] & 0xff) || (stv2_current_tilemap.transparency == STV_TRANSPARENCY_NONE))
32993271                     {
33003272                        if (((xcnt + 0) <= screen_x) && (ycnt <= screen_y))
33013273                        {
33023274                           if ( stv2_current_tilemap.colour_calculation_enabled == 0 )
3303                              bitmap.pix32(ycnt, xcnt) = machine.pens[(gfxdata[xs] & 0xff) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset];
3275                              bitmap.pix32(ycnt, xcnt) = machine().pens[(gfxdata[xs] & 0xff) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset];
33043276                           else
3305                              bitmap.pix32(ycnt, xcnt) = alpha_blend_r32(bitmap.pix32(ycnt, xcnt), machine.pens[(gfxdata[xs] & 0xff) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset], stv2_current_tilemap.alpha);
3277                              bitmap.pix32(ycnt, xcnt) = alpha_blend_r32(bitmap.pix32(ycnt, xcnt), machine().pens[(gfxdata[xs] & 0xff) | (stv2_current_tilemap.bitmap_palette_number * 0x100) | pal_color_offset], stv2_current_tilemap.alpha);
33063278                        }
33073279                     }
33083280                  }
r20790r20791
33183290         {
33193291            for (xcnt = 0; xcnt <xsize;xcnt++)
33203292            {
3321               if (!stv_vdp2_window_process(machine,xcnt,ycnt))
3293               if (!stv_vdp2_window_process(xcnt,ycnt))
33223294               {
33233295                  if (((gfxdata[0] & 0x07) | (gfxdata[1] & 0xff)) || (stv2_current_tilemap.transparency == STV_TRANSPARENCY_NONE))
33243296                  {
33253297                     if (((xcnt + 0) <= screen_x) && (ycnt <= screen_y))
33263298                     {
33273299                        if ( stv2_current_tilemap.colour_calculation_enabled == 0 )
3328                           bitmap.pix32(ycnt, xcnt) = machine.pens[((gfxdata[0] & 0x07) * 0x100) | (gfxdata[1] & 0xff) | pal_color_offset];
3300                           bitmap.pix32(ycnt, xcnt) = machine().pens[((gfxdata[0] & 0x07) * 0x100) | (gfxdata[1] & 0xff) | pal_color_offset];
33293301                        else
3330                           bitmap.pix32(ycnt, xcnt) = alpha_blend_r32(bitmap.pix32(ycnt, xcnt), machine.pens[((gfxdata[0] & 0x07) * 0x100) | (gfxdata[1] & 0xff) | pal_color_offset], stv2_current_tilemap.alpha);
3302                           bitmap.pix32(ycnt, xcnt) = alpha_blend_r32(bitmap.pix32(ycnt, xcnt), machine().pens[((gfxdata[0] & 0x07) * 0x100) | (gfxdata[1] & 0xff) | pal_color_offset], stv2_current_tilemap.alpha);
33313303                     }
33323304                  }
33333305               }
r20790r20791
33653337                     g = pal5bit(((gfxdata[2*xs] & 0x03) << 3) | ((gfxdata[2*xs+1] & 0xe0) >> 5));
33663338                     r = pal5bit(gfxdata[2*xs+1] & 0x1f);
33673339                     if(stv2_current_tilemap.fade_control & 1)
3368                        stv_vdp2_compute_color_offset(machine,&r,&g,&b,stv2_current_tilemap.fade_control & 2);
3340                        stv_vdp2_compute_color_offset(&r,&g,&b,stv2_current_tilemap.fade_control & 2);
33693341
3370                     if (!stv_vdp2_window_process(machine,xcnt,ycnt))
3342                     if (!stv_vdp2_window_process(xcnt,ycnt))
33713343                     {
33723344                        if (((xcnt + 0) <= screen_x) && (ycnt <= screen_y))
33733345                        {
r20790r20791
34073379                  g = pal5bit(((gfxdata[2*xs] & 0x03) << 3) | ((gfxdata[2*xs+1] & 0xe0) >> 5));
34083380                  r = pal5bit(gfxdata[2*xs+1] & 0x1f);
34093381                  if(stv2_current_tilemap.fade_control & 1)
3410                     stv_vdp2_compute_color_offset(machine, &r,&g,&b,stv2_current_tilemap.fade_control & 2);
3382                     stv_vdp2_compute_color_offset( &r,&g,&b,stv2_current_tilemap.fade_control & 2);
34113383
3412                  if (!stv_vdp2_window_process(machine,xcnt,ycnt))
3384                  if (!stv_vdp2_window_process(xcnt,ycnt))
34133385                  {
34143386                     if ((gfxdata[2*xs] & 0x80) || (stv2_current_tilemap.transparency == STV_TRANSPARENCY_NONE))
34153387                     {
r20790r20791
34603432                  r = ((dot_data & 0x000000ff) >> 0);
34613433
34623434                  if(stv2_current_tilemap.fade_control & 1)
3463                     stv_vdp2_compute_color_offset(machine,&r,&g,&b,stv2_current_tilemap.fade_control & 2);
3435                     stv_vdp2_compute_color_offset(&r,&g,&b,stv2_current_tilemap.fade_control & 2);
34643436
3465                  if (!stv_vdp2_window_process(machine,xcnt,ycnt))
3437                  if (!stv_vdp2_window_process(xcnt,ycnt))
34663438                  {
34673439                     if (((xcnt + 0) <= screen_x) && (ycnt <= screen_y))
34683440                     {
r20790r20791
36533625   *_map = map;
36543626}
36553627
3656static void stv_vdp2_draw_basic_tilemap(running_machine &machine, bitmap_rgb32 &bitmap, const rectangle &cliprect)
3628void saturn_state::stv_vdp2_draw_basic_tilemap(bitmap_rgb32 &bitmap, const rectangle &cliprect)
36573629{
3658   saturn_state *state = machine.driver_data<saturn_state>();
36593630   /* hopefully this is easier to follow than it is efficient .. */
36603631
36613632   /* I call character patterns tiles .. even if they represent up to 4 tiles */
r20790r20791
39343905         /* 1 word per tile mode with supplement bits */
39353906         if (stv2_current_tilemap.pattern_data_size ==1)
39363907         {
3937            data = state->m_vdp2_vram[newbase + offs/2];
3908            data = m_vdp2_vram[newbase + offs/2];
39383909            data = (offs&1) ? (data & 0x0000ffff) : ((data & 0xffff0000) >> 16);
39393910
39403911            /* Supplement Mode 12 bits, no flip */
r20790r20791
39593930         /* 2 words per tile, no supplement bits */
39603931         else
39613932         {
3962            data = state->m_vdp2_vram[newbase + offs];
3933            data = m_vdp2_vram[newbase + offs];
39633934            tilecode = (data & 0x00007fff);
39643935            pal   = (data &    0x007f0000)>>16;
39653936   //          specialc = (data & 0x10000000)>>28;
r20790r20791
40183989               else if ( stv2_current_tilemap.colour_depth == 3 )
40193990               {
40203991                  /* RGB555 */
4021                  stv_vdp2_drawgfxzoom_rgb555(bitmap,cliprect,machine,tilecode+(0+(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos >> 16, drawypos >> 16,stv2_current_tilemap.transparency,0,scalex,scaley,SCR_TILESIZE_X, SCR_TILESIZE_Y,stv2_current_tilemap.alpha);
4022                  stv_vdp2_drawgfxzoom_rgb555(bitmap,cliprect,machine,tilecode+(1-(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,(drawxpos+tilesizex) >> 16,drawypos >> 16,stv2_current_tilemap.transparency,0,scalex,scaley,SCR_TILESIZE_X1(tilesizex), SCR_TILESIZE_Y,stv2_current_tilemap.alpha);
4023                  stv_vdp2_drawgfxzoom_rgb555(bitmap,cliprect,machine,tilecode+(2+(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos >> 16,(drawypos+tilesizey) >> 16,stv2_current_tilemap.transparency,0,scalex,scaley,SCR_TILESIZE_X, SCR_TILESIZE_Y1(tilesizey),stv2_current_tilemap.alpha);
4024                  stv_vdp2_drawgfxzoom_rgb555(bitmap,cliprect,machine,tilecode+(3-(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,(drawxpos+tilesizex)>> 16,(drawypos+tilesizey) >> 16,stv2_current_tilemap.transparency,0,scalex,scaley,SCR_TILESIZE_X1(tilesizex), SCR_TILESIZE_Y1(tilesizey),stv2_current_tilemap.alpha);
3992                  stv_vdp2_drawgfxzoom_rgb555(bitmap,cliprect,tilecode+(0+(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos >> 16, drawypos >> 16,stv2_current_tilemap.transparency,0,scalex,scaley,SCR_TILESIZE_X, SCR_TILESIZE_Y,stv2_current_tilemap.alpha);
3993                  stv_vdp2_drawgfxzoom_rgb555(bitmap,cliprect,tilecode+(1-(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,(drawxpos+tilesizex) >> 16,drawypos >> 16,stv2_current_tilemap.transparency,0,scalex,scaley,SCR_TILESIZE_X1(tilesizex), SCR_TILESIZE_Y,stv2_current_tilemap.alpha);
3994                  stv_vdp2_drawgfxzoom_rgb555(bitmap,cliprect,tilecode+(2+(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos >> 16,(drawypos+tilesizey) >> 16,stv2_current_tilemap.transparency,0,scalex,scaley,SCR_TILESIZE_X, SCR_TILESIZE_Y1(tilesizey),stv2_current_tilemap.alpha);
3995                  stv_vdp2_drawgfxzoom_rgb555(bitmap,cliprect,tilecode+(3-(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,(drawxpos+tilesizex)>> 16,(drawypos+tilesizey) >> 16,stv2_current_tilemap.transparency,0,scalex,scaley,SCR_TILESIZE_X1(tilesizex), SCR_TILESIZE_Y1(tilesizey),stv2_current_tilemap.alpha);
40253996               }
40263997               else
40273998               {
40283999                  /* normal */
4029                  stv_vdp2_drawgfxzoom(bitmap,cliprect,machine.gfx[gfx],tilecode+(0+(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos >> 16, drawypos >> 16,stv2_current_tilemap.transparency,0,scalex,scaley,SCR_TILESIZE_X, SCR_TILESIZE_Y,stv2_current_tilemap.alpha);
4030                  stv_vdp2_drawgfxzoom(bitmap,cliprect,machine.gfx[gfx],tilecode+(1-(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,(drawxpos+tilesizex) >> 16,drawypos >> 16,stv2_current_tilemap.transparency,0,scalex,scaley,SCR_TILESIZE_X1(tilesizex), SCR_TILESIZE_Y,stv2_current_tilemap.alpha);
4031                  stv_vdp2_drawgfxzoom(bitmap,cliprect,machine.gfx[gfx],tilecode+(2+(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos >> 16,(drawypos+tilesizey) >> 16,stv2_current_tilemap.transparency,0,scalex,scaley,SCR_TILESIZE_X, SCR_TILESIZE_Y1(tilesizey),stv2_current_tilemap.alpha);
4032                  stv_vdp2_drawgfxzoom(bitmap,cliprect,machine.gfx[gfx],tilecode+(3-(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,(drawxpos+tilesizex)>> 16,(drawypos+tilesizey) >> 16,stv2_current_tilemap.transparency,0,scalex,scaley,SCR_TILESIZE_X1(tilesizex), SCR_TILESIZE_Y1(tilesizey),stv2_current_tilemap.alpha);
4000                  stv_vdp2_drawgfxzoom(bitmap,cliprect,machine().gfx[gfx],tilecode+(0+(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos >> 16, drawypos >> 16,stv2_current_tilemap.transparency,0,scalex,scaley,SCR_TILESIZE_X, SCR_TILESIZE_Y,stv2_current_tilemap.alpha);
4001                  stv_vdp2_drawgfxzoom(bitmap,cliprect,machine().gfx[gfx],tilecode+(1-(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,(drawxpos+tilesizex) >> 16,drawypos >> 16,stv2_current_tilemap.transparency,0,scalex,scaley,SCR_TILESIZE_X1(tilesizex), SCR_TILESIZE_Y,stv2_current_tilemap.alpha);
4002                  stv_vdp2_drawgfxzoom(bitmap,cliprect,machine().gfx[gfx],tilecode+(2+(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos >> 16,(drawypos+tilesizey) >> 16,stv2_current_tilemap.transparency,0,scalex,scaley,SCR_TILESIZE_X, SCR_TILESIZE_Y1(tilesizey),stv2_current_tilemap.alpha);
4003                  stv_vdp2_drawgfxzoom(bitmap,cliprect,machine().gfx[gfx],tilecode+(3-(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,(drawxpos+tilesizex)>> 16,(drawypos+tilesizey) >> 16,stv2_current_tilemap.transparency,0,scalex,scaley,SCR_TILESIZE_X1(tilesizex), SCR_TILESIZE_Y1(tilesizey),stv2_current_tilemap.alpha);
40334004               }
40344005            }
40354006            else
r20790r20791
40384009                  popmessage("Unsupported tilemap gfx zoom color depth = 4, tile size = 0, contact MAMEdev");
40394010               else if ( stv2_current_tilemap.colour_depth == 3)
40404011               {
4041                  stv_vdp2_drawgfxzoom_rgb555(bitmap,cliprect,machine,tilecode,pal,flipyx&1,flipyx&2, drawxpos >> 16, drawypos >> 16,stv2_current_tilemap.transparency,0,scalex,scaley,SCR_TILESIZE_X,SCR_TILESIZE_Y,stv2_current_tilemap.alpha);
4012                  stv_vdp2_drawgfxzoom_rgb555(bitmap,cliprect,tilecode,pal,flipyx&1,flipyx&2, drawxpos >> 16, drawypos >> 16,stv2_current_tilemap.transparency,0,scalex,scaley,SCR_TILESIZE_X,SCR_TILESIZE_Y,stv2_current_tilemap.alpha);
40424013               }
40434014               else
4044                  stv_vdp2_drawgfxzoom(bitmap,cliprect,machine.gfx[gfx],tilecode,pal,flipyx&1,flipyx&2, drawxpos >> 16, drawypos >> 16,stv2_current_tilemap.transparency,0,scalex,scaley,SCR_TILESIZE_X,SCR_TILESIZE_Y,stv2_current_tilemap.alpha);
4015                  stv_vdp2_drawgfxzoom(bitmap,cliprect,machine().gfx[gfx],tilecode,pal,flipyx&1,flipyx&2, drawxpos >> 16, drawypos >> 16,stv2_current_tilemap.transparency,0,scalex,scaley,SCR_TILESIZE_X,SCR_TILESIZE_Y,stv2_current_tilemap.alpha);
40454016            }
40464017         }
40474018         else
r20790r20791
40544025               if ( stv2_current_tilemap.colour_depth == 4 )
40554026               {
40564027                  /* normal */
4057                  stv_vdp2_drawgfx_rgb888(bitmap,cliprect,machine,tilecode+(0+(flipyx&1)+(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos, drawypos,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4058                  stv_vdp2_drawgfx_rgb888(bitmap,cliprect,machine,tilecode+(1-(flipyx&1)+(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos+8,drawypos,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4059                  stv_vdp2_drawgfx_rgb888(bitmap,cliprect,machine,tilecode+(2+(flipyx&1)-(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos,drawypos+8,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4060                  stv_vdp2_drawgfx_rgb888(bitmap,cliprect,machine,tilecode+(3-(flipyx&1)-(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos+8,drawypos+8,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4028                  stv_vdp2_drawgfx_rgb888(bitmap,cliprect,tilecode+(0+(flipyx&1)+(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos, drawypos,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4029                  stv_vdp2_drawgfx_rgb888(bitmap,cliprect,tilecode+(1-(flipyx&1)+(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos+8,drawypos,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4030                  stv_vdp2_drawgfx_rgb888(bitmap,cliprect,tilecode+(2+(flipyx&1)-(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos,drawypos+8,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4031                  stv_vdp2_drawgfx_rgb888(bitmap,cliprect,tilecode+(3-(flipyx&1)-(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos+8,drawypos+8,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
40614032               }
40624033               else if ( stv2_current_tilemap.colour_depth == 3 )
40634034               {
40644035                  /* normal */
4065                  stv_vdp2_drawgfx_rgb555(bitmap,cliprect,machine,tilecode+(0+(flipyx&1)+(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos, drawypos,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4066                  stv_vdp2_drawgfx_rgb555(bitmap,cliprect,machine,tilecode+(1-(flipyx&1)+(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos+8,drawypos,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4067                  stv_vdp2_drawgfx_rgb555(bitmap,cliprect,machine,tilecode+(2+(flipyx&1)-(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos,drawypos+8,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4068                  stv_vdp2_drawgfx_rgb555(bitmap,cliprect,machine,tilecode+(3-(flipyx&1)-(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos+8,drawypos+8,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4036                  stv_vdp2_drawgfx_rgb555(bitmap,cliprect,tilecode+(0+(flipyx&1)+(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos, drawypos,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4037                  stv_vdp2_drawgfx_rgb555(bitmap,cliprect,tilecode+(1-(flipyx&1)+(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos+8,drawypos,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4038                  stv_vdp2_drawgfx_rgb555(bitmap,cliprect,tilecode+(2+(flipyx&1)-(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos,drawypos+8,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4039                  stv_vdp2_drawgfx_rgb555(bitmap,cliprect,tilecode+(3-(flipyx&1)-(flipyx&2))*4,flipyx&1,flipyx&2,drawxpos+8,drawypos+8,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
40694040               }
40704041               else if (stv2_current_tilemap.transparency == STV_TRANSPARENCY_ALPHA)
40714042               {
40724043                  /* alpha */
4073                  drawgfx_alpha(bitmap,cliprect,machine.gfx[gfx],tilecode+(0+(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos, drawypos,0,stv2_current_tilemap.alpha);
4074                  drawgfx_alpha(bitmap,cliprect,machine.gfx[gfx],tilecode+(1-(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos+8,drawypos,0,stv2_current_tilemap.alpha);
4075                  drawgfx_alpha(bitmap,cliprect,machine.gfx[gfx],tilecode+(2+(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos,drawypos+8,0,stv2_current_tilemap.alpha);
4076                  drawgfx_alpha(bitmap,cliprect,machine.gfx[gfx],tilecode+(3-(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos+8,drawypos+8,0,stv2_current_tilemap.alpha);
4044                  drawgfx_alpha(bitmap,cliprect,machine().gfx[gfx],tilecode+(0+(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos, drawypos,0,stv2_current_tilemap.alpha);
4045                  drawgfx_alpha(bitmap,cliprect,machine().gfx[gfx],tilecode+(1-(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos+8,drawypos,0,stv2_current_tilemap.alpha);
4046                  drawgfx_alpha(bitmap,cliprect,machine().gfx[gfx],tilecode+(2+(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos,drawypos+8,0,stv2_current_tilemap.alpha);
4047                  drawgfx_alpha(bitmap,cliprect,machine().gfx[gfx],tilecode+(3-(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos+8,drawypos+8,0,stv2_current_tilemap.alpha);
40774048               }
40784049               else
40794050               {
40804051                  /* normal */
4081                  drawgfx_transpen(bitmap,cliprect,machine.gfx[gfx],tilecode+(0+(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos, drawypos,(stv2_current_tilemap.transparency==STV_TRANSPARENCY_PEN)?0:-1);
4082                  drawgfx_transpen(bitmap,cliprect,machine.gfx[gfx],tilecode+(1-(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos+8,drawypos,(stv2_current_tilemap.transparency==STV_TRANSPARENCY_PEN)?0:-1);
4083                  drawgfx_transpen(bitmap,cliprect,machine.gfx[gfx],tilecode+(2+(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos,drawypos+8,(stv2_current_tilemap.transparency==STV_TRANSPARENCY_PEN)?0:-1);
4084                  drawgfx_transpen(bitmap,cliprect,machine.gfx[gfx],tilecode+(3-(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos+8,drawypos+8,(stv2_current_tilemap.transparency==STV_TRANSPARENCY_PEN)?0:-1);
4052                  drawgfx_transpen(bitmap,cliprect,machine().gfx[gfx],tilecode+(0+(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos, drawypos,(stv2_current_tilemap.transparency==STV_TRANSPARENCY_PEN)?0:-1);
4053                  drawgfx_transpen(bitmap,cliprect,machine().gfx[gfx],tilecode+(1-(flipyx&1)+(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos+8,drawypos,(stv2_current_tilemap.transparency==STV_TRANSPARENCY_PEN)?0:-1);
4054                  drawgfx_transpen(bitmap,cliprect,machine().gfx[gfx],tilecode+(2+(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos,drawypos+8,(stv2_current_tilemap.transparency==STV_TRANSPARENCY_PEN)?0:-1);
4055                  drawgfx_transpen(bitmap,cliprect,machine().gfx[gfx],tilecode+(3-(flipyx&1)-(flipyx&2))*tilecodespacing,pal,flipyx&1,flipyx&2,drawxpos+8,drawypos+8,(stv2_current_tilemap.transparency==STV_TRANSPARENCY_PEN)?0:-1);
40854056               }
40864057            }
40874058            else
40884059            {
40894060               if ( stv2_current_tilemap.colour_depth == 4)
40904061               {
4091                  stv_vdp2_drawgfx_rgb888(bitmap,cliprect,machine,tilecode,flipyx&1,flipyx&2,drawxpos,drawypos,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4062                  stv_vdp2_drawgfx_rgb888(bitmap,cliprect,tilecode,flipyx&1,flipyx&2,drawxpos,drawypos,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
40924063               }
40934064               else if ( stv2_current_tilemap.colour_depth == 3)
40944065               {
4095                  stv_vdp2_drawgfx_rgb555(bitmap,cliprect,machine,tilecode,flipyx&1,flipyx&2,drawxpos,drawypos,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
4066                  stv_vdp2_drawgfx_rgb555(bitmap,cliprect,tilecode,flipyx&1,flipyx&2,drawxpos,drawypos,stv2_current_tilemap.transparency,stv2_current_tilemap.alpha);
40964067               }
40974068               else
40984069               {
40994070                  if (stv2_current_tilemap.transparency == STV_TRANSPARENCY_ALPHA)
4100                     drawgfx_alpha(bitmap,cliprect,machine.gfx[gfx],tilecode,pal,flipyx&1,flipyx&2, drawxpos, drawypos,0,stv2_current_tilemap.alpha);
4071                     drawgfx_alpha(bitmap,cliprect,machine().gfx[gfx],tilecode,pal,flipyx&1,flipyx&2, drawxpos, drawypos,0,stv2_current_tilemap.alpha);
41014072                  else
4102                     drawgfx_transpen(bitmap,cliprect,machine.gfx[gfx],tilecode,pal,flipyx&1,flipyx&2, drawxpos, drawypos,(stv2_current_tilemap.transparency==STV_TRANSPARENCY_PEN)?0:-1);
4073                     drawgfx_transpen(bitmap,cliprect,machine().gfx[gfx],tilecode,pal,flipyx&1,flipyx&2, drawxpos, drawypos,(stv2_current_tilemap.transparency==STV_TRANSPARENCY_PEN)?0:-1);
41034074               }
41044075            }
41054076            drawxpos = olddrawxpos;
r20790r20791
41544125
41554126#define STV_VDP2_READ_VERTICAL_LINESCROLL( _val, _address ) \
41564127   { \
4157      _val = state->m_vdp2_vram[ _address ]; \
4128      _val = m_vdp2_vram[ _address ]; \
41584129      _val &= 0x07ffff00; \
41594130      if ( _val & 0x04000000 ) _val |= 0xf8000000; \
41604131   }
41614132
41624133
4163static void stv_vdp2_check_tilemap_with_linescroll(running_machine &machine, bitmap_rgb32 &bitmap, const rectangle &cliprect)
4134void saturn_state::stv_vdp2_check_tilemap_with_linescroll(bitmap_rgb32 &bitmap, const rectangle &cliprect)
41644135{
4165   saturn_state *state = machine.driver_data<saturn_state>();
41664136   rectangle mycliprect;
41674137   int cur_line = cliprect.min_y;
41684138   int address;
r20790r20791
42144184      }
42154185      else
42164186      {
4217         prev_scroll_values[i] = state->m_vdp2_vram[ (address / 4) + i ];
4187         prev_scroll_values[i] = m_vdp2_vram[ (address / 4) + i ];
42184188      }
42194189   }
42204190
r20790r20791
42394209            }
42404210            else
42414211            {
4242               scroll_values[i] = state->m_vdp2_vram[ (address / 4) + i ];
4212               scroll_values[i] = m_vdp2_vram[ (address / 4) + i ];
42434213            }
42444214         }
42454215
r20790r20791
42844254
42854255//      if ( LOG_VDP2 ) logerror( "Linescroll: y < %d, %d >, scrollx = %d, scrolly = %d, incx = %f\n", mycliprect.min_y, mycliprect.max_y, stv2_current_tilemap.scrollx, stv2_current_tilemap.scrolly, (float)stv2_current_tilemap.incx/65536.0 );
42864256      // render current tilemap portion
4287      stv_vdp2_apply_window_on_layer(machine,mycliprect);
4257      stv_vdp2_apply_window_on_layer(mycliprect);
42884258
42894259      if (stv2_current_tilemap.bitmap_enable) // this layer is a bitmap
42904260      {
r20790r20791
42924262         //if ( window_applied && stv2_current_tilemap.colour_depth != 4)
42934263         //  stv2_current_tilemap.window_control = 0;
42944264
4295         stv_vdp2_draw_basic_bitmap(machine, bitmap, mycliprect);
4265         stv_vdp2_draw_basic_bitmap(bitmap, mycliprect);
42964266      }
42974267      else
42984268      {
4299         stv_vdp2_draw_basic_tilemap(machine, bitmap, mycliprect);
4269         stv_vdp2_draw_basic_tilemap(bitmap, mycliprect);
43004270      }
43014271
43024272      // update parameters for next iteration
r20790r20791
43054275   }
43064276}
43074277
4308static void stv_vdp2_draw_line(running_machine &machine, bitmap_rgb32 &bitmap, const rectangle &cliprect)
4278void saturn_state::stv_vdp2_draw_line(bitmap_rgb32 &bitmap, const rectangle &cliprect)
43094279{
4310   saturn_state *state = machine.driver_data<saturn_state>();
43114280   int x,y;
4312   UINT8* gfxdata = state->m_vdp2.gfx_decode;
4281   UINT8* gfxdata = m_vdp2.gfx_decode;
43134282   UINT32 base_offs,base_mask;
43144283   UINT32 pix;
43154284   UINT8 interlace;
r20790r20791
43334302            pen = (gfxdata[base_offs+0]<<8)|gfxdata[base_offs+1];
43344303            pix = bitmap.pix32(y, x);
43354304
4336            bitmap.pix32(y, x) = stv_add_blend(machine.pens[pen & 0x7ff],pix);
4305            bitmap.pix32(y, x) = stv_add_blend(machine().pens[pen & 0x7ff],pix);
43374306         }
43384307      }
43394308   }
43404309}
43414310
4342static void stv_vdp2_draw_mosaic(running_machine &machine, bitmap_rgb32 &bitmap, const rectangle &cliprect, UINT8 is_roz)
4311void saturn_state::stv_vdp2_draw_mosaic(bitmap_rgb32 &bitmap, const rectangle &cliprect, UINT8 is_roz)
43434312{
4344   saturn_state *state = machine.driver_data<saturn_state>();
43454313   int x,y,xi,yi;
43464314   UINT8 h_size,v_size;
43474315   UINT32 pix;
r20790r20791
43714339   }
43724340}
43734341
4374static void stv_vdp2_check_tilemap(running_machine &machine, bitmap_rgb32 &bitmap, const rectangle &cliprect)
4342void saturn_state::stv_vdp2_check_tilemap(bitmap_rgb32 &bitmap, const rectangle &cliprect)
43754343{
43764344   /* the idea is here we check the tilemap capabilities / whats enabled and call an appropriate tilemap drawing routine, or
43774345     at the very list throw up a few errors if the tilemaps want to do something we don't support yet */
4378   saturn_state *state = machine.driver_data<saturn_state>();
4379
43804346//  int window_applied = 0;
43814347   rectangle mycliprect = cliprect;
43824348
r20790r20791
43844350         stv2_current_tilemap.vertical_linescroll_enable ||
43854351         stv2_current_tilemap.linezoom_enable )
43864352   {
4387      stv_vdp2_check_tilemap_with_linescroll(machine, bitmap, cliprect);
4353      stv_vdp2_check_tilemap_with_linescroll(bitmap, cliprect);
43884354      return;
43894355   }
43904356
43914357//  window_applied =
4392   stv_vdp2_apply_window_on_layer(machine,mycliprect);
4358   stv_vdp2_apply_window_on_layer(mycliprect);
43934359
43944360   if (stv2_current_tilemap.bitmap_enable) // this layer is a bitmap
43954361   {
r20790r20791
43974363      //if ( window_applied && stv2_current_tilemap.colour_depth != 4)
43984364      //  stv2_current_tilemap.window_control = 0;
43994365
4400      stv_vdp2_draw_basic_bitmap(machine, bitmap, mycliprect);
4366      stv_vdp2_draw_basic_bitmap(bitmap, mycliprect);
44014367   }
44024368   else
44034369   {
4404      stv_vdp2_draw_basic_tilemap(machine, bitmap, mycliprect);
4370      stv_vdp2_draw_basic_tilemap(bitmap, mycliprect);
44054371   }
44064372
44074373   /* post-processing functions (TODO: needs layer bitmaps to be individual planes to work correctly) */
44084374   if(stv2_current_tilemap.line_screen_enabled && TEST_FUNCTIONS)
4409      stv_vdp2_draw_line(machine,bitmap,cliprect);
4375      stv_vdp2_draw_line(bitmap,cliprect);
44104376
44114377   if(stv2_current_tilemap.mosaic_screen_enabled && TEST_FUNCTIONS)
4412      stv_vdp2_draw_mosaic(machine,bitmap,cliprect,stv2_current_tilemap.layer_name & 0x80);
4378      stv_vdp2_draw_mosaic(bitmap,cliprect,stv2_current_tilemap.layer_name & 0x80);
44134379
44144380
44154381   {
r20790r20791
44834449   }
44844450}
44854451
4486static void stv_vdp2_draw_rotation_screen(running_machine &machine, bitmap_rgb32 &bitmap, const rectangle &cliprect, int iRP);
44874452
4488
4489static void stv_vdp2_copy_roz_bitmap(bitmap_rgb32 &bitmap,
4490                              running_machine &machine,
4453void saturn_state::stv_vdp2_copy_roz_bitmap(bitmap_rgb32 &bitmap,
44914454                              bitmap_rgb32 &roz_bitmap,
44924455                              const rectangle &cliprect,
44934456                              int iRP,
r20790r20791
44964459                              int planerenderedsizex,
44974460                              int planerenderedsizey)
44984461{
4499   saturn_state *state = machine.driver_data<saturn_state>();
45004462   INT32 xsp, ysp, xp, yp, dx, dy, x, y, xs, ys, dxs, dys;
45014463   INT32 vcnt, hcnt;
45024464   INT32 kx, ky;
r20790r20791
45614523   {
45624524      if ( STV_VDP2_CRKTE == 0 )
45634525      {
4564         coeff_table_base = state->m_vdp2_vram;
4526         coeff_table_base = m_vdp2_vram;
45654527      }
45664528      else
45674529      {
4568         coeff_table_base = state->m_vdp2_cram;
4530         coeff_table_base = m_vdp2_cram;
45694531      }
45704532      if ( coeff_table_size == 0 )
45714533      {
r20790r20791
47284690                  if (pix & 0xffffff)
47294691                  {
47304692                     if(stv2_current_tilemap.fade_control & 1)
4731                        stv_vdp2_compute_color_offset_UINT32(machine,&pix,stv2_current_tilemap.fade_control & 2);
4693                        stv_vdp2_compute_color_offset_UINT32(&pix,stv2_current_tilemap.fade_control & 2);
47324694
47334695                     line[hcnt] = pix;
47344696                  }
47354697                  break;
47364698               case STV_TRANSPARENCY_NONE:
47374699                  if(stv2_current_tilemap.fade_control & 1)
4738                     stv_vdp2_compute_color_offset_UINT32(machine,&pix,stv2_current_tilemap.fade_control & 2);
4700                     stv_vdp2_compute_color_offset_UINT32(&pix,stv2_current_tilemap.fade_control & 2);
47394701
47404702                  line[hcnt] = pix;
47414703                  break;
r20790r20791
47434705                  if (pix & 0xffffff)
47444706                  {
47454707                     if(stv2_current_tilemap.fade_control & 1)
4746                        stv_vdp2_compute_color_offset_UINT32(machine,&pix,stv2_current_tilemap.fade_control & 2);
4708                        stv_vdp2_compute_color_offset_UINT32(&pix,stv2_current_tilemap.fade_control & 2);
47474709
47484710                     line[hcnt] = alpha_blend_r32( line[hcnt], pix, stv2_current_tilemap.alpha );
47494711                  }
r20790r20791
47524714                  if (pix & 0xffffff)
47534715                  {
47544716                     if(stv2_current_tilemap.fade_control & 1)
4755                        stv_vdp2_compute_color_offset_UINT32(machine,&pix,stv2_current_tilemap.fade_control & 2);
4717                        stv_vdp2_compute_color_offset_UINT32(&pix,stv2_current_tilemap.fade_control & 2);
47564718
47574719                     line[hcnt] = stv_add_blend( line[hcnt], pix );
47584720                  }
r20790r20791
48394801                  if (pix & 0xffffff)
48404802                  {
48414803                     if(stv2_current_tilemap.fade_control & 1)
4842                        stv_vdp2_compute_color_offset_UINT32(machine,&pix,stv2_current_tilemap.fade_control & 2);
4804                        stv_vdp2_compute_color_offset_UINT32(&pix,stv2_current_tilemap.fade_control & 2);
48434805
48444806                     line[hcnt] = pix;
48454807                  }
48464808                  break;
48474809               case STV_TRANSPARENCY_NONE:
48484810                  if(stv2_current_tilemap.fade_control & 1)
4849                     stv_vdp2_compute_color_offset_UINT32(machine,&pix,stv2_current_tilemap.fade_control & 2);
4811                     stv_vdp2_compute_color_offset_UINT32(&pix,stv2_current_tilemap.fade_control & 2);
48504812
48514813                  line[hcnt] = pix;
48524814                  break;
r20790r20791
48544816                  if (pix & 0xffffff)
48554817                  {
48564818                     if(stv2_current_tilemap.fade_control & 1)
4857                        stv_vdp2_compute_color_offset_UINT32(machine,&pix,stv2_current_tilemap.fade_control & 2);
4819                        stv_vdp2_compute_color_offset_UINT32(&pix,stv2_current_tilemap.fade_control & 2);
48584820
48594821                     line[hcnt] = alpha_blend_r32( line[hcnt], pix, stv2_current_tilemap.alpha );
48604822                  }
r20790r20791
48634825                  if (pix & 0xffffff)
48644826                  {
48654827                     if(stv2_current_tilemap.fade_control & 1)
4866                        stv_vdp2_compute_color_offset_UINT32(machine,&pix,stv2_current_tilemap.fade_control & 2);
4828                        stv_vdp2_compute_color_offset_UINT32(&pix,stv2_current_tilemap.fade_control & 2);
48674829
48684830                     line[hcnt] = stv_add_blend( line[hcnt], pix );
48694831                  }
r20790r20791
48744836   }
48754837}
48764838
4877static void stv_vdp2_draw_NBG0(running_machine &machine, bitmap_rgb32 &bitmap, const rectangle &cliprect)
4839void saturn_state::stv_vdp2_draw_NBG0(bitmap_rgb32 &bitmap, const rectangle &cliprect)
48784840{
4879   saturn_state *state = machine.driver_data<saturn_state>();
48804841   UINT32 base_mask;
48814842
48824843   base_mask = STV_VDP2_VRAMSZ ? 0x7ffff : 0x3ffff;
r20790r20791
49514912   stv2_current_tilemap.plane_size = (STV_VDP2_R1ON) ? STV_VDP2_RBPLSZ : STV_VDP2_N0PLSZ;
49524913   stv2_current_tilemap.colour_ram_address_offset = STV_VDP2_N0CAOS;
49534914   stv2_current_tilemap.fade_control = (STV_VDP2_N0COEN * 1) | (STV_VDP2_N0COSL * 2);
4954   stv_vdp2_check_fade_control_for_layer(machine);
4915   stv_vdp2_check_fade_control_for_layer();
49554916   stv2_current_tilemap.window_control = (STV_VDP2_N0LOG << 0) |
49564917                                 (STV_VDP2_N0W0E << 1) |
49574918                                 (STV_VDP2_N0W1E << 2) |
r20790r20791
49674928
49684929   if ( stv2_current_tilemap.enabled && (!(STV_VDP2_R1ON))) /* TODO: check cycle pattern for RBG1 */
49694930   {
4970      stv2_current_tilemap.enabled = stv_vdp2_check_vram_cycle_pattern_registers( machine, STV_VDP2_CP_NBG0_PNMDR, STV_VDP2_CP_NBG0_CPDR, stv2_current_tilemap.bitmap_enable );
4931      stv2_current_tilemap.enabled = stv_vdp2_check_vram_cycle_pattern_registers( STV_VDP2_CP_NBG0_PNMDR, STV_VDP2_CP_NBG0_CPDR, stv2_current_tilemap.bitmap_enable );
49714932   }
49724933
49734934   if(STV_VDP2_R1ON)
4974      stv_vdp2_draw_rotation_screen(machine, bitmap, cliprect, 2 );
4935      stv_vdp2_draw_rotation_screen(bitmap, cliprect, 2 );
49754936   else
4976      stv_vdp2_check_tilemap(machine, bitmap, cliprect);
4937      stv_vdp2_check_tilemap(bitmap, cliprect);
49774938}
49784939
4979static void stv_vdp2_draw_NBG1(running_machine &machine, bitmap_rgb32 &bitmap, const rectangle &cliprect)
4940void saturn_state::stv_vdp2_draw_NBG1(bitmap_rgb32 &bitmap, const rectangle &cliprect)
49804941{
4981   saturn_state *state = machine.driver_data<saturn_state>();
49824942   UINT32 base_mask;
49834943
49844944   base_mask = STV_VDP2_VRAMSZ ? 0x7ffff : 0x3ffff;
r20790r20791
50525012   stv2_current_tilemap.plane_size = STV_VDP2_N1PLSZ;
50535013   stv2_current_tilemap.colour_ram_address_offset = STV_VDP2_N1CAOS;
50545014   stv2_current_tilemap.fade_control = (STV_VDP2_N1COEN * 1) | (STV_VDP2_N1COSL * 2);
5055   stv_vdp2_check_fade_control_for_layer(machine);
5015   stv_vdp2_check_fade_control_for_layer();
50565016   stv2_current_tilemap.window_control = (STV_VDP2_N1LOG << 0) |
50575017                                 (STV_VDP2_N1W0E << 1) |
50585018                                 (STV_VDP2_N1W1E << 2) |
r20790r20791
50685028
50695029   if ( stv2_current_tilemap.enabled )
50705030   {
5071      stv2_current_tilemap.enabled = stv_vdp2_check_vram_cycle_pattern_registers( machine, STV_VDP2_CP_NBG1_PNMDR, STV_VDP2_CP_NBG1_CPDR, stv2_current_tilemap.bitmap_enable );
5031      stv2_current_tilemap.enabled = stv_vdp2_check_vram_cycle_pattern_registers( STV_VDP2_CP_NBG1_PNMDR, STV_VDP2_CP_NBG1_CPDR, stv2_current_tilemap.bitmap_enable );
50725032   }
50735033
5074   stv_vdp2_check_tilemap(machine, bitmap, cliprect);
5034   stv_vdp2_check_tilemap(bitmap, cliprect);
50755035}
50765036
5077static void stv_vdp2_draw_NBG2(running_machine &machine, bitmap_rgb32 &bitmap, const rectangle &cliprect)
5037void saturn_state::stv_vdp2_draw_NBG2(bitmap_rgb32 &bitmap, const rectangle &cliprect)
50785038{
5079   saturn_state *state = machine.driver_data<saturn_state>();
5080
50815039   /*
50825040      NBG2 is the first of the 2 more basic tilemaps, it has exactly the same capabilities as NBG3
50835041
r20790r20791
51555113
51565114   stv2_current_tilemap.colour_ram_address_offset = STV_VDP2_N2CAOS;
51575115   stv2_current_tilemap.fade_control = (STV_VDP2_N2COEN * 1) | (STV_VDP2_N2COSL * 2);
5158   stv_vdp2_check_fade_control_for_layer(machine);
5116   stv_vdp2_check_fade_control_for_layer();
51595117   stv2_current_tilemap.window_control = (STV_VDP2_N2LOG << 0) |
51605118                                 (STV_VDP2_N2W0E << 1) |
51615119                                 (STV_VDP2_N2W1E << 2) |
r20790r20791
51735131
51745132   if ( stv2_current_tilemap.enabled )
51755133   {
5176      stv2_current_tilemap.enabled = stv_vdp2_check_vram_cycle_pattern_registers( machine, STV_VDP2_CP_NBG2_PNMDR, STV_VDP2_CP_NBG2_CPDR, stv2_current_tilemap.bitmap_enable );
5134      stv2_current_tilemap.enabled = stv_vdp2_check_vram_cycle_pattern_registers( STV_VDP2_CP_NBG2_PNMDR, STV_VDP2_CP_NBG2_CPDR, stv2_current_tilemap.bitmap_enable );
51775135   }
51785136
5179   stv_vdp2_check_tilemap(machine, bitmap, cliprect);
5137   stv_vdp2_check_tilemap(bitmap, cliprect);
51805138}
51815139
5182static void stv_vdp2_draw_NBG3(running_machine &machine, bitmap_rgb32 &bitmap, const rectangle &cliprect)
5140void saturn_state::stv_vdp2_draw_NBG3(bitmap_rgb32 &bitmap, const rectangle &cliprect)
51835141{
5184   saturn_state *state = machine.driver_data<saturn_state>();
51855142   /*
51865143      NBG3 is the second of the 2 more basic tilemaps, it has exactly the same capabilities as NBG2
51875144
r20790r20791
52595216
52605217   stv2_current_tilemap.colour_ram_address_offset = STV_VDP2_N3CAOS;
52615218   stv2_current_tilemap.fade_control = (STV_VDP2_N3COEN * 1) | (STV_VDP2_N3COSL * 2);
5262   stv_vdp2_check_fade_control_for_layer(machine);
5219   stv_vdp2_check_fade_control_for_layer();
52635220   stv2_current_tilemap.window_control = (STV_VDP2_N3LOG << 0) |
52645221                                 (STV_VDP2_N3W0E << 1) |
52655222                                 (STV_VDP2_N3W1E << 2) |
r20790r20791
52775234
52785235   if ( stv2_current_tilemap.enabled )
52795236   {
5280      stv2_current_tilemap.enabled = stv_vdp2_check_vram_cycle_pattern_registers( machine, STV_VDP2_CP_NBG3_PNMDR, STV_VDP2_CP_NBG3_CPDR, stv2_current_tilemap.bitmap_enable );
5237      stv2_current_tilemap.enabled = stv_vdp2_check_vram_cycle_pattern_registers( STV_VDP2_CP_NBG3_PNMDR, STV_VDP2_CP_NBG3_CPDR, stv2_current_tilemap.bitmap_enable );
52815238   }
52825239
5283   stv_vdp2_check_tilemap(machine, bitmap, cliprect);
5240   stv_vdp2_check_tilemap(bitmap, cliprect);
52845241}
52855242
52865243
5287static void stv_vdp2_draw_rotation_screen(running_machine &machine, bitmap_rgb32 &bitmap, const rectangle &cliprect, int iRP)
5244void saturn_state::stv_vdp2_draw_rotation_screen(bitmap_rgb32 &bitmap, const rectangle &cliprect, int iRP)
52885245{
5289   saturn_state *state = machine.driver_data<saturn_state>();
52905246   rectangle roz_clip_rect, mycliprect;
52915247   int planesizex = 0, planesizey = 0;
52925248   int planerenderedsizex, planerenderedsizey;
r20790r20791
53375293      stv2_current_tilemap.map_count = 16;
53385294   }
53395295
5340   stv_vdp2_fill_rotation_parameter_table(machine, iRP);
5296   stv_vdp2_fill_rotation_parameter_table(iRP);
53415297
53425298   if ( iRP == 1 )
53435299   {
r20790r20791
53845340      stv2_current_tilemap.scrollx = stv_current_rotation_parameter_table.mx >> 16;
53855341      stv2_current_tilemap.scrolly = stv_current_rotation_parameter_table.my >> 16;
53865342
5387      stv_vdp2_check_tilemap(machine, bitmap,cliprect);
5343      stv_vdp2_check_tilemap(bitmap,cliprect);
53885344   }
53895345   else
53905346   {
5391      if ( !state->m_vdp2.roz_bitmap[iRP-1].valid() )
5392         state->m_vdp2.roz_bitmap[iRP-1].allocate(4096, 4096);
5347      if ( !m_vdp2.roz_bitmap[iRP-1].valid() )
5348         m_vdp2.roz_bitmap[iRP-1].allocate(4096, 4096);
53935349
53945350      roz_clip_rect.min_x = roz_clip_rect.min_y = 0;
53955351      if ( (iRP == 1 && STV_VDP2_RAOVR == 3) ||
r20790r20791
54265382      if ( (stv_rbg_cache_data.is_cache_dirty & iRP) ||
54275383         memcmp(&stv_rbg_cache_data.layer_data[iRP-1],&stv2_current_tilemap,sizeof(stv2_current_tilemap)) != 0 )
54285384      {
5429         state->m_vdp2.roz_bitmap[iRP-1].fill(get_black_pen(machine), roz_clip_rect );
5430         stv_vdp2_check_tilemap(machine, state->m_vdp2.roz_bitmap[iRP-1], roz_clip_rect);
5385         m_vdp2.roz_bitmap[iRP-1].fill(get_black_pen(machine()), roz_clip_rect );
5386         stv_vdp2_check_tilemap(m_vdp2.roz_bitmap[iRP-1], roz_clip_rect);
54315387         // prepare cache data
54325388         stv_rbg_cache_data.watch_vdp2_vram_writes |= iRP;
54335389         stv_rbg_cache_data.is_cache_dirty &= ~iRP;
r20790r20791
54535409      if ( window_control )
54545410      {
54555411         stv2_current_tilemap.window_control = window_control;
5456         stv_vdp2_apply_window_on_layer(machine,mycliprect);
5412         stv_vdp2_apply_window_on_layer(mycliprect);
54575413      }
54585414
54595415      stv2_current_tilemap.fade_control = fade_control;
54605416
54615417      g_profiler.start(PROFILER_USER2);
5462      stv_vdp2_copy_roz_bitmap(bitmap, machine, state->m_vdp2.roz_bitmap[iRP-1], mycliprect, iRP, planesizex, planesizey, planerenderedsizex, planerenderedsizey );
5418      stv_vdp2_copy_roz_bitmap(bitmap, m_vdp2.roz_bitmap[iRP-1], mycliprect, iRP, planesizex, planesizey, planerenderedsizex, planerenderedsizey );
54635419      g_profiler.stop();
54645420   }
54655421
54665422}
54675423
5468static void stv_vdp2_draw_RBG0(running_machine &machine, bitmap_rgb32 &bitmap, const rectangle &cliprect)
5424void saturn_state::stv_vdp2_draw_RBG0(bitmap_rgb32 &bitmap, const rectangle &cliprect)
54695425{
5470   saturn_state *state = machine.driver_data<saturn_state>();
54715426   /*
54725427      Colours           : 16, 256, 2048, 32768, 16770000
54735428      Char Size         : 1x1 cells, 2x2 cells
r20790r20791
55205475
55215476   stv2_current_tilemap.colour_ram_address_offset = STV_VDP2_R0CAOS;
55225477   stv2_current_tilemap.fade_control = (STV_VDP2_R0COEN * 1) | (STV_VDP2_R0COSL * 2);
5523   stv_vdp2_check_fade_control_for_layer(machine);
5478   stv_vdp2_check_fade_control_for_layer();
55245479   stv2_current_tilemap.window_control = (STV_VDP2_R0LOG << 0) |
55255480                                 (STV_VDP2_R0W0E << 1) |
55265481                                 (STV_VDP2_R0W1E << 2) |
r20790r20791
55515506   switch(STV_VDP2_RPMD)
55525507   {
55535508      case 0://Rotation Parameter A
5554         stv_vdp2_draw_rotation_screen(machine, bitmap, cliprect, 1 );
5509         stv_vdp2_draw_rotation_screen(bitmap, cliprect, 1 );
55555510         break;
55565511      case 1://Rotation Parameter B
55575512      //case 2:
5558         stv_vdp2_draw_rotation_screen(machine, bitmap, cliprect, 2 );
5513         stv_vdp2_draw_rotation_screen(bitmap, cliprect, 2 );
55595514         break;
55605515      case 2://Rotation Parameter A & B CKTE
5561         stv_vdp2_draw_rotation_screen(machine, bitmap, cliprect, 2 );
5562         stv_vdp2_draw_rotation_screen(machine, bitmap, cliprect, 1 );
5516         stv_vdp2_draw_rotation_screen(bitmap, cliprect, 2 );
5517         stv_vdp2_draw_rotation_screen(bitmap, cliprect, 1 );
55635518         break;
55645519      case 3://Rotation Parameter A & B Window (wrong)
5565         stv_vdp2_draw_rotation_screen(machine, bitmap, cliprect, 1 );
5520         stv_vdp2_draw_rotation_screen(bitmap, cliprect, 1 );
55665521         break;
55675522   }
55685523
55695524}
55705525
5571static void stv_vdp2_draw_back(running_machine &machine, bitmap_rgb32 &bitmap, const rectangle &cliprect)
5526void saturn_state::stv_vdp2_draw_back(bitmap_rgb32 &bitmap, const rectangle &cliprect)
55725527{
5573   saturn_state *state = machine.driver_data<saturn_state>();
55745528   int x,y;
5575   UINT8* gfxdata = state->m_vdp2.gfx_decode;
5529   UINT8* gfxdata = m_vdp2.gfx_decode;
55765530   UINT32 base_offs,base_mask;
55775531   UINT8 interlace;
55785532
r20790r20791
55825536
55835537   /* draw black if BDCLMD and DISP are cleared */
55845538   if(!(STV_VDP2_BDCLMD) && !(STV_VDP2_DISP))
5585      bitmap.fill(get_black_pen(machine), cliprect);
5539      bitmap.fill(get_black_pen(machine()), cliprect);
55865540   else
55875541   {
55885542      base_mask = STV_VDP2_VRAMSZ ? 0x7ffff : 0x3ffff;
r20790r20791
56035557            g = pal5bit((dot & 0x03e0) >> 5);
56045558            r = pal5bit( dot & 0x001f);
56055559            if(STV_VDP2_BKCOEN)
5606               stv_vdp2_compute_color_offset( machine, &r, &g, &b, STV_VDP2_BKCOSL );
5560               stv_vdp2_compute_color_offset( &r, &g, &b, STV_VDP2_BKCOSL );
56075561
56085562            bitmap.pix32(y, x) = MAKE_RGB(r, g, b);
56095563         }
r20790r20791
56115565   }
56125566}
56135567
5614READ32_HANDLER ( saturn_vdp2_vram_r )
5568READ32_MEMBER ( saturn_state::saturn_vdp2_vram_r )
56155569{
5616   saturn_state *state = space.machine().driver_data<saturn_state>();
5617
5618   return state->m_vdp2_vram[offset];
5570   return m_vdp2_vram[offset];
56195571}
56205572
5621WRITE32_HANDLER ( saturn_vdp2_vram_w )
5573WRITE32_MEMBER ( saturn_state::saturn_vdp2_vram_w )
56225574{
5623   saturn_state *state = space.machine().driver_data<saturn_state>();
5624   UINT8* gfxdata = state->m_vdp2.gfx_decode;
5575   UINT8* gfxdata = m_vdp2.gfx_decode;
56255576
5626   COMBINE_DATA(&state->m_vdp2_vram[offset]);
5577   COMBINE_DATA(&m_vdp2_vram[offset]);
56275578
5628   data = state->m_vdp2_vram[offset];
5579   data = m_vdp2_vram[offset];
56295580   /* put in gfx region for easy decoding */
56305581   gfxdata[offset*4+0] = (data & 0xff000000) >> 24;
56315582   gfxdata[offset*4+1] = (data & 0x00ff0000) >> 16;
r20790r20791
56755626
56765627}
56775628
5678READ16_HANDLER ( saturn_vdp2_regs_r )
5629READ16_MEMBER ( saturn_state::saturn_vdp2_regs_r )
56795630{
5680   saturn_state *state = space.machine().driver_data<saturn_state>();
5681
56825631   switch(offset)
56835632   {
56845633      case 0x002/2:
r20790r20791
56895638            /* TODO: handle various h/v settings. */
56905639            if(!space.debugger_access())
56915640            {
5692               state->m_vdp2.h_count = space.machine().primary_screen->hpos() & 0x3ff;
5693               state->m_vdp2.v_count = space.machine().primary_screen->vpos() & (STV_VDP2_LSMD == 3 ? 0x7ff : 0x3ff);
5641               m_vdp2.h_count = space.machine().primary_screen->hpos() & 0x3ff;
5642               m_vdp2.v_count = space.machine().primary_screen->vpos() & (STV_VDP2_LSMD == 3 ? 0x7ff : 0x3ff);
56945643               /* latch flag */
5695               state->m_vdp2.exltfg |= 1;
5644               m_vdp2.exltfg |= 1;
56965645            }
56975646         }
56985647
r20790r20791
57025651      {
57035652         /*Screen Status Register*/
57045653                              /*VBLANK              HBLANK            ODD               PAL    */
5705         state->m_vdp2_regs[offset] = (state->m_vdp2.exltfg<<9) |
5706                                 (state->m_vdp2.exsyfg<<8) |
5707                                 (get_vblank(space.machine()) << 3) |
5708                                 (get_hblank(space.machine()) << 2) |
5709                                 (get_odd_bit(space.machine()) << 1) |
5710                                 (state->m_vdp2.pal << 0);
5654         m_vdp2_regs[offset] = (m_vdp2.exltfg<<9) |
5655                                 (m_vdp2.exsyfg<<8) |
5656                                 (get_vblank() << 3) |
5657                                 (get_hblank() << 2) |
5658                                 (get_odd_bit() << 1) |
5659                                 (m_vdp2.pal << 0);
57115660
57125661         /* vblank bit is always 1 if DISP bit is disabled */
57135662         if(!STV_VDP2_DISP)
5714            state->m_vdp2_regs[offset] |= 1 << 3;
5663            m_vdp2_regs[offset] |= 1 << 3;
57155664
57165665         /* HV latches clears if this register is read */
57175666         if(!space.debugger_access())
57185667         {
5719            state->m_vdp2.exltfg &= ~1;
5720            state->m_vdp2.exsyfg &= ~1;
5668            m_vdp2.exltfg &= ~1;
5669            m_vdp2.exsyfg &= ~1;
57215670         }
57225671         break;
57235672      }
57245673      case 0x006/2:
57255674      {
5726         state->m_vdp2_regs[offset] = (STV_VDP2_VRAMSZ << 15) |
5675         m_vdp2_regs[offset] = (STV_VDP2_VRAMSZ << 15) |
57275676                                 ((0 << 0) & 0xf); // VDP2 version
57285677
57295678         if(!space.debugger_access())
r20790r20791
57345683      /* HCNT */
57355684      case 0x008/2:
57365685      {
5737         state->m_vdp2_regs[offset] = (state->m_vdp2.h_count);
5686         m_vdp2_regs[offset] = (m_vdp2.h_count);
57385687         break;
57395688      }
57405689
57415690      /* VCNT */
57425691      case 0x00a/2:
57435692      {
5744         state->m_vdp2_regs[offset] = (state->m_vdp2.v_count);
5693         m_vdp2_regs[offset] = (m_vdp2.v_count);
57455694         break;
57465695      }
57475696
r20790r20791
57515700         break;
57525701   }
57535702
5754   return state->m_vdp2_regs[offset];
5703   return m_vdp2_regs[offset];
57555704}
57565705
5757READ32_HANDLER ( saturn_vdp2_cram_r )
5706READ32_MEMBER ( saturn_state::saturn_vdp2_cram_r )
57585707{
5759   saturn_state *state = space.machine().driver_data<saturn_state>();
5760
57615708   offset &= (0xfff) >> (2);
5762
5763   return state->m_vdp2_cram[offset];
5709   return m_vdp2_cram[offset];
57645710}
57655711
57665712
57675713
57685714
5769WRITE32_HANDLER ( saturn_vdp2_cram_w )
5715WRITE32_MEMBER ( saturn_state::saturn_vdp2_cram_w )
57705716{
5771   saturn_state *state = space.machine().driver_data<saturn_state>();
57725717   int r,g,b;
57735718   UINT8 cmode0;
57745719
57755720   cmode0 = (STV_VDP2_CRMD & 3) == 0;
57765721
57775722   offset &= (0xfff) >> (2);
5778   COMBINE_DATA(&state->m_vdp2_cram[offset]);
5723   COMBINE_DATA(&m_vdp2_cram[offset]);
57795724
57805725   switch( STV_VDP2_CRMD )
57815726   {
r20790r20791
57855730      {
57865731         //offset &= (0xfff) >> 2;
57875732
5788         b = ((state->m_vdp2_cram[offset] & 0x00ff0000) >> 16);
5789         g = ((state->m_vdp2_cram[offset] & 0x0000ff00) >> 8);
5790         r = ((state->m_vdp2_cram[offset] & 0x000000ff) >> 0);
5733         b = ((m_vdp2_cram[offset] & 0x00ff0000) >> 16);
5734         g = ((m_vdp2_cram[offset] & 0x0000ff00) >> 8);
5735         r = ((m_vdp2_cram[offset] & 0x000000ff) >> 0);
57915736         palette_set_color(space.machine(),offset,MAKE_RGB(r,g,b));
57925737         palette_set_color(space.machine(),offset^0x400,MAKE_RGB(r,g,b));
57935738      }
r20790r20791
57985743      {
57995744         offset &= (0xfff) >> (cmode0+2);
58005745
5801         b = ((state->m_vdp2_cram[offset] & 0x00007c00) >> 10);
5802         g = ((state->m_vdp2_cram[offset] & 0x000003e0) >> 5);
5803         r = ((state->m_vdp2_cram[offset] & 0x0000001f) >> 0);
5746         b = ((m_vdp2_cram[offset] & 0x00007c00) >> 10);
5747         g = ((m_vdp2_cram[offset] & 0x000003e0) >> 5);
5748         r = ((m_vdp2_cram[offset] & 0x0000001f) >> 0);
58045749         palette_set_color_rgb(space.machine(),(offset*2)+1,pal5bit(r),pal5bit(g),pal5bit(b));
58055750         if(cmode0)
58065751            palette_set_color_rgb(space.machine(),((offset*2)+1)^0x400,pal5bit(r),pal5bit(g),pal5bit(b));
58075752
5808         b = ((state->m_vdp2_cram[offset] & 0x7c000000) >> 26);
5809         g = ((state->m_vdp2_cram[offset] & 0x03e00000) >> 21);
5810         r = ((state->m_vdp2_cram[offset] & 0x001f0000) >> 16);
5753         b = ((m_vdp2_cram[offset] & 0x7c000000) >> 26);
5754         g = ((m_vdp2_cram[offset] & 0x03e00000) >> 21);
5755         r = ((m_vdp2_cram[offset] & 0x001f0000) >> 16);
58115756         palette_set_color_rgb(space.machine(),offset*2,pal5bit(r),pal5bit(g),pal5bit(b));
58125757         if(cmode0)
58135758            palette_set_color_rgb(space.machine(),(offset*2)^0x400,pal5bit(r),pal5bit(g),pal5bit(b));
r20790r20791
58165761   }
58175762}
58185763
5819static void refresh_palette_data(running_machine &machine)
5764void saturn_state::refresh_palette_data( void )
58205765{
5821   saturn_state *state = machine.driver_data<saturn_state>();
58225766   int r,g,b;
58235767   int c_i;
58245768   UINT8 bank;
r20790r20791
58305774      {
58315775         for(c_i=0;c_i<0x400;c_i++)
58325776         {
5833            b = ((state->m_vdp2_cram[c_i] & 0x00ff0000) >> 16);
5834            g = ((state->m_vdp2_cram[c_i] & 0x0000ff00) >> 8);
5835            r = ((state->m_vdp2_cram[c_i] & 0x000000ff) >> 0);
5836            palette_set_color(machine,c_i,MAKE_RGB(r,g,b));
5837            palette_set_color(machine,c_i+0x400,MAKE_RGB(r,g,b));
5777            b = ((m_vdp2_cram[c_i] & 0x00ff0000) >> 16);
5778            g = ((m_vdp2_cram[c_i] & 0x0000ff00) >> 8);
5779            r = ((m_vdp2_cram[c_i] & 0x000000ff) >> 0);
5780            palette_set_color(machine(),c_i,MAKE_RGB(r,g,b));
5781            palette_set_color(machine(),c_i+0x400,MAKE_RGB(r,g,b));
58385782         }
58395783      }
58405784      break;
r20790r20791
58445788         {
58455789            for(c_i=0;c_i<0x400;c_i++)
58465790            {
5847               b = ((state->m_vdp2_cram[c_i] & 0x00007c00) >> 10);
5848               g = ((state->m_vdp2_cram[c_i] & 0x000003e0) >> 5);
5849               r = ((state->m_vdp2_cram[c_i] & 0x0000001f) >> 0);
5850               palette_set_color_rgb(machine,(c_i*2)+1+bank*0x400,pal5bit(r),pal5bit(g),pal5bit(b));
5851               b = ((state->m_vdp2_cram[c_i] & 0x7c000000) >> 26);
5852               g = ((state->m_vdp2_cram[c_i] & 0x03e00000) >> 21);
5853               r = ((state->m_vdp2_cram[c_i] & 0x001f0000) >> 16);
5854               palette_set_color_rgb(machine,c_i*2+bank*0x400,pal5bit(r),pal5bit(g),pal5bit(b));
5791               b = ((m_vdp2_cram[c_i] & 0x00007c00) >> 10);
5792               g = ((m_vdp2_cram[c_i] & 0x000003e0) >> 5);
5793               r = ((m_vdp2_cram[c_i] & 0x0000001f) >> 0);
5794               palette_set_color_rgb(machine(),(c_i*2)+1+bank*0x400,pal5bit(r),pal5bit(g),pal5bit(b));
5795               b = ((m_vdp2_cram[c_i] & 0x7c000000) >> 26);
5796               g = ((m_vdp2_cram[c_i] & 0x03e00000) >> 21);
5797               r = ((m_vdp2_cram[c_i] & 0x001f0000) >> 16);
5798               palette_set_color_rgb(machine(),c_i*2+bank*0x400,pal5bit(r),pal5bit(g),pal5bit(b));
58555799            }
58565800         }
58575801      }
r20790r20791
58605804      {
58615805         for(c_i=0;c_i<0x800;c_i++)
58625806         {
5863            b = ((state->m_vdp2_cram[c_i] & 0x00007c00) >> 10);
5864            g = ((state->m_vdp2_cram[c_i] & 0x000003e0) >> 5);
5865            r = ((state->m_vdp2_cram[c_i] & 0x0000001f) >> 0);
5866            palette_set_color_rgb(machine,(c_i*2)+1,pal5bit(r),pal5bit(g),pal5bit(b));
5867            b = ((state->m_vdp2_cram[c_i] & 0x7c000000) >> 26);
5868            g = ((state->m_vdp2_cram[c_i] & 0x03e00000) >> 21);
5869            r = ((state->m_vdp2_cram[c_i] & 0x001f0000) >> 16);
5870            palette_set_color_rgb(machine,c_i*2,pal5bit(r),pal5bit(g),pal5bit(b));
5807            b = ((m_vdp2_cram[c_i] & 0x00007c00) >> 10);
5808            g = ((m_vdp2_cram[c_i] & 0x000003e0) >> 5);
5809            r = ((m_vdp2_cram[c_i] & 0x0000001f) >> 0);
5810            palette_set_color_rgb(machine(),(c_i*2)+1,pal5bit(r),pal5bit(g),pal5bit(b));
5811            b = ((m_vdp2_cram[c_i] & 0x7c000000) >> 26);
5812            g = ((m_vdp2_cram[c_i] & 0x03e00000) >> 21);
5813            r = ((m_vdp2_cram[c_i] & 0x001f0000) >> 16);
5814            palette_set_color_rgb(machine(),c_i*2,pal5bit(r),pal5bit(g),pal5bit(b));
58715815         }
58725816      }
58735817      break;
58745818   }
58755819}
58765820
5877WRITE16_HANDLER ( saturn_vdp2_regs_w )
5821WRITE16_MEMBER ( saturn_state::saturn_vdp2_regs_w )
58785822{
5879   saturn_state *state = space.machine().driver_data<saturn_state>();
5880   COMBINE_DATA(&state->m_vdp2_regs[offset]);
5823   COMBINE_DATA(&m_vdp2_regs[offset]);
58815824
5882   if(state->m_vdp2.old_crmd != STV_VDP2_CRMD)
5825   if(m_vdp2.old_crmd != STV_VDP2_CRMD)
58835826   {
5884      state->m_vdp2.old_crmd = STV_VDP2_CRMD;
5885      refresh_palette_data(space.machine());
5827      m_vdp2.old_crmd = STV_VDP2_CRMD;
5828      refresh_palette_data();
58865829   }
5887   if(state->m_vdp2.old_tvmd != STV_VDP2_TVMD)
5830   if(m_vdp2.old_tvmd != STV_VDP2_TVMD)
58885831   {
5889      state->m_vdp2.old_tvmd = STV_VDP2_TVMD;
5890      stv_vdp2_dynamic_res_change(space.machine());
5832      m_vdp2.old_tvmd = STV_VDP2_TVMD;
5833      stv_vdp2_dynamic_res_change();
58915834   }
58925835
58935836   if(STV_VDP2_VRAMSZ)
58945837      printf("VDP2 sets up 8 Mbit VRAM!\n");
58955838}
58965839
5897static int get_hblank_duration(running_machine &machine)
5840int saturn_state::get_hblank_duration( void )
58985841{
5899   saturn_state *state = machine.driver_data<saturn_state>();
59005842   int res;
59015843
59025844   res = (STV_VDP2_HRES & 1) ? 455 : 427;
r20790r20791
59105852
59115853/*some vblank lines measurements (according to Charles MacDonald)*/
59125854/* TODO: interlace mode "eats" one line, should be 262.5 */
5913static int get_vblank_duration(running_machine &machine)
5855int saturn_state::get_vblank_duration( void )
59145856{
5915   saturn_state *state = machine.driver_data<saturn_state>();
59165857   int res;
59175858
5918   res = (state->m_vdp2.pal) ? 313 : 263;
5859   res = (m_vdp2.pal) ? 313 : 263;
59195860
59205861   /* compensate for interlacing */
59215862   if((STV_VDP2_LSMD & 3) == 3)
r20790r20791
59275868   return res;
59285869}
59295870
5930static int get_pixel_clock(running_machine &machine)
5871int saturn_state::get_pixel_clock( void )
59315872{
5932   saturn_state *state = machine.driver_data<saturn_state>();
59335873   int res,divider;
59345874
5935   res = state->m_vdp2.dotsel ? MASTER_CLOCK_352 : MASTER_CLOCK_320;
5875   res = m_vdp2.dotsel ? MASTER_CLOCK_352 : MASTER_CLOCK_320;
59365876   /* TODO: divider is ALWAYS 8, this thing is just to over-compensate for MAME framework faults ... */
59375877   divider = 8;
59385878
r20790r20791
59485888   return res/divider;
59495889}
59505890
5951static UINT8 get_hblank(running_machine &machine)
5891UINT8 saturn_state::get_hblank( void )
59525892{
5953   const rectangle &visarea = machine.primary_screen->visible_area();
5954   int cur_h = machine.primary_screen->hpos();
5893   const rectangle &visarea = machine().primary_screen->visible_area();
5894   int cur_h = machine().primary_screen->hpos();
59555895
59565896   if (cur_h > visarea.max_x) //TODO
59575897      return 1;
r20790r20791
59595899   return 0;
59605900}
59615901
5962UINT8 get_vblank(running_machine &machine)
5902UINT8 saturn_state::get_vblank( void )
59635903{
5964   saturn_state *state = machine.driver_data<saturn_state>();
59655904   int cur_v,vblank;
5966   cur_v = machine.primary_screen->vpos();
5905   cur_v = machine().primary_screen->vpos();
59675906
5968   vblank = (state->m_vdp2.pal) ? 288 : 240;
5907   vblank = (m_vdp2.pal) ? 288 : 240;
59695908
59705909   if((STV_VDP2_LSMD & 3) == 3)
59715910      vblank<<=1;
r20790r20791
59765915   return 0;
59775916}
59785917
5979static UINT8 get_odd_bit(running_machine &machine)
5918UINT8 saturn_state::get_odd_bit( void )
59805919{
5981   saturn_state *state = machine.driver_data<saturn_state>();
59825920   int cur_v;
5983   cur_v = machine.primary_screen->vpos();
5921   cur_v = machine().primary_screen->vpos();
59845922
59855923   if(STV_VDP2_HRES & 4) //exclusive monitor mode makes this bit to be always 1
59865924      return 1;
r20790r20791
59945932   return 0;
59955933}
59965934
5997static void stv_vdp2_state_save_postload(running_machine &machine)
5935void saturn_state::stv_vdp2_state_save_postload( void )
59985936{
5999   saturn_state *state = machine.driver_data<saturn_state>();
6000   UINT8 *gfxdata = state->m_vdp2.gfx_decode;
5937   UINT8 *gfxdata = m_vdp2.gfx_decode;
60015938   int offset;
60025939   UINT32 data;
60035940
60045941   for ( offset = 0; offset < 0x100000/4; offset++ )
60055942   {
6006      data = state->m_vdp2_vram[offset];
5943      data = m_vdp2_vram[offset];
60075944      /* put in gfx region for easy decoding */
60085945      gfxdata[offset*4+0] = (data & 0xff000000) >> 24;
60095946      gfxdata[offset*4+1] = (data & 0x00ff0000) >> 16;
60105947      gfxdata[offset*4+2] = (data & 0x0000ff00) >> 8;
60115948      gfxdata[offset*4+3] = (data & 0x000000ff) >> 0;
60125949
6013      machine.gfx[0]->mark_dirty(offset/8);
6014      machine.gfx[1]->mark_dirty(offset/8);
6015      machine.gfx[2]->mark_dirty(offset/8);
6016      machine.gfx[3]->mark_dirty(offset/8);
5950      machine().gfx[0]->mark_dirty(offset/8);
5951      machine().gfx[1]->mark_dirty(offset/8);
5952      machine().gfx[2]->mark_dirty(offset/8);
5953      machine().gfx[3]->mark_dirty(offset/8);
60175954
60185955      /* 8-bit tiles overlap, so this affects the previous one as well */
60195956      if (offset/8 != 0)
60205957      {
6021         machine.gfx[2]->mark_dirty(offset/8 - 1);
6022         machine.gfx[3]->mark_dirty(offset/8 - 1);
5958         machine().gfx[2]->mark_dirty(offset/8 - 1);
5959         machine().gfx[3]->mark_dirty(offset/8 - 1);
60235960      }
60245961
60255962   }
r20790r20791
60285965   stv_rbg_cache_data.is_cache_dirty = 3;
60295966   memset( &stv_vdp2_layer_data_placement, 0, sizeof(stv_vdp2_layer_data_placement));
60305967
6031   refresh_palette_data(machine);
5968   refresh_palette_data();
60325969}
60335970
6034static void stv_vdp2_exit (running_machine &machine)
5971void saturn_state::stv_vdp2_exit ( void )
60355972{
6036   saturn_state *state = machine.driver_data<saturn_state>();
6037   state->m_vdp2.roz_bitmap[0].reset();
6038   state->m_vdp2.roz_bitmap[1].reset();
5973   m_vdp2.roz_bitmap[0].reset();
5974   m_vdp2.roz_bitmap[1].reset();
60395975}
60405976
6041static int stv_vdp2_start (running_machine &machine)
5977int saturn_state::stv_vdp2_start ( void )
60425978{
6043   saturn_state *state = machine.driver_data<saturn_state>();
6044   machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(stv_vdp2_exit), &machine));
5979   machine().add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(saturn_state::stv_vdp2_exit), this));
60455980
6046   state->m_vdp2_regs = auto_alloc_array_clear(machine, UINT16, 0x040000/2 );
6047   state->m_vdp2_vram = auto_alloc_array_clear(machine, UINT32, 0x100000/4 );
6048   state->m_vdp2_cram = auto_alloc_array_clear(machine, UINT32, 0x080000/4 );
6049   state->m_vdp2.gfx_decode = auto_alloc_array(machine, UINT8, 0x100000 );
5981   m_vdp2_regs = auto_alloc_array_clear(machine(), UINT16, 0x040000/2 );
5982   m_vdp2_vram = auto_alloc_array_clear(machine(), UINT32, 0x100000/4 );
5983   m_vdp2_cram = auto_alloc_array_clear(machine(), UINT32, 0x080000/4 );
5984   m_vdp2.gfx_decode = auto_alloc_array(machine(), UINT8, 0x100000 );
60505985
6051//  machine.gfx[0]->granularity()=4;
6052//  machine.gfx[1]->granularity()=4;
5986//  machine().gfx[0]->granularity()=4;
5987//  machine().gfx[1]->granularity()=4;
60535988
60545989   memset( &stv_rbg_cache_data, 0, sizeof(stv_rbg_cache_data));
60555990   stv_rbg_cache_data.is_cache_dirty = 3;
60565991   memset( &stv_vdp2_layer_data_placement, 0, sizeof(stv_vdp2_layer_data_placement));
60575992
6058   state_save_register_global_pointer(machine, state->m_vdp2_regs, 0x040000/2);
6059   state_save_register_global_pointer(machine, state->m_vdp2_vram, 0x100000/4);
6060   state_save_register_global_pointer(machine, state->m_vdp2_cram, 0x080000/4);
6061   machine.save().register_postload(save_prepost_delegate(FUNC(stv_vdp2_state_save_postload), &machine));
5993   state_save_register_global_pointer(machine(), m_vdp2_regs, 0x040000/2);
5994   state_save_register_global_pointer(machine(), m_vdp2_vram, 0x100000/4);
5995   state_save_register_global_pointer(machine(), m_vdp2_cram, 0x080000/4);
5996   machine().save().register_postload(save_prepost_delegate(FUNC(saturn_state::stv_vdp2_state_save_postload), this));
60625997
60635998   return 0;
60645999}
r20790r20791
60676002VIDEO_START_MEMBER(saturn_state,stv_vdp2)
60686003{
60696004   machine().primary_screen->register_screen_bitmap(m_tmpbitmap);
6070   stv_vdp2_start(machine());
6071   stv_vdp1_start(machine());
6005   stv_vdp2_start();
6006   stv_vdp1_start();
60726007   vdpdebug.l_en = 0xff;
60736008   vdpdebug.error = 0xffffffff;
60746009   vdpdebug.roz = 0;
r20790r20791
60826017   machine().gfx[7]->set_source(m_vdp1.gfx_decode);
60836018}
60846019
6085void stv_vdp2_dynamic_res_change(running_machine &machine)
6020void saturn_state::stv_vdp2_dynamic_res_change( void )
60866021{
6087   saturn_state *state = machine.driver_data<saturn_state>();
60886022   const int d_vres[4] = { 224, 240, 256, 256 };
60896023   const int d_hres[4] = { 320, 352, 640, 704 };
60906024   int horz_res,vert_res;
60916025   int vres_mask;
60926026
6093   vres_mask = (state->m_vdp2.pal << 1)|1; //PAL uses mask 3, NTSC uses mask 1
6027   vres_mask = (m_vdp2.pal << 1)|1; //PAL uses mask 3, NTSC uses mask 1
60946028   vert_res = d_vres[STV_VDP2_VRES & vres_mask];
60956029
60966030   if((STV_VDP2_VRES & 3) == 3)
r20790r20791
61106044      attoseconds_t refresh;;
61116045      rectangle visarea(0, horz_res-1, 0, vert_res-1);
61126046
6113      vblank_period = get_vblank_duration(machine);
6114      hblank_period = get_hblank_duration(machine);
6115      refresh  = HZ_TO_ATTOSECONDS(get_pixel_clock(machine)) * (hblank_period) * vblank_period;
6047      vblank_period = get_vblank_duration();
6048      hblank_period = get_hblank_duration();
6049      refresh  = HZ_TO_ATTOSECONDS(get_pixel_clock()) * (hblank_period) * vblank_period;
61166050      //printf("%d %d %d %d\n",horz_res,vert_res,horz_res+hblank_period,vblank_period);
61176051
6118      machine.primary_screen->configure((hblank_period), (vblank_period), visarea, refresh );
6052      machine().primary_screen->configure((hblank_period), (vblank_period), visarea, refresh );
61196053   }
6120//  machine.primary_screen->set_visible_area(0*8, horz_res-1,0*8, vert_res-1);
6121   //if(LOG_VDP2) popmessage("%04d %04d",horz_res-1,vert-1);
6054//  machine().primary_screen->set_visible_area(0*8, horz_res-1,0*8, vert_res-1);
61226055}
61236056
61246057/*This is for calculating the rgb brightness*/
61256058/*TODO: Optimize this...*/
6126static void stv_vdp2_fade_effects(running_machine &machine)
6059void saturn_state::stv_vdp2_fade_effects( void )
61276060{
6128   saturn_state *state = machine.driver_data<saturn_state>();
61296061   /*
61306062   Note:We have to use temporary storages because palette_get_color must use
61316063   variables setted with unsigned int8
r20790r20791
61386070   for(i=0;i<2048;i++)
61396071   {
61406072      /*Fade A*/
6141      color = palette_get_color(machine, i);
6073      color = palette_get_color(machine(), i);
61426074      t_r = (STV_VDP2_COAR & 0x100) ? (RGB_RED(color) - (0x100 - (STV_VDP2_COAR & 0xff))) : ((STV_VDP2_COAR & 0xff) + RGB_RED(color));
61436075      t_g = (STV_VDP2_COAG & 0x100) ? (RGB_GREEN(color) - (0x100 - (STV_VDP2_COAG & 0xff))) : ((STV_VDP2_COAG & 0xff) + RGB_GREEN(color));
61446076      t_b = (STV_VDP2_COAB & 0x100) ? (RGB_BLUE(color) - (0x100 - (STV_VDP2_COAB & 0xff))) : ((STV_VDP2_COAB & 0xff) + RGB_BLUE(color));
r20790r20791
61516083      r = t_r;
61526084      g = t_g;
61536085      b = t_b;
6154      palette_set_color(machine,i+(2048*1),MAKE_RGB(r,g,b));
6086      palette_set_color(machine(),i+(2048*1),MAKE_RGB(r,g,b));
61556087
61566088      /*Fade B*/
6157      color = palette_get_color(machine, i);
6089      color = palette_get_color(machine(), i);
61586090      t_r = (STV_VDP2_COBR & 0x100) ? (RGB_RED(color) - (0xff - (STV_VDP2_COBR & 0xff))) : ((STV_VDP2_COBR & 0xff) + RGB_RED(color));
61596091      t_g = (STV_VDP2_COBG & 0x100) ? (RGB_GREEN(color) - (0xff - (STV_VDP2_COBG & 0xff))) : ((STV_VDP2_COBG & 0xff) + RGB_GREEN(color));
61606092      t_b = (STV_VDP2_COBB & 0x100) ? (RGB_BLUE(color) - (0xff - (STV_VDP2_COBB & 0xff))) : ((STV_VDP2_COBB & 0xff) + RGB_BLUE(color));
r20790r20791
61676099      r = t_r;
61686100      g = t_g;
61696101      b = t_b;
6170      palette_set_color(machine,i+(2048*2),MAKE_RGB(r,g,b));
6102      palette_set_color(machine(),i+(2048*2),MAKE_RGB(r,g,b));
61716103   }
61726104   //popmessage("%04x %04x %04x %04x %04x %04x",STV_VDP2_COAR,STV_VDP2_COAG,STV_VDP2_COAB,STV_VDP2_COBR,STV_VDP2_COBG,STV_VDP2_COBB);
61736105}
r20790r20791
62056137                  (0 = OR,1 = AND)
62066138******************************************************************************************/
62076139
6208static void stv_vdp2_get_window0_coordinates(running_machine &machine,UINT16 *s_x, UINT16 *e_x, UINT16 *s_y, UINT16 *e_y)
6140void saturn_state::stv_vdp2_get_window0_coordinates(UINT16 *s_x, UINT16 *e_x, UINT16 *s_y, UINT16 *e_y)
62096141{
6210   saturn_state *state = machine.driver_data<saturn_state>();
6211
62126142   /*W0*/
62136143   switch(STV_VDP2_LSMD & 3)
62146144   {
r20790r20791
62526182   }
62536183}
62546184
6255static void stv_vdp2_get_window1_coordinates(running_machine &machine,UINT16 *s_x, UINT16 *e_x, UINT16 *s_y, UINT16 *e_y)
6185void saturn_state::stv_vdp2_get_window1_coordinates(UINT16 *s_x, UINT16 *e_x, UINT16 *s_y, UINT16 *e_y)
62566186{
6257   saturn_state *state = machine.driver_data<saturn_state>();
6258
62596187   /*W1*/
62606188   switch(STV_VDP2_LSMD & 3)
62616189   {
r20790r20791
63006228
63016229}
63026230
6303static int get_window_pixel(UINT16 s_x,UINT16 e_x,UINT16 s_y,UINT16 e_y,int x, int y,UINT8 win_num)
6231int saturn_state::get_window_pixel(UINT16 s_x,UINT16 e_x,UINT16 s_y,UINT16 e_y,int x, int y,UINT8 win_num)
63046232{
63056233   if(stv2_current_tilemap.window_control & (2 << win_num))
63066234   {
r20790r20791
63336261   return 0;
63346262}
63356263
6336static int stv_vdp2_window_process(running_machine &machine,int x,int y)
6264int saturn_state::stv_vdp2_window_process(int x,int y)
63376265{
63386266   UINT16 s_x=0,e_x=0,s_y=0,e_y=0;
63396267   UINT8 w0_pix, w1_pix;
r20790r20791
63416269   if ((stv2_current_tilemap.window_control & 6) == 0)
63426270      return 0;
63436271
6344   stv_vdp2_get_window0_coordinates(machine,&s_x, &e_x, &s_y, &e_y);
6272   stv_vdp2_get_window0_coordinates(&s_x, &e_x, &s_y, &e_y);
63456273   w0_pix = get_window_pixel(s_x,e_x,s_y,e_y,x,y,0);
63466274
6347   stv_vdp2_get_window1_coordinates(machine,&s_x, &e_x, &s_y, &e_y);
6275   stv_vdp2_get_window1_coordinates(&s_x, &e_x, &s_y, &e_y);
63486276   w1_pix = get_window_pixel(s_x,e_x,s_y,e_y,x,y,1);
63496277
63506278   return stv2_current_tilemap.window_control & 1 ? (w0_pix & w1_pix) : (w0_pix | w1_pix);
63516279}
63526280
6353static int stv_vdp2_apply_window_on_layer(running_machine &machine,rectangle &cliprect)
6281int saturn_state::stv_vdp2_apply_window_on_layer(rectangle &cliprect)
63546282{
6355   //saturn_state *state = machine.driver_data<saturn_state>();
63566283   UINT16 s_x=0,e_x=0,s_y=0,e_y=0;
63576284
63586285   if ( stv2_current_tilemap.window_control == 0x12 )
63596286   {
63606287      /* w0, transparent outside supported */
6361      stv_vdp2_get_window0_coordinates(machine,&s_x, &e_x, &s_y, &e_y);
6288      stv_vdp2_get_window0_coordinates(&s_x, &e_x, &s_y, &e_y);
63626289
63636290      if ( s_x > cliprect.min_x ) cliprect.min_x = s_x;
63646291      if ( e_x < cliprect.max_x ) cliprect.max_x = e_x;
r20790r20791
63706297   else if ( stv2_current_tilemap.window_control == 0x24 )
63716298   {
63726299      /* w1, transparent outside supported */
6373      stv_vdp2_get_window1_coordinates(machine,&s_x, &e_x, &s_y, &e_y);
6300      stv_vdp2_get_window1_coordinates(&s_x, &e_x, &s_y, &e_y);
63746301
63756302      if ( s_x > cliprect.min_x ) cliprect.min_x = s_x;
63766303      if ( e_x < cliprect.max_x ) cliprect.max_x = e_x;
r20790r20791
63906317static int      stv_sprite_priorities_usage_valid;
63916318static UINT8    stv_sprite_priorities_in_fb_line[512][8];
63926319
6393static void draw_sprites(running_machine &machine, bitmap_rgb32 &bitmap, const rectangle &cliprect, UINT8 pri)
6320void saturn_state::draw_sprites(bitmap_rgb32 &bitmap, const rectangle &cliprect, UINT8 pri)
63946321{
6395   saturn_state *state = machine.driver_data<saturn_state>();
63966322   int x,y,r,g,b;
63976323   int i;
63986324   UINT16 pix;
r20790r20791
64836409   }
64846410
64856411   /* framebuffer interlace */
6486   if ( (STV_VDP2_LSMD == 3) && state->m_vdp1.framebuffer_double_interlace == 0 )
6412   if ( (STV_VDP2_LSMD == 3) && m_vdp1.framebuffer_double_interlace == 0 )
64876413      interlace_framebuffer = 1;
64886414   else
64896415      interlace_framebuffer = 0;
r20790r20791
65056431                                 (STV_VDP2_SPSWA * 0x40);
65066432   mycliprect = cliprect;
65076433
6508   stv_vdp2_apply_window_on_layer(machine,mycliprect);
6434   stv_vdp2_apply_window_on_layer(mycliprect);
65096435
65106436   if (interlace_framebuffer == 0 && double_x == 0 )
65116437   {
r20790r20791
65176443               if (stv_sprite_priorities_in_fb_line[y][pri] == 0)
65186444                  continue;
65196445
6520            framebuffer_line = state->m_vdp1.framebuffer_display_lines[y];
6446            framebuffer_line = m_vdp1.framebuffer_display_lines[y];
65216447            bitmap_line = &bitmap.pix32(y);
65226448
65236449            for ( x = mycliprect.min_x; x <= mycliprect.max_x; x++ )
r20790r20791
65406466                  r = pal5bit( pix & 0x001f);
65416467                  if ( color_offset_pal )
65426468                  {
6543                     stv_vdp2_compute_color_offset( machine, &r, &g, &b, STV_VDP2_SPCOSL );
6469                     stv_vdp2_compute_color_offset( &r, &g, &b, STV_VDP2_SPCOSL );
65446470                  }
65456471
65466472                  bitmap_line[x] = MAKE_RGB(r, g, b);
r20790r20791
65726498                        pix += (STV_VDP2_SPCAOS << 8);
65736499                        pix &= 0x7ff;
65746500                        pix += color_offset_pal;
6575                        bitmap_line[x] = machine.pens[ pix ];
6501                        bitmap_line[x] = machine().pens[ pix ];
65766502                     }
65776503                  }
65786504
r20790r20791
65976523               if (stv_sprite_priorities_in_fb_line[y][pri] == 0)
65986524                  continue;
65996525
6600            framebuffer_line = state->m_vdp1.framebuffer_display_lines[y];
6526            framebuffer_line = m_vdp1.framebuffer_display_lines[y];
66016527            bitmap_line = &bitmap.pix32(y);
66026528
66036529            for ( x = mycliprect.min_x; x <= mycliprect.max_x; x++ )
r20790r20791
66176543                  r = pal5bit( pix & 0x001f);
66186544                  if ( color_offset_pal )
66196545                  {
6620                     stv_vdp2_compute_color_offset( machine, &r, &g, &b, STV_VDP2_SPCOSL );
6546                     stv_vdp2_compute_color_offset( &r, &g, &b, STV_VDP2_SPCOSL );
66216547                  }
66226548                  ccr = sprite_ccr[0];
66236549                  if ( STV_VDP2_CCMD )
r20790r20791
66696595                        {
66706596                           if ( STV_VDP2_CCMD )
66716597                           {
6672                              bitmap_line[x] = stv_add_blend( bitmap_line[x], machine.pens[pix] );
6598                              bitmap_line[x] = stv_add_blend( bitmap_line[x], machine().pens[pix] );
66736599                           }
66746600                           else
66756601                           {
6676                              bitmap_line[x] = alpha_blend_r32( bitmap_line[x], machine.pens[pix], ((UINT16)(0x1f-ccr)*0xff)/0x1f );
6602                              bitmap_line[x] = alpha_blend_r32( bitmap_line[x], machine().pens[pix], ((UINT16)(0x1f-ccr)*0xff)/0x1f );
66776603                           }
66786604                        }
66796605                        else
6680                           bitmap_line[x] = machine.pens[pix];
6606                           bitmap_line[x] = machine().pens[pix];
66816607                     }
66826608                  }
66836609
r20790r20791
67036629            if (stv_sprite_priorities_in_fb_line[y][pri] == 0)
67046630               continue;
67056631
6706         framebuffer_line = state->m_vdp1.framebuffer_display_lines[y];
6632         framebuffer_line = m_vdp1.framebuffer_display_lines[y];
67076633         if ( interlace_framebuffer == 0 )
67086634         {
67096635            bitmap_line = &bitmap.pix32(y);
r20790r20791
67316657               r = pal5bit( pix & 0x001f);
67326658               if ( color_offset_pal )
67336659               {
6734                  stv_vdp2_compute_color_offset( machine, &r, &g, &b, STV_VDP2_SPCOSL );
6660                  stv_vdp2_compute_color_offset( &r, &g, &b, STV_VDP2_SPCOSL );
67356661               }
67366662               if ( alpha_enabled == 0 )
67376663               {
r20790r20791
68336759                     {
68346760                        if(double_x)
68356761                        {
6836                           bitmap_line[x*2] = machine.pens[ pix ];
6837                           if ( interlace_framebuffer == 1 ) bitmap_line2[x*2] = machine.pens[ pix ];
6838                           bitmap_line[x*2+1] = machine.pens[ pix ];
6839                           if ( interlace_framebuffer == 1 ) bitmap_line2[x*2+1] = machine.pens[ pix ];
6762                           bitmap_line[x*2] = machine().pens[ pix ];
6763                           if ( interlace_framebuffer == 1 ) bitmap_line2[x*2] = machine().pens[ pix ];
6764                           bitmap_line[x*2+1] = machine().pens[ pix ];
6765                           if ( interlace_framebuffer == 1 ) bitmap_line2[x*2+1] = machine().pens[ pix ];
68406766                        }
68416767                        else
68426768                        {
6843                           bitmap_line[x] = machine.pens[ pix ];
6844                           if ( interlace_framebuffer == 1 ) bitmap_line2[x] = machine.pens[ pix ];
6769                           bitmap_line[x] = machine().pens[ pix ];
6770                           if ( interlace_framebuffer == 1 ) bitmap_line2[x] = machine().pens[ pix ];
68456771                        }
68466772                     }
68476773                     else // alpha_blend == 1
r20790r20791
68506776                        {
68516777                           if(double_x)
68526778                           {
6853                              bitmap_line[x*2] = stv_add_blend( bitmap_line[x*2], machine.pens[pix] );
6854                              if ( interlace_framebuffer == 1 ) bitmap_line2[x*2] = stv_add_blend( bitmap_line2[x], machine.pens[pix] );
6855                              bitmap_line[x*2+1] = stv_add_blend( bitmap_line[x*2+1], machine.pens[pix] );
6856                              if ( interlace_framebuffer == 1 ) bitmap_line2[x*2+1] = stv_add_blend( bitmap_line2[x], machine.pens[pix] );
6779                              bitmap_line[x*2] = stv_add_blend( bitmap_line[x*2], machine().pens[pix] );
6780                              if ( interlace_framebuffer == 1 ) bitmap_line2[x*2] = stv_add_blend( bitmap_line2[x], machine().pens[pix] );
6781                              bitmap_line[x*2+1] = stv_add_blend( bitmap_line[x*2+1], machine().pens[pix] );
6782                              if ( interlace_framebuffer == 1 ) bitmap_line2[x*2+1] = stv_add_blend( bitmap_line2[x], machine().pens[pix] );
68576783                           }
68586784                           else
68596785                           {
6860                              bitmap_line[x] = stv_add_blend( bitmap_line[x], machine.pens[pix] );
6861                              if ( interlace_framebuffer == 1 ) bitmap_line2[x] = stv_add_blend( bitmap_line2[x], machine.pens[pix] );
6786                              bitmap_line[x] = stv_add_blend( bitmap_line[x], machine().pens[pix] );
6787                              if ( interlace_framebuffer == 1 ) bitmap_line2[x] = stv_add_blend( bitmap_line2[x], machine().pens[pix] );
68626788                           }
68636789                        }
68646790                        else
68656791                        {
68666792                           if(double_x)
68676793                           {
6868                              bitmap_line[x*2] = alpha_blend_r32( bitmap_line[x*2], machine.pens[pix], ((UINT16)(0x1f-ccr)*0xff)/0x1f );
6869                              if ( interlace_framebuffer == 1 ) bitmap_line2[x*2] = alpha_blend_r32( bitmap_line2[x], machine.pens[pix], ((UINT16)(0x1f-ccr)*0xff)/0x1f );
6870                              bitmap_line[x*2+1] = alpha_blend_r32( bitmap_line[x*2+1], machine.pens[pix], ((UINT16)(0x1f-ccr)*0xff)/0x1f );
6871                              if ( interlace_framebuffer == 1 ) bitmap_line2[x*2+1] = alpha_blend_r32( bitmap_line2[x], machine.pens[pix], ((UINT16)(0x1f-ccr)*0xff)/0x1f );
6794                              bitmap_line[x*2] = alpha_blend_r32( bitmap_line[x*2], machine().pens[pix], ((UINT16)(0x1f-ccr)*0xff)/0x1f );
6795                              if ( interlace_framebuffer == 1 ) bitmap_line2[x*2] = alpha_blend_r32( bitmap_line2[x], machine().pens[pix], ((UINT16)(0x1f-ccr)*0xff)/0x1f );
6796                              bitmap_line[x*2+1] = alpha_blend_r32( bitmap_line[x*2+1], machine().pens[pix], ((UINT16)(0x1f-ccr)*0xff)/0x1f );
6797                              if ( interlace_framebuffer == 1 ) bitmap_line2[x*2+1] = alpha_blend_r32( bitmap_line2[x], machine().pens[pix], ((UINT16)(0x1f-ccr)*0xff)/0x1f );
68726798                           }
68736799                           else
68746800                           {
6875                              bitmap_line[x] = alpha_blend_r32( bitmap_line[x], machine.pens[pix], ((UINT16)(0x1f-ccr)*0xff)/0x1f );
6876                              if ( interlace_framebuffer == 1 ) bitmap_line2[x] = alpha_blend_r32( bitmap_line2[x], machine.pens[pix], ((UINT16)(0x1f-ccr)*0xff)/0x1f );
6801                              bitmap_line[x] = alpha_blend_r32( bitmap_line[x], machine().pens[pix], ((UINT16)(0x1f-ccr)*0xff)/0x1f );
6802                              if ( interlace_framebuffer == 1 ) bitmap_line2[x] = alpha_blend_r32( bitmap_line2[x], machine().pens[pix], ((UINT16)(0x1f-ccr)*0xff)/0x1f );
68776803                           }
68786804                        }
68796805                     }
r20790r20791
69076833
69086834UINT32 saturn_state::screen_update_stv_vdp2(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
69096835{
6910   saturn_state *state = machine().driver_data<saturn_state>();
6836   stv_vdp2_fade_effects();
69116837
6912   stv_vdp2_fade_effects(machine());
6838   stv_vdp2_draw_back(m_tmpbitmap,cliprect);
69136839
6914   stv_vdp2_draw_back(machine(), m_tmpbitmap,cliprect);
6915
6916   #if DEBUG_MODE
6917   if(machine().input().code_pressed_once(KEYCODE_T))
6918   {
6919      vdpdebug.l_en^=1;
6920      popmessage("NBG3 %sabled",vdpdebug.l_en & 1 ? "en" : "dis");
6921   }
6922   if(machine().input().code_pressed_once(KEYCODE_Y))
6923   {
6924      vdpdebug.l_en^=2;
6925      popmessage("NBG2 %sabled",vdpdebug.l_en & 2 ? "en" : "dis");
6926   }
6927   if(machine().input().code_pressed_once(KEYCODE_U))
6928   {
6929      vdpdebug.l_en^=4;
6930      popmessage("NBG1 %sabled",vdpdebug.l_en & 4 ? "en" : "dis");
6931   }
6932   if(machine().input().code_pressed_once(KEYCODE_I))
6933   {
6934      vdpdebug.l_en^=8;
6935      popmessage("NBG0 %sabled",vdpdebug.l_en & 8 ? "en" : "dis");
6936   }
6937   if(machine().input().code_pressed_once(KEYCODE_K))
6938   {
6939      vdpdebug.l_en^=0x10;
6940      popmessage("RBG0 %sabled",vdpdebug.l_en & 0x10 ? "en" : "dis");
6941   }
6942   if(machine().input().code_pressed_once(KEYCODE_O))
6943   {
6944      vdpdebug.l_en^=0x20;
6945      popmessage("SPRITE %sabled",vdpdebug.l_en & 0x20 ? "en" : "dis");
6946   }
6947   #endif
6948
69496840   if(STV_VDP2_DISP)
69506841   {
69516842      UINT8 pri;
r20790r20791
69576848      /*If a plane has a priority value of zero it isn't shown at all.*/
69586849      for(pri=1;pri<8;pri++)
69596850      {
6960         if (vdpdebug.l_en & 1)    { if(pri==STV_VDP2_N3PRIN) stv_vdp2_draw_NBG3(machine(), m_tmpbitmap,cliprect); }
6961         if (vdpdebug.l_en & 2)    { if(pri==STV_VDP2_N2PRIN) stv_vdp2_draw_NBG2(machine(), m_tmpbitmap,cliprect); }
6962         if (vdpdebug.l_en & 4)    { if(pri==STV_VDP2_N1PRIN) stv_vdp2_draw_NBG1(machine(), m_tmpbitmap,cliprect); }
6963         if (vdpdebug.l_en & 8)    { if(pri==STV_VDP2_N0PRIN) stv_vdp2_draw_NBG0(machine(), m_tmpbitmap,cliprect); }
6964         if (vdpdebug.l_en & 0x10) { if(pri==STV_VDP2_R0PRIN) stv_vdp2_draw_RBG0(machine(), m_tmpbitmap,cliprect); }
6965         if (vdpdebug.l_en & 0x20) { draw_sprites(machine(),m_tmpbitmap,cliprect,pri); }
6851         if(pri==STV_VDP2_N3PRIN) { stv_vdp2_draw_NBG3(m_tmpbitmap,cliprect); }
6852         if(pri==STV_VDP2_N2PRIN) { stv_vdp2_draw_NBG2(m_tmpbitmap,cliprect); }
6853         if(pri==STV_VDP2_N1PRIN) { stv_vdp2_draw_NBG1(m_tmpbitmap,cliprect); }
6854         if(pri==STV_VDP2_N0PRIN) { stv_vdp2_draw_NBG0(m_tmpbitmap,cliprect); }
6855         if(pri==STV_VDP2_R0PRIN) { stv_vdp2_draw_RBG0(m_tmpbitmap,cliprect); }
6856         { draw_sprites(m_tmpbitmap,cliprect,pri); }
69666857      }
69676858   }
69686859
6969#if DEBUG_MODE
6970   /*popmessage("N0 %02x %04x %02x %04x N1 %02x %04x %02x %04x"
6971   ,STV_VDP2_N0ZMXI,STV_VDP2_N0ZMXD
6972   ,STV_VDP2_N0ZMYI,STV_VDP2_N0ZMYD
6973   ,STV_VDP2_N1ZMXI,STV_VDP2_N1ZMXD
6974   ,STV_VDP2_N1ZMYI,STV_VDP2_N1ZMYD);*/
6975
6976   if ( machine().input().code_pressed_once(KEYCODE_W) )
6977   {
6978      int tilecode;
6979
6980      for (tilecode = 0;tilecode<0x8000;tilecode++)
6981      {
6982         machine().gfx[0]->mark_dirty(tilecode);
6983      }
6984
6985      for (tilecode = 0;tilecode<0x2000;tilecode++)
6986      {
6987         machine().gfx[1]->mark_dirty(tilecode);
6988      }
6989
6990      for (tilecode = 0;tilecode<0x4000;tilecode++)
6991      {
6992         machine().gfx[2]->mark_dirty(tilecode);
6993      }
6994
6995      for (tilecode = 0;tilecode<0x1000;tilecode++)
6996      {
6997         machine().gfx[3]->mark_dirty(tilecode);
6998      }
6999
7000      /* vdp 1 ... doesn't have to be tile based */
7001
7002      for (tilecode = 0;tilecode<0x8000;tilecode++)
7003      {
7004         machine().gfx[4]->mark_dirty(tilecode);
7005      }
7006      for (tilecode = 0;tilecode<0x2000;tilecode++)
7007      {
7008         machine().gfx[5]->mark_dirty(tilecode);
7009      }
7010      for (tilecode = 0;tilecode<0x4000;tilecode++)
7011      {
7012         machine().gfx[6]->mark_dirty(tilecode);
7013      }
7014      for (tilecode = 0;tilecode<0x1000;tilecode++)
7015      {
7016         machine().gfx[7]->mark_dirty(tilecode);
7017      }
7018   }
7019
7020   if ( machine().input().code_pressed_once(KEYCODE_N) )
7021   {
7022      FILE *fp;
7023
7024      fp=fopen("mamevdp1", "w+b");
7025      if (fp)
7026      {
7027         fwrite(m_vdp1_vram, 0x80000, 1, fp);
7028         fclose(fp);
7029      }
7030   }
7031
7032   if ( machine().input().code_pressed_once(KEYCODE_M) )
7033   {
7034      FILE *fp;
7035
7036      fp=fopen("vdp1_vram.bin", "r+b");
7037      if (fp)
7038      {
7039         fread(m_vdp1_vram, 0x80000, 1, fp);
7040         fclose(fp);
7041      }
7042   }
7043
7044#endif
7045
70466860   copybitmap(bitmap, m_tmpbitmap, 0, 0, 0, 0, cliprect);
7047
70486861   return 0;
70496862}
70506863
7051/* below is some old code we might use .. */
70526864
7053#if 0
7054
7055static void stv_dump_ram()
7056{
7057   FILE *fp;
7058
7059   fp=fopen("workraml.dmp", "w+b");
7060   if (fp)
7061   {
7062      fwrite(stv_workram_l, 0x00100000, 1, fp);
7063      fclose(fp);
7064   }
7065   fp=fopen("workramh.dmp", "w+b");
7066   if (fp)
7067   {
7068      fwrite(stv_workram_h, 0x00100000, 1, fp);
7069      fclose(fp);
7070   }
7071   fp=fopen("scu.dmp", "w+b");
7072   if (fp)
7073   {
7074      fwrite(stv_scu, 0xd0, 1, fp);
7075      fclose(fp);
7076   }
7077   fp=fopen("stv_a0_vram.dmp", "w+b");
7078   if (fp)
7079   {
7080      fwrite(stv_a0_vram, 0x00020000, 1, fp);
7081      fclose(fp);
7082   }
7083   fp=fopen("stv_a1_vram.dmp", "w+b");
7084   if (fp)
7085   {
7086      fwrite(stv_a1_vram, 0x00020000, 1, fp);
7087      fclose(fp);
7088   }
7089   fp=fopen("stv_b0_vram.dmp", "w+b");
7090   if (fp)
7091   {
7092      fwrite(stv_b0_vram, 0x00020000, 1, fp);
7093      fclose(fp);
7094   }
7095   fp=fopen("stv_b1_vram.dmp", "w+b");
7096   if (fp)
7097   {
7098      fwrite(stv_b1_vram, 0x00020000, 1, fp);
7099      fclose(fp);
7100   }
7101   fp=fopen("cram.dmp", "w+b");
7102   if (fp)
7103   {
7104      fwrite(stv_cram, 0x00080000, 1, fp);
7105      fclose(fp);
7106   }
7107   fp=fopen("68k.dmp", "w+b");
7108   if (fp)
7109   {
7110      fwrite(machine.root_device().memregion(REGION_CPU3)->base(), 0x100000, 1, fp);
7111      fclose(fp);
7112   }
7113}
7114
7115
7116#endif
7117

Previous 199869 Revisions Next


© 1997-2024 The MAME Team