Subversion Repositories Kolibri OS

Rev

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