Update 'src/include/globals.asm'
This commit is contained in:
		
							parent
							
								
									0c8ed9c424
								
							
						
					
					
						commit
						1f7f17a353
					
				| 
						 | 
					@ -6,32 +6,37 @@ INCLUDE "hardware.inc"
 | 
				
			||||||
INCLUDE "structs.asm"
 | 
					INCLUDE "structs.asm"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
; Waits for VRAM to be safe to access. (Includes hblank.)
 | 
					; PPU modes:
 | 
				
			||||||
 | 
					; - 0: HBlank
 | 
				
			||||||
 | 
					; - 1: VBlank
 | 
				
			||||||
 | 
					; - 2: OAM Scan
 | 
				
			||||||
 | 
					; - 3: Drawing
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Waits for PPU mode to be 0 or 1.
 | 
				
			||||||
 | 
					; We don't wait for 2 because it's super short and impractical to do much of anything in.
 | 
				
			||||||
MACRO wait_vram
 | 
					MACRO wait_vram
 | 
				
			||||||
.waitvram\@
 | 
					    ld hl, rSTAT
 | 
				
			||||||
    ldh a, [rSTAT]
 | 
					:   bit 1, [hl]
 | 
				
			||||||
    and STATF_BUSY
 | 
					    jr nz, :-
 | 
				
			||||||
    jr nz, .waitvram\@
 | 
					 | 
				
			||||||
ENDM
 | 
					ENDM
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
; Waits for lcd to be in vblank.
 | 
					; Waits for PPU mode to be at the start of mode 1.
 | 
				
			||||||
 | 
					; We do this by checking for scanline 144.
 | 
				
			||||||
MACRO wait_vblank
 | 
					MACRO wait_vblank
 | 
				
			||||||
.waitvb\@
 | 
					    ld b, 144
 | 
				
			||||||
    ldh a, [rSTAT]
 | 
					:   ldh a, [rLY]
 | 
				
			||||||
    and STATF_LCD
 | 
					    cp a, b
 | 
				
			||||||
    cp STATF_VBL
 | 
					    jr nz, :-
 | 
				
			||||||
    jr nz, .waitvb\@
 | 
					 | 
				
			||||||
ENDM
 | 
					ENDM
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
; Waits for lcd to not be in vblank.
 | 
					; Waits for PPU mode to be at the end of mode 1.
 | 
				
			||||||
 | 
					; We do this by checking for scanline 0.
 | 
				
			||||||
MACRO wait_vblank_end
 | 
					MACRO wait_vblank_end
 | 
				
			||||||
.waitvbe\@
 | 
					:   ldh a, [rLY]
 | 
				
			||||||
    ldh a, [rSTAT]
 | 
					    jr nz, :-
 | 
				
			||||||
    and STATF_LCD
 | 
					 | 
				
			||||||
    cp STATF_VBL
 | 
					 | 
				
			||||||
    jr z, .waitvbe\@
 | 
					 | 
				
			||||||
ENDM
 | 
					ENDM
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue