Subversion Repositories Kolibri OS

Rev

Rev 759 | Rev 764 | 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: 760 $
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
 
759 Rus 348
	xchg bx, bx
753 serge 349
 
742 Rus 350
	movzx eax,word [BOOT_VAR+0x900A]  ; X max
351
	dec   eax
759 Rus 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
759 Rus 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
759 Rus 1132
	mov   eax,[Screen_Max_X]
742 Rus 1133
	shr   eax,1
1134
	mov   [MOUSE_X],ax
759 Rus 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:
759 Rus 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
 
759 Rus 2067
sysfn_shutdown: 	 ; 18.9 = system shutdown
748 heavyiron 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
759 Rus 2886
	mov	eax, [Screen_Max_X]
671 Ghost 2887
	mov	[edx + RECT.right], eax
759 Rus 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
 
759 Rus 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:
760 Rus 3936
     movzx esi, bh			 ; save number of subfunction, if bh = 1, return data size, otherwise, read data
3937
     xor   bh, bh
3938
     cmp   ebx, 16
75 diamond 3939
     jae   .not_owner
760 Rus 3940
     mov   edx, [4 * ebx + irq_owner]	 ; check for irq owner
742 Rus 3941
 
760 Rus 3942
     mov   eax,[TASK_BASE]
742 Rus 3943
 
760 Rus 3944
     cmp   edx,[eax+TASKDATA.pid]
1 ha 3945
     je    gidril1
75 diamond 3946
.not_owner:
760 Rus 3947
     xor   edx, edx
3948
     dec   edx
3949
     jmp   gid1
1 ha 3950
 
3951
  gidril1:
3952
 
760 Rus 3953
     shl   ebx, 12
3954
     lea   eax, [ebx + IRQ_SAVE]	 ; calculate address of the beginning of buffer + 0x0 - data size
3955
     mov   edx, [eax]			 ;                                              + 0x4 - data offset
3956
     dec   esi
1 ha 3957
     jz    gid1
760 Rus 3958
     test  edx, edx			 ; check if buffer is empty
3959
     jz    gid1
1 ha 3960
 
760 Rus 3961
     mov   ebx, [eax + 0x4]
3962
     mov   edi, ecx
742 Rus 3963
 
760 Rus 3964
     mov   ecx, 4000			 ; buffer size, used frequently
742 Rus 3965
 
760 Rus 3966
     cmp   ebx, ecx			 ; check for the end of buffer, if end of buffer, begin cycle again
759 Rus 3967
     jb    @f
742 Rus 3968
 
760 Rus 3969
     xor   ebx, ebx
759 Rus 3970
 
3971
   @@:
3972
 
760 Rus 3973
     lea   esi, [ebx + edx]		 ; calculate data size and offset
3974
     cld
3975
     cmp   esi, ecx			 ; if greater than the buffer size, begin cycle again
3976
     jbe   @f
759 Rus 3977
 
760 Rus 3978
     sub   ecx, ebx
3979
     sub   edx, ecx
759 Rus 3980
 
760 Rus 3981
     lea   esi, [eax + ebx + 0x10]
3982
     rep   movsb
3983
 
3984
     xor   ebx, ebx
3985
   @@:
3986
     lea   esi, [eax + ebx + 0x10]
3987
     mov   ecx, edx
3988
     add   ebx, edx
3989
 
3990
     rep   movsb
3991
     mov   edx, [eax]
3992
     mov   [eax], ecx			 ; set data size to zero
3993
     mov   [eax + 0x4], ebx		 ; set data offset
3994
 
1 ha 3995
   gid1:
760 Rus 3996
     mov   [esp+32], edx		 ; eax
1 ha 3997
     ret
3998
 
3999
 
4000
set_io_access_rights:
4001
 
4002
     pushad
4003
 
465 serge 4004
     mov edi, tss._io_map_0
1 ha 4005
 
465 serge 4006
;     mov   ecx,eax
4007
;     and   ecx,7    ; offset in byte
1 ha 4008
 
465 serge 4009
;     shr   eax,3    ; number of byte
4010
;     add   edi,eax
1 ha 4011
 
465 serge 4012
;     mov   ebx,1
4013
;     shl   ebx,cl
1 ha 4014
 
742 Rus 4015
     cmp   ebp,0		; enable access - ebp = 0
1 ha 4016
     jne   siar1
4017
 
465 serge 4018
;     not   ebx
4019
;     and   [edi],byte bl
4020
     btr [edi], eax
1 ha 4021
 
4022
     popad
4023
 
4024
     ret
4025
 
465 serge 4026
siar1:
1 ha 4027
 
465 serge 4028
     bts [edi], eax
4029
  ;  or    [edi],byte bl        ; disable access - ebp = 1
1 ha 4030
 
4031
     popad
4032
 
4033
     ret
4034
 
4035
r_f_port_area:
4036
 
4037
     test  eax, eax
4038
     jnz   free_port_area
4039
;     je    r_port_area
4040
;     jmp   free_port_area
4041
 
4042
;   r_port_area:
4043
 
4044
     pushad
4045
 
742 Rus 4046
     cmp   ebx,ecx	      ; beginning > end ?
75 diamond 4047
     ja    rpal1
4048
     cmp   ecx,65536
4049
     jae   rpal1
381 serge 4050
     mov   esi,[RESERVED_PORTS]
742 Rus 4051
     test  esi,esi	      ; no reserved areas ?
1 ha 4052
     je    rpal2
742 Rus 4053
     cmp   esi,255	      ; max reserved
75 diamond 4054
     jae   rpal1
465 serge 4055
 rpal3:
1 ha 4056
     mov   edi,esi
4057
     shl   edi,4
381 serge 4058
     add   edi,RESERVED_PORTS
1 ha 4059
     cmp   ebx,[edi+8]
75 diamond 4060
     ja    rpal4
1 ha 4061
     cmp   ecx,[edi+4]
4062
     jae   rpal1
4063
;     jb    rpal4
4064
;     jmp   rpal1
465 serge 4065
 rpal4:
1 ha 4066
 
4067
     dec   esi
4068
     jnz   rpal3
4069
     jmp   rpal2
4070
   rpal1:
4071
     popad
4072
     mov   eax,1
4073
     ret
4074
 
4075
   rpal2:
4076
     popad
4077
 
4078
 
4079
     ; enable port access at port IO map
4080
     cli
742 Rus 4081
     pushad			   ; start enable io map
1 ha 4082
 
4083
     cmp   ecx,65536 ;16384
4084
     jae   no_unmask_io ; jge
4085
 
4086
     mov   eax,ebx
4087
 
4088
   new_port_access:
4089
 
4090
     pushad
4091
 
742 Rus 4092
     xor   ebp,ebp		  ; enable - eax = port
1 ha 4093
     call  set_io_access_rights
4094
 
4095
     popad
4096
 
4097
     inc   eax
4098
     cmp   eax,ecx
4099
     jbe   new_port_access
4100
 
4101
   no_unmask_io:
4102
 
742 Rus 4103
     popad			   ; end enable io map
1 ha 4104
     sti
4105
 
381 serge 4106
     mov   edi,[RESERVED_PORTS]
1 ha 4107
     add   edi,1
