Subversion Repositories Kolibri OS

Rev

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