Subversion Repositories Kolibri OS

Rev

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

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