@@ -75,6 +75,7 @@ static SDL_Texture *texture;
75
75
/* Event queue specific variables */
76
76
static uint32_t queues_capacity ;
77
77
static uint32_t event_count ;
78
+ static uint32_t deferred_submissions = 0 ;
78
79
static event_queue_t event_queue = {
79
80
.base = 0 ,
80
81
.end = 0 ,
@@ -128,6 +129,8 @@ static uint32_t round_pow2(uint32_t x)
128
129
return x ;
129
130
}
130
131
132
+ void syscall_submit_queue (struct riscv_t * rv );
133
+
131
134
/* check if we need to setup SDL and run event loop */
132
135
static bool check_sdl (struct riscv_t * rv , uint32_t width , uint32_t height )
133
136
{
@@ -136,7 +139,6 @@ static bool check_sdl(struct riscv_t *rv, uint32_t width, uint32_t height)
136
139
fprintf (stderr , "Failed to call SDL_Init()\n" );
137
140
exit (1 );
138
141
}
139
-
140
142
window = SDL_CreateWindow ("rv32emu" , SDL_WINDOWPOS_UNDEFINED ,
141
143
SDL_WINDOWPOS_UNDEFINED , width , height ,
142
144
0 /* flags */ );
@@ -149,6 +151,11 @@ static bool check_sdl(struct riscv_t *rv, uint32_t width, uint32_t height)
149
151
renderer = SDL_CreateRenderer (window , -1 , SDL_RENDERER_ACCELERATED );
150
152
texture = SDL_CreateTexture (renderer , SDL_PIXELFORMAT_ARGB8888 ,
151
153
SDL_TEXTUREACCESS_STREAMING , width , height );
154
+
155
+ if (deferred_submissions ) {
156
+ syscall_submit_queue (rv );
157
+ deferred_submissions = 0 ;
158
+ }
152
159
}
153
160
154
161
SDL_Event event ;
@@ -158,12 +165,6 @@ static bool check_sdl(struct riscv_t *rv, uint32_t width, uint32_t height)
158
165
rv_halt (rv );
159
166
return false;
160
167
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 */
167
168
case SDL_KEYUP : {
168
169
if (event .key .repeat )
169
170
break ;
@@ -192,12 +193,6 @@ static bool check_sdl(struct riscv_t *rv, uint32_t width, uint32_t height)
192
193
break ;
193
194
}
194
195
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 */
201
196
case SDL_MOUSEBUTTONUP : {
202
197
event_t new_event = {
203
198
.type = MOUSE_BUTTON_EVENT ,
@@ -257,6 +252,14 @@ void syscall_submit_queue(struct riscv_t *rv)
257
252
/* submit_queue(count) */
258
253
uint32_t count = rv_get_reg (rv , rv_reg_a0 );
259
254
255
+ if (!window ) {
256
+ deferred_submissions += count ;
257
+ return ;
258
+ }
259
+
260
+ if (deferred_submissions )
261
+ count = deferred_submissions ;
262
+
260
263
while (count -- ) {
261
264
submission_t submission = submission_pop (rv );
262
265
0 commit comments