Subversion Repositories Kolibri OS

Rev

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

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