Subversion Repositories Kolibri OS

Rev

Rev 6319 | Details | Compare with Previous | Last modification | View Log | RSS feed

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