Minor formatting in main

This commit is contained in:
yenatch 2013-03-28 01:37:31 -04:00
parent a7fbc916d4
commit 50e9c799aa

263
main.asm
View File

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