@@ -75,6 +75,7 @@ static SDL_Texture *texture;
7575/* Event queue specific variables */
7676static uint32_t queues_capacity ;
7777static uint32_t event_count ;
78+ static uint32_t deferred_submissions = 0 ;
7879static event_queue_t event_queue = {
7980 .base = 0 ,
8081 .end = 0 ,
@@ -128,6 +129,8 @@ static uint32_t round_pow2(uint32_t x)
128129 return x ;
129130}
130131
132+ void syscall_submit_queue (struct riscv_t * rv );
133+
131134/* check if we need to setup SDL and run event loop */
132135static bool check_sdl (struct riscv_t * rv , uint32_t width , uint32_t height )
133136{
@@ -136,7 +139,6 @@ static bool check_sdl(struct riscv_t *rv, uint32_t width, uint32_t height)
136139 fprintf (stderr , "Failed to call SDL_Init()\n" );
137140 exit (1 );
138141 }
139-
140142 window = SDL_CreateWindow ("rv32emu" , SDL_WINDOWPOS_UNDEFINED ,
141143 SDL_WINDOWPOS_UNDEFINED , width , height ,
142144 0 /* flags */ );
@@ -149,6 +151,11 @@ static bool check_sdl(struct riscv_t *rv, uint32_t width, uint32_t height)
149151 renderer = SDL_CreateRenderer (window , -1 , SDL_RENDERER_ACCELERATED );
150152 texture = SDL_CreateTexture (renderer , SDL_PIXELFORMAT_ARGB8888 ,
151153 SDL_TEXTUREACCESS_STREAMING , width , height );
154+
155+ if (deferred_submissions ) {
156+ syscall_submit_queue (rv );
157+ deferred_submissions = 0 ;
158+ }
152159 }
153160
154161 SDL_Event event ;
@@ -158,12 +165,6 @@ static bool check_sdl(struct riscv_t *rv, uint32_t width, uint32_t height)
158165 rv_halt (rv );
159166 return false;
160167 case SDL_KEYDOWN :
161- if (event .key .keysym .sym == SDLK_ESCAPE &&
162- SDL_GetRelativeMouseMode () == SDL_TRUE ) {
163- SDL_SetRelativeMouseMode (SDL_FALSE );
164- break ;
165- }
166- /* fall through */
167168 case SDL_KEYUP : {
168169 if (event .key .repeat )
169170 break ;
@@ -192,12 +193,6 @@ static bool check_sdl(struct riscv_t *rv, uint32_t width, uint32_t height)
192193 break ;
193194 }
194195 case SDL_MOUSEBUTTONDOWN :
195- if (event .button .button == SDL_BUTTON_LEFT &&
196- SDL_GetRelativeMouseMode () == SDL_FALSE ) {
197- SDL_SetRelativeMouseMode (SDL_TRUE );
198- break ;
199- }
200- /* fall through */
201196 case SDL_MOUSEBUTTONUP : {
202197 event_t new_event = {
203198 .type = MOUSE_BUTTON_EVENT ,
@@ -257,6 +252,14 @@ void syscall_submit_queue(struct riscv_t *rv)
257252 /* submit_queue(count) */
258253 uint32_t count = rv_get_reg (rv , rv_reg_a0 );
259254
255+ if (!window ) {
256+ deferred_submissions += count ;
257+ return ;
258+ }
259+
260+ if (deferred_submissions )
261+ count = deferred_submissions ;
262+
260263 while (count -- ) {
261264 submission_t submission = submission_pop (rv );
262265
0 commit comments