Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 115 lines (96 sloc) 3.754 kb
cbc8a4f7 »
2011-09-14 import
1 using System;
2 using System.Runtime.InteropServices;
13841f28 »
2011-09-18 add breakpoints
3 using System.IO;
d9d9a445 »
2011-10-02 Add log4net and fix a bug in the stack pushing too many bytes
4 using log4net;
24ed316d »
2011-10-24 Add new config system and make anything that uses memory make use of it
5 using x86CS.Configuration;
cbc8a4f7 »
2011-09-14 import
6
7 namespace x86CS
8 {
9 public class Memory
10 {
d9d9a445 »
2011-10-02 Add log4net and fix a bug in the stack pushing too many bytes
11 private static readonly ILog Logger = LogManager.GetLogger(typeof(Memory));
596f534d »
2011-10-08 switch to using a byte array for memory instead of using Marshal bloc…
12 private static readonly byte[] memory;
2718b948 »
2011-10-18 fix far jump/far call
13 public static bool LoggingEnabled = Logger.IsDebugEnabled;
df086a17 »
2011-09-24 implement protected mode and 32 bit instructions
14
a4171dc3 »
2011-09-26 Fix breakpoints and a jumps which were somewhat broken
15 public static bool A20 { get; set; }
8be87c4e »
2011-10-09 Checkpoint commit of the rewrite to use the BEAEngine disassembling l…
16 public static byte[] MemoryArray { get { return memory; } }
cbc8a4f7 »
2011-09-14 import
17
18 static Memory()
19 {
24ed316d »
2011-10-24 Add new config system and make anything that uses memory make use of it
20 memory = new byte[SystemConfig.Machine.MemorySize * 1024 * 1024];
cbc8a4f7 »
2011-09-14 import
21 }
22
3fec5fd5 »
2011-09-16 Fix cpu register access
23 public static void SegBlockWrite(ushort segment, ushort offset, byte[] buffer, int length)
24 {
4abfe41c »
2011-09-25 Run through resharper
25 var virtualPtr = (uint)((segment << 4) + offset);
13841f28 »
2011-09-18 add breakpoints
26
d9d9a445 »
2011-10-02 Add log4net and fix a bug in the stack pushing too many bytes
27 Memory.BlockWrite(virtualPtr, buffer, length);
3fec5fd5 »
2011-09-16 Fix cpu register access
28 }
29
3201ed51 »
2011-09-22 rewrite the decoder and split it up into more parts
30 public static void BlockWrite(uint addr, byte[] buffer, int length)
cbc8a4f7 »
2011-09-14 import
31 {
2718b948 »
2011-10-18 fix far jump/far call
32 if(LoggingEnabled)
3dc970b5 »
2011-10-15 conditional logging of memory only when set to debug
33 Logger.Debug(String.Format("Block write {0:X} length {1:X} ends {2:X}", addr, length, addr + length));
13841f28 »
2011-09-18 add breakpoints
34
ff5c8992 »
2011-10-08 more performance enhancements for memory, i don't really see how memo…
35 Buffer.BlockCopy(buffer, 0, memory, (int)addr, length);
cbc8a4f7 »
2011-09-14 import
36 }
37
3201ed51 »
2011-09-22 rewrite the decoder and split it up into more parts
38 public static int BlockRead(uint addr, byte[] buffer, int length)
3fec5fd5 »
2011-09-16 Fix cpu register access
39 {
50d6e246 »
2011-10-08 Apparently Buffer.BlockCopy is faster than array.copy
40 Buffer.BlockCopy(memory, (int)addr, buffer, 0, length);
3fec5fd5 »
2011-09-16 Fix cpu register access
41
2718b948 »
2011-10-18 fix far jump/far call
42 if(LoggingEnabled)
3dc970b5 »
2011-10-15 conditional logging of memory only when set to debug
43 Logger.Debug(String.Format("Block read {0:X} length {1:X} ends {2:X}", addr, length, addr + length));
13841f28 »
2011-09-18 add breakpoints
44
3fec5fd5 »
2011-09-16 Fix cpu register access
45 return buffer.Length;
46 }
47
38fb166e »
2011-10-11 remove beaengine as performance wasnt as good as expected, start to r…
48 public static uint Read(uint addr, int size)
cbc8a4f7 »
2011-09-14 import
49 {
3dc970b5 »
2011-10-15 conditional logging of memory only when set to debug
50 uint ret;
fd5db889 »
2011-10-18 Add NEG, JS, JNS, SETZ, SETNZ, LEAVE, SAR, SHRD, CPUID
51 bool passedMem = false;
52
24ed316d »
2011-10-24 Add new config system and make anything that uses memory make use of it
53 if (addr > MemoryArray.Length)
fd5db889 »
2011-10-18 Add NEG, JS, JNS, SETZ, SETNZ, LEAVE, SAR, SHRD, CPUID
54 passedMem = true;
3dc970b5 »
2011-10-15 conditional logging of memory only when set to debug
55
38fb166e »
2011-10-11 remove beaengine as performance wasnt as good as expected, start to r…
56 switch (size)
57 {
58 case 8:
fd5db889 »
2011-10-18 Add NEG, JS, JNS, SETZ, SETNZ, LEAVE, SAR, SHRD, CPUID
59 if (passedMem)
60 ret = 0xff;
61 else
62 ret = memory[addr];
3dc970b5 »
2011-10-15 conditional logging of memory only when set to debug
63 break;
38fb166e »
2011-10-11 remove beaengine as performance wasnt as good as expected, start to r…
64 case 16:
fd5db889 »
2011-10-18 Add NEG, JS, JNS, SETZ, SETNZ, LEAVE, SAR, SHRD, CPUID
65 if (passedMem)
66 ret = 0xffff;
67 else
68 ret = (ushort)(memory[addr] | memory[addr + 1] << 8);
3dc970b5 »
2011-10-15 conditional logging of memory only when set to debug
69 break;
38fb166e »
2011-10-11 remove beaengine as performance wasnt as good as expected, start to r…
70 default:
fd5db889 »
2011-10-18 Add NEG, JS, JNS, SETZ, SETNZ, LEAVE, SAR, SHRD, CPUID
71 if (passedMem)
72 ret = 0xffffffff;
73 else
74 ret = (uint)(memory[addr] | memory[addr + 1] << 8 | memory[addr + 2] << 16 | memory[addr + 3] << 24);
3dc970b5 »
2011-10-15 conditional logging of memory only when set to debug
75 break;
38fb166e »
2011-10-11 remove beaengine as performance wasnt as good as expected, start to r…
76 }
930fcfe4 »
2011-10-18 Add CBW, LES
77
2718b948 »
2011-10-18 fix far jump/far call
78 if(LoggingEnabled)
fd5db889 »
2011-10-18 Add NEG, JS, JNS, SETZ, SETNZ, LEAVE, SAR, SHRD, CPUID
79 Logger.Debug(String.Format("Read {0} address {1:X} value {2:X}{3}", size, addr, ret, passedMem ? " (OverRead)" : ""));
3dc970b5 »
2011-10-15 conditional logging of memory only when set to debug
80
81 return ret;
7f495499 »
2011-09-18 more opcodes
82 }
83
b812e167 »
2011-10-12 add compare
84 public static void Write(uint addr, uint value, int size)
cbc8a4f7 »
2011-09-14 import
85 {
24ed316d »
2011-10-24 Add new config system and make anything that uses memory make use of it
86 if (addr > MemoryArray.Length)
fd5db889 »
2011-10-18 Add NEG, JS, JNS, SETZ, SETNZ, LEAVE, SAR, SHRD, CPUID
87 {
2718b948 »
2011-10-18 fix far jump/far call
88 if(LoggingEnabled)
89 Logger.Debug(String.Format("Write {0} address {1:X} value {2:X} (OverWrite, ignored)", size, addr, value));
fd5db889 »
2011-10-18 Add NEG, JS, JNS, SETZ, SETNZ, LEAVE, SAR, SHRD, CPUID
90 return;
91 }
92
2718b948 »
2011-10-18 fix far jump/far call
93 if (LoggingEnabled)
3dc970b5 »
2011-10-15 conditional logging of memory only when set to debug
94 Logger.Debug(String.Format("Write {0} address {1:X} value {2:X}", size, addr, value));
95
b812e167 »
2011-10-12 add compare
96 switch (size)
97 {
98 case 8:
99 memory[addr] = (byte)value;
100 break;
101 case 16:
102 memory[addr] = (byte)value;
103 memory[addr + 1] = (byte)((ushort)value).GetHigh();
104 break;
105 default:
106 memory[addr] = (byte)value;
107 memory[addr + 1] = (byte)(value >> 8);
108 memory[addr + 2] = (byte)(value >> 16);
109 memory[addr + 3] = (byte)(value >> 24);
110 break;
111 }
df086a17 »
2011-09-24 implement protected mode and 32 bit instructions
112 }
cbc8a4f7 »
2011-09-14 import
113 }
114 }
Something went wrong with that request. Please try again.