shithub: pokecrystal

Download patch

ref: 1237156948ba0fa3d98b6b35f4a2ec9cb797ed05
parent: ba5bc304f959d2387b45b9320808797272cf958a
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Fri Oct 30 06:45:31 EDT 2020

Identify mobile Name Card exchange labels

--- a/constants/scgb_constants.asm
+++ b/constants/scgb_constants.asm
@@ -35,6 +35,12 @@
 SCGB_PARTY_MENU_HP_BARS EQU $fc
 SCGB_DEFAULT EQU $ff
 
+; GetCrystalCGBLayout arguments (see engine/gfx/crystal_layouts.asm)
+	const_def
+	const CRYSTAL_CGB_MOBILE_0
+	const CRYSTAL_CGB_MOBILE_1
+	const CRYSTAL_CGB_NAME_CARD
+
 ; PredefPals indexes (see gfx/sgb/predef.pal)
 ; GetPredefPal arguments (see engine/gfx/color.asm)
 	const_def
--- a/data/text/common_2.asm
+++ b/data/text/common_2.asm
@@ -260,7 +260,7 @@
 	text "'s home."
 	prompt
 
-_MysteryGiftReceivedCardText::
+_NameCardReceivedCardText::
 	text "Received"
 	line "@"
 	text_ram wMysteryGiftCardHolderName
@@ -267,7 +267,7 @@
 	text "'s CARD."
 	prompt
 
-_MysteryGiftListedCardText::
+_NameCardListedCardText::
 	text_ram wMysteryGiftCardHolderName
 	text "'s CARD was"
 	line "listed as no.@"
@@ -275,17 +275,17 @@
 	text "."
 	prompt
 
-_MysteryGiftNotRegisteredCardText::
+_NameCardNotRegisteredCardText::
 	text "The CARD was not"
 	line "registered."
 	prompt
 
-_MysteryGiftLinkCancelledText::
+_NameCardLinkCancelledText::
 	text "The link has been"
 	line "cancelled."
 	prompt
 
-_MysteryGiftLinkCommErrorText::
+_NameCardLinkCommErrorText::
 	text "Communication"
 	line "error."
 	prompt
--- a/engine/gfx/cgb_layouts.asm
+++ b/engine/gfx/cgb_layouts.asm
@@ -17,19 +17,18 @@
 	ld l, a
 	ld h, 0
 	add hl, hl
-	ld de, .dw
+	ld de, .Jumptable
 	add hl, de
 	ld a, [hli]
 	ld h, [hl]
 	ld l, a
-	ld de, .ReturnFromJumpTable
+	ld de, .done
 	push de
 	jp hl
-
-.ReturnFromJumpTable:
+.done:
 	ret
 
-.dw
+.Jumptable:
 	dw _CGB_BattleGrayscale
 	dw _CGB_BattleColors
 	dw _CGB_PokegearPals
--- a/engine/gfx/crystal_layouts.asm
+++ b/engine/gfx/crystal_layouts.asm
@@ -1,9 +1,9 @@
-GetMysteryGift_MobileAdapterLayout:
+GetCrystalCGBLayout:
 	ld a, b
 	cp SCGB_DEFAULT
-	jr nz, .not_ram
+	jr nz, .not_default
 	ld a, [wDefaultSGBLayout]
-.not_ram
+.not_default
 	push af
 	farcall ResetBGPals
 	pop af
@@ -10,7 +10,7 @@
 	ld l, a
 	ld h, 0
 	add hl, hl
-	ld de, .dw
+	ld de, .Jumptable
 	add hl, de
 	ld a, [hli]
 	ld h, [hl]
@@ -18,15 +18,16 @@
 	ld de, .done
 	push de
 	jp hl
-.done
+.done:
 	ret
 
-.dw
-	dw MG_Mobile_Layout00
-	dw MG_Mobile_Layout01
-	dw MG_Mobile_Layout02
+.Jumptable:
+	dw _CrystalCGB_MobileLayout0
+	dw _CrystalCGB_MobileLayout1
+	dw _CrystalCGB_NameCard
 
