System timer proc thunk creation moved out of if1632/thunk.c.

diff --git a/misc/system.c b/misc/system.c
index 2bdd049..9302671 100644
--- a/misc/system.c
+++ b/misc/system.c
@@ -7,6 +7,9 @@
 #include "wine/winbase16.h"
 #include "wine/winuser16.h"
 #include "services.h"
+#include "callback.h"
+#include "stackframe.h"
+#include "builtin16.h"
 #include "debugtools.h"
 
 DEFAULT_DEBUG_CHANNEL(system)
@@ -119,6 +122,29 @@
     return 0;
 }
 
+static void SYSTEM_CallSystemTimerProc( FARPROC16 proc, WORD timer )
+{
+    CONTEXT86 context;
+    memset( &context, '\0', sizeof(context) );
+
+    CS_reg( &context )  = SELECTOROF( proc );
+    EIP_reg( &context ) = OFFSETOF( proc );
+    EBP_reg( &context ) = OFFSETOF( NtCurrentTeb()->cur_stack )
+                          + (WORD)&((STACK16FRAME*)0)->bp;
+
+    AX_reg( &context ) = timer;
+
+    CallTo16RegisterShort( &context, 0 );
+}
+
+WORD WINAPI WIN16_CreateSystemTimer( WORD rate, FARPROC16 proc )
+{
+    FARPROC thunk = THUNK_Alloc( proc, (RELAY)SYSTEM_CallSystemTimerProc );
+    WORD timer = CreateSystemTimer( rate, (SYSTEMTIMERPROC)thunk );
+    if (!timer) THUNK_Free( thunk );
+    return timer;
+}
+
 
 /***********************************************************************
  *           KillSystemTimer   (SYSTEM.3)
@@ -127,8 +153,12 @@
  */
 WORD WINAPI SYSTEM_KillSystemTimer( WORD timer )
 {
-    if (!timer || (timer > NB_SYS_TIMERS)) return timer;  /* Error */
+    if ( !timer || timer > NB_SYS_TIMERS || !SYS_Timers[timer-1].callback ) 
+        return timer;  /* Error */
+
+    THUNK_Free( (FARPROC)SYS_Timers[timer-1].callback );
     SYS_Timers[timer-1].callback = NULL;
+
     if (!--SYS_NbTimers) SYSTEM_StopTicks();
     return 0;
 }