summaryrefslogtreecommitdiff
path: root/src/home/lcd.asm
diff options
context:
space:
mode:
authorDaniel Harding <33dannye@gmail.com>2021-09-19 00:21:14 -0500
committerGitHub <noreply@github.com>2021-09-19 00:21:14 -0500
commitdf67aac83b466dadf5f74c881bf84dd9ef19bdfc (patch)
tree47501aced2d256052b8f78bc97328d5af5703add /src/home/lcd.asm
parente4bce9b7ee5e89f8edfd921de2379f0fa06af206 (diff)
parent8dee6b7a11e85d6d4b9f8ec9fb9d53a499fd37dc (diff)
Merge pull request #110 from ElectroDeoxys/master
Split Home bank
Diffstat (limited to 'src/home/lcd.asm')
-rw-r--r--src/home/lcd.asm83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/home/lcd.asm b/src/home/lcd.asm
new file mode 100644
index 0000000..5e8fc5d
--- /dev/null
+++ b/src/home/lcd.asm
@@ -0,0 +1,83 @@
+; wait for VBlankHandler to finish unless lcd is off
+WaitForVBlank:
+ push hl
+ ld a, [wLCDC]
+ bit LCDC_ENABLE_F, a
+ jr z, .lcd_off
+ ld hl, wVBlankCounter
+ ld a, [hl]
+.wait_vblank
+ halt
+ nop
+ cp [hl]
+ jr z, .wait_vblank
+.lcd_off
+ pop hl
+ ret
+
+; turn LCD on
+EnableLCD:
+ ld a, [wLCDC] ;
+ bit LCDC_ENABLE_F, a ;
+ ret nz ; assert that LCD is off
+ or LCDC_ON ;
+ ld [wLCDC], a ;
+ ldh [rLCDC], a ; turn LCD on
+ ld a, FLUSH_ALL_PALS
+ ld [wFlushPaletteFlags], a
+ ret
+
+; wait for vblank, then turn LCD off
+DisableLCD:
+ ldh a, [rLCDC] ;
+ bit LCDC_ENABLE_F, a ;
+ ret z ; assert that LCD is on
+ ldh a, [rIE]
+ ld [wIE], a
+ res INT_VBLANK, a ;
+ ldh [rIE], a ; disable vblank interrupt
+.wait_vblank
+ ldh a, [rLY] ;
+ cp LY_VBLANK ;
+ jr nz, .wait_vblank ; wait for vblank
+ ldh a, [rLCDC] ;
+ and LCDC_OFF ;
+ ldh [rLCDC], a ;
+ ld a, [wLCDC] ;
+ and LCDC_OFF ;
+ ld [wLCDC], a ; turn LCD off
+ xor a
+ ldh [rBGP], a
+ ldh [rOBP0], a
+ ldh [rOBP1], a
+ ld a, [wIE]
+ ldh [rIE], a
+ ret
+
+; set OBJ size: 8x8
+Set_OBJ_8x8:
+ ld a, [wLCDC]
+ and LCDC_OBJ8
+ ld [wLCDC], a
+ ret
+
+; set OBJ size: 8x16
+Set_OBJ_8x16:
+ ld a, [wLCDC]
+ or LCDC_OBJ16
+ ld [wLCDC], a
+ ret
+
+; set Window Display on
+Set_WD_on:
+ ld a, [wLCDC]
+ or LCDC_WINON
+ ld [wLCDC], a
+ ret
+
+; set Window Display off
+Set_WD_off:
+ ld a, [wLCDC]
+ and LCDC_WINOFF
+ ld [wLCDC], a
+ ret