src/mess/video/gb.c
| r1056 | r1057 | |
| 1184 | 1184 | gb_lcd.lcd_int_state = lcd_int_state; |
| 1185 | 1185 | } |
| 1186 | 1186 | |
| 1187 | enum { |
| 1188 | GB_LCD_STATE_LY00_M2=1, |
| 1189 | GB_LCD_STATE_LYXX_M3, |
| 1190 | GB_LCD_STATE_LYXX_M0, |
| 1191 | GB_LCD_STATE_LYXX_M2, |
| 1192 | GB_LCD_STATE_LY9X_M1, |
| 1193 | GB_LCD_STATE_LY00_M1, |
| 1194 | GB_LCD_STATE_LY00_M0 |
| 1195 | }; |
| 1196 | |
| 1187 | 1197 | static TIMER_CALLBACK(gb_lcd_timer_proc) |
| 1188 | 1198 | { |
| 1189 | 1199 | int mode = param; |
| 1190 | 1200 | if ( LCDCONT & 0x80 ) { |
| 1191 | 1201 | switch( mode ) { |
| 1192 | | case 0: /* Switch to mode 0 */ |
| 1202 | case GB_LCD_STATE_LYXX_M0: /* Switch to mode 0 */ |
| 1193 | 1203 | /* update current scanline */ |
| 1194 | 1204 | update_scanline(); |
| 1195 | 1205 | /* Increment the number of window lines drawn if enabled */ |
| r1056 | r1057 | |
| 1205 | 1215 | if( gbc_hdma_enabled ) |
| 1206 | 1216 | gbc_hdma(0x10); |
| 1207 | 1217 | if ( CURLINE == 143 ) { |
| 1208 | | mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(204 - 10 * gb_lcd.sprCount,0), 1, time_never ); |
| 1218 | mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(204 - 10 * gb_lcd.sprCount,0), GB_LCD_STATE_LY9X_M1, time_never ); |
| 1209 | 1219 | } else { |
| 1210 | | mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(204 - 10 * gb_lcd.sprCount,0), 2, time_never ); |
| 1220 | mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(204 - 10 * gb_lcd.sprCount,0), GB_LCD_STATE_LYXX_M2, time_never ); |
| 1211 | 1221 | } |
| 1212 | 1222 | break; |
| 1213 | | case 2: /* Switch to mode 2 */ |
| 1223 | case GB_LCD_STATE_LYXX_M2: /* Switch to mode 2 */ |
| 1214 | 1224 | gb_increment_scanline(); |
| 1215 | | case 5: /* on scanline 0, don't increment the current line counter */ |
| 1216 | 1225 | /* Set Mode 2 lcdstate */ |
| 1217 | 1226 | LCDSTAT = (LCDSTAT & 0xFC) | 0x02; |
| 1218 | 1227 | /* Generate lcd interrupt if requested */ |
| 1219 | 1228 | gb_lcd_int_check(); |
| 1220 | 1229 | /* Mode 2 last for approximately 80 clock cycles */ |
| 1221 | | mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(80,0), 3, time_never ); |
| 1230 | mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(80,0), GB_LCD_STATE_LYXX_M3, time_never ); |
| 1222 | 1231 | break; |
| 1223 | | case 3: /* Switch to mode 3 */ |
| 1232 | case GB_LCD_STATE_LY00_M2: /* on scanline 0, don't increment the current line counter */ |
| 1233 | /* Set Mode 2 lcdstate */ |
| 1234 | LCDSTAT = (LCDSTAT & 0xFC) | 0x02; |
| 1235 | /* Generate lcd interrupt if requested */ |
| 1236 | gb_lcd_int_check(); |
| 1237 | /* Mode 2 last for approximately 80 clock cycles */ |
| 1238 | mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(76,0), GB_LCD_STATE_LYXX_M3, time_never ); |
| 1239 | break; |
| 1240 | case GB_LCD_STATE_LYXX_M3: /* Switch to mode 3 */ |
| 1224 | 1241 | gb_select_sprites(); |
| 1225 | 1242 | /* Set Mode 3 lcdstate */ |
| 1226 | 1243 | LCDSTAT = (LCDSTAT & 0xFC) | 0x03; |
| 1227 | 1244 | gb_lcd_int_check(); |
| 1228 | 1245 | /* Mode 3 lasts for approximately 172+#sprites*10 clock cycles */ |
| 1229 | | mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(172 + 10 * gb_lcd.sprCount,0), 0, time_never ); |
| 1246 | mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(172 + 10 * gb_lcd.sprCount,0), GB_LCD_STATE_LYXX_M0, time_never ); |
| 1230 | 1247 | gb_lcd.start_x = 0; |
| 1231 | 1248 | break; |
| 1232 | | case 1: /* Switch to or stay in mode 1 */ |
| 1249 | case GB_LCD_STATE_LY9X_M1: /* Switch to or stay in mode 1 */ |
| 1233 | 1250 | gb_increment_scanline(); |
| 1234 | 1251 | if ( CURLINE == 144 ) { |
| 1235 | 1252 | /* Trigger VBlank interrupt generation */ |
| r1056 | r1057 | |
| 1239 | 1256 | /* Trigger LCD interrupt if requested */ |
| 1240 | 1257 | gb_lcd_int_check(); |
| 1241 | 1258 | } |
| 1242 | | if ( gb_lcd.current_line == 153 ) { |
| 1243 | | mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(24,0), 4, time_never ); |
| 1244 | | } else { |
| 1245 | | mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(456,0), 1, time_never ); |
| 1259 | switch( gb_lcd.current_line ) { |
| 1260 | case 153: |
| 1261 | mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(6,0), GB_LCD_STATE_LY00_M1, time_never ); |
| 1262 | break; |
| 1263 | case 152: |
| 1264 | mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(452,0), GB_LCD_STATE_LY9X_M1, time_never ); |
| 1265 | break; |
| 1266 | default: |
| 1267 | mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(456,0), GB_LCD_STATE_LY9X_M1, time_never ); |
| 1246 | 1268 | } |
| 1247 | 1269 | break; |
| 1248 | | case 4: /* we stay in VBlank but current line counter should already be incremented */ |
| 1270 | case GB_LCD_STATE_LY00_M1: /* we stay in VBlank but current line counter should already be incremented */ |
| 1249 | 1271 | gb_increment_scanline(); |
| 1250 | | mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(456-24,0), 5, time_never ); |
| 1272 | mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(456-(2),0), GB_LCD_STATE_LY00_M0, time_never ); |
| 1251 | 1273 | break; |
| 1274 | case GB_LCD_STATE_LY00_M0: /* The STAT register seems to go to 0 for about 4 cycles */ |
| 1275 | /* Set Mode 0 lcdstat */ |
| 1276 | LCDSTAT = ( LCDSTAT & 0xFC ); |
| 1277 | gb_lcd_int_check(); |
| 1278 | mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(4,0), GB_LCD_STATE_LY00_M2, time_never ); |
| 1279 | break; |
| 1280 | |
| 1252 | 1281 | } |
| 1253 | 1282 | } else { |
| 1254 | 1283 | gb_increment_scanline(); |
| r1056 | r1057 | |
| 1270 | 1299 | /* Generate lcd interrupt if requested */ |
| 1271 | 1300 | gb_lcd_int_check(); |
| 1272 | 1301 | } |
| 1273 | | mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(80,0), 3, time_never ); |
| 1302 | mame_timer_adjust( gb_lcd.lcd_timer, MAME_TIME_IN_CYCLES(80,0), GB_LCD_STATE_LYXX_M3, time_never ); |
| 1274 | 1303 | } |
| 1275 | 1304 | |
| 1276 | 1305 | READ8_HANDLER( gb_video_r ) { |
| 1277 | | /* When reading STAT make sure the timers are up to date */ |
| 1278 | | if ( offset == 0x01 ) { |
| 1306 | if ( offset == 0x01 || offset == 0x04 ) { |
| 1307 | if ( 0 && activecpu_get_pc() > 0x100 ) { |
| 1308 | logerror("LCDSTAT/LY read, cycles left is %d\n", (int)MAME_TIME_TO_CYCLES(0,mame_timer_timeleft( gb_lcd.lcd_timer )) ); |
| 1309 | } |
| 1310 | if ( offset == 0x01 || (int)MAME_TIME_TO_CYCLES(0,mame_timer_timeleft( gb_lcd.lcd_timer)) < 0 ) |
| 1279 | 1311 | mame_timer_set_global_time(mame_timer_get_time()); |
| 1280 | | } |
| 1312 | } |
| 1281 | 1313 | return gb_vid_regs[offset]; |
| 1282 | 1314 | } |
| 1283 | 1315 | |