;       DJOB3.M68 - Dynamic memory display PART 3
;
;       Copyright [c] STUYVESANT SofSystems


       SEARCH  SYS
       SEARCH  SYSSYM
       SEARCH  TRM

       RADIX 8.


       AUTOEXTERN


       M%SIZE=0
       M%STAT=4.
       M%NAME=6.
       M%ADDR=12.


       MN%COL=42.                                      ; MODULE NAME LINE COLUMN
       MZ%COL=54.                                      ;    "   SIZE  "     "
       MS%COL=62.                                      ;    "   STAT  "     "
       MA%COL=67.                                      ;    "   ADDR  "     "



D$GRPH::TST     J%BAS(A5)                               ; CHK FOR NO MEM
       JEQ     NO$MEM                                  ; jmp if none

DG$REP: MOV     J%BAS(A5),A1                            ; get saved base
       CLR     D0                                      ; pre-clear index to module list in DSECT
       CLRW    D2                                      ; pre-clear index to which line to print on
DG$LOP: TST     @A1                                     ; test size word of partition
       JEQ     DG$FIN                                  ; jmp if size word is 0 therefore marked end of mod list

       CMM     M%SIZE(A1),M%SIZE(A5)[~D0]              ; cmp actual mod size with stored module size
       BEQ     100$                                    ; br if same
                                                       ; not same so code below to save and display
       MOV     M%SIZE(A1),M%SIZE(A5)[~D0]              ; save for later cmp
       MOVW    #24.,D1                                 ; pre-set to last line
       SUBW    D2,D1                                   ; less the number displayed
       LSLW    D1,#8.                                  ; shift to high byte
       MOVB    #MZ%COL,D1                              ; set low byte to correct column
       TCRT                                            ; position
       MOV     M%SIZE(A5)[~D0],D1                      ; load in saved size
       OCVT    7.,OT$TRM!OT$ZER                        ; display it

100$:   CMMW    M%STAT(A1),M%STAT(A5)[~D0]              ; check status for same
       BEQ     200$                                    ; br if same
                                                       ; not same so code below to save and display
       MOVW    M%STAT(A1),M%STAT(A5)[~D0]              ; save for later cmp
       MOVW    #24.,D1                                 ; pre-set last line
       SUBW    D2,D1                                   ; less the number so far displayed
       LSLW    D1,#8.                                  ; shift to high byte
       MOVB    #MS%COL,D1                              ; slip in the column below in low byte
       TCRT                                            ; position
       CLR     D1                                      ; pre-clear d1
       MOVW    M%STAT(A5)[~D0],D1                      ; movw saved status
       OCVT    3.,OT$TRM!OT$ZER                        ; display it

200$:   CMM     M%NAME(A1),M%NAME(A5)[~D0]              ; check for names to be the same
       BNE     250$                                    ; br if they ain't
                                                       ; they were so check the extension
       CMMW    <M%NAME+4>(A1),<M%NAME+4>(A5)[~D0]      ; check
       BEQ     300$                                    ; br if everything matched don't re-display
                                                       ; something wase different so display new
250$:   MOV     M%NAME(A1),M%NAME(A5)[~D0]              ; save it
       MOVW    <M%NAME+4>(A1),<M%NAME+4>(A5)[~D0]      ; ext. too
       MOVW    #24.,D1                                 ; pre-set last line
       SUBW    D2,D1                                   ; less the number so far displayed
       LSLW    D1,#8.                                  ; shift up to high byte
       MOVB    #MN%COL,D1                              ; slip in the column
       TCRT                                            ; do it
       TYPE    <         >                             ; erase old incase size diferent
       TCRT                                            ; re-do it
       PRNAM   M%NAME(A5)[~D0]                         ; print saved name

300$:   CMP     A1,M%ADDR(A5)[~D0]                      ; check addr for match
       BEQ     DG$NXT                                  ; br if they was
                                                       ; they weren't so code below to save and display
       MOV     A1,M%ADDR(A5)[~D0]                      ; save it for later cmp
       MOVW    #24.,D1                                 ; pre-set last line
       SUBW    D2,D1                                   ; less the number so far displayed
       LSLW    D1,#8.                                  ; shift up to high byte
       MOVB    #MA%COL,D1                              ; slip in the column
       TCRT                                            ; position
       MOV     M%ADDR(A5)[~D0],D1                      ; set in the saved addr
       OCVT    8.,OT$TRM!OT$ZER                        ; display it

DG$NXT:                                                 ; THE NEXT CODE VERIFIES THE NEW ADDRESS IN A1 AS VALID
       MOV     A1,D3                                   ; SAVE THE OLD
       ADD     M%SIZE(A5)[~D0],D3                      ; ADD THE NEW SIZE
       MOV     MEMEND,D7                               ; GET ADDRESS FOR USER MEMORY END
       CMP     D7,D3                                   ; CMP THE TWO
       BGE     100$                                    ; IF D7 IS >= A1 IS NOT TO LARGE -->100$
       BR      150$                                    ; IT WAS TO LARGE SO TRY AGAIN

100$:   BTST    #0,D3                                   ; IS IT AN ODD ADDRESS ?
       BEQ     200$                                    ; IF =0 ITS VALID -->200$

150$:   CALL    NO$MEM                                  ; CALL RTN TO CLEAR SCREEN
       MOVW    #16.,M%LINE(A5)                         ; SET TO WORST SO WE ERASE EVERYTHING
       JMP     DG$REP                                  ; BR TO RTN TO RESTART EVERYTHING

200$:   MOV     D3,A1                                   ; ITS BEEN VALIDATED
       INCW    D2                                      ; inc current line cntr
       CMPB    D2,#17.                                 ; cmp to max allowed for display
       BEQ     DG$EXT                                  ; br to DG$EXT if maxed out
       ADDW    #M%DEF,D0                               ; point to next entry id DSECT list
300$:   JMP     DG$LOP                                  ; go for next

DG$FIN: CMPW    D2,M%LINE(A5)                           ; cmp current lines displayed to old
       BGE     DG$EXT                                  ; br to DG$EXT (exit) if >= overlayed all old stuff
       CALL    ERASE                                   ; must be < so br to rtn to erase old
DG$EXT: MOVW    D2,M%LINE(A5)                           ; save current lines displayed for later use
       RTN                                             ; go back for more

NO$MEM: CLR     D0                                      ; clear D0
       CLR     D2                                      ; clear D1

       ; this code will erase the old portion of the screen

ERASE:  MOVW    D2,D3                                   ; get a copy of D2
       TCKI                                            ; check for input
       CTRLC   FINISH                                  ; br out of rtn for ^C

50$:    INCW    D3                                      ; point past last displayed
       CMPW    D3,M%LINE(A5)                           ; cmp with old last line displayed
       BGT     100$                                    ; if > we've erase the last
       MOVW    #25.,D1                                 ; pre-set to last line(+1)
       SUBW    D3,D1                                   ; sub out current line
       LSLW    D1,#8.                                  ; shift up to high byte
       MOVB    #MN%COL,D1                              ; slip in the column
       TCRT                                            ; do it
       TYPE    <                                      >; use a blank line to erase
       CLR     M%SIZE(A5)[~D0]                         ; clear the old data saved
       CLRW    M%STAT(A5)[~D0]                         ; same
       CLR     M%NAME(A5)[~D0]                         ; same
       CLRW    <M%NAME+4>(A5)[~D0]                     ; same
       CLR     M%ADDR(A5)[~D0]                         ; same
       ADDW    #M%DEF,D0                               ; point to next block
       BR      50$                                     ; go around for more
100$:   RTN                                             ; rtn we finished
       END                                             ; all done