// I N I T	QINIT.SR

get "BRAVO.DF";
get "HEAP.DF";
get "DISPLAY.DF";
get "CHAR.DF";
get "GINN.DF"; // **

// Incoming Procedures

external [
	min
	creates
	array
	movec
	createdisplay
	splitwindow
	open
	errhlt
	createdoce
	createdocm
	insertlf
	setlf
	docalloc
	updatedisplay
	selectwholeww
	invalidatewindow
// ** GYPSY ADDED:
	hplay
	insertparas
	lastparacp
	swatoff
	setsel
	qinitselect;
	qinitbravocom;
	qinitdoc;
	qinitdisplay;
	qinitformat;
	qinitmenu
	qinitcomt
	qinitfcode
	qsetupmenu
// ** END GYPSY ADDITIONS
	];

// Incoming Statics

external [
	vyorig
	rgyfirst
	rgylast
	rgdoc
	rgcpfdispl
	rgdlfirst
	rgdllast
	macww
	selaux
// ** GYPSY ADDED:
	rgdirpage
	vcasson
	vdpon
	topofheap
	freet
	freee
	mphd
	vinsertk
	vlooksp
	vlookcr
	vlooktab
	vwindows
	vwwon
	vwwoff
	vwwcurrent
	rgchoppage
	currentspec
	otherspec
	speclist
// ** END GYPSY ADDITIONS
 	];

// Outgoing Procedures

external [
	qinit;
	];

// Outgoing Statics

external [
	vdcbsys;
	vdcborig;
	vysys;
	pzone;
	instream;
	liststream;
	inword;
	inwordnext;
	vdcbblack;
	cparamuser;
	cparamcom;
	rgptcom;
	rgpvcom;
	rgptuser;
	rgpvuser;
	vpt;
	vpv;
	vcparam;
	pxv;
// ** GYPSY ADDED:
	mdoc
	mww
	rgmenu
	sdoc
	sww
	selection
	rgsdoc
	rgsfile
	ddoc
// ** END GYPSY ADDITIONS
	]; 

// Local Statics

static [
	vdcbsys;
	vdcborig;
	vysys;
	pzone;
	instream;
	liststream;
	inword;
	inwordnext;
	vdcbblack;
	cparamuser;
	cparamcom;
	rgptcom;
	rgpvcom;
	rgptuser;
	rgpvuser;
	vpt;
	vpv;
	vcparam;
	pxv;
// ** GYPSY ADDED:
	mdoc
	mww
	rgmenu
	sdoc
	sww
	selection
	rgsdoc
	rgsfile
	ddoc
// ** END GYPSY ADDITIONS
	];

// Local structures
structure SW:
	[ ANYCOMCM bit 1;
	ANYREMCM bit 1;
	blank bit 14
	] 
// Local manifests
manifest
	[ 
	swloc = #1002;
	maxbuf = 5000;
	] 

// B R A V O
let qinit() be
[

qinitformat(array);
// qinitdisplay uses values set in qinitformat!!!!
qinitdoc(array);
qinitdisplay(array);
qinitselect(array);

// ** moved creates(...) to init()

// ** GYPSY additions:

vdpon = false // $$ dp is diablo printer
vcasson = false // $$ cass is cassette
	
mphd = 32 // guess (32 microns per horizontal dot)
vinsertk = false
currentspec = 0
otherspec = 0
speclist = 0

vlooksp = false
vlookcr = false
vlooktab = false
qinitmenu(array)
qinitcomt(array)
qinitfcode(array)
rgsfile=array(maxdoc)
rgsdoc=array(maxww)
rgdirpage=array(maxww)
movec(rgsfile, rgsfile + maxdoc-1, 0)
movec(rgsdoc, rgsdoc + maxww-1, 0)
movec(rgdirpage, rgsdoc + maxww-1, 0)
// ** END GYPSY additions

qinitbravocom( );
// ** tsread = false;
// ** qinitparams();

// ** GYPSY moved from GINIT.SR to here to expand heap asap
if freee << odd then freee = freee - 1 // **
hplay(freet-freee,false);
topofheap = freee;
freee = freet; // **
// ** END GYPSY additions

// ** GYPSY changes to rgyfirst and rgylast for bigger windows
rgyfirst ! 0 = ywwtop;
rgylast ! 0 = min(ywwscr1+48,807) ; // $$
// ** END GYPSY changes

rgdoc ! 0 = 0;
rgcpfdispl ! 0 = 0;
rgdlfirst ! 0 = 0; rgdllast ! 0 = -1;
macww = macww+1;

// ** deleted fsestablish

createdisplay();

// ** GYPSY change for smaller system window
splitwindow(ywwsys,1);
// ** END GYPSY change

// ** GYPSY moved
unless creates(fnscr,"$SCRATCH.TX",true) do
	errhlt("ufo");
// ** END GYPSY change

// ** GYPSY create docsys as a normal doc and other things
createdoce(docsys,3);
rgdoc ! 0 = 0;
mdoc=1
mww=1
createdoce(mdoc,6)
splitwindow(ywwmenu2, 6) // %% no more ywwmenu1
rgdoc!1 = 1
// ** END GYPSY change

createdocm(6);

// ** GYPSY change
rgdoc ! 2 = 6;
// ** END GYPSY change

// ** GYPSY shortened system window contents:
insertparas(docsys, 0, docsys, 0, 0)
insertlf(docsys,lastparacp(docsys)-2,lfsys,idbanner1,4);
insertlf(docsys,lastparacp(docsys)-2,lfsys,idbanner2,80);
insertlf(docsys,lastparacp(docsys)-2,lfsys,idbanner3,10);
setlf(lfsys,idbanner1,"  ");
setlf(lfsys,idbanner2,
" 	           G Y P S Y               8/17/75"
);	// %%
setlf(lfsys,idbanner3,"  ");
// ** END GYPSY additions

rgcpfdispl ! 1 = 0;
rgcpfdispl ! 0 = 0;

// ** GYPSY added SCRATCH PAD document:
sdoc = docalloc();
createdocm(sdoc);
splitwindow(ywwscr1, sdoc); // %% no more ywwscr2
sww = macww-1;
// insertparas(sdoc, 0, sdoc, 0, 0)
// ** END GYPSY additions

updatedisplay();

// ** GYPSY doesnt underline yet, but does make a PLACE:
// ** END GYPSY change

// ** GYPSY ADDITIONS:
// Code for directory follows - its a kludge because no attempt
// has been made yet to integrate it with previous code which
// itself has not been integrated with init procedures
// ALL THIS INITIALISATION CODE MUST BE CLEANSED SOON
vwwon = -1 ;
vwwoff = -1 ;
vwwcurrent = 2 ; // **  CAREFUL !!
selectwholeww(selaux,3)
setsel(selaux,0,-1) // ******** LT!!! -1) //TM did -1
selectwholeww(selection,2)
let tww=nil
tww=selection>>SEL.ww
rgsdoc!tww = selection>>SEL.doc
ddoc = docalloc()
rgdoc!tww=ddoc
createdocm(ddoc)
rgchoppage ! ddoc = true
invalidatewindow(tww)
selectwholeww(selection,tww)
updatedisplay()
qsetupmenu()
swatoff() // **
// ** END GYPSY additions

// ** scratch-open was moved up
]