diff options
Diffstat (limited to 'common.asm')
-rw-r--r-- | common.asm | 534 |
1 files changed, 455 insertions, 79 deletions
@@ -3249,7 +3249,375 @@ ProtectedDelay3: ; 0x1b3a pop bc ret -INCBIN "baserom.gbc",$1B40,$20AF - $1B40 +TextCommandProcessor: ; 1B40 + ld a,[$d358] + push af + set 1,a + ld e,a + ld a,[$fff4] + xor e + ld [$d358],a + ld a,c + ld [$cc3a],a + ld a,b + ld [$cc3b],a + +NextTextCommand: ; 1B55 + ld a,[hli] + cp a,$50 ; terminator + jr nz,.doTextCommand\@ + pop af + ld [$d358],a + ret +.doTextCommand\@ + push hl + cp a,$17 + jp z,TextCommand17 + cp a,$0e + jp nc,TextCommand0B ; if a != 0x17 and a >= 0xE, go to command 0xB +; if a < 0xE, use a jump table + ld hl,TextCommandJumpTable + 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] + +; draw box +; 04AAAABBCC +; AAAA = address of upper left corner +; BB = height +; CC = width +TextCommand04: ; 1B78 + 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 TextBoxBorder + pop hl + jr NextTextCommand + +; place string inline +; 00{string} +TextCommand00: ; 1B8A + 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 + +; place string from RAM +; 01AAAA +; AAAA = address of string +TextCommand01: ; 1B97 + 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 + +; print BCD number +; 02AAAABB +; AAAA = address of BCD number +; BB +; bits 0-4 = length in bytes +; bits 5-7 = unknown flags +TextCommand02: ; 1BA5 + 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 $15cd + ld b,h + ld c,l + pop hl + jr NextTextCommand + +; repoint destination address +; 03AAAA +; AAAA = new destination address +TextCommand03: ; 1BB7 + pop hl + ld a,[hli] + ld [$cc3a],a + ld c,a + ld a,[hli] + ld [$cc3b],a + ld b,a + jp NextTextCommand + +; repoint destination to second line of dialogue text box +; 05 +; (no arguments) +TextCommand05: ; 1BC5 + pop hl + ld bc,$c4e1 ; address of second line of dialogue text box + jp NextTextCommand + +; blink arrow and wait for A or B to be pressed +; 06 +; (no arguments) +TextCommand06: ; 1BCC + ld a,[W_ISLINKBATTLE] + cp a,$04 + jp z,TextCommand0D + ld a,$ee ; down arrow + ld [$c4f2],a ; place down arrow in lower right corner of dialogue text box + push bc + call $3898 ; blink arrow and wait for A or B to be pressed + pop bc + ld a,$7f ; blank space + ld [$c4f2],a ; overwrite down arrow with blank space + pop hl + jp NextTextCommand + +; scroll text up one line +; 07 +; (no arguments) +TextCommand07: ; 1BE7 + ld a,$7f ; blank space + ld [$c4f2],a ; place blank space in lower right corner of dialogue text box + call $1b18 ; scroll up text + call $1b18 + pop hl + ld bc,$c4e1 ; address of second line of dialogue text box + jp NextTextCommand + +; execute asm inline +; 08{code} +TextCommand08: ; 1BF9 + pop hl + ld de,NextTextCommand + push de ; return address + 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: ; 1BFF + 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 a,$0f + ld c,a + ld a,b + and a,$f0 + swap a + set 6,a + ld b,a + call $3c5f + ld b,h + ld c,l + pop hl + jp NextTextCommand + +; wait half a second if the user doesn't hold A or B +; 0A +; (no arguments) +TextCommand0A: ; 1C1D + push bc + call $019a ; update joypad state + ld a,[$ffb4] + and a,%00000011 ; A and B buttons + jr nz,.skipDelay\@ + ld c,30 + call DelayFrames +.skipDelay\@ + pop bc + pop hl + jp NextTextCommand + +; plays sounds +; this actually handles various command ID's, not just 0B +; (no arguments) +TextCommand0B: ; 1C31 + pop hl + push bc + dec hl + ld a,[hli] + ld b,a ; b = command number that got us here + push hl + ld hl,TextCommandSounds +.loop\@ + ld a,[hli] + cp b + jr z,.matchFound\@ + inc hl + jr .loop\@ +.matchFound\@ + cp a,$14 + jr z,.pokemonCry\@ + cp a,$15 + jr z,.pokemonCry\@ + cp a,$16 + jr z,.pokemonCry\@ + ld a,[hl] + call $23b1 + call $3748 + pop hl + pop bc + jp NextTextCommand +.pokemonCry\@ + push de + ld a,[hl] + call $13d0 + pop de + pop hl + pop bc + jp NextTextCommand + +; format: text command ID, sound ID or cry ID +TextCommandSounds: ; 1C64 +db $0B,$86 +db $12,$9A +db $0E,$91 +db $0F,$86 +db $10,$89 +db $11,$94 +db $13,$98 +db $14,$A8 +db $15,$97 +db $16,$78 + +; draw ellipses +; 0CAA +; AA = number of ellipses to draw +TextCommand0C: ; 1C78 + pop hl + ld a,[hli] + ld d,a + push hl + ld h,b + ld l,c +.loop\@ + ld a,$75 ; ellipsis + ld [hli],a + push de + call $019a ; update joypad state + pop de + ld a,[$ffb4] ; joypad state + and a,%00000011 ; is A or B button pressed? + jr nz,.skipDelay\@ ; if so, skip the delay + ld c,10 + call DelayFrames +.skipDelay\@ + 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: ; 1C9A + push bc + call $3898 ; wait for A or B to be pressed + pop bc + pop hl + jp NextTextCommand + +; process text commands in another ROM bank +; 17AAAABB +; AAAA = address of text commands +; BB = bank +TextCommand17: ; 1CA3 + pop hl + ld a,[$ffb8] + push af + ld a,[hli] + ld e,a + ld a,[hli] + ld d,a + ld a,[hli] + ld [$ffb8],a + ld [$2000],a + push hl + ld l,e + ld h,d + call TextCommandProcessor + pop hl + pop af + ld [$ffb8],a + ld [$2000],a + jp NextTextCommand + +TextCommandJumpTable: ; 1CC1 +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 + +; this function seems to be used only once +; it store the address of a row and column of the VRAM background map in hl +; INPUT: h - row, l - column, b - high byte of background tile map address in VRAM +GetRowColAddressBgMap: ; 1CDD + xor a + srl h + rr a + srl h + rr a + srl h + rr a + or l + ld l,a + ld a,b + or h + ld h,a + ret + +INCBIN "baserom.gbc",$1CF0,$20AF - $1CF0 DelayFrame: ; 20AF ; delay for one frame @@ -4083,7 +4451,7 @@ MoveSprite: ; 363A .loop\@ ld a,[de] - ldi [hl],a + ld [hli],a inc de inc c cp a,$FF ; have we reached the end of the movement data? @@ -10956,11 +11324,12 @@ ItemUseBall: ; 03:5687 ld [$d11c],a ld a,[W_BATTLETYPE] cp a,2 ;SafariBattle - jr nz,.next2\@ + jr nz,.skipSafariZoneCode\@ +.safariZone\@ ; remove a Safari Ball from inventory ld hl,W_NUMSAFARIBALLS dec [hl] -.next2\@ ;$56b6 +.skipSafariZoneCode\@ ;$56b6 call GoPAL_SET_CF1C ld a,$43 ld [$d11e],a @@ -10974,62 +11343,69 @@ ItemUseBall: ; 03:5687 jp z,$5801 ld a,[W_BATTLETYPE] dec a - jr nz,.next3\@ - ld hl,W_GRASSRATE ;backups wildMon data + jr nz,.notOldManBattle\@ +.oldManBattle\@ + ld hl,W_GRASSRATE ld de,W_PLAYERNAME ld bc,11 - call CopyData + call CopyData ; save the player's name in the Wild Monster data (part of the Cinnabar Island Missingno glitch) jp .BallSuccess\@ ;$578b -.next3\@ ;$56e9 +.notOldManBattle\@ ;$56e9 ld a,[W_CURMAP] - cp a,$93 ;MonTower 6F - jr nz,.next4\@ + cp a,POKEMONTOWER_6 + jr nz,.loop\@ ld a,[$cfd8] cp a,MAROWAK ld b,$10 jp z,$5801 -.next4\@ ;$56fa - call $3e5c ;GetRandom +; if not fighting ghost Marowak, loop until a random number in the current +; pokeball's allowed range is found +.loop\@ ;$56fa + call GenRandom ld b,a ld hl,$cf91 ld a,[hl] - cp a,MASTER_BALL;1 + cp a,MASTER_BALL jp z,.BallSuccess\@ ;$578b - cp a,POKE_BALL ;4 - jr z,.next5\@ + cp a,POKE_BALL + jr z,.checkForAilments ld a,200 cp b - jr c,.next4\@ ;get only numbers < 200 + jr c,.loop\@ ;get only numbers <= 200 for Great Ball ld a,[hl] - cp a,GREAT_BALL ;3 - jr z,.next5\@ - ld a,150 ;get only numbers < 150 + cp a,GREAT_BALL + jr z,.checkForAilments + ld a,150 ;get only numbers <= 150 for Ultra Ball cp b - jr c,.next4\@ -.next5\@ ;$571a - ld a,[$cfe9] ;status ailments + jr c,.loop\@ +.checkForAilments\@ ;$571a +; pokemon can be caught more easily with any (primary) status ailment +; Frozen/Asleep pokemon are relatively even easier to catch +; for Frozen/Asleep pokemon, any random number from 0-24 ensures a catch. +; for the others, a random number from 0-11 ensures a catch. + ld a,[W_ENEMYMONSTATUS] ;status ailments and a - jr z,.next6\@ + jr z,.noAilments\@ and a,(FRZ + SLP) ;is frozen and/or asleep? ld c,12 - jr z,.noAilments\@ + jr z,.notFrozenOrAsleep\@ ld c,25 -.noAilments\@ ;$5728 +.notFrozenOrAsleep\@ ;$5728 ld a,b sub c jp c,.BallSuccess\@ ;$578b ld b,a -.next6\@ ;$572e +.noAilments\@ ;$572e push bc ;save RANDOM number xor a - ld [$ff96],a - ld hl,$cff4 ;enemy: Max HP + ld [H_MULTIPLICAND],a + ld hl,W_ENEMYMONMAXHP ld a,[hli] - ld [$ff97],a + ld [H_MULTIPLICAND + 1],a ld a,[hl] - ld [$ff98],a + ld [H_MULTIPLICAND + 2],a ld a,255 - ld [$ff99],a + ld [H_MULTIPLIER],a call $38ac ;Multiply: MaxHP * 255 ld a,[$cf91] cp a,GREAT_BALL @@ -11037,10 +11413,10 @@ ItemUseBall: ; 03:5687 jr nz,.next7\@ ld a,8 .next7\@ ;$574d - ld [$ff99],a - ld b,4 ;GreatBall's BallFactor + ld [H_DIVISOR],a + ld b,4 ;number of significant bytes call $38b9 ;Divide - ld hl,$cfe6 ;currentHP + ld hl,W_ENEMYMONCURHP ld a,[hli] ld b,a ld a,[hl] @@ -11051,44 +11427,44 @@ ItemUseBall: ; 03:5687 srl b rr a srl b - rr a + rr a ; a = current HP / 4 and a jr nz,.next8\@ inc a .next8\@ ;$5766 - ld [$ff99],a + ld [H_DIVISOR],a ld b,4 - call $38b9 ;Divide - ld a,[$ff97] + call $38b9 ; Divide: ((MaxHP * 255) / BallFactor) / (CurHP / 4) + ld a,[H_QUOTIENT + 2] and a jr z,.next9\@ ld a,255 - ld [$ff98],a + ld [H_QUOTIENT + 3],a .next9\@ ;$5776 pop bc ld a,[$d007] ;enemy: Catch Rate cp b jr c,.next10\@ - ld a,[$ff97] + ld a,[H_QUOTIENT + 2] and a - jr nz,.BallSuccess\@ - call $3e5c ;get random number + jr nz,.BallSuccess\@ ; if ((MaxHP * 255) / BallFactor) / (CurHP / 4) > 0x255, automatic success + call GenRandom ld b,a - ld a,[$ff98] + ld a,[H_QUOTIENT + 3] cp b jr c,.next10\@ .BallSuccess\@ ;$578b jr .BallSuccess2\@ .next10\@ ;$578d - ld a,[$ff98] + ld a,[H_QUOTIENT + 3] ld [$d11e],a xor a - ld [$ff96],a - ld [$ff97],a + ld [H_MULTIPLICAND],a + ld [H_MULTIPLICAND + 1],a ld a,[$d007] ;enemy: Catch Rate - ld [$ff98],a + ld [H_MULTIPLICAND + 2],a ld a,100 - ld [$ff99],a + ld [H_MULTIPLIER],a call $38ac ;Multiply: CatchRate * 100 ld a,[$cf91] ld b,255 @@ -11102,21 +11478,21 @@ ItemUseBall: ; 03:5687 jr z,.next11\@ .next11\@ ;$57b8 ld a,b - ld [$ff99],a + ld [H_DIVISOR],a ld b,4 call $38b9 ;Divide - ld a,[$ff97] + ld a,[H_QUOTIENT + 2] and a ld b,$63 jr nz,.next12\@ ld a,[$d11e] - ld [$ff99],a + ld [H_MULTIPLIER],a call $38ac ld a,255 - ld [$ff99],a + ld [H_DIVISOR],a ld b,4 call $38b9 - ld a,[$cfe9] ;status ailments + ld a,[W_ENEMYMONSTATUS] ;status ailments and a jr z,.next13\@ and a,(FRZ + SLP) @@ -11124,11 +11500,11 @@ ItemUseBall: ; 03:5687 jr z,.next14\@ ld b,10 .next14\@ ;$57e6 - ld a,[$ff98] + ld a,[H_QUOTIENT + 3] add b - ld [$ff98],a + ld [H_QUOTIENT + 3],a .next13\@ ;$57eb - ld a,[$ff98] + ld a,[H_QUOTIENT + 3] cp a,10 ld b,$20 jr c,.next12\@ @@ -21637,17 +22013,17 @@ AIUseDireHit: ; 0x3a7c2 unused jp AIPrintItemUse Function67CF: ; 0x3a7cf 67CF - ld [$FF99],a + ld [H_DIVISOR],a ld hl,$CFF4 ld a,[hli] - ld [$FF95],a + ld [H_DIVIDEND],a ld a,[hl] - ld [$FF96],a + ld [H_DIVIDEND + 1],a ld b,2 call $38B9 - ld a,[$FF98] + ld a,[H_QUOTIENT + 3] ld c,a - ld a,[$FF97] + ld a,[H_QUOTIENT + 2] ld b,a ld hl,$CFE7 ld a,[hld] @@ -25541,25 +25917,25 @@ AdjustDamageForMoveType: ; 63A5 and a,$80 ld b,a ld a,[hl] ; a = damage multiplier - ld [$ff99],a + ld [H_MULTIPLIER],a add b ld [$d05b],a xor a - ld [$ff96],a + ld [H_MULTIPLICAND],a ld hl,W_DAMAGE ld a,[hli] - ld [$ff97],a + ld [H_MULTIPLICAND + 1],a ld a,[hld] - ld [$ff98],a + ld [H_MULTIPLICAND + 2],a call $38ac ; multiply ld a,10 - ld [$ff99],a + ld [H_DIVISOR],a ld b,$04 call $38b9 ; divide - ld a,[$ff97] + ld a,[H_QUOTIENT + 2] ld [hli],a ld b,a - ld a,[$ff98] + ld a,[H_QUOTIENT + 3] ld [hl],a or b ; is damage 0? jr nz,.skipTypeImmunity\@ @@ -25848,10 +26224,10 @@ CalcHitChance: ; 6624 ld c,a ; c = 14 - EVASIONMOD (this "reflects" the value over 7, so that an increase in the target's evasion decreases the hit chance instead of increasing the hit chance) ; zero the high bytes of the multiplicand xor a - ld [$ff96],a - ld [$ff97],a + ld [H_MULTIPLICAND],a + ld [H_MULTIPLICAND + 1],a ld a,[hl] - ld [$ff98],a ; set multiplicand to move accuracy + ld [H_MULTIPLICAND + 2],a ; set multiplicand to move accuracy push hl ld d,$02 ; loop has two iterations ; loop to do the calculations, the first iteration multiplies by the accuracy ratio and the second iteration multiplies by the evasion ratio @@ -25865,28 +26241,28 @@ CalcHitChance: ; 6624 add hl,bc ; hl = address of stat modifier ratio pop bc ld a,[hli] - ld [$ff99],a ; set multiplier to the numerator of the ratio + ld [H_MULTIPLIER],a ; set multiplier to the numerator of the ratio call $38ac ; multiply ld a,[hl] - ld [$ff99],a ; set divisor to the the denominator of the ratio (the dividend is the product of the previous multiplication) + ld [H_DIVISOR],a ; set divisor to the the denominator of the ratio (the dividend is the product of the previous multiplication) ld b,$04 ; number of significant bytes in the dividend call $38b9 ; divide - ld a,[$ff98] + ld a,[H_QUOTIENT + 3] ld b,a - ld a,[$ff97] + ld a,[H_QUOTIENT + 2] or b jp nz,.nextCalculation\@ ; make sure the result is always at least one - ld [$ff97],a + ld [H_QUOTIENT + 2],a ld a,$01 - ld [$ff98],a + ld [H_QUOTIENT + 3],a .nextCalculation\@ ld b,c dec d jr nz,.loop\@ - ld a,[$ff97] + ld a,[H_QUOTIENT + 2] and a ; is the calculated hit chance over 0xFF? - ld a,[$ff98] + ld a,[H_QUOTIENT + 3] jr z,.storeAccuracy\@ ; if calculated hit chance over 0xFF ld a,$ff ; set the hit chance to 0xFF |