Subversion Repositories Kolibri OS

Rev

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