C_Sharp 板


LINE

https://www.dropbox.com/s/cit9jl96hzg4lui/Apr8086-needcheck0907.zip?dl=0 這是老電腦 8086的模擬器初步實作 目前只能算是完成CPU的部分(極少數指令尚未完成) 要問的是一個跟模擬器實作層面無關的問題 應該確認是編譯器或是 .net framework潛在的bug 只要在專案 x86\CPU.cs 裡頭的 cpu_exec() 內加入 debug_inf = Reg_B.X.ToString() + Reg_C.X.ToString(); 這樣一行 ln 266 (目前觀察到只要對register物件內容有ToString()的動作或是相關字串操作 就很容易有問題) x86\CPU.cs cpu_exec() switch case 0x83: 內的 MessageBox.show 內容 ln 2418開始下面幾行 就會從 a:0 4 b:4 c:4 d:04 e:00 f: 0400 變成 a:0 4 b:4 c:4 d:00 e:00 f: 0000 (測試方式可以啟動程式UI後,點擊 DEBUG 的 button 就會測試運作 , MessageBox到 f: 後就可以把程式關閉掉) 實際上目前是簡化問題 , 有時候a b c裡頭的value 會隨著開啟程式時間不同, 跳亂數...... (前面幾次開關城市 測試 a: b: c: 內容都正常,有可能哪次突然跳亂數) 由於開發需要檢測每次執行指令各register狀態,甚至輸出log,之前撰寫GameBoy 也是用一樣的方式輸出各register內容, 沒任何問題,但這次有使用到指標與比較進階的struct [StructLayout(LayoutKind.Explicit, Size = 2)] struct RegWord { [FieldOffset(1)] public byte H; //heigh byte [FieldOffset(0)] public byte L; //low byte [FieldOffset(0)] public ushort X; //word } 除了編譯器或是 .net framework本身bug外,想不出別的理由.... 資訊更新一:應該跟指標的使用問題有關係 但應該不是我的問題 後來把 Main.cs 中 fixed (ushort* p = &Reg_ES) { Table_SegRegs[0] = p; } fixed (ushort* p = &Reg_CS) { Table_SegRegs[1] = p; } fixed (ushort* p = &Reg_SS) { Table_SegRegs[2] = p; } fixed (ushort* p = &Reg_DS) { Table_SegRegs[3] = p; } fixed (ushort* p = &Reg_A.X) { Table_WordRegs[0] = p; } fixed (ushort* p = &Reg_C.X) { Table_WordRegs[1] = p; } fixed (ushort* p = &Reg_D.X) { Table_WordRegs[2] = p; } fixed (ushort* p = &Reg_B.X) { Table_WordRegs[3] = p; } fixed (ushort* p = &Reg_SP) { Table_WordRegs[4] = p; } fixed (ushort* p = &Reg_BP) { Table_WordRegs[5] = p; } fixed (ushort* p = &Reg_SI) { Table_WordRegs[6] = p; } fixed (ushort* p = &Reg_DI) { Table_WordRegs[7] = p; } fixed (byte* P = &Reg_A.L) { Table_ByteRegs[0] = P; } fixed (byte* P = &Reg_C.L) { Table_ByteRegs[1] = P; } fixed (byte* P = &Reg_D.L) { Table_ByteRegs[2] = P; } fixed (byte* P = &Reg_B.L) { Table_ByteRegs[3] = P; } fixed (byte* P = &Reg_A.H) { Table_ByteRegs[4] = P; } fixed (byte* P = &Reg_C.H) { Table_ByteRegs[5] = P; } fixed (byte* P = &Reg_D.H) { Table_ByteRegs[6] = P; } fixed (byte* P = &Reg_B.H) { Table_ByteRegs[7] = P; } 這種寫法除掉改用別方式來處理register解碼與對應 就ok了 改用下面這種方式 但直接靠array來mapping指標操作解碼對應 不知到快了 switch有多少倍去.... byte Table_ByteRegsGet(int reg) { switch (reg) { case 0: return Reg_A.L; case 1: return Reg_C.L; case 2: return Reg_D.L; case 3: return Reg_B.L; case 4: return Reg_A.H; case 5: return Reg_C.H; case 6: return Reg_D.H; case 7: return Reg_B.H; } return 0; } void Table_ByteRegsSet(int reg, byte val) { switch (reg) { case 0: Reg_A.L = val; break; case 1: Reg_C.L = val; break; case 2: Reg_D.L = val; break; case 3: Reg_B.L = val; break; case 4: Reg_A.H = val; break; case 5: Reg_C.H = val; break; case 6: Reg_D.H = val; break; case 7: Reg_B.H = val; break; } } --



※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.254.20.56
※ 文章網址: https://webptt.com/m.aspx?n=bbs/C_Sharp/M.1473217109.A.BD5.html ※ 編輯: erspicu (60.248.56.181), 09/07/2016 16:39:20 ※ 編輯: erspicu (60.248.56.181), 09/07/2016 16:45:57
1F:→ fo40225: 你在fixed區塊內把指標的值保留在陣列裡 出了fixed 09/08 00:49
2F:→ fo40225: 那個位址值就不保證了 只要GC一動作 你的指標就廢了 09/08 00:49
3F:→ fo40225: ToString() 會配置物件 很容易觸發0代GC 09/08 00:49
4F:→ fo40225: 使用vs 偵錯 視窗 記憶體 把位址打上去 在init後下斷點 09/08 00:51
5F:→ fo40225: init最後面寫個迴圈 new object() 然後觀察迴圈前後 09/08 00:53
6F:→ fo40225: 陣列裡所記錄的位址 記憶體會被改變的 09/08 00:54
對喔 fixed {} 的目的應該就是為了確保在某區塊範圍內指標使用的正確性 出了範圍就不一定了... 但總是覺得這樣有點不合理 照理來說物件生成後指標應該就是固定了 但因為GC特性 指標會被改變掉 這種用ARRAY塞指標 來達成快速解碼對應的方式是參考 C專案來的 看來在C#行不通 用其他的hash物件或是siwtch達成雖可行 但就是沒array操控指標方便 以後再看看更好的方式 感謝.. ※ 編輯: erspicu (36.239.98.135), 09/08/2016 10:27:29
7F:推 Litfal: C#不太適合處理這種實值指標、或是需要很精確控制記憶體 09/09 15:55
8F:→ Litfal: 的狀況 09/09 15:55







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:Tech_Job站內搜尋

TOP