From d486c872bc0244bbf93d6a79458b83506a4ba573 Mon Sep 17 00:00:00 2001 From: ADM228 Date: Fri, 8 Mar 2024 21:22:22 +0300 Subject: [PATCH] 7/8, 15/16 table generation --- TODO.txt | 2 +- source/sound/SNESFM.asm | 49 ++++++++++++++++++++++++++++++++++------- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/TODO.txt b/TODO.txt index d5fe282..97521ee 100644 --- a/TODO.txt +++ b/TODO.txt @@ -8,7 +8,7 @@ [D] - implemented; documentation in progress - [d] Toggleable noise support -- [ ] [ ] Generate 7/8 and 15/16 tables on the fly +- [d] [d] Generate 7/8 and 15/16 tables on the fly - [ ] Custom sample support: - [ ] Use sample addresses for that - [ ] ×4 pointer instead of ×2? diff --git a/source/sound/SNESFM.asm b/source/sound/SNESFM.asm index 3f0fed2..371ad14 100644 --- a/source/sound/SNESFM.asm +++ b/source/sound/SNESFM.asm @@ -405,6 +405,9 @@ InternalDefines: GBL_TIMER_SPEED = $0700 + TBL_7over8 = $0C00 + TBL_15over16 = $0D00 + ;Temporary channel pointers during song playback CHTEMP_SONG_POINTER_L = $20 @@ -582,14 +585,34 @@ SetVolume: MOV X, #$7F MOV Y, #$08 MOV A, #$00 - .loopVolumeSetup: + .loop: MOV $F2, A MOV $F3, X INC $F2 MOV $F3, X CLRC ADC A, #$10 - DBNZ Y, .loopVolumeSetup + DBNZ Y, .loop + +if !SNESFM_CFG_SAMPLE_GENERATE + +GenerateMultTables: + MOV X, #$00 ;0, 1 ; + MOV A, X ;2 ; Zero everything out + MOV !TEMP_VALUE, X ;3, 4 ;__ + + CALL GMT_loop + + MOV A, #256*15/16 ; + MOV GMT_loop+2, A ; + MOV A, #(TBL_15over16>>8) ; Set everything for round 2 + MOV GMT_loop+9, A ;__ + MOV A, X + MOV !TEMP_VALUE, X + + CALL GMT_loop + +endif GetInstrumentData: MOV MESSAGE_CNT_TH1, #$01 @@ -2112,6 +2135,20 @@ WaitCPUMsg: AND A, #$F0 RET +if !SNESFM_CFG_SAMPLE_GENERATE + +GMT_loop: + CLRC ; 0 + ADC !TEMP_VALUE, #256*7/8 ; 1, 2, 3 + BCC + ; 4, 5 + INC A ; 6 + + MOV TBL_7over8+X, A ; 7, 8, 9 + INC X ; 10 + BNE GMT_loop ; 11, 12 + RET ; 13 + +endif + set_echoFIR: MOV $00, #$08 MOV $01, #$0F @@ -2757,7 +2794,7 @@ ConvertToBRR: if !SNESFM_CFG_SAMPLE_USE_FILTER1 .FilterLoop: MOV Y, BRR_SMPPT_L ; # - MOV A, $0D00+Y ; # + MOV A, TBL_15over16+Y ; # BBS4 BRR_TEMP_FLAGS, + ; # CLRC ; Python code: # ADC A, BRR_CSMPT_L ; currentsmppoint += smppoint_L*15/16 # @@ -2925,7 +2962,7 @@ ConvertToBRR: +: MOV BRR_CSMPT_H, A ; MOV Y, BRR_CSMPT_L ; - MOV A, $0C00+Y ; + MOV A, TBL_7over8+Y ; MOV BRR_CSMPT_L, A ; MOV Y, BRR_CSMPT_H ; MOV A, #$E0 ; 7/8 multiplication @@ -3264,10 +3301,6 @@ assert pc() < $6000 endspcblock Includes: - spcblock $0C00 !SNESFM_CFG_SPCBLOCK_TYPE - LookupTables: - incbin "multTables.bin" - endspcblock if not(!SNESFM_CFG_PITCHTABLE_GEN) spcblock $0E00 !SNESFM_CFG_SPCBLOCK_TYPE PitchTableLo: