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