Subversion Repositories Kolibri OS

Rev

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