Actually call on_reset callback
[lsnes.git] / include / library / memorysearch.hpp
blobe32bc52149f379b0f3c82313edbc5d27fb4a2fbf
1 #ifndef _library__memorysearch__hpp__included__
2 #define _library__memorysearch__hpp__included__
4 #include "memoryspace.hpp"
6 #include <string>
7 #include <list>
8 #include <vector>
9 #include <cstdint>
10 #include <stdexcept>
12 class memory_space;
14 /**
15 * Context for memory search. Each individual context is independent.
17 class memory_search
19 public:
20 /**
21 * Creates a new memory search context with all addresses.
23 * Parameter space: The memory space.
25 memory_search(memory_space& space);
27 /**
28 * Reset the context so all addresses are candidates again.
30 void reset();
32 /**
33 * This searches the memory space, leaving those addresses for which condition object returns true.
35 * Parameter obj The condition to search for.
37 template<class T> void search(const T& obj) throw();
39 /**
40 * DQ a range of addresses (inclusive on both ends!).
42 void dq_range(uint64_t first, uint64_t last);
44 /**
45 * Search for all bytes (update values)
47 void update() throw();
49 /**
50 * Get number of memory addresses that are still candidates
52 uint64_t get_candidate_count() throw();
54 /**
55 * Returns list of all candidates. This function isn't lazy, so be careful when calling with many candidates.
57 std::list<uint64_t> get_candidates();
58 /**
59 * Is specified address a candidate?
61 bool is_candidate(uint64_t addr) throw();
62 /**
63 * Next candidate in VMA.
65 uint64_t cycle_candidate_vma(uint64_t addr, bool next) throw();
67 template<typename T> void s_value(T value) throw();
68 template<typename T> void s_difference(T value) throw();
69 template<typename T> void s_lt() throw();
70 template<typename T> void s_le() throw();
71 template<typename T> void s_eq() throw();
72 template<typename T> void s_ne() throw();
73 template<typename T> void s_ge() throw();
74 template<typename T> void s_gt() throw();
75 template<typename T> void s_seqlt() throw();
76 template<typename T> void s_seqle() throw();
77 template<typename T> void s_seqge() throw();
78 template<typename T> void s_seqgt() throw();
79 template<typename T> T v_read(uint64_t addr) throw();
80 template<typename T> T v_readold(uint64_t addr) throw();
81 template<typename T> void v_write(uint64_t addr, T val) throw();
83 static bool searchable_region(memory_space::region* r)
85 return (r && !r->readonly && !r->special);
87 /**
88 * Savestate type.
90 enum savestate_type
92 ST_PREVMEM,
93 ST_SET,
94 ST_ALL
96 /**
97 * Save state.
99 void savestate(std::vector<char>& buffer, enum savestate_type type) const;
101 * Load state.
103 void loadstate(const std::vector<char>& buffer);
104 private:
105 memory_space& mspace;
106 std::vector<uint8_t> previous_content;
107 std::vector<uint64_t> still_in;
108 uint64_t candidates;
111 #endif