PROGRAM Video; {Set up for 48-line display}

TYPE Memtype = ARRAY[0..3391] OF BYTE;

VAR A, B, C : INTEGER; {Dummy variables}
    M : Memtype ABSOLUTE $EE00:$0000; {Screen memory}
    MA : Memtype ABSOLUTE $EF00:$0000; {Attribute memory}
    MM : Memtype; {Image of data memory}
    MMA : Memtype; {Image of attribute memory}

CONST Lines = 43; {40 character lines + 3 control bytes (Max = 70)}

BEGIN
    PORT[4]:=$20; {60 Hz}
    PORT[4]:=00; {80 col}
    PORT[$0C]:=$0F; {48 line mode}
    FILLCHAR(MM[0],3392,0); {Initialize data memory}
    FILLCHAR(MMA[0],3392,14); {Initialize attribute memory}
    MM[3]:=255; {End of invisible line 1}
    MM[4]:=9; {Point to line 2}
    MM[6]:=255; {End of last line in list}
    MM[7]:=6; {This line points to itself}
    MM[9]:=255; {End of invisible line 2}
    MM[10]:=12; {Point to line 3}
    MM[12]:=255; {End of invisible line 3}
    MM[13]:=16; {Point to first visible line}
    A:=0;
    WHILE A<47 DO {Set up links for all 48 lines}
    BEGIN
	B:=(A+1)*Lines+16; {Beginning of next line}
	MM[B-3]:=255; {End of line}
	MM[B-2]:=LO(B); {Set up link}
	MM[B-1]:=HI(B);
	MMA[B-2]:=255; {Set line attributes}
	A:=A+1 {Next row}
    END;
    MM[48*Lines-2]:=6; {Last line links back to here}
    MMA[48*Lines-3]:=255;
    {At this point, the screen image is ready to move to video memory}
    MEM[$EE00:1]:=0; {Unlink screen lines}
    FOR A:=0 TO 1024 DO C:=C+1; {This delay is required}
    MOVE(MM[3],M[3],3389); {Set screen data memory}
    MOVE(MMA[3],MA[3],3389); {Set attribute memory}
    MEM[$EE00:1]:=3; {Relink screen lines}

    {Do screen stuff here}

    WRITE('[?3l') {Reset screen}
END.

