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 "@"

48
event/poisonstep_pals.asm Normal file
View File

@ -0,0 +1,48 @@
LoadPoisonBGPals: ; cbcdd
call .LoadPals
ld a, [hCGB]
and a
ret nz
ret ; ????
.LoadPals: ; cbce5
ld a, [hCGB]
and a
jr nz, .cgb
ld a, [TimeOfDayPal]
and $3
cp $3
ld a, %00000000
jr z, .convert_pals
ld a, %10101010
.convert_pals
call DmgToCgbBGPals
ld c, 4
call DelayFrames
callba _UpdateTimePals
ret
.cgb
ld a, [rSVBK]
push af
ld a, $5
ld [rSVBK], a
ld hl, BGPals
ld c, $20
.loop
; RGB 28, 21, 31
ld a, (palred 28 + palgreen 21 + palblue 31) % $100
ld [hli], a
ld a, (palred 28 + palgreen 21 + palblue 31) / $100
ld [hli], a
dec c
jr nz, .loop
pop af
ld [rSVBK], a
ld a, $1
ld [hCGBPalUpdate], a
ld c, 4
call DelayFrames
callba _UpdateTimePals
ret

61
event/print_photo.asm Executable file
View File

@ -0,0 +1,61 @@
PhotoStudio: ; 16dc7
ld hl, .Text_AskWhichMon
call PrintText
callba SelectMonFromParty
jr c, .cancel
ld a, [CurPartySpecies]
cp EGG
jr z, .egg
ld hl, .Text_HoldStill
call PrintText
call DisableSpriteUpdates
callba PrintPartymon
call ReturnToMapWithSpeechTextbox
ld a, [hPrinter]
and a
jr nz, .cancel
ld hl, .Text_Presto
jr .print_text
.cancel
ld hl, .Text_NoPicture
jr .print_text
.egg
ld hl, .Text_Egg
.print_text
call PrintText
ret
; 16e04
.Text_AskWhichMon: ; 0x16e04
; Which #MON should I photo- graph?
text_jump UnknownText_0x1be024
db "@"
; 0x16e09
.Text_HoldStill: ; 0x16e09
; All righty. Hold still for a bit.
text_jump UnknownText_0x1be047
db "@"
; 0x16e0e
.Text_Presto: ; 0x16e0e
; Presto! All done. Come again, OK?
text_jump UnknownText_0x1be06a
db "@"
; 0x16e13
.Text_NoPicture: ; 0x16e13
; Oh, no picture? Come again, OK?
text_jump UnknownText_0x1c0000
db "@"
; 0x16e18
.Text_Egg: ; 0x16e18
; An EGG? My talent is worth more…
text_jump UnknownText_0x1c0021
db "@"
; 0x16e1d

62
event/photo.asm → event/print_unown.asm Executable file → Normal file
View File

@ -231,65 +231,3 @@ PlaceUnownPrinterFrontpic: ; 16dac
predef PlaceGraphic
ret
; 16dc7
PhotoStudio: ; 16dc7
ld hl, .Text_AskWhichMon
call PrintText
callba SelectMonFromParty
jr c, .cancel
ld a, [CurPartySpecies]
cp EGG
jr z, .egg
ld hl, .Text_HoldStill
call PrintText
call DisableSpriteUpdates
callba PrintPartymon
call ReturnToMapWithSpeechTextbox
ld a, [hPrinter]
and a
jr nz, .cancel
ld hl, .Text_Presto
jr .print_text
.cancel
ld hl, .Text_NoPicture
jr .print_text
.egg
ld hl, .Text_Egg
.print_text
call PrintText
ret
; 16e04
.Text_AskWhichMon: ; 0x16e04
; Which #MON should I photo- graph?
text_jump UnknownText_0x1be024
db "@"
; 0x16e09
.Text_HoldStill: ; 0x16e09
; All righty. Hold still for a bit.
text_jump UnknownText_0x1be047
db "@"
; 0x16e0e
.Text_Presto: ; 0x16e0e
; Presto! All done. Come again, OK?
text_jump UnknownText_0x1be06a
db "@"
; 0x16e13
.Text_NoPicture: ; 0x16e13
; Oh, no picture? Come again, OK?
text_jump UnknownText_0x1c0000
db "@"
; 0x16e18
.Text_Egg: ; 0x16e18
; An EGG? My talent is worth more…
text_jump UnknownText_0x1c0021
db "@"
; 0x16e1d

