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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
|
//
// srecord - manipulate eprom load files
// Copyright (C) 1998, 1999, 2001-2003, 2005 Peter Miller;
// All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
//
// MANIFEST: interface definition for lib/srec/record.cc
//
#ifndef INCLUDE_SREC_RECORD_H
#define INCLUDE_SREC_RECORD_H
#pragma interface "srec_record"
/**
* The srec_record class is used to represent a data record read
* from a file. (It is not limited to any particular file format.)
* The records may be of various types.
*/
class srec_record
{
public:
/**
* The destructor. It isn't vurtual, so don't derived anything
* from this class.
*/
~srec_record();
/**
* The type of the various record types.
*/
enum type_t
{
type_unknown,
type_header,
type_data,
type_data_count,
type_start_address
};
/**
* The type of record addresses.
*/
typedef unsigned long address_t;
/**
* The type of record data values.
*/
typedef unsigned char data_t;
/**
* The default constructor. The record will have an
* indeterminate type, zero address, and no data.
*/
srec_record();
/**
* The copy constructor.
*/
srec_record(const srec_record &);
/**
* A constructor. The record will have the given type, a zero
* address and no data.
*/
srec_record(type_t);
/**
* A constructor. The record will have the given type, the
* given address and no data.
*/
srec_record(type_t, address_t);
/**
* A constructor. The record will have the given type, the
* given address and a copy of the given data.
*/
srec_record(type_t the_type, address_t the_address, const data_t *the_data,
int the_data_length);
/**
* The assignment operator.
*/
srec_record &operator=(const srec_record &);
/**
* The get_address method is used to get the address of the
* record.
*/
address_t get_address() const { return address; }
/**
* The get_address_end method is used to get the address "off
* the end" of this record.
*/
address_t get_address_end() const { return (address + length); }
/**
* The set_address method is used to set the address of the
* record.
*/
void set_address(address_t arg) { address = arg; }
/**
* The get_length method is used to get the length (number of
* bytes) of the record data.
*/
int get_length() const { return length; }
/**
* The set_length method is used to set the number of data
* bytes in the reocrd data.
*
* Note that you can reduce the length, but you can't increase it.
*/
void
set_length(int arg)
{
if (arg < 0)
arg = 0;
if (arg < length)
length = arg;
}
/**
* The get_data method is used to get a ponter to the baseof
* the record data.
*
* Note: Accessing beyond get_length() bytes will give an
* undefined value.
*/
const data_t *get_data() const { return data; }
/**
* The get_data method is used to fetch the nth data value.
*
* Note: For perfoemance reasons, no range checking is
* performed. Accessing beyond get_length() bytes will give
* an undefined value.
*/
int get_data(int n) const { return data[n]; }
/**
* The is_all_zero method is used to determin if the record
* contains data bytes which are all zero.
*/
bool is_all_zero() const;
/**
* The set_data method is used to set values in the data array.
* No range checking is performed. The record length is not
* consulted or adjusted.
*/
void set_data(int n, int d) { data[n] = d; }
/**
* The get_type method is used to get the type of the record.
*/
type_t get_type() const { return type; }
/**
* The set_type method is used to set the type of the record.
*/
void set_type(type_t arg) { type = arg; }
/**
* The maximum_data_length method is used to determine the
* maximum data length possible within a record, for a given
* address.
*/
static int maximum_data_length(address_t);
/**
* The decode_big_endian method is used to extract `len'
* bytes from the given `data' and assemble a big-endian value
* (most significant byte first).
*/
static address_t decode_big_endian(data_t *data, int len);
/**
* The encode_big_endian method is used to break down `val' into
* 'len' bytes of `data' orderdd big-endian (most significan
* byte first).
*/
static void encode_big_endian(data_t *data, address_t val, int len);
/**
* The encode_little_endian method is used to break down
* `val' into 'len' bytes of `data' orderdd big-endian (least
* significan byte first).
*/
static void encode_little_endian(data_t *data, address_t val, int len);
enum {
/**
* The max_data_length is the largest number of data bytes
* which any record can hold.
*/
max_data_length = 255 };
private:
/**
* The type instance variable is used to remember the type of
* the record.
*/
type_t type;
/**
* The address instance variable is used to remember the address
* of the record.
*/
address_t address;
/**
* The length instance variable is used to remember the number
* of valid bytes in the `data' array.
*/
int length;
/**
* The data instance variable is used to remember the data
* of the record. Only the first `length' bytes are valid,
* the rest are undefined.
*/
data_t data[max_data_length];
};
#endif // INCLUDE_SREC_RECORD_H
|