Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1 ha 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;
5565 serge 3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved.
431 serge 4
;; PROGRAMMING:
5
;; Ivan Poddubny
6
;; Marat Zakiyanov (Mario79)
7
;; VaStaNi
8
;; Trans
9
;; Mihail Semenyako (mike.dld)
10
;; Sergey Kuzmin (Wildwest)
11
;; Andrey Halyavin (halyavin)
12
;; Mihail Lisovin (Mihasik)
13
;; Andrey Ignatiev (andrew_programmer)
14
;; NoName
15
;; Evgeny Grechnikov (Diamond)
16
;; Iliya Mihailov (Ghost)
17
;; Sergey Semyonov (Serge)
18
;; Johnny_B
543 spraid 19
;; SPraid (simba)
1043 hidnplayr 20
;; Hidnplayr
1273 Lrz 21
;; Alexey Teplov ()
2010 serge 22
;; Rus
23
;; Nable
24
;; shurf
25
;; Alver
26
;; Maxis
27
;; Galkov
28
;; CleverMouse
29
;; tsdima
30
;; turbanoff
31
;; Asper
32
;; art_zh
1 ha 33
;;
431 serge 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.
1 ha 37
;;
431 serge 38
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa
39
;; PROGRAMMING:
1 ha 40
;;
431 serge 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
1 ha 53
;;
431 serge 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
;;
1 ha 67
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
426 mikedld 68
 
3500 Serge 69
format binary as "mnt"
70
 
426 mikedld 71
include 'macros.inc'
2434 Serge 72
include 'struct.inc'
426 mikedld 73
 
425 victor 74
$Revision: 6242 $
426 mikedld 75
 
593 mikedld 76
 
1055 Galkov 77
USE_COM_IRQ     equ 1      ; make irq 3 and irq 4 available for PCI devices
3626 Serge 78
VESA_1_2_VIDEO  equ 0      ; enable vesa 1.2 bank switch functions
566 serge 79
 
1043 hidnplayr 80
; Enabling the next line will enable serial output console
3589 Serge 81
;debug_com_base  equ 0x3f8  ; 0x3f8 is com1, 0x2f8 is com2, 0x3e8 is com3, 0x2e8 is com4, no irq's are used
1043 hidnplayr 82
 
164 serge 83
include "proc32.inc"
7 me_root 84
include "kglobals.inc"
1 ha 85
include "lang.inc"
3555 Serge 86
include "encoding.inc"
1 ha 87
 
164 serge 88
include "const.inc"
3908 Serge 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
 
1055 Galkov 97
max_processes    equ   255
98
tss_step         equ   (128+8192) ; tss & i/o - 65535 ports, * 256=557056*4
1 ha 99
 
1055 Galkov 100
os_stack       equ  (os_data_l-gdts)    ; GDTs
465 serge 101
os_code        equ  (os_code_l-gdts)
102
graph_data     equ  (3+graph_data_l-gdts)
1055 Galkov 103
tss0           equ  (tss0_l-gdts)
465 serge 104
app_code       equ  (3+app_code_l-gdts)
105
app_data       equ  (3+app_data_l-gdts)
1220 serge 106
app_tls        equ  (3+tls_data_l-gdts)
586 serge 107
pci_code_sel   equ  (pci_code_32-gdts)
108
pci_data_sel   equ  (pci_data_32-gdts)
1 ha 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
1055 Galkov 142
                  org   0x0
2434 Serge 143
        jmp     start_of_code
1 ha 144
 
3500 Serge 145
if lang eq sp
146
include "kernelsp.inc"  ; spanish kernel messages
4265 Serge 147
else if lang eq et
148
version db    'Kolibri OS  versioon 0.7.7.0+    ',13,10,13,10,0
3500 Serge 149
else
1324 Lrz 150
version db    'Kolibri OS  version 0.7.7.0+     ',13,10,13,10,0
3500 Serge 151
end if
1 ha 152
 
465 serge 153
include "boot/bootstr.inc"     ; language-independent boot messages
1 ha 154
include "boot/preboot.inc"
155
 
3500 Serge 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
465 serge 160
else if lang eq ru
161
include "boot/bootru.inc"      ; russian system boot messages
1055 Galkov 162
include "boot/ru.inc"          ; Russian font
465 serge 163
else if lang eq et
164
include "boot/bootet.inc"      ; estonian system boot messages
1055 Galkov 165
include "boot/et.inc"          ; Estonian font
465 serge 166
else
3500 Serge 167
include "boot/booten.inc"      ; english system boot messages
465 serge 168
end if
1 ha 169
 
465 serge 170
include "boot/bootcode.inc"    ; 16 bit system boot code
171
include "bus/pci/pci16.inc"
709 diamond 172
include "detect/biosdisk.inc"
1 ha 173
 
174
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
175
;;                                                                      ;;
176
;;                  SWITCH TO 32 BIT PROTECTED MODE                     ;;
177
;;                                                                      ;;
178
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
179
 
180
 
181
; CR0 Flags - Protected mode and Paging
182
 
2434 Serge 183
        mov     ecx, CR0_PE
1 ha 184
 
185
; Enabling 32 bit protected mode
186
 
1055 Galkov 187
        sidt    [cs:old_ints_h]
1 ha 188
 
1055 Galkov 189
        cli                             ; disable all irqs
190
        cld
2434 Serge 191
        mov     al, 255                 ; mask all irqs
192
        out     0xa1, al
193
        out     0x21, al
194
   l.5:
195
        in      al, 0x64                ; Enable A20
1055 Galkov 196
        test    al, 2
197
        jnz     l.5
198
        mov     al, 0xD1
199
        out     0x64, al
2434 Serge 200
   l.6:
201
        in      al, 0x64
1055 Galkov 202
        test    al, 2
203
        jnz     l.6
204
        mov     al, 0xDF
205
        out     0x60, al
2434 Serge 206
   l.7:
207
        in      al, 0x64
1055 Galkov 208
        test    al, 2
209
        jnz     l.7
210
        mov     al, 0xFF
211
        out     0x64, al
465 serge 212
 
1055 Galkov 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
1 ha 219
 
465 serge 220
align 8
221
tmp_gdt:
1 ha 222
 
1055 Galkov 223
        dw     23
224
        dd     tmp_gdt+0x10000
225
        dw     0
183 diamond 226
 
1055 Galkov 227
        dw     0xffff
228
        dw     0x0000
229
        db     0x00
230
        dw     11011111b *256 +10011010b
231
        db     0x00
375 Ghost 232
 
1055 Galkov 233
        dw     0xffff
234
        dw     0x0000
235
        db     0x00
236
        dw     11011111b *256 +10010010b
237
        db     0x00
1 ha 238
 
3500 Serge 239
include "data16.inc"
1 ha 240
 
3626 Serge 241
if ~ lang eq sp
242
diff16 "end of bootcode",0,$+0x10000
243
end if
244
 
465 serge 245
use32
246
org $+0x10000
1 ha 247
 
465 serge 248
align 4
249
B32:
2434 Serge 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
6240 serge 256
        mov     esp, TMP_STACK_TOP       ; Set stack
1 ha 257
 
465 serge 258
; CLEAR 0x280000 - HEAP_BASE
1 ha 259
 
2434 Serge 260
        xor     eax, eax
261
        mov     edi, CLEAN_ZONE
262
        mov     ecx, (HEAP_BASE-OS_BASE-CLEAN_ZONE) / 4
263
        cld
264
        rep stosd
1 ha 265
 
465 serge 266
; CLEAR KERNEL UNDEFINED GLOBALS
2434 Serge 267
        mov     edi, endofcode-OS_BASE
268
        mov     ecx, 0x90000
269
        sub     ecx, edi
270
        shr     ecx, 2
271
        rep stosd
1 ha 272
 
465 serge 273
; SAVE & CLEAR 0-0xffff
1 ha 274
 
2434 Serge 275
        mov     edi, 0x1000
3908 Serge 276
        mov     ecx, 0x8000 / 4
2434 Serge 277
        rep stosd
3908 Serge 278
        mov     edi, 0xa000
279
        mov     ecx, 0x6000 / 4
280
        rep stosd
429 serge 281
 
2434 Serge 282
        call    test_cpu
283
        bts     [cpu_caps-OS_BASE], CAPS_TSC    ;force use rdtsc
424 spraid 284
 
2434 Serge 285
        call    check_acpi
5629 serge 286
        call    init_hpet
2434 Serge 287
        call    init_BIOS32
465 serge 288
; MEMORY MODEL
2434 Serge 289
        call    mem_test
290
        call    init_mem
291
        call    init_page_map
1 ha 292
 
465 serge 293
; ENABLE PAGING
1 ha 294
 
5201 serge 295
        mov     eax, sys_proc-OS_BASE+PROC.pdt_0
2434 Serge 296
        mov     cr3, eax
1 ha 297
 
2434 Serge 298
        mov     eax, cr0
299
        or      eax, CR0_PG+CR0_WP
300
        mov     cr0, eax
1 ha 301
 
2434 Serge 302
        lgdt    [gdts]
303
        jmp     pword os_code:high_code
1 ha 304
 
513 serge 305
align 4
1055 Galkov 306
bios32_entry    dd ?
307
tmp_page_tabs   dd ?
3500 Serge 308
use16
5201 serge 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
3500 Serge 327
use32
498 diamond 328
 
3908 Serge 329
__DEBUG__ fix 1
465 serge 330
__DEBUG_LEVEL__ fix 1
331
include 'init.inc'
380 serge 332
 
465 serge 333
org OS_BASE+$
1 ha 334
 
2465 Serge 335
include 'fdo.inc'
336
 
465 serge 337
align 4
338
high_code:
2434 Serge 339
        mov     ax, os_stack
340
        mov     bx, app_data
341
        mov     cx, app_tls
342
        mov     ss, ax
343
        add     esp, OS_BASE
1 ha 344
 
2434 Serge 345
        mov     ds, bx
346
        mov     es, bx
347
        mov     fs, cx
348
        mov     gs, bx
1 ha 349
 
5565 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
 
357
        mov     eax, PG_GLOBAL
2434 Serge 358
        bt      [cpu_caps], CAPS_PGE
359
        jnc     @F
1 ha 360
 
5565 serge 361
        or      [sys_proc+PROC.pdt_0+(OS_BASE shr 20)], eax
362
        or      ebx, eax
519 serge 363
 
5565 serge 364
        mov     eax, cr4
365
        or      eax, CR4_PGE
366
        mov     cr4, eax
519 serge 367
@@:
5565 serge 368
        mov     [pte_valid_mask], ebx
369
 
3500 Serge 370
        xor     eax, eax
5201 serge 371
        mov     dword [sys_proc+PROC.pdt_0], eax
372
        mov     dword [sys_proc+PROC.pdt_0+4], eax
519 serge 373
 
3500 Serge 374
        mov     eax, cr3
375
        mov     cr3, eax          ; flush TLB
465 serge 376
 
2434 Serge 377
        mov     ecx, pg_data.mutex
378
        call    mutex_init
2130 serge 379
 
2434 Serge 380
        mov     ecx, disk_list_mutex
381
        call    mutex_init
2130 serge 382
 
2987 Serge 383
        mov     ecx, keyboard_list_mutex
384
        call    mutex_init
385
 
386
        mov     ecx, unpack_mutex
387
        call    mutex_init
388
 
3555 Serge 389
        mov     ecx, application_table_mutex
390
        call    mutex_init
391
 
3908 Serge 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
5201 serge 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
3908 Serge 406
;-----------------------------------------------------------------------------
1 ha 407
; SAVE REAL MODE VARIABLES
3908 Serge 408
;-----------------------------------------------------------------------------
76 mario79 409
; --------------- APM ---------------------
465 serge 410
 
411
; init selectors
3908 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
414
                                                                                ; protected-mode 32-bit code segment
415
        movzx   ecx, word [BOOT_VARS+BOOT_APM_CODE_16]; real-mode segment base address of
416
                                                                                ; protected-mode 16-bit code segment
417
        movzx   edx, word [BOOT_VARS+BOOT_APM_DATA_16]; real-mode segment base address of
2434 Serge 418
                                                                                ; protected-mode 16-bit data segment
465 serge 419
 
2434 Serge 420
        shl     eax, 4
421
        mov     [dword apm_code_32 + 2], ax
422
        shr     eax, 16
423
        mov     [dword apm_code_32 + 4], al
465 serge 424
 
2434 Serge 425
        shl     ecx, 4
426
        mov     [dword apm_code_16 + 2], cx
427
        shr     ecx, 16
428
        mov     [dword apm_code_16 + 4], cl
465 serge 429
 
2434 Serge 430
        shl     edx, 4
431
        mov     [dword apm_data_16 + 2], dx
432
        shr     edx, 16
433
        mov     [dword apm_data_16 + 4], dl
465 serge 434
 
2434 Serge 435
        mov     dword[apm_entry], ebx
436
        mov     word [apm_entry + 4], apm_code_32 - gdts
76 mario79 437
 
3908 Serge 438
        mov     eax, [BOOT_VARS + BOOT_APM_VERSION] ; version & flags
2434 Serge 439
        mov     [apm_vf], eax
76 mario79 440
; -----------------------------------------
3908 Serge 441
        mov     al, [BOOT_VARS+BOOT_DMA]            ; DMA access
2434 Serge 442
        mov     [allow_dma_access], al
3908 Serge 443
        movzx   eax, byte [BOOT_VARS+BOOT_BPP]      ; bpp
5201 serge 444
        mov     [_display.bits_per_pixel], eax
2434 Serge 445
        mov     [_display.vrefresh], 60
3908 Serge 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
450
        movzx   eax, word [BOOT_VARS+BOOT_X_RES]; X max
2434 Serge 451
        mov     [_display.width], eax
2987 Serge 452
        mov     [display_width_standard], eax
2434 Serge 453
        dec     eax
454
        mov     [screen_workarea.right], eax
3908 Serge 455
        movzx   eax, word [BOOT_VARS+BOOT_Y_RES]; Y max
2434 Serge 456
        mov     [_display.height], eax
2987 Serge 457
        mov     [display_height_standard], eax
2434 Serge 458
        dec     eax
459
        mov     [screen_workarea.bottom], eax
3908 Serge 460
        movzx   eax, word [BOOT_VARS+BOOT_VESA_MODE] ; screen mode
3626 Serge 461
        mov     dword [SCR_MODE], eax
3908 Serge 462
;        mov     eax, [BOOT_VAR+0x9014]             ; Vesa 1.2 bnk sw add
3589 Serge 463
;        mov     [BANK_SWITCH], eax
3626 Serge 464
        mov     eax, 640 *4                         ; Bytes PerScanLine
3908 Serge 465
        cmp     [SCR_MODE], word 0x13               ; 320x200
2434 Serge 466
        je      @f
3908 Serge 467
        cmp     [SCR_MODE], word 0x12               ; VGA 640x480
2434 Serge 468
        je      @f
3908 Serge 469
        movzx   eax, word[BOOT_VARS+BOOT_PITCH]      ; for other modes
3626 Serge 470
@@:
5565 serge 471
        mov     [_display.lfb_pitch], eax
2434 Serge 472
        mov     eax, [_display.width]
473
        mul     [_display.height]
5565 serge 474
        mov     [_display.win_map_size], eax
1300 serge 475
 
2439 Serge 476
        call    calculate_fast_getting_offset_for_WinMapAddress
2987 Serge 477
; for Qemu or non standart video cards
3232 Serge 478
; Unfortunately [BytesPerScanLine] does not always
2987 Serge 479
;                             equal to [_display.width] * [ScreenBPP] / 8
480
        call    calculate_fast_getting_offset_for_LFB
2439 Serge 481
 
3908 Serge 482
        mov     esi, BOOT_VARS+0x9080
1055 Galkov 483
        movzx   ecx, byte [esi-1]
484
        mov     [NumBiosDisks], ecx
485
        mov     edi, BiosDisksData
2434 Serge 486
        rep movsd
1 ha 487
 
5201 serge 488
setvideomode:
1 ha 489
 
3908 Serge 490
        mov     eax, [BOOT_VARS+BOOT_LFB]
2434 Serge 491
        mov     [LFBAddress], eax
1 ha 492
 
5201 serge 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
2439 Serge 505
 
5201 serge 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
1 ha 511
 
5201 serge 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
2987 Serge 538
        mov     [_display.check_mouse], check_mouse_area_for_putpixel
539
        mov     [_display.check_m_pixel], check_mouse_area_for_getpixel
540
 
375 Ghost 541
; -------- Fast System Call init ----------
378 serge 542
; Intel SYSENTER/SYSEXIT (AMD CPU support it too)
2434 Serge 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
434 diamond 550
;           mov eax, sysenter_stack ; Check it
2434 Serge 551
        xor     eax, eax
552
        wrmsr
553
        mov     ecx, MSR_SYSENTER_EIP
554
        mov     eax, sysenter_entry
555
        wrmsr
375 Ghost 556
.SEnP:
378 serge 557
; AMD SYSCALL/SYSRET
2434 Serge 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
164 serge 568
 
