Subversion Repositories Kolibri OS

Rev

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