Subversion Repositories Kolibri OS

Rev

Rev 6242 | Rev 6252 | 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: 6246 $
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
 
6246 serge 537
        call    init_video
538
        call    init_mtrr
539
        mov     [LFBAddress], LFB_BASE
540
        mov     ecx, bios_fb
541
        call    set_framebuffer
2434 Serge 542
        call    init_fpu
543
        call    init_malloc
276 serge 544
 
5201 serge 545
        stdcall alloc_kernel_space, 0x50000         ; FIXME check size
2434 Serge 546
        mov     [default_io_map], eax
465 serge 547
 
2434 Serge 548
        add     eax, 0x2000
549
        mov     [ipc_tmp], eax
550
        mov     ebx, 0x1000
164 serge 551
 
2434 Serge 552
        add     eax, 0x40000
553
        mov     [proc_mem_map], eax
164 serge 554
 
2434 Serge 555
        add     eax, 0x8000
556
        mov     [proc_mem_pdir], eax
164 serge 557
 
2434 Serge 558
        add     eax, ebx
559
        mov     [proc_mem_tab], eax
164 serge 560
 
2434 Serge 561
        add     eax, ebx
562
        mov     [tmp_task_ptab], eax
164 serge 563
 
2434 Serge 564
        add     eax, ebx
565
        mov     [ipc_pdir], eax
164 serge 566
 
2434 Serge 567
        add     eax, ebx
568
        mov     [ipc_ptab], eax
164 serge 569
 
2434 Serge 570
        stdcall kernel_alloc, (unpack.LZMA_BASE_SIZE+(unpack.LZMA_LIT_SIZE shl \
571
                (unpack.lc+unpack.lp)))*4
712 serge 572
 
2434 Serge 573
        mov     [unpack.p], eax
709 diamond 574
 
2434 Serge 575
        call    init_events
576
        mov     eax, srv.fd-SRV.fd
577
        mov     [srv.fd], eax
578
        mov     [srv.bk], eax
278 serge 579
 
41 mikedld 580
;Set base of graphic segment to linear address of LFB
2434 Serge 581
        mov     eax, [LFBAddress]         ; set for gs
582
        mov     [graph_data_l+2], ax
583
        shr     eax, 16
584
        mov     [graph_data_l+4], al
585
        mov     [graph_data_l+7], ah
1 ha 586
 
5565 serge 587
        stdcall kernel_alloc, [_display.win_map_size]
588
        mov     [_display.win_map], eax
1300 serge 589
 
2434 Serge 590
        xor     eax, eax
591
        inc     eax
429 serge 592
 
469 serge 593
; set background
1300 serge 594
 
2434 Serge 595
        mov     [BgrDrawMode], eax
596
        mov     [BgrDataWidth], eax
597
        mov     [BgrDataHeight], eax
598
        mov     [mem_BACKGROUND], 4
599
        mov     [img_background], static_background_data
469 serge 600
 
4265 Serge 601
; set clipboard
602
 
603
        xor     eax, eax
604
        mov     [clipboard_slots], eax
605
        mov     [clipboard_write_lock], eax
606
        stdcall kernel_alloc, 4096
607
        test    eax, eax
608
        jnz     @f
609
 
610
        dec     eax
611
@@:
612
        mov     [clipboard_main_list], eax
613
 
5645 serge 614
        mov     eax, [hpet_base]
615
        test    eax, eax
616
        jz      @F
5629 serge 617
        mov     eax, [hpet_base]
618
        stdcall map_io_mem, [hpet_base], 1024, PG_GLOBAL+PAT_UC+PG_SWR
619
        mov     [hpet_base], eax
5645 serge 620
        mov     eax, [eax]
621
        DEBUGF  1, "K : HPET caps %x\n", eax
622
@@:
3500 Serge 623
; SET UP OS TASK
624
 
625
        mov     esi, boot_setostask
626
        call    boot_log
627
 
5577 serge 628
        mov     eax, sys_proc
629
        lea     edi, [eax+PROC.heap_lock]
630
        mov     ecx, (PROC.ht_free-PROC.heap_lock)/4
5201 serge 631
 
5577 serge 632
        list_init eax
633
        add     eax, PROC.thr_list
634
        list_init eax
635
 
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
        and     ecx, not 0x80000000     ; force counted string
1633
        mov     eax, [esp+64+8]         ; background color (if given)
1634
        mov     edi, [esp+64+4]
2434 Serge 1635
        jmp     dtext
5201 serge 1636
;-----------------------------------------------------------------------------
5596 serge 1637
iglobal
1638
midi_base dw 0
5201 serge 1639
endg
1640
;-----------------------------------------------------------------------------
1 ha 1641
align 4
1642
sys_setup:
5201 serge 1643
;  1 = roland mpu midi base , base io address
1644
;  2 = keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1645
;  3 = not used
1646
;  4 = not used
1647
;  5 = system language, 1eng 2fi 3ger 4rus
1648
;  6 = not used
1649
;  7 = not used
1650
;  8 = not used
1651
;  9 = not used
1652
; 10 = not used
1 ha 1653
; 11 = enable lba read
1654
; 12 = enable pci access
5201 serge 1655
;-----------------------------------------------------------------------------
1656
        and     [esp+32], dword 0
1657
; F.21.1 - set MPU MIDI base port
1658
        dec     ebx
1659
        jnz     @f
1 ha 1660
 
2434 Serge 1661
        cmp     ecx, 0x100
5201 serge 1662
        jb      @f
1 ha 1663
 
2434 Serge 1664
        mov     esi, 65535
1665
        cmp     esi, ecx
5201 serge 1666
        jb      @f
1276 Lrz 1667
 
5201 serge 1668
        mov     [midi_base], cx
1669
        mov     word [mididp], cx
1670
        inc     cx
1671
        mov     word [midisp], cx
2434 Serge 1672
        ret
5201 serge 1673
;--------------------------------------
1674
@@:
1675
; F.21.2 - set keyboard layout
1676
        dec     ebx
1677
        jnz     @f
1276 Lrz 1678
 
2434 Serge 1679
        mov     edi, [TASK_BASE]
1680
        mov     eax, [edi+TASKDATA.mem_start]
1681
        add     eax, edx
5201 serge 1682
; 1 = normal layout
1683
        dec     ecx
1684
        jnz     .shift
1 ha 1685
 
2434 Serge 1686
        mov     ebx, keymap
1687
        mov     ecx, 128
1688
        call    memmove
1689
        ret
5201 serge 1690
;--------------------------------------
1691
.shift:
1692
; 2 = layout at pressed Shift
2434 Serge 1693
        dec     ecx
5201 serge 1694
        jnz     .alt
1276 Lrz 1695
 
2434 Serge 1696
        mov     ebx, keymap_shift
1697
        mov     ecx, 128
1698
        call    memmove
1699
        ret
5201 serge 1700
;--------------------------------------
1701
.alt:
1702
; 3 = layout at pressed Alt
2434 Serge 1703
        dec     ecx
5201 serge 1704
        jnz     .country
1705
 
2434 Serge 1706
        mov     ebx, keymap_alt
1707
        mov     ecx, 128
1708
        call    memmove
1709
        ret
5201 serge 1710
;--------------------------------------
1711
.country:
1712
; country identifier
2434 Serge 1713
        sub     ecx, 6
5201 serge 1714
        jnz     .error
1715
 
2434 Serge 1716
        mov     word [keyboard], dx
1717
        ret
5201 serge 1718
;--------------------------------------
1719
@@:
1720
; F.21.5 - set system language
1721
        sub     ebx, 3
1722
        jnz     @f
1276 Lrz 1723
 
2434 Serge 1724
        mov     [syslang], ecx
1725
        ret
5201 serge 1726
;--------------------------------------
1727
@@:
1728
; F.21.11 - enable/disable low-level access to HD
1729
        and     ecx, 1
1730
        sub     ebx, 6
1731
        jnz     @f
1638 serge 1732
 
5201 serge 1733
        mov     [lba_read_enabled], ecx
2434 Serge 1734
        ret
5201 serge 1735
;--------------------------------------
1736
@@:
1737
; F.21.12 - enable/disable low-level access to PCI
2434 Serge 1738
        dec     ebx
5201 serge 1739
        jnz     .error
1 ha 1740
 
2434 Serge 1741
        mov     [pci_access_enabled], ecx
1742
        ret
5201 serge 1743
;--------------------------------------
1744
.error:
2434 Serge 1745
        or      [esp+32], dword -1
1746
        ret
5201 serge 1747
;-----------------------------------------------------------------------------
1 ha 1748
align 4
1749
sys_getsetup:
5201 serge 1750
;  1 = roland mpu midi base , base io address
1751
;  2 = keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1752
;  3 = not used
1753
;  4 = not used
1754
;  5 = system language, 1eng 2fi 3ger 4rus
1755
;  6 = not used
1756
;  7 = not used
1757
;  8 = not used
1758
;  9 = get hs timer tic
1759
; 10 = not used
1760
; 11 = get the state "lba read"
1761
; 12 = get the state "pci access"
1762
;-----------------------------------------------------------------------------
1763
; F.26.1 - get MPU MIDI base port
1764
        dec     ebx
1765
        jnz     @f
1 ha 1766
 
2434 Serge 1767
        movzx   eax, [midi_base]
1768
        mov     [esp+32], eax
1769
        ret
5201 serge 1770
;--------------------------------------
1771
@@:
1772
; F.26.2 - get keyboard layout
2434 Serge 1773
        dec     ebx
5201 serge 1774
        jnz     @f
1 ha 1775
 
2434 Serge 1776
        mov     edi, [TASK_BASE]
1777
        mov     ebx, [edi+TASKDATA.mem_start]
1778
        add     ebx, edx
5201 serge 1779
; 1 = normal layout
1780
        dec     ecx
1781
        jnz     .shift
1276 Lrz 1782
 
2434 Serge 1783
        mov     eax, keymap
1784
        mov     ecx, 128
1785
        call    memmove
1786
        ret
5201 serge 1787
;--------------------------------------
1788
.shift:
1789
; 2 = layout with pressed Shift
2434 Serge 1790
        dec     ecx
5201 serge 1791
        jnz     .alt
1276 Lrz 1792
 
2434 Serge 1793
        mov     eax, keymap_shift
1794
        mov     ecx, 128
1795
        call    memmove
1796
        ret
5201 serge 1797
;--------------------------------------
1798
.alt:
1799
; 3 = layout with pressed Alt
2434 Serge 1800
        dec     ecx
5201 serge 1801
        jne     .country
1276 Lrz 1802
 
2434 Serge 1803
        mov     eax, keymap_alt
1804
        mov     ecx, 128
1805
        call    memmove
1806
        ret
5201 serge 1807
;--------------------------------------
1808
.country:
1809
; 9 = country identifier
2434 Serge 1810
        sub     ecx, 6
5201 serge 1811
        jnz     .error
1812
 
2434 Serge 1813
        movzx   eax, word [keyboard]
1814
        mov     [esp+32], eax
1815
        ret
5201 serge 1816
;--------------------------------------
1817
@@:
1818
; F.26.5 - get system language
1819
        sub     ebx, 3
1820
        jnz     @f
1276 Lrz 1821
 
2434 Serge 1822
        mov     eax, [syslang]
1823
        mov     [esp+32], eax
1276 Lrz 1824
        ret
5201 serge 1825
;--------------------------------------
1826
@@:
1827
; F.26.9 - get the value of the time counter
1828
        sub     ebx, 4
1829
        jnz     @f
1830
 
1831
        mov     eax, [timer_ticks]
2434 Serge 1832
        mov     [esp+32], eax
1833
        ret
5201 serge 1834
;--------------------------------------
1835
@@:
5984 serge 1836
; F.26.10 - get the time from kernel launch in nanoseconds
1837
        sub     ebx, 1
1838
        jnz     @f
1839
 
1840
        call    get_clock_ns
1841
        mov     [esp+24], edx
1842
        mov     [esp+32], eax
1843
        ret
1844
;--------------------------------------
1845
@@:
5201 serge 1846
; F.26.11 - Find out whether low-level HD access is enabled
5984 serge 1847
        sub     ebx, 1
5201 serge 1848
        jnz     @f
1849
 
2434 Serge 1850
        mov     eax, [lba_read_enabled]
1851
        mov     [esp+32], eax
1852
        ret
5201 serge 1853
;--------------------------------------
1854
@@:
1855
; F.26.12 - Find out whether low-level PCI access is enabled
2434 Serge 1856
        dec     ebx
5201 serge 1857
        jnz     .error
1858
 
2434 Serge 1859
        mov     eax, [pci_access_enabled]
1860
        mov     [esp+32], eax
1861
        ret
5201 serge 1862
;--------------------------------------
1863
.error:
1864
        or      [esp+32], dword -1
2434 Serge 1865
        ret
5201 serge 1866
;-----------------------------------------------------------------------------
479 kastigar 1867
get_timer_ticks:
2434 Serge 1868
        mov     eax, [timer_ticks]
1869
        ret
5201 serge 1870
;-----------------------------------------------------------------------------
283 diamond 1871
iglobal
1 ha 1872
align 4
5984 serge 1873
mousefn dd msscreen
1874
        dd mswin
1875
        dd msbutton
1876
        dd msbuttonExt
1055 Galkov 1877
        dd app_load_cursor
1878
        dd app_set_cursor
1879
        dd app_delete_cursor
1880
        dd msz
283 diamond 1881
endg
5201 serge 1882
;-----------------------------------------------------------------------------
1 ha 1883
readmousepos:
1884
 
1885
; eax=0 screen relative
1886
; eax=1 window relative
1887
; eax=2 buttons pressed
5984 serge 1888
; eax=3 buttons pressed ext
221 serge 1889
; eax=4 load cursor
1890
; eax=5 set cursor
5984 serge 1891
; eax=6 delete cursor
479 kastigar 1892
; eax=7 get mouse_z
1 ha 1893
 
2434 Serge 1894
        cmp     ebx, 7
5984 serge 1895
        ja      @f
2434 Serge 1896
        jmp     [mousefn+ebx*4]
5984 serge 1897
 
221 serge 1898
msscreen:
2434 Serge 1899
        mov     eax, [MOUSE_X]
1900
        shl     eax, 16
1901
        mov     ax, [MOUSE_Y]
1902
        mov     [esp+36-4], eax
5984 serge 1903
@@:
2434 Serge 1904
        ret
5984 serge 1905
 
221 serge 1906
mswin:
2434 Serge 1907
        mov     eax, [MOUSE_X]
1908
        shl     eax, 16
1909
        mov     ax, [MOUSE_Y]
1910
        mov     esi, [TASK_BASE]
1911
        mov     bx, word [esi-twdw+WDATA.box.left]
1912
        shl     ebx, 16
1913
        mov     bx, word [esi-twdw+WDATA.box.top]
1914
        sub     eax, ebx
1915
        mov     edi, [CURRENT_TASK]
1916
        shl     edi, 8
1917
        sub     ax, word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1918
        rol     eax, 16
1919
        sub     ax, word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1920
        rol     eax, 16
1921
        mov     [esp+36-4], eax
1922
        ret
5984 serge 1923
 
221 serge 1924
msbutton:
2434 Serge 1925
        movzx   eax, byte [BTN_DOWN]
1926
        mov     [esp+36-4], eax
1927
        ret
5984 serge 1928
 
1929
msbuttonExt:
1930
        mov     eax, [BTN_DOWN]
2434 Serge 1931
        mov     [esp+36-4], eax
1932
        ret
164 serge 1933
 
221 serge 1934
app_load_cursor:
2434 Serge 1935
        cmp     ecx, OS_BASE
5984 serge 1936
        jae     @f
2434 Serge 1937
        stdcall load_cursor, ecx, edx
1938
        mov     [esp+36-4], eax
5984 serge 1939
@@:
2434 Serge 1940
        ret
164 serge 1941
 
221 serge 1942
app_set_cursor:
2434 Serge 1943
        stdcall set_cursor, ecx
1944
        mov     [esp+36-4], eax
1945
        ret
1 ha 1946
 
233 serge 1947
app_delete_cursor:
2434 Serge 1948
        stdcall delete_cursor, ecx
1949
        mov     [esp+36-4], eax
1950
        ret
1 ha 1951
 
5984 serge 1952
msz:
1953
        mov     edi, [TASK_COUNT]
1954
        movzx   edi, word [WIN_POS + edi*2]
1955
        cmp     edi, [CURRENT_TASK]
1956
        jne     @f
1957
        mov     ax, [MOUSE_SCROLL_H]
1958
        shl     eax, 16
1959
        mov     ax, [MOUSE_SCROLL_V]
1960
        mov     [esp+36-4], eax
1961
        and     [MOUSE_SCROLL_H], word 0
1962
        and     [MOUSE_SCROLL_V], word 0
1963
        ret
1964
@@:
1965
        and     [esp+36-4], dword 0
1966
        ret
1967
 
1 ha 1968
is_input:
1969
 
2434 Serge 1970
        push    edx
1971
        mov     dx, word [midisp]
1972
        in      al, dx
1973
        and     al, 0x80
1974
        pop     edx
1975
        ret
1 ha 1976
 
1977
is_output:
1978
 
2434 Serge 1979
        push    edx
1980
        mov     dx, word [midisp]
1981
        in      al, dx
1982
        and     al, 0x40
1983
        pop     edx
1984
        ret
1 ha 1985
 
1986
 
1987
get_mpu_in:
1988
 
2434 Serge 1989
        push    edx
1990
        mov     dx, word [mididp]
1991
        in      al, dx
1992
        pop     edx
1993
        ret
1 ha 1994
 
1995
 
1996
put_mpu_out:
1997
 
2434 Serge 1998
        push    edx
1999
        mov     dx, word [mididp]
2000
        out     dx, al
2001
        pop     edx
2002
        ret
1 ha 2003
 
2004
 
2005
 
2006
align 4
2007
 
2008
sys_midi:
2434 Serge 2009
        cmp     [mididp], 0
2010
        jnz     sm0
2011
        mov     [esp+36], dword 1
2012
        ret
1276 Lrz 2013
sm0:
2434 Serge 2014
        and     [esp+36], dword 0
2015
        dec     ebx
2016
        jnz     smn1
1276 Lrz 2017
 ;    call setuart
2018
su1:
2434 Serge 2019
        call    is_output
2020
        test    al, al
2021
        jnz     su1
2022
        mov     dx, word [midisp]
2023
        mov     al, 0xff
2024
        out     dx, al
1276 Lrz 2025
su2:
2434 Serge 2026
        mov     dx, word [midisp]
2027
        mov     al, 0xff
2028
        out     dx, al
2029
        call    is_input
2030
        test    al, al
2031
        jnz     su2
2032
        call    get_mpu_in
2033
        cmp     al, 0xfe
2034
        jnz     su2
1276 Lrz 2035
su3:
2434 Serge 2036
        call    is_output
2037
        test    al, al
2038
        jnz     su3
2039
        mov     dx, word [midisp]
2040
        mov     al, 0x3f
2041
        out     dx, al
2042
        ret
1276 Lrz 2043
smn1:
2434 Serge 2044
        dec     ebx
2045
        jnz     smn2
1276 Lrz 2046
sm10:
2434 Serge 2047
        call    get_mpu_in
2048
        call    is_output
2049
        test    al, al
2050
        jnz     sm10
2051
        mov     al, bl
2052
        call    put_mpu_out
2053
        smn2:
2054
        ret
1 ha 2055
 
2056
detect_devices:
2057
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
769 Rus 2058
;include 'detect/commouse.inc'
479 kastigar 2059
;include 'detect/ps2mouse.inc'
1 ha 2060
;include 'detect/dev_fd.inc'
2061
;include 'detect/dev_hdcd.inc'
2062
;include 'detect/sear_par.inc'
2063
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2434 Serge 2064
        ret
1 ha 2065
 
2066
sys_end:
2434 Serge 2067
;--------------------------------------
2068
        cmp     [_display.select_cursor], 0
2069
        je      @f
2070
; restore default cursor before killing
2071
        pusha
2072
        mov     ecx, [current_slot]
2439 Serge 2073
        call    restore_default_cursor_before_killing
2434 Serge 2074
        popa
2075
@@:
2076
;--------------------------------------
3555 Serge 2077
; kill all sockets this process owns
2078
        pusha
2079
        mov     edx, [TASK_BASE]
2080
        mov     edx, [edx+TASKDATA.pid]
6078 serge 2081
        call    socket_process_end
3555 Serge 2082
        popa
2083
;--------------------------------------
2434 Serge 2084
        mov     ecx, [current_slot]
2085
        mov     eax, [ecx+APPDATA.tls_base]
2086
        test    eax, eax
2087
        jz      @F
1220 serge 2088
 
2434 Serge 2089
        stdcall user_free, eax
1220 serge 2090
@@:
2091
 
2434 Serge 2092
        mov     eax, [TASK_BASE]
6240 serge 2093
        mov     [eax+TASKDATA.state], TSTATE_ZOMBIE
3555 Serge 2094
        call    wakeup_osloop
41 mikedld 2095
 
3626 Serge 2096
.waitterm:            ; wait here for termination
2097
        call    change_task
2098
        jmp     .waitterm
2439 Serge 2099
;------------------------------------------------------------------------------
2465 Serge 2100
align 4
2439 Serge 2101
restore_default_cursor_before_killing:
2987 Serge 2102
        pushfd
2103
        cli
2439 Serge 2104
        mov     eax, [def_cursor]
2105
        mov     [ecx+APPDATA.cursor], eax
1 ha 2106
 
2439 Serge 2107
        movzx   eax, word [MOUSE_Y]
2108
        movzx   ebx, word [MOUSE_X]
2465 Serge 2109
        mov     eax, [d_width_calc_area + eax*4]
2110
 
5565 serge 2111
        add     eax, [_display.win_map]
2439 Serge 2112
        movzx   edx, byte [ebx+eax]
2113
        shl     edx, 8
2114
        mov     esi, [edx+SLOT_BASE+APPDATA.cursor]
2465 Serge 2115
 
2116
        cmp     esi, [current_cursor]
2117
        je      @f
2118
 
2439 Serge 2119
        push    esi
2120
        call    [_display.select_cursor]
2121
        mov     [current_cursor], esi
2465 Serge 2122
@@:
2123
        mov     [redrawmouse_unconditional], 1
3555 Serge 2124
        call    wakeup_osloop
2987 Serge 2125
        popfd
2439 Serge 2126
        ret
2127
;------------------------------------------------------------------------------
75 diamond 2128
iglobal
170 serge 2129
align 4
75 diamond 2130
sys_system_table:
2268 Serge 2131
        dd      sysfn_deactivate        ; 1 = deactivate window
1055 Galkov 2132
        dd      sysfn_terminate         ; 2 = terminate thread
2133
        dd      sysfn_activate          ; 3 = activate window
2134
        dd      sysfn_getidletime       ; 4 = get idle time
2135
        dd      sysfn_getcpuclock       ; 5 = get cpu clock
2136
        dd      sysfn_saveramdisk       ; 6 = save ramdisk
2137
        dd      sysfn_getactive         ; 7 = get active window
2138
        dd      sysfn_sound_flag        ; 8 = get/set sound_flag
2139
        dd      sysfn_shutdown          ; 9 = shutdown with parameter
2140
        dd      sysfn_minimize          ; 10 = minimize window
2141
        dd      sysfn_getdiskinfo       ; 11 = get disk subsystem info
2142
        dd      sysfn_lastkey           ; 12 = get last pressed key
2143
        dd      sysfn_getversion        ; 13 = get kernel version
2144
        dd      sysfn_waitretrace       ; 14 = wait retrace
2145
        dd      sysfn_centermouse       ; 15 = center mouse cursor
2146
        dd      sysfn_getfreemem        ; 16 = get free memory size
2147
        dd      sysfn_getallmem         ; 17 = get total memory size
2148
        dd      sysfn_terminate2        ; 18 = terminate thread using PID
2149
                                        ;                 instead of slot
2150
        dd      sysfn_mouse_acceleration; 19 = set/get mouse acceleration
2151
        dd      sysfn_meminfo           ; 20 = get extended memory info
2152
        dd      sysfn_pid_to_slot       ; 21 = get slot number for pid
2153
        dd      sysfn_min_rest_window   ; 22 = minimize and restore any window
2987 Serge 2154
        dd      sysfn_min_windows       ; 23 = minimize all windows
2155
        dd      sysfn_set_screen_sizes  ; 24 = set screen sizes for Vesa
5984 serge 2156
 
2157
        dd      sysfn_zmodif            ; 25 = get/set window z modifier  ;Fantomer
75 diamond 2158
sysfn_num = ($ - sys_system_table)/4
2159
endg
2268 Serge 2160
;------------------------------------------------------------------------------
1 ha 2161
sys_system:
1055 Galkov 2162
        dec     ebx
2163
        cmp     ebx, sysfn_num
2164
        jae     @f
2165
        jmp     dword [sys_system_table + ebx*4]
75 diamond 2166
@@:
1055 Galkov 2167
        ret
2268 Serge 2168
;------------------------------------------------------------------------------
1055 Galkov 2169
sysfn_shutdown:          ; 18.9 = system shutdown
2434 Serge 2170
        cmp     ecx, 1
2171
        jl      exit_for_anyone
2172
        cmp     ecx, 4
2173
        jg      exit_for_anyone
3908 Serge 2174
        mov     [BOOT_VARS+0x9030], cl
748 heavyiron 2175
 
2434 Serge 2176
        mov     eax, [TASK_COUNT]
2177
        mov     [SYS_SHUTDOWN], al
2178
        mov     [shutdown_processes], eax
3555 Serge 2179
        call    wakeup_osloop
2434 Serge 2180
        and     dword [esp+32], 0
748 heavyiron 2181
 exit_for_anyone:
2434 Serge 2182
        ret
1 ha 2183
  uglobal
2434 Serge 2184
   shutdown_processes:
2185
                       dd 0x0
1 ha 2186
  endg
2268 Serge 2187
;------------------------------------------------------------------------------
1055 Galkov 2188
sysfn_terminate:        ; 18.2 = TERMINATE
2987 Serge 2189
        push    ecx
2434 Serge 2190
        cmp     ecx, 2
2191
        jb      noprocessterminate
2192
        mov     edx, [TASK_COUNT]
2193
        cmp     ecx, edx
2194
        ja      noprocessterminate
2195
        mov     eax, [TASK_COUNT]
2196
        shl     ecx, 5
2197
        mov     edx, [ecx+CURRENT_TASK+TASKDATA.pid]
2198
        add     ecx, CURRENT_TASK+TASKDATA.state
2199
        cmp     byte [ecx], 9
2200
        jz      noprocessterminate
3500 Serge 2201
        push    ecx edx
2202
        lea     edx, [(ecx-(CURRENT_TASK and 1FFFFFFFh)-TASKDATA.state)*8+SLOT_BASE]
2203
        call    request_terminate
2204
        pop     edx ecx
2205
        test    eax, eax
2206
        jz      noprocessterminate
2434 Serge 2207
;--------------------------------------
3555 Serge 2208
; terminate all network sockets it used
2209
        pusha
2210
        mov     eax, edx
6078 serge 2211
        call    socket_process_end
3555 Serge 2212
        popa
2213
;--------------------------------------
2434 Serge 2214
        cmp     [_display.select_cursor], 0
2465 Serge 2215
        je      .restore_end
2434 Serge 2216
; restore default cursor before killing
2217
        pusha
2218
        mov     ecx, [esp+32]
2219
        shl     ecx, 8
2439 Serge 2220
        add     ecx, SLOT_BASE
2465 Serge 2221
        mov     eax, [def_cursor]
2222
        cmp     [ecx+APPDATA.cursor], eax
2223
        je      @f
2439 Serge 2224
        call    restore_default_cursor_before_killing
2465 Serge 2225
@@:
2434 Serge 2226
        popa
2465 Serge 2227
.restore_end:
2434 Serge 2228
;--------------------------------------
1 ha 2229
     ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
2434 Serge 2230
        mov     [ecx], byte 3; clear possible i40's
3555 Serge 2231
        call    wakeup_osloop
1 ha 2232
     ;call MEM_Heap_UnLock
2233
 
3555 Serge 2234
        cmp     edx, [application_table_owner]; clear app table stat
2434 Serge 2235
        jne     noatsc
3555 Serge 2236
        call    unlock_application_table
2987 Serge 2237
noatsc:
2238
noprocessterminate:
2239
        add     esp, 4
2434 Serge 2240
        ret
2268 Serge 2241
;------------------------------------------------------------------------------
85 halyavin 2242
sysfn_terminate2:
2243
;lock application_table_status mutex
164 serge 2244
.table_status:
3555 Serge 2245
        call    lock_application_table
2434 Serge 2246
        mov     eax, ecx
2247
        call    pid_to_slot
2248
        test    eax, eax
2249
        jz      .not_found
2250
        mov     ecx, eax
2251
        cli
2252
        call    sysfn_terminate
3555 Serge 2253
        call    unlock_application_table
2434 Serge 2254
        sti
2255
        and     dword [esp+32], 0
2256
        ret
85 halyavin 2257
.not_found:
3555 Serge 2258
        call    unlock_application_table
2434 Serge 2259
        or      dword [esp+32], -1
2260
        ret
2268 Serge 2261
;------------------------------------------------------------------------------
2262
sysfn_deactivate:         ; 18.1 = DEACTIVATE WINDOW
2434 Serge 2263
        cmp     ecx, 2
2264
        jb      .nowindowdeactivate
2265
        cmp     ecx, [TASK_COUNT]
2266
        ja      .nowindowdeactivate
85 halyavin 2267
 
2434 Serge 2268
        movzx   esi, word [WIN_STACK + ecx*2]
2269
        cmp     esi, 1
2270
        je      .nowindowdeactivate ; already deactive
2268 Serge 2271
 
2434 Serge 2272
        mov     edi, ecx
2273
        shl     edi, 5
2274
        add     edi, window_data
2275
        movzx   esi, word [WIN_STACK + ecx * 2]
2276
        lea     esi, [WIN_POS + esi * 2]
2277
        call    window._.window_deactivate
2268 Serge 2278
 
2434 Serge 2279
        call    syscall_display_settings._.calculate_whole_screen
2280
        call    syscall_display_settings._.redraw_whole_screen
2268 Serge 2281
.nowindowdeactivate:
2434 Serge 2282
        ret
3500 Serge 2283
;------------------------------------------------------------------------------
1055 Galkov 2284
sysfn_activate:         ; 18.3 = ACTIVATE WINDOW
2434 Serge 2285
        cmp     ecx, 2
2286
        jb      .nowindowactivate
2287
        cmp     ecx, [TASK_COUNT]
2288
        ja      .nowindowactivate
3500 Serge 2289
;-------------------------------------
2290
@@:
2291
; If the window is captured and moved by the user,
2292
; then you can't change the position in window stack!!!
2293
        mov     al, [mouse.active_sys_window.action]
2294
        and     al, WINDOW_MOVE_AND_RESIZE_FLAGS
2295
        test    al, al
2296
        jz      @f
2297
        call    change_task
2298
        jmp     @b
2299
@@:
2300
;-------------------------------------
2434 Serge 2301
        mov     [window_minimize], 2; restore window if minimized
3555 Serge 2302
        call    wakeup_osloop
105 poddubny 2303
 
2434 Serge 2304
        movzx   esi, word [WIN_STACK + ecx*2]
2305
        cmp     esi, [TASK_COUNT]
2306
        je      .nowindowactivate; already active
105 poddubny 2307
 
2434 Serge 2308
        mov     edi, ecx
2309
        shl     edi, 5
2310
        add     edi, window_data
2311
        movzx   esi, word [WIN_STACK + ecx * 2]
2312
        lea     esi, [WIN_POS + esi * 2]
2313
        call    waredraw
105 poddubny 2314
.nowindowactivate:
2434 Serge 2315
        ret
2268 Serge 2316
;------------------------------------------------------------------------------
5984 serge 2317
align 4
2318
sysfn_zmodif:
2319
;18,25,1 - get z_modif
2320
;18,25,2 - set z_modif
2321
;edx = -1(for current task) or TID
2322
;esi(for 2) = new value z_modif
2323
;return:
2324
;1:   eax = z_modif
2325
;2: eax=0(fail),1(success) for set z_modif
2326
 
2327
        cmp     edx, -1
2328
        jne     @f
2329
        mov     edx, [CURRENT_TASK]
2330
     @@:
2331
        cmp     edx, [TASK_COUNT]
2332
        ja      .fail
2333
        cmp     edx, 1
2334
        je      .fail
2335
 
2336
        mov     eax, edx
2337
        shl     edx, 5
2338
 
2339
        cmp     [edx + CURRENT_TASK + TASKDATA.state], 9
2340
        je      .fail
2341
 
2342
        cmp     ecx, 1
2343
        jnz     .set_zmod
2344
 
2345
        mov     al, [edx + window_data + WDATA.z_modif]
2346
        jmp     .exit
2347
 
2348
.set_zmod:
2349
        cmp     ecx, 2
2350
        jnz     .fail
2351
 
2352
        mov     ebx, esi
2353
        mov     esi, eax
2354
 
2355
        cmp     bl, ZPOS_ALWAYS_TOP
2356
        jg      .fail
2357
 
2358
        mov     [edx + window_data + WDATA.z_modif], bl
2359
 
2360
        mov     eax, [edx + window_data + WDATA.box.left]
2361
        mov     ebx, [edx + window_data + WDATA.box.top]
2362
        mov     ecx, [edx + window_data + WDATA.box.width]
2363
        mov     edx, [edx + window_data + WDATA.box.height]
2364
        add     ecx, eax
2365
        add     edx, ebx
2366
        call    window._.set_screen
2367
        call    window._.set_top_wnd
2368
        call    window._.redraw_top_wnd
2369
 
2370
        shl     esi, 5
2371
        mov     [esi + window_data + WDATA.fl_redraw], 1
2372
 
2373
 
2374
        mov     eax, 1
2375
        jmp     .exit
2376
.fail:
2377
        xor     eax, eax
2378
.exit:
2379
        mov     [esp+32], eax
2380
        ret
2381
 
2382
;------------------------------------------------------------------------------
1055 Galkov 2383
sysfn_getidletime:              ; 18.4 = GET IDLETIME
3555 Serge 2384
        mov     eax, [CURRENT_TASK+32+TASKDATA.cpu_usage]
2434 Serge 2385
        mov     [esp+32], eax
2386
        ret
2268 Serge 2387
;------------------------------------------------------------------------------
1055 Galkov 2388
sysfn_getcpuclock:              ; 18.5 = GET TSC/SEC
3500 Serge 2389
        mov     eax, dword [cpu_freq]
2434 Serge 2390
        mov     [esp+32], eax
2391
        ret
2268 Serge 2392
;------------------------------------------------------------------------------
3500 Serge 2393
get_cpu_freq:
2394
        mov     eax, dword [cpu_freq]
2395
        mov     edx, dword [cpu_freq+4]
2396
        ret
1 ha 2397
;  SAVE ramdisk to /hd/1/menuet.img
2398
;!!!!!!!!!!!!!!!!!!!!!!!!
2399
   include 'blkdev/rdsave.inc'
2400
;!!!!!!!!!!!!!!!!!!!!!!!!
2268 Serge 2401
;------------------------------------------------------------------------------
1232 Lrz 2402
align 4
1055 Galkov 2403
sysfn_getactive:        ; 18.7 = get active window
2434 Serge 2404
        mov     eax, [TASK_COUNT]
2405
        movzx   eax, word [WIN_POS + eax*2]
2406
        mov     [esp+32], eax
2407
        ret
2268 Serge 2408
;------------------------------------------------------------------------------
1055 Galkov 2409
sysfn_sound_flag:       ; 18.8 = get/set sound_flag
1232 Lrz 2410
;     cmp  ecx,1
2434 Serge 2411
        dec     ecx
2412
        jnz     nogetsoundflag
2413
        movzx   eax, byte [sound_flag]; get sound_flag
2414
        mov     [esp+32], eax
2415
        ret
1 ha 2416
 nogetsoundflag:
1232 Lrz 2417
;     cmp  ecx,2
2434 Serge 2418
        dec     ecx
2419
        jnz     nosoundflag
2420
        xor     byte [sound_flag], 1
75 diamond 2421
 nosoundflag:
2434 Serge 2422
        ret
2268 Serge 2423
;------------------------------------------------------------------------------
1055 Galkov 2424
sysfn_minimize:         ; 18.10 = minimize window
2434 Serge 2425
        mov     [window_minimize], 1
3555 Serge 2426
        call    wakeup_osloop
2434 Serge 2427
        ret
2268 Serge 2428
;------------------------------------------------------------------------------
1232 Lrz 2429
align 4
1055 Galkov 2430
sysfn_getdiskinfo:      ; 18.11 = get disk info table
2434 Serge 2431
        dec     ecx
5201 serge 2432
        jnz     .exit
2433
.small_table:
2434 Serge 2434
        mov     edi, edx
2435
        mov     esi, DRIVE_DATA
5201 serge 2436
        mov     ecx, DRIVE_DATA_SIZE ;10
2434 Serge 2437
        cld
5201 serge 2438
        rep movsb
2439
.exit:
2434 Serge 2440
        ret
2268 Serge 2441
;------------------------------------------------------------------------------
1055 Galkov 2442
sysfn_lastkey:          ; 18.12 = return 0 (backward compatibility)
2443
        and     dword [esp+32], 0
2444
        ret
2268 Serge 2445
;------------------------------------------------------------------------------
1055 Galkov 2446
sysfn_getversion:       ; 18.13 = get kernel ID and version
2434 Serge 2447
        mov     edi, ecx
2448
        mov     esi, version_inf
2449
        mov     ecx, version_end-version_inf
2450
        rep movsb
2451
        ret
2268 Serge 2452
;------------------------------------------------------------------------------
75 diamond 2453
sysfn_waitretrace:     ; 18.14 = sys wait retrace
41 mikedld 2454
     ;wait retrace functions
2455
 sys_wait_retrace:
2434 Serge 2456
        mov     edx, 0x3da
41 mikedld 2457
 WaitRetrace_loop:
2434 Serge 2458
        in      al, dx
2459
        test    al, 1000b
2460
        jz      WaitRetrace_loop
2461
        and     [esp+32], dword 0
2462
        ret
2268 Serge 2463
;------------------------------------------------------------------------------
1232 Lrz 2464
align 4
1055 Galkov 2465
sysfn_centermouse:      ; 18.15 = mouse centered
5565 serge 2466
        mov     eax, [_display.width]
2434 Serge 2467
        shr     eax, 1
2468
        mov     [MOUSE_X], ax
5565 serge 2469
        mov     eax, [_display.height]
2434 Serge 2470
        shr     eax, 1
2471
        mov     [MOUSE_Y], ax
3555 Serge 2472
        call    wakeup_osloop
2434 Serge 2473
        xor     eax, eax
2474
        and     [esp+32], eax
2475
        ret
2268 Serge 2476
;------------------------------------------------------------------------------
5984 serge 2477
sysfn_mouse_acceleration:       ; 18.19 = set/get mouse features
2478
        cmp     ecx, 8
2479
        jnc     @f
2480
        jmp     dword [.table+ecx*4]
2481
.get_mouse_acceleration:
2434 Serge 2482
        xor     eax, eax
2483
        mov     ax, [mouse_speed_factor]
2484
        mov     [esp+32], eax
2485
        ret
5984 serge 2486
.set_mouse_acceleration:
2434 Serge 2487
        mov     [mouse_speed_factor], dx
2488
        ret
5984 serge 2489
.get_mouse_delay:
2490
        xor     eax, eax
2491
        mov     al, [mouse_delay]
2434 Serge 2492
        mov     [esp+32], eax
2493
        ret
5984 serge 2494
.set_mouse_delay:
2495
        mov     [mouse_delay], dl
2496
@@:
2434 Serge 2497
        ret
5984 serge 2498
.set_pointer_position:
5565 serge 2499
        cmp     dx, word[_display.height]
5984 serge 2500
        jae     @b
2434 Serge 2501
        rol     edx, 16
5565 serge 2502
        cmp     dx, word[_display.width]
5984 serge 2503
        jae     @b
2434 Serge 2504
        mov     [MOUSE_X], edx
5201 serge 2505
        mov     [mouse_active], 1
5984 serge 2506
        jmp     wakeup_osloop
2507
.set_mouse_button:
2508
        mov     [BTN_DOWN], edx
2434 Serge 2509
        mov     [mouse_active], 1
5984 serge 2510
        jmp     wakeup_osloop
2511
.get_doubleclick_delay:
2512
        xor     eax, eax
2513
        mov     al, [mouse_doubleclick_delay]
2514
        mov     [esp+32], eax
2434 Serge 2515
        ret
5984 serge 2516
.set_doubleclick_delay:
2517
        mov     [mouse_doubleclick_delay], dl
2518
        ret
2519
align 4
2520
.table:
2521
dd      .get_mouse_acceleration
2522
dd      .set_mouse_acceleration
2523
dd      .get_mouse_delay
2524
dd      .set_mouse_delay
2525
dd      .set_pointer_position
2526
dd      .set_mouse_button
2527
dd      .get_doubleclick_delay
2528
dd      .set_doubleclick_delay
2268 Serge 2529
;------------------------------------------------------------------------------
75 diamond 2530
sysfn_getfreemem:
2434 Serge 2531
        mov     eax, [pg_data.pages_free]
