| 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 "Base.hxx" |
| 19 | #include "MT24LC256.hxx" |
| 20 | #include "FlashWidget.hxx" |
| 21 | |
| 22 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 23 | FlashWidget::FlashWidget(GuiObject* boss, const GUI::Font& font, |
| 24 | int x, int y, Controller& controller) |
| 25 | : ControllerWidget(boss, font, x, y, controller), |
| 26 | myEEPROMEraseCurrent(nullptr) |
| 27 | { |
| 28 | std::fill(myPage, myPage + MAX_PAGES, nullptr); |
| 29 | } |
| 30 | |
| 31 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 32 | void FlashWidget::init(GuiObject* boss, const GUI::Font& font, int x, int y) |
| 33 | { |
| 34 | const GUI::Font& ifont = instance().frameBuffer().infoFont(); |
| 35 | const int lineHeight = font.getLineHeight(); |
| 36 | int xpos = x, ypos = y; |
| 37 | |
| 38 | new StaticTextWidget(boss, font, xpos, ypos + 2, getHeader()); |
| 39 | |
| 40 | ypos += lineHeight + 6; |
| 41 | |
| 42 | new StaticTextWidget(boss, ifont, xpos, ypos, "Pages/Ranges used:" ); |
| 43 | |
| 44 | ypos += lineHeight + 2; |
| 45 | xpos += 8; |
| 46 | |
| 47 | for(uInt32 page = 0; page < MAX_PAGES; ++page) |
| 48 | { |
| 49 | myPage[page] = new StaticTextWidget(boss, ifont, xpos, ypos, |
| 50 | page ? " " : "none " ); |
| 51 | ypos += lineHeight; |
| 52 | } |
| 53 | |
| 54 | xpos -= 8; ypos += 2; |
| 55 | myEEPROMEraseCurrent = new ButtonWidget(boss, font, xpos, ypos, |
| 56 | "Erase used pages" , kEEPROMEraseCurrent); |
| 57 | myEEPROMEraseCurrent->setTarget(this); |
| 58 | } |
| 59 | |
| 60 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 61 | void FlashWidget::handleCommand(CommandSender*, int cmd, int, int) |
| 62 | { |
| 63 | if(cmd == kEEPROMEraseCurrent) { |
| 64 | eraseCurrent(); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 69 | // display the pages used by the current ROM and update erase button status |
| 70 | void FlashWidget::loadConfig() |
| 71 | { |
| 72 | int useCount = 0, startPage = -1; |
| 73 | for(uInt32 page = 0; page < MT24LC256::PAGE_NUM; ++page) |
| 74 | { |
| 75 | if(isPageUsed(page)) |
| 76 | { |
| 77 | if (startPage == -1) |
| 78 | startPage = page; |
| 79 | } |
| 80 | else |
| 81 | { |
| 82 | if(startPage != -1) |
| 83 | { |
| 84 | int from = startPage * MT24LC256::PAGE_SIZE; |
| 85 | int to = page * MT24LC256::PAGE_SIZE - 1; |
| 86 | ostringstream label; |
| 87 | |
| 88 | label.str("" ); |
| 89 | label << Common::Base::HEX3 << startPage; |
| 90 | |
| 91 | if(int(page) - 1 != startPage) |
| 92 | label << "-" << Common::Base::HEX3 << page - 1; |
| 93 | else |
| 94 | label << " " ; |
| 95 | label << ": " << Common::Base::HEX4 << from << "-" << Common::Base::HEX4 << to; |
| 96 | |
| 97 | myPage[useCount]->setLabel(label.str()); |
| 98 | |
| 99 | startPage = -1; |
| 100 | if(++useCount == MAX_PAGES) |
| 101 | break; |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | myEEPROMEraseCurrent->setEnabled(useCount != 0); |
| 107 | } |
| 108 | |