HP-42S / Free42 Extension for Visual Studio Code
11-04-2018, 04:14 PM
Post: #1
 Thomas Okken Senior Member Posts: 823 Joined: Feb 2014
HP-42S / Free42 Extension for Visual Studio Code
An Extension for editing HP-42S / Free42 code in Visual Studio Code has been made available in the Visual Studio Marketplace: https://marketplace.visualstudio.com/ite...42s-free42

I haven't tried it myself, but the previews look promising.

11-04-2018, 08:08 PM
Post: #2
 Thomas Klemm Senior Member Posts: 1,448 Joined: Dec 2013
RE: HP-42S / Free42 Extension for Visual Studio Code
11-04-2018, 10:47 PM
Post: #3
 tcab Member Posts: 131 Joined: Dec 2017
RE: HP-42S / Free42 Extension for Visual Studio Code
This looks great!

The extension appears and installs ok in my Visual Studio Code (the free editor) on my Mac but I'm not getting the promised behaviours. I've tried both *.hp42 and *.free42 file extensions but only the latter does any syntax highlighting at all, but not the fancy HP42 syntax completion. And the formatting menu is not appearing either. I've tried restarting visual studio code. Has anyone gotten this working?
11-04-2018, 11:33 PM (This post was last modified: 11-04-2018 11:35 PM by Sylvain Cote.)
Post: #4
 Sylvain Cote Senior Member Posts: 1,073 Joined: Dec 2013
RE: HP-42S / Free42 Extension for Visual Studio Code
Tried it on Visual Studio Code (1.28.2) over macOS High Sierra (10.13.6).
Installation, color coding, syntax completion & formatting works perfectly.
I am not able to encode or decode the program, I do not see the options in any menu or contextual menu.
I have read the how-to, but it is not clear for me how you do it and unfortunately the screen capture is in German.
Some help will be appreciated, thank you!
Sylvain
11-05-2018, 12:24 AM
Post: #5
 Thomas Klemm Senior Member Posts: 1,448 Joined: Dec 2013
RE: HP-42S / Free42 Extension for Visual Studio Code
(11-04-2018 10:47 PM)tcab Wrote:  I've tried both *.hp42 and *.free42 file extensions but only the latter does any syntax highlighting at all
The suffix .hp42s works for me.

Quote:And the formatting menu is not appearing either.

Try: right click
Format Document ⌥ ⇧ F

(11-04-2018 11:33 PM)Sylvain Cote Wrote:  I am not able to encode or decode the program, I do not see the options in any menu or contextual menu.

Try: right click
Command Palette… ⇧ ⌘ P

Start typing: encode code

The following should show up:
hp42s/free42: Encode Code

HTH
Thomas
11-05-2018, 01:20 AM
Post: #6
 tcab Member Posts: 131 Joined: Dec 2017
RE: HP-42S / Free42 Extension for Visual Studio Code
@Thomas - thanks for those tips. Indeed it looks like the file extension has to be .hp42s not .hp42 (looks like a typo in the plugin documentation). Raw exporting works in the way you say, too.

Formatting works and strips line numbers etc. It would be nice, I think, to have a command to add line numbers back. I remember, in the past, I had trouble pasting RPN code into Free42 unless it had line numbers - even if all the line numbers were 00. Though... I just tried again without line numbers and things pasted ok into Free42. Hmm.
11-05-2018, 06:05 AM (This post was last modified: 11-05-2018 01:10 PM by Thomas Klemm.)
Post: #7
 Thomas Klemm Senior Member Posts: 1,448 Joined: Dec 2013
RE: HP-42S / Free42 Extension for Visual Studio Code
(11-05-2018 01:20 AM)tcab Wrote:  It would be nice, I think, to have a command to add line numbers back.

This command inserts line numbers to the files:
Code:
perl -i~ -ne 'printf "%02d $_",$.' <files ...>

The original files are renamed to contain a tilde (~) as suffix.
This can be changed of course. See perl -h:
Code:
  -i[extension]     edit <> files in place (makes backup if extension supplied)

