Subversion Repositories Kolibri OS

Rev

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