45 |
|
|
46 |
|
// Global variables |
47 |
|
static GtkWidget *win; // Preferences window |
48 |
< |
static bool start_clicked = true; // Return value of PrefsEditor() function |
48 |
> |
static bool start_clicked = false; // Return value of PrefsEditor() function |
49 |
|
|
50 |
|
|
51 |
|
// Prototypes |
712 |
|
static GtkWidget *w_jit_lazy_flush; |
713 |
|
static GtkWidget *w_jit_follow_const_jumps; |
714 |
|
|
715 |
+ |
// Are we running a JIT capable CPU? |
716 |
+ |
static bool is_jit_capable(void) |
717 |
+ |
{ |
718 |
+ |
#if USE_JIT && (defined __i386__ || defined __x86_64__) |
719 |
+ |
return true; |
720 |
+ |
#elif defined __APPLE__ && defined __MACH__ |
721 |
+ |
// XXX run-time detect so that we can use a PPC GUI prefs editor |
722 |
+ |
static char cpu[10]; |
723 |
+ |
if (cpu[0] == 0) { |
724 |
+ |
FILE *fp = popen("uname -p", "r"); |
725 |
+ |
if (fp == NULL) |
726 |
+ |
return false; |
727 |
+ |
fgets(cpu, sizeof(cpu) - 1, fp); |
728 |
+ |
fclose(fp); |
729 |
+ |
} |
730 |
+ |
if (cpu[0] == 'i' && cpu[2] == '8' && cpu[3] == '6') // XXX assuming i?86 |
731 |
+ |
return true; |
732 |
+ |
#endif |
733 |
+ |
return false; |
734 |
+ |
} |
735 |
+ |
|
736 |
|
// Set sensitivity of widgets |
737 |
|
static void set_jit_sensitive(void) |
738 |
|
{ |
771 |
|
// Read settings from widgets and set preferences |
772 |
|
static void read_jit_settings(void) |
773 |
|
{ |
774 |
< |
#if USE_JIT |
754 |
< |
bool jit_enabled = PrefsFindBool("jit"); |
774 |
> |
bool jit_enabled = is_jit_capable() && PrefsFindBool("jit"); |
775 |
|
if (jit_enabled) { |
776 |
|
const char *str = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(w_jit_cache_size)->entry)); |
777 |
|
PrefsReplaceInt32("jitcachesize", atoi(str)); |
778 |
|
} |
759 |
– |
#endif |
779 |
|
} |
780 |
|
|
781 |
|
// Create "JIT Compiler" pane |
782 |
|
static void create_jit_pane(GtkWidget *top) |
783 |
|
{ |
784 |
< |
#if USE_JIT |
784 |
> |
if (!is_jit_capable()) |
785 |
> |
return; |
786 |
> |
|
787 |
|
GtkWidget *box, *table, *label, *menu; |
788 |
|
char str[32]; |
789 |
|
|
809 |
|
w_jit_follow_const_jumps = make_checkbox(box, STR_JIT_FOLLOW_CONST_JUMPS, "jitinline", GTK_SIGNAL_FUNC(tb_jit_follow_const_jumps)); |
810 |
|
|
811 |
|
set_jit_sensitive(); |
791 |
– |
#endif |
812 |
|
} |
813 |
|
|
814 |
|
/* |
1560 |
|
void MountVolume(void *fh) { } |
1561 |
|
void FileDiskLayout(loff_t size, uint8 *data, loff_t &start_byte, loff_t &real_size) { } |
1562 |
|
|
1563 |
+ |
#if defined __APPLE__ && defined __MACH__ |
1564 |
+ |
void DarwinAddCDROMPrefs(void) { } |
1565 |
+ |
void DarwinAddFloppyPrefs(void) { } |
1566 |
+ |
void DarwinAddSerialPrefs(void) { } |
1567 |
+ |
bool DarwinCDReadTOC(char *, uint8 *) { } |
1568 |
+ |
#endif |
1569 |
+ |
|
1570 |
|
|
1571 |
|
/* |
1572 |
|
* Display alert |
1694 |
|
if (start) { |
1695 |
|
char gui_connection_path[64]; |
1696 |
|
sprintf(gui_connection_path, "/org/BasiliskII/GUI/%d", getpid()); |
1697 |
< |
|
1697 |
> |
|
1698 |
> |
// Search and run the BasiliskII executable |
1699 |
> |
// XXX it can be in a bundle on MacOS X |
1700 |
> |
char b2_path[PATH_MAX]; |
1701 |
> |
strcpy(b2_path, argv[0]); |
1702 |
> |
char *p = strrchr(b2_path, '/'); |
1703 |
> |
p = p ? p + 1 : b2_path; |
1704 |
> |
*p = '\0'; |
1705 |
> |
strcat(b2_path, "BasiliskII"); |
1706 |
> |
|
1707 |
|
int pid = fork(); |
1708 |
< |
if (pid == 0) { // Child |
1673 |
< |
char b2_path[PATH_MAX]; |
1674 |
< |
strcpy(b2_path, argv[0]); |
1675 |
< |
char *p = strrchr(b2_path, '/'); |
1676 |
< |
p = p ? p + 1 : b2_path; |
1677 |
< |
*p = '\0'; |
1678 |
< |
strcat(b2_path, "BasiliskII"); |
1708 |
> |
if (pid == 0) { |
1709 |
|
execl(b2_path, b2_path, "--gui-connection", gui_connection_path, (char *)NULL); |
1710 |
+ |
return -errno; |
1711 |
+ |
} |
1712 |
|
|
1713 |
< |
char str[256]; |
1714 |
< |
sprintf(str, GetString(STR_NO_B2_EXE_FOUND), b2_path, strerror(errno)); |
1715 |
< |
ErrorAlert(str); |
1713 |
> |
// Establish a connection to Basilisk II |
1714 |
> |
rpc_connection_t *connection; |
1715 |
> |
if ((connection = rpc_init_server(gui_connection_path)) == NULL) { |
1716 |
> |
printf("ERROR: failed to initialize GUI-side RPC server connection\n"); |
1717 |
> |
return 1; |
1718 |
> |
} |
1719 |
> |
static const rpc_method_descriptor_t vtable[] = { |
1720 |
> |
{ RPC_METHOD_ERROR_ALERT, handle_ErrorAlert }, |
1721 |
> |
{ RPC_METHOD_WARNING_ALERT, handle_WarningAlert }, |
1722 |
> |
{ RPC_METHOD_EXIT, handle_Exit } |
1723 |
> |
}; |
1724 |
> |
if (rpc_method_add_callbacks(connection, vtable, sizeof(vtable) / sizeof(vtable[0])) < 0) { |
1725 |
> |
printf("ERROR: failed to setup GUI method callbacks\n"); |
1726 |
> |
return 1; |
1727 |
> |
} |
1728 |
> |
int socket; |
1729 |
> |
if ((socket = rpc_listen_socket(connection)) < 0) { |
1730 |
> |
printf("ERROR: failed to initialize RPC server thread\n"); |
1731 |
|
return 1; |
1732 |
|
} |
1686 |
– |
else { // Parent |
1687 |
– |
rpc_connection_t *connection; |
1688 |
– |
if ((connection = rpc_init_server(gui_connection_path)) == NULL) { |
1689 |
– |
printf("ERROR: failed to initialize GUI-side RPC server connection\n"); |
1690 |
– |
return 1; |
1691 |
– |
} |
1733 |
|
|
1734 |
< |
static const rpc_method_descriptor_t vtable[] = { |
1735 |
< |
{ RPC_METHOD_ERROR_ALERT, handle_ErrorAlert }, |
1736 |
< |
{ RPC_METHOD_WARNING_ALERT, handle_WarningAlert }, |
1737 |
< |
{ RPC_METHOD_EXIT, handle_Exit } |
1738 |
< |
}; |
1739 |
< |
if (rpc_method_add_callbacks(connection, vtable, sizeof(vtable) / sizeof(vtable[0])) < 0) { |
1740 |
< |
printf("ERROR: failed to setup GUI method callbacks\n"); |
1741 |
< |
return 1; |
1734 |
> |
int child_status = 1; |
1735 |
> |
GMainLoop *loop = g_main_new(TRUE); |
1736 |
> |
while (g_main_is_running(loop)) { |
1737 |
> |
|
1738 |
> |
// Process a few events pending |
1739 |
> |
const int N_EVENTS_DISPATCH = 10; |
1740 |
> |
for (int i = 0; i < N_EVENTS_DISPATCH; i++) { |
1741 |
> |
if (!g_main_iteration(FALSE)) |
1742 |
> |
break; |
1743 |
|
} |
1744 |
|
|
1745 |
< |
if (rpc_listen(connection) < 0) { |
1746 |
< |
printf("ERROR: failed to initialize RPC server thread\n"); |
1747 |
< |
return 1; |
1745 |
> |
// Check if the child has terminated |
1746 |
> |
int status = 1; |
1747 |
> |
int ret = waitpid(pid, &status, WNOHANG); |
1748 |
> |
if (ret == pid || (ret < 0 && errno == ECHILD)) { |
1749 |
> |
if (WIFEXITED(status)) { |
1750 |
> |
child_status = WEXITSTATUS(status); |
1751 |
> |
if (child_status & 0x80) |
1752 |
> |
child_status |= -1 ^0xff; |
1753 |
> |
} |
1754 |
> |
break; |
1755 |
|
} |
1756 |
|
|
1757 |
< |
int status, ret = -1; |
1758 |
< |
while (waitpid(pid, &status, 0) != pid) |
1759 |
< |
; |
1760 |
< |
if (WIFEXITED(status)) |
1761 |
< |
ret = WEXITSTATUS(status); |
1757 |
> |
// Check for RPC events |
1758 |
> |
// XXX implement an rpc_try_dispatch(connection, timeout) |
1759 |
> |
fd_set rfds; |
1760 |
> |
FD_ZERO(&rfds); |
1761 |
> |
FD_SET(socket, &rfds); |
1762 |
> |
struct timeval tv; |
1763 |
> |
tv.tv_sec = 1; |
1764 |
> |
tv.tv_usec = 0; |
1765 |
> |
ret = select(socket + 1, &rfds, NULL, NULL, &tv); |
1766 |
> |
if (ret < 0) |
1767 |
> |
break; |
1768 |
> |
if (ret == 0) |
1769 |
> |
continue; |
1770 |
> |
rpc_dispatch(connection); |
1771 |
> |
} |
1772 |
> |
|
1773 |
> |
rpc_exit(connection); |
1774 |
|
|
1775 |
< |
rpc_exit(connection); |
1776 |
< |
return ret; |
1775 |
> |
// Report failure to execute the BasiliskII binary |
1776 |
> |
if (child_status < 0) { |
1777 |
> |
char str[256]; |
1778 |
> |
sprintf(str, GetString(STR_NO_B2_EXE_FOUND), b2_path, strerror(-child_status)); |
1779 |
> |
ErrorAlert(str); |
1780 |
> |
return 1; |
1781 |
|
} |
1782 |
+ |
|
1783 |
+ |
return child_status; |
1784 |
|
} |
1785 |
|
|
1786 |
|
return 0; |