2019-12-22 14:15:19 +01:00
|
|
|
package apple2
|
|
|
|
|
2020-06-06 14:10:27 +02:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
2019-12-22 14:15:19 +01:00
|
|
|
|
|
|
|
type diskette interface {
|
|
|
|
powerOn(cycle uint64)
|
|
|
|
powerOff(cycle uint64)
|
|
|
|
read(quarterTrack int, cycle uint64) uint8
|
|
|
|
write(quarterTrack int, value uint8, cycle uint64)
|
|
|
|
}
|
|
|
|
|
2020-08-11 23:56:08 +02:00
|
|
|
func loadDiskette(filename string) (diskette, error) {
|
2019-12-22 14:15:19 +01:00
|
|
|
data, err := loadResource(filename)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
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)
|
2019-12-22 14:15:19 +01:00
|
|
|
return &d, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if isFileWoz(data) {
|
|
|
|
f, err := newFileWoz(data)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return newDisquetteWoz(f)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, errors.New("Diskette format not supported")
|
|
|
|
}
|