Skip to content

Commit 254dc3e

Browse files
committed
First version supporting vgm 1.72 exports from Furnace
1 parent 422a63b commit 254dc3e

File tree

9 files changed

+1993
-0
lines changed

9 files changed

+1993
-0
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required (VERSION 3.8)
2+
3+
project ("VGM2LNX")
4+
5+
set(CMAKE_CXX_STANDARD 17)
6+
7+
add_executable (VGM2LNX VGM2LNX.cpp convert.cpp )
8+

Ex.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#pragma once
2+
3+
#include <exception>
4+
#include <memory>
5+
#include <sstream>
6+
7+
class Ex : public std::exception
8+
{
9+
public:
10+
11+
Ex() : exception{}, mSS{ std::make_shared<std::stringstream>() }, mStr{}
12+
{
13+
}
14+
15+
template<typename T>
16+
Ex& operator<<( T const& t )
17+
{
18+
*mSS << t;
19+
return *this;
20+
}
21+
22+
char const* what() const
23+
{
24+
mStr = mSS->str();
25+
return mStr.c_str();
26+
}
27+
28+
private:
29+
std::shared_ptr<std::stringstream> mSS;
30+
mutable std::string mStr;
31+
};
32+

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# VGM2LNX
2+
Conversion tool for VGM files holding Lynx music to Lynx cartridge images with simple player.
3+
4+
## Compilation
5+
6+
Use CMake. Requires C++17
7+
8+
## Usage
9+
```
10+
VGM2LNX input.vgm [output.lnx]
11+
```
12+
If output file is missing, input file is taken with replaced extension to .lnx
13+
14+
## Caveats
15+
Generated player does not work with Handy or any other Lynx emulator know at the time of writing. Please use only real hardware.
16+
17+

VGM2LNX.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
#include <iostream>
3+
#include <fstream>
4+
#include <filesystem>
5+
#include <vector>
6+
#include "Ex.hpp"
7+
8+
std::vector<uint8_t> convert( std::vector<uint8_t> const& plain );
9+
10+
int main( int argc, char const* argv[] )
11+
{
12+
try
13+
{
14+
if ( argc < 2 )
15+
{
16+
std::cout << "VGM2LNX input.vgm [output.lnx]\n";
17+
return 1;
18+
}
19+
20+
std::filesystem::path path{ argv[1] };
21+
std::filesystem::path outpath{ argv[ argc < 3 ? 1 : 2] };
22+
if ( argc < 3 )
23+
outpath.replace_extension( ".lnx" );
24+
25+
if ( !std::filesystem::exists( path ) )
26+
{
27+
throw Ex{} << "File '" << path.string() << "' does not exist\n";
28+
}
29+
30+
size_t size = std::filesystem::file_size( path );
31+
32+
if ( size == 0 )
33+
{
34+
throw Ex{} << "File '" << path.string() << "' is empty\n";
35+
}
36+
37+
std::vector<uint8_t> input;
38+
input.resize( size );
39+
40+
{
41+
std::ifstream fin{ path, std::ios::binary };
42+
fin.read( (char*)input.data(), size );
43+
}
44+
45+
auto cvt = convert( input );
46+
47+
std::ofstream fout{ outpath, std::ios::binary };
48+
fout.write( (char const*)cvt.data(), cvt.size() );
49+
}
50+
catch ( Ex const& ex )
51+
{
52+
std::cerr << ex.what() << std::endl;
53+
return -1;
54+
}
55+
}

0 commit comments

Comments
 (0)