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