Subversion Repositories Kolibri OS

Rev

Rev 1055 | Rev 1063 | 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: 1056 $
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
 
1056 Galkov 457
           call build_interrupt_table ;lidt is executed
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
1056 Galkov 1299
   hexletters = __fdo_hexdigits
1 ha 1300
     add   edx,hexletters
1301
     mov   dl,[edx]
1302
     mov   [edi],dl
1303
     dec   edi
1304
     loop  d_hexnum
1305
     pop   eax
652 mario79 1306
     call  normalize_number
1 ha 1307
     call  draw_num_text
1308
     add   esp,64
1309
     popad
1310
     ret
1311
   no_display_hexnum:
1312
 
1055 Galkov 1313
     cmp   ah,0x02               ; BINARY
1 ha 1314
     jne   no_display_binnum
1315
     shr   eax,16
655 mario79 1316
     and   eax,0xC03f
652 mario79 1317
;     and   eax,0x3f
1318
     push  eax
75 diamond 1319
     and   eax,0x3f
1 ha 1320
     mov   edi,esp
194 diamond 1321
     add   edi,4+64-1
1 ha 1322
     mov   ecx,eax
1323
     mov   eax,ebx
1324
     mov   ebx,2
1325
   d_binnum:
1326
     xor   edx,edx
655 mario79 1327
     call  division_64_bits
1 ha 1328
     div   ebx
1329
     add   dl,48
1330
     mov   [edi],dl
1331
     dec   edi
1332
     loop  d_binnum
1333
     pop   eax
652 mario79 1334
     call  normalize_number
1 ha 1335
     call  draw_num_text
1336
     add   esp,64
1337
     popad
1338
     ret
1339
   no_display_binnum:
1340
 
1341
     add   esp,64
1342
     popad
1343
     ret
1344
 
652 mario79 1345
normalize_number:
1346
     test  ah,0x80
1347
     jz   .continue
1348
     mov  ecx,48
1349
     and   eax,0x3f
1350
@@:
1351
     inc   edi
1352
     cmp   [edi],cl
1353
     jne   .continue
1354
     dec   eax
1355
     cmp   eax,1
665 diamond 1356
     ja    @r
1357
     mov   al,1
652 mario79 1358
.continue:
1359
     and   eax,0x3f
1360
     ret
1 ha 1361
 
655 mario79 1362
division_64_bits:
1363
     test  [esp+1+4],byte 0x40
1364
     jz   .continue
1365
     push  eax
1366
     mov   eax,ebp
1367
     div   ebx
1368
     mov   ebp,eax
1369
     pop   eax
1370
.continue:
1371
     ret
652 mario79 1372
 
1 ha 1373
draw_num_text:
684 diamond 1374
     mov   esi,eax
1375
     mov   edx,64+4
1376
     sub   edx,eax
1377
     add   edx,esp
1378
     mov   ebx,[esp+64+32-8+4]
1379
; add window start x & y
1380
     mov   ecx,[TASK_BASE]
465 serge 1381
 
1382
     mov   edi,[CURRENT_TASK]
1383
     shl   edi,8
1384
 
684 diamond 1385
     mov   eax,[ecx-twdw+WDATA.box.left]
1386
     add   eax,[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1387
     shl   eax,16
1388
     add   eax,[ecx-twdw+WDATA.box.top]
1389
     add   eax,[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1390
     add   ebx,eax
1391
     mov   ecx,[esp+64+32-12+4]
1055 Galkov 1392
        and     ecx, not 0x80000000     ; force counted string
1393
        mov     eax, [esp+64+8]         ; background color (if given)
1394
        mov     edi, [esp+64+4]
139 diamond 1395
     jmp   dtext
1 ha 1396
 
1397
align 4
1398
 
1399
sys_setup:
1400
 
1401
; 1=roland mpu midi base , base io address
1402
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1403
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1404
; 5=system language, 1eng 2fi 3ger 4rus
1405
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1406
; 8=fat32 partition in hd
1407
; 9
1408
; 10 = sound dma channel
1409
; 11 = enable lba read
1410
; 12 = enable pci access
1411
 
1412
 
1413
     mov  [esp+36],dword 0
1055 Galkov 1414
     cmp  eax,1                      ; MIDI
1 ha 1415
     jnz  nsyse1
1416
     cmp  ebx,0x100
1417
     jb   nsyse1
1418
     mov  edx,65535
1419
     cmp  edx,ebx
1420
     jb   nsyse1
1421
     mov  [midi_base],bx
1422
     mov  word [mididp],bx
1423
     inc  bx
1424
     mov  word [midisp],bx
1425
     ret
1426
 
283 diamond 1427
iglobal
1 ha 1428
midi_base dw 0
283 diamond 1429
endg
1 ha 1430
 
1431
   nsyse1:
1432
 
1055 Galkov 1433
     cmp  eax,2                      ; KEYBOARD
1 ha 1434
     jnz  nsyse2
1435
     cmp  ebx,1
1436
     jnz  kbnobase
379 serge 1437
     mov  edi,[TASK_BASE]
115 poddubny 1438
     add  ecx,[edi+TASKDATA.mem_start]
1 ha 1439
     mov  eax,ecx
1440
     mov  ebx,keymap
1441
     mov  ecx,128
1442
     call memmove
1443
     ret
1444
   kbnobase:
1445
     cmp  ebx,2
1446
     jnz  kbnoshift
379 serge 1447
     mov  edi,[TASK_BASE]
115 poddubny 1448
     add  ecx,[edi+TASKDATA.mem_start]
1 ha 1449
     mov  eax,ecx
1450
     mov  ebx,keymap_shift
1451
     mov  ecx,128
1452
     call memmove
1453
     ret
1454
   kbnoshift:
1455
     cmp  ebx,3
1456
     jne  kbnoalt
379 serge 1457
     mov  edi,[TASK_BASE]
115 poddubny 1458
     add  ecx,[edi+TASKDATA.mem_start]
1 ha 1459
     mov  eax,ecx
1460
     mov  ebx,keymap_alt
1461
     mov  ecx,128
1462
     call memmove
1463
     ret
1464
   kbnoalt:
1465
     cmp  ebx,9
1466
     jnz  kbnocountry
1467
     mov  word [keyboard],cx
1468
     ret
1469
   kbnocountry:
1470
     mov  [esp+36],dword 1
1471
     ret
1472
   nsyse2:
1055 Galkov 1473
     cmp  eax,3                      ; CD
802 serge 1474
     jnz  nsyse4
75 diamond 1475
     test ebx,ebx
1476
     jz   nosesl
1477
     cmp  ebx, 4
1478
     ja   nosesl
1 ha 1479
     mov  [cd_base],bl
1480
     cmp  ebx,1
1481
     jnz  noprma
1482
     mov  [cdbase],0x1f0
1483
     mov  [cdid],0xa0
1484
   noprma:
1485
     cmp  ebx,2
1486
     jnz  noprsl
1487
     mov  [cdbase],0x1f0
1488
     mov  [cdid],0xb0
1489
   noprsl:
1490
     cmp  ebx,3
1491
     jnz  nosema
1492
     mov  [cdbase],0x170
1493
     mov  [cdid],0xa0
1494
   nosema:
1495
     cmp  ebx,4
1496
     jnz  nosesl
1497
     mov  [cdbase],0x170
1498
     mov  [cdid],0xb0
1499
   nosesl:
1500
     ret
1501
 
1502
cd_base db 0
1503
 
1504
   nsyse4:
1505
 
1055 Galkov 1506
     cmp  eax,5                      ; SYSTEM LANGUAGE
1 ha 1507
     jnz  nsyse5
1508
     mov  [syslang],ebx
1509
     ret
1510
   nsyse5:
1511
 
1055 Galkov 1512
     cmp  eax,7                      ; HD BASE
1 ha 1513
     jne  nsyse7
75 diamond 1514
     test ebx,ebx
1515
     jz   nosethd
1516
     cmp  ebx,4
1517
     ja   nosethd
1 ha 1518
     mov  [hd_base],bl
1519
     cmp  ebx,1
1520
     jnz  noprmahd
1521
     mov  [hdbase],0x1f0
1522
     mov  [hdid],0x0
1523
     mov  [hdpos],1
1524
;     call set_FAT32_variables
1525
   noprmahd:
1526
     cmp  ebx,2
1527
     jnz  noprslhd
1528
     mov  [hdbase],0x1f0
1529
     mov  [hdid],0x10
1530
     mov  [hdpos],2
1531
;     call set_FAT32_variables
1532
   noprslhd:
1533
     cmp  ebx,3
1534
     jnz  nosemahd
1535
     mov  [hdbase],0x170
1536
     mov  [hdid],0x0
1537
     mov  [hdpos],3
1538
;     call set_FAT32_variables
1539
   nosemahd:
1540
     cmp  ebx,4
1541
     jnz  noseslhd
1542
     mov  [hdbase],0x170
1543
     mov  [hdid],0x10
1544
     mov  [hdpos],4
1545
;     call set_FAT32_variables
1546
   noseslhd:
1547
    call  reserve_hd1
321 diamond 1548
    call  reserve_hd_channel
1549
    call  free_hd_channel
1055 Galkov 1550
    mov   [hd1_status],0        ; free
75 diamond 1551
   nosethd:
1 ha 1552
     ret
1553
 
283 diamond 1554
iglobal
1 ha 1555
hd_base db 0
283 diamond 1556
endg
1 ha 1557
 
802 serge 1558
nsyse7:
1 ha 1559
 
1055 Galkov 1560
     cmp  eax,8                      ; HD PARTITION
1 ha 1561
     jne  nsyse8
1562
     mov  [fat32part],ebx
1563
;     call set_FAT32_variables
1564
    call  reserve_hd1
321 diamond 1565
    call  reserve_hd_channel
1566
    call  free_hd_channel
1 ha 1567
     pusha
1568
     call  choice_necessity_partition_1
1569
     popa
1055 Galkov 1570
    mov   [hd1_status],0        ; free
1 ha 1571
     ret
1572
 
802 serge 1573
nsyse8:
1055 Galkov 1574
     cmp  eax,11                     ; ENABLE LBA READ
1 ha 1575
     jne  no_set_lba_read
1576
     and  ebx,1
1577
     mov  [lba_read_enabled],ebx
1578
     ret
1579
 
802 serge 1580
no_set_lba_read:
1055 Galkov 1581
     cmp  eax,12                     ; ENABLE PCI ACCESS
1 ha 1582
     jne  no_set_pci_access
1583
     and  ebx,1
1584
     mov  [pci_access_enabled],ebx
1585
     ret
1586
   no_set_pci_access:
1587
 
1588
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1589
include 'vmodeint.inc'
1590
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1591
 
75 diamond 1592
sys_setup_err:
1 ha 1593
     mov  [esp+36],dword -1
1594
     ret
1595
 
1596
align 4
1597
 
1598
sys_getsetup:
1599
 
1600
; 1=roland mpu midi base , base io address
1601
; 2=keyboard   1, base kaybap 2, shift keymap, 9 country 1eng 2fi 3ger 4rus
1602
; 3=cd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1603
; 5=system language, 1eng 2fi 3ger 4rus
1604
; 7=hd base    1, pri.master 2, pri slave 3 sec master, 4 sec slave
1605
; 8=fat32 partition in hd
1606
; 9=get hs timer tic
1607
 
1608
     cmp  eax,1
1609
     jne  ngsyse1
1610
     movzx eax,[midi_base]
1611
     mov  [esp+36],eax
1612
     ret
802 serge 1613
ngsyse1:
1 ha 1614
 
1615
     cmp  eax,2
1616
     jne  ngsyse2
1617
     cmp  ebx,1
1618
     jnz  kbnobaseret
379 serge 1619
     mov  edi,[TASK_BASE]
115 poddubny 1620
     add  ecx,[edi+TASKDATA.mem_start]
1 ha 1621
     mov  ebx,ecx
1622
     mov  eax,keymap
1623
     mov  ecx,128
1624
     call memmove
1625
     ret
802 serge 1626
kbnobaseret:
1 ha 1627
     cmp  ebx,2
1628
     jnz  kbnoshiftret
379 serge 1629
     mov  edi,[TASK_BASE]
115 poddubny 1630
     add  ecx,[edi+TASKDATA.mem_start]
1 ha 1631
     mov  ebx,ecx
1632
     mov  eax,keymap_shift
1633
     mov  ecx,128
1634
     call memmove
1635
     ret
802 serge 1636
kbnoshiftret:
1 ha 1637
     cmp  ebx,3
1638
     jne  kbnoaltret
379 serge 1639
     mov  edi,[TASK_BASE]
115 poddubny 1640
     add  ecx,[edi+TASKDATA.mem_start]
1 ha 1641
     mov  ebx,ecx
1642
     mov  eax,keymap_alt
1643
     mov  ecx,128
1644
     call memmove
1645
     ret
802 serge 1646
kbnoaltret:
1 ha 1647
     cmp  ebx,9
1648
     jnz  ngsyse2
1649
     movzx eax,word [keyboard]
1650
     mov  [esp+36],eax
1651
     ret
802 serge 1652
ngsyse2:
1 ha 1653
 
1055 Galkov 1654
         cmp  eax,3
1655
         jnz  ngsyse3
1656
         movzx eax,[cd_base]
1657
         mov  [esp+36],eax
1658
         ret
802 serge 1659
ngsyse3:
1055 Galkov 1660
         cmp  eax,5
1661
         jnz  ngsyse5
1662
         mov  eax,[syslang]
1663
         mov  [esp+36],eax
1664
         ret
802 serge 1665
ngsyse5:
1 ha 1666
     cmp  eax,7
1667
     jnz  ngsyse7
1668
     movzx eax,[hd_base]
1669
     mov  [esp+36],eax
1670
     ret
802 serge 1671
ngsyse7:
1 ha 1672
     cmp  eax,8
1673
     jnz  ngsyse8
1674
     mov eax,[fat32part]
1675
     mov  [esp+36],eax
1676
     ret
802 serge 1677
ngsyse8:
1 ha 1678
     cmp  eax,9
1679
     jne  ngsyse9
1680
     mov  eax,[timer_ticks] ;[0xfdf0]
1681
     mov  [esp+36],eax
1682
     ret
802 serge 1683
ngsyse9:
1 ha 1684
     cmp  eax,11
1685
     jnz  ngsyse11
1686
     mov eax,[lba_read_enabled]
1687
     mov  [esp+36],eax
1688
     ret
802 serge 1689
ngsyse11:
1 ha 1690
     cmp  eax,12
1691
     jnz  ngsyse12
1692
     mov eax,[pci_access_enabled]
1693
     mov  [esp+36],eax
1694
     ret
802 serge 1695
ngsyse12:
1 ha 1696
     mov  [esp+36],dword 1
1697
     ret
1698
 
479 kastigar 1699
get_timer_ticks:
1700
    mov eax,[timer_ticks]
1701
    ret
1702
 
283 diamond 1703
iglobal
1 ha 1704
align 4
221 serge 1705
mousefn dd msscreen, mswin, msbutton, msset
1055 Galkov 1706
        dd app_load_cursor
1707
        dd app_set_cursor
1708
        dd app_delete_cursor
1709
        dd msz
283 diamond 1710
endg
1 ha 1711
 
1712
readmousepos:
1713
 
1714
; eax=0 screen relative
1715
; eax=1 window relative
1716
; eax=2 buttons pressed
221 serge 1717
; eax=3 set mouse pos   ; reserved
1718
; eax=4 load cursor
1719
; eax=5 set cursor
1720
; eax=6 delete cursor   ; reserved
479 kastigar 1721
; eax=7 get mouse_z
1 ha 1722
 
1055 Galkov 1723
           cmp eax, 7
1724
           ja msset
1725
           jmp [mousefn+eax*4]
221 serge 1726
msscreen:
1055 Galkov 1727
           mov  eax,[MOUSE_X]
1728
           shl  eax,16
1729
           mov  ax,[MOUSE_Y]
1730
           mov  [esp+36],eax
1731
           ret
221 serge 1732
mswin:
1055 Galkov 1733
           mov  eax,[MOUSE_X]
1734
           shl  eax,16
1735
           mov  ax,[MOUSE_Y]
1736
           mov  esi,[TASK_BASE]
1737
           mov  bx, word [esi-twdw+WDATA.box.left]
1738
           shl  ebx,16
1739
           mov  bx, word [esi-twdw+WDATA.box.top]
1740
           sub  eax,ebx
1 ha 1741
 
1055 Galkov 1742
           mov  edi,[CURRENT_TASK]
1743
           shl  edi,8
1744
           sub  ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.top]
1745
           rol  eax,16
1746
           sub  ax,word[edi+SLOT_BASE+APPDATA.wnd_clientbox.left]
1747
           rol  eax,16
1748
           mov  [esp+36],eax
1749
           ret
221 serge 1750
msbutton:
1055 Galkov 1751
           movzx eax,byte [BTN_DOWN]
1752
           mov  [esp+36],eax
1753
           ret
479 kastigar 1754
msz:
1055 Galkov 1755
           mov   edi, [TASK_COUNT]
1756
           movzx edi, word [WIN_POS + edi*2]
1757
           cmp   edi, [CURRENT_TASK]
1758
           jne   @f
1759
           mov   ax,[MOUSE_SCROLL_H]
1760
           shl   eax,16
1761
           mov   ax,[MOUSE_SCROLL_V]
1762
           mov   [esp+36],eax
1763
           mov   [MOUSE_SCROLL_H],word 0
1764
           mov   [MOUSE_SCROLL_V],word 0
1765
           ret
479 kastigar 1766
       @@:
1055 Galkov 1767
           mov  [esp+36],dword 0
1768
           ret
221 serge 1769
msset:
1055 Galkov 1770
           ret
164 serge 1771
 
221 serge 1772
app_load_cursor:
465 serge 1773
      ;     add ebx, new_app_base
1055 Galkov 1774
           cmp ebx, OS_BASE
1775
           jae msset
1776
           stdcall load_cursor, ebx, ecx
1777
           mov [esp+36], eax
1778
           ret
164 serge 1779
 
221 serge 1780
app_set_cursor:
1055 Galkov 1781
           stdcall set_cursor, ebx
1782
           mov [esp+36], eax
1783
           ret
1 ha 1784
 
233 serge 1785
app_delete_cursor:
1055 Galkov 1786
           stdcall delete_cursor, ebx
1787
           mov [esp+36], eax
1788
           ret
1 ha 1789
 
1790
is_input:
1791
 
1792
   push edx
1055 Galkov 1793
   mov  dx,word [midisp]
1794
   in   al,dx
1795
   and  al,0x80
1796
   pop  edx
1 ha 1797
   ret
1798
 
1799
is_output:
1800
 
1801
   push edx
1055 Galkov 1802
   mov  dx,word [midisp]
1803
   in   al,dx
1804
   and  al,0x40
1805
   pop  edx
1 ha 1806
   ret
1807
 
1808
 
1809
get_mpu_in:
1810
 
1811
   push edx
1055 Galkov 1812
   mov  dx,word [mididp]
1813
   in   al,dx
1814
   pop  edx
1 ha 1815
   ret
1816
 
1817
 
1818
put_mpu_out:
1819
 
1820
   push edx
1055 Galkov 1821
   mov  dx,word [mididp]
1822
   out  dx,al
1823
   pop  edx
1 ha 1824
   ret
1825
 
1826
 
1827
setuart:
1828
 
1829
 su1:
1830
   call is_output
1055 Galkov 1831
   cmp  al,0
1832
   jnz  su1
1833
   mov  dx,word [midisp]
1834
   mov  al,0xff
1835
   out  dx,al
1 ha 1836
 su2:
1055 Galkov 1837
   mov  dx,word [midisp]
1838
   mov  al,0xff
1839
   out  dx,al
1 ha 1840
   call is_input
1055 Galkov 1841
   cmp  al,0
1842
   jnz  su2
1 ha 1843
   call get_mpu_in
1055 Galkov 1844
   cmp  al,0xfe
1845
   jnz  su2
1 ha 1846
 su3:
1847
   call is_output
1055 Galkov 1848
   cmp  al,0
1849
   jnz  su3
1850
   mov  dx,word [midisp]
1851
   mov  al,0x3f
1852
   out  dx,al
1 ha 1853
 
1854
   ret
1855
 
1856
 
1857
align 4
1858
 
1859
sys_midi:
1860
 
1861
     cmp  [mididp],0
1862
     jnz  sm0
1863
     mov  [esp+36],dword 1
1864
     ret
1865
   sm0:
1866
 
1867
     cmp  eax,1
1868
     mov  [esp+36],dword 0
1869
     jnz  smn1
1870
     call setuart
1871
     ret
1872
   smn1:
1873
 
1874
     cmp  eax,2
1875
     jnz  smn2
1876
   sm10:
1877
     call get_mpu_in
1878
     call is_output
1879
     test al,al
1880
     jnz  sm10
1881
     mov  al,bl
1882
     call put_mpu_out
1883
     ret
1884
   smn2:
1885
 
1886
     ret
1887
 
1888
 
1889
detect_devices:
1890
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
769 Rus 1891
;include 'detect/commouse.inc'
479 kastigar 1892
;include 'detect/ps2mouse.inc'
1 ha 1893
;include 'detect/dev_fd.inc'
1894
;include 'detect/dev_hdcd.inc'
1895
;include 'detect/sear_par.inc'
1896
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1897
    ret
1898
 
1899
 
1900
sys_end:
1901
 
379 serge 1902
     mov   eax,[TASK_BASE]
115 poddubny 1903
     mov   [eax+TASKDATA.state], 3  ; terminate this program
41 mikedld 1904
 
1055 Galkov 1905
    waitterm:            ; wait here for termination
684 diamond 1906
     mov   ebx,100
1 ha 1907
     call  delay_hs
1908
     jmp   waitterm
1909
 
75 diamond 1910
iglobal
170 serge 1911
align 4
75 diamond 1912
sys_system_table:
1055 Galkov 1913
        dd      exit_for_anyone         ; 1 = obsolete
1914
        dd      sysfn_terminate         ; 2 = terminate thread
1915
        dd      sysfn_activate          ; 3 = activate window
1916
        dd      sysfn_getidletime       ; 4 = get idle time
1917
        dd      sysfn_getcpuclock       ; 5 = get cpu clock
1918
        dd      sysfn_saveramdisk       ; 6 = save ramdisk
1919
        dd      sysfn_getactive         ; 7 = get active window
1920
        dd      sysfn_sound_flag        ; 8 = get/set sound_flag
1921
        dd      sysfn_shutdown          ; 9 = shutdown with parameter
1922
        dd      sysfn_minimize          ; 10 = minimize window
1923
        dd      sysfn_getdiskinfo       ; 11 = get disk subsystem info
1924
        dd      sysfn_lastkey           ; 12 = get last pressed key
1925
        dd      sysfn_getversion        ; 13 = get kernel version
1926
        dd      sysfn_waitretrace       ; 14 = wait retrace
1927
        dd      sysfn_centermouse       ; 15 = center mouse cursor
1928
        dd      sysfn_getfreemem        ; 16 = get free memory size
1929
        dd      sysfn_getallmem         ; 17 = get total memory size
1930
        dd      sysfn_terminate2        ; 18 = terminate thread using PID
1931
                                        ;                 instead of slot
1932
        dd      sysfn_mouse_acceleration; 19 = set/get mouse acceleration
1933
        dd      sysfn_meminfo           ; 20 = get extended memory info
1934
        dd      sysfn_pid_to_slot       ; 21 = get slot number for pid
1935
        dd      sysfn_min_rest_window   ; 22 = minimize and restore any window
75 diamond 1936
sysfn_num = ($ - sys_system_table)/4
1937
endg
1938
 
1 ha 1939
sys_system:
1055 Galkov 1940
        dec     ebx
1941
        cmp     ebx, sysfn_num
1942
        jae     @f
1943
        jmp     dword [sys_system_table + ebx*4]
75 diamond 1944
@@:
1055 Galkov 1945
        ret
1 ha 1946
 
214 serge 1947
 
1055 Galkov 1948
sysfn_shutdown:          ; 18.9 = system shutdown
748 heavyiron 1949
     cmp  ecx,1
1950
     jl   exit_for_anyone
1951
     cmp  ecx,4
1952
     jg   exit_for_anyone
1953
     mov  [BOOT_VAR+0x9030],cl
1954
 
379 serge 1955
     mov  eax,[TASK_COUNT]
709 diamond 1956
     mov  [SYS_SHUTDOWN],al
1 ha 1957
     mov  [shutdown_processes],eax
684 diamond 1958
     and  dword [esp+32], 0
748 heavyiron 1959
 exit_for_anyone:
1 ha 1960
     ret
1961
  uglobal
1962
   shutdown_processes: dd 0x0
1963
  endg
1964
 
1055 Galkov 1965
sysfn_terminate:        ; 18.2 = TERMINATE
684 diamond 1966
     cmp  ecx,2
1 ha 1967
     jb   noprocessterminate
379 serge 1968
     mov  edx,[TASK_COUNT]
684 diamond 1969
     cmp  ecx,edx
75 diamond 1970
     ja   noprocessterminate
379 serge 1971
     mov  eax,[TASK_COUNT]
684 diamond 1972
     shl  ecx,5
1973
     mov  edx,[ecx+CURRENT_TASK+TASKDATA.pid]
1974
     add  ecx,CURRENT_TASK+TASKDATA.state
1975
     cmp  byte [ecx], 9
75 diamond 1976
     jz   noprocessterminate
41 mikedld 1977
 
1 ha 1978
     ;call MEM_Heap_Lock      ;guarantee that process isn't working with heap
1055 Galkov 1979
     mov  [ecx],byte 3       ; clear possible i40's
1 ha 1980
     ;call MEM_Heap_UnLock
1981
 
1982
     cmp  edx,[application_table_status]    ; clear app table stat
1983
     jne  noatsc
1984
     mov  [application_table_status],0
1985
   noatsc:
75 diamond 1986
   noprocessterminate:
1 ha 1987
     ret
1988
 
85 halyavin 1989
sysfn_terminate2:
1990
;lock application_table_status mutex
164 serge 1991
.table_status:
85 halyavin 1992
    cli
1993
    cmp    [application_table_status],0
1055 Galkov 1994
    je     .stf
85 halyavin 1995
    sti
1996
    call   change_task
1997
    jmp    .table_status
1998
.stf:
1999
    call   set_application_table_status
684 diamond 2000
    mov    eax,ecx
85 halyavin 2001
    call   pid_to_slot
2002
    test   eax,eax
1055 Galkov 2003
    jz     .not_found
684 diamond 2004
    mov    ecx,eax
85 halyavin 2005
    cli
2006
    call   sysfn_terminate
2007
    mov    [application_table_status],0
2008
    sti
684 diamond 2009
    and    dword [esp+32],0
85 halyavin 2010
    ret
2011
.not_found:
2012
    mov    [application_table_status],0
1055 Galkov 2013
    or     dword [esp+32],-1
85 halyavin 2014
    ret
2015
 
1055 Galkov 2016
sysfn_activate:         ; 18.3 = ACTIVATE WINDOW
684 diamond 2017
     cmp  ecx,2
105 poddubny 2018
     jb   .nowindowactivate
684 diamond 2019
     cmp  ecx,[TASK_COUNT]
105 poddubny 2020
     ja   .nowindowactivate
2021
 
2022
     mov   [window_minimize], 2   ; restore window if minimized
2023
 
684 diamond 2024
     movzx esi, word [WIN_STACK + ecx*2]
379 serge 2025
     cmp   esi, [TASK_COUNT]
105 poddubny 2026
     je    .nowindowactivate ; already active
2027
 
684 diamond 2028
     mov   edi, ecx
105 poddubny 2029
     shl   edi, 5
2030
     add   edi, window_data
684 diamond 2031
     movzx esi, word [WIN_STACK + ecx * 2]
380 serge 2032
     lea   esi, [WIN_POS + esi * 2]
105 poddubny 2033
     call  waredraw
2034
.nowindowactivate:
1 ha 2035
     ret
41 mikedld 2036
 
1055 Galkov 2037
sysfn_getidletime:              ; 18.4 = GET IDLETIME
1 ha 2038
     mov  eax,[idleusesec]
684 diamond 2039
     mov  [esp+32], eax
1 ha 2040
     ret
2041
 
1055 Galkov 2042
sysfn_getcpuclock:              ; 18.5 = GET TSC/SEC
381 serge 2043
     mov  eax,[CPU_FREQ]
684 diamond 2044
     mov  [esp+32], eax
1 ha 2045
     ret
2046
 
2047
;  SAVE ramdisk to /hd/1/menuet.img
2048
;!!!!!!!!!!!!!!!!!!!!!!!!
2049
   include 'blkdev/rdsave.inc'
2050
;!!!!!!!!!!!!!!!!!!!!!!!!
75 diamond 2051
 
1055 Galkov 2052
sysfn_getactive:        ; 18.7 = get active window
379 serge 2053
     mov  eax, [TASK_COUNT]
380 serge 2054
   movzx  eax, word [WIN_POS + eax*2]
684 diamond 2055
     mov  [esp+32],eax
1 ha 2056
     ret
75 diamond 2057
 
1055 Galkov 2058
sysfn_sound_flag:       ; 18.8 = get/set sound_flag
684 diamond 2059
     cmp  ecx,1
1 ha 2060
     jne  nogetsoundflag
2061
     movzx  eax,byte [sound_flag] ; get sound_flag
684 diamond 2062
     mov  [esp+32],eax
1 ha 2063
     ret
2064
 nogetsoundflag:
684 diamond 2065
     cmp  ecx,2
1 ha 2066
     jnz  nosoundflag
75 diamond 2067
     xor  byte [sound_flag], 1
2068
 nosoundflag:
41 mikedld 2069
     ret
75 diamond 2070
 
1055 Galkov 2071
sysfn_minimize:         ; 18.10 = minimize window
1 ha 2072
     mov   [window_minimize],1
2073
     ret
75 diamond 2074
 
1055 Galkov 2075
sysfn_getdiskinfo:      ; 18.11 = get disk info table
684 diamond 2076
     cmp  ecx,1
1 ha 2077
     jnz  full_table
2078
  small_table:
2079
     call for_all_tables
75 diamond 2080
     mov ecx,10
1 ha 2081
     cld
2082
     rep movsb
2083
     ret
2084
   for_all_tables:
684 diamond 2085
     mov edi,edx
381 serge 2086
     mov esi,DRIVE_DATA
1 ha 2087
     ret
2088
  full_table:
684 diamond 2089
     cmp  ecx,2
1 ha 2090
     jnz  exit_for_anyone
2091
     call for_all_tables
75 diamond 2092
     mov ecx,16384
1 ha 2093
     cld
2094
     rep movsd
2095
     ret
75 diamond 2096
 
1055 Galkov 2097
sysfn_lastkey:          ; 18.12 = return 0 (backward compatibility)
2098
        and     dword [esp+32], 0
2099
        ret
75 diamond 2100
 
1055 Galkov 2101
sysfn_getversion:       ; 18.13 = get kernel ID and version
684 diamond 2102
     mov edi,ebx
1 ha 2103
     mov esi,version_inf
2104
     mov ecx,version_end-version_inf
2105
     rep movsb
2106
     ret
75 diamond 2107
 
2108
sysfn_waitretrace:     ; 18.14 = sys wait retrace
41 mikedld 2109
     ;wait retrace functions
2110
 sys_wait_retrace:
2111
     mov edx,0x3da
2112
 WaitRetrace_loop:
2113
     in al,dx
2114
     test al,1000b
2115
     jz WaitRetrace_loop
684 diamond 2116
     and [esp+32],dword 0
1 ha 2117
     ret
75 diamond 2118
 
1055 Galkov 2119
sysfn_centermouse:      ; 18.15 = mouse centered
1 ha 2120
     call  mouse_centered
684 diamond 2121
     and [esp+32],dword 0
1 ha 2122
     ret
75 diamond 2123
 
120 mario79 2124
sysfn_mouse_acceleration: ; 18.19 = set/get mouse features
684 diamond 2125
     cmp  ecx,0  ; get mouse speed factor
120 mario79 2126
     jnz  .set_mouse_acceleration
164 serge 2127
     xor  eax,eax
120 mario79 2128
     mov  ax,[mouse_speed_factor]
684 diamond 2129
     mov  [esp+32],eax
120 mario79 2130
     ret
2131
 .set_mouse_acceleration:
684 diamond 2132
     cmp  ecx,1  ; set mouse speed factor
120 mario79 2133
     jnz  .get_mouse_delay
684 diamond 2134
     mov  [mouse_speed_factor],dx
120 mario79 2135
     ret
2136
 .get_mouse_delay:
684 diamond 2137
     cmp  ecx,2  ; get mouse delay
120 mario79 2138
     jnz  .set_mouse_delay
2139
     mov  eax,[mouse_delay]
684 diamond 2140
     mov  [esp+32],eax
120 mario79 2141
     ret
2142
 .set_mouse_delay:
684 diamond 2143
     cmp  ecx,3  ; set mouse delay
120 mario79 2144
     jnz  .set_pointer_position
684 diamond 2145
     mov  [mouse_delay],edx
120 mario79 2146
     ret
2147
 .set_pointer_position:
684 diamond 2148
     cmp  ecx,4  ; set mouse pointer position
621 mario79 2149
     jnz  .set_mouse_button
684 diamond 2150
     mov   [MOUSE_Y],dx    ;y
2151
     ror   edx,16
2152
     mov   [MOUSE_X],dx    ;x
2153
     rol   edx,16
621 mario79 2154
     ret
2155
 .set_mouse_button:
684 diamond 2156
     cmp   ecx,5  ; set mouse button features
621 mario79 2157
     jnz  .end
684 diamond 2158
     mov   [BTN_DOWN],dl
621 mario79 2159
     mov   [mouse_active],1
120 mario79 2160
 .end:
2161
     ret
2162
 
75 diamond 2163
sysfn_getfreemem:
170 serge 2164
     mov eax, [pg_data.pages_free]
2165
     shl eax, 2
684 diamond 2166
     mov [esp+32],eax
1 ha 2167
     ret
75 diamond 2168
 
2169
sysfn_getallmem:
170 serge 2170
     mov  eax,[MEM_AMOUNT]
2171
     shr eax, 10
684 diamond 2172
     mov  [esp+32],eax
32 halyavin 2173
     ret
2174
 
608 alver 2175
; // Alver, 2007-22-08 // {
2176
sysfn_pid_to_slot:
684 diamond 2177
     mov   eax, ecx
608 alver 2178
     call  pid_to_slot
684 diamond 2179
     mov   [esp+32], eax
608 alver 2180
     ret
2181
 
2182
sysfn_min_rest_window:
2183
     pushad
1055 Galkov 2184
     mov   eax, edx      ; ebx - operating
684 diamond 2185
     shr   ecx, 1
608 alver 2186
     jnc    @f
2187
     call  pid_to_slot
2188
@@:
1055 Galkov 2189
     or    eax, eax      ; eax - number of slot
608 alver 2190
     jz    .error
1055 Galkov 2191
     cmp   eax, 255         ; varify maximal slot number
608 alver 2192
     ja    .error
684 diamond 2193
     movzx eax, word [WIN_STACK + eax*2]
2194
     shr   ecx, 1
608 alver 2195
     jc    .restore
2196
 ; .minimize:
2197
     call  minimize_window
2198
     jmp   .exit
2199
.restore:
2200
     call  restore_minimized_window
2201
.exit:
2202
     popad
2203
     xor   eax, eax
684 diamond 2204
     mov   [esp+32], eax
608 alver 2205
     ret
2206
.error:
2207
     popad
2208
     xor   eax, eax
2209
     dec   eax
684 diamond 2210
     mov   [esp+32], eax
608 alver 2211
     ret
2212
; } \\ Alver, 2007-22-08 \\
2213
 
