Subversion Repositories Kolibri OS

Rev

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

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