Subversion Repositories Kolibri OS

Rev

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

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