Subversion Repositories Kolibri OS

Rev

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