2013-03-28 04:49:38 +00:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
2013-03-30 05:43:15 +00:00
|
|
|
"fmt"
|
2013-03-28 04:49:38 +00:00
|
|
|
"io/ioutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ReadRomOrDie(filename string) []byte {
|
|
|
|
bytes, err := ioutil.ReadFile(filename)
|
|
|
|
if err != nil {
|
|
|
|
panic("Cannot read ROM file: " + filename)
|
|
|
|
}
|
|
|
|
return bytes
|
|
|
|
}
|
2013-03-30 05:43:15 +00:00
|
|
|
|
|
|
|
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
|
2013-04-08 03:18:00 +00:00
|
|
|
value[i+1024] = b
|
|
|
|
value[i+1536] = b | 0x80
|
2013-03-30 05:43:15 +00:00
|
|
|
}
|
|
|
|
return value
|
|
|
|
}
|
2013-04-08 01:31:14 +00:00
|
|
|
|
|
|
|
func ReadFullCharacterRomOrDie(filename string) [2048]byte {
|
|
|
|
bytes := ReadRomOrDie(filename)
|
|
|
|
if len(bytes) != 2048 {
|
|
|
|
panic(fmt.Sprintf("Got %d bytes (not 2048) from file '%s'", len(bytes), filename))
|
|
|
|
}
|
|
|
|
var value [2048]byte
|
|
|
|
copy(value[:], bytes)
|
|
|
|
return value
|
|
|
|
}
|