-MG_Mobile_Layout_FillBox:
+Crystal_FillBoxCGB:
+; This is a copy of FillBoxCGB.
 .row
 	push bc
 	push hl
@@ -42,7 +43,8 @@
 	jr nz, .row
 	ret
 
-MG_Mobile_Layout_WipeAttrmap:
+Crystal_WipeAttrmap:
+; This is a copy of WipeAttrmap.
 	hlcoord 0, 0, wAttrmap
 	ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
 	xor a
@@ -62,9 +64,9 @@
 	call FarCopyWRAM
 	ret
 
-MG_Mobile_Layout00:
+_CrystalCGB_MobileLayout0:
 	call MG_Mobile_Layout_LoadPals
-	call MG_Mobile_Layout_WipeAttrmap
+	call Crystal_WipeAttrmap
 	call MG_Mobile_Layout_CreatePalBoxes
 	farcall ApplyAttrmap
 	farcall ApplyPals
@@ -74,33 +76,33 @@
 	hlcoord 0, 0, wAttrmap
 	lb bc, 4, 1
 	ld a, $1
-	call MG_Mobile_Layout_FillBox
+	call Crystal_FillBoxCGB
 	lb bc, 2, 1
 	ld a, $2
-	call MG_Mobile_Layout_FillBox
+	call Crystal_FillBoxCGB
 	lb bc, 6, 1
 	ld a, $3
-	call MG_Mobile_Layout_FillBox
+	call Crystal_FillBoxCGB
 	hlcoord 1, 0, wAttrmap
 	ld a, $1
 	lb bc, 3, 18
-	call MG_Mobile_Layout_FillBox
+	call Crystal_FillBoxCGB
 	lb bc, 2, 18
 	ld a, $2
-	call MG_Mobile_Layout_FillBox
+	call Crystal_FillBoxCGB
 	lb bc, 12, 18
 	ld a, $3
-	call MG_Mobile_Layout_FillBox
+	call Crystal_FillBoxCGB
 	hlcoord 19, 0, wAttrmap
 	lb bc, 4, 1
 	ld a, $1
-	call MG_Mobile_Layout_FillBox
+	call Crystal_FillBoxCGB
 	lb bc, 2, 1
 	ld a, $2
-	call MG_Mobile_Layout_FillBox
+	call Crystal_FillBoxCGB
 	lb bc, 6, 1
 	ld a, $3
-	call MG_Mobile_Layout_FillBox
+	call Crystal_FillBoxCGB
 	hlcoord 0, 12, wAttrmap
 	ld bc, 6 * SCREEN_WIDTH
 	ld a, $7
@@ -129,7 +131,7 @@
 	call FarCopyWRAM
 	ret
 
-MG_Mobile_Layout01:
+_CrystalCGB_MobileLayout1:
 	call MG_Mobile_Layout_LoadPals
 	ld de, wBGPals1 palette PAL_BG_TEXT
 	ld hl, .TextPalette
@@ -136,7 +138,7 @@
 	ld bc, 1 palettes
 	ld a, BANK(wBGPals1)
 	call FarCopyWRAM
-	call MG_Mobile_Layout_WipeAttrmap
+	call Crystal_WipeAttrmap
 	hlcoord 0, 0, wAttrmap
 	ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
 	xor a
@@ -170,7 +172,7 @@
 	hlcoord 0, 0, wAttrmap
 	lb bc, 4, SCREEN_WIDTH
 	ld a, $7
-	call MG_Mobile_Layout_FillBox
+	call Crystal_FillBoxCGB
 	hlcoord 0, 2, wAttrmap
 	ld a, $4
 	ld [hl], a
@@ -182,7 +184,7 @@
 	hlcoord 0, 0, wAttrmap
 	lb bc, 2, SCREEN_WIDTH
 	ld a, $7
-	call MG_Mobile_Layout_FillBox
+	call Crystal_FillBoxCGB
 	hlcoord 0, 1, wAttrmap
 	ld a, $4
 	ld [hl], a
@@ -192,7 +194,7 @@
 
 INCLUDE "engine/tilesets/tileset_palettes.asm"
 
-MG_Mobile_Layout02:
+_CrystalCGB_NameCard:
 	ld hl, .BGPalette
 	ld de, wBGPals1
 	ld bc, 1 palettes
@@ -199,7 +201,7 @@
 	ld a, BANK(wBGPals1)
 	call FarCopyWRAM
 	farcall ApplyPals
-	call MG_Mobile_Layout_WipeAttrmap
+	call Crystal_WipeAttrmap
 	farcall ApplyAttrmap
 	ld hl, .OBPalette
 	ld de, wOBPals1
@@ -236,7 +238,7 @@
 	hlcoord 0, 0, wAttrmap
 	lb bc, 16, 2
 	ld a, $4
-	call MG_Mobile_Layout_FillBox
+	call Crystal_FillBoxCGB
 	ld a, $3
 	ldcoord_a 0, 1, wAttrmap
 	ldcoord_a 0, 14, wAttrmap
@@ -243,31 +245,31 @@
 	hlcoord 2, 0, wAttrmap
 	lb bc, 8, 18
 	ld a, $5
-	call MG_Mobile_Layout_FillBox
+	call Crystal_FillBoxCGB
 	hlcoord 2, 8, wAttrmap
 	lb bc, 8, 18
 	ld a, $6
-	call MG_Mobile_Layout_FillBox
+	call Crystal_FillBoxCGB
 	hlcoord 0, 16, wAttrmap
 	lb bc, 2, SCREEN_WIDTH
 	ld a, $4
-	call MG_Mobile_Layout_FillBox
+	call Crystal_FillBoxCGB
 	ld a, $3
 	lb bc, 6, 1
 	hlcoord 6, 1, wAttrmap
-	call MG_Mobile_Layout_FillBox
+	call Crystal_FillBoxCGB
 	ld a, $3
 	lb bc, 6, 1
 	hlcoord 17, 1, wAttrmap
-	call MG_Mobile_Layout_FillBox
+	call Crystal_FillBoxCGB
 	ld a, $3
 	lb bc, 6, 1
 	hlcoord 6, 9, wAttrmap
-	call MG_Mobile_Layout_FillBox
+	call Crystal_FillBoxCGB
 	ld a, $3
 	lb bc, 6, 1
 	hlcoord 17, 9, wAttrmap
-	call MG_Mobile_Layout_FillBox
+	call Crystal_FillBoxCGB
 	ld a, $2
 	hlcoord 2, 16, wAttrmap
 	ld [hli], a
--- a/engine/link/mystery_gift.asm
+++ b/engine/link/mystery_gift.asm
@@ -22,6 +22,8 @@
 
 MESSAGE_PREFIX EQU $5a
 
+NAME_CARD_PREFIX EQU $3c
+
 DoMysteryGift:
 	call ClearTilemap
 	call ClearSprites
@@ -260,7 +262,7 @@
 ExchangeMysteryGiftData:
 	di
 	farcall ClearChannels
-	call InitializeMysteryGiftInterrupts
+	call InitializeIRCommunicationInterrupts
 
 .restart
 	call BeginIRCommunication
@@ -267,7 +269,7 @@
 	call InitializeIRCommunicationRoles
 	ldh a, [hMGStatusFlags]
 	cp MG_CANCELED
-	jp z, EndOrContinueIRCommunication
+	jp z, EndOrContinueMysteryGiftIRCommunication
 	cp MG_OKAY
 	jr nz, .restart
 
@@ -279,8 +281,8 @@
 	ld b, 1
 	call TryReceivingIRDataBlock
 	jr nz, .failed
