shithub: pokecrystal

Download patch

ref: 3c6c80f1b24487ae4aa9d250d1dff290f09c231e
parent: 69762a2bfd6b6134b99a24b3c8f091ff6a410ef9
author: xCrystal <rgr.crystal@gmail.com>
date: Fri Dec 29 13:53:21 EST 2017

LY_BLANK and rLCDC constants

--- a/constants/hardware_constants.asm
+++ b/constants/hardware_constants.asm
@@ -114,10 +114,16 @@
 rWave_e     EQU $ff3e
 rWave_f     EQU $ff3f
 rLCDC       EQU $ff40 ; LCD Control (R/W)
+rLCDC_SPRITE_ENABLE  EQU 1
+rLCDC_SPRITE_SIZE    EQU 2
+rLCDC_WINDOW_TILEMAP EQU 6
+rLCDC_ENABLE         EQU 7
+rLCDC_DEFAULT        EQU %11100011
 rSTAT       EQU $ff41 ; LCDC Status (R/W)
 rSCY        EQU $ff42 ; Scroll Y (R/W)
 rSCX        EQU $ff43 ; Scroll X (R/W)
 rLY         EQU $ff44 ; LCDC Y-Coordinate (R)
+LY_VBLANK   EQU 144
 rLYC        EQU $ff45 ; LY Compare (R/W)
 rDMA        EQU $ff46 ; DMA Transfer and Start Address (W)
 rBGP        EQU $ff47 ; BG Palette Data (R/W) - Non CGB Mode Only
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -8395,11 +8395,11 @@
 	ld b, SCGB_BATTLE_GRAYSCALE
 	call GetSGBLayout
 	ld hl, rLCDC
-	res 6, [hl]
+	res rLCDC_WINDOW_TILEMAP, [hl] ; select 9800-9BFF
 	call InitBattleDisplay
 	call BattleStartMessage
 	ld hl, rLCDC
-	set 6, [hl]
+	set rLCDC_WINDOW_TILEMAP, [hl] ; select 9C00-9FFF
 	xor a
 	ld [hBGMapMode], a
 	call EmptyBattleTextBox
--- a/engine/color.asm
+++ b/engine/color.asm
@@ -617,7 +617,7 @@
 
 ApplyAttrMap:
 	ld a, [rLCDC]
-	bit 7, a
+	bit rLCDC_ENABLE, a
 	jr z, .UpdateVBank1
 	ld a, [hBGMapMode]
 	push af
@@ -1073,7 +1073,7 @@
 	ld bc, $100 tiles
 	call CopyData
 	call DrawDefaultTiles
-	ld a, $e3
+	ld a, rLCDC_DEFAULT
 	ld [rLCDC], a
 	ld hl, PalPacket_9d06
 	call PushSGBPals
@@ -1107,7 +1107,7 @@
 	ld bc, 16 palettes
 	call CopyData
 	call DrawDefaultTiles
-	ld a, $e3
+	ld a, rLCDC_DEFAULT
 	ld [rLCDC], a
 	ld hl, PalPacket_9d46
 	call PushSGBPals
@@ -1131,7 +1131,7 @@
 	dec b
 	jr nz, .loop
 	call DrawDefaultTiles
-	ld a, $e3
+	ld a, rLCDC_DEFAULT
 	ld [rLCDC], a
 	ld hl, PalPacket_9d36
 	call PushSGBPals
--- a/engine/dummy_game.asm
+++ b/engine/dummy_game.asm
@@ -34,7 +34,7 @@
 	ld [wJumptableIndex], a
 	ld a, $1
 	ld [hBGMapMode], a
-	ld a, $e3
+	ld a, rLCDC_DEFAULT
 	ld [rLCDC], a
 	ld a, $e4
 	call DmgToCgbBGPals
--- a/engine/intro_menu.asm
+++ b/engine/intro_menu.asm
@@ -1035,7 +1035,7 @@
 	ld [rSVBK], a
 
 	ld hl, rLCDC
-	res 2, [hl]
+	res rLCDC_SPRITE_SIZE, [hl] ; 8x8
 	call ClearScreen
 	call WaitBGMap2
 	xor a
--- a/engine/mystery_gift.asm
+++ b/engine/mystery_gift.asm
@@ -116,7 +116,7 @@
 
 .PrintTextAndExit: ; 1049c5 (41:49c5)
 	call PrintText
-	ld a, $e3
+	ld a, rLCDC_DEFAULT
 	ld [rLCDC], a
 	ret
 ; 1049cd (41:49cd)
@@ -262,7 +262,7 @@
 	; Delay frame
 .ly_loop
 	ld a, [rLY]
-	cp $90
+	cp LY_VBLANK
 	jr c, .ly_loop
 	ld c, LOW(rRP)
 	ld a, $c0
@@ -281,7 +281,7 @@
 	and b
 	ld b, a
 	ld a, [rLY]
