// April 27, 1978  7:04 PM				*** "UNDERLAY" ***

get "zpComDf.bcpl"


// outgoing procedures:

external [
	initEventTable
	]
  

// incoming procedures:

external [
	Zero			// SYSTEM
	SetBlock

	needBlock		// ZPINIT1
	]



// incoming statics:

external [
	@commandTable		// ZPINIT1
	@actionTable
	@versionX
	]



//*****************************************************************
// initialization of command tables
//*****************************************************************

let initEventTable() be [initEventTable
	// command table:
	commandTable=needBlock(commandTableSize)
	Zero(commandTable, commandTableSize)
			// keyboard
	SetBlock(commandTable, CMchar + endCommand, #200)
	commandTable!crKey=CMtext + changeCommand
	commandTable!escKey=CMmake + changeCommand
	commandTable!bsKey=CMdelChar
	commandTable!delKey=CMstartAgain
	commandTable!lfKey=CMmoreHelp + endCommand
	commandTable!controlA=CMbackUp
	commandTable!controlB=CMbitmap + endCommand
	commandTable!controlC=CMcolorOnOff + endCommand
	commandTable!controlD=CMdelSelection + endCommand
	commandTable!controlE=CMselectAll + endCommand
	commandTable!controlF=CMreadFont
	commandTable!controlG=CMshowGrid
	commandTable!controlI=CMrefresh + endCommand
	commandTable!controlO=CMhelp + endCommand
	commandTable!controlP=CMplot + endCommand
	commandTable!controlQ=CMquit + endCommand
	commandTable!controlR=CMread + endCommand
	commandTable!controlS=CMselect + changeCommand
	commandTable!controlT=CMtextMode
	commandTable!controlU=CMundelete + endCommand
	commandTable!controlV=CMvideo
	commandTable!controlW=CMwrite + endCommand
	commandTable!controlX=CMdelete + changeCommand
	commandTable!controlY=CMstatistics + endCommand
	commandTable!controlZ=CMmTransf2 + changeCommand
			// menu (menu for version X does not have color commands)
	// right column:
	commandTable!(menuCode+1)=CMbrush
	commandTable!(menuCode+2)=CMbrush
	commandTable!(menuCode+3)=CMbrush
	commandTable!(menuCode+4)=CMbrush
	commandTable!(menuCode+5)=CMfreeHand + changeCommand
	test versionX
	ifso [
		commandTable!(menuCode+7)=CMredraw + changeCommand
		commandTable!(menuCode+8)=CMmake + changeCommand
		commandTable!(menuCode+9)=CMdelete + changeCommand
		commandTable!(menuCode+11)=CMselect + changeCommand
		commandTable!(menuCode+12)=CMmTransf2 + changeCommand
		commandTable!(menuCode+13)=CMmTransf4 + changeCommand
		commandTable!(menuCode+14)=CMmTransf6 + changeCommand
		]
	ifnot [
		commandTable!(menuCode+6)=CMpaint + changeCommand
		commandTable!(menuCode+7)=CMpaint + changeCommand
		commandTable!(menuCode+8)=CMpaint + changeCommand
		commandTable!(menuCode+9)=CMpaint + changeCommand
		commandTable!(menuCode+10)=CMredraw + changeCommand
		commandTable!(menuCode+11)=CMmake + changeCommand
		commandTable!(menuCode+12)=CMselect + changeCommand
		commandTable!(menuCode+13)=CMmTransf2 + changeCommand
		commandTable!(menuCode+14)=CMmTransf4 + changeCommand
		commandTable!(menuCode+15)=CMmTransf6 + changeCommand
		]
	commandTable!(menuCode+16)=CMfont
	commandTable!(menuCode+17)=CMfont
	// left column:
	commandTable!(menuCode+18)=CMthickness
	commandTable!(menuCode+19)=CMthickness
	commandTable!(menuCode+20)=CMthickness
	commandTable!(menuCode+21)=CMthickness
	commandTable!(menuCode+22)=CMfreeHand + changeCommand
	test versionX
	ifso [
		commandTable!(menuCode+24)=CMdash + changeCommand
		commandTable!(menuCode+25)=CMcyclic + changeCommand
		commandTable!(menuCode+29)=CMcTransf2 + changeCommand
		commandTable!(menuCode+30)=CMcTransf4 + changeCommand
		commandTable!(menuCode+31)=CMcTransf6 + changeCommand
		]
	ifnot [
		commandTable!(menuCode+23)=CMpaint + changeCommand
		commandTable!(menuCode+24)=CMpaint + changeCommand
		commandTable!(menuCode+25)=CMpaint + changeCommand
		commandTable!(menuCode+26)=CMcolorOnOff + endCommand
		commandTable!(menuCode+27)=CMdash + changeCommand
		commandTable!(menuCode+28)=CMcyclic + changeCommand
		commandTable!(menuCode+29)=CMdelete + changeCommand
		commandTable!(menuCode+30)=CMcTransf2 + changeCommand
		commandTable!(menuCode+31)=CMcTransf4 + changeCommand
		commandTable!(menuCode+32)=CMcTransf6 + changeCommand
		]
	commandTable!(menuCode+33)=CMfont
	commandTable!(menuCode+34)=CMfont
	// text display buffer
	commandTable!(menuCode+35)=CMtext + changeCommand

	// action table:
	actionTable=needBlock(actionTableSize)
	Zero(actionTable, actionTableSize)

	initActionTable(CMbackUp, CAbackUp)
	initActionTable(CMstartAgain, CAstartAgain)

	initActionTable(CMmake, BAmake, SWaddKnot, EAmake)
	initActionTable(CMcyclic, BAcyclic, SWaddKnot, EAcyclic)

	initActionTable(CMchar, CAchar)
	initActionTable(CMdelChar, CAdelChar)
	initActionTable(CMtext, BAtext, SWtext, EAtext)

	initActionTable(CMdelete, BAdelete, SWdelete)
	initActionTable(CMundelete, CAundelete)

	initActionTable(CMselect, BAselect, SWselect, EAstartAgain)
	initActionTable(CMselectAll, BAselectAll)

	initActionTable(CMmTransf2, BAmTransf2, SWtransform, EAstartAgain)
	initActionTable(CMcTransf2, BAcTransf2, SWtransform, EAstartAgain)
	initActionTable(CMmTransf4, BAmTransf4, SWtransform, EAstartAgain)
	initActionTable(CMcTransf4, BAcTransf4, SWtransform, EAstartAgain)
	initActionTable(CMmTransf6, BAmTransf6, SWtransform, EAstartAgain)
	initActionTable(CMcTransf6, BAcTransf6, SWtransform, EAstartAgain)

	initActionTable(CMredraw, BAredraw, SWredraw)
	initActionTable(CMdash, BAdash, SWdash)

	initActionTable(CMpaint, BApaint, SWpaint)
	initActionTable(CMcolorOnOff, CAcolorOnOff)

	initActionTable(CMdelSelection, CAdelSelection)
	initActionTable(CMrefresh, CArefresh)
	initActionTable(CMshowGrid, CAshowGrid)

	initActionTable(CMquit, CAquit)
	initActionTable(CMhelp, CAhelp)
	initActionTable(CMmoreHelp, CAmoreHelp)

	initActionTable(CMfreeHand, BAfreeHand, SWfreeHand, EAfreeHand)

	initActionTable(CMread, CAread)
	initActionTable(CMwrite, CAwrite)
	initActionTable(CMstatistics, CAstatistics)
	initActionTable(CMbitmap, CAbitmap)
	initActionTable(CMplot, CAplot)
	initActionTable(CMreadFont, CAreadFont)
	initActionTable(CMvideo, CAvideo)

	initActionTable(CMbrush, CAbrush)
	initActionTable(CMthickness, CAthickness)
	initActionTable(CMfont, CAfont)
	initActionTable(CMtextMode, CAtextMode)

	]initEventTable



and initActionTable(CM, BA, SW, EA; numargs n) be [initActionTable
	switchon n into [
		case 4:
			(actionTable!CM)<<ACTION.end=EA
		case 3:
			(actionTable!CM)<<ACTION.switch=SW
		case 2:
			(actionTable!CM)<<ACTION.begin=BA
	]initActionTable