InitializePrinterData:
	ld hl, wOverworldMap
	ld bc, $40c
	xor a
	ld [rSB], a
	ld [rSC], a
	ld [wPrinterDataJumptableIndex], a
	call ByteFill
	ld hl, wc2d4
	set 0, [hl]
	ld a, [wGBPrinter]
	and 7
	ld c, a
	ld b, 0
	ld hl, .GBPrinterBrightnessConversionTable
	add hl, bc
	ld a, [hl]
	ld [wPrinterBrightness], a
	xor a
	ld [wJumptableIndex], a
	ret

.GBPrinterBrightnessConversionTable:
	db PRINT_LIGHTEST
	db PRINT_LIGHTER
	db PRINT_NORMAL
	db PRINT_DARKER
	db PRINT_DARKEST

PrinterFunctionJumptable:
	dw Function84077
	dw Function84143
	dw PrinterDelaySix
	dw Function84099
	dw ContinuePrintingIfNoError
	dw Function8412e
	dw Function840c5
	dw ContinuePrintingIfNoError
	dw PrinterDelaySix
	dw Function840de
	dw ContinuePrintingIfNoError
	dw PrinterDelaySix
	dw CheckPrintFinishedNormally
	dw DonePrinting
	dw IncrementJumptableIndex
	dw PrinterDelaySix
	dw Function84103
	dw SetJumptableIndexToOne
	dw FinalizePrinting
	dw _FinalizePrinting

IncrementJumptableIndex:
	ld hl, wJumptableIndex
	inc [hl]
	ret

DecrementJumptableIndex:
	ld hl, wJumptableIndex
	dec [hl]
	ret

DonePrinting:
	xor a
	ld [wPrinterStatusFlags], a
	ld hl, wJumptableIndex
	set 7, [hl]
	ret

SetJumptableIndexToOne:
	ld a, $1
	ld [wJumptableIndex], a
	ret

Function84077:
	call ClearAllPrinterData
	ld hl, Unknown_842b7
	call CopyIntoPrinterData
	xor a
	ld [wPrinterSendByteCounter], a
	ld [wPrinterSendByteCounter + 1], a
	ld a, [wcf65]
	ld [wPrinterRowIndex], a
	call IncrementJumptableIndex
	call Function841c3
	ld a, $1
	ld [wPrinterTextIndex], a
	ret

Function84099:
	call ClearAllPrinterData
	ld hl, wPrinterRowIndex
	ld a, [hl]
	and a
	jr z, Function840c5
	ld hl, Unknown_842c3
	call CopyIntoPrinterData
	call Function84260
	ld a, $80
	ld [wPrinterSendByteCounter], a
	ld a, $2
	ld [wPrinterSendByteCounter + 1], a
	call Function84219
	call IncrementJumptableIndex
	call Function841c3
	ld a, $2
	ld [wPrinterTextIndex], a
	ret

Function840c5:
	ld a, $6
	ld [wJumptableIndex], a
	ld hl, Unknown_842c9
	call CopyIntoPrinterData
	xor a
	ld [wPrinterSendByteCounter], a
	ld [wPrinterSendByteCounter + 1], a
	call IncrementJumptableIndex
	jp Function841c3

Function840de:
	call ClearAllPrinterData
	ld hl, Unknown_842bd
	call CopyIntoPrinterData
	call Function84249
	ld a, $4
	ld [wPrinterSendByteCounter], a
	xor a
	ld [wPrinterSendByteCounter + 1], a
	call Function84219
	call IncrementJumptableIndex
	call Function841c3
	ld a, $3
	ld [wPrinterTextIndex], a
	ret

Function84103:
	call ClearAllPrinterData
	ld hl, Unknown_842b7
	call CopyIntoPrinterData
	xor a
	ld [wPrinterSendByteCounter], a
	ld [wPrinterSendByteCounter + 1], a
	ld a, [wcf65]
	ld [wPrinterRowIndex], a
	call IncrementJumptableIndex
	jp Function841c3

PrinterDelaySix:
	ld hl, wPrinterSerialFrameDelay
	inc [hl]
	ld a, [hl]
	cp $6
	ret c
	xor a
	ld [hl], a
	jp IncrementJumptableIndex

