Subversion Repositories Kolibri OS

Rev

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