Subversion Repositories Kolibri OS

Rev

Rev 135 | Rev 268 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
31 halyavin 1
;
2
;   PROCESS MANAGEMENT
3
;
4
;   VTurjanmaa
5
;   additions by M.Lisovin lisovin@26.ru
6
;   Compile with FASM for Menuet
7
;
8
 
9
  use32
10
  org    0x0
11
STACK_SIZE=1024
12
  db     'MENUET01'              ; 8 byte id
13
  dd     0x01                    ; header version
14
  dd     START                   ; start of code
15
  dd     I_END                   ; size of image
16
  dd     U_END+STACK_SIZE        ; memory for app
17
  dd     U_END+STACK_SIZE        ; esp
18
  dd     0x0 , 0x0               ; I_Param , I_Icon
19
 
20
include 'lang.inc'
21
include 'macros.inc'
22
display_processes=32            ; number of processes to show
23
START:                          ; start of execution
24
; calculate window position
25
; at the center of the screen
26
    call calculate_window_pos
27
 
28
;main loop when process name isn't edited.
29
red:
30
    mov  ebp,1
31
    call draw_window            ; redraw all window
32
still:
33
    mov  eax,23                 ; wait here for event
34
    mov  ebx,100                ; 1 sec.
35
    int  0x40
36
 
37
    cmp  eax,1                  ; redraw request ?
38
    je   red
39
    cmp  eax,2                  ; key in buffer ?
40
    je   key
41
    cmp  eax,3                  ; button in buffer ?
42
    je   button
43
still_end:
44
    xor  ebp,ebp                ; draw new state of processes
45
    call draw_window
46
    jmp  still
47
 
48
 
49
  key:                          ; key
50
    mov  eax,2
51
    int  0x40
52
    cmp  ah,184                 ; PageUp
53
    je   pgdn
54
    cmp  ah,183
55
    je   pgup                   ; PageDown
56
    cmp  ah,27
57
    je   close                  ; Esc
58
    jmp  still_end
59
 
60
  button:
61
; get button id
62
    mov  eax,17
63
    int  0x40
64
    shr  eax,8
65
 
66
;id in [10,50] corresponds to terminate buttons.
67
    cmp  eax,10
68
    jb   noterm
69
    cmp  eax,50
70
    jg   noterm
71
 
72
;calculate button index
73
    sub  eax,11
74
 
75
;calculate process slot
76
    mov  ecx,[tasklist+4*eax]
77
 
78
;ignore empty buttons
79
    test ecx,ecx
80
    jle  still_end
81
;terminate application
82
    mov  eax,18
83
    mov  ebx,2
84
    int  0x40
85
    jmp  still_end
86
  noterm:
87
 
88
;special buttons
89
    cmp  eax,51
90
    jz   pgdn
91
    cmp  eax,52
92
    jz   pgup
93
    cmp  eax,53
94
    jz   read_string
95
    cmp  eax,54
96
    jz   program_start
97
    cmp  eax,55
98
    jz   reboot
99
    cmp  eax,1
100
    jz   close
101
    jmp  still_end
102
 
103
;buttons handlers
104
  pgdn:
105
    sub  [list_start],display_processes
205 heavyiron 106
;    cmp  [list_start],0
31 halyavin 107
    jge  still_end
108
    mov  [list_start],0
109
    jmp  still_end
110
 
111
  pgup:
112
    mov  eax,[list_add]  ;maximal displayed process slot
113
    mov  [list_start],eax
114
    jmp  still_end
115
 
116
  program_start:
205 heavyiron 117
    mov  eax,70
31 halyavin 118
    mov  ebx,file_start
119
    int  0x40
120
    jmp  still_end
121
 
122
  reboot:
123
    mov  eax,18
124
    mov  ebx,1
125
    int  0x40
126
;close program if we going to reboot
127
 
128
  close:
129
    mov  eax,-1                 ; close this program
130
    int  0x40
131
 
132
draw_next_process:
133
;input:
134
;  edi - current slot
135
;  [curposy] - y position
136
;output:
137
;  edi - next slot (or -1 if no next slot)
138
;registers corrupted!
139
 
140
;create button
141
    test  ebp,ebp
142
    jnz   .nodelete
143
;delete old button
144
    mov   eax,8
145
    mov   edx,[index]
146
    add   edx,(1 shl 31)+11
147
    int   0x40
148
.nodelete:
149
;create terminate process button
150
    mov   eax,8
151
    mov   ebx,15*65536+100
152
    mov   ecx,[curposy]
153
    shl   ecx,16
154
    mov   cx,10
155
    mov   edx,[index]
156
    add   edx,11
157
    mov   esi,0xaabbcc
158
;contrast
159
    test  dword [index],1
160
    jz    .change_color_button
161
    mov   esi,0x8899aa
162
.change_color_button:
163
    int   0x40
164
 
165
;draw background for proccess information
166
    mov   eax,13
167
    mov   ebx,115*65536+395
168
    ;ecx was already set
169
    mov   edx,0x88ff88
170
;contrast
171
    test  dword [index],1
172
    jz    .change_color_info
173
    mov   edx,0xddffdd
174
.change_color_info:
175
    int   0x40
176
 
177
;nothing else should be done
178
;if there is no process for this button
179
    test  edi,edi
180
    jl    .ret
181
 
182
;find process
183
    inc   edi
184
;more comfortable register for next loop
185
    mov   ecx,edi
186
;precacluate pointer to process buffer
187
    mov   ebx,process_info_buffer
188
 
189
;find process loop
190
.find_loop:
191
    cmp   ecx,256
192
    jge   .no_processes
193
 
194
;load process information in buffer
195
    mov   eax,9
196
;    mov   ebx,process_info_buffer
197
    int   0x40
198
 
199
;if current slot greater than maximal slot,
200
;there is no more proccesses.
201
    cmp   ecx,eax
202
    jg    .no_processes
203
 
204
;if slot state is equal to 9, it is empty.
205
    cmp   [process_info_buffer+process_information.slot_state],9
206
    jnz   .process_found
207
 
208
    inc   ecx
209
    jmp   .find_loop
210
 
211
.no_processes:
212
    mov   edi,-1
213
    ret
214
 
215
.process_found:
216
    mov  edi,ecx
217
    mov  [list_add],ecx
218
 
219
;get processor cpeed
220
;for percent calculating
221
    mov  eax,18
222
    mov  ebx,5
223
    int  0x40
224
 
225
    xor  edx,edx
226
    mov  ebx,100
227
    div ebx
228
 
229
;eax = number of operation for 1% now
230
;calculate process cpu usage percent
231
    mov  ebx,eax
232
    mov  eax,[process_info_buffer+process_information.cpu_usage]
233
;    cdq
234
   xor edx,edx ; for CPU more 2 GHz - mike.dld
235
 
236
    div  ebx
237
    mov  [cpu_percent],eax
238
 
239
;set text color to display process information
240
;([tcolor] variable)
241
;0%      : black
242
;1-80%   : green
243
;81-100% : red
244
    test eax,eax
245
    jg   .no_black
246
    mov  [tcolor],eax
247
    jmp  .color_set
248
.no_black:
249
    cmp  eax,80
250
    ja   .no_green
251
    mov  dword [tcolor],0x107a30
252
    jmp  .color_set
253
.no_green:
254
    mov  dword [tcolor],0xac0000
255
.color_set:
256
 
257
;show slot number
258
    mov  eax,47
259
    mov  ebx,2*65536+1*256
260
;ecx haven't changed since .process_found
261
;    mov  ecx,edi
262
    mov  edx,[curposy]
263
    add  edx,20*65536+1
264
    mov  esi,[tcolor]
265
    int  0x40
266
 
267
;show process name
268
    mov  eax,4
269
    mov  ebx,[curposy]
270
    add  ebx,50*65536+1
271
    mov  ecx,[tcolor]
272
    mov  edx,process_info_buffer.process_name
273
    mov  esi,11
274
    int  0x40
275
 
276
;show pid
277
    mov  eax,47
278
    mov  ebx,8*65536+1*256
279
    mov  ecx,[process_info_buffer.PID]
280
    mov  edx,[curposy]
281
    add  edx,130*65536+1
282
    mov  esi,[tcolor]
283
    int  0x40
284
 
285
;show cpu usage
286
    mov  ecx,[process_info_buffer.cpu_usage]
287
    add  edx,60*65536
288
    int  0x40
289
 
290
;show cpu percent
291
    mov  ebx,3*65536+0*256
292
    mov  ecx,[cpu_percent]
293
    add  edx,60*65536
294
    int  0x40
295
 
296
;show memory start - obsolete
297
    mov  ebx,8*65536+1*256
298
    mov  ecx,[process_info_buffer.memory_start]
299
    add  edx,30*65536
300
    int  0x40
301
 
302
;show memory usage
303
    mov  ecx,[process_info_buffer.used_memory]
304
    inc  ecx
305
    add  edx,60*65536
306
    int  0x40
307
 
308
;show window stack and value
309
    mov  ecx,dword [process_info_buffer.window_stack_position]
310
    add  edx,60*65536
311
    int  0x40
312
 
313
;show window xy size
314
    mov  ecx,[process_info_buffer.x_size]
315
    shl  ecx,16
316
    add  ecx,[process_info_buffer.y_size]
317
    add  edx,60*65536
318
    int  0x40
319
 
320
.ret:
321
;build index->slot map for terminating processes.
322
    mov  eax,[index]
323
    mov  [tasklist+4*eax],edi
324
    ret
325
 
