summaryrefslogtreecommitdiff
path: root/vm/rom.go
diff options
context:
space:
mode:
authorstefan <stefan@s00.xyz>2023-05-24 08:32:08 -0400
committerstefan <stefan@s00.xyz>2023-05-24 08:32:08 -0400
commitba2b9c8a1bb1876b6eb4c9783fde798b19de4418 (patch)
tree9b49307112b0f489189cf65c1b50dd281f8e430f /vm/rom.go
parentc30e7f5f99f9ad4d9552b645d7b89d7385972f99 (diff)
downloadevm-ba2b9c8a1bb1876b6eb4c9783fde798b19de4418.tar.gz
init
Diffstat (limited to 'vm/rom.go')
-rw-r--r--vm/rom.go19
1 files changed, 19 insertions, 0 deletions
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
+}