1 From de71f12eb59a41899a5c77d797e144e6f0919777 Mon Sep 17 00:00:00 2001
2 From: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
3 Date: Mon, 17 Mar 2014 14:22:58 +0200
4 Subject: [PATCH 17/19] Fix performance problem with non-bus breakpoints
7 snes/memory/memory.cpp | 35 ++++++++++++++++++++++++++---------
8 snes/memory/memory.hpp | 1 +
10 3 files changed, 28 insertions(+), 9 deletions(-)
12 diff --git a/snes/memory/memory.cpp b/snes/memory/memory.cpp
13 index a9a484a..d22e313 100755
14 --- a/snes/memory/memory.cpp
15 +++ b/snes/memory/memory.cpp
16 @@ -43,6 +43,7 @@ void Bus::map(
19 for(unsigned bank = bank_lo; bank <= bank_hi; bank++) {
20 + region_start.insert((bank << 16) | addr_lo);
21 for(unsigned addr = addr_lo; addr <= addr_hi; addr++) {
22 unsigned destaddr = (bank << 16) | addr;
23 if(mode == MapMode::Linear) destaddr = mirror(base + offset++, length);
24 @@ -60,6 +61,7 @@ void Bus::map_reset() {
27 map(MapMode::Direct, 0x00, 0xff, 0x0000, 0xffff, 0xFF, reader, writer);
28 + region_start.clear();
32 @@ -70,11 +72,21 @@ void Bus::map_xml() {
34 unsigned Bus::enumerateMirrors(uint8 clazz, uint32 offset, unsigned start)
37 - for(i = start; i < 0x1000000; i++)
38 - if((classmap[i] == clazz && target[i] == offset) || (i == offset && clazz == 255))
47 + //Given region can not contain the same address twice.
48 + for(std::set<uint32>::iterator i = region_start.lower_bound(start); i != region_start.end(); i++) {
49 + if(classmap[*i] != clazz) continue;
50 + if(target[*i] > offset) continue;
51 + uint32 wouldbe = offset - target[*i] + *i;
52 + if(wouldbe > 0xFFFFFF) continue;
53 + if(classmap[wouldbe] == clazz && target[wouldbe] == offset) return wouldbe;
58 void Bus::clearDebugFlags()
59 @@ -94,10 +106,15 @@ void Bus::debugFlags(uint8 setf, uint8 clrf, uint8 clazz, uint32 offset)
62 debugflags[offset] = (debugflags[offset] | setf) & ~clrf;
64 - for(unsigned i = 0; i < 0x1000000; i++)
65 - if(classmap[i] == clazz && target[i] == offset)
66 - debugflags[i] = (debugflags[i] | setf) & ~clrf;
70 + i = enumerateMirrors(clazz, offset, i);
71 + if(i >= 0x1000000) break;
72 + debugflags[i] = (debugflags[i] | setf) & ~clrf;
79 diff --git a/snes/memory/memory.hpp b/snes/memory/memory.hpp
80 index c20e14d..ee0c0a9 100755
81 --- a/snes/memory/memory.hpp
82 +++ b/snes/memory/memory.hpp
83 @@ -52,6 +52,7 @@ struct Bus {
87 + std::set<uint32> region_start;
90 function<uint8 (unsigned)> reader[256];
91 diff --git a/snes/snes.hpp b/snes/snes.hpp
92 index 4e3ba64..9589db9 100755
95 @@ -38,6 +38,7 @@ namespace SNES {
96 #include <nall/varint.hpp>
97 #include <nall/vector.hpp>
98 #include <nall/gameboy/cartridge.hpp>
100 using namespace nall;
102 #include <gameboy/gameboy.hpp>