home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 3 / CD_Magazyn_EXEC_nr_3.iso / Internet / Strony_WWW / Opus4.x / DOpus414JRsrc.lha / DirectoryOpus4 / Program / getusage.asm < prev    next >
Assembly Source File  |  2000-03-04  |  3KB  |  158 lines

  1. ; Directory Opus 4
  2. ; Original GPL release version 4.12
  3. ; Copyright 1993-2000 Jonathan Potter
  4. ; This program is free software; you can redistribute it and/or
  5. ; modify it under the terms of the GNU General Public License
  6. ; as published by the Free Software Foundation; either version 2
  7. ; of the License, or (at your option) any later version.
  8. ; This program is distributed in the hope that it will be useful,
  9. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. ; GNU General Public License for more details.
  12. ; You should have received a copy of the GNU General Public License
  13. ; along with this program; if not, write to the Free Software
  14. ; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  15. ; All users of Directory Opus 4 (including versions distributed
  16. ; under the GPL) are entitled to upgrade to the latest version of
  17. ; Directory Opus version 5 at a reduced price. Please see
  18. ; http://www.gpsoft.com.au for more information.
  19. ; The release of Directory Opus 4 under the GPL in NO WAY affects
  20. ; the existing commercial status of Directory Opus 5.
  21.  
  22. * Get CPU usage as a percentage
  23. * getusage() routine takes no arguments, returns value from 0 to 100 in d0
  24. * basically pinched from an old version of xoper, thanks Werner :)
  25.  
  26.     XDEF _getusage
  27.  
  28.     section code,code
  29.  
  30. _getusage:
  31.     movem.l d1-d3/a6,-(sp)
  32.     move.l 4,a6
  33.     move.l 280(a6),d0
  34.     move.l 284(a6),d1
  35.     move.l oldidl,d3
  36.     move.l d0,oldidl
  37.     sub.l d3,d0
  38.     move.l olddisp,d3
  39.     move.l d1,olddisp
  40.     sub.l d1,d3
  41.     move.l d0,d1
  42.     sub.l d3,d1
  43.     sub.l d3,d0
  44.     neg.l d3
  45.     bsr getpcent
  46.     movem.l (sp)+,d1-d3/a6
  47.     rts
  48.  
  49. getpcent:
  50.     lsl.l #1,d3
  51.     move.l d3,d1
  52.     lsl.l #2,d3
  53.     add.l d1,d3
  54.     lsl.l #2,d3
  55.     move.l d3,d1
  56.     lsl.l #3,d3
  57.     move.l d3,d2
  58.     lsl.l #1,d3
  59.     add.l d2,d3
  60.     add.l d1,d3
  61.     move.l d0,d1
  62.     move.l d3,d0
  63.     IFGE __CPU-68020
  64.     tst d1
  65.     beq.s div_by_0
  66.     divu.l d1,d0
  67. div_by_0
  68.     rts
  69.     ELSE
  70.     bsr div32
  71.     rts
  72.  
  73. * 32-bit division routines
  74.  
  75. div32:
  76.     tst.l d1
  77.     beq div8
  78.     swap d1
  79.     move.w d1,d2
  80.     bne.s div1
  81.     swap d0
  82.     swap d1
  83.     swap d2
  84.     move.w d0,d2
  85.     beq.s div2
  86.     divu d1,d2
  87.     move.w d2,d0
  88. div2
  89.     swap d0
  90.     move.w d0,d2
  91.     divu d1,d2
  92.     move.w d2,d0
  93.     swap d2
  94.     move.w d2,d1
  95.     bra div8
  96. div1
  97.     moveq #$10,d3
  98.     cmpi.w #$80,d1
  99.     bcc.s div3
  100.     rol.l #8,d1
  101.     subq.w #8,d3
  102. div3
  103.     cmpi.w #$800,d1
  104.     bcc.s div4
  105.     rol.l #4,d1
  106.     subq.w #4,d3
  107. div4
  108.     cmpi.w #$2000,d1
  109.     bcc.s div5
  110.     rol.l #2,d1
  111.     subq.w #2,d3
  112. div5
  113.     tst.w d1
  114.     bmi.s div6
  115.     rol.l #1,d1
  116.     subq.w #1,d3
  117. div6
  118.     move.w d0,d2
  119.     lsr.l d3,d0
  120.     swap d2
  121.     clr.w d2
  122.     lsr.l d3,d2
  123.     swap d3
  124.     divu d1,d0
  125.     move.w d0,d3
  126.     move.w d2,d0
  127.     move.w d3,d2
  128.     swap d1
  129.     mulu d1,d2
  130.     sub.l d2,d0
  131.     bcc.s div7
  132.     subq.w #1,d3
  133.     add.l d1,d0
  134. div7
  135.     moveq #0,d1
  136.     move.w d3,d1
  137.     swap d3
  138.     rol.l d3,d0
  139.     swap d0
  140.     exg d1,d0
  141. div8
  142.     rts
  143.     ENDIF
  144.  
  145.     section data,data
  146.  
  147. oldidl
  148.     dc.l 0
  149. olddisp
  150.     dc.l 0
  151.  
  152.     end
  153.