Subversion Repositories Kolibri OS

Rev

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