/* ------------------------------ ue9.c ---------------------------- */

#include "uedit.h"

extern struct RexxMsg  *rexxMsgIn,*rexxReplyMsg;

/* ----------------- MACRO FUNCTION POINTERS ------------------- */

typedef  int	 (*PFA)();

PFA   macroFunc[MAXFCTTOKENS]
= { Fnull,
Fnull, Fnull, Fnull, Fnull, Fnull,
Fnull, Fnull, Fnull, Fnull, Fnull,
Fnull, Fnull, FmouseDown,
FtrackMouse, FupdateDisplay, FinputWaiting, FthisKey, FabortSave,
FrestartPrint, Freformat,
FrunLearn, FfullRefresh, FrefreshDisplay, FabortPrint, Fnull,
Fnull, FbeepDisplay, FseeRuler, FsetRuler,  Fnull,Fnull,

FstopSpell,

#ifdef ISSPELL
FspellerUp,
#endif
#ifndef ISSPELL
spellmsg,
#endif

FhyperClose, FhyperUp, FinTiny, FscreenToBack, FscreenToFront,
FnewFile,

FnameBuffer,	/* these functions have arguments */
FcheckedSubMenu, Fmenu, FcheckedMenu, FsubMenu, FrunKey,
FgtNum,
FincNum, FdecNum, FequateNum, FeqNum, FgeNum,
Fand, For, Fmul, Fdiv, Fadd,
Fsub, Fmod, FmouseXY, FsetRGB, FisEmpty,
FgetSplitLines, FgetChar,
FonScreen, FvScroll, FhScroll, FinsertRgn, FsetEol,
FclearRgn, FswapBuf, Fprint, FloadFile, FinsertFile,
FalertUser, FaskYesNo, FsaveFile, FsetFileName, FgetFileName,
FflipFlag, FgetFlag, Ftoggle, FtoNumber, FtoWord,
FtoUpper, FtoLower, FsetLocal, FhexDecimal, FfileSize,
FlocToLine, FlineToLoc, Fsearch, FsaveLearn, FfreeBuf,
FgetLocal, Fis, FloadLearn, Fquit, FprinterCode,
FsaveConfig, FloadConfig, FmoveCursor, FequateLoc, FincLoc,
FdecLoc, FeqLoc, FgeLoc, FgtLoc, FgetKey,
FinputKey, FswapKey, FkillKey, Fdelay, FeditBuf,
FputMsg, FinputString, FinputNum, FinsertChar, FcopyChar,
FclearChar, FswapChar, FteachOne, Fexecute, Fspeak,
FcopyColData, FclearColData, FgadgetName, FtypeChar, FchangeDir,
FinUse, FsetMaxFiles, FgetMaxFiles, FgetSerialNum, FgetColors,
FlocToIndex, FindexToLoc, FlocToCol, FcolToLoc, FsplitWindow,
FgetTabs, FgetPageRowCol, FgotoPage, FgetKeyVal,

#ifdef ISSPELL
Fspell,  FstartSpell,
#endif
#ifndef ISSPELL
spellmsg,spellmsg,
#endif

FstringComp, FrexxIn, FrexxOut, FloadKeys,
FsaveKeys, Fpush, Fpop, FgetBufAddr, FgetStackSize,
FrollStack, FsetSearch, FattachBuf,FdetachBuf,FcopyKey,
FgotoSplit, FgetSearch, FfileRequest,

#ifdef ISK
Fpeek, Fpoke, FgetAddress,
#endif
#ifndef ISK
Fnull,Fnull,Fnull,
#endif

FupFlag, FdownFlag,
Fnull, Fnull, Fnull,				 /* these map into switch case default */
Ftext, FswapLoc,
Fgrep, FsetGrep, FgetGrep, FsetColors, FhyperOpen, Fhyper, FsaveState, FloadState,
FsetTaskPri, Fdraw,
FsetFont, FsortLines, Fcompile, FcompileDefaults, FgetFont,
FstackBuf, FcompareBuf, Fnull,  /* <--- KEEP THIS Fnull, maps define() */
FclearBuf, FtabsToSpaces, FspacesToTabs,
FgetRGB,Fxor,
Ffold, FsetFold, FgetFold,Fnull,Fnull
};


void	saveSplit(), unsaveSplit();

static ULONG idleSec,idleMic,workSec,workMic;
static short	changedMark = 0;
extern UCHAR	*statePtr;

editWork()  				/* Avoid STATICS ! */
{
register long	count,idleCount;
register short  i,m,rtn;

	if (stopPause) { FRTN: return(FALSE); }
	displayFlag = ALLPAGE;
	switchFast();
	rtn = 0;
	gcol = -1;
	if (primitive==0) {
		/* if (startingUp) - this is GUARANTEED here if prim==0  */
		upMenus();
		args[0] = literal_;
		if (statePtr) {
			stackDepth = 1;
			ptrArgs[0] = statePtr;
			FloadState();
			statePtr = NULL;
			stackDepth = 0;
		}
		if (lcmd!=NULL) {
			ptrArgs[0] = lcmd;
			if (FloadLearn()) FrunLearn();
			lcmd = NULL;
		}
		m = kcmd;
		if (m>0) { kcmd = 0L; FrunKey(m); }
	}
	changedMark = 0;
	while (1) { 			/* don't display unless no keys queued up */
TOP1:
		if (noDisplay && primitive<2) onDisplay();
		cleared = 0;
TOP2:
		m = FALSE;
		idleCount = 0L;
		count = 0L;
TOP3:
		stopPause = FALSE;
TOP4:
		if (!nextEvent()) {
			if (displayFlag) { display(); goto TOP4; }
			if (reportMouse) goto TOP4;
			if (didScroll)
					{ didScroll = 0; displayFlag = (PAGE_ << curSplit); goto TOP4;}
			if (count==0L) setTime(&workSec,&workMic,40L);

			if (curBuf->Flags & CHANGED) {
				if (!changedMark) {
					changedMark = TRUE;
					showTitle = TRUE;
				}
			} else if (changedMark) {
				changedMark = 0;
				showTitle = TRUE;
			}
			if (showTitle) setTitle();
			if (count==0L) setGlobals();

/* --------------- new new new new onAbort_ ------------------ */
			stopPause = FALSE;
			if (primitive<2) {
				if (hadAbort && !clampAbort) {
					clampAbort = TRUE;
					FrunKey(onAbort);
					setGlobals();
					clampAbort = FALSE;
					hadAbort = FALSE;
					goto TOP1;
				}
			}
			if (toTiny) {
				if (!makeTiny()) {
					makeWindow();
					if (edWindow==NULL) badQuit();
				}
			}
			if (tiny) { loopTiny(); goto TOP1; }

			if (FindPort("REXX")) rexxWork();
			if (buffer) freeCompileBuf();
			rmbFlags();
			if (primitive<2) {
				if (rexxMsgIn || rexxReplyMsg) {
					FrunKey(rexxMacro);
					setGlobals();
				}
				if (idleCount++ == 0L) setTime(&idleSec,&idleMic,idleTime);
				if (isTime(idleSec,idleMic)) {
					idleCount = 0L;
					FrunKey(idleMacro);
					setGlobals();
				}
				if (count==1L && !m) {
					cleared = 0;
					updateMenus();
					setGlobals();
					if (rowCol) showRow(TRUE);
				}
			}
			count++;
			if (isTime(workSec,workMic)) {  /* 4 sec housekeep */
				noMemory = FALSE;
				if (AvailMem((long)MEMF_LARGEST) < 10240L) noMemory = TRUE;
				if (!m || noMemory) findMemory(noMemory);
				count = 0L;
				m = TRUE;
			}
			if (!busyWork()) waite();
			goto TOP3;
		}

		i = inputChar;
		m = macroNum;
		if (i==0 && m) gcol = -1;
		count = primitive;
		if (count) {
			if (count==2) {
				if (stopPause) goto FRTN;
				if (i==pmEsc)  return(rtn);
				if (m) goto TOP2;
			} else if (count==1) {
				if (stopPause) {
					primQuit();
					goto TOP1;
				}
				if (i==ESC && inputQualifier==0) return(TRUE);
			}
		}
		if (newSplit!=curSplit) {
			if (count!=2) {
				swapSplit(newSplit); /* sets curBuf, displayFlag, switchFast() */
				FrefreshDisplay();
				restoreMsg();
			}
			newSplit = curSplit;
		}
		if (teachKeys) {
			showKeyHelp(m);
			goto TOP1;
		}
		if (i || m) {
			if (cmdTable[preKeyMacro]!=NULL && count!=2) {
				FrunKey(preKeyMacro);
				m = mcrNum;
				if (m<0 || m>=MAXMACROS) m = 0;
				i = inpChar;
				if (i<0 || i>255) i = 0;
				if (i==0 && m==0) goto TOP1;
			}
			count = 1L;
			if (cmdMultiplier>0L) {
				count = cmdMultiplier;
				cmdMultiplier=0;
				if (primitive==0 && hideDisplay) noDisplay = 1;
			}
			if (i) {
				if (!onScreen(curBuf->Block,curBuf->Ptr)) cursorMid(FALSE);
				if (!canChange(curBuf)) goto TOP1;
				while (count--) {
					if (stop()) { rtn = FALSE; goto TOP1; }
					rtn = insertChar(i);
				}
				goto TOP1;
			}
			/* Guaranteed got M here since no i */
			while (count--) {
				if (stopPause) { rtn = FALSE; goto TOP1; }
				rtn = FrunKey(m);
			}
			goto TOP1;
		} /* else goto TOP2; */ /* gadget release comes here! */
	}
}

void primQuit()
{
register short i;

	stopPause = 0;
	for (i=0; i<MAXFILES; i++) {
		if (buf[i] && (buf[i]->Flags & CHANGED)) {
			if (!yesNo("Save changes before quitting?","")) break;
			for (i=0; i<MAXFILES; i++) {
				if (buf[i]->Flags & CHANGED) saveFile(buf[i]);
			}
			break;
		}
	}
	if (stopPause) return;
	if (yesNo("Really quit?","")) badQuit();
}

#asm
	xref _alphaDigitFast
	xref _args
	xref _buf
	xref _bufPtrArgs
	xref _charHeight
	xref _charWidth
	xref _cleared
	xref _cleareol
	xref _collectRaw
	xref _colTrack
	xref _columnar
	xref _cram
	xref _curBuf
	xref _curCol
	xref _curLearn
	xref _curSplit
	xref _curTable
	xref _decFast
	xref _depth
	xref _display
	xref _displayFlag
	xref _downLineFast
	xref _edWindow
	xref _eFileFast
	xref _eFormFast
	xref _eLineFast
	xref _eol
	xref _eWordFast
	xref _fastB
	xref _fastBufPtr
	xref _fastP
	xref _fB
	xref _fixSOF
	xref _fP
	xref _freeBuf
	xref _gB
	xref _gChar
	xref _getCol
	xref _GetMsg
	xref _getRaw
	xref _GfxBase
	xref _gotoColFast
	xref _gP
	xref _hideDisplay
	xref _incFast
	xref _inSplit
	xref _lineHeight
	xref _longArgs
	xref _longPtrArgs
	xref _macroptr
	xref _mask1
	xref _mask2
	xref _maxLineChars
	xref _maxLines
	xref _mouseX
	xref _mouseY
	xref _move
	xref _n
	xref _newBlock
	xref _newBuf
	xref _noDisplay
	xref _nSplit
	xref _numArg
	xref _oldBuf
	xref _oldCursorCol
	xref _oldCurSplit
	xref _oldSplit
	xref _oldStart
	xref _oldStop
	xref _packBuf
	xref _prints
	xref _ptrArgs
	xref _restoreMsg
	xref _rp
	xref _saveFast
	xref _saves
	xref _SetAPen
	xref _SetBPen
	xref _setTitle
	xref _SetWindowTitles
	xref _sFileFast
	xref _sFormFast
	xref _showTitle
	xref _sLineFast
	xref _splitBufNum
	xref _startSplit
	xref _stci_d
	xref _stopPause
	xref _stopSplit
	xref _strcat
	xref _strcpy
	xref _such
	xref _sWordFast
	xref _tabCalc
	xref _tabTables
	xref _text
	xref _tiny
	xref _toTiny
	xref _unsaveFast
	xref _upLineFast
	xref _uport
	xref _WaitBlit
	xref _wptr
	xref _xnum
	xref _xyToBP
	xref _z
#endasm

/*
NOTE::::::::::::::::::
The asm versions of FrunKey and unpackArgs are in the ue17.asm module.
This is the only instance where the asm isn't in the same module as the C
counterpart */

#ifdef USEC99

static short offset = 0;

FrunKey(register short tnum)	/* WARNING: NO STATICS on these - RECURSIVE!!!! */
{
register UCHAR  		*sPtr,*macroPtr,funcNum;
register short  		rtn,doingIf;
register long           tPtr;

	tPtr = (long)&cmdTable[tnum];
	macroPtr  = *(UCHAR **)tPtr;
	if (macroPtr==NULL) return(FALSE);
	if (++stackDepth > MAXSTACK) {
BADRTN:
		rtn = Fnull();
		goto RTNPT;
	}
	rtn = FALSE;
	doingIf  = 0;
	sPtr = macroPtr;
	macroPtr += offset;
	offset = 0;

CONT:
	if (stopPause) goto BADRTN;
    if (msgList->lh_Head->ln_Succ) {
		if (stop() || noMemory) goto BADRTN;
		doTiny();
	}
	if (*(UCHAR **)tPtr!=sPtr) goto BADRTN;					 /* killed or swapped! */
	funcNum = *(macroPtr++);
	if (funcNum<=returnFalse_) goto SPECFCT;
	if (funcNum<=newFile_) goto NORMALFCT;

	/* ******************* ARGD ********************** */
	macroptr = macroPtr;						 /* globals for unpackArgs */
	numArg = numArgs[funcNum];
	unpackArgs();
	macroPtr = macroptr;
	if (macroPtr==NULL) goto BADRTN;

	if (funcNum!=runKey_) {
NORMALFCT:
		rtn = (*macroFunc[funcNum])();
		goto CONT;
	}
/* ============== THIS IS RUNKEY ========================= */
	if (tnum==startupMacro && !startingUp) goto CONT;
	rtn = (short) *longPtrArgs[0];
	if (rtn==startupMacro) { killMenus(); rtn = TRUE; goto CONT; }

	if (rtn>=MAXMACROS || rtn<0) goto BADRTN;
	rtn  = FrunKey(rtn);
	goto CONT;

SPECFCT:
	switch(funcNum) {
		case 0x00:  	goto RTNPT;
		case abort_:	goto BADRTN;
		case not_:  	doingIf = 1; goto CONT;
		case do_:		/* its number is used for GOSUB */
			offset = (short)( (USHORT)(macroPtr[0] << 8) | macroPtr[1] );
						+ (short)(macroPtr - sPtr);
			rtn = FrunKey(tnum);
			macroPtr += 2;
			goto CONT;
		case if_:		doingIf = 3; goto CONT; /* NOT_ is really IFNOT_ */
		case goto_: 	if (doingIf & 1) {
							doingIf &= 2;		/* jump goto if fail */
							if ((doingIf >> 1)!=rtn) {
									macroPtr += 2;
									goto CONT;
							}
						}

						macroPtr += (short)((USHORT)(macroPtr[0] << 8) | macroPtr[1]);
						goto CONT;
		case nothing_:  rtn = TRUE; goto CONT;
		case return_:		goto RTNPT; break;
		case returnTrue_:	rtn = TRUE; goto RTNPT;
		case returnFalse_:  rtn = FALSE; goto RTNPT;
	}
	goto BADRTN;
RTNPT:
	stackDepth--;
	return(rtn);
}

/* WARNING - ASM-Frunkey expects to find macroptr in a3 & numArg in d1 */

void unpackArgs()
{
register UCHAR  		*x;
register struct CB  	**bptr;
register UCHAR  		i,numa,j,k;
long					**ppLongArg,*pLongArg;
UCHAR					*pArg;

	x	 = macroptr;
	numa = numArg;
	pArg = args;
	ppLongArg = longPtrArgs;
	pLongArg  = longArgs;
	bptr = bufPtrArgs;
	i = 0;
TOPCONT:
	if (i>=numa) goto NOARGS;
	*ppLongArg = pLongArg;
	j = *(x++);
	*pArg = j;
	switch ((short)j) {
	case buf_:
			j = *(x++);
			if (j>=ALLBUFS) goto BADRTN;
			*pLongArg = j;
			*bptr = buf[j];
			goto CONT;
	case bufN_:
			*pArg = buf_;
			k = *(x++);
			j = *(x++);
			if (j>=ALLBUFS) goto BADRTN;
			if (k==nN_) {
				j = n[j];
				if (j>=ALLBUFS) goto BADRTN;
			}
			k = n[j];
			if (k>=ALLBUFS) goto BADRTN;
			*pLongArg = (long)k;
			*bptr = buf[k];
			goto CONT;
	case currentFile_:
			j = curBuf->BufNum;
			*pLongArg = j;
			*bptr = buf[j];
			*pArg = buf_;
			goto CONT;
	case n_:
			j = *(x++);
HANDLEN:	if (j>=ALLBUFS) goto BADRTN;
			*ppLongArg = &n[j];
			goto CONT;
	case nN_:
			*pArg = n_;
			j = *(x++);
			if (j>=ALLBUFS)  goto BADRTN;
			j = n[j];
			goto HANDLEN;
	case literal_:
			ptrArgs[i] = x;
			*pLongArg = 0L;
			while (*x) *pLongArg = ((*pLongArg) << 8L) | *(x++);
			x++;
			goto CONT;
	case keyArg_:
			*pLongArg = (long)((*x << 8L) | (*(x+1)));
			x += 2;
			goto CONT;
	case REALARG_:
			*pLongArg = (long)((*x << 24L) | (*(x+1) << 16L)
									| (*(x+2) << 8L) | (*(x+3)));
			x += 4;
			goto CONT;
    case byteArg_:
            *pLongArg = (long) *(x++); goto CONT;
	case 0:
BADRTN: x = NULL;
			goto NOARGS;
	default:
			if (j >= pmEsc_ && j <= macroNum_)
				*ppLongArg = (long *)such[j - pmEsc_];
			break;
	}
CONT:
	pArg++;
	ppLongArg++;
	pLongArg++;
	bptr++;
	i++;
	goto TOPCONT;
NOARGS:
	macroptr = x;
}

#endif

FscreenToFront()
{
	if (edScreen==NULL) return(FALSE);
	ScreenToFront(edScreen);
	return(TRUE);
}

FscreenToBack()
{
	if (edScreen==NULL) return(FALSE);
	ScreenToBack(edScreen);
	return(TRUE);
}

FinTiny()
{
	return(tiny);
}

Fnull()
{
/*  onDisplay(); */

	displayFlag |= ALLPAGE;
	unsaveFlags();
	mouseDown = learnMode = curMsgIn = curMsgOut = teachKeys = cmdMultiplier = 0;
	stopPause = TRUE;
	FbeepDisplay();
	if (execLearn) execLearn = STOP_EXEC_LEARN;
	wipeMsgQ();
	showTitle = TRUE;  /* setTitle();  */
	clearMsg();
	replyRexx(10L);  /* is this ALWAYS safe?? */
	hadAbort=TRUE;
	return(FALSE);
}

void wipeLearn()
{
	zero(learnQ);
}

wipeMsgQ()
{
	zero(msgQ);
}

void setTime(	register ULONG *seconds,
				register ULONG *micros,
				register ULONG tenths)
{
/* -----------
	long	l[3];
	DateStamp(l);
------------------ */
	CurrentTime(seconds,micros);
	*seconds += tenths/10L;
	*micros  +=  ((tenths % 10L) * 100000L);
	if (*micros>=1000000L) { (*seconds)++; (*micros) -= 1000000L; }
}

isTime( register ULONG sec,
		register ULONG mic)
{
ULONG seconds,micros;
/* -----------
	long	l[3];
	DateStamp(l);
------------------ */

	CurrentTime(&seconds,&micros);
	if ((seconds==sec && micros>=mic) || seconds>sec) return(TRUE);
	return(FALSE);
}

FteachOne()
{
		showKeyHelp((short)*longPtrArgs[0]);
		return(TRUE);
}

void primitiveEdit(short i)
{
register struct CB  	*curB;
register short  		savePrim;
register ULONG  		saveFlags;

	savePrim = primitive;
	primitive=i;

	curB=curBuf;
	saveFlags = curB->Flags;
	if (i==2) {
		curB->PPtr = (UCHAR *)curB->NextBlock;
		curB->PBlock = curB->NextBlock;
		curB->Flags &= ~OVERSTRIKE;
	}
	restoreMsg();
	showTitle = TRUE; /* setTitle();  */
	editWork();
	curB->Flags |= saveFlags;
	clearMsg();
	primitive = savePrim;
}

void upMenus()
{
	if (edWindow!=NULL) {
		if (edMenu[0]==NULL) {
			menuInset = 0;
			nullArrays();
			FrunKey(startupMacro);
			menuFix();
			startingUp = 0;
		}
		if (edMenu[0]!=NULL) {
			if (!menusUp) {
				/* setColors(menuVid); */
				/* windowColors(); */
				SetMenuStrip(edWindow,edMenu[0]);
				menusUp = 1;
			}
		}
	}
}

void killMenus()
{
	downMenus();
	freeMenus();
}

void downMenus()
{
register struct Window *ed;

	ed = edWindow;
	if (ed!=NULL && menusUp && edMenu[0]!=NULL) {
		OffMenu(ed,(long)NOITEM);
		ClearMenuStrip(ed);
	}
	menusUp = 0;
}

void menuFix()  		/* find which menus to inset for checkwidth */
{
register struct Menu  *mm,**edm;
register short  kk,ii,i,k;
short				j,jj,iii;

	edm = edMenu;
STARTOVER:
	for (i=1; i<MAXMENUS; i++)
	if (edMenu[i]!=NULL && edMenu[i-1]==NULL) {
	for (--i; i<(MAXMENUS-1); i++) {
		edMenu[i] = edMenu[i+1];
		edMenu[i+1]=NULL;
		ii = i*MAXITEMS*MAXSUBITEMS;
		iii= ii + (MAXITEMS*MAXSUBITEMS);
		jj = 0;
		for (j=0; j<MAXITEMS; j++) {
			for (k=0; k<MAXSUBITEMS; k++) {
				kk = k + jj;
				menuMacroNum[ii + kk] = menuMacroNum[iii + kk];
				menuMacroNum[iii + kk] = 0;
			}
			jj += MAXSUBITEMS;
		}
	}
	goto STARTOVER;
	}
	for (i=0; i<MAXMENUS; i++) {
		mm = edm[i];
		if (mm!=NULL && mm->FirstItem==NULL)  {
			FreeMem(mm,(long)sizeof(struct Menu));
			edMenu[i]=NULL;
			goto STARTOVER;
	}
	}
	for (i=0; i<(MAXMENUS-1); i++) {
		mm = edm[i];
		if (mm!=NULL) mm->NextMenu=edMenu[i+1];
	}
	if (edMenu[MAXMENUS-1]!=NULL) edMenu[MAXMENUS-1]->NextMenu=NULL;
}

void freeMenus()
{
register struct Menu **edm,*mm;
register short i;

	edm = edMenu;
	i = 0;
	while (1) {
		mm = *edm;
		if (mm!=NULL) {
			freeItems(mm->FirstItem);
			FreeMem(mm,(long)sizeof(struct Menu));
			*edm = NULL;
		}
		edm++;
		if (++i>=MAXMENUS) return;
	}
}

void freeItems(register struct MenuItem *item)
{
register struct   MenuItem     *nextItem;

	while (item!=NULL) {
		if (item->SubItem) freeItems(item->SubItem);
		FreeMem(item->ItemFill,(long)sizeof(struct IntuiText));
		if (item->SelectFill) FreeMem(item->SelectFill,(long)sizeof(struct IntuiText));
		nextItem = item->NextItem;
		FreeMem(item,(long)sizeof(struct MenuItem));
		item = nextItem;
	}
}

void updateMenus()
{
register struct MenuItem   *itemPtr,*subPtr;
register long			i;

	upMenus();
	i = 0;
	while (1) {
		if (edMenu[i]!=NULL) {
			itemPtr = edMenu[i]->FirstItem;
			while (itemPtr!=NULL) {
				subPtr = itemPtr->SubItem;
				while (subPtr!=NULL) {
					setChecks(subPtr,i);
					subPtr = subPtr->NextItem;
				}
				setChecks(itemPtr,i);
				itemPtr = itemPtr->NextItem;
			}
		}
		if (++i>=MAXMENUS) return;
	}
}

void setChecks( register struct MenuItem *itemPtr,
				register long i)
{
register short  	argNum;
register ULONG  	k;

	if (itemPtr->Flags & CHECKIT) {
		OffMenu(edWindow,i);
		argNum = (UBYTE)itemPtr->Command - 128 + pmEsc_;
		if (argNum<trueTabs_) k = *(such[argNum - pmEsc_]);
		else if (argNum==favorite_)  k = curBuf->Flags & FAVORITE;
		else {
			k = 1L << (argNum - trueTabs_);
			k = curBuf->Flags & k;
		}
		if (k)  itemPtr->Flags |=  CHECKED;
		else	itemPtr->Flags &= ~CHECKED;
		OnMenu(edWindow,i);
	}
}

void setPMTitle(register UCHAR *x, short flag)
{
register UCHAR *y;
register short i;

	strcpy(x,"Primitive Mode string input (ESC   = done):");
	if (flag) movdat((UCHAR *)"number",&x[15],(short)6);
	i = pmEsc;
	if (i==eol) y = "ENTER";
	else {
		if (i==27) y = "ESC  ";
		else if (i<32) {
			y = "CTL- ";
			if (i<=26)  	i += 96;
			else if (i==28) i = '\\';
			else if (i==29) i = ']';
			else if (i==30) i = '^';
			else if (i==31) i = '_';
			y[4] = i;
		}
	}
	movdat(y,&x[29],(short)5);
}

getNum(register long *output)
{
register struct   CB	*curB;
register short  		rtn,i;

	rtn = FALSE;
	if (!getBuf(ALLBUFS)) goto RTN;
	saveSplit();
	curB = buf[ALLBUFS];
	curBuf = curB;
	splitBufNum[0] = curB->BufNum;
	setPMTitle(curB->FileName,1);
	/* --------------------------------
	strcpy(curB->FileName,"Primitive Mode number input (pmESC = done):");
	--------------------------------------- */
	primitiveEdit(2);					 /* editWork does a switchFast() */
	sFileFast();
	*output = 0L;
	if (curB->Flags & CHANGED) {
		i = *fastP;
		if (i=='-' || (i>='0' && i<='9')) rtn = TRUE;
		if (!alphaDigitFast()) incFast();
		copyNum('-');
		*output = atole(xnum);
	}
	freeBuf(ALLBUFS);
	unsaveSplit();
	curBuf = buf[splitBufNum[curSplit]];
	switchFast();
/*    localColors = curB->colors; */
	
	showTitle = TRUE; /* setTitle(); */
	displayFlag = ALLPAGE;
RTN:
	return(rtn);
}


short	rotor = 0;
UCHAR	z1[MAXLINECHARS],z2[MAXLINECHARS];

static UCHAR tBar[MAXLINECHARS];

#ifdef USEC

UCHAR *fixString(	register short parse,
					register short num,
					register short len)
{
register UCHAR    *x,*y;
register short    type;
UCHAR			*zz;
struct  CB  *bufPtr;

	type = args[num];
	if (rotor) { y = z1; rotor = 0; }
	else { y = z2; rotor = 1; }
	if (type==literal_) {
		x=ptrArgs[num];
		if (x==NULL || *x==0x00) return(NULL);
	} else if (type==buf_) {
		bufPtr=bufPtrArgs[num];
		x=(UCHAR *)bufPtr->NextBlock;
		if (bufPtr==NULL || x==NULL) return(NULL);
		if (bufPtr->Flags & NEEDPACK) packBuf(bufPtr,TRUE);
	} else {
		stci_d(y,(long)(*(longPtrArgs[num])));
		return(y);
	}
	zz = y;
	if (parse<EOFILE) parse = EOFILE + 1;
	while (1) {
		type = *(x++);
		if (type<parse) break;
		*(y++) = type;
		if (--len==0) break;
	}
	*y = 0x00;
	y = zz;
	if (*y==0x00) return(NULL);
	return(y);
}

#endif

#ifndef USEC
#asm

	xdef	_fixString
_fixString:
	movem.l d2-d7/a2/a3,-(sp)
	move.w  36(sp),d4
	move.w  38(sp),d6
	move.w  40(sp),d5			;if(len>=128)len=127
	lea _args,a0		 ;type=args[num]
	moveq	#0,d2
	move.b  (a0,d6.w),d2
	tst.w	_rotor  		 ;if(rotor){y=z1rotor=0}
	beq FS10002
	lea _z1,a2
	clr.w	_rotor  		;else{y=z2rotor=1}
	bra FS10003
FS10002:
	lea _z2,a2
	move.w  #1,_rotor
FS10003:			;if(type==literal_){
	cmp.w	#7,d2
	bne FS10004 		;x=ptrArgs[num]
	move.w  d6,d0
	add.w	d0,d0
	add.w	d0,d0
	lea _ptrArgs,a0
	move.l  (a0,d0.w),a3
	move.l  a3,d0			 ;if(x==NULL)return(NULL)
	beq FS2
	tst.b (a3)
	bne FS10006
	moveq	#0,d0
	bra FS2
FS10004:		   ;}elseif(type==buf_){
	cmp.w	#1,d2
	bne FS10007 		;bufPtr=bufPtrArgs[num]
	move.w  d6,d0
	add.w	d0,d0
	add.w	d0,d0
	lea _bufPtrArgs,a0
	move.l  (a0,d0.w),d3			;x=(UCHAR*)bufPtr->NextBlock
	move.l  d3,a0
	move.l  160(a0),a3  		;if(bufPtr==NULL||x==NULL)return(NULL)
	tst.l	d3
	beq FS10014
	move.l  a3,d0
	beq FS10014
;;; move.l  d3,a0
	btst.b  #5,170(a0)  		;if(bufPtr->Flags&NEEDPACK)packBuf(bufPtr,TRUE)
	beq FS10010
	move.w  #1,-(sp)
	move.l  d3,-(sp)
	jsr _packBuf			;}else{
	addq.w  #6,sp
	bra FS10010
FS10007:			;stci_d(y,(long)(*(longPtrArgs[num])))
	move.w  d6,d0
	add.w	d0,d0
	add.w	d0,d0
	lea _longPtrArgs,a0
	move.l  (a0,d0.w),a0
	move.l  (a0),-(sp)
	move.l  a2,-(sp)
	jsr _stci_d 		;return(y)
	move.l  a2,d0
	addq.w  #8,sp
	bra FS2 		;}
FS10010:
FS10006:			;zz=y
	move.l  a2,d7			;if(parse<EOFILE)parse=EOFILE+1
	cmp.w	#3,d4
	bge FS10011
	moveq	#4,d4			;while(1){
FS10011:
	moveq	#0,d2
FS10012:			;type=*(x++)
	move.b  (a3)+,d2
	cmp.w	d4,d2			;if(type<parse)break
	blt FS10013 			;*(y++)=type
	move.b  d2,(a2)+		;if(--len==0)break
	dbra	d5,FS10012  	;}
FS10013:			;*y=0x00
	clr.b	(a2)			;y=zz
	move.l  d7,a2			;if(*y==0x00)return(NULL)
	tst.b	(a2)
	beq FS10014
	move.l  a2,d0		;};
FS2:
	movem.l (sp)+,d2-d7/a2/a3
	rts
FS10014:
	moveq	#0,d0
	bra FS2 		;return(y)

#endasm
#endif

void nameBuf(register struct CB *bufPtr)
{
register UCHAR    *name;
register short    bufnum;

	name = bufPtr->FileName;
	if (*name<' ') {
		bufnum = bufPtr->BufNum;
		if (bufferNames[bufnum]!=NULL)
			strncpy(name,bufferNames[bufnum],(size_t)60);
		else {
			strcpy(name,"Buffer-");
			catNumber(name,(long)bufnum,40);
		}
	}
}

void setTitle()
{
register struct CB  *curb;
register UCHAR  *t;
register short  i,j,sp,start;
register ULONG  flags,tt;

	if (noDisplay || tiny || MENUDRAWN) return;
	setColors(titleVid);
	showTitle = FALSE;
	t = tBar;
	tt = (ULONG)t;
	wptr = t;
	sp = nSplit;
	while (1) {
		curb = buf[splitBufNum[sp]];
		if (curb==NULL) goto BUMP;
		t = (UCHAR *)tt;
		if (sp==curSplit) strcpy(t,VNAME);
		else strcpy(t,"            ");
		if (sp==0) {
			flags = curBuf->Flags;
			strcat(t,"tiokrwjmcabf ");
			if (flags & TRUETABS)		t[12] = 'T';
			if (flags & AUTOINDENT) 	t[13] = 'I';
			if (flags & OVERSTRIKE) 	t[14] = 'O';
			if (flags & AUTOBACKUP) 	t[15] = 'K';
			if (flags & READONLY)		t[16] = 'R';
			if (flags & WORDWRAP)		t[17] = 'W';
			if (flags & RIGHTJUSTIFY)	t[18] = 'J';
			if (flags & MAPCHARS)		t[19] = 'M';
			if (flags & CHANGED)	  { t[20] = 'C'; changedMark = TRUE; }
			else changedMark = FALSE;
			if (flags & USERLOCALA) 	t[21] = 'A';
			if (flags & USERLOCALB) 	t[22] = 'B';
			if (flags & FAVORITE)		t[23] = 'F';
			if (primitive==2)			t[24] = 'X';
		} else strcat(t,"              ");
		strcat(t,"[");
		catNumber(t,(long)curb->BufNum,NAMELEN);
		if (teachKeys) strcat(t,",T");
		if (learnMode) { strcat(t,",L"); catNumber(t,(long)curLearn,NAMELEN); }
		if (prints) { strcat(t,",P"); catNumber(t,(long)prints,NAMELEN); }
		if (saves)  { strcat(t,",S"); catNumber(t,(long)saves,NAMELEN); }

		strcat(t,"]  ");

		if (*curb->FileName<' ') nameBuf(curb);
		strcat(t,curb->FileName);

		i = j = 0;
		while (1) {
			if (*t==0) j = 1;
			if (j) *t = ' ';
			t++;
			if (++i>MAXLINECHARS) break;
		}
		i = maxLineChars + 1;
		if (i>=MAXLINECHARS) i = MAXLINECHARS - 1;
		t = (UCHAR *)tt;
		t[i] = 0;
		start = startSplit[sp];
		if (start==0) {
			SetWindowTitles(edWindow,t,0L);
			WaitBlit();
		} else {
			move(0,start);
			text(i);
			cleareol();
		}
BUMP:
		if (--sp<0) return;
	}
}

#ifdef USEC
void getBP( register struct CB *gbptr,
			short gArgNum)
{
register  UCHAR 	*fPtr;
register  short 	gArg,i,saveColumnar;
register  long  	fb,fp;
UCHAR				**ov;

	gArg = args[gArgNum];
	fB=gB=NULL;
	fP=gP=NULL;
	if (gArg!=upLine_ && gArg!=downLine_) colTrack = -1;

	/* mouseLoc_ to atCursor_ 99-118 */
	if (gArg>mouseLoc_) goto POINT1;
	if (gArg>=atCursor_) {
		if (gArg==mouseLoc_) xyToBP(gbptr);    /* update mouse b/p */
		i = gArg - atCursor_;
		ov=  (UCHAR **) gbptr;
		fPtr = ov[i];
		gB = (struct DB *)fPtr;
		gP = ov[i+CBOVL];
		return;
	}
POINT1:
	fb = fp = 0L;
	saveFast();
	fastBufPtr = gbptr;
	fastB = gbptr->Block;
	fPtr = gbptr->Ptr;
	fastP = fPtr;

	/* sFile_ to eChar_ 119-128 */
	if (gArg > eChar_) goto POINT2;  /* guaranteed <char_ here */
	switch(gArg) {
	case  sFile_:	sFileFast();	goto FINISH;
	case  eFile_:	eFileFast();	goto FINISH;
	case  sLine_:	sLineFast();	goto FINISH;
	case  eLine_:	eLineFast();	goto FINISH;
	case  upLine_:   upLineFast();   goto FINISH;
	case  downLine_: downLineFast(); goto FINISH;
	case  sWord_:	sWordFast();	goto FINISH;
	case  eWord_:	eWordFast();	goto FINISH;
	case  sChar_:	decFast();  goto FINISH;
	case  eChar_:	incFast();  goto FINISH;
	}
	goto BADBP;

POINT2:
	/* char_ to all_ 129-134 */
	if (gArg > all_) goto POINT3;	/* guaranteed < loc_ here */
	switch(gArg) {
	case  char_:	fb=(long)fastB; 	fp=(long)fPtr;   incFast(); goto FINISH;
	case  word_:	fb=(long)fastB; 	fp=(long)fPtr;   eWordFast();	 goto FINISH;
	case  line_:	fb=(long)fastB; 	fp=(long)fPtr;
					if (*fPtr!=eol && *fPtr!=12) eLineFast();
					goto FINISH;
	case  hilite_:  fb=(long)gbptr->SHBlock;  fp=(long)gbptr->SHPtr;
					fastB=gbptr->EHBlock;	fastP=gbptr->EHPtr;
					goto FINISH;
	case  invert_:  fb=(long)gbptr->SIBlock;  fp=(long)gbptr->SIPtr;
					fastB=gbptr->EIBlock;	fastP=gbptr->EIPtr;
					goto FINISH;
	case  all_: 	fb=(long)gbptr->NextBlock;  fp=(long)((struct DB *)fb)->Data;
					eFileFast(); goto FINISH;
	}
	goto BADBP;

POINT3:
	/* loc_ to locPC_ 135-140 */
	if (gArg > locPC_) goto POINT4;
	switch(gArg) {
	case  loc_: 	fb=(long)gbptr->LABlock;  fp=(long)gbptr->LAPtr;
					fastB=gbptr->LBBlock;	fastP=gbptr->LBPtr;
					goto FINISH;
	case  locCD_:	fb=(long)gbptr->LCBlock;	fp=(long)gbptr->LCPtr;
					fastB=gbptr->LDBlock;	fastP=gbptr->LDPtr;
					goto FINISH;
	case  locEF_:	fb=(long)gbptr->LEBlock;	fp=(long)gbptr->LEPtr;
					fastB=gbptr->LFBlock;	fastP=gbptr->LFPtr;
					goto FINISH;
	case  locGH_:	fb=(long)gbptr->LGBlock;	fp=(long)gbptr->LGPtr;
					fastB=gbptr->LHBlock;	fastP=gbptr->LHPtr;
					goto FINISH;
	case  locIJ_:	fb=(long)gbptr->LIBlock;	fp=(long)gbptr->LIPtr;
					fastB=gbptr->LJBlock;	fastP=gbptr->LJPtr;
					goto FINISH;
	case  locPC_:	fb=(long)gbptr->LSPBlock;	fp=(long)gbptr->LSPPtr;
					fastB=gbptr->LSCBlock;  fastP=gbptr->LSCPtr;
					goto FINISH;
	}
	goto BADBP;

POINT4:
	/* sForm_ to eForm_ */
	if (gArg==sForm_)  { sFormFast(); goto FINISH; }
	if (gArg==eForm_)  { eFormFast(); goto FINISH; }

	/* sTab_ to eTab_ 160-161 */
	if (gArg==eTab_ || gArg==sTab_) {
		saveColumnar=columnar;
		columnar = 0;
		fPtr = gbptr->NextBlock->Data;
		if (*fPtr==0x00) fixSOF((struct CB *)gbptr);
		curTable = tabTables[gbptr->tabTable];
		while (1) {
			if (gArg==sTab_) {
				decFast();
				if (fastP==fPtr) break;
			} else {
				incFast();
				if (*fastP==EOFILE) break;
			}
			curCol = getCol();
			if (tabCalc() & 0x0100) break;
		}
		columnar = saveColumnar;
		goto FINISH;
	}

BADBP:
	fastB=NULL; fastP=NULL;

FINISH:
	gB=fastB; gP=fastP;
	if (fb!=NULL && gB!=NULL && (ULONG)loc(fb,fp)>(ULONG)loc(gB,gP)) {
		fastP=(UCHAR *)fp; fastB=(struct DB *)fb;
		fp=(long)gP; fb=(long)gB;
		gP=fastP; gB=fastB;
	}
	fB = (struct DB *)fb;
	fP = (UCHAR *)fp;
	unsaveFast();
}
#endif

