Subversion Repositories Kolibri OS

Rev

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