Subversion Repositories Kolibri OS

Rev

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