#ifndef USEC
#asm
	xdef	_getBP
_getBP:
	movem.l d2-d7/a2/a3,-(sp)
	move.l  36(sp),a2			;RUCHAR*fPtrRshortgArg,i,saveColumnarRlongfb,fpUCHAR**ovgArg=args[gArgNum]
	move.w  40(sp),d0
	lea _args,a0
	moveq	#0,d2
	move.b  (a0,d0.w),d2
	clr.l	_gB 		;fB=gB=NULL
	clr.l	_fB 		;fP=gP=NULL
	clr.l	_gP
	clr.l	_fP 		;if(gArg!=upLine_&&gArg!=downLine_)colTrack=-1
	cmp.w	#123,d2
	beq GBP10001
	cmp.w	#124,d2
	beq GBP10001
	move.w  #-1,_colTrack			;/*mouseLoc_toatCursor_99-118*/if(gArg>mouseLoc_)gotoPOINT1
GBP10001:
	cmp.w	#118,d2
	bgt GBP10002			;if(gArg>=atCursor_){
	cmp.w	#99,d2
	blt GBP10003			;if(gArg==mouseLoc_)xyToBP(gbptr)/*updatemouseb/p*/
	cmp.w	#118,d2
	bne GBP10004
	move.l  a2,-(sp)
	jsr _xyToBP 		;i=gArg-atCursor_
	addq.w  #4,sp
GBP10004:
	move.w  d2,d5
	sub.w	#99,d5  		;ov=(UCHAR**)gbptr
	move.l  a2,d6			;fPtr=ov[i]
	move.w  d5,d0
	add.w	d0,d0
	add.w	d0,d0
	move.l  d6,a0
	move.l  (a0,d0.w),a3			;gB=(structDB*)fPtr
	move.l  a3,_gB  		;gP=ov[i+CBOVL]
	add.w	#80,d0
	move.l  d6,a0
	move.l  (a0,d0.w),_gP			;return
GBP2:
	movem.l (sp)+,d2-d7/a2/a3
	rts 		;}POINT1:
GBP10003:
GBP10002:			;fb=fp=0L
	moveq	#0,d4
	move.l  d4,d3			;saveFast()
	jsr _saveFast			;fastBufPtr=gbptr
	move.l  a2,_fastBufPtr  		;fastB=gbptr->Block
	move.l  (a2),_fastB 		;fPtr=gbptr->Ptr
	move.l  80(a2),a3			;fastP=fPtr
	move.l  a3,_fastP			;/*sFile_toeChar_119-128*/if(gArg>eChar_)gotoPOINT2/*guaranteed<char_here*/
	cmp.w	#128,d2
	bgt GBP10005			;switch(gArg){
	move.w  d2,d0
	bra GBP10006			;casesFile_:sFileFast()gotoFINISH
GBP10008:
	jsr _sFileFast
	bra GBP10009			;caseeFile_:eFileFast()gotoFINISH
GBP10010:
	jsr _eFileFast
	bra GBP10009			;casesLine_:sLineFast()gotoFINISH
GBP10011:
	jsr _sLineFast
	bra GBP10009			;caseeLine_:eLineFast()gotoFINISH
GBP10012:
	jsr _eLineFast
	bra GBP10009			;caseupLine_:upLineFast()gotoFINISH
GBP10013:
	jsr _upLineFast
	bra GBP10009			;casedownLine_:downLineFast()gotoFINISH
GBP10014:
	jsr _downLineFast
	bra GBP10009			;casesWord_:sWordFast()gotoFINISH
GBP10015:
	jsr _sWordFast
	bra GBP10009			;caseeWord_:eWordFast()gotoFINISH
GBP10016:
	jsr _eWordFast
	bra GBP10009			;casesChar_:decFast()gotoFINISH
GBP10017:
	jsr _decFast
	bra GBP10009			;caseeChar_:incFast()gotoFINISH
GBP10018:
	jsr _incFast
	bra GBP10009			;}
GBP3:
	dc.w	GBP10008-GBP4-2
	dc.w	GBP10010-GBP4-2
	dc.w	GBP10011-GBP4-2
	dc.w	GBP10012-GBP4-2
	dc.w	GBP10013-GBP4-2
	dc.w	GBP10014-GBP4-2
	dc.w	GBP10015-GBP4-2
	dc.w	GBP10016-GBP4-2
	dc.w	GBP10017-GBP4-2
	dc.w	GBP10018-GBP4-2
GBP10006:
	sub.w	#119,d0
	cmp.w	#10,d0
	bcc GBP10007
	add.w	d0,d0
	move.w  GBP3(pc,d0.w),d0
GBP4:
	jmp (pc,d0.w)
GBP10007:			;gotoBADBP
	bra GBP10019			;POINT2:
GBP10005:			;/*char_toall_129-134*/if(gArg>all_)gotoPOINT3/*guaranteed<loc_here*/
	cmp.w	#134,d2
	bgt GBP10020			;switch(gArg){
	move.w  d2,d0
	bra GBP10021			;casechar_:fb=(long)fastBfp=(long)fPtrincFast()gotoFINISH
GBP10023:
	move.l  _fastB,d3
	move.l  a3,d4
	jsr _incFast
	bra GBP10009			;caseword_:fb=(long)fastBfp=(long)fPtreWordFast()gotoFINISH
GBP10024:
	move.l  _fastB,d3
	move.l  a3,d4
	jsr _eWordFast
	bra GBP10009			;caseline_:fb=(long)fastBfp=(long)fPtr
GBP10025:
	move.l  _fastB,d3
	move.l  a3,d4			;if(*fPtr!=eol&&*fPtr!=12)eLineFast()
	move.b  (a3),d0
	cmp.b	_eol,d0
	beq GBP10026
	cmp.b	#12,(a3)
	beq GBP10026
	jsr _eLineFast  		;gotoFINISH
GBP10026:
	bra GBP10009			;casehilite_:fb=(long)gbptr->SHBlockfp=(long)gbptr->SHPtr
GBP10027:
	move.l  4(a2),d3
	move.l  84(a2),d4			;fastB=gbptr->EHBlockfastP=gbptr->EHPtr
	move.l  8(a2),_fastB
	move.l  88(a2),_fastP			;gotoFINISH
	bra GBP10009			;caseinvert_:fb=(long)gbptr->SIBlockfp=(long)gbptr->SIPtr
GBP10028:
	move.l  12(a2),d3
	move.l  92(a2),d4			;fastB=gbptr->EIBlockfastP=gbptr->EIPtr
	move.l  16(a2),_fastB
	move.l  96(a2),_fastP			;gotoFINISH
	bra GBP10009			;caseall_:fb=(long)gbptr->NextBlockfp=(long)((structDB*)fb)->Data
GBP10029:
	move.l  160(a2),d3
	move.l  d3,d4			;eFileFast()gotoFINISH
	jsr _eFileFast
	bra GBP10009			;}
GBP5:
	dc.w	GBP10023-GBP6-2
	dc.w	GBP10024-GBP6-2
	dc.w	GBP10025-GBP6-2
	dc.w	GBP10027-GBP6-2
	dc.w	GBP10028-GBP6-2
	dc.w	GBP10029-GBP6-2
GBP10021:
	sub.w	#129,d0
	cmp.w	#6,d0
	bcc GBP10022
	add.w	d0,d0
	move.w  GBP5(pc,d0.w),d0
GBP6:
	jmp (pc,d0.w)
GBP10022:			;gotoBADBP
	bra GBP10019			;POINT3:
GBP10020:			;/*loc_tolocPC_135-140*/if(gArg>locPC_)gotoPOINT4
	cmp.w	#140,d2
	bgt GBP10030			;switch(gArg){
	move.w  d2,d0
	bra GBP10031			;caseloc_:fb=(long)gbptr->LABlockfp=(long)gbptr->LAPtr
GBP10033:
	move.l  28(a2),d3
	move.l  108(a2),d4  		;fastB=gbptr->LBBlockfastP=gbptr->LBPtr
	move.l  32(a2),_fastB
	move.l  112(a2),_fastP  		;gotoFINISH
	bra GBP10009			;caselocCD_:fb=(long)gbptr->LCBlockfp=(long)gbptr->LCPtr
GBP10034:
	move.l  36(a2),d3
	move.l  116(a2),d4  		;fastB=gbptr->LDBlockfastP=gbptr->LDPtr
	move.l  40(a2),_fastB
	move.l  120(a2),_fastP  		;gotoFINISH
	bra GBP10009			;caselocEF_:fb=(long)gbptr->LEBlockfp=(long)gbptr->LEPtr
GBP10035:
	move.l  44(a2),d3
	move.l  124(a2),d4  		;fastB=gbptr->LFBlockfastP=gbptr->LFPtr
	move.l  48(a2),_fastB
	move.l  128(a2),_fastP  		;gotoFINISH
	bra GBP10009			;caselocGH_:fb=(long)gbptr->LGBlockfp=(long)gbptr->LGPtr
GBP10036:
	move.l  52(a2),d3
	move.l  132(a2),d4  		;fastB=gbptr->LHBlockfastP=gbptr->LHPtr
	move.l  56(a2),_fastB
	move.l  136(a2),_fastP  		;gotoFINISH
	bra GBP10009			;caselocIJ_:fb=(long)gbptr->LIBlockfp=(long)gbptr->LIPtr
GBP10037:
	move.l  60(a2),d3
	move.l  140(a2),d4  		;fastB=gbptr->LJBlockfastP=gbptr->LJPtr
	move.l  64(a2),_fastB
	move.l  144(a2),_fastP  		;gotoFINISH
	bra GBP10009			;caselocPC_:fb=(long)gbptr->LSPBlockfp=(long)gbptr->LSPPtr
GBP10038:
	move.l  68(a2),d3
	move.l  148(a2),d4  		;fastB=gbptr->LSCBlockfastP=gbptr->LSCPtr
	move.l  72(a2),_fastB
	move.l  152(a2),_fastP  		;gotoFINISH
	bra GBP10009			;}
