program MASTMIND; (* written in TURBO PASCAL by Doug Cox July '85
                                    for the Osborne 1 & Vixen only *)
label Q; {$B-}
const
  Loc: Array[1..8] of Char = 'Location';
  Let: Array[1..6] of Char = 'Letter';
  Mast: Array[1..4] of Char = 'MAST';
  Mind: Array[1..4] of Char = 'MIND';
  Replay: Array[1..33] of Char = 'Do you want to play again (Y/N)? ';
  ScreenTop: Integer= $F000;
type
  Row= 1..24; Col= 1..128;
  PointerType= ^ScreenPointer;
  ScreenPointer= Array[Row, Col] of Byte;
var
  p: PointerType ABSOLUTE ScreenTop;
  ch: Char;
  box: Array[1..4] of Char;
  temp: Array[1..4] of Char;
  locations, letters: Array[1..7] of Byte;
  h, i, j, k, v, w, x, y, z: Byte;
  ok: Boolean;
begin
repeat
  ClrScr;
  p^[1,1]:= 32; (* space *)
  x:= 31;
  repeat
    for y:= 6 to 22 do p^[y,x]:= 22; (* graphic 'v' *)
    x:= x + 4;
  until x = 51;
  x:= 32;
  for z:= 1 to 4 do
  begin
    for x:= x to x + 2 do
    begin
      y:= 6;
      repeat
        p^[y,x]:= 27; (* graphic '}' *)
        y:= y + 2;
      until y = 24;
    end;
    x:= x + 2;
  end;
  y:= 4;
  for x:= 31 to 33 do p^[y,x]:= 13; (* graphic 'm' *)
  for x:= 45 to 47 do p^[y,x]:= 13;
  p^[y,34]:= 22; p^[y,39]:= 22; p^[y,44]:= 22;
  for x:= 35 to 38 do p^[y,x]:= Ord(Mast[x-34]) + 128;
  for x:= 40 to 43 do p^[y,x]:= Ord(Mind[x-39]) + 128;
  p^[7,33]:= 22; p^[7,37]:= 22; p^[7,41]:= 22; p^[7,45]:= 22;
  x:= 29;y:= 24; z:= 64;
  repeat
    p^[y,x]:= Ord(succ(z)); (* 'A' thru 'F' *)
    x:= x + 4; z:= z + 1;
  until x = 53;
  for z:= 1 to 4 do
  begin
    Randomize;
    x:= Random (60); x:= Trunc (x div 10);
    box[z]:= Chr(x + 65);
  end;
  for z:= 1 to 7 do locations[z]:= 0;
  for z:= 1 to 7 do letters[z]:= 0;
  h:= 19; i:= 21; j:= 49; k:= 21; v:= 1; y:= 21; z:= 1;
  repeat
    x:= 33;
    for w:= 1 to 4 do temp[w]:= box[w];
    for w:= 1 to 4 do
    begin
      p^[y,x]:= 127; read (Kbd, ch); ch:= UpCase(ch);
      if ch = ^C then Goto Q;
      if ch in ['A'..'F'] then p^[y,x]:= Ord(ch)
      else p^[y,x]:= 63; (* ? *)
      x:= x + 4;
      if ch = box[w] then locations[z]:= locations[z] + 1;
      if ch = temp[1] then
        begin temp[1]:= Chr(1); letters[z]:= letters[z] + 1; end
      else if ch = temp[2] then
        begin temp[2]:= Chr(1); letters[z]:= letters[z] + 1; end
      else if ch = temp[3] then
        begin temp[3]:= Chr(1); letters[z]:= letters[z] + 1; end
      else if ch = temp[4] then
        begin temp[4]:= Chr(1); letters[z]:= letters[z] + 1; end;
    end;
    for x:= 21 to 28 do p^[y,x]:= Ord(Loc[x-20]);
    for x:= 51 to 56 do p^[y,x]:= Ord(Let[x-50]);
    p^[i,h]:= locations[z] + 48; p^[k,j]:= letters[z] + 48;
    if locations[z] <> 1 then p^[y,29]:= 115; (* s *)
    if letters[z] <> 1 then p^[y,57]:= 115;
    i:= i - 2; k:= k - 2; v:= v + 1; y:= y - 2; z:= z + 1;
  until (locations[z-1] = 4) or (v = 8);
Q:p^[7,32]:= 22; p^[7,34]:= 22; p^[7,36]:= 22; p^[7,38]:= 22;
  p^[7,40]:= 22; p^[7,42]:= 22; p^[7,44]:= 22; p^[7,46]:= 22;
  p^[7,33]:= Ord(box[1]) + 128; p^[7,37]:= Ord(box[2]) + 128;
  p^[7,41]:= Ord(box[3]) + 128; p^[7,45]:= Ord(box[4]) + 128;
  for x:= 22 to 54 do p^[1,x]:= Ord(Replay[x-21]); p^[1,55]:= 22;
  read (Kbd, ch);
until UpCase(ch) <> 'Y';
ClrScr;
end.
