diff options
author | yenatch <yenatch@gmail.com> | 2017-12-24 20:29:55 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-24 20:29:55 -0500 |
commit | c2a7216d9b8689591ede817015bf96f263396bb8 (patch) | |
tree | 008635aac62c3fdbb446453d308c2255fb0554d9 /engine/routines/sine.asm | |
parent | 0b8b6f9259bedacad55bb4667de5b2bbe6eafda7 (diff) | |
parent | c6b12b07b302b82765181b2521e1e0f2ca5f7725 (diff) |
Merge pull request #424 from roukaour/master
Rename a routine and some maps; remove all code from main.asm
Diffstat (limited to 'engine/routines/sine.asm')
-rwxr-xr-x | engine/routines/sine.asm | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/engine/routines/sine.asm b/engine/routines/sine.asm new file mode 100755 index 000000000..89a905d2e --- /dev/null +++ b/engine/routines/sine.asm @@ -0,0 +1,50 @@ +_Sine:: ; 84d9 +; A simple sine function. +; Return d * sin(e) in hl. + +; e is a signed 6-bit value. + ld a, e + and %111111 + cp %100000 + jr nc, .negative + + call .ApplySineWave + ld a, h + ret + +.negative + and %011111 + call .ApplySineWave + ld a, h + xor -1 + inc a + ret + +.ApplySineWave: ; 84ef + ld e, a + ld a, d + ld d, 0 + ld hl, .sinewave + add hl, de + add hl, de + ld e, [hl] + inc hl + ld d, [hl] + ld hl, 0 + +; Factor amplitude +.multiply + srl a + jr nc, .even + add hl, de +.even + sla e + rl d + and a + jr nz, .multiply + ret + +.sinewave ; 850b +; A $20-word table representing a sine wave. +; 90 degrees is index $10 at a base amplitude of $100. + sine_wave $100 |