Subversion Repositories Kolibri OS

Rev

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