
* This code contains the routines that are called instead of the normal *
* Rom routines. 							*
* Special action is performed either before or after the normal Rom	*
* code. 								*
*									*
* This code is rather heavy but it works.				*

   include 'include:exec/types.i'

GADGETDOWN	EQU	$00000020
GADGETUP	EQU	$00000040

   xref  _Hook
   xdef  _OWentry_point
   xdef  _CWentry_point
   xdef  _MIentry_point
   xdef  _PMentry_point

   STRUCTURE   HK,0
   LONG   HK_BASE
   LONG   HK_SYSFUNC
   LONG   HK_MYFUNC
   LONG   HK_ENTRY
   LONG   HK_LVO

regboys   reg  d1/d2/d3/d5/a0/a1/a2/a3/a4/a5/a6

_OWentry_point: 		       ; entry point for OpenWindow()
   movem.l  regboys,-(sp)
   lea	    _Hook,a3

   move.l   HK_SYSFUNC(a3),a5
   jsr	    (a5)

   move.l   d0,-(sp)
   move.l   HK_MYFUNC(a3),a5
   jsr	    (a5)
   move.l   (sp)+,d0

   movem.l  (sp)+,regboys
   rts

_CWentry_point: 		       ; entry point for CloseWindow()
   movem.l  regboys,-(sp)
   lea	    _Hook+20,a3

   move.l   a0,-(sp)
   move.l   HK_MYFUNC(a3),a5
   jsr	    (a5)
   move.l   (sp)+,a0

   move.l   HK_SYSFUNC(a3),a5
   jsr	    (a5)

   movem.l  (sp)+,regboys
   rts

_MIentry_point: 		       ; entry point for ModifyIDCMP()
   movem.l  regboys,-(sp)
   lea	    _Hook+40,a3

   ori.l    #GADGETDOWN,d0
   ori.l    #GADGETUP,d0
   move.l   HK_SYSFUNC(a3),a5
   jsr	    (a5)

   movem.l  (sp)+,regboys
   rts

_PMentry_point: 		       ; entry point for PutMsg()
   movem.l  regboys,-(sp)
   lea	    _Hook+60,a3

   movem.l  regboys,-(sp)
   move.l   a1,-(sp)
   move.l   a0,-(sp)
   move.l   HK_MYFUNC(a3),a5
   jsr	    (a5)
   adda.w   #8,sp
   movem.l  (sp)+,regboys

   tst.l    d0
   bne.b    done

   move.l   HK_SYSFUNC(a3),a5
   jsr	    (a5)

done:
   movem.l  (sp)+,regboys
   rts

   end
