Clean up some header files
[lsnes.git] / memorymanip.hpp
blobda01dd71d85d7d7b9bfe167255c4346a2b5b2b81
1 #ifndef _memorymanip__hpp__included__
2 #define _memorymanip__hpp__included__
4 #include "window.hpp"
5 #include <string>
6 #include <list>
7 #include <vector>
8 #include <cstdint>
9 #include <stdexcept>
11 /**
12 * \brief Information about region of memory
14 * This structure contains information about memory region.
16 struct memory_region
18 /**
19 * \brief Name of region.
21 * This is name of region, mainly for debugging and showing to the user.
23 std::string region_name;
24 /**
25 * \brief Base address of region.
27 uint32_t baseaddr;
28 /**
29 * \brief Size of region in bytes.
31 uint32_t size;
32 /**
33 * \brief Last valid address in this region.
35 uint32_t lastaddr;
36 /**
37 * \brief True for ROM, false for RAM.
39 bool readonly;
40 /**
41 * \brief Endianess of the region.
43 * If true, region uses host endian.
44 * If false, region uses SNES (big) endian.
46 bool native_endian;
49 /**
50 * \brief Refresh cart memory mappings
52 * This function rereads cartridge memory map. Call after loading a new cartridge.
54 * \throws std::bad_alloc Not enough memory.
56 void refresh_cart_mappings() throw(std::bad_alloc);
58 /**
59 * \brief Get listing of all regions
61 * This function returns a list of all known regions.
63 * \return All regions
64 * \throws std::bad_alloc Not enough memory.
66 std::vector<struct memory_region> get_regions() throw(std::bad_alloc);
68 /**
69 * \brief Read byte from memory
71 * This function reads one byte from memory.
73 * \param addr The address to read.
74 * \return The byte read.
76 uint8_t memory_read_byte(uint32_t addr) throw();
78 /**
79 * \brief Read word from memory
81 * This function reads two bytes from memory.
83 * \param addr The address to read.
84 * \return The word read.
86 uint16_t memory_read_word(uint32_t addr) throw();
88 /**
89 * \brief Read dword from memory
91 * This function reads four bytes from memory.
93 * \param addr The address to read.
94 * \return The dword read.
96 uint32_t memory_read_dword(uint32_t addr) throw();
98 /**
99 * \brief Read qword from memory
101 * This function reads eight bytes from memory.
103 * \param addr The address to read.
104 * \return The qword read.
106 uint64_t memory_read_qword(uint32_t addr) throw();
109 * \brief Write byte to memory
111 * This function writes one byte to memory.
113 * \param addr The address to write.
114 * \param data The value to write.
115 * \return true if the write succeeded.
117 bool memory_write_byte(uint32_t addr, uint8_t data) throw();
120 * \brief Write word to memory
122 * This function writes two bytes to memory.
124 * \param addr The address to write.
125 * \param data The value to write.
126 * \return true if the write succeeded.
128 bool memory_write_word(uint32_t addr, uint16_t data) throw();
131 * \brief Write dword to memory
133 * This function writes four bytes to memory.
135 * \param addr The address to write.
136 * \param data The value to write.
137 * \return true if the write succeeded.
139 bool memory_write_dword(uint32_t addr, uint32_t data) throw();
142 * \brief Write qword to memory
144 * This function writes eight bytes to memory.
146 * \param addr The address to write.
147 * \param data The value to write.
148 * \return true if the write succeeded.
150 bool memory_write_qword(uint32_t addr, uint64_t data) throw();
153 * \brief Memory search context
155 * Context for memory search. Each individual context is independent.
157 class memorysearch
159 public:
161 * \brief Create new memory search context.
163 * Creates a new memory search context with all addresses.
165 * \throws std::bad_alloc Not enough memory.
167 memorysearch() throw(std::bad_alloc);
170 * \brief Reset the context
172 * Reset the context so all addresses are candidates again.
174 * \throws std::bad_alloc Not enough memory.
176 void reset() throw(std::bad_alloc);
179 * \brief Search for address satisfying criteria
181 * This searches the memory space, leaving those addresses for which condition object returns true.
183 * \param obj The condition to search for.
185 template<class T>
186 void search(const T& obj) throw();
189 * \brief Search for byte with specified value
190 * \param value The value to search for
192 void byte_value(uint8_t value) throw();
194 * \brief Search for bytes that are signed less
196 void byte_slt() throw();
198 * \brief Search for bytes that are signed less or equal
200 void byte_sle() throw();
202 * \brief Search for bytes that are signed equal
204 void byte_seq() throw();
206 * \brief Search for bytes that are signed not equal
208 void byte_sne() throw();
210 * \brief Search for bytes that are signed greater or equal
212 void byte_sge() throw();
214 * \brief Search for bytes that are signed greater
216 void byte_sgt() throw();
218 * \brief Search for bytes that are unsigned less
220 void byte_ult() throw();
222 * \brief Search for bytes that are unsigned less or equal
224 void byte_ule() throw();
226 * \brief Search for bytes that are unsigned equal
228 void byte_ueq() throw();
230 * \brief Search for bytes that are unsigned not equal
232 void byte_une() throw();
234 * \brief Search for bytes that are unsigned greater or equal
236 void byte_uge() throw();
238 * \brief Search for bytes that are unsigned greater
240 void byte_ugt() throw();
243 * \brief Search for word with specified value
244 * \param value The value to search for
246 void word_value(uint16_t value) throw();
248 * \brief Search for words that are signed less
250 void word_slt() throw();
252 * \brief Search for words that are signed less or equal
254 void word_sle() throw();
256 * \brief Search for words that are signed equal
258 void word_seq() throw();
260 * \brief Search for words that are signed not equal
262 void word_sne() throw();
264 * \brief Search for words that are signed greater or equal
266 void word_sge() throw();
268 * \brief Search for words that are signed greater
270 void word_sgt() throw();
272 * \brief Search for words that are unsigned less
274 void word_ult() throw();
276 * \brief Search for words that are unsigned less or equal
278 void word_ule() throw();
280 * \brief Search for words that are unsigned equal
282 void word_ueq() throw();
284 * \brief Search for words that are unsigned not equal
286 void word_une() throw();
288 * \brief Search for words that are unsigned greater or equal
290 void word_uge() throw();
292 * \brief Search for words that are unsigned greater
294 void word_ugt() throw();
297 * \brief Search for dword with specified value
298 * \param value The value to search for
300 void dword_value(uint32_t value) throw();
302 * \brief Search for dwords that are signed less
304 void dword_slt() throw();
306 * \brief Search for dwords that are signed less or equal
308 void dword_sle() throw();
310 * \brief Search for dwords that are signed equal
312 void dword_seq() throw();
314 * \brief Search for dwords that are signed not equal
316 void dword_sne() throw();
318 * \brief Search for dwords that are signed greater or equal
320 void dword_sge() throw();
322 * \brief Search for dwords that are signed greater
324 void dword_sgt() throw();
326 * \brief Search for dwords that are unsigned less
328 void dword_ult() throw();
330 * \brief Search for dwords that are unsigned less or equal
332 void dword_ule() throw();
334 * \brief Search for dwords that are unsigned equal
336 void dword_ueq() throw();
338 * \brief Search for dwords that are unsigned not equal
340 void dword_une() throw();
342 * \brief Search for dwords that are unsigned greater or equal
344 void dword_uge() throw();
346 * \brief Search for dwords that are unsigned greater
348 void dword_ugt() throw();
351 * \brief Search for qword with specified value
352 * \param value The value to search for
354 void qword_value(uint64_t value) throw();
356 * \brief Search for qwords that are signed less
358 void qword_slt() throw();
360 * \brief Search for qwords that are signed less or equal
362 void qword_sle() throw();
364 * \brief Search for qwords that are signed equal
366 void qword_seq() throw();
368 * \brief Search for qwords that are signed not equal
370 void qword_sne() throw();
372 * \brief Search for qwords that are signed greater or equal
374 void qword_sge() throw();
376 * \brief Search for qwords that are signed greater
378 void qword_sgt() throw();
380 * \brief Search for qwords that are unsigned less
382 void qword_ult() throw();
384 * \brief Search for qwords that are unsigned less or equal
386 void qword_ule() throw();
388 * \brief Search for qwords that are unsigned equal
390 void qword_ueq() throw();
392 * \brief Search for qwords that are unsigned not equal
394 void qword_une() throw();
396 * \brief Search for qwords that are unsigned greater or equal
398 void qword_uge() throw();
400 * \brief Search for qwords that are unsigned greater
402 void qword_ugt() throw();
405 * \brief Get number of memory addresses that are still candidates
407 * This returns the number of memory addresses satisfying constraints so far.
409 * \return The number of candidates
411 uint32_t get_candidate_count() throw();
414 * \brief Get List of all candidate addresses
416 * Returns list of all candidates. This function isn't lazy, so be careful when calling with many candidates.
418 * \return Candidate address list
419 * \throws std::bad_alloc Not enough memory.
421 std::list<uint32_t> get_candidates() throw(std::bad_alloc);
422 private:
423 std::vector<uint8_t> previous_content;
424 std::vector<uint64_t> still_in;
425 uint32_t candidates;
428 #endif