41 mikedld 2214
uglobal
2215
;// mike.dld, 2006-29-01 [
2216
screen_workarea RECT
2217
;// mike.dld, 2006-29-01 ]
1 ha 2218
window_minimize db 0
1055 Galkov 2219
sound_flag      db 0
41 mikedld 2220
endg
1 ha 2221
 
41 mikedld 2222
iglobal
2223
version_inf:
1018 diamond 2224
  db 0,7,5,0  ; version 0.7.5.0
41 mikedld 2225
  db UID_KOLIBRI
540 victor 2226
  dd __REV__
41 mikedld 2227
version_end:
2228
endg
1 ha 2229
 
41 mikedld 2230
UID_NONE=0
1055 Galkov 2231
UID_MENUETOS=1   ;official
2232
UID_KOLIBRI=2    ;russian
1 ha 2233
 
2234
sys_cachetodiskette:
1055 Galkov 2235
        cmp     ebx, 1
2236
        jne     .no_floppy_a_save
2237
        mov     [flp_number], 1
2238
        jmp     .save_image_on_floppy
671 Ghost 2239
.no_floppy_a_save:
1055 Galkov 2240
        cmp     ebx, 2
2241
        jne     .no_floppy_b_save
2242
        mov     [flp_number], 2
671 Ghost 2243
.save_image_on_floppy:
1055 Galkov 2244
        call    save_image
2245
        mov     [esp + 32], dword 0
2246
        cmp     [FDC_Status], 0
2247
        je      .yes_floppy_save
671 Ghost 2248
.no_floppy_b_save:
1055 Galkov 2249
        mov     [esp + 32], dword 1
671 Ghost 2250
.yes_floppy_save:
1055 Galkov 2251
        ret
1 ha 2252
 
2253
uglobal
2254
;  bgrchanged  dd  0x0
546 diamond 2255
bgrlock db 0
2256
bgrlockpid dd 0
1 ha 2257
endg
2258
 
2259
sys_background:
2260
 
1055 Galkov 2261
    cmp   ebx,1                            ; BACKGROUND SIZE
1 ha 2262
    jnz   nosb1
2263
    cmp   ecx,0
1055 Galkov 2264
    je    sbgrr
684 diamond 2265
    cmp   edx,0
1055 Galkov 2266
    je    sbgrr
546 diamond 2267
@@:
1055 Galkov 2268
        mov     al, 1
2269
        xchg    [bgrlock], al
2270
        test    al, al
2271
        jz      @f
2272
        call    change_task
2273
        jmp     @b
546 diamond 2274
@@:
684 diamond 2275
    mov   [BgrDataWidth],ecx
2276
    mov   [BgrDataHeight],edx
1 ha 2277
;    mov   [bgrchanged],1
469 serge 2278
 
2279
    pushad
2280
; return memory for old background
2281
    stdcall kernel_free, [img_background]
2282
; calculate RAW size
2283
    xor  eax,eax
2284
    inc  eax
527 diamond 2285
    cmp  [BgrDataWidth],eax
469 serge 2286
    jae   @f
527 diamond 2287
    mov [BgrDataWidth],eax
469 serge 2288
@@:
527 diamond 2289
    cmp  [BgrDataHeight],eax
469 serge 2290
    jae   @f
527 diamond 2291
    mov [BgrDataHeight],eax
469 serge 2292
@@:
527 diamond 2293
    mov  eax,[BgrDataWidth]
2294
    imul eax,[BgrDataHeight]
2295
    lea  eax,[eax*3]
469 serge 2296
    mov  [mem_BACKGROUND],eax
2297
; get memory for new background
546 diamond 2298
    stdcall kernel_alloc, eax
469 serge 2299
    test eax, eax
2300
    jz .exit_mem
2301
    mov [img_background], eax
2302
.exit_mem:
2303
    popad
1055 Galkov 2304
        mov     [bgrlock], 0
469 serge 2305
 
1 ha 2306
  sbgrr:
2307
    ret
469 serge 2308
 
875 serge 2309
nosb1:
1 ha 2310
 
1055 Galkov 2311
    cmp   ebx,2                            ; SET PIXEL
1 ha 2312
    jnz   nosb2
875 serge 2313
 
2314
    mov ebx, [mem_BACKGROUND]
2315
    add ebx, 4095
2316
    and ebx, -4096
2317
    sub ebx, 4
2318
    cmp   ecx, ebx
1055 Galkov 2319
    ja   @F
875 serge 2320
 
469 serge 2321
    mov   eax,[img_background]
684 diamond 2322
    mov   ebx,[eax+ecx]
2323
    and   ebx,0xFF000000 ;255*256*256*256
2324
    and   edx,0x00FFFFFF ;255*256*256+255*256+255
2325
    add   edx,ebx
2326
    mov   [eax+ecx],edx
875 serge 2327
@@:
1 ha 2328
    ret
875 serge 2329
nosb2:
1 ha 2330
 
1055 Galkov 2331
    cmp   ebx,3                            ; DRAW BACKGROUND
1 ha 2332
    jnz   nosb3
2333
draw_background_temp:
2334
;    cmp   [bgrchanged],1 ;0
2335
;    je    nosb31
2336
;draw_background_temp:
2337
;    mov   [bgrchanged],1 ;0
76 mario79 2338
    mov    [background_defined], 1
