Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Label more stuff and document printer functions #143

Merged
merged 1 commit into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/constants/duel_constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ DEF PRIZES_5 EQU $05
DEF PRIZES_6 EQU $06

; constants to use as input to LookForCardInDeck
DEF SEARCHEFFECT_CARD_ID EQU $0
DEF SEARCHEFFECT_NIDORAN EQU $1
DEF SEARCHEFFECT_BASIC_FIGHTING EQU $2
DEF SEARCHEFFECT_BASIC_ENERGY EQU $3
DEF SEARCHEFFECT_POKEMON EQU $4
const_def
const SEARCHEFFECT_CARD_ID ; $0
const SEARCHEFFECT_NIDORAN ; $1
const SEARCHEFFECT_BASIC_FIGHTING ; $2
const SEARCHEFFECT_BASIC_ENERGY ; $3
const SEARCHEFFECT_POKEMON ; $4
2 changes: 1 addition & 1 deletion src/engine/duel/core.asm
Original file line number Diff line number Diff line change
Expand Up @@ -8388,7 +8388,7 @@ Func_74dc:
ret c ; card not found
push de
ld a, e
call Func_758a
call RequestToPrintCard
pop de
inc de
jr .card_loop
Expand Down
16 changes: 8 additions & 8 deletions src/engine/input_name.asm
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ ENDR
; if pressed, set the carry bit on.
NamingScreen_CheckButtonState:
xor a
ld [wPlaysSfx], a
ld [wMenuInputSFX], a
ldh a, [hDPadHeld]
or a
jp z, .no_press
Expand Down Expand Up @@ -416,8 +416,8 @@ NamingScreen_CheckButtonState:
ld a, $06
cp d
jp z, NamingScreen_CheckButtonState
ld a, $01
ld [wPlaysSfx], a
ld a, SFX_01
ld [wMenuInputSFX], a
.no_press
ldh a, [hKeysPressed]
and A_BUTTON | B_BUTTON
Expand All @@ -433,7 +433,7 @@ NamingScreen_CheckButtonState:
scf
ret
.asm_69ef
ld a, [wPlaysSfx]
ld a, [wMenuInputSFX]
or a
jr z, .asm_69f8
call PlaySFX
Expand Down Expand Up @@ -1143,7 +1143,7 @@ Func_1aec3:

Func_1aefb:
xor a
ld [wPlaysSfx], a
ld [wMenuInputSFX], a
ldh a, [hDPadHeld]
or a
jp z, .asm_6f73
Expand Down Expand Up @@ -1216,8 +1216,8 @@ Func_1aefb:
ld a, $02
cp d
jp z, Func_1aefb
ld a, $01
ld [wPlaysSfx], a
ld a, SFX_01
ld [wMenuInputSFX], a
.asm_6f73
ldh a, [hKeysPressed]
and $03
Expand All @@ -1233,7 +1233,7 @@ Func_1aefb:
scf
ret
.asm_6f89
ld a, [wPlaysSfx]
ld a, [wMenuInputSFX]
or a
jr z, .asm_6f92
call PlaySFX
Expand Down
89 changes: 48 additions & 41 deletions src/engine/link/printer.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
; if there's an error in connection,
; show Printer Not Connected scene with error message
_PreparePrinterConnection:
ld bc, $0
lb de, PRINTERPKT_DATA, $0
ld bc, 0
lb de, PRINTERPKT_DATA, FALSE
call SendPrinterPacket
ret nc ; return if no error

Expand Down Expand Up @@ -80,7 +80,7 @@ ShowPrinterConnectionErrorScene:
ret

; main card printer function
Func_19eb4:
_RequestToPrintCard:
ld e, a
ld d, $0
call LoadCardDataToBuffer1_FromCardID
Expand All @@ -97,9 +97,9 @@ Func_19eb4:
call DrawWideTextBox_PrintText
call EnableLCD
call PrepareForPrinterCommunications
call DrawTopCardInfoInSRAMGfxBuffer0
call .DrawTopCardInfoInSRAMGfxBuffer0
call Func_19f87
call DrawCardPicInSRAMGfxBuffer2
call .DrawCardPicInSRAMGfxBuffer2
call Func_19f99
jr c, .error
call DrawBottomCardInfoInSRAMGfxBuffer0
Expand All @@ -114,14 +114,14 @@ Func_19eb4:
call ResetPrinterCommunicationSettings
jp HandlePrinterError

DrawCardPicInSRAMGfxBuffer2:
; draw card's picture in sGfxBuffer2
.DrawCardPicInSRAMGfxBuffer2:
ld hl, wLoadedCard1Gfx
ld a, [hli]
ld h, [hl]
ld l, a
ld de, sGfxBuffer2
call Func_37a5
; draw card's picture in sGfxBuffer2
ld a, $40
lb hl, 12, 1
lb de, 2, 68
Expand All @@ -133,7 +133,7 @@ DrawCardPicInSRAMGfxBuffer2:
; the card's information in sGfxBuffer0
; this includes card's type, lv, HP and attacks if Pokemon card
; or otherwise just the card's name and type symbol
DrawTopCardInfoInSRAMGfxBuffer0:
.DrawTopCardInfoInSRAMGfxBuffer0:
call Func_1a025
call Func_212f

Expand Down Expand Up @@ -187,12 +187,12 @@ DrawTopCardInfoInSRAMGfxBuffer0:

Func_19f87:
call TryInitPrinterCommunications
ret c
ret c ; aborted
ld hl, sGfxBuffer0
call Func_1a0cc
call SendTilesToPrinter
ret c
call Func_1a0cc
call Func_1a111
call SendTilesToPrinter
call SendPrinterInstructionPacket_1Sheet
ret

