...
|
...
|
@@ -39,6 +39,8 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
39
|
39
|
WITH REGARD TO THIS SOFTWARE.
|
40
|
40
|
*/
|
41
|
41
|
|
|
42
|
+#define PAD 2
|
|
43
|
+#define PAD2 4
|
42
|
44
|
#define WIDTH 64 * 8
|
43
|
45
|
#define HEIGHT 40 * 8
|
44
|
46
|
#define TIMEOUT_MS 334
|
...
|
...
|
@@ -60,6 +62,13 @@ static Uint64 exec_deadline, deadline_interval, ms_interval;
|
60
|
62
|
char *rom_path;
|
61
|
63
|
int window_created = 0;
|
62
|
64
|
|
|
65
|
+static int
|
|
66
|
+clamp(int v, int min, int max)
|
|
67
|
+{
|
|
68
|
+
|
|
69
|
+ return v < min ? min : v > max ? max
|
|
70
|
+ : v;
|
|
71
|
+}
|
63
|
72
|
static Uint8
|
64
|
73
|
audio_dei(int instance, Uint8 *d, Uint8 port)
|
65
|
74
|
{
|
...
|
...
|
@@ -171,7 +180,7 @@ set_zoom(Uint8 z, int win)
|
171
|
180
|
if(z >= 1) {
|
172
|
181
|
zoom = z;
|
173
|
182
|
if(win)
|
174
|
|
- set_window_size(emu_window, (uxn_screen.width) * zoom, (uxn_screen.height) * zoom);
|
|
183
|
+ set_window_size(emu_window, (uxn_screen.width + PAD2) * zoom, (uxn_screen.height + PAD2) * zoom);
|
175
|
184
|
}
|
176
|
185
|
}
|
177
|
186
|
|
...
|
...
|
@@ -184,23 +193,29 @@ emu_resize(int width, int height)
|
184
|
193
|
return 0;
|
185
|
194
|
if(emu_texture != NULL)
|
186
|
195
|
SDL_DestroyTexture(emu_texture);
|
187
|
|
- SDL_RenderSetLogicalSize(emu_renderer, width, height);
|
|
196
|
+ SDL_RenderSetLogicalSize(emu_renderer, width + PAD2, height + PAD2);
|
188
|
197
|
emu_texture = SDL_CreateTexture(emu_renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STATIC, width, height);
|
189
|
198
|
if(emu_texture == NULL || SDL_SetTextureBlendMode(emu_texture, SDL_BLENDMODE_NONE))
|
190
|
199
|
return system_error("SDL_SetTextureBlendMode", SDL_GetError());
|
191
|
200
|
if(SDL_UpdateTexture(emu_texture, NULL, uxn_screen.pixels, sizeof(Uint32)) != 0)
|
192
|
201
|
return system_error("SDL_UpdateTexture", SDL_GetError());
|
193
|
|
- set_window_size(emu_window, width * zoom, height * zoom);
|
|
202
|
+ set_window_size(emu_window, (width + PAD2) * zoom, (height + PAD2) * zoom);
|
194
|
203
|
return 1;
|
195
|
204
|
}
|
196
|
205
|
|
197
|
206
|
static void
|
198
|
207
|
emu_redraw(void)
|
199
|
208
|
{
|
|
209
|
+ SDL_Rect r;
|
|
210
|
+ r.x = PAD;
|
|
211
|
+ r.y = PAD;
|
|
212
|
+ r.w = uxn_screen.width;
|
|
213
|
+ r.h = uxn_screen.height;
|
200
|
214
|
screen_redraw();
|
201
|
215
|
if(SDL_UpdateTexture(emu_texture, NULL, uxn_screen.pixels, uxn_screen.width * sizeof(Uint32)) != 0)
|
202
|
216
|
system_error("SDL_UpdateTexture", SDL_GetError());
|
203
|
|
- SDL_RenderCopy(emu_renderer, emu_texture, NULL, NULL);
|
|
217
|
+ SDL_RenderClear(emu_renderer);
|
|
218
|
+ SDL_RenderCopy(emu_renderer, emu_texture, NULL, &r);
|
204
|
219
|
SDL_RenderPresent(emu_renderer);
|
205
|
220
|
}
|
206
|
221
|
|
...
|
...
|
@@ -359,7 +374,7 @@ handle_events(Uxn *u)
|
359
|
374
|
uxn_eval(u, PEEK2(&u->dev[0x30 + 0x10 * (event.type - audio0_event)]));
|
360
|
375
|
/* Mouse */
|
361
|
376
|
else if(event.type == SDL_MOUSEMOTION)
|
362
|
|
- mouse_pos(u, &u->dev[0x90], event.motion.x, event.motion.y);
|
|
377
|
+ mouse_pos(u, &u->dev[0x90], clamp(event.motion.x - PAD, 0, uxn_screen.width), clamp(event.motion.y - PAD, 0, uxn_screen.height));
|
363
|
378
|
else if(event.type == SDL_MOUSEBUTTONUP)
|
364
|
379
|
mouse_up(u, &u->dev[0x90], SDL_BUTTON(event.button.button));
|
365
|
380
|
else if(event.type == SDL_MOUSEBUTTONDOWN)
|
...
|
...
|
@@ -447,10 +462,10 @@ run(Uxn *u)
|
447
|
462
|
Uint64 next_refresh = 0;
|
448
|
463
|
Uint64 frame_interval = SDL_GetPerformanceFrequency() / 60;
|
449
|
464
|
window_created = 1;
|
450
|
|
- emu_window = SDL_CreateWindow("Uxn", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, uxn_screen.width * zoom, uxn_screen.height * zoom, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
|
465
|
+ emu_window = SDL_CreateWindow("Uxn", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, (uxn_screen.width + PAD2) * zoom, (uxn_screen.height + PAD2) * zoom, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
451
|
466
|
if(emu_window == NULL)
|
452
|
467
|
return system_error("sdl_window", SDL_GetError());
|
453
|
|
- emu_renderer = SDL_CreateRenderer(emu_window, -1, 0);
|
|
468
|
+ emu_renderer = SDL_CreateRenderer(emu_window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
|
454
|
469
|
if(emu_renderer == NULL)
|
455
|
470
|
return system_error("sdl_renderer", SDL_GetError());
|
456
|
471
|
emu_resize(uxn_screen.width, uxn_screen.height);
|