File format autodetection

This commit is contained in:
Ivan Izaguirre 2020-10-03 23:00:04 +02:00
parent 1d014b8a4f
commit e07754d1d0
2 changed files with 24 additions and 3 deletions

View File

@ -136,6 +136,18 @@ func MainApple() *Apple2 {
flag.Parse()
// Process a filename with autodetection
filename := flag.Arg(0)
diskImageFinal := *diskImage
hardDiskImageFinal := *hardDiskImage
if filename != "" {
if isDiskette(filename) {
diskImageFinal = filename
} else {
hardDiskImageFinal = filename
}
}
if *wozImage != "" {
f, err := loadFileWoz(*wozImage)
if err != nil {
@ -263,17 +275,17 @@ func MainApple() *Apple2 {
a.AddFastChip(*fastChipCardSlot)
}
if *disk2Slot > 0 {
err := a.AddDisk2(*disk2Slot, *disk2RomFile, *diskImage, *diskBImage)
err := a.AddDisk2(*disk2Slot, *disk2RomFile, diskImageFinal, *diskBImage)
if err != nil {
panic(err)
}
}
if *hardDiskImage != "" {
if hardDiskImageFinal != "" {
if *hardDiskSlot <= 0 {
// If there is a hard disk image, but no slot assigned, use slot 7.
*hardDiskSlot = 7
}
err := a.AddSmartPortDisk(*hardDiskSlot, *hardDiskImage, *traceHD)
err := a.AddSmartPortDisk(*hardDiskSlot, hardDiskImageFinal, *traceHD)
if err != nil {
panic(err)
}

View File

@ -11,6 +11,15 @@ type diskette interface {
write(quarterTrack int, value uint8, cycle uint64)
}
func isDiskette(filename string) bool {
data, err := loadResource(filename)
if err != nil {
return false
}
return isFileNib(data) || isFileDsk(data) || isFileWoz(data)
}
func loadDiskette(filename string) (diskette, error) {
data, err := loadResource(filename)
if err != nil {