Subversion Repositories Kolibri OS

Rev

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