diff options
author | IIMarckus <iimarckus@gmail.com> | 2019-08-16 01:03:03 -0600 |
---|---|---|
committer | IIMarckus <iimarckus@gmail.com> | 2019-08-16 01:03:03 -0600 |
commit | 2176239aa565126b528facc9041ed3b58eaade90 (patch) | |
tree | 4589377cff104542abb2ee309496b5e4786eb59f /macros | |
parent | 901e6f25deda73fa7053942d7d094108a73e2bea (diff) |
Incorporate the rest of the audio engine.
Diffstat (limited to 'macros')
-rw-r--r-- | macros/code.asm | 106 | ||||
-rwxr-xr-x | macros/wram.asm | 24 |
2 files changed, 117 insertions, 13 deletions
diff --git a/macros/code.asm b/macros/code.asm new file mode 100644 index 00000000..9429884c --- /dev/null +++ b/macros/code.asm @@ -0,0 +1,106 @@ +; Syntactic sugar macros + +lb: MACRO ; r, hi, lo + ld \1, ((\2) & $ff) << 8 | ((\3) & $ff) +ENDM + +ln: MACRO ; r, hi, lo + ld \1, ((\2) & $f) << 4 | ((\3) & $f) +ENDM + +ldpixel: MACRO +if _NARG >= 5 + lb \1, \2 * 8 + \4, \3 * 8 + \5 +else + lb \1, \2 * 8, \3 * 8 +endc +ENDM + +depixel EQUS "ldpixel de," +bcpixel EQUS "ldpixel bc," + +; Design patterns + +jumptable: MACRO + ld a, [\2] + ld e, a + ld d, 0 + ld hl, \1 + add hl, de + add hl, de + ld a, [hli] + ld h, [hl] + ld l, a + jp hl +ENDM + +maskbits: MACRO +; masks just enough bits to cover the first argument +; the second argument is an optional shift amount +; e.g. "maskbits 26" becomes "and %00011111" (since 26 - 1 = %00011001) +; and "maskbits 3, 2" becomes "and %00001100" (since "maskbits 3" becomes %00000011) +; example usage in rejection sampling: +; .loop +; call Random +; maskbits 26 +; cp 26 +; jr nc, .loop +x = 1 +rept 8 +if x + 1 < (\1) +x = x << 1 | 1 +endc +endr +if _NARG == 2 + and x << (\2) +else + and x +endc +ENDM + +calc_sine_wave: MACRO +; input: a = a signed 6-bit value +; output: a = d * sin(a * pi/32) + and %111111 + cp %100000 + jr nc, .negative\@ + call .apply\@ + ld a, h + ret +.negative\@ + and %011111 + call .apply\@ + ld a, h + xor $ff + inc a + ret +.apply\@ + ld e, a + ld a, d + ld d, 0 +if _NARG == 1 + ld hl, \1 +else + ld hl, .sinetable\@ +endc + add hl, de + add hl, de + ld e, [hl] + inc hl + ld d, [hl] + ld hl, 0 +.multiply\@ ; factor amplitude + srl a + jr nc, .even\@ + add hl, de +.even\@ + sla e + rl d + and a + jr nz, .multiply\@ + ret +if _NARG == 0 +.sinetable\@ + sine_table 32 +endc +ENDM diff --git a/macros/wram.asm b/macros/wram.asm index d7ba1834..1df2ee28 100755 --- a/macros/wram.asm +++ b/macros/wram.asm @@ -119,7 +119,7 @@ channel_struct: MACRO ; Addreses are Channel1 (c101). \1MusicID:: dw \1MusicBank:: db -\1Flags:: db ; 0:on/off 1:subroutine 3:sfx 4:noise 5:rest +\1Flags1:: db ; 0:on/off 1:subroutine 3:sfx 4:noise 5:rest \1Flags2:: db ; 0:vibrato on/off 2:duty 4:cry pitch \1Flags3:: db ; 0:vibrato up/down \1MusicAddress:: dw @@ -129,14 +129,12 @@ channel_struct: MACRO \1Condition:: db ; conditional jumps \1DutyCycle:: db ; bits 6-7 (0:12.5% 1:25% 2:50% 3:75%) \1Intensity:: db ; hi:pressure lo:velocity -\1Frequency:: ; 11 bits -\1FrequencyLo:: db -\1FrequencyHi:: db +\1Frequency:: dw ; 11 bits \1Pitch:: db ; 0:rest 1-c:note \1Octave:: db ; 7-0 (0 is highest) -\1StartingOctave:: db ; raises existing octaves (to repeat phrases) +\1PitchOffset:: db ; raises existing octaves (to repeat phrases) \1NoteDuration:: db ; frames remaining for the current note -\1Field0x16:: ds 1 ; c117 +\1Field16:: ds 1 ; c117 ds 1 ; c118 \1LoopCount:: db \1Tempo:: dw @@ -149,16 +147,16 @@ channel_struct: MACRO \1PitchWheelTarget:: dw ; frequency endpoint for pitch wheel \1PitchWheelAmount:: db ; c124 \1PitchWheelAmountFraction:: db ; c125 -\1Field0x25:: ds 1 ; c126 +\1Field25:: ds 1 ; c126 ds 1 ; c127 \1CryPitch:: dw -\1Field0x29:: ds 1 -\1Field0x2a:: ds 2 -\1Field0x2c:: ds 1 +\1Field29:: ds 1 +\1Field2a:: ds 2 +\1Field2c:: ds 1 \1NoteLength:: db ; frames per 16th note -\1Field0x2e:: ds 1 ; c12f -\1Field0x2f:: ds 1 ; c130 -\1Field0x30:: ds 1 ; c131 +\1Field2e:: ds 1 ; c12f +\1Field2f:: ds 1 ; c130 +\1Field30:: ds 1 ; c131 ds 1 ; c132 ENDM |