-	call ReceiveIRDataPayload_GotRegionPrefix
-	jp nz, EndOrContinueIRCommunication
+	call ReceiveMysteryGiftDataPayload_GotRegionPrefix
+	jp nz, EndOrContinueMysteryGiftIRCommunication
 	jr ReceiverExchangeMysteryGiftDataPayloads_GotPayload
 
 .failed
@@ -328,45 +330,45 @@
 	jr z, .continue
 	ld a, MG_CANCELED
 	ldh [hMGStatusFlags], a
-	jp EndOrContinueIRCommunication
+	jp EndOrContinueMysteryGiftIRCommunication
 
 ReceiverExchangeMysteryGiftDataPayloads:
 	; Receive the data payload
-	call ReceiveIRDataPayload
-	jp nz, EndOrContinueIRCommunication
+	call ReceiveMysteryGiftDataPayload
+	jp nz, EndOrContinueMysteryGiftIRCommunication
 	; fallthrough
 ReceiverExchangeMysteryGiftDataPayloads_GotPayload:
 	; Switch roles
 	call BeginSendingIRCommunication
-	jp nz, EndOrContinueIRCommunication
+	jp nz, EndOrContinueMysteryGiftIRCommunication
 	; Send the data payload
-	call SendIRDataPayload
-	jp nz, EndOrContinueIRCommunication
+	call SendMysteryGiftDataPayload
+	jp nz, EndOrContinueMysteryGiftIRCommunication
 	; Switch roles
 	call BeginReceivingIRCommunication
-	jp nz, EndOrContinueIRCommunication
+	jp nz, EndOrContinueMysteryGiftIRCommunication
 	; Receive an empty block
 	call ReceiveEmptyIRDataBlock
-	jp EndOrContinueIRCommunication
+	jp EndOrContinueMysteryGiftIRCommunication
 
 SenderExchangeMysteryGiftDataPayloads:
 	; Send the data payload
-	call SendIRDataPayload
-	jp nz, EndOrContinueIRCommunication
+	call SendMysteryGiftDataPayload
+	jp nz, EndOrContinueMysteryGiftIRCommunication
 	; Switch roles
 	call BeginReceivingIRCommunication
-	jp nz, EndOrContinueIRCommunication
+	jp nz, EndOrContinueMysteryGiftIRCommunication
 	; Receive the data payload
-	call ReceiveIRDataPayload
-	jp nz, EndOrContinueIRCommunication
+	call ReceiveMysteryGiftDataPayload
+	jp nz, EndOrContinueMysteryGiftIRCommunication
 	; Switch roles
 	call BeginSendingIRCommunication
-	jp nz, EndOrContinueIRCommunication
+	jp nz, EndOrContinueMysteryGiftIRCommunication
 	; Send an empty block
 	call SendEmptyIRDataBlock
-	jp EndOrContinueIRCommunication
+	jp EndOrContinueMysteryGiftIRCommunication
 
-ReceiveIRDataPayload:
+ReceiveMysteryGiftDataPayload:
 	; Receive the region prefix
 	ld hl, hMGExchangedByte
 	ld b, 1
@@ -373,7 +375,7 @@
 	call TryReceivingIRDataBlock
 	ret nz
 	; fallthrough
-ReceiveIRDataPayload_GotRegionPrefix:
+ReceiveMysteryGiftDataPayload_GotRegionPrefix:
 	; Receive an empty block
 	call ReceiveEmptyIRDataBlock
 	ldh a, [hMGStatusFlags]
@@ -413,7 +415,7 @@
 	cp MG_OKAY
 	ret
 
-SendIRDataPayload:
+SendMysteryGiftDataPayload:
 	; Send the region prefix
 	ld a, REGION_PREFIX
 	ldh [hMGExchangedByte], a
@@ -458,7 +460,7 @@
 	cp MG_OKAY
 	ret
 
