home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / GCC / GERLIB_USR08B.LHA / gerlib / support / mui / demo.h
Encoding:
C/C++ Source or Header  |  1993-12-12  |  3.5 KB  |  181 lines

  1. /*************************************************************/
  2. /* Includes and other common stuff for the MUI demo programs */
  3. /*************************************************************/
  4.  
  5. /* MUI */
  6. #include <libraries/mui.h>
  7.  
  8. /* System */
  9. #include <inline/stubs.h>
  10. #include <dos/dos.h>
  11. #include <graphics/gfxmacros.h>
  12. #include <workbench/workbench.h>
  13.  
  14. /* Prototypes */
  15. #include <clib/alib_protos.h>
  16. #include <clib/exec_protos.h>
  17. #include <clib/dos_protos.h>
  18. #include <clib/icon_protos.h>
  19. #include <clib/graphics_protos.h>
  20. #include <clib/intuition_protos.h>
  21. #include <clib/gadtools_protos.h>
  22. #include <clib/muimaster_protos.h>
  23. #include <clib/asl_protos.h>
  24.  
  25. /* ANSI C */
  26. #include <stdlib.h>
  27. #include <string.h>
  28.  
  29. #ifndef __GNUC__
  30. #include <stdio.h>
  31. #endif
  32.  
  33. /* Compiler specific stuff */
  34.  
  35. #ifdef _DCC
  36.  
  37. #define REG(x) __ ## x
  38. #define ASM
  39. #define SAVEDS __geta4
  40.  
  41. #endif
  42.  
  43. #ifdef __GNUC__
  44.  
  45. /* these need some more work */
  46. #define REG(x)
  47. #define ASM
  48. #define SAVEDS
  49.  
  50. /* for normal and base-relative programs */
  51.  
  52. extern void hookEntry(void);        /* Assembler stub that saves the registers (a0,a2,a1) on the stack */
  53. extern void hookEntrya1a2(void);    /* Assembler stub that saves the registers (a2,a1) on the stack */
  54.  
  55. /* for resident programs (does not function yet due to a bug in gcc) */
  56.  
  57. extern void hookEntryRes(void);        /* Assembler stub that saves the registers (a0,a2,a1) on the stack (resident only) */
  58. extern void hookEntryResa1a2(void);    /* Assembler stub that saves the registers (a2,a1) on the stack (resident only) */
  59.  
  60. ULONG aska4(void);                    /* return current a4 */
  61.  
  62. #else
  63.  
  64. #define REG(x) register __ ## x
  65. #define ASM    __asm
  66. #define SAVEDS __saveds
  67.  
  68. #include <pragmas/exec_pragmas.h>
  69. #include <pragmas/dos_pragmas.h>
  70. #include <pragmas/icon_pragmas.h>
  71. #include <pragmas/graphics_pragmas.h>
  72. #include <pragmas/intuition_pragmas.h>
  73. #include <pragmas/gadtools_pragmas.h>
  74. #include <pragmas/muimaster_pragmas.h>
  75. #include <pragmas/asl_pragmas.h>
  76.  
  77. extern struct Library *IntuitionBase,*UtilityBase,*GfxBase,*DOSBase,*IconBase;
  78.  
  79. #endif
  80.  
  81. #ifdef __GNUC__
  82. #include <inline/mui_master.h>
  83. struct Library *IntuitionBase;
  84. /* struct Library *UtilityBase, *GfxBase,*IconBase; */
  85. #endif
  86.  
  87. struct Library *MUIMasterBase;
  88.  
  89.  
  90.  
  91. /*************************/
  92. /* Init & Fail Functions */
  93. /*************************/
  94.  
  95. static VOID fail(APTR app,char *str)
  96. {
  97.     if (app)
  98.         MUI_DisposeObject(app);
  99.  
  100. #ifndef _DCC
  101.     if (MUIMasterBase)
  102.         CloseLibrary(MUIMasterBase);
  103. #endif
  104.  
  105. #ifdef __GNUC__
  106.     if(IntuitionBase) CloseLibrary(IntuitionBase);
  107. /*    if(UtilityBase) CloseLibrary(UtilityBase);
  108.     if(GfxBase) CloseLibrary(GfxBase);
  109.     if(IconBase) CloseLibrary(IconBase); */
  110.  
  111.     if (str)
  112.     {
  113.         PutStr(str);
  114.         PutStr("\n");
  115.     }
  116. #else
  117.     if (str)
  118.     {
  119.         puts(str);
  120.         exit(20);
  121.     }
  122. #endif
  123.  
  124.     exit(0);
  125. }
  126.  
  127.  
  128. #ifdef _DCC
  129.  
  130. int brkfunc(void) { return(0); }
  131.  
  132. int wbmain(struct WBStartup *wb_startup)
  133. {
  134.     extern int main(int argc, char *argv[]);
  135.     return (main(0, NULL));
  136. }
  137.  
  138. #endif
  139.  
  140.  
  141. #ifdef __SASC
  142. int CXBRK(void) { return(0); }
  143. int _CXBRK(void) { return(0); }
  144. void chkabort(void) {}
  145. #endif
  146.  
  147.  
  148. static VOID init(VOID)
  149. {
  150. #ifdef _DCC
  151.     onbreak(brkfunc);
  152. #endif
  153.  
  154. #ifndef _DCC
  155.     if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
  156.         fail(NULL,"Failed to open "MUIMASTER_NAME".");
  157. #endif
  158.  
  159.     if (!(IntuitionBase = OpenLibrary("intuition.library",37)))
  160.         fail(NULL,"Failed to open intuition.library.");
  161.  
  162. }
  163.  
  164.  
  165. #ifndef __SASC
  166. static VOID stccpy(char *dest,char *source,int len)
  167. {
  168.     strncpy(dest,source,len);
  169.     dest[len-1]='\0';
  170. }
  171. #endif
  172.  
  173.  
  174. #ifndef MAKE_ID
  175. #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  176. #endif
  177.  
  178. #ifndef __GNUC__
  179. LONG __stack = 8192;
  180. #endif
  181.