Split generic CD-ROM from SCSI-style CD-ROM;

Redid the way SCSI and ATAPI devices are handled;
Slight timings change in the NCR 5380;
Devices are now closed by device_close_all() in the reverse order of the one in which they were started;
Slight changes to some code in win/;
Added the WM_HARDRESET and WM_SHUTDOWN window messages for configuration manager purposes.
This commit is contained in:
OBattler
2018-10-10 22:33:24 +02:00
parent 173b1f7694
commit 6155802b59
36 changed files with 4557 additions and 4792 deletions

View File

@@ -8,7 +8,7 @@
*
* MIDI device core module.
*
* Version: @(#)midi.c 1.0.0 2018/09/06
* Version: @(#)midi.c 1.0.1 2018/10/10
*
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
@@ -179,6 +179,11 @@ midi_init(midi_device_t* device)
void
midi_close(void)
{
if (midi && midi->m_device) {
free(midi->m_device);
midi->m_device = NULL;
}
if (midi) {
free(midi);
midi = NULL;

View File

@@ -61,7 +61,6 @@ static int (*f_fluid_synth_sysex)(void *synth, const char *data, int len, char
static int (*f_fluid_synth_pitch_bend)(void *synth, int chan, int val);
static int (*f_fluid_synth_program_change)(void *synth, int chan, int program);
static int (*f_fluid_synth_sfload)(void *synth, const char *filename, int reset_presets);
static int (*f_fluid_synth_sfunload)(void *synth, unsigned int id, int reset_presets);
static int (*f_fluid_synth_set_interp_method)(void *synth, int chan, int interp_method);
static void (*f_fluid_synth_set_reverb)(void *synth, double roomsize, double damping, double width, double level);
static void (*f_fluid_synth_set_reverb_on)(void *synth, int on);
@@ -84,7 +83,6 @@ static dllimp_t fluidsynth_imports[] = {
{ "fluid_synth_pitch_bend", &f_fluid_synth_pitch_bend },
{ "fluid_synth_program_change", &f_fluid_synth_program_change },
{ "fluid_synth_sfload", &f_fluid_synth_sfload },
{ "fluid_synth_sfunload", &f_fluid_synth_sfunload },
{ "fluid_synth_set_interp_method", &f_fluid_synth_set_interp_method },
{ "fluid_synth_set_reverb", &f_fluid_synth_set_reverb },
{ "fluid_synth_set_reverb_on", &f_fluid_synth_set_reverb_on },
@@ -104,13 +102,14 @@ typedef struct fluidsynth
int samplerate;
int sound_font;
thread_t* thread_h;
event_t* event;
thread_t *thread_h;
event_t *event, *start_event;
int buf_size;
float* buffer;
int16_t* buffer_int16;
int midi_pos;
int on;
} fluidsynth_t;
fluidsynth_t fsdev;
@@ -136,9 +135,14 @@ static void fluidsynth_thread(void *param)
fluidsynth_t* data = (fluidsynth_t*)param;
int buf_pos = 0;
int buf_size = data->buf_size / BUFFER_SEGMENTS;
while (1)
thread_set_event(data->start_event);
while (data->on)
{
thread_wait_event(data->event, -1);
thread_reset_event(data->event);
if (sound_is_float)
{
float *buf = (float*)((uint8_t*)data->buffer + buf_pos);
@@ -237,6 +241,8 @@ void fluidsynth_sysex(uint8_t* data, unsigned int len)
void* fluidsynth_init(const device_t *info)
{
fluidsynth_t* data = &fsdev;
midi_device_t* dev;
memset(data, 0, sizeof(fluidsynth_t));
/* Try loading the DLL. */
@@ -324,12 +330,10 @@ void* fluidsynth_init(const device_t *info)
data->buffer = NULL;
data->buffer_int16 = malloc(data->buf_size);
}
data->event = thread_create_event();
data->thread_h = thread_create(fluidsynth_thread, data);
al_set_midi(data->samplerate, data->buf_size);
midi_device_t* dev = malloc(sizeof(midi_device_t));
dev = malloc(sizeof(midi_device_t));
memset(dev, 0, sizeof(midi_device_t));
dev->play_msg = fluidsynth_msg;
@@ -338,6 +342,16 @@ void* fluidsynth_init(const device_t *info)
midi_init(dev);
data->on = 1;
data->start_event = thread_create_event();
data->event = thread_create_event();
data->thread_h = thread_create(fluidsynth_thread, data);
thread_wait_event(data->start_event, -1);
thread_reset_event(data->start_event);
return dev;
}
@@ -347,10 +361,9 @@ void fluidsynth_close(void* p)
fluidsynth_t* data = &fsdev;
if (data->sound_font != -1) {
f_fluid_synth_sfunload(data->synth, data->sound_font, 1);
data->sound_font = -1;
}
data->on = 0;
thread_set_event(data->event);
thread_wait(data->thread_h, -1);
if (data->synth) {
f_delete_fluid_synth(data->synth);
@@ -362,8 +375,6 @@ void fluidsynth_close(void* p)
data->settings = NULL;
}
midi_close();
if (data->buffer)
{
free(data->buffer);

View File

@@ -83,6 +83,8 @@ int cm32l_available()
static thread_t *thread_h = NULL;
static event_t *event = NULL;
static event_t *start_event = NULL;
static int mt32_on = 0;
#define RENDER_RATE 100
#define BUFFER_SEGMENTS 10
@@ -119,13 +121,19 @@ static void mt32_thread(void *param)
{
int buf_pos = 0;
int bsize = buf_size / BUFFER_SEGMENTS;
while (1)
float *buf;
int16_t *buf16;
thread_set_event(start_event);
while (mt32_on)
{
thread_wait_event(event, -1);
thread_reset_event(event);
if (sound_is_float)
{
float *buf = (float *) ((uint8_t*)buffer + buf_pos);
buf = (float *) ((uint8_t*)buffer + buf_pos);
memset(buf, 0, bsize);
mt32_stream(buf, bsize / (2 * sizeof(float)));
buf_pos += bsize;
@@ -138,9 +146,9 @@ static void mt32_thread(void *param)
}
else
{
int16_t *buf = (int16_t *) ((uint8_t*)buffer_int16 + buf_pos);
memset(buf, 0, bsize);
mt32_stream_int16(buf, bsize / (2 * sizeof(int16_t)));
buf16 = (int16_t *) ((uint8_t*)buffer_int16 + buf_pos);
memset(buf16, 0, bsize);
mt32_stream_int16(buf16, bsize / (2 * sizeof(int16_t)));
buf_pos += bsize;
if (buf_pos >= buf_size)
{
@@ -164,9 +172,12 @@ void mt32_sysex(uint8_t* data, unsigned int len)
void* mt32emu_init(wchar_t *control_rom, wchar_t *pcm_rom)
{
midi_device_t* dev;
wchar_t s[512];
char fn[512];
context = mt32emu_create_context(handler, NULL);
if (!rom_getfile(control_rom, s, 512)) return 0;
wcstombs(fn, s, (wcslen(s) << 1) + 2);
if (!mt32_check("mt32emu_add_rom_file", mt32emu_add_rom_file(context, fn), MT32EMU_RC_ADDED_CONTROL_ROM)) return 0;
@@ -176,8 +187,6 @@ void* mt32emu_init(wchar_t *control_rom, wchar_t *pcm_rom)
if (!mt32_check("mt32emu_open_synth", mt32emu_open_synth(context), MT32EMU_RC_OK)) return 0;
event = thread_create_event();
thread_h = thread_create(mt32_thread, 0);
samplerate = mt32emu_get_actual_stereo_output_samplerate(context);
/* buf_size = samplerate/RENDER_RATE*2; */
if (sound_is_float)
@@ -201,7 +210,7 @@ void* mt32emu_init(wchar_t *control_rom, wchar_t *pcm_rom)
al_set_midi(samplerate, buf_size);
midi_device_t* dev = malloc(sizeof(midi_device_t));
dev = malloc(sizeof(midi_device_t));
memset(dev, 0, sizeof(midi_device_t));
dev->play_msg = mt32_msg;
@@ -210,6 +219,16 @@ void* mt32emu_init(wchar_t *control_rom, wchar_t *pcm_rom)
midi_init(dev);
mt32_on = 1;
start_event = thread_create_event();
event = thread_create_event();
thread_h = thread_create(mt32_thread, 0);
thread_wait_event(start_event, -1);
thread_reset_event(start_event);
return dev;
}
@@ -227,15 +246,15 @@ void mt32_close(void* p)
{
if (!p) return;
if (thread_h)
thread_kill(thread_h);
if (event)
thread_destroy_event(event);
mt32_on = 0;
thread_set_event(event);
thread_wait(thread_h, -1);
event = NULL;
start_event = NULL;
thread_h = NULL;
if (context)
{
if (context) {
mt32emu_close_synth(context);
mt32emu_free_context(context);
}
@@ -248,10 +267,6 @@ void mt32_close(void* p)
if (buffer_int16)
free(buffer_int16);
buffer_int16 = NULL;
midi_close();
free((midi_device_t*)p);
}
static const device_config_t mt32_config[] =

View File

@@ -8,7 +8,7 @@
*
* Sound emulation core.
*
* Version: @(#)sound.c 1.0.20 2018/10/02
* Version: @(#)sound.c 1.0.21 2018/10/09
*
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
@@ -26,7 +26,6 @@
#include "../86box.h"
#include "../device.h"
#include "../timer.h"
#include "../scsi/scsi_device.h"
#include "../cdrom/cdrom.h"
#include "../plat.h"
#include "sound.h"
@@ -188,68 +187,69 @@ void sound_set_cd_volume(unsigned int vol_l, unsigned int vol_r)
static void sound_cd_thread(void *param)
{
int i = 0;
int c, has_audio, d, r, i = 0;
int32_t audio_vol_l, audio_vol_r;
int channel_select[2];
float cd_buffer_temp[2] = {0.0, 0.0};
float cd_buffer_temp2[2] = {0.0, 0.0};
int32_t cd_buffer_temp4[2] = {0, 0};
int c, has_audio;
int d, r;
thread_set_event(sound_cd_start_event);
while (cdaudioon)
{
while (cdaudioon) {
thread_wait_event(sound_cd_event, -1);
thread_reset_event(sound_cd_event);
if (!soundon || !cdaudioon)
return;
for (c = 0; c < CD_BUFLEN*2; c += 2)
{
if (sound_is_float)
{
for (c = 0; c < CD_BUFLEN*2; c += 2) {
if (sound_is_float) {
cd_out_buffer[c] = 0.0;
cd_out_buffer[c+1] = 0.0;
}
else
{
} else {
cd_out_buffer_int16[c] = 0;
cd_out_buffer_int16[c+1] = 0;
}
}
for (i = 0; i < CDROM_NUM; i++)
{
for (i = 0; i < CDROM_NUM; i++) {
has_audio = 0;
if ((cdrom_drives[i].bus_type == CDROM_BUS_DISABLED) || !cdrom[i] || !cdrom[i]->handler)
if ((cdrom_drives[i].bus_type == CDROM_BUS_DISABLED) || !cdrom_drives[i].handler)
continue;
if (cdrom[i]->handler->audio_callback)
if (cdrom_drives[i].handler->audio_callback)
{
r = cdrom[i]->handler->audio_callback(i, cd_buffer[i], CD_BUFLEN*2);
r = cdrom_drives[i].handler->audio_callback(i, cd_buffer[i], CD_BUFLEN*2);
has_audio = (cdrom_drives[i].bus_type && cdrom_drives[i].sound_on/* && r*/);
} else
continue;
if (soundon && has_audio)
{
int32_t audio_vol_l = cdrom_mode_sense_get_volume(cdrom[i], 0);
int32_t audio_vol_r = cdrom_mode_sense_get_volume(cdrom[i], 1);
int channel_select[2];
channel_select[0] = cdrom_mode_sense_get_channel(cdrom[i], 0);
channel_select[1] = cdrom_mode_sense_get_channel(cdrom[i], 1);
if (soundon && has_audio) {
if (cdrom_drives[i].get_volume) {
audio_vol_l = cdrom_drives[i].get_volume(cdrom_drives[i].p, 0);
audio_vol_r = cdrom_drives[i].get_volume(cdrom_drives[i].p, 1);
} else {
audio_vol_l = 255;
audio_vol_r = 255;
}
if (!r)
{
for (c = 0; c < CD_BUFLEN*2; c += 2)
{
if (sound_is_float)
{
if (cdrom_drives[i].get_channel) {
channel_select[0] = cdrom_drives[i].get_channel(cdrom_drives[i].p, 0);
channel_select[1] = cdrom_drives[i].get_channel(cdrom_drives[i].p, 1);
} else {
channel_select[0] = 1;
channel_select[1] = 2;
}
if (!r) {
for (c = 0; c < CD_BUFLEN*2; c += 2) {
if (sound_is_float) {
cd_out_buffer[c] += 0.0;
cd_out_buffer[c+1] += 0.0;
}
else
{
} else {
cd_out_buffer_int16[c] += 0;
cd_out_buffer_int16[c+1] += 0;
}
@@ -257,8 +257,7 @@ static void sound_cd_thread(void *param)
continue;
}
for (c = 0; c < CD_BUFLEN*2; c += 2)
{
for (c = 0; c < CD_BUFLEN*2; c += 2) {
/* First, transfer the CD audio data to the temporary buffer. */
cd_buffer_temp[0] = (float) cd_buffer[i][c];
cd_buffer_temp[1] = (float) cd_buffer[i][c+1];
@@ -271,25 +270,17 @@ static void sound_cd_thread(void *param)
/*Apply ATAPI channel select*/
cd_buffer_temp2[0] = cd_buffer_temp2[1] = 0.0;
if (channel_select[0] & 1)
{
cd_buffer_temp2[0] += cd_buffer_temp[0];
}
if (channel_select[0] & 2)
{
cd_buffer_temp2[1] += cd_buffer_temp[0];
}
if (channel_select[1] & 1)
{
cd_buffer_temp2[0] += cd_buffer_temp[1];
}
if (channel_select[1] & 2)
{
cd_buffer_temp2[1] += cd_buffer_temp[1];
}
if (sound_process_handlers_num)
{
if (channel_select[0] & 1)
cd_buffer_temp2[0] += cd_buffer_temp[0];
if (channel_select[0] & 2)
cd_buffer_temp2[1] += cd_buffer_temp[0];
if (channel_select[1] & 1)
cd_buffer_temp2[0] += cd_buffer_temp[1];
if (channel_select[1] & 2)
cd_buffer_temp2[1] += cd_buffer_temp[1];
if (sound_process_handlers_num) {
cd_buffer_temp4[0] = (int32_t) cd_buffer_temp2[0];
cd_buffer_temp4[1] = (int32_t) cd_buffer_temp2[1];
@@ -298,9 +289,7 @@ static void sound_cd_thread(void *param)
cd_buffer_temp2[0] = (float) cd_buffer_temp4[0];
cd_buffer_temp2[1] = (float) cd_buffer_temp4[1];
}
else
{
} else {
/*Apply sound card CD volume*/
cd_buffer_temp2[0] *= (float) cd_vol_l;
cd_buffer_temp2[0] /= 65535.0;
@@ -309,13 +298,10 @@ static void sound_cd_thread(void *param)
cd_buffer_temp2[1] /= 65535.0;
}
if (sound_is_float)
{
if (sound_is_float) {
cd_out_buffer[c] += (cd_buffer_temp2[0] / 32768.0);
cd_out_buffer[c+1] += (cd_buffer_temp2[1] / 32768.0);
}
else
{
} else {
if (cd_buffer_temp2[0] > 32767)
cd_buffer_temp2[0] = 32767;
if (cd_buffer_temp2[0] < -32768)
@@ -331,6 +317,7 @@ static void sound_cd_thread(void *param)
}
}
}
if (sound_is_float)
givealbuffer_cd(cd_out_buffer);
else
@@ -540,21 +527,15 @@ void sound_cd_thread_reset(void)
int i = 0;
int available_cdrom_drives = 0;
for (i = 0; i < CDROM_NUM; i++)
{
if (cdrom[i] && cdrom[i]->handler && cdrom[i]->handler->audio_stop)
{
cdrom[i]->handler->audio_stop(i);
}
for (i = 0; i < CDROM_NUM; i++) {
if (cdrom_drives[i].handler && cdrom_drives[i].handler->audio_stop)
cdrom_drives[i].handler->audio_stop(i);
if ((cdrom_drives[i].bus_type != CDROM_BUS_DISABLED) && cdrom[i])
{
if (cdrom_drives[i].bus_type != CDROM_BUS_DISABLED)
available_cdrom_drives++;
}
}
if (available_cdrom_drives && !cd_thread_enable)
{
if (available_cdrom_drives && !cd_thread_enable) {
cdaudioon = 1;
sound_cd_start_event = thread_create_event();
@@ -564,9 +545,7 @@ void sound_cd_thread_reset(void)
thread_wait_event(sound_cd_start_event, -1);
thread_reset_event(sound_cd_start_event);
}
else if (!available_cdrom_drives && cd_thread_enable)
{
} else if (!available_cdrom_drives && cd_thread_enable) {
sound_cd_thread_end();
}