This commit is contained in:
Rangi
2018-04-04 23:56:40 -04:00
274 changed files with 667 additions and 554 deletions

54
engine/link/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, wOTPartyCount
ld de, wOTPartyMonOT
ld a, ENEMY_OT_NAME
jr .done
.check_party_ot_name
cp INIT_PLAYEROT_LIST
jr nz, .check_mon_name
ld hl, wPartyCount
ld de, wPartyMonOT
ld a, PARTY_OT_NAME
jr .done
.check_mon_name
cp INIT_MON_LIST
jr nz, .check_item_name
ld hl, wCurMart
ld de, PokemonNames
ld a, MON_NAME
jr .done
.check_item_name
cp INIT_BAG_ITEM_LIST
jr nz, .check_ob_item_name
ld hl, wNumItems
ld de, ItemNames
ld a, ITEM_NAME
jr .done
.check_ob_item_name
ld hl, wCurMart
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

2589
engine/link/link.asm Normal file

File diff suppressed because it is too large Load Diff

95
engine/link/link_2.asm Normal file
View File

@@ -0,0 +1,95 @@
LinkMonStatsScreen: ; 4d319
ld a, [wMenuCursorY]
dec a
ld [wCurPartyMon], a
call LowVolume
predef StatsScreenInit
ld a, [wCurPartyMon]
inc a
ld [wMenuCursorY], a
call ClearScreen
call ClearBGPalettes
call MaxVolume
farcall LoadTradeScreenBorder
farcall Link_WaitBGMap
farcall InitTradeSpeciesList
farcall SetTradeRoomBGPals
call WaitBGMap2
ret
Link_WaitBGMap: ; 4d354
call WaitBGMap
call WaitBGMap2
ret
LinkTextbox2: ; 4d35b
ld h, d
ld l, e
push bc
push hl
call .PlaceBorder
pop hl
pop bc
ld de, wAttrMap - wTileMap
add hl, de
inc b
inc b
inc c
inc c
ld a, PAL_BG_TEXT
.row
push bc
push hl
.col
ld [hli], a
dec c
jr nz, .col
pop hl
ld de, SCREEN_WIDTH
add hl, de
pop bc
dec b
jr nz, .row
ret
; 4d37e
.PlaceBorder: ; 4d37e
push hl
ld a, $76
ld [hli], a
inc a
call .PlaceRow
inc a
ld [hl], a
pop hl
ld de, SCREEN_WIDTH
add hl, de
.loop
push hl
ld a, "┌"
ld [hli], a
ld a, " "
call .PlaceRow
ld [hl], "─"
pop hl
ld de, SCREEN_WIDTH
add hl, de
dec b
jr nz, .loop
ld a, "┐"
ld [hli], a
ld a, "│"
call .PlaceRow
ld [hl], "└"
ret
; 4d3ab
.PlaceRow: ; 4d3ab
ld d, c
.row_loop
ld [hli], a
dec d
jr nz, .row_loop
ret

363
engine/link/link_trade.asm Normal file
View File

