Subversion Repositories Kolibri OS

Rev

Rev 860 | Rev 862 | 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
    mov ebx, [mem_BACKGROUND]
861 serge 2324
    add ebx, 4095
2325
    and ebx, -4096
2326
    sub ebx, 4
2327
    cmp   ecx, ebx
2328
    ja   @F
2329
2330
 
469 serge 2331
    mov   ebx,[eax+ecx]
684 diamond 2332
    and   ebx,0xFF000000 ;255*256*256*256
2333
    and   edx,0x00FFFFFF ;255*256*256+255*256+255
2334
    add   edx,ebx
2335
    mov   [eax+ecx],edx
2336
@@:
861 serge 2337
    ret
1 ha 2338
2339
 
861 serge 2340
2341
 
742 Rus 2342
    jnz   nosb3
1 ha 2343
draw_background_temp:
2344
;    cmp   [bgrchanged],1 ;0
2345
;    je    nosb31
2346
;draw_background_temp:
2347
;    mov   [bgrchanged],1 ;0
2348
    mov    [background_defined], 1
76 mario79 2349
    call  force_redraw_background
709 diamond 2350
    mov    [REDRAW_BACKGROUND], byte 2
2351
   nosb31:
1 ha 2352
    ret
2353
  nosb3:
2354
2355
 
742 Rus 2356
    jnz   nosb4
1 ha 2357
    cmp   ecx,[BgrDrawMode]
684 diamond 2358
    je	  nosb41
742 Rus 2359
    mov   [BgrDrawMode],ecx
684 diamond 2360
;    mov   [bgrchanged],1
1 ha 2361
   nosb41:
2362
    ret
2363
  nosb4:
2364
2365
 
742 Rus 2366
    jnz   nosb5
1 ha 2367
  ; bughere
2368
    mov   eax, ecx
684 diamond 2369
    mov   ebx, edx
2370
    add   ebx, [img_background]   ;IMG_BACKGROUND
469 serge 2371
    mov   ecx, esi
684 diamond 2372
    call  memmove
1 ha 2373
  .fin:
2374
    ret
2375
  nosb5:
2376
479 kastigar 2377
 
742 Rus 2378
	jnz	nosb6
2379
@@:
546 diamond 2380
	mov	al, 1
742 Rus 2381
	xchg	[bgrlock], al
2382
	test	al, al
2383
	jz	@f
2384
	call	change_task
2385
	jmp	@b
2386
@@:
546 diamond 2387
	mov	eax, [CURRENT_TASK]
742 Rus 2388
	mov	[bgrlockpid], eax
2389
	stdcall user_alloc, [mem_BACKGROUND]
2390
	mov	[esp+32], eax
2391
	test	eax, eax
2392
	jz	.nomem
2393
	mov	ebx, eax
2394
	shr	ebx, 12
2395
	or	dword [page_tabs+(ebx-1)*4], DONT_FREE_BLOCK
2396
	mov	esi, [img_background]
2397
	shr	esi, 12
2398
	mov	ecx, [mem_BACKGROUND]
2399
	add	ecx, 0xFFF
2400
	shr	ecx, 12
2401
.z:
546 diamond 2402
	mov	eax, [page_tabs+ebx*4]
742 Rus 2403
	test	al, 1
2404
	jz	@f
2405
	call	free_page
2406
@@:
546 diamond 2407
	mov	eax, [page_tabs+esi*4]
742 Rus 2408
	or	al, PG_UW
2409
	mov	[page_tabs+ebx*4], eax
2410
	mov	eax, ebx
2411
	shl	eax, 12
2412
	invlpg	[eax]
2413
	inc	ebx
2414
	inc	esi
2415
	loop	.z
2416
	ret
2417
.nomem:
546 diamond 2418
	and	[bgrlockpid], 0
742 Rus 2419
	mov	[bgrlock], 0
2420
nosb6:
546 diamond 2421
	cmp	ebx, 7
742 Rus 2422
	jnz	nosb7
2423
	cmp	[bgrlock], 0
2424
	jz	.err
2425
	mov	eax, [CURRENT_TASK]
2426
	cmp	[bgrlockpid], eax
2427
	jnz	.err
2428
	mov	eax, ecx
2429
	mov	ebx, ecx
2430
	shr	eax, 12
2431
	mov	ecx, [page_tabs+(eax-1)*4]
2432
	test	cl, USED_BLOCK+DONT_FREE_BLOCK
2433
	jz	.err
2434
	jnp	.err
2435
	push	eax
2436
	shr	ecx, 12
2437
@@:
546 diamond 2438
	and	dword [page_tabs+eax*4], 0
742 Rus 2439
	mov	edx, eax
2440
	shl	edx, 12
2441
        push eax
802 serge 2442
	invlpg	[edx]
742 Rus 2443
        pop eax
802 serge 2444
	inc	eax
742 Rus 2445
	loop	@b
2446
	pop	eax
2447
	and	dword [page_tabs+(eax-1)*4], not DONT_FREE_BLOCK
2448
	stdcall user_free, ebx
2449
	mov	[esp+32], eax
2450
	and	[bgrlockpid], 0
2451
	mov	[bgrlock], 0
2452
	ret
2453
.err:
546 diamond 2454
	and	dword [esp+32], 0
742 Rus 2455
	ret
2456
546 diamond 2457
 
2458
    ret
1 ha 2459
2460
 
709 diamond 2461
    mov   [draw_data+32 + RECT.left],dword 0
2462
    mov   [draw_data+32 + RECT.top],dword 0
2463
    push  eax ebx
2464
    mov   eax,[Screen_Max_X]
753 serge 2465
    mov   ebx,[Screen_Max_Y]
2466
    mov   [draw_data+32 + RECT.right],eax
709 diamond 2467
    mov   [draw_data+32 + RECT.bottom],ebx
2468
    pop   ebx eax
2469
    mov   byte [REDRAW_BACKGROUND], 1
2470
    ret
2471
479 kastigar 2472
 
1 ha 2473
2474
 
2475
2476
 
742 Rus 2477
    jnz   nogb1
1 ha 2478
    mov   eax,[BgrDataWidth]
527 diamond 2479
    shl   eax,16
1 ha 2480
    mov   ax,[BgrDataHeight]
531 diamond 2481
    mov   [esp+36],eax
1 ha 2482
    ret
2483
2484
 
861 serge 2485
2486
 
742 Rus 2487
    jnz   nogb2
1 ha 2488
    mov ecx, [mem_BACKGROUND]
861 serge 2489
    add ecx, 4095
2490
    and ecx, -4096
2491
    sub ecx, 4
2492
    cmp ebx, ecx
2493
    ja  @F
2494
2495
 
469 serge 2496
    mov   eax,[ebx+eax]
2497
2498
 
1 ha 2499
    mov   [esp+36],eax
2500
@@:
861 serge 2501
    ret
1 ha 2502
  nogb2:
2503
2504
 
742 Rus 2505
    jnz   nogb4
1 ha 2506
    mov   eax,[BgrDrawMode]
527 diamond 2507
  nogb4:
1 ha 2508
    mov   [esp+36],eax
2509
    ret
2510
2511
 
2512
 
2513
2514
 
2515
	mov	[esp + 32],dword 1
671 Ghost 2516
	; test main buffer
2517
	mov	ebx, [CURRENT_TASK]			     ; TOP OF WINDOW STACK
742 Rus 2518
	movzx	ecx, word [WIN_STACK + ebx * 2]
671 Ghost 2519
	mov	edx, [TASK_COUNT]
2520
	cmp	ecx, edx
2521
	jne	.finish
2522
	cmp	[KEY_COUNT], byte 0
2523
	je	.finish
2524
	movzx	eax, byte [KEY_BUFF]
2525
	shl	eax, 8
2526
	push	eax
2527
	dec	byte [KEY_COUNT]
2528
	and	byte [KEY_COUNT], 127
2529
	movzx	ecx, byte [KEY_COUNT]
2530
	add	ecx, 2
2531
	mov	eax, KEY_BUFF + 1
2532
	mov	ebx, KEY_BUFF
2533
	call	memmove
2534
	pop	eax
2535
.ret_eax:
92 diamond 2536
	mov	[esp + 32], eax
671 Ghost 2537
	ret
2538
.finish:
2539
; test hotkeys buffer
92 diamond 2540
	mov	ecx, hotkey_buffer
671 Ghost 2541
@@:
92 diamond 2542
	cmp	[ecx], ebx
671 Ghost 2543
	jz	.found
2544
	add	ecx, 8
2545
	cmp	ecx, hotkey_buffer + 120 * 8
2546
	jb	@b
2547
	ret
2548
.found:
92 diamond 2549
	mov	ax, [ecx + 6]
671 Ghost 2550
	shl	eax, 16
2551
	mov	ah, [ecx + 4]
2552
	mov	al, 2
2553
	and	dword [ecx + 4], 0
2554
	and	dword [ecx], 0
2555
	jmp	.ret_eax
2556
1 ha 2557
 
2558
2559
 
2560
2561
 
742 Rus 2562
	mov	[esp + 32], dword 1
671 Ghost 2563
	movzx	ecx, word [WIN_STACK + ebx * 2]
2564
	mov	edx, [TASK_COUNT] ; less than 256 processes
2565
	cmp	ecx, edx
2566
	jne	.exit
2567
	movzx	eax, byte [BTN_COUNT]
2568
	test	eax, eax
2569
	jz	.exit
2570
	mov	eax, [BTN_BUFF]
2571
	shl	eax, 8
2572
; // Alver 22.06.2008 // {
803 alver 2573
        mov       al, byte [btn_down_determ]
2574
        and       al,0xFE                                       ; delete left button bit
2575
; } \\ Alver \\
2576
	mov	[BTN_COUNT], byte 0
671 Ghost 2577
	mov	[esp + 32], eax
2578
.exit:
2579
	ret
2580
1 ha 2581
 
2582
 
2583
2584
 
2585
2586
 
2587
;
2588
;  +00 dword     process cpu usage
2589
;  +04  word     position in windowing stack
2590
;  +06  word     windowing stack value at current position (cpu nro)
2591
;  +10 12 bytes  name
2592
;  +22 dword     start in mem
2593
;  +26 dword     used mem
2594
;  +30 dword     PID , process idenfification number
2595
;
2596
2597
 
742 Rus 2598
    jne  .no_who_am_i
684 diamond 2599
    mov  ecx,[CURRENT_TASK]
2600
  .no_who_am_i:
2601
	cmp	ecx, max_processes
742 Rus 2602
	ja	.nofillbuf
2603
1 ha 2604
 
684 diamond 2605
	mov	ax, [WIN_STACK + ecx * 2]
742 Rus 2606
	mov	[ebx+4], ax
2607
; +6: word: number of the thread slot, which window has in the window stack
684 diamond 2608
;           position ecx (has no relation to the specific thread)
2609
	mov	ax, [WIN_POS + ecx * 2]
742 Rus 2610
	mov	[ebx+6], ax
2611
1 ha 2612
 
742 Rus 2613
1 ha 2614
 
684 diamond 2615
	mov	eax, [ecx+CURRENT_TASK+TASKDATA.cpu_usage]
742 Rus 2616
	mov	[ebx], eax
2617
; +10: 11 bytes: name of the process
684 diamond 2618
	push	ecx
742 Rus 2619
	lea	eax, [ecx*8+SLOT_BASE+APPDATA.app_name]
2620
	add	ebx, 10
2621
	mov	ecx, 11
2622
	call	memmove
2623
	pop	ecx
2624
1 ha 2625
 
684 diamond 2626
; +26: size of used memory - 1
2627
	push	edi
742 Rus 2628
	lea	edi, [ebx+12]
2629
	xor	eax, eax
2630
	mov	edx, 0x100000*16
2631
	cmp	ecx, 1 shl 5
2632
	je	.os_mem
2633
	mov	edx, [SLOT_BASE+ecx*8+APPDATA.mem_size]
2634
        xor eax, eax
840 serge 2635
.os_mem:
684 diamond 2636
	stosd
742 Rus 2637
	lea	eax, [edx-1]
2638
	stosd
2639
1 ha 2640
 
684 diamond 2641
	mov	eax, [ecx+CURRENT_TASK+TASKDATA.pid]
742 Rus 2642
	stosd
2643
1 ha 2644
 
2645
	push	esi
742 Rus 2646
	lea	esi, [ecx + window_data + WDATA.box]
