Subversion Repositories Kolibri OS

Rev

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