GBP7:
	dc.w	GBP10033-GBP8-2
	dc.w	GBP10034-GBP8-2
	dc.w	GBP10035-GBP8-2
	dc.w	GBP10036-GBP8-2
	dc.w	GBP10037-GBP8-2
	dc.w	GBP10038-GBP8-2
GBP10031:
	sub.w	#135,d0
	cmp.w	#6,d0
	bcc GBP10032
	add.w	d0,d0
	move.w  GBP7(pc,d0.w),d0
GBP8:
	jmp (pc,d0.w)
GBP10032:			;gotoBADBP
	bra GBP10019			;POINT4:
GBP10030:			;/*sForm_toeForm_156-157*/if(gArg==sForm_){sFormFast()gotoFINISH}
	cmp.w	#196,d2
	bne GBP10039
	jsr _sFormFast
	bra GBP10009			;if(gArg==eForm_){eFormFast()gotoFINISH}
GBP10039:
	cmp.w	#195,d2
	bne GBP10040
	jsr _eFormFast
	bra GBP10009			;/*sTab_toeTab_160-161*/if(gArg==eTab_||gArg==sTab_){
GBP10040:
	cmp.w	#199,d2
	beq GBP9
	cmp.w	#198,d2
	bne GBP10041
GBP9:			;saveColumnar=columnar
	move.w  _columnar+2,d7  		;columnar=0
	clr.l	_columnar			;fPtr=gbptr->NextBlock->Data
	move.l  160(a2),a3  		;if(*fPtr==0x00)fixSOF((structCB*)gbptr)
	tst.b	(a3)
	bne GBP10042
	move.l  a2,-(sp)
	jsr _fixSOF 		;curTable=tabTables[gbptr->tabTable]
	addq.w  #4,sp
GBP10042:
	move.w  176(a2),d0
	muls.w  #33,d0
	lea _tabTables,a0
	add.l	a0,d0
	move.l  d0,_curTable			;while(1){
GBP10043:			;if(gArg==sTab_){
	cmp.w	#198,d2
	bne GBP10045			;decFast()
	jsr _decFast			;if(fastP==fPtr)break
	move.l  _fastP,a0
	cmp.l	a3,a0
	beq GBP10044			;}else{
	bra GBP10046
GBP10045:			;incFast()
	jsr _incFast			;if(*fastP==EOFILE)break
;;;	move.l  _fastP,a0
	cmp.b	#3,(a1)
	beq GBP10044			;}
GBP10046:			;curCol=getCol()
	jsr _getCol
	move.w  d0,_curCol  		;if(tabCalc()&0x0100)break
	jsr _tabCalc
	btst.l  #8,d0
	beq GBP10043			;}
GBP10044:			;columnar=saveColumnar
	move.w  d7,a0
	move.l  a0,_columnar			;gotoFINISH
	bra GBP10009			;}BADBP:
GBP10041:
GBP10019:			;fastB=NULLfastP=NULL
	clr.l	_fastB
	clr.l	_fastP  		;FINISH:
GBP10009:			;gB=fastBgP=fastP
	move.l  _fastB,_gB
	move.l  _fastP,_gP  		;if(fb!=NULL&&gB!=NULL&&(ULONG)loc(fb,fp)>(ULONG)loc(gB,gP)){
	tst.l	d3
	beq GBP10047
	tst.l	_gB
	beq GBP10047
	move.l  _gB,a0
	moveq	#0,d0
	move.w  246(a0),d0
	moveq	#16,d1
	asl.l	d1,d0
	add.l	_gP,d0
	sub.l	_gB,d0
	move.l  d3,a0
	moveq	#0,d1
	move.w  246(a0),d1
	move.l  d0,-(sp)
	moveq	#16,d0
	asl.l	d0,d1
	add.l	d4,d1
	sub.l	d3,d1
	move.l  (sp)+,d0
	cmp.l	d1,d0
	bcc GBP10047			;fastP=(UCHAR*)fpfastB=(structDB*)fb
	move.l  d4,_fastP
	move.l  d3,_fastB			;fp=(long)gPfb=(long)gB
	move.l  _gP,d4
	move.l  _gB,d3  		;gP=fastPgB=fastB
	move.l  _fastP,_gP
	move.l  _fastB,_gB  		;}fB=(structDB*)fb
GBP10047:
	move.l  d3,_fB  		;fP=(UCHAR*)fp
	move.l  d4,_fP  		;unsaveFast()
	jsr _unsaveFast 		;}
	bra GBP2			;

#endasm
#endif

#ifdef USEC

void xyToBP(struct CB *bufPtr)
{
register struct CB  *curB;
register short  line,start,hite,my;
short stop;

	my   = mouseY;
	line   = inSplit(my);
	start = startSplit[line];
	stop  = stopSplit[line];
	curB  = buf[splitBufNum[line]];
	hite  = lineHeight[start];
	if (curB==bufPtr && my>=hite) {
		saveFast();
		fastBufPtr = curB;
		fastB = curB->PBlock;
		fastP = curB->PPtr;

		start++;
		line = (my - hite - 2);
		my = charHeight;
		if (cram) my--;
		line /= my;
		line += start;
		if (line>=stop) line = stop - 1;
		if (line>start) {
			hite = *fastP;
			while (start<line && hite!=EOFILE) {
				if (hite==eol || hite==12) start++;
				hite = *incFast();
			}
		}
		gotoColFast(1 + curB->PageCol + ((mouseX - 2)/charWidth));
		curB->MPtr   = fastP;
		curB->MBlock = fastB;
		unsaveFast();
	}
}
#endif

#ifndef USEC
#asm

	xdef  _xyToBP
_xyToBP:
	movem.l d2-d6/a2,-(sp)  	;
	move.w  _mouseY,d5  	;line=inSplit(my)
	move.w  d5,-(sp)
	jsr _inSplit
	move.w  d0,d3		;start=startSplit[line]
	add.w	d0,d0
	lea _startSplit,a0
	move.w  (a0,d0.w),d4		;stop=stopSplit[line]
	lea _stopSplit,a0
	move.w  (a0,d0.w),d6		;curB=buf[splitBufNum[line]]
	lea _splitBufNum,a0
	move.w  (a0,d0.w),d0
	asl.w	#2,d0
	lea _buf,a0
	move.l  (a0,d0.w),a2		;hite=lineHeight[start]
	move.w  d4,d0
	add.w	d0,d0
	lea _lineHeight,a0
	move.w  (a0,d0.w),d2		;if(curB==bufPtr&&my>=hite){
	cmp.l	30(sp),a2
	addq.w  #2,sp
	bne GTBP10001
	cmp.w	d2,d5
	blt GTBP10001		;saveFast()
	jsr _saveFast		;fastBufPtr=curB
	move.l  a2,_fastBufPtr  	;fastB=curB->PBlock
	move.l  20(a2),_fastB		;fastP=curB->PPtr
	move.l  100(a2),_fastP  	;start++
	addq.w  #1,d4		;line=(my-hite-2)
	move.w  d5,d0
	sub.w	d2,d0
	move.w  d0,d3
	subq.w  #2,d3		;my=charHeight
	move.w  _charHeight,d5  	;if(cram)my--
	tst.l	_cram
	beq GTBP10002
	subq.w  #1,d5		;line/=my
GTBP10002:
	ext.l	d3
	divs.w  d5,d3		;line+=start
	add.w	d4,d3		;if(line>=stop)line=stop-1
	cmp.w	d6,d3
	blt GTBP10003
	move.w  d6,d3
	subq.w  #1,d3		;if(line>start){
GTBP10003:
	cmp.w	d4,d3
	ble GTBP10004		;hite=*fastP
	move.l  _fastP,a0
	moveq	#0,d0
	move.b  (a0),d0
	move.w  d0,d2		;while(start<line&&hite!=EOFILE){
GTBP10005:
	cmp.w	d3,d4
	bge GTBP10006
	cmp.w	#3,d2
	beq GTBP10006		;if(hite==eol||hite==12)start++
	moveq	#0,d0
	move.b  _eol,d0
	cmp.w	d2,d0
	beq GTBP2
	cmp.w	#12,d2
	bne GTBP10007
GTBP2:
	addq.w  #1,d4		;hite=*incFast()
GTBP10007:
	jsr _incFast
;;;	move.l  d0,a0
	moveq	#0,d2
	move.b  (a1),d2
;;;	move.w  d0,d2		;}
	bra GTBP10005
GTBP10006:  	;}gotoColFast(1+curB->PageCol+((mouseX-2)/charWidth))
GTBP10004:
	move.w  _mouseX,d0
	subq.w  #2,d0
	ext.l	d0
	divs.w  _charWidth,d0
	add.w	164(a2),d0
	addq.w  #1,d0
	move.w  d0,-(sp)
	jsr _gotoColFast		;curB->MPtr=fastP
	move.l  _fastP,156(a2)  	;curB->MBlock=fastB
	move.l  _fastB,76(a2)		;unsaveFast()
	jsr _unsaveFast 	;}}
	addq.w  #2,sp
GTBP10001:
GTBP3:
	movem.l (sp)+,d2-d6/a2
	rts

#endasm
#endif

#ifdef USEC
void saveSplit()
{
register short *start,*stop;

	start = startSplit;
	stop = stopSplit;

	oldBuf = splitBufNum[0];
	oldStart = *start;
	oldStop = *stop;
	oldSplit = nSplit;
	oldCurSplit = curSplit;
	nSplit = curSplit = 0;
	*start = 0;
	*stop = maxLines + 1;
}

void unsaveSplit()
{
	curSplit = oldCurSplit;
	newSplit = oldCurSplit;
	splitBufNum[0] = oldBuf;
	startSplit[0] = oldStart;
	stopSplit[0] = oldStop;
	nSplit = oldSplit;
}
#endif

#ifndef USEC
#asm

	xdef  _saveSplit  ;void saveSplit()
