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