;             >>>>> AAA - December '86
laser
topmargin 1"
margin 1"
bottommargin 1"
hlt bold
; pick one of the fonts, and comment out or erase the one you don't want
;font helvetica
font times
point 10
leading 1
; The following rulers work for Times-Roman and Helvetica - 10 point type
; Three columns per page (2 1/16")
...............................<

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

AAA
BY SDH

           MORE FUN WITH STATUS WORDS

 Hey  gang! This month let's fool around with some
more status words! Remember,  status  words dictate
the  way  a  JOB handles certain  operations,  like
output in HEX, keyboard  entries  (the  KBD  call),
hlt key
bl |
keyboard  echoing,  and enabling/disabling _|cC|_. We
will be flipping some  bits  on and off inside some
status  words  to  see  how  this  can  aid  us  in
programming.  In particular, we will  look  at  the
T.STS, JOBSTS, and JOBTYP status words in detail.
hlt bold
_Format of the JOBSTS and JOBTYP Status Words_
 Below are some graphical  representations  of the
above two status  words  (T.STS  was  covered  last
month).   Each   flag   is   described  within  the
illustration. We will be exploring  some  of  these
flags  in  the  program  listing below. The numbers
shown   in   the  illustrations   are   the   octal
equivalents of the flag names.
;insert JOBSTS AND JOBTYP PICS HERE from SD Doodles

_Creating MACROs to Flip Bits_
 Let's  create some MACROs that we can place in  a
UNIVERSAL  file  and  then SEARCH these MACROs upon
assembly.  This  will make  our  programming  tasks
easier  for  future  programs using the features of
these  MACROs.  In  particular,  let's  create  the
following:

1) CLRCTC - clear  out  a ^C within the program
2) NOCTC  - do not allow ^C's to be "seen"
3) SETCTC - do allow ^C's to be "seen"
4) HEX    - allow  I/O  to  be in HEX
5) OCTAL  - allow I/O to be in OCTAL
6) ONEKEY - allow only 1 input key, no CR needed
7) MNYKEY - allow many key input, CR needed

plus,  let's  include last month's MACROs, ECHO and
NOECHO (even though  we don't use them, it would be
nice to have them all  in  one .UNV file). After we
have  created these tools, a  sample  program  will
illustrate  their  use  via a program called SETUP.
This  program will act similar  to  SET  from  AMOS
command mode, but it will be in a menu type format.
If you didn't read last month's submission, you may
become  lost  -  I  will be using a few tricks from
last  month  without  going  into  the  discussion.
Ready? Here are all the MARCOs for this month, plus
a few from last  month, all bundled into a UNIVERAL
file called STSWRD (STatuS WoRDs):
;ED - I don't know how you want this in here
; this file is called STSWRD.M68 in 300,7
point 7
UNIVERSAL

;MACROS FOR TERMINAL STATUS WORD
;--------------------------------------------------------------------------
DEFINE  NOECHO                  ;makes keyboard entries "invisible"
       PUSH    A6              ;"black box"
       JOBIDX  A6              ;give A6 the JOBIDX
       MOV     JOBTRM(A6),A6   ;A6 points to the Terminal Status Word
       ORW     #T$ECS,@A6      ;second bit now contains a "1" (no echo)
       POP     A6              ;restore original
ENDM

DEFINE  ECHO                    ;turns ECHO back on for keyboard input
       PUSH    A6              ;"black box"
       PUSH    D4
       JOBIDX  A6              ;get the JOBIDX
       MOV     JOBTRM(A6),A6   ;A6 points to the Terminal Status Word
       MOVW    #T$ECS,D4       ;D4 contains 00000010
       COMW    D4              ;D4 contains 11111101
       ANDW    D4,@A6          ;second bit now contains a "0"
       POP     D4              ;restore originals
       POP     A6
ENDM

DEFINE  ONEKEY                  ;makes KBD only accept one key (D1 holds it)
       PUSH    A6              ;"black box"
       JOBIDX  A6              ;get JCB pointer
       MOV     JOBTRM(A6),A6   ;A6 holds pointer to TSW
       ORW     #T$IMI,@A6      ;set "one key" for KBD (D1 will hold char.)
       POP     A6              ;restore original
ENDM

DEFINE  MNYKEY                  ;multiple keystrokes on KBD call (A2 pointer)
       PUSH    A6              ;"black box"
       PUSH    D4
       MOV     JOBTRM(A6),A6   ;A6 holds pointer to TSW
       MOVW    #T$IMI,D4       ;we will complement this value
       COMW    D4              ;to set up the AND so as to
       ANDW    D4,@A6          ;turn off the T$IMI bit (back to normal mode)
       POP     D4              ;restore originals
       POP     A6
ENDM

;MACROS FOR JOB STATUS WORD
;--------------------------

