Subversion Repositories Kolibri OS

Rev

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