Subversion Repositories Kolibri OS

Rev

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