/* --------------------------- Ue14.c ------------------------- */

#include "uedit.h"

Freformat() 						/* Assumes fast == curBuf cursor */
{
register struct CB  	*curb;
register short  		nextC,spacing,spaces,hyphening,lastC,eoline;
short					rtn;
long					saveFlags;
long					savecol;
struct DB				*iBlock;
UCHAR					*iPtr;

	curb = curBuf;
	if (!canChange(curb)) return(FALSE);
	rtn = visible = lastC = 0;
	eoline = eol;
	savecol = columnar;
	columnar = 0L;
	saveFlags = curb->Flags | CHANGED | NEEDPACK;
	curb->Flags |= (WORDWRAP | OVERSTRIKE | AUTOINDENT);
	popFast();  									 /* fast to cursor */

	if (*fastP==EOFILE) {
FALSERTN:
		popFast();
		goto RTNPOINT;
	}
	
	spaces = curb->LineLength - 3;
	spacing = curb->LeftMargin;
	if (spacing>=spaces) goto FALSERTN;
	
	solFast();
WHILEBLANK: /* find sPar */
	if (!blankLineFast()) goto NOTBLANK;  /* sets INDENT */
	nextC = *fastP;
	if (nextC != eoline && nextC != 12) eLineFast();
	if (*incFast()==EOFILE) goto FALSERTN;
	goto WHILEBLANK;

NOTBLANK:											/* fast at spar sol */
	if (indent>=spaces) goto FALSERTN;
	
	iBlock = fastB; 				 /* insert point for insertChar() */
	iPtr = fastP;
	eParFast(); 								 /* skips cursor line */
	curb->MBlock = fastB;
	curb->MPtr = fastP;

	reformatting = TRUE;
	fastB = iBlock; 						 /* set to insertion block */
	fastP = iPtr;
	gcol = -1;
	if (spacing>0) {
		takeFast();
		if (!insertChar(eoline)) goto RTNPOINT;
		untakeFast();
		solFast();
		decFast();
		*fastP = 0x00;
		iPtr = fastP;
		incFast();
		matchPtrs((UCHAR **)curb,(ULONG)fastB,(ULONG)iPtr,(ULONG)fastP);
	}
	hyphening = spacing = spaces = wrap = 0;
	while (*fastP==' ' || *fastP==TAB) incFast();
	takeFast(); 					 /* cursor here for insertChar() */
	flipRight = 1;
	while (1) { 									 /* quit at eop */
		if (fastP==curb->MPtr) break;
		nextC = *fastP;
		if (nextC<' ') {
			if (nextC==TAB || nextC==eoline) {
				if (nextC==eoline) {
					fastB->eols = 255;
				}
				if (nextC==TAB) *fastP = ' ';
				else
				if (!(spacing && spaces==0 && indent==0)) *fastP = ' ';
				nextC  = ' ';
			}
		}
		if (hyphening) {
			if (nextC==' ') goto DELPT;
			hyphening = 0;
		}
		if (spacing) {
			if (nextC=='"' || nextC==')') goto INSPOINT; /* " */
		}
		if (nextC>='A') goto FASTER;
		if ((nextC=='-' || nextC=='/') && !spaces &&
				lastC!='-' && lastC!='/') hyphening = 1;
		if (nextC==' ') {
			if (++spaces==1) goto INSPOINT;
			if (spacing && spaces==2) { spacing = 0; goto INSPOINT; }
DELPT:  	nextC = DEL;
			goto INSPOINT;
		}
		if (nextC=='.' || nextC=='?' || nextC=='!' || nextC==':') {
			spacing = TRUE;
			goto INSPOINT;
		}
FASTER:
		spaces = spacing = 0;
INSPOINT:
		lastC = nextC;
		if (!insertChar(nextC)) goto RTNPOINT;
	}
	rtn = TRUE;
DELMORE:
	decFast();
	if (*fastP==' ' || *fastP==TAB) { *fastP = 0x00; incFast(); goto DELMORE; }
	incFast();
	fixPtrs(curb,(ULONG)fastB,(ULONG)fastP);

RTNPOINT:
	reformatting = FALSE;
	columnar = savecol;
	curb->Flags = saveFlags;
	takeFast();
	shiftit(curb);
	fixSOF(curb);
	popFast();
	displayFlag |= ((PAGE_ << curSplit) | SHOWCURSOR_);
	visible=1;
	return(rtn);
}

#ifdef USEC

FstackBuf()
{
register short  i,flag;
register struct CB *bp;
struct CB		*bpp;

	i = (short)*longPtrArgs[0];
	if (i<MAXFILES || i>=ALLBUFS) goto BRTN;
	flag = (short)*longPtrArgs[1];
	if (flag == -2) {										 /* get status */
		flag = bufferFlags[i];
		*longPtrArgs[1] = flag;
		return(flag);
	}
	if (flag == -1) {									/* clear the stack */
		bp = buf[0];
		while (pop(&(bStack[i]),&bpp)) if (bpp) {
			buf[0] = bpp;
			freeBuf(0);
		}
		buf[0] = bp;
		bufPopStack[i] = 0;
RTN:
		return(TRUE);
	}
	if (flag >= 0) { 
		bufferFlags[i] = flag;
		goto RTN;
	}
BRTN:
	return(FALSE);
}

#endif

void seeRuler(short flag)
{
register	UCHAR	*p,*tabs;
register	short	j,k,n,wid;
short				max,cch,ln;
long				l0,l1,l2;
struct CB *curb;
UCHAR				z[128];

	curb = curBuf;
	tabs = tabTables[curb->tabTable];
	ln = oldCursorLine - 3;
	if (ln>=maxLines || ln<2) ln = 2;
	l0 = lineHeight[ln];
	l1 = lineHeight[ln+1];
	l2 = lineHeight[ln+2];
	SetDrMd(rp,(long)JAM2);
	setColors(rulerVid);
/* --------------
	SetAPen(rp,(long)wid);
	SetBPen(rp,(long)n);
------------- */
	
	if (flag) RectFill(rp,0L,l0 + 2L,
					(long)(horPixels - 1), l2 + 1L);
/* --------------
	SetAPen(rp,(long)k);
	SetBPen(rp,(long)wid);
------------- */
	cch = charHeight;
	if (cram) cch--;
	wid = charWidth >> 1;
	max = (horPixels - wid)/charWidth;
	z[0] = '#';   z[1] = curb->tabTable + '0';   z[2] = ' ';
	p = &z[3];
	if (flag) {
		for (j = 3; j<max; j++) {
			n = j + curb->PageCol + 4;
			*p = ' ';
			if ( (n % 10) == 0 ) {
				if (n/1000) *p = '0' + ((n/1000) % 10);
				*(++p) = ' ';
				if (n/100)  *p = '0' + ((n/100) % 10);
				*(++p) = ' ';
				if (n/10)	*p = '0' + ((n/10) % 10);
				*(++p) = '0';
				*(++p) = ' ';
				*(++p) = 0x00;
				j += 4;
			} else p++;
		}
		Move(rp,(long)wid,l1);
		Text(rp,z,(long)max);
	}
	p = z;
	for (j = 0; j<max; j++,p++) {
		k = j + curb->PageCol + 1;
		*p = ' ';
		while (*tabs && *tabs<k) tabs++;
		if (*tabs==k) {
				if (*(++tabs)==0) *p = 'X';
				else *p = '^';
		}
	}
	Move(rp,0L,l2);
	Text(rp,z,(long)max);
	j = curb->PageCol + 1;
	max = horPixels - 1;
	for (k=-1; k<max; k += charWidth,j++) {
		n = l2;
		if ( (j % 10)==0) n -= cch;
		else if ( (j % 5)==0) n -= (cch - 2);
		else n -= (cch >> 1);
		Move(rp,(long)k + wid,l2);
		Draw(rp,(long)k + wid,(long)n);
	}
	displayFlag |= ALLPAGE;
	setColors(normalVid);
}

