summaryrefslogtreecommitdiff
path: root/vm/rom.go
blob: 958e70e7021f832edcd348712d85ba5915f64a18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
}