709 diamond 2339
    call  force_redraw_background
2340
    mov    [REDRAW_BACKGROUND], byte 2
1 ha 2341
   nosb31:
2342
    ret
2343
  nosb3:
2344
 
1055 Galkov 2345
    cmp   ebx,4                            ; TILED / STRETCHED
1 ha 2346
    jnz   nosb4
684 diamond 2347
    cmp   ecx,[BgrDrawMode]
1055 Galkov 2348
    je    nosb41
684 diamond 2349
    mov   [BgrDrawMode],ecx
1 ha 2350
;    mov   [bgrchanged],1
2351
   nosb41:
2352
    ret
2353
  nosb4:
2354
 
1055 Galkov 2355
    cmp   ebx,5                            ; BLOCK MOVE TO BGR
1 ha 2356
    jnz   nosb5
2357
  ; bughere
684 diamond 2358
    mov   eax, ecx
2359
    mov   ebx, edx
469 serge 2360
    add   ebx, [img_background]   ;IMG_BACKGROUND
684 diamond 2361
    mov   ecx, esi
1 ha 2362
    call  memmove
2363
  .fin:
2364
    ret
2365
  nosb5:
479 kastigar 2366
 
1055 Galkov 2367
        cmp     ebx, 6
2368
        jnz     nosb6
546 diamond 2369
@@:
1055 Galkov 2370
        mov     al, 1
2371
        xchg    [bgrlock], al
2372
        test    al, al
2373
        jz      @f
2374
        call    change_task
2375
        jmp     @b
546 diamond 2376
@@:
1055 Galkov 2377
        mov     eax, [CURRENT_TASK]
2378
        mov     [bgrlockpid], eax
2379
        stdcall user_alloc, [mem_BACKGROUND]
2380
        mov     [esp+32], eax
2381
        test    eax, eax
2382
        jz      .nomem
2383
        mov     ebx, eax
2384
        shr     ebx, 12
2385
        or      dword [page_tabs+(ebx-1)*4], DONT_FREE_BLOCK
2386
        mov     esi, [img_background]
2387
        shr     esi, 12
2388
        mov     ecx, [mem_BACKGROUND]
2389
        add     ecx, 0xFFF
2390
        shr     ecx, 12
546 diamond 2391
.z:
1055 Galkov 2392
        mov     eax, [page_tabs+ebx*4]
2393
        test    al, 1
2394
        jz      @f
2395
        call    free_page
546 diamond 2396
@@:
1055 Galkov 2397
        mov     eax, [page_tabs+esi*4]
2398
        or      al, PG_UW
2399
        mov     [page_tabs+ebx*4], eax
2400
        mov     eax, ebx
2401
        shl     eax, 12
2402
        invlpg  [eax]
2403
        inc     ebx
2404
        inc     esi
2405
        loop    .z
2406
        ret
546 diamond 2407
.nomem:
1055 Galkov 2408
        and     [bgrlockpid], 0
2409
        mov     [bgrlock], 0
546 diamond 2410
nosb6:
1055 Galkov 2411
        cmp     ebx, 7
2412
        jnz     nosb7
2413
        cmp     [bgrlock], 0
2414
        jz      .err
2415
        mov     eax, [CURRENT_TASK]
2416
        cmp     [bgrlockpid], eax
2417
        jnz     .err
2418
        mov     eax, ecx
2419
        mov     ebx, ecx
2420
        shr     eax, 12
2421
        mov     ecx, [page_tabs+(eax-1)*4]
2422
        test    cl, USED_BLOCK+DONT_FREE_BLOCK
2423
        jz      .err
2424
        jnp     .err
2425
        push    eax
2426
        shr     ecx, 12
546 diamond 2427
@@:
1055 Galkov 2428
        and     dword [page_tabs+eax*4], 0
2429
        mov     edx, eax
2430
        shl     edx, 12
2431
        push eax
2432
        invlpg  [edx]
2433
        pop eax
2434
        inc     eax
2435
        loop    @b
2436
        pop     eax
2437
        and     dword [page_tabs+(eax-1)*4], not DONT_FREE_BLOCK
2438
        stdcall user_free, ebx
2439
        mov     [esp+32], eax
2440
        and     [bgrlockpid], 0
2441
        mov     [bgrlock], 0
2442
        ret
546 diamond 2443
.err:
1055 Galkov 2444
        and     dword [esp+32], 0
2445
        ret
546 diamond 2446
 
2447
nosb7:
1 ha 2448
    ret
2449
 
709 diamond 2450
force_redraw_background:
2451
    mov   [draw_data+32 + RECT.left],dword 0
2452
    mov   [draw_data+32 + RECT.top],dword 0
2453
    push  eax ebx
753 serge 2454
    mov   eax,[Screen_Max_X]
2455
    mov   ebx,[Screen_Max_Y]
709 diamond 2456
    mov   [draw_data+32 + RECT.right],eax
2457
    mov   [draw_data+32 + RECT.bottom],ebx
2458
    pop   ebx eax
2459
    mov   byte [REDRAW_BACKGROUND], 1
2460
    ret
479 kastigar 2461
 
1 ha 2462
align 4
2463
 
2464
sys_getbackground:
2465
 
1055 Galkov 2466
    cmp   eax,1                                  ; SIZE
1 ha 2467
    jnz   nogb1
527 diamond 2468
    mov   eax,[BgrDataWidth]
1 ha 2469
    shl   eax,16
531 diamond 2470
    mov   ax,[BgrDataHeight]
1 ha 2471
    mov   [esp+36],eax
2472
    ret
2473
 
875 serge 2474
nogb1:
2475
 
1055 Galkov 2476
    cmp   eax,2                                  ; PIXEL
1 ha 2477
    jnz   nogb2
875 serge 2478
 
2479
    mov ecx, [mem_BACKGROUND]
2480
    add ecx, 4095
2481
    and ecx, -4096
2482
    sub ecx, 4
2483
    cmp ebx, ecx
1055 Galkov 2484
    ja  @F
875 serge 2485
 
469 serge 2486
    mov   eax,[img_background]
2487
    mov   eax,[ebx+eax]
2488
 
1 ha 2489
    and   eax, 0xFFFFFF
2490
    mov   [esp+36],eax
875 serge 2491
@@:
1 ha 2492
    ret
2493
  nogb2:
2494
 
1055 Galkov 2495
    cmp   eax,4                                  ; TILED / STRETCHED
1 ha 2496
    jnz   nogb4
527 diamond 2497
    mov   eax,[BgrDrawMode]
1 ha 2498
  nogb4:
2499
    mov   [esp+36],eax
2500
    ret
2501
 
2502
 
2503
align 4
2504
 
2505
sys_getkey:
1055 Galkov 2506
        mov     [esp + 32],dword 1
2507
        ; test main buffer
2508
        mov     ebx, [CURRENT_TASK]                          ; TOP OF WINDOW STACK
2509
        movzx   ecx, word [WIN_STACK + ebx * 2]
2510
        mov     edx, [TASK_COUNT]
2511
        cmp     ecx, edx
2512
        jne     .finish
2513
        cmp     [KEY_COUNT], byte 0
2514
        je      .finish
2515
        movzx   eax, byte [KEY_BUFF]
2516
        shl     eax, 8
2517
        push    eax
2518
        dec     byte [KEY_COUNT]
2519
        and     byte [KEY_COUNT], 127
2520
        movzx   ecx, byte [KEY_COUNT]
2521
        add     ecx, 2
2522
        mov     eax, KEY_BUFF + 1
2523
        mov     ebx, KEY_BUFF
2524
        call    memmove
2525
        pop     eax
92 diamond 2526
.ret_eax:
1055 Galkov 2527
        mov     [esp + 32], eax
2528
        ret
671 Ghost 2529
.finish:
92 diamond 2530
; test hotkeys buffer
1055 Galkov 2531
        mov     ecx, hotkey_buffer
92 diamond 2532
@@:
1055 Galkov 2533
        cmp     [ecx], ebx
2534
        jz      .found
2535
        add     ecx, 8
2536
        cmp     ecx, hotkey_buffer + 120 * 8
2537
        jb      @b
2538
        ret
92 diamond 2539
.found:
1055 Galkov 2540
        mov     ax, [ecx + 6]
2541
        shl     eax, 16
2542
        mov     ah, [ecx + 4]
2543
        mov     al, 2
2544
        and     dword [ecx + 4], 0
2545
        and     dword [ecx], 0
2546
        jmp     .ret_eax
1 ha 2547
 
2548
align 4
2549
 
2550
sys_getbutton:
2551
 
1055 Galkov 2552
        mov     ebx, [CURRENT_TASK]                         ; TOP OF WINDOW STACK
2553
        mov     [esp + 32], dword 1
2554
        movzx   ecx, word [WIN_STACK + ebx * 2]
2555
        mov     edx, [TASK_COUNT] ; less than 256 processes
2556
        cmp     ecx, edx
2557
        jne     .exit
2558
        movzx   eax, byte [BTN_COUNT]
2559
        test    eax, eax
2560
        jz      .exit
2561
        mov     eax, [BTN_BUFF]
2562
        shl     eax, 8
803 alver 2563
; // Alver 22.06.2008 // {
1055 Galkov 2564
        mov       al, byte [btn_down_determ]
2565
        and       al,0xFE                                       ; delete left button bit
803 alver 2566
; } \\ Alver \\
1055 Galkov 2567
        mov     [BTN_COUNT], byte 0
2568
        mov     [esp + 32], eax
671 Ghost 2569
.exit:
1055 Galkov 2570
        ret
1 ha 2571
 
2572
 
2573
align 4
2574
 
2575
sys_cpuusage:
2576
 
2577
;  RETURN:
2578
;
2579
;  +00 dword     process cpu usage
2580
;  +04  word     position in windowing stack
2581
;  +06  word     windowing stack value at current position (cpu nro)
2582
;  +10 12 bytes  name
2583
;  +22 dword     start in mem
2584
;  +26 dword     used mem
2585
;  +30 dword     PID , process idenfification number
2586
;
2587
 
1055 Galkov 2588
    cmp  ecx,-1         ; who am I ?
684 diamond 2589
    jne  .no_who_am_i
2590
    mov  ecx,[CURRENT_TASK]
2591
  .no_who_am_i:
1055 Galkov 2592
        cmp     ecx, max_processes
2593
        ja      .nofillbuf
1 ha 2594
 
684 diamond 2595
; +4: word: position of the window of thread in the window stack
1055 Galkov 2596
        mov     ax, [WIN_STACK + ecx * 2]
2597
        mov     [ebx+4], ax
684 diamond 2598
; +6: word: number of the thread slot, which window has in the window stack
2599
;           position ecx (has no relation to the specific thread)
1055 Galkov 2600
        mov     ax, [WIN_POS + ecx * 2]
2601
        mov     [ebx+6], ax
1 ha 2602
 
1055 Galkov 2603
        shl     ecx, 5
1 ha 2604
 
684 diamond 2605
; +0: dword: memory usage
1055 Galkov 2606
        mov     eax, [ecx+CURRENT_TASK+TASKDATA.cpu_usage]
2607
        mov     [ebx], eax
684 diamond 2608
; +10: 11 bytes: name of the process
1055 Galkov 2609
        push    ecx
2610
        lea     eax, [ecx*8+SLOT_BASE+APPDATA.app_name]
2611
        add     ebx, 10
2612
        mov     ecx, 11
2613
        call    memmove
2614
        pop     ecx
1 ha 2615
 
684 diamond 2616
; +22: address of the process in memory
2617
; +26: size of used memory - 1
1055 Galkov 2618
        push    edi
2619
        lea     edi, [ebx+12]
2620
        xor     eax, eax
2621
        mov     edx, 0x100000*16
2622
        cmp     ecx, 1 shl 5
2623
        je      .os_mem
2624
        mov     edx, [SLOT_BASE+ecx*8+APPDATA.mem_size]
2625
        mov     eax, std_application_base_address
684 diamond 2626
.os_mem:
1055 Galkov 2627
        stosd
2628
        lea     eax, [edx-1]
2629
        stosd
1 ha 2630
 
684 diamond 2631
; +30: PID/TID
1055 Galkov 2632
        mov     eax, [ecx+CURRENT_TASK+TASKDATA.pid]
2633
        stosd
1 ha 2634
 
2635
    ; window position and size
1055 Galkov 2636
        push    esi
2637
        lea     esi, [ecx + window_data + WDATA.box]
2638
        movsd
2639
        movsd
2640
        movsd
2641
        movsd
1 ha 2642
 
2643
    ; Process state (+50)
1055 Galkov 2644
        mov     eax, dword [ecx+CURRENT_TASK+TASKDATA.state]
2645
        stosd
1 ha 2646
 
138 mikedld 2647
    ; Window client area box
1055 Galkov 2648
        lea     esi, [ecx*8 + SLOT_BASE + APPDATA.wnd_clientbox]
2649
        movsd
2650
        movsd
2651
        movsd
2652
        movsd
1 ha 2653
 
164 serge 2654
    ; Window state
1055 Galkov 2655
        mov     al, [ecx+window_data+WDATA.fl_wstate]
2656
        stosb
164 serge 2657
 
1055 Galkov 2658
        pop     esi
2659
        pop     edi
138 mikedld 2660
 
684 diamond 2661
.nofillbuf:
1 ha 2662
    ; return number of processes
2663
 
379 serge 2664
    mov    eax,[TASK_COUNT]
684 diamond 2665
    mov    [esp+32],eax
1 ha 2666
    ret
2667
 
2668
align 4
2669
sys_clock:
1055 Galkov 2670
        cli
1 ha 2671
  ; Mikhail Lisovin  xx Jan 2005
1055 Galkov 2672
  @@:   mov   al, 10
2673
        out   0x70, al
2674
        in    al, 0x71
2675
        test  al, al
2676
        jns   @f
2677
        mov   esi, 1
2678
        call  delay_ms
2679
        jmp   @b
1 ha 2680
  @@:
2681
  ; end Lisovin's fix
2682
 
1055 Galkov 2683
        xor   al,al           ; seconds
2684
        out   0x70,al
2685
        in    al,0x71
2686
        movzx ecx,al
2687
        mov   al,02           ; minutes
2688
        shl   ecx,16
2689
        out   0x70,al
2690
        in    al,0x71
2691
        movzx edx,al
2692
        mov   al,04           ; hours
2693
        shl   edx,8
2694
        out   0x70,al
2695
        in    al,0x71
2696
        add   ecx,edx
2697
        movzx edx,al
2698
        add   ecx,edx
2699
        sti
2700
        mov     [esp + 32], ecx
2701
        ret
1 ha 2702
 
2703
 
2704
align 4
2705
 
2706
sys_date:
2707
 
1055 Galkov 2708
        cli
2709
  @@:   mov   al, 10
2710
        out   0x70, al
2711
        in    al, 0x71
2712
        test  al, al
2713
        jns   @f
2714
        mov   esi, 1
2715
        call  delay_ms
2716
        jmp   @b
75 diamond 2717
  @@:
2718
 
1055 Galkov 2719
        mov     ch,0
2720
        mov     al,7            ; date
2721
        out     0x70,al
2722
        in      al,0x71
2723
        mov     cl,al
2724
        mov     al,8            ; month
2725
        shl     ecx,16
2726
        out     0x70,al
2727
        in      al,0x71
2728
        mov     ch,al
2729
        mov     al,9            ; year
2730
        out     0x70,al
2731
        in      al,0x71
2732
        mov     cl,al
2733
        sti
2734
        mov     [esp+32], ecx
2735
        ret
1 ha 2736
 
2737
 
2738
; redraw status
2739
 
2740
sys_redrawstat:
1055 Galkov 2741
        cmp     ebx, 1
2742
        jne     no_widgets_away
2743
        ; buttons away
2744
        mov     ecx,[CURRENT_TASK]
1 ha 2745
  sys_newba2:
1055 Galkov 2746
        mov     edi,[BTN_ADDR]
2747
        cmp     [edi], dword 0  ; empty button list ?
2748
        je      end_of_buttons_away
2749
        movzx   ebx, word [edi]
2750
        inc     ebx
2751
        mov     eax,edi
1 ha 2752
  sys_newba:
1055 Galkov 2753
        dec     ebx
2754
        jz      end_of_buttons_away
1 ha 2755
 
1055 Galkov 2756
        add     eax, 0x10
2757
        cmp     cx, [eax]
2758
        jnz     sys_newba
1 ha 2759
 
1055 Galkov 2760
        push    eax ebx ecx
2761
        mov     ecx,ebx
2762
        inc     ecx
2763
        shl     ecx, 4
2764
        mov     ebx, eax
2765
        add     eax, 0x10
2766
        call    memmove
2767
        dec     dword [edi]
2768
        pop     ecx ebx eax
1 ha 2769
 
1055 Galkov 2770
        jmp     sys_newba2
1 ha 2771
 
2772
  end_of_buttons_away:
2773
 
1055 Galkov 2774
        ret
1 ha 2775
 
2776
  no_widgets_away:
2777
 
1055 Galkov 2778
        cmp     ebx, 2
2779
        jnz     srl1
1 ha 2780
 
1055 Galkov 2781
        mov     edx, [TASK_BASE]      ; return whole screen draw area for this app
2782
        add     edx, draw_data - CURRENT_TASK
2783
        mov     [edx + RECT.left], 0
2784
        mov     [edx + RECT.top], 0
2785
        mov     eax, [Screen_Max_X]
2786
        mov     [edx + RECT.right], eax
2787
        mov     eax, [Screen_Max_Y]
2788
        mov     [edx + RECT.bottom], eax
1 ha 2789
 
1055 Galkov 2790
        mov     edi, [TASK_BASE]
2791
        or      [edi - twdw + WDATA.fl_wdrawn], 1   ; no new position & buttons from app
2792
        call    sys_window_mouse
2793
        ret
1 ha 2794
 
2795
  srl1:
1055 Galkov 2796
        ret
1 ha 2797
 
2798
 
2799
sys_drawwindow:
2800
 
684 diamond 2801
    mov   eax,edx
2802
    shr   eax,16+8
2803
    and   eax,15
1 ha 2804
 
684 diamond 2805
;    cmp   eax,0   ; type I    - original style
1 ha 2806
    jne   nosyswI
33 mario79 2807
    inc   [mouse_pause]
36 mario79 2808
    call  [disable_mouse]
1 ha 2809
    call  sys_set_window
36 mario79 2810
    call  [disable_mouse]
1 ha 2811
    call  drawwindow_I
114 mikedld 2812
    ;dec   [mouse_pause]
2813
    ;call   [draw_pointer]
2814
    ;ret
2815
    jmp   draw_window_caption.2
1 ha 2816
  nosyswI:
2817
 
1055 Galkov 2818
    cmp   al,1    ; type II   - only reserve area, no draw
1 ha 2819
    jne   nosyswII
33 mario79 2820
    inc   [mouse_pause]
36 mario79 2821
    call  [disable_mouse]
1 ha 2822
    call  sys_set_window
36 mario79 2823
    call  [disable_mouse]
1 ha 2824
    call  sys_window_mouse
33 mario79 2825
    dec   [mouse_pause]
36 mario79 2826
    call   [draw_pointer]
1 ha 2827
    ret
2828
  nosyswII:
2829
 
1055 Galkov 2830
    cmp   al,2    ; type III  - new style
1 ha 2831
    jne   nosyswIII
33 mario79 2832
    inc   [mouse_pause]
36 mario79 2833
    call  [disable_mouse]
1 ha 2834
    call  sys_set_window
36 mario79 2835
    call  [disable_mouse]
1 ha 2836
    call  drawwindow_III
114 mikedld 2837
    ;dec   [mouse_pause]
2838
    ;call   [draw_pointer]
2839
    ;ret
2840
    jmp   draw_window_caption.2
1 ha 2841
  nosyswIII:
2842
 
1055 Galkov 2843
    cmp   al,3    ; type IV - skinned window
2844
    je    draw_skin_window
2845
    cmp   al,4    ; type V - skinned window not sized! {not_sized_skin_window}
549 spraid 2846
    jne   nosyswV
2847
  draw_skin_window:
567 serge 2848
 
569 diamond 2849
    inc   [mouse_pause]
2850
    call  [disable_mouse]
2851
    call  sys_set_window
2852
    call  [disable_mouse]
684 diamond 2853
    mov   eax, [TASK_COUNT]
2854
    movzx eax, word [WIN_POS + eax*2]
2855
    cmp   eax, [CURRENT_TASK]
2856
    setz  al
2857
    movzx eax, al
2858
    push  eax
36 mario79 2859
    call  drawwindow_IV
