Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
616 bw 1
{cp866}
2
 
3
{ User interface }
4
procedure kos_definewindow(x, y, w, h: Word; style, header, clframe: DWord); assembler; register;
5
asm
6
  pushl %ebx
7
  pushl %ecx
8
  pushl %edx
9
  pushl %esi
10
  pushl %edi
11
  movl  %eax, %ebx
12
  xchgl %edx, %ecx
13
  movl  header, %esi
14
  shll  $16, %ebx
15
  shll  $16, %ecx
16
  movl  clframe, %edi
17
  movw  %dx, %bx
18
  movw  h, %cx
19
  xorl  %eax, %eax
20
  movl  style, %edx
21
  decl  %ebx  {уменьшить ширину на 1}
22
  decl  %ecx  {уменьшить высоту на 1}
23
  int   $0x40
24
  popl %edi
25
  popl %esi
26
  popl %edx
27
  popl %ecx
28
  popl %ebx
29
end;
30
 
31
procedure kos_movewindow(x, y, w, h: DWord); assembler; register;
32
asm
33
  pushl %eax
34
  pushl %ebx
35
  pushl %ecx
36
  pushl %edx
37
  pushl %esi
38
  movl  %eax, %ebx
39
  xchgl %ecx, %edx
40
  movl  $67, %eax
41
  movl  h, %esi
42
  decl  %edx  {уменьшить ширину на 1}
43
  decl  %esi  {уменьшить высоту на 1}
44
  int   $0x40
45
  popl  %esi
46
  popl  %edx
47
  popl  %ecx
48
  popl  %ebx
49
  popl  %eax
50
end;
51
 
52
function kos_getkey(): DWord; assembler; register;
53
asm
54
  movl $2, %eax
55
  int  $0x40
56
end;
57
 
58
function kos_getevent(wait: Boolean = True): DWord; assembler; register;
59
asm
60
  andl $1, %eax
61
  xorb $1, %al
62
  addl $10, %eax
63
  int  $0x40
64
end;
65
 
66
function kos_waitevent(timeout: DWord): DWord; assembler; register;
67
asm
68
  pushl %ebx
69
  movl  $23, %ebx
70
  xchgl %eax, %ebx
71
  int  $0x40
72
  popl  %ebx
73
end;
74
 
75
function kos_getbutton(): DWord; assembler; register;
76
asm
77
  movl  $17, %eax
78
  int   $0x40
79
  shrl  $8, %eax
80
  andl  $0xFF, %eax
81
end;
82
 
83
function kos_getmousepos(): TKosPoint; assembler; register;
84
{@return: x*65536 + y}
85
asm
86
  pushl %eax
87
  pushl %ebx
88
  pushl %ecx
89
  pushl %eax
90
  movl  $37, %eax
91
  xorl  %ebx, %ebx
92
  int   $0x40
93
  movswl %ax, %ecx
94
  popl  %ebx
95
  shrl  $16, %eax
96
  movl  %ecx, TKosPoint.Y(%ebx)
97
  movl  %eax, TKosPoint.X(%ebx)
98
  popl  %ecx
99
  popl  %ebx
100
  popl  %eax
101
end;
102
 
103
function kos_getmousewinpos(): TKosPoint; assembler; register;
104
{@return: x*65536 + y}
105
asm
106
  pushl %eax
107
  pushl %ebx
108
  pushl %ecx
109
  pushl %eax
110
  movl  $37, %eax
111
  movl  $1, %ebx
112
  int   $0x40
113
  movswl %ax, %ecx
114
  popl  %ebx
115
  shrl  $16, %eax
116
  movl  %ecx, TKosPoint.Y(%ebx)
117
  movl  %eax, TKosPoint.X(%ebx)
118
  popl  %ecx
119
  popl  %ebx
120
  popl  %eax
121
end;
122
 
123
function kos_getmousebuttons(): DWord; assembler; register;
124
{@return:
125
  бит 0 установлен = левая кнопка нажата
126
  бит 1 установлен = правая кнопка нажата
127
  бит 2 установлен = средняя кнопка нажата
128
  бит 3 установлен = 4-я кнопка нажата
129
  бит 4 установлен = 5-я кнопка нажата}
130
asm
131
  pushl %ebx
132
  movl  $37, %eax
133
  movl  $2, %ebx
134
  int   $0x40
135
  popl  %ebx
136
end;
137
 
138
procedure kos_maskevents(mask: DWord); assembler; register;
139
asm
140
  pushl %ebx
141
  xchgl %eax, %ebx
