Subversion Repositories Kolibri OS

Rev

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