381 serge 4108
     mov   [RESERVED_PORTS],edi
1 ha 4109
     shl   edi,4
381 serge 4110
     add   edi,RESERVED_PORTS
379 serge 4111
     mov   esi,[TASK_BASE]
115 poddubny 4112
     mov   esi,[esi+TASKDATA.pid]
1 ha 4113
     mov   [edi],esi
4114
     mov   [edi+4],ebx
4115
     mov   [edi+8],ecx
4116
 
4117
     xor   eax, eax
4118
     ret
4119
 
4120
free_port_area:
4121
 
4122
     pushad
4123
 
381 serge 4124
     mov   esi,[RESERVED_PORTS]     ; no reserved areas ?
75 diamond 4125
     test  esi,esi
1 ha 4126
     je    frpal2
379 serge 4127
     mov   edx,[TASK_BASE]
115 poddubny 4128
     mov   edx,[edx+TASKDATA.pid]
1 ha 4129
   frpal3:
4130
     mov   edi,esi
4131
     shl   edi,4
381 serge 4132
     add   edi,RESERVED_PORTS
1 ha 4133
     cmp   edx,[edi]
4134
     jne   frpal4
4135
     cmp   ebx,[edi+4]
4136
     jne   frpal4
4137
     cmp   ecx,[edi+8]
4138
     jne   frpal4
4139
     jmp   frpal1
4140
   frpal4:
4141
     dec   esi
4142
     jnz   frpal3
4143
   frpal2:
4144
     popad
4145
     mov   eax,1
4146
     ret
4147
   frpal1:
4148
     mov   ecx,256
4149
     sub   ecx,esi
4150
     shl   ecx,4
4151
     mov   esi,edi
4152
     add   esi,16
4153
     cld
4154
     rep   movsb
4155
 
381 serge 4156
     dec   dword [RESERVED_PORTS]
1 ha 4157
 
4158
     popad
4159
 
4160
 
4161
     ; disable port access at port IO map
4162
 
742 Rus 4163
     pushad			   ; start disable io map
1 ha 4164
 
4165
     cmp   ecx,65536 ;16384
4166
     jge   no_mask_io
4167
 
4168
     mov   eax,ebx
4169
 
4170
   new_port_access_disable:
4171
 
4172
     pushad
4173
 
742 Rus 4174
     mov   ebp,1		  ; disable - eax = port
1 ha 4175
     call  set_io_access_rights
4176
 
4177
     popad
4178
 
4179
     inc   eax
4180
     cmp   eax,ecx
4181
     jbe   new_port_access_disable
4182
 
4183
   no_mask_io:
4184
 
742 Rus 4185
     popad			   ; end disable io map
1 ha 4186
 
4187
     xor   eax, eax
4188
     ret
4189
 
4190
 
4191
reserve_free_irq:
4192
 
75 diamond 4193
     mov   ecx, 1
4194
     cmp   ebx, 16
4195
     jae   fril1
4196
     test  eax,eax
1 ha 4197
     jz    reserve_irq
4198
 
75 diamond 4199
     lea   edi,[irq_owner+ebx*4]
1 ha 4200
     mov   edx,[edi]
379 serge 4201
     mov   eax,[TASK_BASE]
115 poddubny 4202
     cmp   edx,[eax+TASKDATA.pid]
1 ha 4203
     jne   fril1
75 diamond 4204
     dec   ecx
4205
     mov   [edi],ecx
1 ha 4206
   fril1:
4207
     mov   [esp+36],ecx ; return in eax
4208
     ret
4209
 
4210
  reserve_irq:
4211
 
75 diamond 4212
     lea   edi,[irq_owner+ebx*4]
4213
     cmp   dword [edi], 0
4214
     jnz   ril1
1 ha 4215
 
379 serge 4216
     mov   edx,[TASK_BASE]
115 poddubny 4217
     mov   edx,[edx+TASKDATA.pid]
1 ha 4218
     mov   [edi],edx
75 diamond 4219
     dec   ecx
1 ha 4220
   ril1:
4221
     mov   [esp+36],ecx ; return in eax
4222
     ret
4223
 
4224
drawbackground:
33 mario79 4225
       inc   [mouse_pause]
381 serge 4226
       cmp   [SCR_MODE],word 0x12
117 mario79 4227
       je   dbrv20
1 ha 4228
     dbrv12:
381 serge 4229
       cmp  [SCR_MODE],word 0100000000000000b
1 ha 4230
       jge  dbrv20
381 serge 4231
       cmp  [SCR_MODE],word 0x13
1 ha 4232
       je   dbrv20
4233
       call  vesa12_drawbackground
33 mario79 4234
       dec   [mouse_pause]
36 mario79 4235
       call   [draw_pointer]
1 ha 4236
       ret
4237
     dbrv20:
527 diamond 4238
       cmp   [BgrDrawMode],dword 1
1 ha 4239
       jne   bgrstr
4240
       call  vesa20_drawbackground_tiled
33 mario79 4241
       dec   [mouse_pause]
36 mario79 4242
       call   [draw_pointer]
1 ha 4243
       ret
4244
     bgrstr:
4245
       call  vesa20_drawbackground_stretch
33 mario79 4246
       dec   [mouse_pause]
36 mario79 4247
       call   [draw_pointer]
1 ha 4248
       ret
4249
 
75 diamond 4250
align 4
1 ha 4251
 
742 Rus 4252
syscall_putimage:			; PutImage
1 ha 4253
sys_putimage:
53 mikedld 4254
     test  ecx,0x80008000
4255
     jnz   .exit
4256
     test  ecx,0x0000FFFF
4257
     jz    .exit
4258
     test  ecx,0xFFFF0000
4259
     jnz   @f
4260
  .exit:
4261
     ret
4262
 @@:
742 Rus 4263
	mov	edi,[current_slot]
4264
	add	dx,word[edi+APPDATA.wnd_clientbox.top]
4265
	rol	edx,16
4266
	add	dx,word[edi+APPDATA.wnd_clientbox.left]
4267
	rol	edx,16
114 mikedld 4268
  .forced:
742 Rus 4269
	push	ebp esi 0
4270
	mov	ebp, putimage_get24bpp
4271
	mov	esi, putimage_init24bpp
283 diamond 4272
sys_putimage_bpp:
4273
;        call    [disable_mouse] ; this will be done in xxx_putimage
117 mario79 4274
;        mov     eax, vga_putimage
742 Rus 4275
	cmp	[SCR_MODE], word 0x12
4276
	jz	@f   ;.doit
4277
	mov	eax, vesa12_putimage
4278
	cmp	[SCR_MODE], word 0100000000000000b
4279
	jae	@f
4280
	cmp	[SCR_MODE], word 0x13
4281
	jnz	.doit
75 diamond 4282
@@:
742 Rus 4283
	mov	eax, vesa20_putimage
75 diamond 4284
.doit:
742 Rus 4285
	inc	[mouse_pause]
4286
	call	eax
4287
	dec	[mouse_pause]
4288
	pop	ebp esi ebp
4289
	jmp	[draw_pointer]
1 ha 4290
 
283 diamond 4291
syscall_putimage_palette:
742 Rus 4292
	mov	edi, esi
