pokered/engine/cable_club.asm

972 lines
21 KiB
NASM
Raw Normal View History

2015-02-07 10:43:08 +00:00
; performs the appropriate action when the player uses the gameboy on the table in the Colosseum or Trade Centre
; In the Colosseum, it starts a battle. In the Trade Centre, it displays the trade selection screen.
; Before doing either action, it swaps random numbers, trainer names and party data with the other gameboy.
CableClub_DoBattleOrTrade: ; 5317 (1:5317)
2014-05-22 22:13:20 +00:00
ld c, $50
call DelayFrames
call ClearScreen
call UpdateSprites
call LoadFontTilePatterns
call LoadHpBarAndStatusTilePatterns
call LoadTrainerInfoTextBoxTiles
hlCoord 3, 8
2015-02-07 10:43:08 +00:00
ld b, 2
ld c, 12
call CableClub_TextBoxBorder
hlCoord 4, 10
2015-02-07 10:43:08 +00:00
ld de, PleaseWaitString
2014-05-22 22:13:20 +00:00
call PlaceString
2015-02-07 10:43:08 +00:00
ld hl, wPlayerNumHits
2014-05-22 22:13:20 +00:00
xor a
ld [hli], a
ld [hl], $50
2015-02-07 10:43:08 +00:00
; fall through
2014-05-22 22:13:20 +00:00
2015-02-07 10:43:08 +00:00
; This is called after completing a trade.
CableClub_DoBattleOrTradeAgain: ; 5345
ld hl, wSerialPlayerDataBlock
ld a, SERIAL_PREAMBLE_BYTE
ld b, 6
.writePlayeDataBlockPreambleLoop
2014-05-22 22:13:20 +00:00
ld [hli], a
dec b
2015-02-07 10:43:08 +00:00
jr nz, .writePlayeDataBlockPreambleLoop
ld hl, wSerialRandomNumberListBlock
ld a, SERIAL_PREAMBLE_BYTE
ld b, 7
.writeRandomNumberListPreambleLoop
2014-05-22 22:13:20 +00:00
ld [hli], a
dec b
2015-02-07 10:43:08 +00:00
jr nz, .writeRandomNumberListPreambleLoop
ld b, 10
.generateRandomNumberListLoop
call Random
2015-02-07 10:43:08 +00:00
cp SERIAL_PREAMBLE_BYTE ; all the random numbers have to be less than the preamble byte
jr nc, .generateRandomNumberListLoop
2014-05-22 22:13:20 +00:00
ld [hli], a
dec b
2015-02-07 10:43:08 +00:00
jr nz, .generateRandomNumberListLoop
ld hl, wSerialPartyMonsPatchList
ld a, SERIAL_PREAMBLE_BYTE
2014-05-22 22:13:20 +00:00
ld [hli], a
ld [hli], a
ld [hli], a
ld b, $c8
xor a
2015-02-07 10:43:08 +00:00
.zeroPlayerDataPatchListLoop
2014-05-22 22:13:20 +00:00
ld [hli], a
dec b
2015-02-07 10:43:08 +00:00
jr nz, .zeroPlayerDataPatchListLoop
ld hl, W_GRASSRATE
ld bc, W_TRAINERHEADERPTR - W_GRASSRATE
.zeroEnemyPartyLoop
2014-05-22 22:13:20 +00:00
xor a
ld [hli], a
dec bc
ld a, b
or c
2015-02-07 10:43:08 +00:00
jr nz, .zeroEnemyPartyLoop
ld hl, wPartyMons - 1
2015-02-07 10:43:08 +00:00
ld de, wSerialPartyMonsPatchList + 10
ld bc, 0
.patchPartyMonsLoop
2014-05-22 22:13:20 +00:00
inc c
ld a, c
2015-02-07 10:43:08 +00:00
cp SERIAL_PREAMBLE_BYTE
jr z, .startPatchListPart2
2014-05-22 22:13:20 +00:00
ld a, b
2015-02-07 10:43:08 +00:00
dec a ; are we in part 2 of the patch list?
jr nz, .checkPlayerDataByte ; jump if in part 1
; if we're in part 2
2014-05-22 22:13:20 +00:00
ld a, c
2015-02-07 10:43:08 +00:00
cp (wPartyMonOT - (wPartyMons - 1)) - (SERIAL_PREAMBLE_BYTE - 1)
jr z, .finishedPatchingPlayerData
.checkPlayerDataByte
2014-05-22 22:13:20 +00:00
inc hl
ld a, [hl]
2015-02-07 10:43:08 +00:00
cp SERIAL_NO_DATA_BYTE
jr nz, .patchPartyMonsLoop
; if the player data byte matches SERIAL_NO_DATA_BYTE, patch it with $FF and record the offset in the patch list
2014-05-22 22:13:20 +00:00
ld a, c
ld [de], a
inc de
ld [hl], $ff
2015-02-07 10:43:08 +00:00
jr .patchPartyMonsLoop
.startPatchListPart2
ld a, SERIAL_PATCH_LIST_PART_TERMINATOR
ld [de], a ; end of part 1
2014-05-22 22:13:20 +00:00
inc de
ld bc, $100
2015-02-07 10:43:08 +00:00
jr .patchPartyMonsLoop
.finishedPatchingPlayerData
ld a, SERIAL_PATCH_LIST_PART_TERMINATOR
ld [de], a ; end of part 2
call Serial_SyncAndExchangeNybble
ld a, [hSerialConnectionStatus]
cp USING_INTERNAL_CLOCK
jr nz, .skipSendingTwoZeroBytes
; if using internal clock
; send two zero bytes for syncing purposes?
2014-05-22 22:13:20 +00:00
call Delay3
xor a
2015-02-07 10:43:08 +00:00
ld [hSerialSendData], a
ld a, START_TRANSFER_INTERNAL_CLOCK
ld [rSC], a
2014-05-22 22:13:20 +00:00
call DelayFrame
xor a
2015-02-07 10:43:08 +00:00
ld [hSerialSendData], a
ld a, START_TRANSFER_INTERNAL_CLOCK
ld [rSC], a
.skipSendingTwoZeroBytes
2014-05-22 22:13:20 +00:00
call Delay3
2015-02-07 10:43:08 +00:00
ld a, (1 << SERIAL)
ld [rIE], a
ld hl, wSerialRandomNumberListBlock
ld de, wSerialOtherGameboyRandomNumberListBlock
2014-05-22 22:13:20 +00:00
ld bc, $11
2015-02-07 10:43:08 +00:00
call Serial_ExchangeBytes
ld a, SERIAL_NO_DATA_BYTE
2014-05-22 22:13:20 +00:00
ld [de], a
2015-02-07 10:43:08 +00:00
ld hl, wSerialPlayerDataBlock
ld de, wSerialEnemyDataBlock
2014-05-22 22:13:20 +00:00
ld bc, $1a8
2015-02-07 10:43:08 +00:00
call Serial_ExchangeBytes
ld a, SERIAL_NO_DATA_BYTE
2014-05-22 22:13:20 +00:00
ld [de], a
2015-02-07 10:43:08 +00:00
ld hl, wSerialPartyMonsPatchList
ld de, wSerialEnemyMonsPatchList
2014-05-22 22:13:20 +00:00
ld bc, $c8
2015-02-07 10:43:08 +00:00
call Serial_ExchangeBytes
ld a, (1 << SERIAL) | (1 << TIMER) | (1 << VBLANK)
ld [rIE], a
2014-05-22 22:13:20 +00:00
ld a, $ff
call PlaySound
2015-02-07 10:43:08 +00:00
ld a, [hSerialConnectionStatus]
cp USING_INTERNAL_CLOCK
jr z, .skipCopyingRandomNumberList ; the list generated by the gameboy clocking the connection is used by both gameboys
ld hl, wSerialOtherGameboyRandomNumberListBlock
.findStartOfRandomNumberListLoop
2014-05-22 22:13:20 +00:00
ld a, [hli]
and a
2015-02-07 10:43:08 +00:00
jr z, .findStartOfRandomNumberListLoop
cp SERIAL_PREAMBLE_BYTE
jr z, .findStartOfRandomNumberListLoop
cp SERIAL_NO_DATA_BYTE
jr z, .findStartOfRandomNumberListLoop
2014-05-22 22:13:20 +00:00
dec hl
2015-02-07 10:43:08 +00:00
ld de, wLinkBattleRandomNumberList
ld c, 10
.copyRandomNumberListLoop
2014-05-22 22:13:20 +00:00
ld a, [hli]
2015-02-07 10:43:08 +00:00
cp SERIAL_NO_DATA_BYTE
jr z, .copyRandomNumberListLoop
2014-05-22 22:13:20 +00:00
ld [de], a
inc de
dec c
2015-02-07 10:43:08 +00:00
jr nz, .copyRandomNumberListLoop
.skipCopyingRandomNumberList
ld hl, wSerialEnemyDataBlock + 3
.findStartOfEnemyNameLoop
2014-05-22 22:13:20 +00:00
ld a, [hli]
and a
2015-02-07 10:43:08 +00:00
jr z, .findStartOfEnemyNameLoop
cp SERIAL_PREAMBLE_BYTE
jr z, .findStartOfEnemyNameLoop
cp SERIAL_NO_DATA_BYTE
jr z, .findStartOfEnemyNameLoop
2014-05-22 22:13:20 +00:00
dec hl
2015-02-07 10:43:08 +00:00
ld de, wLinkEnemyTrainerName
ld c, 11
.copyEnemyNameLoop
2014-05-22 22:13:20 +00:00
ld a, [hli]
2015-02-07 10:43:08 +00:00
cp SERIAL_NO_DATA_BYTE
jr z, .copyEnemyNameLoop
2014-05-22 22:13:20 +00:00
ld [de], a
inc de
dec c
2015-02-07 10:43:08 +00:00
jr nz, .copyEnemyNameLoop
ld de, wEnemyPartyCount
ld bc, W_TRAINERHEADERPTR - wEnemyPartyCount
.copyEnemyPartyLoop
2014-05-22 22:13:20 +00:00
ld a, [hli]
2015-02-07 10:43:08 +00:00
cp SERIAL_NO_DATA_BYTE
jr z, .copyEnemyPartyLoop
2014-05-22 22:13:20 +00:00
ld [de], a
inc de
dec bc
ld a, b
or c
2015-02-07 10:43:08 +00:00
jr nz, .copyEnemyPartyLoop
ld de, wSerialPartyMonsPatchList
ld hl, wPartyMons
2015-02-07 10:43:08 +00:00
ld c, 2 ; patch list has 2 parts
.unpatchPartyMonsLoop
2014-05-22 22:13:20 +00:00
ld a, [de]
inc de
and a
2015-02-07 10:43:08 +00:00
jr z, .unpatchPartyMonsLoop
cp SERIAL_PREAMBLE_BYTE
jr z, .unpatchPartyMonsLoop
cp SERIAL_NO_DATA_BYTE
jr z, .unpatchPartyMonsLoop
cp SERIAL_PATCH_LIST_PART_TERMINATOR
jr z, .finishedPartyMonsPatchListPart
2014-05-22 22:13:20 +00:00
push hl
push bc
ld b, 0
2014-05-22 22:13:20 +00:00
dec a
ld c, a
add hl, bc
2015-02-07 10:43:08 +00:00
ld a, SERIAL_NO_DATA_BYTE
2014-05-22 22:13:20 +00:00
ld [hl], a
pop bc
pop hl
2015-02-07 10:43:08 +00:00
jr .unpatchPartyMonsLoop
.finishedPartyMonsPatchListPart
ld hl, wPartyMons + (SERIAL_PREAMBLE_BYTE - 1)
dec c ; is there another part?
jr nz, .unpatchPartyMonsLoop
ld de, wSerialEnemyMonsPatchList
ld hl, wEnemyMons
2015-02-07 10:43:08 +00:00
ld c, 2 ; patch list has 2 parts
.unpatchEnemyMonsLoop
2014-05-22 22:13:20 +00:00
ld a, [de]
inc de
and a
2015-02-07 10:43:08 +00:00
jr z, .unpatchEnemyMonsLoop
cp SERIAL_PREAMBLE_BYTE
jr z, .unpatchEnemyMonsLoop
cp SERIAL_NO_DATA_BYTE
jr z, .unpatchEnemyMonsLoop
cp SERIAL_PATCH_LIST_PART_TERMINATOR
jr z, .finishedEnemyMonsPatchListPart
2014-05-22 22:13:20 +00:00
push hl
push bc
2015-02-07 10:43:08 +00:00
ld b, 0
2014-05-22 22:13:20 +00:00
dec a
ld c, a
add hl, bc
2015-02-07 10:43:08 +00:00
ld a, SERIAL_NO_DATA_BYTE
2014-05-22 22:13:20 +00:00
ld [hl], a
pop bc
pop hl
2015-02-07 10:43:08 +00:00
jr .unpatchEnemyMonsLoop
.finishedEnemyMonsPatchListPart
ld hl, wEnemyMons + (SERIAL_PREAMBLE_BYTE - 1)
2014-05-22 22:13:20 +00:00
dec c
2015-02-07 10:43:08 +00:00
jr nz, .unpatchEnemyMonsLoop
ld a, wEnemyMonOT % $100
ld [wcf8d], a
2015-02-07 10:43:08 +00:00
ld a, wEnemyMonOT / $100
ld [wcf8e], a
2014-05-22 22:13:20 +00:00
xor a
2015-02-07 10:43:08 +00:00
ld [wTradeCenterPointerTableIndex], a
2014-05-22 22:13:20 +00:00
ld a, $ff
call PlaySound
2015-02-07 10:43:08 +00:00
ld a, [hSerialConnectionStatus]
cp USING_INTERNAL_CLOCK
ld c, 66
call z, DelayFrames ; delay if using internal clock
ld a, [wLinkState]
cp LINK_STATE_START_BATTLE
ld a, LINK_STATE_TRADING
ld [wLinkState], a
2014-05-22 22:13:20 +00:00
jr nz, .asm_5506
2015-02-07 10:43:08 +00:00
ld a, LINK_STATE_BATTLING
ld [wLinkState], a
2014-05-22 22:13:20 +00:00
ld a, SONY1 + $c8
2015-02-07 10:43:08 +00:00
ld [W_CUROPPONENT], a
2014-05-22 22:13:20 +00:00
call ClearScreen
call Delay3
2015-02-07 10:43:08 +00:00
ld hl, W_OPTIONS
2014-05-22 22:13:20 +00:00
res 7, [hl]
predef InitOpponent
predef HealParty
2015-02-07 10:43:08 +00:00
jp ReturnToCableClubRoom
2014-05-22 22:13:20 +00:00
.asm_5506
ld c, BANK(Music_GameCorner)
ld a, MUSIC_GAME_CORNER
call PlayMusic
2015-02-07 10:43:08 +00:00
jr CallCurrentTradeCenterFunction
2014-05-22 22:13:20 +00:00
PleaseWaitString: ; 550f (1:550f)
db "PLEASE WAIT!@"
2015-02-07 10:43:08 +00:00
CallCurrentTradeCenterFunction:
ld hl, TradeCenterPointerTable
ld b, 0
ld a, [wTradeCenterPointerTableIndex]
2014-05-22 22:13:20 +00:00
cp $ff
jp z, LoadTitlescreenGraphics
add a
ld c, a
add hl, bc
ld a, [hli]
ld h, [hl]
ld l, a
jp [hl]
TradeCenter_SelectMon:
call ClearScreen
call LoadTrainerInfoTextBoxTiles
2015-02-07 10:43:08 +00:00
call TradeCenter_DrawPartyLists
call TradeCenter_DrawCancelBox
2014-05-22 22:13:20 +00:00
xor a
2015-02-07 10:43:08 +00:00
ld hl, wSerialSyncAndExchangeNybbleReceiveData
2014-05-22 22:13:20 +00:00
ld [hli], a
ld [hli], a
ld [hli], a
ld [hl], a
ld [wcc37], a
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
ld [wMenuJoypadPollCount], a
2014-05-22 22:13:20 +00:00
inc a
2015-02-07 10:43:08 +00:00
ld [wSerialExchangeNybbleSendData], a
jp .playerMonMenu
.enemyMonMenu
2014-05-22 22:13:20 +00:00
xor a
ld [wcc37], a
2014-05-22 22:13:20 +00:00
inc a
2015-02-07 10:43:08 +00:00
ld [wWhichTradeMonSelectionMenu], a
ld a, D_DOWN | D_LEFT | A_BUTTON
ld [wMenuWatchedKeys], a
ld a, [wEnemyPartyCount]
ld [wMaxMenuItem], a
2015-02-07 10:43:08 +00:00
ld a, 9
ld [wTopMenuItemY], a
2015-02-07 10:43:08 +00:00
ld a, 1
ld [wTopMenuItemX], a
2015-02-07 10:43:08 +00:00
.enemyMonMenu_HandleInput
2015-02-08 00:24:16 +00:00
ld hl, hFlags_0xFFF6
2014-05-22 22:13:20 +00:00
set 1, [hl]
call HandleMenuInput
2015-02-08 00:24:16 +00:00
ld hl, hFlags_0xFFF6
2014-05-22 22:13:20 +00:00
res 1, [hl]
and a
2015-02-07 10:43:08 +00:00
jp z, .getNewInput
bit 0, a ; A button pressed?
jr z, .enemyMonMenu_ANotPressed
; if A button pressed
ld a, [wMaxMenuItem]
2014-05-22 22:13:20 +00:00
ld c, a
ld a, [wCurrentMenuItem]
2014-05-22 22:13:20 +00:00
cp c
2015-02-07 10:43:08 +00:00
jr c, .displayEnemyMonStats
ld a, [wMaxMenuItem]
2014-05-22 22:13:20 +00:00
dec a
ld [wCurrentMenuItem], a
2015-02-07 10:43:08 +00:00
.displayEnemyMonStats
2014-05-22 22:13:20 +00:00
ld a, $1
ld [wd11b], a
2014-05-22 22:13:20 +00:00
callab Func_39bd5
ld hl, wEnemyMons
2015-02-07 10:43:08 +00:00
call TradeCenter_DisplayStats
jp .getNewInput
.enemyMonMenu_ANotPressed
bit 5, a ; Left pressed?
jr z, .enemyMonMenu_LeftNotPressed
; if Left pressed, switch back to the player mon menu
xor a ; player mon menu
ld [wWhichTradeMonSelectionMenu], a
ld a, [wMenuCursorLocation]
2014-05-22 22:13:20 +00:00
ld l, a
ld a, [wMenuCursorLocation + 1]
2014-05-22 22:13:20 +00:00
ld h, a
ld a, [wTileBehindCursor]
2014-05-22 22:13:20 +00:00
ld [hl], a
ld a, [wCurrentMenuItem]
2014-05-22 22:13:20 +00:00
ld b, a
ld a, [wPartyCount]
2014-05-22 22:13:20 +00:00
dec a
cp b
2015-02-07 10:43:08 +00:00
jr nc, .playerMonMenu
ld [wCurrentMenuItem], a
2015-02-07 10:43:08 +00:00
jr .playerMonMenu
.enemyMonMenu_LeftNotPressed
bit 7, a ; Down pressed?
jp z, .getNewInput
jp .selectedCancelMenuItem ; jump if Down pressed
.playerMonMenu
xor a ; player mon menu
ld [wWhichTradeMonSelectionMenu], a
ld [wcc37], a
2015-02-07 10:43:08 +00:00
ld a, D_DOWN | D_RIGHT | A_BUTTON
ld [wMenuWatchedKeys], a
ld a, [wPartyCount]
ld [wMaxMenuItem], a
2015-02-07 10:43:08 +00:00
ld a, 1
ld [wTopMenuItemY], a
2015-02-07 10:43:08 +00:00
ld a, 1
ld [wTopMenuItemX], a
2015-02-07 10:43:08 +00:00
hlCoord 1, 1
2014-05-22 22:13:20 +00:00
ld bc, $0601
call ClearScreenArea
2015-02-07 10:43:08 +00:00
.playerMonMenu_HandleInput
2015-02-08 00:24:16 +00:00
ld hl, hFlags_0xFFF6
2014-05-22 22:13:20 +00:00
set 1, [hl]
call HandleMenuInput
2015-02-08 00:24:16 +00:00
ld hl, hFlags_0xFFF6
2014-05-22 22:13:20 +00:00
res 1, [hl]
2015-02-07 10:43:08 +00:00
and a ; was anything pressed?
jr nz, .playerMonMenu_SomethingPressed
jp .getNewInput
.playerMonMenu_SomethingPressed
bit 0, a ; A button pressed?
jr z, .playerMonMenu_ANotPressed
jp .chosePlayerMon ; jump if A button pressed
; unreachable code
2014-05-22 22:13:20 +00:00
ld a, $4
ld [wd11b], a
2014-05-22 22:13:20 +00:00
callab Func_39bd5
2015-02-07 10:43:08 +00:00
call TradeCenter_DisplayStats
jp .getNewInput
.playerMonMenu_ANotPressed
bit 4, a ; Right pressed?
jr z, .playerMonMenu_RightNotPressed
; if Right pressed, switch to the enemy mon menu
ld a, $1 ; enemy mon menu
ld [wWhichTradeMonSelectionMenu], a
ld a, [wMenuCursorLocation]
2014-05-22 22:13:20 +00:00
ld l, a
ld a, [wMenuCursorLocation + 1]
2014-05-22 22:13:20 +00:00
ld h, a
ld a, [wTileBehindCursor]
2014-05-22 22:13:20 +00:00
ld [hl], a
ld a, [wCurrentMenuItem]
2014-05-22 22:13:20 +00:00
ld b, a
ld a, [wEnemyPartyCount]
2014-05-22 22:13:20 +00:00
dec a
cp b
2015-02-07 10:43:08 +00:00
jr nc, .notPastLastEnemyMon
; when switching to the enemy mon menu, if the menu selection would be past the last enemy mon, select the last enemy mon
ld [wCurrentMenuItem], a
2015-02-07 10:43:08 +00:00
.notPastLastEnemyMon
jp .enemyMonMenu
.playerMonMenu_RightNotPressed
bit 7, a ; Down pressed?
jr z, .getNewInput
jp .selectedCancelMenuItem ; jump if Down pressed
.getNewInput
ld a, [wWhichTradeMonSelectionMenu]
2014-05-22 22:13:20 +00:00
and a
2015-02-07 10:43:08 +00:00
jp z, .playerMonMenu_HandleInput
jp .enemyMonMenu_HandleInput
.chosePlayerMon
2014-05-22 22:13:20 +00:00
call SaveScreenTilesToBuffer1
call PlaceUnfilledArrowMenuCursor
ld a, [wMaxMenuItem]
2014-05-22 22:13:20 +00:00
ld c, a
ld a, [wCurrentMenuItem]
2014-05-22 22:13:20 +00:00
cp c
2015-02-07 10:43:08 +00:00
jr c, .displayStatsTradeMenu
ld a, [wMaxMenuItem]
2014-05-22 22:13:20 +00:00
dec a
2015-02-07 10:43:08 +00:00
.displayStatsTradeMenu
2014-05-22 22:13:20 +00:00
push af
2015-02-07 10:43:08 +00:00
hlCoord 0, 14
ld b, 2
ld c, 18
call CableClub_TextBoxBorder
hlCoord 2, 16
2014-05-22 22:13:20 +00:00
ld de, .statsTrade
call PlaceString
xor a
ld [wCurrentMenuItem], a
ld [wLastMenuItem], a
ld [wMenuJoypadPollCount], a
ld [wMaxMenuItem], a
2015-02-07 10:43:08 +00:00
ld a, 16
ld [wTopMenuItemY], a
2015-02-07 10:43:08 +00:00
.selectStatsMenuItem
ld a, " "
Coorda 11, 16
ld a, D_RIGHT | B_BUTTON | A_BUTTON
ld [wMenuWatchedKeys], a
2015-02-07 10:43:08 +00:00
ld a, 1
ld [wTopMenuItemX], a
2014-05-22 22:13:20 +00:00
call HandleMenuInput
2015-02-07 10:43:08 +00:00
bit 4, a ; Right pressed?
jr nz, .selectTradeMenuItem
bit 1, a ; B button pressed?
jr z, .displayPlayerMonStats
.cancelPlayerMonChoice
2014-05-22 22:13:20 +00:00
pop af
ld [wCurrentMenuItem], a
2014-05-22 22:13:20 +00:00
call LoadScreenTilesFromBuffer1
2015-02-07 10:43:08 +00:00
jp .playerMonMenu
.selectTradeMenuItem
ld a, " "
Coorda 1, 16
ld a, D_LEFT | B_BUTTON | A_BUTTON
ld [wMenuWatchedKeys], a
2015-02-07 10:43:08 +00:00
ld a, 11
ld [wTopMenuItemX], a
2014-05-22 22:13:20 +00:00
call HandleMenuInput
2015-02-07 10:43:08 +00:00
bit 5, a ; Left pressed?
jr nz, .selectStatsMenuItem
bit 1, a ; B button pressed?
jr nz, .cancelPlayerMonChoice
jr .choseTrade
.displayPlayerMonStats
2014-05-22 22:13:20 +00:00
pop af
ld [wCurrentMenuItem], a
2014-05-22 22:13:20 +00:00
ld a, $4
ld [wd11b], a
2014-05-22 22:13:20 +00:00
callab Func_39bd5
2015-02-07 10:43:08 +00:00
call TradeCenter_DisplayStats
2014-05-22 22:13:20 +00:00
call LoadScreenTilesFromBuffer1
2015-02-07 10:43:08 +00:00
jp .playerMonMenu
.choseTrade
2014-05-22 22:13:20 +00:00
call PlaceUnfilledArrowMenuCursor
pop af
ld [wCurrentMenuItem], a
2015-02-07 10:43:08 +00:00
ld [wTradingWhichPlayerMon], a
ld [wSerialExchangeNybbleSendData], a
2015-02-07 11:04:50 +00:00
call Serial_PrintWaitingTextAndSyncAndExchangeNybble
2015-02-07 10:43:08 +00:00
ld a, [wSerialSyncAndExchangeNybbleReceiveData]
2014-05-22 22:13:20 +00:00
cp $f
2015-02-07 10:43:08 +00:00
jp z, CallCurrentTradeCenterFunction ; go back to the beginning of the trade selection menu if the other person cancelled
ld [wTradingWhichEnemyMon], a
call TradeCenter_PlaceSelectedEnemyMonMenuCursor
ld a, $1 ; TradeCenter_Trade
ld [wTradeCenterPointerTableIndex], a
jp CallCurrentTradeCenterFunction
2014-05-22 22:13:20 +00:00
.statsTrade
db "STATS TRADE@"
2015-02-07 10:43:08 +00:00
.selectedCancelMenuItem
ld a, [wCurrentMenuItem]
2014-05-22 22:13:20 +00:00
ld b, a
ld a, [wMaxMenuItem]
2014-05-22 22:13:20 +00:00
cp b
2015-02-07 10:43:08 +00:00
jp nz, .getNewInput
ld a, [wMenuCursorLocation]
2014-05-22 22:13:20 +00:00
ld l, a
ld a, [wMenuCursorLocation + 1]
2014-05-22 22:13:20 +00:00
ld h, a
2015-02-07 10:43:08 +00:00
ld a, " "
2014-05-22 22:13:20 +00:00
ld [hl], a
2015-02-07 10:43:08 +00:00
.cancelMenuItem_Loop
ld a, $ed ; filled arrow cursor
Coorda 1, 16
.cancelMenuItem_JoypadLoop
2014-05-25 18:21:48 +00:00
call JoypadLowSensitivity
2015-02-07 10:43:08 +00:00
ld a, [$ffb5]
and a ; pressed anything?
jr z, .cancelMenuItem_JoypadLoop
bit 0, a ; A button pressed?
jr nz, .cancelMenuItem_APressed
bit 6, a ; Up pressed?
jr z, .cancelMenuItem_JoypadLoop
; if Up pressed
ld a, " "
Coorda 1, 16
ld a, [wPartyCount]
2014-05-22 22:13:20 +00:00
dec a
ld [wCurrentMenuItem], a
2015-02-07 10:43:08 +00:00
jp .playerMonMenu
.cancelMenuItem_APressed
ld a, $ec ; unfilled arrow cursor
Coorda 1, 16
2014-05-22 22:13:20 +00:00
ld a, $f
2015-02-07 10:43:08 +00:00
ld [wSerialExchangeNybbleSendData], a
2015-02-07 11:04:50 +00:00
call Serial_PrintWaitingTextAndSyncAndExchangeNybble
2015-02-07 10:43:08 +00:00
ld a, [wSerialSyncAndExchangeNybbleReceiveData]
cp $f ; did the other person choose Cancel too?
jr nz, .cancelMenuItem_Loop
; fall through
2014-05-22 22:13:20 +00:00
2015-02-07 10:43:08 +00:00
ReturnToCableClubRoom: ; 577d (1:577d)
2014-05-22 22:13:20 +00:00
call GBPalWhiteOutWithDelay3
2015-02-08 02:37:40 +00:00
ld hl, wCharRAMInUseForText
2014-05-22 22:13:20 +00:00
ld a, [hl]
push af
push hl
res 0, [hl]
xor a
ld [wd72d], a
2014-05-22 22:13:20 +00:00
dec a
2014-09-13 07:50:56 +00:00
ld [wDestinationWarpID], a
2014-05-22 22:13:20 +00:00
call LoadMapData
2014-09-14 18:29:18 +00:00
callba ClearVariablesAfterLoadingMapData
2014-05-22 22:13:20 +00:00
pop hl
pop af
ld [hl], a
2014-09-13 07:50:56 +00:00
call GBFadeInFromWhite
2014-05-22 22:13:20 +00:00
ret
2015-02-07 10:43:08 +00:00
TradeCenter_DrawCancelBox:
hlCoord 11, 15
2014-05-22 22:13:20 +00:00
ld a, $7e
2015-02-07 10:43:08 +00:00
ld bc, 2 * 20 + 9
2014-05-22 22:13:20 +00:00
call FillMemory
2015-02-07 10:43:08 +00:00
hlCoord 0, 15
ld b, 1
ld c, 9
call CableClub_TextBoxBorder
hlCoord 2, 16
2014-05-22 22:13:20 +00:00
ld de, CancelTextString
jp PlaceString
CancelTextString:
db "CANCEL@"
2015-02-07 10:43:08 +00:00
TradeCenter_PlaceSelectedEnemyMonMenuCursor:
ld a, [wSerialSyncAndExchangeNybbleReceiveData]
hlCoord 1, 9
ld bc, 20
2014-05-22 22:13:20 +00:00
call AddNTimes
2015-02-07 10:43:08 +00:00
ld [hl], $ec ; cursor
2014-05-22 22:13:20 +00:00
ret
2015-02-07 10:43:08 +00:00
TradeCenter_DisplayStats:
ld a, [wCurrentMenuItem]
2014-05-22 22:13:20 +00:00
ld [wWhichPokemon], a
predef StatusScreen
predef StatusScreen2
2014-05-22 22:13:20 +00:00
call GBPalNormal
call LoadTrainerInfoTextBoxTiles
2015-02-07 10:43:08 +00:00
call TradeCenter_DrawPartyLists
jp TradeCenter_DrawCancelBox
2014-05-22 22:13:20 +00:00
2015-02-07 10:43:08 +00:00
TradeCenter_DrawPartyLists:
hlCoord 0, 0
ld b, 6
ld c, 18
call CableClub_TextBoxBorder
hlCoord 0, 8
ld b, 6
ld c, 18
call CableClub_TextBoxBorder
hlCoord 5, 0
ld de, wPlayerName
2014-05-22 22:13:20 +00:00
call PlaceString
2015-02-07 10:43:08 +00:00
hlCoord 5, 8
ld de, wLinkEnemyTrainerName
2014-05-22 22:13:20 +00:00
call PlaceString
2015-02-07 10:43:08 +00:00
hlCoord 2, 1
ld de, wPartySpecies
2015-02-07 10:43:08 +00:00
call TradeCenter_PrintPartyListNames
hlCoord 2, 9
ld de, wEnemyPartyMons
2015-02-07 10:43:08 +00:00
; fall through
2014-05-22 22:13:20 +00:00
2015-02-07 10:43:08 +00:00
TradeCenter_PrintPartyListNames:
2014-05-22 22:13:20 +00:00
ld c, $0
2015-02-07 10:43:08 +00:00
.loop
2014-05-22 22:13:20 +00:00
ld a, [de]
cp $ff
ret z
ld [wd11e], a
2014-05-22 22:13:20 +00:00
push bc
push hl
push de
push hl
ld a, c
ld [$ff95], a
call GetMonName
pop hl
call PlaceString
pop de
inc de
pop hl
2015-02-07 10:43:08 +00:00
ld bc, 20
2014-05-22 22:13:20 +00:00
add hl, bc
pop bc
inc c
2015-02-07 10:43:08 +00:00
jr .loop
2014-05-22 22:13:20 +00:00
TradeCenter_Trade:
2015-02-07 10:43:08 +00:00
ld c, 100
2014-05-22 22:13:20 +00:00
call DelayFrames
xor a
2015-02-07 10:43:08 +00:00
ld [wSerialExchangeNybbleSendData + 1], a ; unnecessary
ld [wSerialExchangeNybbleReceiveData], a
ld [wcc37], a
ld [wMenuJoypadPollCount], a
2015-02-07 10:43:08 +00:00
hlCoord 0, 12
ld b, 4
ld c, 18
call CableClub_TextBoxBorder
ld a, [wTradingWhichPlayerMon]
ld hl, wPartySpecies
2014-05-22 22:13:20 +00:00
ld c, a
2015-02-07 10:43:08 +00:00
ld b, 0
2014-05-22 22:13:20 +00:00
add hl, bc
ld a, [hl]
ld [wd11e], a
2014-05-22 22:13:20 +00:00
call GetMonName
ld hl, wcd6d
2015-02-07 10:43:08 +00:00
ld de, wNameOfPlayerMonToBeTraded
ld bc, 11
2014-05-22 22:13:20 +00:00
call CopyData
2015-02-07 10:43:08 +00:00
ld a, [wTradingWhichEnemyMon]
ld hl, wEnemyPartyMons
2014-05-22 22:13:20 +00:00
ld c, a
2015-02-07 10:43:08 +00:00
ld b, 0
2014-05-22 22:13:20 +00:00
add hl, bc
ld a, [hl]
ld [wd11e], a
2014-05-22 22:13:20 +00:00
call GetMonName
ld hl, WillBeTradedText
2015-02-07 10:43:08 +00:00
bcCoord 1, 14
2014-05-22 22:13:20 +00:00
call TextCommandProcessor
call SaveScreenTilesToBuffer1
2015-02-07 10:43:08 +00:00
hlCoord 10, 7
2014-05-22 22:13:20 +00:00
ld bc, $080b
2015-02-07 10:43:08 +00:00
ld a, TRADE_CANCEL_MENU
ld [wTwoOptionMenuID], a
2015-02-07 20:27:36 +00:00
ld a, TWO_OPTION_MENU
2015-02-07 10:43:08 +00:00
ld [wTextBoxID], a
2014-05-22 22:13:20 +00:00
call DisplayTextBoxID
call LoadScreenTilesFromBuffer1
ld a, [wCurrentMenuItem]
2014-05-22 22:13:20 +00:00
and a
2015-02-07 10:43:08 +00:00
jr z, .tradeConfirmed
; if trade cancelled
2014-05-22 22:13:20 +00:00
ld a, $1
2015-02-07 10:43:08 +00:00
ld [wSerialExchangeNybbleSendData], a
hlCoord 0, 12
ld b, 4
ld c, 18
call CableClub_TextBoxBorder
hlCoord 1, 14
2014-05-22 22:13:20 +00:00
ld de, TradeCanceled
call PlaceString
2015-02-07 11:04:50 +00:00
call Serial_PrintWaitingTextAndSyncAndExchangeNybble
2015-02-07 10:43:08 +00:00
jp .tradeCancelled
.tradeConfirmed
2014-05-22 22:13:20 +00:00
ld a, $2
2015-02-07 10:43:08 +00:00
ld [wSerialExchangeNybbleSendData], a
2015-02-07 11:04:50 +00:00
call Serial_PrintWaitingTextAndSyncAndExchangeNybble
2015-02-07 10:43:08 +00:00
ld a, [wSerialSyncAndExchangeNybbleReceiveData]
dec a ; did the other person cancel?
jr nz, .doTrade
; if the other person cancelled
hlCoord 0, 12
ld b, 4
ld c, 18
call CableClub_TextBoxBorder
hlCoord 1, 14
2014-05-22 22:13:20 +00:00
ld de, TradeCanceled
call PlaceString
2015-02-07 10:43:08 +00:00
jp .tradeCancelled
.doTrade
ld a, [wTradingWhichPlayerMon]
ld hl, wPartyMonOT
2014-05-22 22:13:20 +00:00
call SkipFixedLengthTextEntries
2015-02-07 10:43:08 +00:00
ld de, wTradedPlayerMonOT
ld bc, 11
2014-05-22 22:13:20 +00:00
call CopyData
ld hl, wPartyMon1Species
2015-02-07 10:43:08 +00:00
ld a, [wTradingWhichPlayerMon]
ld bc, wPartyMon2 - wPartyMon1
2014-05-22 22:13:20 +00:00
call AddNTimes
2015-02-07 10:43:08 +00:00
ld bc, wPartyMon1OTID - wPartyMon1
2014-05-22 22:13:20 +00:00
add hl, bc
ld a, [hli]
2015-02-07 10:43:08 +00:00
ld [wTradedPlayerMonOTID], a
2014-05-22 22:13:20 +00:00
ld a, [hl]
2015-02-07 10:43:08 +00:00
ld [wTradedPlayerMonOTID + 1], a
ld a, [wTradingWhichEnemyMon]
ld hl, wEnemyMonOT
2014-05-22 22:13:20 +00:00
call SkipFixedLengthTextEntries
2015-02-07 10:43:08 +00:00
ld de, wTradedEnemyMonOT
ld bc, 11
2014-05-22 22:13:20 +00:00
call CopyData
ld hl, wEnemyMons
2015-02-07 10:43:08 +00:00
ld a, [wTradingWhichEnemyMon]
ld bc, wEnemyMon2 - wEnemyMon1
2014-05-22 22:13:20 +00:00
call AddNTimes
2015-02-07 10:43:08 +00:00
ld bc, wEnemyMon1OTID - wEnemyMon1
2014-05-22 22:13:20 +00:00
add hl, bc
ld a, [hli]
2015-02-07 10:43:08 +00:00
ld [wTradedEnemyMonOTID], a
2014-05-22 22:13:20 +00:00
ld a, [hl]
2015-02-07 10:43:08 +00:00
ld [wTradedEnemyMonOTID + 1], a
ld a, [wTradingWhichPlayerMon]
2014-05-22 22:13:20 +00:00
ld [wWhichPokemon], a
ld hl, wPartySpecies
2015-02-07 10:43:08 +00:00
ld b, 0
2014-05-22 22:13:20 +00:00
ld c, a
add hl, bc
ld a, [hl]
2015-02-07 10:43:08 +00:00
ld [wTradedPlayerMonSpecies], a
2014-05-22 22:13:20 +00:00
xor a
ld [wcf95], a
2014-05-22 22:13:20 +00:00
call RemovePokemon
2015-02-07 10:43:08 +00:00
ld a, [wTradingWhichEnemyMon]
2014-05-22 22:13:20 +00:00
ld c, a
ld [wWhichPokemon], a
ld hl, wEnemyPartyMons
2015-02-07 10:43:08 +00:00
ld d, 0
2014-05-22 22:13:20 +00:00
ld e, a
add hl, de
ld a, [hl]
ld [wcf91], a
2014-05-22 22:13:20 +00:00
ld hl, wEnemyMons
ld a, c
2015-02-07 10:43:08 +00:00
ld bc, wEnemyMon2 - wEnemyMon1
2014-05-22 22:13:20 +00:00
call AddNTimes
2015-02-08 02:37:40 +00:00
ld de, wLoadedMon
2015-02-07 10:43:08 +00:00
ld bc, wEnemyMon2 - wEnemyMon1
2014-05-22 22:13:20 +00:00
call CopyData
call AddEnemyMonToPlayerParty
ld a, [wPartyCount]
2014-05-22 22:13:20 +00:00
dec a
ld [wWhichPokemon], a
ld a, $1
ld [wccd4], a
2015-02-07 10:43:08 +00:00
ld a, [wTradingWhichEnemyMon]
ld hl, wEnemyPartyMons
2015-02-07 10:43:08 +00:00
ld b, 0
2014-05-22 22:13:20 +00:00
ld c, a
add hl, bc
ld a, [hl]
2015-02-07 10:43:08 +00:00
ld [wTradedEnemyMonSpecies], a
2014-05-22 22:13:20 +00:00
ld a, $a
ld [wMusicHeaderPointer], a
ld a, $2
ld [wc0f0], a
2014-05-22 22:13:20 +00:00
ld a, MUSIC_SAFARI_ZONE
ld [wc0ee], a
2014-05-22 22:13:20 +00:00
call PlaySound
2015-02-07 10:43:08 +00:00
ld c, 100
2014-05-22 22:13:20 +00:00
call DelayFrames
call ClearScreen
call LoadHpBarAndStatusTilePatterns
xor a
ld [wcc5b], a
2015-02-07 10:43:08 +00:00
ld a, [hSerialConnectionStatus]
cp USING_EXTERNAL_CLOCK
jr z, .usingExternalClock
predef Func_410e2
2015-02-07 10:43:08 +00:00
jr .tradeCompleted
.usingExternalClock
predef Func_410f3
2015-02-07 10:43:08 +00:00
.tradeCompleted
2014-08-09 05:39:13 +00:00
callab TryEvolvingMon
2014-05-22 22:13:20 +00:00
call ClearScreen
call LoadTrainerInfoTextBoxTiles
2015-02-07 11:04:50 +00:00
call Serial_PrintWaitingTextAndSyncAndExchangeNybble
2015-02-07 10:43:08 +00:00
ld c, 40
2014-05-22 22:13:20 +00:00
call DelayFrames
2015-02-07 10:43:08 +00:00
hlCoord 0, 12
ld b, 4
ld c, 18
call CableClub_TextBoxBorder
hlCoord 1, 14
2014-05-22 22:13:20 +00:00
ld de, TradeCompleted
call PlaceString
predef SaveSAVtoSRAM2
2015-02-07 10:43:08 +00:00
ld c, 50
2014-05-22 22:13:20 +00:00
call DelayFrames
xor a
2015-02-07 10:43:08 +00:00
ld [wTradeCenterPointerTableIndex], a
jp CableClub_DoBattleOrTradeAgain
.tradeCancelled
ld c, 100
2014-05-22 22:13:20 +00:00
call DelayFrames
2015-02-07 10:43:08 +00:00
xor a ; TradeCenter_SelectMon
ld [wTradeCenterPointerTableIndex], a
jp CallCurrentTradeCenterFunction
2014-05-22 22:13:20 +00:00
WillBeTradedText: ; 5a24 (1:5a24)
TX_FAR _WillBeTradedText
db "@"
TradeCompleted:
db "Trade completed!@"
TradeCanceled:
db "Too bad! The trade"
next "was canceled!@"
2015-02-07 10:43:08 +00:00
TradeCenterPointerTable: ; 5a5b (1:5a5b)
2014-05-22 22:13:20 +00:00
dw TradeCenter_SelectMon
dw TradeCenter_Trade
2015-02-07 10:43:08 +00:00
CableClub_Run: ; 5a5f (1:5a5f)
ld a, [wLinkState]
cp LINK_STATE_START_TRADE
jr z, .doBattleOrTrade
cp LINK_STATE_START_BATTLE
jr z, .doBattleOrTrade
cp LINK_STATE_RESET ; this is never used
2014-05-22 22:13:20 +00:00
ret nz
2015-02-07 10:43:08 +00:00
predef EmptyFunc3
2014-05-23 22:34:35 +00:00
jp Init
2015-02-07 10:43:08 +00:00
.doBattleOrTrade
call CableClub_DoBattleOrTrade
2014-05-22 22:13:20 +00:00
ld hl, Club_GFX
ld a, h
ld [W_TILESETGFXPTR + 1], a
2014-05-22 22:13:20 +00:00
ld a, l
ld [W_TILESETGFXPTR], a
2014-05-22 22:13:20 +00:00
ld a, Bank(Club_GFX)
ld [W_TILESETBANK], a
2014-05-22 22:13:20 +00:00
ld hl, Club_Coll
ld a, h
ld [W_TILESETCOLLISIONPTR + 1], a
2014-05-22 22:13:20 +00:00
ld a, l
ld [W_TILESETCOLLISIONPTR], a
2014-05-22 22:13:20 +00:00
xor a
2015-02-07 10:43:08 +00:00
ld [W_GRASSRATE], a
inc a ; LINK_STATE_IN_CABLE_CLUB
ld [wLinkState], a
ld [$ffb5], a
2014-05-22 22:13:20 +00:00
ld a, $a
ld [wMusicHeaderPointer], a
ld a, BANK(Music_Celadon)
ld [wc0f0], a
2014-05-22 22:13:20 +00:00
ld a, MUSIC_CELADON
ld [wc0ee], a
2014-05-22 22:13:20 +00:00
jp PlaySound
2015-02-07 10:43:08 +00:00
EmptyFunc3: ; 5aaf (1:5aaf)
2014-05-22 22:13:20 +00:00
ret
2015-02-07 10:43:08 +00:00
Diploma_TextBoxBorder: ; 5ab0 (1:5ab0)
call GetPredefRegisters
2014-05-22 22:13:20 +00:00
2015-02-07 10:43:08 +00:00
; b = height
; c = width
CableClub_TextBoxBorder: ; 5ab3 (1:5ab3)
2014-05-22 22:13:20 +00:00
push hl
2015-02-07 10:43:08 +00:00
ld a, $78 ; border upper left corner tile
2014-05-22 22:13:20 +00:00
ld [hli], a
2015-02-07 10:43:08 +00:00
inc a ; border top horizontal line tile
call CableClub_DrawHorizontalLine
inc a ; border upper right corner tile
2014-05-22 22:13:20 +00:00
ld [hl], a
pop hl
2015-02-07 10:43:08 +00:00
ld de, 20
2014-05-22 22:13:20 +00:00
add hl, de
2015-02-07 10:43:08 +00:00
.loop
2014-05-22 22:13:20 +00:00
push hl
2015-02-07 10:43:08 +00:00
ld a, $7b ; border left vertical line tile
2014-05-22 22:13:20 +00:00
ld [hli], a
2015-02-07 10:43:08 +00:00
ld a, " "
call CableClub_DrawHorizontalLine
ld [hl], $77 ; border right vertical line tile
2014-05-22 22:13:20 +00:00
pop hl
2015-02-07 10:43:08 +00:00
ld de, 20
2014-05-22 22:13:20 +00:00
add hl, de
dec b
2015-02-07 10:43:08 +00:00
jr nz, .loop
ld a, $7c ; border lower left corner tile
2014-05-22 22:13:20 +00:00
ld [hli], a
2015-02-07 10:43:08 +00:00
ld a, $76 ; border bottom horizontal line tile
call CableClub_DrawHorizontalLine
ld [hl], $7d ; border lower right corner tile
2014-05-22 22:13:20 +00:00
ret
2015-02-07 10:43:08 +00:00
; c = width
CableClub_DrawHorizontalLine: ; 5ae0 (1:5ae0)
2014-05-22 22:13:20 +00:00
ld d, c
.asm_5ae1
ld [hli], a
dec d
jr nz, .asm_5ae1
ret