home *** CD-ROM | disk | FTP | other *** search
- // MIOTDREM - Memory and IO support
- // --------------------------------
- //
- // Copyright (c) 1991, Stuart G. Phillips. All rights reserved.
- //
- // Permission is granted for non-commercial use of this software.
- // You are expressly prohibited from selling this software in any form,
- // distributing it with another product, or removing this notice.
- // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- // IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- // WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
- // PURPOSE.
- //
- // This module contains the support for all memory and IO operations
- // such as read/write memory, read/write IO etc.
- //
-
- #include "miotdr.h"
- #include "mio.h"
-
- void read_memory(unsigned int segment,
- unsigned int offset,
- unsigned char count)
- {
- // Read [count] bytes from specified [segment:offset];
-
- unsigned char *p = (unsigned char *)
- (((long)segment << 16) + (long)offset);
- unsigned char *txb = tx_buffer;
-
- for (int i = 0;i < count;i++)
- *txb++ = *p++;
-
- send(tx_buffer,(unsigned int)count);
- }
-
-
- void write_memory(unsigned int segment,
- unsigned int offset,
- unsigned char count,
- unsigned char *data)
- {
- // Write [count] bytes of data into the specified [segment:offset]
-
- unsigned char *p = (unsigned char *)
- (((long)segment << 16) + (long)offset);
-
- for (int i = 0;i < count;i++)
- *p++ = *data++;
-
- send_ack();
- }
-
-
- void read_io(unsigned int port,
- unsigned char word_or_byte)
- {
- // Read the specified IO port; word_or_byte TRUE indicates WORD
- struct td_omsg *txb = (struct td_omsg *) tx_buffer;
-
- if (word_or_byte)
- txb->td_readio.value = inportw(port);
- else
- txb->td_readio.value = inportb(port);
-
- send((unsigned char *)txb,sizeof(txb->td_readio));
- }
-
-
- void write_io(unsigned int port,
- unsigned char word_or_byte,
- unsigned int data)
- {
- // Write the supplied data to the specified port; word_or_byte TRUE
- // indicates WORD
-
- if (word_or_byte)
- outportw(port,data);
- else
- outportb(port,data);
-
- send_ack();
- }
-
-
- void set_mem(unsigned int segment,
- unsigned int offset,
- unsigned int count,
- unsigned char data)
- {
- // Set memory at [segment:offset] to [data] for [count] bytes
- unsigned char *p = (unsigned char *)
- (((long)segment << 16) + (long) offset);
-
- for (int i = 0;i < count;i++)
- *p++ = data;
-
- send_ack();
- }
-
-
- void copy_mem(unsigned int src_seg,
- unsigned int src_off,
- unsigned int dst_seg,
- unsigned int dst_off,
- unsigned int count)
- {
- // Copy memory from [src_seg:src_off] to [dst_seg:dst_off] for
- // [count] bytes
- unsigned char *s = (unsigned char *)
- (((long)src_seg << 16) + (long)src_off),
- *d = (unsigned char *)
- (((long)dst_seg << 16) + (long)dst_off);
-
- for (int i = 0;i < count;i++)
- *d++ = *s++;
-
- send_ack();
- }
-