Reworked network and SCSI thread initialization and termination;
Hard disk controller name and other related strings are now char * instead of fixed-size arrays.
This commit is contained in:
21
src/config.c
21
src/config.c
@@ -714,7 +714,10 @@ load_other_peripherals(void)
|
||||
else
|
||||
scsi_card_current = 0;
|
||||
|
||||
memset(hdc_name, '\0', sizeof(hdc_name));
|
||||
if (hdc_name) {
|
||||
free(hdc_name);
|
||||
hdc_name = NULL;
|
||||
}
|
||||
p = config_get_string(cat, "hdc", NULL);
|
||||
if (p == NULL) {
|
||||
p = config_get_string(cat, "hdd_controller", NULL);
|
||||
@@ -722,12 +725,17 @@ load_other_peripherals(void)
|
||||
config_delete_var(cat, "hdd_controller");
|
||||
}
|
||||
if (p == NULL) {
|
||||
if (machines[machine].flags & MACHINE_HAS_HDC)
|
||||
if (machines[machine].flags & MACHINE_HAS_HDC) {
|
||||
hdc_name = (char *) malloc((strlen("internal") + 1) * sizeof(char));
|
||||
strcpy(hdc_name, "internal");
|
||||
else
|
||||
} else {
|
||||
hdc_name = (char *) malloc((strlen("none") + 1) * sizeof(char));
|
||||
strcpy(hdc_name, "none");
|
||||
} else
|
||||
}
|
||||
} else {
|
||||
hdc_name = (char *) malloc((strlen(p) + 1) * sizeof(char));
|
||||
strcpy(hdc_name, p);
|
||||
}
|
||||
config_set_string(cat, "hdc", hdc_name);
|
||||
|
||||
memset(temp, '\0', sizeof(temp));
|
||||
@@ -1142,6 +1150,11 @@ config_load(wchar_t *fn)
|
||||
vid_api = 1;
|
||||
enable_sync = 1;
|
||||
joystick_type = 7;
|
||||
if (hdc_name) {
|
||||
free(hdc_name);
|
||||
hdc_name = NULL;
|
||||
}
|
||||
hdc_name = (char *) malloc((strlen("none") + 1) * sizeof(char));
|
||||
strcpy(hdc_name, "none");
|
||||
serial_enabled[0] = 0;
|
||||
serial_enabled[1] = 0;
|
||||
|
@@ -45,7 +45,7 @@ device_init(void)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
void *
|
||||
device_add(device_t *d)
|
||||
{
|
||||
void *priv = NULL;
|
||||
@@ -65,7 +65,9 @@ device_add(device_t *d)
|
||||
}
|
||||
|
||||
devices[c] = d;
|
||||
device_priv[c] = priv;
|
||||
device_priv[c] = priv;
|
||||
|
||||
return priv;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -98,7 +98,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
extern void device_init(void);
|
||||
extern void device_add(device_t *d);
|
||||
extern void *device_add(device_t *d);
|
||||
extern void device_close_all(void);
|
||||
extern void device_reset_all(void);
|
||||
extern void *device_get_priv(device_t *d);
|
||||
|
@@ -28,7 +28,7 @@
|
||||
#include "hdc.h"
|
||||
|
||||
|
||||
char hdc_name[16]; /* configured HDC name */
|
||||
char *hdc_name; /* configured HDC name */
|
||||
int hdc_current;
|
||||
|
||||
|
||||
@@ -73,8 +73,8 @@ static device_t inthdc_device = {
|
||||
|
||||
|
||||
static struct {
|
||||
char name[50];
|
||||
char internal_name[16];
|
||||
char *name;
|
||||
char *internal_name;
|
||||
device_t *device;
|
||||
int is_mfm;
|
||||
} controllers[] = {
|
||||
|
@@ -27,7 +27,7 @@
|
||||
* least 7 devices, with each device being
|
||||
* able to support 8 units, but hey... */
|
||||
|
||||
extern char hdc_name[16];
|
||||
extern char *hdc_name;
|
||||
extern int hdc_current;
|
||||
|
||||
|
||||
|
@@ -29,11 +29,18 @@
|
||||
#include "network.h"
|
||||
|
||||
|
||||
static void *pcap_handle; /* handle to WinPcap DLL */
|
||||
static pcap_t *pcap; /* handle to WinPcap library */
|
||||
static thread_t *poll_tid;
|
||||
static NETRXCB poll_rx; /* network RX function to call */
|
||||
static void *poll_arg; /* network RX function arg */
|
||||
static volatile
|
||||
void *pcap_handle; /* handle to WinPcap DLL */
|
||||
static volatile
|
||||
pcap_t *pcap; /* handle to WinPcap library */
|
||||
static volatile
|
||||
thread_t *poll_tid;
|
||||
static volatile
|
||||
NETRXCB poll_rx; /* network RX function to call */
|
||||
static volatile
|
||||
void *poll_arg; /* network RX function arg */
|
||||
static volatile
|
||||
event_t *thread_started;
|
||||
|
||||
|
||||
/* Pointers to the real functions. */
|
||||
@@ -72,6 +79,8 @@ poll_thread(void *arg)
|
||||
uint16_t mac_cmp16[2];
|
||||
event_t *evt;
|
||||
|
||||
thread_set_event((event_t *) thread_started);
|
||||
|
||||
pclog("PCAP: polling thread started, arg %08lx\n", arg);
|
||||
|
||||
/* Create a waitable event. */
|
||||
@@ -84,7 +93,7 @@ poll_thread(void *arg)
|
||||
network_wait_for_poll();
|
||||
|
||||
/* Wait for the next packet to arrive. */
|
||||
data = f_pcap_next(pcap, &h);
|
||||
data = f_pcap_next((pcap_t *) pcap, &h);
|
||||
if (data != NULL) {
|
||||
/* Received MAC. */
|
||||
mac_cmp32[0] = *(uint32_t *)(data+6);
|
||||
@@ -96,7 +105,7 @@ poll_thread(void *arg)
|
||||
if ((mac_cmp32[0] != mac_cmp32[1]) ||
|
||||
(mac_cmp16[0] != mac_cmp16[1])) {
|
||||
if (poll_rx != NULL)
|
||||
poll_rx(poll_arg, (uint8_t *)data, h.caplen);
|
||||
poll_rx((void *) poll_arg, (uint8_t *)data, h.caplen);
|
||||
} else {
|
||||
/* Mark as invalid packet. */
|
||||
data = NULL;
|
||||
@@ -111,7 +120,6 @@ poll_thread(void *arg)
|
||||
}
|
||||
|
||||
thread_destroy_event(evt);
|
||||
poll_tid = NULL;
|
||||
|
||||
pclog("PCAP: polling stopped.\n");
|
||||
}
|
||||
@@ -224,15 +232,15 @@ network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg)
|
||||
"( ((ether dst ff:ff:ff:ff:ff:ff) or (ether dst %02x:%02x:%02x:%02x:%02x:%02x)) and not (ether src %02x:%02x:%02x:%02x:%02x:%02x) )",
|
||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
|
||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
if (f_pcap_compile(pcap, &fp, filter_exp, 0, 0xffffffff) != -1) {
|
||||
if (f_pcap_setfilter(pcap, &fp) == -1) {
|
||||
if (f_pcap_compile((pcap_t *) pcap, &fp, filter_exp, 0, 0xffffffff) != -1) {
|
||||
if (f_pcap_setfilter((pcap_t *) pcap, &fp) == -1) {
|
||||
pclog(" Error installing filter (%s) !\n", filter_exp);
|
||||
f_pcap_close(pcap);
|
||||
f_pcap_close((pcap_t *) pcap);
|
||||
return (-1);
|
||||
}
|
||||
} else {
|
||||
pclog(" Could not compile filter (%s) !\n", filter_exp);
|
||||
f_pcap_close(pcap);
|
||||
f_pcap_close((pcap_t *) pcap);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
@@ -245,6 +253,8 @@ network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg)
|
||||
pclog(" Starting thread..\n");
|
||||
poll_tid = thread_create(poll_thread, mac);
|
||||
|
||||
thread_wait_event((event_t *) thread_started, -1);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
@@ -253,13 +263,15 @@ network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg)
|
||||
void
|
||||
network_pcap_close(void)
|
||||
{
|
||||
pcap_t *pc;
|
||||
volatile pcap_t *pc;
|
||||
|
||||
if (pcap != NULL) {
|
||||
pclog("Closing WinPcap\n");
|
||||
|
||||
/* Tell the polling thread to shut down. */
|
||||
pc = pcap; pcap = NULL;
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
/* Terminate the polling thread. */
|
||||
if (poll_tid != NULL) {
|
||||
@@ -271,14 +283,32 @@ network_pcap_close(void)
|
||||
while (poll_tid != NULL)
|
||||
;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Tell the thread to terminate. */
|
||||
if (poll_tid != NULL) {
|
||||
network_busy(0);
|
||||
|
||||
pclog("Waiting for network thread to end...\n");
|
||||
/* Wait for the end event. */
|
||||
network_wait_for_end((void *) poll_tid);
|
||||
pclog("Network thread ended\n");
|
||||
|
||||
poll_tid = NULL;
|
||||
}
|
||||
|
||||
if (thread_started) {
|
||||
thread_destroy_event((event_t *) thread_started);
|
||||
thread_started = NULL;
|
||||
}
|
||||
|
||||
/* OK, now shut down WinPcap itself. */
|
||||
f_pcap_close(pc);
|
||||
f_pcap_close((pcap_t *) pc);
|
||||
pc = pcap = NULL;
|
||||
|
||||
/* Unload the DLL if possible. */
|
||||
if (pcap_handle != NULL) {
|
||||
dynld_close(pcap_handle);
|
||||
dynld_close((void *) pcap_handle);
|
||||
pcap_handle = NULL;
|
||||
}
|
||||
}
|
||||
@@ -291,12 +321,12 @@ void
|
||||
network_pcap_stop(void)
|
||||
{
|
||||
/* OK, now shut down WinPcap itself. */
|
||||
f_pcap_close(pcap);
|
||||
f_pcap_close((pcap_t *) pcap);
|
||||
pcap = NULL;
|
||||
|
||||
/* Unload the DLL if possible. */
|
||||
if (pcap_handle != NULL) {
|
||||
dynld_close(pcap_handle);
|
||||
dynld_close((void *) pcap_handle);
|
||||
pcap_handle = NULL;
|
||||
}
|
||||
}
|
||||
@@ -344,7 +374,7 @@ network_pcap_test(void)
|
||||
|
||||
/* Unload the DLL if possible. */
|
||||
if (pcap_handle != NULL) {
|
||||
dynld_close(pcap_handle);
|
||||
dynld_close((void *) pcap_handle);
|
||||
pcap_handle = NULL;
|
||||
}
|
||||
|
||||
@@ -365,7 +395,7 @@ network_pcap_test(void)
|
||||
|
||||
/* Unload the DLL if possible. */
|
||||
if (pcap_handle != NULL) {
|
||||
dynld_close(pcap_handle);
|
||||
dynld_close((void *) pcap_handle);
|
||||
pcap_handle = NULL;
|
||||
}
|
||||
|
||||
@@ -377,8 +407,8 @@ network_pcap_test(void)
|
||||
"( ((ether dst ff:ff:ff:ff:ff:ff) or (ether dst %02x:%02x:%02x:%02x:%02x:%02x)) and not (ether src %02x:%02x:%02x:%02x:%02x:%02x) )",
|
||||
0, 1, 2, 3, 4, 5,
|
||||
0, 1, 2, 3, 4, 5);
|
||||
if (f_pcap_compile(pcap, &fp, filter_exp, 0, 0xffffffff) != -1) {
|
||||
if (f_pcap_setfilter(pcap, &fp) == -1) {
|
||||
if (f_pcap_compile((pcap_t *) pcap, &fp, filter_exp, 0, 0xffffffff) != -1) {
|
||||
if (f_pcap_setfilter((pcap_t *) pcap, &fp) == -1) {
|
||||
pclog(" Error installing filter (%s) !\n", filter_exp);
|
||||
network_pcap_stop();
|
||||
return 0;
|
||||
@@ -402,7 +432,7 @@ network_pcap_in(uint8_t *bufp, int len)
|
||||
if (pcap != NULL) {
|
||||
network_busy(1);
|
||||
|
||||
f_pcap_sendpacket(pcap, bufp, len);
|
||||
f_pcap_sendpacket((pcap_t *) pcap, bufp, len);
|
||||
|
||||
network_busy(0);
|
||||
}
|
||||
|
@@ -29,10 +29,16 @@
|
||||
#include "network.h"
|
||||
|
||||
|
||||
static queueADT slirpq; /* SLiRP library handle */
|
||||
static thread_t *poll_tid;
|
||||
static NETRXCB poll_rx; /* network RX function to call */
|
||||
static void *poll_arg; /* network RX function arg */
|
||||
static volatile
|
||||
queueADT slirpq; /* SLiRP library handle */
|
||||
static volatile
|
||||
thread_t *poll_tid;
|
||||
static volatile
|
||||
NETRXCB poll_rx; /* network RX function to call */
|
||||
static volatile
|
||||
void *poll_arg; /* network RX function arg */
|
||||
static volatile
|
||||
event_t *thread_started;
|
||||
|
||||
|
||||
|
||||
@@ -75,6 +81,8 @@ poll_thread(void *arg)
|
||||
struct queuepacket *qp;
|
||||
event_t *evt;
|
||||
|
||||
thread_set_event((event_t *) thread_started);
|
||||
|
||||
pclog("SLiRP: polling thread started, arg %08lx\n", arg);
|
||||
|
||||
/* Create a waitable event. */
|
||||
@@ -92,6 +100,8 @@ poll_thread(void *arg)
|
||||
if (QueuePeek(slirpq) == 0) {
|
||||
/* If we did not get anything, wait a while. */
|
||||
thread_wait_event(evt, 10);
|
||||
|
||||
network_mutex_wait(0);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -103,7 +113,7 @@ poll_thread(void *arg)
|
||||
#endif
|
||||
|
||||
if (poll_rx != NULL)
|
||||
poll_rx(poll_arg, (uint8_t *)&qp->data, qp->len);
|
||||
poll_rx((void *) poll_arg, (uint8_t *)&qp->data, qp->len);
|
||||
|
||||
/* Done with this one. */
|
||||
free(qp);
|
||||
@@ -112,7 +122,6 @@ poll_thread(void *arg)
|
||||
}
|
||||
|
||||
thread_destroy_event(evt);
|
||||
evt = poll_tid = NULL;
|
||||
|
||||
pclog("SLiRP: polling stopped.\n");
|
||||
}
|
||||
@@ -141,6 +150,8 @@ network_slirp_setup(uint8_t *mac, NETRXCB func, void *arg)
|
||||
pclog("SLiRP: starting thread..\n");
|
||||
poll_tid = thread_create(poll_thread, mac);
|
||||
|
||||
thread_wait_event((event_t *) thread_started, -1);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
@@ -155,6 +166,8 @@ network_slirp_close(void)
|
||||
|
||||
/* Tell the polling thread to shut down. */
|
||||
sl = slirpq; slirpq = NULL;
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
/* Terminate the polling thread. */
|
||||
if (poll_tid != NULL) {
|
||||
@@ -166,6 +179,24 @@ network_slirp_close(void)
|
||||
while (poll_tid != NULL)
|
||||
;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Tell the thread to terminate. */
|
||||
if (poll_tid != NULL) {
|
||||
network_busy(0);
|
||||
|
||||
pclog("Waiting for network thread to end...\n");
|
||||
/* Wait for the end event. */
|
||||
network_wait_for_end((void *) poll_tid);
|
||||
pclog("Network thread ended\n");
|
||||
|
||||
poll_tid = NULL;
|
||||
}
|
||||
|
||||
if (thread_started) {
|
||||
thread_destroy_event((event_t *) thread_started);
|
||||
thread_started = NULL;
|
||||
}
|
||||
|
||||
/* OK, now shut down SLiRP itself. */
|
||||
QueueDestroy(sl);
|
||||
|
@@ -86,8 +86,25 @@ void
|
||||
network_wait_for_poll()
|
||||
{
|
||||
while (poll_data.busy)
|
||||
thread_wait_event((event_t *) poll_data.poll_complete, -1);
|
||||
thread_reset_event((event_t *) poll_data.poll_complete);
|
||||
thread_wait_event((event_t *) poll_data.wake_poll_thread, -1);
|
||||
thread_reset_event((event_t *) poll_data.wake_poll_thread);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
network_wait_for_end(void *handle)
|
||||
{
|
||||
thread_wait((event_t *) handle, -1);
|
||||
|
||||
if (poll_data.wake_poll_thread) {
|
||||
thread_destroy_event((event_t *) poll_data.wake_poll_thread);
|
||||
poll_data.wake_poll_thread = NULL;
|
||||
}
|
||||
|
||||
if (poll_data.poll_complete) {
|
||||
thread_destroy_event((event_t *) poll_data.poll_complete);
|
||||
poll_data.poll_complete = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -103,6 +120,13 @@ network_busy(uint8_t set)
|
||||
{
|
||||
poll_data.busy = !!set;
|
||||
if (!set)
|
||||
thread_set_event((event_t *) poll_data.wake_poll_thread);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
network_end(void)
|
||||
{
|
||||
thread_set_event((event_t *) poll_data.poll_complete);
|
||||
}
|
||||
|
||||
@@ -187,6 +211,8 @@ network_attach(void *dev, uint8_t *mac, NETRXCB rx)
|
||||
void
|
||||
network_close(void)
|
||||
{
|
||||
thread_close_mutex((mutex_t *) netMutex);
|
||||
|
||||
switch(network_type) {
|
||||
case NET_TYPE_PCAP:
|
||||
network_pcap_close();
|
||||
@@ -196,8 +222,6 @@ network_close(void)
|
||||
network_slirp_close();
|
||||
break;
|
||||
}
|
||||
|
||||
thread_close_mutex((event_t *) netMutex);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -58,10 +58,11 @@ extern char network_pcap[512];
|
||||
/* Function prototypes. */
|
||||
extern void network_mutex_wait(uint8_t wait);
|
||||
extern void network_wait_for_poll(void);
|
||||
extern void network_wait_for_end(void *handle);
|
||||
extern void network_mutex_init(void);
|
||||
extern void network_mutex_close(void);
|
||||
extern void network_thread_init(void);
|
||||
extern void network_busy(uint8_t set);
|
||||
extern void network_end(void);
|
||||
|
||||
extern void network_init(void);
|
||||
extern int network_attach(void *, uint8_t *, NETRXCB);
|
||||
|
@@ -102,6 +102,7 @@ typedef void mutex_t;
|
||||
extern thread_t *thread_create(void (*thread_rout)(void *param), void *param);
|
||||
extern void thread_kill(thread_t *handle);
|
||||
|
||||
extern int thread_wait(thread_t *arg, int timeout);
|
||||
extern void thread_sleep(int t);
|
||||
|
||||
extern event_t *thread_create_event(void);
|
||||
|
@@ -269,7 +269,9 @@ aha_fast_cmds(void *p, uint8_t cmd)
|
||||
x54x_busy(1);
|
||||
dev->BIOSMailboxReq++;
|
||||
|
||||
#if 0
|
||||
x54x_thread_start(dev);
|
||||
#endif
|
||||
x54x_busy(0);
|
||||
return 1;
|
||||
}
|
||||
|
@@ -59,7 +59,12 @@ static volatile
|
||||
event_t *evt;
|
||||
|
||||
static volatile
|
||||
event_t *poll_complete;
|
||||
event_t *wake_poll_thread;
|
||||
static volatile
|
||||
event_t *thread_started;
|
||||
|
||||
static volatile
|
||||
x54x_t *x54x_dev;
|
||||
|
||||
|
||||
#ifdef ENABLE_X54X_LOG
|
||||
@@ -1292,30 +1297,34 @@ void
|
||||
x54x_wait_for_poll(void)
|
||||
{
|
||||
if (x54x_is_busy()) {
|
||||
thread_wait_event((event_t *) poll_complete, -1);
|
||||
thread_wait_event((event_t *) wake_poll_thread, -1);
|
||||
}
|
||||
thread_reset_event((event_t *) poll_complete);
|
||||
thread_reset_event((event_t *) wake_poll_thread);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
x54x_cmd_thread(void *priv)
|
||||
{
|
||||
x54x_t *dev = (x54x_t *)priv;
|
||||
x54x_t *dev = (x54x_t *) x54x_dev;
|
||||
|
||||
thread_set_event((event_t *) thread_started);
|
||||
|
||||
x54x_log("Polling thread started\n");
|
||||
|
||||
while (1)
|
||||
while (x54x_dev)
|
||||
{
|
||||
scsi_mutex_wait(1);
|
||||
|
||||
if ((dev->Status & STAT_INIT) || (!dev->MailboxInit && !dev->BIOSMailboxInit) || (!dev->MailboxReq && !dev->BIOSMailboxReq)) {
|
||||
/* If we did not get anything, wait a while. */
|
||||
thread_wait_event((event_t *) evt, 10);
|
||||
|
||||
scsi_mutex_wait(0);
|
||||
continue;
|
||||
}
|
||||
|
||||
scsi_mutex_wait(1);
|
||||
|
||||
if (!(dev->Status & STAT_INIT) && dev->MailboxInit && dev->MailboxReq)
|
||||
if (!(x54x_dev->Status & STAT_INIT) && x54x_dev->MailboxInit && dev->MailboxReq)
|
||||
{
|
||||
x54x_wait_for_poll();
|
||||
|
||||
@@ -1329,23 +1338,6 @@ x54x_cmd_thread(void *priv)
|
||||
scsi_mutex_wait(0);
|
||||
}
|
||||
|
||||
if (poll_tid) {
|
||||
thread_kill((thread_t *) poll_tid);
|
||||
poll_tid = NULL;
|
||||
}
|
||||
|
||||
if (poll_complete) {
|
||||
thread_destroy_event((event_t *) poll_complete);
|
||||
poll_complete = NULL;
|
||||
}
|
||||
|
||||
if (evt) {
|
||||
thread_destroy_event((event_t *) evt);
|
||||
evt = NULL;
|
||||
}
|
||||
|
||||
scsi_mutex(0);
|
||||
|
||||
x54x_log("%s: Callback: polling stopped.\n", dev->name);
|
||||
}
|
||||
|
||||
@@ -1355,7 +1347,7 @@ x54x_busy(uint8_t set)
|
||||
{
|
||||
busy = !!set;
|
||||
if (!set)
|
||||
thread_set_event((event_t *) poll_complete);
|
||||
thread_set_event((event_t *) wake_poll_thread);
|
||||
}
|
||||
|
||||
|
||||
@@ -1545,8 +1537,6 @@ x54x_out(uint16_t port, uint8_t val, void *priv)
|
||||
if ((val == CMD_START_SCSI) && (dev->Command == 0xff)) {
|
||||
x54x_busy(1);
|
||||
dev->MailboxReq++;
|
||||
|
||||
x54x_thread_start(dev);
|
||||
x54x_log("Start SCSI command: ");
|
||||
x54x_busy(0);
|
||||
return;
|
||||
@@ -1970,13 +1960,19 @@ x54x_init(device_t *info)
|
||||
|
||||
timer_add(x54x_reset_poll, &dev->ResetCB, &dev->ResetCB, dev);
|
||||
|
||||
x54x_dev = dev;
|
||||
|
||||
scsi_mutex(1);
|
||||
|
||||
poll_complete = thread_create_event();
|
||||
wake_poll_thread = thread_create_event();
|
||||
thread_started = thread_create_event();
|
||||
|
||||
/* Create a waitable event. */
|
||||
evt = thread_create_event();
|
||||
|
||||
x54x_thread_start(dev);
|
||||
thread_wait_event((event_t *) thread_started, -1);
|
||||
|
||||
return(dev);
|
||||
}
|
||||
|
||||
@@ -1988,6 +1984,20 @@ x54x_close(void *priv)
|
||||
|
||||
if (dev)
|
||||
{
|
||||
x54x_dev = NULL;
|
||||
|
||||
/* Tell the thread to terminate. */
|
||||
if (poll_tid != NULL) {
|
||||
x54x_busy(0);
|
||||
|
||||
x54x_log("Waiting for SCSI thread to end...\n");
|
||||
/* Wait for the end event. */
|
||||
thread_wait((event_t *) poll_tid, -1);
|
||||
x54x_log("SCSI thread ended\n");
|
||||
|
||||
poll_tid = NULL;
|
||||
}
|
||||
|
||||
dev->MailboxInit = dev->BIOSMailboxInit = 0;
|
||||
dev->MailboxCount = dev->BIOSMailboxCount = 0;
|
||||
dev->MailboxReq = dev->BIOSMailboxReq = 0;
|
||||
@@ -1995,21 +2005,21 @@ x54x_close(void *priv)
|
||||
if (dev->ven_data)
|
||||
free(dev->ven_data);
|
||||
|
||||
if (poll_tid) {
|
||||
thread_kill((thread_t *) poll_tid);
|
||||
poll_tid = NULL;
|
||||
}
|
||||
|
||||
if (poll_complete) {
|
||||
thread_destroy_event((event_t *) poll_complete);
|
||||
poll_complete = NULL;
|
||||
}
|
||||
|
||||
if (evt) {
|
||||
thread_destroy_event((event_t *) evt);
|
||||
evt = NULL;
|
||||
}
|
||||
|
||||
if (thread_started) {
|
||||
thread_destroy_event((event_t *) thread_started);
|
||||
thread_started = NULL;
|
||||
}
|
||||
|
||||
if (wake_poll_thread) {
|
||||
thread_destroy_event((event_t *) wake_poll_thread);
|
||||
wake_poll_thread = NULL;
|
||||
}
|
||||
|
||||
scsi_mutex(0);
|
||||
|
||||
if (dev->nvr != NULL)
|
||||
|
@@ -427,6 +427,22 @@ void sound_reset(void)
|
||||
}
|
||||
}
|
||||
|
||||
void sound_cd_thread_end(void)
|
||||
{
|
||||
if (sound_cd_thread_h) {
|
||||
pclog("Waiting for CD Audio thread to terminate...\n");
|
||||
thread_wait(sound_cd_thread_h, -1);
|
||||
pclog("CD Audio thread terminated...\n");
|
||||
|
||||
if (sound_cd_event) {
|
||||
thread_destroy_event(sound_cd_event);
|
||||
sound_cd_event = NULL;
|
||||
}
|
||||
|
||||
sound_cd_thread_h = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void sound_cd_thread_reset(void)
|
||||
{
|
||||
int i = 0;
|
||||
@@ -447,9 +463,7 @@ void sound_cd_thread_reset(void)
|
||||
}
|
||||
else if (!available_cdrom_drives && cd_thread_enable)
|
||||
{
|
||||
thread_destroy_event(sound_cd_event);
|
||||
thread_kill(sound_cd_thread_h);
|
||||
sound_cd_thread_h = NULL;
|
||||
sound_cd_thread_end();
|
||||
}
|
||||
|
||||
cd_thread_enable = available_cdrom_drives ? 1 : 0;
|
||||
|
@@ -46,6 +46,7 @@ void sound_realloc_buffers(void);
|
||||
void sound_init();
|
||||
void sound_reset();
|
||||
|
||||
void sound_cd_thread_end();
|
||||
void sound_cd_thread_reset();
|
||||
|
||||
void closeal(void);
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Platform support defintions for Win32.
|
||||
*
|
||||
* Version: @(#)win.h 1.0.6 2017/10/18
|
||||
* Version: @(#)win.h 1.0.7 2017/10/19
|
||||
*
|
||||
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
@@ -78,7 +78,7 @@ extern void set_language(int id);
|
||||
extern int get_vidpause(void);
|
||||
|
||||
#ifdef EMU_DEVICE_H
|
||||
extern void deviceconfig_open(HWND hwnd, device_t *device);
|
||||
extern uint8_t deviceconfig_open(HWND hwnd, device_t *device);
|
||||
#endif
|
||||
extern void joystickconfig_open(HWND hwnd, int joy_nr, int type);
|
||||
|
||||
|
@@ -32,6 +32,8 @@
|
||||
|
||||
static device_t *config_device;
|
||||
|
||||
static uint8_t deviceconfig_changed = 0;
|
||||
|
||||
|
||||
static BOOL CALLBACK
|
||||
deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
@@ -39,7 +41,6 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
HWND h;
|
||||
|
||||
int val_int;
|
||||
int ret;
|
||||
int id;
|
||||
int c;
|
||||
int num;
|
||||
@@ -278,21 +279,12 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
if (!changed)
|
||||
{
|
||||
deviceconfig_changed = 0;
|
||||
EndDialog(hdlg, 0);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ret = ui_msgbox(MBX_QUESTION, (wchar_t *)IDS_2051);
|
||||
switch(ret)
|
||||
{
|
||||
case 1:
|
||||
EndDialog(hdlg, 0);
|
||||
return TRUE;
|
||||
case -1:
|
||||
return FALSE;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
deviceconfig_changed = 1;
|
||||
|
||||
id = IDC_CONFIG_BASE;
|
||||
config = config_device->config;
|
||||
@@ -367,15 +359,12 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
config++;
|
||||
}
|
||||
|
||||
config_save();
|
||||
|
||||
pc_reset_hard();
|
||||
|
||||
EndDialog(hdlg, 0);
|
||||
return TRUE;
|
||||
}
|
||||
else if (cid == IDCANCEL)
|
||||
{
|
||||
deviceconfig_changed = 0;
|
||||
EndDialog(hdlg, 0);
|
||||
return TRUE;
|
||||
}
|
||||
@@ -462,7 +451,7 @@ deviceconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void deviceconfig_open(HWND hwnd, device_t *device)
|
||||
uint8_t deviceconfig_open(HWND hwnd, device_t *device)
|
||||
{
|
||||
device_config_t *config = device->config;
|
||||
uint16_t *data_block = malloc(16384);
|
||||
@@ -472,6 +461,8 @@ void deviceconfig_open(HWND hwnd, device_t *device)
|
||||
int y = 10;
|
||||
int id = IDC_CONFIG_BASE;
|
||||
|
||||
deviceconfig_changed = 0;
|
||||
|
||||
memset(data_block, 0, 4096);
|
||||
|
||||
dlg->style = DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU;
|
||||
@@ -731,4 +722,6 @@ void deviceconfig_open(HWND hwnd, device_t *device)
|
||||
DialogBoxIndirect(hinstance, dlg, hwnd, deviceconfig_dlgproc);
|
||||
|
||||
free(data_block);
|
||||
|
||||
return deviceconfig_changed;
|
||||
}
|
||||
|
@@ -87,6 +87,8 @@ static char temp_hdc_name[16];
|
||||
static char *hdc_names[16];
|
||||
static int temp_bugger;
|
||||
|
||||
static uint8_t temp_deviceconfig;
|
||||
|
||||
/* Hard disks category */
|
||||
static hard_disk_t temp_hdd[HDD_NUM];
|
||||
|
||||
@@ -196,6 +198,8 @@ static void win_settings_init(void)
|
||||
temp_fdd_check_bpb[i] = fdd_get_check_bpb(i);
|
||||
}
|
||||
memcpy(temp_cdrom_drives, cdrom_drives, CDROM_NUM * sizeof(cdrom_drive_t));
|
||||
|
||||
temp_deviceconfig = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -268,6 +272,8 @@ static int win_settings_changed(void)
|
||||
}
|
||||
i = i || memcmp(cdrom_drives, temp_cdrom_drives, CDROM_NUM * sizeof(cdrom_drive_t));
|
||||
|
||||
i = i || !!temp_deviceconfig;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -347,6 +353,11 @@ static void win_settings_save(void)
|
||||
|
||||
/* Peripherals category */
|
||||
scsi_card_current = temp_scsi_card;
|
||||
if (hdc_name) {
|
||||
free(hdc_name);
|
||||
hdc_name = NULL;
|
||||
}
|
||||
hdc_name = (char *) malloc(sizeof(temp_hdc_name));
|
||||
strncpy(hdc_name, temp_hdc_name, sizeof(temp_hdc_name) - 1);
|
||||
hdc_init(hdc_name);
|
||||
ide_enable[2] = temp_ide_ter;
|
||||
@@ -660,7 +671,7 @@ static BOOL CALLBACK win_settings_machine_proc(HWND hdlg, UINT message, WPARAM w
|
||||
h = GetDlgItem(hdlg, IDC_COMBO_MACHINE);
|
||||
temp_machine = listtomachine[SendMessage(h, CB_GETCURSEL, 0, 0)];
|
||||
|
||||
deviceconfig_open(hdlg, (void *)machine_getdevice(temp_machine));
|
||||
temp_deviceconfig |= deviceconfig_open(hdlg, (void *)machine_getdevice(temp_machine));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -842,7 +853,7 @@ static BOOL CALLBACK win_settings_video_proc(HWND hdlg, UINT message, WPARAM wPa
|
||||
break;
|
||||
|
||||
case IDC_BUTTON_VOODOO:
|
||||
deviceconfig_open(hdlg, (void *)&voodoo_device);
|
||||
temp_deviceconfig |= deviceconfig_open(hdlg, (void *)&voodoo_device);
|
||||
break;
|
||||
|
||||
case IDC_CONFIGURE_VID:
|
||||
@@ -852,7 +863,7 @@ static BOOL CALLBACK win_settings_video_proc(HWND hdlg, UINT message, WPARAM wPa
|
||||
h = GetDlgItem(hdlg, IDC_COMBO_VIDEO);
|
||||
SendMessage(h, CB_GETLBTEXT, SendMessage(h, CB_GETCURSEL, 0, 0), (LPARAM) lptsTemp);
|
||||
wcstombs(stransi, lptsTemp, 512);
|
||||
deviceconfig_open(hdlg, (void *)video_card_getdevice(video_card_getid(stransi)));
|
||||
temp_deviceconfig |= deviceconfig_open(hdlg, (void *)video_card_getdevice(video_card_getid(stransi)));
|
||||
|
||||
free(stransi);
|
||||
free(lptsTemp);
|
||||
@@ -1218,7 +1229,7 @@ static BOOL CALLBACK win_settings_sound_proc(HWND hdlg, UINT message, WPARAM wPa
|
||||
h = GetDlgItem(hdlg, IDC_COMBO_SOUND);
|
||||
temp_sound_card = settings_list_to_sound[SendMessage(h, CB_GETCURSEL, 0, 0)];
|
||||
|
||||
deviceconfig_open(hdlg, (void *)sound_card_getdevice(temp_sound_card));
|
||||
temp_deviceconfig |= deviceconfig_open(hdlg, (void *)sound_card_getdevice(temp_sound_card));
|
||||
break;
|
||||
|
||||
case IDC_COMBO_MIDI:
|
||||
@@ -1247,7 +1258,7 @@ static BOOL CALLBACK win_settings_sound_proc(HWND hdlg, UINT message, WPARAM wPa
|
||||
h = GetDlgItem(hdlg, IDC_COMBO_MIDI);
|
||||
temp_midi_device = settings_list_to_midi[SendMessage(h, CB_GETCURSEL, 0, 0)];
|
||||
|
||||
deviceconfig_open(hdlg, (void *)midi_device_getdevice(temp_midi_device));
|
||||
temp_deviceconfig |= deviceconfig_open(hdlg, (void *)midi_device_getdevice(temp_midi_device));
|
||||
break;
|
||||
|
||||
case IDC_CHECK_MPU401:
|
||||
@@ -1259,7 +1270,7 @@ static BOOL CALLBACK win_settings_sound_proc(HWND hdlg, UINT message, WPARAM wPa
|
||||
break;
|
||||
|
||||
case IDC_CONFIGURE_MPU401:
|
||||
deviceconfig_open(hdlg, (void *)&mpu401_device);
|
||||
temp_deviceconfig |= deviceconfig_open(hdlg, (void *)&mpu401_device);
|
||||
break;
|
||||
}
|
||||
return FALSE;
|
||||
@@ -1587,7 +1598,7 @@ static BOOL CALLBACK win_settings_peripherals_proc(HWND hdlg, UINT message, WPAR
|
||||
h = GetDlgItem(hdlg, IDC_COMBO_SCSI);
|
||||
temp_scsi_card = settings_list_to_scsi[SendMessage(h, CB_GETCURSEL, 0, 0)];
|
||||
|
||||
deviceconfig_open(hdlg, (void *)scsi_card_getdevice(temp_scsi_card));
|
||||
temp_deviceconfig |= deviceconfig_open(hdlg, (void *)scsi_card_getdevice(temp_scsi_card));
|
||||
break;
|
||||
|
||||
case IDC_COMBO_SCSI:
|
||||
@@ -1827,7 +1838,7 @@ static BOOL CALLBACK win_settings_network_proc(HWND hdlg, UINT message, WPARAM w
|
||||
h = GetDlgItem(hdlg, IDC_COMBO_NET);
|
||||
temp_net_card = settings_list_to_network[SendMessage(h, CB_GETCURSEL, 0, 0)];
|
||||
|
||||
deviceconfig_open(hdlg, (void *)network_card_getdevice(temp_net_card));
|
||||
temp_deviceconfig |= deviceconfig_open(hdlg, (void *)network_card_getdevice(temp_net_card));
|
||||
break;
|
||||
}
|
||||
return FALSE;
|
||||
|
@@ -59,6 +59,20 @@ thread_sleep(int t)
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
thread_wait(thread_t *arg, int timeout)
|
||||
{
|
||||
if (arg == NULL) return(0);
|
||||
|
||||
if (timeout == -1)
|
||||
timeout = INFINITE;
|
||||
|
||||
if (WaitForSingleObject(arg, timeout)) return(1);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
event_t *
|
||||
thread_create_event(void)
|
||||
{
|
||||
@@ -99,6 +113,8 @@ thread_wait_event(event_t *arg, int timeout)
|
||||
|
||||
if (arg == NULL) return(0);
|
||||
|
||||
if (ev->handle == NULL) return(0);
|
||||
|
||||
if (timeout == -1)
|
||||
timeout = INFINITE;
|
||||
|
||||
|
Reference in New Issue
Block a user