[nostalgia/core] Add unloadRom function

This commit is contained in:
Gary Talent 2020-01-12 20:44:57 -06:00
parent 84ee494834
commit 04727ae57a
3 changed files with 23 additions and 4 deletions

View File

@ -32,4 +32,7 @@ uint8_t *loadRom(const char*) {
return nullptr; return nullptr;
} }
void unloadRom(uint8_t*) {
}
} }

View File

@ -14,4 +14,6 @@ namespace nostalgia::core {
uint8_t *loadRom(const char *path = ""); uint8_t *loadRom(const char *path = "");
void unloadRom(uint8_t*);
} }

View File

@ -6,15 +6,29 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
#include <ox/fs/fs.hpp> #include <cstdio>
#include <ox/std/std.hpp>
#include "../media.hpp" #include "../media.hpp"
namespace nostalgia::core { namespace nostalgia::core {
uint8_t *loadRom(const char*) { uint8_t *loadRom(const char *path) {
return nullptr; auto file = fopen(path, "r");
if (file) {
fseek(file, 0, SEEK_END);
const auto size = ftell(file);
rewind(file);
auto buff = new uint8_t[size];
fread(buff, size, 1, file);
fclose(file);
return buff;
} else {
return nullptr;
}
}
void unloadRom(uint8_t *rom) {
delete rom;
} }
} }