Subversion Repositories Kolibri OS

Rev

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

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