4293
	mov	esi, edx
4294
	mov	edx, ecx
4295
	mov	ecx, ebx
4296
	mov	ebx, eax
283 diamond 4297
sys_putimage_palette:
4298
; ebx = pointer to image
4299
; ecx = [xsize]*65536 + [ysize]
4300
; edx = [xstart]*65536 + [ystart]
314 diamond 4301
; esi = number of bits per pixel, must be 8, 24 or 32
283 diamond 4302
; edi = pointer to palette
314 diamond 4303
; ebp = row delta
742 Rus 4304
	mov	eax, [CURRENT_TASK]
4305
	shl	eax, 8
4306
	add	dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
4307
	rol	edx, 16
4308
	add	dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
4309
	rol	edx, 16
283 diamond 4310
.forced:
742 Rus 4311
	push	ebp esi ebp
4312
	cmp	esi, 8
4313
	jnz	@f
4314
	mov	ebp, putimage_get8bpp
4315
	mov	esi, putimage_init8bpp
4316
	jmp	sys_putimage_bpp
314 diamond 4317
@@:
742 Rus 4318
	cmp	esi, 24
4319
	jnz	@f
4320
	mov	ebp, putimage_get24bpp
4321
	mov	esi, putimage_init24bpp
4322
	jmp	sys_putimage_bpp
314 diamond 4323
@@:
742 Rus 4324
	cmp	esi, 32
4325
	jnz	@f
4326
	mov	ebp, putimage_get32bpp
4327
	mov	esi, putimage_init32bpp
4328
	jmp	sys_putimage_bpp
314 diamond 4329
@@:
742 Rus 4330
	pop	ebp esi
4331
	ret
283 diamond 4332
 
4333
putimage_init24bpp:
742 Rus 4334
	lea	eax, [eax*3]
283 diamond 4335
putimage_init8bpp:
742 Rus 4336
	ret
283 diamond 4337
 
4338
putimage_get24bpp:
742 Rus 4339
	mov	eax, [esi]
4340
	add	esi, 3
4341
	ret	4
283 diamond 4342
putimage_get8bpp:
742 Rus 4343
	movzx	eax, byte [esi]
4344
	push	edx
4345
	mov	edx, [esp+8]
4346
	mov	eax, [edx+eax*4]
4347
	pop	edx
4348
	inc	esi
4349
	ret	4
283 diamond 4350
 
314 diamond 4351
putimage_init32bpp:
742 Rus 4352
	shl	eax, 2
4353
	ret
314 diamond 4354
putimage_get32bpp:
742 Rus 4355
	lodsd
4356
	ret	4
314 diamond 4357
 
1 ha 4358
; eax x beginning
4359
; ebx y beginning
4360
; ecx x end
283 diamond 4361
	; edx y end
1 ha 4362
; edi color
4363
 
4364
__sys_drawbar:
742 Rus 4365
	mov	esi,[current_slot]
4366
	add	eax,[esi+APPDATA.wnd_clientbox.left]
4367
	add	ecx,[esi+APPDATA.wnd_clientbox.left]
4368
	add	ebx,[esi+APPDATA.wnd_clientbox.top]
4369
	add	edx,[esi+APPDATA.wnd_clientbox.top]
114 mikedld 4370
  .forced:
33 mario79 4371
    inc   [mouse_pause]
283 diamond 4372
;        call    [disable_mouse]
381 serge 4373
    cmp   [SCR_MODE],word 0x12
742 Rus 4374
    je	 dbv20
1 ha 4375
   sdbv20:
381 serge 4376
    cmp  [SCR_MODE],word 0100000000000000b
1 ha 4377
    jge  dbv20
381 serge 4378
    cmp  [SCR_MODE],word 0x13
742 Rus 4379
    je	 dbv20
1 ha 4380
    call vesa12_drawbar
33 mario79 4381
    dec   [mouse_pause]
36 mario79 4382
    call   [draw_pointer]
1 ha 4383
    ret
4384
  dbv20:
4385
    call vesa20_drawbar
33 mario79 4386
    dec   [mouse_pause]
36 mario79 4387
    call   [draw_pointer]
1 ha 4388
    ret
4389
 
4390
 
4391
 
4392
kb_read:
4393
 
742 Rus 4394
	push	ecx edx
1 ha 4395
 
742 Rus 4396
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4397
      kr_loop:
742 Rus 4398
	in	al,0x64
4399
	test	al,1
4400
	jnz	kr_ready
4401
	loop	kr_loop
4402
	mov	ah,1
4403
	jmp	kr_exit
1 ha 4404
      kr_ready:
742 Rus 4405
	push	ecx
4406
	mov	ecx,32
1 ha 4407
      kr_delay:
742 Rus 4408
	loop	kr_delay
4409
	pop	ecx
4410
	in	al,0x60
4411
	xor	ah,ah
1 ha 4412
      kr_exit:
4413
 
742 Rus 4414
	pop	edx ecx
1 ha 4415
 
742 Rus 4416
	ret
1 ha 4417
 
4418
 
4419
kb_write:
4420
 
742 Rus 4421
	push	ecx edx
1 ha 4422
 
742 Rus 4423
	mov	dl,al
265 diamond 4424
;        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4425
;      kw_loop1:
4426
;        in      al,0x64
4427
;        test    al,0x20
4428
;        jz      kw_ok1
4429
;        loop    kw_loop1
4430
;        mov     ah,1
4431
;        jmp     kw_exit
4432
;      kw_ok1:
742 Rus 4433
	in	al,0x60
4434
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4435
      kw_loop:
742 Rus 4436
	in	al,0x64
4437
	test	al,2
4438
	jz	kw_ok
4439
	loop	kw_loop
4440
	mov	ah,1
4441
	jmp	kw_exit
1 ha 4442
      kw_ok:
742 Rus 4443
	mov	al,dl
4444
	out	0x60,al
4445
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4446
      kw_loop3:
742 Rus 4447
	in	al,0x64
4448
	test	al,2
4449
	jz	kw_ok3
4450
	loop	kw_loop3
4451
	mov	ah,1
4452
	jmp	kw_exit
1 ha 4453
      kw_ok3:
742 Rus 4454
	mov	ah,8
1 ha 4455
      kw_loop4:
742 Rus 4456
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4457
      kw_loop5:
742 Rus 4458
	in	al,0x64
4459
	test	al,1
4460
	jnz	kw_ok4
4461
	loop	kw_loop5
4462
	dec	ah
4463
	jnz	kw_loop4
1 ha 4464
      kw_ok4:
742 Rus 4465
	xor	ah,ah
1 ha 4466
      kw_exit:
4467
 
742 Rus 4468
	pop	edx ecx
1 ha 4469
 
742 Rus 4470
	ret
1 ha 4471
 
4472
 
4473
kb_cmd:
4474
 
742 Rus 4475
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4476
      c_wait:
742 Rus 4477
	in	al,0x64
4478
	test	al,2
4479
	jz	c_send
4480
	loop	c_wait
4481
	jmp	c_error
1 ha 4482
      c_send:
742 Rus 4483
	mov	al,bl
4484
	out	0x64,al
4485
	mov	ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4486
      c_accept:
742 Rus 4487
	in	al,0x64
