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

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

unix.superglobalmegacorp.com

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