111
event/print_unown_2.asm Normal file
View File

@ -0,0 +1,111 @@
RotateUnownFrontpic: ; e0000
; something to do with Unown printer
push de
xor a
call GetSRAMBank
ld hl, sScratch
ld bc, 0
.loop
push bc
push hl
push bc
ld de, wd002
call .Copy
call .Rotate
ld hl, UnownPrinter_OverworldMapRectangle
pop bc
add hl, bc
add hl, bc
ld a, [hli]
ld e, a
ld d, [hl]
ld hl, wd012
call .Copy
pop hl
ld bc, $10
add hl, bc
pop bc
inc c
ld a, c
cp 7 * 7
jr c, .loop
ld hl, OverworldMap
ld de, sScratch
ld bc, 7 * 7 tiles
call CopyBytes
pop hl
ld de, sScratch
ld c, 7 * 7
ld a, [hROMBank]
ld b, a
call Get2bpp
call CloseSRAM
ret
.Copy: ; e004e
ld c, $10
.loop_copy
ld a, [hli]
ld [de], a
inc de
dec c
jr nz, .loop_copy
ret
.Rotate: ; e0057
ld hl, wd012
ld e, %10000000
ld d, 8
.loop_decompress
push hl
ld hl, wd002
call .CountSetBit
pop hl
ld a, b
ld [hli], a
push hl
ld hl, wd003
call .CountSetBit
pop hl
ld a, b
ld [hli], a
srl e
dec d
jr nz, .loop_decompress
ret
.CountSetBit: ; e0078
ld b, 0
ld c, 8
.loop_count
ld a, [hli]
and e
jr z, .clear
scf
jr .apply
.clear
and a
.apply
rr b
inc hl
dec c
jr nz, .loop_count
ret
overworldmaprect: MACRO
y = 0
rept \1
x = \1 * (\2 +- 1) + y
rept \2
dw OverworldMap tile x
x = x +- \2
endr
y = y + 1
endr
endm
UnownPrinter_OverworldMapRectangle: ; e008b
overworldmaprect 7, 7

View File

@ -227,7 +227,6 @@ hof_mon: MACRO
endm
hall_of_fame: MACRO
\1::
\1WinCount:: db
\1Mon1:: hof_mon \1Mon1
\1Mon2:: hof_mon \1Mon2

965
main.asm

File diff suppressed because it is too large Load Diff

View File

@ -60,7 +60,7 @@ ReceptionistScript_0x9e3e2:
opentext
writetext Text_BattleTowerWelcomesYou
buttonsound
writebyte BATTLETOWERACTION_CHECK_EXPLANATION_READ ; if new save file: bit 1, [s1_be4f]
writebyte BATTLETOWERACTION_CHECK_EXPLANATION_READ ; if new save file: bit 1, [sBattleTowerSaveFileFlags]
special BattleTowerAction
if_not_equal $0, Script_Menu_ChallengeExplanationCancel
jump Script_BattleTowerIntroductionYesNo
@ -85,7 +85,7 @@ Script_ChooseChallenge: ; 0x9e40f
special Special_TryQuickSave
iffalse Script_Menu_ChallengeExplanationCancel
dotrigger $1
writebyte BATTLETOWERACTION_SET_EXPLANATION_READ ; set 1, [s1_be4f]
writebyte BATTLETOWERACTION_SET_EXPLANATION_READ ; set 1, [sBattleTowerSaveFileFlags]
special BattleTowerAction
special BattleTowerRoomMenu
if_equal $a, Script_Menu_ChallengeExplanationCancel

View File

@ -1079,9 +1079,9 @@ BattleTowerAction_CheckExplanationRead: ; 17075f (5c:475f) BattleTowerAction $00
and a
ret z
ld a, BANK(s1_be4f)
ld a, BANK(sBattleTowerSaveFileFlags)
call GetSRAMBank
ld a, [s1_be4f]
ld a, [sBattleTowerSaveFileFlags]
and $2
ld [ScriptVar], a
call CloseSRAM
@ -1097,11 +1097,11 @@ BattleTowerAction_GetChallengeState: ; 170778 (5c:4778) BattleTowerAction $02
ret
BattleTowerAction_SetExplanationRead: ; 170788 (5c:4788) BattleTowerAction $01
ld a, BANK(s1_be4f)
ld a, BANK(sBattleTowerSaveFileFlags)
call GetSRAMBank
ld a, [s1_be4f]
ld a, [sBattleTowerSaveFileFlags]
or $2
ld [s1_be4f], a
ld [sBattleTowerSaveFileFlags], a
call CloseSRAM
ret
@ -1583,20 +1583,20 @@ Function170abe: ; 170abe (5c:4abe) BattleTowerAction $14
and a
ret z
ld a, BANK(s1_be4f)
ld a, BANK(sBattleTowerSaveFileFlags)
call GetSRAMBank
ld a, [s1_be4f]
ld a, [sBattleTowerSaveFileFlags]
and $1
ld [ScriptVar], a
call CloseSRAM
ret
Function170ad7: ; 170ad7 (5c:4ad7) BattleTowerAction $15
ld a, BANK(s1_be4f)
ld a, BANK(sBattleTowerSaveFileFlags)
call GetSRAMBank
ld a, [s1_be4f]
ld a, [sBattleTowerSaveFileFlags]
or $1
ld [s1_be4f], a
ld [sBattleTowerSaveFileFlags], a
call CloseSRAM
ret

View File

@ -0,0 +1,46 @@
GetMobileOTTrainerClass: ; mobile function
ld h, b
ld l, c
call .GetMobileOTTrainerClass
ld c, a
ret
.GetMobileOTTrainerClass: ; 4e930
ld a, [hli]
xor [hl]
ld c, a
jr z, .skip_male_trainers
srl c
srl c
.male_trainer_loop
srl c
ld a, c
cp MaleTrainersEnd - MaleTrainers - 1
jr nc, .male_trainer_loop
inc c
.skip_male_trainers
ld a, [de]
cp $1
ld hl, MaleTrainers
jr nz, .finished
ld hl, FemaleTrainers
ld a, c
and a
jr z, .finished
.female_trainer_loop
srl c
ld a, c
cp FemaleTrainersEnd - FemaleTrainers - 1
jr nc, .female_trainer_loop
inc c
.finished
ld b, $0
add hl, bc
ld a, [hl]
ret
INCLUDE "data/trainers/gendered_trainers.asm"

243
sram.asm
View File

