all repos — mgba @ b3f5e6b9eeee88dd8f1cd59d1c671ac8ee936ba0

mGBA Game Boy Advance Emulator

GBA e-Reader: Bitmap scanning
Vicki Pfau vi@endrift.com
Sun, 23 Feb 2020 17:59:03 -0800
commit

b3f5e6b9eeee88dd8f1cd59d1c671ac8ee936ba0

parent

709149458319ec6bdf1a95c615a3ce5a6bbe1cb0

3 files changed, 40 insertions(+), 5 deletions(-)

jump to
M src/gba/ereader.csrc/gba/ereader.c

@@ -323,13 +323,16 @@ void GBAHardwareEReaderScan(struct GBACartridgeHardware* hw, const void* data, size_t size) {

if (!hw->eReaderDots) { hw->eReaderDots = anonymousMemoryMap(EREADER_DOTCODE_SIZE); } + hw->eReaderX = -24; memset(hw->eReaderDots, 0, EREADER_DOTCODE_SIZE); uint8_t blockRS[44][0x10]; bool parsed = false; + bool bitmap = false; size_t blocks; int base; switch (size) { + // Raw sizes case 2112: parsed = true; // Fallthrough

@@ -344,11 +347,38 @@ case 1872:

base = 1; blocks = 18; break; + // Bitmap sizes + case 5456: + bitmap = true; + break; default: return; } size_t i; + if (bitmap) { + size_t x; + for (i = 0; i < 40; ++i) { + const uint8_t* line = &((const uint8_t*) data)[(i + 2) * 124]; + uint8_t* origin = &hw->eReaderDots[EREADER_DOTCODE_STRIDE * i + 200]; + for (x = 0; x < 124; ++x) { + uint8_t byte = line[x]; + if (x == 123) { + byte &= 0xE0; + } + origin[x * 8 + 0] = (byte >> 7) & 1; + origin[x * 8 + 1] = (byte >> 6) & 1; + origin[x * 8 + 2] = (byte >> 5) & 1; + origin[x * 8 + 3] = (byte >> 4) & 1; + origin[x * 8 + 4] = (byte >> 3) & 1; + origin[x * 8 + 5] = (byte >> 2) & 1; + origin[x * 8 + 6] = (byte >> 1) & 1; + origin[x * 8 + 7] = byte & 1; + } + } + return; + } + for (i = 0; i < blocks + 1; ++i) { uint8_t* origin = &hw->eReaderDots[35 * i + 200]; _eReaderAnchor(&origin[EREADER_DOTCODE_STRIDE * 0]);

@@ -427,7 +457,6 @@ memcpy(&origin[EREADER_DOTCODE_STRIDE * (33 + y) + 7], &block[b], 26);

b += 26; } } - hw->eReaderX = -24; } void _eReaderReset(struct GBACartridgeHardware* hw) {
M src/platform/qt/CoreController.cppsrc/platform/qt/CoreController.cpp

@@ -682,9 +682,15 @@ }

void CoreController::scanCard(const QString& path) { #ifdef M_CORE_GBA - QFile file(path); - file.open(QIODevice::ReadOnly); - m_eReaderData = file.read(2912); + QImage image(path); + if (image.isNull()) { + QFile file(path); + file.open(QIODevice::ReadOnly); + m_eReaderData = file.read(2912); + } else if (image.size() == QSize(989, 44)) { + const uchar* bits = image.constBits(); + m_eReaderData.setRawData(reinterpret_cast<const char*>(bits), image.sizeInBytes()); + } mCoreThreadRunFunction(&m_threadContext, [](mCoreThread* thread) { CoreController* controller = static_cast<CoreController*>(thread->userData);
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -424,7 +424,7 @@ }

} void Window::scanCard() { - QStringList filenames = GBAApp::app()->getOpenFileNames(this, tr("Select e-Reader dotcode"), tr("e-Reader card (*.raw *.bin)")); + QStringList filenames = GBAApp::app()->getOpenFileNames(this, tr("Select e-Reader dotcode"), tr("e-Reader card (*.raw *.bin *.bmp)")); for (QString& filename : filenames) { m_controller->scanCard(filename); }