Skip to content

Commit

Permalink
Support panning for Ricoh chips
Browse files Browse the repository at this point in the history
  • Loading branch information
viciious committed Jun 21, 2024
1 parent 7efbc1f commit d7a1dc1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src-md/crt0.s
Original file line number Diff line number Diff line change
Expand Up @@ -2646,6 +2646,7 @@ bump_fm:
move.b RF5C68_ENV.w,rf5c68_envelope
move.b RF5C68_CHN.w,rf5c68_chanmask
move.b RF5C68_CTL.w,rf5c68_chanctl
move.b RF5C68_PAN.w,rf5c68_pan
bra.b 7f

6:
Expand Down Expand Up @@ -2705,8 +2706,12 @@ bump_fm:
tst.w pcm_env
beq.b 20f /* PCM muted */

moveq #0,d1
move.b rf5c68_envelope,d1
swap.w d1
move.b rf5c68_pan,d1
move.l d1,-(sp)
moveq #0,d1
move.w rf5c68_freq_incr,d1
move.l d1,-(sp)
move.w rf5c68_loop_ofs,d1
Expand Down Expand Up @@ -3195,7 +3200,10 @@ rf5c68_envelope:
dc.b 0
rf5c68_chanmask:
dc.b 255
rf5c68_pan:
dc.b 128

.align 2
offs68k:
dc.w 0
offsz80:
Expand Down
20 changes: 17 additions & 3 deletions src-md/vgm.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,26 @@ void vgm_stop_rf5c68_samples(int chan)
scd_queue_stop_src(VGM_MCD_SOURCE_ID+chan);
}

void vgm_play_rf5c68_samples(int chan, int offset, int loopstart, int incr, int vol)
static uint8_t vgm_midipan2lcf(uint8_t pan)
{
if (pan == 0b00001111) {
return 0; // full left
} else if (pan == 255) {
// no panning
return pan;
} else {
return (pan & 0xf0) | ((256 - pan) >> 4);
}
}

void vgm_play_rf5c68_samples(int chan, int offset, int loopstart, int incr, int volpan)
{
//int freq = ((uint16_t)incr * 32604) >> 11;
int freq = incr << 4; // good enough
int length = loopstart - offset;
void *ptr = (char *)MCD_WORDRAM_VGM_PTR + rf5c68_dataofs + offset;
int vol = (volpan >> 16) & 0xff;
int pan = vgm_midipan2lcf(volpan & 0xff);

if (!cd_ok)
return;
Expand All @@ -252,15 +266,15 @@ void vgm_play_rf5c68_samples(int chan, int offset, int loopstart, int incr, int
if (loopstart == 0)
{
// hacky hack
scd_queue_update_src(VGM_MCD_SOURCE_ID+chan, freq, 128, vol, 0);
scd_queue_update_src(VGM_MCD_SOURCE_ID+chan, freq, pan, vol, 0);
return;
}

if (!freq)
return;

scd_queue_setptr_buf(VGM_MCD_BUFFER_ID+chan, ptr, length);
scd_queue_play_src(VGM_MCD_SOURCE_ID+chan, VGM_MCD_BUFFER_ID+chan, freq, 128, vol, 0);
scd_queue_play_src(VGM_MCD_SOURCE_ID+chan, VGM_MCD_BUFFER_ID+chan, freq, pan, vol, 0);
}

void vgm_stop_samples(void)
Expand Down

0 comments on commit d7a1dc1

Please sign in to comment.