Subversion Repositories Kolibri OS

Rev

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