Skip to content

Instantly share code, notes, and snippets.

@DavidBuchanan314
Last active December 12, 2019 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidBuchanan314/2ecf054b6456419edc1f651f96878ce6 to your computer and use it in GitHub Desktop.
Save DavidBuchanan314/2ecf054b6456419edc1f651f96878ce6 to your computer and use it in GitHub Desktop.
#include "stdafx.h"
static unsigned char *rom = (unsigned char *) 0x80000000L;
const size_t rom_size = 0x4000000, block_size = 0x10000;
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
DWORD dwBytesWritten;
size_t i;
printf("Hello, world!\n");
HANDLE hFile = CreateFile(L"\\Storage Card\\romdump.bin",
GENERIC_WRITE,
0,
NULL,
CREATE_NEW,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile == INVALID_HANDLE_VALUE) {
printf("Failed to open file\n");
goto done;
}
for (i=0; i<rom_size;) {
BOOL bErrorFlag = WriteFile(hFile,
&rom[i],
block_size,
&dwBytesWritten,
NULL);
if (bErrorFlag == FALSE) {
printf("Error writing file\n");
goto done;
}
if (dwBytesWritten != block_size) {
printf("Didn't write enough\n");
goto done;
}
i+=block_size;
printf("Dumped 0x%lx bytes. (%u%%)\n", i, ((i/block_size)*100)/(rom_size/block_size));
}
CloseHandle(hFile);
printf("Done!\n");
done:
getchar();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment