get "BRAVO1.DF";
get "CHAR.DF";
get "SELECT.DF";
get "rn1.df"
get "com.DF";
get "display.DF";
get "doc.df"


// Incoming Procedures

external
	[
	gets;
	resetts;
	getchar;
	SetRegionSys;
	confirm;
	updatedisplay;
	tsflush;
	stnum;
	SetRegionW;
	deleted;
	inserta;
	augmentomseq;
	inserttx;
	deactivateomseq;
	getint;
	setsel;
	InsertBuf;
	ClearBuf;
	underline;
	updateunderline;
	innum;
	invalidatesel;
	errhlta;
	ult;
	bravochar;
	];

// Incoming Statics

external
	[
	tsread;
	tsmacro;
	tscorrect;
	tsstop;
	tsquick;
	rgmaccp;
	vcp;
	fnts;
	ccommand;
	vrlwsys;
	tsbreak;
	selaux;
	mpWwWwd;
	]

// Outgoing Procedures

external [
	GetCharReplay;
	SetSelReplay;
	ComReplay;
	];

let GetCharReplay() = valof
[ let tchar = nil;
tchar = gets(fnts);
if tchar eq chat then
	[ tchar = gets(fnts);
	if tchar eq $E then
		[ tsread = false;
		tsmacro = false;
		resetts();
		resultis bravochar();
		] 
	] 
if (tchar eq chesc) & tscorrect & not tsmacro then
	[ tsread = false;
	resultis bravochar();
	] 
resultis tchar;
] 


and ComReplay() be
[ let tchar = nil;
let sbcomnum = vec 8;
test tsstop ifso
	[ tsstop = false;
	tchar = chsp;
	] 
ifnot	tchar = getchar();
sbcomnum ! 0 = 0;
SetRegionSys(risyscom,85)	//REPLAY:
	[ if (tchar ge $A) & (tchar le $Z) then
		tchar = tchar+#40;
	switchon tchar into
		[ 
case $q:		tsquick = true;
		SetRegionSys(risysstate,86);
		endcase;
case $s:		tsquick = false;
		SetRegionSys(risysstate,87);
		endcase;
case $t:		tsread = false;
		tscorrect = true;
		test confirm("TERMINATE REPLAY") ifso
			[ 
			SetRegionSys(risyscom,nriready)
			SetRegionSys(risysstate,nrisel)
			SetRegionSys(risyspast,rinil)
			updatedisplay()
			tsflush();
			tscorrect = false;
			return;
			] 
		ifnot	[ tsread = true;
			tscorrect = false;
			endcase;
			] 
case chsp:		test tsstop ifso return
		ifnot	[ tsstop = true;
			stnum(sbcomnum,ccommand);
			SetRegionW(vrlwsys,0,sbcomnum);
			let trid = 0
			trid<<RID.nrl = 1
			trid<<RID.ri = 0
			SetRegionSys(risysstate,88,trid)
			] 
		endcase;
case $p:		tsstop = false;
		SetRegionSys(risysstate,89);
		endcase;
case $b:			deleted(doctx5);
		unless rgmaccp ! doctx1 eq 0 then
		 inserta(doctx5,0,doctx1,0,rgmaccp ! doctx1-1) 
		SetRegionSys(risysstate,90,37);
		updatedisplay();
		tsread = false;
		tscorrect = true;
		augmentomseq("M");
		inserttx(1);
		deactivateomseq("M");
		vcp = 0;
		tsbreak = getint(doctx1);
		deleted(doctx1);
		test rgmaccp ! doctx5 eq 0 ifnot
			[  inserta(doctx1,0,doctx5,0,rgmaccp ! doctx5-1) 
			selaux >> SEL.doc = doctx1;
			selaux >> SEL.ww = 0;
			selaux >> SEL.type = schar;
			setsel(selaux,0,rgmaccp ! doctx1-1);
			InsertBuf(1,selaux>>SEL.doc,
selaux>>SEL.cpfirst,selaux>>SEL.cplast-selaux>>SEL.cpfirst+1)
			] 
		ifso	ClearBuf(1);
default:		SetRegionSys(risysstate,91);
		tsstop = true;
		endcase;
		] 
	updatedisplay()
//		unless vfhpsp do
//			[ blinkscreen();
// Core storage running low-Suggest termination of replay
//			SetRegionSys(risysstate,49,92);
//			vfhpsp = true;
//			]
//		updatedisplay();
	unless tsstop do return;
	tchar = getchar();
	] repeat
]


and SetSelReplay(sel1) be
[ underline(uloff,sel1);
let tchar = gets(fnts);
if tchar eq $' then
	[ sel1 >> SEL.type = snone;
	return;
	] 
if tchar eq $** then
	return;
test tchar eq chat ifso
	[ tchar = gets(fnts);
	unless tchar eq $E do errhlta(104);
	resetts();
	tsread = false;
	tscorrect = false;
	underline(sel1 >> SEL.ulmode,sel1);
	updateunderline( );
	] 
ifnot	[ unless tchar eq ${ do errhlta(106);
	sel1 >> SEL.type = innum(fnts,8);
	sel1 >> SEL.ww = innum(fnts,8);
	sel1 >> SEL.cpfirst = innum(fnts,8);
	sel1 >> SEL.cplast = innum(fnts,8);
	invalidatesel(sel1);
	sel1 >> SEL.doc = (mpWwWwd ! (sel1 >> SEL.ww))>>WWD.doc;
	let maccp = rgmaccp ! (sel1 >> SEL.doc);
	unless ult(sel1 >> SEL.cpfirst,maccp) & ult(sel1 >> SEL.cplast,maccp) do
		errhlta(105);
//		if carg eq 4 then
//			unless FProc(sel1, fmCaller) do
//				errhlta(107)
	underline(sel1 >> SEL.ulmode,sel1);
	updateunderline( );
	]
]