Subversion Repositories Kolibri OS

Rev

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