mirror of
https://github.com/zellyn/goapple2.git
synced 2024-10-15 03:24:16 +00:00
30 lines
598 B
Go
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
|
|
}
|