Subversion Repositories Kolibri OS

Rev

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