home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / SYSTEM / MMCLK12.ZIP / MMCLOCK.MAC < prev    next >
Encoding:
Text File  |  1990-03-26  |  5.2 KB  |  262 lines

  1.     .xlist
  2.  
  3. ; ======================================================================
  4. ;
  5. ; Include-file for MM58167A clock/calendar driver.
  6. ; (C) Copyright 1990 Richard B. Wales.  All Rights Reserved.
  7.  
  8. ; ======================================================================
  9. ;
  10. ; Short delay between successive I/O operations.  Without this delay,
  11. ; a pair of IN and/or OUT operations in immediate succession might fail
  12. ; on a very fast PC.
  13.  
  14. DELAY    macro    COUNT
  15.       rept    COUNT
  16.         jmp    short $+2
  17.       endm
  18.     endm
  19.  
  20. ; ======================================================================
  21. ;
  22. ; Maximum number of times to attempt a "read" or "write" operation before
  23. ; giving up.  If the counters roll over before we are through accessing
  24. ; them, the entire operation must be repeated.
  25.  
  26. MAX_RETRIES equ    5
  27.  
  28. ; ======================================================================
  29. ;
  30. ; Print a string (DOS Int 21H, function 09H).
  31.  
  32. PRINT    macro    STRING
  33.     mov    ah, 9
  34.     mov    dx, offset STRING
  35.     int    21h
  36.     endm
  37.  
  38. ; ======================================================================
  39. ;
  40. ; Push multiple registers.
  41.  
  42. PUSHM    macro    r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12
  43.       irp    x, <r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12>
  44.         ifnb <&x>
  45.           ifidni <&x>,<flags>
  46.         pushf
  47.           else
  48.             push &x
  49.           endif
  50.         endif
  51.       endm
  52.     endm
  53.  
  54. ; ======================================================================
  55. ;
  56. ; Pop multiple registers.
  57.  
  58. POPM    macro    r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12
  59.       irp    x, <r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12>
  60.         ifnb <&x>
  61.           ifidni <&x>,<flags>
  62.         popf
  63.           else
  64.             pop &x
  65.           endif
  66.         endif
  67.       endm
  68.     endm
  69.  
  70. ; ======================================================================
  71. ;
  72. ; Set up addressability via DS.
  73.  
  74. INIT_DS    macro
  75.     mov    ax, cs
  76.     mov    ds, ax
  77.     assume    ds:code
  78.         endm
  79.  
  80. ; ======================================================================
  81. ;
  82. ; Swap the high- and low-order bytes in AX.
  83.  
  84. SWAP    macro
  85.     xchg    ah, al
  86.     endm
  87.  
  88. ; ======================================================================
  89. ;
  90. ; Split a byte into high- and low-order nybbles in AH and AL.
  91. ; Assumes CL has previously been loaded with the value 4.
  92.  
  93. SPLIT    macro    REG
  94.     ifidni    <®>,<AL>
  95.     else
  96.       mov    al, REG
  97.     endif
  98.     xor    ah, ah
  99.     shl    ax, cl
  100.     shr    al, cl
  101.     endm
  102.  
  103. ; ======================================================================
  104. ;
  105. ; Check first, and then translate, each byte of a word.
  106.  
  107. CKXLAT    macro    SRC, DEST, HBOUND, LBOUND, ERRLABEL
  108.     ifidni    <&SRC>,<AX>
  109.     else
  110.       mov    ax, SRC
  111.     endif
  112.     cmp    al, LBOUND
  113.     ja    short ERRLABEL
  114.     xlat
  115.     SWAP
  116.     cmp    al, HBOUND
  117.     ja    short ERRLABEL
  118.     xlat
  119.     SWAP
  120.     ifidni    <&DEST>,<AX>
  121.     else
  122.       mov    DEST, ax
  123.     endif
  124.     endm
  125.  
  126. ; ======================================================================
  127. ;
  128. ; Translate first, and then check, each byte of a word.
  129.  
  130. XLATCK    macro    SRC, DEST, HBOUND, LBOUND, ERRLABEL
  131.     ifidni    <&SRC>,<AX>
  132.     else
  133.       mov    ax, SRC
  134.     endif
  135.     xlat
  136.     cmp    al, LBOUND
  137.     ja    short ERRLABEL
  138.     SWAP
  139.     xlat
  140.     cmp    al, HBOUND
  141.     ja    short ERRLABEL
  142.     SWAP
  143.     ifidni    <&DEST>,<AX>
  144.     else
  145.       mov    DEST, ax
  146.     endif
  147.     endm
  148.  
  149. ; ======================================================================
  150. ;
  151. ; Translate first, and then check, each byte of a word.
  152. ; Also include a check for a zero result after translation.
  153. ; Suppress the final SWAP.
  154.  
  155. XLATCKZ    macro    SRC, DEST, HBOUND, LBOUND, ERRLABEL
  156.     ifidni    <&SRC>,<AX>
  157.     else
  158.       mov    ax, SRC
  159.     endif
  160.     xlat
  161.     cmp    al, LBOUND
  162.     ja    short ERRLABEL
  163.     and    al, al
  164.     jz    short ERRLABEL
  165.     SWAP
  166.     xlat
  167.     cmp    al, HBOUND
  168.     ja    short ERRLABEL
  169.     and    al, al
  170.     jz    short ERRLABEL
  171.     ifidni    <&DEST>,<AX>
  172.     else
  173.       mov    DEST, ax
  174.     endif
  175.     endm
  176.  
  177. ; =======================================================================
  178. ;
  179. ; Load a register from memory.
  180.  
  181. LODSWR    macro    REG
  182.     lodsw
  183.     ifidni    <®>,<AX>
  184.     else
  185.       mov    REG, ax
  186.     endif
  187.     endm
  188.  
  189. ; =======================================================================
  190. ;
  191. ; Store a register value into memory.
  192.  
  193. STOSWR    macro    REG
  194.     ifidni    <®>,<AX>
  195.     else
  196.       mov    ax, REG
  197.     endif
  198.     stosw
  199.     endm
  200.  
  201. ; ======================================================================
  202. ;
  203. ; Read a word value from an I/O port to a register.
  204.  
  205. INWR    macro    REG
  206.     in    ax, dx
  207.     DELAY    3
  208.     ifidni    <®>,<AX>
  209.     else
  210.       mov    REG, ax
  211.     endif
  212.     endm
  213.  
  214. ; ======================================================================
  215. ;
  216. ; Write a word value to an I/O port from a register.
  217.  
  218. OUTWR    macro    REG
  219.     ifidni    <®>,<AX>
  220.     else
  221.       mov    ax, REG
  222.     endif
  223.     out    dx, ax
  224.     DELAY    3
  225.     endm
  226.  
  227. ; ======================================================================
  228. ;
  229. ; Read a byte value from an I/O port to a register.
  230.  
  231. INBR    macro    REG
  232.     in    al, dx
  233.     DELAY    3
  234.     ifidni    <®>,<AL>
  235.     else
  236.       mov    REG, al
  237.     endif
  238.     endm
  239.  
  240. ; ======================================================================
  241. ;
  242. ; Write a byte value to an I/O port from a register.
  243.  
  244. OUTBR    macro    REG
  245.     ifidni    <®>,<AL>
  246.     else
  247.       mov    al, REG
  248.     endif
  249.     out    dx, al
  250.     DELAY    3
  251.     endm
  252.  
  253. ; ======================================================================
  254. ;
  255. ; Standard header information.
  256.  
  257.     .list
  258.     page    78, 132
  259.     .lall
  260. code    segment    public 'CODE'
  261.     assume    cs:code, ds:nothing, ss:nothing
  262.