Last active
January 9, 2020 19:29
-
-
Save oupo/75fd51fe05c8de512c33f1d4354ed735 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fat.h> | |
#include <nds.h> | |
#include <stdio.h> | |
#include <iostream> | |
#include <algorithm> | |
// https://github.com/nayuki/QR-Code-generator | |
#include "BitBuffer.hpp" | |
#include "QrCode.hpp" | |
using qrcodegen::QrCode; | |
using qrcodegen::QrSegment; | |
using std::uint8_t; | |
void waitKey() | |
{ | |
scanKeys(); | |
while ((keysDown() & KEY_A) == 0) | |
{ | |
swiWaitForVBlank(); | |
scanKeys(); | |
} | |
} | |
void dumpQR(u16 *videoMemoryMain, int blockid, uint8_t *buf, int len) | |
{ | |
std::vector<uint8_t> vec(4 + len); | |
vec[0] = blockid & 0xff; | |
vec[1] = (blockid >> 8) & 0xff; | |
vec[2] = (blockid >> 16) & 0xff; | |
vec[3] = (blockid >> 24) & 0xff; | |
std::copy(buf, buf + len, vec.begin() + 4); | |
const QrCode::Ecc errCorLvl = QrCode::Ecc::MEDIUM; // Error correction level | |
const QrCode qr = QrCode::encodeBinary(vec, errCorLvl); | |
int size = qr.getSize(); | |
for (int y = -1; y < size + 1; y++) | |
{ | |
for (int x = -1; x < size + 1; x++) | |
{ | |
int c = qr.getModule(x, y) ? 31 : 0; | |
for (int dx = 0; dx < 2; dx ++) { | |
for (int dy = 0; dy < 2; dy ++) { | |
videoMemoryMain[(2 * x + dx + 50) + (2 * y + dy + 10) * 256] = ARGB16(1, c, c, c); | |
} | |
} | |
} | |
} | |
} | |
const int BLOCK_SIZE = 0x200; | |
void dump(void) | |
{ | |
videoSetMode(MODE_5_2D); | |
vramSetBankA(VRAM_A_MAIN_BG); | |
int bgMain = bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0); | |
u16 *videoMemoryMain = bgGetGfxPtr(bgMain); | |
for (int i = 0; i < 256 * 256; i++) | |
videoMemoryMain[i] = ARGB16(1, 31, 31, 31); | |
char name[13] = ""; | |
char code[5] = ""; | |
strncpy(name, (char *)0x080000A0, 12); | |
memcpy(code, (char *)0x080000AC, 4); | |
printf("Dump target: %s\n", name); | |
size_t i; | |
for (i = 0x0; i < 0x100000; i += BLOCK_SIZE) | |
{ | |
printf("Dumping %07X...", i); | |
dumpQR(videoMemoryMain, i / BLOCK_SIZE, ((uint8_t *)GBAROM) + i, BLOCK_SIZE); | |
printf("done\n"); | |
} | |
printf("Done!\n"); | |
} | |
int main(void) | |
{ | |
consoleDemoInit(); | |
videoSetMode(MODE_FB0); | |
vramSetBankA(VRAM_A_LCD); | |
sysSetCartOwner(1); | |
dump(); | |
while (1) | |
{ | |
swiWaitForVBlank(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment