Last active
November 9, 2016 01:08
-
-
Save cesarmiquel/6cbbe361c1b649cf9e8e60e77c80728a to your computer and use it in GitHub Desktop.
Useful routines / snippets of GB Z80 code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; | |
; These come from: | |
; https://github.com/pret/pokered/blob/master/home.asm | |
; | |
; ---------------------------------------------------------------------------------------- | |
; Disable LCD | |
; ---------------------------------------------------------------------------------------- | |
DisableLCD:: | |
xor a | |
ld [rIF], a | |
ld a, [rIE] | |
ld b, a | |
res 0, a | |
ld [rIE], a | |
.wait | |
ld a, [rLY] | |
cp LY_VBLANK | |
jr nz, .wait | |
ld a, [rLCDC] | |
and $ff ^ rLCDC_ENABLE_MASK | |
ld [rLCDC], a | |
ld a, b | |
ld [rIE], a | |
ret | |
; ---------------------------------------------------------------------------------------- | |
; Enable LCD | |
; ---------------------------------------------------------------------------------------- | |
EnableLCD:: | |
ld a, [rLCDC] | |
set rLCDC_ENABLE, a | |
ld [rLCDC], a | |
ret | |
; ---------------------------------------------------------------------------------------- | |
; Clear OAM sprite data | |
; ---------------------------------------------------------------------------------------- | |
ClearSprites:: | |
xor a | |
ld hl, wOAMBuffer | |
ld b, 40 * 4 | |
.loop | |
ld [hli], a | |
dec b | |
jr nz, .loop | |
ret | |
; ---------------------------------------------------------------------------------------- | |
; Hide all sprites | |
; ---------------------------------------------------------------------------------------- | |
HideSprites:: | |
ld a, 160 | |
ld hl, wOAMBuffer | |
ld de, 4 | |
ld b, 40 | |
.loop | |
ld [hl], a | |
add hl, de | |
dec b | |
jr nz, .loop | |
ret | |
; ---------------------------------------------------------------------------------------- | |
; Wait for VBlank - Looses content of A register and flags. | |
; ---------------------------------------------------------------------------------------- | |
WaitVBlank: | |
ld a, [rLY] | |
cp LY_VBLANK | |
jr nz, WaitVBlank | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment