remove dynamic casting

This commit is contained in:
thrust26 2020-04-21 15:14:52 +02:00
parent 8e3e0479b1
commit 98d42cfd94
4 changed files with 17 additions and 12 deletions

View File

@ -22,7 +22,8 @@
CartridgeFA2Widget::CartridgeFA2Widget( CartridgeFA2Widget::CartridgeFA2Widget(
GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont, GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont,
int x, int y, int w, int h, CartridgeFA2& cart) int x, int y, int w, int h, CartridgeFA2& cart)
: CartridgeEnhancedWidget(boss, lfont, nfont, x, y, w, h, cart) : CartridgeEnhancedWidget(boss, lfont, nfont, x, y, w, h, cart),
myCartFA2(cart)
{ {
int xpos = 2, int xpos = 2,
ypos = initialize(); ypos = initialize();
@ -74,20 +75,18 @@ string CartridgeFA2Widget::description()
void CartridgeFA2Widget::handleCommand(CommandSender* sender, void CartridgeFA2Widget::handleCommand(CommandSender* sender,
int cmd, int data, int id) int cmd, int data, int id)
{ {
CartridgeFA2& cart = dynamic_cast<CartridgeFA2&>(myCart);
switch(cmd) switch(cmd)
{ {
case kFlashErase: case kFlashErase:
cart.flash(0); myCartFA2.flash(0);
break; break;
case kFlashLoad: case kFlashLoad:
cart.flash(1); myCartFA2.flash(1);
break; break;
case kFlashSave: case kFlashSave:
cart.flash(2); myCartFA2.flash(2);
break; break;
default: default:

View File

@ -33,9 +33,7 @@ class CartridgeFA2Widget : public CartridgeEnhancedWidget
virtual ~CartridgeFA2Widget() = default; virtual ~CartridgeFA2Widget() = default;
private: private:
string manufacturer() override { return "Chris D. Walton (Star Castle 2600 Arcade)"; } CartridgeFA2& myCartFA2;
string description() override;
ButtonWidget *myFlashErase{nullptr}, *myFlashLoad{nullptr}, *myFlashSave{nullptr}; ButtonWidget *myFlashErase{nullptr}, *myFlashLoad{nullptr}, *myFlashSave{nullptr};
@ -45,6 +43,11 @@ class CartridgeFA2Widget : public CartridgeEnhancedWidget
kFlashSave = 'flSV' kFlashSave = 'flSV'
}; };
private:
string manufacturer() override { return "Chris D. Walton (Star Castle 2600 Arcade)"; }
string description() override;
private: private:
void handleCommand(CommandSender* sender, int cmd, int data, int id) override; void handleCommand(CommandSender* sender, int cmd, int data, int id) override;

View File

@ -22,7 +22,8 @@
CartridgeWDWidget::CartridgeWDWidget( CartridgeWDWidget::CartridgeWDWidget(
GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont, GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont,
int x, int y, int w, int h, CartridgeWD& cart) int x, int y, int w, int h, CartridgeWD& cart)
: CartridgeEnhancedWidget(boss, lfont, nfont, x, y, w, h, cart) : CartridgeEnhancedWidget(boss, lfont, nfont, x, y, w, h, cart),
myCartWD(cart)
{ {
initialize(); initialize();
} }
@ -45,8 +46,7 @@ string CartridgeWDWidget::description()
string CartridgeWDWidget::hotspotStr(int bank, int segment, bool prefix) string CartridgeWDWidget::hotspotStr(int bank, int segment, bool prefix)
{ {
ostringstream info; ostringstream info;
CartridgeWD& cart = dynamic_cast<CartridgeWD&>(myCart); CartridgeWD::BankOrg banks = myCartWD.ourBankOrg[bank];
CartridgeWD::BankOrg banks = cart.ourBankOrg[bank];
info << "(" << (prefix ? "hotspot " : "") info << "(" << (prefix ? "hotspot " : "")
<< "$" << Common::Base::HEX1 << (myCart.hotspot() + bank) << ") [" << "$" << Common::Base::HEX1 << (myCart.hotspot() + bank) << ") ["

View File

@ -31,6 +31,9 @@ class CartridgeWDWidget : public CartridgeEnhancedWidget
CartridgeWD& cart); CartridgeWD& cart);
virtual ~CartridgeWDWidget() = default; virtual ~CartridgeWDWidget() = default;
private:
CartridgeWD& myCartWD;
private: private:
string manufacturer() override { return "Wickstead Design"; } string manufacturer() override { return "Wickstead Design"; }