Subversion Repositories Kolibri OS

Rev

Rev 2 | Rev 30 | 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.  
  327.         mov     di,0x1000      ; load kernel image from 0x8000:0 -> 0x1000:0
  328.  
  329.       new_kernel_block_move:
  330.  
  331.         mov     ebx,0
  332.  
  333.       new_kernel_byte_move:
  334.  
  335.         mov     ax,di
  336.         add     ax,0x7000
  337.         mov     es,ax
  338.         mov     dl,[es:bx]
  339.         mov     es,di
  340.         mov     [es:bx],dl
  341.  
  342.         inc     ebx
  343.         cmp     ebx,65536
  344.         jbe     new_kernel_byte_move
  345.  
  346.         add     di,0x1000
  347.         cmp     di,0x2000
  348.         jbe     new_kernel_block_move
  349.  
  350.         wbinvd  ; write and invalidate cache
  351.  
  352.         mov     ax,0x1000
  353.         mov     es,ax
  354.         mov     ax,0x2000
  355.         mov     ss,ax
  356.         mov     sp,0xff00
  357.  
  358.         jmp     0x1000:0000
  359.  
  360.  
  361. APM_PowerOff:
  362. ;!!!!!!!!!!!!!!!!!!!!!!!!
  363. mov ax,0x5300
  364. xor bx,bx
  365. int 0x15
  366. push ax
  367.  
  368. mov ax,0x5301
  369. xor bx,bx
  370. int 0x15
  371.  
  372. mov ax,0x5308
  373. mov bx,1
  374. mov cx,bx
  375. int 0x15
  376.  
  377. mov ax,0x530E
  378. xor bx,bx
  379. pop cx
  380. int 0x15
  381.  
  382. mov ax,0x530D
  383. mov bx,1
  384. mov cx,bx
  385. int 0x15
  386.  
  387. mov ax,0x530F
  388. mov bx,1
  389. mov cx,bx
  390. int 0x15
  391.  
  392. mov ax,0x5307
  393. mov bx,1
  394. mov cx,3
  395. int 0x15
  396. ;!!!!!!!!!!!!!!!!!!!!!!!!
  397.         ret
  398. uglobal
  399.   flm db 0
  400. endg
  401.  
  402. floppy_write:   ; write diskette image to physical floppy
  403.  
  404.         pusha
  405.  
  406.         mov  ax,0x1000
  407.         mov  es,ax
  408.         cmp  [es:flm-0x10000],byte 1
  409.         je   fwwritedone
  410.         mov  [es:flm-0x10000],byte 1
  411.  
  412.         mov     ax,0x0000               ; reset drive
  413.         mov     dx,0x0000
  414.         int     0x13
  415.  
  416.         mov     cx,0x0001               ; startcyl,startsector
  417.         mov     dx,0x0000               ; starthead,drive
  418.         push    word 80*2               ; read no of sect
  419.  
  420.       fwwrites:
  421.         pusha
  422.  
  423.         ; move 1mb+ -> 0:a000
  424.  
  425.         pusha
  426.         mov     si,fwmovedesc -0x10000
  427.         push    word 0x1000
  428.         pop     es
  429.         mov     cx,256*18
  430.         mov     ah,0x87
  431.         int     0x15
  432.         mov     eax,[es:fwmovedesc-0x10000+0x12]
  433.         add     eax,512*18
  434.         mov     [es:fwmovedesc-0x10000+0x12],eax
  435.         popa
  436.  
  437.         xor     si,si
  438.       fwnewwrite:
  439.         push    word 0x0
  440.         pop     es
  441.         mov     bx,0xa000               ; es:bx -> data area
  442.         mov     ax,0x0300+18            ; read, no of sectors to read
  443.         int     0x13
  444.  
  445.         cmp     ah,0
  446.         jz      fwgoodwrite
  447.  
  448.         add     si,1
  449.         cmp     si,10
  450.         jnz     fwnewwrite
  451.  
  452.         add     esp,32+2
  453.  
  454.         popa                            ; can't access diskette
  455.         ret
  456.  
  457.       fwgoodwrite:
  458.  
  459.         popa
  460.  
  461.         inc     dh
  462.         cmp     dh,2
  463.         jnz     fwbb2
  464.         mov     dh,0
  465.         inc     ch
  466.  
  467.       fwbb2:
  468.  
  469.         cld
  470.         pop     ax
  471.         dec     ax
  472.         push    ax
  473.         cmp     ax,0
  474.         jnz     fwrs
  475.  
  476.         pop     ax
  477.  
  478.         jmp     fwwritedone
  479.       fwrs:
  480.         jmp     fwwrites
  481.  
  482.       fwmovedesc:
  483.  
  484.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  485.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  486.         db      0xff,0xff,0x0,0x00,0x10,0x93,0x0,0x0
  487.         db      0xff,0xff,0x0,0xa0,0x00,0x93,0x0,0x0
  488.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  489.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  490.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  491.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  492.  
  493.       fwwritedone:
  494.  
  495.         popa
  496.  
  497.         ret
  498.  
  499.  
  500. use32
  501.  
  502. uglobal
  503.   shutdownpos dd 0x0
  504. endg
  505.  
  506. iglobal
  507. ;shutdowntext:
  508. ;    db   "IT'S SAFE TO POWER OFF COMPUTER OR      "
  509. ;    db   '                                        '
  510. ;    db   '1) SAVE RAMDISK TO FLOPPY               '
  511. ;    db   '2) APM - POWEROFF                       '
  512. ;    db   '3) REBOOT                               '
  513. ;    db   '4) RESTART KERNEL                       '
  514. shutdowntext:
  515.     db   "¥§®¯ á­®¥ ¢ëª«î祭¨¥ ª®¬¯ìîâ¥à  ¨«¨    "
  516.     db   '                                        '
  517.     db   '1) ‘®åà ­¨âì à ¬¤¨áª ­  ¤¨áª¥âã         '
  518.     db   '2) APM - ¢ëª«î祭¨¥ ¯¨â ­¨ï             '
  519.     db   '3) ¥à¥§ £à㧪  á¨áâ¥¬ë                 '
  520.     db   '4) ¥áâ àâ ï¤à  ¨§ Ž‡“                  '
  521. rosef:
  522.     db 'ROSE    TXT'
  523. endg
  524.