From d46124baddabf4ec1e464e55007a626ae6f2a91e Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Sun, 5 Jan 2025 17:52:32 +0200 Subject: [PATCH] Allow hiding the embedded binaries This might be useful for purists. --- README.md | 4 +++- main.go | 7 ++++++- static/static.go | 8 ++++++++ static/static_test.go | 14 ++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d423902..9dc8f50 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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. diff --git a/main.go b/main.go index ec2a8eb..676ca62 100644 --- a/main.go +++ b/main.go @@ -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.") @@ -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) diff --git a/static/static.go b/static/static.go index d176417..cc4437b 100644 --- a/static/static.go +++ b/static/static.go @@ -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 +} diff --git a/static/static_test.go b/static/static_test.go index 8240d23..1284663 100644 --- a/static/static_test.go +++ b/static/static_test.go @@ -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") + } +}