Function8412e:
	ld hl, wPrinterSerialFrameDelay
	inc [hl]
	ld a, [hl]
	cp $6
	ret c
	xor a
	ld [hl], a
	ld hl, wPrinterRowIndex
	dec [hl]
	call DecrementJumptableIndex
	jp DecrementJumptableIndex

Function84143:
	ld a, [wPrinterDataJumptableIndex]
	and a
	ret nz
	ld a, [wPrinterHandshake]
	cp $ff
	jr nz, .printer_connected
	ld a, [wPrinterStatusFlags]
	cp $ff
	jr z, .printer_error

.printer_connected
	ld a, [wPrinterHandshake]
	cp $81
	jr nz, .printer_error
	ld a, [wPrinterStatusFlags]
	and a
	jr nz, .printer_error
	ld hl, wc2d4
	set 1, [hl]
	ld a, $5
	ld [wHandshakeFrameDelay], a
	jp IncrementJumptableIndex

.printer_error
	ld a, $ff
	ld [wPrinterHandshake], a
	ld [wPrinterStatusFlags], a
	ld a, $e
	ld [wJumptableIndex], a
	ret

ContinuePrintingIfNoError:
	ld a, [wPrinterDataJumptableIndex]
	and a
	ret nz
	ld a, [wPrinterStatusFlags]
	and $f0
	jr nz, .printer_error
	ld a, [wPrinterStatusFlags]
	and $1
	jp nz, DecrementJumptableIndex
	jp IncrementJumptableIndex

.printer_error
	ld a, $12
	ld [wJumptableIndex], a
	ret

CheckPrintFinishedNormally:
	ld a, [wPrinterDataJumptableIndex]
	and a
	ret nz
	ld a, [wPrinterStatusFlags]
	and $f3
	ret nz
	jp IncrementJumptableIndex

FinalizePrinting:
	call IncrementJumptableIndex
	; fallthrough

_FinalizePrinting:
	ld a, [wPrinterDataJumptableIndex]
	and a
	ret nz
	ld a, [wPrinterStatusFlags]
	and $f0
	ret nz
	xor a
	ld [wJumptableIndex], a
	ret

Function841c3:
	ld a, [wPrinterDataJumptableIndex]
	and a
	jr nz, Function841c3
	xor a
	ld [wPrinterSendByteOffset], a
	ld [wPrinterSendByteOffset + 1], a
	ld a, $1
	ld [wPrinterDataJumptableIndex], a
	ld a, $88
	ld [rSB], a
	ld a, $1
	ld [rSC], a
	ld a, $81
	ld [rSC], a
	ret

CopyIntoPrinterData:
	ld a, [hli]
	ld [wPrinterData1], a
	ld a, [hli]
	ld [wPrinterData2], a
	ld a, [hli]
	ld [wPrinterData3], a
	ld a, [hli]
	ld [wPrinterData4], a
	ld a, [hli]
	ld [wPrinterChecksum], a
	ld a, [hl]
	ld [wPrinterChecksum + 1], a
	ret

ClearAllPrinterData:
	xor a
	ld hl, wPrinterData1
	ld [hli], a
	ld [hli], a
	ld [hli], a
	ld [hli], a
	ld [hli], a
	ld [hl], a
	ld [wPrinterSendByteCounter], a
	ld [wPrinterSendByteCounter + 1], a
	ld hl, wOverworldMap
	ld bc, $280
	jp ByteFill

Function84219:
	ld hl, 0
	ld bc, $4
	ld de, wPrinterData1
	call PrinterCalculateChecksum
	ld a, [wPrinterSendByteCounter]
	ld c, a
	ld a, [wPrinterSendByteCounter + 1]
	ld b, a
	ld de, wOverworldMap
	call PrinterCalculateChecksum
	ld a, l
	ld [wPrinterChecksum], a
	ld a, h
	ld [wPrinterChecksum + 1], a
	ret

PrinterCalculateChecksum:
	ld a, [de]
	inc de
	add l
	jr nc, .no_carry
	inc h
.no_carry
	ld l, a
	dec bc
	ld a, c
	or b
	jr nz, PrinterCalculateChecksum
	ret

Function84249:
	ld a, $1
	ld [wOverworldMap], a
	ld a, [wcbfa]
	ld [wc801], a
	ld a, $e4
	ld [wc802], a
	ld a, [wPrinterBrightness]
	ld [wc803], a
	ret

