commit 9db76ea
zzo38
·
2023-04-14 00:05:43 +0000 UTC
parent abdf01d
Add switch to use a separate thread for reading from stdin.
2 files changed,
+24,
-1
M
main.c
+3,
-0
1@@ -7,6 +7,9 @@
2 -F
3 Start in full screen mode.
4
5+-I
6+ Use a separate thread to read from stdin.
7+
8 -N
9 Tells the window manager to omit the frame.
10
M
main.c
+21,
-1
1@@ -203,6 +203,7 @@ static Uint8 use_mouse=1;
2 static Uint8 use_debug=0;
3 static Uint8 use_utc=0;
4 static Uint8 use_extension=0;
5+static Uint8 use_thread=0;
6 static Uint8 hide_cursor=0;
7 static Uint8 allow_write=0;
8 static Uint8 joypad_repeat=0;
9@@ -220,6 +221,7 @@ static volatile Uint8 timer_expired=0;
10 static SDL_Surface*screen;
11 static Uint8 layers;
12 static Uint8 palet=7;
13+static SDL_Thread*in_thread;
14
15 static Sint32*audio_option;
16 static SDL_AudioSpec audiospec;
17@@ -1229,12 +1231,28 @@ static int run_screen(void) {
18 device[9].d[6]=k&7;
19 run(GET16(device[9].d));
20 break;
21+ case SDL_USEREVENT+1:
22+ if(use_extension) device[1].d[7]&=0xF0;
23+ device[1].d[2]=e.user.code;
24+ run(GET16(device[1].d));
25+ break;
26 }
27 if(picture_changed) redraw();
28 }
29 return 0;
30 }
31
32+static int stdin_thread_fn(void*unused) {
33+ int c;
34+ SDL_Event e;
35+ e.type=SDL_USEREVENT+1;
36+ while((c=getchar())>=0) {
37+ e.user.code=c;
38+ SDL_PushEvent(&e);
39+ }
40+ return 0;
41+}
42+
43 static void set_datetime(char*s) {
44 int i=2;
45 i=strtol(s,&s,10);
46@@ -1282,9 +1300,10 @@ int main(int argc,char**argv) {
47 device[10].aux=&uxnfile0;
48 device[11].aux=&uxnfile1;
49 device[12].in=datetime_in;
50- while((i=getopt(argc,argv,"+ADFNQST:YZa:dh:ijnp:qs:t:w:xyz:"))>0) switch(i) {
51+ while((i=getopt(argc,argv,"+ADFINQST:YZa:dh:ijnp:qs:t:w:xyz:"))>0) switch(i) {
52 case 'D': scrflags|=SDL_DOUBLEBUF; break;
53 case 'F': scrflags|=SDL_FULLSCREEN; break;
54+ case 'I': use_thread=1; break;
55 case 'N': scrflags|=SDL_NOFRAME; break;
56 case 'Q': use_mouse=0; break;
57 case 'S': disallow_size_change=1; break;
58@@ -1346,6 +1365,7 @@ int main(int argc,char**argv) {
59 }
60 if(use_screen) {
61 if(size_changed) set_screen_mode(scr_w,scr_h);
62+ if(use_thread) in_thread=SDL_CreateThread(stdin_thread_fn,0);
63 while(run_screen()) {
64 for(i=0;i<15;i++) for(j=0;j<16;j++) device[i].d[j]=0;
65 load_rom();