home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright © 1993-1997 Fabrizio Oddone
- ••• ••• ••• ••• ••• ••• ••• ••• ••• •••
- This source code is distributed as freeware:
- you may copy, exchange, modify this code.
- You may include this code in any kind of application: freeware,
- shareware, or commercial, provided that full credits are given.
- You may not sell or distribute this code for profit.
- */
-
-
- #include "UtilsSys7.h"
- #include "FabWList.h"
- #include "Independents.h"
- #include "SimResIDs.h"
-
- #include "Disasm.h"
- #include "DoEditDialog.h"
- #include "Globals.h"
- #include "Main.h"
- #include "Registers.h"
- #include "DragManSim.h"
- #include "SimUtils.h"
-
- #if defined(FabSystem7orlater)
-
- enum {
- kREGFONT = 128
- };
-
-
- /* CLRRECT: makes a Rect an empty Rect */
- #define CLRRECT(r) (*(long *)&r = 0, *(long *)((Ptr)&r + 2) = 0)
-
- static ControlHandle Ctrl_Base;
- static short regLineHeight;
- static short regDistFromTop;
- static short regVertSepLine;
- static short oldChoice;
-
- static void Do_A_Button(ControlHandle theControl);
-
-
- #pragma segment Init
- /* Init_Registers: initializes the Registers window */
-
- OSErr Init_Registers(void)
- {
- Str255 tempS;
- FMetricRec theMetrics;
- Rect tempRect;
- FabWindowPtr thefabw;
- WindowPtr w;
- Handle myStrHandle;
- RgnHandle theRgn;
- Fixed tempFixed;
- short fontNumber, fontSize;
- short theWidth, i;
- short maxLength = 0;
- OSErr err = appMemFullErr;
-
- gWPtr_Registers = w = GetNewWindow(kWIND_Registers, nil, (WindowPtr)-1L);
- if (w) {
- SetPortWindowPort(w);
- if (gPrefs.remembWind)
- if (IsOnScreenWeak(gPrefs.RegsTopLeft))
- MoveWindow(w, gPrefs.RegsTopLeft.h, gPrefs.RegsTopLeft.v, false);
- (void)WantThisHandleSafe(myStrHandle = Get1Resource('REGF', kREGFONT));
- if (myStrHandle && GetFontNumber((StringPtr)(*myStrHandle + 2), &fontNumber)) {
- fontSize = *(short *)*myStrHandle;
- }
- else {
- fontNumber = monaco;
- fontSize = 9;
- }
- if (myStrHandle)
- ReleaseResource(myStrHandle);
-
- TextFont(fontNumber);
- TextSize(fontSize);
- if (Ctrl_Base = GetNewControl(kCNTL_RegsBase, w)) {
- FontMetrics(&theMetrics);
- tempFixed = theMetrics.descent + theMetrics.ascent + theMetrics.leading;
-
- tempFixed = mySwap(tempFixed);
-
- regLineHeight = (short)tempFixed;
-
- regDistFromTop = *(short *)&theMetrics.ascent + kREG_HORZSEPLINE;
- HLock(myStrHandle = Get1Resource('STR#', kREG_NAMES));
- for(i = 0; i < kDISP_REGS; i++) {
- if (maxLength < (theWidth = StringWidth(GetPtrIndHString(myStrHandle, i))))
- maxLength = theWidth;
- }
- HUnlock(myStrHandle);
- tempFixed = maxLength;
- regVertSepLine = maxLength + kDIST_FROMLEFT + kDIST_FROMNAME;
-
- tempFixed = mySwap(tempFixed);
-
- maxLength = 0;
- {
- register Byte *myString;
- register Byte j, rememberedCh, stopAt;
- SignedByte savedState;
-
- savedState = WantThisHandleSafe(myStrHandle = (Handle)GetString(kSTR_BINALLOWED));
- myString = (Byte *)*myStrHandle;
- for (stopAt = *myString++, j = 0; j < stopAt; j++)
- if (maxLength < (theWidth = CharWidth(*myString++))) {
- maxLength = theWidth;
- rememberedCh = *(myString - 1);
- }
- HSetState(myStrHandle, savedState);
- for (myString = (Byte *)&tempS, j = 0; j <= 15; j++)
- *myString++ = rememberedCh;
- maxLength = TextWidth(&tempS, 0, 16);
- }
-
- tempFixed += ((long)maxLength << 16) +
- ((const long)(kDIST_FROMLEFT + kDIST_FROMNAME + kDIST_FROMVERTSEP)<< 16);
- tempFixed = mySwap(tempFixed);
- SizeWindow(w, (short)tempFixed + 2,
- REG_TOP + regLineHeight * kDISP_REGS, false);
- SetControlValue(Ctrl_Base, gPrefs.remembWind ? gPrefs.RegsBase : kPOP_HEX);
- oldChoice = GetControlValue(Ctrl_Base);
-
- // InitFabWindow((FabWindowPtr)w);
- thefabw = AddWindowToList(w);
- SetUpdate(thefabw, Update_Registers);
- SetGoAway(thefabw, CloseRegisters);
- SetContent(thefabw, Do_Registers);
- SetGetDragRect(thefabw, getDragRectRegs);
-
- theRgn = NewRgn();
- tempRect = (*Ctrl_Base)->contrlRect;
- RectRgn(theRgn, &tempRect);
- InstallRgnHandler(thefabw, theRgn, nil, nil,
- toMenu(kBalloons_Regs, kBRegs_Base), 0, 0);
-
- tempRect.top = REG_TOP;
- tempRect.left = PRCT_L(w);
- tempRect.bottom = REG_TOP + regLineHeight;
- tempRect.right = PRCT_R(w);
- for (i = kBRegs_PC; i <= kBRegs_Lo8; i++) {
- theRgn = NewRgn();
- RectRgn(theRgn, &tempRect);
- InstallRgnHandler(thefabw, theRgn, nil, nil,
- toMenu(kBalloons_Regs, i), 0, 0);
- tempRect.top = tempRect.bottom;
- tempRect.bottom += regLineHeight;
- }
- // no resizable objects for this window
- // ResizeObjects(w);
-
- RecalcGlobalCoords(thefabw);
- if (gDragManagerActive)
- (void) MyInstallHWindow(w);
-
- err = noErr;
- }
- }
- //SetFractEnable(false);
- return err;
- }
-
-
- #pragma segment Main
-
- short GetRegistersBase(void)
- {
- return GetControlValue(Ctrl_Base);
- }
-
- void Update_Registers(WindowPtr w, short)
- {
- Str255 sTemp;
- register Handle tempH;
- register short i,j;
-
- EraseRect(&w->portRect);
- HLockHi(tempH = Get1Resource('STR#', kREG_NAMES));
- for(i = 0, j = regDistFromTop; i <= kDISP_REGS - 1; i++, j += regLineHeight) {
- MoveTo(REG_LEFT + kDIST_FROMLEFT, j);
- DrawString((ConstStr255Param)GetPtrIndHString(tempH, i));
- MoveTo(REG_LEFT + regVertSepLine + kDIST_FROMVERTSEP + 1, j);
- FromNumToString(sTemp, gRegs[i], oldChoice);
- DrawString(sTemp);
- }
- HUnlock(tempH);
- /* Draw the horizontal line */
- MoveTo(REG_LEFT, kREG_HORZSEPLINE);
- LineTo(REG_RIGHT, kREG_HORZSEPLINE);
- /* Draw the vertical line */
- MoveTo(regVertSepLine, REG_TOP);
- LineTo(regVertSepLine, REG_BOTTOM - 1);
- UpdateControls(w, w->visRgn);
- }
-
- void Do_Registers(WindowPtr w, EventRecord *theEvent)
- {
- Rect tempRect, oldRect, shiftingRect;
- Point myPt;
- ControlHandle theControl;
- register short code;
- register Boolean inbigrect;
-
- myPt = theEvent->where;
- GlobalToLocal(&myPt);
- if (FindControl(myPt, w, &theControl) != 0) {
- if (TrackControl(theControl, myPt, (ControlActionUPP)-1L) == kControlLabelPart)
- if ((code = GetControlValue(Ctrl_Base)) != oldChoice) {
- oldChoice = code;
- tempRect.top = REG_TOP;
- tempRect.left = REG_LEFT + regVertSepLine + 1;
- tempRect.bottom = REG_BOTTOM;
- tempRect.right = REG_RIGHT;
- InvalRect(&tempRect);
- }
- }
- else {
- tempRect.top = REG_TOP;
- tempRect.left = REG_LEFT;
- tempRect.bottom = REG_BOTTOM;
- tempRect.right = REG_RIGHT;
- if (PtInRect(myPt, &tempRect)){
- CLRRECT(oldRect);
- do {
- GetMouse(&myPt);
- if (!PtInRect(myPt, &oldRect)) {
- if (inbigrect = PtInRect(myPt, &tempRect)) {
- shiftingRect.top = REG_TOP;
- shiftingRect.left = REG_LEFT;
- shiftingRect.bottom = REG_TOP + regLineHeight;
- shiftingRect.right = REG_RIGHT;
- for(code = kREG_PC;
- !(PtInRect(myPt, &shiftingRect)&&(code <= kREG_LOW8));
- code++, shiftingRect.top += regLineHeight,
- shiftingRect.bottom += regLineHeight)
- ;
- InvertRect(&oldRect);
- InvertRect(&shiftingRect);
- oldRect = shiftingRect;
- }
- else {
- InvertRect(&oldRect);
- CLRRECT(oldRect);
- }
- }
- }
- while( StillDown() );
- if (inbigrect) {
- InvertRect(&oldRect);
- if(DoEditDialog(code, kREG_EXTNAMES, oldChoice)) {
- oldRect.left += regVertSepLine+1;
- InvalRect(&oldRect);
- if (code == kREG_PC)
- InvalDisasm();
- }
- UnloadSeg(DoEditDialog);
- }
- }
- }
- }
-
- /* ChangedRegister: to tell us that a register has changed its value */
-
- void ChangedRegister(short whichreg)
- {
- Rect tempRect;
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort(gWPtr_Registers);
- tempRect.top = REG_TOP + (regLineHeight * whichreg);
- tempRect.left = REG_LEFT + regVertSepLine+1;
- tempRect.bottom = tempRect.top + regLineHeight;
- tempRect.right = REG_RIGHT;
- InvalRect(&tempRect);
- if (whichreg == kREG_PC)
- InvalDisasm();
- SetPort(savePort);
- }
-
- /* ChangedAllRegisters: to tell us that _all_ registers have changed */
-
- void ChangedAllRegisters(void)
- {
- Rect tempRect;
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPortWindowPort(gWPtr_Registers);
- tempRect.top = REG_TOP;
- tempRect.left = REG_LEFT + regVertSepLine+1;
- tempRect.bottom = tempRect.top + (regLineHeight * kREG_ZERO);
- tempRect.right = REG_RIGHT;
- InvalRect(&tempRect);
- InvalDisasm();
- SetPort(savePort);
- }
-
- /* procedure called when closing the Registers window */
-
- void CloseRegisters(WindowPtr w)
- {
- DoCloseWindow(w, kMItem_Registers);
- }
-
- void getDragRectRegs(WindowPtr w, RectPtr r)
- {
- *r = w->portRect;
- }
-
- #endif
-
-