Subversion Repositories Kolibri OS

Rev

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

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