@@ -0,0 +1,363 @@
LinkCommsBorderGFX:
INCBIN "gfx/trade/border_tiles.2bpp"
; 16d421
__LoadTradeScreenBorder: ; 16d421
ld de, LinkCommsBorderGFX
ld hl, vTiles2
lb bc, BANK(LinkCommsBorderGFX), 70
call Get2bpp
ret
; 16d42e
Function16d42e: ; 16d42e
ld hl, Tilemap_MobileTradeBorderFullscreen
decoord 0, 0
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
call CopyBytes
ret
; 16d43b
Function16d43b: ; 16d43b
call LoadStandardMenuHeader
call ClearBGPalettes
call ClearTileMap
call ClearSprites
farcall __LoadTradeScreenBorder ; useless to farcall
farcall Function16d42e ; useless to farcall
ld b, SCGB_DIPLOMA
call GetSGBLayout
call SetPalettes
call WaitBGMap
call JoyWaitAorB
call Call_ExitMenu
ret
; 16d465
Tilemap_MobileTradeBorderFullscreen:
INCBIN "gfx/trade/border_mobile_fullscreen.tilemap"
Tilemap_CableTradeBorderTop:
INCBIN "gfx/trade/border_cable_top.tilemap"
Tilemap_CableTradeBorderBottom:
INCBIN "gfx/trade/border_cable_bottom.tilemap"
_LinkTextbox: ; 16d61d
ld h, d
ld l, e
push bc
push hl
call .PlaceBorder
pop hl
pop bc
ld de, wAttrMap - wTileMap
add hl, de
inc b
inc b
inc c
inc c
ld a, PAL_BG_TEXT
.row
push bc
push hl
.col
ld [hli], a
dec c
jr nz, .col
pop hl
ld de, SCREEN_WIDTH
add hl, de
pop bc
dec b
jr nz, .row
ret
; 16d640
.PlaceBorder ; 16d640
push hl
ld a, $30
ld [hli], a
inc a
call .PlaceRow
inc a
ld [hl], a
pop hl
ld de, SCREEN_WIDTH
add hl, de
.loop
push hl
ld a, $33
ld [hli], a
ld a, " "
call .PlaceRow
ld [hl], $34
pop hl
ld de, SCREEN_WIDTH
add hl, de
dec b
jr nz, .loop
ld a, $35
ld [hli], a
ld a, $36
call .PlaceRow
ld [hl], $37
ret
; 16d66d
.PlaceRow ; 16d66d
ld d, c
.row_loop
ld [hli], a
dec d
jr nz, .row_loop
ret
; 16d673
InitTradeSpeciesList: ; 16d673
call _LoadTradeScreenBorder
call Function16d6ae
farcall InitMG_Mobile_LinkTradePalMap
farcall PlaceTradePartnerNamesAndParty
hlcoord 10, 17
ld de, .CANCEL
call PlaceString
ret
; 16d68f
.CANCEL: ; 16d68f
db "CANCEL@"
; 16d696
_LoadTradeScreenBorder: ; 16d696
call __LoadTradeScreenBorder
ret
; 16d69a
LinkComms_LoadPleaseWaitTextboxBorderGFX: ; 16d69a
ld de, LinkCommsBorderGFX + $30 tiles
ld hl, vTiles2 tile $76
lb bc, BANK(LinkCommsBorderGFX), 8
call Get2bpp
ret
; 16d6a7
LoadTradeRoomBGPals_: ; 16d6a7
farcall LoadTradeRoomBGPals
ret
; 16d6ae
Function16d6ae: ; 16d6ae
call Function16d42e
ld hl, Tilemap_CableTradeBorderTop
decoord 0, 0
ld bc, 2 * SCREEN_WIDTH
call CopyBytes
ld hl, Tilemap_CableTradeBorderBottom
decoord 0, 16
ld bc, 2 * SCREEN_WIDTH
call CopyBytes
ret
; 16d6ca
LinkTextbox: ; 16d6ca
call _LinkTextbox
ret
; 16d6ce
Function16d6ce: ; 16d6ce
call LoadStandardMenuHeader
call Function16d6e1
farcall WaitLinkTransfer
call Call_ExitMenu
call WaitBGMap2
ret
; 16d6e1
Function16d6e1: ; 16d6e1
hlcoord 4, 10
ld b, 1
ld c, 10
predef LinkTextboxAtHL
hlcoord 5, 11
ld de, .Waiting
call PlaceString
call WaitBGMap
call WaitBGMap2
ld c, 50
jp DelayFrames
; 16d701
.Waiting: ; 16d701
db "WAITING..!@"
; 16d70c
LinkTradeMenu: ; 16d70c
call .MenuAction
call .GetJoypad
ret
; 16d713
.GetJoypad: ; 16d713
push bc
push af
ld a, [hJoyLast]
and D_PAD
ld b, a
ld a, [hJoyPressed]
and BUTTONS
or b
ld b, a
pop af
ld a, b
pop bc
ld d, a
ret
; 16d725
.MenuAction: ; 16d725
ld hl, w2DMenuFlags2
res 7, [hl]
ld a, [hBGMapMode]
push af
call .loop
pop af
ld [hBGMapMode], a
ret
.loop
call .UpdateCursor
call .UpdateBGMapAndOAM
call .loop2
jr nc, .done
farcall _2DMenuInterpretJoypad
jr c, .done
ld a, [w2DMenuFlags1]
bit 7, a
jr nz, .done
call .GetJoypad
ld b, a
ld a, [wMenuJoypadFilter]
and b
jr z, .loop
.done
ret
; 16d759
.UpdateBGMapAndOAM: ; 16d759
ld a, [hOAMUpdate]
push af
ld a, $1
ld [hOAMUpdate], a
call WaitBGMap
pop af
ld [hOAMUpdate], a
xor a
ld [hBGMapMode], a
ret
.loop2
call RTC
call .TryAnims
ret c
ld a, [w2DMenuFlags1]
bit 7, a
jr z, .loop2
and a
ret
; 16d77a
.UpdateCursor: ; 16d77a
ld hl, wCursorCurrentTile
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [hl]
cp $1f
jr nz, .not_currently_selected
ld a, [wCursorOffCharacter]
ld [hl], a
push hl
push bc
ld bc, MON_NAME_LENGTH
add hl, bc
ld [hl], a
pop bc
pop hl
.not_currently_selected
ld a, [w2DMenuCursorInitY]
ld b, a
ld a, [w2DMenuCursorInitX]
ld c, a
call Coord2Tile
ld a, [w2DMenuCursorOffsets]
swap a
and $f
ld c, a
ld a, [wMenuCursorY]
ld b, a
xor a
dec b
jr z, .skip
.loop3
add c
dec b
jr nz, .loop3
.skip
ld c, SCREEN_WIDTH
call AddNTimes
ld a, [w2DMenuCursorOffsets]
and $f
ld c, a
ld a, [wMenuCursorX]
ld b, a
xor a
dec b
jr z, .skip2
.loop4
add c
dec b
jr nz, .loop4
.skip2
ld c, a
add hl, bc
ld a, [hl]
cp $1f
jr z, .cursor_already_there
ld [wCursorOffCharacter], a
ld [hl], $1f
push hl
push bc
ld bc, MON_NAME_LENGTH
add hl, bc
ld [hl], $1f
pop bc
pop hl
.cursor_already_there
ld a, l
ld [wCursorCurrentTile], a
ld a, h
ld [wCursorCurrentTile + 1], a
ret
; 16d7e7
.TryAnims: ; 16d7e7
ld a, [w2DMenuFlags1]
bit 6, a
jr z, .skip_anims
farcall PlaySpriteAnimationsAndDelayFrame
.skip_anims
call JoyTextDelay
call .GetJoypad
and a
ret z
scf
ret
; 16d7fe

