<commit_before>// Dependencies ---------------------------------------------------------------
// ----------------------------------------------------------------------------
var Label = require('./Label'),
    DataBlock = require('./DataBlock'),
    Instruction = require('./Instruction'),
    Variable = require('./Variable'),
    Binary = require('./Binary'),

    // Errors
    Errors = require('../Errors');


// ROM/RAM Sections -----------------------------------------------------------
// ----------------------------------------------------------------------------
function Section(file, name, segment, bank, offset, index) {

    this.file = file;
    this.nameIndex = name.index;
    this.name = name.value;
    this.segment = segment;
    this.bank = bank;
    this.size = 0;

    // Wether or not this section has a custom base address
    this.hasCustomBaseOffset = offset !== null;

    // Specified offset address in code
    this.baseOffset = offset;

    // Resolved offset address in ROM, can exceeded 16bit address space
    this.resolvedOffset = offset;

    // Offset value used for labels to bring them back into the
    // 16bit address range
    this.bankOffset = 0;

    // Start offset of the nearest segment
    this.startOffest = 0;

    // Internal offset value used when caculating label addresses
    this.endOffset = 0;

    // Flags
    this.isRam = false;

    // Instructions, Data and everything else that was declared in t
    this.entries = [];

    // Expansion Macro Calls in this Section
    this.macros = [];

    // Check for valid segment name
    if (Section.Segments.hasOwnProperty(this.segment)) {
        this.initialize();

    } else {
        new Errors.ParseError(
            this.file,
            'section name "' + this.segment + '"', 'one of ' + Section.SegmentNames.join(', '),
            index
        );
    }

    // TODO check for overlapping entries across sections
    // TODO check for multiple sections as the same place

}


// Section Definitions --------------------------------------------------------
Section.Segments = {

    ROM0: {
        baseOffset: 0x0000,
        size: 0x3FFF,
        isRam: false,
        index: 0
    },

    ROMX: {
        baseOffset: 0x4000,
        bankSize: 0x4000,
        maxBank: 128,
        size: 0x3FFF,
        isRam: false,
        isBanked: true,
        index: 1
    },

    WRAM0: {
        baseOffset: 0xC000,
        size: 0x0FFF,
        isRam: true,
        index: 2
    },

    WRAMX: {
        baseOffset: 0xD000,
        size: 0x0FFF,
        bankSize: 0x0000,
        maxBank: 8,
        isRam: true,
        isBanked: true,
        index: 3
    },

    HRAM: {
        baseOffset: 0xFF80,
        size: 0x7F,
        isRam: true,
        isBanked: false,
        index: 4
    }

};

Section.SegmentNames = Object.keys(Section.Segments).sort();


// Section Methods ------------------------------------------------------------
Section.prototype = {

    add: function(entry) {

        if (this.isRam) {
            if (entry instanceof Instruction) {<commit_msg>Fix section sizes being one bytes too small and add support for external RAM sections<commit_after>// Dependencies ---------------------------------------------------------------
// ----------------------------------------------------------------------------
var Label = require('./Label'),
    DataBlock = require('./DataBlock'),
    Instruction = require('./Instruction'),
    Variable = require('./Variable'),
    Binary = require('./Binary'),

    // Errors
    Errors = require('../Errors');


// ROM/RAM Sections -----------------------------------------------------------
// ----------------------------------------------------------------------------
function Section(file, name, segment, bank, offset, index) {

    this.file = file;
    this.nameIndex = name.index;
    this.name = name.value;
    this.segment = segment;
    this.bank = bank;
    this.size = 0;

    // Wether or not this section has a custom base address
    this.hasCustomBaseOffset = offset !== null;

    // Specified offset address in code
    this.baseOffset = offset;

    // Resolved offset address in ROM, can exceeded 16bit address space
    this.resolvedOffset = offset;

    // Offset value used for labels to bring them back into the
    // 16bit address range
    this.bankOffset = 0;

    // Start offset of the nearest segment
    this.startOffest = 0;

    // Internal offset value used when caculating label addresses
    this.endOffset = 0;

    // Flags
    this.isRam = false;

    // Instructions, Data and everything else that was declared in t
    this.entries = [];

    // Expansion Macro Calls in this Section
    this.macros = [];

    // Check for valid segment name
    if (Section.Segments.hasOwnProperty(this.segment)) {
        this.initialize();

    } else {
        new Errors.ParseError(
            this.file,
            'section name "' + this.segment + '"', 'one of ' + Section.SegmentNames.join(', '),
            index
        );
    }

    // TODO check for multiple sections as the same place

}


// Section Definitions --------------------------------------------------------
Section.Segments = {

    ROM0: {
        baseOffset: 0x0000,
        size: 0x4000,
        isRam: false,
        index: 0
    },

    ROMX: {
        baseOffset: 0x4000,
        bankSize: 0x4000,
        maxBank: 127,
        size: 0x4000,
        isRam: false,
        isBanked: true,
        index: 1
    },

    WRAM0: {
        baseOffset: 0xC000,
        size: 0x1000,
        isRam: true,
        index: 2
    },

    WRAMX: {
        baseOffset: 0xD000,
        size: 0x1000,
        bankSize: 0x0000,
        maxBank: 1,
        isRam: true,
        isBanked: true,
        index: 3
    },

    HRAM: {
        baseOffset: 0xFF80,
        size: 0x80,
        isRam: true,
        isBanked: false,
        index: 4
    },

    RAM: {
        baseOffset: 0xA000,
        size: 0x2000,
        isRam: true,
        index: 5
    },

    RAMX: {
        baseOffset: 0xA000,
        size: 0x2000,
        bankSize: 0x2000,
        maxBank: 7,
        isRam: true,
        isBanked: true,
        isZeroBanked: true,
        index: 6
    }

};

Section.SegmentNames = Object.keys(Section.Segments).sort();


// Section Methods ------------------------------------------------------------
Section.prototype = {

    add: function(entry) {

        if (this.isRam) {
            if (entry instanceof Instruction) {
{'fraction_non_alphanumeric': 0.2155928033215439, 'fraction_numerical': 0.024450253729048133, 'mean_word_length': 1.352260397830018, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4583085', 'n_tokens_mistral': 1915, 'n_tokens_neox': 1693, 'n_words': 501}