Annotation of nono/wx/wxdumpmonitor.cpp, revision 1.1.1.4

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 "wxdumpmonitor.h"
                      8: #include "wxtextscreen.h"
                      9: #include "mystring.h"
                     10: #include "bus.h"
                     11: 
                     12: //
                     13: // メモリダンプウィンドウ
                     14: //
                     15: 
                     16: enum {
                     17:        ID_TEXT,
                     18:        ID_PREV,
                     19:        ID_NEXT,
                     20: };
                     21: 
                     22: // イベントテーブル
                     23: wxBEGIN_EVENT_TABLE(WXMemdumpWindow, inherited)
                     24:        EVT_TEXT_ENTER(ID_TEXT, WXMemdumpWindow::OnTextEnter)
                     25:        EVT_BUTTON(ID_PREV, WXMemdumpWindow::OnPrev)
                     26:        EVT_BUTTON(ID_NEXT, WXMemdumpWindow::OnNext)
                     27:        EVT_TIMER(wxID_ANY, WXMemdumpWindow::OnTimer)
                     28: wxEND_EVENT_TABLE()
                     29: 
                     30: // コンストラクタ
                     31: WXMemdumpWindow::WXMemdumpWindow(wxWindow *parent, wxWindowID id)
1.1.1.4 ! root       32:        : inherited(parent, id, _("Memory Dump"))
1.1       root       33: {
                     34:        col = 76;
                     35:        row = 16;
                     36:        // 最初に不一致を起こさせて再描画させるため
                     37:        last_addr = 0xffffffff;
                     38: 
1.1.1.4 ! root       39:        wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
1.1       root       40:        wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
                     41: 
                     42:        // 上枠
                     43:        wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
                     44:        vbox->Add(hbox);
                     45: 
                     46:        // アドレスコントロール
                     47:        addrctrl = new wxTextCtrl(this, ID_TEXT,
                     48:                wxEmptyString, wxDefaultPosition, wxDefaultSize,
                     49:                wxTE_PROCESS_ENTER);
                     50:        hbox->Add(addrctrl);
                     51:        hbox->AddSpacer(20);
                     52: 
                     53:        // △ボタン
                     54:        // XXX とりあえずね
                     55:        prev_btn = new wxButton(this, ID_PREV, wxT("△"));
                     56:        next_btn = new wxButton(this, ID_NEXT, wxT("▽"));
                     57:        hbox->Add(prev_btn);
                     58:        hbox->Add(next_btn);
                     59: 
                     60:        // XXX TODO 初期フォーカスをテキストコントロールに移したい
                     61: 
                     62:        // テキストスクリーン
                     63:        monitor.Init(col, row);
                     64:        screen = new WXTextScreen(this, col, row, monitor.GetBuf());
                     65:        vbox->Add(screen, 0, wxEXPAND);
                     66: 
1.1.1.4 ! root       67:        topsizer->Add(vbox, BorderFlags);
        !            68:        SetSizer(topsizer);
1.1       root       69: 
                     70:        Layout();
                     71:        Fit();
                     72: 
                     73:        // メモリが高速で変わるのを目で追う必要もないと思うので
                     74:        // 30Hz くらいでどうか。
                     75:        timer.SetOwner(this);
                     76:        timer.Start(33);
                     77: }
                     78: 
                     79: // デストラクタ
                     80: WXMemdumpWindow::~WXMemdumpWindow()
                     81: {
                     82: }
                     83: 
                     84: // テキスト入力イベント
                     85: void
                     86: WXMemdumpWindow::OnTextEnter(wxCommandEvent& event)
                     87: {
                     88:        // 入力文字列(16進文字列)を数値に変換
                     89:        wxString wstr = event.GetString();
                     90:        const char *cstr = (const char *)wstr.mb_str();
                     91:        uint32 val = strtoul(cstr, NULL, 16);
                     92: 
                     93:        // 16 に整列
                     94:        val &= ~15;
                     95: 
                     96:        input_addr = val;
                     97: }
                     98: 
                     99: // △(PREV) ボタン押下イベント
                    100: void
                    101: WXMemdumpWindow::OnPrev(wxCommandEvent& event)
                    102: {
                    103:        input_addr -= 0x100;
                    104: }
                    105: 
                    106: // ▽(NEXT) ボタン押下イベント
                    107: void
                    108: WXMemdumpWindow::OnNext(wxCommandEvent& event)
                    109: {
                    110:        input_addr += 0x100;
                    111: }
                    112: 
                    113: // タイマーイベント
                    114: void
                    115: WXMemdumpWindow::OnTimer(wxTimerEvent& event)
                    116: {
                    117:        if (input_addr != last_addr) {
                    118:                // EVT_TEXT を起こさず変更する
                    119:                addrctrl->ChangeValue(wxString(string_format("%08x", input_addr)));
                    120:                last_addr = input_addr;
                    121: 
                    122:                // カーソルを末尾に
                    123:                addrctrl->SetInsertionPointEnd();
                    124:        }
                    125: 
                    126:        // テキストスクリーンを更新
                    127:        Update();
                    128:        screen->Refresh();
                    129: }
                    130: 
                    131: // フォントサイズ変更
                    132: void
                    133: WXMemdumpWindow::SetFontSize(fontsize_t fontsize)
                    134: {
                    135:        screen->SetFontSize(fontsize);
                    136: 
                    137:        Layout();
                    138:        Fit();
                    139: }
                    140: 
                    141: // テキストスクリーンを更新
                    142: void
                    143: WXMemdumpWindow::Update()
                    144: {
                    145:        uint32 laddr;
                    146:        uint64 paddr;
                    147: 
                    148:        monitor.Clear();
                    149: 
                    150:        laddr = input_addr;
                    151:        paddr = 0;      // shut up gcc
                    152:        for (int y = 0; y < row; y++) {
                    153:                if (is_logical) {
                    154:                } else {
                    155:                        // 物理アドレス
                    156:                        paddr = laddr;
                    157:                }
                    158: 
                    159:                // アドレス作成
                    160:                std::string addrstr = string_format("%08x", laddr);
                    161:                if (is_logical == false) {
                    162:                        // 物理アドレス
                    163:                        addrstr += ":";
                    164:                } else if ((int64)paddr < 0) {
                    165:                        // MMU 時点でバスエラー
                    166:                        addrstr += ":BusErr";
                    167:                } else if (paddr == laddr) {
                    168:                        // PA==VA
                    169:                        addrstr += "=PA";
                    170:                } else {
                    171:                        // PA!=VA
                    172:                        addrstr += string_format(":%08x:", (uint32)paddr);
                    173:                }
                    174:                monitor.Print(0, y, "%s", addrstr.c_str());
                    175: 
                    176:                // ダンプ作成
                    177:                std::string hexstr;
                    178:                std::string chrstr;
                    179:                for (int x = 0; x < 8; x++) {
1.1.1.3   root      180:                        uint64 b1 = vm_phys_peek_8(paddr);
                    181:                        uint64 b2 = vm_phys_peek_8(paddr + 1);
1.1       root      182: 
                    183:                        // 偶数バイト目
                    184:                        if ((int64)b1 < 0) {
                    185:                                hexstr += "--";
                    186:                                chrstr += " ";
                    187:                        } else {
                    188:                                uint32 c1 = (uint32)b1;
                    189:                                hexstr += string_format("%02x", c1);
                    190:                                chrstr += string_format("%c",
                    191:                                        (0x20 <= c1 && c1 <= 0x7e) ? c1 : '.');
                    192:                        }
                    193:                        // 奇数バイト目
                    194:                        if ((int64)b2 < 0) {
                    195:                                hexstr += "--";
                    196:                                chrstr += " ";
                    197:                        } else {
                    198:                                uint32 c2 = (uint32)b2;
                    199:                                hexstr += string_format("%02x", c2);
                    200:                                chrstr += string_format("%c",
                    201:                                        (0x20 <= c2 && c2 <= 0x7e) ? c2 : '.');
                    202:                        }
                    203:                        hexstr += " ";
                    204: 
                    205:                        laddr += 2;
                    206:                        paddr += 2;
                    207:                }
                    208: 
                    209:                monitor.Print(19, y, "%s", hexstr.c_str());
                    210:                monitor.Print(60, y, "%s", chrstr.c_str());
                    211:        }
                    212: }

unix.superglobalmegacorp.com

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