program CRTLST,1.7(12)  ! 23-Sept-84    Irv Bromberg, edited 20-Mar-86

map1 ch,f               ! file channel# variable
map1 File,s,36          ! output filename
map1 String,s,40        ! string to hold TCRT sequence output by driver
map1 LastStr,s,40       ! last string processed
map1 Code,f             ! ASCII code value
map1 I,f                ! for-next iterative counter
map1 ScrCmd,f           ! screen command number
map1 CRLF,s,2,chr(13)+chr(10)
map1 DimON,b,1,11       ! TCRT command for dim ON
map1 DimOFF,b,1,12      ! TCRT command for dim OFF

print tab(-1,0);        ! clear screen
print "CRTLST - This program lists the TCRT calls generated by the terminal"
print "driver your terminal is using, in source code format."
print
print "Hint:  This program runs faster if you LOAD TCRT.SBR first."
print
print "Enter a filename for listing (default ext=DAT): ";

input line "",File
! if no filename specified then send output to user's screen
ch=(File<>"")   ! True = -1 = filename specified, False = 0 = no filename
if File="" File="CRTLST.TMP"    ! if no filename then use temporary name
open #ch,File,output

print #ch "RADIX 10";CRLF;"CTRL=-64";CRLF
print #ch "Cursor addressing:"  ! just show an example of cursor address
print #ch                               ! sequences, for top left corner and bottom
print #ch "Row=01 Col=01 -- ";  ! right corner
xcall TCRT,String,chr(1)+chr(1)
call Codes
print #ch "Row=24 Col=80 -- ";
xcall TCRT,String,chr(24)+chr(80)
call Codes
print #ch

print #ch "Screen Commands:"    ! do all tab(-1,n) functions for values of
for ScrCmd=0 to 255             ! n from 0 to 255
                               ! Get screen command into string,
 xcall TCRT,String,ScrCmd      ! see AMUS.LOG 8(8):33,35 Aug/85
 if ch=0 goto ChkStr

! If outputting to disk file then show activity on user's screen but indicate
! which TCRT commands are not implemented by showing them in DIM video:
       if String="" print tab(-1,DimON);
       print ScrCmd using "####";      ! show current TCRT command#
       if String="" print tab(-1,DimOFF);

ChkStr:  if String="" goto SaveLast
   if LastStr="" print #ch     ! output empty line only if last was not empty
   print #ch "C"+ScrCmd+":";space(6-len(ScrCmd));      ! constant spacing
   call Codes

SaveLast: LastStr=String
next ScrCmd
if ch print     ! end of activity display if output was to file
print "Done"
end

Codes:  print #ch "BYTE     ";  ! make it like TDV source code
       for I=1 to len(String)
       Code=asc(String[I;1])   ! get next character to show
       if Code>127 print #ch "128+"; : Code=Code-128 ! show chars with parity set
       if Code<32 print #ch "CTRL+"; : Code=Code+64    ! show control codes
       print #ch "'";chr(Code);",";    ! output in source code like format
       next I
       print #ch "0"   ! need terminating null at end of each TCRT sequence
       return