Subversion Repositories Kolibri OS

Rev

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

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