Subversion Repositories Kolibri OS

Rev

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