1735
engine/link/mystery_gift.asm Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,152 @@
PrepMysteryGiftDataToSend: ; 2c642 (b:4642)
ld de, wMysteryGiftStaging
ld a, $1
ld [de], a
inc de ; wc801
ld a, BANK(sGameData)
call GetSRAMBank
ld hl, sPlayerData + wPlayerID - wPlayerData
ld a, [hli]
ld [de], a
ld b, a
inc de ; wc802
ld a, [hl]
ld [de], a
ld c, a
inc de ; wc803
push bc
ld hl, sPlayerData + wPlayerName - wPlayerData
ld bc, NAME_LENGTH
call CopyBytes
push de ; wc80e
ld hl, sPokemonData + wPokedexCaught - wPokemonData
ld b, wEndPokedexCaught - wPokedexCaught
call CountSetBits
pop de
pop bc
ld a, [wd265]
ld [de], a
inc de ; wc80f
call CloseSRAM
call Random
and 1
ld [de], a
inc de ; wc810
call .RandomSample
ld [de], a
inc de ; wc811
ld a, c
ld c, b
ld b, a
call .RandomSample
ld [de], a
inc de ; wc812
ld a, BANK(sBackupMysteryGiftItem)
call GetSRAMBank
ld a, [sBackupMysteryGiftItem]
ld [de], a
inc de
ld a, [sBackupMysteryGiftItem + 1]
ld [de], a
ld a, $14
ld [wca00], a
call CloseSRAM
ld hl, wMysteryGiftStaging
ld de, wMysteryGiftPlayerData
ld bc, wMysteryGiftPlayerDataEnd - wMysteryGiftPlayerData
jp CopyBytes
.RandomSample: ; 2c6ac (b:46ac)
push de
call Random
cp 10 percent
jr c, .tenpercent
call Random
and %111
ld d, a
rl d
ld e, $80
.loop
rlc e
dec a
jr nz, .loop
ld a, e
and c
jr z, .skip
ld a, $1
.skip
add d
jr .done
.tenpercent
call Random
cp 20 percent - 1
jr c, .twopercent
call Random
and %011
ld d, a
rl d
ld e, $80
.loop2
rlc e
dec a
jr nz, .loop2
ld a, e
and b
jr z, .skip2
ld a, $1
.skip2
add d
add $10
jr .done
.twopercent
call Random
cp 20 percent - 1
jr c, .pointfourpercent
ld a, b
swap a
and $7
add $18
jr .done
.pointfourpercent
ld a, b
and $80
ld a, $20
jr z, .done
ld a, $21
.done
pop de
ret
MysteryGiftGetItemHeldEffect: ; 2c708 (b:4708)
ld a, c
cp MysteryGiftItems.End - MysteryGiftItems
jr nc, MysteryGiftFallbackItem
ld hl, MysteryGiftItems
ld b, 0
add hl, bc
ld c, [hl]
ret
MysteryGiftGetDecoration: ; 2c715 (b:4715)
ld a, c
cp MysteryGiftDecos.End - MysteryGiftDecos
jr nc, MysteryGiftFallbackItem
ld hl, MysteryGiftDecos
ld b, 0
add hl, bc
ld c, [hl]
ret
MysteryGiftFallbackItem: ; 2c722 (b:4722)
ld c, DECO_POLKADOT_BED ; GREAT_BALL
ret
; 2c725 (b:4725)
INCLUDE "data/items/mystery_gift_items.asm"
INCLUDE "data/decorations/mystery_gift_decos.asm"

