// findmacpos.sr


get "BRAVO1.DF";
get "AltoFileSys.D";
get "vm.Df";

// Incoming Procedures

external [
	ActOnPages;
	errhlta
	setmacfp;
	move;
	movec;
	VirtualDA;
	];

// Incoming Statics

external [
	mpfnof
	fillInDA
	DCread
	];

// Outgoing Procedures

external [
	FindMacPos;
//	OfToCfa
	];


// F I N D M A C P O S
//
let FindMacPos(fn) be
[
let of = mpfnof ! fn;
let mpPgnDa = vec 130; let tvec = vec #400; let rc = nil
mpPgnDa = mpPgnDa + 1
mpPgnDa!-1 = of>>OF.fda
mpPgnDa ! 0 = of >> OF.rgda; movec(mpPgnDa+1,mpPgnDa+129,fillInDA)
let pgnLast = ActOnPages(0,mpPgnDa,lv (of >> OF.fileid),0,129,DCread,lv rc,0,tvec)
if pgnLast ge 129 then errhlta(162)
of >> OF.macpos = ((pgnLast-1) lshift 9)+rc;
setmacfp(fn,pgnLast+1); move(mpPgnDa,lv ((mpfnof ! fn) >> OF.rgda),pgnLast+2)
] 


// O F T O C F A
//
// and OfToCfa(of,vecCfa,pgn,rc; numargs na) be
// [
// movec(vecCfa,vecCfa+lCFA-1,0);
// switchon na into
// 	[ 
// case 4:	vecCfa >> CFA.fa.charPos = rc
// case 3:	vecCfa >> CFA.fa.pageNumber = pgn
// 	] 
// move(lv (of >> OF.sn1),lv (vecCfa >> CFA.fp.serialNumber),lSN)
// vecCfa >> CFA.fp.version = of >> OF.version
// let mpPgnDa = lv (of >> OF.rgda)
// vecCfa >> CFA.fp.leaderVirtualDa = VirtualDA(mpPgnDa ! 0)
// vecCfa >> CFA.fa.da = mpPgnDa ! (vecCfa >> CFA.fa.pageNumber)
// ]