1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
diff --git a/platforms/audio-shared/Sound_Queue.cpp b/platforms/audio-shared/Sound_Queue.cpp
index 4dd4fb1..9a4402e 100644
--- a/platforms/audio-shared/Sound_Queue.cpp
+++ b/platforms/audio-shared/Sound_Queue.cpp
@@ -144,9 +144,9 @@ void Sound_Queue::write( const sample_t* in, int count, bool sync )
{
write_pos = 0;
write_buf = (write_buf + 1) % buf_count;
-
- if (sync_output)
- SDL_SemWait( free_sem );
+ // We don't like deadlocks in SDL_SemWait, remove them
+ //if (sync_output)
+ // SDL_SemWait( free_sem );
}
}
}
diff --git a/platforms/desktop-shared/application.cpp b/platforms/desktop-shared/application.cpp
index d39cf93..d75be4d 100644
--- a/platforms/desktop-shared/application.cpp
+++ b/platforms/desktop-shared/application.cpp
@@ -44,17 +44,10 @@ static void run_emulator(void);
static void render(void);
static void frame_throttle(void);
-int application_init(const char* arg)
+int application_init(const char* rom, const char* state)
{
Log ("<·> %s %s Desktop App <·>", GEARBOY_TITLE, GEARBOY_VERSION);
- if (IsValidPointer(arg) && (strlen(arg) > 0))
- {
- Log ("Loading with argv: %s");
- }
-
- int ret = sdl_init();
-
application_fullscreen = false;
config_init();
@@ -67,42 +60,39 @@ int application_init(const char* arg)
emu_savefiles_dir_option = config_emulator.savefiles_dir_option;
emu_savestates_dir_option = config_emulator.savestates_dir_option;
- gui_init();
+ // We need no renderer and no SDL, remove those functions
- ImGui_ImplSDL2_InitForOpenGL(sdl_window, gl_context);
-
- renderer_init();
SDL_GL_SetSwapInterval(config_video.sync ? 1 : 0);
- if (IsValidPointer(arg) && (strlen(arg) > 0))
- {
- gui_load_rom(arg);
- }
+
+ printf("Loading rom: %s\n", rom);
+ gui_load_rom(rom);
+ printf("Loading state: %s\n", state);
+ emu_load_state_file(state);
- return ret;
+ return 0x00;
}
void application_destroy(void)
{
config_write();
config_destroy();
- renderer_destroy();
- gui_destroy();
+ // We can't destroy objects we did not create. We remove them
+ //renderer_destroy();
+ //gui_destroy();
emu_destroy();
- sdl_destroy();
+ //sdl_destroy();
}
void application_mainloop(void)
{
- while (running)
- {
+ // Only 100 ticks for emulation. No crypto-mining on gearboy!
+ for (int i = 0; i < 100; i++) {
frame_time_start = SDL_GetPerformanceCounter();
sdl_events();
run_emulator();
- render();
frame_time_end = SDL_GetPerformanceCounter();
- frame_throttle();
}
}
@@ -466,20 +456,7 @@ static void sdl_shortcuts_gui(const SDL_Event* event)
static void run_emulator(void)
{
- if (!emu_is_empty())
- {
- static int i = 0;
- i++;
-
- if (i > 20)
- {
- i = 0;
-
- char title[256];
- sprintf(title, "%s %s - %s", GEARBOY_TITLE, GEARBOY_VERSION, emu_get_core()->GetCartridge()->GetFileName());
- SDL_SetWindowTitle(sdl_window, title);
- }
- }
+ // We removed stuff like window titles here
config_emulator.paused = emu_is_paused();
emu_audio_sync = config_audio.sync;
emu_update();
diff --git a/platforms/desktop-shared/application.h b/platforms/desktop-shared/application.h
index 74a8c9e..ebbd3cb 100644
--- a/platforms/desktop-shared/application.h
+++ b/platforms/desktop-shared/application.h
@@ -35,7 +35,7 @@ EXTERN SDL_version application_sdl_build_version;
EXTERN SDL_version application_sdl_link_version;
EXTERN bool application_fullscreen;
-EXTERN int application_init(const char* arg);
+EXTERN int application_init(const char* rom, const char* state);
EXTERN void application_destroy(void);
EXTERN void application_mainloop(void);
EXTERN void application_trigger_quit(void);
diff --git a/platforms/desktop-shared/main.cpp b/platforms/desktop-shared/main.cpp
index 161eb9e..37e842e 100644
--- a/platforms/desktop-shared/main.cpp
+++ b/platforms/desktop-shared/main.cpp
@@ -21,7 +21,11 @@
int main(int argc, char* argv[])
{
- int ret = application_init((argc == 2) ? argv[1] : NULL);
+ if (argc < 3) {
+ printf("Usage: gearboy [rom] [state]\n");
+ return -1;
+ }
+ int ret = application_init(argv[1], argv[2]);
if (ret >= 0)
application_mainloop();
|