Subversion Repositories Kolibri OS

Rev

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