4488
	test	al,2
4489
	jz	c_ok
4490
	loop	c_accept
1 ha 4491
      c_error:
742 Rus 4492
	mov	ah,1
4493
	jmp	c_exit
1 ha 4494
      c_ok:
742 Rus 4495
	xor	ah,ah
1 ha 4496
      c_exit:
742 Rus 4497
	ret
1 ha 4498
 
4499
 
4500
setmouse:  ; set mousepicture -pointer
742 Rus 4501
	   ; ps2 mouse enable
1 ha 4502
 
381 serge 4503
     mov     [MOUSE_PICTURE],dword mousepointer
1 ha 4504
 
4505
     cli
33 mario79 4506
;     mov     bl,0xa8                 ; enable mouse cmd
4507
;     call    kb_cmd
4508
;     call    kb_read                 ; read status
4509
;     mov     bl,0x20                 ; get command byte
4510
;     call    kb_cmd
4511
;     call    kb_read
4512
;     or      al,3                    ; enable interrupt
4513
;     mov     bl,0x60                 ; write command
4514
;     push    eax
4515
;     call    kb_cmd
4516
;     pop     eax
4517
;     call    kb_write
4518
;     mov     bl,0xd4                 ; for mouse
4519
;     call    kb_cmd
4520
;     mov     al,0xf4                 ; enable mouse device
4521
;     call    kb_write
4522
;     call    kb_read           ; read status return
1 ha 4523
 
4524
     ; com1 mouse enable
4525
 
4526
     mov   bx,0x3f8 ; combase
4527
 
4528
     mov   dx,bx
4529
     add   dx,3
4530
     mov   al,0x80
4531
     out   dx,al
4532
 
4533
     mov   dx,bx
4534
     add   dx,1
4535
     mov   al,0
4536
     out   dx,al
4537
 
4538
     mov   dx,bx
4539
     add   dx,0
742 Rus 4540
     mov   al,0x30*2	; 0x30 / 4
1 ha 4541
     out   dx,al
4542
 
4543
     mov   dx,bx
4544
     add   dx,3
742 Rus 4545
     mov   al,2 	; 3
1 ha 4546
     out   dx,al
4547
 
4548
     mov   dx,bx
4549
     add   dx,4
4550
     mov   al,0xb
4551
     out   dx,al
4552
 
4553
     mov   dx,bx
4554
     add   dx,1
4555
     mov   al,1
4556
     out   dx,al
4557
 
4558
 
4559
     ; com2 mouse enable
4560
 
4561
     mov   bx,0x2f8 ; combase
4562
 
4563
     mov   dx,bx
4564
     add   dx,3
4565
     mov   al,0x80
4566
     out   dx,al
4567
 
4568
     mov   dx,bx
4569
     add   dx,1
4570
     mov   al,0
4571
     out   dx,al
4572
 
4573
     mov   dx,bx
4574
     add   dx,0
4575
     mov   al,0x30*2
4576
     out   dx,al
4577
 
4578
     mov   dx,bx
4579
     add   dx,3
4580
     mov   al,2
4581
     out   dx,al
4582
 
4583
     mov   dx,bx
4584
     add   dx,4
4585
     mov   al,0xb
4586
     out   dx,al
4587
 
4588
     mov   dx,bx
4589
     add   dx,1
4590
     mov   al,1
4591
     out   dx,al
4592
 
4593
     ret
4594
 
4595
 
4596
_rdtsc:
164 serge 4597
     bt [cpu_caps], CAPS_TSC
4598
     jnc ret_rdtsc
1 ha 4599
     rdtsc
4600
     ret
4601
   ret_rdtsc:
4602
     mov   edx,0xffffffff
4603
     mov   eax,0xffffffff
4604
     ret
4605
 
4606
rerouteirqs:
4607
 
742 Rus 4608
	cli
1 ha 4609
 
742 Rus 4610
	mov	al,0x11 	;  icw4, edge triggered
4611
	out	0x20,al
4612
	call	pic_delay
4613
	out	0xA0,al
4614
	call	pic_delay
1 ha 4615
 
742 Rus 4616
	mov	al,0x20 	;  generate 0x20 +
4617
	out	0x21,al
4618
	call	pic_delay
4619
	mov	al,0x28 	;  generate 0x28 +
4620
	out	0xA1,al
4621
	call	pic_delay
1 ha 4622
 
742 Rus 4623
	mov	al,0x04 	;  slave at irq2
4624
	out	0x21,al
4625
	call	pic_delay
4626
	mov	al,0x02 	;  at irq9
4627
	out	0xA1,al
4628
	call	pic_delay
1 ha 4629
 
742 Rus 4630
	mov	al,0x01 	;  8086 mode
4631
	out	0x21,al
4632
	call	pic_delay
4633
	out	0xA1,al
4634
	call	pic_delay
1 ha 4635
 
742 Rus 4636
	mov	al,255		; mask all irq's
4637
	out	0xA1,al
4638
	call	pic_delay
4639
	out	0x21,al
4640
	call	pic_delay
1 ha 4641
 
742 Rus 4642
	mov	ecx,0x1000
4643
	cld
4644
picl1:	call	pic_delay
4645
	loop	picl1
1 ha 4646
 
742 Rus 4647
	mov	al,255		; mask all irq's
4648
	out	0xA1,al
4649
	call	pic_delay
4650
	out	0x21,al
4651
	call	pic_delay
1 ha 4652
 
742 Rus 4653
	cli
1 ha 4654
 
742 Rus 4655
	ret
1 ha 4656
 
4657
 
4658
pic_delay:
4659
 
742 Rus 4660
	jmp	pdl1
4661
pdl1:	ret
1 ha 4662
 
4663
 
4664
sys_msg_board_str:
4665
 
4666
     pushad
4667
   @@:
4668
     cmp    [esi],byte 0
4669
     je     @f
4670
     mov    eax,1
4671
     movzx  ebx,byte [esi]
4672
     call   sys_msg_board
4673
     inc    esi
4674
     jmp    @b
4675
   @@:
4676
     popad
4677
     ret
4678
 
709 diamond 4679
sys_msg_board_byte:
4680
; in: al = byte to display
4681
; out: nothing
4682
; destroys: nothing
742 Rus 4683
	pushad
4684
	mov	ecx, 2
4685
	shl	eax, 24
4686
	jmp	@f
709 diamond 4687
 
4688
sys_msg_board_word:
4689
; in: ax = word to display
4690
; out: nothing
4691
; destroys: nothing
742 Rus 4692
	pushad
4693
	mov	ecx, 4
4694
	shl	eax, 16
4695
	jmp	@f
709 diamond 4696
 
4697
sys_msg_board_dword:
4698
; in: eax = dword to display
4699
; out: nothing
4700
; destroys: nothing
742 Rus 4701
	pushad
4702
	mov	ecx, 8
709 diamond 4703
@@:
742 Rus 4704
	push	ecx
4705
	rol	eax, 4
4706
	push	eax
4707
	and	al, 0xF
4708
	cmp	al, 10
4709
	sbb	al, 69h
4710
	das
4711
	mov	bl, al
4712
	xor	eax, eax
4713
	inc	eax
4714
	call	sys_msg_board
