Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
8129 IgorA 1
;const int
2
MENUET_BORDER_SIZE = 4;
3
;const int
4
MENUET_HEADER_SIZE = 20;
5
 
6
;const int
8133 IgorA 7
KOLIBRI_THREAD_DATA_USER     = 0; // Thread data begin from the user dword
8129 IgorA 8
;const int
8133 IgorA 9
KOLIBRI_THREAD_DATA_ST_BEGIN = 1; // Stack beginning follows after the user dword
8129 IgorA 10
;const int
8133 IgorA 11
KOLIBRI_THREAD_DATA_NEXT     = 2;
8129 IgorA 12
;const int
8133 IgorA 13
KOLIBRI_THREAD_DATA_PID	    = 3;
8129 IgorA 14
;const int
8133 IgorA 15
KOLIBRI_THREAD_DATA_FLAG     = 4;
8129 IgorA 16
;const int
8133 IgorA 17
KOLIBRI_THREAD_DATA_X	    = 5;
8129 IgorA 18
;const int
8133 IgorA 19
KOLIBRI_THREAD_DATA_Y	    = 6;
8129 IgorA 20
;const int
8133 IgorA 21
KOLIBRI_THREAD_DATA_C_WINDOW = 7;
8129 IgorA 22
;const int
8133 IgorA 23
KOLIBRI_THREAD_DATA_C_HEADER = 8;
8129 IgorA 24
;const int
8133 IgorA 25
KOLIBRI_THREAD_DATA_C_BORDER = 9;
8129 IgorA 26
;const int
8133 IgorA 27
KOLIBRI_THREAD_DATA_C_TITLE  = 10;
8129 IgorA 28
;const int
8133 IgorA 29
KOLIBRI_THREAD_DATA_TITLE    = 11;
8129 IgorA 30
;const int
8133 IgorA 31
KOLIBRI_THREAD_DATA_PICTURE  = 12;
8129 IgorA 32
;const int
8133 IgorA 33
KOLIBRI_THREAD_DATA_SZ_PICT  = 13;
8129 IgorA 34
;const int
8133 IgorA 35
KOLIBRI_THREAD_DATA_LAST_SX  = 14;
8129 IgorA 36
;const int
8133 IgorA 37
KOLIBRI_THREAD_DATA_LAST_SY  = 15;
8129 IgorA 38
;const int
8133 IgorA 39
KOLIBRI_THREAD_DATA_LEN	    = 16;
8129 IgorA 40
 
41
;const int
42
MENUET_MUTEX_MAX_TIME_WAIT  = 20;
43
 
44
;const int
8133 IgorA 45
KOLIBRI_FILE_BLOCK_SIZE	    = 512;
8129 IgorA 46
 
47
;const int
8133 IgorA 48
KOLIBRI_FILE_MEMORY_OS_NEED  = 4096;
8129 IgorA 49
 
50
;/***
51
 
52
macro segment name
53
{
54
  segment name
55
  if name eq _init_ | name eq _INIT_
56
Menuet_SegmentInit:
57
  else if name eq _exit_ | name eq _EXIT_
58
Menuet_SegmentExit:
59
  end if
60
}
61
 
62
macro endseg  name
63
{
64
  if name eq _init_ | name eq _INIT_
65
Menuet_SegmentInitEnd:
66
  else if name eq _exit_ | name eq _EXIT_
67
Menuet_SegmentExitEnd:
68
  end if
69
  endseg  name
70
}
71
 
72
macro Menuet_Put_MovEaxVal_Ret	address,val
73
{
74
  mov  byte [address],0xB8
75
  mov  dword [address+4],0xC089C300
76
  mov  dword [address+1],val
77
}
78
 
79
proc @Kolibri@Main$qv
80
  and  esp,not 3
81
  sub  esp,1024
82
  mov  eax,9
83
  mov  ebx,esp
84
  mov  ecx,-1
85
  int  0x40
86
  mov  ebx,[esp+26]
87
  mov  edx,[esp+30]
88
  lea  eax,[ebx-0x20]
89
  add  esp,1024
90
  cmp  esp,eax
91
  cmova esp,eax
92
  and  esp,not 3
93
if defined @Kolibri@CommandLine
94
	mov	byte [@Kolibri@CommandLine+256], 0
95
end if
96
  xor  eax,eax
97
  cld
98
  mov  edi,@Kolibri@_ThreadTable
99
  mov  ecx,256
100
  rep stos dword [edi]
101
  mov  esi,@Kolibri@GetPid$qv
102
  mov  edi,@Kolibri@_ThreadSavedBegProc
103
  movs dword [edi],[esi]
104
  movs dword [edi],[esi]
105
  mov  esi,@Kolibri@GetThreadData$qv
106
  movs dword [edi],[esi]
107
  movs dword [edi],[esi]
108
  Menuet_Put_MovEaxVal_Ret  @Kolibri@GetPid$qv,edx
109
if defined MenuetHeapInit
110
  mov  ecx,esp
111
  push ebx
112
  push ecx
113
  push U_END
114
  call MenuetHeapInit	; Initialize a dynamic heap and create new memory in its begin.
115
  pop  ecx		; Parameters: begin of a new heap, end of data to create in
116
  mov  [esp+4],eax	; the begin of a heap. Return address of the created data.
117
  mov  dword [esp],0
118
else
119
  xor  eax,eax
120
  push eax
121
  push eax
122
end if
123
  call @Kolibri@ThreadMain$qpvt1
124
.ThreadFinish:
125
  add  esp,8
126
if defined MenuetHeapFreeAndThreadFinish
127
  test eax,eax
128
  jz   .ThreadFinish_end
129
  push dword @Kolibri@_ExitProcessNow
130
  push eax
131
  call MenuetHeapFreeAndThreadFinish   ; Free the given memory and finish the thread,
132
end if				       ; should exit process if second argument points to not zero.
133
.ThreadFinish_end:
134
  or   eax,-1
135
  int  0x40
136
endp
137
 
138
proc @Kolibri@ThreadMain$qpvt1
139
  xchg ebx,[esp+4]
140
  xchg ebp,[esp+8]
141
  push esi edi
8133 IgorA 142
  sub  esp,KOLIBRI_THREAD_DATA_LEN*4
8129 IgorA 143
  mov  [esp],ebx
144
  mov  [esp+4],ebp
145
  mov  eax,40
146
  mov  ebx,0x27
147
  int  0x40
148
  mov  ebx,esp
149
  cmp  byte [@Kolibri@_ThreadSavedBegProc],0x90
150
  jz   .main_else_first_check
151
  Menuet_Put_MovEaxVal_Ret  @Kolibri@GetThreadData$qv,esp
152
if defined Menuet_SegmentInit & defined Menuet_SegmentInitEnd
153
  push Menuet_SegmentInitEnd
154
  push Menuet_SegmentInit
155
  jmp  .main_after_first_check
156
end if
157
.main_else_first_check:
158
  xor  eax,eax
159
  push eax eax
160
.main_after_first_check:
161
  push ebx
162
  call @@Kolibri@_CallStart$qppvpvt2
163
  add  esp,12
164
  test al,al
165
  jnz  .main_test_close_first
166
  jmp  .main_end
167
.main_close_first:
8133 IgorA 168
  btr  dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],31
8129 IgorA 169
  push esp
8133 IgorA 170
  call @@KolibriOnClose$qppv
8129 IgorA 171
  pop  ecx
172
  test al,al
173
  jnz  .main_end
174
.main_test_close_first:
8133 IgorA 175
  cmp  dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],0
8129 IgorA 176
  jl   .main_close_first
177
  push esp
178
  push dword 1
179
  call @Kolibri@Redraw$qippv
180
  add  esp,8
181
.main_paint_msg:
8133 IgorA 182
  or   dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],3
8129 IgorA 183
  sub  esp,1024
184
  mov  eax,9
185
  mov  ebx,esp
186
  mov  ecx,-1
187
  int  0x40
188
  mov  eax,[esp+34]
189
  mov  ebx,[esp+38]
190
  mov  ecx,[esp+42]
191
  mov  edx,[esp+46]
192
  add  esp,1024
8133 IgorA 193
  cmp  ecx,[esp+KOLIBRI_THREAD_DATA_LAST_SX*4]
8129 IgorA 194
  jnz  .main_size
8133 IgorA 195
  cmp  edx,[esp+KOLIBRI_THREAD_DATA_LAST_SY*4]
8129 IgorA 196
  jz   .main_paint
197
.main_size:
8133 IgorA 198
  mov  [esp+KOLIBRI_THREAD_DATA_LAST_SX*4],ecx
199
  mov  [esp+KOLIBRI_THREAD_DATA_LAST_SY*4],edx
8129 IgorA 200
  push edx
201
  push ecx
202
  push ebx
203
  push eax
204
  lea  ecx,[esp+16]
205
  mov  edx,esp
206
  push ecx
207
  push edx
8133 IgorA 208
  call @@KolibriOnSize$qpippv
8129 IgorA 209
  add  esp,24
8133 IgorA 210
  test dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],3
8129 IgorA 211
  jz   .main_cycle
212
.main_paint:
8133 IgorA 213
  cmp  dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],0
8129 IgorA 214
  jl   .main_close
215
  push esp
216
  push dword 0
217
  call @Kolibri@Redraw$qippv
218
  add  esp,8
219
.main_cycle:
220
  mov  eax,11
221
.main_message:
8133 IgorA 222
  cmp  dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],0
8129 IgorA 223
  jl   .main_close
224
  int  0x40
225
  test eax,eax
226
  jnz  .main_on_message
8133 IgorA 227
  cmp  dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],0
8129 IgorA 228
  jne  .main_paint
229
  push esp
8133 IgorA 230
  call @@KolibriOnIdle$qppv
8129 IgorA 231
  pop  ecx
232
  test eax,eax
233
  jz   .main_cycle
234
  jl   .main_wait_message
235
  mov  ebx,eax
236
  mov  eax,23
237
  jmp  .main_message
238
.main_wait_message:
239
  mov  eax,10
240
  jmp  .main_message
241
.main_key_press:
242
  push esp
8133 IgorA 243
  call @@KolibriOnKeyPress$qppv
8129 IgorA 244
  pop  ecx
245
  jmp  .main_cycle
246
.main_mouse:
247
  push esp
8133 IgorA 248
  call @@KolibriOnMouse$qppv
8129 IgorA 249
  pop  ecx
250
  jmp  .main_cycle
251
.main_on_message:
252
  dec  eax
253
  jz   .main_paint_msg
254
  dec  eax
255
  jz   .main_key_press
256
  cmp  eax,4
257
  jz   .main_mouse
258
  dec  eax
259
  jnz  .main_cycle
260
.main_button:
261
  mov  eax,17
262
  int  0x40
263
  test al,al
264
  jnz  .main_cycle
265
.main_close:
8133 IgorA 266
  btr  dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],31
8129 IgorA 267
  push esp
8133 IgorA 268
  call @@KolibriOnClose$qppv
8129 IgorA 269
  pop  ecx
270
  test al,al
271
  jz   .main_button
272
.main_end:
273
  mov  ebx,esp
274
  lock dec dword [@Kolibri@_ThreadNumber]
275
if defined Menuet_SegmentExit & defined Menuet_SegmentExitEnd
276
  jnz  .main_else_last_check
277
  push Menuet_SegmentExitEnd
278
  push Menuet_SegmentExit
279
  jmp  .main_after_last_check
280
end if
281
.main_else_last_check:
282
  xor  eax,eax
283
  push eax
284
  push eax
285
.main_after_last_check:
286
  push ebx
287
  call @@Kolibri@_RemoveThreadData$qppvpvt2
288
  add  esp,12
289
  lock inc dword [@Kolibri@_ThreadScanCount+4]
290
  mov  ebx,1
291
  jmp  .main_end_wait
292
.main_end_wait_loop:
293
  mov  eax,5
294
  int  0x40
295
  shl  ebx,1
296
  cmp  ebx,MENUET_MUTEX_MAX_TIME_WAIT
297
  jna  .main_end_wait
298
  mov  ebx,MENUET_MUTEX_MAX_TIME_WAIT
299
.main_end_wait:
300
  cmp  dword [@Kolibri@_ExitProcessNow],0
301
  jnz  @Kolibri@ExitProcess$qv
302
  cmp  dword [@Kolibri@_ThreadScanCount],0
303
  jnz  .main_end_wait_loop
304
  lock dec dword [@Kolibri@_ThreadScanCount+4]
305
  mov  ebp,[esp+4]
306
  mov  ebx,[esp]
8133 IgorA 307
  add  esp,KOLIBRI_THREAD_DATA_LEN*4
8129 IgorA 308
  mov  eax,ebp
309
  pop  edi esi
310
  xchg ebp,[esp+8]
311
  xchg ebx,[esp+4]
312
  ret
313
endp
314
 
315
macro call func
316
{
317
  if func eq __chkstk
318
	sub  esp,eax
319
  else
320
	call func
321
  end if
322
}
323
 
324
proc @Kolibri@Redraw$qippv
325
  push ebp
326
  mov  ebp,[esp+12]
8133 IgorA 327
  mov  edx,[ebp+KOLIBRI_THREAD_DATA_FLAG*4]
8129 IgorA 328
  cmp  dword [esp+8],0
329
  jl   .redraw_only_inv
330
  jz   .redraw_no_frame
331
  or   dl,2
332
.redraw_no_frame:
333
  bt   edx,30
334
  jnc  .redraw_begin
335
  or   dl,1
8133 IgorA 336
  mov  [ebp+KOLIBRI_THREAD_DATA_FLAG*4],edx
8129 IgorA 337
  jmp  .redraw_end
338
.redraw_only_inv:
339
  test dl,3
340
  jnz  .redraw_no_frame
341
.redraw_end:
342
  pop  ebp
343
  ret
344
.redraw_begin:
345
  push ebx esi edi
8133 IgorA 346
  and  dword [ebp+KOLIBRI_THREAD_DATA_FLAG*4],0xFFFFFFFC
8129 IgorA 347
  test dl,2
348
  jz   .redraw_picture
349
  mov  eax,12
350
  mov  ebx,1
351
  int  0x40
352
  xor  eax,eax
8133 IgorA 353
  mov  ebx,[ebp+KOLIBRI_THREAD_DATA_X*4]
354
  mov  ecx,[ebp+KOLIBRI_THREAD_DATA_Y*4]
355
  mov  edx,[ebp+KOLIBRI_THREAD_DATA_C_WINDOW*4]
356
  mov  esi,[ebp+KOLIBRI_THREAD_DATA_C_HEADER*4]
357
  mov  edi,[ebp+KOLIBRI_THREAD_DATA_C_BORDER*4]
8129 IgorA 358
  int  0x40
8133 IgorA 359
  mov  edx,[ebp+KOLIBRI_THREAD_DATA_TITLE*4]
8129 IgorA 360
  test edx,edx
361
  jz   .window_defined
362
  mov  edi,edx
363
  mov  ecx,0xFFFFFFFF
364
  xor  al,al
365
  cld
366
  repnz scas byte [edi]
367
  not  ecx
368
  mov  esi,ecx
369
  dec  esi
370
  jz   .window_defined
371
  mov  eax,4
372
  mov  ebx,0x00070007
8133 IgorA 373
  mov  ecx,[ebp+KOLIBRI_THREAD_DATA_C_TITLE*4]
8129 IgorA 374
  int  0x40
375
.window_defined:
376
  mov  eax,12
377
  mov  ebx,2
378
  int  0x40
379
.redraw_picture:
380
  mov  eax,12
381
  mov  ebx,2
382
  int  0x40
8133 IgorA 383
  mov  esi,[ebp+KOLIBRI_THREAD_DATA_PICTURE*4]
8129 IgorA 384
  test esi,esi
385
  jz   .redraw_end_draw
8133 IgorA 386
  mov  ecx,[ebp+KOLIBRI_THREAD_DATA_SZ_PICT*4]
8129 IgorA 387
  jecxz .redraw_end_draw
8133 IgorA 388
  mov  al,byte [ebp+KOLIBRI_THREAD_DATA_C_WINDOW*4+3]
8129 IgorA 389
  and  al,15
390
  mov  edx,MENUET_BORDER_SIZE*65536+MENUET_HEADER_SIZE
391
  cmp  al,3
392
  jnz  .redraw_no_skin
393
  mov  eax,48
394
  mov  ebx,4
395
  int  0x40
396
  mov  dx,ax
397
.redraw_no_skin:
398
  mov  eax,7
399
  mov  ebx,esi
400
  int  0x40
401
.redraw_end_draw:
402
  pop  edi esi ebx ebp
403
  ret
404
endp
405
 
406
proc @Kolibri@MoveWindow$qxpxi uses ebx esi
407
  mov  eax,[esp+12]
408
  mov  ebx,[eax]
409
  mov  ecx,[eax+4]
410
  mov  edx,[eax+8]
411
  mov  esi,[eax+12]
412
  mov  eax,67
413
  int  0x40
414
  ret
415
endp
416
 
417
;proc @Kolibri@Abort$qv
418
;  push dword [@Kolibri@DebugPrefix]
419
;  call @Kolibri@DebugPutString$qpxc
420
;  mov	dword [esp],Menuet_abort_string
421
;  call @Kolibri@DebugPutString$qpxc
422
;  pop	ecx
423
proc @Kolibri@ExitProcess$qv
424
  lock bts dword [@Kolibri@_ExitProcessNow],0
425
  jc   .exit_process_wait
426
  sub  esp,1024
427
  mov  eax,9
428
  mov  ebx,esp
429
  mov  ecx,-1
430
  int  0x40
431
  mov  esi,eax
432
  mov  edi,[esp+30]
433
.exit_process_loop:
434
  mov  eax,9
435
  mov  ebx,esp
436
  mov  ecx,esi
437
  int  0x40
438
  mov  eax,[esp+30]
439
  cmp  eax,edi
440
  jz   .exit_process_continue
441
  mov  ebx,eax
442
  or   bl,15
443
  inc  ebx
444
  jz   .exit_process_continue
445
  mov  ebx,eax
446
  call Menuet_HashInt
447
  movzx eax,al
448
  mov  eax,dword [@Kolibri@_ThreadTable+eax*4]
449
  jmp  .exit_process_test
450
.exit_process_next:
8133 IgorA 451
  mov  eax,dword [eax+KOLIBRI_THREAD_DATA_NEXT*4]
8129 IgorA 452
.exit_process_test:
453
  test eax,eax
454
  jz   .exit_process_continue
8133 IgorA 455
  cmp  ebx,[eax+KOLIBRI_THREAD_DATA_PID*4]
8129 IgorA 456
  jnz  .exit_process_next
457
  mov  eax,18
458
  mov  ebx,2
459
  mov  ecx,esi
460
  int  0x40
461
.exit_process_continue:
462
  dec  esi
463
  jnl  .exit_process_loop
464
  add  esp,1024
465
  mov  dword [@Kolibri@_ExitProcessNow],-1
466
if defined EMULATOR
467
  int3
468
  call 0x76543210
469
end if
470
.exit_process_end:
471
  mov  dword [@Kolibri@_ThreadMutex],0
472
  or   eax,-1
473
  int  0x40
474
.exit_process_wait:
475
  mov  eax,5
476
  mov  ebx,1
477
.exit_process_wait_loop:
478
  cmp  dword [@Kolibri@_ExitProcessNow],0
479
  jl   .exit_process_end
480
  int  0x40
481
  shl  ebx,1
482
  cmp  ebx,MENUET_MUTEX_MAX_TIME_WAIT
483
  jna  .exit_process_wait_loop
484
  mov  ebx,MENUET_MUTEX_MAX_TIME_WAIT
485
  jmp  .exit_process_wait_loop
486
endp
487
 
488
proc @Kolibri@ExitThread$qppv,@Kolibri@ThreadMain$qpvt1
489
  mov  esp,[esp+4]
490
  jmp  Menuet_main_end
491
endp
492
 
493
proc @Kolibri@ReturnMessageLoop$qppv,@Kolibri@ThreadMain$qpvt1
494
  mov  esp,[esp+4]
8133 IgorA 495
  bt   dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],30
8129 IgorA 496
  jc   Menuet_main_end
497
  jmp  Menuet_main_cycle
498
endp
499
 
500
proc @Kolibri@Delay$qui uses ebx
501
  mov  eax,5
502
  mov  ebx,[esp+8]
503
  int  0x40
504
  ret
505
endp
506
 
507
proc @Kolibri@Clock$qv uses ebx
508
  mov  eax,26
509
  mov  ebx,9
510
  int  0x40
511
  ret
512
endp
513
 
514
proc @Kolibri@GetPackedTime$qv
515
  mov  eax,3
516
  int  0x40
517
  ret
518
endp
519
 
520
proc @Kolibri@GetTime$qpi
521
  mov  eax,3
522
  int  0x40
523
  mov  edx,[esp+4]
524
  movzx ecx,al
525
  shr  ecx,4
526
  and  al,0x0F
527
  imul ecx,10
528
  add  cl,al
529
  mov  dword [edx+8],ecx
530
  mov  cl,ah
531
  shr  ecx,4
532
  and  ah,0x0F
533
  imul ecx,10
534
  add  cl,ah
535
  mov  dword [edx+4],ecx
536
  bswap eax
537
  mov  cl,ah
538
  shr  ecx,4
539
  and  ah,0x0F
540
  imul ecx,10
541
  add  cl,ah
542
  mov  dword [edx],ecx
543
  ret
544
endp
545
 
546
proc @Kolibri@GetPackedDate$qv
547
  mov  eax,29
548
  int  0x40
549
  ret
550
endp
551
 
552
proc @Kolibri@GetDate$qpi
553
  mov  eax,29
554
  int  0x40
555
  mov  edx,[esp+4]
556
  movzx ecx,al
557
  shr  ecx,4
558
  and  al,0x0F
559
  imul ecx,10
560
  add  cl,al
561
  mov  dword [edx+4],ecx
562
  mov  cl,ah
563
  shr  ecx,4
564
  and  ah,0x0F
565
  imul ecx,10
566
  add  cl,ah
567
  mov  dword [edx],ecx
568
  bswap eax
569
  mov  cl,ah
570
  shr  ecx,4
571
  and  ah,0x0F
572
  imul ecx,10
573
  add  cl,ah
574
  mov  dword [edx+8],ecx
575
  ret
576
endp
577
 
578
proc @Kolibri@ReadCommonColors$qpui uses ebx
579
  mov  eax,48
580
  mov  ebx,3
581
  mov  ecx,[esp+8]
582
  mov  edx,40
583
  int  0x40
584
  ret
585
endp
586
 
8133 IgorA 587
proc @Kolibri@DrawText$qssipxc uses ebx
588
  mov  eax,4
589
  mov  ebx,[esp+8-2]
590
  mov  bx,[esp+12]
591
  mov  ecx,[esp+16]
592
  or   ecx,0x80000000
593
  mov  edx,[esp+20]
594
  int  0x40
595
  ret
596
endp
597
 
8129 IgorA 598
proc @Kolibri@GetProcessInfo$qpuipct1t1piui uses ebx esi edi
599
  sub  esp,1024
600
  mov  eax,9
601
  mov  ebx,esp
602
  mov  ecx,[1024+12+24+esp]
603
  int  0x40
604
  xor  edi,edi
605
  or   edi,[1024+12+4+esp]
606
  jz   .get_proc_info_no_usecpu
607
  mov  ecx,[esp]
608
  mov  [edi],ecx
609
  xor  edi,edi
610
.get_proc_info_no_usecpu:
611
  or   edi,[1024+12+8+esp]
612
  jz   .get_proc_info_no_name
613
  lea  esi,[esp+10]
614
  cld
615
  movs dword [edi],[esi]
616
  movs dword [edi],[esi]
617
  movs dword [edi],[esi]
618
  mov  byte [edi],0
619
  xor  edi,edi
620
.get_proc_info_no_name:
621
  or   edi,[1024+12+12+esp]
622
  jz   .get_proc_info_no_mem
623
  mov  ecx,[esp+26]
624
  mov  [edi],ecx
625
  xor  edi,edi
626
.get_proc_info_no_mem:
627
  or   edi,[1024+12+16+esp]
628
  jz   .get_proc_info_no_pid
629
  mov  ecx,[esp+30]
630
  mov  [edi],ecx
631
  xor  edi,edi
632
.get_proc_info_no_pid:
633
  or   edi,[1024+12+20+esp]
634
  jz   .get_proc_info_no_rect
635
  lea  esi,[esp+34]
636
  cld
637
  movs dword [edi],[esi]
638
  movs dword [edi],[esi]
639
  movs dword [edi],[esi]
640
  movs dword [edi],[esi]
641
  xor  edi,edi
642
.get_proc_info_no_rect:
643
  add  esp,1024
644
  ret
645
endp
646
 
647
proc @Kolibri@GetPid$qv uses ebx
648
  sub  esp,1024
649
  mov  eax,9
650
  mov  ebx,esp
651
  mov  ecx,-1
652
  int  0x40
653
  mov  eax,[esp+30]
654
  add  esp,1024
655
  ret
656
endp
657
 
658
proc @Kolibri@GetPid$qppv
659
  mov  ecx,[esp+4]
8133 IgorA 660
  mov  eax,[ecx+KOLIBRI_THREAD_DATA_PID*4]
8129 IgorA 661
  ret
662
endp
663
 
664
proc @Kolibri@_HashByte$qui
665
@Kolibri@_HashWord$qui:
666
@Kolibri@_HashDword$qui:
667
  mov  eax,[esp+4]
668
Menuet_HashInt:
669
  mul  dword [Menuet_hash_int_val0]
670
  xor  eax,edx
671
  bswap eax
672
  mul  dword [Menuet_hash_int_val1]
673
  shrd eax,edx,14
674
  bswap eax
675
  lea  eax,[eax+4*eax]
676
  ror  eax,9
677
  ret
678
endp
679
 
680
Menuet_hash_int_val0:
681
  dd   0xA82F94C5
682
Menuet_hash_int_val1:
683
  dd   0x9193780B
684
 
685
proc @Kolibri@GetThreadData$qv
686
  call @Kolibri@GetPid$qv
687
  push eax
688
  call @Kolibri@GetThreadData$qui
689
  pop  ecx
690
  ret
691
endp
692
 
693
proc @Kolibri@GetThreadData$qui
694
  mov  eax,[esp+4]
695
  call Menuet_HashInt
696
  movzx eax,al
697
  cmp  dword [@Kolibri@_ThreadScanCount+4],0
698
  jnz  .get_thread_data_wait
699
.get_thread_data_nowait:
700
  lock inc dword [@Kolibri@_ThreadScanCount]
701
  mov  eax,dword [@Kolibri@_ThreadTable+eax*4]
702
  mov  ecx,[esp+4]
703
  jmp  .get_thread_data_test
704
.get_thread_data_loop:
8133 IgorA 705
  mov  eax,dword [eax+KOLIBRI_THREAD_DATA_NEXT*4]
8129 IgorA 706
.get_thread_data_test:
707
  test eax,eax
708
  jz   .get_thread_data_end
8133 IgorA 709
  cmp  ecx,[eax+KOLIBRI_THREAD_DATA_PID*4]
8129 IgorA 710
  jnz  .get_thread_data_loop
711
.get_thread_data_end:
712
  lock dec dword [@Kolibri@_ThreadScanCount]
713
  ret
714
.get_thread_data_wait:
715
  push eax ebx
716
  mov  eax,5
717
  mov  ebx,1
718
.get_thread_data_wait_loop:
719
  int  0x40
720
  cmp  dword [@Kolibri@_ThreadScanCount+4],0
721
  jz   .get_thread_data_wait_end
722
  shl  ebx,1
723
  cmp  ebx,MENUET_MUTEX_MAX_TIME_WAIT
724
  jna  .get_thread_data_wait_loop
725
  mov  ebx,MENUET_MUTEX_MAX_TIME_WAIT
726
  jmp  .get_thread_data_wait_loop
727
.get_thread_data_wait_end:
728
  pop  ebx eax
729
  jmp .get_thread_data_nowait
730
endp
731
 
732
proc @Kolibri@_GetSkinHeader$qv uses ebx
733
  mov  eax,48
734
  mov  ebx,4
735
  int  0x40
736
  ret
737
endp
738
 
739
proc @Kolibri@GetScreenSize$qrust1
740
  mov  eax,14
741
  int  0x40
742
  mov  ecx,[esp+8]
743
  mov  word [ecx],ax
744
  mov  ecx,[esp+4]
745
  shr  eax,16
746
  mov  word [ecx],ax
747
  ret
748
endp
749
 
750
proc Menuet_MutexLockNoWait
751
  pop  eax
752
  xor  al,al
753
  ret
754
endp
755
 
756
proc Menuet_MutexLockWait uses ebx
757
  mov  eax,5
758
  xor  ebx,ebx
759
.lock_wait_cycle:
760
  int  0x40
761
  shl  byte [ecx],1
762
  jz   .lock_wait_cycle
763
  mov  al,1
764
  ret
765
endp
766
 
767
proc Menuet_MutexLockWaitTime
768
  cmp  dword [esp+12],0
769
  jng  .MutexLockWait
770
  push ebx edx
771
  mov  edx,[esp+20]
772
  mov  eax,26
773
  mov  ebx,9
774
  int  0x40
775
  add  edx,eax
776
.lock_wait_time_cycle:
777
  mov  eax,5
778
  xor  ebx,ebx
779
  int  0x40
780
  shl  byte [ecx],1
781
  jnz  .lock_wait_time_ret_true
782
  mov  eax,26
783
  mov  ebx,9
784
  int  0x40
785
  cmp  eax,edx
786
  js   .lock_wait_time_cycle
787
  pop  edx ebx eax
788
  xor  al,al
789
  ret
790
.lock_wait_time_ret_true:
791
  pop  edx ebx
792
  mov  al,1
793
  ret
794
endp
795
 
796
proc Menuet_MutexLock
797
  shl  byte [ecx],1
798
  jnz  .lock_first
799
  call eax
800
.lock_first:
801
  mov  al,1
802
  ret
803
endp
804
 
805
proc @Kolibri@TryLock$qp14Kolibri@TMutex
806
  mov  eax,Menuet_MutexLockNoWait
807
  mov  ecx,[esp+4]
808
  jmp  Menuet_MutexLock
809
endp
810
 
811
proc @Kolibri@Lock$qp14Kolibri@TMutex
812
  mov  eax,Menuet_MutexLockWait
813
  mov  ecx,[esp+4]
814
  jmp  Menuet_MutexLock
815
endp
816
 
817
proc @Kolibri@LockTime$qp14Kolibri@TMutexi
818
  mov  eax,Menuet_MutexLockWaitTime
819
  mov  ecx,[esp+4]
820
  jmp  Menuet_MutexLock
821
endp
822
 
823
proc @Kolibri@UnLock$qp14Kolibri@TMutex
824
  mov  ecx,[esp+4]
825
  shr  byte [ecx],1
826
  jz   .unlock_pause
827
  ret
828
.unlock_pause:
829
  mov  byte [ecx],0x40
830
  push ebx
831
  mov  eax,5
832
  xor  ebx,ebx
833
  int  0x40
834
  pop  ebx
835
  ret
836
endp
837
 
838
proc Menuet_MutexLockRec
839
  shl  byte [ecx],1
840
  jng  .lock_first
841
  cmp  dword [ecx+4],edx
842
  jz   .lock_rec_self
843
  call eax
844
.lock_rec_first:
845
  mov  al,1
846
  mov  dword [ecx+4],edx
847
  ret
848
.lock_rec_self:
849
  mov  al,1
850
  add  dword [ecx],0x100
851
  jc   .lock_rec_overflow
852
  ret
853
.lock_rec_overflow:
854
  push dword [@Kolibri@DebugPrefix]
855
  call @Kolibri@DebugPutString$qpxc
856
  mov  dword [esp],Menuet_try_lock_rec_overflow_string
857
  call @Kolibri@DebugPutString$qpxc
858
  pop  ecx
859
  jmp  @Kolibri@Abort$qv
860
endp
861
 
862
proc @Kolibri@TryLock$qp16Kolibri@TRecMutexui
863
  mov  eax,Menuet_MutexLockNoWait
864
  mov  ecx,[esp+4]
865
  mov  edx,[esp+8]
866
  jmp  Menuet_MutexLockRec
867
endp
868
 
869
proc @Kolibri@Lock$qp16Kolibri@TRecMutexui
870
  mov  eax,Menuet_MutexLockWait
871
  mov  ecx,[esp+4]
872
  mov  edx,[esp+8]
873
  jmp  Menuet_MutexLockRec
874
endp
875
 
876
proc @Kolibri@LockTime$qp16Kolibri@TRecMutexiui
877
  mov  eax,Menuet_MutexLockWaitTime
878
  mov  ecx,[esp+4]
879
  mov  edx,[esp+12]
880
  jmp  Menuet_MutexLockRec
881
endp
882
 
883
proc @Kolibri@UnLock$qp16Kolibri@TRecMutexui
884
  mov  ecx,[esp+4]
885
  mov  edx,[esp+8]
886
  cmp  dword [ecx+4],edx
887
  jnz  .unlock_rec_notlocked
888
  sub  dword [ecx],0x100
889
  jnc  .unlock_rec_end
890
  add dword [ecx],0x100
891
  shl byte [ecx],1
892
  shr byte [ecx],2
893
  jng  .unlock_rec_pause
894
.unlock_rec_end:
895
  ret
896
.unlock_rec_pause:
897
  mov  byte [ecx],0x20
898
  push ebx
899
  mov  eax,5
900
  xor  ebx,ebx
901
  int  0x40
902
  pop  ebx
903
  ret
904
.unlock_rec_notlocked:
905
  push dword [@Kolibri@DebugPrefix]
906
  call @Kolibri@DebugPutString$qpxc
907
  mov  dword [esp],Menuet_unlock_rec_notlocked_string
908
  call @Kolibri@DebugPutString$qpxc
909
  pop  ecx
910
  jmp  @Kolibri@Abort$qv
911
endp
912
 
913
proc @Kolibri@DebugPutChar$qc
914
  mov  cl,byte [esp+4]
915
  cmp  cl,13
916
  jz   .debug_put_char_ret
917
  push ebx
918
  cmp  cl,10
919
  jz   .debug_put_char_enter
920
.debug_put_char_after_cmp:
921
  mov  eax,63
922
  mov  ebx,1
923
  int  0x40
924
  pop  ebx
925
.debug_put_char_ret:
926
  ret
927
.debug_put_char_enter:
928
  mov  cl,13
929
  mov  eax,63
930
  mov  ebx,1
931
  int  0x40
932
  mov  cl,10
933
  jmp  .debug_put_char_after_cmp
934
endp
935
 
936
proc @Kolibri@DebugPutString$qpxc
937
  push esi
938
  push dword 0
939
  mov  esi,dword [esp+12]
940
  jmp  .debug_put_string_test
941
.debug_put_string_loop:
942
  mov  dword [esp],eax
943
  call @Kolibri@DebugPutChar$qc
944
  inc  esi
945
.debug_put_string_test:
946
  xor  eax,eax
947
  or   al,[esi]
948
  test al,al
949
  jnz  .debug_put_string_loop
950
  pop  ecx esi
951
  ret
952
endp
953
 
954
proc @Kolibri@GetKey$qv
955
  mov  eax,2
956
  int  0x40
957
  test al,al
958
  jnz  .get_key_eof
959
  movzx eax,ah
960
  ret
961
.get_key_eof:
962
  mov  eax,-1
963
  ret
964
endp
965
 
966
proc @Kolibri@GetMouseButton$qv uses ebx
967
  mov  eax,37
968
  mov  ebx,2
969
  int  0x40
970
  ret
971
endp
972
 
973
proc @Kolibri@GetMousePosition$qrst1o uses ebx
974
  mov  eax,37
975
  xor  ebx,ebx
976
  cmp  byte [esp+16],0
977
  jnz  .get_mouse_pos_absolute
978
  inc  ebx
979
.get_mouse_pos_absolute:
980
  int  0x40
981
  mov  ecx,[esp+12]
982
  mov  word [ecx],ax
983
  mov  ecx,[esp+8]
984
  shr  eax,16
985
  mov  word [ecx],ax
986
  ret
987
endp
988
 
989
proc @Kolibri@WasThreadCreated$qv
990
  cmp  byte [@Kolibri@_ThreadSavedBegProc],0x90
991
  setz al
992
  ret
993
endp
994
 
995
proc @Kolibri@CreateThread$qpvuit1
996
  push ebx
997
  mov  edx,[esp+16]
998
  mov  ebx,[esp+12]
999
  test edx,edx
1000
  jnz  .create_thread_after_new
1001
if defined MenuetHeapAlloc
1002
  cmp  ebx,4096
1003
  jnb  .create_thread_alloc
1004
  mov  ebx,STACKSIZE
1005
.create_thread_alloc:
1006
  push ebx
1007
  call MenuetHeapAlloc	 ; Create new dynamic memory of the given size
1008
  pop  ecx
1009
  test eax,eax
1010
  jnz  .create_thread_mem_created
1011
end if
1012
  or   eax,-1
1013
  jmp  .create_thread_end
1014
.create_thread_mem_created:
1015
  lea  edx,[eax+ebx]
1016
.create_thread_after_new:
1017
  neg  ebx
1018
  jz   .create_thread_test_first
1019
  add  ebx,edx
1020
.create_thread_test_first:
1021
  cmp  byte [@Kolibri@_ThreadSavedBegProc],0x90
1022
  jnz  .create_thread_init
1023
.create_thread_fill_stack:
1024
  lock inc dword [@Kolibri@_ThreadNumber]
1025
  and  edx,not 3
1026
  sub  edx,12
1027
  mov  ecx,[esp+8]
1028
  mov  dword [edx+8],ebx
1029
  mov  dword [edx+4],ecx
1030
  mov  dword [edx],Menuet_ThreadFinish
1031
  mov  eax,51
1032
  mov  ebx,1
1033
  mov  ecx,@Kolibri@ThreadMain$qpvt1
1034
  int  0x40
1035
  mov  ebx,eax
1036
  or   bl,15
1037
  inc  ebx
1038
  jnz  .create_thread_end
1039
  lock dec dword [@Kolibri@_ThreadNumber]
1040
if defined MenuetHeapFree
1041
  or   ebx,[edx+8]
1042
  jz   .create_thread_end
1043
  push ebx
1044
  call MenuetHeapFree	; Delete the given dynamic memory
1045
  pop  ecx
1046
end if
1047
.create_thread_end:
1048
  pop  ebx
1049
  ret
1050
.create_thread_init:
1051
  push esi edi
1052
  cld
1053
  mov  esi,@Kolibri@_ThreadSavedBegProc
1054
  mov  edi,@Kolibri@GetPid$qv
1055
  movs dword [edi],[esi]
1056
  movs dword [edi],[esi]
1057
  mov  edi,@Kolibri@GetThreadData$qv
1058
  movs dword [edi],[esi]
1059
  movs dword [edi],[esi]
1060
  mov  eax,0x90909090
1061
  mov  edi,@Kolibri@_ThreadSavedBegProc
1062
  stos dword [edi]
1063
  stos dword [edi]
1064
  stos dword [edi]
1065
  stos dword [edi]
1066
  pop  edi esi
1067
  jmp  .create_thread_fill_stack
1068
endp
1069
 
1070
proc @Kolibri@_FileAccess$qpv uses ebx
1071
  mov  eax,70
1072
  mov  ebx,[esp+8]
1073
  int  0x40
1074
  mov  ecx,[esp+8]
1075
  mov  [ecx],ebx
1076
  ret
1077
endp
1078
 
1079
Menuet_abort_string:
1080
  db 'Abnormal program termination.',10,0
1081
Menuet_try_lock_rec_overflow_string:
1082
  db 'Recursive mutex lock count overflow.',10,0
1083
Menuet_unlock_rec_notlocked_string:
1084
  db 'Recursive mutex unlock error.',10,0
1085
 
1086
include "kos_lib.inc"
1087
 
1088
;/**/
1089