Subversion Repositories Kolibri OS

Rev

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