From dd486d81fd526942554fc3c77cfe6451e55e77a6 Mon Sep 17 00:00:00 2001 From: revelj Date: Sun, 16 Aug 2020 09:34:00 +0200 Subject: [PATCH] Made frequency table lookups work across 256 byte boundaries Fixes https://github.com/trash80/mGB/issues/3 --- Source/mGBASMSynthFunctions.s | 93 +++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 43 deletions(-) diff --git a/Source/mGBASMSynthFunctions.s b/Source/mGBASMSynthFunctions.s index 364bbb7..fa3a46a 100644 --- a/Source/mGBASMSynthFunctions.s +++ b/Source/mGBASMSynthFunctions.s @@ -60,12 +60,13 @@ _asmUpdatePu1PbWheelReset$:: ld A,(hl) ld B,A - ld A,#<_freq - add A,B - add A,B - ld E,A - ld A,#>_freq - ld D,A + ld A,B + add A,A + add A,#<_freq + ld E,A + adc #>_freq + sub E + ld D,a ld A,(DE) ld (#0xFF13),A @@ -144,15 +145,15 @@ _asmUpdatePu2PbWheelReset$:: ld hl, #_noteStatus + 3 ld A,(hl) - ld B,A +; ld B,A - - ld A,#<_freq - add A,B - add A,B - ld E,A - ld A,#>_freq - ld D,A +; ld A,B + add A,A + add A,#<_freq + ld E,A + adc #>_freq + sub E + ld D,a ld A,(DE) ld (#0xFF18),A @@ -254,14 +255,15 @@ _asmUpdateWavPbWheelReset$:: ld hl, #_noteStatus + 5 ld A,(hl) - ld B,A +; ld B,A - ld A,#<_freq - add A,B - add A,B - ld E,A - ld A,#>_freq - ld D,A +; ld A,B + add A,A + add A,#<_freq + ld E,A + adc #>_freq + sub E + ld D,a ld A,(DE) @@ -342,7 +344,8 @@ _asmUpdateNoiPbWheelReset$:: ld A,#<_noiFreq add A,B ld E,A - ld A,#>_noiFreq + adc A,#>_noiFreq + sub E ld D,A ld A,(DE) @@ -380,7 +383,7 @@ _asmPlayNotePu1:: cp #0x00 jr nz,_asmPlayNotePu1OnSet$ - jr _asmPlayNotePu1Off$ + jp _asmPlayNotePu1Off$ _asmPlayNotePu1OnSet$:: ld A, (#0xFF12) @@ -426,12 +429,13 @@ _asmPlayNotePu1On$:: ld hl, #_noteStatus + 1 ld (hl),B - ld A,#<_freq - add A,B - add A,B - ld E,A - ld A,#>_freq - ld D,A + ld A,B + add A,A + add A,#<_freq + ld E,A + adc #>_freq + sub E + ld D,a ld A,(DE) ld (#0xFF13),A @@ -522,7 +526,7 @@ _asmPlayNotePu2$:: cp #0x00 jr nz,_asmPlayNotePu2OnSet$ - jr _asmPlayNotePu2Off$ + jp _asmPlayNotePu2Off$ _asmPlayNotePu2OnSet$:: ld A, (#0xFF17) @@ -566,12 +570,13 @@ _asmPlayNotePu2On$:: ld hl, #_noteStatus + 3 ld (hl),B - ld A,#<_freq - add A,B - add A,B - ld E,A - ld A,#>_freq - ld D,A + ld A,B + add A,A + add A,#<_freq + ld E,A + adc #>_freq + sub E + ld D,a ld A,(DE) ld (#0xFF18),A @@ -689,12 +694,13 @@ pop bc ret _asmPlayNoteWavSet$:: - ld A,#<_freq - add A,B - add A,B - ld E,A - ld A,#>_freq - ld D,A + ld A,B + add A,A + add A,#<_freq + ld E,A + adc #>_freq + sub E + ld D,a ld A,(DE) @@ -821,7 +827,8 @@ _asmPlayNoteNoiOn$:: ld A,#<_noiFreq add A,B ld E,A - ld A,#>_noiFreq + adc A,#>_noiFreq + sub E ld D,A ld A,(DE)