bsnes/sourcery/sourcery.cpp

86 lines
3.1 KiB
C++
Raw Normal View History

#include <nall/nall.hpp>
using namespace nall;
struct Sourcery {
auto main(Arguments arguments) -> void;
auto parse(Markup::Node&) -> void;
private:
string pathname;
file_buffer source;
file_buffer header;
};
auto Sourcery::main(Arguments arguments) -> void {
if(arguments.size() != 3) return print("usage: sourcery resource.bml resource.cpp resource.hpp\n");
string markupName = arguments.take();
string sourceName = arguments.take();
string headerName = arguments.take();
if(!markupName.endsWith(".bml")) return print("error: arguments in incorrect order\n");
if(!sourceName.endsWith(".cpp")) return print("error: arguments in incorrect order\n");
if(!headerName.endsWith(".hpp")) return print("error: arguments in incorrect order\n");
string markup = string::read(markupName);
if(!markup) return print("error: unable to read resource manifest\n");
pathname = Location::path(markupName);
if(!source.open(sourceName, file::mode::write)) return print("error: unable to write source file\n");
if(!header.open(headerName, file::mode::write)) return print("error: unable to write header file\n");
source.print("#include \"", headerName, "\"\n");
source.print("\n");
auto document = BML::unserialize(markup);
parse(document);
}
auto Sourcery::parse(Markup::Node& root) -> void {
for(auto node : root) {
if(node.name() == "namespace") {
header.print("namespace ", node["name"].text(), " {\n");
source.print("namespace ", node["name"].text(), " {\n");
parse(node);
header.print("}\n");
source.print("}\n");
} else if(node.name() == "binary") {
string filename{pathname, node["file"].text()};
if(!file::exists(filename)) {
print("warning: binary file ", node["file"].text(), " not found\n");
continue;
}
auto buffer = file::read(filename);
header.print("extern const unsigned char ", node["name"].text(), "[", buffer.size(), "];\n");
source.print("const unsigned char ", node["name"].text(), "[", buffer.size(), "] = {\n");
buffer.foreach([&](uint offset, int data) {
if((offset & 31) == 0) source.print(" ");
source.print(data, ",");
if((offset & 31) == 31) source.print("\n");
});
if(buffer.size() & 31) source.print("\n");
source.print("};\n");
} else if(node.name() == "string") {
string filename{pathname, node["file"].text()};
if(!file::exists(filename)) {
print("warning: string file ", node["file"].text(), " not found\n");
continue;
}
auto buffer = file::read(filename);
header.print("extern const char ", node["name"].text(), "[", buffer.size() + 1, "];\n");
Update to bsnes v107 release. [This is specifically a release of bsnes, not the whole higan suite, even though it contains all the higan source. -Ed.] byuu says: Today I am posting the first release of the new bsnes emulator. bsnes is designed to be a revival of the classic bsnes design, focusing specifically on performance and ease of use for SNES emulation. In addition to all of the features of higan, bsnes supports the following features: - 300% faster (than higan) scanline-based, multi-threaded graphics renderer - option to disable sprite limits in games - option to enable hires mode 7 graphics - option to enable more accurate pixel-based graphics renderer - option to overclock SuperFX games by up to 800% - periodic auto-saving of game save RAM - save state manager with state screenshots - several new save state hotkeys such as increment/decrement slot# - option to auto-save states when unloading a game or closing the emulator - option to auto-load aforementioned states when loading games - save state undo and redo support (with associated hotkeys) - speed override modes (50%, 75%, 100%, 150%, 200%) - recent games list - frame advance mode - screenshot hotkey - path selection for games, patches, saves, cheats, states, and screenshots - dynamic video, audio, input driver changes - direct loading and playing of games without the use of the higan library - ZIP archive and multiple file extension support for games - firmware folder for unappended coprocessor firmware (see documentation for more) - compatibility with sd2snes and Snes9X MSU1 game file naming - compatibility with higan gamepaks (game folders) - soft-patching support for both BPS and IPS patches - menubar that does not pause emulation when entered - video pixel shaders (requires OpenGL 3.2) - built-in game database with over 1,200 games to ensure perfect memory mapping - (Linux, BSD only:) audio dynamic rate control to eliminate stuttering - and much more! The one feature I regret not being able to support in this release is Windows dynamic rate control. I put in my best attempt, but XAudio2's API is simply not fine-grained enough, and the WASAPI driver is not mature enough. I hope that DRC support can be added to the Windows port in the near future, and I would like to offer a large cash bounty to anyone who can help me make this happen.
2019-02-22 06:46:53 +00:00
source.print("const char ", node["name"].text(), "[", buffer.size() + 1, "] = {\n");
buffer.foreach([&](uint offset, uint8_t data) {
if((offset & 31) == 0) source.print(" ");
source.print(data, ",");
if((offset & 31) == 31) source.print("\n");
});
Update to bsnes v107 release. [This is specifically a release of bsnes, not the whole higan suite, even though it contains all the higan source. -Ed.] byuu says: Today I am posting the first release of the new bsnes emulator. bsnes is designed to be a revival of the classic bsnes design, focusing specifically on performance and ease of use for SNES emulation. In addition to all of the features of higan, bsnes supports the following features: - 300% faster (than higan) scanline-based, multi-threaded graphics renderer - option to disable sprite limits in games - option to enable hires mode 7 graphics - option to enable more accurate pixel-based graphics renderer - option to overclock SuperFX games by up to 800% - periodic auto-saving of game save RAM - save state manager with state screenshots - several new save state hotkeys such as increment/decrement slot# - option to auto-save states when unloading a game or closing the emulator - option to auto-load aforementioned states when loading games - save state undo and redo support (with associated hotkeys) - speed override modes (50%, 75%, 100%, 150%, 200%) - recent games list - frame advance mode - screenshot hotkey - path selection for games, patches, saves, cheats, states, and screenshots - dynamic video, audio, input driver changes - direct loading and playing of games without the use of the higan library - ZIP archive and multiple file extension support for games - firmware folder for unappended coprocessor firmware (see documentation for more) - compatibility with sd2snes and Snes9X MSU1 game file naming - compatibility with higan gamepaks (game folders) - soft-patching support for both BPS and IPS patches - menubar that does not pause emulation when entered - video pixel shaders (requires OpenGL 3.2) - built-in game database with over 1,200 games to ensure perfect memory mapping - (Linux, BSD only:) audio dynamic rate control to eliminate stuttering - and much more! The one feature I regret not being able to support in this release is Windows dynamic rate control. I put in my best attempt, but XAudio2's API is simply not fine-grained enough, and the WASAPI driver is not mature enough. I hope that DRC support can be added to the Windows port in the near future, and I would like to offer a large cash bounty to anyone who can help me make this happen.
2019-02-22 06:46:53 +00:00
if(buffer.size() & 31) source.print("\n");
source.print("};\n");
}
}
}
#include <nall/main.hpp>
auto nall::main(Arguments arguments) -> void {
Sourcery().main(arguments);
}