4715
	pop	eax
4716
	pop	ecx
4717
	loop	@b
4718
	popad
4719
	ret
709 diamond 4720
 
1 ha 4721
uglobal
373 mikedld 4722
  msg_board_data: times 4096 db 0
1 ha 4723
  msg_board_count dd 0x0
4724
endg
4725
 
4726
sys_msg_board:
4727
 
4728
; eax=1 : write :  bl byte to write
4729
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4730
 
671 Ghost 4731
	mov	ecx, [msg_board_count]
4732
	cmp	eax, 1
4733
	jne	.smbl1
1 ha 4734
 
4735
 
671 Ghost 4736
	mov	[msg_board_data+ecx],bl
4737
	inc	ecx
4738
	and	ecx, 4095
4739
	mov	[msg_board_count], ecx
4740
	mov	[check_idle_semaphore], 5
4741
	ret
4742
.smbl1:
4743
	cmp	eax, 2
4744
	jne	.smbl2
4745
	test	ecx, ecx
4746
	jz	.smbl21
4747
	mov	eax, msg_board_data+1
4748
	mov	ebx, msg_board_data
4749
	movzx	edx, byte [ebx]
4750
	call	memmove
4751
	dec	[msg_board_count]
4752
	mov	[esp + 36], edx ;eax
4753
	mov	[esp + 24], dword 1
4754
	ret
4755
.smbl21:
4756
	mov	[esp+36], ecx
4757
	mov	[esp+24], ecx
4758
.smbl2:
4759
	ret
1 ha 4760
 
4761
 
4762
 
4763
sys_process_def:
742 Rus 4764
	mov	edi, [CURRENT_TASK]
1 ha 4765
 
742 Rus 4766
	dec	eax		; 1 = set keyboard mode
1 ha 4767
     jne   no_set_keyboard_setup
4768
 
4769
     shl   edi,8
380 serge 4770
     mov   [edi+SLOT_BASE + APPDATA.keyboard_mode],bl
1 ha 4771
 
4772
     ret
4773
 
4774
   no_set_keyboard_setup:
4775
 
742 Rus 4776
	dec	eax		; 2 = get keyboard mode
1 ha 4777
     jne   no_get_keyboard_setup
4778
 
4779
     shl   edi,8
380 serge 4780
     movzx eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
1 ha 4781
 
4782
     mov   [esp+36],eax
4783
 
4784
     ret
4785
 
4786
   no_get_keyboard_setup:
4787
 
742 Rus 4788
	dec	eax		; 3 = get keyboard ctrl, alt, shift
1 ha 4789
     jne   no_get_keyboard_cas
4790
 
4791
;     xor   eax,eax
4792
;     movzx eax,byte [shift]
4793
;     movzx ebx,byte [ctrl]
4794
;     shl   ebx,2
4795
;     add   eax,ebx
4796
;     movzx ebx,byte [alt]
4797
;     shl   ebx,3
4798
;     add   eax,ebx
4799
 
4800
 ;// mike.dld [
4801
     mov   eax, [kb_state]
4802
 ;// mike.dld ]
4803
 
4804
     mov   [esp+36],eax
4805
 
4806
     ret
4807
 
4808
   no_get_keyboard_cas:
4809
 
742 Rus 4810
	dec	eax
4811
	jnz	no_add_keyboard_hotkey
1 ha 4812
 
742 Rus 4813
	mov	eax, hotkey_list
92 diamond 4814
@@:
742 Rus 4815
	cmp	dword [eax+8], 0
4816
	jz	.found_free
4817
	add	eax, 16
4818
	cmp	eax, hotkey_list+16*256
4819
	jb	@b
4820
	mov	dword [esp+36], 1
4821
	ret
92 diamond 4822
.found_free:
742 Rus 4823
	mov	[eax+8], edi
4824
	mov	[eax+4], ecx
4825
	movzx	ebx, bl
4826
	lea	ebx, [hotkey_scancodes+ebx*4]
4827
	mov	ecx, [ebx]
4828
	mov	[eax], ecx
4829
	mov	[ebx], eax
4830
	mov	[eax+12], ebx
4831
	jecxz	@f
4832
	mov	[ecx+12], eax
92 diamond 4833
@@:
742 Rus 4834
	and	dword [esp+36], 0
4835
	ret
92 diamond 4836
 
4837
no_add_keyboard_hotkey:
4838
 
742 Rus 4839
	dec	eax
4840
	jnz	no_del_keyboard_hotkey
92 diamond 4841
 
742 Rus 4842
	movzx	ebx, bl
4843
	lea	ebx, [hotkey_scancodes+ebx*4]
4844
	mov	eax, [ebx]
92 diamond 4845
.scan:
742 Rus 4846
	test	eax, eax
4847
	jz	.notfound
4848
	cmp	[eax+8], edi
4849
	jnz	.next
4850
	cmp	[eax+4], ecx
4851
	jz	.found
92 diamond 4852
.next:
742 Rus 4853
	mov	eax, [eax]
4854
	jmp	.scan
92 diamond 4855
.notfound:
742 Rus 4856
	mov	dword [esp+36], 1
4857
	ret
92 diamond 4858
.found:
742 Rus 4859
	mov	ecx, [eax]
4860
	jecxz	@f
4861
	mov	edx, [eax+12]
4862
	mov	[ecx+12], edx
92 diamond 4863
@@:
742 Rus 4864
	mov	ecx, [eax+12]
4865
	mov	edx, [eax]
4866
	mov	[ecx], edx
4867
	xor	edx, edx
4868
	mov	[eax+4], edx
4869
	mov	[eax+8], edx
4870
	mov	[eax+12], edx
4871
	mov	[eax], edx
4872
	mov	[esp+36], edx
4873
	ret
92 diamond 4874
 
4875
no_del_keyboard_hotkey:
1 ha 4876
     ret
4877
 
4878
 
4879
align 4
4880
 
742 Rus 4881
sys_gs: 			; direct screen access
1 ha 4882
 
742 Rus 4883
     cmp  eax,1 		; resolution
1 ha 4884
     jne  no_gs1
753 serge 4885
     mov  eax,[Screen_Max_X]
1 ha 4886
     shl  eax,16
753 serge 4887
     mov  ax,[Screen_Max_Y]
1 ha 4888
     add  eax,0x00010001
4889
     mov  [esp+36],eax
4890
     ret
4891
   no_gs1:
4892
 
742 Rus 4893
     cmp   eax,2		; bits per pixel
1 ha 4894
     jne   no_gs2
381 serge 4895
     movzx eax,byte [ScreenBPP]
1 ha 4896
     mov   [esp+36],eax
4897
     ret
4898
   no_gs2:
4899
 
742 Rus 4900
     cmp   eax,3		; bytes per scanline
1 ha 4901
     jne   no_gs3
381 serge 4902
     mov   eax,[BytesPerScanLine]
1 ha 4903
     mov   [esp+36],eax
4904
     ret
4905
   no_gs3:
4906
 
4907
     mov  [esp+36],dword -1
4908
     ret
4909
 
4910
 
4911
align 4 ; PCI functions
4912
 
4913
sys_pci:
4914
 
4915
     call  pci_api
4916
     mov   [esp+36],eax
