Subversion Repositories Kolibri OS

Rev

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

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