-- SimIOImpl.mesa
-- created by Suzuki,  5-Jan-82 15:35:30

DIRECTORY
  Rope: TYPE,
  SimIO: TYPE,
  TTY: TYPE USING [Create, Destroy, Handle, PutChar],
  CWF;
  
SimIOImpl: MONITOR IMPORTS Rope, TTY, CWF
   EXPORTS SimIO = { OPEN TTY;

  SimWindow: TTY.Handle;
  
  CR: CHARACTER = 15C;
  
  Start: PUBLIC ENTRY PROC = {
    SimWindow ← TTY.Create["SimIO"]};
  
  WF0: PUBLIC ENTRY PROC [s: LONG STRING] = {
    CWF.FWF0[Char1,s]};
  WF1: PUBLIC ENTRY PROC [s: LONG STRING, f: LONG POINTER] = {
    CWF.FWF1[Char1,s,f]};
  WF2: PUBLIC ENTRY PROC [s: LONG STRING, f1, f2: LONG POINTER] = {
    CWF.FWF2[Char1, s, f1, f2]};
  WF3: PUBLIC ENTRY PROC [s: LONG STRING, f1, f2, f3: LONG POINTER] = {
    CWF.FWF3[Char1, s, f1, f2, f3]};
  WF4: PUBLIC ENTRY PROC [s: LONG STRING, f1, f2, f3, f4: LONG POINTER] = {
    CWF.FWF4[Char1, s, f1, f2, f3, f4]};

  Stop: PUBLIC ENTRY PROC = {TTY.Destroy[SimWindow]};
  
  CharAction: PROC [c: CHARACTER] RETURNS [BOOLEAN] = {
    PutChar[SimWindow, c]; RETURN [FALSE]};
    
  Char1: PROC [c: CHARACTER] = {PutChar[SimWindow, c]};
    
  PutRope: PROC [r: Rope.Ref, newLine: BOOLEAN ← FALSE] = {
    [] ← Rope.Map[base: r, action: CharAction];
    IF newLine THEN PutChar[SimWindow, CR];
    };
    
  }.