Skip to content

Commit

Permalink
Externalize the download sources
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorza committed Dec 2, 2023
1 parent c12b234 commit c4dbba5
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 57 deletions.
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"type": "go",
"request": "launch",
"mode": "auto",
"cwd": "d:/temp/nextdev/",
"program": "d:/source/zxenv/.",
"args": ["new", "tilemap"]
"cwd": "test",
"program": ".",
"args": ["init"]
}
]
}
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,12 @@ Running the `new` command creates a folder with the name of your project that in
## What is installed
|Tool |URL|
|------------|-----------------------------------------------------------------------------|
|CSpect |http://www.javalemmings.com/public/zxnext/CSpect2_16_6.zip|
|ZEsarUX |https://github.com/chernandezba/zesarux/releases/download/ZEsarUX-10.1/ZEsarUX_windows-10.1.zip|
|DeZogPlugin |https://github.com/maziac/DeZogPlugin/releases/download/v2.1.0/DeZogPlugin.dll|
|dezog-conf |https://raw.githubusercontent.com/maziac/DeZogPlugin/main/DeZogPlugin.dll.config|
|CSpect |http://www.javalemmings.com/public/zxnext/CSpect2_19_4.4.zip|
|ZEsarUX |https://github.com/chernandezba/zesarux/releases/download/ZEsarUX-10.1/ZEsarUX_windows-10.3.zip|
|sjasmplus* |https://github.com/z00m128/sjasmplus/releases/download/v1.20.1/sjasmplus-1.20.1.win.zip|
|hdfmonkey |http://uto.speccy.org/downloads/hdfmonkey_windows.zip|
|sdcard |http://www.zxspectrumnext.online/cspect/cspect-next-<SIZE>.zip|
|core-3 sdcard|https://www.specnext.com/distro/22.09/sn-emulator-22.09.zip|
|core-3 sdcard|https://github.com/taylorza/zxenv/raw/main/images/tbblue_core_3_02_00_os_2_08.zip|

* - sjasmplus builds for Linux and Mac are hosted in this repository and built by me from the original source code without any changes

Expand All @@ -96,9 +94,9 @@ This does what I needed for now, but I would like to do add the following suppor

- [x] Improve the handling of command line arguments so that more options can be speficied
- [x] Support command line options selecting the SD Card image to install
- [ ] Move projects into a project folder under the development environment
- [x] Move projects into a project folder under the development environment
- [x] Add support for ZEsarUX emulator
- [ ] Add support for an external config file that can override the links used to get the resources
- [x] Add support for an external config file that can override the links used to get the resources
- [x] Add support for setting up the environment on a Mac
- [x] Add support for setting up the environment on Linux
- [ ] Cleanup the code so that it makes more intelligent decisions about paths
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "zxenv",
Short: "CLI for the ZX Spectrum Next development environment v0.0.10",
Long: `CLI for the ZX Spectrum Next development environment v0.0.10`,
Short: "CLI for the ZX Spectrum Next development environment v0.0.12",
Long: `CLI for the ZX Spectrum Next development environment v0.0.12`,
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand Down
44 changes: 43 additions & 1 deletion internal/engine/development.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package engine

