Merge pull request #6147 from jriwanek-forks/miscclean

Some misc cleanups and code formatting
This commit is contained in:
Miran Grča
2025-09-10 02:23:17 +02:00
committed by GitHub
15 changed files with 379 additions and 302 deletions

View File

@@ -103,8 +103,29 @@ if(INSTRUMENT)
add_compile_definitions(USE_INSTRUMENT) add_compile_definitions(USE_INSTRUMENT)
endif() endif()
target_link_libraries(86Box cpu chipset mch dev mem fdd game cdrom rdisk mo hdd target_link_libraries(86Box
net print scsi sio snd utils vid voodoo plat ui) cpu
chipset
mch
dev
mem
fdd
game
cdrom
rdisk
mo
hdd
net
print
scsi
sio
snd
utils
vid
voodoo
plat
ui
)
if(HAIKU) if(HAIKU)
target_link_libraries(86Box be) target_link_libraries(86Box be)

View File

@@ -92,8 +92,8 @@ cart_image_close(int drive)
static void static void
cart_image_load(int drive, char *fn) cart_image_load(int drive, char *fn)
{ {
FILE *fp; FILE *fp = NULL;
uint32_t size; uint32_t size = 0;
uint32_t base = 0x00000000; uint32_t base = 0x00000000;
cart_image_close(drive); cart_image_close(drive);
@@ -137,7 +137,7 @@ cart_image_load(int drive, char *fn)
static void static void
cart_load_common(int drive, char *fn, uint8_t hard_reset) cart_load_common(int drive, char *fn, uint8_t hard_reset)
{ {
FILE *fp; FILE *fp = NULL;
cartridge_log("Cartridge: loading drive %d with '%s'\n", drive, fn); cartridge_log("Cartridge: loading drive %d with '%s'\n", drive, fn);

View File

@@ -105,39 +105,39 @@ static const struct
void (*close)(int drive); void (*close)(int drive);
int size; int size;
} loaders[] = { } loaders[] = {
{ "001", img_load, img_close, -1}, { "001", img_load, img_close, -1 },
{ "002", img_load, img_close, -1}, { "002", img_load, img_close, -1 },
{ "003", img_load, img_close, -1}, { "003", img_load, img_close, -1 },
{ "004", img_load, img_close, -1}, { "004", img_load, img_close, -1 },
{ "005", img_load, img_close, -1}, { "005", img_load, img_close, -1 },
{ "006", img_load, img_close, -1}, { "006", img_load, img_close, -1 },
{ "007", img_load, img_close, -1}, { "007", img_load, img_close, -1 },
{ "008", img_load, img_close, -1}, { "008", img_load, img_close, -1 },
{ "009", img_load, img_close, -1}, { "009", img_load, img_close, -1 },
{ "010", img_load, img_close, -1}, { "010", img_load, img_close, -1 },
{ "12", img_load, img_close, -1}, { "12", img_load, img_close, -1 },
{ "144", img_load, img_close, -1}, { "144", img_load, img_close, -1 },
{ "360", img_load, img_close, -1}, { "360", img_load, img_close, -1 },
{ "720", img_load, img_close, -1}, { "720", img_load, img_close, -1 },
{ "86F", d86f_load, d86f_close, -1}, { "86F", d86f_load, d86f_close, -1 },
{ "BIN", img_load, img_close, -1}, { "BIN", img_load, img_close, -1 },
{ "CQ", img_load, img_close, -1}, { "CQ", img_load, img_close, -1 },
{ "CQM", img_load, img_close, -1}, { "CQM", img_load, img_close, -1 },
{ "DDI", img_load, img_close, -1}, { "DDI", img_load, img_close, -1 },
{ "DSK", img_load, img_close, -1}, { "DSK", img_load, img_close, -1 },
{ "FDI", fdi_load, fdi_close, -1}, { "FDI", fdi_load, fdi_close, -1 },
{ "FDF", img_load, img_close, -1}, { "FDF", img_load, img_close, -1 },
{ "FLP", img_load, img_close, -1}, { "FLP", img_load, img_close, -1 },
{ "HDM", img_load, img_close, -1}, { "HDM", img_load, img_close, -1 },
{ "IMA", img_load, img_close, -1}, { "IMA", img_load, img_close, -1 },
{ "IMD", imd_load, imd_close, -1}, { "IMD", imd_load, imd_close, -1 },
{ "IMG", img_load, img_close, -1}, { "IMG", img_load, img_close, -1 },
{ "JSON", pcjs_load, pcjs_close, -1}, { "JSON", pcjs_load, pcjs_close, -1 },
{ "MFM", mfm_load, mfm_close, -1}, { "MFM", mfm_load, mfm_close, -1 },
{ "TD0", td0_load, td0_close, -1}, { "TD0", td0_load, td0_close, -1 },
{ "VFD", img_load, img_close, -1}, { "VFD", img_load, img_close, -1 },
{ "XDF", img_load, img_close, -1}, { "XDF", img_load, img_close, -1 },
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
static const struct { static const struct {
@@ -211,7 +211,7 @@ fdd_get_internal_name(int type)
int int
fdd_get_from_internal_name(char *s) fdd_get_from_internal_name(char *s)
{ {
int c = 0; int c = 0;
while (strlen(drive_types[c].internal_name)) { while (strlen(drive_types[c].internal_name)) {
if (!strcmp((char *) drive_types[c].internal_name, s)) if (!strcmp((char *) drive_types[c].internal_name, s))
@@ -466,7 +466,7 @@ fdd_load(int drive, char *fn)
if (!fn) if (!fn)
return; return;
if (strstr(fn, "wp://") == fn) { if (strstr(fn, "wp://") == fn) {
offs = 5; offs = 5;
ui_writeprot[drive] = 1; ui_writeprot[drive] = 1;
} }
fn += offs; fn += offs;

View File

@@ -1,3 +1,4 @@
extern char *path_get_basename(const char *path);
extern void path_get_dirname(char *dest, const char *path); extern void path_get_dirname(char *dest, const char *path);
extern char *path_get_filename(char *s); extern char *path_get_filename(char *s);
extern char *path_get_extension(char *s); extern char *path_get_extension(char *s);
@@ -5,4 +6,4 @@ extern void path_append_filename(char *dest, const char *s1, const char *s2);
extern void path_slash(char *path); extern void path_slash(char *path);
extern const char *path_get_slash(char *path); extern const char *path_get_slash(char *path);
extern void path_normalize(char *path); extern void path_normalize(char *path);
extern int path_abs(char *path); extern int path_abs(char *path);

View File

@@ -199,8 +199,8 @@ typedef struct emu8k_voice_t {
* something, similarly to targets and current, but... of what? * something, similarly to targets and current, but... of what?
* what is curious is that if they are already zero, they are not written to, so it really * what is curious is that if they are already zero, they are not written to, so it really
* looks like they are information about the status of the channel. (lfo position maybe?) */ * looks like they are information about the status of the channel. (lfo position maybe?) */
uint32_t unknown_data0_4; uint32_t z2;
uint32_t unknown_data0_5; uint32_t z1;
union { union {
uint32_t psst; uint32_t psst;
struct { struct {
@@ -229,7 +229,7 @@ typedef struct emu8k_voice_t {
}; };
#define CCCA_FILTQ_GET(ccca) (ccca >> 28) #define CCCA_FILTQ_GET(ccca) (ccca >> 28)
#define CCCA_FILTQ_SET(ccca, q) ccca = (ccca & 0x0FFFFFFF) | (q << 28) #define CCCA_FILTQ_SET(ccca, q) ccca = (ccca & 0x0FFFFFFF) | (q << 28)
/* Bit 27 should always be zero */ /* Bit 27 should always be zero on EMU8000 */
#define CCCA_DMA_ACTIVE(ccca) (ccca & 0x04000000) #define CCCA_DMA_ACTIVE(ccca) (ccca & 0x04000000)
#define CCCA_DMA_WRITE_MODE(ccca) (ccca & 0x02000000) #define CCCA_DMA_WRITE_MODE(ccca) (ccca & 0x02000000)
#define CCCA_DMA_WRITE_RIGHT(ccca) (ccca & 0x01000000) #define CCCA_DMA_WRITE_RIGHT(ccca) (ccca & 0x01000000)
@@ -316,7 +316,9 @@ typedef struct emu8k_voice_t {
int env_engine_on; int env_engine_on;
emu8k_mem_internal_t addr, loop_start, loop_end; emu8k_mem_internal_t addr;
emu8k_mem_internal_t loop_start;
emu8k_mem_internal_t loop_end;
int32_t initial_att; int32_t initial_att;
int32_t initial_filter; int32_t initial_filter;

View File

@@ -774,14 +774,14 @@ pit_irq0_timer_pcjr(int new_out, int old_out, UNUSED(void *priv))
static const device_config_t pcjr_config[] = { static const device_config_t pcjr_config[] = {
// clang-format off // clang-format off
{ {
.name = "display_type", .name = "display_type",
.description = "Display type", .description = "Display type",
.type = CONFIG_SELECTION, .type = CONFIG_SELECTION,
.default_string = "", .default_string = NULL,
.default_int = PCJR_RGB, .default_int = PCJR_RGB,
.file_filter = "", .file_filter = NULL,
.spinner = { 0 }, .spinner = { 0 },
.selection = { .selection = {
{ .description = "RGB", .value = PCJR_RGB }, { .description = "RGB", .value = PCJR_RGB },
{ .description = "Composite", .value = PCJR_COMPOSITE }, { .description = "Composite", .value = PCJR_COMPOSITE },
{ .description = "RGB (no brown)", .value = PCJR_RGB_NO_BROWN }, { .description = "RGB (no brown)", .value = PCJR_RGB_NO_BROWN },
@@ -807,11 +807,11 @@ static const device_config_t pcjr_config[] = {
.bios = { { 0 } } .bios = { { 0 } }
}, },
{ {
.name = "apply_hd", .name = "apply_hd",
.description = "Apply overscan deltas", .description = "Apply overscan deltas",
.type = CONFIG_BINARY, .type = CONFIG_BINARY,
.default_string = "", .default_string = NULL,
.default_int = 1 .default_int = 1
}, },
{ .name = "", .description = "", .type = CONFIG_END } { .name = "", .description = "", .type = CONFIG_END }
// clang-format on // clang-format on

View File

@@ -267,6 +267,13 @@ plat_getcwd(char *bufp, int max)
return 0; return 0;
} }
char *
path_get_basename(const char *path)
{
QFileInfo fi(path);
return fi.fileName().toUtf8().data();
}
void void
path_get_dirname(char *dest, const char *path) path_get_dirname(char *dest, const char *path)
{ {

View File

@@ -50,9 +50,13 @@ joystick_init(void)
SDL_SetHint(SDL_HINT_JOYSTICK_THREAD, "1"); SDL_SetHint(SDL_HINT_JOYSTICK_THREAD, "1");
#endif #endif
if (SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) != 0) { #ifdef __APPLE__
if (SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) != 0)
#else
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) != 0)
#endif
return; return;
}
joysticks_present = SDL_NumJoysticks(); joysticks_present = SDL_NumJoysticks();
memset(sdl_joy, 0, sizeof(sdl_joy)); memset(sdl_joy, 0, sizeof(sdl_joy));

View File

@@ -34,128 +34,146 @@
#endif #endif
#define I_NORMAL 0 #define I_NORMAL 0
#define I_MUSIC 1 #define I_MUSIC 1
#define I_WT 2 #define I_WT 2
#define I_CD 3 #define I_CD 3
#define I_MIDI 4 #define I_MIDI 4
static int audio[5] = {-1, -1, -1, -1, -1}; static int audio[5] = { -1, -1, -1, -1, -1 };
#ifdef USE_NEW_API #ifdef USE_NEW_API
static struct audio_swpar info[5]; static struct audio_swpar info[5];
#else #else
static audio_info_t info[5]; static audio_info_t info[5];
#endif #endif
static int freqs[5] = {SOUND_FREQ, MUSIC_FREQ, WT_FREQ, CD_FREQ, 0}; static int freqs[5] = { SOUND_FREQ, MUSIC_FREQ, WT_FREQ, CD_FREQ, 0 };
void closeal(void){ void
int i; closeal(void)
for(i = 0; i < sizeof(audio) / sizeof(audio[0]); i++){ {
if(audio[i] != -1){ for (int i = 0; i < sizeof(audio) / sizeof(audio[0]); i++) {
close(audio[i]); if (audio[i] != -1)
} close(audio[i]);
audio[i] = -1;
} audio[i] = -1;
}
} }
void inital(void){ void
int i; inital(void)
for(i = 0; i < sizeof(audio) / sizeof(audio[0]); i++){ {
audio[i] = open("/dev/audio", O_WRONLY); for (int i = 0; i < sizeof(audio) / sizeof(audio[0]); i++) {
if(audio[i] == -1) audio[i] = open("/dev/audio0", O_WRONLY); audio[i] = open("/dev/audio", O_WRONLY);
if(audio[i] != -1){ if (audio[i] == -1)
audio[i] = open("/dev/audio0", O_WRONLY);
if (audio[i] != -1) {
#ifdef USE_NEW_API #ifdef USE_NEW_API
AUDIO_INITPAR(&info[i]); AUDIO_INITPAR(&info[i]);
ioctl(audio[i], AUDIO_GETPAR, &info[i]); ioctl(audio[i], AUDIO_GETPAR, &info[i]);
info[i].sig = 1; info[i].sig = 1;
info[i].bits = 16; info[i].bits = 16;
info[i].pchan = 2; info[i].pchan = 2;
info[i].bps = 2; info[i].bps = 2;
ioctl(audio[i], AUDIO_SETPAR, &info[i]); ioctl(audio[i], AUDIO_SETPAR, &info[i]);
#else #else
AUDIO_INITINFO(&info[i]); AUDIO_INITINFO(&info[i]);
#if defined(__NetBSD__) && (__NetBSD_Version__ >= 900000000) #if defined(__NetBSD__) && (__NetBSD_Version__ >= 900000000)
ioctl(audio[i], AUDIO_GETFORMAT, &info[i]); ioctl(audio[i], AUDIO_GETFORMAT, &info[i]);
#else #else
ioctl(audio[i], AUDIO_GETINFO, &info[i]); ioctl(audio[i], AUDIO_GETINFO, &info[i]);
#endif #endif
info[i].play.channels = 2; info[i].play.channels = 2;
info[i].play.precision = 16; info[i].play.precision = 16;
info[i].play.encoding = AUDIO_ENCODING_SLINEAR; info[i].play.encoding = AUDIO_ENCODING_SLINEAR;
info[i].hiwat = 5; info[i].hiwat = 5;
info[i].lowat = 3; info[i].lowat = 3;
ioctl(audio[i], AUDIO_SETINFO, &info[i]); ioctl(audio[i], AUDIO_SETINFO, &info[i]);
#endif #endif
} }
} }
} }
void givealbuffer_common(const void *buf, const uint8_t src, const int size){ void
const int freq = freqs[src]; givealbuffer_common(const void *buf, const uint8_t src, const int size)
int16_t* output; {
int output_size; const int freq = freqs[src];
int16_t* conv; int16_t* output;
int conv_size; int output_size;
int i; int16_t* conv;
double gain; int conv_size;
int target_rate; double gain;
if(audio[src] == -1) return; int target_rate;
gain = sound_muted ? 0.0 : pow(10.0, (double) sound_gain / 20.0); if(audio[src] == -1)
return;
if(sound_is_float){ gain = sound_muted ? 0.0 : pow(10.0, (double) sound_gain / 20.0);
float* input = (float*)buf;
conv_size = sizeof(int16_t) * size; if (sound_is_float) {
conv = malloc(conv_size); float* input = (float*)buf;
for(i = 0; i < conv_size / sizeof(int16_t); i++){ conv_size = sizeof(int16_t) * size;
conv[i] = 32767 * input[i]; conv = malloc(conv_size);
} for (int i = 0; i < conv_size / sizeof(int16_t); i++)
}else{ conv[i] = 32767 * input[i];
conv_size = size * sizeof(int16_t); } else {
conv = malloc(conv_size); conv_size = size * sizeof(int16_t);
memcpy(conv, buf, conv_size); conv = malloc(conv_size);
} memcpy(conv, buf, conv_size);
}
#ifdef USE_NEW_API #ifdef USE_NEW_API
target_rate = info[src].rate; target_rate = info[src].rate;
#else #else
target_rate = info[src].play.sample_rate; target_rate = info[src].play.sample_rate;
#endif #endif
output_size = (double)conv_size * target_rate / freq; output_size = (double) conv_size * target_rate / freq;
output_size -= output_size % 4; output_size -= output_size % 4;
output = malloc(output_size); output = malloc(output_size);
for(i = 0; i < output_size / sizeof(int16_t) / 2; i++){ for (int i = 0; i < output_size / sizeof(int16_t) / 2; i++) {
int ind = i * freq / target_rate * 2; int ind = i * freq / target_rate * 2;
output[i * 2 + 0] = conv[ind + 0] * gain; output[i * 2 + 0] = conv[ind + 0] * gain;
output[i * 2 + 1] = conv[ind + 1] * gain; output[i * 2 + 1] = conv[ind + 1] * gain;
} }
write(audio[src], output, output_size); write(audio[src], output, output_size);
free(conv); free(conv);
free(output); free(output);
} }
void givealbuffer(const void *buf){ void
givealbuffer_common(buf, I_NORMAL, SOUNDBUFLEN << 1); givealbuffer(const void *buf)
{
givealbuffer_common(buf, I_NORMAL, SOUNDBUFLEN << 1);
} }
void givealbuffer_music(const void *buf){ void
givealbuffer_common(buf, I_MUSIC, MUSICBUFLEN << 1); givealbuffer_music(const void *buf)
{
givealbuffer_common(buf, I_MUSIC, MUSICBUFLEN << 1);
} }
void givealbuffer_wt(const void *buf){ void
givealbuffer_common(buf, I_WT, WTBUFLEN << 1); givealbuffer_wt(const void *buf)
{
givealbuffer_common(buf, I_WT, WTBUFLEN << 1);
} }
void givealbuffer_cd(const void *buf){ void
givealbuffer_common(buf, I_CD, CD_BUFLEN << 1); givealbuffer_cd(const void *buf)
{
givealbuffer_common(buf, I_CD, CD_BUFLEN << 1);
} }
void givealbuffer_midi(const void *buf, const uint32_t size){
givealbuffer_common(buf, I_MIDI, (int) size); void
givealbuffer_midi(const void *buf, const uint32_t size)
{
givealbuffer_common(buf, I_MIDI, (int) size);
} }
void al_set_midi(const int freq, UNUSED(const int buf_size)){ void
freqs[I_MIDI] = freq; al_set_midi(const int freq, UNUSED(const int buf_size))
{
freqs[I_MIDI] = freq;
} }

View File

@@ -37,6 +37,12 @@
#define FREQ SOUND_FREQ #define FREQ SOUND_FREQ
#define BUFLEN SOUNDBUFLEN #define BUFLEN SOUNDBUFLEN
#define I_NORMAL 0
#define I_MUSIC 1
#define I_WT 2
#define I_CD 3
#define I_MIDI 4
ALuint buffers[4]; /* front and back buffers */ ALuint buffers[4]; /* front and back buffers */
ALuint buffers_music[4]; /* front and back buffers */ ALuint buffers_music[4]; /* front and back buffers */
ALuint buffers_wt[4]; /* front and back buffers */ ALuint buffers_wt[4]; /* front and back buffers */
@@ -124,7 +130,7 @@ inital(void)
int16_t *cd_buf_int16 = NULL; int16_t *cd_buf_int16 = NULL;
int16_t *midi_buf_int16 = NULL; int16_t *midi_buf_int16 = NULL;
int init_midi = 0; int init_midi = 0;
if (initialized) if (initialized)
return; return;
@@ -166,32 +172,36 @@ inital(void)
else else
alGenSources(4, source); alGenSources(4, source);
alSource3f(source[0], AL_POSITION, 0.0f, 0.0f, 0.0f); alSource3f(source[I_NORMAL], AL_POSITION, 0.0f, 0.0f, 0.0f);
alSource3f(source[0], AL_VELOCITY, 0.0f, 0.0f, 0.0f); alSource3f(source[I_NORMAL], AL_VELOCITY, 0.0f, 0.0f, 0.0f);
alSource3f(source[0], AL_DIRECTION, 0.0f, 0.0f, 0.0f); alSource3f(source[I_NORMAL], AL_DIRECTION, 0.0f, 0.0f, 0.0f);
alSourcef(source[0], AL_ROLLOFF_FACTOR, 0.0f); alSourcef(source[I_NORMAL], AL_ROLLOFF_FACTOR, 0.0f);
alSourcei(source[0], AL_SOURCE_RELATIVE, AL_TRUE); alSourcei(source[I_NORMAL], AL_SOURCE_RELATIVE, AL_TRUE);
alSource3f(source[1], AL_POSITION, 0.0f, 0.0f, 0.0f);
alSource3f(source[1], AL_VELOCITY, 0.0f, 0.0f, 0.0f); alSource3f(source[I_MUSIC], AL_POSITION, 0.0f, 0.0f, 0.0f);
alSource3f(source[1], AL_DIRECTION, 0.0f, 0.0f, 0.0f); alSource3f(source[I_MUSIC], AL_VELOCITY, 0.0f, 0.0f, 0.0f);
alSourcef(source[1], AL_ROLLOFF_FACTOR, 0.0f); alSource3f(source[I_MUSIC], AL_DIRECTION, 0.0f, 0.0f, 0.0f);
alSourcei(source[1], AL_SOURCE_RELATIVE, AL_TRUE); alSourcef(source[I_MUSIC], AL_ROLLOFF_FACTOR, 0.0f);
alSource3f(source[2], AL_POSITION, 0.0f, 0.0f, 0.0f); alSourcei(source[I_MUSIC], AL_SOURCE_RELATIVE, AL_TRUE);
alSource3f(source[2], AL_VELOCITY, 0.0f, 0.0f, 0.0f);
alSource3f(source[2], AL_DIRECTION, 0.0f, 0.0f, 0.0f); alSource3f(source[I_WT], AL_POSITION, 0.0f, 0.0f, 0.0f);
alSourcef(source[2], AL_ROLLOFF_FACTOR, 0.0f); alSource3f(source[I_WT], AL_VELOCITY, 0.0f, 0.0f, 0.0f);
alSourcei(source[2], AL_SOURCE_RELATIVE, AL_TRUE); alSource3f(source[I_WT], AL_DIRECTION, 0.0f, 0.0f, 0.0f);
alSource3f(source[3], AL_POSITION, 0.0f, 0.0f, 0.0f); alSourcef(source[I_WT], AL_ROLLOFF_FACTOR, 0.0f);
alSource3f(source[3], AL_VELOCITY, 0.0f, 0.0f, 0.0f); alSourcei(source[I_WT], AL_SOURCE_RELATIVE, AL_TRUE);
alSource3f(source[3], AL_DIRECTION, 0.0f, 0.0f, 0.0f);
alSourcef(source[3], AL_ROLLOFF_FACTOR, 0.0f); alSource3f(source[I_CD], AL_POSITION, 0.0f, 0.0f, 0.0f);
alSourcei(source[3], AL_SOURCE_RELATIVE, AL_TRUE); alSource3f(source[I_CD], AL_VELOCITY, 0.0f, 0.0f, 0.0f);
alSource3f(source[I_CD], AL_DIRECTION, 0.0f, 0.0f, 0.0f);
alSourcef(source[I_CD], AL_ROLLOFF_FACTOR, 0.0f);
alSourcei(source[I_CD], AL_SOURCE_RELATIVE, AL_TRUE);
if (init_midi) { if (init_midi) {
alSource3f(source[4], AL_POSITION, 0.0f, 0.0f, 0.0f); alSource3f(source[I_MIDI], AL_POSITION, 0.0f, 0.0f, 0.0f);
alSource3f(source[4], AL_VELOCITY, 0.0f, 0.0f, 0.0f); alSource3f(source[I_MIDI], AL_VELOCITY, 0.0f, 0.0f, 0.0f);
alSource3f(source[4], AL_DIRECTION, 0.0f, 0.0f, 0.0f); alSource3f(source[I_MIDI], AL_DIRECTION, 0.0f, 0.0f, 0.0f);
alSourcef(source[4], AL_ROLLOFF_FACTOR, 0.0f); alSourcef(source[I_MIDI], AL_ROLLOFF_FACTOR, 0.0f);
alSourcei(source[4], AL_SOURCE_RELATIVE, AL_TRUE); alSourcei(source[I_MIDI], AL_SOURCE_RELATIVE, AL_TRUE);
} }
if (sound_is_float) { if (sound_is_float) {
@@ -228,18 +238,18 @@ inital(void)
} }
} }
alSourceQueueBuffers(source[0], 4, buffers); alSourceQueueBuffers(source[I_NORMAL], 4, buffers);
alSourceQueueBuffers(source[1], 4, buffers_music); alSourceQueueBuffers(source[I_MUSIC], 4, buffers_music);
alSourceQueueBuffers(source[2], 4, buffers_wt); alSourceQueueBuffers(source[I_WT], 4, buffers_wt);
alSourceQueueBuffers(source[3], 4, buffers_cd); alSourceQueueBuffers(source[I_CD], 4, buffers_cd);
if (init_midi) if (init_midi)
alSourceQueueBuffers(source[4], 4, buffers_midi); alSourceQueueBuffers(source[I_MIDI], 4, buffers_midi);
alSourcePlay(source[0]); alSourcePlay(source[I_NORMAL]);
alSourcePlay(source[1]); alSourcePlay(source[I_MUSIC]);
alSourcePlay(source[2]); alSourcePlay(source[I_WT]);
alSourcePlay(source[3]); alSourcePlay(source[I_CD]);
if (init_midi) if (init_midi)
alSourcePlay(source[4]); alSourcePlay(source[I_MIDI]);
if (sound_is_float) { if (sound_is_float) {
if (init_midi) if (init_midi)

View File

@@ -556,11 +556,11 @@ emu8k_inw(uint16_t addr, void *priv)
return ret; return ret;
case 4: case 4:
READ16(addr, emu8k->voice[emu8k->cur_voice].unknown_data0_4); READ16(addr, emu8k->voice[emu8k->cur_voice].z2);
return ret; return ret;
case 5: case 5:
READ16(addr, emu8k->voice[emu8k->cur_voice].unknown_data0_5); READ16(addr, emu8k->voice[emu8k->cur_voice].z1);
return ret; return ret;
case 6: case 6:
@@ -888,11 +888,11 @@ emu8k_outw(uint16_t addr, uint16_t val, void *priv)
return; return;
case 4: case 4:
WRITE16(addr, emu8k->voice[emu8k->cur_voice].unknown_data0_4, val); WRITE16(addr, emu8k->voice[emu8k->cur_voice].z2, val);
return; return;
case 5: case 5:
WRITE16(addr, emu8k->voice[emu8k->cur_voice].unknown_data0_5, val); WRITE16(addr, emu8k->voice[emu8k->cur_voice].z1, val);
return; return;
case 6: case 6:
@@ -1006,7 +1006,7 @@ emu8k_outw(uint16_t addr, uint16_t val, void *priv)
case 0x9: case 0x9:
emu8k->reverb_engine.reflections[0].feedback = (val & 0xF) / 15.0; emu8k->reverb_engine.reflections[0].feedback = (val & 0xF) / 15.0;
break; break;
case 0xB: case 0xB:
#if 0 #if 0
emu8k->reverb_engine.reflections[0].feedback_r = (val&0xF)/15.0; emu8k->reverb_engine.reflections[0].feedback_r = (val&0xF)/15.0;
#endif #endif
@@ -1050,7 +1050,7 @@ emu8k_outw(uint16_t addr, uint16_t val, void *priv)
case 1: case 1:
emu8k->reverb_engine.refl_in_amp = val & 0xFF; emu8k->reverb_engine.refl_in_amp = val & 0xFF;
break; break;
case 3: case 3:
#if 0 #if 0
emu8k->reverb_engine.refl_in_amp_r = val&0xFF; emu8k->reverb_engine.refl_in_amp_r = val&0xFF;
#endif #endif
@@ -1811,11 +1811,10 @@ emu8k_update(emu8k_t *emu8k)
emu_voice->filt_buffer[1] += (emu_voice->filt_buffer[0] * coef0) >> 24; emu_voice->filt_buffer[1] += (emu_voice->filt_buffer[0] * coef0) >> 24;
emu_voice->filt_buffer[0] += (vhp * coef0) >> 24; emu_voice->filt_buffer[0] += (vhp * coef0) >> 24;
dat = (int32_t) (emu_voice->filt_buffer[1] >> 8); dat = (int32_t) (emu_voice->filt_buffer[1] >> 8);
if (dat > 32767) { if (dat > 32767)
dat = 32767; dat = 32767;
} else if (dat < -32768) { else if (dat < -32768)
dat = -32768; dat = -32768;
}
#elif defined FILTER_MOOG #elif defined FILTER_MOOG
@@ -1823,15 +1822,15 @@ emu8k_update(emu8k_t *emu8k)
dat <<= 8; dat <<= 8;
dat -= (coef2 * emu_voice->filt_buffer[4]) >> 24; /*feedback*/ dat -= (coef2 * emu_voice->filt_buffer[4]) >> 24; /*feedback*/
int64_t t1 = emu_voice->filt_buffer[1]; int64_t t1 = emu_voice->filt_buffer[1];
emu_voice->filt_buffer[1] = ((dat + emu_voice->filt_buffer[0]) * coef0 - emu_voice->filt_buffer[1] * coef1) >> 24; emu_voice->filt_buffer[1] = ((dat + emu_voice->filt_buffer[0]) * coef0 - emu_voice->filt_buffer[1] * coef1) >> 24;
emu_voice->filt_buffer[1] = ClipBuffer(emu_voice->filt_buffer[1]); emu_voice->filt_buffer[1] = ClipBuffer(emu_voice->filt_buffer[1]);
int64_t t2 = emu_voice->filt_buffer[2]; int64_t t2 = emu_voice->filt_buffer[2];
emu_voice->filt_buffer[2] = ((emu_voice->filt_buffer[1] + t1) * coef0 - emu_voice->filt_buffer[2] * coef1) >> 24; emu_voice->filt_buffer[2] = ((emu_voice->filt_buffer[1] + t1) * coef0 - emu_voice->filt_buffer[2] * coef1) >> 24;
emu_voice->filt_buffer[2] = ClipBuffer(emu_voice->filt_buffer[2]); emu_voice->filt_buffer[2] = ClipBuffer(emu_voice->filt_buffer[2]);
int64_t t3 = emu_voice->filt_buffer[3]; int64_t t3 = emu_voice->filt_buffer[3];
emu_voice->filt_buffer[3] = ((emu_voice->filt_buffer[2] + t2) * coef0 - emu_voice->filt_buffer[3] * coef1) >> 24; emu_voice->filt_buffer[3] = ((emu_voice->filt_buffer[2] + t2) * coef0 - emu_voice->filt_buffer[3] * coef1) >> 24;
emu_voice->filt_buffer[3] = ClipBuffer(emu_voice->filt_buffer[3]); emu_voice->filt_buffer[3] = ClipBuffer(emu_voice->filt_buffer[3]);
@@ -1841,11 +1840,10 @@ emu8k_update(emu8k_t *emu8k)
emu_voice->filt_buffer[0] = ClipBuffer(dat); emu_voice->filt_buffer[0] = ClipBuffer(dat);
dat = (int32_t) (emu_voice->filt_buffer[4] >> 8); dat = (int32_t) (emu_voice->filt_buffer[4] >> 8);
if (dat > 32767) { if (dat > 32767)
dat = 32767; dat = 32767;
} else if (dat < -32768) { else if (dat < -32768)
dat = -32768; dat = -32768;
}
#elif defined FILTER_CONSTANT #elif defined FILTER_CONSTANT
@@ -1864,11 +1862,10 @@ emu8k_update(emu8k_t *emu8k)
emu_voice->filt_buffer[1] = ClipBuffer(emu_voice->filt_buffer[1]); emu_voice->filt_buffer[1] = ClipBuffer(emu_voice->filt_buffer[1]);
dat = (int32_t) (emu_voice->filt_buffer[1] >> 8); dat = (int32_t) (emu_voice->filt_buffer[1] >> 8);
if (dat > 32767) { if (dat > 32767)
dat = 32767; dat = 32767;
} else if (dat < -32768) { else if (dat < -32768)
dat = -32768; dat = -32768;
}
#endif #endif
} }
@@ -2372,6 +2369,8 @@ emu8k_init(emu8k_t *emu8k, uint16_t emu_addr, int onboard_ram)
void void
emu8k_close(emu8k_t *emu8k) emu8k_close(emu8k_t *emu8k)
{ {
free(emu8k->rom); if (emu8k->rom)
free(emu8k->ram); free(emu8k->rom);
if (emu8k->ram)
free(emu8k->ram);
} }

View File

@@ -32,109 +32,125 @@
#define I_CD 3 #define I_CD 3
#define I_MIDI 4 #define I_MIDI 4
static struct sio_hdl* audio[5] = {NULL, NULL, NULL, NULL, NULL}; static struct sio_hdl* audio[5] = { NULL, NULL, NULL, NULL, NULL };
static struct sio_par info[5]; static struct sio_par info[5];
static int freqs[5] = {SOUND_FREQ, MUSIC_FREQ, WT_FREQ, CD_FREQ, 0}; static int freqs[5] = { SOUND_FREQ, MUSIC_FREQ, WT_FREQ, CD_FREQ, 0 };
void closeal(void){ void
int i; closeal(void)
for(i = 0; i < sizeof(audio) / sizeof(audio[0]); i++){ {
if(audio[i] != NULL){ for (int i = 0; i < sizeof(audio) / sizeof(audio[0]); i++) {
sio_close(audio[i]); if (audio[i] != NULL)
} sio_close(audio[i]);
audio[i] = NULL;
} audio[i] = NULL;
}
} }
void inital(void){ void
int i; inital(void)
for(i = 0; i < sizeof(audio) / sizeof(audio[0]); i++){ {
audio[i] = sio_open(SIO_DEVANY, SIO_PLAY, 0); for (int i = 0; i < sizeof(audio) / sizeof(audio[0]); i++) {
if(audio[i] != NULL){ audio[i] = sio_open(SIO_DEVANY, SIO_PLAY, 0);
int rate; if (audio[i] != NULL) {
int max_frames; int rate;
sio_getpar(audio[i], &info[i]); int max_frames;
rate = info[i].rate; sio_getpar(audio[i], &info[i]);
max_frames = info[i].bufsz; rate = info[i].rate;
sio_initpar(&info[i]); max_frames = info[i].bufsz;
info[i].sig = 1; sio_initpar(&info[i]);
info[i].bits = 16; info[i].sig = 1;
info[i].pchan = 2; info[i].bits = 16;
info[i].rate = rate; info[i].pchan = 2;
info[i].appbufsz = max_frames; info[i].rate = rate;
sio_setpar(audio[i], &info[i]); info[i].appbufsz = max_frames;
sio_getpar(audio[i], &info[i]); sio_setpar(audio[i], &info[i]);
if(!sio_start(audio[i])){ sio_getpar(audio[i], &info[i]);
sio_close(audio[i]); if (!sio_start(audio[i])) {
audio[i] = NULL; sio_close(audio[i]);
} audio[i] = NULL;
} }
} }
}
} }
void givealbuffer_common(const void *buf, const uint8_t src, const int size){ void
const int freq = freqs[src]; givealbuffer_common(const void *buf, const uint8_t src, const int size)
int16_t* output; {
int output_size; const int freq = freqs[src];
int16_t* conv; int16_t* output;
int conv_size; int output_size;
int i; int16_t* conv;
double gain; int conv_size;
int target_rate; double gain;
if(audio[src] == NULL) return; int target_rate;
if (audio[src] == NULL)
return;
gain = sound_muted ? 0.0 : pow(10.0, (double) sound_gain / 20.0); gain = sound_muted ? 0.0 : pow(10.0, (double) sound_gain / 20.0);
if(sound_is_float){ if (sound_is_float) {
float* input = (float*)buf; float* input = (float*) buf;
conv_size = sizeof(int16_t) * size; conv_size = sizeof(int16_t) * size;
conv = malloc(conv_size); conv = malloc(conv_size);
for(i = 0; i < conv_size / sizeof(int16_t); i++){ for (int i = 0; i < conv_size / sizeof(int16_t); i++)
conv[i] = 32767 * input[i]; conv[i] = 32767 * input[i];
} } else {
}else{ conv_size = size * sizeof(int16_t);
conv_size = size * sizeof(int16_t); conv = malloc(conv_size);
conv = malloc(conv_size); memcpy(conv, buf, conv_size);
memcpy(conv, buf, conv_size); }
}
target_rate = info[src].rate; target_rate = info[src].rate;
output_size = (double)conv_size * target_rate / freq; output_size = (double) conv_size * target_rate / freq;
output_size -= output_size % 4; output_size -= output_size % 4;
output = malloc(output_size); output = malloc(output_size);
for(i = 0; i < output_size / sizeof(int16_t) / 2; i++){ for (int i = 0; i < output_size / sizeof(int16_t) / 2; i++) {
int ind = i * freq / target_rate * 2; int ind = i * freq / target_rate * 2;
output[i * 2 + 0] = conv[ind + 0] * gain; output[i * 2 + 0] = conv[ind + 0] * gain;
output[i * 2 + 1] = conv[ind + 1] * gain; output[i * 2 + 1] = conv[ind + 1] * gain;
} }
sio_write(audio[src], output, output_size); sio_write(audio[src], output, output_size);
free(conv); free(conv);
free(output); free(output);
} }
void givealbuffer(const void *buf){ void
givealbuffer_common(buf, I_NORMAL, SOUNDBUFLEN << 1); givealbuffer(const void *buf)
{
givealbuffer_common(buf, I_NORMAL, SOUNDBUFLEN << 1);
} }
void givealbuffer_music(const void *buf){ void
givealbuffer_common(buf, I_MUSIC, MUSICBUFLEN << 1); givealbuffer_music(const void *buf)
{
givealbuffer_common(buf, I_MUSIC, MUSICBUFLEN << 1);
} }
void givealbuffer_wt(const void *buf){ void
givealbuffer_common(buf, I_WT, WTBUFLEN << 1); givealbuffer_wt(const void *buf)
{
givealbuffer_common(buf, I_WT, WTBUFLEN << 1);
} }
void givealbuffer_cd(const void *buf){ void
givealbuffer_common(buf, I_CD, CD_BUFLEN << 1); givealbuffer_cd(const void *buf)
{
givealbuffer_common(buf, I_CD, CD_BUFLEN << 1);
} }
void givealbuffer_midi(const void *buf, const uint32_t size){
givealbuffer_common(buf, I_MIDI, (int) size); void
givealbuffer_midi(const void *buf, const uint32_t size)
{
givealbuffer_common(buf, I_MIDI, (int) size);
} }
void al_set_midi(const int freq, UNUSED(const int buf_size)){ void
freqs[I_MIDI] = freq; al_set_midi(const int freq, UNUSED(const int buf_size))
{
freqs[I_MIDI] = freq;
} }

View File

@@ -55,7 +55,6 @@ int wavetable_pos_global = 0;
int sound_gain = 0; int sound_gain = 0;
static sound_handler_t sound_handlers[8]; static sound_handler_t sound_handlers[8];
static sound_handler_t music_handlers[8]; static sound_handler_t music_handlers[8];
static sound_handler_t wavetable_handlers[8]; static sound_handler_t wavetable_handlers[8];

View File

@@ -39,8 +39,8 @@
static void *xaudio2_handle = NULL; static void *xaudio2_handle = NULL;
static HRESULT(WINAPI *pXAudio2Create)(IXAudio2 **ppXAudio2, uint32_t Flags, XAUDIO2_PROCESSOR XAudio2Processor); static HRESULT(WINAPI *pXAudio2Create)(IXAudio2 **ppXAudio2, uint32_t Flags, XAUDIO2_PROCESSOR XAudio2Processor);
static dllimp_t xaudio2_imports[] = { static dllimp_t xaudio2_imports[] = {
{"XAudio2Create", &pXAudio2Create}, {"XAudio2Create", &pXAudio2Create },
{ NULL, NULL }, { NULL, NULL },
}; };
# define XAudio2Create pXAudio2Create # define XAudio2Create pXAudio2Create
#endif #endif
@@ -119,22 +119,18 @@ void
inital(void) inital(void)
{ {
#if defined(_WIN32) && !defined(USE_FAUDIO) #if defined(_WIN32) && !defined(USE_FAUDIO)
if (xaudio2_handle == NULL) { if (xaudio2_handle == NULL)
xaudio2_handle = dynld_module("xaudio2_9.dll", xaudio2_imports); xaudio2_handle = dynld_module("xaudio2_9.dll", xaudio2_imports);
}
if (xaudio2_handle == NULL) { if (xaudio2_handle == NULL)
xaudio2_handle = dynld_module("xaudio2_9redist.dll", xaudio2_imports); xaudio2_handle = dynld_module("xaudio2_9redist.dll", xaudio2_imports);
}
if (xaudio2_handle == NULL) { if (xaudio2_handle == NULL)
return; return;
}
#endif #endif
if (XAudio2Create(&xaudio2, 0, XAUDIO2_DEFAULT_PROCESSOR)) { if (XAudio2Create(&xaudio2, 0, XAUDIO2_DEFAULT_PROCESSOR))
return; return;
}
if (IXAudio2_CreateMasteringVoice(xaudio2, &mastervoice, 2, FREQ, 0, 0, NULL, 0)) { if (IXAudio2_CreateMasteringVoice(xaudio2, &mastervoice, 2, FREQ, 0, 0, NULL, 0)) {
IXAudio2_Release(xaudio2); IXAudio2_Release(xaudio2);
@@ -209,6 +205,7 @@ closeal(void)
{ {
if (!initialized) if (!initialized)
return; return;
initialized = 0; initialized = 0;
(void) IXAudio2SourceVoice_Stop(srcvoice, 0, XAUDIO2_COMMIT_NOW); (void) IXAudio2SourceVoice_Stop(srcvoice, 0, XAUDIO2_COMMIT_NOW);
(void) IXAudio2SourceVoice_FlushSourceBuffers(srcvoice); (void) IXAudio2SourceVoice_FlushSourceBuffers(srcvoice);
@@ -229,9 +226,11 @@ closeal(void)
IXAudio2SourceVoice_DestroyVoice(srcvoice); IXAudio2SourceVoice_DestroyVoice(srcvoice);
IXAudio2MasteringVoice_DestroyVoice(mastervoice); IXAudio2MasteringVoice_DestroyVoice(mastervoice);
IXAudio2_Release(xaudio2); IXAudio2_Release(xaudio2);
srcvoice = srcvoicecd = srcvoicemidi = NULL; srcvoice = NULL;
mastervoice = NULL; srcvoicecd = NULL;
xaudio2 = NULL; srcvoicemidi = NULL;
mastervoice = NULL;
xaudio2 = NULL;
#if defined(_WIN32) && !defined(USE_FAUDIO) #if defined(_WIN32) && !defined(USE_FAUDIO)
dynld_close(xaudio2_handle); dynld_close(xaudio2_handle);

View File

@@ -351,7 +351,7 @@ plat_put_backslash(char *s)
/* Return the last element of a pathname. */ /* Return the last element of a pathname. */
char * char *
plat_get_basename(const char *path) path_get_basename(const char *path)
{ {
int c = (int) strlen(path); int c = (int) strlen(path);
@@ -1420,6 +1420,7 @@ main(int argc, char **argv)
f_rl_callback_handler_remove(); f_rl_callback_handler_remove();
return 0; return 0;
} }
char * char *
plat_vidapi_name(UNUSED(int i)) plat_vidapi_name(UNUSED(int i))
{ {