-EndOrContinueIRCommunication:
+EndOrContinueMysteryGiftIRCommunication:
 	nop
 	ldh a, [hMGStatusFlags]
 	; Quit if player canceled
@@ -491,12 +493,12 @@
 	jr z, .sender
 ; receiver
 	call BeginReceivingIRCommunication
-	jr nz, EndOrContinueIRCommunication
+	jr nz, EndOrContinueMysteryGiftIRCommunication
 	jp ReceiverExchangeMysteryGiftDataPayloads
 
 .sender
 	call BeginSendingIRCommunication
-	jr nz, EndOrContinueIRCommunication
+	jr nz, EndOrContinueMysteryGiftIRCommunication
 	jp SenderExchangeMysteryGiftDataPayloads
 
 .quit
@@ -513,121 +515,149 @@
 	pop af
 	ret
 
-Function104c2d:
+ExchangeNameCardData:
 	di
 	farcall ClearChannels
-	call InitializeMysteryGiftInterrupts
+	call InitializeIRCommunicationInterrupts
 
-.loop2
+.restart
 	call BeginIRCommunication
 	call InitializeIRCommunicationRoles
 	ldh a, [hMGStatusFlags]
 	cp MG_CANCELED
-	jp z, Function104d1c
+	jp z, EndNameCardIRCommunication
 	cp MG_OKAY
-	jr nz, .loop2
+	jr nz, .restart
 
 	ldh a, [hMGRole]
 	cp IR_SENDER
 	jr z, .sender
 ; receiver
-	call Function104c8a
-	jp nz, Function104d1c
+	; Receive the data payload
+	call ReceiveNameCardDataPayload
+	jp nz, EndNameCardIRCommunication
+	; Switch roles
 	call BeginSendingIRCommunication
-	jp nz, Function104d1c
-	call Function104cd2
-	jp nz, Function104d1c
+	jp nz, EndNameCardIRCommunication
+	; Send the data payload
+	call SendNameCardDataPayload
+	jp nz, EndNameCardIRCommunication
+	; Switch roles
 	call BeginReceivingIRCommunication
-	jp nz, Function104d1c
+	jp nz, EndNameCardIRCommunication
+	; Receive an empty block
 	call ReceiveEmptyIRDataBlock
-	jp Function104d1c
+	jp EndNameCardIRCommunication
 
 .sender
-	call Function104cd2
-	jp nz, Function104d1c
+	; Send the data payload
+	call SendNameCardDataPayload
+	jp nz, EndNameCardIRCommunication
+	; Switch roles
 	call BeginReceivingIRCommunication
-	jp nz, Function104d1c
-	call Function104c8a
-	jp nz, Function104d1c
+	jp nz, EndNameCardIRCommunication
+	; Receive the data payload
+	call ReceiveNameCardDataPayload
+	jp nz, EndNameCardIRCommunication
+	; Switch roles
 	call BeginSendingIRCommunication
-	jp nz, Function104d1c
+	jp nz, EndNameCardIRCommunication
+	; Send an empty block
 	call SendEmptyIRDataBlock
-	jp Function104d1c
+	jp EndNameCardIRCommunication
 
-Function104c8a:
+ReceiveNameCardDataPayload:
+	; Receive the Name Card prefix
 	ld hl, hMGExchangedByte
 	ld b, 1
 	call TryReceivingIRDataBlock
 	ret nz
+	; Receive an empty block
 	call ReceiveEmptyIRDataBlock
 	ldh a, [hMGStatusFlags]
 	cp MG_OKAY
 	ret nz
+	; Verify the received Name Card prefix
 	ldh a, [hMGExchangedByte]
-	cp $3c
+	cp NAME_CARD_PREFIX
 	jp nz, WrongMysteryGiftRegion
 	swap a
 	ldh [hMGExchangedByte], a
+	; Switch roles
 	call BeginSendingIRCommunication
 	ret nz
+	; Send the swapped Name Card prefix
 	ld hl, hMGExchangedByte
 	ld b, 1
 	call TrySendingIRDataBlock
 	ret nz
