From 4c1ef2aef5dbd13f08519962764bded20a0f8929 Mon Sep 17 00:00:00 2001 From: padz Date: Tue, 11 Sep 2012 22:37:03 -0400 Subject: [PATCH 1/2] PrintLetterDelay and some battle init --- main.asm | 723 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- wram.asm | 99 +++++++- 2 files changed, 810 insertions(+), 12 deletions(-) diff --git a/main.asm b/main.asm index d65fdf9c9..4dc685c2f 100644 --- a/main.asm +++ b/main.asm @@ -125,7 +125,109 @@ EnableLCD: ; 58a ret ; 0x591 -INCBIN "baserom.gbc",$591,$e8d - $591 +INCBIN "baserom.gbc",$591,$984 - $591 + +GetJoypadState; 984 + push af + push hl + push de + push bc + ld a,[$c2c7] + cp a, $ff + jr z, .asm_9a7 + ld a,[$ff00+$a4] + ld b, a + ld a,[$ff00+$a8] + ld e, a + xor b + ld d, a + and e + ld [$ff00+$a6], a + ld a, d + and b + ld [$ff00+$a7], a + ld c, a + ld a, b + ld [$ff00+$a8], a +.asm_9a2 + pop bc + pop de + pop hl + pop af + ret +.asm_9a7 + ld a,[$ff00+$9d] + push af + ld a, [$c2ca] + rst $10 + ld hl, $c2c8 + ld a, [hli] + ld h, [hl] + ld l, a + ld a, [$c2cb] + and a + jr z, .asm_9c2 + dec a + ld [$c2cb], a + pop af + rst $10 + jr .asm_9a2 +.asm_9c2 + ld a, [hli] + cp a, $ff + jr z, .asm_9e0 + ld b, a + ld a, [hli] + ld [$c2cb], a + cp a, $ff + jr nz, .asm_9d6 + dec hl + dec hl + ld b, $00 + jr .asm_9e5 +.asm_9d6 + ld a, l + ld [$c2c8], a + ld a, h + ld [$c2c9], a + jr .asm_9e5 +.asm_9e0 + call Functiona0a + ld b, $00 +.asm_9e5 + pop af + rst $10 + ld a, b + ld [$ff00+$a7], a + ld [$ff00+$a8], a + jr .asm_9a2 + ld [$c2ca], a + ld a, l + ld [$c2c8], a + ld a, h + ld [$c2c9], a + xor a + ld [$c2cb], a + xor a + ld [$ff00+$a7], a + ld [$ff00+$a6], a + ld [$ff00+$a8], a + ld a, $ff + ld [$c2c7], a + ret +;a0a + +Functiona0a: + xor a + ld [$c2ca], a + ld [$c2c8], a + ld [$c2c9], a + ld [$c2cb], a + ld [$c2c7], a + ret +;a1b + +INCBIN "baserom.gbc",$a1b,$e8d - $a1b ; copy bc bytes from a:hl to de FarCopyBytes: @@ -355,7 +457,7 @@ CheckDict: call $13c6 .asm_1174 ld [hli], a - call $313d + call PrintLetterDelay jp NextChar ; 0x117b @@ -404,7 +506,7 @@ Char5D: ld de, $c656 jr .asm_126a ; 0x1250 $18 push de - ld de, $d47d + ld de, PlayerName call $1078 ld h, b ld l, c @@ -814,8 +916,56 @@ PrintLetterDelay: ; 313d ; This function is used to wait a short period after printing a letter to the ; screen unless the player presses the A/B button or the delay is turned off ; through the [$cfcc] or [$cfcf] flags. - INCBIN "baserom.gbc",$313d,$318c - $313d -; 0x318c + ld a, [$cfcc] + bit 4, a + ret nz + ld a, [$cfcf] + bit 1, a + ret z + push hl + push de + push bc + ld hl, $ffd8 + ld a, [hl] + push af + ld [hl], a + ld a, [$cfcf] + bit 0, a + jr z, .asm_3160 + ld a, [$cfcc] + and a, $07 + jr .asm_3162 +.asm_3160 + ld a, $01 +.asm_3162 + ld [$cfb2], a +.joypad + call GetJoypadState + ld a, [$c2d7] + and a + jr nz, .asm_317f + ld a, [$ff00+$a8] ; joypad + bit 0, a ; a + jr z, .asm_3176 + jr .asm_317a +.asm_3176 + bit 1, a ; b + jr z, .asm_317f +.asm_317a + call DelayFrame + jr .end +.asm_317f + ld a, [$cfb2] + and a + jr nz, .joypad +.end + pop af + ld [$ff00+$d8], a + pop bc + pop de + pop hl + ret +;318c CopyDataUntil: ; 318c ; Copies [hl, bc) to [de, bc - hl). @@ -10624,7 +10774,418 @@ INCBIN "baserom.gbc",$3d14e,$3ddc2 - $3d14e jp $3ad5 ; 0x3ddc8 -INCBIN "baserom.gbc",$3ddc8,$3fc8b - $3ddc8 +INCBIN "baserom.gbc",$3ddc8,$3e8eb - $3ddc8 + +Function3e8eb: ; 3e8eb +;part of battle init + xor a + ld hl, EnemyMonSpecies2 + ld bc, $0027 + call ByteFill + ld a, [InLinkBattle] + and a + jp nz, $5abd + ld a, [$cfc0] + bit 0, a + jp nz, $5abd + ld a, [EnemyMonSpecies] + ld [EnemyMonSpecies2], a + ld [$cf60], a + ld [$d108], a + call $3856 + ld a, [$d22d] + dec a + jr z, .asm_3e925 + ld a, [$d109] + ld hl, $d289 + call $3927 + ld a, [hl] + jr .asm_3e945 +.asm_3e925 + ld a, [$d230] + cp a, $0a + ld a, [$d241] + jr z, .asm_3e945 + call $2f9f + cp a, $c0 + ld a, $00 + jr c, .asm_3e945 + call $2f9f + cp a, $14 + ld a, [$d241] + jr nc, .asm_3e945 + ld a, [$d242] +.asm_3e945 + ld [EnemyMonItem], a + ld a, [$d22d] + and a + jr z, .asm_3e963 + ld a, [$c671] + bit 3, a + jr z, .asm_3e963 + ld hl, $c6f2 + ld de, EnemyMonDVs + ld a, [hli] + ld [de], a + inc de + ld a, [hl] + ld [de], a + jp .asm_3ea1a +.asm_3e963 + ld a, $09 + ld hl, $70c4 + rst $08 + ld a, [$d22d] + dec a + jr nz, .asm_3e9a8 + ld a, [$d230] + cp a, $05 + jr nz, .asm_3e996 + call $7a01 + ld a, [hl] + and a + push af + call $7a19 + inc hl + ld a, [hld] + ld c, a + ld b, [hl] + pop af + jr nz, .asm_3e9a8 + call $7a19 + inc hl + call $2f9f + ld [hld], a + ld c, a + call $2f9f + ld [hl], a + ld b, a + jr .asm_3e9a8 +.asm_3e996 + cp a, $07 + jr nz, .asm_3e9a0 + ld b, $ea + ld c, $aa + jr .asm_3e9a8 +.asm_3e9a0 + call $2f9f + ld b, a + call $2f9f + ld c, a +.asm_3e9a8 + ld hl, EnemyMonDVs + ld a, b + ld [hli], a + ld [hl], c + ld a, [$d22d] + dec a + jr nz, .asm_3ea1a + ld a, [EnemyMonSpecies] + cp a, UNOWN + jr nz, .asm_3e9c8 + ld hl, EnemyMonDVs + ld a, $2d + call $2d83 + call CheckUnownLetter + jr c, .asm_3e9a0 +.asm_3e9c8 + ld a, [EnemyMonSpecies] + cp a, MAGIKARP + jr nz, .asm_3ea1a + ld de, $d20c + ld bc, PlayerID + ld hl, Functionfbbfc + ld a, BANK(Functionfbbfc) + rst $08 + ld a, [$d1ea] + cp a, $06 + jr nz, .asm_3e9fe + call $2f8c + cp a, $0c + jr c, .asm_3e9fe + ld a, [$d1eb] + cp a, $50 + jr nc, .asm_3e9a0 + call $2f8c + cp a, $32 + jr c, .asm_3e9fe + ld a, [$d1eb] + cp a, $40 + jr nc, .asm_3e9a0 +.asm_3e9fe + ld a, [$dcb5] + cp a, $09 + jr z, .asm_3ea1a + ld a, [$dcb6] + cp a, $06 + jr z, .asm_3ea1a + call $2f8c + cp a, $64 + jr c, .asm_3ea1a + ld a, [$d1ea] + cp a, $04 + jr c, .asm_3e9a0 +.asm_3ea1a + ld a, $46 + ld [EnemyMonHappiness], a + ld a, [$d143] + ld [EnemyMonLevel], a + ld de, EnemyMonMaxHP + ld b, $00 + ld hl, $d201 + ld a, $0c + call $2d83 + ld a, [$d22d] + cp a, $02 + jr z, .asm_3ea74 + and a + jr z, .asm_3ea44 + ld a, [$c671] + bit 3, a + jp nz, .asm_3ea90 +.asm_3ea44 + call CheckSleepingWildMon + ld a, $07 + jr c, .asm_3ea4c + xor a +.asm_3ea4c + ld hl, EnemyMonStatus + ld [hli], a + xor a + ld [hli], a + ld a, [$d218] ; EnemyMonMaxHP + ld [hli], a + ld a, [$d219] ; EnemyMonMaxHP + 1 + ld [hl], a + ld a, [$d230] + cp a, $05 + jr nz, .asm_3ea90 + call $7a01 + ld a, [hl] + and a + jr z, .asm_3ea6e + ld a, [hl] + ld [$d217], a ; EnemyMonHP + 1 + jr .asm_3ea90 +.asm_3ea6e + ld a, [$d217] ; EnemyMonHP + 1 + ld [hl], a + jr .asm_3ea90 +.asm_3ea74 + ld hl, $d2ab + ld a, [$d109] + call $3927 + ld a, [hld] + ld [$d217], a ; EnemyMonHP + 1 + ld a, [hld] + ld [$d216], a ; EnemyMonHP + ld a, [$d109] + ld [$c663], a + dec hl + ld a, [hl] + ld [EnemyMonStatus], a +.asm_3ea90 + ld hl, $d23d + ld de, $d224 + ld a, [hli] + ld [de], a + inc de + ld a, [hl] + ld [de], a + ld de, EnemyMonMoves + ld a, [$d22d] + cp a, $02 + jr nz, .asm_3eab6 + ld hl, OTPartyMon1Moves + ld a, [$d109] + call $3927 + ld bc, $0004 + call CopyBytes + jr .asm_3eac5 +.asm_3eab6 + xor a + ld h, d + ld l, e + ld [hli], a + ld [hli], a + ld [hli], a + ld [hl], a + ld [$d1ea], a + ld a, $1b + call $2d83 +.asm_3eac5 + ld a, [$d22d] + cp a, $02 + jr z, .asm_3ead9 + ld hl, EnemyMonMoves + ld de, EnemyMonPP + ld a, $05 + call $2d83 + jr .asm_3eaeb +.asm_3ead9 + ld hl, $d29f + ld a, [$d109] + call $3927 + ld de, EnemyMonPP + ld bc, $0004 + call CopyBytes +.asm_3eaeb + ld hl, $d237 + ld de, $d226 + ld b, $05 +.asm_3eaf3 + ld a, [hli] + ld [de], a + inc de + dec b + jr nz, .asm_3eaf3 + ld a, [$d23f] + ld [de], a + inc de + ld a, [$d240] + ld [de], a + ld a, [EnemyMonSpecies] + ld [$d265], a + call $343b + ld a, [$d22d] + and a + ret z + ld hl, $d073 + ld de, $c616 + ld bc, $000b + call CopyBytes + ld a, [EnemyMonSpecies] + dec a + ld c, a + ld b, $01 + ld hl, $deb9 + ld a, $03 + call $2d83 + ld hl, EnemyMonAtk + ld de, $c6c1 + ld bc, $000a + call CopyBytes + ret +; 3eb38 + +CheckSleepingWildMon: ; 3eb38 + ld a, [$d230] + cp a, $08 ; headbutt encounter? + jr nz, .asm_3eb5b + ld hl, SleepingWildMonMornTable + ld a, [TimeOfDay] + cp a, $01 + jr c, .asm_3eb51 + ld hl, SleepingWildMonDayTable + jr z, .asm_3eb51 + ld hl, SleepingWildMonNiteTable +.asm_3eb51 + ld a, [EnemyMonSpecies] + ld de, $0001 + call IsInArray + ret c +.asm_3eb5b + and a + ret +; 3eb5d + +SleepingWildMonNiteTable: ; 3eb5d + db CATERPIE + db METAPOD + db BUTTERFREE + db WEEDLE + db KAKUNA + db BEEDRILL + db SPEAROW + db EKANS + db EXEGGCUTE + db LEDYBA + db AIPOM + db $ff ; end +; 3eb69 + +SleepingWildMonDayTable: ; 3eb69 + db VENONAT + db HOOTHOOT + db NOCTOWL + db SPINARAK + db HERACROSS + db $ff ; end +; 3eb6f + +SleepingWildMonMornTable ; 3eb6f + db VENONAT + db HOOTHOOT + db NOCTOWL + db SPINARAK + db HERACROSS + db $ff ; end +; 3eb75 + +CheckUnownLetter: ; 3eb75 + ld a, [$def3] + ld c, a + ld de, $0000 +.asm_3eb7c + srl c + jr nc, .asm_3eb96 + ld hl, UnownLetterPointerTable + add hl, de + ld a, [hli] + ld h, [hl] + ld l, a + push de + ld a, [$d234] + ld de, $0001 + push bc + call IsInArray + pop bc + pop de + jr c, .asm_3eb9f +.asm_3eb96 + inc e + inc e + ld a, e + cp a, $08 + jr c, .asm_3eb7c + scf + ret +.asm_3eb9f + and a + ret + +UnownLetterPointerTable: ; 3eba1 + dw UnownLetterTable + dw UnownLetterTable2 + dw UnownLetterTable3 + dw UnownLetterTable4 +; 3eba9 + +UnownLetterTable: ; 3eba9 + ; A B C D E F G H I J K + db $01, $02, $03, $04, $05, $06, $07, $08, $09, $0a, $0b + db $ff +; 3ebb5 + +UnownLetterTable2: ; 3ebb5 + ; L M N O P Q R + db $0c, $0d, $0e, $0f, $10, $11, $12 + db $ff +; 3ebbd + +UnownLetterTable3: ; 3ebbd + ; S T U V W + db $13, $14, $15, $16, $17 + db $ff +; 3ebc3 + +UnownLetterTable4: ; 3ebc3 + ; X Y Z + db $18, $19, $1a + db $ff +;3ebc7 + +INCBIN "baserom.gbc",$3ebc7,$3fc8b - $3ebc7 ; I have no clue what most of this does @@ -73086,7 +73647,153 @@ INCBIN "gfx/font.1bpp",$0,$400 FontBattleExtra: INCBIN "gfx/font_battle_extra.2bpp",$0,$200 -INCBIN "baserom.gbc",$F8800,$4000-$800 +INCBIN "baserom.gbc",$F8800,$3bfc-$800 + +Functionfbbfc ; fbbfc +;input: +; d: $d2 +; e: $0c +; b: $d4 ; PlayerID +; c: $7b ; PlayerID +; a: BANK(Functionfbbfc) $3e + ld h, b + ld l, c + ld a, [hli] + ld b, a + ld c, [hl] ; ld bc, [bc] + rrc b + rrc c + ld a, [de] + inc de + rrca + rrca + xor b + ld b, a + ld a, [de] + rrca + rrca + xor c + ld c, a + ld a, b + and a + jr nz, .asm_fbc21 + ld a, c + cp a, $0a + jr nc, .asm_fbc21 + ld hl, $00be + add hl, bc + ld d, h + ld e, l + jr .asm_fbc78 +.asm_fbc21 + ld hl, Tablefbca8 + ld a, $02 + ld [$d265], a +.asm_fbc29 + ld a, [hli] + ld e, a + ld a, [hli] + ld d, a + call Functionfbc9a + jr nc, .asm_fbc63 + call Functionfbca1 + ld a, b + ld [$ff00+$b3], a + ld a, c + ld [$ff00+$b4], a + ld a, [hl] + ld [$ff00+$b7], a + ld b, $02 + call Divide + ld a, [$ff00+$b6] + ld c, a + xor a + ld [$ff00+$b4], a + ld [$ff00+$b5], a + ld a, $64 + ld [$ff00+$b6], a + ld a, [$d265] + ld [$ff00+$b7], a + call Multiply + ld b, $00 + ld a, [$ff00+$b6] + add c + ld e, a + ld a, [$ff00+$b5] + adc b + ld d, a + jr .asm_fbc78 +.asm_fbc63 + inc hl + ld a, [$d265] + inc a + ld [$d265], a + cp a, $10 + jr c, .asm_fbc29 + call Functionfbca1 + ld hl, $0640 + add hl, bc + ld d, h + ld e, l +.asm_fbc78 + ld h, d + ld l, e + add hl, hl + add hl, hl + add hl, de + add hl, hl + ld de, $ff02 + ld a, $ff +.asm_fbc83 + inc a + add hl, de + jr c, .asm_fbc83 + ld d, $00 +.asm_fbc89 ; mod $0c + cp a, $0c + jr c, .asm_fbc92 + sub a, $0c + inc d + jr .asm_fbc89 +.asm_fbc92 + ld e, a + ld hl, $d1ea + ld [hl], d + inc hl + ld [hl], e + ret +; fbc9a + +Functionfbc9a: ; fbc9a + ld a, b + cp d + ret c + ret nc + ld a, c + cp e + ret +; fbca1 + +Functionfbca1: ; fbca1 + ld a, c + sub e + ld c, a + ld a, b + sbc d + ld b, a + ret +; fbcab + +Tablefbca8: ; fbca8 + db $6e, $00, $01, $36, $01, $02, $c6, $02 + db $04, $96, $0a, $14, $1e, $1e, $32, $2e + db $45, $64, $c6, $7f, $96, $5e, $ba, $96 + db $6e, $e1, $64, $f6, $f4, $32, $c6, $fc + db $14, $ba, $fe, $05, $82, $ff + db $02, $e6, $ff +; fbcd1 + +INCBIN "baserom.gbc",$FBCD1,$fc000-$fbcd1 SECTION "bank3F",DATA,BANK[$3F] @@ -115461,7 +116168,7 @@ UnknownText_0x1c5d03: ; 0x1c5d03 sound0 db $0, $51 db "@" - text_from_ram $d47d + text_from_ram PlayerName db $0, " sent the", $4f db "trophy home.", $58 ; 0x1c5d3e diff --git a/wram.asm b/wram.asm index 8764fedcf..3387c1ce6 100644 --- a/wram.asm +++ b/wram.asm @@ -6,7 +6,10 @@ InLinkBattle: ; 0xc2dc SECTION "BattleMons",BSS[$c62a] BattleMonSpecies: ; c62a - ds 3 ; wtf? + ds 1 + ds 1 +BattleMonSpecies2: ; c62c + ds 1 BattleMonItem: ; c62d ds 1 @@ -41,9 +44,8 @@ BattleMonHappiness: ; c638 BattleMonLevel: ; c639 ds 1 -; TODO this is probably wrong -EnemyMonPokerusStatus: ; c63a - ds 2 ; dunno +BattleMonStatus: ; c63a + ds 2 BattleMonHP: ; c63c ds 2 @@ -61,6 +63,66 @@ BattleMonSpclAtk: ; c646 BattleMonSpclDef: ; c648 ds 2 +SECTION "EnemyMon",BSS[$d204] + +EnemyMonSpecies: ; d204 + ds 1 + ds 1 +EnemyMonSpecies2: ; d206 + ds 1 +EnemyMonItem: ; d207 + ds 1 + +EnemyMonMoves: +EnemyMonMove1: ; d208 + ds 1 +EnemyMonMove2: ; d209 + ds 1 +EnemyMonMove3: ; d20a + ds 1 +EnemyMonMove4: ; d20b + ds 1 + +EnemyMonDVs: +EnemyMonAtkDefDV: ; d20c + ds 1 +EnemyMonSpdSpclDV: ; d20d + ds 1 + +EnemyMonPP: +EnemyMonPPMove1: ; d20e + ds 1 +EnemyMonPPMove2: ; d20f + ds 1 +EnemyMonPPMove3: ; d210 + ds 1 +EnemyMonPPMove4: ; d211 + ds 1 + +EnemyMonHappiness: ; d212 + ds 1 +EnemyMonLevel: ; d213 + ds 1 + +EnemyMonStatus: ; d214 + ds 2 + +EnemyMonHP: ; d216 + ds 2 +EnemyMonMaxHP: ; d218 + ds 2 + +EnemyMonAtk: ; d21a + ds 2 +EnemyMonDef: ; d21c + ds 2 +EnemyMonSpd: ; d21e + ds 2 +EnemyMonSpclAtk: ; d220 + ds 2 +EnemyMonSpclDef: ; d222 + ds 2 + SECTION "OtherTrainerClass",BSS[$d22f] OtherTrainerClass: ; 0xd22f @@ -621,6 +683,35 @@ PlayerID: ; 0xd47b PlayerName: ; 0xd47d ds 11 +PlayerSprite: ; 0xd4d8 + ds 1 + +SECTION "Misc",BSS[$d857] +Money: ; d84e + ds 3 + +Badges: ; d857 + ds 2 + +SECTION "Items",BSS[$d8bd] +TMsHMs: ; d859 + ds 57 + +NumItems: ; d892 + ds 1 +Items: ; d893 + ds 69 + +NumKeyItems: ; d88c + ds 1 +KeyItems: ; d88d + ds 13 + +NumBalls: ; d8d7 + ds 1 +Balls: ; d8d8 + ds 25 + SECTION "scriptram",BSS[$d962] MooMooBerries: ; 0xd962 ds 1 ; how many berries fed to MooMoo From e8b7789127ab6ed4ebd875d09490d57e874c3066 Mon Sep 17 00:00:00 2001 From: padz Date: Sun, 16 Sep 2012 21:20:04 -0400 Subject: [PATCH 2/2] comment last commit --- main.asm | 230 +++++++++++++++++++++++++++++++++---------------------- wram.asm | 19 +++-- 2 files changed, 151 insertions(+), 98 deletions(-) diff --git a/main.asm b/main.asm index 4dc685c2f..e6c81e152 100644 --- a/main.asm +++ b/main.asm @@ -128,16 +128,26 @@ EnableLCD: ; 58a INCBIN "baserom.gbc",$591,$984 - $591 GetJoypadState; 984 +; stores joypad state in $ffa8 +; 0 is off, 1 is on +; bit 0: A +; 1: B +; 2: SELECT +; 3: START +; 4: RIGHT +; 5: LEFT +; 6: UP +; 7: DOWN push af push hl push de push bc - ld a,[$c2c7] + ld a, [$c2c7] cp a, $ff jr z, .asm_9a7 - ld a,[$ff00+$a4] + ld a, [$ff00+$a4] ; input mask (usually 00) ld b, a - ld a,[$ff00+$a8] + ld a, [$ff00+$a8] ; joypad ld e, a xor b ld d, a @@ -149,14 +159,14 @@ GetJoypadState; 984 ld c, a ld a, b ld [$ff00+$a8], a -.asm_9a2 +.quit pop bc pop de pop hl pop af ret .asm_9a7 - ld a,[$ff00+$9d] + ld a, [$ff00+$9d] push af ld a, [$c2ca] rst $10 @@ -171,7 +181,7 @@ GetJoypadState; 984 ld [$c2cb], a pop af rst $10 - jr .asm_9a2 + jr .quit .asm_9c2 ld a, [hli] cp a, $ff @@ -200,7 +210,7 @@ GetJoypadState; 984 ld a, b ld [$ff00+$a7], a ld [$ff00+$a8], a - jr .asm_9a2 + jr .quit ld [$c2ca], a ld a, l ld [$c2c8], a @@ -218,6 +228,7 @@ GetJoypadState; 984 ;a0a Functiona0a: +; clears $c2c7-$c2cb xor a ld [$c2ca], a ld [$c2c8], a @@ -903,10 +914,26 @@ AddNTimes: ; 0x30fe INCBIN "baserom.gbc",$3105,$3119-$3105 Multiply: ; 0x3119 +; function to do multiplication +; all values are big endian +; INPUT +; ffb4-ffb6 = multiplicand +; ffb7 = multiplier +; OUTPUT +; ffb3-ffb6 = product INCBIN "baserom.gbc",$3119,$3124 - $3119 ; 0x3124 Divide: ; 0x3124 +; function to do division +; all values are big endian +; INPUT +; ffb3-ffb6 = dividend +; ffb7 = divisor +; b = number of bytes in the dividend (starting from ffb3) +; OUTPUT +; ffb4-ffb6 = quotient +; ffb7 = remainder INCBIN "baserom.gbc",$3124,$3136 - $3124 ; 0x3136 @@ -914,8 +941,9 @@ INCBIN "baserom.gbc",$3136,$313d - $3136 PrintLetterDelay: ; 313d ; This function is used to wait a short period after printing a letter to the -; screen unless the player presses the A/B button or the delay is turned off -; through the [$cfcc] or [$cfcf] flags. +; screen unless the delay is turned off through bit 4 (on) in [$cfcc] or bit +; 1 (off) in [$cfcf]. If A and B are pressed, bits 0-2 in [$cfcc] and bit 0 in +; [$cfcf] are checked. ld a, [$cfcc] bit 4, a ret nz @@ -933,31 +961,31 @@ PrintLetterDelay: ; 313d bit 0, a jr z, .asm_3160 ld a, [$cfcc] - and a, $07 + and a, $07 ; takes bits 0-2 of $cfcc jr .asm_3162 .asm_3160 ld a, $01 .asm_3162 ld [$cfb2], a -.joypad +.checkjoypad call GetJoypadState ld a, [$c2d7] and a jr nz, .asm_317f ld a, [$ff00+$a8] ; joypad - bit 0, a ; a - jr z, .asm_3176 - jr .asm_317a -.asm_3176 - bit 1, a ; b + bit 0, a ; is a pressed? + jr z, .anotpressed + jr .delay +.anotpressed + bit 1, a ; is b pressed? jr z, .asm_317f -.asm_317a +.delay call DelayFrame jr .end .asm_317f ld a, [$cfb2] and a - jr nz, .joypad + jr nz, .checkjoypad .end pop af ld [$ff00+$d8], a @@ -10732,7 +10760,7 @@ IsJohtoGymLeader: ; 0x3d128 ld hl, JohtoGymLeaders IsGymLeaderCommon: push de - ld a, [$d22f] + ld a, [OtherTrainerClass] ld de, $0001 call IsInArray pop de @@ -10802,7 +10830,7 @@ Function3e8eb: ; 3e8eb ld a, [hl] jr .asm_3e945 .asm_3e925 - ld a, [$d230] + ld a, [BattleType] cp a, $0a ld a, [$d241] jr z, .asm_3e945 @@ -10838,7 +10866,7 @@ Function3e8eb: ; 3e8eb ld a, [$d22d] dec a jr nz, .asm_3e9a8 - ld a, [$d230] + ld a, [BattleType] cp a, $05 jr nz, .asm_3e996 call $7a01 @@ -10882,22 +10910,22 @@ Function3e8eb: ; 3e8eb jr nz, .asm_3ea1a ld a, [EnemyMonSpecies] cp a, UNOWN - jr nz, .asm_3e9c8 + jr nz, .notunown ld hl, EnemyMonDVs ld a, $2d call $2d83 call CheckUnownLetter jr c, .asm_3e9a0 -.asm_3e9c8 +.notunown ld a, [EnemyMonSpecies] cp a, MAGIKARP jr nz, .asm_3ea1a - ld de, $d20c + ld de, EnemyMonDVs ld bc, PlayerID - ld hl, Functionfbbfc - ld a, BANK(Functionfbbfc) + ld hl, CalcMagikarpLength + ld a, BANK(CalcMagikarpLength) rst $08 - ld a, [$d1ea] + ld a, [$d1ea] ; Magikarp's length cp a, $06 jr nz, .asm_3e9fe call $2f8c @@ -10957,7 +10985,7 @@ Function3e8eb: ; 3e8eb ld [hli], a ld a, [$d219] ; EnemyMonMaxHP + 1 ld [hl], a - ld a, [$d230] + ld a, [BattleType] cp a, $05 jr nz, .asm_3ea90 call $7a01 @@ -11069,22 +11097,22 @@ Function3e8eb: ; 3e8eb ; 3eb38 CheckSleepingWildMon: ; 3eb38 - ld a, [$d230] - cp a, $08 ; headbutt encounter? - jr nz, .asm_3eb5b + ld a, [BattleType] + cp a, $08 ; headbutt + jr nz, .notsleeping ld hl, SleepingWildMonMornTable ld a, [TimeOfDay] - cp a, $01 - jr c, .asm_3eb51 + cp a, $01 ; day + jr c, .check ld hl, SleepingWildMonDayTable - jr z, .asm_3eb51 + jr z, .check ld hl, SleepingWildMonNiteTable -.asm_3eb51 +.check ld a, [EnemyMonSpecies] ld de, $0001 call IsInArray ret c -.asm_3eb5b +.notsleeping and a ret ; 3eb5d @@ -11123,11 +11151,12 @@ SleepingWildMonMornTable ; 3eb6f ; 3eb75 CheckUnownLetter: ; 3eb75 +; returns carry if not a valid letter ld a, [$def3] ld c, a ld de, $0000 .asm_3eb7c - srl c + srl c ; bit 0 off? jr nc, .asm_3eb96 ld hl, UnownLetterPointerTable add hl, de @@ -11141,16 +11170,16 @@ CheckUnownLetter: ; 3eb75 call IsInArray pop bc pop de - jr c, .asm_3eb9f + jr c, .end .asm_3eb96 inc e inc e ld a, e - cp a, $08 + cp a, $08 ; has the end of the table been reached? jr c, .asm_3eb7c scf ret -.asm_3eb9f +.end and a ret @@ -73649,18 +73678,23 @@ INCBIN "gfx/font_battle_extra.2bpp",$0,$200 INCBIN "baserom.gbc",$F8800,$3bfc-$800 -Functionfbbfc ; fbbfc -;input: -; d: $d2 -; e: $0c -; b: $d4 ; PlayerID -; c: $7b ; PlayerID -; a: BANK(Functionfbbfc) $3e +CalcMagikarpLength: ; fbbfc +; Stores Magikarp's length at $d1ea-$d1eb in big endian +; +; input: +; de: EnemyMonDVs +; bc: PlayerID +; output: +; $d1ea-$d1eb: length +; +; does a whole bunch of arbitrary nonsense +; cycles through a table of arbitrary values +; http://web.archive.org/web/20110628181718/http://upokecenter.com/games/gs/guides/magikarp.php ld h, b ld l, c ld a, [hli] ld b, a - ld c, [hl] ; ld bc, [bc] + ld c, [hl] ; ld bc, [PlayerID] rrc b rrc c ld a, [de] @@ -73668,35 +73702,35 @@ Functionfbbfc ; fbbfc rrca rrca xor b - ld b, a + ld b, a ; b = rrcrrc(atkdefdv) xor rrc(hipid) ld a, [de] rrca rrca xor c - ld c, a + ld c, a ; c = rrcrrc(spdspcdv) xor rrc(lopid) ld a, b and a - jr nz, .asm_fbc21 + jr nz, .loadtable ld a, c cp a, $0a - jr nc, .asm_fbc21 - ld hl, $00be - add hl, bc - ld d, h + jr nc, .loadtable + ld hl, $00be ; if bc < $000a + add hl, bc ; hl = $00be + bc + ld d, h ; de = hl ld e, l - jr .asm_fbc78 -.asm_fbc21 - ld hl, Tablefbca8 + jr .endtable +.loadtable + ld hl, MagikarpLengthTable ld a, $02 ld [$d265], a -.asm_fbc29 +.readtable ld a, [hli] ld e, a ld a, [hli] ld d, a - call Functionfbc9a - jr nc, .asm_fbc63 - call Functionfbca1 + call BLessThanD ; checks value against the table + jr nc, .advancetable + call BCMinusDE ld a, b ld [$ff00+$b3], a ld a, c @@ -73706,7 +73740,7 @@ Functionfbbfc ; fbbfc ld b, $02 call Divide ld a, [$ff00+$b6] - ld c, a + ld c, a ; c = bc / [hl] xor a ld [$ff00+$b4], a ld [$ff00+$b5], a @@ -73714,7 +73748,7 @@ Functionfbbfc ; fbbfc ld [$ff00+$b6], a ld a, [$d265] ld [$ff00+$b7], a - call Multiply + call Multiply ; $64 * (2 + number of rows down the table) ld b, $00 ld a, [$ff00+$b6] add c @@ -73722,40 +73756,40 @@ Functionfbbfc ; fbbfc ld a, [$ff00+$b5] adc b ld d, a - jr .asm_fbc78 -.asm_fbc63 - inc hl + jr .endtable +.advancetable + inc hl ; aligning to next byte triplet ld a, [$d265] inc a ld [$d265], a cp a, $10 - jr c, .asm_fbc29 - call Functionfbca1 + jr c, .readtable + call BCMinusDE ld hl, $0640 add hl, bc ld d, h ld e, l -.asm_fbc78 +.endtable ld h, d ld l, e add hl, hl add hl, hl add hl, de - add hl, hl + add hl, hl ; hl = de * 10 ld de, $ff02 ld a, $ff -.asm_fbc83 +.loop inc a - add hl, de - jr c, .asm_fbc83 + add hl, de ; - 254 + jr c, .loop ld d, $00 -.asm_fbc89 ; mod $0c +.modloop ; mod $0c cp a, $0c - jr c, .asm_fbc92 + jr c, .done sub a, $0c inc d - jr .asm_fbc89 -.asm_fbc92 + jr .modloop +.done ld e, a ld hl, $d1ea ld [hl], d @@ -73764,17 +73798,23 @@ Functionfbbfc ; fbbfc ret ; fbc9a -Functionfbc9a: ; fbc9a +BLessThanD: ; fbc9a +; returns carry if b < d ld a, b cp d ret c ret nc +; fbc9e + +CLessThanE: ;fbc9e +; unused ld a, c cp e ret ; fbca1 -Functionfbca1: ; fbca1 +BCMinusDE: ; fbca1 +; stores bc - de in bc ld a, c sub e ld c, a @@ -73782,18 +73822,28 @@ Functionfbca1: ; fbca1 sbc d ld b, a ret -; fbcab +; fbca8 -Tablefbca8: ; fbca8 - db $6e, $00, $01, $36, $01, $02, $c6, $02 - db $04, $96, $0a, $14, $1e, $1e, $32, $2e - db $45, $64, $c6, $7f, $96, $5e, $ba, $96 - db $6e, $e1, $64, $f6, $f4, $32, $c6, $fc - db $14, $ba, $fe, $05, $82, $ff - db $02, $e6, $ff -; fbcd1 +MagikarpLengthTable: ; fbca8 +; stored in sets of 3 +; first two values are little endian +; third value is the divisor + db $6e, $00, $01 + db $36, $01, $02 + db $c6, $02, $04 + db $96, $0a, $14 + db $1e, $1e, $32 + db $2e, $45, $64 + db $c6, $7f, $96 + db $5e, $ba, $96 + db $6e, $e1, $64 + db $f6, $f4, $32 + db $c6, $fc, $14 + db $ba, $fe, $05 + db $82, $ff, $02 +; fbccf -INCBIN "baserom.gbc",$FBCD1,$fc000-$fbcd1 +INCBIN "baserom.gbc",$FBCCF,$fc000-$fbccf SECTION "bank3F",DATA,BANK[$3F] diff --git a/wram.asm b/wram.asm index 3387c1ce6..00acd048f 100644 --- a/wram.asm +++ b/wram.asm @@ -130,8 +130,9 @@ OtherTrainerClass: ; 0xd22f ; 0 if opponent is a wild Pokémon, not a trainer ds 1 -Wramd230: ; 0xd230 -; XXX what is this for +BattleType: ; 0xd230 +; 00 trainer +; 08 headbutt ds 1 OtherTrainerID: ; 0xd231 @@ -139,7 +140,7 @@ OtherTrainerID: ; 0xd231 ; (Joey, Mikey, Albert, etc.) ds 1 -SECTION "Timeofday",BSS[$d269] +SECTION "TimeOfDay",BSS[$d269] TimeOfDay: ; 0xd269 ; 0 if morn @@ -686,14 +687,14 @@ PlayerName: ; 0xd47d PlayerSprite: ; 0xd4d8 ds 1 -SECTION "Misc",BSS[$d857] +SECTION "Status",BSS[$d84e] Money: ; d84e ds 3 Badges: ; d857 ds 2 -SECTION "Items",BSS[$d8bd] +SECTION "Items",BSS[$d859] TMsHMs: ; d859 ds 57 @@ -702,9 +703,9 @@ NumItems: ; d892 Items: ; d893 ds 69 -NumKeyItems: ; d88c +NumKeyItems: ; d8bc ds 1 -KeyItems: ; d88d +KeyItems: ; d8bd ds 13 NumBalls: ; d8d7 @@ -801,12 +802,13 @@ PartySpecies: ; 0xdcd8 ds 1 ; any empty slots including the 7th must be FF ; or the routine will keep going - +PartyMons: PartyMon1: PartyMon1Species: ; 0xdcdf ds 1 PartyMon1Item: ; 0xdce0 ds 1 + PartyMon1Moves: ; 0xdce1 PartyMon1Move1: ; 0xdce1 ds 1 @@ -816,6 +818,7 @@ PartyMon1Move3: ; 0xdce3 ds 1 PartyMon1Move4: ; 0xdce4 ds 1 + PartyMon1ID: ; 0xdce5 ds 2 PartyMon1Exp: ; 0xdce7