If you use that command often you can make it a function and add it e.g. to your ~/.bash_profile:
Code:
function add_line_numbers () {     perl -i~ -ne 'printf "%02d $_",$.' "\$@" }

Use %03d instead of %02d if you prefer 3-digit numbers.

Cheers
Thomas
11-05-2018, 10:04 AM
Post: #8
 Thomas Okken Senior Member Posts: 823 Joined: Feb 2014
RE: HP-42S / Free42 Extension for Visual Studio Code
(11-05-2018 01:20 AM)tcab Wrote:  It would be nice, I think, to have a command to add line numbers back. I remember, in the past, I had trouble pasting RPN code into Free42 unless it had line numbers - even if all the line numbers were 00. Though... I just tried again without line numbers and things pasted ok into Free42. Hmm.

That was fixed earlier this year:

Quote:2018-01-07: release 2.0.10

* Program Paste without line numbers didn't handle certain numbers,
specifically, those that started with a digit and didn't consist of only
digits. Fixed.

2018-01-07: release 2.0.9

* Program Paste no longer requires line numbers.
[...]
11-05-2018, 10:52 AM (This post was last modified: 11-05-2018 10:53 AM by Sylvain Cote.)
Post: #9
 Sylvain Cote Senior Member Posts: 1,073 Joined: Dec 2013
RE: HP-42S / Free42 Extension for Visual Studio Code
Thanks Thomas,

Perl call from command line and from .profile worked, same thing for Palette / encode code.
It does not seems to, but does it have a way to decode a hex or raw file ?

Best regards,

Sylvain
11-05-2018, 01:01 PM
Post: #10
 Heilingbrunner Junior Member Posts: 8 Joined: Nov 2018
RE: HP-42S / Free42 Extension for Visual Studio Code
Hello Everybody,

i am happy to see you tried my extension.

I had thought about decoding raw code to text back again, but i think the most use case is encoding from code to raw format.

Jochen
11-05-2018, 01:08 PM
Post: #11
 Thomas Klemm Senior Member Posts: 1,448 Joined: Dec 2013
RE: HP-42S / Free42 Extension for Visual Studio Code
(11-05-2018 10:52 AM)Sylvain Cote Wrote:  It does not seems to, but does it have a way to decode a hex or raw file ?

I don't think so. But you can use this online decoder.

Cheers
Thomas
11-07-2018, 09:23 AM
Post: #12
 Heilingbrunner Junior Member Posts: 8 Joined: Nov 2018
RE: HP-42S / Free42 Extension for Visual Studio Code
I have two questions:

1. Why do we need line numbers in the code ?
The VSC editor already shows line numbers.

2. Why is the last ending END command ignored in the { <size>-Byte Prgm } display, but the raw file has three byte more ?
11-07-2018, 04:41 PM
Post: #13
 Thomas Klemm Senior Member Posts: 1,448 Joined: Dec 2013
RE: HP-42S / Free42 Extension for Visual Studio Code
(11-07-2018 09:23 AM)Heilingbrunner Wrote:  Why do we need line numbers in the code ?

While editing a file in vscode I don't care about line numbers.
The same holds if I load a .raw file into an emulator.
However when I enter a program manually into a real calculator it helps to have line numbers.
If I miss a command it helps to find the error.

Quote:The VSC editor already shows line numbers.

True. But when the x-Byte Prgm line is generated it is off by one.

HP-42S
Code:
00 { 20-Byte Prgm } 01▸LBL "TREE" 02 X<>Y 03 - 04 LASTX 05 X↑2 06 1ᴇ4 07 + 08 SQRT 09 ÷ 10 × 11 END

Visual Studio Code
Code:
 1    { 23-Byte Prgm }  2    LBL "TREE"  3    X<>Y  4    -  5    LASTX  6    X↑2  7    1ᴇ4  8    +  9    SQRT 10    ÷ 11    × 12    END

Cheers
Thomas
11-07-2018, 05:21 PM
Post: #14
 Thomas Okken Senior Member Posts: 823 Joined: Feb 2014
