Subversion Repositories Kolibri OS

Rev

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