Subversion Repositories Kolibri OS

Rev

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

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