Previous 15994 Revisions Next

r1906 Tuesday 11th March, 2008 at 17:52:41 UTC by Wilbert Pol
[GAMEBOY] Updates to pass running_machine around.
[src/mess/video]gb.c

src/mess/video/gb.c
r1905r1906
1212***************************************************************************/
1313
1414#include "driver.h"
15#include "deprecat.h"
1615#include "includes/gb.h"
1716#include "cpu/z80gb/z80gb.h"
1817#include "profiler.h"
r1905r1906
108107   emu_timer   *lcd_timer;
109108} gb_lcd;
110109
111static void (*update_scanline)(void);
110static void (*update_scanline)( running_machine *machine );
112111
113112/* Prototypes */
114113static TIMER_CALLBACK(gb_lcd_timer_proc);
115114static TIMER_CALLBACK(gbc_lcd_timer_proc);
116static void gb_lcd_switch_on( void );
115static void gb_lcd_switch_on( running_machine *machine );
117116
118117static const unsigned char palette[] =
119118{
r1905r1906
242241   }
243242}
244243
245INLINE void gb_update_sprites (void)
244INLINE void gb_update_sprites ( running_machine *machine )
246245{
247246   bitmap_t *bitmap = tmpbitmap;
248247   UINT8 height, tilemask, line, *oam, *vram;
r1905r1906
292291            {
293292               register int colour = ((data & 0x0100) ? 2 : 0) | ((data & 0x0001) ? 1 : 0);
294293               if (colour && !bg_zbuf[xindex] && xindex >= 0 && xindex < 160)
295                  gb_plot_pixel(bitmap, xindex, yindex, Machine->pens[spal[colour]]);
294                  gb_plot_pixel(bitmap, xindex, yindex, machine->pens[spal[colour]]);
296295               data >>= 1;
297296            }
298297            break;
r1905r1906
301300            {
302301               register int colour = ((data & 0x0100) ? 2 : 0) | ((data & 0x0001) ? 1 : 0);
303302               if (colour && xindex >= 0 && xindex < 160)
304                  gb_plot_pixel(bitmap, xindex, yindex, Machine->pens[spal[colour]]);
303                  gb_plot_pixel(bitmap, xindex, yindex, machine->pens[spal[colour]]);
305304               data >>= 1;
306305            }
307306            break;
r1905r1906
310309            {
311310               register int colour = ((data & 0x8000) ? 2 : 0) | ((data & 0x0080) ? 1 : 0);
312311               if (colour && !bg_zbuf[xindex] && xindex >= 0 && xindex < 160)
313                  gb_plot_pixel(bitmap, xindex, yindex, Machine->pens[spal[colour]]);
312                  gb_plot_pixel(bitmap, xindex, yindex, machine->pens[spal[colour]]);
314313               data <<= 1;
315314            }
316315            break;
r1905r1906
319318            {
320319               register int colour = ((data & 0x8000) ? 2 : 0) | ((data & 0x0080) ? 1 : 0);
321320               if (colour && xindex >= 0 && xindex < 160)
322                  gb_plot_pixel(bitmap, xindex, yindex, Machine->pens[spal[colour]]);
321                  gb_plot_pixel(bitmap, xindex, yindex, machine->pens[spal[colour]]);
323322               data <<= 1;
324323            }
325324            break;
r1905r1906
329328   }
330329}
331330
332static void gb_update_scanline (void) {
331static void gb_update_scanline( running_machine *machine ) {
333332   bitmap_t *bitmap = tmpbitmap;
334333
335334   profiler_mark(PROFILER_VIDEO);
r1905r1906
386385            r.min_y = r.max_y = gb_lcd.current_line;
387386            r.min_x = gb_lcd.start_x;
388387            r.max_x = gb_lcd.end_x - 1;
389            fillbitmap( bitmap, Machine->pens[ gb_bpal[0] ], &r );
388            fillbitmap( bitmap, machine->pens[ gb_bpal[0] ], &r );
390389         }
391390         while ( l < 2 ) {
392391            UINT8   xindex, *map, *tiles;
r1905r1906
414413            while ( i > 0 ) {
415414               while ( ( gb_lcd.layer[l].xshift < 8 ) && i ) {
416415                  register int colour = ( ( data & 0x8000 ) ? 2 : 0 ) | ( ( data & 0x0080 ) ? 1 : 0 );
417                  gb_plot_pixel( bitmap, xindex, gb_lcd.current_line, Machine->pens[ gb_bpal[ colour ] ] );
416                  gb_plot_pixel( bitmap, xindex, gb_lcd.current_line, machine->pens[ gb_bpal[ colour ] ] );
418417                  bg_zbuf[ xindex ] = colour;
419418                  xindex++;
420419                  data <<= 1;
r1905r1906
438437            l++;
439438         }
440439         if ( gb_lcd.end_x == 160 && LCDCONT & 0x02 ) {
441            gb_update_sprites();
440            gb_update_sprites( machine );
442441         }
443442         gb_lcd.start_x = gb_lcd.end_x;
444443      }
r1905r1906
447446         /* Draw an empty line when LCD is disabled */
448447         if ( gb_lcd.previous_line != gb_lcd.current_line ) {
449448            if ( gb_lcd.current_line < 144 ) {
450               rectangle r = Machine->screen[0].visarea;
449               rectangle r = machine->screen[0].visarea;
451450               r.min_y = r.max_y = gb_lcd.current_line;
452               fillbitmap( bitmap, Machine->pens[0], &r );
451               fillbitmap( bitmap, machine->pens[0], &r );
453452            }
454453            gb_lcd.previous_line = gb_lcd.current_line;
455454         }
r1905r1906
618617   }
619618}
620619
621static void sgb_update_scanline (void) {
620static void sgb_update_scanline( running_machine *machine ) {
622621   bitmap_t *bitmap = tmpbitmap;
623622
624623   profiler_mark(PROFILER_VIDEO);
r1905r1906
676675            return;
677676         case 2: /* Blank screen (black) */
678677            {
679               rectangle r = Machine->screen[0].visarea;
678               rectangle r = machine->screen[0].visarea;
680679               r.min_x = SGB_XOFFSET;
681680               r.max_x -= SGB_XOFFSET;
682681               r.min_y = SGB_YOFFSET;
683682               r.max_y -= SGB_YOFFSET;
684               fillbitmap( bitmap, Machine->pens[0], &r );
683               fillbitmap( bitmap, machine->pens[0], &r );
685684            } return;
686685         case 3: /* Blank screen (white - or should it be color 0?) */
687686            {
688               rectangle r = Machine->screen[0].visarea;
687               rectangle r = machine->screen[0].visarea;
689688               r.min_x = SGB_XOFFSET;
690689               r.max_x -= SGB_XOFFSET;
691690               r.min_y = SGB_YOFFSET;
692691               r.max_y -= SGB_YOFFSET;
693               fillbitmap( bitmap, Machine->pens[32767], &r );
692               fillbitmap( bitmap, machine->pens[32767], &r );
694693            } return;
695694         }
696695
r1905r1906
704703
705704         /* if background or screen disabled clear line */
706705         if ( ! ( LCDCONT & 0x01 ) ) {
707            rectangle r = Machine->screen[0].visarea;
706            rectangle r = machine->screen[0].visarea;
708707            r.min_x = SGB_XOFFSET;
709708            r.max_x -= SGB_XOFFSET;
710709            r.min_y = r.max_y = gb_lcd.current_line + SGB_YOFFSET;
711            fillbitmap( bitmap, Machine->pens[0], &r );
710            fillbitmap( bitmap, machine->pens[0], &r );
712711         }
713712         while( l < 2 ) {
714713            UINT8   xindex, sgb_palette, *map, *tiles;
r1905r1906
774773         if ( gb_lcd.previous_line != gb_lcd.current_line ) {
775774            /* Also refresh border here??? */
776775            if ( gb_lcd.current_line < 144 ) {
777               rectangle r = Machine->screen[0].visarea;
776               rectangle r = machine->screen[0].visarea;
778777               r.min_x = SGB_XOFFSET;
779778               r.max_x -= SGB_XOFFSET;
780779               r.min_y = r.max_y = gb_lcd.current_line + SGB_YOFFSET;
781               fillbitmap(bitmap, Machine->pens[0], &r);
780               fillbitmap(bitmap, machine->pens[0], &r);
782781            }
783782            gb_lcd.previous_line = gb_lcd.current_line;
784783         }
r1905r1906
790789
791790/* --- Gameboy Color Specific --- */
792791
793INLINE void cgb_update_sprites (void) {
792INLINE void cgb_update_sprites ( running_machine *machine ) {
794793   bitmap_t *bitmap = tmpbitmap;
795794   UINT8 height, tilemask, line, *oam;
796795   int i, xindex, yindex;
r1905r1906
844843            {
845844               register int colour = ((data & 0x0100) ? 2 : 0) | ((data & 0x0001) ? 1 : 0);
846845               if (colour && !bg_zbuf[xindex] && xindex >= 0 && xindex < 160)
847                  gb_plot_pixel(bitmap, xindex, yindex, Machine->pens[cgb_spal[pal + colour]]);
846                  gb_plot_pixel(bitmap, xindex, yindex, machine->pens[cgb_spal[pal + colour]]);
848847               data >>= 1;
849848            }
850849            break;
r1905r1906
855854               if((bg_zbuf[xindex] & 0x80) && (bg_zbuf[xindex] & 0x7f) && (LCDCONT & 0x1))
856855                  colour = 0;
857856               if (colour && xindex >= 0 && xindex < 160)
858                  gb_plot_pixel(bitmap, xindex, yindex, Machine->pens[cgb_spal[pal + colour]]);
857                  gb_plot_pixel(bitmap, xindex, yindex, machine->pens[cgb_spal[pal + colour]]);
859858               data >>= 1;
860859            }
861860            break;
r1905r1906
864863            {
865864               register int colour = ((data & 0x8000) ? 2 : 0) | ((data & 0x0080) ? 1 : 0);
866865               if (colour && !bg_zbuf[xindex] && xindex >= 0 && xindex < 160)
867                  gb_plot_pixel(bitmap, xindex, yindex, Machine->pens[cgb_spal[pal + colour]]);
866                  gb_plot_pixel(bitmap, xindex, yindex, machine->pens[cgb_spal[pal + colour]]);
868867               data <<= 1;
869868            }
870869            break;
r1905r1906
875874               if((bg_zbuf[xindex] & 0x80) && (bg_zbuf[xindex] & 0x7f) && (LCDCONT & 0x1))
876875                  colour = 0;
877876               if (colour && xindex >= 0 && xindex < 160)
878                  gb_plot_pixel(bitmap, xindex, yindex, Machine->pens[cgb_spal[pal + colour]]);
877                  gb_plot_pixel(bitmap, xindex, yindex, machine->pens[cgb_spal[pal + colour]]);
879878               data <<= 1;
880879            }
881880            break;
r1905r1906
885884   }
886885}
887886
888static void cgb_update_scanline (void) {
887static void cgb_update_scanline ( running_machine *machine ) {
889888   bitmap_t *bitmap = tmpbitmap;
890889
891890   profiler_mark(PROFILER_VIDEO);
r1905r1906
938937         gb_lcd.end_x = MIN(160 - cycles_to_go,160);
939938         /* Draw empty line when the background is disabled */
940939         if ( ! ( LCDCONT & 0x01 ) ) {
941            rectangle r = Machine->screen[0].visarea;
940            rectangle r = machine->screen[0].visarea;
942941            r.min_y = r.max_y = gb_lcd.current_line;
943942            r.min_x = gb_lcd.start_x;
944943            r.max_x = gb_lcd.end_x - 1;
945            fillbitmap( bitmap, Machine->pens[ ( gbc_mode == GBC_MODE_MONO ) ? 0 : 32767 ], &r );
944            fillbitmap( bitmap, machine->pens[ ( gbc_mode == GBC_MODE_MONO ) ? 0 : 32767 ], &r );
946945         }
947946         while ( l < 2 ) {
948947            UINT8   xindex, *map, *tiles, *gbcmap;
r1905r1906
991990                     colour = ( ( data & 0x8000 ) ? 2 : 0 ) | ( ( data & 0x0080 ) ? 1 : 0 );
992991                     data <<= 1;
993992                  }
994                  gb_plot_pixel( bitmap, xindex, gb_lcd.current_line, Machine->pens[ cgb_bpal[ ( ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x07 ) * 4 ) + colour ] ] );
993                  gb_plot_pixel( bitmap, xindex, gb_lcd.current_line, machine->pens[ cgb_bpal[ ( ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x07 ) * 4 ) + colour ] ] );
995994                  bg_zbuf[ xindex ] = colour + ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x80 );
996995                  xindex++;
997996                  gb_lcd.layer[l].xshift++;
r1905r1906
10221021            l++;
10231022         }
10241023         if ( gb_lcd.end_x == 160 && ( LCDCONT & 0x02 ) ) {
1025            cgb_update_sprites();
1024            cgb_update_sprites( machine );
10261025         }
10271026         gb_lcd.start_x = gb_lcd.end_x;
10281027      }
r1905r1906
10311030         /* Draw an empty line when LCD is disabled */
10321031         if ( gb_lcd.previous_line != gb_lcd.current_line ) {
10331032            if ( gb_lcd.current_line < 144 ) {
1034               rectangle r = Machine->screen[0].visarea;
1033               rectangle r = machine->screen[0].visarea;
10351034               r.min_y = r.max_y = gb_lcd.current_line;
1036               fillbitmap( bitmap, Machine->pens[ ( gbc_mode == GBC_MODE_MONO ) ? 0 : 32767 ], &r );
1035               fillbitmap( bitmap, machine->pens[ ( gbc_mode == GBC_MODE_MONO ) ? 0 : 32767 ], &r );
10371036            }
10381037            gb_lcd.previous_line = gb_lcd.current_line;
10391038         }
r1905r1906
11611160   switch( mode ) {
11621161   case GB_VIDEO_CGB:   vram_size = 0x4000; break;
11631162   }
1164   gb_vram = new_memory_region( Machine, REGION_GFX1, vram_size, 0 );
1165   gb_oam = new_memory_region( Machine, REGION_GFX2, 0x100, 0 );
1163   gb_vram = new_memory_region( machine, REGION_GFX1, vram_size, 0 );
1164   gb_oam = new_memory_region( machine, REGION_GFX2, 0x100, 0 );
11661165   memset( gb_vram, 0, vram_size );
11671166   memset( &gb_lcd, 0, sizeof(gb_lcd) );
11681167
r1905r1906
13491348         break;
13501349      case GB_LCD_STATE_LYXX_M0:      /* Switch to mode 0 */
13511350         /* update current scanline */
1352         update_scanline();
1351         update_scanline( machine );
13531352         /* Increment the number of window lines drawn if enabled */
13541353         if ( gb_lcd.layer[1].enabled ) {
13551354            gb_lcd.window_lines_drawn++;
r1905r1906
15501549   } else {
15511550      gb_increment_scanline();
15521551      if ( gb_lcd.current_line < 144 ) {
1553         update_scanline();
1552         update_scanline( machine );
15541553      }
15551554      timer_adjust_oneshot(gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(456,0), 0);
15561555   }
r1905r1906
15801579         break;
15811580      case GB_LCD_STATE_LYXX_M0:      /* Switch to mode 0 */
15821581         /* update current scanline */
1583         update_scanline();
1582         update_scanline( machine );
15841583         /* Increment the number of window lines drawn if enabled */
15851584         if ( gb_lcd.layer[1].enabled ) {
15861585            gb_lcd.window_lines_drawn++;
r1905r1906
18011800   } else {
18021801      gb_increment_scanline();
18031802      if ( gb_lcd.current_line < 144 ) {
1804         update_scanline();
1803         update_scanline( machine );
18051804      }
18061805      timer_adjust_oneshot(gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(456,0), 0);
18071806   }
18081807}
18091808
1810static void gb_lcd_switch_on( void ) {
1809static void gb_lcd_switch_on( running_machine *machine ) {
18111810   gb_lcd.current_line = 0;
18121811   gb_lcd.previous_line = 153;
18131812   gb_lcd.window_lines_drawn = 0;
r1905r1906
18201819      LCDSTAT |= 0x04;
18211820      /* Generate lcd interrupt if requested */
18221821      if ( LCDSTAT & 0x40 ) {
1823         cpunum_set_input_line( Machine, 0, LCD_INT, HOLD_LINE );
1822         cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
18241823      }
18251824   }
18261825   gb_lcd.state = GB_LCD_STATE_LY00_M2;
r1905r1906
18691868      }
18701869      /* If LCD is being switched on */
18711870      if ( !( LCDCONT & 0x80 ) && ( data & 0x80 ) ) {
1872         gb_lcd_switch_on();
1871         gb_lcd_switch_on( machine );
18731872      }
18741873      break;
18751874   case 0x01:                  /* STAT - LCD Status */
r1905r1906
19011900            ( ( LCDSTAT & 0x60 ) == 0x00 && ( data & 0x60 ) == 0x20 ) ||
19021901            ( ( LCDSTAT & 0x60 ) == 0x20 && ( data & 0x40 ) )
19031902            ) ) {
1904            cpunum_set_input_line( Machine, 0, LCD_INT, HOLD_LINE );
1903            cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
19051904         }
19061905         /*
19071906            - 0x20 -> 0x08/0x18/0x28/0x48 (mode 0, after m2int) - trigger
r1905r1906
19091908            - 0x00 -> 0xXX (mode 0) - trigger stat bug
19101909         */
19111910         if ( gb_lcd.mode_irq && gb_lcd.mode == 0 ) {
1912            cpunum_set_input_line( Machine, 0, LCD_INT, HOLD_LINE );
1911            cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
19131912         }
19141913      }
19151914      break;
r1905r1906
19221921               LCDSTAT |= 0x04;
19231922               /* Generate lcd interrupt if requested */
19241923               if ( LCDSTAT & 0x40 ) {
1925                  cpunum_set_input_line( Machine, 0, LCD_INT, HOLD_LINE );
1924                  cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
19261925               }
19271926            }
19281927         } else {
r1905r1906
19401939      }
19411940      return;
19421941   case 0x07:                  /* BGP - Background Palette */
1943      update_scanline();
1942      update_scanline( machine );
19441943      gb_bpal[0] = data & 0x3;
19451944      gb_bpal[1] = (data & 0xC) >> 2;
19461945      gb_bpal[2] = (data & 0x30) >> 4;
19471946      gb_bpal[3] = (data & 0xC0) >> 6;
19481947      break;
19491948   case 0x08:                  /* OBP0 - Object Palette 0 */
1950//      update_scanline();
1949//      update_scanline( machine );
19511950      gb_spal0[0] = data & 0x3;
19521951      gb_spal0[1] = (data & 0xC) >> 2;
19531952      gb_spal0[2] = (data & 0x30) >> 4;
19541953      gb_spal0[3] = (data & 0xC0) >> 6;
19551954      break;
19561955   case 0x09:                  /* OBP1 - Object Palette 1 */
1957//      update_scanline();
1956//      update_scanline( machine );
19581957      gb_spal1[0] = data & 0x3;
19591958      gb_spal1[1] = (data & 0xC) >> 2;
19601959      gb_spal1[2] = (data & 0x30) >> 4;
r1905r1906
19621961      break;
19631962   case 0x02:                  /* SCY - Scroll Y */
19641963   case 0x03:                  /* SCX - Scroll X */
1965      update_scanline();
1964      update_scanline( machine );
19661965   case 0x0A:                  /* WY - Window Y position */
19671966   case 0x0B:                  /* WX - Window X position */
19681967      break;
r1905r1906
20122011      }
20132012      /* If LCD is being switched on */
20142013      if ( !( LCDCONT & 0x80 ) && ( data & 0x80 ) ) {
2015         gb_lcd_switch_on();
2014         gb_lcd_switch_on( machine );
20162015      }
20172016      break;
20182017   case 0x01:      /* STAT - LCD Status */
r1905r1906
20222021            - 0x20 -> 0x08/0x18/0x28/0x48 (mode 0, after m2int) - trigger
20232022         */
20242023         if ( gb_lcd.mode_irq && gb_lcd.mode == 0 && ( LCDSTAT & 0x28 ) == 0x20 && ( data & 0x08 ) ) {
2025            cpunum_set_input_line( Machine, 0, LCD_INT, HOLD_LINE );
2024            cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
20262025         }
20272026         /* Check if line irqs are being disabled */
20282027         if ( ! ( data & 0x40 ) ) {
r1905r1906
20322031         if ( ! ( LCDSTAT & 0x40 ) && ( data & 0x40 ) ) {
20332032            if ( CMPLINE == CURLINE ) {
20342033               gb_lcd.line_irq = 1;
2035               cpunum_set_input_line( Machine, 0, LCD_INT, HOLD_LINE );
2034               cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
20362035            }
20372036         }
20382037      }
r1905r1906
20442043            LCDSTAT |= 0x04;
20452044            /* Generate lcd interrupt if requested */
20462045            if ( LCDSTAT & 0x40 ) {
2047               cpunum_set_input_line( Machine, 0, LCD_INT, HOLD_LINE );
2046               cpunum_set_input_line( machine, 0, LCD_INT, HOLD_LINE );
20482047            }
20492048         } else {
20502049            LCDSTAT &= 0xFB;
r1905r1906
20562055   case 0x07:      /* BGP - GB background palette */
20572056      /* Some GBC games are lazy and still call this */
20582057      if( gbc_mode == GBC_MODE_MONO ) {
2059         update_scanline();
2058         update_scanline( machine );
20602059         cgb_bpal[0] = gbc_to_gb_pal[(data & 0x03)];
20612060         cgb_bpal[1] = gbc_to_gb_pal[(data & 0x0C) >> 2];
20622061         cgb_bpal[2] = gbc_to_gb_pal[(data & 0x30) >> 4];

Previous 15994 Revisions Next


© 1998-2018 The MESS Team