Bus fixes: Reading of CPU MMIO registers does not update MDR
[lsnes.git] / bsnes-patches / v085 / 0017-Fix-performance-problem-with-non-bus-breakpoints.patch
blob9505165793d03595ba9a8f7cebc2ac5d94ad834d
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/27] Fix performance problem with non-bus breakpoints
6 ---
7 snes/memory/memory.cpp | 35 ++++++++++++++++++++++++++---------
8 snes/memory/memory.hpp | 1 +
9 snes/snes.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 a9a484a0..d22e3137 100755
14 --- a/snes/memory/memory.cpp
15 +++ b/snes/memory/memory.cpp
16 @@ -43,6 +43,7 @@ void Bus::map(
18 unsigned offset = 0;
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() {
26 idcount = 0;
27 map(MapMode::Direct, 0x00, 0xff, 0x0000, 0xffff, 0xFF, reader, writer);
28 + region_start.clear();
31 void Bus::map_xml() {
32 @@ -70,11 +72,21 @@ void Bus::map_xml() {
34 unsigned Bus::enumerateMirrors(uint8 clazz, uint32 offset, unsigned start)
36 - unsigned i;
37 - for(i = start; i < 0x1000000; i++)
38 - if((classmap[i] == clazz && target[i] == offset) || (i == offset && clazz == 255))
39 - return i;
40 - return i;
41 + if(clazz == 255) {
42 + if(start > offset)
43 + return 0x1000000;
44 + else
45 + return start;
46 + }
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;
54 + }
55 + return 0x1000000;
58 void Bus::clearDebugFlags()
59 @@ -94,10 +106,15 @@ void Bus::debugFlags(uint8 setf, uint8 clrf, uint8 clazz, uint32 offset)
60 setf <<= 3;
61 clrf <<= 3;
62 debugflags[offset] = (debugflags[offset] | setf) & ~clrf;
63 - } else
64 - for(unsigned i = 0; i < 0x1000000; i++)
65 - if(classmap[i] == clazz && target[i] == offset)
66 - debugflags[i] = (debugflags[i] | setf) & ~clrf;
67 + } else {
68 + uint32 i = 0;
69 + while(true) {
70 + i = enumerateMirrors(clazz, offset, i);
71 + if(i >= 0x1000000) break;
72 + debugflags[i] = (debugflags[i] | setf) & ~clrf;
73 + i++;
74 + }
75 + }
78 Bus::Bus() {
79 diff --git a/snes/memory/memory.hpp b/snes/memory/memory.hpp
80 index c20e14db..ee0c0a9e 100755
81 --- a/snes/memory/memory.hpp
82 +++ b/snes/memory/memory.hpp
83 @@ -52,6 +52,7 @@ struct Bus {
84 uint8 *debugflags;
85 uint8 u_debugflags;
86 uint32 *target;
87 + std::set<uint32> region_start;
89 unsigned idcount;
90 function<uint8 (unsigned)> reader[256];
91 diff --git a/snes/snes.hpp b/snes/snes.hpp
92 index 4e3ba64c..9589db9b 100755
93 --- a/snes/snes.hpp
94 +++ b/snes/snes.hpp
95 @@ -38,6 +38,7 @@ namespace SNES {
96 #include <nall/varint.hpp>
97 #include <nall/vector.hpp>
98 #include <nall/gameboy/cartridge.hpp>
99 +#include <set>
100 using namespace nall;
102 #include <gameboy/gameboy.hpp>
104 2.15.0.rc1