Function84260:
	ld a, [wPrinterRowIndex]
	xor $ff
	ld d, a
	ld a, [wcf65]
	inc a
	add d
	ld hl, wPrinterTilemap
	ld de, $28
.asm_84271
	and a
	jr z, .asm_84278
	add hl, de
	dec a
	jr .asm_84271
.asm_84278
	ld e, l
	ld d, h
	ld hl, wOverworldMap
	ld c, $28
.asm_8427f
	ld a, [de]
	inc de
	push bc
	push de
	push hl
	swap a
	ld d, a
	and $f0
	ld e, a
	ld a, d
	and $f
	ld d, a
	and $8
	ld a, d
	jr nz, .asm_84297
	or $90
	jr .asm_84299
.asm_84297
	or $80
.asm_84299
	ld d, a
	lb bc, $21, 1
	call Request2bpp
	pop hl
	ld de, $10
	add hl, de
	pop de
	pop bc
	dec c
	jr nz, .asm_8427f
	ret

Unknown_842b7: db  1, 0, $00, 0,  1, 0
Unknown_842bd: db  2, 0, $04, 0,  0, 0
Unknown_842c3: db  4, 0, $80, 2,  0, 0
Unknown_842c9: db  4, 0, $00, 0,  4, 0

_PrinterReceive::
	ld a, [wPrinterDataJumptableIndex]
	jumptable

.Jumptable
	dw PrinterReceiveNop
	dw PrinterSend33
	dw PrinterSendData1
	dw PrinterSendData2
	dw PrinterSendData3
	dw PrinterSendData4
	dw Function84361
	dw PrinterSendData5
	dw PrinterSendData6
	dw PrinterSendZero
	dw PrinterReceiveStatus1
	dw PrinterGetStatusAndStop
	dw PrinterSend33
	dw PrinterSend0F
	dw PrinterSendZero
	dw PrinterSendZero
	dw PrinterSendZero
	dw PrinterSend0F
	dw PrinterSendZero
	dw PrinterSendZero
	dw PrinterReceiveStatus1
	dw PrinterGetStatusAndStop
	dw PrinterSend33
	dw PrinterSend08
	dw PrinterSendZero
	dw PrinterSendZero
	dw PrinterSendZero
	dw PrinterSend08
	dw PrinterSendZero
	dw PrinterSendZero
	dw PrinterReceiveStatus1
	dw PrinterGetStatusAndStop

PrinterReceiveIncrementIndex:
	ld hl, wPrinterDataJumptableIndex
	inc [hl]
PrinterReceiveNop:
	ret

PrinterSend33:
	ld a, $33
	jr PrinterSendIncrement

PrinterSendData1:
	ld a, [wPrinterData1]
	jr PrinterSendIncrement

PrinterSendData2:
	ld a, [wPrinterData2]
	jr PrinterSendIncrement

PrinterSendData3:
	ld a, [wPrinterData3]
	jr PrinterSendIncrement

PrinterSendData4:
	ld a, [wPrinterData4]
	jr PrinterSendIncrement

Function84361:
	ld hl, wPrinterSendByteCounter
	ld a, [hli]
	ld d, [hl]
	ld e, a
	or d
	jr z, .no_data
	dec de
	ld [hl], d
	dec hl
	ld [hl], e
	ld a, [wPrinterSendByteOffset]
	ld e, a
	ld a, [wPrinterSendByteOffset + 1]
	ld d, a
	ld hl, wOverworldMap
	add hl, de
	inc de
	ld a, e
	ld [wPrinterSendByteOffset], a
	ld a, d
	ld [wPrinterSendByteOffset + 1], a
	ld a, [hl]
	jp PrinterSendByte
.no_data
	call PrinterReceiveIncrementIndex
	; fallthrough

PrinterSendData5:
	ld a, [wPrinterChecksum]
	jr PrinterSendIncrement

PrinterSendData6:
	ld a, [wPrinterChecksum + 1]
	jr PrinterSendIncrement

PrinterReceiveStatus1:
	ld a, [rSB]
	ld [wPrinterHandshake], a
PrinterSendZero:
	xor a
	jr PrinterSendIncrement

PrinterSend0F:
	ld a, $f
	jr PrinterSendIncrement

PrinterSend08:
	ld a, $8
