Subversion Repositories Kolibri OS

Rev

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

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