Subversion Repositories Kolibri OS

Rev

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