implement load_rom and unload_rom
This commit is contained in:
@@ -115,7 +115,7 @@ include(test/CMakeLists.txt)
|
||||
|
||||
# Yaze C API
|
||||
add_library(yaze_c SHARED
|
||||
app/yaze.cc
|
||||
./yaze.cc
|
||||
app/rom.cc
|
||||
${YAZE_APP_EMU_SRC}
|
||||
${YAZE_APP_CORE_SRC}
|
||||
|
||||
25
src/yaze.cc
25
src/yaze.cc
@@ -1,15 +1,36 @@
|
||||
#include "yaze.h"
|
||||
|
||||
#include "app/rom.h"
|
||||
|
||||
// TODO: Implement yaze_initialize
|
||||
void yaze_initialize(void) {}
|
||||
|
||||
// TODO: Implement yaze_cleanup
|
||||
void yaze_cleanup(void) {}
|
||||
|
||||
// TODO: Implement load_rom
|
||||
Rom load_rom(const char* filename) {
|
||||
yaze::app::Rom* internal_rom;
|
||||
internal_rom = new yaze::app::Rom();
|
||||
if (!internal_rom->LoadFromFile(filename).ok()) {
|
||||
delete internal_rom;
|
||||
Rom rom;
|
||||
rom.impl = nullptr;
|
||||
rom.filename = filename;
|
||||
rom.data = nullptr;
|
||||
rom.size = 0;
|
||||
return rom;
|
||||
}
|
||||
|
||||
Rom rom;
|
||||
rom.impl = internal_rom;
|
||||
rom.filename = filename;
|
||||
rom.data = nullptr;
|
||||
rom.data = internal_rom->data();
|
||||
rom.size = internal_rom->size();
|
||||
return rom;
|
||||
}
|
||||
|
||||
void unload_rom(Rom rom) {
|
||||
if (rom.impl) {
|
||||
delete static_cast<yaze::app::Rom*>(rom.impl);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef YAZE_H
|
||||
#define YAZE_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -16,9 +17,12 @@ typedef struct Rom Rom;
|
||||
struct Rom {
|
||||
const char* filename;
|
||||
const uint8_t* data;
|
||||
size_t size;
|
||||
void* impl; // yaze::app::Rom*
|
||||
};
|
||||
|
||||
Rom load_rom(const char* filename);
|
||||
void unload_rom(Rom rom);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user