+	; Send an empty block
 	call SendEmptyIRDataBlock
 	ldh a, [hMGStatusFlags]
 	cp MG_OKAY
 	ret nz
+	; Switch roles
 	call BeginReceivingIRCommunication
 	ret nz
-	ld hl, wMysteryGiftTrainer
+	; Receive the staged data
+	ld hl, wNameCardData
 	ld a, [wMysteryGiftStagedDataLength]
 	ld b, a
 	call TryReceivingIRDataBlock
 	ret nz
+	; Receive an empty block
 	call ReceiveEmptyIRDataBlock
 	ldh a, [hMGStatusFlags]
 	cp MG_OKAY
 	ret
 
-Function104cd2:
-	ld a, $3c
+SendNameCardDataPayload:
+	; Send the Name Card prefix
+	ld a, NAME_CARD_PREFIX
 	ldh [hMGExchangedByte], a
 	ld hl, hMGExchangedByte
 	ld b, 1
 	call TrySendingIRDataBlock
 	ret nz
+	; Send an empty block
 	call SendEmptyIRDataBlock
 	ldh a, [hMGStatusFlags]
 	cp MG_OKAY
 	ret nz
+	; Switch roles
 	call BeginReceivingIRCommunication
 	ret nz
+	; Receive the swapped Name Card prefix
 	ld hl, hMGExchangedByte
 	ld b, 1
 	call TryReceivingIRDataBlock
 	ret nz
+	; Receive an empty block
 	call ReceiveEmptyIRDataBlock
 	ldh a, [hMGStatusFlags]
 	cp MG_OKAY
 	ret nz
+	; Verify the received swapped Name Card prefix
 	ldh a, [hMGExchangedByte]
 	swap a
-	cp $3c
+	cp NAME_CARD_PREFIX
 	jp nz, WrongMysteryGiftRegion
+	; Switch roles
 	call BeginSendingIRCommunication
 	ret nz
+	; Send the staged data
 	ld hl, wMysteryGiftStaging
 	ld a, [wMysteryGiftStagedDataLength]
 	ld b, a
 	call TrySendingIRDataBlock
 	ret nz
+	; Send an empty block
 	call SendEmptyIRDataBlock
 	ldh a, [hMGStatusFlags]
 	cp MG_OKAY
 	ret
 
-Function104d1c:
+EndNameCardIRCommunication:
 	nop
 	ldh a, [hMGStatusFlags]
 	push af
@@ -674,7 +704,7 @@
 	cp MG_OKAY
 	ret
 
-InitializeMysteryGiftInterrupts:
+InitializeIRCommunicationInterrupts:
 	call StartFastIRTimer
 	ld a, 1 << TIMER
 	ldh [rIE], a
@@ -1175,6 +1205,7 @@
 	ld d, 0
 	call ReceiveInfraredLEDOn
 	jp z, InfraredLEDReceiveTimedOut
+
 	ld d, 16
 	call SendInfraredLEDOff
 	ret
@@ -1536,22 +1567,22 @@
 MysteryGiftGFX:
 INCBIN "gfx/mystery_gift/mystery_gift.2bpp"
 
-Function105688:
+DoNameCardSwap:
 	call ClearTilemap
 	call ClearSprites
 	call WaitBGMap
-	call Function1057d7
+	call InitNameCardLayout
 	hlcoord 3, 8
-	ld de, String_PressAToLink_BToCancel_JP
+	ld de, .String_PressAToLink_BToCancel_JP
 	call PlaceString
 	call WaitBGMap
-	call Function10578c
+	call StageDataForNameCard
 	call ClearMysteryGiftTrainer
-	ld a, $24
+	ld a, wNameCardDataEnd - wNameCardData
 	ld [wMysteryGiftStagedDataLength], a
 	ldh a, [rIE]
 	push af
