goapple2/util/util.go
2013-03-29 22:43:15 -07:00

30 lines
598 B
Go

package util
import (
"fmt"
"io/ioutil"
)
func ReadRomOrDie(filename string) []byte {
bytes, err := ioutil.ReadFile(filename)
if err != nil {
panic("Cannot read ROM file: " + filename)
}
return bytes
}
func ReadSmallCharacterRomOrDie(filename string) [2048]byte {
bytes := ReadRomOrDie(filename)
if len(bytes) != 512 {
panic(fmt.Sprintf("Got %d bytes (not 512) from file '%s'", len(bytes), filename))
}
var value [2048]byte
for i, b := range bytes {
value[i] = (b ^ 0xff) & 0x7f
value[i+512] = b | 0x80
value[i+1024] = b & 0x7f
value[i+1536] = b & 0x7f
}
return value
}