114 mikedld 2860
    ;dec   [mouse_pause]
2861
    ;call   [draw_pointer]
2862
    ;ret
2863
    jmp   draw_window_caption.2
549 spraid 2864
  nosyswV:
1 ha 2865
 
2866
    ret
2867
 
2868
 
114 mikedld 2869
draw_window_caption:
1055 Galkov 2870
        inc     [mouse_pause]
2871
        call    [disable_mouse]
114 mikedld 2872
 
1055 Galkov 2873
        xor     eax,eax
2874
        mov     edx,[TASK_COUNT]
2875
        movzx   edx,word[WIN_POS+edx*2]
2876
        cmp     edx,[CURRENT_TASK]
2877
        jne     @f
2878
        inc     eax
2879
    @@: mov     edx,[CURRENT_TASK]
2880
        shl     edx,5
2881
        add     edx,window_data
2882
        movzx   ebx,[edx+WDATA.fl_wstyle]
2883
        and     bl,0x0F
2884
        cmp     bl,3
2885
        je      .draw_caption_style_3           ;{for 3 and 4 style write caption}
2886
        cmp     bl,4
2887
        je      .draw_caption_style_3
567 serge 2888
 
1055 Galkov 2889
        jmp     .not_style_3
549 spraid 2890
  .draw_caption_style_3:
114 mikedld 2891
 
1055 Galkov 2892
        push    edx
2893
        call    drawwindow_IV_caption
2894
        add     esp,4
2895
        jmp     .2
114 mikedld 2896
 
2897
  .not_style_3:
1055 Galkov 2898
        cmp     bl,2
2899
        jne     .not_style_2
114 mikedld 2900
 
1055 Galkov 2901
        call    drawwindow_III_caption
2902
        jmp     .2
114 mikedld 2903
 
2904
  .not_style_2:
1055 Galkov 2905
        cmp     bl,0
2906
        jne     .2
114 mikedld 2907
 
1055 Galkov 2908
        call    drawwindow_I_caption
114 mikedld 2909
 
2910
;--------------------------------------------------------------
1055 Galkov 2911
  .2:   ;jmp     @f
2912
        mov     edi,[CURRENT_TASK]
2913
        shl     edi,5
2914
        test    [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
2915
        jz      @f
2916
        mov     edx,[edi*8+SLOT_BASE+APPDATA.wnd_caption]
2917
        or      edx,edx
2918
        jz      @f
114 mikedld 2919
 
1055 Galkov 2920
        movzx   eax,[edi+window_data+WDATA.fl_wstyle]
2921
        and     al,0x0F
2922
        cmp     al,3
2923
        je      .skinned
2924
        cmp     al,4
2925
        je      .skinned
567 serge 2926
 
1055 Galkov 2927
        jmp     .not_skinned
567 serge 2928
  .skinned:
1055 Galkov 2929
        mov     ebp,[edi+window_data+WDATA.box.left-2]
2930
        mov     bp,word[edi+window_data+WDATA.box.top]
2931
        movzx   eax,word[edi+window_data+WDATA.box.width]
2932
        sub     ax,[_skinmargins.left]
2933
        sub     ax,[_skinmargins.right]
2934
        push    edx
2935
        cwde
2936
        cdq
2937
        mov     ebx,6
2938
        idiv    ebx
2939
        pop     edx
2940
        or      eax,eax
2941
        js      @f
2942
        mov     esi,eax
2943
        mov     ebx,dword[_skinmargins.left-2]
2944
        mov     bx,word[_skinh]
2945
        sub     bx,[_skinmargins.bottom]
2946
        sub     bx,[_skinmargins.top]
2947
        sar     bx,1
2948
        adc     bx,0
2949
        add     bx,[_skinmargins.top]
2950
        add     bx,-3
2951
        add     ebx,ebp
2952
        jmp     .dodraw
114 mikedld 2953
 
2954
  .not_skinned:
1055 Galkov 2955
        cmp     al,1
2956
        je      @f
114 mikedld 2957
 
1055 Galkov 2958
        mov     ebp,[edi+window_data+WDATA.box.left-2]
2959
        mov     bp,word[edi+window_data+WDATA.box.top]
2960
        movzx   eax,word[edi+window_data+WDATA.box.width]
2961
        sub     eax,16
2962
        push    edx
2963
        cwde
2964
        cdq
2965
        mov     ebx,6
2966
        idiv    ebx
2967
        pop     edx
2968
        or      eax,eax
2969
        js      @f
2970
        mov     esi,eax
2971
        mov     ebx,0x00080007
2972
        add     ebx,ebp
139 diamond 2973
.dodraw:
1055 Galkov 2974
        mov     ecx,[common_colours+16];0x00FFFFFF
2975
        or      ecx, 0x80000000
2976
        xor     edi,edi
803 alver 2977
; // Alver 22.06.2008 // {
1043 hidnplayr 2978
;       call    dtext
1055 Galkov 2979
        call dtext_asciiz_esi
803 alver 2980
; } \\ Alver \\
114 mikedld 2981
 
2982
    @@:
2983
;--------------------------------------------------------------
1055 Galkov 2984
        dec     [mouse_pause]
2985
        call    [draw_pointer]
2986
        ret
114 mikedld 2987
 
2988
iglobal
2989
align 4
2990
window_topleft dd \
1055 Galkov 2991
  1, 21,\               ;type 0
2992
  0,  0,\       ;type 1
2993
  5, 20,\       ;type 2
2994
  5,  ?,\       ;type 3 {set by skin}
2995
  5,  ?         ;type 4 {set by skin}
114 mikedld 2996
endg
2997
 
2998
set_window_clientbox:
1055 Galkov 2999
        push    eax ecx edi
114 mikedld 3000
 
1055 Galkov 3001
        mov     eax,[_skinh]
3002
        mov     [window_topleft+4*7],eax
3003
        mov     [window_topleft+4*9],eax
114 mikedld 3004
 
1055 Galkov 3005
        mov     ecx,edi
3006
        sub     edi,window_data
3007
        shl     edi,3