DEFINE  CLRCTC                  ;clear out a ^C when user hits one (fool them)
       PUSH    A6              ;"black box"
       PUSH    D7
       TYPECR  ^C              ;simulates user "exiting" by displaying a ^C
       JOBIDX  A6              ;A6 now contains pointer to JOBIDX (JOBSTS)
       MOVW    #J.CCC,D7       ;Reg. D7 contains ^C abort flag
       COMW    D7              ;logical one's complement (0->1 and 1->0)
       ANDW    D7,@A6          ;flag is now turned OFF
       POP     D7              ;restore originalS
       POP     A6
ENDM

;MACROS FOR JOB TYPE STATUS WORD
;--------------------------------

DEFINE  NOCTC                   ;"set noctrlc"
       PUSH    A6              ;"black box"
       PUSH    D7
       JOBIDX  A6              ;point to JOBIDX (JOBSTS)
       LEA     A6,JOBTYP(A6)   ;A6 points to JOBTYP word
       MOVW    #J.CCA,D7       ;Reg. D7 contains ^C enable flag
       COMW    D7              ;flip the bits
       ANDW    D7,@A6          ;^C disabled
       POP     D7              ;restore originals
       POP     A6
ENDM

DEFINE  CTC                     ;"set ctrlc"
       PUSH    A6              ;"black box"
       JOBIDX  A6              ;point to JOBIDX (JOBSTS)
       LEA     A6,JOBTYP(A6)   ;A6 points to JOBTYP word
       ORW     #J.CCA,@A6      ;^C set
       POP     A6              ;restore original
ENDM

DEFINE  HEX                     ;set binary output to HEX
       PUSH    A6              ;"black box"
       JOBIDX  A6              ;point to JOBIDX (JOBSTS)
       LEA     A6,JOBTYP(A6)   ;A6 points to JOBTYP word
       ORW     #J.HEX,@A6      ;HEX set
       POP     A6              ;restore original
ENDM

DEFINE  OCTAL                   ;set OCTAL
       PUSH    A6              ;"black box"
       PUSH    D7
       JOBIDX  A6              ;point to JOBIDX (JOBSTS)
       LEA     A6,JOBTYP(A6)   ;A6 points to JOBTYP word
       MOVW    #J.HEX,D7       ;get the flag number
       COMW    D7              ;flip the bits
       ANDW    D7,@A6          ;OCTAL set
       POP     D7              ;restore original
       POP     A6
ENDM
point 10
One  of the newer features of  our  MACROs  it  the
"black  box" feature. The black box  feature  makes
each MACRO  behave  as  though  it is an invisible,
magical box: you can call this MACRO  at  any  time
hlt italic
and _never_ worry  about  "destroying"  the  original
contents of any register!  The way we do this is by
PUSHing  and POPing _any_ register  used  within  the
MACRO (see  MARCH '86 AAA for details on PUSH, POP,
and the Stack).
 As for  the  details  on  these  MACROs, they use
the  exact  same  theory  as last month's  session:

1) have an address  register  point  to  the status
word  located in system memory needing modification
(A6 in above MACROs).

2) get the flag needing  to be turned ON or OFF (an
actual value - note the "#" symbol).

3) if  the  flag needs to be ON, ORW this flag with
the word pointed to by the address register.

4) if the flag  needs to be OFF, move the flag to a
data register, COMplement the Word (COMW), and then
ANDW this value with  the  word  pointed  to by the
address   register.   See  last  month's  AAA   for
AND/OR/COM theory.
hlt bold
_SETUP_
 Now   let's   put  these  MACROs  to  work  in  a
demonstration program. All this program does is SET
certain bits (flags) ON or OFF  within status words
located  in  system  memory. You should  type  this
program in (you learn  as  you  type), and then run
SETUP. After you execute this program,  type SET at
the  dot  to  see  the  changes. This program  also
hlt key
bl |
"captures" _|cC|_ if hit,  and  "fools"  the  user  -
you'll  have  to  run the program to see the way it
fools you!
;ED this file is called SETUP.M68 in [300,7]
point 7
;************************************
; SETUP - SetUp some JOB attributes
;
; by Dave Heyliger - AMUS Staff
;    for AAA December '86
;************************************

       SEARCH  SYS                     ;search AM universals
       SEARCH  SYSSYM
       SEARCH  TRM

       SEARCH  STSWRD                  ;and our own universal

;Define a PRINT TAB(#,#) MACRO - we've seen this before...
DEFINE  PRTTAB  AA,BB                   ;PRINT TAB(#,#)
       MOVB    #'AA,D1                 ;get first #
       LSLW    D1,#10                  ;shift left 8. bits
       MOVB    #'BB,D1                 ;get second #
       TCRT                            ;PRINT TAB(#,#)
ENDM

;MAIN LOOP - rest of program contains Subroutines
;------------------------------------------------
TOP:    CALL    MENU                    ;type out the menu, wait for input
       CALL    ANALIZ                  ;analyse user input
       CRLF                            ;simulate a return
       EXIT                            ;then quit

;MENU Subroutine - types out user interface
;------------------------------------------
MENU:   PRTTAB  -1,0                    ;clear the screen
       PRTTAB  4,20.                   ;tab to row 4, column 20 (20 decimal!)
       TYPE    <SETUP - Set up your terminal without using SET!>

       PRTTAB  6,12.                   ;tab to row 6, column 12 (decimal)
       TYPE    <Choose: 1) set hex  2) set octal  3) no ^C  4) ^C  5) Exit>

       PRTTAB  8.,30.                  ;tab to row 8, column 30 (decimal)
       TYPE    <User's Choice: >       ;prompt for responce

       ONEKEY                          ;expect only 1 keystroke, no return
       KBD                             ;get the key into D1
       RTN                             ;return from subroutine

