ref: af0119ca7e73c21205b5bb89bb9361db9aafa15f
parent: 295604cbb51b0664c92f1a3a675ea7ffc3dc63ca
author: pikalaxalt <[email protected]>
date: Wed May 11 13:16:03 EDT 2016
Name all printer functions
--- a/battle/core.asm
+++ b/battle/core.asm
@@ -4939,7 +4939,7 @@
pop hl
dec hl
- ld a, BREEDMON
+ ld a, TEMPMON
ld [MonType], a
callab GetGender
ld a, " "
@@ -5017,7 +5017,7 @@
ld a, [hl]
ld [de], a
- ld a, BREEDMON
+ ld a, TEMPMON
ld [MonType], a
callab GetGender
ld a, " "
--- a/constants.asm
+++ b/constants.asm
@@ -33,3 +33,4 @@
INCLUDE "constants/battle_tower_constants.asm"
INCLUDE "constants/cry_constants.asm"
INCLUDE "constants/audio_constants.asm"
+INCLUDE "constants/printer_constants.asm"
--- /dev/null
+++ b/constants/printer_constants.asm
@@ -1,0 +1,9 @@
+const_value SET 1
+
+ const PRINTER_STATUS_CHECKING
+ const PRINTER_STATUS_TRANSMITTING
+ const PRINTER_STATUS_PRINTING
+ const PRINTER_ERROR_1
+ const PRINTER_ERROR_2
+ const PRINTER_ERROR_3
+ const PRINTER_ERROR_4
--- a/constants/wram_constants.asm
+++ b/constants/wram_constants.asm
@@ -3,7 +3,7 @@
PARTYMON EQU 0
OTPARTYMON EQU 1
BOXMON EQU 2
-BREEDMON EQU 3
+TEMPMON EQU 3
WILDMON EQU 4
; Options: ; cfcc
--- a/engine/breeding/egg.asm
+++ b/engine/breeding/egg.asm
@@ -8,7 +8,7 @@
ld [TempMonDVs], a
ld a, [wBreedMon1DVs + 1]
ld [TempMonDVs + 1], a
- ld a, BREEDMON
+ ld a, TEMPMON
ld [MonType], a
predef GetGender
jr c, .genderless
@@ -588,7 +588,7 @@
ld [TempMonDVs], a
ld a, [wBreedMon2DVs + 1]
ld [TempMonDVs + 1], a
- ld a, BREEDMON
+ ld a, TEMPMON
ld [MonType], a
predef GetGender
jr c, .inherit_mon2_moves
@@ -604,7 +604,7 @@
ld [TempMonDVs], a
ld a, [wBreedMon1DVs + 1]
ld [TempMonDVs + 1], a
- ld a, BREEDMON
+ ld a, TEMPMON
ld [MonType], a
predef GetGender
jr c, .inherit_mon1_moves
--- a/engine/diploma.asm
+++ b/engine/diploma.asm
@@ -1,32 +1,32 @@
_Diploma: ; 1dd702
- call Function1dd709
+ call PlaceDiplomaOnScreen
call WaitPressAorB_BlinkCursor
ret
; 1dd709
-Function1dd709: ; 1dd709
+PlaceDiplomaOnScreen: ; 1dd709
call ClearBGPalettes
call ClearTileMap
call ClearSprites
call DisableLCD
- ld hl, LZ_1dd805
+ ld hl, DiplomaGFX
ld de, VTiles2
call Decompress
- ld hl, Tilemap_1ddc4b
+ ld hl, DiplomaPage1Tilemap
decoord 0, 0
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
call CopyBytes
- ld de, String_1dd760
+ ld de, .Player
hlcoord 2, 5
call PlaceString
- ld de, String_1dd767
+ ld de, .EmptyString
hlcoord 15, 5
call PlaceString
ld de, PlayerName
hlcoord 9, 5
call PlaceString
- ld de, String_1dd768
+ ld de, .Certification
hlcoord 2, 8
call PlaceString
call EnableLCD
@@ -38,13 +38,13 @@
ret
; 1dd760
-String_1dd760:
+.Player:
db "PLAYER@"
-String_1dd767:
+.EmptyString:
db "@"
-String_1dd768:
+.Certification:
db "This certifies"
next "that you have"
next "completed the"
@@ -53,19 +53,19 @@
db "@"
; 1dd7ae
-Function1dd7ae: ; 1dd7ae
+PrintDiplomaPage2: ; 1dd7ae
hlcoord 0, 0
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
ld a, $7f
call ByteFill
- ld hl, Tilemap_1dddb3
+ ld hl, DiplomaPage2Tilemap
decoord 0, 0
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
call CopyBytes
- ld de, String_1dd7fa
+ ld de, .GameFreak
hlcoord 8, 0
call PlaceString
- ld de, String_1dd7f0
+ ld de, .PlayTime
hlcoord 3, 15
call PlaceString
hlcoord 12, 15
@@ -72,7 +72,7 @@
ld de, GameTimeHours
lb bc, 2, 4
call PrintNum
- ld [hl], $67
+ ld [hl], $67 ; colon
inc hl
ld de, GameTimeMinutes
lb bc, PRINTNUM_LEADINGZEROS | 1, 2
@@ -80,15 +80,15 @@
ret
; 1dd7f0
-String_1dd7f0: db "PLAY TIME@"
-String_1dd7fa: db "GAME FREAK@"
+.PlayTime: db "PLAY TIME@"
+.GameFreak: db "GAME FREAK@"
; 1dd805
-LZ_1dd805: ; 1dd805
+DiplomaGFX: ; 1dd805
INCBIN "gfx/unknown/1dd805.2bpp.lz"
-Tilemap_1ddc4b: ; 1ddc4b
+DiplomaPage1Tilemap: ; 1ddc4b
INCBIN "gfx/unknown/1ddc4b.tilemap"
-Tilemap_1dddb3: ; 1dddb3
+DiplomaPage2Tilemap: ; 1dddb3
INCBIN "gfx/unknown/1dddb3.tilemap"
--- a/engine/printer.asm
+++ b/engine/printer.asm
@@ -1,669 +1,63 @@
-Function84000: ; 84000
- ld hl, OverworldMap
- lb bc, 4, 12
- xor a
- call Function842ab
- xor a
- ld [rSB], a
- ld [rSC], a
- ld [wc2d5], a
- ld hl, wc2d4
- set 0, [hl]
- ld a, [GBPrinter]
- ld [wcbfb], a
- xor a
- ld [wJumptableIndex], a
- ret
-; 84022
+INCLUDE "engine/printer/serial.asm"
-Function84022: ; 84022
- ld a, [wJumptableIndex]
- ld e, a
- ld d, 0
- ld hl, .Jumptable
- add hl, de
- add hl, de
- ld a, [hli]
- ld h, [hl]
- ld l, a
- jp [hl]
-; 84031
-
-
-.Jumptable: ; 84031 (21:4031)
-
- dw Function84077
- dw Function84143
- dw Function84120
- dw Function84099
- dw Function84180
- dw Function8412e
- dw Function840c5
- dw Function84180
- dw Function84120
- dw Function840de
- dw Function84180
- dw Function84120
- dw Function841a1
- dw Function84063
- dw Function8406d
- dw Function84120
- dw Function84103
- dw Function84071
- dw Function841b0
- dw Function841b3
-
-
-Function84059: ; 84059 (21:4059)
- ld hl, wJumptableIndex
- inc [hl]
- ret
-
-Function8405e: ; 8405e (21:405e)
- ld hl, wJumptableIndex
- dec [hl]
- ret
-
-Function84063: ; 84063 (21:4063)
- xor a
- ld [wca89], a
- ld hl, wJumptableIndex
- set 7, [hl]
- ret
-
-Function8406d: ; 8406d (21:406d)
- call Function84059
- ret
-
-Function84071: ; 84071 (21:4071)
- ld a, $1
- ld [wJumptableIndex], a
- ret
-
-Function84077: ; 84077 (21:4077)
- call Function841fb
- ld hl, Unknown_842b7
- call Function841e2
- xor a
- ld [wca8e], a
- ld [wca8f], a
- ld a, [wcf65]
- ld [wca81], a
- call Function84059
- call Function841c3
- ld a, $1
- ld [wcbf8], a
- ret
-
-Function84099: ; 84099 (21:4099)
- call Function841fb
- ld hl, wca81
- ld a, [hl]
- and a
- jr z, Function840c5
- ld hl, Unknown_842c3
- call Function841e2
- call Function84260
- ld a, $80
- ld [wca8e], a
- ld a, $2
- ld [wca8f], a
- call Function84219
- call Function84059
- call Function841c3
- ld a, $2
- ld [wcbf8], a
- ret
-
-Function840c5: ; 840c5 (21:40c5)
- ld a, $6
- ld [wJumptableIndex], a
- ld hl, Unknown_842c9
- call Function841e2
- xor a
- ld [wca8e], a
- ld [wca8f], a
- call Function84059
- call Function841c3
- ret
-
-Function840de: ; 840de (21:40de)
- call Function841fb
- ld hl, Unknown_842bd
- call Function841e2
- call Function84249
- ld a, $4
- ld [wca8e], a
- ld a, $0
- ld [wca8f], a
- call Function84219
- call Function84059
- call Function841c3
- ld a, $3
- ld [wcbf8], a
- ret
-
-Function84103: ; 84103 (21:4103)
- call Function841fb
- ld hl, Unknown_842b7
- call Function841e2
- xor a
- ld [wca8e], a
- ld [wca8f], a
- ld a, [wcf65]
- ld [wca81], a
- call Function84059
- call Function841c3
- ret
-
-Function84120: ; 84120 (21:4120)
- ld hl, wca8b
- inc [hl]
- ld a, [hl]
- cp $6
- ret c
- xor a
- ld [hl], a
- call Function84059
- ret
-
-Function8412e: ; 8412e (21:412e)
- ld hl, wca8b
- inc [hl]
- ld a, [hl]
- cp $6
- ret c
- xor a
- ld [hl], a
- ld hl, wca81
- dec [hl]
- call Function8405e
- call Function8405e
- ret
-
-Function84143: ; 84143 (21:4143)
- ld a, [wc2d5]
- and a
- ret nz
- ld a, [wca88]
- cp $ff
- jr nz, .printer_connected
- ld a, [wca89]
- cp $ff
- jr z, .printer_error
-
-.printer_connected
- ld a, [wca88]
- cp $81
- jr nz, .printer_error
- ld a, [wca89]
- cp $0
- jr nz, .printer_error
- ld hl, wc2d4
- set 1, [hl]
- ld a, $5
- ld [wca8a], a
- call Function84059
- ret
-
-.printer_error
- ld a, $ff
- ld [wca88], a
- ld [wca89], a
- ld a, $e
- ld [wJumptableIndex], a
- ret
-
-Function84180: ; 84180 (21:4180)
- ld a, [wc2d5]
- and a
- ret nz
- ld a, [wca89]
- and $f0
- jr nz, .asm_8419b
- ld a, [wca89]
- and $1
- jr nz, .asm_84197
- call Function84059
- ret
-.asm_84197
- call Function8405e
- ret
-.asm_8419b
- ld a, $12
- ld [wJumptableIndex], a
- ret
-
-Function841a1: ; 841a1 (21:41a1)
- ld a, [wc2d5]
- and a
- ret nz
- ld a, [wca89]
- and $f3
- ret nz
- call Function84059
- ret
-
-Function841b0: ; 841b0 (21:41b0)
- call Function84059
-
-Function841b3: ; 841b3 (21:41b3)
- ld a, [wc2d5]
- and a
- ret nz
- ld a, [wca89]
- and $f0
- ret nz
- xor a
- ld [wJumptableIndex], a
- ret
-
-Function841c3: ; 841c3 (21:41c3)
- ld a, [wc2d5]
- and a
- jr nz, Function841c3
- xor a
- ld [wca8c], a
- ld [wca8d], a
- ld a, $1
- ld [wc2d5], a
- ld a, $88
- ld [rSB], a
- ld a, $1
- ld [rSC], a
- ld a, $81
- ld [rSC], a
- ret
-
-Function841e2: ; 841e2 (21:41e2)
- ld a, [hli]
- ld [wca82], a
- ld a, [hli]
- ld [wca83], a
- ld a, [hli]
- ld [wca84], a
- ld a, [hli]
- ld [wca85], a
- ld a, [hli]
- ld [wca86], a
- ld a, [hl]
- ld [wca87], a
- ret
-
-Function841fb: ; 841fb (21:41fb)
- xor a
- ld hl, wca82
- ld [hli], a
- ld [hli], a
- ld [hli], a
- ld [hl], a
- ld hl, wca86
- ld [hli], a
- ld [hl], a
- xor a
- ld [wca8e], a
- ld [wca8f], a
- ld hl, OverworldMap
- ld bc, $280
- call Function842ab
- ret
-
-Function84219: ; 84219 (21:4219)
- ld hl, 0
- ld bc, $4
- ld de, wca82
- call Function8423c
- ld a, [wca8e]
- ld c, a
- ld a, [wca8f]
- ld b, a
- ld de, OverworldMap
- call Function8423c
- ld a, l
- ld [wca86], a
- ld a, h
- ld [wca87], a
- ret
-
-Function8423c: ; 8423c (21:423c)
- ld a, [de]
- inc de
- add l
- jr nc, .asm_84242
- inc h
-.asm_84242
- ld l, a
- dec bc
- ld a, c
- or b
- jr nz, Function8423c
- ret
-
-Function84249: ; 84249 (21:4249)
- ld a, $1
- ld [OverworldMap], a
- ld a, [wcbfa]
- ld [wc801], a
- ld a, $e4
- ld [wc802], a
- ld a, [wcbfb]
- ld [wc803], a
- ret
-
-Function84260: ; 84260 (21:4260)
- ld a, [wca81]
- xor $ff
- ld d, a
- ld a, [wcf65]
- inc a
- add d
- ld hl, wca90
- 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, OverworldMap
- 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
-
-Function842ab: ; 842ab
- push de
- ld e, a
-.asm_842ad
- ld [hl], e
- inc hl
- dec bc
- ld a, c
- or b
- jr nz, .asm_842ad
- ld a, e
- pop de
- ret
-; 842b7
-
-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
-Unknown_842cf: db 8, 0, $00, 0, 8, 0 ; unused
-Unknown_842d5: db 15, 0, $00, 0, 15, 0 ; unused
-; 842db
-
-
-_PrinterReceive:: ; 842db
- ld a, [wc2d5]
- 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]
-; 842ea
-
-
-.Jumptable: ; 842ea (21:42ea)
-
- dw Function8432f
- dw Function84330
- dw Function84339
- dw Function84343
- dw Function8434d
- dw Function84357
- dw Function84361
- dw Function8438b
- dw Function84395
- dw Function8439f
- dw Function843a8
- dw Function843b6
- dw Function84330
- dw Function843c0
- dw Function843c9
- dw Function843c9
- dw Function843c9
- dw Function843c0
- dw Function843c9
- dw Function8439f
- dw Function843a8
- dw Function843e6
- dw Function84330
- dw Function843d2
- dw Function843c9
- dw Function843c9
- dw Function843c9
- dw Function843d2
- dw Function843c9
- dw Function8439f
- dw Function843a8
- dw Function843b6
-
-
-Function8432a: ; 8432a (21:432a)
- ld hl, wc2d5
- inc [hl]
- ret
-
-Function8432f: ; 8432f (21:432f)
- ret
-
-Function84330: ; 84330 (21:4330)
- ld a, $33
- call Function843db
- call Function8432a
- ret
-
-Function84339: ; 84339 (21:4339)
- ld a, [wca82]
- call Function843db
- call Function8432a
- ret
-
-Function84343: ; 84343 (21:4343)
- ld a, [wca83]
- call Function843db
- call Function8432a
- ret
-
-Function8434d: ; 8434d (21:434d)
- ld a, [wca84]
- call Function843db
- call Function8432a
- ret
-
-Function84357: ; 84357 (21:4357)
- ld a, [wca85]
- call Function843db
- call Function8432a
- ret
-
-Function84361: ; 84361 (21:4361)
- ld hl, wca8e
- ld a, [hli]
- ld d, [hl]
- ld e, a
- or d
- jr z, .asm_84388
- dec de
- ld [hl], d
- dec hl
- ld [hl], e
- ld a, [wca8c]
- ld e, a
- ld a, [wca8d]
- ld d, a
- ld hl, OverworldMap
- add hl, de
- inc de
- ld a, e
- ld [wca8c], a
- ld a, d
- ld [wca8d], a
- ld a, [hl]
- call Function843db
- ret
-.asm_84388
- call Function8432a
-
-Function8438b: ; 8438b (21:438b)
- ld a, [wca86]
- call Function843db
- call Function8432a
- ret
-
-Function84395: ; 84395 (21:4395)
- ld a, [wca87]
- call Function843db
- call Function8432a
- ret
-
-Function8439f: ; 8439f (21:439f)
- ld a, $0
- call Function843db
- call Function8432a
- ret
-
-Function843a8: ; 843a8 (21:43a8)
- ld a, [rSB]
- ld [wca88], a
- ld a, $0
- call Function843db
- call Function8432a
- ret
-
-Function843b6: ; 843b6 (21:43b6)
- ld a, [rSB]
- ld [wca89], a
- xor a
- ld [wc2d5], a
- ret
-
-Function843c0: ; 843c0 (21:43c0)
- ld a, $f
- call Function843db
- call Function8432a
- ret
-
-Function843c9: ; 843c9 (21:43c9)
- ld a, $0
- call Function843db
- call Function8432a
- ret
-
-Function843d2: ; 843d2 (21:43d2)
- ld a, $8
- call Function843db
- call Function8432a
- ret
-
-Function843db: ; 843db (21:43db)
- ld [rSB], a
- ld a, $1
- ld [rSC], a
- ld a, $81
- ld [rSC], a
- ret
-
-Function843e6: ; 843e6 (21:43e6)
- ld a, [rSB]
- ld [wca89], a
- xor a
- ld [wc2d5], a
- ret
-
-Function843f0: ; 843f0
-.asm_843f0
+SendScreenToPrinter: ; 843f0
+.loop
call JoyTextDelay
- call Function846f6
- jr c, .asm_8440f
+ call CheckCancelPrint
+ jr c, .cancel
ld a, [wJumptableIndex]
bit 7, a
- jr nz, .asm_8440d
- call Function84022
- call Function84757
- call Function84785
+ jr nz, .finished
+ call PrinterJumptableIteration
+ call CheckPrinterStatus
+ call PlacePrinterStatusString
call DelayFrame
- jr .asm_843f0
+ jr .loop
-.asm_8440d
+.finished
and a
ret
-.asm_8440f
+.cancel
scf
ret
; 84411
-Function84411: ; 84411
+Printer_CleanUpAfterSend: ; 84411
xor a
- ld [wc2d4], a
- ld [wc2d5], a
+ ld [wPrinterConnectionOpen], a
+ ld [wPrinterOpcode], a
ret
; 84419
-Function84419: ; 84419
+Printer_PrepareTileMapForPrint: ; 84419
push af
- call Function84000
+ call Printer_StartTransmission
pop af
ld [wcbfa], a
- call Function84728
+ call Printer_CopyTileMapToBuffer
ret
; 84425
-Function84425: ; 84425
+Printer_ExitPrinter: ; 84425
call ReturnToMapFromSubmenu
- call Function84753
+ call Printer_RestartMapMusic
ret
; 8442c
PrintDexEntry: ; 8442c
- ld a, [wcf65]
+ ld a, [wPrinterQueueLength]
push af
+
ld hl, VTiles1
ld de, FontInversed
lb bc, BANK(FontInversed), $80
call Request1bpp
+
xor a
ld [hPrinter], a
- call Function8474c
+ call Printer_PlayMusic
+
ld a, [rIE]
push af
xor a
@@ -670,144 +64,164 @@
ld [rIF], a
ld a, $9
ld [rIE], a
- call Function84000
+
+ call Printer_StartTransmission
ld a, $10
ld [wcbfa], a
callba PrintPage1
call ClearTileMap
- ld a, $e4
+ ld a, %11100100
call DmgToCgbBGPals
call DelayFrame
+
ld hl, hVBlank
ld a, [hl]
push af
ld [hl], $4
- ld a, $8
- ld [wcf65], a
- call Function84742
- call Function843f0
- jr c, .asm_8449d
- call Function84411
+
+ 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
ld [hBGMapMode], a
- call Function84000
+
+ call Printer_StartTransmission
ld a, $3
ld [wcbfa], a
callba PrintPage2
- call Function84742
- ld a, $4
- ld [wcf65], a
- call Function843f0
+ call Printer_ResetJoypadRegisters
+ ld a, 4
+ ld [wPrinterQueueLength], a
+ call SendScreenToPrinter
-.asm_8449d
+.skip_second_page
pop af
ld [hVBlank], a
- call Function84411
+ call Printer_CleanUpAfterSend
+
xor a
ld [rIF], a
pop af
ld [rIE], a
- call Function84425
- ld c, $8
-.asm_844ae
+
+ call Printer_ExitPrinter
+ ld c, 8
+.low_volume_delay_frames
call LowVolume
call DelayFrame
dec c
- jr nz, .asm_844ae
+ jr nz, .low_volume_delay_frames
+
pop af
- ld [wcf65], a
+ ld [wPrinterQueueLength], a
ret
; 844bc
PrintPCBox: ; 844bc (21:44bc)
- ld a, [wcf65]
+ ld a, [wPrinterQueueLength]
push af
- ld a, $9
- ld [wcf65], a
+ ld a, 18 / 2
+ ld [wPrinterQueueLength], a
+
ld a, e
- ld [wd004], a
+ ld [wAddrOfBoxToPrint], a
ld a, d
- ld [wd005], a
+ ld [wAddrOfBoxToPrint + 1], a
ld a, b
- ld [wd006], a
+ ld [wBankOfBoxToPrint], a
ld a, c
- ld [wd007], a
+ ld [wWhichBoxToPrint], a
+
xor a
ld [hPrinter], a
- ld [wd003], a
- call Function8474c
+ ld [wFinishedPrintingBox], a
+ call Printer_PlayMusic
+
ld a, [rIE]
push af
xor a
ld [rIF], a
- ld a, $9
+ ld a, %1001
ld [rIE], a
+
ld hl, hVBlank
ld a, [hl]
push af
- ld [hl], $4
+ ld [hl], %0100
+
xor a
ld [hBGMapMode], a
- call Function84817
- ld a, $10
- call Function84419
- call Function84559
- jr c, .asm_84545
- call Function84411
+ call PrintPCBox_Page1
+ ld a, $10 ; to be loaded to wcbfa
+ call Printer_PrepareTileMapForPrint
+ call Printer_ResetRegistersAndStartDataSend
+ jr c, .cancel
+
+ call Printer_CleanUpAfterSend
ld c, 12
call DelayFrames
xor a
ld [hBGMapMode], a
- call Function8486f
- ld a, $0
- call Function84419
- call Function84559
- jr c, .asm_84545
- call Function84411
+ call PrintPCBox_Page2
+ ld a, $0 ; to be loaded to wcbfa
+ call Printer_PrepareTileMapForPrint
+ call Printer_ResetRegistersAndStartDataSend
+ jr c, .cancel
+
+ call Printer_CleanUpAfterSend
ld c, 12
call DelayFrames
+
xor a
ld [hBGMapMode], a
- call Function84893
- ld a, $0
- call Function84419
- call Function84559
- jr c, .asm_84545
- call Function84411
+ call PrintPCBox_Page3
+ ld a, $0 ; to be loaded to wcbfa
+ call Printer_PrepareTileMapForPrint
+ call Printer_ResetRegistersAndStartDataSend
+ jr c, .cancel
+
+ call Printer_CleanUpAfterSend
ld c, 12
call DelayFrames
+
xor a
ld [hBGMapMode], a
- call Function848b7
- ld a, $3
- call Function84419
- call Function84559
-.asm_84545
+ call PrintPCBox_Page4
+ ld a, $3 ; to be loaded to wcbfa
+ call Printer_PrepareTileMapForPrint
+ call Printer_ResetRegistersAndStartDataSend
+.cancel
pop af
ld [hVBlank], a
- call Function84411
+ call Printer_CleanUpAfterSend
+
xor a
ld [rIF], a
pop af
ld [rIE], a
- call Function84425
+ call Printer_ExitPrinter
+
pop af
- ld [wcf65], a
+ ld [wPrinterQueueLength], a
ret
-Function84559: ; 84559 (21:4559)
- call Function84742
- call Function843f0
+Printer_ResetRegistersAndStartDataSend: ; 84559 (21:4559)
+ call Printer_ResetJoypadRegisters
+ call SendScreenToPrinter
ret
PrintUnownStamp: ; 84560
- ld a, [wcf65]
+ ld a, [wPrinterQueueLength]
push af
xor a
ld [hPrinter], a
- call Function8474c
+ call Printer_PlayMusic
ld a, [rIE]
push af
xor a
@@ -822,36 +236,36 @@
ld [hBGMapMode], a
call LoadTileMapToTempTileMap
callba PlaceUnownPrinterFrontpic
- ld a, $0
- call Function84419
+ ld a, $0 ; to be loaded to wcbfa
+ call Printer_PrepareTileMapForPrint
call Call_LoadTempTileMapToTileMap
- call Function84742
- ld a, $9
- ld [wcf65], a
-.asm_84597
+ call Printer_ResetJoypadRegisters
+ ld a, 18 / 2
+ ld [wPrinterQueueLength], a
+.loop
call JoyTextDelay
- call Function846f6
- jr c, .asm_845c0
+ call CheckCancelPrint
+ jr c, .done
ld a, [wJumptableIndex]
bit 7, a
- jr nz, .asm_845c0
- call Function84022
+ jr nz, .done
+ call PrinterJumptableIteration
ld a, [wJumptableIndex]
cp $2
- jr nc, .asm_845b5
- ld a, $3
- ld [wca81], a
+ jr nc, .check_status
+ ld a, 6 / 2
+ ld [wPrinterRowIndex], a
-.asm_845b5
- call Function84757
- call Function84785
+.check_status
+ call CheckPrinterStatus
+ call PlacePrinterStatusString
call DelayFrame
- jr .asm_84597
+ jr .loop
-.asm_845c0
+.done
pop af
ld [hVBlank], a
- call Function84411
+ call Printer_CleanUpAfterSend
call Call_LoadTempTileMapToTileMap
xor a
ld [rIF], a
@@ -858,176 +272,202 @@
pop af
ld [rIE], a
pop af
- ld [wcf65], a
+ ld [wPrinterQueueLength], a
ret
; 845d4
PrintMail: ; 845d4
- call Function845db
- call Function84425
+ call PrintMail_
+ call Printer_ExitPrinter
ret
; 845db
-Function845db: ; 845db
- ld a, [wcf65]
+PrintMail_: ; 845db
+ ld a, [wPrinterQueueLength]
push af
xor a
ld [hPrinter], a
- call Function8474c
+ call Printer_PlayMusic
+
ld a, [rIE]
push af
xor a
ld [rIF], a
- ld a, $9
+ ld a, %1001
ld [rIE], a
+
xor a
ld [hBGMapMode], a
- ld a, $13
- call Function84419
+
+ ld a, $13 ; to be loaded to wcbfa
+ call Printer_PrepareTileMapForPrint
ld hl, hVBlank
ld a, [hl]
push af
- ld [hl], $4
- ld a, $9
- ld [wcf65], a
- call Function843f0
+ ld [hl], %0100
+
+ ld a, 18 / 2
+ ld [wPrinterQueueLength], a
+ call SendScreenToPrinter
+
pop af
ld [hVBlank], a
- call Function84411
- call Function84735
+ call Printer_CleanUpAfterSend
+ call Printer_CopyBufferToTileMap
+
xor a
ld [rIF], a
pop af
ld [rIE], a
+
pop af
- ld [wcf65], a
+ ld [wPrinterQueueLength], a
ret
; 8461a
PrintPartymon: ; 8461a
- ld a, [wcf65]
+ ld a, [wPrinterQueueLength]
push af
xor a
ld [hPrinter], a
- call Function8474c
+ call Printer_PlayMusic
+
ld a, [rIE]
push af
xor a
ld [rIF], a
- ld a, $9
+ ld a, %1001
ld [rIE], a
+
xor a
ld [hBGMapMode], a
- callba Function1dc381
- ld a, $10
- call Function84419
+ callba PrintPartyMonPage1
+ ld a, $10 ; to be loaded to wcbfa
+ call Printer_PrepareTileMapForPrint
+
ld hl, hVBlank
ld a, [hl]
push af
- ld [hl], $4
- ld a, $8
- ld [wcf65], a
- call Function84742
- call Function843f0
- jr c, .asm_84671
- call Function84411
+ ld [hl], %0100
+
+ 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
ld [hBGMapMode], a
- callba Function1dc47b
- ld a, $3
- call Function84419
- ld a, $9
- ld [wcf65], a
- call Function84742
- call Function843f0
+ callba PrintPartyMonPage2
+ ld a, $3 ; to be loaded to wcbfa
+ call Printer_PrepareTileMapForPrint
-.asm_84671
+ ld a, 18 / 2
+ ld [wPrinterQueueLength], a
+ call Printer_ResetJoypadRegisters
+ call SendScreenToPrinter
+.cancel
pop af
ld [hVBlank], a
- call Function84411
- call Function84735
+ call Printer_CleanUpAfterSend
+
+ call Printer_CopyBufferToTileMap
xor a
ld [rIF], a
pop af
ld [rIE], a
- call Function84425
+ call Printer_ExitPrinter
+
pop af
- ld [wcf65], a
+ ld [wPrinterQueueLength], a
ret
; 84688
_PrintDiploma: ; 84688
- ld a, [wcf65]
+ ld a, [wPrinterQueueLength]
push af
- callba Function1dd709
+
+ callba PlaceDiplomaOnScreen
+
xor a
ld [hPrinter], a
- call Function8474c
+ call Printer_PlayMusic
+
ld a, [rIE]
push af
xor a
ld [rIF], a
- ld a, $9
+ ld a, %1001
ld [rIE], a
+
ld hl, hVBlank
ld a, [hl]
push af
- ld [hl], $4
- ld a, $10
- call Function84419
- call Function84742
- ld a, $9
- ld [wcf65], a
- call Function843f0
- jr c, .asm_846e2
- call Function84411
+ ld [hl], %0100
+
+ ld a, $10 ; to be loaded to wcbfa
+ 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
ld [hBGMapMode], a
- callba Function1dd7ae
- ld a, $3
- call Function84419
+
+ callba PrintDiplomaPage2
+
+ ld a, $3 ; to be loaded to wcbfa
+ call Printer_PrepareTileMapForPrint
call Call_LoadTempTileMapToTileMap
- call Function84742
- ld a, $9
- ld [wcf65], a
- call Function843f0
+ call Printer_ResetJoypadRegisters
-.asm_846e2
+ ld a, 18 / 2
+ ld [wPrinterQueueLength], a
+ call SendScreenToPrinter
+.cancel
pop af
ld [hVBlank], a
- call Function84411
+ call Printer_CleanUpAfterSend
+
xor a
ld [rIF], a
pop af
ld [rIE], a
- call Function84425
+ call Printer_ExitPrinter
+
pop af
- ld [wcf65], a
+ ld [wPrinterQueueLength], a
ret
; 846f6
-Function846f6: ; 846f6
+CheckCancelPrint: ; 846f6
ld a, [hJoyDown]
and B_BUTTON
- jr nz, .asm_846fe
+ jr nz, .pressed_b
and a
ret
-.asm_846fe
+.pressed_b
ld a, [wca80]
cp $c
- jr nz, .asm_84722
-.asm_84705
- ld a, [wc2d5]
+ jr nz, .cancel
+.loop
+ ld a, [wPrinterOpcode]
and a
- jr nz, .asm_84705
- ld a, $16
- ld [wc2d5], a
+ jr nz, .loop
+ ld a, $16 ; cancel
+ ld [wPrinterOpcode], a
ld a, $88
ld [rSB], a
ld a, $1
@@ -1034,12 +474,12 @@
ld [rSC], a
ld a, $81
ld [rSC], a
-.asm_8471c
- ld a, [wc2d5]
+.loop2
+ ld a, [wPrinterOpcode]
and a
- jr nz, .asm_8471c
+ jr nz, .loop2
-.asm_84722
+.cancel
ld a, $1
ld [hPrinter], a
scf
@@ -1046,16 +486,16 @@
ret
; 84728
-Function84728: ; 84728
+Printer_CopyTileMapToBuffer: ; 84728
hlcoord 0, 0
- ld de, wca90
+ ld de, wPrinterTileMapBuffer
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
call CopyBytes
ret
; 84735
-Function84735: ; 84735
- ld hl, wca90
+Printer_CopyBufferToTileMap: ; 84735
+ ld hl, wPrinterTileMapBuffer
decoord 0, 0
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
call CopyBytes
@@ -1062,7 +502,7 @@
ret
; 84742
-Function84742: ; 84742
+Printer_ResetJoypadRegisters: ; 84742
xor a
ld [hJoyReleased], a
ld [hJoyPressed], a
@@ -1071,27 +511,29 @@
ret
; 8474c
-Function8474c: ; 8474c
+Printer_PlayMusic: ; 8474c
ld de, MUSIC_PRINTER
call PlayMusic2
ret
; 84753
-Function84753: ; 84753
+Printer_RestartMapMusic: ; 84753
call RestartMapMusic
ret
; 84757
-Function84757: ; 84757
- ld a, [wca88]
+CheckPrinterStatus: ; 84757
+; Check for printer errors
+; If [ca88] == -1, we're disconnected
+ ld a, [wPrinterHandshake]
cp -1
jr nz, .printer_connected
- ld a, [wca89]
+ ld a, [wPrinterStatusFlags]
cp -1
jr z, .error_2
-
.printer_connected
- ld a, [wca89]
+; ca89 contains printer status flags
+ ld a, [wPrinterStatusFlags]
and %11100000
ret z ; no error
@@ -1099,27 +541,31 @@
jr nz, .error_1
bit 6, a
jr nz, .error_4
- ld a, 6 ; error 3
+ ; paper error
+ ld a, PRINTER_ERROR_3
jr .load_text_index
.error_4
- ld a, 7 ; error 4
+ ; temperature error
+ ld a, PRINTER_ERROR_4
jr .load_text_index
.error_1
- ld a, 4 ; error 1
+ ; printer battery low
+ ld a, PRINTER_ERROR_1
jr .load_text_index
.error_2
- ld a, 5 ; error 2
-
+ ; connection error
+ ld a, PRINTER_ERROR_2
.load_text_index
- ld [wcbf8], a
+ ld [wPrinterStatus], a
ret
; 84785
-Function84785: ; 84785
- ld a, [wcbf8]
+PlacePrinterStatusString: ; 84785
+; Print nonzero printer status
+ ld a, [wPrinterStatus]
and a
ret z
push af
@@ -1146,12 +592,13 @@
ld a, $1
ld [hBGMapMode], a
xor a
- ld [wcbf8], a
+ ld [wPrinterStatus], a
ret
; 847bd
Function847bd: ; 847bd
- ld a, [wcbf8]
+; XXX
+ ld a, [wPrinterStatus]
and a
ret z
push af
@@ -1178,7 +625,7 @@
ld a, $1
ld [hBGMapMode], a
xor a
- ld [wcbf8], a
+ ld [wPrinterStatus], a
ret
; 847f5
@@ -1187,34 +634,38 @@
; 84807
PrinterStatusStringPointers: ; 84807
- dw String_1dc275 ; @
- dw String_1dc276 ; CHECKING LINK
- dw String_1dc289 ; TRANSMITTING
- dw String_1dc29c ; PRINTING
- dw String_1dc2ad ; error 1
- dw String_1dc2e2 ; error 2
- dw String_1dc317 ; error 3
- dw String_1dc34c ; error 4
+ 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
; 84817
-Function84817: ; 84817 (21:4817)
+PrintPCBox_Page1: ; 84817 (21:4817)
xor a
- ld [wd002], 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, [wd007]
+
+ ld a, [wWhichBoxToPrint]
ld bc, BOX_NAME_LENGTH
ld hl, wBoxNames
call AddNTimes
@@ -1222,11 +673,11 @@
ld e, l
hlcoord 6, 5
call PlaceString
- ld a, $1
- call Function849c6
+ ld a, 1
+ call Printer_GetBoxMonSpecies
hlcoord 2, 9
- ld c, $3
- call Function848e7
+ ld c, 3
+ call Printer_PrintBoxListSegment
ret
; 84865 (21:4865)
@@ -1234,7 +685,7 @@
db "#MON LIST@"
; 8486f
-Function8486f: ; 8486f (21:486f)
+PrintPCBox_Page2: ; 8486f (21:486f)
hlcoord 0, 0
ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
ld a, " "
@@ -1241,17 +692,17 @@
call ByteFill
call Printer_PlaceEmptyBoxSlotString
call Printer_PlaceSideBorders
- ld a, [wd003]
+ ld a, [wFinishedPrintingBox]
and a
ret nz
- ld a, $4
- call Function849c6
+ ld a, 4
+ call Printer_GetBoxMonSpecies
hlcoord 2, 0
- ld c, $6
- call Function848e7
+ ld c, 6
+ call Printer_PrintBoxListSegment
ret
-Function84893: ; 84893 (21:4893)
+PrintPCBox_Page3: ; 84893 (21:4893)
hlcoord 0, 0
ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
ld a, " "
@@ -1258,17 +709,17 @@
call ByteFill
call Printer_PlaceEmptyBoxSlotString
call Printer_PlaceSideBorders
- ld a, [wd003]
+ ld a, [wFinishedPrintingBox]
and a
ret nz
- ld a, $a
- call Function849c6
+ ld a, 10
+ call Printer_GetBoxMonSpecies
hlcoord 2, 0
- ld c, $6
- call Function848e7
+ ld c, 6
+ call Printer_PrintBoxListSegment
ret
-Function848b7: ; 848b7 (21:48b7)
+PrintPCBox_Page4: ; 848b7 (21:48b7)
hlcoord 0, 0
ld bc, SCREEN_HEIGHT * SCREEN_WIDTH
ld a, " "
@@ -1279,41 +730,44 @@
call ClearBox
call Printer_PlaceSideBorders
call Printer_PlaceBottomBorders
- ld a, [wd003]
+ ld a, [wFinishedPrintingBox]
and a
ret nz
- ld a, $10
- call Function849c6
+ ld a, 16
+ call Printer_GetBoxMonSpecies
hlcoord 2, 0
- ld c, $5
- call Function848e7
+ ld c, 5
+ call Printer_PrintBoxListSegment
ret
-Function848e7: ; 848e7 (21:48e7)
- ld a, [wd006]
+Printer_PrintBoxListSegment: ; 848e7 (21:48e7)
+ ld a, [wBankOfBoxToPrint]
call GetSRAMBank
-
-Function848ed: ; 848ed (21:48ed)
+.loop
ld a, c
and a
- jp z, Function84986
+ jp z, .max_length
dec c
ld a, [de]
cp $ff
- jp z, Function84981
+ jp z, .finish
ld [wd265], a
ld [CurPartySpecies], a
+
push bc
push hl
push de
+
push hl
- ld bc, $10
+ ld bc, 16
ld a, " "
call ByteFill
pop hl
+
push hl
call GetBasePokemonName
pop hl
+
push hl
call PlaceString
ld a, [CurPartySpecies]
@@ -1320,78 +774,82 @@
cp EGG
pop hl
jr z, .ok2
- ld bc, $b
+
+ ld bc, PKMN_NAME_LENGTH
add hl, bc
- call Function8498a
- ld bc, $9
+ call Printer_GetMonGender
+ ld bc, SCREEN_WIDTH - PKMN_NAME_LENGTH
add hl, bc
ld a, "/"
ld [hli], a
+
push hl
- ld bc, $e
+ ld bc, 14
ld a, " "
call ByteFill
pop hl
+
push hl
- ld a, [wd004]
+ ld a, [wAddrOfBoxToPrint]
ld l, a
- ld a, [wd005]
+ ld a, [wAddrOfBoxToPrint + 1]
ld h, a
- ld bc, $372
+ ld bc, sBoxMonNicknames - sBox
add hl, bc
- ld bc, $b
- ld a, [wd002]
+ ld bc, PKMN_NAME_LENGTH
+ ld a, [wWhichBoxMonToPrint]
call AddNTimes
ld e, l
ld d, h
pop hl
+
push hl
call PlaceString
pop hl
- ld bc, $b
+
+ ld bc, PKMN_NAME_LENGTH
add hl, bc
push hl
- ld a, [wd004]
+ ld a, [wAddrOfBoxToPrint]
ld l, a
- ld a, [wd005]
+ ld a, [wAddrOfBoxToPrint + 1]
ld h, a
- ld bc, $35
+ ld bc, 2 + MONS_PER_BOX + MON_LEVEL
add hl, bc
- ld bc, $20
- ld a, [wd002]
+ ld bc, BOXMON_STRUCT_LENGTH
+ ld a, [wWhichBoxMonToPrint]
call AddNTimes
ld a, [hl]
pop hl
call PrintLevel_Force3Digits
.ok2
- ld hl, wd002
+ ld hl, wWhichBoxMonToPrint
inc [hl]
pop de
pop hl
- ld bc, $3c
+ ld bc, 3 * SCREEN_WIDTH
add hl, bc
pop bc
inc de
- jp Function848ed
+ jp .loop
-Function84981: ; 84981 (21:4981)
+.finish
ld a, $1
- ld [wd003], a
-
-Function84986: ; 84986 (21:4986)
+ ld [wFinishedPrintingBox], a
+.max_length
call CloseSRAM
ret
-Function8498a: ; 8498a (21:498a)
+Printer_GetMonGender: ; 8498a (21:498a)
push hl
- ld a, [wd004]
+ ld a, [wAddrOfBoxToPrint]
ld l, a
- ld a, [wd005]
+ ld a, [wAddrOfBoxToPrint + 1]
ld h, a
ld bc, $2b
add hl, bc
- ld bc, $20
- ld a, [wd002]
+ ld bc, BOXMON_STRUCT_LENGTH
+ ld a, [wWhichBoxMonToPrint]
call AddNTimes
ld de, TempMonDVs
ld a, [hli]
@@ -1399,28 +857,28 @@
inc de
ld a, [hli]
ld [de], a
- ld a, [wd002]
+ ld a, [wWhichBoxMonToPrint]
ld [CurPartyMon], a
- ld a, $3
+ ld a, TEMPMON
ld [MonType], a
callba GetGender
- ld a, $7f
- jr c, .asm_849c3
- ld a, $ef
- jr nz, .asm_849c3
- ld a, $f5
-.asm_849c3
+ ld a, " "
+ jr c, .got_gender
+ ld a, "♂"
+ jr nz, .got_gender
+ ld a, "♀"
+.got_gender
pop hl
ld [hli], a
ret
-Function849c6: ; 849c6 (21:49c6)
+Printer_GetBoxMonSpecies: ; 849c6 (21:49c6)
push hl
ld e, a
ld d, $0
- ld a, [wd004]
+ ld a, [wAddrOfBoxToPrint]
ld l, a
- ld a, [wd005]
+ ld a, [wAddrOfBoxToPrint + 1]
ld h, a
add hl, de
ld e, l
--- /dev/null
+++ b/engine/printer/serial.asm
@@ -1,0 +1,645 @@
+Printer_StartTransmission: ; 84000
+ ld hl, wGameboyPrinterRAM
+ ld bc, wGameboyPrinterRAMEnd - wGameboyPrinterRAM
+ xor a
+ call Printer_ByteFill
+ xor a
+ ld [rSB], a
+ ld [rSC], a
+ ld [wPrinterOpcode], a
+ ld hl, wPrinterConnectionOpen
+ set 0, [hl]
+ ld a, [GBPrinter]
+ ld [wGBPrinterSettings], a
+ xor a
+ ld [wJumptableIndex], a
+ ret
+; 84022
+
+PrinterJumptableIteration: ; 84022
+ ld a, [wJumptableIndex]
+ ld e, a
+ ld d, 0
+ ld hl, .Jumptable
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp [hl]
+; 84031
+
+
+.Jumptable: ; 84031 (21:4031)
+
+ 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_WaitLoopBack ; 12
+ dw Printer_WaitLoopBack_ ; 13
+
+
+Printer_NextSection: ; 84059 (21:4059)
+ ld hl, wJumptableIndex
+ inc [hl]
+ ret
+
+Printer_PrevSection: ; 8405e (21:405e)
+ ld hl, wJumptableIndex
+ dec [hl]
+ ret
+
+Printer_Quit: ; 84063 (21:4063)
+ xor a
+ ld [wPrinterStatusFlags], a
+ ld hl, wJumptableIndex
+ set 7, [hl]
+ ret
+
+Printer_NextSection_: ; 8406d (21:406d)
+ call Printer_NextSection
+ ret
+
+Printer_SectionOne: ; 84071 (21:4071)
+ ld a, $1
+ ld [wJumptableIndex], a
+ ret
+
+Print_InitPrinterHandshake: ; 84077 (21:4077)
+ 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: ; 84099 (21:4099)
+ call Printer_ResetData
+ ; check ???
+ 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, (40 tiles) % $100
+ ld [wPrinterSendByteCounter], a
+ ld a, (40 tiles) / $100
+ 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: ; 840c5 (21:40c5)
+ ; 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: ; 840de (21:40de)
+ call Printer_ResetData
+ ld hl, PrinterDataPacket2 ; signal request print
+ call Printer_CopyPacket
+ ; prepare to send 1 tile
+ call Printer_StageHeaderForSend
+ ld a, 4 % $100
+ ld [wPrinterSendByteCounter], a
+ ld a, 4 / $100
+ 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: ; 84103 (21:4103)
+ 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: ; 84120 (21:4120)
+ ld hl, wPrinterSerialFrameDelay
+ inc [hl]
+ ld a, [hl]
+ cp $6
+ ret c
+ xor a
+ ld [hl], a
+ call Printer_NextSection
+ ret
+
+Printer_WaitSerialAndLoopBack2: ; 8412e (21:412e)
+ 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: ; 84143 (21:4143)
+ 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: ; 84180 (21:4180)
+ 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_WaitLoopBack
+ ld [wJumptableIndex], a
+ ret
+
+Printer_WaitUntilFinished: ; 841a1 (21:41a1)
+ ld a, [wPrinterOpcode]
+ and a
+ ret nz
+ ld a, [wPrinterStatusFlags]
+ and $f3
+ ret nz
+ call Printer_NextSection
+ ret
+
+Printer_WaitLoopBack: ; 841b0 (21:41b0)
+ call Printer_NextSection
+Printer_WaitLoopBack_: ; 841b3 (21:41b3)
+ ld a, [wPrinterOpcode]
+ and a
+ ret nz
+ ld a, [wPrinterStatusFlags]
+ and $f0
+ ret nz
+ xor a
+ ld [wJumptableIndex], a
+ ret
+
+Printer_WaitHandshake: ; 841c3 (21:41c3)
+.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
+ ld [rSB], a
+ ld a, $1
+ ld [rSC], a
+ ld a, $81
+ ld [rSC], a
+ ret
+
+Printer_CopyPacket: ; 841e2 (21:41e2)
+ ld a, [hli]
+ ld [wca82], a
+ ld a, [hli]
+ ld [wca83], a
+ ld a, [hli]
+ ld [wca84], a
+ ld a, [hli]
+ ld [wca85], a
+ ld a, [hli]
+ ld [wPrinterChecksum], a
+ ld a, [hl]
+ ld [wPrinterChecksum + 1], a
+ ret
+
+Printer_ResetData: ; 841fb (21:41fb)
+ xor a
+ ld hl, wca82
+ 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, wGameboyPrinterRAM
+ ld bc, wGameboyPrinter2bppSourceEnd - wGameboyPrinter2bppSource
+ call Printer_ByteFill
+ ret
+
+Printer_ComputeChecksum: ; 84219 (21:4219)
+ ld hl, 0
+ ld bc, 4
+ ld de, wca82
+ 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: ; 8423c (21:423c)
+.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: ; 84249 (21:4249)
+ ld a, $1
+ ld [wGameboyPrinter2bppSource + 0], a
+ ld a, [wcbfa]
+ ld [wGameboyPrinter2bppSource + 1], a
+ ld a, %11100100
+ ld [wGameboyPrinter2bppSource + 2], a
+ ld a, [wGBPrinterSettings]
+ ld [wGameboyPrinter2bppSource + 3], a
+ ret
+
+Printer_Convert2RowsTo2bpp: ; 84260 (21:4260)
+ ; 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: ; 842ab
+ 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
+; 842b7
+
+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: ; unused
+ db 8, 0, $00, 0
+ dw 8
+PrinterDataPacket6: ; unused
+ db 15, 0, $00, 0
+ dw 15
+; 842db
+
+_PrinterReceive:: ; 842db
+ 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]
+; 842ea
+
+
+.Jumptable: ; 842ea (21:42ea)
+ dw Printer_DoNothing ; 00
+
+ dw Printer_Send0x33 ; 01
+ dw Printer_Sendwca82 ; 02
+ dw Printer_Sendwca83 ; 03
+ dw Printer_Sendwca84 ; 04
+ dw Printer_Sendwca85 ; 05
+ dw Printer_SendNextByte ; 06
+ dw Printer_SendwPrinterChecksumLo ; 07
+ dw Printer_SendwPrinterChecksumHi ; 08
+ dw Printer_Send0x00 ; 09
+ dw Printer_ReceiveTowPrinterHandshakeAndSend0x00 ; 0a
+ dw Printer_ReceiveTowPrinterStatusFlagsAndExitSendLoop ; 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 ; 13
+ dw Printer_ReceiveTowPrinterHandshakeAndSend0x00 ; 14
+ dw Printer_ReceiveTowPrinterStatusFlagsAndExitSendLoop_ ; 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 ; 1d
+ dw Printer_ReceiveTowPrinterHandshakeAndSend0x00 ; 1e
+ dw Printer_ReceiveTowPrinterStatusFlagsAndExitSendLoop ; 1f
+
+
+Printer_NextInstruction: ; 8432a (21:432a)
+ ld hl, wPrinterOpcode
+ inc [hl]
+ ret
+
+Printer_DoNothing: ; 8432f (21:432f)
+ ret
+
+Printer_Send0x33: ; 84330 (21:4330)
+ ld a, $33
+ call Printer_SerialSend
+ call Printer_NextInstruction
+ ret
+
+Printer_Sendwca82: ; 84339 (21:4339)
+ ld a, [wca82]
+ call Printer_SerialSend
+ call Printer_NextInstruction
+ ret
+
+Printer_Sendwca83: ; 84343 (21:4343)
+ ld a, [wca83]
+ call Printer_SerialSend
+ call Printer_NextInstruction
+ ret
+
+Printer_Sendwca84: ; 8434d (21:434d)
+ ld a, [wca84]
+ call Printer_SerialSend
+ call Printer_NextInstruction
+ ret
+
+Printer_Sendwca85: ; 84357 (21:4357)
+ ld a, [wca85]
+ call Printer_SerialSend
+ call Printer_NextInstruction
+ ret
+
+Printer_SendNextByte: ; 84361 (21:4361)
+ ; 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: ; 8438b (21:438b)
+ ld a, [wPrinterChecksum]
+ call Printer_SerialSend
+ call Printer_NextInstruction
+ ret
+
+Printer_SendwPrinterChecksumHi: ; 84395 (21:4395)
+ ld a, [wPrinterChecksum + 1]
+ call Printer_SerialSend
+ call Printer_NextInstruction
+ ret
+
+Printer_Send0x00: ; 8439f (21:439f)
+ ld a, $0
+ call Printer_SerialSend
+ call Printer_NextInstruction
+ ret
+
+Printer_ReceiveTowPrinterHandshakeAndSend0x00: ; 843a8 (21:43a8)
+ ld a, [rSB]
+ ld [wPrinterHandshake], a
+ ld a, $0
+ call Printer_SerialSend
+ call Printer_NextInstruction
+ ret
+
+Printer_ReceiveTowPrinterStatusFlagsAndExitSendLoop: ; 843b6 (21:43b6)
+ ld a, [rSB]
+ ld [wPrinterStatusFlags], a
+ xor a
+ ld [wPrinterOpcode], a
+ ret
+
+Printer_Send0x0f: ; 843c0 (21:43c0)
+ ld a, $f
+ call Printer_SerialSend
+ call Printer_NextInstruction
+ ret
+
+Printer_Send0x00_: ; 843c9 (21:43c9)
+ ld a, $0
+ call Printer_SerialSend
+ call Printer_NextInstruction
+ ret
+
+Printer_Send0x08: ; 843d2 (21:43d2)
+ ld a, $8
+ call Printer_SerialSend
+ call Printer_NextInstruction
+ ret
+
+Printer_SerialSend: ; 843db (21:43db)
+ ld [rSB], a
+ ld a, $1 ; switch to internal clock
+ ld [rSC], a
+ ld a, $81 ; start transfer
+ ld [rSC], a
+ ret
+
+Printer_ReceiveTowPrinterStatusFlagsAndExitSendLoop_: ; 843e6 (21:43e6)
+ ld a, [rSB]
+ ld [wPrinterStatusFlags], a
+ xor a
+ ld [wPrinterOpcode], a
+ ret
--- a/engine/stats_screen.asm
+++ b/engine/stats_screen.asm
@@ -222,7 +222,7 @@
StatsScreen_CopyToTempMon: ; 4ddf2 (13:5df2)
ld a, [MonType]
- cp BREEDMON
+ cp TEMPMON
jr nz, .breedmon
ld a, [wBufferMon]
ld [CurSpecies], a
@@ -249,7 +249,7 @@
StatsScreen_GetJoypad: ; 4de2c (13:5e2c)
call GetJoypad
ld a, [MonType]
- cp BREEDMON
+ cp TEMPMON
jr nz, .notbreedmon
push hl
push de
@@ -1144,7 +1144,7 @@
ld h, [hl]
ld l, a
ld a, [MonType]
- cp BREEDMON
+ cp TEMPMON
ret z
ld a, [CurPartyMon]
jp SkipNames
--- a/event/daycare.asm
+++ b/event/daycare.asm
@@ -723,7 +723,7 @@
ld a, [wBreedMon2Species]
cp DITTO
jr z, .GotDVs
- ld a, BREEDMON
+ ld a, TEMPMON
ld [MonType], a
push hl
callba GetGender
--- a/event/halloffame.asm
+++ b/event/halloffame.asm
@@ -495,7 +495,7 @@
call GetBasePokemonName
hlcoord 7, 13
call PlaceString
- ld a, BREEDMON
+ ld a, TEMPMON
ld [MonType], a
callba GetGender
ld a, " "
--- a/home/handshake.asm
+++ b/home/handshake.asm
@@ -13,16 +13,17 @@
AskSerial:: ; 2063
; send out a handshake while serial int is off
- ld a, [wc2d4]
+ ld a, [wPrinterConnectionOpen]
bit 0, a
ret z
- ld a, [wc2d5]
+; if we're still interpreting data, don't try to receive
+ ld a, [wPrinterOpcode]
and a
ret nz
; once every 6 frames
- ld hl, wca8a
+ ld hl, wHandshakeFrameDelay
inc [hl]
ld a, [hl]
cp 6
@@ -31,8 +32,8 @@
xor a
ld [hl], a
- ld a, $c
- ld [wc2d5], a
+ ld a, 12
+ ld [wPrinterOpcode], a
; handshake
ld a, $88
--- a/home/serial.asm
+++ b/home/serial.asm
@@ -10,7 +10,7 @@
and a
jr nz, .mobile
- ld a, [wc2d4]
+ ld a, [wPrinterConnectionOpen]
bit 0, a
jr nz, .printer
--- a/items/item_effects.asm
+++ b/items/item_effects.asm
@@ -3242,11 +3242,11 @@
ld hl, TempMonMoves ; Wasted cycles
dec a
- jr z, .got_nonpartymon ; BREEDMON
+ jr z, .got_nonpartymon ; TEMPMON
ld hl, BattleMonMoves ; WILDMON
-.got_nonpartymon ; BOXMON, BREEDMON, WILDMON
+.got_nonpartymon ; BOXMON, TEMPMON, WILDMON
call GetMthMoveOfCurrentMon
jr .gotdatmove
--- a/main.asm
+++ b/main.asm
@@ -3643,7 +3643,7 @@
jr z, .otpartymon
cp BOXMON
jr z, .boxmon
- cp BREEDMON
+ cp TEMPMON
jr z, .breedmon
; WILDMON
--- a/misc/mobile_22.asm
+++ b/misc/mobile_22.asm
@@ -96,14 +96,14 @@
ret
Function891ab: ; 891ab
- call Function89240
+ call Mobile22_SetBGMapMode1
callba ReloadMapPart
- call Function8923c
+ call Mobile22_SetBGMapMode0
ret
; 891b8
Function891b8: ; 891b8
- call Function8923c
+ call Mobile22_SetBGMapMode0
hlcoord 0, 0
ld a, " "
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
@@ -129,7 +129,7 @@
ret
Function891de: ; 891de
- call Function8923c
+ call Mobile22_SetBGMapMode0
call ClearPalettes
hlcoord 0, 0, AttrMap
ld a, $7
@@ -197,18 +197,18 @@
pop de
ret
-Function89235: ; 89235 (22:5235)
+Mobile22_ButtonSound: ; 89235 (22:5235)
call JoyWaitAorB
call PlayClickSFX
ret
-Function8923c: ; 8923c
+Mobile22_SetBGMapMode0: ; 8923c
xor a
ld [hBGMapMode], a
ret
; 89240
-Function89240: ; 89240
+Mobile22_SetBGMapMode1: ; 89240
ld a, $1
ld [hBGMapMode], a
ret
@@ -253,7 +253,7 @@
pop af
ld [wMenuCursorBuffer], a
call PushWindow
- call Function8923c
+ call Mobile22_SetBGMapMode0
call Function89209
call VerticalMenu
push af
@@ -1796,7 +1796,7 @@
; 89b07 (22:5b07)
Function89b07: ; 89b07
- call Function8923c
+ call Mobile22_SetBGMapMode0
call DelayFrame
callba Function4a3a7
ret
@@ -1824,7 +1824,7 @@
ret
Function89b3b: ; 89b3b (22:5b3b)
- call Function8923c
+ call Mobile22_SetBGMapMode0
callba Function48cda
ret
@@ -2152,37 +2152,41 @@
ret
Function89d0d: ; 89d0d (22:5d0d)
- call Function8923c
+ call Mobile22_SetBGMapMode0
ld a, [rSVBK]
push af
ld a, $5
ld [rSVBK], a
- ld c, $8
+
+ ld c, 8
ld de, UnknBGPals
-.asm_89d1c
+.loop
push bc
- ld hl, Palette_89d4e
- ld bc, $8
+ ld hl, .Palette1
+ ld bc, 1 palettes
call CopyBytes
pop bc
dec c
- jr nz, .asm_89d1c
- ld hl, Palette_89d56
- ld de, wd010
- ld bc, $8
+ jr nz, .loop
+
+ ld hl, .Palette2
+ ld de, UnknBGPals + 2 palettes
+ ld bc, 1 palettes
call CopyBytes
+
pop af
ld [rSVBK], a
+
call SetPalettes
- callba Function845db
- call Function89240
- ld c, $18
+ callba PrintMail_
+ call Mobile22_SetBGMapMode1
+ ld c, 24
call DelayFrames
call RestartMapMusic
ret
; 89d4e (22:5d4e)
-Palette_89d4e: ; 89d4e
+.Palette1: ; 89d4e
RGB 31, 31, 31
RGB 19, 19, 19
RGB 15, 15, 15
@@ -2189,7 +2193,7 @@
RGB 00, 00, 00
; 89d56
-Palette_89d56: ; 89d56
+.Palette2: ; 89d56
RGB 31, 31, 31
RGB 19, 19, 19
RGB 19, 19, 19
@@ -2201,7 +2205,7 @@
call CopyMenuDataHeader
pop af
ld [wMenuCursorBuffer], a
- call Function8923c
+ call Mobile22_SetBGMapMode0
call PlaceVerticalMenuItems
call InitVerticalMenuCursor
ld hl, w2DMenuFlags1
@@ -2210,7 +2214,7 @@
Function89d75: ; 89d75 (22:5d75)
push hl
- call Function8923c
+ call Mobile22_SetBGMapMode0
call _hl_
callba Mobile_OpenAndCloseMenu_HDMATransferTileMapAndAttrMap
pop hl
@@ -2218,13 +2222,13 @@
Function89d85: ; 89d85 (22:5d85)
push hl
- call Function8923c
+ call Mobile22_SetBGMapMode0
call _hl_
call CGBOnly_LoadEDTile
pop hl
asm_89d90: ; 89d90 (22:5d90)
- call Function8923c
+ call Mobile22_SetBGMapMode0
push hl
call _hl_
call Function89dab
@@ -2242,9 +2246,9 @@
ret
Function89dab: ; 89dab (22:5dab)
- call Function8923c
+ call Mobile22_SetBGMapMode0
callba MobileMenuJoypad
- call Function8923c
+ call Mobile22_SetBGMapMode0
ld a, c
ld hl, wMenuJoypadFilter
and [hl]
@@ -2422,7 +2426,7 @@
Function89ee1: ; 89ee1 (22:5ee1)
call ClearBGPalettes
call Function893e2
- call Function8923c
+ call Mobile22_SetBGMapMode0
callba Function4a3a7
callba MG_Mobile_Layout_CreatePalBoxes
hlcoord 1, 0
@@ -2628,7 +2632,7 @@
call Function89a0c
call CloseSRAM
call Function891ab
- call Function89235
+ call Mobile22_ButtonSound
jp Function89e36
Function8a03d: ; 8a03d (22:603d)
@@ -2683,7 +2687,7 @@
jp Function89e36
Function8a0a1: ; 8a0a1 (22:60a1)
- call Function8923c
+ call Mobile22_SetBGMapMode0
push bc
call Function8a0c9
ld e, $6
@@ -2784,7 +2788,7 @@
ld hl, MenuDataHeader_0x8a176
call LoadMenuDataHeader
.asm_8a121
- call Function8923c
+ call Mobile22_SetBGMapMode0
call Function8a17b
jr c, .asm_8a16b
ld a, [wMenuCursorY]
@@ -2951,7 +2955,7 @@
Function8a262: ; 8a262 (22:6262)
call ClearBGPalettes
call Function893e2
- call Function8923c
+ call Mobile22_SetBGMapMode0
callba Function4a3a7
callba MG_Mobile_Layout_CreatePalBoxes
hlcoord 1, 0
@@ -3045,7 +3049,7 @@
Function8a31c: ; 8a31c (22:631c)
push bc
- call Function8923c
+ call Mobile22_SetBGMapMode0
callba Function4a3a7
callba MG_Mobile_Layout_CreatePalBoxes
hlcoord 1, 0
@@ -3063,7 +3067,7 @@
set 7, [hl]
.asm_8a34e
call Function8a3a2
- call Function8923c
+ call Mobile22_SetBGMapMode0
call Function8a453
call Function8a4d3
call Function8a4fc
@@ -3588,7 +3592,7 @@
call Function8a765
call CloseSRAM
jr nc, .asm_8a73f
- call Function8923c
+ call Mobile22_SetBGMapMode0
call Function89448
call Function89a23
hlcoord 1, 13
@@ -3807,7 +3811,7 @@
call Function892b4
call CloseSRAM
call Function89a23
- call Function8923c
+ call Mobile22_SetBGMapMode0
hlcoord 1, 13
ld de, String_8a926
call PlaceString
@@ -4080,7 +4084,7 @@
hlcoord 1, 13
call PlaceString
call WaitBGMap
- call Function89235
+ call Mobile22_ButtonSound
and a
ret
@@ -4368,7 +4372,7 @@
jr z, .asm_8ad0b
cp $2
jr z, .asm_8ad37
- call Function8923c
+ call Mobile22_SetBGMapMode0
push bc
hlcoord 0, 12
ld b, $4
@@ -4380,7 +4384,7 @@
ld a, $2
call Function8925e
jr c, .asm_8ad87
- call Function8923c
+ call Mobile22_SetBGMapMode0
hlcoord 0, 12
ld b, $4
ld c, $12
--- a/misc/mobile_22_2.asm
+++ b/misc/mobile_22_2.asm
@@ -255,7 +255,7 @@
ld d, $0
call Function8b385
.asm_8b46e
- call Function8923c
+ call Mobile22_SetBGMapMode0
call Function8b493
call Function8b4cc
call Function8b518
@@ -276,7 +276,7 @@
Function8b493: ; 8b493 (22:7493)
push bc
- call Function8923c
+ call Mobile22_SetBGMapMode0
call Function8b521
ld hl, Jumptable_8b4a0
pop bc
@@ -657,7 +657,7 @@
; 8b703
Function8b703: ; 8b703
- call Function8923c
+ call Mobile22_SetBGMapMode0
push hl
ld a, $c
ld [hli], a
@@ -733,7 +733,7 @@
; 8b75d
Function8b75d: ; 8b75d
- call Function8923c
+ call Mobile22_SetBGMapMode0
hlcoord 0, 0
ld a, $1
ld bc, SCREEN_WIDTH
--- a/misc/printer_77.asm
+++ b/misc/printer_77.asm
@@ -1,27 +1,27 @@
PrintPage1: ; 1dc1b0
hlcoord 0, 0
- ld de, wca90
+ decoord 0, 0, wPrinterTileMapBuffer
ld bc, 17 * SCREEN_WIDTH
call CopyBytes
- ld hl, wcab5
+ hlcoord 17, 1, wPrinterTileMapBuffer
ld a, $62
ld [hli], a
inc a
ld [hl], a
- ld hl, wcac9
+ hlcoord 17, 2, wPrinterTileMapBuffer
ld a, $64
ld [hli], a
inc a
ld [hl], a
- ld hl, wcb45
+ hlcoord 1, 9, wPrinterTileMapBuffer
ld a, " "
ld [hli], a
ld [hl], a
- ld hl, wcb59
+ hlcoord 1, 10, wPrinterTileMapBuffer
ld a, $61
ld [hli], a
ld [hl], a
- ld hl, wcb6e
+ hlcoord 2, 11, wPrinterTileMapBuffer
lb bc, 5, 18
call ClearBox
ld a, [wd265]
@@ -34,9 +34,9 @@
callba GetDexEntryPagePointer
pop af
ld a, b
- ld hl, wcb6d
+ hlcoord 1, 11, wPrinterTileMapBuffer
call nz, FarString
- ld hl, wcaa3
+ hlcoord 19, 0, wPrinterTileMapBuffer
ld [hl], $35
ld de, SCREEN_WIDTH
add hl, de
@@ -51,19 +51,19 @@
; 1dc213
PrintPage2: ; 1dc213
- ld hl, wca90
- ld bc, $a0
+ hlcoord 0, 0, wPrinterTileMapBuffer
+ ld bc, 8 * SCREEN_WIDTH
ld a, " "
call ByteFill
- ld hl, wca90
+ hlcoord 0, 0, wPrinterTileMapBuffer
ld a, $36
- ld b, $6
+ ld b, 6
call .FillColumn
- ld hl, wcaa3
+ hlcoord 19, 0, wPrinterTileMapBuffer
ld a, $37
- ld b, $6
+ ld b, 6
call .FillColumn
- ld hl, wcb08
+ hlcoord 0, 6, wPrinterTileMapBuffer
ld [hl], $38
inc hl
ld a, $39
@@ -70,7 +70,7 @@
ld bc, SCREEN_HEIGHT
call ByteFill
ld [hl], $3a
- ld hl, wcb1c
+ hlcoord 0, 7, wPrinterTileMapBuffer
ld bc, SCREEN_WIDTH
ld a, $32
call ByteFill
@@ -83,7 +83,7 @@
ld c, 2 ; get page 2
callba GetDexEntryPagePointer
pop af
- ld hl, wcaa5
+ hlcoord 1, 1, wPrinterTileMapBuffer
ld a, b
call nz, FarString
ret
@@ -102,29 +102,29 @@
; 1dc275
GBPrinterStrings:
-String_1dc275: db "@"
-String_1dc276: next " CHECKING LINK...@"
-String_1dc289: next " TRANSMITTING...@"
-String_1dc29c: next " PRINTING...@"
-String_1dc2ad:
+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 "@"
-String_1dc2e2:
+GBPrinterString_PrinterError2:
db " Printer Error 2"
next ""
next "Check the Game Boy"
next "Printer Manual."
db "@"
-String_1dc317:
+GBPrinterString_PrinterError3:
db " Printer Error 3"
next ""
next "Check the Game Boy"
next "Printer Manual."
db "@"
-String_1dc34c:
+GBPrinterString_PrinterError4:
db " Printer Error 4"
next ""
next "Check the Game Boy"
@@ -132,7 +132,7 @@
db "@"
; 1dc381
-Function1dc381: ; 1dc381
+PrintPartyMonPage1: ; 1dc381
call ClearBGPalettes
call ClearTileMap
call ClearSprites
@@ -232,7 +232,7 @@
ret
; 1dc47b
-Function1dc47b: ; 1dc47b
+PrintPartyMonPage2: ; 1dc47b
call ClearBGPalettes
call ClearTileMap
call ClearSprites
--- a/wram.asm
+++ b/wram.asm
@@ -157,8 +157,8 @@
wc2cf:: ds 1
wMapTimeOfDay:: ds 1
ds 3
-wc2d4:: ds 1
-wc2d5:: ds 1
+wPrinterConnectionOpen:: ds 1
+wPrinterOpcode:: ds 1
wLastDexEntry:: ds 1
wDisableTextAcceleration:: ds 1
wPreviousLandmark:: ds 1
@@ -897,6 +897,44 @@
OverworldMapEnd::
ds OverworldMap - @
+wGameboyPrinterRAM::
+wGameboyPrinterScreen:: ds SCREEN_HEIGHT * SCREEN_WIDTH ; c800
+wGameboyPrinterScreenEnd:: ; c968
+ ds wGameboyPrinterScreen - @
+wGameboyPrinter2bppSource::
+ ds 40 tiles
+wGameboyPrinter2bppSourceEnd::
+wca80:: ds 1
+wPrinterRowIndex:: ds 1
+wca82:: ds 1
+wca83:: ds 1
+wca84:: ds 1
+wca85:: ds 1
+wPrinterChecksum:: dw ; ca86
+wPrinterHandshake:: ds 1
+wPrinterStatusFlags::
+; bit 7: set if error 1 (battery low)
+; bit 6: set if error 4 (too hot or cold)
+; bit 5: set if error 3 (paper jammed or empty)
+; if this and the previous byte are both $ff: error 2 (connection error)
+ ds 1
+
+wHandshakeFrameDelay:: ds 1
+wPrinterSerialFrameDelay:: ds 1
+wPrinterSendByteOffset:: dw
+wPrinterSendByteCounter:: dw
+
+; tilemap backup?
+wPrinterTileMapBuffer:: ds SCREEN_HEIGHT * SCREEN_WIDTH ; ca90
+wPrinterTileMapBufferEnd::
+wPrinterStatus:: ds 1 ; cbf8
+ ds 1
+wcbfa:: ds 1
+wGBPrinterSettings:: ds 1
+ ds 16
+wGameboyPrinterRAMEnd::
+ ds wGameboyPrinterRAM - @
+
wBillsPCPokemonList:: ; c800
; Pokemon, box number, list index
@@ -1018,44 +1056,14 @@
wca50:: ds 16
wca60:: ds 16
wca70:: ds 16
-wca80:: ds 1
-wca81:: ds 1
-wca82:: ds 1
-wca83:: ds 1
-wca84:: ds 1
-wca85:: ds 1
-wca86:: ds 1
-wca87:: ds 1
-; Gameboy Printer
-wca88:: ds 1
-wca89::
-; bit 7: set if error 1
-; bit 6: set if error 4
-; bit 5: set if error 3
- ds 1
+ ds 35
-wca8a:: ds 1
-wca8b:: ds 1
-wca8c:: ds 1
-wca8d:: ds 1
-wca8e:: ds 1
-wca8f:: ds 1
-
-; tilemap backup?
-wca90:: ds 16
-wcaa0:: ds 3
-wcaa3:: ds 2
-wcaa5:: ds 11
-wcab0:: ds 5
+wcaa3:: ds 2 ; caa3
+wcaa5:: ds 16
wcab5:: ds 10
-wcabf:: ds 1
-wcac0:: ds 9
-wcac9:: ds 7
-wcad0:: ds 16
-wcae0:: ds 16
-wcaf0:: ds 16
-wcb00:: ds 8
+wcabf:: ds 10
+wcac9:: ds 63
wcb08:: ds 6
wcb0e:: ds 5
wcb13:: ds 9
@@ -1078,11 +1086,8 @@
wcbe8:: dw
wLinkOTPartyMonTypes::
ds 2 * PARTY_LENGTH
- ds 2
+ ds 84
-wcbf8:: ds 2
-wcbfa:: ds 1
-wcbfb:: ds 79
wcc4a:: ds 22
wcc60:: ds 1
wcc61:: ds 1
@@ -1295,6 +1300,7 @@
wUnownPuzzleCursorPosition::
wCardFlipCursorX::
wCurrPocket::
+wPrinterQueueLength::
wcf65:: ds 1
wCreditsLYOverride::
wTitleScreenTimerHi::
@@ -1544,6 +1550,7 @@
wCurrentRadioLine::
wMovementBufferCount::
wMartItem1BCD::
+wWhichBoxMonToPrint::
ds 1
wd003::
LuckyNumberDigit2Buffer::
@@ -1551,6 +1558,7 @@
wNextRadioLine::
wMovementBufferPerson::
wPlaceBallsDirection::
+wFinishedPrintingBox::
ds 1
wd004::
LuckyNumberDigit3Buffer::
@@ -1557,6 +1565,7 @@
PhoneCallerHi::
wRadioTextDelay::
wTrainerHUDTiles::
+wAddrOfBoxToPrint::
ds 1
wd005::
LuckyNumberDigit4Buffer::
@@ -1569,9 +1578,11 @@
LuckyNumberDigit5Buffer::
EndFlypoint:: ; d006
wOaksPkmnTalkSegmentCounter::
+wBankOfBoxToPrint::
ds 1
wd007::
+wWhichBoxToPrint::
MovementBuffer:: ; d007
ds 1