text.asm 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. TextBoxBorder::
  2. ; Draw a c×b text box at hl.
  3. ; top row
  4. push hl
  5. ld a, "┌"
  6. ld [hli], a
  7. inc a ; ─
  8. call NPlaceChar
  9. inc a ; ┐
  10. ld [hl], a
  11. pop hl
  12. ld de, SCREEN_WIDTH
  13. add hl, de
  14. ; middle rows
  15. .next
  16. push hl
  17. ld a, "│"
  18. ld [hli], a
  19. ld a, " "
  20. call NPlaceChar
  21. ld [hl], "│"
  22. pop hl
  23. ld de, SCREEN_WIDTH
  24. add hl, de
  25. dec b
  26. jr nz, .next
  27. ; bottom row
  28. ld a, "└"
  29. ld [hli], a
  30. ld a, "─"
  31. call NPlaceChar
  32. ld [hl], "┘"
  33. ret
  34. NPlaceChar::
  35. ; Place char a c times.
  36. ld d, c
  37. .loop
  38. ld [hli], a
  39. dec d
  40. jr nz, .loop
  41. ret
  42. PlaceString::
  43. push hl
  44. PlaceNextChar::
  45. ld a, [de]
  46. cp "@"
  47. jr nz, Char4ETest
  48. ld b, h
  49. ld c, l
  50. pop hl
  51. ret
  52. Char4ETest::
  53. cp $4E ; next
  54. jr nz, .char4FTest
  55. ld bc, 2 * SCREEN_WIDTH
  56. ld a, [hFlags_0xFFF6]
  57. bit 2, a
  58. jr z, .ok
  59. ld bc, SCREEN_WIDTH
  60. .ok
  61. pop hl
  62. add hl, bc
  63. push hl
  64. jp PlaceNextChar_inc
  65. .char4FTest
  66. cp $4F ; line
  67. jr nz, .next3
  68. pop hl
  69. coord hl, 1, 16
  70. push hl
  71. jp PlaceNextChar_inc
  72. .next3 ; Check against a dictionary
  73. dict: macro
  74. if \1 == 0
  75. and a
  76. else
  77. cp \1
  78. endc
  79. jp z, \2
  80. endm
  81. dict $00, Char00 ; error
  82. dict $4C, Char4C ; autocont
  83. dict $4B, Char4B ; cont_
  84. dict $51, Char51 ; para
  85. dict $49, Char49 ; page
  86. dict $52, Char52 ; player
  87. dict $53, Char53 ; rival
  88. dict $54, Char54 ; POKé
  89. dict $5B, Char5B ; PC
  90. dict $5E, Char5E ; ROCKET
  91. dict $5C, Char5C ; TM
  92. dict $5D, Char5D ; TRAINER
  93. dict $55, Char55 ; cont
  94. dict $56, Char56 ; 6 dots
  95. dict $57, Char57 ; done
  96. dict $58, Char58 ; prompt
  97. dict $4A, Char4A ; PKMN
  98. dict $5F, Char5F ; dex
  99. dict $59, Char59 ; TARGET
  100. dict $5A, Char5A ; USER
  101. ld [hli], a
  102. call PrintLetterDelay
  103. PlaceNextChar_inc::
  104. inc de
  105. jp PlaceNextChar
  106. Char00::
  107. ld b, h
  108. ld c, l
  109. pop hl
  110. ld de, Char00Text
  111. dec de
  112. ret
  113. Char00Text:: ; “%d ERROR.”
  114. TX_FAR _Char00Text
  115. db "@"
  116. Char52:: ; player’s name
  117. push de
  118. ld de, wPlayerName
  119. jr FinishDTE
  120. Char53:: ; rival’s name
  121. push de
  122. ld de, wRivalName
  123. jr FinishDTE
  124. Char5D:: ; TRAINER
  125. push de
  126. ld de, Char5DText
  127. jr FinishDTE
  128. Char5C:: ; TM
  129. push de
  130. ld de, Char5CText
  131. jr FinishDTE
  132. Char5B:: ; PC
  133. push de
  134. ld de, Char5BText
  135. jr FinishDTE
  136. Char5E:: ; ROCKET
  137. push de
  138. ld de, Char5EText
  139. jr FinishDTE
  140. Char54:: ; POKé
  141. push de
  142. ld de, Char54Text
  143. jr FinishDTE
  144. Char56:: ; ……
  145. push de
  146. ld de, Char56Text
  147. jr FinishDTE
  148. Char4A:: ; PKMN
  149. push de
  150. ld de, Char4AText
  151. jr FinishDTE
  152. Char59::
  153. ; depending on whose turn it is, print
  154. ; enemy active monster’s name, prefixed with “Enemy ”
  155. ; or
  156. ; player active monster’s name
  157. ; (like Char5A but flipped)
  158. ld a, [H_WHOSETURN]
  159. xor 1
  160. jr MonsterNameCharsCommon
  161. Char5A::
  162. ; depending on whose turn it is, print
  163. ; player active monster’s name
  164. ; or
  165. ; enemy active monster’s name, prefixed with “Enemy ”
  166. ld a, [H_WHOSETURN]
  167. MonsterNameCharsCommon::
  168. push de
  169. and a
  170. jr nz, .Enemy
  171. ld de, wBattleMonNick ; player active monster name
  172. jr FinishDTE
  173. .Enemy
  174. ; print “Enemy ”
  175. ld de, Char5AText
  176. call PlaceString
  177. ld h, b
  178. ld l, c
  179. ld de, wEnemyMonNick ; enemy active monster name
  180. FinishDTE::
  181. call PlaceString
  182. ld h, b
  183. ld l, c
  184. pop de
  185. inc de
  186. jp PlaceNextChar
  187. Char5CText::
  188. db "TM@"
  189. Char5DText::
  190. db "TRAINER@"
  191. Char5BText::
  192. db "PC@"
  193. Char5EText::
  194. db "ROCKET@"
  195. Char54Text::
  196. db "POKé@"
  197. Char56Text::
  198. db "……@"
  199. Char5AText::
  200. db "Enemy @"
  201. Char4AText::
  202. db $E1,$E2,"@" ; PKMN
  203. Char55::
  204. push de
  205. ld b, h
  206. ld c, l
  207. ld hl, Char55Text
  208. call TextCommandProcessor
  209. ld h, b
  210. ld l, c
  211. pop de
  212. inc de
  213. jp PlaceNextChar
  214. Char55Text::
  215. ; equivalent to Char4B
  216. TX_FAR _Char55Text
  217. db "@"
  218. Char5F::
  219. ; ends a Pokédex entry
  220. ld [hl], "."
  221. pop hl
  222. ret
  223. Char58:: ; prompt
  224. ld a, [wLinkState]
  225. cp LINK_STATE_BATTLING
  226. jp z, .ok
  227. ld a, "▼"
  228. Coorda 18, 16
  229. .ok
  230. call ProtectedDelay3
  231. call ManualTextScroll
  232. ld a, " "
  233. Coorda 18, 16
  234. Char57:: ; done
  235. pop hl
  236. ld de, Char58Text
  237. dec de
  238. ret
  239. Char58Text::
  240. db "@"
  241. Char51:: ; para
  242. push de
  243. ld a, "▼"
  244. Coorda 18, 16
  245. call ProtectedDelay3
  246. call ManualTextScroll
  247. coord hl, 1, 13
  248. lb bc, 4, 18
  249. call ClearScreenArea
  250. ld c, 20
  251. call DelayFrames
  252. pop de
  253. coord hl, 1, 14
  254. jp PlaceNextChar_inc
  255. Char49::
  256. push de
  257. ld a, "▼"
  258. Coorda 18, 16
  259. call ProtectedDelay3
  260. call ManualTextScroll
  261. coord hl, 1, 10
  262. lb bc, 7, 18
  263. call ClearScreenArea
  264. ld c, 20
  265. call DelayFrames
  266. pop de
  267. pop hl
  268. coord hl, 1, 11
  269. push hl
  270. jp PlaceNextChar_inc
  271. Char4B::
  272. ld a, "▼"
  273. Coorda 18, 16
  274. call ProtectedDelay3
  275. push de
  276. call ManualTextScroll
  277. pop de
  278. ld a, " "
  279. Coorda 18, 16
  280. ;fall through
  281. Char4C::
  282. push de
  283. call ScrollTextUpOneLine
  284. call ScrollTextUpOneLine
  285. coord hl, 1, 16
  286. pop de
  287. jp PlaceNextChar_inc
  288. ; move both rows of text in the normal text box up one row
  289. ; always called twice in a row
  290. ; first time, copy the two rows of text to the "in between" rows that are usually emtpy
  291. ; second time, copy the bottom row of text into the top row of text
  292. ScrollTextUpOneLine::
  293. coord hl, 0, 14 ; top row of text
  294. coord de, 0, 13 ; empty line above text
  295. ld b, SCREEN_WIDTH * 3
  296. .copyText
  297. ld a, [hli]
  298. ld [de], a
  299. inc de
  300. dec b
  301. jr nz, .copyText
  302. coord hl, 1, 16
  303. ld a, " "
  304. ld b, SCREEN_WIDTH - 2
  305. .clearText
  306. ld [hli], a
  307. dec b
  308. jr nz, .clearText
  309. ; wait five frames
  310. ld b, 5
  311. .WaitFrame
  312. call DelayFrame
  313. dec b
  314. jr nz, .WaitFrame
  315. ret
  316. ProtectedDelay3::
  317. push bc
  318. call Delay3
  319. pop bc
  320. ret
  321. TextCommandProcessor::
  322. ld a, [wLetterPrintingDelayFlags]
  323. push af
  324. set 1, a
  325. ld e, a
  326. ld a, [$fff4]
  327. xor e
  328. ld [wLetterPrintingDelayFlags], a
  329. ld a, c
  330. ld [wTextDest], a
  331. ld a, b
  332. ld [wTextDest + 1], a
  333. NextTextCommand::
  334. ld a, [hli]
  335. cp "@" ; terminator
  336. jr nz, .doTextCommand
  337. pop af
  338. ld [wLetterPrintingDelayFlags], a
  339. ret
  340. .doTextCommand
  341. push hl
  342. cp $17
  343. jp z, TextCommand17
  344. cp $0e
  345. jp nc, TextCommand0B ; if a != 0x17 and a >= 0xE, go to command 0xB
  346. ; if a < 0xE, use a jump table
  347. ld hl, TextCommandJumpTable
  348. push bc
  349. add a
  350. ld b, 0
  351. ld c, a
  352. add hl, bc
  353. pop bc
  354. ld a, [hli]
  355. ld h, [hl]
  356. ld l, a
  357. jp hl
  358. ; draw box
  359. ; 04AAAABBCC
  360. ; AAAA = address of upper left corner
  361. ; BB = height
  362. ; CC = width
  363. TextCommand04::
  364. pop hl
  365. ld a, [hli]
  366. ld e, a
  367. ld a, [hli]
  368. ld d, a
  369. ld a, [hli]
  370. ld b, a
  371. ld a, [hli]
  372. ld c, a
  373. push hl
  374. ld h, d
  375. ld l, e
  376. call TextBoxBorder
  377. pop hl
  378. jr NextTextCommand
  379. ; place string inline
  380. ; 00{string}
  381. TextCommand00::
  382. pop hl
  383. ld d, h
  384. ld e, l
  385. ld h, b
  386. ld l, c
  387. call PlaceString
  388. ld h, d
  389. ld l, e
  390. inc hl
  391. jr NextTextCommand
  392. ; place string from RAM
  393. ; 01AAAA
  394. ; AAAA = address of string
  395. TextCommand01::
  396. pop hl
  397. ld a, [hli]
  398. ld e, a
  399. ld a, [hli]
  400. ld d, a
  401. push hl
  402. ld h, b
  403. ld l, c
  404. call PlaceString
  405. pop hl
  406. jr NextTextCommand
  407. ; print BCD number
  408. ; 02AAAABB
  409. ; AAAA = address of BCD number
  410. ; BB
  411. ; bits 0-4 = length in bytes
  412. ; bits 5-7 = unknown flags
  413. TextCommand02::
  414. pop hl
  415. ld a, [hli]
  416. ld e, a
  417. ld a, [hli]
  418. ld d, a
  419. ld a, [hli]
  420. push hl
  421. ld h, b
  422. ld l, c
  423. ld c, a
  424. call PrintBCDNumber
  425. ld b, h
  426. ld c, l
  427. pop hl
  428. jr NextTextCommand
  429. ; repoint destination address
  430. ; 03AAAA
  431. ; AAAA = new destination address
  432. TextCommand03::
  433. pop hl
  434. ld a, [hli]
  435. ld [wTextDest], a
  436. ld c, a
  437. ld a, [hli]
  438. ld [wTextDest + 1], a
  439. ld b, a
  440. jp NextTextCommand
  441. ; repoint destination to second line of dialogue text box
  442. ; 05
  443. ; (no arguments)
  444. TextCommand05::
  445. pop hl
  446. coord bc, 1, 16 ; address of second line of dialogue text box
  447. jp NextTextCommand
  448. ; blink arrow and wait for A or B to be pressed
  449. ; 06
  450. ; (no arguments)
  451. TextCommand06::
  452. ld a, [wLinkState]
  453. cp LINK_STATE_BATTLING
  454. jp z, TextCommand0D
  455. ld a, "▼"
  456. Coorda 18, 16 ; place down arrow in lower right corner of dialogue text box
  457. push bc
  458. call ManualTextScroll ; blink arrow and wait for A or B to be pressed
  459. pop bc
  460. ld a, " "
  461. Coorda 18, 16 ; overwrite down arrow with blank space
  462. pop hl
  463. jp NextTextCommand
  464. ; scroll text up one line
  465. ; 07
  466. ; (no arguments)
  467. TextCommand07::
  468. ld a, " "
  469. Coorda 18, 16 ; place blank space in lower right corner of dialogue text box
  470. call ScrollTextUpOneLine
  471. call ScrollTextUpOneLine
  472. pop hl
  473. coord bc, 1, 16 ; address of second line of dialogue text box
  474. jp NextTextCommand
  475. ; execute asm inline
  476. ; 08{code}
  477. TextCommand08::
  478. pop hl
  479. ld de, NextTextCommand
  480. push de ; return address
  481. jp hl
  482. ; print decimal number (converted from binary number)
  483. ; 09AAAABB
  484. ; AAAA = address of number
  485. ; BB
  486. ; bits 0-3 = how many digits to display
  487. ; bits 4-7 = how long the number is in bytes
  488. TextCommand09::
  489. pop hl
  490. ld a, [hli]
  491. ld e, a
  492. ld a, [hli]
  493. ld d, a
  494. ld a, [hli]
  495. push hl
  496. ld h, b
  497. ld l, c
  498. ld b, a
  499. and $0f
  500. ld c, a
  501. ld a, b
  502. and $f0
  503. swap a
  504. set BIT_LEFT_ALIGN,a
  505. ld b, a
  506. call PrintNumber
  507. ld b, h
  508. ld c, l
  509. pop hl
  510. jp NextTextCommand
  511. ; wait half a second if the user doesn't hold A or B
  512. ; 0A
  513. ; (no arguments)
  514. TextCommand0A::
  515. push bc
  516. call Joypad
  517. ld a, [hJoyHeld]
  518. and A_BUTTON | B_BUTTON
  519. jr nz, .skipDelay
  520. ld c, 30
  521. call DelayFrames
  522. .skipDelay
  523. pop bc
  524. pop hl
  525. jp NextTextCommand
  526. ; plays sounds
  527. ; this actually handles various command ID's, not just 0B
  528. ; (no arguments)
  529. TextCommand0B::
  530. pop hl
  531. push bc
  532. dec hl
  533. ld a, [hli]
  534. ld b, a ; b = command number that got us here
  535. push hl
  536. ld hl, TextCommandSounds
  537. .loop
  538. ld a, [hli]
  539. cp b
  540. jr z, .matchFound
  541. inc hl
  542. jr .loop
  543. .matchFound
  544. cp $14
  545. jr z, .pokemonCry
  546. cp $15
  547. jr z, .pokemonCry
  548. cp $16
  549. jr z, .pokemonCry
  550. ld a, [hl]
  551. call PlaySound
  552. call WaitForSoundToFinish
  553. pop hl
  554. pop bc
  555. jp NextTextCommand
  556. .pokemonCry
  557. push de
  558. ld a, [hl]
  559. call PlayCry
  560. pop de
  561. pop hl
  562. pop bc
  563. jp NextTextCommand
  564. ; format: text command ID, sound ID or cry ID
  565. TextCommandSounds::
  566. db $0B, SFX_GET_ITEM_1 ; actually plays SFX_LEVEL_UP when the battle music engine is loaded
  567. db $12, SFX_CAUGHT_MON
  568. db $0E, SFX_POKEDEX_RATING ; unused?
  569. db $0F, SFX_GET_ITEM_1 ; unused?
  570. db $10, SFX_GET_ITEM_2
  571. db $11, SFX_GET_KEY_ITEM
  572. db $13, SFX_DEX_PAGE_ADDED
  573. db $14, NIDORINA ; used in OakSpeech
  574. db $15, PIDGEOT ; used in SaffronCityText12
  575. db $16, DEWGONG ; unused?
  576. ; draw ellipses
  577. ; 0CAA
  578. ; AA = number of ellipses to draw
  579. TextCommand0C::
  580. pop hl
  581. ld a, [hli]
  582. ld d, a
  583. push hl
  584. ld h, b
  585. ld l, c
  586. .loop
  587. ld a, "…"
  588. ld [hli], a
  589. push de
  590. call Joypad
  591. pop de
  592. ld a, [hJoyHeld] ; joypad state
  593. and A_BUTTON | B_BUTTON
  594. jr nz, .skipDelay ; if so, skip the delay
  595. ld c, 10
  596. call DelayFrames
  597. .skipDelay
  598. dec d
  599. jr nz, .loop
  600. ld b, h
  601. ld c, l
  602. pop hl
  603. jp NextTextCommand
  604. ; wait for A or B to be pressed
  605. ; 0D
  606. ; (no arguments)
  607. TextCommand0D::
  608. push bc
  609. call ManualTextScroll ; wait for A or B to be pressed
  610. pop bc
  611. pop hl
  612. jp NextTextCommand
  613. ; process text commands in another ROM bank
  614. ; 17AAAABB
  615. ; AAAA = address of text commands
  616. ; BB = bank
  617. TextCommand17::
  618. pop hl
  619. ld a, [H_LOADEDROMBANK]
  620. push af
  621. ld a, [hli]
  622. ld e, a
  623. ld a, [hli]
  624. ld d, a
  625. ld a, [hli]
  626. ld [H_LOADEDROMBANK], a
  627. ld [MBC1RomBank], a
  628. push hl
  629. ld l, e
  630. ld h, d
  631. call TextCommandProcessor
  632. pop hl
  633. pop af
  634. ld [H_LOADEDROMBANK], a
  635. ld [MBC1RomBank], a
  636. jp NextTextCommand
  637. TextCommandJumpTable::
  638. dw TextCommand00
  639. dw TextCommand01
  640. dw TextCommand02
  641. dw TextCommand03
  642. dw TextCommand04
  643. dw TextCommand05
  644. dw TextCommand06
  645. dw TextCommand07
  646. dw TextCommand08
  647. dw TextCommand09
  648. dw TextCommand0A
  649. dw TextCommand0B
  650. dw TextCommand0C
  651. dw TextCommand0D