
(********************************************************************)
(*                                                                  *)
(*  hal.sd7       HAL 9000 simulation program                       *)
(*  Copyright (C) 1991, 1992, 1993, 1994, 2004, 2005  Thomas Mertes *)
(*                                                                  *)
(*  This program is free software; you can redistribute it and/or   *)
(*  modify it under the terms of the GNU General Public License as  *)
(*  published by the Free Software Foundation; either version 2 of  *)
(*  the License, or (at your option) any later version.             *)
(*                                                                  *)
(*  This program is distributed in the hope that it will be useful, *)
(*  but WITHOUT ANY WARRANTY; without even the implied warranty of  *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   *)
(*  GNU General Public License for more details.                    *)
(*                                                                  *)
(*  You should have received a copy of the GNU General Public       *)
(*  License along with this program; if not, write to the           *)
(*  Free Software Foundation, Inc., 51 Franklin Street,             *)
(*  Fifth Floor, Boston, MA  02110-1301, USA.                       *)
(*                                                                  *)
(********************************************************************)


$ include "seed7_05.s7i";
  include "console.s7i";
  include "window.s7i";
  include "keybd.s7i";
  include "time.s7i";
  include "duration.s7i";

var text: scr is STD_NULL;
var text: camera is STD_NULL;
var text: win1 is STD_NULL;
var text: win2 is STD_NULL;
var text: win3 is STD_NULL;
var text: win4 is STD_NULL;
var text: curr_win is STD_NULL;
var char: ch is ' ';


const proc: write_camera (inout text: win) is func
  begin
    writeln(win, "#########");
    writeln(win, "#####HAL#");
    writeln(win, "#########");
    writeln(win, "#########");
    writeln(win, "#########");
    writeln(win, "##     ##");
    writeln(win, "#       #");
    writeln(win, "#       #");
    writeln(win, "##     ##");
    writeln(win, "#########");
    write  (win, "#########");
  end func;


const proc: focus_0 (inout text: win) is func
  begin
    setPos(win, 6, 1);
    writeln(win, "##     ##");
    writeln(win, "#       #");
    writeln(win, "#       #");
    writeln(win, "##     ##");
  end func;


const proc: focus_1 (inout text: win) is func
  begin
    setPos(win, 6, 1);
    writeln(win, "##.---.##");
    writeln(win, "#/     \\#");
    writeln(win, "#\\     /#");
    writeln(win, "##'---'##");
  end func;


const proc: focus_2 (inout text: win) is func
  begin
    setPos(win, 6, 1);
    writeln(win, "## ___ ##");
    writeln(win, "# /   \\ #");
    writeln(win, "# \\___/ #");
    writeln(win, "##     ##");
  end func;


const proc: focus_3 (inout text: win) is func
  begin
    setPos(win, 6, 1);
    writeln(win, "##     ##");
    writeln(win, "#  /'\\  #");
    writeln(win, "#  \\_/  #");
    writeln(win, "##     ##");
  end func;


const proc: focus_4 (inout text: win) is func
  begin
    setPos(win, 6, 1);
    writeln(win, "##     ##");
    writeln(win, "#  .-.  #");
    writeln(win, "#  '-'  #");
    writeln(win, "##     ##");
  end func;


const proc: write_sys_0 (inout text: win) is func
  begin
    clear(win);
    writeln(win);
    writeln(win, "  ####  ##  ##   ####");
    writeln(win, " ###    ##  ##  ###");
    writeln(win, "    ###   ##       ###");
    writeln(win, "  ####    ##     ####");
    writeln(win);
    writeln(win, "  System Module");
    writeln(win);
  end func;


const proc: write_sys_1 (inout text: win) is func
  begin
    clear(win);
    writeln(win);
    writeln(win, " HAL-9000  Version 2.0");
    writeln(win, " Copyright 1990 Thomas Mertes");
    writeln(win);
    writeln(win, " SYSTEM IS UP");
    writeln(win);
  end func;


