Subversion Repositories Kolibri OS

Rev

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

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