Skip to content

Commit c43328c

Browse files
committed
hosted: move screen rendering to separate thread
Fixes lack of screen updates during lengthy operations.
1 parent a45cd2a commit c43328c

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

hosted/Arduino.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,15 @@ void dump_yuv()
7373
#endif
7474
}
7575

76+
static SDL_Thread *scrthr;
77+
static int screen_thread(void *p);
78+
static bool screen_quit = false;
79+
7680
static void my_exit(void)
7781
{
7882
fprintf(stderr, "my_exit\n");
83+
screen_quit = true;
84+
SDL_WaitThread(scrthr, NULL);
7985
if (vid_fp)
8086
pclose(vid_fp);
8187
if (aud_fp)
@@ -186,6 +192,7 @@ int main(int argc, char **argv)
186192

187193
hosting_mem_allocated = mallinfo().uordblks;
188194

195+
SDL_CreateThread(screen_thread, NULL);
189196
setup();
190197
for (;;)
191198
loop();
@@ -197,9 +204,6 @@ uint64_t total_frames = 0;
197204
extern uint64_t total_samples;
198205

199206
void hosted_pump_events() {
200-
static int last_line = 0;
201-
static SDL_Color *pl = palette[0];
202-
203207
SDL_Event event;
204208
SDL_PumpEvents();
205209
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_ALLEVENTS ^ (SDL_KEYUPMASK|SDL_KEYDOWNMASK)) == 1) {
@@ -213,7 +217,18 @@ void hosted_pump_events() {
213217
}
214218
SDL_PumpEvents();
215219
}
220+
}
216221

222+
int screen_thread(void *p)
223+
{
224+
static int last_line = 0;
225+
static SDL_Color *pl = palette[0];
226+
227+
while (!screen_quit) {
228+
if (!vs23_int.enabled) {
229+
SDL_Delay(10);
230+
continue;
231+
}
217232
int new_line = SpiRamReadRegister(CURLINE);
218233

219234
if (new_line > last_line) {
@@ -361,7 +376,8 @@ void hosted_pump_events() {
361376
}
362377
}
363378
last_line = new_line;
364-
vs23.setFrame(micros() / vs23_int.line_us / vs23_int.line_count);
379+
usleep(100);
380+
}
365381
}
366382

367383
uint32_t VS23S010::frame()

0 commit comments

Comments
 (0)