Subversion Repositories Kolibri OS

Rev

Rev 566 | Rev 569 | 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: 567 $
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
 
102 poddubny 2966
    ; parameter for drawwindow_IV
35 halyavin 2967
    push  0
379 serge 2968
    mov   edi, [TASK_COUNT]
380 serge 2969
    movzx edi, word [WIN_POS + edi*2]
379 serge 2970
    cmp   edi, [CURRENT_TASK]
33 mario79 2971
    jne   @f
102 poddubny 2972
    inc   dword [esp]
2973
 @@:
33 mario79 2974
 
2975
    inc   [mouse_pause]
36 mario79 2976
    call  [disable_mouse]
1 ha 2977
    call  sys_set_window
36 mario79 2978
    call  [disable_mouse]
2979
    call  drawwindow_IV
114 mikedld 2980
    ;dec   [mouse_pause]
2981
    ;call   [draw_pointer]
2982
    ;ret
2983
    jmp   draw_window_caption.2
549 spraid 2984
  nosyswV:
1 ha 2985
 
2986
    ret
2987
 
2988
 
114 mikedld 2989
draw_window_caption:
429 serge 2990
        inc     [mouse_pause]
2991
        call    [disable_mouse]
114 mikedld 2992
 
429 serge 2993
        xor     eax,eax
2994
        mov     edx,[TASK_COUNT]
2995
        movzx   edx,word[WIN_POS+edx*2]
2996
        cmp     edx,[CURRENT_TASK]
2997
        jne     @f
2998
        inc     eax
2999
    @@: mov     edx,[CURRENT_TASK]
3000
        shl     edx,5
3001
        add     edx,window_data
3002
        movzx   ebx,[edx+WDATA.fl_wstyle]
3003
        and     bl,0x0F
3004
        cmp     bl,3
549 spraid 3005
        je      .draw_caption_style_3		;{for 3 and 4 style write caption}
3006
        cmp     bl,4
3007
        je      .draw_caption_style_3
567 serge 3008
 
549 spraid 3009
        jmp     .not_style_3
3010
  .draw_caption_style_3:
114 mikedld 3011
 
429 serge 3012
        push    edx
3013
        call    drawwindow_IV_caption
3014
        add     esp,4
3015
        jmp     .2
114 mikedld 3016
 
3017
  .not_style_3:
429 serge 3018
        cmp     bl,2
3019
        jne     .not_style_2
114 mikedld 3020
 
429 serge 3021
        call    drawwindow_III_caption
3022
        jmp     .2
114 mikedld 3023
 
3024
  .not_style_2:
429 serge 3025
        cmp     bl,0
3026
        jne     .2
114 mikedld 3027
 
429 serge 3028
        call    drawwindow_I_caption
114 mikedld 3029
 
3030
;--------------------------------------------------------------
429 serge 3031
  .2:   ;jmp     @f
3032
        mov     edi,[CURRENT_TASK]
3033
        shl     edi,5