FsetRuler()
{
register UCHAR  *tabs;
register struct CB  *curb;
register short  k,col,i,j;
short				cch,flag,saveCursorLine,cancel;
UCHAR				saveTabs[MAXTABS + 1];

	saveDis();
	saveCursorLine = oldCursorLine;
	if (oldCursorLine<2) oldCursorLine = 3;
	else if (oldCursorLine>=stopSplit[curSplit]) oldCursorLine = 3;
	i = lineHeight[oldCursorLine - 2];
	cch = charHeight;
	if (cram) cch--;
	curb = curBuf;
	tabs = tabTables[curb->tabTable];
	strcpy(saveTabs,tabs);
	seeRuler(TRUE);
	flag = 0;
	while (1) {
		mouseY = 0;
		if (nextEvent()) {
			j = gChar;
			if (j==TAB) {
				col = *tabs - 1;
				k = 1;
				if (col<0) { col = 4; *tabs = 5; goto DOMORE; }
				if (col==0) {
					if (tabs[1]==0) tabs[1] = 5;
					if (tabs[1]) { k=2; col = tabs[1] - 1; }
				}
				for (; k<MAXTABS; k++)
					if (tabs[k]!=(col + tabs[k-1]) ) break;
				if (k<MAXTABS && (col=(tabs[k-1]+col))<=255)
										tabs[k] = col;
				goto DOMORE;
			}
			if (j==BS) {
				for (k = 0; k<MAXTABS; k++) if (tabs[k]>0) tabs[k]--;
				goto DOMORE;
			}
			if (j==' ') {
				for (k = 0; k<MAXTABS; k++) if (tabs[k]>0) tabs[k]++;
				goto DOMORE;
			}
			if (j==DEL) {
				for (k=0; k<MAXTABS; k++) tabs[k] = 0;
				goto DOMORE;
			}
			if (mouseDown) {
				k = mouseX;
				soakInputs();
				col = (k - mouseX)/(charWidth >> 1);
				if (!col) goto DOLESS;
				if (-col > 40) col = -curb->PageCol;
				if (-col > curb->PageCol) col = -curb->PageCol;
				curb->PageCol += col;
				displayFlag |= HSCROLL_;
				hscrollamt = col;
				flag = TRUE;
				goto DOMORE;
			}
DOLESS:
			if (mouseY>= i && mouseY<=(i + (cch << 2)) ) {
				col = curb->PageCol + 1 + (mouseX - 2)/charWidth;
				for (k = cancel = 0, j = -1 ; k<MAXTABS; k++)
				if (tabs[k]==col) {
					tabs[k] = 0;
					cancel = TRUE;
					break;
				} else if (tabs[k]==0 && j==-1) j = k;
				if (col == 1) flag = TRUE;
				if (!cancel && j>=0) tabs[j] = col;
				displayFlag = (PAGE_ << curSplit);
DOMORE:
/* =============== new new ================ */
				sortTabs(curb->tabTable);
				if (flag) forceRefresh(); /* display() */
				seeRuler(flag);
				flag = FALSE;
				gChar = 0;
			} else /* === if (gChar || mouseY) ==== */  goto BREAKOUT;
		} else if (!busyWork()) waite();
		if (stopPause || gChar) break;
	}
BREAKOUT:
	if (stopPause) strcpy(tabs,saveTabs);  /* restore old */
	soakInputs();
	oldCursorLine = saveCursorLine;
	unsaveDis();
	return(TRUE);
}

/* DOC:  gettabs/settabs: These are guaranteed to follow each with a space */

FprinterCode()
{
register UCHAR  *zz;
register struct CB   *bufPtr;
register short  bufNum,a1,a2,i;
short				rtn;
UCHAR				z[6];

	rtn = FALSE;
	bufNum = *longPtrArgs[0];
	if (!getBuf(bufNum)) goto FALSERTN;
	bufPtr = buf[bufNum];
	if (!canChange(bufPtr)) goto FALSERTN;

	i = *longPtrArgs[1];
	if (i<0 || i>75) goto FALSERTN;
	zz = z;
	zz[0] = ESC;
	zz[1] = ' ' + i;
	a1 = (short) *longPtrArgs[2];
	a2 = (short) *longPtrArgs[3];
	i = 2;
	if (a1<0 || a2<0 || a1>223 || a2>223) goto FALSERTN;
	zz[2] = a1 + ' ';
	zz[3] = a2 + ' ';
	if (a2>0) i = 4;
	if (i==2 && a1>0) i = 3;
	zz[i++] = ESC;

	pushFast(bufPtr,&(bufPtr->Block),&(bufPtr->Ptr));
	stickMode = 0;
	while (i--) if (!stickChar(*(zz++))) goto FALSERTN;
	takeFast();
	/* ============ SHOULD NOT NEED THIS!!!!!!!!!! ================ */
	fixPtrs((UCHAR **)bufPtr,(ULONG)fastB,(ULONG)fastP);
	rtn = TRUE;

FALSERTN:

	popFast();
	displayFlag |= SHOWCURSOR_; /* splitFlag(bufNum, SHOWCURSOR_); */
	return(rtn);
}

#ifdef USEC

FgetTabs()  		/* getTabs(buffer,tableNum) inserts them at cursor */
{
register	UCHAR	*p,*tabs;
register	short	tableNum,bufNum;
UCHAR				t[256];

	tableNum = *longPtrArgs[1];
	if (tableNum<0 || tableNum>4) goto FRTN;
	bufNum = *longPtrArgs[0];
	if (!getBuf(bufNum)) goto FRTN;
	tabs = tabTables[tableNum];
	*t = 0x00;
	while (*tabs) {
		catNumber(t,(long)*tabs,DATASIZE);
		strncatmax(t," ",DATASIZE);
		tabs++;
	}
	p = t;
	fastBufPtr = buf[bufNum];
	fastB = fastBufPtr->Block;
	fastP = fastBufPtr->Ptr;
	stickMode = 0;
	while (*p) if (!stickChar(*(p++))) goto FRTN;
	popFast();
	return(TRUE);
FRTN:
	popFast();
	return(FALSE);
}

FnameBuffer()
{
register UCHAR  *x;
register struct CB *bufPtr;
register short  i;

	i = *longPtrArgs[0];
	if (i<MAXFILES || i>=ALLBUFS) goto FRTN;
	x = ptrArgs[1];
	if (*x<=' ' || strlen(x)>63) goto FRTN;
	bufferNames[i] = x;
	bufPtr = buf[i];
	if (bufPtr!=NULL) bufPtr->FileName[0] = 0x00;
	return(TRUE);
FRTN:
	return(FALSE);
}

FseeRuler()
{
	saveDis();
	seeRuler(TRUE);
	while (!collectRaw()) {
		if (stopPause) break;
		if (!busyWork()) waite();
	}
	unsaveDis();
	return(TRUE);
}

