mirror of
https://github.com/ivanizag/izapple2.git
synced 2025-01-29 14:29:45 +00:00
Embed default resources in the executable
This commit is contained in:
parent
f9d213a806
commit
343df8a554
@ -9,11 +9,11 @@ import (
|
||||
func MainApple() *Apple2 {
|
||||
romFile := flag.String(
|
||||
"rom",
|
||||
"../romdumps/Apple2_Plus.rom",
|
||||
"<internal>/Apple2_Plus.rom",
|
||||
"main rom file")
|
||||
disk2RomFile := flag.String(
|
||||
"diskRom",
|
||||
"../romdumps/DISK2.rom",
|
||||
"<internal>/DISK2.rom",
|
||||
"rom file for the disk drive controller")
|
||||
disk2Slot := flag.Int(
|
||||
"disk2Slot",
|
||||
@ -21,7 +21,7 @@ func MainApple() *Apple2 {
|
||||
"slot for the disk driver. -1 for none.")
|
||||
diskImage := flag.String(
|
||||
"disk",
|
||||
"../romdumps/dos33.dsk",
|
||||
"<internal>/dos33.dsk",
|
||||
"file to load on the first disk drive")
|
||||
cpuClock := flag.Float64(
|
||||
"mhz",
|
||||
@ -29,7 +29,7 @@ func MainApple() *Apple2 {
|
||||
"cpu speed in Mhz, use 0 for full speed. Use F5 to toggle.")
|
||||
charRomFile := flag.String(
|
||||
"charRom",
|
||||
"../romdumps/Apple2rev7CharGen.rom",
|
||||
"<internal>/Apple2rev7CharGen.rom",
|
||||
"rom file for the disk drive controller")
|
||||
languageCardSlot := flag.Int(
|
||||
"languageCardSlot",
|
||||
@ -83,12 +83,4 @@ func MainApple() *Apple2 {
|
||||
//a.AddCardLogger(4)
|
||||
|
||||
return a
|
||||
/* if *useSDL {
|
||||
a.ConfigureStdConsole(false, *stdoutScreen)
|
||||
apple2sdl.SDLRun(a)
|
||||
} else {
|
||||
a.ConfigureStdConsole(true, true)
|
||||
a.Run(log)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package apple2
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
type card interface {
|
||||
@ -23,10 +22,7 @@ func (c *cardBase) loadRom(filename string) {
|
||||
if c.a != nil {
|
||||
panic("Rom must be loaded before inserting the card in the slot")
|
||||
}
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
data := loadResource(filename)
|
||||
c.rom = newMemoryRange(0, data)
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package apple2
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
/*
|
||||
@ -27,10 +26,7 @@ func NewCharacterGenerator(filename string) *CharacterGenerator {
|
||||
}
|
||||
|
||||
func (cg *CharacterGenerator) load(filename string) {
|
||||
bytes, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
bytes := loadResource(filename)
|
||||
size := len(bytes)
|
||||
if size != rev7CharGenSize {
|
||||
panic("Character ROM size not supported")
|
||||
|
@ -1,7 +1,6 @@
|
||||
package apple2
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
@ -40,10 +39,7 @@ func (d *diskette16sector) write(track int, position int, value uint8) int {
|
||||
func loadDisquette(filename string) *diskette16sector {
|
||||
var d diskette16sector
|
||||
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
data := loadResource(filename)
|
||||
size := len(data)
|
||||
|
||||
if size == nibImageSize {
|
||||
|
@ -2,7 +2,6 @@ package apple2
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
// See https://fabiensanglard.net/fd_proxy/prince_of_persia/Inside%20the%20Apple%20IIe.pdf
|
||||
@ -122,10 +121,7 @@ const (
|
||||
)
|
||||
|
||||
func (mmu *memoryManager) loadRom(filename string) {
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
data := loadResource(filename)
|
||||
size := len(data)
|
||||
if size != apple2RomSize && size != apple2eRomSize {
|
||||
panic("Rom size not supported")
|
||||
|
41
resources.go
Normal file
41
resources.go
Normal file
@ -0,0 +1,41 @@
|
||||
package apple2
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/ivanizag/apple2/romdumps"
|
||||
)
|
||||
|
||||
const (
|
||||
internalPrefix = "<internal>/"
|
||||
)
|
||||
|
||||
func loadResource(filename string) []uint8 {
|
||||
var file io.Reader
|
||||
if strings.HasPrefix(filename, internalPrefix) {
|
||||
// load from embedded resource
|
||||
resource := strings.TrimPrefix(filename, internalPrefix)
|
||||
resourceFile, err := romdumps.Assets.Open(resource)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer resourceFile.Close()
|
||||
file = resourceFile
|
||||
} else {
|
||||
diskFile, err := os.Open(filename)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer diskFile.Close()
|
||||
file = diskFile
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return data
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1
romdumps/generate/.gitignore
vendored
Normal file
1
romdumps/generate/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
files
|
24
romdumps/generate/generate.go
Normal file
24
romdumps/generate/generate.go
Normal file
@ -0,0 +1,24 @@
|
||||
// To generate the resources put the files on a "files" subdirectory and run main
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
208
romdumps/romdumps_vfsdata.go
Normal file
208
romdumps/romdumps_vfsdata.go
Normal file
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user