mirror of https://github.com/pret/pokecrystal.git
Sine and Cosine
This commit is contained in:
parent
5b38b377f2
commit
9f7c4ef0b4
63
main.asm
63
main.asm
|
@ -1307,24 +1307,29 @@ GetSpriteDirection: ; 1b07
|
||||||
; 1b0f
|
; 1b0f
|
||||||
|
|
||||||
|
|
||||||
Function1b0f: ; 1b0f
|
Cosine: ; 1b0f
|
||||||
add $10
|
; Return d * cos(a) in hl
|
||||||
|
add $10 ; 90 degrees
|
||||||
|
|
||||||
|
Sine: ; 1b11
|
||||||
|
; Return d * sin(a) in hl
|
||||||
|
; a is a signed 6-bit value.
|
||||||
|
|
||||||
Function1b11: ; 1b11
|
|
||||||
ld e, a
|
ld e, a
|
||||||
|
|
||||||
ld a, [hROMBank]
|
ld a, [hROMBank]
|
||||||
push af
|
push af
|
||||||
ld a, BANK(Function84d9)
|
ld a, BANK(_Sine)
|
||||||
rst Bankswitch
|
rst Bankswitch
|
||||||
|
|
||||||
call Function84d9
|
call _Sine
|
||||||
|
|
||||||
pop af
|
pop af
|
||||||
rst Bankswitch
|
rst Bankswitch
|
||||||
ret
|
ret
|
||||||
; 1b1e
|
; 1b1e
|
||||||
|
|
||||||
|
|
||||||
Function1b1e: ; 1b1e
|
Function1b1e: ; 1b1e
|
||||||
ld [$d003], a
|
ld [$d003], a
|
||||||
xor a
|
xor a
|
||||||
|
@ -11138,7 +11143,7 @@ Function4c5d: ; 4c5d
|
||||||
inc [hl]
|
inc [hl]
|
||||||
ld a, [hl]
|
ld a, [hl]
|
||||||
ld d, $60
|
ld d, $60
|
||||||
call Function1b11
|
call Sine
|
||||||
ld a, h
|
ld a, h
|
||||||
sub $60
|
sub $60
|
||||||
ld hl, $001a
|
ld hl, $001a
|
||||||
|
@ -11211,7 +11216,7 @@ Function4cc9: ; 4cc9
|
||||||
inc [hl]
|
inc [hl]
|
||||||
ld a, [hl]
|
ld a, [hl]
|
||||||
ld d, $60
|
ld d, $60
|
||||||
call Function1b11
|
call Sine
|
||||||
ld a, h
|
ld a, h
|
||||||
sub $60
|
sub $60
|
||||||
ld hl, $001a
|
ld hl, $001a
|
||||||
|
@ -11302,7 +11307,7 @@ Function4d4f: ; 4d4f
|
||||||
inc [hl]
|
inc [hl]
|
||||||
ld a, [hl]
|
ld a, [hl]
|
||||||
ld d, $60
|
ld d, $60
|
||||||
call Function1b11
|
call Sine
|
||||||
ld a, h
|
ld a, h
|
||||||
sub $60
|
sub $60
|
||||||
ld hl, $001a
|
ld hl, $001a
|
||||||
|
@ -17031,17 +17036,22 @@ Function849d: ; 849d
|
||||||
ret
|
ret
|
||||||
; 84d9
|
; 84d9
|
||||||
|
|
||||||
Function84d9: ; 84d9
|
_Sine: ; 84d9
|
||||||
|
; A simple sine function.
|
||||||
|
; Return d * sin(e) in hl.
|
||||||
|
|
||||||
|
; e is a signed 6-bit value.
|
||||||
ld a, e
|
ld a, e
|
||||||
and $3f
|
and %111111
|
||||||
cp $20
|
cp %100000
|
||||||
jr nc, .asm_84e5
|
jr nc, .negative
|
||||||
|
|
||||||
call Function84ef
|
call Function84ef
|
||||||
ld a, h
|
ld a, h
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.asm_84e5
|
.negative
|
||||||
and $1f
|
and %011111
|
||||||
call Function84ef
|
call Function84ef
|
||||||
ld a, h
|
ld a, h
|
||||||
xor $ff
|
xor $ff
|
||||||
|
@ -17053,27 +17063,36 @@ Function84ef: ; 84ef
|
||||||
ld e, a
|
ld e, a
|
||||||
ld a, d
|
ld a, d
|
||||||
ld d, 0
|
ld d, 0
|
||||||
ld hl, $450b
|
ld hl, SineWave
|
||||||
add hl, de
|
add hl, de
|
||||||
add hl, de
|
add hl, de
|
||||||
ld e, [hl]
|
ld e, [hl]
|
||||||
inc hl
|
inc hl
|
||||||
ld d, [hl]
|
ld d, [hl]
|
||||||
ld hl, 0
|
ld hl, 0
|
||||||
.asm_84fe
|
|
||||||
srl a
|
|
||||||
jr nc, .asm_8503
|
|
||||||
add hl, de
|
|
||||||
|
|
||||||
.asm_8503
|
; Factor amplitude
|
||||||
|
.multiply
|
||||||
|
srl a
|
||||||
|
jr nc, .even
|
||||||
|
add hl, de
|
||||||
|
.even
|
||||||
sla e
|
sla e
|
||||||
rl d
|
rl d
|
||||||
and a
|
and a
|
||||||
jr nz, .asm_84fe
|
jr nz, .multiply
|
||||||
ret
|
ret
|
||||||
; 850b
|
; 850b
|
||||||
|
|
||||||
INCBIN "baserom.gbc", $850b, $854b - $850b
|
SineWave: ; 850b
|
||||||
|
; A $20-word table representing a sine wave.
|
||||||
|
; 90 degrees is index $10 at a base amplitude of $100.
|
||||||
|
x set 0
|
||||||
|
rept $20
|
||||||
|
dw (sin(x) + (sin(x) & $ff)) >> 8 ; round up
|
||||||
|
x set x + $100 * $40000
|
||||||
|
endr
|
||||||
|
; 854b
|
||||||
|
|
||||||
|
|
||||||
GetPredefFn: ; 854b
|
GetPredefFn: ; 854b
|
||||||
|
|
Loading…
Reference in New Issue