Subversion Repositories Kolibri OS

Rev

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

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