Skip to content

Commit

Permalink
FM overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
GbaCretin committed Aug 5, 2022
1 parent 6b72738 commit c38f3ca
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 72 deletions.
2 changes: 0 additions & 2 deletions src/def.inc
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ SFXPS_CHANNEL_COUNT equ PA_CHANNEL_COUNT

; FMCNT defs
FMCNT_CH_ENABLE equ 1
FMCNT_VOL_UPDATE equ 2
FMCNT_PITCH_SLIDE_ENABLE equ 4

FMCNT_MIN_FNUM equ $0080
FMCNT_MAX_FNUM equ $07FF
Expand Down
53 changes: 1 addition & 52 deletions src/fm.s
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,6 @@ FMCNT_init:
pop hl
ret

; DOESN'T BACKUP REGISTERS !!!
FMCNT_irq:
ld b,FM_CHANNEL_COUNT
ld ix,FM_ch4

loop$:
dec b
; If the channel's enable bit is 0,
; then continue to the next channel
ld a,(ix+FM_Channel.enable)
bit 0,a
jr z,skip_loop$

; If if FMCNT vol upd. flag is enabled...
; (This check is executed inside the function
; too, this is to save time in most scenarios)
bit 1,a
call nz,FMCNT_update_total_levels

; Clear all the update bitflags
ld a,(ix+FM_Channel.enable)
and a,FMCNT_VOL_UPDATE ^ $FF
ld (ix+FM_Channel.enable),a

skip_loop$:
ld de,-FM_Channel.SIZE
add ix,de
inc b
djnz loop$
ret

; b: channel (0~3)
; ix: address to FMCNT channel data
; (FM_channel_volumes[channel]): volume (0~7F)
Expand All @@ -109,17 +78,6 @@ FMCNT_update_total_levels:
push bc
push hl
push af
; if the FMCNT vol enable flag
; isn't set, return
ld a,(ix+FM_Channel.enable)
bit 1,a
jp z,return$

; If it is set, clear volume flag
; and proceed with the function
and a,FMCNT_VOL_UPDATE ^ $FF
ld (ix+FM_Channel.enable),a

ld e,(ix+FM_Channel.algo)
ld c,1 ; Prepare operator value

Expand Down Expand Up @@ -329,6 +287,7 @@ FM_op_register_offsets_LUT:
; a: fbalgo (--FFFAAA; Feedback, Algorithm)
; c: channel (0~3)
; ix: Pointer to FMCNT channel data
; Total levels must be updated afterwards
FMCNT_set_fbalgo:
push de
push af
Expand All @@ -355,11 +314,6 @@ even_channel$:
and a,%00000111 ; --FFFAAA -> 00000AAA
rlca ; algorithm *= 2
ld (ix+FM_Channel.algo),a

; Set FM volume update flag
ld a,(ix+FM_Channel.enable)
or a,FMCNT_VOL_UPDATE
ld (ix+FM_Channel.enable),a
pop hl
pop af
pop de
Expand Down Expand Up @@ -458,10 +412,6 @@ FMCNT_set_operator:
push af
push bc
push hl
ld a,(ix+FM_Channel.enable)
or a,FMCNT_VOL_UPDATE
ld (ix+FM_Channel.enable),a

; Load OP register offset in a, then
; add said offset to DTMUL base address.
; After that, move result to d
Expand Down Expand Up @@ -566,7 +516,6 @@ FMCNT_set_note:
or a,b ; OR block with F-Num 2
ld b,a

; WRITE TO REGISTERS DIRECTLY DO NOT BUFFER IN WRAM FOR NO ABSOLUTE REASON
; Write Block and F-Num 2
ld e,b
ld d,REG_FM_CH13_FBLOCK
Expand Down
1 change: 0 additions & 1 deletion src/main.s
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ execute_tma_tick:

call FADE_irq
call MLM_irq
call FMCNT_irq
ret

fast_beep:
Expand Down
17 changes: 6 additions & 11 deletions src/mlm.s
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 +667,8 @@ set_fm_instrument$:
call FMCNT_set_operator
add hl,de

; Set volume update flag
ld a,(ix+FM_Channel.enable)
or a,FMCNT_VOL_UPDATE
ld (ix+FM_Channel.enable),a
ld b,c
call FMCNT_update_total_levels
pop ix
pop af
pop bc
Expand Down Expand Up @@ -910,10 +908,8 @@ set_fm_channel_volume$:
and a,127 ; Wrap volume inbetween 0 and 127
ld (ix+FM_Channel.volume),a

; set channel volume update flag
ld a,(ix+FM_Channel.enable)
or a,FMCNT_VOL_UPDATE
ld (ix+FM_Channel.enable),a
ld b,c
call FMCNT_update_total_levels
pop ix
pop af
pop bc
Expand Down Expand Up @@ -990,9 +986,8 @@ ch_counter set 0
and a,127

ld (FM_ch1+(ch_counter*FM_Channel.SIZE)+FM_Channel.volume),a
ld a,(FM_ch1+(ch_counter*FM_Channel.SIZE)+FM_Channel.enable)
or a,FMCNT_VOL_UPDATE
ld (FM_ch1+(ch_counter*FM_Channel.SIZE)+FM_Channel.enable),a
ld b,ch_counter
call FMCNT_update_total_levels
ch_counter set ch_counter+1
edup

Expand Down
6 changes: 3 additions & 3 deletions src/mlmcom.s
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@ MLMCOM_FM_TL_set:
ld e,a
ld hl,FM_ch1+FM_Channel.enable
add hl,de
ld a,(hl)
or a,FMCNT_VOL_UPDATE
ld (hl),a

ld b,c
call FMCNT_update_total_levels
ret

; invalid command, plays a noisy beep
Expand Down
7 changes: 4 additions & 3 deletions test/sdata/sdata.s
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,15 @@ MLM_song_fm4:

MLM_el_fm:
set_inst 2
set_vol $FF
set_pan PANNING_CENTER,0
fm_note NOTE_C,4,24
fm_note NOTE_D,4,24
note_off 30
set_vol $E8
set_pan PANNING_LEFT,0
set_vol $E0
;set_pan PANNING_LEFT,0
fm_note NOTE_E,4,24
set_pan PANNING_RIGHT,0
;set_pan PANNING_RIGHT,0
fm_note NOTE_C,4,24
note_off 30
jump MLM_el_fm-MLM_header
Expand Down

0 comments on commit c38f3ca

Please sign in to comment.