Replace vfsgen with go embed
This commit is contained in:
parent
cc7f4678a8
commit
f28dbdaa1c
|
@ -4,7 +4,6 @@ import (
|
|||
"errors"
|
||||
|
||||
"github.com/ivanizag/iz6502"
|
||||
"github.com/ivanizag/izapple2/storage"
|
||||
)
|
||||
|
||||
func newApple2() *Apple2 {
|
||||
|
@ -77,7 +76,7 @@ const (
|
|||
|
||||
// LoadRom loads a standard Apple2+ or 2e ROM
|
||||
func (a *Apple2) LoadRom(filename string) error {
|
||||
data, _, err := storage.LoadResource(filename)
|
||||
data, _, err := LoadResource(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -98,7 +97,7 @@ func (a *Apple2) AddDisk2(slot int, diskImage, diskBImage string) error {
|
|||
a.insertCard(c, slot)
|
||||
|
||||
if diskImage != "" {
|
||||
diskette, err := storage.LoadDiskette(diskImage)
|
||||
diskette, err := LoadDiskette(diskImage)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -106,7 +105,7 @@ func (a *Apple2) AddDisk2(slot int, diskImage, diskBImage string) error {
|
|||
}
|
||||
|
||||
if diskBImage != "" {
|
||||
diskette, err := storage.LoadDiskette(diskBImage)
|
||||
diskette, err := LoadDiskette(diskBImage)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@ package izapple2
|
|||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"github.com/ivanizag/izapple2/storage"
|
||||
)
|
||||
|
||||
const defaultInternal = "<default>"
|
||||
|
@ -162,7 +160,9 @@ func MainApple() *Apple2 {
|
|||
diskImageFinal := *diskImage
|
||||
hardDiskImageFinal := *hardDiskImage
|
||||
if filename != "" {
|
||||
if storage.IsDiskette(filename) {
|
||||
// Try loading as diskette
|
||||
_, err := LoadDiskette(filename)
|
||||
if err == nil {
|
||||
diskImageFinal = filename
|
||||
} else {
|
||||
hardDiskImageFinal = filename
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/ivanizag/iz6502"
|
||||
"github.com/ivanizag/izapple2/storage"
|
||||
)
|
||||
|
||||
/*
|
||||
|
@ -36,7 +35,7 @@ func loadBase64aRom(a *Apple2) error {
|
|||
|
||||
for i := 0; i < base64aRomChipCount; i++ {
|
||||
filename := fmt.Sprintf("<internal>/BASE64A_%X.BIN", 0xd0+i*0x08)
|
||||
data, _, err := storage.LoadResource(filename)
|
||||
data, _, err := LoadResource(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@ package izapple2
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ivanizag/izapple2/storage"
|
||||
)
|
||||
|
||||
// Card represents an Apple II card to be inserted in a slot
|
||||
|
@ -43,7 +41,7 @@ func (c *cardBase) reset() {
|
|||
}
|
||||
|
||||
func (c *cardBase) loadRomFromResource(resource string) {
|
||||
data, _, err := storage.LoadResource(resource)
|
||||
data, _, err := LoadResource(resource)
|
||||
if err != nil {
|
||||
// The resource should be internal and never fail
|
||||
panic(err)
|
||||
|
|
|
@ -2,7 +2,6 @@ package izapple2
|
|||
|
||||
import (
|
||||
"github.com/ivanizag/izapple2/component"
|
||||
"github.com/ivanizag/izapple2/storage"
|
||||
)
|
||||
|
||||
// TODO: fast mode
|
||||
|
@ -54,7 +53,7 @@ func NewCardDisk2Sequencer() *CardDisk2Sequencer {
|
|||
c.name = "Disk II"
|
||||
c.loadRomFromResource("<internal>/DISK2.rom")
|
||||
|
||||
data, _, err := storage.LoadResource("<internal>/DISK2P6.rom")
|
||||
data, _, err := LoadResource("<internal>/DISK2P6.rom")
|
||||
if err != nil {
|
||||
// The resource should be internal and never fail
|
||||
panic(err)
|
||||
|
|
|
@ -21,7 +21,7 @@ type cardDisk2SequencerDrive struct {
|
|||
}
|
||||
|
||||
func (d *cardDisk2SequencerDrive) insertDiskette(filename string) error {
|
||||
data, writeable, err := storage.LoadResource(filename)
|
||||
data, writeable, err := LoadResource(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/ivanizag/izapple2/component"
|
||||
"github.com/ivanizag/izapple2/storage"
|
||||
)
|
||||
|
||||
/*
|
||||
|
@ -47,7 +46,7 @@ func NewCardVidex() *CardVidex {
|
|||
}
|
||||
|
||||
func (c *CardVidex) loadCharacterMap(filename string) error {
|
||||
bytes, _, err := storage.LoadResource(filename)
|
||||
bytes, _, err := LoadResource(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@ package izapple2
|
|||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/ivanizag/izapple2/storage"
|
||||
)
|
||||
|
||||
/*
|
||||
|
@ -52,7 +50,7 @@ func newCharacterGenerator(filename string, order charColumnMap, isApple2e bool)
|
|||
}
|
||||
|
||||
func (cg *CharacterGenerator) load(filename string) error {
|
||||
bytes, _, err := storage.LoadResource(filename)
|
||||
bytes, _, err := LoadResource(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
2
go.mod
2
go.mod
|
@ -7,7 +7,6 @@ require (
|
|||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20211213063430-748e38ca8aec
|
||||
github.com/ivanizag/iz6502 v1.2.1
|
||||
github.com/pkg/profile v1.6.0
|
||||
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546
|
||||
github.com/veandco/go-sdl2 v0.4.12
|
||||
)
|
||||
|
||||
|
@ -19,7 +18,6 @@ require (
|
|||
github.com/godbus/dbus/v5 v5.0.4 // indirect
|
||||
github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
|
||||
github.com/srwiley/oksvg v0.0.0-20200311192757-870daf9aa564 // indirect
|
||||
github.com/srwiley/rasterx v0.0.0-20200120212402-85cb7272f5e9 // indirect
|
||||
github.com/stretchr/testify v1.5.1 // indirect
|
||||
|
|
5
go.sum
5
go.sum
|
@ -40,11 +40,7 @@ github.com/pkg/profile v1.6.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdL
|
|||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 h1:bUGsEnyNbVPw06Bs80sCeARAlK8lhwqGyi6UT8ymuGk=
|
||||
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 h1:pXY9qYc/MP5zdvqWEUH6SjNiu7VhSjuVFTFiTcphaLU=
|
||||
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
|
||||
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
|
||||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/srwiley/oksvg v0.0.0-20200311192757-870daf9aa564 h1:HunZiaEKNGVdhTRQOVpMmj5MQnGnv+e8uZNu3xFLgyM=
|
||||
|
@ -87,7 +83,6 @@ golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
|
|||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA=
|
||||
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
|
|
@ -1,24 +1,29 @@
|
|||
package storage
|
||||
package izapple2
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"embed"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/ivanizag/izapple2/romdumps"
|
||||
"github.com/ivanizag/izapple2/storage"
|
||||
)
|
||||
|
||||
const (
|
||||
internalPrefix = "<internal>/"
|
||||
embedPrefix = "resources/"
|
||||
httpPrefix = "http://"
|
||||
httpsPrefix = "https://"
|
||||
)
|
||||
|
||||
//go:embed resources
|
||||
var internalFiles embed.FS
|
||||
|
||||
func isInternalResource(filename string) bool {
|
||||
return strings.HasPrefix(filename, internalPrefix)
|
||||
}
|
||||
|
@ -34,8 +39,8 @@ func LoadResource(filename string) ([]uint8, bool, error) {
|
|||
var file io.Reader
|
||||
if isInternalResource(filename) {
|
||||
// load from embedded resource
|
||||
resource := strings.TrimPrefix(filename, internalPrefix)
|
||||
resourceFile, err := romdumps.Assets.Open(resource)
|
||||
resource := embedPrefix + strings.TrimPrefix(filename, internalPrefix)
|
||||
resourceFile, err := internalFiles.Open(resource)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
@ -96,7 +101,7 @@ func LoadResource(filename string) ([]uint8, bool, error) {
|
|||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
if isFileDsk(bytes) || isFileNib(bytes) || isFileWoz(bytes) {
|
||||
if storage.IsDiskette(bytes) {
|
||||
data = bytes
|
||||
break
|
||||
}
|
||||
|
@ -105,3 +110,13 @@ func LoadResource(filename string) ([]uint8, bool, error) {
|
|||
|
||||
return data, writeable, nil
|
||||
}
|
||||
|
||||
// LoadDiskette returns a Diskette by detecting the format
|
||||
func LoadDiskette(filename string) (storage.Diskette, error) {
|
||||
data, writeable, err := LoadResource(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return storage.MakeDiskette(data, filename, writeable)
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,65 @@
|
|||
Ш
|
||||
|
||||
|
||||
|
||||
99;;8(
|
||||
|
||||
|
||||
|
||||
99;;-Ш8H
|
||||
|
||||
|
||||
|
||||
(H(H(H(H-H8H
|
||||
|
||||
|
||||
|
||||
(H(H(H(HШШШШ
|
||||
|
||||
|
||||
|
||||
XxXxXxXxXxXx
|
||||
|
||||
|
||||
|
||||
XxXxXxXxШШШШ
|
||||
|
||||
|
||||
|
||||
hh€hh€h€h€
|
||||
|
||||
|
||||
|
||||
hh€hh€ШНШШ
|
||||
|
||||
|
||||
|
||||
<EFBFBD>№<EFBFBD>№<EFBFBD>»<EFBFBD>»<EFBFBD>Ѕ<EFBFBD>ё
|
||||
|
||||
|
||||
|
||||
<EFBFBD>№<EFBFBD>№<EFBFBD>»<EFBFBD>»ШЩШШ
|
||||
|
||||
|
||||
|
||||
ЁИЁИЁИЁИ)YЁИ
|
||||
|
||||
|
||||
|
||||
ЁИЁИЁИЁИЩэШш
|
||||
|
||||
|
||||
|
||||
ШшШшШшШшЩэ ш
|
||||
|
||||
|
||||
|
||||
ШшШшШшШшШЭиа
|
||||
|
||||
|
||||
|
||||
и€ии€иMиа
|
||||
|
||||
|
||||
|
||||
и€ии€и
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1 +0,0 @@
|
|||
files
|
|
@ -1,24 +0,0 @@
|
|||
// To generate the resources put the files on a "files" subdirectory and run "go run generate.go"
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/shurcooL/vfsgen"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var cwd, _ = os.Getwd()
|
||||
templates := http.Dir(filepath.Join(cwd, "files"))
|
||||
if err := vfsgen.Generate(templates, vfsgen.Options{
|
||||
Filename: "../romdumps_vfsdata.go",
|
||||
PackageName: "romdumps",
|
||||
VariableName: "Assets",
|
||||
}); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
|
@ -13,22 +13,12 @@ type Diskette interface {
|
|||
}
|
||||
|
||||
// IsDiskette returns true if the files looks like a 5 1/4 diskette
|
||||
func IsDiskette(filename string) bool {
|
||||
data, _, err := LoadResource(filename)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
func IsDiskette(data []byte) bool {
|
||||
return isFileNib(data) || isFileDsk(data) || isFileWoz(data)
|
||||
}
|
||||
|
||||
// LoadDiskette returns a Diskette by detecting the format
|
||||
func LoadDiskette(filename string) (Diskette, error) {
|
||||
data, writeable, err := LoadResource(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// MakeDiskette returns a Diskette by detecting the format
|
||||
func MakeDiskette(data []byte, filename string, writeable bool) (Diskette, error) {
|
||||
if isFileNib(data) {
|
||||
var d diskette16sector
|
||||
d.nib = newFileNib(data)
|
||||
|
|
Loading…
Reference in New Issue