Subversion Repositories Kolibri OS

Rev

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