Subversion Repositories Kolibri OS

Rev

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

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