Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1 ha 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;
431 serge 3
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved.
4
;; PROGRAMMING:
5
;; Ivan Poddubny
6
;; Marat Zakiyanov (Mario79)
7
;; VaStaNi
8
;; Trans
9
;; Mihail Semenyako (mike.dld)
10
;; Sergey Kuzmin (Wildwest)
11
;; Andrey Halyavin (halyavin)
12
;; Mihail Lisovin (Mihasik)
13
;; Andrey Ignatiev (andrew_programmer)
14
;; NoName
15
;; Evgeny Grechnikov (Diamond)
16
;; Iliya Mihailov (Ghost)
17
;; Sergey Semyonov (Serge)
18
;; Johnny_B
543 spraid 19
;; SPraid (simba)
1 ha 20
;;
431 serge 21
;; Data in this file was originally part of MenuetOS project which is
22
;; distributed under the terms of GNU GPL. It is modified and redistributed as
23
;; part of KolibriOS project under the terms of GNU GPL.
1 ha 24
;;
431 serge 25
;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa
26
;; PROGRAMMING:
1 ha 27
;;
431 serge 28
;; Ville Mikael Turjanmaa, villemt@itu.jyu.fi
29
;; - main os coding/design
30
;; Jan-Michael Brummer, BUZZ2@gmx.de
31
;; Felix Kaiser, info@felix-kaiser.de
32
;; Paolo Minazzi, paolo.minazzi@inwind.it
33
;; quickcode@mail.ru
34
;; Alexey, kgaz@crosswinds.net
35
;; Juan M. Caravaca, bitrider@wanadoo.es
36
;; kristol@nic.fi
37
;; Mike Hibbett, mikeh@oceanfree.net
38
;; Lasse Kuusijarvi, kuusijar@lut.fi
39
;; Jarek Pelczar, jarekp3@wp.pl
1 ha 40
;;
431 serge 41
;; KolibriOS is distributed in the hope that it will be useful, but WITHOUT ANY
42
;; WARRANTY. No author or distributor accepts responsibility to anyone for the
43
;; consequences of using it or for whether it serves any particular purpose or
44
;; works at all, unless he says so in writing. Refer to the GNU General Public
45
;; License (the "GPL") for full details.
46
;
47
;; Everyone is granted permission to copy, modify and redistribute KolibriOS,
48
;; but only under the conditions described in the GPL. A copy of this license
49
;; is supposed to have been given to you along with KolibriOS so you can know
50
;; your rights and responsibilities. It should be in a file named COPYING.
51
;; Among other things, the copyright notice and this notice must be preserved
52
;; on all copies.
53
;;
1 ha 54
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
426 mikedld 55
 
56
include 'macros.inc'
57
 
425 victor 58
$Revision: 543 $
426 mikedld 59
 
164 serge 60
include "proc32.inc"
7 me_root 61
include "kglobals.inc"
1 ha 62
include "lang.inc"
63
 
164 serge 64
include "const.inc"
465 serge 65
max_processes    equ   255
66
tss_step         equ   (128+8192) ; tss & i/o - 65535 ports, * 256=557056*4
1 ha 67
 
164 serge 68
 
465 serge 69
os_stack       equ  (os_data_l-gdts)    ; GDTs
70
os_code        equ  (os_code_l-gdts)
71
graph_data     equ  (3+graph_data_l-gdts)
72
tss0           equ  (tss0_l-gdts)
73
app_code       equ  (3+app_code_l-gdts)
74
app_data       equ  (3+app_data_l-gdts)
1 ha 75
 
76
 
77
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
78
;;
79
;;   Included files:
80
;;
81
;;   Kernel16.inc
82
;;    - Booteng.inc   English text for bootup
83
;;    - Bootcode.inc  Hardware setup
84
;;    - Pci16.inc     PCI functions
85
;;
86
;;   Kernel32.inc
87
;;    - Sys32.inc     Process management
88
;;    - Shutdown.inc  Shutdown and restart
89
;;    - Fat32.inc     Read / write hd
90
;;    - Vesa12.inc    Vesa 1.2 driver
91
;;    - Vesa20.inc    Vesa 2.0 driver
92
;;    - Vga.inc       VGA driver
93
;;    - Stack.inc     Network interface
94
;;    - Mouse.inc     Mouse pointer
95
;;    - Scincode.inc  Window skinning
96
;;    - Pci32.inc     PCI functions
97
;;
98
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
99
 
100
 
101
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
102
;;                                                                      ;;
103
;;                  16 BIT ENTRY FROM BOOTSECTOR                        ;;
104
;;                                                                      ;;
105
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
106
 
107
use16
429 serge 108
                  org   0x0
109
                  jmp   start_of_code
1 ha 110
 
536 diamond 111
version db    'Kolibri OS  version 0.7.0.0      ',13,10,13,10,0
1 ha 112
 
465 serge 113
include "boot/bootstr.inc"     ; language-independent boot messages
1 ha 114
include "boot/preboot.inc"
115
 
465 serge 116
if lang eq en
117
include "boot/booteng.inc"     ; english system boot messages
118
else if lang eq ru
119
include "boot/bootru.inc"      ; russian system boot messages
120
include "boot/ru.inc"          ; Russian font
121
else if lang eq et
122
include "boot/bootet.inc"      ; estonian system boot messages
123
include "boot/et.inc"          ; Estonian font
124
else
125
include "boot/bootge.inc"      ; german system boot messages
126
end if
1 ha 127
 
465 serge 128
include "boot/bootcode.inc"    ; 16 bit system boot code
129
include "bus/pci/pci16.inc"
1 ha 130
 
131
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
132
;;                                                                      ;;
133
;;                  SWITCH TO 32 BIT PROTECTED MODE                     ;;
134
;;                                                                      ;;
135
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
136
 
137
 
138
; CR0 Flags - Protected mode and Paging
139
 
429 serge 140
        mov ecx, CR0_PE
1 ha 141
 
142
; Enabling 32 bit protected mode
143
 
465 serge 144
        sidt    [cs:old_ints_h]
1 ha 145
 
429 serge 146
        cli                             ; disable all irqs
147
        cld
148
        mov     al,255                  ; mask all irqs
149
        out     0xa1,al
150
        out     0x21,al
151
   l.5: in      al, 0x64                ; Enable A20
152
        test    al, 2
153
        jnz     l.5
154
        mov     al, 0xD1
155
        out     0x64, al
156
   l.6: in      al, 0x64
157
        test    al, 2
158
        jnz     l.6
159
        mov     al, 0xDF
160
        out     0x60, al
161
   l.7: in      al, 0x64
162
        test    al, 2
163
        jnz     l.7
164
        mov     al, 0xFF
165
        out     0x64, al
465 serge 166
 
167
        lgdt    [cs:tmp_gdt]            ; Load GDT
168
        mov     eax, cr0                ; protected mode
429 serge 169
        or      eax, ecx
170
        and     eax, 10011111b *65536*256 + 0xffffff ; caching enabled
171
        mov     cr0, eax
172
        jmp     pword os_code:B32       ; jmp to enable 32 bit mode
1 ha 173
 
465 serge 174
align 8
175
tmp_gdt:
1 ha 176
 
465 serge 177
        dw     23
178
        dd     tmp_gdt+0x10000
179
        dw     0
183 diamond 180
 
465 serge 181
        dw     0xffff
182
        dw     0x0000
183
        db     0x00
184
        dw     11011111b *256 +10011010b
185
        db     0x00
375 Ghost 186
 
465 serge 187
        dw     0xffff
188
        dw     0x0000
189
        db     0x00
190
        dw     11011111b *256 +10010010b
191
        db     0x00
1 ha 192
 
465 serge 193
include "data16.inc"
1 ha 194
 
465 serge 195
use32
196
org $+0x10000
1 ha 197
 
465 serge 198
align 4
199
B32:
200
           mov   ax,os_stack       ; Selector for os
201
           mov   ds,ax
202
           mov   es,ax
203
           mov   fs,ax
204
           mov   gs,ax
205
           mov   ss,ax
206
           mov   esp,0x3ec00       ; Set stack
1 ha 207
 
465 serge 208
; CLEAR 0x280000 - HEAP_BASE
1 ha 209
 
465 serge 210
           xor   eax,eax
211
           mov   edi,0x280000
212
           mov   ecx,(HEAP_BASE-OS_BASE-0x280000) / 4
213
           cld
214
           rep   stosd
1 ha 215
 
465 serge 216
           mov   edi,0x40000
217
           mov   ecx,(0x90000-0x40000)/4
218
           rep   stosd
1 ha 219
 
465 serge 220
; CLEAR KERNEL UNDEFINED GLOBALS
221
           mov   edi, endofcode-OS_BASE
222
           mov   ecx, (uglobals_size/4)+4
223
           rep   stosd
1 ha 224
 
465 serge 225
; SAVE & CLEAR 0-0xffff
1 ha 226
 
465 serge 227
           xor esi, esi
228
           mov   edi,0x2F0000
229
           mov   ecx,0x10000 / 4
230
           rep   movsd
231
           xor edi, edi
232
           mov   ecx,0x10000 / 4
233
           rep   stosd
429 serge 234
 
465 serge 235
           call test_cpu
236
           bts [cpu_caps-OS_BASE], CAPS_TSC     ;force use rdtsc
424 spraid 237
 
465 serge 238
; MEMORY MODEL
239
           call mem_test
240
           call init_mem
241
           call init_page_map
1 ha 242
 
465 serge 243
; ENABLE PAGING
1 ha 244
 
465 serge 245
           mov eax, sys_pgdir-OS_BASE
246
           mov cr3, eax
1 ha 247
 
465 serge 248
           mov eax,cr0
249
           or eax,CR0_PG+CR0_WP
250
           mov cr0,eax
1 ha 251
 
465 serge 252
           lgdt [gdts]
253
           jmp pword os_code:high_code
1 ha 254
 
513 serge 255
align 4
256
tmp_page_tabs   dd ?
498 diamond 257
use16
258
org $-0x10000
259
include "boot/shutdown.inc" ; shutdown or restart
260
org $+0x10000
261
use32
262
 
465 serge 263
__DEBUG__ fix 1
264
__DEBUG_LEVEL__ fix 1
265
include 'init.inc'
380 serge 266
 
465 serge 267
org OS_BASE+$
1 ha 268
 
465 serge 269
align 4
270
high_code:
519 serge 271
           mov ax,os_stack
272
           mov bx,app_data
273
           mov ss,ax
274
           add  esp, OS_BASE
1 ha 275
 
519 serge 276
           mov ds,bx
277
           mov es,bx
278
           mov fs,bx
279
           mov gs,bx
1 ha 280
 
519 serge 281
           bt [cpu_caps], CAPS_PGE
282
           jnc @F
1 ha 283
 
519 serge 284
           or dword [sys_pgdir+(OS_BASE shr 20)], PG_GLOBAL
285
 
286
           mov ebx, cr4
287
           or ebx, CR4_PGE
288
           mov cr4, ebx
289
@@:
290
           xor eax, eax
291
           mov dword [sys_pgdir], eax
292
           mov dword [sys_pgdir+4], eax
293
 
465 serge 294
           mov eax, cr3
295
           mov cr3, eax           ; flush TLB
296
 
1 ha 297
; SAVE REAL MODE VARIABLES
465 serge 298
        mov     ax, [BOOT_VAR + 0x9031]
429 serge 299
        mov     [IDEContrRegsBaseAddr], ax
76 mario79 300
; --------------- APM ---------------------
465 serge 301
 
302
; init selectors
303
    mov ebx,    [BOOT_VAR+0x9040]              ; offset of APM entry point
304
    movzx eax, word [BOOT_VAR+0x9050] ; real-mode segment base address of
305
                                      ; protected-mode 32-bit code segment
306
    movzx ecx, word [BOOT_VAR+0x9052] ; real-mode segment base address of
307
                                      ; protected-mode 16-bit code segment
308
    movzx edx, word [BOOT_VAR+0x9054] ; real-mode segment base address of
309
                                      ; protected-mode 16-bit data segment
310
 
311
    shl    eax, 4
312
    mov    [dword apm_code_32 + 2], ax
313
    shr    eax, 16
314
    mov    [dword apm_code_32 + 4], al
315
 
316
    shl    ecx, 4
317
    mov    [dword apm_code_16 + 2], cx
318
    shr    ecx, 16
319
    mov    [dword apm_code_16 + 4], cl
320
 
321
    shl    edx, 4
322
    mov    [dword apm_data_16 + 2], dx
323
    shr    edx, 16
324
    mov    [dword apm_data_16 + 4], dl
325
 
326
    mov    dword[apm_entry], ebx
76 mario79 327
    mov    word [apm_entry + 4], apm_code_32 - gdts
328
 
465 serge 329
    mov    eax, [BOOT_VAR + 0x9044]    ; version & flags
76 mario79 330
    mov    [apm_vf], eax
331
; -----------------------------------------
465 serge 332
;        movzx eax,byte [BOOT_VAR+0x9010]  ; mouse port
1 ha 333
;        mov   [0xF604],byte 1  ;al
514 diamond 334
        mov     al, [BOOT_VAR+0x901F]   ; DMA access
335
        mov     [allow_dma_access], al
465 serge 336
        mov   al,[BOOT_VAR+0x9000]        ; bpp
429 serge 337
        mov   [ScreenBPP],al
465 serge 338
        movzx eax,word [BOOT_VAR+0x900A]  ; X max
429 serge 339
        dec   eax
340
        mov   [ScreenWidth],eax
341
        mov   [screen_workarea.right],eax
465 serge 342
        movzx eax,word [BOOT_VAR+0x900C]  ; Y max
429 serge 343
        dec   eax
344
        mov   [ScreenHeight],eax
345
        mov   [screen_workarea.bottom],eax
465 serge 346
        movzx eax,word [BOOT_VAR+0x9008]  ; screen mode
429 serge 347
        mov   [SCR_MODE],eax
465 serge 348
        mov   eax,[BOOT_VAR+0x9014]       ; Vesa 1.2 bnk sw add
429 serge 349
        mov   [BANK_SWITCH],eax
350
        mov   [BytesPerScanLine],word 640*4         ; Bytes PerScanLine
351
        cmp   [SCR_MODE],word 0x13          ; 320x200
352
        je    @f
353
        cmp   [SCR_MODE],word 0x12          ; VGA 640x480
354
        je    @f
465 serge 355
        mov   ax,[BOOT_VAR+0x9001]        ; for other modes
429 serge 356
        mov   [BytesPerScanLine],ax
465 serge 357
@@:
1 ha 358
 
359
; GRAPHICS ADDRESSES
360
 
465 serge 361
        mov     byte [BOOT_VAR+0x901e],0x0
362
        mov     eax,[BOOT_VAR+0x9018]
429 serge 363
        mov     [LFBAddress],eax
1 ha 364
 
429 serge 365
        cmp     [SCR_MODE],word 0100000000000000b
366
        jge     setvesa20
367
        cmp     [SCR_MODE],word 0x13
368
        je      v20ga32
369
        mov     [PUTPIXEL],dword Vesa12_putpixel24  ; Vesa 1.2
465 serge 370
        mov     [GETPIXEL],dword Vesa12_getpixel24
429 serge 371
        cmp     [ScreenBPP],byte 24
372
        jz      ga24
373
        mov     [PUTPIXEL],dword Vesa12_putpixel32
465 serge 374
        mov     [GETPIXEL],dword Vesa12_getpixel32
1 ha 375
      ga24:
429 serge 376
        jmp     v20ga24
1 ha 377
      setvesa20:
429 serge 378
        mov     [PUTPIXEL],dword Vesa20_putpixel24  ; Vesa 2.0
465 serge 379
        mov     [GETPIXEL],dword Vesa20_getpixel24
429 serge 380
        cmp     [ScreenBPP],byte 24
381
        jz      v20ga24
1 ha 382
      v20ga32:
429 serge 383
        mov     [PUTPIXEL],dword Vesa20_putpixel32
465 serge 384
        mov     [GETPIXEL],dword Vesa20_getpixel32
1 ha 385
      v20ga24:
429 serge 386
        cmp     [SCR_MODE],word 0x12                ; 16 C VGA 640x480
387
        jne     no_mode_0x12
388
        mov     [PUTPIXEL],dword VGA_putpixel
465 serge 389
        mov     [GETPIXEL],dword Vesa20_getpixel32
1 ha 390
      no_mode_0x12:
391
 
375 Ghost 392
; -------- Fast System Call init ----------
378 serge 393
; Intel SYSENTER/SYSEXIT (AMD CPU support it too)
429 serge 394
           bt [cpu_caps], CAPS_SEP
395
           jnc .SEnP   ; SysEnter not Present
396
           xor edx, edx
397
           mov ecx, MSR_SYSENTER_CS
398
           mov eax, os_code
399
           wrmsr
400
           mov ecx, MSR_SYSENTER_ESP
434 diamond 401
;           mov eax, sysenter_stack ; Check it
402
           xor     eax, eax
