?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. ;clock driver MSX2
  2.         module Clock
  3.     define RTCreg 0xb4
  4.     define RTCdat 0xb5
  5.     define MODEreg 0x0d
  6.    
  7. readTime:
  8. ;I/O Ports
  9. ;Port 00B4h allows you to specify the RTC register (0-15) to access, and
  10. ;port 00B5h allows you to read or write data in the specified register. Bits 4 to 7 of these ports are not used.
  11. ;
  12. ;Block 0
  13. ;Register       Bit 3   Bit 2   Bit 1   Bit 0
  14. ;0              Units counter for seconds
  15. ;1              0           Tens counter for seconds
  16. ;2              Units counter for minutes
  17. ;3              0           Tens counter for minutes
  18. ;4              Units counter for hours
  19. ;5              0           0       Tens counter for hours
  20. ;
  21.  
  22.         ld bc, RTCreg
  23.         ld a,MODEreg
  24.     out (c),a           ; Selecting MODE register
  25.  
  26.         ld bc, RTCdat
  27.     in a, (c)           ; Reading MODE register
  28.     and 12
  29.     out (c),a           ;Selecting BLOCK0
  30.  
  31. ; Seconds-----------------------------------------------------------------
  32.         ld bc, RTCreg
  33.     ld a,0
  34.     out (c),a           ;Selecting 0 register (Units counter for seconds)
  35.  
  36.     ld bc, RTCdat
  37.     in  a, (c)          ; Reading 0 register
  38.     and 15
  39.     ld e,a
  40.  
  41.         ld bc, RTCreg
  42.     ld a, 1
  43.     out (c),a           ;Selecting 1 register (Tens counter for seconds)
  44.  
  45.     ld bc, RTCdat
  46.     in  a, (c)          ; Reading 1 register
  47.     and 7
  48.     cp 0
  49.     jp z,zerosecs
  50.     ld d,a
  51.     xor a
  52. secCounter:
  53.     add 10
  54.     dec d
  55.     jp nz,secCounter
  56. zerosecs:
  57.     add e
  58.         ld (seconds),a
  59. ; Minites-----------------------------------------------------------------
  60.         ld bc, RTCreg
  61.     ld a,2
  62.     out (c),a           ;Selecting 2 register
  63.  
  64.     ld bc, RTCdat
  65.     in  a, (c)          ; Reading 2 register
  66.     and 15
  67.     ld e,a
  68.  
  69.         ld bc, RTCreg
  70.     ld a, 3
  71.     out (c),a           ;Selecting 3 register
  72.  
  73.     ld bc, RTCdat
  74.     in  a, (c)          ; Reading 3 register
  75.     and 7
  76.     cp 0
  77.     jp z,zerominutes
  78.     ld d,a
  79.     xor a
  80. minCounter:
  81.     add 10
  82.     dec d
  83.     jp nz,minCounter
  84. zerominutes:
  85.     add e
  86.     ld (minutes),a
  87. ; Hours-----------------------------------------------------------------
  88.  
  89.         ld bc, RTCreg
  90.     ld a,4
  91.     out (c),a          ;Selecting 4 register
  92.  
  93.     ld bc, RTCdat
  94.     in  a, (c)         ; Reading 4 register
  95.     and 7
  96.     ld e,a
  97.  
  98.         ld bc, RTCreg
  99.     ld a, 5
  100.     out (c),a          ;Selecting 5 register
  101.  
  102.     ld bc, RTCdat
  103.     in  a, (c)         ; Reading 5 register
  104.     and 3
  105.     cp 0
  106.     jp z,zerohour
  107.     ld d,a
  108.     xor a
  109. hourCounter:
  110.     add 10
  111.     dec d
  112.     jp nz,hourCounter
  113. zerohour:
  114.     add e
  115.     ld (hours),a
  116.         ret
  117.     endmodule
  118.