326
read_string:
327
 
328
;clean string
329
    mov  edi,start_application
330
    xor  eax,eax
331
    mov  ecx,60
332
    cld
333
    rep  stosb
334
    call print_text
335
 
336
    mov  edi,start_application
337
;edi now contains pointer to last symbol
338
    jmp  still1
339
 
340
;read string main loop
341
  f11:
342
;full update
343
    push edi
344
    mov  ebp,1
345
    call draw_window
346
    pop  edi
347
  still1:
348
;wait for message
349
    mov  eax,23
350
    mov  ebx,100
351
    int  0x40
352
    cmp  eax,1
353
    je   f11
354
;if no message - update process information
355
    cmp  eax,0
356
    jnz  .message_received
357
    push edi                ;edi should be saved since draw_window
358
    xor  ebp,ebp            ;corrupt registers
359
    call draw_window
360
    pop  edi
361
    jmp  still1
362
 
363
.message_received:
364
    cmp  eax,2
365
    jne  read_done          ;buttons message
366
;read char
367
    mov  eax,2
368
    int  0x40
369
    shr  eax,8
370
 
371
;if enter pressed, exit read string loop
372
    cmp  eax,13
373
    je   read_done
374
;if backslash pressed?
375
    cmp  eax,8
376
    jnz  nobsl
377
;decrease pointer to last symbol
378
    cmp  edi,start_application
379
    jz   still1
380
    dec  edi
381
;fill last symbol with space because
382
;print_text show all symbols
383
    mov  [edi],byte 32
384
    call print_text
385
    jmp  still1
386
 
387
  nobsl:
388
;write new symbol
389
    mov  [edi],al
390
;display new text
391
    call print_text
392
;increment pointer to last symbol
393
    inc  edi
394
;compare with end of string
395
    mov  esi,start_application
396
    add  esi,60
397
    cmp  esi,edi
398
    jnz  still1
399
 
400
;exiting from read string loop
401
  read_done:
402
;terminate string for file functions
403
    mov  [edi],byte 0
404
 
405
    call print_text
406
    jmp  still
407
 
408
 
409
print_text:
410
;display start_application string
411
 
412
    pushad
413
 
414
;display text background
415
    mov  eax,13
416
    mov  ebx,64*65536+62*6
417
    mov  ecx,400*65536+12
418
    mov  edx,0xffffcc  ;0xeeeeee
419
    int  0x40
420
 
421
;display text
422
    mov  eax,4
423
    mov  edx,start_application  ;from start_application string
424
    mov  ebx,70*65536+402       ;text center-aligned
425
    xor  ecx,ecx                ;black text
426
    mov  esi,60                 ;60 symbols
427
    int  0x40
428
 
429
    popad
430
    ret
431
 
432
window_x_size=524
433
window_y_size=430
434
calculate_window_pos:
435
;set window size and position for 0 function
436
;to [winxpos] and [winypos] variables
437
 
438
;get screen size
439
    mov  eax,14
440
    int  0x40
441
    mov  ebx,eax
442
 
443
;calculate (x_screen-window_x_size)/2
444
    shr  ebx,16+1
445
    sub  ebx,window_x_size/2
446
    shl  ebx,16
447
    mov  bx,window_x_size
448
;winxpos=xcoord*65536+xsize
449
    mov  [winxpos],ebx
450
 
451
;calculate (y_screen-window_y_size)/2
452
    and  eax,0xffff
453
    shr  eax,1
454
    sub  eax,window_y_size/2
455
    shl  eax,16
456
    mov  ax,window_y_size
457
;winypos=ycoord*65536+ysize
458
    mov  [winypos],eax
459
 
460
    ret
461
 
462
;   *********************************************
463
;   *******  WINDOW DEFINITIONS AND DRAW ********
464
;   *********************************************
465
 
466
 
467
draw_window:
468
;ebp=1 - redraw all
469
;ebp=0 - redraw only process information
470
 
471
    test ebp,ebp
472
    jz   .show_process_info
473
 
474
    mov  eax,12                    ; function 12:tell os about windowdraw
475
    mov  ebx,1                     ; 1, start of draw
476
    int  0x40
477
 
478
                                   ; DRAW WINDOW
479
    xor  eax,eax                   ; function 0 : define and draw window
480
    mov  ebx,[winxpos]             ; [x start] *65536 + [x size]
481
    mov  ecx,[winypos]             ; [y start] *65536 + [y size]
482
    mov  edx,0x03ddffdd  ;ffffff   ; color of work area RRGGBB,8->color
483
    mov  esi,0x805080d0            ; color of grab bar  RRGGBB,8->color gl
484
    mov  edi,0x005080d0            ; color of frames    RRGGBB
485
    int  0x40
486
 
487
                                   ; WINDOW CAPTION
488
    mov  eax,4                     ; function 4 : write text to window
