revert between 56095 -> 55830 in arch
[AROS.git] / workbench / devs / diskimage / include / SDI_interrupt.h
blob1a66be0dd5f5d745ce88d9c7eabdba3ddfe61807
1 #ifndef SDI_INTERRUPT_H
2 #define SDI_INTERRUPT_H
4 /* Includeheader
6 Name: SDI_interrupt.h
7 Versionstring: $VER: SDI_interrupt.h 1.1 (25.04.2006)
8 Author: Guido Mersmann
9 Distribution: PD
10 Project page: http://www.sf.net/projects/sditools/
11 Description: defines to hide compiler specific interrupt and
12 handler stuff
14 1.0 17.05.05 : inspired by the SDI_#?.h files made by Jens Langner
15 and Dirk Stöcker I created files to handle interrupt
16 and handler functions in an API compatible way.
17 1.1 25.04.06 : fixed MakeInterrupt() and MakeHandler() macro. (geit)
22 ** This is PD (Public Domain). This means you can do with it whatever you want
23 ** without any restrictions. I only ask you to tell me improvements, so I may
24 ** fix the main line of this files as well.
26 ** To keep confusion level low: When changing this file, please note it in
27 ** above history list and indicate that the change was not made by myself
28 ** (e.g. add your name or nick name).
30 ** Find the latest version of this file at:
31 ** http://cvs.sourceforge.net/viewcvs.py/sditools/sditools/headers/
33 ** Guido Mersmann <geit@gmx.de>
37 #include "SDI_compiler.h"
40 ** The INTERRUPTPROTO macro is for creating interrupts functions and the
41 ** HANDLERPROTO macro is for handler type setup like used by the
42 ** input.device.
44 ** The usage is simular to the DISPATCHERPROTO macro provided by SDI_hook.h.
46 ** It gets the function name as argument. To supply this function for use by
47 ** an interrupt structure or handler argument, use the ENTRY macro, which also
48 ** gets the function name as argument. There is also a MakeInterrupt and a
49 ** MakeHandler macro for easy structure setup.
51 ** Example:
53 ** We create a handler function for the input.device.
55 ** HANDLERPROTO( handlerfunc, ULONG, struct InputEvent *inputevent, APTR userdata)
56 ** {
57 ** ... Modify/parse input stream here
58 ** ...
59 ** return( (ULONG) inputevent );
60 ** }
61 ** MakeHandler( handlerstruct, handlerfunc, "TestHandler", &our_user_data);
63 ** As you can see usage is as simple as using SDI hooks. To create interrupt
64 ** use INTERRUPTPROTO and MakeInterrupt. Internally both macros are identically.
66 ** There are also functions to create more specific interrupt and handler
67 ** structures. By default type is NT_INTERRUPT and priority is 0.
69 ** MakeHandlerType - additional argument for type
70 ** MakeHandlerPri - additional argument for pri
71 ** MakeHandlerTypePri - additional arguments for type and pri
74 ** Notes: Since the interrupt structure is used for handlers and also foreign
75 ** handlers are using this structure I keeped the arguments definition
76 ** on the user side.
80 #ifdef __MORPHOS__
82 #ifndef SDI_TRAP_LIB /* avoid defining this twice */
84 #include <proto/alib.h>
85 #include <emul/emulregs.h>
87 #define SDI_TRAP_LIB 0xFF00 /* SDI prefix to reduce conflicts */
89 struct SDI_EmulLibEntry
91 UWORD Trap;
92 UWORD pad;
93 APTR Func;
95 #endif
97 #define INTERRUPTPROTO(name, ret, obj, data) \
98 SAVEDS ASM ret name( obj, data); \
99 static ret Trampoline_##name(void) {return name(( obj) REG_A0, \
100 (data) REG_A1);} \
101 static const struct SDI_EmulLibEntry Gate_##name = {SDI_TRAP_LIB, 0, \
102 (APTR) Trampoline_##name}; \
103 SAVEDS ASM ret name( obj, data)
105 #define HANDLERPROTO(name, ret, obj, data) \
106 SAVEDS ASM ret name( obj, data); \
107 static ret Trampoline_##name(void) {return name(( obj) REG_A0, \
108 (data) REG_A1);} \
109 static const struct SDI_EmulLibEntry Gate_##name = {SDI_TRAP_LIB, 0, \
110 (APTR) Trampoline_##name}; \
111 SAVEDS ASM ret name( obj, data)
113 #define ENTRY(func) (APTR)&Gate_##func
115 #else
117 #define INTERRUPTPROTO(name, ret, obj, data) \
118 SAVEDS ASM ret name(REG(a0, obj), REG(a1, data))
119 #define HANDLERPROTO(name, ret, obj, data) \
120 SAVEDS ASM ret name(REG(a0, obj), REG(a1, data))
122 #define ENTRY(func) (APTR)func
124 #endif /* __MORPHOS__ */
126 /* some structure creating macros for easy and more specific usage */
128 #define MakeInterrupt( name, func, title, isdata ) \
129 static struct Interrupt name = {{ NULL, NULL, NT_INTERRUPT, 0, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) }
131 #define MakeInterruptPri( name, func, title, isdata, pri ) \
132 static struct Interrupt name = {{ NULL, NULL, NT_INTERRUPT, pri, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) }
134 #define MakeInterruptType( name, func, title, isdata, type ) \
135 static struct Interrupt name = {{ NULL, NULL, type, 0, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) }
137 #define MakeInterruptTypePri( name, func, title, isdata, type, pri ) \
138 static struct Interrupt name = {{ NULL, NULL, type, pri, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) }
140 #define MakeHandler( name, func, title, isdata ) \
141 static struct Interrupt name = {{ NULL, NULL, NT_INTERRUPT, 0, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) }
143 #define MakeHandlerPri( name, func, title, isdata, pri ) \
144 static struct Interrupt name = {{ NULL, NULL, NT_INTERRUPT, pri, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) }
146 #define MakeHandlerType( name, func, title, isdata, type ) \
147 static struct Interrupt name = {{ NULL, NULL, type, 0, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) }
149 #define MakeHandlerTypePri( name, func, title, isdata, type, pri ) \
150 static struct Interrupt name = {{ NULL, NULL, type, pri, (STRPTR) title}, (APTR) isdata, (void (*)()) ENTRY(func) }
153 #endif /* SDI_INTERRUPT_H */