Subversion Repositories Kolibri OS

Rev

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