Subversion Repositories Kolibri OS

Rev

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

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