@@ -1,12 +1,18 @@
#ifndef INCLUDE_QUIRKS_H
#define INCLUDE_QUIRKS_H
+#include <TINYSTL/string.h>
+
namespace WalrusRPG
{
namespace Quirks
- void init();
+ void init(const char *argv_0);
void deinit();
+ // Relative path to absolute path resolving.
+ // Exists because at this time Ndless doesn't support relative paths.
+ tinystl::string solve_absolute_path(const char *path);
}
@@ -1,15 +1,48 @@
+#include <cstddef>
+#include <cstring>
#include "Quirks.h"
#include "Interrupts.h"
using namespace WalrusRPG;
using namespace Nspire;
+using tinystl::string;
+namespace
+{
+ static char* base_path = nullptr;
+}
-void Quirks::init()
+void Quirks::init(const char *argv_0)
Interrupts::init();
+ // Find last '/' occurence and remove the trailing characters
+ // so we get rid of the executable name.
+ int last_slash_occurence = -1;
+ for (unsigned i = 0; argv_0[i] != '\0'; i++)
+ {
+ if (argv_0[i] == '/')
+ last_slash_occurence = i;
+ }
+ if( last_slash_occurence > 0)
+ base_path = new char[last_slash_occurence+2];
+ strncpy(base_path, argv_0, last_slash_occurence);
+ base_path[last_slash_occurence] = '/';
+ base_path[last_slash_occurence+1] = '\0';
void Quirks::deinit()
Interrupts::off();
+ delete[] base_path;
+string Quirks::solve_absolute_path(const char *path)
+ string str;
+ str.append(base_path, path);
+ return str;
@@ -1,11 +1,17 @@
+string Quirks::solve_absolute_path(const char* path)
+ return path;
@@ -13,13 +13,12 @@ using WalrusRPG::PIAF::Archive;
int main(int argc, char *argv[])
UNUSED(argc);
- UNUSED(argv);
Graphics::init();
Timing::init();
- Quirks::init();
+ Quirks::init(argv[0]);
- // Archive arc("samples/one_file.wrf");
+ // Archive arc(Quirks::solve_absolute_path("samples/one_file.wrf"));
uint16_t dungeonTest[] = {
21, 21, 1, 1, 1, 1, 21, 22, 21, 22, 21, 22, 21, 21, 1, 22, 21,
@@ -3,6 +3,7 @@
#include <cstdio>
#include <zlib.h>
using WalrusRPG::PIAF::Archive;
using WalrusRPG::PIAF::File;
using WalrusRPG::PIAF::FileEntry;
@@ -41,7 +42,7 @@ namespace
-Archive::Archive(std::string &filepath) : Archive(filepath.c_str())
+Archive::Archive(string &filepath) : Archive(filepath.c_str())
@@ -3,7 +3,7 @@
#include <cstdint>
-#include <string>
@@ -59,7 +59,7 @@ namespace WalrusRPG
public:
// RAII stuff
Archive(const char *filepath);
- Archive(std::string &filepath);
+ Archive(tinystl::string &filepath);
~Archive();
FileEntry get_file_entry(char *filename);