diff options
| author | entrpntr <12521136+entrpntr@users.noreply.github.com> | 2020-06-06 15:09:50 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-06 15:09:50 -0400 |
| commit | 2c9fbba109e8347fb4641d63d0f2817371644e6f (patch) | |
| tree | 292e206b009b27f0def4280aebf90c890057ba7a /engine/events | |
| parent | 41aed88e16a138293971d63e7facfceb8f612c60 (diff) | |
| parent | afcf8f19575164e4b0fa92319041f888e719f68d (diff) | |
Merge pull request #45 from libjet/bank3e
Disassemble bank $3e
Diffstat (limited to 'engine/events')
| -rwxr-xr-x | engine/events/magikarp.asm | 314 | ||||
| -rwxr-xr-x | engine/events/name_rater.asm | 219 | ||||
| -rwxr-xr-x | engine/events/play_slow_cry.asm | 30 |
3 files changed, 563 insertions, 0 deletions
diff --git a/engine/events/magikarp.asm b/engine/events/magikarp.asm new file mode 100755 index 00000000..035148b5 --- /dev/null +++ b/engine/events/magikarp.asm @@ -0,0 +1,314 @@ +CheckMagikarpLength: + ; Returns 3 if you select a Magikarp that beats the previous record. + ; Returns 2 if you select a Magikarp, but the current record is longer. + ; Returns 1 if you press B in the Pokemon selection menu. + ; Returns 0 if the Pokemon you select is not a Magikarp. + + ; Let's start by selecting a Magikarp. + farcall SelectMonFromParty + jr c, .declined + ld a, [wCurPartySpecies] + cp MAGIKARP + jr nz, .not_magikarp + + ; Now let's compute its length based on its DVs and ID. + ld a, [wCurPartyMon] + ld hl, wPartyMon1Species + ld bc, PARTYMON_STRUCT_LENGTH + call AddNTimes + push hl + ld bc, MON_DVS + add hl, bc + ld d, h + ld e, l + pop hl + ld bc, MON_ID + add hl, bc + ld b, h + ld c, l + call CalcMagikarpLength + call PrintMagikarpLength + ld hl, .MagikarpGuruMeasureText + call PrintText + + ; Did we beat the record? + ld hl, wMagikarpLength + ld de, wBestMagikarpLengthFeet + ld c, 2 + call CompareBytes + jr nc, .not_long_enough + + ; NEW RECORD!!! Let's save that. + ld hl, wMagikarpLength + ld de, wBestMagikarpLengthFeet + ld a, [hli] + ld [de], a + inc de + ld a, [hl] + ld [de], a + inc de + ld a, [wCurPartyMon] + ld hl, wPartyMonOT + call SkipNames + call CopyBytes + ld a, MAGIKARPLENGTH_BEAT_RECORD + ld [wScriptVar], a + ret + +.not_long_enough + ld a, MAGIKARPLENGTH_TOO_SHORT + ld [wScriptVar], a + ret + +.declined + ld a, MAGIKARPLENGTH_REFUSED + ld [wScriptVar], a + ret + +.not_magikarp + xor a ; MAGIKARPLENGTH_NOT_MAGIKARP + ld [wScriptVar], a + ret + +.MagikarpGuruMeasureText: + text_far _MagikarpGuruMeasureText + text_end + +Magikarp_LoadFeetInchesChars: + ld hl, vTiles2 tile "′" ; $6e + ld de, .feetinchchars + lb bc, BANK(.feetinchchars), 2 + call Request2bpp + ret + +.feetinchchars +INCBIN "gfx/font/feet_inches.2bpp" + +PrintMagikarpLength: + call Magikarp_LoadFeetInchesChars + ld hl, wStringBuffer1 + ld de, wMagikarpLength + lb bc, PRINTNUM_LEFTALIGN | 1, 2 + call PrintNum + ld [hl], "′" + inc hl + ld de, wMagikarpLength + 1 + lb bc, PRINTNUM_LEFTALIGN | 1, 2 + call PrintNum + ld [hl], "″" + inc hl + ld [hl], "@" + ret + +CalcMagikarpLength: +; Return Magikarp's length (in feet and inches) at wMagikarpLength (big endian). +; +; input: +; de: wEnemyMonDVs +; bc: wPlayerID + +; This function is poorly commented. + +; In short, it generates a value between 190 and 1786 using +; a Magikarp's DVs and its trainer ID. This value is further +; filtered in LoadEnemyMon to make longer Magikarp even rarer. + +; The value is generated from a lookup table. +; The index is determined by the dv xored with the player's trainer id. + +; bc = rrc(dv[0]) ++ rrc(dv[1]) ^ rrc(id) + +; if bc < 10: [wMagikarpLength] = c + 190 +; if bc ≥ $ff00: [wMagikarpLength] = c + 1370 +; else: [wMagikarpLength] = z * 100 + (bc - x) / y + +; X, Y, and Z depend on the value of b as follows: + +; if b = 0: x = 310, y = 2, z = 3 +; if b = 1: x = 710, y = 4, z = 4 +; if b = 2-9: x = 2710, y = 20, z = 5 +; if b = 10-29: x = 7710, y = 50, z = 6 +; if b = 30-68: x = 17710, y = 100, z = 7 +; if b = 69-126: x = 32710, y = 150, z = 8 +; if b = 127-185: x = 47710, y = 150, z = 9 +; if b = 186-224: x = 57710, y = 100, z = 10 +; if b = 225-243: x = 62710, y = 50, z = 11 +; if b = 244-251: x = 64710, y = 20, z = 12 +; if b = 252-253: x = 65210, y = 5, z = 13 +; if b = 254: x = 65410, y = 2, z = 14 + + ; bc = rrc(dv[0]) ++ rrc(dv[1]) ^ rrc(id) + + ; id + ld h, b + ld l, c + ld a, [hli] + ld b, a + ld c, [hl] + rrc b + rrc c + + ; dv + ld a, [de] + inc de + rrca + rrca + xor b + ld b, a + + ld a, [de] + rrca + rrca + xor c + ld c, a + + ; if bc < 10: + ; de = bc + 190 + ; break + + ld a, b + and a + jr nz, .no + ld a, c + cp 10 + jr nc, .no + + ld hl, 190 + add hl, bc + ld d, h + ld e, l + jr .done + +.no + + ld hl, MagikarpLengths + ld a, 2 + ld [wTempByteValue], a + +.read + ld a, [hli] + ld e, a + ld a, [hli] + ld d, a + call .BCLessThanDE + jr nc, .next + + ; c = (bc - de) / [hl] + call .BCMinusDE + ld a, b + ldh [hDividend + 0], a + ld a, c + ldh [hDividend + 1], a + ld a, [hl] + ldh [hDivisor], a + ld b, 2 + call Divide + ldh a, [hQuotient + 3] + ld c, a + + ; de = c + 100 × (2 + i) + xor a + ldh [hMultiplicand + 0], a + ldh [hMultiplicand + 1], a + ld a, 100 + ldh [hMultiplicand + 2], a + ld a, [wTempByteValue] + ldh [hMultiplier], a + call Multiply + ld b, 0 + ldh a, [hProduct + 3] + add c + ld e, a + ldh a, [hProduct + 2] + adc b + ld d, a + jr .done + +.next + inc hl ; align to next triplet + ld a, [wTempByteValue] + inc a + ld [wTempByteValue], a + cp 16 + jr c, .read + + call .BCMinusDE + ld hl, 1600 + add hl, bc + ld d, h + ld e, l + +.done + ; convert from mm to feet and inches + ; in = mm / 25.4 + ; ft = in / 12 + + ; hl = de × 10 + ld h, d + ld l, e + add hl, hl + add hl, hl + add hl, de + add hl, hl + + ; hl = hl / 254 + ld de, -254 + ld a, -1 +.div_254 + inc a + add hl, de + jr c, .div_254 + + ; d, e = hl / 12, hl % 12 + ld d, 0 +.mod_12 + cp 12 + jr c, .ok + sub 12 + inc d + jr .mod_12 +.ok + ld e, a + + ld hl, wMagikarpLength + ld [hl], d ; ft + inc hl + ld [hl], e ; in + ret + +.BCLessThanDE: +; Intention: Return bc < de. +; Reality: Return b < d. + ld a, b + cp d + ret c + ret nc ; whoops + ld a, c + cp e + ret + +.BCMinusDE: +; bc -= de + ld a, c + sub e + ld c, a + ld a, b + sbc d + ld b, a + ret + +INCLUDE "data/events/magikarp_lengths.asm" + +MagikarpHouseSign: + ld a, [wBestMagikarpLengthFeet] + ld [wMagikarpLength], a + ld a, [wBestMagikarpLengthInches] + ld [wMagikarpLength + 1], a + call PrintMagikarpLength + ld hl, .KarpGuruRecordText + call PrintText + ret + +.KarpGuruRecordText: + text_far _KarpGuruRecordText + text_end diff --git a/engine/events/name_rater.asm b/engine/events/name_rater.asm new file mode 100755 index 00000000..e2b24c4c --- /dev/null +++ b/engine/events/name_rater.asm @@ -0,0 +1,219 @@ +_NameRater: +; Introduce himself + ld hl, NameRaterHelloText + call PrintText + call YesNoBox + jp c, .cancel +; Select a Pokemon from your party + ld hl, NameRaterWhichMonText + call PrintText + farcall SelectMonFromParty + jr c, .cancel +; He can't rename an egg... + ld a, [wCurPartySpecies] + cp EGG + jr z, .egg +; ... or a Pokemon you got from a trade. + call GetCurNick + call CheckIfMonIsYourOT + jr c, .traded +; This name is good, but we can do better. How about it? + ld hl, NameRaterBetterNameText + call PrintText + call YesNoBox + jr c, .cancel +; What name shall I give it then? + ld hl, NameRaterWhatNameText + call PrintText +; Load the new nickname into wStringBuffer2 + xor a ; PARTYMON + ld [wMonType], a + ld a, [wCurPartySpecies] + ld [wNamedObjectIndexBuffer], a + ld [wCurSpecies], a + call GetBaseData + ld b, NAME_MON + ld de, wStringBuffer2 + farcall _NamingScreen +; If the new name is empty, treat it as unchanged. + call IsNewNameEmpty + ld hl, NameRaterSameNameText + jr c, .samename +; If the new name is the same as the old name, treat it as unchanged. + call CompareNewToOld + ld hl, NameRaterSameNameText + jr c, .samename +; Copy the new name from wStringBuffer2 + ld hl, wPartyMonNicknames + ld bc, MON_NAME_LENGTH + ld a, [wCurPartyMon] + call AddNTimes + ld e, l + ld d, h + ld hl, wStringBuffer2 + ld bc, MON_NAME_LENGTH + call CopyBytes + ld hl, NameRaterFinishedText + +.samename + push hl + call GetCurNick + ld hl, NameRaterNamedText + call PrintText + pop hl + jr .done + +.traded + ld hl, NameRaterPerfectNameText + jr .done + +.cancel + ld hl, NameRaterComeAgainText + jr .done + +.egg + ld hl, NameRaterEggText + +.done + call PrintText + ret + +CheckIfMonIsYourOT: +; Checks to see if the partymon loaded in [wCurPartyMon] has the different OT as you. Returns carry if not. + ld hl, wPartyMonOT + ld bc, NAME_LENGTH + ld a, [wCurPartyMon] + call AddNTimes + ld de, wPlayerName + ld c, NAME_LENGTH + call .loop + jr c, .nope + + ld hl, wPartyMon1ID + ld bc, PARTYMON_STRUCT_LENGTH + ld a, [wCurPartyMon] + call AddNTimes + ld de, wPlayerID + ld c, 2 ; number of bytes in which your ID is stored +.loop + ld a, [de] + cp [hl] + jr nz, .nope + inc hl + inc de + dec c + jr nz, .loop + and a + ret + +.nope + scf + ret + +IsNewNameEmpty: +; Checks to see if the nickname loaded in wStringBuffer2 is empty. If so, return carry. + ld hl, wStringBuffer2 + ld c, MON_NAME_LENGTH - 1 +.loop + ld a, [hli] + cp "@" + jr z, .terminator + cp " " + jr nz, .nonspace + dec c + jr nz, .loop + +.terminator + scf + ret + +.nonspace + and a + ret + +CompareNewToOld: +; Compares the nickname in wStringBuffer2 to the previous nickname. If they are the same, return carry. + ld hl, wPartyMonNicknames + ld bc, MON_NAME_LENGTH + ld a, [wCurPartyMon] + call AddNTimes + push hl + call GetNicknameLength + ld b, c + ld hl, wStringBuffer2 + call GetNicknameLength + pop hl + ld a, c + cp b + jr nz, .different + ld de, wStringBuffer2 +.loop + ld a, [de] + cp "@" + jr z, .terminator + cp [hl] + jr nz, .different + inc hl + inc de + jr .loop + +.different + and a + ret + +.terminator + scf + ret + +GetNicknameLength: +; Gets the length of the name starting at hl and returns it in c. + ld c, 0 +.loop + ld a, [hli] + cp "@" + ret z + inc c + ld a, c + cp MON_NAME_LENGTH - 1 + jr nz, .loop + ret + +NameRaterHelloText: + text_far _NameRaterHelloText + text_end + +NameRaterWhichMonText: + text_far _NameRaterWhichMonText + text_end + +NameRaterBetterNameText: + text_far _NameRaterBetterNameText + text_end + +NameRaterWhatNameText: + text_far _NameRaterWhatNameText + text_end + +NameRaterFinishedText: + text_far _NameRaterFinishedText + text_end + +NameRaterComeAgainText: + text_far _NameRaterComeAgainText + text_end + +NameRaterPerfectNameText: + text_far _NameRaterPerfectNameText + text_end + +NameRaterEggText: + text_far _NameRaterEggText + text_end + +NameRaterSameNameText: + text_far _NameRaterSameNameText + text_end + +NameRaterNamedText: + text_far _NameRaterNamedText + text_end diff --git a/engine/events/play_slow_cry.asm b/engine/events/play_slow_cry.asm new file mode 100755 index 00000000..6839b396 --- /dev/null +++ b/engine/events/play_slow_cry.asm @@ -0,0 +1,30 @@ +PlaySlowCry: + ld a, [wScriptVar] + call LoadCry + jr c, .done + + ld hl, wCryPitch + ld a, [hli] + ld h, [hl] + ld l, a + ld bc, -$140 + add hl, bc + ld a, l + ld [wCryPitch], a + ld a, h + ld [wCryPitch + 1], a + ld hl, wCryLength + ld a, [hli] + ld h, [hl] + ld l, a + ld bc, $60 + add hl, bc + ld a, l + ld [wCryLength], a + ld a, h + ld [wCryLength + 1], a + farcall _PlayCry + call WaitSFX + +.done + ret |