142
  movl  $40, %eax
143
  int   $0x40
144
  xchgl %eax, %ebx
145
  popl  %ebx
146
end;
147
 
148
procedure kos_setcaption(caption: PChar); assembler; register;
149
asm
150
  pushl %ecx
151
  pushl %ebx
152
  xchgl %eax, %ecx
153
  movl $1, %ebx
154
  movl $71, %eax
155
  int  $0x40
156
  xchgl %eax, %ecx
157
  popl %ebx
158
  popl %ecx
159
end;
160
 
161
 
162
{ Graphics }
163
 
619 bw 164
function kos_screensize(): TKosPoint; assembler; register;
165
asm
166
  pushl %eax
167
  pushl %ecx
168
  pushl %eax
169
  movl  $14, %eax
170
  int   $0x40
171
  movswl %ax, %ecx
172
  popl  %ebx
173
  shrl  $16, %eax
174
  movl  %ecx, TKosPoint.Y(%ebx)
175
  movl  %eax, TKosPoint.X(%ebx)
176
  popl  %ecx
177
  popl  %eax
178
end;
179
 
616 bw 180
procedure kos_begindraw(); assembler; register;
181
asm
182
  pushl %ebx
183
  movl  $12, %eax
184
  movl  $1, %ebx
185
  int   $0x40
186
  popl  %ebx
187
end;
188
 
189
procedure kos_enddraw(); assembler; register;
190
asm
191
  pushl %ebx
192
  movl  $12, %eax
193
  movl  $2, %ebx
194
  int   $0x40
195
  popl  %ebx
196
end;
197
 
198
procedure kos_putpixel(x, y: Word; color: DWord); assembler; register;
199
asm
200
  pushl %ebx
201
  movl  %eax, %ebx
202
  xchgl %edx, %ecx
203
  movl  $1, %eax
204
  int   $0x40
205
  xchgl %edx, %ecx
206
  popl  %ebx
207
end;
208
 
209
procedure kos_drawtext(x, y: Word; text: String; flags, bgcolor: DWord); assembler; register;
210
label nobg;
211
asm
212
  pusha
213
  shll  $16, %eax
214
  pushl %ecx
215
  movl  flags, %ecx  {флаги, цвет}
216
  movl  bgcolor, %edi
217
  movw  %dx, %ax
218
  andl   $0x7FFFFFFF, %ecx
219
  btl   $31, %edi
220
  jnc   nobg
221
  orl   $0x40000000, %ecx
222
nobg:
223
  popl  %edx
224
  movl  %eax, %ebx    {координаты}
225
  movzbl (%edx), %esi {длина строки}
226
  movl  $4, %eax      {номер функции}
227
  incl  %edx          {указатель на строку}
228
  andl  $0xFFFFFF, %edi
229
  int   $0x40
230
  popa
231
end;
232
 
233
procedure kos_drawrect(x, y, w, h: Word; color: DWord); assembler; register;
234
asm
235
  pushl %eax
236
  pushl %ebx
237
  pushl %ecx
238
  pushl %edx
239
  movl  %eax, %ebx
240
  xchgl %edx, %ecx
241
  shll  $16, %ebx
242
  shll  $16, %ecx
243
  movl  $13, %eax
244
  movw  %dx, %bx
245
  movw  h, %cx
246
  movl  color, %edx
247
  int   $0x40
248
  popl %edx
249
  popl %ecx
250
  popl %ebx
251
  popl %eax
252
end;
253
 
254
procedure kos_drawline(x1, y1, x2, y2: Word; color: DWord = $000000); assembler; register;
255
asm
256
  pushl %eax
257
  pushl %ebx
258
  pushl %ecx
259
  pushl %edx
260
 
261
  xchgl %eax, %ecx
262
  xchgl %ecx, %edx
263
  movl  color, %ebx
264
  {eax - x2, ebx - color, ecx - y1, edx - x1}
265
  shll  $16, %ecx
266
  shll  $16, %edx
267
  movw  %ax, %dx
268
  movw  y2, %cx
269
  movl  $38, %eax
270
  xchgl %ebx, %edx
271
  int   $0x40
272
 
273
  popl  %edx
274
  popl  %ecx
275
  popl  %ebx
276
  popl  %eax
277
end;
278
 
279
procedure kos_drawimage(x, y, w, h, depth: DWord; image: Pointer; palette: Pointer; xoffset: DWord); assembler; register;
280
asm
281
  pusha
282
  shll  $16, %eax
283
  shll  $16, %ecx
284
  orl   %eax, %edx
