Annotation of nono/vm/dipsw.cpp, revision 1.1.1.1

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
                     33: DipswDevice::Set(int n, bool val)
                     34: {
                     35:        assertmsg(0 <= n && n < dipsw.size(),
                     36:                "n=%d size=%zd: out of range", n, dipsw.size());
                     37: 
                     38:        dipsw[n] = val;
                     39: }
                     40: 
                     41: // 値を取得。true/false の意味は機種依存。
                     42: bool
                     43: DipswDevice::Get(int n) const
                     44: {
                     45:        assertmsg(0 <= n && n < dipsw.size(),
                     46:                "n=%d size=%zd: out of range", n, dipsw.size());
                     47: 
                     48:        return dipsw[n];
                     49: }
                     50: 
                     51: // 位置を設定。pos は 0 が上、1 が下。
                     52: void
                     53: DipswDevice::SetPosition(int n, int pos)
                     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
                     67: DipswDevice::GetPosition(int n) const
                     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:        if (inherited::Init() == false) {
                    123:                return false;
                    124:        }
                    125: 
                    126:        const ConfigItem& item1 = gConfig->Find("luna-dipsw1");
                    127:        const std::string& str1 = item1.AsString();
                    128:        if (str1.size() != 8) {
                    129:                item1.Err("must be 8 digits");
                    130:                return false;
                    131:        }
                    132: 
                    133:        const ConfigItem& item2 = gConfig->Find("luna-dipsw2");
                    134:        const std::string& str2 = item2.AsString();
                    135:        if (str2.size() != 8) {
                    136:                item2.Err("must be 8 digits");
                    137:                return false;
                    138:        }
                    139: 
                    140:        for (int i = 0; i < 8; i++) {
                    141:                dipsw[i]     = (str1[i] != '0');
                    142:                dipsw[i + 8] = (str2[i] != '0');
                    143:        }
                    144: 
                    145:        // LUNA-I/LUNA-88K とも DIP#1-1 を up(=true) で自動起動。
                    146:        bool val;
                    147:        const ConfigItem& item_autoboot = gConfig->Find("dipsw-autoboot");
                    148:        const std::string& autoboot = item_autoboot.AsString();
                    149:        if (autoboot.empty() == false) {
                    150:                if (autoboot == "yes") {
                    151:                        val = true;
                    152:                } else if (autoboot == "no") {
                    153:                        val = false;
                    154:                } else {
                    155:                        item_autoboot.Err();
                    156:                        return false;
                    157:                }
                    158:                dipsw[0] = val;
                    159:        }
                    160: 
                    161:        // LUNA-I/LUNA-88K とも DIP#1-2 を down(=false) でシリアルコンソール。
                    162:        const ConfigItem& item_serial = gConfig->Find("dipsw-serial");
                    163:        const std::string& serial = item_serial.AsString();
                    164:        if (serial.empty() == false) {
                    165:                if (serial == "yes") {
                    166:                        val = false;
                    167:                } else if (serial == "no") {
                    168:                        val = true;
                    169:                } else {
                    170:                        item_serial.Err();
                    171:                        return false;
                    172:                }
                    173:                dipsw[1] = val;
                    174:        }
                    175: 
                    176:        return true;
                    177: }
                    178: 
                    179: 
                    180: //
                    181: // DIPSW (NEWS)
                    182: //
                    183: 
                    184: // コンストラクタ
                    185: NewsDipswDevice::NewsDipswDevice()
                    186:        : inherited(8)
                    187: {
                    188:        // 上が false の方向。
                    189:        upside = false;
                    190: }
                    191: 
                    192: // デストラクタ
                    193: NewsDipswDevice::~NewsDipswDevice()
                    194: {
                    195: }
                    196: 
                    197: // 初期化
                    198: bool
                    199: NewsDipswDevice::Init()
                    200: {
                    201:        if (inherited::Init() == false) {
                    202:                return false;
                    203:        }
                    204: 
                    205:        const ConfigItem& item = gConfig->Find("news-dipsw");
                    206:        const std::string& str = item.AsString();
                    207:        if (str.size() != 8) {
                    208:                item.Err("Must be 8 digits");
                    209:                return false;
                    210:        }
                    211:        for (int i = 0; i < 8; i++) {
                    212:                dipsw[i] = (str[i] != '0');
                    213:        }
                    214: 
                    215:        // DIP5 オン(true)で自動起動。
                    216:        bool val;
                    217:        const ConfigItem& item_autoboot = gConfig->Find("dipsw-autoboot");
                    218:        const std::string& autoboot = item_autoboot.AsString();
                    219:        if (autoboot.empty() == false) {
                    220:                if (autoboot == "yes") {
                    221:                        val = true;
                    222:                } else if (autoboot == "no") {
                    223:                        val = false;
                    224:                } else {
                    225:                        item_autoboot.Err();
                    226:                        return false;
                    227:                }
                    228:                dipsw[4] = val;
                    229:        }
                    230: 
                    231:        // DIP1,2,3 すべてオフでシリアルコンソール。
                    232:        // シリアルコンソールでない場合はビデオカード/モニタを選択しないと
                    233:        // いけないが、とりあえず NWB-512 モノクロビデオカード(?) にしとく。
                    234:        const ConfigItem& item_serial = gConfig->Find("dipsw-serial");
                    235:        const std::string& serial = item_serial.AsString();
                    236:        if (serial.empty() == false) {
                    237:                if (serial == "yes") {
                    238:                        dipsw[0] = false;
                    239:                        dipsw[1] = false;
                    240:                        dipsw[2] = false;
                    241:                } else if (serial == "no") {
                    242:                        dipsw[0] = false;
                    243:                        dipsw[1] = false;
                    244:                        dipsw[2] = true;
                    245:                } else {
                    246:                        item_serial.Err();
                    247:                        return false;
                    248:                }
                    249:        }
                    250: 
                    251:        return true;
                    252: }

unix.superglobalmegacorp.com

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