(* * * * * * * * * * * * * * * * * * *
 *
 * prog6-1.pas --     VM demo
 *
 *      This test program demonstrates
 *          - vm intialization
 *          - allocation
 *          - wiring
 *
 * * * * * * * * * * * * * * * * * * *)

program prog6_1;

uses    _globals,
        _vm;

label
    100;

var
    vm:                 VM_Vm;
    handle1:            VM_VmBlk;
    addr:               Pointer;    

begin
    addr:= Nil;
    if vm.init(16384) then begin
        goto 100;
        end;

    if handle1.alloc(100000) then begin
        goto 100;
        end;

    (*
     *  Write some text to various places in the VM block
     *)
    if handle1.wire(54320, 80, addr) then begin
        goto 100;
        end;
    StrPtr(addr)^:= '      Americans are broad minded people. They''ll';
    if handle1.unwire(54320, 80, True) then begin
        goto 100;
        end;

    if handle1.wire(660, 80, addr) then begin
        goto 100;
        end;
    StrPtr(addr)^:= '      accept the fact that a person can be an alcoholic,';
    if handle1.unwire(660, 80, True) then begin
        goto 100;
        end;

    if handle1.wire(9878, 80, addr) then begin
        goto 100;
        end;
    StrPtr(addr)^:= '      a dope fiend, a wife beater, and even a newspaperman,';
    if handle1.unwire(9878, 80, True) then begin
        goto 100;
        end;

    if handle1.wire(76654, 80, addr) then begin
        goto 100;
        end;
    StrPtr(addr)^:= '      but if a man doesn''t drive, there''s something wrong';
    if handle1.unwire(76654, 80, True) then begin
        goto 100;
        end;

    if handle1.wire(10, 80, addr) then begin
        goto 100;
        end;
    StrPtr(addr)^:= '      with him.';
    if handle1.unwire(10, 80, True) then begin
        goto 100;
        end;

    if handle1.wire(24000, 80, addr) then begin
        goto 100;
        end;
    StrPtr(addr)^:= '                          -- Art Buchwald';
    if handle1.unwire(24000, 80, True) then begin
        goto 100;
        end;


    (*
     *  Now let's recall the blocks.
     *)
    if handle1.wire(54320, 80, addr) then begin
        goto 100;
        end;
    writeln(StrPtr(addr)^);
    if handle1.unwire(54320, 80, False) then begin
        goto 100;
        end;

    if handle1.wire(660, 80, addr) then begin
        goto 100;
        end;
    writeln(StrPtr(addr)^);
    if handle1.unwire(660, 80, False) then begin
        goto 100;
        end;

    if handle1.wire(9878, 80, addr) then begin
        goto 100;
        end;
    writeln(StrPtr(addr)^);
    if handle1.unwire(9878, 80, False) then begin
        goto 100;
        end;

    if handle1.wire(76654, 80, addr) then begin
        goto 100;
        end;
    writeln(StrPtr(addr)^);
    if handle1.unwire(76654, 80, False) then begin
        goto 100;
        end;

    if handle1.wire(10, 80, addr) then begin
        goto 100;
        end;
    writeln(StrPtr(addr)^);
    if handle1.unwire(10, 80, False) then begin
        goto 100;
        end;

    if handle1.wire(24000, 80, addr) then begin
        goto 100;
        end;
    writeln(StrPtr(addr)^);
    if handle1.unwire(24000, 80, False) then begin
        goto 100;
        end;
    
    if handle1.free then
        ;

    if vm.shutdown then
        ;

    Halt;
100:
    write('Died: Error #',  errno);
end.

