Subversion Repositories Kolibri OS

Rev

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