2647
	movsd
2648
	movsd
2649
	movsd
2650
	movsd
2651
1 ha 2652
 
2653
	mov	eax, dword [ecx+CURRENT_TASK+TASKDATA.state]
742 Rus 2654
	stosd
2655
1 ha 2656
 
138 mikedld 2657
	lea	esi, [ecx*8 + SLOT_BASE + APPDATA.wnd_clientbox]
742 Rus 2658
	movsd
2659
	movsd
2660
	movsd
2661
	movsd
2662
1 ha 2663
 
164 serge 2664
	mov	al, [ecx+window_data+WDATA.fl_wstate]
742 Rus 2665
	stosb
2666
164 serge 2667
 
742 Rus 2668
	pop	edi
2669
138 mikedld 2670
 
684 diamond 2671
    ; return number of processes
1 ha 2672
2673
 
379 serge 2674
    mov    [esp+32],eax
684 diamond 2675
    ret
1 ha 2676
2677
 
2678
sys_clock:
2679
	cli
742 Rus 2680
  ; Mikhail Lisovin  xx Jan 2005
1 ha 2681
  @@:	mov   al, 10
742 Rus 2682
	out   0x70, al
2683
	in    al, 0x71
2684
	test  al, al
2685
	jns   @f
2686
	mov   esi, 1
2687
	call  delay_ms
2688
	jmp   @b
2689
  @@:
1 ha 2690
  ; end Lisovin's fix
2691
2692
 
742 Rus 2693
	out   0x70,al
2694
	in    al,0x71
2695
	movzx ecx,al
2696
	mov   al,02	      ; minutes
2697
	shl   ecx,16
2698
	out   0x70,al
2699
	in    al,0x71
2700
	movzx edx,al
2701
	mov   al,04	      ; hours
2702
	shl   edx,8
2703
	out   0x70,al
2704
	in    al,0x71
2705
	add   ecx,edx
2706
	movzx edx,al
2707
	add   ecx,edx
2708
	sti
2709
	mov	[esp + 32], ecx
671 Ghost 2710
	ret
742 Rus 2711
1 ha 2712
 
2713
 
2714
2715
 
2716
2717
 
742 Rus 2718
  @@:	mov   al, 10
2719
	out   0x70, al
2720
	in    al, 0x71
2721
	test  al, al
2722
	jns   @f
2723
	mov   esi, 1
2724
	call  delay_ms
2725
	jmp   @b
2726
  @@:
75 diamond 2727
2728
 
742 Rus 2729
	mov	al,7		; date
2730
	out	0x70,al
2731
	in	al,0x71
2732
	mov	cl,al
2733
	mov	al,8		; month
2734
	shl	ecx,16
2735
	out	0x70,al
2736
	in	al,0x71
2737
	mov	ch,al
2738
	mov	al,9		; year
2739
	out	0x70,al
2740
	in	al,0x71
2741
	mov	cl,al
2742
	sti
2743
	mov	[esp+32], ecx
2744
	ret
2745
1 ha 2746
 
2747
 
2748
2749
 
2750
	cmp	ebx, 1
671 Ghost 2751
	jne	no_widgets_away
2752
	; buttons away
2753
	mov	ecx,[CURRENT_TASK]
2754
  sys_newba2:
1 ha 2755
	mov	edi,[BTN_ADDR]
671 Ghost 2756
	cmp	[edi], dword 0	; empty button list ?
742 Rus 2757
	je	end_of_buttons_away
671 Ghost 2758
	movzx	ebx, word [edi]
2759
	inc	ebx
2760
	mov	eax,edi
2761
  sys_newba:
1 ha 2762
	dec	ebx
671 Ghost 2763
	jz	end_of_buttons_away
2764
1 ha 2765
 
671 Ghost 2766
	cmp	cx, [eax]
2767
	jnz	sys_newba
2768
1 ha 2769
 
671 Ghost 2770
	mov	ecx,ebx
2771
	inc	ecx
2772
	shl	ecx, 4
2773
	mov	ebx, eax
2774
	add	eax, 0x10
2775
	call	memmove
2776
	dec	dword [edi]
2777
	pop	ecx ebx eax
2778
1 ha 2779
 
671 Ghost 2780
1 ha 2781
 
2782
2783
 
671 Ghost 2784
1 ha 2785
 
2786
2787
 
671 Ghost 2788
	jnz	srl1
2789
1 ha 2790
 
671 Ghost 2791
	add	edx, draw_data - CURRENT_TASK
2792
	mov	[edx + RECT.left], 0
2793
	mov	[edx + RECT.top], 0
2794
	mov	eax, [Screen_Max_X]
759 Rus 2795
	mov	[edx + RECT.right], eax
671 Ghost 2796
	mov	eax, [Screen_Max_Y]
759 Rus 2797
	mov	[edx + RECT.bottom], eax
671 Ghost 2798
1 ha 2799
 
671 Ghost 2800
	or	[edi - twdw + WDATA.fl_wdrawn], 1   ; no new position & buttons from app
2801
	call	sys_window_mouse
2802
	ret
2803
1 ha 2804
 
2805
	ret
671 Ghost 2806
1 ha 2807
 
2808
 
2809
2810
 
684 diamond 2811
    shr   eax,16+8
2812
    and   eax,15
2813
1 ha 2814
 
684 diamond 2815
    jne   nosyswI
1 ha 2816
    inc   [mouse_pause]
33 mario79 2817
    call  [disable_mouse]
36 mario79 2818
    call  sys_set_window
1 ha 2819
    call  [disable_mouse]
36 mario79 2820
    call  drawwindow_I
1 ha 2821
    ;dec   [mouse_pause]
114 mikedld 2822
    ;call   [draw_pointer]
2823
    ;ret
2824
    jmp   draw_window_caption.2
2825
  nosyswI:
1 ha 2826
2827
 
742 Rus 2828
    jne   nosyswII
1 ha 2829
    inc   [mouse_pause]
33 mario79 2830
    call  [disable_mouse]
36 mario79 2831
    call  sys_set_window
1 ha 2832
    call  [disable_mouse]
36 mario79 2833
    call  sys_window_mouse
1 ha 2834
    dec   [mouse_pause]
33 mario79 2835
    call   [draw_pointer]
36 mario79 2836
    ret
1 ha 2837
  nosyswII:
2838
2839
 
742 Rus 2840
    jne   nosyswIII
1 ha 2841
    inc   [mouse_pause]
33 mario79 2842
    call  [disable_mouse]
36 mario79 2843
    call  sys_set_window
1 ha 2844
    call  [disable_mouse]
36 mario79 2845
    call  drawwindow_III
1 ha 2846
    ;dec   [mouse_pause]
114 mikedld 2847
    ;call   [draw_pointer]
2848
    ;ret
2849
    jmp   draw_window_caption.2
2850
  nosyswIII:
1 ha 2851
2852
 
742 Rus 2853
    je	  draw_skin_window
2854
    cmp   al,4	  ; type V - skinned window not sized! {not_sized_skin_window}
2855
    jne   nosyswV
549 spraid 2856
  draw_skin_window:
2857
567 serge 2858
 
569 diamond 2859
    call  [disable_mouse]
2860
    call  sys_set_window
2861
    call  [disable_mouse]
2862
    mov   eax, [TASK_COUNT]
684 diamond 2863
    movzx eax, word [WIN_POS + eax*2]
2864
    cmp   eax, [CURRENT_TASK]
2865
    setz  al
2866
    movzx eax, al
2867
    push  eax
2868
    call  drawwindow_IV
36 mario79 2869
    ;dec   [mouse_pause]
114 mikedld 2870
    ;call   [draw_pointer]
2871
    ;ret
2872
    jmp   draw_window_caption.2
2873
  nosyswV:
549 spraid 2874
1 ha 2875
 
2876
2877
 
2878
 
114 mikedld 2879
	inc	[mouse_pause]
742 Rus 2880
	call	[disable_mouse]
2881
114 mikedld 2882
 
742 Rus 2883
	mov	edx,[TASK_COUNT]
2884
	movzx	edx,word[WIN_POS+edx*2]
2885
	cmp	edx,[CURRENT_TASK]
2886
	jne	@f
2887
	inc	eax
2888
    @@: mov	edx,[CURRENT_TASK]
2889
	shl	edx,5
2890
	add	edx,window_data
2891
	movzx	ebx,[edx+WDATA.fl_wstyle]
2892
	and	bl,0x0F
2893
	cmp	bl,3
2894
	je	.draw_caption_style_3		;{for 3 and 4 style write caption}
2895
	cmp	bl,4
2896
	je	.draw_caption_style_3
2897
567 serge 2898
 
742 Rus 2899
  .draw_caption_style_3:
549 spraid 2900
114 mikedld 2901
 
742 Rus 2902
	call	drawwindow_IV_caption
2903
	add	esp,4
2904
	jmp	.2
2905
114 mikedld 2906
 
2907
	cmp	bl,2
742 Rus 2908
	jne	.not_style_2
2909
114 mikedld 2910
 
742 Rus 2911
	jmp	.2
2912
114 mikedld 2913
 
2914
	cmp	bl,0
742 Rus 2915
	jne	.2
2916
114 mikedld 2917
 
742 Rus 2918
114 mikedld 2919
 
2920
  .2:	;jmp     @f
742 Rus 2921
	mov	edi,[CURRENT_TASK]
2922
	shl	edi,5
2923
	test	[edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
2924
	jz	@f
2925
	mov	edx,[edi*8+SLOT_BASE+APPDATA.wnd_caption]
2926
	or	edx,edx
2927
	jz	@f
2928
114 mikedld 2929
 
742 Rus 2930
	and	al,0x0F
2931
	cmp	al,3
2932
	je	.skinned
2933
	cmp	al,4
2934
	je	.skinned
2935
567 serge 2936
 
742 Rus 2937
  .skinned:
567 serge 2938
	mov	ebp,[edi+window_data+WDATA.box.left-2]
742 Rus 2939
	mov	bp,word[edi+window_data+WDATA.box.top]
2940
	movzx	eax,word[edi+window_data+WDATA.box.width]
2941
	sub	ax,[_skinmargins.left]
2942
	sub	ax,[_skinmargins.right]
2943
	push	edx
2944
	cwde
2945
	cdq
2946
	mov	ebx,6
2947
	idiv	ebx
2948
	pop	edx
2949
	or	eax,eax
2950
	js	@f
2951
	mov	esi,eax
2952
	mov	ebx,dword[_skinmargins.left-2]
2953
	mov	bx,word[_skinh]
2954
	sub	bx,[_skinmargins.bottom]
2955
	sub	bx,[_skinmargins.top]
2956
	sar	bx,1
2957
	adc	bx,0
2958
	add	bx,[_skinmargins.top]
2959
	add	bx,-3
2960
	add	ebx,ebp
2961
	jmp	.dodraw
2962
114 mikedld 2963
 
2964
	cmp	al,1
742 Rus 2965
	je	@f
2966
114 mikedld 2967
 
742 Rus 2968
	mov	bp,word[edi+window_data+WDATA.box.top]
2969
	movzx	eax,word[edi+window_data+WDATA.box.width]
2970
	sub	eax,16
2971
	push	edx
2972
	cwde
2973
	cdq
2974
	mov	ebx,6
2975
	idiv	ebx
2976
	pop	edx
2977
	or	eax,eax
2978
	js	@f
2979
	mov	esi,eax
2980
	mov	ebx,0x00080007
2981
	add	ebx,ebp
2982
.dodraw:
139 diamond 2983
	mov	ecx,[common_colours+16];0x00FFFFFF
742 Rus 2984
	or	ecx, 0x80000000
2985
	xor	edi,edi
2986
; // Alver 22.06.2008 // {
803 alver 2987
;	call	dtext
2988
        call dtext_asciiz_esi
2989
; } \\ Alver \\
2990
114 mikedld 2991
 
2992
;--------------------------------------------------------------
2993
	dec	[mouse_pause]
742 Rus 2994
	call	[draw_pointer]
2995
	ret
2996
114 mikedld 2997
 
2998
align 4
2999
window_topleft dd \
3000
  1, 21,\		;type 0
549 spraid 3001
  0,  0,\	;type 1
742 Rus 3002
  5, 20,\	;type 2
3003
  5,  ?,\	;type 3 {set by skin}
3004
  5,  ? 	;type 4 {set by skin}
3005
endg
114 mikedld 3006
3007
 
3008
	push	eax ecx edi
742 Rus 3009
114 mikedld 3010
 
742 Rus 3011
	mov	[window_topleft+4*7],eax
3012
	mov	[window_topleft+4*9],eax
3013
114 mikedld 3014
 
742 Rus 3015
	sub	edi,window_data
3016
	shl	edi,3
3017
	test	[ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE
3018
	jz	@f
3019
114 mikedld 3020
 
742 Rus 3021
	and	eax,0x0F
3022
	mov	eax,[eax*8+window_topleft+0]
3023
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3024
	shl	eax,1
3025
	neg	eax
3026
	add	eax,[ecx+WDATA.box.width]
3027
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
3028
114 mikedld 3029
 
742 Rus 3030
	and	eax,0x0F
3031
	push	[eax*8+window_topleft+0]
3032
	mov	eax,[eax*8+window_topleft+4]
3033
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3034
	neg	eax
3035
	sub	eax,[esp]
3036
	add	eax,[ecx+WDATA.box.height]
3037
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3038
	add	esp,4
3039
114 mikedld 3040
 
742 Rus 3041
	ret
3042
    @@:
114 mikedld 3043
	xor	eax,eax
742 Rus 3044
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3045
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3046
	mov	eax,[ecx+WDATA.box.width]
3047
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
3048
	mov	eax,[ecx+WDATA.box.height]
3049
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3050
114 mikedld 3051
 
742 Rus 3052
	ret
3053
114 mikedld 3054
 
1 ha 3055
3056
 
684 diamond 3057
    shl   eax,5
3058
    add   eax,window_data
3059
1 ha 3060
 
3061
    mov   [eax+WDATA.cl_workarea],edx
684 diamond 3062
    mov   [eax+WDATA.cl_titlebar],esi
3063
    mov   [eax+WDATA.cl_frames],edi
3064
1 ha 3065
 
684 diamond 3066
3067
 
1 ha 3068
    test  [edi+WDATA.fl_wdrawn],1
186 diamond 3069
    jnz   newd
3070
1 ha 3071
 
3072
    add   eax,100
3073
    mov   [new_window_starting],eax
3074
3075
 
860 serge 3076
    mov   [edi+WDATA.box.width],eax
3077
    movsx eax,cx
3078
    mov   [edi+WDATA.box.height],eax
3079
    sar   ebx,16
114 mikedld 3080
    sar   ecx,16
684 diamond 3081
    mov   [edi+WDATA.box.left],ebx
860 serge 3082
    mov   [edi+WDATA.box.top],ecx
3083
1 ha 3084
 
3085
3086
 
164 serge 3087
1 ha 3088
 
742 Rus 3089
    ;mov   esi,edi
114 mikedld 3090
3091
 
742 Rus 3092
	mov	eax, [edi+WDATA.cl_frames]
3093
114 mikedld 3094
 
1 ha 3095
    shl   edi,3
114 mikedld 3096
    add   edi,SLOT_BASE
380 serge 3097
114 mikedld 3098
 
742 Rus 3099
	mov	[edi+APPDATA.wnd_caption],0
3100
	cmp	cl,3
3101
	je	set_APPDATA_wnd_caption
3102
	cmp	cl,4								; {SPraid.simba}
3103
	je	set_APPDATA_wnd_caption
3104
567 serge 3105
 
742 Rus 3106
    set_APPDATA_wnd_caption:
549 spraid 3107
	mov	[edi+APPDATA.wnd_caption],eax
742 Rus 3108
    @@: mov	esi,[esp+0]
3109
114 mikedld 3110
 
115 poddubny 3111
	movsd
742 Rus 3112
	movsd
3113
	movsd
3114
	movsd
3115
    pop   edi esi ecx
1 ha 3116
3117
 
742 Rus 3118
	movzx	esi, word [WIN_STACK+esi*2]
3119
	lea	esi, [WIN_POS+esi*2]
3120
	call	waredraw
3121
569 diamond 3122
 
684 diamond 3123
;;;    call  delay_hs
1 ha 3124
    mov   eax, [edi+WDATA.box.left]
115 poddubny 3125
    mov   ebx, [edi+WDATA.box.top]
3126
    mov   ecx, [edi+WDATA.box.width]
3127
    mov   edx, [edi+WDATA.box.height]
3128
    add   ecx, eax
1 ha 3129
    add   edx, ebx
3130
    call  calculatescreen
3131
3132
 
742 Rus 3133
    mov   [BTN_COUNT],byte 0	       ; empty button buffer
3134
1 ha 3135
 
3136
    mov   [edi+WDATA.fl_redraw],byte 0	 ; no redraw
742 Rus 3137
    mov   edx,edi
1 ha 3138
3139
 
3140
3141
 
114 mikedld 3142
1 ha 3143
 
114 mikedld 3144
	dec	eax	; subfunction #1 - set window caption
742 Rus 3145
	jnz	.get_window_caption
3146
114 mikedld 3147
 
742 Rus 3148
	;       so there's no parameter for PID/TID
3149
114 mikedld 3150
 
742 Rus 3151
	shl	edi,5
3152
114 mikedld 3153
 
742 Rus 3154
	; check is trivial, and if application resizes its memory,
3155
	;   caption still can become over bounds
3156
; diamond, 31.10.2006: check removed because with new memory manager
202 diamond 3157
; there can be valid data after APPDATA.mem_size bound
3158
;        mov     ecx,[edi*8+SLOT_BASE+APPDATA.mem_size]
380 serge 3159
;        add     ecx,255 ; max caption length
202 diamond 3160
;        cmp     ebx,ecx
3161
;        ja      .exit_fail
3162
114 mikedld 3163
 
742 Rus 3164
	or	[edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
3165
114 mikedld 3166
 
742 Rus 3167
114 mikedld 3168
 
742 Rus 3169
	ret
3170
114 mikedld 3171
 
3172
	dec	eax	; subfunction #2 - get window caption
742 Rus 3173
	jnz	.exit_fail
3174
114 mikedld 3175
 
742 Rus 3176
114 mikedld 3177
 
3178
	xor	eax,eax
742 Rus 3179
	inc	eax	; eax = 1 (fail)
3180
	ret
3181
114 mikedld 3182
 
3183
 
1 ha 3184
3185
 
742 Rus 3186
	shl	edi,5
3187
	add	edi,window_data
3188
1 ha 3189
 
742 Rus 3190
	jnz	.window_move_return
3191
1 ha 3192
 
742 Rus 3193
	push	dword [edi + WDATA.box.top]
3194
	push	dword [edi + WDATA.box.width]
3195
	push	dword [edi + WDATA.box.height]
3196
1 ha 3197
 
742 Rus 3198
	je    .no_x_reposition
3199
	mov	[edi + WDATA.box.left], eax
3200
      .no_x_reposition:
49 mikedld 3201
	cmp   ebx,-1
742 Rus 3202
	je    .no_y_reposition
3203
	mov	[edi + WDATA.box.top], ebx
3204
      .no_y_reposition:
49 mikedld 3205
1 ha 3206
 
742 Rus 3207
	jnz	.no_y_resizing
3208
1 ha 3209
 
742 Rus 3210
	je    .no_x_resizing
3211
	mov	[edi + WDATA.box.width], ecx
3212
      .no_x_resizing:
49 mikedld 3213
	cmp   edx,-1
742 Rus 3214
	je    .no_y_resizing
3215
	mov	[edi + WDATA.box.height], edx
3216
      .no_y_resizing:
49 mikedld 3217
1 ha 3218
 
742 Rus 3219
	call  set_window_clientbox
3220
1 ha 3221
 
742 Rus 3222
	mov   esi,edi
3223
	sub   edi,window_data
3224
	shr   edi,5
3225
	shl   edi,8
3226
	add   edi, SLOT_BASE + APPDATA.saved_box
3227
	mov   ecx,4
3228
	cld
3229
	rep   movsd
3230
	popad
3231
49 mikedld 3232
 
742 Rus 3233
	mov   eax, [edi + WDATA.box.left]
3234
	mov   ebx, [edi + WDATA.box.top]
3235
	mov   ecx, [edi + WDATA.box.width]
3236
	mov   edx, [edi + WDATA.box.height]
3237
	add   ecx,eax
3238
	add   edx,ebx
3239
221 serge 3240
 
742 Rus 3241
	popad
3242
49 mikedld 3243
 
742 Rus 3244
	pop   ecx
3245
	pop   ebx
3246
	pop   eax
3247
	add   ecx,eax
3248
	add   edx,ebx
3249
	mov   [dlx],eax 	    ; save for drawlimits
3250
	mov   [dly],ebx
3251
	mov   [dlxe],ecx
3252
	mov   [dlye],edx
3253
	call  calculatescreen
3254
49 mikedld 3255
 
742 Rus 3256
49 mikedld 3257
 
742 Rus 3258
	xor   esi,esi
3259
	call  redrawscreen
3260
49 mikedld 3261
 
742 Rus 3262
	mov   [MOUSE_BACKGROUND],byte 0 ; no mouse under
3263
	mov   [MOUSE_DOWN],byte 0 ; react to mouse up/down
3264
49 mikedld 3265
 
742 Rus 3266
49 mikedld 3267
 
742 Rus 3268
49 mikedld 3269
 
3270
3271
 
742 Rus 3272
1 ha 3273
 
3274
  window_move_pr   dd  0x0
3275
  window_move_eax  dd  0x0
3276
  window_move_ebx  dd  0x0
3277
  window_move_ecx  dd  0x0
3278
  window_move_edx  dd  0x0
3279
endg
3280
3281
 
3282
;nt - not tested
3283
;---------------------------------------------------------------------------------------------
3284
;eax
3285
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3286
;1 - change task. Ret nothing. Block. ok.
3287
;2 - performance control
3288
; ebx
3289
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3290
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3291
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3292
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3293
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3294
;eax
3295
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3296
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3297
;---------------------------------------------------------------------------------------------
3298
sys_sheduler: ;noname & halyavin
3299
    cmp eax,0
3300
    je shed_counter
3301
    cmp eax,2
3302
    je perf_control
3303
    cmp eax,3
3304
    je rdmsr_instr
3305
    cmp eax,4
3306
    je wrmsr_instr
3307
    cmp eax,1
3308
    jne not_supported
3309
    call change_task ;delay,0
3310
ret
3311
shed_counter:
3312
    mov eax,[context_counter]
3313
    mov [esp+36],eax
3314
not_supported:
3315
ret
3316
perf_control:
3317
    inc eax ;now eax=3
3318
    cmp ebx,eax
3319
    je cache_disable
3320
    dec eax
3321
    cmp ebx,eax
3322
    je cache_enable
3323
    dec eax
3324
    cmp ebx,eax
3325
    je is_cache_enabled
3326
    dec eax
3327
    cmp ebx,eax
3328
    je modify_pce
3329
ret
3330
3331
 
3332
;now counter in ecx
3333
;(edx:eax) esi:edi => edx:esi
3334
mov eax,esi
3335
rdmsr
3336
mov [esp+36],eax
3337
mov [esp+24],edx ;ret in ebx?
3338
ret
3339
3340
 
3341
;now counter in ecx
3342
;(edx:eax) esi:edi => edx:esi
3343
	; Fast Call MSR can't be destroy
482 Ghost 3344
	; Íî MSR_AMD_EFER ìîæíî èçìåíÿòü, ò.ê. â ýòîì ðåãèñòðå ëèø
3345
	; âêëþ÷àþòñÿ/âûêëþ÷àþòñÿ ðàñøèðåííûå âîçìîæíîñòè
3346
	cmp	ecx, MSR_SYSENTER_CS
3347
	je	@f
3348
	cmp	ecx, MSR_SYSENTER_ESP
3349
	je	@f
3350
	cmp	ecx, MSR_SYSENTER_EIP
3351
	je	@f
3352
	cmp	ecx, MSR_AMD_STAR
3353
	je	@f
3354
3355
 
3356
	wrmsr
3357
	; mov   [esp + 36], eax
742 Rus 3358
	; mov   [esp + 24], edx ;ret in ebx?
3359
@@:
482 Ghost 3360
ret
1 ha 3361
3362
 
3363
       mov eax,cr0
3364
       or  eax,01100000000000000000000000000000b
3365
       mov cr0,eax
3366
       wbinvd ;set MESI
3367
ret
3368
3369
 
3370
       mov eax,cr0
3371
       and eax,10011111111111111111111111111111b
3372
       mov cr0,eax
3373
ret
3374
3375
 
3376
       mov eax,cr0
3377
       mov ebx,eax
3378
       and eax,01100000000000000000000000000000b
3379
       jz cache_disabled
3380
       mov [esp+36],ebx
3381
cache_disabled:
3382
       mov dword [esp+36],eax ;0
3383
ret
3384
3385
 
3386
       mov eax,cr4
3387
;       mov ebx,0
3388
;       or  bx,100000000b ;pce
3389
;       xor eax,ebx ;invert pce
3390
       bts eax,8 ;pce=cr4[8]
17 me_root 3391
       mov cr4,eax
1 ha 3392
       mov [esp+36],eax
3393
ret
3394
;---------------------------------------------------------------------------------------------
3395
3396
 
3397
 
3398
3399
 
3400
	push eax edx
742 Rus 3401
1 ha 3402
 
759 Rus 3403
        mov  ecx, [_display_data]
840 serge 3404
3405
 
3406
	imul edx, ebx
742 Rus 3407
1 ha 3408
 
840 serge 3409
        mov  dl, [eax+edx] ; lea eax, [...]
3410
3411
 
742 Rus 3412
	mov  eax, [CURRENT_TASK]
3413
	cmp  al, dl
3414
	setne cl
3415
1 ha 3416
 
742 Rus 3417
	ret
3418
1 ha 3419
 
3420
  cpustring db 'CPU',0
521 diamond 3421
endg
1 ha 3422
3423
 
67 diamond 3424
background_defined    db    0	 ; diamond, 11.04.2006
742 Rus 3425
endg
67 diamond 3426
1 ha 3427
 
3428
; check misc
3429
3430
 
3431
3432
 
3433
    jne   nocpustart
3434
501 serge 3435
 
742 Rus 3436
	call	fs_execute_from_sysdir
3437
501 serge 3438
 
1 ha 3439
465 serge 3440
 
3441
    cmp   [mouse_active], 1
1 ha 3442
    jne   mouse_not_active
3443
    mov   [mouse_active], 0
3444
    xor   edi, edi
3445
    mov   ecx,	[TASK_COUNT]
742 Rus 3446
set_mouse_event:
465 serge 3447
    add   edi, 256
1 ha 3448
    or	  [edi+SLOT_BASE+APPDATA.event_mask], dword 100000b
742 Rus 3449
    loop  set_mouse_event
1 ha 3450
3451
 
465 serge 3452
    cmp   [REDRAW_BACKGROUND],byte 0		   ; background update ?
742 Rus 3453
    jz	  nobackgr
3454
    cmp    [background_defined], 0
76 mario79 3455
    jz	  nobackgr
742 Rus 3456
    cmp   [REDRAW_BACKGROUND], byte 2
709 diamond 3457
    jnz   no_set_bgr_event
3458
    xor   edi, edi
473 diamond 3459
    mov   ecx,	[TASK_COUNT]
742 Rus 3460
set_bgr_event:
473 diamond 3461
    add   edi, 256
3462
    or	  [edi+SLOT_BASE+APPDATA.event_mask], 16
742 Rus 3463
    loop  set_bgr_event
473 diamond 3464
no_set_bgr_event:
709 diamond 3465
;    mov   [draw_data+32 + RECT.left],dword 0
3466
;    mov   [draw_data+32 + RECT.top],dword 0
3467
;    mov   eax,[Screen_Max_X]
753 serge 3468
;    mov   ebx,[Screen_Max_Y]
3469
;    mov   [draw_data+32 + RECT.right],eax
709 diamond 3470
;    mov   [draw_data+32 + RECT.bottom],ebx
3471
    call  drawbackground
1 ha 3472
    mov   [REDRAW_BACKGROUND],byte 0
381 serge 3473
    mov   [MOUSE_BACKGROUND],byte 0
3474
1 ha 3475
 
465 serge 3476
1 ha 3477
 
3478
3479
 
381 serge 3480
    je	 noshutdown
742 Rus 3481
1 ha 3482
 
3483
3484
 
381 serge 3485
    jne  no_mark_system_shutdown
1 ha 3486
3487
 
709 diamond 3488
    mov   edx,OS_BASE+0x3040
465 serge 3489
    jecxz @f
709 diamond 3490
markz:
465 serge 3491
    mov   [edx+TASKDATA.state],byte 3
115 poddubny 3492
    add   edx,0x20
1 ha 3493
    loop  markz
3494
@@:
709 diamond 3495
1 ha 3496
 
3497
3498
 
3499
3500
 
381 serge 3501
    je	 system_shutdown
742 Rus 3502
1 ha 3503
 
465 serge 3504
1 ha 3505
 
3506
 
742 Rus 3507
    mov   ebx,TASK_DATA+TASKDATA.state
379 serge 3508
    mov   esi,1
1 ha 3509
3510
 
465 serge 3511
    mov   cl,[ebx]
1 ha 3512
    cmp   cl,byte 3
3513
    jz	  terminate
742 Rus 3514
    cmp   cl,byte 4
1 ha 3515
    jz	  terminate
742 Rus 3516
1 ha 3517
 
3518
    inc   esi
3519
    dec   eax
3520
    jnz   newct
3521
    ret
3522
3523
 
3524
3525
 
3526
3527
 
3528
3529
 
742 Rus 3530
	 push  eax
3531
1 ha 3532
 
684 diamond 3533
;;;         call  delay_hs
1 ha 3534
3535
 
742 Rus 3536
	 xor   ecx,ecx
3537
       newdw2:
1 ha 3538
3539
 
742 Rus 3540
	 push  ecx
3541
1 ha 3542
 
742 Rus 3543
	 shl   eax,5
3544
	 add   eax,window_data
3545
1 ha 3546
 
742 Rus 3547
	 je    not_this_task
3548
				   ; check if window in redraw area
3549
	 mov   edi,eax
3550
1 ha 3551
 
742 Rus 3552
	 jz    bgli
3553
1 ha 3554
 
742 Rus 3555
	 mov   ebx, [edi + WDATA.box.top]
3556
	 mov   ecx, [edi + WDATA.box.width]
3557
	 mov   edx, [edi + WDATA.box.height]
3558
	 add   ecx,eax
3559
	 add   edx,ebx
3560
1 ha 3561
 
742 Rus 3562
	 cmp   ecx,ebx
3563
	 jb    ricino
3564
1 ha 3565
 
742 Rus 3566
	 cmp   ecx,eax
3567
	 jb    ricino
3568
1 ha 3569
 
742 Rus 3570
	 mov   ebx, [edi + WDATA.box.top]
3571
	 mov   ecx, [edi + WDATA.box.width]
3572
	 mov   edx, [edi + WDATA.box.height]
3573
	 add   ecx, eax
3574
	 add   edx, ebx
3575
164 serge 3576
 
742 Rus 3577
	 cmp   edx,eax
3578
	 jb    ricino
3579
1 ha 3580
 
742 Rus 3581
	 cmp   ecx,eax
3582
	 jb    ricino
3583
1 ha 3584
 
742 Rus 3585
1 ha 3586
 
742 Rus 3587
	 jnz   .az
3588
	 mov   al,[REDRAW_BACKGROUND]
3589
	 cmp   al,2
3590
	 jz    newdw8
3591
	 test  al,al
3592
	 jz    .az
3593
	 lea   eax,[edi+draw_data-window_data]
3594
	 mov   ebx,[dlx]
3595
	 cmp   ebx,[eax+RECT.left]
3596
	 jae   @f
3597
	 mov   [eax+RECT.left],ebx
3598
	@@:
3599
	 mov   ebx,[dly]
3600
	 cmp   ebx,[eax+RECT.top]
3601
	 jae   @f
3602
	 mov   [eax+RECT.top],ebx
3603
	@@:
3604
	 mov   ebx,[dlxe]
3605
	 cmp   ebx,[eax+RECT.right]
3606
	 jbe   @f
3607
	 mov   [eax+RECT.right],ebx
3608
	@@:
3609
	 mov   ebx,[dlye]
3610
	 cmp   ebx,[eax+RECT.bottom]
3611
	 jbe   @f
3612
	 mov   [eax+RECT.bottom],ebx
3613
	@@:
3614
	 jmp   newdw8
3615
	.az:
3616
1 ha 3617
 
742 Rus 3618
	 add   eax,draw_data-window_data
3619
1 ha 3620
 
742 Rus 3621
	 mov   [eax + RECT.left], ebx
3622
	 mov   ebx,[dly]
3623
	 mov   [eax + RECT.top], ebx
3624
	 mov   ebx,[dlxe]
3625
	 mov   [eax + RECT.right], ebx
3626
	 mov   ebx,[dlye]
3627
	 mov   [eax + RECT.bottom], ebx
3628
1 ha 3629
 
742 Rus 3630
1 ha 3631
 
742 Rus 3632
	 jne   nobgrd
3633
	 mov   byte [REDRAW_BACKGROUND], 1
3634
1 ha 3635
 
3636
       nobgrd:
3637
3638
 
742 Rus 3639
1 ha 3640
 
3641
3642
 
3643
3644
 
742 Rus 3645
1 ha 3646
 
742 Rus 3647
	 jle   newdw2
3648
1 ha 3649
 
742 Rus 3650
	 popad
3651
1 ha 3652
 
742 Rus 3653
1 ha 3654
 
3655
3656
 
742 Rus 3657
1 ha 3658
 
742 Rus 3659
	xor   eax, eax
3660
	mov   ecx, 1023    ;0x0fff00 / 4
3661
	cld
3662
	rep   stosd
3663
1 ha 3664
 
840 serge 3665
	mov   eax,0x01010101
742 Rus 3666
	mov   ecx,1280*1024 / 4
3667
	rep   stosd
3668
1 ha 3669
 
742 Rus 3670
1 ha 3671
 
742 Rus 3672
1 ha 3673
 
3674
  imax	  dd 0x0
742 Rus 3675
endg
1 ha 3676
3677
 
3678
 
3679
 
3680
3681
 
3682
 
742 Rus 3683
	push  ecx
3684
1 ha 3685
 
742 Rus 3686
	; 
3687
	imul  ecx, 33941
3688
	shr   ecx, 9
3689
	; 
3690
1 ha 3691
 
742 Rus 3692
	and   al,0x10
3693
	mov   ah,al
3694
	cld
3695
1 ha 3696
 
742 Rus 3697
	and   al,0x10
3698
	cmp   al,ah
3699
	jz    cnt1
3700
1 ha 3701
 
742 Rus 3702
	loop  cnt1
3703
1 ha 3704
 
742 Rus 3705
	pop   eax
3706
1 ha 3707
 
742 Rus 3708
1 ha 3709
 
3710
 
3711
	mov	edi, [TASK_BASE]
742 Rus 3712
	mov	[edi + TASKDATA.event_mask], ebx
3713
	ret
3714
1 ha 3715
 
3716
 
3717
 
3718
; ebx = delay time
684 diamond 3719
	push  ecx
742 Rus 3720
	push  edx
3721
1 ha 3722
 
742 Rus 3723
1 ha 3724
 
3725
	mov   ecx,[timer_ticks]
742 Rus 3726
	sub   ecx,edx
3727
	cmp   ecx,ebx
3728
	jae   zerodelay
3729
1 ha 3730
 
742 Rus 3731
1 ha 3732
 
742 Rus 3733
1 ha 3734
 
3735
	pop   edx
742 Rus 3736
	pop   ecx
3737
1 ha 3738
 
742 Rus 3739
1 ha 3740
 
3741
 
3742
3743
 
3744
; ebx = to
3745
; ecx = no of bytes
3746
    test ecx, ecx
3747
    jle  .ret
3748
3749
 
3750
 
3751
3752
 
3753
    mov  esi, eax
3754
3755
 
3756
    jz	 @f
742 Rus 3757
1 ha 3758
 
3759
    shr  ecx, 2
3760
    rep  movsd
3761
    pop  ecx
3762
    and  ecx, 11b
3763
    jz	 .finish
742 Rus 3764
  @@:
1 ha 3765
    rep  movsb
3766
3767
 
3768
    pop  ecx edi esi
3769
  .ret:
3770
    ret
3771
3772
 
3773
 
75 diamond 3774
;align 4
3775
;
1 ha 3776
;read_floppy_file:
75 diamond 3777
;
1 ha 3778
;; as input
75 diamond 3779
;;
3780
;; eax pointer to file
3781
;; ebx file lenght
3782
;; ecx start 512 byte block number
3783
;; edx number of blocks to read
3784
;; esi pointer to return/work area (atleast 20 000 bytes)
3785
;;
3786
;;
3787
;; on return
3788
;;
3789
;; eax = 0 command succesful
3790
;;       1 no fd base and/or partition defined
3791
;;       2 yet unsupported FS
3792
;;       3 unknown FS
3793
;;       4 partition not defined at hd
3794
;;       5 file not found
3795
;; ebx = size of file
3796
;
1 ha 3797
;     mov   edi,[TASK_BASE]
379 serge 3798
;     add   edi,0x10
75 diamond 3799
;     add   esi,[edi]
3800
;     add   eax,[edi]
3801
;
1 ha 3802
;     pushad
75 diamond 3803
;     mov  edi,esi
3804
;     add  edi,1024
3805
;     mov  esi,0x100000+19*512
3806
;     sub  ecx,1
3807
;     shl  ecx,9
3808
;     add  esi,ecx
3809
;     shl  edx,9
3810
;     mov  ecx,edx
3811
;     cld
3812
;     rep  movsb
3813
;     popad
3814
;
3815
;     mov   [esp+36],eax
3816
;     mov   [esp+24],ebx
3817
;     ret
3818
1 ha 3819
 
3820
 
3821
 
3822
3823
 
3824
3825
 
765 Rus 3826
    add   ebx, [eax + TASKDATA.mem_start]
3827
1 ha 3828
 
765 Rus 3829
    jae   .not_owner
75 diamond 3830
    mov   edi, [eax + TASKDATA.pid]
765 Rus 3831
    cmp   edi, [irq_owner + 4 * ecx]
3832
    je	  .spril1
3833
.not_owner:
75 diamond 3834
    xor   ecx, ecx
765 Rus 3835
    jmp   .end
3836
  .spril1:
3837
1 ha 3838
 
765 Rus 3839
    mov   esi, ebx
3840
    lea   edi, [irq00read + ecx]
3841
    push  16
3842
    pop   ecx
3843
3844
 
1 ha 3845
    rep   movsd
3846
  .end:
765 Rus 3847
    mov   [esp+32], ecx
3848
    ret
1 ha 3849
3850
 
3851
 
3852
3853
 
3854
     movzx esi, bh			 ; save number of subfunction, if bh = 1, return data size, otherwise, read data
760 Rus 3855
     xor   bh, bh
3856
     cmp   ebx, 16
3857
     jae   .not_owner
75 diamond 3858
     mov   edx, [4 * ebx + irq_owner]	 ; check for irq owner
760 Rus 3859
742 Rus 3860
 
760 Rus 3861
742 Rus 3862
 
760 Rus 3863
     je    gidril1
1 ha 3864
.not_owner:
75 diamond 3865
     xor   edx, edx
760 Rus 3866
     dec   edx
3867
     jmp   gid1
3868
1 ha 3869
 
3870
3871
 
760 Rus 3872
     lea   eax, [ebx + IRQ_SAVE]	 ; calculate address of the beginning of buffer + 0x0 - data size
3873
     mov   edx, [eax]			 ;                                              + 0x4 - data offset
3874
     dec   esi
3875
     jz    gid1
1 ha 3876
     test  edx, edx			 ; check if buffer is empty
760 Rus 3877
     jz    gid1
3878
1 ha 3879
 
760 Rus 3880
     mov   edi, ecx
3881
742 Rus 3882
 
760 Rus 3883
742 Rus 3884
 
760 Rus 3885
     jb    @f
759 Rus 3886
742 Rus 3887
 
760 Rus 3888
759 Rus 3889
 
3890
3891
 
760 Rus 3892
     cld
3893
     cmp   esi, ecx			 ; if greater than the buffer size, begin cycle again
3894
     jbe   @f
3895
759 Rus 3896
 
760 Rus 3897
     sub   edx, ecx
3898
759 Rus 3899
 
760 Rus 3900
     rep   movsb
3901
3902
 
3903
   @@:
3904
     lea   esi, [eax + ebx + 0x10]
3905
     mov   ecx, edx
3906
     add   ebx, edx
3907
3908
 
3909
     mov   edx, [eax]
3910
     mov   [eax], ecx			 ; set data size to zero
3911
     mov   [eax + 0x4], ebx		 ; set data offset
3912
3913
 
1 ha 3914
     mov   [esp+32], edx		 ; eax
760 Rus 3915
     ret
1 ha 3916
3917
 
3918
 
3919
3920
 
3921
3922
 
465 serge 3923
1 ha 3924
 
465 serge 3925
;     and   ecx,7    ; offset in byte
3926
1 ha 3927
 
465 serge 3928
;     add   edi,eax
3929
1 ha 3930
 
465 serge 3931
;     shl   ebx,cl
3932
1 ha 3933
 
742 Rus 3934
     jne   siar1
1 ha 3935
3936
 
465 serge 3937
;     and   [edi],byte bl
3938
     btr [edi], eax
3939
1 ha 3940
 
3941
3942
 
3943
3944
 
465 serge 3945
1 ha 3946
 
465 serge 3947
  ;  or    [edi],byte bl        ; disable access - ebp = 1
3948
1 ha 3949
 
3950
3951
 
3952
3953
 
3954
3955
 
3956
     jnz   free_port_area
3957
;     je    r_port_area
3958
;     jmp   free_port_area
3959
3960
 
3961
3962
 
3963
3964
 
742 Rus 3965
     ja    rpal1
75 diamond 3966
     cmp   ecx,65536
3967
     jae   rpal1
3968
     mov   esi,[RESERVED_PORTS]
381 serge 3969
     test  esi,esi	      ; no reserved areas ?
742 Rus 3970
     je    rpal2
1 ha 3971
     cmp   esi,255	      ; max reserved
742 Rus 3972
     jae   rpal1
75 diamond 3973
 rpal3:
465 serge 3974
     mov   edi,esi
1 ha 3975
     shl   edi,4
3976
     add   edi,RESERVED_PORTS
381 serge 3977
     cmp   ebx,[edi+8]
1 ha 3978
     ja    rpal4
75 diamond 3979
     cmp   ecx,[edi+4]
1 ha 3980
     jae   rpal1
3981
;     jb    rpal4
3982
;     jmp   rpal1
3983
 rpal4:
465 serge 3984
1 ha 3985
 
3986
     jnz   rpal3
3987
     jmp   rpal2
3988
   rpal1:
3989
     popad
3990
     mov   eax,1
3991
     ret
3992
3993
 
3994
     popad
3995
3996
 
3997
 
3998
     cli
3999
     pushad			   ; start enable io map
742 Rus 4000
1 ha 4001
 
4002
     jae   no_unmask_io ; jge
4003
4004
 
4005
4006
 
4007
4008
 
4009
4010
 
742 Rus 4011
     call  set_io_access_rights
1 ha 4012
4013
 
4014
4015
 
4016
     cmp   eax,ecx
4017
     jbe   new_port_access
4018
4019
 
4020
4021
 
742 Rus 4022
     sti
1 ha 4023
4024
 
381 serge 4025
     add   edi,1
1 ha 4026
     mov   [RESERVED_PORTS],edi
381 serge 4027
     shl   edi,4
1 ha 4028
     add   edi,RESERVED_PORTS
381 serge 4029
     mov   esi,[TASK_BASE]
379 serge 4030
     mov   esi,[esi+TASKDATA.pid]
115 poddubny 4031
     mov   [edi],esi
1 ha 4032
     mov   [edi+4],ebx
4033
     mov   [edi+8],ecx
4034
4035
 
4036
     ret
4037
4038
 
4039
4040
 
4041
4042
 
381 serge 4043
     test  esi,esi
75 diamond 4044
     je    frpal2
1 ha 4045
     mov   edx,[TASK_BASE]
379 serge 4046
     mov   edx,[edx+TASKDATA.pid]
115 poddubny 4047
   frpal3:
1 ha 4048
     mov   edi,esi
4049
     shl   edi,4
4050
     add   edi,RESERVED_PORTS
381 serge 4051
     cmp   edx,[edi]
1 ha 4052
     jne   frpal4
4053
     cmp   ebx,[edi+4]
4054
     jne   frpal4
4055
     cmp   ecx,[edi+8]
4056
     jne   frpal4
4057
     jmp   frpal1
4058
   frpal4:
4059
     dec   esi
4060
     jnz   frpal3
4061
   frpal2:
4062
     popad
4063
     mov   eax,1
4064
     ret
4065
   frpal1:
4066
     mov   ecx,256
4067
     sub   ecx,esi
4068
     shl   ecx,4
4069
     mov   esi,edi
4070
     add   esi,16
4071
     cld
4072
     rep   movsb
4073
4074
 
381 serge 4075
1 ha 4076
 
4077
4078
 
4079
 
4080
4081
 
742 Rus 4082
1 ha 4083
 
4084
     jge   no_mask_io
4085
4086
 
4087
4088
 
4089
4090
 
4091
4092
 
742 Rus 4093
     call  set_io_access_rights
1 ha 4094
4095
 
4096
4097
 
4098
     cmp   eax,ecx
4099
     jbe   new_port_access_disable
4100
4101
 
4102
4103
 
742 Rus 4104
1 ha 4105
 
4106
     ret
4107
4108
 
4109
 
4110
4111
 
765 Rus 4112
     inc   esi
4113
     cmp   ecx, 16
4114
     jae   ril1
4115
1 ha 4116
 
769 Rus 4117
     lea   ecx, [irq_owner + 4 * ecx]
765 Rus 4118
     mov   edx, [ecx]
4119
     mov   eax, [TASK_BASE]
4120
     mov   edi, [eax + TASKDATA.pid]
4121
     pop   eax
769 Rus 4122
     dec   ebx
765 Rus 4123
     jnz   reserve_irq
4124
1 ha 4125
 
765 Rus 4126
     jne   ril1
4127
     dec   esi
4128
     mov   [ecx], esi
4129
4130
 
4131
4132
 
1 ha 4133
4134
 
765 Rus 4135
     jne   ril1
4136
1 ha 4137
 
769 Rus 4138
4139
 
774 Rus 4140
769 Rus 4141
 
765 Rus 4142
769 Rus 4143
 
765 Rus 4144
   ril1:
1 ha 4145
     mov   [esp+32], esi ; return in eax
765 Rus 4146
     ret
1 ha 4147
4148
 
769 Rus 4149
f_irqs:
4150
     dd 0x0
4151
     dd 0x0
4152
     dd p_irq2
4153
     dd p_irq3
4154
     dd p_irq4
4155
     dd p_irq5
4156
     dd p_irq6
4157
     dd p_irq7
4158
     dd p_irq8
4159
     dd p_irq9
4160
     dd p_irq10
4161
     dd p_irq11
4162
     dd 0x0
4163
     dd 0x0
4164
     dd p_irq14
4165
     dd p_irq15
4166
4167
 
4168
4169
 
1 ha 4170
       inc   [mouse_pause]
33 mario79 4171
       cmp   [SCR_MODE],word 0x12
381 serge 4172
       je   dbrv20
117 mario79 4173
     dbrv12:
1 ha 4174
       cmp  [SCR_MODE],word 0100000000000000b
381 serge 4175
       jge  dbrv20
1 ha 4176
       cmp  [SCR_MODE],word 0x13
381 serge 4177
       je   dbrv20
1 ha 4178
       call  vesa12_drawbackground
4179
       dec   [mouse_pause]
33 mario79 4180
       call   [draw_pointer]
36 mario79 4181
       ret
1 ha 4182
     dbrv20:
4183
       cmp   [BgrDrawMode],dword 1
527 diamond 4184
       jne   bgrstr
1 ha 4185
       call  vesa20_drawbackground_tiled
4186
       dec   [mouse_pause]
33 mario79 4187
       call   [draw_pointer]
36 mario79 4188
       ret
1 ha 4189
     bgrstr:
4190
       call  vesa20_drawbackground_stretch
4191
       dec   [mouse_pause]
33 mario79 4192
       call   [draw_pointer]
36 mario79 4193
       ret
1 ha 4194
4195
 
75 diamond 4196
1 ha 4197
 
742 Rus 4198
sys_putimage:
1 ha 4199
     test  ecx,0x80008000
53 mikedld 4200
     jnz   .exit
4201
     test  ecx,0x0000FFFF
4202
     jz    .exit
4203
     test  ecx,0xFFFF0000
4204
     jnz   @f
4205
  .exit:
4206
     ret
4207
 @@:
4208
	mov	edi,[current_slot]
742 Rus 4209
	add	dx,word[edi+APPDATA.wnd_clientbox.top]
4210
	rol	edx,16
4211
	add	dx,word[edi+APPDATA.wnd_clientbox.left]
4212
	rol	edx,16
4213
  .forced:
114 mikedld 4214
	push	ebp esi 0
742 Rus 4215
	mov	ebp, putimage_get24bpp
4216
	mov	esi, putimage_init24bpp
4217
sys_putimage_bpp:
283 diamond 4218
;        call    [disable_mouse] ; this will be done in xxx_putimage
4219
;        mov     eax, vga_putimage
117 mario79 4220
	cmp	[SCR_MODE], word 0x12
742 Rus 4221
	jz	@f   ;.doit
4222
	mov	eax, vesa12_putimage
4223
	cmp	[SCR_MODE], word 0100000000000000b
4224
	jae	@f
4225
	cmp	[SCR_MODE], word 0x13
4226
	jnz	.doit
4227
@@:
75 diamond 4228
	mov	eax, vesa20_putimage
742 Rus 4229
.doit:
75 diamond 4230
	inc	[mouse_pause]
742 Rus 4231
	call	eax
4232
	dec	[mouse_pause]
4233
	pop	ebp esi ebp
4234
	jmp	[draw_pointer]
4235
1 ha 4236
 
283 diamond 4237
	mov	edi, esi
742 Rus 4238
	mov	esi, edx
4239
	mov	edx, ecx
4240
	mov	ecx, ebx
4241
	mov	ebx, eax
4242
sys_putimage_palette:
283 diamond 4243
; ebx = pointer to image
4244
; ecx = [xsize]*65536 + [ysize]
4245
; edx = [xstart]*65536 + [ystart]
4246
; esi = number of bits per pixel, must be 8, 24 or 32
314 diamond 4247
; edi = pointer to palette
283 diamond 4248
; ebp = row delta
314 diamond 4249
	mov	eax, [CURRENT_TASK]
742 Rus 4250
	shl	eax, 8
4251
	add	dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
4252
	rol	edx, 16
4253
	add	dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
4254
	rol	edx, 16
4255
.forced:
283 diamond 4256
	push	ebp esi ebp
742 Rus 4257
	cmp	esi, 8
4258
	jnz	@f
4259
	mov	ebp, putimage_get8bpp
4260
	mov	esi, putimage_init8bpp
4261
	jmp	sys_putimage_bpp
4262
@@:
314 diamond 4263
        cmp     esi, 16
844 serge 4264
        jnz     @f
4265
        mov     ebp, putimage_get16bpp
4266
        mov     esi, putimage_init16bpp
4267
        jmp     sys_putimage_bpp
4268
@@:
4269
	cmp	esi, 24
742 Rus 4270
	jnz	@f
4271
	mov	ebp, putimage_get24bpp
4272
	mov	esi, putimage_init24bpp
4273
	jmp	sys_putimage_bpp
4274
@@:
314 diamond 4275
	cmp	esi, 32
742 Rus 4276
	jnz	@f
4277
	mov	ebp, putimage_get32bpp
4278
	mov	esi, putimage_init32bpp
4279
	jmp	sys_putimage_bpp
4280
@@:
314 diamond 4281
	pop	ebp esi ebp
844 serge 4282
	ret
742 Rus 4283
283 diamond 4284
 
4285
	lea	eax, [eax*3]
742 Rus 4286
putimage_init8bpp:
283 diamond 4287
	ret
742 Rus 4288
283 diamond 4289
 
4290
	mov	eax, [esi]
742 Rus 4291
	add	esi, 3
4292
	ret	4
4293
putimage_get8bpp:
283 diamond 4294
	movzx	eax, byte [esi]
742 Rus 4295
	push	edx
4296
	mov	edx, [esp+8]
4297
	mov	eax, [edx+eax*4]
4298
	pop	edx
4299
	inc	esi
4300
	ret	4
4301
283 diamond 4302
 
314 diamond 4303
	shl	eax, 2
742 Rus 4304
	ret
4305
putimage_get32bpp:
314 diamond 4306
	lodsd
742 Rus 4307
	ret	4
4308
314 diamond 4309
 
844 serge 4310
        add     eax, eax
4311
        ret
4312
putimage_get16bpp:
4313
; 0RRRRRGGGGGBBBBB -> 00000000RRRRR000GGGGG000BBBBB000
4314
        push    ecx edx
4315
        movzx   eax, word [esi]
4316
        add     esi, 2
4317
        mov     ecx, eax
4318
        mov     edx, eax
4319
        and     eax, 0x1F
4320
        and     ecx, 0x1F shl 5
4321
        and     edx, 0x1F shl 10
4322
        shl     eax, 3
4323
        shl     ecx, 6
4324
        shl     edx, 9
4325
        or      eax, ecx
4326
        or      eax, edx
4327
        pop     edx ecx
4328
        ret
4329
4330
 
1 ha 4331
; ebx y beginning
4332
; ecx x end
4333
	; edx y end
283 diamond 4334
; edi color
1 ha 4335
4336
 
4337
	mov	esi,[current_slot]
742 Rus 4338
	add	eax,[esi+APPDATA.wnd_clientbox.left]
4339
	add	ecx,[esi+APPDATA.wnd_clientbox.left]
4340
	add	ebx,[esi+APPDATA.wnd_clientbox.top]
4341
	add	edx,[esi+APPDATA.wnd_clientbox.top]
4342
  .forced:
114 mikedld 4343
    inc   [mouse_pause]
33 mario79 4344
;        call    [disable_mouse]
283 diamond 4345
    cmp   [SCR_MODE],word 0x12
381 serge 4346
    je	 dbv20
742 Rus 4347
   sdbv20:
1 ha 4348
    cmp  [SCR_MODE],word 0100000000000000b
381 serge 4349
    jge  dbv20
1 ha 4350
    cmp  [SCR_MODE],word 0x13
381 serge 4351
    je	 dbv20
742 Rus 4352
    call vesa12_drawbar
1 ha 4353
    dec   [mouse_pause]
33 mario79 4354
    call   [draw_pointer]
36 mario79 4355
    ret
1 ha 4356
  dbv20:
4357
    call vesa20_drawbar
4358
    dec   [mouse_pause]
33 mario79 4359
    call   [draw_pointer]
36 mario79 4360
    ret
1 ha 4361
4362
 
4363
 
4364
 
4365
4366
 
742 Rus 4367
1 ha 4368
 
742 Rus 4369
      kr_loop:
1 ha 4370
	in	al,0x64
742 Rus 4371
	test	al,1
4372
	jnz	kr_ready
4373
	loop	kr_loop
4374
	mov	ah,1
4375
	jmp	kr_exit
4376
      kr_ready:
1 ha 4377
	push	ecx
742 Rus 4378
	mov	ecx,32
4379
      kr_delay:
1 ha 4380
	loop	kr_delay
742 Rus 4381
	pop	ecx
4382
	in	al,0x60
4383
	xor	ah,ah
4384
      kr_exit:
1 ha 4385
4386
 
742 Rus 4387
1 ha 4388
 
742 Rus 4389
1 ha 4390
 
4391
 
4392
4393
 
742 Rus 4394
1 ha 4395
 
742 Rus 4396
;        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
265 diamond 4397
;      kw_loop1:
4398
;        in      al,0x64
4399
;        test    al,0x20
4400
;        jz      kw_ok1
4401
;        loop    kw_loop1
4402
;        mov     ah,1
4403
;        jmp     kw_exit
4404
;      kw_ok1:
4405
	in	al,0x60
742 Rus 4406
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4407
      kw_loop:
1 ha 4408
	in	al,0x64
742 Rus 4409
	test	al,2
4410
	jz	kw_ok
4411
	loop	kw_loop
4412
	mov	ah,1
4413
	jmp	kw_exit
4414
      kw_ok:
1 ha 4415
	mov	al,dl
742 Rus 4416
	out	0x60,al
4417
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4418
      kw_loop3:
1 ha 4419
	in	al,0x64
742 Rus 4420
	test	al,2
4421
	jz	kw_ok3
4422
	loop	kw_loop3
4423
	mov	ah,1
4424
	jmp	kw_exit
4425
      kw_ok3:
1 ha 4426
	mov	ah,8
742 Rus 4427
      kw_loop4:
1 ha 4428
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
742 Rus 4429
      kw_loop5:
1 ha 4430
	in	al,0x64
742 Rus 4431
	test	al,1
4432
	jnz	kw_ok4
4433
	loop	kw_loop5
4434
	dec	ah
4435
	jnz	kw_loop4
4436
      kw_ok4:
1 ha 4437
	xor	ah,ah
742 Rus 4438
      kw_exit:
1 ha 4439
4440
 
742 Rus 4441
1 ha 4442
 
742 Rus 4443
1 ha 4444
 
4445
 
4446
4447
 
742 Rus 4448
      c_wait:
1 ha 4449
	in	al,0x64
742 Rus 4450
	test	al,2
4451
	jz	c_send
4452
	loop	c_wait
4453
	jmp	c_error
4454
      c_send:
1 ha 4455
	mov	al,bl
742 Rus 4456
	out	0x64,al
4457
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4458
      c_accept:
1 ha 4459
	in	al,0x64
742 Rus 4460
	test	al,2
4461
	jz	c_ok
4462
	loop	c_accept
4463
      c_error:
1 ha 4464
	mov	ah,1
742 Rus 4465
	jmp	c_exit
4466
      c_ok:
1 ha 4467
	xor	ah,ah
742 Rus 4468
      c_exit:
1 ha 4469
	ret
742 Rus 4470
1 ha 4471
 
4472
 
4473
	   ; ps2 mouse enable
742 Rus 4474
1 ha 4475
 
381 serge 4476
1 ha 4477
 
4478
4479
 
4480
4481
 
4482
 
4483
     bt [cpu_caps], CAPS_TSC
164 serge 4484
     jnc ret_rdtsc
4485
     rdtsc
1 ha 4486
     ret
4487
   ret_rdtsc:
4488
     mov   edx,0xffffffff
4489
     mov   eax,0xffffffff
4490
     ret
4491
4492
 
4493
4494
 
742 Rus 4495
	out	0x20,al
4496
	call	pic_delay
4497
	out	0xA0,al
4498
	call	pic_delay
4499
1 ha 4500
 
742 Rus 4501
	out	0x21,al
4502
	call	pic_delay
4503
	mov	al,0x28 	;  generate 0x28 +
4504
	out	0xA1,al
4505
	call	pic_delay
4506
1 ha 4507
 
742 Rus 4508
	out	0x21,al
4509
	call	pic_delay
4510
	mov	al,0x02 	;  at irq9
4511
	out	0xA1,al
4512
	call	pic_delay
4513
1 ha 4514
 
742 Rus 4515
	out	0x21,al
4516
	call	pic_delay
4517
	out	0xA1,al
4518
	call	pic_delay
4519
1 ha 4520
 
742 Rus 4521
	out	0xA1,al
4522
	call	pic_delay
4523
	out	0x21,al
4524
	call	pic_delay
4525
1 ha 4526
 
742 Rus 4527
	cld
4528
picl1:	call	pic_delay
4529
	loop	picl1
4530
1 ha 4531
 
742 Rus 4532
	out	0xA1,al
4533
	call	pic_delay
4534
	out	0x21,al
4535
	call	pic_delay
4536
1 ha 4537
 
742 Rus 4538
1 ha 4539
 
4540
 
4541
4542
 
742 Rus 4543
pdl1:	ret
4544
1 ha 4545
 
4546
 
4547
4548
 
4549
   @@:
4550
     cmp    [esi],byte 0
4551
     je     @f
4552
     mov    eax,1
4553
     movzx  ebx,byte [esi]
4554
     call   sys_msg_board
4555
     inc    esi
4556
     jmp    @b
4557
   @@:
4558
     popad
4559
     ret
4560
4561
 
709 diamond 4562
; in: al = byte to display
4563
; out: nothing
4564
; destroys: nothing
4565
	pushad
742 Rus 4566
	mov	ecx, 2
4567
	shl	eax, 24
4568
	jmp	@f
4569
709 diamond 4570
 
4571
; in: ax = word to display
4572
; out: nothing
4573
; destroys: nothing
4574
	pushad
742 Rus 4575
	mov	ecx, 4
4576
	shl	eax, 16
4577
	jmp	@f
4578
709 diamond 4579
 
4580
; in: eax = dword to display
4581
; out: nothing
4582
; destroys: nothing
4583
	pushad
742 Rus 4584
	mov	ecx, 8
4585
@@:
709 diamond 4586
	push	ecx
742 Rus 4587
	rol	eax, 4
4588
	push	eax
4589
	and	al, 0xF
4590
	cmp	al, 10
4591
	sbb	al, 69h
4592
	das
4593
	mov	bl, al
4594
	xor	eax, eax
4595
	inc	eax
4596
	call	sys_msg_board
4597
	pop	eax
4598
	pop	ecx
4599
	loop	@b
4600
	popad
4601
	ret
4602
709 diamond 4603
 
1 ha 4604
  msg_board_data: times 4096 db 0
373 mikedld 4605
  msg_board_count dd 0x0
1 ha 4606
endg
4607
4608
 
4609
4610
 
4611
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4612
4613
 
671 Ghost 4614
	cmp	eax, 1
4615
	jne	.smbl1
4616
1 ha 4617
 
4618
 
671 Ghost 4619
	inc	ecx
4620
	and	ecx, 4095
4621
	mov	[msg_board_count], ecx
4622
	mov	[check_idle_semaphore], 5
4623
	ret
4624
.smbl1:
4625
	cmp	eax, 2
4626
	jne	.smbl2
4627
	test	ecx, ecx
4628
	jz	.smbl21
4629
	mov	eax, msg_board_data+1
4630
	mov	ebx, msg_board_data
4631
	movzx	edx, byte [ebx]
4632
	call	memmove
4633
	dec	[msg_board_count]
4634
	mov	[esp + 36], edx ;eax
4635
	mov	[esp + 24], dword 1
4636
	ret
4637
.smbl21:
4638
	mov	[esp+36], ecx
4639
	mov	[esp+24], ecx
4640
.smbl2:
4641
	ret
4642
1 ha 4643
 
4644
 
4645
 
4646
	mov	edi, [CURRENT_TASK]
742 Rus 4647
1 ha 4648
 
742 Rus 4649
     jne   no_set_keyboard_setup
1 ha 4650
4651
 
4652
     mov   [edi+SLOT_BASE + APPDATA.keyboard_mode],bl
380 serge 4653
1 ha 4654
 
4655
4656
 
4657
4658
 
742 Rus 4659
     jne   no_get_keyboard_setup
1 ha 4660
4661
 
4662
     movzx eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
380 serge 4663
1 ha 4664
 
4665
4666
 
4667
4668
 
4669
4670
 
742 Rus 4671
     jne   no_get_keyboard_cas
1 ha 4672
4673
 
4674
;     movzx eax,byte [shift]
4675
;     movzx ebx,byte [ctrl]
4676
;     shl   ebx,2
4677
;     add   eax,ebx
4678
;     movzx ebx,byte [alt]
4679
;     shl   ebx,3
4680
;     add   eax,ebx
4681
4682
 
4683
     mov   eax, [kb_state]
4684
 ;// mike.dld ]
4685
4686
 
4687
4688
 
4689
4690
 
4691
4692
 
742 Rus 4693
	jnz	no_add_keyboard_hotkey
4694
1 ha 4695
 
742 Rus 4696
@@:
92 diamond 4697
	cmp	dword [eax+8], 0
742 Rus 4698
	jz	.found_free
4699
	add	eax, 16
4700
	cmp	eax, hotkey_list+16*256
4701
	jb	@b
4702
	mov	dword [esp+36], 1
4703
	ret
4704
.found_free:
92 diamond 4705
	mov	[eax+8], edi
742 Rus 4706
	mov	[eax+4], ecx
4707
	movzx	ebx, bl
4708
	lea	ebx, [hotkey_scancodes+ebx*4]
4709
	mov	ecx, [ebx]
4710
	mov	[eax], ecx
4711
	mov	[ebx], eax
4712
	mov	[eax+12], ebx
4713
	jecxz	@f
4714
	mov	[ecx+12], eax
4715
@@:
92 diamond 4716
	and	dword [esp+36], 0
742 Rus 4717
	ret
4718
92 diamond 4719
 
4720
4721
 
742 Rus 4722
	jnz	no_del_keyboard_hotkey
4723
92 diamond 4724
 
742 Rus 4725
	lea	ebx, [hotkey_scancodes+ebx*4]
4726
	mov	eax, [ebx]
4727
.scan:
92 diamond 4728
	test	eax, eax
742 Rus 4729
	jz	.notfound
4730
	cmp	[eax+8], edi
4731
	jnz	.next
4732
	cmp	[eax+4], ecx
4733
	jz	.found
4734
.next:
92 diamond 4735
	mov	eax, [eax]
742 Rus 4736
	jmp	.scan
4737
.notfound:
92 diamond 4738
	mov	dword [esp+36], 1
742 Rus 4739
	ret
4740
.found:
92 diamond 4741
	mov	ecx, [eax]
742 Rus 4742
	jecxz	@f
4743
	mov	edx, [eax+12]
4744
	mov	[ecx+12], edx
4745
@@:
92 diamond 4746
	mov	ecx, [eax+12]
742 Rus 4747
	mov	edx, [eax]
4748
	mov	[ecx], edx
4749
	xor	edx, edx
4750
	mov	[eax+4], edx
4751
	mov	[eax+8], edx
4752
	mov	[eax+12], edx
4753
	mov	[eax], edx
4754
	mov	[esp+36], edx
4755
	ret
4756
92 diamond 4757
 
4758
     ret
1 ha 4759
4760
 
4761
 
4762
4763
 
742 Rus 4764
1 ha 4765
 
742 Rus 4766
     jne  no_gs1
1 ha 4767
     mov  eax,[Screen_Max_X]
753 serge 4768
     shl  eax,16
1 ha 4769
     mov  ax,[Screen_Max_Y]
753 serge 4770
     add  eax,0x00010001
1 ha 4771
     mov  [esp+36],eax
4772
     ret
4773
   no_gs1:
4774
4775
 
742 Rus 4776
     jne   no_gs2
1 ha 4777
     movzx eax,byte [ScreenBPP]
381 serge 4778
     mov   [esp+36],eax
1 ha 4779
     ret
4780
   no_gs2:
4781
4782
 
742 Rus 4783
     jne   no_gs3
1 ha 4784
     mov   eax,[BytesPerScanLine]
381 serge 4785
     mov   [esp+36],eax
1 ha 4786
     ret
4787
   no_gs3:
4788
4789
 
4790
     ret
4791
4792
 
4793
 
4794
4795
 
4796
4797
 
4798
     mov   [esp+36],eax
4799
     ret
4800
4801
 
4802
 
4803
4804
 
742 Rus 4805
1 ha 4806
 
742 Rus 4807
	mov	ebx, ecx
4808
	mov	ecx, edx
4809
	mov	edx, [TASK_BASE]
4810
	add	eax, [edx-twdw+WDATA.box.left]
4811
	add	ebx, [edx-twdw+WDATA.box.top]
4812
	mov	edi, [current_slot]
4813
	add	eax, [edi+APPDATA.wnd_clientbox.left]
4814
	add	ebx, [edi+APPDATA.wnd_clientbox.top]
4815
	xor	edi, edi ; no force
4816
;       mov     edi, 1
684 diamond 4817
	call	[disable_mouse]
742 Rus 4818
	jmp	[putpixel]
4819
1 ha 4820
 
4821
4822
 
742 Rus 4823
1 ha 4824
 
742 Rus 4825
	mov   ebp,[eax-twdw+WDATA.box.left]
4826
	push  esi
4827
	mov   esi,[current_slot]
4828
	add   ebp,[esi+APPDATA.wnd_clientbox.left]
4829
	shl   ebp,16
4830
	add   ebp,[eax-twdw+WDATA.box.top]
4831
	add   bp,word[esi+APPDATA.wnd_clientbox.top]
4832
	pop   esi
4833
	add   ebx,ebp
4834
	mov   eax,edi
4835
	xor   edi,edi
4836
	jmp   dtext
4837
1 ha 4838
 
4839
4840
 
742 Rus 4841
1 ha 4842
 
742 Rus 4843
	mov	ebx, ecx
4844
	mov	ecx, edx
4845
	mov	edx, esi
4846
	mov	esi, 12
4847
	call	fileread
4848
	mov	[esp+32], eax
4849
	ret
4850
1 ha 4851
 
4852
4853
 
742 Rus 4854
1 ha 4855
 
671 Ghost 4856
	and	edi, 0x80FFFFFF
4857
	test	bx, bx	; x.size
4858
	je	.drectr
4859
	test	cx, cx ; y.size
4860
	je	.drectr
4861
1 ha 4862
 
671 Ghost 4863
	mov	ebx, ecx
4864
1 ha 4865
 
671 Ghost 4866
	shr	eax, 16 ; eax - x.coord
4867
	movzx	edx, bx ; edx - y.size
4868
	shr	ebx, 16 ; ebx - y.coord
4869
	mov	esi, [current_slot]
4870
1 ha 4871
 
671 Ghost 4872
	add	ebx, [esi + APPDATA.wnd_clientbox.top]
4873
	add	ecx, eax
4874
	add	edx, ebx
4875
	jmp	[drawbar]
4876
.drectr:
4877
	ret
4878
1 ha 4879
 
4880
syscall_getscreensize:			; GetScreenSize
742 Rus 4881
	mov	ax, [Screen_Max_X]
759 Rus 4882
	shl	eax, 16
671 Ghost 4883
	mov	ax, [Screen_Max_Y]
759 Rus 4884
	mov	[esp + 32], eax
671 Ghost 4885
	ret
4886
1 ha 4887
 
671 Ghost 4888
4889
 
742 Rus 4890
1 ha 4891
 
742 Rus 4892
	jb	.audio
4893
	jz	.eject
4894
	cmp	eax, 5
4895
	jnz	.ret
4896
.load:
588 diamond 4897
	call	.reserve
742 Rus 4898
	call	LoadMedium
4899
	call	.free
4900
	ret
4901
.eject:
588 diamond 4902
	call	.reserve
742 Rus 4903
	call	clear_CD_cache
4904
	call	allow_medium_removal
4905
	call	EjectMedium
4906
	call	.free
4907
	ret
4908
.audio:
588 diamond 4909
     call  sys_cd_audio
1 ha 4910
     mov   [esp+36],eax
4911
.ret:
588 diamond 4912
     ret
1 ha 4913
4914
 
588 diamond 4915
	call	reserve_cd
742 Rus 4916
	mov	eax, ebx
4917
	shr	eax, 1
4918
	and	eax, 1
4919
	inc	eax
4920
	mov	[ChannelNumber], ax
4921
	mov	eax, ebx
4922
	and	eax, 1
4923
	mov	[DiskNumber], al
4924
	call	reserve_cd_channel
4925
	and	ebx, 3
4926
	inc	ebx
4927
	mov	[cdpos], ebx
4928
	add	ebx, ebx
4929
	mov	cl, 8
4930
	sub	cl, bl
4931
	mov	al, [DRIVE_DATA+1]
4932
	shr	al, cl
4933
	test	al, 2
4934
	jz	.err
4935
	ret
4936
.free:
588 diamond 4937
	call	free_cd_channel
742 Rus 4938
	and	[cd_status], 0
4939
	ret
4940
.err:
590 diamond 4941
	call	.free
742 Rus 4942
	pop	eax
4943
	ret
4944
588 diamond 4945
 
1 ha 4946
4947
 
742 Rus 4948
     mov   ecx, [Screen_Max_X]
753 serge 4949
     inc   ecx
1 ha 4950
     xor   edx, edx
671 Ghost 4951
     mov   eax, ebx
4952
     div   ecx
1 ha 4953
     mov   ebx, edx
671 Ghost 4954
     xchg  eax, ebx
4955
     call  dword [GETPIXEL] ; eax - x, ebx - y
4956
     mov   [esp + 32], ecx
4957
     ret
1 ha 4958
4959
 
4960
 
4961
4962
 
742 Rus 4963
1 ha 4964
 
671 Ghost 4965
	movzx	eax, word[edi-twdw+WDATA.box.left]
752 Lrz 4966
	mov	ebp, eax
4967
	mov	esi, [current_slot]
671 Ghost 4968
	add	ebp, [esi+APPDATA.wnd_clientbox.left]
4969
	add	ax, word[esi+APPDATA.wnd_clientbox.left]
752 Lrz 4970
	add	ebp,ebx
4971
	shl	eax, 16
4972
	movzx	ebx, word[edi-twdw+WDATA.box.top]
4973
	add	eax, ebp
671 Ghost 4974
	mov	ebp, ebx
752 Lrz 4975
	add	ebp, [esi+APPDATA.wnd_clientbox.top]
671 Ghost 4976
	add	bx, word[esi+APPDATA.wnd_clientbox.top]
752 Lrz 4977
	add	ebp, ecx
759 Rus 4978
	shl	ebx, 16
752 Lrz 4979
	xor	edi, edi
671 Ghost 4980
	add	ebx, ebp
752 Lrz 4981
	mov	ecx, edx
4982
	jmp	[draw_line]
671 Ghost 4983
1 ha 4984
 
4985
4986
 
742 Rus 4987
4988
 
4989
     jae   .err
75 diamond 4990
742 Rus 4991
 
774 Rus 4992
     je    .err
4993
4994
 
742 Rus 4995
     mov   [esp+32],eax
4996
4997
 
1 ha 4998
.err:
75 diamond 4999
     or    dword [esp+32], -1
742 Rus 5000
     ret
75 diamond 5001
1 ha 5002
 
5003
5004
 
742 Rus 5005
1 ha 5006
 
5007
     mov   [esp+36],eax
5008
     ret
5009
5010
 
5011
5012
 
742 Rus 5013
1 ha 5014
 
5015
     mov   [esp+36],eax
5016
     ret
5017
5018
 
5019
5020
 
5021
5022
 
742 Rus 5023
1 ha 5024
 
5025
;     call  change_task                 ; between sent packet
5026
5027
 
5028
     ret
5029
5030
 
5031
5032
 
742 Rus 5033
     call  app_socket_handler
1 ha 5034
5035
 
5036
;     call  change_task                 ; between sent packet
5037
5038
 
5039
     mov   [esp+24],ebx
5040
     ret
5041
5042
 
5043
5044
 
742 Rus 5045
1 ha 5046
 
379 serge 5047
     add   edi,TASKDATA.mem_start
115 poddubny 5048
     add   eax,[edi]
1 ha 5049
     add   ecx,[edi]
5050
     add   edx,[edi]
5051
     call  file_read
5052
5053
 
5054
     mov   [esp+24],ebx
5055
5056
 
5057
5058
 
375 Ghost 5059
	ret
742 Rus 5060
378 serge 5061
 
757 serge 5062
set_screen:
5063
	cmp eax, [Screen_Max_X]
759 Rus 5064
	jne .set
5065
709 diamond 5066
 
759 Rus 5067
	jne .set
5068
	ret
5069
.set:
757 serge 5070
	pushfd
759 Rus 5071
	cli
5072
757 serge 5073
 
759 Rus 5074
	mov [Screen_Max_Y], edx
5075
757 serge 5076
 
759 Rus 5077
	mov [screen_workarea.bottom], edx
5078
	inc eax
5079
	shl eax, 2			;32 bpp
5080
	mov [BytesPerScanLine], eax
5081
	push ebx
5082
	push esi
5083
	push edi
5084
	call	repos_windows
5085
	mov	eax, 0
5086
	mov	ebx, 0
5087
	mov	ecx, [Screen_Max_X]
5088
	mov	edx, [Screen_Max_Y]
5089
	call	calculatescreen
5090
	pop edi
5091
	pop esi
5092
	pop ebx
5093
757 serge 5094
 
759 Rus 5095
	ret
5096
757 serge 5097
 
76 mario79 5098
apm_entry    dp    0
5099
apm_vf	      dd    0
742 Rus 5100
align 4
1 ha 5101
sys_apm:
76 mario79 5102
    cmp    word [apm_vf], 0    ; Check APM BIOS enable
5103
    jne    @f
5104
    or	  [esp + 56], byte 1	; error
742 Rus 5105
    mov    [esp + 36], dword 8	  ; 32-bit protected-mode interface not supported
5106
    ret
76 mario79 5107
164 serge 5108
 
465 serge 5109
    xchg    eax, ecx
5110
    xchg    ebx, ecx
76 mario79 5111
164 serge 5112
 
76 mario79 5113
    ja	  @f
742 Rus 5114
    and    [esp + 56], byte 0xfe    ; emulate func 0..3 as func 0
78 diamond 5115
    mov    eax, [apm_vf]
76 mario79 5116
    mov    [esp + 36], eax
5117
    shr    eax, 16
5118
    mov    [esp + 32], eax
5119
    ret
5120
78 diamond 5121
 
465 serge 5122
5123
 
5124
    xchg [master_tab], esi
5125
    push esi
5126
    mov edi, cr3
5127
    mov cr3, edi		 ;flush TLB
742 Rus 5128
465 serge 5129
 
742 Rus 5130
465 serge 5131
 
5132
    mov [master_tab], eax
5133
    mov eax, cr3
5134
    mov cr3, eax
5135
    pop eax
5136
5137
 
76 mario79 5138
    mov    [esp + 12], esi
5139
    mov    [esp + 24], ebx
5140
    mov    [esp + 28], edx
5141
    mov    [esp + 32], ecx
5142
    mov    [esp + 36], eax
5143
    setc    al
5144
    and    [esp + 56], byte 0xfe
78 diamond 5145
    or	  [esp + 56], al
742 Rus 5146
465 serge 5147
 
5148
 
76 mario79 5149
; -----------------------------------------
5150
1 ha 5151
 
76 mario79 5152
5153
 
742 Rus 5154
     mov   [esp + 32], dword -1
671 Ghost 5155
     ret
1 ha 5156
5157
 
465 serge 5158
system_shutdown:	  ; shut down the system
742 Rus 5159
1 ha 5160
 
742 Rus 5161
	   jne @F
5162
	   ret
5163
@@:
465 serge 5164
	   call stop_all_services
742 Rus 5165
	   push 3		 ; stop playing cd
5166
	   pop	eax
5167
	   call sys_cd_audio
5168
1 ha 5169
 
465 serge 5170
	   cli
742 Rus 5171
1 ha 5172
 
742 Rus 5173
	   push 12
5174
	   pop	esi
5175
	   xor	ebx,ebx
5176
	   or	ecx,-1
5177
	   mov	edx, OS_BASE+0x70000
5178
	   call fileread
5179
1 ha 5180
 
847 serge 5181
   ;        mov  edi,OS_BASE+0x40000
5182
   ;        mov  ecx,1000
5183
   ;        rep  movsb
5184
1 ha 5185
 
855 serge 5186
           mov  edi, OS_BASE
847 serge 5187
           mov  ecx,0x10000/4
5188
           cld
5189
           rep movsd
5190
1 ha 5191
 
742 Rus 5192
1 ha 5193
 
742 Rus 5194
	   out 0x21, al
5195
	   out 0xA1, al
5196
1 ha 5197
 
709 diamond 5198
       ;    mov  word [OS_BASE+0x467+0],pr_mode_exit
847 serge 5199
       ;    mov  word [OS_BASE+0x467+2],0x1000
5200
1 ha 5201
 
742 Rus 5202
	   out	0x70,al
5203
	   mov	al,0x05
5204
	   out	0x71,al
5205
1 ha 5206
 
742 Rus 5207
	   out	0x64,al
5208
709 diamond 5209
 
742 Rus 5210
1 ha 5211
 
709 diamond 5212
	cmp	byte [OS_BASE + 0x9030], 2
742 Rus 5213
	jnz	no_acpi_power_off
5214
1 ha 5215
 
709 diamond 5216
; 1) The first 1 Kb of the Extended BIOS Data Area (EBDA).
5217
	movzx	eax, word [OS_BASE + 0x40E]
742 Rus 5218
	shl	eax, 4
5219
	jz	@f
5220
	mov	ecx, 1024/16
5221
	call	scan_rsdp
5222
	jnc	.rsdp_found
5223
@@:
709 diamond 5224
; 2) The BIOS read-only memory space between 0E0000h and 0FFFFFh.
5225
	mov	eax, 0xE0000
