More splitting of main.asm; remove unneeded rept 2

This commit is contained in:
pikalaxalt
2016-05-04 11:46:23 -04:00
parent 82f1534925
commit 3713b71d9e
107 changed files with 1222 additions and 1610 deletions

819
main.asm
View File

@@ -1174,169 +1174,7 @@ Function29fe4: ; unreferenced
ret
INCLUDE "engine/wildmons.asm"
DetermineLinkBattleResult: ; 2b930
callba UpdateEnemyMonInParty
ld hl, PartyMon1HP
call .CountMonsRemaining
push bc
ld hl, OTPartyMon1HP
call .CountMonsRemaining
ld a, c
pop bc
cp c
jr z, .even_number_of_mons_remaining
jr c, .defeat
jr .victory
.even_number_of_mons_remaining
call .BothSides_CheckNumberMonsAtFullHealth
jr z, .drawn
ld a, e
cp $1
jr z, .victory
cp $2
jr z, .defeat
ld hl, PartyMon1HP
call .CalcPercentHPRemaining
push de
ld hl, OTPartyMon1HP
call .CalcPercentHPRemaining
pop hl
ld a, d
cp h
jr c, .victory
jr z, .compare_lo
jr .defeat
.compare_lo
ld a, e
cp l
jr z, .drawn
jr nc, .defeat
.victory
ld a, [wBattleResult]
and $f0
ld [wBattleResult], a
ret
.defeat
ld a, [wBattleResult]
and $f0
add $1
ld [wBattleResult], a
ret
.drawn
ld a, [wBattleResult]
and $f0
add $2
ld [wBattleResult], a
ret
.CountMonsRemaining: ; 2b995
ld c, 0
ld b, 3
ld de, PARTYMON_STRUCT_LENGTH - 1
.loop
ld a, [hli]
or [hl]
jr nz, .not_fainted
inc c
.not_fainted
add hl, de
dec b
jr nz, .loop
ret
.CalcPercentHPRemaining: ; 2b9a6
ld de, 0
ld c, $3
.loop2
ld a, [hli]
or [hl]
jr z, .next
dec hl
xor a
ld [hDividend + 0], a
ld a, [hli]
ld [hDividend + 1], a
ld a, [hli]
ld [hDividend + 2], a
xor a
ld [hDividend + 3], a
ld a, [hli]
ld b, a
ld a, [hld]
srl b
rr a
srl b
rr a
ld [hDivisor], a
ld b, $4
call Divide
ld a, [hQuotient + 2]
add e
ld e, a
ld a, [hQuotient + 1]
adc d
ld d, a
dec hl
.next
push de
ld de, $2f
add hl, de
pop de
dec c
jr nz, .loop2
ret
.BothSides_CheckNumberMonsAtFullHealth: ; 2b9e1
ld hl, PartyMon1HP
call .CheckFaintedOrFullHealth
jr nz, .finish ; we have a pokemon that's neither fainted nor at full health
ld hl, OTPartyMon1HP
call .CheckFaintedOrFullHealth
ld e, $1
ret
.finish
ld hl, OTPartyMon1HP
call .CheckFaintedOrFullHealth
ld e, $0
ret nz ; we both have pokemon that are neither fainted nor at full health
ld e, $2
ld a, $1
and a
ret
.CheckFaintedOrFullHealth: ; 2ba01
ld d, 3
.loop3
ld a, [hli]
ld b, a
ld a, [hli]
ld c, a
or b
jr z, .fainted_or_full_health
ld a, [hli]
cp b
ret nz
ld a, [hld]
cp c
ret nz
.fainted_or_full_health
push de
ld de, PARTYMON_STRUCT_LENGTH - 2
add hl, de
pop de
dec d
jr nz, .loop3
ret
INCLUDE "battle/link_result.asm"
ChrisBackpic: ; 2ba1a
INCBIN "gfx/misc/player.6x6.2bpp.lz"
@@ -2103,78 +1941,6 @@ DisplayDexEntry: ; 4424d
String_44331: ; 44331
db "#@"
GetDexEntryPointer: ; 44333
; return dex entry pointer b:de
push hl
ld hl, PokedexDataPointerTable
ld a, b
dec a
ld d, 0
ld e, a
add hl, de
add hl, de
ld e, [hl]
inc hl
ld d, [hl]
push de
rlca
rlca
and $3
ld hl, .PokedexEntryBanks
ld d, 0
ld e, a
add hl, de
ld b, [hl]
pop de
pop hl
ret
.PokedexEntryBanks: ; 44351
GLOBAL PokedexEntries1
GLOBAL PokedexEntries2
GLOBAL PokedexEntries3
GLOBAL PokedexEntries4
db BANK(PokedexEntries1)
db BANK(PokedexEntries2)
db BANK(PokedexEntries3)
db BANK(PokedexEntries4)
GetDexEntryPagePointer: ; 44355
call GetDexEntryPointer ; b:de
push hl
ld h, d
ld l, e
; skip species name
.loop1
ld a, b
call GetFarByte
inc hl
cp "@"
jr nz, .loop1
; skip height and weight
rept 4
inc hl
endr
; if c != 1: skip entry
dec c
jr z, .done
; skip entry
.loop2
ld a, b
call GetFarByte
inc hl
cp "@"
jr nz, .loop2
.done
ld d, h
ld e, l
pop hl
ret
PokedexDataPointerTable: ; 0x44378
INCLUDE "data/pokedex/entry_pointers.asm"
INCLUDE "engine/mail.asm"
@@ -2505,7 +2271,7 @@ SaveMenu_LoadEDTile: ; 4cf45 (13:4f45)
and a
jp z, WaitBGMap
; The following is a modified version of Function3246.
; The following is a modified version of LoadEDTile.
ld a, [hBGMapMode]
push af
xor a
@@ -2646,7 +2412,7 @@ PhoneRing_LoadEDTile: ; 4d188
cp $0
jp z, WaitBGMap
; What follows is a modified version of Function3246 (LoadEDTile).
; What follows is a modified version of LoadEDTile.
ld a, [hBGMapMode]
push af
xor a
@@ -2817,304 +2583,7 @@ LinkTextbox2: ; 4d35b
jr nz, .row_loop
ret
_ResetClock: ; 4d3b1
callba BlankScreen
ld b, SCGB_08
call GetSGBLayout
call LoadStandardFont
call LoadFontsExtra
ld de, MUSIC_MAIN_MENU
call PlayMusic
ld hl, .text_askreset
call PrintText
ld hl, .NoYes_MenuDataHeader
call CopyMenuDataHeader
call VerticalMenu
ret c
ld a, [wMenuCursorY]
cp $1
ret z
call ClockResetPassword
jr c, .wrongpassword
ld a, BANK(sRTCStatusFlags)
call GetSRAMBank
ld a, $80
ld [sRTCStatusFlags], a
call CloseSRAM
ld hl, .text_okay
call PrintText
ret
.wrongpassword
ld hl, .text_wrong
call PrintText
ret
.text_okay ; 0x4d3fe
; Password OK. Select CONTINUE & reset settings.
text_jump UnknownText_0x1c55db
db "@"
.text_wrong ; 0x4d403
; Wrong password!
text_jump UnknownText_0x1c560b
db "@"
.text_askreset ; 0x4d408
; Reset the clock?
text_jump UnknownText_0x1c561c
db "@"
.NoYes_MenuDataHeader: ; 0x4d40d
db $00 ; flags
db 07, 14 ; start coords
db 11, 19 ; end coords
dw .NoYes_MenuData2
db 1 ; default option
.NoYes_MenuData2: ; 0x4d415
db $c0 ; flags
db 2 ; items
db "NO@"
db "YES@"
ClockResetPassword: ; 4d41e
call .CalculatePassword
push de
ld hl, StringBuffer2
ld bc, 5
xor a
call ByteFill
ld a, $4
ld [StringBuffer2 + 5], a
ld hl, .pleaseenterpasswordtext
call PrintText
.loop
call .updateIDdisplay
.loop2
call JoyTextDelay
ld a, [hJoyLast]
ld b, a
and A_BUTTON
jr nz, .confirm
ld a, b
and D_PAD
jr z, .loop2
call .dpadinput
ld c, 3
call DelayFrames
jr .loop
.confirm
call .ConvertDecIDToBytes
pop de
ld a, e
cp l
jr nz, .nope
ld a, d
cp h
jr nz, .nope
and a
ret
.nope
scf
ret
.pleaseenterpasswordtext ; 0x4d463
; Please enter the password.
text_jump UnknownText_0x1c562e
db "@"
.updateIDdisplay ; 4d468
hlcoord 14, 15
ld de, StringBuffer2
ld c, 5
.loop3
ld a, [de]
add "0"
ld [hli], a
inc de
dec c
jr nz, .loop3
hlcoord 14, 16
ld bc, 5
ld a, " "
call ByteFill
hlcoord 14, 16
ld a, [StringBuffer2 + 5]
ld e, a
ld d, $0
add hl, de
ld [hl], $61
ret
.dpadinput ; 4d490
ld a, b
and D_LEFT
jr nz, .left
ld a, b
and D_RIGHT
jr nz, .right
ld a, b
and D_UP
jr nz, .up
ld a, b
and D_DOWN
jr nz, .down
ret
.left
ld a, [StringBuffer2 + 5]
and a
ret z
dec a
ld [StringBuffer2 + 5], a
ret
.right
ld a, [StringBuffer2 + 5]
cp $4
ret z
inc a
ld [StringBuffer2 + 5], a
ret
.up
call .getcurrentdigit
ld a, [hl]
cp 9
jr z, .wraparound_up
inc a
ld [hl], a
ret
.wraparound_up
ld [hl], $0
ret
.down
call .getcurrentdigit
ld a, [hl]
and a
jr z, .wraparound_down
dec a
ld [hl], a
ret
.wraparound_down
ld [hl], 9
ret
.getcurrentdigit ; 4d4d5
ld a, [StringBuffer2 + 5]
ld e, a
ld d, $0
ld hl, StringBuffer2
add hl, de
ret
.ConvertDecIDToBytes: ; 4d4e0
ld hl, 0
ld de, StringBuffer2 + 4
ld bc, 1
call .ConvertToBytes
ld bc, 10
call .ConvertToBytes
ld bc, 100
call .ConvertToBytes
ld bc, 1000
call .ConvertToBytes
ld bc, 10000
.ConvertToBytes: ; 4d501
ld a, [de]
dec de
push hl
ld hl, 0
call AddNTimes
ld c, l
ld b, h
pop hl
add hl, bc
ret
.CalculatePassword: ; 4d50f
ld a, BANK(sPlayerData)
call GetSRAMBank
ld de, 0
ld hl, sPlayerData + (PlayerID - wPlayerData)
ld c, $2
call .ComponentFromNumber
ld hl, sPlayerData + (PlayerName - wPlayerData)
ld c, $5 ; PLAYER_NAME_LENGTH_J
call .ComponentFromString
ld hl, sPlayerData + (Money - wPlayerData)
ld c, $3
call .ComponentFromNumber
call CloseSRAM
ret
.ComponentFromNumber: ; 4d533
ld a, [hli]
add e
ld e, a
ld a, $0
adc d
ld d, a
dec c
jr nz, .ComponentFromNumber
ret
.ComponentFromString: ; 4d53e
ld a, [hli]
cp "@"
ret z
add e
ld e, a
ld a, $0
adc d
ld d, a
dec c
jr nz, .ComponentFromString
ret
_DeleteSaveData: ; 4d54c
callba BlankScreen
ld b, SCGB_08
call GetSGBLayout
call LoadStandardFont
call LoadFontsExtra
ld de, MUSIC_MAIN_MENU
call PlayMusic
ld hl, .Text_ClearAllSaveData
call PrintText
ld hl, .NoYesMenuDataHeader
call CopyMenuDataHeader
call VerticalMenu
ret c
ld a, [wMenuCursorY]
cp $1
ret z
callba EmptyAllSRAMBanks
ret
.Text_ClearAllSaveData: ; 0x4d580
; Clear all save data?
text_jump UnknownText_0x1c564a
db "@"
.NoYesMenuDataHeader: ; 0x4d585
db $00 ; flags
db 07, 14 ; start coords
db 11, 19 ; end coords
dw .MenuData2
db 1 ; default option
.MenuData2: ; 0x4d58d
db $c0 ; flags
db 2 ; items
db "NO@"
db "YES@"
INCLUDE "engine/delete_save_change_clock.asm"
Tilesets::
INCLUDE "tilesets/tileset_headers.asm"
@@ -3587,7 +3056,7 @@ CheckPartyFullAfterContest: ; 4d9e5
ld de, wBufferMonOT
ld bc, NAME_LENGTH
call CopyBytes
callab Function51322
callab InsertPokemonIntoBox
ld a, [CurPartySpecies]
ld [wd265], a
call GetPokemonName
@@ -3730,141 +3199,7 @@ SetEggMonCaughtData: ; 4dbb8 (13:5bb8)
ld [CurPartyLevel], a
ret
_FindGreaterThanThatLevel: ; 4dbd2
ld hl, PartyMon1Level
call FindGreaterThanThatLevel
ret
_FindAtLeastThatHappy: ; 4dbd9
ld hl, PartyMon1Happiness
call FindAtLeastThatHappy
ret
_FindThatSpecies: ; 4dbe0
ld hl, PartyMon1Species
jp FindThatSpecies
_FindThatSpeciesYourTrainerID: ; 4dbe6
ld hl, PartyMon1Species
call FindThatSpecies
ret z
ld a, c
ld hl, PartyMon1ID
ld bc, PARTYMON_STRUCT_LENGTH
call AddNTimes
ld a, [PlayerID]
cp [hl]
jr nz, .nope
inc hl
ld a, [PlayerID + 1]
cp [hl]
jr nz, .nope
ld a, $1
and a
ret
.nope
xor a
ret
FindAtLeastThatHappy: ; 4dc0a
; Sets the bits for the Pokemon that have a happiness greater than or equal to b.
; The lowest bits are used. Sets z if no Pokemon in your party is at least that happy.
ld c, $0
ld a, [PartyCount]
ld d, a
.loop
ld a, d
dec a
push hl
push bc
ld bc, PARTYMON_STRUCT_LENGTH
call AddNTimes
pop bc
ld a, b
cp [hl]
pop hl
jr z, .greater_equal
jr nc, .lower
.greater_equal
ld a, c
or $1
ld c, a
.lower
sla c
dec d
jr nz, .loop
call RetroactivelyIgnoreEggs
ld a, c
and a
ret
FindGreaterThanThatLevel: ; 4dc31
ld c, $0
ld a, [PartyCount]
ld d, a
.loop
ld a, d
dec a
push hl
push bc
ld bc, PARTYMON_STRUCT_LENGTH
call AddNTimes
pop bc
ld a, b
cp [hl]
pop hl
jr c, .greater
ld a, c
or $1
ld c, a
.greater
sla c
dec d
jr nz, .loop
call RetroactivelyIgnoreEggs
ld a, c
and a
ret
FindThatSpecies: ; 4dc56
; Find species b in your party.
; If you have no Pokemon, returns c = -1 and z.
; If that species is in your party, returns its location in c, and nz.
; Otherwise, returns z.
ld c, -1
ld hl, PartySpecies
.loop
ld a, [hli]
cp -1
ret z
inc c
cp b
jr nz, .loop
ld a, $1
and a
ret
RetroactivelyIgnoreEggs: ; 4dc67
ld e, -2
ld hl, PartySpecies
.loop
ld a, [hli]
cp -1
ret z
cp EGG
jr nz, .skip_notegg
ld a, c
and e
ld c, a
.skip_notegg
rlc e
jr .loop
INCLUDE "engine/search2.asm"
INCLUDE "engine/stats_screen.asm"
CatchTutorial:: ; 4e554
@@ -5303,141 +4638,7 @@ _SwitchPartyMons:
ret
INCLUDE "gfx/load_pics.asm"
Function51322: ; 51322
ld a, BANK(sBoxCount)
call GetSRAMBank
ld hl, sBoxCount
call Function513cb
ld a, [sBoxCount]
dec a
ld [wd265], a
ld hl, sBoxMonNicknames
ld bc, PKMN_NAME_LENGTH
ld de, wBufferMonNick
call Function513e0
ld a, [sBoxCount]
dec a
ld [wd265], a
ld hl, sBoxMonOT
ld bc, NAME_LENGTH
ld de, wBufferMonOT
call Function513e0
ld a, [sBoxCount]
dec a
ld [wd265], a
ld hl, sBoxMons
ld bc, BOXMON_STRUCT_LENGTH
ld de, wBufferMon
call Function513e0
ld hl, wBufferMonMoves
ld de, TempMonMoves
ld bc, NUM_MOVES
call CopyBytes
ld hl, wBufferMonPP
ld de, TempMonPP
ld bc, NUM_MOVES
call CopyBytes
ld a, [CurPartyMon]
ld b, a
callba Functiondcb6
jp CloseSRAM
Function5138b: ; 5138b
ld hl, PartyCount
call Function513cb
ld a, [PartyCount]
dec a
ld [wd265], a
ld hl, PartyMonNicknames
ld bc, PKMN_NAME_LENGTH
ld de, wBufferMonNick
call Function513e0
ld a, [PartyCount]
dec a
ld [wd265], a
ld hl, PartyMonOT
ld bc, NAME_LENGTH
ld de, wBufferMonOT
call Function513e0
ld a, [PartyCount]
dec a
ld [wd265], a
ld hl, PartyMons
ld bc, PARTYMON_STRUCT_LENGTH
ld de, wBufferMon
call Function513e0
ret
Function513cb: ; 513cb
inc [hl]
inc hl
ld a, [CurPartyMon]
ld c, a
ld b, 0
add hl, bc
ld a, [CurPartySpecies]
ld c, a
.asm_513d8
ld a, [hl]
ld [hl], c
inc hl
inc c
ld c, a
jr nz, .asm_513d8
ret
Function513e0: ; 513e0
push de
push hl
push bc
ld a, [wd265]
dec a
call AddNTimes
push hl
add hl, bc
ld d, h
ld e, l
pop hl
.asm_513ef
push bc
ld a, [wd265]
ld b, a
ld a, [CurPartyMon]
cp b
pop bc
jr z, .asm_51415
push hl
push de
push bc
call CopyBytes
pop bc
pop de
pop hl
push hl
ld a, l
sub c
ld l, a
ld a, h
sbc b
ld h, a
pop de
ld a, [wd265]
dec a
ld [wd265], a
jr .asm_513ef
.asm_51415
pop bc
pop hl
ld a, [CurPartyMon]
call AddNTimes
ld d, h
ld e, l
pop hl
call CopyBytes
ret
INCLUDE "engine/move_mon_wo_mail.asm"
BaseData::
INCLUDE "data/base_stats.asm"
@@ -5895,7 +5096,7 @@ LoadPoisonBGPals: ; cbcdd
ld a, [hCGB]
and a
ret nz
ret
ret ; ????
.LoadPals: ; cbce5
ld a, [hCGB]
@@ -5904,9 +5105,9 @@ LoadPoisonBGPals: ; cbcdd
ld a, [TimeOfDayPal]
and $3
cp $3
ld a, $0
ld a, %00000000
jr z, .convert_pals
ld a, $aa
ld a, %10101010
.convert_pals
call DmgToCgbBGPals