shithub: pokecrystal

Download patch

ref: 50e9c799aad6e21cd652f526264f553ae843a3df
parent: a7fbc916d47f0dd0c1e9ee2b54d0b93a848f88d3
author: yenatch <[email protected]>
date: Wed Mar 27 21:37:31 EDT 2013

Minor formatting in main

--- a/main.asm
+++ b/main.asm
@@ -63,7 +63,7 @@
 INCLUDE "vblank.asm"
 
 
-DelayFrame: ; 0x45a
+DelayFrame: ; 45a
 ; Wait for one frame
 	ld a, 1
 	ld [VBlankOccurred], a
@@ -75,25 +75,26 @@
 	and a
 	jr nz, .halt
 	ret
-; 0x468
+; 468
 
-DelayFrames: ; 0x468
+
+DelayFrames: ; 468
 ; Wait c frames
 	call DelayFrame
 	dec c
 	jr nz, DelayFrames
 	ret
-; 0x46f
+; 46f
 
+
 RTC: ; 46f
 ; update time and time-sensitive palettes
 
 ; rtc enabled?
 	ld a, [$c2ce]
-	cp $0
+	cp 0
 	ret z
 	
-; update clock
 	call UpdateTime
 	
 ; obj update on?
@@ -106,8 +107,10 @@
 	ret
 ; 485
 
+
 INCBIN "baserom.gbc",$485,$52f - $485
 
+
 IncGradGBPalTable_01: ; 52f
 	db %11111111 ; bgp
 	db %11111111 ; obp1
@@ -142,8 +145,10 @@
 	db %00000000
 ; 547
 
+
 INCBIN "baserom.gbc",$547,$568 - $547
 
+
 DisableLCD: ; 568
 ; Turn the LCD off
 ; Most of this is just going through the motions
@@ -186,6 +191,7 @@
 	ret
 ; 58a
 
+
 EnableLCD: ; 58a
 	ld a, [rLCDC]
 	set 7, a ; lcd enable
@@ -193,10 +199,12 @@
 	ret
 ; 591
 
+
 AskTimer: ; 591
 	INCBIN "baserom.gbc",$591,$59c - $591
 ; 59c
 
+
 LatchClock: ; 59c
 ; latch clock counter data
 	ld a, $0
@@ -206,6 +214,7 @@
 	ret
 ; 5a7
 
+
 UpdateTime: ; 5a7
 ; get rtc data
 	call GetClock
@@ -218,6 +227,7 @@
 	ret
 ; 5b7
 
+
 GetClock: ; 5b7
 ; store clock data in hRTCDayHi-hRTCSeconds
 
@@ -811,7 +821,8 @@
 	ld a, [hCGB]
 	and a
 	ret z
-	
+
+
 UpdateCGBPals: ; c33
 ; return carry if successful
 ; any pals to update?
@@ -818,114 +829,54 @@
 	ld a, [hCGBPalUpdate]
 	and a
 	ret z
-	
+
+
 ForceUpdateCGBPals: ; c37
-; save wram bank
+
 	ld a, [rSVBK]
 	push af
-; bankswitch
 	ld a, 5 ; BANK(BGPals)
 	ld [rSVBK], a
-; get bg pal buffer
+
 	ld hl, BGPals ; 5:d080
-	
-; update bg pals
+
+; copy 8 pals to bgpd
 	ld a, %10000000 ; auto increment, index 0
 	ld [rBGPI], a
-	ld c, rBGPD - rJOYP
+	ld c, rBGPD % $100
 	ld b, 4 ; NUM_PALS / 2
-	
 .bgp
-; copy 16 bytes (8 colors / 2 pals) to bgpd
+	rept $10
 	ld a, [hli]
 	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-; done?
+	endr
+
 	dec b
 	jr nz, .bgp
 	
 ; hl is now 5:d0c0 OBPals
 	
-; update obj pals
+; copy 8 pals to obpd
 	ld a, %10000000 ; auto increment, index 0
 	ld [rOBPI], a
 	ld c, rOBPD - rJOYP
 	ld b, 4 ; NUM_PALS / 2
-	
 .obp
-; copy 16 bytes (8 colors / 2 pals) to obpd
+	rept $10
 	ld a, [hli]
 	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-	ld a, [hli]
-	ld [$ff00+c], a
-; done?
+	endr
+
 	dec b
 	jr nz, .obp
 	
-; restore wram bank
 	pop af
 	ld [rSVBK], a
+
 ; clear pal update queue
 	xor a
 	ld [hCGBPalUpdate], a
-; successfully updated palettes
+
 	scf
 	ret
 ; c9f
@@ -935,23 +886,22 @@
 ; exists to forego reinserting cgb-converted image data
 
 ; input: a -> bgp
+
 	ld [rBGP], a
 	push af
-	
-; check cgb
+
 	ld a, [hCGB]
 	and a
 	jr z, .end
