Subversion Repositories Kolibri OS

Rev

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