// I N I T QINITCOMT.SR

get "BRAVO.DF";
get "CHAR.DF";
get "GINN.DF";

// Incoming Procedures
external [
	qlevel
	qpageto // $$
	qourfile // $$
	qquit
	qdirectory
	qdrawer // %%
	qcancel
	qfile
	qall
	print
	qfetch
	qscan
	qcontinue
	qsubstitute
	qturnto
	qaddpage
	qcreatedraft
	qmakeversion
	qdouble
	qheadings
	qpagenums
	qrepaginate
	start
	stop
	cassette
	casswrite
	errhlt
	movec
	insert;
	coleft;
	coleftword;
	coright;
	placeleft;
	placeright;
	paragraph
	carrier
	tabulator
	paste;
	cut;
	cutpaste
	exchange
	select;
	thing;
	mark;
	stripeline;
	stripewindow;
	stripenone;
	stripefly;
	stripemenu;
	rollup;
	rolldown;
	rollupfast;
	rolldownfast;
	rollupfar
	rolldownfar
	roll;
	modwindow;
	divwindow;
	newwindow;
	delwindow;
	lookey;
	flyaway;
	bugmenu;
	]

// Incoming Statics

external [
	vstripe
	comt
	midkeyset
	badkeyset
	scrolltimer
	scrolltoggle
	vkeys
	vwindows
	vwindowstripe // %%
	vmark
	vcutpaste
	vjumpbar
	vblackout
	vmscroll
	vthing
	vwords
	vplacekeys
	vcoright
	novice
	];

// Outgoing Procedures

external [
	qinitcomt
	];

// Outgoing Statics

external [
	routine
	module
	];

// Local Statics

static [
	routine
	module
	];


