simplified file extensions in cartridge loader package

This commit is contained in:
JetSetIlly 2024-04-05 12:32:56 +01:00
parent a0b18e9a96
commit 4ab23ab63e
2 changed files with 35 additions and 97 deletions

View file

@ -15,12 +15,35 @@
package cartridgeloader
// FileExtensions is the list of file extensions that are recognised by the
// cartridgeloader package.
var FileExtensions = [...]string{
".BIN", ".ROM", ".A26", ".2K", ".4K", ".F8", ".F6", ".F4", ".2K+", ".2KSC",
import (
"slices"
)
// file extensions that imply that the emulator should figure out the mapping
// automatically through data fingerprinting
var autoFileExtensions = []string{
".BIN", ".ROM", ".A26",
}
// explicit extensions specify a mapping explicitly
var explicitFileExtensions = []string{
".2K", ".4K", ".F8", ".F6", ".F4", ".2K+", ".2KSC",
".4K+", ".4KSC", ".F8+", ".F8SC", ".F6+", ".F6SC", ".F4+", ".F4SC", ".CV",
".FA", ".FE", ".E0", ".E7", ".3F", ".UA", ".AR", ".DF", ".3E", ".E3P",
".E3+", ".3E+", ".EF", ".EFSC", ".SB", ".WD", ".ACE", ".CDF0", ".CDF1", ".CDFJ",
".CDFJ+", ".DP+", ".DPC", ".CDF", ".WAV", ".MP3", ".MVC",
".CDFJ+", ".DP+", ".DPC", ".CDF", ".MVC",
}
// special file extensions. files with these extensions are treated very
// differently to other supported cartridge files
var audioFileExtensions = []string{
".WAV", ".MP3",
}
// FileExtensions is the list of file extensions that are recognised by the
// cartridgeloader package.
var FileExtensions = []string{}
func init() {
FileExtensions = slices.Concat(autoFileExtensions, explicitFileExtensions, audioFileExtensions)
}

View file

@ -26,6 +26,7 @@ import (
"net/url"
"os"
"path/filepath"
"slices"
"strings"
"github.com/jetsetilly/gopher2600/hardware/memory/cartridge/mapper"
@ -157,102 +158,16 @@ func NewLoader(filename string, mapping string) (Loader, error) {
data := make([]byte, 0)
cl.Data = &data
// decide what mapping to use if the requested mapping is AUTO
if mapping == "AUTO" {
ext := strings.ToUpper(filepath.Ext(filename))
switch ext {
case ".BIN":
fallthrough
case ".ROM":
fallthrough
case ".A26":
extension := strings.ToUpper(filepath.Ext(filename))
if slices.Contains(autoFileExtensions, extension) {
cl.Mapping = "AUTO"
case ".2K":
fallthrough
case ".4K":
fallthrough
case ".F8":
fallthrough
case ".F6":
fallthrough
case ".F4":
fallthrough
case ".2K+":
fallthrough
case ".2KSC":
fallthrough
case ".4K+":
fallthrough
case ".4KSC":
fallthrough
case ".F8+":
fallthrough
case ".F8SC":
fallthrough
case ".F6+":
fallthrough
case ".F6SC":
fallthrough
case ".F4+":
fallthrough
case ".F4SC":
fallthrough
case ".CV":
fallthrough
case ".FA":
fallthrough
case ".FE":
fallthrough
case ".E0":
fallthrough
case ".E7":
fallthrough
case ".3F":
fallthrough
case ".UA":
fallthrough
case ".AR":
fallthrough
case ".DF":
fallthrough
case ".3E":
fallthrough
case ".E3P":
fallthrough // synonym for 3E+
case ".E3+":
fallthrough // synonym for 3E+
case ".3E+":
fallthrough
case ".EF":
fallthrough
case ".EFSC":
fallthrough
case ".SB":
fallthrough
case ".WD":
fallthrough
case ".ACE":
fallthrough
case ".CDF0":
fallthrough
case ".CDF1":
fallthrough
case ".CDFJ":
fallthrough
case ".CDFJ+":
fallthrough
case ".DP+":
fallthrough
case ".DPC":
cl.Mapping = ext[1:]
case ".CDF":
cl.Mapping = "CDFJ"
case ".WAV":
fallthrough
case ".MP3":
} else if slices.Contains(explicitFileExtensions, extension) {
cl.Mapping = extension[1:]
} else if slices.Contains(audioFileExtensions, extension) {
cl.Mapping = "AR"
cl.IsSoundData = true
case ".MVC":
cl.Mapping = "MVC"
}
}