Subversion Repositories Kolibri OS

Rev

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

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