@ -1,9 +1,11 @@
SRAM_Begin EQU $a000
SRAM_End EQU $c000
GLOBAL SRAM_Begin, SRAM_End
SECTION "Scratch", SRAM
sScratch::
@ -11,12 +13,12 @@ SECTION "SRAM Bank 0", SRAM
; a600
sPartyMail::
sPartyMon1Mail:: mailmsg sPartyMon1Mail
sPartyMon2Mail:: mailmsg sPartyMon2Mail
sPartyMon3Mail:: mailmsg sPartyMon3Mail
sPartyMon4Mail:: mailmsg sPartyMon4Mail
sPartyMon5Mail:: mailmsg sPartyMon5Mail
sPartyMon6Mail:: mailmsg sPartyMon6Mail
sPartyMon1Mail:: mailmsg sPartyMon1Mail
sPartyMon2Mail:: mailmsg sPartyMon2Mail
sPartyMon3Mail:: mailmsg sPartyMon3Mail
sPartyMon4Mail:: mailmsg sPartyMon4Mail
sPartyMon5Mail:: mailmsg sPartyMon5Mail
sPartyMon6Mail:: mailmsg sPartyMon6Mail
; a71a
sPartyMailBackup::
@ -28,45 +30,45 @@ sPartyMon5MailBackup:: mailmsg sPartyMon5MailBackup
sPartyMon6MailBackup:: mailmsg sPartyMon6MailBackup
; a834
sMailboxCount:: ds 1
sMailboxCount:: db
sMailbox::
sMailbox1:: mailmsg sMailbox1
sMailbox2:: mailmsg sMailbox2
sMailbox3:: mailmsg sMailbox3
sMailbox4:: mailmsg sMailbox4
sMailbox5:: mailmsg sMailbox5
sMailbox6:: mailmsg sMailbox6
sMailbox7:: mailmsg sMailbox7
sMailbox8:: mailmsg sMailbox8
sMailbox9:: mailmsg sMailbox9
sMailbox10:: mailmsg sMailbox10
sMailbox1:: mailmsg sMailbox1
sMailbox2:: mailmsg sMailbox2
sMailbox3:: mailmsg sMailbox3
sMailbox4:: mailmsg sMailbox4
sMailbox5:: mailmsg sMailbox5
sMailbox6:: mailmsg sMailbox6
sMailbox7:: mailmsg sMailbox7
sMailbox8:: mailmsg sMailbox8
sMailbox9:: mailmsg sMailbox9
sMailbox10:: mailmsg sMailbox10
; aa0b
sMailboxCountBackup:: ds 1
sMailboxCountBackup:: db
sMailboxBackup::
sMailbox1Backup:: mailmsg sMailbox1Backup
sMailbox2Backup:: mailmsg sMailbox2Backup
sMailbox3Backup:: mailmsg sMailbox3Backup
sMailbox4Backup:: mailmsg sMailbox4Backup
sMailbox5Backup:: mailmsg sMailbox5Backup
sMailbox6Backup:: mailmsg sMailbox6Backup
sMailbox7Backup:: mailmsg sMailbox7Backup
sMailbox8Backup:: mailmsg sMailbox8Backup
sMailbox9Backup:: mailmsg sMailbox9Backup
sMailbox10Backup:: mailmsg sMailbox10Backup
sMailbox1Backup:: mailmsg sMailbox1Backup
sMailbox2Backup:: mailmsg sMailbox2Backup
sMailbox3Backup:: mailmsg sMailbox3Backup
sMailbox4Backup:: mailmsg sMailbox4Backup
sMailbox5Backup:: mailmsg sMailbox5Backup
sMailbox6Backup:: mailmsg sMailbox6Backup
sMailbox7Backup:: mailmsg sMailbox7Backup
sMailbox8Backup:: mailmsg sMailbox8Backup
sMailbox9Backup:: mailmsg sMailbox9Backup
sMailbox10Backup:: mailmsg sMailbox10Backup
; abe2
sMysteryGiftItem:: ds 1
sMysteryGiftUnlocked:: ds 1
sBackupMysteryGiftItem:: ds 1
sNumDailyMysteryGiftPartnerIDs:: ds 1
sMysteryGiftItem:: db
sMysteryGiftUnlocked:: db
sBackupMysteryGiftItem:: db
sNumDailyMysteryGiftPartnerIDs:: db
sDailyMysteryGiftPartnerIDs:: ds 5 * 2 ; maximum 5 per day, 2 bytes per ID
sMysteryGiftDecorationsReceived:: flag_array NUM_NON_TROPHY_DECOS
ds 4
sMysteryGiftTimer:: ds 1
sMysteryGiftTimerStartDay:: ds 1
sMysteryGiftTimer:: db
sMysteryGiftTimerStartDay:: db
ds 1
sMysteryGiftTrainerHouseFlag:: ds 1
sMysteryGiftTrainerHouseFlag:: db
sMysteryGiftPartnerName:: ds NAME_LENGTH
s0_ac09:: ds 1
sMysteryGiftTrainer:: ds (1 + 1 + NUM_MOVES) * PARTY_LENGTH + 2 ; ac0a
@ -75,13 +77,15 @@ sBackupMysteryGiftItemEnd::
ds $30
sRTCStatusFlags:: ds 8
sLuckyNumberDay:: ds 1
sLuckyIDNumber:: ds 2
sLuckyNumberDay:: db
sLuckyIDNumber:: dw
SECTION "Backup Save", SRAM
sBackupOptions:: ds OptionsEnd - Options
s0_b208:: ds 1 ; loaded with 99, used to check save corruption
sBackupCheckValue1:: db ; loaded with SAVE_CHECK_VALUE_1, used to check save corruption
sBackupGameData:: ; b209
sBackupPlayerData:: ds wPlayerDataEnd - wPlayerData
@ -93,16 +97,18 @@ sBackupGameDataEnd::
ds $18a
; bf0d
sBackupChecksum:: ds 2
s0_bf0f:: ds 1 ; loaded with 0x7f, used to check save corruption
sStackTop:: ds 2
sBackupChecksum:: dw
sBackupCheckValue2:: db ; loaded with SAVE_CHECK_VALUE_2, used to check save corruption
sStackTop:: dw
SECTION "Save", SRAM
sOptions:: ds OptionsEnd - Options
s1_a008:: ds 1 ; loaded with 99, used to check save corruption
sCheckValue1:: db ; loaded with SAVE_CHECK_VALUE_1, used to check save corruption
sGameData:: ; a009
sPlayerData:: ds wPlayerDataEnd - wPlayerData
@ -114,22 +120,28 @@ sGameDataEnd::
ds $18a
; ad0d
sChecksum:: ds 2
s1_ad0f:: ds 1 ; loaded with 0x7f, used to check save corruption
sChecksum:: dw
sCheckValue2:: db ; loaded with SAVE_CHECK_VALUE_2, used to check save corruption
SECTION "Active Box", SRAM
; ad10
box sBox
; b160
ds $f4
SECTION "Link Battle Data", SRAM
sLinkBattleResults:: ds $c
sLinkBattleStats:: ; b260
sLinkBattleWins:: ds 2
sLinkBattleLosses:: ds 2 ; b262
sLinkBattleDraws:: ds 2 ; b264
sLinkBattleStats::
sLinkBattleWins:: dw ; b260
sLinkBattleLosses:: dw ; b262
sLinkBattleDraws:: dw ; b264
sLinkBattleRecord::
sLinkBattleRecord1:: link_battle_record sLinkBattleRecord1
@ -139,88 +151,80 @@ sLinkBattleRecord4:: link_battle_record sLinkBattleRecord4
sLinkBattleRecord5:: link_battle_record sLinkBattleRecord5
sLinkBattleStatsEnd::
SECTION "SRAM Hall of Fame", SRAM
sHallOfFame:: ; b2c0
; temporary until I can find a way to macrofy it
hall_of_fame sHallOfFame01
hall_of_fame sHallOfFame02
hall_of_fame sHallOfFame03
hall_of_fame sHallOfFame04
hall_of_fame sHallOfFame05
hall_of_fame sHallOfFame06
hall_of_fame sHallOfFame07
hall_of_fame sHallOfFame08
hall_of_fame sHallOfFame09
hall_of_fame sHallOfFame10
hall_of_fame sHallOfFame11
hall_of_fame sHallOfFame12
hall_of_fame sHallOfFame13
hall_of_fame sHallOfFame14
hall_of_fame sHallOfFame15
hall_of_fame sHallOfFame16
hall_of_fame sHallOfFame17
hall_of_fame sHallOfFame18
hall_of_fame sHallOfFame19
hall_of_fame sHallOfFame20
hall_of_fame sHallOfFame21
hall_of_fame sHallOfFame22
hall_of_fame sHallOfFame23
hall_of_fame sHallOfFame24
hall_of_fame sHallOfFame25
hall_of_fame sHallOfFame26
hall_of_fame sHallOfFame27
hall_of_fame sHallOfFame28
hall_of_fame sHallOfFame29
hall_of_fame sHallOfFame30
; x = 1
; rept NUM_HOF_TEAMS
; ; PRINTT("{x}\n")
; if STRLEN({x}) == 2
; PRINTT(STRSUB({x},2,1))
; hall_of_fame STRCAT("sHallOfFame0", STRSUB({x},2,1))
; else
; PRINTT(STRSUB({x},2,2))
; hall_of_fame STRCAT("sHallOfFame", STRSUB({x},2,2))
; endc
; x = x + 1
; endr
SECTION "SRAM Hall of Fame", SRAM
sHallOfFame:: ; b2c0
sHallOfFame01:: hall_of_fame sHallOfFame01
sHallOfFame02:: hall_of_fame sHallOfFame02
sHallOfFame03:: hall_of_fame sHallOfFame03
sHallOfFame04:: hall_of_fame sHallOfFame04
sHallOfFame05:: hall_of_fame sHallOfFame05
sHallOfFame06:: hall_of_fame sHallOfFame06
sHallOfFame07:: hall_of_fame sHallOfFame07
sHallOfFame08:: hall_of_fame sHallOfFame08
sHallOfFame09:: hall_of_fame sHallOfFame09
sHallOfFame10:: hall_of_fame sHallOfFame10
sHallOfFame11:: hall_of_fame sHallOfFame11
sHallOfFame12:: hall_of_fame sHallOfFame12
sHallOfFame13:: hall_of_fame sHallOfFame13
sHallOfFame14:: hall_of_fame sHallOfFame14
sHallOfFame15:: hall_of_fame sHallOfFame15
sHallOfFame16:: hall_of_fame sHallOfFame16
sHallOfFame17:: hall_of_fame sHallOfFame17
sHallOfFame18:: hall_of_fame sHallOfFame18
sHallOfFame19:: hall_of_fame sHallOfFame19
sHallOfFame20:: hall_of_fame sHallOfFame20
sHallOfFame21:: hall_of_fame sHallOfFame21
sHallOfFame22:: hall_of_fame sHallOfFame22
sHallOfFame23:: hall_of_fame sHallOfFame23
sHallOfFame24:: hall_of_fame sHallOfFame24
sHallOfFame25:: hall_of_fame sHallOfFame25
sHallOfFame26:: hall_of_fame sHallOfFame26
sHallOfFame27:: hall_of_fame sHallOfFame27
sHallOfFame28:: hall_of_fame sHallOfFame28
sHallOfFame29:: hall_of_fame sHallOfFame29
sHallOfFame30:: hall_of_fame sHallOfFame30
sHallOfFameEnd::
SECTION "SRAM Crystal Data", SRAM
sMobileEventIndex:: ds 1 ; be3c
sCrystalData::
ds wCrystalDataEnd - wCrystalData
sMobileEventIndexBackup:: ds 1
SECTION "SRAM Crystal Data", SRAM
sMobileEventIndex:: db ; be3c
sCrystalData:: ds wCrystalDataEnd - wCrystalData
sMobileEventIndexBackup:: db
SECTION "SRAM Battle Tower", SRAM
; data of the BattleTower must be in SRAM because you can save and leave between battles
sBattleTowerChallengeState:: ds 1
; Battle Tower data must be in SRAM because you can save and leave between battles
sBattleTowerChallengeState::
; 0: normal
; 2: battle tower
db
sBattleTower:: ; be46
sNrOfBeatenBattleTowerTrainers:: ds 1
sBTChoiceOfLevelGroup:: ds 1
; The 7 trainers of the BattleTower are saved here, so nobody appears more than once
sBTTrainers:: ; sbe48
ds 7
s1_be4f:: ds 1
sBattleTowerReward:: ds 1
; Pkmn of previous trainer
sNrOfBeatenBattleTowerTrainers:: db
sBTChoiceOfLevelGroup:: db
; Battle Tower trainers are saved here, so nobody appears more than once
sBTTrainers:: ds BATTLETOWER_NROFTRAINERS ; sbe48
sBattleTowerSaveFileFlags:: db
sBattleTowerReward:: db
; team of previous trainer
sBTPkmnOfTrainers:: ; 0xbe51
sBTPkmnPrevTrainer1::
ds 1
sBTPkmnPrevTrainer2:: ds 1
sBTPkmnPrevTrainer3:: ds 1
; Pkmn of preprevious trainer
sBTPkmnPrevPrevTrainer1:: ds 1
sBTPkmnPrevPrevTrainer2:: ds 1
sBTPkmnPrevPrevTrainer3:: ds 1
sBTPkmnPrevTrainer1:: db
sBTPkmnPrevTrainer2:: db
sBTPkmnPrevTrainer3:: db
; team of preprevious trainer
sBTPkmnPrevPrevTrainer1:: db
sBTPkmnPrevPrevTrainer2:: db
sBTPkmnPrevPrevTrainer3:: db
SECTION "Boxes 1-7", SRAM, BANK [2]
box sBox1
box sBox2
box sBox3
@ -229,7 +233,9 @@ SECTION "Boxes 1-7", SRAM, BANK [2]
box sBox6
box sBox7
SECTION "Boxes 8-14", SRAM
box sBox8
box sBox9
box sBox10
@ -239,7 +245,8 @@ SECTION "Boxes 8-14", SRAM
box sBox14
SECTION "SRAM Mobile", SRAM, BANK [5]
ds 1 ; Former location for sMobileEventIndex, moved to 1:BE3C in English
ds 1 ; former location for sMobileEventIndex, moved to 1:BE3C in English
sTrainerRankings:: ; a001
sTrainerRankingGameTimeHOF:: ds 4
sTrainerRankingStepCountHOF:: ds 4
@ -285,9 +292,11 @@ sTrainerRankingShortestMagikarp:: ds 2
sTrainerRankingBugContestScore:: ds 2
sTrainerRankingsChecksum:: ds 2
sTrainerRankingsEnd:: ; a083
ds 1 ; Former location for sMobileEventIndexBackup, moved to 1:BE44 in English
sTrainerRankingsBackup:: ds sTrainerRankingsEnd - sTrainerRankings
ds $945
; aa4b
sMobileLoginPassword:: ds MOBILE_LOGIN_PASSWORD_LENGTH

View File

@ -349,7 +349,7 @@ wBT_OTTemp:: battle_tower_struct wBT_OTTemp
NEXTU ; c608
; hall of fame temp struct
hall_of_fame wHallOfFameTemp
wHallOfFameTemp:: hall_of_fame wHallOfFameTemp
NEXTU ; c608
; timeset temp storage
@ -2838,14 +2838,13 @@ w3_d662:: battle_tower_struct w3_d662
UNION ; d742
w3_d742:: battle_tower_struct w3_d742
; d822
NEXTU ; d742
ds $be
wBTChoiceOfLvlGroup::
w3_d800:: ; ds BG_MAP_WIDTH * SCREEN_HEIGHT ($240)
ds $69
ENDU ; d869
w3_d869:: ds $17
w3_d880:: ds 1
w3_d881:: ds 1
@ -2860,7 +2859,6 @@ w3_d8a1:: ds 1
w3_d8a2:: ds 1
w3_d8a3:: ds $19d
w3_da40:: ds $1c0
w3_dc00:: ds SCREEN_WIDTH * SCREEN_HEIGHT
w3_dd68:: ds SCREEN_WIDTH * SCREEN_HEIGHT
ds $11c