Subversion Repositories Kolibri OS

Rev

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