Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1 ha 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;
709 diamond 3
;; Copyright (C) KolibriOS team 2004-2008. All rights reserved.
431 serge 4
;; PROGRAMMING:
5
;; Ivan Poddubny
6
;; Marat Zakiyanov (Mario79)
7
;; VaStaNi
8
;; Trans
9
;; Mihail Semenyako (mike.dld)
10
;; Sergey Kuzmin (Wildwest)
11
;; Andrey Halyavin (halyavin)
12
;; Mihail Lisovin (Mihasik)
13
;; Andrey Ignatiev (andrew_programmer)
14
;; NoName
15
;; Evgeny Grechnikov (Diamond)
16
;; Iliya Mihailov (Ghost)
17
;; Sergey Semyonov (Serge)
18
;; Johnny_B
543 spraid 19
;; SPraid (simba)
1 ha 20
;;
431 serge 21
;; Data in this file was originally part of MenuetOS project which is
22
;; distributed under the terms of GNU GPL. It is modified and redistributed as
23
;; part of KolibriOS project under the terms of GNU GPL.
1 ha 24
;;
431 serge 25
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa
26
;; PROGRAMMING:
1 ha 27
;;
431 serge 28
;; Ville Mikael Turjanmaa, villemt@itu.jyu.fi
29
;; - main os coding/design
30
;; Jan-Michael Brummer, BUZZ2@gmx.de
31
;; Felix Kaiser, info@felix-kaiser.de
32
;; Paolo Minazzi, paolo.minazzi@inwind.it
33
;; quickcode@mail.ru
34
;; Alexey, kgaz@crosswinds.net
35
;; Juan M. Caravaca, bitrider@wanadoo.es
36
;; kristol@nic.fi
37
;; Mike Hibbett, mikeh@oceanfree.net
38
;; Lasse Kuusijarvi, kuusijar@lut.fi
39
;; Jarek Pelczar, jarekp3@wp.pl
1 ha 40
;;
431 serge 41
;; KolibriOS is distributed in the hope that it will be useful, but WITHOUT ANY
42
;; WARRANTY. No author or distributor accepts responsibility to anyone for the
43
;; consequences of using it or for whether it serves any particular purpose or
44
;; works at all, unless he says so in writing. Refer to the GNU General Public
45
;; License (the "GPL") for full details.
46
;
47
;; Everyone is granted permission to copy, modify and redistribute KolibriOS,
48
;; but only under the conditions described in the GPL. A copy of this license
49
;; is supposed to have been given to you along with KolibriOS so you can know
50
;; your rights and responsibilities. It should be in a file named COPYING.
51
;; Among other things, the copyright notice and this notice must be preserved
52
;; on all copies.
53
;;
1 ha 54
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
426 mikedld 55
 
56
include 'macros.inc'
57
 
425 victor 58
$Revision: 847 $
426 mikedld 59
 
593 mikedld 60
 
841 serge 61
fastcall equ call
62
 
769 Rus 63
USE_COM_IRQ equ 1      ;make irq 3 and irq 4 available for PCI devices
566 serge 64
 
164 serge 65
include "proc32.inc"
7 me_root 66
include "kglobals.inc"
1 ha 67
include "lang.inc"
68
 
164 serge 69
include "const.inc"
742 Rus 70
max_processes	 equ   255
71
tss_step	 equ   (128+8192) ; tss & i/o - 65535 ports, * 256=557056*4
1 ha 72
 
164 serge 73
 
742 Rus 74
os_stack       equ  (os_data_l-gdts)	; GDTs
465 serge 75
os_code        equ  (os_code_l-gdts)
76
graph_data     equ  (3+graph_data_l-gdts)
742 Rus 77
tss0	       equ  (tss0_l-gdts)
465 serge 78
app_code       equ  (3+app_code_l-gdts)
79
app_data       equ  (3+app_data_l-gdts)
586 serge 80
pci_code_sel   equ  (pci_code_32-gdts)
81
pci_data_sel   equ  (pci_data_32-gdts)
1 ha 82
 
83
 
84
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
85
;;
86
;;   Included files:
87
;;
88
;;   Kernel16.inc
89
;;    - Booteng.inc   English text for bootup
90
;;    - Bootcode.inc  Hardware setup
91
;;    - Pci16.inc     PCI functions
92
;;
93
;;   Kernel32.inc
94
;;    - Sys32.inc     Process management
95
;;    - Shutdown.inc  Shutdown and restart
96
;;    - Fat32.inc     Read / write hd
97
;;    - Vesa12.inc    Vesa 1.2 driver
98
;;    - Vesa20.inc    Vesa 2.0 driver
99
;;    - Vga.inc       VGA driver
100
;;    - Stack.inc     Network interface
101
;;    - Mouse.inc     Mouse pointer
102
;;    - Scincode.inc  Window skinning
103
;;    - Pci32.inc     PCI functions
104
;;
105
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
106
 
107
 
847 serge 108
use32
109
org 0x100000
1 ha 110
 
847 serge 111
mboot:
112
  dd  0x1BADB002
113
  dd  0x00010003
114
  dd  -(0x1BADB002 + 0x00010003)
115
  dd  mboot
116
  dd  0x100000
117
  dd  __edata - OS_BASE
118
  dd  LAST_PAGE
119
  dd  __start
1 ha 120
 
121
 
847 serge 122
align 16
123
__start:
124
           cld
1 ha 125
 
847 serge 126
           mov esp, __os_stack-OS_BASE
127
           push 0
128
           popf
1 ha 129
 
847 serge 130
           cmp eax, 0x2BADB002
131
           mov ecx, sz_invboot
132
           jne .fault
1 ha 133
 
847 serge 134
           bt dword [ebx], 3
135
           mov ecx, sz_nomods
136
           jnc .fault
1 ha 137
 
847 serge 138
           bt dword [ebx], 6
139
           mov ecx, sz_nommap
140
           jnc .fault
1 ha 141
 
847 serge 142
           mov [_boot_mbi-OS_BASE], ebx
1 ha 143
 
847 serge 144
           xor eax, eax
145
           cpuid
146
           cmp eax, 0
147
           mov ecx, sz_nopse
148
           jbe .fault
1 ha 149
 
847 serge 150
           mov eax, 1
151
           cpuid
152
           bt edx, 3
153
           mov ecx, sz_nopse
154
           jnc .fault
1 ha 155
 
847 serge 156
; ENABLE PAGING
1 ha 157
 
847 serge 158
           mov ecx, 32
159
           mov edi, _sys_pdbr+(OS_BASE shr 20)-OS_BASE
160
           mov eax, PG_LARGE+PG_SW
161
@@:
162
           stosd
163
           add eax, 4*1024*1024
164
           loop @B
465 serge 165
 
847 serge 166
           mov dword [_sys_pdbr-OS_BASE],   PG_LARGE+PG_SW
167
           mov dword [_sys_pdbr-OS_BASE+4], PG_LARGE+PG_SW+4*1024*1024
168
           mov dword [_sys_pdbr-OS_BASE+(page_tabs shr 20)], sys_pgdir+PG_SW-OS_BASE
1 ha 169
 
847 serge 170
           mov ebx, cr4
171
           or ebx, CR4_PSE
172
           and ebx, not CR4_PAE
173
           mov cr4, ebx
1 ha 174
 
847 serge 175
           mov eax, _sys_pdbr-OS_BASE
176
           mov ebx, cr0
177
           or ebx,CR0_PG+CR0_WP
183 diamond 178
 
847 serge 179
           mov cr3, eax
180
           mov cr0, ebx
375 Ghost 181
 
847 serge 182
           mov ebx, [_boot_mbi]
1 ha 183
 
847 serge 184
           mov edx, [ebx+20]
185
           mov esi, [ebx+24]
186
           mov ecx, LAST_PAGE
187
           test edx, edx
188
           jz .no_mods
189
.scan_mod:
190
           mov ecx, [esi+4]
191
           add esi, 16
192
           dec edx
193
           jnz .scan_mod
1 ha 194
 
847 serge 195
.no_mods:
196
           add ecx, 4095
197
           and ecx, not 4095
1 ha 198
 
847 serge 199
           lgdt [gdts]
200
           jmp pword os_code:high_code
1 ha 201
 
847 serge 202
 
203
.fault:
204
;           push ecx
205
;           call _lcls
206
;           call __bprintf
207
_hlt:
208
           hlt
209
           jmp _hlt
210
 
211
sz_invboot db 'Invalid multiboot loader magic value',0x0A
212
           db 'Halted',0
213
 
214
sz_nomods  db 'No modules loaded',0x0A
215
           db 'Halted',0
216
 
217
sz_nommap  db 'No memory table', 0x0A
218
           db 'Halted',0
219
 
220
sz_nopse   db 'Page size extensions not supported',0x0A
221
           db 'Halted',0
222
 
223
 
224
 
465 serge 225
; CLEAR 0x280000 - HEAP_BASE
1 ha 226
 
847 serge 227
       ;    xor   eax,eax
228
       ;    mov   edi,0x280000
229
       ;    mov   ecx,(0x800000-0x280000) / 4
230
       ;    cld
231
       ;    rep   stosd
1 ha 232
 
847 serge 233
       ;    mov   edi,0x40000
234
       ;    mov   ecx,(0x90000-0x40000)/4
235
       ;    rep   stosd
1 ha 236
 
465 serge 237
; CLEAR KERNEL UNDEFINED GLOBALS
847 serge 238
       ;    mov   edi, endofcode-OS_BASE
239
       ;    mov   ecx, (uglobals_size/4)+4
240
       ;    rep   stosd
1 ha 241
 
465 serge 242
; SAVE & CLEAR 0-0xffff
1 ha 243
 
847 serge 244
       ;    xor esi, esi
245
       ;    mov   edi,0x2F0000
246
       ;    mov   ecx,0x10000 / 4
247
       ;    rep   movsd
248
       ;    xor edi, edi
249
       ;    mov   ecx,0x10000 / 4
250
       ;    rep   stosd
429 serge 251
 
847 serge 252
        ;   call test_cpu
742 Rus 253
	   bts [cpu_caps-OS_BASE], CAPS_TSC	;force use rdtsc
424 spraid 254
 
847 serge 255
        ;   call init_BIOS32
837 serge 256
 
839 serge 257
           mov dword [sys_pgdir-OS_BASE], PG_LARGE+PG_SW
258
           mov dword [sys_pgdir-OS_BASE+4], PG_LARGE+PG_SW+4*1024*1024
1 ha 259
 
839 serge 260
           mov ecx, 32
261
           lea edi, [sys_pgdir-OS_BASE+0xE00]
262
           mov eax, PG_LARGE+PG_SW
263
@@:
264
           stosd
265
           add eax, 4*1024*1024
266
           loop @B
837 serge 267
 
839 serge 268
           mov ebx, cr4
269
           or ebx, CR4_PSE
270
           and ebx, not CR4_PAE
271
           mov cr4, ebx
272
 
1 ha 273
 
742 Rus 274
	   mov eax, sys_pgdir-OS_BASE
839 serge 275
           mov ebx, cr0
276
           or ebx,CR0_PG+CR0_WP
1 ha 277
 
839 serge 278
           mov cr3, eax
279
           mov cr0, ebx
1 ha 280
 
742 Rus 281
	   lgdt [gdts]
282
	   jmp pword os_code:high_code
1 ha 283
 
513 serge 284
align 4
742 Rus 285
bios32_entry	dd ?
286
tmp_page_tabs	dd ?
586 serge 287
 
847 serge 288
;use16
289
;org $-0x10000
290
;include "boot/shutdown.inc" ; shutdown or restart
291
;org $+0x10000
292
;use32
498 diamond 293
 
465 serge 294
__DEBUG__ fix 1
295
__DEBUG_LEVEL__ fix 1
380 serge 296
 
465 serge 297
org OS_BASE+$
1 ha 298
 
839 serge 299
MEM_WB     equ 6               ;write-back memory
300
MEM_WC     equ 1               ;write combined memory
301
MEM_UC     equ 0               ;uncached memory
302
 
303
 
846 serge 304
include 'printf.inc'
843 serge 305
include 'core/mm.asm'
839 serge 306
 
847 serge 307
include 'core/init.asm'
839 serge 308
 
309
align 4
847 serge 310
proc test_cpu
311
           locals
312
              cpu_type   dd ?
313
              cpu_id     dd ?
314
              cpu_Intel  dd ?
315
              cpu_AMD    dd ?
316
           endl
317
 
318
           mov [cpu_type], 0
319
           xor eax, eax
320
           mov [cpu_caps], eax
321
           mov [cpu_caps+4], eax
322
 
323
           pushfd
324
           pop eax
325
           mov ecx, eax
326
           xor eax, 0x40000
327
           push eax
328
           popfd
329
           pushfd
330
           pop eax
331
           xor eax, ecx
332
           mov [cpu_type], CPU_386
333
           jz .end_cpuid
334
           push ecx
335
           popfd
336
 
337
           mov [cpu_type], CPU_486
338
           mov eax, ecx
339
           xor eax, 0x200000
340
           push eax
341
           popfd
342
           pushfd
343
           pop eax
344
           xor eax, ecx
345
           je .end_cpuid
346
           mov [cpu_id], 1
347
 
348
           xor eax, eax
349
           cpuid
350
 
351
           mov [cpu_vendor], ebx
352
           mov [cpu_vendor+4], edx
353
           mov [cpu_vendor+8], ecx
354
           cmp ebx, dword [intel_str]
355
           jne .check_AMD
356
           cmp edx, dword [intel_str+4]
357
           jne .check_AMD
358
           cmp ecx, dword [intel_str+8]
359
           jne .check_AMD
360
           mov [cpu_Intel], 1
361
           cmp eax, 1
362
           jl .end_cpuid
363
           mov eax, 1
364
           cpuid
365
           mov [cpu_sign], eax
366
           mov [cpu_info],  ebx
367
           mov [cpu_caps],  edx
368
           mov [cpu_caps+4],ecx
369
 
370
           shr eax, 8
371
           and eax, 0x0f
372
           ret
373
.end_cpuid:
374
           mov eax, [cpu_type]
375
           ret
376
 
377
.check_AMD:
378
           cmp ebx, dword [AMD_str]
379
           jne .unknown
380
           cmp edx, dword [AMD_str+4]
381
           jne .unknown
382
           cmp ecx, dword [AMD_str+8]
383
           jne .unknown
384
           mov [cpu_AMD], 1
385
           cmp eax, 1
386
           jl .unknown
387
           mov eax, 1
388
           cpuid
389
           mov [cpu_sign], eax
390
           mov [cpu_info],  ebx
391
           mov [cpu_caps],  edx
392
           mov [cpu_caps+4],ecx
393
           shr eax, 8
394
           and eax, 0x0f
395
           ret
396
.unknown:
397
           mov eax, 1
398
           cpuid
399
           mov [cpu_sign], eax
400
           mov [cpu_info],  ebx
401
           mov [cpu_caps],  edx
402
           mov [cpu_caps+4],ecx
403
           shr eax, 8
404
           and eax, 0x0f
405
           ret
406
endp
407
 
408
align 4
465 serge 409
high_code:
742 Rus 410
	   mov ax,os_stack
847 serge 411
           mov dx,app_data
742 Rus 412
	   mov ss,ax
847 serge 413
           mov esp, __os_stack
1 ha 414
 
847 serge 415
           mov ds, dx
416
           mov es, dx
417
           mov fs, dx
418
           mov gs, dx
1 ha 419
 
847 serge 420
           push ecx
421
           push ebx
839 serge 422
 
847 serge 423
         ;  mov dword [sys_pgdir-OS_BASE+(page_tabs shr 20)], sys_pgdir+PG_SW-OS_BASE
1 ha 424
 
847 serge 425
         ;  bt [cpu_caps], CAPS_PGE
426
         ;  jnc @F
519 serge 427
 
847 serge 428
         ;  or dword [sys_pgdir-OS_BASE+(OS_BASE shr 20)], PG_GLOBAL
429
 
430
         ;  mov ebx, cr4
431
         ;  or ebx, CR4_PGE
432
         ;  mov cr4, ebx
519 serge 433
@@:
847 serge 434
         ;  xor eax, eax
435
         ;  mov dword [sys_pgdir], eax
436
         ;  mov dword [sys_pgdir+4], eax
519 serge 437
 
847 serge 438
         ;  mov eax, cr3
439
         ;  mov cr3, eax           ; flush TLB
465 serge 440
 
846 serge 441
           mov edx, 0x3fB
442
           mov eax, 3
443
           out dx, al
444
 
847 serge 445
           call test_cpu
446
           call _init
839 serge 447
 
841 serge 448
	   mov [tss._ss0], os_stack
847 serge 449
           mov [tss._esp0], __os_stack
450
           mov [tss._esp], __os_stack
841 serge 451
	   mov [tss._cs],os_code
452
	   mov [tss._ss],os_stack
453
	   mov [tss._ds],app_data
454
	   mov [tss._es],app_data
455
	   mov [tss._fs],app_data
456
	   mov [tss._gs],app_data
457
	   mov [tss._io],128
458
;Add IO access table - bit array of permitted ports
459
	   mov edi, tss._io_map_0
460
	   xor eax, eax
461
	   not eax
462
	   mov ecx, 8192/4
463
	   rep stosd		     ; access to 4096*8=65536 ports
464
 
465
	   mov	ax,tss0
466
	   ltr	ax
467
 
847 serge 468
           xchg bx, bx
469
 
470
           mov ecx, 1280*1024
471
           fastcall _balloc
472
           mov [_display_data], eax
473
 
474
           mov ecx, (unpack.LZMA_BASE_SIZE+(unpack.LZMA_LIT_SIZE shl \
475
                    (unpack.lc+unpack.lp)))*4
476
           fastcall _balloc
477
           mov [unpack.p], eax
478
 
479
; MEMORY MODEL
480
 
841 serge 481
           call init_kernel_heap     ; FIXME initialize heap after pager
482
 
843 serge 483
           call _init_mm
484
           mov [pg_data.pg_mutex], 0
839 serge 485
 
847 serge 486
           hlt
487
 
488
 
1 ha 489
; SAVE REAL MODE VARIABLES
742 Rus 490
	mov	ax, [BOOT_VAR + 0x9031]
491
	mov	[IDEContrRegsBaseAddr], ax
76 mario79 492
; --------------- APM ---------------------
465 serge 493
 
494
; init selectors
742 Rus 495
    mov ebx,	[BOOT_VAR+0x9040]	       ; offset of APM entry point
465 serge 496
    movzx eax, word [BOOT_VAR+0x9050] ; real-mode segment base address of
742 Rus 497
				      ; protected-mode 32-bit code segment
465 serge 498
    movzx ecx, word [BOOT_VAR+0x9052] ; real-mode segment base address of
742 Rus 499
				      ; protected-mode 16-bit code segment
465 serge 500
    movzx edx, word [BOOT_VAR+0x9054] ; real-mode segment base address of
742 Rus 501
				      ; protected-mode 16-bit data segment
465 serge 502
 
503
    shl    eax, 4
504
    mov    [dword apm_code_32 + 2], ax
505
    shr    eax, 16
506
    mov    [dword apm_code_32 + 4], al
507
 
508
    shl    ecx, 4
509
    mov    [dword apm_code_16 + 2], cx
510
    shr    ecx, 16
511
    mov    [dword apm_code_16 + 4], cl
512
 
513
    shl    edx, 4
514
    mov    [dword apm_data_16 + 2], dx
515
    shr    edx, 16
516
    mov    [dword apm_data_16 + 4], dl
517
 
518
    mov    dword[apm_entry], ebx
76 mario79 519
    mov    word [apm_entry + 4], apm_code_32 - gdts
520
 
465 serge 521
    mov    eax, [BOOT_VAR + 0x9044]    ; version & flags
76 mario79 522
    mov    [apm_vf], eax
523
; -----------------------------------------
465 serge 524
;        movzx eax,byte [BOOT_VAR+0x9010]  ; mouse port
1 ha 525
;        mov   [0xF604],byte 1  ;al
742 Rus 526
	mov	al, [BOOT_VAR+0x901F]	; DMA access
527
	mov	[allow_dma_access], al
528
	mov   al,[BOOT_VAR+0x9000]	  ; bpp
529
	mov   [ScreenBPP],al
753 serge 530
 
742 Rus 531
	movzx eax,word [BOOT_VAR+0x900A]  ; X max
532
	dec   eax
759 Rus 533
	mov   [Screen_Max_X],eax
742 Rus 534
	mov   [screen_workarea.right],eax
535
	movzx eax,word [BOOT_VAR+0x900C]  ; Y max
536
	dec   eax
759 Rus 537
	mov   [Screen_Max_Y],eax
742 Rus 538
	mov   [screen_workarea.bottom],eax
539
	movzx eax,word [BOOT_VAR+0x9008]  ; screen mode
540
	mov   [SCR_MODE],eax
541
	mov   eax,[BOOT_VAR+0x9014]	  ; Vesa 1.2 bnk sw add
542
	mov   [BANK_SWITCH],eax
543
	mov   [BytesPerScanLine],word 640*4	    ; Bytes PerScanLine
544
	cmp   [SCR_MODE],word 0x13	    ; 320x200
545
	je    @f
546
	cmp   [SCR_MODE],word 0x12	    ; VGA 640x480
547
	je    @f
548
	mov   ax,[BOOT_VAR+0x9001]	  ; for other modes
549
	mov   [BytesPerScanLine],ax
465 serge 550
@@:
742 Rus 551
	mov	esi, BOOT_VAR+0x9080
552
	movzx	ecx, byte [esi-1]
553
	mov	[NumBiosDisks], ecx
554
	mov	edi, BiosDisksData
555
	rep	movsd
1 ha 556
 
557
; GRAPHICS ADDRESSES
558
 
742 Rus 559
	mov	byte [BOOT_VAR+0x901e],0x0
560
	mov	eax,[BOOT_VAR+0x9018]
561
	mov	[LFBAddress],eax
1 ha 562
 
742 Rus 563
	cmp	[SCR_MODE],word 0100000000000000b
564
	jge	setvesa20
565
	cmp	[SCR_MODE],word 0x13
566
	je	v20ga32
567
	mov	[PUTPIXEL],dword Vesa12_putpixel24  ; Vesa 1.2
568
	mov	[GETPIXEL],dword Vesa12_getpixel24
569
	cmp	[ScreenBPP],byte 24
570
	jz	ga24
571
	mov	[PUTPIXEL],dword Vesa12_putpixel32
572
	mov	[GETPIXEL],dword Vesa12_getpixel32
1 ha 573
      ga24:
742 Rus 574
	jmp	v20ga24
1 ha 575
      setvesa20:
742 Rus 576
	mov	[PUTPIXEL],dword Vesa20_putpixel24  ; Vesa 2.0
577
	mov	[GETPIXEL],dword Vesa20_getpixel24
578
	cmp	[ScreenBPP],byte 24
579
	jz	v20ga24
1 ha 580
      v20ga32:
742 Rus 581
	mov	[PUTPIXEL],dword Vesa20_putpixel32
582
	mov	[GETPIXEL],dword Vesa20_getpixel32
1 ha 583
      v20ga24:
742 Rus 584
	cmp	[SCR_MODE],word 0x12		    ; 16 C VGA 640x480
585
	jne	no_mode_0x12
586
	mov	[PUTPIXEL],dword VGA_putpixel
587
	mov	[GETPIXEL],dword Vesa20_getpixel32
1 ha 588
      no_mode_0x12:
589
 
375 Ghost 590
; -------- Fast System Call init ----------
378 serge 591
; Intel SYSENTER/SYSEXIT (AMD CPU support it too)
742 Rus 592
	   bt [cpu_caps], CAPS_SEP
593
	   jnc .SEnP   ; SysEnter not Present
594
	   xor edx, edx
595
	   mov ecx, MSR_SYSENTER_CS
596
	   mov eax, os_code
597
	   wrmsr
598
	   mov ecx, MSR_SYSENTER_ESP
434 diamond 599
;           mov eax, sysenter_stack ; Check it
742 Rus 600
	   xor	   eax, eax
601
	   wrmsr
602
	   mov ecx, MSR_SYSENTER_EIP
603
	   mov eax, sysenter_entry
604
	   wrmsr
375 Ghost 605
.SEnP:
378 serge 606
; AMD SYSCALL/SYSRET
742 Rus 607
	   cmp byte[cpu_vendor], 'A'
608
	   jne .noSYSCALL
609
	   mov eax, 0x80000001
610
	   cpuid
611
	   test edx, 0x800  ; bit_11 - SYSCALL/SYSRET support
612
	   jz .noSYSCALL
613
	   mov ecx, MSR_AMD_EFER
614
	   rdmsr
615
	   or eax, 1   ; bit_0 - System Call Extension (SCE)
616
	   wrmsr
164 serge 617
 
375 Ghost 618
	; !!!! It`s dirty hack, fix it !!!
619
	; Bits of EDX :
620
	; Bit 31–16 During the SYSRET instruction, this field is copied into the CS register
621
	;  and the contents of this field, plus 8, are copied into the SS register.
622
	; Bit 15–0 During the SYSCALL instruction, this field is copied into the CS register
623
	;  and the contents of this field, plus 8, are copied into the SS register.
624
 
742 Rus 625
	; mov   edx, (os_code + 16) * 65536 + os_code
626
	   mov edx, 0x1B0008
375 Ghost 627
 
742 Rus 628
	   mov eax, syscall_entry
629
	   mov ecx, MSR_AMD_STAR
630
	   wrmsr
375 Ghost 631
.noSYSCALL:
632
; -----------------------------------------
633
 
465 serge 634
; LOAD IDT
378 serge 635
 
742 Rus 636
	   call build_interrupt_table
637
	   lidt [idtreg]
378 serge 638
 
841 serge 639
           mov [LFBSize], 0x800000
742 Rus 640
	   call init_LFB
841 serge 641
           call init_fpu
742 Rus 642
	   call init_malloc
276 serge 643
 
742 Rus 644
	   stdcall alloc_kernel_space, 0x51000
645
	   mov [default_io_map], eax
465 serge 646
 
742 Rus 647
	   add eax, 0x2000
648
	   mov [ipc_tmp], eax
649
	   mov ebx, 0x1000
164 serge 650
 
742 Rus 651
	   add eax, 0x40000
652
	   mov [proc_mem_map], eax
164 serge 653
 
742 Rus 654
	   add eax, 0x8000
655
	   mov [proc_mem_pdir], eax
164 serge 656
 
742 Rus 657
	   add eax, ebx
658
	   mov [proc_mem_tab], eax
164 serge 659
 
742 Rus 660
	   add eax, ebx
661
	   mov [tmp_task_pdir], eax
164 serge 662
 
742 Rus 663
	   add eax, ebx
664
	   mov [tmp_task_ptab], eax
164 serge 665
 
742 Rus 666
	   add eax, ebx
667
	   mov [ipc_pdir], eax
164 serge 668
 
742 Rus 669
	   add eax, ebx
670
	   mov [ipc_ptab], eax
164 serge 671
 
742 Rus 672
	   call init_events
673
	   mov eax, srv.fd-SRV_FD_OFFSET
674
	   mov [srv.fd], eax
675
	   mov [srv.bk], eax
278 serge 676
 
742 Rus 677
	   mov edi, irq_tab
678
	   xor eax, eax
679
	   mov ecx, 16
680
	   rep stosd
164 serge 681
 
41 mikedld 682
;Set base of graphic segment to linear address of LFB
742 Rus 683
	mov	eax,[LFBAddress]	  ; set for gs
684
	mov	[graph_data_l+2],ax
685
	shr	eax,16
686
	mov	[graph_data_l+4],al
687
	mov	[graph_data_l+7],ah
1 ha 688
 
742 Rus 689
	mov [CURRENT_TASK],dword 1
690
	mov [TASK_COUNT],dword 1
691
	mov [TASK_BASE],dword TASK_DATA
692
	mov [current_slot], SLOT_BASE+256
429 serge 693
 
469 serge 694
; set background
742 Rus 695
	xor  eax,eax
696
	inc  eax
697
	mov   [BgrDrawMode],eax
698
	mov   [BgrDataWidth],eax
699
	mov   [BgrDataHeight],eax
700
	mov    [mem_BACKGROUND],4095
701
	stdcall kernel_alloc, [mem_BACKGROUND]
702
	mov [img_background], eax
469 serge 703
 
742 Rus 704
	mov	[SLOT_BASE + 256 + APPDATA.dir_table], sys_pgdir - OS_BASE
469 serge 705
 
709 diamond 706
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
707
 
742 Rus 708
	call  rerouteirqs
709 diamond 709
 
710
; Initialize system V86 machine
742 Rus 711
	call	init_sys_v86
709 diamond 712
 
725 diamond 713
; TIMER SET TO 1/100 S
714
 
742 Rus 715
	mov   al,0x34		   ; set to 100Hz
716
	out   0x43,al
717
	mov   al,0x9b		   ; lsb    1193180 / 1193
718
	out   0x40,al
719
	mov   al,0x2e		   ; msb
720
	out   0x40,al
725 diamond 721
 
722
; Enable timer IRQ (IRQ0) and hard drives IRQs (IRQ14, IRQ15)
723
; they are used: when partitions are scanned, hd_read relies on timer
742 Rus 724
	mov	al, 0xFE
725
	out	0x21, al
726
	mov	al, 0x3F
727
	out	0xA1, al
725 diamond 728
 
256 diamond 729
;!!!!!!!!!!!!!!!!!!!!!!!!!!
730
include 'detect/disks.inc'
731
;!!!!!!!!!!!!!!!!!!!!!!!!!!
732
 
521 diamond 733
  call Parser_params
734
 
1 ha 735
; READ RAMDISK IMAGE FROM HD
736
 
737
;!!!!!!!!!!!!!!!!!!!!!!!
846 serge 738
;include 'boot/rdload.inc'
1 ha 739
;!!!!!!!!!!!!!!!!!!!!!!!
740
;    mov    [dma_hdd],1
741
; CALCULATE FAT CHAIN FOR RAMDISK
742
 
846 serge 743
 
742 Rus 744
	call  calculatefatchain
1 ha 745
 
746
 
847 serge 747
 ; mov ax,[OS_BASE+0x10000+bx_from_load]
748
 ; cmp ax,'r1'           ; if using not ram disk, then load librares and parameters {SPraid.simba}
749
 ; je  no_lib_load
488 spraid 750
; LOADING LIBRARES
847 serge 751
;   stdcall dll.Load,@IMPORT                 ; loading librares for kernel (.obj files)
752
;   call load_file_parse_table               ; prepare file parse table
753
;   call set_kernel_conf                     ; configure devices and gui
754
;no_lib_load:
488 spraid 755
 
1 ha 756
; LOAD FONTS I and II
757
 
742 Rus 758
	stdcall read_file, char, FONT_I, 0, 2304
759
	stdcall read_file, char2, FONT_II, 0, 2560
490 serge 760
 
742 Rus 761
	mov   esi,boot_fonts
762
	call  boot_log
1 ha 763
 
764
; PRINT AMOUNT OF MEMORY
742 Rus 765
	mov	esi, boot_memdetect
766
	call	boot_log
1 ha 767
 
742 Rus 768
	movzx	ecx, word [boot_y]
769
	or	ecx, (10+29*6) shl 16 ; "Determining amount of memory"
770
	sub	ecx, 10
771
	mov	edx, 0xFFFFFF
846 serge 772
        mov     ebx, [_mem_amount]
742 Rus 773
	shr	ebx, 20
774
	mov	edi, 1
775
	mov	eax, 0x00040000
776
	call	display_number_force
41 mikedld 777
 
465 serge 778
; BUILD SCHEDULER
779
 
742 Rus 780
	call   build_scheduler ; sys32.inc
465 serge 781
 
742 Rus 782
	mov    esi,boot_devices
783
	call   boot_log
567 serge 784
 
742 Rus 785
	mov  [pci_access_enabled],1
567 serge 786
 
1 ha 787
 
788
; SET PRELIMINARY WINDOW STACK AND POSITIONS
789
 
742 Rus 790
	mov   esi,boot_windefs
791
	call  boot_log
792
	call  setwindowdefaults
1 ha 793
 
794
; SET BACKGROUND DEFAULTS
795
 
742 Rus 796
	mov   esi,boot_bgr
797
	call  boot_log
798
	call  init_background
799
	call  calculatebackground
1 ha 800
 
801
; RESERVE SYSTEM IRQ'S JA PORT'S
802
 
742 Rus 803
	mov   esi,boot_resirqports
804
	call  boot_log
805
	call  reserve_irqs_ports
1 ha 806
 
807
; SET PORTS FOR IRQ HANDLERS
808
 
742 Rus 809
	mov  esi,boot_setrports
810
	call boot_log
769 Rus 811
	;call setirqreadports
1 ha 812
 
813
; SET UP OS TASK
814
 
742 Rus 815
	mov  esi,boot_setostask
816
	call boot_log
214 serge 817
 
742 Rus 818
	xor  eax, eax
819
	mov  dword [SLOT_BASE+APPDATA.fpu_state], fpu_data
820
	mov  dword [SLOT_BASE+APPDATA.fpu_handler], eax
821
	mov  dword [SLOT_BASE+APPDATA.sse_handler], eax
164 serge 822
 
742 Rus 823
	; name for OS/IDLE process
281 serge 824
 
742 Rus 825
	mov dword [SLOT_BASE+256+APPDATA.app_name],   dword 'OS/I'
826
	mov dword [SLOT_BASE+256+APPDATA.app_name+4], dword 'DLE '
847 serge 827
        mov edi,  __os_stack-8192+512
742 Rus 828
	mov dword [SLOT_BASE+256+APPDATA.pl0_stack], edi
829
	add edi, 0x2000-512
830
	mov dword [SLOT_BASE+256+APPDATA.fpu_state], edi
831
	mov dword [SLOT_BASE+256+APPDATA.saved_esp0], edi ; just for case
832
	mov dword [SLOT_BASE+256+APPDATA.io_map],\
833
		  (tss._io_map_0-OS_BASE+PG_MAP)
834
	mov dword [SLOT_BASE+256+APPDATA.io_map+4],\
835
		  (tss._io_map_1-OS_BASE+PG_MAP)
357 serge 836
 
742 Rus 837
	mov esi, fpu_data
838
	mov ecx, 512/4
839
	cld
840
	rep movsd
357 serge 841
 
843 serge 842
        mov dword [SLOT_BASE+256+APPDATA.fpu_handler], eax
742 Rus 843
	mov dword [SLOT_BASE+256+APPDATA.sse_handler], eax
214 serge 844
 
742 Rus 845
	mov ebx, SLOT_BASE+256+APP_OBJ_OFFSET
846
	mov  dword [SLOT_BASE+256+APPDATA.fd_obj], ebx
847
	mov  dword [SLOT_BASE+256+APPDATA.bk_obj], ebx
281 serge 848
 
742 Rus 849
	mov  dword [SLOT_BASE+256+APPDATA.cur_dir], sysdir_path
521 diamond 850
 
742 Rus 851
	; task list
852
	mov  [CURRENT_TASK],dword 1
853
	mov  [TASK_COUNT],dword 1
854
	mov  [current_slot], SLOT_BASE+256
855
	mov  [TASK_BASE],dword TASK_DATA
856
	mov  [TASK_DATA+TASKDATA.wnd_number], 1 ; on screen number
857
	mov  [TASK_DATA+TASKDATA.pid], 1	; process id number
858
	mov  [TASK_DATA+TASKDATA.mem_start], 0	; process base address
1 ha 859
 
843 serge 860
        call init_cursors
802 serge 861
        mov eax, [def_cursor]
742 Rus 862
	mov [SLOT_BASE+APPDATA.cursor],eax
863
	mov [SLOT_BASE+APPDATA.cursor+256],eax
281 serge 864
 
839 serge 865
       ; stdcall load_pe_driver, szAtiHW
837 serge 866
 
465 serge 867
  ; READ TSC / SECOND
281 serge 868
 
742 Rus 869
	mov   esi,boot_tsc
870
	call  boot_log
871
	cli
872
	call  _rdtsc
873
	mov   ecx,eax
874
	mov   esi,250		    ; wait 1/4 a second
875
	call  delay_ms
876
	call  _rdtsc
877
	sti
878
	sub   eax,ecx
879
	shl   eax,2
880
	mov   [CPU_FREQ],eax	      ; save tsc / sec
881
	mov ebx, 1000000
882
	div ebx
883
	mov [stall_mcs], eax
1 ha 884
 
885
; SET VARIABLES
886
 
742 Rus 887
	call  set_variables
1 ha 888
 
774 Rus 889
; SET MOUSE
890
 
891
	;call   detect_devices
892
	stdcall load_driver, szPS2MDriver
839 serge 893
       ; stdcall load_driver, szCOM_MDriver
774 Rus 894
 
895
	mov   esi,boot_setmouse
896
	call  boot_log
897
	call  setmouse
898
 
899
 
1 ha 900
; STACK AND FDC
901
 
839 serge 902
        call  stack_init
742 Rus 903
	call  fdc_init
1 ha 904
 
905
; PALETTE FOR 320x200 and 640x480 16 col
906
 
742 Rus 907
	cmp   [SCR_MODE],word 0x12
908
	jne   no_pal_vga
909
	mov   esi,boot_pal_vga
910
	call  boot_log
911
	call  paletteVGA
1 ha 912
      no_pal_vga:
913
 
742 Rus 914
	cmp   [SCR_MODE],word 0x13
915
	jne   no_pal_ega
916
	mov   esi,boot_pal_ega
917
	call  boot_log
918
	call  palette320x200
1 ha 919
      no_pal_ega:
920
 
921
; LOAD DEFAULT SKIN
922
 
742 Rus 923
	call	load_default_skin
1 ha 924
 
465 serge 925
;protect io permission map
926
 
742 Rus 927
	   mov esi, [default_io_map]
928
	   stdcall map_page,esi,(tss._io_map_0-OS_BASE), PG_MAP
929
	   add esi, 0x1000
930
	   stdcall map_page,esi,(tss._io_map_1-OS_BASE), PG_MAP
465 serge 931
 
742 Rus 932
	   stdcall map_page,tss._io_map_0,\
933
		   (tss._io_map_0-OS_BASE), PG_MAP
934
	   stdcall map_page,tss._io_map_1,\
935
		   (tss._io_map_1-OS_BASE), PG_MAP
465 serge 936
 
847 serge 937
;  mov ax,[OS_BASE+0x10000+bx_from_load]
938
;  cmp ax,'r1'           ; if not rused ram disk - load network configuration from files {SPraid.simba}
939
;  je  no_st_network
940
;        call set_network_conf
941
;  no_st_network:
512 spraid 942
 
1 ha 943
; LOAD FIRST APPLICATION
742 Rus 944
	cli
501 serge 945
 
742 Rus 946
	cmp   byte [BOOT_VAR+0x9030],1
947
	jne   no_load_vrr_m
237 serge 948
 
742 Rus 949
	mov	ebp, vrr_m
950
	call	fs_execute_from_sysdir
488 spraid 951
 
742 Rus 952
	cmp   eax,2		     ; if vrr_m app found (PID=2)
953
	je    first_app_found
41 mikedld 954
 
237 serge 955
no_load_vrr_m:
488 spraid 956
 
837 serge 957
 
742 Rus 958
	mov	ebp, firstapp
959
	call	fs_execute_from_sysdir
488 spraid 960
 
742 Rus 961
	cmp   eax,2		     ; continue if a process has been loaded
962
	je    first_app_found
501 serge 963
 
742 Rus 964
	mov	esi, boot_failed
965
	call	boot_log
653 diamond 966
 
742 Rus 967
	mov   eax, 0xDEADBEEF	     ; otherwise halt
968
	hlt
501 serge 969
 
237 serge 970
first_app_found:
501 serge 971
 
742 Rus 972
	cli
1 ha 973
 
742 Rus 974
	;mov   [TASK_COUNT],dword 2
975
	mov   [CURRENT_TASK],dword 1	   ; set OS task fisrt
1 ha 976
 
21 poddubny 977
; SET KEYBOARD PARAMETERS
742 Rus 978
	mov   al, 0xf6	       ; reset keyboard, scan enabled
979
	call  kb_write
1 ha 980
 
742 Rus 981
	; wait until 8042 is ready
982
	xor ecx,ecx
841 serge 983
@@:
742 Rus 984
	in     al,64h
985
	and    al,00000010b
986
	loopnz @b
1 ha 987
 
742 Rus 988
	mov   al, 0xF3	     ; set repeat rate & delay
989
	call  kb_write
265 diamond 990
;        call  kb_read
742 Rus 991
	mov   al, 0 ; 30 250 ;00100010b ; 24 500  ;00100100b  ; 20 500
992
	call  kb_write
265 diamond 993
;        call  kb_read
1 ha 994
     ;// mike.dld [
742 Rus 995
	call  set_lights
1 ha 996
     ;// mike.dld ]
997
 
21 poddubny 998
; START MULTITASKING
1 ha 999
 
847 serge 1000
;if preboot_blogesc
1001
;        mov     esi, boot_tasking
1002
;        call    boot_log
1003
;.bll1:  in      al, 0x60        ; wait for ESC key press
1004
;        cmp     al, 129
1005
;        jne     .bll1
1006
;end if
767 diamond 1007
 
465 serge 1008
;       mov   [ENABLE_TASKSWITCH],byte 1        ; multitasking enabled
21 poddubny 1009
 
1 ha 1010
; UNMASK ALL IRQ'S
1011
 
742 Rus 1012
	mov   esi,boot_allirqs
1013
	call  boot_log
41 mikedld 1014
 
742 Rus 1015
	cli			     ;guarantee forbidance of interrupts.
1016
	mov   al,0		     ; unmask all irq's
1017
	out   0xA1,al
1018
	out   0x21,al
1 ha 1019
 
742 Rus 1020
	mov   ecx,32
1 ha 1021
 
1022
     ready_for_irqs:
1023
 
742 Rus 1024
	mov   al,0x20		     ; ready for irqs
1025
	out   0x20,al
1026
	out   0xa0,al
1 ha 1027
 
742 Rus 1028
	loop  ready_for_irqs	     ; flush the queue
1 ha 1029
 
774 Rus 1030
	stdcall attach_int_handler, dword 1, irq1, dword 0
164 serge 1031
 
1 ha 1032
;        mov    [dma_hdd],1
742 Rus 1033
	cmp	[IDEContrRegsBaseAddr], 0
1034
	setnz	[dma_hdd]
1035
	mov [timer_ticks_enable],1		; for cd driver
1 ha 1036
 
465 serge 1037
;        stdcall init_uart_service, DRV_ENTRY
1038
 
742 Rus 1039
	sti
1040
	call change_task
465 serge 1041
 
742 Rus 1042
	jmp osloop
465 serge 1043
 
725 diamond 1044
;        jmp   $                      ; wait here for timer to take control
1 ha 1045
 
742 Rus 1046
	; Fly :)
1 ha 1047
 
465 serge 1048
include 'unpacker.inc'
1049
include 'fdo.inc'
1050
 
1051
align 4
1052
boot_log:
742 Rus 1053
	 pushad
465 serge 1054
 
742 Rus 1055
	 mov   ebx,10*65536
1056
	 mov   bx,word [boot_y]
1057
	 add   [boot_y],dword 10
1058
	 mov   ecx,0x80ffffff	; ASCIIZ string with white color
1059
	 mov   edx,esi
1060
	 mov   edi,1
1061
	 call  dtext
465 serge 1062
 
742 Rus 1063
	 mov   [novesachecksum],1000
1064
	 call  checkVga_N13
465 serge 1065
 
764 Rus 1066
	 popad
465 serge 1067
 
742 Rus 1068
	 ret
465 serge 1069
 
1070
 
1 ha 1071
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1072
;                                                                    ;
33 mario79 1073
;                    MAIN OS LOOP START                              ;
1 ha 1074
;                                                                    ;
1075
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1076
align 32
1077
osloop:
742 Rus 1078
	call   [draw_pointer]
1079
	call   checkbuttons
1080
	call   checkwindows
49 mikedld 1081
;       call   check_window_move_request
742 Rus 1082
	call   checkmisc
1083
	call   checkVga_N13
839 serge 1084
        call   stack_handler
742 Rus 1085
	call   checkidle
1086
	call   check_fdd_motor_status
1087
	call   check_ATAPI_device_event
1088
	jmp    osloop
33 mario79 1089
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1090
;                                                                    ;
1091
;                      MAIN OS LOOP END                              ;
1092
;                                                                    ;
1093
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1 ha 1094
 
1095
checkidle:
742 Rus 1096
	pushad
1 ha 1097
 
742 Rus 1098
	cmp  [check_idle_semaphore],0
1099
	jne  no_idle_state
1 ha 1100
 
742 Rus 1101
	call change_task
1102
	mov  eax,[idlemem]
1103
	mov  ebx,[timer_ticks] ;[0xfdf0]
1104
	cmp  eax,ebx
1105
	jnz  idle_exit
1106
	call _rdtsc
1107
	mov  ecx,eax
1 ha 1108
      idle_loop:
742 Rus 1109
	hlt
1110
	cmp  [check_idle_semaphore],0
1111
	jne  idle_loop_exit
1112
	mov  eax,[timer_ticks] ;[0xfdf0]
1113
	cmp  ebx,eax
1114
	jz   idle_loop
1 ha 1115
      idle_loop_exit:
742 Rus 1116
	mov  [idlemem],eax
1117
	call _rdtsc
1118
	sub  eax,ecx
1119
	mov  ebx,[idleuse]
1120
	add  ebx,eax
1121
	mov  [idleuse],ebx
1 ha 1122
 
742 Rus 1123
	popad
1124
	ret
1 ha 1125
 
1126
      idle_exit:
1127
 
742 Rus 1128
	mov  ebx,[timer_ticks] ;[0xfdf0]
1129
	mov  [idlemem],ebx
1130
	call change_task
1 ha 1131
 
742 Rus 1132
	popad
1133
	ret
1 ha 1134
 
1135
      no_idle_state:
1136
 
742 Rus 1137
	dec  [check_idle_semaphore]
1 ha 1138
 
742 Rus 1139
	mov  ebx,[timer_ticks] ;[0xfdf0]
1140
	mov  [idlemem],ebx
1141
	call change_task
1 ha 1142
 
742 Rus 1143
	popad
1144
	ret
1 ha 1145
 
1146
uglobal
742 Rus 1147
  idlemem		dd   0x0
1148
  idleuse		dd   0x0
1149
  idleusesec		dd   0x0
1150
  check_idle_semaphore	dd   0x0
1 ha 1151
endg
1152
 
1153
 
1154
 
1155
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1156
;                                                                      ;
1157
;                   INCLUDED SYSTEM FILES                              ;
1158
;                                                                      ;
1159
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1160
 
1161
 
7 me_root 1162
include "kernel32.inc"
1 ha 1163
 
1164
 
1165
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1166
;                                                                      ;
1167
;                       KERNEL FUNCTIONS                               ;
1168
;                                                                      ;
1169
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1170
 
1171
reserve_irqs_ports:
1172
 
742 Rus 1173
	pushad
1 ha 1174
 
742 Rus 1175
	mov  [irq_owner+4*0], 1    ; timer
769 Rus 1176
	;mov  [irq_owner+4*1], 1    ; keyboard
742 Rus 1177
	mov  [irq_owner+4*6], 1    ; floppy diskette
1178
	mov  [irq_owner+4*13], 1   ; math co-pros
1179
	mov  [irq_owner+4*14], 1   ; ide I
1180
	mov  [irq_owner+4*15], 1   ; ide II
465 serge 1181
 
671 Ghost 1182
	; RESERVE PORTS
742 Rus 1183
	mov   edi,1		       ; 0x00-0x2d
1184
	mov   [RESERVED_PORTS],edi
1185
	shl   edi,4
1186
	mov   [RESERVED_PORTS+edi+0],dword 1
1187
	mov   [RESERVED_PORTS+edi+4],dword 0x0
1188
	mov   [RESERVED_PORTS+edi+8],dword 0x2d
269 serge 1189
 
742 Rus 1190
	inc   dword [RESERVED_PORTS]	      ; 0x30-0x4d
1191
	mov   edi,[RESERVED_PORTS]
1192
	shl   edi,4
1193
	mov   [RESERVED_PORTS+edi+0],dword 1
1194
	mov   [RESERVED_PORTS+edi+4],dword 0x30
1195
	mov   [RESERVED_PORTS+edi+8],dword 0x4d
269 serge 1196
 
742 Rus 1197
	inc   dword [RESERVED_PORTS]	      ; 0x50-0xdf
1198
	mov   edi,[RESERVED_PORTS]
1199
	shl   edi,4
1200
	mov   [RESERVED_PORTS+edi+0],dword 1
1201
	mov   [RESERVED_PORTS+edi+4],dword 0x50
1202
	mov   [RESERVED_PORTS+edi+8],dword 0xdf
233 serge 1203
 
742 Rus 1204
	inc   dword [RESERVED_PORTS]	      ; 0xe5-0xff
1205
	mov   edi,[RESERVED_PORTS]
1206
	shl   edi,4
1207
	mov   [RESERVED_PORTS+edi+0],dword 1
1208
	mov   [RESERVED_PORTS+edi+4],dword 0xe5
1209
	mov   [RESERVED_PORTS+edi+8],dword 0xff
233 serge 1210
 
742 Rus 1211
	popad
1212
	ret
1 ha 1213
 
1214
setirqreadports:
1215
 
742 Rus 1216
	mov   [irq12read+0],dword 0x60 + 0x01000000  ; read port 0x60 , byte
1217
	mov   [irq12read+4],dword 0		     ; end of port list
769 Rus 1218
	;mov   [irq04read+0],dword 0x3f8 + 0x01000000 ; read port 0x3f8 , byte
1219
	;mov   [irq04read+4],dword 0                  ; end of port list
1220
	;mov   [irq03read+0],dword 0x2f8 + 0x01000000 ; read port 0x2f8 , byte
1221
	;mov   [irq03read+4],dword 0                  ; end of port list
1 ha 1222
 
742 Rus 1223
	ret
1 ha 1224
 
1225
iglobal
1226
  process_number dd 0x1
1227
endg
1228
 
1229
set_variables:
1230
 
742 Rus 1231
	mov   ecx,0x100 		      ; flush port 0x60
1232
.fl60:	in    al,0x60
1233
	loop  .fl60
1234
	mov   [MOUSE_BUFF_COUNT],byte 0 		; mouse buffer
1235
	mov   [KEY_COUNT],byte 0		 ; keyboard buffer
1236
	mov   [BTN_COUNT],byte 0		 ; button buffer
381 serge 1237
;        mov   [MOUSE_X],dword 100*65536+100    ; mouse x/y
1 ha 1238
 
742 Rus 1239
	push  eax
1240
	mov   ax,[BOOT_VAR+0x900c]
1241
	shr   ax,1
1242
	shl   eax,16
1243
	mov   ax,[BOOT_VAR+0x900A]
1244
	shr   ax,1
1245
	mov   [MOUSE_X],eax
1246
	pop   eax
41 mikedld 1247
 
802 serge 1248
        mov   [BTN_ADDR],dword BUTTON_INFO    ; address of button list
1 ha 1249
 
1250
     ;!! IP 04.02.2005:
742 Rus 1251
	mov   [next_usage_update], 100
1252
	mov   byte [DONT_SWITCH], 0 ; change task if possible
1 ha 1253
 
742 Rus 1254
	ret
1 ha 1255
 
1256
;* mouse centered - start code- Mario79
1257
mouse_centered:
742 Rus 1258
	push  eax
759 Rus 1259
	mov   eax,[Screen_Max_X]
742 Rus 1260
	shr   eax,1
1261
	mov   [MOUSE_X],ax
759 Rus 1262
	mov   eax,[Screen_Max_Y]
742 Rus 1263
	shr   eax,1
1264
	mov   [MOUSE_Y],ax
1265
	pop   eax
1266
	ret
1 ha 1267
;* mouse centered - end code- Mario79
1268
 
1269
align 4
1270
 
1271
sys_outport:
1272
 
742 Rus 1273
    mov   edi,ebx	   ; separate flag for read / write
1 ha 1274
    and   ebx,65535
1275
 
381 serge 1276
    mov   ecx,[RESERVED_PORTS]
1 ha 1277
    test  ecx,ecx
1278
    jne   sopl8
1279
    mov   [esp+36],dword 1
1280
    ret
1281
 
1282
  sopl8:
379 serge 1283
    mov   edx,[TASK_BASE]
1 ha 1284
    mov   edx,[edx+0x4]
1285
    and   ebx,65535
1286
    cld
1287
  sopl1:
1288
 
1289
    mov   esi,ecx
1290
    shl   esi,4
381 serge 1291
    add   esi,RESERVED_PORTS
1 ha 1292
    cmp   edx,[esi+0]
1293
    jne   sopl2
1294
    cmp   ebx,[esi+4]
742 Rus 1295
    jb	  sopl2
1 ha 1296
    cmp   ebx,[esi+8]
742 Rus 1297
    jg	  sopl2
1 ha 1298
    jmp   sopl3
1299
 
1300
  sopl2:
1301
 
1302
    dec   ecx
1303
    jnz   sopl1
1304
    mov   [esp+36],dword 1
1305
    ret
1306
 
1307
  sopl3:
1308
 
1309
    test  edi,0x80000000 ; read ?
1310
    jnz   sopl4
1311
 
742 Rus 1312
    mov   dx,bx 	 ; write
1 ha 1313
    out   dx,al
1314
    mov   [esp+36],dword 0
1315
    ret
1316
 
1317
  sopl4:
1318
 
742 Rus 1319
    mov   dx,bx 	 ; read
1320
    in	  al,dx
1 ha 1321
    and   eax,0xff
1322
    mov   [esp+36],dword 0
1323
    mov   [esp+24],eax
1324
    ret
1325
 
1326
display_number:
1327
 
1328
; eax = print type, al=0 -> ebx is number
1329
;                   al=1 -> ebx is pointer
1330
;                   ah=0 -> display decimal
1331
;                   ah=1 -> display hexadecimal
1332
;                   ah=2 -> display binary
1333
;                   eax bits 16-21 = number of digits to display (0-32)
1334
;                   eax bits 22-31 = reserved
1335
;
1336
; ebx = number or pointer
1337
; ecx = x shl 16 + y
1338
; edx = color
655 mario79 1339
	xor	edi, edi
211 serge 1340
display_number_force:
652 mario79 1341
     push  eax
655 mario79 1342
     and   eax,0x3fffffff
1343
     cmp   eax,0xffff		 ; length > 0 ?
1344
     pop   eax
1 ha 1345
     jge   cont_displ
1346
     ret
1347
   cont_displ:
652 mario79 1348
     push  eax
655 mario79 1349
     and   eax,0x3fffffff
1350
     cmp   eax,61*0x10000	 ; length <= 60 ?
1351
     pop   eax
75 diamond 1352
     jb    cont_displ2
1 ha 1353
     ret
1354
   cont_displ2:
1355
 
1356
     pushad
1357
 
655 mario79 1358
     cmp   al,1 		 ; ecx is a pointer ?
1 ha 1359
     jne   displnl1
655 mario79 1360
     mov   ebp,ebx
1361
     add   ebp,4
840 serge 1362
     mov   ebp,[ebp]
1363
     mov   ebx,[ebx]
1 ha 1364
   displnl1:
1365
     sub   esp,64
1366
 
655 mario79 1367
     cmp   ah,0 		 ; DECIMAL
1 ha 1368
     jne   no_display_desnum
1369
     shr   eax,16
655 mario79 1370
     and   eax,0xC03f
652 mario79 1371
;     and   eax,0x3f
1372
     push  eax
75 diamond 1373
     and   eax,0x3f
1 ha 1374
     mov   edi,esp
194 diamond 1375
     add   edi,4+64-1
1 ha 1376
     mov   ecx,eax
1377
     mov   eax,ebx
1378
     mov   ebx,10
1379
   d_desnum:
1380
     xor   edx,edx
655 mario79 1381
     call  division_64_bits
1 ha 1382
     div   ebx
1383
     add   dl,48
1384
     mov   [edi],dl
1385
     dec   edi
1386
     loop  d_desnum
1387
     pop   eax
652 mario79 1388
     call  normalize_number
1 ha 1389
     call  draw_num_text
1390
     add   esp,64
1391
     popad
1392
     ret
1393
   no_display_desnum:
1394
 
655 mario79 1395
     cmp   ah,0x01		 ; HEXADECIMAL
1 ha 1396
     jne   no_display_hexnum
1397
     shr   eax,16
655 mario79 1398
     and   eax,0xC03f
652 mario79 1399
;     and   eax,0x3f
1400
     push  eax
75 diamond 1401
     and   eax,0x3f
1 ha 1402
     mov   edi,esp
194 diamond 1403
     add   edi,4+64-1
1 ha 1404
     mov   ecx,eax
1405
     mov   eax,ebx
1406
     mov   ebx,16
1407
   d_hexnum:
1408
     xor   edx,edx
655 mario79 1409
     call  division_64_bits
1 ha 1410
     div   ebx
1411
     add   edx,hexletters
1412
     mov   dl,[edx]
1413
     mov   [edi],dl
1414
     dec   edi
1415
     loop  d_hexnum
1416
     pop   eax
652 mario79 1417
     call  normalize_number
1 ha 1418
     call  draw_num_text
1419
     add   esp,64
1420
     popad
1421
     ret
1422
   no_display_hexnum:
1423
 
655 mario79 1424
     cmp   ah,0x02		 ; BINARY
1 ha 1425
     jne   no_display_binnum
1426
     shr   eax,16
655 mario79 1427
     and   eax,0xC03f
652 mario79 1428
;     and   eax,0x3f
1429
     push  eax
75 diamond 1430
     and   eax,0x3f
1 ha 1431
     mov   edi,esp
194 diamond 1432
     add   edi,4+64-1
1 ha 1433
     mov   ecx,eax
1434
     mov   eax,ebx
1435
     mov   ebx,2
1436
   d_binnum:
1437
     xor   edx,edx
655 mario79 1438
     call  division_64_bits
1 ha 1439
     div   ebx
1440
     add   dl,48
1441
     mov   [edi],dl
1442
     dec   edi
1443
     loop  d_binnum
1444
     pop   eax
652 mario79 1445
     call  normalize_number
1 ha 1446
     call  draw_num_text
1447
     add   esp,64
1448
     popad
1449
     ret
1450
   no_display_binnum:
1451
 
1452
     add   esp,64
1453
     popad
1454
     ret
1455
 
652 mario79 1456
normalize_number:
1457
     test  ah,0x80
1458
     jz   .continue
1459
     mov  ecx,48
1460
     and   eax,0x3f
1461
@@:
1462
     inc   edi
1463
     cmp   [edi],cl
1464
     jne   .continue
1465
     dec   eax
1466
     cmp   eax,1
665 diamond 1467
     ja    @r
1468
     mov   al,1
652 mario79 1469
.continue:
1470
     and   eax,0x3f
1471
     ret
1 ha 1472
 
655 mario79 1473
division_64_bits:
1474
     test  [esp+1+4],byte 0x40
1475
     jz   .continue
1476
     push  eax
1477
     mov   eax,ebp
1478
     div   ebx
1479
     mov   ebp,eax
1480
     pop   eax
1481
.continue:
1482
     ret
652 mario79 1483
 
1 ha 1484
draw_num_text:
684 diamond 1485
     mov   esi,eax
1486
     mov   edx,64+4
1487
     sub   edx,eax
1488
     add   edx,esp
1489
     mov   ebx,[esp+64+32-8+4]
1490
; add window start x & y
1491
     mov   ecx,[TASK_BASE]
465 serge 1492
 
1493
     mov   edi,[CURRENT_TASK]
1494
     shl   edi,8
1495
 
684 diamond 1496
     mov   eax,[ecx-twdw+WDATA.box.left]
1497
     add   eax,[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1498
     shl   eax,16
1499
     add   eax,[ecx-twdw+WDATA.box.top]
1500
     add   eax,[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1501
     add   ebx,eax
1502
     mov   ecx,[esp+64+32-12+4]
742 Rus 1503
	and	ecx, not 0x80000000	; force counted string
1504
	mov	eax, [esp+64+8] 	; background color (if given)
1505
	mov	edi, [esp+64+4]
139 diamond 1506
     jmp   dtext
1 ha 1507
 
1508
align 4
1509
 
1510
sys_setup:
1511
 
1512
; 1=roland mpu midi base , base io address
1513
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1514
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1515
; 5=system language, 1eng 2fi 3ger 4rus
1516
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1517
; 8=fat32 partition in hd
1518
; 9
1519
; 10 = sound dma channel
1520
; 11 = enable lba read
1521
; 12 = enable pci access
1522
 
1523
 
1524
     mov  [esp+36],dword 0
742 Rus 1525
     cmp  eax,1 		     ; MIDI
1 ha 1526
     jnz  nsyse1
1527
     cmp  ebx,0x100
1528
     jb   nsyse1
1529
     mov  edx,65535
1530
     cmp  edx,ebx
1531
     jb   nsyse1
1532
     mov  [midi_base],bx
1533
     mov  word [mididp],bx
1534
     inc  bx
1535
     mov  word [midisp],bx
1536
     ret
1537
 
283 diamond 1538
iglobal
1 ha 1539
midi_base dw 0
283 diamond 1540
endg
1 ha 1541
 
1542
   nsyse1:
1543
 
742 Rus 1544
     cmp  eax,2 		     ; KEYBOARD
1 ha 1545
     jnz  nsyse2
1546
     cmp  ebx,1
1547
     jnz  kbnobase
379 serge 1548
     mov  edi,[TASK_BASE]
115 poddubny 1549
     add  ecx,[edi+TASKDATA.mem_start]
1 ha 1550
     mov  eax,ecx
1551
     mov  ebx,keymap
1552
     mov  ecx,128
1553
     call memmove
1554
     ret
1555
   kbnobase:
1556
     cmp  ebx,2
1557
     jnz  kbnoshift
379 serge 1558
     mov  edi,[TASK_BASE]
115 poddubny 1559
     add  ecx,[edi+TASKDATA.mem_start]
1 ha 1560
     mov  eax,ecx
1561
     mov  ebx,keymap_shift
1562
     mov  ecx,128
1563
     call memmove
1564
     ret
1565
   kbnoshift:
1566
     cmp  ebx,3
1567
     jne  kbnoalt
379 serge 1568
     mov  edi,[TASK_BASE]
115 poddubny 1569
     add  ecx,[edi+TASKDATA.mem_start]
1 ha 1570
     mov  eax,ecx
1571
     mov  ebx,keymap_alt
1572
     mov  ecx,128
1573
     call memmove
1574
     ret
1575
   kbnoalt:
1576
     cmp  ebx,9
1577
     jnz  kbnocountry
1578
     mov  word [keyboard],cx
1579
     ret
1580
   kbnocountry:
1581
     mov  [esp+36],dword 1
1582
     ret
1583
   nsyse2:
742 Rus 1584
     cmp  eax,3 		     ; CD
802 serge 1585
     jnz  nsyse4
75 diamond 1586
     test ebx,ebx
1587
     jz   nosesl
1588
     cmp  ebx, 4
1589
     ja   nosesl
1 ha 1590
     mov  [cd_base],bl
1591
     cmp  ebx,1
1592
     jnz  noprma
1593
     mov  [cdbase],0x1f0
1594
     mov  [cdid],0xa0
1595
   noprma:
1596
     cmp  ebx,2
1597
     jnz  noprsl
1598
     mov  [cdbase],0x1f0
1599
     mov  [cdid],0xb0
1600
   noprsl:
1601
     cmp  ebx,3
1602
     jnz  nosema
1603
     mov  [cdbase],0x170
1604
     mov  [cdid],0xa0
1605
   nosema:
1606
     cmp  ebx,4
1607
     jnz  nosesl
1608
     mov  [cdbase],0x170
1609
     mov  [cdid],0xb0
1610
   nosesl:
1611
     ret
1612
 
1613
cd_base db 0
1614
 
1615
   nsyse4:
1616
 
742 Rus 1617
     cmp  eax,5 		     ; SYSTEM LANGUAGE
1 ha 1618
     jnz  nsyse5
1619
     mov  [syslang],ebx
1620
     ret
1621
   nsyse5:
1622
 
742 Rus 1623
     cmp  eax,7 		     ; HD BASE
1 ha 1624
     jne  nsyse7
75 diamond 1625
     test ebx,ebx
1626
     jz   nosethd
1627
     cmp  ebx,4
1628
     ja   nosethd
1 ha 1629
     mov  [hd_base],bl
1630
     cmp  ebx,1
1631
     jnz  noprmahd
1632
     mov  [hdbase],0x1f0
1633
     mov  [hdid],0x0
1634
     mov  [hdpos],1
1635
;     call set_FAT32_variables
1636
   noprmahd:
1637
     cmp  ebx,2
1638
     jnz  noprslhd
1639
     mov  [hdbase],0x1f0
1640
     mov  [hdid],0x10
1641
     mov  [hdpos],2
1642
;     call set_FAT32_variables
1643
   noprslhd:
1644
     cmp  ebx,3
1645
     jnz  nosemahd
1646
     mov  [hdbase],0x170
1647
     mov  [hdid],0x0
1648
     mov  [hdpos],3
1649
;     call set_FAT32_variables
1650
   nosemahd:
1651
     cmp  ebx,4
1652
     jnz  noseslhd
1653
     mov  [hdbase],0x170
1654
     mov  [hdid],0x10
1655
     mov  [hdpos],4
1656
;     call set_FAT32_variables
1657
   noseslhd:
1658
    call  reserve_hd1
321 diamond 1659
    call  reserve_hd_channel
1660
    call  free_hd_channel
742 Rus 1661
    mov   [hd1_status],0	; free
75 diamond 1662
   nosethd:
1 ha 1663
     ret
1664
 
283 diamond 1665
iglobal
1 ha 1666
hd_base db 0
283 diamond 1667
endg
1 ha 1668
 
802 serge 1669
nsyse7:
1 ha 1670
 
742 Rus 1671
     cmp  eax,8 		     ; HD PARTITION
1 ha 1672
     jne  nsyse8
1673
     mov  [fat32part],ebx
1674
;     call set_FAT32_variables
1675
    call  reserve_hd1
321 diamond 1676
    call  reserve_hd_channel
1677
    call  free_hd_channel
1 ha 1678
     pusha
1679
     call  choice_necessity_partition_1
1680
     popa
742 Rus 1681
    mov   [hd1_status],0	; free
1 ha 1682
     ret
1683
 
802 serge 1684
nsyse8:
742 Rus 1685
     cmp  eax,11		     ; ENABLE LBA READ
1 ha 1686
     jne  no_set_lba_read
1687
     and  ebx,1
1688
     mov  [lba_read_enabled],ebx
1689
     ret
1690
 
802 serge 1691
no_set_lba_read:
1692
     cmp  eax,12                     ; ENABLE PCI ACCESS
1 ha 1693
     jne  no_set_pci_access
1694
     and  ebx,1
1695
     mov  [pci_access_enabled],ebx
1696
     ret
1697
   no_set_pci_access:
1698
 
1699
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1700
include 'vmodeint.inc'
1701
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1702
 
75 diamond 1703
sys_setup_err:
1 ha 1704
     mov  [esp+36],dword -1
1705
     ret
1706
 
1707
align 4
1708
 
1709
sys_getsetup:
1710
 
1711
; 1=roland mpu midi base , base io address
1712
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1713
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1714
; 5=system language, 1eng 2fi 3ger 4rus
1715
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1716
; 8=fat32 partition in hd
1717
; 9=get hs timer tic
1718
 
1719
     cmp  eax,1
1720
     jne  ngsyse1
1721
     movzx eax,[midi_base]
1722
     mov  [esp+36],eax
1723
     ret
802 serge 1724
ngsyse1:
1 ha 1725
 
1726
     cmp  eax,2
1727
     jne  ngsyse2
1728
     cmp  ebx,1
1729
     jnz  kbnobaseret
379 serge 1730
     mov  edi,[TASK_BASE]
115 poddubny 1731
     add  ecx,[edi+TASKDATA.mem_start]
1 ha 1732
     mov  ebx,ecx
1733
     mov  eax,keymap
1734
     mov  ecx,128
1735
     call memmove
1736
     ret
802 serge 1737
kbnobaseret:
1 ha 1738
     cmp  ebx,2
1739
     jnz  kbnoshiftret
379 serge 1740
     mov  edi,[TASK_BASE]
115 poddubny 1741
     add  ecx,[edi+TASKDATA.mem_start]
1 ha 1742
     mov  ebx,ecx
1743
     mov  eax,keymap_shift
1744
     mov  ecx,128
1745
     call memmove
1746
     ret
802 serge 1747
kbnoshiftret:
1 ha 1748
     cmp  ebx,3
1749
     jne  kbnoaltret
379 serge 1750
     mov  edi,[TASK_BASE]
115 poddubny 1751
     add  ecx,[edi+TASKDATA.mem_start]
1 ha 1752
     mov  ebx,ecx
1753
     mov  eax,keymap_alt
1754
     mov  ecx,128
1755
     call memmove
1756
     ret
802 serge 1757
kbnoaltret:
1 ha 1758
     cmp  ebx,9
1759
     jnz  ngsyse2
1760
     movzx eax,word [keyboard]
1761
     mov  [esp+36],eax
1762
     ret
802 serge 1763
ngsyse2:
1 ha 1764
 
802 serge 1765
         cmp  eax,3
1766
         jnz  ngsyse3
1767
         movzx eax,[cd_base]
1768
         mov  [esp+36],eax
1769
         ret
1770
ngsyse3:
1771
         cmp  eax,5
1772
         jnz  ngsyse5
1773
         mov  eax,[syslang]
1774
         mov  [esp+36],eax
1775
         ret
1776
ngsyse5:
1 ha 1777
     cmp  eax,7
1778
     jnz  ngsyse7
1779
     movzx eax,[hd_base]
1780
     mov  [esp+36],eax
1781
     ret
802 serge 1782
ngsyse7:
1 ha 1783
     cmp  eax,8
1784
     jnz  ngsyse8
1785
     mov eax,[fat32part]
1786
     mov  [esp+36],eax
1787
     ret
802 serge 1788
ngsyse8:
1 ha 1789
     cmp  eax,9
1790
     jne  ngsyse9
1791
     mov  eax,[timer_ticks] ;[0xfdf0]
1792
     mov  [esp+36],eax
1793
     ret
802 serge 1794
ngsyse9:
1 ha 1795
     cmp  eax,11
1796
     jnz  ngsyse11
1797
     mov eax,[lba_read_enabled]
1798
     mov  [esp+36],eax
1799
     ret
802 serge 1800
ngsyse11:
1 ha 1801
     cmp  eax,12
1802
     jnz  ngsyse12
1803
     mov eax,[pci_access_enabled]
1804
     mov  [esp+36],eax
1805
     ret
802 serge 1806
ngsyse12:
1 ha 1807
     mov  [esp+36],dword 1
1808
     ret
1809
 
479 kastigar 1810
get_timer_ticks:
1811
    mov eax,[timer_ticks]
1812
    ret
1813
 
283 diamond 1814
iglobal
1 ha 1815
align 4
221 serge 1816
mousefn dd msscreen, mswin, msbutton, msset
742 Rus 1817
	dd app_load_cursor
1818
	dd app_set_cursor
1819
	dd app_delete_cursor
1820
	dd msz
283 diamond 1821
endg
1 ha 1822
 
1823
readmousepos:
1824
 
1825
; eax=0 screen relative
1826
; eax=1 window relative
1827
; eax=2 buttons pressed
221 serge 1828
; eax=3 set mouse pos   ; reserved
1829
; eax=4 load cursor
1830
; eax=5 set cursor
1831
; eax=6 delete cursor   ; reserved
479 kastigar 1832
; eax=7 get mouse_z
1 ha 1833
 
742 Rus 1834
	   cmp eax, 7
1835
	   ja msset
1836
	   jmp [mousefn+eax*4]
221 serge 1837
msscreen:
742 Rus 1838
	   mov	eax,[MOUSE_X]
1839
	   shl	eax,16
1840
	   mov	ax,[MOUSE_Y]
1841
	   mov	[esp+36],eax
1842
	   ret
221 serge 1843
mswin:
742 Rus 1844
	   mov	eax,[MOUSE_X]
1845
	   shl	eax,16
1846
	   mov	ax,[MOUSE_Y]
1847
	   mov	esi,[TASK_BASE]
1848
	   mov	bx, word [esi-twdw+WDATA.box.left]
1849
	   shl	ebx,16
1850
	   mov	bx, word [esi-twdw+WDATA.box.top]
1851
	   sub	eax,ebx
1 ha 1852
 
742 Rus 1853
	   mov	edi,[CURRENT_TASK]
1854
	   shl	edi,8
1855
	   sub	ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1856
	   rol	eax,16
1857
	   sub	ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1858
	   rol	eax,16
1859
	   mov	[esp+36],eax
1860
	   ret
221 serge 1861
msbutton:
742 Rus 1862
	   movzx eax,byte [BTN_DOWN]
1863
	   mov	[esp+36],eax
1864
	   ret
479 kastigar 1865
msz:
742 Rus 1866
	   mov	 edi, [TASK_COUNT]
1867
	   movzx edi, word [WIN_POS + edi*2]
1868
	   cmp	 edi, [CURRENT_TASK]
1869
	   jne	 @f
1870
	   mov	 ax,[MOUSE_SCROLL_H]
1871
	   shl	 eax,16
1872
	   mov	 ax,[MOUSE_SCROLL_V]
1873
	   mov	 [esp+36],eax
1874
	   mov	 [MOUSE_SCROLL_H],word 0
1875
	   mov	 [MOUSE_SCROLL_V],word 0
1876
	   ret
479 kastigar 1877
       @@:
742 Rus 1878
	   mov	[esp+36],dword 0
1879
	   ret
221 serge 1880
msset:
742 Rus 1881
	   ret
164 serge 1882
 
221 serge 1883
app_load_cursor:
465 serge 1884
      ;     add ebx, new_app_base
742 Rus 1885
	   cmp ebx, OS_BASE
1886
	   jae msset
1887
	   stdcall load_cursor, ebx, ecx
1888
	   mov [esp+36], eax
1889
	   ret
164 serge 1890
 
221 serge 1891
app_set_cursor:
742 Rus 1892
	   stdcall set_cursor, ebx
1893
	   mov [esp+36], eax
1894
	   ret
1 ha 1895
 
233 serge 1896
app_delete_cursor:
742 Rus 1897
	   stdcall delete_cursor, ebx
1898
	   mov [esp+36], eax
1899
	   ret
1 ha 1900
 
1901
is_input:
1902
 
1903
   push edx
742 Rus 1904
   mov	dx,word [midisp]
1905
   in	al,dx
1906
   and	al,0x80
1907
   pop	edx
1 ha 1908
   ret
1909
 
1910
is_output:
1911
 
1912
   push edx
742 Rus 1913
   mov	dx,word [midisp]
1914
   in	al,dx
1915
   and	al,0x40
1916
   pop	edx
1 ha 1917
   ret
1918
 
1919
 
1920
get_mpu_in:
1921
 
1922
   push edx
742 Rus 1923
   mov	dx,word [mididp]
1924
   in	al,dx
1925
   pop	edx
1 ha 1926
   ret
1927
 
1928
 
1929
put_mpu_out:
1930
 
1931
   push edx
742 Rus 1932
   mov	dx,word [mididp]
1933
   out	dx,al
1934
   pop	edx
1 ha 1935
   ret
1936
 
1937
 
1938
setuart:
1939
 
1940
 su1:
1941
   call is_output
742 Rus 1942
   cmp	al,0
1943
   jnz	su1
1944
   mov	dx,word [midisp]
1945
   mov	al,0xff
1946
   out	dx,al
1 ha 1947
 su2:
742 Rus 1948
   mov	dx,word [midisp]
1949
   mov	al,0xff
1950
   out	dx,al
1 ha 1951
   call is_input
742 Rus 1952
   cmp	al,0
1953
   jnz	su2
1 ha 1954
   call get_mpu_in
742 Rus 1955
   cmp	al,0xfe
1956
   jnz	su2
1 ha 1957
 su3:
1958
   call is_output
742 Rus 1959
   cmp	al,0
1960
   jnz	su3
1961
   mov	dx,word [midisp]
1962
   mov	al,0x3f
1963
   out	dx,al
1 ha 1964
 
1965
   ret
1966
 
1967
 
1968
align 4
1969
 
1970
sys_midi:
1971
 
1972
     cmp  [mididp],0
1973
     jnz  sm0
1974
     mov  [esp+36],dword 1
1975
     ret
1976
   sm0:
1977
 
1978
     cmp  eax,1
1979
     mov  [esp+36],dword 0
1980
     jnz  smn1
1981
     call setuart
1982
     ret
1983
   smn1:
1984
 
1985
     cmp  eax,2
1986
     jnz  smn2
1987
   sm10:
1988
     call get_mpu_in
1989
     call is_output
1990
     test al,al
1991
     jnz  sm10
1992
     mov  al,bl
1993
     call put_mpu_out
1994
     ret
1995
   smn2:
1996
 
1997
     ret
1998
 
1999
 
2000
detect_devices:
2001
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
769 Rus 2002
;include 'detect/commouse.inc'
479 kastigar 2003
;include 'detect/ps2mouse.inc'
1 ha 2004
;include 'detect/dev_fd.inc'
2005
;include 'detect/dev_hdcd.inc'
2006
;include 'detect/sear_par.inc'
2007
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2008
    ret
2009
 
2010
 
2011
sys_end:
2012
 
379 serge 2013
     mov   eax,[TASK_BASE]
115 poddubny 2014
     mov   [eax+TASKDATA.state], 3  ; terminate this program
41 mikedld 2015
 
742 Rus 2016
    waitterm:		 ; wait here for termination
684 diamond 2017
     mov   ebx,100
1 ha 2018
     call  delay_hs
2019
     jmp   waitterm
2020
 
75 diamond 2021
iglobal
170 serge 2022
align 4
75 diamond 2023
sys_system_table:
759 Rus 2024
	dd	exit_for_anyone 	; 1 = obsolete
742 Rus 2025
	dd	sysfn_terminate 	; 2 = terminate thread
2026
	dd	sysfn_activate		; 3 = activate window
2027
	dd	sysfn_getidletime	; 4 = get idle time
2028
	dd	sysfn_getcpuclock	; 5 = get cpu clock
2029
	dd	sysfn_saveramdisk	; 6 = save ramdisk
2030
	dd	sysfn_getactive 	; 7 = get active window
2031
	dd	sysfn_sound_flag	; 8 = get/set sound_flag
748 heavyiron 2032
	dd	sysfn_shutdown		; 9 = shutdown with parameter
742 Rus 2033
	dd	sysfn_minimize		; 10 = minimize window
2034
	dd	sysfn_getdiskinfo	; 11 = get disk subsystem info
2035
	dd	sysfn_lastkey		; 12 = get last pressed key
2036
	dd	sysfn_getversion	; 13 = get kernel version
2037
	dd	sysfn_waitretrace	; 14 = wait retrace
2038
	dd	sysfn_centermouse	; 15 = center mouse cursor
2039
	dd	sysfn_getfreemem	; 16 = get free memory size
2040
	dd	sysfn_getallmem 	; 17 = get total memory size
2041
	dd	sysfn_terminate2	; 18 = terminate thread using PID
2042
					;                 instead of slot
2043
	dd	sysfn_mouse_acceleration; 19 = set/get mouse acceleration
2044
	dd	sysfn_meminfo		; 20 = get extended memory info
2045
	dd	sysfn_pid_to_slot	; 21 = get slot number for pid
2046
	dd	sysfn_min_rest_window	; 22 = minimize and restore any window
75 diamond 2047
sysfn_num = ($ - sys_system_table)/4
2048
endg
2049
 
1 ha 2050
sys_system:
742 Rus 2051
	dec	ebx
2052
	cmp	ebx, sysfn_num
2053
	jae	@f
2054
	jmp	dword [sys_system_table + ebx*4]
75 diamond 2055
@@:
742 Rus 2056
	ret
1 ha 2057
 
214 serge 2058
 
759 Rus 2059
sysfn_shutdown: 	 ; 18.9 = system shutdown
748 heavyiron 2060
     cmp  ecx,1
2061
     jl   exit_for_anyone
2062
     cmp  ecx,4
2063
     jg   exit_for_anyone
2064
     mov  [BOOT_VAR+0x9030],cl
2065
 
379 serge 2066
     mov  eax,[TASK_COUNT]
709 diamond 2067
     mov  [SYS_SHUTDOWN],al
1 ha 2068
     mov  [shutdown_processes],eax
684 diamond 2069
     and  dword [esp+32], 0
748 heavyiron 2070
 exit_for_anyone:
1 ha 2071
     ret
2072
  uglobal
2073
   shutdown_processes: dd 0x0
2074
  endg
2075
 
742 Rus 2076
sysfn_terminate:	; 18.2 = TERMINATE
684 diamond 2077
     cmp  ecx,2
1 ha 2078
     jb   noprocessterminate
379 serge 2079
     mov  edx,[TASK_COUNT]
684 diamond 2080
     cmp  ecx,edx
75 diamond 2081
     ja   noprocessterminate
379 serge 2082
     mov  eax,[TASK_COUNT]
684 diamond 2083
     shl  ecx,5
2084
     mov  edx,[ecx+CURRENT_TASK+TASKDATA.pid]
2085
     add  ecx,CURRENT_TASK+TASKDATA.state
2086
     cmp  byte [ecx], 9
75 diamond 2087
     jz   noprocessterminate
41 mikedld 2088
 
1 ha 2089
     ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
742 Rus 2090
     mov  [ecx],byte 3	     ; clear possible i40's
1 ha 2091
     ;call MEM_Heap_UnLock
2092
 
2093
     cmp  edx,[application_table_status]    ; clear app table stat
2094
     jne  noatsc
2095
     mov  [application_table_status],0
2096
   noatsc:
75 diamond 2097
   noprocessterminate:
1 ha 2098
     ret
2099
 
85 halyavin 2100
sysfn_terminate2:
2101
;lock application_table_status mutex
164 serge 2102
.table_status:
85 halyavin 2103
    cli
2104
    cmp    [application_table_status],0
742 Rus 2105
    je	   .stf
85 halyavin 2106
    sti
2107
    call   change_task
2108
    jmp    .table_status
2109
.stf:
2110
    call   set_application_table_status
684 diamond 2111
    mov    eax,ecx
85 halyavin 2112
    call   pid_to_slot
2113
    test   eax,eax
742 Rus 2114
    jz	   .not_found
684 diamond 2115
    mov    ecx,eax
85 halyavin 2116
    cli
2117
    call   sysfn_terminate
2118
    mov    [application_table_status],0
2119
    sti
684 diamond 2120
    and    dword [esp+32],0
85 halyavin 2121
    ret
2122
.not_found:
2123
    mov    [application_table_status],0
742 Rus 2124
    or	   dword [esp+32],-1
85 halyavin 2125
    ret
2126
 
742 Rus 2127
sysfn_activate: 	; 18.3 = ACTIVATE WINDOW
684 diamond 2128
     cmp  ecx,2
105 poddubny 2129
     jb   .nowindowactivate
684 diamond 2130
     cmp  ecx,[TASK_COUNT]
105 poddubny 2131
     ja   .nowindowactivate
2132
 
2133
     mov   [window_minimize], 2   ; restore window if minimized
2134
 
684 diamond 2135
     movzx esi, word [WIN_STACK + ecx*2]
379 serge 2136
     cmp   esi, [TASK_COUNT]
105 poddubny 2137
     je    .nowindowactivate ; already active
2138
 
684 diamond 2139
     mov   edi, ecx
105 poddubny 2140
     shl   edi, 5
2141
     add   edi, window_data
684 diamond 2142
     movzx esi, word [WIN_STACK + ecx * 2]
380 serge 2143
     lea   esi, [WIN_POS + esi * 2]
105 poddubny 2144
     call  waredraw
2145
.nowindowactivate:
1 ha 2146
     ret
41 mikedld 2147
 
742 Rus 2148
sysfn_getidletime:		; 18.4 = GET IDLETIME
1 ha 2149
     mov  eax,[idleusesec]
684 diamond 2150
     mov  [esp+32], eax
1 ha 2151
     ret
2152
 
742 Rus 2153
sysfn_getcpuclock:		; 18.5 = GET TSC/SEC
381 serge 2154
     mov  eax,[CPU_FREQ]
684 diamond 2155
     mov  [esp+32], eax
1 ha 2156
     ret
2157
 
2158
;  SAVE ramdisk to /hd/1/menuet.img
2159
;!!!!!!!!!!!!!!!!!!!!!!!!
2160
   include 'blkdev/rdsave.inc'
2161
;!!!!!!!!!!!!!!!!!!!!!!!!
75 diamond 2162
 
742 Rus 2163
sysfn_getactive:	; 18.7 = get active window
379 serge 2164
     mov  eax, [TASK_COUNT]
380 serge 2165
   movzx  eax, word [WIN_POS + eax*2]
684 diamond 2166
     mov  [esp+32],eax
1 ha 2167
     ret
75 diamond 2168
 
742 Rus 2169
sysfn_sound_flag:	; 18.8 = get/set sound_flag
684 diamond 2170
     cmp  ecx,1
1 ha 2171
     jne  nogetsoundflag
2172
     movzx  eax,byte [sound_flag] ; get sound_flag
684 diamond 2173
     mov  [esp+32],eax
1 ha 2174
     ret
2175
 nogetsoundflag:
684 diamond 2176
     cmp  ecx,2
1 ha 2177
     jnz  nosoundflag
75 diamond 2178
     xor  byte [sound_flag], 1
2179
 nosoundflag:
41 mikedld 2180
     ret
75 diamond 2181
 
742 Rus 2182
sysfn_minimize: 	; 18.10 = minimize window
1 ha 2183
     mov   [window_minimize],1
2184
     ret
75 diamond 2185
 
742 Rus 2186
sysfn_getdiskinfo:	; 18.11 = get disk info table
684 diamond 2187
     cmp  ecx,1
1 ha 2188
     jnz  full_table
2189
  small_table:
2190
     call for_all_tables
75 diamond 2191
     mov ecx,10
1 ha 2192
     cld
2193
     rep movsb
2194
     ret
2195
   for_all_tables:
684 diamond 2196
     mov edi,edx
381 serge 2197
     mov esi,DRIVE_DATA
1 ha 2198
     ret
2199
  full_table:
684 diamond 2200
     cmp  ecx,2
1 ha 2201
     jnz  exit_for_anyone
2202
     call for_all_tables
75 diamond 2203
     mov ecx,16384
1 ha 2204
     cld
2205
     rep movsd
2206
     ret
75 diamond 2207
 
742 Rus 2208
sysfn_lastkey:		; 18.12 = return 0 (backward compatibility)
2209
	and	dword [esp+32], 0
2210
	ret
75 diamond 2211
 
742 Rus 2212
sysfn_getversion:	; 18.13 = get kernel ID and version
684 diamond 2213
     mov edi,ebx
1 ha 2214
     mov esi,version_inf
2215
     mov ecx,version_end-version_inf
2216
     rep movsb
2217
     ret
75 diamond 2218
 
2219
sysfn_waitretrace:     ; 18.14 = sys wait retrace
41 mikedld 2220
     ;wait retrace functions
2221
 sys_wait_retrace:
2222
     mov edx,0x3da
2223
 WaitRetrace_loop:
2224
     in al,dx
2225
     test al,1000b
2226
     jz WaitRetrace_loop
684 diamond 2227
     and [esp+32],dword 0
1 ha 2228
     ret
75 diamond 2229
 
742 Rus 2230
sysfn_centermouse:	; 18.15 = mouse centered
1 ha 2231
     call  mouse_centered
684 diamond 2232
     and [esp+32],dword 0
1 ha 2233
     ret
75 diamond 2234
 
120 mario79 2235
sysfn_mouse_acceleration: ; 18.19 = set/get mouse features
684 diamond 2236
     cmp  ecx,0  ; get mouse speed factor
120 mario79 2237
     jnz  .set_mouse_acceleration
164 serge 2238
     xor  eax,eax
120 mario79 2239
     mov  ax,[mouse_speed_factor]
684 diamond 2240
     mov  [esp+32],eax
120 mario79 2241
     ret
2242
 .set_mouse_acceleration:
684 diamond 2243
     cmp  ecx,1  ; set mouse speed factor
120 mario79 2244
     jnz  .get_mouse_delay
684 diamond 2245
     mov  [mouse_speed_factor],dx
120 mario79 2246
     ret
2247
 .get_mouse_delay:
684 diamond 2248
     cmp  ecx,2  ; get mouse delay
120 mario79 2249
     jnz  .set_mouse_delay
2250
     mov  eax,[mouse_delay]
684 diamond 2251
     mov  [esp+32],eax
120 mario79 2252
     ret
2253
 .set_mouse_delay:
684 diamond 2254
     cmp  ecx,3  ; set mouse delay
120 mario79 2255
     jnz  .set_pointer_position
684 diamond 2256
     mov  [mouse_delay],edx
120 mario79 2257
     ret
2258
 .set_pointer_position:
684 diamond 2259
     cmp  ecx,4  ; set mouse pointer position
621 mario79 2260
     jnz  .set_mouse_button
684 diamond 2261
     mov   [MOUSE_Y],dx    ;y
2262
     ror   edx,16
2263
     mov   [MOUSE_X],dx    ;x
2264
     rol   edx,16
621 mario79 2265
     ret
2266
 .set_mouse_button:
684 diamond 2267
     cmp   ecx,5  ; set mouse button features
621 mario79 2268
     jnz  .end
684 diamond 2269
     mov   [BTN_DOWN],dl
621 mario79 2270
     mov   [mouse_active],1
120 mario79 2271
 .end:
2272
     ret
2273
 
75 diamond 2274
sysfn_getfreemem:
170 serge 2275
     mov eax, [pg_data.pages_free]
2276
     shl eax, 2
684 diamond 2277
     mov [esp+32],eax
1 ha 2278
     ret
75 diamond 2279
 
2280
sysfn_getallmem:
846 serge 2281
     mov  eax,[_mem_amount]
170 serge 2282
     shr eax, 10
684 diamond 2283
     mov  [esp+32],eax
32 halyavin 2284
     ret
2285
 
608 alver 2286
; // Alver, 2007-22-08 // {
2287
sysfn_pid_to_slot:
684 diamond 2288
     mov   eax, ecx
608 alver 2289
     call  pid_to_slot
684 diamond 2290
     mov   [esp+32], eax
608 alver 2291
     ret
2292
 
2293
sysfn_min_rest_window:
2294
     pushad
742 Rus 2295
     mov   eax, edx	 ; ebx - operating
684 diamond 2296
     shr   ecx, 1
608 alver 2297
     jnc    @f
2298
     call  pid_to_slot
2299
@@:
742 Rus 2300
     or    eax, eax	 ; eax - number of slot
608 alver 2301
     jz    .error
742 Rus 2302
     cmp   eax, 255	    ; varify maximal slot number
608 alver 2303
     ja    .error
684 diamond 2304
     movzx eax, word [WIN_STACK + eax*2]
2305
     shr   ecx, 1
608 alver 2306
     jc    .restore
2307
 ; .minimize:
2308
     call  minimize_window
2309
     jmp   .exit
2310
.restore:
2311
     call  restore_minimized_window
2312
.exit:
2313
     popad
2314
     xor   eax, eax
684 diamond 2315
     mov   [esp+32], eax
608 alver 2316
     ret
2317
.error:
2318
     popad
2319
     xor   eax, eax
2320
     dec   eax
684 diamond 2321
     mov   [esp+32], eax
608 alver 2322
     ret
2323
; } \\ Alver, 2007-22-08 \\
2324
 
41 mikedld 2325
uglobal
2326
;// mike.dld, 2006-29-01 [
2327
screen_workarea RECT
2328
;// mike.dld, 2006-29-01 ]
1 ha 2329
window_minimize db 0
742 Rus 2330
sound_flag	db 0
41 mikedld 2331
endg
1 ha 2332
 
41 mikedld 2333
iglobal
2334
version_inf:
641 diamond 2335
  db 0,7,1,0  ; version 0.7.1.0
41 mikedld 2336
  db UID_KOLIBRI
540 victor 2337
  dd __REV__
41 mikedld 2338
version_end:
2339
endg
1 ha 2340
 
41 mikedld 2341
UID_NONE=0
742 Rus 2342
UID_MENUETOS=1	 ;official
2343
UID_KOLIBRI=2	 ;russian
1 ha 2344
 
2345
sys_cachetodiskette:
671 Ghost 2346
	cmp	ebx, 1
2347
	jne	.no_floppy_a_save
2348
	mov	[flp_number], 1
2349
	jmp	.save_image_on_floppy
2350
.no_floppy_a_save:
2351
	cmp	ebx, 2
2352
	jne	.no_floppy_b_save
2353
	mov	[flp_number], 2
2354
.save_image_on_floppy:
2355
	call	save_image
2356
	mov	[esp + 32], dword 0
2357
	cmp	[FDC_Status], 0
2358
	je	.yes_floppy_save
2359
.no_floppy_b_save:
2360
	mov	[esp + 32], dword 1
2361
.yes_floppy_save:
2362
	ret
1 ha 2363
 
2364
uglobal
2365
;  bgrchanged  dd  0x0
546 diamond 2366
bgrlock db 0
2367
bgrlockpid dd 0
1 ha 2368
endg
2369
 
2370
sys_background:
2371
 
742 Rus 2372
    cmp   ebx,1 			   ; BACKGROUND SIZE
1 ha 2373
    jnz   nosb1
2374
    cmp   ecx,0
742 Rus 2375
    je	  sbgrr
684 diamond 2376
    cmp   edx,0
742 Rus 2377
    je	  sbgrr
546 diamond 2378
@@:
742 Rus 2379
	mov	al, 1
2380
	xchg	[bgrlock], al
2381
	test	al, al
2382
	jz	@f
2383
	call	change_task
2384
	jmp	@b
546 diamond 2385
@@:
684 diamond 2386
    mov   [BgrDataWidth],ecx
2387
    mov   [BgrDataHeight],edx
1 ha 2388
;    mov   [bgrchanged],1
469 serge 2389
 
2390
    pushad
2391
; return memory for old background
2392
    stdcall kernel_free, [img_background]
2393
; calculate RAW size
2394
    xor  eax,eax
2395
    inc  eax
527 diamond 2396
    cmp  [BgrDataWidth],eax
469 serge 2397
    jae   @f
527 diamond 2398
    mov [BgrDataWidth],eax
469 serge 2399
@@:
527 diamond 2400
    cmp  [BgrDataHeight],eax
469 serge 2401
    jae   @f
527 diamond 2402
    mov [BgrDataHeight],eax
469 serge 2403
@@:
527 diamond 2404
    mov  eax,[BgrDataWidth]
2405
    imul eax,[BgrDataHeight]
2406
    lea  eax,[eax*3]
469 serge 2407
    mov  [mem_BACKGROUND],eax
2408
; get memory for new background
546 diamond 2409
    stdcall kernel_alloc, eax
469 serge 2410
    test eax, eax
2411
    jz .exit_mem
2412
    mov [img_background], eax
2413
.exit_mem:
2414
    popad
742 Rus 2415
	mov	[bgrlock], 0
469 serge 2416
 
1 ha 2417
  sbgrr:
2418
    ret
469 serge 2419
 
1 ha 2420
  nosb1:
2421
 
742 Rus 2422
    cmp   ebx,2 			   ; SET PIXEL
1 ha 2423
    jnz   nosb2
684 diamond 2424
    cmp   ecx,[mem_BACKGROUND]
2425
    jae   nosb2
469 serge 2426
    mov   eax,[img_background]
684 diamond 2427
    mov   ebx,[eax+ecx]
2428
    and   ebx,0xFF000000 ;255*256*256*256
2429
    and   edx,0x00FFFFFF ;255*256*256+255*256+255
2430
    add   edx,ebx
2431
    mov   [eax+ecx],edx
1 ha 2432
;    mov   [bgrchanged],1
2433
    ret
2434
  nosb2:
2435
 
742 Rus 2436
    cmp   ebx,3 			   ; DRAW BACKGROUND
1 ha 2437
    jnz   nosb3
2438
draw_background_temp:
2439
;    cmp   [bgrchanged],1 ;0
2440
;    je    nosb31
2441
;draw_background_temp:
2442
;    mov   [bgrchanged],1 ;0
76 mario79 2443
    mov    [background_defined], 1
709 diamond 2444
    call  force_redraw_background
2445
    mov    [REDRAW_BACKGROUND], byte 2
1 ha 2446
   nosb31:
2447
    ret
2448
  nosb3:
2449
 
742 Rus 2450
    cmp   ebx,4 			   ; TILED / STRETCHED
1 ha 2451
    jnz   nosb4
684 diamond 2452
    cmp   ecx,[BgrDrawMode]
742 Rus 2453
    je	  nosb41
684 diamond 2454
    mov   [BgrDrawMode],ecx
1 ha 2455
;    mov   [bgrchanged],1
2456
   nosb41:
2457
    ret
2458
  nosb4:
2459
 
742 Rus 2460
    cmp   ebx,5 			   ; BLOCK MOVE TO BGR
1 ha 2461
    jnz   nosb5
2462
  ; bughere
684 diamond 2463
    mov   eax, ecx
2464
    mov   ebx, edx
469 serge 2465
    add   ebx, [img_background]   ;IMG_BACKGROUND
684 diamond 2466
    mov   ecx, esi
1 ha 2467
    call  memmove
2468
  .fin:
2469
    ret
2470
  nosb5:
479 kastigar 2471
 
742 Rus 2472
	cmp	ebx, 6
2473
	jnz	nosb6
546 diamond 2474
@@:
742 Rus 2475
	mov	al, 1
2476
	xchg	[bgrlock], al
2477
	test	al, al
2478
	jz	@f
2479
	call	change_task
2480
	jmp	@b
546 diamond 2481
@@:
742 Rus 2482
	mov	eax, [CURRENT_TASK]
2483
	mov	[bgrlockpid], eax
2484
	stdcall user_alloc, [mem_BACKGROUND]
2485
	mov	[esp+32], eax
2486
	test	eax, eax
2487
	jz	.nomem
2488
	mov	ebx, eax
2489
	shr	ebx, 12
2490
	or	dword [page_tabs+(ebx-1)*4], DONT_FREE_BLOCK
2491
	mov	esi, [img_background]
2492
	shr	esi, 12
2493
	mov	ecx, [mem_BACKGROUND]
2494
	add	ecx, 0xFFF
2495
	shr	ecx, 12
546 diamond 2496
.z:
742 Rus 2497
	mov	eax, [page_tabs+ebx*4]
2498
	test	al, 1
2499
	jz	@f
2500
	call	free_page
546 diamond 2501
@@:
742 Rus 2502
	mov	eax, [page_tabs+esi*4]
2503
	or	al, PG_UW
2504
	mov	[page_tabs+ebx*4], eax
2505
	mov	eax, ebx
2506
	shl	eax, 12
2507
	invlpg	[eax]
2508
	inc	ebx
2509
	inc	esi
2510
	loop	.z
2511
	ret
546 diamond 2512
.nomem:
742 Rus 2513
	and	[bgrlockpid], 0
2514
	mov	[bgrlock], 0
546 diamond 2515
nosb6:
742 Rus 2516
	cmp	ebx, 7
2517
	jnz	nosb7
2518
	cmp	[bgrlock], 0
2519
	jz	.err
2520
	mov	eax, [CURRENT_TASK]
2521
	cmp	[bgrlockpid], eax
2522
	jnz	.err
2523
	mov	eax, ecx
2524
	mov	ebx, ecx
2525
	shr	eax, 12
2526
	mov	ecx, [page_tabs+(eax-1)*4]
2527
	test	cl, USED_BLOCK+DONT_FREE_BLOCK
2528
	jz	.err
2529
	jnp	.err
2530
	push	eax
2531
	shr	ecx, 12
546 diamond 2532
@@:
742 Rus 2533
	and	dword [page_tabs+eax*4], 0
2534
	mov	edx, eax
2535
	shl	edx, 12
802 serge 2536
        push eax
742 Rus 2537
	invlpg	[edx]
802 serge 2538
        pop eax
742 Rus 2539
	inc	eax
2540
	loop	@b
2541
	pop	eax
2542
	and	dword [page_tabs+(eax-1)*4], not DONT_FREE_BLOCK
2543
	stdcall user_free, ebx
2544
	mov	[esp+32], eax
2545
	and	[bgrlockpid], 0
2546
	mov	[bgrlock], 0
2547
	ret
546 diamond 2548
.err:
742 Rus 2549
	and	dword [esp+32], 0
2550
	ret
546 diamond 2551
 
2552
nosb7:
1 ha 2553
    ret
2554
 
709 diamond 2555
force_redraw_background:
2556
    mov   [draw_data+32 + RECT.left],dword 0
2557
    mov   [draw_data+32 + RECT.top],dword 0
2558
    push  eax ebx
753 serge 2559
    mov   eax,[Screen_Max_X]
2560
    mov   ebx,[Screen_Max_Y]
709 diamond 2561
    mov   [draw_data+32 + RECT.right],eax
2562
    mov   [draw_data+32 + RECT.bottom],ebx
2563
    pop   ebx eax
2564
    mov   byte [REDRAW_BACKGROUND], 1
2565
    ret
479 kastigar 2566
 
1 ha 2567
align 4
2568
 
2569
sys_getbackground:
2570
 
742 Rus 2571
    cmp   eax,1 				 ; SIZE
1 ha 2572
    jnz   nogb1
527 diamond 2573
    mov   eax,[BgrDataWidth]
1 ha 2574
    shl   eax,16
531 diamond 2575
    mov   ax,[BgrDataHeight]
1 ha 2576
    mov   [esp+36],eax
2577
    ret
2578
  nogb1:
2579
 
742 Rus 2580
    cmp   eax,2 				 ; PIXEL
1 ha 2581
    jnz   nogb2
469 serge 2582
;    mov   edx,0x160000-16
2583
;    cmp   edx,ebx
2584
;    jbe   nogb2
2585
;    mov   eax, [ebx+IMG_BACKGROUND]
2586
    mov   eax,[img_background]
2587
    mov   eax,[ebx+eax]
2588
 
1 ha 2589
    and   eax, 0xFFFFFF
2590
    mov   [esp+36],eax
2591
    ret
2592
  nogb2:
2593
 
742 Rus 2594
    cmp   eax,4 				 ; TILED / STRETCHED
1 ha 2595
    jnz   nogb4
527 diamond 2596
    mov   eax,[BgrDrawMode]
1 ha 2597
  nogb4:
2598
    mov   [esp+36],eax
2599
    ret
2600
 
2601
 
2602
align 4
2603
 
2604
sys_getkey:
671 Ghost 2605
	mov	[esp + 32],dword 1
2606
	; test main buffer
742 Rus 2607
	mov	ebx, [CURRENT_TASK]			     ; TOP OF WINDOW STACK
671 Ghost 2608
	movzx	ecx, word [WIN_STACK + ebx * 2]
2609
	mov	edx, [TASK_COUNT]
2610
	cmp	ecx, edx
2611
	jne	.finish
2612
	cmp	[KEY_COUNT], byte 0
2613
	je	.finish
2614
	movzx	eax, byte [KEY_BUFF]
2615
	shl	eax, 8
2616
	push	eax
2617
	dec	byte [KEY_COUNT]
2618
	and	byte [KEY_COUNT], 127
2619
	movzx	ecx, byte [KEY_COUNT]
2620
	add	ecx, 2
2621
	mov	eax, KEY_BUFF + 1
2622
	mov	ebx, KEY_BUFF
2623
	call	memmove
2624
	pop	eax
92 diamond 2625
.ret_eax:
671 Ghost 2626
	mov	[esp + 32], eax
2627
	ret
2628
.finish:
92 diamond 2629
; test hotkeys buffer
671 Ghost 2630
	mov	ecx, hotkey_buffer
92 diamond 2631
@@:
671 Ghost 2632
	cmp	[ecx], ebx
2633
	jz	.found
2634
	add	ecx, 8
2635
	cmp	ecx, hotkey_buffer + 120 * 8
2636
	jb	@b
2637
	ret
92 diamond 2638
.found:
671 Ghost 2639
	mov	ax, [ecx + 6]
2640
	shl	eax, 16
2641
	mov	ah, [ecx + 4]
2642
	mov	al, 2
2643
	and	dword [ecx + 4], 0
2644
	and	dword [ecx], 0
2645
	jmp	.ret_eax
1 ha 2646
 
2647
align 4
2648
 
2649
sys_getbutton:
2650
 
742 Rus 2651
	mov	ebx, [CURRENT_TASK]			    ; TOP OF WINDOW STACK
671 Ghost 2652
	mov	[esp + 32], dword 1
2653
	movzx	ecx, word [WIN_STACK + ebx * 2]
2654
	mov	edx, [TASK_COUNT] ; less than 256 processes
2655
	cmp	ecx, edx
2656
	jne	.exit
2657
	movzx	eax, byte [BTN_COUNT]
2658
	test	eax, eax
2659
	jz	.exit
2660
	mov	eax, [BTN_BUFF]
2661
	shl	eax, 8
803 alver 2662
; // Alver 22.06.2008 // {
2663
        mov       al, byte [btn_down_determ]
2664
        and       al,0xFE                                       ; delete left button bit
2665
; } \\ Alver \\
671 Ghost 2666
	mov	[BTN_COUNT], byte 0
2667
	mov	[esp + 32], eax
2668
.exit:
2669
	ret
1 ha 2670
 
2671
 
2672
align 4
2673
 
2674
sys_cpuusage:
2675
 
2676
;  RETURN:
2677
;
2678
;  +00 dword     process cpu usage
2679
;  +04  word     position in windowing stack
2680
;  +06  word     windowing stack value at current position (cpu nro)
2681
;  +10 12 bytes  name
2682
;  +22 dword     start in mem
2683
;  +26 dword     used mem
2684
;  +30 dword     PID , process idenfification number
2685
;
2686
 
742 Rus 2687
    cmp  ecx,-1 	; who am I ?
684 diamond 2688
    jne  .no_who_am_i
2689
    mov  ecx,[CURRENT_TASK]
2690
  .no_who_am_i:
742 Rus 2691
	cmp	ecx, max_processes
2692
	ja	.nofillbuf
1 ha 2693
 
684 diamond 2694
; +4: word: position of the window of thread in the window stack
742 Rus 2695
	mov	ax, [WIN_STACK + ecx * 2]
2696
	mov	[ebx+4], ax
684 diamond 2697
; +6: word: number of the thread slot, which window has in the window stack
2698
;           position ecx (has no relation to the specific thread)
742 Rus 2699
	mov	ax, [WIN_POS + ecx * 2]
2700
	mov	[ebx+6], ax
1 ha 2701
 
742 Rus 2702
	shl	ecx, 5
1 ha 2703
 
684 diamond 2704
; +0: dword: memory usage
742 Rus 2705
	mov	eax, [ecx+CURRENT_TASK+TASKDATA.cpu_usage]
2706
	mov	[ebx], eax
684 diamond 2707
; +10: 11 bytes: name of the process
742 Rus 2708
	push	ecx
2709
	lea	eax, [ecx*8+SLOT_BASE+APPDATA.app_name]
2710
	add	ebx, 10
2711
	mov	ecx, 11
2712
	call	memmove
2713
	pop	ecx
1 ha 2714
 
684 diamond 2715
; +22: address of the process in memory
2716
; +26: size of used memory - 1
742 Rus 2717
	push	edi
2718
	lea	edi, [ebx+12]
2719
	xor	eax, eax
2720
	mov	edx, 0x100000*16
2721
	cmp	ecx, 1 shl 5
2722
	je	.os_mem
2723
	mov	edx, [SLOT_BASE+ecx*8+APPDATA.mem_size]
840 serge 2724
        xor eax, eax
684 diamond 2725
.os_mem:
742 Rus 2726
	stosd
2727
	lea	eax, [edx-1]
2728
	stosd
1 ha 2729
 
684 diamond 2730
; +30: PID/TID
742 Rus 2731
	mov	eax, [ecx+CURRENT_TASK+TASKDATA.pid]
2732
	stosd
1 ha 2733
 
2734
    ; window position and size
742 Rus 2735
	push	esi
2736
	lea	esi, [ecx + window_data + WDATA.box]
2737
	movsd
2738
	movsd
2739
	movsd
2740
	movsd
1 ha 2741
 
2742
    ; Process state (+50)
742 Rus 2743
	mov	eax, dword [ecx+CURRENT_TASK+TASKDATA.state]
2744
	stosd
1 ha 2745
 
138 mikedld 2746
    ; Window client area box
742 Rus 2747
	lea	esi, [ecx*8 + SLOT_BASE + APPDATA.wnd_clientbox]
2748
	movsd
2749
	movsd
2750
	movsd
2751
	movsd
1 ha 2752
 
164 serge 2753
    ; Window state
742 Rus 2754
	mov	al, [ecx+window_data+WDATA.fl_wstate]
2755
	stosb
164 serge 2756
 
742 Rus 2757
	pop	esi
2758
	pop	edi
138 mikedld 2759
 
684 diamond 2760
.nofillbuf:
1 ha 2761
    ; return number of processes
2762
 
379 serge 2763
    mov    eax,[TASK_COUNT]
684 diamond 2764
    mov    [esp+32],eax
1 ha 2765
    ret
2766
 
2767
align 4
2768
sys_clock:
742 Rus 2769
	cli
1 ha 2770
  ; Mikhail Lisovin  xx Jan 2005
742 Rus 2771
  @@:	mov   al, 10
2772
	out   0x70, al
2773
	in    al, 0x71
2774
	test  al, al
2775
	jns   @f
2776
	mov   esi, 1
2777
	call  delay_ms
2778
	jmp   @b
1 ha 2779
  @@:
2780
  ; end Lisovin's fix
2781
 
742 Rus 2782
	xor   al,al	      ; seconds
2783
	out   0x70,al
2784
	in    al,0x71
2785
	movzx ecx,al
2786
	mov   al,02	      ; minutes
2787
	shl   ecx,16
2788
	out   0x70,al
2789
	in    al,0x71
2790
	movzx edx,al
2791
	mov   al,04	      ; hours
2792
	shl   edx,8
2793
	out   0x70,al
2794
	in    al,0x71
2795
	add   ecx,edx
2796
	movzx edx,al
2797
	add   ecx,edx
2798
	sti
671 Ghost 2799
	mov	[esp + 32], ecx
742 Rus 2800
	ret
1 ha 2801
 
2802
 
2803
align 4
2804
 
2805
sys_date:
2806
 
742 Rus 2807
	cli
2808
  @@:	mov   al, 10
2809
	out   0x70, al
2810
	in    al, 0x71
2811
	test  al, al
2812
	jns   @f
2813
	mov   esi, 1
2814
	call  delay_ms
2815
	jmp   @b
75 diamond 2816
  @@:
2817
 
742 Rus 2818
	mov	ch,0
2819
	mov	al,7		; date
2820
	out	0x70,al
2821
	in	al,0x71
2822
	mov	cl,al
2823
	mov	al,8		; month
2824
	shl	ecx,16
2825
	out	0x70,al
2826
	in	al,0x71
2827
	mov	ch,al
2828
	mov	al,9		; year
2829
	out	0x70,al
2830
	in	al,0x71
2831
	mov	cl,al
2832
	sti
2833
	mov	[esp+32], ecx
2834
	ret
1 ha 2835
 
2836
 
2837
; redraw status
2838
 
2839
sys_redrawstat:
671 Ghost 2840
	cmp	ebx, 1
2841
	jne	no_widgets_away
2842
	; buttons away
2843
	mov	ecx,[CURRENT_TASK]
1 ha 2844
  sys_newba2:
671 Ghost 2845
	mov	edi,[BTN_ADDR]
742 Rus 2846
	cmp	[edi], dword 0	; empty button list ?
671 Ghost 2847
	je	end_of_buttons_away
2848
	movzx	ebx, word [edi]
2849
	inc	ebx
2850
	mov	eax,edi
1 ha 2851
  sys_newba:
671 Ghost 2852
	dec	ebx
2853
	jz	end_of_buttons_away
1 ha 2854
 
671 Ghost 2855
	add	eax, 0x10
2856
	cmp	cx, [eax]
2857
	jnz	sys_newba
1 ha 2858
 
671 Ghost 2859
	push	eax ebx ecx
2860
	mov	ecx,ebx
2861
	inc	ecx
2862
	shl	ecx, 4
2863
	mov	ebx, eax
2864
	add	eax, 0x10
2865
	call	memmove
2866
	dec	dword [edi]
2867
	pop	ecx ebx eax
1 ha 2868
 
671 Ghost 2869
	jmp	sys_newba2
1 ha 2870
 
2871
  end_of_buttons_away:
2872
 
671 Ghost 2873
	ret
1 ha 2874
 
2875
  no_widgets_away:
2876
 
671 Ghost 2877
	cmp	ebx, 2
2878
	jnz	srl1
1 ha 2879
 
671 Ghost 2880
	mov	edx, [TASK_BASE]      ; return whole screen draw area for this app
2881
	add	edx, draw_data - CURRENT_TASK
2882
	mov	[edx + RECT.left], 0
2883
	mov	[edx + RECT.top], 0
759 Rus 2884
	mov	eax, [Screen_Max_X]
671 Ghost 2885
	mov	[edx + RECT.right], eax
759 Rus 2886
	mov	eax, [Screen_Max_Y]
671 Ghost 2887
	mov	[edx + RECT.bottom], eax
1 ha 2888
 
671 Ghost 2889
	mov	edi, [TASK_BASE]
2890
	or	[edi - twdw + WDATA.fl_wdrawn], 1   ; no new position & buttons from app
2891
	call	sys_window_mouse
2892
	ret
1 ha 2893
 
2894
  srl1:
671 Ghost 2895
	ret
1 ha 2896
 
2897
 
2898
sys_drawwindow:
2899
 
684 diamond 2900
    mov   eax,edx
2901
    shr   eax,16+8
2902
    and   eax,15
1 ha 2903
 
684 diamond 2904
;    cmp   eax,0   ; type I    - original style
1 ha 2905
    jne   nosyswI
33 mario79 2906
    inc   [mouse_pause]
36 mario79 2907
    call  [disable_mouse]
1 ha 2908
    call  sys_set_window
36 mario79 2909
    call  [disable_mouse]
1 ha 2910
    call  drawwindow_I
114 mikedld 2911
    ;dec   [mouse_pause]
2912
    ;call   [draw_pointer]
2913
    ;ret
2914
    jmp   draw_window_caption.2
1 ha 2915
  nosyswI:
2916
 
742 Rus 2917
    cmp   al,1	  ; type II   - only reserve area, no draw
1 ha 2918
    jne   nosyswII
33 mario79 2919
    inc   [mouse_pause]
36 mario79 2920
    call  [disable_mouse]
1 ha 2921
    call  sys_set_window
36 mario79 2922
    call  [disable_mouse]
1 ha 2923
    call  sys_window_mouse
33 mario79 2924
    dec   [mouse_pause]
36 mario79 2925
    call   [draw_pointer]
1 ha 2926
    ret
2927
  nosyswII:
2928
 
742 Rus 2929
    cmp   al,2	  ; type III  - new style
1 ha 2930
    jne   nosyswIII
33 mario79 2931
    inc   [mouse_pause]
36 mario79 2932
    call  [disable_mouse]
1 ha 2933
    call  sys_set_window
36 mario79 2934
    call  [disable_mouse]
1 ha 2935
    call  drawwindow_III
114 mikedld 2936
    ;dec   [mouse_pause]
2937
    ;call   [draw_pointer]
2938
    ;ret
2939
    jmp   draw_window_caption.2
1 ha 2940
  nosyswIII:
2941
 
742 Rus 2942
    cmp   al,3	  ; type IV - skinned window
2943
    je	  draw_skin_window
2944
    cmp   al,4	  ; type V - skinned window not sized! {not_sized_skin_window}
549 spraid 2945
    jne   nosyswV
2946
  draw_skin_window:
567 serge 2947
 
569 diamond 2948
    inc   [mouse_pause]
2949
    call  [disable_mouse]
2950
    call  sys_set_window
2951
    call  [disable_mouse]
684 diamond 2952
    mov   eax, [TASK_COUNT]
2953
    movzx eax, word [WIN_POS + eax*2]
2954
    cmp   eax, [CURRENT_TASK]
2955
    setz  al
2956
    movzx eax, al
2957
    push  eax
36 mario79 2958
    call  drawwindow_IV
114 mikedld 2959
    ;dec   [mouse_pause]
2960
    ;call   [draw_pointer]
2961
    ;ret
2962
    jmp   draw_window_caption.2
549 spraid 2963
  nosyswV:
1 ha 2964
 
2965
    ret
2966
 
2967
 
114 mikedld 2968
draw_window_caption:
742 Rus 2969
	inc	[mouse_pause]
2970
	call	[disable_mouse]
114 mikedld 2971
 
742 Rus 2972
	xor	eax,eax
2973
	mov	edx,[TASK_COUNT]
2974
	movzx	edx,word[WIN_POS+edx*2]
2975
	cmp	edx,[CURRENT_TASK]
2976
	jne	@f
2977
	inc	eax
2978
    @@: mov	edx,[CURRENT_TASK]
2979
	shl	edx,5
2980
	add	edx,window_data
2981
	movzx	ebx,[edx+WDATA.fl_wstyle]
2982
	and	bl,0x0F
2983
	cmp	bl,3
2984
	je	.draw_caption_style_3		;{for 3 and 4 style write caption}
2985
	cmp	bl,4
2986
	je	.draw_caption_style_3
567 serge 2987
 
742 Rus 2988
	jmp	.not_style_3
549 spraid 2989
  .draw_caption_style_3:
114 mikedld 2990
 
742 Rus 2991
	push	edx
2992
	call	drawwindow_IV_caption
2993
	add	esp,4
2994
	jmp	.2
114 mikedld 2995
 
2996
  .not_style_3:
742 Rus 2997
	cmp	bl,2
2998
	jne	.not_style_2
114 mikedld 2999
 
742 Rus 3000
	call	drawwindow_III_caption
3001
	jmp	.2
114 mikedld 3002
 
3003
  .not_style_2:
742 Rus 3004
	cmp	bl,0
3005
	jne	.2
114 mikedld 3006
 
742 Rus 3007
	call	drawwindow_I_caption
114 mikedld 3008
 
3009
;--------------------------------------------------------------
742 Rus 3010
  .2:	;jmp     @f
3011
	mov	edi,[CURRENT_TASK]
3012
	shl	edi,5
3013
	test	[edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
3014
	jz	@f
3015
	mov	edx,[edi*8+SLOT_BASE+APPDATA.wnd_caption]
3016
	or	edx,edx
3017
	jz	@f
114 mikedld 3018
 
742 Rus 3019
	movzx	eax,[edi+window_data+WDATA.fl_wstyle]
3020
	and	al,0x0F
3021
	cmp	al,3
3022
	je	.skinned
3023
	cmp	al,4
3024
	je	.skinned
567 serge 3025
 
742 Rus 3026
	jmp	.not_skinned
567 serge 3027
  .skinned:
742 Rus 3028
	mov	ebp,[edi+window_data+WDATA.box.left-2]
3029
	mov	bp,word[edi+window_data+WDATA.box.top]
3030
	movzx	eax,word[edi+window_data+WDATA.box.width]
3031
	sub	ax,[_skinmargins.left]
3032
	sub	ax,[_skinmargins.right]
3033
	push	edx
3034
	cwde
3035
	cdq
3036
	mov	ebx,6
3037
	idiv	ebx
3038
	pop	edx
3039
	or	eax,eax
3040
	js	@f
3041
	mov	esi,eax
3042
	mov	ebx,dword[_skinmargins.left-2]
3043
	mov	bx,word[_skinh]
3044
	sub	bx,[_skinmargins.bottom]
3045
	sub	bx,[_skinmargins.top]
3046
	sar	bx,1
3047
	adc	bx,0
3048
	add	bx,[_skinmargins.top]
3049
	add	bx,-3
3050
	add	ebx,ebp
3051
	jmp	.dodraw
114 mikedld 3052
 
3053
  .not_skinned:
742 Rus 3054
	cmp	al,1
3055
	je	@f
114 mikedld 3056
 
742 Rus 3057
	mov	ebp,[edi+window_data+WDATA.box.left-2]
3058
	mov	bp,word[edi+window_data+WDATA.box.top]
3059
	movzx	eax,word[edi+window_data+WDATA.box.width]
3060
	sub	eax,16
3061
	push	edx
3062
	cwde
3063
	cdq
3064
	mov	ebx,6
3065
	idiv	ebx
3066
	pop	edx
3067
	or	eax,eax
3068
	js	@f
3069
	mov	esi,eax
3070
	mov	ebx,0x00080007
3071
	add	ebx,ebp
139 diamond 3072
.dodraw:
742 Rus 3073
	mov	ecx,[common_colours+16];0x00FFFFFF
3074
	or	ecx, 0x80000000
3075
	xor	edi,edi
803 alver 3076
; // Alver 22.06.2008 // {
3077
;	call	dtext
3078
        call dtext_asciiz_esi
3079
; } \\ Alver \\
114 mikedld 3080
 
3081
    @@:
3082
;--------------------------------------------------------------
742 Rus 3083
	dec	[mouse_pause]
3084
	call	[draw_pointer]
3085
	ret
114 mikedld 3086
 
3087
iglobal
3088
align 4
3089
window_topleft dd \
549 spraid 3090
  1, 21,\		;type 0
742 Rus 3091
  0,  0,\	;type 1
3092
  5, 20,\	;type 2
3093
  5,  ?,\	;type 3 {set by skin}
3094
  5,  ? 	;type 4 {set by skin}
114 mikedld 3095
endg
3096
 
3097
set_window_clientbox:
742 Rus 3098
	push	eax ecx edi
114 mikedld 3099
 
742 Rus 3100
	mov	eax,[_skinh]
3101
	mov	[window_topleft+4*7],eax
3102
	mov	[window_topleft+4*9],eax
114 mikedld 3103
 
742 Rus 3104
	mov	ecx,edi
3105
	sub	edi,window_data
3106
	shl	edi,3
3107
	test	[ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE
3108
	jz	@f
114 mikedld 3109
 
742 Rus 3110
	movzx	eax,[ecx+WDATA.fl_wstyle]
3111
	and	eax,0x0F
3112
	mov	eax,[eax*8+window_topleft+0]
3113
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3114
	shl	eax,1
3115
	neg	eax
3116
	add	eax,[ecx+WDATA.box.width]
3117
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
114 mikedld 3118
 
742 Rus 3119
	movzx	eax,[ecx+WDATA.fl_wstyle]
3120
	and	eax,0x0F
3121
	push	[eax*8+window_topleft+0]
3122
	mov	eax,[eax*8+window_topleft+4]
3123
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3124
	neg	eax
3125
	sub	eax,[esp]
3126
	add	eax,[ecx+WDATA.box.height]
3127
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3128
	add	esp,4
114 mikedld 3129
 
742 Rus 3130
	pop	edi ecx eax
3131
	ret
114 mikedld 3132
    @@:
742 Rus 3133
	xor	eax,eax
3134
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3135
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3136
	mov	eax,[ecx+WDATA.box.width]
3137
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
3138
	mov	eax,[ecx+WDATA.box.height]
3139
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
114 mikedld 3140
 
742 Rus 3141
	pop	edi ecx eax
3142
	ret
114 mikedld 3143
 
1 ha 3144
sys_set_window:
3145
 
684 diamond 3146
    mov   eax,[CURRENT_TASK]
3147
    shl   eax,5
3148
    add   eax,window_data
1 ha 3149
 
3150
    ; colors
684 diamond 3151
    mov   [eax+WDATA.cl_workarea],edx
3152
    mov   [eax+WDATA.cl_titlebar],esi
3153
    mov   [eax+WDATA.cl_frames],edi
1 ha 3154
 
684 diamond 3155
    mov   edi, eax
3156
 
1 ha 3157
    ; check flag (?)
186 diamond 3158
    test  [edi+WDATA.fl_wdrawn],1
3159
    jnz   newd
1 ha 3160
 
3161
    mov   eax,[timer_ticks] ;[0xfdf0]
3162
    add   eax,100
3163
    mov   [new_window_starting],eax
3164
 
684 diamond 3165
    mov   word[edi+WDATA.box.width],bx
3166
    mov   word[edi+WDATA.box.height],cx
114 mikedld 3167
    sar   ebx,16
684 diamond 3168
    sar   ecx,16
3169
    mov   word[edi+WDATA.box.left],bx
3170
    mov   word[edi+WDATA.box.top],cx
1 ha 3171
 
3172
    call  check_window_position
3173
 
164 serge 3174
    call  set_window_clientbox
1 ha 3175
 
742 Rus 3176
    push  ecx esi edi		    ; save for window fullscreen/resize
114 mikedld 3177
    ;mov   esi,edi
3178
 
742 Rus 3179
	mov	cl, [edi+WDATA.fl_wstyle]
3180
	mov	eax, [edi+WDATA.cl_frames]
114 mikedld 3181
 
1 ha 3182
    sub   edi,window_data
114 mikedld 3183
    shl   edi,3
380 serge 3184
    add   edi,SLOT_BASE
114 mikedld 3185
 
742 Rus 3186
	and	cl,0x0F
3187
	mov	[edi+APPDATA.wnd_caption],0
3188
	cmp	cl,3
3189
	je	set_APPDATA_wnd_caption
3190
	cmp	cl,4								; {SPraid.simba}
3191
	je	set_APPDATA_wnd_caption
567 serge 3192
 
742 Rus 3193
	jmp	@f
549 spraid 3194
    set_APPDATA_wnd_caption:
742 Rus 3195
	mov	[edi+APPDATA.wnd_caption],eax
3196
    @@: mov	esi,[esp+0]
114 mikedld 3197
 
115 poddubny 3198
    add   edi, APPDATA.saved_box
742 Rus 3199
	movsd
3200
	movsd
3201
	movsd
3202
	movsd
1 ha 3203
    pop   edi esi ecx
3204
 
742 Rus 3205
	mov	esi, [CURRENT_TASK]
3206
	movzx	esi, word [WIN_STACK+esi*2]
3207
	lea	esi, [WIN_POS+esi*2]
3208
	call	waredraw
569 diamond 3209
 
684 diamond 3210
;;;    mov   ebx, 1
1 ha 3211
;;;    call  delay_hs
115 poddubny 3212
    mov   eax, [edi+WDATA.box.left]
3213
    mov   ebx, [edi+WDATA.box.top]
3214
    mov   ecx, [edi+WDATA.box.width]
3215
    mov   edx, [edi+WDATA.box.height]
1 ha 3216
    add   ecx, eax
3217
    add   edx, ebx
3218
    call  calculatescreen
3219
 
742 Rus 3220
    mov   [KEY_COUNT],byte 0	       ; empty keyboard buffer
3221
    mov   [BTN_COUNT],byte 0	       ; empty button buffer
1 ha 3222
 
3223
  newd:
742 Rus 3224
    mov   [edi+WDATA.fl_redraw],byte 0	 ; no redraw
1 ha 3225
    mov   edx,edi
3226
 
3227
    ret
3228
 
114 mikedld 3229
syscall_windowsettings:
1 ha 3230
 
114 mikedld 3231
  .set_window_caption:
742 Rus 3232
	dec	eax	; subfunction #1 - set window caption
3233
	jnz	.get_window_caption
114 mikedld 3234
 
742 Rus 3235
	; NOTE: only window owner thread can set its caption,
3236
	;       so there's no parameter for PID/TID
114 mikedld 3237
 
742 Rus 3238
	mov	edi,[CURRENT_TASK]
3239
	shl	edi,5
114 mikedld 3240
 
742 Rus 3241
	; have to check if caption is within application memory limit
3242
	; check is trivial, and if application resizes its memory,
3243
	;   caption still can become over bounds
202 diamond 3244
; diamond, 31.10.2006: check removed because with new memory manager
3245
; there can be valid data after APPDATA.mem_size bound
380 serge 3246
;        mov     ecx,[edi*8+SLOT_BASE+APPDATA.mem_size]
202 diamond 3247
;        add     ecx,255 ; max caption length
3248
;        cmp     ebx,ecx
3249
;        ja      .exit_fail
114 mikedld 3250
 
742 Rus 3251
	mov	[edi*8+SLOT_BASE+APPDATA.wnd_caption],ebx
3252
	or	[edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
114 mikedld 3253
 
742 Rus 3254
	call	draw_window_caption
114 mikedld 3255
 
742 Rus 3256
	xor	eax,eax ; eax = 0 (success)
3257
	ret
114 mikedld 3258
 
3259
  .get_window_caption:
742 Rus 3260
	dec	eax	; subfunction #2 - get window caption
3261
	jnz	.exit_fail
114 mikedld 3262
 
742 Rus 3263
	; not implemented yet
114 mikedld 3264
 
3265
  .exit_fail:
742 Rus 3266
	xor	eax,eax
3267
	inc	eax	; eax = 1 (fail)
3268
	ret
114 mikedld 3269
 
3270
 
1 ha 3271
sys_window_move:
3272
 
742 Rus 3273
	mov	edi,[CURRENT_TASK]
3274
	shl	edi,5
3275
	add	edi,window_data
1 ha 3276
 
742 Rus 3277
	test	[edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
3278
	jnz	.window_move_return
1 ha 3279
 
742 Rus 3280
	push	dword [edi + WDATA.box.left]  ; save old coordinates
3281
	push	dword [edi + WDATA.box.top]
3282
	push	dword [edi + WDATA.box.width]
3283
	push	dword [edi + WDATA.box.height]
1 ha 3284
 
742 Rus 3285
	cmp   eax,-1		      ; set new position and size
3286
	je    .no_x_reposition
3287
	mov	[edi + WDATA.box.left], eax
49 mikedld 3288
      .no_x_reposition:
742 Rus 3289
	cmp   ebx,-1
3290
	je    .no_y_reposition
3291
	mov	[edi + WDATA.box.top], ebx
49 mikedld 3292
      .no_y_reposition:
1 ha 3293
 
742 Rus 3294
	test	[edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
3295
	jnz	.no_y_resizing
1 ha 3296
 
742 Rus 3297
	cmp   ecx,-1
3298
	je    .no_x_resizing
3299
	mov	[edi + WDATA.box.width], ecx
49 mikedld 3300
      .no_x_resizing:
742 Rus 3301
	cmp   edx,-1
3302
	je    .no_y_resizing
3303
	mov	[edi + WDATA.box.height], edx
49 mikedld 3304
      .no_y_resizing:
1 ha 3305
 
742 Rus 3306
	call  check_window_position
3307
	call  set_window_clientbox
1 ha 3308
 
742 Rus 3309
	pushad			     ; save for window fullscreen/resize
3310
	mov   esi,edi
3311
	sub   edi,window_data
3312
	shr   edi,5
3313
	shl   edi,8
3314
	add   edi, SLOT_BASE + APPDATA.saved_box
3315
	mov   ecx,4
3316
	cld
3317
	rep   movsd
3318
	popad
49 mikedld 3319
 
742 Rus 3320
	pushad			     ; calculcate screen at new position
3321
	mov   eax, [edi + WDATA.box.left]
3322
	mov   ebx, [edi + WDATA.box.top]
3323
	mov   ecx, [edi + WDATA.box.width]
3324
	mov   edx, [edi + WDATA.box.height]
3325
	add   ecx,eax
3326
	add   edx,ebx
221 serge 3327
 
742 Rus 3328
	call  calculatescreen
3329
	popad
49 mikedld 3330
 
742 Rus 3331
	pop   edx		    ; calculcate screen at old position
3332
	pop   ecx
3333
	pop   ebx
3334
	pop   eax
3335
	add   ecx,eax
3336
	add   edx,ebx
3337
	mov   [dlx],eax 	    ; save for drawlimits
3338
	mov   [dly],ebx
3339
	mov   [dlxe],ecx
3340
	mov   [dlye],edx
3341
	call  calculatescreen
49 mikedld 3342
 
742 Rus 3343
	mov   [edi + WDATA.fl_redraw], 1 ; flag the process as redraw
49 mikedld 3344
 
742 Rus 3345
	mov   eax,edi		    ; redraw screen at old position
3346
	xor   esi,esi
3347
	call  redrawscreen
49 mikedld 3348
 
742 Rus 3349
	mov   [DONT_DRAW_MOUSE],byte 0 ; mouse pointer
3350
	mov   [MOUSE_BACKGROUND],byte 0 ; no mouse under
3351
	mov   [MOUSE_DOWN],byte 0 ; react to mouse up/down
49 mikedld 3352
 
742 Rus 3353
	call  [draw_pointer]
49 mikedld 3354
 
742 Rus 3355
	mov   [window_move_pr],0
49 mikedld 3356
 
3357
      .window_move_return:
3358
 
742 Rus 3359
	ret
1 ha 3360
 
3361
uglobal
3362
  window_move_pr   dd  0x0
3363
  window_move_eax  dd  0x0
3364
  window_move_ebx  dd  0x0
3365
  window_move_ecx  dd  0x0
3366
  window_move_edx  dd  0x0
3367
endg
3368
 
3369
;ok - 100% work
3370
;nt - not tested
3371
;---------------------------------------------------------------------------------------------
3372
;eax
3373
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3374
;1 - change task. Ret nothing. Block. ok.
3375
;2 - performance control
3376
; ebx
3377
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3378
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3379
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3380
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3381
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3382
;eax
3383
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3384
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3385
;---------------------------------------------------------------------------------------------
3386
sys_sheduler: ;noname & halyavin
3387
    cmp eax,0
3388
    je shed_counter
3389
    cmp eax,2
3390
    je perf_control
3391
    cmp eax,3
3392
    je rdmsr_instr
3393
    cmp eax,4
3394
    je wrmsr_instr
3395
    cmp eax,1
3396
    jne not_supported
3397
    call change_task ;delay,0
3398
ret
3399
shed_counter:
3400
    mov eax,[context_counter]
3401
    mov [esp+36],eax
3402
not_supported:
3403
ret
3404
perf_control:
3405
    inc eax ;now eax=3
3406
    cmp ebx,eax
3407
    je cache_disable
3408
    dec eax
3409
    cmp ebx,eax
3410
    je cache_enable
3411
    dec eax
3412
    cmp ebx,eax
3413
    je is_cache_enabled
3414
    dec eax
3415
    cmp ebx,eax
3416
    je modify_pce
3417
ret
3418
 
3419
rdmsr_instr:
3420
;now counter in ecx
3421
;(edx:eax) esi:edi => edx:esi
3422
mov eax,esi
3423
rdmsr
3424
mov [esp+36],eax
3425
mov [esp+24],edx ;ret in ebx?
3426
ret
3427
 
3428
wrmsr_instr:
3429
;now counter in ecx
3430
;(edx:eax) esi:edi => edx:esi
482 Ghost 3431
	; Fast Call MSR can't be destroy
3432
	; Íî MSR_AMD_EFER ìîæíî èçìåíÿòü, ò.ê. â ýòîì ðåãèñòðå ëèø
3433
	; âêëþ÷àþòñÿ/âûêëþ÷àþòñÿ ðàñøèðåííûå âîçìîæíîñòè
3434
	cmp	ecx, MSR_SYSENTER_CS
3435
	je	@f
3436
	cmp	ecx, MSR_SYSENTER_ESP
3437
	je	@f
3438
	cmp	ecx, MSR_SYSENTER_EIP
3439
	je	@f
3440
	cmp	ecx, MSR_AMD_STAR
3441
	je	@f
3442
 
3443
	mov	eax, esi
3444
	wrmsr
742 Rus 3445
	; mov   [esp + 36], eax
3446
	; mov   [esp + 24], edx ;ret in ebx?
482 Ghost 3447
@@:
1 ha 3448
ret
3449
 
3450
cache_disable:
3451
       mov eax,cr0
3452
       or  eax,01100000000000000000000000000000b
3453
       mov cr0,eax
3454
       wbinvd ;set MESI
3455
ret
3456
 
3457
cache_enable:
3458
       mov eax,cr0
3459
       and eax,10011111111111111111111111111111b
3460
       mov cr0,eax
3461
ret
3462
 
3463
is_cache_enabled:
3464
       mov eax,cr0
3465
       mov ebx,eax
3466
       and eax,01100000000000000000000000000000b
3467
       jz cache_disabled
3468
       mov [esp+36],ebx
3469
cache_disabled:
3470
       mov dword [esp+36],eax ;0
3471
ret
3472
 
3473
modify_pce:
3474
       mov eax,cr4
3475
;       mov ebx,0
3476
;       or  bx,100000000b ;pce
3477
;       xor eax,ebx ;invert pce
17 me_root 3478
       bts eax,8 ;pce=cr4[8]
1 ha 3479
       mov cr4,eax
3480
       mov [esp+36],eax
3481
ret
3482
;---------------------------------------------------------------------------------------------
3483
 
3484
 
3485
; check if pixel is allowed to be drawn
3486
 
3487
checkpixel:
742 Rus 3488
	push eax edx
1 ha 3489
 
759 Rus 3490
	mov  edx,[Screen_Max_X]     ; screen x size
840 serge 3491
        mov  ecx, [_display_data]
3492
 
3493
        inc  edx
742 Rus 3494
	imul edx, ebx
1 ha 3495
 
840 serge 3496
        add edx, ecx
3497
        mov  dl, [eax+edx] ; lea eax, [...]
3498
 
742 Rus 3499
	xor  ecx, ecx
3500
	mov  eax, [CURRENT_TASK]
3501
	cmp  al, dl
3502
	setne cl
1 ha 3503
 
742 Rus 3504
	pop  edx eax
3505
	ret
1 ha 3506
 
3507
iglobal
521 diamond 3508
  cpustring db 'CPU',0
1 ha 3509
endg
3510
 
67 diamond 3511
uglobal
742 Rus 3512
background_defined    db    0	 ; diamond, 11.04.2006
67 diamond 3513
endg
1 ha 3514
 
3515
align 4
3516
; check misc
3517
 
3518
checkmisc:
3519
 
3520
    cmp   [ctrl_alt_del], 1
3521
    jne   nocpustart
501 serge 3522
 
742 Rus 3523
	mov	ebp, cpustring
3524
	call	fs_execute_from_sysdir
501 serge 3525
 
1 ha 3526
    mov   [ctrl_alt_del], 0
465 serge 3527
 
3528
nocpustart:
1 ha 3529
    cmp   [mouse_active], 1
3530
    jne   mouse_not_active
3531
    mov   [mouse_active], 0
3532
    xor   edi, edi
742 Rus 3533
    mov   ecx,	[TASK_COUNT]
465 serge 3534
set_mouse_event:
1 ha 3535
    add   edi, 256
742 Rus 3536
    or	  [edi+SLOT_BASE+APPDATA.event_mask], dword 100000b
1 ha 3537
    loop  set_mouse_event
3538
 
465 serge 3539
mouse_not_active:
742 Rus 3540
    cmp   [REDRAW_BACKGROUND],byte 0		   ; background update ?
3541
    jz	  nobackgr
76 mario79 3542
    cmp    [background_defined], 0
742 Rus 3543
    jz	  nobackgr
709 diamond 3544
    cmp   [REDRAW_BACKGROUND], byte 2
3545
    jnz   no_set_bgr_event
473 diamond 3546
    xor   edi, edi
742 Rus 3547
    mov   ecx,	[TASK_COUNT]
473 diamond 3548
set_bgr_event:
3549
    add   edi, 256
742 Rus 3550
    or	  [edi+SLOT_BASE+APPDATA.event_mask], 16
473 diamond 3551
    loop  set_bgr_event
709 diamond 3552
no_set_bgr_event:
3553
;    mov   [draw_data+32 + RECT.left],dword 0
3554
;    mov   [draw_data+32 + RECT.top],dword 0
753 serge 3555
;    mov   eax,[Screen_Max_X]
3556
;    mov   ebx,[Screen_Max_Y]
709 diamond 3557
;    mov   [draw_data+32 + RECT.right],eax
3558
;    mov   [draw_data+32 + RECT.bottom],ebx
1 ha 3559
    call  drawbackground
381 serge 3560
    mov   [REDRAW_BACKGROUND],byte 0
3561
    mov   [MOUSE_BACKGROUND],byte 0
1 ha 3562
 
465 serge 3563
nobackgr:
1 ha 3564
 
3565
    ; system shutdown request
3566
 
381 serge 3567
    cmp  [SYS_SHUTDOWN],byte 0
742 Rus 3568
    je	 noshutdown
1 ha 3569
 
3570
    mov  edx,[shutdown_processes]
3571
 
381 serge 3572
    cmp  [SYS_SHUTDOWN],dl
1 ha 3573
    jne  no_mark_system_shutdown
3574
 
709 diamond 3575
    lea   ecx,[edx-1]
465 serge 3576
    mov   edx,OS_BASE+0x3040
709 diamond 3577
    jecxz @f
465 serge 3578
markz:
115 poddubny 3579
    mov   [edx+TASKDATA.state],byte 3
1 ha 3580
    add   edx,0x20
3581
    loop  markz
709 diamond 3582
@@:
1 ha 3583
 
3584
  no_mark_system_shutdown:
3585
 
3586
    call [disable_mouse]
3587
 
381 serge 3588
    dec  byte [SYS_SHUTDOWN]
742 Rus 3589
    je	 system_shutdown
1 ha 3590
 
465 serge 3591
noshutdown:
1 ha 3592
 
3593
 
742 Rus 3594
    mov   eax,[TASK_COUNT]		    ; termination
379 serge 3595
    mov   ebx,TASK_DATA+TASKDATA.state
1 ha 3596
    mov   esi,1
3597
 
465 serge 3598
newct:
1 ha 3599
    mov   cl,[ebx]
3600
    cmp   cl,byte 3
742 Rus 3601
    jz	  terminate
1 ha 3602
    cmp   cl,byte 4
742 Rus 3603
    jz	  terminate
1 ha 3604
 
3605
    add   ebx,0x20
3606
    inc   esi
3607
    dec   eax
3608
    jnz   newct
3609
    ret
3610
 
3611
; redraw screen
3612
 
3613
redrawscreen:
3614
 
3615
; eax , if process window_data base is eax, do not set flag/limits
3616
 
742 Rus 3617
	 pushad
3618
	 push  eax
1 ha 3619
 
684 diamond 3620
;;;         mov   ebx,2
1 ha 3621
;;;         call  delay_hs
3622
 
742 Rus 3623
	 ;mov   ecx,0               ; redraw flags for apps
3624
	 xor   ecx,ecx
1 ha 3625
       newdw2:
3626
 
742 Rus 3627
	 inc   ecx
3628
	 push  ecx
1 ha 3629
 
742 Rus 3630
	 mov   eax,ecx
3631
	 shl   eax,5
3632
	 add   eax,window_data
1 ha 3633
 
742 Rus 3634
	 cmp   eax,[esp+4]
3635
	 je    not_this_task
3636
				   ; check if window in redraw area
3637
	 mov   edi,eax
1 ha 3638
 
742 Rus 3639
	 cmp   ecx,1		   ; limit for background
3640
	 jz    bgli
1 ha 3641
 
742 Rus 3642
	 mov   eax, [edi + WDATA.box.left]
3643
	 mov   ebx, [edi + WDATA.box.top]
3644
	 mov   ecx, [edi + WDATA.box.width]
3645
	 mov   edx, [edi + WDATA.box.height]
3646
	 add   ecx,eax
3647
	 add   edx,ebx
1 ha 3648
 
742 Rus 3649
	 mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
3650
	 cmp   ecx,ebx
3651
	 jb    ricino
1 ha 3652
 
742 Rus 3653
	 mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
3654
	 cmp   ecx,eax
3655
	 jb    ricino
1 ha 3656
 
742 Rus 3657
	 mov   eax, [edi + WDATA.box.left]
3658
	 mov   ebx, [edi + WDATA.box.top]
3659
	 mov   ecx, [edi + WDATA.box.width]
3660
	 mov   edx, [edi + WDATA.box.height]
3661
	 add   ecx, eax
3662
	 add   edx, ebx
164 serge 3663
 
742 Rus 3664
	 mov   eax,[dly]    ; eax = area y start     edx = window y end
3665
	 cmp   edx,eax
3666
	 jb    ricino
1 ha 3667
 
742 Rus 3668
	 mov   eax,[dlx]    ; eax = area x start     ecx = window x end
3669
	 cmp   ecx,eax
3670
	 jb    ricino
1 ha 3671
 
742 Rus 3672
	bgli:
1 ha 3673
 
742 Rus 3674
	 cmp   ecx,1
3675
	 jnz   .az
3676
	 mov   al,[REDRAW_BACKGROUND]
3677
	 cmp   al,2
3678
	 jz    newdw8
3679
	 test  al,al
3680
	 jz    .az
3681
	 lea   eax,[edi+draw_data-window_data]
3682
	 mov   ebx,[dlx]
3683
	 cmp   ebx,[eax+RECT.left]
3684
	 jae   @f
3685
	 mov   [eax+RECT.left],ebx
3686
	@@:
3687
	 mov   ebx,[dly]
3688
	 cmp   ebx,[eax+RECT.top]
3689
	 jae   @f
3690
	 mov   [eax+RECT.top],ebx
3691
	@@:
3692
	 mov   ebx,[dlxe]
3693
	 cmp   ebx,[eax+RECT.right]
3694
	 jbe   @f
3695
	 mov   [eax+RECT.right],ebx
3696
	@@:
3697
	 mov   ebx,[dlye]
3698
	 cmp   ebx,[eax+RECT.bottom]
3699
	 jbe   @f
3700
	 mov   [eax+RECT.bottom],ebx
3701
	@@:
3702
	 jmp   newdw8
3703
	.az:
1 ha 3704
 
742 Rus 3705
	 mov   eax,edi
3706
	 add   eax,draw_data-window_data
1 ha 3707
 
742 Rus 3708
	 mov   ebx,[dlx]	  ; set limits
3709
	 mov   [eax + RECT.left], ebx
3710
	 mov   ebx,[dly]
3711
	 mov   [eax + RECT.top], ebx
3712
	 mov   ebx,[dlxe]
3713
	 mov   [eax + RECT.right], ebx
3714
	 mov   ebx,[dlye]
3715
	 mov   [eax + RECT.bottom], ebx
1 ha 3716
 
742 Rus 3717
	 sub   eax,draw_data-window_data
1 ha 3718
 
742 Rus 3719
	 cmp   dword [esp],1
3720
	 jne   nobgrd
3721
	 mov   byte [REDRAW_BACKGROUND], 1
1 ha 3722
 
3723
       newdw8:
3724
       nobgrd:
3725
 
742 Rus 3726
	 mov   [eax + WDATA.fl_redraw],byte 1	 ; mark as redraw
1 ha 3727
 
3728
       ricino:
3729
 
3730
       not_this_task:
3731
 
742 Rus 3732
	 pop   ecx
1 ha 3733
 
742 Rus 3734
	 cmp   ecx,[TASK_COUNT]
3735
	 jle   newdw2
1 ha 3736
 
742 Rus 3737
	 pop  eax
3738
	 popad
1 ha 3739
 
742 Rus 3740
	 ret
1 ha 3741
 
3742
calculatebackground:   ; background
3743
 
742 Rus 3744
	; all black
1 ha 3745
 
742 Rus 3746
	mov   edi, [img_background]  ;IMG_BACKGROUND                 ; set background to black
3747
	xor   eax, eax
3748
	mov   ecx, 1023    ;0x0fff00 / 4
3749
	cld
3750
	rep   stosd
1 ha 3751
 
840 serge 3752
        mov   edi, [_display_data]              ; set os to use all pixels
742 Rus 3753
	mov   eax,0x01010101
3754
	mov   ecx,1280*1024 / 4
3755
	rep   stosd
1 ha 3756
 
742 Rus 3757
	mov   byte [REDRAW_BACKGROUND], 0	       ; do not draw background!
1 ha 3758
 
742 Rus 3759
	ret
1 ha 3760
 
3761
uglobal
742 Rus 3762
  imax	  dd 0x0
1 ha 3763
endg
3764
 
3765
 
3766
 
3767
delay_ms:     ; delay in 1/1000 sec
3768
 
3769
 
742 Rus 3770
	push  eax
3771
	push  ecx
1 ha 3772
 
742 Rus 3773
	mov   ecx,esi
3774
	; 
3775
	imul  ecx, 33941
3776
	shr   ecx, 9
3777
	; 
1 ha 3778
 
742 Rus 3779
	in    al,0x61
3780
	and   al,0x10
3781
	mov   ah,al
3782
	cld
1 ha 3783
 
742 Rus 3784
 cnt1:	in    al,0x61
3785
	and   al,0x10
3786
	cmp   al,ah
3787
	jz    cnt1
1 ha 3788
 
742 Rus 3789
	mov   ah,al
3790
	loop  cnt1
1 ha 3791
 
742 Rus 3792
	pop   ecx
3793
	pop   eax
1 ha 3794
 
742 Rus 3795
	ret
1 ha 3796
 
3797
 
3798
set_app_param:
742 Rus 3799
	mov	edi, [TASK_BASE]
3800
	mov	[edi + TASKDATA.event_mask], ebx
3801
	ret
1 ha 3802
 
3803
 
3804
 
3805
delay_hs:     ; delay in 1/100 secs
684 diamond 3806
; ebx = delay time
742 Rus 3807
	push  ecx
3808
	push  edx
1 ha 3809
 
742 Rus 3810
	mov   edx,[timer_ticks]
1 ha 3811
 
3812
      newtic:
742 Rus 3813
	mov   ecx,[timer_ticks]
3814
	sub   ecx,edx
3815
	cmp   ecx,ebx
3816
	jae   zerodelay
1 ha 3817
 
742 Rus 3818
	call  change_task
1 ha 3819
 
742 Rus 3820
	jmp   newtic
1 ha 3821
 
3822
      zerodelay:
742 Rus 3823
	pop   edx
3824
	pop   ecx
1 ha 3825
 
742 Rus 3826
	ret
1 ha 3827
 
3828
 
3829
memmove:       ; memory move in bytes
3830
 
3831
; eax = from
3832
; ebx = to
3833
; ecx = no of bytes
3834
    test ecx, ecx
3835
    jle  .ret
3836
 
3837
 
3838
    push esi edi ecx
3839
 
3840
    mov  edi, ebx
3841
    mov  esi, eax
3842
 
3843
    test ecx, not 11b
742 Rus 3844
    jz	 @f
1 ha 3845
 
3846
    push ecx
3847
    shr  ecx, 2
3848
    rep  movsd
3849
    pop  ecx
3850
    and  ecx, 11b
742 Rus 3851
    jz	 .finish
1 ha 3852
  @@:
3853
    rep  movsb
3854
 
3855
  .finish:
3856
    pop  ecx edi esi
3857
  .ret:
3858
    ret
3859
 
3860
 
75 diamond 3861
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
3862
;align 4
1 ha 3863
;
75 diamond 3864
;read_floppy_file:
1 ha 3865
;
75 diamond 3866
;; as input
3867
;;
3868
;; eax pointer to file
3869
;; ebx file lenght
3870
;; ecx start 512 byte block number
3871
;; edx number of blocks to read
3872
;; esi pointer to return/work area (atleast 20 000 bytes)
3873
;;
3874
;;
3875
;; on return
3876
;;
3877
;; eax = 0 command succesful
3878
;;       1 no fd base and/or partition defined
3879
;;       2 yet unsupported FS
3880
;;       3 unknown FS
3881
;;       4 partition not defined at hd
3882
;;       5 file not found
3883
;; ebx = size of file
1 ha 3884
;
379 serge 3885
;     mov   edi,[TASK_BASE]
75 diamond 3886
;     add   edi,0x10
3887
;     add   esi,[edi]
3888
;     add   eax,[edi]
1 ha 3889
;
75 diamond 3890
;     pushad
3891
;     mov  edi,esi
3892
;     add  edi,1024
3893
;     mov  esi,0x100000+19*512
3894
;     sub  ecx,1
3895
;     shl  ecx,9
3896
;     add  esi,ecx
3897
;     shl  edx,9
3898
;     mov  ecx,edx
3899
;     cld
3900
;     rep  movsb
3901
;     popad
3902
;
3903
;     mov   [esp+36],eax
3904
;     mov   [esp+24],ebx
3905
;     ret
1 ha 3906
 
3907
 
3908
 
3909
align 4
3910
 
3911
sys_programirq:
3912
 
765 Rus 3913
    mov   eax, [TASK_BASE]
3914
    add   ebx, [eax + TASKDATA.mem_start]
1 ha 3915
 
765 Rus 3916
    cmp   ecx, 16
75 diamond 3917
    jae   .not_owner
765 Rus 3918
    mov   edi, [eax + TASKDATA.pid]
3919
    cmp   edi, [irq_owner + 4 * ecx]
3920
    je	  .spril1
75 diamond 3921
.not_owner:
765 Rus 3922
    xor   ecx, ecx
3923
    jmp   .end
3924
  .spril1:
1 ha 3925
 
765 Rus 3926
    shl   ecx, 6
3927
    mov   esi, ebx
3928
    lea   edi, [irq00read + ecx]
3929
    push  16
3930
    pop   ecx
3931
 
1 ha 3932
    cld
3933
    rep   movsd
765 Rus 3934
  .end:
3935
    mov   [esp+32], ecx
1 ha 3936
    ret
3937
 
3938
 
3939
align 4
3940
 
3941
get_irq_data:
760 Rus 3942
     movzx esi, bh			 ; save number of subfunction, if bh = 1, return data size, otherwise, read data
3943
     xor   bh, bh
3944
     cmp   ebx, 16
75 diamond 3945
     jae   .not_owner
760 Rus 3946
     mov   edx, [4 * ebx + irq_owner]	 ; check for irq owner
742 Rus 3947
 
760 Rus 3948
     mov   eax,[TASK_BASE]
742 Rus 3949
 
760 Rus 3950
     cmp   edx,[eax+TASKDATA.pid]
1 ha 3951
     je    gidril1
75 diamond 3952
.not_owner:
760 Rus 3953
     xor   edx, edx
3954
     dec   edx
3955
     jmp   gid1
1 ha 3956
 
3957
  gidril1:
3958
 
760 Rus 3959
     shl   ebx, 12
3960
     lea   eax, [ebx + IRQ_SAVE]	 ; calculate address of the beginning of buffer + 0x0 - data size
3961
     mov   edx, [eax]			 ;                                              + 0x4 - data offset
3962
     dec   esi
1 ha 3963
     jz    gid1
760 Rus 3964
     test  edx, edx			 ; check if buffer is empty
3965
     jz    gid1
1 ha 3966
 
760 Rus 3967
     mov   ebx, [eax + 0x4]
3968
     mov   edi, ecx
742 Rus 3969
 
760 Rus 3970
     mov   ecx, 4000			 ; buffer size, used frequently
742 Rus 3971
 
760 Rus 3972
     cmp   ebx, ecx			 ; check for the end of buffer, if end of buffer, begin cycle again
759 Rus 3973
     jb    @f
742 Rus 3974
 
760 Rus 3975
     xor   ebx, ebx
759 Rus 3976
 
3977
   @@:
3978
 
760 Rus 3979
     lea   esi, [ebx + edx]		 ; calculate data size and offset
3980
     cld
3981
     cmp   esi, ecx			 ; if greater than the buffer size, begin cycle again
3982
     jbe   @f
759 Rus 3983
 
760 Rus 3984
     sub   ecx, ebx
3985
     sub   edx, ecx
759 Rus 3986
 
760 Rus 3987
     lea   esi, [eax + ebx + 0x10]
3988
     rep   movsb
3989
 
3990
     xor   ebx, ebx
3991
   @@:
3992
     lea   esi, [eax + ebx + 0x10]
3993
     mov   ecx, edx
3994
     add   ebx, edx
3995
 
3996
     rep   movsb
3997
     mov   edx, [eax]
3998
     mov   [eax], ecx			 ; set data size to zero
3999
     mov   [eax + 0x4], ebx		 ; set data offset
4000
 
1 ha 4001
   gid1:
760 Rus 4002
     mov   [esp+32], edx		 ; eax
1 ha 4003
     ret
4004
 
4005
 
4006
set_io_access_rights:
4007
 
4008
     pushad
4009
 
465 serge 4010
     mov edi, tss._io_map_0
1 ha 4011
 
465 serge 4012
;     mov   ecx,eax
4013
;     and   ecx,7    ; offset in byte
1 ha 4014
 
465 serge 4015
;     shr   eax,3    ; number of byte
4016
;     add   edi,eax
1 ha 4017
 
465 serge 4018
;     mov   ebx,1
4019
;     shl   ebx,cl
1 ha 4020
 
742 Rus 4021
     cmp   ebp,0		; enable access - ebp = 0
1 ha 4022
     jne   siar1
4023
 
465 serge 4024
;     not   ebx
4025
;     and   [edi],byte bl
4026
     btr [edi], eax
1 ha 4027
 
4028
     popad
4029
 
4030
     ret
4031
 
465 serge 4032
siar1:
1 ha 4033
 
465 serge 4034
     bts [edi], eax
4035
  ;  or    [edi],byte bl        ; disable access - ebp = 1
1 ha 4036
 
4037
     popad
4038
 
4039
     ret
4040
 
4041
r_f_port_area:
4042
 
4043
     test  eax, eax
4044
     jnz   free_port_area
4045
;     je    r_port_area
4046
;     jmp   free_port_area
4047
 
4048
;   r_port_area:
4049
 
4050
     pushad
4051
 
742 Rus 4052
     cmp   ebx,ecx	      ; beginning > end ?
75 diamond 4053
     ja    rpal1
4054
     cmp   ecx,65536
4055
     jae   rpal1
381 serge 4056
     mov   esi,[RESERVED_PORTS]
742 Rus 4057
     test  esi,esi	      ; no reserved areas ?
1 ha 4058
     je    rpal2
742 Rus 4059
     cmp   esi,255	      ; max reserved
75 diamond 4060
     jae   rpal1
465 serge 4061
 rpal3:
1 ha 4062
     mov   edi,esi
4063
     shl   edi,4
381 serge 4064
     add   edi,RESERVED_PORTS
1 ha 4065
     cmp   ebx,[edi+8]
75 diamond 4066
     ja    rpal4
1 ha 4067
     cmp   ecx,[edi+4]
4068
     jae   rpal1
4069
;     jb    rpal4
4070
;     jmp   rpal1
465 serge 4071
 rpal4:
1 ha 4072
 
4073
     dec   esi
4074
     jnz   rpal3
4075
     jmp   rpal2
4076
   rpal1:
4077
     popad
4078
     mov   eax,1
4079
     ret
4080
 
4081
   rpal2:
4082
     popad
4083
 
4084
 
4085
     ; enable port access at port IO map
4086
     cli
742 Rus 4087
     pushad			   ; start enable io map
1 ha 4088
 
4089
     cmp   ecx,65536 ;16384
4090
     jae   no_unmask_io ; jge
4091
 
4092
     mov   eax,ebx
4093
 
4094
   new_port_access:
4095
 
4096
     pushad
4097
 
742 Rus 4098
     xor   ebp,ebp		  ; enable - eax = port
1 ha 4099
     call  set_io_access_rights
4100
 
4101
     popad
4102
 
4103
     inc   eax
4104
     cmp   eax,ecx
4105
     jbe   new_port_access
4106
 
4107
   no_unmask_io:
4108
 
742 Rus 4109
     popad			   ; end enable io map
1 ha 4110
     sti
4111
 
381 serge 4112
     mov   edi,[RESERVED_PORTS]
1 ha 4113
     add   edi,1
381 serge 4114
     mov   [RESERVED_PORTS],edi
1 ha 4115
     shl   edi,4
381 serge 4116
     add   edi,RESERVED_PORTS
379 serge 4117
     mov   esi,[TASK_BASE]
115 poddubny 4118
     mov   esi,[esi+TASKDATA.pid]
1 ha 4119
     mov   [edi],esi
4120
     mov   [edi+4],ebx
4121
     mov   [edi+8],ecx
4122
 
4123
     xor   eax, eax
4124
     ret
4125
 
4126
free_port_area:
4127
 
4128
     pushad
4129
 
381 serge 4130
     mov   esi,[RESERVED_PORTS]     ; no reserved areas ?
75 diamond 4131
     test  esi,esi
1 ha 4132
     je    frpal2
379 serge 4133
     mov   edx,[TASK_BASE]
115 poddubny 4134
     mov   edx,[edx+TASKDATA.pid]
1 ha 4135
   frpal3:
4136
     mov   edi,esi
4137
     shl   edi,4
381 serge 4138
     add   edi,RESERVED_PORTS
1 ha 4139
     cmp   edx,[edi]
4140
     jne   frpal4
4141
     cmp   ebx,[edi+4]
4142
     jne   frpal4
4143
     cmp   ecx,[edi+8]
4144
     jne   frpal4
4145
     jmp   frpal1
4146
   frpal4:
4147
     dec   esi
4148
     jnz   frpal3
4149
   frpal2:
4150
     popad
4151
     mov   eax,1
4152
     ret
4153
   frpal1:
4154
     mov   ecx,256
4155
     sub   ecx,esi
4156
     shl   ecx,4
4157
     mov   esi,edi
4158
     add   esi,16
4159
     cld
4160
     rep   movsb
4161
 
381 serge 4162
     dec   dword [RESERVED_PORTS]
1 ha 4163
 
4164
     popad
4165
 
4166
 
4167
     ; disable port access at port IO map
4168
 
742 Rus 4169
     pushad			   ; start disable io map
1 ha 4170
 
4171
     cmp   ecx,65536 ;16384
4172
     jge   no_mask_io
4173
 
4174
     mov   eax,ebx
4175
 
4176
   new_port_access_disable:
4177
 
4178
     pushad
4179
 
742 Rus 4180
     mov   ebp,1		  ; disable - eax = port
1 ha 4181
     call  set_io_access_rights
4182
 
4183
     popad
4184
 
4185
     inc   eax
4186
     cmp   eax,ecx
4187
     jbe   new_port_access_disable
4188
 
4189
   no_mask_io:
4190
 
742 Rus 4191
     popad			   ; end disable io map
1 ha 4192
 
4193
     xor   eax, eax
4194
     ret
4195
 
4196
 
4197
reserve_free_irq:
4198
 
765 Rus 4199
     xor   esi, esi
4200
     inc   esi
4201
     cmp   ecx, 16
4202
     jae   ril1
1 ha 4203
 
769 Rus 4204
     push  ecx
765 Rus 4205
     lea   ecx, [irq_owner + 4 * ecx]
4206
     mov   edx, [ecx]
4207
     mov   eax, [TASK_BASE]
4208
     mov   edi, [eax + TASKDATA.pid]
769 Rus 4209
     pop   eax
765 Rus 4210
     dec   ebx
4211
     jnz   reserve_irq
1 ha 4212
 
765 Rus 4213
     cmp   edx, edi
4214
     jne   ril1
4215
     dec   esi
4216
     mov   [ecx], esi
4217
 
4218
     jmp   ril1
4219
 
1 ha 4220
  reserve_irq:
4221
 
765 Rus 4222
     cmp   dword [ecx], 0
4223
     jne   ril1
1 ha 4224
 
769 Rus 4225
     mov   ebx, [f_irqs + 4 * eax]
4226
 
774 Rus 4227
     stdcall attach_int_handler, eax, ebx, dword 0
769 Rus 4228
 
765 Rus 4229
     mov   [ecx], edi
769 Rus 4230
 
765 Rus 4231
     dec   esi
1 ha 4232
   ril1:
765 Rus 4233
     mov   [esp+32], esi ; return in eax
1 ha 4234
     ret
4235
 
769 Rus 4236
iglobal
4237
f_irqs:
4238
     dd 0x0
4239
     dd 0x0
4240
     dd p_irq2
4241
     dd p_irq3
4242
     dd p_irq4
4243
     dd p_irq5
4244
     dd p_irq6
4245
     dd p_irq7
4246
     dd p_irq8
4247
     dd p_irq9
4248
     dd p_irq10
4249
     dd p_irq11
4250
     dd 0x0
4251
     dd 0x0
4252
     dd p_irq14
4253
     dd p_irq15
4254
 
4255
endg
4256
 
1 ha 4257
drawbackground:
33 mario79 4258
       inc   [mouse_pause]
381 serge 4259
       cmp   [SCR_MODE],word 0x12
117 mario79 4260
       je   dbrv20
1 ha 4261
     dbrv12:
381 serge 4262
       cmp  [SCR_MODE],word 0100000000000000b
1 ha 4263
       jge  dbrv20
381 serge 4264
       cmp  [SCR_MODE],word 0x13
1 ha 4265
       je   dbrv20
4266
       call  vesa12_drawbackground
33 mario79 4267
       dec   [mouse_pause]
36 mario79 4268
       call   [draw_pointer]
1 ha 4269
       ret
4270
     dbrv20:
527 diamond 4271
       cmp   [BgrDrawMode],dword 1
1 ha 4272
       jne   bgrstr
4273
       call  vesa20_drawbackground_tiled
33 mario79 4274
       dec   [mouse_pause]
36 mario79 4275
       call   [draw_pointer]
1 ha 4276
       ret
4277
     bgrstr:
4278
       call  vesa20_drawbackground_stretch
33 mario79 4279
       dec   [mouse_pause]
36 mario79 4280
       call   [draw_pointer]
1 ha 4281
       ret
4282
 
75 diamond 4283
align 4
1 ha 4284
 
742 Rus 4285
syscall_putimage:			; PutImage
1 ha 4286
sys_putimage:
53 mikedld 4287
     test  ecx,0x80008000
4288
     jnz   .exit
4289
     test  ecx,0x0000FFFF
4290
     jz    .exit
4291
     test  ecx,0xFFFF0000
4292
     jnz   @f
4293
  .exit:
4294
     ret
4295
 @@:
742 Rus 4296
	mov	edi,[current_slot]
4297
	add	dx,word[edi+APPDATA.wnd_clientbox.top]
4298
	rol	edx,16
4299
	add	dx,word[edi+APPDATA.wnd_clientbox.left]
4300
	rol	edx,16
114 mikedld 4301
  .forced:
742 Rus 4302
	push	ebp esi 0
4303
	mov	ebp, putimage_get24bpp
4304
	mov	esi, putimage_init24bpp
283 diamond 4305
sys_putimage_bpp:
4306
;        call    [disable_mouse] ; this will be done in xxx_putimage
117 mario79 4307
;        mov     eax, vga_putimage
742 Rus 4308
	cmp	[SCR_MODE], word 0x12
4309
	jz	@f   ;.doit
4310
	mov	eax, vesa12_putimage
4311
	cmp	[SCR_MODE], word 0100000000000000b
4312
	jae	@f
4313
	cmp	[SCR_MODE], word 0x13
4314
	jnz	.doit
75 diamond 4315
@@:
742 Rus 4316
	mov	eax, vesa20_putimage
75 diamond 4317
.doit:
742 Rus 4318
	inc	[mouse_pause]
4319
	call	eax
4320
	dec	[mouse_pause]
4321
	pop	ebp esi ebp
4322
	jmp	[draw_pointer]
1 ha 4323
 
283 diamond 4324
syscall_putimage_palette:
742 Rus 4325
	mov	edi, esi
4326
	mov	esi, edx
4327
	mov	edx, ecx
4328
	mov	ecx, ebx
4329
	mov	ebx, eax
283 diamond 4330
sys_putimage_palette:
4331
; ebx = pointer to image
4332
; ecx = [xsize]*65536 + [ysize]
4333
; edx = [xstart]*65536 + [ystart]
314 diamond 4334
; esi = number of bits per pixel, must be 8, 24 or 32
283 diamond 4335
; edi = pointer to palette
314 diamond 4336
; ebp = row delta
742 Rus 4337
	mov	eax, [CURRENT_TASK]
4338
	shl	eax, 8
4339
	add	dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
4340
	rol	edx, 16
4341
	add	dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
4342
	rol	edx, 16
283 diamond 4343
.forced:
742 Rus 4344
	push	ebp esi ebp
4345
	cmp	esi, 8
4346
	jnz	@f
4347
	mov	ebp, putimage_get8bpp
4348
	mov	esi, putimage_init8bpp
4349
	jmp	sys_putimage_bpp
314 diamond 4350
@@:
844 serge 4351
        cmp     esi, 16
4352
        jnz     @f
4353
        mov     ebp, putimage_get16bpp
4354
        mov     esi, putimage_init16bpp
4355
        jmp     sys_putimage_bpp
4356
@@:
742 Rus 4357
	cmp	esi, 24
4358
	jnz	@f
4359
	mov	ebp, putimage_get24bpp
4360
	mov	esi, putimage_init24bpp
4361
	jmp	sys_putimage_bpp
314 diamond 4362
@@:
742 Rus 4363
	cmp	esi, 32
4364
	jnz	@f
4365
	mov	ebp, putimage_get32bpp
4366
	mov	esi, putimage_init32bpp
4367
	jmp	sys_putimage_bpp
314 diamond 4368
@@:
844 serge 4369
	pop	ebp esi ebp
742 Rus 4370
	ret
283 diamond 4371
 
4372
putimage_init24bpp:
742 Rus 4373
	lea	eax, [eax*3]
283 diamond 4374
putimage_init8bpp:
742 Rus 4375
	ret
283 diamond 4376
 
4377
putimage_get24bpp:
742 Rus 4378
	mov	eax, [esi]
4379
	add	esi, 3
4380
	ret	4
283 diamond 4381
putimage_get8bpp:
742 Rus 4382
	movzx	eax, byte [esi]
4383
	push	edx
4384
	mov	edx, [esp+8]
4385
	mov	eax, [edx+eax*4]
4386
	pop	edx
4387
	inc	esi
4388
	ret	4
283 diamond 4389
 
314 diamond 4390
putimage_init32bpp:
742 Rus 4391
	shl	eax, 2
4392
	ret
314 diamond 4393
putimage_get32bpp:
742 Rus 4394
	lodsd
4395
	ret	4
314 diamond 4396
 
844 serge 4397
putimage_init16bpp:
4398
        add     eax, eax
4399
        ret
4400
putimage_get16bpp:
4401
; 0RRRRRGGGGGBBBBB -> 00000000RRRRR000GGGGG000BBBBB000
4402
        push    ecx edx
4403
        movzx   eax, word [esi]
4404
        add     esi, 2
4405
        mov     ecx, eax
4406
        mov     edx, eax
4407
        and     eax, 0x1F
4408
        and     ecx, 0x1F shl 5
4409
        and     edx, 0x1F shl 10
4410
        shl     eax, 3
4411
        shl     ecx, 6
4412
        shl     edx, 9
4413
        or      eax, ecx
4414
        or      eax, edx
4415
        pop     edx ecx
4416
        ret
4417
 
1 ha 4418
; eax x beginning
4419
; ebx y beginning
4420
; ecx x end
283 diamond 4421
	; edx y end
1 ha 4422
; edi color
4423
 
4424
__sys_drawbar:
742 Rus 4425
	mov	esi,[current_slot]
4426
	add	eax,[esi+APPDATA.wnd_clientbox.left]
4427
	add	ecx,[esi+APPDATA.wnd_clientbox.left]
4428
	add	ebx,[esi+APPDATA.wnd_clientbox.top]
4429
	add	edx,[esi+APPDATA.wnd_clientbox.top]
114 mikedld 4430
  .forced:
33 mario79 4431
    inc   [mouse_pause]
283 diamond 4432
;        call    [disable_mouse]
381 serge 4433
    cmp   [SCR_MODE],word 0x12
742 Rus 4434
    je	 dbv20
1 ha 4435
   sdbv20:
381 serge 4436
    cmp  [SCR_MODE],word 0100000000000000b
1 ha 4437
    jge  dbv20
381 serge 4438
    cmp  [SCR_MODE],word 0x13
742 Rus 4439
    je	 dbv20
1 ha 4440
    call vesa12_drawbar
33 mario79 4441
    dec   [mouse_pause]
36 mario79 4442
    call   [draw_pointer]
1 ha 4443
    ret
4444
  dbv20:
4445
    call vesa20_drawbar
33 mario79 4446
    dec   [mouse_pause]
36 mario79 4447
    call   [draw_pointer]
1 ha 4448
    ret
4449
 
4450
 
4451
 
4452
kb_read:
4453
 
742 Rus 4454
	push	ecx edx
1 ha 4455
 
742 Rus 4456
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4457
      kr_loop:
742 Rus 4458
	in	al,0x64
4459
	test	al,1
4460
	jnz	kr_ready
4461
	loop	kr_loop
4462
	mov	ah,1
4463
	jmp	kr_exit
1 ha 4464
      kr_ready:
742 Rus 4465
	push	ecx
4466
	mov	ecx,32
1 ha 4467
      kr_delay:
742 Rus 4468
	loop	kr_delay
4469
	pop	ecx
4470
	in	al,0x60
4471
	xor	ah,ah
1 ha 4472
      kr_exit:
4473
 
742 Rus 4474
	pop	edx ecx
1 ha 4475
 
742 Rus 4476
	ret
1 ha 4477
 
4478
 
4479
kb_write:
4480
 
742 Rus 4481
	push	ecx edx
1 ha 4482
 
742 Rus 4483
	mov	dl,al
265 diamond 4484
;        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4485
;      kw_loop1:
4486
;        in      al,0x64
4487
;        test    al,0x20
4488
;        jz      kw_ok1
4489
;        loop    kw_loop1
4490
;        mov     ah,1
4491
;        jmp     kw_exit
4492
;      kw_ok1:
742 Rus 4493
	in	al,0x60
4494
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4495
      kw_loop:
742 Rus 4496
	in	al,0x64
4497
	test	al,2
4498
	jz	kw_ok
4499
	loop	kw_loop
4500
	mov	ah,1
4501
	jmp	kw_exit
1 ha 4502
      kw_ok:
742 Rus 4503
	mov	al,dl
4504
	out	0x60,al
4505
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4506
      kw_loop3:
742 Rus 4507
	in	al,0x64
4508
	test	al,2
4509
	jz	kw_ok3
4510
	loop	kw_loop3
4511
	mov	ah,1
4512
	jmp	kw_exit
1 ha 4513
      kw_ok3:
742 Rus 4514
	mov	ah,8
1 ha 4515
      kw_loop4:
742 Rus 4516
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4517
      kw_loop5:
742 Rus 4518
	in	al,0x64
4519
	test	al,1
4520
	jnz	kw_ok4
4521
	loop	kw_loop5
4522
	dec	ah
4523
	jnz	kw_loop4
1 ha 4524
      kw_ok4:
742 Rus 4525
	xor	ah,ah
1 ha 4526
      kw_exit:
4527
 
742 Rus 4528
	pop	edx ecx
1 ha 4529
 
742 Rus 4530
	ret
1 ha 4531
 
4532
 
4533
kb_cmd:
4534
 
742 Rus 4535
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4536
      c_wait:
742 Rus 4537
	in	al,0x64
4538
	test	al,2
4539
	jz	c_send
4540
	loop	c_wait
4541
	jmp	c_error
1 ha 4542
      c_send:
742 Rus 4543
	mov	al,bl
4544
	out	0x64,al
4545
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4546
      c_accept:
742 Rus 4547
	in	al,0x64
4548
	test	al,2
4549
	jz	c_ok
4550
	loop	c_accept
1 ha 4551
      c_error:
742 Rus 4552
	mov	ah,1
4553
	jmp	c_exit
1 ha 4554
      c_ok:
742 Rus 4555
	xor	ah,ah
1 ha 4556
      c_exit:
742 Rus 4557
	ret
1 ha 4558
 
4559
 
4560
setmouse:  ; set mousepicture -pointer
742 Rus 4561
	   ; ps2 mouse enable
1 ha 4562
 
381 serge 4563
     mov     [MOUSE_PICTURE],dword mousepointer
1 ha 4564
 
4565
     cli
4566
 
4567
     ret
4568
 
4569
 
4570
_rdtsc:
164 serge 4571
     bt [cpu_caps], CAPS_TSC
4572
     jnc ret_rdtsc
1 ha 4573
     rdtsc
4574
     ret
4575
   ret_rdtsc:
4576
     mov   edx,0xffffffff
4577
     mov   eax,0xffffffff
4578
     ret
4579
 
4580
rerouteirqs:
4581
 
742 Rus 4582
	cli
1 ha 4583
 
742 Rus 4584
	mov	al,0x11 	;  icw4, edge triggered
4585
	out	0x20,al
4586
	call	pic_delay
4587
	out	0xA0,al
4588
	call	pic_delay
1 ha 4589
 
742 Rus 4590
	mov	al,0x20 	;  generate 0x20 +
4591
	out	0x21,al
4592
	call	pic_delay
4593
	mov	al,0x28 	;  generate 0x28 +
4594
	out	0xA1,al
4595
	call	pic_delay
1 ha 4596
 
742 Rus 4597
	mov	al,0x04 	;  slave at irq2
4598
	out	0x21,al
4599
	call	pic_delay
4600
	mov	al,0x02 	;  at irq9
4601
	out	0xA1,al
4602
	call	pic_delay
1 ha 4603
 
742 Rus 4604
	mov	al,0x01 	;  8086 mode
4605
	out	0x21,al
4606
	call	pic_delay
4607
	out	0xA1,al
4608
	call	pic_delay
1 ha 4609
 
742 Rus 4610
	mov	al,255		; mask all irq's
4611
	out	0xA1,al
4612
	call	pic_delay
4613
	out	0x21,al
4614
	call	pic_delay
1 ha 4615
 
742 Rus 4616
	mov	ecx,0x1000
4617
	cld
4618
picl1:	call	pic_delay
4619
	loop	picl1
1 ha 4620
 
742 Rus 4621
	mov	al,255		; mask all irq's
4622
	out	0xA1,al
4623
	call	pic_delay
4624
	out	0x21,al
4625
	call	pic_delay
1 ha 4626
 
742 Rus 4627
	cli
1 ha 4628
 
742 Rus 4629
	ret
1 ha 4630
 
4631
 
4632
pic_delay:
4633
 
742 Rus 4634
	jmp	pdl1
4635
pdl1:	ret
1 ha 4636
 
4637
 
4638
sys_msg_board_str:
4639
 
4640
     pushad
4641
   @@:
4642
     cmp    [esi],byte 0
4643
     je     @f
4644
     mov    eax,1
4645
     movzx  ebx,byte [esi]
4646
     call   sys_msg_board
4647
     inc    esi
4648
     jmp    @b
4649
   @@:
4650
     popad
4651
     ret
4652
 
709 diamond 4653
sys_msg_board_byte:
4654
; in: al = byte to display
4655
; out: nothing
4656
; destroys: nothing
742 Rus 4657
	pushad
4658
	mov	ecx, 2
4659
	shl	eax, 24
4660
	jmp	@f
709 diamond 4661
 
4662
sys_msg_board_word:
4663
; in: ax = word to display
4664
; out: nothing
4665
; destroys: nothing
742 Rus 4666
	pushad
4667
	mov	ecx, 4
4668
	shl	eax, 16
4669
	jmp	@f
709 diamond 4670
 
4671
sys_msg_board_dword:
4672
; in: eax = dword to display
4673
; out: nothing
4674
; destroys: nothing
742 Rus 4675
	pushad
4676
	mov	ecx, 8
709 diamond 4677
@@:
742 Rus 4678
	push	ecx
4679
	rol	eax, 4
4680
	push	eax
4681
	and	al, 0xF
4682
	cmp	al, 10
4683
	sbb	al, 69h
4684
	das
4685
	mov	bl, al
4686
	xor	eax, eax
4687
	inc	eax
4688
	call	sys_msg_board
4689
	pop	eax
4690
	pop	ecx
4691
	loop	@b
4692
	popad
4693
	ret
709 diamond 4694
 
1 ha 4695
uglobal
373 mikedld 4696
  msg_board_data: times 4096 db 0
1 ha 4697
  msg_board_count dd 0x0
4698
endg
4699
 
4700
sys_msg_board:
4701
 
4702
; eax=1 : write :  bl byte to write
4703
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4704
 
671 Ghost 4705
	mov	ecx, [msg_board_count]
4706
	cmp	eax, 1
4707
	jne	.smbl1
1 ha 4708
 
4709
 
671 Ghost 4710
	mov	[msg_board_data+ecx],bl
4711
	inc	ecx
4712
	and	ecx, 4095
4713
	mov	[msg_board_count], ecx
4714
	mov	[check_idle_semaphore], 5
4715
	ret
4716
.smbl1:
4717
	cmp	eax, 2
4718
	jne	.smbl2
4719
	test	ecx, ecx
4720
	jz	.smbl21
4721
	mov	eax, msg_board_data+1
4722
	mov	ebx, msg_board_data
4723
	movzx	edx, byte [ebx]
4724
	call	memmove
4725
	dec	[msg_board_count]
4726
	mov	[esp + 36], edx ;eax
4727
	mov	[esp + 24], dword 1
4728
	ret
4729
.smbl21:
4730
	mov	[esp+36], ecx
4731
	mov	[esp+24], ecx
4732
.smbl2:
4733
	ret
1 ha 4734
 
4735
 
4736
 
4737
sys_process_def:
742 Rus 4738
	mov	edi, [CURRENT_TASK]
1 ha 4739
 
742 Rus 4740
	dec	eax		; 1 = set keyboard mode
1 ha 4741
     jne   no_set_keyboard_setup
4742
 
4743
     shl   edi,8
380 serge 4744
     mov   [edi+SLOT_BASE + APPDATA.keyboard_mode],bl
1 ha 4745
 
4746
     ret
4747
 
4748
   no_set_keyboard_setup:
4749
 
742 Rus 4750
	dec	eax		; 2 = get keyboard mode
1 ha 4751
     jne   no_get_keyboard_setup
4752
 
4753
     shl   edi,8
380 serge 4754
     movzx eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
1 ha 4755
 
4756
     mov   [esp+36],eax
4757
 
4758
     ret
4759
 
4760
   no_get_keyboard_setup:
4761
 
742 Rus 4762
	dec	eax		; 3 = get keyboard ctrl, alt, shift
1 ha 4763
     jne   no_get_keyboard_cas
4764
 
4765
;     xor   eax,eax
4766
;     movzx eax,byte [shift]
4767
;     movzx ebx,byte [ctrl]
4768
;     shl   ebx,2
4769
;     add   eax,ebx
4770
;     movzx ebx,byte [alt]
4771
;     shl   ebx,3
4772
;     add   eax,ebx
4773
 
4774
 ;// mike.dld [
4775
     mov   eax, [kb_state]
4776
 ;// mike.dld ]
4777
 
4778
     mov   [esp+36],eax
4779
 
4780
     ret
4781
 
4782
   no_get_keyboard_cas:
4783
 
742 Rus 4784
	dec	eax
4785
	jnz	no_add_keyboard_hotkey
1 ha 4786
 
742 Rus 4787
	mov	eax, hotkey_list
92 diamond 4788
@@:
742 Rus 4789
	cmp	dword [eax+8], 0
4790
	jz	.found_free
4791
	add	eax, 16
4792
	cmp	eax, hotkey_list+16*256
4793
	jb	@b
4794
	mov	dword [esp+36], 1
4795
	ret
92 diamond 4796
.found_free:
742 Rus 4797
	mov	[eax+8], edi
4798
	mov	[eax+4], ecx
4799
	movzx	ebx, bl
4800
	lea	ebx, [hotkey_scancodes+ebx*4]
4801
	mov	ecx, [ebx]
4802
	mov	[eax], ecx
4803
	mov	[ebx], eax
4804
	mov	[eax+12], ebx
4805
	jecxz	@f
4806
	mov	[ecx+12], eax
92 diamond 4807
@@:
742 Rus 4808
	and	dword [esp+36], 0
4809
	ret
92 diamond 4810
 
4811
no_add_keyboard_hotkey:
4812
 
742 Rus 4813
	dec	eax
4814
	jnz	no_del_keyboard_hotkey
92 diamond 4815
 
742 Rus 4816
	movzx	ebx, bl
4817
	lea	ebx, [hotkey_scancodes+ebx*4]
4818
	mov	eax, [ebx]
92 diamond 4819
.scan:
742 Rus 4820
	test	eax, eax
4821
	jz	.notfound
4822
	cmp	[eax+8], edi
4823
	jnz	.next
4824
	cmp	[eax+4], ecx
4825
	jz	.found
92 diamond 4826
.next:
742 Rus 4827
	mov	eax, [eax]
4828
	jmp	.scan
92 diamond 4829
.notfound:
742 Rus 4830
	mov	dword [esp+36], 1
4831
	ret
92 diamond 4832
.found:
742 Rus 4833
	mov	ecx, [eax]
4834
	jecxz	@f
4835
	mov	edx, [eax+12]
4836
	mov	[ecx+12], edx
92 diamond 4837
@@:
742 Rus 4838
	mov	ecx, [eax+12]
4839
	mov	edx, [eax]
4840
	mov	[ecx], edx
4841
	xor	edx, edx
4842
	mov	[eax+4], edx
4843
	mov	[eax+8], edx
4844
	mov	[eax+12], edx
4845
	mov	[eax], edx
4846
	mov	[esp+36], edx
4847
	ret
92 diamond 4848
 
4849
no_del_keyboard_hotkey:
1 ha 4850
     ret
4851
 
4852
 
4853
align 4
4854
 
742 Rus 4855
sys_gs: 			; direct screen access
1 ha 4856
 
742 Rus 4857
     cmp  eax,1 		; resolution
1 ha 4858
     jne  no_gs1
753 serge 4859
     mov  eax,[Screen_Max_X]
1 ha 4860
     shl  eax,16
753 serge 4861
     mov  ax,[Screen_Max_Y]
1 ha 4862
     add  eax,0x00010001
4863
     mov  [esp+36],eax
4864
     ret
4865
   no_gs1:
4866
 
742 Rus 4867
     cmp   eax,2		; bits per pixel
1 ha 4868
     jne   no_gs2
381 serge 4869
     movzx eax,byte [ScreenBPP]
1 ha 4870
     mov   [esp+36],eax
4871
     ret
4872
   no_gs2:
4873
 
742 Rus 4874
     cmp   eax,3		; bytes per scanline
1 ha 4875
     jne   no_gs3
381 serge 4876
     mov   eax,[BytesPerScanLine]
1 ha 4877
     mov   [esp+36],eax
4878
     ret
4879
   no_gs3:
4880
 
4881
     mov  [esp+36],dword -1
4882
     ret
4883
 
4884
 
4885
align 4 ; PCI functions
4886
 
4887
sys_pci:
4888
 
4889
     call  pci_api
4890
     mov   [esp+36],eax
4891
     ret
4892
 
4893
 
4894
align 4  ;  system functions
4895
 
742 Rus 4896
syscall_setpixel:			; SetPixel
1 ha 4897
 
742 Rus 4898
	mov	eax, ebx
4899
	mov	ebx, ecx
4900
	mov	ecx, edx
4901
	mov	edx, [TASK_BASE]
4902
	add	eax, [edx-twdw+WDATA.box.left]
4903
	add	ebx, [edx-twdw+WDATA.box.top]
4904
	mov	edi, [current_slot]
4905
	add	eax, [edi+APPDATA.wnd_clientbox.left]
4906
	add	ebx, [edi+APPDATA.wnd_clientbox.top]
4907
	xor	edi, edi ; no force
684 diamond 4908
;       mov     edi, 1
742 Rus 4909
	call	[disable_mouse]
4910
	jmp	[putpixel]
1 ha 4911
 
4912
align 4
4913
 
742 Rus 4914
syscall_writetext:			; WriteText
1 ha 4915
 
742 Rus 4916
	mov   eax,[TASK_BASE]
4917
	mov   ebp,[eax-twdw+WDATA.box.left]
4918
	push  esi
4919
	mov   esi,[current_slot]
4920
	add   ebp,[esi+APPDATA.wnd_clientbox.left]
4921
	shl   ebp,16
4922
	add   ebp,[eax-twdw+WDATA.box.top]
4923
	add   bp,word[esi+APPDATA.wnd_clientbox.top]
4924
	pop   esi
4925
	add   ebx,ebp
4926
	mov   eax,edi
4927
	xor   edi,edi
4928
	jmp   dtext
1 ha 4929
 
4930
align 4
4931
 
742 Rus 4932
syscall_openramdiskfile:		; OpenRamdiskFile
1 ha 4933
 
742 Rus 4934
	mov	eax, ebx
4935
	mov	ebx, ecx
4936
	mov	ecx, edx
4937
	mov	edx, esi
4938
	mov	esi, 12
4939
	call	fileread
4940
	mov	[esp+32], eax
4941
	ret
1 ha 4942
 
4943
align 4
4944
 
742 Rus 4945
syscall_drawrect:			; DrawRect
1 ha 4946
 
671 Ghost 4947
	mov	edi, edx ; color + gradient
4948
	and	edi, 0x80FFFFFF
4949
	test	bx, bx	; x.size
4950
	je	.drectr
4951
	test	cx, cx ; y.size
4952
	je	.drectr
1 ha 4953
 
671 Ghost 4954
	mov	eax, ebx ; bad idea
4955
	mov	ebx, ecx
1 ha 4956
 
671 Ghost 4957
	movzx	ecx, ax ; ecx - x.size
4958
	shr	eax, 16 ; eax - x.coord
4959
	movzx	edx, bx ; edx - y.size
4960
	shr	ebx, 16 ; ebx - y.coord
4961
	mov	esi, [current_slot]
1 ha 4962
 
671 Ghost 4963
	add	eax, [esi + APPDATA.wnd_clientbox.left]
4964
	add	ebx, [esi + APPDATA.wnd_clientbox.top]
4965
	add	ecx, eax
4966
	add	edx, ebx
4967
	jmp	[drawbar]
4968
.drectr:
4969
	ret
1 ha 4970
 
4971
align 4
742 Rus 4972
syscall_getscreensize:			; GetScreenSize
759 Rus 4973
	mov	ax, [Screen_Max_X]
671 Ghost 4974
	shl	eax, 16
759 Rus 4975
	mov	ax, [Screen_Max_Y]
671 Ghost 4976
	mov	[esp + 32], eax
4977
	ret
1 ha 4978
 
671 Ghost 4979
align 4
4980
 
742 Rus 4981
syscall_cdaudio:			; CD
1 ha 4982
 
742 Rus 4983
	cmp	eax, 4
4984
	jb	.audio
4985
	jz	.eject
4986
	cmp	eax, 5
4987
	jnz	.ret
588 diamond 4988
.load:
742 Rus 4989
	call	.reserve
4990
	call	LoadMedium
4991
	call	.free
4992
	ret
588 diamond 4993
.eject:
742 Rus 4994
	call	.reserve
4995
	call	clear_CD_cache
4996
	call	allow_medium_removal
4997
	call	EjectMedium
4998
	call	.free
4999
	ret
588 diamond 5000
.audio:
1 ha 5001
     call  sys_cd_audio
5002
     mov   [esp+36],eax
588 diamond 5003
.ret:
1 ha 5004
     ret
5005
 
588 diamond 5006
.reserve:
742 Rus 5007
	call	reserve_cd
5008
	mov	eax, ebx
5009
	shr	eax, 1
5010
	and	eax, 1
5011
	inc	eax
5012
	mov	[ChannelNumber], ax
5013
	mov	eax, ebx
5014
	and	eax, 1
5015
	mov	[DiskNumber], al
5016
	call	reserve_cd_channel
5017
	and	ebx, 3
5018
	inc	ebx
5019
	mov	[cdpos], ebx
5020
	add	ebx, ebx
5021
	mov	cl, 8
5022
	sub	cl, bl
5023
	mov	al, [DRIVE_DATA+1]
5024
	shr	al, cl
5025
	test	al, 2
5026
	jz	.err
5027
	ret
588 diamond 5028
.free:
742 Rus 5029
	call	free_cd_channel
5030
	and	[cd_status], 0
5031
	ret
590 diamond 5032
.err:
742 Rus 5033
	call	.free
5034
	pop	eax
5035
	ret
588 diamond 5036
 
1 ha 5037
align 4
5038
 
742 Rus 5039
syscall_getpixel:			; GetPixel
753 serge 5040
     mov   ecx, [Screen_Max_X]
1 ha 5041
     inc   ecx
671 Ghost 5042
     xor   edx, edx
5043
     mov   eax, ebx
1 ha 5044
     div   ecx
671 Ghost 5045
     mov   ebx, edx
5046
     xchg  eax, ebx
5047
     call  dword [GETPIXEL] ; eax - x, ebx - y
5048
     mov   [esp + 32], ecx
1 ha 5049
     ret
5050
 
5051
 
5052
align 4
5053
 
742 Rus 5054
syscall_drawline:			; DrawLine
1 ha 5055
 
671 Ghost 5056
	mov	edi, [TASK_BASE]
752 Lrz 5057
	movzx	eax, word[edi-twdw+WDATA.box.left]
5058
	mov	ebp, eax
671 Ghost 5059
	mov	esi, [current_slot]
5060
	add	ebp, [esi+APPDATA.wnd_clientbox.left]
752 Lrz 5061
	add	ax, word[esi+APPDATA.wnd_clientbox.left]
5062
	add	ebp,ebx
5063
	shl	eax, 16
5064
	movzx	ebx, word[edi-twdw+WDATA.box.top]
671 Ghost 5065
	add	eax, ebp
752 Lrz 5066
	mov	ebp, ebx
671 Ghost 5067
	add	ebp, [esi+APPDATA.wnd_clientbox.top]
752 Lrz 5068
	add	bx, word[esi+APPDATA.wnd_clientbox.top]
759 Rus 5069
	add	ebp, ecx
752 Lrz 5070
	shl	ebx, 16
671 Ghost 5071
	xor	edi, edi
752 Lrz 5072
	add	ebx, ebp
5073
	mov	ecx, edx
671 Ghost 5074
	jmp	[draw_line]
1 ha 5075
 
5076
align 4
5077
 
742 Rus 5078
syscall_getirqowner:			; GetIrqOwner
5079
 
5080
     cmp   ebx,16
75 diamond 5081
     jae   .err
742 Rus 5082
 
774 Rus 5083
     cmp   [irq_rights + 4 * ebx], dword 2
5084
     je    .err
5085
 
742 Rus 5086
     mov   eax,[4 * ebx + irq_owner]
5087
     mov   [esp+32],eax
5088
 
1 ha 5089
     ret
75 diamond 5090
.err:
742 Rus 5091
     or    dword [esp+32], -1
75 diamond 5092
     ret
1 ha 5093
 
5094
align 4
5095
 
742 Rus 5096
syscall_reserveportarea:		; ReservePortArea and FreePortArea
1 ha 5097
 
5098
     call  r_f_port_area
5099
     mov   [esp+36],eax
5100
     ret
5101
 
5102
align 4
5103
 
742 Rus 5104
syscall_threads:			; CreateThreads
1 ha 5105
 
5106
     call  sys_threads
5107
     mov   [esp+36],eax
5108
     ret
5109
 
5110
align 4
5111
 
5112
stack_driver_stat:
5113
 
742 Rus 5114
     call  app_stack_handler		; Stack status
1 ha 5115
 
5116
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5117
;     call  change_task                 ; between sent packet
5118
 
5119
     mov   [esp+36],eax
5120
     ret
5121
 
5122
align 4
5123
 
742 Rus 5124
socket: 				; Socket interface
1 ha 5125
     call  app_socket_handler
5126
 
5127
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5128
;     call  change_task                 ; between sent packet
5129
 
5130
     mov   [esp+36],eax
5131
     mov   [esp+24],ebx
5132
     ret
5133
 
5134
align 4
5135
 
742 Rus 5136
read_from_hd:				; Read from hd - fn not in use
1 ha 5137
 
379 serge 5138
     mov   edi,[TASK_BASE]
115 poddubny 5139
     add   edi,TASKDATA.mem_start
1 ha 5140
     add   eax,[edi]
5141
     add   ecx,[edi]
5142
     add   edx,[edi]
5143
     call  file_read
5144
 
5145
     mov   [esp+36],eax
5146
     mov   [esp+24],ebx
5147
 
5148
     ret
5149
 
375 Ghost 5150
paleholder:
742 Rus 5151
	ret
378 serge 5152
 
757 serge 5153
align 4
5154
set_screen:
759 Rus 5155
	cmp eax, [Screen_Max_X]
5156
	jne .set
709 diamond 5157
 
759 Rus 5158
	cmp edx, [Screen_Max_Y]
5159
	jne .set
5160
	ret
757 serge 5161
.set:
759 Rus 5162
	pushfd
5163
	cli
757 serge 5164
 
759 Rus 5165
	mov [Screen_Max_X], eax
5166
	mov [Screen_Max_Y], edx
757 serge 5167
 
759 Rus 5168
	mov [screen_workarea.right],eax
5169
	mov [screen_workarea.bottom], edx
5170
	inc eax
5171
	shl eax, 2			;32 bpp
5172
	mov [BytesPerScanLine], eax
5173
	push ebx
5174
	push esi
5175
	push edi
5176
	call	repos_windows
5177
	mov	eax, 0
5178
	mov	ebx, 0
5179
	mov	ecx, [Screen_Max_X]
5180
	mov	edx, [Screen_Max_Y]
5181
	call	calculatescreen
5182
	pop edi
5183
	pop esi
5184
	pop ebx
757 serge 5185
 
759 Rus 5186
	popfd
5187
	ret
757 serge 5188
 
76 mario79 5189
; --------------- APM ---------------------
5190
apm_entry    dp    0
742 Rus 5191
apm_vf	      dd    0
1 ha 5192
align 4
76 mario79 5193
sys_apm:
5194
    cmp    word [apm_vf], 0    ; Check APM BIOS enable
5195
    jne    @f
742 Rus 5196
    or	  [esp + 56], byte 1	; error
5197
    mov    [esp + 36], dword 8	  ; 32-bit protected-mode interface not supported
76 mario79 5198
    ret
164 serge 5199
 
465 serge 5200
@@:
5201
    xchg    eax, ecx
76 mario79 5202
    xchg    ebx, ecx
164 serge 5203
 
76 mario79 5204
    cmp    al, 3
742 Rus 5205
    ja	  @f
78 diamond 5206
    and    [esp + 56], byte 0xfe    ; emulate func 0..3 as func 0
76 mario79 5207
    mov    eax, [apm_vf]
5208
    mov    [esp + 36], eax
5209
    shr    eax, 16
5210
    mov    [esp + 32], eax
5211
    ret
78 diamond 5212
 
465 serge 5213
@@:
5214
 
5215
    mov esi, [master_tab+(OS_BASE shr 20)]
5216
    xchg [master_tab], esi
5217
    push esi
5218
    mov edi, cr3
742 Rus 5219
    mov cr3, edi		 ;flush TLB
465 serge 5220
 
742 Rus 5221
    call    pword [apm_entry]	 ; call APM BIOS
465 serge 5222
 
5223
    xchg eax, [esp]
5224
    mov [master_tab], eax
5225
    mov eax, cr3
5226
    mov cr3, eax
5227
    pop eax
5228
 
76 mario79 5229
    mov    [esp + 8 ], edi
5230
    mov    [esp + 12], esi
5231
    mov    [esp + 24], ebx
5232
    mov    [esp + 28], edx
5233
    mov    [esp + 32], ecx
5234
    mov    [esp + 36], eax
5235
    setc    al
78 diamond 5236
    and    [esp + 56], byte 0xfe
742 Rus 5237
    or	  [esp + 56], al
465 serge 5238
 
5239
 
76 mario79 5240
    ret
5241
; -----------------------------------------
1 ha 5242
 
76 mario79 5243
align 4
5244
 
742 Rus 5245
undefined_syscall:			; Undefined system call
671 Ghost 5246
     mov   [esp + 32], dword -1
1 ha 5247
     ret
5248
 
465 serge 5249
align 4
742 Rus 5250
system_shutdown:	  ; shut down the system
1 ha 5251
 
742 Rus 5252
	   cmp byte [BOOT_VAR+0x9030], 1
5253
	   jne @F
5254
	   ret
465 serge 5255
@@:
742 Rus 5256
	   call stop_all_services
5257
	   push 3		 ; stop playing cd
5258
	   pop	eax
5259
	   call sys_cd_audio
1 ha 5260
 
465 serge 5261
yes_shutdown_param:
742 Rus 5262
	   cli
1 ha 5263
 
742 Rus 5264
	   mov	eax, kernel_file ; load kernel.mnt to 0x7000:0
5265
	   push 12
5266
	   pop	esi
5267
	   xor	ebx,ebx
5268
	   or	ecx,-1
5269
	   mov	edx, OS_BASE+0x70000
5270
	   call fileread
1 ha 5271
 
847 serge 5272
   ;        mov  esi, restart_kernel_4000+OS_BASE+0x10000 ; move kernel re-starter to 0x4000:0
5273
   ;        mov  edi,OS_BASE+0x40000
5274
   ;        mov  ecx,1000
5275
   ;        rep  movsb
1 ha 5276
 
847 serge 5277
           mov  esi,OS_BASE+0x2F0000    ; restore 0x0 - 0xffff
5278
           mov  edi, OS_BASE
5279
           mov  ecx,0x10000/4
5280
           cld
5281
           rep movsd
1 ha 5282
 
742 Rus 5283
	   call restorefatchain
1 ha 5284
 
742 Rus 5285
	   mov al, 0xFF
5286
	   out 0x21, al
5287
	   out 0xA1, al
1 ha 5288
 
709 diamond 5289
if 1
847 serge 5290
       ;    mov  word [OS_BASE+0x467+0],pr_mode_exit
5291
       ;    mov  word [OS_BASE+0x467+2],0x1000
1 ha 5292
 
742 Rus 5293
	   mov	al,0x0F
5294
	   out	0x70,al
5295
	   mov	al,0x05
5296
	   out	0x71,al
1 ha 5297
 
742 Rus 5298
	   mov	al,0xFE
5299
	   out	0x64,al
709 diamond 5300
 
742 Rus 5301
	   hlt
1 ha 5302
 
709 diamond 5303
else
742 Rus 5304
	cmp	byte [OS_BASE + 0x9030], 2
5305
	jnz	no_acpi_power_off
1 ha 5306
 
709 diamond 5307
; scan for RSDP
5308
; 1) The first 1 Kb of the Extended BIOS Data Area (EBDA).
742 Rus 5309
	movzx	eax, word [OS_BASE + 0x40E]
5310
	shl	eax, 4
5311
	jz	@f
5312
	mov	ecx, 1024/16
5313
	call	scan_rsdp
5314
	jnc	.rsdp_found
709 diamond 5315
@@:
5316
; 2) The BIOS read-only memory space between 0E0000h and 0FFFFFh.
742 Rus 5317
	mov	eax, 0xE0000
5318
	mov	ecx, 0x2000
5319
	call	scan_rsdp
5320
	jc	no_acpi_power_off
709 diamond 5321
.rsdp_found:
742 Rus 5322
	mov	esi, [eax+16]	; esi contains physical address of the RSDT
5323
	mov	ebp, [ipc_tmp]
5324
	stdcall map_page, ebp, esi, PG_MAP
5325
	lea	eax, [esi+1000h]
5326
	lea	edx, [ebp+1000h]
5327
	stdcall map_page, edx, eax, PG_MAP
5328
	and	esi, 0xFFF
5329
	add	esi, ebp
5330
	cmp	dword [esi], 'RSDT'
5331
	jnz	no_acpi_power_off
5332
	mov	ecx, [esi+4]
5333
	sub	ecx, 24h
5334
	jbe	no_acpi_power_off
5335
	shr	ecx, 2
5336
	add	esi, 24h
709 diamond 5337
.scan_fadt:
742 Rus 5338
	lodsd
5339
	mov	ebx, eax
5340
	lea	eax, [ebp+2000h]
5341
	stdcall map_page, eax, ebx, PG_MAP
5342
	lea	eax, [ebp+3000h]
5343
	add	ebx, 0x1000
5344
	stdcall map_page, eax, ebx, PG_MAP
5345
	and	ebx, 0xFFF
5346
	lea	ebx, [ebx+ebp+2000h]
5347
	cmp	dword [ebx], 'FACP'
5348
	jz	.fadt_found
5349
	loop	.scan_fadt
5350
	jmp	no_acpi_power_off
709 diamond 5351
.fadt_found:
5352
; ebx is linear address of FADT
742 Rus 5353
	mov	edx, [ebx+48]
5354
	test	edx, edx
5355
	jz	.nosmi
5356
	mov	al, [ebx+52]
5357
	out	dx, al
5358
	mov	edx, [ebx+64]
709 diamond 5359
@@:
742 Rus 5360
	in	ax, dx
5361
	test	al, 1
5362
	jz	@b
709 diamond 5363
.nosmi:
742 Rus 5364
	mov	edx, [ebx+64]
5365
	in	ax, dx
5366
	and	ax, 203h
5367
	or	ax, 3C00h
5368
	out	dx, ax
5369
	mov	edx, [ebx+68]
5370
	test	edx, edx
5371
	jz	@f
5372
	in	ax, dx
5373
	and	ax, 203h
5374
	or	ax, 3C00h
5375
	out	dx, ax
709 diamond 5376
@@:
742 Rus 5377
	jmp	$
709 diamond 5378
 
5379
 
5380
no_acpi_power_off:
742 Rus 5381
	   mov	word [OS_BASE+0x467+0],pr_mode_exit
5382
	   mov	word [OS_BASE+0x467+2],0x1000
709 diamond 5383
 
742 Rus 5384
	   mov	al,0x0F
5385
	   out	0x70,al
5386
	   mov	al,0x05
5387
	   out	0x71,al
709 diamond 5388
 
742 Rus 5389
	   mov	al,0xFE
5390
	   out	0x64,al
709 diamond 5391
 
742 Rus 5392
	   hlt
709 diamond 5393
 
5394
scan_rsdp:
742 Rus 5395
	add	eax, OS_BASE
709 diamond 5396
.s:
742 Rus 5397
	cmp	dword [eax], 'RSD '
5398
	jnz	.n
5399
	cmp	dword [eax+4], 'PTR '
5400
	jnz	.n
5401
	xor	edx, edx
5402
	xor	esi, esi
709 diamond 5403
@@:
742 Rus 5404
	add	dl, [eax+esi]
5405
	inc	esi
5406
	cmp	esi, 20
5407
	jnz	@b
5408
	test	dl, dl
5409
	jz	.ok
709 diamond 5410
.n:
742 Rus 5411
	add	eax, 10h
5412
	loop	.s
5413
	stc
709 diamond 5414
.ok:
742 Rus 5415
	ret
709 diamond 5416
end if
5417
 
465 serge 5418
include "data32.inc"
1 ha 5419
 
465 serge 5420
__REV__ = __REV
1 ha 5421
 
5422
uglobals_size = $ - endofcode
41 mikedld 5423
diff16 "end of kernel code",0,$
426 mikedld 5424
 
847 serge 5425
align 16
5426
 
5427
__end:
5428