Subversion Repositories Kolibri OS

Rev

Rev 8133 | Go to most recent revision | Details | 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
7
MENUET_THREAD_DATA_USER     = 0; // Thread data begin from the user dword
8
;const int
9
MENUET_THREAD_DATA_ST_BEGIN = 1; // Stack beginning follows after the user dword
10
;const int
11
MENUET_THREAD_DATA_NEXT     = 2;
12
;const int
13
MENUET_THREAD_DATA_PID	    = 3;
14
;const int
15
MENUET_THREAD_DATA_FLAG     = 4;
16
;const int
17
MENUET_THREAD_DATA_X	    = 5;
18
;const int
19
MENUET_THREAD_DATA_Y	    = 6;
20
;const int
21
MENUET_THREAD_DATA_C_WINDOW = 7;
22
;const int
23
MENUET_THREAD_DATA_C_HEADER = 8;
24
;const int
25
MENUET_THREAD_DATA_C_BORDER = 9;
26
;const int
27
MENUET_THREAD_DATA_C_TITLE  = 10;
28
;const int
29
MENUET_THREAD_DATA_TITLE    = 11;
30
;const int
31
MENUET_THREAD_DATA_PICTURE  = 12;
32
;const int
33
MENUET_THREAD_DATA_SZ_PICT  = 13;
34
;const int
35
MENUET_THREAD_DATA_LAST_SX  = 14;
36
;const int
37
MENUET_THREAD_DATA_LAST_SY  = 15;
38
;const int
39
MENUET_THREAD_DATA_LEN	    = 16;
40
 
41
;const int
42
MENUET_MUTEX_MAX_TIME_WAIT  = 20;
43
 
44
;const int
45
MENUET_FILE_BLOCK_SIZE	    = 512;
46
 
47
;const int
48
MENUET_FILE_MEMORY_OS_NEED  = 4096;
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
142
  sub  esp,MENUET_THREAD_DATA_LEN*4
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:
168
  btr  dword [esp+MENUET_THREAD_DATA_FLAG*4],31
169
  push esp
170
  call @@MenuetOnClose$qppv
171
  pop  ecx
172
  test al,al
173
  jnz  .main_end
174
.main_test_close_first:
175
  cmp  dword [esp+MENUET_THREAD_DATA_FLAG*4],0
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:
182
  or   dword [esp+MENUET_THREAD_DATA_FLAG*4],3
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
193
  cmp  ecx,[esp+MENUET_THREAD_DATA_LAST_SX*4]
194
  jnz  .main_size
195
  cmp  edx,[esp+MENUET_THREAD_DATA_LAST_SY*4]
196
  jz   .main_paint
197
.main_size:
198
  mov  [esp+MENUET_THREAD_DATA_LAST_SX*4],ecx
199
  mov  [esp+MENUET_THREAD_DATA_LAST_SY*4],edx
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
208
  call @@MenuetOnSize$qpippv
209
  add  esp,24
210
  test dword [esp+MENUET_THREAD_DATA_FLAG*4],3
211
  jz   .main_cycle
212
.main_paint:
213
  cmp  dword [esp+MENUET_THREAD_DATA_FLAG*4],0
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:
222
  cmp  dword [esp+MENUET_THREAD_DATA_FLAG*4],0
223
  jl   .main_close
224
  int  0x40
225
  test eax,eax
226
  jnz  .main_on_message
227
  cmp  dword [esp+MENUET_THREAD_DATA_FLAG*4],0
228
  jne  .main_paint
229
  push esp
230
  call @@MenuetOnIdle$qppv
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
243
  call @@MenuetOnKeyPress$qppv
244
  pop  ecx
245
  jmp  .main_cycle
246
.main_mouse:
247
  push esp
248
  call @@MenuetOnMouse$qppv
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:
266
  btr  dword [esp+MENUET_THREAD_DATA_FLAG*4],31
267
  push esp
