Subversion Repositories Kolibri OS

Rev

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