Z80 Environment Final Edition
Welcome to another blog update for the ZX Spectrum Next and after some testing, my decision for my final z80 development environment.
So read on and see which route I went in the end and if you are deciding to go the same way.
Code editor
Sublime Text has now been uninstalled and it's full steam ahead, with VSCode!
So what made me come to this decision? Well although I initially liked Sublime Text for it's simplicity and clean interface, in fact I still do, VSCode tempted me with it's useful extensions and the automation of build/run features in the JSON file settings. (Maybe this can be done in Sublime, however, I didn't explore that route further.)
What's changed?
In my last post, I talked about the JSON file set up and having automated processes for build, run and build/run combined using the F5 and F6 keys.
I also talked about finding that I didn't require the use of an SD card image in the CSpect folder or of hdfmonkey to place the NEX output file into this SD image file.
Since then, I have discovered that although you can code z80 in some circumstances and run the NEX file without loading this to the SD card, this is not always the case.
It would appear that if you are fully taking over the machine and not calling the ROMS in any way, then this is fine; however, if you are calling some feature of the Speccy Next ROMS in the code, you first have to load these. As the ROMS are on the SD card and loaded by CSpect from the image file, this would make sense that you need the SD card image facility. (Well this is my understanding of it, but I'm not 100% on the finer detail, so any info you might have is welcome.)
For instance I made a simple "Hello World" program, which literally wrote the words to the screen after changing the border colour. However much I tried, I couldn't get it to run in CSpect. The MAP and NEX files built, but when running these in CSpect, the screen just went to the Spectrum boot screen.
After some trial and error, I manually tried loading the built NEX file using the command prompt and hdfmonkey, to an SD card image and found it worked. I guess the printing of the characters to the screen are calling some feature of the ROMS.
So with this in mind, I now have a new addition to my JSON file which builds and loads the NEX file to the SD card image, in my CSpect folder.
I didn't need to download hdfmonkey, as that was already in the CSpect download folder, but now I have the best of both worlds, with all options of the build/run process.
Let's have a reminder of the file structure and what it looks like now.
C:\SpecNextDev
\cspect
[All the files from the downloaded CSpect folder placed here]
hdfmonkey.exe (Included with CSpect)
sdcard.mmc (Will create later)
\sjasmplus
[All the files from the sjasmplus folder placed here]
\Projects
\.vscode
tasks.json (We will create this later)
\Project1
\Project2
\HelloWorld
JSON addition
Let's sort the updates to the JSON file before looking at creating the SD card image.
Open VSCode and the projects folder, then locate the "tasks.json" file in the ".vscode" folder that was created in the last post and open it to a tab.
I kept all the same processes as before, but added another feature to the top section of the file as follows:
{ "label": "Build to SD Image", "type": "shell", "command": "cmd.exe", "args": [ "/c", "\"C:\\SpecNextDev\\sjasmplus\\sjasmplus.exe\" ${file} --zxnext=cspect --msg=all --fullpath --outprefix=${fileDirname}\\ && \"C:\\SpecNextDev\\cspect\\hdfmonkey.exe\" put C:\\SpecNextDev\\cspect\\sdcard.mmc ${fileDirname}\\${fileBasenameNoExtension}.nex \\ && \"C:\\SpecNextDev\\cspect\\CSpect.exe\" -brk -w3 -50 -vsync -zxnext -nextrom -map=${fileDirname}\\${fileBasenameNoExtension}.map -mmc=C:\\SpecNextDev\\cspect\\sdcard.mmc" ], "group": { "kind": "build", "isDefault": true }, "problemMatcher": [] }
Don't add this yet as I will show the full JSON script below to copy and paste, which will make things easier. Just have a look so you know where it is in the full version.
NOTE - The full json file script below has slight differences from the previous post version and includes this section above, so copy and paste all the script below and fully replace the json script if you had followed the previous post.
This assembles the ASM source file, creating MAP and NEX files for both, but then instead of first running CSpect, it uses hdfmonkey to copy the NEX file to the SD card image. It then runs CSpect, however, this time it loads the SD card image instead of the NEX file.
It does this so you can then select the NEX file from directly within the emulator, as if you were doing this on an actual Speccy Next.
Here is the version to copy and paste, you can see the above section near the top:
{ "version": "2.0.0", "tasks": [ // This assembles with sjasmplus, copies the .nex file to the SD image with hdfmonkey and then runs cspect with the SD image (Use RUN BUILD TASK or F5) { "label": "Build to SD Image", "type": "shell", "command": "cmd.exe", "args": [ "/c", "\"C:\\SpecNextDev\\sjasmplus\\sjasmplus.exe\" ${file} --zxnext=cspect --msg=all --fullpath --outprefix=${fileDirname}\\ && \"C:\\SpecNextDev\\cspect\\hdfmonkey.exe\" put C:\\SpecNextDev\\cspect\\sdcard.mmc ${fileDirname}\\${fileBasenameNoExtension}.nex \\ && \"C:\\SpecNextDev\\cspect\\CSpect.exe\" -brk -w3 -50 -vsync -zxnext -nextrom -map=${fileDirname}\\${fileBasenameNoExtension}.map -mmc=C:\\SpecNextDev\\cspect\\sdcard.mmc" ], "group": { "kind": "build", "isDefault": true }, "problemMatcher": [] }, // This assembles with sjasmplus and creates the .map and .nex files (Use RUN TASK or F6) { "label": "Assemble with Sjasmplus", "type": "shell", "command": "\"C:\\SpecNextDev\\sjasmplus\\sjasmplus.exe ${file} --zxnext=cspect --msg=all --fullpath --outprefix=${fileDirname}\\", "group": { "kind": "test", "isDefault": true }, "problemMatcher": [] }, // This runs cspect with the already assembled .map and .nex files (Use RUN TASK or F6) { "label": "Run in CSpect", "type": "shell", "command": "\"C:\\SpecNextDev\\cspect\\CSpect.exe -brk -w3 -50 -vsync -zxnext -nextrom -map=${fileDirname}\\${fileBasenameNoExtension}.map -mmc=${fileDirname}\\ ${fileDirname}\\${fileBasenameNoExtension}.nex\"", "group": { "kind": "test", "isDefault": true }, "problemMatcher": [] }, // This does both the assemble with sjasmplus and then runs the .map and .nex files with cspect. It does NOT build to the SD image (Use RUN TASK or F6) { "label": "Build and Run", "type": "shell", "command": "cmd.exe", "args": [ "/c", "\"C:\\SpecNextDev\\sjasmplus\\sjasmplus.exe\" ${file} --zxnext=cspect --msg=all --fullpath --outprefix=${fileDirname}\\ && \"C:\\SpecNextDev\\cspect\\CSpect.exe\" -brk -w3 -50 -vsync -zxnext -nextrom -map=${fileDirname}\\${fileBasenameNoExtension}.map -mmc=${fileDirname}\\ ${fileDirname}\\${fileBasenameNoExtension}.nex" ], "group": { "kind": "test", "isDefault": true }, "problemMatcher": [] }, ] }
All the other code is still here, but now I have the facility to do any of the following:
- Assemble source file with sjasmplus, creating the MAP and NEX files.
- Run the MAP and NEX files with CSpect.
- Do both of these tasks to build and run automatically.
- Use F5 to assemble the source file creating MAP and NEX files, copy NEX to SD card and run CSpect.
Of note, there is one more thing I would like to work out, but haven't yet (if possible) and that is how to automate the process of running the NEX file on the SD card image. I know it's only a minor thing but once CSpect has loaded with the SD image, it's a bit of a chore to have to go through the menu and select the NEX file to run. It would be good if there was a setting/flag in CSpect to do this, something like "-mmc=/sdcard.mmc -start=/main.nex".
Maybe it's possible but I haven't seen how to do this. Let me know if you have any details.
SD Card
So now I get to the SD image file and there are a few ways to do this, one of which is to just download the image and use that; however, I had another idea which at first might seem a bit odd........ There is a method to my madness though!
So first I created 2 more folders in the C:\SpecNextDev folder. "SDCard" and "SpecNextFiles".
You can see here how these are set up and also what it will look like once the files are all downloaded from the Speccy Next site.
C:\SpecNextDev
\cspect
\sjasmplus
\Projects
\SDCard
cspect-next-1gb.img [Downloaded from Spec Next site]
enNextZX.rom [Downloaded from Spec Next site]
enNxtmmc.rom [Downloaded from Spec Next site]
hdfmonkey.exe [Another version copied from CSpect folder]
\SpecNextFiles [All files here extracted from cspect-next-1gb.img]
\apps
CONTRIBUTING.md
\demos
\docs
\dot
\extras
\games
\home
LICENSE.md
\machines
nextzxos
README.md
\src
\sys
TBBLUE.FW
TBBLUE.TBU
\tmp
You might be able to see where I am going with this.................... but what I wanted to do was be able to create multiple SD image files if required and also have the option to specify what size they were, not just be stuck to the 1gb version.
First see the links here to download what is required:
Before downloading, first copy and paste from the CSpect folder, another copy of hdfmonkey.exe to the newly created SDCard folder. (I know it is already there in CSpect, but it just makes things easier later and it is only 164Kb, so these days in PC terms, not a big issue to double up on the program.)
If you already have the Speccy Next distro files somewhere, or have backed up the files from your SD card that you use in the actual machine, then just paste them in the SpecNextFiles folder. Otherwise download the latest distro from the site above, but download the emulator version. There will be a link there and at the time of this post, it is version "sn-emulator-24.11.zip".
Unzip it somewhere and you will see 3 files, "cspect-next-1gb.img", "enNextZX.rom" and "enNxtmmc.rom". Put all the files in the SDCard folder as above. It's up to you if you want to delete these after, but I like to keep everything together for future use.
Copy and paste "enNextZX.rom" and "enNxtmmc.rom" to the CSpect folder.
Next I extracted the files from the downloaded image file "cspect-next-1gb.img" using OSFMount. This is a nifty free piece of software, but once installed you can mount the image file on your computer which then acts as a real SD card.
When mounted, open Windows file explorer, navigate to the SD drive and copy all the files from the image to the SpecNextFiles folder above. (You can then un-mount the image as no longer needed.)
Time to actually create the image file to use, this is surprisingly quick and easy.
Open the command prompt and CD to the SDCard folder, then using the commands below create a blank image file and put all the distro files in it:
CD C:\SpecNextDev\SDCard
hdfmonkey.exe create sdcard.mmc 512MB
hdfmonkey.exe put sdcard.mmc SpecNextFiles/* /
hdfmonkey.exe ls sdcard.mmc
You might now see that having hdfmonkey in this directory makes things a little easier.
This literally took seconds and is a damn sight easier than copying the files to an actual SD card, then using something like Win32DiskImager to create it!
If you want a different size of image file then just replace the 512MB with what ever size you want, e.g. 1GB or 2GB.
The PUT command placed all the files in the SpecNextFiles folder into the root of the image and if you want to check that all worked ok, then use the ls command above to see what is on the image file after.
Now that is done, all that is needed is to copy this new image, sdcard.mmc to the CSpect folder and everything is ready.
Other changes
So after testing some ASM code in the same way as mentioned in my last post, but this time building to the SD image file. I decided that although I wanted to keep my folder structure for projects with each one having it's own folder name, I now wanted to change the name of the ASM file inside the folder.
For example last time I had a folder for HelloWorld and an ASM file called HelloWorld.asm. Now I have the project folder name, HelloWorld, but the ASM file named as main.asm and again if I had another project, but this time called TestGame, I would also call the ASM file main.asm inside TestGame, instead of TestGame.asm.
The reason for this was that although it was good for all my programs to have their own named NEX file, when they loaded to the SD image I would soon have lot's of files cluttering up the root of the image. Doing it this way, for testing purposes, every time CSpect opened to the menu, I would only have 1 NEX file as it would overwrite the previous main file. This made things much easier.
So don't forget to change these 2 lines:
To:
CSPECTMAP "NAME.map"
SAVENEX OPEN "NAME.nex", Start, $ff40
To:
CSPECTMAP "main.map"
SAVENEX OPEN "main.nex", Start, $ff40
Do this for every project and everything should work well.Just to finish off this post, here is how my VSCode setup is now: (Of note, Ctrl+Shift+B does the same as F5 for me.)
So there it is, my z80 coding environment is complete! I hope this has helped in some way and that you come back for further updates now I'm at the stage of the fun coding part.
Let's see where this takes us............................ Have fun 👾
Comments
Post a Comment