src/mess/video/gb.c
| r1445 | r1446 | |
| 90 | 90 | int line_irq; |
| 91 | 91 | int mode_irq; |
| 92 | 92 | int delayed_line_irq; |
| 93 | int sprite_cycles; |
| 93 | 94 | int scrollx_adjust; |
| 94 | 95 | struct layer_struct layer[2]; |
| 95 | 96 | emu_timer *lcd_timer; |
| r1445 | r1446 | |
| 196 | 197 | Select which sprites should be drawn for the current scanline and return the |
| 197 | 198 | number of sprites selected. |
| 198 | 199 | */ |
| 199 | | static int gb_select_sprites( void ) { |
| 200 | static void gb_select_sprites( void ) { |
| 200 | 201 | int i, yindex, line, height; |
| 201 | 202 | UINT8 *oam = gb_oam + 39 * 4; |
| 202 | 203 | |
| r1445 | r1446 | |
| 223 | 224 | gb_lcd.sprCount++; |
| 224 | 225 | } |
| 225 | 226 | } |
| 227 | oam -= 4; |
| 226 | 228 | } |
| 227 | 229 | } |
| 228 | | return gb_lcd.sprCount; |
| 229 | 230 | } |
| 230 | 231 | |
| 231 | 232 | INLINE void gb_update_sprites (void) |
| r1445 | r1446 | |
| 1277 | 1278 | |
| 1278 | 1279 | static TIMER_CALLBACK(gb_lcd_timer_proc) |
| 1279 | 1280 | { |
| 1281 | static const int sprite_cycles[] = { 0, 8, 20, 32, 44, 52, 64, 76, 88, 96, 108 }; |
| 1280 | 1282 | int mode = param; |
| 1283 | |
| 1281 | 1284 | if ( LCDCONT & 0x80 ) { |
| 1282 | 1285 | switch( mode ) { |
| 1283 | 1286 | case GB_LCD_STATE_LYXX_PRE_M0: /* Just before switching to mode 0 */ |
| r1445 | r1446 | |
| 1313 | 1316 | /* Check for HBLANK DMA */ |
| 1314 | 1317 | if( gbc_hdma_enabled ) |
| 1315 | 1318 | gbc_hdma(0x10); |
| 1316 | | timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(196 - gb_lcd.scrollx_adjust - 10 * gb_lcd.sprCount,0), GB_LCD_STATE_LYXX_M0_PRE_INC, attotime_never ); |
| 1319 | timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(196 - gb_lcd.scrollx_adjust - gb_lcd.sprite_cycles,0), GB_LCD_STATE_LYXX_M0_PRE_INC, attotime_never ); |
| 1317 | 1320 | break; |
| 1318 | 1321 | case GB_LCD_STATE_LYXX_M0_PRE_INC: /* Just before incrementing the line counter go to mode 2 internally */ |
| 1319 | 1322 | if ( CURLINE < 143 ) { |
| r1445 | r1446 | |
| 1386 | 1389 | break; |
| 1387 | 1390 | case GB_LCD_STATE_LYXX_M3: /* Switch to mode 3 */ |
| 1388 | 1391 | gb_select_sprites(); |
| 1392 | gb_lcd.sprite_cycles = sprite_cycles[ gb_lcd.sprCount ]; |
| 1389 | 1393 | /* Set Mode 3 lcdstate */ |
| 1390 | 1394 | gb_lcd.mode = 3; |
| 1391 | 1395 | LCDSTAT = (LCDSTAT & 0xFC) | 0x03; |
| r1445 | r1446 | |
| 1395 | 1399 | } else { |
| 1396 | 1400 | gb_lcd.scrollx_adjust = 0; |
| 1397 | 1401 | } |
| 1398 | | /* Mode 3 lasts for approximately 172+#sprites*10 clock cycles */ |
| 1399 | | timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(168 + gb_lcd.scrollx_adjust + 10 * gb_lcd.sprCount,0), GB_LCD_STATE_LYXX_PRE_M0, attotime_never ); |
| 1402 | /* Mode 3 lasts for approximately 172+cycles needed to handle sprites clock cycles */ |
| 1403 | timer_adjust( gb_lcd.lcd_timer, ATTOTIME_IN_CYCLES(168 + gb_lcd.scrollx_adjust + gb_lcd.sprite_cycles,0), GB_LCD_STATE_LYXX_PRE_M0, attotime_never ); |
| 1400 | 1404 | gb_lcd.start_x = 0; |
| 1401 | 1405 | break; |
| 1402 | 1406 | case GB_LCD_STATE_LY9X_M1: /* Switch to or stay in mode 1 */ |