-	
+
 	push hl
 	push de
 	push bc
-; save wram bank
-	ld a, [$ff70]
+	ld a, [rSVBK]
 	push af
-; wram bank 5
+
 	ld a, 5
-	ld [$ff70], a
+	ld [rSVBK], a
 
 ; copy & reorder bg pal buffer
 	ld hl, BGPals ; to
@@ -959,15 +909,15 @@
 ; order
 	ld a, [rBGP]
 	ld b, a
-; # pals
-	ld c, 8 ; all pals
+; all pals
+	ld c, 8
 	call CopyPals
 ; request pal update
-	ld a, $1
+	ld a, 1
 	ld [hCGBPalUpdate], a
-; restore wram bank
+
 	pop af
-	ld [$ff70], a
+	ld [rSVBK], a
 	pop bc
 	pop de
 	pop hl
@@ -981,44 +931,41 @@
 ; exists to forego reinserting cgb-converted image data
 
 ; input: d -> obp1
-;		 e -> obp2
+;        e -> obp2
+
 	ld a, e
 	ld [rOBP0], a
 	ld a, d
 	ld [rOBP1], a
 	
-; check cgb
 	ld a, [hCGB]
 	and a
 	ret z
-	
+
 	push hl
 	push de
 	push bc
-; save wram bank
-	ld a, [$ff70]
+	ld a, [rSVBK]
 	push af
-; wram bank 5
-	ld a, $5
-	ld [$ff70], a
-	
+
+	ld a, 5
+	ld [rSVBK], a
+
 ; copy & reorder obj pal buffer
-	; to
-	ld hl, OBPals
-	; from
-	ld de, Unkn2Pals
+	ld hl, OBPals ; to
+	ld de, Unkn2Pals ; from
 ; order
 	ld a, [rOBP0]
 	ld b, a
-; # pals
-	ld c, 8 ; all pals
+; all pals
+	ld c, 8
 	call CopyPals
 ; request pal update
-	ld a, $1
+	ld a, 1
 	ld [hCGBPalUpdate], a
-; restore wram bank
+
 	pop af
-	ld [$ff70], a
+	ld [rSVBK], a
 	pop bc
 	pop de
 	pop hl
@@ -1025,8 +972,10 @@
 	ret
 ; cf8
 
+
 INCBIN "baserom.gbc",$cf8,$d50 - $cf8
 
+
 CopyPals: ; d50
 ; copy c palettes in order b from de to hl
 
@@ -1079,47 +1028,60 @@
 	ret
 ; d79
 
+
 INCBIN "baserom.gbc",$d79,$e8d - $d79
 
-; copy bc bytes from a:hl to de
+
 FarCopyBytes: ; e8d
+; copy bc bytes from a:hl to de
+
 	ld [hBuffer], a
-	ld a, [hROMBank] ; save old bank
+	ld a, [hROMBank]
 	push af
 	ld a, [hBuffer]
 	rst Bankswitch
+
 	call CopyBytes
+
 	pop af
 	rst Bankswitch
 	ret
 ; 0xe9b
 
-; copy bc*2 source bytes from a:hl to de, doubling each byte in process
+
 FarCopyBytesDouble: ; e9b
+; Copy bc bytes from a:hl to bc*2 bytes at de,
+; doubling each byte in the process.
+
 	ld [hBuffer], a
-	ld a, [hROMBank] ; save current bank
+	ld a, [hROMBank]
 	push af
 	ld a, [hBuffer]
-	rst Bankswitch ; bankswitch
-	ld a, h ; switcheroo, de <> hl
+	rst Bankswitch
+
+; switcheroo, de <> hl
+	ld a, h
 	ld h, d
 	ld d, a
 	ld a, l
 	ld l, e
 	ld e, a
+
 	inc b
 	inc c
-	jr .dec ; 0xeab $4
+	jr .dec
+
 .loop
 	ld a, [de]
 	inc de
-	ld [hli], a ; write twice
 	ld [hli], a
+	ld [hli], a
 .dec
 	dec c
 	jr nz, .loop
 	dec b
 	jr nz, .loop
+
 	pop af
 	rst Bankswitch
 	ret
@@ -1126,7 +1088,7 @@
 ; 0xeba
 
 
-INCBIN "baserom.gbc",$eba,$fb6 - $eba
+INCBIN "baserom.gbc", $eba, $fb6 - $eba
 
 
 ClearBox: ; fb6
@@ -1149,14 +1111,16 @@
 	ret
 ; fc8
 
+
 ClearTileMap: ; fc8
-; Fill TileMap with blank tiles
+; Fill TileMap with blank tiles.
+
 	ld hl, TileMap
 	ld a, " "
 	ld bc, 360 ; screen dimensions 20*18
 	call ByteFill
 	
-; We aren't done if the LCD is on
+; We aren't done if the LCD is on.
 	ld a, [rLCDC]
 	bit 7, a
 	ret z
