Rev 1 | Rev 27 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ha | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; |
||
3 | ;; Shutdown for Menuet |
||
4 | ;; |
||
5 | ;; Distributed under General Public License |
||
6 | ;; See file COPYING for details. |
||
7 | ;; Copyright 2003 Ville Turjanmaa |
||
8 | ;; |
||
9 | |||
10 | |||
11 | system_shutdown: ; shut down the system |
||
12 | |||
13 | mov eax,3 ; stop playing cd |
||
14 | call sys_cd_audio |
||
15 | cli |
||
16 | cld |
||
17 | |||
18 | mov al,[0x2f0000+0x9030] |
||
19 | cmp al,1 |
||
20 | jl no_shutdown_parameter |
||
21 | cmp al,4 |
||
22 | jg no_shutdown_parameter |
||
23 | jmp yes_shutdown_param |
||
24 | no_shutdown_parameter: |
||
25 | |||
26 | movzx ecx,word [0x2f0000+0x900A] |
||
27 | movzx esi,word [0x2f0000+0x900C] |
||
28 | imul ecx,esi ;[0xfe04] |
||
29 | ; mov ecx,0x500000/4 ;3fff00/4 ; darken screen |
||
30 | push ecx |
||
31 | mov esi,[0xfe80] |
||
32 | cmp esi,32*0x100000 |
||
33 | jbe no_darken_screen |
||
34 | mov edi,16*0x100000 |
||
35 | sdnewpix: |
||
36 | mov eax,[esi] |
||
37 | add esi,4 |
||
38 | shr eax,1 |
||
39 | and eax,0x7f7f7f7f |
||
40 | stosd |
||
41 | loop sdnewpix |
||
42 | pop ecx |
||
43 | mov esi,16*0x100000 |
||
44 | mov edi,[0xfe80] |
||
45 | cld |
||
46 | rep movsd |
||
47 | no_darken_screen: |
||
48 | |||
49 | mov eax,[0xfe00] |
||
50 | shr eax,1 |
||
51 | sub eax,220 |
||
52 | |||
53 | mov ebx,[0xfe04] |
||
54 | shr ebx,1 |
||
55 | mov [shutdownpos],ebx |
||
56 | sub ebx,120 |
||
57 | |||
58 | mov edi,1 |
||
59 | mov ecx,0x0000ff |
||
60 | |||
61 | sdnewpix2: |
||
62 | |||
63 | call [putpixel] |
||
64 | |||
65 | inc eax |
||
66 | mov esi,[0xfe00] |
||
67 | shr esi,1 |
||
68 | add esi,220 |
||
69 | cmp eax,esi |
||
70 | jnz sdnewpix2 |
||
71 | |||
72 | dec ecx |
||
73 | |||
74 | mov eax,[0xfe00] |
||
75 | shr eax,1 |
||
76 | sub eax,220 |
||
77 | |||
78 | inc ebx |
||
79 | |||
80 | mov edx,[shutdownpos] |
||
81 | add edx,105 |
||
82 | cmp ebx,edx |
||
83 | jnz sdnewpix2 |
||
84 | |||
85 | |||
86 | mov esi,[0xfe00] ; menuet version |
||
87 | shr esi,1 |
||
88 | sub esi,220 |
||
89 | add esi,27 |
||
90 | shl esi,16 |
||
91 | mov eax,esi |
||
92 | add eax,[shutdownpos] |
||
93 | sub eax,105 |
||
94 | mov ebx,0xffff00 |
||
95 | mov ecx,version |
||
96 | mov edx,34 |
||
97 | mov edi,1 |
||
98 | call dtext |
||
99 | |||
100 | mov esi,[0xfe00] ; 'it is safe..' |
||
101 | shr esi,1 |
||
102 | sub esi,220 |
||
103 | add esi,27 |
||
104 | shl esi,16 |
||
105 | mov eax,esi |
||
106 | add eax,[shutdownpos] |
||
107 | add eax,33 |
||
108 | mov esi,6 |
||
109 | mov ebx,0xffffff |
||
110 | mov ecx,shutdowntext |
||
111 | mov edx,40 |
||
112 | mov edi,1 |
||
113 | newsdt: |
||
114 | call dtext |
||
115 | add eax,10 |
||
116 | add ecx,40 |
||
117 | dec esi |
||
118 | jnz newsdt |
||
119 | |||
120 | mov eax,rosef ; load rose.txt |
||
121 | mov ebx,0 |
||
122 | mov ecx,16800 |
||
123 | mov edx,0x90000 |
||
124 | mov esi,12 |
||
125 | call fileread |
||
126 | |||
127 | mov esi,[0xfe00] ; draw rose |
||
128 | shr esi,1 |
||
129 | add esi,20 |
||
130 | shl esi,16 |
||
131 | mov eax,esi |
||
132 | add eax,[shutdownpos] |
||
133 | sub eax,110 |
||
134 | |||
135 | mov ebx,0x00ff00 |
||
136 | mov ecx,0x90001 |
||
137 | mov edx,27 |
||
138 | mov edi,1 |
||
139 | |||
140 | nrl: |
||
141 | call dtext |
||
142 | sub ebx,0x050000 |
||
143 | add eax,8 |
||
144 | add ecx,31 |
||
145 | cmp ecx,dword 0x90001+25*31 |
||
146 | jnz nrl |
||
147 | |||
148 | call checkEgaCga |
||
149 | |||
150 | yes_shutdown_param: |
||
151 | |||
152 | cli |
||
153 | |||
154 | mov eax,kernel ; load kernel.mnt to 0x8000:0 |
||
155 | mov esi,12 |
||
156 | mov ebx,0 |
||
157 | mov ecx,-1 |
||
158 | mov edx,0x80000 |
||
159 | call fileread |
||
160 | |||
161 | mov esi,restart_kernel_4000 ; move kernel re-starter to 0x4000:0 |
||
162 | mov edi,0x40000 |
||
163 | mov ecx,1000 |
||
164 | cld |
||
165 | rep movsb |
||
166 | |||
167 | mov eax,0x2F0000 ; restore 0x0 - 0xffff |
||
168 | mov ebx,0x0000 |
||
169 | mov ecx,0xffff |
||
170 | call memmove |
||
171 | |||
172 | call restorefatchain |
||
173 | |||
174 | mov eax,pr_mode_exit |
||
175 | mov [0x467+0],ax |
||
176 | mov [0x467+2],word 0x1000 |
||
177 | |||
178 | mov al,0x0F |
||
179 | out 0x70,al |
||
180 | mov al,0x05 |
||
181 | out 0x71,al |
||
182 | |||
183 | mov al,0xFE |
||
184 | out 0x64,al |
||
185 | hlt |
||
186 | |||
187 | use16 |
||
188 | |||
189 | pr_mode_exit: |
||
190 | |||
191 | mov ax,1000 |
||
192 | mov ds,ax |
||
193 | mov es,ax |
||
194 | mov fs,ax |
||
195 | mov gs,ax |
||
196 | mov ss,ax |
||
197 | ; mov bl,[shutdown_parameter] |
||
198 | mov al,2 |
||
199 | out 0x21,al |
||
200 | mov al,0 |
||
201 | out 0xA1,al |
||
202 | |||
203 | ; mov [es:shutdown_parameter-0x10000],bl |
||
204 | |||
205 | jmp real_mode-0x10000 |
||
206 | |||
207 | old_ints_h: |
||
208 | dw 4*0x20 |
||
209 | dd 0 |
||
210 | dw 0 |
||
211 | |||
212 | real_mode: |
||
213 | |||
214 | lidt [cs:old_ints_h-0x10000] |
||
215 | mov sp,0xfff0 |
||
216 | |||
217 | sti |
||
218 | |||
219 | jmp temp_3456 |
||
220 | |||
221 | nbw: |
||
222 | xor ax,ax |
||
223 | in al,0x60 |
||
224 | call pause_key |
||
225 | cmp al,7 |
||
226 | jge nbw |
||
227 | mov bl,al |
||
228 | nbw2: |
||
229 | in al,0x60 |
||
230 | call pause_key |
||
231 | cmp al,bl |
||
232 | je nbw2 |
||
233 | cmp al,240 ;ax,240 |
||
234 | jne nbw31 |
||
235 | mov al,bl |
||
236 | dec al |
||
237 | jmp nbw32 |
||
238 | nbw31: |
||
239 | add bl,128 |
||
240 | cmp al,bl |
||
241 | jne nbw |
||
242 | sub al,129 |
||
243 | |||
244 | nbw32: |
||
245 | |||
246 | cmp al,1 ; write floppy |
||
247 | jne no_floppy_write |
||
248 | call floppy_write |
||
249 | jmp temp_3456 ;nbw |
||
250 | no_floppy_write: |
||
251 | |||
252 | cmp al,2 ; poweroff |
||
253 | jne no_apm_off |
||
254 | call APM_PowerOff |
||
255 | no_apm_off: |
||
256 | |||
257 | cmp al,3 ; boot |
||
258 | jnz no_sys_boot |
||
259 | mov ax,0x0040 |
||
260 | mov ds,ax |
||
261 | mov word[0x0072],0x1234 |
||
262 | jmp 0xF000:0xFFF0 |
||
263 | no_sys_boot: |
||
264 | |||
265 | cmp al,4 ; restart kernel |
||
266 | je restart_kernel |
||
267 | |||
268 | temp_3456: |
||
269 | push word 0x0000 |
||
270 | pop es |
||
271 | mov al,byte [es:0x9030] |
||
272 | cmp al,1 |
||
273 | jl nbw |
||
274 | cmp al,4 |
||
275 | jg nbw |
||
276 | jmp nbw32 |
||
277 | |||
278 | ; jmp nbw |
||
279 | pause_key: |
||
280 | mov ecx,100 |
||
281 | pause_key_1: |
||
282 | loop pause_key_1 |
||
283 | ret |
||
284 | |||
285 | iglobal |
||
286 | kernel db 'KERNEL MNT' |
||
287 | ; shutdown_parameter db 0 |
||
288 | endg |
||
289 | |||
290 | restart_kernel: |
||
291 | |||
292 | mov ax,0x0003 ; set text mode for screen |
||
293 | int 0x10 |
||
294 | |||
295 | jmp 0x4000:0000 |
||
296 | |||
297 | |||
298 | restart_kernel_4000: |
||
299 | |||
300 | mov di,0x1000 ; load kernel image from 0x8000:0 -> 0x1000:0 |
||
301 | |||
302 | new_kernel_block_move: |
||
303 | |||
304 | mov ebx,0 |
||
305 | |||
306 | new_kernel_byte_move: |
||
307 | |||
308 | mov ax,di |
||
309 | add ax,0x7000 |
||
310 | mov es,ax |
||
311 | mov dl,[es:bx] |
||
312 | mov es,di |
||
313 | mov [es:bx],dl |
||
314 | |||
315 | inc ebx |
||
316 | cmp ebx,65536 |
||
317 | jbe new_kernel_byte_move |
||
318 | |||
319 | add di,0x1000 |
||
320 | cmp di,0x2000 |
||
321 | jbe new_kernel_block_move |
||
322 | |||
323 | wbinvd ; write and invalidate cache |
||
324 | |||
325 | mov ax,0x1000 |
||
326 | mov es,ax |
||
327 | mov ax,0x2000 |
||
328 | mov ss,ax |
||
329 | mov sp,0xff00 |
||
330 | |||
331 | jmp 0x1000:0000 |
||
332 | |||
333 | |||
334 | APM_PowerOff: |
||
335 | ;!!!!!!!!!!!!!!!!!!!!!!!! |
||
336 | mov ax,0x5300 |
||
337 | xor bx,bx |
||
338 | int 0x15 |
||
339 | push ax |
||
340 | |||
341 | mov ax,0x5301 |
||
342 | xor bx,bx |
||
343 | int 0x15 |
||
344 | |||
345 | mov ax,0x5308 |
||
346 | mov bx,1 |
||
347 | mov cx,bx |
||
348 | int 0x15 |
||
349 | |||
350 | mov ax,0x530E |
||
351 | xor bx,bx |
||
352 | pop cx |
||
353 | int 0x15 |
||
354 | |||
355 | mov ax,0x530D |
||
356 | mov bx,1 |
||
357 | mov cx,bx |
||
358 | int 0x15 |
||
359 | |||
360 | mov ax,0x530F |
||
361 | mov bx,1 |
||
362 | mov cx,bx |
||
363 | int 0x15 |
||
364 | |||
365 | mov ax,0x5307 |
||
366 | mov bx,1 |
||
367 | mov cx,3 |
||
368 | int 0x15 |
||
369 | ;!!!!!!!!!!!!!!!!!!!!!!!! |
||
370 | ret |
||
371 | uglobal |
||
372 | flm db 0 |
||
373 | endg |
||
374 | |||
375 | floppy_write: ; write diskette image to physical floppy |
||
376 | |||
377 | pusha |
||
378 | |||
379 | mov ax,0x1000 |
||
380 | mov es,ax |
||
381 | cmp [es:flm-0x10000],byte 1 |
||
382 | je fwwritedone |
||
383 | mov [es:flm-0x10000],byte 1 |
||
384 | |||
385 | mov ax,0x0000 ; reset drive |
||
386 | mov dx,0x0000 |
||
387 | int 0x13 |
||
388 | |||
389 | mov cx,0x0001 ; startcyl,startsector |
||
390 | mov dx,0x0000 ; starthead,drive |
||
391 | push word 80*2 ; read no of sect |
||
392 | |||
393 | fwwrites: |
||
394 | pusha |
||
395 | |||
396 | ; move 1mb+ -> 0:a000 |
||
397 | |||
398 | pusha |
||
399 | mov si,fwmovedesc -0x10000 |
||
400 | push word 0x1000 |
||
401 | pop es |
||
402 | mov cx,256*18 |
||
403 | mov ah,0x87 |
||
404 | int 0x15 |
||
405 | mov eax,[es:fwmovedesc-0x10000+0x12] |
||
406 | add eax,512*18 |
||
407 | mov [es:fwmovedesc-0x10000+0x12],eax |
||
408 | popa |
||
409 | |||
410 | xor si,si |
||
411 | fwnewwrite: |
||
412 | push word 0x0 |
||
413 | pop es |
||
414 | mov bx,0xa000 ; es:bx -> data area |
||
415 | mov ax,0x0300+18 ; read, no of sectors to read |
||
416 | int 0x13 |
||
417 | |||
418 | cmp ah,0 |
||
419 | jz fwgoodwrite |
||
420 | |||
421 | add si,1 |
||
422 | cmp si,10 |
||
423 | jnz fwnewwrite |
||
424 | |||
425 | add esp,32+2 |
||
426 | |||
427 | popa ; can't access diskette |
||
428 | ret |
||
429 | |||
430 | fwgoodwrite: |
||
431 | |||
432 | popa |
||
433 | |||
434 | inc dh |
||
435 | cmp dh,2 |
||
436 | jnz fwbb2 |
||
437 | mov dh,0 |
||
438 | inc ch |
||
439 | |||
440 | fwbb2: |
||
441 | |||
442 | cld |
||
443 | pop ax |
||
444 | dec ax |
||
445 | push ax |
||
446 | cmp ax,0 |
||
447 | jnz fwrs |
||
448 | |||
449 | pop ax |
||
450 | |||
451 | jmp fwwritedone |
||
452 | fwrs: |
||
453 | jmp fwwrites |
||
454 | |||
455 | fwmovedesc: |
||
456 | |||
457 | db 0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0 |
||
458 | db 0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0 |
||
459 | db 0xff,0xff,0x0,0x00,0x10,0x93,0x0,0x0 |
||
460 | db 0xff,0xff,0x0,0xa0,0x00,0x93,0x0,0x0 |
||
461 | db 0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0 |
||
462 | db 0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0 |
||
463 | db 0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0 |
||
464 | db 0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0 |
||
465 | |||
466 | fwwritedone: |
||
467 | |||
468 | popa |
||
469 | |||
470 | ret |
||
471 | |||
472 | |||
473 | use32 |
||
474 | |||
475 | uglobal |
||
476 | shutdownpos dd 0x0 |
||
477 | endg |
||
478 | |||
479 | iglobal |
||
480 | ;shutdowntext: |
||
481 | ; db "IT'S SAFE TO POWER OFF COMPUTER OR " |
||
482 | ; db ' ' |
||
483 | ; db '1) SAVE RAMDISK TO FLOPPY ' |
||
484 | ; db '2) APM - POWEROFF ' |
||
485 | ; db '3) REBOOT ' |
||
486 | ; db '4) RESTART KERNEL ' |
||
487 | shutdowntext: |
||
488 | db "Безопасное выключение компьютера или " |
||
489 | db ' ' |
||
490 | db '1) Сохранить рамдиск на дискету ' |
||
491 | db '2) APM - выключение питания ' |
||
492 | db '3) Перезагрузка системы ' |
||
493 | db '4) Рестарт ядра из ОЗУ ' |
||
494 | rosef: |
||
495 | db 'ROSE TXT' |
||
496 | endg |