Subversion Repositories Kolibri OS

Rev

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