izapple2/storage/diskette.go

46 lines
1.0 KiB
Go
Raw Normal View History

package storage
2019-12-22 13:15:19 +00:00
2020-06-06 12:10:27 +00:00
import (
"errors"
)
2019-12-22 13:15:19 +00:00
// Diskette represents a diskette and it's RW mechanism
type Diskette interface {
PowerOn(cycle uint64)
PowerOff(cycle uint64)
Read(quarterTrack int, cycle uint64) uint8
Write(quarterTrack int, value uint8, cycle uint64)
2019-12-22 13:15:19 +00:00
}
// IsDiskette returns true if the files looks like a 5 1/4 diskette
2022-01-28 18:25:52 +00:00
func IsDiskette(data []byte) bool {
2020-10-03 21:00:04 +00:00
return isFileNib(data) || isFileDsk(data) || isFileWoz(data)
}
2022-01-28 18:25:52 +00:00
// MakeDiskette returns a Diskette by detecting the format
func MakeDiskette(data []byte, filename string, writeable bool) (Diskette, error) {
2020-06-06 12:10:27 +00:00
if isFileNib(data) {
var d diskette16sector
d.nib = newFileNib(data)
return &d, nil
}
if isFileDsk(data) {
2020-08-29 19:48:09 +00:00
var d diskette16sectorWritable
d.nib = newFileDsk(data, filename)
d.nib.supportsWrite = d.nib.supportsWrite && writeable
2019-12-22 13:15:19 +00:00
return &d, nil
}
if isFileWoz(data) {
2021-05-09 17:48:54 +00:00
f, err := NewFileWoz(data)
2019-12-22 13:15:19 +00:00
if err != nil {
return nil, err
}
return newDisquetteWoz(f)
}
return nil, errors.New("Diskette format not supported")
}