Subversion Repositories Kolibri OS

Rev

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