Subversion Repositories Kolibri OS

Rev

Rev 888 | Rev 890 | 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
 
889 serge 132
863 serge 133
 
889 serge 134
135
 
136
137
 
863 serge 138
139
 
855 serge 140
extrn _16bit_end
141
142
 
851 serge 143
extrn _poweroff
863 serge 144
1 ha 145
 
854 serge 146
extrn _init_mm
147
148
 
864 serge 149
extrn @core_free@4
887 serge 150
864 serge 151
 
859 serge 152
extrn @find_large_md@4
153
886 serge 154
 
859 serge 155
extrn @mem_free@4
886 serge 156
854 serge 157
 
889 serge 158
extrn @load_pe_driver@4
159
160
 
859 serge 161
extrn _alloc_page
854 serge 162
163
 
859 serge 164
165
 
851 serge 166
849 serge 167
 
864 serge 168
 
854 serge 169
1 ha 170
 
851 serge 171
1 ha 172
 
848 serge 173
847 serge 174
 
848 serge 175
176
 
847 serge 177
        ;   bts [cpu_caps-OS_BASE], CAPS_TSC     ;force use rdtsc
854 serge 178
424 spraid 179
 
847 serge 180
837 serge 181
 
848 serge 182
1 ha 183
 
513 serge 184
;bios32_entry    dd ?
854 serge 185
;tmp_page_tabs   dd ?
186
586 serge 187
 
498 diamond 188
 
465 serge 189
__DEBUG_LEVEL__ fix 1
190
380 serge 191
 
848 serge 192
 
839 serge 193
MEM_WC     equ 1               ;write combined memory
194
MEM_UC     equ 0               ;uncached memory
195
196
 
197
 
854 serge 198
           cli
199
@@:
200
           hlt
201
           jmp @B
202
839 serge 203
 
854 serge 204
_panic_printf:
205
839 serge 206
 
854 serge 207
           jmp _printf
208
209
 
839 serge 210
include 'printf.inc'
854 serge 211
212
 
213
proc test_cpu
847 serge 214
           locals
215
              cpu_type   dd ?
216
              cpu_id     dd ?
217
              cpu_Intel  dd ?
218
              cpu_AMD    dd ?
219
           endl
220
221
 
222
           xor eax, eax
223
           mov [cpu_caps], eax
224
           mov [cpu_caps+4], eax
225
226
 
227
           cpuid
228
229
 
230
           mov [cpu_vendor+4], edx
231
           mov [cpu_vendor+8], ecx
232
           cmp ebx, dword [intel_str]
233
           jne .check_AMD
234
           cmp edx, dword [intel_str+4]
235
           jne .check_AMD
236
           cmp ecx, dword [intel_str+8]
237
           jne .check_AMD
238
           mov [cpu_Intel], 1
239
           cmp eax, 1
240
           jl .end_cpuid
241
           mov eax, 1
242
           cpuid
243
           mov [cpu_sign], eax
244
           mov [cpu_info],  ebx
245
           mov [cpu_caps],  edx
246
           mov [cpu_caps+4],ecx
247
248
 
249
           and eax, 0x0f
250
           ret
251
.end_cpuid:
252
           mov eax, [cpu_type]
253
           ret
254
255
 
256
           cmp ebx, dword [AMD_str]
257
           jne .unknown
258
           cmp edx, dword [AMD_str+4]
259
           jne .unknown
260
           cmp ecx, dword [AMD_str+8]
261
           jne .unknown
262
           mov [cpu_AMD], 1
263
           cmp eax, 1
264
           jl .unknown
265
           mov eax, 1
266
           cpuid
267
           mov [cpu_sign], eax
268
           mov [cpu_info],  ebx
269
           mov [cpu_caps],  edx
270
           mov [cpu_caps+4],ecx
271
           shr eax, 8
272
           and eax, 0x0f
273
           ret
274
.unknown:
275
           mov eax, 1
276
           cpuid
277
           mov [cpu_sign], eax
278
           mov [cpu_info],  ebx
279
           mov [cpu_caps],  edx
280
           mov [cpu_caps+4],ecx
281
           shr eax, 8
282
           and eax, 0x0f
283
           ret
284
endp
285
286
 
287
_copy_pg_balloc  dd 0
863 serge 288
289
 
290
 
851 serge 291
854 serge 292
 
742 Rus 293
           mov dx,app_data
847 serge 294
	   mov ss,ax
742 Rus 295
           mov esp, __os_stack
847 serge 296
1 ha 297
 
847 serge 298
           mov es, dx
299
           mov fs, dx
300
           mov gs, dx
301
1 ha 302
 
839 serge 303
 
847 serge 304
         ;  jnc @F
305
519 serge 306
 
847 serge 307
308
 
309
         ;  or ebx, CR4_PGE
310
         ;  mov cr4, ebx
311
@@:
519 serge 312
         ;  mov eax, cr3
847 serge 313
         ;  mov cr3, eax           ; flush TLB
314
465 serge 315
 
846 serge 316
           mov eax, 3
317
           out dx, al
318
319
 
847 serge 320
           call _init
321
839 serge 322
 
863 serge 323
           mov [_copy_pg_balloc], eax
324
325
 
841 serge 326
           mov [tss._esp0], __os_stack
847 serge 327
           mov [tss._esp], __os_stack
328
	   mov [tss._cs],os_code
841 serge 329
	   mov [tss._ss],os_stack
330
	   mov [tss._ds],app_data
331
	   mov [tss._es],app_data
332
	   mov [tss._fs],app_data
333
	   mov [tss._gs],app_data
334
	   mov [tss._io],128
335
;Add IO access table - bit array of permitted ports
336
	   mov edi, tss._io_map_0
337
	   xor eax, eax
338
	   not eax
339
	   mov ecx, 8192/4
340
	   rep stosd		     ; access to 4096*8=65536 ports
341
342
 
343
	   ltr	ax
344
345
 
863 serge 346
347
 
847 serge 348
           fastcall _balloc
349
           mov [_display_data], eax
350
351
 
352
                    (unpack.lc+unpack.lp)))*4
353
           fastcall _balloc
354
           mov [unpack.p], eax
355
356
 
357
358
 
843 serge 359
           mov [pg_data.pg_mutex], 0
360
839 serge 361
 
859 serge 362
363
 
364
           mov edx, 0x40000000
365
           call @init_heap@8
366
367
 
855 serge 368
           mov ecx, _16bit_end
369
           shr ecx, 2
851 serge 370
           mov edi, _16BIT_BASE
855 serge 371
           cld
848 serge 372
           rep movsd
373
847 serge 374
 
855 serge 375
376
 
848 serge 377
__setvars:
378
           mov ax,os_stack
379
           mov dx,app_data
380
	   mov ss,ax
381
           mov esp, __os_stack
382
383
 
384
           mov es, dx
385
           mov fs, dx
386
           mov gs, dx
387
388
 
389
390
 
859 serge 391
           xor esi, esi
848 serge 392
           mov   edi,BOOT_VAR
859 serge 393
           mov   ecx,0x10000 / 4
848 serge 394
           rep   movsd
395
861 serge 396
 
848 serge 397
           xor eax, eax
398
           mov   ecx,0x10000 / 4
399
           rep   stosd
400
401
 
861 serge 402
           mov ecx, (0x90000-0x40000)/4
403
           rep stosd
404
859 serge 405
 
406
           mov dword [_sys_pdbr+4], eax
407
           mov eax, cr3
408
           mov cr3, eax
409
410
 
1 ha 411
	mov	ax, [BOOT_VAR + 0x9031]
742 Rus 412
	mov	[IDEContrRegsBaseAddr], ax
413
; --------------- APM ---------------------
76 mario79 414
465 serge 415
 
416
    mov ebx,    [BOOT_VAR +0x9040]    ; offset of APM entry point
859 serge 417
    movzx eax, word [BOOT_VAR+0x9050] ; real-mode segment base address of
465 serge 418
				      ; protected-mode 32-bit code segment
742 Rus 419
    movzx ecx, word [BOOT_VAR+0x9052] ; real-mode segment base address of
465 serge 420
				      ; protected-mode 16-bit code segment
742 Rus 421
    movzx edx, word [BOOT_VAR+0x9054] ; real-mode segment base address of
465 serge 422
				      ; protected-mode 16-bit data segment
742 Rus 423
465 serge 424
 
425
    mov    [dword apm_code_32 + 2], ax
426
    shr    eax, 16
427
    mov    [dword apm_code_32 + 4], al
428
429
 
430
    mov    [dword apm_code_16 + 2], cx
431
    shr    ecx, 16
432
    mov    [dword apm_code_16 + 4], cl
433
434
 
435
    mov    [dword apm_data_16 + 2], dx
436
    shr    edx, 16
437
    mov    [dword apm_data_16 + 4], dl
438
439
 
440
    mov    word [apm_entry + 4], apm_code_32 - _gdts
851 serge 441
76 mario79 442
 
465 serge 443
    mov    [apm_vf], eax
76 mario79 444
; -----------------------------------------
445
;        movzx eax,byte [BOOT_VAR+0x9010]  ; mouse port
465 serge 446
;        mov   [0xF604],byte 1  ;al
1 ha 447
	mov	al, [BOOT_VAR+0x901F]	; DMA access
742 Rus 448
	mov	[allow_dma_access], al
449
	mov   al,[BOOT_VAR+0x9000]	  ; bpp
450
	mov   [ScreenBPP],al
451
753 serge 452
 
742 Rus 453
	dec   eax
454
	mov   [Screen_Max_X],eax
759 Rus 455
	mov   [screen_workarea.right],eax
742 Rus 456
	movzx eax,word [BOOT_VAR+0x900C]  ; Y max
457
	dec   eax
458
	mov   [Screen_Max_Y],eax
759 Rus 459
	mov   [screen_workarea.bottom],eax
742 Rus 460
	movzx eax,word [BOOT_VAR+0x9008]  ; screen mode
461
	mov   [SCR_MODE],eax
462
	mov   eax,[BOOT_VAR+0x9014]	  ; Vesa 1.2 bnk sw add
463
	mov   [BANK_SWITCH],eax
464
	mov   [BytesPerScanLine],word 640*4	    ; Bytes PerScanLine
465
	cmp   [SCR_MODE],word 0x13	    ; 320x200
466
	je    @f
467
	cmp   [SCR_MODE],word 0x12	    ; VGA 640x480
468
	je    @f
469
848 serge 470
 
742 Rus 471
	mov   [BytesPerScanLine],ax
472
@@:
465 serge 473
	mov	esi, BOOT_VAR+0x9080
742 Rus 474
	movzx	ecx, byte [esi-1]
475
	mov	[NumBiosDisks], ecx
476
	mov	edi, BiosDisksData
477
	rep	movsd
478
1 ha 479
 
480
481
 
742 Rus 482
	mov	eax,[BOOT_VAR+0x9018]
483
	mov	[LFBAddress],eax
484
1 ha 485
 
742 Rus 486
	jge	setvesa20
487
	cmp	[SCR_MODE],word 0x13
488
	je	v20ga32
489
	mov	[PUTPIXEL],dword Vesa12_putpixel24  ; Vesa 1.2
490
	mov	[GETPIXEL],dword Vesa12_getpixel24
491
	cmp	[ScreenBPP],byte 24
492
	jz	ga24
493
	mov	[PUTPIXEL],dword Vesa12_putpixel32
494
	mov	[GETPIXEL],dword Vesa12_getpixel32
495
      ga24:
1 ha 496
	jmp	v20ga24
742 Rus 497
      setvesa20:
1 ha 498
	mov	[PUTPIXEL],dword Vesa20_putpixel24  ; Vesa 2.0
742 Rus 499
	mov	[GETPIXEL],dword Vesa20_getpixel24
500
	cmp	[ScreenBPP],byte 24
501
	jz	v20ga24
502
      v20ga32:
1 ha 503
	mov	[PUTPIXEL],dword Vesa20_putpixel32
742 Rus 504
	mov	[GETPIXEL],dword Vesa20_getpixel32
505
      v20ga24:
1 ha 506
	cmp	[SCR_MODE],word 0x12		    ; 16 C VGA 640x480
742 Rus 507
	jne	no_mode_0x12
508
	mov	[PUTPIXEL],dword VGA_putpixel
509
	mov	[GETPIXEL],dword Vesa20_getpixel32
510
      no_mode_0x12:
1 ha 511
512
 
375 Ghost 513
; Intel SYSENTER/SYSEXIT (AMD CPU support it too)
378 serge 514
	   bt [cpu_caps], CAPS_SEP
742 Rus 515
	   jnc .SEnP   ; SysEnter not Present
516
	   xor edx, edx
517
	   mov ecx, MSR_SYSENTER_CS
518
	   mov eax, os_code
519
	   wrmsr
520
	   mov ecx, MSR_SYSENTER_ESP
521
;           mov eax, sysenter_stack ; Check it
434 diamond 522
	   xor	   eax, eax
742 Rus 523
	   wrmsr
524
	   mov ecx, MSR_SYSENTER_EIP
525
	   mov eax, sysenter_entry
526
	   wrmsr
527
.SEnP:
375 Ghost 528
; AMD SYSCALL/SYSRET
378 serge 529
	   cmp byte[cpu_vendor], 'A'
742 Rus 530
	   jne .noSYSCALL
531
	   mov eax, 0x80000001
532
	   cpuid
533
	   test edx, 0x800  ; bit_11 - SYSCALL/SYSRET support
534
	   jz .noSYSCALL
535
	   mov ecx, MSR_AMD_EFER
536
	   rdmsr
537
	   or eax, 1   ; bit_0 - System Call Extension (SCE)
538
	   wrmsr
539
164 serge 540
 
375 Ghost 541
	; Bits of EDX :
542
	; Bit 31–16 During the SYSRET instruction, this field is copied into the CS register
543
	;  and the contents of this field, plus 8, are copied into the SS register.
544
	; Bit 15–0 During the SYSCALL instruction, this field is copied into the CS register
545
	;  and the contents of this field, plus 8, are copied into the SS register.
546
547
 
742 Rus 548
	   mov edx, 0x1B0008
549
375 Ghost 550
 
742 Rus 551
	   mov ecx, MSR_AMD_STAR
552
	   wrmsr
553
.noSYSCALL:
375 Ghost 554
; -----------------------------------------
555
; LOAD IDT
465 serge 556
378 serge 557
 
854 serge 558
378 serge 559
 
841 serge 560
	   call init_LFB
742 Rus 561
           call init_fpu
841 serge 562
           call init_malloc
854 serge 563
276 serge 564
 
864 serge 565
           xor edx, edx
566
           call @mem_alloc@8
567
	   mov [default_io_map], eax
742 Rus 568
465 serge 569
 
742 Rus 570
	   mov [ipc_tmp], eax
571
	   mov ebx, 0x1000
