diff options
Diffstat (limited to 'home/text.asm')
-rw-r--r-- | home/text.asm | 533 |
1 files changed, 227 insertions, 306 deletions
diff --git a/home/text.asm b/home/text.asm index f78227eb..78d69138 100644 --- a/home/text.asm +++ b/home/text.asm @@ -5,9 +5,9 @@ TextBoxBorder:: push hl ld a, "┌" ld [hli], a - inc a ; ─ - call NPlaceChar - inc a ; ┐ + inc a ; "─" + call .PlaceChars + inc a ; "┐" ld [hl], a pop hl @@ -20,7 +20,7 @@ TextBoxBorder:: ld a, "│" ld [hli], a ld a, " " - call NPlaceChar + call .PlaceChars ld [hl], "│" pop hl @@ -33,11 +33,11 @@ TextBoxBorder:: ld a, "└" ld [hli], a ld a, "─" - call NPlaceChar + call .PlaceChars ld [hl], "┘" ret -NPlaceChar:: +.PlaceChars:: ; Place char a c times. ld d, c .loop @@ -48,21 +48,21 @@ NPlaceChar:: PlaceString:: push hl + PlaceNextChar:: ld a, [de] - cp "@" - jr nz, Char4ETest + jr nz, .NotTerminator ld b, h ld c, l pop hl ret -Char4ETest:: - cp $4E ; next - jr nz, .char4FTest +.NotTerminator + cp "<NEXT>" + jr nz, .NotNext ld bc, 2 * SCREEN_WIDTH - ld a, [hFlags_0xFFFA] + ldh a, [hFlagsFFFA] bit 2, a jr z, .ok ld bc, SCREEN_WIDTH @@ -70,142 +70,101 @@ Char4ETest:: pop hl add hl, bc push hl - jp PlaceNextChar_inc + jp NextChar -.char4FTest - cp $4F ; line - jr nz, .next3 +.NotNext + cp "<LINE>" + jr nz, .NotLine pop hl - coord hl, 1, 16 + hlcoord 1, 16 push hl - jp PlaceNextChar_inc - -.next3 ; Check against a dictionary -dict: macro -if \1 == 0 - and a -else - cp \1 -endc - jp z, \2 -endm - - dict $00, Char00 ; error - dict $4C, Char4C ; autocont - dict $4B, Char4B ; cont_ - dict $51, Char51 ; para - dict $49, Char49 ; page - dict $52, Char52 ; player - dict $53, Char53 ; rival - dict $54, Char54 ; POKé - dict $5B, Char5B ; PC - dict $5E, Char5E ; ROCKET - dict $5C, Char5C ; TM - dict $5D, Char5D ; TRAINER - dict $55, Char55 ; cont - dict $56, Char56 ; 6 dots - dict $57, Char57 ; done - dict $58, Char58 ; prompt - dict $4A, Char4A ; PKMN - dict $5F, Char5F ; dex - dict $59, Char59 ; TARGET - dict $5A, Char5A ; USER + jp NextChar + +.NotLine + +; Check against a dictionary + dict "<NULL>", NullChar + dict "<SCROLL>", _ContTextNoPause + dict "<_CONT>", _ContText + dict "<PARA>", Paragraph + dict "<PAGE>", PageChar + dict "<PLAYER>", PrintPlayerName + dict "<RIVAL>", PrintRivalName + dict "#", PlacePOKe + dict "<PC>", PCChar + dict "<ROCKET>", RocketChar + dict "<TM>", TMChar + dict "<TRAINER>", TrainerChar + dict "<CONT>", ContText + dict "<……>", SixDotsChar + dict "<DONE>", DoneText + dict "<PROMPT>", PromptText + dict "<PKMN>", PlacePKMN + dict "<DEXEND>", PlaceDexEnd + dict "<TARGET>", PlaceMoveTargetsName + dict "<USER>", PlaceMoveUsersName ld [hli], a call PrintLetterDelay -PlaceNextChar_inc:: + +NextChar:: inc de jp PlaceNextChar -Char00:: +NullChar:: ld b, h ld c, l pop hl - ld de, Char00Text + ld de, TextIDErrorText dec de ret -Char00Text:: ; “%d ERROR.” - TX_FAR _Char00Text - db "@" - -Char52:: ; player’s name - push de - ld de, wPlayerName - jr FinishDTE - -Char53:: ; rival’s name - push de - ld de, wRivalName - jr FinishDTE - -Char5D:: ; TRAINER - push de - ld de, Char5DText - jr FinishDTE +TextIDErrorText:: ; "[hSpriteIndexOrTextID] ERROR." + text_far _TextIDErrorText + text_end -Char5C:: ; TM +print_name: MACRO push de - ld de, Char5CText - jr FinishDTE - -Char5B:: ; PC - push de - ld de, Char5BText - jr FinishDTE - -Char5E:: ; ROCKET - push de - ld de, Char5EText - jr FinishDTE - -Char54:: ; POKé - push de - ld de, Char54Text - jr FinishDTE + ld de, \1 + jr PlaceCommandCharacter +ENDM + +PrintPlayerName:: print_name wPlayerName +PrintRivalName:: print_name wRivalName + +TrainerChar:: print_name TrainerCharText +TMChar:: print_name TMCharText +PCChar:: print_name PCCharText +RocketChar:: print_name RocketCharText +PlacePOKe:: print_name PlacePOKeText +SixDotsChar:: print_name SixDotsCharText +PlacePKMN:: print_name PlacePKMNText + +PlaceMoveTargetsName:: + ldh a, [hWhoseTurn] + xor 1 + jr PlaceMoveUsersName.place -Char56:: ; …… - push de - ld de, Char56Text - jr FinishDTE +PlaceMoveUsersName:: + ldh a, [hWhoseTurn] -Char4A:: ; PKMN - push de - ld de, Char4AText - jr FinishDTE - -Char59:: -; depending on whose turn it is, print -; enemy active monster’s name, prefixed with “Enemy ” -; or -; player active monster’s name -; (like Char5A but flipped) - ld a, [H_WHOSETURN] - xor 1 - jr MonsterNameCharsCommon - -Char5A:: -; depending on whose turn it is, print -; player active monster’s name -; or -; enemy active monster’s name, prefixed with “Enemy ” - ld a, [H_WHOSETURN] -MonsterNameCharsCommon:: +.place: push de and a - jr nz, .Enemy - ld de, wBattleMonNick ; player active monster name - jr FinishDTE + jr nz, .enemy -.Enemy - ; print “Enemy ” - ld de, Char5AText + ld de, wBattleMonNick + jr PlaceCommandCharacter + +.enemy + ld de, EnemyText call PlaceString ld h, b ld l, c - ld de, wEnemyMonNick ; enemy active monster name + ld de, wEnemyMonNick + ; fallthrough -FinishDTE:: +PlaceCommandCharacter:: call PlaceString ld h, b ld l, c @@ -213,28 +172,20 @@ FinishDTE:: inc de jp PlaceNextChar -Char5CText:: - db "TM@" -Char5DText:: - db "TRAINER@" -Char5BText:: - db "PC@" -Char5EText:: - db "ROCKET@" -Char54Text:: - db "POKé@" -Char56Text:: - db "……@" -Char5AText:: - db "Enemy @" -Char4AText:: - db $E1, $E2, "@" ; PKMN - -Char55:: +TMCharText:: db "TM@" +TrainerCharText:: db "TRAINER@" +PCCharText:: db "PC@" +RocketCharText:: db "ROCKET@" +PlacePOKeText:: db "POKé@" +SixDotsCharText:: db "……@" +EnemyText:: db "Enemy @" +PlacePKMNText:: db "<PK><MN>@" + +ContText:: push de ld b, h ld c, l - ld hl, Char55Text + ld hl, ContCharText call TextCommandProcessor ld h, b ld l, c @@ -242,101 +193,99 @@ Char55:: inc de jp PlaceNextChar -Char55Text:: -; equivalent to Char4B - TX_FAR _Char55Text - db "@" +ContCharText:: + text_far _ContCharText + text_end -Char5F:: -; ends a Pokédex entry +PlaceDexEnd:: ld [hl], "." pop hl ret -Char58:: ; prompt +PromptText:: ld a, [wLinkState] cp LINK_STATE_BATTLING jp z, .ok ld a, "▼" - Coorda 18, 16 + ldcoord_a 18, 16 .ok call ProtectedDelay3 call ManualTextScroll ld a, " " - Coorda 18, 16 -Char57:: ; done + ldcoord_a 18, 16 + +DoneText:: pop hl - ld de, Char58Text + ld de, .stop dec de ret -Char58Text:: - db "@" +.stop: + text_end -Char51:: ; para +Paragraph:: push de ld a, "▼" - Coorda 18, 16 + ldcoord_a 18, 16 call ProtectedDelay3 call ManualTextScroll - coord hl, 1, 13 + hlcoord 1, 13 lb bc, 4, 18 call ClearScreenArea ld c, 20 call DelayFrames pop de - coord hl, 1, 14 - jp PlaceNextChar_inc + hlcoord 1, 14 + jp NextChar -Char49:: - ld a, [hFlags_0xFFFA] +PageChar:: + ldh a, [hFlagsFFFA] bit 3, a - jr z, .Char49 - ld a, $4e - jp Char4ETest + jr z, .pageChar + ld a, "<NEXT>" + jp PlaceNextChar.NotTerminator -.Char49 +.pageChar push de ld a, "▼" - Coorda 18, 16 + ldcoord_a 18, 16 call ProtectedDelay3 call ManualTextScroll - coord hl, 1, 10 + hlcoord 1, 10 lb bc, 7, 18 call ClearScreenArea ld c, 20 call DelayFrames pop de pop hl - coord hl, 1, 11 + hlcoord 1, 11 push hl - jp PlaceNextChar_inc + jp NextChar -Char4B:: +_ContText:: ld a, "▼" - Coorda 18, 16 + ldcoord_a 18, 16 call ProtectedDelay3 push de call ManualTextScroll pop de ld a, " " - Coorda 18, 16 - ;fall through -Char4C:: + ldcoord_a 18, 16 +_ContTextNoPause:: push de call ScrollTextUpOneLine call ScrollTextUpOneLine - coord hl, 1, 16 + hlcoord 1, 16 pop de - jp PlaceNextChar_inc + jp NextChar ; 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 ScrollTextUpOneLine:: - coord hl, 0, 14 ; top row of text - coord de, 0, 13 ; empty line above text + hlcoord 0, 14 ; top row of text + decoord 0, 13 ; empty line above text ld b, SCREEN_WIDTH * 3 .copyText ld a, [hli] @@ -344,7 +293,7 @@ ScrollTextUpOneLine:: inc de dec b jr nz, .copyText - coord hl, 1, 16 + hlcoord 1, 16 ld a, " " ld b, SCREEN_WIDTH - 2 .clearText @@ -352,7 +301,6 @@ ScrollTextUpOneLine:: dec b jr nz, .clearText - ; wait five frames ld b, 5 .WaitFrame call DelayFrame @@ -372,7 +320,7 @@ TextCommandProcessor:: push af set 1, a ld e, a - ld a, [$fff9] + ldh a, [hClearLetterPrintingDelayFlags] xor e ld [wLetterPrintingDelayFlags], a ld a, c @@ -382,18 +330,18 @@ TextCommandProcessor:: NextTextCommand:: ld a, [hli] - cp "@" ; terminator - jr nz, .doTextCommand + cp TX_END + jr nz, .TextCommand pop af ld [wLetterPrintingDelayFlags], a ret -.doTextCommand + +.TextCommand: push hl - cp $17 - jp z, TextCommand17 - cp $0e - jp nc, TextCommand0B ; if a != 0x17 and a >= 0xE, go to command 0xB -; if a < 0xE, use a jump table + cp TX_FAR + jp z, TextCommand_FAR + cp TX_SOUND_POKEDEX_RATING + jp nc, TextCommand_SOUND ld hl, TextCommandJumpTable push bc add a @@ -406,12 +354,8 @@ NextTextCommand:: ld l, a jp hl -; draw box -; 04AAAABBCC -; AAAA = address of upper left corner -; BB = height -; CC = width -TextCommand04:: +TextCommand_BOX:: +; draw a box (height, width) pop hl ld a, [hli] ld e, a @@ -428,9 +372,8 @@ TextCommand04:: pop hl jr NextTextCommand -; place string inline -; 00{string} -TextCommand00:: +TextCommand_START:: +; write text until "@" pop hl ld d, h ld e, l @@ -442,10 +385,8 @@ TextCommand00:: inc hl jr NextTextCommand -; place string from RAM -; 01AAAA -; AAAA = address of string -TextCommand01:: +TextCommand_RAM:: +; write text from a ram address (little endian) pop hl ld a, [hli] ld e, a @@ -458,13 +399,8 @@ TextCommand01:: pop hl jr NextTextCommand -; print BCD number -; 02AAAABB -; AAAA = address of BCD number -; BB -; bits 0-4 = length in bytes -; bits 5-7 = unknown flags -TextCommand02:: +TextCommand_BCD:: +; write bcd from address, typically ram pop hl ld a, [hli] ld e, a @@ -481,10 +417,8 @@ TextCommand02:: pop hl jr NextTextCommand -; repoint destination address -; 03AAAA -; AAAA = new destination address -TextCommand03:: +TextCommand_MOVE:: +; move to a new tile pop hl ld a, [hli] ld [wTextDest], a @@ -494,58 +428,47 @@ TextCommand03:: ld b, a jp NextTextCommand -; repoint destination to second line of dialogue text box -; 05 -; (no arguments) -TextCommand05:: +TextCommand_LOW:: +; write text at (1,16) pop hl - coord bc, 1, 16 ; address of second line of dialogue text box + bccoord 1, 16 ; second line of dialogue text box jp NextTextCommand -; blink arrow and wait for A or B to be pressed -; 06 -; (no arguments) -TextCommand06:: +TextCommand_PROMPT_BUTTON:: +; wait for button press; show arrow ld a, [wLinkState] cp LINK_STATE_BATTLING - jp z, TextCommand0D + jp z, TextCommand_WAIT_BUTTON ld a, "▼" - Coorda 18, 16 ; place down arrow in lower right corner of dialogue text box + ldcoord_a 18, 16 ; place down arrow in lower right corner of dialogue text box push bc call ManualTextScroll ; blink arrow and wait for A or B to be pressed pop bc ld a, " " - Coorda 18, 16 ; overwrite down arrow with blank space + ldcoord_a 18, 16 ; overwrite down arrow with blank space pop hl jp NextTextCommand -; scroll text up one line -; 07 -; (no arguments) -TextCommand07:: +TextCommand_SCROLL:: +; pushes text up two lines and sets the BC cursor to the border tile +; below the first character column of the text box. ld a, " " - Coorda 18, 16 ; place blank space in lower right corner of dialogue text box + ldcoord_a 18, 16 ; place blank space in lower right corner of dialogue text box call ScrollTextUpOneLine call ScrollTextUpOneLine pop hl - coord bc, 1, 16 ; address of second line of dialogue text box + bccoord 1, 16 ; second line of dialogue text box jp NextTextCommand -; execute asm inline -; 08{code} -TextCommand08:: +TextCommand_START_ASM:: +; run assembly code pop hl ld de, NextTextCommand - push de ; return address + push de jp hl -; print decimal number (converted from binary number) -; 09AAAABB -; AAAA = address of number -; BB -; bits 0-3 = how many digits to display -; bits 4-7 = how long the number is in bytes -TextCommand09:: +TextCommand_NUM:: +; print a number pop hl ld a, [hli] ld e, a @@ -569,45 +492,42 @@ TextCommand09:: pop hl jp NextTextCommand -; wait half a second if the user doesn't hold A or B -; 0A -; (no arguments) -TextCommand0A:: +TextCommand_PAUSE:: +; wait for button press or 30 frames push bc call Joypad - ld a, [hJoyHeld] + ldh a, [hJoyHeld] and A_BUTTON | B_BUTTON - jr nz, .skipDelay - ld c, 30 + jr nz, .done + ld c, 30 ; half a second call DelayFrames -.skipDelay +.done pop bc pop hl jp NextTextCommand -; plays sounds -; this actually handles various command ID's, not just 0B -; (no arguments) -TextCommand0B:: +TextCommand_SOUND:: +; play a sound effect from TextCommandSounds pop hl push bc dec hl ld a, [hli] - ld b, a ; b = command number that got us here + ld b, a ; b = text command number that got us here push hl ld hl, TextCommandSounds .loop ld a, [hli] cp b - jr z, .matchFound + jr z, .play inc hl jr .loop -.matchFound - cp $14 + +.play + cp TX_SOUND_CRY_PIKACHU jr z, .pokemonCry - cp $15 + cp TX_SOUND_CRY_PIDGEOT jr z, .pokemonCry - cp $16 + cp TX_SOUND_CRY_DEWGONG jr z, .pokemonCry ld a, [hl] call PlaySound @@ -615,6 +535,7 @@ TextCommand0B:: pop hl pop bc jp NextTextCommand + .pokemonCry push de ld a, [hl] @@ -624,95 +545,95 @@ TextCommand0B:: pop bc jp NextTextCommand -; format: text command ID, sound ID or cry ID TextCommandSounds:: - db $0B, SFX_GET_ITEM_1 - db $12, SFX_TURN_OFF_PC - db $0E, SFX_POKEDEX_RATING - db $0F, SFX_GET_ITEM_1 - db $10, SFX_GET_ITEM_2 - db $11, SFX_GET_KEY_ITEM - db $13, SFX_TRADE_MACHINE - db $14, PIKACHU ; used in OakSpeech - db $15, PIDGEOT ; used in SaffronCityText12 - db $16, DEWGONG ; unused? - -; draw ellipses -; 0CAA -; AA = number of ellipses to draw -TextCommand0C:: + db TX_SOUND_GET_ITEM_1, SFX_GET_ITEM_1 ; actually plays SFX_LEVEL_UP when the battle music engine is loaded + db TX_SOUND_CAUGHT_MON, SFX_CAUGHT_MON + db TX_SOUND_POKEDEX_RATING, SFX_POKEDEX_RATING ; unused + db TX_SOUND_GET_ITEM_1_DUPLICATE, SFX_GET_ITEM_1 ; unused + db TX_SOUND_GET_ITEM_2, SFX_GET_ITEM_2 + db TX_SOUND_GET_KEY_ITEM, SFX_GET_KEY_ITEM + db TX_SOUND_DEX_PAGE_ADDED, SFX_DEX_PAGE_ADDED + db TX_SOUND_CRY_PIKACHU, PIKACHU ; used in OakSpeech + db TX_SOUND_CRY_PIDGEOT, PIDGEOT ; used in SaffronCityText12 + db TX_SOUND_CRY_DEWGONG, DEWGONG ; unused + +TextCommand_DOTS:: +; wait for button press or 30 frames while printing "…"s 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 Joypad pop de - ld a, [hJoyHeld] ; joypad state + ldh a, [hJoyHeld] ; joypad state and A_BUTTON | B_BUTTON - jr nz, .skipDelay ; if so, skip the delay + jr nz, .next ; if so, skip the delay ld c, 10 call DelayFrames -.skipDelay +.next dec d jr nz, .loop + ld b, h ld c, l pop hl jp NextTextCommand -; wait for A or B to be pressed -; 0D -; (no arguments) -TextCommand0D:: +TextCommand_WAIT_BUTTON:: +; wait for button press; don't show arrow push bc - call ManualTextScroll ; wait for A or B to be pressed + call ManualTextScroll pop bc pop hl jp NextTextCommand -; process text commands in another ROM bank -; 17AAAABB -; AAAA = address of text commands -; BB = bank -TextCommand17:: +TextCommand_FAR:: +; write text from a different bank (little endian) pop hl - ld a, [H_LOADEDROMBANK] + ldh a, [hLoadedROMBank] push af + ld a, [hli] ld e, a ld a, [hli] ld d, a ld a, [hli] - ld [H_LOADEDROMBANK], a + + ldh [hLoadedROMBank], a ld [MBC1RomBank], a + push hl ld l, e ld h, d call TextCommandProcessor pop hl + pop af - ld [H_LOADEDROMBANK], a + ldh [hLoadedROMBank], a ld [MBC1RomBank], a jp NextTextCommand TextCommandJumpTable:: - dw TextCommand00 - dw TextCommand01 - dw TextCommand02 - dw TextCommand03 - dw TextCommand04 - dw TextCommand05 - dw TextCommand06 - dw TextCommand07 - dw TextCommand08 - dw TextCommand09 - dw TextCommand0A - dw TextCommand0B - dw TextCommand0C - dw TextCommand0D +; entries correspond to TX_* constants (see macros/scripts/text.asm) + dw TextCommand_START ; TX_START + dw TextCommand_RAM ; TX_RAM + dw TextCommand_BCD ; TX_BCD + dw TextCommand_MOVE ; TX_MOVE + dw TextCommand_BOX ; TX_BOX + dw TextCommand_LOW ; TX_LOW + dw TextCommand_PROMPT_BUTTON ; TX_PROMPT_BUTTON + dw TextCommand_SCROLL ; TX_SCROLL + dw TextCommand_START_ASM ; TX_START_ASM + dw TextCommand_NUM ; TX_NUM + dw TextCommand_PAUSE ; TX_PAUSE + dw TextCommand_SOUND ; TX_SOUND_GET_ITEM_1 (also handles other TX_SOUND_* commands) + dw TextCommand_DOTS ; TX_DOTS + dw TextCommand_WAIT_BUTTON ; TX_WAIT_BUTTON + ; greater TX_* constants are handled directly by NextTextCommand |