home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / dobbs / v16n10 / embedcp.exe / CODE.EXE / MEMIO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-28  |  3.3 KB  |  120 lines

  1. // MIOTDREM - Memory and IO support
  2. // --------------------------------
  3. //
  4. // Copyright (c) 1991, Stuart G. Phillips.  All rights reserved.
  5. //
  6. // Permission is granted for non-commercial use of this software.
  7. // You are expressly prohibited from selling this software in any form,
  8. // distributing it with another product, or removing this notice.
  9. // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  10. // IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  11. // WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  12. // PURPOSE.
  13. //
  14. // This module contains the support for all memory and IO operations
  15. // such as read/write memory, read/write IO etc.
  16. //
  17.  
  18. #include "miotdr.h"
  19. #include "mio.h"
  20.  
  21. void read_memory(unsigned int segment,
  22.                  unsigned int offset,
  23.                  unsigned char count)
  24. {
  25.     // Read [count] bytes from specified [segment:offset];
  26.  
  27.     unsigned char *p = (unsigned char *)
  28.                             (((long)segment << 16) + (long)offset);
  29.     unsigned char *txb = tx_buffer;
  30.  
  31.     for (int i = 0;i < count;i++)
  32.         *txb++ = *p++;
  33.  
  34.     send(tx_buffer,(unsigned int)count);
  35. }
  36.  
  37.  
  38. void write_memory(unsigned int segment,
  39.                   unsigned int offset,
  40.                   unsigned char count,
  41.                   unsigned char *data)
  42. {
  43.     // Write [count] bytes of data into the specified [segment:offset]
  44.  
  45.     unsigned char *p = (unsigned char *)
  46.                             (((long)segment << 16) + (long)offset);
  47.  
  48.     for (int i = 0;i < count;i++)
  49.         *p++ = *data++;
  50.  
  51.     send_ack();
  52. }
  53.  
  54.  
  55. void read_io(unsigned int port,
  56.              unsigned char word_or_byte)
  57. {
  58.     // Read the specified IO port; word_or_byte TRUE indicates WORD
  59.     struct td_omsg *txb = (struct td_omsg *) tx_buffer;
  60.  
  61.     if (word_or_byte)
  62.         txb->td_readio.value = inportw(port);
  63.     else
  64.         txb->td_readio.value = inportb(port);
  65.  
  66.     send((unsigned char *)txb,sizeof(txb->td_readio));
  67. }
  68.  
  69.  
  70. void write_io(unsigned int port,
  71.               unsigned char word_or_byte,
  72.               unsigned int data)
  73. {
  74.     // Write the supplied data to the specified port; word_or_byte TRUE
  75.     // indicates WORD
  76.  
  77.     if (word_or_byte)
  78.         outportw(port,data);
  79.     else
  80.         outportb(port,data);
  81.  
  82.     send_ack();
  83. }
  84.  
  85.  
  86. void set_mem(unsigned int segment,
  87.              unsigned int offset,
  88.              unsigned int count,
  89.              unsigned char data)
  90. {
  91.     // Set memory at [segment:offset] to [data] for [count] bytes
  92.     unsigned char *p = (unsigned char *)
  93.                             (((long)segment << 16) + (long) offset);
  94.  
  95.     for (int i = 0;i < count;i++)
  96.         *p++ = data;
  97.  
  98.     send_ack();
  99. }
  100.  
  101.  
  102. void copy_mem(unsigned int src_seg,
  103.               unsigned int src_off,
  104.               unsigned int dst_seg,
  105.               unsigned int dst_off,
  106.               unsigned int count)
  107. {
  108.     // Copy memory from [src_seg:src_off] to [dst_seg:dst_off] for
  109.     // [count] bytes
  110.     unsigned char *s = (unsigned char *)
  111.                             (((long)src_seg << 16) + (long)src_off),
  112.                   *d = (unsigned char *)
  113.                             (((long)dst_seg << 16) + (long)dst_off);
  114.  
  115.     for (int i = 0;i < count;i++)
  116.         *d++ = *s++;
  117.  
  118.     send_ack();
  119. }
  120.