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