Subversion Repositories Kolibri OS

Rev

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