Subversion Repositories Kolibri OS

Rev

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