Redo timers to use the Windows WM_TIMER mechanism.
authorGuillermo J. Rozas <edu/mit/csail/zurich/gjr>
Fri, 3 Sep 1993 18:02:29 +0000 (18:02 +0000)
committerGuillermo J. Rozas <edu/mit/csail/zurich/gjr>
Fri, 3 Sep 1993 18:02:29 +0000 (18:02 +0000)
v7/src/microcode/ntenv.c
v7/src/microcode/ntgui.c
v7/src/microcode/ntscreen.h
v7/src/microcode/ntsig.c

index d8c103189f43536b8efb6291566c87ac39d8a2c1..85e1d11a4c09a3bb515bce0073661bdcd875a294 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: ntenv.c,v 1.8 1993/09/01 18:31:49 gjr Exp $
+$Id: ntenv.c,v 1.9 1993/09/03 17:54:57 gjr Exp $
 
 Copyright (c) 1992-1993 Massachusetts Institute of Technology
 
@@ -35,7 +35,7 @@ MIT in each case. */
 #include "scheme.h"
 #include "nt.h"
 #include "osenv.h"
-#include <windows.h>
+#include "ntscreen.h"
 #include <stdlib.h>
 #include <string.h>
 \f
@@ -104,12 +104,14 @@ DEFUN_VOID (OS_real_time_clock)
    This just provides three distinct timers.
  */
 
-#define TIMER_ID_BASE          0x100
 #define TIMER_ID_REAL          (TIMER_ID_BASE + 2)
 #define TIMER_ID_PROFILE       (TIMER_ID_BASE + 1)
 #define TIMER_ID_PROCESS       (TIMER_ID_BASE + 0)
 
-#if 0
+#ifdef USE_WM_TIMER
+
+#define TIMER_ID_BASE          0x100
+
 enum timer_next
 {
   timer_next_none,
@@ -146,11 +148,11 @@ DEFUN (clear_timer, (timer_id), int timer_id)
   return;
 }
 \f
-extern VOID CALLBACK EXFUN (TimerProc, (HWND, UINT, UINT, DWORD));
+extern VOID /* CALLBACK */ EXFUN (TimerProc, (HWND, UINT, UINT, DWORD));
 
-#define THE_TIMER_PROC ((TIMERPROC) TimerProc)
+#define THE_TIMER_PROC ((TIMERPROC) NULL) /* TimerProc */
 
