Command line assembler

PhilHaw
Posts: 65
Joined: Thu Mar 07, 2019 5:37 pm

Re: Command line assembler

Post by PhilHaw »

So far so good Frank but I'm struggling with getting the correctly formatted command to pass to Windows cmd.exe via the shell_cmd option in the Sublime Text build file.

In the Linux version it's:

Code: Select all

// default build type is assemble only

      "shell_cmd": "if mono FXCoreCmdAsm.exe -a '$file_path'/'$file_name'; then echo 'Hex saved to '$file_path'/'$file_base_name'.hex'; else cat '$file_path'/'$file_base_name'.lst; fi",
I can get it to assemble ok using the simplified command:

Code: Select all

"shell_cmd" : "FXCoreCmdAsm.exe -a $file"
but I keep getting errors e.g. "-a was unexpected at this time" if I try the more complex shell command string. I need a Windows command line guru!

Phil.
Philip Hawthorne

Blue Nebula Development Team
PhilHaw
Posts: 65
Joined: Thu Mar 07, 2019 5:37 pm

Re: Command line assembler

Post by PhilHaw »

Update: In case there may be spaces in the file path and/or filename, it should have quotes added around it, which have to be 'escaped' with '\'

Code: Select all

"shell_cmd" : "FXCoreCmdAsm.exe -a \"$file_path/$file_name\"",
Philip Hawthorne

Blue Nebula Development Team
Frank
Posts: 159
Joined: Sun May 03, 2015 2:43 pm

Re: Command line assembler

Post by Frank »

I've been playing with this and I think part of the problem is Sublime Text seems to like a POSIX type environment which Windows is not. The console in Sublime Text, at least on Wndows, is not interactive and requires escaping of things, i.e. pathing in Windows uses \ so we end up with \\ to escape it, we can use / in the build file but it seems that does not always translate well when passed to the Windows system. It may be me not handling things properly in the file.

It may be easier to take the notepad++ approach and call a batch file from Sublime Text to handle the actual build, displaying errors, etc.
PhilHaw
Posts: 65
Joined: Thu Mar 07, 2019 5:37 pm

Re: Command line assembler

Post by PhilHaw »

Sublime text uses 'build files' to run your build and this is what Matthew wrote for the Linux version. They are JSON files and I'm sort of getting it to work but every time I try to put the 'if' statement into the command it gives me an error, usually "-a was unexpected at this time". I'm assuming from the Linux version that the Assembler returns a value depending on whether it succeeded or there was an error, and we need to check for this return value?

As regards the / versus \, JSON treats the \ as an escape character so, for example, we can include quotes around the file name to avoid any problems with spaces by using \"$file\"
Philip Hawthorne

Blue Nebula Development Team
Frank
Posts: 159
Joined: Sun May 03, 2015 2:43 pm

Re: Command line assembler

Post by Frank »

The 'if' is a part of most POSIX shells like bash and I believe Sublime on Mac/Linux calls the local shell. Since it seems that the console in Sublime Text on Windows is not calling a true shell it is unlikely you will get it to work. If Sublime is calling cmd.exe then make sure the 'if' is correct for Windows and not POSIX.

FYI I wrote the Linux version, I did base it on Matthews Mac version. Since MacOS and Linux are both POSIX compliant systems it was an easy conversion. Moving it to Windows is a different story as Windows is not POSIX based so things that just work in Linux/MacOS won't in Windows. This is why I may try to do a batch file based one.
PhilHaw
Posts: 65
Joined: Thu Mar 07, 2019 5:37 pm

Re: Command line assembler

Post by PhilHaw »

Frank, sorry for mis-attributing the Linux build file to Matthew rather than you!

The FX-Core.sublime-build file I created does actually work as far as Assembling the code, running it from RAM and End run from RAM are concerned. So, it does basically the same as what the Notepad++ batch file approach does.

If I am reading the Linux version correctly, does it allow the user to jump to the line in the source code where the error occurred? It would be nice if that could be made to work in Sublime text for Windows too but for now, I will settle for being able to replicate what Notepad++ does.

Here's my build file. It should be saved as FX-Core.sublime-build in Sublime Text's User directory (Click Preferences > Browse packages ... to locate the User folder)

Code: Select all

