Subversion Repositories Kolibri OS

Rev

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