;************************************************
;*      TSLBOJ.M68    (JOBLST spelled backwards)
;*
;*      Scans the system and prints every defined
;*      JOB to the screen "backwards" from last
;*      JOB to the first using the STACK.
;*
;*      Usage: TSLBOJ
;*
;*      by Dave Heyliger - AMUS Staff
;************************************************

       OBJNAM  TSLBOJ.LIT              ;Define the final product

       SEARCH SYS                      ;Grab all MACRO definitions
       SEARCH SYSSYM
       SEARCH TRM

;--- The following will define a 'version number' that will be displayed
;    when you do a DIR/V JOBLST.LIT. These numbers are 'made-up' by the
;    programmer, and can be changed when the code is changed.
;
       VMAJOR=1.                       ;Major version number of the program
       VMINOR=0.                       ;Minor version number of the program
       VEDIT=100.                      ;the edit number of the program

;--- This small portion of the code reserves a little memory space in YOUR
;    memory partition for a variable I called "BUFFER".
;
       .OFINI                          ;OFfset INItialization:
       .OFDEF  BUFFER,7.               ;OFfset DEFinition - "BUFFER"
       .OFSIZ  IMPSIZ                  ;IMPSIZ is the final size of bytes (7)

;--- Start the program with a header, and also get the size of our memory
;    buffer - the 7 bytes where byte "0" is the 1st byte of 7 in "BUFFER".
;
       PHDR    -1,0,PH$REE!PH$REU      ;Program is Re-entrant & Re-useable
       GETIMP  IMPSIZ,A5               ;Reg. A5 now ^'s to byte "0" of BUFFER

;--- Now get the ADDRESS of the start of the JOB table and plop it into A0
;
GETTBL: MOV     JOBTBL,A0               ;Get base of JOB TABLE into A0

;--- Mark the Top of Stack (TOS) with a "-1"
;
       MOV     #-1.,A1                 ;a "-1" will be a marker for TOS
       PUSH    A1                      ;PUSH our marker onto the STACK

;--- Now for each JCB address, PUSH this address onto the STACK
;
STACK:  MOV     (A0)+,A4                ;and let A4 point to each JBC
       MOV     A4,D0                   ;this will set the flags 2 B checked
       BMI     OUTPUT                  ;end of the JOB TABLE on a "-1"
       BEQ     STACK                   ;get the next JCB if zero
       PUSH    A4                      ;else PUSH the JCB address
       JMP     STACK                   ;and do it again for the next JCB

;--- The following loop will 1) POP each JCB address into register A4
;                            2) Check to see if we are at TOS
;                            3) If NOT, print the JOBNAME to the screen
;                            4)    and get the next JCB address from stack
;
OUTPUT: POP     A4                      ;get the next value off the STACK
       MOV     A4,D0                   ;sets the flags
       BMI     EXIT                    ;if it is a "-1" then time to quit
       LEA     A1,JOBNAM(A4)           ;else ^ A1 to the start of a JOB name
       LEA     A2,BUFFER(A5)           ;and ^ A2 to byte "0" of "BUFFER"
       UNPACK                          ;Find the ASCII letters in JOBNAM
       UNPACK                          ;  ...for up to 6 digits
       CLRB    @A2                     ;Place a "null" after the characters
       LEA     A2,BUFFER(A5)           ;Repoint A2 to byte "0" of "BUFFER"
       TTYL    @A2                     ;Print out all chars until a null
       CRLF                            ;Carriage return & line feed
       JMP     OUTPUT                  ;Time for the next name in the table

;--- Finally, let the user know you are through
;
EXIT:   TYPE <End of "backwards" JOB listing for this system>
       CRLF
       EXIT                            ;return to AMOS

       END