home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / code / microema.sit / src / croot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-09  |  2.8 KB  |  119 lines  |  [TEXT/Earl]

  1. /*
  2.  * Main entry point for MicroEmacs for the Macintosh.  With MPW C,
  3.  * this routine is set up as the main entry point, and placed in the
  4.  * same segment as _DataInit().  It calls _DataInit() to initialize
  5.  * the a5-based data, then sets up the size of the application heap,
  6.  * and jumps to the real main routine.  The main routine unloads this
  7.  * segment, and all active segments are loaded into high memory, thus
  8.  * reducing heap fragmentation.  In addition, we lose _RTInit(),
  9.  * _RTExit(), and exit(), thus saving about 1k of code.
  10.  * 
  11.  * We do not use library routines with MPW, since we want to set up
  12.  * the app heap before any other 'CODE' segments are loaded.  Thus
  13.  * the inlines.
  14.  *
  15.  * With the Aztec compiler, we do not gain as much as we do with
  16.  * MPW C, since the data is in 'CODE' #1, but we do gain some
  17.  * since we still get to call MaxApplZone() before library routines.
  18.  * 
  19.  * Under LightSpeed, the utility of doing things this way is
  20.  * questionable, but it probably doesn't hurt.
  21.  */
  22. #ifdef macintosh
  23. #define MPWC
  24. #define MPW_COMPATIBLE
  25. #else
  26. #ifndef MPU68000
  27. #define LSC
  28. #else
  29. #define MPW_COMPATIBLE
  30. #endif
  31. #endif
  32. #ifdef MPW_COMPATIBLE
  33. #include <Resources.h>
  34. #include <QuickDraw.h>
  35. #include <Menus.h>
  36. #include <Fonts.h>
  37. #include <TextEdit.h>
  38. #include <Scrap.h>
  39. #include <Windows.h>
  40. #include <Dialogs.h>
  41. #define THEPORT qd.thePort
  42. #endif
  43. #ifdef LSC
  44. #include <ResourceMgr.h>
  45. #include <QuickDraw.h>
  46. #include <FontMgr.h>
  47. #include <WindowMgr.h>
  48. #include <MenuMgr.h>
  49. #include <DialogMgr.h>
  50. #define THEPORT thePort
  51. #endif
  52. #ifdef MPWC
  53. pascal void PopA0(adr)
  54. char *adr;
  55. extern 0x205f;        /* move.l    (a7)+,a0 */
  56. pascal void _SetApplLimit()
  57. extern 0xA02D;
  58. pascal void romMaxApplZone()
  59. extern 0xA063;
  60. pascal void JMPA0()    /* jmp    (a0) */
  61. extern 0x4ED0;
  62. pascal void UNLKA6()    /* unlk    a6 */
  63. extern 0x4E5E;
  64. #define SetApplLimit(a) PopA0(a);_SetApplLimit();
  65. #define jump(a) PopA0(a);JMPA0();
  66. #define __SEG__ %A5Init
  67. #endif
  68. #ifdef MPU68000
  69. pascal void romMaxApplZone() = 0xA063;
  70. #endif
  71. #ifdef LSC
  72. #define Croot main
  73. #endif
  74. #ifndef IS_64K_ROM
  75. #define IS_64K_ROM    ((*((short *) 0x28E) & 0xF000) == 0xF000)
  76. #endif
  77. Croot()                                   /* <<-- Entry. */
  78. {
  79.     int i;
  80.     extern maineventloop();
  81.     extern exit();
  82. #ifdef MPWC
  83.     _DataInit();           /* All after this is defined as InLine macros. */
  84. #endif
  85.     ReleaseResource(GetResource('CODE',0));
  86. #ifdef MPU68000
  87. #asm        /* LightSpeed C stinks! */
  88.     lea    -20480(a7),a0
  89.     dc.w    $a02d    ; SetApplLimit
  90. #endasm
  91. #else
  92.     SetApplLimit((char *)&i- 20480);          /* Program needs stack! */
  93. #endif
  94. #ifdef MPW_COMPATIBLE
  95.     if(IS_64K_ROM){
  96.         MaxApplZone();
  97.     }else{
  98.         romMaxApplZone();                /* Heap, too! */
  99.     }
  100. #else
  101.     MaxApplZone();
  102. #endif
  103.     InitGraf(&THEPORT);
  104.     InitFonts();
  105.     InitWindows();
  106.     InitMenus();
  107.     TEInit();
  108.     InitDialogs(exit);
  109.     InitCursor();
  110.     LoadScrap();
  111. #ifdef MPWC
  112.     UNLKA6();                         /* Fix up stack. */
  113.     jump(maineventloop);                     /* Bye, bye. */
  114. #else
  115.     maineventloop();
  116. #endif
  117. }
  118.  
  119.