Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ;
  2. ;    CPU USAGE for MenuetOS  -  Compile with FASM 1.30+
  3. ;
  4.  
  5. use32
  6.  
  7.               org    0x0
  8.               db     'MENUET00'              ; 8 byte id
  9.               dd     38                      ; required os version
  10.               dd     START                   ; program start
  11.               dd     I_END                   ; program image size
  12.               dd     0x1000                  ; reguired amount of memory
  13.               dd     0x1000
  14.               dd     0x00000000              ; reserved=no extended header
  15.  
  16. include 'lang.inc'
  17. include 'macros.inc'
  18. START:
  19.  
  20.     call set_variables
  21.  
  22.     call draw_window
  23.  
  24.     mov  edi,0
  25.  
  26. still:
  27.  
  28.     mov  eax,23
  29.     mov  ebx,10
  30.     int  0x40
  31.  
  32.     cmp  eax,1
  33.     je   red
  34.     cmp  eax,2
  35.     je   key
  36.     cmp  eax,3
  37.     je   button
  38.  
  39.     inc  edi
  40.     cmp  edi,10
  41.     jb   still
  42.  
  43.     mov  edi,0
  44.     call draw_usage
  45.  
  46.     jmp  still
  47.  
  48.   red:
  49.     call draw_window
  50.     jmp  still
  51.  
  52.   key:
  53.     mov  eax,2
  54.     int  0x40
  55.     jmp  still
  56.  
  57.   button:
  58.     mov  eax,17
  59.     int  0x40
  60.     cmp  al,byte 0
  61.     jnz  still
  62.     mov  eax,-1
  63.     int  0x40
  64.  
  65.  
  66. set_variables:
  67.  
  68.     pusha
  69.  
  70.     mov  ecx,190
  71.     mov  edi,pros
  72.     mov  eax,100
  73.     cld
  74.     rep  stosb
  75.  
  76.     popa
  77.     ret
  78.  
  79.  
  80. draw_window:
  81.  
  82.     pusha
  83.  
  84.     mov  eax,12                    ; tell os about redraw
  85.     mov  ebx,1
  86.     int  0x40
  87.  
  88.     mov  eax,0                     ; define and draw window
  89.     mov  ebx,50*65536+207
  90.     mov  ecx,50*65536+127
  91.     mov  edx,0x03000000
  92.     mov  esi,0x806688aa
  93.  
  94.     mov  edi,0x0088ccee
  95.     int  0x40
  96.  
  97.     mov  eax,4      ; 'CPU USAGE'
  98.     mov  ebx,8*65536+8
  99.     mov  ecx,dword 0x00ffffff
  100.     mov  edx,text
  101.     mov  esi,textlen-text
  102.     int  0x40
  103.  
  104.     mov  eax,12                    ; tell os about redraw end
  105.     mov  ebx,2
  106.     int  0x40
  107.  
  108.     popa
  109.     ret
  110.  
  111.  
  112.  
  113. draw_usage:
  114.  
  115.     pusha                          ; CPU usage
  116.  
  117.     cld
  118.     mov  eax,18 ; TSC / SEC
  119.     mov  ebx,5
  120.     int  0x40
  121.     shr  eax,20
  122.     push eax
  123.  
  124.     mov  eax,18 ; IDLE / SEC
  125.     mov  ebx,4
  126.     int  0x40
  127.     shr  eax,20
  128.     xor  edx,edx
  129.     mov  ebx,100
  130.     mul  ebx
  131.  
  132.     xor  edx,edx
  133.     pop  ebx
  134.     add  ebx,1
  135.     div  ebx
  136.     push eax
  137.  
  138.     mov  esi,pros+1
  139.     mov  edi,pros
  140.     mov  ecx,195
  141.     cld
  142.     rep  movsb
  143.  
  144.     pop  eax
  145.     mov  [pros+99],al
  146.  
  147.     mov  eax,13
  148.     mov  ebx,5*65536+1
  149.     mov  esi,pros
  150.     mov  edi,pros+99
  151.  
  152.   newpros:
  153.  
  154.     add  esi,1
  155.  
  156.     xor  eax,eax   ; up
  157.     mov  al,[esi]
  158.     add  eax,1
  159.     mov  ecx,22*65536
  160.     mov  cx,ax
  161.     mov  eax,13
  162.     mov  edx,0x0
  163.     int  0x40
  164.  
  165.     pusha          ; down
  166.     xor  eax,eax
  167.     mov  al,[esi]
  168.     mov  ecx,22
  169.     add  ecx,eax
  170.     shl  ecx,16
  171.     mov  cx,101
  172.     sub  cx,ax
  173.     mov  eax,13
  174.     mov  edx,0xdddddd
  175.     int  0x40
  176.     popa
  177.  
  178.     add  ebx,2*65536
  179.  
  180.     cmp  esi,edi
  181.     jb   newpros
  182.  
  183.     popa
  184.     ret
  185.  
  186.  
  187. ; DATA AREA
  188.  
  189. text:     db   'CPU LOAD HISTORY  '
  190. textlen:
  191.  
  192. pros:
  193.  
  194. I_END:
  195.  
  196.  
  197.  
  198.