{
	// set working dir for relative paths
// change this to suit the location of FXCoreAsm.exe
      "working_dir" : "C:/Program Files (x86)/Experimental Noize/FXCore Assembler",

      "file_patterns": ["*.fxc","*.FXC"],

// REGEX for capturing errors

// file regex finds the name of the file for highlighting errors
      "file_regex" : "Source File: (.+)$",

// line regex finds the errors in the output .LST
      "line_regex" : "ERROR.* ([0-9]+):([0-9]+)?(.+)$",

// allow user to cancel "run from RAM" mode by pressing Ctrl+Pause/Break
      "cancel":
      {
            "cmd" : "FXCoreCmdAsm.exe -ee",
      },

// default build type is assemble only
"cmd": ["FXCoreCmdAsm.exe", "-a", "$file"],

"variants": [

{
	"name": "Run from RAM",
	"cmd" : "FXCoreCmdAsm.exe -re -i 0x30 \"$file\"",
},

{
	"name": "End run from RAM",
	"cmd" : "FXCoreCmdAsm.exe -ee -i 0x30",
},

]

}
Philip Hawthorne

Blue Nebula Development Team
Frank
Posts: 159
Joined: Sun May 03, 2015 2:43 pm

Re: Command line assembler

Post by Frank »

The 2 regex statements are what Sublime Text uses to identify and mark the lines with errors. So it does do this on Linux, I just went and tried it to make sure.

See https://www.sublimetext.com/docs/build_systems.html and search for line_regex which explains the things it is looking for.

My understanding is this is run against the output of the build command so this is why the listing file is cat'd at the end of a command that detects an error. I may be incorrect here as I did lift this part from Matthew's original file.

I am assuming Sublime Text has regex built in so it should be possible to make it work in Windows. If it is actually using the system regex then it may be more of an issue as Windows does not have a system regex.
Frank
Posts: 159
Joined: Sun May 03, 2015 2:43 pm

Re: Command line assembler

Post by Frank »

So I have something that works by calling a batch file, it is only working for the default assemble right now but you should be able to expand the batch file and edit fxcore_hw.sublime-build to cover everything or add multiple batch files.

First put this in "C:\Program Files (x86)\Experimental Noize\FXCore Assembler" and name it assemble_st.cmd

Code: Select all

@echo off
"C:\Program Files (x86)\Experimental Noize\FXCore Assembler\FXCoreCmdAsm.exe" %1 %2
if %errorlevel% EQU 0 (echo. & echo NO ERRORS ) Else ( type %3 )
Then in fxcore_hw.sublime-build change it to:

Code: Select all

{
	// set working dir for relative paths
// change this to suit the location of FXCoreAsm.exe
      "working_dir" : "C:/Program Files (x86)/Experimental Noize/FXCore Assembler",

      "file_patterns": ["*.fxc","*.FXC"],

// REGEX for capturing errors

// file regex finds the name of the file for highlighting errors
      "file_regex" : "Source File: (.+)$",

// line regex finds the errors in the output .LST
      "line_regex" : "ERROR.* ([0-9]+):([0-9]+)?(.+)$",

// allow user to cancel "run from RAM" mode by pressing Ctrl+Pause/Break
      "cancel":
      {
            "cmd" : "FXCoreCmdAsm.exe -ee",
      },

// default build type is assemble only
//"cmd": ["FXCoreCmdAsm.exe", "-a", "$file"],
"cmd" : "assemble_st.cmd -a \"$file\" \"$file_path\\\\$file_base_name.lst\"",

"variants": [

{
	"name": "Run from RAM",
	"cmd" : "FXCoreCmdAsm.exe -re -i 0x30 \"$file\"",
},

{
	"name": "End run from RAM",
	"cmd" : "FXCoreCmdAsm.exe -ee -i 0x30",
},

]

}
Now it will mark the error lines in the editor
PhilHaw
Posts: 65
Joined: Thu Mar 07, 2019 5:37 pm

Re: Command line assembler

Post by PhilHaw »

Many thanks Frank. I haven't been able to get this to work yet: it's giving me a 'No Build System' when I try to build which probably means an error in the build file?

The batch file works ok if I run it from the Windows command window. Tried to post a screenshot but the image doesn't appear :cry:

Update: I got it working! Your build file above is missing the opening brace {

I just need to give it a proper test with some deliberate errors to make sure it all works.

Phil.
Philip Hawthorne

Blue Nebula Development Team
PhilHaw
Posts: 65
Joined: Thu Mar 07, 2019 5:37 pm

Re: Command line assembler

Post by PhilHaw »

The error handling works well and double-clicking on an ERROR: line in the build report jumps to the corresponding line in the source code - brilliant!

I could be quite happy with this as I normally run the Assemble first to check for errors before attempting to run the program from RAM on the Dev Board.

Phil.
Philip Hawthorne

Blue Nebula Development Team
Post Reply