429 serge 403
           wrmsr
404
           mov ecx, MSR_SYSENTER_EIP
405
           mov eax, sysenter_entry
406
           wrmsr
375 Ghost 407
.SEnP:
378 serge 408
; AMD SYSCALL/SYSRET
429 serge 409
           cmp byte[cpu_vendor], 'A'
410
           jne .noSYSCALL
411
           mov eax, 0x80000001
412
           cpuid
413
           test edx, 0x800  ; bit_11 - SYSCALL/SYSRET support
414
           jz .noSYSCALL
415
           mov ecx, MSR_AMD_EFER
416
           rdmsr
417
           or eax, 1   ; bit_0 - System Call Extension (SCE)
418
           wrmsr
164 serge 419
 
375 Ghost 420
	; !!!! It`s dirty hack, fix it !!!
421
	; Bits of EDX :
422
	; Bit 31–16 During the SYSRET instruction, this field is copied into the CS register
423
	;  and the contents of this field, plus 8, are copied into the SS register.
424
	; Bit 15–0 During the SYSCALL instruction, this field is copied into the CS register
425
	;  and the contents of this field, plus 8, are copied into the SS register.
426
 
429 serge 427
	; mov	edx, (os_code + 16) * 65536 + os_code
465 serge 428
           mov edx, 0x1B0008
375 Ghost 429
 
429 serge 430
           mov eax, syscall_entry
431
           mov ecx, MSR_AMD_STAR
432
           wrmsr
375 Ghost 433
.noSYSCALL:
434
; -----------------------------------------
435
 
465 serge 436
; LOAD IDT
378 serge 437
 
465 serge 438
           call build_interrupt_table
439
           lidt [idtreg]
378 serge 440
 
465 serge 441
           call init_kernel_heap
442
           stdcall kernel_alloc, RING0_STACK_SIZE+512
443
           mov [os_stack_seg], eax
164 serge 444
 
465 serge 445
           lea esp, [eax+RING0_STACK_SIZE]
164 serge 446
 
465 serge 447
           mov [tss._ss0], os_stack
448
           mov [tss._esp0], esp
449
           mov [tss._esp], esp
450
           mov [tss._cs],os_code
451
           mov [tss._ss],os_stack
452
           mov [tss._ds],app_data
453
           mov [tss._es],app_data
454
           mov [tss._fs],app_data
455
           mov [tss._gs],app_data
456
           mov [tss._io],128
457
;Add IO access table - bit array of permitted ports
458
           mov edi, tss._io_map_0
459
           xor eax, eax
460
           not eax
461
           mov ecx, 8192/4
462
           rep stosd                 ; access to 4096*8=65536 ports
164 serge 463
 
465 serge 464
           mov  ax,tss0
465
           ltr  ax
378 serge 466
 
465 serge 467
           mov [LFBSize], 0x800000
429 serge 468
           call init_LFB
469
           call init_fpu
470
           call init_malloc
276 serge 471
 
465 serge 472
           stdcall alloc_kernel_space, 0x51000
473
           mov [default_io_map], eax
474
 
475
           add eax, 0x2000
429 serge 476
           mov [ipc_tmp], eax
477
           mov ebx, 0x1000
164 serge 478
 
429 serge 479
           add eax, 0x40000
480
           mov [proc_mem_map], eax
164 serge 481
 
429 serge 482
           add eax, 0x8000
483
           mov [proc_mem_pdir], eax
164 serge 484
 
429 serge 485
           add eax, ebx
486
           mov [proc_mem_tab], eax
164 serge 487
 
429 serge 488
           add eax, ebx
489
           mov [tmp_task_pdir], eax
164 serge 490
 
429 serge 491
           add eax, ebx
492
           mov [tmp_task_ptab], eax
164 serge 493
 
429 serge 494
           add eax, ebx
495
           mov [ipc_pdir], eax
164 serge 496
 
429 serge 497
           add eax, ebx
498
           mov [ipc_ptab], eax
164 serge 499
 
429 serge 500
           call init_events
501
           mov eax, srv.fd-SRV_FD_OFFSET
502
           mov [srv.fd], eax
503
           mov [srv.bk], eax
278 serge 504
 
429 serge 505
           mov edi, irq_tab
506
           xor eax, eax
507
           mov ecx, 16
508
           rep stosd
164 serge 509
 
41 mikedld 510
;Set base of graphic segment to linear address of LFB
429 serge 511
        mov     eax,[LFBAddress]          ; set for gs
512
        mov     [graph_data_l+2],ax
513
        shr     eax,16
514
        mov     [graph_data_l+4],al
515
        mov     [graph_data_l+7],ah
1 ha 516
 
465 serge 517
        mov [CURRENT_TASK],dword 1
518
        mov [TASK_COUNT],dword 1
519
        mov [TASK_BASE],dword TASK_DATA
520
        mov [current_slot], SLOT_BASE+256
429 serge 521
 
469 serge 522
; set background
523
        xor  eax,eax
524
        inc  eax
527 diamond 525
        mov   [BgrDrawMode],eax
526
        mov   [BgrDataWidth],eax
527
        mov   [BgrDataHeight],eax
469 serge 528
        mov    [mem_BACKGROUND],4095
529
        stdcall kernel_alloc, [mem_BACKGROUND]
530
        mov [img_background], eax
531
 
532
 
256 diamond 533
;!!!!!!!!!!!!!!!!!!!!!!!!!!
534
include 'detect/disks.inc'
535
;!!!!!!!!!!!!!!!!!!!!!!!!!!
536
 
521 diamond 537
  call Parser_params
538
 
1 ha 539
; READ RAMDISK IMAGE FROM HD
540
 
541
;!!!!!!!!!!!!!!!!!!!!!!!
542
include 'boot/rdload.inc'
543
;!!!!!!!!!!!!!!!!!!!!!!!
544
;    mov    [dma_hdd],1
545
; CALCULATE FAT CHAIN FOR RAMDISK
546
 
429 serge 547
        call  calculatefatchain
1 ha 548
 
549
; LOAD VMODE DRIVER
550
 
551
;!!!!!!!!!!!!!!!!!!!!!!!
552
include 'vmodeld.inc'
553
;!!!!!!!!!!!!!!!!!!!!!!!
554
 
509 diamond 555
  mov ax,[OS_BASE+0x10000+bx_from_load]
535 spraid 556
  cmp ax,'r1'		; if using not ram disk, then load librares and parameters {SPraid.simba}
488 spraid 557
  je  no_lib_load
558
; LOADING LIBRARES
535 spraid 559
   stdcall dll.Load,@IMPORT				; loading librares for kernel (.obj files)
512 spraid 560
   call load_file_parse_table			; prepare file parse table
498 diamond 561
   call set_kernel_conf					; configure devices and gui
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]
535 spraid 766
  cmp ax,'r1'		; if not rused ram disk - load network configuration from files {SPraid.simba}
512 spraid 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]
538 spraid 861
        mov [timer_ticks_enable],1		; for cd driver
1 ha 862
 
465 serge 863
;        stdcall init_uart_service, DRV_ENTRY
864
 
429 serge 865
        sti
465 serge 866
        call change_task
867
 
868
        jmp osloop
869
 
429 serge 870
        jmp   $                      ; wait here for timer to take control
1 ha 871
 
429 serge 872
        ; Fly :)
1 ha 873
 
465 serge 874
include 'unpacker.inc'
875
include 'fdo.inc'
876
 
877
align 4
878
boot_log:
879
         pushad
880
 
881
         mov   eax,10*65536
882
         mov   ax,word [boot_y]
883
         add   [boot_y],dword 10
884
         mov   ebx,0x80ffffff   ; ASCIIZ string with white color
885
         mov   ecx,esi
886
         mov   edi,1
887
         call  dtext
888
 
889
         mov   [novesachecksum],1000
890
         call  checkVga_N13
891
 
892
         cmp   [preboot_blogesc+OS_BASE+0x10000],byte 1
893
         je    .bll2
894
 
895
         cmp   esi,boot_tasking
896
         jne   .bll2
897
         ; begin ealex 04.08.05
898
;         in    al,0x61
899
;         and   al,01111111b
900
;         out   0x61,al
901
         ; end ealex 04.08.05
902
.bll1:   in    al,0x60    ; wait for ESC key press
903
         cmp   al,129
904
         jne   .bll1
905
 
906
.bll2:   popad
907
 
908
         ret
909
 
910
 
1 ha 911
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
912
;                                                                    ;
33 mario79 913
;                    MAIN OS LOOP START                              ;
1 ha 914
;                                                                    ;
915
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
916
align 32
917
osloop:
429 serge 918
        call   [draw_pointer]
919
        call   checkbuttons
920
        call   checkwindows
49 mikedld 921
;       call   check_window_move_request
429 serge 922
        call   checkmisc
923
        call   checkVga_N13
924
        call   stack_handler
925
        call   checkidle
926
        call   check_fdd_motor_status
927
        jmp    osloop
33 mario79 928
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
929
;                                                                    ;
930
;                      MAIN OS LOOP END                              ;
931
;                                                                    ;
932
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1 ha 933
 
934
checkidle:
429 serge 935
        pushad
1 ha 936
 
429 serge 937
        cmp  [check_idle_semaphore],0
938
        jne  no_idle_state
1 ha 939
 
429 serge 940
        call change_task
941
        mov  eax,[idlemem]
942
        mov  ebx,[timer_ticks] ;[0xfdf0]
943
        cmp  eax,ebx
944
        jnz  idle_exit
945
        call _rdtsc
946
        mov  ecx,eax
1 ha 947
      idle_loop:
429 serge 948
        hlt
949
        cmp  [check_idle_semaphore],0
950
        jne  idle_loop_exit
951
        mov  eax,[timer_ticks] ;[0xfdf0]
952
        cmp  ebx,eax
953
        jz   idle_loop
1 ha 954
      idle_loop_exit:
429 serge 955
        mov  [idlemem],eax
956
        call _rdtsc
957
        sub  eax,ecx
958
        mov  ebx,[idleuse]
959
        add  ebx,eax
960
        mov  [idleuse],ebx
1 ha 961
 
429 serge 962
        popad
963
        ret
1 ha 964
 
965
      idle_exit:
966
 
429 serge 967
        mov  ebx,[timer_ticks] ;[0xfdf0]
968
        mov  [idlemem],ebx
969
        call change_task
1 ha 970
 
429 serge 971
        popad
972
        ret
1 ha 973
 
974
      no_idle_state:
975
 
429 serge 976
        dec  [check_idle_semaphore]
1 ha 977
 
429 serge 978
        mov  ebx,[timer_ticks] ;[0xfdf0]
979
        mov  [idlemem],ebx
980
        call change_task
1 ha 981
 
429 serge 982
        popad
983
        ret
1 ha 984
 
985
uglobal
429 serge 986
  idlemem               dd   0x0
987
  idleuse               dd   0x0
988
  idleusesec            dd   0x0
989
  check_idle_semaphore  dd   0x0
1 ha 990
endg
991
 
992
 
993
 
994
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
995
;                                                                      ;
996
;                   INCLUDED SYSTEM FILES                              ;
997
;                                                                      ;
998
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
999
 
1000
 
7 me_root 1001
include "kernel32.inc"
1 ha 1002
 
1003
 
1004
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1005
;                                                                      ;
1006
;                       KERNEL FUNCTIONS                               ;
1007
;                                                                      ;
1008
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1009
 
1010
reserve_irqs_ports:
1011
 
429 serge 1012
        pushad
1 ha 1013
 
465 serge 1014
        mov  [irq_owner+4*0], 1    ; timer
1015
        mov  [irq_owner+4*1], 1    ; keyboard
1016
        mov  [irq_owner+4*5], 1    ; sound blaster
1017
        mov  [irq_owner+4*6], 1    ; floppy diskette
1018
        mov  [irq_owner+4*13], 1   ; math co-pros
1019
        mov  [irq_owner+4*14], 1   ; ide I
1020
        mov  [irq_owner+4*15], 1   ; ide II
1021
 
58 mario79 1022
;        movzx eax,byte [0xf604]        ; mouse irq
1023
;        dec   eax
1024
;        add   eax,mouseirqtable
1025
;        movzx eax,byte [eax]
1026
;        shl   eax,2
1027
;        mov   [irq_owner+eax],byte 1
1 ha 1028
 
1029
 
429 serge 1030
                                       ; RESERVE PORTS
1031
        mov   edi,1                    ; 0x00-0x2d
1032
        mov   [RESERVED_PORTS],edi
1033
        shl   edi,4
1034
        mov   [RESERVED_PORTS+edi+0],dword 1
1035
        mov   [RESERVED_PORTS+edi+4],dword 0x0
1036
        mov   [RESERVED_PORTS+edi+8],dword 0x2d
269 serge 1037
 
429 serge 1038
        inc   dword [RESERVED_PORTS]          ; 0x30-0x4d
1039
        mov   edi,[RESERVED_PORTS]
1040
        shl   edi,4
1041
        mov   [RESERVED_PORTS+edi+0],dword 1
1042
        mov   [RESERVED_PORTS+edi+4],dword 0x30
1043
        mov   [RESERVED_PORTS+edi+8],dword 0x4d
269 serge 1044
 
429 serge 1045
        inc   dword [RESERVED_PORTS]          ; 0x50-0xdf
1046
        mov   edi,[RESERVED_PORTS]
1047
        shl   edi,4
1048
        mov   [RESERVED_PORTS+edi+0],dword 1
1049
        mov   [RESERVED_PORTS+edi+4],dword 0x50
1050
        mov   [RESERVED_PORTS+edi+8],dword 0xdf
233 serge 1051
 
429 serge 1052
        inc   dword [RESERVED_PORTS]          ; 0xe5-0xff
1053
        mov   edi,[RESERVED_PORTS]
1054
        shl   edi,4
1055
        mov   [RESERVED_PORTS+edi+0],dword 1
1056
        mov   [RESERVED_PORTS+edi+4],dword 0xe5
1057
        mov   [RESERVED_PORTS+edi+8],dword 0xff
233 serge 1058
 
1059
 
58 mario79 1060
;        cmp   [0xf604],byte 2          ; com1 mouse -> 0x3f0-0x3ff
1061
;        jne   ripl1
1062
;        inc   dword [0x2d0000]
1063
;        mov   edi,[0x2d0000]
1064
;        shl   edi,4
1065
;        mov   [0x2d0000+edi+0],dword 1
1066
;        mov   [0x2d0000+edi+4],dword 0x3f0
1067
;        mov   [0x2d0000+edi+8],dword 0x3ff
1068
;      ripl1:
1069
;        cmp   [0xf604],byte 3          ; com2 mouse -> 0x2f0-0x2ff
1070
;        jne   ripl2
1071
;        inc   dword [0x2d0000]
1072
;        mov   edi,[0x2d0000]
1073
;        shl   edi,4
1074
;        mov   [0x2d0000+edi+0],dword 1
1075
;        mov   [0x2d0000+edi+4],dword 0x2f0
1076
;        mov   [0x2d0000+edi+8],dword 0x2ff
1077
;      ripl2:
1 ha 1078
 
429 serge 1079
        popad
1080
        ret
1 ha 1081
 
1082
iglobal
429 serge 1083
mouseirqtable   db  12    ; ps2
1084
                db  4     ; com1
1085
                db  3     ; com2
1 ha 1086
endg
1087
 
1088
setirqreadports:
1089
 
429 serge 1090
        mov   [irq12read+0],dword 0x60 + 0x01000000  ; read port 0x60 , byte
1091
        mov   [irq12read+4],dword 0                  ; end of port list
1092
        mov   [irq04read+0],dword 0x3f8 + 0x01000000 ; read port 0x3f8 , byte
1093
        mov   [irq04read+4],dword 0                  ; end of port list
1094
        mov   [irq03read+0],dword 0x2f8 + 0x01000000 ; read port 0x2f8 , byte
1095
        mov   [irq03read+4],dword 0                  ; end of port list
1 ha 1096
 
429 serge 1097
        ret
1 ha 1098
 
1099
iglobal
1100
  process_number dd 0x1
1101
endg
1102
 
1103
set_variables:
1104
 
429 serge 1105
        mov   ecx,0x100                       ; flush port 0x60
1106
.fl60:  in    al,0x60
1107
        loop  .fl60
1108
        mov   [MOUSE_BUFF_COUNT],byte 0                 ; mouse buffer
1109
        mov   [KEY_COUNT],byte 0                 ; keyboard buffer
1110
        mov   [BTN_COUNT],byte 0                 ; button buffer
381 serge 1111
;        mov   [MOUSE_X],dword 100*65536+100    ; mouse x/y
1 ha 1112
 
429 serge 1113
        push  eax
465 serge 1114
        mov   ax,[BOOT_VAR+0x900c]
429 serge 1115
        shr   ax,1
1116
        shl   eax,16
465 serge 1117
        mov   ax,[BOOT_VAR+0x900A]
429 serge 1118
        shr   ax,1
1119
        mov   [MOUSE_X],eax
1120
        pop   eax
41 mikedld 1121
 
429 serge 1122
        mov   byte [SB16_Status],0            ; Minazzi Paolo
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:
536 diamond 2290
  db 0,7,0,0  ; version 0.7.0.0
41 mikedld 2291
  db UID_KOLIBRI
540 victor 2292
  dd __REV__
41 mikedld 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
527 diamond 2359
    mov   [BgrDataWidth],ebx
2360
    mov   [BgrDataHeight],ecx
1 ha 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
527 diamond 2369
    cmp  [BgrDataWidth],eax
469 serge 2370
    jae   @f
527 diamond 2371
    mov [BgrDataWidth],eax
469 serge 2372
@@:
527 diamond 2373
    cmp  [BgrDataHeight],eax
469 serge 2374
    jae   @f
527 diamond 2375
    mov [BgrDataHeight],eax
469 serge 2376
@@:
527 diamond 2377
    mov  eax,[BgrDataWidth]
2378
    imul eax,[BgrDataHeight]
2379
    lea  eax,[eax*3]
469 serge 2380
    mov  [mem_BACKGROUND],eax
2381
; get memory for new background
2382
    stdcall kernel_alloc, [mem_BACKGROUND]
2383
    test eax, eax
2384
    jz .exit_mem
2385
    mov [img_background], eax
2386
.exit_mem:
2387
    popad
2388
 
1 ha 2389
  sbgrr:
2390
    ret
469 serge 2391
 
1 ha 2392
  nosb1:
2393
 
429 serge 2394
    cmp   eax,2                            ; SET PIXEL
1 ha 2395
    jnz   nosb2
501 serge 2396
    mov   edx,[mem_BACKGROUND]
2397
    cmp   edx,ebx
1 ha 2398
    jbe   nosb2
2399
    mov   edx,[ebx]
2400
    and   edx,0xFF000000 ;255*256*256*256
2401
    and   ecx,0x00FFFFFF ;255*256*256+255*256+255
2402
    add   edx,ecx
479 kastigar 2403
    ;mov   [ebx+IMG_BACKGROUND],edx
469 serge 2404
    push  eax
2405
    mov   eax,[img_background]
2406
    mov   [ebx+eax],edx
2407
    pop   eax
1 ha 2408
;    mov   [bgrchanged],1
2409
    ret
2410
  nosb2:
2411
 
429 serge 2412
    cmp   eax,3                            ; DRAW BACKGROUND
1 ha 2413
    jnz   nosb3
2414
draw_background_temp:
2415
;    cmp   [bgrchanged],1 ;0
2416
;    je    nosb31
2417
;draw_background_temp:
2418
;    mov   [bgrchanged],1 ;0
381 serge 2419
    mov   [REDRAW_BACKGROUND],byte 1
76 mario79 2420
    mov    [background_defined], 1
1 ha 2421
   nosb31:
2422
    ret
2423
  nosb3:
2424
 
429 serge 2425
    cmp   eax,4                            ; TILED / STRETCHED
1 ha 2426
    jnz   nosb4
527 diamond 2427
    cmp   ebx,[BgrDrawMode]
429 serge 2428
    je    nosb41
527 diamond 2429
    mov   [BgrDrawMode],ebx
1 ha 2430
;    mov   [bgrchanged],1
2431
   nosb41:
2432
    ret
2433
  nosb4:
2434
 
429 serge 2435
    cmp   eax,5                            ; BLOCK MOVE TO BGR
1 ha 2436
    jnz   nosb5
2437
  ; bughere
2438
    mov   eax, ebx
2439
    mov   ebx, ecx
469 serge 2440
    add   ebx, [img_background]   ;IMG_BACKGROUND
1 ha 2441
    mov   ecx, edx
2442
    call  memmove
2443
  .fin:
2444
    ret
2445
  nosb5:
479 kastigar 2446
 
1 ha 2447
    ret
2448
 
479 kastigar 2449
 
1 ha 2450
align 4
2451
 
2452
sys_getbackground:
2453
 
429 serge 2454
    cmp   eax,1                                  ; SIZE
1 ha 2455
    jnz   nogb1
527 diamond 2456
    mov   eax,[BgrDataWidth]
1 ha 2457
    shl   eax,16
531 diamond 2458
    mov   ax,[BgrDataHeight]
1 ha 2459
    mov   [esp+36],eax
2460
    ret
2461
  nogb1:
2462
 
429 serge 2463
    cmp   eax,2                                  ; PIXEL
1 ha 2464
    jnz   nogb2
469 serge 2465
;    mov   edx,0x160000-16
2466
;    cmp   edx,ebx
2467
;    jbe   nogb2
2468
;    mov   eax, [ebx+IMG_BACKGROUND]
2469
    mov   eax,[img_background]
2470
    mov   eax,[ebx+eax]
2471
 
1 ha 2472
    and   eax, 0xFFFFFF
2473
    mov   [esp+36],eax
2474
    ret
2475
  nogb2:
2476
 
429 serge 2477
    cmp   eax,4                                  ; TILED / STRETCHED
1 ha 2478
    jnz   nogb4
527 diamond 2479
    mov   eax,[BgrDrawMode]
1 ha 2480
  nogb4:
2481
    mov   [esp+36],eax
2482
    ret
2483
 
2484
 
2485
align 4
2486
 
2487
sys_getkey:
2488
    mov   [esp+36],dword 1
92 diamond 2489
; test main buffer
429 serge 2490
    mov   ebx, [CURRENT_TASK]                          ; TOP OF WINDOW STACK
380 serge 2491
    movzx ecx,word [WIN_STACK + ebx * 2]
379 serge 2492
    mov   edx,[TASK_COUNT]
1 ha 2493
    cmp   ecx,edx
2494
    jne   .finish
381 serge 2495
    cmp   [KEY_COUNT],byte 0
429 serge 2496
    je    .finish
381 serge 2497
    movzx eax,byte [KEY_BUFF]
1 ha 2498
    shl   eax,8
2499
    push  eax
381 serge 2500
    dec   byte [KEY_COUNT]
2501
    and   byte [KEY_COUNT],127
2502
    movzx ecx,byte [KEY_COUNT]
1 ha 2503
    add   ecx,2
2504
 ;   mov   esi,0xf402
2505
 ;   mov   edi,0xf401
2506
 ;   cld
2507
 ;  rep   movsb
381 serge 2508
    mov   eax, KEY_BUFF+1
2509
    mov   ebx, KEY_BUFF
1 ha 2510
    call  memmove
2511
    pop   eax
92 diamond 2512
.ret_eax:
1 ha 2513
    mov   [esp+36],eax
92 diamond 2514
    ret
1 ha 2515
 .finish:
92 diamond 2516
; test hotkeys buffer
429 serge 2517
        mov     ecx, hotkey_buffer
92 diamond 2518
@@:
429 serge 2519
        cmp     [ecx], ebx
2520
        jz      .found
2521
        add     ecx, 8
2522
        cmp     ecx, hotkey_buffer+120*8
2523
        jb      @b
2524
        ret
92 diamond 2525
.found:
429 serge 2526
        mov     ax, [ecx+6]
2527
        shl     eax, 16
2528
        mov     ah, [ecx+4]
2529
        mov     al, 2
2530
        and     dword [ecx+4], 0
2531
        and     dword [ecx], 0
2532
        jmp     .ret_eax
1 ha 2533
 
2534
align 4
2535
 
2536
sys_getbutton:
2537
 
429 serge 2538
    mov   ebx, [CURRENT_TASK]                         ; TOP OF WINDOW STACK
1 ha 2539
    mov   [esp+36],dword 1
380 serge 2540
    movzx ecx, word [WIN_STACK + ebx * 2]
379 serge 2541
    mov   edx, [TASK_COUNT] ; less than 256 processes
1 ha 2542
    cmp   ecx,edx
2543
    jne   .exit
381 serge 2544
    movzx eax,byte [BTN_COUNT]
1 ha 2545
    test  eax,eax
429 serge 2546
    jz    .exit
381 serge 2547
    mov   eax,[BTN_BUFF]
1 ha 2548
    shl   eax,8
381 serge 2549
    mov   [BTN_COUNT],byte 0
1 ha 2550
    mov   [esp+36],eax
2551
 .exit:
2552
    ret
2553
 
2554
 
2555
align 4
2556
 
2557
sys_cpuusage:
2558
 
2559
;  RETURN:
2560
;
2561
;  +00 dword     process cpu usage
2562
;  +04  word     position in windowing stack
2563
;  +06  word     windowing stack value at current position (cpu nro)
2564
;  +10 12 bytes  name
2565
;  +22 dword     start in mem
2566
;  +26 dword     used mem
2567
;  +30 dword     PID , process idenfification number
2568
;
2569
 
379 serge 2570
    mov  edi,[TASK_BASE]   ; eax = return area
115 poddubny 2571
    add  eax,[edi + TASKDATA.mem_start]
1 ha 2572
 
429 serge 2573
    cmp  ebx,-1         ; who am I ?
1 ha 2574
    jne  no_who_am_i
379 serge 2575
    mov  ebx,[CURRENT_TASK]
1 ha 2576
  no_who_am_i:
2577
 
429 serge 2578
    push eax            ; return area
2579
    push ebx            ; process number
1 ha 2580
 
2581
    push ebx
2582
    push ebx
2583
    push eax
2584
 
2585
    ; return memory usage
2586
 
2587
    xor  edx,edx
2588
    mov  eax,0x20
2589
    mul  ebx
379 serge 2590
    add  eax,CURRENT_TASK+TASKDATA.cpu_usage
1 ha 2591
    mov  ebx,eax
2592
    pop  eax
2593
    mov  ecx,[ebx]
2594
    mov  [eax],ecx
2595
    pop  ebx
380 serge 2596
    mov  cx, [WIN_STACK + ebx * 2]
1 ha 2597
    mov  [eax+4],cx
380 serge 2598
    mov  cx, [WIN_POS + ebx * 2]
1 ha 2599
    mov  [eax+6],cx
2600
    push eax
2601
    mov  eax,ebx
2602
    shl  eax,8
380 serge 2603
    add  eax,SLOT_BASE+APPDATA.app_name
1 ha 2604
    pop  ebx
2605
    add  ebx,10
2606
    mov  ecx,11
2607
    call memmove
2608
 
2609
    ; memory usage
2610
 
2611
    xor    eax,eax
2612
    mov    edx,0x100000*16
429 serge 2613
    pop    ecx                                   ; get gdt of tss
1 ha 2614
    cmp    ecx,1
429 serge 2615
    je     os_mem
1 ha 2616
    shl    ecx,8
380 serge 2617
    mov    edx,[SLOT_BASE+ecx+APPDATA.mem_size] ;0x8c
1 ha 2618
    mov    eax,std_application_base_address
2619
    ; eax run base -> edx used memory
2620
  os_mem:
2621
    dec    edx
2622
    mov    [ebx+12],eax
2623
    mov    [ebx+16],edx
2624
 
2625
    ; PID (+30)
2626
 
2627
    mov    eax,[esp]
2628
    shl    eax,5
379 serge 2629
    add    eax,CURRENT_TASK+TASKDATA.pid
1 ha 2630
    mov    eax,[eax]
2631
    mov    [ebx+20],eax
2632
 
2633
    ; window position and size
2634
 
2635
    mov    esi,[esp]
2636
    shl    esi,5
115 poddubny 2637
    add    esi,window_data + WDATA.box
1 ha 2638
    mov    edi,[esp+4]
2639
    add    edi,34
115 poddubny 2640
    mov    ecx,4
1 ha 2641
    cld
115 poddubny 2642
    rep    movsd
1 ha 2643
 
2644
    ; Process state (+50)
2645
 
2646
    mov    eax,[esp]
2647
    shl    eax,5
379 serge 2648
    add    eax,CURRENT_TASK+TASKDATA.state
1 ha 2649
    mov    eax,[eax]
2650
    mov    [ebx+40],ax
2651
 
138 mikedld 2652
    ; Window client area box
1 ha 2653
 
138 mikedld 2654
    mov    esi,[esp]
2655
    shl    esi,8
380 serge 2656
    add    esi,SLOT_BASE+APPDATA.wnd_clientbox
138 mikedld 2657
    lea    edi,[ebx+44]
2658
    mov    ecx,4
2659
    rep    movsd
164 serge 2660
 
2661
    ; Window state
2662
 
138 mikedld 2663
    mov    esi,[esp]
2664
    shl    esi,5
2665
    add    esi,window_data + WDATA.box
465 serge 2666
    mov    al,[esi+WDATA.fl_wstate]
164 serge 2667
    mov    [edi],al
138 mikedld 2668
 
1 ha 2669
    pop    ebx
2670
    pop    eax
2671
 
2672
    ; return number of processes
2673
 
379 serge 2674
    mov    eax,[TASK_COUNT]
1 ha 2675
    mov    [esp+36],eax
2676
    ret
2677
 
2678
align 4
2679
sys_clock:
429 serge 2680
        cli
1 ha 2681
  ; Mikhail Lisovin  xx Jan 2005
429 serge 2682
  @@:   mov   al, 10
2683
        out   0x70, al
2684
        in    al, 0x71
2685
        test  al, al
2686
        jns   @f
2687
        mov   esi, 1
2688
        call  delay_ms
2689
        jmp   @b
1 ha 2690
  @@:
2691
  ; end Lisovin's fix
2692
 
429 serge 2693
        xor   al,al           ; seconds
2694
        out   0x70,al
2695
        in    al,0x71
2696
        movzx ecx,al
2697
        mov   al,02           ; minutes
2698
        shl   ecx,16
2699
        out   0x70,al
2700
        in    al,0x71
2701
        movzx edx,al
2702
        mov   al,04           ; hours
2703
        shl   edx,8
2704
        out   0x70,al
2705
        in    al,0x71
2706
        add   ecx,edx
2707
        movzx edx,al
2708
        add   ecx,edx
2709
        sti
2710
        mov   [esp+36],ecx
2711
        ret
1 ha 2712
 
2713
 
2714
align 4
2715
 
2716
sys_date:
2717
 
429 serge 2718
        cli
75 diamond 2719
 
429 serge 2720
  @@:   mov   al, 10
2721
        out   0x70, al
2722
        in    al, 0x71
2723
        test  al, al
2724
        jns   @f
2725
        mov   esi, 1
2726
        call  delay_ms
2727
        jmp   @b
75 diamond 2728
  @@:
2729
 
429 serge 2730
        mov     ch,0
2731
        mov     al,7            ; date
2732
        out     0x70,al
2733
        in      al,0x71
2734
        mov     cl,al
2735
        mov     al,8            ; month
2736
        shl     ecx,16
2737
        out     0x70,al
2738
        in      al,0x71
2739
        mov     ch,al
2740
        mov     al,9            ; year
2741
        out     0x70,al
2742
        in      al,0x71
2743
        mov     cl,al
2744
        sti
2745
        mov     [esp+36],ecx
2746
        ret
1 ha 2747
 
2748
 
2749
; redraw status
2750
 
2751
sys_redrawstat:
2752
 
2753
    cmp  eax,1
2754
    jne  no_widgets_away
2755
 
2756
    ; buttons away
2757
 
379 serge 2758
    mov   ecx,[CURRENT_TASK]
1 ha 2759
 
2760
  sys_newba2:
2761
 
381 serge 2762
    mov   edi,[BTN_ADDR]
1 ha 2763
    cmp   [edi],dword 0  ; empty button list ?
429 serge 2764
    je    end_of_buttons_away
1 ha 2765
 
2766
    movzx ebx,word [edi]
2767
    inc   ebx
2768
 
2769
    mov   eax,edi
2770
 
2771
  sys_newba:
2772
 
2773
    dec   ebx
429 serge 2774
    jz    end_of_buttons_away
1 ha 2775
 
2776
    add   eax,0x10
2777
    cmp   cx,[eax]
2778
    jnz   sys_newba
2779
 
2780
    push  eax ebx ecx
2781
    mov   ecx,ebx
2782
    inc   ecx
2783
    shl   ecx,4
2784
    mov   ebx,eax
2785
    add   eax,0x10
2786
    call  memmove
2787
    dec   dword [edi]
2788
    pop   ecx ebx eax
2789
 
2790
    jmp   sys_newba2
2791
 
2792
  end_of_buttons_away:
2793
 
2794
    ret
2795
 
2796
  no_widgets_away:
2797
 
2798
    cmp   eax,2
2799
    jnz   srl1
2800
 
379 serge 2801
    mov   edx,[TASK_BASE]      ; return whole screen draw area for this app
2802
    add   edx,draw_data-CURRENT_TASK
115 poddubny 2803
    mov   [edx+RECT.left], 0
2804
    mov   [edx+RECT.top], 0
381 serge 2805
    mov   eax,[ScreenWidth]
115 poddubny 2806
    mov   [edx+RECT.right],eax
381 serge 2807
    mov   eax,[ScreenHeight]
115 poddubny 2808
    mov   [edx+RECT.bottom],eax
1 ha 2809
 
379 serge 2810
    mov   edi,[TASK_BASE]
429 serge 2811
    or    [edi-twdw+WDATA.fl_wdrawn], 1   ; no new position & buttons from app
1 ha 2812
 
2813
    call  sys_window_mouse
2814
 
2815
    ret
2816
 
2817
  srl1:
2818
 
2819
    ret
2820
 
2821
 
2822
sys_drawwindow:
2823
 
2824
    mov   edi,ecx
2825
    shr   edi,16+8
2826
    and   edi,15
2827
 
2828
    cmp   edi,0   ; type I    - original style
2829
    jne   nosyswI
33 mario79 2830
    inc   [mouse_pause]
36 mario79 2831
    call  [disable_mouse]
1 ha 2832
    call  sys_set_window
36 mario79 2833
    call  [disable_mouse]
1 ha 2834
    call  drawwindow_I
114 mikedld 2835
    ;dec   [mouse_pause]
2836
    ;call   [draw_pointer]
2837
    ;ret
2838
    jmp   draw_window_caption.2
1 ha 2839
  nosyswI:
2840
 
2841
    cmp   edi,1   ; type II   - only reserve area, no draw
2842
    jne   nosyswII
33 mario79 2843
    inc   [mouse_pause]
36 mario79 2844
    call  [disable_mouse]
1 ha 2845
    call  sys_set_window
36 mario79 2846
    call  [disable_mouse]
1 ha 2847
    call  sys_window_mouse
33 mario79 2848
    dec   [mouse_pause]
36 mario79 2849
    call   [draw_pointer]
1 ha 2850
    ret
2851
  nosyswII:
2852
 
2853
    cmp   edi,2   ; type III  - new style
2854
    jne   nosyswIII
33 mario79 2855
    inc   [mouse_pause]
36 mario79 2856
    call  [disable_mouse]
1 ha 2857
    call  sys_set_window
36 mario79 2858
    call  [disable_mouse]
1 ha 2859
    call  drawwindow_III
114 mikedld 2860
    ;dec   [mouse_pause]
2861
    ;call   [draw_pointer]
2862
    ;ret
2863
    jmp   draw_window_caption.2
1 ha 2864
  nosyswIII:
2865
 
2866
    cmp   edi,3   ; type IV - skinned window
2867
    jne   nosyswIV
33 mario79 2868
 
102 poddubny 2869
    ; parameter for drawwindow_IV
35 halyavin 2870
    push  0
379 serge 2871
    mov   edi, [TASK_COUNT]
380 serge 2872
    movzx edi, word [WIN_POS + edi*2]
379 serge 2873
    cmp   edi, [CURRENT_TASK]
33 mario79 2874
    jne   @f
102 poddubny 2875
    inc   dword [esp]
2876
 @@:
33 mario79 2877
 
2878
    inc   [mouse_pause]
36 mario79 2879
    call  [disable_mouse]
1 ha 2880
    call  sys_set_window
36 mario79 2881
    call  [disable_mouse]
2882
    call  drawwindow_IV
114 mikedld 2883
    ;dec   [mouse_pause]
2884
    ;call   [draw_pointer]
2885
    ;ret
2886
    jmp   draw_window_caption.2
1 ha 2887
  nosyswIV:
2888
 
2889
    ret
2890
 
2891
 
114 mikedld 2892
draw_window_caption:
429 serge 2893
        inc     [mouse_pause]
2894
        call    [disable_mouse]
114 mikedld 2895
 
429 serge 2896
        xor     eax,eax
2897
        mov     edx,[TASK_COUNT]
2898
        movzx   edx,word[WIN_POS+edx*2]
2899
        cmp     edx,[CURRENT_TASK]
2900
        jne     @f
2901
        inc     eax
2902
    @@: mov     edx,[CURRENT_TASK]
2903
        shl     edx,5
2904
        add     edx,window_data
2905
        movzx   ebx,[edx+WDATA.fl_wstyle]
2906
        and     bl,0x0F
2907
        cmp     bl,3
2908
        jne     .not_style_3
114 mikedld 2909
 
429 serge 2910
        push    edx
2911
        call    drawwindow_IV_caption
2912
        add     esp,4
2913
        jmp     .2
114 mikedld 2914
 
2915
  .not_style_3:
429 serge 2916
        cmp     bl,2
2917
        jne     .not_style_2
114 mikedld 2918
 
429 serge 2919
        call    drawwindow_III_caption
2920
        jmp     .2
114 mikedld 2921
 
2922
  .not_style_2:
429 serge 2923
        cmp     bl,0
2924
        jne     .2
114 mikedld 2925
 
429 serge 2926
        call    drawwindow_I_caption
114 mikedld 2927
 
2928
;--------------------------------------------------------------
429 serge 2929
  .2:   ;jmp     @f
2930
        mov     edi,[CURRENT_TASK]
2931
        shl     edi,5
2932
        test    [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
2933
        jz      @f
2934
        mov     ecx,[edi*8+SLOT_BASE+APPDATA.wnd_caption]
2935
        or      ecx,ecx
2936
        jz      @f
465 serge 2937
        add     ecx,[edi+CURRENT_TASK+TASKDATA.mem_start]
114 mikedld 2938
 
429 serge 2939
        movzx   eax,[edi+window_data+WDATA.fl_wstyle]
2940
        and     al,0x0F
2941
        cmp     al,3
2942
        jne     .not_skinned
114 mikedld 2943
 
429 serge 2944
        mov     ebp,[edi+window_data+WDATA.box.left-2]
2945
        mov     bp,word[edi+window_data+WDATA.box.top]
2946
        movzx   eax,word[edi+window_data+WDATA.box.width]
2947
        sub     ax,[_skinmargins.left]
2948
        sub     ax,[_skinmargins.right]
2949
        cwde
2950
        cdq
2951
        mov     ebx,6
2952
        idiv    ebx
2953
        or      eax,eax
2954
        js      @f
2955
        mov     edx,eax
2956
        mov     eax,dword[_skinmargins.left-2]
2957
        mov     ax,word[_skinh]
2958
        sub     ax,[_skinmargins.bottom]
2959
        sub     ax,[_skinmargins.top]
2960
        sar     ax,1
2961
        adc     ax,0
2962
        add     ax,[_skinmargins.top]
2963
        add     ax,-3
2964
        add     eax,ebp
2965
        jmp     .dodraw
114 mikedld 2966
 
2967
  .not_skinned:
429 serge 2968
        cmp     al,1
2969
        je      @f
114 mikedld 2970
 
429 serge 2971
        mov     ebp,[edi+window_data+WDATA.box.left-2]
2972
        mov     bp,word[edi+window_data+WDATA.box.top]
2973
        movzx   eax,word[edi+window_data+WDATA.box.width]
2974
        sub     eax,16
2975
        cwde
2976
        cdq
2977
        mov     ebx,6
2978
        idiv    ebx
2979
        or      eax,eax
2980
        js      @f
2981
        mov     edx,eax
2982
        mov     eax,0x00080007
2983
        add     eax,ebp
139 diamond 2984
.dodraw:
429 serge 2985
        mov     ebx,[common_colours+16];0x00FFFFFF
2986
        or      ebx, 0x80000000
2987
        xor     edi,edi
2988
        call    dtext
114 mikedld 2989
 
2990
    @@:
2991
;--------------------------------------------------------------
429 serge 2992
        dec     [mouse_pause]
2993
        call    [draw_pointer]
2994
        ret
114 mikedld 2995
 
2996
iglobal
2997
align 4
2998
window_topleft dd \
2999
  1, 21,\
3000
  0,  0,\
3001
  5, 20,\
3002
  5,  ?
3003
endg
3004
 
3005
set_window_clientbox:
429 serge 3006
        push    eax ecx edi
114 mikedld 3007
 
429 serge 3008
        mov     eax,[_skinh]
3009
        mov     [window_topleft+4*7],eax
114 mikedld 3010
 
429 serge 3011
        mov     ecx,edi
3012
        sub     edi,window_data
3013
        shl     edi,3
3014
        test    [ecx+WDATA.fl_wstyle],WSTYLE_CLIENTRELATIVE
3015
        jz      @f
114 mikedld 3016
 
429 serge 3017
        movzx   eax,[ecx+WDATA.fl_wstyle]
3018
        and     eax,0x0F
3019
        mov     eax,[eax*8+window_topleft+0]
3020
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3021
        shl     eax,1
3022
        neg     eax
3023
        add     eax,[ecx+WDATA.box.width]
3024
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
114 mikedld 3025
 
429 serge 3026
        movzx   eax,[ecx+WDATA.fl_wstyle]
3027
        and     eax,0x0F
3028
        push    [eax*8+window_topleft+0]
3029
        mov     eax,[eax*8+window_topleft+4]
3030
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3031
        neg     eax
3032
        sub     eax,[esp]
3033
        add     eax,[ecx+WDATA.box.height]
3034
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
3035
        add     esp,4
114 mikedld 3036
 
429 serge 3037
        pop     edi ecx eax
3038
        ret
114 mikedld 3039
    @@:
429 serge 3040
        xor     eax,eax
3041
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.left],eax
3042
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.top],eax
3043
        mov     eax,[ecx+WDATA.box.width]
3044
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.width],eax
3045
        mov     eax,[ecx+WDATA.box.height]
3046
        mov     [edi+SLOT_BASE+APPDATA.wnd_clientbox.height],eax
114 mikedld 3047
 
429 serge 3048
        pop     edi ecx eax
3049
        ret
114 mikedld 3050
 
1 ha 3051
sys_set_window:
3052
 
379 serge 3053
    mov   edi,[CURRENT_TASK]
1 ha 3054
    shl   edi,5
3055
    add   edi,window_data
3056
 
3057
    ; colors
114 mikedld 3058
    mov   [edi+WDATA.cl_workarea],ecx
3059
    mov   [edi+WDATA.cl_titlebar],edx
3060
    mov   [edi+WDATA.cl_frames],esi
1 ha 3061
 
3062
    ; check flag (?)
186 diamond 3063
    test  [edi+WDATA.fl_wdrawn],1
3064
    jnz   newd
1 ha 3065
 
3066
    push  eax
3067
    mov   eax,[timer_ticks] ;[0xfdf0]
3068
    add   eax,100
3069
    mov   [new_window_starting],eax
3070
    pop   eax
3071
 
114 mikedld 3072
    mov   word[edi+WDATA.box.width],ax
3073
    mov   word[edi+WDATA.box.height],bx
3074
    sar   eax,16
3075
    sar   ebx,16
3076
    mov   word[edi+WDATA.box.left],ax
3077
    mov   word[edi+WDATA.box.top],bx
1 ha 3078
 
3079
    call  check_window_position
3080
 
164 serge 3081
    call  set_window_clientbox
1 ha 3082
 
429 serge 3083
    push  ecx esi edi               ; save for window fullscreen/resize
114 mikedld 3084
    ;mov   esi,edi
3085
 
429 serge 3086
        mov     cl,[edi+WDATA.fl_wstyle]
114 mikedld 3087
 
1 ha 3088
    sub   edi,window_data
114 mikedld 3089
    shl   edi,3
380 serge 3090
    add   edi,SLOT_BASE
114 mikedld 3091
 
429 serge 3092
        and     cl,0x0F
3093
        mov     [edi+APPDATA.wnd_caption],0
3094
        cmp     cl,3
3095
        jne     @f
3096
        mov     [edi+APPDATA.wnd_caption],esi
3097
    @@: mov     esi,[esp+0]
114 mikedld 3098
 
115 poddubny 3099
    add   edi, APPDATA.saved_box
429 serge 3100
        movsd
3101
        movsd
3102
        movsd
3103
        movsd
1 ha 3104
    pop   edi esi ecx
3105
 
3106
    push  eax ebx ecx edx
3107
;;;    mov   eax, 1
3108
;;;    call  delay_hs
115 poddubny 3109
    mov   eax, [edi+WDATA.box.left]
3110
    mov   ebx, [edi+WDATA.box.top]
3111
    mov   ecx, [edi+WDATA.box.width]
3112
    mov   edx, [edi+WDATA.box.height]
1 ha 3113
    add   ecx, eax
3114
    add   edx, ebx
3115
    call  calculatescreen
3116
    pop   edx ecx ebx eax
3117
 
429 serge 3118
    mov   [KEY_COUNT],byte 0           ; empty keyboard buffer
3119
    mov   [BTN_COUNT],byte 0           ; empty button buffer
1 ha 3120
 
3121
  newd:
429 serge 3122
    mov   [edi+WDATA.fl_redraw],byte 0   ; no redraw
1 ha 3123
    mov   edx,edi
3124
 
3125
    ret
3126
 
114 mikedld 3127
syscall_windowsettings:
1 ha 3128
 
114 mikedld 3129
  .set_window_caption:
429 serge 3130
        dec     eax     ; subfunction #1 - set window caption
3131
        jnz     .get_window_caption
114 mikedld 3132
 
429 serge 3133
        ; NOTE: only window owner thread can set its caption,
3134
        ;       so there's no parameter for PID/TID
114 mikedld 3135
 
429 serge 3136
        mov     edi,[CURRENT_TASK]
3137
        shl     edi,5
114 mikedld 3138
 
429 serge 3139
        ; have to check if caption is within application memory limit
3140
        ; check is trivial, and if application resizes its memory,
3141
        ;   caption still can become over bounds
202 diamond 3142
; diamond, 31.10.2006: check removed because with new memory manager
3143
; there can be valid data after APPDATA.mem_size bound
380 serge 3144
;        mov     ecx,[edi*8+SLOT_BASE+APPDATA.mem_size]
202 diamond 3145
;        add     ecx,255 ; max caption length
3146
;        cmp     ebx,ecx
3147
;        ja      .exit_fail
114 mikedld 3148
 
429 serge 3149
        mov     [edi*8+SLOT_BASE+APPDATA.wnd_caption],ebx
3150
        or      [edi+window_data+WDATA.fl_wstyle],WSTYLE_HASCAPTION
114 mikedld 3151
 
429 serge 3152
        call    draw_window_caption
114 mikedld 3153
 
429 serge 3154
        xor     eax,eax ; eax = 0 (success)
3155
        ret
114 mikedld 3156
 
3157
  .get_window_caption:
429 serge 3158
        dec     eax     ; subfunction #2 - get window caption
3159
        jnz     .exit_fail
114 mikedld 3160
 
429 serge 3161
        ; not implemented yet
114 mikedld 3162
 
3163
  .exit_fail:
429 serge 3164
        xor     eax,eax
3165
        inc     eax     ; eax = 1 (fail)
3166
        ret
114 mikedld 3167
 
3168
 
1 ha 3169
sys_window_move:
3170
 
429 serge 3171
        mov     edi,[CURRENT_TASK]
3172
        shl     edi,5
3173
        add     edi,window_data
1 ha 3174
 
429 serge 3175
        test    [edi+WDATA.fl_wstate],WSTATE_MAXIMIZED
3176
        jnz     .window_move_return
1 ha 3177
 
429 serge 3178
        push    dword [edi + WDATA.box.left]  ; save old coordinates
3179
        push    dword [edi + WDATA.box.top]
3180
        push    dword [edi + WDATA.box.width]
3181
        push    dword [edi + WDATA.box.height]
1 ha 3182
 
429 serge 3183
        cmp   eax,-1                  ; set new position and size
3184
        je    .no_x_reposition
3185
        mov     [edi + WDATA.box.left], eax
49 mikedld 3186
      .no_x_reposition:
429 serge 3187
        cmp   ebx,-1
3188
        je    .no_y_reposition
3189
        mov     [edi + WDATA.box.top], ebx
49 mikedld 3190
      .no_y_reposition:
1 ha 3191
 
429 serge 3192
        test    [edi+WDATA.fl_wstate],WSTATE_ROLLEDUP
3193
        jnz     .no_y_resizing
1 ha 3194
 
429 serge 3195
        cmp   ecx,-1
3196
        je    .no_x_resizing
3197
        mov     [edi + WDATA.box.width], ecx
49 mikedld 3198
      .no_x_resizing:
429 serge 3199
        cmp   edx,-1
3200
        je    .no_y_resizing
3201
        mov     [edi + WDATA.box.height], edx
49 mikedld 3202
      .no_y_resizing:
1 ha 3203
 
429 serge 3204
        call  check_window_position
3205
        call  set_window_clientbox
1 ha 3206
 
429 serge 3207
        pushad                       ; save for window fullscreen/resize
3208
        mov   esi,edi
3209
        sub   edi,window_data
3210
        shr   edi,5
3211
        shl   edi,8
3212
        add   edi, SLOT_BASE + APPDATA.saved_box
3213
        mov   ecx,4
3214
        cld
3215
        rep   movsd
3216
        popad
49 mikedld 3217
 
429 serge 3218
        pushad                       ; calculcate screen at new position
3219
        mov   eax, [edi + WDATA.box.left]
3220
        mov   ebx, [edi + WDATA.box.top]
3221
        mov   ecx, [edi + WDATA.box.width]
3222
        mov   edx, [edi + WDATA.box.height]
3223
        add   ecx,eax
3224
        add   edx,ebx
221 serge 3225
 
429 serge 3226
        call  calculatescreen
3227
        popad
49 mikedld 3228
 
429 serge 3229
        pop   edx                   ; calculcate screen at old position
3230
        pop   ecx
3231
        pop   ebx
3232
        pop   eax
3233
        add   ecx,eax
3234
        add   edx,ebx
3235
        mov   [dlx],eax             ; save for drawlimits
3236
        mov   [dly],ebx
3237
        mov   [dlxe],ecx
3238
        mov   [dlye],edx
3239
        call  calculatescreen
49 mikedld 3240
 
429 serge 3241
        mov   [edi + WDATA.fl_redraw], 1 ; flag the process as redraw
49 mikedld 3242
 
429 serge 3243
        mov   eax,edi               ; redraw screen at old position
3244
        xor   esi,esi
3245
        call  redrawscreen
49 mikedld 3246
 
429 serge 3247
        mov   [DONT_DRAW_MOUSE],byte 0 ; mouse pointer
3248
        mov   [MOUSE_BACKGROUND],byte 0 ; no mouse under
3249
        mov   [MOUSE_DOWN],byte 0 ; react to mouse up/down
49 mikedld 3250
 
429 serge 3251
        call  [draw_pointer]
49 mikedld 3252
 
429 serge 3253
        mov   [window_move_pr],0
49 mikedld 3254
 
3255
      .window_move_return:
3256
 
429 serge 3257
        ret
1 ha 3258
 
3259
uglobal
3260
  window_move_pr   dd  0x0
3261
  window_move_eax  dd  0x0
3262
  window_move_ebx  dd  0x0
3263
  window_move_ecx  dd  0x0
3264
  window_move_edx  dd  0x0
3265
endg
3266
 
3267
;ok - 100% work
3268
;nt - not tested
3269
;---------------------------------------------------------------------------------------------
3270
;eax
3271
;0 - task switch counter. Ret switch counter in eax. Block. ok.
3272
;1 - change task. Ret nothing. Block. ok.
3273
;2 - performance control
3274
; ebx
3275
; 0 - enable or disable (inversion) PCE flag on CR4 for rdmpc in user mode.
3276
; returned new cr4 in eax. Ret cr4 in eax. Block. ok.
3277
; 1 - is cache enabled. Ret cr0 in eax if enabled else zero in eax. Block. ok.
3278
; 2 - enable cache. Ret 1 in eax. Ret nothing. Block. ok.
3279
; 3 - disable cache. Ret 0 in eax. Ret nothing. Block. ok.
3280
;eax
3281
;3 - rdmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3282
;4 - wrmsr. Counter in edx. (edx:eax) [esi:edi, edx] => [edx:esi, ecx]. Ret in ebx:eax. Block. ok.
3283
;---------------------------------------------------------------------------------------------
3284
sys_sheduler: ;noname & halyavin
3285
    cmp eax,0
3286
    je shed_counter
3287
    cmp eax,2
3288
    je perf_control
3289
    cmp eax,3
3290
    je rdmsr_instr
3291
    cmp eax,4
3292
    je wrmsr_instr
3293
    cmp eax,1
3294
    jne not_supported
3295
    call change_task ;delay,0
3296
ret
3297
shed_counter:
3298
    mov eax,[context_counter]
3299
    mov [esp+36],eax
3300
not_supported:
3301
ret
3302
perf_control:
3303
    inc eax ;now eax=3
3304
    cmp ebx,eax
3305
    je cache_disable
3306
    dec eax
3307
    cmp ebx,eax
3308
    je cache_enable
3309
    dec eax
3310
    cmp ebx,eax
3311
    je is_cache_enabled
3312
    dec eax
3313
    cmp ebx,eax
3314
    je modify_pce
3315
ret
3316
 
3317
rdmsr_instr:
3318
;now counter in ecx
3319
;(edx:eax) esi:edi => edx:esi
3320
mov eax,esi
3321
rdmsr
3322
mov [esp+36],eax
3323
mov [esp+24],edx ;ret in ebx?
3324
ret
3325
 
3326
wrmsr_instr:
3327
;now counter in ecx
3328
;(edx:eax) esi:edi => edx:esi
482 Ghost 3329
	; Fast Call MSR can't be destroy
3330
	; Íî MSR_AMD_EFER ìîæíî èçìåíÿòü, ò.ê. â ýòîì ðåãèñòðå ëèø
3331
	; âêëþ÷àþòñÿ/âûêëþ÷àþòñÿ ðàñøèðåííûå âîçìîæíîñòè
3332
	cmp	ecx, MSR_SYSENTER_CS
3333
	je	@f
3334
	cmp	ecx, MSR_SYSENTER_ESP
3335
	je	@f
3336
	cmp	ecx, MSR_SYSENTER_EIP
3337
	je	@f
3338
	cmp	ecx, MSR_AMD_STAR
3339
	je	@f
3340
 
3341
	mov	eax, esi
3342
	wrmsr
3343
	; mov	[esp + 36], eax
3344
	; mov	[esp + 24], edx ;ret in ebx?
3345
@@:
1 ha 3346
ret
3347
 
3348
cache_disable:
3349
       mov eax,cr0
3350
       or  eax,01100000000000000000000000000000b
3351
       mov cr0,eax
3352
       wbinvd ;set MESI
3353
ret
3354
 
3355
cache_enable:
3356
       mov eax,cr0
3357
       and eax,10011111111111111111111111111111b
3358
       mov cr0,eax
3359
ret
3360
 
3361
is_cache_enabled:
3362
       mov eax,cr0
3363
       mov ebx,eax
3364
       and eax,01100000000000000000000000000000b
3365
       jz cache_disabled
3366
       mov [esp+36],ebx
3367
cache_disabled:
3368
       mov dword [esp+36],eax ;0
3369
ret
3370
 
3371
modify_pce:
3372
       mov eax,cr4
3373
;       mov ebx,0
3374
;       or  bx,100000000b ;pce
3375
;       xor eax,ebx ;invert pce
17 me_root 3376
       bts eax,8 ;pce=cr4[8]
1 ha 3377
       mov cr4,eax
3378
       mov [esp+36],eax
3379
ret
3380
;---------------------------------------------------------------------------------------------
3381
 
3382
 
3383
; check if pixel is allowed to be drawn
3384
 
3385
checkpixel:
429 serge 3386
        push eax edx
1 ha 3387
 
429 serge 3388
        mov  edx,[ScreenWidth]     ; screen x size
3389
        inc  edx
3390
        imul edx, ebx
3391
        mov  dl, [eax+edx+display_data] ; lea eax, [...]
1 ha 3392
 
429 serge 3393
        xor  ecx, ecx
3394
        mov  eax, [CURRENT_TASK]
3395
        cmp  al, dl
3396
        setne cl
1 ha 3397
 
429 serge 3398
        pop  edx eax
3399
        ret
1 ha 3400
 
3401
iglobal
521 diamond 3402
  cpustring db 'CPU',0
1 ha 3403
endg
3404
 
67 diamond 3405
uglobal
429 serge 3406
background_defined    db    0    ; diamond, 11.04.2006
67 diamond 3407
endg
1 ha 3408
 
3409
align 4
3410
; check misc
3411
 
3412
checkmisc:
3413
 
3414
    cmp   [ctrl_alt_del], 1
3415
    jne   nocpustart
501 serge 3416
 
521 diamond 3417
        mov     ebp, cpustring
3418
        call    fs_execute_from_sysdir
501 serge 3419
 
1 ha 3420
    mov   [ctrl_alt_del], 0
465 serge 3421
 
3422
nocpustart:
1 ha 3423
    cmp   [mouse_active], 1
3424
    jne   mouse_not_active
3425
    mov   [mouse_active], 0
3426
    xor   edi, edi
465 serge 3427
    mov   ecx,  [TASK_COUNT]
3428
set_mouse_event:
1 ha 3429
    add   edi, 256
465 serge 3430
    or    [edi+SLOT_BASE+APPDATA.event_mask], dword 100000b
1 ha 3431
    loop  set_mouse_event
3432
 
465 serge 3433
mouse_not_active:
429 serge 3434
    cmp   [REDRAW_BACKGROUND],byte 0               ; background update ?
3435
    jz    nobackgr
76 mario79 3436
    cmp    [background_defined], 0
429 serge 3437
    jz    nobackgr
473 diamond 3438
;    mov   [REDRAW_BACKGROUND],byte 2
3439
;    call  change_task
3440
    xor   edi, edi
3441
    mov   ecx,  [TASK_COUNT]
3442
set_bgr_event:
3443
    add   edi, 256
3444
    or    [edi+SLOT_BASE+APPDATA.event_mask], 16
3445
    loop  set_bgr_event
465 serge 3446
    mov   [draw_data+32 + RECT.left],dword 0
3447
    mov   [draw_data+32 + RECT.top],dword 0
381 serge 3448
    mov   eax,[ScreenWidth]
3449
    mov   ebx,[ScreenHeight]
465 serge 3450
    mov   [draw_data+32 + RECT.right],eax
3451
    mov   [draw_data+32 + RECT.bottom],ebx
1 ha 3452
    call  drawbackground
381 serge 3453
    mov   [REDRAW_BACKGROUND],byte 0
3454
    mov   [MOUSE_BACKGROUND],byte 0
1 ha 3455
 
465 serge 3456
nobackgr:
1 ha 3457
 
3458
    ; system shutdown request
3459
 
381 serge 3460
    cmp  [SYS_SHUTDOWN],byte 0
429 serge 3461
    je   noshutdown
1 ha 3462
 
3463
    mov  edx,[shutdown_processes]
3464
    sub  dl,2
3465
 
381 serge 3466
    cmp  [SYS_SHUTDOWN],dl
1 ha 3467
    jne  no_mark_system_shutdown
3468
 
465 serge 3469
    mov   edx,OS_BASE+0x3040
381 serge 3470
    movzx ecx,byte [SYS_SHUTDOWN]
1 ha 3471
    add   ecx,5
465 serge 3472
markz:
115 poddubny 3473
    mov   [edx+TASKDATA.state],byte 3
1 ha 3474
    add   edx,0x20
3475
    loop  markz
3476
 
3477
  no_mark_system_shutdown:
3478
 
3479
    call [disable_mouse]
3480
 
381 serge 3481
    dec  byte [SYS_SHUTDOWN]
1 ha 3482
 
381 serge 3483
    cmp  [SYS_SHUTDOWN],byte 0
429 serge 3484
    je   system_shutdown
1 ha 3485
 
465 serge 3486
noshutdown:
1 ha 3487
 
3488
 
429 serge 3489
    mov   eax,[TASK_COUNT]                  ; termination
379 serge 3490
    mov   ebx,TASK_DATA+TASKDATA.state
1 ha 3491
    mov   esi,1
3492
 
465 serge 3493
newct:
1 ha 3494
    mov   cl,[ebx]
3495
    cmp   cl,byte 3
429 serge 3496
    jz    terminate
1 ha 3497
    cmp   cl,byte 4
429 serge 3498
    jz    terminate
1 ha 3499
 
3500
    add   ebx,0x20
3501
    inc   esi
3502
    dec   eax
3503
    jnz   newct
3504
 
3505
    ret
3506
 
3507
 
3508
; redraw screen
3509
 
3510
redrawscreen:
3511
 
3512
; eax , if process window_data base is eax, do not set flag/limits
3513
 
429 serge 3514
         pushad
3515
         push  eax
1 ha 3516
 
3517
;;;         mov   eax,2
3518
;;;         call  delay_hs
3519
 
429 serge 3520
         ;mov   ecx,0               ; redraw flags for apps
3521
         xor   ecx,ecx
1 ha 3522
       newdw2:
3523
 
429 serge 3524
         inc   ecx
3525
         push  ecx
1 ha 3526
 
429 serge 3527
         mov   eax,ecx
3528
         shl   eax,5
3529
         add   eax,window_data
1 ha 3530
 
429 serge 3531
         cmp   eax,[esp+4]
3532
         je    not_this_task
3533
                                   ; check if window in redraw area
3534
         mov   edi,eax
1 ha 3535
 
429 serge 3536
         cmp   ecx,1               ; limit for background
3537
         jz    bgli
1 ha 3538
 
429 serge 3539
         mov   eax, [edi + WDATA.box.left]
3540
         mov   ebx, [edi + WDATA.box.top]
3541
         mov   ecx, [edi + WDATA.box.width]
3542
         mov   edx, [edi + WDATA.box.height]
3543
         add   ecx,eax
3544
         add   edx,ebx
1 ha 3545
 
429 serge 3546
         mov   ecx,[dlye]   ; ecx = area y end     ebx = window y start
3547
         cmp   ecx,ebx
3548
         jb    ricino
1 ha 3549
 
429 serge 3550
         mov   ecx,[dlxe]   ; ecx = area x end     eax = window x start
3551
         cmp   ecx,eax
3552
         jb    ricino
1 ha 3553
 
429 serge 3554
         mov   eax, [edi + WDATA.box.left]
3555
         mov   ebx, [edi + WDATA.box.top]
3556
         mov   ecx, [edi + WDATA.box.width]
3557
         mov   edx, [edi + WDATA.box.height]
3558
         add   ecx, eax
3559
         add   edx, ebx
164 serge 3560
 
429 serge 3561
         mov   eax,[dly]    ; eax = area y start     edx = window y end
3562
         cmp   edx,eax
3563
         jb    ricino
1 ha 3564
 
429 serge 3565
         mov   eax,[dlx]    ; eax = area x start     ecx = window x end
3566
         cmp   ecx,eax
3567
         jb    ricino
1 ha 3568
 
429 serge 3569
        bgli:
1 ha 3570
 
429 serge 3571
         cmp   edi,esi
3572
         jz    ricino
1 ha 3573
 
429 serge 3574
         mov   eax,edi
3575
         add   eax,draw_data-window_data
1 ha 3576
 
429 serge 3577
         mov   ebx,[dlx]          ; set limits
3578
         mov   [eax + RECT.left], ebx
3579
         mov   ebx,[dly]
3580
         mov   [eax + RECT.top], ebx
3581
         mov   ebx,[dlxe]
3582
         mov   [eax + RECT.right], ebx
3583
         mov   ebx,[dlye]
3584
         mov   [eax + RECT.bottom], ebx
1 ha 3585
 
429 serge 3586
         sub   eax,draw_data-window_data
1 ha 3587
 
429 serge 3588
         cmp   ecx,1
3589
         jne   nobgrd
3590
         cmp   esi,1
3591
         je    newdw8
3592
         call  drawbackground
1 ha 3593
 
3594
       newdw8:
3595
       nobgrd:
3596
 
429 serge 3597
         mov   [eax + WDATA.fl_redraw],byte 1    ; mark as redraw
1 ha 3598
 
3599
       ricino:
3600
 
3601
       not_this_task:
3602
 
429 serge 3603
         pop   ecx
1 ha 3604
 
429 serge 3605
         cmp   ecx,[TASK_COUNT]
3606
         jle   newdw2
1 ha 3607
 
429 serge 3608
         pop  eax
3609
         popad
1 ha 3610
 
429 serge 3611
         ret
1 ha 3612
 
3613
calculatebackground:   ; background
3614
 
429 serge 3615
        ; all black
1 ha 3616
 
469 serge 3617
        mov   edi, [img_background]  ;IMG_BACKGROUND                 ; set background to black
429 serge 3618
        xor   eax, eax
469 serge 3619
        mov   ecx, 1023    ;0x0fff00 / 4
429 serge 3620
        cld
3621
        rep   stosd
1 ha 3622
 
429 serge 3623
        mov   edi,display_data              ; set os to use all pixels
3624
        mov   eax,0x01010101
472 serge 3625
        mov   ecx,1280*1024 / 4
429 serge 3626
        rep   stosd
1 ha 3627
 
429 serge 3628
        mov   byte [REDRAW_BACKGROUND], 0              ; do not draw background!
1 ha 3629
 
429 serge 3630
        ret
1 ha 3631
 
3632
uglobal
429 serge 3633
  imax    dd 0x0
1 ha 3634
endg
3635
 
3636
 
3637
 
3638
delay_ms:     ; delay in 1/1000 sec
3639
 
3640
 
429 serge 3641
        push  eax
3642
        push  ecx
1 ha 3643
 
429 serge 3644
        mov   ecx,esi
3645
        ; 
3646
        imul  ecx, 33941
3647
        shr   ecx, 9
3648
        ; 
1 ha 3649
 
429 serge 3650
        in    al,0x61
3651
        and   al,0x10
3652
        mov   ah,al
3653
        cld
1 ha 3654
 
429 serge 3655
 cnt1:  in    al,0x61
3656
        and   al,0x10
3657
        cmp   al,ah
3658
        jz    cnt1
1 ha 3659
 
429 serge 3660
        mov   ah,al
3661
        loop  cnt1
1 ha 3662
 
429 serge 3663
        pop   ecx
3664
        pop   eax
1 ha 3665
 
429 serge 3666
        ret
1 ha 3667
 
3668
 
3669
set_app_param:
429 serge 3670
        push edi
1 ha 3671
 
429 serge 3672
        mov  edi,[TASK_BASE]
3673
        mov  [edi+TASKDATA.event_mask],eax
1 ha 3674
 
429 serge 3675
        pop  edi
3676
        ret
1 ha 3677
 
3678
 
3679
 
3680
delay_hs:     ; delay in 1/100 secs
429 serge 3681
        push  eax
3682
        push  ecx
3683
        push  edx
1 ha 3684
 
429 serge 3685
        mov   edx,[timer_ticks]
3686
        add   edx,eax
1 ha 3687
 
3688
      newtic:
429 serge 3689
        mov   ecx,[timer_ticks]
3690
        cmp   edx,ecx
3691
        jbe   zerodelay
1 ha 3692
 
429 serge 3693
        call  change_task
1 ha 3694
 
429 serge 3695
        jmp   newtic
1 ha 3696
 
3697
      zerodelay:
429 serge 3698
        pop   edx
3699
        pop   ecx
3700
        pop   eax
1 ha 3701
 
429 serge 3702
        ret
1 ha 3703
 
3704
 
3705
memmove:       ; memory move in bytes
3706
 
3707
; eax = from
3708
; ebx = to
3709
; ecx = no of bytes
3710
    test ecx, ecx
3711
    jle  .ret
3712
 
3713
 
3714
    push esi edi ecx
3715
 
3716
    mov  edi, ebx
3717
    mov  esi, eax
3718
 
3719
    test ecx, not 11b
429 serge 3720
    jz   @f
1 ha 3721
 
3722
    push ecx
3723
    shr  ecx, 2
3724
    rep  movsd
3725
    pop  ecx
3726
    and  ecx, 11b
429 serge 3727
    jz   .finish
1 ha 3728
  @@:
3729
    rep  movsb
3730
 
3731
  .finish:
3732
    pop  ecx edi esi
3733
  .ret:
3734
    ret
3735
 
3736
 
75 diamond 3737
;  Sysfunction 34, read_floppy_file, is obsolete. Use 58 or 70 function instead.
3738
;align 4
1 ha 3739
;
75 diamond 3740
;read_floppy_file:
1 ha 3741
;
75 diamond 3742
;; as input
3743
;;
3744
;; eax pointer to file
3745
;; ebx file lenght
3746
;; ecx start 512 byte block number
3747
;; edx number of blocks to read
3748
;; esi pointer to return/work area (atleast 20 000 bytes)
3749
;;
3750
;;
3751
;; on return
3752
;;
3753
;; eax = 0 command succesful
3754
;;       1 no fd base and/or partition defined
3755
;;       2 yet unsupported FS
3756
;;       3 unknown FS
3757
;;       4 partition not defined at hd
3758
;;       5 file not found
3759
;; ebx = size of file
1 ha 3760
;
379 serge 3761
;     mov   edi,[TASK_BASE]
75 diamond 3762
;     add   edi,0x10
3763
;     add   esi,[edi]
3764
;     add   eax,[edi]
1 ha 3765
;
75 diamond 3766
;     pushad
3767
;     mov  edi,esi
3768
;     add  edi,1024
3769
;     mov  esi,0x100000+19*512
3770
;     sub  ecx,1
3771
;     shl  ecx,9
3772
;     add  esi,ecx
3773
;     shl  edx,9
3774
;     mov  ecx,edx
3775
;     cld
3776
;     rep  movsb
3777
;     popad
3778
;
3779
;     mov   [esp+36],eax
3780
;     mov   [esp+24],ebx
3781
;     ret
1 ha 3782
 
3783
 
3784
 
3785
align 4
3786
 
3787
sys_programirq:
3788
 
379 serge 3789
    mov   edi,[TASK_BASE]
115 poddubny 3790
    add   eax,[edi+TASKDATA.mem_start]
1 ha 3791
 
75 diamond 3792
    cmp   ebx,16
3793
    jae   .not_owner
379 serge 3794
    mov   edi,[TASK_BASE]
115 poddubny 3795
    mov   edi,[edi+TASKDATA.pid]
75 diamond 3796
    cmp   edi,[irq_owner+ebx*4]
429 serge 3797
    je    spril1
75 diamond 3798
.not_owner:
1 ha 3799
    mov   [esp+36],dword 1
3800
    ret
3801
  spril1:
3802
 
3803
    mov   esi,eax
3804
    shl   ebx,6
3805
    add   ebx,irq00read
3806
    mov   edi,ebx
3807
    mov   ecx,16
3808
    cld
3809
    rep   movsd
3810
    mov   [esp+36],dword 0
3811
    ret
3812
 
3813
 
3814
align 4
3815
 
3816
get_irq_data:
75 diamond 3817
     cmp   eax,16
3818
     jae   .not_owner
429 serge 3819
     mov   edx,eax           ; check for correct owner
1 ha 3820
     shl   edx,2
3821
     add   edx,irq_owner
3822
     mov   edx,[edx]
379 serge 3823
     mov   edi,[TASK_BASE]
115 poddubny 3824
     mov   edi,[edi+TASKDATA.pid]
1 ha 3825
     cmp   edx,edi
3826
     je    gidril1
75 diamond 3827
.not_owner:
429 serge 3828
     mov   [esp+32],dword 2     ; ecx=2
1 ha 3829
     ret
3830
 
3831
  gidril1:
3832
 
3833
     mov   ebx,eax
3834
     shl   ebx,12
381 serge 3835
     add   ebx,IRQ_SAVE
1 ha 3836
     mov   eax,[ebx]
3837
     mov   ecx,1
3838
     test  eax,eax
3839
     jz    gid1
3840
 
3841
     dec   eax
3842
     mov   esi,ebx
3843
     mov   [ebx],eax
3844
     movzx ebx,byte [ebx+0x10]
3845
     add   esi,0x10
3846
     mov   edi,esi
3847
     inc   esi
3848
     mov   ecx,4000 / 4
3849
     cld
3850
     rep   movsd
75 diamond 3851
;     xor   ecx,ecx     ; as result of 'rep' ecx=0
1 ha 3852
   gid1:
3853
     mov   [esp+36],eax
3854
     mov   [esp+32],ecx
3855
     mov   [esp+24],ebx
3856
     ret
3857
 
3858
 
3859
set_io_access_rights:
3860
 
3861
     pushad
3862
 
465 serge 3863
     mov edi, tss._io_map_0
1 ha 3864
 
465 serge 3865
;     mov   ecx,eax
3866
;     and   ecx,7    ; offset in byte
1 ha 3867
 
465 serge 3868
;     shr   eax,3    ; number of byte
3869
;     add   edi,eax
1 ha 3870
 
465 serge 3871
;     mov   ebx,1
3872
;     shl   ebx,cl
1 ha 3873
 
429 serge 3874
     cmp   ebp,0                ; enable access - ebp = 0
1 ha 3875
     jne   siar1
3876
 
465 serge 3877
;     not   ebx
3878
;     and   [edi],byte bl
3879
     btr [edi], eax
1 ha 3880
 
3881
     popad
3882
 
3883
     ret
3884
 
465 serge 3885
siar1:
1 ha 3886
 
465 serge 3887
     bts [edi], eax
3888
  ;  or    [edi],byte bl        ; disable access - ebp = 1
1 ha 3889
 
3890
     popad
3891
 
3892
     ret
3893
 
3894
r_f_port_area:
3895
 
3896
     test  eax, eax
3897
     jnz   free_port_area
3898
;     je    r_port_area
3899
;     jmp   free_port_area
3900
 
3901
;   r_port_area:
3902
 
3903
     pushad
3904
 
429 serge 3905
     cmp   ebx,ecx            ; beginning > end ?
75 diamond 3906
     ja    rpal1
3907
     cmp   ecx,65536
3908
     jae   rpal1
381 serge 3909
     mov   esi,[RESERVED_PORTS]
429 serge 3910
     test  esi,esi            ; no reserved areas ?
1 ha 3911
     je    rpal2
429 serge 3912
     cmp   esi,255            ; max reserved
75 diamond 3913
     jae   rpal1
465 serge 3914
 rpal3:
1 ha 3915
     mov   edi,esi
3916
     shl   edi,4
381 serge 3917
     add   edi,RESERVED_PORTS
1 ha 3918
     cmp   ebx,[edi+8]
75 diamond 3919
     ja    rpal4
1 ha 3920
     cmp   ecx,[edi+4]
3921
     jae   rpal1
3922
;     jb    rpal4
3923
;     jmp   rpal1
465 serge 3924
 rpal4:
1 ha 3925
 
3926
     dec   esi
3927
     jnz   rpal3
3928
     jmp   rpal2
3929
   rpal1:
3930
     popad
3931
     mov   eax,1
3932
     ret
3933
 
3934
   rpal2:
3935
     popad
3936
 
3937
 
3938
     ; enable port access at port IO map
3939
     cli
429 serge 3940
     pushad                        ; start enable io map
1 ha 3941
 
3942
     cmp   ecx,65536 ;16384
3943
     jae   no_unmask_io ; jge
3944
 
3945
     mov   eax,ebx
3946
 
3947
   new_port_access:
3948
 
3949
     pushad
3950
 
429 serge 3951
     xor   ebp,ebp                ; enable - eax = port
1 ha 3952
     call  set_io_access_rights
3953
 
3954
     popad
3955
 
3956
     inc   eax
3957
     cmp   eax,ecx
3958
     jbe   new_port_access
3959
 
3960
   no_unmask_io:
3961
 
429 serge 3962
     popad                         ; end enable io map
1 ha 3963
     sti
3964
 
381 serge 3965
     mov   edi,[RESERVED_PORTS]
1 ha 3966
     add   edi,1
381 serge 3967
     mov   [RESERVED_PORTS],edi
1 ha 3968
     shl   edi,4
381 serge 3969
     add   edi,RESERVED_PORTS
379 serge 3970
     mov   esi,[TASK_BASE]
115 poddubny 3971
     mov   esi,[esi+TASKDATA.pid]
1 ha 3972
     mov   [edi],esi
3973
     mov   [edi+4],ebx
3974
     mov   [edi+8],ecx
3975
 
3976
     xor   eax, eax
3977
     ret
3978
 
3979
free_port_area:
3980
 
3981
     pushad
3982
 
381 serge 3983
     mov   esi,[RESERVED_PORTS]     ; no reserved areas ?
75 diamond 3984
     test  esi,esi
1 ha 3985
     je    frpal2
379 serge 3986
     mov   edx,[TASK_BASE]
115 poddubny 3987
     mov   edx,[edx+TASKDATA.pid]
1 ha 3988
   frpal3:
3989
     mov   edi,esi
3990
     shl   edi,4
381 serge 3991
     add   edi,RESERVED_PORTS
1 ha 3992
     cmp   edx,[edi]
3993
     jne   frpal4
3994
     cmp   ebx,[edi+4]
3995
     jne   frpal4
3996
     cmp   ecx,[edi+8]
3997
     jne   frpal4
3998
     jmp   frpal1
3999
   frpal4:
4000
     dec   esi
4001
     jnz   frpal3
4002
   frpal2:
4003
     popad
4004
     mov   eax,1
4005
     ret
4006
   frpal1:
4007
     mov   ecx,256
4008
     sub   ecx,esi
4009
     shl   ecx,4
4010
     mov   esi,edi
4011
     add   esi,16
4012
     cld
4013
     rep   movsb
4014
 
381 serge 4015
     dec   dword [RESERVED_PORTS]
1 ha 4016
 
4017
     popad
4018
 
4019
 
4020
     ; disable port access at port IO map
4021
 
429 serge 4022
     pushad                        ; start disable io map
1 ha 4023
 
4024
     cmp   ecx,65536 ;16384
4025
     jge   no_mask_io
4026
 
4027
     mov   eax,ebx
4028
 
4029
   new_port_access_disable:
4030
 
4031
     pushad
4032
 
429 serge 4033
     mov   ebp,1                  ; disable - eax = port
1 ha 4034
     call  set_io_access_rights
4035
 
4036
     popad
4037
 
4038
     inc   eax
4039
     cmp   eax,ecx
4040
     jbe   new_port_access_disable
4041
 
4042
   no_mask_io:
4043
 
429 serge 4044
     popad                         ; end disable io map
1 ha 4045
 
4046
     xor   eax, eax
4047
     ret
4048
 
4049
 
4050
reserve_free_irq:
4051
 
75 diamond 4052
     mov   ecx, 1
4053
     cmp   ebx, 16
4054
     jae   fril1
4055
     test  eax,eax
1 ha 4056
     jz    reserve_irq
4057
 
75 diamond 4058
     lea   edi,[irq_owner+ebx*4]
1 ha 4059
     mov   edx,[edi]
379 serge 4060
     mov   eax,[TASK_BASE]
115 poddubny 4061
     cmp   edx,[eax+TASKDATA.pid]
1 ha 4062
     jne   fril1
75 diamond 4063
     dec   ecx
4064
     mov   [edi],ecx
1 ha 4065
   fril1:
4066
     mov   [esp+36],ecx ; return in eax
4067
     ret
4068
 
4069
  reserve_irq:
4070
 
75 diamond 4071
     lea   edi,[irq_owner+ebx*4]
4072
     cmp   dword [edi], 0
4073
     jnz   ril1
1 ha 4074
 
379 serge 4075
     mov   edx,[TASK_BASE]
115 poddubny 4076
     mov   edx,[edx+TASKDATA.pid]
1 ha 4077
     mov   [edi],edx
75 diamond 4078
     dec   ecx
1 ha 4079
   ril1:
4080
     mov   [esp+36],ecx ; return in eax
4081
     ret
4082
 
4083
drawbackground:
33 mario79 4084
       inc   [mouse_pause]
381 serge 4085
       cmp   [SCR_MODE],word 0x12
117 mario79 4086
       je   dbrv20
1 ha 4087
     dbrv12:
381 serge 4088
       cmp  [SCR_MODE],word 0100000000000000b
1 ha 4089
       jge  dbrv20
381 serge 4090
       cmp  [SCR_MODE],word 0x13
1 ha 4091
       je   dbrv20
4092
       call  vesa12_drawbackground
33 mario79 4093
       dec   [mouse_pause]
36 mario79 4094
       call   [draw_pointer]
1 ha 4095
       ret
4096
     dbrv20:
527 diamond 4097
       cmp   [BgrDrawMode],dword 1
1 ha 4098
       jne   bgrstr
4099
       call  vesa20_drawbackground_tiled
33 mario79 4100
       dec   [mouse_pause]
36 mario79 4101
       call   [draw_pointer]
1 ha 4102
       ret
4103
     bgrstr:
4104
       call  vesa20_drawbackground_stretch
33 mario79 4105
       dec   [mouse_pause]
36 mario79 4106
       call   [draw_pointer]
1 ha 4107
       ret
4108
 
75 diamond 4109
align 4
1 ha 4110
 
429 serge 4111
syscall_putimage:                       ; PutImage
33 mario79 4112
 
75 diamond 4113
     mov   edx,ecx
4114
     mov   ecx,ebx
465 serge 4115
     mov   ebx, eax
75 diamond 4116
 
1 ha 4117
sys_putimage:
53 mikedld 4118
     test  ecx,0x80008000
4119
     jnz   .exit
4120
     test  ecx,0x0000FFFF
4121
     jz    .exit
4122
     test  ecx,0xFFFF0000
4123
     jnz   @f
4124
  .exit:
4125
     ret
4126
 @@:
465 serge 4127
        mov     edi,[current_slot]
4128
        add     dx,word[edi+APPDATA.wnd_clientbox.top]
429 serge 4129
        rol     edx,16
465 serge 4130
        add     dx,word[edi+APPDATA.wnd_clientbox.left]
429 serge 4131
        rol     edx,16
114 mikedld 4132
  .forced:
429 serge 4133
        push    ebp esi 0
4134
        mov     ebp, putimage_get24bpp
4135
        mov     esi, putimage_init24bpp
283 diamond 4136
sys_putimage_bpp:
4137
;        call    [disable_mouse] ; this will be done in xxx_putimage
117 mario79 4138
;        mov     eax, vga_putimage
429 serge 4139
        cmp     [SCR_MODE], word 0x12
4140
        jz      @f   ;.doit
4141
        mov     eax, vesa12_putimage
4142
        cmp     [SCR_MODE], word 0100000000000000b
4143
        jae     @f
4144
        cmp     [SCR_MODE], word 0x13
4145
        jnz     .doit
75 diamond 4146
@@:
429 serge 4147
        mov     eax, vesa20_putimage
75 diamond 4148
.doit:
429 serge 4149
        inc     [mouse_pause]
4150
        call    eax
4151
        dec     [mouse_pause]
4152
        pop     ebp esi ebp
4153
        jmp     [draw_pointer]
1 ha 4154
 
283 diamond 4155
syscall_putimage_palette:
465 serge 4156
        mov     edi, esi
429 serge 4157
        mov     esi, edx
4158
        mov     edx, ecx
4159
        mov     ecx, ebx
465 serge 4160
        mov     ebx, eax
283 diamond 4161
sys_putimage_palette:
4162
; ebx = pointer to image
4163
; ecx = [xsize]*65536 + [ysize]
4164
; edx = [xstart]*65536 + [ystart]
314 diamond 4165
; esi = number of bits per pixel, must be 8, 24 or 32
283 diamond 4166
; edi = pointer to palette
314 diamond 4167
; ebp = row delta
429 serge 4168
        mov     eax, [CURRENT_TASK]
4169
        shl     eax, 8
4170
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.top]
4171
        rol     edx, 16
4172
        add     dx, word [eax+SLOT_BASE+APPDATA.wnd_clientbox.left]
4173
        rol     edx, 16
283 diamond 4174
.forced:
429 serge 4175
        push    ebp esi ebp
4176
        cmp     esi, 8
4177
        jnz     @f
4178
        mov     ebp, putimage_get8bpp
4179
        mov     esi, putimage_init8bpp
4180
        jmp     sys_putimage_bpp
314 diamond 4181
@@:
429 serge 4182
        cmp     esi, 24
4183
        jnz     @f
4184
        mov     ebp, putimage_get24bpp
4185
        mov     esi, putimage_init24bpp
4186
        jmp     sys_putimage_bpp
314 diamond 4187
@@:
429 serge 4188
        cmp     esi, 32
4189
        jnz     @f
4190
        mov     ebp, putimage_get32bpp
4191
        mov     esi, putimage_init32bpp
4192
        jmp     sys_putimage_bpp
314 diamond 4193
@@:
429 serge 4194
        pop     ebp esi
4195
        ret
283 diamond 4196
 
4197
putimage_init24bpp:
429 serge 4198
        lea     eax, [eax*3]
283 diamond 4199
putimage_init8bpp:
429 serge 4200
        ret
283 diamond 4201
 
4202
putimage_get24bpp:
429 serge 4203
        mov     eax, [esi]
4204
        add     esi, 3
4205
        ret     4
283 diamond 4206
putimage_get8bpp:
429 serge 4207
        movzx   eax, byte [esi]
4208
        push    edx
4209
        mov     edx, [esp+8]
4210
        mov     eax, [edx+eax*4]
4211
        pop     edx
4212
        inc     esi
4213
        ret     4
283 diamond 4214
 
314 diamond 4215
putimage_init32bpp:
429 serge 4216
        shl     eax, 2
4217
        ret
314 diamond 4218
putimage_get32bpp:
429 serge 4219
        lodsd
4220
        ret     4
314 diamond 4221
 
1 ha 4222
; eax x beginning
4223
; ebx y beginning
4224
; ecx x end
283 diamond 4225
	; edx y end
1 ha 4226
; edi color
4227
 
4228
__sys_drawbar:
465 serge 4229
        mov     esi,[current_slot]
4230
        add     eax,[esi+APPDATA.wnd_clientbox.left]
4231
        add     ecx,[esi+APPDATA.wnd_clientbox.left]
4232
        add     ebx,[esi+APPDATA.wnd_clientbox.top]
4233
        add     edx,[esi+APPDATA.wnd_clientbox.top]
114 mikedld 4234
  .forced:
33 mario79 4235
    inc   [mouse_pause]
283 diamond 4236
;        call    [disable_mouse]
381 serge 4237
    cmp   [SCR_MODE],word 0x12
429 serge 4238
    je   dbv20
1 ha 4239
   sdbv20:
381 serge 4240
    cmp  [SCR_MODE],word 0100000000000000b
1 ha 4241
    jge  dbv20
381 serge 4242
    cmp  [SCR_MODE],word 0x13
429 serge 4243
    je   dbv20
1 ha 4244
    call vesa12_drawbar
33 mario79 4245
    dec   [mouse_pause]
36 mario79 4246
    call   [draw_pointer]
1 ha 4247
    ret
4248
  dbv20:
4249
    call vesa20_drawbar
33 mario79 4250
    dec   [mouse_pause]
36 mario79 4251
    call   [draw_pointer]
1 ha 4252
    ret
4253
 
4254
 
4255
 
4256
kb_read:
4257
 
429 serge 4258
        push    ecx edx
1 ha 4259
 
429 serge 4260
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4261
      kr_loop:
429 serge 4262
        in      al,0x64
4263
        test    al,1
4264
        jnz     kr_ready
4265
        loop    kr_loop
4266
        mov     ah,1
4267
        jmp     kr_exit
1 ha 4268
      kr_ready:
429 serge 4269
        push    ecx
4270
        mov     ecx,32
1 ha 4271
      kr_delay:
429 serge 4272
        loop    kr_delay
4273
        pop     ecx
4274
        in      al,0x60
4275
        xor     ah,ah
1 ha 4276
      kr_exit:
4277
 
429 serge 4278
        pop     edx ecx
1 ha 4279
 
429 serge 4280
        ret
1 ha 4281
 
4282
 
4283
kb_write:
4284
 
429 serge 4285
        push    ecx edx
1 ha 4286
 
429 serge 4287
        mov     dl,al
265 diamond 4288
;        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
4289
;      kw_loop1:
4290
;        in      al,0x64
4291
;        test    al,0x20
4292
;        jz      kw_ok1
4293
;        loop    kw_loop1
4294
;        mov     ah,1
4295
;        jmp     kw_exit
4296
;      kw_ok1:
429 serge 4297
        in      al,0x60
4298
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4299
      kw_loop:
429 serge 4300
        in      al,0x64
4301
        test    al,2
4302
        jz      kw_ok
4303
        loop    kw_loop
4304
        mov     ah,1
4305
        jmp     kw_exit
1 ha 4306
      kw_ok:
429 serge 4307
        mov     al,dl
4308
        out     0x60,al
4309
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4310
      kw_loop3:
429 serge 4311
        in      al,0x64
4312
        test    al,2
4313
        jz      kw_ok3
4314
        loop    kw_loop3
4315
        mov     ah,1
4316
        jmp     kw_exit
1 ha 4317
      kw_ok3:
429 serge 4318
        mov     ah,8
1 ha 4319
      kw_loop4:
429 serge 4320
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4321
      kw_loop5:
429 serge 4322
        in      al,0x64
4323
        test    al,1
4324
        jnz     kw_ok4
4325
        loop    kw_loop5
4326
        dec     ah
4327
        jnz     kw_loop4
1 ha 4328
      kw_ok4:
429 serge 4329
        xor     ah,ah
1 ha 4330
      kw_exit:
4331
 
429 serge 4332
        pop     edx ecx
1 ha 4333
 
429 serge 4334
        ret
1 ha 4335
 
4336
 
4337
kb_cmd:
4338
 
429 serge 4339
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4340
      c_wait:
429 serge 4341
        in      al,0x64
4342
        test    al,2
4343
        jz      c_send
4344
        loop    c_wait
4345
        jmp     c_error
1 ha 4346
      c_send:
429 serge 4347
        mov     al,bl
4348
        out     0x64,al
4349
        mov     ecx,0x1ffff ; last 0xffff, new value in view of fast CPU's
1 ha 4350
      c_accept:
429 serge 4351
        in      al,0x64
4352
        test    al,2
4353
        jz      c_ok
4354
        loop    c_accept
1 ha 4355
      c_error:
429 serge 4356
        mov     ah,1
4357
        jmp     c_exit
1 ha 4358
      c_ok:
429 serge 4359
        xor     ah,ah
1 ha 4360
      c_exit:
429 serge 4361
        ret
1 ha 4362
 
4363
 
4364
setmouse:  ; set mousepicture -pointer
429 serge 4365
           ; ps2 mouse enable
1 ha 4366
 
381 serge 4367
     mov     [MOUSE_PICTURE],dword mousepointer
1 ha 4368
 
4369
     cli
33 mario79 4370
;     mov     bl,0xa8                 ; enable mouse cmd
4371
;     call    kb_cmd
4372
;     call    kb_read                 ; read status
4373
;     mov     bl,0x20                 ; get command byte
4374
;     call    kb_cmd
4375
;     call    kb_read
4376
;     or      al,3                    ; enable interrupt
4377
;     mov     bl,0x60                 ; write command
4378
;     push    eax
4379
;     call    kb_cmd
4380
;     pop     eax
4381
;     call    kb_write
4382
;     mov     bl,0xd4                 ; for mouse
4383
;     call    kb_cmd
4384
;     mov     al,0xf4                 ; enable mouse device
4385
;     call    kb_write
4386
;     call    kb_read           ; read status return
1 ha 4387
 
4388
     ; com1 mouse enable
4389
 
4390
     mov   bx,0x3f8 ; combase
4391
 
4392
     mov   dx,bx
4393
     add   dx,3
4394
     mov   al,0x80
4395
     out   dx,al
4396
 
4397
     mov   dx,bx
4398
     add   dx,1
4399
     mov   al,0
4400
     out   dx,al
4401
 
4402
     mov   dx,bx
4403
     add   dx,0
429 serge 4404
     mov   al,0x30*2    ; 0x30 / 4
1 ha 4405
     out   dx,al
4406
 
4407
     mov   dx,bx
4408
     add   dx,3
429 serge 4409
     mov   al,2         ; 3
1 ha 4410
     out   dx,al
4411
 
4412
     mov   dx,bx
4413
     add   dx,4
4414
     mov   al,0xb
4415
     out   dx,al
4416
 
4417
     mov   dx,bx
4418
     add   dx,1
4419
     mov   al,1
4420
     out   dx,al
4421
 
4422
 
4423
     ; com2 mouse enable
4424
 
4425
     mov   bx,0x2f8 ; combase
4426
 
4427
     mov   dx,bx
4428
     add   dx,3
4429
     mov   al,0x80
4430
     out   dx,al
4431
 
4432
     mov   dx,bx
4433
     add   dx,1
4434
     mov   al,0
4435
     out   dx,al
4436
 
4437
     mov   dx,bx
4438
     add   dx,0
4439
     mov   al,0x30*2
4440
     out   dx,al
4441
 
4442
     mov   dx,bx
4443
     add   dx,3
4444
     mov   al,2
4445
     out   dx,al
4446
 
4447
     mov   dx,bx
4448
     add   dx,4
4449
     mov   al,0xb
4450
     out   dx,al
4451
 
4452
     mov   dx,bx
4453
     add   dx,1
4454
     mov   al,1
4455
     out   dx,al
4456
 
4457
     ret
4458
 
4459
 
4460
_rdtsc:
164 serge 4461
     bt [cpu_caps], CAPS_TSC
4462
     jnc ret_rdtsc
1 ha 4463
     rdtsc
4464
     ret
4465
   ret_rdtsc:
4466
     mov   edx,0xffffffff
4467
     mov   eax,0xffffffff
4468
     ret
4469
 
4470
rerouteirqs:
4471
 
429 serge 4472
        cli
1 ha 4473
 
429 serge 4474
        mov     al,0x11         ;  icw4, edge triggered
4475
        out     0x20,al
4476
        call    pic_delay
4477
        out     0xA0,al
4478
        call    pic_delay
1 ha 4479
 
429 serge 4480
        mov     al,0x20         ;  generate 0x20 +
4481
        out     0x21,al
4482
        call    pic_delay
4483
        mov     al,0x28         ;  generate 0x28 +
4484
        out     0xA1,al
4485
        call    pic_delay
1 ha 4486
 
429 serge 4487
        mov     al,0x04         ;  slave at irq2
4488
        out     0x21,al
4489
        call    pic_delay
4490
        mov     al,0x02         ;  at irq9
4491
        out     0xA1,al
4492
        call    pic_delay
1 ha 4493
 
429 serge 4494
        mov     al,0x01         ;  8086 mode
4495
        out     0x21,al
4496
        call    pic_delay
4497
        out     0xA1,al
4498
        call    pic_delay
1 ha 4499
 
429 serge 4500
        mov     al,255          ; mask all irq's
4501
        out     0xA1,al
4502
        call    pic_delay
4503
        out     0x21,al
4504
        call    pic_delay
1 ha 4505
 
429 serge 4506
        mov     ecx,0x1000
4507
        cld
4508
picl1:  call    pic_delay
4509
        loop    picl1
1 ha 4510
 
429 serge 4511
        mov     al,255          ; mask all irq's
4512
        out     0xA1,al
4513
        call    pic_delay
4514
        out     0x21,al
4515
        call    pic_delay
1 ha 4516
 
429 serge 4517
        cli
1 ha 4518
 
429 serge 4519
        ret
1 ha 4520
 
4521
 
4522
pic_delay:
4523
 
429 serge 4524
        jmp     pdl1
4525
pdl1:   ret
1 ha 4526
 
4527
 
4528
sys_msg_board_str:
4529
 
4530
     pushad
4531
   @@:
4532
     cmp    [esi],byte 0
4533
     je     @f
4534
     mov    eax,1
4535
     movzx  ebx,byte [esi]
4536
     call   sys_msg_board
4537
     inc    esi
4538
     jmp    @b
4539
   @@:
4540
     popad
4541
     ret
4542
 
4543
uglobal
373 mikedld 4544
  msg_board_data: times 4096 db 0
1 ha 4545
  msg_board_count dd 0x0
4546
endg
4547
 
4548
sys_msg_board:
4549
 
4550
; eax=1 : write :  bl byte to write
4551
; eax=2 :  read :  ebx=0 -> no data, ebx=1 -> data in al
4552
 
4553
     mov  ecx,[msg_board_count]
4554
     cmp  eax, 1
4555
     jne  smbl1
4556
 
4557
 
4558
     mov  [msg_board_data+ecx],bl
4559
     inc  ecx
373 mikedld 4560
     and  ecx, 4095
1 ha 4561
     mov  [msg_board_count], ecx
4562
     mov  [check_idle_semaphore], 5
4563
     ret
4564
   smbl1:
4565
 
4566
     cmp   eax, 2
4567
     jne   smbl2
4568
     test  ecx, ecx
4569
     jz    smbl21
4570
;     mov   edi, msg_board_data
4571
;     mov   esi, msg_board_data+1
4572
;     movzx eax, byte [edi]
4573
     mov   eax, msg_board_data+1
4574
     mov   ebx, msg_board_data
4575
     movzx edx, byte [ebx]
4576
     call  memmove
4577
;     push  ecx
4578
;     shr   ecx, 2
4579
;     cld
4580
;     rep   movsd
4581
;     pop   ecx
4582
;     and   ecx, 3
4583
;     rep   movsb
4584
     dec   [msg_board_count]
4585
     mov   [esp+36], edx ;eax
4586
     mov   [esp+24], dword 1
4587
     ret
4588
   smbl21:
4589
     mov   [esp+36], ecx
4590
     mov   [esp+24], ecx
4591
 
4592
   smbl2:
4593
     ret
4594
 
4595
 
4596
 
4597
sys_process_def:
429 serge 4598
        mov     edi, [CURRENT_TASK]
1 ha 4599
 
429 serge 4600
        dec     eax             ; 1 = set keyboard mode
1 ha 4601
     jne   no_set_keyboard_setup
4602
 
4603
     shl   edi,8
380 serge 4604
     mov   [edi+SLOT_BASE + APPDATA.keyboard_mode],bl
1 ha 4605
 
4606
     ret
4607
 
4608
   no_set_keyboard_setup:
4609
 
429 serge 4610
        dec     eax             ; 2 = get keyboard mode
1 ha 4611
     jne   no_get_keyboard_setup
4612
 
4613
     shl   edi,8
380 serge 4614
     movzx eax, byte [SLOT_BASE+edi + APPDATA.keyboard_mode]
1 ha 4615
 
4616
     mov   [esp+36],eax
4617
 
4618
     ret
4619
 
4620
   no_get_keyboard_setup:
4621
 
429 serge 4622
        dec     eax             ; 3 = get keyboard ctrl, alt, shift
1 ha 4623
     jne   no_get_keyboard_cas
4624
 
4625
;     xor   eax,eax
4626
;     movzx eax,byte [shift]
4627
;     movzx ebx,byte [ctrl]
4628
;     shl   ebx,2
4629
;     add   eax,ebx
4630
;     movzx ebx,byte [alt]
4631
;     shl   ebx,3
4632
;     add   eax,ebx
4633
 
4634
 ;// mike.dld [
4635
     mov   eax, [kb_state]
4636
 ;// mike.dld ]
4637
 
4638
     mov   [esp+36],eax
4639
 
4640
     ret
4641
 
4642
   no_get_keyboard_cas:
4643
 
429 serge 4644
        dec     eax
4645
        jnz     no_add_keyboard_hotkey
1 ha 4646
 
429 serge 4647
        mov     eax, hotkey_list
92 diamond 4648
@@:
429 serge 4649
        cmp     dword [eax+8], 0
4650
        jz      .found_free
4651
        add     eax, 16
4652
        cmp     eax, hotkey_list+16*256
4653
        jb      @b
4654
        mov     dword [esp+36], 1
4655
        ret
92 diamond 4656
.found_free:
429 serge 4657
        mov     [eax+8], edi
4658
        mov     [eax+4], ecx
4659
        movzx   ebx, bl
4660
        lea     ebx, [hotkey_scancodes+ebx*4]
4661
        mov     ecx, [ebx]
4662
        mov     [eax], ecx
4663
        mov     [ebx], eax
4664
        mov     [eax+12], ebx
4665
        jecxz   @f
4666
        mov     [ecx+12], eax
92 diamond 4667
@@:
429 serge 4668
        and     dword [esp+36], 0
4669
        ret
92 diamond 4670
 
4671
no_add_keyboard_hotkey:
4672
 
429 serge 4673
        dec     eax
4674
        jnz     no_del_keyboard_hotkey
92 diamond 4675
 
429 serge 4676
        movzx   ebx, bl
4677
        lea     ebx, [hotkey_scancodes+ebx*4]
4678
        mov     eax, [ebx]
92 diamond 4679
.scan:
429 serge 4680
        test    eax, eax
4681
        jz      .notfound
4682
        cmp     [eax+8], edi
4683
        jnz     .next
4684
        cmp     [eax+4], ecx
4685
        jz      .found
92 diamond 4686
.next:
429 serge 4687
        mov     eax, [eax]
4688
        jmp     .scan
92 diamond 4689
.notfound:
429 serge 4690
        mov     dword [esp+36], 1
4691
        ret
92 diamond 4692
.found:
429 serge 4693
        mov     ecx, [eax]
4694
        jecxz   @f
4695
        mov     edx, [eax+12]
4696
        mov     [ecx+12], edx
92 diamond 4697
@@:
429 serge 4698
        mov     ecx, [eax+12]
4699
        mov     edx, [eax]
4700
        mov     [ecx], edx
4701
        xor     edx, edx
4702
        mov     [eax+4], edx
4703
        mov     [eax+8], edx
4704
        mov     [eax+12], edx
4705
        mov     [eax], edx
4706
        mov     [esp+36], edx
4707
        ret
92 diamond 4708
 
4709
no_del_keyboard_hotkey:
1 ha 4710
     ret
4711
 
4712
 
4713
align 4
4714
 
429 serge 4715
sys_gs:                         ; direct screen access
1 ha 4716
 
429 serge 4717
     cmp  eax,1                 ; resolution
1 ha 4718
     jne  no_gs1
381 serge 4719
     mov  eax,[ScreenWidth]
1 ha 4720
     shl  eax,16
381 serge 4721
     mov  ax,[ScreenHeight]
1 ha 4722
     add  eax,0x00010001
4723
     mov  [esp+36],eax
4724
     ret
4725
   no_gs1:
4726
 
429 serge 4727
     cmp   eax,2                ; bits per pixel
1 ha 4728
     jne   no_gs2
381 serge 4729
     movzx eax,byte [ScreenBPP]
1 ha 4730
     mov   [esp+36],eax
4731
     ret
4732
   no_gs2:
4733
 
429 serge 4734
     cmp   eax,3                ; bytes per scanline
1 ha 4735
     jne   no_gs3
381 serge 4736
     mov   eax,[BytesPerScanLine]
1 ha 4737
     mov   [esp+36],eax
4738
     ret
4739
   no_gs3:
4740
 
4741
     mov  [esp+36],dword -1
4742
     ret
4743
 
4744
 
4745
align 4 ; PCI functions
4746
 
4747
sys_pci:
4748
 
4749
     call  pci_api
4750
     mov   [esp+36],eax
4751
     ret
4752
 
4753
 
4754
align 4  ;  system functions
4755
 
429 serge 4756
syscall_setpixel:                       ; SetPixel
1 ha 4757
 
4758
 
379 serge 4759
     mov   edx,[TASK_BASE]
115 poddubny 4760
     add   eax,[edx-twdw+WDATA.box.left]
4761
     add   ebx,[edx-twdw+WDATA.box.top]
465 serge 4762
        mov     edi,[current_slot]
4763
        add     eax,[edi+APPDATA.wnd_clientbox.left]
4764
        add     ebx,[edi+APPDATA.wnd_clientbox.top]
112 poddubny 4765
     xor   edi,edi ; no force
114 mikedld 4766
;     mov   edi,1
112 poddubny 4767
     call  [disable_mouse]
1 ha 4768
     jmp   [putpixel]
4769
 
4770
align 4
4771
 
429 serge 4772
syscall_writetext:                      ; WriteText
1 ha 4773
 
465 serge 4774
        mov   edi,[TASK_BASE]
4775
        mov   ebp,[edi-twdw+WDATA.box.left]
4776
        push  esi
4777
        mov   esi,[current_slot]
4778
        add   ebp,[esi+APPDATA.wnd_clientbox.left]
4779
        shl   ebp,16
4780
        add   ebp,[edi-twdw+WDATA.box.top]
4781
        add   bp,word[esi+APPDATA.wnd_clientbox.top]
4782
        pop   esi
4783
        add   ecx,[edi+TASKDATA.mem_start]
4784
        add   eax,ebp
4785
        xor   edi,edi
4786
        jmp   dtext
1 ha 4787
 
4788
align 4
4789
 
429 serge 4790
syscall_openramdiskfile:                ; OpenRamdiskFile
1 ha 4791
 
4792
 
379 serge 4793
     mov   edi,[TASK_BASE]
164 serge 4794
     add   edi,TASKDATA.mem_start
1 ha 4795
     add   eax,[edi]
4796
     add   edx,[edi]
4797
     mov   esi,12
4798
     call  fileread
4799
     mov   [esp+36],ebx
4800
     ret
4801
 
4802
align 4
4803
 
429 serge 4804
syscall_drawrect:                       ; DrawRect
1 ha 4805
 
4806
     mov   edi,ecx
52 mikedld 4807
     and   edi,0x80FFFFFF
1 ha 4808
     test  ax,ax
4809
     je    drectr
4810
     test  bx,bx
4811
     je    drectr
4812
     movzx ecx,ax
4813
     shr   eax,16
4814
     movzx edx,bx
4815
     shr   ebx,16
465 serge 4816
        mov     esi,[current_slot]
4817
        add     eax,[esi+APPDATA.wnd_clientbox.left]
4818
        add     ebx,[esi+APPDATA.wnd_clientbox.top]
1 ha 4819
     add   ecx,eax
4820
     add   edx,ebx
4821
     jmp   [drawbar]
4822
    drectr:
4823
     ret
4824
 
4825
align 4
4826
 
429 serge 4827
syscall_getscreensize:                  ; GetScreenSize
1 ha 4828
 
381 serge 4829
     movzx eax,word[ScreenWidth]
1 ha 4830
     shl   eax,16
381 serge 4831
     mov   ax,[ScreenHeight]
1 ha 4832
     mov   [esp+36],eax
4833
     ret
4834
 
4835
align 4
4836
 
429 serge 4837
syscall_cdaudio:                        ; CD
1 ha 4838
 
4839
     call  sys_cd_audio
4840
     mov   [esp+36],eax
4841
     ret
4842
 
4843
align 4
4844
 
429 serge 4845
syscall_delramdiskfile:                 ; DelRamdiskFile
1 ha 4846
 
379 serge 4847
     mov   edi,[TASK_BASE]
164 serge 4848
     add   edi,TASKDATA.mem_start
1 ha 4849
     add   eax,[edi]
4850
     call  filedelete
4851
     mov   [esp+36],eax
4852
     ret
4853
 
4854
align 4
4855
 
429 serge 4856
syscall_writeramdiskfile:               ; WriteRamdiskFile
1 ha 4857
 
379 serge 4858
     mov   edi,[TASK_BASE]
164 serge 4859
     add   edi,TASKDATA.mem_start
1 ha 4860
     add   eax,[edi]
4861
     add   ebx,[edi]
4862
     call  filesave
4863
     mov   [esp+36],eax
4864
     ret
4865
 
4866
align 4
4867
 
429 serge 4868
syscall_getpixel:                       ; GetPixel
381 serge 4869
     mov   ecx,[ScreenWidth]
1 ha 4870
     inc   ecx
4871
     xor   edx,edx
4872
     div   ecx
4873
     mov   ebx,edx
4874
     xchg  eax,ebx
465 serge 4875
     call  dword [GETPIXEL]
1 ha 4876
     mov   [esp+36],ecx
4877
     ret
4878
 
4879
align 4
4880
 
429 serge 4881
syscall_readstring:                     ; ReadString
1 ha 4882
 
379 serge 4883
     mov   edi,[TASK_BASE]
164 serge 4884
     add   edi,TASKDATA.mem_start
1 ha 4885
     add   eax,[edi]
4886
     call  read_string
4887
     mov   [esp+36],eax
4888
     ret
4889
 
4890
align 4
4891
 
429 serge 4892
syscall_drawline:                       ; DrawLine
1 ha 4893
 
379 serge 4894
     mov   edi,[TASK_BASE]
115 poddubny 4895
     movzx edx,word[edi-twdw+WDATA.box.left]
1 ha 4896
     mov   ebp,edx
465 serge 4897
        mov     esi,[current_slot]
4898
        add     ebp,[esi+APPDATA.wnd_clientbox.left]
4899
        add     dx,word[esi+APPDATA.wnd_clientbox.left]
1 ha 4900
     shl   edx,16
4901
     add   ebp,edx
115 poddubny 4902
     movzx edx,word[edi-twdw+WDATA.box.top]
1 ha 4903
     add   eax,ebp
4904
     mov   ebp,edx
465 serge 4905
        add     ebp,[esi+APPDATA.wnd_clientbox.top]
4906
        add     dx,word[esi+APPDATA.wnd_clientbox.top]
1 ha 4907
     shl   edx,16
4908
     xor   edi,edi
4909
     add   edx,ebp
4910
     add   ebx,edx
4911
     jmp   [draw_line]
4912
 
4913
align 4
4914
 
429 serge 4915
syscall_getirqowner:                    ; GetIrqOwner
75 diamond 4916
     cmp   eax,16
4917
     jae   .err
1 ha 4918
     shl   eax,2
4919
     add   eax,irq_owner
4920
     mov   eax,[eax]
4921
     mov   [esp+36],eax
4922
     ret
75 diamond 4923
.err:
4924
     or    dword [esp+36], -1
4925
     ret
1 ha 4926
 
4927
align 4
4928
 
429 serge 4929
syscall_reserveportarea:                ; ReservePortArea and FreePortArea
1 ha 4930
 
4931
     call  r_f_port_area
4932
     mov   [esp+36],eax
4933
     ret
4934
 
4935
align 4
4936
 
429 serge 4937
syscall_threads:                        ; CreateThreads
1 ha 4938
 
4939
     call  sys_threads
4940
     mov   [esp+36],eax
4941
     ret
4942
 
4943
align 4
4944
 
4945
stack_driver_stat:
4946
 
429 serge 4947
     call  app_stack_handler            ; Stack status
1 ha 4948
 
4949
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4950
;     call  change_task                 ; between sent packet
4951
 
4952
     mov   [esp+36],eax
4953
     ret
4954
 
4955
align 4
4956
 
429 serge 4957
socket:                                 ; Socket interface
1 ha 4958
     call  app_socket_handler
4959
 
4960
;     mov   [check_idle_semaphore],5    ; enable these for zero delay
4961
;     call  change_task                 ; between sent packet
4962
 
4963
     mov   [esp+36],eax
4964
     mov   [esp+24],ebx
4965
     ret
4966
 
4967
align 4
4968
 
429 serge 4969
user_events:                            ; User event times
1 ha 4970
 
4971
     mov   eax,0x12345678
4972
     mov   [esp+36],eax
4973
 
4974
     ret
4975
 
4976
align 4
4977
 
429 serge 4978
read_from_hd:                           ; Read from hd - fn not in use
1 ha 4979
 
379 serge 4980
     mov   edi,[TASK_BASE]
115 poddubny 4981
     add   edi,TASKDATA.mem_start
1 ha 4982
     add   eax,[edi]
4983
     add   ecx,[edi]
4984
     add   edx,[edi]
4985
     call  file_read
4986
 
4987
     mov   [esp+36],eax
4988
     mov   [esp+24],ebx
4989
 
4990
     ret
4991
 
375 Ghost 4992
align 4
4993
paleholder:
4994
	ret
378 serge 4995
 
76 mario79 4996
; --------------- APM ---------------------
4997
apm_entry    dp    0
429 serge 4998
apm_vf        dd    0
1 ha 4999
align 4
76 mario79 5000
sys_apm:
5001
    cmp    word [apm_vf], 0    ; Check APM BIOS enable
5002
    jne    @f
429 serge 5003
    or    [esp + 56], byte 1    ; error
5004
    mov    [esp + 36], dword 8    ; 32-bit protected-mode interface not supported
76 mario79 5005
    ret
164 serge 5006
 
465 serge 5007
@@:
5008
    xchg    eax, ecx
76 mario79 5009
    xchg    ebx, ecx
164 serge 5010
 
76 mario79 5011
    cmp    al, 3
429 serge 5012
    ja    @f
78 diamond 5013
    and    [esp + 56], byte 0xfe    ; emulate func 0..3 as func 0
76 mario79 5014
    mov    eax, [apm_vf]
5015
    mov    [esp + 36], eax
5016
    shr    eax, 16
5017
    mov    [esp + 32], eax
5018
    ret
78 diamond 5019
 
465 serge 5020
@@:
5021
 
5022
    mov esi, [master_tab+(OS_BASE shr 20)]
5023
    xchg [master_tab], esi
5024
    push esi
5025
    mov edi, cr3
5026
    mov cr3, edi                 ;flush TLB
5027
 
5028
    call    pword [apm_entry]    ; call APM BIOS
5029
 
5030
    xchg eax, [esp]
5031
    mov [master_tab], eax
5032
    mov eax, cr3
5033
    mov cr3, eax
5034
    pop eax
5035
 
76 mario79 5036
    mov    [esp + 8 ], edi
5037
    mov    [esp + 12], esi
5038
    mov    [esp + 24], ebx
5039
    mov    [esp + 28], edx
5040
    mov    [esp + 32], ecx
5041
    mov    [esp + 36], eax
5042
    setc    al
78 diamond 5043
    and    [esp + 56], byte 0xfe
429 serge 5044
    or    [esp + 56], al
465 serge 5045
 
5046
 
76 mario79 5047
    ret
5048
; -----------------------------------------
1 ha 5049
 
76 mario79 5050
align 4
5051
 
429 serge 5052
undefined_syscall:                      ; Undefined system call
1 ha 5053
 
5054
     mov   [esp+36],dword -1
5055
     ret
5056
 
465 serge 5057
align 4
5058
system_shutdown:          ; shut down the system
1 ha 5059
 
465 serge 5060
           cmp byte [BOOT_VAR+0x9030], 1
5061
           jne @F
5062
           ret
5063
@@:
5064
           call stop_all_services
5065
           push 3                ; stop playing cd
5066
           pop  eax
5067
           call sys_cd_audio
1 ha 5068
 
465 serge 5069
yes_shutdown_param:
5070
           cli
1 ha 5071
 
465 serge 5072
           mov  eax, kernel_file ; load kernel.mnt to 0x8000:0
5073
           push 12
5074
           pop  esi
5075
           xor  ebx,ebx
5076
           or   ecx,-1
5077
           mov  edx, OS_BASE+0x80000
5078
           call fileread
1 ha 5079
 
465 serge 5080
           mov  esi, restart_kernel_4000+OS_BASE+0x10000 ; move kernel re-starter to 0x4000:0
5081
           mov  edi,OS_BASE+0x40000
5082
           mov  ecx,1000
5083
           rep  movsb
1 ha 5084
 
465 serge 5085
           mov  esi,OS_BASE+0x2F0000    ; restore 0x0 - 0xffff
5086
           mov  edi, OS_BASE
5087
           mov  ecx,0x10000/4
5088
           cld
5089
           rep movsd
1 ha 5090
 
465 serge 5091
           call restorefatchain
1 ha 5092
 
465 serge 5093
           mov al, 0xFF
5094
           out 0x21, al
5095
           out 0xA1, al
1 ha 5096
 
465 serge 5097
           mov  word [OS_BASE+0x467+0],pr_mode_exit
5098
           mov  word [OS_BASE+0x467+2],0x1000
1 ha 5099
 
465 serge 5100
           mov  al,0x0F
5101
           out  0x70,al
5102
           mov  al,0x05
5103
           out  0x71,al
1 ha 5104
 
465 serge 5105
           mov  al,0xFE
5106
           out  0x64,al
5107
           hlt
1 ha 5108
 
5109
 
465 serge 5110
include "data32.inc"
1 ha 5111
 
465 serge 5112
__REV__ = __REV
1 ha 5113
 
5114
uglobals_size = $ - endofcode
41 mikedld 5115
diff16 "end of kernel code",0,$
426 mikedld 5116