View File

@@ -0,0 +1,24 @@
PlaceWaitingText:: ; 4000
hlcoord 3, 10
ld b, 1
ld c, 11
ld a, [wBattleMode]
and a
jr z, .notinbattle
call TextBox
jr .proceed
.notinbattle
predef LinkTextboxAtHL
.proceed
hlcoord 4, 11
ld de, .Waiting
call PlaceString
ld c, 50
jp DelayFrames
.Waiting: ; 4025
db "Waiting...!@"

View File

@@ -0,0 +1,147 @@
; These functions seem to be related to backwards compatibility
ValidateOTTrademon: ; fb57e
ld a, [wd003]
ld hl, wOTPartyMon1Species
call GetPartyLocation
push hl
ld a, [wd003]
inc a
ld c, a
ld b, 0
ld hl, wOTPartyCount
add hl, bc
ld a, [hl]
pop hl
cp EGG
jr z, .matching_or_egg
cp [hl]
jr nz, .abnormal
.matching_or_egg
ld b, h
ld c, l
ld hl, MON_LEVEL
add hl, bc
ld a, [hl]
cp MAX_LEVEL + 1
jr nc, .abnormal
ld a, [wLinkMode]
cp LINK_TIMECAPSULE
jr nz, .normal
ld hl, wOTPartySpecies
ld a, [wd003]
ld c, a
ld b, 0
add hl, bc
ld a, [hl]
; Magnemite and Magneton's types changed
; from Electric to Electric/Steel.
cp MAGNEMITE
jr z, .normal
cp MAGNETON
jr z, .normal
ld [wCurSpecies], a
call GetBaseData
ld hl, wLinkOTPartyMonTypes
add hl, bc
add hl, bc
ld a, [wBaseType1]
cp [hl]
jr nz, .abnormal
inc hl
ld a, [wBaseType2]
cp [hl]
jr nz, .abnormal
.normal
and a
ret
.abnormal
scf
ret
; fb5dd
Functionfb5dd: ; fb5dd
ld a, [wd002]
ld d, a
ld a, [wPartyCount]
ld b, a
ld c, $0
.loop
ld a, c
cp d
jr z, .next
push bc
ld a, c
ld hl, wPartyMon1HP
call GetPartyLocation
pop bc
ld a, [hli]
or [hl]
jr nz, .done
.next
inc c
dec b
jr nz, .loop
ld a, [wd003]
ld hl, wOTPartyMon1HP
call GetPartyLocation
ld a, [hli]
or [hl]
jr nz, .done
scf
ret
.done
and a
ret
; fb60d
PlaceTradePartnerNamesAndParty: ; fb60d
hlcoord 4, 0
ld de, wPlayerName
call PlaceString
ld a, $14
ld [bc], a
hlcoord 4, 8
ld de, wOTPlayerName
call PlaceString
ld a, $14
ld [bc], a
hlcoord 7, 1
ld de, wPartySpecies
call .PlaceSpeciesNames
hlcoord 7, 9
ld de, wOTPartySpecies
.PlaceSpeciesNames: ; fb634
ld c, $0
.loop
ld a, [de]
cp -1
ret z
ld [wd265], a
push bc
push hl
push de
push hl
ld a, c
ld [hProduct], a
call GetPokemonName
pop hl
call PlaceString
pop de
inc de
pop hl
ld bc, SCREEN_WIDTH
add hl, bc
pop bc
inc c
jr .loop
; fb656
INCLUDE "data/pokemon/gen1_base_special.asm"

View File

@@ -0,0 +1,39 @@
ConvertMon_2to1: ; fb8f1
; Takes the Gen-2 Pokemon number stored in wd265, finds it in the Pokered_MonIndices table, and returns its index in wd265.
push bc
push hl
ld a, [wd265]
ld b, a
ld c, 0
ld hl, Pokered_MonIndices
.loop
inc c
ld a, [hli]
cp b
jr nz, .loop
ld a, c
ld [wd265], a
pop hl
pop bc
ret
; fb908
ConvertMon_1to2: ; fb908
; Takes the Gen-1 Pokemon number stored in wd265 and returns the corresponding value from Pokered_MonIndices in wd265.
push bc
push hl
ld a, [wd265]
dec a
ld hl, Pokered_MonIndices
ld b, 0
ld c, a
add hl, bc
ld a, [hl]
ld [wd265], a
pop hl
pop bc
ret
; fb91c
INCLUDE "data/pokemon/gen1_order.asm"