srecord: input/file/logisim.h Source File

srecord 1.65.0

Loading...
Searching...
No Matches
logisim.h
Go to the documentation of this file.
1//
2// srecord - Manipulate EPROM load files
3// Copyright (C) 2013 Peter Miller
4//
5// This program is free software; you can redistribute it and/or modify it
6// 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 (at your
8// option) any later version.
9//
10// This program is distributed in the hope that it will be useful, but WITHOUT
11// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13// 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 <http://www.gnu.org/licenses/>.
17//
18
19#ifndef SRECORD_INPUT_FILE_LOGISIM_H
20#define SRECORD_INPUT_FILE_LOGISIM_H
21
22#include <inttypes.h>
23#include <list>
24
25#include <srecord/record.h>
26#include <srecord/input/file.h>
27
28namespace srecord {
29
30/**
31 * The input_file_logisim class is used to represent
32 * the processing required to parse Logisim rom data files.
33 *
34 *
35 * http://ozark.hendrix.edu/~burch/logisim/docs/2.3.0/guide/mem/menu.html
36 *
37 * Pop-up menus and files
38 *
39 * The pop-up menu for memory includes four options in addition to the
40 * options common to all components:
41 *
42 * Edit Contents:
43 * Bring up a hex editor for editing the contents of memory.
44 * Clear Contents:
45 * Resets all values in memory to 0.
46 * Load Image...:
47 * Resets all values in memory based on the values found in a file
48 * using the format described below.
49 * Save Image...:
50 * Stores all values in memory into a file using the format
51 * described below.
52 *
53 * The file format used for image files is intentionally simple; this
54 * permits you to write a program, such as an assembler, that generates
55 * memory images that can then be loaded into memory. As an example of
56 * this file format, if we had a 256-byte memory whose first five bytes
57 * were 2, 3, 0, 20, and -1, and all subsequent values were 0, then the
58 * image would be the following text file.
59 *
60 * v2.0 raw
61 *
62 * 02
63 * 03
64 * 00
65 * 14
66 * ff
67 *
68 * The first line identifies the file format used (currently, there is
69 * only one file format recognized). Subsequent values list the values
70 * in hexadecimal, starting from address 0; you can place several
71 * such values on the same line. Logisim will assume that any values
72 * unlisted in the file are zero.
73 *
74 * The image file can use run-length encoding; for example, rather
75 * than list the value 00 sixteen times in a row, the file can include
76 * 16*00 rather than repeat 00 sixteen times. Notice than the number of
77 * repetitions is written in base 10. Files produced by Logisim will
78 * use run-length encoding for runs of at least four values
79 */
80 class input_file_logisim:
81 public input_file
82{
83public:
84 /**
85 * The destructor.
86 */
87 virtual ~input_file_logisim();
88
89 static input_file::pointer create(const std::string &file_name);
90
91 enum state_t
92 {
93 state_line_one,
94 state_line_two,
95 state_lines_of_data,
96 };
97
98protected:
99 // See base class for documentation
100 bool read(srecord::record &rec);
101
102 // See base class for documentation
103 const char *get_file_format_name(void) const;
104
105 // See base class for documentation
106 int format_option_number(void) const;
107
108 /**
109 * The constructor.
110 */
111 input_file_logisim(const std::string &file_name);
112
113private:
114 srecord::record::address_t address;
115 state_t state;
116
117 struct datum_t
118 {
119 datum_t() : address(0), count(1), value(0xFF) { }
120 datum_t(uint32_t aa, long ac, uint32_t av) :
121 address(aa), count(ac), value(av) { }
122 uint32_t address;
123 long count;
124 uint32_t value;
125 std::string representation(void) const;
126 };
127
128 std::list<datum_t> jobs;
129
130 bool read_inner(record &rec);
131 void read_inner_one(void);
132 void read_inner_two(void);
133 void read_inner_job(void);
134
135 /**
136 * The default constructor.
137 */
138 input_file_logisim();
139
140 /**
141 * The copy constructor.
142 */
143 input_file_logisim(const input_file_logisim &);
144
145 /**
146 * The assignment operator.
147 */
148 input_file_logisim &operator=(const input_file_logisim &);
149};
150
151};
152
153// vim: set ts=8 sw=4 et :
154#endif // SRECORD_INPUT_FILE_LOGISIM_H
srecord::input_file_logisim::read
bool read(srecord::record &rec)
The read method is used to read one record from the input.
srecord::input_file_logisim::get_file_format_name
const char * get_file_format_name(void) const
The get_file_format_name method is used to find out the name of the file format being read.
srecord::input_file_logisim::~input_file_logisim
virtual ~input_file_logisim()
The destructor.
srecord::input_file_logisim::create
static input_file::pointer create(const std::string &file_name)
srecord::input_file_logisim::format_option_number
int format_option_number(void) const
The format_option_number method is used to obtain the option number, which can then be turned into te...
srecord::input_file_logisim::state_t
state_t
Definition logisim.h:92
srecord::input_file_logisim::state_line_one
@ state_line_one
Definition logisim.h:93
srecord::input_file_logisim::state_lines_of_data
@ state_lines_of_data
Definition logisim.h:95
srecord::input_file_logisim::state_line_two
@ state_line_two
Definition logisim.h:94
srecord::input_file_logisim::input_file_logisim
input_file_logisim(const std::string &file_name)
The constructor.
srecord::input_file::input_file
input_file(const std::string &file_name)
The constructor.
srecord::input_file::pointer
std::shared_ptr< input_file > pointer
Definition file.h:39
srecord::record
The srecord::record class is used to represent a data record read from a file.
Definition record.h:35
srecord::record::address_t
uint32_t address_t
The type of record addresses.
Definition record.h:58
file.h
srecord
Definition adler16.h:25
record.h