home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 171.lha / travail.asm < prev    next >
Assembly Source File  |  1988-04-28  |  11KB  |  278 lines

  1. ************************************************************************
  2. ************************************************************************
  3. *  travail.asm                                                         *
  4. *                                                                      *
  5. *     An assembly language look-alike replacement for AVAIL,           *
  6. *  the Commodore SW Toolkit utility for showing current memory         *
  7. *  in-use and available.  Reentrant and "pure."                        *
  8. *                                                                      *
  9. *     Dr. Gerald Hull                                                  *
  10. *     CREATIVE FOCUS                                                   *
  11. *     12 White Street                                                  *
  12. *     Binghamton, New York  13901                                      *
  13. *     (607) 648-4082                                                   *
  14. *                                                                      *
  15. ************************************************************************
  16. ************************************************************************
  17.  
  18.  
  19. ************************************************************************
  20. *  Global register usage
  21.  
  22. REGS     reg      d2-d7/a2-a4,a6
  23.  
  24. OUT      equr     a2                   output handle
  25. DOS      equr     a3                   Doslib handle
  26. FP       equr     a5                   local frame pointer
  27. LVP      equr     a6                   library vector pointer
  28. SP       equr     a7                   stack pointer
  29.  
  30.  
  31. ************************************************************************
  32. *  Include files
  33.  
  34.          nolist
  35.          include  'exec/types.i'
  36.          include  'exec/lists.i'
  37.          include  'exec/memory.i'
  38.          include  'exec/execbase.i'
  39.          list
  40.  
  41.  
  42. ************************************************************************
  43. *  Library vector offsets
  44.  
  45.          xref     _LVOOpenLibrary
  46.          xref     _LVOCloseLibrary
  47.          xref     _LVOOutput
  48.          xref     _LVOWrite
  49.          xref     _LVOAvailMem
  50.          xref     _LVOPermit
  51.          xref     _LVOForbid
  52.  
  53.  
  54. ************************************************************************
  55. *  Equates, macros, etc.
  56.  
  57. EB       equ      4                    _AbsEcecBase
  58.                               
  59. MIN_LIB  equ      $1f                  minimum library acceptable
  60. LF       equ      $0a                  line feed
  61. BASE     equ      $0a                  ints to ascii in base 10
  62. PREC     equ      $08                  maximum digits per number
  63.  
  64. LOKE     equ      -62                  local frame memory needed
  65.  
  66. LOKEVAR  macro                         allocates local frame space
  67. \1       equ      LOKI+\2                 (based on a suggestion by
  68. LOKI     set      \1                       Wesley Howe)
  69.          endm
  70.  
  71. LOKI     set      0
  72.          LOKEVAR  CMAX,-4              maximum CHIP memory
  73.          LOKEVAR  FMAX,-4                 "    FAST   "
  74.          LOKEVAR  TAVAIL,-4            total available memory
  75.          LOKEVAR  LARGE,-4             largest block available
  76.  
  77. LOKI     set      LOKE+5
  78.          LOKEVAR  AVAIL,10             ->  end+1 for Avail  numbers
  79.          LOKEVAR  INUSE,10             "     "    "  In-Use    "
  80.          LOKEVAR  MAX,10               "     "    "  Maximum   "
  81.          LOKEVAR  LRGST,10             "     "    "  Largest   "
  82.  
  83.  
  84. ************************************************************************
  85. *  Program starts here
  86.  
  87. START    link     FP,#LOKE             allocate local frame
  88.          clr.l    TAVAIL(FP)           initialize 
  89.          clr.l    LARGE(FP)               variables
  90.          movem.l  REGS,-(SP)           save needed registers
  91.          move.l   EB,LVP               _AbsExecBase
  92.          lea      DOSNAME(pc),a1       prepare registers for
  93.          moveq    #MIN_LIB,d0             OpenLibrary call
  94.          jsr      _LVOOpenLibrary(LVP) do it
  95.          tst.l    d0                   did it work?
  96.          bne.s    CONT                 yes!
  97. BAD      moveq    #20,d0               no!
  98.          movem.l  (SP)+,REGS           restore registers
  99.          rts                           go home in tears
  100.  
  101. CONT     move.l   d0,DOS               save DosLib handle
  102.          movea.l  DOS,LVP                 and
  103.          jsr      _LVOOutput(LVP)      go for Output handle
  104.          move.l   d0,OUT               save it
  105.  
  106.          movea.l  EB,LVP               _AbsExecBase
  107.          jsr      _LVOForbid(LVP)      lock out all other tasks
  108.          movea.l  LVP,a1
  109.          move.l   MemList(a1),d3       get MemList header
  110.          moveq    #0,d4                for summing CHIP blocks
  111.          moveq    #0,d5                 "     "    FAST   "
  112.  
  113. SCAN:    move.l   d3,a1                            get node pointer
  114.          move.l   LN_SUCC(a1),d3                   lookahead
  115.          beq.s    DUN                              found last node
  116.          btst     #MEMB_CHIP,MH_ATTRIBUTES+1(a1)   test for CHIP
  117.          beq.s    FST                              skip to FAST if not
  118.          add.l    MH_UPPER(a1),d5                  calculate size
  119.          sub.l    MH_LOWER(a1),d5                     of CHIP block
  120. FST      btst     #MEMB_FAST,MH_ATTRIBUTES+1(a1)   test for FAST too!
  121.          beq.s    SCAN                             nope
  122.          add.l    MH_UPPER(a1),d4                  calculate size
  123.          sub.l    MH_LOWER(a1),d4                     of FAST block
  124.          bra.s    SCAN                             repeat
  125.  
  126. DUN      move.l   d4,FMAX(FP)          save FAST totals
  127.          move.l   d5,CMAX(FP)            "  CHIP   "
  128.          jsr      _LVOPermit(LVP)
  129.  
  130.          lea      WRDZ(pc),a0          output column
  131.          bsr      WRITES                  headings
  132.  
  133.          moveq    #MEMF_CHIP,d6        load registers
  134.          lea      CHIP(pc),a4             for CHIP values
  135.          bsr.s    DOTYPE               calc & output CHIP values
  136.  
  137.          moveq    #MEMF_FAST,d6        load registers
  138.          move.l   FMAX(FP),d5             for FAST
  139.          lea      FAST(pc),a4             values
  140.          bsr.s    DOTYPE               calc & output FAST values
  141.  
  142.          lea      TOTL(pc),a4          load
  143.          move.l   TAVAIL(FP),d0           registers
  144.          move.l   CMAX(FP),d6
  145.          add.l    FMAX(FP),d6             for total
  146.          move.l   d6,d5
  147.          sub.l    d0,d5                   values
  148.          move.l   LARGE(FP),d7
  149.          bsr.s    DOSTR                output totals
  150.  
  151.          move.l   LVP,a1               get DosLib handle
  152.          movea.l  EB,LVP                  and
  153.          jsr      _LVOCloseLibrary(LVP)   close it up
  154.                   
  155.          movem.l  (SP)+,REGS
  156.          unlk     FP                   release local frame
  157.          rts
  158.  
  159.  
  160. ************************************************************************
  161. *  DOTYPE:  calculates and outputs memory values per type
  162. *
  163. *     in:   d6  = memtype
  164. *           d5  = Maximum
  165. *           a4 -> type string
  166.  
  167. DOTYPE   move.l   EB,LVP               _AbsExecBase
  168.  
  169.          move.l   d6,d1                CHIP or FAST
  170.          ori.l    #MEMF_LARGEST,d1     look
  171.          moveq    #0,d0                   for
  172.          jsr      _LVOAvailMem(LVP)       biggest chunk
  173.          cmp.l    LARGE(FP),d0         biggest so far?
  174.          ble.s    NOTL                    nope
  175.          move.l   d0,LARGE(FP)         yup; stuff it
  176. NOTL     move.l   d0,d7                save for DOSTR
  177.  
  178.          move.l   d6,d1
  179.          moveq    #0,d0                memtype again
  180.          jsr      _LVOAvailMem(LVP)    available aggregate
  181.          add.l    d0,TAVAIL(FP)        add to total
  182.  
  183.          move.l   d5,d6                Maximum in d6
  184.          sub.l    d0,d5                In-Use in d5
  185. *                                      fall into DOSTR
  186.  
  187.  
  188. ************************************************************************
  189. *  DOSTR:   outputs type string and values
  190. *
  191. *     in:   a4 -> type string
  192. *           d0  = Available
  193. *           d5  = In-Use
  194. *           d6  = Maximum
  195. *           d7  = Largest
  196.  
  197. DOSTR    move.b   #' ',d1              fill string
  198.          lea      LOKE(FP),a1             buffer
  199.          moveq    #WRDZLEN-2,d2           with
  200. REP      move.b   d1,(a1)+                blanks
  201.          dbra     d2,REP                  and
  202.          move.b   #LF,(a1)                linefeed
  203.  
  204.          lea      LOKE(FP),a1          beginning of str buf
  205.          moveq    #TYPELEN-1,d1        insert
  206. TXT      move.b   (a4)+,(a1)+             type
  207.          dbra     d1,TXT                  string
  208.  
  209.          lea      AVAIL(FP),a0         insert Available
  210.          bsr.s    MAKEDEC                 number
  211.  
  212.          move.l   d5,d0                insert
  213.          lea      INUSE(FP),a0            In-Use
  214.          bsr.s    MAKEDEC                 number
  215.  
  216.          move.l   d6,d0                insert
  217.          lea      MAX(FP),a0              Maximum
  218.          bsr.s    MAKEDEC                 number
  219.  
  220.          move.l   d7,d0                insert
  221.          lea      LRGST(FP),a0            Largest
  222.          bsr.s    MAKEDEC                 number
  223.  
  224.  
  225.          lea      LOKE(FP),a0          prepare
  226. WRITES   move.l   OUT,d1                  registers
  227.          move.l   a0,d2                   for
  228.          moveq    #WRDZLEN,d3             Write
  229.          movea.l  DOS,LVP                 call
  230.          jsr      _LVOWrite(LVP)       do it
  231.          rts
  232.  
  233.  
  234. ************************************************************************
  235. *  MAKEDEC: converts an integer to its decimal representation
  236. *
  237. *     in:   d0  = value to output
  238. *           a0 -> end+1 of string dest
  239.  
  240. MAKEDEC  moveq    #PREC-1,d2           set max digits
  241. LDIV     moveq    #BASE,d1             base for digits
  242.          move.w   d0,d4                save Z
  243.          clr.w    d0                   d1 from YZ to Y0
  244.          swap     d0                   d1 from Y0 to 0Y
  245.          divu     d1,d0                d0 = 0Y / X = R1Q1
  246.          move.w   d0,d3                save Q1
  247.          move.w   d4,d0                d0 from R1Q1 to R1Z
  248.          divu     d1,d0                d0 = R1Z / X = R0Q0
  249.  
  250. SMALL    swap     d0                   d0 = QR or Q0R0
  251.          move.l   d0,d1                d1 = QR or Q0R0
  252.          move.w   d3,d0                d0 = Q0 or Q0Q1
  253.          swap     d0                   d0 = 0Q or Q1Q0
  254.  
  255.          add.b    #'0',d1              make d1.b ascii
  256.          move.b   d1,-(a0)             put it out
  257.          tst.l    d0                   no more digits?
  258.          dbeq     d2,LDIV              or PREC reached?
  259.          rts
  260.  
  261.  
  262. ************************************************************************
  263. *  Data constants
  264.  
  265. WRDZ     dc.b     'Type  Available    In-Use'      column
  266.          dc.b     '   Maximum   Largest',LF           headings
  267. WRDZLEN  equ      *-WRDZ
  268.  
  269. CHIP     dc.b     'chip '                          strings
  270. FAST     dc.b     'fast '                             for
  271. TOTL     dc.b     'total'                             types
  272. TYPELEN  equ      *-TOTL
  273.  
  274. DOSNAME  dc.b     'dos.library',0                  DosLibrary card
  275.  
  276.          END
  277.  
  278.