From ba2b9c8a1bb1876b6eb4c9783fde798b19de4418 Mon Sep 17 00:00:00 2001 From: stefan Date: Wed, 24 May 2023 08:32:08 -0400 Subject: init --- vm/rom.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 vm/rom.go (limited to 'vm/rom.go') diff --git a/vm/rom.go b/vm/rom.go new file mode 100644 index 0000000..958e70e --- /dev/null +++ b/vm/rom.go @@ -0,0 +1,19 @@ +package main + +import ( + "os" + "fmt" +) + +type Rom []byte + +func (r *Rom) Fetch(pc *uint64, n uint64) []byte { + if (*pc + n > uint64(len(*r)) - 1) { + fmt.Fprintf(os.Stderr, "error: trying to read outside of rom\n") + os.Exit(1) + } + x := make([]byte, n) + copy(x, (*r)[*pc:*pc + n]) + *pc += n + return x +} -- cgit v1.2.3