Subversion Repositories Kolibri OS

Rev

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