Subversion Repositories Kolibri OS

Rev

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