268
  call @@MenuetOnClose$qppv
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]
307
  add  esp,MENUET_THREAD_DATA_LEN*4
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]
327
  mov  edx,[ebp+MENUET_THREAD_DATA_FLAG*4]
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
336
  mov  [ebp+MENUET_THREAD_DATA_FLAG*4],edx
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
346
  and  dword [ebp+MENUET_THREAD_DATA_FLAG*4],0xFFFFFFFC
347
  test dl,2
348
  jz   .redraw_picture
349
  mov  eax,12
350
  mov  ebx,1
351
  int  0x40
352
  xor  eax,eax
353
  mov  ebx,[ebp+MENUET_THREAD_DATA_X*4]
354
  mov  ecx,[ebp+MENUET_THREAD_DATA_Y*4]
355
  mov  edx,[ebp+MENUET_THREAD_DATA_C_WINDOW*4]
356
  mov  esi,[ebp+MENUET_THREAD_DATA_C_HEADER*4]
357
  mov  edi,[ebp+MENUET_THREAD_DATA_C_BORDER*4]
358
  int  0x40
359
  mov  edx,[ebp+MENUET_THREAD_DATA_TITLE*4]
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
373
  mov  ecx,[ebp+MENUET_THREAD_DATA_C_TITLE*4]
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
383
  mov  esi,[ebp+MENUET_THREAD_DATA_PICTURE*4]
384
  test esi,esi
385
  jz   .redraw_end_draw
386
  mov  ecx,[ebp+MENUET_THREAD_DATA_SZ_PICT*4]
387
  jecxz .redraw_end_draw
388
  mov  al,byte [ebp+MENUET_THREAD_DATA_C_WINDOW*4+3]
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:
451
  mov  eax,dword [eax+MENUET_THREAD_DATA_NEXT*4]
452
.exit_process_test:
453
  test eax,eax
454
  jz   .exit_process_continue
455
  cmp  ebx,[eax+MENUET_THREAD_DATA_PID*4]
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]
495
  bt   dword [esp+MENUET_THREAD_DATA_FLAG*4],30
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
 
587
proc @Kolibri@GetProcessInfo$qpuipct1t1piui uses ebx esi edi
588
  sub  esp,1024
589
  mov  eax,9
590
  mov  ebx,esp
591
  mov  ecx,[1024+12+24+esp]
592
  int  0x40
593
  xor  edi,edi
594
  or   edi,[1024+12+4+esp]
595
  jz   .get_proc_info_no_usecpu
596
  mov  ecx,[esp]
597
  mov  [edi],ecx
598
  xor  edi,edi
599
.get_proc_info_no_usecpu:
600
  or   edi,[1024+12+8+esp]
601
  jz   .get_proc_info_no_name
602
  lea  esi,[esp+10]
603
  cld
604
  movs dword [edi],[esi]
605
  movs dword [edi],[esi]
606
  movs dword [edi],[esi]
607
  mov  byte [edi],0
608
  xor  edi,edi
609
.get_proc_info_no_name:
610
  or   edi,[1024+12+12+esp]
611
  jz   .get_proc_info_no_mem
612
  mov  ecx,[esp+26]
613
  mov  [edi],ecx
614
  xor  edi,edi
615
.get_proc_info_no_mem:
616
  or   edi,[1024+12+16+esp]
617
  jz   .get_proc_info_no_pid
618
  mov  ecx,[esp+30]
619
  mov  [edi],ecx
620
  xor  edi,edi
621
.get_proc_info_no_pid:
622
  or   edi,[1024+12+20+esp]
623
  jz   .get_proc_info_no_rect
624
  lea  esi,[esp+34]
625
  cld
626
  movs dword [edi],[esi]
627
  movs dword [edi],[esi]
628
  movs dword [edi],[esi]
629
  movs dword [edi],[esi]
630
  xor  edi,edi
631
.get_proc_info_no_rect:
632
  add  esp,1024
633
  ret
634
endp
635
 
636
proc @Kolibri@GetPid$qv uses ebx
637
  sub  esp,1024
638
  mov  eax,9
639
  mov  ebx,esp
640
  mov  ecx,-1
641
  int  0x40
642
  mov  eax,[esp+30]
643
  add  esp,1024
644
  ret
645
endp
646
 
647
proc @Kolibri@GetPid$qppv
648
  mov  ecx,[esp+4]
649
  mov  eax,[ecx+MENUET_THREAD_DATA_PID*4]
650
  ret
651
endp
652
 
653
proc @Kolibri@_HashByte$qui
654
@Kolibri@_HashWord$qui:
655
@Kolibri@_HashDword$qui:
656
  mov  eax,[esp+4]
657
Menuet_HashInt:
658
  mul  dword [Menuet_hash_int_val0]
659
  xor  eax,edx
660
  bswap eax
661
  mul  dword [Menuet_hash_int_val1]
662
  shrd eax,edx,14
663
  bswap eax
664
  lea  eax,[eax+4*eax]
665
  ror  eax,9
666
  ret
667
endp
668
 
669
Menuet_hash_int_val0:
670
  dd   0xA82F94C5
671
Menuet_hash_int_val1:
672
  dd   0x9193780B
673
 
674
proc @Kolibri@GetThreadData$qv
675
  call @Kolibri@GetPid$qv
676
  push eax
677
  call @Kolibri@GetThreadData$qui
678
  pop  ecx
679
  ret
680
endp
681
 
682
proc @Kolibri@GetThreadData$qui
683
  mov  eax,[esp+4]
684
  call Menuet_HashInt
685
  movzx eax,al
686
  cmp  dword [@Kolibri@_ThreadScanCount+4],0
687
  jnz  .get_thread_data_wait
688
.get_thread_data_nowait:
689
  lock inc dword [@Kolibri@_ThreadScanCount]
690
  mov  eax,dword [@Kolibri@_ThreadTable+eax*4]
691
  mov  ecx,[esp+4]
692
  jmp  .get_thread_data_test
693
.get_thread_data_loop:
694
  mov  eax,dword [eax+MENUET_THREAD_DATA_NEXT*4]
695
.get_thread_data_test:
696
  test eax,eax
697
  jz   .get_thread_data_end
698
  cmp  ecx,[eax+MENUET_THREAD_DATA_PID*4]
699
  jnz  .get_thread_data_loop
700
.get_thread_data_end:
701
  lock dec dword [@Kolibri@_ThreadScanCount]
702
  ret
703
.get_thread_data_wait:
704
  push eax ebx
705
  mov  eax,5
706
  mov  ebx,1
707
.get_thread_data_wait_loop:
708
  int  0x40
709
  cmp  dword [@Kolibri@_ThreadScanCount+4],0
710
  jz   .get_thread_data_wait_end
711
  shl  ebx,1
712
  cmp  ebx,MENUET_MUTEX_MAX_TIME_WAIT
713
  jna  .get_thread_data_wait_loop
714
  mov  ebx,MENUET_MUTEX_MAX_TIME_WAIT
715
  jmp  .get_thread_data_wait_loop
716
.get_thread_data_wait_end:
717
  pop  ebx eax
718
  jmp .get_thread_data_nowait
719
endp
720
 
721
proc @Kolibri@_GetSkinHeader$qv uses ebx
722
  mov  eax,48
723
  mov  ebx,4
724
  int  0x40
725
  ret
726
endp
727
 
728
proc @Kolibri@GetScreenSize$qrust1
729
  mov  eax,14
730
  int  0x40
731
  mov  ecx,[esp+8]
732
  mov  word [ecx],ax
733
  mov  ecx,[esp+4]
734
  shr  eax,16
735
  mov  word [ecx],ax
736
  ret
737
endp
738
 
739
proc Menuet_MutexLockNoWait
740
  pop  eax
741
  xor  al,al
742
  ret
743
endp
744
 