3034
        test    [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
3035
        jz      @f
3036
        mov     ecx,[edi*8+SLOT_BASE+APPDATA.wnd_caption]
3037
        or      ecx,ecx
3038
        jz      @f
465 serge 3039
        add     ecx,[edi+CURRENT_TASK+TASKDATA.mem_start]
114 mikedld 3040
 
429 serge 3041
        movzx   eax,[edi+window_data+WDATA.fl_wstyle]
3042
        and     al,0x0F
3043
        cmp     al,3
549 spraid 3044
        je      .skinned
3045
        cmp     al,4
3046
        je      .skinned
567 serge 3047
 
549 spraid 3048
        jmp     .not_skinned
567 serge 3049
  .skinned:
429 serge 3050
        mov     ebp,[edi+window_data+WDATA.box.left-2]
3051
        mov     bp,word[edi+window_data+WDATA.box.top]
3052
        movzx   eax,word[edi+window_data+WDATA.box.width]
3053
        sub     ax,[_skinmargins.left]
3054
        sub     ax,[_skinmargins.right]
3055
        cwde
3056
        cdq
3057
        mov     ebx,6
3058
        idiv    ebx
3059
        or      eax,eax
3060
        js      @f
3061
        mov     edx,eax
3062
        mov     eax,dword[_skinmargins.left-2]
3063
        mov     ax,word[_skinh]
3064
        sub     ax,[_skinmargins.bottom]
3065
        sub     ax,[_skinmargins.top]
3066
        sar     ax,1
3067
        adc     ax,0
3068
        add     ax,[_skinmargins.top]
3069
        add     ax,-3
3070
        add     eax,ebp
3071
        jmp     .dodraw
114 mikedld 3072
 
3073
  .not_skinned:
429 serge 3074
        cmp     al,1
3075
        je      @f
114 mikedld 3076
 
429 serge 3077
        mov     ebp,[edi+window_data+WDATA.box.left-2]
3078
        mov     bp,word[edi+window_data+WDATA.box.top]
3079
        movzx   eax,word[edi+window_data+WDATA.box.width]
3080
        sub     eax,16
3081
        cwde
3082
        cdq
3083
        mov     ebx,6
3084
        idiv    ebx
3085
        or      eax,eax
3086
        js      @f
3087
        mov     edx,eax
3088
        mov     eax,0x00080007
3089
        add     eax,ebp
139 diamond 3090
.dodraw:
429 serge 3091
        mov     ebx,[common_colours+16];0x00FFFFFF
3092
        or      ebx, 0x80000000
3093
        xor     edi,edi
3094
        call    dtext
114 mikedld 3095
 
3096
    @@:
3097
;--------------------------------------------------------------
429 serge 3098
        dec     [mouse_pause]
3099
        call    [draw_pointer]
3100
        ret
114 mikedld 3101
 
3102
iglobal
3103
align 4
3104
window_topleft dd \
549 spraid 3105
  1, 21,\		;type 0
3106
  0,  0,\       ;type 1
3107
  5, 20,\       ;type 2
3108
  5,  ?,\       ;type 3 {set by skin}
3109
  5,  ?         ;type 4 {set by skin}
114 mikedld 3110
endg
3111
 
3112
set_window_clientbox:
429 serge 3113
        push    eax ecx edi
114 mikedld 3114
 
429 serge 3115
        mov     eax,[_skinh]
3116
        mov     [window_topleft+4*7],eax
549 spraid 3117
        mov     [window_topleft+4*9],eax
114 mikedld 3118
 
429 serge 3119
        mov     ecx,edi
3120
        sub     edi,window_data
3121
        shl     edi,3
3122
        test    [ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE
3123
        jz      @f
114 mikedld 3124
 
429 serge 3125
        movzx   eax,[ecx+WDATA.fl_wstyle]
3126
        and     eax,0x0F
3127
        mov     eax,[eax*8+window_topleft+0]
3128
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3129
        shl     eax,1
3130
        neg     eax
3131
        add     eax,[ecx+WDATA.box.width]
3132
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
114 mikedld 3133
 
429 serge 3134
        movzx   eax,[ecx+WDATA.fl_wstyle]
3135
        and     eax,0x0F
3136
        push    [eax*8+window_topleft+0]
3137
        mov     eax,[eax*8+window_topleft+4]
3138
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3139
        neg     eax
3140
        sub     eax,[esp]
3141
        add     eax,[ecx+WDATA.box.height]
3142
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3143
        add     esp,4
114 mikedld 3144
 
429 serge 3145
        pop     edi ecx eax
3146
        ret
114 mikedld 3147
    @@:
429 serge 3148
        xor     eax,eax
3149
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3150
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3151
        mov     eax,[ecx+WDATA.box.width]
3152
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
3153
        mov     eax,[ecx+WDATA.box.height]
3154
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
114 mikedld 3155
 
429 serge 3156
        pop     edi ecx eax
3157
        ret
114 mikedld 3158
 
1 ha 3159
sys_set_window:
3160
 
379 serge 3161
    mov   edi,[CURRENT_TASK]
1 ha 3162
    shl   edi,5
3163
    add   edi,window_data
3164
 
3165
    ; colors
114 mikedld 3166
    mov   [edi+WDATA.cl_workarea],ecx
3167
    mov   [edi+WDATA.cl_titlebar],edx
3168
    mov   [edi+WDATA.cl_frames],esi
1 ha 3169
 
3170
    ; check flag (?)
186 diamond 3171
    test  [edi+WDATA.fl_wdrawn],1
3172
    jnz   newd
1 ha 3173
 
3174
    push  eax
3175
    mov   eax,[timer_ticks] ;[0xfdf0]
3176
    add   eax,100
3177
    mov   [new_window_starting],eax
3178
    pop   eax
3179
 
114 mikedld 3180
    mov   word[edi+WDATA.box.width],ax
3181
    mov   word[edi+WDATA.box.height],bx
3182
    sar   eax,16
3183
    sar   ebx,16
3184
    mov   word[edi+WDATA.box.left],ax
3185
    mov   word[edi+WDATA.box.top],bx
1 ha 3186
 
3187
    call  check_window_position
3188
 
164 serge 3189
    call  set_window_clientbox
1 ha 3190
 
429 serge 3191
    push  ecx esi edi               ; save for window fullscreen/resize
114 mikedld 3192
    ;mov   esi,edi
3193
 
429 serge 3194
        mov     cl,[edi+WDATA.fl_wstyle]
114 mikedld 3195
 
1 ha 3196
    sub   edi,window_data
114 mikedld 3197
    shl   edi,3
380 serge 3198
    add   edi,SLOT_BASE
114 mikedld 3199
 
429 serge 3200
        and     cl,0x0F
3201
        mov     [edi+APPDATA.wnd_caption],0
3202
        cmp     cl,3
549 spraid 3203
        je      set_APPDATA_wnd_caption
3204
        cmp     cl,4								; {SPraid.simba}
3205
        je      set_APPDATA_wnd_caption
567 serge 3206
 
3207
        jmp     @f
549 spraid 3208
    set_APPDATA_wnd_caption:
429 serge 3209
        mov     [edi+APPDATA.wnd_caption],esi
3210
    @@: mov     esi,[esp+0]
114 mikedld 3211
 
115 poddubny 3212
    add   edi, APPDATA.saved_box
429 serge 3213
        movsd
3214
        movsd
3215
        movsd
3216
        movsd
1 ha 3217
    pop   edi esi ecx
3218
 
3219
    push  eax ebx ecx edx
3220
;;;    mov   eax, 1
3221
;;;    call  delay_hs
115 poddubny 3222
    mov   eax, [edi+WDATA.box.left]
3223
    mov   ebx, [edi+WDATA.box.top]
3224
    mov   ecx, [edi+WDATA.box.width]
3225
    mov   edx, [edi+WDATA.box.height]
1 ha 3226
    add   ecx, eax
3227
    add   edx, ebx
3228
    call  calculatescreen
3229
    pop   edx ecx ebx eax
3230
 
429 serge 3231
    mov   [KEY_COUNT],byte 0           ; empty keyboard buffer
3232
    mov   [BTN_COUNT],byte 0           ; empty button buffer
1 ha 3233
 
3234
  newd:
429 serge 3235
    mov   [edi+WDATA.fl_redraw],byte 0   ; no redraw
1 ha 3236
    mov   edx,edi
3237
 
3238
    ret
3239
 
114 mikedld 3240
syscall_windowsettings:
1 ha 3241
 
114 mikedld 3242
  .set_window_caption:
429 serge 3243
        dec     eax     ; subfunction #1 - set window caption
3244
        jnz     .get_window_caption
114 mikedld 3245
 
429 serge 3246
        ; NOTE: only window owner thread can set its caption,
3247
        ;       so there's no parameter for PID/TID
114 mikedld 3248
 
429 serge 3249
        mov     edi,[CURRENT_TASK]
3250
        shl     edi,5
114 mikedld 3251
 
429 serge 3252
        ; have to check if caption is within application memory limit
3253
        ; check is trivial, and if application resizes its memory,
3254
        ;   caption still can become over bounds
202 diamond 3255
; diamond, 31.10.2006: check removed because with new memory manager
3256
; there can be valid data after APPDATA.mem_size bound
380 serge 3257
;        mov     ecx,[edi*8+SLOT_BASE+APPDATA.mem_size]
202 diamond 3258
;        add     ecx,255 ; max caption length
3259
;        cmp     ebx,ecx
3260
;        ja      .exit_fail
114 mikedld 3261
 
429 serge 3262
        mov     [edi*8+SLOT_BASE+APPDATA.wnd_caption],ebx
3263
        or      [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
114 mikedld 3264
 
429 serge 3265
        call    draw_window_caption
114 mikedld 3266
 
429 serge 3267
        xor     eax,eax ; eax = 0 (success)
3268
        ret
114 mikedld 3269
 
3270
  .get_window_caption:
429 serge 3271
        dec     eax     ; subfunction #2 - get window caption
3272
        jnz     .exit_fail
114 mikedld 3273
 
429 serge 3274
        ; not implemented yet
114 mikedld 3275
 
3276
  .exit_fail:
429 serge 3277
        xor     eax,eax
3278
        inc     eax     ; eax = 1 (fail)
3279
        ret
114 mikedld 3280
 
3281
 
1 ha 3282
sys_window_move:
3283
 
429 serge 3284
        mov     edi,[CURRENT_TASK]
3285
        shl     edi,5
3286
        add     edi,window_data
1 ha 3287
 
429 serge 3288
        test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
3289
        jnz     .window_move_return
1 ha 3290
 
429 serge 3291
        push    dword [edi + WDATA.box.left]  ; save old coordinates
3292
        push    dword [edi + WDATA.box.top]
3293
        push    dword [edi + WDATA.box.width]
3294
        push    dword [edi + WDATA.box.height]
1 ha 3295
 
429 serge 3296
        cmp   eax,-1                  ; set new position and size
3297
        je    .no_x_reposition
3298
        mov     [edi + WDATA.box.left], eax
49 mikedld 3299
      .no_x_reposition:
429 serge 3300
        cmp   ebx,-1
3301
        je    .no_y_reposition
3302
        mov     [edi + WDATA.box.top], ebx
49 mikedld 3303
      .no_y_reposition:
1 ha 3304
 
429 serge 3305
        test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
3306
        jnz     .no_y_resizing
1 ha 3307
 
429 serge 3308
        cmp   ecx,-1
3309
        je    .no_x_resizing
3310
        mov     [edi + WDATA.box.width], ecx
49 mikedld 3311
      .no_x_resizing:
429 serge 3312
        cmp   edx,-1
3313
        je    .no_y_resizing
3314
        mov     [edi + WDATA.box.height], edx
49 mikedld 3315
      .no_y_resizing:
1 ha 3316
 
429 serge 3317
        call  check_window_position
3318
        call  set_window_clientbox
1 ha 3319
 
429 serge 3320
        pushad                       ; save for window fullscreen/resize
3321
        mov   esi,edi
3322
        sub   edi,window_data
3323
        shr   edi,5
3324
        shl   edi,8
3325
        add   edi, SLOT_BASE + APPDATA.saved_box
3326
        mov   ecx,4
3327
        cld
3328
        rep   movsd
3329
        popad
49 mikedld 3330
 
429 serge 3331
        pushad                       ; calculcate screen at new position
3332
        mov   eax, [edi + WDATA.box.left]
3333
        mov   ebx, [edi + WDATA.box.top]
3334
        mov   ecx, [edi + WDATA.box.width]
3335
        mov   edx, [edi + WDATA.box.height]
3336
        add   ecx,eax
3337
        add   edx,ebx
221 serge 3338
 
429 serge 3339
        call  calculatescreen
3340
        popad
49 mikedld 3341
 
429 serge 3342
        pop   edx                   ; calculcate screen at old position
3343
        pop   ecx
3344
        pop   ebx
3345
        pop   eax
3346
        add   ecx,eax
3347
        add   edx,ebx
3348
        mov   [dlx],eax             ; save for drawlimits
3349
        mov   [dly],ebx
3350
        mov   [dlxe],ecx
3351
        mov   [dlye],edx
3352
        call  calculatescreen
49 mikedld 3353
 
429 serge 3354
        mov   [edi + WDATA.fl_redraw], 1 ; flag the process as redraw
49 mikedld 3355
 
429 serge 3356
        mov   eax,edi               ; redraw screen at old position
3357
        xor   esi,esi
3358
        call  redrawscreen
49 mikedld 3359
 
429 serge 3360
        mov   [DONT_DRAW_MOUSE],byte 0 ; mouse pointer
3361
        mov   [MOUSE_BACKGROUND],byte 0 ; no mouse under
3362
        mov   [MOUSE_DOWN],byte 0 ; react to mouse up/down
49 mikedld 3363
 
429 serge 3364
        call  [draw_pointer]
49 mikedld 3365
 
429 serge 3366
        mov   [window_move_pr],0
49 mikedld 3367
 
3368
      .window_move_return:
3369
 
429 serge 3370
        ret
1 ha 3371
 
3372
uglobal
3373
  window_move_pr   dd  0x0
3374
  window_move_eax  dd  0x0
3375
  window_move_ebx  dd  0x0
3376
  window_move_ecx  dd  0x0
3377
  window_move_edx  dd  0x0
3378
endg
3379
 
3380
;ok - 100% work
3381
;nt - not tested
3382
;---------------------------------------------------------------------------------------------
3383
;eax
3384
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3385
;1 - change task. Ret nothing. Block. ok.
3386
;2 - performance control
3387
; ebx
3388
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3389
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3390
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3391
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3392
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3393
;eax
3394
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3395
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3396
;---------------------------------------------------------------------------------------------
3397
sys_sheduler: ;noname & halyavin
3398
    cmp eax,0
3399
    je shed_counter
3400
    cmp eax,2
3401
    je perf_control
3402
    cmp eax,3
3403
    je rdmsr_instr
3404
    cmp eax,4
3405
    je wrmsr_instr
3406
    cmp eax,1
3407
    jne not_supported
3408
    call change_task ;delay,0
3409
ret
3410
shed_counter:
3411
    mov eax,[context_counter]
3412
    mov [esp+36],eax
3413
not_supported:
3414
ret
3415
perf_control:
3416
    inc eax ;now eax=3
3417
    cmp ebx,eax
3418
    je cache_disable
3419
    dec eax
3420
    cmp ebx,eax
3421
    je cache_enable
3422
    dec eax
3423
    cmp ebx,eax
3424
    je is_cache_enabled
3425
    dec eax
3426
    cmp ebx,eax
3427
    je modify_pce
3428
ret
3429
 
3430
rdmsr_instr:
3431
;now counter in ecx
3432
;(edx:eax) esi:edi => edx:esi
3433
mov eax,esi
3434
rdmsr
3435
mov [esp+36],eax
3436
mov [esp+24],edx ;ret in ebx?
3437
ret
3438
 
3439
wrmsr_instr:
3440
;now counter in ecx
3441
;(edx:eax) esi:edi => edx:esi
482 Ghost 3442
	; Fast Call MSR can't be destroy
3443
	; Íî MSR_AMD_EFER ìîæíî èçìåíÿòü, ò.ê. â ýòîì ðåãèñòðå ëèø
3444
	; âêëþ÷àþòñÿ/âûêëþ÷àþòñÿ ðàñøèðåííûå âîçìîæíîñòè
3445
	cmp	ecx, MSR_SYSENTER_CS
3446
	je	@f
3447
	cmp	ecx, MSR_SYSENTER_ESP
3448
	je	@f
3449
	cmp	ecx, MSR_SYSENTER_EIP
3450
	je	@f
3451
	cmp	ecx, MSR_AMD_STAR
3452
	je	@f
3453
 
3454
	mov	eax, esi
3455
	wrmsr
3456
	; mov	[esp + 36], eax
3457
	; mov	[esp + 24], edx ;ret in ebx?
3458
@@:
1 ha 3459
ret
3460
 
3461
cache_disable:
3462
       mov eax,cr0
3463
       or  eax,01100000000000000000000000000000b
3464
       mov cr0,eax
3465
       wbinvd ;set MESI
3466
ret
3467
 
3468
cache_enable:
3469
       mov eax,cr0
3470
       and eax,10011111111111111111111111111111b
3471
       mov cr0,eax
3472
ret
3473
 
3474
is_cache_enabled:
3475
       mov eax,cr0
3476
       mov ebx,eax
3477
       and eax,01100000000000000000000000000000b
3478
       jz cache_disabled
3479
       mov [esp+36],ebx
3480
cache_disabled:
3481
       mov dword [esp+36],eax ;0
3482
ret
3483
 
3484
modify_pce:
3485
       mov eax,cr4
3486
;       mov ebx,0
3487
;       or  bx,100000000b ;pce
3488
;       xor eax,ebx ;invert pce
17 me_root 3489
       bts eax,8 ;pce=cr4[8]
1 ha 3490
       mov cr4,eax
3491
       mov [esp+36],eax
3492
ret
3493
;---------------------------------------------------------------------------------------------
3494
 
3495
 
3496
; check if pixel is allowed to be drawn
3497
 
3498
checkpixel:
429 serge 3499
        push eax edx
1 ha 3500
 
429 serge 3501
        mov  edx,[ScreenWidth]     ; screen x size
3502
        inc  edx
3503
        imul edx, ebx
3504
        mov  dl, [eax+edx+display_data] ; lea eax, [...]
1 ha 3505
 
429 serge 3506
        xor  ecx, ecx
3507
        mov  eax, [CURRENT_TASK]
3508
        cmp  al, dl
3509
        setne cl
1 ha 3510
 
429 serge 3511
        pop  edx eax
3512
        ret
1 ha 3513
 
3514
iglobal
521 diamond 3515
  cpustring db 'CPU',0
1 ha 3516
endg
3517
 
67 diamond 3518
uglobal
429 serge 3519
background_defined    db    0    ; diamond, 11.04.2006
67 diamond 3520
endg
1 ha 3521
 
3522
align 4
3523
; check misc
3524
 
3525
checkmisc:
3526
 
3527
    cmp   [ctrl_alt_del], 1
3528
    jne   nocpustart
501 serge 3529
 
521 diamond 3530
        mov     ebp, cpustring
3531
        call    fs_execute_from_sysdir
501 serge 3532
 
1 ha 3533
    mov   [ctrl_alt_del], 0
465 serge 3534
 
3535
nocpustart:
1 ha 3536
    cmp   [mouse_active], 1
3537
    jne   mouse_not_active
3538
    mov   [mouse_active], 0
3539
    xor   edi, edi
465 serge 3540
    mov   ecx,  [TASK_COUNT]
3541
set_mouse_event:
1 ha 3542
    add   edi, 256
465 serge 3543
    or    [edi+SLOT_BASE+APPDATA.event_mask], dword 100000b
1 ha 3544
    loop  set_mouse_event
3545
 
465 serge 3546
mouse_not_active:
429 serge 3547
    cmp   [REDRAW_BACKGROUND],byte 0               ; background update ?
3548
    jz    nobackgr
76 mario79 3549
    cmp    [background_defined], 0
429 serge 3550
    jz    nobackgr
473 diamond 3551
;    mov   [REDRAW_BACKGROUND],byte 2
3552
;    call  change_task
3553
    xor   edi, edi
3554
    mov   ecx,  [TASK_COUNT]
3555
set_bgr_event:
3556
    add   edi, 256
3557
    or    [edi+SLOT_BASE+APPDATA.event_mask], 16
3558
    loop  set_bgr_event
465 serge 3559
    mov   [draw_data+32 + RECT.left],dword 0
3560
    mov   [draw_data+32 + RECT.top],dword 0
381 serge 3561
    mov   eax,[ScreenWidth]
3562
    mov   ebx,[ScreenHeight]
465 serge 3563
    mov   [draw_data+32 + RECT.right],eax
3564
    mov   [draw_data+32 + RECT.bottom],ebx
1 ha 3565
    call  drawbackground
381 serge 3566
    mov   [REDRAW_BACKGROUND],byte 0
3567
    mov   [MOUSE_BACKGROUND],byte 0
1 ha 3568
 
465 serge 3569
nobackgr:
1 ha 3570
 
3571
    ; system shutdown request
3572
 
381 serge 3573
    cmp  [SYS_SHUTDOWN],byte 0
429 serge 3574
    je   noshutdown
1 ha 3575
 
3576
    mov  edx,[shutdown_processes]
3577
    sub  dl,2
3578
 
381 serge 3579
    cmp  [SYS_SHUTDOWN],dl
1 ha 3580
    jne  no_mark_system_shutdown
3581
 
465 serge 3582
    mov   edx,OS_BASE+0x3040
381 serge 3583
    movzx ecx,byte [SYS_SHUTDOWN]
1 ha 3584
    add   ecx,5
465 serge 3585
markz:
115 poddubny 3586
    mov   [edx+TASKDATA.state],byte 3
1 ha 3587
    add   edx,0x20
3588
    loop  markz
3589
 
3590
  no_mark_system_shutdown:
3591
 
3592
    call [disable_mouse]
3593
 
381 serge 3594
    dec  byte [SYS_SHUTDOWN]
1 ha 3595
 
381 serge 3596
    cmp  [SYS_SHUTDOWN],byte 0
429 serge 3597
    je   system_shutdown
1 ha 3598
 
465 serge 3599
noshutdown:
1 ha 3600
 
3601
 
429 serge 3602
    mov   eax,[TASK_COUNT]                  ; termination
379 serge 3603
    mov   ebx,TASK_DATA+TASKDATA.state
1 ha 3604
    mov   esi,1
3605
 
465 serge 3606
newct:
1 ha 3607
    mov   cl,[ebx]
3608
    cmp   cl,byte 3
429 serge 3609
    jz    terminate
1 ha 3610
    cmp   cl,byte 4
429 serge 3611
    jz    terminate
1 ha 3612
 
3613
    add   ebx,0x20
3614
    inc   esi
3615
    dec   eax
3616
    jnz   newct
3617
 
3618
    ret
3619
 
3620
 
3621
; redraw screen
3622
 
3623
redrawscreen:
3624
 
3625
; eax , if process window_data base is eax, do not set flag/limits
3626
 
429 serge 3627
         pushad
3628
         push  eax
1 ha 3629
 
3630
;;;         mov   eax,2
3631
;;;         call  delay_hs
3632
 
429 serge 3633
         ;mov   ecx,0               ; redraw flags for apps
3634
         xor   ecx,ecx
1 ha 3635
       newdw2:
3636
 
429 serge 3637
         inc   ecx
3638
         push  ecx
1 ha 3639
 
429 serge 3640
         mov   eax,ecx
3641
         shl   eax,5
3642
         add   eax,window_data
1 ha 3643
 
429 serge 3644
         cmp   eax,[esp+4]
3645
         je    not_this_task
3646
                                   ; check if window in redraw area
3647
         mov   edi,eax
1 ha 3648
 
429 serge 3649
         cmp   ecx,1               ; limit for background
3650
         jz    bgli
1 ha 3651
 
429 serge 3652
         mov   eax, [edi + WDATA.box.left]
3653
         mov   ebx, [edi + WDATA.box.top]
3654
         mov   ecx, [edi + WDATA.box.width]
3655
         mov   edx, [edi + WDATA.box.height]
3656
         add   ecx,eax
3657
         add   edx,ebx
1 ha 3658
 
429 serge 3659
         mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
3660
         cmp   ecx,ebx
3661
         jb    ricino
1 ha 3662
 
429 serge 3663
         mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
3664
         cmp   ecx,eax
3665
         jb    ricino
1 ha 3666
 
429 serge 3667
         mov   eax, [edi + WDATA.box.left]
3668
         mov   ebx, [edi + WDATA.box.top]
3669
         mov   ecx, [edi + WDATA.box.width]
3670
         mov   edx, [edi + WDATA.box.height]
3671
         add   ecx, eax
3672
         add   edx, ebx
164 serge 3673
 
429 serge 3674
         mov   eax,[dly]    ; eax = area y start     edx = window y end
3675
         cmp   edx,eax
3676
         jb    ricino
1 ha 3677
 
429 serge 3678
         mov   eax,[dlx]    ; eax = area x start     ecx = window x end
3679
         cmp   ecx,eax
3680
         jb    ricino
1 ha 3681
 
429 serge 3682
        bgli:
1 ha 3683
 
429 serge 3684
         cmp   edi,esi
3685
         jz    ricino
1 ha 3686
 
429 serge 3687
         mov   eax,edi
3688
         add   eax,draw_data-window_data
1 ha 3689
 
429 serge 3690
         mov   ebx,[dlx]          ; set limits
3691
         mov   [eax + RECT.left], ebx
3692
         mov   ebx,[dly]
3693
         mov   [eax + RECT.top], ebx
3694
         mov   ebx,[dlxe]
3695
         mov   [eax + RECT.right], ebx
3696
         mov   ebx,[dlye]
3697
         mov   [eax + RECT.bottom], ebx
1 ha 3698
 
429 serge 3699
         sub   eax,draw_data-window_data
1 ha 3700
 
429 serge 3701
         cmp   ecx,1
3702
         jne   nobgrd
3703
         cmp   esi,1
3704
         je    newdw8
3705
         call  drawbackground
1 ha 3706
 
3707
       newdw8:
3708
       nobgrd:
3709
 
429 serge 3710
         mov   [eax + WDATA.fl_redraw],byte 1    ; mark as redraw
1 ha 3711
 
3712
       ricino:
3713
 
3714
       not_this_task:
3715
 
429 serge 3716
         pop   ecx
1 ha 3717
 
429 serge 3718
         cmp   ecx,[TASK_COUNT]
3719
         jle   newdw2
1 ha 3720
 
429 serge 3721
         pop  eax
3722
         popad
1 ha 3723
 
429 serge 3724
         ret
1 ha 3725
 
3726
calculatebackground:   ; background
3727
 
429 serge 3728
        ; all black
1 ha 3729
 
469 serge 3730
        mov   edi, [img_background]  ;IMG_BACKGROUND                 ; set background to black
429 serge 3731
        xor   eax, eax
469 serge 3732
        mov   ecx, 1023    ;0x0fff00 / 4
429 serge 3733
        cld
3734
        rep   stosd
1 ha 3735
 
429 serge 3736
        mov   edi,display_data              ; set os to use all pixels
3737
        mov   eax,0x01010101
472 serge 3738
        mov   ecx,1280*1024 / 4
429 serge 3739
        rep   stosd
1 ha 3740
 
429 serge 3741
        mov   byte [REDRAW_BACKGROUND], 0              ; do not draw background!
1 ha 3742
 
429 serge 3743
        ret
1 ha 3744
 
3745
uglobal
429 serge 3746
  imax    dd 0x0
1 ha 3747
endg
3748
 
3749
 
3750
 
3751
delay_ms:     ; delay in 1/1000 sec
3752
 
3753
 
429 serge 3754
        push  eax
3755
        push  ecx
1 ha 3756
 
429 serge 3757
        mov   ecx,esi
3758
        ; 
3759
        imul  ecx, 33941
3760
        shr   ecx, 9
3761
        ; 
1 ha 3762
 
429 serge 3763
        in    al,0x61
3764
        and   al,0x10
3765
        mov   ah,al
3766
        cld
1 ha 3767
 
429 serge 3768
 cnt1:  in    al,0x61
3769
        and   al,0x10
3770
        cmp   al,ah
3771
        jz    cnt1
1 ha 3772
 
429 serge 3773
        mov   ah,al
3774
        loop  cnt1
1 ha 3775
 
429 serge 3776
        pop   ecx
3777
        pop   eax
1 ha 3778
 
429 serge 3779
        ret
1 ha 3780
 
3781
 
3782
set_app_param:
429 serge 3783
        push edi
1 ha 3784
 
429 serge 3785
        mov  edi,[TASK_BASE]
3786
        mov  [edi+TASKDATA.event_mask],eax
1 ha 3787
 
429 serge 3788
        pop  edi
3789
        ret
1 ha 3790
 
3791
 
3792
 
3793
delay_hs:     ; delay in 1/100 secs
429 serge 3794
        push  eax
3795
        push  ecx
3796
        push  edx
1 ha 3797
 
429 serge 3798
        mov   edx,[timer_ticks]
3799
        add   edx,eax
1 ha 3800
 
3801
      newtic:
429 serge 3802
        mov   ecx,[timer_ticks]
3803
        cmp   edx,ecx
3804
        jbe   zerodelay
1 ha 3805
 
429 serge 3806
        call  change_task
1 ha 3807
 
429 serge 3808
        jmp   newtic
1 ha 3809
 
3810
      zerodelay:
429 serge 3811
        pop   edx
3812
        pop   ecx
3813
        pop   eax
1 ha 3814
 
429 serge 3815
        ret
1 ha 3816
 
3817
 
3818
memmove:       ; memory move in bytes
3819
 
3820
; eax = from
3821
; ebx = to
3822
; ecx = no of bytes
3823
    test ecx, ecx
3824
    jle  .ret
3825
 
3826
 
3827
    push esi edi ecx
3828
 
3829
    mov  edi, ebx
3830
    mov  esi, eax
3831
 
3832
    test ecx, not 11b
429 serge 3833
    jz   @f
1 ha 3834
 
3835
    push ecx
3836
    shr  ecx, 2
3837
    rep  movsd
3838
    pop  ecx
3839
    and  ecx, 11b
429 serge 3840
    jz   .finish
1 ha 3841
  @@:
3842
    rep  movsb
3843
 
3844
  .finish:
3845
    pop  ecx edi esi
3846
  .ret:
3847
    ret
3848
 
3849
 
75 diamond 3850
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
3851
;align 4
1 ha 3852
;
75 diamond 3853
;read_floppy_file:
1 ha 3854
;
75 diamond 3855
;; as input
3856
;;
3857
;; eax pointer to file
3858
;; ebx file lenght
3859
;; ecx start 512 byte block number
3860
;; edx number of blocks to read
3861
;; esi pointer to return/work area (atleast 20 000 bytes)
3862
;;
3863
;;
3864
;; on return
3865
;;
3866
;; eax = 0 command succesful
3867
;;       1 no fd base and/or partition defined
3868
;;       2 yet unsupported FS
3869
;;       3 unknown FS
3870
;;       4 partition not defined at hd
3871
;;       5 file not found
3872
;; ebx = size of file
1 ha 3873
;
379 serge 3874
;     mov   edi,[TASK_BASE]
75 diamond 3875
;     add   edi,0x10
3876
;     add   esi,[edi]
3877
;     add   eax,[edi]
1 ha 3878
;
75 diamond 3879
;     pushad
3880
;     mov  edi,esi
3881
;     add  edi,1024
3882
;     mov  esi,0x100000+19*512
3883
;     sub  ecx,1
3884
;     shl  ecx,9
3885
;     add  esi,ecx
3886
;     shl  edx,9
3887
;     mov  ecx,edx
3888
;     cld
3889
;     rep  movsb
3890
;     popad
3891
;
3892
;     mov   [esp+36],eax
3893
;     mov   [esp+24],ebx
3894
;     ret
1 ha 3895
 
3896
 
3897
 
3898
align 4
3899
 
3900
sys_programirq:
3901
 
379 serge 3902
    mov   edi,[TASK_BASE]
115 poddubny 3903
    add   eax,[edi+TASKDATA.mem_start]
1 ha 3904
 
75 diamond 3905
    cmp   ebx,16
3906
    jae   .not_owner
379 serge 3907
    mov   edi,[TASK_BASE]
115 poddubny 3908
    mov   edi,[edi+TASKDATA.pid]
75 diamond 3909
    cmp   edi,[irq_owner+ebx*4]
429 serge 3910
    je    spril1
75 diamond 3911
.not_owner:
1 ha 3912
    mov   [esp+36],dword 1
3913
    ret
3914
  spril1:
3915
 
3916
    mov   esi,eax
3917
    shl   ebx,6
3918
    add   ebx,irq00read
3919
    mov   edi,ebx
3920
    mov   ecx,16
3921
    cld
3922
    rep   movsd
3923
    mov   [esp+36],dword 0
3924
    ret
3925
 
3926
 
3927
align 4
3928
 
3929
get_irq_data:
75 diamond 3930
     cmp   eax,16
3931
     jae   .not_owner
429 serge 3932
     mov   edx,eax           ; check for correct owner
1 ha 3933
     shl   edx,2
3934
     add   edx,irq_owner
3935
     mov   edx,[edx]
379 serge 3936
     mov   edi,[TASK_BASE]
115 poddubny 3937
     mov   edi,[edi+TASKDATA.pid]
1 ha 3938
     cmp   edx,edi
3939
     je    gidril1
75 diamond 3940
.not_owner:
429 serge 3941
     mov   [esp+32],dword 2     ; ecx=2
1 ha 3942
     ret
3943
 
3944
  gidril1:
3945
 
3946
     mov   ebx,eax
3947
     shl   ebx,12
381 serge 3948
     add   ebx,IRQ_SAVE
1 ha 3949
     mov   eax,[ebx]
3950
     mov   ecx,1
3951
     test  eax,eax
3952
     jz    gid1
3953
 
3954
     dec   eax
3955
     mov   esi,ebx
3956
     mov   [ebx],eax
3957
     movzx ebx,byte [ebx+0x10]
3958
     add   esi,0x10
3959
     mov   edi,esi
3960
     inc   esi
3961
     mov   ecx,4000 / 4
3962
     cld
3963
     rep   movsd
75 diamond 3964
;     xor   ecx,ecx     ; as result of 'rep' ecx=0
1 ha 3965
   gid1:
3966
     mov   [esp+36],eax
3967
     mov   [esp+32],ecx
3968
     mov   [esp+24],ebx
3969
     ret
3970
 
3971
 
3972
set_io_access_rights:
3973
 
3974
     pushad
3975
 
465 serge 3976
     mov edi, tss._io_map_0
1 ha 3977
 
465 serge 3978
;     mov   ecx,eax
3979
;     and   ecx,7    ; offset in byte
1 ha 3980
 
465 serge 3981
;     shr   eax,3    ; number of byte
3982
;     add   edi,eax
1 ha 3983
 
465 serge 3984
;     mov   ebx,1
3985
;     shl   ebx,cl
1 ha 3986
 
429 serge 3987
     cmp   ebp,0                ; enable access - ebp = 0
1 ha 3988
     jne   siar1
3989
 
465 serge 3990
;     not   ebx
3991
;     and   [edi],byte bl
3992
     btr [edi], eax
1 ha 3993
 
3994
     popad
3995
 
3996
     ret
3997
 
465 serge 3998
siar1:
1 ha 3999
 
465 serge 4000
     bts [edi], eax
4001
  ;  or    [edi],byte bl        ; disable access - ebp = 1
1 ha 4002
 
4003
     popad
4004
 
4005
     ret
4006
 
4007
r_f_port_area:
4008
 
4009
     test  eax, eax
4010
     jnz   free_port_area
4011
;     je    r_port_area
4012
;     jmp   free_port_area
4013
 
4014
;   r_port_area:
4015
 
4016
     pushad
4017
 
429 serge 4018
     cmp   ebx,ecx            ; beginning > end ?
75 diamond 4019
     ja    rpal1
4020
     cmp   ecx,65536
4021
     jae   rpal1
381 serge 4022
     mov   esi,[RESERVED_PORTS]
429 serge 4023
     test  esi,esi            ; no reserved areas ?
1 ha 4024
     je    rpal2
429 serge 4025
     cmp   esi,255            ; max reserved
75 diamond 4026
     jae   rpal1
465 serge 4027
 rpal3:
1 ha 4028
     mov   edi,esi
4029
     shl   edi,4
381 serge 4030
     add   edi,RESERVED_PORTS
1 ha 4031
     cmp   ebx,[edi+8]
75 diamond 4032
     ja    rpal4
1 ha 4033
     cmp   ecx,[edi+4]
4034
     jae   rpal1
4035
;     jb    rpal4
4036
;     jmp   rpal1
465 serge 4037
 rpal4:
1 ha 4038
 
4039
     dec   esi
4040
     jnz   rpal3
4041
     jmp   rpal2
4042
   rpal1:
4043
     popad
4044
     mov   eax,1
4045
     ret
4046
 
4047
   rpal2:
4048
     popad
4049
 
4050
 
4051
     ; enable port access at port IO map
4052
     cli
429 serge 4053
     pushad                        ; start enable io map
1 ha 4054
 
4055
     cmp   ecx,65536 ;16384
4056
     jae   no_unmask_io ; jge
4057
 
4058
     mov   eax,ebx
4059
 
4060
   new_port_access:
4061
 
4062
     pushad
4063
 
429 serge 4064
     xor   ebp,ebp                ; enable - eax = port
1 ha 4065
     call  set_io_access_rights
4066
 
4067
     popad
4068
 
4069
     inc   eax
4070
     cmp   eax,ecx
4071
     jbe   new_port_access
4072
 
4073
   no_unmask_io:
4074
 
429 serge 4075
     popad                         ; end enable io map
1 ha 4076
     sti
4077
 
381 serge 4078
     mov   edi,[RESERVED_PORTS]
1 ha 4079
     add   edi,1
381 serge 4080
     mov   [RESERVED_PORTS],edi
1 ha 4081
     shl   edi,4
381 serge 4082
     add   edi,RESERVED_PORTS
379 serge 4083
     mov   esi,[TASK_BASE]
115 poddubny 4084
     mov   esi,[esi+TASKDATA.pid]
1 ha 4085
     mov   [edi],esi
4086
     mov   [edi+4],ebx
4087
     mov   [edi+8],ecx
4088
 
4089
     xor   eax, eax
4090
     ret
4091
 
4092
free_port_area:
4093
 
4094
     pushad
4095
 
381 serge 4096
     mov   esi,[RESERVED_PORTS]     ; no reserved areas ?
75 diamond 4097
     test  esi,esi
1 ha 4098
     je    frpal2
379 serge 4099
     mov   edx,[TASK_BASE]
115 poddubny 4100
     mov   edx,[edx+TASKDATA.pid]
1 ha 4101
   frpal3:
4102
     mov   edi,esi
4103
     shl   edi,4
381 serge 4104
     add   edi,RESERVED_PORTS
1 ha 4105
     cmp   edx,[edi]
4106
     jne   frpal4
4107
     cmp   ebx,[edi+4]
4108
     jne   frpal4
4109
     cmp   ecx,[edi+8]
4110
     jne   frpal4
4111
     jmp   frpal1
4112
   frpal4:
4113
     dec   esi
4114
     jnz   frpal3
4115
   frpal2:
4116
     popad
4117
     mov   eax,1
4118
     ret
4119
   frpal1:
4120
     mov   ecx,256
4121
     sub   ecx,esi
4122
     shl   ecx,4
4123
     mov   esi,edi
4124
     add   esi,16
4125
     cld
4126
     rep   movsb
4127
 
381 serge 4128
     dec   dword [RESERVED_PORTS]
1 ha 4129
 
4130
     popad
4131
 
4132
 
4133
     ; disable port access at port IO map
4134
 
429 serge 4135
     pushad                        ; start disable io map
1 ha 4136
 
4137
     cmp   ecx,65536 ;16384
4138
     jge   no_mask_io
4139
 
4140
     mov   eax,ebx
4141
 
4142
   new_port_access_disable:
4143
 
4144
     pushad
4145
 
429 serge 4146
     mov   ebp,1                  ; disable - eax = port
1 ha 4147
     call  set_io_access_rights
4148
 
4149
     popad
4150
 
4151
     inc   eax
4152
     cmp   eax,ecx
4153
     jbe   new_port_access_disable
4154
 
4155
   no_mask_io:
4156
 
429 serge 4157
     popad                         ; end disable io map
1 ha 4158
 
4159
     xor   eax, eax
4160
     ret
4161
 
4162
 
4163
reserve_free_irq:
4164
 
75 diamond 4165
     mov   ecx, 1
4166
     cmp   ebx, 16
4167
     jae   fril1
4168
     test  eax,eax
1 ha 4169
     jz    reserve_irq
4170
 
75 diamond 4171
     lea   edi,[irq_owner+ebx*4]
1 ha 4172
     mov   edx,[edi]
379 serge 4173
     mov   eax,[TASK_BASE]
115 poddubny 4174
     cmp   edx,[eax+TASKDATA.pid]
1 ha 4175
     jne   fril1
75 diamond 4176
     dec   ecx
4177
     mov   [edi],ecx
1 ha 4178
   fril1:
4179
     mov   [esp+36],ecx ; return in eax
4180
     ret
4181
 
4182
  reserve_irq:
4183
 
75 diamond 4184
     lea   edi,[irq_owner+ebx*4]
4185
     cmp   dword [edi], 0
4186
     jnz   ril1
1 ha 4187
 
379 serge 4188
     mov   edx,[TASK_BASE]
115 poddubny 4189
     mov   edx,[edx+TASKDATA.pid]
1 ha 4190
     mov   [edi],edx
75 diamond 4191
     dec   ecx
1 ha 4192
   ril1:
4193
     mov   [esp+36],ecx ; return in eax
4194
     ret
4195
 
4196
drawbackground:
33 mario79 4197
       inc   [mouse_pause]
381 serge 4198
       cmp   [SCR_MODE],word 0x12
117 mario79 4199
       je   dbrv20
1 ha 4200
     dbrv12:
381 serge 4201
       cmp  [SCR_MODE],word 0100000000000000b
1 ha 4202
       jge  dbrv20
381 serge 4203
       cmp  [SCR_MODE],word 0x13
1 ha 4204
       je   dbrv20
4205
       call  vesa12_drawbackground
33 mario79 4206
       dec   [mouse_pause]
36 mario79 4207
       call   [draw_pointer]
1 ha 4208
       ret
4209
     dbrv20:
527 diamond 4210
       cmp   [BgrDrawMode],dword 1
1 ha 4211
       jne   bgrstr
4212
       call  vesa20_drawbackground_tiled
33 mario79 4213
       dec   [mouse_pause]
36 mario79 4214
       call   [draw_pointer]
1 ha 4215
       ret
4216
     bgrstr:
4217
       call  vesa20_drawbackground_stretch
33 mario79 4218
       dec   [mouse_pause]
36 mario79 4219
       call   [draw_pointer]
1 ha 4220
       ret
4221
 
75 diamond 4222
align 4
1 ha 4223
 
429 serge 4224
syscall_putimage:                       ; PutImage
33 mario79 4225
 
75 diamond 4226
     mov   edx,ecx
4227
     mov   ecx,ebx
465 serge 4228
     mov   ebx, eax
75 diamond 4229
 
1 ha 4230
sys_putimage:
53 mikedld 4231
     test  ecx,0x80008000
4232
     jnz   .exit
4233
     test  ecx,0x0000FFFF
4234
     jz    .exit
4235
     test  ecx,0xFFFF0000
4236
     jnz   @f
4237
  .exit:
4238
     ret
4239
 @@:
465 serge 4240
        mov     edi,[current_slot]
4241
        add     dx,word[edi+APPDATA.wnd_clientbox.top]
429 serge 4242
        rol     edx,16
465 serge 4243
        add     dx,word[edi+APPDATA.wnd_clientbox.left]
429 serge 4244
        rol     edx,16
114 mikedld 4245
  .forced:
429 serge 4246
        push    ebp esi 0
4247
        mov     ebp, putimage_get24bpp
4248
        mov     esi, putimage_init24bpp
283 diamond 4249
sys_putimage_bpp:
4250
;        call    [disable_mouse] ; this will be done in xxx_putimage
117 mario79 4251
;        mov     eax, vga_putimage
429 serge 4252
        cmp     [SCR_MODE], word 0x12
4253
        jz      @f   ;.doit
4254
        mov     eax, vesa12_putimage
4255
        cmp     [SCR_MODE], word 0100000000000000b
4256
        jae     @f
4257
        cmp     [SCR_MODE], word 0x13
4258
        jnz     .doit
75 diamond 4259
@@:
429 serge 4260
        mov     eax, vesa20_putimage
75 diamond 4261
.doit:
429 serge 4262
        inc     [mouse_pause]
4263
        call    eax
4264
        dec     [mouse_pause]
4265
        pop     ebp esi ebp
4266
        jmp     [draw_pointer]
1 ha 4267
 
283 diamond 4268
syscall_putimage_palette:
465 serge 4269
        mov     edi, esi
429 serge 4270
        mov     esi, edx
4271
        mov     edx, ecx
4272
        mov     ecx, ebx
465 serge 4273
        mov     ebx, eax
283 diamond 4274
sys_putimage_palette:
4275
; ebx = pointer to image
4276
; ecx = [xsize]*65536 + [ysize]
4277
; edx = [xstart]*65536 + [ystart]
314 diamond 4278
; esi = number of bits per pixel, must be 8, 24 or 32
283 diamond 4279
; edi = pointer to palette
314 diamond 4280
; ebp = row delta
429 serge 4281
        mov     eax, [CURRENT_TASK]
4282
        shl     eax, 8
4283
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
4284
        rol     edx, 16
4285
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
4286
        rol     edx, 16
283 diamond 4287
.forced:
429 serge 4288
        push    ebp esi ebp
4289
        cmp     esi, 8
4290
        jnz     @f
4291
        mov     ebp, putimage_get8bpp
4292
        mov     esi, putimage_init8bpp
4293
        jmp     sys_putimage_bpp
314 diamond 4294
@@:
429 serge 4295
        cmp     esi, 24
4296
        jnz     @f
4297
        mov     ebp, putimage_get24bpp
4298
        mov     esi, putimage_init24bpp
4299
        jmp     sys_putimage_bpp
314 diamond 4300
@@:
429 serge 4301
        cmp     esi, 32
4302
        jnz     @f
4303
        mov     ebp, putimage_get32bpp
4304
        mov     esi, putimage_init32bpp
4305
        jmp     sys_putimage_bpp
314 diamond 4306
@@:
429 serge 4307
        pop     ebp esi
4308
        ret
283 diamond 4309
 
4310
putimage_init24bpp:
429 serge 4311
        lea     eax, [eax*3]
283 diamond 4312
putimage_init8bpp:
429 serge 4313
        ret
283 diamond 4314
 
4315
putimage_get24bpp:
429 serge 4316
        mov     eax, [esi]
4317
        add     esi, 3
4318
        ret     4
283 diamond 4319
putimage_get8bpp:
429 serge 4320
        movzx   eax, byte [esi]
4321
        push    edx
4322
        mov     edx, [esp+8]
4323
        mov     eax, [edx+eax*4]
4324
        pop     edx
4325
        inc     esi
4326
        ret     4
283 diamond 4327
 
314 diamond 4328
putimage_init32bpp:
429 serge 4329
        shl     eax, 2
4330
        ret
314 diamond 4331
putimage_get32bpp:
429 serge 4332
        lodsd
4333
        ret     4
314 diamond 4334
 
1 ha 4335
; eax x beginning
4336
; ebx y beginning
4337
; ecx x end
283 diamond 4338
	; edx y end
1 ha 4339
; edi color
4340
 
4341
__sys_drawbar:
465 serge 4342
        mov     esi,[current_slot]
4343
        add     eax,[esi+APPDATA.wnd_clientbox.left]
4344
        add     ecx,[esi+APPDATA.wnd_clientbox.left]
4345
        add     ebx,[esi+APPDATA.wnd_clientbox.top]
4346
        add     edx,[esi+APPDATA.wnd_clientbox.top]
114 mikedld 4347
  .forced:
33 mario79 4348
    inc   [mouse_pause]
283 diamond 4349
;        call    [disable_mouse]
381 serge 4350
    cmp   [SCR_MODE],word 0x12
429 serge 4351
    je   dbv20
1 ha 4352
   sdbv20:
381 serge 4353
    cmp  [SCR_MODE],word 0100000000000000b
1 ha 4354
    jge  dbv20
381 serge 4355
    cmp  [SCR_MODE],word 0x13
429 serge 4356
    je   dbv20
1 ha 4357
    call vesa12_drawbar
33 mario79 4358
    dec   [mouse_pause]
36 mario79 4359
    call   [draw_pointer]
1 ha 4360
    ret
4361
  dbv20:
4362
    call vesa20_drawbar
33 mario79 4363
    dec   [mouse_pause]
36 mario79 4364
    call   [draw_pointer]
1 ha 4365
    ret
4366
 
4367
 
4368
 
4369
kb_read:
4370
 
429 serge 4371
        push    ecx edx
1 ha 4372
 
429 serge 4373
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4374
      kr_loop:
429 serge 4375
        in      al,0x64
4376
        test    al,1
4377
        jnz     kr_ready
4378
        loop    kr_loop
4379
        mov     ah,1
4380
        jmp     kr_exit
1 ha 4381
      kr_ready:
429 serge 4382
        push    ecx
4383
        mov     ecx,32
1 ha 4384
      kr_delay:
429 serge 4385
        loop    kr_delay
4386
        pop     ecx
4387
        in      al,0x60
4388
        xor     ah,ah
1 ha 4389
      kr_exit:
4390
 
429 serge 4391
        pop     edx ecx
1 ha 4392
 
429 serge 4393
        ret
1 ha 4394
 
4395
 
4396
kb_write:
4397
 
429 serge 4398
        push    ecx edx
1 ha 4399
 
429 serge 4400
        mov     dl,al
265 diamond 4401
;        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4402
;      kw_loop1:
4403
;        in      al,0x64
4404
;        test    al,0x20
4405
;        jz      kw_ok1
4406
;        loop    kw_loop1
4407
;        mov     ah,1
4408
;        jmp     kw_exit
4409
;      kw_ok1:
429 serge 4410
        in      al,0x60
4411
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4412
      kw_loop:
429 serge 4413
        in      al,0x64
4414
        test    al,2
4415
        jz      kw_ok
4416
        loop    kw_loop
4417
        mov     ah,1
4418
        jmp     kw_exit
1 ha 4419
      kw_ok:
429 serge 4420
        mov     al,dl
4421
        out     0x60,al
4422
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4423
      kw_loop3:
429 serge 4424
        in      al,0x64
4425
        test    al,2
4426
        jz      kw_ok3
4427
        loop    kw_loop3
4428
        mov     ah,1
4429
        jmp     kw_exit
1 ha 4430
      kw_ok3:
429 serge 4431
        mov     ah,8
1 ha 4432
      kw_loop4:
429 serge 4433
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4434
      kw_loop5:
429 serge 4435
        in      al,0x64
4436
        test    al,1
4437
        jnz     kw_ok4
4438
        loop    kw_loop5
4439
        dec     ah
4440
        jnz     kw_loop4
1 ha 4441
      kw_ok4:
429 serge 4442
        xor     ah,ah
1 ha 4443
      kw_exit:
4444
 
429 serge 4445
        pop     edx ecx
1 ha 4446
 
429 serge 4447
        ret
1 ha 4448
 
4449
 
4450
kb_cmd:
4451
 
429 serge 4452
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4453
      c_wait:
429 serge 4454
        in      al,0x64
4455
        test    al,2
4456
        jz      c_send
4457
        loop    c_wait
4458
        jmp     c_error
1 ha 4459
      c_send:
429 serge 4460
        mov     al,bl
4461
        out     0x64,al
4462
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4463
      c_accept:
429 serge 4464
        in      al,0x64
4465
        test    al,2
4466
        jz      c_ok
4467
        loop    c_accept
1 ha 4468
      c_error:
429 serge 4469
        mov     ah,1
4470
        jmp     c_exit
1 ha 4471
      c_ok:
429 serge 4472
        xor     ah,ah
1 ha 4473
      c_exit:
429 serge 4474
        ret
1 ha 4475
 
4476
 
4477
setmouse:  ; set mousepicture -pointer
429 serge 4478
           ; ps2 mouse enable
1 ha 4479
 
381 serge 4480
     mov     [MOUSE_PICTURE],dword mousepointer
1 ha 4481
 
4482
     cli
33 mario79 4483
;     mov     bl,0xa8                 ; enable mouse cmd
4484
;     call    kb_cmd
4485
;     call    kb_read                 ; read status
4486
;     mov     bl,0x20                 ; get command byte
4487
;     call    kb_cmd
4488
;     call    kb_read
4489
;     or      al,3                    ; enable interrupt
4490
;     mov     bl,0x60                 ; write command
4491
;     push    eax
4492
;     call    kb_cmd
4493
;     pop     eax
4494
;     call    kb_write
4495
;     mov     bl,0xd4                 ; for mouse
4496
;     call    kb_cmd
4497
;     mov     al,0xf4                 ; enable mouse device
4498
;     call    kb_write
4499
;     call    kb_read           ; read status return
1 ha 4500
 
4501
     ; com1 mouse enable
4502
 
4503
     mov   bx,0x3f8 ; combase
4504
 
4505
     mov   dx,bx
4506
     add   dx,3
4507
     mov   al,0x80
4508
     out   dx,al
4509
 
4510
     mov   dx,bx
4511
     add   dx,1
4512
     mov   al,0
4513
     out   dx,al
4514
 
4515
     mov   dx,bx
4516
     add   dx,0
429 serge 4517
     mov   al,0x30*2    ; 0x30 / 4
1 ha 4518
     out   dx,al
4519
 
4520
     mov   dx,bx
4521
     add   dx,3
429 serge 4522
     mov   al,2         ; 3
1 ha 4523
     out   dx,al
4524
 
4525
     mov   dx,bx
4526
     add   dx,4
4527
     mov   al,0xb
4528
     out   dx,al
4529
 
4530
     mov   dx,bx
4531
     add   dx,1
4532
     mov   al,1
4533
     out   dx,al
4534
 
4535
 
4536
     ; com2 mouse enable
4537
 
4538
     mov   bx,0x2f8 ; combase
4539
 
4540
     mov   dx,bx
4541
     add   dx,3
4542
     mov   al,0x80
4543
     out   dx,al
4544
 
4545
     mov   dx,bx
4546
     add   dx,1
4547
     mov   al,0
4548
     out   dx,al
4549
 
4550
     mov   dx,bx
4551
     add   dx,0
4552
     mov   al,0x30*2
4553
     out   dx,al
4554
 
4555
     mov   dx,bx
4556
     add   dx,3
4557
     mov   al,2
4558
     out   dx,al
4559
 
4560
     mov   dx,bx
4561
     add   dx,4
4562
     mov   al,0xb
4563
     out   dx,al
4564
 
4565
     mov   dx,bx
4566
     add   dx,1
4567
     mov   al,1
4568
     out   dx,al
4569
 
4570
     ret
4571
 
4572
 
4573
_rdtsc:
164 serge 4574
     bt [cpu_caps], CAPS_TSC
4575
     jnc ret_rdtsc
1 ha 4576
     rdtsc
4577
     ret
4578
   ret_rdtsc:
4579
     mov   edx,0xffffffff
4580
     mov   eax,0xffffffff
4581
     ret
4582
 
4583
rerouteirqs:
4584
 
429 serge 4585
        cli
1 ha 4586
 
429 serge 4587
        mov     al,0x11         ;  icw4, edge triggered
4588
        out     0x20,al
4589
        call    pic_delay
4590
        out     0xA0,al
4591
        call    pic_delay
1 ha 4592
 
429 serge 4593
        mov     al,0x20         ;  generate 0x20 +
4594
        out     0x21,al
4595
        call    pic_delay
4596
        mov     al,0x28         ;  generate 0x28 +
4597
        out     0xA1,al
4598
        call    pic_delay
1 ha 4599
 
429 serge 4600
        mov     al,0x04         ;  slave at irq2
4601
        out     0x21,al
4602
        call    pic_delay
4603
        mov     al,0x02         ;  at irq9
4604
        out     0xA1,al
4605
        call    pic_delay
1 ha 4606
 
429 serge 4607
        mov     al,0x01         ;  8086 mode
4608
        out     0x21,al
4609
        call    pic_delay
4610
        out     0xA1,al
4611
        call    pic_delay
1 ha 4612
 
429 serge 4613
        mov     al,255          ; mask all irq's
4614
        out     0xA1,al
4615
        call    pic_delay
4616
        out     0x21,al
4617
        call    pic_delay
1 ha 4618
 
429 serge 4619
        mov     ecx,0x1000
4620
        cld
4621
picl1:  call    pic_delay
4622
        loop    picl1
1 ha 4623
 
429 serge 4624
        mov     al,255          ; mask all irq's
4625
        out     0xA1,al
4626
        call    pic_delay
4627
        out     0x21,al
4628
        call    pic_delay
1 ha 4629
 
429 serge 4630
        cli
1 ha 4631
 
429 serge 4632
        ret
1 ha 4633
 
4634
 
4635
pic_delay:
4636
 
429 serge 4637
        jmp     pdl1
4638
pdl1:   ret
1 ha 4639
 
4640
 
4641
sys_msg_board_str:
4642
 
4643
     pushad
4644
   @@:
4645
     cmp    [esi],byte 0
4646
     je     @f
4647
     mov    eax,1
4648
     movzx  ebx,byte [esi]
4649
     call   sys_msg_board
4650
     inc    esi
4651
     jmp    @b
4652
   @@:
4653
     popad
4654
     ret
4655
 
4656
uglobal
373 mikedld 4657
  msg_board_data: times 4096 db 0
1 ha 4658
  msg_board_count dd 0x0
4659
endg
4660
 
4661
sys_msg_board:
4662
 
4663
; eax=1 : write :  bl byte to write
4664
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4665
 
4666
     mov  ecx,[msg_board_count]
4667
     cmp  eax, 1
4668
     jne  smbl1
4669
 
4670
 
4671
     mov  [msg_board_data+ecx],bl
4672
     inc  ecx
373 mikedld 4673
     and  ecx, 4095
1 ha 4674
     mov  [msg_board_count], ecx
4675
     mov  [check_idle_semaphore], 5
4676
     ret
4677
   smbl1:
4678
 
4679
     cmp   eax, 2
4680
     jne   smbl2
4681
     test  ecx, ecx
4682
     jz    smbl21
4683
;     mov   edi, msg_board_data
4684
;     mov   esi, msg_board_data+1
4685
;     movzx eax, byte [edi]
4686
     mov   eax, msg_board_data+1
4687
     mov   ebx, msg_board_data
4688
     movzx edx, byte [ebx]
4689
     call  memmove
4690
;     push  ecx
4691
;     shr   ecx, 2
4692
;     cld
4693
;     rep   movsd
4694
;     pop   ecx
4695
;     and   ecx, 3
4696
;     rep   movsb
4697
     dec   [msg_board_count]
4698
     mov   [esp+36], edx ;eax
4699
     mov   [esp+24], dword 1
4700
     ret
4701
   smbl21:
4702
     mov   [esp+36], ecx
4703
     mov   [esp+24], ecx
4704
 
4705
   smbl2:
4706
     ret
4707
 
4708
 
4709
 
4710
sys_process_def:
429 serge 4711
        mov     edi, [CURRENT_TASK]
1 ha 4712
 
429 serge 4713
        dec     eax             ; 1 = set keyboard mode
1 ha 4714
     jne   no_set_keyboard_setup
4715
 
4716
     shl   edi,8
380 serge 4717
     mov   [edi+SLOT_BASE + APPDATA.keyboard_mode],bl
1 ha 4718
 
4719
     ret
4720
 
4721
   no_set_keyboard_setup:
4722
 
429 serge 4723
        dec     eax             ; 2 = get keyboard mode
1 ha 4724
     jne   no_get_keyboard_setup
4725
 
4726
     shl   edi,8
380 serge 4727
     movzx eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
1 ha 4728
 
4729
     mov   [esp+36],eax
4730
 
4731
     ret
4732
 
4733
   no_get_keyboard_setup:
4734
 
429 serge 4735
        dec     eax             ; 3 = get keyboard ctrl, alt, shift
1 ha 4736
     jne   no_get_keyboard_cas
4737
 
4738
;     xor   eax,eax
4739
;     movzx eax,byte [shift]
4740
;     movzx ebx,byte [ctrl]
4741
;     shl   ebx,2
4742
;     add   eax,ebx
4743
;     movzx ebx,byte [alt]
4744
;     shl   ebx,3
4745
;     add   eax,ebx
4746
 
4747
 ;// mike.dld [
4748
     mov   eax, [kb_state]
4749
 ;// mike.dld ]
4750
 
4751
     mov   [esp+36],eax
4752
 
4753
     ret
4754
 
4755
   no_get_keyboard_cas:
4756
 
429 serge 4757
        dec     eax
4758
        jnz     no_add_keyboard_hotkey
1 ha 4759
 
429 serge 4760
        mov     eax, hotkey_list
92 diamond 4761
@@:
429 serge 4762
        cmp     dword [eax+8], 0
4763
        jz      .found_free
4764
        add     eax, 16
4765
        cmp     eax, hotkey_list+16*256
4766
        jb      @b
4767
        mov     dword [esp+36], 1
4768
        ret
92 diamond 4769
.found_free:
429 serge 4770
        mov     [eax+8], edi
4771
        mov     [eax+4], ecx
4772
        movzx   ebx, bl
4773
        lea     ebx, [hotkey_scancodes+ebx*4]
4774
        mov     ecx, [ebx]
4775
        mov     [eax], ecx
4776
        mov     [ebx], eax
4777
        mov     [eax+12], ebx
4778
        jecxz   @f
4779
        mov     [ecx+12], eax
92 diamond 4780
@@:
429 serge 4781
        and     dword [esp+36], 0
4782
        ret
92 diamond 4783
 
4784
no_add_keyboard_hotkey:
4785
 
429 serge 4786
        dec     eax
4787
        jnz     no_del_keyboard_hotkey
92 diamond 4788
 
429 serge 4789
        movzx   ebx, bl
4790
        lea     ebx, [hotkey_scancodes+ebx*4]
4791
        mov     eax, [ebx]
92 diamond 4792
.scan:
429 serge 4793
        test    eax, eax
4794
        jz      .notfound
4795
        cmp     [eax+8], edi
4796
        jnz     .next
4797
        cmp     [eax+4], ecx
4798
        jz      .found
92 diamond 4799
.next:
429 serge 4800
        mov     eax, [eax]
4801
        jmp     .scan
92 diamond 4802
.notfound:
429 serge 4803
        mov     dword [esp+36], 1
4804
        ret
92 diamond 4805
.found:
429 serge 4806
        mov     ecx, [eax]
4807
        jecxz   @f
4808
        mov     edx, [eax+12]
4809
        mov     [ecx+12], edx
92 diamond 4810
@@:
429 serge 4811
        mov     ecx, [eax+12]
4812
        mov     edx, [eax]
4813
        mov     [ecx], edx
4814
        xor     edx, edx
4815
        mov     [eax+4], edx
4816
        mov     [eax+8], edx
4817
        mov     [eax+12], edx
4818
        mov     [eax], edx
4819
        mov     [esp+36], edx
4820
        ret
92 diamond 4821
 
4822
no_del_keyboard_hotkey:
1 ha 4823
     ret
4824
 
4825
 
4826
align 4
4827
 
429 serge 4828
sys_gs:                         ; direct screen access
1 ha 4829
 
429 serge 4830
     cmp  eax,1                 ; resolution
1 ha 4831
     jne  no_gs1
381 serge 4832
     mov  eax,[ScreenWidth]
1 ha 4833
     shl  eax,16
381 serge 4834
     mov  ax,[ScreenHeight]
1 ha 4835
     add  eax,0x00010001
4836
     mov  [esp+36],eax
4837
     ret
4838
   no_gs1:
4839
 
429 serge 4840
     cmp   eax,2                ; bits per pixel
1 ha 4841
     jne   no_gs2
381 serge 4842
     movzx eax,byte [ScreenBPP]
1 ha 4843
     mov   [esp+36],eax
4844
     ret
4845
   no_gs2:
4846
 
429 serge 4847
     cmp   eax,3                ; bytes per scanline
1 ha 4848
     jne   no_gs3
381 serge 4849
     mov   eax,[BytesPerScanLine]
1 ha 4850
     mov   [esp+36],eax
4851
     ret
4852
   no_gs3:
4853
 
4854
     mov  [esp+36],dword -1
4855
     ret
4856
 
4857
 
4858
align 4 ; PCI functions
4859
 
4860
sys_pci:
4861
 
4862
     call  pci_api
4863
     mov   [esp+36],eax
4864
     ret
4865
 
4866
 
4867
align 4  ;  system functions
4868
 
429 serge 4869
syscall_setpixel:                       ; SetPixel
1 ha 4870
 
4871
 
379 serge 4872
     mov   edx,[TASK_BASE]
115 poddubny 4873
     add   eax,[edx-twdw+WDATA.box.left]
4874
     add   ebx,[edx-twdw+WDATA.box.top]
465 serge 4875
        mov     edi,[current_slot]
4876
        add     eax,[edi+APPDATA.wnd_clientbox.left]
4877
        add     ebx,[edi+APPDATA.wnd_clientbox.top]
112 poddubny 4878
     xor   edi,edi ; no force
114 mikedld 4879
;     mov   edi,1
112 poddubny 4880
     call  [disable_mouse]
1 ha 4881
     jmp   [putpixel]
4882
 
4883
align 4
4884
 
429 serge 4885
syscall_writetext:                      ; WriteText
1 ha 4886
 
465 serge 4887
        mov   edi,[TASK_BASE]
4888
        mov   ebp,[edi-twdw+WDATA.box.left]
4889
        push  esi
4890
        mov   esi,[current_slot]
4891
        add   ebp,[esi+APPDATA.wnd_clientbox.left]
4892
        shl   ebp,16
4893
        add   ebp,[edi-twdw+WDATA.box.top]
4894
        add   bp,word[esi+APPDATA.wnd_clientbox.top]
4895
        pop   esi
4896
        add   ecx,[edi+TASKDATA.mem_start]
4897
        add   eax,ebp
4898
        xor   edi,edi
4899
        jmp   dtext
1 ha 4900
 
4901
align 4
4902
 
429 serge 4903
syscall_openramdiskfile:                ; OpenRamdiskFile
1 ha 4904
 
4905
 
379 serge 4906
     mov   edi,[TASK_BASE]
164 serge 4907
     add   edi,TASKDATA.mem_start
1 ha 4908
     add   eax,[edi]
4909
     add   edx,[edi]
4910
     mov   esi,12
4911
     call  fileread
4912
     mov   [esp+36],ebx
4913
     ret
4914
 
4915
align 4
4916
 
429 serge 4917
syscall_drawrect:                       ; DrawRect
1 ha 4918
 
4919
     mov   edi,ecx
52 mikedld 4920
     and   edi,0x80FFFFFF
1 ha 4921
     test  ax,ax
4922
     je    drectr
4923
     test  bx,bx
4924
     je    drectr
4925
     movzx ecx,ax
4926
     shr   eax,16
4927
     movzx edx,bx
4928
     shr   ebx,16
465 serge 4929
        mov     esi,[current_slot]
4930
        add     eax,[esi+APPDATA.wnd_clientbox.left]
4931
        add     ebx,[esi+APPDATA.wnd_clientbox.top]
1 ha 4932
     add   ecx,eax
4933
     add   edx,ebx
4934
     jmp   [drawbar]
4935
    drectr:
4936
     ret
4937
 
4938
align 4
4939
 
429 serge 4940
syscall_getscreensize:                  ; GetScreenSize
1 ha 4941
 
381 serge 4942
     movzx eax,word[ScreenWidth]
1 ha 4943
     shl   eax,16
381 serge 4944
     mov   ax,[ScreenHeight]
1 ha 4945
     mov   [esp+36],eax
4946
     ret
4947
 
4948
align 4
4949
 
429 serge 4950
syscall_cdaudio:                        ; CD
1 ha 4951
 
4952
     call  sys_cd_audio
4953
     mov   [esp+36],eax
4954
     ret
4955
 
4956
align 4
4957
 
429 serge 4958
syscall_delramdiskfile:                 ; DelRamdiskFile
1 ha 4959
 
379 serge 4960
     mov   edi,[TASK_BASE]
164 serge 4961
     add   edi,TASKDATA.mem_start
1 ha 4962
     add   eax,[edi]
4963
     call  filedelete
4964
     mov   [esp+36],eax
4965
     ret
4966
 
4967
align 4
4968
 
429 serge 4969
syscall_writeramdiskfile:               ; WriteRamdiskFile
1 ha 4970
 
379 serge 4971
     mov   edi,[TASK_BASE]
164 serge 4972
     add   edi,TASKDATA.mem_start
1 ha 4973
     add   eax,[edi]
4974
     add   ebx,[edi]
4975
     call  filesave
4976
     mov   [esp+36],eax
4977
     ret
4978
 
4979
align 4
4980
 
429 serge 4981
syscall_getpixel:                       ; GetPixel
381 serge 4982
     mov   ecx,[ScreenWidth]
1 ha 4983
     inc   ecx
4984
     xor   edx,edx
4985
     div   ecx
4986
     mov   ebx,edx
4987
     xchg  eax,ebx
465 serge 4988
     call  dword [GETPIXEL]
1 ha 4989
     mov   [esp+36],ecx
4990
     ret
4991
 
4992
align 4
4993
 
429 serge 4994
syscall_readstring:                     ; ReadString
1 ha 4995
 
379 serge 4996
     mov   edi,[TASK_BASE]
164 serge 4997
     add   edi,TASKDATA.mem_start
1 ha 4998
     add   eax,[edi]
4999
     call  read_string
5000
     mov   [esp+36],eax
5001
     ret
5002
 
5003
align 4
5004
 
429 serge 5005
syscall_drawline:                       ; DrawLine
1 ha 5006
 
379 serge 5007
     mov   edi,[TASK_BASE]
115 poddubny 5008
     movzx edx,word[edi-twdw+WDATA.box.left]
1 ha 5009
     mov   ebp,edx
465 serge 5010
        mov     esi,[current_slot]
5011
        add     ebp,[esi+APPDATA.wnd_clientbox.left]
5012
        add     dx,word[esi+APPDATA.wnd_clientbox.left]
1 ha 5013
     shl   edx,16
5014
     add   ebp,edx
115 poddubny 5015
     movzx edx,word[edi-twdw+WDATA.box.top]
1 ha 5016
     add   eax,ebp
5017
     mov   ebp,edx
465 serge 5018
        add     ebp,[esi+APPDATA.wnd_clientbox.top]
5019
        add     dx,word[esi+APPDATA.wnd_clientbox.top]
1 ha 5020
     shl   edx,16
5021
     xor   edi,edi
5022
     add   edx,ebp
5023
     add   ebx,edx
5024
     jmp   [draw_line]
5025
 
5026
align 4
5027
 
429 serge 5028
syscall_getirqowner:                    ; GetIrqOwner
75 diamond 5029
     cmp   eax,16
5030
     jae   .err
1 ha 5031
     shl   eax,2
5032
     add   eax,irq_owner
5033
     mov   eax,[eax]
5034
     mov   [esp+36],eax
5035
     ret
75 diamond 5036
.err:
5037
     or    dword [esp+36], -1
5038
     ret
1 ha 5039
 
5040
align 4
5041
 
429 serge 5042
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
1 ha 5043
 
5044
     call  r_f_port_area
5045
     mov   [esp+36],eax
5046
     ret
5047
 
5048
align 4
5049
 
429 serge 5050
syscall_threads:                        ; CreateThreads
1 ha 5051
 
5052
     call  sys_threads
5053
     mov   [esp+36],eax
5054
     ret
5055
 
5056
align 4
5057
 
5058
stack_driver_stat:
5059
 
429 serge 5060
     call  app_stack_handler            ; Stack status
1 ha 5061
 
5062
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5063
;     call  change_task                 ; between sent packet
5064
 
5065
     mov   [esp+36],eax
5066
     ret
5067
 
5068
align 4
5069
 
429 serge 5070
socket:                                 ; Socket interface
1 ha 5071
     call  app_socket_handler
5072
 
5073
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
5074
;     call  change_task                 ; between sent packet
5075
 
5076
     mov   [esp+36],eax
5077
     mov   [esp+24],ebx
5078
     ret
5079
 
5080
align 4
5081
 
429 serge 5082
user_events:                            ; User event times
1 ha 5083
 
5084
     mov   eax,0x12345678
5085
     mov   [esp+36],eax
5086
 
5087
     ret
5088
 
5089
align 4
5090
 
429 serge 5091
read_from_hd:                           ; Read from hd - fn not in use
1 ha 5092
 
379 serge 5093
     mov   edi,[TASK_BASE]
115 poddubny 5094
     add   edi,TASKDATA.mem_start
1 ha 5095
     add   eax,[edi]
5096
     add   ecx,[edi]
5097
     add   edx,[edi]
5098
     call  file_read
5099
 
5100
     mov   [esp+36],eax
5101
     mov   [esp+24],ebx
5102
 
5103
     ret
5104
 
375 Ghost 5105
align 4
5106
paleholder:
5107
	ret
378 serge 5108
 
76 mario79 5109
; --------------- APM ---------------------
5110
apm_entry    dp    0
429 serge 5111
apm_vf        dd    0
1 ha 5112
align 4
76 mario79 5113
sys_apm:
5114
    cmp    word [apm_vf], 0    ; Check APM BIOS enable
5115
    jne    @f
429 serge 5116
    or    [esp + 56], byte 1    ; error
5117
    mov    [esp + 36], dword 8    ; 32-bit protected-mode interface not supported
76 mario79 5118
    ret
164 serge 5119
 
465 serge 5120
@@:
5121
    xchg    eax, ecx
76 mario79 5122
    xchg    ebx, ecx
164 serge 5123
 
76 mario79 5124
    cmp    al, 3
429 serge 5125
    ja    @f
78 diamond 5126
    and    [esp + 56], byte 0xfe    ; emulate func 0..3 as func 0
76 mario79 5127
    mov    eax, [apm_vf]
5128
    mov    [esp + 36], eax
5129
    shr    eax, 16
5130
    mov    [esp + 32], eax
5131
    ret
78 diamond 5132
 
465 serge 5133
@@:
5134
 
5135
    mov esi, [master_tab+(OS_BASE shr 20)]
5136
    xchg [master_tab], esi
5137
    push esi
5138
    mov edi, cr3
5139
    mov cr3, edi                 ;flush TLB
5140
 
5141
    call    pword [apm_entry]    ; call APM BIOS
5142
 
5143
    xchg eax, [esp]
5144
    mov [master_tab], eax
5145
    mov eax, cr3
5146
    mov cr3, eax
5147
    pop eax
5148
 
76 mario79 5149
    mov    [esp + 8 ], edi
5150
    mov    [esp + 12], esi
5151
    mov    [esp + 24], ebx
5152
    mov    [esp + 28], edx
5153
    mov    [esp + 32], ecx
5154
    mov    [esp + 36], eax
5155
    setc    al
78 diamond 5156
    and    [esp + 56], byte 0xfe
429 serge 5157
    or    [esp + 56], al
465 serge 5158
 
5159
 
76 mario79 5160
    ret
5161
; -----------------------------------------
1 ha 5162
 
76 mario79 5163
align 4
5164
 
429 serge 5165
undefined_syscall:                      ; Undefined system call
1 ha 5166
 
5167
     mov   [esp+36],dword -1
5168
     ret
5169
 
465 serge 5170
align 4
5171
system_shutdown:          ; shut down the system
1 ha 5172
 
465 serge 5173
           cmp byte [BOOT_VAR+0x9030], 1
5174
           jne @F
5175
           ret
5176
@@:
5177
           call stop_all_services
5178
           push 3                ; stop playing cd
5179
           pop  eax
5180
           call sys_cd_audio
1 ha 5181
 
465 serge 5182
yes_shutdown_param:
5183
           cli
1 ha 5184
 
465 serge 5185
           mov  eax, kernel_file ; load kernel.mnt to 0x8000:0
5186
           push 12
5187
           pop  esi
5188
           xor  ebx,ebx
5189
           or   ecx,-1
5190
           mov  edx, OS_BASE+0x80000
5191
           call fileread
1 ha 5192
 
465 serge 5193
           mov  esi, restart_kernel_4000+OS_BASE+0x10000 ; move kernel re-starter to 0x4000:0
5194
           mov  edi,OS_BASE+0x40000
5195
           mov  ecx,1000
5196
           rep  movsb
1 ha 5197
 
465 serge 5198
           mov  esi,OS_BASE+0x2F0000    ; restore 0x0 - 0xffff
5199
           mov  edi, OS_BASE
5200
           mov  ecx,0x10000/4
5201
           cld
5202
           rep movsd
1 ha 5203
 
465 serge 5204
           call restorefatchain
1 ha 5205
 
465 serge 5206
           mov al, 0xFF
5207
           out 0x21, al
5208
           out 0xA1, al
1 ha 5209
 
465 serge 5210
           mov  word [OS_BASE+0x467+0],pr_mode_exit
5211
           mov  word [OS_BASE+0x467+2],0x1000
1 ha 5212
 
465 serge 5213
           mov  al,0x0F
5214
           out  0x70,al
5215
           mov  al,0x05
5216
           out  0x71,al
1 ha 5217
 
465 serge 5218
           mov  al,0xFE
5219
           out  0x64,al
5220
           hlt
1 ha 5221
 
5222
 
465 serge 5223
include "data32.inc"
1 ha 5224
 
465 serge 5225
__REV__ = __REV
1 ha 5226
 
5227
uglobals_size = $ - endofcode
41 mikedld 5228
diff16 "end of kernel code",0,$
426 mikedld 5229