-
Notifications
You must be signed in to change notification settings - Fork 20
/
win_cart_ram.go
186 lines (152 loc) · 5.12 KB
/
win_cart_ram.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// This file is part of Gopher2600.
//
// Gopher2600 is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Gopher2600 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Gopher2600. If not, see <https://www.gnu.org/licenses/>.
package sdlimgui
import (
"fmt"
"github.com/inkyblackness/imgui-go/v4"
"github.com/jetsetilly/gopher2600/gui/fonts"
"github.com/jetsetilly/gopher2600/hardware/memory/memorymap"
)
const winCartRAMID = "Cartridge RAM"
type winCartRAM struct {
debuggerWin
img *SdlImgui
// height of status line at bottom of frame. valid after first frame of a
// tab (although it should be same for each tab)
statusHeight float32
// required dimensions of mapped/unmapped indicator
mappedIndicatorDim imgui.Vec2
}
func newWinCartRAM(img *SdlImgui) (window, error) {
win := &winCartRAM{img: img}
return win, nil
}
func (win *winCartRAM) init() {
win.mappedIndicatorDim = imguiGetFrameDim(" mapped ", " unmapped ")
}
func (win *winCartRAM) id() string {
return winCartRAMID
}
func (win *winCartRAM) debuggerDraw() bool {
if !win.debuggerOpen {
return false
}
if !win.img.lz.Cart.HasRAMbus {
return false
}
imgui.SetNextWindowPosV(imgui.Vec2{533, 430}, imgui.ConditionFirstUseEver, imgui.Vec2{0, 0})
imgui.SetNextWindowSizeV(imgui.Vec2{478, 271}, imgui.ConditionFirstUseEver)
imgui.SetNextWindowSizeConstraints(imgui.Vec2{478, 271}, imgui.Vec2{529, 1000})
title := fmt.Sprintf("%s %s", win.img.lz.Cart.ID, win.id())
if imgui.BeginV(win.debuggerID(title), &win.debuggerOpen, imgui.WindowFlagsNone) {
win.draw()
}
win.debuggerGeom.update()
imgui.End()
return true
}
func (win *winCartRAM) draw() {
// get comparison data. assuming that there is such a thing and that it's
// safe to get StaticData from.
comp := win.img.lz.Rewind.Comparison.State.Mem.Cart.GetRAMbus().GetRAM()
imgui.BeginTabBarV("", imgui.TabBarFlagsFittingPolicyScroll)
for bank := range win.img.lz.Cart.RAM {
current := win.img.lz.Cart.RAM[bank]
diff := comp[bank]
if imgui.BeginTabItem(current.Label) {
imgui.BeginChildV("cartram", imgui.Vec2{X: 0, Y: imguiRemainingWinHeight() - win.statusHeight}, false, 0)
// show cartridge origin for mapped RAM banks
origin := current.Origin
if win.img.dbg.Disasm.Prefs.FxxxMirror.Get().(bool) {
origin = (origin & memorymap.CartridgeBits) | memorymap.OriginCartFxxxMirror
}
// pos is retreived in before() and used in after()
var pos imgui.Vec2
// number of colors to pop in afer()
popColor := 0
before := func(idx int) {
pos = imgui.CursorScreenPos()
a := diff.Data[idx]
b := current.Data[idx]
if a != b {
imgui.PushStyleColor(imgui.StyleColorFrameBg, win.img.cols.ValueDiff)
popColor++
}
}
after := func(idx int) {
imgui.PopStyleColorV(popColor)
popColor = 0
dl := imgui.WindowDrawList()
// idx is based on original values of type uint16 so the type conversion is safe
addr := memorymap.OriginCart + uint16(idx)
read, okr := win.img.dbg.Disasm.Sym.GetSymbol(addr, true)
write, okw := win.img.dbg.Disasm.Sym.GetSymbol(addr, false)
if okr || okw {
sz := imgui.FontSize() * 0.4
pos.X += 1.0
pos.Y += 1.0
p1 := pos
p1.Y += sz
p2 := pos
p2.X += sz
dl.AddTriangleFilled(pos, p1, p2, imgui.PackedColorFromVec4(win.img.cols.ValueSymbol))
}
if okr && okw && read.Symbol == write.Symbol {
win.img.imguiTooltip(func() {
imguiColorLabelSimple(read.Symbol, win.img.cols.ValueSymbol)
}, true)
} else {
if okr {
win.img.imguiTooltip(func() {
imguiColorLabelSimple(read.Symbol, win.img.cols.ValueSymbol)
}, true)
}
if okw {
win.img.imguiTooltip(func() {
imguiColorLabelSimple(write.Symbol, win.img.cols.ValueSymbol)
}, true)
}
}
a := diff.Data[idx]
b := current.Data[idx]
if a != b {
win.img.imguiTooltip(func() {
imguiColorLabelSimple(fmt.Sprintf("%02x %c %02x", a, fonts.ByteChange, b), win.img.cols.ValueDiff)
}, true)
}
}
commitBank := bank
commit := func(idx int, data uint8) {
win.img.dbg.PushFunction(func() {
win.img.vcs.Mem.Cart.GetRAMbus().PutRAM(commitBank, idx, data)
})
}
drawByteGrid("cartRamByteGrid", current.Data, uint32(origin), before, after, commit)
imgui.EndChild()
// status line
win.statusHeight = imguiMeasureHeight(func() {
imgui.PushStyleVarFloat(imgui.StyleVarFrameRounding, readOnlyButtonRounding)
if current.Mapped {
imguiColourButton(win.img.cols.True, " mapped ", win.mappedIndicatorDim)
} else {
imguiColourButton(win.img.cols.False, " unmapped ", win.mappedIndicatorDim)
}
imgui.PopStyleVar()
})
imgui.EndTabItem()
}
}
imgui.EndTabBar()
}