DEFINITION MODULE ScreenBIOS;

(*
  This module will use screen coordinates as defined by Wirth  (0,0 is the
  lower left hand corner of the page), FOR GRAPHICS ONLY. Text coordinates
  are defined with 0,0 in the upper left hand corner of the screen.
  Page refers to page number defined as 0 to 7 for lowResText, 0 to 3 for
  hiResText, and 0 for graphics.
*)

  EXPORT QUALIFIED
    screenMode, area, settings, current,
    SetScreenMode, SetCursorType, PutCursor, GetCursor, CursorOff, CursorOn,
    RestoreScreen, ReadLightPenPosition, SelectActivePage,
    ScrollUp, ScrollDown, ClearScreen, GetChar, PutCharAttr, PutChar,
    SetPalette, WritePixel, ReadPixel, WriteChDTD, GetVideoState,
    SetScrollMode;

  TYPE
    screenMode = (mono40x25, col40x25, mono80x25, col80x25, col320x200,
                  mono320x200, mono640x200, bw80x25);
    area = RECORD
      topMargin, bottomMargin, leftMargin, rightMargin: CARDINAL
      (* in text coordinates *)
    END;
    settings = RECORD
      mode: screenMode;
      window: area;
      page: CARDINAL;
      numCols: CARDINAL;
      maxGraphX, maxGraphY: INTEGER;
      cursY, cursX: CARDINAL;
      cursorStart, cursorEnd: CARDINAL;
      attrib: CARDINAL;
    END;

  VAR
    current: settings;

  PROCEDURE SetScreenMode(newMode: screenMode);
    (*
       screenMode = (mono40x25, col40x25, mono80x25, col80x25, col320x200,
                    mono320x200, mono640x200, bw80x25);
    *)

  PROCEDURE SetCursorType(startScan, endScan : CARDINAL);

  PROCEDURE PutCursor(row, column, page : CARDINAL);

  PROCEDURE GetCursor(VAR row, column : CARDINAL;
                                 page : CARDINAL;
                                 VAR startScan, endScan : CARDINAL);
    (* Returns both cursor position and cursor type. *)

  PROCEDURE CursorOn;

  PROCEDURE CursorOff;

  PROCEDURE RestoreScreen; (* Restore screen to initial entry params *)

  PROCEDURE ReadLightPenPosition(VAR x, y:CARDINAL);
    (* Not implemented *)

  PROCEDURE SelectActivePage(page : CARDINAL);

  PROCEDURE ScrollUp(lines: CARDINAL; window : area; attr: CARDINAL);

  PROCEDURE ClearScreen(attr: CARDINAL);

  PROCEDURE ScrollDown(lines: CARDINAL; window : area; attr: CARDINAL);

  PROCEDURE GetChar(VAR ch : CHAR; VAR attr: CARDINAL; page: CARDINAL);
    (* Reads the character at the current cursor position *)

  PROCEDURE PutCharAttr(ch : CHAR; attr: CARDINAL; count, page: CARDINAL);
    (* Writes the character at the current cursor position with attribute
       for text or colour in graphics, count times *)

  PROCEDURE PutChar(ch : CHAR; count, page: CARDINAL);
    (* Writes the character at the current cursor position count times *)

  PROCEDURE SetPalette(ID, colour : CARDINAL);
    (* medResGraphics ONLY *)
    (* ID = 0 -> colour = background, ID = 1, corour = palette (0 or 1) *)

  PROCEDURE WritePixel(row, column, colour: CARDINAL);

  PROCEDURE ReadPixel(row, column: CARDINAL; VAR colour: CARDINAL);

  PROCEDURE WriteChDTD(ch: CHAR; colour: CARDINAL; page: CARDINAL);
    (* Checks for bs, cr, lf, bel and executes as commands. *)

  PROCEDURE GetVideoState( VAR mode : screenMode; VAR col: CARDINAL;
                           VAR page: CARDINAL);

  PROCEDURE SetScrollMode(mode: CARDINAL);
    (* FOR Heath MS-DOS BIOS ONLY
       0 = normal software, 1 = jump scroll (hardware), 2 = smooth *)

  END ScreenBIOS.