-	call Function104c2d
+	call ExchangeNameCardData
 	ld d, a
 	xor a
 	ldh [rIF], a
@@ -1559,25 +1590,25 @@
 	ldh [rIE], a
 	ld a, d
 	cp $10
-	jp z, Function105712
-	cp %01101100
-	jp nz, Function10571a
-	call Function1056eb
+	jp z, .LinkCanceled
+	cp MG_OKAY
+	jp nz, .CommunicationError
+	call .SlideNameCardUpOffScreen
 	ld c, 60
 	call DelayFrames
-	call Function105777
-	ld hl, MysteryGiftReceivedCardText
+	call .ClearScreen
+	ld hl, .NameCardReceivedCardText
 	call PrintText
-	ld de, wMysteryGiftTrainer
+	ld de, wNameCardData
 	farcall Function8ac70
 	ld a, c
 	ld [wDeciramBuffer], a
-	ld hl, MysteryGiftNotRegisteredCardText
-	jr c, PrintTextAndExit_JP
-	ld hl, MysteryGiftListedCardText
-	jr PrintTextAndExit_JP
+	ld hl, .NameCardNotRegisteredCardText
+	jr c, .PrintTextAndExit
+	ld hl, .NameCardListedCardText
+	jr .PrintTextAndExit
 
-Function1056eb:
+.SlideNameCardUpOffScreen:
 	ld c, 16
 .loop
 	ld hl, wVirtualOAMSprite00YCoord
@@ -1606,24 +1637,24 @@
 	pop bc
 	jr .loop
 
-Function105712:
-	call Function105777
-	ld hl, MysteryGiftLinkCancelledText
-	jr PrintTextAndExit_JP
+.LinkCanceled:
+	call .ClearScreen
+	ld hl, .NameCardLinkCancelledText
+	jr .PrintTextAndExit
 
-Function10571a:
-	call Function105777
-	ld hl, MysteryGiftLinkCommErrorText
+.CommunicationError:
+	call .ClearScreen
+	ld hl, .NameCardCommErrorText
 	call PrintText
-	jp Function105688
+	jp DoNameCardSwap
 
-PrintTextAndExit_JP:
+.PrintTextAndExit:
 	call PrintText
 	ld a, LCDC_DEFAULT
 	ldh [rLCDC], a
 	ret
 
-String_PressAToLink_BToCancel_JP:
+.String_PressAToLink_BToCancel_JP:
 	db   "エーボタン<WO>おすと"
 	next "つうしん<PKMN>おこなわれるよ!"
 	next "ビーボタン<WO>おすと"
@@ -1630,27 +1661,27 @@
 	next "つうしん<WO>ちゅうし します"
 	db   "@"
 
-MysteryGiftReceivedCardText:
-	text_far _MysteryGiftReceivedCardText
+.NameCardReceivedCardText:
+	text_far _NameCardReceivedCardText
 	text_end
 
-MysteryGiftListedCardText:
-	text_far _MysteryGiftListedCardText
+.NameCardListedCardText:
+	text_far _NameCardListedCardText
 	text_end
 
-MysteryGiftNotRegisteredCardText:
-	text_far _MysteryGiftNotRegisteredCardText
+.NameCardNotRegisteredCardText:
+	text_far _NameCardNotRegisteredCardText
 	text_end
 
-MysteryGiftLinkCancelledText:
-	text_far _MysteryGiftLinkCancelledText
+.NameCardLinkCancelledText:
+	text_far _NameCardLinkCancelledText
 	text_end
 
-MysteryGiftLinkCommErrorText:
-	text_far _MysteryGiftLinkCommErrorText
+.NameCardCommErrorText:
+	text_far _NameCardLinkCommErrorText
 	text_end
 
-Function105777:
+.ClearScreen:
 	call ClearSprites
 	call ClearTilemap
 	call EnableLCD
@@ -1660,8 +1691,8 @@
 	call SetPalettes
 	ret
 
