Skip to content

Commit

Permalink
Embed default resources in the executable
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanizag committed Jun 1, 2019
1 parent f9d213a commit 343df8a
Show file tree
Hide file tree
Showing 13 changed files with 282 additions and 32 deletions.
16 changes: 4 additions & 12 deletions apple2main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ 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",
6,
"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",
CpuClockMhz,
"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",
Expand Down Expand Up @@ -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)
}
*/
}
6 changes: 1 addition & 5 deletions cardBase.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package apple2

import (
"io"
"io/ioutil"
)

type card interface {
Expand All @@ -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)
}

Expand Down
6 changes: 1 addition & 5 deletions characterGenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package apple2

import (
"fmt"
"io/ioutil"
)

/*
Expand All @@ -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")
Expand Down
6 changes: 1 addition & 5 deletions diskette16sector.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package apple2

import (
"io/ioutil"
"os"
)

Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 1 addition & 5 deletions memoryManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package apple2

import (
"io"
"io/ioutil"
)

// See https://fabiensanglard.net/fd_proxy/prince_of_persia/Inside%20the%20Apple%20IIe.pdf
Expand Down Expand Up @@ -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")
Expand Down
41 changes: 41 additions & 0 deletions resources.go
Original file line number Diff line number Diff line change
@@ -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 removed romdumps/Apple2_Plus.rom
Binary file not shown.
Binary file removed romdumps/Apple2rev7CharGen.rom
Binary file not shown.
Binary file removed romdumps/DISK2.rom
Binary file not shown.
Binary file removed romdumps/dos33.dsk
Binary file not shown.
1 change: 1 addition & 0 deletions romdumps/generate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
files
24 changes: 24 additions & 0 deletions romdumps/generate/generate.go
Original file line number Diff line number Diff line change
@@ -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 changes: 208 additions & 0 deletions romdumps/romdumps_vfsdata.go

Large diffs are not rendered by default.

0 comments on commit 343df8a

Please sign in to comment.