home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / microcrn / issue_48.arc / PPXFER.ARC / BLOCK.C next >
C/C++ Source or Header  |  1988-04-23  |  2KB  |  67 lines

  1. #pragma inline
  2. #include "ppxfer.h"
  3. #define SVE asm push AX; asm push BX; asm push CX; asm push DX; asm push F;
  4. #define RST asm pop AX; asm pop BX; asm pop CX; asm pop DX; asm pop F;
  5.  
  6.  
  7. void receive_block (dbyte * buffer, unsigned int count) {
  8.     _CX = count;
  9.     _BX = buffer;
  10.     _DX = BASE + 2;
  11. wait1:
  12.     asm in AL,DX;
  13.     asm test AL, 00001000B;
  14.     asm jz wait1;    /* wait for handshake to drop */
  15. hshake_lo:
  16.     asm dec DX;        /* BASE + 1 */
  17.     asm in AL,DX;
  18.     asm and AL, 11111000B;  /* mask off pertinent bits */
  19.     asm mov AH,AL;       /* stash it */
  20.     asm inc DX;        /* BASE + 2 */
  21.     asm in AL,DX;
  22.     asm and AL, 00000111B;  /* rest of byte */
  23.     asm or AL,AH;       /* combine the byte */
  24.     asm xor AL, 10000011B;  /* flip "inverted" bits */
  25.     asm mov byte ptr [BX], AL;       /* store the result */
  26.     asm inc BX;             /* move the pointer to the next mem location */
  27.     _DX = BASE;
  28.     asm mov AL, 11111110B;
  29.     asm out DX,AL;        /* lower "byte recd" line */
  30.     _DX = BASE + 2;
  31. wait2:
  32.     asm in AL,DX;
  33.     asm test AL,00001000B;
  34.     asm jnz wait2;           /* wait for handshake to rise */
  35.     _DX = BASE;
  36.     asm mov AL, 11111111B;
  37.     asm out DX, AL;    /* De-assert "byte recd" */
  38.     _DX = BASE+2;
  39.     asm loop wait1;
  40. }
  41.  
  42. void send_block (dbyte * buffer, unsigned int count) {
  43.     _CX = count;
  44.     _BX = buffer;
  45.     _DX = BASE;
  46. send:
  47.     asm mov AL,byte ptr [BX];     /* get a byte to send */
  48.     asm inc BX;
  49.     asm out DX,AL;
  50.     _DX = BASE + 2;
  51.     asm mov AL, 1100B    /* lower handshake */
  52.     asm out DX,AL;
  53. wait3:
  54.     asm in AL,DX;        /* wait for "byte recd" to go low */
  55.     asm test AL,1;
  56.     asm jz wait3;
  57. byterecd:
  58.     asm mov AL, 0100B;    /* raise handshake */
  59.     asm out DX,AL;
  60. wait4:
  61.     asm in AL,DX;
  62.     asm test AL,1;        /* wait for byte recd to go high */
  63.     asm jnz wait4;
  64.     _DX = BASE;
  65.     asm loop send;
  66. }
  67.