FcompareBuf()	/* uses cursor, goes from cursor fwd */
{
struct CB		*bp1,*bp2;
struct DB		*b1,*b2;
register UCHAR  *p1,*p2;
register UCHAR  c1,c2;

	bp1 = bufPtrArgs[0];
	bp2 = bufPtrArgs[1];

	if (bp1==NULL || bp2==NULL) return(FALSE);

	p1 = bp1->Ptr; b1 = bp1->Block;
	p2 = bp2->Ptr; b2 = bp2->Block;

	while (1) {
AGAIN1:
		c1 = *p1;
		if (c1<=EOFILE) {
			while (c1==0x00) { p1++; c1 = *p1; }
			if (c1==EOB) {
				b1 = b1->NextBlock;
				p1 = b1->Data;
				goto AGAIN1;
			}
		}
AGAIN2:
		c2 = *p2;
		if (c2<=EOFILE) {
			while (c2==0x00) { p2++; c2 = *p2; }
			if (c2==EOB) {
				b2 = b2->NextBlock;
				p2 = b2->Data;
				goto AGAIN2;
			}
			if (c2==EOFILE) break;
		}
		if (c1==EOFILE) break;
		if (c1 != c2) break;
		p1++; p2++;
	}
	bp1->Ptr = p1; bp1->Block = b1;
	bp2->Ptr = p2; bp2->Block = b2;

	fastBufPtr = bp1; fastB = bp1->Block; fastP = bp1->Ptr;
	incFast(); sLineFast();
	bp1->PPtr = fastP; bp1->PBlock = fastB;

	fastBufPtr = bp2; fastB = bp2->Block; fastP = bp2->Ptr;
	incFast(); sLineFast();
	bp2->PPtr = fastP; bp2->PBlock = fastB;

	popFast();
	splitFlag(bp1->BufNum, PAGE_);
	splitFlag(bp2->BufNum, PAGE_);
	return( (c1==c2) ? TRUE : FALSE );
}

FswapLoc()
{
register struct CB *bufPtr;

	bufPtr = bufPtrArgs[0];
	if (bufPtr==NULL) return(FALSE);
	swapLoc(bufPtr,args[1],args[2]);
	return(TRUE);
}

void swapLoc(	register UCHAR **ov,
				register short loc1,
				register short loc2)
{
register UCHAR *j;

		if (ov==NULL) return;
		loc1 -= atCursor_; loc2 -= atCursor_;
		j = ov[loc1]; ov[loc1] = ov[loc2]; ov[loc2] = j;
		loc1 += CBOVL; loc2 += CBOVL;
		j = ov[loc1]; ov[loc1] = ov[loc2]; ov[loc2] = j;
}

inSplit(register short y)
{
register short  *lh,*s;
register short  i,ns,ii,jj;

	ns = nSplit;
	lh = lineHeight;
	s = startSplit;
	for (i=0; i<=ns; i++) {
		ii = s[i];
		jj = stopSplit[i];
		if ( y >= lh[ii] && y < lh[jj] ) return(i);
	}
	return(curSplit);
}

void splitFlag( register short bufn,
				register short flag)
{
register short *s;
register short i,ns,jj,kk;

	s = splitBufNum;
	i = curSplit;
	jj = displayFlag;
	if (bufn==s[i]) {
		kk = flag & 15; 	/* writing this shit for crappy manx compiler */
		jj |= kk;			/* spoonfeed it in hopes of better output */

		flag &= PAGE_;
		flag <<= i;
		jj |= flag;
		displayFlag = jj;
		return;
	}
	ns = nSplit;
	for (i=0; i<=ns; i++) {
		if (bufn==s[i])  {
			kk = PAGE_ << i;
			jj |= kk;
			displayFlag = jj;
			return;
		}
	}
}

void fixSplit()
{
register short  	*s;
register struct CB  **bufPtr;
register short  	i,j,k,splits;

	splits = nSplit;
	if (splits>0) {
		s = splitBufNum;
		j = curBuf->BufNum;
		bufPtr = buf;
		for (i=0; i<=splits; i++) {
			k = s[i];
			if (bufPtr[k]==NULL) {
				if (k<MAXFILES || !getBuf(k)) s[i] = j;
				displayFlag |= (PAGE_ << i);
				showTitle = TRUE;
			}
		}
	}
}

void swapSplit(register short new)
{
register short  *s;
register struct CB *bufPtr;
register short  j,newbufnum,oldbufnum,old,splits;
short			lowestNew,lowestOld;

	j = nSplit;
	old = curSplit;
	if (j==0 || new==old || new>j) return;

	s = splitBufNum;

	newbufnum = s[new];
	bufPtr = buf[newbufnum];
	if (bufPtr==NULL) return;

	oldbufnum = s[old];

	splits = j;

	lowestOld = lowestNew = -1;
	for (j=0; j<=splits; j++) {
		if (s[j]==newbufnum && lowestNew == -1) lowestNew = j;
		if (s[j]==oldbufnum && lowestOld == -1) lowestOld = j;
	}

	if (new>lowestNew) {
		swapLoc(bufPtr,atCursor_,locSC_);
		swapLoc(bufPtr,sPage_,   locSP_);
	}
	if (old>lowestOld) {
		swapLoc(curBuf,atCursor_,locSC_);
		swapLoc(curBuf,sPage_,   locSP_);
	}

	curBuf = bufPtr;
	curSplit = new;
	newSplit = new;
	switchFast();
	displayFlag |= (PAGE_ << new);
}

FsplitWindow()
{
register short  *s1,*s0;
register short  i,k,splits,lines;
register short  start,dropSplit;
short			bufNum;

	bufNum = (short) *longPtrArgs[0];
	lines  = (short) *longPtrArgs[1];
	splits = nSplit;
	s1 = stopSplit;
	s0 = startSplit;
	if (lines<2) {  									/* terminate split */
		if (splits==0) goto FRTN;							  /* no splits */
		start = dropSplit = -1; 							/*  find split */
		for (k=splits; k>=0; k--) {
			if (bufNum == splitBufNum[k]) {
				if (dropSplit == -1) dropSplit = k; 	/* hi bufnum split */
				start = k;  							/* lo bufnum split */
			}
		}
		if (dropSplit<0) goto FRTN; 					/* no bufnum split */

		k = dropSplit;  						 /* UPPERMOST bufnum split */
								/* if bufNum curBuf, dropSplit is curSplit */
		if (buf[bufNum]==curBuf) dropSplit = curSplit;

		if (start!=k) { 					 /* 2 or more splits on bufnum */
			i = dropSplit + 1;
			if (i>splits) i = splits - 1;
			swapSplit(i);
		}

		i = dropSplit;
		start = s0[i];
		lines = s1[i] - s0[i];
		while (i<splits) {  							 /* i is dropsplit */
			splitBufNum[i] = splitBufNum[i+1];     /* shift array downward */
			s0[i] = s0[i+1];
			s1[i] = s1[i+1];
			i++;
		}

		i = 0;
		while (i<dropSplit) {
			s1[i] += lines;
			s0[i] += lines;
			i++;
		}

		nSplit = --splits;

		i = curSplit;
		if (i>splits) i = splits;
		curSplit = i;
		newSplit = i;
		dropSplit = splitBufNum[i];
		curBuf = buf[dropSplit];

		if (dropSplit!=bufNum) {
			bufNum = dropSplit;
			start = dropSplit = -1;
			for (k=splits; k>=0; k--) {
				if (bufNum == splitBufNum[k]) {
					if (dropSplit == -1) dropSplit = k; /* hi bufnum split */
					start = k;  						/* lo bufnum split */
				}
			}
			if (curSplit!=start) {
				swapLoc(curBuf,atCursor_,locSC_);
				swapLoc(curBuf,sPage_,   locSP_);
			}
		}
		switchFast();
	} else {											/* create a split */
		if (splits >= (MAXSPLITS-1)) goto FRTN;
		if (!getBuf(bufNum)) goto FRTN;

		i = s1[0] - s0[0];
		if ( ++lines < 3) lines=3;
		if ( (i-lines) < 3 ) goto FRTN;
/* swapSplit(0); */

		i = splits + 1;
		while (i>1) {
			s1[i] = s1[i-1];
			s0[i] = s0[i-1];
			splitBufNum[i] = splitBufNum[i-1];
			i--;
		}

		s1[1]  = s1[0]; 		/* stop1 = stop0 */
		s1[0] -= lines; 		/* stop0 -= lines */
		s0[1] = s1[0];  		/* start1 = stop0 + 1 */

		nSplit = ++splits;

		splitBufNum[1] = bufNum;
		if (curSplit>0) curSplit++;
		swapSplit(1);
	}
	s0[0] = 0;
	s1[nSplit]  = maxLines + 1;
	showTitle = TRUE;	/* setTitle(); */
	displayFlag |= ALLPAGE;
	return(TRUE);
FRTN:
	return(FALSE);
}

