Subversion Repositories Kolibri OS

Rev

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

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