Subversion Repositories Kolibri OS

Rev

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

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