Subversion Repositories Kolibri OS

Rev

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