4917
     ret
4918
 
4919
 
4920
align 4  ;  system functions
4921
 
742 Rus 4922
syscall_setpixel:			; SetPixel
1 ha 4923
 
742 Rus 4924
	mov	eax, ebx
4925
	mov	ebx, ecx
4926
	mov	ecx, edx
4927
	mov	edx, [TASK_BASE]
4928
	add	eax, [edx-twdw+WDATA.box.left]
4929
	add	ebx, [edx-twdw+WDATA.box.top]
4930
	mov	edi, [current_slot]
4931
	add	eax, [edi+APPDATA.wnd_clientbox.left]
4932
	add	ebx, [edi+APPDATA.wnd_clientbox.top]
4933
	xor	edi, edi ; no force
684 diamond 4934
;       mov     edi, 1
742 Rus 4935
	call	[disable_mouse]
4936
	jmp	[putpixel]
1 ha 4937
 
4938
align 4
4939
 
742 Rus 4940
syscall_writetext:			; WriteText
1 ha 4941
 
742 Rus 4942
	mov   eax,[TASK_BASE]
4943
	mov   ebp,[eax-twdw+WDATA.box.left]
4944
	push  esi
4945
	mov   esi,[current_slot]
4946
	add   ebp,[esi+APPDATA.wnd_clientbox.left]
4947
	shl   ebp,16
4948
	add   ebp,[eax-twdw+WDATA.box.top]
4949
	add   bp,word[esi+APPDATA.wnd_clientbox.top]
4950
	pop   esi
4951
	add   ebx,ebp
4952
	mov   eax,edi
4953
	xor   edi,edi
4954
	jmp   dtext
1 ha 4955
 
4956
align 4
4957
 
742 Rus 4958
syscall_openramdiskfile:		; OpenRamdiskFile
1 ha 4959
 
742 Rus 4960
	mov	eax, ebx
4961
	mov	ebx, ecx
4962
	mov	ecx, edx
4963
	mov	edx, esi
4964
	mov	esi, 12
4965
	call	fileread
4966
	mov	[esp+32], eax
4967
	ret
1 ha 4968
 
4969
align 4
4970
 
742 Rus 4971
syscall_drawrect:			; DrawRect
1 ha 4972
 
671 Ghost 4973
	mov	edi, edx ; color + gradient
4974
	and	edi, 0x80FFFFFF
4975
	test	bx, bx	; x.size
4976
	je	.drectr
4977
	test	cx, cx ; y.size
4978
	je	.drectr
1 ha 4979
 
671 Ghost 4980
	mov	eax, ebx ; bad idea
4981
	mov	ebx, ecx
1 ha 4982
 
671 Ghost 4983
	movzx	ecx, ax ; ecx - x.size
4984
	shr	eax, 16 ; eax - x.coord
4985
	movzx	edx, bx ; edx - y.size
4986
	shr	ebx, 16 ; ebx - y.coord
4987
	mov	esi, [current_slot]
1 ha 4988
 
671 Ghost 4989
	add	eax, [esi + APPDATA.wnd_clientbox.left]
4990
	add	ebx, [esi + APPDATA.wnd_clientbox.top]
4991
	add	ecx, eax
4992
	add	edx, ebx
4993
	jmp	[drawbar]
4994
.drectr:
4995
	ret
1 ha 4996
 
4997
align 4
742 Rus 4998
syscall_getscreensize:			; GetScreenSize
759 Rus 4999
	mov	ax, [Screen_Max_X]
671 Ghost 5000
	shl	eax, 16
759 Rus 5001
	mov	ax, [Screen_Max_Y]
671 Ghost 5002
	mov	[esp + 32], eax
5003
	ret
1 ha 5004
 
671 Ghost 5005
align 4
5006
 
742 Rus 5007
syscall_cdaudio:			; CD
1 ha 5008
 
742 Rus 5009
	cmp	eax, 4
5010
	jb	.audio
5011
	jz	.eject
5012
	cmp	eax, 5
5013
	jnz	.ret
588 diamond 5014
.load:
742 Rus 5015
	call	.reserve
5016
	call	LoadMedium
5017
	call	.free
5018
	ret
588 diamond 5019
.eject:
742 Rus 5020
	call	.reserve
5021
	call	clear_CD_cache
5022
	call	allow_medium_removal
5023
	call	EjectMedium
5024
	call	.free
5025
	ret
588 diamond 5026
.audio:
1 ha 5027
     call  sys_cd_audio
5028
     mov   [esp+36],eax
588 diamond 5029
.ret:
1 ha 5030
     ret
5031
 
588 diamond 5032
.reserve:
742 Rus 5033
	call	reserve_cd
5034
	mov	eax, ebx
5035
	shr	eax, 1
5036
	and	eax, 1
5037
	inc	eax
5038
	mov	[ChannelNumber], ax
5039
	mov	eax, ebx
5040
	and	eax, 1
5041
	mov	[DiskNumber], al
5042
	call	reserve_cd_channel
5043
	and	ebx, 3
5044
	inc	ebx
5045
	mov	[cdpos], ebx
5046
	add	ebx, ebx
5047
	mov	cl, 8
5048
	sub	cl, bl
5049
	mov	al, [DRIVE_DATA+1]
5050
	shr	al, cl
5051
	test	al, 2
5052
	jz	.err
5053
	ret
588 diamond 5054
.free:
742 Rus 5055
	call	free_cd_channel
5056
	and	[cd_status], 0
5057
	ret
590 diamond 5058
.err:
742 Rus 5059
	call	.free
5060
	pop	eax
5061
	ret
588 diamond 5062
 
1 ha 5063
align 4
5064
 
742 Rus 5065
syscall_delramdiskfile: 		; DelRamdiskFile
1 ha 5066
 
379 serge 5067
     mov   edi,[TASK_BASE]
164 serge 5068
     add   edi,TASKDATA.mem_start
1 ha 5069
     add   eax,[edi]
5070
     call  filedelete
5071
     mov   [esp+36],eax
5072
     ret
5073
 
5074
align 4
5075
 
742 Rus 5076
syscall_writeramdiskfile:		; WriteRamdiskFile
1 ha 5077
 
379 serge 5078
     mov   edi,[TASK_BASE]
164 serge 5079
     add   edi,TASKDATA.mem_start
1 ha 5080
     add   eax,[edi]
5081
     add   ebx,[edi]
5082
     call  filesave
5083
     mov   [esp+36],eax
5084
     ret
5085
 
5086
align 4
5087
 
742 Rus 5088
syscall_getpixel:			; GetPixel
753 serge 5089
     mov   ecx, [Screen_Max_X]
1 ha 5090
     inc   ecx
671 Ghost 5091
     xor   edx, edx
5092
     mov   eax, ebx
1 ha 5093
     div   ecx
671 Ghost 5094
     mov   ebx, edx
5095
     xchg  eax, ebx
5096
     call  dword [GETPIXEL] ; eax - x, ebx - y
5097
     mov   [esp + 32], ecx
1 ha 5098
     ret
5099
 
5100
 
5101
align 4
5102
 
742 Rus 5103
syscall_drawline:			; DrawLine
1 ha 5104
 
671 Ghost 5105
	mov	edi, [TASK_BASE]