2532
        shl     eax, 2
2533
        mov     [esp+32], eax
2534
        ret
2987 Serge 2535
;------------------------------------------------------------------------------
75 diamond 2536
sysfn_getallmem:
2434 Serge 2537
        mov     eax, [MEM_AMOUNT]
2538
        shr     eax, 10
2539
        mov     [esp+32], eax
2540
        ret
2987 Serge 2541
;------------------------------------------------------------------------------
608 alver 2542
sysfn_pid_to_slot:
2434 Serge 2543
        mov     eax, ecx
2544
        call    pid_to_slot
2545
        mov     [esp+32], eax
2546
        ret
2987 Serge 2547
;------------------------------------------------------------------------------
608 alver 2548
sysfn_min_rest_window:
2434 Serge 2549
        pushad
2550
        mov     eax, edx ; ebx - operating
2551
        shr     ecx, 1
2552
        jnc     @f
2553
        call    pid_to_slot
608 alver 2554
@@:
2434 Serge 2555
        or      eax, eax ; eax - number of slot
2556
        jz      .error
2557
        cmp     eax, 255    ; varify maximal slot number
2558
        ja      .error
2559
        movzx   eax, word [WIN_STACK + eax*2]
2560
        shr     ecx, 1
2561
        jc      .restore
608 alver 2562
 ; .minimize:
2434 Serge 2563
        call    minimize_window
2564
        jmp     .exit
608 alver 2565
.restore:
2434 Serge 2566
        call    restore_minimized_window
608 alver 2567
.exit:
2434 Serge 2568
        popad
2569
        xor     eax, eax
2570
        mov     [esp+32], eax
2571
        ret
608 alver 2572
.error:
2434 Serge 2573
        popad
2574
        xor     eax, eax
2575
        dec     eax
2576
        mov     [esp+32], eax
2577
        ret
2987 Serge 2578
;------------------------------------------------------------------------------
2579
sysfn_min_windows:
2580
        call    minimize_all_window
2581
        mov     [esp+32], eax
2582
        call    change_task
2583
        ret
2584
;------------------------------------------------------------------------------
2585
sysfn_set_screen_sizes:
2586
        cmp     [SCR_MODE], word 0x13
2587
        jbe     .exit
608 alver 2588
 
2987 Serge 2589
        cmp     [_display.select_cursor], select_cursor
2590
        jne     .exit
2591
 
2592
        cmp     ecx, [display_width_standard]
2593
        ja      .exit
2594
 
2595
        cmp     edx, [display_height_standard]
2596
        ja      .exit
2597
 
2598
        pushfd
2599
        cli
2600
        mov     eax, ecx
5565 serge 2601
        mov     ecx, [_display.lfb_pitch]
2987 Serge 2602
        mov     [_display.width], eax
5201 serge 2603
        dec     eax
2987 Serge 2604
        mov     [_display.height], edx
5201 serge 2605
        dec     edx
2987 Serge 2606
; eax - new Screen_Max_X
2607
; edx - new Screen_Max_Y
2608
        mov     [do_not_touch_winmap], 1
2609
        call    set_screen
2610
        mov     [do_not_touch_winmap], 0
2611
        popfd
2612
        call    change_task
2613
.exit:
2614
        ret
2615
;------------------------------------------------------------------------------
41 mikedld 2616
uglobal
2617
screen_workarea RECT
2987 Serge 2618
display_width_standard dd 0
2619
display_height_standard dd 0
2620
do_not_touch_winmap db 0
1 ha 2621
window_minimize db 0
1055 Galkov 2622
sound_flag      db 0
2987 Serge 2623
 
41 mikedld 2624
endg
1 ha 2625
 
2130 serge 2626
UID_NONE=0
2627
UID_MENUETOS=1   ;official
2628
UID_KOLIBRI=2    ;russian
2629
 
41 mikedld 2630
iglobal
2631
version_inf:
3908 Serge 2632
        db 0,7,7,0  ; version 0.7.7.0
2633
        db 0
3500 Serge 2634
.rev    dd __REV__
41 mikedld 2635
version_end:
2636
endg
2987 Serge 2637
;------------------------------------------------------------------------------
2638
align 4
1 ha 2639
sys_cachetodiskette:
1055 Galkov 2640
        cmp     ebx, 1
4287 Serge 2641
        jb      .no_floppy_save
1055 Galkov 2642
        cmp     ebx, 2
4287 Serge 2643
        ja      .no_floppy_save
1055 Galkov 2644
        call    save_image
4287 Serge 2645
        mov     [esp + 32], eax
2646
        ret
2647
.no_floppy_save:
1055 Galkov 2648
        mov     [esp + 32], dword 1
2649
        ret
2987 Serge 2650
;------------------------------------------------------------------------------
1 ha 2651
uglobal
2652
;  bgrchanged  dd  0x0
1071 diamond 2653
align 4
2654
bgrlockpid dd 0
546 diamond 2655
bgrlock db 0
1 ha 2656
endg
2987 Serge 2657
;------------------------------------------------------------------------------
2658
align 4
1 ha 2659
sys_background:
2434 Serge 2660
        cmp     ebx, 1                     ; BACKGROUND SIZE
2661
        jnz     nosb1
2662
        test    ecx, ecx
2663
        jz      sbgrr
2987 Serge 2664
 
2434 Serge 2665
        test    edx, edx
2666
        jz      sbgrr
2987 Serge 2667
;--------------------------------------
2668
align 4
546 diamond 2669
@@:
1071 diamond 2670
;;Maxis use atomic bts for mutexes  4.4.2009
2671
        bts     dword [bgrlock], 0
2672
        jnc     @f
1055 Galkov 2673
        call    change_task
2674
        jmp     @b
2987 Serge 2675
;--------------------------------------
2676
align 4
546 diamond 2677
@@:
2434 Serge 2678
        mov     [BgrDataWidth], ecx
2679
        mov     [BgrDataHeight], edx
1 ha 2680
;    mov   [bgrchanged],1
469 serge 2681
 
2434 Serge 2682
        pushad
469 serge 2683
; return memory for old background
1107 diamond 2684
        mov     eax, [img_background]
2685
        cmp     eax, static_background_data
2686
        jz      @f
2687
        stdcall kernel_free, eax
2987 Serge 2688
;--------------------------------------
2689
align 4
1107 diamond 2690
@@:
469 serge 2691
; calculate RAW size
2434 Serge 2692
        xor     eax, eax
2693
        inc     eax
2694
        cmp     [BgrDataWidth], eax
2695
        jae     @f
2696
        mov     [BgrDataWidth], eax
2987 Serge 2697
;--------------------------------------
2698
align 4
469 serge 2699
@@:
2434 Serge 2700
        cmp     [BgrDataHeight], eax
2701
        jae     @f
2702
        mov     [BgrDataHeight], eax
2987 Serge 2703
;--------------------------------------
2704
align 4
469 serge 2705
@@:
2434 Serge 2706
        mov     eax, [BgrDataWidth]
2707
        imul    eax, [BgrDataHeight]
2708
        lea     eax, [eax*3]
2465 Serge 2709
; it is reserved with aligned to the boundary of 4 KB pages,
2710
; otherwise there may be exceptions a page fault for vesa20_drawbackground_tiled
2711
; because the 32 bit read is used for  high performance: "mov eax,[esi]"
2712
        shr     eax, 12
2713
        inc     eax
2714
        shl     eax, 12
2434 Serge 2715
        mov     [mem_BACKGROUND], eax
469 serge 2716
; get memory for new background
2434 Serge 2717
        stdcall kernel_alloc, eax
2718
        test    eax, eax
2719
        jz      .memfailed
2720
        mov     [img_background], eax
2721
        jmp     .exit
2987 Serge 2722
;--------------------------------------
2723
align 4
1107 diamond 2724
.memfailed:
2725
; revert to static monotone data
2726
        mov     [img_background], static_background_data
2727
        xor     eax, eax
2728
        inc     eax
2729
        mov     [BgrDataWidth], eax
2730
        mov     [BgrDataHeight], eax
2731
        mov     [mem_BACKGROUND], 4
2987 Serge 2732
;--------------------------------------
2733
align 4
1107 diamond 2734
.exit:
2434 Serge 2735
        popad
1055 Galkov 2736
        mov     [bgrlock], 0
2987 Serge 2737
;--------------------------------------
2738
align 4
2739
sbgrr:
2434 Serge 2740
        ret
2987 Serge 2741
;------------------------------------------------------------------------------
2742
align 4
875 serge 2743
nosb1:
2434 Serge 2744
        cmp     ebx, 2                     ; SET PIXEL
2745
        jnz     nosb2
875 serge 2746
 
2434 Serge 2747
        mov     eax, [img_background]
2748
        test    ecx, ecx
2749
        jz      @f
2750
        cmp     eax, static_background_data
2751
        jz      .ret
2987 Serge 2752
;--------------------------------------
2753
align 4
1107 diamond 2754
@@:
2434 Serge 2755
        mov     ebx, [mem_BACKGROUND]
2756
        add     ebx, 4095
2757
        and     ebx, -4096
2758
        sub     ebx, 4
2759
        cmp     ecx, ebx
2760
        ja      .ret
875 serge 2761
 
2434 Serge 2762
        mov     ebx, [eax+ecx]
2763
        and     ebx, 0xFF000000;255*256*256*256
2764
        and     edx, 0x00FFFFFF;255*256*256+255*256+255
2765
        add     edx, ebx
2766
        mov     [eax+ecx], edx
2987 Serge 2767
;--------------------------------------
2768
align 4
1107 diamond 2769
.ret:
2434 Serge 2770
        ret
2987 Serge 2771
;------------------------------------------------------------------------------
2772
align 4
875 serge 2773
nosb2:
2434 Serge 2774
        cmp     ebx, 3                     ; DRAW BACKGROUND
2775
        jnz     nosb3
2987 Serge 2776
;--------------------------------------
2777
align 4
1 ha 2778
draw_background_temp:
2434 Serge 2779
        mov     [background_defined], 1
2780
        call    force_redraw_background
2987 Serge 2781
;--------------------------------------
2782
align 4
2783
nosb31:
2434 Serge 2784
        ret
2987 Serge 2785
;------------------------------------------------------------------------------
2786
align 4
2787
nosb3:
2434 Serge 2788
        cmp     ebx, 4                     ; TILED / STRETCHED
2789
        jnz     nosb4
2790
        cmp     ecx, [BgrDrawMode]
2791
        je      nosb41
2792
        mov     [BgrDrawMode], ecx
2987 Serge 2793
;--------------------------------------
2794
align 4
2795
nosb41:
2434 Serge 2796
        ret
2987 Serge 2797
;------------------------------------------------------------------------------
2798
align 4
2799
nosb4:
2434 Serge 2800
        cmp     ebx, 5                     ; BLOCK MOVE TO BGR
2801
        jnz     nosb5
2802
        cmp     [img_background], static_background_data
2803
        jnz     @f
2804
        test    edx, edx
2805
        jnz     .fin
2806
        cmp     esi, 4
2807
        ja      .fin
2987 Serge 2808
;--------------------------------------
2809
align 4
2810
@@:
1 ha 2811
  ; bughere
2434 Serge 2812
        mov     eax, ecx
2813
        mov     ebx, edx
2814
        add     ebx, [img_background];IMG_BACKGROUND
2815
        mov     ecx, esi
2816
        call    memmove
2987 Serge 2817
;--------------------------------------
2818
align 4
2819
.fin:
2434 Serge 2820
        ret
2987 Serge 2821
;------------------------------------------------------------------------------
2822
align 4
2823
nosb5:
1055 Galkov 2824
        cmp     ebx, 6
2825
        jnz     nosb6
2987 Serge 2826
;--------------------------------------
2827
align 4
1071 diamond 2828
;;Maxis use atomic bts for mutex 4.4.2009
546 diamond 2829
@@:
1073 heavyiron 2830
        bts     dword [bgrlock], 0
1071 diamond 2831
        jnc     @f
1055 Galkov 2832
        call    change_task
2833
        jmp     @b
2987 Serge 2834
;--------------------------------------
2835
align 4
546 diamond 2836
@@:
1055 Galkov 2837
        mov     eax, [CURRENT_TASK]
2838
        mov     [bgrlockpid], eax
1107 diamond 2839
        cmp     [img_background], static_background_data
2840
        jz      .nomem
1055 Galkov 2841
        stdcall user_alloc, [mem_BACKGROUND]
2842
        mov     [esp+32], eax
2843
        test    eax, eax
2844
        jz      .nomem
2845
        mov     ebx, eax
2846
        shr     ebx, 12
2847
        or      dword [page_tabs+(ebx-1)*4], DONT_FREE_BLOCK
2848
        mov     esi, [img_background]
2849
        shr     esi, 12
2850
        mov     ecx, [mem_BACKGROUND]
2851
        add     ecx, 0xFFF
2852
        shr     ecx, 12
2987 Serge 2853
;--------------------------------------
2854
align 4
546 diamond 2855
.z:
1055 Galkov 2856
        mov     eax, [page_tabs+ebx*4]
2857
        test    al, 1
2858
        jz      @f
2859
        call    free_page
2987 Serge 2860
;--------------------------------------
2861
align 4
546 diamond 2862
@@:
1055 Galkov 2863
        mov     eax, [page_tabs+esi*4]
5565 serge 2864
        or      al, PG_UWR
1055 Galkov 2865
        mov     [page_tabs+ebx*4], eax
2866
        mov     eax, ebx
2867
        shl     eax, 12
2868
        invlpg  [eax]
2869
        inc     ebx
2870
        inc     esi
2871
        loop    .z
2872
        ret
2987 Serge 2873
;--------------------------------------
2874
align 4
546 diamond 2875
.nomem:
1055 Galkov 2876
        and     [bgrlockpid], 0
2877
        mov     [bgrlock], 0
2987 Serge 2878
;------------------------------------------------------------------------------
2879
align 4
546 diamond 2880
nosb6:
1055 Galkov 2881
        cmp     ebx, 7
2882
        jnz     nosb7
2883
        cmp     [bgrlock], 0
2884
        jz      .err
2885
        mov     eax, [CURRENT_TASK]
2886
        cmp     [bgrlockpid], eax
2887
        jnz     .err
2888
        mov     eax, ecx
2889
        mov     ebx, ecx
2890
        shr     eax, 12
2891
        mov     ecx, [page_tabs+(eax-1)*4]
2892
        test    cl, USED_BLOCK+DONT_FREE_BLOCK
2893
        jz      .err
2894
        jnp     .err
2895
        push    eax
2896
        shr     ecx, 12
1312 diamond 2897
        dec     ecx
2987 Serge 2898
;--------------------------------------
2899
align 4
546 diamond 2900
@@:
1055 Galkov 2901
        and     dword [page_tabs+eax*4], 0
2902
        mov     edx, eax
2903
        shl     edx, 12
2434 Serge 2904
        push    eax
1055 Galkov 2905
        invlpg  [edx]
2434 Serge 2906
        pop     eax
1055 Galkov 2907
        inc     eax
2908
        loop    @b
2909
        pop     eax
2910
        and     dword [page_tabs+(eax-1)*4], not DONT_FREE_BLOCK
2911
        stdcall user_free, ebx
2912
        mov     [esp+32], eax
2913
        and     [bgrlockpid], 0
2914
        mov     [bgrlock], 0
2915
        ret
2987 Serge 2916
;--------------------------------------
2917
align 4
546 diamond 2918
.err:
1055 Galkov 2919
        and     dword [esp+32], 0
2920
        ret
2987 Serge 2921
;------------------------------------------------------------------------------
2922
align 4
2923
nosb7:
2924
        cmp     ebx, 8
2925
        jnz     nosb8
546 diamond 2926
 
3555 Serge 2927
        mov     ecx, [current_slot]
2928
        xor     eax, eax
2929
        xchg    eax, [ecx+APPDATA.draw_bgr_x]
2987 Serge 2930
        mov     [esp + 32], eax ; eax = [left]*65536 + [right]
3555 Serge 2931
        xor     eax, eax
2932
        xchg    eax, [ecx+APPDATA.draw_bgr_y]
2987 Serge 2933
        mov     [esp + 20], eax ; ebx = [top]*65536 + [bottom]
2434 Serge 2934
        ret
2987 Serge 2935
;------------------------------------------------------------------------------
2936
align 4
2937
nosb8:
2938
        cmp     ebx, 9
2939
        jnz     nosb9
2940
; ecx = [left]*65536 + [right]
2941
; edx = [top]*65536 + [bottom]
5565 serge 2942
        mov     eax, [_display.width]
2943
        mov     ebx, [_display.height]
2944
        dec     eax
2945
        dec     ebx
2987 Serge 2946
; check [right]
2947
        cmp     cx, ax
5201 serge 2948
        ja      .exit
2987 Serge 2949
; check [left]
2950
        ror     ecx, 16
2951
        cmp     cx, ax
5201 serge 2952
        ja      .exit
2987 Serge 2953
; check [bottom]
2954
        cmp     dx, bx
5201 serge 2955
        ja      .exit
2987 Serge 2956
; check [top]
2957
        ror     edx, 16
2958
        cmp     dx, bx
5201 serge 2959
        ja      .exit
1 ha 2960
 
2987 Serge 2961
        movzx   eax, cx  ; [left]
2962
        movzx   ebx, dx  ; [top]
2963
 
2964
        shr     ecx, 16 ; [right]
2965
        shr     edx, 16 ; [bottom]
2966
 
2967
        mov     [background_defined], 1
2968
 
2969
        mov     [draw_data+32 + RECT.left], eax
2970
        mov     [draw_data+32 + RECT.top], ebx
2971
 
2972
        mov     [draw_data+32 + RECT.right], ecx
2973
        mov     [draw_data+32 + RECT.bottom], edx
2974
 
2975
        inc     byte[REDRAW_BACKGROUND]
3555 Serge 2976
        call    wakeup_osloop
2987 Serge 2977
;--------------------------------------
2978
align 4
2979
.exit:
2980
        ret
2981
;------------------------------------------------------------------------------
2982
align 4
2983
nosb9:
2984
        ret
2985
;------------------------------------------------------------------------------
2986
align 4
2987
uglobal
2988
  BG_Rect_X_left_right  dd   0x0
2989
  BG_Rect_Y_top_bottom  dd   0x0
2990
endg
2991
;------------------------------------------------------------------------------
2992
align 4
709 diamond 2993
force_redraw_background:
2434 Serge 2994
        and     [draw_data+32 + RECT.left], 0
2995
        and     [draw_data+32 + RECT.top], 0
2996
        push    eax ebx
5565 serge 2997
        mov     eax, [_display.width]
2998
        mov     ebx, [_display.height]
2999
        dec     eax
3000
        dec     ebx
2434 Serge 3001
        mov     [draw_data+32 + RECT.right], eax
3002
        mov     [draw_data+32 + RECT.bottom], ebx
3003
        pop     ebx eax
3004
        inc     byte[REDRAW_BACKGROUND]
3555 Serge 3005
        call    wakeup_osloop
2434 Serge 3006
        ret
2987 Serge 3007
;------------------------------------------------------------------------------
1 ha 3008
align 4
3009
sys_getbackground:
1304 Lrz 3010
;    cmp   eax,1                                  ; SIZE
2434 Serge 3011
        dec     ebx
3012
        jnz     nogb1
3013
        mov     eax, [BgrDataWidth]
3014
        shl     eax, 16
3555 Serge 3015
        mov     ax, word [BgrDataHeight]
2434 Serge 3016
        mov     [esp+32], eax
3017
        ret
2987 Serge 3018
;------------------------------------------------------------------------------
3019
align 4
875 serge 3020
nogb1:
1304 Lrz 3021
;    cmp   eax,2                                  ; PIXEL
2434 Serge 3022
        dec     ebx
3023
        jnz     nogb2
875 serge 3024
 
1107 diamond 3025
        mov     eax, [img_background]
1304 Lrz 3026
        test    ecx, ecx
1107 diamond 3027
        jz      @f
3028
        cmp     eax, static_background_data
3029
        jz      .ret
2987 Serge 3030
;--------------------------------------
3031
align 4
1107 diamond 3032
@@:
2434 Serge 3033
        mov     ebx, [mem_BACKGROUND]
3034
        add     ebx, 4095
3035
        and     ebx, -4096
3036
        sub     ebx, 4
3037
        cmp     ecx, ebx
3038
        ja      .ret
875 serge 3039
 
2434 Serge 3040
        mov     eax, [ecx+eax]
469 serge 3041
 
2434 Serge 3042
        and     eax, 0xFFFFFF
3043
        mov     [esp+32], eax
