Subversion Repositories Kolibri OS

Rev

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