commit 9e37b59

zzo38  ·  2023-06-23 05:27:31 +0000 UTC
parent 8f291ff
Change the EOF trigger working, and use a condition variable in case the event queue is full.
3 files changed,  +35, -16
M main.c
+5, -7
 1@@ -268,6 +268,11 @@ b_ ?offset%
 2 
 3 Nonstandard ports of devices are:
 4 
 5+16
 6+  Input flags. Currently only the low bit is used (the rest must be clear).
 7+  If the low bit is set, then EOF trigger is enabled; the vector is called
 8+  on EOF, with the type and input both set to zero.
 9+
10 36*/46*/56*/66*
11   Detune register. This is treated as sixteen fraction bits, and is then
12   added to 1.0 and multiplied by the frequency which has been specified by
13@@ -311,13 +316,6 @@ This section lists the UUID-based extensions that are implemented in
14 this emulator (the -x switch is required, since they use nonstandard
15 expansion commands to activate them).
16 
17-5afdcdfe-e263-11ed-9634-002618745416
18-  The device number must be 0x10. This will enable calling the stdio vector
19-  on EOF; the type will be zero in this case. The version will be 1 (but
20-  this only means that the emulator supports this feature; it does not mean
21-  that stdin is connected to something that actually has a EOF). This
22-  implementation requires the -n switch to be used to support this command.
23-
24 80175132-e263-11ed-b8c9-002618745416
25   Allows setting separate foreground and background colours. The device
26   number must be zero, and the version will be 1. The data is eight 16-bit
M main.c
+21, -9
 1@@ -231,8 +231,8 @@ static volatile Uint8 timer_expired=0;
 2 static SDL_Surface*screen;
 3 static Uint8 layers;
 4 static Uint8 palet=7;
 5-static Uint8 eof_trigger=0;
 6 static Uint8 touch_mode=0;
 7+static SDL_cond*stdin_cond;
 8 
 9 static Uint16 scriptc;
10 static Script*scriptv;
11@@ -879,13 +879,9 @@ static void run_audio(void) {
12 }
13 
14 static void do_extension_by_uuid(Uint16 addr) {
15-  static const Uint8 uuid_eof[]="\x5A\xFD\xCD\xFE\xE2\x63\x11\xED\x96\x34\x00\x26\x18\x74\x54\x16";
16   static const Uint8 uuid_8color[]="\x80\x17\x51\x32\xE2\x63\x11\xED\xB8\xC9\x00\x26\x18\x74\x54\x16";
17   int i;
18-  if(mem[addr+1]==0x10 && !use_screen && !memcmp(mem+addr+2,uuid_eof,16)) {
19-    eof_trigger=1;
20-    mem[addr+18]=1;
21-  } else if(mem[addr+1]==0x00 && use_screen && !memcmp(mem+addr+2,uuid_8color,16)) {
22+  if(mem[addr+1]==0x00 && use_screen && !memcmp(mem+addr+2,uuid_8color,16)) {
23     for(i=0;i<8;i++) {
24       colors[i+070].r=(mem[addr+19+i+i]>>4)*0x11;
25       colors[i+070].g=(mem[addr+19+i+i]&15)*0x11;
26@@ -1321,7 +1317,12 @@ static int run_screen(void) {
27       case SDL_USEREVENT+1:
28         device[1].d[2]=e.user.code;
29         device[1].d[7]=1;
30+        if(e.user.data1) {
31+          if(!(device[1].d[6]&1)) break;
32+          device[1].d[7]=0;
33+        }
34         run(GET16(device[1].d));
35+        SDL_CondBroadcast(stdin_cond);
36         break;
37       case SDL_JOYAXISMOTION:
38         if(!joy_axis_mode) break;
39@@ -1375,10 +1376,18 @@ static int run_screen(void) {
40 static int stdin_thread_fn(void*unused) {
41   int c;
42   SDL_Event e;
43+  SDL_mutex*mut=SDL_CreateMutex();
44+  SDL_LockMutex(mut);
45   e.type=SDL_USEREVENT+1;
46+  e.user.data1=0;
47   while((c=fgetc(inf))>=0) {
48     e.user.code=c;
49-    SDL_PushEvent(&e);
50+    while(SDL_PushEvent(&e)) SDL_CondWaitTimeout(stdin_cond,mut,timer_rate?:10);
51+  }
52+  if(use_extension) {
53+    e.user.code=0;
54+    e.user.data1="";
55+    while(SDL_PushEvent(&e)) SDL_CondWaitTimeout(stdin_cond,mut,timer_rate?:10);
56   }
57   return 0;
58 }
59@@ -1708,7 +1717,10 @@ int main(int argc,char**argv) {
60   }
61   if(use_screen) {
62     if(size_changed) set_screen_mode(scr_w,scr_h);
63-    if(use_thread) SDL_CreateThread(stdin_thread_fn,0);
64+    if(use_thread) {
65+      stdin_cond=SDL_CreateCond();
66+      SDL_CreateThread(stdin_thread_fn,0);
67+    }
68     while(run_screen()) {
69       for(i=0;i<15;i++) for(j=0;j<16;j++) device[i].d[j]=0;
70       if(scriptc) do_script(0);
71@@ -1723,7 +1735,7 @@ int main(int argc,char**argv) {
72       device[1].d[2]=i;
73       run(GET16(device[1].d));
74     }
75-    if(eof_trigger) {
76+    if(use_extension && (device[1].d[6]&1)) {
77       device[1].d[2]=device[1].d[7]=0;
78       run(GET16(device[1].d));
79     }
+9, -0
 1@@ -0,0 +1,9 @@
 2+|0100
 3+  #c0c0 #08 DEO2k INC INC DEO2k INC INC DEO2
 4+  #0126 DEO
 5+  #0000 STH2k #28 DEO2k INC INC DEO2
 6+  [; #10 DEO2 BRK ]@
 7+  #12 DEI DUP #0a NEQ [? POP STH2rk #28 DEO2 #2a DEI2k #0008 ADD2 ROT DEO2 BRK ]@
 8+  #0005 SFT2 ;Font ADD2 #2c DEO2 #012f DEO BRK
 9+
10+\_@20'8*- \@Font \~ascii.font