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

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.7 ! root       27:        gBusErr.reset(new BusErrDevice());
1.1       root       28: 
                     29:        // まず全域をバスエラーで初期化。
                     30:        // この後継承先で必要に応じて上書きする。
                     31:        for (int i = 0; i < countof(::devtable); i++) {
1.1.1.7 ! root       32:                ::devtable[i] = gBusErr.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: {
1.1.1.7 ! root       60:        // d->Create() は gDevices に要素を追加する場合があるため、ここで
        !            61:        // ranged for は使えない。また追加されたデバイスの Create() も(念のため)
        !            62:        // 実行したいため、ループ終了条件で毎回 size() を取り出して比較する。
        !            63:        for (int i = 0; i < gDevices.size(); i++) {
        !            64:                Device *d = gDevices[i];
1.1       root       65:                if (!d->Create()) {
                     66:                        return false;
                     67:                }
                     68:        }
                     69: 
                     70:        return true;
                     71: }
                     72: 
                     73: // 初期化
                     74: bool
                     75: VM::Init()
                     76: {
                     77:        for (const auto& d : gDevices) {
                     78:                if (!d->Init()) {
                     79:                        return false;
                     80:                }
                     81:        }
                     82: 
                     83:        return true;
                     84: }
                     85: 
                     86: // 設定の適用
                     87: bool
                     88: VM::Apply()
                     89: {
                     90:        for (const auto& d : gDevices) {
                     91:                if (!d->Apply()) {
                     92:                        return false;
                     93:                }
                     94:        }
                     95: 
                     96:        return true;
                     97: }
                     98: 
1.1.1.7 ! root       99: // ブートページを切り替える (共通処理)
        !           100: // 派生クラスから呼ぶこと。
1.1       root      101: void
1.1.1.7 ! root      102: VM::SwitchBootPage(Device *parent, bool isrom)
1.1       root      103: {
1.1.1.7 ! root      104:        // ログ表示
        !           105:        if (isrom) {
        !           106:                parent->putlogf(1, lstr("SwitchBootPage ROM (Boot)"));
        !           107:        } else {
        !           108:                parent->putlogf(1, lstr("SwitchBootPage RAM (Normal)"));
1.1       root      109:        }
1.1.1.7 ! root      110: 
        !           111:        // スケジューラに指示
        !           112:        gScheduler->RequestBootPageMode(isrom);
1.1       root      113: }

unix.superglobalmegacorp.com

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