Subversion Repositories Kolibri OS

Rev

Rev 1267 | Rev 1272 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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