_saveSplit:
	lea _startSplit,a0  ;	start = startSplit;
	lea _stopSplit,a1		;	stop = stopSplit;
	move.w  _splitBufNum,_oldBuf  ;    oldBuf = splitBufNum[0];
	move.w  (a0),_oldStart  ;	oldStart = *start;
	move.w  (a1),_oldStop	;	oldStop = *stop;
	move.w  _nSplit,_oldSplit	;	oldSplit = nSplit;
	move.w  _curSplit,_oldCurSplit    ;    oldCurSplit = curSplit;
	clr.w	_curSplit		;	nSplit = curSplit = 0;
	clr.w	_nSplit
	clr.w	(a0)			;	*start = 0;
	move.w  _maxLines,d0	;	*stop = maxLines + 1;
	addq.w  #1,d0
	move.w  d0,(a1)
	rts

	xdef  _unsaveSplit    ;void unsaveSplit()
_unsaveSplit:
	move.w  _oldBuf,_splitBufNum	;	splitBufNum[0] = oldBuf;
	move.w  _oldStart,_startSplit	;	 startSplit[0] = oldStart;
	move.w  _oldStop,_stopSplit    ;	stopSplit[0] = oldStop;
	move.w  _oldSplit,_nSplit	;	 nSplit = oldSplit;
	move.w  _oldCurSplit,_curSplit    ;    curSplit = oldCurSplit;
	move.w  _oldCurSplit,_newSplit    ;    newSplit = oldCurSplit;
	rts

#endasm
#endif

#ifdef USEC

getBuf(register short bufNum)
{
register struct CB  **bf;
struct   DB 	*b;
register short  rtn;

	rtn = FALSE;
	if (bufNum<0 || bufNum>ALLBUFS) goto RTN;
	bf = &(buf[bufNum]);
	if (*bf == NULL) {  				 /* must allocate the buffer */
		if (newBuf(bufNum,bf)<0 || !newBlock(*bf,&b,NULL) ) {
			freeBuf(bufNum);
			goto RTN;
		}
	}
	rtn = TRUE;
RTN:
	return(rtn);
}

#endif

#ifndef USEC
#asm

							;getBuf(bufNum)
	xdef  _getBuf	  ;register short	 bufNum;
_getBuf:
	link	a5,#GTBP93
	movem.l GTBP94,-(sp)
	move.w  8(a5),d4		;{
							;register struct CB  **bf;
							;struct   DB		*b;
							;register short rtn;
	moveq	#0,d5			;	rtn = FALSE;
	tst.w	d4  		;	if (bufNum<0 || bufNum>ALLBUFS) goto RTN;
	blt GTBP95
	cmp.w	#100,d4
	bgt GTBP95
;;; moveq	#0,d0
	move.w  d4,d0			;	bf = &(buf[bufNum]);
	add.w	d0,d0
	add.w	d0,d0
;;; asl.l	#2,d0
	lea _buf,a2
	add.w	d0,a2
	tst.l	(a2)			;	if (*bf == NULL) {
	bne GTBP96
	move.l  a2,-(sp)		; if (newBuf(bufNum,bf)<0
	move.w  d4,-(sp)		;		|| !newBlock(*bf,&b,NULL) ) {
	jsr _newBuf
	tst.w	d0  	;;;
	addq.w  #6,sp
	blt GTBP98
	clr.l	-(sp)
	pea -4(a5)
	move.l  (a2),-(sp)
	jsr _newBlock
	tst.w	d0  	;;;
	lea 12(sp),sp
	bne GTBP97
GTBP98:
	move.w  d4,-(sp)		;		freeBuf(bufNum);
	jsr _freeBuf
	addq.w  #2,sp			;		goto RTN;
	bra GTBP95
GTBP97: 				;	}  }
GTBP96: 				;	rtn = TRUE;
	moveq	#1,d5
GTBP95: 				;RTN:
	move.l  d5,d0			;	return(rtn);
GTBP99:
	movem.l (sp)+,GTBP94
	unlk	a5
	rts
GTBP93: equ -4
GTBP94: reg d4/d5/a2

#endasm
#endif

#ifdef USEC

void copyNum(short flag)  /* INSISTS fastP be sitting on 1st digit */
{
register UCHAR     *fP,*x;
register short     i,hex;
register UCHAR     c;

	hex = FALSE;
	x = xnum;
	*x = 0x00;
	fP = fastP;
	i = *fP;
	if (i<'0' || i>'9') return;
	if (fP!=decFast()) {								   /* not at sFile */
		i = *fastP;
		if (i=='-' || i==flag)  *(x++) = '-';
		fP = incFast();
	}
	i = 0;
	if (*fP=='0') {
		c = *incFast();
		if (c=='x' || c=='X') {
			hex = TRUE;
			*(x++) = '0';
			*(x++) = 'x';
			i = 2;
			fP = incFast();
		} else fP = decFast();
	}

	while (i < 14) {
		c = *fP;
		if (c>='0' && c<='9') goto TAKEIT;
		if (hex) {
			if (c>='a' && c<='f') goto TAKEIT;
			if (c>='A' && c<='F') goto TAKEIT;
		}
		break;  										  /* end of number */
TAKEIT:
		*(x++) = c;
		fP = incFast();
		i++;
	}
	*x = 0x00;
	if (i==0) *xnum = 0x00;
}

long atole(register UCHAR *x)
{
register short   num,minus,ishex;
register long	val;

	val = 0L;
	minus = FALSE;
	ishex = FALSE;
	num = *x;
	if (ISWEIRD(num)) goto RTN;
	if (num=='-') { minus = TRUE; x++; }
	if (*x=='0') {
		x++;
		num = *x;
		if (num=='x' || num=='X') { ishex = TRUE; x++; }
	}
CONT:
	num = *(x++);
	if (num<'0') goto RTN;
	if (ishex) {
		if (num<='9') { val = (val << 4L) + (num - '0'); goto CONT; }
		if (num>='a' && num<='f') num -= ('a' - 'A');
		if (num<'A' || num>'F') goto RTN;
		num -= ('A' - 10);
		val <<= 4L;
		val += num;
		goto CONT;
	}
	if (num>'9') goto RTN;
	num -= '0';
	val = (val << 3L) + (val << 1L);
	val += num;
	goto CONT;
RTN:
	if (minus) val = -val;
	return(val);
}
#endif

#ifndef USEC
#asm
	xdef	_copyNum
_copyNum:
	movem.l	d2-d4/a2/a3,-(sp)		  ;RUCHAR*fP,*xRshorti,hexRUCHARchex=FALSE
	moveq	#0,d4			;x=xnum
	lea	_xnum,a3
;;;	move.l	a0,a3			;*x=0x00
	clr.b	(a3)			;fP=fastP
	move.l	_fastP,a2			;i=*fP
	moveq	#0,d3
	move.b	(a2),d3
;;;	move.w	d0,d3			;if(i<'0'||i>'9')return
	cmp.b	#48,d3
	blt	NV42
	cmp.b	#57,d3
	ble	NV10264
NV42:
NV43:
	movem.l	(sp)+,d2-d4/a2/a3
	rts 		;if(fP!=decFast()){/*notatsFile*/
NV10264:
	jsr	_decFast
	cmp.l	a2,d0
	beq	NV10265 		;i=*fastP
;;;	move.l	_fastP,a0
;;;	moveq	#0,d3
	move.b	(a1),d3
;;;	move.w	d0,d3			;if(i=='-'||i==flag)*(x++)='-'
	cmp.b	#45,d3
	beq	NV44
	cmp.w	28(sp),d3
	bne	NV10266
NV44:
	move.b	#45,(a3)+			;fP=incFast()
NV10266:
	jsr	_incFast
;;;	move.l	d0,a2			;}i=0
NV10265:
	moveq	#0,d3			;if(*fP=='0'){
	cmp.b	#48,(a1)
	bne	NV10267 		;c=*incFast()
	jsr	_incFast
;;;	move.l	d0,a0
	move.b	(a1),d2 		;if(c=='x'||c=='X'){
	cmp.b	#120,d2
	beq	NV45
	cmp.b	#88,d2
	bne	NV10268
NV45:			;hex=TRUE
	moveq	#1,d4			;*(x++)='0'
	move.b	#48,(a3)+			;*(x++)='x'
	move.b	#120,(a3)+  		;i=2
	moveq	#2,d3			;fP=incFast()
	jsr	_incFast
;;;	move.l	d0,a1			;}elsefP=decFast()
	bra	NV10269
NV10268:
	jsr	_decFast
;;;	move.l	d0,a1
NV10269:			;}while(i<14){
NV10267:
NV10270:
	cmp.b	#14,d3
	bge	NV10271 		;c=*fP
	move.b	(a1),d2 		;if(c>='0'&&c<='9')gotoTAKEIT
	cmp.b	#48,d2
	bcs	NV46
	cmp.b	#57,d2
	bls	NV10272
NV46:			;if(hex){
	tst.w	d4
	beq	NV10271 		;if(c>='a'&&c<='f')gotoTAKEIT
	cmp.b	#97,d2
	bcs	NV47
	cmp.b	#102,d2
	bls	NV10272
NV47:			;if(c>='A'&&c<='F')gotoTAKEIT
	cmp.b	#65,d2
	bcs	NV10271
	cmp.b	#70,d2
	bls	NV10272
;;;NV48:		   ;}break/*endofnumber*/
;;;NV10273:
	bra	NV10271 		;TAKEIT:
NV10272:			;*(x++)=c
	move.b	d2,(a3)+			;fP=incFast()
	jsr	_incFast
;;;	move.l	d0,a1			;i++
	addq.w	#1,d3			;}
	bra	NV10270
NV10271:			;*x=0x00
	clr.b	(a3)			;if(i==0)*xnum=0x00
	tst.w	d3
	bne	NV43
	clr.b	_xnum			;}
