Subversion Repositories Kolibri OS

Rev

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