Subversion Repositories Kolibri OS

Rev

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

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