;;;NV10274:
	bra	NV43			;/*Ue19.c*/voidinitFolds(){

	xdef  _atole
_atole:
	movem.l JLABEL37,-(sp)
	move.l  24(sp),a2
							;register short   num,minus,ishex;
							;register long    val;
	moveq  #0,d7		;	val = 0L;
	moveq  #0,d5		;	minus = FALSE;
	moveq  #0,d6		;	ishex = FALSE;
	moveq  #0,d4		;	num = *x;
	move.b  (a2),d4
	cmp.w	#3,d4			;	if (ISWEIRD(num)) goto RTN;
	ble JLABEL38
	cmp.b	#45,d4  	;	if (num=='-') { minus = TRUE; x++; }
	bne JLABEL39
	moveq	#1,d5
	addq.w  #1,a2
JLABEL39:					;	if (*x=='0') {
	cmp.b	#48,(a2)
	bne JLABEL43
	addq.w  #1,a2			;		x++;
	moveq	#0,d4			;		num = *x;
	move.b  (a2),d4
	cmp.w	#120,d4 ;if(num=='x'||num=='X'){ishex=TRUE;x++;}
	beq JLABEL42
	cmp.w	#88,d4
	bne JLABEL43
JLABEL42:
	moveq	#1,d6
	addq.w  #1,a2
;JLABEL41:
;JLABEL40:  			;CONT:
JLABEL43:
	move.b  (a2)+,d4		;		num = *(x++);
	cmp.b	#48,d4  	;		if (num<'0') goto RTN;
	blt JLABEL38
	tst.w	d6  		;		if (ishex) {
	beq JLABEL44
	cmp.b	#57,d4  ;if(num<='9'){val=(val<<4L)+(num-'0');go
	bgt JLABEL45
	moveq	#0,d0
	move.w  d4,d0
	sub.w	#48,d0
	move.l  d7,d1
	asl.l	#4,d1
	move.l  d0,d7
	add.l	d1,d7
	bra JLABEL43	;to CONT; }
JLABEL45:				;if(num>='a'&&num<='f')num-=('a'-'A');
	cmp.b	#97,d4
	blt JLABEL46
	cmp.b	#102,d4
	bgt JLABEL46
	sub.w	#32,d4
JLABEL46:			;		if (num<'A' || num>'F') goto RTN;
	cmp.b	#65,d4
	blt JLABEL38
	cmp.b	#70,d4
	bgt JLABEL38
	sub.w	#55,d4  	;			num -= ('A' - 10);
	asl.l	#4,d7			;			val <<= 4L;
	moveq	#0,d0
	move.w  d4,d0			;			val += num;
	add.l	d0,d7
	bra JLABEL43			;			goto CONT;
JLABEL44:					;		if (num>'9') goto RTN;
	cmp.b	#57,d4
	bgt JLABEL38
	sub.w	#48,d4  	;		num -= '0';
	move.l  d7,d0			;		val = (val << 3L) + (val << 1L);
	asl.l	#3,d0
	move.l  d7,d1
	add.l	d1,d1		;asl.l   #1,d1
	move.l  d0,d7
	add.l	d1,d7
	moveq	#0,d0
	move.w  d4,d0			;		val += num;
	add.l	d0,d7
	bra JLABEL43			;		goto CONT;
JLABEL38:					;RTN:
	tst.w	d5  		;	if (minus) val = -val;
	beq JLABEL47
	neg.l	d7
JLABEL47:					;	return(val);
	move.l  d7,d0
JLABEL48:
	movem.l (sp)+,JLABEL37
	rts
JLABEL37:	reg d4-d7/a2

#endasm
#endif

#ifdef USEC

onScreen(	struct DB *b,
			UCHAR *p)
{
register struct CB    *curB;
register UCHAR  *pp;
register short  oldCur,rtn;
register ULONG  locPt,locEP;

	rtn = TRUE;
	curB   = curBuf;
	locPt  = (ULONG)loc(b,p);
	pp = curB->EPtr;
	locEP  = (ULONG)loc(curB->EBlock,pp);
	oldCur = oldCursorCol;
	if (locPt <  (ULONG)loc(curB->PBlock,curB->PPtr) ||
				locPt > locEP  || (*pp!=EOFILE && locPt==locEP) ||
				oldCur < 1 || oldCur > maxLineChars) rtn = FALSE;
	return(rtn);
}

#endif

#ifndef USEC
#asm

							;onScreen(b,p)
							;struct DB *b;
							;UCHAR *p;
	xdef  _onScreen
_onScreen:
	movem.l d2/d3/d6/d7/a2/a3,-(sp)
							;register struct CB    *curB;
							;register UCHAR *pp;
							;register short oldCur,rtn;
							;register ULONG locPt,locEP;
	moveq	#1,d0			;	rtn = TRUE;
	moveq	#16,d1
	move.l  _curBuf,a2  ;	curB   = curBuf;
	move.l  104(a2),a3  ;	pp = curB->EPtr;

	move.l  28(sp),a0		;	locPt  = (ULONG)loc(b,p);
	moveq	#0,d2
	move.w  246(a0),d2
	asl.l	d1,d2
	add.l	32(sp),d2
	move.l  d2,d6
	sub.l	28(sp),d6	; locPt

	move.l  24(a2),a0	;	locEP  = (ULONG)loc(curB->EBlock,pp);
	moveq	#0,d2
	move.w  246(a0),d2
	asl.l	d1,d2
	add.l	a3,d2
	move.l  d2,d7
	sub.l	24(a2),d7		; locEP

	move.w  _oldCursorCol,d3 ;   oldCur = oldCursorCol;
			;if(locPt<(ULONG)loc(curB->PBlock,curB->PPtr)||
			; locPt>locEP||(*pp!=EOFILE&&locPt==locEP)
			; ||
	move.l  20(a2),a0	;oldCur<1||oldCur>maxLineChars)rtn=FALS
	moveq	#0,d2
	move.w  246(a0),d2
	asl.l	d1,d2
	add.l	100(a2),d2
	sub.l	20(a2),d2
	cmp.l	d2,d6
	bcs YYYY14
	cmp.l	d7,d6
	bhi YYYY14
	cmp.b	#3,(a3)
	beq YYYY15
	cmp.l	d7,d6
	beq YYYY14
YYYY15:
	cmp.w	#1,d3
	blt YYYY14
	cmp.w	_maxLineChars,d3
	ble YYYY13
YYYY14:
	moveq	#0,d0
YYYY13: 				;	return(rtn);
	movem.l (sp)+,d2/d3/d6/d7/a2/a3
	rts

#endasm
#endif

static short saveDisplay;

#ifdef USEC

FupdateDisplay()
{
register short rtn;

	rtn = FALSE;
	if (showTitle) { setTitle(); rtn = TRUE; }
	if (displayFlag) { display(); rtn = TRUE; }
	return(rtn);
}

FrefreshDisplay()
{
	displayFlag |= (PAGE_ << curSplit);
	setTitle();
	display();
	return(TRUE);
}

FfullRefresh()
{
	displayFlag = ALLPAGE;
	setTitle();
	display();
	return(TRUE);
}

void onDisplay()
{
	if (noDisplay && tiny==0) {
		cleared = 0;
		restoreMsg();
		noDisplay = 0;
		FfullRefresh();
	}
}

void flipDisplay()
{
	onDisplay();
	if (hideDisplay)  hideDisplay = FALSE;
	else  hideDisplay = TRUE;
}

void forceRefresh()
{
register short i;

	if (tiny) return;
	i = noDisplay;
	noDisplay = 0;
	FfullRefresh();
	noDisplay = i;
}

void saveDis()
{
	if (tiny) return;
	forceRefresh();
	saveDisplay = noDisplay;
	noDisplay = 0;
}

void unsaveDis()
{
	if (tiny) return;
	forceRefresh();
	noDisplay = saveDisplay;
}

#endif

#ifndef USEC
#asm

	xdef  _FupdateDisplay
_FupdateDisplay:
	move.l d4,-(sp)
	moveq	#0,d4
	tst.w	_showTitle
	beq TESTTT4
	jsr _setTitle
	moveq	#1,d4
TESTTT4:
	tst.w	_displayFlag	; if (displayFlag) {
	beq TESTT4  			;	display() ; return(TRUE) ; }
	jsr _display
	moveq	#1,d4
TESTT4:
	move.l  d4,d0
	move.l (sp)+,d4
	rts

	xdef  _FrefreshDisplay
_FrefreshDisplay:
	moveq	#16,d0
	move.w  _curSplit,d1		; displayFlag |= (PAGE_ << curSplit) ;
	asl.w	d1,d0
	or.w	d0,_displayFlag ; setTitle() ;
	jsr _setTitle				; display() ;
	jsr _display				; return(TRUE) ;
	moveq	#1,d0
	rts

	xdef  _FfullRefresh
_FfullRefresh:
	or.w	#-16,_displayFlag	; displayFlag |= ALLPAGE ;
	jsr _FrefreshDisplay		; FrefreshDisplay() ;
	rts

	xdef  _onDisplay
_onDisplay:
	tst.w	_noDisplay  ; if (noDisplay && tiny==0) {
	beq TESTT14 		;
	tst.w	_tiny
	bne TESTT14 		 ;
	clr.w	_cleared		; cleared = 0 ; noDisplay = 0 ;
	jsr _restoreMsg
	clr.w	_noDisplay  ; FfullRefresh() ;
	jsr _FfullRefresh
TESTT14:
	rts

	xdef  _flipDisplay
_flipDisplay:
	jsr _onDisplay  		; if (hideDisplay) hideDisplay = FALSE ;
	tst.l	_hideDisplay
	beq TESTT18
	clr.l	_hideDisplay		; else hideDisplay = TRUE ;
	bra TESTT19
TESTT18:
	move.l  #1,_hideDisplay
TESTT19:
	rts

	xdef  _forceRefresh
_forceRefresh:
	move.l d4,-(sp) 		;register short i ; i = noDisplay ;
	tst.w	_tiny
	bne TESTT99
	move.w  _noDisplay,d4		; noDisplay = 0 ;
	clr.w	_noDisplay  	; FfullRefresh() ;
	jsr _FfullRefresh			; noDisplay = i ;
	move.w  d4,_noDisplay		;}
TESTT99:
	move.l (sp)+,d4
	rts

	xdef  _saveDis
_saveDis:
	tst.w	_tiny
	bne TESTT98
	jsr _forceRefresh
	move.w  _noDisplay,_saveDisplay
	clr.w	_noDisplay
TESTT98:
	rts

	xdef  _unsaveDis
_unsaveDis:
	tst.w	_tiny
	bne TESTT97
	jsr _forceRefresh
	move.w  _saveDisplay,_noDisplay
TESTT97:
	rts

#endasm
#endif