489
    mov  ebx,8*65536+8             ; [x start] *65536 + [y start]
490
    mov  ecx,0x10ffffff            ; font 1 & color ( 0xF0RRGGBB )
491
    mov  edx,labelt                ; pointer to text beginning
492
    mov  esi,labellen-labelt       ; text length
493
    int  0x40
494
 
495
    mov  ebx,22*65536+35           ; draw info text with function 4
496
    xor  ecx,ecx
497
    mov  edx,text
205 heavyiron 498
    mov  esi,text_len
31 halyavin 499
    mov  eax,4
500
    int  0x40
501
 
502
.show_process_info:
503
    mov  edi,[list_start]
504
    mov  [list_add],edi
505
    mov  dword [index],0
506
    mov  dword [curposy],54
507
.loop_draw:
508
    call draw_next_process
509
    inc  dword [index]
510
    add  dword [curposy],10
511
    cmp  [index],display_processes
512
    jl   .loop_draw
513
 
514
    test ebp,ebp
515
    jz   .end_redraw
516
    mov  eax,8
517
    mov  esi,0xaabbcc
518
 
519
; previous page button
520
    mov  ebx,30*65536+96
521
    mov  ecx,380*65536+10
522
    mov  edx,51
523
    int  0x40
524
 
525
; next page button
526
    mov  ebx,130*65536+96
527
    inc  edx
528
    int  0x40
529
 
530
; ">" (text enter) button
531
    mov  ebx,30*65536+20
532
    add  ecx,20 shl 16
533
    inc  edx
534
    int  0x40
535
 
536
; run button
537
    mov  ebx,456*65536+50
538
    inc  edx
539
    int  0x40
540
 
541
; reboot button
542
    sub  ebx,120*65536
543
    add  ebx,60
544
    sub  ecx,20 shl 16
545
    inc  edx
546
    int  0x40
547
 
548
;"PREV PAGE", "NEXT PAGE" and "REBOOT" labels
549
    mov  eax,4
550
    mov  ebx,50*65536+382
551
    xor  ecx,ecx
552
    mov  edx,tbts
553
    mov  esi,tbte-tbts
554
    int  0x40
555
 
556
;">" labels
557
    mov  eax,4
558
    mov  ebx,40*65536+402
559
    xor  ecx,ecx
560
    mov  edx,tbts_2
561
    mov  esi,1
562
    int  0x40
563
 
564
;"RUN" labels
565
    mov  eax,4
566
    mov  ebx,475*65536+402
567
    xor  ecx,ecx
568
    mov  edx,tbts_3
569
    mov  esi,tbte_2-tbts_3
570
    int  0x40
571
 
572
;print application name in text box
573
    call print_text
574
 
575
    mov  eax,12                    ; function 12:tell os about windowdraw
576
    mov  ebx,2                     ; 2, end of draw
577
    int  0x40
578
 
579
.end_redraw:
580
    ret
581
 
582
 
583
; DATA AREA
584
list_start  dd 0
585
 
205 heavyiron 586
file_start: dd 7
587
            dd 0,0,0,0
31 halyavin 588
 
589
start_application: db '/RD/1/LAUNCHER',0
590
                   times 60 db 32
591
 
135 diamond 592
if lang eq en
31 halyavin 593
text:
594
  db ' NAME/TERMINATE     PID     CPU-USAGE  %   '
205 heavyiron 595
  db 'MEMORY START/USAGE  W-STACK   W-SIZE'
596
text_len = $-text
31 halyavin 597
 
598
tbts:   db  'PREV PAGE       NEXT PAGE                         REBOOT SYSTEM'
599
tbte:
600
tbts_2  db  '>'
601
tbts_3  db  'RUN'
602
tbte_2:
603
 
604
labelt:
605
     db   'Processes - Ctrl/Alt/Del'
606
labellen:
135 diamond 607
else
608
text:
205 heavyiron 609
  db ' NAME/BEENDEN       PID     CPU-LAST   % '
610
  db 'SPEICHER START/NUTZUNG  W-STACK  W-SIZE'
611
text_len = $-text
31 halyavin 612
 
135 diamond 613
tbts:   db  'SEITE ZURUECK       SEITE VOR                      REBOOT SYSTEM'
614
tbte:
615
tbts_2  db  '>'
616
tbts_3  db  'START'
617
tbte_2:
618
 
619
labelt:
620
     db   'Prozesse  - Ctrl/Alt/Del'
621
labellen:
622
end if
623
 
31 halyavin 624
I_END:
625
 
626
winxpos  rd 1
627
winypos  rd 1
628
 
629
cpu_percent rd 1
630
tcolor      rd 1
631
list_add    rd 1
632
curposy     rd 1
633
index       rd 1
634
tasklist    rd display_processes
635
process_info_buffer process_information
636
U_END: