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 "Debugger.hxx" |
19 | #include "CartDebug.hxx" |
20 | #include "CartWD.hxx" |
21 | #include "PopUpWidget.hxx" |
22 | #include "CartWDWidget.hxx" |
23 | |
24 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
25 | CartridgeWDWidget::CartridgeWDWidget( |
26 | GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont, |
27 | int x, int y, int w, int h, CartridgeWD& cart) |
28 | : CartDebugWidget(boss, lfont, nfont, x, y, w, h), |
29 | myCart(cart) |
30 | { |
31 | string info = |
32 | "This scheme has eight 1K slices, which can be mapped into four 1K " |
33 | "segments in various combinations. Each 'bank' selects a predefined " |
34 | "segment arrangement (indicated in square brackets)\n" |
35 | "In the third (uppermost) segment the byte at $3FC is overwritten with 0.\n\n" |
36 | "64 bytes RAM @ $F000 - $F080\n" |
37 | " $F000 - $F03F (R), $F040 - $F07F (W)\n" ; |
38 | |
39 | int xpos = 2, |
40 | ypos = addBaseInformation(myCart.mySize, "Wickstead Design" , info, 12) + myLineHeight; |
41 | |
42 | VariantList items; |
43 | VarList::push_back(items, "0 ($30) [0,0,1,3]" , 0); |
44 | VarList::push_back(items, "1 ($31) [0,1,2,3]" , 1); |
45 | VarList::push_back(items, "2 ($32) [4,5,6,7]" , 2); |
46 | VarList::push_back(items, "3 ($33) [7,4,2,3]" , 3); |
47 | VarList::push_back(items, "4 ($34) [0,0,6,7]" , 4); |
48 | VarList::push_back(items, "5 ($35) [0,1,7,6]" , 5); |
49 | VarList::push_back(items, "6 ($36) [2,3,4,5]" , 6); |
50 | VarList::push_back(items, "7 ($37) [6,0,5,1]" , 7); |
51 | VarList::push_back(items, "8 ($38) [0,0,1,3]" , 8); |
52 | VarList::push_back(items, "9 ($39) [0,1,2,3]" , 9); |
53 | VarList::push_back(items, "10 ($3A) [4,5,6,7]" , 10); |
54 | VarList::push_back(items, "11 ($3B) [7,4,2,3]" , 11); |
55 | VarList::push_back(items, "12 ($3C) [0,0,6,7]" , 12); |
56 | VarList::push_back(items, "13 ($3D) [0,1,7,6]" , 13); |
57 | VarList::push_back(items, "14 ($3E) [2,3,4,5]" , 14); |
58 | VarList::push_back(items, "15 ($3F) [6,0,5,1]" , 15); |
59 | myBank = new PopUpWidget(boss, _font, xpos, ypos-2, |
60 | _font.getStringWidth("15 ($3F) [6,0,5,1]" ), |
61 | myLineHeight, items, "Set bank " , |
62 | 0, kBankChanged); |
63 | myBank->setTarget(this); |
64 | addFocusWidget(myBank); |
65 | } |
66 | |
67 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
68 | void CartridgeWDWidget::saveOldState() |
69 | { |
70 | myOldState.internalram.clear(); |
71 | |
72 | for(uInt32 i = 0; i < internalRamSize(); ++i) |
73 | myOldState.internalram.push_back(myCart.myRAM[i]); |
74 | |
75 | myOldState.bank = myCart.getBank(); |
76 | } |
77 | |
78 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
79 | void CartridgeWDWidget::loadConfig() |
80 | { |
81 | myBank->setSelectedIndex(myCart.getBank(), myCart.getBank() != myOldState.bank); |
82 | |
83 | CartDebugWidget::loadConfig(); |
84 | } |
85 | |
86 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
87 | void CartridgeWDWidget::handleCommand(CommandSender* sender, |
88 | int cmd, int data, int id) |
89 | { |
90 | if(cmd == kBankChanged) |
91 | { |
92 | myCart.unlockBank(); |
93 | myCart.bank(myBank->getSelected()); |
94 | myCart.lockBank(); |
95 | invalidate(); |
96 | } |
97 | } |
98 | |
99 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
100 | string CartridgeWDWidget::bankState() |
101 | { |
102 | ostringstream& buf = buffer(); |
103 | |
104 | static const char* const segments[] = { |
105 | "[0,0,1,3]" , "[0,1,2,3]" , "[4,5,6,7]" , "[7,4,2,3]" , |
106 | "[0,0,6,7]" , "[0,1,7,6]" , "[2,3,4,5]" , "[6,0,5,1]" |
107 | }; |
108 | uInt16 bank = myCart.getBank(); |
109 | buf << "Bank = " << std::dec << bank << ", segments = " << segments[bank & 0x7]; |
110 | |
111 | return buf.str(); |
112 | } |
113 | |
114 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
115 | uInt32 CartridgeWDWidget::internalRamSize() |
116 | { |
117 | return 64; |
118 | } |
119 | |
120 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
121 | uInt32 CartridgeWDWidget::internalRamRPort(int start) |
122 | { |
123 | return 0xF000 + start; |
124 | } |
125 | |
126 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
127 | string CartridgeWDWidget::internalRamDescription() |
128 | { |
129 | ostringstream desc; |
130 | desc << "$F000 - $F03F used for Read Access\n" |
131 | << "$F040 - $F07F used for Write Access" ; |
132 | |
133 | return desc.str(); |
134 | } |
135 | |
136 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
137 | const ByteArray& CartridgeWDWidget::internalRamOld(int start, int count) |
138 | { |
139 | myRamOld.clear(); |
140 | for(int i = 0; i < count; ++i) |
141 | myRamOld.push_back(myOldState.internalram[start + i]); |
142 | return myRamOld; |
143 | } |
144 | |
145 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
146 | const ByteArray& CartridgeWDWidget::internalRamCurrent(int start, int count) |
147 | { |
148 | myRamCurrent.clear(); |
149 | for(int i = 0; i < count; ++i) |
150 | myRamCurrent.push_back(myCart.myRAM[start + i]); |
151 | return myRamCurrent; |
152 | } |
153 | |
154 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
155 | void CartridgeWDWidget::internalRamSetValue(int addr, uInt8 value) |
156 | { |
157 | myCart.myRAM[addr] = value; |
158 | } |
159 | |
160 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
161 | uInt8 CartridgeWDWidget::internalRamGetValue(int addr) |
162 | { |
163 | return myCart.myRAM[addr]; |
164 | } |
165 | |
166 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
167 | string CartridgeWDWidget::internalRamLabel(int addr) |
168 | { |
169 | CartDebug& dbg = instance().debugger().cartDebug(); |
170 | return dbg.getLabel(addr + 0xF000, false); |
171 | } |
172 | |