RE: HP-42S / Free42 Extension for Visual Studio Code
(11-07-2018 09:23 AM)Heilingbrunner Wrote:  Why is the last ending END command ignored in the { <size>-Byte Prgm } display

That's what the real HP-42S does. It is strange, since the END is, in fact, a part of the program... but that's the way it is.
11-07-2018, 09:52 PM
Post: #15
 Heilingbrunner Junior Member Posts: 8 Joined: Nov 2018
RE: HP-42S / Free42 Extension for Visual Studio Code
Ok, i will add a command for the line numbers.
11-09-2018, 09:24 AM
Post: #16
 Heilingbrunner Junior Member Posts: 8 Joined: Nov 2018
RE: HP-42S / Free42 Extension for Visual Studio Code
Hi,

in version 0.0.4, i improved the document formatter. It inserts/refreshes the line numbers.
The encoder although detects wrong line numbers.

Regards.
11-11-2018, 09:01 AM
Post: #17
 Dieter Senior Member Posts: 2,398 Joined: Dec 2013
RE: HP-42S / Free42 Extension for Visual Studio Code
(11-05-2018 01:01 PM)Heilingbrunner Wrote:  I had thought about decoding raw code to text back again, but i think the most use case is encoding from code to raw format.

I can't say much about the 42s and Free42 in this regard, but for the HP-41 I use hp41uc (Leo Duran's HP41 user code compiler/decompiler) in both ways. Raw files are great for transferring programs or saving/loading programs for use with an emulator, e.g. Warren Furlow's V41. But I also like the decompiler option very much, as it generates nice program listings. Which can be posted here, for instance. There are even several formatting options.

Dieter
11-16-2018, 11:18 PM (This post was last modified: 11-16-2018 11:31 PM by Heilingbrunner.)
Post: #18
 Heilingbrunner Junior Member Posts: 8 Joined: Nov 2018
RE: HP-42S / Free42 Extension for Visual Studio Code
Hi,
Now the extension supports multi programs in a *hp42s/*free42 file. The formatter and encoder will update the line numbers and program sizes as required for manual input on a original HP-42S (tcab). The program size calculation behaves as the original.
The next feature will be the decoder. But this will take some time.
Hope you can use it.

Regards.
11-17-2018, 09:54 PM
Post: #19
 Thomas Klemm Senior Member Posts: 1,448 Joined: Dec 2013
RE: HP-42S / Free42 Extension for Visual Studio Code
Thanks for the update. However I noticed a weird behaviour when an error occurs during encoding.

Code:
LBL "TOO-LONG-FOR-A-LABEL"

Encode this to get:
Code:
00 { Error [1, 01]: Code: 'LBL "TOO-LONG-FOR-A-LABEL"'; Message: 'line number not correct' } LBL "TOO-LONG-FOR-A-LABEL"
The message is a bit misleading.

Correct the label:
Code:
00 { Error [1, 01]: Code: 'LBL "TOO-LONG-FOR-A-LABEL"'; Message: 'line number not correct' } LBL "SHORT"

Encode again to get:
Code:
00 { 1-Byte Prgm } 00 { 9-Byte Prgm } LBL "SHORT"

Format to get some strange line numbering:
Code:
01 00 { 1-Byte Prgm } 02 00 { 9-Byte Prgm } 01 LBL "SHORT"

Is there an easier way to remove line numbers instead of using ⇧ ⌥ ⌘ with cursors to select a block and delete it?

Kind regards
Thomas
11-18-2018, 07:58 AM (This post was last modified: 11-18-2018 08:06 AM by Heilingbrunner.)
Post: #20
 Heilingbrunner Junior Member Posts: 8 Joined: Nov 2018
RE: HP-42S / Free42 Extension for Visual Studio Code
Sorry, for that bug.

My asumption was that a program starts with a 'LBL "NAME"'. Now the extension will detect a program with a '{}' line, which will be filled with a error message or the program size.

In Visual Studio Code block editing is possible. A good introduction can be found at the Visual Studio Code documentation.
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)