-- Compiler GriffinInit/n
--m.stone February 13, 1981  3:37 PM
--Tiberi December 12, 1979  12:01 PM

DIRECTORY
	GriffinDefs: FROM "GriffinDefs",
	GriffinStartDefs: FROM "GriffinStartDefs",
	PointDefs: FROM "PointDefs",
	ScreenDefs: FROM "ScreenDefs",
	InlineDefs: FROM "InlineDefs",
	MiscDefs: FROM "MiscDefs",
	ControllerMenuDefs: FROM "ControllerMenuDefs",
	ControllerDefs: FROM "ControllerDefs",
	MenuDefs: FROM "MenuDefs",
	SegmentDefs: FROM "SegmentDefs",
	SplineDefs: FROM "SplineDefs",
	Real: FROM "Real",
	GriffinMemoryDefs: FROM "GriffinMemoryDefs";

GriffinInit: PROGRAM
	IMPORTS ScreenDefs, SegmentDefs, InlineDefs,
GriffinMemoryDefs, Real, ControllerMenuDefs, ControllerDefs,
SplineDefs, PointDefs, GriffinStartDefs EXPORTS GriffinDefs = 
BEGIN OPEN GriffinMemoryDefs;

dc: ControllerDefs.DisplayController;
MainScreen: ScreenDefs.Screen;
i: INTEGER ← 0;
NotXM: PUBLIC SIGNAL = CODE;

AllocateBitmapBits: PROCEDURE [nwords,nlines: CARDINAL]
	RETURNS[ptr: POINTER]=
BEGIN OPEN SegmentDefs;
words: CARDINAL = (nwords*nlines+256)/256;
longptr: LONG POINTER TO CARDINAL ← NIL;
memConfig: SegmentDefs.MemoryConfig ← SegmentDefs.GetMemoryConfig[];
zero: CARDINAL ← 0;
--IF NOT memConfig.useXM THEN SIGNAL GriffinDefs.NotXM;
longptr ← LongDataSegmentAddress [NewDataSegment[DefaultBase1,words]];
ptr ← InlineDefs.LowHalf[longptr];
InlineDefs.LongCOPY[from:@zero, to:longptr, nwords:1]; --works on both altos and D*
InlineDefs.LongCOPY[from:longptr, to:longptr+1, nwords:words*256-1]; --set all to zero
END;

Real.InitReals[];

dc ← ControllerDefs.ReadDisplayController[];
MainScreen ← [[bank: 1,nWords: (dc.dwidth+15)/16,nBits: dc.dwidth, nLines: dc.dheight,bits: NIL], 0,0,0,0];
MainScreen.bitmap.bits ←
	AllocateBitmapBits[MainScreen.bitmap.nWords,MainScreen.bitmap.nLines];
IF InlineDefs.BITAND[LOOPHOLE[MainScreen.bitmap.bits,CARDINAL],1]=1 THEN
	MainScreen.bitmap.bits←MainScreen.bitmap.bits+1;

--MainScreen.ty ← 0;
--MainScreen.lx ← 0;
--MainScreen.rx ← MainScreen.bitmap.nBits-1;
--MainScreen.by ← MainScreen.bitmap.nLines-1;

MainScreen.ty ← 6;
MainScreen.lx ← 6;
MainScreen.rx ← 602;
MainScreen.by ← 802;

PointDefs.InitPointFns[];
SplineDefs.InitSplines[Allocate,Free];
ScreenDefs.SetScreen[@MainScreen];
ScreenDefs.ClearScreen[];

START GriffinStartDefs.GriffinFile;
START GriffinStartDefs.ShowObjects;	
START GriffinStartDefs.FigureOps;	
START GriffinStartDefs.ObjectOps;
START GriffinStartDefs.DrawOps;
START GriffinStartDefs.ObjectXForms;
ControllerMenuDefs.InitColorMenu[];
ControllerMenuDefs.InitCaptionMenu[];
ControllerMenuDefs.InitShapeMenu[];

END.