3008
        test    [ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE
3009
        jz      @f
114 mikedld 3010
 
1055 Galkov 3011
        movzx   eax,[ecx+WDATA.fl_wstyle]
3012
        and     eax,0x0F
3013
        mov     eax,[eax*8+window_topleft+0]
3014
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3015
        shl     eax,1
3016
        neg     eax
3017
        add     eax,[ecx+WDATA.box.width]
3018
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
114 mikedld 3019
 
1055 Galkov 3020
        movzx   eax,[ecx+WDATA.fl_wstyle]
3021
        and     eax,0x0F
3022
        push    [eax*8+window_topleft+0]
3023
        mov     eax,[eax*8+window_topleft+4]
3024
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3025
        neg     eax
3026
        sub     eax,[esp]
3027
        add     eax,[ecx+WDATA.box.height]
3028
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3029
        add     esp,4
114 mikedld 3030
 
1055 Galkov 3031
        pop     edi ecx eax
3032
        ret
114 mikedld 3033
    @@:
1055 Galkov 3034
        xor     eax,eax
3035
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3036
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3037
        mov     eax,[ecx+WDATA.box.width]
3038
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
3039
        mov     eax,[ecx+WDATA.box.height]
3040
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
114 mikedld 3041
 
1055 Galkov 3042
        pop     edi ecx eax
3043
        ret
114 mikedld 3044
 
1 ha 3045
sys_set_window:
3046
 
684 diamond 3047
    mov   eax,[CURRENT_TASK]
3048
    shl   eax,5
3049
    add   eax,window_data
1 ha 3050
 
3051
    ; colors
684 diamond 3052
    mov   [eax+WDATA.cl_workarea],edx
3053
    mov   [eax+WDATA.cl_titlebar],esi
3054
    mov   [eax+WDATA.cl_frames],edi
1 ha 3055
 
684 diamond 3056
    mov   edi, eax
3057
 
1 ha 3058
    ; check flag (?)
186 diamond 3059
    test  [edi+WDATA.fl_wdrawn],1
3060
    jnz   newd
1 ha 3061
 
3062
    mov   eax,[timer_ticks] ;[0xfdf0]
3063
    add   eax,100
3064
    mov   [new_window_starting],eax
3065
 
856 diamond 3066
    movsx eax,bx
3067
    mov   [edi+WDATA.box.width],eax
3068
    movsx eax,cx
3069
    mov   [edi+WDATA.box.height],eax
114 mikedld 3070
    sar   ebx,16
684 diamond 3071
    sar   ecx,16
856 diamond 3072
    mov   [edi+WDATA.box.left],ebx
3073
    mov   [edi+WDATA.box.top],ecx
1 ha 3074
 
3075
    call  check_window_position
3076
 
164 serge 3077
    call  set_window_clientbox
1 ha 3078
 
1055 Galkov 3079
    push  ecx esi edi               ; save for window fullscreen/resize
114 mikedld 3080
    ;mov   esi,edi
3081
 
1055 Galkov 3082
        mov     cl, [edi+WDATA.fl_wstyle]
3083
        mov     eax, [edi+WDATA.cl_frames]
114 mikedld 3084
 
1 ha 3085
    sub   edi,window_data
114 mikedld 3086
    shl   edi,3
380 serge 3087
    add   edi,SLOT_BASE
114 mikedld 3088
 
1055 Galkov 3089
        and     cl,0x0F
3090
        mov     [edi+APPDATA.wnd_caption],0
3091
        cmp     cl,3
3092
        je      set_APPDATA_wnd_caption
3093
        cmp     cl,4                                                            ; {SPraid.simba}
3094
        je      set_APPDATA_wnd_caption
567 serge 3095
 
1055 Galkov 3096
        jmp     @f
549 spraid 3097
    set_APPDATA_wnd_caption:
1055 Galkov 3098
        mov     [edi+APPDATA.wnd_caption],eax
3099
    @@: mov     esi,[esp+0]
114 mikedld 3100
 
115 poddubny 3101
    add   edi, APPDATA.saved_box
1055 Galkov 3102
        movsd
3103
        movsd
3104
        movsd
3105
        movsd
1 ha 3106
    pop   edi esi ecx
3107
 
1055 Galkov 3108
        mov     esi, [CURRENT_TASK]
3109
        movzx   esi, word [WIN_STACK+esi*2]
3110
        lea     esi, [WIN_POS+esi*2]
3111
        call    waredraw
569 diamond 3112
 
684 diamond 3113
;;;    mov   ebx, 1
1 ha 3114
;;;    call  delay_hs
115 poddubny 3115
    mov   eax, [edi+WDATA.box.left]
3116
    mov   ebx, [edi+WDATA.box.top]
3117
    mov   ecx, [edi+WDATA.box.width]
3118
    mov   edx, [edi+WDATA.box.height]
1 ha 3119
    add   ecx, eax
3120
    add   edx, ebx
3121
    call  calculatescreen
3122
 
1055 Galkov 3123
    mov   [KEY_COUNT],byte 0           ; empty keyboard buffer
3124
    mov   [BTN_COUNT],byte 0           ; empty button buffer
1 ha 3125
 
3126
  newd:
1055 Galkov 3127
    mov   [edi+WDATA.fl_redraw],byte 0   ; no redraw
1 ha 3128
    mov   edx,edi
3129
 
3130
    ret
3131
 
114 mikedld 3132
syscall_windowsettings:
1 ha 3133
 
114 mikedld 3134
  .set_window_caption:
1055 Galkov 3135
        dec     eax     ; subfunction #1 - set window caption
3136
        jnz     .get_window_caption
114 mikedld 3137
 
1055 Galkov 3138
        ; NOTE: only window owner thread can set its caption,
3139
        ;       so there's no parameter for PID/TID
114 mikedld 3140
 
1055 Galkov 3141
        mov     edi,[CURRENT_TASK]
3142
        shl     edi,5
114 mikedld 3143
 
1055 Galkov 3144
        ; have to check if caption is within application memory limit
3145
        ; check is trivial, and if application resizes its memory,
3146
        ;   caption still can become over bounds
202 diamond 3147
; diamond, 31.10.2006: check removed because with new memory manager
3148
; there can be valid data after APPDATA.mem_size bound
380 serge 3149
;        mov     ecx,[edi*8+SLOT_BASE+APPDATA.mem_size]
202 diamond 3150
;        add     ecx,255 ; max caption length
3151
;        cmp     ebx,ecx
3152
;        ja      .exit_fail
114 mikedld 3153
 
1055 Galkov 3154
        mov     [edi*8+SLOT_BASE+APPDATA.wnd_caption],ebx
3155
        or      [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
114 mikedld 3156
 
1055 Galkov 3157
        call    draw_window_caption
114 mikedld 3158
 
1055 Galkov 3159
        xor     eax,eax ; eax = 0 (success)
3160
        ret
114 mikedld 3161
 
3162
  .get_window_caption:
1055 Galkov 3163
        dec     eax     ; subfunction #2 - get window caption
3164
        jnz     .exit_fail
114 mikedld 3165
 
1055 Galkov 3166
        ; not implemented yet
114 mikedld 3167
 
3168
  .exit_fail:
1055 Galkov 3169
        xor     eax,eax
3170
        inc     eax     ; eax = 1 (fail)
3171
        ret
114 mikedld 3172
 
3173
 
1 ha 3174
sys_window_move:
3175
 
1055 Galkov 3176
        mov     edi,[CURRENT_TASK]
3177
        shl     edi,5
3178
        add     edi,window_data
1 ha 3179
 
1055 Galkov 3180
        test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
3181
        jnz     .window_move_return
1 ha 3182
 
1055 Galkov 3183
        push    dword [edi + WDATA.box.left]  ; save old coordinates
3184
        push    dword [edi + WDATA.box.top]
3185
        push    dword [edi + WDATA.box.width]
3186
        push    dword [edi + WDATA.box.height]
1 ha 3187
 
1055 Galkov 3188
        cmp   eax,-1                  ; set new position and size
3189
        je    .no_x_reposition
3190
        mov     [edi + WDATA.box.left], eax
49 mikedld 3191
      .no_x_reposition:
1055 Galkov 3192
        cmp   ebx,-1
3193
        je    .no_y_reposition
3194
        mov     [edi + WDATA.box.top], ebx
49 mikedld 3195
      .no_y_reposition:
1 ha 3196
 
1055 Galkov 3197
        test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
3198
        jnz     .no_y_resizing
1 ha 3199
 
1055 Galkov 3200
        cmp   ecx,-1
3201
        je    .no_x_resizing
3202
        mov     [edi + WDATA.box.width], ecx
49 mikedld 3203
      .no_x_resizing:
1055 Galkov 3204
        cmp   edx,-1
3205
        je    .no_y_resizing
3206
        mov     [edi + WDATA.box.height], edx
49 mikedld 3207
      .no_y_resizing:
1 ha 3208
 
1055 Galkov 3209
        call  check_window_position
3210
        call  set_window_clientbox
1 ha 3211
 
1055 Galkov 3212
        pushad                       ; save for window fullscreen/resize
3213
        mov   esi,edi
3214
        sub   edi,window_data
3215
        shr   edi,5
3216
        shl   edi,8
3217
        add   edi, SLOT_BASE + APPDATA.saved_box
3218
        mov   ecx,4
3219
        cld
3220
        rep   movsd
3221
        popad
49 mikedld 3222
 
1055 Galkov 3223
        pushad                       ; calculcate screen at new position
3224
        mov   eax, [edi + WDATA.box.left]
3225
        mov   ebx, [edi + WDATA.box.top]
3226
        mov   ecx, [edi + WDATA.box.width]
3227
        mov   edx, [edi + WDATA.box.height]
3228
        add   ecx,eax
3229
        add   edx,ebx
221 serge 3230
 
1055 Galkov 3231
        call  calculatescreen
3232
        popad
49 mikedld 3233
 
1055 Galkov 3234
        pop   edx                   ; calculcate screen at old position
3235
        pop   ecx
3236
        pop   ebx
3237
        pop   eax
3238
        add   ecx,eax
3239
        add   edx,ebx
3240
        mov   [dlx],eax             ; save for drawlimits
3241
        mov   [dly],ebx
3242
        mov   [dlxe],ecx
3243
        mov   [dlye],edx
3244
        call  calculatescreen
49 mikedld 3245
 
1055 Galkov 3246
        mov   [edi + WDATA.fl_redraw], 1 ; flag the process as redraw
49 mikedld 3247
 
1055 Galkov 3248
        mov   eax,edi               ; redraw screen at old position
3249
        xor   esi,esi
3250
        call  redrawscreen
49 mikedld 3251
 
1055 Galkov 3252
        mov   [DONT_DRAW_MOUSE],byte 0 ; mouse pointer
3253
        mov   [MOUSE_BACKGROUND],byte 0 ; no mouse under
3254
        mov   [MOUSE_DOWN],byte 0 ; react to mouse up/down
49 mikedld 3255
 
1055 Galkov 3256
        call  [draw_pointer]
49 mikedld 3257
 
1055 Galkov 3258
        mov   [window_move_pr],0
49 mikedld 3259
 
3260
      .window_move_return:
3261
 
1055 Galkov 3262
        ret
1 ha 3263
 
3264
uglobal
3265
  window_move_pr   dd  0x0
3266
  window_move_eax  dd  0x0
3267
  window_move_ebx  dd  0x0
3268
  window_move_ecx  dd  0x0
3269
  window_move_edx  dd  0x0
3270
endg
3271
 
3272
;ok - 100% work
3273
;nt - not tested
3274
;---------------------------------------------------------------------------------------------
3275
;eax
3276
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3277
;1 - change task. Ret nothing. Block. ok.
3278
;2 - performance control
3279
; ebx
3280
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3281
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3282
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3283
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3284
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3285
;eax
3286
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3287
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3288
;---------------------------------------------------------------------------------------------
3289
sys_sheduler: ;noname & halyavin
3290
    cmp eax,0
3291
    je shed_counter
3292
    cmp eax,2
3293
    je perf_control
3294
    cmp eax,3
3295
    je rdmsr_instr
3296
    cmp eax,4
3297
    je wrmsr_instr
3298
    cmp eax,1
3299
    jne not_supported
3300
    call change_task ;delay,0
3301
ret
3302
shed_counter:
3303
    mov eax,[context_counter]
3304
    mov [esp+36],eax
3305
not_supported:
3306
ret
3307
perf_control:
3308
    inc eax ;now eax=3
3309
    cmp ebx,eax
3310
    je cache_disable
3311
    dec eax
3312
    cmp ebx,eax
3313
    je cache_enable
3314
    dec eax
3315
    cmp ebx,eax
3316
    je is_cache_enabled
3317
    dec eax
3318
    cmp ebx,eax
3319
    je modify_pce
3320
ret
3321
 
3322
rdmsr_instr:
3323
;now counter in ecx
3324
;(edx:eax) esi:edi => edx:esi
3325
mov eax,esi
3326
rdmsr
3327
mov [esp+36],eax
3328
mov [esp+24],edx ;ret in ebx?
3329
ret
3330
 
3331
wrmsr_instr:
3332
;now counter in ecx
3333
;(edx:eax) esi:edi => edx:esi
1055 Galkov 3334
        ; Fast Call MSR can't be destroy
3335
        ; Íî MSR_AMD_EFER ìîæíî èçìåíÿòü, ò.ê. â ýòîì ðåãèñòðå ëèø
3336
        ; âêëþ÷àþòñÿ/âûêëþ÷àþòñÿ ðàñøèðåííûå âîçìîæíîñòè
3337
        cmp     ecx, MSR_SYSENTER_CS
3338
        je      @f
3339
        cmp     ecx, MSR_SYSENTER_ESP
3340
        je      @f
3341
        cmp     ecx, MSR_SYSENTER_EIP
3342
        je      @f
3343
        cmp     ecx, MSR_AMD_STAR
3344
        je      @f
482 Ghost 3345
 
1055 Galkov 3346
        mov     eax, esi
3347
        wrmsr
3348
        ; mov   [esp + 36], eax
3349
        ; mov   [esp + 24], edx ;ret in ebx?
482 Ghost 3350
@@:
1 ha 3351
ret
3352
 
3353
cache_disable:
3354
       mov eax,cr0
3355
       or  eax,01100000000000000000000000000000b
3356
       mov cr0,eax
3357
       wbinvd ;set MESI
3358
ret
3359
 
3360
cache_enable:
3361
       mov eax,cr0
3362
       and eax,10011111111111111111111111111111b
3363
       mov cr0,eax
3364
ret
3365
 
3366
is_cache_enabled:
3367
       mov eax,cr0
3368
       mov ebx,eax
3369
       and eax,01100000000000000000000000000000b
3370
       jz cache_disabled
3371
       mov [esp+36],ebx
3372
cache_disabled:
3373
       mov dword [esp+36],eax ;0
3374
ret
3375
 
3376
modify_pce:
3377
       mov eax,cr4
3378
;       mov ebx,0
3379
;       or  bx,100000000b ;pce
3380
;       xor eax,ebx ;invert pce
17 me_root 3381
       bts eax,8 ;pce=cr4[8]
1 ha 3382
       mov cr4,eax
3383
       mov [esp+36],eax
3384
ret
3385
;---------------------------------------------------------------------------------------------
3386
 
3387
 
3388
; check if pixel is allowed to be drawn
3389
 
3390
checkpixel:
1055 Galkov 3391
        push eax edx
1 ha 3392
 
1055 Galkov 3393
        mov  edx,[Screen_Max_X]     ; screen x size
3394
        inc  edx
3395
        imul edx, ebx
3396
        mov  dl, [eax+edx+display_data] ; lea eax, [...]
1 ha 3397
 
1055 Galkov 3398
        xor  ecx, ecx
3399
        mov  eax, [CURRENT_TASK]
3400
        cmp  al, dl
3401
        setne cl
1 ha 3402
 
1055 Galkov 3403
        pop  edx eax
3404
        ret
1 ha 3405
 
3406
iglobal
521 diamond 3407
  cpustring db 'CPU',0
1 ha 3408
endg
3409
 
67 diamond 3410
uglobal
1055 Galkov 3411
background_defined    db    0    ; diamond, 11.04.2006
67 diamond 3412
endg
1 ha 3413
 
3414
align 4
3415
; check misc
3416
 
3417
checkmisc:
3418
 
3419
    cmp   [ctrl_alt_del], 1
3420
    jne   nocpustart
501 serge 3421
 
1055 Galkov 3422
        mov     ebp, cpustring
3423
        call    fs_execute_from_sysdir
501 serge 3424
 
1 ha 3425
    mov   [ctrl_alt_del], 0
465 serge 3426
 
3427
nocpustart:
1 ha 3428
    cmp   [mouse_active], 1
3429
    jne   mouse_not_active
3430
    mov   [mouse_active], 0
3431
    xor   edi, edi
1055 Galkov 3432
    mov   ecx,  [TASK_COUNT]
465 serge 3433
set_mouse_event:
1 ha 3434
    add   edi, 256
1055 Galkov 3435
    or    [edi+SLOT_BASE+APPDATA.event_mask], dword 100000b
1 ha 3436
    loop  set_mouse_event
3437
 
465 serge 3438
mouse_not_active:
1055 Galkov 3439
    cmp   [REDRAW_BACKGROUND],byte 0               ; background update ?
3440
    jz    nobackgr
76 mario79 3441
    cmp    [background_defined], 0
1055 Galkov 3442
    jz    nobackgr
709 diamond 3443
    cmp   [REDRAW_BACKGROUND], byte 2
3444
    jnz   no_set_bgr_event
473 diamond 3445
    xor   edi, edi
1055 Galkov 3446
    mov   ecx,  [TASK_COUNT]
473 diamond 3447
set_bgr_event:
3448
    add   edi, 256
1055 Galkov 3449
    or    [edi+SLOT_BASE+APPDATA.event_mask], 16
473 diamond 3450
    loop  set_bgr_event
709 diamond 3451
no_set_bgr_event:
3452
;    mov   [draw_data+32 + RECT.left],dword 0
3453
;    mov   [draw_data+32 + RECT.top],dword 0
753 serge 3454
;    mov   eax,[Screen_Max_X]
3455
;    mov   ebx,[Screen_Max_Y]
709 diamond 3456
;    mov   [draw_data+32 + RECT.right],eax
3457
;    mov   [draw_data+32 + RECT.bottom],ebx
1 ha 3458
    call  drawbackground
381 serge 3459
    mov   [REDRAW_BACKGROUND],byte 0
3460
    mov   [MOUSE_BACKGROUND],byte 0
1 ha 3461
 
465 serge 3462
nobackgr:
1 ha 3463
 
3464
    ; system shutdown request
3465
 
381 serge 3466
    cmp  [SYS_SHUTDOWN],byte 0
1055 Galkov 3467
    je   noshutdown
1 ha 3468
 
3469
    mov  edx,[shutdown_processes]
3470
 
381 serge 3471
    cmp  [SYS_SHUTDOWN],dl
1 ha 3472
    jne  no_mark_system_shutdown
3473
 
709 diamond 3474
    lea   ecx,[edx-1]
465 serge 3475
    mov   edx,OS_BASE+0x3040
709 diamond 3476
    jecxz @f
465 serge 3477
markz:
115 poddubny 3478
    mov   [edx+TASKDATA.state],byte 3
1 ha 3479
    add   edx,0x20
3480
    loop  markz
709 diamond 3481
@@:
1 ha 3482
 
3483
  no_mark_system_shutdown:
3484
 
3485
    call [disable_mouse]
3486
 
381 serge 3487
    dec  byte [SYS_SHUTDOWN]
1055 Galkov 3488
    je   system_shutdown
1 ha 3489
 
465 serge 3490
noshutdown:
1 ha 3491
 
3492
 
1055 Galkov 3493
    mov   eax,[TASK_COUNT]                  ; termination
379 serge 3494
    mov   ebx,TASK_DATA+TASKDATA.state
1 ha 3495
    mov   esi,1
3496
 
465 serge 3497
newct:
1 ha 3498
    mov   cl,[ebx]
3499
    cmp   cl,byte 3
1055 Galkov 3500
    jz    terminate
1 ha 3501
    cmp   cl,byte 4
1055 Galkov 3502
    jz    terminate
1 ha 3503
 
3504
    add   ebx,0x20
3505
    inc   esi
3506
    dec   eax
3507
    jnz   newct
3508
    ret
3509
 
3510
; redraw screen
3511
 
3512
redrawscreen:
3513
 
3514
; eax , if process window_data base is eax, do not set flag/limits
3515
 
1055 Galkov 3516
         pushad
3517
         push  eax
1 ha 3518
 
684 diamond 3519
;;;         mov   ebx,2
1 ha 3520
;;;         call  delay_hs
3521
 
1055 Galkov 3522
         ;mov   ecx,0               ; redraw flags for apps
3523
         xor   ecx,ecx
1 ha 3524
       newdw2:
3525
 
1055 Galkov 3526
         inc   ecx
3527
         push  ecx
1 ha 3528
 
1055 Galkov 3529
         mov   eax,ecx
3530
         shl   eax,5
3531
         add   eax,window_data
1 ha 3532
 
1055 Galkov 3533
         cmp   eax,[esp+4]
3534
         je    not_this_task
3535
                                   ; check if window in redraw area
3536
         mov   edi,eax
1 ha 3537
 
1055 Galkov 3538
         cmp   ecx,1               ; limit for background
3539
         jz    bgli
1 ha 3540
 
1055 Galkov 3541
         mov   eax, [edi + WDATA.box.left]
3542
         mov   ebx, [edi + WDATA.box.top]
3543
         mov   ecx, [edi + WDATA.box.width]
3544
         mov   edx, [edi + WDATA.box.height]
3545
         add   ecx,eax
3546
         add   edx,ebx
1 ha 3547
 
1055 Galkov 3548
         mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
3549
         cmp   ecx,ebx
3550
         jb    ricino
1 ha 3551
 
1055 Galkov 3552
         mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
3553
         cmp   ecx,eax
3554
         jb    ricino
1 ha 3555
 
1055 Galkov 3556
         mov   eax, [edi + WDATA.box.left]
3557
         mov   ebx, [edi + WDATA.box.top]
3558
         mov   ecx, [edi + WDATA.box.width]
3559
         mov   edx, [edi + WDATA.box.height]
3560
         add   ecx, eax
3561
         add   edx, ebx
164 serge 3562
 
1055 Galkov 3563
         mov   eax,[dly]    ; eax = area y start     edx = window y end
3564
         cmp   edx,eax
3565
         jb    ricino
1 ha 3566
 
1055 Galkov 3567
         mov   eax,[dlx]    ; eax = area x start     ecx = window x end
3568
         cmp   ecx,eax
3569
         jb    ricino
1 ha 3570
 
1055 Galkov 3571
        bgli:
1 ha 3572
 
1055 Galkov 3573
         cmp   ecx,1
3574
         jnz   .az
3575
         mov   al,[REDRAW_BACKGROUND]
3576
         cmp   al,2
3577
         jz    newdw8
3578
         test  al,al
3579
         jz    .az
3580
         lea   eax,[edi+draw_data-window_data]
3581
         mov   ebx,[dlx]
3582
         cmp   ebx,[eax+RECT.left]
3583
         jae   @f
3584
         mov   [eax+RECT.left],ebx
3585
        @@:
3586
         mov   ebx,[dly]
3587
         cmp   ebx,[eax+RECT.top]
3588
         jae   @f
3589
         mov   [eax+RECT.top],ebx
3590
        @@:
3591
         mov   ebx,[dlxe]
3592
         cmp   ebx,[eax+RECT.right]
3593
         jbe   @f
3594
         mov   [eax+RECT.right],ebx
3595
        @@:
3596
         mov   ebx,[dlye]
3597
         cmp   ebx,[eax+RECT.bottom]
3598
         jbe   @f
3599
         mov   [eax+RECT.bottom],ebx
3600
        @@:
3601
         jmp   newdw8
3602
        .az:
1 ha 3603
 
1055 Galkov 3604
         mov   eax,edi
3605
         add   eax,draw_data-window_data
1 ha 3606
 
1055 Galkov 3607
         mov   ebx,[dlx]          ; set limits
3608
         mov   [eax + RECT.left], ebx
3609
         mov   ebx,[dly]
3610
         mov   [eax + RECT.top], ebx
3611
         mov   ebx,[dlxe]
3612
         mov   [eax + RECT.right], ebx
3613
         mov   ebx,[dlye]
3614
         mov   [eax + RECT.bottom], ebx
1 ha 3615
 
1055 Galkov 3616
         sub   eax,draw_data-window_data
1 ha 3617
 
1055 Galkov 3618
         cmp   dword [esp],1
3619
         jne   nobgrd
3620
         mov   byte [REDRAW_BACKGROUND], 1
1 ha 3621
 
3622
       newdw8:
3623
       nobgrd:
3624
 
1055 Galkov 3625
         mov   [eax + WDATA.fl_redraw],byte 1    ; mark as redraw
1 ha 3626
 
3627
       ricino:
3628
 
3629
       not_this_task:
3630
 
1055 Galkov 3631
         pop   ecx
1 ha 3632
 
1055 Galkov 3633
         cmp   ecx,[TASK_COUNT]
3634
         jle   newdw2
1 ha 3635
 
1055 Galkov 3636
         pop  eax
3637
         popad
1 ha 3638
 
1055 Galkov 3639
         ret
1 ha 3640
 
3641
calculatebackground:   ; background
3642
 
1055 Galkov 3643
        ; all black
1 ha 3644
 
1055 Galkov 3645
        mov   edi, [img_background]  ;IMG_BACKGROUND                 ; set background to black
3646
        xor   eax, eax
3647
        mov   ecx, 1023    ;0x0fff00 / 4
3648
        cld
3649
        rep   stosd
1 ha 3650
 
1055 Galkov 3651
        mov   edi,display_data              ; set os to use all pixels
3652
        mov   eax,0x01010101
3653
        mov   ecx,1280*1024 / 4
3654
        rep   stosd
1 ha 3655
 
1055 Galkov 3656
        mov   byte [REDRAW_BACKGROUND], 0              ; do not draw background!
1 ha 3657
 
1055 Galkov 3658
        ret
1 ha 3659
 
3660
uglobal
1055 Galkov 3661
  imax    dd 0x0
1 ha 3662
endg
3663
 
3664
 
3665
 
3666
delay_ms:     ; delay in 1/1000 sec
3667
 
3668
 
1055 Galkov 3669
        push  eax
3670
        push  ecx
1 ha 3671
 
1055 Galkov 3672
        mov   ecx,esi
3673
        ; 
3674
        imul  ecx, 33941
3675
        shr   ecx, 9
3676
        ; 
1 ha 3677
 
1055 Galkov 3678
        in    al,0x61
3679
        and   al,0x10
3680
        mov   ah,al
3681
        cld
1 ha 3682
 
1055 Galkov 3683
 cnt1:  in    al,0x61
3684
        and   al,0x10
3685
        cmp   al,ah
3686
        jz    cnt1
1 ha 3687
 
1055 Galkov 3688
        mov   ah,al
3689
        loop  cnt1
1 ha 3690
 
1055 Galkov 3691
        pop   ecx
3692
        pop   eax
1 ha 3693
 
1055 Galkov 3694
        ret
1 ha 3695
 
3696
 
3697
set_app_param:
1055 Galkov 3698
        mov     edi, [TASK_BASE]
3699
        mov     [edi + TASKDATA.event_mask], ebx
3700
        ret
1 ha 3701
 
3702
 
3703
 
3704
delay_hs:     ; delay in 1/100 secs
684 diamond 3705
; ebx = delay time
1055 Galkov 3706
        push  ecx
3707
        push  edx
1 ha 3708
 
1055 Galkov 3709
        mov   edx,[timer_ticks]
1 ha 3710
 
3711
      newtic:
1055 Galkov 3712
        mov   ecx,[timer_ticks]
3713
        sub   ecx,edx
3714
        cmp   ecx,ebx
3715
        jae   zerodelay
1 ha 3716
 
1055 Galkov 3717
        call  change_task
1 ha 3718
 
1055 Galkov 3719
        jmp   newtic
1 ha 3720
 
3721
      zerodelay:
1055 Galkov 3722
        pop   edx
3723
        pop   ecx
1 ha 3724
 
1055 Galkov 3725
        ret
1 ha 3726
 
3727
 
3728
memmove:       ; memory move in bytes
3729
 
3730
; eax = from
3731
; ebx = to
3732
; ecx = no of bytes
3733
    test ecx, ecx
3734
    jle  .ret
3735
 
3736
 
3737
    push esi edi ecx
3738
 
3739
    mov  edi, ebx
3740
    mov  esi, eax
3741
 
3742
    test ecx, not 11b
1055 Galkov 3743
    jz   @f
1 ha 3744
 
3745
    push ecx
3746
    shr  ecx, 2
3747
    rep  movsd
3748
    pop  ecx
3749
    and  ecx, 11b
1055 Galkov 3750
    jz   .finish
1 ha 3751
  @@:
3752
    rep  movsb
3753
 
3754
  .finish:
3755
    pop  ecx edi esi
3756
  .ret:
3757
    ret
3758
 
3759
 
75 diamond 3760
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
3761
;align 4
1 ha 3762
;
75 diamond 3763
;read_floppy_file:
1 ha 3764
;
75 diamond 3765
;; as input
3766
;;
3767
;; eax pointer to file
3768
;; ebx file lenght
3769
;; ecx start 512 byte block number
3770
;; edx number of blocks to read
3771
;; esi pointer to return/work area (atleast 20 000 bytes)
3772
;;
3773
;;
3774
;; on return
3775
;;
3776
;; eax = 0 command succesful
3777
;;       1 no fd base and/or partition defined
3778
;;       2 yet unsupported FS
3779
;;       3 unknown FS
3780
;;       4 partition not defined at hd
3781
;;       5 file not found
3782
;; ebx = size of file
1 ha 3783
;
379 serge 3784
;     mov   edi,[TASK_BASE]
75 diamond 3785
;     add   edi,0x10
3786
;     add   esi,[edi]
3787
;     add   eax,[edi]
1 ha 3788
;
75 diamond 3789
;     pushad
3790
;     mov  edi,esi
3791
;     add  edi,1024
3792
;     mov  esi,0x100000+19*512
3793
;     sub  ecx,1
3794
;     shl  ecx,9
3795
;     add  esi,ecx
3796
;     shl  edx,9
3797
;     mov  ecx,edx
3798
;     cld
3799
;     rep  movsb
3800
;     popad
3801
;
3802
;     mov   [esp+36],eax
3803
;     mov   [esp+24],ebx
3804
;     ret
1 ha 3805
 
3806
 
3807
 
3808
align 4
3809
 
3810
sys_programirq:
3811
 
765 Rus 3812
    mov   eax, [TASK_BASE]
3813
    add   ebx, [eax + TASKDATA.mem_start]
1 ha 3814
 
765 Rus 3815
    cmp   ecx, 16
75 diamond 3816
    jae   .not_owner
765 Rus 3817
    mov   edi, [eax + TASKDATA.pid]
3818
    cmp   edi, [irq_owner + 4 * ecx]
1055 Galkov 3819
    je    .spril1
75 diamond 3820
.not_owner:
765 Rus 3821
    xor   ecx, ecx
973 diamond 3822
    inc   ecx
765 Rus 3823
    jmp   .end
3824
  .spril1:
1 ha 3825
 
765 Rus 3826
    shl   ecx, 6
3827
    mov   esi, ebx
3828
    lea   edi, [irq00read + ecx]
3829
    push  16
3830
    pop   ecx
3831
 
1 ha 3832
    cld
3833
    rep   movsd
765 Rus 3834
  .end:
3835
    mov   [esp+32], ecx
1 ha 3836
    ret
3837
 
3838
 
3839
align 4
3840
 
3841
get_irq_data:
1055 Galkov 3842
     movzx esi, bh                       ; save number of subfunction, if bh = 1, return data size, otherwise, read data
760 Rus 3843
     xor   bh, bh
3844
     cmp   ebx, 16
75 diamond 3845
     jae   .not_owner
1055 Galkov 3846
     mov   edx, [4 * ebx + irq_owner]    ; check for irq owner
742 Rus 3847
 
760 Rus 3848
     mov   eax,[TASK_BASE]
742 Rus 3849
 
760 Rus 3850
     cmp   edx,[eax+TASKDATA.pid]
1 ha 3851
     je    gidril1
75 diamond 3852
.not_owner:
760 Rus 3853
     xor   edx, edx
3854
     dec   edx
3855
     jmp   gid1
1 ha 3856
 
3857
  gidril1:
3858
 
760 Rus 3859
     shl   ebx, 12
1055 Galkov 3860
     lea   eax, [ebx + IRQ_SAVE]         ; calculate address of the beginning of buffer + 0x0 - data size
3861
     mov   edx, [eax]                    ;                                              + 0x4 - data offset
760 Rus 3862
     dec   esi
1 ha 3863
     jz    gid1
1055 Galkov 3864
     test  edx, edx                      ; check if buffer is empty
760 Rus 3865
     jz    gid1
1 ha 3866
 
760 Rus 3867
     mov   ebx, [eax + 0x4]
3868
     mov   edi, ecx
742 Rus 3869
 
1055 Galkov 3870
     mov   ecx, 4000                     ; buffer size, used frequently
742 Rus 3871
 
1055 Galkov 3872
     cmp   ebx, ecx                      ; check for the end of buffer, if end of buffer, begin cycle again
759 Rus 3873
     jb    @f
742 Rus 3874
 
760 Rus 3875
     xor   ebx, ebx
759 Rus 3876
 
3877
   @@:
3878
 
1055 Galkov 3879
     lea   esi, [ebx + edx]              ; calculate data size and offset
760 Rus 3880
     cld
1055 Galkov 3881
     cmp   esi, ecx                      ; if greater than the buffer size, begin cycle again
760 Rus 3882
     jbe   @f
759 Rus 3883
 
760 Rus 3884
     sub   ecx, ebx
3885
     sub   edx, ecx
759 Rus 3886
 
760 Rus 3887
     lea   esi, [eax + ebx + 0x10]
3888
     rep   movsb
3889
 
3890
     xor   ebx, ebx
3891
   @@:
3892
     lea   esi, [eax + ebx + 0x10]
3893
     mov   ecx, edx
3894
     add   ebx, edx
3895
 
3896
     rep   movsb
3897
     mov   edx, [eax]
1055 Galkov 3898
     mov   [eax], ecx                    ; set data size to zero
3899
     mov   [eax + 0x4], ebx              ; set data offset
760 Rus 3900
 
1 ha 3901
   gid1:
1055 Galkov 3902
     mov   [esp+32], edx                 ; eax
1 ha 3903
     ret
3904
 
3905
 
3906
set_io_access_rights:
3907
 
3908
     pushad
3909
 
465 serge 3910
     mov edi, tss._io_map_0
1 ha 3911
 
465 serge 3912
;     mov   ecx,eax
3913
;     and   ecx,7    ; offset in byte
1 ha 3914
 
465 serge 3915
;     shr   eax,3    ; number of byte
3916
;     add   edi,eax
1 ha 3917
 
465 serge 3918
;     mov   ebx,1
3919
;     shl   ebx,cl
1 ha 3920
 
1055 Galkov 3921
     cmp   ebp,0                ; enable access - ebp = 0
1 ha 3922
     jne   siar1
3923
 
465 serge 3924
;     not   ebx
3925
;     and   [edi],byte bl
3926
     btr [edi], eax
1 ha 3927
 
3928
     popad
3929
 
3930
     ret
3931
 
465 serge 3932
siar1:
1 ha 3933
 
465 serge 3934
     bts [edi], eax
3935
  ;  or    [edi],byte bl        ; disable access - ebp = 1
1 ha 3936
 
3937
     popad
3938
 
3939
     ret
3940
 
3941
r_f_port_area:
3942
 
3943
     test  eax, eax
3944
     jnz   free_port_area
3945
;     je    r_port_area
3946
;     jmp   free_port_area
3947
 
3948
;   r_port_area:
3949
 
3950
     pushad
3951
 
1055 Galkov 3952
     cmp   ebx,ecx            ; beginning > end ?
75 diamond 3953
     ja    rpal1
3954
     cmp   ecx,65536
3955
     jae   rpal1
381 serge 3956
     mov   esi,[RESERVED_PORTS]
1055 Galkov 3957
     test  esi,esi            ; no reserved areas ?
1 ha 3958
     je    rpal2
1055 Galkov 3959
     cmp   esi,255            ; max reserved
75 diamond 3960
     jae   rpal1
465 serge 3961
 rpal3:
1 ha 3962
     mov   edi,esi
3963
     shl   edi,4
381 serge 3964
     add   edi,RESERVED_PORTS
1 ha 3965
     cmp   ebx,[edi+8]
75 diamond 3966
     ja    rpal4
1 ha 3967
     cmp   ecx,[edi+4]
3968
     jae   rpal1
3969
;     jb    rpal4
3970
;     jmp   rpal1
465 serge 3971
 rpal4:
1 ha 3972
 
3973
     dec   esi
3974
     jnz   rpal3
3975
     jmp   rpal2
3976
   rpal1:
3977
     popad
3978
     mov   eax,1
3979
     ret
3980
 
3981
   rpal2:
3982
     popad
3983
 
3984
 
3985
     ; enable port access at port IO map
3986
     cli
1055 Galkov 3987
     pushad                        ; start enable io map
1 ha 3988
 
3989
     cmp   ecx,65536 ;16384
3990
     jae   no_unmask_io ; jge
3991
 
3992
     mov   eax,ebx
3993
 
3994
   new_port_access:
3995
 
3996
     pushad
3997
 
1055 Galkov 3998
     xor   ebp,ebp                ; enable - eax = port
1 ha 3999
     call  set_io_access_rights
4000
 
4001
     popad
4002
 
4003
     inc   eax
4004
     cmp   eax,ecx
4005
     jbe   new_port_access
4006
 
4007
   no_unmask_io:
4008
 
1055 Galkov 4009
     popad                         ; end enable io map
1 ha 4010
     sti
4011
 
381 serge 4012
     mov   edi,[RESERVED_PORTS]
1 ha 4013
     add   edi,1
381 serge 4014
     mov   [RESERVED_PORTS],edi
1 ha 4015
     shl   edi,4
381 serge 4016
     add   edi,RESERVED_PORTS
379 serge 4017
     mov   esi,[TASK_BASE]
115 poddubny 4018
     mov   esi,[esi+TASKDATA.pid]
1 ha 4019
     mov   [edi],esi
4020
     mov   [edi+4],ebx
4021
     mov   [edi+8],ecx
4022
 
4023
     xor   eax, eax
4024
     ret
4025
 
4026
free_port_area:
4027
 
4028
     pushad
4029
 
381 serge 4030
     mov   esi,[RESERVED_PORTS]     ; no reserved areas ?
75 diamond 4031
     test  esi,esi
1 ha 4032
     je    frpal2
379 serge 4033
     mov   edx,[TASK_BASE]
115 poddubny 4034
     mov   edx,[edx+TASKDATA.pid]
1 ha 4035
   frpal3:
4036
     mov   edi,esi
4037
     shl   edi,4
381 serge 4038
     add   edi,RESERVED_PORTS
1 ha 4039
     cmp   edx,[edi]
4040
     jne   frpal4
4041
     cmp   ebx,[edi+4]
4042
     jne   frpal4
4043
     cmp   ecx,[edi+8]
4044
     jne   frpal4
4045
     jmp   frpal1
4046
   frpal4:
4047
     dec   esi
4048
     jnz   frpal3
4049
   frpal2:
4050
     popad
4051
     mov   eax,1
4052
     ret
4053
   frpal1:
4054
     mov   ecx,256
4055
     sub   ecx,esi
4056
     shl   ecx,4
4057
     mov   esi,edi
4058
     add   esi,16
4059
     cld
4060
     rep   movsb
4061
 
381 serge 4062
     dec   dword [RESERVED_PORTS]
1 ha 4063
 
4064
     popad
4065
 
4066
 
4067
     ; disable port access at port IO map
4068
 
1055 Galkov 4069
     pushad                        ; start disable io map
1 ha 4070
 
4071
     cmp   ecx,65536 ;16384
4072
     jge   no_mask_io
4073
 
4074
     mov   eax,ebx
4075
 
4076
   new_port_access_disable:
4077
 
4078
     pushad
4079
 
1055 Galkov 4080
     mov   ebp,1                  ; disable - eax = port
1 ha 4081
     call  set_io_access_rights
4082
 
4083
     popad
4084
 
4085
     inc   eax
4086
     cmp   eax,ecx
4087
     jbe   new_port_access_disable
4088
 
4089
   no_mask_io:
4090
 
1055 Galkov 4091
     popad                         ; end disable io map
1 ha 4092
 
4093
     xor   eax, eax
4094
     ret
4095
 
4096
 
4097
reserve_free_irq:
4098
 
765 Rus 4099
     xor   esi, esi
4100
     inc   esi
4101
     cmp   ecx, 16
4102
     jae   ril1
1 ha 4103
 
769 Rus 4104
     push  ecx
765 Rus 4105
     lea   ecx, [irq_owner + 4 * ecx]
4106
     mov   edx, [ecx]
4107
     mov   eax, [TASK_BASE]
4108
     mov   edi, [eax + TASKDATA.pid]
769 Rus 4109
     pop   eax
765 Rus 4110
     dec   ebx
4111
     jnz   reserve_irq
1 ha 4112
 
765 Rus 4113
     cmp   edx, edi
4114
     jne   ril1
4115
     dec   esi
4116
     mov   [ecx], esi
4117
 
4118
     jmp   ril1
4119
 
1 ha 4120
  reserve_irq:
4121
 
765 Rus 4122
     cmp   dword [ecx], 0
4123
     jne   ril1
1 ha 4124
 
769 Rus 4125
     mov   ebx, [f_irqs + 4 * eax]
4126
 
774 Rus 4127
     stdcall attach_int_handler, eax, ebx, dword 0
769 Rus 4128
 
765 Rus 4129
     mov   [ecx], edi
769 Rus 4130
 
765 Rus 4131
     dec   esi
1 ha 4132
   ril1:
765 Rus 4133
     mov   [esp+32], esi ; return in eax
1 ha 4134
     ret
4135
 
769 Rus 4136
iglobal
4137
f_irqs:
4138
     dd 0x0
4139
     dd 0x0
4140
     dd p_irq2
4141
     dd p_irq3
4142
     dd p_irq4
4143
     dd p_irq5
4144
     dd p_irq6
4145
     dd p_irq7
4146
     dd p_irq8
4147
     dd p_irq9
4148
     dd p_irq10
4149
     dd p_irq11
4150
     dd 0x0
4151
     dd 0x0
4152
     dd p_irq14
4153
     dd p_irq15
4154
 
4155
endg
4156
 
1 ha 4157
drawbackground:
33 mario79 4158
       inc   [mouse_pause]
381 serge 4159
       cmp   [SCR_MODE],word 0x12
117 mario79 4160
       je   dbrv20
1 ha 4161
     dbrv12:
381 serge 4162
       cmp  [SCR_MODE],word 0100000000000000b
1 ha 4163
       jge  dbrv20
381 serge 4164
       cmp  [SCR_MODE],word 0x13
1 ha 4165
       je   dbrv20
4166
       call  vesa12_drawbackground
33 mario79 4167
       dec   [mouse_pause]
36 mario79 4168
       call   [draw_pointer]
1 ha 4169
       ret
4170
     dbrv20:
527 diamond 4171
       cmp   [BgrDrawMode],dword 1
1 ha 4172
       jne   bgrstr
4173
       call  vesa20_drawbackground_tiled
33 mario79 4174
       dec   [mouse_pause]
36 mario79 4175
       call   [draw_pointer]
1 ha 4176
       ret
4177
     bgrstr:
4178
       call  vesa20_drawbackground_stretch
33 mario79 4179
       dec   [mouse_pause]
36 mario79 4180
       call   [draw_pointer]
1 ha 4181
       ret
4182
 
75 diamond 4183
align 4
1 ha 4184
 
1055 Galkov 4185
syscall_putimage:                       ; PutImage
1 ha 4186
sys_putimage:
53 mikedld 4187
     test  ecx,0x80008000
4188
     jnz   .exit
4189
     test  ecx,0x0000FFFF
4190
     jz    .exit
4191
     test  ecx,0xFFFF0000
4192
     jnz   @f
4193
  .exit:
4194
     ret
4195
 @@:
1055 Galkov 4196
        mov     edi,[current_slot]
4197
        add     dx,word[edi+APPDATA.wnd_clientbox.top]
4198
        rol     edx,16
4199
        add     dx,word[edi+APPDATA.wnd_clientbox.left]
4200
        rol     edx,16
114 mikedld 4201
  .forced:
1055 Galkov 4202
        push    ebp esi 0
4203
        mov     ebp, putimage_get24bpp
4204
        mov     esi, putimage_init24bpp
283 diamond 4205
sys_putimage_bpp:
4206
;        call    [disable_mouse] ; this will be done in xxx_putimage
117 mario79 4207
;        mov     eax, vga_putimage
1055 Galkov 4208
        cmp     [SCR_MODE], word 0x12
4209
        jz      @f   ;.doit
4210
        mov     eax, vesa12_putimage
4211
        cmp     [SCR_MODE], word 0100000000000000b
4212
        jae     @f
4213
        cmp     [SCR_MODE], word 0x13
4214
        jnz     .doit
75 diamond 4215
@@:
1055 Galkov 4216
        mov     eax, vesa20_putimage
75 diamond 4217
.doit:
1055 Galkov 4218
        inc     [mouse_pause]
4219
        call    eax
4220
        dec     [mouse_pause]
4221
        pop     ebp esi ebp
4222
        jmp     [draw_pointer]
1 ha 4223
 
283 diamond 4224
syscall_putimage_palette:
1055 Galkov 4225
        mov     edi, esi
4226
        mov     esi, edx
4227
        mov     edx, ecx
4228
        mov     ecx, ebx
4229
        mov     ebx, eax
283 diamond 4230
sys_putimage_palette:
4231
; ebx = pointer to image
4232
; ecx = [xsize]*65536 + [ysize]
4233
; edx = [xstart]*65536 + [ystart]
314 diamond 4234
; esi = number of bits per pixel, must be 8, 24 or 32
283 diamond 4235
; edi = pointer to palette
314 diamond 4236
; ebp = row delta
1055 Galkov 4237
        mov     eax, [CURRENT_TASK]
4238
        shl     eax, 8
4239
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
4240
        rol     edx, 16
4241
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
4242
        rol     edx, 16
283 diamond 4243
.forced:
1055 Galkov 4244
        cmp     esi, 1
4245
        jnz     @f
4246
        push    edi
4247
        mov     eax, [edi+4]
4248
        sub     eax, [edi]
4249
        push    eax
4250
        push    dword [edi]
4251
        push    0ffffff80h
4252
        mov     edi, esp
4253
        call    put_mono_image
4254
        add     esp, 12
4255
        pop     edi
4256
        ret
911 diamond 4257
@@:
1055 Galkov 4258
        cmp     esi, 2
4259
        jnz     @f
4260
        push    edi
4261
        push    0ffffff80h
4262
        mov     edi, esp
4263
        call    put_2bit_image
4264
        pop     eax
4265
        pop     edi
4266
        ret
911 diamond 4267
@@:
1055 Galkov 4268
        cmp     esi, 4
4269
        jnz     @f
4270
        push    edi
4271
        push    0ffffff80h
4272
        mov     edi, esp
4273
        call    put_4bit_image
4274
        pop     eax
4275
        pop     edi
4276
        ret
314 diamond 4277
@@:
1055 Galkov 4278
        push    ebp esi ebp
4279
        cmp     esi, 8
4280
        jnz     @f
4281
        mov     ebp, putimage_get8bpp
4282
        mov     esi, putimage_init8bpp
4283
        jmp     sys_putimage_bpp
918 diamond 4284
@@:
1055 Galkov 4285
        cmp     esi, 15
4286
        jnz     @f
4287
        mov     ebp, putimage_get15bpp
4288
        mov     esi, putimage_init15bpp
4289
        jmp     sys_putimage_bpp
906 diamond 4290
@@:
1055 Galkov 4291
        cmp     esi, 16
4292
        jnz     @f
4293
        mov     ebp, putimage_get16bpp
4294
        mov     esi, putimage_init16bpp
4295
        jmp     sys_putimage_bpp
842 diamond 4296
@@:
1055 Galkov 4297
        cmp     esi, 24
4298
        jnz     @f
4299
        mov     ebp, putimage_get24bpp
4300
        mov     esi, putimage_init24bpp
4301
        jmp     sys_putimage_bpp
314 diamond 4302
@@:
1055 Galkov 4303
        cmp     esi, 32
4304
        jnz     @f
4305
        mov     ebp, putimage_get32bpp
4306
        mov     esi, putimage_init32bpp
4307
        jmp     sys_putimage_bpp
314 diamond 4308
@@:
1055 Galkov 4309
        pop     ebp esi ebp
4310
        ret
283 diamond 4311
 
911 diamond 4312
put_mono_image:
1055 Galkov 4313
        push    ebp esi ebp
4314
        mov     ebp, putimage_get1bpp
4315
        mov     esi, putimage_init1bpp
4316
        jmp     sys_putimage_bpp
918 diamond 4317
put_2bit_image:
1055 Galkov 4318
        push    ebp esi ebp
4319
        mov     ebp, putimage_get2bpp
4320
        mov     esi, putimage_init2bpp
4321
        jmp     sys_putimage_bpp
911 diamond 4322
put_4bit_image:
1055 Galkov 4323
        push    ebp esi ebp
4324
        mov     ebp, putimage_get4bpp
4325
        mov     esi, putimage_init4bpp
4326
        jmp     sys_putimage_bpp
911 diamond 4327
 
283 diamond 4328
putimage_init24bpp:
1055 Galkov 4329
        lea     eax, [eax*3]
283 diamond 4330
putimage_init8bpp:
1055 Galkov 4331
        ret
283 diamond 4332
 
911 diamond 4333
align 16
283 diamond 4334
putimage_get24bpp:
1055 Galkov 4335
        movzx   eax, byte [esi+2]
4336
        shl     eax, 16
4337
        mov     ax, [esi]
4338
        add     esi, 3
4339
        ret     4
911 diamond 4340
align 16
283 diamond 4341
putimage_get8bpp:
1055 Galkov 4342
        movzx   eax, byte [esi]
4343
        push    edx
4344
        mov     edx, [esp+8]
4345
        mov     eax, [edx+eax*4]
4346
        pop     edx
4347
        inc     esi
4348
        ret     4
283 diamond 4349
 
911 diamond 4350
putimage_init1bpp:
1055 Galkov 4351
        add     eax, ecx
4352
        push    ecx
4353
        add     eax, 7
4354
        add     ecx, 7
4355
        shr     eax, 3
4356
        shr     ecx, 3
4357
        sub     eax, ecx
4358
        pop     ecx
4359
        ret
911 diamond 4360
align 16
4361
putimage_get1bpp:
1055 Galkov 4362
        push    edx
4363
        mov     edx, [esp+8]
4364
        mov     al, [edx]
4365
        add     al, al
4366
        jnz     @f
4367
        lodsb
4368
        adc     al, al
911 diamond 4369
@@:
1055 Galkov 4370
        mov     [edx], al
4371
        sbb     eax, eax
4372
        and     eax, [edx+8]
4373
        add     eax, [edx+4]
4374
        pop     edx
4375
        ret     4
911 diamond 4376
 
918 diamond 4377
putimage_init2bpp:
1055 Galkov 4378
        add     eax, ecx
4379
        push    ecx
4380
        add     ecx, 3
4381
        add     eax, 3
4382
        shr     ecx, 2
4383
        shr     eax, 2
4384
        sub     eax, ecx
4385
        pop     ecx
4386
        ret
918 diamond 4387
align 16
4388
putimage_get2bpp:
1055 Galkov 4389
        push    edx
4390
        mov     edx, [esp+8]
4391
        mov     al, [edx]
4392
        mov     ah, al
4393
        shr     al, 6
4394
        shl     ah, 2
4395
        jnz     .nonewbyte
4396
        lodsb
4397
        mov     ah, al
4398
        shr     al, 6
4399
        shl     ah, 2
4400
        add     ah, 1
918 diamond 4401
.nonewbyte:
1055 Galkov 4402
        mov     [edx], ah
4403
        mov     edx, [edx+4]
4404
        movzx   eax, al
4405
        mov     eax, [edx+eax*4]
4406
        pop     edx
4407
        ret     4
918 diamond 4408
 
911 diamond 4409
putimage_init4bpp:
1055 Galkov 4410
        add     eax, ecx
4411
        push    ecx
4412
        add     ecx, 1
4413
        add     eax, 1
4414
        shr     ecx, 1
4415
        shr     eax, 1
4416
        sub     eax, ecx
4417
        pop     ecx
4418
        ret
911 diamond 4419
align 16
4420
putimage_get4bpp:
1055 Galkov 4421
        push    edx
4422
        mov     edx, [esp+8]
4423
        add     byte [edx], 80h
4424
        jc      @f
4425
        movzx   eax, byte [edx+1]
4426
        mov     edx, [edx+4]
4427
        and     eax, 0x0F
4428
        mov     eax, [edx+eax*4]
4429
        pop     edx
4430
        ret     4
911 diamond 4431
@@:
1055 Galkov 4432
        movzx   eax, byte [esi]
4433
        add     esi, 1
4434
        mov     [edx+1], al
4435
        shr     eax, 4
4436
        mov     edx, [edx+4]
4437
        mov     eax, [edx+eax*4]
4438
        pop     edx
4439
        ret     4
911 diamond 4440
 
314 diamond 4441
putimage_init32bpp:
1055 Galkov 4442
        shl     eax, 2
4443
        ret
911 diamond 4444
align 16
314 diamond 4445
putimage_get32bpp:
1055 Galkov 4446
        lodsd
4447
        ret     4
314 diamond 4448
 
906 diamond 4449
putimage_init15bpp:
911 diamond 4450
putimage_init16bpp:
1055 Galkov 4451
        add     eax, eax
4452
        ret
911 diamond 4453
align 16
906 diamond 4454
putimage_get15bpp:
842 diamond 4455
; 0RRRRRGGGGGBBBBB -> 00000000RRRRR000GGGGG000BBBBB000
1055 Galkov 4456
        push    ecx edx
4457
        movzx   eax, word [esi]
4458
        add     esi, 2
4459
        mov     ecx, eax
4460
        mov     edx, eax
4461
        and     eax, 0x1F
4462
        and     ecx, 0x1F shl 5
4463
        and     edx, 0x1F shl 10
4464
        shl     eax, 3
4465
        shl     ecx, 6
4466
        shl     edx, 9
4467
        or      eax, ecx
4468
        or      eax, edx
4469
        pop     edx ecx
4470
        ret     4
906 diamond 4471
 
911 diamond 4472
align 16
906 diamond 4473
putimage_get16bpp:
4474
; RRRRRGGGGGGBBBBB -> 00000000RRRRR000GGGGGG00BBBBB000
1055 Galkov 4475
        push    ecx edx
4476
        movzx   eax, word [esi]
4477
        add     esi, 2
4478
        mov     ecx, eax
4479
        mov     edx, eax
4480
        and     eax, 0x1F
4481
        and     ecx, 0x3F shl 5
4482
        and     edx, 0x1F shl 11
4483
        shl     eax, 3
4484
        shl     ecx, 5
4485
        shl     edx, 8
4486
        or      eax, ecx
4487
        or      eax, edx
4488
        pop     edx ecx
4489
        ret     4
842 diamond 4490
 
1 ha 4491
; eax x beginning
4492
; ebx y beginning
4493
; ecx x end
1055 Galkov 4494
        ; edx y end
1 ha 4495
; edi color
4496
 
4497
__sys_drawbar:
1055 Galkov 4498
        mov     esi,[current_slot]
4499
        add     eax,[esi+APPDATA.wnd_clientbox.left]
4500
        add     ecx,[esi+APPDATA.wnd_clientbox.left]
4501
        add     ebx,[esi+APPDATA.wnd_clientbox.top]
4502
        add     edx,[esi+APPDATA.wnd_clientbox.top]
114 mikedld 4503
  .forced:
33 mario79 4504
    inc   [mouse_pause]
283 diamond 4505
;        call    [disable_mouse]
381 serge 4506
    cmp   [SCR_MODE],word 0x12
1055 Galkov 4507
    je   dbv20
1 ha 4508
   sdbv20:
381 serge 4509
    cmp  [SCR_MODE],word 0100000000000000b
1 ha 4510
    jge  dbv20
381 serge 4511
    cmp  [SCR_MODE],word 0x13
1055 Galkov 4512
    je   dbv20
1 ha 4513
    call vesa12_drawbar
33 mario79 4514
    dec   [mouse_pause]
36 mario79 4515
    call   [draw_pointer]
1 ha 4516
    ret
4517
  dbv20:
4518
    call vesa20_drawbar
33 mario79 4519
    dec   [mouse_pause]
36 mario79 4520
    call   [draw_pointer]
1 ha 4521
    ret
4522
 
4523
 
4524
 
4525
kb_read:
4526
 
1055 Galkov 4527
        push    ecx edx
1 ha 4528
 
1055 Galkov 4529
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4530
      kr_loop:
1055 Galkov 4531
        in      al,0x64
4532
        test    al,1
4533
        jnz     kr_ready
4534
        loop    kr_loop
4535
        mov     ah,1
4536
        jmp     kr_exit
1 ha 4537
      kr_ready:
1055 Galkov 4538
        push    ecx
4539
        mov     ecx,32
1 ha 4540
      kr_delay:
1055 Galkov 4541
        loop    kr_delay
4542
        pop     ecx
4543
        in      al,0x60
4544
        xor     ah,ah
1 ha 4545
      kr_exit:
4546
 
1055 Galkov 4547
        pop     edx ecx
1 ha 4548
 
1055 Galkov 4549
        ret
1 ha 4550
 
4551
 
4552
kb_write:
4553
 
1055 Galkov 4554
        push    ecx edx
1 ha 4555
 
1055 Galkov 4556
        mov     dl,al
265 diamond 4557
;        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4558
;      kw_loop1:
4559
;        in      al,0x64
4560
;        test    al,0x20
4561
;        jz      kw_ok1
4562
;        loop    kw_loop1
4563
;        mov     ah,1
4564
;        jmp     kw_exit
4565
;      kw_ok1:
1055 Galkov 4566
        in      al,0x60
4567
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4568
      kw_loop:
1055 Galkov 4569
        in      al,0x64
4570
        test    al,2
4571
        jz      kw_ok
4572
        loop    kw_loop
4573
        mov     ah,1
4574
        jmp     kw_exit
1 ha 4575
      kw_ok:
1055 Galkov 4576
        mov     al,dl
4577
        out     0x60,al
4578
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4579
      kw_loop3:
1055 Galkov 4580
        in      al,0x64
4581
        test    al,2
4582
        jz      kw_ok3
4583
        loop    kw_loop3
4584
        mov     ah,1
4585
        jmp     kw_exit
1 ha 4586
      kw_ok3:
1055 Galkov 4587
        mov     ah,8
1 ha 4588
      kw_loop4:
1055 Galkov 4589
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4590
      kw_loop5:
1055 Galkov 4591
        in      al,0x64
4592
        test    al,1
4593
        jnz     kw_ok4
4594
        loop    kw_loop5
4595
        dec     ah
4596
        jnz     kw_loop4
1 ha 4597
      kw_ok4:
1055 Galkov 4598
        xor     ah,ah
1 ha 4599
      kw_exit:
4600
 
1055 Galkov 4601
        pop     edx ecx
1 ha 4602
 
1055 Galkov 4603
        ret
1 ha 4604
 
4605
 
4606
kb_cmd:
4607
 
1055 Galkov 4608
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4609
      c_wait:
1055 Galkov 4610
        in      al,0x64
4611
        test    al,2
4612
        jz      c_send
4613
        loop    c_wait
4614
        jmp     c_error
1 ha 4615
      c_send:
1055 Galkov 4616
        mov     al,bl
4617
        out     0x64,al
4618
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4619
      c_accept:
1055 Galkov 4620
        in      al,0x64
4621
        test    al,2
4622
        jz      c_ok
4623
        loop    c_accept
1 ha 4624
      c_error:
1055 Galkov 4625
        mov     ah,1
4626
        jmp     c_exit
1 ha 4627
      c_ok:
1055 Galkov 4628
        xor     ah,ah
1 ha 4629
      c_exit:
1055 Galkov 4630
        ret
1 ha 4631
 
4632
 
4633
setmouse:  ; set mousepicture -pointer
1055 Galkov 4634
           ; ps2 mouse enable
1 ha 4635
 
381 serge 4636
     mov     [MOUSE_PICTURE],dword mousepointer
1 ha 4637
 
4638
     cli
4639
 
4640
     ret
4641
 
1055 Galkov 4642
if used _rdtsc
1 ha 4643
_rdtsc:
164 serge 4644
     bt [cpu_caps], CAPS_TSC
4645
     jnc ret_rdtsc
1 ha 4646
     rdtsc
4647
     ret
4648
   ret_rdtsc:
4649
     mov   edx,0xffffffff
4650
     mov   eax,0xffffffff
4651
     ret
1055 Galkov 4652
end if
1 ha 4653
 
4654
rerouteirqs:
4655
 
1055 Galkov 4656
        cli
1 ha 4657
 
1055 Galkov 4658
        mov     al,0x11         ;  icw4, edge triggered
4659
        out     0x20,al
4660
        call    pic_delay
4661
        out     0xA0,al
4662
        call    pic_delay
1 ha 4663
 
1055 Galkov 4664
        mov     al,0x20         ;  generate 0x20 +
4665
        out     0x21,al
4666
        call    pic_delay
4667
        mov     al,0x28         ;  generate 0x28 +
4668
        out     0xA1,al
4669
        call    pic_delay
1 ha 4670
 
1055 Galkov 4671
        mov     al,0x04         ;  slave at irq2
4672
        out     0x21,al
4673
        call    pic_delay
4674
        mov     al,0x02         ;  at irq9
4675
        out     0xA1,al
4676
        call    pic_delay
1 ha 4677
 
1055 Galkov 4678
        mov     al,0x01         ;  8086 mode
4679
        out     0x21,al
4680
        call    pic_delay
4681
        out     0xA1,al
4682
        call    pic_delay
1 ha 4683
 
1055 Galkov 4684
        mov     al,255          ; mask all irq's
4685
        out     0xA1,al
4686
        call    pic_delay
4687
        out     0x21,al
4688
        call    pic_delay
1 ha 4689
 
1055 Galkov 4690
        mov     ecx,0x1000
4691
        cld
4692
picl1:  call    pic_delay
4693
        loop    picl1
1 ha 4694
 
1055 Galkov 4695
        mov     al,255          ; mask all irq's
4696
        out     0xA1,al
4697
        call    pic_delay
4698
        out     0x21,al
4699
        call    pic_delay
1 ha 4700
 
1055 Galkov 4701
        cli
1 ha 4702
 
1055 Galkov 4703
        ret
1 ha 4704
 
4705
 
4706
pic_delay:
4707
 
1055 Galkov 4708
        jmp     pdl1
4709
pdl1:   ret
1 ha 4710
 
4711
 
4712
sys_msg_board_str:
4713
 
4714
     pushad
4715
   @@:
4716
     cmp    [esi],byte 0
4717
     je     @f
4718
     mov    eax,1
4719
     movzx  ebx,byte [esi]
4720
     call   sys_msg_board
4721
     inc    esi
4722
     jmp    @b
4723
   @@:
4724
     popad
4725
     ret
4726
 
709 diamond 4727
sys_msg_board_byte:
4728
; in: al = byte to display
4729
; out: nothing
4730
; destroys: nothing
1055 Galkov 4731
        pushad
4732
        mov     ecx, 2
4733
        shl     eax, 24
4734
        jmp     @f
709 diamond 4735
 
4736
sys_msg_board_word:
4737
; in: ax = word to display
4738
; out: nothing
4739
; destroys: nothing
1055 Galkov 4740
        pushad
4741
        mov     ecx, 4
4742
        shl     eax, 16
4743
        jmp     @f
709 diamond 4744
 
4745
sys_msg_board_dword:
4746
; in: eax = dword to display
4747
; out: nothing
4748
; destroys: nothing
1055 Galkov 4749
        pushad
4750
        mov     ecx, 8
709 diamond 4751
@@:
1055 Galkov 4752
        push    ecx
4753
        rol     eax, 4
4754
        push    eax
4755
        and     al, 0xF
4756
        cmp     al, 10
4757
        sbb     al, 69h
4758
        das
4759
        mov     bl, al
4760
        xor     eax, eax
4761
        inc     eax
4762
        call    sys_msg_board
4763
        pop     eax
4764
        pop     ecx
4765
        loop    @b
4766
        popad
4767
        ret
709 diamond 4768
 
1 ha 4769
uglobal
373 mikedld 4770
  msg_board_data: times 4096 db 0
1 ha 4771
  msg_board_count dd 0x0
4772
endg
4773
 
4774
sys_msg_board:
4775
 
4776
; eax=1 : write :  bl byte to write
4777
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4778
 
1055 Galkov 4779
        mov     ecx, [msg_board_count]
4780
        cmp     eax, 1
4781
        jne     .smbl1
1 ha 4782
 
1043 hidnplayr 4783
if defined debug_com_base
1 ha 4784
 
1055 Galkov 4785
        push    dx ax
1043 hidnplayr 4786
 
1055 Galkov 4787
       @@:                              ; Wait for empty transmit register  (yes, this slows down system..)
4788
        mov     dx, debug_com_base+5
4789
        in      al, dx
4790
        test    al, 1 shl 5
4791
        jz      @r
1043 hidnplayr 4792
 
1055 Galkov 4793
        mov     dx, debug_com_base      ; Output the byte
4794
        mov     al, bl
4795
        out     dx, al
1043 hidnplayr 4796
 
1055 Galkov 4797
        pop     ax dx
1043 hidnplayr 4798
 
4799
end if
4800
 
1055 Galkov 4801
        mov     [msg_board_data+ecx],bl
4802
        inc     ecx
4803
        and     ecx, 4095
4804
        mov     [msg_board_count], ecx
4805
        mov     [check_idle_semaphore], 5
4806
        ret
671 Ghost 4807
.smbl1:
1055 Galkov 4808
        cmp     eax, 2
4809
        jne     .smbl2
4810
        test    ecx, ecx
4811
        jz      .smbl21
4812
        mov     eax, msg_board_data+1
4813
        mov     ebx, msg_board_data
4814
        movzx   edx, byte [ebx]
4815
        call    memmove
4816
        dec     [msg_board_count]
4817
        mov     [esp + 36], edx ;eax
4818
        mov     [esp + 24], dword 1
4819
        ret
671 Ghost 4820
.smbl21:
1055 Galkov 4821
        mov     [esp+36], ecx
4822
        mov     [esp+24], ecx
671 Ghost 4823
.smbl2:
1055 Galkov 4824
        ret
1 ha 4825
 
4826
 
4827
 
4828
sys_process_def:
1055 Galkov 4829
        mov     edi, [CURRENT_TASK]
1 ha 4830
 
1055 Galkov 4831
        dec     eax             ; 1 = set keyboard mode
1 ha 4832
     jne   no_set_keyboard_setup
4833
 
4834
     shl   edi,8
380 serge 4835
     mov   [edi+SLOT_BASE + APPDATA.keyboard_mode],bl
1 ha 4836
 
4837
     ret
4838
 
4839
   no_set_keyboard_setup:
4840
 
1055 Galkov 4841
        dec     eax             ; 2 = get keyboard mode
1 ha 4842
     jne   no_get_keyboard_setup
4843
 
4844
     shl   edi,8
380 serge 4845
     movzx eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
1 ha 4846
 
4847
     mov   [esp+36],eax
4848
 
4849
     ret
4850
 
4851
   no_get_keyboard_setup:
4852
 
1055 Galkov 4853
        dec     eax             ; 3 = get keyboard ctrl, alt, shift
1 ha 4854
     jne   no_get_keyboard_cas
4855
 
4856
;     xor   eax,eax
4857
;     movzx eax,byte [shift]
4858
;     movzx ebx,byte [ctrl]
4859
;     shl   ebx,2
4860
;     add   eax,ebx
4861
;     movzx ebx,byte [alt]
4862
;     shl   ebx,3
4863
;     add   eax,ebx
4864
 
4865
 ;// mike.dld [
4866
     mov   eax, [kb_state]
4867
 ;// mike.dld ]
4868
 
4869
     mov   [esp+36],eax
4870
 
4871
     ret
4872
 
4873
   no_get_keyboard_cas:
4874
 
1055 Galkov 4875
        dec     eax
4876
        jnz     no_add_keyboard_hotkey
1 ha 4877
 
1055 Galkov 4878
        mov     eax, hotkey_list
92 diamond 4879
@@:
1055 Galkov 4880
        cmp     dword [eax+8], 0
4881
        jz      .found_free
4882
        add     eax, 16
4883
        cmp     eax, hotkey_list+16*256
4884
        jb      @b
4885
        mov     dword [esp+36], 1
4886
        ret
92 diamond 4887
.found_free:
1055 Galkov 4888
        mov     [eax+8], edi
4889
        mov     [eax+4], ecx
4890
        movzx   ebx, bl
4891
        lea     ebx, [hotkey_scancodes+ebx*4]
4892
        mov     ecx, [ebx]
4893
        mov     [eax], ecx
4894
        mov     [ebx], eax
4895
        mov     [eax+12], ebx
4896
        jecxz   @f
4897
        mov     [ecx+12], eax
92 diamond 4898
@@:
1055 Galkov 4899
        and     dword [esp+36], 0
4900
        ret
92 diamond 4901
 
4902
no_add_keyboard_hotkey:
4903
 
1055 Galkov 4904
        dec     eax
4905
        jnz     no_del_keyboard_hotkey
92 diamond 4906
 
1055 Galkov 4907
        movzx   ebx, bl
4908
        lea     ebx, [hotkey_scancodes+ebx*4]
4909
        mov     eax, [ebx]
92 diamond 4910
.scan:
1055 Galkov 4911
        test    eax, eax
4912
        jz      .notfound
4913
        cmp     [eax+8], edi
4914
        jnz     .next
4915
        cmp     [eax+4], ecx
4916
        jz      .found
92 diamond 4917
.next:
1055 Galkov 4918
        mov     eax, [eax]
4919
        jmp     .scan
92 diamond 4920
.notfound:
1055 Galkov 4921
        mov     dword [esp+36], 1
4922
        ret
92 diamond 4923
.found:
1055 Galkov 4924
        mov     ecx, [eax]
4925
        jecxz   @f
4926
        mov     edx, [eax+12]
4927
        mov     [ecx+12], edx
92 diamond 4928
@@:
1055 Galkov 4929
        mov     ecx, [eax+12]
4930
        mov     edx, [eax]
4931
        mov     [ecx], edx
4932
        xor     edx, edx
4933
        mov     [eax+4], edx
4934
        mov     [eax+8], edx
4935
        mov     [eax+12], edx
4936
        mov     [eax], edx
4937
        mov     [esp+36], edx
4938
        ret
92 diamond 4939
 
4940
no_del_keyboard_hotkey:
1 ha 4941
     ret
4942
 
4943
 
4944
align 4
4945
 
1055 Galkov 4946
sys_gs:                         ; direct screen access
1 ha 4947
 
1055 Galkov 4948
     cmp  eax,1                 ; resolution
1 ha 4949
     jne  no_gs1
753 serge 4950
     mov  eax,[Screen_Max_X]
1 ha 4951
     shl  eax,16
753 serge 4952
     mov  ax,[Screen_Max_Y]
1 ha 4953
     add  eax,0x00010001
4954
     mov  [esp+36],eax
4955
     ret
4956
   no_gs1:
4957
 
1055 Galkov 4958
     cmp   eax,2                ; bits per pixel
1 ha 4959
     jne   no_gs2
381 serge 4960
     movzx eax,byte [ScreenBPP]
1 ha 4961
     mov   [esp+36],eax
4962
     ret
4963
   no_gs2:
4964
 
1055 Galkov 4965
     cmp   eax,3                ; bytes per scanline
1 ha 4966
     jne   no_gs3
381 serge 4967
     mov   eax,[BytesPerScanLine]
1 ha 4968
     mov   [esp+36],eax
4969
     ret
4970
   no_gs3:
4971
 
4972
     mov  [esp+36],dword -1
4973
     ret
4974
 
4975
 
4976
align 4 ; PCI functions
4977
 
4978
sys_pci:
4979
 
4980
     call  pci_api
4981
     mov   [esp+36],eax
4982
     ret
4983
 
4984
 
4985
align 4  ;  system functions
4986
 
1055 Galkov 4987
syscall_setpixel:                       ; SetPixel
1 ha 4988
 
1055 Galkov 4989
        mov     eax, ebx
4990
        mov     ebx, ecx
4991
        mov     ecx, edx
4992
        mov     edx, [TASK_BASE]
4993
        add     eax, [edx-twdw+WDATA.box.left]
4994
        add     ebx, [edx-twdw+WDATA.box.top]
4995
        mov     edi, [current_slot]
4996
        add     eax, [edi+APPDATA.wnd_clientbox.left]
4997
        add     ebx, [edi+APPDATA.wnd_clientbox.top]
4998
        xor     edi, edi ; no force
684 diamond 4999
;       mov     edi, 1
1055 Galkov 5000
        call    [disable_mouse]
5001
        jmp     [putpixel]
1 ha 5002
 
5003
align 4
5004
 
1055 Galkov 5005
syscall_writetext:                      ; WriteText
1 ha 5006
 
1055 Galkov 5007
        mov   eax,[TASK_BASE]
5008
        mov   ebp,[eax-twdw+WDATA.box.left]
5009
        push  esi
5010
        mov   esi,[current_slot]
5011
        add   ebp,[esi+APPDATA.wnd_clientbox.left]
5012
        shl   ebp,16
5013
        add   ebp,[eax-twdw+WDATA.box.top]
5014
        add   bp,word[esi+APPDATA.wnd_clientbox.top]
5015
        pop   esi
5016
        add   ebx,ebp
5017
        mov   eax,edi
5018
        xor   edi,edi
5019
        jmp   dtext
1 ha 5020
 
5021
align 4
5022
 
1055 Galkov 5023
syscall_openramdiskfile:                ; OpenRamdiskFile
1 ha 5024
 
1055 Galkov 5025
        mov     eax, ebx
5026
        mov     ebx, ecx
5027
        mov     ecx, edx
5028
        mov     edx, esi
5029
        mov     esi, 12
5030
        call    fileread
5031
        mov     [esp+32], eax
5032
        ret
1 ha 5033
 
5034
align 4
5035
 
1055 Galkov 5036
syscall_drawrect:                       ; DrawRect
1 ha 5037
 
1055 Galkov 5038
        mov     edi, edx ; color + gradient
5039
        and     edi, 0x80FFFFFF
5040
        test    bx, bx  ; x.size
5041
        je      .drectr
5042
        test    cx, cx ; y.size
5043
        je      .drectr
1 ha 5044
 
1055 Galkov 5045
        mov     eax, ebx ; bad idea
5046
        mov     ebx, ecx
1 ha 5047
 
1055 Galkov 5048
        movzx   ecx, ax ; ecx - x.size
5049
        shr     eax, 16 ; eax - x.coord
5050
        movzx   edx, bx ; edx - y.size
5051
        shr     ebx, 16 ; ebx - y.coord
5052
        mov     esi, [current_slot]
1 ha 5053
 
1055 Galkov 5054
        add     eax, [esi + APPDATA.wnd_clientbox.left]
5055
        add     ebx, [esi + APPDATA.wnd_clientbox.top]
5056
        add     ecx, eax
5057
        add     edx, ebx
5058
        jmp     [drawbar]
671 Ghost 5059
.drectr:
1055 Galkov 5060
        ret
1 ha 5061
 
5062
align 4
1055 Galkov 5063
syscall_getscreensize:                  ; GetScreenSize
5064
        mov     ax, [Screen_Max_X]
5065
        shl     eax, 16
5066
        mov     ax, [Screen_Max_Y]
5067
        mov     [esp + 32], eax
5068
        ret
1 ha 5069
 
671 Ghost 5070
align 4
5071
 
1055 Galkov 5072
syscall_cdaudio:                        ; CD
1 ha 5073
 
1055 Galkov 5074
        cmp     eax, 4
5075
        jb      .audio
5076
        jz      .eject
5077
        cmp     eax, 5
5078
        jnz     .ret
588 diamond 5079
.load:
1055 Galkov 5080
        call    .reserve
5081
        call    LoadMedium
5082
        call    .free
5083
        ret
588 diamond 5084
.eject:
1055 Galkov 5085
        call    .reserve
5086
        call    clear_CD_cache
5087
        call    allow_medium_removal
5088
        call    EjectMedium
5089
        call    .free
5090
        ret
588 diamond 5091
.audio:
1 ha 5092
     call  sys_cd_audio
5093
     mov   [esp+36],eax
588 diamond 5094
.ret:
1 ha 5095
     ret
5096
 
588 diamond 5097
.reserve:
1055 Galkov 5098
        call    reserve_cd
5099
        mov     eax, ebx
5100
        shr     eax, 1
5101
        and     eax, 1
5102
        inc     eax
5103
        mov     [ChannelNumber], ax
5104
        mov     eax, ebx
5105
        and     eax, 1
5106
        mov     [DiskNumber], al
5107
        call    reserve_cd_channel
5108
        and     ebx, 3
5109
        inc     ebx
5110
        mov     [cdpos], ebx
5111
        add     ebx, ebx
5112
        mov     cl, 8
5113
        sub     cl, bl
5114
        mov     al, [DRIVE_DATA+1]
5115
        shr     al, cl
5116
        test    al, 2
5117
        jz      .err
5118
        ret
588 diamond 5119
.free:
1055 Galkov 5120
        call    free_cd_channel
5121
        and     [cd_status], 0
5122
        ret
590 diamond 5123
.err:
1055 Galkov 5124
        call    .free
5125
        pop     eax
5126
        ret
588 diamond 5127
 
1 ha 5128
align 4
5129
 
1055 Galkov 5130
syscall_getpixel:                       ; GetPixel
753 serge 5131
     mov   ecx, [Screen_Max_X]
1 ha 5132
     inc   ecx
671 Ghost 5133
     xor   edx, edx
5134
     mov   eax, ebx
1 ha 5135
     div   ecx
671 Ghost 5136
     mov   ebx, edx
5137
     xchg  eax, ebx
5138
     call  dword [GETPIXEL] ; eax - x, ebx - y
5139
     mov   [esp + 32], ecx
1 ha 5140
     ret
5141
 
921 mario79 5142
align 4
1 ha 5143
 
921 mario79 5144
syscall_getarea:
5145
;eax = 36
1055 Galkov 5146
;ebx = pointer to bufer for img BBGGRRBBGGRR...
5147
;ecx = [size x]*65536 + [size y]
5148
;edx = [start x]*65536 + [start y]
921 mario79 5149
     pushad
1055 Galkov 5150
         inc   [mouse_pause]
927 mario79 5151
; Check of use of the hardware cursor.
5152
      cmp  [disable_mouse],__sys_disable_mouse
1055 Galkov 5153
          jne  @f
927 mario79 5154
; Since the test for the coordinates of the mouse should not be used,
5155
; then use the call [disable_mouse] is not possible!
5156
      cmp  dword [MOUSE_VISIBLE],dword 0
5157
      jne  @f
5158
      pushf
5159
      cli
5160
      call draw_mouse_under
5161
      popf
5162
      mov  [MOUSE_VISIBLE],dword 1
5163
@@:
921 mario79 5164
     mov   edi,ebx
5165
     mov   eax,edx
5166
     shr   eax,16
5167
     mov   ebx,edx
5168
     and   ebx,0xffff
939 mario79 5169
     dec   eax
1055 Galkov 5170
           dec   ebx
921 mario79 5171
     ; eax - x, ebx - y
5172
     mov   edx,ecx
5173
 
5174
     shr   ecx,16
5175
     and   edx,0xffff
5176
     mov   esi,ecx
5177
     ; ecx - size x, edx - size y
1055 Galkov 5178
 
5179
         mov   ebp,edx
5180
         dec   ebp
927 mario79 5181
     lea   ebp,[ebp*3]
1055 Galkov 5182
 
5183
         imul  ebp,esi
5184
 
5185
         mov   esi,ecx
5186
         dec   esi
5187
         lea   esi,[esi*3]
5188
 
927 mario79 5189
     add   ebp,esi
5190
     add   ebp,edi
5191
 
5192
     add   ebx,edx
1055 Galkov 5193
 
921 mario79 5194
.start_y:
927 mario79 5195
     push  ecx edx
921 mario79 5196
.start_x:
927 mario79 5197
     push  eax ebx ecx
921 mario79 5198
     add   eax,ecx
927 mario79 5199
 
921 mario79 5200
     call  dword [GETPIXEL] ; eax - x, ebx - y
5201
 
927 mario79 5202
     mov   [ebp],cx
5203
     shr   ecx,16
5204
     mov   [ebp+2],cl
921 mario79 5205
 
1055 Galkov 5206
     pop   ecx ebx eax
927 mario79 5207
     sub   ebp,3
921 mario79 5208
     dec   ecx
5209
     jnz   .start_x
1055 Galkov 5210
         pop   edx ecx
5211
         dec   ebx
921 mario79 5212
     dec   edx
5213
     jnz   .start_y
1055 Galkov 5214
     dec        [mouse_pause]
927 mario79 5215
; Check of use of the hardware cursor.
5216
      cmp  [disable_mouse],__sys_disable_mouse
1055 Galkov 5217
          jne  @f
5218
         call  [draw_pointer]
927 mario79 5219
@@:
921 mario79 5220
     popad
5221
     ret
5222
 
1 ha 5223
align 4
5224
 
1055 Galkov 5225
syscall_drawline:                       ; DrawLine
1 ha 5226
 
1055 Galkov 5227
        mov     edi, [TASK_BASE]
5228
        movzx   eax, word[edi-twdw+WDATA.box.left]
5229
        mov     ebp, eax
5230
        mov     esi, [current_slot]
5231
        add     ebp, [esi+APPDATA.wnd_clientbox.left]
5232
        add     ax, word[esi+APPDATA.wnd_clientbox.left]
5233
        add     ebp,ebx
5234
        shl     eax, 16
5235
        movzx   ebx, word[edi-twdw+WDATA.box.top]
5236
        add     eax, ebp
5237
        mov     ebp, ebx
5238
        add     ebp, [esi+APPDATA.wnd_clientbox.top]
5239
        add     bx, word[esi+APPDATA.wnd_clientbox.top]
5240
        add     ebp, ecx
5241
        shl     ebx, 16
5242
        xor     edi, edi
5243
        add     ebx, ebp
5244
        mov     ecx, edx
5245
        jmp     [draw_line]
1 ha 5246
 
5247
align 4
5248
 
1055 Galkov 5249
syscall_getirqowner:                    ; GetIrqOwner
742 Rus 5250
 
5251
     cmp   ebx,16
75 diamond 5252
     jae   .err
742 Rus 5253
 
774 Rus 5254
     cmp   [irq_rights + 4 * ebx], dword 2
5255
     je    .err
5256
 
742 Rus 5257
     mov   eax,[4 * ebx + irq_owner]
5258
     mov   [esp+32],eax
5259
 
1 ha 5260
     ret
75 diamond 5261
.err:
742 Rus 5262
     or    dword [esp+32], -1
75 diamond 5263
     ret
1 ha 5264
 
5265
align 4
5266
 
1055 Galkov 5267
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
1 ha 5268
 
5269
     call  r_f_port_area
5270
     mov   [esp+36],eax
5271
     ret
5272
 
5273
align 4
5274
 
1055 Galkov 5275
syscall_threads:                        ; CreateThreads
1 ha 5276
 
5277
     call  sys_threads
5278
     mov   [esp+36],eax
5279
     ret
5280
 
5281
align 4
5282
 
5283
stack_driver_stat:
5284
 
1055 Galkov 5285
     call  app_stack_handler            ; Stack status
1 ha 5286
 
5287
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5288
;     call  change_task                 ; between sent packet
5289
 
5290
     mov   [esp+36],eax
5291
     ret
5292
 
5293
align 4
5294
 
1055 Galkov 5295
socket:                                 ; Socket interface
1 ha 5296
     call  app_socket_handler
5297
 
5298
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5299
;     call  change_task                 ; between sent packet
5300
 
5301
     mov   [esp+36],eax
5302
     mov   [esp+24],ebx
5303
     ret
5304
 
5305
align 4
5306
 
1055 Galkov 5307
read_from_hd:                           ; Read from hd - fn not in use
1 ha 5308
 
379 serge 5309
     mov   edi,[TASK_BASE]
115 poddubny 5310
     add   edi,TASKDATA.mem_start
1 ha 5311
     add   eax,[edi]
5312
     add   ecx,[edi]
5313
     add   edx,[edi]
5314
     call  file_read
5315
 
5316
     mov   [esp+36],eax
5317
     mov   [esp+24],ebx
5318
 
5319
     ret
5320
 
375 Ghost 5321
paleholder:
1055 Galkov 5322
        ret
378 serge 5323
 
757 serge 5324
align 4
5325
set_screen:
1055 Galkov 5326
        cmp eax, [Screen_Max_X]
5327
        jne .set
709 diamond 5328
 
1055 Galkov 5329
        cmp edx, [Screen_Max_Y]
5330
        jne .set
5331
        ret
757 serge 5332
.set:
1055 Galkov 5333
        pushfd
5334
        cli
757 serge 5335
 
1055 Galkov 5336
        mov [Screen_Max_X], eax
5337
        mov [Screen_Max_Y], edx
757 serge 5338
 
1055 Galkov 5339
        mov [screen_workarea.right],eax
5340
        mov [screen_workarea.bottom], edx
5341
        inc eax
5342
        shl eax, 2                      ;32 bpp
5343
        mov [BytesPerScanLine], eax
5344
        push ebx
5345
        push esi
5346
        push edi
5347
        call    repos_windows
5348
        mov     eax, 0
5349
        mov     ebx, 0
5350
        mov     ecx, [Screen_Max_X]
5351
        mov     edx, [Screen_Max_Y]
5352
        call    calculatescreen
5353
        pop edi
5354
        pop esi
5355
        pop ebx
757 serge 5356
 
1055 Galkov 5357
        popfd
5358
        ret
757 serge 5359
 
76 mario79 5360
; --------------- APM ---------------------
5361
apm_entry    dp    0
1055 Galkov 5362
apm_vf        dd    0
1 ha 5363
align 4
76 mario79 5364
sys_apm:
5365
    cmp    word [apm_vf], 0    ; Check APM BIOS enable
5366
    jne    @f
1055 Galkov 5367
    or    [esp + 56], byte 1    ; error
5368
    mov    [esp + 36], dword 8    ; 32-bit protected-mode interface not supported
76 mario79 5369
    ret
164 serge 5370
 
465 serge 5371
@@:
5372
    xchg    eax, ecx
76 mario79 5373
    xchg    ebx, ecx
164 serge 5374
 
76 mario79 5375
    cmp    al, 3
1055 Galkov 5376
    ja    @f
78 diamond 5377
    and    [esp + 56], byte 0xfe    ; emulate func 0..3 as func 0
76 mario79 5378
    mov    eax, [apm_vf]
5379
    mov    [esp + 36], eax
5380
    shr    eax, 16
5381
    mov    [esp + 32], eax
5382
    ret
78 diamond 5383
 
465 serge 5384
@@:
5385
 
5386
    mov esi, [master_tab+(OS_BASE shr 20)]
5387
    xchg [master_tab], esi
5388
    push esi
5389
    mov edi, cr3
1055 Galkov 5390
    mov cr3, edi                 ;flush TLB
465 serge 5391
 
1055 Galkov 5392
    call    pword [apm_entry]    ; call APM BIOS
465 serge 5393
 
5394
    xchg eax, [esp]
5395
    mov [master_tab], eax
5396
    mov eax, cr3
5397
    mov cr3, eax
5398
    pop eax
5399
 
76 mario79 5400
    mov    [esp + 8 ], edi
5401
    mov    [esp + 12], esi
5402
    mov    [esp + 24], ebx
5403
    mov    [esp + 28], edx
5404
    mov    [esp + 32], ecx
5405
    mov    [esp + 36], eax
5406
    setc    al
78 diamond 5407
    and    [esp + 56], byte 0xfe
1055 Galkov 5408
    or    [esp + 56], al
465 serge 5409
 
5410
 
76 mario79 5411
    ret
5412
; -----------------------------------------
1 ha 5413
 
76 mario79 5414
align 4
5415
 
1055 Galkov 5416
undefined_syscall:                      ; Undefined system call
671 Ghost 5417
     mov   [esp + 32], dword -1
1 ha 5418
     ret
5419
 
465 serge 5420
align 4
1055 Galkov 5421
system_shutdown:          ; shut down the system
1 ha 5422
 
1055 Galkov 5423
           cmp byte [BOOT_VAR+0x9030], 1
5424
           jne @F
5425
           ret
465 serge 5426
@@:
1055 Galkov 5427
           call stop_all_services
5428
           push 3                ; stop playing cd
5429
           pop  eax
5430
           call sys_cd_audio
1 ha 5431
 
465 serge 5432
yes_shutdown_param:
1055 Galkov 5433
           cli
1 ha 5434
 
1055 Galkov 5435
           mov  eax, kernel_file ; load kernel.mnt to 0x7000:0
5436
           push 12
5437
           pop  esi
5438
           xor  ebx,ebx
5439
           or   ecx,-1
5440
           mov  edx, OS_BASE+0x70000
5441
           call fileread
1 ha 5442
 
1055 Galkov 5443
           mov  esi, restart_kernel_4000+OS_BASE+0x10000 ; move kernel re-starter to 0x4000:0
5444
           mov  edi,OS_BASE+0x40000
5445
           mov  ecx,1000
5446
           rep  movsb
1 ha 5447
 
1055 Galkov 5448
           mov  esi,OS_BASE+0x2F0000    ; restore 0x0 - 0xffff
5449
           mov  edi, OS_BASE
5450
           mov  ecx,0x10000/4
5451
           cld
5452
           rep movsd
1 ha 5453
 
1055 Galkov 5454
           call restorefatchain
1 ha 5455
 
1055 Galkov 5456
           mov al, 0xFF
5457
           out 0x21, al
5458
           out 0xA1, al
1 ha 5459
 
709 diamond 5460
if 1
1055 Galkov 5461
           mov  word [OS_BASE+0x467+0],pr_mode_exit
5462
           mov  word [OS_BASE+0x467+2],0x1000
1 ha 5463
 
1055 Galkov 5464
           mov  al,0x0F
5465
           out  0x70,al
5466
           mov  al,0x05
5467
           out  0x71,al
1 ha 5468
 
1055 Galkov 5469
           mov  al,0xFE
5470
           out  0x64,al
709 diamond 5471
 
1055 Galkov 5472
           hlt
1 ha 5473
 
709 diamond 5474
else
1055 Galkov 5475
        cmp     byte [OS_BASE + 0x9030], 2
5476
        jnz     no_acpi_power_off
1 ha 5477
 
709 diamond 5478
; scan for RSDP
5479
; 1) The first 1 Kb of the Extended BIOS Data Area (EBDA).
1055 Galkov 5480
        movzx   eax, word [OS_BASE + 0x40E]
5481
        shl     eax, 4
5482
        jz      @f
5483
        mov     ecx, 1024/16
5484
        call    scan_rsdp
5485
        jnc     .rsdp_found
709 diamond 5486
@@:
5487
; 2) The BIOS read-only memory space between 0E0000h and 0FFFFFh.
1055 Galkov 5488
        mov     eax, 0xE0000
