Subversion Repositories Kolibri OS

Rev

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

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