ref: 67922daa1a01df7cc6d6d18c9da15c623c5f40d5
parent: f0ae1dcc352cb0f3a2867fdb56e7519ad69a0fd7
author: IIMarckus <iimarckus@gmail.com>
date: Fri Oct 29 16:48:52 EDT 2010
Expand routine that gets item name given item id hg-commit-id: 1a57150ac99a
--- a/pokered.asm
+++ b/pokered.asm
@@ -1139,8 +1139,91 @@
db $FE,7,ULTRA_BALL,GREAT_BALL,FULL_RESTORE,MAX_POTION,FULL_HEAL
db REVIVE,MAX_REPEL,$FF
-INCBIN "baserom.gbc",$24D6,$3A87 - $24D6
+INCBIN "baserom.gbc",$24D6,$2FCF - $24D6
+GetItemName: ; 2FCF
+; given an item ID at [$D11E], store the name of the item into a string
+; starting at $CD6D
+ push hl
+ push bc
+ ld a,[$D11E]
+ cp HM_01 ; is this a TM/HM?
+ jr nc,.Machine\@
+ ld [$D0B5],a
+ ld a,4
+ ld [$D0B6],a
+ ld a,1
+ ld [$D0B7],a
+ call $376B
+ jr .Finish\@
+.Machine\@
+ call GetMachineName
+.Finish\@
+ ld de,$CD6D ; pointer to where item name is stored in RAM
+ pop bc
+ pop hl
+ ret
+
+GetMachineName:
+; copies the name of the TM/HM in [$D11E] to $CD6D
+ push hl
+ push de
+ push bc
+ ld a,[$D11E]
+ push af
+ cp TM_01 ; is this a TM? [not HM]
+ jr nc,.WriteTM\@
+; if HM, then write "HM" and add 5 to the item ID, so we can reuse the
+; TM printing code
+ add 5
+ ld [$D11E],a
+ ld hl,HiddenPrefix ; points to "HM"
+ ld bc,2
+ jr .WriteMachinePrefix\@
+.WriteTM\@
+ ld hl,TechnicalPrefix ; points to "TM"
+ ld bc,2
+.WriteMachinePrefix\@
+ ld de,$CD6D
+ call CopyData
+
+; now get the machine number and convert it to text
+ ld a,[$D11E]
+ sub TM_01 - 1
+ ld b,$F6 ; "0"
+.FirstDigit\@
+ sub 10
+ jr c,.SecondDigit\@
+ inc b
+ jr .FirstDigit\@
+.SecondDigit\@
+ add 10
+ push af
+ ld a,b
+ ld [de],a
+ inc de
+ pop af
+ ld b,$F6 ; "0"
+ add b
+ ld [de],a
+ inc de
+ ld a,$50 ; text null
+ ld [de],a
+
+ pop af
+ ld [$D11E],a
+ pop bc
+ pop de
+ pop hl
+ ret
+
+TechnicalPrefix:
+ db $93,$8C ; "TM"
+HiddenPrefix:
+ db $87,$8C ; "HM"
+
+INCBIN "baserom.gbc",$3040,$3A87 - $3040
+
AddNTimes: ; 3A87
; add bc to hl a times
and a
@@ -3878,7 +3961,7 @@
; print "x used [$CF05] on z!"
ld a,[$CF05]
ld [$D11E],a
- call $2FCF ; get item name
+ call GetItemName
ld hl,AIBattleUseItemText
jp PrintText