5489
        mov     ecx, 0x2000
5490
        call    scan_rsdp
5491
        jc      no_acpi_power_off
709 diamond 5492
.rsdp_found:
1055 Galkov 5493
        mov     esi, [eax+16]   ; esi contains physical address of the RSDT
5494
        mov     ebp, [ipc_tmp]
5495
        stdcall map_page, ebp, esi, PG_MAP
5496
        lea     eax, [esi+1000h]
5497
        lea     edx, [ebp+1000h]
5498
        stdcall map_page, edx, eax, PG_MAP
5499
        and     esi, 0xFFF
5500
        add     esi, ebp
5501
        cmp     dword [esi], 'RSDT'
5502
        jnz     no_acpi_power_off
5503
        mov     ecx, [esi+4]
5504
        sub     ecx, 24h
5505
        jbe     no_acpi_power_off
5506
        shr     ecx, 2
5507
        add     esi, 24h
709 diamond 5508
.scan_fadt:
1055 Galkov 5509
        lodsd
5510
        mov     ebx, eax
5511
        lea     eax, [ebp+2000h]
5512
        stdcall map_page, eax, ebx, PG_MAP
5513
        lea     eax, [ebp+3000h]
5514
        add     ebx, 0x1000
5515
        stdcall map_page, eax, ebx, PG_MAP
