Subversion Repositories Kolibri OS

Rev

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

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