Move more main.asm code into individual files

This commit is contained in:
Remy Oukaour
2017-12-15 21:22:26 -05:00
parent 01bd8ac94c
commit e44640b008
35 changed files with 1159 additions and 1153 deletions

View File

@@ -20,8 +20,8 @@
const BATTLETOWERACTION_11 ; store 0 in 5:aa8d
const BATTLETOWERACTION_12 ; store 1 in 5:aa8d
const BATTLETOWERACTION_13 ; check 5:aa8d
const BATTLETOWERACTION_14 ; if save file is yours: bit 0, [s1_be4f]
const BATTLETOWERACTION_15 ; set 0, [s1_be4f]
const BATTLETOWERACTION_14 ; if save file is yours: bit 0, [sBattleTowerSaveFileFlags]
const BATTLETOWERACTION_15 ; set 0, [sBattleTowerSaveFileFlags]
const BATTLETOWERACTION_16 ; update time in SRAM bank 5
const BATTLETOWERACTION_17 ; check time in SRAM bank 5
const BATTLETOWERACTION_LEVEL_CHECK

View File

@@ -65,6 +65,11 @@ HMENURETURN_SCRIPT EQU %10000000
HMENURETURN_ASM EQU %11111111
; save file corruption check values
SAVE_CHECK_VALUE_1 EQU 99
SAVE_CHECK_VALUE_2 EQU 127
; time of day boundaries
MORN_HOUR EQU 4 ; 4 AM
DAY_HOUR EQU 10 ; 10 AM

19
engine/empty_sram.asm Normal file
View File

@@ -0,0 +1,19 @@
EmptyAllSRAMBanks: ; 4cf1f
ld a, $0
call .EmptyBank
ld a, $1
call .EmptyBank
ld a, $2
call .EmptyBank
ld a, $3
call .EmptyBank
ret
.EmptyBank: ; 4cf34
call GetSRAMBank
ld hl, SRAM_Begin
ld bc, SRAM_End - SRAM_Begin
xor a
call ByteFill
call CloseSRAM
ret

View File

@@ -0,0 +1,79 @@
InitDisplayForHallOfFame: ; 4e881
call ClearBGPalettes
call ClearTileMap
call ClearSprites
call DisableLCD
call LoadStandardFont
call LoadFontsBattleExtra
hlbgcoord 0, 0
ld bc, VBGMap1 - VBGMap0
ld a, " "
call ByteFill
hlcoord 0, 0, AttrMap
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
xor a
call ByteFill
xor a
ld [hSCY], a
ld [hSCX], a
call EnableLCD
ld hl, .SavingRecordDontTurnOff
call PrintText
call WaitBGMap2
call SetPalettes
ret
.SavingRecordDontTurnOff: ; 0x4e8bd
; SAVING RECORD… DON'T TURN OFF!
text_jump UnknownText_0x1bd39e
db "@"
InitDisplayForRedCredits: ; 4e8c2
call ClearBGPalettes
call ClearTileMap
call ClearSprites
call DisableLCD
call LoadStandardFont
call LoadFontsBattleExtra
hlbgcoord 0, 0
ld bc, VBGMap1 - VBGMap0
ld a, " "
call ByteFill
hlcoord 0, 0, AttrMap
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
xor a
call ByteFill
ld hl, UnknBGPals
ld c, 4 tiles
.load_white_palettes
ld a, (palred 31 + palgreen 31 + palblue 31) % $100
ld [hli], a
ld a, (palred 31 + palgreen 31 + palblue 31) / $100
ld [hli], a
dec c
jr nz, .load_white_palettes
xor a
ld [hSCY], a
ld [hSCX], a
call EnableLCD
call WaitBGMap2
call SetPalettes
ret
ResetDisplayBetweenHallOfFameMons: ; 4e906
ld a, [rSVBK]
push af
ld a, $6
ld [rSVBK], a
ld hl, wDecompressScratch
ld bc, wScratchAttrMap - wDecompressScratch
ld a, " "
call ByteFill
hlbgcoord 0, 0
ld de, wDecompressScratch
ld b, 0
ld c, 4 tiles
call Request2bpp
pop af
ld [rSVBK], a
ret

54
engine/init_list.asm Normal file
View File

@@ -0,0 +1,54 @@
InitList: ; 50db9
ld a, [wInitListType]
cp INIT_ENEMYOT_LIST
jr nz, .check_party_ot_name
ld hl, OTPartyCount
ld de, OTPartyMonOT
ld a, ENEMY_OT_NAME
jr .done
.check_party_ot_name
cp INIT_PLAYEROT_LIST
jr nz, .check_mon_name
ld hl, PartyCount
ld de, PartyMonOT
ld a, PARTY_OT_NAME
jr .done
.check_mon_name
cp INIT_MON_LIST
jr nz, .check_item_name
ld hl, CurMart
ld de, PokemonNames
ld a, PKMN_NAME
jr .done
.check_item_name
cp INIT_BAG_ITEM_LIST
jr nz, .check_ob_item_name
ld hl, NumItems
ld de, ItemNames
ld a, ITEM_NAME
jr .done
.check_ob_item_name
ld hl, CurMart
ld de, ItemNames
ld a, ITEM_NAME
.done
ld [wNamedObjectTypeBuffer], a
ld a, l
ld [wListPointer], a
ld a, h
ld [wListPointer + 1], a
ld a, e
ld [wUnusedD102], a
ld a, d
ld [wUnusedD102 + 1], a
ld bc, ItemAttributes
ld a, c
ld [wItemAttributesPtr], a
ld a, b
ld [wItemAttributesPtr + 1], a
ret

View File

@@ -2581,3 +2581,14 @@ UnusedGen1LinkCommsBorderGFX: ; 29f54
; unreferenced
INCBIN "gfx/trade/unused_gen_1_border_tiles.2bpp"
; 29fe4
Function29fe4: ; unreferenced
ld a, BANK(sPartyMail)
call GetSRAMBank
ld d, $0
ld b, CHECK_FLAG
predef FlagPredef
call CloseSRAM
ld a, c
and a
ret

20
engine/pack_f.asm Normal file
View File

@@ -0,0 +1,20 @@
DrawKrisPackGFX: ; 48e81
ld hl, PackFGFXPointers
add hl, de
add hl, de
ld a, [hli]
ld e, a
ld d, [hl]
ld hl, VTiles2 tile $50
lb bc, BANK(PackFGFX), 15
call Request2bpp
ret
PackFGFXPointers: ; 48e93
dw PackFGFX + (15 tiles) * 1
dw PackFGFX + (15 tiles) * 3
dw PackFGFX + (15 tiles) * 0
dw PackFGFX + (15 tiles) * 2
PackFGFX: ; 48e9b
INCBIN "gfx/pack/pack_f.2bpp"

56
engine/place_graphics.asm Normal file
View File

@@ -0,0 +1,56 @@
PlaceGraphic: ; 2ef6e
; Fill wBoxAlignment-aligned box width b height c
; with iterating tile starting from hGraphicStartTile at hl.
; Predef $13
ld de, SCREEN_WIDTH
ld a, [wBoxAlignment]
and a
jr nz, .right
ld a, [hGraphicStartTile]
.x1
push bc
push hl
.y1
ld [hl], a
add hl, de
inc a
dec c
jr nz, .y1
pop hl
inc hl
pop bc
dec b
jr nz, .x1
ret
.right
; Right-aligned.
push bc
ld b, 0
dec c
add hl, bc
pop bc
ld a, [hGraphicStartTile]
.x2
push bc
push hl
.y2
ld [hl], a
add hl, de
inc a
dec c
jr nz, .y2
pop hl
dec hl
pop bc
dec b
jr nz, .x2
ret

25
engine/pokegear_2.asm Normal file
View File

@@ -0,0 +1,25 @@
TownMap_ConvertLineBreakCharacters: ; 1de2c5
ld hl, StringBuffer1
.loop
ld a, [hl]
cp "@"
jr z, .end
cp "%"
jr z, .line_break
cp "¯"
jr z, .line_break
inc hl
jr .loop
.line_break
ld [hl], "<LNBRK>"
.end
ld de, StringBuffer1
hlcoord 9, 0
call PlaceString
ret
PokegearGFX: ; 1de2e4
INCBIN "gfx/pokegear/pokegear.2bpp.lz"

64
engine/printhoursmins.asm Normal file
View File

@@ -0,0 +1,64 @@
Function1dd6a9: ; 1dd6a9
; XXX
ld a, b
ld b, c
ld c, a
push bc
push de
ld hl, sp+$2
ld d, h
ld e, l
pop hl
lb bc, PRINTNUM_LEADINGZEROS | 2, 5
call PrintNum
pop bc
ret
PrintHoursMins ; 1dd6bb (77:56bb)
; Hours in b, minutes in c
ld a, b
cp 12
push af
jr c, .AM
jr z, .PM
sub 12
jr .PM
.AM:
or a
jr nz, .PM
ld a, 12
.PM:
ld b, a
; Crazy stuff happening with the stack
push bc
ld hl, sp+$1
push de
push hl
pop de
pop hl
ld [hl], " "
lb bc, 1, 2
call PrintNum
ld [hl], ":"
inc hl
ld d, h
ld e, l
ld hl, sp+$0
push de
push hl
pop de
pop hl
lb bc, PRINTNUM_LEADINGZEROS | 1, 2
call PrintNum
pop bc
ld de, String_AM
pop af
jr c, .place_am_pm
ld de, String_PM
.place_am_pm
inc hl
call PlaceString
ret
String_AM: db "AM@" ; 1dd6fc
String_PM: db "PM@" ; 1dd6ff

View File

@@ -500,12 +500,12 @@ HallOfFame_InitSaveIfNeeded: ; 14da0
; 14da9
ValidateSave: ; 14da9
ld a, BANK(s1_a008)
ld a, BANK(sCheckValue1) ; BANK(sCheckValue2)
call GetSRAMBank
ld a, 99
ld [s1_a008], a
ld a, " "
ld [s1_ad0f], a
ld a, SAVE_CHECK_VALUE_1
ld [sCheckValue1], a
ld a, SAVE_CHECK_VALUE_2
ld [sCheckValue2], a
jp CloseSRAM
; 14dbb
@@ -568,12 +568,12 @@ SaveChecksum: ; 14e13
; 14e2d
ValidateBackupSave: ; 14e2d
ld a, BANK(s0_b208)
ld a, BANK(sBackupCheckValue1) ; BANK(sBackupCheckValue2)
call GetSRAMBank
ld a, 99
ld [s0_b208], a
ld a, " "
ld [s0_bf0f], a
ld a, SAVE_CHECK_VALUE_1
ld [sBackupCheckValue1], a
ld a, SAVE_CHECK_VALUE_2
ld [sBackupCheckValue2], a
call CloseSRAM
ret
; 14e40
@@ -731,13 +731,13 @@ INCLUDE "data/default_options.asm"
CheckPrimarySaveFile: ; 14f84
ld a, BANK(s1_a008)
ld a, BANK(sCheckValue1) ; BANK(sCheckValue2)
call GetSRAMBank
ld a, [s1_a008]
cp 99
ld a, [sCheckValue1]
cp SAVE_CHECK_VALUE_1
jr nz, .nope
ld a, [s1_ad0f]
cp " "
ld a, [sCheckValue2]
cp SAVE_CHECK_VALUE_2
jr nz, .nope
ld hl, sOptions
ld de, Options
@@ -753,13 +753,13 @@ CheckPrimarySaveFile: ; 14f84
; 14faf
CheckBackupSaveFile: ; 14faf
ld a, BANK(s0_b208)
ld a, BANK(sBackupCheckValue1) ; BANK(sBackupCheckValue2)
call GetSRAMBank
ld a, [s0_b208]
cp 99
ld a, [sBackupCheckValue1]
cp SAVE_CHECK_VALUE_1
jr nz, .nope
ld a, [s0_bf0f]
cp " "
ld a, [sBackupCheckValue2]
cp SAVE_CHECK_VALUE_2
jr nz, .nope
ld hl, sBackupOptions
ld de, Options

View File

@@ -0,0 +1,145 @@
_SwitchPartyMons:
ld a, [wd0e3]
dec a
ld [Buffer3], a
ld b, a
ld a, [wMenuCursorY]
dec a
ld [Buffer2], a
cp b
jr z, .skip
call .SwapMonAndMail
ld a, [Buffer3]
call .ClearSprite
ld a, [Buffer2]
call .ClearSprite
.skip
ret
.ClearSprite: ; 50f34 (14:4f34)
push af
hlcoord 0, 1
ld bc, 2 * SCREEN_WIDTH
call AddNTimes
ld bc, 2 * SCREEN_WIDTH
ld a, " "
call ByteFill
pop af
ld hl, Sprites
ld bc, $10
call AddNTimes
ld de, $4
ld c, $4
.gfx_loop
ld [hl], $a0
add hl, de
dec c
jr nz, .gfx_loop
ld de, SFX_SWITCH_POKEMON
call WaitPlaySFX
ret
.SwapMonAndMail: ; 50f62 (14:4f62)
push hl
push de
push bc
ld bc, PartySpecies
ld a, [Buffer2]
ld l, a
ld h, $0
add hl, bc
ld d, h
ld e, l
ld a, [Buffer3]
ld l, a
ld h, $0
add hl, bc
ld a, [hl]
push af
ld a, [de]
ld [hl], a
pop af
ld [de], a
ld a, [Buffer2]
ld hl, PartyMon1Species
ld bc, PARTYMON_STRUCT_LENGTH
call AddNTimes
push hl
ld de, wd002
ld bc, PARTYMON_STRUCT_LENGTH
call CopyBytes
ld a, [Buffer3]
ld hl, PartyMon1
ld bc, PARTYMON_STRUCT_LENGTH
call AddNTimes
pop de
push hl
ld bc, PARTYMON_STRUCT_LENGTH
call CopyBytes
pop de
ld hl, wd002
ld bc, PARTYMON_STRUCT_LENGTH
call CopyBytes
ld a, [Buffer2]
ld hl, PartyMonOT
call SkipNames
push hl
call .CopyNameTowd002
ld a, [Buffer3]
ld hl, PartyMonOT
call SkipNames
pop de
push hl
call .CopyName
pop de
ld hl, wd002
call .CopyName
ld hl, PartyMonNicknames
ld a, [Buffer2]
call SkipNames
push hl
call .CopyNameTowd002
ld hl, PartyMonNicknames
ld a, [Buffer3]
call SkipNames
pop de
push hl
call .CopyName
pop de
ld hl, wd002
call .CopyName
ld hl, sPartyMail
ld a, [Buffer2]
ld bc, MAIL_STRUCT_LENGTH
call AddNTimes
push hl
ld de, wd002
ld bc, MAIL_STRUCT_LENGTH
ld a, BANK(sPartyMail)
call GetSRAMBank
call CopyBytes
ld hl, sPartyMail
ld a, [Buffer3]
ld bc, MAIL_STRUCT_LENGTH
call AddNTimes
pop de
push hl
ld bc, MAIL_STRUCT_LENGTH
call CopyBytes
pop de
ld hl, wd002
ld bc, MAIL_STRUCT_LENGTH
call CopyBytes
call CloseSRAM
pop bc
pop de
pop hl
ret
.CopyNameTowd002: ; 51036 (14:5036)
ld de, wd002
.CopyName: ; 51039 (14:5039)
ld bc, NAME_LENGTH
call CopyBytes
ret

127
engine/tempmon.asm Normal file
View File

@@ -0,0 +1,127 @@
CopyPkmnToTempMon: ; 5084a
; gets the BaseData of a Pkmn
; and copys the PkmnStructure to TempMon
ld a, [CurPartyMon]
ld e, a
call GetPkmnSpecies
ld a, [CurPartySpecies]
ld [CurSpecies], a
call GetBaseData
ld a, [MonType]
ld hl, PartyMon1Species
ld bc, PARTYMON_STRUCT_LENGTH
and a
jr z, .copywholestruct
ld hl, OTPartyMon1Species
ld bc, PARTYMON_STRUCT_LENGTH
cp OTPARTYMON
jr z, .copywholestruct
ld bc, BOXMON_STRUCT_LENGTH
callab CopyBoxmonToTempMon
jr .done
.copywholestruct
ld a, [CurPartyMon]
call AddNTimes
ld de, TempMon
ld bc, PARTYMON_STRUCT_LENGTH
call CopyBytes
.done
ret
CalcwBufferMonStats: ; 5088b
ld bc, wBufferMon
jr _TempMonStatsCalculation
CalcTempmonStats: ; 50890
ld bc, TempMon
_TempMonStatsCalculation: ; 50893
ld hl, MON_LEVEL
add hl, bc
ld a, [hl]
ld [CurPartyLevel], a
ld hl, MON_MAXHP
add hl, bc
ld d, h
ld e, l
ld hl, MON_STAT_EXP - 1
add hl, bc
push bc
ld b, $1
predef CalcPkmnStats
pop bc
ld hl, MON_HP
add hl, bc
ld d, h
ld e, l
ld a, [CurPartySpecies]
cp EGG
jr nz, .not_egg
xor a
ld [de], a
inc de
ld [de], a
jr .zero_status
.not_egg
push bc
ld hl, MON_MAXHP
add hl, bc
ld bc, 2
call CopyBytes
pop bc
.zero_status
ld hl, MON_STATUS
add hl, bc
xor a
ld [hli], a
ld [hl], a
ret
GetPkmnSpecies: ; 508d5
; [MonType] has the type of the Pkmn
; e = Nr. of Pkmn (i.e. [CurPartyMon])
ld a, [MonType]
and a ; PARTYMON
jr z, .partymon
cp OTPARTYMON
jr z, .otpartymon
cp BOXMON
jr z, .boxmon
cp TEMPMON
jr z, .breedmon
; WILDMON
.partymon
ld hl, PartySpecies
jr .done
.otpartymon
ld hl, OTPartySpecies
jr .done
.boxmon
ld a, BANK(sBoxSpecies)
call GetSRAMBank
ld hl, sBoxSpecies
call .done
call CloseSRAM
ret
.breedmon
ld a, [wBreedMon1Species]
jr .done2
.done
ld d, 0
add hl, de
ld a, [hl]
.done2
ld [CurPartySpecies], a
ret

58
event/buena_menu.asm Normal file
View File

@@ -0,0 +1,58 @@
AskRememberPassword: ; 4ae12
call .DoMenu
ld a, $0
jr c, .okay
ld a, $1
.okay
ld [ScriptVar], a
ret
.DoMenu: ; 4ae1f
lb bc, 14, 7
push bc
ld hl, YesNoMenuDataHeader
call CopyMenuDataHeader
pop bc
ld a, b
ld [wMenuBorderLeftCoord], a
add $5
ld [wMenuBorderRightCoord], a
ld a, c
ld [wMenuBorderTopCoord], a
add $4
ld [wMenuBorderBottomCoord], a
call PushWindow
call VerticalMenu
push af
ld c, 15
call DelayFrames
call Buena_ExitMenu
pop af
jr c, .refused
ld a, [wMenuCursorY]
cp $2
jr z, .refused
and a
ret
.refused
ld a, $2
ld [wMenuCursorY], a
scf
ret
Buena_ExitMenu: ; 4ae5e
ld a, [hOAMUpdate]
push af
call ExitMenu
call UpdateSprites
xor a
ld [hOAMUpdate], a
call DelayFrame
ld a, $1
ld [hOAMUpdate], a
call ApplyTilemap
pop af
ld [hOAMUpdate], a
ret

View File

@@ -0,0 +1,38 @@
BugContest_SetCaughtContestMon: ; e6ce
ld a, [wContestMon]
and a
jr z, .firstcatch
ld [wd265], a
callba DisplayAlreadyCaughtText
callba DisplayCaughtContestMonStats
lb bc, 14, 7
call PlaceYesNoBox
ret c
.firstcatch
call .generatestats
ld a, [TempEnemyMonSpecies]
ld [wd265], a
call GetPokemonName
ld hl, .caughttext
call PrintText
ret
.generatestats ; e6fd
ld a, [TempEnemyMonSpecies]
ld [CurSpecies], a
ld [CurPartySpecies], a
call GetBaseData
xor a
ld bc, PARTYMON_STRUCT_LENGTH
ld hl, wContestMon
call ByteFill
xor a
ld [MonType], a
ld hl, wContestMon
jp GeneratePartyMonStats
.caughttext ; 0xe71d
; Caught @ !
text_jump UnknownText_0x1c10c0
db "@"

Some files were not shown because too many files have changed in this diff Show More