const proc: write_shp (inout text: win) is func
  begin
    clear(win);
    writeln(win, "  .          .           .      ");
    writeln(win, "   .    *          .        .   ");
    writeln(win, "    __       .            ___   ");
    writeln(win, "   /  \\_________O________/  _|  ");
    writeln(win, "  |*   __________________   _|  ");
    writeln(win, "   \\__/              .   \\___|  ");
    writeln(win, "         .    .                 ");
    writeln(win, "    .           .       .    *  ");
    write  (win, "         .             .        ");
  end func;


const proc: write_antenna (inout text: win) is func
  begin
    clear(win);
    writeln(win, "                   /\",          ");
    writeln(win, "          O_     /'  |          ");
    writeln(win, "            '-,/'   ,|          ");
    writeln(win, "              /'-, ,|           ");
    writeln(win, "             /    /\"\\\\_         ");
    writeln(win, "            / _,*'   I=I        ");
    writeln(win, "            \"\"       I I        ");
    writeln(win, "   /===\\         ,/\"\"\" \"\"\"\\,    ");
    write  (win, "--#     #--------#         #----");
  end func;


const proc: write_com (inout text: win) is func
  begin
    clear(win);
    writeln(win);
    writeln(win, "   ####  ####  ##   ##");
    writeln(win, "  ##    ##  ## #######");
    writeln(win, "  ##    ##  ## ## # ##");
    writeln(win, "   ####  ####  ##   ##");
    writeln(win);
    writeln(win, "  Command Organisation Module");
    writeln(win);
  end func;


const proc: write_lrn_0 (inout text: win) is func
  begin
    clear(win);
    writeln(win);
    writeln(win, "  ##    #####   ##   ##");
    writeln(win, "  ##    ##  ##  #### ##");
    writeln(win, "  ##    #####   ## ####");
    writeln(win, "  ##### ##  ##  ##   ##");
    writeln(win);
    writeln(win, "  LeaRNing module");
    writeln(win);
  end func;


const proc: write_lrn_1 (inout text: win) is func
  begin
    clear(win);
    writeln(win);
    writeln(win, " Good morning mister Chandra");
    writeln(win, " I am ready for my first");
    writeln(win, " Lesson");
    writeln(win);
  end func;


const proc: main is func
  local
    var integer: count is 0;
  begin
    scr := open(CONSOLE);
    camera := openWindow(scr, 10, 36, 11, 9);
    win1 := openWindow(scr, 2, 2, 9, 32);
    win2 := openWindow(scr, 2, 47, 9, 32);
    win3 := openWindow(scr, 14, 2, 9, 32);
    win4 := openWindow(scr, 14, 47, 9, 32);
    box(win1);
    box(win2);
    box(win3);
    box(win4);
    write_camera(camera);
    write_sys_0(win1);
    write_shp(win2);
    write_com(win3);
    write_lrn_0(win4);
    while busy_getc(KEYBOARD) = KEY_NONE do
      case rand(1, 4) of
        when {1}: curr_win := win1;
        when {2}: curr_win := win2;
        when {3}: curr_win := win3;
        when {4}: curr_win := win4;
      end case;
      case rand(1, 7) of
        when {1}: write_sys_0(curr_win);
        when {2}: write_sys_1(curr_win);
        when {3}: write_shp(curr_win);
        when {4}: write_antenna(curr_win);
        when {5}: write_com(curr_win);
        when {6}: write_lrn_0(curr_win);
        when {7}: write_lrn_1(curr_win);
      end case;
      case rand(0, 4) of
        when {0}: focus_0(camera);
        when {1}: focus_1(camera);
        when {2}: focus_2(camera);
        when {3}: focus_3(camera);
        when {4}: focus_4(camera);
      end case;
      flush(scr);
      await(time(NOW) + 500000 . MICRO_SECONDS);
    end while;
    setPos(scr, 24, 1);
  end func;
