Subversion Repositories Kolibri OS

Rev

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