#INCLUDE "course.module"

PROC test (CHAN BYTE keyboard?, screen!, error!)
  --{{{  
  -- COPYRIGHT : P.H.Welch, 1984
  
  SEQ
    --{{{  simple pause
    SEQ
      out.string ("Press a key ...", 0, screen!)
      flush (screen!)
      --{{{  wait for keystroke
      BYTE ch:
      keyboard ? ch
      --}}}
      out.string ("*c*n", 0, screen!)
    --}}}
    --{{{  test screen
    VAL [][2]BYTE coord IS [[41, 11], [20, 5], [30, 15], [3, 16], [12, 20],
                            [58, 7], [6, 9], [54, 18], [45, 1], [5, 3]]:
    VAL INT X IS 0:
    VAL INT Y IS 1:
    SEQ
      erase.screen (screen!)
      SEQ i = 0 FOR SIZE coord
        VAL [2]BYTE c IS coord[i]:
        SEQ
          cursor.x.y (c[X], c[Y], screen!)
          out.string ("Hello World", 0, screen!)
          flush (screen!)
          --{{{  wait for keystroke
          BYTE ch:
          keyboard ? ch
          --}}}
      erase.screen (screen!)
      flush (screen!)
      --{{{  wait for keystroke
      BYTE ch:
      keyboard ? ch
      --}}}
      SEQ count = 0 FOR 10
        VAL BYTE bcount IS BYTE count:  -- bcount is a BYTE version of count
        SEQ i = 0 FOR SIZE coord        -- bcount is needed 3 lines below this one
          VAL [2]BYTE c IS coord[i]:    -- (because we can't add a BYTE to an INT)
          SEQ
            cursor.x.y (c[X] + bcount, c[Y] + bcount, screen!)
            out.string ("Goodbye World", 0, screen!)
      flush (screen!)
      --{{{  wait for keystroke
      BYTE ch:
      keyboard ? ch
      --}}}
      erase.screen (screen!)
      cursor.x.y (1, 1, screen!)         -- place cursor top-right on a blank screen
      flush (screen!)
    --}}}
    --{{{  test out.int
    SEQ
      out.string ("*c*n", 0, screen!)
      out.int (42, 10, screen!)
      out.int (-42, 10, screen!)
      out.string ("*c*n*n", 0, screen!)
    --}}}
    --{{{  test in.string
    [20]BYTE s:
    INT length:
    BOOL ok:
    SEQ
      ok := TRUE
      WHILE ok
        SEQ
          out.string ("String (up to 10 characters)? ", 0, screen!)
          flush (screen!)
          in.string (s, length, 10, keyboard?, screen!)
          out.string ("*c*n  --> *"", 0, screen!)
          out.string ([s FOR length], 0, screen!)
          out.string ("*" (", 0, screen!)
          out.int (length, 0, screen!)
          out.string (" characters)*c*nAgain (yes/no)? ", 0, screen!)
          flush (screen!)
          in.bool (ok, keyboard?, screen!)
          out.string ("*c*n*n", 0, screen!)
    --}}}
    --{{{  test in.int
    INT n:
    BOOL ok:
    SEQ
      ok := TRUE
      WHILE ok
        SEQ
          out.string ("Number? ", 0, screen!)
          flush (screen!)
          in.int (n, 10, keyboard?, screen!)
          out.string ("*c*n  --> ", 0, screen!)
          out.int (n, 0, screen!)
          out.string ("*c*nAgain (yes/no)? ", 0, screen!)
          flush (screen!)
          in.bool (ok, keyboard?, screen!)
          out.string ("*c*n*n", 0, screen!)
    --}}}
    --{{{  test ask stuff
    BOOL more:
    SEQ
      more := TRUE
      WHILE more
        [10]BYTE name:
        INT name.length, age:
        VAL INT this.year IS 2000:
        VAL INT target.age IS 21:
        SEQ
          ask.string ("Name? ", name, name.length, 10, keyboard?, screen!)
          ask.int ("Age? ", age, 2, keyboard?, screen!)
          out.string ("   --> ", 0, screen!)
          out.string ([name FOR name.length], 0, screen!)
          out.string (" will be ", 0, screen!)
          out.int (target.age, 0, screen!)
          out.string (" in ", 0, screen!)
          out.int (this.year + (target.age - age), 0, screen!)
          out.string (" approximately*c*n", 0, screen!)
          ask.bool ("Again(yes/no)? ", more, keyboard?, screen!)
          out.string ("*c*n", 0, screen!)
    --}}}
    --{{{  test string stuff
    BOOL more:
    SEQ
      more := TRUE
      WHILE more
        [10]BYTE a, b:
        INT a.length, b.length:
        SEQ
          ask.string ("First string? ", a, a.length, 10, keyboard?, screen!)
          ask.string ("Second string? ", b, b.length, 10, keyboard?, screen!)
          IF
            equal.string (a, b)
              out.string ("   --> Strings are the same*c*n", 0, screen!)
            TRUE
              out.string ("   --> Strings are different*c*n", 0, screen!)
          CASE compare.string (a, b)
            string.less
              out.string ("   --> First < Second*c*n", 0, screen!)
            string.same
              out.string ("   --> First = Second*c*n", 0, screen!)
            string.more
              out.string ("   --> First > Second*c*n", 0, screen!)
          ask.bool ("Again(yes/no)? ", more, keyboard?, screen!)
          out.string ("*c*n", 0, screen!)
    --}}}
  --}}}
:
