Subversion Repositories Kolibri OS

Rev

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