--VideoMagic.mesa
--last edited by Maureen Stone September 10, 1982 3:49 pm
--last edited by Ken Pier November 18, 1982 1:14 pm

DIRECTORY
 DisplayExtras,
 DoradoInputOutput,
 ColorDisplay,
 ColorDisplayHeadDorado,
 Real;
 
VideoMagic: PROGRAM IMPORTS DisplayExtras, ColorDisplay, ColorDisplayHeadDorado,
                                         DoradoInputOutput, Real
SHARES ColorDisplayHeadDorado= {OPEN DisplayExtras, ColorDisplayHeadDorado, ColorDisplay;


SetTables: PROC [factor: REAL] = {
	FOR i: NAT IN [0..255] DO
		in,out: Byte;
		in ← GetRedMap[i];
		out ← MIN[255,MAX[0,Real.RoundI[in*factor]]];
		ColorDisplay.SetRedMap[in: i, out: out];
		in ← GetGreenMap[i];
		out ← MIN[255,MAX[0,Real.RoundI[in*factor]]];
		ColorDisplay.SetGreenMap[in: i, out: out];
		in ← GetBlueMap[i];
		out ← MIN[255,MAX[0,Real.RoundI[in*factor]]];
		ColorDisplay.SetBlueMap[in: i, out: out];
		ENDLOOP;
	};
SetLineSize: PROC [size: CARDINAL] = {
  color.hcontrol.HRamMaxAddr ← size;
  mcb.flags.hc ← TRUE;
  };
	
SetMDSH: PROC [m: [0..377B] ← 115, d: [0..16] ← 12, 
                    z: [0..17B] ← 5, size: CARDINAL, h: CARDINAL] = {
  color.hcontrol.HRamMaxAddr ← size;
  color.hcontrol.HBTrailLength ← h;
  color.ccontrol ← [zero: z, mul: m, div: d];
  mcb.flags ← [hc: TRUE, clk: TRUE];
  };

Set24: PROC [m: [0..377B] ← 115, d: [0..16] ← 14,
               z: [0..17B] ← 5, size: CARDINAL ← 909, h: CARDINAL ← 30] = {
  color.ccontrol ← [zero: z, mul: m, div: d];
  
  color.hcontrol.HRamMaxAddr ← size;
  color.hcontrol.HBLeadLength ← 2*HBLeadLength;
  color.hcontrol.HSTrailAddr ← 2*HSTrailAddr;
  color.hcontrol.HBTrailLength ← 2*h;
  achan.leftMargin ← bchan.leftMargin ← 550B;
  mcb.flags ← [hc: TRUE, clk: TRUE];
    };

Set77: PROC [] = {
  [] ← DisplayExtras.SetFieldRate[lf77hz];
  };

Set60: PROC [] = {
  [] ← DisplayExtras.SetFieldRate[lf60hz];
  };

XSyncEnable: PROC [] = {
  DoradoInputOutput.Output[datum: 200B, register: 377B];
  };

XSyncDisable: PROC [] = {
  DoradoInputOutput.Output[datum: 0, register: 377B];
  };



HBLeadLength: [0..377B] ← 6;
HSTrailAddr: [0..377B] ← 28;

}.