1055 Galkov 569
        ; !!!! It`s dirty hack, fix it !!!
570
        ; Bits of EDX :
3555 Serge 571
        ; Bit 31–16 During the SYSRET instruction, this field is copied into the CS register
1055 Galkov 572
        ;  and the contents of this field, plus 8, are copied into the SS register.
3555 Serge 573
        ; Bit 15–0 During the SYSCALL instruction, this field is copied into the CS register
1055 Galkov 574
        ;  and the contents of this field, plus 8, are copied into the SS register.
375 Ghost 575
 
1055 Galkov 576
        ; mov   edx, (os_code + 16) * 65536 + os_code
2434 Serge 577
        mov     edx, 0x1B0008
375 Ghost 578
 
2434 Serge 579
        mov     eax, syscall_entry
580
        mov     ecx, MSR_AMD_STAR
581
        wrmsr
375 Ghost 582
.noSYSCALL:
583
; -----------------------------------------
1310 diamond 584
        stdcall alloc_page
5565 serge 585
        stdcall map_page, tss-0xF80, eax, PG_SWR
1310 diamond 586
        stdcall alloc_page
5565 serge 587
        stdcall map_page, tss+0x80, eax, PG_SWR
1310 diamond 588
        stdcall alloc_page
5565 serge 589
        stdcall map_page, tss+0x1080, eax, PG_SWR
375 Ghost 590
 
465 serge 591
; LOAD IDT
378 serge 592
 
2434 Serge 593
        call    build_interrupt_table ;lidt is executed
1056 Galkov 594
          ;lidt [idtreg]
378 serge 595
 
2434 Serge 596
        call    init_kernel_heap
3555 Serge 597
        stdcall kernel_alloc, (RING0_STACK_SIZE+512) * 2
2434 Serge 598
        mov     [os_stack_seg], eax
164 serge 599
 
2434 Serge 600
        lea     esp, [eax+RING0_STACK_SIZE]
164 serge 601
 
2434 Serge 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
465 serge 612
;Add IO access table - bit array of permitted ports
2434 Serge 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
164 serge 618
 
2434 Serge 619
        mov     ax, tss0
620
        ltr     ax
378 serge 621
 
2987 Serge 622
        mov     [LFBSize], 0xC00000
2434 Serge 623
        call    init_LFB
624
        call    init_fpu
625
        call    init_malloc
276 serge 626
 
5201 serge 627
        stdcall alloc_kernel_space, 0x50000         ; FIXME check size
2434 Serge 628
        mov     [default_io_map], eax
465 serge 629
 
2434 Serge 630
        add     eax, 0x2000
631
        mov     [ipc_tmp], eax
632
        mov     ebx, 0x1000
164 serge 633
 
2434 Serge 634
        add     eax, 0x40000
635
        mov     [proc_mem_map], eax
164 serge 636
 
2434 Serge 637
        add     eax, 0x8000
638
        mov     [proc_mem_pdir], eax
164 serge 639
 
2434 Serge 640
        add     eax, ebx
641
        mov     [proc_mem_tab], eax
164 serge 642
 
2434 Serge 643
        add     eax, ebx
644
        mov     [tmp_task_ptab], eax
164 serge 645
 
2434 Serge 646
        add     eax, ebx
647
        mov     [ipc_pdir], eax
164 serge 648
 
2434 Serge 649
        add     eax, ebx
650
        mov     [ipc_ptab], eax
164 serge 651
 
2434 Serge 652
        stdcall kernel_alloc, (unpack.LZMA_BASE_SIZE+(unpack.LZMA_LIT_SIZE shl \
653
                (unpack.lc+unpack.lp)))*4
712 serge 654
 
2434 Serge 655
        mov     [unpack.p], eax
709 diamond 656
 
2434 Serge 657
        call    init_events
658
        mov     eax, srv.fd-SRV.fd
659
        mov     [srv.fd], eax
660
        mov     [srv.bk], eax
278 serge 661
 
41 mikedld 662
;Set base of graphic segment to linear address of LFB
2434 Serge 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
1 ha 668
 
5565 serge 669
        stdcall kernel_alloc, [_display.win_map_size]
670
        mov     [_display.win_map], eax
1300 serge 671
 
2434 Serge 672
        xor     eax, eax
673
        inc     eax
429 serge 674
 
469 serge 675
; set background
1300 serge 676
 
2434 Serge 677
        mov     [BgrDrawMode], eax
678
        mov     [BgrDataWidth], eax
679
        mov     [BgrDataHeight], eax
680
        mov     [mem_BACKGROUND], 4
681
        mov     [img_background], static_background_data
469 serge 682
 
4265 Serge 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
 
5645 serge 696
        mov     eax, [hpet_base]
697
        test    eax, eax
698
        jz      @F
5629 serge 699
        mov     eax, [hpet_base]
700
        stdcall map_io_mem, [hpet_base], 1024, PG_GLOBAL+PAT_UC+PG_SWR
701
        mov     [hpet_base], eax
5645 serge 702
        mov     eax, [eax]
703
        DEBUGF  1, "K : HPET caps %x\n", eax
704
@@:
3500 Serge 705
; SET UP OS TASK
706
 
707
        mov     esi, boot_setostask
708
        call    boot_log
709
 
5577 serge 710
        mov     eax, sys_proc
711
        lea     edi, [eax+PROC.heap_lock]
712
        mov     ecx, (PROC.ht_free-PROC.heap_lock)/4
5201 serge 713
 
5577 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
 
5201 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
3555 Serge 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
3500 Serge 758
 
3555 Serge 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
3500 Serge 765
 
3555 Serge 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
3500 Serge 770
 
5201 serge 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
5565 serge 792
        stdcall map_io_mem, [acpi_lapic_base], 0x1000, PG_GLOBAL+PG_NOCACHE+PG_SWR
5201 serge 793
        mov     [LAPIC_BASE], eax
794
        lea     edi, [eax+300h]
795
        mov     esi, smpt+4
796
        dec     ebx
797
.wake_cpus_loop:
798
        lodsd
799
        push    esi
800
        xor     esi, esi
801
        inc     esi
802
        shl     eax, 24
803
        mov     [edi+10h], eax
804
; assert INIT IPI
805
        mov     dword [edi], 0C500h
806
        call    delay_ms
807
@@:
808
        test    dword [edi], 1000h
809
        jnz     @b
810
; deassert INIT IPI
811
        mov     dword [edi], 8500h
812
        call    delay_ms
813
@@:
814
        test    dword [edi], 1000h
815
        jnz     @b
816
; send STARTUP IPI
817
        mov     dword [edi], 600h + (8000h shr 12)
818
        call    delay_ms
819
@@:
820
        test    dword [edi], 1000h
821
        jnz     @b
822
        pop     esi
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:
3500 Serge 833
 
709 diamond 834
; REDIRECT ALL IRQ'S TO INT'S 0x20-0x2f
2987 Serge 835
        mov     esi, boot_initirq
836
        call    boot_log
837
        call    init_irqs
709 diamond 838
 
2987 Serge 839
        mov     esi, boot_picinit
840
        call    boot_log
2434 Serge 841
        call    PIC_init
709 diamond 842
 
2987 Serge 843
        mov     esi, boot_v86machine
844
        call    boot_log
709 diamond 845
; Initialize system V86 machine
1055 Galkov 846
        call    init_sys_v86
709 diamond 847
 
2987 Serge 848
        mov     esi, boot_inittimer
849
        call    boot_log
1638 serge 850
; Initialize system timer (IRQ0)
2434 Serge 851
        call    PIT_init
725 diamond 852
 
4287 Serge 853
; Register ramdisk file system
5201 serge 854
        cmp     [boot_dev+OS_BASE+0x10000], 1
855
        je      @f
3626 Serge 856
 
5201 serge 857
        call    register_ramdisk
858
;--------------------------------------
859
@@:
2987 Serge 860
        mov     esi, boot_initapic
861
        call    boot_log
1638 serge 862
; Try to Initialize APIC
2434 Serge 863
        call    APIC_init
725 diamond 864
 
3500 Serge 865
        mov     esi, boot_enableirq
866
        call    boot_log
3908 Serge 867
; Enable timer IRQ (IRQ0) and co-processor IRQ (IRQ13)
725 diamond 868
; they are used: when partitions are scanned, hd_read relies on timer
2434 Serge 869
        call    unmask_timer
2141 serge 870
        stdcall enable_irq, 2               ; @#$%! PIC
871
        stdcall enable_irq, 13              ; co-processor
725 diamond 872
 
5201 serge 873
; Setup serial output console (if enabled)
874
if defined debug_com_base
3908 Serge 875
 
5201 serge 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
1523 diamond 885
        out     dx, al
5201 serge 886
 
887
        ; Set speed to 115200 baud (max speed)
888
        mov     dx, debug_com_base
889
        mov     al, 0x01
1523 diamond 890
        out     dx, al
5201 serge 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
 
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
3908 Serge 926
@@:
5201 serge 927
        DEBUGF  1, "K : %d CPU detected\n", eax
3908 Serge 928
;-----------------------------------------------------------------------------
5201 serge 929
; detect Floppy drives
930
;-----------------------------------------------------------------------------
2987 Serge 931
        mov     esi, boot_detectfloppy
932
        call    boot_log
933
include 'detect/dev_fd.inc'
5201 serge 934
;-----------------------------------------------------------------------------
935
; create pci-devices list
936
;-----------------------------------------------------------------------------
937
        mov     [pci_access_enabled], 1
938
        call    pci_enum
939
;-----------------------------------------------------------------------------
940
; initialisation IDE ATA code
941
;-----------------------------------------------------------------------------
942
include 'detect/init_ata.inc'
943
;-----------------------------------------------------------------------------
1289 diamond 944
if 0
2434 Serge 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
2987 Serge 948
 
949
        mov     esi, boot_loadlibs
950
        call    boot_log
488 spraid 951
; LOADING LIBRARES
2434 Serge 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
488 spraid 955
no_lib_load:
1289 diamond 956
end if
488 spraid 957
 
1638 serge 958
; Display APIC status
2434 Serge 959
        mov     esi, boot_APIC_found
2219 Serge 960
        cmp     [irq_mode], IRQ_APIC
2434 Serge 961
        je      @f
962
        mov     esi, boot_APIC_nfound
2219 Serge 963
@@:
2987 Serge 964
        call    boot_log
1638 serge 965
 
1 ha 966
; PRINT AMOUNT OF MEMORY
1055 Galkov 967
        mov     esi, boot_memdetect
968
        call    boot_log
1 ha 969
 
1055 Galkov 970
        movzx   ecx, word [boot_y]
2130 serge 971
        if lang eq ru
2434 Serge 972
        or      ecx, (10+30*6) shl 16
3500 Serge 973
        else if lang eq sp
974
        or      ecx, (10+33*6) shl 16
3908 Serge 975
        else
2434 Serge 976
        or      ecx, (10+29*6) shl 16
3908 Serge 977
        end if
1055 Galkov 978
        sub     ecx, 10
979
        mov     edx, 0xFFFFFF
980
        mov     ebx, [MEM_AMOUNT]
981
        shr     ebx, 20
2434 Serge 982
        xor     edi, edi
1055 Galkov 983
        mov     eax, 0x00040000
2434 Serge 984
        inc     edi
1055 Galkov 985
        call    display_number_force
41 mikedld 986
 
465 serge 987
; BUILD SCHEDULER
988
 
2987 Serge 989
;        call    build_scheduler; sys32.inc
465 serge 990
 
2987 Serge 991
;        mov     esi, boot_devices
992
;        call    boot_log
567 serge 993
 
5201 serge 994
include "detect/vortex86.inc"                     ; Vortex86 SoC detection code
3555 Serge 995
 
5201 serge 996
        stdcall load_pe_driver, szVidintel, 0
997
 
3555 Serge 998
        call    usb_init
999
 
1 ha 1000
; SET PRELIMINARY WINDOW STACK AND POSITIONS
1001
 
2434 Serge 1002
        mov     esi, boot_windefs
1003
        call    boot_log
1004
        call    set_window_defaults
1 ha 1005
 
1006
; SET BACKGROUND DEFAULTS
1007
 
2434 Serge 1008
        mov     esi, boot_bgr
1009
        call    boot_log
1010
        call    init_background
1011
        call    calculatebackground
1 ha 1012
 
1013
; RESERVE SYSTEM IRQ'S JA PORT'S
1014
 
2434 Serge 1015
        mov     esi, boot_resirqports
1016
        call    boot_log
1017
        call    reserve_irqs_ports
1 ha 1018
 
2434 Serge 1019
        call    init_display
1020
        mov     eax, [def_cursor]
1021
        mov     [SLOT_BASE+APPDATA.cursor+256], eax
3555 Serge 1022
        mov     [SLOT_BASE+APPDATA.cursor+256*2], eax
281 serge 1023
 
3555 Serge 1024
; PRINT CPU FREQUENCY
281 serge 1025
 
3555 Serge 1026
        mov     esi, boot_cpufreq
2434 Serge 1027
        call    boot_log
3555 Serge 1028
 
5984 serge 1029
        cli
1030
        mov     ebx, [hpet_base]
1031
        test    ebx, ebx
1032
        jz      @F
1033
        mov     ebx, [ebx+0xF0]
1034
 
3555 Serge 1035
        rdtsc
5984 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
2434 Serge 1055
        mov     ecx, eax
1056
        mov     esi, 250            ; wait 1/4 a second
1057
        call    delay_ms
3555 Serge 1058
        rdtsc
5201 serge 1059
        sti
3555 Serge 1060
 
2434 Serge 1061
        sub     eax, ecx
3500 Serge 1062
        xor     edx, edx
1063
        shld    edx, eax, 2
2434 Serge 1064
        shl     eax, 2
5984 serge 1065
.next:
3500 Serge 1066
        mov     dword [cpu_freq], eax
1067
        mov     dword [cpu_freq+4], edx
3555 Serge 1068
        mov     ebx, 1000000
1069
        div     ebx
1070
        mov     ebx, eax
1 ha 1071
 
1055 Galkov 1072
        movzx   ecx, word [boot_y]
2130 serge 1073
        if lang eq ru
3555 Serge 1074
        add     ecx, (10+19*6) shl 16 - 10
3500 Serge 1075
        else if lang eq sp
3555 Serge 1076
        add     ecx, (10+25*6) shl 16 - 10
3908 Serge 1077
        else
3555 Serge 1078
        add     ecx, (10+17*6) shl 16 - 10
3908 Serge 1079
        end if
3555 Serge 1080
 
1055 Galkov 1081
        mov     edx, 0xFFFFFF
2434 Serge 1082
        xor     edi, edi
1055 Galkov 1083
        mov     eax, 0x00040000
2229 Serge 1084
        inc     edi
1055 Galkov 1085
        call    display_number_force
1038 diamond 1086
 
1 ha 1087
; SET VARIABLES
1088
 
2434 Serge 1089
        call    set_variables
1 ha 1090
 
1091
; STACK AND FDC
1092
 
2434 Serge 1093
        call    stack_init
1094
        call    fdc_init
1 ha 1095
 
1096
; PALETTE FOR 320x200 and 640x480 16 col
1097
 
2434 Serge 1098
        cmp     [SCR_MODE], word 0x12
1099
        jne     no_pal_vga
1100
        mov     esi, boot_pal_vga
1101
        call    boot_log
1102
        call    paletteVGA
1 ha 1103
      no_pal_vga:
1104
 
2434 Serge 1105
        cmp     [SCR_MODE], word 0x13
1106
        jne     no_pal_ega
1107
        mov     esi, boot_pal_ega
1108
        call    boot_log
1109
        call    palette320x200
1 ha 1110
      no_pal_ega:
1111
 
1112
; LOAD DEFAULT SKIN
1113
 
1055 Galkov 1114
        call    load_default_skin
1 ha 1115
 
5984 serge 1116
; Protect I/O permission map
465 serge 1117
 
2434 Serge 1118
        mov     esi, [default_io_map]
5565 serge 1119
        stdcall map_page, esi, [SLOT_BASE+256+APPDATA.io_map], PG_READ
2434 Serge 1120
        add     esi, 0x1000
5565 serge 1121
        stdcall map_page, esi, [SLOT_BASE+256+APPDATA.io_map+4], PG_READ
465 serge 1122
 
2434 Serge 1123
        stdcall map_page, tss._io_map_0, \
5565 serge 1124
                [SLOT_BASE+256+APPDATA.io_map], PG_READ
2434 Serge 1125
        stdcall map_page, tss._io_map_1, \
5565 serge 1126
                [SLOT_BASE+256+APPDATA.io_map+4], PG_READ
465 serge 1127
 
2141 serge 1128
; SET KEYBOARD PARAMETERS
2434 Serge 1129
        mov     al, 0xf6       ; reset keyboard, scan enabled
5201 serge 1130
        call    kb_write_wait_ack
2987 Serge 1131
        test    ah, ah
1132
        jnz     .no_keyboard
2141 serge 1133
 
2987 Serge 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
2141 serge 1143
       ; mov   al, 0xED       ; Keyboard LEDs - only for testing!
5201 serge 1144
       ; call  kb_write_wait_ack
2141 serge 1145
       ; mov   al, 111b
5201 serge 1146
       ; call  kb_write_wait_ack
2141 serge 1147
 
2434 Serge 1148
        mov     al, 0xF3     ; set repeat rate & delay
5201 serge 1149
        call    kb_write_wait_ack
2434 Serge 1150
        mov     al, 0; 30 250 ;00100010b ; 24 500  ;00100100b  ; 20 500
5201 serge 1151
        call    kb_write_wait_ack
2141 serge 1152
     ;// mike.dld [
2434 Serge 1153
        call    set_lights
2141 serge 1154
     ;// mike.dld ]
1155
        stdcall attach_int_handler, 1, irq1, 0
5201 serge 1156
        DEBUGF  1, "K : IRQ1 return code %x\n", eax
2987 Serge 1157
.no_keyboard:
2141 serge 1158
 
5201 serge 1159
; Load PS/2 mouse driver
2141 serge 1160
 
5201 serge 1161
        stdcall load_pe_driver, szPS2MDriver, 0
2141 serge 1162
 
2434 Serge 1163
        mov     esi, boot_setmouse
1164
        call    boot_log
1165
        call    setmouse
2141 serge 1166
 
5201 serge 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
1043 hidnplayr 1170
 
5201 serge 1171
        cli
1172
        mov     ebp, firstapp
1173
        call    fs_execute_from_sysdir
1174
        test    eax, eax
1175
        jns     first_app_found
1043 hidnplayr 1176
 
5201 serge 1177
        mov     esi, boot_failed
1178
        call    boot_log
1043 hidnplayr 1179
 
5201 serge 1180
        mov     eax, 0xDEADBEEF      ; otherwise halt
1181
        hlt
1043 hidnplayr 1182
 
5201 serge 1183
first_app_found:
1043 hidnplayr 1184
 
2010 serge 1185
; START MULTITASKING
1 ha 1186
 
1638 serge 1187
; A 'All set - press ESC to start' messages if need
767 diamond 1188
if preboot_blogesc
1055 Galkov 1189
        mov     esi, boot_tasking
1190
        call    boot_log
2434 Serge 1191
.bll1:
1192
        in      al, 0x60        ; wait for ESC key press
1055 Galkov 1193
        cmp     al, 129
1194
        jne     .bll1
767 diamond 1195
end if
1196
 
5201 serge 1197
        mov     [timer_ticks_enable], 1         ; for cd driver
3908 Serge 1198
 
5201 serge 1199
        sti
3908 Serge 1200
 
5201 serge 1201
        call    mtrr_validate
3725 Serge 1202
 
5201 serge 1203
        jmp     osloop
3908 Serge 1204
 
1205
 
5201 serge 1206
        ; Fly :)
3908 Serge 1207
 
5201 serge 1208
uglobal
1209
align 4
1210
ap_initialized  dd      0
1211
endg
3908 Serge 1212
 
5201 serge 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
1223
        mov     eax, sys_proc-OS_BASE+PROC.pdt_0
1224
        mov     cr3, eax
1225
        lock inc [ap_initialized]
1226
        jmp     idle_loop
3908 Serge 1227
 
1228
 
465 serge 1229
include 'unpacker.inc'
1230
 
1231
align 4
1232
boot_log:
2217 Serge 1233
        pushad
465 serge 1234
 
2434 Serge 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
465 serge 1243
 
2434 Serge 1244
        mov     [novesachecksum], 1000
1245
        call    checkVga_N13
465 serge 1246
 
1276 Lrz 1247
        popad
465 serge 1248
 
1276 Lrz 1249
        ret
465 serge 1250
 
3555 Serge 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
 
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
 
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
 
5201 serge 1286
        mov     [edx + APPDATA.process], sys_proc
3555 Serge 1287
 
5201 serge 1288
        lea     ebx, [edx+APPDATA.list]
1289
        lea     ecx, [sys_proc+PROC.thr_list]
1290
        list_add_tail ebx, ecx
1291
 
3555 Serge 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
 
1 ha 1301
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1302
;                                                                    ;
33 mario79 1303
;                    MAIN OS LOOP START                              ;
1 ha 1304
;                                                                    ;
1305
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1306
align 32
1307
osloop:
3555 Serge 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
5201 serge 1315
 
2465 Serge 1316
        call    __sys_draw_pointer
2434 Serge 1317
        call    window_check_events
1318
        call    mouse_check_events
1319
        call    checkmisc
1320
        call    checkVga_N13
5201 serge 1321
;--------------------------------------
3555 Serge 1322
.no_periodic:
2434 Serge 1323
        call    stack_handler
1324
        call    check_fdd_motor_status
1325
        call    check_ATAPI_device_event
2987 Serge 1326
        call    check_lights_state
2434 Serge 1327
        call    check_timers
5201 serge 1328
 
2434 Serge 1329
        jmp     osloop
33 mario79 1330
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1331
;                                                                    ;
1332
;                      MAIN OS LOOP END                              ;
1333
;                                                                    ;
1334
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3555 Serge 1335
proc osloop_has_work?
1336
        cmp     [osloop_nonperiodic_work], 0
1337
        jnz     .yes
1338
        call    stack_handler_has_work?
1339
        jnz     .yes
4287 Serge 1340
        call    check_fdd_motor_status_has_work?
1341
        jnz     .yes
3555 Serge 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
1055 Galkov 1350
        ret
3555 Serge 1351
.yes:
1352
        xor     eax, eax
1353
        inc     eax
1354
        ret
1355
endp
1 ha 1356
 
3555 Serge 1357
proc wakeup_osloop
1358
        mov     [osloop_nonperiodic_work], 1
1359
        ret
1360
endp
1361
 
1 ha 1362
uglobal
3555 Serge 1363
align 4
1364
osloop_nonperiodic_work dd      ?
1 ha 1365
endg
1366
 
5201 serge 1367
uglobal
1368
align 64
1369
idle_addr       rb      64
1370
endg
1371
 
3555 Serge 1372
idle_thread:
1373
        sti
5201 serge 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.
3555 Serge 1379
idle_loop:
5201 serge 1380
        cmp     [use_mwait_for_idle], 0
1381
        jnz     idle_loop_mwait
1382
 
1383
idle_loop_hlt:
3555 Serge 1384
        hlt
5201 serge 1385
        jmp     idle_loop_hlt
1 ha 1386
 
5201 serge 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
1 ha 1396
 
3555 Serge 1397
 
1 ha 1398
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1399
;                                                                      ;
1400
;                   INCLUDED SYSTEM FILES                              ;
1401
;                                                                      ;
1402
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1403
 
1404
 
7 me_root 1405
include "kernel32.inc"
1 ha 1406
 
1407
 
1408
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1409
;                                                                      ;
1410
;                       KERNEL FUNCTIONS                               ;
1411
;                                                                      ;
1412
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1413
 
1414
reserve_irqs_ports:
1415
 
1273 Lrz 1416
 
1417
; RESERVE PORTS
2434 Serge 1418
        mov     eax, RESERVED_PORTS
1419
        mov     ecx, 1
1273 Lrz 1420
 
2434 Serge 1421
        mov     [eax], dword 4
269 serge 1422
 
2434 Serge 1423
        mov     [eax+16], ecx
1424
        mov     [eax+16+4], dword 0
3500 Serge 1425
        mov     [eax+16+8], dword 0x2D
269 serge 1426
 
2434 Serge 1427
        mov     [eax+32], ecx
1428
        mov     [eax+32+4], dword 0x30
1429
        mov     [eax+32+8], dword 0x4D
233 serge 1430
 
2434 Serge 1431
        mov     [eax+48], ecx
1432
        mov     [eax+48+4], dword 0x50
3500 Serge 1433
        mov     [eax+48+8], dword 0xDF
233 serge 1434
 
2434 Serge 1435
        mov     [eax+64], ecx
1436
        mov     [eax+64+4], dword 0xE5
1437
        mov     [eax+64+8], dword 0xFF
1273 Lrz 1438
 
1055 Galkov 1439
        ret
1 ha 1440
 
1441
 
1442
iglobal
3555 Serge 1443
  process_number dd 0x2
1 ha 1444
endg
1445
 
1446
set_variables:
1447
 
2434 Serge 1448
        mov     ecx, 0x16                    ; flush port 0x60
2141 serge 1449
.fl60:
2434 Serge 1450
        in      al, 0x60
1451
        loop    .fl60
1452
        push    eax
1 ha 1453
 
3908 Serge 1454
        mov     ax, [BOOT_VARS+BOOT_Y_RES]
2434 Serge 1455
        shr     ax, 1
1456
        shl     eax, 16
3908 Serge 1457
        mov     ax, [BOOT_VARS+BOOT_X_RES]
2434 Serge 1458
        shr     ax, 1
1459
        mov     [MOUSE_X], eax
3555 Serge 1460
        call    wakeup_osloop
41 mikedld 1461
 
2434 Serge 1462
        xor     eax, eax
1463
        mov     [BTN_ADDR], dword BUTTON_INFO ; address of button list
1 ha 1464
 
2434 Serge 1465
        mov     byte [KEY_COUNT], al              ; keyboard buffer
1466
        mov     byte [BTN_COUNT], al              ; button buffer
1267 Lrz 1467
;        mov   [MOUSE_X],dword 100*65536+100    ; mouse x/y
1468
 
2434 Serge 1469
        pop     eax
1055 Galkov 1470
        ret
1 ha 1471
 
1472
align 4
1304 Lrz 1473
;input  eax=43,bl-byte of output, ecx - number of port
1 ha 1474
sys_outport:
1475
 
2434 Serge 1476
        mov     edi, ecx   ; separate flag for read / write
1477
        and     ecx, 65535
1 ha 1478
 
2434 Serge 1479
        mov     eax, [RESERVED_PORTS]
1480
        test    eax, eax
1481
        jnz     .sopl8
1482
        inc     eax
1483
        mov     [esp+32], eax
1484
        ret
1 ha 1485
 
1304 Lrz 1486
  .sopl8:
2434 Serge 1487
        mov     edx, [TASK_BASE]
1488
        mov     edx, [edx+0x4]
1304 Lrz 1489
    ;and   ecx,65535
1490
    ;cld - set on interrupt 0x40
1491
  .sopl1:
1 ha 1492
 
2434 Serge 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
1304 Lrz 1502
.sopl3:
1 ha 1503
 
2434 Serge 1504
        test    edi, 0x80000000; read ?
1505
        jnz     .sopl4
1 ha 1506
 
2434 Serge 1507
        mov     eax, ebx
1508
        mov     dx, cx   ; write
1509
        out     dx, al
1510
        and     [esp+32], dword 0
1511
        ret
1 ha 1512
 
2434 Serge 1513
        .sopl2:
1 ha 1514
 
2434 Serge 1515
        dec     eax
1516
        jnz     .sopl1
1517
        inc     eax
1518
        mov     [esp+32], eax
1519
        ret
1 ha 1520
 
1638 serge 1521
 
1304 Lrz 1522
  .sopl4:
1 ha 1523
 
2434 Serge 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
1 ha 1530
 
1531
display_number:
1369 Lrz 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
1 ha 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
2434 Serge 1549
        xor     edi, edi
211 serge 1550
display_number_force:
2434 Serge 1551
        push    eax
1552
        and     eax, 0x3fffffff
1553
        cmp     eax, 0xffff     ; length > 0 ?
1554
        pop     eax
1555
        jge     cont_displ
1556
        ret
1 ha 1557
   cont_displ:
2434 Serge 1558
        push    eax
1559
        and     eax, 0x3fffffff
1560
        cmp     eax, 61*0x10000  ; length <= 60 ?
1561
        pop     eax
1562
        jb      cont_displ2
1563
        ret
1 ha 1564
   cont_displ2:
1565
 
2434 Serge 1566
        pushad
1 ha 1567
 
2434 Serge 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]
1276 Lrz 1574
 displnl1:
2434 Serge 1575
        sub     esp, 64
1 ha 1576
 
2434 Serge 1577
        test    ah, ah            ; DECIMAL
1578
        jnz     no_display_desnum
1579
        shr     eax, 16
1580
        and     eax, 0xC03f
652 mario79 1581
;     and   eax,0x3f
2434 Serge 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
1276 Lrz 1589
 d_desnum:
2434 Serge 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
1 ha 1603
   no_display_desnum:
1604
 
2434 Serge 1605
        cmp     ah, 0x01         ; HEXADECIMAL
1606
        jne     no_display_hexnum
1607
        shr     eax, 16
1608
        and     eax, 0xC03f
652 mario79 1609
;     and   eax,0x3f
2434 Serge 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
1 ha 1617
   d_hexnum:
2434 Serge 1618
        xor     edx, edx
1619
        call    division_64_bits
1620
        div     ebx
1056 Galkov 1621
   hexletters = __fdo_hexdigits
2434 Serge 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
1 ha 1633
   no_display_hexnum:
1634
 
2434 Serge 1635
        cmp     ah, 0x02         ; BINARY
1636
        jne     no_display_binnum
1637
        shr     eax, 16
1638
        and     eax, 0xC03f
652 mario79 1639
;     and   eax,0x3f
2434 Serge 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
1 ha 1647
   d_binnum:
2434 Serge 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
1 ha 1661
   no_display_binnum:
1662
 
2434 Serge 1663
        add     esp, 64
1664
        popad
1665
        ret
1 ha 1666
 
652 mario79 1667
normalize_number:
2434 Serge 1668
        test    ah, 0x80
1669
        jz      .continue
1670
        mov     ecx, 48
1671
        and     eax, 0x3f
652 mario79 1672
@@:
2434 Serge 1673
        inc     edi
1674
        cmp     [edi], cl
1675
        jne     .continue
1676
        dec     eax
1677
        cmp     eax, 1
1678
        ja      @r
1679
        mov     al, 1
652 mario79 1680
.continue:
2434 Serge 1681
        and     eax, 0x3f
1682
        ret
1 ha 1683
 
655 mario79 1684
division_64_bits:
2434 Serge 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
655 mario79 1692
.continue:
2434 Serge 1693
        ret
652 mario79 1694
 
1 ha 1695
draw_num_text:
2434 Serge 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]
684 diamond 1701
; add window start x & y
2434 Serge 1702
        mov     ecx, [TASK_BASE]
465 serge 1703
 
2434 Serge 1704
        mov     edi, [CURRENT_TASK]
1705
        shl     edi, 8
465 serge 1706
 
2434 Serge 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]
1055 Galkov 1714
        and     ecx, not 0x80000000     ; force counted string
1715
        mov     eax, [esp+64+8]         ; background color (if given)
1716
        mov     edi, [esp+64+4]
2434 Serge 1717
        jmp     dtext
5201 serge 1718
;-----------------------------------------------------------------------------
5596 serge 1719
iglobal
1720
midi_base dw 0
5201 serge 1721
endg
1722
;-----------------------------------------------------------------------------
1 ha 1723
align 4
1724
sys_setup:
5201 serge 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
1 ha 1735
; 11 = enable lba read
1736
; 12 = enable pci access
5201 serge 1737
;-----------------------------------------------------------------------------
1738
        and     [esp+32], dword 0
1739
; F.21.1 - set MPU MIDI base port
1740
        dec     ebx
1741
        jnz     @f
1 ha 1742
 
2434 Serge 1743
        cmp     ecx, 0x100
5201 serge 1744
        jb      @f
1 ha 1745
 
2434 Serge 1746
        mov     esi, 65535
1747
        cmp     esi, ecx
5201 serge 1748
        jb      @f
1276 Lrz 1749
 
5201 serge 1750
        mov     [midi_base], cx
1751
        mov     word [mididp], cx
1752
        inc     cx
1753
        mov     word [midisp], cx
2434 Serge 1754
        ret
5201 serge 1755
;--------------------------------------
1756
@@:
1757
; F.21.2 - set keyboard layout
1758
        dec     ebx
1759
        jnz     @f
1276 Lrz 1760
 
2434 Serge 1761
        mov     edi, [TASK_BASE]
1762
        mov     eax, [edi+TASKDATA.mem_start]
1763
        add     eax, edx
5201 serge 1764
; 1 = normal layout
1765
        dec     ecx
1766
        jnz     .shift
1 ha 1767
 
2434 Serge 1768
        mov     ebx, keymap
1769
        mov     ecx, 128
1770
        call    memmove
1771
        ret
5201 serge 1772
;--------------------------------------
1773
.shift:
1774
; 2 = layout at pressed Shift
2434 Serge 1775
        dec     ecx
5201 serge 1776
        jnz     .alt
1276 Lrz 1777
 
2434 Serge 1778
        mov     ebx, keymap_shift
1779
        mov     ecx, 128
1780
        call    memmove
1781
        ret
5201 serge 1782
;--------------------------------------
1783
.alt:
1784
; 3 = layout at pressed Alt
2434 Serge 1785
        dec     ecx
5201 serge 1786
        jnz     .country
1787
 
2434 Serge 1788
        mov     ebx, keymap_alt
1789
        mov     ecx, 128
1790
        call    memmove
1791
        ret
5201 serge 1792
;--------------------------------------
1793
.country:
1794
; country identifier
2434 Serge 1795
        sub     ecx, 6
5201 serge 1796
        jnz     .error
1797
 
2434 Serge 1798
        mov     word [keyboard], dx
1799
        ret
5201 serge 1800
;--------------------------------------
1801
@@:
1802
; F.21.5 - set system language
1803
        sub     ebx, 3
1804
        jnz     @f
1276 Lrz 1805
 
2434 Serge 1806
        mov     [syslang], ecx
1807
        ret
5201 serge 1808
;--------------------------------------
1809
@@:
1810
; F.21.11 - enable/disable low-level access to HD
1811
        and     ecx, 1
1812
        sub     ebx, 6
1813
        jnz     @f
1638 serge 1814
 
5201 serge 1815
        mov     [lba_read_enabled], ecx
2434 Serge 1816
        ret
5201 serge 1817
;--------------------------------------
1818
@@:
1819
; F.21.12 - enable/disable low-level access to PCI
2434 Serge 1820
        dec     ebx
5201 serge 1821
        jnz     .error
1 ha 1822
 
2434 Serge 1823
        mov     [pci_access_enabled], ecx
1824
        ret
5201 serge 1825
;--------------------------------------
1826
.error:
2434 Serge 1827
        or      [esp+32], dword -1
1828
        ret
5201 serge 1829
;-----------------------------------------------------------------------------
1 ha 1830
align 4
1831
sys_getsetup:
5201 serge 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
1 ha 1848
 
2434 Serge 1849
        movzx   eax, [midi_base]
1850
        mov     [esp+32], eax
1851
        ret
5201 serge 1852
;--------------------------------------
1853
@@:
1854
; F.26.2 - get keyboard layout
2434 Serge 1855
        dec     ebx
5201 serge 1856
        jnz     @f
1 ha 1857
 
2434 Serge 1858
        mov     edi, [TASK_BASE]
1859
        mov     ebx, [edi+TASKDATA.mem_start]
1860
        add     ebx, edx
5201 serge 1861
; 1 = normal layout
1862
        dec     ecx
1863
        jnz     .shift
1276 Lrz 1864
 
2434 Serge 1865
        mov     eax, keymap
1866
        mov     ecx, 128
1867
        call    memmove
1868
        ret
5201 serge 1869
;--------------------------------------
1870
.shift:
1871
; 2 = layout with pressed Shift
2434 Serge 1872
        dec     ecx
5201 serge 1873
        jnz     .alt
1276 Lrz 1874
 
2434 Serge 1875
        mov     eax, keymap_shift
1876
        mov     ecx, 128
1877
        call    memmove
1878
        ret
5201 serge 1879
;--------------------------------------
1880
.alt:
1881
; 3 = layout with pressed Alt
2434 Serge 1882
        dec     ecx
5201 serge 1883
        jne     .country
1276 Lrz 1884
 
2434 Serge 1885
        mov     eax, keymap_alt
1886
        mov     ecx, 128
1887
        call    memmove
1888
        ret
5201 serge 1889
;--------------------------------------
1890
.country:
1891
; 9 = country identifier
2434 Serge 1892
        sub     ecx, 6
5201 serge 1893
        jnz     .error
1894
 
2434 Serge 1895
        movzx   eax, word [keyboard]
1896
        mov     [esp+32], eax
1897
        ret
5201 serge 1898
;--------------------------------------
1899
@@:
1900
; F.26.5 - get system language
1901
        sub     ebx, 3
1902
        jnz     @f
1276 Lrz 1903
 
2434 Serge 1904
        mov     eax, [syslang]
1905
        mov     [esp+32], eax
1276 Lrz 1906
        ret
5201 serge 1907
;--------------------------------------
1908
@@:
1909
; F.26.9 - get the value of the time counter
1910
        sub     ebx, 4
1911
        jnz     @f
1912
 
1913
        mov     eax, [timer_ticks]
2434 Serge 1914
        mov     [esp+32], eax
1915
        ret
5201 serge 1916
;--------------------------------------
1917
@@:
5984 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
@@:
5201 serge 1928
; F.26.11 - Find out whether low-level HD access is enabled
5984 serge 1929
        sub     ebx, 1
5201 serge 1930
        jnz     @f
1931
 
2434 Serge 1932
        mov     eax, [lba_read_enabled]
1933
        mov     [esp+32], eax
1934
        ret
5201 serge 1935
;--------------------------------------
1936
@@:
1937
; F.26.12 - Find out whether low-level PCI access is enabled
2434 Serge 1938
        dec     ebx
5201 serge 1939
        jnz     .error
1940
 
2434 Serge 1941
        mov     eax, [pci_access_enabled]
1942
        mov     [esp+32], eax
1943
        ret
5201 serge 1944
;--------------------------------------
1945
.error:
1946
        or      [esp+32], dword -1
2434 Serge 1947
        ret
5201 serge 1948
;-----------------------------------------------------------------------------
479 kastigar 1949
get_timer_ticks:
2434 Serge 1950
        mov     eax, [timer_ticks]
1951
        ret
5201 serge 1952
;-----------------------------------------------------------------------------
283 diamond 1953
iglobal
1 ha 1954
align 4
5984 serge 1955
mousefn dd msscreen
1956
        dd mswin
1957
        dd msbutton
1958
        dd msbuttonExt
1055 Galkov 1959
        dd app_load_cursor
1960
        dd app_set_cursor
1961
        dd app_delete_cursor
1962
        dd msz
283 diamond 1963
endg
5201 serge 1964
;-----------------------------------------------------------------------------
1 ha 1965
readmousepos:
1966
 
1967
; eax=0 screen relative
1968
; eax=1 window relative
1969
; eax=2 buttons pressed
5984 serge 1970
; eax=3 buttons pressed ext
221 serge 1971
; eax=4 load cursor
1972
; eax=5 set cursor
5984 serge 1973
; eax=6 delete cursor
479 kastigar 1974
; eax=7 get mouse_z
1 ha 1975
 
2434 Serge 1976
        cmp     ebx, 7
5984 serge 1977
        ja      @f
2434 Serge 1978
        jmp     [mousefn+ebx*4]
5984 serge 1979
 
221 serge 1980
msscreen:
2434 Serge 1981
        mov     eax, [MOUSE_X]
1982
        shl     eax, 16
1983
        mov     ax, [MOUSE_Y]
1984
        mov     [esp+36-4], eax
5984 serge 1985
@@:
2434 Serge 1986
        ret
5984 serge 1987
 
221 serge 1988
mswin:
2434 Serge 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
5984 serge 2005
 
221 serge 2006
msbutton:
2434 Serge 2007
        movzx   eax, byte [BTN_DOWN]
2008
        mov     [esp+36-4], eax
2009
        ret
5984 serge 2010
 
2011
msbuttonExt:
2012
        mov     eax, [BTN_DOWN]
2434 Serge 2013
        mov     [esp+36-4], eax
2014
        ret
164 serge 2015
 
221 serge 2016
app_load_cursor:
2434 Serge 2017
        cmp     ecx, OS_BASE
5984 serge 2018
        jae     @f
2434 Serge 2019
        stdcall load_cursor, ecx, edx
2020
        mov     [esp+36-4], eax
5984 serge 2021
@@:
2434 Serge 2022
        ret
164 serge 2023
 
221 serge 2024
app_set_cursor:
2434 Serge 2025
        stdcall set_cursor, ecx
2026
        mov     [esp+36-4], eax
2027
        ret
1 ha 2028
 
233 serge 2029
app_delete_cursor:
2434 Serge 2030
        stdcall delete_cursor, ecx
2031
        mov     [esp+36-4], eax
2032
        ret
1 ha 2033
 
5984 serge 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
 
1 ha 2050
is_input:
2051
 
2434 Serge 2052
        push    edx
2053
        mov     dx, word [midisp]
2054
        in      al, dx
2055
        and     al, 0x80
2056
        pop     edx
2057
        ret
1 ha 2058
 
2059
is_output:
2060
 
2434 Serge 2061
        push    edx
2062
        mov     dx, word [midisp]
2063
        in      al, dx
2064
        and     al, 0x40
2065
        pop     edx
2066
        ret
1 ha 2067
 
2068
 
2069
get_mpu_in:
2070
 
2434 Serge 2071
        push    edx
2072
        mov     dx, word [mididp]
2073
        in      al, dx
2074
        pop     edx
2075
        ret
1 ha 2076
 
2077
 
2078
put_mpu_out:
2079
 
2434 Serge 2080
        push    edx
2081
        mov     dx, word [mididp]
2082
        out     dx, al
2083
        pop     edx
2084
        ret
1 ha 2085
 
2086
 
2087
 
2088
align 4
2089
 
2090
sys_midi:
2434 Serge 2091
        cmp     [mididp], 0
2092
        jnz     sm0
2093
        mov     [esp+36], dword 1
2094
        ret
1276 Lrz 2095
sm0:
2434 Serge 2096
        and     [esp+36], dword 0
2097
        dec     ebx
2098
        jnz     smn1
1276 Lrz 2099
 ;    call setuart
2100
su1:
2434 Serge 2101
        call    is_output
2102
        test    al, al
2103
        jnz     su1
2104
        mov     dx, word [midisp]
2105
        mov     al, 0xff
2106
        out     dx, al
1276 Lrz 2107
su2:
2434 Serge 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
1276 Lrz 2117
su3:
2434 Serge 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
1276 Lrz 2125
smn1:
2434 Serge 2126
        dec     ebx
2127
        jnz     smn2
1276 Lrz 2128
sm10:
2434 Serge 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
1 ha 2137
 
2138
detect_devices:
2139
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
769 Rus 2140
;include 'detect/commouse.inc'
479 kastigar 2141
;include 'detect/ps2mouse.inc'
1 ha 2142
;include 'detect/dev_fd.inc'
2143
;include 'detect/dev_hdcd.inc'
2144
;include 'detect/sear_par.inc'
2145
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2434 Serge 2146
        ret
1 ha 2147
 
2148
sys_end:
2434 Serge 2149
;--------------------------------------
2150
        cmp     [_display.select_cursor], 0
2151
        je      @f
2152
; restore default cursor before killing
2153
        pusha
2154
        mov     ecx, [current_slot]
2439 Serge 2155
        call    restore_default_cursor_before_killing
2434 Serge 2156
        popa
2157
@@:
2158
;--------------------------------------
3555 Serge 2159
; kill all sockets this process owns
2160
        pusha
2161
        mov     edx, [TASK_BASE]
2162
        mov     edx, [edx+TASKDATA.pid]
6078 serge 2163
        call    socket_process_end
3555 Serge 2164
        popa
2165
;--------------------------------------
2434 Serge 2166
        mov     ecx, [current_slot]
2167
        mov     eax, [ecx+APPDATA.tls_base]
2168
        test    eax, eax
2169
        jz      @F
1220 serge 2170
 
2434 Serge 2171
        stdcall user_free, eax
1220 serge 2172
@@:
2173
 
2434 Serge 2174
        mov     eax, [TASK_BASE]
6240 serge 2175
        mov     [eax+TASKDATA.state], TSTATE_ZOMBIE
3555 Serge 2176
        call    wakeup_osloop
41 mikedld 2177
 
3626 Serge 2178
.waitterm:            ; wait here for termination
2179
        call    change_task
2180
        jmp     .waitterm
2439 Serge 2181
;------------------------------------------------------------------------------
2465 Serge 2182
align 4
2439 Serge 2183
restore_default_cursor_before_killing:
2987 Serge 2184
        pushfd
2185
        cli
2439 Serge 2186
        mov     eax, [def_cursor]
2187
        mov     [ecx+APPDATA.cursor], eax
1 ha 2188
 
2439 Serge 2189
        movzx   eax, word [MOUSE_Y]
2190
        movzx   ebx, word [MOUSE_X]
2465 Serge 2191
        mov     eax, [d_width_calc_area + eax*4]
2192
 
5565 serge 2193
        add     eax, [_display.win_map]
2439 Serge 2194
        movzx   edx, byte [ebx+eax]
2195
        shl     edx, 8
2196
        mov     esi, [edx+SLOT_BASE+APPDATA.cursor]
2465 Serge 2197
 
2198
        cmp     esi, [current_cursor]
2199
        je      @f
2200
 
2439 Serge 2201
        push    esi
2202
        call    [_display.select_cursor]
2203
        mov     [current_cursor], esi
2465 Serge 2204
@@:
2205
        mov     [redrawmouse_unconditional], 1
3555 Serge 2206
        call    wakeup_osloop
2987 Serge 2207
        popfd
2439 Serge 2208
        ret
2209
;------------------------------------------------------------------------------
75 diamond 2210
iglobal
170 serge 2211
align 4
75 diamond 2212
sys_system_table:
2268 Serge 2213
        dd      sysfn_deactivate        ; 1 = deactivate window
1055 Galkov 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
2987 Serge 2236
        dd      sysfn_min_windows       ; 23 = minimize all windows
2237
        dd      sysfn_set_screen_sizes  ; 24 = set screen sizes for Vesa
5984 serge 2238
 
2239
        dd      sysfn_zmodif            ; 25 = get/set window z modifier  ;Fantomer
75 diamond 2240
sysfn_num = ($ - sys_system_table)/4
2241
endg
2268 Serge 2242
;------------------------------------------------------------------------------
1 ha 2243
sys_system:
1055 Galkov 2244
        dec     ebx
2245
        cmp     ebx, sysfn_num
2246
        jae     @f
2247
        jmp     dword [sys_system_table + ebx*4]
75 diamond 2248
@@:
1055 Galkov 2249
        ret
2268 Serge 2250
;------------------------------------------------------------------------------
1055 Galkov 2251
sysfn_shutdown:          ; 18.9 = system shutdown
2434 Serge 2252
        cmp     ecx, 1
2253
        jl      exit_for_anyone
2254
        cmp     ecx, 4
2255
        jg      exit_for_anyone
3908 Serge 2256
        mov     [BOOT_VARS+0x9030], cl
748 heavyiron 2257
 
2434 Serge 2258
        mov     eax, [TASK_COUNT]
2259
        mov     [SYS_SHUTDOWN], al
2260
        mov     [shutdown_processes], eax
3555 Serge 2261
        call    wakeup_osloop
2434 Serge 2262
        and     dword [esp+32], 0
748 heavyiron 2263
 exit_for_anyone:
2434 Serge 2264
        ret
1 ha 2265
  uglobal
2434 Serge 2266
   shutdown_processes:
2267
                       dd 0x0
1 ha 2268
  endg
2268 Serge 2269
;------------------------------------------------------------------------------
1055 Galkov 2270
sysfn_terminate:        ; 18.2 = TERMINATE
2987 Serge 2271
        push    ecx
2434 Serge 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
3500 Serge 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
2434 Serge 2289
;--------------------------------------
3555 Serge 2290
; terminate all network sockets it used
2291
        pusha
2292
        mov     eax, edx
6078 serge 2293
        call    socket_process_end
3555 Serge 2294
        popa
2295
;--------------------------------------
2434 Serge 2296
        cmp     [_display.select_cursor], 0
2465 Serge 2297
        je      .restore_end
2434 Serge 2298
; restore default cursor before killing
2299
        pusha
2300
        mov     ecx, [esp+32]
2301
        shl     ecx, 8
2439 Serge 2302
        add     ecx, SLOT_BASE
2465 Serge 2303
        mov     eax, [def_cursor]
2304
        cmp     [ecx+APPDATA.cursor], eax
2305
        je      @f
2439 Serge 2306
        call    restore_default_cursor_before_killing
2465 Serge 2307
@@:
2434 Serge 2308
        popa
2465 Serge 2309
.restore_end:
2434 Serge 2310
;--------------------------------------
1 ha 2311
     ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
2434 Serge 2312
        mov     [ecx], byte 3; clear possible i40's
3555 Serge 2313
        call    wakeup_osloop
1 ha 2314
     ;call MEM_Heap_UnLock
2315
 
3555 Serge 2316
        cmp     edx, [application_table_owner]; clear app table stat
2434 Serge 2317
        jne     noatsc
3555 Serge 2318
        call    unlock_application_table
2987 Serge 2319
noatsc:
2320
noprocessterminate:
2321
        add     esp, 4
2434 Serge 2322
        ret
2268 Serge 2323
;------------------------------------------------------------------------------
85 halyavin 2324
sysfn_terminate2:
2325
;lock application_table_status mutex
164 serge 2326
.table_status:
3555 Serge 2327
        call    lock_application_table
2434 Serge 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
3555 Serge 2335
        call    unlock_application_table
2434 Serge 2336
        sti
2337
        and     dword [esp+32], 0
2338
        ret
85 halyavin 2339
.not_found:
3555 Serge 2340
        call    unlock_application_table
2434 Serge 2341
        or      dword [esp+32], -1
2342
        ret
2268 Serge 2343
;------------------------------------------------------------------------------
2344
sysfn_deactivate:         ; 18.1 = DEACTIVATE WINDOW
2434 Serge 2345
        cmp     ecx, 2
2346
        jb      .nowindowdeactivate
2347
        cmp     ecx, [TASK_COUNT]
2348
        ja      .nowindowdeactivate
85 halyavin 2349
 
2434 Serge 2350
        movzx   esi, word [WIN_STACK + ecx*2]
2351
        cmp     esi, 1
2352
        je      .nowindowdeactivate ; already deactive
2268 Serge 2353
 
2434 Serge 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
2268 Serge 2360
 
2434 Serge 2361
        call    syscall_display_settings._.calculate_whole_screen
2362
        call    syscall_display_settings._.redraw_whole_screen
2268 Serge 2363
.nowindowdeactivate:
2434 Serge 2364
        ret
3500 Serge 2365
;------------------------------------------------------------------------------
1055 Galkov 2366
sysfn_activate:         ; 18.3 = ACTIVATE WINDOW
2434 Serge 2367
        cmp     ecx, 2
2368
        jb      .nowindowactivate
2369
        cmp     ecx, [TASK_COUNT]
2370
        ja      .nowindowactivate
3500 Serge 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
;-------------------------------------
2434 Serge 2383
        mov     [window_minimize], 2; restore window if minimized
3555 Serge 2384
        call    wakeup_osloop
105 poddubny 2385
 
2434 Serge 2386
        movzx   esi, word [WIN_STACK + ecx*2]
2387
        cmp     esi, [TASK_COUNT]
2388
        je      .nowindowactivate; already active
105 poddubny 2389
 
2434 Serge 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
105 poddubny 2396
.nowindowactivate:
2434 Serge 2397
        ret
2268 Serge 2398
;------------------------------------------------------------------------------
5984 serge 2399
align 4
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]
2414
        ja      .fail
2415
        cmp     edx, 1
2416
        je      .fail
2417
 
2418
        mov     eax, edx
2419
        shl     edx, 5
2420
 
2421
        cmp     [edx + CURRENT_TASK + TASKDATA.state], 9
2422
        je      .fail
2423
 
2424
        cmp     ecx, 1
2425
        jnz     .set_zmod
2426
 
2427
        mov     al, [edx + window_data + WDATA.z_modif]
2428
        jmp     .exit
2429
 
2430
.set_zmod:
2431
        cmp     ecx, 2
2432
        jnz     .fail
2433
 
2434
        mov     ebx, esi
2435
        mov     esi, eax
2436
 
2437
        cmp     bl, ZPOS_ALWAYS_TOP
2438
        jg      .fail
2439
 
2440
        mov     [edx + window_data + WDATA.z_modif], bl
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
2448
        call    window._.set_screen
2449
        call    window._.set_top_wnd
2450
        call    window._.redraw_top_wnd
2451
 
2452
        shl     esi, 5
2453
        mov     [esi + window_data + WDATA.fl_redraw], 1
2454
 
2455
 
2456
        mov     eax, 1
2457
        jmp     .exit
2458
.fail:
2459
        xor     eax, eax
2460
.exit:
2461
        mov     [esp+32], eax
2462
        ret
2463
 
2464
;------------------------------------------------------------------------------
1055 Galkov 2465
sysfn_getidletime:              ; 18.4 = GET IDLETIME
3555 Serge 2466
        mov     eax, [CURRENT_TASK+32+TASKDATA.cpu_usage]
2434 Serge 2467
        mov     [esp+32], eax
2468
        ret
2268 Serge 2469
;------------------------------------------------------------------------------
1055 Galkov 2470
sysfn_getcpuclock:              ; 18.5 = GET TSC/SEC
3500 Serge 2471
        mov     eax, dword [cpu_freq]
2434 Serge 2472
        mov     [esp+32], eax
2473
        ret
2268 Serge 2474
;------------------------------------------------------------------------------
3500 Serge 2475
get_cpu_freq:
2476
        mov     eax, dword [cpu_freq]
2477
        mov     edx, dword [cpu_freq+4]
2478
        ret
1 ha 2479
;  SAVE ramdisk to /hd/1/menuet.img
2480
;!!!!!!!!!!!!!!!!!!!!!!!!
2481
   include 'blkdev/rdsave.inc'
2482
;!!!!!!!!!!!!!!!!!!!!!!!!
2268 Serge 2483
;------------------------------------------------------------------------------
1232 Lrz 2484
align 4
1055 Galkov 2485
sysfn_getactive:        ; 18.7 = get active window
2434 Serge 2486
        mov     eax, [TASK_COUNT]
2487
        movzx   eax, word [WIN_POS + eax*2]
2488
        mov     [esp+32], eax
2489
        ret
2268 Serge 2490
;------------------------------------------------------------------------------
1055 Galkov 2491
sysfn_sound_flag:       ; 18.8 = get/set sound_flag
1232 Lrz 2492
;     cmp  ecx,1
2434 Serge 2493
        dec     ecx
2494
        jnz     nogetsoundflag
2495
        movzx   eax, byte [sound_flag]; get sound_flag
2496
        mov     [esp+32], eax
2497
        ret
1 ha 2498
 nogetsoundflag:
1232 Lrz 2499
;     cmp  ecx,2
2434 Serge 2500
        dec     ecx
2501
        jnz     nosoundflag
2502
        xor     byte [sound_flag], 1
75 diamond 2503
 nosoundflag:
2434 Serge 2504
        ret
2268 Serge 2505
;------------------------------------------------------------------------------
1055 Galkov 2506
sysfn_minimize:         ; 18.10 = minimize window
2434 Serge 2507
        mov     [window_minimize], 1
3555 Serge 2508
        call    wakeup_osloop
2434 Serge 2509
        ret
2268 Serge 2510
;------------------------------------------------------------------------------
1232 Lrz 2511
align 4
1055 Galkov 2512
sysfn_getdiskinfo:      ; 18.11 = get disk info table
2434 Serge 2513
        dec     ecx
5201 serge 2514
        jnz     .exit
2515
.small_table:
2434 Serge 2516
        mov     edi, edx
2517
        mov     esi, DRIVE_DATA
5201 serge 2518
        mov     ecx, DRIVE_DATA_SIZE ;10
2434 Serge 2519
        cld
5201 serge 2520
        rep movsb
2521
.exit:
2434 Serge 2522
        ret
2268 Serge 2523
;------------------------------------------------------------------------------
1055 Galkov 2524
sysfn_lastkey:          ; 18.12 = return 0 (backward compatibility)
2525
        and     dword [esp+32], 0
2526
        ret
2268 Serge 2527
;------------------------------------------------------------------------------
1055 Galkov 2528
sysfn_getversion:       ; 18.13 = get kernel ID and version
2434 Serge 2529
        mov     edi, ecx
2530
        mov     esi, version_inf
2531
        mov     ecx, version_end-version_inf
2532
        rep movsb
2533
        ret
2268 Serge 2534
;------------------------------------------------------------------------------
75 diamond 2535
sysfn_waitretrace:     ; 18.14 = sys wait retrace
41 mikedld 2536
     ;wait retrace functions
2537
 sys_wait_retrace:
2434 Serge 2538
        mov     edx, 0x3da
41 mikedld 2539
 WaitRetrace_loop:
2434 Serge 2540
        in      al, dx
2541
        test    al, 1000b
2542
        jz      WaitRetrace_loop
2543
        and     [esp+32], dword 0
2544
        ret
2268 Serge 2545
;------------------------------------------------------------------------------
1232 Lrz 2546
align 4
1055 Galkov 2547
sysfn_centermouse:      ; 18.15 = mouse centered
5565 serge 2548
        mov     eax, [_display.width]
2434 Serge 2549
        shr     eax, 1
2550
        mov     [MOUSE_X], ax
5565 serge 2551
        mov     eax, [_display.height]
2434 Serge 2552
        shr     eax, 1
2553
        mov     [MOUSE_Y], ax
3555 Serge 2554
        call    wakeup_osloop
2434 Serge 2555
        xor     eax, eax
2556
        and     [esp+32], eax
2557
        ret
2268 Serge 2558
;------------------------------------------------------------------------------
5984 serge 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:
2434 Serge 2564
        xor     eax, eax
2565
        mov     ax, [mouse_speed_factor]
2566
        mov     [esp+32], eax
2567
        ret
5984 serge 2568
.set_mouse_acceleration:
2434 Serge 2569
        mov     [mouse_speed_factor], dx
2570
        ret
5984 serge 2571
.get_mouse_delay:
2572
        xor     eax, eax
2573
        mov     al, [mouse_delay]
2434 Serge 2574
        mov     [esp+32], eax
2575
        ret
5984 serge 2576
.set_mouse_delay:
2577
        mov     [mouse_delay], dl
2578
@@:
2434 Serge 2579
        ret
5984 serge 2580
.set_pointer_position:
5565 serge 2581
        cmp     dx, word[_display.height]
5984 serge 2582
        jae     @b
2434 Serge 2583
        rol     edx, 16
5565 serge 2584
        cmp     dx, word[_display.width]
5984 serge 2585
        jae     @b
2434 Serge 2586
        mov     [MOUSE_X], edx
5201 serge 2587
        mov     [mouse_active], 1
5984 serge 2588
        jmp     wakeup_osloop
2589
.set_mouse_button:
2590
        mov     [BTN_DOWN], edx
2434 Serge 2591
        mov     [mouse_active], 1
5984 serge 2592
        jmp     wakeup_osloop
2593
.get_doubleclick_delay:
2594
        xor     eax, eax
2595
        mov     al, [mouse_doubleclick_delay]
2596
        mov     [esp+32], eax
2434 Serge 2597
        ret
5984 serge 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
2268 Serge 2611
;------------------------------------------------------------------------------
75 diamond 2612
sysfn_getfreemem:
2434 Serge 2613
        mov     eax, [pg_data.pages_free]
2614
        shl     eax, 2
2615
        mov     [esp+32], eax
2616
        ret
2987 Serge 2617
;------------------------------------------------------------------------------
75 diamond 2618
sysfn_getallmem:
2434 Serge 2619
        mov     eax, [MEM_AMOUNT]
2620
        shr     eax, 10
2621
        mov     [esp+32], eax
2622
        ret
2987 Serge 2623
;------------------------------------------------------------------------------
608 alver 2624
sysfn_pid_to_slot:
2434 Serge 2625
        mov     eax, ecx
2626
        call    pid_to_slot
2627
        mov     [esp+32], eax
2628
        ret
2987 Serge 2629
;------------------------------------------------------------------------------
608 alver 2630
sysfn_min_rest_window:
2434 Serge 2631
        pushad
2632
        mov     eax, edx ; ebx - operating
2633
        shr     ecx, 1
2634
        jnc     @f
2635
        call    pid_to_slot
608 alver 2636
@@:
2434 Serge 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
608 alver 2644
 ; .minimize:
2434 Serge 2645
        call    minimize_window
2646
        jmp     .exit
608 alver 2647
.restore:
2434 Serge 2648
        call    restore_minimized_window
608 alver 2649
.exit:
2434 Serge 2650
        popad
2651
        xor     eax, eax
2652
        mov     [esp+32], eax
2653
        ret
608 alver 2654
.error:
2434 Serge 2655
        popad
2656
        xor     eax, eax
2657
        dec     eax
2658
        mov     [esp+32], eax
2659
        ret
2987 Serge 2660
;------------------------------------------------------------------------------
2661
sysfn_min_windows:
2662
        call    minimize_all_window
2663
        mov     [esp+32], eax
2664
        call    change_task
2665
        ret
2666
;------------------------------------------------------------------------------
2667
sysfn_set_screen_sizes:
2668
        cmp     [SCR_MODE], word 0x13
2669
        jbe     .exit
608 alver 2670
 
2987 Serge 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
5565 serge 2683
        mov     ecx, [_display.lfb_pitch]
2987 Serge 2684
        mov     [_display.width], eax
5201 serge 2685
        dec     eax
2987 Serge 2686
        mov     [_display.height], edx
5201 serge 2687
        dec     edx
2987 Serge 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
;------------------------------------------------------------------------------
41 mikedld 2698
uglobal
2699
screen_workarea RECT
2987 Serge 2700
display_width_standard dd 0
2701
display_height_standard dd 0
2702
do_not_touch_winmap db 0
1 ha 2703
window_minimize db 0
1055 Galkov 2704
sound_flag      db 0
2987 Serge 2705
 
41 mikedld 2706
endg
1 ha 2707
 
2130 serge 2708
UID_NONE=0
2709
UID_MENUETOS=1   ;official
2710
UID_KOLIBRI=2    ;russian
2711
 
41 mikedld 2712
iglobal
2713
version_inf:
3908 Serge 2714
        db 0,7,7,0  ; version 0.7.7.0
2715
        db 0
3500 Serge 2716
.rev    dd __REV__
41 mikedld 2717
version_end:
2718
endg
2987 Serge 2719
;------------------------------------------------------------------------------
2720
align 4
1 ha 2721
sys_cachetodiskette:
1055 Galkov 2722
        cmp     ebx, 1
4287 Serge 2723
        jb      .no_floppy_save
1055 Galkov 2724
        cmp     ebx, 2
4287 Serge 2725
        ja      .no_floppy_save
1055 Galkov 2726
        call    save_image
4287 Serge 2727
        mov     [esp + 32], eax
2728
        ret
2729
.no_floppy_save:
1055 Galkov 2730
        mov     [esp + 32], dword 1
2731
        ret
2987 Serge 2732
;------------------------------------------------------------------------------
1 ha 2733
uglobal
2734
;  bgrchanged  dd  0x0
1071 diamond 2735
align 4
2736
bgrlockpid dd 0
546 diamond 2737
bgrlock db 0
1 ha 2738
endg
2987 Serge 2739
;------------------------------------------------------------------------------
2740
align 4
1 ha 2741
sys_background:
2434 Serge 2742
        cmp     ebx, 1                     ; BACKGROUND SIZE
2743
        jnz     nosb1
2744
        test    ecx, ecx
2745
        jz      sbgrr
2987 Serge 2746
 
2434 Serge 2747
        test    edx, edx
2748
        jz      sbgrr
2987 Serge 2749
;--------------------------------------
2750
align 4
546 diamond 2751
@@:
1071 diamond 2752
;;Maxis use atomic bts for mutexes  4.4.2009
2753
        bts     dword [bgrlock], 0
2754
        jnc     @f
1055 Galkov 2755
        call    change_task
2756
        jmp     @b
2987 Serge 2757
;--------------------------------------
2758
align 4
546 diamond 2759
@@:
2434 Serge 2760
        mov     [BgrDataWidth], ecx
2761
        mov     [BgrDataHeight], edx
1 ha 2762
;    mov   [bgrchanged],1
469 serge 2763
 
2434 Serge 2764
        pushad
469 serge 2765
; return memory for old background
1107 diamond 2766
        mov     eax, [img_background]
2767
        cmp     eax, static_background_data
2768
        jz      @f
2769
        stdcall kernel_free, eax
2987 Serge 2770
;--------------------------------------
2771
align 4
1107 diamond 2772
@@:
469 serge 2773
; calculate RAW size
2434 Serge 2774
        xor     eax, eax
2775
        inc     eax
2776
        cmp     [BgrDataWidth], eax
2777
        jae     @f
2778
        mov     [BgrDataWidth], eax
2987 Serge 2779
;--------------------------------------
2780
align 4
469 serge 2781
@@:
2434 Serge 2782
        cmp     [BgrDataHeight], eax
2783
        jae     @f
2784
        mov     [BgrDataHeight], eax
2987 Serge 2785
;--------------------------------------
2786
align 4
469 serge 2787
@@:
2434 Serge 2788
        mov     eax, [BgrDataWidth]
2789
        imul    eax, [BgrDataHeight]
2790
        lea     eax, [eax*3]
2465 Serge 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
2434 Serge 2797
        mov     [mem_BACKGROUND], eax
469 serge 2798
; get memory for new background
2434 Serge 2799
        stdcall kernel_alloc, eax
2800
        test    eax, eax
2801
        jz      .memfailed
2802
        mov     [img_background], eax
2803
        jmp     .exit
2987 Serge 2804
;--------------------------------------
2805
align 4
1107 diamond 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
2987 Serge 2814
;--------------------------------------
2815
align 4
1107 diamond 2816
.exit:
2434 Serge 2817
        popad
1055 Galkov 2818
        mov     [bgrlock], 0
2987 Serge 2819
;--------------------------------------
2820
align 4
2821
sbgrr:
2434 Serge 2822
        ret
2987 Serge 2823
;------------------------------------------------------------------------------
2824
align 4
875 serge 2825
nosb1:
2434 Serge 2826
        cmp     ebx, 2                     ; SET PIXEL
2827
        jnz     nosb2
875 serge 2828
 
2434 Serge 2829
        mov     eax, [img_background]
2830
        test    ecx, ecx
2831
        jz      @f
2832
        cmp     eax, static_background_data
2833
        jz      .ret
2987 Serge 2834
;--------------------------------------
2835
align 4
1107 diamond 2836
@@:
2434 Serge 2837
        mov     ebx, [mem_BACKGROUND]
2838
        add     ebx, 4095
2839
        and     ebx, -4096
2840
        sub     ebx, 4
2841
        cmp     ecx, ebx
2842
        ja      .ret
875 serge 2843
 
2434 Serge 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
2987 Serge 2849
;--------------------------------------
2850
align 4
1107 diamond 2851
.ret:
2434 Serge 2852
        ret
2987 Serge 2853
;------------------------------------------------------------------------------
2854
align 4
875 serge 2855
nosb2:
2434 Serge 2856
        cmp     ebx, 3                     ; DRAW BACKGROUND
2857
        jnz     nosb3
2987 Serge 2858
;--------------------------------------
2859
align 4
1 ha 2860
draw_background_temp:
2434 Serge 2861
        mov     [background_defined], 1
2862
        call    force_redraw_background
2987 Serge 2863
;--------------------------------------
2864
align 4
2865
nosb31:
2434 Serge 2866
        ret
2987 Serge 2867
;------------------------------------------------------------------------------
2868
align 4
2869
nosb3:
2434 Serge 2870
        cmp     ebx, 4                     ; TILED / STRETCHED
2871
        jnz     nosb4
2872
        cmp     ecx, [BgrDrawMode]
2873
        je      nosb41
2874
        mov     [BgrDrawMode], ecx
2987 Serge 2875
;--------------------------------------
2876
align 4
2877
nosb41:
2434 Serge 2878
        ret
2987 Serge 2879
;------------------------------------------------------------------------------
2880
align 4
2881
nosb4:
2434 Serge 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
2987 Serge 2890
;--------------------------------------
2891
align 4
2892
@@:
1 ha 2893
  ; bughere
2434 Serge 2894
        mov     eax, ecx
2895
        mov     ebx, edx
2896
        add     ebx, [img_background];IMG_BACKGROUND
2897
        mov     ecx, esi
2898
        call    memmove
2987 Serge 2899
;--------------------------------------
2900
align 4
2901
.fin:
2434 Serge 2902
        ret
2987 Serge 2903
;------------------------------------------------------------------------------
2904
align 4
2905
nosb5:
1055 Galkov 2906
        cmp     ebx, 6
2907
        jnz     nosb6
2987 Serge 2908
;--------------------------------------
2909
align 4
1071 diamond 2910
;;Maxis use atomic bts for mutex 4.4.2009
546 diamond 2911
@@:
1073 heavyiron 2912
        bts     dword [bgrlock], 0
1071 diamond 2913
        jnc     @f
1055 Galkov 2914
        call    change_task
2915
        jmp     @b
2987 Serge 2916
;--------------------------------------
2917
align 4
546 diamond 2918
@@:
1055 Galkov 2919
        mov     eax, [CURRENT_TASK]
2920
        mov     [bgrlockpid], eax
1107 diamond 2921
        cmp     [img_background], static_background_data
2922
        jz      .nomem
1055 Galkov 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
2987 Serge 2935
;--------------------------------------
2936
align 4
546 diamond 2937
.z:
1055 Galkov 2938
        mov     eax, [page_tabs+ebx*4]
2939
        test    al, 1
2940
        jz      @f
2941
        call    free_page
2987 Serge 2942
;--------------------------------------
2943
align 4
546 diamond 2944
@@:
1055 Galkov 2945
        mov     eax, [page_tabs+esi*4]
5565 serge 2946
        or      al, PG_UWR
1055 Galkov 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
2987 Serge 2955
;--------------------------------------
2956
align 4
546 diamond 2957
.nomem:
1055 Galkov 2958
        and     [bgrlockpid], 0
2959
        mov     [bgrlock], 0
2987 Serge 2960
;------------------------------------------------------------------------------
2961
align 4
546 diamond 2962
nosb6:
1055 Galkov 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
1312 diamond 2979
        dec     ecx
2987 Serge 2980
;--------------------------------------
2981
align 4
546 diamond 2982
@@:
1055 Galkov 2983
        and     dword [page_tabs+eax*4], 0
2984
        mov     edx, eax
2985
        shl     edx, 12
2434 Serge 2986
        push    eax
1055 Galkov 2987
        invlpg  [edx]
2434 Serge 2988
        pop     eax
1055 Galkov 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
2987 Serge 2998
;--------------------------------------
2999
align 4
546 diamond 3000
.err:
1055 Galkov 3001
        and     dword [esp+32], 0
3002
        ret
2987 Serge 3003
;------------------------------------------------------------------------------
3004
align 4
3005
nosb7:
3006
        cmp     ebx, 8
3007
        jnz     nosb8
546 diamond 3008
 
3555 Serge 3009
        mov     ecx, [current_slot]
3010
        xor     eax, eax
3011
        xchg    eax, [ecx+APPDATA.draw_bgr_x]
2987 Serge 3012
        mov     [esp + 32], eax ; eax = [left]*65536 + [right]
3555 Serge 3013
        xor     eax, eax
3014
        xchg    eax, [ecx+APPDATA.draw_bgr_y]
2987 Serge 3015
        mov     [esp + 20], eax ; ebx = [top]*65536 + [bottom]
2434 Serge 3016
        ret
2987 Serge 3017
;------------------------------------------------------------------------------
3018
align 4
3019
nosb8:
3020
        cmp     ebx, 9
3021
        jnz     nosb9
3022
; ecx = [left]*65536 + [right]
3023
; edx = [top]*65536 + [bottom]
5565 serge 3024
        mov     eax, [_display.width]
3025
        mov     ebx, [_display.height]
3026
        dec     eax
3027
        dec     ebx
2987 Serge 3028
; check [right]
3029
        cmp     cx, ax
5201 serge 3030
        ja      .exit
2987 Serge 3031
; check [left]
3032
        ror     ecx, 16
3033
        cmp     cx, ax
5201 serge 3034
        ja      .exit
2987 Serge 3035
; check [bottom]
3036
        cmp     dx, bx
5201 serge 3037
        ja      .exit
2987 Serge 3038
; check [top]
3039
        ror     edx, 16
3040
        cmp     dx, bx
5201 serge 3041
        ja      .exit
1 ha 3042
 
2987 Serge 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]
3555 Serge 3058
        call    wakeup_osloop
2987 Serge 3059
;--------------------------------------
3060
align 4
3061
.exit:
3062
        ret
3063
;------------------------------------------------------------------------------
3064
align 4
3065
nosb9:
3066
        ret
3067
;------------------------------------------------------------------------------
3068
align 4
3069
uglobal
3070
  BG_Rect_X_left_right  dd   0x0
3071
  BG_Rect_Y_top_bottom  dd   0x0
3072
endg
3073
;------------------------------------------------------------------------------
3074
align 4
709 diamond 3075
force_redraw_background:
2434 Serge 3076
        and     [draw_data+32 + RECT.left], 0
3077
        and     [draw_data+32 + RECT.top], 0
3078
        push    eax ebx
5565 serge 3079
        mov     eax, [_display.width]
3080
        mov     ebx, [_display.height]
3081
        dec     eax
3082
        dec     ebx
2434 Serge 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]
3555 Serge 3087
        call    wakeup_osloop
2434 Serge 3088
        ret
2987 Serge 3089
;------------------------------------------------------------------------------
1 ha 3090
align 4
3091
sys_getbackground:
1304 Lrz 3092
;    cmp   eax,1                                  ; SIZE
2434 Serge 3093
        dec     ebx
3094
        jnz     nogb1
3095
        mov     eax, [BgrDataWidth]
3096
        shl     eax, 16
3555 Serge 3097
        mov     ax, word [BgrDataHeight]
2434 Serge 3098
        mov     [esp+32], eax
3099
        ret
2987 Serge 3100
;------------------------------------------------------------------------------
3101
align 4
875 serge 3102
nogb1:
1304 Lrz 3103
;    cmp   eax,2                                  ; PIXEL
2434 Serge 3104
        dec     ebx
3105
        jnz     nogb2
875 serge 3106
 
1107 diamond 3107
        mov     eax, [img_background]
1304 Lrz 3108
        test    ecx, ecx
1107 diamond 3109
        jz      @f
3110
        cmp     eax, static_background_data
3111
        jz      .ret
2987 Serge 3112
;--------------------------------------
3113
align 4
1107 diamond 3114
@@:
2434 Serge 3115
        mov     ebx, [mem_BACKGROUND]
3116
        add     ebx, 4095
3117
        and     ebx, -4096
3118
        sub     ebx, 4
3119
        cmp     ecx, ebx
3120
        ja      .ret
875 serge 3121
 
2434 Serge 3122
        mov     eax, [ecx+eax]
469 serge 3123
 
2434 Serge 3124
        and     eax, 0xFFFFFF
3125
        mov     [esp+32], eax
2987 Serge 3126
;--------------------------------------
3127
align 4
1107 diamond 3128
.ret:
2434 Serge 3129
        ret
2987 Serge 3130
;------------------------------------------------------------------------------
3131
align 4
3132
nogb2:
1 ha 3133
 
1304 Lrz 3134
;    cmp   eax,4                                  ; TILED / STRETCHED
2434 Serge 3135
        dec     ebx
3136
        dec     ebx
3137
        jnz     nogb4
3138
        mov     eax, [BgrDrawMode]
2987 Serge 3139
;--------------------------------------
3140
align 4
3141
nogb4:
2434 Serge 3142
        mov     [esp+32], eax
3143
        ret
2987 Serge 3144
;------------------------------------------------------------------------------
1 ha 3145
align 4
3146
sys_getkey:
2434 Serge 3147
        mov     [esp + 32], dword 1
1055 Galkov 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
5201 serge 3156
        movzx   ax, byte [KEY_BUFF + 120 + 2]
1055 Galkov 3157
        shl     eax, 8
5201 serge 3158
        mov     al, byte [KEY_BUFF]
3159
        shl     eax, 8
1055 Galkov 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
5201 serge 3168
        add     eax, 120 + 2
3169
        add     ebx, 120 + 2
3170
        call    memmove
1055 Galkov 3171
        pop     eax
2987 Serge 3172
;--------------------------------------
3173
align 4
92 diamond 3174
.ret_eax:
1055 Galkov 3175
        mov     [esp + 32], eax
3176
        ret
2987 Serge 3177
;--------------------------------------
3178
align 4
671 Ghost 3179
.finish:
92 diamond 3180
; test hotkeys buffer
1055 Galkov 3181
        mov     ecx, hotkey_buffer
2987 Serge 3182
;--------------------------------------
3183
align 4
92 diamond 3184
@@:
1055 Galkov 3185
        cmp     [ecx], ebx
3186
        jz      .found
3187
        add     ecx, 8
3188
        cmp     ecx, hotkey_buffer + 120 * 8
3189
        jb      @b
3190
        ret
2987 Serge 3191
;--------------------------------------
3192
align 4
92 diamond 3193
.found:
1055 Galkov 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
2987 Serge 3201
;------------------------------------------------------------------------------
1 ha 3202
align 4
3203
sys_getbutton:
1055 Galkov 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]
1391 mikedld 3214
        and     al, 0xFE                                    ; delete left button bit
1055 Galkov 3215
        mov     [BTN_COUNT], byte 0
3216
        mov     [esp + 32], eax
2987 Serge 3217
;--------------------------------------
3218
align 4
671 Ghost 3219
.exit:
1055 Galkov 3220
        ret
2987 Serge 3221
;------------------------------------------------------------------------------
1 ha 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
 
2434 Serge 3236
        cmp     ecx, -1 ; who am I ?
3237
        jne     .no_who_am_i
3238
        mov     ecx, [CURRENT_TASK]
684 diamond 3239
  .no_who_am_i:
1055 Galkov 3240
        cmp     ecx, max_processes
3241
        ja      .nofillbuf
1 ha 3242
 
684 diamond 3243
; +4: word: position of the window of thread in the window stack
1055 Galkov 3244
        mov     ax, [WIN_STACK + ecx * 2]
3245
        mov     [ebx+4], ax
684 diamond 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)
1055 Galkov 3248
        mov     ax, [WIN_POS + ecx * 2]
3249
        mov     [ebx+6], ax
1 ha 3250
 
1055 Galkov 3251
        shl     ecx, 5
1 ha 3252
 
684 diamond 3253
; +0: dword: memory usage
1055 Galkov 3254
        mov     eax, [ecx+CURRENT_TASK+TASKDATA.cpu_usage]
3255
        mov     [ebx], eax
684 diamond 3256
; +10: 11 bytes: name of the process
1055 Galkov 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
1 ha 3263
 
684 diamond 3264
; +22: address of the process in memory
3265
; +26: size of used memory - 1
1055 Galkov 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
5201 serge 3272
        mov     edx, [SLOT_BASE+ecx*8+APPDATA.process]
3273
        mov     edx, [edx+PROC.mem_used]
1055 Galkov 3274
        mov     eax, std_application_base_address
684 diamond 3275
.os_mem:
1055 Galkov 3276
        stosd
3277
        lea     eax, [edx-1]
3278
        stosd
1 ha 3279
 
684 diamond 3280
; +30: PID/TID
1055 Galkov 3281
        mov     eax, [ecx+CURRENT_TASK+TASKDATA.pid]
3282
        stosd
1 ha 3283
 
3284
    ; window position and size
1055 Galkov 3285
        push    esi
3286
        lea     esi, [ecx + window_data + WDATA.box]
3287
        movsd
3288
        movsd
3289
        movsd
3290
        movsd
1 ha 3291
 
3292
    ; Process state (+50)
1055 Galkov 3293
        mov     eax, dword [ecx+CURRENT_TASK+TASKDATA.state]
3294
        stosd
1 ha 3295
 
138 mikedld 3296
    ; Window client area box
1055 Galkov 3297
        lea     esi, [ecx*8 + SLOT_BASE + APPDATA.wnd_clientbox]
3298
        movsd
3299
        movsd
3300
        movsd
3301
        movsd
1 ha 3302
 
164 serge 3303
    ; Window state
1055 Galkov 3304
        mov     al, [ecx+window_data+WDATA.fl_wstate]
3305
        stosb
164 serge 3306
 
2010 serge 3307
    ; Event mask (+71)
3308
        mov     EAX, dword [ECX+CURRENT_TASK+TASKDATA.event_mask]
3309
        stosd
3310
 
4265 Serge 3311
    ; Keyboard mode (+75)
3312
        mov     al, byte [ecx*8 + SLOT_BASE + APPDATA.keyboard_mode]
4287 Serge 3313
        stosb
4265 Serge 3314
 
1055 Galkov 3315
        pop     esi
3316
        pop     edi
138 mikedld 3317
 
684 diamond 3318
.nofillbuf:
1 ha 3319
    ; return number of processes
3320
 
2434 Serge 3321
        mov     eax, [TASK_COUNT]
3322
        mov     [esp+32], eax
3323
        ret
1 ha 3324
 
3325
align 4
3326
sys_clock:
1055 Galkov 3327
        cli
1 ha 3328
  ; Mikhail Lisovin  xx Jan 2005
3329
  @@:
2434 Serge 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
  @@:
1 ha 3339
  ; end Lisovin's fix
3340
 
2434 Serge 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
1055 Galkov 3357
        sti
3358
        mov     [esp + 32], ecx
3359
        ret
1 ha 3360
 
3361
 
3362
align 4
3363
 
3364
sys_date:
3365
 
1055 Galkov 3366
        cli
75 diamond 3367
  @@:
2434 Serge 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
  @@:
75 diamond 3377
 
2434 Serge 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
1055 Galkov 3392
        sti
3393
        mov     [esp+32], ecx
3394
        ret
1 ha 3395
 
3396
 
3397
; redraw status
3398
 
3399
sys_redrawstat:
1055 Galkov 3400
        cmp     ebx, 1
3401
        jne     no_widgets_away
3402
        ; buttons away
2434 Serge 3403
        mov     ecx, [CURRENT_TASK]
1 ha 3404
  sys_newba2:
2434 Serge 3405
        mov     edi, [BTN_ADDR]
1055 Galkov 3406
        cmp     [edi], dword 0  ; empty button list ?
3407
        je      end_of_buttons_away
3408
        movzx   ebx, word [edi]
3409
        inc     ebx
2434 Serge 3410
        mov     eax, edi
1 ha 3411
  sys_newba:
1055 Galkov 3412
        dec     ebx
3413
        jz      end_of_buttons_away
1 ha 3414
 
1055 Galkov 3415
        add     eax, 0x10
3416
        cmp     cx, [eax]
3417
        jnz     sys_newba
1 ha 3418
 
1055 Galkov 3419
        push    eax ebx ecx
2434 Serge 3420
        mov     ecx, ebx
1055 Galkov 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
1 ha 3428
 
1055 Galkov 3429
        jmp     sys_newba2
1 ha 3430
 
3431
  end_of_buttons_away:
3432
 
1055 Galkov 3433
        ret
1 ha 3434
 
3435
  no_widgets_away:
3436
 
1055 Galkov 3437
        cmp     ebx, 2
3438
        jnz     srl1
1 ha 3439
 
1055 Galkov 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
5565 serge 3444
        mov     eax, [_display.width]
3445
        dec     eax
1055 Galkov 3446
        mov     [edx + RECT.right], eax
5565 serge 3447
        mov     eax, [_display.height]
3448
        dec     eax
1055 Galkov 3449
        mov     [edx + RECT.bottom], eax
1 ha 3450
 
3451
  srl1:
1055 Galkov 3452
        ret
1 ha 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
;---------------------------------------------------------------------------------------------
1344 Lrz 3471
iglobal
3472
align 4
3473
sheduler:
2434 Serge 3474
        dd      sys_sheduler.00
3475
        dd      change_task
3476
        dd      sys_sheduler.02
3477
        dd      sys_sheduler.03
3478
        dd      sys_sheduler.04
1344 Lrz 3479
endg
1638 serge 3480
sys_sheduler:
1344 Lrz 3481
;rewritten by   29.12.2009
2434 Serge 3482
        jmp     dword [sheduler+ebx*4]
1344 Lrz 3483
;.shed_counter:
3484
.00:
2434 Serge 3485
        mov     eax, [context_counter]
3486
        mov     [esp+32], eax
3487
        ret
1273 Lrz 3488
 
1344 Lrz 3489
.02:
3490
;.perf_control:
2434 Serge 3491
        inc     ebx                     ;before ebx=2, ebx=3
3492
        cmp     ebx, ecx                ;if ecx=3, ebx=3
3493
        jz      cache_disable
1365 Lrz 3494
 
2434 Serge 3495
        dec     ebx                     ;ebx=2
3496
        cmp     ebx, ecx                ;
3497
        jz      cache_enable            ;if ecx=2 and ebx=2
1365 Lrz 3498
 
2434 Serge 3499
        dec     ebx                     ;ebx=1
3500
        cmp     ebx, ecx
3501
        jz      is_cache_enabled        ;if ecx=1 and ebx=1
1365 Lrz 3502
 
2434 Serge 3503
        dec     ebx
3504
        test    ebx, ecx                ;ebx=0 and ecx=0
3505
        jz      modify_pce              ;if ecx=0
1365 Lrz 3506
 
2434 Serge 3507
        ret
1345 Lrz 3508
 
1638 serge 3509
.03:
1344 Lrz 3510
;.rdmsr_instr:
3511
;now counter in ecx
3512
;(edx:eax) esi:edi => edx:esi
2434 Serge 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
1344 Lrz 3519
 
3520
.04:
1273 Lrz 3521
;.wrmsr_instr:
3522
;now counter in ecx
3523
;(edx:eax) esi:edi => edx:esi
3524
        ; Fast Call MSR can't be destroy
3555 Serge 3525
        ; Но MSR_AMD_EFER можно изменять, т.к. в этом регистре лиш
3526
        ; включаются/выключаются расширенные возможности
2434 Serge 3527
        cmp     edx, MSR_SYSENTER_CS
1273 Lrz 3528
        je      @f
2434 Serge 3529
        cmp     edx, MSR_SYSENTER_ESP
1273 Lrz 3530
        je      @f
2434 Serge 3531
        cmp     edx, MSR_SYSENTER_EIP
1273 Lrz 3532
        je      @f
2434 Serge 3533
        cmp     edx, MSR_AMD_STAR
1273 Lrz 3534
        je      @f
3535
 
2434 Serge 3536
        mov     eax, esi
3537
        mov     ecx, edx
1273 Lrz 3538
        wrmsr
1344 Lrz 3539
        ; mov   [esp + 32], eax
3540
        ; mov   [esp + 20], edx ;ret in ebx?
1273 Lrz 3541
@@:
2434 Serge 3542
        ret
1273 Lrz 3543
 
1 ha 3544
cache_disable:
2434 Serge 3545
        mov     eax, cr0
3546
        or      eax, 01100000000000000000000000000000b
3547
        mov     cr0, eax
3548
        wbinvd  ;set MESI
3549
        ret
1 ha 3550
 
3551
cache_enable:
2434 Serge 3552
        mov     eax, cr0
3553
        and     eax, 10011111111111111111111111111111b
3554
        mov     cr0, eax
3555
        ret
1 ha 3556
 
3557
is_cache_enabled:
2434 Serge 3558
        mov     eax, cr0
3559
        mov     ebx, eax
3560
        and     eax, 01100000000000000000000000000000b
3561
        jz      cache_disabled
3562
        mov     [esp+32], ebx
1 ha 3563
cache_disabled:
2434 Serge 3564
        mov     dword [esp+32], eax;0
3565
        ret
1 ha 3566
 
3567
modify_pce:
2434 Serge 3568
        mov     eax, cr4
1 ha 3569
;       mov ebx,0
3570
;       or  bx,100000000b ;pce
3571
;       xor eax,ebx ;invert pce
2434 Serge 3572
        bts     eax, 8;pce=cr4[8]
3573
        mov     cr4, eax
3574
        mov     [esp+32], eax
3575
        ret
1 ha 3576
;---------------------------------------------------------------------------------------------
3577
 
3578
 
3579
iglobal
521 diamond 3580
  cpustring db 'CPU',0
1 ha 3581
endg
3582
 
67 diamond 3583
uglobal
1055 Galkov 3584
background_defined    db    0    ; diamond, 11.04.2006
67 diamond 3585
endg
2987 Serge 3586
;-----------------------------------------------------------------------------
1 ha 3587
align 4
3588
checkmisc:
2434 Serge 3589
        cmp     [ctrl_alt_del], 1
3590
        jne     nocpustart
501 serge 3591
 
1055 Galkov 3592
        mov     ebp, cpustring
3593
        call    fs_execute_from_sysdir
501 serge 3594
 
2434 Serge 3595
        mov     [ctrl_alt_del], 0
2987 Serge 3596
;--------------------------------------
3597
align 4
465 serge 3598
nocpustart:
2434 Serge 3599
        cmp     [mouse_active], 1
3600
        jne     mouse_not_active
3601
        mov     [mouse_active], 0
1 ha 3602
 
2434 Serge 3603
        xor     edi, edi
3604
        mov     ebx, CURRENT_TASK
3605
 
3606
        mov     ecx, [TASK_COUNT]
3607
        movzx   eax, word [WIN_POS + ecx*2]     ; active window
3608
        shl     eax, 8
3609
        push    eax
3610
 
3611
        movzx   eax, word [MOUSE_X]
3612
        movzx   edx, word [MOUSE_Y]
2987 Serge 3613
;--------------------------------------
2434 Serge 3614
align 4
3615
.set_mouse_event:
3616
        add     edi, 256
3617
        add     ebx, 32
3618
        test    [ebx+TASKDATA.event_mask], 0x80000000
3619
        jz      .pos_filter
3620
 
3621
        cmp     edi, [esp]                      ; skip if filtration active
3622
        jne     .skip
2987 Serge 3623
;--------------------------------------
3624
align 4
2434 Serge 3625
.pos_filter:
3626
        test    [ebx+TASKDATA.event_mask], 0x40000000
3627
        jz      .set
3628
 
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
2987 Serge 3642
;--------------------------------------
3643
align 4
2434 Serge 3644
.set:
2987 Serge 3645
        or      [edi+SLOT_BASE+APPDATA.event_mask], 100000b  ; set event 6
3646
;--------------------------------------
3647
align 4
2434 Serge 3648
.skip:
3649
        loop    .set_mouse_event
3650
 
3651
        pop     eax
2987 Serge 3652
;--------------------------------------
3653
align 4
465 serge 3654
mouse_not_active:
2434 Serge 3655
        cmp     byte[REDRAW_BACKGROUND], 0         ; background update ?
3656
        jz      nobackgr
2987 Serge 3657
 
2434 Serge 3658
        cmp     [background_defined], 0
3659
        jz      nobackgr
2987 Serge 3660
;--------------------------------------
3661
align 4
3555 Serge 3662
backgr:
2987 Serge 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
 
2434 Serge 3673
        call    drawbackground
2987 Serge 3674
;        DEBUGF  1, "K : drawbackground\n"
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]
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
3555 Serge 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:
3626 Serge 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
3555 Serge 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
@@:
3626 Serge 3699
        cmp     word [edi+SLOT_BASE+APPDATA.draw_bgr_y], dx
3555 Serge 3700
        jae     @f
3626 Serge 3701
        mov     word [edi+SLOT_BASE+APPDATA.draw_bgr_y], dx
3555 Serge 3702
@@:
3626 Serge 3703
        shr     edx, 16
3555 Serge 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:
2987 Serge 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 -----------
3717
        dec     byte[REDRAW_BACKGROUND]    ; got new update request?
3555 Serge 3718
        jnz     backgr
2987 Serge 3719
 
3555 Serge 3720
        xor     eax, eax
2434 Serge 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
2987 Serge 3725
;--------------------------------------
3726
align 4
465 serge 3727
nobackgr:
2987 Serge 3728
; system shutdown request
2434 Serge 3729
        cmp     [SYS_SHUTDOWN], byte 0
3730
        je      noshutdown
1 ha 3731
 
2434 Serge 3732
        mov     edx, [shutdown_processes]
1 ha 3733
 
2434 Serge 3734
        cmp     [SYS_SHUTDOWN], dl
3500 Serge 3735
        jne     noshutdown
1 ha 3736
 
2434 Serge 3737
        lea     ecx, [edx-1]
3738
        mov     edx, OS_BASE+0x3040
3500 Serge 3739
        jecxz   no_mark_system_shutdown
2987 Serge 3740
;--------------------------------------
3741
align 4
465 serge 3742
markz:
3500 Serge 3743
        push    ecx edx
6240 serge 3744
        cmp     [edx+TASKDATA.state], TSTATE_FREE
3500 Serge 3745
        jz      .nokill
3746
        lea     edx, [(edx-(CURRENT_TASK and 1FFFFFFFh))*8+SLOT_BASE]
5201 serge 3747
        cmp     [edx+APPDATA.process], sys_proc
3500 Serge 3748
        jz      .nokill
3749
        call    request_terminate
3750
        jmp     .common
3751
.nokill:
3752
        dec     byte [SYS_SHUTDOWN]
3753
        xor     eax, eax
3754
.common:
3755
        pop     edx ecx
3756
        test    eax, eax
3757
        jz      @f
6240 serge 3758
        mov     [edx+TASKDATA.state], TSTATE_ZOMBIE
3500 Serge 3759
@@:
2434 Serge 3760
        add     edx, 0x20
3761
        loop    markz
3555 Serge 3762
        call    wakeup_osloop
2987 Serge 3763
;--------------------------------------
3764
align 4
709 diamond 3765
@@:
2987 Serge 3766
no_mark_system_shutdown:
2434 Serge 3767
        dec     byte [SYS_SHUTDOWN]
3768
        je      system_shutdown
2987 Serge 3769
;--------------------------------------
3770
align 4
465 serge 3771
noshutdown:
2434 Serge 3772
        mov     eax, [TASK_COUNT]           ; termination
3773
        mov     ebx, TASK_DATA+TASKDATA.state
3774
        mov     esi, 1
2987 Serge 3775
;--------------------------------------
3776
align 4
465 serge 3777
newct:
2434 Serge 3778
        mov     cl, [ebx]
3779
        cmp     cl, byte 3
3500 Serge 3780
        jz      .terminate
2987 Serge 3781
 
2434 Serge 3782
        cmp     cl, byte 4
3500 Serge 3783
        jnz     .noterminate
3784
.terminate:
3785
        pushad
3786
        mov     ecx, eax
3787
        shl     ecx, 8
3788
        add     ecx, SLOT_BASE
3789
        call    restore_default_cursor_before_killing
3790
        popad
1 ha 3791
 
3500 Serge 3792
        pushad
3793
        call    terminate
3794
        popad
3795
        cmp     byte [SYS_SHUTDOWN], 0
3796
        jz      .noterminate
3797
        dec     byte [SYS_SHUTDOWN]
3798
        je      system_shutdown
3799
 
3800
.noterminate:
2434 Serge 3801
        add     ebx, 0x20
3802
        inc     esi
3803
        dec     eax
3804
        jnz     newct
3805
        ret
2987 Serge 3806
;-----------------------------------------------------------------------------
3807
align 4
1 ha 3808
redrawscreen:
3809
; eax , if process window_data base is eax, do not set flag/limits
3810
 
2434 Serge 3811
        pushad
3812
        push    eax
1 ha 3813
 
684 diamond 3814
;;;         mov   ebx,2
1 ha 3815
;;;         call  delay_hs
3816
 
1055 Galkov 3817
         ;mov   ecx,0               ; redraw flags for apps
2434 Serge 3818
        xor     ecx, ecx
2987 Serge 3819
;--------------------------------------
3820
align 4
3821
newdw2:
2434 Serge 3822
        inc     ecx
3823
        push    ecx
1 ha 3824
 
2434 Serge 3825
        mov     eax, ecx
3826
        shl     eax, 5
3827
        add     eax, window_data
1 ha 3828
 
2434 Serge 3829
        cmp     eax, [esp+4]
3830
        je      not_this_task
1055 Galkov 3831
                                   ; check if window in redraw area
2434 Serge 3832
        mov     edi, eax
1 ha 3833
 
2434 Serge 3834
        cmp     ecx, 1             ; limit for background
3835
        jz      bgli
1 ha 3836
 
5984 serge 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
 
2434 Serge 3845
        mov     eax, [edi + WDATA.box.left]
3846
        mov     ebx, [edi + WDATA.box.top]
1 ha 3847
 
2434 Serge 3848
        mov     ecx, [draw_limits.bottom] ; ecx = area y end     ebx = window y start
3849
        cmp     ecx, ebx
3850
        jb      ricino
1 ha 3851
 
2434 Serge 3852
        mov     ecx, [draw_limits.right] ; ecx = area x end     eax = window x start
3853
        cmp     ecx, eax
3854
        jb      ricino
1 ha 3855
 
2434 Serge 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
164 serge 3862
 
2434 Serge 3863
        mov     eax, [draw_limits.top]  ; eax = area y start     edx = window y end
3864
        cmp     edx, eax
3865
        jb      ricino
1 ha 3866
 
2434 Serge 3867
        mov     eax, [draw_limits.left]  ; eax = area x start     ecx = window x end
3868
        cmp     ecx, eax
3869
        jb      ricino
2987 Serge 3870
;--------------------------------------
3871
align 4
3872
bgli:
2434 Serge 3873
        cmp     dword[esp], 1
3874
        jnz     .az
2987 Serge 3875
 
2434 Serge 3876
        cmp     byte[REDRAW_BACKGROUND], 0
3877
        jz      .az
2987 Serge 3878
 
2434 Serge 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
2987 Serge 3884
 
2434 Serge 3885
        mov     [eax+RECT.left], ebx
3886
        mov     dl, 1
2987 Serge 3887
;--------------------------------------
3888
align 4
3889
@@:
2434 Serge 3890
        mov     ebx, [draw_limits.top]
3891
        cmp     ebx, [eax+RECT.top]
3892
        jae     @f
2987 Serge 3893
 
2434 Serge 3894
        mov     [eax+RECT.top], ebx
3895
        mov     dl, 1
2987 Serge 3896
;--------------------------------------
3897
align 4
3898
@@:
2434 Serge 3899
        mov     ebx, [draw_limits.right]
3900
        cmp     ebx, [eax+RECT.right]
3901
        jbe     @f
2987 Serge 3902
 
2434 Serge 3903
        mov     [eax+RECT.right], ebx
3904
        mov     dl, 1
2987 Serge 3905
;--------------------------------------
3906
align 4
3907
@@:
2434 Serge 3908
        mov     ebx, [draw_limits.bottom]
3909
        cmp     ebx, [eax+RECT.bottom]
3910
        jbe     @f
2987 Serge 3911
 
2434 Serge 3912
        mov     [eax+RECT.bottom], ebx
3913
        mov     dl, 1
2987 Serge 3914
;--------------------------------------
3915
align 4
3916
@@:
2434 Serge 3917
        add     byte[REDRAW_BACKGROUND], dl
3555 Serge 3918
        call    wakeup_osloop
2434 Serge 3919
        jmp     newdw8
2987 Serge 3920
;--------------------------------------
3921
align 4
3922
.az:
2434 Serge 3923
        mov     eax, edi
3924
        add     eax, draw_data-window_data
1 ha 3925
 
2434 Serge 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
1 ha 3934
 
2434 Serge 3935
        sub     eax, draw_data-window_data
1 ha 3936
 
2434 Serge 3937
        cmp     dword [esp], 1
3938
        jne     nobgrd
3939
        inc     byte[REDRAW_BACKGROUND]
3555 Serge 3940
        call    wakeup_osloop
2987 Serge 3941
;--------------------------------------
3942
align 4
3943
newdw8:
3944
nobgrd:
4265 Serge 3945
;--------------------------------------
3946
        push    eax  edi ebp
3947
        mov     edi, [esp+12]
3948
        cmp     edi, 1
3949
        je      .found
1 ha 3950
 
4265 Serge 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]
5565 serge 3975
        add     ebp, [_display.win_map]
4265 Serge 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
 
2434 Serge 4004
        mov     [eax + WDATA.fl_redraw], byte 1  ; mark as redraw
2987 Serge 4005
;--------------------------------------
4006
align 4
4007
ricino:
4008
not_this_task:
2434 Serge 4009
        pop     ecx
1 ha 4010
 
2434 Serge 4011
        cmp     ecx, [TASK_COUNT]
4012
        jle     newdw2
1 ha 4013
 
2434 Serge 4014
        pop     eax
4015
        popad
4016
        ret
2987 Serge 4017
;-----------------------------------------------------------------------------
4018
align 4
1 ha 4019
calculatebackground:   ; background
5565 serge 4020
        mov     edi, [_display.win_map]              ; set os to use all pixels
2434 Serge 4021
        mov     eax, 0x01010101
5565 serge 4022
        mov     ecx, [_display.win_map_size]
2434 Serge 4023
        shr     ecx, 2
4024
        rep stosd
1 ha 4025
 
2434 Serge 4026
        mov     byte[REDRAW_BACKGROUND], 0            ; do not draw background!
1055 Galkov 4027
        ret
2987 Serge 4028
;-----------------------------------------------------------------------------
1 ha 4029
uglobal
1055 Galkov 4030
  imax    dd 0x0
1 ha 4031
endg
2987 Serge 4032
;-----------------------------------------------------------------------------
4033
align 4
1 ha 4034
delay_ms:     ; delay in 1/1000 sec
2434 Serge 4035
        push    eax
4036
        push    ecx
1 ha 4037
 
2434 Serge 4038
        mov     ecx, esi
1055 Galkov 4039
        ; 
2434 Serge 4040
        imul    ecx, 33941
4041
        shr     ecx, 9
1055 Galkov 4042
        ; 
1 ha 4043
 
2434 Serge 4044
        in      al, 0x61
4045
        and     al, 0x10
4046
        mov     ah, al
1055 Galkov 4047
        cld
2987 Serge 4048
;--------------------------------------
4049
align 4
4050
cnt1:
2434 Serge 4051
        in      al, 0x61
4052
        and     al, 0x10
4053
        cmp     al, ah
4054
        jz      cnt1
1 ha 4055
 
2434 Serge 4056
        mov     ah, al
4057
        loop    cnt1
1 ha 4058
 
2434 Serge 4059
        pop     ecx
4060
        pop     eax
1055 Galkov 4061
        ret
2987 Serge 4062
;-----------------------------------------------------------------------------
2434 Serge 4063
align 4
1 ha 4064
set_app_param:
1055 Galkov 4065
        mov     edi, [TASK_BASE]
2434 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
1055 Galkov 4072
        ret
2987 Serge 4073
;-----------------------------------------------------------------------------
3500 Serge 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
 
3626 Serge 4083
if 1
2987 Serge 4084
align 4
1 ha 4085
delay_hs:     ; delay in 1/100 secs
684 diamond 4086
; ebx = delay time
3626 Serge 4087
 
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
4095
 
4096
        mov     ebx, edx
4097
        mov     ecx, [esp]
4098
        push    edx
4099
        push    eax
4100
        call    wait_event_timeout
4101
        pop     eax
4102
        pop     ebx
4103
        call    destroy_event
4104
.done:
4105
        add     esp, 4
4106
        popad
4107
        ret
4108
 
4109
else
4110
 
4111
align 4
4112
delay_hs:     ; delay in 1/100 secs
4113
; ebx = delay time
2434 Serge 4114
        push    ecx
4115
        push    edx
1 ha 4116
 
2434 Serge 4117
        mov     edx, [timer_ticks]
2987 Serge 4118
;--------------------------------------
4119
align 4
4120
newtic:
2434 Serge 4121
        mov     ecx, [timer_ticks]
4122
        sub     ecx, edx
4123
        cmp     ecx, ebx
4124
        jae     zerodelay
1 ha 4125
 
2434 Serge 4126
        call    change_task
1 ha 4127
 
2434 Serge 4128
        jmp     newtic
2987 Serge 4129
;--------------------------------------
4130
align 4
4131
zerodelay:
2434 Serge 4132
        pop     edx
4133
        pop     ecx
1055 Galkov 4134
        ret
3626 Serge 4135
end if
4136
 
2987 Serge 4137
;-----------------------------------------------------------------------------
2434 Serge 4138
align 16        ;very often call this subrutine
1 ha 4139
memmove:       ; memory move in bytes
4140
; eax = from
4141
; ebx = to
4142
; ecx = no of bytes
2434 Serge 4143
        test    ecx, ecx
4144
        jle     .ret
1 ha 4145
 
2434 Serge 4146
        push    esi edi ecx
1 ha 4147
 
2434 Serge 4148
        mov     edi, ebx
4149
        mov     esi, eax
1 ha 4150
 
2434 Serge 4151
        test    ecx, not 11b
4152
        jz      @f
1 ha 4153
 
2434 Serge 4154
        push    ecx
4155
        shr     ecx, 2
4156
        rep movsd
4157
        pop     ecx
4158
        and     ecx, 11b
4159
        jz      .finish
2987 Serge 4160
;--------------------------------------
4161
align 4
4162
@@:
2434 Serge 4163
        rep movsb
2987 Serge 4164
;--------------------------------------
4165
align 4
4166
.finish:
2434 Serge 4167
        pop     ecx edi esi
2987 Serge 4168
;--------------------------------------
4169
align 4
4170
.ret:
2434 Serge 4171
        ret
2987 Serge 4172
;-----------------------------------------------------------------------------
75 diamond 4173
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
4174
;align 4
1 ha 4175
;
75 diamond 4176
;read_floppy_file:
1 ha 4177
;
75 diamond 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
1 ha 4196
;
379 serge 4197
;     mov   edi,[TASK_BASE]
75 diamond 4198
;     add   edi,0x10
4199
;     add   esi,[edi]
4200
;     add   eax,[edi]
1 ha 4201
;
75 diamond 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
1 ha 4218
 
4219
 
4220
 
4221
align 4
4222
set_io_access_rights:
2434 Serge 4223
        push    edi eax
4224
        mov     edi, tss._io_map_0
465 serge 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
2434 Serge 4231
        test    ebp, ebp
1232 Lrz 4232
;     cmp   ebp,0                ; enable access - ebp = 0
2434 Serge 4233
        jnz     .siar1
465 serge 4234
;     not   ebx
4235
;     and   [edi],byte bl
2434 Serge 4236
        btr     [edi], eax
4237
        pop     eax edi
4238
        ret
2106 serge 4239
.siar1:
2434 Serge 4240
        bts     [edi], eax
465 serge 4241
  ;  or    [edi],byte bl        ; disable access - ebp = 1
2434 Serge 4242
        pop     eax edi
4243
        ret
1306 Lrz 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:
1638 serge 4250
;  * eax = 0 - succesful
1306 Lrz 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
1 ha 4255
r_f_port_area:
4256
 
2434 Serge 4257
        test    ebx, ebx
4258
        jnz     free_port_area
1 ha 4259
;     je    r_port_area
4260
;     jmp   free_port_area
4261
 
4262
;   r_port_area:
4263
 
1306 Lrz 4264
;     pushad
1 ha 4265
 
2434 Serge 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
465 serge 4275
 rpal3:
2434 Serge 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
1 ha 4283
;     jb    rpal4
4284
;     jmp   rpal1
465 serge 4285
 rpal4:
2434 Serge 4286
        dec     eax
4287
        jnz     rpal3
4288
        jmp     rpal2
1 ha 4289
   rpal1:
1306 Lrz 4290
;     popad
4291
;     mov   eax,1
2434 Serge 4292
        xor     eax, eax
4293
        inc     eax
4294
        ret
1 ha 4295
   rpal2:
1306 Lrz 4296
;     popad
1 ha 4297
     ; enable port access at port IO map
2434 Serge 4298
        cli
4299
        pushad                        ; start enable io map
1 ha 4300
 
2434 Serge 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
1306 Lrz 4306
new_port_access:
4307
;     pushad
2434 Serge 4308
        call    set_io_access_rights
1306 Lrz 4309
;     popad
2434 Serge 4310
        inc     eax
4311
        cmp     eax, edx
4312
        jbe     new_port_access
4313
;       pop     ebp
1306 Lrz 4314
no_unmask_io:
2434 Serge 4315
        popad                         ; end enable io map
4316
        sti
1 ha 4317
 
2434 Serge 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
1 ha 4328
 
2434 Serge 4329
        xor     eax, eax
4330
        ret
1 ha 4331
 
4332
free_port_area:
4333
 
1306 Lrz 4334
;     pushad
2434 Serge 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]
1 ha 4340
   frpal3:
2434 Serge 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
1 ha 4351
   frpal4:
2434 Serge 4352
        dec     eax
4353
        jnz     frpal3
1 ha 4354
   frpal2:
1306 Lrz 4355
;     popad
2434 Serge 4356
        inc     eax
4357
        ret
1 ha 4358
   frpal1:
2434 Serge 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
1 ha 4367
 
2434 Serge 4368
        dec     dword [RESERVED_PORTS]
1306 Lrz 4369
;popad
4370
;disable port access at port IO map
1 ha 4371
 
1306 Lrz 4372
;     pushad                        ; start disable io map
2434 Serge 4373
        pop     eax     ;start port
4374
        cmp     edx, 65536;16384
4375
        jge     no_mask_io
1 ha 4376
 
1306 Lrz 4377
;     mov   eax,ecx
2434 Serge 4378
        xor     ebp, ebp
4379
        inc     ebp
1306 Lrz 4380
new_port_access_disable:
4381
;     pushad
4382
;     mov   ebp,1                  ; disable - eax = port
2434 Serge 4383
        call    set_io_access_rights
1306 Lrz 4384
;     popad
2434 Serge 4385
        inc     eax
4386
        cmp     eax, edx
4387
        jbe     new_port_access_disable
1306 Lrz 4388
no_mask_io:
4389
;     popad                         ; end disable io map
2434 Serge 4390
        xor     eax, eax
4391
        ret
4392
;-----------------------------------------------------------------------------
2106 serge 4393
align 4
1 ha 4394
drawbackground:
2434 Serge 4395
dbrv20:
4396
        cmp     [BgrDrawMode], dword 1
4397
        jne     bgrstr
4398
        call    vesa20_drawbackground_tiled
2465 Serge 4399
;        call    [draw_pointer]
4400
        call    __sys_draw_pointer
2434 Serge 4401
        ret
4402
;--------------------------------------
75 diamond 4403
align 4
2434 Serge 4404
bgrstr:
4405
        call    vesa20_drawbackground_stretch
2465 Serge 4406
;        call    [draw_pointer]
4407
        call    __sys_draw_pointer
2434 Serge 4408
        ret
4409
;-----------------------------------------------------------------------------
4410
align 4
1055 Galkov 4411
syscall_putimage:                       ; PutImage
1 ha 4412
sys_putimage:
2434 Serge 4413
        test    ecx, 0x80008000
4414
        jnz     .exit
4415
        test    ecx, 0x0000FFFF
4416
        jz      .exit
4417
        test    ecx, 0xFFFF0000
4418
        jnz     @f
4419
;--------------------------------------
4420
align 4
4421
.exit:
4422
        ret
4423
;--------------------------------------
4424
align 4
4425
@@:
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
4431
;--------------------------------------
4432
align 4
4433
.forced:
1055 Galkov 4434
        push    ebp esi 0
4435
        mov     ebp, putimage_get24bpp
4436
        mov     esi, putimage_init24bpp
2434 Serge 4437
;--------------------------------------
4438
align 4
283 diamond 4439
sys_putimage_bpp:
2434 Serge 4440
        call    vesa20_putimage
1055 Galkov 4441
        pop     ebp esi ebp
2434 Serge 4442
        ret
4443
;        jmp     [draw_pointer]
4444
;-----------------------------------------------------------------------------
1495 Lrz 4445
align 4
283 diamond 4446
sys_putimage_palette:
4447
; ebx = pointer to image
4448
; ecx = [xsize]*65536 + [ysize]
4449
; edx = [xstart]*65536 + [ystart]
314 diamond 4450
; esi = number of bits per pixel, must be 8, 24 or 32
283 diamond 4451
; edi = pointer to palette
314 diamond 4452
; ebp = row delta
1055 Galkov 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
2434 Serge 4459
;--------------------------------------
4460
align 4
283 diamond 4461
.forced:
1055 Galkov 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
2434 Serge 4475
;--------------------------------------
4476
align 4
911 diamond 4477
@@:
1055 Galkov 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
2434 Serge 4487
;--------------------------------------
4488
align 4
911 diamond 4489
@@:
1055 Galkov 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
2434 Serge 4499
;--------------------------------------
4500
align 4
314 diamond 4501
@@:
1055 Galkov 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
2434 Serge 4508
;--------------------------------------
4509
align 4
918 diamond 4510
@@:
2987 Serge 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
@@:
1055 Galkov 4519
        cmp     esi, 15
4520
        jnz     @f
4521
        mov     ebp, putimage_get15bpp
4522
        mov     esi, putimage_init15bpp
4523
        jmp     sys_putimage_bpp
2434 Serge 4524
;--------------------------------------
4525
align 4
906 diamond 4526
@@:
1055 Galkov 4527
        cmp     esi, 16
4528
        jnz     @f
4529
        mov     ebp, putimage_get16bpp
4530
        mov     esi, putimage_init16bpp
4531
        jmp     sys_putimage_bpp
2434 Serge 4532
;--------------------------------------
4533
align 4
842 diamond 4534
@@:
1055 Galkov 4535
        cmp     esi, 24
4536
        jnz     @f
4537
        mov     ebp, putimage_get24bpp
4538
        mov     esi, putimage_init24bpp
4539
        jmp     sys_putimage_bpp
2434 Serge 4540
;--------------------------------------
4541
align 4
314 diamond 4542
@@:
1055 Galkov 4543
        cmp     esi, 32
4544
        jnz     @f
4545
        mov     ebp, putimage_get32bpp
4546
        mov     esi, putimage_init32bpp
4547
        jmp     sys_putimage_bpp
2434 Serge 4548
;--------------------------------------
4549
align 4
314 diamond 4550
@@:
1055 Galkov 4551
        pop     ebp esi ebp
4552
        ret
2434 Serge 4553
;-----------------------------------------------------------------------------
4554
align 4
911 diamond 4555
put_mono_image:
1055 Galkov 4556
        push    ebp esi ebp
4557
        mov     ebp, putimage_get1bpp
4558
        mov     esi, putimage_init1bpp
4559
        jmp     sys_putimage_bpp
2434 Serge 4560
;-----------------------------------------------------------------------------
4561
align 4
918 diamond 4562
put_2bit_image:
1055 Galkov 4563
        push    ebp esi ebp
4564
        mov     ebp, putimage_get2bpp
4565
        mov     esi, putimage_init2bpp
4566
        jmp     sys_putimage_bpp
2434 Serge 4567
;-----------------------------------------------------------------------------
4568
align 4
911 diamond 4569
put_4bit_image:
1055 Galkov 4570
        push    ebp esi ebp
4571
        mov     ebp, putimage_get4bpp
4572
        mov     esi, putimage_init4bpp
4573
        jmp     sys_putimage_bpp
2434 Serge 4574
;-----------------------------------------------------------------------------
4575
align 4
283 diamond 4576
putimage_init24bpp:
1055 Galkov 4577
        lea     eax, [eax*3]
283 diamond 4578
putimage_init8bpp:
2987 Serge 4579
putimage_init9bpp:
1055 Galkov 4580
        ret
2434 Serge 4581
;-----------------------------------------------------------------------------
911 diamond 4582
align 16
283 diamond 4583
putimage_get24bpp:
1055 Galkov 4584
        movzx   eax, byte [esi+2]
4585
        shl     eax, 16
4586
        mov     ax, [esi]
4587
        add     esi, 3
4588
        ret     4
2434 Serge 4589
;-----------------------------------------------------------------------------
911 diamond 4590
align 16
283 diamond 4591
putimage_get8bpp:
1055 Galkov 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
2434 Serge 4599
;-----------------------------------------------------------------------------
2987 Serge 4600
align 16
4601
putimage_get9bpp:
4602
        lodsb
4603
        mov     ah, al
4604
        shl     eax, 8
4605
        mov     al, ah
4606
        ret     4
4607
;-----------------------------------------------------------------------------
2434 Serge 4608
align 4
911 diamond 4609
putimage_init1bpp:
1055 Galkov 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
2434 Serge 4619
;-----------------------------------------------------------------------------
911 diamond 4620
align 16
4621
putimage_get1bpp:
1055 Galkov 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
911 diamond 4629
@@:
1055 Galkov 4630
        mov     [edx], al
4631
        sbb     eax, eax
4632
        and     eax, [edx+8]
4633
        add     eax, [edx+4]
4634
        pop     edx
4635
        ret     4
2434 Serge 4636
;-----------------------------------------------------------------------------
4637
align 4
918 diamond 4638
putimage_init2bpp:
1055 Galkov 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
2434 Serge 4648
;-----------------------------------------------------------------------------
918 diamond 4649
align 16
4650
putimage_get2bpp:
1055 Galkov 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
918 diamond 4663
.nonewbyte:
1055 Galkov 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
2434 Serge 4670
;-----------------------------------------------------------------------------
4671
align 4
911 diamond 4672
putimage_init4bpp:
1055 Galkov 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
2434 Serge 4682
;-----------------------------------------------------------------------------
911 diamond 4683
align 16
4684
putimage_get4bpp:
1055 Galkov 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
911 diamond 4695
@@:
1055 Galkov 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
2434 Serge 4704
;-----------------------------------------------------------------------------
4705
align 4
314 diamond 4706
putimage_init32bpp:
1055 Galkov 4707
        shl     eax, 2
4708
        ret
2434 Serge 4709
;-----------------------------------------------------------------------------
911 diamond 4710
align 16
314 diamond 4711
putimage_get32bpp:
1055 Galkov 4712
        lodsd
4713
        ret     4
2434 Serge 4714
;-----------------------------------------------------------------------------
4715
align 4
906 diamond 4716
putimage_init15bpp:
911 diamond 4717
putimage_init16bpp:
1055 Galkov 4718
        add     eax, eax
4719
        ret
2434 Serge 4720
;-----------------------------------------------------------------------------
911 diamond 4721
align 16
906 diamond 4722
putimage_get15bpp:
842 diamond 4723
; 0RRRRRGGGGGBBBBB -> 00000000RRRRR000GGGGG000BBBBB000
1055 Galkov 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
2434 Serge 4739
;-----------------------------------------------------------------------------
911 diamond 4740
align 16
906 diamond 4741
putimage_get16bpp:
4742
; RRRRRGGGGGGBBBBB -> 00000000RRRRR000GGGGGG00BBBBB000
1055 Galkov 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
2434 Serge 4758
;-----------------------------------------------------------------------------
4759
;align 4
1 ha 4760
; eax x beginning
4761
; ebx y beginning
4762
; ecx x end
1055 Galkov 4763
        ; edx y end
1 ha 4764
; edi color
2434 Serge 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
4775
;        call    [draw_pointer]
4776
;        ret
4777
;-----------------------------------------------------------------------------
4778
align 4
5201 serge 4779
kb_write_wait_ack:
1 ha 4780
 
1055 Galkov 4781
        push    ecx edx
1 ha 4782
 
2434 Serge 4783
        mov     dl, al
4784
        mov     ecx, 0x1ffff; last 0xffff, new value in view of fast CPU's
5201 serge 4785
.wait_output_ready:
2434 Serge 4786
        in      al, 0x64
4787
        test    al, 2
5201 serge 4788
        jz      @f
4789
        loop    .wait_output_ready
2434 Serge 4790
        mov     ah, 1
5201 serge 4791
        jmp     .nothing
4792
@@:
2434 Serge 4793
        mov     al, dl
4794
        out     0x60, al
5201 serge 4795
        mov     ecx, 0xfffff; last 0xffff, new value in view of fast CPU's
4796
.wait_ack:
2434 Serge 4797
        in      al, 0x64
5201 serge 4798
        test    al, 1
4799
        jnz     @f
4800
        loop    .wait_ack
2434 Serge 4801
        mov     ah, 1
5201 serge 4802
        jmp     .nothing
4803
@@:
4804
        in      al, 0x60
2434 Serge 4805
        xor     ah, ah
1 ha 4806
 
5201 serge 4807
.nothing:
1055 Galkov 4808
        pop     edx ecx
1 ha 4809
 
1055 Galkov 4810
        ret
2434 Serge 4811
;-----------------------------------------------------------------------------
1 ha 4812
 
4813
setmouse:  ; set mousepicture -pointer
1055 Galkov 4814
           ; ps2 mouse enable
1 ha 4815
 
2434 Serge 4816
;        mov     [MOUSE_PICTURE], dword mousepointer
1 ha 4817
 
2434 Serge 4818
        cli
1 ha 4819
 
2434 Serge 4820
        ret
1 ha 4821
 
1055 Galkov 4822
if used _rdtsc
1 ha 4823
_rdtsc:
2434 Serge 4824
        bt      [cpu_caps], CAPS_TSC
4825
        jnc     ret_rdtsc
4826
        rdtsc
4827
        ret
1 ha 4828
   ret_rdtsc:
2434 Serge 4829
        mov     edx, 0xffffffff
4830
        mov     eax, 0xffffffff
4831
        ret
1055 Galkov 4832
end if
1 ha 4833
 
4834
sys_msg_board_str:
4835
 
2434 Serge 4836
        pushad
1 ha 4837
   @@:
2434 Serge 4838
        cmp     [esi], byte 0
4839
        je      @f
3626 Serge 4840
        mov     ebx, 1
4841
        movzx   ecx, byte [esi]
2434 Serge 4842
        call    sys_msg_board
4843
        inc     esi
4844
        jmp     @b
1 ha 4845
   @@:
2434 Serge 4846
        popad
4847
        ret
1 ha 4848
 
709 diamond 4849
sys_msg_board_byte:
4850
; in: al = byte to display
4851
; out: nothing
4852
; destroys: nothing
1055 Galkov 4853
        pushad
4854
        mov     ecx, 2
4855
        shl     eax, 24
4856
        jmp     @f
709 diamond 4857
 
4858
sys_msg_board_word:
4859
; in: ax = word to display
4860
; out: nothing
4861
; destroys: nothing
1055 Galkov 4862
        pushad
4863
        mov     ecx, 4
4864
        shl     eax, 16
4865
        jmp     @f
709 diamond 4866
 
4867
sys_msg_board_dword:
4868
; in: eax = dword to display
4869
; out: nothing
4870
; destroys: nothing
1055 Galkov 4871
        pushad
4872
        mov     ecx, 8
709 diamond 4873
@@:
1055 Galkov 4874
        push    ecx
4875
        rol     eax, 4
4876
        push    eax
4877
        and     al, 0xF
4878
        cmp     al, 10
4879
        sbb     al, 69h
4880
        das
3626 Serge 4881
        mov     cl, al
4882
        xor     ebx, ebx
4883
        inc     ebx
1055 Galkov 4884
        call    sys_msg_board
4885
        pop     eax
4886
        pop     ecx
4887
        loop    @b
4888
        popad
4889
        ret
709 diamond 4890
 
3500 Serge 4891
msg_board_data_size = 65536 ; Must be power of two
4892
 
1 ha 4893
uglobal
3500 Serge 4894
  msg_board_data  rb msg_board_data_size
1 ha 4895
  msg_board_count dd 0x0
4896
endg
4897
 
4898
sys_msg_board:
4899
 
3626 Serge 4900
; ebx=1 : write :  bl byte to write
4901
; ebx=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
1 ha 4902
 
3626 Serge 4903
        push    eax ebx                 ; Save eax and ebx, since we're restoring their order required.
4904
        mov     eax, ebx
4905
        mov     ebx, ecx
4906
 
1055 Galkov 4907
        mov     ecx, [msg_board_count]
4908
        cmp     eax, 1
4909
        jne     .smbl1
1 ha 4910
 
1043 hidnplayr 4911
if defined debug_com_base
1 ha 4912
 
1055 Galkov 4913
        push    dx ax
1043 hidnplayr 4914
 
1055 Galkov 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
1043 hidnplayr 4920
 
1055 Galkov 4921
        mov     dx, debug_com_base      ; Output the byte
4922
        mov     al, bl
4923
        out     dx, al
1043 hidnplayr 4924
 
1055 Galkov 4925
        pop     ax dx
1043 hidnplayr 4926
 
4927
end if
4928
 
2434 Serge 4929
        mov     [msg_board_data+ecx], bl
3908 Serge 4930
; // if debug_direct_print == 1
4931
        cmp     byte [debug_direct_print], 1
4932
        jnz     @f
3555 Serge 4933
        pusha
4934
iglobal
3908 Serge 4935
msg_board_pos   dd      (42*6)*65536+10 ; for printing debug output on the screen
3555 Serge 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
3908 Serge 4947
        mov     word [msg_board_pos+2], (42*6)
3555 Serge 4948
        add     word [msg_board_pos], 10
5565 serge 4949
        mov     ax, word [_display.width]
3555 Serge 4950
        cmp     word [msg_board_pos], ax
5565 serge 4951
        jb      @f
3555 Serge 4952
        mov     word [msg_board_pos], 10
4953
@@:
3908 Serge 4954
; // end if
4955
 
3555 Serge 4956
if 0
4957
        pusha
4958
        mov     al, bl
4959
        mov     edx, 402h
4960
        out     dx, al
4961
        popa
4962
end if
1055 Galkov 4963
        inc     ecx
3500 Serge 4964
        and     ecx, msg_board_data_size - 1
1055 Galkov 4965
        mov     [msg_board_count], ecx
3626 Serge 4966
 
4967
        pop     ebx eax
1055 Galkov 4968
        ret
671 Ghost 4969
.smbl1:
1055 Galkov 4970
        cmp     eax, 2
4971
        jne     .smbl2
4972
        test    ecx, ecx
4973
        jz      .smbl21
3626 Serge 4974
 
4975
        add     esp, 8                  ; Returning data in ebx and eax, so no need to restore them.
1055 Galkov 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]
3626 Serge 4981
        mov     [esp + 32], edx ;eax
4982
        mov     [esp + 20], dword 1
1055 Galkov 4983
        ret
671 Ghost 4984
.smbl21:
3626 Serge 4985
        mov     [esp+32], ecx
4986
        mov     [esp+20], ecx
671 Ghost 4987
.smbl2:
3626 Serge 4988
        pop     ebx eax
1055 Galkov 4989
        ret
1 ha 4990
 
1494 Lrz 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
2987 Serge 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
1494 Lrz 5006
endg
2987 Serge 5007
;-----------------------------------------------------------------------------
5008
align 4
1 ha 5009
sys_process_def:
2434 Serge 5010
        dec     ebx
2987 Serge 5011
        cmp     ebx, 7
5012
        jae     .not_support    ;if >=8 then or eax,-1
1494 Lrz 5013
 
1055 Galkov 5014
        mov     edi, [CURRENT_TASK]
2434 Serge 5015
        jmp     dword [f66call+ebx*4]
1 ha 5016
 
1494 Lrz 5017
.not_support:
2434 Serge 5018
        or      eax, -1
5019
        ret
2987 Serge 5020
;-----------------------------------------------------------------------------
5021
align 4
1494 Lrz 5022
.1:
2434 Serge 5023
        shl     edi, 8
5024
        mov     [edi+SLOT_BASE + APPDATA.keyboard_mode], cl
1 ha 5025
 
2434 Serge 5026
        ret
2987 Serge 5027
;-----------------------------------------------------------------------------
5028
align 4
2434 Serge 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
2987 Serge 5034
;-----------------------------------------------------------------------------
5035
align 4
2434 Serge 5036
.3:                             ;3 = get keyboard ctrl, alt, shift
5037
        mov     eax, [kb_state]
5038
        mov     [esp+32], eax
5039
        ret
2987 Serge 5040
;-----------------------------------------------------------------------------
5041
align 4
1494 Lrz 5042
.4:
1055 Galkov 5043
        mov     eax, hotkey_list
92 diamond 5044
@@:
1055 Galkov 5045
        cmp     dword [eax+8], 0
5046
        jz      .found_free
5047
        add     eax, 16
5048
        cmp     eax, hotkey_list+16*256
5049
        jb      @b
1494 Lrz 5050
        mov     dword [esp+32], 1
1055 Galkov 5051
        ret
92 diamond 5052
.found_free:
1055 Galkov 5053
        mov     [eax+8], edi
1494 Lrz 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
3500 Serge 5061
        test    edx, edx
5062
        jz      @f
1494 Lrz 5063
        mov     [edx+12], eax
92 diamond 5064
@@:
1494 Lrz 5065
        and     dword [esp+32], 0
1055 Galkov 5066
        ret
2987 Serge 5067
;-----------------------------------------------------------------------------
5068
align 4
1494 Lrz 5069
.5:
5070
        movzx   ebx, cl
1055 Galkov 5071
        lea     ebx, [hotkey_scancodes+ebx*4]
5072
        mov     eax, [ebx]
92 diamond 5073
.scan:
1055 Galkov 5074
        test    eax, eax
5075
        jz      .notfound
5076
        cmp     [eax+8], edi
5077
        jnz     .next
1494 Lrz 5078
        cmp     [eax+4], edx
1055 Galkov 5079
        jz      .found
92 diamond 5080
.next:
1055 Galkov 5081
        mov     eax, [eax]
5082
        jmp     .scan
92 diamond 5083
.notfound:
1494 Lrz 5084
        mov     dword [esp+32], 1
1055 Galkov 5085
        ret
92 diamond 5086
.found:
1055 Galkov 5087
        mov     ecx, [eax]
5088
        jecxz   @f
5089
        mov     edx, [eax+12]
5090
        mov     [ecx+12], edx
92 diamond 5091
@@:
1055 Galkov 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
1494 Lrz 5100
        mov     [esp+32], edx
1055 Galkov 5101
        ret
2987 Serge 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
92 diamond 5132
 
2987 Serge 5133
        xor     eax, eax
5134
        mov     [PID_lock_input], eax
5135
@@:
5136
        ret
5137
;-----------------------------------------------------------------------------
5138
uglobal
5139
  PID_lock_input dd 0x0
5140
endg
1497 Lrz 5141
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5142
;; 61 sys function.                                                ;;
5143
;; in eax=61,ebx in [1..3]                                         ;;
5144
;; out eax                                                         ;;
5145
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5146
iglobal
1 ha 5147
align 4
1497 Lrz 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
1 ha 5153
 
1497 Lrz 5154
 
5155
align 4
5156
 
1055 Galkov 5157
sys_gs:                         ; direct screen access
2434 Serge 5158
        dec     ebx
5159
        cmp     ebx, 2
5160
        ja      .not_support
5161
        jmp     dword [f61call+ebx*4]
1497 Lrz 5162
.not_support:
2434 Serge 5163
        or      [esp+32], dword -1
1497 Lrz 5164
        ret
1 ha 5165
 
1497 Lrz 5166
 
5167
.1:                             ; resolution
5565 serge 5168
        mov     eax, [_display.width]
2434 Serge 5169
        shl     eax, 16
5565 serge 5170
        mov     ax, word [_display.height]
2434 Serge 5171
        mov     [esp+32], eax
5172
        ret
5173
.2:                             ; bits per pixel
5201 serge 5174
        mov     eax, [_display.bits_per_pixel]
2434 Serge 5175
        mov     [esp+32], eax
5176
        ret
1497 Lrz 5177
.3:                             ; bytes per scanline
5565 serge 5178
        mov     eax, [_display.lfb_pitch]
2434 Serge 5179
        mov     [esp+32], eax
5180
        ret
1 ha 5181
 
5182
align 4  ;  system functions
5183
 
1055 Galkov 5184
syscall_setpixel:                       ; SetPixel
1 ha 5185
 
1055 Galkov 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
2434 Serge 5196
        and     ecx, 0xFBFFFFFF  ;negate 0x04000000 save to mouseunder area
2465 Serge 5197
;        jmp     [putpixel]
5198
        jmp     __sys_putpixel
1 ha 5199
 
5200
align 4
5201
 
1055 Galkov 5202
syscall_writetext:                      ; WriteText
1 ha 5203
 
2434 Serge 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
3500 Serge 5213
        test    ecx, 0x08000000  ; redirect the output to the user area
5214
        jnz     @f
2434 Serge 5215
        add     ebx, ebp
3500 Serge 5216
align 4
5217
@@:
2434 Serge 5218
        mov     eax, edi
2987 Serge 5219
        test    ecx, 0x08000000  ; redirect the output to the user area
5220
        jnz     dtext
2434 Serge 5221
        xor     edi, edi
5222
        jmp     dtext
1 ha 5223
 
5224
align 4
5225
 
1055 Galkov 5226
syscall_drawrect:                       ; DrawRect
1 ha 5227
 
1055 Galkov 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
1 ha 5234
 
1055 Galkov 5235
        mov     eax, ebx ; bad idea
5236
        mov     ebx, ecx
1 ha 5237
 
1055 Galkov 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]
1 ha 5243
 
1055 Galkov 5244
        add     eax, [esi + APPDATA.wnd_clientbox.left]
5245
        add     ebx, [esi + APPDATA.wnd_clientbox.top]
5246
        add     ecx, eax
5247
        add     edx, ebx
2465 Serge 5248
;        jmp     [drawbar]
5249
        jmp     vesa20_drawbar
671 Ghost 5250
.drectr:
1055 Galkov 5251
        ret
1 ha 5252
 
5253
align 4
1055 Galkov 5254
syscall_getscreensize:                  ; GetScreenSize
5565 serge 5255
        mov     ax, word [_display.width]
5256
        dec     ax
1055 Galkov 5257
        shl     eax, 16
5565 serge 5258
        mov     ax, word [_display.height]
5259
        dec     ax
1055 Galkov 5260
        mov     [esp + 32], eax
5261
        ret
5201 serge 5262
;-----------------------------------------------------------------------------
671 Ghost 5263
align 4
5201 serge 5264
syscall_cdaudio:
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
671 Ghost 5271
 
5201 serge 5272
        mov     eax, ecx
5273
        shr     eax, 2
5274
        lea     eax, [eax*5]
5275
        mov     al, [eax+DRIVE_DATA+1]
1 ha 5276
 
5201 serge 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
 
1290 Lrz 5289
        cmp     ebx, 4
5201 serge 5290
        je      .eject
5291
 
1290 Lrz 5292
        cmp     ebx, 5
5201 serge 5293
        je      .load
5294
;--------------------------------------
5295
.exit:
5296
        ret
5297
;--------------------------------------
588 diamond 5298
.load:
1055 Galkov 5299
        call    .reserve
5300
        call    LoadMedium
2434 Serge 5301
        jmp     .free
5201 serge 5302
;--------------------------------------
588 diamond 5303
.eject:
1055 Galkov 5304
        call    .reserve
5305
        call    clear_CD_cache
5306
        call    allow_medium_removal
5307
        call    EjectMedium
2434 Serge 5308
        jmp     .free
5201 serge 5309
;--------------------------------------
588 diamond 5310
.reserve:
1055 Galkov 5311
        call    reserve_cd
5201 serge 5312
 
5313
        mov     ebx, ecx
5314
        inc     ebx
5315
        mov     [cdpos], ebx
5316
 
1290 Lrz 5317
        mov     eax, ecx
1055 Galkov 5318
        shr     eax, 1
5319
        and     eax, 1
5320
        inc     eax
5321
        mov     [ChannelNumber], ax
1290 Lrz 5322
        mov     eax, ecx
1055 Galkov 5323
        and     eax, 1
5324
        mov     [DiskNumber], al
5325
        call    reserve_cd_channel
5326
        ret
5201 serge 5327
;--------------------------------------
588 diamond 5328
.free:
1055 Galkov 5329
        call    free_cd_channel
5330
        and     [cd_status], 0
5331
        ret
2987 Serge 5332
;-----------------------------------------------------------------------------
1 ha 5333
align 4
2987 Serge 5334
syscall_getpixel_WinMap:                       ; GetPixel WinMap
5565 serge 5335
        cmp     ebx, [_display.width]
5336
        jb      @f
5337
        cmp     ecx, [_display.height]
5338
        jb      @f
2987 Serge 5339
        xor     eax, eax
5340
        jmp     .store
5341
;--------------------------------------
5342
align 4
5343
@@:
5344
        mov     eax, [d_width_calc_area + ecx*4]
5565 serge 5345
        add     eax, [_display.win_map]
2987 Serge 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
1055 Galkov 5354
syscall_getpixel:                       ; GetPixel
5565 serge 5355
        mov     ecx, [_display.width]
2434 Serge 5356
        xor     edx, edx
5357
        mov     eax, ebx
5358
        div     ecx
5359
        mov     ebx, edx
5360
        xchg    eax, ebx
5361
        and     ecx, 0xFBFFFFFF  ;negate 0x04000000 use mouseunder area
5362
        call    dword [GETPIXEL]; eax - x, ebx - y
5363
        mov     [esp + 32], ecx
5364
        ret
2987 Serge 5365
;-----------------------------------------------------------------------------
921 mario79 5366
align 4
5367
syscall_getarea:
5368
;eax = 36
1055 Galkov 5369
;ebx = pointer to bufer for img BBGGRRBBGGRR...
5370
;ecx = [size x]*65536 + [size y]
5371
;edx = [start x]*65536 + [start y]
2434 Serge 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
921 mario79 5380
     ; eax - x, ebx - y
2434 Serge 5381
        mov     edx, ecx
1638 serge 5382
 
2434 Serge 5383
        shr     ecx, 16
5384
        and     edx, 0xffff
5385
        mov     esi, ecx
921 mario79 5386
     ; ecx - size x, edx - size y
1638 serge 5387
 
2434 Serge 5388
        mov     ebp, edx
5389
        dec     ebp
5390
        lea     ebp, [ebp*3]
1638 serge 5391
 
2434 Serge 5392
        imul    ebp, esi
1638 serge 5393
 
2434 Serge 5394
        mov     esi, ecx
5395
        dec     esi
5396
        lea     esi, [esi*3]
1638 serge 5397
 
2434 Serge 5398
        add     ebp, esi
5399
        add     ebp, edi
927 mario79 5400
 
2434 Serge 5401
        add     ebx, edx
2987 Serge 5402
;--------------------------------------
5403
align 4
921 mario79 5404
.start_y:
2434 Serge 5405
        push    ecx edx
2987 Serge 5406
;--------------------------------------
5407
align 4
921 mario79 5408
.start_x:
2434 Serge 5409
        push    eax ebx ecx
5410
        add     eax, ecx
927 mario79 5411
 
2434 Serge 5412
        and     ecx, 0xFBFFFFFF  ;negate 0x04000000 use mouseunder area
5413
        call    dword [GETPIXEL]; eax - x, ebx - y
1638 serge 5414
 
2434 Serge 5415
        mov     [ebp], cx
5416
        shr     ecx, 16
5417
        mov     [ebp+2], cl
921 mario79 5418
 
2434 Serge 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
2987 Serge 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
921 mario79 5453
 
2987 Serge 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
;--------------------------------------
1 ha 5465
align 4
2987 Serge 5466
.start_y:
5467
        push    ecx edx
5468
;--------------------------------------
5469
align 4
5470
.start_x:
5471
        push    eax ecx
5472
        add     eax, ecx
1 ha 5473
 
2987 Serge 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]
5565 serge 5484
        add     edx, [_display.win_map]
2987 Serge 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
5498
 
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
1055 Galkov 5512
syscall_drawline:                       ; DrawLine
1 ha 5513
 
1055 Galkov 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]
2434 Serge 5520
        add     ebp, ebx
1055 Galkov 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
2465 Serge 5532
;        jmp     [draw_line]
5533
        jmp     __sys_draw_line
1 ha 5534
 
5535
 
5536
align 4
1055 Galkov 5537
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
1 ha 5538
 
2434 Serge 5539
        call    r_f_port_area
5540
        mov     [esp+32], eax
5541
        ret
1 ha 5542
 
5543
align 4
1055 Galkov 5544
syscall_threads:                        ; CreateThreads
1369 Lrz 5545
;
4265 Serge 5546
;   ecx=thread entry point
5547
;   edx=thread stack pointer
1369 Lrz 5548
;
5549
; on return : eax = pid
1 ha 5550
 
4265 Serge 5551
        xor     ebx, ebx
2434 Serge 5552
        call    new_sys_threads
1369 Lrz 5553
 
2434 Serge 5554
        mov     [esp+32], eax
5555
        ret
1 ha 5556
 
5557
align 4
5558
 
375 Ghost 5559
paleholder:
1055 Galkov 5560
        ret
2439 Serge 5561
;------------------------------------------------------------------------------
757 serge 5562
align 4
2439 Serge 5563
calculate_fast_getting_offset_for_WinMapAddress:
5564
; calculate data area for fast getting offset to _WinMapAddress
2465 Serge 5565
        xor     eax, eax
2439 Serge 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
2987 Serge 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
5565 serge 5585
        add     eax, [_display.lfb_pitch]
2987 Serge 5586
        dec     ecx
5587
        jnz     @r
5588
        ret
5589
;------------------------------------------------------------------------------
5590
align 4
757 serge 5591
set_screen:
2987 Serge 5592
; in:
5593
; eax - new Screen_Max_X
5594
; ecx - new BytesPerScanLine
5595
; edx - new Screen_Max_Y
709 diamond 5596
 
1055 Galkov 5597
        pushfd
5598
        cli
757 serge 5599
 
5565 serge 5600
        mov     [_display.lfb_pitch], ecx
757 serge 5601
 
2434 Serge 5602
        mov     [screen_workarea.right], eax
5603
        mov     [screen_workarea.bottom], edx
1300 serge 5604
 
2434 Serge 5605
        push    ebx
5606
        push    esi
5607
        push    edi
1300 serge 5608
 
5609
        pushad
5610
 
2987 Serge 5611
        cmp     [do_not_touch_winmap], 1
5612
        je      @f
5613
 
5565 serge 5614
        stdcall kernel_free, [_display.win_map]
1300 serge 5615
 
2434 Serge 5616
        mov     eax, [_display.width]
5617
        mul     [_display.height]
5565 serge 5618
        mov     [_display.win_map_size], eax
1300 serge 5619
 
5620
        stdcall kernel_alloc, eax
5565 serge 5621
        mov     [_display.win_map], eax
2434 Serge 5622
        test    eax, eax
5623
        jz      .epic_fail
2987 Serge 5624
; store for f.18.24
5625
        mov     eax, [_display.width]
5626
        mov     [display_width_standard], eax
1300 serge 5627
 
2987 Serge 5628
        mov     eax, [_display.height]
5629
        mov     [display_height_standard], eax
5630
@@:
2439 Serge 5631
        call    calculate_fast_getting_offset_for_WinMapAddress
2987 Serge 5632
; for Qemu or non standart video cards
5633
; Unfortunately [BytesPerScanLine] does not always
5634
;                             equal to [_display.width] * [ScreenBPP] / 8
5635
        call    calculate_fast_getting_offset_for_LFB
1300 serge 5636
        popad
5637
 
1055 Galkov 5638
        call    repos_windows
2434 Serge 5639
        xor     eax, eax
5640
        xor     ebx, ebx
5565 serge 5641
        mov     ecx, [_display.width]
5642
        mov     edx, [_display.height]
5643
        dec     ecx
5644
        dec     edx
1055 Galkov 5645
        call    calculatescreen
2434 Serge 5646
        pop     edi
5647
        pop     esi
5648
        pop     ebx
757 serge 5649
 
1055 Galkov 5650
        popfd
5651
        ret
757 serge 5652
 
1300 serge 5653
.epic_fail:
5654
        hlt                     ; Houston, we've had a problem
5655
 
76 mario79 5656
; --------------- APM ---------------------
1330 Lrz 5657
uglobal
2434 Serge 5658
apm_entry       dp      0
5659
apm_vf          dd      0
1330 Lrz 5660
endg
5661
 
1 ha 5662
align 4
76 mario79 5663
sys_apm:
2434 Serge 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
164 serge 5672
 
465 serge 5673
@@:
2434 Serge 5674
;       xchg    eax, ecx
5675
;       xchg    ebx, ecx
164 serge 5676
 
2434 Serge 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
78 diamond 5685
 
465 serge 5686
@@:
5687
 
2434 Serge 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
465 serge 5693
 
2434 Serge 5694
        call    pword [apm_entry]       ;call APM BIOS
465 serge 5695
 
2434 Serge 5696
        xchg    eax, [esp]
5697
        mov     [master_tab], eax
5698
        mov     eax, cr3
5699
        mov     cr3, eax
5700
        pop     eax
465 serge 5701
 
2434 Serge 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
76 mario79 5712
; -----------------------------------------
1 ha 5713
 
76 mario79 5714
align 4
5715
 
1055 Galkov 5716
undefined_syscall:                      ; Undefined system call
2434 Serge 5717
        mov     [esp + 32], dword -1
5718
        ret
1 ha 5719
 
5720
 
3626 Serge 5721
if ~ lang eq sp
5722
diff16 "end of .text segment",0,$
5723
end if
5724
 
465 serge 5725
include "data32.inc"
1 ha 5726
 
465 serge 5727
__REV__ = __REV
1 ha 5728
 
3500 Serge 5729
if ~ lang eq sp
41 mikedld 5730
diff16 "end of kernel code",0,$
3500 Serge 5731
end if