Subversion Repositories Kolibri OS

Rev

Rev 890 | Rev 897 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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