| 1 |
#ifndef BREAKPOINT_HH |
| 2 |
#define BREAKPOINT_HH |
| 3 |
|
| 4 |
#include "BreakPointBase.hh" |
| 5 |
#include "CommandException.hh" |
| 6 |
|
| 7 |
#include "strCat.hh" |
| 8 |
|
| 9 |
#include <cstdint> |
| 10 |
#include <optional> |
| 11 |
|
| 12 |
namespace openmsx { |
| 13 |
|
| 14 |
class BreakPoint final : public BreakPointBase<BreakPoint> |
| 15 |
{ |
| 16 |
public: |
| 17 |
static constexpr std::string_view prefix = "bp#"; |
| 18 |
|
| 19 |
public: |
| 20 |
[[nodiscard]] std::optional<uint16_t> getAddress() const { return address; } |
| 21 |
[[nodiscard]] TclObject getAddressString() const { return addrStr; } |
| 22 |
void setAddress(Interpreter& interp, const TclObject& addr) { |
| 23 |
addrStr = addr; |
| 24 |
evaluateAddress(interp); |
| 25 |
} |
| 26 |
|
| 27 |
void evaluateAddress(Interpreter& interp) { |
| 28 |
try { |
| 29 |
address = parseAddress(interp); |
| 30 |
} catch (MSXException&) { |
| 31 |
address = {}; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
[[nodiscard]] std::string parseAddressError(Interpreter& interp) const { |
| 36 |
try { |
| 37 |
parseAddress(interp); |
| 38 |
return {}; |
| 39 |
} catch (MSXException& e) { |
| 40 |
return e.getMessage(); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
private: |
| 45 |
uint16_t parseAddress(Interpreter& interp) const { |
| 46 |
auto tmp = addrStr.eval(interp).getInt(interp); |
| 47 |
if ((tmp < 0) || (tmp > 0xffff)) { |
| 48 |
throw CommandException("address outside of range 0...0xffff"); |
| 49 |
} |
| 50 |
return uint16_t(tmp); |
| 51 |
} |
| 52 |
|
| 53 |
TclObject addrStr; |
| 54 |
std::optional<uint16_t> address; |
| 55 |
}; |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
#endif |