Annotation of nono/vm/subram.cpp, revision 1.1

1.1     ! root        1: //
        !             2: // nono
        !             3: // Copyright (C) 2020 nono project
        !             4: // Licensed under nono-license.txt
        !             5: //
        !             6: 
        !             7: //
        !             8: // サブメモリ
        !             9: //
        !            10: 
        !            11: // SubRAM はバイト配置とする。
        !            12: 
        !            13: #include "subram.h"
        !            14: #include "mainapp.h"
        !            15: 
        !            16: //
        !            17: // 共通クラス
        !            18: //
        !            19: 
        !            20: // コンストラクタ
        !            21: SubRAMBaseDevice::SubRAMBaseDevice(int objid_, uint ramsize_kb)
        !            22:        : inherited(objid_)
        !            23: {
        !            24:        ramsize = ramsize_kb * 1024;
        !            25: 
        !            26:        ram.reset(new uint8[ramsize]);
        !            27:        memset(&ram[0], 0, ramsize);
        !            28: }
        !            29: 
        !            30: // デストラクタ
        !            31: SubRAMBaseDevice::~SubRAMBaseDevice()
        !            32: {
        !            33: }
        !            34: 
        !            35: // リセット
        !            36: void
        !            37: SubRAMBaseDevice::ResetHard(bool poweron)
        !            38: {
        !            39:        if (poweron) {
        !            40:                // 実際にはゼロ初期化ではなくゴミだと思うがとりあえず。
        !            41:                memset(&ram[0], 0, ramsize);
        !            42:        }
        !            43: }
        !            44: 
        !            45: // アドレスデコーダ
        !            46: inline uint64
        !            47: SubRAMBaseDevice::Decoder(uint32 addr) const
        !            48: {
        !            49:        // たぶん 128KB というかサイズ分で折り返しイメージが見えるはず。要確認。
        !            50:        return addr % ramsize;
        !            51: }
        !            52: 
        !            53: uint64
        !            54: SubRAMBaseDevice::Read8(uint32 addr)
        !            55: {
        !            56:        uint32 offset = Decoder(addr);
        !            57:        uint32 data = ram[offset];
        !            58:        putlog(4, "$%08x.B -> $%02x", addr, data);
        !            59:        return data;
        !            60: }
        !            61: 
        !            62: uint64
        !            63: SubRAMBaseDevice::Read16(uint32 addr)
        !            64: {
        !            65:        uint32 offset = Decoder(addr);
        !            66:        uint32 data;
        !            67:        data  = (uint32)ram[offset + 0] << 8;
        !            68:        data |= (uint32)ram[offset + 1];
        !            69:        putlog(4, "$%08x.W -> $%04x", addr, data);
        !            70:        return data;
        !            71: }
        !            72: 
        !            73: uint64
        !            74: SubRAMBaseDevice::Read32(uint32 addr)
        !            75: {
        !            76:        uint32 offset = Decoder(addr);
        !            77:        uint32 data;
        !            78:        data  = (uint32)ram[offset + 0] << 24;
        !            79:        data |= (uint32)ram[offset + 1] << 16;
        !            80:        data |= (uint32)ram[offset + 2] << 8;
        !            81:        data |= (uint32)ram[offset + 3];
        !            82:        putlog(4, "$%08x.L -> $%08x", addr, data);
        !            83:        return data;
        !            84: }
        !            85: 
        !            86: uint64
        !            87: SubRAMBaseDevice::Write8(uint32 addr, uint32 data)
        !            88: {
        !            89:        putlog(3, "$%08x.B <- $%02x", addr, data);
        !            90: 
        !            91:        uint32 offset = Decoder(addr);
        !            92:        ram[offset] = data;
        !            93:        return 0;
        !            94: }
        !            95: 
        !            96: uint64
        !            97: SubRAMBaseDevice::Write16(uint32 addr, uint32 data)
        !            98: {
        !            99:        putlog(3, "$%08x.W <- $%04x", addr, data);
        !           100: 
        !           101:        uint32 offset = Decoder(addr);
        !           102:        ram[offset + 0] = (data >> 8) & 0xff;
        !           103:        ram[offset + 1] =  data       & 0xff;
        !           104:        return 0;
        !           105: }
        !           106: 
        !           107: uint64
        !           108: SubRAMBaseDevice::Write32(uint32 addr, uint32 data)
        !           109: {
        !           110:        putlog(3, "$%08x.L <- $%08x", addr, data);
        !           111: 
        !           112:        uint32 offset = Decoder(addr);
        !           113:        ram[offset + 0] =  data >> 24;
        !           114:        ram[offset + 1] = (data >> 16) & 0xff;
        !           115:        ram[offset + 2] = (data >> 8)  & 0xff;
        !           116:        ram[offset + 3] =  data        & 0xff;
        !           117:        return 0;
        !           118: }
        !           119: 
        !           120: uint64
        !           121: SubRAMBaseDevice::Peek8(uint32 addr)
        !           122: {
        !           123:        uint32 offset = Decoder(addr);
        !           124:        return ram[offset];
        !           125: }
        !           126: 
        !           127: uint64
        !           128: SubRAMBaseDevice::Poke8(uint32 addr, uint32 data)
        !           129: {
        !           130:        if ((int32)data >= 0) {
        !           131:                uint32 offset = Decoder(addr);
        !           132:                ram[offset] = data;
        !           133:        }
        !           134:        return 0;
        !           135: }
        !           136: 
        !           137: 
        !           138: //
        !           139: // サブメモリ 1
        !           140: //
        !           141: 
        !           142: // コンストラクタ
        !           143: SubRAMDevice::SubRAMDevice(int ramsize_kb)
        !           144:        : inherited(OBJ_SUBRAM, ramsize_kb)
        !           145: {
        !           146: }
        !           147: 
        !           148: // デストラクタ
        !           149: SubRAMDevice::~SubRAMDevice()
        !           150: {
        !           151: }
        !           152: 
        !           153: // リセット
        !           154: void
        !           155: SubRAMDevice::ResetHard(bool poweron)
        !           156: {
        !           157:        // 通常モードなら電源オンで初期化。
        !           158:        // MSXDOS モードなら MSXDOSDevice::Init() がすでにここに
        !           159:        // 書き込んでいるため、消してはいけない。
        !           160:        if (gMainApp.msxdos_mode == false) {
        !           161:                inherited::ResetHard(poweron);
        !           162:        }
        !           163: }
        !           164: 
        !           165: 
        !           166: //
        !           167: // サブメモリ 2
        !           168: //
        !           169: 
        !           170: // コンストラクタ
        !           171: SubRAM2Device::SubRAM2Device(int ramsize_kb)
        !           172:        : inherited(OBJ_SUBRAM2, ramsize_kb)
        !           173: {
        !           174: }
        !           175: 
        !           176: // デストラクタ
        !           177: SubRAM2Device::~SubRAM2Device()
        !           178: {
        !           179: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.