mirror of
https://github.com/ariejan/i6502.git
synced 2024-12-28 05:29:53 +00:00
39 lines
611 B
Go
39 lines
611 B
Go
package i6502
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
)
|
|
|
|
/*
|
|
Read-Only Memory
|
|
*/
|
|
type Rom struct {
|
|
data []byte
|
|
}
|
|
|
|
/*
|
|
Create a new Rom component, using the content of `path`. The file automatically
|
|
specifies the size of Rom.
|
|
*/
|
|
func NewRom(path string) (*Rom, error) {
|
|
data, err := ioutil.ReadFile(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &Rom{data: data}, nil
|
|
}
|
|
|
|
func (r *Rom) Size() uint16 {
|
|
return uint16(len(r.data))
|
|
}
|
|
|
|
func (r *Rom) Read(address uint16) byte {
|
|
return r.data[address]
|
|
}
|
|
|
|
func (r *Rom) Write(address uint16, data byte) {
|
|
panic(fmt.Errorf("Trying to write to ROM at 0x%04X", address))
|
|
}
|