/*
 * Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
 */

#include <ox/fs/fs.hpp>
#include <ox/std/std.hpp>

#include "../media.hpp"

#include "addresses.hpp"

namespace nostalgia::core {

ox::Result<char*> loadRom(const char*) noexcept {
	// put the header in the wrong order to prevent mistaking this code for the
	// media section
	constexpr auto headerP2 = "_HEADER_________";
	constexpr auto headerP1 = "NOSTALGIA_MEDIA";
	constexpr auto headerP1Len = 15;
	constexpr auto headerP2Len = 16;
	constexpr auto headerLen = headerP1Len + headerP2Len + 1;
	for (auto current = MEM_ROM; current < reinterpret_cast<char*>(0x0a000000); current += headerLen) {
		if (ox_memcmp(current, headerP1, headerP1Len) == 0 &&
		    ox_memcmp(current + headerP1Len, headerP2, headerP2Len) == 0) {
			return current + headerLen;
		}
	}
	return OxError(1);
}

void unloadRom(char*) noexcept {
}

}
