Esempio n. 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)
		}
	}
}
Esempio n. 2
0
func runEmulator() {
	flag.Parse()
	path := flag.Arg(1)
	if path == "" {
		printHelp("emulate")
		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)
	err = dcpu.Exec()
	assert(err)
}