Subversion Repositories Kolibri OS

Rev

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

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