Skip to content

Commit

Permalink
Trying to use 4 SIDs #277
Browse files Browse the repository at this point in the history
  • Loading branch information
lgblgblgb committed Jun 8, 2021
1 parent c7e0a8a commit 0c8f0d0
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 23 deletions.
26 changes: 15 additions & 11 deletions targets/mega65/audio65.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int audio_volume = AUDIO_DEFAULT_VOLUME;

static int stereo_separation_orig = 100;
static int stereo_separation_other = 0;
struct SidEmulation sid1, sid2; // the two SIDs
struct SidEmulation sid[4];
static int mixing_freq; // playback sample rate (in Hz) of the emulator itself
static double dma_audio_mixing_value;
static opl3_chip opl3;
Expand Down Expand Up @@ -164,17 +164,19 @@ static void audio_callback ( void *userdata, Uint8 *stereo_out_stream, int len )
#if 1
//DEBUGPRINT("AUDIO: audio callback, wants %d samples" NL, len);
len >>= 2; // the real size if /4, since it's a stereo stream, and 2 bytes/sample, we want to render
short streams[7][len]; // currently. 4 dma channels + two SIDs' 1-1 channel (SID is already rendered together) + 1 for OPL3
short streams[9][len]; // currently. 4 dma channels + 4 SIDs + 1 for OPL3
for (int i = 0; i < 4; i++)
render_dma_audio(i, streams[i], len);
sid_render(&sid2, streams[4], len, 1);
sid_render(&sid1, streams[5], len, 1);
OPL3_GenerateStream(&opl3, streams[6], len, 1);
sid_render(&sid[0], streams[4], len, 1); // $D400 - left
sid_render(&sid[1], streams[5], len, 1); // $D420 - left
sid_render(&sid[2], streams[6], len, 1); // $D440 - right
sid_render(&sid[3], streams[7], len, 1); // $D460 - right
OPL3_GenerateStream(&opl3, streams[8], len, 1);
// Now mix channels
for (int i = 0; i < len; i++) {
// mixing streams together
int orig_left = (int)streams[0][i] + (int)streams[1][i] + (int)streams[4][i] + (int)streams[6][i];
int orig_right = (int)streams[2][i] + (int)streams[3][i] + (int)streams[5][i] + (int)streams[6][i];
int orig_left = (int)streams[0][i] + (int)streams[1][i] + (int)streams[4][i] + (int)streams[5][i] + (int)streams[8][i];
int orig_right = (int)streams[2][i] + (int)streams[3][i] + (int)streams[6][i] + (int)streams[7][i] + (int)streams[8][i];
#if 1
// channel stereo separation (including inversion) + volume handling
int left = ((orig_left * stereo_separation_orig) / 100) + ((orig_right * stereo_separation_other) / 100);
Expand All @@ -196,8 +198,8 @@ static void audio_callback ( void *userdata, Uint8 *stereo_out_stream, int len )
// DEBUG("AUDIO: audio callback, wants %d samples" NL, len);
// We use the trick, to render boths SIDs with step of 2, with a byte offset
// to get a stereo stream, wanted by SDL.
sid_render(&sid2, ((short *)(stereo_out_stream)) + 0, len >> 1, 2); // SID @ left
sid_render(&sid1, ((short *)(stereo_out_stream)) + 1, len >> 1, 2); // SID @ right
//sid_render(&sid2, ((short *)(stereo_out_stream)) + 0, len >> 1, 2); // SID @ left
//sid_render(&sid1, ((short *)(stereo_out_stream)) + 1, len >> 1, 2); // SID @ right
#endif
}
#endif
Expand All @@ -207,8 +209,10 @@ void audio65_init ( int sid_cycles_per_sec, int sound_mix_freq, int volume, int
{
// We always initialize SIDs, even if no audio emulation is compiled in
// Since there can be problem to write SID registers otherwise?
sid_init(&sid1, sid_cycles_per_sec, sound_mix_freq);
sid_init(&sid2, sid_cycles_per_sec, sound_mix_freq);
sid_init(&sid[0], sid_cycles_per_sec, sound_mix_freq);
sid_init(&sid[1], sid_cycles_per_sec, sound_mix_freq);
sid_init(&sid[2], sid_cycles_per_sec, sound_mix_freq);
sid_init(&sid[3], sid_cycles_per_sec, sound_mix_freq);
OPL3_Reset(&opl3, sound_mix_freq);
#ifdef AUDIO_EMULATION
mixing_freq = sound_mix_freq;
Expand Down
2 changes: 1 addition & 1 deletion targets/mega65/audio65.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#define AUDIO_UNCHANGED_SEPARATION -1000
#define AUDIO_UNCHANGED_VOLUME -1000

extern struct SidEmulation sid1, sid2;
extern struct SidEmulation sid[4];
extern SDL_AudioDeviceID audio;
extern int stereo_separation;

Expand Down
4 changes: 3 additions & 1 deletion targets/mega65/io_mapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,9 @@ void io_write ( unsigned int addr, Uint8 data )
case 0x15: // $D500-$D5FF ~ C65 I/O mode
case 0x34: // $D400-$D4FF ~ M65 I/O mode
case 0x35: // $D500-$D5FF ~ M65 I/O mode
sid_write_reg(addr & 0x40 ? &sid2 : &sid1, addr & 31, data);
//sid_write_reg(addr & 0x40 ? &sid[1] : &sid[0], addr & 31, data);
//DEBUGPRINT("SID #%d reg#%02X data=%02X" NL, (addr >> 5) & 3, addr & 0x1F, data);
sid_write_reg(&sid[(addr >> 5) & 3], addr & 0x1F, data);
return;
case 0x16: // $D600-$D6FF ~ C65 I/O mode
if ((addr & 0xFF) == 0x07) {
Expand Down
8 changes: 5 additions & 3 deletions targets/mega65/m65_snapshot.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* A work-in-progess MEGA65 (Commodore 65 clone origins) emulator
Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
Copyright (C)2016,2017 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
Copyright (C)2016,2017,2021 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -32,6 +32,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "xemu/f011_core.h"
#include "m65_snapshot.h"
#include "memory_mapper.h"
#include "audio65.h"
#include "io_mapper.h"
#include <string.h>

#define M65_MEMORY_BLOCK_VERSION 1
Expand Down Expand Up @@ -78,8 +80,8 @@ const struct xemu_snapshot_definition_st m65_snapshot_definition[] = {
{ "CIA#2", &cia2, cia_snapshot_load_state, cia_snapshot_save_state },
{ "VIC-4", NULL, vic4_snapshot_load_state, vic4_snapshot_save_state },
{ "M65", NULL, m65emu_snapshot_load_state, m65emu_snapshot_save_state },
{ "SID#1", &sid1, sid_snapshot_load_state, sid_snapshot_save_state },
{ "SID#2", &sid2, sid_snapshot_load_state, sid_snapshot_save_state },
{ "SID#1", &sid[0], sid_snapshot_load_state, sid_snapshot_save_state },
{ "SID#2", &sid[1], sid_snapshot_load_state, sid_snapshot_save_state },
{ "DMAgic", NULL, dma_snapshot_load_state, dma_snapshot_save_state },
{ "SDcard", NULL, sdcard_snapshot_load_state, sdcard_snapshot_save_state },
{ "FDC-F011", NULL, fdc_snapshot_load_state, fdc_snapshot_save_state },
Expand Down
8 changes: 3 additions & 5 deletions targets/mega65/m65_snapshot.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* A work-in-progess MEGA65 (Commodore 65 clone origins) emulator
Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
Copyright (C)2016,2017 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
Copyright (C)2016,2017,2021 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -16,15 +16,13 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

#ifndef __XEMU_M65_SNAPSHOT_H_INCLUDED
#define __XEMU_M65_SNAPSHOT_H_INCLUDED
#ifndef XEMU_MEGA65_SNAPSHOT_H_INCLUDED
#define XEMU_MEGA65_SNAPSHOT_H_INCLUDED

#ifdef XEMU_SNAPSHOT_SUPPORT
#include "xemu/emutools_snapshot.h"

// From other modules ...
extern struct Cia6526 cia1, cia2;
extern struct SidEmulation sid1, sid2;;
extern int m65emu_snapshot_load_state ( const struct xemu_snapshot_definition_st *def, struct xemu_snapshot_block_st *block );
extern int m65emu_snapshot_save_state ( const struct xemu_snapshot_definition_st *def );
extern int m65emu_snapshot_loading_finalize ( const struct xemu_snapshot_definition_st *def, struct xemu_snapshot_block_st *block );
Expand Down
6 changes: 4 additions & 2 deletions targets/mega65/mega65.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,10 @@ static void update_emulator ( void )
// XXX: some things has been moved here from the main loop, however update_emulator is called from other places as well, FIXME check if it causes problems or not!
if (XEMU_UNLIKELY(inject_ready_check_status))
inject_ready_check_do();
sid1.sFrameCount++;
sid2.sFrameCount++;
sid[0].sFrameCount++;
sid[1].sFrameCount++;
sid[2].sFrameCount++;
sid[3].sFrameCount++;
strcpy(emulator_speed_title, cpu_clock_speed_strs[cpu_clock_speed_str_index]);
strcat(emulator_speed_title, " ");
strcat(emulator_speed_title, videostd_name);
Expand Down

1 comment on commit 0c8f0d0

@lgblgblgb
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log to #29 too

Please sign in to comment.