Comments are spaced out instead of tabbed out.

hg-commit-id: 201f8c76b32b
This commit is contained in:
stag019 2012-03-23 00:08:47 -04:00
parent 297cd4d822
commit aae2e7b4af

230
main.asm
View file

@ -21132,69 +21132,69 @@ SpriteSheetPointerTable: ; 0x17b27
INCBIN "baserom.gbc",$17c47,$17dad - $17c47 INCBIN "baserom.gbc",$17c47,$17dad - $17c47
SubstituteEffectHandler: ;0x17DAD SubstituteEffectHandler: ;0x17DAD
ld c, 50 ld c, 50
call DelayFrames call DelayFrames
ld hl, W_PLAYERMONMAXHP ld hl, W_PLAYERMONMAXHP
ld de, W_PLAYERSUBSITUTEHP ld de, W_PLAYERSUBSITUTEHP
ld bc, W_PLAYERBATTSTATUS2 ld bc, W_PLAYERBATTSTATUS2
ld a, [$ff00+$f3] ;whose turn? ld a, [$ff00+$f3] ;whose turn?
and a and a
jr z, .notEnemy jr z, .notEnemy
ld hl, W_ENEMYMONMAXHP ld hl, W_ENEMYMONMAXHP
ld de, W_ENEMYSUBSITUTEHP ld de, W_ENEMYSUBSITUTEHP
ld bc, W_ENEMYBATTSTATUS2 ld bc, W_ENEMYBATTSTATUS2
.notEnemy .notEnemy
ld a, [bc] ;load flags ld a, [bc] ;load flags
bit 4, a ;user already has substitute? bit 4, a ;user already has substitute?
jr nz, .alreadyHasSubstitute ;skip this code if so jr nz, .alreadyHasSubstitute ;skip this code if so
;user doesn't have a substitute [yet] ;user doesn't have a substitute [yet]
push bc push bc
ld a, [hli] ;load max hp ld a, [hli] ;load max hp
ld b, [hl] ld b, [hl]
srl a ;max hp / 4, [quarter health to remove from user] srl a ;max hp / 4, [quarter health to remove from user]
rr b rr b
srl a srl a
rr b rr b
push de push de
ld de, $fff2 ;subtract 8 to point to [current hp] instead of [max hp] ld de, $fff2 ;subtract 8 to point to [current hp] instead of [max hp]
add hl, de ;HL -= 8 add hl, de ;HL -= 8
pop de pop de
ld a, b ld a, b
ld [de], a ;save copy of HP to subtract in ccd7/ccd8 [how much HP substitute has] ld [de], a ;save copy of HP to subtract in ccd7/ccd8 [how much HP substitute has]
ld a, [hld] ;load current hp ld a, [hld] ;load current hp
sub b ;subtract [max hp / 4] sub b ;subtract [max hp / 4]
ld d, a ;save low byte result in D ld d, a ;save low byte result in D
ld a, [hl] ld a, [hl]
sbc a, 0 ;borrow from high byte if needed sbc a, 0 ;borrow from high byte if needed
pop bc pop bc
jr c, .notEnoughHP ;underflow means user would be left with negative health jr c, .notEnoughHP ;underflow means user would be left with negative health
;bug: note since it only brances on carry, it will possibly leave user with 0HP ;bug: note since it only brances on carry, it will possibly leave user with 0HP
.userHasZeroOrMoreHP .userHasZeroOrMoreHP
ldi [hl], a ;store high byte HP ldi [hl], a ;store high byte HP
ld [hl], d ;store low byte HP ld [hl], d ;store low byte HP
ld h, b ld h, b
ld l, c ld l, c
set 4, [hl] ;set bit 4 of flags, user now has substitute set 4, [hl] ;set bit 4 of flags, user now has substitute
ld a, [$d355] ;load options ld a, [$d355] ;load options
bit 7, a ;battle animation is enabled? bit 7, a ;battle animation is enabled?
ld hl, $7ba8 ;animation enabled: 0F:7BA8 ld hl, $7ba8 ;animation enabled: 0F:7BA8
ld b, $0f ld b, $0f
jr z, .animationEnabled jr z, .animationEnabled
ld hl, $56e0 ;animation disabled: 1E:56E0 ld hl, $56e0 ;animation disabled: 1E:56E0
ld b, $1e ld b, $1e
.animationEnabled .animationEnabled
call Bankswitch ;jump to routine depending on animation setting call Bankswitch ;jump to routine depending on animation setting
ld hl, UnnamedText_17e1d ;"it created a substitute" ld hl, UnnamedText_17e1d ;"it created a substitute"
call PrintText call PrintText
ld hl, $4d5a ld hl, $4d5a
ld b, $0f ld b, $0f
jp Bankswitch jp Bankswitch
.alreadyHasSubstitute .alreadyHasSubstitute
ld hl, UnnamedText_17e22 ;"x has a substitute" ld hl, UnnamedText_17e22 ;"x has a substitute"
jr .printText jr .printText
.notEnoughHP .notEnoughHP
ld hl, UnnamedText_17e27 ;"too weak to make substitute" ld hl, UnnamedText_17e27 ;"too weak to make substitute"
.printText .printText
jp PrintText jp PrintText
@ -39833,32 +39833,32 @@ UnnamedText_3ddca: ; 0x3ddca
db $50 db $50
; 0x3ddca + 5 bytes ; 0x3ddca + 5 bytes
CalculateDamage: ; 0x3ddcf CalculateDamage: ; 0x3ddcf
xor a xor a
ld hl, W_DAMAGE ;damage to eventually inflict, intitialise to zero ld hl, W_DAMAGE ;damage to eventually inflict, intitialise to zero
ldi [hl], a ldi [hl], a
ld [hl], a ld [hl], a
ld hl, W_PLAYERMOVEPOWER ld hl, W_PLAYERMOVEPOWER
ld a, [hli] ;*read attack base power ld a, [hli] ;*read attack base power
and a and a
ld d, a ;*D = attack base, used later ld d, a ;*D = attack base, used later
ret z ;return if attack is zero ret z ;return if attack is zero
ld a, [hl] ;*test attacking type ld a, [hl] ;*test attacking type
cp a, $14 ;types >= $14 are all special cp a, $14 ;types >= $14 are all special
jr nc, .specialAttack jr nc, .specialAttack
.physicalAttack .physicalAttack
ld hl, W_ENEMYMONDEFENSE ;opponent defense ld hl, W_ENEMYMONDEFENSE ;opponent defense
ld a, [hli] ;*BC = opponent defense used later ld a, [hli] ;*BC = opponent defense used later
ld b, a ld b, a
ld c, [hl] ld c, [hl]
ld a, [W_ENEMYBATTSTATUS3] ;test for reflect ld a, [W_ENEMYBATTSTATUS3] ;test for reflect
bit 2, a bit 2, a
jr z, .next\@ jr z, .next\@
.doubleDefense .doubleDefense
sla c ;x2 defense if bit2 of D069 is set sla c ;x2 defense if bit2 of D069 is set
rl b rl b
.next\@ .next\@
ld hl, $d025 ;attack pointer ld hl, $d025 ;attack pointer
ld a, [$d05e] ld a, [$d05e]
and a and a
jr z, .next3\@ jr z, .next3\@
@ -39876,21 +39876,21 @@ CalculateDamage: ; 0x3ddcf
pop bc pop bc
jr .next3\@ jr .next3\@
.specialAttack .specialAttack
ld hl, W_ENEMYMONSPECIAL ;opponent special ld hl, W_ENEMYMONSPECIAL ;opponent special
ld a, [hli] ;*BC = opponent special defense used later ld a, [hli] ;*BC = opponent special defense used later
ld b, a ld b, a
ld c, [hl] ld c, [hl]
ld a, [W_ENEMYBATTSTATUS3] ;test for lightscreen ld a, [W_ENEMYBATTSTATUS3] ;test for lightscreen
bit 1, a bit 1, a
jr z, .next2\@ jr z, .next2\@
.doubleSpecialDefense .doubleSpecialDefense
sla c ;x2 special defense if bit1 of D069 set sla c ;x2 special defense if bit1 of D069 set
rl b rl b
.next2\@ .next2\@
ld hl, $d02b ld hl, $d02b
ld a, [$d05e] ;XXX ld a, [$d05e] ;XXX
and a and a
jr z, .next3\@ ;skip portion of code that pulls up inactive pokemon jr z, .next3\@ ;skip portion of code that pulls up inactive pokemon
.loadOtherPoke .loadOtherPoke
ld c, 5 ld c, 5
call $5f1c call $5f1c
@ -39905,98 +39905,98 @@ CalculateDamage: ; 0x3ddcf
call AddNTimes call AddNTimes
pop bc pop bc
.next3\@ .next3\@
ld a, [hli] ;HL: when this was taken ld a, [hli] ;HL: when this was taken
ld l, [hl] ld l, [hl]
ld h, a ;*HL = attacker attack ld h, a ;*HL = attacker attack
or b ;is either attack or defense high byte nonzero? or b ;is either attack or defense high byte nonzero?
jr z, .next4\@ jr z, .next4\@
srl b ;[defense] BC /= 4 [this is just so it fits into a single byte, 10bits max] srl b ;[defense] BC /= 4 [this is just so it fits into a single byte, 10bits max]
rr c rr c
srl b srl b
rr c rr c
srl h ;[attack] HL /= 4 [to apply equal scaling] srl h ;[attack] HL /= 4 [to apply equal scaling]
rr l rr l
srl h srl h
rr l rr l
ld a, l ld a, l
or h or h
jr nz, .next4\@ ;is HL result zero? jr nz, .next4\@ ;is HL result zero?
inc l ;minimum HL = 1 inc l ;minimum HL = 1
.next4\@ .next4\@
ld b, l ;*B = attack [possibly scaled] [C contains defense] ld b, l ;*B = attack [possibly scaled] [C contains defense]
ld a, [$d022] ;*E = level ld a, [$d022] ;*E = level
ld e, a ld e, a
ld a, [$d05e] ;critical hit? ld a, [$d05e] ;critical hit?
and a and a
jr z, .next5\@ jr z, .next5\@
sla e ;double level if it was a critical hit sla e ;double level if it was a critical hit
.next5\@ .next5\@
ld a, 1 ;return Z = 0 ld a, 1 ;return Z = 0
and a and a
ret ret
INCBIN "baserom.gbc",$3de75,$3df65 - $3de75 INCBIN "baserom.gbc",$3de75,$3df65 - $3de75
MoreCalculateDamage: ;$3df65 MoreCalculateDamage: ;$3df65
ld a, [$ff00+$f3] ;FFF3 decides which address to use ld a, [$ff00+$f3] ;FFF3 decides which address to use
and a and a
ld a, [W_PLAYERMOVEEFFECT] ld a, [W_PLAYERMOVEEFFECT]
jr z, .next\@ jr z, .next\@
ld a, [$cfcd] ld a, [$cfcd]
.next\@ .next\@
cp a, 7 ;effect to halve opponent defense [suicide moves] cp a, 7 ;effect to halve opponent defense [suicide moves]
jr nz, .next2\@ jr nz, .next2\@
.halveDefense .halveDefense
srl c ;explosion and selfdestruct will halve the defense... srl c ;explosion and selfdestruct will halve the defense...
jr nz, .next2\@ jr nz, .next2\@
inc c ;...with a minimum value of 1 [it is used as a divisor later on] inc c ;...with a minimum value of 1 [it is used as a divisor later on]
.next2\@ .next2\@
cp a, $1d cp a, $1d
jr z, .next3\@ jr z, .next3\@
cp a, $1e cp a, $1e
jr z, .next3\@ jr z, .next3\@
cp a, $26 ;OHKO? cp a, $26 ;OHKO?
jp z, $6016 jp z, $6016
ld a, d ;if attack base power zero then do nothing ld a, d ;if attack base power zero then do nothing
and a and a
ret z ret z
.next3\@ .next3\@
xor a xor a
ld hl, $ff95 ;multiplication address ld hl, $ff95 ;multiplication address
ldi [hl], a ;init to zero ldi [hl], a ;init to zero
ldi [hl], a ldi [hl], a
ld [hl], a ld [hl], a
ld a, e ld a, e
add a ;A = level *2 add a ;A = level *2
jr nc, .noCarry jr nc, .noCarry
.carry .carry
push af push af
ld a, 1 ;add carry for level if needed ld a, 1 ;add carry for level if needed
ld [hl], a ;level high byte [previously zero] ld [hl], a ;level high byte [previously zero]
pop af pop af
.noCarry .noCarry
inc hl inc hl
ldi [hl], a ;level low byte ldi [hl], a ;level low byte
ld a, 5 ;[divisor] = 5 ld a, 5 ;[divisor] = 5
ldd [hl], a ldd [hl], a
push bc push bc
ld b, 4 ld b, 4
call Divide ;divide level by 5 call Divide ;divide level by 5
pop bc pop bc
inc [hl] ;+2 [?] inc [hl] ;+2 [?]
inc [hl] inc [hl]
inc hl ;8bit multiplier inc hl ;8bit multiplier
ld [hl], d ld [hl], d
call Multiply ;*multiply by attack base power call Multiply ;*multiply by attack base power
ld [hl], b ld [hl], b
call Multiply ;*multiply by attacker attack stat call Multiply ;*multiply by attacker attack stat
ld [hl], c ld [hl], c
ld b, 4 ld b, 4
call Divide ;*divide by defender defense stat call Divide ;*divide by defender defense stat
ld [hl], $32 ld [hl], $32
ld b, 4 ld b, 4
call Divide ;divide above result by 50 call Divide ;divide above result by 50
ld hl, W_DAMAGE ;[stuff below I never got to, was only interested in stuff above] ld hl, W_DAMAGE ;[stuff below I never got to, was only interested in stuff above]
INCBIN "baserom.gbc",$3dfc0,$3e04f - $3dfc0 INCBIN "baserom.gbc",$3dfc0,$3e04f - $3dfc0
@ -41015,23 +41015,23 @@ PlayMoveAnimation: ; 6F07
INCBIN "baserom.gbc",$3ef12,$3f138 - $3ef12 INCBIN "baserom.gbc",$3ef12,$3f138 - $3ef12
JumpMoveEffect: ;$3f138 JumpMoveEffect: ;$3f138
ld a, [$ff00+$f3] ;whose turn? ld a, [$ff00+$f3] ;whose turn?
and a and a
ld a, [W_PLAYERMOVEEFFECT] ld a, [W_PLAYERMOVEEFFECT]
jr z, .next1\@ jr z, .next1\@
ld a, [W_ENEMYMOVEEFFECT] ld a, [W_ENEMYMOVEEFFECT]
.next1\@ .next1\@
dec a ;subtract 1, there is no special effect for 00 dec a ;subtract 1, there is no special effect for 00
add a ;x2, 16bit pointers add a ;x2, 16bit pointers
ld hl, $7150 ;pointer table at 7150 ld hl, $7150 ;pointer table at 7150
ld b, 0 ld b, 0
ld c, a ld c, a
add hl, bc add hl, bc
ld a, [hli] ld a, [hli]
ld h, [hl] ld h, [hl]
ld l, a ld l, a
jp [hl] ;jump to special effect handler jp [hl] ;jump to special effect handler
INCBIN "baserom.gbc",$3f150,$3f245 - $3f150 INCBIN "baserom.gbc",$3f150,$3f245 - $3f150
@ -41062,65 +41062,65 @@ INCBIN "baserom.gbc",$3f2e9,$3f30c - $3f2e9
FreezeBurnParalyzeEffect: ;0x3f30c FreezeBurnParalyzeEffect: ;0x3f30c
xor a xor a
ld [$cc5b], a ld [$cc5b], a
call $7b79 ;test bit 4 of d063/d068 flags [target has substitute flag] call $7b79 ;test bit 4 of d063/d068 flags [target has substitute flag]
ret nz ;return if they have a substitute, can't effect them ret nz ;return if they have a substitute, can't effect them
ld a, [$ff00+$f3] ;whose turn? ld a, [$ff00+$f3] ;whose turn?
and a and a
jp nz, opponentAttacker jp nz, opponentAttacker
ld a, [W_ENEMYMONSTATUS] ld a, [W_ENEMYMONSTATUS]
and a and a
jp nz, CheckDefrost jp nz, CheckDefrost
;opponent has no existing status ;opponent has no existing status
ld a, [W_PLAYERMOVETYPE] ld a, [W_PLAYERMOVETYPE]
ld b, a ld b, a
ld a, [W_ENEMYMONTYPE1] ld a, [W_ENEMYMONTYPE1]
cp b cp b
ret z ;return if they match [can't freeze an ice type etc.] ret z ;return if they match [can't freeze an ice type etc.]
ld a, [W_ENEMYMONTYPE2] ld a, [W_ENEMYMONTYPE2]
cp b cp b
ret z ;return.. ret z ;return..
ld a, [W_PLAYERMOVEEFFECT] ld a, [W_PLAYERMOVEEFFECT]
cp a, 7 ;10% status effects are 04, 05, 06 so 07 will set carry for those cp a, 7 ;10% status effects are 04, 05, 06 so 07 will set carry for those
ld b, $1a ;[1A-1]/100 or [26-1]/256 = 9.8%~ chance ld b, $1a ;[1A-1]/100 or [26-1]/256 = 9.8%~ chance
jr c, .next1\@ ;branch ahead if this is a 10% chance effect.. jr c, .next1\@ ;branch ahead if this is a 10% chance effect..
ld b, $4d ;..or use [4D-1]/100 or [76-1]/256 = 29.7%~ chance ld b, $4d ;..or use [4D-1]/100 or [76-1]/256 = 29.7%~ chance
sub a, $1e ;subtract $1E to map to equivalent 10% chance effects sub a, $1e ;subtract $1E to map to equivalent 10% chance effects
.next1\@ .next1\@
push af ;push effect... push af ;push effect...
call $6e9b ;get random 8bit value for probability test call $6e9b ;get random 8bit value for probability test
cp b ;success? cp b ;success?
pop bc ;...pop effect into C pop bc ;...pop effect into C
ret nc ;do nothing if random value is >= 1A or 4D [no status applied] ret nc ;do nothing if random value is >= 1A or 4D [no status applied]
;the test passed ;the test passed
ld a, b ;what type of effect is this? ld a, b ;what type of effect is this?
cp a, BURN_SIDE_EFFECT1 cp a, BURN_SIDE_EFFECT1
jr z, .burn jr z, .burn
cp a, FREEZE_SIDE_EFFECT cp a, FREEZE_SIDE_EFFECT
jr z, .freeze jr z, .freeze
ld a, PAR ld a, PAR
ld [W_ENEMYMONSTATUS], a ld [W_ENEMYMONSTATUS], a
call $6d27 ;quarter speed of affected monster call $6d27 ;quarter speed of affected monster
ld a, $a9 ld a, $a9
call $7bb9 ;animation call $7bb9 ;animation
jp $7b6e ;print paralysis text jp $7b6e ;print paralysis text
.burn .burn
ld a, BRN ld a, BRN
ld [W_ENEMYMONSTATUS], a ld [W_ENEMYMONSTATUS], a
call $6d64 call $6d64
ld a, $a9 ld a, $a9
call $7bb9 ;animation call $7bb9 ;animation
ld hl, UnnamedText_3f3d8 ld hl, UnnamedText_3f3d8
jp PrintText jp PrintText
.freeze .freeze
call $79cf ;resets bit 5 of the D063/D068 flags call $79cf ;resets bit 5 of the D063/D068 flags
ld a, FRZ ld a, FRZ
ld [W_ENEMYMONSTATUS], a ld [W_ENEMYMONSTATUS], a
ld a, $a9 ld a, $a9
call $7bb9 ;animation call $7bb9 ;animation
ld hl, UnnamedText_3f3dd ld hl, UnnamedText_3f3dd
jp PrintText jp PrintText
opponentAttacker: ;0x3f382 opponentAttacker: ;0x3f382
ld a, [W_PLAYERMONSTATUS] ;this appears to the same as above with addresses swapped for opponent ld a, [W_PLAYERMONSTATUS] ;this appears to the same as above with addresses swapped for opponent
and a and a
jp nz, CheckDefrost jp nz, CheckDefrost
ld a, [W_ENEMYMOVETYPE] ld a, [W_ENEMYMOVETYPE]
@ -41339,15 +41339,15 @@ UnnamedText_3fb74: ; 0x3fb74
db $50 db $50
; 0x3fb74 + 5 bytes ; 0x3fb74 + 5 bytes
CheckTargetSubstitute: ;0x3fb79 CheckTargetSubstitute: ;0x3fb79
push hl push hl
ld hl, $d068 ld hl, $d068
ld a, [$ff00+$f3] ;whose turn? ld a, [$ff00+$f3] ;whose turn?
and a and a
jr z, .next1\@ jr z, .next1\@
ld hl, $d063 ld hl, $d063
.next1\@ .next1\@
bit 4, [hl] ;test bit 4 in d063/d068 flags bit 4, [hl] ;test bit 4 in d063/d068 flags
pop hl pop hl
ret ret