Subversion Repositories Kolibri OS

Rev

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