Subversion Repositories Kolibri OS

Rev

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