home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / µSim 1.0.5 / source / Main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-06  |  17.5 KB  |  716 lines  |  [TEXT/CWIE]

  1. /*
  2. Copyright © 1993,1994,1995 Fabrizio Oddone
  3. ••• ••• ••• ••• ••• ••• ••• ••• ••• •••
  4. This source code is distributed as freeware:
  5. you may copy, exchange, modify this code.
  6. You may include this code in any kind of application: freeware,
  7. shareware, or commercial, provided that full credits are given.
  8. You may not sell or distribute this code for profit.
  9. */
  10.  
  11. //#pragma load "MacDump"
  12.  
  13. #include    "UtilsSys7.h"
  14. #include    "CursorBalloon.h"
  15. #include    "FabTaskManager.h"
  16. #include    "FabWList.h"
  17. #include    "FabLibResIDs.h"
  18.  
  19. #include    "AEHandlers.h"
  20. #include    "ControlStore.h"
  21. #include    "Disasm.h"
  22. #include    "Dump.h"
  23. #include    "DoMenu.h"
  24. #include    "Globals.h"
  25. #include    "InitMenus.h"
  26. #include    "Input.h"
  27. #include    "Main.h"
  28. #include    "Microprogram_Ed.h"
  29. #include    "Preferences.h"
  30. #include    "Simulator.h"
  31. #include    "SimUtils.h"
  32.  
  33. #if defined(FabSystem7orlater)
  34.  
  35. #pragma segment Main
  36.  
  37. //extern void _DATAINIT(void);
  38.  
  39. static void DoDiskEvent(void);
  40. static void MyZoom(WindowPtr whichWindow, short code);
  41. static Boolean CheckTheStack(void);
  42. static void AvoidMenuSelections(void);
  43. static void WantMenuSelections(void);
  44. static void AEErrorAlert(OSErr reason);
  45.  
  46. void main(void);
  47.  
  48.  
  49. /* DomyKeyEvent: we got a key down, of course */
  50.  
  51. void DomyKeyEvent(EventRecord *evt)
  52. {
  53. enum {
  54. kUndoKey = 0x7A10,
  55. kCutKey = 0x7810,
  56. kCopyKey = 0x6310,
  57. kPasteKey = 0x7610,
  58. kHelpKey = 0x7205,
  59. kFwdDel = 0x757F,
  60. kHomeKey = 0x7301,
  61. kEndKey = 0x7704,
  62. kPgUpKey = 0x740B,
  63. kPgDnKey = 0x790C,
  64. kClearKey = 0x471B,
  65. kEnterKey = 0x4C03
  66. };
  67.  
  68. register WindowPtr    frontW;
  69. register short    txtStart;
  70. register unsigned char    ch;
  71.  
  72. frontW = FrontWindow();
  73. ch = CHARFROMMESSAGE(evt->message);
  74. if (evt->modifiers & cmdKey) {
  75.     AdjustMenus(gTheInput);
  76.     Handle_My_Menu(MenuKey(ch));
  77.     }
  78. else {
  79.     switch ((unsigned short)evt->message) {
  80.         case kUndoKey    :    Handle_My_Menu((kRes_Menu_Edit << 16) + kMItem_Undo);
  81.             break;
  82.         case kCutKey    :    Handle_My_Menu((kRes_Menu_Edit << 16) + kMItem_Cut);
  83.             if (gWPtr_Microprogram_Ed == frontW)
  84.                 Key_Microprogram_Ed(evt, true);
  85.             break;
  86.         case kCopyKey    :    Handle_My_Menu((kRes_Menu_Edit << 16) + kMItem_Copy);
  87.             break;
  88.         case kPasteKey    :    Handle_My_Menu((kRes_Menu_Edit << 16) + kMItem_Paste);
  89.             if (gWPtr_Microprogram_Ed == frontW)
  90.                 Key_Microprogram_Ed(evt, true);
  91.             break;
  92.         case kHelpKey    :    (void)HMSetBalloons(1 - HMGetBalloons());
  93.                             RecalcMouseRegion(frontW, evt->where);
  94.             break;
  95.         case kFwdDel    :
  96.             if (gTheInput) {
  97.                 if ((txtStart = (*gTheInput)->selStart) == (*gTheInput)->selEnd)
  98.                     TESetSelect(txtStart, txtStart + 1, gTheInput);
  99.                 TEDelete(gTheInput);
  100.                 if (gWPtr_Microprogram_Ed == frontW)
  101.                     Key_Microprogram_Ed(evt, true);
  102.                 }
  103.             break;
  104.         case kClearKey    :
  105.             if (gTheInput) {
  106.                 TEDelete(gTheInput);
  107.                 if (gWPtr_Microprogram_Ed == frontW)
  108.                     Key_Microprogram_Ed(evt, true);
  109.                 }
  110.             break;
  111.         case kHomeKey    :
  112.             if (gWPtr_Dump == frontW)
  113.                 DumpHome();
  114.             else if (gWPtr_Disasm == frontW)
  115.                 DisasmHome();
  116.             else if (gWPtr_IO == frontW)
  117.                 IOHome();
  118.             break;
  119.         case kEndKey    :
  120.             if (gWPtr_Dump == frontW)
  121.                 DumpEnd();
  122.             else if (gWPtr_Disasm == frontW)
  123.                 DisasmEnd();
  124.             else if (gWPtr_IO == frontW)
  125.                 IOEnd();
  126.             break;
  127.         case kPgUpKey    :
  128.             if (gWPtr_Dump == frontW)
  129.                 DumpPgUp();
  130.             else if (gWPtr_Disasm == frontW)
  131.                 DisasmPgUp();
  132.             else if (gWPtr_IO == frontW)
  133.                 IOPgUp();
  134.             break;
  135.         case kPgDnKey    :
  136.             if (gWPtr_Dump == frontW)
  137.                 DumpPgDn();
  138.             else if (gWPtr_Disasm == frontW)
  139.                 DisasmPgDn();
  140.             else if (gWPtr_IO == frontW)
  141.                 IOPgDn();
  142.             break;
  143.         case kEnterKey:
  144.             if (gTheInput) {
  145.                 TESelView(gTheInput);
  146.                 if (gWPtr_IO == frontW)
  147.                     AdjustScrollbars(frontW, false);
  148.                 }
  149.             break;
  150.         default:
  151.             if (gWPtr_Microprogram_Ed == frontW)
  152.                 Key_Microprogram_Ed(evt, false);
  153.             else
  154.                 DoKeyDown(frontW, ch, true);
  155.         }
  156.     }
  157. }
  158.  
  159. /* DoDiskEvent: checks for inserted disks */
  160.  
  161. void DoDiskEvent(void)
  162. {
  163. if (HiWrd(gMyEvent.message)) {
  164. //    myEvent.where.h = ((qd.screenBits.bounds.right - qd.screenBits.bounds.left)>>1) - (304 / 2);
  165. //    myEvent.where.v = ((qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) / 3) - (104 / 2);
  166.     InitCursor();
  167.     DILoad();
  168.     (void)DIBadMount(gMyEvent.where, gMyEvent.message);
  169.     DIUnload();
  170.     }
  171. }
  172.  
  173. /* DoZoom: a window was zoomed */
  174.  
  175. void MyZoom(WindowPtr whichWindow, short code)
  176. {
  177. Rect    globalPortRect, theSect, zoomRect;
  178. GDHandle    nthDevice, dominantGDevice;
  179. register RectPtr    rectP;
  180. long    sectArea, greatestArea;
  181. short    bias;
  182.  
  183. /* theEvent is a global EventRecord from the main event loop */
  184. /* savePort is a global GrafPtr for scratch */
  185.  
  186. EraseRect(&whichWindow->portRect);
  187.  
  188. /* If there is the possibility of multiple gDevices, then we */
  189. /* must check them to make sure we are zooming onto the right */
  190. /* display device when zooming out. */
  191. if ((code == inZoomOut) && gHasColorQD) {
  192.     /* window's portRect must be converted to global coordinates */
  193.     globalPortRect = whichWindow->portRect;
  194.     LocalToGlobal(&topLeft(globalPortRect));
  195.     LocalToGlobal(&botRight(globalPortRect));
  196.     /* must calculate height of window's title bar */
  197.     bias = globalPortRect.top - 1 - (*((WindowPeek)whichWindow)->strucRgn)->rgnBBox.top;
  198.     nthDevice = GetDeviceList();
  199.     greatestArea = 0;
  200.     /* This loop checks the window against all the gdRects in the */
  201.     /* gDevice list and remembers which gdRect contains the largest */
  202.     /* portion of the window being zoomed. */
  203.     while (nthDevice) {
  204.         (void)SectRect(&globalPortRect, &(*nthDevice)->gdRect, &theSect);
  205.         sectArea = (theSect.right - theSect.left) * (long)(theSect.bottom - theSect.top);
  206.         if (sectArea > greatestArea) {
  207.             greatestArea = sectArea;
  208.             dominantGDevice = nthDevice;
  209.             }
  210.         nthDevice = GetNextDevice(nthDevice);
  211.         }
  212.     /* We must create a zoom rectangle manually in this case. */
  213.     /* account for menu bar height as well, if on main device */
  214.     if (dominantGDevice == GetMainDevice())
  215.         bias += GetMBarHeight();
  216.     rectP = &(*dominantGDevice)->gdRect;
  217.     zoomRect.top = rectP->top + bias + 3;
  218.     zoomRect.left = rectP->left + 3;
  219.     zoomRect.bottom = rectP->bottom - 3;
  220.     zoomRect.right = rectP->right - 3;
  221.     /* Set up the WStateData record for this window. */
  222.     (*(WStateDataHandle)((WindowPeek)whichWindow)->dataHandle)->stdState = zoomRect;
  223.     }
  224. ZoomWindow(whichWindow, code, true);
  225. }
  226.  
  227. /* DoCloseWindow: a window must be closed */
  228.  
  229. void DoCloseWindow(WindowPtr w, short whichMenuItem)
  230. {
  231. HideWindow(w);
  232. CheckItem(gMenu_Windows, whichMenuItem, false);
  233. }
  234.  
  235.  
  236. void DoUpdate(EventRecord *passEvt)
  237. {
  238. GrafPtr        savePort;
  239. FabWindowPtr    thefabw;
  240. register WindowPtr    w;
  241. register void (*theProc)(WindowPtr);
  242.  
  243. GetPort(&savePort);
  244. SetPort(w = (WindowPtr)passEvt->message);
  245. BeginUpdate(w);
  246. if (thefabw = GetFabWindowPtr(w)) {
  247.     theProc = thefabw->updateProc;
  248.     if (theProc)
  249.         theProc(w);
  250.     }
  251. EndUpdate(w);
  252. SetPort(savePort);
  253. }
  254.  
  255. void DoActivate(EventRecord *passEvt)
  256. {
  257. register WindowPtr    whichWindow;
  258.  
  259. whichWindow = (WindowPtr)passEvt->message;
  260. DecideActivation(passEvt, whichWindow, passEvt->where, passEvt->modifiers & activeFlag);
  261. }
  262.  
  263. /* DecideActivation: common routine because of activate and
  264. suspend&resume events */
  265.  
  266. void DecideActivation(EventRecord *evt, WindowPtr w, Point mouseGlob, Boolean active)
  267. {
  268. GrafPtr    savePort;
  269. FabWindowPtr    thefabw;
  270. register void (*theActivProc)(EventRecord *, WindowPtr, Boolean);
  271.  
  272. GetPort(&savePort);
  273. SetPort(w);
  274.  
  275. if (thefabw = GetFabWindowPtr(w)) {
  276.     theActivProc = thefabw->activateProc;
  277.     if (theActivProc)
  278.         theActivProc(evt, w, active);
  279.     }
  280. if (active) {
  281.     RecalcMouseRegion(w, mouseGlob);
  282.     }
  283. SetPort(savePort);
  284. }
  285.  
  286. void DoOSEvent(EventRecord *passEvt)
  287. {
  288. register WindowPtr    frontW = FrontWindow();
  289. register Boolean    willbeActive;
  290.  
  291. if ((*(Byte *)&passEvt->message) == suspendResumeMessage) {
  292.     InitCursor();
  293.     if (willbeActive = (CHARFROMMESSAGE(passEvt->message) & resumeFlag)) {
  294.         /* resume */
  295.         gInTheForeground = true;
  296.         if (CHARFROMMESSAGE(passEvt->message) & convertClipboardFlag)
  297.             (void)TEFromScrap();
  298.         }
  299.     else {
  300.         /* suspend */
  301.         gInTheForeground = false;
  302.         }
  303.     if (frontW)
  304.         DecideActivation(passEvt, frontW, passEvt->where, willbeActive);
  305.     }
  306.  
  307. else if ((*(Byte *)&passEvt->message) == mouseMovedMessage) {
  308.         RecalcMouseRegion(frontW, passEvt->where);
  309.         }
  310. }
  311.  
  312. void DoHighLevelEvent(EventRecord *evt)
  313. {
  314. OSErr    err;
  315.  
  316. err = AEProcessAppleEvent(evt);
  317. if (err)
  318.     if (err != userCanceledErr && err != errAEEventNotHandled) {
  319.         AEErrorAlert(err);
  320.         UnloadSeg(AEErrorAlert);
  321.         }
  322. }
  323.  
  324. void main(void)
  325. {
  326. GrafPtr        savePort;
  327. FabWindowPtr    thefabw;
  328. WindowPtr    w;
  329. register void (*theProc)(WindowPtr);
  330. register void (*theDoGrowProc)(WindowPtr, EventRecord *);
  331. register RectPtr    wStateP;
  332. register short    code;
  333.  
  334. MaxApplZone();
  335. //UnloadSeg(_DATAINIT);
  336. InitAll();
  337. UnloadSeg(InitAll);
  338. do {
  339. if (gRstatus)
  340.     gSleep = 0L;
  341. else if (gInTheForeground && gTheInput && ((*gTheInput)->selStart == (*gTheInput)->selEnd))
  342.     gSleep = LMGetCaretTime();
  343. else
  344.     gSleep = ULONG_MAX;
  345.  
  346.     if (WaitNextEvent(everyEvent, &gMyEvent, gSleep, mouseRgn)) {
  347.         switch (gMyEvent.what) {
  348.             case nullEvent :
  349.                 DoIdle();
  350.             case mouseDown :
  351.                 code = FindWindow(gMyEvent.where, &w);
  352.                 switch (code) {
  353.                     case inMenuBar :
  354.                         AdjustMenus(gTheInput);
  355.                         Handle_My_Menu(MenuSelect(gMyEvent.where));
  356.                         break;
  357.                     case inDrag :
  358.                         DragWindow(w, gMyEvent.where, &qd.screenBits.bounds);
  359.                         GetPort(&savePort);
  360.                         SetPort(w);
  361.                         if (((WindowPeek)w)->spareFlag) {
  362.                             wStateP = &(*(WStateDataHandle)((WindowPeek)w)->dataHandle)->userState;
  363.                             *wStateP = w->portRect;
  364.                             LocalToGlobal(&topLeft(*wStateP));
  365.                             LocalToGlobal(&botRight(*wStateP));
  366.                             }
  367.                         if (thefabw = GetFabWindowPtr(w)) {
  368.                             theProc = thefabw->dragProc;
  369.                             if (theProc)
  370.                                 theProc(w);
  371.                             RecalcGlobalCoords(thefabw);
  372.                             }
  373.                         (void) EventAvail(0, &gMyEvent);
  374.                         RecalcMouseRegion(w, gMyEvent.where);
  375.                         SetPort(savePort);
  376.                         break;
  377.                     case inGrow :
  378.                         GetPort(&savePort);
  379.                         SetPort(w);
  380.                         if (thefabw = GetFabWindowPtr(w)) {
  381.                             theDoGrowProc = thefabw->growProc;
  382.                             if (theDoGrowProc)
  383.                                 theDoGrowProc(w, &gMyEvent);
  384.                             ResizeObjects(w);
  385.                             RecalcGlobalCoords(thefabw);
  386.                             }
  387.                         (void) EventAvail(0, &gMyEvent);
  388.                         RecalcMouseRegion(w, gMyEvent.where);
  389.                         SetPort(savePort);
  390.                         break;
  391.                     case inZoomIn :
  392.                     case inZoomOut :
  393.                         GetPort(&savePort);
  394.                         SetPort(w);
  395.                         if (TrackBox(w, gMyEvent.where, code)) {
  396.                             MyZoom(w, code);
  397.                             
  398.                             if (thefabw = GetFabWindowPtr(w)) {
  399.                                 theProc = thefabw->zoomProc;
  400.                                 if (theProc)
  401.                                     theProc(w);
  402.                                 ResizeObjects(w);
  403.                                 RecalcGlobalCoords(thefabw);
  404.                                 }
  405.                             }
  406.                         (void) EventAvail(0, &gMyEvent);
  407.                         RecalcMouseRegion(w, gMyEvent.where);
  408.                         SetPort(savePort);
  409.                         break;
  410.                     case inGoAway :
  411.                         if (TrackGoAway(w, gMyEvent.where)) {
  412.                             if (thefabw = GetFabWindowPtr(w)) {
  413.                                 theProc = thefabw->goAwayProc;
  414.                                 if (theProc)
  415.                                     theProc(w);
  416.                                 }
  417.                             }
  418.                         break;
  419.                     case inContent :
  420.                         if (w != FrontWindow()) 
  421.                             SelectWindow(w);
  422.                         else {
  423.                             if (thefabw = GetFabWindowPtr(w)) {
  424.                                 GetPort(&savePort);
  425.                                 SetPort(w);
  426.                                 theDoGrowProc = thefabw->contentProc;
  427.                                 if (theDoGrowProc)
  428.                                     theDoGrowProc(w, &gMyEvent);
  429.                                 SetPort(savePort);
  430.                                 }
  431.                             }
  432.                         break;
  433.                     case inSysWindow :
  434.                         SystemClick(&gMyEvent, w);
  435.                         break;
  436.                     }
  437.                 break;
  438.             case keyDown:
  439.             case autoKey:
  440.                 DomyKeyEvent(&gMyEvent);
  441.                 break;
  442.             case updateEvt :
  443.                 DoUpdate(&gMyEvent);
  444.                 break;
  445.             case diskEvt :
  446.                 DoDiskEvent();
  447.                 break;
  448.             case activateEvt :
  449.                 DoActivate(&gMyEvent);
  450.                 break;
  451.             case osEvt :
  452.                 DoOSEvent(&gMyEvent);
  453.                 break;
  454.             case kHighLevelEvent:
  455.                 DoHighLevelEvent(&gMyEvent);
  456.                 break;
  457.             }
  458.         }
  459.     else
  460.         DoIdle();
  461.     }
  462. while (gDoneFlag == false);
  463. SavePreferencesFile();
  464. CleanUp();
  465. }
  466.  
  467. /* DoIdle: so that we have something to do while the user has nothing to do */
  468.  
  469. void DoIdle(void)
  470. {
  471. enum {
  472. kMIN_COMPUTE = 5L
  473. };
  474.  
  475. long    tickc;
  476. Boolean    stackProblems;
  477.  
  478. CheckCallQueue();
  479. if (gInTheForeground)
  480.     if (gTheInput)
  481.         TEIdle(gTheInput);
  482.  
  483. if (gRstatus) {
  484.     if (CheckTheStack() == false) {
  485.         if (gPwrManagerIsPresent)
  486.             (void)IdleUpdate();
  487.         switch (gRstatus) {
  488.             case kST_GOING:
  489.                 tickc = TickCount();
  490.                 do {
  491.                     ExecuteInstructionsGO();
  492.                     stackProblems = CheckTheStack();
  493.                     }
  494.                 while ((TickCount() - tickc < kMIN_COMPUTE) && (stackProblems == false));
  495.                 break;
  496.             case kST_STEPASM:
  497.                 ExecuteInstructionsGO();
  498.                 StopIt();
  499.                 break;
  500.             case kST_STEPMPROG:
  501.                 ExecuteInstructions(gSubclk++);
  502.                 gSubclk &= 3;
  503.                 if (gSubclk == 0)
  504.                     gRstatus = kST_STOPPED;
  505.                 break;
  506.             case kST_STEPSUBCYC:
  507.                 ExecuteInstructions(gSubclk++);
  508.                 gSubclk &= 3;
  509.                 gRstatus = kST_STOPPED;
  510.                 break;
  511.             }
  512.         }
  513.     }
  514. }
  515.  
  516. Boolean CheckTheStack(void)
  517. {
  518. Boolean    result = true;
  519.  
  520. if ((unsigned short)gRegs[kREG_SP] > gPrefs.DefSPValue) {
  521.     if (gRegs[kREG_PC] == kPCExitToShell)
  522.         (void)NoteAlert_AE(kALRT_TOSHELL, myStdFilterProcNoCancel, myIdleFunct);
  523.     else
  524.         (void)StopAlert_AE(kALRT_STKUNDERFLOW, myStdFilterProcNoCancel, myIdleFunct);
  525.     StopIt();
  526.     }
  527. else if ((unsigned short)gRegs[kREG_SP] < (gPrefs.DefSPValue - gPrefs.DefStkSize)) {
  528.     (void)StopAlert_AE(kALRT_STKOVERFLOW, myStdFilterProcNoCancel, myIdleFunct);
  529.     StopIt();
  530.     }
  531. else
  532.     result = false;
  533. return result;
  534. }
  535.  
  536. /* AdjustMenus: we set the menus before MenuSelect or MenuKey */
  537.  
  538. void AdjustMenus(TEHandle activeTE)
  539. {
  540. register WindowPtr    window;
  541. long    offset;
  542. Boolean    undo = false;
  543. Boolean    cutCopyClear = false;
  544. Boolean    paste = false;
  545. Boolean    selectAll = false;
  546. Boolean    insertdelete = false;
  547. Boolean    go = false;
  548. Boolean    step = false;
  549. Boolean    stop = false;
  550.  
  551. if (window = FrontWindow()) {
  552.     if ( ISDAWINDOW(window) ) {
  553.         undo = true;                /* all editing is enabled for DA windows */
  554.         cutCopyClear = true;
  555.         paste = true;
  556.         }
  557.     else if ( ISAPPWINDOW(window) || isMovableModal(window)) {
  558.     /* Cut, Copy, and Clear is enabled for appl. windows with selections */
  559.         if (activeTE) {
  560.             selectAll = true;
  561.             if ( (*activeTE)->selStart < (*activeTE)->selEnd )
  562.                 cutCopyClear = true;
  563.             }
  564.  
  565.         if ((window == gWPtr_Microprogram_Ed) && (keyDownDest == kKEY_LIST)) {
  566.             cutCopyClear = true;
  567.             if (theSelection[kL_COMMENTS] != maxLLine[kL_COMMENTS])
  568.                 insertdelete = true;
  569.             }
  570.     /* if there’s any text in the clipboard, paste is enabled */
  571.         if ((GetScrap(nil, 'TEXT', &offset)  > 0) &&
  572.             (activeTE || (window == gWPtr_Microprogram_Ed && keyDownDest == kKEY_LIST)))
  573.             paste = true;
  574.         }
  575.     if ( undo )
  576.         EnableItem(gMenu_Edit, kMItem_Undo);
  577.     else
  578.         DisableItem(gMenu_Edit, kMItem_Undo);
  579.     if ( cutCopyClear ) {
  580.         EnableItem(gMenu_Edit, kMItem_Cut);
  581.         EnableItem(gMenu_Edit, kMItem_Copy);
  582.         EnableItem(gMenu_Edit, kMItem_Clear);
  583.         }
  584.     else {
  585.         DisableItem(gMenu_Edit, kMItem_Cut);
  586.         DisableItem(gMenu_Edit, kMItem_Copy);
  587.         DisableItem(gMenu_Edit, kMItem_Clear);
  588.         }
  589.     if ( paste )
  590.         EnableItem(gMenu_Edit, kMItem_Paste);
  591.     else
  592.         DisableItem(gMenu_Edit, kMItem_Paste);
  593.     if ( selectAll )
  594.         EnableItem(gMenu_Edit, kMItem_Select_All);
  595.     else
  596.         DisableItem(gMenu_Edit, kMItem_Select_All);
  597.     if ( insertdelete ) {
  598.         EnableItem(gMenu_Edit, kMItem_Insert);
  599.         EnableItem(gMenu_Edit, kMItem_Delete);
  600.         }
  601.     else {
  602.         DisableItem(gMenu_Edit, kMItem_Insert);
  603.         DisableItem(gMenu_Edit, kMItem_Delete);
  604.         }
  605.     if (isMovableModal(window))
  606.         AvoidMenuSelections();
  607.     else
  608.         WantMenuSelections();
  609.     }
  610. else {    /* no windows are open */
  611.     DisableItem(gMenu_Edit, kMItem_Undo);    /* check this when implementing undo */
  612.     DisableItem(gMenu_Edit, kMItem_Cut);
  613.     DisableItem(gMenu_Edit, kMItem_Copy);
  614.     DisableItem(gMenu_Edit, kMItem_Clear);
  615.     DisableItem(gMenu_Edit, kMItem_Paste);
  616.     DisableItem(gMenu_Edit, kMItem_Select_All);
  617.     DisableItem(gMenu_Edit, kMItem_Insert);
  618.     DisableItem(gMenu_Edit, kMItem_Delete);
  619.     WantMenuSelections();
  620.     }
  621.  
  622. if (((WindowPeek)gWPtr_Disasm)->visible)
  623.     EnableItem(gMenu_Control, kMItem_Disasmfrom);
  624. else
  625.     DisableItem(gMenu_Control, kMItem_Disasmfrom);
  626.  
  627. if (((WindowPeek)gWPtr_Dump)->visible)
  628.     EnableItem(gMenu_Control, kMItem_Dumpfrom);
  629. else
  630.     DisableItem(gMenu_Control, kMItem_Dumpfrom);
  631.  
  632. if (DocIsOpen) {
  633.     if (gRstatus == kST_STOPPED) {
  634.         go = true;
  635.         step = true;
  636.         }
  637.     if (gRstatus == kST_GOING) {
  638.         stop = true;
  639.         }
  640.     EnableItem(gMenu_Windows, kMItem_Microprogram);
  641.     EnableItem(gMenu_File, kMItem_Close);
  642.     EnableItem(gMenu_File, kMItem_Save_Control_St2);
  643.     EnableItem(gMenu_File, kMItem_Save_CS_Stationery);
  644.     EnableItem(gMenu_Control, kMItem_SelectCurMPC);
  645.     }
  646. else {
  647.     DisableItem(gMenu_Windows, kMItem_Microprogram);
  648.     DisableItem(gMenu_File, kMItem_Close);
  649.     DisableItem(gMenu_File, kMItem_Save_Control_St2);
  650.     DisableItem(gMenu_File, kMItem_Save_CS_Stationery);
  651.     DisableItem(gMenu_Control, kMItem_SelectCurMPC);
  652.     }
  653. if (go)
  654.     EnableItem(gMenu_Control, kMItem_Go);
  655. else
  656.     DisableItem(gMenu_Control, kMItem_Go);
  657. if (step) {
  658.     EnableItem(gMenu_Control, kMItem_StepSub);
  659.     EnableItem(gMenu_Control, kMItem_StepMicro);
  660.     EnableItem(gMenu_Control, kMItem_StepInstr);
  661.     }
  662. else {
  663.     DisableItem(gMenu_Control, kMItem_StepSub);
  664.     DisableItem(gMenu_Control, kMItem_StepMicro);
  665.     DisableItem(gMenu_Control, kMItem_StepInstr);
  666.     }
  667. if (stop)
  668.     EnableItem(gMenu_Control, kMItem_Stop);
  669. else
  670.     DisableItem(gMenu_Control, kMItem_Stop);
  671. if (gRstatus == kST_GOING) {
  672.     DisableItem(gMenu_Control, kMItem_ResetMem);
  673.     DisableItem(gMenu_Control, kMItem_ResetRegs);
  674.     }
  675. else {
  676.     EnableItem(gMenu_Control, kMItem_ResetMem);
  677.     EnableItem(gMenu_Control, kMItem_ResetRegs);
  678.     }
  679. } /*AdjustMenus*/
  680.  
  681. void AvoidMenuSelections(void)
  682. {
  683. DisableItem(gMenu_File, 0);
  684. DisableItem(gMenu_Apple, 1);
  685. DisableItem(gMenu_Windows, 0);
  686. DisableItem(gMenu_Control, 0);
  687. DisableItem(gMenu_Assembler, 0);
  688. }
  689.  
  690. void WantMenuSelections(void)
  691. {
  692. EnableItem(gMenu_File, 0);
  693. EnableItem(gMenu_Apple, 1);
  694. EnableItem(gMenu_Windows, 0);
  695. EnableItem(gMenu_Control, 0);
  696. EnableItem(gMenu_Assembler, 0);
  697. }
  698.  
  699. #pragma segment Rare
  700.  
  701. /* AEErrorAlert: errors while handling AEvents */
  702.  
  703. static void AEErrorAlert(OSErr reason)
  704. {
  705. Str255    tempS;
  706.  
  707. MyNumToString(reason, tempS);
  708. ParamText(tempS, nil, nil, nil);
  709. (void)StopAlert_UPP(kALRT_AEPROCESSERR, myStdFilterProcNoCancel);
  710. }
  711.  
  712. #pragma segment Main
  713.  
  714. #endif
  715.  
  716.