5516
        and     ebx, 0xFFF
5517
        lea     ebx, [ebx+ebp+2000h]
5518
        cmp     dword [ebx], 'FACP'
5519
        jz      .fadt_found
5520
        loop    .scan_fadt
5521
        jmp     no_acpi_power_off
709 diamond 5522
.fadt_found:
5523
; ebx is linear address of FADT
1055 Galkov 5524
        mov     edx, [ebx+48]
5525
        test    edx, edx
5526
        jz      .nosmi
5527
        mov     al, [ebx+52]
5528
        out     dx, al
5529
        mov     edx, [ebx+64]
709 diamond 5530
@@:
1055 Galkov 5531
        in      ax, dx
5532
        test    al, 1
5533
        jz      @b
709 diamond 5534
.nosmi:
1055 Galkov 5535
        mov     edx, [ebx+64]
5536
        in      ax, dx
5537
        and     ax, 203h
5538
        or      ax, 3C00h
5539
        out     dx, ax
5540
        mov     edx, [ebx+68]
5541
        test    edx, edx
5542
        jz      @f
5543
        in      ax, dx
5544
        and     ax, 203h
5545
        or      ax, 3C00h
5546
        out     dx, ax
709 diamond 5547
@@:
1055 Galkov 5548
        jmp     $
