/************************************************************************************* * * File Operations.c * * This file contains the routines for the module operations. * *************************************************************************************/ #include "AcquireInterface.h" #include "LG-3 Module.h" extern TGlobals myGlobals; extern TMInfo myTMInfo; extern int myTaskDone; /* The following routine displays the about box for the module */ int DoAbout (void) { int item; DialogPtr myDialogPtr; DialogTHndl myDialogTHndl; myDialogTHndl = (DialogTHndl) GetResource ('DLOG', AboutDialogID); HNoPurge ((Handle) myDialogTHndl); CenterDialog (myDialogTHndl); myDialogPtr = GetNewDialog (AboutDialogID, nil, (DialogPtr) -1); ModalDialog (nil, &item); DisposDialog (myDialogPtr); HPurge ((Handle) myDialogTHndl); return noErr; } /* The following routine reduces the memory set aside for the module if possible */ int DoPrepare (AcquireRecordPtr myRecPtr) { if (myRecPtr->maxData > MemoryNeeded) myRecPtr->maxData = MemoryNeeded; return noErr; } /* The following routine determines image parameters and informs the host */ int DoStart (AcquireRecordPtr myRecPtr, long *dataPtr) { int width, height, item; int widthType, heightType, hookType, radioType; int topType, bottomType, toggleType; int done, live; Rect widthBox, heightBox, hookBox, radioBox; Rect topBox, bottomBox, toggleBox; Str255 widthString, heightString; Handle widthText, heightText, hookHandle, radioHandle; DialogPtr myDialogPtr; DialogTHndl myDialogTHndl; ControlHandle topScroll, bottomScroll, toggleButton; width = myGlobals.width; height = myGlobals.height; myDialogTHndl = (DialogTHndl) GetResource ('DLOG', VideoDialogID); HNoPurge ((Handle) myDialogTHndl); CenterDialog (myDialogTHndl); myDialogPtr = GetNewDialog (VideoDialogID, nil, (DialogPtr) -1); GetDItem (myDialogPtr, HookID, &hookType, &hookHandle, &hookBox); SetDItem (myDialogPtr, HookID, hookType, &OutlineOK, &hookBox); GetDItem (myDialogPtr, WidthID, &widthType, &widthText, &widthBox); GetDItem (myDialogPtr, HeightID, &heightType, &heightText, &heightBox); NumToString (width, widthString); NumToString (height, heightString); SetIText (widthText, widthString); SetIText (heightText, heightString); SelIText (myDialogPtr, WidthID, 0, 32767); GetDItem (myDialogPtr, Source1ID, &radioType, &radioHandle, &radioBox); if (myGlobals.source == 0) SetCtlValue(radioHandle, 1); else SetCtlValue(radioHandle, 0); GetDItem (myDialogPtr, Source2ID, &radioType, &radioHandle, &radioBox); if (myGlobals.source == 1) SetCtlValue(radioHandle, 1); else SetCtlValue(radioHandle, 0); GetDItem (myDialogPtr, Source3ID, &radioType, &radioHandle, &radioBox); if (myGlobals.source == 2) SetCtlValue(radioHandle, 1); else SetCtlValue(radioHandle, 0); GetDItem (myDialogPtr, Source4ID, &radioType, &radioHandle, &radioBox); if (myGlobals.source == 3) SetCtlValue(radioHandle, 1); else SetCtlValue(radioHandle, 0); GetDItem (myDialogPtr, TopID, &topType, &topScroll, &topBox); GetDItem (myDialogPtr, BottomID, &bottomType, &bottomScroll, &bottomBox); SetCtlValue (topScroll, 255 - myGlobals.top); SetCtlValue (bottomScroll, 255 - myGlobals.bottom); GetDItem (myDialogPtr, ToggleID, &toggleType, &toggleButton, &toggleBox); SetCTitle (toggleButton, "\pStart"); done = 0; live = 0; myTaskDone = 0; do { ModalDialog ((ModalFilterProcPtr) MyEventFilter, &item); switch (item) { case OK: GetIText (widthText, widthString); if (!ConvertString (widthString, &width, 0)) { SelIText (myDialogPtr, WidthID, 0, 32767); SysBeep (1); break; } GetIText (heightText, heightString); if (!ConvertString (heightString, &height, 1)) { SelIText (myDialogPtr, HeightID, 0, 32767); SysBeep (1); break; } done = 1; break; case Cancel: done = 1; break; case ToggleID: if (live) { myTaskDone = 0; RemoveTMTask (); live = 0; SetCTitle (toggleButton, "\pStart"); } else { myTaskDone = 0; InstallTMTask (); PrimeTime (&myTMInfo, 250L); live = 1; SetCTitle (toggleButton, "\pStop"); } break; case Source1ID: GetDItem (myDialogPtr, Source1ID, &radioType, &radioHandle, &radioBox); SetCtlValue (radioHandle, 1); GetDItem (myDialogPtr, Source2ID, &radioType, &radioHandle, &radioBox); SetCtlValue (radioHandle, 0); GetDItem (myDialogPtr, Source3ID, &radioType, &radioHandle, &radioBox); SetCtlValue (radioHandle, 0); GetDItem (myDialogPtr, Source4ID, &radioType, &radioHandle, &radioBox); SetCtlValue (radioHandle, 0); myGlobals.source = 0; break; case Source2ID: GetDItem (myDialogPtr, Source1ID, &radioType, &radioHandle, &radioBox); SetCtlValue (radioHandle, 0); GetDItem (myDialogPtr, Source2ID, &radioType, &radioHandle, &radioBox); SetCtlValue (radioHandle, 1); GetDItem (myDialogPtr, Source3ID, &radioType, &radioHandle, &radioBox); SetCtlValue (radioHandle, 0); GetDItem (myDialogPtr, Source4ID, &radioType, &radioHandle, &radioBox); SetCtlValue (radioHandle, 0); myGlobals.source = 1; break; case Source3ID: GetDItem (myDialogPtr, Source1ID, &radioType, &radioHandle, &radioBox); SetCtlValue (radioHandle, 0); GetDItem (myDialogPtr, Source2ID, &radioType, &radioHandle, &radioBox); SetCtlValue (radioHandle, 0); GetDItem (myDialogPtr, Source3ID, &radioType, &radioHandle, &radioBox); SetCtlValue (radioHandle, 1); GetDItem (myDialogPtr, Source4ID, &radioType, &radioHandle, &radioBox); SetCtlValue (radioHandle, 0); myGlobals.source = 2; break; case Source4ID: GetDItem (myDialogPtr, Source1ID, &radioType, &radioHandle, &radioBox); SetCtlValue (radioHandle, 0); GetDItem (myDialogPtr, Source2ID, &radioType, &radioHandle, &radioBox); SetCtlValue (radioHandle, 0); GetDItem (myDialogPtr, Source3ID, &radioType, &radioHandle, &radioBox); SetCtlValue (radioHandle, 0); GetDItem (myDialogPtr, Source4ID, &radioType, &radioHandle, &radioBox); SetCtlValue (radioHandle, 1); myGlobals.source = 3; break; } } while (!done); if (live) RemoveTMTask (); DisposDialog (myDialogPtr); HPurge ((Handle) myDialogTHndl); myRecPtr->imageMode = 1; myRecPtr->imageSize.h = width; myRecPtr->imageSize.v = height; myRecPtr->depth = 8; myRecPtr->planes = 1; myRecPtr->data = nil; if (item == Cancel) width = 0; myGlobals.width = width; myGlobals.height = height; if (item == OK) StorePrefs (); return noErr; } /* The following routine returns the data to the host */ int DoContinue (AcquireRecordPtr myRecPtr, long *dataPtr) { int width, height, slot; long base, xOffset, yOffset; Ptr start; if (myRecPtr->data) { myRecPtr->data = nil; return noErr; } slot = FindBoard (); if (!slot) return acquireNoScanner; width = myGlobals.width; height = myGlobals.height; if (!width) return 1; base = 0xf0000000 + (slot * 0x01100000); ResetBoard (base, 1); if (!GetFrame (base)) return acquireScannerProblem; xOffset = 320 - (width / 2); yOffset = 240 - (height / 2); start = (Ptr) (base + (1024 * yOffset) + xOffset); SetRect (&myRecPtr->theRect, 0, 0, width, height); myRecPtr->loPlane = 0; myRecPtr->hiPlane = 0; myRecPtr->colBytes = 1; myRecPtr->rowBytes = 1024; myRecPtr->data = start; return noErr; } /* The following routine clears the permanent variables */ int DoFinish (long *dataPtr) { *dataPtr = 0; return noErr; }