285
  orl   h, %ecx
286
  movl  depth, %esi
287
  movl  image, %ebx
288
  movl  palette, %edi
289
  movl  xoffset, %ebp
290
  movl  $65, %eax
291
  int   $0x40
292
  popa
293
end;
294
 
295
procedure kos_drawimage24(x, y, w, h: DWord; image: Pointer); assembler; register;
296
asm
297
  pushl %eax
298
  pushl %ebx
299
  pushl %ecx
300
  pushl %edx
301
  shll  $16, %eax
302
  shll  $16, %ecx
303
  orl   %eax, %edx
304
  orl   h, %ecx
305
  movl  image, %ebx
306
  movl  $7, %eax
307
  int   $0x40
308
  popl  %edx
309
  popl  %ecx
310
  popl  %ebx
311
  popl  %eax
312
end;
313
 
314
 
315
{ Work with system }
316
 
317
{ Work with system - System services }
318
 
319
function kos_killthread(tid: TThreadID): Boolean; assembler; register;
320
asm
321
  pushl %ecx
322
  pushl %ebx
323
  movl  $18, %ecx
324
  movl  $18, %ebx
325
  xchgl %eax, %ecx
326
  int   $0x40
327
  andl  $1, %eax
328
  popl  %ebx
329
  popl  %ecx
330
  xorb  $1, %al
331
end;
332
 
333
procedure kos_setactivewindow(slot: TThreadSlot); assembler; register;
334
asm
335
  pushl %ecx
336
  pushl %ebx
337
  movl  $18, %ecx
338
  movl  $3, %ebx
339
  xchgl %eax, %ecx
340
  int   $0x40
341
  xchgl %eax, %ecx
342
  popl  %ebx
343
  popl  %ecx
344
end;
345
 
346
{$ifdef EMULATOR}
347
function kos_getthreadslot(tid: TThreadID): TThreadSlot;
348
var
349
  ThreadInfo: TKosThreadInfo;
350
  HighThreadSlot: TThreadSlot;
351
begin
352
  Result := 0;
353
  repeat
354
    Inc(Result);
355
    HighThreadSlot := kos_threadinfo(@ThreadInfo, Result);
356
  until (Result > HighThreadSlot) or (ThreadInfo.ThreadID = tid);
357
end;
358
 
359
{$else}
360
 
361
function kos_getthreadslot(tid: TThreadID): TThreadSlot; assembler; register;
362
asm
363
  pushl %ecx
364
  pushl %ebx
365
  movl  $18, %ecx
366
  movl  $21, %ebx
367
  xchgl %eax, %ecx
368
  int   $0x40
369
  popl  %ebx
370
  popl  %ecx
371
end;
372
{$endif}
373
 
374
{ Work with system - Set system parameters }
375
 
376
procedure kos_enablepci(); assembler; register;
377
asm
378
  pushl %eax
379
  pushl %ebx
380
  pushl %ecx
381
  movl  $21, %eax
382
  movl  $12, %ebx
383
  movl  $1, %ecx
384
  int   $0x40
385
  popl  %ecx
386
  popl  %ebx
387
  popl  %eax
388
end;
389
 
390
{ Work with system - Internal system services }
391
 
392
procedure kos_switchthread(); assembler; register;
393
asm
394
  pushl %eax
395
  pushl %ebx
396
  movl  $68, %eax
397
  movl  $1, %ebx
398
  int   $0x40
399
  popl  %ebx
400
  popl  %eax
401
end;
402
 
403
function kos_initheap(): DWord; assembler; register;
404
asm
405
  pushl %ebx
406
  movl  $68, %eax
407
  movl  $11, %ebx
408
  int   $0x40
409
  popl  %ebx
410
end;
411
 
412
function kos_alloc(size: DWord): Pointer; assembler; register;
413
asm
414
  pushl %ebx
415
  pushl %ecx
416
  movl  %eax, %ecx
417
  movl  $68, %eax
418
  movl  $12, %ebx
419
  int   $0x40
420
  popl  %ecx
421
  popl  %ebx
422
end;
423
 
424
function kos_free(ptr: Pointer): Boolean; assembler; register;
425
asm
426
  pushl %ebx
427
  pushl %ecx
428
  movl  %eax, %ecx
429
  movl  $68, %eax
430
  movl  $13, %ebx
431
  int   $0x40
432
  popl  %ecx
433
  popl  %ebx
434
end;
435
 
436
function kos_loaddriver(name: PChar): THandle; assembler; register;
437
asm
438
  pushl %ebx
439
  pushl %ecx
