Subversion Repositories Kolibri OS

Rev

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