@@ -1164,7 +1128,7 @@
 ; fdb
 
 
-INCBIN "baserom.gbc",$fdb,$fe8 - $fdb
+INCBIN "baserom.gbc", $fdb, $fe8 - $fdb
 
 
 TextBox: ; fe8
@@ -1225,9 +1189,10 @@
 	call NPlaceChar
 	ld [hl], "┘"
 	ret
-; 0x101e
+; 101e
 
-NPlaceChar: ; 0x101e
+
+NPlaceChar: ; 101e
 ; place a row of width c of identical characters
 	ld d,c
 .loop\@
@@ -1235,7 +1200,7 @@
 	dec d
 	jr nz,.loop\@
 	ret
-; 0x1024
+; 1024
 
 
 TextBoxPalette: ; 1024
@@ -1420,8 +1385,10 @@
 	jp NextChar
 ; 0x117b
 
-INCBIN "baserom.gbc",$117b,$1203 - $117b
 
+INCBIN "baserom.gbc", $117b, $1203 - $117b
+
+
 Char5D:
 	ld a, [hBattleTurn]
 	push de
@@ -3143,11 +3110,11 @@
 	
 .cgb
 ; Save WRAM bank
-	ld a, [$ff70]
+	ld a, [rSVBK]
 	push af
 ; WRAM bank 5
 	ld a, 5
-	ld [$ff70], a
+	ld [rSVBK], a
 ; Fill BGPals and OBPals with $ffff (white)
 	ld hl, BGPals
 	ld bc, $0080
@@ -3155,7 +3122,7 @@
 	call ByteFill
 ; Restore WRAM bank
 	pop af
-	ld [$ff70], a
+	ld [rSVBK], a
 ; Request palette update
 	ld a, 1
 	ld [hCGBPalUpdate], a
@@ -15316,11 +15283,11 @@
 	call $6f06
 	
 ; Save WRAM bank
-	ld a, [$ff70]
+	ld a, [rSVBK]
 	push af
 ; WRAM bank 5
 	ld a, 5
-	ld [$ff70], a
+	ld [rSVBK], a
 	
 ; Update palette colors
 	ld hl, TitleScreenPalettes
@@ -15335,17 +15302,17 @@
 	
 ; Restore WRAM bank
 	pop af
-	ld [$ff70], a
+	ld [rSVBK], a
 	
 	
 ; LY/SCX trickery starts here
 	
 ; Save WRAM bank
-	ld a, [$ff70]
+	ld a, [rSVBK]
 	push af
 ; WRAM bank 5
 	ld a, 5
-	ld [$ff70], a
+	ld [rSVBK], a
 	
 ; Make alternating lines come in from opposite sides
 
@@ -15375,7 +15342,7 @@
 	
 ; Restore WRAM bank
 	pop af
-	ld [$ff70], a
+	ld [rSVBK], a
 	
 	
 ; Reset audio
@@ -15770,10 +15737,10 @@
 	ld [$cf63], a
 	ret
 .asm_117be7
-	ld a, [$ff70]
+	ld a, [rSVBK]
 	push af
 	ld a, $3
-	ld [$ff70], a
+	ld [rSVBK], a
 	ld a, [$cd89]
 	and $1
 	jr nz, .asm_117c16 ; 0x117bf3 $21
@@ -15797,20 +15764,20 @@
 	jr .asm_117c20 ; 0x117c14 $a
 .asm_117c16
 	pop af
-	ld [$ff70], a
+	ld [rSVBK], a
 	ld a, $d3
 	ld [$c300], a
 	jr .asm_117bd0 ; 0x117c1e $b0
 .asm_117c20
 	pop af
-	ld [$ff70], a
+	ld [rSVBK], a
 	ld a, $5c
 	ld hl, $6eb9
 	rst FarCall
-	ld a, [$ff70]
+	ld a, [rSVBK]
 	push af
 	ld a, $3
-	ld [$ff70], a
+	ld [rSVBK], a
 	ld a, $7
 	call GetSRAMBank
 	ld hl, $d002
@@ -15819,7 +15786,7 @@
 	call CopyBytes
 	call CloseSRAM
 	pop af
-	ld [$ff70], a
+	ld [rSVBK], a
 	jp Function117cdd
 
 Function117c4a:
@@ -15832,10 +15799,10 @@
 	rst FarCall
 	ld hl, MobileStadiumSuccessText
 	call $1057
-	ld a, [$ff70]
+	ld a, [rSVBK]
 	push af
 	ld a, $5
-	ld [$ff70], a
+	ld [rSVBK], a
 	ld hl, $d000
 	ld de, $0008
 	ld c, $8
@@ -15851,7 +15818,7 @@
 	jr nz, .asm_117c71 ; 0x117c7b $f4
 	call $04b6
 	pop af
-	ld [$ff70], a
+	ld [rSVBK], a
 	ld a, $80
 	ld [$cf63], a
 	ret