PrinterSendIncrement:
	call PrinterSendByte
	jp PrinterReceiveIncrementIndex

PrinterSendByte:
	ld [rSB], a
	ld a, $1
	ld [rSC], a
	ld a, $81
	ld [rSC], a
	ret

PrinterGetStatusAndStop:
	ld a, [rSB]
	ld [wPrinterStatusFlags], a
	xor a
	ld [wPrinterDataJumptableIndex], a
	ret

Function84559:
	call PrinterClearJoypad
	; fallthrough

Function843f0:
	call JoyTextDelay
	call Function846f6
	ret c
	ld a, [wJumptableIndex]
	cp $80
	ret nc
	jumptable PrinterFunctionJumptable
	call CheckPrinterError
	call ShowPrinterStatus
	call DelayFrame
	jr Function843f0

ResetPrinterControlData:
	xor a
	ld [wc2d4], a
	ld [wPrinterDataJumptableIndex], a
	ret

Function84425:
	call ReturnToMapFromSubmenu
	jp RestartMapMusic

PrintDexEntry:
	ld a, [wcf65]
	push af
	ld hl, vFontTiles
	ld de, FontInversed
	lb bc, BANK(FontInversed), $80
	call Request1bpp
	xor a
	ld [hPrinter], a
	call PlayPrinterMusic
	ld a, [rIE]
	push af
	xor a
	ld [rIF], a
	ld a, $9
	ld [rIE], a
	call InitializePrinterData
	ld a, $10
	ld [wcbfa], a
	callba PrintPage1
	call ClearTileMap
	ld a, $e4
	call DmgToCgbBGPals
	call DelayFrame
	ld hl, hVBlank
	ld a, [hl]
	push af
	ld [hl], $4
	ld a, $8
	ld [wcf65], a
	call PrinterClearJoypad
	call Function843f0
	jr c, .asm_8449d
	call ResetPrinterControlData
	ld c, 12
	call DelayFrames
	xor a
	ld [hBGMapMode], a
	call InitializePrinterData
	ld a, $3
	ld [wcbfa], a
	callba PrintPage2
	call PrinterClearJoypad
	ld a, $4
	ld [wcf65], a
	call Function843f0

.asm_8449d
	pop af
	ld [hVBlank], a
	call ResetPrinterControlData
	xor a
	ld [rIF], a
	pop af
	ld [rIE], a
	call Function84425
	ld c, $8
.asm_844ae
	call LowVolume
	call DelayFrame
	dec c
	jr nz, .asm_844ae
	pop af
	ld [wcf65], a
	ret

PrintPCBox:
	ld a, [wcf65]
	push af
	ld a, $9
	ld [wcf65], a
	ld a, e
	ld [wd004], a
	ld a, d
	ld [wd005], a
	ld a, b
	ld [wd006], a
	ld a, c
	ld [wd007], a
	xor a
	ld [hPrinter], a
	ld [wd003], a
	call PlayPrinterMusic
	ld a, [rIE]
	push af
	xor a
	ld [rIF], a
	ld a, $9
	ld [rIE], a
	ld hl, hVBlank
	ld a, [hl]
	push af
	ld [hl], $4
	xor a
	ld [hBGMapMode], a
	call Function84817
	ld a, $10
	call Function84419
	call Function84559
	jr c, .asm_84545
	call ResetPrinterControlData
	ld c, 12
	call DelayFrames
	xor a
	ld [hBGMapMode], a
	call Function8486f
	xor a
	call Function84419
	call Function84559
	jr c, .asm_84545
	call ResetPrinterControlData
	ld c, 12
	call DelayFrames
	xor a
	ld [hBGMapMode], a
	call Function84893
	xor a
	call Function84419
	call Function84559
	jr c, .asm_84545
	call ResetPrinterControlData
	ld c, 12
	call DelayFrames
	xor a
	ld [hBGMapMode], a
	call Function848b7
	ld a, $3
	call Function84419
	call Function84559
.asm_84545
	pop af
	ld [hVBlank], a
	call ResetPrinterControlData
	xor a
	ld [rIF], a
	pop af
	ld [rIE], a
	call Function84425
	pop af
	ld [wcf65], a
	ret

