1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
// tap.cpp
// Revision 13-dec-2004
#include "tap.h"
#include <algorithm>
using std::fill;
tap::CodeHeader::CodeHeader (address init, address size,
const std::string & filename)
{
//memset (block, 0, sizeof (block) );
fill (block, block + sizeof (block), byte (0) );
block [0]= 19; // Length of block: 17 bytes + flag + checksum
block [1]= 0;
block [2]= 0; // Flag: 00 -> header
block [3]= 3; // Type: code block.
// File name.
std::string::size_type l= filename.size ();
if (l > 10)
l= 10;
for (std::string::size_type i= 0; i < 10; ++i)
block [4 + i]= i < l ? filename [i] : ' ';
// Length of the code block.
block [14]= lobyte (size);
block [15]= hibyte (size);
// Start of the code block.
block [16]= lobyte (init);
block [17]= hibyte (init);
// Parameter 2: 32768 in a code block.
block [18]= 0x00;
block [19]= 0x80;
// Checksum
byte check= block [2]; // Flag byte included.
for (int i= 3; i < 20; ++i)
check^= block [i];
block [20]= check;
}
void tap::CodeHeader::write (std::ostream & out) const
{
out.write (reinterpret_cast <const char *> (block), sizeof (block) );
}
tap::CodeBlock::CodeBlock (address sizen, const byte * datan) :
datasize (sizen),
data (datan)
{
address blocksize= datasize + 2; // Code + flag + checksum.
head [0]= lobyte (blocksize);
head [1]= hibyte (blocksize);
head [2]= 0xFF; // Flag: data block.
// Compute the checksum.
check= 0xFF; // Flag byte included.
for (int i= 0; i < datasize; ++i)
check^= data [i];
}
void tap::CodeBlock::write (std::ostream & out) const
{
out.write (reinterpret_cast <const char *> (head), sizeof (head) );
out.write (reinterpret_cast <const char *> (data), datasize);
out.write (reinterpret_cast <const char *> (& check), 1);
}
address tap::CodeBlock::size () const
{
return datasize + sizeof (head) + 1;
}
tap::BasicHeader::BasicHeader (const std::string & basic)
{
block [0]= 19;
block [1]= 0;
block [2]= 0; // Flag: header.
block [3]= 0; // Type: Basic block.
for (int i= 0; i < 10; ++i)
block [4 + i]= "loader " [i];
// Length of the basic block.
const address basicsize= static_cast <address> (basic.size () );
block [14]= lobyte (basicsize);
block [15]= hibyte (basicsize);
// Autostart in line 10.
block [16]= '\x0A';
block [17]= '\x00';
// Start of variable area: at the end.
block [18]= block [14];
block [19]= block [15];
// Checksum
byte check= block [2]; // Flag byte included.
for (int i= 3; i < 20; ++i)
check^= block [i];
block [20]= check;
}
void tap::BasicHeader::write (std::ostream & out) const
{
out.write (reinterpret_cast <const char *> (block), sizeof (block) );
}
tap::BasicBlock::BasicBlock (const std::string & basicn) :
basic (basicn),
basicsize (static_cast <address> (basic.size () ) )
{
address blocksize= basicsize + 2; // Code + flag + checksum.
block [0]= blocksize & 0xFF;
block [1]= blocksize >> 8;
block [2]= 0xFF; // Flag: data block.
// Compute the checksum.
check= 0xFF; // Flag byte included.
for (int i= 0; i < basicsize; ++i)
check^= static_cast <unsigned char> (basic [i]);
}
void tap::BasicBlock::write (std::ostream & out) const
{
out.write (reinterpret_cast <const char *> (block), sizeof (block) );
out.write (basic.data (), basicsize);
out.write (reinterpret_cast <const char *> (& check), 1);
}
// End of tap.cpp
|