2987 Serge 3044
;--------------------------------------
3045
align 4
1107 diamond 3046
.ret:
2434 Serge 3047
        ret
2987 Serge 3048
;------------------------------------------------------------------------------
3049
align 4
3050
nogb2:
1 ha 3051
 
1304 Lrz 3052
;    cmp   eax,4                                  ; TILED / STRETCHED
2434 Serge 3053
        dec     ebx
3054
        dec     ebx
3055
        jnz     nogb4
3056
        mov     eax, [BgrDrawMode]
2987 Serge 3057
;--------------------------------------
3058
align 4
3059
nogb4:
2434 Serge 3060
        mov     [esp+32], eax
3061
        ret
2987 Serge 3062
;------------------------------------------------------------------------------
1 ha 3063
align 4
3064
sys_getkey:
2434 Serge 3065
        mov     [esp + 32], dword 1
1055 Galkov 3066
        ; test main buffer
3067
        mov     ebx, [CURRENT_TASK]                          ; TOP OF WINDOW STACK
3068
        movzx   ecx, word [WIN_STACK + ebx * 2]
3069
        mov     edx, [TASK_COUNT]
3070
        cmp     ecx, edx
3071
        jne     .finish
3072
        cmp     [KEY_COUNT], byte 0
3073
        je      .finish
5201 serge 3074
        movzx   ax, byte [KEY_BUFF + 120 + 2]
1055 Galkov 3075
        shl     eax, 8
5201 serge 3076
        mov     al, byte [KEY_BUFF]
3077
        shl     eax, 8
1055 Galkov 3078
        push    eax
3079
        dec     byte [KEY_COUNT]
3080
        and     byte [KEY_COUNT], 127
3081
        movzx   ecx, byte [KEY_COUNT]
3082
        add     ecx, 2
3083
        mov     eax, KEY_BUFF + 1
3084
        mov     ebx, KEY_BUFF
3085
        call    memmove
5201 serge 3086
        add     eax, 120 + 2
3087
        add     ebx, 120 + 2
3088
        call    memmove
1055 Galkov 3089
        pop     eax
2987 Serge 3090
;--------------------------------------
3091
align 4
92 diamond 3092
.ret_eax:
1055 Galkov 3093
        mov     [esp + 32], eax
3094
        ret
2987 Serge 3095
;--------------------------------------
3096
align 4
671 Ghost 3097
.finish:
92 diamond 3098
; test hotkeys buffer
1055 Galkov 3099
        mov     ecx, hotkey_buffer
2987 Serge 3100
;--------------------------------------
3101
align 4
92 diamond 3102
@@:
1055 Galkov 3103
        cmp     [ecx], ebx
3104
        jz      .found
3105
        add     ecx, 8
3106
        cmp     ecx, hotkey_buffer + 120 * 8
3107
        jb      @b
3108
        ret
2987 Serge 3109
;--------------------------------------
3110
align 4
92 diamond 3111
.found:
1055 Galkov 3112
        mov     ax, [ecx + 6]
3113
        shl     eax, 16
3114
        mov     ah, [ecx + 4]
3115
        mov     al, 2
3116
        and     dword [ecx + 4], 0
3117
        and     dword [ecx], 0
3118
        jmp     .ret_eax
2987 Serge 3119
;------------------------------------------------------------------------------
1 ha 3120
align 4
3121
sys_getbutton:
1055 Galkov 3122
        mov     ebx, [CURRENT_TASK]                         ; TOP OF WINDOW STACK
3123
        mov     [esp + 32], dword 1
3124
        movzx   ecx, word [WIN_STACK + ebx * 2]
3125
        mov     edx, [TASK_COUNT] ; less than 256 processes
3126
        cmp     ecx, edx
3127
        jne     .exit
3128
        movzx   eax, byte [BTN_COUNT]
3129
        test    eax, eax
3130
        jz      .exit
3131
        mov     eax, [BTN_BUFF]
1391 mikedld 3132
        and     al, 0xFE                                    ; delete left button bit
1055 Galkov 3133
        mov     [BTN_COUNT], byte 0
3134
        mov     [esp + 32], eax
2987 Serge 3135
;--------------------------------------
3136
align 4
671 Ghost 3137
.exit:
1055 Galkov 3138
        ret
2987 Serge 3139
;------------------------------------------------------------------------------
1 ha 3140
align 4
3141
sys_cpuusage:
3142
 
3143
;  RETURN:
3144
;
3145
;  +00 dword     process cpu usage
3146
;  +04  word     position in windowing stack
3147
;  +06  word     windowing stack value at current position (cpu nro)
3148
;  +10 12 bytes  name
3149
;  +22 dword     start in mem
3150
;  +26 dword     used mem
3151
;  +30 dword     PID , process idenfification number
3152
;
3153
 
2434 Serge 3154
        cmp     ecx, -1 ; who am I ?
3155
        jne     .no_who_am_i
3156
        mov     ecx, [CURRENT_TASK]
684 diamond 3157
  .no_who_am_i:
1055 Galkov 3158
        cmp     ecx, max_processes
3159
        ja      .nofillbuf
1 ha 3160
 
684 diamond 3161
; +4: word: position of the window of thread in the window stack
1055 Galkov 3162
        mov     ax, [WIN_STACK + ecx * 2]
3163
        mov     [ebx+4], ax
684 diamond 3164
; +6: word: number of the thread slot, which window has in the window stack
3165
;           position ecx (has no relation to the specific thread)
1055 Galkov 3166
        mov     ax, [WIN_POS + ecx * 2]
3167
        mov     [ebx+6], ax
1 ha 3168
 
1055 Galkov 3169
        shl     ecx, 5
1 ha 3170
 
684 diamond 3171
; +0: dword: memory usage
1055 Galkov 3172
        mov     eax, [ecx+CURRENT_TASK+TASKDATA.cpu_usage]
3173
        mov     [ebx], eax
684 diamond 3174
; +10: 11 bytes: name of the process
1055 Galkov 3175
        push    ecx
3176
        lea     eax, [ecx*8+SLOT_BASE+APPDATA.app_name]
3177
        add     ebx, 10
3178
        mov     ecx, 11
3179
        call    memmove
3180
        pop     ecx
1 ha 3181
 
684 diamond 3182
; +22: address of the process in memory
3183
; +26: size of used memory - 1
1055 Galkov 3184
        push    edi
3185
        lea     edi, [ebx+12]
3186
        xor     eax, eax
3187
        mov     edx, 0x100000*16
3188
        cmp     ecx, 1 shl 5
3189
        je      .os_mem
5201 serge 3190
        mov     edx, [SLOT_BASE+ecx*8+APPDATA.process]
3191
        mov     edx, [edx+PROC.mem_used]
1055 Galkov 3192
        mov     eax, std_application_base_address
684 diamond 3193
.os_mem:
1055 Galkov 3194
        stosd
3195
        lea     eax, [edx-1]
3196
        stosd
1 ha 3197
 
684 diamond 3198
; +30: PID/TID
1055 Galkov 3199
        mov     eax, [ecx+CURRENT_TASK+TASKDATA.pid]
3200
        stosd
1 ha 3201
 
3202
    ; window position and size
1055 Galkov 3203
        push    esi
3204
        lea     esi, [ecx + window_data + WDATA.box]
3205
        movsd
3206
        movsd
3207
        movsd
3208
        movsd
1 ha 3209
 
3210
    ; Process state (+50)
1055 Galkov 3211
        mov     eax, dword [ecx+CURRENT_TASK+TASKDATA.state]
3212
        stosd
1 ha 3213
 
138 mikedld 3214
    ; Window client area box
1055 Galkov 3215
        lea     esi, [ecx*8 + SLOT_BASE + APPDATA.wnd_clientbox]
3216
        movsd
3217
        movsd
3218
        movsd
3219
        movsd
1 ha 3220
 
164 serge 3221
    ; Window state
1055 Galkov 3222
        mov     al, [ecx+window_data+WDATA.fl_wstate]
3223
        stosb
164 serge 3224
 
2010 serge 3225
    ; Event mask (+71)
3226
        mov     EAX, dword [ECX+CURRENT_TASK+TASKDATA.event_mask]
3227
        stosd
3228
 
4265 Serge 3229
    ; Keyboard mode (+75)
3230
        mov     al, byte [ecx*8 + SLOT_BASE + APPDATA.keyboard_mode]
4287 Serge 3231
        stosb
4265 Serge 3232
 
1055 Galkov 3233
        pop     esi
3234
        pop     edi
138 mikedld 3235
 
684 diamond 3236
.nofillbuf:
1 ha 3237
    ; return number of processes
3238
 
2434 Serge 3239
        mov     eax, [TASK_COUNT]
3240
        mov     [esp+32], eax
3241
        ret
1 ha 3242
 
3243
align 4
3244
sys_clock:
1055 Galkov 3245
        cli
1 ha 3246
  ; Mikhail Lisovin  xx Jan 2005
3247
  @@:
2434 Serge 3248
        mov     al, 10
3249
        out     0x70, al
3250
        in      al, 0x71
3251
        test    al, al
3252
        jns     @f
3253
        mov     esi, 1
3254
        call    delay_ms
3255
        jmp     @b
3256
  @@:
1 ha 3257
  ; end Lisovin's fix
3258
 
2434 Serge 3259
        xor     al, al        ; seconds
3260
        out     0x70, al
3261
        in      al, 0x71
3262
        movzx   ecx, al
3263
        mov     al, 02        ; minutes
3264
        shl     ecx, 16
3265
        out     0x70, al
3266
        in      al, 0x71
3267
        movzx   edx, al
3268
        mov     al, 04        ; hours
3269
        shl     edx, 8
3270
        out     0x70, al
3271
        in      al, 0x71
3272
        add     ecx, edx
3273
        movzx   edx, al
3274
        add     ecx, edx
1055 Galkov 3275
        sti
3276
        mov     [esp + 32], ecx
3277
        ret
1 ha 3278
 
3279
 
3280
align 4
3281
 
3282
sys_date:
3283
 
1055 Galkov 3284
        cli
75 diamond 3285
  @@:
2434 Serge 3286
        mov     al, 10
3287
        out     0x70, al
3288
        in      al, 0x71
3289
        test    al, al
3290
        jns     @f
3291
        mov     esi, 1
3292
        call    delay_ms
3293
        jmp     @b
3294
  @@:
75 diamond 3295
 
2434 Serge 3296
        mov     ch, 0
3297
        mov     al, 7           ; date
3298
        out     0x70, al
3299
        in      al, 0x71
3300
        mov     cl, al
3301
        mov     al, 8           ; month
3302
        shl     ecx, 16
3303
        out     0x70, al
3304
        in      al, 0x71
3305
        mov     ch, al
3306
        mov     al, 9           ; year
3307
        out     0x70, al
3308
        in      al, 0x71
3309
        mov     cl, al
1055 Galkov 3310
        sti
3311
        mov     [esp+32], ecx
3312
        ret
1 ha 3313
 
3314
 
3315
; redraw status
3316
 
3317
sys_redrawstat:
1055 Galkov 3318
        cmp     ebx, 1
3319
        jne     no_widgets_away
3320
        ; buttons away
2434 Serge 3321
        mov     ecx, [CURRENT_TASK]
1 ha 3322
  sys_newba2:
2434 Serge 3323
        mov     edi, [BTN_ADDR]
1055 Galkov 3324
        cmp     [edi], dword 0  ; empty button list ?
3325
        je      end_of_buttons_away
3326
        movzx   ebx, word [edi]
3327
        inc     ebx
2434 Serge 3328
        mov     eax, edi
1 ha 3329
  sys_newba:
1055 Galkov 3330
        dec     ebx
3331
        jz      end_of_buttons_away
1 ha 3332
 
1055 Galkov 3333
        add     eax, 0x10
3334
        cmp     cx, [eax]
3335
        jnz     sys_newba
1 ha 3336
 
1055 Galkov 3337
        push    eax ebx ecx
2434 Serge 3338
        mov     ecx, ebx
1055 Galkov 3339
        inc     ecx
3340
        shl     ecx, 4
3341
        mov     ebx, eax
3342
        add     eax, 0x10
3343
        call    memmove
3344
        dec     dword [edi]
3345
        pop     ecx ebx eax
1 ha 3346
 
1055 Galkov 3347
        jmp     sys_newba2
1 ha 3348
 
3349
  end_of_buttons_away:
3350
 
1055 Galkov 3351
        ret
1 ha 3352
 
3353
  no_widgets_away:
3354
 
1055 Galkov 3355
        cmp     ebx, 2
3356
        jnz     srl1
1 ha 3357
 
1055 Galkov 3358
        mov     edx, [TASK_BASE]      ; return whole screen draw area for this app
3359
        add     edx, draw_data - CURRENT_TASK
3360
        mov     [edx + RECT.left], 0
3361
        mov     [edx + RECT.top], 0
5565 serge 3362
        mov     eax, [_display.width]
3363
        dec     eax
1055 Galkov 3364
        mov     [edx + RECT.right], eax
5565 serge 3365
        mov     eax, [_display.height]
3366
        dec     eax
1055 Galkov 3367
        mov     [edx + RECT.bottom], eax
1 ha 3368
 
3369
  srl1:
1055 Galkov 3370
        ret
1 ha 3371
 
3372
;ok - 100% work
3373
;nt - not tested
3374
;---------------------------------------------------------------------------------------------
3375
;eax
3376
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3377
;1 - change task. Ret nothing. Block. ok.
3378
;2 - performance control
3379
; ebx
3380
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3381
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3382
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3383
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3384
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3385
;eax
3386
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3387
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3388
;---------------------------------------------------------------------------------------------
1344 Lrz 3389
iglobal
3390
align 4
3391
sheduler:
2434 Serge 3392
        dd      sys_sheduler.00
3393
        dd      change_task
3394
        dd      sys_sheduler.02
3395
        dd      sys_sheduler.03
3396
        dd      sys_sheduler.04
1344 Lrz 3397
endg
1638 serge 3398
sys_sheduler:
1344 Lrz 3399
;rewritten by   29.12.2009
2434 Serge 3400
        jmp     dword [sheduler+ebx*4]
1344 Lrz 3401
;.shed_counter:
3402
.00:
2434 Serge 3403
        mov     eax, [context_counter]
3404
        mov     [esp+32], eax
3405
        ret
1273 Lrz 3406
 
1344 Lrz 3407
.02:
3408
;.perf_control:
2434 Serge 3409
        inc     ebx                     ;before ebx=2, ebx=3
3410
        cmp     ebx, ecx                ;if ecx=3, ebx=3
3411
        jz      cache_disable
1365 Lrz 3412
 
2434 Serge 3413
        dec     ebx                     ;ebx=2
3414
        cmp     ebx, ecx                ;
3415
        jz      cache_enable            ;if ecx=2 and ebx=2
1365 Lrz 3416
 
2434 Serge 3417
        dec     ebx                     ;ebx=1
3418
        cmp     ebx, ecx
3419
        jz      is_cache_enabled        ;if ecx=1 and ebx=1
1365 Lrz 3420
 
2434 Serge 3421
        dec     ebx
3422
        test    ebx, ecx                ;ebx=0 and ecx=0
3423
        jz      modify_pce              ;if ecx=0
1365 Lrz 3424
 
2434 Serge 3425
        ret
1345 Lrz 3426
 
1638 serge 3427
.03:
1344 Lrz 3428
;.rdmsr_instr:
3429
;now counter in ecx
3430
;(edx:eax) esi:edi => edx:esi
2434 Serge 3431
        mov     eax, esi
3432
        mov     ecx, edx
3433
        rdmsr
3434
        mov     [esp+32], eax
3435
        mov     [esp+20], edx           ;ret in ebx?
3436
        ret
1344 Lrz 3437
 
3438
.04:
1273 Lrz 3439
;.wrmsr_instr:
3440
;now counter in ecx
3441
;(edx:eax) esi:edi => edx:esi
3442
        ; Fast Call MSR can't be destroy
3555 Serge 3443
        ; Но MSR_AMD_EFER можно изменять, т.к. в этом регистре лиш
3444
        ; включаются/выключаются расширенные возможности
2434 Serge 3445
        cmp     edx, MSR_SYSENTER_CS
1273 Lrz 3446
        je      @f
2434 Serge 3447
        cmp     edx, MSR_SYSENTER_ESP
1273 Lrz 3448
        je      @f
2434 Serge 3449
        cmp     edx, MSR_SYSENTER_EIP
1273 Lrz 3450
        je      @f
2434 Serge 3451
        cmp     edx, MSR_AMD_STAR
1273 Lrz 3452
        je      @f
3453
 
2434 Serge 3454
        mov     eax, esi
3455
        mov     ecx, edx
1273 Lrz 3456
        wrmsr
1344 Lrz 3457
        ; mov   [esp + 32], eax
3458
        ; mov   [esp + 20], edx ;ret in ebx?
1273 Lrz 3459
@@:
2434 Serge 3460
        ret
1273 Lrz 3461
 
1 ha 3462
cache_disable:
2434 Serge 3463
        mov     eax, cr0
3464
        or      eax, 01100000000000000000000000000000b
3465
        mov     cr0, eax
3466
        wbinvd  ;set MESI
3467
        ret
1 ha 3468
 
3469
cache_enable:
2434 Serge 3470
        mov     eax, cr0
3471
        and     eax, 10011111111111111111111111111111b
3472
        mov     cr0, eax
3473
        ret
1 ha 3474
 
3475
is_cache_enabled:
2434 Serge 3476
        mov     eax, cr0
3477
        mov     ebx, eax
3478
        and     eax, 01100000000000000000000000000000b
3479
        jz      cache_disabled
3480
        mov     [esp+32], ebx
1 ha 3481
cache_disabled:
2434 Serge 3482
        mov     dword [esp+32], eax;0
3483
        ret
1 ha 3484
 
3485
modify_pce:
2434 Serge 3486
        mov     eax, cr4
1 ha 3487
;       mov ebx,0
3488
;       or  bx,100000000b ;pce
3489
;       xor eax,ebx ;invert pce
2434 Serge 3490
        bts     eax, 8;pce=cr4[8]
3491
        mov     cr4, eax
3492
        mov     [esp+32], eax
3493
        ret
1 ha 3494
;---------------------------------------------------------------------------------------------
3495
 
3496
 
3497
iglobal
521 diamond 3498
  cpustring db 'CPU',0
1 ha 3499
endg
3500
 
67 diamond 3501
uglobal
1055 Galkov 3502
background_defined    db    0    ; diamond, 11.04.2006
67 diamond 3503
endg
2987 Serge 3504
;-----------------------------------------------------------------------------
1 ha 3505
align 4
3506
checkmisc:
2434 Serge 3507
        cmp     [ctrl_alt_del], 1
3508
        jne     nocpustart
501 serge 3509
 
1055 Galkov 3510
        mov     ebp, cpustring
3511
        call    fs_execute_from_sysdir
501 serge 3512
 
2434 Serge 3513
        mov     [ctrl_alt_del], 0
2987 Serge 3514
;--------------------------------------
3515
align 4
465 serge 3516
nocpustart:
2434 Serge 3517
        cmp     [mouse_active], 1
3518
        jne     mouse_not_active
3519
        mov     [mouse_active], 0
1 ha 3520
 
2434 Serge 3521
        xor     edi, edi
3522
        mov     ebx, CURRENT_TASK
3523
 
3524
        mov     ecx, [TASK_COUNT]
3525
        movzx   eax, word [WIN_POS + ecx*2]     ; active window
3526
        shl     eax, 8
3527
        push    eax
3528
 
3529
        movzx   eax, word [MOUSE_X]
3530
        movzx   edx, word [MOUSE_Y]
2987 Serge 3531
;--------------------------------------
2434 Serge 3532
align 4
3533
.set_mouse_event:
3534
        add     edi, 256
3535
        add     ebx, 32
3536
        test    [ebx+TASKDATA.event_mask], 0x80000000
3537
        jz      .pos_filter
3538
 
3539
        cmp     edi, [esp]                      ; skip if filtration active
3540
        jne     .skip
2987 Serge 3541
;--------------------------------------
3542
align 4
2434 Serge 3543
.pos_filter:
3544
        test    [ebx+TASKDATA.event_mask], 0x40000000
3545
        jz      .set
3546
 
3547
        mov     esi, [ebx-twdw+WDATA.box.left]
3548
        cmp     eax, esi
3549
        jb      .skip
3550
        add     esi, [ebx-twdw+WDATA.box.width]
3551
        cmp     eax, esi
3552
        ja      .skip
3553
 
3554
        mov     esi, [ebx-twdw+WDATA.box.top]
3555
        cmp     edx, esi
3556
        jb      .skip
3557
        add     esi, [ebx-twdw+WDATA.box.height]
3558
        cmp     edx, esi
