Subversion Repositories Kolibri OS

Rev

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