Subversion Repositories Kolibri OS

Rev

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

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