Func_19f99:
Expand All @@ -201,11 +201,11 @@ Func_19f99:
ld hl, sGfxBuffer0 + $8 tiles
ld c, $06
.asm_19fa2
call Func_1a0cc
call SendTilesToPrinter
ret c
dec c
jr nz, .asm_19fa2
call Func_1a111
call SendPrinterInstructionPacket_1Sheet
ret

; writes the tiles necessary to draw
Expand Down Expand Up @@ -267,11 +267,11 @@ Func_1a011:
ld hl, sGfxBuffer0
ld c, $05
.asm_1a01a
call Func_1a0cc
call SendTilesToPrinter
ret c
dec c
jr nz, .asm_1a01a
call Func_1a108
call SendPrinterInstructionPacket_1Sheet_3LineFeeds
ret

; calls setup text and sets wTilePatternSelector
Expand All @@ -291,7 +291,7 @@ PrepareForPrinterCommunications:
call SwitchToCGBNormalSpeed
call ResetSerial
ld a, $10
ld [wce9b], a
ld [wPrinterNumberLineFeeds], a
call EnableSRAM
ld a, [sPrinterContrastLevel]
ld [wPrinterContrastLevel], a
Expand Down Expand Up @@ -331,8 +331,8 @@ ResetPrinterCommunicationSettings:

; send some bytes through serial
Func_1a080: ; unreferenced
ld bc, $0
lb de, PRINTERPKT_NUL, $0
ld bc, 0
lb de, PRINTERPKT_NUL, FALSE
jp SendPrinterPacket

; tries initiating the communications for
Expand All @@ -347,16 +347,16 @@ TryInitPrinterCommunications:
ldh a, [hKeysHeld]
and B_BUTTON
jr nz, .b_button
ld bc, $0
lb de, PRINTERPKT_NUL, $0
ld bc, 0
lb de, PRINTERPKT_NUL, FALSE
call SendPrinterPacket
jr c, .delay
and (1 << PRINTER_STATUS_BUSY) | (1 << PRINTER_STATUS_PRINTING)
jr nz, .wait_input

.init
ld bc, $0
lb de, PRINTERPKT_INIT, $0
ld bc, 0
lb de, PRINTERPKT_INIT, FALSE
call SendPrinterPacket
jr nc, .no_carry
ld hl, wPrinterInitAttempts
Expand Down Expand Up @@ -387,7 +387,8 @@ TryInitPrinterCommunications:
; loads tiles given by map in hl to sGfxBuffer5
; copies first 20 tiles, then offsets by 2 tiles
; and copies another 20
Func_1a0cc:
; compresses this data and sends it to printer
SendTilesToPrinter:
push bc
ld de, sGfxBuffer5
call .Copy20Tiles
Expand Down Expand Up @@ -438,33 +439,40 @@ Func_1a0cc:
pop hl
ret

Func_1a108:
SendPrinterInstructionPacket_1Sheet_3LineFeeds:
call GetPrinterContrastSerialData
push hl
lb hl, $3, $1
lb hl, 3, 1
jr SendPrinterInstructionPacket

Func_1a111:
; uses wPrinterNumberLineFeeds to get number
; of line feeds to insert before print
SendPrinterInstructionPacket_1Sheet:
call GetPrinterContrastSerialData
push hl
ld hl, wce9b
ld hl, wPrinterNumberLineFeeds
ld a, [hl]
ld [hl], $00
ld h, a
ld l, $01
ld l, 1
; fallthrough

; h = number of line feeds where:
; high nybble is number of line feeds before printing
; low nybble is number of line feeds after printing
; l = number of sheets
; expects printer contrast information to be on stack
SendPrinterInstructionPacket:
push hl
ld bc, $0
lb de, PRINTERPKT_DATA, $0
ld bc, 0
lb de, PRINTERPKT_DATA, FALSE
call SendPrinterPacket
jr c, .asm_1a135
jr c, .aborted
ld hl, sp+$00 ; contrast level bytes
ld bc, $4 ; instruction packets are 4 bytes in size
lb de, PRINTERPKT_PRINT_INSTRUCTION, $0
ld bc, 4 ; instruction packets are 4 bytes in size
lb de, PRINTERPKT_PRINT_INSTRUCTION, FALSE
call SendPrinterPacket
.asm_1a135
.aborted
pop hl
pop hl
ret
Expand All @@ -479,7 +487,7 @@ GetPrinterContrastSerialData:
ld hl, .contrast_level_data
add hl, de
ld h, [hl]
ld l, $e4
ld l, %11100100 ; palette format
ret

.contrast_level_data
Expand Down Expand Up @@ -586,9 +594,8 @@ SendCardListToPrinter:
.skip_load_gfx
call TryInitPrinterCommunications
ret c
call Func_1a108
call SendPrinterInstructionPacket_1Sheet_3LineFeeds
ret
; 0z1a1ff
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol


; increases printer horizontal offset by 2
AddToPrinterGfxBuffer:
Expand Down Expand Up @@ -616,11 +623,11 @@ LoadGfxBufferForPrinter:
ld c, a
ld hl, sGfxBuffer0
.loop_gfx_buffer
call Func_1a0cc
call SendTilesToPrinter
jr c, .set_carry
dec c
jr nz, .loop_gfx_buffer
call Func_1a111
call SendPrinterInstructionPacket_1Sheet
jr c, .set_carry

call ClearPrinterGfxBuffer
Expand Down Expand Up @@ -1030,7 +1037,7 @@ CompressDataForPrinterSerialTransfer:
ld c, l
ld b, h
ld hl, sGfxBuffer5 + $28 tiles
lb de, PRINTERPKT_DATA, $1
lb de, PRINTERPKT_DATA, TRUE
ret

; checks whether the next byte sequence in hl, up to c bytes, can be compressed
Expand Down
Loading