summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTauwasser <Tauwasser@tauwasser.eu>2018-06-02 00:30:32 +0200
committerTauwasser <Tauwasser@tauwasser.eu>2018-06-02 00:30:32 +0200
commitdd8ff58554b17ea73b152973dc4be0003d3ea89b (patch)
treea83cfee0d0b5b7be43e42b1e847f63a04520e054
parent454c4632146ff34353b6ba1a44e22bcaa76e7f4d (diff)
home, macros: disassemble text-related functions and add text fn macros
Signed-off-by: Tauwasser <Tauwasser@tauwasser.eu>
-rw-r--r--home/print_bcd.asm105
-rw-r--r--home/text.asm368
-rw-r--r--macros.asm1
-rw-r--r--macros/text.asm133
-rw-r--r--shim.sym5
5 files changed, 608 insertions, 4 deletions
diff --git a/home/print_bcd.asm b/home/print_bcd.asm
new file mode 100644
index 0000000..fa8d825
--- /dev/null
+++ b/home/print_bcd.asm
@@ -0,0 +1,105 @@
+INCLUDE "constants.asm"
+
+SECTION "BCD Finalize", ROM0[$33a3]
+
+PrintLetterDelay:: ; 33a3 (0:33a3)
+ ld a, [wce5f]
+ bit 4, a
+ ret nz
+ ld a, [wTextBoxFlags]
+ bit 1, a
+ ret z
+ push hl
+ push de
+ push bc
+ ld a, [wTextBoxFlags]
+ bit 0, a
+ jr z, .waitOneFrame
+ ld a, [wce5f]
+ and $07
+ jr .initFrameCnt
+.waitOneFrame
+ ld a, $01
+.initFrameCnt
+ ld [wVBlankJoyFrameCounter], a
+.checkButtons
+ call GetJoypad
+ ldh a, [hJoyState]
+.checkAButton
+ bit 0, a ; is the A button pressed?
+ jr z, .checkBButton
+ jr .endWait
+.checkBButton
+ bit 1, a ; is the B button pressed?
+ jr z, .buttonsNotPressed
+.endWait
+ call DelayFrame
+ jr .done
+.buttonsNotPressed ; if neither A nor B is pressed
+ ld a, [wVBlankJoyFrameCounter]
+ and a
+ jr nz, .checkButtons
+.done
+ pop bc
+ pop de
+ pop hl
+ ret
+; 0x33e3
+
+SECTION "BCD Functions", ROM0[$3ab2]
+
+; function to print a BCD (Binary-coded decimal) number
+; de = address of BCD number
+; hl = destination address
+; c = flags and length
+; bit 7: if set, do not print leading zeroes
+; if unset, print leading zeroes
+; bit 6: if set, left-align the string (do not pad empty digits with spaces)
+; if unset, right-align the string
+; bits 0-5: length of BCD number in bytes
+; Note that bits 5 and 7 are modified during execution. The above reflects
+; their meaning at the beginning of the functions's execution.
+PrintBCDNumber:: ; 3ab2 (0:3ab2)
+ ld b, c ; save flags in b
+ res 7, c
+ res 6, c ; c now holds the length
+.loop
+ ld a, [de]
+ swap a
+ call PrintBCDDigit
+ ld a, [de]
+ call PrintBCDDigit
+ inc de
+ dec c
+ jr nz, .loop
+ bit 7, b ; were any non-zero digits printed?
+ jr z, .done
+.numberEqualsZero ; if every digit of the BCD number is zero
+ bit 6, b
+ jr nz, .skipRightAlignmentAdjustment
+ dec hl ; if the string is right-aligned, it needs
+.skipRightAlignmentAdjustment ;to be moved back one space
+ ld [hl], "0"
+ call PrintLetterDelay
+ inc hl
+.done
+ ret
+
+PrintBCDDigit:: ; 3ad5 (0:3ad5)
+ and $0f
+ and a
+ jr z, .zeroDigit
+ res 7, b ; unset 7 to indicate that a nonzero
+.outputDigit ; digit has been reached
+ add "0"
+ ld [hli], a
+ jp PrintLetterDelay
+.zeroDigit
+ bit 7, b ; either printing leading zeroes or
+ jr z, .outputDigit ; already reached a nonzero digit?
+ bit 6, b
+ ret nz ; left-align, don't pad with space
+ ld a, " "
+ ld [hli], a
+ ret
+; 0x3aed \ No newline at end of file
diff --git a/home/text.asm b/home/text.asm
new file mode 100644
index 0000000..83bbd42
--- /dev/null
+++ b/home/text.asm
@@ -0,0 +1,368 @@
+INCLUDE "constants.asm"
+
+SECTION "Text Commands", ROM0[$107e]
+
+ScrollTextUpOneLine:: ; 107e (0:107e)
+; move both rows of text in the normal text box up one row
+; always called twice in a row
+; first time, copy the two rows of text to the "in between" rows that are usually emtpy
+; second time, copy the bottom row of text into the top row of text
+ coord hl, TEXTBOX_X, TEXTBOX_INNERY ; top row of text
+ coord de, TEXTBOX_X, TEXTBOX_INNERY - 1 ; empty line above text
+ ld b, TEXTBOX_WIDTH * 3
+.copyText
+ ld a, [hli]
+ ld [de], a
+ inc de
+ dec b
+ jr nz, .copyText
+ coord hl, TEXTBOX_INNERX, TEXTBOX_INNERY + 2
+ ld a, " "
+ ld b, TEXTBOX_INNERW
+.clearText
+ ld [hli], a
+ dec b
+ jr nz, .clearText
+ ld b, $05 ; wait five frames
+.waitFrame
+ call DelayFrame
+ dec b
+ jr nz, .waitFrame
+ ret
+
+ProtectedWaitBGMap:: ; 10a0 (0:10a0)
+ push bc
+ call WaitBGMap
+ pop bc
+ ret
+
+TextCommandProcessor:: ; 10a6 (0:10a6)
+; Process a string of text commands
+; at hl and write text to bc
+ ld a, [wTextBoxFlags]
+ push af
+ set 1, a
+ ld [wTextBoxFlags], a
+ ld a, c
+ ld [wTextDest], a
+ ld a, b
+ ld [wTextDest + 1], a
+ ; fall through
+
+NextTextCommand:: ; 10b7 (0:10b7)
+ ld a, [hli]
+ cp "@" ; terminator
+ jr nz, .doTextCommand
+ pop af
+ ld [wTextBoxFlags], a
+ ret
+.doTextCommand
+ push hl
+ ld hl, TextCommands
+ push bc
+ add a
+ ld b, $00
+ ld c, a
+ add hl, bc
+ pop bc
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp hl
+
+Text_TX_BOX:: ; 10d0 (0:10d0)
+; TX_BOX
+; draw a box
+; little endian
+; [$04][addr][height][width]
+ pop hl
+ ld a, [hli]
+ ld e, a
+ ld a, [hli]
+ ld d, a
+ ld a, [hli]
+ ld b, a
+ ld a, [hli]
+ ld c, a
+ push hl
+ ld h, d
+ ld l, e
+ call DrawTextBox
+ pop hl
+ jr NextTextCommand
+
+Text_TX:: ; 10e2 (0:10e2)
+; TX
+; write text until "@"
+; [$00]["...@"]
+ pop hl
+ ld d, h
+ ld e, l
+ ld h, b
+ ld l, c
+ call PlaceString
+ ld h, d
+ ld l, e
+ inc hl
+ jr NextTextCommand
+
+Text_TX_RAM:: ; 10ef (0:10ef)
+; text_from_ram
+; write text from a ram address
+; little endian
+; [$01][addr]
+ pop hl
+ ld a, [hli]
+ ld e, a
+ ld a, [hli]
+ ld d, a
+ push hl
+ ld h, b
+ ld l, c
+ call PlaceString
+ pop hl
+ jr NextTextCommand
+
+Text_TX_BCD:: ; 10fd (0:10fd)
+; TX_BCD
+; write bcd from address, typically ram
+; [$02][addr][flags]
+; flags: see PrintBCDNumber
+ pop hl
+ ld a, [hli]
+ ld e, a
+ ld a, [hli]
+ ld d, a
+ ld a, [hli]
+ push hl
+ ld h, b
+ ld l, c
+ ld c, a
+ call PrintBCDNumber
+ ld b, h
+ ld c, l
+ pop hl
+ jr NextTextCommand
+
+Text_TX_MOVE:: ; 110f (0:110f)
+; TX_MOVE
+; move to a new tile
+; [$03][addr]
+ pop hl
+ ld a, [hli]
+ ld [wTextDest], a
+ ld c, a
+ ld a, [hli]
+ ld [wTextDest + 1], a
+ ld b, a
+ jp NextTextCommand
+
+Text_TX_LOW:: ; 111d (0:111d)
+; TX_LOW
+; write text at (1,16)
+; [$05]
+ pop hl
+ coord bc, TEXTBOX_INNERX, TEXTBOX_INNERY + 2
+ jp NextTextCommand
+; 0x1124
+
+Text_WAIT_BUTTON:: ; 1124 (0:1124)
+; TX_WAITBUTTON
+; wait for button press
+; show arrow
+; [06]
+ ld a, [wLinkMode]
+ cp $03
+ jp z, Text_TX_LINK_WAIT_BUTTON
+ ld a, "▼"
+ ldcoord_a TEXTBOX_WIDTH - 2, TEXTBOX_Y + TEXTBOX_HEIGHT - 1
+ push bc
+ call ButtonSound
+ pop bc
+ ld a, "─"
+ ldcoord_a TEXTBOX_WIDTH - 2, TEXTBOX_Y + TEXTBOX_HEIGHT - 1
+ pop hl
+ jp NextTextCommand
+
+Text_TX_SCROLL:: ; 113f (0:113f)
+; TX_SCROLL
+; pushes text up two lines and sets the BC cursor to the border tile
+; below the first character column of the text box.
+; [07]
+ ld a, "─"
+ ldcoord_a TEXTBOX_WIDTH - 2, TEXTBOX_Y + TEXTBOX_HEIGHT - 1
+ call ScrollTextUpOneLine
+ call ScrollTextUpOneLine
+ pop hl
+ coord bc, TEXTBOX_INNERX, TEXTBOX_INNERY + 2
+ jp NextTextCommand
+
+Text_START_ASM:: ; 1151 (0:1151)
+; TX_ASM
+; Executes code following this command.
+; Text processing is resumed upon returning.
+; [08][asm...ret]
+ pop hl
+ ld de, NextTextCommand
+ push de
+ jp hl
+
+Text_TX_NUM:: ; 1157 (0:1157)
+; TX_NUM
+; [$09][addr][hi:bytes lo:digits]
+ pop hl
+ ld a, [hli]
+ ld e, a
+ ld a, [hli]
+ ld d, a
+ ld a, [hli]
+ push hl
+ ld h, b
+ ld l, c
+ ld b, a
+ and $0f
+ ld c, a
+ ld a, b
+ and $f0
+ swap a
+ set 6, a
+ ld b, a
+ call PrintNumber
+ ld b, h
+ ld c, l
+ pop hl
+ jp NextTextCommand
+; 0x1175
+
+Text_TX_EXIT: ; 1175 (0:1175)
+; TX_EXIT
+; [$0A]
+ push bc
+ call GetJoypad
+ ldh a, [hJoyState]
+ and (A_BUTTON | B_BUTTON)
+ jr nz, .done
+ ld c, 30
+ call DelayFrames
+.done
+ pop bc
+ pop hl
+ jp NextTextCommand
+; 0x1189
+
+Text_PlaySound:: ; 1189 (0:1189)
+; Text_PlaySound
+; [0B|0E..13] Play Sound Effects
+; [14..16] Play Pokémon Cries
+ pop hl
+ push bc
+ dec hl
+ ld a, [hli]
+ ld b, a
+ push hl
+ ld hl, .soundTable
+.loop
+ ld a, [hli]
+ cp b
+ jr z, .found
+ inc hl
+ inc hl
+ jr .loop
+.found
+ cp $14
+ jr z, .playCry
+ cp $15
+ jr z, .playCry
+ cp $16
+ jr z, .playCry
+ push de
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ call PlaySFX
+ call WaitSFX
+ pop de
+ pop hl
+ pop bc
+ jp NextTextCommand
+.playCry
+ push de
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ call PlayCry
+ pop de
+ pop hl
+ pop bc
+ jp NextTextCommand
+
+.soundTable:
+ dbw TX_SOUND_0B, $0063
+ dbw TX_SOUND_12, $006B
+ dbw TX_SOUND_0E, $0066
+ dbw TX_SOUND_0F, $0067
+ dbw TX_SOUND_10, $0068
+ dbw TX_SOUND_11, $0069
+ dbw TX_SOUND_13, $0027
+ dbw TX_CRY_14, MON_NIDORINA ; or MON_LEAFY?
+ dbw TX_CRY_15, MON_PIGEOT
+ dbw TX_CRY_16, MON_JUGON
+
+Text_TX_DOTS: ; 11e1 (0:11e1)
+ pop hl
+ ld a, [hli]
+ ld d, a
+ push hl
+ ld h, b
+ ld l, c
+.loop
+ ld a, "…"
+ ld [hli], a
+ push de
+ call GetJoypad
+ pop de
+ ldh a, [hJoyState]
+ and (A_BUTTON | B_BUTTON)
+ jr nz, .next
+ ld c, 10
+ call DelayFrames
+.next
+ dec d
+ jr nz, .loop
+ ld b, h
+ ld c, l
+ pop hl
+ jp NextTextCommand
+
+Text_TX_LINK_WAIT_BUTTON:: ; 1203 (0:1203)
+ push bc
+ call ButtonSound
+ pop bc
+ pop hl
+ jp NextTextCommand
+; 0x120c
+
+TextCommands:: ; 120c
+ dw Text_TX
+ dw Text_TX_RAM
+ dw Text_TX_BCD
+ dw Text_TX_MOVE
+ dw Text_TX_BOX
+ dw Text_TX_LOW
+ dw Text_WAIT_BUTTON
+ dw Text_TX_SCROLL
+ dw Text_START_ASM
+ dw Text_TX_NUM
+ dw Text_TX_EXIT
+ dw Text_PlaySound
+ dw Text_TX_DOTS
+ dw Text_TX_LINK_WAIT_BUTTON
+ dw Text_PlaySound
+ dw Text_PlaySound
+ dw Text_PlaySound
+ dw Text_PlaySound
+ dw Text_PlaySound
+ dw Text_PlaySound
+ dw Text_PlaySound
+ dw Text_PlaySound
+ dw Text_PlaySound
diff --git a/macros.asm b/macros.asm
index e985105..7e5c924 100644
--- a/macros.asm
+++ b/macros.asm
@@ -6,4 +6,5 @@ INCLUDE "macros/code.asm"
INCLUDE "macros/gfx.asm"
INCLUDE "macros/coords.asm"
INCLUDE "macros/farcall.asm"
+INCLUDE "macros/text.asm"
INCLUDE "macros/wram.asm"
diff --git a/macros/text.asm b/macros/text.asm
new file mode 100644
index 0000000..e98970b
--- /dev/null
+++ b/macros/text.asm
@@ -0,0 +1,133 @@
+text EQUS "db $00," ; Start writing text.
+next EQUS "db $4e," ; Move a line down.
+line EQUS "db $4f," ; Start writing at the bottom line.
+para EQUS "db $51," ; Start a new paragraph.
+cont EQUS "db $55," ; Scroll to the next line.
+done EQUS "db $57" ; End a text box.
+prompt EQUS "db $58" ; Prompt the player to end a text box (initiating some other event).
+
+; TODO: determine if these are in
+; Pokedex text commands are only used with pokered.
+; They are included for compatibility.
+page EQUS "db $50," ; Start a new Pokedex page.
+dex EQUS "db $e8, $50" ; End a Pokedex entry.
+
+ enum_start 1
+ enum TX_RAM
+text_from_ram: MACRO
+ db TX_RAM
+ dw \1 ; address
+ ENDM
+
+ enum TX_BCD
+text_bcd: macro
+ db TX_BCD
+ dw \1 ; address
+ db \2 ; flags + digits, see PrintBCDNumber
+ ENDM
+
+ enum TX_MOVE
+text_move: macro
+ db TX_MOVE
+ dw \1 ; address
+ ENDM
+
+ enum TX_BOX
+text_box: macro
+ db TX_BOX
+ dw \1 ; address
+ db \2, \3 ; width, height
+ ENDM
+
+ enum TX_LOW
+text_low: macro
+ db TX_LOW
+ endm
+
+ enum WAIT_BUTTON
+text_waitbutton: macro
+ db WAIT_BUTTON
+ endm
+
+ enum TX_SCROLL
+text_scroll: macro
+ db TX_SCROLL
+ endm
+
+ enum START_ASM
+start_asm: macro
+ db START_ASM
+ endm
+
+ enum TX_NUM
+deciram: macro
+ db TX_NUM
+ dw \1 ; address
+ dn \2, \3 ; bytes, flags + digits
+ endm
+
+ enum TX_EXIT
+interpret_data: macro
+ db TX_EXIT
+ endm
+
+ enum TX_SOUND_0B
+sound_dex_fanfare_50_79: macro
+ db TX_SOUND_0B
+ endm
+
+ enum TX_DOTS
+limited_interpret_data: macro
+ db TX_DOTS
+ db \1
+ endm
+
+ enum TX_LINK_WAIT_BUTTON
+link_wait_button: macro
+ db TX_LINK_WAIT_BUTTON
+ endm
+
+ enum TX_SOUND_0E
+sound_dex_fanfare_20_49: macro
+ db TX_SOUND_0E
+ endm
+
+ enum TX_SOUND_0F
+sound_item: macro
+ db TX_SOUND_0F
+ endm
+
+ enum TX_SOUND_10
+sound_caught_mon: macro
+ db TX_SOUND_10
+ endm
+
+ enum TX_SOUND_11
+sound_dex_fanfare_80_109: macro
+ db TX_SOUND_11
+ endm
+
+ enum TX_SOUND_12
+sound_fanfare: macro
+ db TX_SOUND_12
+ endm
+
+ enum TX_SOUND_13
+sound_slot_machine_start: macro
+ db TX_SOUND_13
+ endm
+
+ enum TX_CRY_14
+cry_nidorina: macro
+ db TX_CRY_14
+ endm
+
+ enum TX_CRY_15
+cry_pigeot: macro
+ db TX_CRY_15
+ endm
+
+ enum TX_CRY_16
+cry_jugon: macro
+ db TX_CRY_16
+ endm
diff --git a/shim.sym b/shim.sym
index d56f713..6599c3a 100644
--- a/shim.sym
+++ b/shim.sym
@@ -9,10 +9,6 @@
00:0E93 PlaceString
00:0E94 PlaceNextChar
00:0E9D CheckDict
-00:10A6 PlaceHLTextAtBC
-00:10B7 DoTextUntilTerminator
-00:10C1 DoTextUntilTerminator.continue
-00:10E2 Text_TX
00:1d49 LoadMenuHeader
00:1e58 OpenMenu
00:1F9E ClearWindowData
@@ -34,6 +30,7 @@
00:3655 SetHPPal.done
00:36C8 NamesPointers
00:36E0 GetName
+00:39BA PlayCry
00:3D86 WaitSFX
00:3D87 WaitSFX.wait
00:3DA5 MaxVolume