|
| 1 | + |
| 2 | +#include <assert.h> |
| 3 | +#include <ion.h> |
| 4 | + |
| 5 | +#include <bootloader/interface.h> |
| 6 | +#include <bootloader/slot.h> |
| 7 | +#include <bootloader/boot.h> |
| 8 | + |
| 9 | +#include "computer.h" |
| 10 | +#include "cable.h" |
| 11 | + |
| 12 | +namespace Bootloader { |
| 13 | + |
| 14 | +void Interface::drawImage(KDContext* ctx, const Image* image, int offset) { |
| 15 | + const uint8_t* data; |
| 16 | + size_t size; |
| 17 | + size_t pixelBufferSize; |
| 18 | + |
| 19 | + if (image != nullptr) { |
| 20 | + data = image->compressedPixelData(); |
| 21 | + size = image->compressedPixelDataSize(); |
| 22 | + pixelBufferSize = image->width() * image->height(); |
| 23 | + } else { |
| 24 | + return; |
| 25 | + } |
| 26 | + |
| 27 | + KDColor pixelBuffer[4000]; |
| 28 | + assert(pixelBufferSize <= 4000); |
| 29 | + assert(Ion::stackSafe()); // That's a VERY big buffer we're allocating on the stack |
| 30 | + |
| 31 | + Ion::decompress( |
| 32 | + data, |
| 33 | + reinterpret_cast<uint8_t *>(pixelBuffer), |
| 34 | + size, |
| 35 | + pixelBufferSize * sizeof(KDColor) |
| 36 | + ); |
| 37 | + |
| 38 | + KDRect bounds((320 - image->width()) / 2, offset, image->width(), image->height()); |
| 39 | + |
| 40 | + ctx->fillRectWithPixels(bounds, pixelBuffer, nullptr); |
| 41 | +} |
| 42 | + |
| 43 | +void Interface::draw() { |
| 44 | + KDContext * ctx = KDIonContext::sharedContext(); |
| 45 | + ctx->fillRect(KDRect(0,0,320,240), KDColorBlack); |
| 46 | + drawImage(ctx, ImageStore::Computer, 70); |
| 47 | + drawImage(ctx, ImageStore::Cable, 172); |
| 48 | + |
| 49 | + ctx->drawString("Slot A:", KDPoint(0, 0), KDFont::SmallFont, KDColorWhite, KDColorBlack); |
| 50 | + ctx->drawString("Slot B:", KDPoint(0, 13), KDFont::SmallFont, KDColorWhite, KDColorBlack); |
| 51 | + ctx->drawString("Current:", KDPoint(0, 26), KDFont::SmallFont, KDColorWhite, KDColorBlack); |
| 52 | + |
| 53 | + if (Boot::mode() == BootMode::SlotA) { |
| 54 | + ctx->drawString("Slot A", KDPoint(63, 26), KDFont::SmallFont, KDColorWhite, KDColorBlack); |
| 55 | + } else if (Boot::mode() == BootMode::SlotB) { |
| 56 | + ctx->drawString("Slot B", KDPoint(63, 26), KDFont::SmallFont, KDColorWhite, KDColorBlack); |
| 57 | + } |
| 58 | + |
| 59 | + Slot slots[2] = {Slot::A(), Slot::B()}; |
| 60 | + |
| 61 | + for(uint8_t i = 0; i < 2; i++) { |
| 62 | + Slot slot = slots[i]; |
| 63 | + |
| 64 | + if (slot.kernelHeader()->isValid() && slot.userlandHeader()->isValid()) { |
| 65 | + if (slot.userlandHeader()->isOmega() && slot.userlandHeader()->isUpsilon()) { |
| 66 | + ctx->drawString("Upsilon", KDPoint(56, i*13), KDFont::SmallFont, KDColorWhite, KDColorBlack); |
| 67 | + ctx->drawString(slot.userlandHeader()->upsilonVersion(), KDPoint(112, i*13), KDFont::SmallFont, KDColorWhite, KDColorBlack); |
| 68 | + } else if (slot.userlandHeader()->isOmega()) { |
| 69 | + ctx->drawString("Omega", KDPoint(56, i*13), KDFont::SmallFont, KDColorWhite, KDColorBlack); |
| 70 | + ctx->drawString(slot.userlandHeader()->omegaVersion(), KDPoint(112, i*13), KDFont::SmallFont, KDColorWhite, KDColorBlack); |
| 71 | + } else { |
| 72 | + ctx->drawString("Epsilon", KDPoint(56, i*13), KDFont::SmallFont, KDColorWhite, KDColorBlack); |
| 73 | + ctx->drawString(slot.userlandHeader()->version(), KDPoint(112, i*13), KDFont::SmallFont, KDColorWhite, KDColorBlack); |
| 74 | + } |
| 75 | + ctx->drawString(slot.kernelHeader()->patchLevel(), KDPoint(168, i*13), KDFont::SmallFont, KDColorWhite, KDColorBlack); |
| 76 | + } else { |
| 77 | + ctx->drawString("Invalid", KDPoint(56, i*13), KDFont::SmallFont, KDColorWhite, KDColorBlack); |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | +} |
| 82 | + |
| 83 | +} |
0 commit comments