572
164 serge 573
 
742 Rus 574
	   mov [proc_mem_map], eax
575
164 serge 576
 
742 Rus 577
	   mov [proc_mem_pdir], eax
578
164 serge 579
 
742 Rus 580
	   mov [proc_mem_tab], eax
581
164 serge 582
 
742 Rus 583
	   mov [tmp_task_pdir], eax
584
164 serge 585
 
742 Rus 586
	   mov [tmp_task_ptab], eax
587
164 serge 588
 
742 Rus 589
	   mov [ipc_pdir], eax
590
164 serge 591
 
742 Rus 592
	   mov [ipc_ptab], eax
593
164 serge 594
 
742 Rus 595
	   mov eax, srv.fd-SRV_FD_OFFSET
596
	   mov [srv.fd], eax
597
	   mov [srv.bk], eax
598
278 serge 599
 
742 Rus 600
	   xor eax, eax
601
	   mov ecx, 16
602
	   rep stosd
603
164 serge 604
 
41 mikedld 605
	mov	eax,[LFBAddress]	  ; set for gs
742 Rus 606
	mov	[graph_data_l+2],ax
607
	shr	eax,16
608
	mov	[graph_data_l+4],al
609
	mov	[graph_data_l+7],ah
610
1 ha 611
 
742 Rus 612
	mov [TASK_COUNT],dword 1
613
	mov [TASK_BASE],dword TASK_DATA
614
	mov [current_slot], SLOT_BASE+256
615
429 serge 616
 
469 serge 617
	xor  eax,eax
742 Rus 618
	inc  eax
619
	mov   [BgrDrawMode],eax
620
	mov   [BgrDataWidth],eax
621
	mov   [BgrDataHeight],eax
622
        mov ecx, 4095
864 serge 623
        mov edx, PG_SW
624
	mov    [mem_BACKGROUND],4095
742 Rus 625
        call @mem_alloc@8
864 serge 626
	mov [img_background], eax
742 Rus 627
469 serge 628
 
854 serge 629
469 serge 630
 
709 diamond 631
632
 
742 Rus 633
709 diamond 634
 
635
        call    init_sys_v86
861 serge 636
709 diamond 637
 
725 diamond 638
639
 
742 Rus 640
	out   0x43,al
641
	mov   al,0x9b		   ; lsb    1193180 / 1193
642
	out   0x40,al
643
	mov   al,0x2e		   ; msb
644
	out   0x40,al
645
725 diamond 646
 
647
; they are used: when partitions are scanned, hd_read relies on timer
648
	mov	al, 0xFE
742 Rus 649
	out	0x21, al
650
	mov	al, 0x3F
651
	out	0xA1, al
652
725 diamond 653
 
256 diamond 654
include 'detect/disks.inc'
655
;!!!!!!!!!!!!!!!!!!!!!!!!!!
656
657
 
521 diamond 658
659
 
1 ha 660
661
 
662
;include 'boot/rdload.inc'
846 serge 663
;!!!!!!!!!!!!!!!!!!!!!!!
1 ha 664
;    mov    [dma_hdd],1
665
; CALCULATE FAT CHAIN FOR RAMDISK
666
667
 
742 Rus 668
1 ha 669
 
670
 
847 serge 671
 ; cmp ax,'r1'           ; if using not ram disk, then load librares and parameters {SPraid.simba}
672
 ; je  no_lib_load
673
; LOADING LIBRARES
488 spraid 674
;   stdcall dll.Load,@IMPORT                 ; loading librares for kernel (.obj files)
847 serge 675
;   call load_file_parse_table               ; prepare file parse table
676
;   call set_kernel_conf                     ; configure devices and gui
677
;no_lib_load:
678
488 spraid 679
 
1 ha 680
681
 
742 Rus 682
        stdcall read_file, char2, FONT_II, 0, 2560
848 serge 683
490 serge 684
 
742 Rus 685
	call  boot_log
686
1 ha 687
 
688
	mov	esi, boot_memdetect
742 Rus 689
	call	boot_log
690
1 ha 691
 
742 Rus 692
	or	ecx, (10+29*6) shl 16 ; "Determining amount of memory"
693
	sub	ecx, 10
694
	mov	edx, 0xFFFFFF
695
        mov     ebx, [_mem_amount]
846 serge 696
	shr	ebx, 20
742 Rus 697
	mov	edi, 1
698
	mov	eax, 0x00040000
699
	call	display_number_force
700
41 mikedld 701
 
465 serge 702
703
 
742 Rus 704
465 serge 705
 
742 Rus 706
	call   boot_log
707
567 serge 708
 
742 Rus 709
567 serge 710
 
1 ha 711
 
712
713
 
742 Rus 714
	call  boot_log
715
	call  setwindowdefaults
716
1 ha 717
 
718
719
 
742 Rus 720
	call  boot_log
721
	call  init_background
722
	call  calculatebackground
723
1 ha 724
 
725
726
 
742 Rus 727
	call  boot_log
728
	call  reserve_irqs_ports
729
1 ha 730
 
731
732
 
742 Rus 733
	call boot_log
734
	;call setirqreadports
769 Rus 735
1 ha 736
 
737
738
 
742 Rus 739
	call boot_log
740
214 serge 741
 
742 Rus 742
	mov  dword [SLOT_BASE+APPDATA.fpu_state], fpu_data
743
	mov  dword [SLOT_BASE+APPDATA.fpu_handler], eax
744
	mov  dword [SLOT_BASE+APPDATA.sse_handler], eax
745
164 serge 746
 
742 Rus 747
281 serge 748
 
742 Rus 749
	mov dword [SLOT_BASE+256+APPDATA.app_name+4], dword 'DLE '
750
        mov edi,  __os_stack-8192+512
847 serge 751
	mov dword [SLOT_BASE+256+APPDATA.pl0_stack], edi
742 Rus 752
	add edi, 0x2000-512
753
	mov dword [SLOT_BASE+256+APPDATA.fpu_state], edi
754
	mov dword [SLOT_BASE+256+APPDATA.saved_esp0], edi ; just for case
755
	mov dword [SLOT_BASE+256+APPDATA.io_map],\
756
		  (tss._io_map_0-OS_BASE+PG_MAP)
757
	mov dword [SLOT_BASE+256+APPDATA.io_map+4],\
758
		  (tss._io_map_1-OS_BASE+PG_MAP)
759
357 serge 760
 
742 Rus 761
	mov ecx, 512/4
762
	cld
763
	rep movsd
764
357 serge 765
 
843 serge 766
	mov dword [SLOT_BASE+256+APPDATA.sse_handler], eax
742 Rus 767
214 serge 768
 
742 Rus 769
	mov  dword [SLOT_BASE+256+APPDATA.fd_obj], ebx
770
	mov  dword [SLOT_BASE+256+APPDATA.bk_obj], ebx
771
281 serge 772
 
742 Rus 773
521 diamond 774
 
742 Rus 775
	mov  [CURRENT_TASK],dword 1
776
	mov  [TASK_COUNT],dword 1
777
	mov  [current_slot], SLOT_BASE+256
778
	mov  [TASK_BASE],dword TASK_DATA
779
	mov  [TASK_DATA+TASKDATA.wnd_number], 1 ; on screen number
780
	mov  [TASK_DATA+TASKDATA.pid], 1	; process id number
781
	mov  [TASK_DATA+TASKDATA.mem_start], 0	; process base address
782
1 ha 783
 
843 serge 784
        mov eax, [def_cursor]
802 serge 785
	mov [SLOT_BASE+APPDATA.cursor],eax
742 Rus 786
	mov [SLOT_BASE+APPDATA.cursor+256],eax
787
281 serge 788
 
889 serge 789
        ;call @load_pe_driver@4
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
861 serge 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
887 serge 2291
 
2292
    call @mem_free@4
2293
2294
 
469 serge 2295
    xor  eax,eax
2296
    inc  eax
2297
    cmp  [BgrDataWidth],eax
527 diamond 2298
    jae   @f
469 serge 2299
    mov [BgrDataWidth],eax
527 diamond 2300
@@:
469 serge 2301
    cmp  [BgrDataHeight],eax
527 diamond 2302
    jae   @f
469 serge 2303
    mov [BgrDataHeight],eax
527 diamond 2304
@@:
469 serge 2305
    mov  eax,[BgrDataWidth]
527 diamond 2306
    imul eax,[BgrDataHeight]
2307
    lea  ecx,[eax*3]
864 serge 2308
    mov  [mem_BACKGROUND],ecx
2309
; get memory for new background
469 serge 2310
    mov edx, PG_SW
864 serge 2311
    stdcall @mem_alloc@8
2312
    test eax, eax
469 serge 2313
    jz .exit_mem
2314
    mov [img_background], eax
2315
.exit_mem:
2316
    popad
2317
	mov	[bgrlock], 0
742 Rus 2318
469 serge 2319
 
1 ha 2320
    ret
2321
469 serge 2322
 
861 serge 2323
1 ha 2324
 
742 Rus 2325
    jnz   nosb2
1 ha 2326
862 serge 2327
 
861 serge 2328
    add ebx, 4095
2329
    and ebx, -4096
2330
    sub ebx, 4
2331
    cmp   ecx, ebx
2332
    ja   @F
2333
2334
 
469 serge 2335
    mov   ebx,[eax+ecx]
684 diamond 2336
    and   ebx,0xFF000000 ;255*256*256*256
2337
    and   edx,0x00FFFFFF ;255*256*256+255*256+255
2338
    add   edx,ebx
2339
    mov   [eax+ecx],edx
2340
@@:
861 serge 2341
    ret
1 ha 2342
2343
 
861 serge 2344
2345
 
742 Rus 2346
    jnz   nosb3
1 ha 2347
draw_background_temp:
2348
;    cmp   [bgrchanged],1 ;0
2349
;    je    nosb31
2350
;draw_background_temp:
2351
;    mov   [bgrchanged],1 ;0
2352
    mov    [background_defined], 1
76 mario79 2353
    call  force_redraw_background
709 diamond 2354
    mov    [REDRAW_BACKGROUND], byte 2
2355
   nosb31:
1 ha 2356
    ret
2357
  nosb3:
2358
2359
 
742 Rus 2360
    jnz   nosb4
1 ha 2361
    cmp   ecx,[BgrDrawMode]
684 diamond 2362
    je	  nosb41
742 Rus 2363
    mov   [BgrDrawMode],ecx
684 diamond 2364
;    mov   [bgrchanged],1
1 ha 2365
   nosb41:
2366
    ret
2367
  nosb4:
2368
2369
 
742 Rus 2370
    jnz   nosb5
1 ha 2371
  ; bughere
2372
    mov   eax, ecx
684 diamond 2373
    mov   ebx, edx
2374
    add   ebx, [img_background]   ;IMG_BACKGROUND
469 serge 2375
    mov   ecx, esi
684 diamond 2376
    call  memmove
1 ha 2377
  .fin:
2378
    ret
2379
  nosb5:
2380
479 kastigar 2381
 
742 Rus 2382
	jnz	nosb6
2383
@@:
546 diamond 2384
	mov	al, 1
742 Rus 2385
	xchg	[bgrlock], al
2386
	test	al, al
2387
	jz	@f
2388
	call	change_task
2389
	jmp	@b
2390
@@:
546 diamond 2391
	mov	eax, [CURRENT_TASK]
742 Rus 2392
	mov	[bgrlockpid], eax
2393
	stdcall user_alloc, [mem_BACKGROUND]
2394
	mov	[esp+32], eax
2395
	test	eax, eax
2396
	jz	.nomem
2397
	mov	ebx, eax
2398
	shr	ebx, 12
2399
	or	dword [page_tabs+(ebx-1)*4], DONT_FREE_BLOCK
2400
	mov	esi, [img_background]
2401
	shr	esi, 12
2402
	mov	ecx, [mem_BACKGROUND]
2403
	add	ecx, 0xFFF
2404
	shr	ecx, 12
2405
.z:
546 diamond 2406
	mov	eax, [page_tabs+esi*4]
742 Rus 2407
	or	al, PG_UW
2408
	mov	[page_tabs+ebx*4], eax
2409
	mov	eax, ebx
2410
	shl	eax, 12
2411
	invlpg	[eax]
2412
	inc	ebx
2413
	inc	esi
2414
	loop	.z
2415
	ret
2416
.nomem:
546 diamond 2417
	and	[bgrlockpid], 0
742 Rus 2418
	mov	[bgrlock], 0
2419
nosb6:
546 diamond 2420
	cmp	ebx, 7
742 Rus 2421
	jnz	nosb7
2422
	cmp	[bgrlock], 0
2423
	jz	.err
2424
	mov	eax, [CURRENT_TASK]
2425
	cmp	[bgrlockpid], eax
2426
	jnz	.err
2427
	mov	eax, ecx
2428
	mov	ebx, ecx
2429
	shr	eax, 12
2430
	mov	ecx, [page_tabs+(eax-1)*4]
2431
	test	cl, USED_BLOCK+DONT_FREE_BLOCK
2432
	jz	.err
2433
	jnp	.err
2434
	push	eax
2435
	shr	ecx, 12
2436
@@:
546 diamond 2437
	and	dword [page_tabs+eax*4], 0
742 Rus 2438
	mov	edx, eax
2439
	shl	edx, 12
2440
        push eax
802 serge 2441
	invlpg	[edx]
742 Rus 2442
        pop eax
802 serge 2443
	inc	eax
742 Rus 2444
	loop	@b
2445
	pop	eax
2446
	and	dword [page_tabs+(eax-1)*4], not DONT_FREE_BLOCK
2447
	stdcall user_free, ebx
2448
	mov	[esp+32], eax
2449
	and	[bgrlockpid], 0
2450
	mov	[bgrlock], 0
2451
	ret
2452
.err:
546 diamond 2453
	and	dword [esp+32], 0
742 Rus 2454
	ret
2455
546 diamond 2456
 
2457
    ret
1 ha 2458
2459
 
709 diamond 2460
    mov   [draw_data+32 + RECT.left],dword 0
2461
    mov   [draw_data+32 + RECT.top],dword 0
2462
    push  eax ebx
2463
    mov   eax,[Screen_Max_X]
753 serge 2464
    mov   ebx,[Screen_Max_Y]
2465
    mov   [draw_data+32 + RECT.right],eax
709 diamond 2466
    mov   [draw_data+32 + RECT.bottom],ebx
2467
    pop   ebx eax
2468
    mov   byte [REDRAW_BACKGROUND], 1
2469
    ret
2470
479 kastigar 2471
 
1 ha 2472
2473
 
2474
2475
 
742 Rus 2476
    jnz   nogb1
1 ha 2477
    mov   eax,[BgrDataWidth]
527 diamond 2478
    shl   eax,16
1 ha 2479
    mov   ax,[BgrDataHeight]
531 diamond 2480
    mov   [esp+36],eax