FgotoSplit()
{
register short *s;
register short i,bufNum,ns;

	ns = nSplit;
	if (ns==0) goto FRTN;
	bufNum = (short)*longPtrArgs[0];
	s = splitBufNum;
	i = curSplit;
	while (1) {
		if (++i>ns) i = 0;
		if (i==curSplit) goto FRTN;
		if (s[i]==bufNum) {
			if (!getBuf(bufNum)) goto FRTN;
			swapSplit(i);
			showTitle = TRUE; /* setTitle(); */
			return(TRUE);
		}
	}
FRTN:
	return(FALSE);
}

#endif

#ifndef USEC
#asm
	XREF	_args
	XREF	_blankLineFast
	XREF	_bStack
	XREF	_buf
	XREF	_bufferFlags
	XREF	_bufferNames
	XREF	_bufPopStack
	XREF	_bufPtrArgs
	XREF	_busyWork
	XREF	_canChange
	XREF	_catNumber
	XREF	_collectRaw
	XREF	_columnar
	XREF	_curBuf
	XREF	_curSplit
	XREF	_decFast
	XREF	_displayFlag
	XREF	_eLineFast
	XREF	_eol
	XREF	_eParFast
	XREF	_fastB
	XREF	_fastBufPtr
	XREF	_fastP
	XREF	_fixPtrs
	XREF	_fixSOF
	XREF	_flipRight
	XREF	_freeBuf
	XREF	_gcol
	XREF	_getBuf
	XREF	_incFast
	XREF	_indent
	XREF	_insertChar
	XREF	_longPtrArgs
	XREF	_matchPtrs
	XREF	_MAXFILES
	XREF	_maxLines
	XREF	_newSplit
	XREF	_nSplit
	XREF	_pop
	XREF	_popFast
	XREF	_ptrArgs
	XREF	_reformatting
	XREF	_saveDis
	XREF	_seeRuler
	XREF	_setTitle
	XREF	_shiftit
	XREF	_showTitle
	XREF	_sLineFast
	XREF	_solFast
	XREF	_splitBufNum
	XREF	_splitFlag
	XREF	_startSplit
	XREF	_stickChar
	XREF	_stickMode
	XREF	_stopPause
	XREF	_stopSplit
	XREF	_strlen
	XREF	_strncatmax
	XREF	_swapSplit
	XREF	_switchFast
	XREF	_tabTables
	XREF	_takeFast
	XREF	_unsaveDis
	XREF	_untakeFast
	XREF	_visible
	XREF	_waite
	XREF	_wrap

	xdef	_swapSplit
_swapSplit:
	link	a5,#SP6
	movem.l	d2-d7/a2/a3,-(sp)
	move.w	8(a5),d3			;Rshort*sRstructCB*bufPtrRshortj,newbufnum,oldbufnum,old,splitsshortlowestNew,lowestOldj=nSplit
	move.w	_nSplit,d2  		;old=curSplit
	move.w	_curSplit,d4			;if(j==0||new==old||new>j)return
	tst.w	d2
	beq	SP7
	cmp.w	d4,d3
	beq	SP7
	cmp.w	d2,d3
	ble	SP10019
SP7:
SP8:
	movem.l	(sp)+,d2-d7/a2/a3
	unlk	a5
	rts 		;s=splitBufNum
SP10019:
	lea	_splitBufNum,a0
	move.l	a0,a2			;newbufnum=s[new]
	move.w	d3,d0
	add.w	d0,d0
	move.w	(a2,d0.w),d7			;bufPtr=buf[newbufnum]
	move.w	d7,d0
;;;	asl.l	#2,d0
	add.w	d0,d0
	add.w	d0,d0
	lea	_buf,a0
	move.l	(a0,d0.w),a3			;if(bufPtr==NULL)return
	move.l	a3,d0
	beq SP8 		;oldbufnum=s[old]
SP10020:
	move.w	d4,d0
	add.w	d0,d0
	move.w	(a2,d0.w),-2(a5)			;splits=nSplit
	move.w	d2,-4(a5)	;;;_nSplit,-4(a5)		   ;lowestOld=lowestNew=-1
	moveq	#-1,d5
	move.w	d5,d6			;for(j=0j<=splitsj++){
	moveq	#0,d2
	bra	SP10024
SP10023:			;if(s[j]==newbufnum&&lowestNew==-1)lowestNew=j
	move.w	d2,d0
	add.w	d0,d0
	move.w	(a2,d0.w),d0
	cmp.w	d7,d0
	bne	SP10025
	cmp.w	#-1,d5
	bne	SP10025
	move.w	d2,d5			;if(s[j]==oldbufnum&&lowestOld==-1)lowestOld=j
SP10025:
	move.w	d2,d0
	add.w	d0,d0
	move.w	(a2,d0.w),d0
	cmp.w	-2(a5),d0
	bne	SP10026
	cmp.w	#-1,d6
	bne	SP10026
	move.w	d2,d6			;}
SP10026:
SP10021:
	addq.w	#1,d2
SP10024:
	cmp.w	-4(a5),d2
	ble	SP10023
SP10022:			;if(new>lowestNew){
	cmp.w	d5,d3
	ble	SP10027 		;swapLoc(bufPtr,atCursor_,locSC_)
	move.w	#117,-(sp)
	move.w	#99,-(sp)
	move.l	a3,-(sp)
	jsr	_swapLoc			;swapLoc(bufPtr,sPage_,locSP_)
	move.w	#116,-(sp)
	move.w	#104,-(sp)
	move.l	a3,-(sp)
	jsr	_swapLoc			;}if(old>lowestOld){
	lea	16(sp),sp
SP10027:
	cmp.w	d6,d4
	ble	SP10028 		;swapLoc(curBuf,atCursor_,locSC_)
	move.w	#117,-(sp)
	move.w	#99,-(sp)
	move.l	_curBuf,-(sp)
	jsr	_swapLoc			;swapLoc(curBuf,sPage_,locSP_)
	move.w	#116,-(sp)
	move.w	#104,-(sp)
	move.l	_curBuf,-(sp)
	jsr	_swapLoc			;}curBuf=bufPtr
	lea	16(sp),sp
SP10028:
	move.l	a3,_curBuf  		;curSplit=new
	move.w	d3,_curSplit			;newSplit=new
	move.w	d3,_newSplit			;switchFast()
	jsr	_switchFast 		;displayFlag|=(PAGE_<<new)
	moveq	#16,d0
	asl.w	d3,d0
	or.w	d0,_displayFlag 		;}
	bra	SP8
