Subversion Repositories Kolibri OS

Rev

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