Subversion Repositories Kolibri OS

Rev

Rev 9715 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2022. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. $Revision: 9910 $
  9.  
  10.  
  11. ;setting date,time,clock and alarm-clock
  12. ;add sys_settime at servetable as for ex. 22 fcn:
  13. ; 22 - SETTING DATE TIME, CLOCK AND ALARM-CLOCK
  14. ; ebx =0 - set time ecx - 00SSMMHH
  15. ; ebx =1 - set date ecx=00DDMMYY
  16. ; ebx =2 - set day of week ecx- 1-7
  17. ; ebx =3 - set alarm-clock ecx - 00SSMMHH
  18. ; out: 0 -Ok 1 -wrong format 2 -battery low
  19. sys_settime:
  20.         cli
  21.         mov     al, 0x0d
  22.         out     0x70, al
  23.         in      al, 0x71
  24.         bt      ax, 7
  25.         jnc     .bat_low
  26.         cmp     ebx, 2  ;day of week
  27.         jne     .nosetweek
  28.         test    ecx, ecx   ;test day of week
  29.         je      .wrongtime
  30.         cmp     ecx, 7
  31.         ja      .wrongtime
  32.         mov     edx, 0x70
  33.         call    startstopclk
  34.         dec     edx
  35.         mov     al, 6
  36.         out     dx, al
  37.         inc     edx
  38.         mov     al, cl
  39.         out     dx, al
  40.         jmp     .endsettime
  41.   .nosetweek:           ;set date
  42.         cmp     ebx, 1
  43.         jne     .nosetdate
  44.         cmp     cl, 0x99;test year
  45.         ja      .wrongtime
  46.         shl     ecx, 4
  47.         cmp     cl, 0x90
  48.         ja      .wrongtime
  49.         cmp     ch, 0x99;test month
  50.         ja      .wrongtime
  51.         shr     ecx, 4
  52.         test    ch, ch
  53.         je      .wrongtime
  54.         cmp     ch, 0x12
  55.         ja      .wrongtime
  56.         shl     ecx, 8
  57.         bswap   ecx   ;ebx=00YYMMDD
  58.         test    cl, cl ;test day
  59.         je      .wrongtime
  60.         shl     ecx, 4
  61.         cmp     cl, 0x90
  62.         ja      .wrongtime
  63.         shr     ecx, 4
  64.         cmp     ch, 2 ;February
  65.         jne     .testday
  66.         cmp     cl, 0x29
  67.         ja      .wrongtime
  68.         jmp     .setdate
  69.     .testday:
  70.         cmp     ch, 8
  71.         jb      .testday1 ;Aug-Dec
  72.         bt      cx, 8
  73.         jnc     .days31
  74.         jmp     .days30
  75.     .testday1:
  76.         bt      cx, 8 ;Jan-Jul ex.Feb
  77.         jnc     .days30
  78.     .days31:
  79.         cmp     cl, 0x31
  80.         ja      .wrongtime
  81.         jmp     .setdate
  82.     .days30:
  83.         cmp     cl, 0x30
  84.         ja      .wrongtime
  85.     .setdate:
  86.         mov     edx, 0x70
  87.         call    startstopclk
  88.         dec     edx
  89.         mov     al, 7    ;set days
  90.         out     dx, al
  91.         inc     edx
  92.         mov     al, cl
  93.         out     dx, al
  94.         dec     edx
  95.         mov     al, 8    ;set months
  96.         out     dx, al
  97.         inc     edx
  98.         mov     al, ch
  99.         out     dx, al
  100.         dec     edx
  101.         mov     al, 9    ;set years
  102.         out     dx, al
  103.         inc     edx
  104.         shr     ecx, 8
  105.         mov     al, ch
  106.         out     dx, al
  107.         jmp     .endsettime
  108.     .nosetdate:       ;set time or alarm-clock
  109.         cmp     ebx, 3
  110.         ja      .wrongtime
  111.         cmp     cl, 0x23
  112.         ja      .wrongtime
  113.         cmp     ch, 0x59
  114.         ja      .wrongtime
  115.         shl     ecx, 4
  116.         cmp     cl, 0x90
  117.         ja      .wrongtime
  118.         cmp     ch, 0x92
  119.         ja      .wrongtime
  120.         shl     ecx, 4
  121.         bswap   ecx    ;00HHMMSS
  122.         cmp     cl, 0x59
  123.         ja      .wrongtime
  124.         shl     ecx, 4
  125.         cmp     cl, 0x90
  126.         ja      .wrongtime
  127.         shr     ecx, 4
  128.  
  129.         mov     edx, 0x70
  130.         call    startstopclk
  131.         dec     edx
  132.         cmp     ebx, 3
  133.      
  134.         je      .setalarm
  135.         xor     eax, eax;al=0-set seconds
  136.         out     dx, al
  137.         inc     edx
  138.         mov     al, cl
  139.         out     dx, al
  140.         dec     edx
  141.         mov     al, 2 ;set minutes
  142.         out     dx, al
  143.         inc     edx
  144.         mov     al, ch
  145.         out     dx, al
  146.         dec     edx
  147.         mov     al, 4 ;set hours
  148.         out     dx, al
  149.         inc     edx
  150.         shr     ecx, 8
  151.         mov     al, ch
  152.         out     dx, al
  153.         jmp     .endsettime
  154.    .setalarm:
  155.         mov     al, 1;set seconds for al.
  156.         out     dx, al
  157.         inc     edx
  158.         mov     al, cl
  159.         out     dx, al
  160.         dec     edx
  161.         mov     al, 3;set minutes for al.
  162.         out     dx, al
  163.         inc     edx
  164.         mov     al, ch
  165.         out     dx, al
  166.         dec     edx
  167.         mov     al, 5;set hours for al.
  168.         out     dx, al
  169.         inc     edx
  170.         shr     ecx, 8
  171.         mov     al, ch
  172.         out     dx, al
  173.         dec     edx
  174.         mov     al, 0x0b;enable irq's
  175.         out     dx, al
  176.         inc     dx
  177.         in      al, dx
  178.         bts     ax, 5;set bit 5
  179.         out     dx, al
  180.     .endsettime:
  181.         dec     edx
  182.         call    startstopclk
  183.         sti
  184.         and     [esp + SYSCALL_STACK.eax], dword 0
  185.         ret
  186.    .bat_low:
  187.         sti
  188.         mov     [esp + SYSCALL_STACK.eax], dword 2
  189.         ret
  190.    .wrongtime:
  191.         sti
  192.         mov     [esp + SYSCALL_STACK.eax], dword 1
  193.         ret
  194.  
  195. startstopclk:
  196.         mov     al, 0x0b
  197.         out     dx, al
  198.         inc     dx
  199.         in      al, dx
  200.         btc     ax, 7
  201.         out     dx, al
  202.         ret
  203.  
  204. align 4
  205. sys_clock:
  206.         cli
  207.   ; Mikhail Lisovin  xx Jan 2005
  208.   @@:
  209.         mov     al, 10
  210.         out     0x70, al
  211.         in      al, 0x71
  212.         test    al, al
  213.         jns     @f
  214.         mov     esi, 1
  215.         call    delay_ms
  216.         jmp     @b
  217.   @@:
  218.   ; end Lisovin's fix
  219.  
  220.         xor     al, al        ; seconds
  221.         out     0x70, al
  222.         in      al, 0x71
  223.         movzx   ecx, al
  224.         mov     al, 02        ; minutes
  225.         shl     ecx, 16
  226.         out     0x70, al
  227.         in      al, 0x71
  228.         movzx   edx, al
  229.         mov     al, 04        ; hours
  230.         shl     edx, 8
  231.         out     0x70, al
  232.         in      al, 0x71
  233.         add     ecx, edx
  234.         movzx   edx, al
  235.         add     ecx, edx
  236.         sti
  237.         mov     [esp + SYSCALL_STACK.eax], ecx
  238.         ret
  239.  
  240. align 4
  241. sys_date:
  242.         cli
  243.   @@:
  244.         mov     al, 10
  245.         out     0x70, al
  246.         in      al, 0x71
  247.         test    al, al
  248.         jns     @f
  249.         mov     esi, 1
  250.         call    delay_ms
  251.         jmp     @b
  252.   @@:
  253.         mov     ch, 0
  254.         mov     al, 7           ; date
  255.         out     0x70, al
  256.         in      al, 0x71
  257.         mov     cl, al
  258.         mov     al, 8           ; month
  259.         shl     ecx, 16
  260.         out     0x70, al
  261.         in      al, 0x71
  262.         mov     ch, al
  263.         mov     al, 9           ; year
  264.         out     0x70, al
  265.         in      al, 0x71
  266.         mov     cl, al
  267.         sti
  268.         mov     [esp + SYSCALL_STACK.eax], ecx
  269.         ret
  270.