Subversion Repositories Kolibri OS

Rev

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