Annotation of nono/vm/vm.cpp, revision 1.1.1.6

1.1       root        1: //
                      2: // nono
1.1.1.4   root        3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
1.1       root        5: //
                      6: 
                      7: #include "vm.h"
                      8: #include "bus.h"
1.1.1.3   root        9: #include "mainapp.h"
1.1       root       10: #include "mpu.h"
1.1.1.4   root       11: #include "mythread.h"
1.1       root       12: #include "ram.h"
                     13: #include "renderer.h"
1.1.1.6 ! root       14: #include "rtc.h"
1.1       root       15: #include "scheduler.h"
                     16: 
1.1.1.3   root       17: std::unique_ptr<VM> gVM;
1.1       root       18: 
                     19: // コンストラクタ
1.1.1.3   root       20: VM::VM()
1.1       root       21: {
                     22:        // どこでやるのがいいかわからんけど、このコンストラクタはメインスレッドで
                     23:        // 作られるので、ここでメインスレッドの名前を設定。
1.1.1.4   root       24:        PTHREAD_SETNAME("Main");
1.1       root       25: 
1.1.1.4   root       26:        // バスエラーデバイスだけここで作成。
1.1.1.3   root       27:        buserr.reset(new BusErrDevice());
1.1       root       28: 
                     29:        // まず全域をバスエラーで初期化。
                     30:        // この後継承先で必要に応じて上書きする。
                     31:        for (int i = 0; i < countof(::devtable); i++) {
1.1.1.3   root       32:                ::devtable[i] = buserr.get();
1.1       root       33:        }
                     34: }
                     35: 
                     36: // デストラクタ
                     37: VM::~VM()
                     38: {
1.1.1.4   root       39:        Dispose();
                     40: }
                     41: 
                     42: // 終了
                     43: void
                     44: VM::Dispose()
                     45: {
                     46:        if ((bool)gScheduler) {
                     47:                // スケジューラを停止。
                     48:                // スケジューラ(VMスレッド)からのアクセスさえなくなれば
                     49:                // 後の有象無象はグローバルデストラクタにお任せでもいいか。
                     50:                // だめだったらもっと頑張る。
                     51:                gScheduler->Terminate();
                     52:                gScheduler.reset();
                     53:        }
1.1       root       54: }
                     55: 
                     56: // コンストラクタ後の初期化
                     57: bool
                     58: VM::Create()
                     59: {
                     60:        for (const auto& d : gDevices) {
                     61:                if (!d->Create()) {
                     62:                        return false;
                     63:                }
                     64:        }
                     65: 
                     66:        return true;
                     67: }
                     68: 
                     69: // 初期化
                     70: bool
                     71: VM::Init()
                     72: {
                     73:        for (const auto& d : gDevices) {
                     74:                if (!d->Init()) {
                     75:                        return false;
                     76:                }
                     77:        }
                     78: 
                     79:        return true;
                     80: }
                     81: 
                     82: // 設定の適用
                     83: bool
                     84: VM::Apply()
                     85: {
                     86:        for (const auto& d : gDevices) {
                     87:                if (!d->Apply()) {
                     88:                        return false;
                     89:                }
                     90:        }
                     91: 
                     92:        return true;
                     93: }
                     94: 
                     95: // VM の全デバイスの電源をオン
                     96: bool
                     97: VM::DevicePowerOn()
                     98: {
1.1.1.6 ! root       99:        // 時刻開始
        !           100:        // RTC::PowerOn() でもいいかも知れないけど念のため全 PowerOn より先に。
        !           101:        if (!gRTC->InitRTC()) {
        !           102:                return false;
        !           103:        }
        !           104: 
1.1       root      105:        for (const auto& d : gDevices) {
                    106:                if (!d->PowerOn()) {
                    107:                        return false;
                    108:                }
                    109:        }
                    110: 
                    111:        // ハードウェアリセット
                    112:        ResetHard();
                    113: 
                    114:        // スケジューラを開始
                    115:        gScheduler->Run();
                    116: 
                    117:        return true;
                    118: }
                    119: 
                    120: // VM の全デバイスの電源をオフ
                    121: // (Scheduler から呼ばれる)
                    122: bool
                    123: VM::DevicePowerOff()
                    124: {
                    125:        for (const auto& d : gDevices) {
                    126:                if (!d->PowerOff()) {
                    127:                        return false;
                    128:                }
                    129:        }
                    130:        // GUI に通知
                    131:        if (poweroff_callback) {
                    132:                poweroff_callback();
                    133:        }
                    134:        return true;
                    135: }
                    136: 
                    137: // VM 電源オフ時のコールバックを設定する
                    138: void
                    139: VM::SetPowerOffCallback(void (*callback)())
                    140: {
                    141:        poweroff_callback = callback;
                    142: }
                    143: 
                    144: // ハードウェアリセット
                    145: void
                    146: VM::ResetHard()
                    147: {
                    148:        for (const auto& d : gDevices) {
                    149:                d->ResetHard();
                    150:        }
                    151: }

unix.superglobalmegacorp.com

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