<commit_before>﻿using System;

namespace elbsms_core.Memory
{
    internal class Interconnect
    {
        private const int RamSize = 0x2000; // 8KB
        private const int RamMask = RamSize - 1;
        private readonly byte[] _ram = new byte[RamSize];

        private readonly MemoryControlRegister _memoryControl;

        private GameMedia _cartridge;
        private GameMedia _segaCard;

        public Interconnect()
        {
            _memoryControl = new MemoryControlRegister { Value = 0x00 };
        }

        internal void LoadGameMedia(GameMedia media)
        {
            switch (media.MediaType)
            {
                case GameMediaType.Cartridge:
                    _cartridge = media;
                    break;

                case GameMediaType.SegaCard:
                    _segaCard = media;
                    break;

                default:
                    throw new Exception($"Unsupported GameMediaType value: {media.MediaType}");
            }
        }

        internal byte ReadByte(ushort address)
        {
            // 0x0000 -> 0xBFFF - Bootstrap/Cartridge/Card/Expansion
            if (address < 0xC000)
            {
                if (_memoryControl.CartridgeSlotEnabled && _cartridge != null)
                    return _cartridge.ReadByte(address);
            }
            // 0xC000 -> 0xDFFF - System RAM
            // 0xE000 -> 0xFFFF - System RAM (mirror)
            else
            {
                if (_memoryControl.WorkRamEnabled)
                {
                    return _ram[address & RamMask];
                }
            }

            return 0xFF;
        }
<commit_msg>Map reads from sega card media as well as from cartridge<commit_after>﻿using System;

namespace elbsms_core.Memory
{
    internal class Interconnect
    {
        private const int RamSize = 0x2000; // 8KB
        private const int RamMask = RamSize - 1;
        private readonly byte[] _ram = new byte[RamSize];

        private readonly MemoryControlRegister _memoryControl;

        private GameMedia _cartridge;
        private GameMedia _segaCard;

        public Interconnect()
        {
            _memoryControl = new MemoryControlRegister { Value = 0x00 };
        }

        internal void LoadGameMedia(GameMedia media)
        {
            switch (media.MediaType)
            {
                case GameMediaType.Cartridge:
                    _cartridge = media;
                    break;

                case GameMediaType.SegaCard:
                    _segaCard = media;
                    break;

                default:
                    throw new Exception($"Unsupported GameMediaType value: {media.MediaType}");
            }
        }

        internal byte ReadByte(ushort address)
        {
            // 0x0000 -> 0xBFFF - Bootstrap/Cartridge/Card/Expansion
            if (address < 0xC000)
            {
                if (_memoryControl.CartridgeSlotEnabled && _cartridge != null)
                    return _cartridge.ReadByte(address);

                if (_memoryControl.CardSlotEnabled && _segaCard != null)
                    return _segaCard.ReadByte(address);
            }
            // 0xC000 -> 0xDFFF - System RAM
            // 0xE000 -> 0xFFFF - System RAM (mirror)
            else
            {
                if (_memoryControl.WorkRamEnabled)
                {
                    return _ram[address & RamMask];
                }
            }

            return 0xFF;
        }

{'fraction_non_alphanumeric': 0.06883747500714081, 'fraction_numerical': 0.017709225935447014, 'mean_word_length': 1.3346666666666667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '3811350', 'n_tokens_mistral': 960, 'n_tokens_neox': 834, 'n_words': 212}