1 //
2 // srecord - manipulate eprom load files
3 // Copyright (C) 1998, 1999, 2001, 2002, 2006-2008, 2010 Peter Miller
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program. If not, see
17 // <http://www.gnu.org/licenses/>.
18 //
19 
20 #include <srecord/input/filter/unsplit.h>
21 #include <srecord/record.h>
22 
23 
~input_filter_unsplit()24 srecord::input_filter_unsplit::~input_filter_unsplit()
25 {
26 }
27 
28 
input_filter_unsplit(const srecord::input::pointer & a1,int a2,int a3,int a4)29 srecord::input_filter_unsplit::input_filter_unsplit(
30         const srecord::input::pointer &a1, int a2, int a3, int a4) :
31     srecord::input_filter(a1),
32     modulus(a2),
33     offset(a3),
34     width(a4),
35     buffer(),
36     buffer_pos(0)
37 {
38 }
39 
40 
41 srecord::input::pointer
create(const input::pointer & a_deeper,int a2,int a3,int a4)42 srecord::input_filter_unsplit::create(const input::pointer &a_deeper, int a2,
43     int a3, int a4)
44 {
45     return pointer(new srecord::input_filter_unsplit(a_deeper, a2, a3, a4));
46 }
47 
48 
49 bool
read(srecord::record & record)50 srecord::input_filter_unsplit::read(srecord::record &record)
51 {
52     for (;;)
53     {
54         while
55         (
56             buffer.get_type() != srecord::record::type_data
57         ||
58             buffer_pos >= buffer.get_length()
59         )
60         {
61             if (!srecord::input_filter::read(buffer))
62                 return false;
63             if (buffer.get_type() != srecord::record::type_data)
64             {
65                 record = buffer;
66                 return true;
67             }
68             buffer_pos = 0;
69         }
70 
71         unsigned long addr = buffer.get_address() + buffer_pos;
72         unsigned char c = buffer.get_data(buffer_pos++);
73         int phase = addr % width;
74         addr = (addr / width) * modulus + phase + offset;
75         record = srecord::record(srecord::record::type_data, addr, &c, 1);
76         return true;
77     }
78 }
79