1 ha 2481
    ret
2482
2483
 
861 serge 2484
2485
 
742 Rus 2486
    jnz   nogb2
1 ha 2487
862 serge 2488
 
861 serge 2489
    add ecx, 4095
2490
    and ecx, -4096
2491
    sub ecx, 4
2492
    cmp ebx, ecx
2493
    ja  @F
2494
2495
 
469 serge 2496
    mov   eax,[ebx+eax]
2497
2498
 
1 ha 2499
    mov   [esp+36],eax
2500
@@:
861 serge 2501
    ret
1 ha 2502
862 serge 2503
 
1 ha 2504
2505
 
742 Rus 2506
    jnz   nogb4
1 ha 2507
    mov   eax,[BgrDrawMode]
527 diamond 2508
  nogb4:
1 ha 2509
    mov   [esp+36],eax
2510
    ret
2511
2512
 
2513
 
2514
2515
 
2516
	mov	[esp + 32],dword 1
671 Ghost 2517
	; test main buffer
2518
	mov	ebx, [CURRENT_TASK]			     ; TOP OF WINDOW STACK
742 Rus 2519
	movzx	ecx, word [WIN_STACK + ebx * 2]
671 Ghost 2520
	mov	edx, [TASK_COUNT]
2521
	cmp	ecx, edx
2522
	jne	.finish
2523
	cmp	[KEY_COUNT], byte 0
2524
	je	.finish
2525
	movzx	eax, byte [KEY_BUFF]
2526
	shl	eax, 8
2527
	push	eax
2528
	dec	byte [KEY_COUNT]
2529
	and	byte [KEY_COUNT], 127
2530
	movzx	ecx, byte [KEY_COUNT]
2531
	add	ecx, 2
2532
	mov	eax, KEY_BUFF + 1
2533
	mov	ebx, KEY_BUFF
2534
	call	memmove
2535
	pop	eax
2536
.ret_eax:
92 diamond 2537
	mov	[esp + 32], eax
671 Ghost 2538
	ret
2539
.finish:
2540
; test hotkeys buffer
92 diamond 2541
	mov	ecx, hotkey_buffer
671 Ghost 2542
@@:
92 diamond 2543
	cmp	[ecx], ebx
671 Ghost 2544
	jz	.found
2545
	add	ecx, 8
2546
	cmp	ecx, hotkey_buffer + 120 * 8
2547
	jb	@b
2548
	ret
2549
.found:
92 diamond 2550
	mov	ax, [ecx + 6]
671 Ghost 2551
	shl	eax, 16
2552
	mov	ah, [ecx + 4]
2553
	mov	al, 2
2554
	and	dword [ecx + 4], 0
2555
	and	dword [ecx], 0
2556
	jmp	.ret_eax
2557
1 ha 2558
 
2559
2560
 
2561
2562
 
742 Rus 2563
	mov	[esp + 32], dword 1
671 Ghost 2564
	movzx	ecx, word [WIN_STACK + ebx * 2]
2565
	mov	edx, [TASK_COUNT] ; less than 256 processes
2566
	cmp	ecx, edx
2567
	jne	.exit
2568
	movzx	eax, byte [BTN_COUNT]
2569
	test	eax, eax
2570
	jz	.exit
2571
	mov	eax, [BTN_BUFF]
2572
	shl	eax, 8
2573
; // Alver 22.06.2008 // {
803 alver 2574
        mov       al, byte [btn_down_determ]
2575
        and       al,0xFE                                       ; delete left button bit
2576
; } \\ Alver \\
2577
	mov	[BTN_COUNT], byte 0
671 Ghost 2578
	mov	[esp + 32], eax
2579
.exit:
2580
	ret
2581
1 ha 2582
 
2583
 
2584
2585
 
2586
2587
 
2588
;
2589
;  +00 dword     process cpu usage
2590
;  +04  word     position in windowing stack
2591
;  +06  word     windowing stack value at current position (cpu nro)
2592
;  +10 12 bytes  name
2593
;  +22 dword     start in mem
2594
;  +26 dword     used mem
2595
;  +30 dword     PID , process idenfification number
2596
;
2597
2598
 
742 Rus 2599
    jne  .no_who_am_i
684 diamond 2600
    mov  ecx,[CURRENT_TASK]
2601
  .no_who_am_i:
2602
	cmp	ecx, max_processes
742 Rus 2603
	ja	.nofillbuf
2604
1 ha 2605
 
684 diamond 2606
	mov	ax, [WIN_STACK + ecx * 2]
742 Rus 2607
	mov	[ebx+4], ax
2608
; +6: word: number of the thread slot, which window has in the window stack
684 diamond 2609
;           position ecx (has no relation to the specific thread)
2610
	mov	ax, [WIN_POS + ecx * 2]
742 Rus 2611
	mov	[ebx+6], ax
2612
1 ha 2613
 
742 Rus 2614
1 ha 2615
 
684 diamond 2616
	mov	eax, [ecx+CURRENT_TASK+TASKDATA.cpu_usage]
742 Rus 2617
	mov	[ebx], eax
2618
; +10: 11 bytes: name of the process
684 diamond 2619
	push	ecx
742 Rus 2620
	lea	eax, [ecx*8+SLOT_BASE+APPDATA.app_name]
2621
	add	ebx, 10
2622
	mov	ecx, 11
2623
	call	memmove
2624
	pop	ecx
2625
1 ha 2626
 
684 diamond 2627
; +26: size of used memory - 1
2628
	push	edi
742 Rus 2629
	lea	edi, [ebx+12]
2630
	xor	eax, eax
2631
	mov	edx, 0x100000*16
2632
	cmp	ecx, 1 shl 5
2633
	je	.os_mem
2634
	mov	edx, [SLOT_BASE+ecx*8+APPDATA.mem_size]
2635
        xor eax, eax
840 serge 2636
.os_mem:
684 diamond 2637
	stosd
742 Rus 2638
	lea	eax, [edx-1]
2639
	stosd
2640
1 ha 2641
 
684 diamond 2642
	mov	eax, [ecx+CURRENT_TASK+TASKDATA.pid]
742 Rus 2643
	stosd
2644
1 ha 2645
 
2646
	push	esi
742 Rus 2647
	lea	esi, [ecx + window_data + WDATA.box]
2648
	movsd
2649
	movsd
2650
	movsd
2651
	movsd
2652
1 ha 2653
 
2654
	mov	eax, dword [ecx+CURRENT_TASK+TASKDATA.state]
742 Rus 2655
	stosd
2656
1 ha 2657
 
138 mikedld 2658
	lea	esi, [ecx*8 + SLOT_BASE + APPDATA.wnd_clientbox]
742 Rus 2659
	movsd
2660
	movsd
2661
	movsd
2662
	movsd
2663
1 ha 2664
 
164 serge 2665
	mov	al, [ecx+window_data+WDATA.fl_wstate]
742 Rus 2666
	stosb
2667
164 serge 2668
 
742 Rus 2669
	pop	edi
2670
138 mikedld 2671
 
684 diamond 2672
    ; return number of processes
1 ha 2673
2674
 
379 serge 2675
    mov    [esp+32],eax
684 diamond 2676
    ret
1 ha 2677
2678
 
2679
sys_clock:
2680
	cli
742 Rus 2681
  ; Mikhail Lisovin  xx Jan 2005
1 ha 2682
  @@:	mov   al, 10
742 Rus 2683
	out   0x70, al
2684
	in    al, 0x71
2685
	test  al, al
2686
	jns   @f
2687
	mov   esi, 1
2688
	call  delay_ms
2689
	jmp   @b
2690
  @@:
1 ha 2691
  ; end Lisovin's fix
2692
2693
 
742 Rus 2694
	out   0x70,al
2695
	in    al,0x71
2696
	movzx ecx,al
2697
	mov   al,02	      ; minutes
2698
	shl   ecx,16
2699
	out   0x70,al
2700
	in    al,0x71
2701
	movzx edx,al
2702
	mov   al,04	      ; hours
2703
	shl   edx,8
2704
	out   0x70,al
2705
	in    al,0x71
2706
	add   ecx,edx
2707
	movzx edx,al
2708
	add   ecx,edx
2709
	sti
2710
	mov	[esp + 32], ecx
671 Ghost 2711
	ret
742 Rus 2712
1 ha 2713
 
2714
 
2715
2716
 
2717
2718
 
742 Rus 2719
  @@:	mov   al, 10
2720
	out   0x70, al
2721
	in    al, 0x71
2722
	test  al, al
2723
	jns   @f
2724
	mov   esi, 1
2725
	call  delay_ms
2726
	jmp   @b
2727
  @@:
75 diamond 2728
2729
 
742 Rus 2730
	mov	al,7		; date
2731
	out	0x70,al
2732
	in	al,0x71
2733
	mov	cl,al
2734
	mov	al,8		; month
2735
	shl	ecx,16
2736
	out	0x70,al
2737
	in	al,0x71
2738
	mov	ch,al
2739
	mov	al,9		; year
2740
	out	0x70,al
2741
	in	al,0x71
2742
	mov	cl,al
2743
	sti
2744
	mov	[esp+32], ecx
2745
	ret
2746
1 ha 2747
 
2748
 
2749
2750
 
2751
	cmp	ebx, 1
671 Ghost 2752
	jne	no_widgets_away
2753
	; buttons away
2754
	mov	ecx,[CURRENT_TASK]
2755
  sys_newba2:
1 ha 2756
	mov	edi,[BTN_ADDR]
671 Ghost 2757
	cmp	[edi], dword 0	; empty button list ?
742 Rus 2758
	je	end_of_buttons_away
671 Ghost 2759
	movzx	ebx, word [edi]
2760
	inc	ebx
2761
	mov	eax,edi
2762
  sys_newba:
1 ha 2763
	dec	ebx
671 Ghost 2764
	jz	end_of_buttons_away
2765
1 ha 2766
 
671 Ghost 2767
	cmp	cx, [eax]
2768
	jnz	sys_newba
2769
1 ha 2770
 
671 Ghost 2771
	mov	ecx,ebx
2772
	inc	ecx
2773
	shl	ecx, 4
2774
	mov	ebx, eax
2775
	add	eax, 0x10
2776
	call	memmove
2777
	dec	dword [edi]
2778
	pop	ecx ebx eax
2779
1 ha 2780
 
671 Ghost 2781
1 ha 2782
 
2783
2784
 
671 Ghost 2785
1 ha 2786
 
2787
2788
 
671 Ghost 2789
	jnz	srl1
2790
1 ha 2791
 
671 Ghost 2792
	add	edx, draw_data - CURRENT_TASK
2793
	mov	[edx + RECT.left], 0
2794
	mov	[edx + RECT.top], 0
2795
	mov	eax, [Screen_Max_X]
759 Rus 2796
	mov	[edx + RECT.right], eax
671 Ghost 2797
	mov	eax, [Screen_Max_Y]
759 Rus 2798
	mov	[edx + RECT.bottom], eax
671 Ghost 2799
1 ha 2800
 
671 Ghost 2801
	or	[edi - twdw + WDATA.fl_wdrawn], 1   ; no new position & buttons from app
2802
	call	sys_window_mouse
2803
	ret
2804
1 ha 2805
 
2806
	ret
671 Ghost 2807
1 ha 2808
 
2809
 
2810
2811
 
684 diamond 2812
    shr   eax,16+8
2813
    and   eax,15
2814
1 ha 2815
 
684 diamond 2816
    jne   nosyswI
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  drawwindow_I
1 ha 2822
    ;dec   [mouse_pause]
114 mikedld 2823
    ;call   [draw_pointer]
2824
    ;ret
2825
    jmp   draw_window_caption.2
2826
  nosyswI:
1 ha 2827
2828
 
742 Rus 2829
    jne   nosyswII
1 ha 2830
    inc   [mouse_pause]
33 mario79 2831
    call  [disable_mouse]
36 mario79 2832
    call  sys_set_window
1 ha 2833
    call  [disable_mouse]
36 mario79 2834
    call  sys_window_mouse
1 ha 2835
    dec   [mouse_pause]
33 mario79 2836
    call   [draw_pointer]
36 mario79 2837
    ret
1 ha 2838
  nosyswII:
2839
2840
 
742 Rus 2841
    jne   nosyswIII
1 ha 2842
    inc   [mouse_pause]
33 mario79 2843
    call  [disable_mouse]
36 mario79 2844
    call  sys_set_window
1 ha 2845
    call  [disable_mouse]
36 mario79 2846
    call  drawwindow_III
1 ha 2847
    ;dec   [mouse_pause]
114 mikedld 2848
    ;call   [draw_pointer]
2849
    ;ret
2850
    jmp   draw_window_caption.2
2851
  nosyswIII:
1 ha 2852
2853
 
742 Rus 2854
    je	  draw_skin_window
2855
    cmp   al,4	  ; type V - skinned window not sized! {not_sized_skin_window}
2856
    jne   nosyswV
549 spraid 2857
  draw_skin_window:
2858
567 serge 2859
 
569 diamond 2860
    call  [disable_mouse]
2861
    call  sys_set_window
2862
    call  [disable_mouse]
2863
    mov   eax, [TASK_COUNT]
684 diamond 2864
    movzx eax, word [WIN_POS + eax*2]
2865
    cmp   eax, [CURRENT_TASK]
2866
    setz  al
2867
    movzx eax, al
2868
    push  eax
2869
    call  drawwindow_IV
36 mario79 2870
    ;dec   [mouse_pause]
114 mikedld 2871
    ;call   [draw_pointer]
2872
    ;ret
2873
    jmp   draw_window_caption.2
2874
  nosyswV:
549 spraid 2875
1 ha 2876
 
2877
2878
 
2879
 
114 mikedld 2880
	inc	[mouse_pause]
742 Rus 2881
	call	[disable_mouse]
2882
114 mikedld 2883
 
742 Rus 2884
	mov	edx,[TASK_COUNT]
2885
	movzx	edx,word[WIN_POS+edx*2]
2886
	cmp	edx,[CURRENT_TASK]
2887
	jne	@f
2888
	inc	eax
2889
    @@: mov	edx,[CURRENT_TASK]
2890
	shl	edx,5
2891
	add	edx,window_data
2892
	movzx	ebx,[edx+WDATA.fl_wstyle]
2893
	and	bl,0x0F
2894
	cmp	bl,3
2895
	je	.draw_caption_style_3		;{for 3 and 4 style write caption}
2896
	cmp	bl,4
2897
	je	.draw_caption_style_3
2898
567 serge 2899
 
742 Rus 2900
  .draw_caption_style_3:
549 spraid 2901
114 mikedld 2902
 
742 Rus 2903
	call	drawwindow_IV_caption
2904
	add	esp,4
2905
	jmp	.2
2906
114 mikedld 2907
 
2908
	cmp	bl,2
742 Rus 2909
	jne	.not_style_2
2910
114 mikedld 2911
 
742 Rus 2912
	jmp	.2
2913
114 mikedld 2914
 
2915
	cmp	bl,0
742 Rus 2916
	jne	.2
2917
114 mikedld 2918
 
742 Rus 2919
114 mikedld 2920
 
2921
  .2:	;jmp     @f
742 Rus 2922
	mov	edi,[CURRENT_TASK]
2923
	shl	edi,5
2924
	test	[edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
2925
	jz	@f
2926
	mov	edx,[edi*8+SLOT_BASE+APPDATA.wnd_caption]
2927
	or	edx,edx
2928
	jz	@f
2929
114 mikedld 2930
 
742 Rus 2931
	and	al,0x0F
2932
	cmp	al,3
2933
	je	.skinned
2934
	cmp	al,4
2935
	je	.skinned
2936
567 serge 2937
 
742 Rus 2938
  .skinned:
567 serge 2939
	mov	ebp,[edi+window_data+WDATA.box.left-2]
742 Rus 2940
	mov	bp,word[edi+window_data+WDATA.box.top]
2941
	movzx	eax,word[edi+window_data+WDATA.box.width]
2942
	sub	ax,[_skinmargins.left]
2943
	sub	ax,[_skinmargins.right]
2944
	push	edx
2945
	cwde
2946
	cdq
2947
	mov	ebx,6
2948
	idiv	ebx
2949
	pop	edx
2950
	or	eax,eax
2951
	js	@f
2952
	mov	esi,eax
2953
	mov	ebx,dword[_skinmargins.left-2]
2954
	mov	bx,word[_skinh]
2955
	sub	bx,[_skinmargins.bottom]
2956
	sub	bx,[_skinmargins.top]
2957
	sar	bx,1
2958
	adc	bx,0
2959
	add	bx,[_skinmargins.top]
2960
	add	bx,-3
2961
	add	ebx,ebp
2962
	jmp	.dodraw
2963
114 mikedld 2964
 
2965
	cmp	al,1
742 Rus 2966
	je	@f
2967
114 mikedld 2968
 
742 Rus 2969
	mov	bp,word[edi+window_data+WDATA.box.top]
2970
	movzx	eax,word[edi+window_data+WDATA.box.width]
2971
	sub	eax,16
2972
	push	edx
2973
	cwde
2974
	cdq
2975
	mov	ebx,6
2976
	idiv	ebx
2977
	pop	edx
2978
	or	eax,eax
2979
	js	@f
2980
	mov	esi,eax
2981
	mov	ebx,0x00080007
2982
	add	ebx,ebp
2983
.dodraw:
139 diamond 2984
	mov	ecx,[common_colours+16];0x00FFFFFF
742 Rus 2985
	or	ecx, 0x80000000
2986
	xor	edi,edi
2987
; // Alver 22.06.2008 // {
803 alver 2988
;	call	dtext
2989
        call dtext_asciiz_esi
2990
; } \\ Alver \\
2991
114 mikedld 2992
 
2993
;--------------------------------------------------------------
2994
	dec	[mouse_pause]
742 Rus 2995
	call	[draw_pointer]
2996
	ret
2997
114 mikedld 2998
 
2999
align 4
3000
window_topleft dd \
3001
  1, 21,\		;type 0
549 spraid 3002
  0,  0,\	;type 1
742 Rus 3003
  5, 20,\	;type 2
3004
  5,  ?,\	;type 3 {set by skin}
3005
  5,  ? 	;type 4 {set by skin}
3006
endg
114 mikedld 3007
3008
 
3009
	push	eax ecx edi
742 Rus 3010
114 mikedld 3011
 
742 Rus 3012
	mov	[window_topleft+4*7],eax
3013
	mov	[window_topleft+4*9],eax
3014
114 mikedld 3015
 
742 Rus 3016
	sub	edi,window_data
3017
	shl	edi,3
