Пример #1
0
func runDebugger() {
	flag.Parse()
	path := flag.Arg(1)
	if path == "" {
		printHelp("debug")
		return
	}

	file, err := os.Open(path)
	assert(err)

	dcpu := emulator.NewDCPU()
	ram := words.NewReadWriter(dcpu.RAM)
	_, err = io.Copy(ram, file)
	file.Close()
	assert(err)

	in := bufio.NewReader(os.Stdin)
	for {
		fmt.Print("(d) ")
		buf, _, err := in.ReadLine()
		line := string(buf)
		if err == io.EOF {
			return
		}
		assert(err)

		switch line {
		case "quit":
			return
		case "step":
			err := dcpu.Step()
			if err != nil {
				fmt.Println("dcpu err: ", err)
			}
		case "steploop":
			err := debugger.StepLoop(dcpu)
			if err != nil {
				fmt.Println("dcpu err: ", err)
			}
		case "stepjmp":
			err := debugger.StepJmp(dcpu)
			if err != nil {
				fmt.Println("dcpu err: ", err)
			}
		case "mem":
			words.Hexdump(dcpu.RAM, os.Stdout)
		case "r":
			debugger.RDump(dcpu)
		case "op":
			debugger.PrintInstruction(dcpu)
		}
	}
}
Пример #2
0
func runHexdump() {
	flag.Parse()
	srcPath := flag.Arg(1)
	if srcPath == "" {
		printHelp("hexdump")
		return
	}
	src, err := ioutil.ReadFile(srcPath)
	assert(err)
	w := make([]uint16, len(src)/2)
	words.CopyFromBytes(w, src)
	words.Hexdump(w, os.Stdout)
}