Subversion Repositories Kolibri OS

Rev

Rev 27 | Rev 46 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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 [es:shutdown_parameter-0x10000],bl
  199.  
  200.     jmp real_mode-0x10000      
  201.  
  202. old_ints_h:
  203.         dw      4*0x20
  204.         dd      0
  205.         dw      0
  206.  
  207. rdelay:
  208.     ret
  209. real_mode:
  210.  
  211.     lidt [cs:old_ints_h-0x10000]
  212.     mov  sp,0xfff0
  213. ;remap IRQs
  214.     mov  al,0x11
  215.     out  0x20,al
  216.     call rdelay
  217.     out  0xA0,al
  218.     call rdelay
  219.    
  220.     mov  al,0x08
  221.     out  0x21,al
  222.     call rdelay
  223.     mov  al,0x70
  224.     out  0xA1,al
  225.     call rdelay
  226.    
  227.     mov  al,0x04
  228.     out  0x21,al
  229.     call rdelay
  230.     mov  al,0x02
  231.     out  0xA1,al
  232.     call rdelay
  233.    
  234.     mov  al,0x01
  235.     out  0x21,al
  236.     call rdelay
  237.     out  0xA1,al
  238.     call rdelay
  239.    
  240.     mov  al,2
  241.     out  0x21,al
  242.     mov  al,0
  243.     out  0xA1,al
  244.     sti
  245.  
  246.     jmp  temp_3456
  247.  
  248.   nbw:
  249.     xor  ax,ax
  250.     in   al,0x60
  251.     call pause_key
  252.     cmp  al,7
  253.     jge  nbw
  254.     mov  bl,al
  255.   nbw2:
  256.     in   al,0x60
  257.     call pause_key
  258.     cmp  al,bl
  259.     je   nbw2
  260.     cmp  al,240  ;ax,240
  261.     jne  nbw31
  262.     mov  al,bl
  263.     dec  al
  264.     jmp  nbw32
  265.   nbw31:
  266.     add  bl,128
  267.     cmp  al,bl
  268.     jne  nbw
  269.     sub  al,129
  270.  
  271.   nbw32:
  272.    
  273.     cmp  al,1              ; write floppy
  274.     jne  no_floppy_write
  275.     call floppy_write
  276.     jmp  temp_3456 ;nbw
  277.   no_floppy_write:
  278.  
  279.     cmp  al,2              ; poweroff
  280.     jne  no_apm_off
  281.     call APM_PowerOff
  282.   no_apm_off:
  283.  
  284.     cmp  al,3              ; boot
  285.     jnz  no_sys_boot
  286.     mov  ax,0x0040
  287.     mov  ds,ax
  288.     mov  word[0x0072],0x1234
  289.     jmp  0xF000:0xFFF0
  290.   no_sys_boot:
  291.  
  292.     cmp  al,4              ; restart kernel
  293.     je   restart_kernel
  294.  
  295.   temp_3456:
  296.     push    word 0x0000
  297.     pop     es
  298.     mov  al,byte [es:0x9030]
  299.     cmp  al,1
  300.     jl   nbw
  301.     cmp  al,4
  302.     jg   nbw
  303.     jmp  nbw32
  304.  
  305. ;    jmp  nbw
  306.     pause_key:
  307.       mov ecx,100
  308.     pause_key_1:
  309.       loop  pause_key_1
  310.       ret
  311.  
  312. iglobal
  313.   kernel  db  'KERNEL  MNT'
  314. ;  shutdown_parameter db 0
  315. endg
  316.  
  317. restart_kernel:
  318.  
  319.         mov     ax,0x0003      ; set text mode for screen
  320.         int     0x10
  321.  
  322.         jmp     0x4000:0000
  323.  
  324.  
  325. restart_kernel_4000:
  326.         cli
  327.  
  328.         mov     di,0x1000      ; load kernel image from 0x8000:0 -> 0x1000:0
  329.  
  330.       new_kernel_block_move:
  331.  
  332.         mov     ebx,0
  333.  
  334.       new_kernel_byte_move:
  335.  
  336.         mov     ax,di
  337.         add     ax,0x7000
  338.         mov     es,ax
  339.         mov     dl,[es:bx]
  340.         mov     es,di
  341.         mov     [es:bx],dl
  342.  
  343.         inc     ebx
  344.         cmp     ebx,65536
  345.         jbe     new_kernel_byte_move
  346.  
  347.         add     di,0x1000
  348.         cmp     di,0x2000
  349.         jbe     new_kernel_block_move
  350.  
  351.         wbinvd  ; write and invalidate cache
  352.  
  353.         mov     ax,0x1000
  354.         mov     es,ax
  355.         mov     ax,0x3000
  356.         mov     ss,ax
  357.         mov     sp,0xec00
  358.         sti
  359.  
  360.         jmp     0x1000:0000
  361.  
  362.  
  363. APM_PowerOff:
  364. ;!!!!!!!!!!!!!!!!!!!!!!!!
  365. mov ax,0x5300
  366. xor bx,bx
  367. int 0x15
  368. push ax
  369.  
  370. mov ax,0x5301
  371. xor bx,bx
  372. int 0x15
  373.  
  374. mov ax,0x5308
  375. mov bx,1
  376. mov cx,bx
  377. int 0x15
  378.  
  379. mov ax,0x530E
  380. xor bx,bx
  381. pop cx
  382. int 0x15
  383.  
  384. mov ax,0x530D
  385. mov bx,1
  386. mov cx,bx
  387. int 0x15
  388.  
  389. mov ax,0x530F
  390. mov bx,1
  391. mov cx,bx
  392. int 0x15
  393.  
  394. mov ax,0x5307
  395. mov bx,1
  396. mov cx,3
  397. int 0x15
  398. ;!!!!!!!!!!!!!!!!!!!!!!!!
  399.         ret
  400. uglobal
  401.   flm db 0
  402. endg
  403.  
  404. floppy_write:   ; write diskette image to physical floppy
  405.  
  406.         pusha
  407.  
  408.         mov  ax,0x1000
  409.         mov  es,ax
  410.         cmp  [es:flm-0x10000],byte 1
  411.         je   fwwritedone
  412.         mov  [es:flm-0x10000],byte 1
  413.  
  414.         mov     ax,0x0000               ; reset drive
  415.         mov     dx,0x0000
  416.         int     0x13
  417.  
  418.         mov     cx,0x0001               ; startcyl,startsector
  419.         mov     dx,0x0000               ; starthead,drive
  420.         push    word 80*2               ; read no of sect
  421.  
  422.       fwwrites:
  423.         pusha
  424.  
  425.         ; move 1mb+ -> 0:a000
  426.  
  427.         pusha
  428.         mov     si,fwmovedesc -0x10000
  429.         push    word 0x1000
  430.         pop     es
  431.         mov     cx,256*18
  432.         mov     ah,0x87
  433.         int     0x15
  434.         mov     eax,[es:fwmovedesc-0x10000+0x12]
  435.         add     eax,512*18
  436.         mov     [es:fwmovedesc-0x10000+0x12],eax
  437.         popa
  438.  
  439.         xor     si,si
  440.       fwnewwrite:
  441.         push    word 0x0
  442.         pop     es
  443.         mov     bx,0xa000               ; es:bx -> data area
  444.         mov     ax,0x0300+18            ; read, no of sectors to read
  445.         int     0x13
  446.  
  447.         cmp     ah,0
  448.         jz      fwgoodwrite
  449.  
  450.         add     si,1
  451.         cmp     si,10
  452.         jnz     fwnewwrite
  453.  
  454.         add     esp,32+2
  455.  
  456.         popa                            ; can't access diskette
  457.         ret
  458.  
  459.       fwgoodwrite:
  460.  
  461.         popa
  462.  
  463.         inc     dh
  464.         cmp     dh,2
  465.         jnz     fwbb2
  466.         mov     dh,0
  467.         inc     ch
  468.  
  469.       fwbb2:
  470.  
  471.         cld
  472.         pop     ax
  473.         dec     ax
  474.         push    ax
  475.         cmp     ax,0
  476.         jnz     fwrs
  477.  
  478.         pop     ax
  479.  
  480.         jmp     fwwritedone
  481.       fwrs:
  482.         jmp     fwwrites
  483.  
  484.       fwmovedesc:
  485.  
  486.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  487.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  488.         db      0xff,0xff,0x0,0x00,0x10,0x93,0x0,0x0
  489.         db      0xff,0xff,0x0,0xa0,0x00,0x93,0x0,0x0
  490.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  491.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  492.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  493.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  494.  
  495.       fwwritedone:
  496.  
  497.         popa
  498.  
  499.         ret
  500.  
  501.  
  502. use32
  503.  
  504. uglobal
  505.   shutdownpos dd 0x0
  506. endg
  507.  
  508. iglobal
  509. ;shutdowntext:
  510. ;    db   "IT'S SAFE TO POWER OFF COMPUTER OR      "
  511. ;    db   '                                        '
  512. ;    db   '1) SAVE RAMDISK TO FLOPPY               '
  513. ;    db   '2) APM - POWEROFF                       '
  514. ;    db   '3) REBOOT                               '
  515. ;    db   '4) RESTART KERNEL                       '
  516. shutdowntext:
  517.     db   "¥§®¯ á­®¥ ¢ëª«î祭¨¥ ª®¬¯ìîâ¥à  ¨«¨    "
  518.     db   '                                        '
  519.     db   '1) ‘®åà ­¨âì à ¬¤¨áª ­  ¤¨áª¥âã         '
  520.     db   '2) APM - ¢ëª«î祭¨¥ ¯¨â ­¨ï             '
  521.     db   '3) ¥à¥§ £à㧪  á¨áâ¥¬ë                 '
  522.     db   '4) ¥áâ àâ ï¤à  ¨§ Ž‡“                  '
  523. rosef:
  524.     db 'ROSE    TXT'
  525. endg
  526.