2013-04-16 00:43:23 +00:00
|
|
|
package disk
|
|
|
|
|
2013-05-07 04:23:36 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2013-05-07 04:23:36 +00:00
|
|
|
func NewNybble(tracks [][]byte) *Nybble {
|
2013-04-16 00:43:23 +00:00
|
|
|
nd := Nybble{
|
2013-05-07 04:23:36 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2013-05-07 04:23:36 +00:00
|
|
|
func (disk *Nybble) Writeable() bool {
|
|
|
|
return disk.writeable
|
2013-04-16 00:43:23 +00:00
|
|
|
}
|
|
|
|
|
2013-05-07 04:23:36 +00:00
|
|
|
func (disk *Nybble) GetPos() SavedPos {
|
|
|
|
return SavedPos{disk.halfTrack, disk.position}
|
2013-04-16 00:43:23 +00:00
|
|
|
}
|
|
|
|
|
2013-05-07 04:23:36 +00:00
|
|
|
func (disk *Nybble) SetPos(pos SavedPos) {
|
|
|
|
disk.halfTrack = pos.halfTrack
|
|
|
|
disk.position = pos.position
|
2013-04-16 00:43:23 +00:00
|
|
|
}
|