3018
	test	[ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE
3019
	jz	@f
3020
114 mikedld 3021
 
742 Rus 3022
	and	eax,0x0F
3023
	mov	eax,[eax*8+window_topleft+0]
3024
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3025
	shl	eax,1
3026
	neg	eax
3027
	add	eax,[ecx+WDATA.box.width]
3028
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
3029
114 mikedld 3030
 
742 Rus 3031
	and	eax,0x0F
3032
	push	[eax*8+window_topleft+0]
3033
	mov	eax,[eax*8+window_topleft+4]
3034
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3035
	neg	eax
3036
	sub	eax,[esp]
3037
	add	eax,[ecx+WDATA.box.height]
3038
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3039
	add	esp,4
3040
114 mikedld 3041
 
742 Rus 3042
	ret
3043
    @@:
114 mikedld 3044
	xor	eax,eax
742 Rus 3045
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3046
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3047
	mov	eax,[ecx+WDATA.box.width]
3048
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
3049
	mov	eax,[ecx+WDATA.box.height]
3050
	mov	[edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3051
114 mikedld 3052
 
742 Rus 3053
	ret
3054
114 mikedld 3055
 
1 ha 3056
3057
 
684 diamond 3058
    shl   eax,5
3059
    add   eax,window_data
3060
1 ha 3061
 
3062
    mov   [eax+WDATA.cl_workarea],edx
684 diamond 3063
    mov   [eax+WDATA.cl_titlebar],esi
3064
    mov   [eax+WDATA.cl_frames],edi
3065
1 ha 3066
 
684 diamond 3067
3068
 
1 ha 3069
    test  [edi+WDATA.fl_wdrawn],1
186 diamond 3070
    jnz   newd
3071
1 ha 3072
 
3073
    add   eax,100
3074
    mov   [new_window_starting],eax
3075
3076
 
860 serge 3077
    mov   [edi+WDATA.box.width],eax
3078
    movsx eax,cx
3079
    mov   [edi+WDATA.box.height],eax
3080
    sar   ebx,16
114 mikedld 3081
    sar   ecx,16
684 diamond 3082
    mov   [edi+WDATA.box.left],ebx
860 serge 3083
    mov   [edi+WDATA.box.top],ecx
3084
1 ha 3085
 
3086
3087
 
164 serge 3088
1 ha 3089
 
742 Rus 3090
    ;mov   esi,edi
114 mikedld 3091
3092
 
742 Rus 3093
	mov	eax, [edi+WDATA.cl_frames]
3094
114 mikedld 3095
 
1 ha 3096
    shl   edi,3
114 mikedld 3097
    add   edi,SLOT_BASE
380 serge 3098
114 mikedld 3099
 
742 Rus 3100
	mov	[edi+APPDATA.wnd_caption],0
3101
	cmp	cl,3
3102
	je	set_APPDATA_wnd_caption
3103
	cmp	cl,4								; {SPraid.simba}
3104
	je	set_APPDATA_wnd_caption
3105
567 serge 3106
 
742 Rus 3107
    set_APPDATA_wnd_caption:
549 spraid 3108
	mov	[edi+APPDATA.wnd_caption],eax
742 Rus 3109
    @@: mov	esi,[esp+0]
3110
114 mikedld 3111
 
115 poddubny 3112
	movsd
742 Rus 3113
	movsd
3114
	movsd
3115
	movsd
3116
    pop   edi esi ecx
1 ha 3117
3118
 
742 Rus 3119
	movzx	esi, word [WIN_STACK+esi*2]
3120
	lea	esi, [WIN_POS+esi*2]
3121
	call	waredraw
3122
569 diamond 3123
 
684 diamond 3124
;;;    call  delay_hs
1 ha 3125
    mov   eax, [edi+WDATA.box.left]
115 poddubny 3126
    mov   ebx, [edi+WDATA.box.top]
3127
    mov   ecx, [edi+WDATA.box.width]
3128
    mov   edx, [edi+WDATA.box.height]
3129
    add   ecx, eax
1 ha 3130
    add   edx, ebx
3131
    call  calculatescreen
3132
3133
 
742 Rus 3134
    mov   [BTN_COUNT],byte 0	       ; empty button buffer
3135
1 ha 3136
 
3137
    mov   [edi+WDATA.fl_redraw],byte 0	 ; no redraw
742 Rus 3138
    mov   edx,edi
1 ha 3139
3140
 
3141
3142
 
114 mikedld 3143
1 ha 3144
 
114 mikedld 3145
	dec	eax	; subfunction #1 - set window caption
742 Rus 3146
	jnz	.get_window_caption
3147
114 mikedld 3148
 
742 Rus 3149
	;       so there's no parameter for PID/TID
3150
114 mikedld 3151
 
742 Rus 3152
	shl	edi,5
3153
114 mikedld 3154
 
742 Rus 3155
	; check is trivial, and if application resizes its memory,
3156
	;   caption still can become over bounds
3157
; diamond, 31.10.2006: check removed because with new memory manager
202 diamond 3158
; there can be valid data after APPDATA.mem_size bound
3159
;        mov     ecx,[edi*8+SLOT_BASE+APPDATA.mem_size]
380 serge 3160
;        add     ecx,255 ; max caption length
202 diamond 3161
;        cmp     ebx,ecx
3162
;        ja      .exit_fail
3163
114 mikedld 3164
 
742 Rus 3165
	or	[edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
3166
114 mikedld 3167
 
742 Rus 3168
114 mikedld 3169
 
742 Rus 3170
	ret
3171
114 mikedld 3172
 
3173
	dec	eax	; subfunction #2 - get window caption
742 Rus 3174
	jnz	.exit_fail
3175
114 mikedld 3176
 
742 Rus 3177
114 mikedld 3178
 
3179
	xor	eax,eax
742 Rus 3180
	inc	eax	; eax = 1 (fail)
3181
	ret
3182
114 mikedld 3183
 
3184
 
1 ha 3185
3186
 
742 Rus 3187
	shl	edi,5
3188
	add	edi,window_data
3189
1 ha 3190
 
742 Rus 3191
	jnz	.window_move_return
3192
1 ha 3193
 
742 Rus 3194
	push	dword [edi + WDATA.box.top]
3195
	push	dword [edi + WDATA.box.width]
3196
	push	dword [edi + WDATA.box.height]
3197
1 ha 3198
 
742 Rus 3199
	je    .no_x_reposition
3200
	mov	[edi + WDATA.box.left], eax
3201
      .no_x_reposition:
49 mikedld 3202
	cmp   ebx,-1
742 Rus 3203
	je    .no_y_reposition
3204
	mov	[edi + WDATA.box.top], ebx
3205
      .no_y_reposition:
49 mikedld 3206
1 ha 3207
 
742 Rus 3208
	jnz	.no_y_resizing
3209
1 ha 3210
 
742 Rus 3211
	je    .no_x_resizing
3212
	mov	[edi + WDATA.box.width], ecx
3213
      .no_x_resizing:
49 mikedld 3214
	cmp   edx,-1
742 Rus 3215
	je    .no_y_resizing
3216
	mov	[edi + WDATA.box.height], edx
3217
      .no_y_resizing:
49 mikedld 3218
1 ha 3219
 
742 Rus 3220
	call  set_window_clientbox
3221
1 ha 3222
 
742 Rus 3223
	mov   esi,edi
3224
	sub   edi,window_data
3225
	shr   edi,5
3226
	shl   edi,8
3227
	add   edi, SLOT_BASE + APPDATA.saved_box
3228
	mov   ecx,4
3229
	cld
3230
	rep   movsd
3231
	popad
3232
49 mikedld 3233
 
742 Rus 3234
	mov   eax, [edi + WDATA.box.left]
3235
	mov   ebx, [edi + WDATA.box.top]
3236
	mov   ecx, [edi + WDATA.box.width]
3237
	mov   edx, [edi + WDATA.box.height]
3238
	add   ecx,eax
3239
	add   edx,ebx
3240
221 serge 3241
 
742 Rus 3242
	popad
3243
49 mikedld 3244
 
742 Rus 3245
	pop   ecx
3246
	pop   ebx
3247
	pop   eax
3248
	add   ecx,eax
3249
	add   edx,ebx
3250
	mov   [dlx],eax 	    ; save for drawlimits
3251
	mov   [dly],ebx
3252
	mov   [dlxe],ecx
3253
	mov   [dlye],edx
3254
	call  calculatescreen
3255
49 mikedld 3256
 
742 Rus 3257
49 mikedld 3258
 
742 Rus 3259
	xor   esi,esi
3260
	call  redrawscreen
3261
49 mikedld 3262
 
742 Rus 3263
	mov   [MOUSE_BACKGROUND],byte 0 ; no mouse under
3264
	mov   [MOUSE_DOWN],byte 0 ; react to mouse up/down
3265
49 mikedld 3266
 
742 Rus 3267
49 mikedld 3268
 
742 Rus 3269
49 mikedld 3270
 
3271
3272
 
742 Rus 3273
1 ha 3274
 
3275
  window_move_pr   dd  0x0
3276
  window_move_eax  dd  0x0
3277
  window_move_ebx  dd  0x0
3278
  window_move_ecx  dd  0x0
3279
  window_move_edx  dd  0x0
3280
endg
3281
3282
 
3283
;nt - not tested
3284
;---------------------------------------------------------------------------------------------
3285
;eax
3286
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3287
;1 - change task. Ret nothing. Block. ok.
3288
;2 - performance control
3289
; ebx
3290
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3291
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3292
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3293
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3294
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3295
;eax
3296
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3297
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3298
;---------------------------------------------------------------------------------------------
3299
sys_sheduler: ;noname & halyavin
3300
    cmp eax,0
3301
    je shed_counter
3302
    cmp eax,2
3303
    je perf_control
3304
    cmp eax,3
3305
    je rdmsr_instr
3306
    cmp eax,4
3307
    je wrmsr_instr
3308
    cmp eax,1
3309
    jne not_supported
3310
    call change_task ;delay,0
3311
ret
3312
shed_counter:
3313
    mov eax,[context_counter]
3314
    mov [esp+36],eax
3315
not_supported:
3316
ret
3317
perf_control:
3318
    inc eax ;now eax=3
3319
    cmp ebx,eax
3320
    je cache_disable
3321
    dec eax
3322
    cmp ebx,eax
3323
    je cache_enable
3324
    dec eax
3325
    cmp ebx,eax
3326
    je is_cache_enabled
3327
    dec eax
3328
    cmp ebx,eax
3329
    je modify_pce
3330
ret
3331
3332
 
3333
;now counter in ecx
3334
;(edx:eax) esi:edi => edx:esi
3335
mov eax,esi
3336
rdmsr
3337
mov [esp+36],eax
3338
mov [esp+24],edx ;ret in ebx?
3339
ret
3340
3341
 
3342
;now counter in ecx
3343
;(edx:eax) esi:edi => edx:esi
3344
	; Fast Call MSR can't be destroy
482 Ghost 3345
	; Íî MSR_AMD_EFER ìîæíî èçìåíÿòü, ò.ê. â ýòîì ðåãèñòðå ëèø
3346
	; âêëþ÷àþòñÿ/âûêëþ÷àþòñÿ ðàñøèðåííûå âîçìîæíîñòè
3347
	cmp	ecx, MSR_SYSENTER_CS
3348
	je	@f
3349
	cmp	ecx, MSR_SYSENTER_ESP
3350
	je	@f
3351
	cmp	ecx, MSR_SYSENTER_EIP
3352
	je	@f
3353
	cmp	ecx, MSR_AMD_STAR
3354
	je	@f
3355
3356
 
3357
	wrmsr
3358
	; mov   [esp + 36], eax
742 Rus 3359
	; mov   [esp + 24], edx ;ret in ebx?
3360
@@:
482 Ghost 3361
ret
1 ha 3362
3363
 
3364
       mov eax,cr0
3365
       or  eax,01100000000000000000000000000000b
3366
       mov cr0,eax
3367
       wbinvd ;set MESI
3368
ret
3369
3370
 
3371
       mov eax,cr0
3372
       and eax,10011111111111111111111111111111b
3373
       mov cr0,eax
3374
ret
3375
3376
 
3377
       mov eax,cr0
3378
       mov ebx,eax
3379
       and eax,01100000000000000000000000000000b
3380
       jz cache_disabled
3381
       mov [esp+36],ebx
3382
cache_disabled:
3383
       mov dword [esp+36],eax ;0
3384
ret
3385
3386
 
3387
       mov eax,cr4
3388
;       mov ebx,0
3389
;       or  bx,100000000b ;pce
3390
;       xor eax,ebx ;invert pce
3391
       bts eax,8 ;pce=cr4[8]
17 me_root 3392
       mov cr4,eax
1 ha 3393
       mov [esp+36],eax
3394
ret
3395
;---------------------------------------------------------------------------------------------
3396
3397
 
3398
 
3399
3400
 
3401
	push eax edx
742 Rus 3402
1 ha 3403
 
759 Rus 3404
        mov  ecx, [_display_data]
840 serge 3405
3406
 
3407
	imul edx, ebx
742 Rus 3408
1 ha 3409
 
840 serge 3410
        mov  dl, [eax+edx] ; lea eax, [...]
3411
3412
 
742 Rus 3413
	mov  eax, [CURRENT_TASK]
3414
	cmp  al, dl
3415
	setne cl
3416
1 ha 3417
 
742 Rus 3418
	ret
3419
1 ha 3420
 
3421
  cpustring db 'CPU',0
521 diamond 3422
endg
1 ha 3423
3424
 
67 diamond 3425
background_defined    db    0	 ; diamond, 11.04.2006
742 Rus 3426
endg
67 diamond 3427
1 ha 3428
 
3429
; check misc
3430
3431
 
3432
3433
 
3434
    jne   nocpustart
3435
501 serge 3436
 
742 Rus 3437
	call	fs_execute_from_sysdir
3438
501 serge 3439
 
1 ha 3440
465 serge 3441
 
3442
    cmp   [mouse_active], 1
1 ha 3443
    jne   mouse_not_active
3444
    mov   [mouse_active], 0
3445
    xor   edi, edi
3446
    mov   ecx,	[TASK_COUNT]
742 Rus 3447
set_mouse_event:
465 serge 3448
    add   edi, 256
1 ha 3449
    or	  [edi+SLOT_BASE+APPDATA.event_mask], dword 100000b
742 Rus 3450
    loop  set_mouse_event
1 ha 3451
3452
 
465 serge 3453
    cmp   [REDRAW_BACKGROUND],byte 0		   ; background update ?
742 Rus 3454
    jz	  nobackgr
3455
    cmp    [background_defined], 0
76 mario79 3456
    jz	  nobackgr
742 Rus 3457
    cmp   [REDRAW_BACKGROUND], byte 2
709 diamond 3458
    jnz   no_set_bgr_event
3459
    xor   edi, edi
473 diamond 3460
    mov   ecx,	[TASK_COUNT]
742 Rus 3461
set_bgr_event:
473 diamond 3462
    add   edi, 256
3463
    or	  [edi+SLOT_BASE+APPDATA.event_mask], 16
742 Rus 3464
    loop  set_bgr_event
473 diamond 3465
no_set_bgr_event:
709 diamond 3466
;    mov   [draw_data+32 + RECT.left],dword 0
3467
;    mov   [draw_data+32 + RECT.top],dword 0
3468
;    mov   eax,[Screen_Max_X]
753 serge 3469
;    mov   ebx,[Screen_Max_Y]
3470
;    mov   [draw_data+32 + RECT.right],eax
709 diamond 3471
;    mov   [draw_data+32 + RECT.bottom],ebx
3472
    call  drawbackground
1 ha 3473
    mov   [REDRAW_BACKGROUND],byte 0
381 serge 3474
    mov   [MOUSE_BACKGROUND],byte 0
3475
1 ha 3476
 
465 serge 3477
1 ha 3478
 
3479
3480
 
381 serge 3481
    je	 noshutdown
742 Rus 3482
1 ha 3483
 
3484
3485
 
381 serge 3486
    jne  no_mark_system_shutdown
1 ha 3487
3488
 
709 diamond 3489
    mov   edx,OS_BASE+0x3040
465 serge 3490
    jecxz @f
709 diamond 3491
markz:
465 serge 3492
    mov   [edx+TASKDATA.state],byte 3
115 poddubny 3493
    add   edx,0x20
1 ha 3494
    loop  markz
3495
@@:
709 diamond 3496
1 ha 3497
 
3498
3499
 
3500
3501
 
381 serge 3502
    je	 system_shutdown
742 Rus 3503
1 ha 3504
 
465 serge 3505
1 ha 3506
 
3507
 
742 Rus 3508
    mov   ebx,TASK_DATA+TASKDATA.state
379 serge 3509
    mov   esi,1
1 ha 3510
3511
 
465 serge 3512
    mov   cl,[ebx]
1 ha 3513
    cmp   cl,byte 3
3514
    jz	  terminate
742 Rus 3515
    cmp   cl,byte 4
1 ha 3516
    jz	  terminate
742 Rus 3517
1 ha 3518
 
3519
    inc   esi
3520
    dec   eax
3521
    jnz   newct
3522
    ret
3523
3524
 
3525
3526
 
3527
3528
 
3529
3530
 
742 Rus 3531
	 push  eax
3532
1 ha 3533
 
684 diamond 3534
;;;         call  delay_hs
1 ha 3535
3536
 
742 Rus 3537
	 xor   ecx,ecx
3538
       newdw2:
1 ha 3539
3540
 
742 Rus 3541
	 push  ecx
3542
1 ha 3543
 
742 Rus 3544
	 shl   eax,5
3545
	 add   eax,window_data
3546
1 ha 3547
 
742 Rus 3548
	 je    not_this_task
3549
				   ; check if window in redraw area
3550
	 mov   edi,eax
3551
1 ha 3552
 
742 Rus 3553
	 jz    bgli
3554
1 ha 3555
 
742 Rus 3556
	 mov   ebx, [edi + WDATA.box.top]
3557
	 mov   ecx, [edi + WDATA.box.width]
3558
	 mov   edx, [edi + WDATA.box.height]
3559
	 add   ecx,eax
3560
	 add   edx,ebx
3561
1 ha 3562
 
742 Rus 3563
	 cmp   ecx,ebx
3564
	 jb    ricino
3565
1 ha 3566
 
742 Rus 3567
	 cmp   ecx,eax
3568
	 jb    ricino
3569
1 ha 3570
 
742 Rus 3571
	 mov   ebx, [edi + WDATA.box.top]
3572
	 mov   ecx, [edi + WDATA.box.width]
3573
	 mov   edx, [edi + WDATA.box.height]
3574
	 add   ecx, eax
3575
	 add   edx, ebx
3576
164 serge 3577
 
742 Rus 3578
	 cmp   edx,eax
3579
	 jb    ricino
3580
1 ha 3581
 
742 Rus 3582
	 cmp   ecx,eax
3583
	 jb    ricino
3584
1 ha 3585
 
742 Rus 3586
1 ha 3587
 
742 Rus 3588
	 jnz   .az
3589
	 mov   al,[REDRAW_BACKGROUND]
3590
	 cmp   al,2
3591
	 jz    newdw8
3592
	 test  al,al
3593
	 jz    .az
3594
	 lea   eax,[edi+draw_data-window_data]
3595
	 mov   ebx,[dlx]
3596
	 cmp   ebx,[eax+RECT.left]
3597
	 jae   @f
3598
	 mov   [eax+RECT.left],ebx
3599
	@@:
3600
	 mov   ebx,[dly]
3601
	 cmp   ebx,[eax+RECT.top]
3602
	 jae   @f
3603
	 mov   [eax+RECT.top],ebx
3604
	@@:
3605
	 mov   ebx,[dlxe]
3606
	 cmp   ebx,[eax+RECT.right]
3607
	 jbe   @f
3608
	 mov   [eax+RECT.right],ebx
3609
	@@:
3610
	 mov   ebx,[dlye]
3611
	 cmp   ebx,[eax+RECT.bottom]
3612
	 jbe   @f
3613
	 mov   [eax+RECT.bottom],ebx
3614
	@@:
3615
	 jmp   newdw8
3616
	.az:
3617
1 ha 3618
 
742 Rus 3619
	 add   eax,draw_data-window_data
3620
1 ha 3621
 
742 Rus 3622
	 mov   [eax + RECT.left], ebx
3623
	 mov   ebx,[dly]
3624
	 mov   [eax + RECT.top], ebx
3625
	 mov   ebx,[dlxe]
3626
	 mov   [eax + RECT.right], ebx
3627
	 mov   ebx,[dlye]
3628
	 mov   [eax + RECT.bottom], ebx
3629
1 ha 3630
 
742 Rus 3631
1 ha 3632
 
742 Rus 3633
	 jne   nobgrd
3634
	 mov   byte [REDRAW_BACKGROUND], 1
3635
1 ha 3636
 
3637
       nobgrd:
3638
3639
 
742 Rus 3640
1 ha 3641
 
3642
3643
 
3644
3645
 
742 Rus 3646
1 ha 3647
 
742 Rus 3648
	 jle   newdw2
3649
1 ha 3650
 
742 Rus 3651
	 popad
3652
1 ha 3653
 
742 Rus 3654
1 ha 3655
 
3656
3657
 
742 Rus 3658
1 ha 3659
 
742 Rus 3660
	xor   eax, eax
3661
	mov   ecx, 1023    ;0x0fff00 / 4
3662
	cld
3663
	rep   stosd
3664
1 ha 3665
 
840 serge 3666
	mov   eax,0x01010101
742 Rus 3667
	mov   ecx,1280*1024 / 4
3668
	rep   stosd
3669
1 ha 3670
 
742 Rus 3671
1 ha 3672
 
742 Rus 3673
1 ha 3674
 
3675
  imax	  dd 0x0
742 Rus 3676
endg
1 ha 3677
3678
 
3679
 
3680
 
3681
3682
 
3683
 
742 Rus 3684
	push  ecx
3685
1 ha 3686
 
742 Rus 3687
	; 
3688
	imul  ecx, 33941
3689
	shr   ecx, 9
3690
	; 
3691
1 ha 3692
 
742 Rus 3693
	and   al,0x10
3694
	mov   ah,al
3695
	cld
3696
1 ha 3697
 
742 Rus 3698
	and   al,0x10
3699
	cmp   al,ah
3700
	jz    cnt1
3701
1 ha 3702
 
742 Rus 3703
	loop  cnt1
3704
1 ha 3705
 
742 Rus 3706
	pop   eax
3707
1 ha 3708
 
742 Rus 3709
1 ha 3710
 
3711
 
3712
	mov	edi, [TASK_BASE]
742 Rus 3713
	mov	[edi + TASKDATA.event_mask], ebx
3714
	ret
3715
1 ha 3716
 
3717
 
3718
 
3719
; ebx = delay time
684 diamond 3720
	push  ecx
742 Rus 3721
	push  edx
3722
1 ha 3723
 
742 Rus 3724
1 ha 3725
 
3726
	mov   ecx,[timer_ticks]
742 Rus 3727
	sub   ecx,edx
3728
	cmp   ecx,ebx
3729
	jae   zerodelay
3730
1 ha 3731
 
742 Rus 3732
1 ha 3733
 
742 Rus 3734
1 ha 3735
 
3736
	pop   edx
742 Rus 3737
	pop   ecx
3738
1 ha 3739
 
742 Rus 3740
1 ha 3741
 
3742
 
3743
3744
 
3745
; ebx = to
3746
; ecx = no of bytes
3747
    test ecx, ecx
3748
    jle  .ret
3749
3750
 
3751
 
3752
3753
 
3754
    mov  esi, eax
3755
3756
 
3757
    jz	 @f
742 Rus 3758
1 ha 3759
 
3760
    shr  ecx, 2
3761
    rep  movsd
3762
    pop  ecx
3763
    and  ecx, 11b
3764
    jz	 .finish
742 Rus 3765
  @@:
1 ha 3766
    rep  movsb
3767
3768
 
3769
    pop  ecx edi esi
3770
  .ret:
3771
    ret
3772
3773
 
3774
 
75 diamond 3775
;align 4
3776
;
1 ha 3777
;read_floppy_file:
75 diamond 3778
;
1 ha 3779
;; as input
75 diamond 3780
;;
3781
;; eax pointer to file
3782
;; ebx file lenght
3783
;; ecx start 512 byte block number
3784
;; edx number of blocks to read
3785
;; esi pointer to return/work area (atleast 20 000 bytes)
3786
;;
3787
;;
3788
;; on return
3789
;;
3790
;; eax = 0 command succesful
3791
;;       1 no fd base and/or partition defined
3792
;;       2 yet unsupported FS
3793
;;       3 unknown FS
3794
;;       4 partition not defined at hd
3795
;;       5 file not found
3796
;; ebx = size of file
3797
;
1 ha 3798
;     mov   edi,[TASK_BASE]
379 serge 3799
;     add   edi,0x10
75 diamond 3800
;     add   esi,[edi]
3801
;     add   eax,[edi]
3802
;
1 ha 3803
;     pushad
75 diamond 3804
;     mov  edi,esi
3805
;     add  edi,1024
3806
;     mov  esi,0x100000+19*512
3807
;     sub  ecx,1
3808
;     shl  ecx,9
3809
;     add  esi,ecx
3810
;     shl  edx,9
3811
;     mov  ecx,edx
3812
;     cld
3813
;     rep  movsb
3814
;     popad
3815
;
3816
;     mov   [esp+36],eax
3817
;     mov   [esp+24],ebx
3818
;     ret
3819
1 ha 3820
 
3821
 
3822
 
3823
3824
 
3825
3826
 
765 Rus 3827
    add   ebx, [eax + TASKDATA.mem_start]
3828
1 ha 3829
 
765 Rus 3830
    jae   .not_owner
75 diamond 3831
    mov   edi, [eax + TASKDATA.pid]
765 Rus 3832
    cmp   edi, [irq_owner + 4 * ecx]
3833
    je	  .spril1
3834
.not_owner:
75 diamond 3835
    xor   ecx, ecx
765 Rus 3836
    jmp   .end
3837
  .spril1:
3838
1 ha 3839
 
765 Rus 3840
    mov   esi, ebx
3841
    lea   edi, [irq00read + ecx]
3842
    push  16
3843
    pop   ecx
3844
3845
 
1 ha 3846
    rep   movsd
3847
  .end:
765 Rus 3848
    mov   [esp+32], ecx
3849
    ret
1 ha 3850
3851
 
3852
 
3853
3854
 
3855
     movzx esi, bh			 ; save number of subfunction, if bh = 1, return data size, otherwise, read data
760 Rus 3856
     xor   bh, bh
3857
     cmp   ebx, 16
3858
     jae   .not_owner
75 diamond 3859
     mov   edx, [4 * ebx + irq_owner]	 ; check for irq owner
760 Rus 3860
742 Rus 3861
 
760 Rus 3862
742 Rus 3863
 
760 Rus 3864
     je    gidril1
1 ha 3865
.not_owner:
75 diamond 3866
     xor   edx, edx
760 Rus 3867
     dec   edx
3868
     jmp   gid1
3869
1 ha 3870
 
3871
3872
 
760 Rus 3873
     lea   eax, [ebx + IRQ_SAVE]	 ; calculate address of the beginning of buffer + 0x0 - data size
3874
     mov   edx, [eax]			 ;                                              + 0x4 - data offset
3875
     dec   esi
3876
     jz    gid1
1 ha 3877
     test  edx, edx			 ; check if buffer is empty
760 Rus 3878
     jz    gid1
3879
1 ha 3880
 
760 Rus 3881
     mov   edi, ecx
3882
742 Rus 3883
 
760 Rus 3884
742 Rus 3885
 
760 Rus 3886
     jb    @f
759 Rus 3887
742 Rus 3888
 
760 Rus 3889
759 Rus 3890
 
3891
3892
 
760 Rus 3893
     cld
3894
     cmp   esi, ecx			 ; if greater than the buffer size, begin cycle again
3895
     jbe   @f
3896
759 Rus 3897
 
760 Rus 3898
     sub   edx, ecx
3899
759 Rus 3900
 
760 Rus 3901
     rep   movsb
3902
3903
 
3904
   @@:
3905
     lea   esi, [eax + ebx + 0x10]
3906
     mov   ecx, edx
3907
     add   ebx, edx
3908
3909
 
3910
     mov   edx, [eax]
3911
     mov   [eax], ecx			 ; set data size to zero
3912
     mov   [eax + 0x4], ebx		 ; set data offset
3913
3914
 
1 ha 3915
     mov   [esp+32], edx		 ; eax
760 Rus 3916
     ret
1 ha 3917
3918
 
3919
 
3920
3921
 
3922
3923
 
465 serge 3924
1 ha 3925
 
465 serge 3926
;     and   ecx,7    ; offset in byte
3927
1 ha 3928
 
465 serge 3929
;     add   edi,eax
3930
1 ha 3931
 
465 serge 3932
;     shl   ebx,cl
3933
1 ha 3934
 
742 Rus 3935
     jne   siar1
1 ha 3936
3937
 
465 serge 3938
;     and   [edi],byte bl
3939
     btr [edi], eax
3940
1 ha 3941
 
3942
3943
 
3944
3945
 
465 serge 3946
1 ha 3947
 
465 serge 3948
  ;  or    [edi],byte bl        ; disable access - ebp = 1
3949
1 ha 3950
 
3951
3952
 
3953
3954
 
3955
3956
 
3957
     jnz   free_port_area
3958
;     je    r_port_area
3959
;     jmp   free_port_area
3960
3961
 
3962
3963
 
3964
3965
 
742 Rus 3966
     ja    rpal1
75 diamond 3967
     cmp   ecx,65536
3968
     jae   rpal1
3969
     mov   esi,[RESERVED_PORTS]
381 serge 3970
     test  esi,esi	      ; no reserved areas ?
742 Rus 3971
     je    rpal2
1 ha 3972
     cmp   esi,255	      ; max reserved
742 Rus 3973
     jae   rpal1
75 diamond 3974
 rpal3:
465 serge 3975
     mov   edi,esi
1 ha 3976
     shl   edi,4
3977
     add   edi,RESERVED_PORTS
381 serge 3978
     cmp   ebx,[edi+8]
1 ha 3979
     ja    rpal4
75 diamond 3980
     cmp   ecx,[edi+4]
1 ha 3981
     jae   rpal1
3982
;     jb    rpal4
3983
;     jmp   rpal1
3984
 rpal4:
465 serge 3985
1 ha 3986
 
3987
     jnz   rpal3
3988
     jmp   rpal2
3989
   rpal1:
3990
     popad
3991
     mov   eax,1
3992
     ret
3993
3994
 
3995
     popad
3996
3997
 
3998
 
3999
     cli
4000
     pushad			   ; start enable io map
742 Rus 4001
1 ha 4002
 
4003
     jae   no_unmask_io ; jge
4004
4005
 
4006
4007
 
4008
4009
 
4010
4011
 
742 Rus 4012
     call  set_io_access_rights
1 ha 4013
4014
 
4015
4016
 
4017
     cmp   eax,ecx
4018
     jbe   new_port_access
4019
4020
 
4021
4022
 
742 Rus 4023
     sti
1 ha 4024
4025
 
381 serge 4026
     add   edi,1
1 ha 4027
     mov   [RESERVED_PORTS],edi
381 serge 4028
     shl   edi,4
1 ha 4029
     add   edi,RESERVED_PORTS
381 serge 4030
     mov   esi,[TASK_BASE]
379 serge 4031
     mov   esi,[esi+TASKDATA.pid]
115 poddubny 4032
     mov   [edi],esi
1 ha 4033
     mov   [edi+4],ebx
4034
     mov   [edi+8],ecx
4035
4036
 
4037
     ret
4038
4039
 
4040
4041
 
4042
4043
 
381 serge 4044
     test  esi,esi
75 diamond 4045
     je    frpal2
1 ha 4046
     mov   edx,[TASK_BASE]
379 serge 4047
     mov   edx,[edx+TASKDATA.pid]
115 poddubny 4048
   frpal3:
1 ha 4049
     mov   edi,esi
4050
     shl   edi,4
4051
     add   edi,RESERVED_PORTS
381 serge 4052
     cmp   edx,[edi]
1 ha 4053
     jne   frpal4
4054
     cmp   ebx,[edi+4]
4055
     jne   frpal4
4056
     cmp   ecx,[edi+8]
4057
     jne   frpal4
4058
     jmp   frpal1
4059
   frpal4:
4060
     dec   esi
4061
     jnz   frpal3
4062
   frpal2:
4063
     popad
4064
     mov   eax,1
4065
     ret
4066
   frpal1:
4067
     mov   ecx,256
4068
     sub   ecx,esi
4069
     shl   ecx,4
4070
     mov   esi,edi
4071
     add   esi,16
4072
     cld
4073
     rep   movsb
4074
4075
 
381 serge 4076
1 ha 4077
 
4078
4079
 
4080
 
4081
4082
 
742 Rus 4083
1 ha 4084
 
4085
     jge   no_mask_io
4086
4087
 
4088
4089
 
4090
4091
 
4092
4093
 
742 Rus 4094
     call  set_io_access_rights
1 ha 4095
4096
 
4097
4098
 
4099
     cmp   eax,ecx
4100
     jbe   new_port_access_disable
4101
4102
 
4103
4104
 
742 Rus 4105
1 ha 4106
 
4107
     ret
4108
4109
 
4110
 
4111
4112
 
765 Rus 4113
     inc   esi
4114
     cmp   ecx, 16
4115
     jae   ril1
4116
1 ha 4117
 
769 Rus 4118
     lea   ecx, [irq_owner + 4 * ecx]
765 Rus 4119
     mov   edx, [ecx]
4120
     mov   eax, [TASK_BASE]
4121
     mov   edi, [eax + TASKDATA.pid]
4122
     pop   eax
769 Rus 4123
     dec   ebx
765 Rus 4124
     jnz   reserve_irq
4125
1 ha 4126
 
765 Rus 4127
     jne   ril1
4128
     dec   esi
4129
     mov   [ecx], esi
4130
4131
 
4132
4133
 
1 ha 4134
4135
 
765 Rus 4136
     jne   ril1
4137
1 ha 4138
 
769 Rus 4139
4140
 
774 Rus 4141
769 Rus 4142
 
765 Rus 4143
769 Rus 4144
 
765 Rus 4145
   ril1:
1 ha 4146
     mov   [esp+32], esi ; return in eax
765 Rus 4147
     ret
1 ha 4148
4149
 
769 Rus 4150
f_irqs:
4151
     dd 0x0
4152
     dd 0x0
4153
     dd p_irq2
4154
     dd p_irq3
4155
     dd p_irq4
4156
     dd p_irq5
4157
     dd p_irq6
4158
     dd p_irq7
4159
     dd p_irq8
4160
     dd p_irq9
4161
     dd p_irq10
4162
     dd p_irq11
4163
     dd 0x0
4164
     dd 0x0
4165
     dd p_irq14
4166
     dd p_irq15
4167
4168
 
4169
4170
 
1 ha 4171
       inc   [mouse_pause]
33 mario79 4172
       cmp   [SCR_MODE],word 0x12
381 serge 4173
       je   dbrv20
117 mario79 4174
     dbrv12:
1 ha 4175
       cmp  [SCR_MODE],word 0100000000000000b
381 serge 4176
       jge  dbrv20
1 ha 4177
       cmp  [SCR_MODE],word 0x13
381 serge 4178
       je   dbrv20
1 ha 4179
       call  vesa12_drawbackground
4180
       dec   [mouse_pause]
33 mario79 4181
       call   [draw_pointer]
36 mario79 4182
       ret
1 ha 4183
     dbrv20:
4184
       cmp   [BgrDrawMode],dword 1
527 diamond 4185
       jne   bgrstr
1 ha 4186
       call  vesa20_drawbackground_tiled
4187
       dec   [mouse_pause]
33 mario79 4188
       call   [draw_pointer]
36 mario79 4189
       ret
1 ha 4190
     bgrstr:
4191
       call  vesa20_drawbackground_stretch
4192
       dec   [mouse_pause]
33 mario79 4193
       call   [draw_pointer]
36 mario79 4194
       ret
1 ha 4195
4196
 
75 diamond 4197
1 ha 4198
 
742 Rus 4199
sys_putimage:
1 ha 4200
     test  ecx,0x80008000
53 mikedld 4201
     jnz   .exit
4202
     test  ecx,0x0000FFFF
4203
     jz    .exit
4204
     test  ecx,0xFFFF0000
4205
     jnz   @f
4206
  .exit:
4207
     ret
4208
 @@:
4209
	mov	edi,[current_slot]
742 Rus 4210
	add	dx,word[edi+APPDATA.wnd_clientbox.top]
4211
	rol	edx,16
4212
	add	dx,word[edi+APPDATA.wnd_clientbox.left]
4213
	rol	edx,16
4214
  .forced:
114 mikedld 4215
	push	ebp esi 0
742 Rus 4216
	mov	ebp, putimage_get24bpp
4217
	mov	esi, putimage_init24bpp
4218
sys_putimage_bpp:
283 diamond 4219
;        call    [disable_mouse] ; this will be done in xxx_putimage
4220
;        mov     eax, vga_putimage
117 mario79 4221
	cmp	[SCR_MODE], word 0x12
742 Rus 4222
	jz	@f   ;.doit
4223
	mov	eax, vesa12_putimage
4224
	cmp	[SCR_MODE], word 0100000000000000b
4225
	jae	@f
4226
	cmp	[SCR_MODE], word 0x13
4227
	jnz	.doit
4228
@@:
75 diamond 4229
	mov	eax, vesa20_putimage
742 Rus 4230
.doit:
75 diamond 4231
	inc	[mouse_pause]
742 Rus 4232
	call	eax
4233
	dec	[mouse_pause]
4234
	pop	ebp esi ebp
4235
	jmp	[draw_pointer]
4236
1 ha 4237
 
283 diamond 4238
	mov	edi, esi
742 Rus 4239
	mov	esi, edx
4240
	mov	edx, ecx
4241
	mov	ecx, ebx
4242
	mov	ebx, eax
4243
sys_putimage_palette:
283 diamond 4244
; ebx = pointer to image
4245
; ecx = [xsize]*65536 + [ysize]
4246
; edx = [xstart]*65536 + [ystart]
4247
; esi = number of bits per pixel, must be 8, 24 or 32
314 diamond 4248
; edi = pointer to palette
283 diamond 4249
; ebp = row delta
314 diamond 4250
	mov	eax, [CURRENT_TASK]
742 Rus 4251
	shl	eax, 8
4252
	add	dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
4253
	rol	edx, 16
4254
	add	dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
4255
	rol	edx, 16
4256
.forced:
283 diamond 4257
	push	ebp esi ebp
742 Rus 4258
	cmp	esi, 8
4259
	jnz	@f
4260
	mov	ebp, putimage_get8bpp
4261
	mov	esi, putimage_init8bpp
4262
	jmp	sys_putimage_bpp
4263
@@:
314 diamond 4264
        cmp     esi, 16
844 serge 4265
        jnz     @f
4266
        mov     ebp, putimage_get16bpp
4267
        mov     esi, putimage_init16bpp
4268
        jmp     sys_putimage_bpp
4269
@@:
4270
	cmp	esi, 24
742 Rus 4271
	jnz	@f
4272
	mov	ebp, putimage_get24bpp
4273
	mov	esi, putimage_init24bpp
4274
	jmp	sys_putimage_bpp
4275
@@:
314 diamond 4276
	cmp	esi, 32
742 Rus 4277
	jnz	@f
4278
	mov	ebp, putimage_get32bpp
4279
	mov	esi, putimage_init32bpp
4280
	jmp	sys_putimage_bpp
4281
@@:
314 diamond 4282
	pop	ebp esi ebp
844 serge 4283
	ret
742 Rus 4284
283 diamond 4285
 
4286
	lea	eax, [eax*3]
742 Rus 4287
putimage_init8bpp:
283 diamond 4288
	ret
742 Rus 4289
283 diamond 4290
 
4291
	mov	eax, [esi]
742 Rus 4292
	add	esi, 3
4293
	ret	4
4294
putimage_get8bpp:
283 diamond 4295
	movzx	eax, byte [esi]
742 Rus 4296
	push	edx
4297
	mov	edx, [esp+8]
4298
	mov	eax, [edx+eax*4]
4299
	pop	edx
4300
	inc	esi
4301
	ret	4
4302
283 diamond 4303
 
314 diamond 4304
	shl	eax, 2
742 Rus 4305
	ret
4306
putimage_get32bpp:
314 diamond 4307
	lodsd
742 Rus 4308
	ret	4
4309
314 diamond 4310
 
844 serge 4311
        add     eax, eax
4312
        ret
4313
putimage_get16bpp:
4314
; 0RRRRRGGGGGBBBBB -> 00000000RRRRR000GGGGG000BBBBB000
4315
        push    ecx edx
4316
        movzx   eax, word [esi]
4317
        add     esi, 2
4318
        mov     ecx, eax
4319
        mov     edx, eax
4320
        and     eax, 0x1F
4321
        and     ecx, 0x1F shl 5
4322
        and     edx, 0x1F shl 10
4323
        shl     eax, 3
4324
        shl     ecx, 6
4325
        shl     edx, 9
4326
        or      eax, ecx
4327
        or      eax, edx
4328
        pop     edx ecx
4329
        ret
4330
4331
 
1 ha 4332
; ebx y beginning
4333
; ecx x end
4334
	; edx y end
283 diamond 4335
; edi color
1 ha 4336
4337
 
4338
	mov	esi,[current_slot]
742 Rus 4339
	add	eax,[esi+APPDATA.wnd_clientbox.left]
4340
	add	ecx,[esi+APPDATA.wnd_clientbox.left]
4341
	add	ebx,[esi+APPDATA.wnd_clientbox.top]
4342
	add	edx,[esi+APPDATA.wnd_clientbox.top]
4343
  .forced:
114 mikedld 4344
    inc   [mouse_pause]
33 mario79 4345
;        call    [disable_mouse]
283 diamond 4346
    cmp   [SCR_MODE],word 0x12
381 serge 4347
    je	 dbv20
742 Rus 4348
   sdbv20:
1 ha 4349
    cmp  [SCR_MODE],word 0100000000000000b
381 serge 4350
    jge  dbv20
1 ha 4351
    cmp  [SCR_MODE],word 0x13
381 serge 4352
    je	 dbv20
742 Rus 4353
    call vesa12_drawbar
1 ha 4354
    dec   [mouse_pause]
33 mario79 4355
    call   [draw_pointer]
36 mario79 4356
    ret
1 ha 4357
  dbv20:
4358
    call vesa20_drawbar
4359
    dec   [mouse_pause]
33 mario79 4360
    call   [draw_pointer]
36 mario79 4361
    ret
1 ha 4362
4363
 
4364
 
4365
 
4366
4367
 
742 Rus 4368
1 ha 4369
 
742 Rus 4370
      kr_loop:
1 ha 4371
	in	al,0x64
742 Rus 4372
	test	al,1
4373
	jnz	kr_ready
4374
	loop	kr_loop
4375
	mov	ah,1
4376
	jmp	kr_exit
4377
      kr_ready:
1 ha 4378
	push	ecx
742 Rus 4379
	mov	ecx,32
4380
      kr_delay:
1 ha 4381
	loop	kr_delay
742 Rus 4382
	pop	ecx
4383
	in	al,0x60
4384
	xor	ah,ah
4385
      kr_exit:
1 ha 4386
4387
 
742 Rus 4388
1 ha 4389
 
742 Rus 4390
1 ha 4391
 
4392
 
4393
4394
 
742 Rus 4395
1 ha 4396
 
742 Rus 4397
;        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
265 diamond 4398
;      kw_loop1:
4399
;        in      al,0x64
4400
;        test    al,0x20
4401
;        jz      kw_ok1
4402
;        loop    kw_loop1
4403
;        mov     ah,1
4404
;        jmp     kw_exit
4405
;      kw_ok1:
4406
	in	al,0x60
742 Rus 4407
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4408
      kw_loop:
1 ha 4409
	in	al,0x64
742 Rus 4410
	test	al,2
4411
	jz	kw_ok
4412
	loop	kw_loop
4413
	mov	ah,1
4414
	jmp	kw_exit
4415
      kw_ok:
1 ha 4416
	mov	al,dl
742 Rus 4417
	out	0x60,al
4418
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4419
      kw_loop3:
1 ha 4420
	in	al,0x64
742 Rus 4421
	test	al,2
4422
	jz	kw_ok3
4423
	loop	kw_loop3
4424
	mov	ah,1
4425
	jmp	kw_exit
4426
      kw_ok3:
1 ha 4427
	mov	ah,8
742 Rus 4428
      kw_loop4:
1 ha 4429
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
742 Rus 4430
      kw_loop5:
1 ha 4431
	in	al,0x64
742 Rus 4432
	test	al,1
4433
	jnz	kw_ok4
4434
	loop	kw_loop5
4435
	dec	ah
4436
	jnz	kw_loop4
4437
      kw_ok4:
1 ha 4438
	xor	ah,ah
742 Rus 4439
      kw_exit:
1 ha 4440
4441
 
742 Rus 4442
1 ha 4443
 
742 Rus 4444
1 ha 4445
 
4446
 
4447
4448
 
742 Rus 4449
      c_wait:
1 ha 4450
	in	al,0x64
742 Rus 4451
	test	al,2
4452
	jz	c_send
4453
	loop	c_wait
4454
	jmp	c_error
4455
      c_send:
1 ha 4456
	mov	al,bl
742 Rus 4457
	out	0x64,al
4458
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4459
      c_accept:
1 ha 4460
	in	al,0x64
742 Rus 4461
	test	al,2
4462
	jz	c_ok
4463
	loop	c_accept
4464
      c_error:
1 ha 4465
	mov	ah,1
742 Rus 4466
	jmp	c_exit
4467
      c_ok:
1 ha 4468
	xor	ah,ah
742 Rus 4469
      c_exit:
1 ha 4470
	ret
742 Rus 4471
1 ha 4472
 
4473
 
4474
	   ; ps2 mouse enable
742 Rus 4475
1 ha 4476
 
381 serge 4477
1 ha 4478
 
4479
4480
 
4481
4482
 
4483
 
4484
     bt [cpu_caps], CAPS_TSC
164 serge 4485
     jnc ret_rdtsc
4486
     rdtsc
1 ha 4487
     ret
4488
   ret_rdtsc:
4489
     mov   edx,0xffffffff
4490
     mov   eax,0xffffffff
4491
     ret
4492
4493
 
4494
4495
 
742 Rus 4496
	out	0x20,al
4497
	call	pic_delay
4498
	out	0xA0,al
4499
	call	pic_delay
4500
1 ha 4501
 
742 Rus 4502
	out	0x21,al
4503
	call	pic_delay
4504
	mov	al,0x28 	;  generate 0x28 +
4505
	out	0xA1,al
4506
	call	pic_delay
4507
1 ha 4508
 
742 Rus 4509
	out	0x21,al
4510
	call	pic_delay
4511
	mov	al,0x02 	;  at irq9
4512
	out	0xA1,al
4513
	call	pic_delay
4514
1 ha 4515
 
742 Rus 4516
	out	0x21,al
4517
	call	pic_delay
4518
	out	0xA1,al
4519
	call	pic_delay
4520
1 ha 4521
 
742 Rus 4522
	out	0xA1,al
4523
	call	pic_delay
4524
	out	0x21,al
4525
	call	pic_delay
4526
1 ha 4527
 
742 Rus 4528
	cld
4529
picl1:	call	pic_delay
4530
	loop	picl1
4531
1 ha 4532
 
742 Rus 4533
	out	0xA1,al
4534
	call	pic_delay
4535
	out	0x21,al
4536
	call	pic_delay
4537
1 ha 4538
 
742 Rus 4539
1 ha 4540
 
4541
 
4542
4543
 
742 Rus 4544
pdl1:	ret
4545
1 ha 4546
 
4547
 
4548
4549
 
4550
   @@:
4551
     cmp    [esi],byte 0
4552
     je     @f
4553
     mov    eax,1
4554
     movzx  ebx,byte [esi]
4555
     call   sys_msg_board
4556
     inc    esi
4557
     jmp    @b
4558
   @@:
4559
     popad
4560
     ret
4561
4562
 
709 diamond 4563
; in: al = byte to display
4564
; out: nothing
4565
; destroys: nothing
4566
	pushad
742 Rus 4567
	mov	ecx, 2
4568
	shl	eax, 24
4569
	jmp	@f
4570
709 diamond 4571
 
4572
; in: ax = word to display
4573
; out: nothing
4574
; destroys: nothing
4575
	pushad
742 Rus 4576
	mov	ecx, 4
4577
	shl	eax, 16
4578
	jmp	@f
4579
709 diamond 4580
 
4581
; in: eax = dword to display
4582
; out: nothing
4583
; destroys: nothing
4584
	pushad
742 Rus 4585
	mov	ecx, 8
4586
@@:
709 diamond 4587
	push	ecx
742 Rus 4588
	rol	eax, 4
4589
	push	eax
4590
	and	al, 0xF
4591
	cmp	al, 10
4592
	sbb	al, 69h
4593
	das
4594
	mov	bl, al
4595
	xor	eax, eax
4596
	inc	eax
4597
	call	sys_msg_board
4598
	pop	eax
4599
	pop	ecx
4600
	loop	@b
4601
	popad
4602
	ret
4603
709 diamond 4604
 
1 ha 4605
  msg_board_data: times 4096 db 0
373 mikedld 4606
  msg_board_count dd 0x0
1 ha 4607
endg
4608
4609
 
4610
4611
 
4612
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4613
4614
 
671 Ghost 4615
	cmp	eax, 1
4616
	jne	.smbl1
4617
1 ha 4618
 
4619
 
671 Ghost 4620
	inc	ecx
4621
	and	ecx, 4095
4622
	mov	[msg_board_count], ecx
4623
	mov	[check_idle_semaphore], 5
4624
	ret
4625
.smbl1:
4626
	cmp	eax, 2
4627
	jne	.smbl2
4628
	test	ecx, ecx
4629
	jz	.smbl21
4630
	mov	eax, msg_board_data+1
4631
	mov	ebx, msg_board_data
4632
	movzx	edx, byte [ebx]
4633
	call	memmove
4634
	dec	[msg_board_count]
4635
	mov	[esp + 36], edx ;eax
4636
	mov	[esp + 24], dword 1
4637
	ret
4638
.smbl21:
4639
	mov	[esp+36], ecx
4640
	mov	[esp+24], ecx
4641
.smbl2:
4642
	ret
4643
1 ha 4644
 
4645
 
4646
 
4647
	mov	edi, [CURRENT_TASK]
742 Rus 4648
1 ha 4649
 
742 Rus 4650
     jne   no_set_keyboard_setup
1 ha 4651
4652
 
4653
     mov   [edi+SLOT_BASE + APPDATA.keyboard_mode],bl
380 serge 4654
1 ha 4655
 
4656
4657
 
4658
4659
 
742 Rus 4660
     jne   no_get_keyboard_setup
1 ha 4661
4662
 
4663
     movzx eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
380 serge 4664
1 ha 4665
 
4666
4667
 
4668
4669
 
4670
4671
 
742 Rus 4672
     jne   no_get_keyboard_cas
1 ha 4673
4674
 
4675
;     movzx eax,byte [shift]
4676
;     movzx ebx,byte [ctrl]
4677
;     shl   ebx,2
4678
;     add   eax,ebx
4679
;     movzx ebx,byte [alt]
4680
;     shl   ebx,3
4681
;     add   eax,ebx
4682
4683
 
4684
     mov   eax, [kb_state]
4685
 ;// mike.dld ]
4686
4687
 
4688
4689
 
4690
4691
 
4692
4693
 
742 Rus 4694
	jnz	no_add_keyboard_hotkey
4695
1 ha 4696
 
742 Rus 4697
@@:
92 diamond 4698
	cmp	dword [eax+8], 0
742 Rus 4699
	jz	.found_free
4700
	add	eax, 16
4701
	cmp	eax, hotkey_list+16*256
4702
	jb	@b
4703
	mov	dword [esp+36], 1
4704
	ret
4705
.found_free:
92 diamond 4706
	mov	[eax+8], edi
742 Rus 4707
	mov	[eax+4], ecx
4708
	movzx	ebx, bl
4709
	lea	ebx, [hotkey_scancodes+ebx*4]
4710
	mov	ecx, [ebx]
4711
	mov	[eax], ecx
4712
	mov	[ebx], eax
4713
	mov	[eax+12], ebx
4714
	jecxz	@f
4715
	mov	[ecx+12], eax
4716
@@:
92 diamond 4717
	and	dword [esp+36], 0
742 Rus 4718
	ret
4719
92 diamond 4720
 
4721
4722
 
742 Rus 4723
	jnz	no_del_keyboard_hotkey
4724
92 diamond 4725
 
742 Rus 4726
	lea	ebx, [hotkey_scancodes+ebx*4]
4727
	mov	eax, [ebx]
4728
.scan:
92 diamond 4729
	test	eax, eax
742 Rus 4730
	jz	.notfound
4731
	cmp	[eax+8], edi
4732
	jnz	.next
4733
	cmp	[eax+4], ecx
4734
	jz	.found
4735
.next:
92 diamond 4736
	mov	eax, [eax]
742 Rus 4737
	jmp	.scan
4738
.notfound:
92 diamond 4739
	mov	dword [esp+36], 1
742 Rus 4740
	ret
4741
.found:
92 diamond 4742
	mov	ecx, [eax]
742 Rus 4743
	jecxz	@f
4744
	mov	edx, [eax+12]
4745
	mov	[ecx+12], edx
4746
@@:
92 diamond 4747
	mov	ecx, [eax+12]
742 Rus 4748
	mov	edx, [eax]
4749
	mov	[ecx], edx
4750
	xor	edx, edx
4751
	mov	[eax+4], edx
4752
	mov	[eax+8], edx
4753
	mov	[eax+12], edx
4754
	mov	[eax], edx
4755
	mov	[esp+36], edx
4756
	ret
4757
92 diamond 4758
 
4759
     ret
1 ha 4760
4761
 
4762
 
4763
4764
 
742 Rus 4765
1 ha 4766
 
742 Rus 4767
     jne  no_gs1
1 ha 4768
     mov  eax,[Screen_Max_X]
753 serge 4769
     shl  eax,16
1 ha 4770
     mov  ax,[Screen_Max_Y]
753 serge 4771
     add  eax,0x00010001
1 ha 4772
     mov  [esp+36],eax
4773
     ret
4774
   no_gs1:
4775
4776
 
742 Rus 4777
     jne   no_gs2
1 ha 4778
     movzx eax,byte [ScreenBPP]
381 serge 4779
     mov   [esp+36],eax
1 ha 4780
     ret
4781
   no_gs2:
4782
4783
 
742 Rus 4784
     jne   no_gs3
1 ha 4785
     mov   eax,[BytesPerScanLine]
381 serge 4786
     mov   [esp+36],eax
1 ha 4787
     ret
4788
   no_gs3:
4789
4790
 
4791
     ret
4792
4793
 
4794
 
4795
4796
 
4797
4798
 
4799
     mov   [esp+36],eax
4800
     ret
4801
4802
 
4803
 
4804
4805
 
742 Rus 4806
1 ha 4807
 
742 Rus 4808
	mov	ebx, ecx
4809
	mov	ecx, edx
4810
	mov	edx, [TASK_BASE]
4811
	add	eax, [edx-twdw+WDATA.box.left]
4812
	add	ebx, [edx-twdw+WDATA.box.top]
4813
	mov	edi, [current_slot]
4814
	add	eax, [edi+APPDATA.wnd_clientbox.left]
4815
	add	ebx, [edi+APPDATA.wnd_clientbox.top]
4816
	xor	edi, edi ; no force
4817
;       mov     edi, 1
684 diamond 4818
	call	[disable_mouse]
742 Rus 4819
	jmp	[putpixel]
4820
1 ha 4821
 
4822
4823
 
742 Rus 4824
1 ha 4825
 
742 Rus 4826
	mov   ebp,[eax-twdw+WDATA.box.left]
4827
	push  esi
4828
	mov   esi,[current_slot]
4829
	add   ebp,[esi+APPDATA.wnd_clientbox.left]
4830
	shl   ebp,16
4831
	add   ebp,[eax-twdw+WDATA.box.top]
4832
	add   bp,word[esi+APPDATA.wnd_clientbox.top]
4833
	pop   esi
4834
	add   ebx,ebp
4835
	mov   eax,edi
4836
	xor   edi,edi
4837
	jmp   dtext
4838
1 ha 4839
 
4840
4841
 
742 Rus 4842
1 ha 4843
 
742 Rus 4844
	mov	ebx, ecx
4845
	mov	ecx, edx
4846
	mov	edx, esi
4847
	mov	esi, 12
4848
	call	fileread
4849
	mov	[esp+32], eax
4850
	ret
4851
1 ha 4852
 
4853
4854
 
742 Rus 4855
1 ha 4856
 
671 Ghost 4857
	and	edi, 0x80FFFFFF
4858
	test	bx, bx	; x.size
4859
	je	.drectr
4860
	test	cx, cx ; y.size
4861
	je	.drectr
4862
1 ha 4863
 
671 Ghost 4864
	mov	ebx, ecx
4865
1 ha 4866
 
671 Ghost 4867
	shr	eax, 16 ; eax - x.coord
4868
	movzx	edx, bx ; edx - y.size
4869
	shr	ebx, 16 ; ebx - y.coord
4870
	mov	esi, [current_slot]
4871
1 ha 4872
 
671 Ghost 4873
	add	ebx, [esi + APPDATA.wnd_clientbox.top]
4874
	add	ecx, eax
4875
	add	edx, ebx
4876
	jmp	[drawbar]
4877
.drectr:
4878
	ret
4879
1 ha 4880
 
4881
syscall_getscreensize:			; GetScreenSize
742 Rus 4882
	mov	ax, [Screen_Max_X]
759 Rus 4883
	shl	eax, 16
671 Ghost 4884
	mov	ax, [Screen_Max_Y]
759 Rus 4885
	mov	[esp + 32], eax
671 Ghost 4886
	ret
4887
1 ha 4888
 
671 Ghost 4889
4890
 
742 Rus 4891
1 ha 4892
 
742 Rus 4893
	jb	.audio
4894
	jz	.eject
4895
	cmp	eax, 5
4896
	jnz	.ret
4897
.load:
588 diamond 4898
	call	.reserve
742 Rus 4899
	call	LoadMedium
4900
	call	.free
4901
	ret
4902
.eject:
588 diamond 4903
	call	.reserve
742 Rus 4904
	call	clear_CD_cache
4905
	call	allow_medium_removal
4906
	call	EjectMedium
4907
	call	.free
4908
	ret
4909
.audio:
588 diamond 4910
     call  sys_cd_audio
1 ha 4911
     mov   [esp+36],eax
4912
.ret:
588 diamond 4913
     ret
1 ha 4914
4915
 
588 diamond 4916
	call	reserve_cd
742 Rus 4917
	mov	eax, ebx
4918
	shr	eax, 1
4919
	and	eax, 1
4920
	inc	eax
4921
	mov	[ChannelNumber], ax
4922
	mov	eax, ebx
4923
	and	eax, 1
4924
	mov	[DiskNumber], al
4925
	call	reserve_cd_channel
4926
	and	ebx, 3
4927
	inc	ebx
4928
	mov	[cdpos], ebx
4929
	add	ebx, ebx
4930
	mov	cl, 8
4931
	sub	cl, bl
4932
	mov	al, [DRIVE_DATA+1]
4933
	shr	al, cl
4934
	test	al, 2
4935
	jz	.err
4936
	ret
4937
.free:
588 diamond 4938
	call	free_cd_channel
742 Rus 4939
	and	[cd_status], 0
4940
	ret
4941
.err:
590 diamond 4942
	call	.free
742 Rus 4943
	pop	eax
4944
	ret
4945
588 diamond 4946
 
1 ha 4947
4948
 
742 Rus 4949
     mov   ecx, [Screen_Max_X]
753 serge 4950
     inc   ecx
1 ha 4951
     xor   edx, edx
671 Ghost 4952
     mov   eax, ebx
4953
     div   ecx
1 ha 4954
     mov   ebx, edx
671 Ghost 4955
     xchg  eax, ebx
4956
     call  dword [GETPIXEL] ; eax - x, ebx - y
4957
     mov   [esp + 32], ecx
4958
     ret
1 ha 4959
4960
 
4961
 
4962
4963
 
742 Rus 4964
1 ha 4965
 
671 Ghost 4966
	movzx	eax, word[edi-twdw+WDATA.box.left]
752 Lrz 4967
	mov	ebp, eax
4968
	mov	esi, [current_slot]
671 Ghost 4969
	add	ebp, [esi+APPDATA.wnd_clientbox.left]
4970
	add	ax, word[esi+APPDATA.wnd_clientbox.left]
752 Lrz 4971
	add	ebp,ebx
4972
	shl	eax, 16
4973
	movzx	ebx, word[edi-twdw+WDATA.box.top]
4974
	add	eax, ebp
671 Ghost 4975
	mov	ebp, ebx
752 Lrz 4976
	add	ebp, [esi+APPDATA.wnd_clientbox.top]
671 Ghost 4977
	add	bx, word[esi+APPDATA.wnd_clientbox.top]
752 Lrz 4978
	add	ebp, ecx
759 Rus 4979
	shl	ebx, 16
752 Lrz 4980
	xor	edi, edi
671 Ghost 4981
	add	ebx, ebp
752 Lrz 4982
	mov	ecx, edx
4983
	jmp	[draw_line]
671 Ghost 4984
1 ha 4985
 
4986
4987
 
742 Rus 4988
4989
 
4990
     jae   .err
75 diamond 4991
742 Rus 4992
 
774 Rus 4993
     je    .err
4994
4995
 
742 Rus 4996
     mov   [esp+32],eax
4997
4998
 
1 ha 4999
.err:
75 diamond 5000
     or    dword [esp+32], -1
742 Rus 5001
     ret
75 diamond 5002
1 ha 5003
 
5004
5005
 
742 Rus 5006
1 ha 5007
 
5008
     mov   [esp+36],eax
5009
     ret
5010
5011
 
5012
5013
 
742 Rus 5014
1 ha 5015
 
5016
     mov   [esp+36],eax
5017
     ret
5018
5019
 
5020
5021
 
5022
5023
 
742 Rus 5024
1 ha 5025
 
5026
;     call  change_task                 ; between sent packet
5027
5028
 
5029
     ret
5030
5031
 
5032
5033
 
742 Rus 5034
     call  app_socket_handler
1 ha 5035
5036
 
5037
;     call  change_task                 ; between sent packet
5038
5039
 
5040
     mov   [esp+24],ebx
5041
     ret
5042
5043
 
5044
5045
 
742 Rus 5046
1 ha 5047
 
379 serge 5048
     add   edi,TASKDATA.mem_start
115 poddubny 5049
     add   eax,[edi]
1 ha 5050
     add   ecx,[edi]
5051
     add   edx,[edi]
5052
     call  file_read
5053
5054
 
5055
     mov   [esp+24],ebx
5056
5057
 
5058
5059
 
375 Ghost 5060
	ret
742 Rus 5061
378 serge 5062
 
757 serge 5063
set_screen:
5064
	cmp eax, [Screen_Max_X]
759 Rus 5065
	jne .set
5066
709 diamond 5067
 
759 Rus 5068
	jne .set
5069
	ret
5070
.set:
757 serge 5071
	pushfd
759 Rus 5072
	cli
5073
757 serge 5074
 
759 Rus 5075
	mov [Screen_Max_Y], edx
5076
757 serge 5077
 
759 Rus 5078
	mov [screen_workarea.bottom], edx
5079
	inc eax
5080
	shl eax, 2			;32 bpp
5081
	mov [BytesPerScanLine], eax
5082
	push ebx
5083
	push esi
5084
	push edi
5085
	call	repos_windows
5086
	mov	eax, 0
5087
	mov	ebx, 0
5088
	mov	ecx, [Screen_Max_X]
5089
	mov	edx, [Screen_Max_Y]
5090
	call	calculatescreen
5091
	pop edi
5092
	pop esi
5093
	pop ebx
5094
757 serge 5095
 
759 Rus 5096
	ret
5097
757 serge 5098
 
76 mario79 5099
apm_entry    dp    0
5100
apm_vf	      dd    0
742 Rus 5101
align 4
1 ha 5102
sys_apm:
76 mario79 5103
    cmp    word [apm_vf], 0    ; Check APM BIOS enable
5104
    jne    @f
5105
    or	  [esp + 56], byte 1	; error
742 Rus 5106
    mov    [esp + 36], dword 8	  ; 32-bit protected-mode interface not supported
5107
    ret
76 mario79 5108
164 serge 5109
 
465 serge 5110
    xchg    eax, ecx
5111
    xchg    ebx, ecx
76 mario79 5112
164 serge 5113
 
76 mario79 5114
    ja	  @f
742 Rus 5115
    and    [esp + 56], byte 0xfe    ; emulate func 0..3 as func 0
78 diamond 5116
    mov    eax, [apm_vf]
76 mario79 5117
    mov    [esp + 36], eax
5118
    shr    eax, 16
5119
    mov    [esp + 32], eax
5120
    ret
5121
78 diamond 5122
 
465 serge 5123
5124
 
5125
    xchg [master_tab], esi
5126
    push esi
5127
    mov edi, cr3
5128
    mov cr3, edi		 ;flush TLB
742 Rus 5129
465 serge 5130
 
742 Rus 5131
465 serge 5132
 
5133
    mov [master_tab], eax
5134
    mov eax, cr3
5135
    mov cr3, eax
5136
    pop eax
5137
5138
 
76 mario79 5139
    mov    [esp + 12], esi
5140
    mov    [esp + 24], ebx
5141
    mov    [esp + 28], edx
5142
    mov    [esp + 32], ecx
5143
    mov    [esp + 36], eax
5144
    setc    al
5145
    and    [esp + 56], byte 0xfe
78 diamond 5146
    or	  [esp + 56], al
742 Rus 5147
465 serge 5148
 
5149
 
76 mario79 5150
; -----------------------------------------
5151
1 ha 5152
 
76 mario79 5153
5154
 
742 Rus 5155
     mov   [esp + 32], dword -1
671 Ghost 5156
     ret
1 ha 5157
5158
 
465 serge 5159
system_shutdown:	  ; shut down the system
742 Rus 5160
1 ha 5161
 
742 Rus 5162
	   jne @F
5163
	   ret
5164
@@:
465 serge 5165
	   call stop_all_services
742 Rus 5166
	   push 3		 ; stop playing cd
5167
	   pop	eax
5168
	   call sys_cd_audio
5169
1 ha 5170
 
465 serge 5171
863 serge 5172
 
742 Rus 5173
1 ha 5174
 
863 serge 5175
           je _sys_reboot
5176
1 ha 5177
 
863 serge 5178
           je _sys_restart
5179
1 ha 5180
 
863 serge 5181
           mov  esi, BOOT_VAR    ; restore 0x0 - 0xffff
855 serge 5182
           mov  edi, OS_BASE
847 serge 5183
           mov  ecx,0x10000/4
5184
           rep movsd
5185
1 ha 5186
 
863 serge 5187
           mov ecx, _16bit_end
5188
           shr ecx, 2
5189
           mov edi, _16BIT_BASE + OS_BASE
5190
           rep movsd
5191
1 ha 5192
 
863 serge 5193
           mov eax, _sys_pdbr + (0x100000000-OS_BASE)
5194
           mov cr3, eax
5195
1 ha 5196
 
863 serge 5197
1 ha 5198
 
5199
 
863 serge 5200
709 diamond 5201
 
863 serge 5202
           mov dx,app_data
5203
	   mov ss,ax
5204
           mov esp, __os_stack
5205
1 ha 5206
 
863 serge 5207
           mov es, dx
5208
           mov fs, dx
5209
           mov gs, dx
5210
1 ha 5211
 
863 serge 5212
709 diamond 5213
 
863 serge 5214
           mov  esi, BOOT_VAR    ; restore 0x0 - 0xffff
5215
           mov  edi, OS_BASE
5216
           mov  ecx,0x10000/4
5217
           rep movsd
5218
709 diamond 5219
 
863 serge 5220
           mov [_pg_balloc], eax
5221
709 diamond 5222
 
863 serge 5223
           mov eax, _sys_pdbr + (0x100000000-OS_BASE)
5224
           mov cr3, eax
5225
5226
 
5227
           mov edi, cur_saved_data
5228
           sub edi, OS_BASE
5229
           sub ecx, edi
5230
           shr ecx, 2
5231
           xor eax, eax
5232
           rep stosd
5233
5234
 
5235
5236
 
5237
5238
 
5239
           mov  word [OS_BASE+0x467+0],0xFFF0
5240
           mov  word [OS_BASE+0x467+2],0xF000
5241
5242
 
742 Rus 5243
	   out	0x70,al
5244
	   mov	al,0x05
5245
	   out	0x71,al
5246
709 diamond 5247
 
742 Rus 5248
	   out	0x64,al
5249
709 diamond 5250
 
742 Rus 5251
709 diamond 5252
 
465 serge 5253
1 ha 5254
 
465 serge 5255
1 ha 5256
 
849 serge 5257
;diff16 "end of kernel code",0,$
5258