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