From: Guillermo J. Rozas Date: Fri, 3 Sep 1993 18:02:29 +0000 (+0000) Subject: Redo timers to use the Windows WM_TIMER mechanism. X-Git-Tag: 20090517-FFI~7902 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=6b0c7913d1fb53359252aa03d493fc3fe4df7667;p=mit-scheme.git Redo timers to use the Windows WM_TIMER mechanism. --- diff --git a/v7/src/microcode/ntenv.c b/v7/src/microcode/ntenv.c index d8c103189..85e1d11a4 100644 --- a/v7/src/microcode/ntenv.c +++ b/v7/src/microcode/ntenv.c @@ -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 +#include "ntscreen.h" #include #include @@ -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; } -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 */ + +#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 */ void DEFUN (OS_process_timer_set, (first, interval), diff --git a/v7/src/microcode/ntgui.c b/v7/src/microcode/ntgui.c index 15092e4fc..8cdb4ff83 100644 --- a/v7/src/microcode/ntgui.c +++ b/v7/src/microcode/ntgui.c @@ -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); diff --git a/v7/src/microcode/ntscreen.h b/v7/src/microcode/ntscreen.h index df9a33abc..fd3a005cc 100644 --- a/v7/src/microcode/ntscreen.h +++ b/v7/src/microcode/ntscreen.h @@ -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 diff --git a/v7/src/microcode/ntsig.c b/v7/src/microcode/ntsig.c index a7d6d4bcc..93f98c385 100644 --- a/v7/src/microcode/ntsig.c +++ b/v7/src/microcode/ntsig.c @@ -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" @@ -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: