Subversion Repositories Kolibri OS

Rev

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

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