mirror of
https://github.com/ivanizag/izapple2.git
synced 2025-02-06 07:30:16 +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 {
|
func MainApple() *Apple2 {
|
||||||
romFile := flag.String(
|
romFile := flag.String(
|
||||||
"rom",
|
"rom",
|
||||||
"../romdumps/Apple2_Plus.rom",
|
"<internal>/Apple2_Plus.rom",
|
||||||
"main rom file")
|
"main rom file")
|
||||||
disk2RomFile := flag.String(
|
disk2RomFile := flag.String(
|
||||||
"diskRom",
|
"diskRom",
|
||||||
"../romdumps/DISK2.rom",
|
"<internal>/DISK2.rom",
|
||||||
"rom file for the disk drive controller")
|
"rom file for the disk drive controller")
|
||||||
disk2Slot := flag.Int(
|
disk2Slot := flag.Int(
|
||||||
"disk2Slot",
|
"disk2Slot",
|
||||||
@ -21,7 +21,7 @@ func MainApple() *Apple2 {
|
|||||||
"slot for the disk driver. -1 for none.")
|
"slot for the disk driver. -1 for none.")
|
||||||
diskImage := flag.String(
|
diskImage := flag.String(
|
||||||
"disk",
|
"disk",
|
||||||
"../romdumps/dos33.dsk",
|
"<internal>/dos33.dsk",
|
||||||
"file to load on the first disk drive")
|
"file to load on the first disk drive")
|
||||||
cpuClock := flag.Float64(
|
cpuClock := flag.Float64(
|
||||||
"mhz",
|
"mhz",
|
||||||
@ -29,7 +29,7 @@ func MainApple() *Apple2 {
|
|||||||
"cpu speed in Mhz, use 0 for full speed. Use F5 to toggle.")
|
"cpu speed in Mhz, use 0 for full speed. Use F5 to toggle.")
|
||||||
charRomFile := flag.String(
|
charRomFile := flag.String(
|
||||||
"charRom",
|
"charRom",
|
||||||
"../romdumps/Apple2rev7CharGen.rom",
|
"<internal>/Apple2rev7CharGen.rom",
|
||||||
"rom file for the disk drive controller")
|
"rom file for the disk drive controller")
|
||||||
languageCardSlot := flag.Int(
|
languageCardSlot := flag.Int(
|
||||||
"languageCardSlot",
|
"languageCardSlot",
|
||||||
@ -83,12 +83,4 @@ func MainApple() *Apple2 {
|
|||||||
//a.AddCardLogger(4)
|
//a.AddCardLogger(4)
|
||||||
|
|
||||||
return a
|
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 (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type card interface {
|
type card interface {
|
||||||
@ -23,10 +22,7 @@ func (c *cardBase) loadRom(filename string) {
|
|||||||
if c.a != nil {
|
if c.a != nil {
|
||||||
panic("Rom must be loaded before inserting the card in the slot")
|
panic("Rom must be loaded before inserting the card in the slot")
|
||||||
}
|
}
|
||||||
data, err := ioutil.ReadFile(filename)
|
data := loadResource(filename)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
c.rom = newMemoryRange(0, data)
|
c.rom = newMemoryRange(0, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package apple2
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -27,10 +26,7 @@ func NewCharacterGenerator(filename string) *CharacterGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cg *CharacterGenerator) load(filename string) {
|
func (cg *CharacterGenerator) load(filename string) {
|
||||||
bytes, err := ioutil.ReadFile(filename)
|
bytes := loadResource(filename)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
size := len(bytes)
|
size := len(bytes)
|
||||||
if size != rev7CharGenSize {
|
if size != rev7CharGenSize {
|
||||||
panic("Character ROM size not supported")
|
panic("Character ROM size not supported")
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package apple2
|
package apple2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -40,10 +39,7 @@ func (d *diskette16sector) write(track int, position int, value uint8) int {
|
|||||||
func loadDisquette(filename string) *diskette16sector {
|
func loadDisquette(filename string) *diskette16sector {
|
||||||
var d diskette16sector
|
var d diskette16sector
|
||||||
|
|
||||||
data, err := ioutil.ReadFile(filename)
|
data := loadResource(filename)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
size := len(data)
|
size := len(data)
|
||||||
|
|
||||||
if size == nibImageSize {
|
if size == nibImageSize {
|
||||||
|
@ -2,7 +2,6 @@ package apple2
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// See https://fabiensanglard.net/fd_proxy/prince_of_persia/Inside%20the%20Apple%20IIe.pdf
|
// 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) {
|
func (mmu *memoryManager) loadRom(filename string) {
|
||||||
data, err := ioutil.ReadFile(filename)
|
data := loadResource(filename)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
size := len(data)
|
size := len(data)
|
||||||
if size != apple2RomSize && size != apple2eRomSize {
|
if size != apple2RomSize && size != apple2eRomSize {
|
||||||
panic("Rom size not supported")
|
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