ref: 11556196ba546f5c45b97fffc2c263a79eb639b9
parent: a849c3557b8ee3dd2b464ccdc646aebd33d7b2a7
author: Remy Oukaour <[email protected]>
date: Tue Jan 9 11:39:36 EST 2018
Consistent sine wave code formatting
--- a/engine/battle/battle_transition.asm
+++ b/engine/battle/battle_transition.asm
@@ -640,7 +640,7 @@
.cgb
ld hl, .daypals
ld a, [TimeOfDayPal]
- and (1 << 2) - 1
+ and $3
cp 3
jr nz, .daytime
ld hl, .nightpals
@@ -754,22 +754,23 @@
StartTrainerBattle_DrawSineWave: ; 8c6f7 (23:46f7)
- and (1 << 6) - 1
- cp 1 << 5
- jr nc, .okay
- call .DoSineWave
+; a = d * sin(a * pi/32)
+ and %111111
+ cp %100000
+ jr nc, .negative
+ call .ApplySineWave
ld a, h
ret
-.okay
- and (1 << 5) - 1
- call .DoSineWave
+.negative
+ and %011111
+ call .ApplySineWave
ld a, h
- xor -1 ; cpl
+ xor $ff
inc a
ret
-.DoSineWave: ; 8c70c (23:470c)
+.ApplySineWave: ; 8c70c (23:470c)
ld e, a
ld a, d
ld d, 0
@@ -780,15 +781,15 @@
inc hl
ld d, [hl]
ld hl, 0
-.loop
+.multiply
srl a
- jr nc, .skip
+ jr nc, .even
add hl, de
-.skip
+.even
sla e
rl d
and a
- jr nz, .loop
+ jr nz, .multiply
ret
; 8c728 (23:4728)
--- a/engine/battle_anims/functions.asm
+++ b/engine/battle_anims/functions.asm
@@ -4083,11 +4083,12 @@
ret
BattleAnim_Cosine: ; ce732 (33:6732)
- add $10
+; a = d * cos(a * pi/32)
+ add %010000
BattleAnim_Sine: ; ce734 (33:6734)
-; a = d sin a
- and $3f
- cp $20
+; a = d * sin(a * pi/32)
+ and %111111
+ cp %100000
jr nc, .negative
call .ApplySineWave
ld a, h
@@ -4094,7 +4095,7 @@
ret
.negative
- and $1f
+ and %011111
call .ApplySineWave
ld a, h
xor $ff
@@ -4111,7 +4112,7 @@
ld e, [hl]
inc hl
ld d, [hl]
- ld hl, $0
+ ld hl, 0
.multiply
srl a
jr nc, .even
--- a/engine/events/celebi.asm
+++ b/engine/events/celebi.asm
@@ -238,27 +238,27 @@
CelebiEvent_Cosine: ; 49b3b (12:5b3b)
- add $10
- and $3f
- cp $20
+; a = d * cos(a * pi/32)
+ add %010000
+ and %111111
+ cp %100000
jr nc, .negative
- call .SineFunction
+ call .ApplySineWave
ld a, h
ret
.negative
- and $1f
- call .SineFunction
+ and %011111
+ call .ApplySineWave
ld a, h
xor $ff
inc a
ret
-
-.SineFunction: ; 49b52 (12:5b52)
+.ApplySineWave: ; 49b52 (12:5b52)
ld e, a
ld a, d
- ld d, $0
+ ld d, 0
ld hl, .sinewave
add hl, de
add hl, de
@@ -276,7 +276,6 @@
and a
jr nz, .multiply
ret
-
; 49b6e (12:5b6e)
.sinewave ; 49b6e
--- a/engine/routines/sine.asm
+++ b/engine/routines/sine.asm
@@ -7,7 +7,6 @@
and %111111
cp %100000
jr nc, .negative
-
call .ApplySineWave
ld a, h
ret
@@ -16,7 +15,7 @@
and %011111
call .ApplySineWave
ld a, h
- xor -1
+ xor $ff
inc a
ret
@@ -31,7 +30,6 @@
inc hl
ld d, [hl]
ld hl, 0
-
; Factor amplitude
.multiply
srl a
--- a/engine/sprites.asm
+++ b/engine/sprites.asm
@@ -576,11 +576,12 @@
Sprites_Cosine: ; 8e72a
- add $10
+; a = d * cos(a * pi/32)
+ add %010000
Sprites_Sine: ; 8e72c
-; floor(d * sin(a * pi/32))
- and $3f
- cp $20
+; a = d * sin(a * pi/32)
+ and %111111
+ cp %100000
jr nc, .negative
call .ApplySineWave
ld a, h
@@ -587,10 +588,10 @@
ret
.negative
- and $1f
+ and %011111
call .ApplySineWave
ld a, h
- xor $ff ; cpl
+ xor $ff
inc a
ret
; 8e741
@@ -610,7 +611,6 @@
srl a
jr nc, .even
add hl, de
-
.even
sla e
rl d
--- a/home/sine.asm
+++ b/home/sine.asm
@@ -1,6 +1,6 @@
Cosine:: ; 1b0f
; Return d * cos(a) in hl
- add $10 ; 90 degrees
+ add %010000 ; 90 degrees
Sine:: ; 1b11
; Return d * sin(a) in hl