<commit_before>#ifndef INES_HEADER_H
#define INES_HEADER_H

#include "bank.h"

using namespace std;

#define HORZ_MIRROR 0x0
#define VERT_MIRROR 0x1
#define FOUR_SCREEN 0x8

class InesHeader : public Bank {
public:
  InesHeader()
    : Bank(0),
    _current(data.begin()),
    flags6(0x0),
    flags7(0x0),
    flags9(0x0),
    flags10(0x0) {

    // Add the 4 byte costant
    addByte(0x4e);
    addByte(0x45);
    addByte(0x53);
    addByte(0x1a);

    // Advance to end
    advance(0xff);
  };
  ~InesHeader() {};

  void setPRGRomSize(unsigned char size) {
    data.at(4) = size;
  };

  void setCHRRomSize(unsigned char size) {
    data.at(5) = size;
  };

  void setMapper(unsigned char mapper) {
    unsigned char upper = mapper >> 4;
    unsigned char lower = mapper & 0xf;
    flags6 = flags6 | (lower << 4);
    flags7 = flags7 | (upper << 4);
    updateFlags6();
    updateFlags7();
  };

  void setMirroring(unsigned char type) {
    // Make sure we only set mirroring bits
    type = type | 0x9;
    flags6 = flags6 | type;
    updateFlags6();
  };

  void setPRGRamSize(unsigned char size) {
    data.at(8) = size;
  };

  void setSRAM(bool sram) {
    if (sram) {
      flags6 = flags6 | 0x2;
    } else if ((flags6 & 0x2) == 0x2) {
      flags6 = flags6 ^ 0x2;
    }
    updateFlags6();
  };

  void setTrainer(bool trainer) {
    if (trainer) {
      flags6 = flags6 | 0x4;
    } else if ((flags6 & 0x4) == 0x4) {
      flags6 = flags6 ^ 0x4;
    }
    updateFlags6();
  };

  void setMirroringNESASM(unsigned char value) {
    /*
    0 = H (Horizontal Mirroring ONLY)
    1 = V (Vertical Mirroring ONLY)
    2 = H + Bat. (Horiztonal Mirroring + Battery ON)
    3 = V + Bat. (Vertical Mirroring + Battery ON)
    4 = H + Train. (Horizontal Mirroring + Trainer ON)<commit_msg>Getters for ines header data<commit_after>#ifndef INES_HEADER_H
#define INES_HEADER_H

#include "bank.h"

using namespace std;

#define HORZ_MIRROR 0x0
#define VERT_MIRROR 0x1
#define FOUR_SCREEN 0x8

class InesHeader : public Bank {
public:
  InesHeader()
    : Bank(0),
    _current(data.begin()),
    flags6(0x0),
    flags7(0x0),
    flags9(0x0),
    flags10(0x0) {

    // Add the 4 byte costant
    addByte(0x4e);
    addByte(0x45);
    addByte(0x53);
    addByte(0x1a);

    // Advance to end
    advance(0xff);
  };
  ~InesHeader() {};

  void setPRGRomSize(unsigned char size) {
    data.at(4) = size;
  };

  unsigned char prgRomSize() {
    return data.at(4);
  };

  void setCHRRomSize(unsigned char size) {
    data.at(5) = size;
  };

  unsigned char chrRomSize() {
    return data.at(5);
  };

  void setMapper(unsigned char mapper) {
    unsigned char upper = mapper >> 4;
    unsigned char lower = mapper & 0xf;
    flags6 = flags6 | (lower << 4);
    flags7 = flags7 | (upper << 4);
    updateFlags6();
    updateFlags7();
  };

  unsigned char mapper() {
    unsigned char lower = (flags6 >> 4);
    unsigned char upper = (flags7 >> 4);
    return (upper << 4) + lower;
  };

  void setMirroring(unsigned char type) {
    // Make sure we only set mirroring bits
    type = type | 0x9;
    flags6 = flags6 | type;
    updateFlags6();
  };

  string mirroring() {
    unsigned char mirrorValue = flags6 & 0x9;
    string ret;
    switch (mirrorValue) {
      case HORZ_MIRROR:
        ret = "HORZ";
        break;

      case VERT_MIRROR:
        ret = "VERT";
        break;

      case FOUR_SCREEN:
        ret = "4SCR";
        break;

      default:
        ret = "UNKNOWN";
        break;
    }
    return ret;
  };

  void setPRGRamSize(unsigned char size) {
    data.at(8) = size;
  };

  void setSRAM(bool sram) {
    if (sram) {
      flags6 = flags6 | 0x2;
    } else if ((flags6 & 0x2) == 0x2) {
      flags6 = flags6 ^ 0x2;
    }
    updateFlags6();
  };

  bool sram() {
    return ((flags6 & 0x2) > 0);
  };

  void setTrainer(bool trainer) {
    if (trainer) {
      flags6 = flags6 | 0x4;
    } else if ((flags6 & 0x4) == 0x4) {
      flags6 = flags6 ^ 0x4;
    }
    updateFlags6();
  };

  bool trainer() {
    return ((flags6 & 0x4) > 0);
  };

  void setMirroringNESASM(unsigned char value) {
    /*
    0 = H (Horizontal Mirroring ONLY)
    1 = V (Vertical Mirroring ONLY)
    2 = H + Bat. (Horiztonal Mirroring + Battery ON)
    3 = V + Bat. (Vertical Mirroring + Battery ON)
    4 = H + Train. (Horizontal Mirroring + Trainer ON)
{'fraction_non_alphanumeric': 0.1281816097225407, 'fraction_numerical': 0.042421462967209354, 'mean_word_length': 2.448221343873518, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4762158', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1641, 'n_words': 420}