Subversion Repositories Kolibri OS

Rev

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