Subversion Repositories Kolibri OS

Rev

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