Subversion Repositories Kolibri OS

Rev

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