Subversion Repositories Kolibri OS

Rev

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