Subversion Repositories Kolibri OS

Rev

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