2020-10-17 20:10:48 +02:00
|
|
|
package storage
|
2019-12-22 14:15:19 +01:00
|
|
|
|
2020-06-06 14:10:27 +02:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
2019-12-22 14:15:19 +01:00
|
|
|
|
2020-10-17 20:10:48 +02: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 14:15:19 +01:00
|
|
|
}
|
|
|
|
|
2020-10-17 20:10:48 +02:00
|
|
|
// IsDiskette returns true if the files looks like a 5 1/4 diskette
|
2022-01-28 19:25:52 +01:00
|
|
|
func IsDiskette(data []byte) bool {
|
2020-10-03 23:00:04 +02:00
|
|
|
return isFileNib(data) || isFileDsk(data) || isFileWoz(data)
|
|
|
|
}
|
|
|
|
|
2022-01-28 19:25:52 +01:00
|
|
|
// MakeDiskette returns a Diskette by detecting the format
|
|
|
|
func MakeDiskette(data []byte, filename string, writeable bool) (Diskette, error) {
|
2020-06-06 14:10:27 +02:00
|
|
|
if isFileNib(data) {
|
|
|
|
var d diskette16sector
|
|
|
|
d.nib = newFileNib(data)
|
|
|
|
return &d, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if isFileDsk(data) {
|
2020-08-29 21:48:09 +02:00
|
|
|
var d diskette16sectorWritable
|
|
|
|
d.nib = newFileDsk(data, filename)
|
2020-11-03 10:51:12 -06:00
|
|
|
d.nib.supportsWrite = d.nib.supportsWrite && writeable
|
2019-12-22 14:15:19 +01:00
|
|
|
return &d, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if isFileWoz(data) {
|
2021-05-09 19:48:54 +02:00
|
|
|
f, err := NewFileWoz(data)
|
2019-12-22 14:15:19 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return newDisquetteWoz(f)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, errors.New("Diskette format not supported")
|
|
|
|
}
|