1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 23:52:26 +00:00
CLK/OSBindings/Mac/Clock Signal/Machine/CSROMFetcher.mm
2018-01-01 16:04:13 -05:00

36 lines
1.1 KiB
Plaintext

//
// CSROMFetcher.m
// Clock Signal
//
// Created by Thomas Harte on 01/01/2018.
// Copyright © 2018 Thomas Harte. All rights reserved.
//
#import <Foundation/Foundation.h>
#include "CSROMFetcher.hpp"
#import "NSBundle+DataResource.h"
#import "NSData+StdVector.h"
#include <string>
void CSApplyROMFetcher(ROMMachine::Machine &rom_machine) {
rom_machine.set_rom_fetcher( [] (const std::string &machine, const std::vector<std::string> &names) -> std::vector<std::unique_ptr<std::vector<std::uint8_t>>> {
NSString *subDirectory = [@"ROMImages/" stringByAppendingString:[NSString stringWithUTF8String:machine.c_str()]];
std::vector<std::unique_ptr<std::vector<std::uint8_t>>> results;
for(auto &name: names) {
NSData *fileData = [[NSBundle mainBundle] dataForResource:[NSString stringWithUTF8String:name.c_str()] withExtension:nil subdirectory:subDirectory];
if(!fileData)
results.emplace_back(nullptr);
else {
std::unique_ptr<std::vector<std::uint8_t>> data(new std::vector<std::uint8_t>);
*data = fileData.stdVector8;
results.emplace_back(std::move(data));
}
}
return results;
});
}