Skip to content

Commit 91dc7da

Browse files
committed
MEGA65: audio mixer small code reorg. #272
Just some code clean-up to move the audio mixer register ("coeffs") R/W into audio65.c
1 parent 3e2dc44 commit 91dc7da

File tree

3 files changed

+39
-25
lines changed

3 files changed

+39
-25
lines changed

targets/mega65/audio65.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* A work-in-progess MEGA65 (Commodore 65 clone origins) emulator
22
Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
3-
Copyright (C)2016-2024 LGB (Gábor Lénárt) <[email protected]>
3+
Copyright (C)2016-2025 LGB (Gábor Lénárt) <[email protected]>
44
55
This program is free software; you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -45,6 +45,8 @@ static int system_sound_mix_freq; // playback sample rate (in Hz) of the emulat
4545
static int system_sid_cycles_per_sec;
4646
static double dma_audio_mixing_value;
4747

48+
Uint8 mixer_register = 0x00;
49+
static Uint8 mixer_coeffs[0x100];
4850

4951
#if NUMBER_OF_SIDS != 4
5052
# error "Currently NUMBER_OF_SIDS macro must be set to 4!"
@@ -385,6 +387,28 @@ void audio65_start ( void )
385387
}
386388

387389

390+
Uint8 audio65_read_mixer_register ( void )
391+
{
392+
return mixer_coeffs[mixer_register];
393+
}
394+
395+
396+
void audio65_write_mixer_register ( const Uint8 data )
397+
{
398+
mixer_coeffs[mixer_register] = data;
399+
if (mixer_register == 0x1E || mixer_register == 0x1F) { // HDMI-LEFT?
400+
int vol = (mixer_coeffs[0x1E] << 8) + mixer_coeffs[0x1F];
401+
vol = vol * 100 / 65536;
402+
audio_set_stereo_parameters(vol, AUDIO_UNCHANGED_SEPARATION);
403+
}
404+
if (mixer_register == 0x3E || mixer_register == 0x3F) { // HDMI-RIGHT?
405+
int vol = (mixer_coeffs[0x3E] << 8) + mixer_coeffs[0x3F];
406+
vol = vol * 100 / 65536;
407+
audio_set_stereo_parameters(vol, AUDIO_UNCHANGED_SEPARATION);
408+
}
409+
}
410+
411+
388412
void audio65_init ( int sid_cycles_per_sec, int sound_mix_freq, int volume, int separation, unsigned int buffer_size )
389413
{
390414
static volatile int initialized = 0;

targets/mega65/audio65.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* A work-in-progess MEGA65 (Commodore-65 clone origins) emulator
22
Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
3-
Copyright (C)2016-2024 LGB (Gábor Lénárt) <[email protected]>
3+
Copyright (C)2016-2025 LGB (Gábor Lénárt) <[email protected]>
44
55
This program is free software; you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -40,6 +40,7 @@ extern struct SidEmulation sid[NUMBER_OF_SIDS];
4040

4141
extern int stereo_separation;
4242
extern int audio_volume;
43+
extern Uint8 mixer_register;
4344

4445
extern void audio65_init ( int sid_cycles_per_sec, int sound_mix_freq, int volume, int separation, unsigned int buffer_size );
4546
extern void audio65_reset ( void );
@@ -50,4 +51,7 @@ extern void audio65_sid_write ( const int addr, const Uint8 data );
5051
extern void audio65_sid_inc_framecount ( void );
5152
extern void audio_set_stereo_parameters ( int vol, int sep );
5253

54+
extern Uint8 audio65_read_mixer_register ( void );
55+
extern void audio65_write_mixer_register ( const Uint8 data );
56+
5357
#endif

targets/mega65/io_mapper.c

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ int core_age_in_days;
4848
static const Uint8 fpga_firmware_version[] = { 'X','e','m','u' };
4949
static const Uint8 cpld_firmware_version[] = { 'N','o','w','!' };
5050

51-
static Uint8 coeff_addr = 0x00;
52-
static Uint8 mixer_coeffs[0x100];
5351

5452
#define RETURN_ON_IO_READ_NOT_IMPLEMENTED(func, fb) \
5553
do { DEBUG("IO: NOT IMPLEMENTED read (emulator lacks feature), %s $%04X fallback to answer $%02X" NL, func, addr, fb); \
@@ -261,6 +259,10 @@ Uint8 io_read ( unsigned int addr )
261259
return rand() & 0xF;
262260
case 0xDF: // D6DF: FPGA die temperature, high byte: assuming to be 164 (just because I see that on a real MEGA65 currently at my room's temperature ...)
263261
return 164;
262+
case 0xF4:
263+
return mixer_register;
264+
case 0xF5:
265+
return audio65_read_mixer_register();
264266
default:
265267
DEBUG("MEGA65: reading MEGA65 specific I/O @ $D6%02X result is $%02X" NL, addr, D6XX_registers[addr]);
266268
return D6XX_registers[addr];
@@ -344,22 +346,6 @@ Uint8 io_read ( unsigned int addr )
344346
}
345347
}
346348

347-
void update_mixer_coeffs(Uint8 data)
348-
{
349-
mixer_coeffs[coeff_addr] = data;
350-
351-
if (coeff_addr == 0x1E || coeff_addr == 0x1F) { // HDMI-LEFT?
352-
int vol = (mixer_coeffs[0x1E] << 8) + mixer_coeffs[0x1F];
353-
vol = vol * 100 / 65536;
354-
audio_set_stereo_parameters(vol, AUDIO_UNCHANGED_SEPARATION);
355-
}
356-
357-
if (coeff_addr == 0x3E || coeff_addr == 0x3F) { // HDMI-RIGHT?
358-
int vol = (mixer_coeffs[0x3E] << 8) + mixer_coeffs[0x3F];
359-
vol = vol * 100 / 65536;
360-
audio_set_stereo_parameters(vol, AUDIO_UNCHANGED_SEPARATION);
361-
}
362-
}
363349

364350

365351
/* Please read comments at io_read() above, those apply here too.
@@ -481,14 +467,14 @@ void io_write ( unsigned int addr, Uint8 data )
481467
eth65_write_reg(addr, data);
482468
return;
483469
}
484-
485470
if (addr == 0xF4) { // audio mixer co-efficient address
486-
coeff_addr = data;
471+
mixer_register = data;
472+
return;
487473
}
488-
if (addr == 0XF5) { // audio mixer co-efficient value
489-
update_mixer_coeffs(data);
474+
if (addr == 0xF5) { // audio mixer co-efficient value
475+
audio65_write_mixer_register(data);
476+
return;
490477
}
491-
492478
static int d6cf_exit_status = 0x42;
493479
switch (addr) {
494480
case 0x0A: // write bit 7 is zero -> flush the queue

0 commit comments

Comments
 (0)