3559
        ja      .skip
2987 Serge 3560
;--------------------------------------
3561
align 4
2434 Serge 3562
.set:
2987 Serge 3563
        or      [edi+SLOT_BASE+APPDATA.event_mask], 100000b  ; set event 6
3564
;--------------------------------------
3565
align 4
2434 Serge 3566
.skip:
3567
        loop    .set_mouse_event
3568
 
3569
        pop     eax
2987 Serge 3570
;--------------------------------------
3571
align 4
465 serge 3572
mouse_not_active:
2434 Serge 3573
        cmp     byte[REDRAW_BACKGROUND], 0         ; background update ?
3574
        jz      nobackgr
2987 Serge 3575
 
2434 Serge 3576
        cmp     [background_defined], 0
3577
        jz      nobackgr
2987 Serge 3578
;--------------------------------------
3579
align 4
3555 Serge 3580
backgr:
2987 Serge 3581
        mov     eax, [draw_data+32 + RECT.left]
3582
        shl     eax, 16
3583
        add     eax, [draw_data+32 + RECT.right]
3584
        mov     [BG_Rect_X_left_right], eax ; [left]*65536 + [right]
3585
 
3586
        mov     eax, [draw_data+32 + RECT.top]
3587
        shl     eax, 16
3588
        add     eax, [draw_data+32 + RECT.bottom]
3589
        mov     [BG_Rect_Y_top_bottom], eax ; [top]*65536 + [bottom]
3590
 
2434 Serge 3591
        call    drawbackground
2987 Serge 3592
;        DEBUGF  1, "K : drawbackground\n"
3593
;        DEBUGF  1, "K : backg x %x\n",[BG_Rect_X_left_right]
3594
;        DEBUGF  1, "K : backg y %x\n",[BG_Rect_Y_top_bottom]
3595
;--------- set event 5 start ----------
3596
        push    ecx edi
3597
        xor     edi, edi
3598
        mov     ecx, [TASK_COUNT]
3599
;--------------------------------------
3600
align 4
3601
set_bgr_event:
3602
        add     edi, 256
3555 Serge 3603
        mov     eax, [BG_Rect_X_left_right]
3604
        mov     edx, [BG_Rect_Y_top_bottom]
3605
        cmp     [edi+SLOT_BASE+APPDATA.draw_bgr_x], 0
3606
        jz      .set
3607
.join:
3626 Serge 3608
        cmp     word [edi+SLOT_BASE+APPDATA.draw_bgr_x], ax
3609
        jae     @f
3610
        mov     word [edi+SLOT_BASE+APPDATA.draw_bgr_x], ax
3611
@@:
3612
        shr     eax, 16
3555 Serge 3613
        cmp     word [edi+SLOT_BASE+APPDATA.draw_bgr_x+2], ax
3614
        jbe     @f
3615
        mov     word [edi+SLOT_BASE+APPDATA.draw_bgr_x+2], ax
3616
@@:
3626 Serge 3617
        cmp     word [edi+SLOT_BASE+APPDATA.draw_bgr_y], dx
3555 Serge 3618
        jae     @f
3626 Serge 3619
        mov     word [edi+SLOT_BASE+APPDATA.draw_bgr_y], dx
3555 Serge 3620
@@:
3626 Serge 3621
        shr     edx, 16
3555 Serge 3622
        cmp     word [edi+SLOT_BASE+APPDATA.draw_bgr_y+2], dx
3623
        jbe     @f
3624
        mov     word [edi+SLOT_BASE+APPDATA.draw_bgr_y+2], dx
3625
@@:
3626
        jmp     .common
3627
.set:
3628
        mov     [edi+SLOT_BASE+APPDATA.draw_bgr_x], eax
3629
        mov     [edi+SLOT_BASE+APPDATA.draw_bgr_y], edx
3630
.common:
2987 Serge 3631
        or      [edi+SLOT_BASE+APPDATA.event_mask], 10000b  ; set event 5
3632
        loop    set_bgr_event
3633
        pop     edi ecx
3634
;--------- set event 5 stop -----------
3635
        dec     byte[REDRAW_BACKGROUND]    ; got new update request?
3555 Serge 3636
        jnz     backgr
2987 Serge 3637
 
3555 Serge 3638
        xor     eax, eax
2434 Serge 3639
        mov     [draw_data+32 + RECT.left], eax
3640
        mov     [draw_data+32 + RECT.top], eax
3641
        mov     [draw_data+32 + RECT.right], eax
3642
        mov     [draw_data+32 + RECT.bottom], eax
2987 Serge 3643
;--------------------------------------
3644
align 4
465 serge 3645
nobackgr:
2987 Serge 3646
; system shutdown request
2434 Serge 3647
        cmp     [SYS_SHUTDOWN], byte 0
3648
        je      noshutdown
1 ha 3649
 
2434 Serge 3650
        mov     edx, [shutdown_processes]
1 ha 3651
 
2434 Serge 3652
        cmp     [SYS_SHUTDOWN], dl
3500 Serge 3653
        jne     noshutdown
1 ha 3654
 
2434 Serge 3655
        lea     ecx, [edx-1]
3656
        mov     edx, OS_BASE+0x3040
3500 Serge 3657
        jecxz   no_mark_system_shutdown
2987 Serge 3658
;--------------------------------------
3659
align 4
465 serge 3660
markz:
3500 Serge 3661
        push    ecx edx
6240 serge 3662
        cmp     [edx+TASKDATA.state], TSTATE_FREE
3500 Serge 3663
        jz      .nokill
3664
        lea     edx, [(edx-(CURRENT_TASK and 1FFFFFFFh))*8+SLOT_BASE]
5201 serge 3665
        cmp     [edx+APPDATA.process], sys_proc
3500 Serge 3666
        jz      .nokill
3667
        call    request_terminate
3668
        jmp     .common
3669
.nokill:
3670
        dec     byte [SYS_SHUTDOWN]
3671
        xor     eax, eax
3672
.common:
3673
        pop     edx ecx
3674
        test    eax, eax
3675
        jz      @f
6240 serge 3676
        mov     [edx+TASKDATA.state], TSTATE_ZOMBIE
3500 Serge 3677
@@:
2434 Serge 3678
        add     edx, 0x20
3679
        loop    markz
3555 Serge 3680
        call    wakeup_osloop
2987 Serge 3681
;--------------------------------------
3682
align 4
709 diamond 3683
@@:
2987 Serge 3684
no_mark_system_shutdown:
2434 Serge 3685
        dec     byte [SYS_SHUTDOWN]
3686
        je      system_shutdown
2987 Serge 3687
;--------------------------------------
3688
align 4
465 serge 3689
noshutdown:
2434 Serge 3690
        mov     eax, [TASK_COUNT]           ; termination
3691
        mov     ebx, TASK_DATA+TASKDATA.state
3692
        mov     esi, 1
2987 Serge 3693
;--------------------------------------
3694
align 4
465 serge 3695
newct:
2434 Serge 3696
        mov     cl, [ebx]
3697
        cmp     cl, byte 3
3500 Serge 3698
        jz      .terminate
2987 Serge 3699
 
2434 Serge 3700
        cmp     cl, byte 4
3500 Serge 3701
        jnz     .noterminate
3702
.terminate:
3703
        pushad
3704
        mov     ecx, eax
3705
        shl     ecx, 8
3706
        add     ecx, SLOT_BASE
3707
        call    restore_default_cursor_before_killing
3708
        popad
1 ha 3709
 
3500 Serge 3710
        pushad
3711
        call    terminate
3712
        popad
3713
        cmp     byte [SYS_SHUTDOWN], 0
3714
        jz      .noterminate
3715
        dec     byte [SYS_SHUTDOWN]
3716
        je      system_shutdown
3717
 
3718
.noterminate:
2434 Serge 3719
        add     ebx, 0x20
3720
        inc     esi
3721
        dec     eax
3722
        jnz     newct
3723
        ret
2987 Serge 3724
;-----------------------------------------------------------------------------
3725
align 4
1 ha 3726
redrawscreen:
3727
; eax , if process window_data base is eax, do not set flag/limits
3728
 
2434 Serge 3729
        pushad
3730
        push    eax
1 ha 3731
 
684 diamond 3732
;;;         mov   ebx,2
1 ha 3733
;;;         call  delay_hs
3734
 
1055 Galkov 3735
         ;mov   ecx,0               ; redraw flags for apps
2434 Serge 3736
        xor     ecx, ecx
2987 Serge 3737
;--------------------------------------
3738
align 4
3739
newdw2:
2434 Serge 3740
        inc     ecx
3741
        push    ecx
1 ha 3742
 
2434 Serge 3743
        mov     eax, ecx
3744
        shl     eax, 5
3745
        add     eax, window_data
1 ha 3746
 
2434 Serge 3747
        cmp     eax, [esp+4]
3748
        je      not_this_task
1055 Galkov 3749
                                   ; check if window in redraw area
2434 Serge 3750
        mov     edi, eax
1 ha 3751
 
2434 Serge 3752
        cmp     ecx, 1             ; limit for background
3753
        jz      bgli
1 ha 3754
 
5984 serge 3755
        mov     eax, [esp+4]        ;if upper in z-position - no redraw
3756
        test    eax, eax
3757
        jz      @f
3758
        mov     al, [eax + WDATA.z_modif]
3759
        cmp     [edi + WDATA.z_modif], al
3760
        jg      ricino
3761
      @@:
3762
 
2434 Serge 3763
        mov     eax, [edi + WDATA.box.left]
3764
        mov     ebx, [edi + WDATA.box.top]
1 ha 3765
 
2434 Serge 3766
        mov     ecx, [draw_limits.bottom] ; ecx = area y end     ebx = window y start
3767
        cmp     ecx, ebx
3768
        jb      ricino
1 ha 3769
 
2434 Serge 3770
        mov     ecx, [draw_limits.right] ; ecx = area x end     eax = window x start
3771
        cmp     ecx, eax
3772
        jb      ricino
1 ha 3773
 
2434 Serge 3774
        mov     eax, [edi + WDATA.box.left]
3775
        mov     ebx, [edi + WDATA.box.top]
3776
        mov     ecx, [edi + WDATA.box.width]
3777
        mov     edx, [edi + WDATA.box.height]
3778
        add     ecx, eax
3779
        add     edx, ebx
164 serge 3780
 
2434 Serge 3781
        mov     eax, [draw_limits.top]  ; eax = area y start     edx = window y end
3782
        cmp     edx, eax
3783
        jb      ricino
1 ha 3784
 
2434 Serge 3785
        mov     eax, [draw_limits.left]  ; eax = area x start     ecx = window x end
3786
        cmp     ecx, eax
3787
        jb      ricino
2987 Serge 3788
;--------------------------------------
3789
align 4
3790
bgli:
2434 Serge 3791
        cmp     dword[esp], 1
3792
        jnz     .az
2987 Serge 3793
 
2434 Serge 3794
        cmp     byte[REDRAW_BACKGROUND], 0
3795
        jz      .az
2987 Serge 3796
 
2434 Serge 3797
        mov     dl, 0
3798
        lea     eax, [edi+draw_data-window_data]
3799
        mov     ebx, [draw_limits.left]
3800
        cmp     ebx, [eax+RECT.left]
3801
        jae     @f
2987 Serge 3802
 
2434 Serge 3803
        mov     [eax+RECT.left], ebx
3804
        mov     dl, 1
2987 Serge 3805
;--------------------------------------
3806
align 4
3807
@@:
2434 Serge 3808
        mov     ebx, [draw_limits.top]
3809
        cmp     ebx, [eax+RECT.top]
3810
        jae     @f
2987 Serge 3811
 
2434 Serge 3812
        mov     [eax+RECT.top], ebx
3813
        mov     dl, 1
2987 Serge 3814
;--------------------------------------
3815
align 4
3816
@@:
2434 Serge 3817
        mov     ebx, [draw_limits.right]
3818
        cmp     ebx, [eax+RECT.right]
3819
        jbe     @f
2987 Serge 3820
 
2434 Serge 3821
        mov     [eax+RECT.right], ebx
3822
        mov     dl, 1
2987 Serge 3823
;--------------------------------------
3824
align 4
3825
@@:
2434 Serge 3826
        mov     ebx, [draw_limits.bottom]
3827
        cmp     ebx, [eax+RECT.bottom]
3828
        jbe     @f
2987 Serge 3829
 
2434 Serge 3830
        mov     [eax+RECT.bottom], ebx
3831
        mov     dl, 1
2987 Serge 3832
;--------------------------------------
3833
align 4
3834
@@:
2434 Serge 3835
        add     byte[REDRAW_BACKGROUND], dl
3555 Serge 3836
        call    wakeup_osloop
2434 Serge 3837
        jmp     newdw8
2987 Serge 3838
;--------------------------------------
3839
align 4
3840
.az:
2434 Serge 3841
        mov     eax, edi
3842
        add     eax, draw_data-window_data
1 ha 3843
 
2434 Serge 3844
        mov     ebx, [draw_limits.left]        ; set limits
3845
        mov     [eax + RECT.left], ebx
3846
        mov     ebx, [draw_limits.top]
3847
        mov     [eax + RECT.top], ebx
3848
        mov     ebx, [draw_limits.right]
3849
        mov     [eax + RECT.right], ebx
3850
        mov     ebx, [draw_limits.bottom]
3851
        mov     [eax + RECT.bottom], ebx
1 ha 3852
 
2434 Serge 3853
        sub     eax, draw_data-window_data
1 ha 3854
 
2434 Serge 3855
        cmp     dword [esp], 1
3856
        jne     nobgrd
3857
        inc     byte[REDRAW_BACKGROUND]
3555 Serge 3858
        call    wakeup_osloop
2987 Serge 3859
;--------------------------------------
3860
align 4
3861
newdw8:
3862
nobgrd:
4265 Serge 3863
;--------------------------------------
3864
        push    eax  edi ebp
3865
        mov     edi, [esp+12]
3866
        cmp     edi, 1
3867
        je      .found
1 ha 3868
 
4265 Serge 3869
        mov     eax, [draw_limits.left]
3870
        mov     ebx, [draw_limits.top]
3871
        mov     ecx, [draw_limits.right]
3872
        sub     ecx, eax
3873
        test    ecx, ecx
3874
        jz      .not_found
3875
 
3876
        mov     edx, [draw_limits.bottom]
3877
        sub     edx, ebx
3878
        test    edx, edx
3879
        jz      .not_found
3880
 
3881
; eax - x, ebx - y
3882
; ecx - size x, edx - size y
3883
        add     ebx, edx
3884
;--------------------------------------
3885
align 4
3886
.start_y:
3887
        push    ecx
3888
;--------------------------------------
3889
align 4
3890
.start_x:
3891
        add     eax, ecx
3892
        mov     ebp, [d_width_calc_area + ebx*4]
5565 serge 3893
        add     ebp, [_display.win_map]
4265 Serge 3894
        movzx   ebp, byte[eax+ebp] ; get value for current point
3895
        cmp     ebp, edi
3896
        jne     @f
3897
 
3898
        pop     ecx
3899
        jmp     .found
3900
;--------------------------------------
3901
align 4
3902
@@:
3903
        sub     eax, ecx
3904
 
3905
        dec     ecx
3906
        jnz     .start_x
3907
 
3908
        pop     ecx
3909
        dec     ebx
3910
        dec     edx
3911
        jnz     .start_y
3912
;--------------------------------------
3913
align 4
3914
.not_found:
3915
        pop     ebp edi eax
3916
        jmp     ricino
3917
;--------------------------------------
3918
align 4
3919
.found:
3920
        pop     ebp edi eax
3921
 
2434 Serge 3922
        mov     [eax + WDATA.fl_redraw], byte 1  ; mark as redraw
2987 Serge 3923
;--------------------------------------
3924
align 4
3925
ricino:
3926
not_this_task:
2434 Serge 3927
        pop     ecx
1 ha 3928
 
2434 Serge 3929
        cmp     ecx, [TASK_COUNT]
3930
        jle     newdw2
1 ha 3931
 
2434 Serge 3932
        pop     eax
3933
        popad
3934
        ret
2987 Serge 3935
;-----------------------------------------------------------------------------
3936
align 4
1 ha 3937
calculatebackground:   ; background
5565 serge 3938
        mov     edi, [_display.win_map]              ; set os to use all pixels
2434 Serge 3939
        mov     eax, 0x01010101
5565 serge 3940
        mov     ecx, [_display.win_map_size]
2434 Serge 3941
        shr     ecx, 2
3942
        rep stosd
1 ha 3943
 
2434 Serge 3944
        mov     byte[REDRAW_BACKGROUND], 0            ; do not draw background!
1055 Galkov 3945
        ret
2987 Serge 3946
;-----------------------------------------------------------------------------
1 ha 3947
uglobal
1055 Galkov 3948
  imax    dd 0x0
1 ha 3949
endg
2987 Serge 3950
;-----------------------------------------------------------------------------
3951
align 4
1 ha 3952
delay_ms:     ; delay in 1/1000 sec
2434 Serge 3953
        push    eax
3954
        push    ecx
1 ha 3955
 
2434 Serge 3956
        mov     ecx, esi
1055 Galkov 3957
        ; 
2434 Serge 3958
        imul    ecx, 33941
3959
        shr     ecx, 9
1055 Galkov 3960
        ; 
1 ha 3961
 
2434 Serge 3962
        in      al, 0x61
3963
        and     al, 0x10
3964
        mov     ah, al
1055 Galkov 3965
        cld
2987 Serge 3966
;--------------------------------------
3967
align 4
3968
cnt1:
2434 Serge 3969
        in      al, 0x61
3970
        and     al, 0x10
3971
        cmp     al, ah
3972
        jz      cnt1
1 ha 3973
 
2434 Serge 3974
        mov     ah, al
3975
        loop    cnt1
1 ha 3976
 
2434 Serge 3977
        pop     ecx
3978
        pop     eax
1055 Galkov 3979
        ret
2987 Serge 3980
;-----------------------------------------------------------------------------
2434 Serge 3981
align 4
1 ha 3982
set_app_param:
1055 Galkov 3983
        mov     edi, [TASK_BASE]
2434 Serge 3984
        mov     eax, ebx
3985
        btr     eax, 3                           ; move MOUSE_FILTRATION
3986
        mov     ebx, [current_slot]              ; bit into event_filter
3987
        setc    byte [ebx+APPDATA.event_filter]
3988
        xchg    eax, [edi + TASKDATA.event_mask] ; set new event mask
3989
        mov     [esp+32], eax                    ; return old mask value
1055 Galkov 3990
        ret
2987 Serge 3991
;-----------------------------------------------------------------------------
3500 Serge 3992
 
3993
; this is for syscall
3994
proc delay_hs_unprotected
3995
        call    unprotect_from_terminate
3996
        call    delay_hs
3997
        call    protect_from_terminate
3998
        ret
3999
endp
4000
 
3626 Serge 4001
if 1
2987 Serge 4002
align 4
1 ha 4003
delay_hs:     ; delay in 1/100 secs
684 diamond 4004
; ebx = delay time
3626 Serge 4005
 
4006
        pushad
4007
        push    ebx
4008
        xor     esi, esi
4009
        mov     ecx, MANUAL_DESTROY
4010
        call    create_event
4011
        test    eax, eax
4012
        jz      .done
4013
 
4014
        mov     ebx, edx
4015
        mov     ecx, [esp]
4016
        push    edx
4017
        push    eax
4018
        call    wait_event_timeout
4019
        pop     eax
4020
        pop     ebx
4021
        call    destroy_event
4022
.done:
4023
        add     esp, 4
4024
        popad
4025
        ret
4026
 
4027
else
4028
 
4029
align 4
4030
delay_hs:     ; delay in 1/100 secs
4031
; ebx = delay time
2434 Serge 4032
        push    ecx
4033
        push    edx
1 ha 4034
 
2434 Serge 4035
        mov     edx, [timer_ticks]
2987 Serge 4036
;--------------------------------------
4037
align 4
4038
newtic:
2434 Serge 4039
        mov     ecx, [timer_ticks]
4040
        sub     ecx, edx
4041
        cmp     ecx, ebx
4042
        jae     zerodelay
1 ha 4043
 
2434 Serge 4044
        call    change_task
1 ha 4045
 
2434 Serge 4046
        jmp     newtic
2987 Serge 4047
;--------------------------------------
4048
align 4
4049
zerodelay:
2434 Serge 4050
        pop     edx
4051
        pop     ecx
1055 Galkov 4052
        ret
3626 Serge 4053
end if
4054
 
2987 Serge 4055
;-----------------------------------------------------------------------------
2434 Serge 4056
align 16        ;very often call this subrutine
1 ha 4057
memmove:       ; memory move in bytes
4058
; eax = from
4059
; ebx = to
4060
; ecx = no of bytes
2434 Serge 4061
        test    ecx, ecx
4062
        jle     .ret
1 ha 4063
 
2434 Serge 4064
        push    esi edi ecx
1 ha 4065
 
2434 Serge 4066
        mov     edi, ebx
4067
        mov     esi, eax
1 ha 4068
 
2434 Serge 4069
        test    ecx, not 11b
4070
        jz      @f
1 ha 4071
 
2434 Serge 4072
        push    ecx
4073
        shr     ecx, 2
4074
        rep movsd
4075
        pop     ecx
4076
        and     ecx, 11b
4077
        jz      .finish
2987 Serge 4078
;--------------------------------------
4079
align 4
4080
@@:
2434 Serge 4081
        rep movsb
2987 Serge 4082
;--------------------------------------
4083
align 4
4084
.finish:
2434 Serge 4085
        pop     ecx edi esi
2987 Serge 4086
;--------------------------------------
4087
align 4
4088
.ret:
2434 Serge 4089
        ret
2987 Serge 4090
;-----------------------------------------------------------------------------
75 diamond 4091
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
4092
;align 4
1 ha 4093
;
75 diamond 4094
;read_floppy_file:
1 ha 4095
;
75 diamond 4096
;; as input
4097
;;
4098
;; eax pointer to file
4099
;; ebx file lenght
4100
;; ecx start 512 byte block number
4101
;; edx number of blocks to read
4102
;; esi pointer to return/work area (atleast 20 000 bytes)
4103
;;
4104
;;
4105
;; on return
4106
;;
4107
;; eax = 0 command succesful
4108
;;       1 no fd base and/or partition defined
4109
;;       2 yet unsupported FS
4110
;;       3 unknown FS
4111
;;       4 partition not defined at hd
4112
;;       5 file not found
4113
;; ebx = size of file
1 ha 4114
;
379 serge 4115
;     mov   edi,[TASK_BASE]
75 diamond 4116
;     add   edi,0x10
4117
;     add   esi,[edi]
4118
;     add   eax,[edi]
1 ha 4119
;
75 diamond 4120
;     pushad
4121
;     mov  edi,esi
4122
;     add  edi,1024
4123
;     mov  esi,0x100000+19*512
4124
;     sub  ecx,1
4125
;     shl  ecx,9
4126
;     add  esi,ecx
4127
;     shl  edx,9
4128
;     mov  ecx,edx
4129
;     cld
4130
;     rep  movsb
4131
;     popad
4132
;
4133
;     mov   [esp+36],eax
4134
;     mov   [esp+24],ebx
4135
;     ret
1 ha 4136
 
4137
 
4138
 
4139
align 4
4140
set_io_access_rights:
2434 Serge 4141
        push    edi eax
4142
        mov     edi, tss._io_map_0
465 serge 4143
;     mov   ecx,eax
4144
;     and   ecx,7    ; offset in byte
4145
;     shr   eax,3    ; number of byte
4146
;     add   edi,eax
4147
;     mov   ebx,1
4148
;     shl   ebx,cl
2434 Serge 4149
        test    ebp, ebp
1232 Lrz 4150
;     cmp   ebp,0                ; enable access - ebp = 0
2434 Serge 4151
        jnz     .siar1
465 serge 4152
;     not   ebx
4153
;     and   [edi],byte bl
2434 Serge 4154
        btr     [edi], eax
4155
        pop     eax edi
4156
        ret
2106 serge 4157
.siar1:
2434 Serge 4158
        bts     [edi], eax
465 serge 4159
  ;  or    [edi],byte bl        ; disable access - ebp = 1
2434 Serge 4160
        pop     eax edi
4161
        ret
1306 Lrz 4162
;reserve/free group of ports
4163
;  * eax = 46 - number function
4164
;  * ebx = 0 - reserve, 1 - free
4165
;  * ecx = number start arrea of ports
4166
;  * edx = number end arrea of ports (include last number of port)
4167
;Return value:
1638 serge 4168
;  * eax = 0 - succesful
1306 Lrz 4169
;  * eax = 1 - error
4170
;  * The system has reserve this ports:
4171
;    0..0x2d, 0x30..0x4d, 0x50..0xdf, 0xe5..0xff (include last number of port).
4172
;destroys eax,ebx, ebp
1 ha 4173
r_f_port_area:
4174
 
2434 Serge 4175
        test    ebx, ebx
4176
        jnz     free_port_area
1 ha 4177
;     je    r_port_area
4178
;     jmp   free_port_area
4179
 
4180
;   r_port_area:
4181
 
1306 Lrz 4182
;     pushad
1 ha 4183
 
2434 Serge 4184
        cmp     ecx, edx      ; beginning > end ?
4185
        ja      rpal1
4186
        cmp     edx, 65536
4187
        jae     rpal1
4188
        mov     eax, [RESERVED_PORTS]
4189
        test    eax, eax      ; no reserved areas ?
4190
        je      rpal2
4191
        cmp     eax, 255      ; max reserved
4192
        jae     rpal1
465 serge 4193
 rpal3:
2434 Serge 4194
        mov     ebx, eax
4195
        shl     ebx, 4
4196
        add     ebx, RESERVED_PORTS
4197
        cmp     ecx, [ebx+8]
4198
        ja      rpal4
4199
        cmp     edx, [ebx+4]
4200
        jae     rpal1
1 ha 4201
;     jb    rpal4
4202
;     jmp   rpal1
465 serge 4203
 rpal4:
2434 Serge 4204
        dec     eax
4205
        jnz     rpal3
4206
        jmp     rpal2
1 ha 4207
   rpal1:
1306 Lrz 4208
;     popad
4209
;     mov   eax,1
2434 Serge 4210
        xor     eax, eax
4211
        inc     eax
4212
        ret
1 ha 4213
   rpal2:
1306 Lrz 4214
;     popad
1 ha 4215
     ; enable port access at port IO map
2434 Serge 4216
        cli
4217
        pushad                        ; start enable io map
1 ha 4218
 
2434 Serge 4219
        cmp     edx, 65536;16384
4220
        jae     no_unmask_io; jge
4221
        mov     eax, ecx
4222
;       push    ebp
4223
        xor     ebp, ebp               ; enable - eax = port
1306 Lrz 4224
new_port_access:
4225
;     pushad
2434 Serge 4226
        call    set_io_access_rights
1306 Lrz 4227
;     popad
2434 Serge 4228
        inc     eax
4229
        cmp     eax, edx
4230
        jbe     new_port_access
4231
;       pop     ebp
1306 Lrz 4232
no_unmask_io:
2434 Serge 4233
        popad                         ; end enable io map
4234
        sti
1 ha 4235
 
2434 Serge 4236
        mov     eax, [RESERVED_PORTS]
4237
        add     eax, 1
4238
        mov     [RESERVED_PORTS], eax
4239
        shl     eax, 4
4240
        add     eax, RESERVED_PORTS
4241
        mov     ebx, [TASK_BASE]
4242
        mov     ebx, [ebx+TASKDATA.pid]
4243
        mov     [eax], ebx
4244
        mov     [eax+4], ecx
4245
        mov     [eax+8], edx
1 ha 4246
 
2434 Serge 4247
        xor     eax, eax
4248
        ret
1 ha 4249
 
4250
free_port_area:
4251
 
1306 Lrz 4252
;     pushad
2434 Serge 4253
        mov     eax, [RESERVED_PORTS]; no reserved areas ?
4254
        test    eax, eax
4255
        jz      frpal2
4256
        mov     ebx, [TASK_BASE]
4257
        mov     ebx, [ebx+TASKDATA.pid]
1 ha 4258
   frpal3:
2434 Serge 4259
        mov     edi, eax
4260
        shl     edi, 4
4261
        add     edi, RESERVED_PORTS
4262
        cmp     ebx, [edi]
4263
        jne     frpal4
4264
        cmp     ecx, [edi+4]
4265
        jne     frpal4
4266
        cmp     edx, [edi+8]
4267
        jne     frpal4
4268
        jmp     frpal1
1 ha 4269
   frpal4:
2434 Serge 4270
        dec     eax
4271
        jnz     frpal3
1 ha 4272
   frpal2:
1306 Lrz 4273
;     popad
2434 Serge 4274
        inc     eax
4275
        ret
1 ha 4276
   frpal1:
2434 Serge 4277
        push    ecx
4278
        mov     ecx, 256
4279
        sub     ecx, eax
4280
        shl     ecx, 4
4281
        mov     esi, edi
4282
        add     esi, 16
4283
        cld
4284
        rep movsb
1 ha 4285
 
2434 Serge 4286
        dec     dword [RESERVED_PORTS]
1306 Lrz 4287
;popad
4288
;disable port access at port IO map
1 ha 4289
 
1306 Lrz 4290
;     pushad                        ; start disable io map
2434 Serge 4291
        pop     eax     ;start port
4292
        cmp     edx, 65536;16384
4293
        jge     no_mask_io
1 ha 4294
 
1306 Lrz 4295
;     mov   eax,ecx
2434 Serge 4296
        xor     ebp, ebp
4297
        inc     ebp
1306 Lrz 4298
new_port_access_disable:
4299
;     pushad
4300
;     mov   ebp,1                  ; disable - eax = port
2434 Serge 4301
        call    set_io_access_rights
1306 Lrz 4302
;     popad
2434 Serge 4303
        inc     eax
4304
        cmp     eax, edx
4305
        jbe     new_port_access_disable
1306 Lrz 4306
no_mask_io:
4307
;     popad                         ; end disable io map
2434 Serge 4308
        xor     eax, eax
4309
        ret
4310
;-----------------------------------------------------------------------------
2106 serge 4311
align 4
1 ha 4312
drawbackground:
2434 Serge 4313
dbrv20:
4314
        cmp     [BgrDrawMode], dword 1
4315
        jne     bgrstr
4316
        call    vesa20_drawbackground_tiled
2465 Serge 4317
;        call    [draw_pointer]
4318
        call    __sys_draw_pointer
2434 Serge 4319
        ret
4320
;--------------------------------------
75 diamond 4321
align 4
2434 Serge 4322
bgrstr:
4323
        call    vesa20_drawbackground_stretch
2465 Serge 4324
;        call    [draw_pointer]
4325
        call    __sys_draw_pointer
2434 Serge 4326
        ret
4327
;-----------------------------------------------------------------------------
4328
align 4
1055 Galkov 4329
syscall_putimage:                       ; PutImage
1 ha 4330
sys_putimage:
2434 Serge 4331
        test    ecx, 0x80008000
4332
        jnz     .exit
4333
        test    ecx, 0x0000FFFF
4334
        jz      .exit
4335
        test    ecx, 0xFFFF0000
4336
        jnz     @f
4337
;--------------------------------------
4338
align 4
4339
.exit:
4340
        ret
4341
;--------------------------------------
4342
align 4
4343
@@:
4344
        mov     edi, [current_slot]
4345
        add     dx, word[edi+APPDATA.wnd_clientbox.top]
4346
        rol     edx, 16
4347
        add     dx, word[edi+APPDATA.wnd_clientbox.left]
4348
        rol     edx, 16
4349
;--------------------------------------
4350
align 4
4351
.forced:
1055 Galkov 4352
        push    ebp esi 0
4353
        mov     ebp, putimage_get24bpp
4354
        mov     esi, putimage_init24bpp
2434 Serge 4355
;--------------------------------------
4356
align 4
283 diamond 4357
sys_putimage_bpp:
2434 Serge 4358
        call    vesa20_putimage
1055 Galkov 4359
        pop     ebp esi ebp
2434 Serge 4360
        ret
4361
;        jmp     [draw_pointer]
4362
;-----------------------------------------------------------------------------
1495 Lrz 4363
align 4
283 diamond 4364
sys_putimage_palette:
4365
; ebx = pointer to image
4366
; ecx = [xsize]*65536 + [ysize]
4367
; edx = [xstart]*65536 + [ystart]
314 diamond 4368
; esi = number of bits per pixel, must be 8, 24 or 32
283 diamond 4369
; edi = pointer to palette
314 diamond 4370
; ebp = row delta
1055 Galkov 4371
        mov     eax, [CURRENT_TASK]
4372
        shl     eax, 8
4373
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
4374
        rol     edx, 16
4375
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
4376
        rol     edx, 16
2434 Serge 4377
;--------------------------------------
4378
align 4
283 diamond 4379
.forced:
1055 Galkov 4380
        cmp     esi, 1
4381
        jnz     @f
4382
        push    edi
4383
        mov     eax, [edi+4]
4384
        sub     eax, [edi]
4385
        push    eax
4386
        push    dword [edi]
4387
        push    0ffffff80h
4388
        mov     edi, esp
4389
        call    put_mono_image
4390
        add     esp, 12
4391
        pop     edi
4392
        ret
2434 Serge 4393
;--------------------------------------
4394
align 4
911 diamond 4395
@@:
1055 Galkov 4396
        cmp     esi, 2
4397
        jnz     @f
4398
        push    edi
4399
        push    0ffffff80h
4400
        mov     edi, esp
4401
        call    put_2bit_image
4402
        pop     eax
4403
        pop     edi
4404
        ret
2434 Serge 4405
;--------------------------------------
4406
align 4
911 diamond 4407
@@:
1055 Galkov 4408
        cmp     esi, 4
4409
        jnz     @f
4410
        push    edi
4411
        push    0ffffff80h
4412
        mov     edi, esp
4413
        call    put_4bit_image
4414
        pop     eax
4415
        pop     edi
4416
        ret
2434 Serge 4417
;--------------------------------------
4418
align 4
314 diamond 4419
@@:
1055 Galkov 4420
        push    ebp esi ebp
4421
        cmp     esi, 8
4422
        jnz     @f
4423
        mov     ebp, putimage_get8bpp
4424
        mov     esi, putimage_init8bpp
4425
        jmp     sys_putimage_bpp
2434 Serge 4426
;--------------------------------------
4427
align 4
918 diamond 4428
@@:
2987 Serge 4429
        cmp     esi, 9
4430
        jnz     @f
4431
        mov     ebp, putimage_get9bpp
4432
        mov     esi, putimage_init9bpp
4433
        jmp     sys_putimage_bpp
4434
;--------------------------------------
4435
align 4
4436
@@:
1055 Galkov 4437
        cmp     esi, 15
4438
        jnz     @f
4439
        mov     ebp, putimage_get15bpp
4440
        mov     esi, putimage_init15bpp
4441
        jmp     sys_putimage_bpp
2434 Serge 4442
;--------------------------------------
4443
align 4
906 diamond 4444
@@:
1055 Galkov 4445
        cmp     esi, 16
4446
        jnz     @f
4447
        mov     ebp, putimage_get16bpp
4448
        mov     esi, putimage_init16bpp
4449
        jmp     sys_putimage_bpp
2434 Serge 4450
;--------------------------------------
4451
align 4
842 diamond 4452
@@:
1055 Galkov 4453
        cmp     esi, 24
4454
        jnz     @f
4455
        mov     ebp, putimage_get24bpp
4456
        mov     esi, putimage_init24bpp
4457
        jmp     sys_putimage_bpp
2434 Serge 4458
;--------------------------------------
4459
align 4
314 diamond 4460
@@:
1055 Galkov 4461
        cmp     esi, 32
4462
        jnz     @f
4463
        mov     ebp, putimage_get32bpp
4464
        mov     esi, putimage_init32bpp
4465
        jmp     sys_putimage_bpp
2434 Serge 4466
;--------------------------------------
4467
align 4
314 diamond 4468
@@:
1055 Galkov 4469
        pop     ebp esi ebp
4470
        ret
2434 Serge 4471
;-----------------------------------------------------------------------------
4472
align 4
911 diamond 4473
put_mono_image:
1055 Galkov 4474
        push    ebp esi ebp
4475
        mov     ebp, putimage_get1bpp
4476
        mov     esi, putimage_init1bpp
4477
        jmp     sys_putimage_bpp
2434 Serge 4478
;-----------------------------------------------------------------------------
4479
align 4
918 diamond 4480
put_2bit_image:
1055 Galkov 4481
        push    ebp esi ebp
4482
        mov     ebp, putimage_get2bpp
4483
        mov     esi, putimage_init2bpp
4484
        jmp     sys_putimage_bpp
2434 Serge 4485
;-----------------------------------------------------------------------------
4486
align 4
911 diamond 4487
put_4bit_image:
1055 Galkov 4488
        push    ebp esi ebp
4489
        mov     ebp, putimage_get4bpp
4490
        mov     esi, putimage_init4bpp
4491
        jmp     sys_putimage_bpp
2434 Serge 4492
;-----------------------------------------------------------------------------
4493
align 4
283 diamond 4494
putimage_init24bpp:
1055 Galkov 4495
        lea     eax, [eax*3]
283 diamond 4496
putimage_init8bpp:
2987 Serge 4497
putimage_init9bpp:
1055 Galkov 4498
        ret
2434 Serge 4499
;-----------------------------------------------------------------------------
911 diamond 4500
align 16
283 diamond 4501
putimage_get24bpp:
1055 Galkov 4502
        movzx   eax, byte [esi+2]
4503
        shl     eax, 16
4504
        mov     ax, [esi]
4505
        add     esi, 3
4506
        ret     4
2434 Serge 4507
;-----------------------------------------------------------------------------
911 diamond 4508
align 16
283 diamond 4509
putimage_get8bpp:
1055 Galkov 4510
        movzx   eax, byte [esi]
4511
        push    edx
4512
        mov     edx, [esp+8]
4513
        mov     eax, [edx+eax*4]
4514
        pop     edx
4515
        inc     esi
4516
        ret     4
2434 Serge 4517
;-----------------------------------------------------------------------------
2987 Serge 4518
align 16
4519
putimage_get9bpp:
4520
        lodsb
4521
        mov     ah, al
4522
        shl     eax, 8
4523
        mov     al, ah
4524
        ret     4
4525
;-----------------------------------------------------------------------------
2434 Serge 4526
align 4
911 diamond 4527
putimage_init1bpp:
1055 Galkov 4528
        add     eax, ecx
4529
        push    ecx
4530
        add     eax, 7
4531
        add     ecx, 7
4532
        shr     eax, 3
4533
        shr     ecx, 3
4534
        sub     eax, ecx
4535
        pop     ecx
4536
        ret
2434 Serge 4537
;-----------------------------------------------------------------------------
911 diamond 4538
align 16
4539
putimage_get1bpp:
1055 Galkov 4540
        push    edx
4541
        mov     edx, [esp+8]
4542
        mov     al, [edx]
4543
        add     al, al
4544
        jnz     @f
4545
        lodsb
4546
        adc     al, al
911 diamond 4547
@@:
1055 Galkov 4548
        mov     [edx], al
4549
        sbb     eax, eax
4550
        and     eax, [edx+8]
4551
        add     eax, [edx+4]
4552
        pop     edx
4553
        ret     4
2434 Serge 4554
;-----------------------------------------------------------------------------
4555
align 4
918 diamond 4556
putimage_init2bpp:
1055 Galkov 4557
        add     eax, ecx
4558
        push    ecx
4559
        add     ecx, 3
4560
        add     eax, 3
4561
        shr     ecx, 2
4562
        shr     eax, 2
4563
        sub     eax, ecx
4564
        pop     ecx
4565
        ret
2434 Serge 4566
;-----------------------------------------------------------------------------
918 diamond 4567
align 16
4568
putimage_get2bpp:
1055 Galkov 4569
        push    edx
4570
        mov     edx, [esp+8]
4571
        mov     al, [edx]
4572
        mov     ah, al
4573
        shr     al, 6
4574
        shl     ah, 2
4575
        jnz     .nonewbyte
4576
        lodsb
4577
        mov     ah, al
4578
        shr     al, 6
4579
        shl     ah, 2
4580
        add     ah, 1
918 diamond 4581
.nonewbyte:
1055 Galkov 4582
        mov     [edx], ah
4583
        mov     edx, [edx+4]
4584
        movzx   eax, al
4585
        mov     eax, [edx+eax*4]
4586
        pop     edx
4587
        ret     4
2434 Serge 4588
;-----------------------------------------------------------------------------
4589
align 4
911 diamond 4590
putimage_init4bpp:
1055 Galkov 4591
        add     eax, ecx
4592
        push    ecx
4593
        add     ecx, 1
4594
        add     eax, 1
4595
        shr     ecx, 1
4596
        shr     eax, 1
4597
        sub     eax, ecx
4598
        pop     ecx
4599
        ret
2434 Serge 4600
;-----------------------------------------------------------------------------
911 diamond 4601
align 16
4602
putimage_get4bpp:
1055 Galkov 4603
        push    edx
4604
        mov     edx, [esp+8]
4605
        add     byte [edx], 80h
4606
        jc      @f
4607
        movzx   eax, byte [edx+1]
4608
        mov     edx, [edx+4]
4609
        and     eax, 0x0F
4610
        mov     eax, [edx+eax*4]
4611
        pop     edx
4612
        ret     4
911 diamond 4613
@@:
1055 Galkov 4614
        movzx   eax, byte [esi]
4615
        add     esi, 1
4616
        mov     [edx+1], al
4617
        shr     eax, 4
4618
        mov     edx, [edx+4]
4619
        mov     eax, [edx+eax*4]
4620
        pop     edx
4621
        ret     4
2434 Serge 4622
;-----------------------------------------------------------------------------
4623
align 4
314 diamond 4624
putimage_init32bpp:
1055 Galkov 4625
        shl     eax, 2
4626
        ret
2434 Serge 4627
;-----------------------------------------------------------------------------
911 diamond 4628
align 16
314 diamond 4629
putimage_get32bpp:
1055 Galkov 4630
        lodsd
4631
        ret     4
2434 Serge 4632
;-----------------------------------------------------------------------------
4633
align 4
906 diamond 4634
putimage_init15bpp:
911 diamond 4635
putimage_init16bpp:
1055 Galkov 4636
        add     eax, eax
4637
        ret
2434 Serge 4638
;-----------------------------------------------------------------------------
911 diamond 4639
align 16
906 diamond 4640
putimage_get15bpp:
842 diamond 4641
; 0RRRRRGGGGGBBBBB -> 00000000RRRRR000GGGGG000BBBBB000
1055 Galkov 4642
        push    ecx edx
4643
        movzx   eax, word [esi]
4644
        add     esi, 2
4645
        mov     ecx, eax
4646
        mov     edx, eax
4647
        and     eax, 0x1F
4648
        and     ecx, 0x1F shl 5
4649
        and     edx, 0x1F shl 10
4650
        shl     eax, 3
4651
        shl     ecx, 6
4652
        shl     edx, 9
4653
        or      eax, ecx
4654
        or      eax, edx
4655
        pop     edx ecx
4656
        ret     4
2434 Serge 4657
;-----------------------------------------------------------------------------
911 diamond 4658
align 16
906 diamond 4659
putimage_get16bpp:
4660
; RRRRRGGGGGGBBBBB -> 00000000RRRRR000GGGGGG00BBBBB000
1055 Galkov 4661
        push    ecx edx
4662
        movzx   eax, word [esi]
4663
        add     esi, 2
4664
        mov     ecx, eax
4665
        mov     edx, eax
4666
        and     eax, 0x1F
4667
        and     ecx, 0x3F shl 5
4668
        and     edx, 0x1F shl 11
4669
        shl     eax, 3
4670
        shl     ecx, 5
4671
        shl     edx, 8
4672
        or      eax, ecx
4673
        or      eax, edx
4674
        pop     edx ecx
4675
        ret     4
2434 Serge 4676
;-----------------------------------------------------------------------------
4677
;align 4
1 ha 4678
; eax x beginning
4679
; ebx y beginning
4680
; ecx x end
1055 Galkov 4681
        ; edx y end
1 ha 4682
; edi color
2434 Serge 4683
;__sys_drawbar:
4684
;        mov     esi, [current_slot]
4685
;        add     eax, [esi+APPDATA.wnd_clientbox.left]
4686
;        add     ecx, [esi+APPDATA.wnd_clientbox.left]
4687
;        add     ebx, [esi+APPDATA.wnd_clientbox.top]
4688
;        add     edx, [esi+APPDATA.wnd_clientbox.top]
4689
;--------------------------------------
4690
;align 4
4691
;.forced:
4692
;        call    vesa20_drawbar
4693
;        call    [draw_pointer]
4694
;        ret
4695
;-----------------------------------------------------------------------------
4696
align 4
5201 serge 4697
kb_write_wait_ack:
1 ha 4698
 
1055 Galkov 4699
        push    ecx edx
1 ha 4700
 
2434 Serge 4701
        mov     dl, al
4702
        mov     ecx, 0x1ffff; last 0xffff, new value in view of fast CPU's
5201 serge 4703
.wait_output_ready:
2434 Serge 4704
        in      al, 0x64
4705
        test    al, 2
5201 serge 4706
        jz      @f
4707
        loop    .wait_output_ready
2434 Serge 4708
        mov     ah, 1
5201 serge 4709
        jmp     .nothing
4710
@@:
2434 Serge 4711
        mov     al, dl
4712
        out     0x60, al
5201 serge 4713
        mov     ecx, 0xfffff; last 0xffff, new value in view of fast CPU's
4714
.wait_ack:
2434 Serge 4715
        in      al, 0x64
5201 serge 4716
        test    al, 1
4717
        jnz     @f
4718
        loop    .wait_ack
2434 Serge 4719
        mov     ah, 1
5201 serge 4720
        jmp     .nothing
4721
@@:
4722
        in      al, 0x60
2434 Serge 4723
        xor     ah, ah
1 ha 4724
 
5201 serge 4725
.nothing:
1055 Galkov 4726
        pop     edx ecx
1 ha 4727
 
1055 Galkov 4728
        ret
2434 Serge 4729
;-----------------------------------------------------------------------------
1 ha 4730
 
4731
setmouse:  ; set mousepicture -pointer
1055 Galkov 4732
           ; ps2 mouse enable
1 ha 4733
 
2434 Serge 4734
;        mov     [MOUSE_PICTURE], dword mousepointer
1 ha 4735
 
2434 Serge 4736
        cli
1 ha 4737
 
2434 Serge 4738
        ret
1 ha 4739
 
1055 Galkov 4740
if used _rdtsc
1 ha 4741
_rdtsc:
2434 Serge 4742
        bt      [cpu_caps], CAPS_TSC
4743
        jnc     ret_rdtsc
4744
        rdtsc
4745
        ret
1 ha 4746
   ret_rdtsc:
2434 Serge 4747
        mov     edx, 0xffffffff
4748
        mov     eax, 0xffffffff
4749
        ret
1055 Galkov 4750
end if
1 ha 4751
 
4752
sys_msg_board_str:
4753
 
2434 Serge 4754
        pushad
1 ha 4755
   @@:
2434 Serge 4756
        cmp     [esi], byte 0
4757
        je      @f
3626 Serge 4758
        mov     ebx, 1
4759
        movzx   ecx, byte [esi]
2434 Serge 4760
        call    sys_msg_board
4761
        inc     esi
4762
        jmp     @b
1 ha 4763
   @@:
2434 Serge 4764
        popad
4765
        ret
1 ha 4766
 
709 diamond 4767
sys_msg_board_byte:
4768
; in: al = byte to display
4769
; out: nothing
4770
; destroys: nothing
1055 Galkov 4771
        pushad
4772
        mov     ecx, 2
4773
        shl     eax, 24
4774
        jmp     @f
709 diamond 4775
 
4776
sys_msg_board_word:
4777
; in: ax = word to display
4778
; out: nothing
4779
; destroys: nothing
1055 Galkov 4780
        pushad
4781
        mov     ecx, 4
4782
        shl     eax, 16
4783
        jmp     @f
709 diamond 4784
 
4785
sys_msg_board_dword:
4786
; in: eax = dword to display
4787
; out: nothing
4788
; destroys: nothing
1055 Galkov 4789
        pushad
4790
        mov     ecx, 8
709 diamond 4791
@@:
1055 Galkov 4792
        push    ecx
4793
        rol     eax, 4
4794
        push    eax
4795
        and     al, 0xF
4796
        cmp     al, 10
4797
        sbb     al, 69h
4798
        das
3626 Serge 4799
        mov     cl, al
4800
        xor     ebx, ebx
4801
        inc     ebx
1055 Galkov 4802
        call    sys_msg_board
4803
        pop     eax
4804
        pop     ecx
4805
        loop    @b
4806
        popad
4807
        ret
709 diamond 4808
 
3500 Serge 4809
msg_board_data_size = 65536 ; Must be power of two
4810
 
1 ha 4811
uglobal
3500 Serge 4812
  msg_board_data  rb msg_board_data_size
1 ha 4813
  msg_board_count dd 0x0
4814
endg
4815
 
4816
sys_msg_board:
4817
 
3626 Serge 4818
; ebx=1 : write :  bl byte to write
4819
; ebx=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
1 ha 4820
 
3626 Serge 4821
        push    eax ebx                 ; Save eax and ebx, since we're restoring their order required.
4822
        mov     eax, ebx
4823
        mov     ebx, ecx
4824
 
1055 Galkov 4825
        mov     ecx, [msg_board_count]
4826
        cmp     eax, 1
4827
        jne     .smbl1
1 ha 4828
 
1043 hidnplayr 4829
if defined debug_com_base
1 ha 4830
 
1055 Galkov 4831
        push    dx ax
1043 hidnplayr 4832
 
1055 Galkov 4833
       @@:                              ; Wait for empty transmit register  (yes, this slows down system..)
4834
        mov     dx, debug_com_base+5
4835
        in      al, dx
4836
        test    al, 1 shl 5
4837
        jz      @r
1043 hidnplayr 4838
 
1055 Galkov 4839
        mov     dx, debug_com_base      ; Output the byte
4840
        mov     al, bl
4841
        out     dx, al
1043 hidnplayr 4842
 
1055 Galkov 4843
        pop     ax dx
1043 hidnplayr 4844
 
4845
end if
4846
 
2434 Serge 4847
        mov     [msg_board_data+ecx], bl
3908 Serge 4848
; // if debug_direct_print == 1
4849
        cmp     byte [debug_direct_print], 1
4850
        jnz     @f
3555 Serge 4851
        pusha
4852
iglobal
3908 Serge 4853
msg_board_pos   dd      (42*6)*65536+10 ; for printing debug output on the screen
3555 Serge 4854
endg
4855
        lea     edx, [msg_board_data+ecx]
4856
        mov     ecx, 0x40FFFFFF
4857
        mov     ebx, [msg_board_pos]
4858
        mov     edi, 1
4859
        mov     esi, 1
4860
        call    dtext
4861
        popa
4862
        add     word [msg_board_pos+2], 6
4863
        cmp     bl, 10
4864
        jnz     @f
3908 Serge 4865
        mov     word [msg_board_pos+2], (42*6)
3555 Serge 4866
        add     word [msg_board_pos], 10
5565 serge 4867
        mov     ax, word [_display.width]
3555 Serge 4868
        cmp     word [msg_board_pos], ax
5565 serge 4869
        jb      @f
3555 Serge 4870
        mov     word [msg_board_pos], 10
4871
@@:
3908 Serge 4872
; // end if
4873
 
3555 Serge 4874
if 0
4875
        pusha
4876
        mov     al, bl
4877
        mov     edx, 402h
4878
        out     dx, al
4879
        popa
4880
end if
1055 Galkov 4881
        inc     ecx
3500 Serge 4882
        and     ecx, msg_board_data_size - 1
1055 Galkov 4883
        mov     [msg_board_count], ecx
3626 Serge 4884
 
4885
        pop     ebx eax
1055 Galkov 4886
        ret
671 Ghost 4887
.smbl1:
1055 Galkov 4888
        cmp     eax, 2
4889
        jne     .smbl2
4890
        test    ecx, ecx
4891
        jz      .smbl21
3626 Serge 4892
 
4893
        add     esp, 8                  ; Returning data in ebx and eax, so no need to restore them.
1055 Galkov 4894
        mov     eax, msg_board_data+1
4895
        mov     ebx, msg_board_data
4896
        movzx   edx, byte [ebx]
4897
        call    memmove
4898
        dec     [msg_board_count]
3626 Serge 4899
        mov     [esp + 32], edx ;eax
4900
        mov     [esp + 20], dword 1
1055 Galkov 4901
        ret
671 Ghost 4902
.smbl21:
3626 Serge 4903
        mov     [esp+32], ecx
4904
        mov     [esp+20], ecx
671 Ghost 4905
.smbl2:
3626 Serge 4906
        pop     ebx eax
1055 Galkov 4907
        ret
1 ha 4908
 
1494 Lrz 4909
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4910
;; 66 sys function.                                                ;;
4911
;; in eax=66,ebx in [0..5],ecx,edx                                 ;;
4912
;; out eax                                                         ;;
4913
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4914
iglobal
4915
align 4
4916
f66call:
4917
           dd sys_process_def.1   ; 1 = set keyboard mode
4918
           dd sys_process_def.2   ; 2 = get keyboard mode
4919
           dd sys_process_def.3   ; 3 = get keyboard ctrl, alt, shift
2987 Serge 4920
           dd sys_process_def.4   ; 4 = set system-wide hotkey
4921
           dd sys_process_def.5   ; 5 = delete installed hotkey
4922
           dd sys_process_def.6   ; 6 = disable input, work only hotkeys
4923
           dd sys_process_def.7   ; 7 = enable input, opposition to f.66.6
1494 Lrz 4924
endg
2987 Serge 4925
;-----------------------------------------------------------------------------
4926
align 4
1 ha 4927
sys_process_def:
2434 Serge 4928
        dec     ebx
2987 Serge 4929
        cmp     ebx, 7
4930
        jae     .not_support    ;if >=8 then or eax,-1
1494 Lrz 4931
 
1055 Galkov 4932
        mov     edi, [CURRENT_TASK]
2434 Serge 4933
        jmp     dword [f66call+ebx*4]
1 ha 4934
 
1494 Lrz 4935
.not_support:
2434 Serge 4936
        or      eax, -1
4937
        ret
2987 Serge 4938
;-----------------------------------------------------------------------------
4939
align 4
1494 Lrz 4940
.1:
2434 Serge 4941
        shl     edi, 8
4942
        mov     [edi+SLOT_BASE + APPDATA.keyboard_mode], cl
1 ha 4943
 
2434 Serge 4944
        ret
2987 Serge 4945
;-----------------------------------------------------------------------------
4946
align 4
2434 Serge 4947
.2:                             ; 2 = get keyboard mode
4948
        shl     edi, 8
4949
        movzx   eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
4950
        mov     [esp+32], eax
4951
        ret
2987 Serge 4952
;-----------------------------------------------------------------------------
4953
align 4
2434 Serge 4954
.3:                             ;3 = get keyboard ctrl, alt, shift
4955
        mov     eax, [kb_state]
4956
        mov     [esp+32], eax
4957
        ret
2987 Serge 4958
;-----------------------------------------------------------------------------
4959
align 4
1494 Lrz 4960
.4:
1055 Galkov 4961
        mov     eax, hotkey_list
92 diamond 4962
@@:
1055 Galkov 4963
        cmp     dword [eax+8], 0
4964
        jz      .found_free
4965
        add     eax, 16
4966
        cmp     eax, hotkey_list+16*256
4967
        jb      @b
1494 Lrz 4968
        mov     dword [esp+32], 1
1055 Galkov 4969
        ret
92 diamond 4970
.found_free:
1055 Galkov 4971
        mov     [eax+8], edi
1494 Lrz 4972
        mov     [eax+4], edx
4973
        movzx   ecx, cl
4974
        lea     ecx, [hotkey_scancodes+ecx*4]
4975
        mov     edx, [ecx]
4976
        mov     [eax], edx
4977
        mov     [ecx], eax
4978
        mov     [eax+12], ecx
3500 Serge 4979
        test    edx, edx
4980
        jz      @f
1494 Lrz 4981
        mov     [edx+12], eax
92 diamond 4982
@@:
1494 Lrz 4983
        and     dword [esp+32], 0
1055 Galkov 4984
        ret
2987 Serge 4985
;-----------------------------------------------------------------------------
4986
align 4
1494 Lrz 4987
.5:
4988
        movzx   ebx, cl
1055 Galkov 4989
        lea     ebx, [hotkey_scancodes+ebx*4]
4990
        mov     eax, [ebx]
92 diamond 4991
.scan:
1055 Galkov 4992
        test    eax, eax
4993
        jz      .notfound
4994
        cmp     [eax+8], edi
4995
        jnz     .next
1494 Lrz 4996
        cmp     [eax+4], edx
1055 Galkov 4997
        jz      .found
92 diamond 4998
.next:
1055 Galkov 4999
        mov     eax, [eax]
5000
        jmp     .scan
92 diamond 5001
.notfound:
1494 Lrz 5002
        mov     dword [esp+32], 1
1055 Galkov 5003
        ret
92 diamond 5004
.found:
1055 Galkov 5005
        mov     ecx, [eax]
5006
        jecxz   @f
5007
        mov     edx, [eax+12]
5008
        mov     [ecx+12], edx
92 diamond 5009
@@:
1055 Galkov 5010
        mov     ecx, [eax+12]
5011
        mov     edx, [eax]
5012
        mov     [ecx], edx
5013
        xor     edx, edx
5014
        mov     [eax+4], edx
5015
        mov     [eax+8], edx
5016
        mov     [eax+12], edx
5017
        mov     [eax], edx
1494 Lrz 5018
        mov     [esp+32], edx
1055 Galkov 5019
        ret
2987 Serge 5020
;-----------------------------------------------------------------------------
5021
align 4
5022
.6:
5023
        pushfd
5024
        cli
5025
        mov     eax, [PID_lock_input]
5026
        test    eax, eax
5027
        jnz     @f
5028
; get current PID
5029
        mov     eax, [CURRENT_TASK]
5030
        shl     eax, 5
5031
        mov     eax, [eax+CURRENT_TASK+TASKDATA.pid]
5032
; set current PID for lock input
5033
        mov     [PID_lock_input], eax
5034
@@:
5035
        popfd
5036
        ret
5037
;-----------------------------------------------------------------------------
5038
align 4
5039
.7:
5040
        mov     eax, [PID_lock_input]
5041
        test    eax, eax
5042
        jz      @f
5043
; get current PID
5044
        mov     ebx, [CURRENT_TASK]
5045
        shl     ebx, 5
5046
        mov     ebx, [ebx+CURRENT_TASK+TASKDATA.pid]
5047
; compare current lock input with current PID
5048
        cmp     ebx, eax
5049
        jne     @f
92 diamond 5050
 
2987 Serge 5051
        xor     eax, eax
5052
        mov     [PID_lock_input], eax
5053
@@:
5054
        ret
5055
;-----------------------------------------------------------------------------
5056
uglobal
5057
  PID_lock_input dd 0x0
5058
endg
1497 Lrz 5059
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5060
;; 61 sys function.                                                ;;
5061
;; in eax=61,ebx in [1..3]                                         ;;
5062
;; out eax                                                         ;;
5063
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5064
iglobal
1 ha 5065
align 4
1497 Lrz 5066
f61call:
5067
           dd sys_gs.1   ; resolution
5068
           dd sys_gs.2   ; bits per pixel
5069
           dd sys_gs.3   ; bytes per scanline
5070
endg
1 ha 5071
 
1497 Lrz 5072
 
5073
align 4
5074
 
1055 Galkov 5075
sys_gs:                         ; direct screen access
2434 Serge 5076
        dec     ebx
5077
        cmp     ebx, 2
5078
        ja      .not_support
5079
        jmp     dword [f61call+ebx*4]
1497 Lrz 5080
.not_support:
2434 Serge 5081
        or      [esp+32], dword -1
1497 Lrz 5082
        ret
1 ha 5083
 
1497 Lrz 5084
 
5085
.1:                             ; resolution
5565 serge 5086
        mov     eax, [_display.width]
2434 Serge 5087
        shl     eax, 16
5565 serge 5088
        mov     ax, word [_display.height]
2434 Serge 5089
        mov     [esp+32], eax
5090
        ret
5091
.2:                             ; bits per pixel
5201 serge 5092
        mov     eax, [_display.bits_per_pixel]
2434 Serge 5093
        mov     [esp+32], eax
5094
        ret
1497 Lrz 5095
.3:                             ; bytes per scanline
5565 serge 5096
        mov     eax, [_display.lfb_pitch]
2434 Serge 5097
        mov     [esp+32], eax
5098
        ret
1 ha 5099
 
5100
align 4  ;  system functions
5101
 
1055 Galkov 5102
syscall_setpixel:                       ; SetPixel
1 ha 5103
 
1055 Galkov 5104
        mov     eax, ebx
5105
        mov     ebx, ecx
5106
        mov     ecx, edx
5107
        mov     edx, [TASK_BASE]
5108
        add     eax, [edx-twdw+WDATA.box.left]
5109
        add     ebx, [edx-twdw+WDATA.box.top]
5110
        mov     edi, [current_slot]
5111
        add     eax, [edi+APPDATA.wnd_clientbox.left]
5112
        add     ebx, [edi+APPDATA.wnd_clientbox.top]
5113
        xor     edi, edi ; no force
2434 Serge 5114
        and     ecx, 0xFBFFFFFF  ;negate 0x04000000 save to mouseunder area
2465 Serge 5115
;        jmp     [putpixel]
5116
        jmp     __sys_putpixel
1 ha 5117
 
5118
align 4
5119
 
1055 Galkov 5120
syscall_writetext:                      ; WriteText
1 ha 5121
 
2434 Serge 5122
        mov     eax, [TASK_BASE]
5123
        mov     ebp, [eax-twdw+WDATA.box.left]
5124
        push    esi
5125
        mov     esi, [current_slot]
5126
        add     ebp, [esi+APPDATA.wnd_clientbox.left]
5127
        shl     ebp, 16
5128
        add     ebp, [eax-twdw+WDATA.box.top]
5129
        add     bp, word[esi+APPDATA.wnd_clientbox.top]
5130
        pop     esi
3500 Serge 5131
        test    ecx, 0x08000000  ; redirect the output to the user area
5132
        jnz     @f
2434 Serge 5133
        add     ebx, ebp
3500 Serge 5134
align 4
5135
@@:
2434 Serge 5136
        mov     eax, edi
2987 Serge 5137
        test    ecx, 0x08000000  ; redirect the output to the user area
5138
        jnz     dtext
2434 Serge 5139
        xor     edi, edi
5140
        jmp     dtext
1 ha 5141
 
5142
align 4
5143
 
1055 Galkov 5144
syscall_drawrect:                       ; DrawRect
1 ha 5145
 
1055 Galkov 5146
        mov     edi, edx ; color + gradient
5147
        and     edi, 0x80FFFFFF
5148
        test    bx, bx  ; x.size
5149
        je      .drectr
5150
        test    cx, cx ; y.size
5151
        je      .drectr
1 ha 5152
 
1055 Galkov 5153
        mov     eax, ebx ; bad idea
5154
        mov     ebx, ecx
1 ha 5155
 
1055 Galkov 5156
        movzx   ecx, ax ; ecx - x.size
5157
        shr     eax, 16 ; eax - x.coord
5158
        movzx   edx, bx ; edx - y.size
5159
        shr     ebx, 16 ; ebx - y.coord
5160
        mov     esi, [current_slot]
1 ha 5161
 
1055 Galkov 5162
        add     eax, [esi + APPDATA.wnd_clientbox.left]
5163
        add     ebx, [esi + APPDATA.wnd_clientbox.top]
5164
        add     ecx, eax
5165
        add     edx, ebx
2465 Serge 5166
;        jmp     [drawbar]
5167
        jmp     vesa20_drawbar
671 Ghost 5168
.drectr:
1055 Galkov 5169
        ret
1 ha 5170
 
5171
align 4
1055 Galkov 5172
syscall_getscreensize:                  ; GetScreenSize
5565 serge 5173
        mov     ax, word [_display.width]
5174
        dec     ax
1055 Galkov 5175
        shl     eax, 16
5565 serge 5176
        mov     ax, word [_display.height]
5177
        dec     ax
1055 Galkov 5178
        mov     [esp + 32], eax
5179
        ret
5201 serge 5180
;-----------------------------------------------------------------------------
671 Ghost 5181
align 4
5201 serge 5182
syscall_cdaudio:
5183
; ECX - position of CD/DVD-drive
5184
; from 0=Primary Master to 3=Secondary Slave for first IDE contr.
5185
; from 4=Primary Master to 7=Secondary Slave for second IDE contr.
5186
; from 8=Primary Master to 11=Secondary Slave for third IDE contr.
5187
        cmp     ecx, 11
5188
        ja      .exit
671 Ghost 5189
 
5201 serge 5190
        mov     eax, ecx
5191
        shr     eax, 2
5192
        lea     eax, [eax*5]
5193
        mov     al, [eax+DRIVE_DATA+1]
1 ha 5194
 
5201 serge 5195
        push    ecx ebx
5196
        mov     ebx, ecx
5197
        and     ebx, 11b
5198
        shl     ebx, 1
5199
        mov     cl, 6
5200
        sub     cl, bl
5201
        shr     al, cl
5202
        test    al, 2 ; it's not an ATAPI device
5203
        pop     ebx ecx
5204
 
5205
        jz      .exit
5206
 
1290 Lrz 5207
        cmp     ebx, 4
5201 serge 5208
        je      .eject
5209
 
1290 Lrz 5210
        cmp     ebx, 5
5201 serge 5211
        je      .load
5212
;--------------------------------------
5213
.exit:
5214
        ret
5215
;--------------------------------------
588 diamond 5216
.load:
1055 Galkov 5217
        call    .reserve
5218
        call    LoadMedium
2434 Serge 5219
        jmp     .free
5201 serge 5220
;--------------------------------------
588 diamond 5221
.eject:
1055 Galkov 5222
        call    .reserve
5223
        call    clear_CD_cache
5224
        call    allow_medium_removal
5225
        call    EjectMedium
2434 Serge 5226
        jmp     .free
5201 serge 5227
;--------------------------------------
588 diamond 5228
.reserve:
1055 Galkov 5229
        call    reserve_cd
5201 serge 5230
 
5231
        mov     ebx, ecx
5232
        inc     ebx
5233
        mov     [cdpos], ebx
5234
 
1290 Lrz 5235
        mov     eax, ecx
1055 Galkov 5236
        shr     eax, 1
5237
        and     eax, 1
5238
        inc     eax
5239
        mov     [ChannelNumber], ax
1290 Lrz 5240
        mov     eax, ecx
1055 Galkov 5241
        and     eax, 1
5242
        mov     [DiskNumber], al
5243
        call    reserve_cd_channel
5244
        ret
5201 serge 5245
;--------------------------------------
588 diamond 5246
.free:
1055 Galkov 5247
        call    free_cd_channel
5248
        and     [cd_status], 0
5249
        ret
2987 Serge 5250
;-----------------------------------------------------------------------------
1 ha 5251
align 4
2987 Serge 5252
syscall_getpixel_WinMap:                       ; GetPixel WinMap
5565 serge 5253
        cmp     ebx, [_display.width]
5254
        jb      @f
5255
        cmp     ecx, [_display.height]
5256
        jb      @f
2987 Serge 5257
        xor     eax, eax
5258
        jmp     .store
5259
;--------------------------------------
5260
align 4
5261
@@:
5262
        mov     eax, [d_width_calc_area + ecx*4]
5565 serge 5263
        add     eax, [_display.win_map]
2987 Serge 5264
        movzx   eax, byte[eax+ebx]        ; get value for current point
5265
;--------------------------------------
5266
align 4
5267
.store:
5268
        mov     [esp + 32], eax
5269
        ret
5270
;-----------------------------------------------------------------------------
5271
align 4
1055 Galkov 5272
syscall_getpixel:                       ; GetPixel
5565 serge 5273
        mov     ecx, [_display.width]
2434 Serge 5274
        xor     edx, edx
5275
        mov     eax, ebx
5276
        div     ecx
5277
        mov     ebx, edx
5278
        xchg    eax, ebx
5279
        and     ecx, 0xFBFFFFFF  ;negate 0x04000000 use mouseunder area
5280
        call    dword [GETPIXEL]; eax - x, ebx - y
5281
        mov     [esp + 32], ecx
5282
        ret
2987 Serge 5283
;-----------------------------------------------------------------------------
921 mario79 5284
align 4
5285
syscall_getarea:
5286
;eax = 36
1055 Galkov 5287
;ebx = pointer to bufer for img BBGGRRBBGGRR...
5288
;ecx = [size x]*65536 + [size y]
5289
;edx = [start x]*65536 + [start y]
2434 Serge 5290
        pushad
5291
        mov     edi, ebx
5292
        mov     eax, edx
5293
        shr     eax, 16
5294
        mov     ebx, edx
5295
        and     ebx, 0xffff
5296
        dec     eax
5297
        dec     ebx
921 mario79 5298
     ; eax - x, ebx - y
2434 Serge 5299
        mov     edx, ecx
1638 serge 5300
 
2434 Serge 5301
        shr     ecx, 16
5302
        and     edx, 0xffff
5303
        mov     esi, ecx
921 mario79 5304
     ; ecx - size x, edx - size y
1638 serge 5305
 
2434 Serge 5306
        mov     ebp, edx
5307
        dec     ebp
5308
        lea     ebp, [ebp*3]
1638 serge 5309
 
2434 Serge 5310
        imul    ebp, esi
1638 serge 5311
 
2434 Serge 5312
        mov     esi, ecx
5313
        dec     esi
5314
        lea     esi, [esi*3]
1638 serge 5315
 
2434 Serge 5316
        add     ebp, esi
5317
        add     ebp, edi
927 mario79 5318
 
2434 Serge 5319
        add     ebx, edx
2987 Serge 5320
;--------------------------------------
5321
align 4
921 mario79 5322
.start_y:
2434 Serge 5323
        push    ecx edx
2987 Serge 5324
;--------------------------------------
5325
align 4
921 mario79 5326
.start_x:
2434 Serge 5327
        push    eax ebx ecx
5328
        add     eax, ecx
927 mario79 5329
 
2434 Serge 5330
        and     ecx, 0xFBFFFFFF  ;negate 0x04000000 use mouseunder area
5331
        call    dword [GETPIXEL]; eax - x, ebx - y
1638 serge 5332
 
2434 Serge 5333
        mov     [ebp], cx
5334
        shr     ecx, 16
5335
        mov     [ebp+2], cl
921 mario79 5336
 
2434 Serge 5337
        pop     ecx ebx eax
5338
        sub     ebp, 3
5339
        dec     ecx
5340
        jnz     .start_x
5341
        pop     edx ecx
5342
        dec     ebx
5343
        dec     edx
5344
        jnz     .start_y
5345
        popad
5346
        ret
2987 Serge 5347
;-----------------------------------------------------------------------------
5348
align 4
5349
syscall_putarea_backgr:
5350
;eax = 25
5351
;ebx = pointer to bufer for img BBGGRRBBGGRR...
5352
;ecx = [size x]*65536 + [size y]
5353
;edx = [start x]*65536 + [start y]
5354
        pushad
5355
        mov     edi, ebx
5356
        mov     eax, edx
5357
        shr     eax, 16
5358
        mov     ebx, edx
5359
        and     ebx, 0xffff
5360
        dec     eax
5361
        dec     ebx
5362
; eax - x, ebx - y
5363
        mov     edx, ecx
5364
        shr     ecx, 16
5365
        and     edx, 0xffff
5366
        mov     esi, ecx
5367
; ecx - size x, edx - size y
5368
        mov     ebp, edx
5369
        dec     ebp
5370
        shl     ebp, 2
921 mario79 5371
 
2987 Serge 5372
        imul    ebp, esi
5373
 
5374
        mov     esi, ecx
5375
        dec     esi
5376
        shl     esi, 2
5377
 
5378
        add     ebp, esi
5379
        add     ebp, edi
5380
 
5381
        add     ebx, edx
5382
;--------------------------------------
1 ha 5383
align 4
2987 Serge 5384
.start_y:
5385
        push    ecx edx
5386
;--------------------------------------
5387
align 4
5388
.start_x:
5389
        push    eax ecx
5390
        add     eax, ecx
1 ha 5391
 
2987 Serge 5392
        mov     ecx, [ebp]
5393
        rol     ecx, 8
5394
        test    cl, cl        ; transparensy = 0
5395
        jz      .no_put
5396
 
5397
        xor     cl, cl
5398
        ror     ecx, 8
5399
 
5400
        pushad
5401
        mov     edx, [d_width_calc_area + ebx*4]
5565 serge 5402
        add     edx, [_display.win_map]
2987 Serge 5403
        movzx   edx, byte [eax+edx]
5404
        cmp     dl, byte 1
5405
        jne     @f
5406
 
5407
        call    dword [PUTPIXEL]; eax - x, ebx - y
5408
;--------------------------------------
5409
align 4
5410
@@:
5411
        popad
5412
;--------------------------------------
5413
align 4
5414
.no_put:
5415
        pop     ecx eax
5416
 
5417
        sub     ebp, 4
5418
        dec     ecx
5419
        jnz     .start_x
5420
 
5421
        pop     edx ecx
5422
        dec     ebx
5423
        dec     edx
5424
        jnz     .start_y
5425
 
5426
        popad
5427
        ret
5428
;-----------------------------------------------------------------------------
5429
align 4
1055 Galkov 5430
syscall_drawline:                       ; DrawLine
1 ha 5431
 
1055 Galkov 5432
        mov     edi, [TASK_BASE]
5433
        movzx   eax, word[edi-twdw+WDATA.box.left]
5434
        mov     ebp, eax
5435
        mov     esi, [current_slot]
5436
        add     ebp, [esi+APPDATA.wnd_clientbox.left]
5437
        add     ax, word[esi+APPDATA.wnd_clientbox.left]
2434 Serge 5438
        add     ebp, ebx
1055 Galkov 5439
        shl     eax, 16
5440
        movzx   ebx, word[edi-twdw+WDATA.box.top]
5441
        add     eax, ebp
5442
        mov     ebp, ebx
5443
        add     ebp, [esi+APPDATA.wnd_clientbox.top]
5444
        add     bx, word[esi+APPDATA.wnd_clientbox.top]
5445
        add     ebp, ecx
5446
        shl     ebx, 16
5447
        xor     edi, edi
5448
        add     ebx, ebp
5449
        mov     ecx, edx
2465 Serge 5450
;        jmp     [draw_line]
5451
        jmp     __sys_draw_line
1 ha 5452
 
5453
 
5454
align 4
1055 Galkov 5455
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
1 ha 5456
 
2434 Serge 5457
        call    r_f_port_area
5458
        mov     [esp+32], eax
5459
        ret
1 ha 5460
 
5461
align 4
1055 Galkov 5462
syscall_threads:                        ; CreateThreads
1369 Lrz 5463
;
4265 Serge 5464
;   ecx=thread entry point
5465
;   edx=thread stack pointer
1369 Lrz 5466
;
5467
; on return : eax = pid
1 ha 5468
 
4265 Serge 5469
        xor     ebx, ebx
2434 Serge 5470
        call    new_sys_threads
1369 Lrz 5471
 
2434 Serge 5472
        mov     [esp+32], eax
5473
        ret
1 ha 5474
 
5475
align 4
5476
 
375 Ghost 5477
paleholder:
1055 Galkov 5478
        ret
2439 Serge 5479
;------------------------------------------------------------------------------
757 serge 5480
align 4
2439 Serge 5481
calculate_fast_getting_offset_for_WinMapAddress:
5482
; calculate data area for fast getting offset to _WinMapAddress
2465 Serge 5483
        xor     eax, eax
2439 Serge 5484
        mov     ecx, [_display.height]
5485
        mov     edi, d_width_calc_area
5486
        cld
5487
@@:
5488
        stosd
5489
        add     eax, [_display.width]
5490
        dec     ecx
5491
        jnz     @r
5492
        ret
5493
;------------------------------------------------------------------------------
5494
align 4
2987 Serge 5495
calculate_fast_getting_offset_for_LFB:
5496
; calculate data area for fast getting offset to LFB
5497
        xor     eax, eax
5498
        mov     ecx, [_display.height]
5499
        mov     edi, BPSLine_calc_area
5500
        cld
5501
@@:
5502
        stosd
5565 serge 5503
        add     eax, [_display.lfb_pitch]
2987 Serge 5504
        dec     ecx
5505
        jnz     @r
5506
        ret
5507
;------------------------------------------------------------------------------
5508
align 4
757 serge 5509
set_screen:
2987 Serge 5510
; in:
5511
; eax - new Screen_Max_X
5512
; ecx - new BytesPerScanLine
5513
; edx - new Screen_Max_Y
709 diamond 5514
 
1055 Galkov 5515
        pushfd
5516
        cli
757 serge 5517
 
5565 serge 5518
        mov     [_display.lfb_pitch], ecx
757 serge 5519
 
2434 Serge 5520
        mov     [screen_workarea.right], eax
5521
        mov     [screen_workarea.bottom], edx
1300 serge 5522
 
2434 Serge 5523
        push    ebx
5524
        push    esi
5525
        push    edi
1300 serge 5526
 
5527
        pushad
5528
 
2987 Serge 5529
        cmp     [do_not_touch_winmap], 1
5530
        je      @f
5531
 
5565 serge 5532
        stdcall kernel_free, [_display.win_map]
1300 serge 5533
 
2434 Serge 5534
        mov     eax, [_display.width]
5535
        mul     [_display.height]
5565 serge 5536
        mov     [_display.win_map_size], eax
1300 serge 5537
 
5538
        stdcall kernel_alloc, eax
5565 serge 5539
        mov     [_display.win_map], eax
2434 Serge 5540
        test    eax, eax
5541
        jz      .epic_fail
2987 Serge 5542
; store for f.18.24
5543
        mov     eax, [_display.width]
5544
        mov     [display_width_standard], eax
1300 serge 5545
 
2987 Serge 5546
        mov     eax, [_display.height]
5547
        mov     [display_height_standard], eax
5548
@@:
2439 Serge 5549
        call    calculate_fast_getting_offset_for_WinMapAddress
2987 Serge 5550
; for Qemu or non standart video cards
5551
; Unfortunately [BytesPerScanLine] does not always
5552
;                             equal to [_display.width] * [ScreenBPP] / 8
5553
        call    calculate_fast_getting_offset_for_LFB
1300 serge 5554
        popad
5555
 
1055 Galkov 5556
        call    repos_windows
2434 Serge 5557
        xor     eax, eax
5558
        xor     ebx, ebx
5565 serge 5559
        mov     ecx, [_display.width]
5560
        mov     edx, [_display.height]
5561
        dec     ecx
5562
        dec     edx
1055 Galkov 5563
        call    calculatescreen
2434 Serge 5564
        pop     edi
5565
        pop     esi
5566
        pop     ebx
757 serge 5567
 
1055 Galkov 5568
        popfd
5569
        ret
757 serge 5570
 
1300 serge 5571
.epic_fail:
5572
        hlt                     ; Houston, we've had a problem
5573
 
76 mario79 5574
; --------------- APM ---------------------
1330 Lrz 5575
uglobal
2434 Serge 5576
apm_entry       dp      0
5577
apm_vf          dd      0
1330 Lrz 5578
endg
5579
 
1 ha 5580
align 4
76 mario79 5581
sys_apm:
2434 Serge 5582
        xor     eax, eax
5583
        cmp     word [apm_vf], ax       ; Check APM BIOS enable
5584
        jne     @f
5585
        inc     eax
5586
        or      dword [esp + 44], eax   ; error
5587
        add     eax, 7
5588
        mov     dword [esp + 32], eax   ; 32-bit protected-mode interface not supported
5589
        ret
164 serge 5590
 
465 serge 5591
@@:
2434 Serge 5592
;       xchg    eax, ecx
5593
;       xchg    ebx, ecx
164 serge 5594
 
2434 Serge 5595
        cmp     dx, 3
5596
        ja      @f
5597
        and     [esp + 44], byte 0xfe    ; emulate func 0..3 as func 0
5598
        mov     eax, [apm_vf]
5599
        mov     [esp + 32], eax
5600
        shr     eax, 16
5601
        mov     [esp + 28], eax
5602
        ret
78 diamond 5603
 
465 serge 5604
@@:
5605
 
2434 Serge 5606
        mov     esi, [master_tab+(OS_BASE shr 20)]
5607
        xchg    [master_tab], esi
5608
        push    esi
5609
        mov     edi, cr3
5610
        mov     cr3, edi                ;flush TLB
465 serge 5611
 
2434 Serge 5612
        call    pword [apm_entry]       ;call APM BIOS
465 serge 5613
 
2434 Serge 5614
        xchg    eax, [esp]
5615
        mov     [master_tab], eax
5616
        mov     eax, cr3
5617
        mov     cr3, eax
5618
        pop     eax
465 serge 5619
 
2434 Serge 5620
        mov     [esp + 4 ], edi
5621
        mov     [esp + 8], esi
5622
        mov     [esp + 20], ebx
5623
        mov     [esp + 24], edx
5624
        mov     [esp + 28], ecx
5625
        mov     [esp + 32], eax
5626
        setc    al
5627
        and     [esp + 44], byte 0xfe
5628
        or      [esp + 44], al
5629
        ret
76 mario79 5630
; -----------------------------------------
1 ha 5631
 
76 mario79 5632
align 4
5633
 
1055 Galkov 5634
undefined_syscall:                      ; Undefined system call
2434 Serge 5635
        mov     [esp + 32], dword -1
5636
        ret
1 ha 5637
 
5638
 
3626 Serge 5639
if ~ lang eq sp
5640
diff16 "end of .text segment",0,$
5641
end if
5642
 
465 serge 5643
include "data32.inc"
1 ha 5644
 
465 serge 5645
__REV__ = __REV
1 ha 5646
 
3500 Serge 5647
if ~ lang eq sp
41 mikedld 5648
diff16 "end of kernel code",0,$
3500 Serge 5649
end if