Skip to content

Commit

Permalink
Merge pull request #172 from skx/no-embed
Browse files Browse the repository at this point in the history
Allow hiding the embedded binaries
  • Loading branch information
skx authored Jan 5, 2025
2 parents 84690ce + d46124b commit 7708d64
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ There are many available command-line options, which are shown in the output of
* Change to the given directory before running.
* `-directories`
* Use directories on the host for drive-contents, discussed later in this document.
* `-embed`
* Enable/Disable the embedded binaries we unconditionally add to the A:-drive. (The utilities to change the output driver, toggle debugging, etc.)
* `-log-path /path/to/file`
* Output debug-logs to the given file, creating it if necessary.
* **NOTE**: You can run `A:!DEBUG 1` to enable "quick debug logging", and `A:!DEBUG 0` to turn it back off again, at runtime.
Expand Down Expand Up @@ -183,7 +185,7 @@ This allows you to customize the emulator, or perform other "one-time" setup via

There are a small number of [extensions](EXTENSIONS.md) added to the BIOS functionality we provide, and these extensions allow changing some aspects of the emulator at runtime.

The behaviour changing is achieved by having a small number of .COM files invoke the extension functions, and these binaries are embedded within our emulator to improve ease of use, via the [static/](static/) directory in our source-tree. This means no matter what you'll always find some binaries installed on A:, despite not being present in reality.
The behaviour changing is achieved by having a small number of .COM files invoke the extension functions, and these binaries are embedded within our emulator to improve ease of use, via the [static/](static/) directory in our source-tree. This means no matter what you'll always find some binaries installed on A:, despite not being present in reality - you can disable the appearance of these binaries via the `-embed=false` command-line flag.

> **NOTE** To avoid naming collisions all our embedded binaries are named with a `!` prefix, except for `#.COM` which is designed to be used as a comment-binary.
Expand Down
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func main() {
ccp := flag.String("ccp", "ccpz", "The name of the CCP that we should run (ccp vs. ccpz).")
cd := flag.String("cd", "", "Change to this directory before launching")
createDirectories := flag.Bool("create", false, "Create subdirectories on the host computer for each CP/M drive.")
embedBin := flag.Bool("embed", true, "Should we embed our utility commands into the A: filesystem.")
input := flag.String("input", cpm.DefaultInputDriver, "The name of the console input driver to use (-list-input-drivers will show valid choices).")
output := flag.String("output", cpm.DefaultOutputDriver, "The name of the console output driver to use (-list-output-drivers will show valid choices).")
logAll := flag.Bool("log-all", false, "Log all function invocations, including the noisy console I/O ones.")
Expand Down Expand Up @@ -269,7 +270,11 @@ func main() {
}

// Load any embedded files within our binary
obj.SetStaticFilesystem(static.GetContent())
if *embedBin {
obj.SetStaticFilesystem(static.GetContent())
} else {
obj.SetStaticFilesystem(static.GetEmptyContent())
}

// Default to not using subdirectories for drives
obj.SetDrives(false)
Expand Down
8 changes: 8 additions & 0 deletions static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ import "embed"
//go:embed */*
var content embed.FS

// empty has no contents.
var empty embed.FS

// GetContent returns the embedded filesystem we store within this package.
func GetContent() embed.FS {
return content
}

// GetEmptyContent returns the embedded filesystem we store within this package which has no contents.
func GetEmptyContent() embed.FS {
return empty
}
14 changes: 14 additions & 0 deletions static/static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,17 @@ func TestStatic(t *testing.T) {
}
}
}

// TestEmpty ensures we have no files.
func TestEmpty(t *testing.T) {

// Read the subdirectory
files, err := GetEmptyContent().ReadDir(".")
if err != nil {
t.Fatalf("error reading contents")
}

if len(files) != 0 {
t.Fatalf("got files, but expected none")
}
}

0 comments on commit 7708d64

Please sign in to comment.