SP6:	equ	-4  		;FgotoSplit(){

	xdef	_FgotoSplit
_FgotoSplit:
	movem.l	d2-d4/a2,-(sp)  		 ;Rshort*sRshorti,bufNum,nsns=nSplit
	move.w	_nSplit,d3  		;if(ns==0)gotoFRTN
	tst.w	d3
	beq	SP10029 		;bufNum=*longPtrArgs[0]
	move.l	_longPtrArgs,a0
	move.w	2(a0),d4			;s=splitBufNum
	lea	_splitBufNum,a0
	move.l	a0,a2			;i=curSplit
	move.w	_curSplit,d2			;while(1){
SP10030:			;if(++i>ns)i=0
	addq.w	#1,d2
	cmp.w	d3,d2
	ble	SP10032
	moveq	#0,d2			;if(i==curSplit)gotoFRTN
SP10032:
	cmp.w	_curSplit,d2
	beq	SP10029 		;if(s[i]==bufNum){
	move.w	d2,d0
	add.w	d0,d0
	move.w	(a2,d0.w),d0
	cmp.w	d4,d0
	bne	SP10033 		;swapSplit(i)
	move.w	d2,-(sp)
	jsr	_swapSplit  		;showTitle=TRUE/*setTitle()*/
	move.w	#1,_showTitle			;return(TRUE)
	moveq	#1,d0
	addq.w	#2,sp
SP9:
	movem.l	(sp)+,d2-d4/a2
	rts 		;}}
SP10033:
	bra	SP10030 		;FRTN:
SP10029:			;return(FALSE)
	moveq	#0,d0
	bra	SP9 		;}FsplitWindow(){

	xdef  _FswapLoc
_FswapLoc:
	move.l  _bufPtrArgs,a1  ;if (bufPtr==NULL) return(FALSE);
	move.l  a1,d0
	beq S4
	moveq	#0,d0			;swapLoc(bufPtr,args[1],args[2]);
	move.b  _args+2,d0
	move.w  d0,-(sp)
;	moveq	#0,d0
	move.b  _args+1,d0
	move.w  d0,-(sp)
	move.l  a1,-(sp)
	jsr _swapLoc			;return(TRUE);
	moveq	#1,d0
	addq.w  #8,sp
S5: rts
S4: moveq	#0,d0
	bra S5

	xdef _swapLoc
_swapLoc:
	moveq	#0,d0
	moveq	#0,d1
	move.l  4(sp),a0
	move.l  a0,d0
	beq ZRTN
	move.w  8(sp),d0
	move.w  10(sp),d1		;loc1 -= atCursor_;loc2 -= atCursor_;
	sub.w	#99,d0
	sub.w	#99,d1  	;j = ov[loc1];ov[loc1] = ov[loc2];ov[loc2] = j;
;;;	asl.w	#2,d0
	add.w	d0,d0
	add.w	d0,d0
;;;	asl.w	#2,d1
	add.w	d1,d1
	add.w	d1,d1
	move.l  (a0,d0.w),a1
	move.l  (a0,d1.w),(a0,d0.w)
	move.l  a1,(a0,d1.w)		;loc1 += CBOVL;loc2 += CBOVL;
	add.w	#80,d0
	add.w	#80,d1  	;j = ov[loc1];ov[loc1] = ov[loc2];ov[loc2] = j;
	move.l  (a0,d0.w),a1
	move.l  (a0,d1.w),(a0,d0.w)
	move.l  a1,(a0,d1.w)		;}
ZRTN:
	rts

	xdef	_FstackBuf
_FstackBuf:
	link	a5,#RF10
	movem.l	d2/d3/a2,-(sp)  	 ;Rshorti,flagRSCB*bpSCB*bppi=(short)*longPtrArgs[0]
	move.l	_longPtrArgs,a0
	move.w	2(a0),d2			;if(i<MAXFILES||i>=ALLBUFS)gotoBRTN
	move.w	d2,a0
	cmp.l	_MAXFILES,a0
	blt	RF10030
	cmp.w	#100,d2
	bge	RF10030 		;flag=(short)*longPtrArgs[1]
	move.l	_longPtrArgs+4,a0
	move.w	2(a0),d3			;if(flag==-2){/*getstatus*/
	cmp.w	#-2,d3
	bne	RF10031 		;flag=bufferFlags[i]
	move.w	d2,d0
	add.w	d0,d0
	lea	_bufferFlags,a0
	move.w	(a0,d0.w),d3			;*longPtrArgs[1]=flag
	move.w	d3,a0
	move.l	_longPtrArgs+4,a1
	move.l	a0,(a1) 		;return(flag)
	move.w	d3,d0
RF11:
	movem.l	(sp)+,d2/d3/a2
	unlk	a5
	rts 		;}if(flag==-1){/*clearthestack*/
RF10031:
	cmp.w	#-1,d3
	bne	RF10032 		;bp=buf[0]
	move.l	_buf,a2 		;while(pop(&(bStack[i]),&bpp))if(bpp){
RF10033:
	pea	-4(a5)
	move.w	d2,d0
	asl.w	#2,d0
	lea	_bStack,a0
	add.w	d0,a0
	move.l	a0,-(sp)
	jsr	_pop
	tst.w	d0
	addq.w	#8,sp
	beq	RF10034
	tst.l	-4(a5)
	beq	RF10033 		;buf[0]=bpp
	move.l	-4(a5),_buf 		;freeBuf(0)
	clr.w	-(sp)
	jsr	_freeBuf			;}buf[0]=bp
	addq.w	#2,sp
	bra	RF10033
RF10034:
	move.l	a2,_buf 		;bufPopStack[i]=0
	move.w	d2,d0
	asl.w	#2,d0
	lea	_bufPopStack,a0
	clr.l	(a0,d0.w)			;RTN:
RF10036:			;return(TRUE)
	moveq	#1,d0
	bra	RF11			;}if(flag>=0){
RF10032:
	tst.w	d3
	blt	RF10037 		;bufferFlags[i]=flag
	move.w	d2,d0
	add.w	d0,d0
	lea	_bufferFlags,a0
	move.w	d3,(a0,d0.w)			;gotoRTN
	bra	RF10036 		;}BRTN:
RF10037:
RF10030:			;return(FALSE)
	moveq	#0,d0
	bra	RF11			;}
RF10:	equ	-4  		;

	xdef	_FsplitWindow
