Subversion Repositories Kolibri OS

Rev

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