about summary refs log tree commit diff stats
path: root/data/maps/the_wise/connections.txtpb
blob: e3aa07b8a1e11d5c1c84cb2165a92351834aaa98 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
connections {
  from_room: "Entry"
  to_room: "Puzzles"
  door { name: "Front Door" }
}
connections {
  from_room: "Puzzles"
  to_room: "Mastery"
  door { name: "Mastery" }
}
0; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#ifndef COMMON_H_04DD2B2A
#define COMMON_H_04DD2B2A

#include <vector>
#include <string_view>
#include <fstream>
#include <stdexcept>

class BufferView {
public:

  BufferView(const std::vector<char>& buffer) : data_(&buffer) {}

  int ReadNextByte() {
    int o2r = offset_;
    offset_++;
    return ReadByte(o2r);
  }

  int ReadByte(int addr) const {
    return static_cast<unsigned char>((*data_)[addr]);
  }

  int ReadNextTwoBytes() {
    int o2r = offset_;
    offset_+=2;
    return ReadTwoBytes(o2r);
  }

  int ReadTwoBytes(int addr) const {
    return static_cast<unsigned char>((*data_)[addr]) | (static_cast<unsigned char>((*data_)[addr + 1]) << 8);
  }

  int ReadNextFourBytes() {
    int o2r = offset_;
    offset_+=4;
    return ReadFourBytes(o2r);
  }

  unsigned long ReadFourBytes(int addr) const {
    return static_cast<unsigned char>((*data_)[addr]) | (static_cast<unsigned char>((*data_)[addr + 1]) << 8) | (static_cast<unsigned char>((*data_)[addr + 2]) << 16) | (static_cast<unsigned char>((*data_)[addr + 3]) << 24);
  }

  void Seek(int offset) {
    offset_ = offset;
  }

  void SeekAdd(int delta) {
    offset_ += delta;
  }

  std::vector<char> Decompress(int addr) {
    int start = addr;
    Seek(addr);
    if (ReadNextByte() != 0x10) {
      throw std::domain_error("No LZ77 signature");
    }

    int length = ReadNextByte();
    length += (ReadNextByte() << 8);
    length += (ReadNextByte() << 16);

    std::vector<char> result(length, 0);

    int bPos = 0;
    while (bPos < length) {
      unsigned char ch = ReadNextByte();
      for (int i=0;i<8;i++) {
        switch ((ch >> (7-i)) & 1) {
          case 0: {
            if (bPos >= length) break;
            result[bPos++] = ReadNextByte();
            break;
          }
          case 1: {
            int t = (ReadNextByte() << 8);
            t += ReadNextByte();
            int n = ((t >> 12) & 0xF) + 3; // num of bytes to copy
            int o = (t & 0xFFF);

            for (int j=0; j<n; j++) {
              if (bPos >= length) break;
              result[bPos] = result[bPos - o - 1];
              bPos++;
            }
            break;
          }
          default: break;
        }
      }
    }

    return result;
  }

private:

  const std::vector<char>* data_;
  int offset_ = 0;
};

class Rom {
public:

  explicit Rom(std::string_view filename) {
    std::ifstream romfile(filename.data(), std::ios::binary);
    if (!romfile.is_open()) {
      throw std::invalid_argument("Could not find ROM file: " + std::string(filename));
    }

    romfile.seekg(0, romfile.end);
    int length = romfile.tellg();
    romfile.seekg(0, romfile.beg);

    if (length != 0x2000000) {
      throw std::invalid_argument("Incorrect ROM length");
    }

    data_ = std::vector<char>(length, 0);
    romfile.read(data_.data(), length);

    const char header[] = {'M','O','T','H','E','R','3',0,0,0,0,0,'A','3','U','J'};
    std::string headerTest;
    for (int i = 0xA0; i < 0xB0; i++) {
      if (data_.at(i) != header[i-0xA0]) {
        std::cout << i << std::endl;

        throw std::invalid_argument("Invalid ROM header");
      }
    }
  }

  const std::vector<char>& data() const { return data_; }

  BufferView buffer() const { return {data_}; }

private:

  std::vector<char> data_;
};

class Palette {
public:

  Palette() = default;

  Palette(BufferView m3, const int addr) {
    for (int i=0; i<16; i++) {
      unsigned short ch = m3.ReadTwoBytes(addr + (i << 1));
      int r = (ch & 0x1F);
      int g = ((ch >> 5) & 0x1F);
      int b = ((ch >> 10) & 0x1F);
      colors_.push_back(Magick::ColorRGB((r << 3)/256.0, (g << 3)/256.0, (b << 3)/256.0));
    }
  }

  const std::vector<Magick::Color>& Colors() const { return colors_; }

private:
  std::vector<Magick::Color> colors_;
};

#endif /* end of include guard: COMMON_H_04DD2B2A */