_FsplitWindow:
	link	a5,#PP2
	movem.l	d2-d7/a2/a3,-(sp)			;bufNum=(short)*longPtrArgs[0]
	move.l	_longPtrArgs,a0
	move.w	2(a0),d7			;lines=(short)*longPtrArgs[1]
	move.l	_longPtrArgs+4,a0
	move.w	2(a0),d6			;splits=nSplit
	move.w	_nSplit,d4  		;s=stopSplit
	lea	_stopSplit,a2			;ss=startSplit
	lea	_startSplit,a3  		;if(lines<2){/*terminatesplit*/
	cmp.w	#2,d6
	bge	PP10001 		;if(splits==0)gotoFRTN/*nosplits*/
	tst.w	d4
	beq	PP10002 		;start=dropSplit=-1/*findsplit*/
	moveq	#-1,d3
	move.w	d3,-2(a5)			;for(k=splitsk>=0k--){
	move.w	d4,d5
	bra	PP10006
PP10005:			;if(bufNum==splitBufNum[k]){
	move.w	d5,d0
	add.w	d0,d0
	lea	_splitBufNum,a0
	move.w	(a0,d0.w),d0
	cmp.w	d7,d0
	bne	PP10007 		;if(dropSplit==-1)dropSplit=k/*highestbufnumsplit*/
	cmp.w	#-1,d3
	bne	PP10008
	move.w	d5,d3			;start=k/*lowestbufnumsplit*/
PP10008:
	move.w	d5,-2(a5)			;}}
PP10007:
PP10003:
	subq.w	#1,d5
PP10006:
	tst.w	d5
	bge	PP10005
PP10004:			;if(dropSplit<0)gotoFRTN/*nobufnumsplit*/
	tst.w	d3
	blt	PP10002 		;k=dropSplit/*UPPERMOSTbufnumsplit*/
	move.w	d3,d5			;/*ifbufNumcurBuf,dropSplitiscurSplit*/if(buf[bufNum]==curBuf)dropSplit=curSplit
	move.w	d7,d0
	add.w	d0,d0
	add.w	d0,d0
	lea	_buf,a0
	move.l	(a0,d0.w),d0
	cmp.l	_curBuf,d0
	bne	PP10009
	move.w	_curSplit,d3			;if(start!=k){/*2ormoresplitsonbufnum*/
PP10009:
	move.w	-2(a5),d0
	cmp.w	d5,d0
	beq	PP10010 		;i=dropSplit+1
	move.w	d3,d2
	addq.w	#1,d2			;if(i>splits)i=splits-1
	cmp.w	d4,d2
	ble	PP10011
	move.w	d4,d2
	subq.w	#1,d2			;swapSplit(i)
PP10011:
	move.w	d2,-(sp)
	jsr	_swapSplit  		;}i=dropSplit
	addq.w	#2,sp
PP10010:
	move.w	d3,d2			;start=ss[i]
	move.w	d2,d0
	add.w	d0,d0
	move.w	(a3,d0.w),-2(a5)			;lines=s[i]-ss[i]
	move.w	(a2,d0.w),d6
	sub.w	(a3,d0.w),d6			;while(i<splits){/*iisdropsplit*/
PP10012:
	cmp.w	d4,d2
	bge	PP10013 		;splitBufNum[i]=splitBufNum[i+1]/*shiftarraydownward*/
	move.w	d2,d0
	addq.w	#1,d0
	add.w	d0,d0
	lea	_splitBufNum,a0
	move.w	d2,d1
	add.w	d1,d1
	move.w	(a0,d0.w),(a0,d1.w) 		;ss[i]=ss[i+1]
	move.w	(a3,d0.w),(a3,d1.w) 		;s[i]=s[i+1]
	move.w	(a2,d0.w),(a2,d1.w) 		;i++
	addq.w	#1,d2			;}
	bra	PP10012
PP10013:			;i=0
	moveq	#0,d2			;while(i<dropSplit){
PP10014:
	cmp.w	d3,d2
	bge	PP10015 		;s[i]+=lines
	move.w	d2,a0
	add.l	a0,a0
	add.l	a2,a0
	add.w	d6,(a0) 		;ss[i]+=lines
	move.w	d2,a0
	add.l	a0,a0
	add.l	a3,a0
	add.w	d6,(a0) 		;i++
	addq.w	#1,d2			;}
	bra	PP10014
PP10015:			;nSplit=--splits
	subq.w	#1,d4
	move.w	d4,_nSplit  		;i=curSplit
	move.w	_curSplit,d2			;if(i>splits)i=splits
	cmp.w	d4,d2
	ble	PP10016
	move.w	d4,d2			;curSplit=i
PP10016:
	move.w	d2,_curSplit			;newSplit=i
	move.w	d2,_newSplit			;dropSplit=splitBufNum[i]
	move.w	d2,d0
	add.w	d0,d0
	lea	_splitBufNum,a0
	move.w	(a0,d0.w),d3			;curBuf=buf[dropSplit]
	move.w	d3,d0
	add.w	d0,d0
	add.w	d0,d0
	lea	_buf,a0
	move.l	(a0,d0.w),_curBuf			;if(dropSplit!=bufNum){
	cmp.w	d7,d3
	beq	PP10017 		;bufNum=dropSplit
	move.w	d3,d7			;start=dropSplit=-1
	moveq	#-1,d3
	move.w	d3,-2(a5)			;for(k=splitsk>=0k--){
	move.w	d4,d5
	bra	PP10021
PP10020:			;if(bufNum==splitBufNum[k]){
	move.w	d5,d0
	add.w	d0,d0
	lea	_splitBufNum,a0
	move.w	(a0,d0.w),d0
	cmp.w	d7,d0
	bne	PP10022 		;if(dropSplit==-1)dropSplit=k/*hibufnumsplit*/
	cmp.w	#-1,d3
	bne	PP10023
	move.w	d5,d3			;start=k/*lobufnumsplit*/
PP10023:
	move.w	d5,-2(a5)			;}}
PP10022:
PP10018:
	subq.w	#1,d5
PP10021:
	tst.w	d5
	bge	PP10020
PP10019:			;if(curSplit!=start){
	move.w	_curSplit,d0
	cmp.w	-2(a5),d0
	beq	PP10024 		;swapLoc(curBuf,atCursor_,locSC_)
	move.w	#117,-(sp)
	move.w	#99,-(sp)
	move.l	_curBuf,-(sp)
	jsr	_swapLoc			;swapLoc(curBuf,sPage_,locSP_)
	move.w	#116,-(sp)
	move.w	#104,-(sp)
	move.l	_curBuf,-(sp)
	jsr	_swapLoc			;}}
	lea	16(sp),sp
PP10024:			;switchFast()
PP10017:
	jsr	_switchFast 		;displayFlag=ALLPAGE
	move.w	#65520,_displayFlag 		;}else{/*createasplit*/
	bra	PP10025
PP10001:			;if(splits>=(MAXSPLITS-1))gotoFRTN
	cmp.w	#7,d4
	bge	PP10002 		;if(!getBuf(bufNum))gotoFRTN
	move.w	d7,-(sp)
	jsr	_getBuf
	tst.w	d0
	addq.w	#2,sp
	beq	PP10002 		;i=s[0]-ss[0]
	move.w	(a2),d2
	sub.w	(a3),d2 		;if(++lines<3)lines=3
	addq.w	#1,d6
	cmp.w	#3,d6
	bge	PP10026
	moveq	#3,d6			;if((i-lines)<3)gotoFRTN
PP10026:
	move.w	d2,d0
	sub.w	d6,d0
	cmp.w	#3,d0
	blt	PP10002
;;;	move.w	#0,-(sp)
;;;	jsr	_swapSplit  			;swapSplit(0)
;;;	addq.w	#2,sp
								;splits=nSplit
	move.w	_nSplit,d4  		;i=splits+1
	move.w	d4,d2
	addq.w	#1,d2			;while(i>1){
	lea	_splitBufNum,a0
PP10027:
	cmp.w	#1,d2
	ble	PP10028
	move.w	d2,d0		  ;s[i]=s[i-1]
	subq.w	#1,d0
	add.w	d0,d0
	move.w	d2,d1
	add.w	d1,d1
	move.w	(a2,d0.w),(a2,d1.w) 		;ss[i]=ss[i-1]
	move.w	(a3,d0.w),(a3,d1.w)
	move.w	(a0,d0.w),(a0,d1.w) 		;splitBufNum[i]=splitBufNum[i-1]
	subq.w	#1,d2			; i-- }
	bra	PP10027
PP10028:
	move.w	(a2),2(a2)  	;s[1]=s[0]
	sub.w	d6,(a2) 		;s[0]-=lines
	move.w	(a2),2(a3)  	;ss[1]=s[0]
	addq.w	#1,d4			;nSplit= ++splits
	move.w	d4,_nSplit  		;splitBufNum[1]=bufNum
	move.w	d7,_splitBufNum+2			;swapSplit(1)
	move.w  _curSplit,d0
	beq PP1111
	addq.w  #1,d0
	move.w  d0,_curSplit
PP1111:
	move.w	#1,-(sp)
	jsr	_swapSplit  		;}
	addq.w	#2,sp
PP10025:			;ss[0]=0
	clr.w	(a3)			;s[nSplit]=maxLines+1
	move.w	_maxLines,d0
	addq.w	#1,d0
	move.w	_nSplit,d1
	add.w	d1,d1
	move.w	d0,(a2,d1.w)			;showTitle=TRUE/*setTitle()*/
	move.w	#1,_showTitle			;displayFlag|=ALLPAGE
	or.w	#65520,_displayFlag 		;return(TRUE)
	moveq	#1,d0
PP3:
	movem.l	(sp)+,d2-d7/a2/a3
	unlk	a5
	rts 		;FRTN:
PP10002:			;return(FALSE)
	moveq	#0,d0
	bra	PP3 		;}
PP2:	equ	-2  		;

	xdef	_inSplit