import (
"encoding/json"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -38,6 +39,7 @@ func (s Sources) resolve(name string) (string, error) {
}

var sources = Sources{
Source{Name: "sources", Arch: "", OS: "", Url: "https://github.com/taylorza/zxenv/blob/main/sources.json?raw=true"},
Source{Name: "cspect", Arch: "", OS: "", Url: "https://www.dropbox.com/s/6hcl37zyqqars4q/CSpect2_19_4_3.zip?dl=1"},
Source{Name: "zesarux", Arch: "amd64", OS: "windows", Url: "https://github.com/chernandezba/zesarux/releases/download/ZEsarUX-10.3/ZEsarUX_windows-10.3.zip"},
Source{Name: "core3", Arch: "", OS: "", Url: "https://github.com/taylorza/zxenv/raw/main/images/tbblue_core_3_02_00_os_2_08.zip"},
Expand All @@ -57,7 +59,12 @@ func SetupDevelopment(env *Environment) error {
fmt.Printf("SD Card Size: %v\n", env.SDSize)
fmt.Println()

err := makeDirectories(env)
err := downloadSources(env)
if err != nil {
fmt.Println(err)
}

err = makeDirectories(env)
if err != nil {
return err
}
Expand Down Expand Up @@ -90,6 +97,41 @@ func SetupDevelopment(env *Environment) error {
return nil
}

func downloadSources(env *Environment) error {
exePath, err := os.Executable()
if err != nil {
return fmt.Errorf("failed to resolve executable path (%w)", err)
}

dir := path.Dir(exePath)
sourcesFile := filepath.Join(dir, "sources.json")

if _, err := os.Stat(sourcesFile); os.IsNotExist(err) {
sourcesFile = filepath.Join(env.BasePath, "sources.json")
}

_, err = os.Stat(sourcesFile)
if os.IsNotExist(err) {
fmt.Println("Downloading sources")
err = download("sources", sourcesFile)
}

if err != nil {
return fmt.Errorf("failed to acquire latest sources.json (%w)", err)
}

sourcesBytes, err := os.ReadFile("sources.json")
if err != nil {
fmt.Printf("failed to read sources.json (%s)\n", err)
}

err = json.Unmarshal(sourcesBytes, &sources)
if err != nil {
return fmt.Errorf("failed to parse sources.json (%s)\n", err)
}
return nil
}

func makeDirectories(env *Environment) error {
err := os.MkdirAll(env.TempPath(), 0777)
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions internal/engine/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@ import (
var tmplfs embed.FS

type project struct {
BasePath string
DevPath string
Emulator string
Name string
Type string
}

func CreateProject(env *Environment, name string, projType string) error {
devpath, err := filepath.Abs(env.BasePath)
basepath, err := filepath.Abs(env.BasePath)
if err != nil {
return err
}
basepath = filepath.ToSlash(basepath)

devpath = filepath.ToSlash(devpath)
p := project{devpath, env.Emulator, name, projType}
devpath := filepath.ToSlash(filepath.Join(basepath, "projects"))
p := project{basepath, devpath, env.Emulator, name, projType}

os.MkdirAll(filepath.Join(devpath, p.Name, "inc"), 0777)
os.MkdirAll(filepath.Join(devpath, p.Name, "src"), 0777)
Expand Down
36 changes: 3 additions & 33 deletions internal/engine/templates/project/launch.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"spotCount": 10
},
"startAutomatically": false,
"commandsAfterLaunch": [
"-logpoint enable"
"commandsAfterLaunch": [
],

// connect to the CSpect emulator via TCIP
Expand All @@ -29,18 +28,6 @@
"port": 11000
},
"rootFolder": "${workspaceFolder}",
"listFiles": [
{
"path": "project.lst",
"useFiles": true,
"asm": "{{.DevPath}}/emulator/sjasmplus",
{{if (eq .Type "DRV")}}
"mainFile": "src/driver.asm"
{{else}}
"mainFile": "src/main.asm"
{{end}}
}
],
"disassemblerArgs": {
"esxdosRst": true
},
Expand All @@ -49,7 +36,6 @@
{{else if (eq .Type "DOT")}}
"load": "{{.Name}}",
{{end}}
"skipInterrupt": false,
"smallValuesMaximum": 513,
"tmpDir": ".tmp"
}
Expand All @@ -70,8 +56,7 @@
"spotCount": 10
},
"startAutomatically": false,
"commandsAfterLaunch": [
"-logpoint enable"
"commandsAfterLaunch": [
],
"disassemblerArgs": {
"esxdosRst": true
Expand Down Expand Up @@ -104,26 +89,13 @@
},
"startAutomatically": false,
"commandsAfterLaunch": [
"-logpoint enable"
],
"zxnext":
{
"serial": "<SERIAL PORT>"
},

"rootFolder": "${workspaceFolder}",
"listFiles": [
{
"path": "project.lst",
"useFiles": true,
"asm": "{{.DevPath}}/emulator/sjasmplus",
{{if (eq .Type "DRV")}}
"mainFile": "src/driver.asm"
{{else}}
"mainFile": "src/main.asm"
{{end}}
}
],
"disassemblerArgs":
{
"esxdosRst": true
Expand All @@ -133,7 +105,6 @@
{{else if (eq .Type "DOT")}}
"load": "{{.Name}}",
{{end}}
"skipInterrupt": false,
"smallValuesMaximum": 513,
"tmpDir": ".tmp"
},
Expand Down Expand Up @@ -163,8 +134,7 @@
"codeCoverageEnabled": true
},
"startAutomatically": false,
"commandsAfterLaunch": [
"-logpoint enable",
"commandsAfterLaunch": [
"-wpmem enable"
],
"disassemblerArgs": {
Expand Down
14 changes: 7 additions & 7 deletions internal/engine/templates/project/tasks.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"label": "Build",
"type": "shell",
"command": "{{.DevPath}}/emulator/sjasmplus",
"command": "{{.BasePath}}/emulator/sjasmplus",
"args": [
{{if (eq .Type "DRV")}}
"src/driver.asm",
Expand Down Expand Up @@ -41,11 +41,11 @@
"label": "Update SDCard",
"type": "shell",
{{if (eq .Type "NEX")}}
"command": "{{.DevPath}}/emulator/hdfmonkey put {{.DevPath}}/sdcard/tbblue-dev.sd {{.Name}}.nex",
"command": "{{.BasePath}}/emulator/hdfmonkey put {{.BasePath}}/sdcard/tbblue-dev.sd {{.Name}}.nex",
{{else if (eq .Type "DOT")}}
"command": "{{.DevPath}}/emulator/hdfmonkey put {{.DevPath}}/sdcard/tbblue-dev.sd {{.Name}} /dot/",
"command": "{{.BasePath}}/emulator/hdfmonkey put {{.BasePath}}/sdcard/tbblue-dev.sd {{.Name}} /dot/",
{{else}}
"command": "{{.DevPath}}/emulator/hdfmonkey put {{.DevPath}}/sdcard/tbblue-dev.sd {{.Name}}.drv",
"command": "{{.BasePath}}/emulator/hdfmonkey put {{.BasePath}}/sdcard/tbblue-dev.sd {{.Name}}.drv",
{{end}}

"dependsOrder": "sequence",
Expand All @@ -59,9 +59,9 @@
"label": "Launch CSpect",
"type": "shell",
{{if (isWindows)}}
"command": "{{.DevPath}}/emulator/CSpect.exe -r -w2 -brk -zxnext -nextrom -mmc={{.DevPath}}/sdcard/tbblue-dev.sd",
"command": "{{.BasePath}}/emulator/CSpect.exe -esc -r -w2 -brk -zxnext -nextrom -mmc={{.BasePath}}/sdcard/tbblue-dev.sd",
{{else}}
"command": "mono {{.DevPath}}/emulator/CSpect.exe -r -w2 -brk -zxnext -nextrom -mmc={{.DevPath}}/sdcard/tbblue-dev.sd",
"command": "mono {{.BasePath}}/emulator/CSpect.exe -esc -r -w2 -brk -zxnext -nextrom -mmc={{.BasePath}}/sdcard/tbblue-dev.sd",
{{end}}
"dependsOrder": "sequence",
"dependsOn": [
Expand All @@ -71,7 +71,7 @@
{
"label": "Launch ZEsarUX",
"type": "shell",
"command": "{{.DevPath}}/emulator/zesarux --romfile {{.DevPath}}/emulator/tbblue_loader.rom --mmc-file {{.DevPath}}/sdcard/tbblue-dev.mmc --enable-mmc --enable-divmmc-ports --machine tbblue --realvideo --enable-remoteprotocol",
"command": "{{.BasePath}}/emulator/zesarux --romfile {{.BasePath}}/emulator/tbblue_loader.rom --mmc-file {{.BasePath}}/sdcard/tbblue-dev.mmc --enable-mmc --enable-divmmc-ports --machine tbblue --realvideo --enable-remoteprotocol",
"dependsOrder": "sequence",
"dependsOn": [
]
Expand Down
2 changes: 1 addition & 1 deletion sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"Name": "cspect",
"Arch": "",
"OS": "",
"Url": "https://www.dropbox.com/s/6hcl37zyqqars4q/CSpect2_19_4_3.zip?dl=1"
"Url": "https://www.dropbox.com/s/vbi5joh78zvwa90/CSpect2_19_4_4.zip?dl=1"
},
{
"Name": "zesarux",
Expand Down

0 comments on commit c4dbba5

Please sign in to comment.