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