mirror of
https://github.com/n64dev/cen64.git
synced 2024-06-21 13:32:40 -04:00
More cleanup/streamlining of UI pullup.
This commit is contained in:
parent
d348c23e2f
commit
1619e0fd98
29
cen64.c
29
cen64.c
|
@ -14,14 +14,17 @@
|
|||
#include "device/device.h"
|
||||
#include "device/options.h"
|
||||
#include "os/common/alloc.h"
|
||||
#include "os/main.h"
|
||||
#include "os/rom_file.h"
|
||||
#include "thread.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
cen64_cold static int load_roms(const char *ddipl_path, const char *ddrom_path,
|
||||
const char *pifrom_path, const char *cart_path, struct rom_file *ddipl,
|
||||
struct rom_file *ddrom, struct rom_file *pifrom, struct rom_file *cart);
|
||||
|
||||
cen64_cold static int run_device(struct cen64_device *device);
|
||||
cen64_cold static CEN64_THREAD_RETURN_TYPE run_device_thread(void *opaque);
|
||||
|
||||
// Called when another simulation instance is desired.
|
||||
int cen64_main(int argc, const char *argv[]) {
|
||||
struct cen64_options options = default_cen64_options;
|
||||
|
@ -74,7 +77,7 @@ int cen64_main(int argc, const char *argv[]) {
|
|||
}
|
||||
|
||||
else {
|
||||
status = os_main(device, &options);
|
||||
status = run_device(device);
|
||||
device_destroy(device);
|
||||
}
|
||||
|
||||
|
@ -145,3 +148,25 @@ int load_roms(const char *ddipl_path, const char *ddrom_path,
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Spins the device until an exit request is received.
|
||||
int run_device(struct cen64_device *device) {
|
||||
cen64_thread thread;
|
||||
|
||||
if (cen64_thread_create(&thread, run_device_thread, device)) {
|
||||
printf("Failed to create the main emulation thread.\n");
|
||||
device_destroy(device);
|
||||
return 1;
|
||||
}
|
||||
|
||||
cen64_gl_window_thread(device);
|
||||
cen64_thread_join(&thread);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CEN64_THREAD_RETURN_TYPE run_device_thread(void *opaque) {
|
||||
struct cen64_device *device = (struct cen64_device *) opaque;
|
||||
|
||||
device_run(device);
|
||||
return CEN64_THREAD_RETURN_VAL;
|
||||
}
|
||||
|
||||
|
|
10
os/main.h
10
os/main.h
|
@ -14,15 +14,5 @@
|
|||
#include "os/gl_window.h"
|
||||
#include "rom_file.h"
|
||||
|
||||
cen64_cold int os_main(struct cen64_device *device,
|
||||
struct cen64_options *options);
|
||||
|
||||
cen64_cold bool os_exit_requested(struct gl_window *gl_window);
|
||||
cen64_cold void os_render_frame(cen64_gl_window window, const void *data,
|
||||
unsigned xres, unsigned yres, unsigned xskip, unsigned type);
|
||||
|
||||
cen64_cold void os_acquire_input(struct gl_window *gl_window);
|
||||
cen64_cold void os_release_input(struct gl_window *gl_window);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -21,100 +21,8 @@
|
|||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
cen64_cold static void *run_device_thread(void *opaque);
|
||||
|
||||
// Only used when passed -nointerface.
|
||||
bool device_exit_requested;
|
||||
|
||||
cen64_cold static void device_sigint(int signum) {
|
||||
device_exit_requested = true;
|
||||
}
|
||||
|
||||
// Unix application entry point.
|
||||
int main(int argc, const char *argv[]) {
|
||||
return cen64_main(argc, argv);
|
||||
}
|
||||
|
||||
// Allocates memory for a new device, runs it.
|
||||
int os_main(struct cen64_device *device, struct cen64_options *options) {
|
||||
struct gl_window_hints hints;
|
||||
cen64_thread thread;
|
||||
|
||||
#if 0
|
||||
// Spawn the user interface (or signal handler).
|
||||
if (!options->no_interface) {
|
||||
device->vi.gl_window.window = &window;
|
||||
get_default_gl_window_hints(&hints);
|
||||
|
||||
if (create_gl_window(&device->bus, &device->vi.gl_window, &hints)) {
|
||||
printf("Failed to create a window.\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
if (signal(SIGINT, device_sigint) == SIG_ERR)
|
||||
printf("Failed to register SIGINT handler.\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
// Pull up the debug API if it was requested.
|
||||
device->debug_sfd = -1;
|
||||
|
||||
if (options->enable_debugger) {
|
||||
if ((device->debug_sfd = netapi_open_connection()) < 0) {
|
||||
printf("Failed to bind/listen for a connection.\n");
|
||||
|
||||
//destroy_gl_window(&device->vi.gl_window);
|
||||
device_destroy(device);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (cen64_thread_create(&thread, run_device_thread, device)) {
|
||||
printf("Failed to create the main emulation thread.\n");
|
||||
device_destroy(device);
|
||||
return 1;
|
||||
}
|
||||
|
||||
cen64_gl_window_thread(device);
|
||||
cen64_thread_join(&thread);
|
||||
// device_run(device);
|
||||
#if 0
|
||||
// Start the device thread, hand over control to the UI thread on success.
|
||||
if ((pthread_create(&device_thread, NULL, run_device_thread, device)) == 0) {
|
||||
//gl_window_thread(&device->vi.gl_window, &device->bus);
|
||||
pthread_join(device_thread, NULL);
|
||||
}
|
||||
|
||||
else
|
||||
printf("Unable to spawn a thread for the device.\n");
|
||||
#endif
|
||||
|
||||
if (device->debug_sfd >= 0)
|
||||
netapi_close_connection(device->debug_sfd);
|
||||
|
||||
#if 0
|
||||
if (!options->no_interface)
|
||||
destroy_gl_window(&device->vi.gl_window);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Pushes a frame to the rendering thread.
|
||||
void os_render_frame(cen64_gl_window window, const void *data,
|
||||
unsigned xres, unsigned yres, unsigned xskip, unsigned type) {
|
||||
// struct glx_window *glx_window = (struct glx_window *) (gl_window->window);
|
||||
|
||||
// glx_window_render_frame(glx_window, data, xres, yres, xskip, type);
|
||||
}
|
||||
|
||||
// Runs the device, always returns NULL.
|
||||
void *run_device_thread(void *opaque) {
|
||||
struct cen64_device *device = (struct cen64_device *) opaque;
|
||||
|
||||
device_run(device);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue