commit d0acf5f

chld  ·  2026-10-27 23:36:18 +0000 UTC
parent 5231ceb
poll instead of wait
4 files changed,  +3, -150
M uxn.c
M uxn.o
M uxn.c
+3, -150
  1@@ -753,17 +753,6 @@ static void set_cursor(void) {
  2   if(hide_cursor) SDL_ShowCursor(paused || !use_mouse);
  3 }
  4 
  5-static Uint32 timer_callback(Uint32 interval) {
  6-  if(!timer_expired) {
  7-    SDL_Event e;
  8-    timer_expired=1;
  9-    e.type=SDL_USEREVENT;
 10-    SDL_PushEvent(&e);
 11-    timer_expired=1;
 12-  }
 13-  return interval;
 14-}
 15-
 16 static void set_screen_mode(int w,int h) {
 17   picture_changed=size_changed=0;
 18   free(bglayer);
 19@@ -936,53 +925,6 @@ static void audio_callback(void*userdata,Uint8*stream,int len) {
 20   }
 21 }
 22 
 23-static void run_audio(void) {
 24-  Uint8 c=audiospec.channels;
 25-  Uint32 vol=audio_option['m'-'a']?0:audio_option['v'-'a'];
 26-  Uint32 fram=(timer_rate*(long long)audiospec.freq)/1000;
 27-  Uint8 q=0;
 28-  Uint32 f=0;
 29-  UxnAudio*a;
 30-  Uint32 o0,o1,d,e;
 31-  for(;;) {
 32-    if(++f==fram) {
 33-      f=0;
 34-      run(GET16(device[2].d));
 35-    }
 36-    if(q) {
 37-      for(d=3;d<7;d++) if(q&(1<<d)) run(GET16(device[d].d));
 38-      q=0;
 39-    }
 40-    //TODO: check for input from stdin
 41-    o0=o1=0;
 42-    for(d=3;d<7;d++) {
 43-      a=device[d].aux;
 44-      if(a->pos>=a->end && !a->length) {
 45-        end:
 46-        if(a->length) q|=1<<d;
 47-        a->pos=a->length=a->end=0;
 48-        continue;
 49-      }
 50-      e=envelope(a);
 51-      if(!e) goto end;
 52-      a->envtime++;
 53-      e*=(Sint8)(mem[a->pos]^0x80);
 54-      a->phase+=a->freq;
 55-      if(a->phase>=0x1000000) {
 56-        a->pos+=a->phase>>24;
 57-        a->phase&=0xFFFFFF;
 58-        while(a->pos>=a->end && a->length) a->pos-=a->length;
 59-      }
 60-      o0+=e*a->vol[0];
 61-      o1+=e*a->vol[1];
 62-    }
 63-    d=(o0*vol)>>12; putchar(d>>8); putchar(d);
 64-    if(c==2) {
 65-      d=(o1*vol)>>12; putchar(d>>8); putchar(d);
 66-    }
 67-  }
 68-}
 69-
 70 static void system_exp(Device *dev, Uint16 addr)
 71 {
 72   Uint32 src, dst;
 73@@ -1307,19 +1249,18 @@ static int run_screen(void) {
 74   SDL_Event e;
 75   int i,j,k;
 76   last_tick = SDL_GetTicks();
 77+  
 78     while (1) {
 79-    /* poll timer */
 80     Uint32 now = SDL_GetTicks();
 81     if (now - last_tick >= timer_rate) {
 82       last_tick = now;
 83       if (!paused) run(GET16(device[2].d));
 84     }
 85   
 86-  while(SDL_WaitEvent(&e)) {
 87+  while(SDL_PollEvent(&e)) {
 88     switch(e.type) {
 89       case SDL_QUIT: return 0;
 90       case SDL_VIDEOEXPOSE: redraw(); break;
 91-      case SDL_USEREVENT: timer_expired=0; if(!paused) run(GET16(device[2].d)); break;
 92       case SDL_KEYDOWN:
 93         i=0;
 94         switch(e.key.keysym.sym) {
 95@@ -1334,7 +1275,7 @@ static int run_screen(void) {
 96           case SDLK_RIGHT: i=0x80; break;
 97           case SDLK_PAGEUP: i=-scroll_size; goto scroll;
 98           case SDLK_PAGEDOWN: i=scroll_size; goto scroll;
 99-          case SDLK_F1: run(GET16(device[2].d)); timer_expired=0; break;
100+	case SDLK_F1: run(GET16(device[2].d));  break;
101           case SDLK_F2: if(audio_option) audio_option['m'-'a']^=1; picture_changed=debugger; break;
102           case SDLK_F3: use_mouse^=1; set_cursor(); picture_changed=debugger; break;
103           case SDLK_F4: layers=(layers+1)%3; redraw(); break;
104@@ -1346,17 +1287,6 @@ static int run_screen(void) {
105           case SDLK_F10: return 0;
106           case SDLK_PAUSE: debugger=0; paused^=1; set_cursor(); picture_changed=1; break;
107         }
108-        if(paused) {
109-          if(debugger) {
110-            if(i&0xF0) {
111-              debug_screen(0,i==0x10?11:i==0x20?10:i==0x40?8:i==0x80?12:0);
112-            } else if(i=e.key.keysym.unicode) {
113-              debug_screen(0,i);
114-            }
115-            picture_changed=1;
116-          }
117-          break;
118-        }
119         if(i) {
120           if(joypad_repeat || !(device[8].d[2]&i)) {
121             device[8].d[2]|=i;
122@@ -1392,83 +1322,6 @@ static int run_screen(void) {
123           run(GET16(device[8].d));
124         }
125         break;
126-      case SDL_MOUSEMOTION:
127-      case SDL_MOUSEBUTTONDOWN:
128-      case SDL_MOUSEBUTTONUP:
129-        if(paused || !use_mouse) break;
130-        k=SDL_GetMouseState(&i,&j);
131-        i/=zoom; j/=zoom;
132-        if(i<0 || i>=screen->w || j<0 || j>=screen->h) break;
133-        if(touch_mode) {
134-          if(e.type==SDL_MOUSEBUTTONDOWN && !device[9].d[6]) {
135-            PUT16(device[9].d+2,i);
136-            PUT16(device[9].d+4,j);
137-            run(GET16(device[9].d));
138-          } else if(e.type==SDL_MOUSEBUTTONUP && !k) {
139-            device[9].d[6]=0;
140-            run(GET16(device[9].d));
141-            i=j=0x8000;
142-          } else if(e.type==SDL_MOUSEMOTION && !k) {
143-            break;
144-          }
145-        }
146-        PUT16(device[9].d+2,i);
147-        PUT16(device[9].d+4,j);
148-        device[9].d[6]=k&7;
149-        run(GET16(device[9].d));
150-        break;
151-      case SDL_USEREVENT+1:
152-        device[1].d[2]=e.user.code;
153-        device[1].d[7]=1;
154-        if(e.user.data1) {
155-          if(!(device[1].d[6]&1)) break;
156-          device[1].d[7]=0;
157-        }
158-        run(GET16(device[1].d));
159-        break;
160-      case SDL_JOYAXISMOTION:
161-        if(!joy_axis_mode) break;
162-        if(j=select_joystick(e.jaxis.which)) {
163-          k=device[8].d[j];
164-          if(e.jaxis.axis==joy_axis_x) {
165-            i=e.jaxis.value*(joy_axis_mode&1?-1:1);
166-            k&=0x3F;
167-            if(i>=joy_sensitivity) k|=0x80; else if(i<=-joy_sensitivity) k|=0x40;
168-          } else if(e.jaxis.axis==joy_axis_y) {
169-            i=e.jaxis.value*(joy_axis_mode&2?-1:1);
170-            k&=0xCF;
171-            if(i>=joy_sensitivity) k|=0x10; else if(i<=-joy_sensitivity) k|=0x20;
172-          }
173-          trigger:
174-          if(k!=device[8].d[j]) {
175-            device[8].d[j]=k;
176-            if(!paused) run(GET16(device[8].d));
177-          }
178-        }
179-        break;
180-      case SDL_JOYBUTTONDOWN:
181-      case SDL_JOYBUTTONUP:
182-        if(e.jbutton.button&~127) break;
183-        if(j=select_joystick(e.jbutton.which)) {
184-          k=device[8].d[j];
185-          i=joy_button_map[e.jbutton.button];
186-          if(e.jbutton.state==SDL_PRESSED) k|=i; else k&=~i;
187-          goto trigger;
188-        }
189-        break;
190-      case SDL_JOYHATMOTION:
191-        if(!joy_hat_mode) break;
192-        if(j=select_joystick(e.jhat.which)) {
193-          k=device[8].d[j]&0x0F;
194-          // Note that the SDL_HAT_ values are bits counted clockwise from UP.
195-          i=(e.jhat.value*0x1111)>>joy_hat_mode;
196-          if(i&SDL_HAT_UP) k|=0x10;
197-          if(i&SDL_HAT_DOWN) k|=0x20;
198-          if(i&SDL_HAT_LEFT) k|=0x40;
199-          if(i&SDL_HAT_RIGHT) k|=0x80;
200-          goto trigger;
201-        }
202-        break;
203     }
204     if(picture_changed) redraw();
205   }
M uxn.o
+0, -0
+0, -0
+0, -0