Annotation of nono/vm/sio.cpp, revision 1.1.1.8

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 "sio.h"
1.1.1.5   root        8: #include "interrupt.h"
1.1.1.8 ! root        9: #include "keyboard.h"
1.1       root       10: 
                     11: //          IODevice
                     12: //              |
                     13: //              v
                     14: //        upd7201Device  (uPD7201 と Z8530 の共通部分)
                     15: //              |
                     16: //    +---------+----------+
                     17: //    v                    v
                     18: // SIODevice           SCCDevice
                     19: // (LUNA, uPD7201)     (X68030, Z8530)
                     20: 
1.1.1.3   root       21: std::unique_ptr<SIODevice> gSIO;
1.1       root       22: 
                     23: SIODevice::SIODevice()
1.1.1.7   root       24:        : inherited("SIO")
1.1       root       25: {
                     26:        devaddr = 0x51000000;
                     27: 
                     28:        cr.chan[0].desc = "Serial Console";
                     29:        cr.chan[1].desc = "Keyboard";
1.1.1.7   root       30: 
1.1.1.8 ! root       31:        // 153.6kHz = 6.510416...usec / bit;
        !            32:        // 12bit = 78.125usec
        !            33:        txc12_ns = 78.125_usec;
        !            34: 
1.1.1.7   root       35:        // LUNA では SIO と呼ぶほうが通りがいい。
1.1.1.8 ! root       36:        for (int ch = 0; ch < txevent.size(); ch++) {
        !            37:                txevent[ch].SetName(string_format("SIO Ch%s TX", cr.chan[ch].name));
        !            38:        }
1.1.1.7   root       39:        monitor.Regist(ID_MONITOR_SIO);
1.1       root       40: }
                     41: 
                     42: SIODevice::~SIODevice()
                     43: {
                     44: }
                     45: 
                     46: uint64
1.1.1.6   root       47: SIODevice::Read(uint32 offset)
1.1       root       48: {
                     49:        uint32 data;
                     50: 
1.1.1.6   root       51:        switch (offset) {
1.1       root       52:         case 0:
1.1.1.3   root       53:                data = ReadData(&cr.chan[0]);
1.1       root       54:                break;
                     55:         case 1:
                     56:                data = ReadCtrl(&cr.chan[0]);
                     57:                break;
                     58:         case 2:
1.1.1.3   root       59:                data = ReadData(&cr.chan[1]);
1.1       root       60:                break;
                     61:         case 3:
                     62:                data = ReadCtrl(&cr.chan[1]);
                     63:                break;
                     64:         default:
                     65:                __unreachable();
                     66:        }
                     67:        return data;
                     68: }
                     69: 
                     70: uint64
1.1.1.6   root       71: SIODevice::Write(uint32 offset, uint32 data)
1.1       root       72: {
1.1.1.6   root       73:        switch (offset) {
1.1       root       74:         case 0:
                     75:                WriteData(&cr.chan[0], data);
                     76:                return 0;
                     77: 
                     78:         case 1:
                     79:                WriteCtrl(&cr.chan[0], data);
                     80:                return 0;
                     81: 
                     82:         case 2:
                     83:                WriteData(&cr.chan[1], data);
                     84:                return 0;
                     85: 
                     86:         case 3:
                     87:                WriteCtrl(&cr.chan[1], data);
                     88:                return 0;
                     89:        }
                     90:        __unreachable();
                     91: }
                     92: 
                     93: uint64
1.1.1.6   root       94: SIODevice::Peek(uint32 offset)
1.1       root       95: {
1.1.1.6   root       96:        switch (offset) {
1.1.1.3   root       97:         case 0:
                     98:                return PeekData(&cr.chan[0]);
                     99: 
                    100:         case 1:
                    101:                return PeekCtrl(&cr.chan[0]);
                    102: 
                    103:         case 2:
                    104:                return PeekData(&cr.chan[1]);
                    105: 
                    106:         case 3:
                    107:                return PeekCtrl(&cr.chan[1]);
                    108:        }
                    109:        __unreachable();
1.1       root      110: }
                    111: 
                    112: // 割り込みを上げる
                    113: void
                    114: SIODevice::Interrupt()
                    115: {
                    116:        putlog(2, "Interrupt");
1.1.1.5   root      117:        gInterrupt->AssertINT(this);
1.1       root      118: }
1.1.1.8 ! root      119: 
        !           120: void
        !           121: SIODevice::Tx(int ch, uint32 data)
        !           122: {
        !           123:        switch (ch) {
        !           124:         case 0:
        !           125:                // TODO: シリアル送信処理
        !           126:                break;
        !           127:         case 1:
        !           128:                gKeyboard->Command(data);
        !           129:                break;
        !           130:         default:
        !           131:                __unreachable();
        !           132:        }
        !           133: }

unix.superglobalmegacorp.com

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