First Commit

Upload literally everything from the pokecrystal16 expand-move-ID branch
This commit is contained in:
Zeta_Null 2023-09-10 12:35:35 -04:00
commit 2f8a41f833
4618 changed files with 480386 additions and 0 deletions

View file

@ -0,0 +1,367 @@
DEF PRINTPARTY_HP EQU "◀" ; $71
PrintPage1:
hlcoord 0, 0
decoord 0, 0, wPrinterTilemapBuffer
ld bc, 17 * SCREEN_WIDTH
call CopyBytes
hlcoord 17, 1, wPrinterTilemapBuffer
ld a, $62
ld [hli], a
inc a ; $63
ld [hl], a
hlcoord 17, 2, wPrinterTilemapBuffer
ld a, $64
ld [hli], a
inc a ; $65
ld [hl], a
hlcoord 1, 9, wPrinterTilemapBuffer
ld a, " "
ld [hli], a
ld [hl], a
hlcoord 1, 10, wPrinterTilemapBuffer
ld a, $61
ld [hli], a
ld [hl], a
hlcoord 2, 11, wPrinterTilemapBuffer
lb bc, 5, 18
call ClearBox
ld a, [wTempSpecies]
call CheckCaughtMon
push af
ld a, [wTempSpecies]
ld b, a
ld c, 1 ; get page 1
farcall GetDexEntryPagePointer
pop af
ld a, b
hlcoord 1, 11, wPrinterTilemapBuffer
call nz, PlaceFarString
hlcoord 19, 0, wPrinterTilemapBuffer
ld [hl], $35
ld de, SCREEN_WIDTH
add hl, de
ld b, $f
.column_loop
ld [hl], $37
add hl, de
dec b
jr nz, .column_loop
ld [hl], $3a
ret
PrintPage2:
hlcoord 0, 0, wPrinterTilemapBuffer
ld bc, 8 * SCREEN_WIDTH
ld a, " "
call ByteFill
hlcoord 0, 0, wPrinterTilemapBuffer
ld a, $36
ld b, 6
call .FillColumn
hlcoord 19, 0, wPrinterTilemapBuffer
ld a, $37
ld b, 6
call .FillColumn
hlcoord 0, 6, wPrinterTilemapBuffer
ld [hl], $38
inc hl
ld a, $39
ld bc, SCREEN_HEIGHT
call ByteFill
ld [hl], $3a
hlcoord 0, 7, wPrinterTilemapBuffer
ld bc, SCREEN_WIDTH
ld a, $32
call ByteFill
ld a, [wTempSpecies]
call CheckCaughtMon
push af
ld a, [wTempSpecies]
ld b, a
ld c, 2 ; get page 2
farcall GetDexEntryPagePointer
pop af
hlcoord 1, 1, wPrinterTilemapBuffer
ld a, b
call nz, PlaceFarString
ret
.FillColumn:
push de
ld de, SCREEN_WIDTH
.column_loop
ld [hl], a
add hl, de
dec b
jr nz, .column_loop
pop de
ret
GBPrinterStrings: ; used only for BANK(GBPrinterStrings)
GBPrinterString_Null: db "@"
GBPrinterString_CheckingLink: next " CHECKING LINK...@"
GBPrinterString_Transmitting: next " TRANSMITTING...@"
GBPrinterString_Printing: next " PRINTING...@"
GBPrinterString_PrinterError1:
db " Printer Error 1"
next ""
next "Check the Game Boy"
next "Printer Manual."
db "@"
GBPrinterString_PrinterError2:
db " Printer Error 2"
next ""
next "Check the Game Boy"
next "Printer Manual."
db "@"
GBPrinterString_PrinterError3:
db " Printer Error 3"
next ""
next "Check the Game Boy"
next "Printer Manual."
db "@"
GBPrinterString_PrinterError4:
db " Printer Error 4"
next ""
next "Check the Game Boy"
next "Printer Manual."
db "@"
PrintPartyMonPage1:
call ClearBGPalettes
call ClearTilemap
call ClearSprites
xor a
ldh [hBGMapMode], a
call LoadFontsBattleExtra
ld de, GBPrinterHPIcon
ld hl, vTiles2 tile PRINTPARTY_HP
lb bc, BANK(GBPrinterHPIcon), 1
call Request1bpp
ld de, GBPrinterLvIcon
ld hl, vTiles2 tile "<LV>"
lb bc, BANK(GBPrinterLvIcon), 1
call Request1bpp
ld de, StatsScreenPageTilesGFX + 14 tiles ; shiny icon
ld hl, vTiles2 tile "⁂"
lb bc, BANK(StatsScreenPageTilesGFX), 1
call Get2bpp
xor a
ld [wMonType], a
farcall CopyMonToTempMon
hlcoord 0, 7
ld b, 9
ld c, 18
call Textbox
hlcoord 8, 2
ld a, [wTempMonLevel]
call PrintLevel_Force3Digits
hlcoord 12, 2
ld [hl], PRINTPARTY_HP
inc hl
ld de, wTempMonMaxHP
lb bc, 2, 3
call PrintNum
ld a, [wCurPartySpecies]
ld [wNamedObjectIndex], a
ld [wCurSpecies], a
ld hl, wPartyMonNicknames
call GetCurPartyMonName
hlcoord 8, 4
call PlaceString
hlcoord 9, 6
ld [hl], "/"
call GetPokemonName
hlcoord 10, 6
call PlaceString
hlcoord 8, 0
ld [hl], "№"
inc hl
ld [hl], "."
inc hl
ld de, wNamedObjectIndex
lb bc, PRINTNUM_LEADINGZEROS | 1, 3
call PrintNum
hlcoord 1, 9
ld de, PrintParty_OTString
call PlaceString
ld hl, wPartyMonOTs
call GetCurPartyMonName
hlcoord 4, 9
call PlaceString
hlcoord 1, 11
ld de, PrintParty_IDNoString
call PlaceString
hlcoord 4, 11
ld de, wTempMonID
lb bc, PRINTNUM_LEADINGZEROS | 2, 5
call PrintNum
hlcoord 1, 14
ld de, PrintParty_MoveString
call PlaceString
hlcoord 7, 14
ld a, [wTempMonMoves + 0]
call PlaceMoveNameString
call PlaceGenderAndShininess
ld hl, wTempMonDVs
predef GetUnownLetter
ld hl, wBoxAlignment
xor a
ld [hl], a
ld a, [wCurPartySpecies]
push hl
call GetPokemonIndexFromID
ld a, l
sub LOW(UNOWN)
if HIGH(UNOWN) == 0
or h
pop hl
else
ld a, h
pop hl
jr nz, .not_unown
if HIGH(UNOWN) == 1
dec a
else
cp HIGH(UNOWN)
endc
endc
jr z, .got_alignment
.not_unown
inc [hl]
.got_alignment
hlcoord 0, 0
call _PrepMonFrontpic
call WaitBGMap
ld b, SCGB_STATS_SCREEN_HP_PALS
call GetSGBLayout
call SetPalettes
ret
PrintPartyMonPage2:
call ClearBGPalettes
call ClearTilemap
call ClearSprites
xor a
ldh [hBGMapMode], a
call LoadFontsBattleExtra
xor a
ld [wMonType], a
farcall CopyMonToTempMon
hlcoord 0, 0
ld b, 15
ld c, 18
call Textbox
ld bc, SCREEN_WIDTH
decoord 0, 0
hlcoord 0, 1
call CopyBytes
hlcoord 7, 0
ld a, [wTempMonMoves + 1]
call PlaceMoveNameString
hlcoord 7, 2
ld a, [wTempMonMoves + 2]
call PlaceMoveNameString
hlcoord 7, 4
ld a, [wTempMonMoves + 3]
call PlaceMoveNameString
hlcoord 7, 7
ld de, PrintParty_StatsString
call PlaceString
hlcoord 16, 7
ld de, wTempMonAttack
call .PrintTempMonStats
hlcoord 16, 9
ld de, wTempMonDefense
call .PrintTempMonStats
hlcoord 16, 11
ld de, wTempMonSpclAtk
call .PrintTempMonStats
hlcoord 16, 13
ld de, wTempMonSpclDef
call .PrintTempMonStats
hlcoord 16, 15
ld de, wTempMonSpeed
call .PrintTempMonStats
call WaitBGMap
ld b, SCGB_STATS_SCREEN_HP_PALS
call GetSGBLayout
call SetPalettes
ret
.PrintTempMonStats:
lb bc, 2, 3
call PrintNum
ret
GetCurPartyMonName:
ld bc, NAME_LENGTH
ld a, [wCurPartyMon]
call AddNTimes
ld e, l
ld d, h
ret
PlaceMoveNameString:
and a
jr z, .no_move
ld [wNamedObjectIndex], a
call GetMoveName
jr .got_string
.no_move
ld de, PrintParty_NoMoveString
.got_string
call PlaceString
ret
PlaceGenderAndShininess:
farcall GetGender
ld a, " "
jr c, .got_gender
ld a, "♂"
jr nz, .got_gender
ld a, "♀"
.got_gender
hlcoord 17, 2
ld [hl], a
ld bc, wTempMonDVs
farcall CheckShininess
ret nc
hlcoord 18, 2
ld [hl], "⁂"
ret
PrintParty_OTString:
db "OT/@"
PrintParty_MoveString:
db "MOVE@"
PrintParty_IDNoString:
db "<ID>№.@"
PrintParty_StatsString:
db "ATTACK"
next "DEFENSE"
next "SPCL.ATK"
next "SPCL.DEF"
next "SPEED"
db "@"
PrintParty_NoMoveString:
db "------------@"
GBPrinterHPIcon:
INCBIN "gfx/printer/hp.1bpp"
GBPrinterLvIcon:
INCBIN "gfx/printer/lv.1bpp"

968
engine/printer/printer.asm Normal file
View file

@ -0,0 +1,968 @@
SendScreenToPrinter:
.loop
call JoyTextDelay
call CheckCancelPrint
jr c, .cancel
ld a, [wJumptableIndex]
bit 7, a
jr nz, .finished
call PrinterJumptableIteration
call CheckPrinterStatus
call PlacePrinterStatusString
call DelayFrame
jr .loop
.finished
and a
ret
.cancel
scf
ret
Printer_CleanUpAfterSend:
xor a
ld [wPrinterConnectionOpen], a
ld [wPrinterOpcode], a
ret
Printer_PrepareTilemapForPrint:
push af
call Printer_StartTransmission
pop af
ld [wPrinterMargins], a
call Printer_CopyTilemapToBuffer
ret
Printer_ExitPrinter:
call ReturnToMapFromSubmenu
call Printer_RestartMapMusic
ret
PrintDexEntry:
ld a, [wPrinterQueueLength]
push af
ld hl, vTiles1
ld de, FontInversed
lb bc, BANK(FontInversed), $80
call Request1bpp
xor a
ldh [hPrinter], a
call Printer_PlayMusic
ldh a, [rIE]
push af
xor a
ldh [rIF], a
ld a, (1 << SERIAL) | (1 << VBLANK)
ldh [rIE], a
call Printer_StartTransmission
ln a, 1, 0
ld [wPrinterMargins], a
farcall PrintPage1
call ClearTilemap
ld a, %11100100
call DmgToCgbBGPals
call DelayFrame
ld hl, hVBlank
ld a, [hl]
push af
ld [hl], 4 ; vblank mode that calls AskSerial
ld a, 8 ; 16 rows
ld [wPrinterQueueLength], a
call Printer_ResetJoypadRegisters
call SendScreenToPrinter
jr c, .skip_second_page ; canceled or got an error
call Printer_CleanUpAfterSend
ld c, 12
call DelayFrames
xor a
ldh [hBGMapMode], a
call Printer_StartTransmission
ln a, 0, 3
ld [wPrinterMargins], a
farcall PrintPage2
call Printer_ResetJoypadRegisters
ld a, 4
ld [wPrinterQueueLength], a
call SendScreenToPrinter
.skip_second_page
pop af
ldh [hVBlank], a
call Printer_CleanUpAfterSend
xor a
ldh [rIF], a
pop af
ldh [rIE], a
call Printer_ExitPrinter
ld c, 8
.low_volume_delay_frames
call LowVolume
call DelayFrame
dec c
jr nz, .low_volume_delay_frames
pop af
ld [wPrinterQueueLength], a
ret
PrintPCBox:
ld a, [wPrinterQueueLength]
push af
ld a, 18 / 2
ld [wPrinterQueueLength], a
ld a, e
ld [wAddrOfBoxToPrint], a
ld a, d
ld [wAddrOfBoxToPrint + 1], a
ld a, b
ld [wBankOfBoxToPrint], a
ld a, c
ld [wWhichBoxToPrint], a
xor a
ldh [hPrinter], a
ld [wFinishedPrintingBox], a
call Printer_PlayMusic
ldh a, [rIE]
push af
xor a
ldh [rIF], a
ld a, (1 << SERIAL) | (1 << VBLANK)
ldh [rIE], a
ld hl, hVBlank
ld a, [hl]
push af
ld [hl], 4 ; vblank mode that calls AskSerial
xor a
ldh [hBGMapMode], a
call PrintPCBox_Page1
ln a, 1, 0 ; to be loaded to wPrinterMargins
call Printer_PrepareTilemapForPrint
call Printer_ResetRegistersAndStartDataSend
jr c, .cancel
call Printer_CleanUpAfterSend
ld c, 12
call DelayFrames
xor a
ldh [hBGMapMode], a
call PrintPCBox_Page2
ln a, 0, 0 ; to be loaded to wPrinterMargins
call Printer_PrepareTilemapForPrint
call Printer_ResetRegistersAndStartDataSend
jr c, .cancel
call Printer_CleanUpAfterSend
ld c, 12
call DelayFrames
xor a
ldh [hBGMapMode], a
call PrintPCBox_Page3
ln a, 0, 0 ; to be loaded to wPrinterMargins
call Printer_PrepareTilemapForPrint
call Printer_ResetRegistersAndStartDataSend
jr c, .cancel
call Printer_CleanUpAfterSend
ld c, 12
call DelayFrames
xor a
ldh [hBGMapMode], a
call PrintPCBox_Page4
ln a, 0, 3 ; to be loaded to wPrinterMargins
call Printer_PrepareTilemapForPrint
call Printer_ResetRegistersAndStartDataSend
.cancel
pop af
ldh [hVBlank], a
call Printer_CleanUpAfterSend
xor a
ldh [rIF], a
pop af
ldh [rIE], a
call Printer_ExitPrinter
pop af
ld [wPrinterQueueLength], a
ret
Printer_ResetRegistersAndStartDataSend:
call Printer_ResetJoypadRegisters
call SendScreenToPrinter
ret
PrintUnownStamp:
ld a, [wPrinterQueueLength]
push af
xor a
ldh [hPrinter], a
call Printer_PlayMusic
ldh a, [rIE]
push af
xor a
ldh [rIF], a
ld a, (1 << SERIAL) | (1 << VBLANK)
ldh [rIE], a
ld hl, hVBlank
ld a, [hl]
push af
ld [hl], 4 ; vblank mode that calls AskSerial
xor a
ldh [hBGMapMode], a
call LoadTilemapToTempTilemap
farcall PlaceUnownPrinterFrontpic
ln a, 0, 0 ; to be loaded to wPrinterMargins
call Printer_PrepareTilemapForPrint
call SafeLoadTempTilemapToTilemap
call Printer_ResetJoypadRegisters
ld a, 18 / 2
ld [wPrinterQueueLength], a
.loop
call JoyTextDelay
call CheckCancelPrint
jr c, .done
ld a, [wJumptableIndex]
bit 7, a
jr nz, .done
call PrinterJumptableIteration
ld a, [wJumptableIndex]
cp $2
jr nc, .check_status
ld a, 6 / 2
ld [wPrinterRowIndex], a
.check_status
call CheckPrinterStatus
call PlacePrinterStatusString
call DelayFrame
jr .loop
.done
pop af
ldh [hVBlank], a
call Printer_CleanUpAfterSend
call SafeLoadTempTilemapToTilemap
xor a
ldh [rIF], a
pop af
ldh [rIE], a
pop af
ld [wPrinterQueueLength], a
ret
PrintMailAndExit:
call PrintMail
call Printer_ExitPrinter
ret
PrintMail:
ld a, [wPrinterQueueLength]
push af
xor a
ldh [hPrinter], a
call Printer_PlayMusic
ldh a, [rIE]
push af
xor a
ldh [rIF], a
ld a, (1 << SERIAL) | (1 << VBLANK)
ldh [rIE], a
xor a
ldh [hBGMapMode], a
ln a, 1, 3 ; to be loaded to wPrinterMargins
call Printer_PrepareTilemapForPrint
ld hl, hVBlank
ld a, [hl]
push af
ld [hl], 4 ; vblank mode that calls AskSerial
ld a, 18 / 2
ld [wPrinterQueueLength], a
call SendScreenToPrinter
pop af
ldh [hVBlank], a
call Printer_CleanUpAfterSend
call Printer_CopyBufferToTilemap
xor a
ldh [rIF], a
pop af
ldh [rIE], a
pop af
ld [wPrinterQueueLength], a
ret
PrintPartymon:
ld a, [wPrinterQueueLength]
push af
xor a
ldh [hPrinter], a
call Printer_PlayMusic
ldh a, [rIE]
push af
xor a
ldh [rIF], a
ld a, (1 << SERIAL) | (1 << VBLANK)
ldh [rIE], a
xor a
ldh [hBGMapMode], a
farcall PrintPartyMonPage1
ln a, 1, 0 ; to be loaded to wPrinterMargins
call Printer_PrepareTilemapForPrint
ld hl, hVBlank
ld a, [hl]
push af
ld [hl], 4 ; vblank mode that calls AskSerial
ld a, 16 / 2
ld [wPrinterQueueLength], a
call Printer_ResetJoypadRegisters
call SendScreenToPrinter
jr c, .cancel
call Printer_CleanUpAfterSend
ld c, 12
call DelayFrames
xor a
ldh [hBGMapMode], a
farcall PrintPartyMonPage2
ln a, 0, 3 ; to be loaded to wPrinterMargins
call Printer_PrepareTilemapForPrint
ld a, 18 / 2
ld [wPrinterQueueLength], a
call Printer_ResetJoypadRegisters
call SendScreenToPrinter
.cancel
pop af
ldh [hVBlank], a
call Printer_CleanUpAfterSend
call Printer_CopyBufferToTilemap
xor a
ldh [rIF], a
pop af
ldh [rIE], a
call Printer_ExitPrinter
pop af
ld [wPrinterQueueLength], a
ret
_PrintDiploma:
ld a, [wPrinterQueueLength]
push af
farcall PlaceDiplomaOnScreen
xor a
ldh [hPrinter], a
call Printer_PlayMusic
ldh a, [rIE]
push af
xor a
ldh [rIF], a
ld a, (1 << SERIAL) | (1 << VBLANK)
ldh [rIE], a
ld hl, hVBlank
ld a, [hl]
push af
ld [hl], 4 ; vblank mode that calls AskSerial
ln a, 1, 0 ; to be loaded to wPrinterMargins
call Printer_PrepareTilemapForPrint
call Printer_ResetJoypadRegisters
ld a, 18 / 2
ld [wPrinterQueueLength], a
call SendScreenToPrinter
jr c, .cancel
call Printer_CleanUpAfterSend
ld c, 12
call DelayFrames
call LoadTilemapToTempTilemap
xor a
ldh [hBGMapMode], a
farcall PrintDiplomaPage2
ln a, 0, 3 ; to be loaded to wPrinterMargins
call Printer_PrepareTilemapForPrint
call SafeLoadTempTilemapToTilemap
call Printer_ResetJoypadRegisters
ld a, 18 / 2
ld [wPrinterQueueLength], a
call SendScreenToPrinter
.cancel
pop af
ldh [hVBlank], a
call Printer_CleanUpAfterSend
xor a
ldh [rIF], a
pop af
ldh [rIE], a
call Printer_ExitPrinter
pop af
ld [wPrinterQueueLength], a
ret
CheckCancelPrint:
ldh a, [hJoyDown]
and B_BUTTON
jr nz, .pressed_b
and a
ret
.pressed_b
ld a, [wUnusedGameboyPrinterSafeCancelFlag]
cp $0c
jr nz, .cancel
; wait for printer activity to finish before canceling?
.loop
ld a, [wPrinterOpcode]
and a
jr nz, .loop
ld a, $16 ; cancel
ld [wPrinterOpcode], a
ld a, $88
ldh [rSB], a
ld a, (0 << rSC_ON) | (1 << rSC_CLOCK)
ldh [rSC], a
ld a, (1 << rSC_ON) | (1 << rSC_CLOCK)
ldh [rSC], a
.loop2
ld a, [wPrinterOpcode]
and a
jr nz, .loop2
.cancel
ld a, $1
ldh [hPrinter], a
scf
ret
Printer_CopyTilemapToBuffer:
hlcoord 0, 0
ld de, wPrinterTilemapBuffer
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
call CopyBytes
ret
Printer_CopyBufferToTilemap:
ld hl, wPrinterTilemapBuffer
decoord 0, 0
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
call CopyBytes
ret
Printer_ResetJoypadRegisters:
xor a
ldh [hJoyReleased], a
ldh [hJoyPressed], a
ldh [hJoyDown], a
ldh [hJoyLast], a
ret
Printer_PlayMusic:
ld de, MUSIC_PRINTER
call PlayMusic2
ret
Printer_RestartMapMusic:
call RestartMapMusic
ret
CheckPrinterStatus:
; Check for printer errors
; If [wPrinterHandshake] == -1, we're disconnected
ld a, [wPrinterHandshake]
cp -1
jr nz, .printer_connected
ld a, [wPrinterStatusFlags]
cp -1
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
; paper error
ld a, PRINTER_ERROR_3
jr .load_text_index
.error_4
; temperature error
ld a, PRINTER_ERROR_4
jr .load_text_index
.error_1
; printer battery low
ld a, PRINTER_ERROR_1
jr .load_text_index
.error_2
; connection error
ld a, PRINTER_ERROR_2
.load_text_index
ld [wPrinterStatus], a
ret
PlacePrinterStatusString:
; Print nonzero printer status
ld a, [wPrinterStatus]
and a
ret z
push af
xor a
ldh [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 PlaceFarString
hlcoord 2, 15
ld de, String_PressBToCancel
call PlaceString
ld a, $1
ldh [hBGMapMode], a
xor a
ld [wPrinterStatus], a
ret
PlacePrinterStatusStringBorderless: ; unreferenced
; Similar to PlacePrinterStatusString, but with different hlcoords
; and ClearBox instead of TextBox.
ld a, [wPrinterStatus]
and a
ret z
push af
xor a
ldh [hBGMapMode], a
hlcoord 2, 4
lb bc, 13, 16
call ClearBox
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 4, 7
ld a, BANK(GBPrinterStrings)
call PlaceFarString
hlcoord 4, 15
ld de, String_PressBToCancel
call PlaceString
ld a, $1
ldh [hBGMapMode], a
xor a
ld [wPrinterStatus], a
ret
String_PressBToCancel:
db "Press B to Cancel@"
PrinterStatusStringPointers:
dw GBPrinterString_Null ; @
dw GBPrinterString_CheckingLink ; CHECKING LINK
dw GBPrinterString_Transmitting ; TRANSMITTING
dw GBPrinterString_Printing ; PRINTING
dw GBPrinterString_PrinterError1 ; error 1
dw GBPrinterString_PrinterError2 ; error 2
dw GBPrinterString_PrinterError3 ; error 3
dw GBPrinterString_PrinterError4 ; error 4
PrintPCBox_Page1:
xor a
ld [wWhichBoxMonToPrint], 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 PlaceString
ld a, [wWhichBoxToPrint]
ld bc, BOX_NAME_LENGTH
ld hl, wBoxNames
call AddNTimes
ld d, h
ld e, l
hlcoord 6, 5
call PlaceString
ld a, 1
call Printer_GetBoxMonSpecies
hlcoord 2, 9
ld c, 3
call Printer_PrintBoxListSegment
ret
.String_PokemonList:
db "#MON LIST@"
PrintPCBox_Page2:
hlcoord 0, 0
ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
ld a, " "
call ByteFill
call Printer_PlaceEmptyBoxSlotString
call Printer_PlaceSideBorders
ld a, [wFinishedPrintingBox]
and a
ret nz
ld a, 4
call Printer_GetBoxMonSpecies
hlcoord 2, 0
ld c, 6
call Printer_PrintBoxListSegment
ret
PrintPCBox_Page3:
hlcoord 0, 0
ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
ld a, " "
call ByteFill
call Printer_PlaceEmptyBoxSlotString
call Printer_PlaceSideBorders
ld a, [wFinishedPrintingBox]
and a
ret nz
ld a, 10
call Printer_GetBoxMonSpecies
hlcoord 2, 0
ld c, 6
call Printer_PrintBoxListSegment
ret
PrintPCBox_Page4:
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, [wFinishedPrintingBox]
and a
ret nz
ld a, 16
call Printer_GetBoxMonSpecies
hlcoord 2, 0
ld c, 5
call Printer_PrintBoxListSegment
ret
Printer_PrintBoxListSegment:
ld a, [wBankOfBoxToPrint]
call OpenSRAM
.loop
ld a, c
and a
jp z, .max_length
dec c
ld a, [de]
cp $ff
jp z, .finish
cp EGG
call nz, Printer_GetTrueBoxSpeciesIndex
ld [wNamedObjectIndex], a
ld [wCurPartySpecies], a
push bc
push hl
push de
push hl
ld bc, 16
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, MON_NAME_LENGTH
add hl, bc
call Printer_GetMonGender
ld bc, SCREEN_WIDTH - MON_NAME_LENGTH
add hl, bc
ld a, "/"
ld [hli], a
push hl
ld bc, 14
ld a, " "
call ByteFill
pop hl
push hl
ld a, [wAddrOfBoxToPrint]
ld l, a
ld a, [wAddrOfBoxToPrint + 1]
ld h, a
ld bc, sBoxMonNicknames - sBox
add hl, bc
ld bc, MON_NAME_LENGTH
ld a, [wWhichBoxMonToPrint]
call AddNTimes
ld e, l
ld d, h
pop hl
push hl
call PlaceString
pop hl
ld bc, MON_NAME_LENGTH
add hl, bc
push hl
ld a, [wAddrOfBoxToPrint]
ld l, a
ld a, [wAddrOfBoxToPrint + 1]
ld h, a
ld bc, 2 + MONS_PER_BOX + MON_LEVEL
add hl, bc
ld bc, BOXMON_STRUCT_LENGTH
ld a, [wWhichBoxMonToPrint]
call AddNTimes
ld a, [hl]
pop hl
call PrintLevel_Force3Digits
.ok2
ld hl, wWhichBoxMonToPrint
inc [hl]
pop de
pop hl
ld bc, 3 * SCREEN_WIDTH
add hl, bc
pop bc
inc de
jp .loop
.finish
ld a, $1
ld [wFinishedPrintingBox], a
.max_length
call CloseSRAM
ret
Printer_GetMonGender:
push hl
ld a, [wAddrOfBoxToPrint]
ld l, a
ld a, [wAddrOfBoxToPrint + 1]
ld h, a
ld bc, 2 + MONS_PER_BOX + MON_DVS
add hl, bc
ld bc, BOXMON_STRUCT_LENGTH
ld a, [wWhichBoxMonToPrint]
call AddNTimes
ld de, wTempMonDVs
ld a, [hli]
ld [de], a
inc de
ld a, [hli]
ld [de], a
ld a, [wWhichBoxMonToPrint]
ld [wCurPartyMon], a
ld a, TEMPMON
ld [wMonType], a
farcall GetGender
ld a, " "
jr c, .got_gender
ld a, "♂"
jr nz, .got_gender
ld a, "♀"
.got_gender
pop hl
ld [hli], a
ret
Printer_GetBoxMonSpecies:
push hl
ld e, a
ld d, 0
ld a, [wAddrOfBoxToPrint]
ld l, a
ld a, [wAddrOfBoxToPrint + 1]
ld h, a
add hl, de
ld e, l
ld d, h
pop hl
ret
Printer_GetTrueBoxSpeciesIndex:
push hl
push af
ld a, [wWhichBoxToPrint]
ld hl, wCurBox
cp [hl]
pop hl
ld l, a
ld a, h
jr z, .done
push bc
ld c, l
ld a, [wAddrOfBoxToPrint]
cpl
add a, e
ld b, a
farcall GetBoxMonPokemonIndexPointer
ldh a, [hSRAMBank]
ld c, a
ld a, b
call OpenSRAM
ld a, [hli]
ld h, [hl]
ld l, a
call GetPokemonIDFromIndex
ld b, a
ld a, c
call OpenSRAM
ld a, b
pop bc
.done
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 a, "┐"
ld [hl], a
ret
Printer_PlaceSideBorders:
hlcoord 0, 0
ld de, SCREEN_WIDTH - 1
ld c, SCREEN_HEIGHT
.loop
ld a, "│"
ld [hl], a
add hl, de
ld a, "│"
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 a, "┘"
ld [hl], a
ret
Printer_PlaceEmptyBoxSlotString:
hlcoord 2, 0
ld c, 6
.loop
push bc
push hl
ld de, .EmptyBoxSlotString
call PlaceString
pop hl
ld bc, 3 * SCREEN_WIDTH
add hl, bc
pop bc
dec c
jr nz, .loop
ret
.EmptyBoxSlotString:
db " ------@"

View file

@ -0,0 +1,628 @@
Printer_StartTransmission:
ld hl, wGameboyPrinterRAM
ld bc, wGameboyPrinterRAMEnd - wGameboyPrinterRAM
xor a
call Printer_ByteFill
xor a
ldh [rSB], a
ldh [rSC], a
ld [wPrinterOpcode], a
ld hl, wPrinterConnectionOpen
set 0, [hl]
ld a, [wGBPrinterBrightness]
ld [wPrinterExposureTime], a
xor a
ld [wJumptableIndex], a
ret
PrinterJumptableIteration:
jumptable .Jumptable, wJumptableIndex
.Jumptable:
dw Print_InitPrinterHandshake ; 00
dw Printer_CheckConnectionStatus ; 01
dw Printer_WaitSerial ; 02
dw Printer_StartTransmittingTilemap ; 03
dw Printer_TransmissionLoop ; 04
dw Printer_WaitSerialAndLoopBack2 ; 05
dw Printer_EndTilemapTransmission ; 06
dw Printer_TransmissionLoop ; 07
dw Printer_WaitSerial ; 08
dw Printer_SignalSendHeader ; 09
dw Printer_TransmissionLoop ; 0a
dw Printer_WaitSerial ; 0b
dw Printer_WaitUntilFinished ; 0c
dw Printer_Quit ; 0d
dw Printer_NextSection ; 0e
dw Printer_WaitSerial ; 0f
dw Printer_SignalLoopBack ; 10
dw Printer_SectionOne ; 11
dw Printer_NextSectionWaitLoopBack ; 12
dw Printer_WaitLoopBack ; 13
_Printer_NextSection:
ld hl, wJumptableIndex
inc [hl]
ret
Printer_PrevSection:
ld hl, wJumptableIndex
dec [hl]
ret
Printer_Quit:
xor a
ld [wPrinterStatusFlags], a
ld hl, wJumptableIndex
set 7, [hl]
ret
Printer_NextSection:
call _Printer_NextSection
ret
Printer_SectionOne:
ld a, $1
ld [wJumptableIndex], a
ret
Print_InitPrinterHandshake:
call Printer_ResetData
ld hl, PrinterDataPacket1
call Printer_CopyPacket
xor a
ld [wPrinterSendByteCounter], a
ld [wPrinterSendByteCounter + 1], a
ld a, [wPrinterQueueLength]
ld [wPrinterRowIndex], a
call _Printer_NextSection
call Printer_WaitHandshake
ld a, PRINTER_STATUS_CHECKING
ld [wPrinterStatus], a
ret
Printer_StartTransmittingTilemap:
call Printer_ResetData
; check remaining tile data
ld hl, wPrinterRowIndex
ld a, [hl]
and a
jr z, Printer_EndTilemapTransmission
; send packet 3
ld hl, PrinterDataPacket3 ; signal start of transmission
call Printer_CopyPacket
; prepare to send 40 tiles
call Printer_Convert2RowsTo2bpp
ld a, LOW(40 tiles)
ld [wPrinterSendByteCounter], a
ld a, HIGH(40 tiles)
ld [wPrinterSendByteCounter + 1], a
; compute the checksum
call Printer_ComputeChecksum
call _Printer_NextSection
call Printer_WaitHandshake
ld a, PRINTER_STATUS_TRANSMITTING
ld [wPrinterStatus], a
ret
Printer_EndTilemapTransmission:
; ensure that we go from here to routine 7
ld a, $6
ld [wJumptableIndex], a
; send packet 4
ld hl, PrinterDataPacket4 ; signal no transmission
call Printer_CopyPacket
; send no tile data
xor a
ld [wPrinterSendByteCounter], a
ld [wPrinterSendByteCounter + 1], a
call _Printer_NextSection
call Printer_WaitHandshake
ret
Printer_SignalSendHeader:
call Printer_ResetData
ld hl, PrinterDataPacket2 ; signal request print
call Printer_CopyPacket
; prepare to send 1 tile
call Printer_StageHeaderForSend
ld a, LOW(4)
ld [wPrinterSendByteCounter], a
ld a, HIGH(4)
ld [wPrinterSendByteCounter + 1], a
; compute the checksum
call Printer_ComputeChecksum
call _Printer_NextSection
call Printer_WaitHandshake
ld a, PRINTER_STATUS_PRINTING
ld [wPrinterStatus], a
ret
Printer_SignalLoopBack:
call Printer_ResetData
; send packet 1
ld hl, PrinterDataPacket1 ; signal no transmission
call Printer_CopyPacket
; send no tile data
xor a
ld [wPrinterSendByteCounter], a
ld [wPrinterSendByteCounter + 1], a
ld a, [wPrinterQueueLength]
ld [wPrinterRowIndex], a
call _Printer_NextSection
call Printer_WaitHandshake
ret
Printer_WaitSerial:
ld hl, wPrinterSerialFrameDelay
inc [hl]
ld a, [hl]
cp $6
ret c
xor a
ld [hl], a
call _Printer_NextSection
ret
Printer_WaitSerialAndLoopBack2:
ld hl, wPrinterSerialFrameDelay
inc [hl]
ld a, [hl]
cp $6
ret c
xor a
ld [hl], a
ld hl, wPrinterRowIndex
dec [hl]
call Printer_PrevSection
call Printer_PrevSection
ret
Printer_CheckConnectionStatus:
ld a, [wPrinterOpcode]
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]
cp $0
jr nz, .printer_error
ld hl, wPrinterConnectionOpen
set 1, [hl]
ld a, $5
ld [wHandshakeFrameDelay], a
call _Printer_NextSection
ret
.printer_error
ld a, $ff
ld [wPrinterHandshake], a
ld [wPrinterStatusFlags], a
ld a, $e
ld [wJumptableIndex], a
ret
Printer_TransmissionLoop:
ld a, [wPrinterOpcode]
and a
ret nz
ld a, [wPrinterStatusFlags]
and $f0
jr nz, .enter_wait_loop
ld a, [wPrinterStatusFlags]
and $1
jr nz, .cycle_back
call _Printer_NextSection
ret
.cycle_back
call Printer_PrevSection
ret
.enter_wait_loop
ld a, $12 ; Printer_NextSectionWaitLoopBack
ld [wJumptableIndex], a
ret
Printer_WaitUntilFinished:
ld a, [wPrinterOpcode]
and a
ret nz
ld a, [wPrinterStatusFlags]
and $f3
ret nz
call _Printer_NextSection
ret
Printer_NextSectionWaitLoopBack:
call _Printer_NextSection
Printer_WaitLoopBack:
ld a, [wPrinterOpcode]
and a
ret nz
ld a, [wPrinterStatusFlags]
and $f0
ret nz
xor a
ld [wJumptableIndex], a
ret
Printer_WaitHandshake:
.loop
ld a, [wPrinterOpcode]
and a
jr nz, .loop
xor a
ld [wPrinterSendByteOffset], a
ld [wPrinterSendByteOffset + 1], a
ld a, $1
ld [wPrinterOpcode], a
ld a, $88
ldh [rSB], a
ld a, (0 << rSC_ON) | (1 << rSC_CLOCK)
ldh [rSC], a
ld a, (1 << rSC_ON) | (1 << rSC_CLOCK)
ldh [rSC], a
ret
Printer_CopyPacket:
ld a, [hli]
ld [wPrinterData], a
ld a, [hli]
ld [wPrinterData + 1], a
ld a, [hli]
ld [wPrinterData + 2], a
ld a, [hli]
ld [wPrinterData + 3], a
ld a, [hli]
ld [wPrinterChecksum], a
ld a, [hl]
ld [wPrinterChecksum + 1], a
ret
Printer_ResetData:
xor a
ld hl, wPrinterData
ld [hli], a
ld [hli], a
ld [hli], a
ld [hl], a
ld hl, wPrinterChecksum
ld [hli], a
ld [hl], a
xor a
ld [wPrinterSendByteCounter], a
ld [wPrinterSendByteCounter + 1], a
ld hl, wGameboyPrinter2bppSource
ld bc, wGameboyPrinter2bppSourceEnd - wGameboyPrinter2bppSource
call Printer_ByteFill
ret
Printer_ComputeChecksum:
ld hl, 0
ld bc, 4
ld de, wPrinterData
call .ComputeChecksum
ld a, [wPrinterSendByteCounter]
ld c, a
ld a, [wPrinterSendByteCounter + 1]
ld b, a
ld de, wGameboyPrinterRAM
call .ComputeChecksum
ld a, l
ld [wPrinterChecksum], a
ld a, h
ld [wPrinterChecksum + 1], a
ret
.ComputeChecksum:
.loop
ld a, [de]
inc de
add l
jr nc, .no_overflow
inc h
.no_overflow
ld l, a
dec bc
ld a, c
or b
jr nz, .loop
ret
Printer_StageHeaderForSend:
ld a, $1
ld [wGameboyPrinter2bppSource + 0], a
ld a, [wPrinterMargins]
ld [wGameboyPrinter2bppSource + 1], a
ld a, %11100100 ; 3,2,1,0
ld [wGameboyPrinter2bppSource + 2], a
ld a, [wPrinterExposureTime]
ld [wGameboyPrinter2bppSource + 3], a
ret
Printer_Convert2RowsTo2bpp:
; de = wPrinterTilemapBuffer + 2 * SCREEN_WIDTH * ([wPrinterQueueLength] - [wPrinterRowIndex])
ld a, [wPrinterRowIndex]
xor $ff
ld d, a
ld a, [wPrinterQueueLength]
inc a
add d
ld hl, wPrinterTilemapBuffer
ld de, 2 * SCREEN_WIDTH
.loop1
and a
jr z, .okay1
add hl, de
dec a
jr .loop1
.okay1
ld e, l
ld d, h
ld hl, wGameboyPrinter2bppSource
ld c, 2 * SCREEN_WIDTH
.loop2
ld a, [de]
inc de
push bc
push de
push hl
; convert tile index to vram address
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, .vtiles_8xxx
or $90
jr .got_vtile_addr
.vtiles_8xxx
or $80
.got_vtile_addr
ld d, a
; copy 1 vtile to hl
lb bc, BANK(Printer_Convert2RowsTo2bpp), 1
call Request2bpp
pop hl
ld de, 1 tiles
add hl, de
pop de
pop bc
dec c
jr nz, .loop2
ret
Printer_ByteFill:
push de
ld e, a
.loop
ld [hl], e
inc hl
dec bc
ld a, c
or b
jr nz, .loop
ld a, e
pop de
ret
PrinterDataPacket1:
db 1, 0, $00, 0
dw 1
PrinterDataPacket2:
db 2, 0, $04, 0
dw 0
PrinterDataPacket3:
db 4, 0, $80, 2
dw 0
PrinterDataPacket4:
db 4, 0, $00, 0
dw 4
PrinterDataPacket5: ; unreferenced
db 8, 0, $00, 0
dw 8
PrinterDataPacket6: ; unreferenced
db 15, 0, $00, 0
dw 15
_PrinterReceive::
ld a, [wPrinterOpcode]
add a
ld e, a
ld d, 0
ld hl, .Jumptable
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.Jumptable:
dw Printer_DoNothing ; 00
dw Printer_Send0x33 ; 01
dw Printer_SendPrinterData1 ; 02
dw Printer_SendPrinterData2 ; 03
dw Printer_SendPrinterData3 ; 04
dw Printer_SendPrinterData4 ; 05
dw Printer_SendNextByte ; 06
dw Printer_SendwPrinterChecksumLo ; 07
dw Printer_SendwPrinterChecksumHi ; 08
dw Printer_Send0x00_2 ; 09
dw Printer_ReceiveTwoPrinterHandshakeAndSend0x00 ; 0a
dw Printer_ReceiveTwoPrinterStatusFlagsAndExitSendLoop ; 0b
dw Printer_Send0x33 ; 0c triggered by AskSerial
dw Printer_Send0x0f ; 0d
dw Printer_Send0x00 ; 0e
dw Printer_Send0x00 ; 0f
dw Printer_Send0x00 ; 10
dw Printer_Send0x0f ; 11
dw Printer_Send0x00 ; 12
dw Printer_Send0x00_2 ; 13
dw Printer_ReceiveTwoPrinterHandshakeAndSend0x00 ; 14
dw Printer_ReceiveTwoPrinterStatusFlagsAndExitSendLoop_2 ; 15
dw Printer_Send0x33 ; 16 triggered by pressing B
dw Printer_Send0x08 ; 17
dw Printer_Send0x00 ; 18
dw Printer_Send0x00 ; 19
dw Printer_Send0x00 ; 1a
dw Printer_Send0x08 ; 1b
dw Printer_Send0x00 ; 1c
dw Printer_Send0x00_2 ; 1d
dw Printer_ReceiveTwoPrinterHandshakeAndSend0x00 ; 1e
dw Printer_ReceiveTwoPrinterStatusFlagsAndExitSendLoop ; 1f
Printer_NextInstruction:
ld hl, wPrinterOpcode
inc [hl]
ret
Printer_DoNothing:
ret
Printer_Send0x33:
ld a, $33
call Printer_SerialSend
call Printer_NextInstruction
ret
Printer_SendPrinterData1:
ld a, [wPrinterData]
call Printer_SerialSend
call Printer_NextInstruction
ret
Printer_SendPrinterData2:
ld a, [wPrinterData + 1]
call Printer_SerialSend
call Printer_NextInstruction
ret
Printer_SendPrinterData3:
ld a, [wPrinterData + 2]
call Printer_SerialSend
call Printer_NextInstruction
ret
Printer_SendPrinterData4:
ld a, [wPrinterData + 3]
call Printer_SerialSend
call Printer_NextInstruction
ret
Printer_SendNextByte:
; decrement 16-bit counter
ld hl, wPrinterSendByteCounter
ld a, [hli]
ld d, [hl]
ld e, a
or d
jr z, .done
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, wGameboyPrinterRAM
add hl, de
inc de
ld a, e
ld [wPrinterSendByteOffset], a
ld a, d
ld [wPrinterSendByteOffset + 1], a
ld a, [hl]
call Printer_SerialSend
ret
.done
call Printer_NextInstruction
Printer_SendwPrinterChecksumLo:
ld a, [wPrinterChecksum]
call Printer_SerialSend
call Printer_NextInstruction
ret
Printer_SendwPrinterChecksumHi:
ld a, [wPrinterChecksum + 1]
call Printer_SerialSend
call Printer_NextInstruction
ret
Printer_Send0x00_2:
; identical to Printer_Send0x00, but referenced less
ld a, $0
call Printer_SerialSend
call Printer_NextInstruction
ret
Printer_ReceiveTwoPrinterHandshakeAndSend0x00:
ldh a, [rSB]
ld [wPrinterHandshake], a
ld a, $0
call Printer_SerialSend
call Printer_NextInstruction
ret
Printer_ReceiveTwoPrinterStatusFlagsAndExitSendLoop:
ldh a, [rSB]
ld [wPrinterStatusFlags], a
xor a
ld [wPrinterOpcode], a
ret
Printer_Send0x0f:
ld a, $f
call Printer_SerialSend
call Printer_NextInstruction
ret
Printer_Send0x00:
ld a, $0
call Printer_SerialSend
call Printer_NextInstruction
ret
Printer_Send0x08:
ld a, $8
call Printer_SerialSend
call Printer_NextInstruction
ret
Printer_SerialSend:
ldh [rSB], a
ld a, (0 << rSC_ON) | (1 << rSC_CLOCK)
ldh [rSC], a
ld a, (1 << rSC_ON) | (1 << rSC_CLOCK)
ldh [rSC], a
ret
Printer_ReceiveTwoPrinterStatusFlagsAndExitSendLoop_2:
; identical to Printer_ReceiveTwoPrinterStatusFlagsAndExitSendLoop, but referenced less
ldh a, [rSB]
ld [wPrinterStatusFlags], a
xor a
ld [wPrinterOpcode], a
ret