-VOID CALLBACK
+VOID /* CALLBACK */
 DEFUN (TimerProc, (hwnd, umsg, timer_id, dwtime),
        HWND hwnd AND UINT umsg AND UINT timer_id AND DWORD dwtime)
 {
@@ -214,22 +216,65 @@ DEFUN (set_timer, (timer_id, first, interval),
   return;
 }
 
-#else /* not 0 */
+#else /* not USE_WM_TIMER */
+\f
+#define TIMER_ID_BASE          0
+
+struct timer_state_s
+{
+  int counter;
+  int reload;
+};
+
+struct timer_state_s scheme_timers[3] = { { 0, 0, }, { 0, 0, }, { 0, 0, } };
+
+extern void EXFUN (low_level_timer_tick, (void));
+
+void
+DEFUN_VOID (low_level_timer_tick)
+{
+  int i;
+  int number_signalled = 0;
+
+  for (i = 0; i < 3; i++)
+    if (scheme_timers[i].counter != 0)
+    {
+      scheme_timers[i].counter -= 1;
+      if (scheme_timers[i].counter == 0)
+      {
+       scheme_timers[i].counter = scheme_timers[i].reload;
+       number_signalled += 1;
+      }
+    }
+
+  if (number_signalled != 0)
+    REQUEST_INTERRUPT (INT_Timer);
+  return;
+}
 
 static void
 DEFUN (set_timer, (timer_id, first, interval),
        int timer_id AND clock_t first AND clock_t interval)
 {
+  struct timer_state_s * timer = &scheme_timers[timer_id];
+
+  /* Round up. */ 
+  timer->counter = ((first + 49) / 50);
+  timer->reload = ((interval + 49) / 50);
   return;
 }
 
 static void
 DEFUN (clear_timer, (timer_id), int timer_id)
 {
+  struct timer_state_s * timer = &scheme_timers[timer_id];
+
+  timer->counter = 0;
+  timer->reload = 0;
   return;
 }
 
-#endif /* 0 */
+#endif /* USE_WM_TIMER */
 \f
 void
 DEFUN (OS_process_timer_set, (first, interval),
index 15092e4fcecb6d0553ff84ffb4d9c41ba18eecec..8cdb4ff83575294de44ea6ebf1c48cb0e4439fb5 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: ntgui.c,v 1.7 1993/09/01 18:34:46 gjr Exp $
+$Id: ntgui.c,v 1.8 1993/09/03 17:56:44 gjr Exp $
 
 Copyright (c) 1993 Massachusetts Institute of Technology
 
@@ -197,9 +197,14 @@ nt_gui_high_priority_poll (void)
 
   if (PeekMessage (&close_msg,
                   master_tty_window,
+#if 0
                   WM_HOTKEY,
                   (WM_HOTKEY + 1),
-                  PM_NOREMOVE))
+#else
+                  WM_CLOSE,
+                  (WM_CLOSE + 1),
+#endif
+                  PM_REMOVE))
   {
     MIT_TranslateMessage (&close_msg);
     DispatchMessage (&close_msg);
@@ -211,6 +216,10 @@ DEFINE_PRIMITIVE ("MICROCODE-POLL-INTERRUPT-HANDLER",
                   Prim_microcode_poll_interrupt_handler, 2, 2,
                  "NT High-priority timer interrupt handler for Windows I/O.")
 {
+#ifndef USE_WM_TIMER
+  extern void low_level_timer_tick (void);
+#endif
+
   PRIMITIVE_HEADER (2);
   if (((ARG_REF (1)) & (ARG_REF (2)) & INT_Global_GC) != 0)
   {
@@ -220,6 +229,9 @@ DEFINE_PRIMITIVE ("MICROCODE-POLL-INTERRUPT-HANDLER",
   else
   {
     nt_gui_default_poll ();
+#ifndef USE_WM_TIMER
+    low_level_timer_tick ();
+#endif
     CLEAR_INTERRUPT (INT_Global_1);
   }
   PRIMITIVE_RETURN (UNSPECIFIC);
index df9a33abc8cd99f44edfdab5b76162ecaf86462e..fd3a005ccb21060890117f042b80e43d9bb63f25 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: ntscreen.h,v 1.6 1993/09/01 18:47:24 gjr Exp $
+$Id: ntscreen.h,v 1.7 1993/09/03 17:57:40 gjr Exp $
 
 Copyright (c) 1993 Massachusetts Institute of Technology
 
@@ -157,8 +157,9 @@ void  Screen_SetMode (HANDLE, int);
 int   Screen_GetMode (HANDLE);
 void  Screen_GetSize (HANDLE, int *rows, int *columns);
 
-BOOL  Screen_GetEvent (HANDLE, SCREEN_EVENT*); // return false on no events
-
+// The following return false on no events
+BOOL  Screen_GetEvent (HANDLE, SCREEN_EVENT *);
+BOOL  Screen_PeekEvent (HANDLE, SCREEN_EVENT *);
 
 //---------------------------------------------------------------------------
 //  Messages
@@ -250,7 +251,9 @@ typedef LRESULT (*COMMAND_HANDLER)(HWND,WORD command);
 #define SCREEN_COMMAND_CLOSE           0x401
 #define SCREEN_COMMAND_CHOOSEBACKCOLOR 0x402
 
-extern VOID init_MIT_TranslateMessage (VOID);
+// Do user-level timer interrupts by using WM_TIMER
+
+#define USE_WM_TIMER
 
 //---------------------------------------------------------------------------
 //  End of File: screen.h
index a7d6d4bcc672118ab9ce56188077eedd24b9e045..93f98c3852ea8713db5da5c2765cb05b338551aa 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Id: ntsig.c,v 1.8 1993/09/01 18:44:09 gjr Exp $
+$Id: ntsig.c,v 1.9 1993/09/03 18:02:29 gjr Exp $
 
 Copyright (c) 1992-1993 Massachusetts Institute of Technology
 
@@ -47,7 +47,6 @@ MIT in each case. */
 #include "ntsys.h"
 #include "ntio.h"
 #include "extern.h"
-#include "ntutil.h"
 #include "ntscreen.h"
 #include "ntscmlib.h"
 \f
@@ -424,8 +423,7 @@ DEFUN_VOID (install_timer)
                                     REGBLOCK_INT_CODE,
                                     REGBLOCK_INT_MASK,
                                     (INT_Global_GC
-                                     | INT_Global_1
-                                     | INT_Timer),
+                                     | INT_Global_1),
                                     &timer_state))
   {
     case WIN32_ASYNC_TIMER_OK: