Subversion Repositories Kolibri OS

Rev

Rev 8153 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
8140 IgorA 1
;const int
2
KOLIBRI_BORDER_SIZE = 4;
3
;const int
4
KOLIBRI_HEADER_SIZE = 20;
5
 
6
;const int
7
KOLIBRI_THREAD_DATA_USER     = 0; // Thread data begin from the user dword
8
;const int
9
KOLIBRI_THREAD_DATA_ST_BEGIN = 1; // Stack beginning follows after the user dword
10
;const int
11
KOLIBRI_THREAD_DATA_NEXT     = 2;
12
;const int
13
KOLIBRI_THREAD_DATA_PID	    = 3;
14
;const int
15
KOLIBRI_THREAD_DATA_FLAG     = 4;
16
;const int
17
KOLIBRI_THREAD_DATA_X	    = 5;
18
;const int
19
KOLIBRI_THREAD_DATA_Y	    = 6;
20
;const int
21
KOLIBRI_THREAD_DATA_C_WINDOW = 7;
22
;const int
23
KOLIBRI_THREAD_DATA_C_HEADER = 8;
24
;const int
25
KOLIBRI_THREAD_DATA_C_BORDER = 9;
26
;const int
27
KOLIBRI_THREAD_DATA_C_TITLE  = 10;
28
;const int
29
KOLIBRI_THREAD_DATA_TITLE    = 11;
30
;const int
31
KOLIBRI_THREAD_DATA_PICTURE  = 12;
32
;const int
33
KOLIBRI_THREAD_DATA_SZ_PICT  = 13;
34
;const int
35
KOLIBRI_THREAD_DATA_LAST_SX  = 14;
36
;const int
37
KOLIBRI_THREAD_DATA_LAST_SY  = 15;
38
;const int
39
KOLIBRI_THREAD_DATA_LEN	    = 16;
40
 
41
;const int
42
KOLIBRI_MUTEX_MAX_TIME_WAIT  = 20;
43
 
44
;const int
45
KOLIBRI_FILE_BLOCK_SIZE	    = 512;
46
 
47
;const int
48
KOLIBRI_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
Kolibri_SegmentInit:
57
  else if name eq _exit_ | name eq _EXIT_
58
Kolibri_SegmentExit:
59
  end if
60
}
61
 
62
macro endseg  name
63
{
64
  if name eq _init_ | name eq _INIT_
65
Kolibri_SegmentInitEnd:
66
  else if name eq _exit_ | name eq _EXIT_
67
Kolibri_SegmentExitEnd:
68
  end if
69
  endseg  name
70
}
71
 
72
macro Kolibri_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
  Kolibri_Put_MovEaxVal_Ret  @Kolibri@GetPid$qv,edx
109
if defined KolibriHeapInit
110
  mov  ecx,esp
111
  push ebx
112
  push ecx
113
  push U_END
114
  call KolibriHeapInit	; 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 KolibriHeapFreeAndThreadFinish
127
  test eax,eax
128
  jz   .ThreadFinish_end
129
  push dword @Kolibri@_ExitProcessNow
130
  push eax
131
  call KolibriHeapFreeAndThreadFinish   ; 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,KOLIBRI_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
  Kolibri_Put_MovEaxVal_Ret  @Kolibri@GetThreadData$qv,esp
152
if defined Kolibri_SegmentInit & defined Kolibri_SegmentInitEnd
153
  push Kolibri_SegmentInitEnd
154
  push Kolibri_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+KOLIBRI_THREAD_DATA_FLAG*4],31
169
  push esp
170
  call @@KolibriOnClose$qppv
171
  pop  ecx
172
  test al,al
173
  jnz  .main_end
174
.main_test_close_first:
175
  cmp  dword [esp+KOLIBRI_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+KOLIBRI_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+KOLIBRI_THREAD_DATA_LAST_SX*4]
194
  jnz  .main_size
195
  cmp  edx,[esp+KOLIBRI_THREAD_DATA_LAST_SY*4]
196
  jz   .main_paint
197
.main_size:
198
  mov  [esp+KOLIBRI_THREAD_DATA_LAST_SX*4],ecx
199
  mov  [esp+KOLIBRI_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 @@KolibriOnSize$qpippv
209
  add  esp,24
210
  test dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],3
211
  jz   .main_cycle
212
.main_paint:
213
  cmp  dword [esp+KOLIBRI_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+KOLIBRI_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+KOLIBRI_THREAD_DATA_FLAG*4],0
228
  jne  .main_paint
229
  push esp
230
  call @@KolibriOnIdle$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 @@KolibriOnKeyPress$qppv
244
  pop  ecx
245
  jmp  .main_cycle
246
.main_mouse:
247
  push esp
248
  call @@KolibriOnMouse$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+KOLIBRI_THREAD_DATA_FLAG*4],31
267
  push esp
268
  call @@KolibriOnClose$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 Kolibri_SegmentExit & defined Kolibri_SegmentExitEnd
276
  jnz  .main_else_last_check
277
  push Kolibri_SegmentExitEnd
278
  push Kolibri_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,KOLIBRI_MUTEX_MAX_TIME_WAIT
297
  jna  .main_end_wait
298
  mov  ebx,KOLIBRI_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,KOLIBRI_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+KOLIBRI_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+KOLIBRI_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+KOLIBRI_THREAD_DATA_FLAG*4],0xFFFFFFFC
347
  mov  eax,12
348
  mov  ebx,1
349
  int  0x40
350
  test dl,2
351
  jz   .redraw_picture
352
  mov  eax,48
353
  mov  ebx,4
354
  int  0x40
355
  mov  ebx,[ebp+KOLIBRI_THREAD_DATA_X*4]
356
  add  ebx,2*5-1
357
  mov  ecx,[ebp+KOLIBRI_THREAD_DATA_Y*4]
358
  add  cx,ax
359
  add  ecx,5-1
360
  mov  edx,[ebp+KOLIBRI_THREAD_DATA_C_WINDOW*4]
361
  mov  edi,[ebp+KOLIBRI_THREAD_DATA_TITLE*4]
362
  xor  eax,eax
363
  int  0x40
364
.redraw_picture:
365
  call	@@KolibriOnPaint$qv
366
.redraw_end_draw:
367
  mov  eax,12
368
  mov  ebx,2
369
  int  0x40
370
  pop  edi esi ebx ebp
371
  ret
372
endp
373
 
374
proc @Kolibri@MoveWindow$qxpxi uses ebx esi
375
  mov  eax,[esp+12]
376
  mov  ebx,[eax]
377
  mov  ecx,[eax+4]
378
  mov  edx,[eax+8]
379
  mov  esi,[eax+12]
380
  mov  eax,67
381
  int  0x40
382
  ret
383
endp
384
 
385
;proc @Kolibri@Abort$qv
386
;  push dword [@Kolibri@DebugPrefix]
387
;  call @Kolibri@DebugPutString$qpxc
388
;  mov	dword [esp],Kolibri_abort_string
389
;  call @Kolibri@DebugPutString$qpxc
390
;  pop	ecx
391
proc @Kolibri@ExitProcess$qv
392
  lock bts dword [@Kolibri@_ExitProcessNow],0
393
  jc   .exit_process_wait
394
  sub  esp,1024
395
  mov  eax,9
396
  mov  ebx,esp
397
  mov  ecx,-1
398
  int  0x40
399
  mov  esi,eax
400
  mov  edi,[esp+30]
401
.exit_process_loop:
402
  mov  eax,9
403
  mov  ebx,esp
404
  mov  ecx,esi
405
  int  0x40
406
  mov  eax,[esp+30]
407
  cmp  eax,edi
408
  jz   .exit_process_continue
409
  mov  ebx,eax
410
  or   bl,15
411
  inc  ebx
412
  jz   .exit_process_continue
413
  mov  ebx,eax
414
  call Kolibri_HashInt
415
  movzx eax,al
416
  mov  eax,dword [@Kolibri@_ThreadTable+eax*4]
417
  jmp  .exit_process_test
418
.exit_process_next:
419
  mov  eax,dword [eax+KOLIBRI_THREAD_DATA_NEXT*4]
420
.exit_process_test:
421
  test eax,eax
422
  jz   .exit_process_continue
423
  cmp  ebx,[eax+KOLIBRI_THREAD_DATA_PID*4]
424
  jnz  .exit_process_next
425
  mov  eax,18
426
  mov  ebx,2
427
  mov  ecx,esi
428
  int  0x40
429
.exit_process_continue:
430
  dec  esi
431
  jnl  .exit_process_loop
432
  add  esp,1024
433
  mov  dword [@Kolibri@_ExitProcessNow],-1
434
if defined EMULATOR
435
  int3
436
  call 0x76543210
437
end if
438
.exit_process_end:
439
  mov  dword [@Kolibri@_ThreadMutex],0
440
  or   eax,-1
441
  int  0x40
442
.exit_process_wait:
443
  mov  eax,5
444
  mov  ebx,1
445
.exit_process_wait_loop:
446
  cmp  dword [@Kolibri@_ExitProcessNow],0
447
  jl   .exit_process_end
448
  int  0x40
449
  shl  ebx,1
450
  cmp  ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT
451
  jna  .exit_process_wait_loop
452
  mov  ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT
453
  jmp  .exit_process_wait_loop
454
endp
455
 
456
proc @Kolibri@ExitThread$qppv,@Kolibri@ThreadMain$qpvt1
457
  mov  esp,[esp+4]
458
  jmp  Kolibri_main_end
459
endp
460
 
461
proc @Kolibri@ReturnMessageLoop$qppv,@Kolibri@ThreadMain$qpvt1
462
  mov  esp,[esp+4]
463
  bt   dword [esp+KOLIBRI_THREAD_DATA_FLAG*4],30
464
  jc   Kolibri_main_end
465
  jmp  Kolibri_main_cycle
466
endp
467
 
468
proc @Kolibri@Delay$qui uses ebx
469
  mov  eax,5
470
  mov  ebx,[esp+8]
471
  int  0x40
472
  ret
473
endp
474
 
475
proc @Kolibri@Clock$qv uses ebx
476
  mov  eax,26
477
  mov  ebx,9
478
  int  0x40
479
  ret
480
endp
481
 
482
proc @Kolibri@GetPackedTime$qv
483
  mov  eax,3
484
  int  0x40
485
  ret
486
endp
487
 
488
proc @Kolibri@GetTime$qpi
489
  mov  eax,3
490
  int  0x40
491
  mov  edx,[esp+4]
492
  movzx ecx,al
493
  shr  ecx,4
494
  and  al,0x0F
495
  imul ecx,10
496
  add  cl,al
497
  mov  dword [edx+8],ecx
498
  mov  cl,ah
499
  shr  ecx,4
500
  and  ah,0x0F
501
  imul ecx,10
502
  add  cl,ah
503
  mov  dword [edx+4],ecx
504
  bswap eax
505
  mov  cl,ah
506
  shr  ecx,4
507
  and  ah,0x0F
508
  imul ecx,10
509
  add  cl,ah
510
  mov  dword [edx],ecx
511
  ret
512
endp
513
 
514
proc @Kolibri@GetPackedDate$qv
515
  mov  eax,29
516
  int  0x40
517
  ret
518
endp
519
 
520
proc @Kolibri@GetDate$qpi
521
  mov  eax,29
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+4],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],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+8],ecx
543
  ret
544
endp
545
 
546
proc @Kolibri@ReadCommonColors$qpui uses ebx
547
  mov  eax,48
548
  mov  ebx,3
549
  mov  ecx,[esp+8]
550
  mov  edx,40
551
  int  0x40
552
  ret
553
endp
554
 
555
proc @Kolibri@DrawText$qssipxc uses ebx
556
  mov  eax,4
557
  mov  ebx,[esp+8-2]
558
  mov  bx,[esp+12]
559
  mov  ecx,[esp+16]
560
  or   ecx,0x80000000
561
  mov  edx,[esp+20]
562
  int  0x40
563
  ret
564
endp
565
 
566
proc @Kolibri@GetProcessInfo$qpuipct1t1piui uses ebx esi edi
567
  sub  esp,1024
568
  mov  eax,9
569
  mov  ebx,esp
570
  mov  ecx,[1024+12+24+esp]
571
  int  0x40
572
  xor  edi,edi
573
  or   edi,[1024+12+4+esp]
574
  jz   .get_proc_info_no_usecpu
575
  mov  ecx,[esp]
576
  mov  [edi],ecx
577
  xor  edi,edi
578
.get_proc_info_no_usecpu:
579
  or   edi,[1024+12+8+esp]
580
  jz   .get_proc_info_no_name
581
  lea  esi,[esp+10]
582
  cld
583
  movs dword [edi],[esi]
584
  movs dword [edi],[esi]
585
  movs dword [edi],[esi]
586
  mov  byte [edi],0
587
  xor  edi,edi
588
.get_proc_info_no_name:
589
  or   edi,[1024+12+12+esp]
590
  jz   .get_proc_info_no_mem
591
  mov  ecx,[esp+26]
592
  mov  [edi],ecx
593
  xor  edi,edi
594
.get_proc_info_no_mem:
595
  or   edi,[1024+12+16+esp]
596
  jz   .get_proc_info_no_pid
597
  mov  ecx,[esp+30]
598
  mov  [edi],ecx
599
  xor  edi,edi
600
.get_proc_info_no_pid:
601
  or   edi,[1024+12+20+esp]
602
  jz   .get_proc_info_no_rect
603
  lea  esi,[esp+34]
604
  cld
605
  movs dword [edi],[esi]
606
  movs dword [edi],[esi]
607
  movs dword [edi],[esi]
608
  movs dword [edi],[esi]
609
  xor  edi,edi
610
.get_proc_info_no_rect:
611
  add  esp,1024
612
  ret
613
endp
614
 
615
proc @Kolibri@GetPid$qv uses ebx
616
  sub  esp,1024
617
  mov  eax,9
618
  mov  ebx,esp
619
  mov  ecx,-1
620
  int  0x40
621
  mov  eax,[esp+30]
622
  add  esp,1024
623
  ret
624
endp
625
 
626
proc @Kolibri@GetPid$qppv
627
  mov  ecx,[esp+4]
628
  mov  eax,[ecx+KOLIBRI_THREAD_DATA_PID*4]
629
  ret
630
endp
631
 
632
proc @Kolibri@_HashByte$qui
633
@Kolibri@_HashWord$qui:
634
@Kolibri@_HashDword$qui:
635
  mov  eax,[esp+4]
636
Kolibri_HashInt:
637
  mul  dword [Kolibri_hash_int_val0]
638
  xor  eax,edx
639
  bswap eax
640
  mul  dword [Kolibri_hash_int_val1]
641
  shrd eax,edx,14
642
  bswap eax
643
  lea  eax,[eax+4*eax]
644
  ror  eax,9
645
  ret
646
endp
647
 
648
Kolibri_hash_int_val0:
649
  dd   0xA82F94C5
650
Kolibri_hash_int_val1:
651
  dd   0x9193780B
652
 
653
proc @Kolibri@GetThreadData$qv
654
  call @Kolibri@GetPid$qv
655
  push eax
656
  call @Kolibri@GetThreadData$qui
657
  pop  ecx
658
  ret
659
endp
660
 
661
proc @Kolibri@GetThreadData$qui
662
  mov  eax,[esp+4]
663
  call Kolibri_HashInt
664
  movzx eax,al
665
  cmp  dword [@Kolibri@_ThreadScanCount+4],0
666
  jnz  .get_thread_data_wait
667
.get_thread_data_nowait:
668
  lock inc dword [@Kolibri@_ThreadScanCount]
669
  mov  eax,dword [@Kolibri@_ThreadTable+eax*4]
670
  mov  ecx,[esp+4]
671
  jmp  .get_thread_data_test
672
.get_thread_data_loop:
673
  mov  eax,dword [eax+KOLIBRI_THREAD_DATA_NEXT*4]
674
.get_thread_data_test:
675
  test eax,eax
676
  jz   .get_thread_data_end
677
  cmp  ecx,[eax+KOLIBRI_THREAD_DATA_PID*4]
678
  jnz  .get_thread_data_loop
679
.get_thread_data_end:
680
  lock dec dword [@Kolibri@_ThreadScanCount]
681
  ret
682
.get_thread_data_wait:
683
  push eax ebx
684
  mov  eax,5
685
  mov  ebx,1
686
.get_thread_data_wait_loop:
687
  int  0x40
688
  cmp  dword [@Kolibri@_ThreadScanCount+4],0
689
  jz   .get_thread_data_wait_end
690
  shl  ebx,1
691
  cmp  ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT
692
  jna  .get_thread_data_wait_loop
693
  mov  ebx,KOLIBRI_MUTEX_MAX_TIME_WAIT
694
  jmp  .get_thread_data_wait_loop
695
.get_thread_data_wait_end:
696
  pop  ebx eax
697
  jmp .get_thread_data_nowait
698
endp
699
 
700
proc @Kolibri@_GetSkinHeader$qv uses ebx
701
  mov  eax,48
702
  mov  ebx,4
703
  int  0x40
704
  ret
705
endp
706
 
707
proc @Kolibri@GetScreenSize$qrust1
708
  mov  eax,14
709
  int  0x40
710
  mov  ecx,[esp+8]
711
  mov  word [ecx],ax
712
  mov  ecx,[esp+4]
713
  shr  eax,16
714
  mov  word [ecx],ax
715
  ret
716
endp
717
 
718
proc Kolibri_MutexLockNoWait
719
  pop  eax
720
  xor  al,al
721
  ret
722
endp
723
 
724
proc Kolibri_MutexLockWait uses ebx
725
  mov  eax,5
726
  xor  ebx,ebx
727
.lock_wait_cycle:
728
  int  0x40
729
  shl  byte [ecx],1
730
  jz   .lock_wait_cycle
731
  mov  al,1
732
  ret
733
endp
734
 
735
proc Kolibri_MutexLockWaitTime
736
  cmp  dword [esp+12],0
737
  jng  .MutexLockWait
738
  push ebx edx
739
  mov  edx,[esp+20]
740
  mov  eax,26
741
  mov  ebx,9
742
  int  0x40
743
  add  edx,eax
744
.lock_wait_time_cycle:
745
  mov  eax,5
746
  xor  ebx,ebx
747
  int  0x40
748
  shl  byte [ecx],1
749
  jnz  .lock_wait_time_ret_true
750
  mov  eax,26
751
  mov  ebx,9
752
  int  0x40
753
  cmp  eax,edx
754
  js   .lock_wait_time_cycle
755
  pop  edx ebx eax
756
  xor  al,al
757
  ret
758
.lock_wait_time_ret_true:
759
  pop  edx ebx
760
  mov  al,1
761
  ret
762
endp
763
 
764
proc Kolibri_MutexLock
765
  shl  byte [ecx],1
766
  jnz  .lock_first
767
  call eax
768
.lock_first:
769
  mov  al,1
770
  ret
771
endp
772
 
773
proc @Kolibri@TryLock$qp14Kolibri@TMutex
774
  mov  eax,Kolibri_MutexLockNoWait
775
  mov  ecx,[esp+4]
776
  jmp  Kolibri_MutexLock
777
endp
778
 
779
proc @Kolibri@Lock$qp14Kolibri@TMutex
780
  mov  eax,Kolibri_MutexLockWait
781
  mov  ecx,[esp+4]
782
  jmp  Kolibri_MutexLock
783
endp
784
 
785
proc @Kolibri@LockTime$qp14Kolibri@TMutexi
786
  mov  eax,Kolibri_MutexLockWaitTime
787
  mov  ecx,[esp+4]
788
  jmp  Kolibri_MutexLock
789
endp
790
 
791
proc @Kolibri@UnLock$qp14Kolibri@TMutex
792
  mov  ecx,[esp+4]
793
  shr  byte [ecx],1
794
  jz   .unlock_pause
795
  ret
796
.unlock_pause:
797
  mov  byte [ecx],0x40
798
  push ebx
799
  mov  eax,5
800
  xor  ebx,ebx
801
  int  0x40
802
  pop  ebx
803
  ret
804
endp
805
 
806
proc Kolibri_MutexLockRec
807
  shl  byte [ecx],1
808
  jng  .lock_first
809
  cmp  dword [ecx+4],edx
810
  jz   .lock_rec_self
811
  call eax
812
.lock_rec_first:
813
  mov  al,1
814
  mov  dword [ecx+4],edx
815
  ret
816
.lock_rec_self:
817
  mov  al,1
818
  add  dword [ecx],0x100
819
  jc   .lock_rec_overflow
820
  ret
821
.lock_rec_overflow:
822
  push dword [@Kolibri@DebugPrefix]
823
  call @Kolibri@DebugPutString$qpxc
824
  mov  dword [esp],Kolibri_try_lock_rec_overflow_string
825
  call @Kolibri@DebugPutString$qpxc
826
  pop  ecx
827
  jmp  @Kolibri@Abort$qv
828
endp
829
 
830
proc @Kolibri@TryLock$qp16Kolibri@TRecMutexui
831
  mov  eax,Kolibri_MutexLockNoWait
832
  mov  ecx,[esp+4]
833
  mov  edx,[esp+8]
834
  jmp  Kolibri_MutexLockRec
835
endp
836
 
837
proc @Kolibri@Lock$qp16Kolibri@TRecMutexui
838
  mov  eax,Kolibri_MutexLockWait
839
  mov  ecx,[esp+4]
840
  mov  edx,[esp+8]
841
  jmp  Kolibri_MutexLockRec
842
endp
843
 
844
proc @Kolibri@LockTime$qp16Kolibri@TRecMutexiui
845
  mov  eax,Kolibri_MutexLockWaitTime
846
  mov  ecx,[esp+4]
847
  mov  edx,[esp+12]
848
  jmp  Kolibri_MutexLockRec
849
endp
850
 
851
proc @Kolibri@UnLock$qp16Kolibri@TRecMutexui
852
  mov  ecx,[esp+4]
853
  mov  edx,[esp+8]
854
  cmp  dword [ecx+4],edx
855
  jnz  .unlock_rec_notlocked
856
  sub  dword [ecx],0x100
857
  jnc  .unlock_rec_end
858
  add dword [ecx],0x100
859
  shl byte [ecx],1
860
  shr byte [ecx],2
861
  jng  .unlock_rec_pause
862
.unlock_rec_end:
863
  ret
864
.unlock_rec_pause:
865
  mov  byte [ecx],0x20
866
  push ebx
867
  mov  eax,5
868
  xor  ebx,ebx
869
  int  0x40
870
  pop  ebx
871
  ret
872
.unlock_rec_notlocked:
873
  push dword [@Kolibri@DebugPrefix]
874
  call @Kolibri@DebugPutString$qpxc
875
  mov  dword [esp],Kolibri_unlock_rec_notlocked_string
876
  call @Kolibri@DebugPutString$qpxc
877
  pop  ecx
878
  jmp  @Kolibri@Abort$qv
879
endp
880
 
881
proc @Kolibri@DebugPutChar$qc
882
  mov  cl,byte [esp+4]
883
  cmp  cl,13
884
  jz   .debug_put_char_ret
885
  push ebx
886
  cmp  cl,10
887
  jz   .debug_put_char_enter
888
.debug_put_char_after_cmp:
889
  mov  eax,63
890
  mov  ebx,1
891
  int  0x40
892
  pop  ebx
893
.debug_put_char_ret:
894
  ret
895
.debug_put_char_enter:
896
  mov  cl,13
897
  mov  eax,63
898
  mov  ebx,1
899
  int  0x40
900
  mov  cl,10
901
  jmp  .debug_put_char_after_cmp
902
endp
903
 
904
proc @Kolibri@DebugPutString$qpxc
905
  push esi
906
  push dword 0
907
  mov  esi,dword [esp+12]
908
  jmp  .debug_put_string_test
909
.debug_put_string_loop:
910
  mov  dword [esp],eax
911
  call @Kolibri@DebugPutChar$qc
912
  inc  esi
913
.debug_put_string_test:
914
  xor  eax,eax
915
  or   al,[esi]
916
  test al,al
917
  jnz  .debug_put_string_loop
918
  pop  ecx esi
919
  ret
920
endp
921
 
922
proc @Kolibri@GetKey$qv
923
  mov  eax,2
924
  int  0x40
925
  test al,al
926
  jnz  .get_key_eof
927
  movzx eax,ah
928
  ret
929
.get_key_eof:
930
  mov  eax,-1
931
  ret
932
endp
933
 
934
proc @Kolibri@GetMouseButton$qv uses ebx
935
  mov  eax,37
936
  mov  ebx,2
937
  int  0x40
938
  ret
939
endp
940
 
941
proc @Kolibri@GetMousePosition$qrst1o uses ebx
942
  mov  eax,37
943
  xor  ebx,ebx
944
  cmp  byte [esp+16],0
945
  jnz  .get_mouse_pos_absolute
946
  inc  ebx
947
.get_mouse_pos_absolute:
948
  int  0x40
949
  mov  ecx,[esp+12]
950
  mov  word [ecx],ax
951
  mov  ecx,[esp+8]
952
  shr  eax,16
953
  mov  word [ecx],ax
954
  ret
955
endp
956
 
957
proc @Kolibri@WasThreadCreated$qv
958
  cmp  byte [@Kolibri@_ThreadSavedBegProc],0x90
959
  setz al
960
  ret
961
endp
962
 
963
proc @Kolibri@CreateThread$qpvuit1
964
  push ebx
965
  mov  edx,[esp+16]
966
  mov  ebx,[esp+12]
967
  test edx,edx
968
  jnz  .create_thread_after_new
969
if defined KolibriHeapAlloc
970
  cmp  ebx,4096
971
  jnb  .create_thread_alloc
972
  mov  ebx,STACKSIZE
973
.create_thread_alloc:
974
  push ebx
975
  call KolibriHeapAlloc	 ; Create new dynamic memory of the given size
976
  pop  ecx
977
  test eax,eax
978
  jnz  .create_thread_mem_created
979
end if
980
  or   eax,-1
981
  jmp  .create_thread_end
982
.create_thread_mem_created:
983
  lea  edx,[eax+ebx]
984
.create_thread_after_new:
985
  neg  ebx
986
  jz   .create_thread_test_first
987
  add  ebx,edx
988
.create_thread_test_first:
989
  cmp  byte [@Kolibri@_ThreadSavedBegProc],0x90
990
  jnz  .create_thread_init
991
.create_thread_fill_stack:
992
  lock inc dword [@Kolibri@_ThreadNumber]
993
  and  edx,not 3
994
  sub  edx,12
995
  mov  ecx,[esp+8]
996
  mov  dword [edx+8],ebx
997
  mov  dword [edx+4],ecx
998
  mov  dword [edx],Kolibri_ThreadFinish
999
  mov  eax,51
1000
  mov  ebx,1
1001
  mov  ecx,@Kolibri@ThreadMain$qpvt1
1002
  int  0x40
1003
  mov  ebx,eax
1004
  or   bl,15
1005
  inc  ebx
1006
  jnz  .create_thread_end
1007
  lock dec dword [@Kolibri@_ThreadNumber]
1008
if defined KolibriHeapFree
1009
  or   ebx,[edx+8]
1010
  jz   .create_thread_end
1011
  push ebx
1012
  call KolibriHeapFree	; Delete the given dynamic memory
1013
  pop  ecx
1014
end if
1015
.create_thread_end:
1016
  pop  ebx
1017
  ret
1018
.create_thread_init:
1019
  push esi edi
1020
  cld
1021
  mov  esi,@Kolibri@_ThreadSavedBegProc
1022
  mov  edi,@Kolibri@GetPid$qv
1023
  movs dword [edi],[esi]
1024
  movs dword [edi],[esi]
1025
  mov  edi,@Kolibri@GetThreadData$qv
1026
  movs dword [edi],[esi]
1027
  movs dword [edi],[esi]
1028
  mov  eax,0x90909090
1029
  mov  edi,@Kolibri@_ThreadSavedBegProc
1030
  stos dword [edi]
1031
  stos dword [edi]
1032
  stos dword [edi]
1033
  stos dword [edi]
1034
  pop  edi esi
1035
  jmp  .create_thread_fill_stack
1036
endp
1037
 
1038
proc @Kolibri@_FileAccess$qpv uses ebx
1039
  mov  eax,70
1040
  mov  ebx,[esp+8]
1041
  int  0x40
1042
  mov  ecx,[esp+8]
1043
  mov  [ecx],ebx
1044
  ret
1045
endp
1046
 
1047
Kolibri_abort_string:
1048
  db 'Abnormal program termination.',10,0
1049
Kolibri_try_lock_rec_overflow_string:
1050
  db 'Recursive mutex lock count overflow.',10,0
1051
Kolibri_unlock_rec_notlocked_string:
1052
  db 'Recursive mutex unlock error.',10,0
1053
 
1054
include "kos_lib.inc"
1055
 
1056
;/**/
1057