440
  movl  %eax, %ecx
441
  movl  $68, %eax
442
  movl  $16, %ebx
443
  int   $0x40
444
  popl  %ecx
445
  popl  %ebx
446
end;
447
 
448
 
449
{ Processes and threads }
450
 
451
function kos_threadinfo(info: PKosThreadInfo; slot: TThreadSlot): DWord; assembler; register;
452
asm
453
  pushl %ebx
454
  movl  %eax, %ebx
455
  xchgl %edx, %ecx
456
  movl  $9, %eax
457
  int   $0x40
458
  xchgl %edx, %ecx
459
  popl  %ebx
460
end;
461
 
462
function kos_newthread(entry, stack: Pointer): TThreadID; assembler; register;
463
asm
464
  pushl %ebx
465
  pushl %ecx
466
  movl  $1, %ebx
467
  movl  %eax, %ecx
468
  movl  $51, %eax
469
  int   $0x40
470
  popl  %ecx
471
  popl  %ebx
472
end;
473
 
474
procedure kos_initipc(ipc: PKosIPC; size: DWord); assembler; register;
475
asm
476
  pushl %ebx
477
  pushl %ecx
478
  movl  $60, %ecx
479
  movl  $1, %ebx
480
  xchgl %eax, %ecx
481
  int   $0x40
482
  popl  %ecx
483
  popl  %ebx
484
end;
485
 
486
function kos_sendmsg(tid: TThreadID; msg: Pointer; size: DWord): DWord; assembler; register;
487
{@return:
488
 
489
  1 - приёмник не определил буфер для IPC-сообщений
490
      (может быть, ещё не успел, а может быть, это не тот поток, который нужен)
491
  2 - приёмник заблокировал IPC-буфер; попробуйте немного подождать
492
  3 - переполнение IPC-буфера приёмника
493
  4 - процесса/потока с таким PID не существует}
494
asm
495
  pushl %esi
496
  pushl %ebx
497
  movl  $60, %esi
498
  movl  $2, %ebx
499
  xchgl %ecx, %esi
500
  xchgl %eax, %ecx
501
  int   $0x40
502
  xchgl %ecx, %esi
503
  popl  %ebx
504
  popl  %esi
505
end;
506
 
507
function kos_resizemem(size: DWord): Boolean; assembler; register;
508
asm
509
  pushl %ebx
510
  pushl %ecx
511
  movl  %eax, %ecx
512
  movl  $64, %eax
513
  movl  $1, %ebx
514
  int   $0x40
515
  xorb  $1, %al
516
  popl  %ecx
517
  popl  %ebx
518
end;
519
 
520
 
521
{ File system }
522
{ File system - Work with the current folder }
523
 
524
procedure kos_setdir(path: PChar); assembler; register;
525
asm
526
  pushl %ecx
527
  pushl %ebx
528
  movl  $30, %ecx
529
  movl  $1, %ebx
530
  xchgl %eax, %ecx
531
  int   $0x40
532
  popl  %ebx
533
  popl  %ecx
534
end;
535
 
536
function kos_getdir(path: PChar; size: DWord): DWord; assembler; register;
537
asm
538
  pushl %ecx
539
  pushl %ebx
540
  movl  $30, %ecx
541
  movl  $2, %ebx
542
  xchgl %eax, %ecx
543
  int   $0x40
544
  popl  %ebx
545
  popl  %ecx
546
end;
547
 
548
{ File system - Work with file system with long names support }
549
 
550
function kos_readfile(kosfile: PKosFile; var readed: Longint): DWord; assembler; register;
551
asm
552
  pushl %ebx
553
  movl  $70, %ebx
554
  xchgl %eax, %ebx
555
  movl  $0, (%ebx)
556
  int   $0x40
557
  movl  %ebx, (%edx)
558
  popl  %ebx
559
end;
560
 
561
function kos_rewritefile(kosfile: PKosFile; var writed: Longint): DWord; assembler; register;
562
asm
563
  pushl %ebx
564
  movl  $70, %ebx
565
  xchgl %eax, %ebx
566
  movl  $2, (%ebx)
567
  int   $0x40
568
  movl  %ebx, (%edx)
569
  popl  %ebx
570
end;
571
 
572
function kos_writefile(kosfile: PKosFile; var writed: Longint): DWord; assembler; register;
573
asm
574
  pushl %ebx
575
  movl  $70, %ebx
576
  xchgl %eax, %ebx
577
  movl  $3, (%ebx)
578
  int   $0x40
579
  movl  %ebx, (%edx)
580
  popl  %ebx
581
end;
582
 
583
function kos_fileinfo(kosfile: PKosFile): DWord; assembler; register;
584
asm
585
  pushl %ebx
586
  movl  $70, %ebx
587
  xchgl %eax, %ebx
588
  movl  $5, (%ebx)
589
  int   $0x40
590
  popl  %ebx
591
end;
592
 
593
 
594
{ Work with hardware }
595
 
596
function kos_readport(index: DWord): DWord; assembler; register;
597
label ok, exit;
598
asm
599
  pushl %ecx
600
  pushl %ebx
601
  xchgl %eax, %ecx         {index}
602
  movl  $43, %eax
603
  orl   $0x80000000, %ecx  {index}
604
  int   $0x40
605
  orl   %eax, %eax
606
  jzl   ok
607
  movl  $-1, %eax
608
  jmp   exit
609
ok:
610
  movl  %ebx, %eax
611
exit:
612
  popl  %ebx
613
  popl  %ecx
614
end;
615
 
616
procedure kos_writeport(index, value: DWord); assembler; register;
617
asm
618
  pushl %eax
619
  pushl %ebx
620
  pushl %ecx
621
  xchgl %edx, %ebx  {value}
622
  xchgl %eax, %ecx  {index}
623
  movl  $43, %eax
624
  int   $0x40
625
  xchgl %edx, %ebx
626
  popl  %ecx
627
  popl  %ebx
628
  popl  %eax
629
end;
630
 
631
function kos_reserveport(port: DWord): Boolean; assembler; register;
632
asm
633
  pushl %ebx
634
  pushl %ecx
635
  pushl %edx
636
  movl  %eax, %ecx  {port}
637
  movl  $46, %eax
638
  movl  %ecx, %edx  {port}
639
  xorl  %ebx, %ebx
640
  int   $0x40
641
  xorb  $1, %al
642
  popl  %edx
643
  popl  %ecx
644
  popl  %ebx
645
end;
646
 
647
{ Work with hardware - Low-level access to PCI}
648
 
649
function kos_lastpcibus(): Byte; assembler; register;
650
asm
651
  pushl %ebx
652
  movl  $62, %eax
653
  movl  $1, %ebx
654
  int   $0x40
655
  popl  %ebx
656
end;
657
 
658
function kos_readpcib(bus, dev, func, reg: Byte): Byte; assembler; register;
659
asm
660
  pushl %ebx
661
  pushl %ecx
662
  pushl %edx
663
  shlb  $3, %dl   {dev}
664
  movb  %al, %bh  {bus}
665
  shlw  $8, %cx   {func}
666
  movb  $4, %bl
667
  movb  reg, %cl  {func}
668
  andb  $7, %ch   {func}
669
  movl  $62, %eax
670
  orb   %dl, %ch  {dev/func}
671
  int   $0x40
672
  popl  %edx
673
  popl  %ecx
674
  popl  %ebx
675
end;
676
 
677
function kos_readpciw(bus, dev, func, reg: Byte): Word; assembler; register;
678
asm
679
  pushl %ebx
680
  pushl %ecx
681
  pushl %edx
682
  shlb  $3, %dl   {dev}
683
  movb  %al, %bh  {bus}
684
  shlw  $8, %cx   {func}
685
  movb  $5, %bl
686
  movb  reg, %cl  {reg}
687
  andb  $7, %ch   {func}
688
  movl  $62, %eax
689
  orb   %dl, %ch  {dev/func}
690
  int   $0x40
691
  popl  %edx
692
  popl  %ecx
693
  popl  %ebx
694
end;
695
 
696
function kos_readpcid(bus, dev, func, reg: Byte): DWord; assembler; register;
697
asm
698
  pushl %ebx
699
  pushl %ecx
700
  pushl %edx
701
  shlb  $3, %dl   {dev}
702
  movb  %al, %bh  {bus}
703
  shlw  $8, %cx   {func}
704
  movb  $6, %bl
705
  movb  reg, %cl  {reg}
706
  andb  $7, %ch   {func}
707
  movl  $62, %eax
708
  orb   %dl, %ch  {dev/func}
709
  int   $0x40
710
  popl  %edx
711
  popl  %ecx
712
  popl  %ebx
713
end;
714
 
715
 
716
{ Other }
717
procedure kos_delay(ms: DWord); assembler; register;
718
asm
719
  pushl %ebx
720
  movl  %eax, %ebx
721
  movl  $5, %eax
722
  int   $0x40
723
  popl  %ebx
724
end;