Subversion Repositories Kolibri OS

Rev

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

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