Annotation of nono/vm/mpu.cpp, revision 1.1.1.5

1.1       root        1: //
                      2: // nono
1.1.1.3   root        3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
1.1       root        5: //
                      6: 
1.1.1.2   root        7: // MPU 共通部
                      8: 
1.1       root        9: #include "mpu.h"
1.1.1.5 ! root       10: #include "config.h"
1.1       root       11: 
1.1.1.2   root       12: std::unique_ptr<MPUDevice> gMPU;
1.1       root       13: 
                     14: // コンストラクタ
1.1.1.2   root       15: MPUDevice::MPUDevice()
1.1       root       16: {
                     17:        logname = "mpu";
                     18:        devname = "MPU";
1.1.1.4   root       19: 
1.1.1.5 ! root       20:        // リセット例外を起こすイベント。
        !            21:        // ハンドラは MPU ごとに異なるので継承クラス側で用意している。
        !            22:        // (この時点ではまだ Scheduler インスタンスは存在してないが、イベントを
        !            23:        // 実際に Scheduler に登録するのは ResetHard() の時点なので問題ない)
        !            24:        event.dev = this;
        !            25:        event.SetName("MPU");
1.1       root       26: }
                     27: 
                     28: // デストラクタ
                     29: MPUDevice::~MPUDevice()
                     30: {
                     31: }
1.1.1.4   root       32: 
1.1.1.5 ! root       33: bool
        !            34: MPUDevice::Init()
        !            35: {
        !            36:        // MPU クロック
        !            37:        const ConfigItem& item = gConfig->Find("mpu-clock");
        !            38:        const std::string& val = item.AsString();
        !            39:        if (val.empty()) {
        !            40:                item.Err();
        !            41:                return false;
        !            42:        }
        !            43:        // 文字列を double に変換
        !            44:        char *end;
        !            45:        errno = 0;
        !            46:        double f = strtod(val.c_str(), &end);
        !            47:        if (end == val.c_str() || end[0] != '\0' || errno == ERANGE) {
        !            48:                item.Err();
        !            49:                return false;
        !            50:        }
        !            51:        // 設定の "mpu-clock" は MHz 単位だが、変数 clock_khz は kHz 単位。
        !            52:        clock_khz = (int)(f * 1000);
        !            53:        // 1MHz 以下はエラー。実際 10MHz 以下でもいい気がするけど
        !            54:        if (clock_khz < 1000) {
        !            55:                item.Err();
        !            56:                return false;
        !            57:        }
        !            58: 
        !            59:        return true;
        !            60: }
        !            61: 
1.1.1.4   root       62: // リセット
                     63: void
                     64: MPUDevice::ResetHard()
                     65: {
                     66:        // 0 サイクル後にリセット例外を起こす
1.1.1.5 ! root       67:        event.time = 0;
        !            68:        event.code = (uint32)-1;
        !            69:        event.Start();
1.1.1.4   root       70: }

unix.superglobalmegacorp.com

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