This commit is contained in:
thrust26 2020-05-26 15:30:32 +02:00
parent d11f9c383a
commit 3728fb40b1
2 changed files with 51 additions and 48 deletions

View File

@ -39,7 +39,7 @@ string Cartridge3EPlusWidget::description()
uInt16 numRomBanks = myCart.romBankCount(); uInt16 numRomBanks = myCart.romBankCount();
uInt16 numRamBanks = myCart.ramBankCount(); uInt16 numRamBanks = myCart.ramBankCount();
info << "3E+ cartridge - (4..64K ROM + RAM)\n" info << "3E+ cartridge - (4" << ELLIPSIS << "64K ROM + RAM)\n"
<< " " << numRomBanks << " 1K ROM banks + " << numRamBanks << " 512b RAM banks\n" << " " << numRomBanks << " 1K ROM banks + " << numRamBanks << " 512b RAM banks\n"
<< " mapped into four segments\n" << " mapped into four segments\n"
"ROM bank & segment selected by writing to $3F\n" "ROM bank & segment selected by writing to $3F\n"
@ -61,6 +61,7 @@ void Cartridge3EPlusWidget::bankSelect(int& ypos)
{ {
size_t size; size_t size;
const uInt8* image = myCart.getImage(size); const uInt8* image = myCart.getImage(size);
const int VGAP = myFontHeight / 4;
VariantList banktype; VariantList banktype;
VarList::push_back(banktype, "ROM", "ROM"); VarList::push_back(banktype, "ROM", "ROM");
@ -68,6 +69,8 @@ void Cartridge3EPlusWidget::bankSelect(int& ypos)
myBankWidgets = make_unique<PopUpWidget* []>(bankSegs()); myBankWidgets = make_unique<PopUpWidget* []>(bankSegs());
ypos -= VGAP * 2;
for(uInt32 seg = 0; seg < bankSegs(); ++seg) for(uInt32 seg = 0; seg < bankSegs(); ++seg)
{ {
int xpos = 2, xpos_s, ypos_s = ypos + 1, width; int xpos = 2, xpos_s, ypos_s = ypos + 1, width;
@ -77,20 +80,25 @@ void Cartridge3EPlusWidget::bankSelect(int& ypos)
label << "Set segment " << seg << " as "; label << "Set segment " << seg << " as ";
new StaticTextWidget(_boss, _font, xpos, ypos, label.str()); new StaticTextWidget(_boss, _font, xpos, ypos, label.str());
ypos += myLineHeight + 8; ypos += myLineHeight + VGAP * 2;
xpos += _font.getMaxCharWidth() * 2; xpos += _font.getMaxCharWidth() * 2;
CartridgeEnhancedWidget::bankList(myCart.romBankCount(), seg, items, width); CartridgeEnhancedWidget::bankList(std::max(myCart.romBankCount(), myCart.ramBankCount()),
seg, items, width);
myBankWidgets[seg] = myBankWidgets[seg] =
new PopUpWidget(_boss, _font, xpos, ypos - 2, width, new PopUpWidget(_boss, _font, xpos, ypos - 2, width,
myLineHeight, items, "Bank "); myLineHeight, items, "Bank ", 0, kBankChanged);
myBankWidgets[seg]->setID(seg);
myBankWidgets[seg]->setTarget(this);
addFocusWidget(myBankWidgets[seg]); addFocusWidget(myBankWidgets[seg]);
xpos += myBankWidgets[seg]->getWidth(); xpos += myBankWidgets[seg]->getWidth();
myBankType[seg] = myBankType[seg] =
new PopUpWidget(_boss, _font, xpos, ypos - 2, 3 * _font.getMaxCharWidth(), new PopUpWidget(_boss, _font, xpos, ypos - 2, 3 * _font.getMaxCharWidth(),
myLineHeight, banktype, " of "); myLineHeight, banktype, " of ", 0, kRomRamChanged);
myBankType[seg]->setID(seg);
myBankType[seg]->setTarget(this);
addFocusWidget(myBankType[seg]); addFocusWidget(myBankType[seg]);
xpos = myBankType[seg]->getRight() + _font.getMaxCharWidth(); xpos = myBankType[seg]->getRight() + _font.getMaxCharWidth();
@ -98,7 +106,8 @@ void Cartridge3EPlusWidget::bankSelect(int& ypos)
// add "Commit" button (why required?) // add "Commit" button (why required?)
myBankCommit[seg] = new ButtonWidget(_boss, _font, xpos, ypos - 4, myBankCommit[seg] = new ButtonWidget(_boss, _font, xpos, ypos - 4,
_font.getStringWidth(" Commit "), myButtonHeight, _font.getStringWidth(" Commit "), myButtonHeight,
"Commit", bankEnum[seg]); "Commit", kChangeBank);
myBankCommit[seg]->setID(seg);
myBankCommit[seg]->setTarget(this); myBankCommit[seg]->setTarget(this);
addFocusWidget(myBankCommit[seg]); addFocusWidget(myBankCommit[seg]);
@ -117,7 +126,7 @@ void Cartridge3EPlusWidget::bankSelect(int& ypos)
myBankState[2 * seg] = new EditTextWidget(_boss, _font, xoffset, ypos_s, myBankState[2 * seg] = new EditTextWidget(_boss, _font, xoffset, ypos_s,
_w - xoffset - 10, myLineHeight, ""); _w - xoffset - 10, myLineHeight, "");
myBankState[2 * seg]->setEditable(false, true); myBankState[2 * seg]->setEditable(false, true);
ypos_s += myLineHeight + 4; ypos_s += myLineHeight + VGAP;
label.str(""); label.str("");
label << "$" << Common::Base::HEX4 << addr2 << "-$" << Common::Base::HEX4 << (addr2 + 0x1FF); label << "$" << Common::Base::HEX4 << addr2 << "-$" << Common::Base::HEX4 << (addr2 + 0x1FF);
@ -127,7 +136,7 @@ void Cartridge3EPlusWidget::bankSelect(int& ypos)
_w - xoffset - 10, myLineHeight, ""); _w - xoffset - 10, myLineHeight, "");
myBankState[2 * seg + 1]->setEditable(false, true); myBankState[2 * seg + 1]->setEditable(false, true);
ypos += 2 * myLineHeight; ypos += myLineHeight + VGAP * 4;
} }
} }
@ -142,42 +151,44 @@ void Cartridge3EPlusWidget::loadConfig()
void Cartridge3EPlusWidget::handleCommand(CommandSender* sender, void Cartridge3EPlusWidget::handleCommand(CommandSender* sender,
int cmd, int data, int id) int cmd, int data, int id)
{ {
uInt16 segment = 0; const uInt16 segment = id;
switch(cmd) switch(cmd)
{ {
case kBank0Changed: case kBankChanged:
segment = 0; case kRomRamChanged:
{
const bool isROM = myBankType[segment]->getSelectedTag() == "ROM";
int bank = myBankWidgets[segment]->getSelected();
myBankCommit[segment]->setEnabled((isROM && bank < myCart.romBankCount())
|| (!isROM && bank < myCart.ramBankCount()));
break; break;
case kBank1Changed: }
segment = 1; case kChangeBank:
break; {
case kBank2Changed: // Ignore bank if either number or type hasn't been selected
segment = 2; if(myBankWidgets[segment]->getSelected() < 0 ||
break; myBankType[segment]->getSelected() < 0)
case kBank3Changed: return;
segment = 3;
uInt8 bank = myBankWidgets[segment]->getSelected();
myCart.unlockBank();
if(myBankType[segment]->getSelectedTag() == "ROM")
myCart.bank(bank, segment);
else
myCart.bank(bank + myCart.romBankCount(), segment);
myCart.lockBank();
invalidate();
updateUIState();
break; break;
}
default: default:
break; break;
} }
// Ignore bank if either number or type hasn't been selected
if(myBankWidgets[segment]->getSelected() < 0 ||
myBankType[segment]->getSelected() < 0)
return;
uInt8 bank = myBankWidgets[segment]->getSelected();
myCart.unlockBank();
if(myBankType[segment]->getSelectedTag() == "ROM")
myCart.bank(bank, segment);
else
myCart.bank(bank + myCart.romBankCount(), segment);
myCart.lockBank();
invalidate();
updateUIState();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -234,8 +245,3 @@ string Cartridge3EPlusWidget::internalRamDescription()
return desc.str(); return desc.str();
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const std::array<Cartridge3EPlusWidget::BankID, 4> Cartridge3EPlusWidget::bankEnum = {
kBank0Changed, kBank1Changed, kBank2Changed, kBank3Changed
};

View File

@ -56,13 +56,10 @@ class Cartridge3EPlusWidget : public CartridgeEnhancedWidget
std::array<ButtonWidget*, 4> myBankCommit{nullptr}; std::array<ButtonWidget*, 4> myBankCommit{nullptr};
std::array<EditTextWidget*, 8> myBankState{nullptr}; std::array<EditTextWidget*, 8> myBankState{nullptr};
enum BankID { enum {
kBank0Changed = 'b0CH', kRomRamChanged = 'rrCh',
kBank1Changed = 'b1CH', kChangeBank = 'chBk',
kBank2Changed = 'b2CH',
kBank3Changed = 'b3CH'
}; };
static const std::array<BankID, 4> bankEnum;
private: private:
// Following constructors and assignment operators not supported // Following constructors and assignment operators not supported