709 diamond 5549
 
5550
 
5551
no_acpi_power_off:
1055 Galkov 5552
           mov  word [OS_BASE+0x467+0],pr_mode_exit
5553
           mov  word [OS_BASE+0x467+2],0x1000
709 diamond 5554
 
1055 Galkov 5555
           mov  al,0x0F
5556
           out  0x70,al
5557
           mov  al,0x05
5558
           out  0x71,al
709 diamond 5559
 
1055 Galkov 5560
           mov  al,0xFE
5561
           out  0x64,al
709 diamond 5562
 
1055 Galkov 5563
           hlt
709 diamond 5564
 
5565
scan_rsdp:
1055 Galkov 5566
        add     eax, OS_BASE
709 diamond 5567
.s:
1055 Galkov 5568
        cmp     dword [eax], 'RSD '
5569
        jnz     .n
5570
        cmp     dword [eax+4], 'PTR '
5571
        jnz     .n
5572
        xor     edx, edx
5573
        xor     esi, esi
709 diamond 5574
@@:
1055 Galkov 5575
        add     dl, [eax+esi]
5576
        inc     esi
5577
        cmp     esi, 20
5578
        jnz     @b
5579
        test    dl, dl
5580
        jz      .ok
709 diamond 5581
.n:
1055 Galkov 5582
        add     eax, 10h
5583
        loop    .s
5584
        stc
709 diamond 5585
.ok:
1055 Galkov 5586
        ret
709 diamond 5587
end if
5588
 
465 serge 5589
include "data32.inc"
1 ha 5590
 
465 serge 5591
__REV__ = __REV
1 ha 5592
 
5593
uglobals_size = $ - endofcode
41 mikedld 5594
diff16 "end of kernel code",0,$