_SIMULATION AND TESTBOARD FOR EMBEDDED SYSTEM DESIGN_ by Michael Kutter [LISTING ONE] FILE *serial_in,*serial_out; void outbyte(unsigned char dest,value) { static long command; /* check to make sure dest indicates SERIAL_DEVICE. */ if (dest != SERIAL_DEVICE) { printf("Error in Hardware destination address\n"); return; } /* reconstruct the command by shifting bits into the */ /* command variable. */ if (control bit in value indicates a new command bit has been sent) { command += new input bit in "value"; command <= 1; } /* record the command after it is complete */ if (latch bit in value indicates the command is complete) { fprintf(serial_out,"serial command: %lx",command); command = 0; } } unsigned char inbyte(unsigned char source) { static long status; unsigned char return_byte = 0; /* check to make sure dest indicates SERIAL_DEVICE. */ if (source != SERIAL_DEVICE) { printf("Error in Hardware destination address\n"); return; } /* get a new status word */ if (latch bit in value indicates a new status read) fscanf(serial_in,"%lx",&status); /* send the status one bit at time, shifting bits */ /* out of the status variable */ if (control bit in status indicates a new statu bit has been requested) { return_byte = status & 0x01; status >= 1; } return(return_byte); } Example 1: Basic RPSC macros #define inbyte(b) (*((unsigned char *)b)) #define outbyte(a,b) (*((unsigned char *)a)=(unsigned char)b) Example 2: You can replace macros with subroutines like these that read from and write to text files FILE *sim_out; /* opened at beginning of simulation */ /* closed at end. */ FILE *sim_in[ONE_FOR_EACH_REGISTER]; unsigned char inbyte(unsigned char address) { int invalue; fscanf(sim_in[address],"%x",&invalue); return(0xFF & invalue); } void outbyte(unsigned char dest,value); { fprintf(sim_out,"%x <-- %x\n",dest,value); }