Previous 15994 Revisions Next

r1666 Thursday 7th February, 2008 at 21:41:40 UTC by Wilbert Pol
[GAMEBOY] Added bound checks to the video code.
[src/mess/video]gb.c

src/mess/video/gb.c
r1665r1666
290290            for (bit = 0; bit < 8; bit++, xindex++)
291291            {
292292               register int colour = ((data & 0x0100) ? 2 : 0) | ((data & 0x0001) ? 1 : 0);
293               if (colour && !bg_zbuf[xindex])
293               if (colour && !bg_zbuf[xindex] && xindex >= 0 && xindex < 160)
294294                  gb_plot_pixel(bitmap, xindex, yindex, Machine->pens[spal[colour]]);
295295               data >>= 1;
296296            }
r1665r1666
299299            for (bit = 0; bit < 8; bit++, xindex++)
300300            {
301301               register int colour = ((data & 0x0100) ? 2 : 0) | ((data & 0x0001) ? 1 : 0);
302               if (colour)
302               if (colour && xindex >= 0 && xindex < 160)
303303                  gb_plot_pixel(bitmap, xindex, yindex, Machine->pens[spal[colour]]);
304304               data >>= 1;
305305            }
306306            break;
307307         case 0x80:               /* priority is set (behind bgnd & wnd, don't flip x) */
308            for (bit = 0; bit < 8; bit++, xindex++)
308            for (bit = 0; bit < 8 && xindex < 160; bit++, xindex++)
309309            {
310310               register int colour = ((data & 0x8000) ? 2 : 0) | ((data & 0x0080) ? 1 : 0);
311               if (colour && !bg_zbuf[xindex])
311               if (colour && !bg_zbuf[xindex] && xindex >= 0 && xindex < 160)
312312                  gb_plot_pixel(bitmap, xindex, yindex, Machine->pens[spal[colour]]);
313313               data <<= 1;
314314            }
315315            break;
316316         case 0x00:               /* priority is not set (overlaps bgnd & wnd, don't flip x) */
317            for (bit = 0; bit < 8; bit++, xindex++)
317            for (bit = 0; bit < 8 && xindex < 160; bit++, xindex++)
318318            {
319319               register int colour = ((data & 0x8000) ? 2 : 0) | ((data & 0x0080) ? 1 : 0);
320               if (colour)
320               if (colour && xindex >= 0 && xindex < 160)
321321                  gb_plot_pixel(bitmap, xindex, yindex, Machine->pens[spal[colour]]);
322322               data <<= 1;
323323            }
r1665r1666
378378      }
379379
380380      if ( cycles_to_go < 160 ) {
381         gb_lcd.end_x = 160 - cycles_to_go;
381         gb_lcd.end_x = MIN(160 - cycles_to_go,160);
382382         /* Draw empty pixels when the background is disabled */
383383         if ( ! ( LCDCONT & 0x01 ) ) {
384384            rectangle r;
r1665r1666
517517            for (bit = 0; bit < 8; bit++, xindex++)
518518            {
519519               register int colour = ((data & 0x0100) ? 2 : 0) | ((data & 0x0001) ? 1 : 0);
520               if ((xindex >= SGB_XOFFSET && xindex <= SGB_XOFFSET + 160) && colour && !bg_zbuf[xindex - SGB_XOFFSET])
520               if ((xindex >= SGB_XOFFSET && xindex < SGB_XOFFSET + 160) && colour && !bg_zbuf[xindex - SGB_XOFFSET])
521521                  gb_plot_pixel(bitmap, xindex, yindex, sgb_pal[pal + spal[colour]]);
522522               data >>= 1;
523523            }
r1665r1666
526526            for (bit = 0; bit < 8; bit++, xindex++)
527527            {
528528               register int colour = ((data & 0x0100) ? 2 : 0) | ((data & 0x0001) ? 1 : 0);
529               if ((xindex >= SGB_XOFFSET && xindex <= SGB_XOFFSET + 160) && colour)
529               if ((xindex >= SGB_XOFFSET && xindex < SGB_XOFFSET + 160) && colour)
530530                  gb_plot_pixel(bitmap, xindex, yindex, sgb_pal[pal + spal[colour]]);
531531               data >>= 1;
532532            }
r1665r1666
535535            for (bit = 0; bit < 8; bit++, xindex++)
536536            {
537537               register int colour = ((data & 0x8000) ? 2 : 0) | ((data & 0x0080) ? 1 : 0);
538               if ((xindex >= SGB_XOFFSET && xindex <= SGB_XOFFSET + 160) && colour && !bg_zbuf[xindex - SGB_XOFFSET])
538               if ((xindex >= SGB_XOFFSET && xindex < SGB_XOFFSET + 160) && colour && !bg_zbuf[xindex - SGB_XOFFSET])
539539                  gb_plot_pixel(bitmap, xindex, yindex, sgb_pal[pal + spal[colour]]);
540540               data <<= 1;
541541            }
r1665r1666
544544            for (bit = 0; bit < 8; bit++, xindex++)
545545            {
546546               register int colour = ((data & 0x8000) ? 2 : 0) | ((data & 0x0080) ? 1 : 0);
547               if ((xindex >= SGB_XOFFSET && xindex <= SGB_XOFFSET + 160) && colour)
547               if ((xindex >= SGB_XOFFSET && xindex < SGB_XOFFSET + 160) && colour)
548548                  gb_plot_pixel(bitmap, xindex, yindex, sgb_pal[pal + spal[colour]]);
549549               data <<= 1;
550550            }
r1665r1666
699699         }
700700      }
701701      if ( cycles_to_go < 160 ) {
702         gb_lcd.end_x = 160 - cycles_to_go;
702         gb_lcd.end_x = MIN(160 - cycles_to_go,160);
703703
704704         /* if background or screen disabled clear line */
705705         if ( ! ( LCDCONT & 0x01 ) ) {
r1665r1666
842842            for (bit = 0; bit < 8; bit++, xindex++)
843843            {
844844               register int colour = ((data & 0x0100) ? 2 : 0) | ((data & 0x0001) ? 1 : 0);
845               if (colour && !bg_zbuf[xindex])
845               if (colour && !bg_zbuf[xindex] && xindex >= 0 && xindex < 160)
846846                  gb_plot_pixel(bitmap, xindex, yindex, Machine->pens[cgb_spal[pal + colour]]);
847847               data >>= 1;
848848            }
r1665r1666
853853               register int colour = ((data & 0x0100) ? 2 : 0) | ((data & 0x0001) ? 1 : 0);
854854               if((bg_zbuf[xindex] & 0x80) && (bg_zbuf[xindex] & 0x7f) && (LCDCONT & 0x1))
855855                  colour = 0;
856               if (colour)
856               if (colour && xindex >= 0 && xindex < 160)
857857                  gb_plot_pixel(bitmap, xindex, yindex, Machine->pens[cgb_spal[pal + colour]]);
858858               data >>= 1;
859859            }
r1665r1666
862862            for (bit = 0; bit < 8; bit++, xindex++)
863863            {
864864               register int colour = ((data & 0x8000) ? 2 : 0) | ((data & 0x0080) ? 1 : 0);
865               if (colour && !bg_zbuf[xindex])
865               if (colour && !bg_zbuf[xindex] && xindex >= 0 && xindex < 160)
866866                  gb_plot_pixel(bitmap, xindex, yindex, Machine->pens[cgb_spal[pal + colour]]);
867867               data <<= 1;
868868            }
r1665r1666
873873               register int colour = ((data & 0x8000) ? 2 : 0) | ((data & 0x0080) ? 1 : 0);
874874               if((bg_zbuf[xindex] & 0x80) && (bg_zbuf[xindex] & 0x7f) && (LCDCONT & 0x1))
875875                  colour = 0;
876               if (colour)
876               if (colour && xindex >= 0 && xindex < 160)
877877                  gb_plot_pixel(bitmap, xindex, yindex, Machine->pens[cgb_spal[pal + colour]]);
878878               data <<= 1;
879879            }
r1665r1666
934934      }
935935
936936      if ( cycles_to_go < 160 ) {
937         gb_lcd.end_x = 160 - cycles_to_go;
937         gb_lcd.end_x = MIN(160 - cycles_to_go,160);
938938         /* Draw empty line when the background is disabled */
939939         if ( ! ( LCDCONT & 0x01 ) ) {
940940            rectangle r = Machine->screen[0].visarea;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team