Switched from non-blocking read to thread and custom SDL event
This commit is contained in:
parent
74fc816810
commit
7b5ad795f8
|
@ -104,7 +104,7 @@ start(Uxn *u)
|
||||||
{
|
{
|
||||||
if(!evaluxn(u, PAGE_PROGRAM))
|
if(!evaluxn(u, PAGE_PROGRAM))
|
||||||
return error("Reset", "Failed");
|
return error("Reset", "Failed");
|
||||||
while(mempeek16(devconsole->dat, 0))
|
if(mempeek16(devconsole->dat, 0))
|
||||||
while(read(0, &devconsole->dat[0x2], 1) > 0)
|
while(read(0, &devconsole->dat[0x2], 1) > 0)
|
||||||
evaluxn(u, mempeek16(devconsole->dat, 0));
|
evaluxn(u, mempeek16(devconsole->dat, 0));
|
||||||
return 1;
|
return 1;
|
||||||
|
|
26
src/uxnemu.c
26
src/uxnemu.c
|
@ -1,7 +1,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include "uxn.h"
|
#include "uxn.h"
|
||||||
|
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
|
@ -30,6 +29,7 @@ static SDL_Rect gRect;
|
||||||
static Ppu ppu;
|
static Ppu ppu;
|
||||||
static Apu apu[POLYPHONY];
|
static Apu apu[POLYPHONY];
|
||||||
static Device *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole;
|
static Device *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole;
|
||||||
|
static Uint32 stdin_event;
|
||||||
|
|
||||||
#define PAD 16
|
#define PAD 16
|
||||||
|
|
||||||
|
@ -329,6 +329,17 @@ nil_talk(Device *d, Uint8 b0, Uint8 w)
|
||||||
|
|
||||||
#pragma mark - Generics
|
#pragma mark - Generics
|
||||||
|
|
||||||
|
static int
|
||||||
|
in_reader(void *p)
|
||||||
|
{
|
||||||
|
SDL_Event event;
|
||||||
|
event.type = stdin_event;
|
||||||
|
while(read(0, &event.cbutton.button, 1) > 0)
|
||||||
|
SDL_PushEvent(&event);
|
||||||
|
return 0;
|
||||||
|
(void)p;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
start(Uxn *u)
|
start(Uxn *u)
|
||||||
{
|
{
|
||||||
|
@ -367,10 +378,13 @@ start(Uxn *u)
|
||||||
if(event.window.event == SDL_WINDOWEVENT_EXPOSED)
|
if(event.window.event == SDL_WINDOWEVENT_EXPOSED)
|
||||||
redraw(u);
|
redraw(u);
|
||||||
break;
|
break;
|
||||||
}
|
default:
|
||||||
}
|
if(event.type == stdin_event) {
|
||||||
while(read(0, &devconsole->dat[0x2], 1) > 0)
|
devconsole->dat[0x2] = event.cbutton.button;
|
||||||
evaluxn(u, mempeek16(devconsole->dat, 0));
|
evaluxn(u, mempeek16(devconsole->dat, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
evaluxn(u, mempeek16(devscreen->dat, 0));
|
evaluxn(u, mempeek16(devscreen->dat, 0));
|
||||||
if(reqdraw)
|
if(reqdraw)
|
||||||
redraw(u);
|
redraw(u);
|
||||||
|
@ -388,8 +402,8 @@ main(int argc, char **argv)
|
||||||
Uxn u;
|
Uxn u;
|
||||||
zoom = 2;
|
zoom = 2;
|
||||||
|
|
||||||
/* set stdin nonblocking */
|
stdin_event = SDL_RegisterEvents(1);
|
||||||
fcntl(0, F_SETFL, fcntl(0, F_GETFL, 0) | O_NONBLOCK);
|
SDL_CreateThread(in_reader, "stdin", NULL);
|
||||||
|
|
||||||
if(argc < 2)
|
if(argc < 2)
|
||||||
return error("Input", "Missing");
|
return error("Input", "Missing");
|
||||||
|
|
Loading…
Reference in New Issue