Previous 15994 Revisions Next

r6982 Saturday 9th January, 2010 at 08:24:51 UTC by Fabio Priuli
Added a few changes from Enik Land that didn't get applied in svn 6604 due to unnoticed diff conflicts
[src/mess/video]smsvdp.c

src/mess/video/smsvdp.c
r6981r6982
5959#define STATUS_SPRCOL         0x20   /* Object collision flag */
6060#define STATUS_HINT           0x02   /* Pending horizontal interrupt flag */
6161
62#define HINT_HPOS             24
63#define VINT_HPOS             1   /* docs says should be near HINT time */
62#define VINT_HPOS             23
63#define HINT_HPOS             23
64#define VCOUNT_CHANGE_HPOS    22
65#define VINT_FLAG_HPOS        7
66#define SPROVR_HPOS           6
67#define SPRCOL_BASEHPOS       42
68#define DISPLAY_CB_HPOS       5  /* fix X-Scroll latchtime (Flubba's VDPTest) */
6469
6570#define GG_CRAM_SIZE          0x40   /* 32 colors x 2 bytes per color = 64 bytes */
6671#define SMS_CRAM_SIZE         0x20   /* 32 colors x 1 bytes per color = 32 bytes */
r6981r6982
106111   int              irq_state;                /* The status of the IRQ line of the VDP */
107112   int              vdp_mode;                 /* Current mode of the VDP: 0,1,2,3,4 */
108113   int              y_pixels;                 /* 192, 224, 240 */
109   int              line_counter;
114   UINT8            line_counter;
110115   UINT8            hcounter;
111116   UINT8            *VRAM;                    /* Pointer to VRAM */
112117   UINT8            *CRAM;                    /* Pointer to CRAM */
r6981r6982
230235READ8_DEVICE_HANDLER( sms_vdp_vcount_r )
231236{
232237   smsvdp_t *smsvdp = get_safe_token(device);
238   int vpos = video_screen_get_vpos(device->machine->primary_screen);
233239
234   return (smsvdp->sms_frame_timing[INIT_VCOUNT] + video_screen_get_vpos(device->machine->primary_screen)) & 0xff;
240   if (video_screen_get_hpos(device->machine->primary_screen) < VCOUNT_CHANGE_HPOS)
241   {
242      vpos--;
243      if (vpos < 0)
244         vpos += video_screen_get_height(device->machine->primary_screen);
245   }
246
247   return (smsvdp->sms_frame_timing[INIT_VCOUNT] + vpos) & 0xff;
235248}
236249
237250
r6981r6982
259272}
260273
261274
262static TIMER_CALLBACK( smsvdp_set_irq )
275static TIMER_CALLBACK( smsvdp_set_status )
263276{
264277   smsvdp_t *smsvdp = (smsvdp_t *) ptr;
265278
266   smsvdp->irq_state = 1;
279   smsvdp->status |= (UINT8) param;
280}
267281
268   if (smsvdp->int_callback)
269      smsvdp->int_callback(machine, ASSERT_LINE);
282
283static TIMER_CALLBACK( smsvdp_check_hint )
284{
285   smsvdp_t *smsvdp = (smsvdp_t *) ptr;
286
287   if (smsvdp->line_counter == 0x00)
288   {
289      smsvdp->line_counter = smsvdp->reg[0x0a];
290      smsvdp->status |= STATUS_HINT;
291   }
292   else
293   {
294      smsvdp->line_counter--;
295   }
296
297   if ((smsvdp->status & STATUS_HINT) && (smsvdp->reg[0x00] & 0x10))
298   {
299      smsvdp->irq_state = 1;
300
301      if (smsvdp->int_callback)
302         smsvdp->int_callback(machine, ASSERT_LINE);
303   }
270304}
271305
272306
307static TIMER_CALLBACK( smsvdp_check_vint )
308{
309   smsvdp_t *smsvdp = (smsvdp_t *) ptr;
310
311   if ((smsvdp->status & STATUS_VINT) && (smsvdp->reg[0x01] & 0x20))
312   {
313      smsvdp->irq_state = 1;
314
315      if (smsvdp->int_callback)
316         smsvdp->int_callback(machine, ASSERT_LINE);
317   }
318}
319
320
273321static TIMER_CALLBACK( smsvdp_display_callback )
274322{
275323   smsvdp_t *smsvdp = (smsvdp_t *) ptr;
r6981r6982
308356   {
309357      if (vpos == vpos_limit)
310358      {
311         if (smsvdp->line_counter == 0x00)
312         {
313            smsvdp->line_counter = smsvdp->reg[0x0a];
314            smsvdp->status |= STATUS_HINT;
315
316            if (smsvdp->reg[0x00] & 0x10)
317            {
318               /* Delay triggering of interrupt to allow software to read the status bit before the irq */
319               timer_set(machine, video_screen_get_time_until_pos(machine->primary_screen, vpos, HINT_HPOS), smsvdp, 0, smsvdp_set_irq);
320            }
321         }
322         else
323         {
324            smsvdp->line_counter -= 1;
325         }
359         timer_set(machine, video_screen_get_time_until_pos(machine->primary_screen, vpos, HINT_HPOS), smsvdp, 0, smsvdp_check_hint);
326360      }
327361      else
328362      {
r6981r6982
331365
332366      if (vpos == vpos_limit + 1)
333367      {
334         smsvdp->status |= STATUS_VINT;
335
336         if (smsvdp->reg[0x01] & 0x20)
337         {
338            /* Delay triggering of interrupt to allow software to read the status bit before the irq */
339            timer_set(machine, video_screen_get_time_until_pos(machine->primary_screen, vpos, VINT_HPOS), smsvdp, 0, smsvdp_set_irq);
340         }
368         timer_set(machine, video_screen_get_time_until_pos(machine->primary_screen, vpos, VINT_FLAG_HPOS), smsvdp, (int)STATUS_VINT, smsvdp_set_status);
369         timer_set(machine, video_screen_get_time_until_pos(machine->primary_screen, vpos, VINT_HPOS), smsvdp, 0, smsvdp_check_vint);
341370      }
342371
343372      sms_update_palette(smsvdp);
r6981r6982
364393   /* Check if we're in the active display area */
365394   if (vpos >= vpos_limit)
366395   {
367      rgb_t border_color;
368
369396      if (vpos == vpos_limit)
370397      {
371398         smsvdp->reg9copy = smsvdp->reg[0x09];
372399      }
373400
374      if (smsvdp->line_counter == 0x00)
375      {
376         smsvdp->line_counter = smsvdp->reg[0x0a];
377         smsvdp->status |= STATUS_HINT;
401      timer_set(machine, video_screen_get_time_until_pos(machine->primary_screen, vpos, HINT_HPOS), smsvdp, 0, smsvdp_check_hint);
378402
379         if (smsvdp->reg[0x00] & 0x10)
380         {
381            /* Delay triggering of interrupt to allow software to read the status bit before the irq */
382            timer_set(machine, video_screen_get_time_until_pos(machine->primary_screen, vpos, HINT_HPOS), smsvdp, 0, smsvdp_set_irq);
383         }
384      }
385      else
386      {
387         smsvdp->line_counter -= 1;
388      }
389
390403      sms_update_palette(smsvdp);
391404
392      /* Check if display is disabled */
393      if (!(smsvdp->reg[0x01] & 0x40))
394         border_color = RGB_BLACK;
395      else
396         border_color = machine->pens[smsvdp->current_palette[BACKDROP_COLOR]];
397
398405      /* Draw left border */
399406      rec.min_x = LBORDER_START;
400407      rec.max_x = LBORDER_START + LBORDER_X_PIXELS - 1;
401      bitmap_fill(smsvdp->tmpbitmap, &rec, border_color);
408      bitmap_fill(smsvdp->tmpbitmap, &rec, machine->pens[smsvdp->current_palette[BACKDROP_COLOR]]);
402409
403410      /* Draw right border */
404411      rec.min_x = LBORDER_START + LBORDER_X_PIXELS + 256;
405412      rec.max_x = rec.min_x + RBORDER_X_PIXELS - 1;
406      bitmap_fill(smsvdp->tmpbitmap, &rec, border_color);
413      bitmap_fill(smsvdp->tmpbitmap, &rec, machine->pens[smsvdp->current_palette[BACKDROP_COLOR]]);
407414
408415      sms_refresh_line(machine, smsvdp, smsvdp->tmpbitmap, LBORDER_START + LBORDER_X_PIXELS, vpos_limit, vpos - vpos_limit);
409416
r6981r6982
434441      sms_refresh_line(machine, smsvdp, smsvdp->tmpbitmap, LBORDER_START + LBORDER_X_PIXELS, vpos_limit + smsvdp->sms_frame_timing[TOP_BORDER], vpos - (vpos_limit + smsvdp->sms_frame_timing[TOP_BORDER]));
435442      return;
436443   }
444
445   /* we're in the vertical or top blanking area */
446   smsvdp->line_counter = smsvdp->reg[0x0a];
437447}
438448
439449
r6981r6982
554564         if (reg_num == 0 || reg_num == 1)
555565            set_display_settings(device);
556566
557         if ((reg_num == 1) && (smsvdp->reg[0x01] & 0x20) && (smsvdp->status & STATUS_VINT))
567         if (reg_num == 1)
558568         {
559            smsvdp->irq_state = 1;
560
561            if (smsvdp->int_callback)
562               smsvdp->int_callback(device->machine, ASSERT_LINE);
569            timer_set(device->machine, video_screen_get_time_until_pos(device->machine->primary_screen, video_screen_get_vpos(device->machine->primary_screen), VINT_HPOS), smsvdp, 0, smsvdp_check_vint);
563570         }
564571         smsvdp->addrmode = 0;
565572         break;
r6981r6982
571578}
572579
573580
574static void sms_refresh_line_mode4( smsvdp_t *smsvdp, int *line_buffer, int line )
581static void sms_refresh_line_mode4( smsvdp_t *smsvdp, int *line_buffer, int *priority_selected, int line )
575582{
576583   int tile_column;
577584   int x_scroll, y_scroll, x_scroll_start_column;
578   int sprite_index;
579   int pixel_x, pixel_plot_x, priority_selected[256];
580   int sprite_x, sprite_y, sprite_line, sprite_tile_selected, sprite_height, sprite_zoom;
581   int sprite_buffer[8], sprite_buffer_count, sprite_buffer_index;
585   int pixel_x, pixel_plot_x;
582586   int bit_plane_0, bit_plane_1, bit_plane_2, bit_plane_3;
583587   int scroll_mod;
584588   UINT16 name_table_address;
585589   UINT8 *name_table;
586   UINT8 *sprite_table = smsvdp->VRAM + ((smsvdp->reg[0x05] << 7) & 0x3f00);
587590
588591   if (smsvdp->y_pixels != 192)
589592   {
r6981r6982
668671         }
669672      }
670673   }
674}
671675
676static void sms_refresh_mode4_sprites( running_machine *machine, smsvdp_t *smsvdp, int *line_buffer, int *priority_selected, int pixel_plot_y, int line )
677{
678   int sprite_index;
679   int pixel_x, pixel_plot_x;
680   int sprite_x, sprite_y, sprite_line, sprite_tile_selected, sprite_height, sprite_zoom;
681   int sprite_col_occurred, sprite_col_x;
682   int sprite_buffer[8], sprite_buffer_count, sprite_buffer_index;
683   int bit_plane_0, bit_plane_1, bit_plane_2, bit_plane_3;
684   UINT8 *sprite_table = smsvdp->VRAM + ((smsvdp->reg[0x05] << 7) & 0x3f00);
685
672686   /* Draw sprite layer */
673687   sprite_height = (smsvdp->reg[0x01] & 0x02 ? 16 : 8);
674688   sprite_zoom = 1;
r6981r6982
693707         else if (line >= 0 && line < smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V])
694708         {
695709            /* Too many sprites per line */
696            smsvdp->status |= STATUS_SPROVR;
710            timer_set(machine, video_screen_get_time_until_pos(machine->primary_screen, pixel_plot_y + line, SPROVR_HPOS), smsvdp, (int)STATUS_SPROVR, smsvdp_set_status);
697711         }
698712         sprite_buffer_count++;
699713      }
r6981r6982
740754      bit_plane_2 = smsvdp->VRAM[((sprite_tile_selected << 5) + ((sprite_line & 0x07) << 2)) + 0x02];
741755      bit_plane_3 = smsvdp->VRAM[((sprite_tile_selected << 5) + ((sprite_line & 0x07) << 2)) + 0x03];
742756
757      sprite_col_occurred = 0;
758      sprite_col_x = 0;
759
743760      for (pixel_x = 0; pixel_x < 8 ; pixel_x++)
744761      {
745762         UINT8 pen_bit_0, pen_bit_1, pen_bit_2, pen_bit_3;
r6981r6982
790807            }
791808            else
792809            {
793               /* sprite collision occurred */
794               smsvdp->status |= STATUS_SPRCOL;
810               if (!sprite_col_occurred)
811               {
812                  sprite_col_occurred = 1;
813                  sprite_col_x = pixel_plot_x;
814               }
795815            }
796816            if (smsvdp->collision_buffer[pixel_plot_x + 1] != 1)
797817            {
r6981r6982
799819            }
800820            else
801821            {
802               /* sprite collision occurred */
803               smsvdp->status |= STATUS_SPRCOL;
822               if (!sprite_col_occurred)
823               {
824                  sprite_col_occurred = 1;
825                  sprite_col_x = pixel_plot_x;
826               }
804827            }
805828         }
806829         else
r6981r6982
830853            }
831854            else
832855            {
833               /* sprite collision occurred */
834               smsvdp->status |= STATUS_SPRCOL;
856               if (!sprite_col_occurred)
857               {
858                  sprite_col_occurred = 1;
859                  sprite_col_x = pixel_plot_x;
860               }
835861            }
836862         }
837863      }
864      if (sprite_col_occurred)
865         timer_set(machine, video_screen_get_time_until_pos(machine->primary_screen, pixel_plot_y + line, SPRCOL_BASEHPOS + sprite_col_x), smsvdp, (int)STATUS_SPRCOL, smsvdp_set_status);
838866   }
839867
840868   /* Fill column 0 with overscan color from reg[0x07] */
r6981r6982
852880}
853881
854882
855static void sms_refresh_tms9918_sprites( smsvdp_t *smsvdp, int *line_buffer, int line )
883static void sms_refresh_tms9918_sprites( running_machine *machine, smsvdp_t *smsvdp, int *line_buffer, int pixel_plot_y, int line )
856884{
857885   int pixel_plot_x;
886   int sprite_col_occurred, sprite_col_x;
858887   int sprite_height, sprite_buffer_count, sprite_index, sprite_buffer[4], sprite_buffer_index;
859888   UINT8 *sprite_table, *sprite_pattern_table;
860889
r6981r6982
885914         else if (line >= 0 && line < smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V])
886915         {
887916            /* Too many sprites per line */
888            smsvdp->status |= STATUS_SPROVR;
917            timer_set(machine, video_screen_get_time_until_pos(machine->primary_screen, pixel_plot_y + line, SPROVR_HPOS), smsvdp, (int)STATUS_SPROVR, smsvdp_set_status);
889918         }
890919         sprite_buffer_count++;
891920      }
r6981r6982
942971
943972      pattern = sprite_pattern_table[sprite_tile_selected * 8 + sprite_line];
944973
974      sprite_col_occurred = 0;
975      sprite_col_x = 0;
976
945977      for (pixel_x = 0; pixel_x < 8; pixel_x++)
946978      {
947979         if (smsvdp->reg[0x01] & 0x01)
r6981r6982
962994               }
963995               else
964996               {
965                  smsvdp->status |= STATUS_SPRCOL;
997                  if (!sprite_col_occurred)
998                  {
999                     sprite_col_occurred = 1;
1000                     sprite_col_x = pixel_plot_x;
1001                  }
9661002               }
9671003
9681004               line_buffer[pixel_plot_x+1] = smsvdp->current_palette[pen_selected];
r6981r6982
9731009               }
9741010               else
9751011               {
976                  smsvdp->status |= STATUS_SPRCOL;
1012                  if (!sprite_col_occurred)
1013                  {
1014                     sprite_col_occurred = 1;
1015                     sprite_col_x = pixel_plot_x;
1016                  }
9771017               }
9781018            }
9791019         }
r6981r6982
9961036               }
9971037               else
9981038               {
999                  smsvdp->status |= STATUS_SPRCOL;
1039                  if (!sprite_col_occurred)
1040                  {
1041                     sprite_col_occurred = 1;
1042                     sprite_col_x = pixel_plot_x;
1043                  }
10001044               }
10011045            }
10021046         }
r6981r6982
10291073                  }
10301074                  else
10311075                  {
1032                     smsvdp->status |= STATUS_SPRCOL;
1076                     if (!sprite_col_occurred)
1077                     {
1078                        sprite_col_occurred = 1;
1079                        sprite_col_x = pixel_plot_x;
1080                     }
10331081                  }
10341082
10351083                  line_buffer[pixel_plot_x+1] = smsvdp->current_palette[pen_selected];
r6981r6982
10401088                  }
10411089                  else
10421090                  {
1043                     smsvdp->status |= STATUS_SPRCOL;
1091                     if (!sprite_col_occurred)
1092                     {
1093                        sprite_col_occurred = 1;
1094                        sprite_col_x = pixel_plot_x;
1095                     }
10441096                  }
10451097               }
10461098            }
r6981r6982
10631115                  }
10641116                  else
10651117                  {
1066                     smsvdp->status |= STATUS_SPRCOL;
1118                     if (!sprite_col_occurred)
1119                     {
1120                        sprite_col_occurred = 1;
1121                        sprite_col_x = pixel_plot_x;
1122                     }
10671123                  }
10681124               }
10691125            }
10701126         }
10711127      }
1128      if (sprite_col_occurred)
1129         timer_set(machine, video_screen_get_time_until_pos(machine->primary_screen, pixel_plot_y + line, SPRCOL_BASEHPOS + sprite_col_x), smsvdp, (int)STATUS_SPRCOL, smsvdp_set_status);
10721130   }
10731131}
10741132
r6981r6982
11201178         line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected];
11211179      }
11221180   }
1123
1124   /* Draw sprite layer */
1125   sms_refresh_tms9918_sprites(smsvdp, line_buffer, line);
11261181}
11271182
11281183
r6981r6982
11611216         line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected];
11621217      }
11631218   }
1164
1165   /* Draw sprite layer */
1166   sms_refresh_tms9918_sprites(smsvdp, line_buffer, line);
11671219}
11681220
11691221
r6981r6982
11711223{
11721224   int x;
11731225   int *blitline_buffer = smsvdp->line_buffer;
1226   int priority_selected[256];
11741227
11751228   switch( smsvdp->vdp_mode )
11761229   {
11771230   case 0:
1178      sms_refresh_line_mode0(smsvdp, blitline_buffer, line);
1231      if (line >= 0 && line < smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V])
1232         sms_refresh_line_mode0(smsvdp, blitline_buffer, line);
1233      sms_refresh_tms9918_sprites(machine, smsvdp, blitline_buffer, pixel_plot_y, line);
11791234      break;
11801235
11811236   case 2:
1182      sms_refresh_line_mode2(smsvdp, blitline_buffer, line);
1237      if (line >= 0 && line < smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V])
1238         sms_refresh_line_mode2(smsvdp, blitline_buffer, line);
1239      sms_refresh_tms9918_sprites(machine, smsvdp, blitline_buffer, pixel_plot_y, line);
11831240      break;
11841241
11851242   case 4:
11861243   default:
1187      sms_refresh_line_mode4(smsvdp, blitline_buffer, line);
1244      memset(priority_selected, 0, sizeof(priority_selected));
1245      if (line >= 0 && line < smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V])
1246         sms_refresh_line_mode4(smsvdp, blitline_buffer, priority_selected, line);
1247      sms_refresh_mode4_sprites(machine, smsvdp, blitline_buffer, priority_selected, pixel_plot_y, line);
11881248      break;
11891249   }
11901250
1191   if (line < 0 || line >= smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V])
1251   /* Check if display is disabled or we're below/above active area */
1252   if (!(smsvdp->reg[0x01] & 0x40) || line < 0 || line >= smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V])
11921253   {
11931254      for (x = 0; x < 256; x++)
11941255      {
11951256         blitline_buffer[x] = smsvdp->current_palette[BACKDROP_COLOR];
11961257      }
11971258   }
1198   /* Check if display is disabled */
1199   else if (!(smsvdp->reg[0x01] & 0x40))
1200   {
1201      for (x = 0; x < 256; x++)
1202      {
1203         blitline_buffer[x] = 0;
1204      }
1205   }
12061259
12071260   if (IS_GAMEGEAR_VDP && smsvdp->gg_sms_mode)
12081261   {
r6981r6982
14591512   smsvdp->prev_bitmap = auto_bitmap_alloc(device->machine, width, height, BITMAP_FORMAT_INDEXED32);
14601513
14611514   smsvdp->smsvdp_display_timer = timer_alloc(device->machine, smsvdp_display_callback, smsvdp);
1462   timer_adjust_periodic(smsvdp->smsvdp_display_timer, video_screen_get_time_until_pos(screen, 0, 0), 0, video_screen_get_scan_period(screen));
1515   timer_adjust_periodic(smsvdp->smsvdp_display_timer, video_screen_get_time_until_pos(screen, 0, DISPLAY_CB_HPOS), 0, video_screen_get_scan_period(screen));
14631516
14641517   state_save_register_device_item(device, 0, smsvdp->status);
14651518   state_save_register_device_item(device, 0, smsvdp->reg9copy);

Previous 15994 Revisions Next


© 1998-2018 The MESS Team