Subversion Repositories Kolibri OS

Rev

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