Subversion Repositories Kolibri OS

Rev

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