Function845db:
	ld a, [wcf65]
	push af
	xor a
	ld [hPrinter], a
	call PlayPrinterMusic
	ld a, [rIE]
	push af
	xor a
	ld [rIF], a
	ld a, $9
	ld [rIE], a
	xor a
	ld [hBGMapMode], a
	ld a, $13
	call Function84419
	ld hl, hVBlank
	ld a, [hl]
	push af
	ld [hl], $4
	ld a, $9
	ld [wcf65], a
	call Function843f0
	pop af
	ld [hVBlank], a
	call ResetPrinterControlData
	call CopyPrinterTilemapToTilemap
	xor a
	ld [rIF], a
	pop af
	ld [rIE], a
	pop af
	ld [wcf65], a
	ret

Function16dac:
	hlcoord 0, 0
	ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
	ld a, " "
	call ByteFill
	hlcoord 7, 11
	ld a, $31
	ld [hGraphicStartTile], a
	lb bc, 7, 7
	predef_jump PlaceGraphic

PrintPartymon:
	ld a, [wcf65]
	push af
	xor a
	ld [hPrinter], a
	call PlayPrinterMusic
	ld a, [rIE]
	push af
	xor a
	ld [rIF], a
	ld a, $9
	ld [rIE], a
	xor a
	ld [hBGMapMode], a
	callba Function1dc381
	ld a, $10
	call Function84419
	ld hl, hVBlank
	ld a, [hl]
	push af
	ld [hl], $4
	ld a, $8
	ld [wcf65], a
	call PrinterClearJoypad
	call Function843f0
	jr c, .asm_84671
	call ResetPrinterControlData
	ld c, 12
	call DelayFrames
	xor a
	ld [hBGMapMode], a
	callba Function1dc47b
	ld a, $3
	call Function84419
	ld a, $9
	ld [wcf65], a
	call PrinterClearJoypad
	call Function843f0

.asm_84671
	pop af
	ld [hVBlank], a
	call ResetPrinterControlData
	call CopyPrinterTilemapToTilemap
	xor a
	ld [rIF], a
	pop af
	ld [rIE], a
	call Function84425
	pop af
	ld [wcf65], a
	ret

_PrintDiploma:
	ld a, [wcf65]
	push af
	callba ShowDiploma
	xor a
	ld [hPrinter], a
	call PlayPrinterMusic
	ld a, [rIE]
	push af
	xor a
	ld [rIF], a
	ld a, $9
	ld [rIE], a
	ld hl, hVBlank
	ld a, [hl]
	push af
	ld [hl], $4
	ld a, $10
	call Function84419
	call PrinterClearJoypad
	ld a, $9
	ld [wcf65], a
	call Function843f0
	jr c, .asm_846e2
	call ResetPrinterControlData
	ld c, 12
	call DelayFrames
	call LoadTileMapToTempTileMap
	xor a
	ld [hBGMapMode], a
	callba PrintDiplomaPlayTimeAndSignature
	ld a, $3
	call Function84419
	call Call_LoadTempTileMapToTileMap
	call PrinterClearJoypad
	ld a, $9
	ld [wcf65], a
	call Function843f0

.asm_846e2
	pop af
	ld [hVBlank], a
	call ResetPrinterControlData
	xor a
	ld [rIF], a
	pop af
	ld [rIE], a
	call Function84425
	pop af
	ld [wcf65], a
	ret

Function846f6:
	ld a, [hJoyDown]
	and B_BUTTON
	ret z
	ld a, [wca80]
	cp $c
	jr nz, .asm_84722
.asm_84705
	ld a, [wPrinterDataJumptableIndex]
	and a
	jr nz, .asm_84705
	ld a, $16
	ld [wPrinterDataJumptableIndex], a
	ld a, $88
	ld [rSB], a
	ld a, $1
	ld [rSC], a
	ld a, $81
	ld [rSC], a
.asm_8471c
	ld a, [wPrinterDataJumptableIndex]
	and a
	jr nz, .asm_8471c

.asm_84722
	ld a, $1
	ld [hPrinter], a
	scf
	ret

Function84419:
	push af
	call InitializePrinterData
	pop af
	ld [wcbfa], a
	coord hl, 0, 0
	ld de, wPrinterTilemap
	ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
	rst CopyBytes
	ret

CopyPrinterTilemapToTilemap:
	ld hl, wPrinterTilemap
	coord de, 0, 0
	ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
	rst CopyBytes
	ret

