Subversion Repositories Kolibri OS

Rev

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