752 Lrz 5106
	movzx	eax, word[edi-twdw+WDATA.box.left]
5107
	mov	ebp, eax
671 Ghost 5108
	mov	esi, [current_slot]
5109
	add	ebp, [esi+APPDATA.wnd_clientbox.left]
752 Lrz 5110
	add	ax, word[esi+APPDATA.wnd_clientbox.left]
5111
	add	ebp,ebx
5112
	shl	eax, 16
5113
	movzx	ebx, word[edi-twdw+WDATA.box.top]
671 Ghost 5114
	add	eax, ebp
752 Lrz 5115
	mov	ebp, ebx
671 Ghost 5116
	add	ebp, [esi+APPDATA.wnd_clientbox.top]
752 Lrz 5117
	add	bx, word[esi+APPDATA.wnd_clientbox.top]
759 Rus 5118
	add	ebp, ecx
752 Lrz 5119
	shl	ebx, 16
671 Ghost 5120
	xor	edi, edi
752 Lrz 5121
	add	ebx, ebp
5122
	mov	ecx, edx
671 Ghost 5123
	jmp	[draw_line]
1 ha 5124
 
5125
align 4
5126
 
742 Rus 5127
syscall_getirqowner:			; GetIrqOwner
5128
 
5129
     cmp   ebx,16
75 diamond 5130
     jae   .err
742 Rus 5131
 
5132
     mov   eax,[4 * ebx + irq_owner]
5133
     mov   [esp+32],eax
5134
 
1 ha 5135
     ret
75 diamond 5136
.err:
742 Rus 5137
     or    dword [esp+32], -1
75 diamond 5138
     ret
1 ha 5139
 
5140
align 4
5141
 
742 Rus 5142
syscall_reserveportarea:		; ReservePortArea and FreePortArea
1 ha 5143
 
5144
     call  r_f_port_area
5145
     mov   [esp+36],eax
5146
     ret
5147
 
5148
align 4
5149
 
742 Rus 5150
syscall_threads:			; CreateThreads
1 ha 5151
 
5152
     call  sys_threads
5153
     mov   [esp+36],eax
5154
     ret
5155
 
5156
align 4
5157
 
5158
stack_driver_stat:
5159
 
742 Rus 5160
     call  app_stack_handler		; Stack status
1 ha 5161
 
5162
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5163
;     call  change_task                 ; between sent packet
5164
 
5165
     mov   [esp+36],eax
5166
     ret
5167
 
5168
align 4
5169
 
742 Rus 5170
socket: 				; Socket interface
1 ha 5171
     call  app_socket_handler
5172
 
5173
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5174
;     call  change_task                 ; between sent packet
5175
 
5176
     mov   [esp+36],eax
5177
     mov   [esp+24],ebx
5178
     ret
5179
 
5180
align 4
5181
 
742 Rus 5182
read_from_hd:				; Read from hd - fn not in use
1 ha 5183
 
379 serge 5184
     mov   edi,[TASK_BASE]
115 poddubny 5185
     add   edi,TASKDATA.mem_start
1 ha 5186
     add   eax,[edi]
5187
     add   ecx,[edi]
5188
     add   edx,[edi]
5189
     call  file_read
5190
 
5191
     mov   [esp+36],eax
5192
     mov   [esp+24],ebx
5193
 
5194
     ret
5195
 
375 Ghost 5196
paleholder:
742 Rus 5197
	ret
378 serge 5198
 
757 serge 5199
align 4
5200
set_screen:
759 Rus 5201
	cmp eax, [Screen_Max_X]
5202
	jne .set
709 diamond 5203
 
759 Rus 5204
	cmp edx, [Screen_Max_Y]
5205
	jne .set
5206
	ret
757 serge 5207
.set:
759 Rus 5208
	pushfd
5209
	cli
757 serge 5210
 
759 Rus 5211
	mov [Screen_Max_X], eax
5212
	mov [Screen_Max_Y], edx
757 serge 5213
 
759 Rus 5214
	mov [screen_workarea.right],eax
5215
	mov [screen_workarea.bottom], edx
5216
	inc eax
5217
	shl eax, 2			;32 bpp
5218
	mov [BytesPerScanLine], eax
5219
	push ebx
5220
	push esi
5221
	push edi
5222
	call	repos_windows
5223
	mov	eax, 0
5224
	mov	ebx, 0
5225
	mov	ecx, [Screen_Max_X]
5226
	mov	edx, [Screen_Max_Y]
5227
	call	calculatescreen
5228
	pop edi
5229
	pop esi
5230
	pop ebx
757 serge 5231
 
759 Rus 5232
	popfd
5233
	ret
757 serge 5234
 
76 mario79 5235
; --------------- APM ---------------------
5236
apm_entry    dp    0
742 Rus 5237
apm_vf	      dd    0
1 ha 5238
align 4
76 mario79 5239
sys_apm:
5240
    cmp    word [apm_vf], 0    ; Check APM BIOS enable
5241
    jne    @f
742 Rus 5242
    or	  [esp + 56], byte 1	; error
5243
    mov    [esp + 36], dword 8	  ; 32-bit protected-mode interface not supported
76 mario79 5244
    ret
164 serge 5245
 
465 serge 5246
@@:
5247
    xchg    eax, ecx
76 mario79 5248
    xchg    ebx, ecx
164 serge 5249
 
76 mario79 5250
    cmp    al, 3
742 Rus 5251
    ja	  @f
78 diamond 5252
    and    [esp + 56], byte 0xfe    ; emulate func 0..3 as func 0
76 mario79 5253
    mov    eax, [apm_vf]
5254
    mov    [esp + 36], eax
5255
    shr    eax, 16
5256
    mov    [esp + 32], eax
5257
    ret
78 diamond 5258
 
465 serge 5259
@@:
5260
 
5261
    mov esi, [master_tab+(OS_BASE shr 20)]
5262
    xchg [master_tab], esi
5263
    push esi
5264
    mov edi, cr3
742 Rus 5265
    mov cr3, edi		 ;flush TLB
465 serge 5266
 
742 Rus 5267
    call    pword [apm_entry]	 ; call APM BIOS
465 serge 5268
 
5269
    xchg eax, [esp]
5270
    mov [master_tab], eax
5271
    mov eax, cr3
5272
    mov cr3, eax
5273
    pop eax
5274
 
76 mario79 5275
    mov    [esp + 8 ], edi
5276
    mov    [esp + 12], esi
5277
    mov    [esp + 24], ebx
5278
    mov    [esp + 28], edx
5279
    mov    [esp + 32], ecx
5280
    mov    [esp + 36], eax
5281
    setc    al
78 diamond 5282
    and    [esp + 56], byte 0xfe
742 Rus 5283
    or	  [esp + 56], al
465 serge 5284
 
5285
 
76 mario79 5286
    ret
5287
; -----------------------------------------
1 ha 5288
 
76 mario79 5289
align 4
5290
 
742 Rus 5291
undefined_syscall:			; Undefined system call
671 Ghost 5292
     mov   [esp + 32], dword -1
1 ha 5293
     ret
5294
 
465 serge 5295
align 4
742 Rus 5296
system_shutdown:	  ; shut down the system
1 ha 5297
 