-Function10578c:
-	ld de, wLinkData
+StageDataForNameCard:
+	ld de, wMysteryGiftStaging
 	ld a, BANK(sPlayerData)
 	call OpenSRAM
 	ld hl, sPlayerData + wPlayerName - wPlayerData
@@ -1682,15 +1713,15 @@
 	ld a, BANK(s4_a603) ; aka BANK(s4_a007) ; MBC30 bank used by JP Crystal; inaccessible by MBC3
 	call OpenSRAM
 	ld hl, s4_a603 ; address of MBC30 bank
-	ld bc, $8
+	ld bc, 8
 	call CopyBytes
 	ld hl, s4_a007 ; address of MBC30 bank
-	ld bc, $c
+	ld bc, 12
 	call CopyBytes
 	call CloseSRAM
 	ret
 
-Function1057d7:
+InitNameCardLayout:
 	call ClearBGPalettes
 	call DisableLCD
 	ld hl, CardTradeGFX
@@ -1775,13 +1806,13 @@
 	hlcoord 17, 15
 	ld [hl], $3e
 	ld de, wVirtualOAMSprite00
-	ld hl, .OAM_data
+	ld hl, .NameCardOAMData
 	ld bc, 16 * SPRITEOAMSTRUCT_LENGTH
 	call CopyBytes
 	call EnableLCD
 	call WaitBGMap
-	ld b, $2
-	farcall GetMysteryGift_MobileAdapterLayout
+	ld b, CRYSTAL_CGB_NAME_CARD
+	farcall GetCrystalCGBLayout
 	jp SetPalettes
 
 .Load6Row:
@@ -1829,7 +1860,7 @@
 	jr nz, .row_loop_no_inc
 	ret
 
-.OAM_data:
+.NameCardOAMData:
 	dbsprite  6,  2, 4, 1, $00, 0
 	dbsprite  7,  2, 4, 1, $01, 0
 	dbsprite  8,  2, 4, 1, $02, 0
--- a/mobile/mobile_12.asm
+++ b/mobile/mobile_12.asm
@@ -45,8 +45,8 @@
 	ld [wMusicFadeID + 1], a
 	ld c, 20
 	call DelayFrames
-	ld b, $1
-	call GetMysteryGift_MobileAdapterLayout
+	ld b, CRYSTAL_CGB_MOBILE_1
+	call GetCrystalCGBLayout
 	call ClearBGPalettes
 	hlcoord 0, 0
 	ld b,  2
@@ -652,8 +652,8 @@
 Function48689:
 	ld c, 7
 	call DelayFrames
-	ld b, $1
-	call GetMysteryGift_MobileAdapterLayout
+	ld b, CRYSTAL_CGB_MOBILE_1
+	call GetCrystalCGBLayout
 	call ClearBGPalettes
 	hlcoord 0, 0
 	ld b, 4
--- a/mobile/mobile_22.asm
+++ b/mobile/mobile_22.asm
@@ -3964,7 +3964,7 @@
 Function8ab93:
 	call ClearBGPalettes
 	call LoadStandardMenuHeader
-	farcall Function105688
+	farcall DoNameCardSwap
 	call ClearSprites
 	call Function891fe
 	call Function89b28
--- a/mobile/mobile_menu.asm
+++ b/mobile/mobile_menu.asm
@@ -603,7 +603,7 @@
 	ret
 
 Function4a492:
-	call MG_Mobile_Layout00
+	call _CrystalCGB_MobileLayout0
 	ret
 
 MainMenu_MobileStudium:
--- a/wram.asm
+++ b/wram.asm
@@ -1007,6 +1007,10 @@
 wMysteryGiftTrainerEnd::
 
 NEXTU
+wNameCardData:: ds NAME_LENGTH + 2 + 2 + 1 + 8 + 12
+wNameCardDataEnd::
+
+NEXTU
 wMysteryGiftCardHolderName:: ds PLAYER_NAME_LENGTH
 ENDU