Subversion Repositories Kolibri OS

Rev

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