home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / SYSTEM / MMCLK12.ZIP / TEST.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-06-23  |  4.2 KB  |  153 lines

  1.     include    mmclock.mac
  2.     title    Test for MM58167A clock/calendar -- Copyright 1990 Wales
  3.  
  4. ; ======================================================================
  5. ;
  6. ; Test for the existence of an MM58167A clock/calendar.
  7. ; (C) Copyright 1990 Richard B. Wales.  All Rights Reserved.
  8. ;
  9. ; Global variables:
  10. ;
  11. ;    None.
  12. ;
  13. ; Global routines:
  14. ;
  15. ;    LookForClock
  16. ;        Attempts to locate a clock/calendar.
  17.  
  18. ; ======================================================================
  19. ;
  20. ; Global symbols.
  21.  
  22.     public    LookForClock
  23.  
  24. ; ======================================================================
  25. ;
  26. ; Default list of I/O ports at which a clock might be found.
  27.  
  28. PortList dw    340h, 240h, 2C0h, 0C0h, 0
  29.  
  30. ; ======================================================================
  31. ;
  32. ; LookForClock
  33. ;
  34. ;    Looks for an MM58167A clock/calendar chip.  If a clock is found,
  35. ;    its I/O port address is copied into "ClkPort".  This routine
  36. ;    relies on various idiosyncrasies of the MM58167A chip; and, in
  37. ;    order not to disturb other devices, does as much "read-only"
  38. ;    checking at each address as possible before writing anything.
  39. ;
  40. ;    Arguments:
  41. ;
  42. ;        BX    Should be set to point to the start of an array
  43. ;            of initial I/O port addresses (2-byte words) at
  44. ;            which to look for a clock.  The list should end
  45. ;            with a zero value.  If BX = 0, a default port
  46. ;            list is used.
  47. ;
  48. ;    Returned values:
  49. ;
  50. ;        DX    Set to the initial I/O port address where the
  51. ;            clock was actually found.  If no clock was found,
  52. ;            DX will be set to zero.
  53.  
  54. LookForClock proc near
  55.  
  56.     ; Set up the registers.
  57.     INIT_DS                ; need DS to get port # from [BX]
  58.     mov    cx, 4            ; CL used in SHL/SHR and added to DX
  59.     and    bx, bx
  60.     jnz    short try_next_port    ; if BX = 0 initially,
  61.     mov    bx, offset PortList    ;     use default port list
  62.  
  63. try_next_port:
  64.     ; Select a candidate port number.
  65.     mov    dx, [bx]        ; get port number
  66.     and    dx, dx            ; is port number zero?
  67.     jz    short give_up        ;     if so, give up
  68.  
  69.     ; Read from the starting port.  If there is a clock present,
  70.     ; the four low-order bits of the value read will be zero,
  71.     ; and the four high-order bits will be in the range 0-9.
  72.     in    al, dx
  73.     SPLIT    al
  74.     jnz    short no_clock        ; are 4 low-order bits zero?
  75.     cmp    ah, 9
  76.     ja    short no_clock        ; are 4 high-order bits <= 9?
  77.  
  78.     ; Try reading the first byte of clock RAM.  Since the low-order
  79.     ; four bits are not supported in this byte, the value read should
  80.     ; have zeros in those bit positions.
  81.     add    dx, cx
  82.     add    dx, cx            ; DX = addr of first RAM byte
  83.     in    al, dx
  84.     shl    al, cl
  85.     jnz    short no_clock
  86.  
  87.     ; Similarly, try reading the sixth byte of clock RAM.  The high-
  88.     ; order four bits are not supported in this byte, so the value
  89.     ; read should have zeros in those bit positions.
  90.     add    dx, cx
  91.     inc    dx            ; DX = addr of sixth RAM byte
  92.     in    al, dx
  93.     shr    al, cl
  94.     jnz    short no_clock
  95.  
  96.     ; Try writing to the first byte of clock RAM, then read the
  97.     ; value back.  The value read back should have zeros in the four
  98.     ; low-order bit positions, regardless of the value written out.
  99.     dec    dx
  100.     sub    dx, cx            ; DX = addr of first RAM byte
  101.     mov    al, 05Ah
  102.     out    dx, al            ; write 05Ah . . .
  103.     DELAY    3
  104.     in    al, dx
  105.     cmp    al, 050h        ; . . . better read back 050h
  106.     jne    short no_clock
  107.     mov    al, 0A5h
  108.     out    dx, al            ; write 0A5h . . .
  109.     DELAY    3
  110.     in    al, dx
  111.     cmp    al, 0A0h        ; . . . better read back 0A0h
  112.     jne    short no_clock
  113.  
  114.     ; Similarly, try writing to the sixth byte of clock RAM, then
  115.     ; reading the value back.  The value read back should have zeros
  116.     ; in the high-order four bit positions, regardless of the value
  117.     ; written out.
  118.     add    dx, cx
  119.     inc    dx            ; DX = addr of sixth RAM byte
  120.     mov    al, 05Ah
  121.     out    dx, al            ; write 05Ah . . .
  122.     DELAY    3
  123.     in    al, dx
  124.     cmp    al, 0Ah            ; . . . better read back 0Ah
  125.     jne    short no_clock
  126.     mov    al, 0A5h
  127.     out    dx, al            ; write 0A5h . . .
  128.     DELAY    3
  129.     in    al, dx
  130.     cmp    al, 05h            ; . . . better read back 05h
  131.     jne    short no_clock
  132.  
  133. ;    We found the clock.
  134.     mov    dx, [bx]        ; I/O port address of clock
  135.     ret
  136.  
  137. no_clock:
  138.     ; If any of the tests failed, there isn't an MM58167A chip
  139.     ; at the port address in question.  Try next port (if any).
  140.     inc    bx
  141.     inc    bx
  142.     jmp    short try_next_port
  143.  
  144. give_up:
  145.     ; No clock found at any of the addresses.
  146.     xor    dx, dx            ; no I/O port address
  147.     ret
  148.  
  149. LookForClock endp
  150.  
  151. code    ends
  152.  
  153.     end