.title TerminalQio Perform Terminal Qio

;
; Author:	Rodrick A. Eldridge
;		104 Computer Science
;		Iowa State University
;		Ames, Iowa 50011
;		(515) 294-5659
;
; Created:	April 1986
;
; Modification History:
;
; Description:	This module contains a set of routines for performing
;		qios to the terminal.
;
;		The routines that are available are:
;
;			routine name	parameters
;			------------	----------
;
;			TerminalQio
;
;			Get		flag,prompt,char
;			GetString	flag,prompt,string
;
;			Put		flag,char
;			PutString	flag,string
;			PutLn
;



external module TerminalQio	<>

external module Get		<flag,prompt,char>
external module GetString	<flag,prompt,string>

external module Put		<flag,char>
external module PutString	<flag,string>
external module PutLn		<>

const
  $dscdef		; descriptor definitions
  $iodef		; i/o definitions
  max_length=512


global module TerminalQio -
  psect=terminal_qio

var
  tt_chan:		.blkw 1
  tt_func:		.blkw 1

  tt_iosb:		.blkw 1
  tt_length:		.blkw 1
			.blkl 1

  tt_cr_lf:		.byte 13,10

  tt_name:		.ascid /TT:/

  tt_char:		.blkb 1

  tt_prompt:		.blkb max_length
  tt_string:		.blkb max_length

begin

  ;
  ; assign channel to terminal
  ;

  $assign_s	chan=tt_chan,-
		devnam=tt_name

  return

end


global module Get <flag,prompt,char> -
  psect=terminal_qio -
  mask=<r6,r7>

begin

  if <tstw tt_chan> eql then
    TerminalQio
    if <lbc r0> then
      return
    end
  end

  if <tstl Get.prompt(ap)> eql then

    movl  #io$_readvblk,tt_func
    if <tstl Get.flag(ap)> neq then
      addw @Get.flag(ap),tt_func
    end

    $qiow_s	chan=tt_chan,-
		func=tt_func,-
		iosb=tt_iosb,-
		p1=tt_char,p2=#1

  else

    movl  #io$_readprompt,tt_func
    if <tstl Get.flag(ap)> neq then
      addw @Get.flag(ap),tt_func
    end

    movq  @Get.prompt(ap),r6			; r6=prompt length, r7=address
    movc5 r6,(r7),#^a/ /,#max_length,tt_prompt
    movw  r6,tt_length
  
    $qiow_s	chan=tt_chan,-
		func=tt_func,-
		iosb=tt_iosb,-
		p1=tt_char,p2=#1,-
		p3=#tt_prompt,p4=#tt_length

  end

  if <lbs r0> then
    movzwl tt_iosb,r0
    if <lbc r0> then
      return
    end
  end

  movb tt_char,@Get.char(ap)			; return character

  return

end


global module GetString <flag,prompt,descr> -
  psect=terminal_qio -
  mask=<r6,r7>

begin

  if <tstw tt_chan> eql then
    TerminalQio
    if <lbc r0> then
      return
    end
  end

  if <tstl GetString.prompt(ap)> eql then

    movl  #io$_readvblk,tt_func
    if <tstl GetString.flag(ap)> neq then
      addw @GetString.flag(ap),tt_func
    end

    $qiow_s	chan=tt_chan,-
		func=tt_func,-
		iosb=tt_iosb,-
		p1=tt_string,p2=#max_length

  else

    movl  #io$_readprompt,tt_func
    if <tstl GetString.flag(ap)> neq then
      addw @GetString.flag(ap),tt_func
    end

    movq  @GetString.prompt(ap),r6		; r6=prompt length, r7=address
    movc5 r6,(r7),#^a/ /,#max_length,tt_prompt
    movw  r6,tt_length
  
    $qiow_s	chan=tt_chan,-
		func=tt_func,-
		iosb=tt_iosb,-
		p1=tt_string,p2=#max_length,-
		p3=#tt_prompt,p4=#tt_length

  end

  if <lbs r0> then
    movzwl tt_iosb,r0
    if <lbc r0> then
      return
    end
  end

  movq  @GetString.descr(ap),r6			; r6=string length, r7=address
  movc5 tt_length,tt_string,#^a/ /,r6,(r7)

  return

end


global module Put <flag,char> -
  psect=terminal_qio

begin

  ;
  ; Put a character to the terminal
  ;

  if <tstw tt_chan> eql then
    TerminalQio
    if <lbc r0> then
      return
    end
  end

  movb  @Put.char(ap),tt_char

  movl  #io$_writevblk,tt_func
  if <tstl Put.flag(ap)> neq then
    addw @Put.flag(ap),tt_func
  end

  $qiow_s	chan=tt_chan,-
		func=tt_func,-
		iosb=tt_iosb,-
		p1=tt_char,p2=#1

  if <lbs r0> then
    movzwl tt_iosb,r0
  end

  return

end


global module PutString <flag,descr> -
  psect=terminal_qio -
  mask=<r6,r7>

begin

  ;
  ; Put a string to the terminal
  ;

  if <tstw tt_chan> eql then
    TerminalQio
    if <lbc r0> then
      return
    end
  end

  movq  @PutString.descr(ap),r6			; r6=string length, r7=address
  movc5 r6,(r7),#^a/ /,#max_length,tt_string
  movw  r6,tt_length

  movl  #io$_writevblk,tt_func
  if <tstl PutString.flag(ap)> neq then
    addw @PutString.flag(ap),tt_func
  end

  $qiow_s	chan=tt_chan,-
		func=tt_func,-
		iosb=tt_iosb,-
		p1=tt_string,p2=tt_length

  if <lbs r0> then
    movzwl tt_iosb,r0
  end

  return

end


global module PutLn -
  psect=terminal_qio

begin

  ;
  ; Put carriage control and line feed to terminal
  ;

  if <tstw tt_chan> eql then
    TerminalQio
    if <lbc r0> then
      return
    end
  end

  $qiow_s	chan=tt_chan,-
		func=#io$_writevblk!io$m_noformat,-
		iosb=tt_iosb,-
		p1=tt_cr_lf,p2=#2

  if <lbs r0> then
    movzwl tt_iosb,r0
  end

  return

end

.end
