Subversion Repositories Kolibri OS

Rev

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