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 "CartFA.hxx" |
21 | #include "PopUpWidget.hxx" |
22 | #include "CartFAWidget.hxx" |
23 | |
24 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
25 | CartridgeFAWidget::CartridgeFAWidget( |
26 | GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont, |
27 | int x, int y, int w, int h, CartridgeFA& cart) |
28 | : CartDebugWidget(boss, lfont, nfont, x, y, w, h), |
29 | myCart(cart) |
30 | { |
31 | uInt16 size = 3 * 4096; |
32 | |
33 | ostringstream info; |
34 | info << "CBS RAM+ FA cartridge, three 4K banks\n" |
35 | << "256 bytes RAM @ $F000 - $F1FF\n" |
36 | << " $F100 - $F1FF (R), $F000 - $F0FF (W)\n" |
37 | << "Startup bank = " << cart.startBank() << " or undetermined\n" ; |
38 | |
39 | // Eventually, we should query this from the debugger/disassembler |
40 | for(uInt32 i = 0, offset = 0xFFC, spot = 0xFF8; i < 3; ++i, offset += 0x1000) |
41 | { |
42 | uInt16 start = (cart.myImage[offset+1] << 8) | cart.myImage[offset]; |
43 | start -= start % 0x1000; |
44 | info << "Bank " << i << " @ $" << Common::Base::HEX4 << (start + 0x200) << " - " |
45 | << "$" << (start + 0xFFF) << " (hotspot = $F" << (spot+i) << ")\n" ; |
46 | } |
47 | |
48 | int xpos = 2, |
49 | ypos = addBaseInformation(size, "CBS" , info.str()) + myLineHeight; |
50 | |
51 | VariantList items; |
52 | VarList::push_back(items, "0 ($FFF8)" ); |
53 | VarList::push_back(items, "1 ($FFF9)" ); |
54 | VarList::push_back(items, "2 ($FFFA)" ); |
55 | myBank = |
56 | new PopUpWidget(boss, _font, xpos, ypos-2, _font.getStringWidth("0 ($FFFx)" ), |
57 | myLineHeight, items, "Set bank " , |
58 | 0, kBankChanged); |
59 | myBank->setTarget(this); |
60 | addFocusWidget(myBank); |
61 | } |
62 | |
63 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
64 | void CartridgeFAWidget::saveOldState() |
65 | { |
66 | myOldState.internalram.clear(); |
67 | |
68 | for(uInt32 i = 0; i < internalRamSize(); ++i) |
69 | myOldState.internalram.push_back(myCart.myRAM[i]); |
70 | |
71 | myOldState.bank = myCart.getBank(); |
72 | } |
73 | |
74 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
75 | void CartridgeFAWidget::loadConfig() |
76 | { |
77 | myBank->setSelectedIndex(myCart.getBank(), myCart.getBank() != myOldState.bank); |
78 | |
79 | CartDebugWidget::loadConfig(); |
80 | } |
81 | |
82 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
83 | void CartridgeFAWidget::handleCommand(CommandSender* sender, |
84 | int cmd, int data, int id) |
85 | { |
86 | if(cmd == kBankChanged) |
87 | { |
88 | myCart.unlockBank(); |
89 | myCart.bank(myBank->getSelected()); |
90 | myCart.lockBank(); |
91 | invalidate(); |
92 | } |
93 | } |
94 | |
95 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
96 | string CartridgeFAWidget::bankState() |
97 | { |
98 | ostringstream& buf = buffer(); |
99 | |
100 | static const char* const spot[] = { "$FFF8" , "$FFF9" , "$FFFA" }; |
101 | buf << "Bank = " << std::dec << myCart.getBank() |
102 | << ", hotspot = " << spot[myCart.getBank()]; |
103 | |
104 | return buf.str(); |
105 | } |
106 | |
107 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
108 | uInt32 CartridgeFAWidget::internalRamSize() |
109 | { |
110 | return 256; |
111 | } |
112 | |
113 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
114 | uInt32 CartridgeFAWidget::internalRamRPort(int start) |
115 | { |
116 | return 0xF100 + start; |
117 | } |
118 | |
119 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
120 | string CartridgeFAWidget::internalRamDescription() |
121 | { |
122 | ostringstream desc; |
123 | desc << "$F000 - $F0FF used for Write Access\n" |
124 | << "$F100 - $F1FF used for Read Access" ; |
125 | |
126 | return desc.str(); |
127 | } |
128 | |
129 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
130 | const ByteArray& CartridgeFAWidget::internalRamOld(int start, int count) |
131 | { |
132 | myRamOld.clear(); |
133 | for(int i = 0; i < count; i++) |
134 | myRamOld.push_back(myOldState.internalram[start + i]); |
135 | return myRamOld; |
136 | } |
137 | |
138 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
139 | const ByteArray& CartridgeFAWidget::internalRamCurrent(int start, int count) |
140 | { |
141 | myRamCurrent.clear(); |
142 | for(int i = 0; i < count; i++) |
143 | myRamCurrent.push_back(myCart.myRAM[start + i]); |
144 | return myRamCurrent; |
145 | } |
146 | |
147 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
148 | void CartridgeFAWidget::internalRamSetValue(int addr, uInt8 value) |
149 | { |
150 | myCart.myRAM[addr] = value; |
151 | } |
152 | |
153 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
154 | uInt8 CartridgeFAWidget::internalRamGetValue(int addr) |
155 | { |
156 | return myCart.myRAM[addr]; |
157 | } |
158 | |
159 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
160 | string CartridgeFAWidget::internalRamLabel(int addr) |
161 | { |
162 | CartDebug& dbg = instance().debugger().cartDebug(); |
163 | return dbg.getLabel(addr + 0xF100, false); |
164 | } |
165 | |