Subversion Repositories Kolibri OS

Rev

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