742 Rus 5226
	mov	ecx, 0x2000
5227
	call	scan_rsdp
5228
	jc	no_acpi_power_off
5229
.rsdp_found:
709 diamond 5230
	mov	esi, [eax+16]	; esi contains physical address of the RSDT
742 Rus 5231
	mov	ebp, [ipc_tmp]
5232
	stdcall map_page, ebp, esi, PG_MAP
5233
	lea	eax, [esi+1000h]
5234
	lea	edx, [ebp+1000h]
5235
	stdcall map_page, edx, eax, PG_MAP
5236
	and	esi, 0xFFF
5237
	add	esi, ebp
5238
	cmp	dword [esi], 'RSDT'
5239
	jnz	no_acpi_power_off
5240
	mov	ecx, [esi+4]
5241
	sub	ecx, 24h
5242
	jbe	no_acpi_power_off
5243
	shr	ecx, 2
5244
	add	esi, 24h
5245
.scan_fadt:
709 diamond 5246
	lodsd
742 Rus 5247
	mov	ebx, eax
5248
	lea	eax, [ebp+2000h]
5249
	stdcall map_page, eax, ebx, PG_MAP
5250
	lea	eax, [ebp+3000h]
5251
	add	ebx, 0x1000
5252
	stdcall map_page, eax, ebx, PG_MAP
