Subversion Repositories Kolibri OS

Rev

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

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