|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2022 nono project
4: // Licensed under nono-license.txt
5: //
6:
7: //
8: // DIPSW
9: //
10:
11: #include "dipsw.h"
12: #include "config.h"
13: #include "mainapp.h"
14:
15: //
16: // DIPSW 共通クラス
17: //
18:
19: // コンストラクタ
20: DipswDevice::DipswDevice(int size_)
21: : inherited(OBJ_DIPSW)
22: {
23: dipsw.resize(size_);
24: }
25:
26: // デストラクタ
27: DipswDevice::~DipswDevice()
28: {
29: }
30:
31: // 値を設定。true/false の意味は機種依存。
32: void
1.1.1.2 root 33: DipswDevice::Set(uint n, bool val)
1.1 root 34: {
1.1.1.2 root 35: assertmsg(n < dipsw.size(),
36: "n=%u size=%zu: out of range", n, dipsw.size());
1.1 root 37:
38: dipsw[n] = val;
39: }
40:
41: // 値を取得。true/false の意味は機種依存。
42: bool
1.1.1.2 root 43: DipswDevice::Get(uint n) const
1.1 root 44: {
1.1.1.2 root 45: assertmsg(n < dipsw.size(),
46: "n=%u size=%zu: out of range", n, dipsw.size());
1.1 root 47:
48: return dipsw[n];
49: }
50:
51: // 位置を設定。pos は 0 が上、1 が下。
52: void
1.1.1.2 root 53: DipswDevice::SetPosition(uint n, uint pos)
1.1 root 54: {
55: bool val;
56:
57: if (upside == true) {
58: val = (pos == 0) ? true : false;
59: } else {
60: val = (pos == 0) ? false : true;
61: }
62: Set(n, val);
63: }
64:
65: // 位置を取得。戻り値は 0 が上、1 が下。
66: int
1.1.1.2 root 67: DipswDevice::GetPosition(uint n) const
1.1 root 68: {
69: bool val = Get(n);
70: int pos;
71:
72: if (upside == true) {
73: pos = (val ? 0 : 1);
74: } else {
75: pos = (val ? 1 : 0);
76: }
77: return pos;
78: }
79:
80:
81: //
82: // DIPSW (LUNA)
83: //
84:
85: // LUNA の DIPSW は #1, #2 にそれぞれ8個、計16個ある。
86: // DIPSW #1, #2 が設定ファイルの luna-dipsw{1,2} に対応する。
87: // luna-dipsw{1,2} はいずれも "0"/"1" を8つ並べた文字列であり、
88: // 先頭が本体表記でいう 1番、末尾側が本体表記でいう 8番に対応する。
89: // 値は "0" が down、"1" が up を表す。
90: //
91: // DipswDevice 内ではこの設定を読み込んで dipsw[0..15] として保持している。
92: // dipsw[0] が本体表記 #1-1 番、dipsw[15] が本体表記 #2-8 番に対応する。
93: // 値は false が down("0")、true が up("1") に対応する。
94:
95: // コンストラクタ
96: LunaDipswDevice::LunaDipswDevice()
97: : inherited(16)
98: {
99: // 上が true の方向。
100: upside = true;
101:
102: // LUNA-I と LUNA-88K で使いやすいように初期値を変えておく。
103: if (gMainApp.IsLUNA1()) {
104: gConfig->SetDefault("luna-dipsw1", "11110111");
105: } else {
106: gConfig->SetDefault("luna-dipsw1", "11111111");
107: }
108:
109: // DIPSW#2 はユーザ定義(?)なので(今の所?)どちらも共通。
110: gConfig->SetDefault("luna-dipsw2", "11111111");
111: }
112:
113: // デストラクタ
114: LunaDipswDevice::~LunaDipswDevice()
115: {
116: }
117:
118: // 初期化
119: bool
120: LunaDipswDevice::Init()
121: {
122: const ConfigItem& item1 = gConfig->Find("luna-dipsw1");
123: const std::string& str1 = item1.AsString();
124: if (str1.size() != 8) {
125: item1.Err("must be 8 digits");
126: return false;
127: }
128:
129: const ConfigItem& item2 = gConfig->Find("luna-dipsw2");
130: const std::string& str2 = item2.AsString();
131: if (str2.size() != 8) {
132: item2.Err("must be 8 digits");
133: return false;
134: }
135:
136: for (int i = 0; i < 8; i++) {
137: dipsw[i] = (str1[i] != '0');
138: dipsw[i + 8] = (str2[i] != '0');
139: }
140:
141: // LUNA-I/LUNA-88K とも DIP#1-1 を up(=true) で自動起動。
142: bool val;
143: const ConfigItem& item_autoboot = gConfig->Find("dipsw-autoboot");
144: const std::string& autoboot = item_autoboot.AsString();
145: if (autoboot.empty() == false) {
146: if (autoboot == "yes") {
147: val = true;
148: } else if (autoboot == "no") {
149: val = false;
150: } else {
151: item_autoboot.Err();
152: return false;
153: }
154: dipsw[0] = val;
155: }
156:
157: // LUNA-I/LUNA-88K とも DIP#1-2 を down(=false) でシリアルコンソール。
158: const ConfigItem& item_serial = gConfig->Find("dipsw-serial");
159: const std::string& serial = item_serial.AsString();
160: if (serial.empty() == false) {
161: if (serial == "yes") {
162: val = false;
163: } else if (serial == "no") {
164: val = true;
165: } else {
166: item_serial.Err();
167: return false;
168: }
169: dipsw[1] = val;
170: }
171:
172: return true;
173: }
174:
175:
176: //
177: // DIPSW (NEWS)
178: //
179:
180: // コンストラクタ
181: NewsDipswDevice::NewsDipswDevice()
182: : inherited(8)
183: {
184: // 上が false の方向。
185: upside = false;
186: }
187:
188: // デストラクタ
189: NewsDipswDevice::~NewsDipswDevice()
190: {
191: }
192:
193: // 初期化
194: bool
195: NewsDipswDevice::Init()
196: {
197: const ConfigItem& item = gConfig->Find("news-dipsw");
198: const std::string& str = item.AsString();
199: if (str.size() != 8) {
200: item.Err("Must be 8 digits");
201: return false;
202: }
203: for (int i = 0; i < 8; i++) {
204: dipsw[i] = (str[i] != '0');
205: }
206:
207: // DIP5 オン(true)で自動起動。
208: bool val;
209: const ConfigItem& item_autoboot = gConfig->Find("dipsw-autoboot");
210: const std::string& autoboot = item_autoboot.AsString();
211: if (autoboot.empty() == false) {
212: if (autoboot == "yes") {
213: val = true;
214: } else if (autoboot == "no") {
215: val = false;
216: } else {
217: item_autoboot.Err();
218: return false;
219: }
220: dipsw[4] = val;
221: }
222:
223: // DIP1,2,3 すべてオフでシリアルコンソール。
224: // シリアルコンソールでない場合はビデオカード/モニタを選択しないと
225: // いけないが、とりあえず NWB-512 モノクロビデオカード(?) にしとく。
226: const ConfigItem& item_serial = gConfig->Find("dipsw-serial");
227: const std::string& serial = item_serial.AsString();
228: if (serial.empty() == false) {
229: if (serial == "yes") {
230: dipsw[0] = false;
231: dipsw[1] = false;
232: dipsw[2] = false;
233: } else if (serial == "no") {
234: dipsw[0] = false;
235: dipsw[1] = false;
236: dipsw[2] = true;
237: } else {
238: item_serial.Err();
239: return false;
240: }
241: }
242:
243: return true;
244: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.