就職活動で提出する作品の関係でx86エミュレータをJavaからC#に移植中。上2つがJavaのコードで下2つがC#に直したコード。プロパティやインデクサを使っていけばいいのだろうか?C#はあまり使ってないのでよくわからん。C#版ではToStringはオーバーライドしてない
package vm.client.idt; public class InterruptDescriptor{ private int offset; private int selector; private int type; public InterruptDescriptor(byte[] memory, int index){ int offsetLow = ((memory[index + 1] & 0xFF) << 8) + (memory[index] & 0xFF); int selector = ((memory[index + 3] & 0xFF) << 8) + (memory[index + 2] & 0xFF); int type = memory[index + 5] & 0xFF; int offsetHigh = ((memory[index + 7] & 0xFF) << 8) + (memory[index + 6] & 0xFF); this.offset = (offsetHigh << 16) | offsetLow; this.selector = selector; this.type = type; } public int getOffset(){ return offset; } public int getSelector(){ return selector; } public int getType(){ return type; } public String toString(){ String str = "Offset = " + Integer.toHexString(offset); str += ", Selector = " + Integer.toHexString(selector); str += ", Type = " + Integer.toHexString(type); return str; } }
package vm.client.idt; public class IDT{ private InterruptDescriptor[] descriptors; public void lidt(byte[] buff, int start, int count){ count++; descriptors = new InterruptDescriptor[count]; for(int i = 0; i < count; i++){ descriptors[i] = new InterruptDescriptor(buff, start + (i * 8)); } } public InterruptDescriptor get(int index){ return descriptors[index]; } }
using System; namespace vm.idt { public class InterruptDescriptor { private Int32 offset; private Int32 selector; private Int32 type; public InterruptDescriptor(byte[] memory, Int32 index) { Int32 offsetLow = ((memory[index + 1] & 0xFF) << 8) + (memory[index] & 0xFF); Int32 selector = ((memory[index + 3] & 0xFF) << 8) + (memory[index + 2] & 0xFF); Int32 type = memory[index + 5] & 0xFF; Int32 offsetHigh = ((memory[index + 7] & 0xFF) << 8) + (memory[index + 6] & 0xFF); this.offset = (offsetHigh << 16) | offsetLow; this.selector = selector; this.type = type; } public Int32 Offset { get { return offset; } } public Int32 Selector { get { return selector; } } public Int32 Type { get { return type; } } } }
using System; namespace vm.idt { public class IDT { private InterruptDescriptor[] descriptors; public void lidt(byte[] buff, Int32 start, Int32 count) { count++; descriptors = new InterruptDescriptor[count]; for (Int32 i = 0; i < count; i++) { descriptors[i] = new InterruptDescriptor(buff, start + (i * 8)); } } public InterruptDescriptor this[Int32 index] { get { return descriptors[index]; } } } }