-	cp $90
+	cp LY_VBLANK
 	jr nc, .ly_loop2
 .ly_loop3
 	ld a, [$ff00+c]
@@ -288,7 +288,7 @@
 	and b
 	ld b, a
 	ld a, [rLY]
-	cp $90
+	cp LY_VBLANK
 	jr c, .ly_loop3
 
 	ld a, b
@@ -1497,7 +1497,7 @@
 
 asm_105726: ; 105726 (41:5726)
 	call PrintText
-	ld a, $e3
+	ld a, rLCDC_DEFAULT
 	ld [rLCDC], a
 	ret
 ; 10572e (41:572e)
--- a/engine/namingscreen.asm
+++ b/engine/namingscreen.asm
@@ -48,7 +48,7 @@
 	call DisableLCD
 	call LoadNamingScreenGFX
 	call NamingScreen_InitText
-	ld a, $e3
+	ld a, rLCDC_DEFAULT
 	ld [rLCDC], a
 	call .GetNamingScreenSetup
 	call WaitBGMap
@@ -1017,7 +1017,7 @@
 	add hl, bc
 	ld [hl], $0
 	call .InitCharset
-	ld a, $e3
+	ld a, rLCDC_DEFAULT
 	ld [rLCDC], a
 	call .initwNamingScreenMaxNameLength
 	ld b, SCGB_DIPLOMA
--- a/engine/pokegear.asm
+++ b/engine/pokegear.asm
@@ -59,7 +59,7 @@
 	call InitPokegearModeIndicatorArrow
 	ld a, 8
 	call SkipMusic
-	ld a, $e3
+	ld a, rLCDC_DEFAULT
 	ld [rLCDC], a
 	call TownMap_InitCursorAndPlayerIconPositions
 	xor a
@@ -1851,7 +1851,7 @@
 	farcall ClearSpriteAnims
 	ld a, 8
 	call SkipMusic
-	ld a, $e3
+	ld a, rLCDC_DEFAULT
 	ld [rLCDC], a
 	call TownMap_GetCurrentLandmark
 	ld [wTownMapPlayerIconLandmark], a
--- a/engine/routines/getsquareroot.asm
+++ b/engine/routines/getsquareroot.asm
@@ -23,8 +23,8 @@
 	ret
 
 .Squares: ; 13b98
-root	set 1
+root = 1
 	rept $ff
-	dw root*root
-root	set root+1
+	dw root * root
+root = root + 1
 	endr
--- a/engine/routines/phonering_copytilemapatonce.asm
+++ b/engine/routines/phonering_copytilemapatonce.asm
@@ -17,7 +17,7 @@
 	ld [hMapAnims], a
 .wait
 	ld a, [rLY]
-	cp $8f
+	cp LY_VBLANK - 1
 	jr c, .wait
 
 	di
@@ -31,7 +31,7 @@
 	call .CopyTilemapAtOnce
 .wait2
 	ld a, [rLY]
-	cp $8f
+	cp LY_VBLANK - 1
 	jr c, .wait2
 	ei
 
--- a/engine/slot_machine.asm
+++ b/engine/slot_machine.asm
@@ -89,7 +89,7 @@
 	ld hl, Options
 	res NO_TEXT_SCROLL, [hl]
 	ld hl, rLCDC
-	res 2, [hl]
+	res rLCDC_SPRITE_SIZE, [hl] ; 8x8
 	ret
 
 .InitGFX: ; 926f7 (24:66f7)
@@ -134,7 +134,7 @@
 	call CopyBytes
 
 	ld hl, rLCDC
-	set 2, [hl]
+	set rLCDC_SPRITE_SIZE, [hl] ; 8x16
 	call EnableLCD
 	ld hl, wSlots
 	ld bc, wSlotsEnd - wSlots
--- a/engine/title.asm
+++ b/engine/title.asm
@@ -201,7 +201,7 @@
 
 ; Set sprite size to 8x16
 	ld a, [rLCDC]
-	set 2, a
+	set rLCDC_SPRITE_SIZE, a
 	ld [rLCDC], a
 
 	ld a, +112
--- a/engine/unown_puzzle.asm
+++ b/engine/unown_puzzle.asm
@@ -45,7 +45,7 @@
 	ld [wHoldingUnownPuzzlePiece], a
 	ld [wUnownPuzzleCursorPosition], a
 	ld [wUnownPuzzleHeldPiece], a
-	ld a, $93
+	ld a, %10010011
 	ld [rLCDC], a
 	call WaitBGMap
 	ld b, SCGB_UNOWN_PUZZLE
@@ -85,7 +85,7 @@
 	call ClearBGPalettes
 	call ClearTileMap
 	call ClearSprites
-	ld a, $e3
+	ld a, rLCDC_DEFAULT
 	ld [rLCDC], a
 	ret
 ; e124e
--- a/engine/unused_title.asm
+++ b/engine/unused_title.asm
@@ -55,8 +55,8 @@
 
 	call EnableLCD
 	ld a, [rLCDC]
-	set 1, a
-	set 2, a
+	set rLCDC_SPRITE_ENABLE, a
+	set rLCDC_SPRITE_SIZE, a
 	ld [rLCDC], a
 
 	call DelayFrame
--- a/gfx/font.asm
+++ b/gfx/font.asm
@@ -107,7 +107,7 @@
 	ld hl, vTiles1
 	lb bc, BANK(Font), $80
 	ld a, [rLCDC]
-	bit 7, a
+	bit rLCDC_ENABLE, a
 	jp z, Copy1bpp
 
 	ld de, Font
--- a/home/copy.asm
+++ b/home/copy.asm
@@ -3,7 +3,7 @@
 
 Get2bpp_2:: ; dc9
 	ld a, [rLCDC]
-	bit 7, a
+	bit rLCDC_ENABLE, a
 	jp z, Copy2bpp
 
 	homecall _Get2bpp
@@ -13,7 +13,7 @@
 
 Get1bpp_2:: ; ddc
 	ld a, [rLCDC]
-	bit 7, a
+	bit rLCDC_ENABLE, a
 	jp z, Copy1bpp
 
 	homecall _Get1bpp
@@ -361,7 +361,7 @@
 
 Get2bpp:: ; f82
 	ld a, [rLCDC]
-	bit 7, a
+	bit rLCDC_ENABLE, a
 	jp nz, Request2bpp
 
 Copy2bpp:: ; f89
@@ -392,7 +392,7 @@
 
 Get1bpp:: ; f9d
 	ld a, [rLCDC]
-	bit 7, a
+	bit rLCDC_ENABLE, a
 	jp nz, Request1bpp
 
 Copy1bpp:: ; fa4
--- a/home/init.asm
+++ b/home/init.asm
@@ -62,7 +62,7 @@
 
 .wait
 	ld a, [rLY]
-	cp 145
+	cp LY_VBLANK + 1
 	jr nz, .wait
 
 	xor a
@@ -125,7 +125,7 @@
 	ld [hWX], a
 	ld [rWX], a
 
-	ld a, %11100011
+	ld a, rLCDC_DEFAULT ; %11100011
 	; LCD on
 	; Win tilemap 1
 	; Win on
--- a/home/lcd.asm
+++ b/home/lcd.asm
@@ -43,7 +43,7 @@
 
 ; Don't need to do anything if the LCD is already off
 	ld a, [rLCDC]
-	bit 7, a ; lcd enable
+	bit rLCDC_ENABLE, a
 	ret z
 
 	xor a
@@ -58,11 +58,11 @@
 .wait
 ; Wait until VBlank would normally happen
 	ld a, [rLY]
-	cp 145
+	cp LY_VBLANK + 1
 	jr nz, .wait
 
 	ld a, [rLCDC]
-	and %01111111 ; lcd enable off
+	and $ff ^ 1 << rLCDC_ENABLE
 	ld [rLCDC], a
 
 	xor a
@@ -75,7 +75,7 @@
 
 EnableLCD:: ; 58a
 	ld a, [rLCDC]
-	set 7, a ; lcd enable
+	set rLCDC_ENABLE, a
 	ld [rLCDC], a
 	ret
 ; 591
--- a/home/text.asm
+++ b/home/text.asm
@@ -31,7 +31,7 @@
 
 	; Update the BG Map.
 	ld a, [rLCDC]
-	bit 7, a
+	bit rLCDC_ENABLE, a
 	ret z
 	jp WaitBGMap
 ; fdb
--- a/home/video.asm
+++ b/home/video.asm
@@ -291,9 +291,9 @@
 
 ; Back out if we're too far into VBlank
 	ld a, [rLY]
-	cp 144
+	cp LY_VBLANK
 	ret c
-	cp 146
+	cp LY_VBLANK + 2
 	ret nc
 
 ; Copy [Requested1bpp] 1bpp tiles from [Requested1bppSource] to [Requested1bppDest]
@@ -372,9 +372,9 @@
 
 ; Back out if we're too far into VBlank
 	ld a, [rLY]
-	cp 144
+	cp LY_VBLANK
 	ret c
-	cp 146
+	cp LY_VBLANK + 2
 	ret nc
 	jr _Serve2bppRequest
 
@@ -454,9 +454,9 @@
 
 ; Back out if we're too far into VBlank
 	ld a, [rLY]
-	cp 144
+	cp LY_VBLANK
 	ret c
-	cp 151
+	cp LY_VBLANK + 7
 	ret nc
 
 	ld a, [hROMBank]
--- a/mobile/mobile_45_sprite_engine.asm
+++ b/mobile/mobile_45_sprite_engine.asm
@@ -411,7 +411,7 @@
 .wait_for_vblank
 ; Wait until a vblank would occur had interrupts not just been disabled.
 	ld a, [rLY]
-	cp $91
+	cp LY_VBLANK + 1
 	jr nz, .wait_for_vblank
 
 	ld a, $d0