...............................<
laser
topmargin 1"
bottommargin 1"
margin 1"
; The following rulers work for Times-Roman and Helvetica - 10 point type
font helvetica
point 10
; Three columns per page (2 1/16")
...............................<

; Two columns per page (3 1/16")
.................................................<

                       AAA
                     by SDH

NOTE: Alphanso's Assembler Assylum has been running
now since December  of  '85.  If  you find yourself
confused or lost during these "beginning" assembler
sessions,  refer  to  the previous AAA's  for  more
details.  There  are some  topics  that  have  been
covered previously that are not discussed in detail
every month.

        Tweeking the Terminal Status Word

 This  month's  session   will  explore a few neat
tricks  you  may  perform with the Terminal  Status
Word.  You  will  also   be   introduced   to  "bit
flipping", talk more about error trapping,  and (of
course), continue employing MACROs.
hlt bold
_Status Words_
 In order for AMOS to keep  track  of each JOB and
terminal on the system, status words are maintained
down  in  system  memory. Status words are  nothing
more  than  a  series  of  bits  (usually  16  bits
contained  in  a  word), where each bit in the word
represents a characteristic  or particular "status"
of  the  JOB  or terminal. The bits  are  sometimes
refered as "flags". If a certain bit is
hlt italic
on,  we  say the flag is _set_, if the bit is off, we
say the flag  is  _clear_.  In this months session, a
frequently  used  status  word  is   going   to  be
modified. This word is the Terminal Status Word.
 AMOS has  a naming convention for flags contained
in  a  status  word.  This  makes it much easier to
write programs (and read other's), because the name
of each  flag  symbolizes the function of the flag.
Below is a graphic representation  of  the Terminal
Status  Word,  with  the  corresponding flag  names
shown:
;ED - SEE MAC ASSEMBLER FILE:JOBTRM
;                        and BITS
;     in SuperDave's Doodles Disk
;(placement of the pics is documented below)
;
; PLACE THE STATUS WORD PICTURE HERE
;
hlt bold
_AND, OR, and COM_
hlt italic
 When you  want  to  flip a bit ON or OFF inside a
status word, you need to adjust only the bit(s) you
want to mess with and leave the other bit(s) alone.
The way we do this in computerland  is  via AND and
OR.  The  best way to understand AND or OR  is  via
graphics (see  below).  Basically,  when  you AND a
number  to  an  existing value, the number you  _AND_
_with_ dictates which  bits will be COPIED. Bits that
are NOT copied are set to zero. Confusing, so let's
look at some pictures:
; AND picture here
 Unlike AND, OR will SET bits - the  number you OR
with  an  existing value will SET the bits you OR -
every bit not ORed will be left "as is". If the bit
was already set, OR has no effect on the bit (since
it is already set!):
;OR picture here
 Finally,  since  we are going to use COM  in  the
program  example  for this month, let's take a look
at it. What COM does is flip a value "180 degrees",
i.e., 1's turn into 0's, and 0's turn into 1's (COM
stands for COMplement):
;COM picture here
hlt bold
_On to the Example_
hlt italic
 Now that _most_ of the  theory  has  been  covered,
let's  look  at  a  program  that employs the above
operations.   The   program   is    called   TRMTST
(Terminal  Test).  TRMTST  will  demonstrate how to
"turn  off"  keyboard  echoing  when  you  need  to
acquire a "password"  or  secret  data.  Before  we
examine   TRMTST  line-by-line,  one   more   note:
TRMTST also  contains  a  _subroutine_. I am assuming
that  most  of  the  readers  are   familiar   with
subroutines  (like  from   your  BASIC  programming
experiences), so I am not going to go into  a heavy
theory discussion on subroutines.
; insert TRMTST.T in 300,7 (or 300,5 if I remembered to move it)
hlt bold
_Line-by-Line, Byte-by-Byte_
 Let's first examine the two MACROs at  the top of
the source file.

_DEFINE NOECHO_
 This MACRO is going to set a flag in the Terminal
Status Word. For background, the second flag inside
the Terminal Status Word is the ECho Suppress flag.
If  this  flag  is set, then your terminal will not
echo characters back  to the screen upon typing. If
the flag is clear, then every keystroke you type is
displayed (or echoed) on your terminal.

_JOBIDX A6_
 Get the pointer of the JCB  for  the  JOB running
the program and place this pointer into A6.

_MOV JOBTRM(A6),A1_
 Add the offset JOBTRM to the pointer contained in
A6,  and  then  MOVe  the  longword  pointed  to by
this result into the address register A1. This move
will place  in  A1  a pointer to the JOB's Terminal
Status Word. In other  words,  A1 now points to the
Terminal  Status  Word  for  the  JOB  running  the
program.

_ORW #T$ECS,@A1_
 OR  the  Word  value  of #T$ECS  with  the  value
pointed  to  by A1. The result  is  stored  in  the
memory  location that  A1  points  to.  Notice  the
naming  of  the  flag:  T$ECS.  This should somehow
remind you of '_T_erminal - _EC_ho _S_uppress'. The value
of  #T$ECS  is  the #2 (remember, the second  bit).
This ORW will set bit 2 in the Terminal Status Word
and leave every other  bit  untouched (or "as is").
This  has  the effect of suppressing  all  keyboard
echoing.  If  you  are  confused,  draw  a  picture
similar to the examples presented above  and notice
how the second bit will be set from the ORW.

_DEFINE ECHO_
 This  MACRO  will  clear  a  bit  in the Terminal
Status  Word, the T$ECS flag.

_MOVW #T$ECS,D4_
 MOVe  the  Word  value  of  #T$ECS  to  the  data
register  D4.  The value #T$ECS is a #2 (it is  the
2nd bit in the status  word, which is equivalent to
#2).

_COMW D4_
 COMplement  the Word contained  in  register  D4.
Remember, complement converts 1's to 0's and 0's to
1's.  So before this  instruction,  D4  contains  a
binary  value  of 0000000000000010, and afterwords,
D4 contains 1111111111111101.

_ANDW D4,@A1_
hlt italic
 Finally, AND the  value pointed to by A1 with the
value contained in D4. Notice that every bit in the
word  pointed  to  by A1 (the Terminal Status Word)
will be left alone _except_ the 2nd  bit  - the T$ECS
flag. This bit will _not_be copied, it will be set to
zero  or  "cleared". This has the effect of turning
echo back on.
hlt bold
 Now let's take a look at some of the instructions
contained within the main body of the program.

_TYPECR_
_TYPECR <First a demo... >_
_TYPECR <Enter in a line.. >_
_KBD_
hlt key
blank |
 These  three  lines don't need much explaination.
The  first  three lines display the function of the
program, and the KBD line waits for user input. KBD
waits for a _|RETURN|_  before continuing with the rest
of the program. Register A2 will be pointing to the
first  character  of  the  line  entered.  We  have
learned that this location is down in system memory
- AMOSL.INI  created  this  location via the TRMDEF
statement (buffer portion).
hlt bold
_CTRLC BYEBYE_
hlt key
blank |
 If by chance  a  user  doesn't  want  to  see the
workings  of  this  fantastic  program  and  hits a
_|cC|_,the program would then jump to the instruction
line labeled by BYEBYE.

hlt bold
_TYPECR_
_TYPECR  <Here is.. >_
_CALL TYPLIN_
 Two more lines of general screen output, and then
a subroutine call. The subroutine TYPLIN (for  Type
Line)  will be executed, and upon completion of the
subroutine,  the program will continue execution on
the line below  the  CALL  instruction line. TYPLIN
simply types out a line pointed to by A2 - see AAA,
Feb '86 for details if you are  fuzzy  about  input
via KBD.

_TYPECR_
_TYPECR <Now a demo... >_
_TYPECR <Enter in a line... >_
 Similar  to  the  above three lines at the top of
the main program.

_NOECHO_
 This is the MACRO call  to  NOECHO.  This has the
effect of generating the code contained  within the
NOECHO MACRO. Notice that this is the first  time a
MACRO with no arguments has been used - yes, it  is
legal. The other effect (already discussed) is that
the ECHO will be turned off.

_KBD_
_CTRLC BYEBYE_
hlt key
blank |
 Similar  to  the  above KBD and CTRLC instruction
lines above. Notice that  even  though  the echo is
suppressed  at  this time, KBD acts "normally"  and
expects a _|RETURN|_  when  the input line is complete.
Special note of the CTRLC  BYEBYE instruction line.
If  you  look ahead in the source  file,  you  will
discover that  if  a _|cC|_ is hit at this time in the
program, TRMTST never "resets"  the Terminal Status
Word  back to "normal". This is because  each  time
you exit a program, AMOS will do this for you!
hlt bold
_ECHO_
_TYPECR_
_TYPECR <Here is what you typed:>_
_CALL TYPLIN_
 Inform  the  user that the computer still  "sees"
the data even though  the  user of the program does
not.  Also  reset the terminal status word with the
MACRO ECHO. Finally,  type  out the line of entered
text with the TYPLIN subroutine.

_EOLN:  TYPECR_
_BYEBYE:EXIT_
 When  the  entire  suppressed input line is typed
out except for the CRLF,  simply type out the CRLF,
and EXIT the program.

_Wrapping Up_
hlt key
blank |
 One item to note: AMOS will normally "upper case"
all input via the KBD line. If  you haven't noticed
this, try TRMTST with lower case  input  - you will
see  your input echoed back to the screen in  upper
case letters!  There  is  a  flag  in  the Terminal
Status  Word  that informs AMOS to pass lower  case
letters. See the  diagram  of  the  Terminal Status
Word above for details. You should be  able  to set
this  flag  after  reading  and  understanding this
months session.
 Well,  that does it for this month.  Next  month,
more of the  same,  but we will learn how to "clear
out" _|cC|_ from within  a  program and not exit back
to AMOS, plus (if possible),  learn how to generate
some ASCII constants from within  the  program.  If
you  would  like  to  see  a particular function or
trick discussed, send Email  or  call. See you next
month.