_inSplit:
	movem.l	d2-d6/a2/a3,-(sp)
	move.w	32(sp),d6			;Rshort*lh,*sRshorti,ns,ii,jjns=nSplit
	move.w	_nSplit,d3  		;lh=lineHeight
	lea	_lineHeight,a0
	move.l	a0,a2			;s=startSplit
	lea	_startSplit,a0
	move.l	a0,a3			;for(i=0i<=nsi++){
	moveq	#0,d2
	bra	SP10004
SP10003:			;ii=s[i]
	move.w	d2,d0
	add.w	d0,d0
	move.w	(a3,d0.w),d4			;jj=stopSplit[i]
	lea	_stopSplit,a0
	move.w	(a0,d0.w),d5			;if(y>=lh[ii]&&y<lh[jj])return(i)
	move.w	d4,d0
	add.w	d0,d0
	move.w	(a2,d0.w),d0
	cmp.w	d6,d0
	bgt	SP10005
	move.w	d5,d0
	add.w	d0,d0
	move.w	(a2,d0.w),d0
	cmp.w	d6,d0
	ble	SP10005
	move.w	d2,d0
SP2:
	movem.l	(sp)+,d2-d6/a2/a3
	rts 		;}
SP10005:
SP10001:
	addq.w	#1,d2
SP10004:
	cmp.w	d3,d2
	ble	SP10003