;ANALYSE Subroutine - gets user input, acts accordingly
;------------------------------------------------------
ANALIZ: CTRLC   FOOLEM                  ;fool'em on control C

       SUBB    #60,D1                  ;adjust ASCII to "decimal 1...5"

       CMPB    D1,#1                   ;set hex?
       BNE     MO                      ;nope, maybe OCTAL
       HEX                             ;yup, set hex
       RTN                             ;and return

MO:     CMPB    D1,#2                   ;set octal?
       BNE     MNC                     ;nope, maybe NO ^C
       OCTAL                           ;yup, set octal
       RTN                             ;and return

MNC:    CMPB    D1,#3                   ;set NO ^C?
       BNE     MSC                     ;nope, maybe SET ^C
       NOCTC                           ;no ^C
       RTN                             ;and return

MSC:    CMPB    D1,#4                   ;set ^C?
       BNE     MQ                      ;nope, maybe Quit
       CTC                             ;set ^C
       RTN                             ;and return

MQ:     CMPB    D1,#5                   ;quit?
       BNE     ERROR                   ;nope, error!
       RTN                             ;return (program then quits)

ERROR:  MOV     #7,D1                   ;ASCII for a bell
       TTY                             ;BEEP!
       CRLF                            ;blank line
       TYPECR  <?not a valid number>   ;error message
       RTN                             ;and return (only to quit)

;FOOL'EM routine - makes user think they are at the dot, but they aren't
;-----------------------------------------------------------------------
FOOLEM: CLRCTC                          ;clear out the ^C
       MLTKEY                          ;just wait for input.....
       TYPE    <.>                     ;give em a "."
       KBD                             ;like so (expects a [CR])
       TYPECR  <HA-HA   - fooled you! ^C will not set you free!>
       ONEKEY                          ;adjust keyboard input
       TYPE    <Any key to continue.....>      ;prompt
       KBD                             ;get key (don't care what it is
       CLRCTC                          ;clear out ^C
       JMP     TOP                     ;upon keystroke, re-run program

END
point 10
hlt bold
_A Quick Look_
 Let's  just  look at a few new features contained
within SETUP. First, the main program contains only
three  lines: a menu  typing/input  subroutine,  an
analyse  input subroutine, and then an exit clause.
You  should   be   moving  into  this  "structured"
programming style if  you  haven't done so already.
This  style  makes  it  a  snap  for  updating  and
debugging. After reading the main loop, one can see
exactly how the program is layed out.
 Within the MENU subroutine, most of the lines are
quite familiar. PRTTAB is actually  replaced by the
instruction lines contained within the MACRO PRTTAB
at  assembly  time.  Notice  the  use of the "." to
hlt italic
represent  _decimal_  values - easier  to  read   and
calculate. ONEKEY is a  MACRO  that  makes  the KBD
call  scan  for  input until _just one key_ is hit  -
the ASCII value of  this keystroke is placed in D1,
_not_  in  the  input buffer  A2  usually  points  to
after a KBD call!
 Three  unique  constructs   make  up  the  ANALIZ
hlt key
subroutine.  First,  if  the user  hits  _|cC|_,  the
CTRLC FOOLEM line is executed. This line translates
into  a  JMP  to  FOOLEM  upon  a  _|cC|_.  If a _|cC|_
is not hit, the next line will take the ASCII value
of   the  input  and  convert  this  value  into  a
"decimal"  value  (an ASCII "1" is a octal "61", so
subtracting an octal 60 from 61  leaves  you with a
value of 1 octal = 1 decimal. Follow  that  one??).
Finally, the remainder  of  the  ANALIZ  subroutine
simulates a CASE statement in Pascal, or an ON/GOTO
in BASIC. You should be able to follow the logic.
 The  FOOLEM  routine  will "clear out"  a  _|cC|_as
the first instruction of  the  routine.  If this is
not done, havoc occurs - remember, the JOB is in an
"abort-wait"  state.  Clearing out this state  will
return the JOB to normal  processing.  Not clearing
out  this state will make the JOB continually  look
for an escape (if you want to see this, comment out
this line and re-assemble the program and watch the
fireworks!).  The  remainder  of the subroutine  is
self explainatory.
hlt bold
_A Wrap_
 Well, that does it for this month. There has been
over 10 submissions to AAA over the last year,  and
AMUS has made these submissions available in a nice
packet for only $10.00. If you would like to obtain
this  packet,  send  a  check  for the amount above
to:
center AAA
center c/o AMUS
center 735 Walnut Street
center Boulder CO 80302
Best tutorial on AMOS/Assembler you can  get (!?!).
See you next month!