Subversion Repositories Kolibri OS

Rev

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

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