5253
	and	ebx, 0xFFF
5254
	lea	ebx, [ebx+ebp+2000h]
5255
	cmp	dword [ebx], 'FACP'
5256
	jz	.fadt_found
5257
	loop	.scan_fadt
5258
	jmp	no_acpi_power_off
5259
.fadt_found:
709 diamond 5260
; ebx is linear address of FADT
5261
	mov	edx, [ebx+48]
742 Rus 5262
	test	edx, edx
5263
	jz	.nosmi
5264
	mov	al, [ebx+52]
5265
	out	dx, al
5266
	mov	edx, [ebx+64]
5267
@@:
709 diamond 5268
	in	ax, dx
742 Rus 5269
	test	al, 1
5270
	jz	@b
5271
.nosmi:
709 diamond 5272
	mov	edx, [ebx+64]
742 Rus 5273
	in	ax, dx
5274
	and	ax, 203h
5275
	or	ax, 3C00h
5276
	out	dx, ax
5277
	mov	edx, [ebx+68]
5278
	test	edx, edx
5279
	jz	@f
5280
	in	ax, dx
5281
	and	ax, 203h
5282
	or	ax, 3C00h
5283
	out	dx, ax
5284
@@:
709 diamond 5285
	jmp	$
742 Rus 5286
709 diamond 5287
 
5288
 
5289
	   mov	word [OS_BASE+0x467+0],pr_mode_exit
742 Rus 5290
	   mov	word [OS_BASE+0x467+2],0x1000
5291
709 diamond 5292
 
742 Rus 5293
	   out	0x70,al
5294
	   mov	al,0x05
5295
	   out	0x71,al
5296
709 diamond 5297
 
742 Rus 5298
	   out	0x64,al
5299
709 diamond 5300
 
742 Rus 5301
709 diamond 5302
 
5303
	add	eax, OS_BASE
742 Rus 5304
.s:
709 diamond 5305
	cmp	dword [eax], 'RSD '
742 Rus 5306
	jnz	.n
5307
	cmp	dword [eax+4], 'PTR '
5308
	jnz	.n
5309
	xor	edx, edx
5310
	xor	esi, esi
5311
@@:
709 diamond 5312
	add	dl, [eax+esi]
742 Rus 5313
	inc	esi
5314
	cmp	esi, 20
5315
	jnz	@b
5316
	test	dl, dl
5317
	jz	.ok
5318
.n:
709 diamond 5319
	add	eax, 10h
742 Rus 5320
	loop	.s
5321
	stc
5322
.ok:
709 diamond 5323
	ret
742 Rus 5324
end if
709 diamond 5325
5326
 
465 serge 5327
1 ha 5328
 
465 serge 5329
1 ha 5330
 
849 serge 5331
;diff16 "end of kernel code",0,$
5332