func handle(conn net.Conn) { defer conn.Close() mouth := make([]m16arch.Byte, 4) hip := make([]byte, 8) mouth[0] = 2 for a, d := range tests { mouth[1] = m16arch.Byte(a) mouth[2] = m16arch.Byte(d) conn.Write(m16arch.To8Byte(mouth)) conn.Read(hip) } s := 256 mouth[0] = 1 mouth[2] = 0 for a, d := range tests { mouth[1] = m16arch.Byte(a) conn.Write(m16arch.To8Byte(mouth)) conn.Read(hip) out := m16arch.From8Byte(hip) if out[0] == d { s-- } } log.Printf("Failed test is %v times.\n", s) }
func readMem(addr m16arch.Byte) m16arch.Byte { date := []m16arch.Byte{0x1, m16arch.Byte(addr), 0, 0} d := m16arch.To8Byte(date) memcon.Write(d) memcon.Read(d) out := m16arch.From8Byte(d) return out[0] }
func main() { memcon = connect(*memplug) cpucon = connect(*cpuplug) for a, v := range bios { date := []m16arch.Byte{0x2, m16arch.Byte(a), m16arch.Byte(v), 0} d := m16arch.To8Byte(date) memcon.Write(d) memcon.Read(d) } for { in := make([]byte, 8) cpucon.Read(in) input := m16arch.From8Byte(in) out := make([]m16arch.Byte, 4) switch input[0] { case 1: out[0] = readMem(input[1]) } cpucon.Write(m16arch.To8Byte(out)) } }
func main() { flag.Parse() mem = make([]m16arch.Byte, *capacity) var conn net.Conn for { var err error conn, err = net.Dial("tcp", *plug) if err == nil { break } } log.Println("Connected!!") defer conn.Close() for { mouth := make([]byte, 8) out := make([]m16arch.Byte, 4) _, err := conn.Read(mouth) if err != nil { break } input := m16arch.From8Byte(mouth) switch input[0] { case 1: //Read out[0] = mem[input[1]] if *debug { log.Printf("Readed value from %x is %x", input[1], mem[input[1]]) } case 2: //Write mem[input[1]] = input[2] if *debug { log.Printf("Writed %x value to %x", input[2], input[1]) } } _, err = conn.Write(m16arch.To8Byte(out)) if err != nil { break } } }
func writeMem(addr, value m16arch.Byte) { date := []m16arch.Byte{0x2, m16arch.Byte(addr), m16arch.Byte(value), 0} d := m16arch.To8Byte(date) memcon.Write(d) memcon.Read(d) }
func readMem(addr m16arch.Byte) m16arch.Byte { conn.Write(m16arch.To8Byte([]m16arch.Byte{0x1, addr, 0x0, 0x0})) date := make([]byte, 8) conn.Read(date) return m16arch.From8Byte(date)[0] }