<commit_before>﻿using System;
using IFVM.Core;

namespace IFVM.Glulx
{
    public class GlulxMachine : Machine
    {
        public GlulxHeader Header { get; }

        public GlulxMachine(Memory memory) : base(memory)
        {
            this.Header = new GlulxHeader(memory);

            VerifyChecksum(memory, this.Header.Checksum);

            // Initial the memory should have a size equal to ExtStart.
            // We must expand it to EndMem.
            if (this.Header.ExtStart != memory.Size)
            {
                throw new InvalidOperationException($"Size expected to be {this.Header.ExtStart}");
            }

            memory.Expand((int)this.Header.EndMem);
        }

        private static void VerifyChecksum(Memory memory, uint expectedValue)
        {
            var scanner = memory.CreateScanner(offset: 0);

            var checksum = 0u;
            while (scanner.CanReadNextDWord)
            {
                if (scanner.Offset == 0x20)
                {
                    // Note: We don't include the checksum value from the header.
                    scanner.SkipDWord();
                }
                else
                {
                    checksum += scanner.NextDWord();
                }
            }

            if (checksum != expectedValue)
            {
                throw new InvalidOperationException("Checksum does not match.");
            }
        }
    }
}<commit_msg>Mark ROM region for Glulx<commit_after>﻿using System;
using IFVM.Core;

namespace IFVM.Glulx
{
    public class GlulxMachine : Machine
    {
        public GlulxHeader Header { get; }

        public GlulxMachine(Memory memory) : base(memory)
        {
            this.Header = new GlulxHeader(memory);

            VerifyChecksum(memory, this.Header.Checksum);

            // Initial the memory should have a size equal to ExtStart.
            // We must expand it to EndMem.
            if (this.Header.ExtStart != memory.Size)
            {
                throw new InvalidOperationException($"Size expected to be {this.Header.ExtStart}");
            }

            memory.Expand((int)this.Header.EndMem);
            memory.AddReadOnlyRegion(0, (int)this.Header.RamStart);
        }

        private static void VerifyChecksum(Memory memory, uint expectedValue)
        {
            var scanner = memory.CreateScanner(offset: 0);

            var checksum = 0u;
            while (scanner.CanReadNextDWord)
            {
                if (scanner.Offset == 0x20)
                {
                    // Note: We don't include the checksum value from the header.
                    scanner.SkipDWord();
                }
                else
                {
                    checksum += scanner.NextDWord();
                }
            }

            if (checksum != expectedValue)
            {
                throw new InvalidOperationException("Checksum does not match.");
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.08434139784946236, 'fraction_numerical': 0.003696236559139785, 'mean_word_length': 1.4085760517799353, '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': '6487650', 'n_tokens_mistral': 791, 'n_tokens_neox': 748, 'n_words': 190}