PrinterClearJoypad:
	xor a
	ld [hJoyReleased], a
	ld [hJoyPressed], a
	ld [hJoyDown], a
	ld [hJoyLast], a
	ret

PlayPrinterMusic:
	ld de, MUSIC_PRINTER
	jp PlayMusic2

CheckPrinterError:
	ld a, [wPrinterHandshake]
	inc a
	jr nz, .printer_connected
	ld a, [wPrinterStatusFlags]
	inc a
	jr z, .error_2

.printer_connected
	ld a, [wPrinterStatusFlags]
	and %11100000
	ret z ; no error

	bit 7, a
	jr nz, .error_1
	bit 6, a
	jr nz, .error_4
	ld a, 6 ; error 3
	jr .load_text_index

.error_4
	ld a, 7 ; error 4
	jr .load_text_index

.error_1
	ld a, 4 ; error 1
	jr .load_text_index

.error_2
	ld a, 5 ; error 2

.load_text_index
	ld [wPrinterTextIndex], a
	ret

ShowPrinterStatus:
	ld a, [wPrinterTextIndex]
	and a
	ret z
	push af
	xor a
	ld [hBGMapMode], a
	hlcoord 0, 5
	lb bc, 10, 18
	call TextBox
	pop af
	ld e, a
	ld d, 0
	ld hl, PrinterStatusStringPointers
	add hl, de
	add hl, de
	ld e, [hl]
	inc hl
	ld d, [hl]
	hlcoord 1, 7
	ld a, BANK(GBPrinterStrings)
	call FarText
	hlcoord 2, 15
	ld de, .press_B_to_cancel
	call PlaceText
	ld a, $1
	ld [hBGMapMode], a
	xor a
	ld [wPrinterTextIndex], a
	ret

.press_B_to_cancel
	db TX_COMPRESSED, $e1, $59, $a1, $10, $4a, $58, $63, $6e, $91, $93
	db $ed, $34

PrinterStatusStringPointers:
	dw String_Printer_Blank ; @
	dw String_Printer_CheckingLink
	dw String_Printer_Transmitting
	dw String_Printer_Printing
	dw String_Printer_Error1
	dw String_Printer_Error2
	dw String_Printer_Error3
	dw String_Printer_Error4

Function84817:
	xor a
	ld [wd002], a
	hlcoord 0, 0
	ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
	ld a, " "
	call ByteFill
	call Printer_PlaceEmptyBoxSlotString
	hlcoord 0, 0
	ld bc, 9 * SCREEN_WIDTH
	ld a, " "
	call ByteFill
	call Printer_PlaceSideBorders
	call Printer_PlaceTopBorder
	hlcoord 4, 3
	ld de, .String_PokemonList
	call PlaceText
	ld a, [wd007]
	ld bc, BOX_NAME_LENGTH
	ld hl, wBoxNames
	rst AddNTimes
	ld d, h
	ld e, l
	hlcoord 6, 5
	call PlaceString
	ld a, $1
	call Function849c6
	hlcoord 2, 9
	ld c, $3
	jr Function848e7

.String_PokemonList
	db TX_COMPRESSED, $07, $2b, $e1, $24, $e8, $d1
	db $74, $d0

Function8486f:
	hlcoord 0, 0
	ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
	ld a, " "
	call ByteFill
	call Printer_PlaceEmptyBoxSlotString
	call Printer_PlaceSideBorders
	ld a, [wd003]
	and a
	ret nz
	ld a, $4
	call Function849c6
	hlcoord 2, 0
	ld c, $6
	jr Function848e7

Function84893:
	hlcoord 0, 0
	ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
	ld a, " "
	call ByteFill
	call Printer_PlaceEmptyBoxSlotString
	call Printer_PlaceSideBorders
	ld a, [wd003]
	and a
	ret nz
	ld a, $a
	call Function849c6
	hlcoord 2, 0
	ld c, $6
	jr Function848e7

Function848b7:
	hlcoord 0, 0
	ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
	ld a, " "
	call ByteFill
	call Printer_PlaceEmptyBoxSlotString
	hlcoord 1, 15
	lb bc, 2, 18
	call ClearBox
	call Printer_PlaceSideBorders
	call Printer_PlaceBottomBorders
	ld a, [wd003]
	and a
	ret nz
	ld a, $10
	call Function849c6
	hlcoord 2, 0
	ld c, $5
	; fallthrough

Function848e7:
	ld a, [wd006]
	sbk a
	; fallthrough

Function848ed:
	ld a, c
	and a
	jp z, CloseSRAM
	dec c
	ld a, [de]
	cp $ff
	jp z, .done
	ld [wd265], a
	ld [wCurPartySpecies], a
	push bc
	push hl
	push de
	push hl
	ld bc, $10
	ld a, " "
	call ByteFill
	pop hl
	push hl
	call GetBasePokemonName
	pop hl
	push hl
	call PlaceString
	ld a, [wCurPartySpecies]
	cp EGG
	pop hl
	jr z, .ok2
	ld bc, $b
	add hl, bc
	call Function8498a
	ld bc, $9
	add hl, bc
	ld a, "/"
	ld [hli], a
	push hl
	ld c, $e
	ld a, " "
	call ByteFill
	pop hl
	push hl
	ld a, [wd004]
	ld l, a
	ld a, [wd005]
	ld h, a
	ld bc, sBoxMonNicknames - sBox
	add hl, bc
	ld bc, $b
	ld a, [wd002]
	rst AddNTimes
	ld e, l
	ld d, h
	pop hl
	push hl
	call PlaceString
	pop hl
	ld bc, $b
	add hl, bc
	push hl
	ld a, [wd004]
	ld l, a
	ld a, [wd005]
	ld h, a
	ld c, $35
	add hl, bc
	ld c, $20
	ld a, [wd002]
	rst AddNTimes
	ld a, [hl]
	pop hl
	call PrintFullLevel
.ok2
	ld hl, wd002
	inc [hl]
	pop de
	pop hl
	ld bc, $3c
	add hl, bc
	pop bc
	inc de
	jp Function848ed

.done
	ld a, $1
	ld [wd003], a
	jp CloseSRAM

Function8498a:
	push hl
	ld a, [wd004]
	ld l, a
	ld a, [wd005]
	ld h, a
	ld bc, $2b
	add hl, bc
	ld c, $20
	ld a, [wd002]
	rst AddNTimes
	ld de, wTempMonDVs
	ld a, [hli]
	ld [de], a
	inc de
	ld a, [hli]
	ld [de], a
	ld a, [wd002]
	ld [wCurPartyMon], a
	ld a, $3
	ld [wMonType], a
	callba GetGender
	ld a, $7f
	jr c, .asm_849c3
	ld a, $ef
	jr nz, .asm_849c3
	ld a, $f5
.asm_849c3
	pop hl
	ld [hli], a
	push af
	ld a, [wd006]
	sbk a
	pop af
	ret

Function849c6:
	push hl
	ld e, a
	ld d, $0
	ld a, [wd004]
	ld l, a
	ld a, [wd005]
	ld h, a
	add hl, de
	ld e, l
	ld d, h
	pop hl
	ret

Printer_PlaceTopBorder:
	hlcoord 0, 0
	ld a, "┌"
	ld [hli], a
	ld a, "─"
	ld c, SCREEN_WIDTH - 2
.loop
	ld [hli], a
	dec c
	jr nz, .loop
	ld [hl], "┐"
	ret

Printer_PlaceSideBorders:
	hlcoord 0, 0
	ld de, SCREEN_WIDTH - 1
	ld c, SCREEN_HEIGHT
	ld a, "│"
.loop
	ld [hl], a
	add hl, de
	ld [hli], a
	dec c
	jr nz, .loop
	ret

Printer_PlaceBottomBorders:
	hlcoord 0, 17
	ld a, "└"
	ld [hli], a
	ld a, "─"
	ld c, SCREEN_WIDTH - 2
.loop
	ld [hli], a
	dec c
	jr nz, .loop
	ld [hl], "┘"
	ret

Printer_PlaceEmptyBoxSlotString:
	hlcoord 2, 0
	ld c, $6
.loop
	push bc
	push hl
	ld de, .two_spaces_six_dashes
	call PlaceText
	pop hl
	ld bc, 3 * SCREEN_WIDTH
	add hl, bc
	pop bc
	dec c
	jr nz, .loop
	ret

.two_spaces_six_dashes
	text "  ------"
	done

