2 * MMSYTEM time functions
4 * Copyright 1993 Martin Ayotte
20 #include "selectors.h"
24 static BOOL mmTimeStarted
= FALSE
;
25 static MMTIME mmSysTimeMS
;
26 static MMTIME mmSysTimeSMPTE
;
28 typedef struct tagTIMERENTRY
{
37 struct tagTIMERENTRY
*Next
;
38 struct tagTIMERENTRY
*Prev
;
39 } TIMERENTRY
, *LPTIMERENTRY
;
41 static LPTIMERENTRY lpTimerList
= NULL
;
43 /**************************************************************************
44 * MMSysTimeCallback [internal]
46 WORD
MMSysTimeCallback(HWND hWnd
, WORD wMsg
, INT nID
, DWORD dwTime
)
48 LPTIMERENTRY lpTimer
= lpTimerList
;
49 mmSysTimeMS
.u
.ms
+= 33;
50 mmSysTimeSMPTE
.u
.smpte
.frame
++;
51 while (lpTimer
!= NULL
) {
53 if (lpTimer
->wCurTime
== 0) {
54 lpTimer
->wCurTime
= lpTimer
->wDelay
;
55 if (lpTimer
->lpFunc
!= (FARPROC
) NULL
) {
56 dprintf_mmtime(stddeb
, "MMSysTimeCallback // before CallBack16 !\n");
57 dprintf_mmtime(stddeb
, "MMSysTimeCallback // lpFunc=%08lx wTimerID=%04X dwUser=%08lX !\n",
58 lpTimer
->lpFunc
, lpTimer
->wTimerID
, lpTimer
->dwUser
);
59 dprintf_mmtime(stddeb
, "MMSysTimeCallback // hInstance=%04X !\n", lpTimer
->hInstance
);
61 /* This is wrong (lpFunc is NULL all the time)
63 lpFunc = MODULE_GetEntryPoint( lpTimer->hInstance,
64 MODULE_GetOrdinal(lpTimer->hInstance,"TimerCallBack" ));
65 dprintf_mmtime(stddeb, "MMSysTimeCallback // lpFunc=%08lx !\n", lpFunc);
69 /* - TimeProc callback that is called here is something strange, under Windows 3.1x it is called
70 * during interrupt time, is allowed to execute very limited number of API calls (like
71 * PostMessage), and must reside in DLL (therefore uses stack of active application). So I
72 * guess current implementation via SetTimer has to be improved upon.
75 CallTo16_word_wwlll(lpTimer
->lpFunc
,
76 lpTimer
->hInstance
, lpTimer
->wTimerID
,
77 0, lpTimer
->dwUser
, 0, 0);
79 dprintf_mmtime(stddeb
, "MMSysTimeCallback // after CallBack16 !\n");
82 if (lpTimer
->wFlags
& TIME_ONESHOT
)
83 timeKillEvent(lpTimer
->wTimerID
);
85 lpTimer
= lpTimer
->Next
;
90 /**************************************************************************
91 * StartMMTime [internal]
97 mmSysTimeMS
.wType
= TIME_MS
;
99 mmSysTimeSMPTE
.wType
= TIME_SMPTE
;
100 mmSysTimeSMPTE
.u
.smpte
.hour
= 0;
101 mmSysTimeSMPTE
.u
.smpte
.min
= 0;
102 mmSysTimeSMPTE
.u
.smpte
.sec
= 0;
103 mmSysTimeSMPTE
.u
.smpte
.frame
= 0;
104 mmSysTimeSMPTE
.u
.smpte
.fps
= 0;
105 mmSysTimeSMPTE
.u
.smpte
.dummy
= 0;
106 SetTimer(0, 1, 33, GetWndProcEntry16("MMSysTimeCallback"));
110 /**************************************************************************
111 * timeGetSystemTime [MMSYSTEM.601]
113 WORD
timeGetSystemTime(LPMMTIME lpTime
, WORD wSize
)
115 dprintf_mmsys(stddeb
, "timeGetSystemTime(%p, %u);\n", lpTime
, wSize
);
121 /**************************************************************************
122 * timeSetEvent [MMSYSTEM.602]
124 WORD
timeSetEvent(WORD wDelay
, WORD wResol
, LPTIMECALLBACK lpFunc
,
125 DWORD dwUser
, WORD wFlags
)
128 LPTIMERENTRY lpNewTimer
;
129 LPTIMERENTRY lpTimer
= lpTimerList
;
130 dprintf_mmtime(stddeb
, "timeSetEvent(%u, %u, %p, %08lX, %04X);\n",
131 wDelay
, wResol
, lpFunc
, dwUser
, wFlags
);
134 lpNewTimer
= (LPTIMERENTRY
) malloc(sizeof(TIMERENTRY
));
135 if (lpNewTimer
== NULL
)
137 while (lpTimer
!= NULL
) {
138 wNewID
= MAX(wNewID
, lpTimer
->wTimerID
);
139 if (lpTimer
->Next
== NULL
)
141 lpTimer
= lpTimer
->Next
;
143 if (lpTimerList
== NULL
) {
144 lpTimerList
= lpNewTimer
;
145 lpNewTimer
->Prev
= NULL
;
147 lpTimer
->Next
= lpNewTimer
;
148 lpNewTimer
->Prev
= lpTimer
;
150 lpNewTimer
->Next
= NULL
;
151 lpNewTimer
->wTimerID
= wNewID
+ 1;
152 lpNewTimer
->wCurTime
= wDelay
;
153 lpNewTimer
->wDelay
= wDelay
;
154 lpNewTimer
->wResol
= wResol
;
155 lpNewTimer
->lpFunc
= (FARPROC
) lpFunc
;
156 lpNewTimer
->hInstance
= GetTaskDS();
157 dprintf_mmtime(stddeb
, "timeSetEvent // hInstance=%04X !\n", lpNewTimer
->hInstance
);
158 dprintf_mmtime(stddeb
, "timeSetEvent // PTR_SEG_TO_LIN(lpFunc)=%p !\n",
159 PTR_SEG_TO_LIN(lpFunc
));
160 lpNewTimer
->dwUser
= dwUser
;
161 lpNewTimer
->wFlags
= wFlags
;
162 return lpNewTimer
->wTimerID
;
165 /**************************************************************************
166 * timeKillEvent [MMSYSTEM.603]
168 WORD
timeKillEvent(WORD wID
)
170 LPTIMERENTRY lpTimer
= lpTimerList
;
171 while (lpTimer
!= NULL
) {
172 if (wID
== lpTimer
->wTimerID
) {
173 if (lpTimer
->Prev
!= NULL
)
174 lpTimer
->Prev
->Next
= lpTimer
->Next
;
175 if (lpTimer
->Next
!= NULL
)
176 lpTimer
->Next
->Prev
= lpTimer
->Prev
;
180 lpTimer
= lpTimer
->Next
;
185 /**************************************************************************
186 * timeGetDevCaps [MMSYSTEM.604]
188 WORD
timeGetDevCaps(LPTIMECAPS lpCaps
, WORD wSize
)
190 dprintf_mmsys(stddeb
, "timeGetDevCaps(%p, %u) !\n", lpCaps
, wSize
);
194 /**************************************************************************
195 * timeBeginPeriod [MMSYSTEM.605]
197 WORD
timeBeginPeriod(WORD wPeriod
)
199 dprintf_mmsys(stddeb
, "timeBeginPeriod(%u) !\n", wPeriod
);
205 /**************************************************************************
206 * timeEndPeriod [MMSYSTEM.606]
208 WORD
timeEndPeriod(WORD wPeriod
)
210 dprintf_mmsys(stddeb
, "timeEndPeriod(%u) !\n", wPeriod
);
214 /**************************************************************************
215 * timeGetTime [MMSYSTEM.607]
219 dprintf_mmsys(stddeb
, "timeGetTime(); !\n");