home *** CD-ROM | disk | FTP | other *** search
- .xlist
-
- ; ======================================================================
- ;
- ; Include-file for MM58167A clock/calendar driver.
- ; (C) Copyright 1990 Richard B. Wales. All Rights Reserved.
-
- ; ======================================================================
- ;
- ; Short delay between successive I/O operations. Without this delay,
- ; a pair of IN and/or OUT operations in immediate succession might fail
- ; on a very fast PC.
-
- DELAY macro COUNT
- rept COUNT
- jmp short $+2
- endm
- endm
-
- ; ======================================================================
- ;
- ; Maximum number of times to attempt a "read" or "write" operation before
- ; giving up. If the counters roll over before we are through accessing
- ; them, the entire operation must be repeated.
-
- MAX_RETRIES equ 5
-
- ; ======================================================================
- ;
- ; Print a string (DOS Int 21H, function 09H).
-
- PRINT macro STRING
- mov ah, 9
- mov dx, offset STRING
- int 21h
- endm
-
- ; ======================================================================
- ;
- ; Push multiple registers.
-
- PUSHM macro r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12
- irp x, <r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12>
- ifnb <&x>
- ifidni <&x>,<flags>
- pushf
- else
- push &x
- endif
- endif
- endm
- endm
-
- ; ======================================================================
- ;
- ; Pop multiple registers.
-
- POPM macro r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12
- irp x, <r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12>
- ifnb <&x>
- ifidni <&x>,<flags>
- popf
- else
- pop &x
- endif
- endif
- endm
- endm
-
- ; ======================================================================
- ;
- ; Set up addressability via DS.
-
- INIT_DS macro
- mov ax, cs
- mov ds, ax
- assume ds:code
- endm
-
- ; ======================================================================
- ;
- ; Swap the high- and low-order bytes in AX.
-
- SWAP macro
- xchg ah, al
- endm
-
- ; ======================================================================
- ;
- ; Split a byte into high- and low-order nybbles in AH and AL.
- ; Assumes CL has previously been loaded with the value 4.
-
- SPLIT macro REG
- ifidni <®>,<AL>
- else
- mov al, REG
- endif
- xor ah, ah
- shl ax, cl
- shr al, cl
- endm
-
- ; ======================================================================
- ;
- ; Check first, and then translate, each byte of a word.
-
- CKXLAT macro SRC, DEST, HBOUND, LBOUND, ERRLABEL
- ifidni <&SRC>,<AX>
- else
- mov ax, SRC
- endif
- cmp al, LBOUND
- ja short ERRLABEL
- xlat
- SWAP
- cmp al, HBOUND
- ja short ERRLABEL
- xlat
- SWAP
- ifidni <&DEST>,<AX>
- else
- mov DEST, ax
- endif
- endm
-
- ; ======================================================================
- ;
- ; Translate first, and then check, each byte of a word.
-
- XLATCK macro SRC, DEST, HBOUND, LBOUND, ERRLABEL
- ifidni <&SRC>,<AX>
- else
- mov ax, SRC
- endif
- xlat
- cmp al, LBOUND
- ja short ERRLABEL
- SWAP
- xlat
- cmp al, HBOUND
- ja short ERRLABEL
- SWAP
- ifidni <&DEST>,<AX>
- else
- mov DEST, ax
- endif
- endm
-
- ; ======================================================================
- ;
- ; Translate first, and then check, each byte of a word.
- ; Also include a check for a zero result after translation.
- ; Suppress the final SWAP.
-
- XLATCKZ macro SRC, DEST, HBOUND, LBOUND, ERRLABEL
- ifidni <&SRC>,<AX>
- else
- mov ax, SRC
- endif
- xlat
- cmp al, LBOUND
- ja short ERRLABEL
- and al, al
- jz short ERRLABEL
- SWAP
- xlat
- cmp al, HBOUND
- ja short ERRLABEL
- and al, al
- jz short ERRLABEL
- ifidni <&DEST>,<AX>
- else
- mov DEST, ax
- endif
- endm
-
- ; =======================================================================
- ;
- ; Load a register from memory.
-
- LODSWR macro REG
- lodsw
- ifidni <®>,<AX>
- else
- mov REG, ax
- endif
- endm
-
- ; =======================================================================
- ;
- ; Store a register value into memory.
-
- STOSWR macro REG
- ifidni <®>,<AX>
- else
- mov ax, REG
- endif
- stosw
- endm
-
- ; ======================================================================
- ;
- ; Read a word value from an I/O port to a register.
-
- INWR macro REG
- in ax, dx
- DELAY 3
- ifidni <®>,<AX>
- else
- mov REG, ax
- endif
- endm
-
- ; ======================================================================
- ;
- ; Write a word value to an I/O port from a register.
-
- OUTWR macro REG
- ifidni <®>,<AX>
- else
- mov ax, REG
- endif
- out dx, ax
- DELAY 3
- endm
-
- ; ======================================================================
- ;
- ; Read a byte value from an I/O port to a register.
-
- INBR macro REG
- in al, dx
- DELAY 3
- ifidni <®>,<AL>
- else
- mov REG, al
- endif
- endm
-
- ; ======================================================================
- ;
- ; Write a byte value to an I/O port from a register.
-
- OUTBR macro REG
- ifidni <®>,<AL>
- else
- mov al, REG
- endif
- out dx, al
- DELAY 3
- endm
-
- ; ======================================================================
- ;
- ; Standard header information.
-
- .list
- page 78, 132
- .lall
- code segment public 'CODE'
- assume cs:code, ds:nothing, ss:nothing