SP10002:			;return(curSplit)
	move.w	_curSplit,d0
	bra	SP2 		;}voidsplitFlag(Rshortbufn,Rshortflag){


	xdef	_splitFlag
_splitFlag:
	movem.l	d2-d7/a2,-(sp)
	move.w	32(sp),d7
	move.w	34(sp),d5			;Rshort*sRshorti,ns,jj,kks=splitBufNum
	lea	_splitBufNum,a0
	move.l	a0,a2			;i=curSplit
	move.w	_curSplit,d2			;jj=displayFlag
	move.w	_displayFlag,d3 		;if(bufn==s[i]){
	move.w	d2,d0
	add.w	d0,d0
	move.w	(a2,d0.w),d0
	cmp.w	d7,d0
	bne	SP10006 		;kk=flag&15/*writingthisshitforcrappymanxcompiler*/
	move.w	d5,d4
	and.w	#15,d4  		;jj|=kk/*spoonfeeditinhopesofbetteroutput*/
	or.w	d4,d3			;flag&=PAGE_
	and.w	#16,d5  		;flag<<=i
	asl.w	d2,d5			;jj|=flag
	or.w	d5,d3			;displayFlag=jj
	move.w	d3,_displayFlag 		;return
SP3:
	movem.l	(sp)+,d2-d7/a2
	rts 		;}ns=nSplit
SP10006:
	move.w	_nSplit,d6  		;for(i=0i<=nsi++){
	moveq	#0,d2
	bra	SP10010
SP10009:			;if(bufn==s[i]){
	move.w	d2,d0
	add.w	d0,d0
	move.w	(a2,d0.w),d0
	cmp.w	d7,d0
	bne	SP10011 		;kk=PAGE_<<i
	moveq	#16,d4
	asl.w	d2,d4			;jj|=kk
	or.w	d4,d3			;displayFlag=jj
	move.w	d3,_displayFlag 		;return
	bra	SP3 		;}}
SP10011:
SP10007:
	addq.w	#1,d2
SP10010:
	cmp.w	d6,d2
	ble	SP10009
SP10008:			;}
	bra	SP3 		;voidfixSplit(){


	xdef	_fixSplit
_fixSplit:
	movem.l	d2-d5/a2/a3,-(sp)		  ;Rshort*sRstructCB**bufPtrRshorti,j,k,splitssplits=nSplit
	move.w	_nSplit,d4  		;if(splits>0){
	tst.w	d4
	ble	SP10012 		;s=splitBufNum
	lea	_splitBufNum,a0
	move.l	a0,a2			;j=curBuf->BufNum
	move.l	_curBuf,a0
	move.w	166(a0),d5  		;bufPtr=buf
	lea	_buf,a0
	move.l	a0,a3			;for(i=0i<=splitsi++){
	moveq	#0,d2
	bra	SP10016
SP10015:			;k=s[i]
	move.w	d2,d0
	add.w	d0,d0
	move.w	(a2,d0.w),d3			;if(bufPtr[k]==NULL){
	move.w	d3,d0
;;;	asl.l	#2,d0
	add.w	d0,d0
	add.w	d0,d0
	tst.l	(a3,d0.w)
	bne	SP10017 		;if(k<MAXFILES||!getBuf(k))s[i]=j
	move.w	d3,a0
	cmp.l	_MAXFILES,a0
	blt	SP4
	move.w	d3,-(sp)
	jsr	_getBuf
	tst.w	d0
	addq.w	#2,sp
	bne	SP10018
SP4:
	move.w	d2,d0
	add.w	d0,d0
	move.w	d5,(a2,d0.w)			;displayFlag|=(PAGE_<<i)
SP10018:
	moveq	#16,d0
	asl.w	d2,d0
	or.w	d0,_displayFlag 		;showTitle=TRUE
	move.w	#1,_showTitle			;}}
SP10017:
SP10013:
	addq.w	#1,d2
SP10016:
	cmp.w	d4,d2
	ble	SP10015
SP10014:			;}}
SP10012:
SP5:
	movem.l	(sp)+,d2-d5/a2/a3
	rts 		;voidswapSplit(Rshortnew){


	xdef	_FcompareBuf
_FcompareBuf:
	movem.l	d2-d7/a2/a3,-(sp)
	move.l	_bufPtrArgs,d4  		;c2bp1=bufPtrArgs[0] bp2=bufPtrArgs[1]
	move.l	_bufPtrArgs+4,d5			;if(bp1==NULL||bp2==NULL)return(FALSE)
	tst.l	d4
	beq	CB2
	tst.l	d5
	bne	CB10001
CB2:
	moveq	#0,d0
CB3:
	movem.l	(sp)+,d2-d7/a2/a3
	rts 		;p1=bp1->Ptrb1=bp1->Block
CB10001:

	move.l	d4,a0
	move.l	80(a0),a2
;;;	move.l	d4,a0
	move.l	(a0),d6 		;p2=bp2->Ptrb2=bp2->Block

	move.l	d5,a0
	move.l	80(a0),a3
;;;	move.l	d5,a0
	move.l	(a0),d7 		;while(1){

CB10002:			;AGAIN1:
CB10004:			;c1=*p1
	move.b	(a2),d2 		;if(c1<=EOFILE){
	cmp.b	#3,d2
	bhi	CB10005 		;while(c1==0x00){p1++c1=*p1}
CB10006:
	tst.b	d2
	bne	CB10007
	addq.l	#1,a2
	move.b	(a2),d2
	bra	CB10006
CB10007:			;if(c1==EOB){
	cmp.b	#2,d2
	bne	CB10008 		;b1=b1->NextBlock
	move.l	d6,a0
	move.l	252(a0),d6  		;p1=b1->Data
	move.l	d6,a2			;gotoAGAIN1
	bra	CB10004 		;}}
CB10008:			;AGAIN2:
CB10005:
CB10009:			;c2=*p2
	move.b	(a3),d3 		;if(c2<=EOFILE){
	cmp.b	#3,d3
	bhi	CB10010 		;while(c2==0x00){p2++c2=*p2}
CB10011:
	tst.b	d3
	bne	CB10012
	addq.l	#1,a3
	move.b	(a3),d3
	bra	CB10011
CB10012:			;if(c2==EOB){
	cmp.b	#2,d3
	bne	CB10013 		;b2=b2->NextBlock
	move.l	d7,a0
	move.l	252(a0),d7  		;p2=b2->Data
	move.l	d7,a3			;gotoAGAIN2
	bra	CB10009 		;}if(c2==EOFILE)break
CB10013:
	cmp.b	#3,d3
	beq	CB10003 		;}if(c1==EOFILE)break
CB10010:
	cmp.b	#3,d2
	beq	CB10003 		;if(c1!=c2)break
	cmp.b	d3,d2
	bne	CB10003 		;p1++p2++
	addq.l	#1,a2
	addq.l	#1,a3			;}
	bra	CB10002
CB10003:			;bp1->Ptr=p1bp1->Block=b1

	move.l	d4,a0
	move.l	a2,80(a0)
;;;	move.l	d4,a0
	move.l	d6,(a0) 		;bp2->Ptr=p2bp2->Block=b2

	move.l	d5,a0
	move.l	a3,80(a0)
;;;	move.l	d5,a0
	move.l	d7,(a0) 		;fastBufPtr=bp1fastB=bp1->BlockfastP=bp1->Ptr

	move.l	d4,_fastBufPtr
	move.l	d4,a0
	move.l	(a0),_fastB
;;;	move.l	d4,a0
	move.l	80(a0),_fastP			;incFast()sLineFast()
	jsr	_incFast
	jsr	_sLineFast  		;bp1->PPtr=fastPbp1->PBlock=fastB

	move.l	d4,a0
	move.l	_fastP,100(a0)
;;;	move.l	d4,a0
	move.l	_fastB,20(a0)			;fastBufPtr=bp2fastB=bp2->BlockfastP=bp2->Ptr

	move.l	d5,_fastBufPtr
	move.l	d5,a0
	move.l	(a0),_fastB
;;;	move.l	d5,a0
	move.l	80(a0),_fastP			;incFast()sLineFast()
	jsr	_incFast
	jsr	_sLineFast  		;bp2->PPtr=fastPbp2->PBlock=fastB

	move.l	d5,a0
	move.l	_fastP,100(a0)
;;;	move.l	d5,a0
	move.l	_fastB,20(a0)			;popFast()
	jsr	_popFast			;splitFlag(bp1->BufNum,PAGE_)

	move.w	#16,-(sp)
	move.l	d4,a0
	move.w	166(a0),-(sp)
	jsr	_splitFlag  		;splitFlag(bp2->BufNum,PAGE_)

	move.w	#16,-(sp)
	move.l	d5,a0
	move.w	166(a0),-(sp)
	jsr	_splitFlag  		;return((c1==c2)?TRUE:FALSE)

	cmp.b	d3,d2
	addq.w	#8,sp
	bne	CB4
	moveq	#1,d0
	bra	CB5
CB4:
	moveq	#0,d0
CB5:
	bra	CB3 		;}

	xdef  _FgetTabs
_FgetTabs:
	link	a5,#I2
	movem.l I3,-(sp)
	;tableNum=*longPtrArgs[1]
	move.l  _longPtrArgs+4,a0
	move.w  2(a0),d5	;if(tableNum<0||tableNum>4)gotoFRTN
;	tst.w	d5
	blt I4
	cmp.w	#4,d5
	bgt I4  ;bufNum=*longPtrArgs[0]
	move.l  _longPtrArgs,a0
	move.w  2(a0),d6	;if(!getBuf(bufNum))gotoFRTN
	move.w  d6,-(sp)
	jsr _getBuf
	tst.w	d0
	addq.w  #2,sp
	beq I4  ;tabs=tabTables[tableNum]
	move.w  d5,d0
	asl.w	#5,d0		; REPLACE MULTIPLY
	add.w	d5,d0
;	muls.w  #33,d0
	lea _tabTables,a3
	add.w	d0,a3	;*t=0x00
	clr.b	-256(a5)	;while(*tabs){
I5:
	tst.b	(a3)
	beq I6  ;catNumber(t,(long)*tabs,DATASIZE)
	move.w  #244,-(sp)
	moveq	#0,d0
	move.b  (a3),d0
	move.l  d0,-(sp)
	pea -256(a5)
	jsr _catNumber  ;strncatmax(t,"",DATASIZE)
	move.w  #244,-(sp)
	pea I1+0
	pea -256(a5)
	jsr _strncatmax ;tabs++
	addq.l  #1,a3	;}
	lea 20(sp),sp
	bra I5
I6: ;p=t
	lea -256(a5),a2 ;fastBufPtr=buf[bufNum]
	moveq	#0,d0
	move.w  d6,d0
;	ext.l	d0
;;;    asl.w   #2,d0
	add.w	d0,d0
	add.w	d0,d0
	lea _buf,a0
	move.l  (a0,d0.w),_fastBufPtr	;fastB=fastBufPtr->Block
	move.l  _fastBufPtr,a0
	move.l  (a0),_fastB ;fastP=fastBufPtr->Ptr
	move.l  _fastBufPtr,a0
	move.l  80(a0),_fastP	;stickMode=0
	clr.w	_stickMode  ;while(*p)if(!stickChar(*(p++)))gotoFRTN
I7:
	tst.b	(a2)
	beq I8
	move.l  a2,a0
	addq.l  #1,a2
	moveq	#0,d0
	move.b  (a0),d0
	move.w  d0,-(sp)
	jsr _stickChar
	tst.w	d0
	addq.w  #2,sp
	beq I4  ;popFast()
	bra I7
I8:
	jsr _popFast	;return(TRUE)
	moveq	#1,d0
I9:
	movem.l (sp)+,I3
	unlk	a5
	rts ;FRTN:
I4: ;popFast()
	jsr _popFast	;return(FALSE)
	moveq	#0,d0
	bra I9  ;}
I2: equ -256
I3: reg d4-d6/a2/a3
I1:
	dc.b	32,0
	ds  0

	xdef  _FnameBuffer
_FnameBuffer:
	movem.l I40,-(sp)	;i=*longPtrArgs[0]
	move.l  _longPtrArgs,a0
	move.w  2(a0),d4	;if(i<MAXFILES||i>=ALLBUFS)gotoFRTN
	moveq	#0,d0
	move.w  d4,d0
	cmp.l	_MAXFILES,d0
	blt I41
	cmp.w	#100,d4
	bge I41 ;x=ptrArgs[1]
	move.l  _ptrArgs+4,a2	;if(*x<=''||strlen(x)>63)gotoFRTN
	cmp.b	#32,(a2)
	bls I41
	move.l  a2,-(sp)
	jsr _strlen
	cmp.w	#63,d0
	addq.w  #4,sp
	bgt I41 ;bufferNames[i]=x
	moveq	#0,d0
	move.w  d4,d0
;;;    asl.w   #2,d0
	add.w	d0,d0
	add.w	d0,d0
	lea _bufferNames,a0
	move.l  a2,(a0,d0.w)	;bufPtr=buf[i]
	lea _buf,a0
	move.l  (a0,d0.w),a3	;if(bufPtr!=NULL)bufPtr->FileName[0]=0x00
	move.l  a3,d0
	beq I42
	clr.b	196(a3) ;return(TRUE)
I42:
	moveq	#1,d0
I43:
	movem.l (sp)+,I40
	rts ;FRTN:
I41:	;return(FALSE)
	moveq	#0,d0
	bra I43 ;}
I40:	reg d4/a2/a3	;FseeRuler(){

	xdef  _FseeRuler
_FseeRuler:
	jsr _saveDis	;saveDis() seeRuler(TRUE)
	move.w  #1,-(sp)
	jsr _seeRuler	;while(!collectRaw()){
	addq.w  #2,sp
I46:
	jsr _collectRaw
	tst.w	d0
	bne I47 ;if(stopPause)break
	tst.w	_stopPause
	bne I47 ;if(!busyWork())waite()
	jsr _busyWork
	tst.w	d0
	bne I48
	jsr _waite   ;}
I48:
	bra I46
I47:	;unsaveDis()
	jsr _unsaveDis  ;return(TRUE)
	moveq	#1,d0
I49:
	rts ;}
#endasm
#endif

