Subversion Repositories Kolibri OS

Rev

Rev 1523 | Rev 1563 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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