Subversion Repositories Kolibri OS

Rev

Rev 712 | Rev 740 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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