745
proc Menuet_MutexLockWait uses ebx
746
  mov  eax,5
747
  xor  ebx,ebx
748
.lock_wait_cycle:
749
  int  0x40
750
  shl  byte [ecx],1
751
  jz   .lock_wait_cycle
752
  mov  al,1
753
  ret
754
endp
755
 
756
proc Menuet_MutexLockWaitTime
757
  cmp  dword [esp+12],0
758
  jng  .MutexLockWait
759
  push ebx edx
760
  mov  edx,[esp+20]
761
  mov  eax,26
762
  mov  ebx,9
763
  int  0x40
764
  add  edx,eax
765
.lock_wait_time_cycle:
766
  mov  eax,5
767
  xor  ebx,ebx
768
  int  0x40
769
  shl  byte [ecx],1
770
  jnz  .lock_wait_time_ret_true
771
  mov  eax,26
772
  mov  ebx,9
773
  int  0x40
774
  cmp  eax,edx
775
  js   .lock_wait_time_cycle
776
  pop  edx ebx eax
777
  xor  al,al
778
  ret
779
.lock_wait_time_ret_true:
780
  pop  edx ebx
781
  mov  al,1
782
  ret
783
endp
784
 
785
proc Menuet_MutexLock
786
  shl  byte [ecx],1
787
  jnz  .lock_first
788
  call eax
789
.lock_first:
790
  mov  al,1
791
  ret
792
endp
793
 
794
proc @Kolibri@TryLock$qp14Kolibri@TMutex
795
  mov  eax,Menuet_MutexLockNoWait
796
  mov  ecx,[esp+4]
797
  jmp  Menuet_MutexLock
798
endp
799
 
800
proc @Kolibri@Lock$qp14Kolibri@TMutex
801
  mov  eax,Menuet_MutexLockWait
802
  mov  ecx,[esp+4]
803
  jmp  Menuet_MutexLock
804
endp
805
 
806
proc @Kolibri@LockTime$qp14Kolibri@TMutexi
807
  mov  eax,Menuet_MutexLockWaitTime
808
  mov  ecx,[esp+4]
809
  jmp  Menuet_MutexLock
810
endp
811
 
812
proc @Kolibri@UnLock$qp14Kolibri@TMutex
813
  mov  ecx,[esp+4]
814
  shr  byte [ecx],1
815
  jz   .unlock_pause
816
  ret
817
.unlock_pause:
818
  mov  byte [ecx],0x40
819
  push ebx
820
  mov  eax,5
821
  xor  ebx,ebx
822
  int  0x40
823
  pop  ebx
824
  ret
825
endp
826
 
827
proc Menuet_MutexLockRec
828
  shl  byte [ecx],1
829
  jng  .lock_first
830
  cmp  dword [ecx+4],edx
831
  jz   .lock_rec_self
832
  call eax
833
.lock_rec_first:
834
  mov  al,1
835
  mov  dword [ecx+4],edx
836
  ret
837
.lock_rec_self:
838
  mov  al,1
839
  add  dword [ecx],0x100
840
  jc   .lock_rec_overflow
841
  ret
842
.lock_rec_overflow:
843
  push dword [@Kolibri@DebugPrefix]
844
  call @Kolibri@DebugPutString$qpxc
845
  mov  dword [esp],Menuet_try_lock_rec_overflow_string
846
  call @Kolibri@DebugPutString$qpxc
847
  pop  ecx
848
  jmp  @Kolibri@Abort$qv
849
endp
850
 
851
proc @Kolibri@TryLock$qp16Kolibri@TRecMutexui
852
  mov  eax,Menuet_MutexLockNoWait
853
  mov  ecx,[esp+4]
854
  mov  edx,[esp+8]
855
  jmp  Menuet_MutexLockRec
856
endp
857
 
858
proc @Kolibri@Lock$qp16Kolibri@TRecMutexui
859
  mov  eax,Menuet_MutexLockWait
860
  mov  ecx,[esp+4]
861
  mov  edx,[esp+8]
862
  jmp  Menuet_MutexLockRec
863
endp
864
 
865
proc @Kolibri@LockTime$qp16Kolibri@TRecMutexiui
866
  mov  eax,Menuet_MutexLockWaitTime
867
  mov  ecx,[esp+4]
868
  mov  edx,[esp+12]
869
  jmp  Menuet_MutexLockRec
870
endp
871
 
872
proc @Kolibri@UnLock$qp16Kolibri@TRecMutexui
873
  mov  ecx,[esp+4]
874
  mov  edx,[esp+8]
875
  cmp  dword [ecx+4],edx
876
  jnz  .unlock_rec_notlocked
877
  sub  dword [ecx],0x100
878
  jnc  .unlock_rec_end
879
  add dword [ecx],0x100
880
  shl byte [ecx],1
881
  shr byte [ecx],2
882
  jng  .unlock_rec_pause
883
.unlock_rec_end:
884
  ret
885
.unlock_rec_pause:
886
  mov  byte [ecx],0x20
887
  push ebx
888
  mov  eax,5
889
  xor  ebx,ebx
890
  int  0x40
891
  pop  ebx
892
  ret
893
.unlock_rec_notlocked:
894
  push dword [@Kolibri@DebugPrefix]
895
  call @Kolibri@DebugPutString$qpxc
896
  mov  dword [esp],Menuet_unlock_rec_notlocked_string
897
  call @Kolibri@DebugPutString$qpxc
898
  pop  ecx
899
  jmp  @Kolibri@Abort$qv
900
endp
901
 
902
proc @Kolibri@DebugPutChar$qc
903
  mov  cl,byte [esp+4]
904
  cmp  cl,13
905
  jz   .debug_put_char_ret
906
  push ebx
907
  cmp  cl,10
908
  jz   .debug_put_char_enter
909
.debug_put_char_after_cmp:
910
  mov  eax,63
911
  mov  ebx,1
912
  int  0x40
913
  pop  ebx
914
.debug_put_char_ret:
915
  ret
916
.debug_put_char_enter:
917
  mov  cl,13
918
  mov  eax,63
919
  mov  ebx,1
920
  int  0x40
921
  mov  cl,10
922
  jmp  .debug_put_char_after_cmp
923
endp
924
 
925
proc @Kolibri@DebugPutString$qpxc
926
  push esi
927
  push dword 0
928
  mov  esi,dword [esp+12]
929
  jmp  .debug_put_string_test
930
.debug_put_string_loop:
931
  mov  dword [esp],eax
932
  call @Kolibri@DebugPutChar$qc
933
  inc  esi
934
.debug_put_string_test:
935
  xor  eax,eax
936
  or   al,[esi]
937
  test al,al
938
  jnz  .debug_put_string_loop
939
  pop  ecx esi
940
  ret
941
endp
942
 
943
proc @Kolibri@GetKey$qv
944
  mov  eax,2
945
  int  0x40
946
  test al,al
947
  jnz  .get_key_eof
948
  movzx eax,ah
949
  ret
950
.get_key_eof:
951
  mov  eax,-1
952
  ret
953
endp
954
 
955
proc @Kolibri@GetMouseButton$qv uses ebx
956
  mov  eax,37
957
  mov  ebx,2
958
  int  0x40
959
  ret
960
endp
961
 
962
proc @Kolibri@GetMousePosition$qrst1o uses ebx
963
  mov  eax,37
964
  xor  ebx,ebx
965
  cmp  byte [esp+16],0
966
  jnz  .get_mouse_pos_absolute
967
  inc  ebx
968
.get_mouse_pos_absolute:
969
  int  0x40
970
  mov  ecx,[esp+12]
971
  mov  word [ecx],ax
972
  mov  ecx,[esp+8]
973
  shr  eax,16
974
  mov  word [ecx],ax
975
  ret
976
endp
977
 
978
proc @Kolibri@WasThreadCreated$qv
979
  cmp  byte [@Kolibri@_ThreadSavedBegProc],0x90
980
  setz al
981
  ret
982
endp
983
 
984
proc @Kolibri@CreateThread$qpvuit1
985
  push ebx
986
  mov  edx,[esp+16]
987
  mov  ebx,[esp+12]
988
  test edx,edx
989
  jnz  .create_thread_after_new
990
if defined MenuetHeapAlloc
991
  cmp  ebx,4096
992
  jnb  .create_thread_alloc
993
  mov  ebx,STACKSIZE
994
.create_thread_alloc:
995
  push ebx
996
  call MenuetHeapAlloc	 ; Create new dynamic memory of the given size
997
  pop  ecx
998
  test eax,eax
999
  jnz  .create_thread_mem_created
1000
end if
1001
  or   eax,-1
1002
  jmp  .create_thread_end
1003
.create_thread_mem_created:
1004
  lea  edx,[eax+ebx]
1005
.create_thread_after_new:
1006
  neg  ebx
1007
  jz   .create_thread_test_first
1008
  add  ebx,edx
1009
.create_thread_test_first:
1010
  cmp  byte [@Kolibri@_ThreadSavedBegProc],0x90
1011
  jnz  .create_thread_init
1012
.create_thread_fill_stack:
1013
  lock inc dword [@Kolibri@_ThreadNumber]
1014
  and  edx,not 3
1015
  sub  edx,12
1016
  mov  ecx,[esp+8]
1017
  mov  dword [edx+8],ebx
1018
  mov  dword [edx+4],ecx
1019
  mov  dword [edx],Menuet_ThreadFinish
1020
  mov  eax,51
1021
  mov  ebx,1
1022
  mov  ecx,@Kolibri@ThreadMain$qpvt1
1023
  int  0x40
1024
  mov  ebx,eax
1025
  or   bl,15
1026
  inc  ebx
1027
  jnz  .create_thread_end
1028
  lock dec dword [@Kolibri@_ThreadNumber]
1029
if defined MenuetHeapFree
1030
  or   ebx,[edx+8]
1031
  jz   .create_thread_end
1032
  push ebx
1033
  call MenuetHeapFree	; Delete the given dynamic memory
1034
  pop  ecx
1035
end if
1036
.create_thread_end:
1037
  pop  ebx
1038
  ret
1039
.create_thread_init:
1040
  push esi edi
1041
  cld
1042
  mov  esi,@Kolibri@_ThreadSavedBegProc
1043
  mov  edi,@Kolibri@GetPid$qv
1044
  movs dword [edi],[esi]
1045
  movs dword [edi],[esi]
1046
  mov  edi,@Kolibri@GetThreadData$qv
1047
  movs dword [edi],[esi]
1048
  movs dword [edi],[esi]
1049
  mov  eax,0x90909090
1050
  mov  edi,@Kolibri@_ThreadSavedBegProc
1051
  stos dword [edi]
1052
  stos dword [edi]
1053
  stos dword [edi]
1054
  stos dword [edi]
1055
  pop  edi esi
1056
  jmp  .create_thread_fill_stack
1057
endp
1058
 
1059
proc @Kolibri@_FileAccess$qpv uses ebx
1060
  mov  eax,70
1061
  mov  ebx,[esp+8]
1062
  int  0x40
1063
  mov  ecx,[esp+8]
1064
  mov  [ecx],ebx
1065
  ret
1066
endp
1067
 
1068
Menuet_abort_string:
1069
  db 'Abnormal program termination.',10,0
1070
Menuet_try_lock_rec_overflow_string:
1071
  db 'Recursive mutex lock count overflow.',10,0
1072
Menuet_unlock_rec_notlocked_string:
1073
  db 'Recursive mutex unlock error.',10,0
1074
 
1075
include "kos_lib.inc"
1076
 
1077
;/**/
1078