Ejemplo n.º 1
0
func findNops(e *dcpu16.Emulator, st *emu.State, pc uint16, in []uint16) (out []uint16) {
	diff := new(emu.Diff)
	for _, op := range in {

		var code emu.Code
		st.Mem[2*int(pc)] = byte(op & 0xFF)
		st.Mem[2*int(pc)+1] = byte((op >> 8) & 0xFF)
		st.Mem[2*int(pc+1)] = st.Mem[2*int(pc)]
		st.Mem[2*int(pc+1)+1] = st.Mem[2*int(pc)+1]
		st.Reg[dcpu16.PC] = uint64(pc)

		diff.Clear()
		code = e.Step(st, diff)
		//			fmt.Printf("%+v\n", diff)

		if code != emu.OK || len(diff.Mem) != 0 || len(diff.Reg) != 1 || !diff.Reg.Has(dcpu16.PC, uint64(pc+1)) {
			continue
		}

		st.Apply(diff)
		diff.Clear()
		code = e.Step(st, diff)
		//			fmt.Printf("%+v\n", diff)
		if code != emu.OK || len(diff.Mem) != 0 || len(diff.Reg) != 1 || !diff.Reg.Has(dcpu16.PC, uint64(pc+2)) {
			continue
		}

		out = append(out, op)
	}
	return
}
Ejemplo n.º 2
0
func (st *state) Step(diff *emu.Diff) (code emu.Code) {
	if code = st.doStep(); code != emu.OK {
		return
	}
	diff.Mem = st.mem.Diff(diff.Mem)
	diff.Reg = st.reg.Diff(diff.Reg)

	return
}