Subversion Repositories Kolibri OS

Rev

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

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