let qinitcomt(array) be
	[
	novice = false // **
	vwindows = not novice
	vwindowstripe = false // %%
	vmark = not novice
	vcutpaste = false
	vjumpbar = not novice
	vblackout = true
	vmscroll = false
	vthing = not novice
	vwords = not novice
	vplacekeys = false
	vcoright = false

	comt = array(maxcode) ;
	movec(comt, comt+maxcode-1, snone) ;

	for i = #40 to #177 do comt!i = sinchar; // $$

	for i = 0 to #200 by #200 do // regular and control
	  [	
	  comt ! (i + chlf)	= vplacekeys? splaceleft, snone ;
	  comt ! (i + shlf)	= vplacekeys? splaceleft, snone ;
	  comt ! (i + chdel)	= vplacekeys? splaceright, snone ;
	  comt ! (i + shdel)	= vplacekeys? splaceright, snone ;

	  comt ! (i + bs)	= scoleft ;
	  comt ! (i + shbs)	= scoleft ;
	  comt ! (i + topblk)	= vcoright? scoright, scoleftword ;
	  comt ! (i + shtopblk)	= vcoright? scoright, scoleftword ;

	  ]

	comt ! (#200+$p)	= sparagraph ;

	comt ! chesc		= scut ;
	comt ! shesc		= spaste ;

	for i =0 to 9 do comt ! (#200+$0+i) = spageto // $$;

	let j = 0
		[
		let ch = table
		    [
			chsp; shsp ; // look at spaces in this doc
			chtab; shtab ; // look at tabs in this doc
			chcr; shcr ; // look at crs in this doc
			$\; $| ; // look at markers in this doc
			$=; $+ ; // $$ look at remarks in this doc
			$b ; $B ; // bold
			$c ; $C ; // center
			$f;	// formatted instead of program
			$h; $H ; // look at headers in this doc
			$i ; $I ; // italic
			$j ; $J ; // justify
			$m ; $M ; // menu item
			$n ; $N; // normal
			$u ; $U; // underline
			$v ; $V; // vanish
			$w; $W; // windows
			$x ; $X ; // remark
		  0 ] ! j
		unless ch do break
		comt ! (#200 + ch) = slookey
		j = j + 1
		] repeat

	comt ! (#200 + $l) = slevel
	comt ! (#200 + $L) = slevel
	comt ! (#200 + $r) = slevel
	comt ! (#200 + $R) = slevel

	comt ! chcr = scarrier ;
	comt ! shcr = scarrier ;

	comt ! chtab = stabulator ;
	comt ! shtab = stabulator ;

	comt ! shsp = smapchar ;

	let x = lv comt ! smouse ;

	// top button
	x!#04=spointchar;
	x!#14=spointchar;
	x!#24=smodwindow;
	x!#34=sflyaway;
	x!#44=sbugmenu;

	// middle button
	x!#02=vmscroll? sroll, vthing? sthing, snone;
	x!#12=vmscroll? sroll, vthing? sthing, snone;
	x!#22=sdivwindow;
	x!#42=vthing? sbugmenu, snone;

	// bottom button
	x!#01=vmark? smark,snone;
	x!#11=vmark? smark,snone;
	x!#21=snewwindow;
	x!#41=vmark? sbugmenu, snone;

	// middle and bottom button
	x!#23=sdelwindow;

	let x = lv comt ! skeyset ;

	x!#10=srolldown;		// 01000
	x!#14=srolldownfast;	// 01100
	x!#06=srollupfast;	// 00110
	x!#02=srollup;		// 00010
	x!#16=srollover;		// 01110
	x!#20=spaste;		// 10000
	x!#01=scut;		// 00001
	x!#21=vcutpaste? scutpaste,sexchange;		// 10001

	badkeyset = #37 ;
	midkeyset = #04 ;
	vkeys = 0;
	scrolltoggle = 0;

	for i=sstripeline to sstripemenu do
		comt ! (sstripe+i-sstripeline) = i

	routine = array(maxsig+maxmitems) ;
	movec(routine, routine+maxsig+maxmitems-1, nomodule) ;
	module = array(maxsig+maxmitems) ;
	movec(module, module+maxsig+maxmitems-1, nomodule) ;

	qinitmodule(sinchar, insert, editmodule) ;
	qinitmodule(smapchar, insert, editmodule) ;
	qinitmodule(scoleft, coleft, editmodule) ;
	qinitmodule(scoleftword, coleftword, editmodule) ;
	qinitmodule(scoright, coright, editmodule) ;
	qinitmodule(splaceleft, placeleft, editmodule) ;
	qinitmodule(splaceright, placeright, editmodule) ;
	qinitmodule(sparagraph, paragraph, editmodule) ;
	qinitmodule(scarrier, carrier, editmodule) ;
	qinitmodule(stabulator, tabulator, editmodule) ;
	qinitmodule(spaste, paste, editmodule) ;
	qinitmodule(scut, cut, editmodule) ;
	qinitmodule(scutpaste, cutpaste, editmodule) ;
	qinitmodule(sexchange, exchange, editmodule) ;

	qinitmodule(sstripeline, stripeline, resmodule) ;
	qinitmodule(sstripewindow, stripewindow, resmodule) ;
	qinitmodule(sstripenone, stripenone, resmodule) ;
	qinitmodule(sstripefly, stripefly, resmodule) ;
	qinitmodule(sstripemenu, stripemenu, resmodule) ;

	qinitmodule(srollup, rollup, mousemodule) ;
	qinitmodule(srolldown, rolldown, mousemodule) ;
	qinitmodule(srollupfast, rollupfast, mousemodule) ;
	qinitmodule(srolldownfast, rolldownfast, mousemodule) ;
	qinitmodule(srollupfar, rollupfar, mousemodule) ;
	qinitmodule(srolldownfar, rolldownfar, mousemodule) ;
	qinitmodule(sroll, roll, mousemodule) ;
	qinitmodule(sflyaway, flyaway, mousemodule) ;
	qinitmodule(spointchar, select, mousemodule) ;
	qinitmodule(sthing, thing, mousemodule) ;
	qinitmodule(smark, mark, mousemodule) ;

	qinitmodule(smodwindow, modwindow, wwmodule) ;
	qinitmodule(sdivwindow, divwindow, wwmodule) ;
	qinitmodule(snewwindow, newwindow, wwmodule) ;
	qinitmodule(sdelwindow, delwindow, wwmodule) ;

	qinitmodule(slookey, lookey, lookmodule) ;
	qinitmodule(spageto, qpageto, menumodule) ;

	qinitmodule(slevel, qlevel, menumodule) ;

	qinitmodule(sbugmenu, bugmenu, resmodule) ;

	qinitmodule(maxsig+mquit, qquit, dirtymodule) ;
	qinitmodule(maxsig+mdirectory, qdirectory, menumodule) ;
	qinitmodule(maxsig+mdrawer, qdrawer, menumodule) ; // %%
	qinitmodule(maxsig+mcancel, qcancel, menumodule) ;
	qinitmodule(maxsig+mfile, qfile, dirtymodule) ;
	qinitmodule(maxsig+mall, qall, menumodule) ;
	qinitmodule(maxsig+mscan, qscan, menumodule) ;
	qinitmodule(maxsig+msubstitute, qsubstitute, menumodule) ;
	qinitmodule(maxsig+mdocument, qcontinue, menumodule) ;

	qinitmodule(maxsig+madd, qaddpage, dirtymodule) ;
	qinitmodule(maxsig+mcreate, qcreatedraft, dirtymodule) ;
	qinitmodule(maxsig+mmake, qmakeversion, dirtymodule) ;
	qinitmodule(maxsig+mfetch, qfetch, dirtymodule) ;
	qinitmodule(maxsig+mturnto, qturnto, dirtymodule) ;

	qinitmodule(maxsig+mput, qourfile, dirtymodule) ;

	qinitmodule(maxsig+mprint, print, menumodule) ;
	qinitmodule(maxsig+mdouble, qdouble, menumodule) ;
	qinitmodule(maxsig+mheadings, qheadings, menumodule) ;
	qinitmodule(maxsig+mpagenums, qpagenums, menumodule) ;
	qinitmodule(maxsig+mrepaginate, qrepaginate, menumodule) ;
	qinitmodule(maxsig+mstart, start, resmodule) ;
	qinitmodule(maxsig+mstop, stop, resmodule) ;

	qinitmodule(maxsig+mcassette, cassette, menumodule) ;
	qinitmodule(maxsig+mwrite, casswrite, menumodule) ;

 	] // end of initcomt

and qinitmodule(sigcode, whichroutine, whichmodule) be
	[
	routine ! sigcode = whichroutine ;
	module ! sigcode = whichmodule ;
	]