Subversion Repositories Kolibri OS

Rev

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