Subversion Repositories Kolibri OS

Rev

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

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