| 1 | //============================================================================ |
| 2 | // |
| 3 | // SSSS tt lll lll |
| 4 | // SS SS tt ll ll |
| 5 | // SS tttttt eeee ll ll aaaa |
| 6 | // SSSS tt ee ee ll ll aa |
| 7 | // SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" |
| 8 | // SS SS tt ee ll ll aa aa |
| 9 | // SSSS ttt eeeee llll llll aaaaa |
| 10 | // |
| 11 | // Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony |
| 12 | // and the Stella Team |
| 13 | // |
| 14 | // See the file "License.txt" for information on usage and redistribution of |
| 15 | // this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 16 | //============================================================================ |
| 17 | |
| 18 | #include <map> |
| 19 | #include "BreakpointMap.hxx" |
| 20 | |
| 21 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 22 | BreakpointMap::BreakpointMap(void) |
| 23 | : myInitialized(false) |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 28 | void BreakpointMap::add(const Breakpoint& breakpoint, const uInt32 flags) |
| 29 | { |
| 30 | Breakpoint bp = convertBreakpoint(breakpoint); |
| 31 | |
| 32 | myInitialized = true; |
| 33 | myMap[bp] = flags; |
| 34 | } |
| 35 | |
| 36 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 37 | void BreakpointMap::add(const uInt16 addr, const uInt8 bank, const uInt32 flags) |
| 38 | { |
| 39 | add(Breakpoint(addr, bank), flags); |
| 40 | } |
| 41 | |
| 42 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 43 | void BreakpointMap::erase(const Breakpoint& breakpoint) |
| 44 | { |
| 45 | // 16 bit breakpoint |
| 46 | if(!myMap.erase(breakpoint)) |
| 47 | { |
| 48 | // 13 bit breakpoint |
| 49 | Breakpoint bp13(breakpoint.addr & ADDRESS_MASK, breakpoint.bank); |
| 50 | |
| 51 | myMap.erase(bp13); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 56 | void BreakpointMap::erase(const uInt16 addr, const uInt8 bank) |
| 57 | { |
| 58 | erase(Breakpoint(addr, bank)); |
| 59 | } |
| 60 | |
| 61 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 62 | uInt32 BreakpointMap::get(const Breakpoint& breakpoint) const |
| 63 | { |
| 64 | // 16 bit breakpoint |
| 65 | auto find = myMap.find(breakpoint); |
| 66 | if(find != myMap.end()) |
| 67 | return find->second; |
| 68 | |
| 69 | // 13 bit breakpoint |
| 70 | Breakpoint bp13(breakpoint.addr & ADDRESS_MASK, breakpoint.bank); |
| 71 | |
| 72 | find = myMap.find(bp13); |
| 73 | if(find != myMap.end()) |
| 74 | return find->second; |
| 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 80 | uInt32 BreakpointMap::get(uInt16 addr, uInt8 bank) const |
| 81 | { |
| 82 | return get(Breakpoint(addr, bank)); |
| 83 | } |
| 84 | |
| 85 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 86 | bool BreakpointMap::check(const Breakpoint& breakpoint) const |
| 87 | { |
| 88 | // 16 bit breakpoint |
| 89 | auto find = myMap.find(breakpoint); |
| 90 | if(find != myMap.end()) |
| 91 | return true; |
| 92 | |
| 93 | // 13 bit breakpoint |
| 94 | Breakpoint bp13(breakpoint.addr & ADDRESS_MASK, breakpoint.bank); |
| 95 | |
| 96 | find = myMap.find(bp13); |
| 97 | return (find != myMap.end()); |
| 98 | } |
| 99 | |
| 100 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 101 | bool BreakpointMap::check(const uInt16 addr, const uInt8 bank) const |
| 102 | { |
| 103 | return check(Breakpoint(addr, bank)); |
| 104 | } |
| 105 | |
| 106 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 107 | BreakpointMap::BreakpointList BreakpointMap::getBreakpoints() const |
| 108 | { |
| 109 | BreakpointList map; |
| 110 | std::map<Breakpoint, uInt32> ordered(myMap.begin(), myMap.end()); |
| 111 | |
| 112 | for(auto item : ordered) |
| 113 | map.push_back(item.first); |
| 114 | |
| 115 | return map; |
| 116 | } |
| 117 | |
| 118 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 119 | BreakpointMap::Breakpoint BreakpointMap::convertBreakpoint(const Breakpoint& breakpoint) |
| 120 | { |
| 121 | if(breakpoint.bank == ANY_BANK) |
| 122 | return Breakpoint(breakpoint.addr, ANY_BANK); |
| 123 | else |
| 124 | return Breakpoint(breakpoint.addr & ADDRESS_MASK, breakpoint.bank); |
| 125 | } |
| 126 | |