ref: 9f7c4ef0b4b907c28787be9f0da17e02731d4079
parent: 5b38b377f2eb4fc412022f1631bd882ba4b3339e
author: yenatch <[email protected]>
date: Sun Sep 1 20:12:27 EDT 2013
Sine and Cosine
--- a/main.asm
+++ b/main.asm
@@ -1307,18 +1307,22 @@
; 1b0f
-Function1b0f: ; 1b0f
- add $10
+Cosine: ; 1b0f
+; Return d * cos(a) in hl
+ add $10 ; 90 degrees
-Function1b11: ; 1b11
+Sine: ; 1b11
+; Return d * sin(a) in hl
+; a is a signed 6-bit value.
+
ld e, a
ld a, [hROMBank]
push af
- ld a, BANK(Function84d9)
+ ld a, BANK(_Sine)
rst Bankswitch
- call Function84d9
+ call _Sine
pop af
rst Bankswitch
@@ -1325,6 +1329,7 @@
ret
; 1b1e
+
Function1b1e: ; 1b1e
ld [$d003], a
xor a
@@ -11138,7 +11143,7 @@
inc [hl]
ld a, [hl]
ld d, $60
- call Function1b11
+ call Sine
ld a, h
sub $60
ld hl, $001a
@@ -11211,7 +11216,7 @@
inc [hl]
ld a, [hl]
ld d, $60
- call Function1b11
+ call Sine
ld a, h
sub $60
ld hl, $001a
@@ -11302,7 +11307,7 @@
inc [hl]
ld a, [hl]
ld d, $60
- call Function1b11
+ call Sine
ld a, h
sub $60
ld hl, $001a
@@ -17031,17 +17036,22 @@
ret
; 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
- and $3f
- cp $20
- jr nc, .asm_84e5
+ and %111111
+ cp %100000
+ jr nc, .negative
+
call Function84ef
ld a, h
ret
-.asm_84e5
- and $1f
+.negative
+ and %011111
call Function84ef
ld a, h
xor $ff
@@ -17053,7 +17063,7 @@
ld e, a
ld a, d
ld d, 0
- ld hl, $450b
+ ld hl, SineWave
add hl, de
add hl, de
ld e, [hl]
@@ -17060,20 +17070,29 @@
inc hl
ld d, [hl]
ld hl, 0
-.asm_84fe
+
+; Factor amplitude
+.multiply
srl a
- jr nc, .asm_8503
+ jr nc, .even
add hl, de
-
-.asm_8503
+.even
sla e
rl d
and a
- jr nz, .asm_84fe
+ jr nz, .multiply
ret
; 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