Subversion Repositories Kolibri OS

Rev

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