goapple2/disk/nybble.go

61 lines
1.1 KiB
Go
Raw Normal View History

2013-04-16 00:43:23 +00:00
package disk
type SavedPos struct {
halfTrack byte
position int
}
2013-04-16 00:43:23 +00:00
type Nybble struct {
Tracks [][]byte
halfTrack byte
position int
writeable bool
}
func NewNybble(tracks [][]byte) *Nybble {
2013-04-16 00:43:23 +00:00
nd := Nybble{
Tracks: tracks,
2013-04-16 00:43:23 +00:00
}
return &nd
}
func (disk *Nybble) Read() byte {
track := disk.Tracks[disk.halfTrack/2]
disk.position = (disk.position + 1) % len(track)
return track[disk.position]
}
2013-04-21 23:49:58 +00:00
func (disk *Nybble) Skip(amount int) {
track := disk.Tracks[disk.halfTrack/2]
disk.position = (disk.position + amount) % len(track)
}
2013-04-16 00:43:23 +00:00
func (disk *Nybble) Write(b byte) {
track := disk.Tracks[disk.halfTrack/2]
disk.position = (disk.position + 1) % len(track)
if disk.writeable {
track[disk.position] = b
}
}
func (disk *Nybble) SetHalfTrack(halfTrack byte) {
disk.halfTrack = halfTrack
}
func (disk *Nybble) HalfTrack() byte {
return disk.halfTrack
}
func (disk *Nybble) Writeable() bool {
return disk.writeable
2013-04-16 00:43:23 +00:00
}
func (disk *Nybble) GetPos() SavedPos {
return SavedPos{disk.halfTrack, disk.position}
2013-04-16 00:43:23 +00:00
}
func (disk *Nybble) SetPos(pos SavedPos) {
disk.halfTrack = pos.halfTrack
disk.position = pos.position
2013-04-16 00:43:23 +00:00
}