home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / µSim 1.1 / source / Main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-26  |  17.0 KB  |  728 lines  |  [TEXT/CWIE]

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