742 Rus 5298
	   cmp byte [BOOT_VAR+0x9030], 1
5299
	   jne @F
5300
	   ret
465 serge 5301
@@:
742 Rus 5302
	   call stop_all_services
5303
	   push 3		 ; stop playing cd
5304
	   pop	eax
5305
	   call sys_cd_audio
1 ha 5306
 
465 serge 5307
yes_shutdown_param:
742 Rus 5308
	   cli
1 ha 5309
 
742 Rus 5310
	   mov	eax, kernel_file ; load kernel.mnt to 0x7000:0
5311
	   push 12
5312
	   pop	esi
5313
	   xor	ebx,ebx
5314
	   or	ecx,-1
5315
	   mov	edx, OS_BASE+0x70000
5316
	   call fileread
1 ha 5317
 
742 Rus 5318
	   mov	esi, restart_kernel_4000+OS_BASE+0x10000 ; move kernel re-starter to 0x4000:0
5319
	   mov	edi,OS_BASE+0x40000
5320
	   mov	ecx,1000
5321
	   rep	movsb
1 ha 5322
 
742 Rus 5323
	   mov	esi,OS_BASE+0x2F0000	; restore 0x0 - 0xffff
5324
	   mov	edi, OS_BASE
5325
	   mov	ecx,0x10000/4
5326
	   cld
5327
	   rep movsd
1 ha 5328
 
742 Rus 5329
	   call restorefatchain
1 ha 5330
 
742 Rus 5331
	   mov al, 0xFF
5332
	   out 0x21, al
5333
	   out 0xA1, al
1 ha 5334
 
709 diamond 5335
if 1
742 Rus 5336
	   mov	word [OS_BASE+0x467+0],pr_mode_exit
5337
	   mov	word [OS_BASE+0x467+2],0x1000
1 ha 5338
 
742 Rus 5339
	   mov	al,0x0F
5340
	   out	0x70,al
5341
	   mov	al,0x05
5342
	   out	0x71,al
1 ha 5343
 
742 Rus 5344
	   mov	al,0xFE
5345
	   out	0x64,al
709 diamond 5346
 
742 Rus 5347
	   hlt
1 ha 5348
 
709 diamond 5349
else
742 Rus 5350
	cmp	byte [OS_BASE + 0x9030], 2
5351
	jnz	no_acpi_power_off
1 ha 5352
 
709 diamond 5353
; scan for RSDP
5354
; 1) The first 1 Kb of the Extended BIOS Data Area (EBDA).
742 Rus 5355
	movzx	eax, word [OS_BASE + 0x40E]
5356
	shl	eax, 4
5357
	jz	@f
5358
	mov	ecx, 1024/16
5359
	call	scan_rsdp
5360
	jnc	.rsdp_found
709 diamond 5361
@@:
5362
; 2) The BIOS read-only memory space between 0E0000h and 0FFFFFh.
742 Rus 5363
	mov	eax, 0xE0000
5364
	mov	ecx, 0x2000
5365
	call	scan_rsdp
5366
	jc	no_acpi_power_off
709 diamond 5367
.rsdp_found:
742 Rus 5368
	mov	esi, [eax+16]	; esi contains physical address of the RSDT
5369
	mov	ebp, [ipc_tmp]
5370
	stdcall map_page, ebp, esi, PG_MAP
5371
	lea	eax, [esi+1000h]
5372
	lea	edx, [ebp+1000h]
5373
	stdcall map_page, edx, eax, PG_MAP
5374
	and	esi, 0xFFF
5375
	add	esi, ebp
5376
	cmp	dword [esi], 'RSDT'
5377
	jnz	no_acpi_power_off
5378
	mov	ecx, [esi+4]
5379
	sub	ecx, 24h
5380
	jbe	no_acpi_power_off
5381
	shr	ecx, 2
5382
	add	esi, 24h
709 diamond 5383
.scan_fadt:
742 Rus 5384
	lodsd
5385
	mov	ebx, eax
5386
	lea	eax, [ebp+2000h]
5387
	stdcall map_page, eax, ebx, PG_MAP
5388
	lea	eax, [ebp+3000h]
5389
	add	ebx, 0x1000
5390
	stdcall map_page, eax, ebx, PG_MAP
5391
	and	ebx, 0xFFF
5392
	lea	ebx, [ebx+ebp+2000h]
5393
	cmp	dword [ebx], 'FACP'
5394
	jz	.fadt_found
5395
	loop	.scan_fadt
5396
	jmp	no_acpi_power_off
709 diamond 5397
.fadt_found:
5398
; ebx is linear address of FADT
742 Rus 5399
	mov	edx, [ebx+48]
5400
	test	edx, edx
5401
	jz	.nosmi
5402
	mov	al, [ebx+52]
5403
	out	dx, al
5404
	mov	edx, [ebx+64]
709 diamond 5405
@@:
742 Rus 5406
	in	ax, dx
5407
	test	al, 1
5408
	jz	@b
709 diamond 5409
.nosmi:
742 Rus 5410
	mov	edx, [ebx+64]
5411
	in	ax, dx
5412
	and	ax, 203h
5413
	or	ax, 3C00h
5414
	out	dx, ax
5415
	mov	edx, [ebx+68]
5416
	test	edx, edx
5417
	jz	@f
5418
	in	ax, dx
5419
	and	ax, 203h
5420
	or	ax, 3C00h
5421
	out	dx, ax
709 diamond 5422
@@:
742 Rus 5423
	jmp	$
709 diamond 5424
 
5425
 
5426
no_acpi_power_off:
742 Rus 5427
	   mov	word [OS_BASE+0x467+0],pr_mode_exit
5428
	   mov	word [OS_BASE+0x467+2],0x1000
709 diamond 5429
 
742 Rus 5430
	   mov	al,0x0F
5431
	   out	0x70,al
5432
	   mov	al,0x05
5433
	   out	0x71,al
709 diamond 5434
 
742 Rus 5435
	   mov	al,0xFE
5436
	   out	0x64,al
709 diamond 5437
 
742 Rus 5438
	   hlt
709 diamond 5439
 
5440
scan_rsdp:
742 Rus 5441
	add	eax, OS_BASE
709 diamond 5442
.s:
742 Rus 5443
	cmp	dword [eax], 'RSD '
5444
	jnz	.n
5445
	cmp	dword [eax+4], 'PTR '
5446
	jnz	.n
5447
	xor	edx, edx
5448
	xor	esi, esi
709 diamond 5449
@@:
742 Rus 5450
	add	dl, [eax+esi]
5451
	inc	esi
5452
	cmp	esi, 20
5453
	jnz	@b
5454
	test	dl, dl
5455
	jz	.ok
709 diamond 5456
.n:
742 Rus 5457
	add	eax, 10h
5458
	loop	.s
5459
	stc
709 diamond 5460
.ok:
742 Rus 5461
	ret
709 diamond 5462
end if
5463
 
465 serge 5464
include "data32.inc"
1 ha 5465
 
465 serge 5466
__REV__ = __REV
1 ha 5467
 
5468
uglobals_size = $ - endofcode
41 mikedld 5469
diff16 "end of kernel code",0,$
426 mikedld 5470