Giter Club home page Giter Club logo

vscode-nextbasic's Introduction

NextBASIC VSCode Syntax

ZX Spectrum NextBASIC syntax highlighting for Visual Studio Code.

vscode-nextbasic demo

Video: how to setup your NextBASIC dev workflow

This video installation walk through is shown on a Mac but is the same process for Windows and Linux: Watch on YouTube

Features

  • Supports 2.08+ NextBASIC syntax
  • Import and export binary NextBASIC files
  • Full NextBASIC syntax, including new ; comment support
  • Jump to definition for GO TO and PROC statements
  • Symbol lookup (for DEFPROC and DEF FN)
  • Renumbering for whole doc, selected lines or line swap
  • Simple syntax validator
  • Indentation support
  • ctrl/cmd+enter will insert a new line with line number pre-populated
  • Format on edit and format full document
  • Collapse DEFPROC
  • Help on hover
  • Export to .bas as +3DOS format or .tap
  • Support directives: #autostart n, #autoline n,m, #program str and custom #define key=value (and replaces #key instances in BASIC)
  • Support for #bank and #bankfile to auto split your code in both "run with cspect" and "export"

Cspect support

Prerequisites:

Important Windows users ensure you use the hdfmonkey build from uto.speccy.org (link above) - it's built without cygwin as a dependency.

Update nextbasic configuration in VS Code, which requires the location of cspect.exe (yes, even on a Mac) and the Next img file.

Video explanation coming soon.

Note that using NextBASIC: run with cspect will overwrite your autoexec.bas file on the cspect image.

Hat tips

Credit to Rob Uttley for solving the autoexec and #autostart.

Credit to @kounch for their superb original work on vscode_zx (cspect, ZEsarUX and zxbasic - BASIC to asm support)

Original syntax based specifically on the work by jsanjose - and modified to specifically support NextBASIC.

vscode-nextbasic's People

Contributors

remy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

em00k 1stage

vscode-nextbasic's Issues

First line of code it's deleted when tokenizing

If I write a program like this and run with "run with cspec" the first line is missing when tokenizing it to BAS:

10 PRINT "HELLO"
20 PRINT "WORLD"
30 GOTO 10

It only prints "WORLD" many times because line 10 is missing in the generated BAS.

Export to .BAS causes errors with new NextZXOS 2.08 integer syntax

For now this is technically an edge case observation rather a bug, as it deals with pre-release code, but as KS2 gets closer it might become a problem once 2.08 becomes the official baseline.

Under NextZXOS / NextBASIC 2.08 the following code snippet...

10 %a = 1
20 PRINT (%a) + 1

...should yield the output "2", but instead gives "1" and N Statement Lost, 20:1 if exported from VS Code. The BASIC file ends up 6 bytes shorter than it should be, suggesting that maybe the binary representation of the constant is not getting translated properly.

There is a post with some more details in the NextBASIC Facebook group here.

Issue with Syntax recognition changes

Hi Remy,

Latest version of the extension 1.3.12 has caused an issue with errors showing in working syntax.

eg. the line IF % SPRITE 20=1 THEN SPRITE 20,smx,smy,12,0

SPRITE 20 now highlights the "20" will an error

Also

IF %in 49150 & @1 = 0 ( which is used to detect the ENTER KET being pressed)

Now highlights "49150" as an error

How to GOTO when #autoline used

Hi there!

Great extension for VSCode..., thank you Remy for putting it all together!

Quick (and probably dumb) question; When I use the #autoline command, how do I know where to GOTO when I need to? The "hard way" of course is to count the number of executable lines and "do the maths", but is there an easier way of referencing lines? Maybe I've missed some documentation somewhere...

Cheers,
Boz.

Unable to run cspect from within vscode on linux

Hi Remy,

I am running Cspect 2.12.36 on latest ubuntu 20.04 (fully patched) and latest vscode (1.50.1). Latest mono installed as i use it for other things. Git cloned and compiled hdfmonkey and sudo installed it.

I have followed your video (which is nice, clear and to the point!) but when i try and run a basic sample 'hello world', cspect window pops up but is black with nothing happening in it (just black).

I can run cspect from a command line and it boots straight into the basic program as expected showing the compilation and injection process was fine and i can see the files in the next browser once i exit basic and they run as expected.

I use the following from the command line:

mono CSpect.exe -w3 -basickeys -zxnext -nextrom -mmc=./cspect-next-2gb.img

I have changed the nextbasic config as:

cspect path: /home/twri/Downloads/0.SpectrumNext/cspect/CSpect2_12_36/CSpect.exe

cspect options: -w3 -basickeys -zxnext -nextrom

(I tried your options which gave the same issue - black screen - so thought i would try my own that work from command line)

hdfmonkey: hdfmonkey (as its in path)

image path: /home/twri/Downloads/0.SpectrumNext/cspect/CSpect2_12_36/cspect-next-2gb.img

The example program is in a folder under /home/twri/Downloads/0.SpectrumNext/cspect/basictest/

thanks

Tom

#xxx is unknown and not in a #define statement

Extension v1.9.1. It refuses to run or export the following program:

1350 DEFPROC flush(chan)
1360 LOCAL n,c
1370 REPEAT
1380 DIM #chan TO n
1390 WHILE n >  0
1400 NEXT #chan TO c
1410 REPEAT UNTIL 0
1420 ENDPROC

(snippet from the wifi2.bas)

with the error:

#chan is unknown and not in a #define statement

in lines 1380 and 1400.

Although the txt2bas 1.17.0 doesn't generate this error when running from the command line.

V1.10.0 tokenising bug with ELSE IF

Posted on FB: https://www.facebook.com/groups/ZXNextBasic/posts/1764228040770194/?comment_id=1765746263951705

210 %z=% SPRITE OVER (j+1,1 TO 34,6,6): IF %z=0 THEN NEXT %i: RETURN: ELSE IF %z=34 THEN: ELSE DRIVER %49,%2,%59: %q=%q+1: %s=%s+1: %m[j]=%m[j]-1: %n[j]=0: %v=%v+1&7+112: SPRITE %v,%SPRITE AT (z,0),%SPRITE AT (z,1),%56,%1: SPRITE CONTINUE %v: SPRITE %z,,,,0:SPRITE %SGN{-j-1},,,,%m[j]>4113+(m[j]<5145): IF %m[j] THEN NEXT %i: RETURN: ELSE GOSUB %1000: NEXT %i: RETURN

Throws NONSENSE in BASIC on statement 6, which is the ELSE IF %z=34 part
Adding an extra space between ELSE and IF avoids the error.

This was fine on prior version of VSCode.

--repro with more details:

FAILS:
10 IF %z THEN: ELSE IF %z=34 THEN: ELSE PRINT "3"

PASSES: (extra space between ELSE and IF)
10 IF %z THEN: ELSE IF %z=34 THEN: ELSE PRINT "3"

also PASSES! (single space but single value after equals)
10 IF %z THEN: ELSE IF %z=3 THEN: ELSE PRINT "3"

And super weird:
PASSES: (If seems only values >32 fail.)
10 IF %z THEN: ELSE IF %z=32 THEN: ELSE PRINT "3"

Installing hdfmonkey on mac

INSTALLING

From a tarball (see http://files.zxdemo.org/gasman/speccy/hdfmonkey/):

tar xzf hdfmonkey-0.4.tar.gz
cd hdfmonkey-0.4
./configure
make
sudo make install

From git:

git clone https://github.com/gasman/hdfmonkey.git
cd hdfmonkey
autoheader
aclocal
autoconf
automake -a
./configure
make
sudo make install

From git into a Debian source package:

git clone https://github.com/gasman/hdfmonkey.git
dpkg-source -b hdfmonkey

From git into Debian binary package:

git clone https://github.com/gasman/hdfmonkey.git hdfmonkey-0.4.1
cd hdfmonkey-0.4.1
fakeroot debian/rules binary

==========================
... above are the installation instructions from the github link.... how to install on mac. I tried installing it somehow but keep getting hdfmonkey put failed error (possibly permission denied?) when selecting 'Run with cspect' from vscode.

This is the error I get:
hdfmonkey put failed (possible bad path to hdfmonkey):
/bin/sh: /Users/geraldinemundy/Desktop/ZXSpecNextDev/CSpect2_11_1/hdfmonkey.exe: Permission denied

VSCODE Extension for ZX Spectrum Next - Export BIN .bas issue

Hi Remy, not sure if you saw this in my Facebook PM. There appears to be an issue exporting bin .bas files from the VSC extension 1.01 version. On initiating the command via command palette, the prompt launches as expected for you to enter file name. However no new file is actually created....

PLOT OVER 1; causes an error warning

if you add the OVER 1 command to PLOT followed by semicolon it causes the extension to think there is an error?
This is the code that created the error.
5 LET x=0
10 LET t=0.1
20 IF INKEY$="p" THEN GO TO 35
30 GO TO 10
35 LET x0=x
40 LET x=x+t
45 IF x>=255 THEN LET x=0
50 PLOT OVER 1;x0,0: PLOT x,0
55 LET t=t+.2
60 GO TO 20
image

Should .....; pause error? as it needs :?

Not sure if this is a bug or feature request? or out of scope?

I made a typo and the extension didn't pick it up?

code example: 330 PRINT INK 2; AT 19,12; CHR$ 147; CHR$ 145; CHR$ 147; PAUSE 6

returns a C Nonsense in Basic error due to the ';' preceding the PAUSE as it is expecting a ':'

1.33 has stopped working

1.33 comes up with nextbasic.run not found, error

Was working 10 min ago before updated to 1.33 thx

PLOT OVER 1 ; returns an error

if you add the OVER 1 command to PLOT followed by semicolon it causes the extension to think there is an error?
This is the code that created the error.
5 LET x=0
10 LET t=0.1
20 IF INKEY$="p" THEN GO TO 35
30 GO TO 10
35 LET x0=x
40 LET x=x+t
45 IF x>=255 THEN LET x=0
50 PLOT OVER 1;x0,0: PLOT x,0
55 LET t=t+.2
60 GO TO 20
image

Possible EXPORT to Bank issue in Windows 11

I have a 2.08 CSPECT image now running in VSCode, but on 1.11.0 onwards, of the extension, , when I EXPORT to BANK, the resultant bank file in only 1k in size and doesn't seem to work.
I have to reverted back to 1.10.0 for the export to work properly. I am on Windows 11.
The banks file just has the header in it..

On Next KS1 and KS2 hardware the txt2bas works in converting the banks as my bank files start :
#bankfile ProcsBank1.bnk etc.

Removing the #bankfile from the ProcsBank1.txt, it then works in CSPECT environment. Maybe there is a way to ignore this line in CSPECT ?

Can the original autoexec.bas be protected/restored?

The way the extension works to launch cspect and our user code is that the autoexec.bas is replaced with a launcher. This is fine for a dev workflow, but not fine if you use cspect recreationally as it nukes the original autoexec.bas.

Can I include a process of restoring this file on the fly?

Feature request: Multi conversion of txt2bas on RUN?

Hi Remy, thanks for your work on this tool!
Would it be feasible/possible to get the VSCode extension to convert all .bas files in the current directory to a tokenised binary.bas version prior to copying to the virtual SD card in Cspect? (Perhaps, secondarily, also for any file named .bank to be converted to a BANK loadable format?)
This would thereby make all converted files directly accessible (to the master program) via LOAD or MERGE.
I have a game project that requires the merging in of 50+ small (but separate) VSCode .bas programs (each one is bespoke for a different part of the game). Cheers!

PRINT 1e6 fails

Exponential numbers don't parse correctly.

Reference - see numbers after 0x0e - they're the same, when the second number should be 1000000

echo "1 print 1\n10 print 1e6" | txt2bas | hexdump -C
00000000  50 4c 55 53 33 44 4f 53  1a 01 00 9c 00 00 00 00  |PLUS3DOS........|
00000010  1c 00 00 00 1c 00 00 00  00 00 00 00 00 00 00 00  |................|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000070  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 4c  |...............L|
00000080  00 01 09 00 f5 31 0e 00  00 01 00 00 0d 00 0a 0b  |.....1..........|
00000090  00 f5 31 65 36 0e 00 00  01 00 00 0d              |..1e6.......|
0000009c

Unable to run via CSpect on Windows

I have installed the VSCode extension and set up the support programs and paths, whenever I attempt to 'run with CSpect' in VSCode it just goes to the Next main menu.

I have tried running the index.bas file from the NEXT browser and get a 'wrong file type' error.

My next paths are attached.

I have version 1.6.1 of the NEXTBasic plugin and running 2_12_36 CSpsct

nextpaths

OPEN # doesn't tokenize right

I've been testing the "windowsChannels" demo that comes with the Next.

Running from "run with cspect" this line gives error:

40 OPEN #4,"w>4,0,16,20,5"

This is because, when it's tokenized to BAS it translates to:

40 OPEN # #4,"w>4,0,16,20,5"

This doesn't happens with the dot command "txt2bas" that comes with the Next.

Error tokenizing BIN

Testing the "spriteAnim" example that comes with Next, previously converted to text file with dot command bas2txt, if I launch it with "run with cspect" it gives me an "Integer out of range" error on this line:

310 SPRITE CONTINUE 0,0 TO 303 STEP 1 RUN ,0 TO 240 STEP 1 RUN ,1 TO 4, BIN 1000,rate+8

If I delete and enter this line by hand into the BASIC editor it works. Same happens on line 370:

370 SPRITE -2,16,0,1,1, BIN 110

So I suspect it's something about tokenizing BIN.

#bank sections and index.bas not always building with RUNinCSpect v1.11.1

Hi Remy - sorry...another bug (for me). Sometimes the files with #bank directives don't seem to build.
For example: Initially, RUN in CSpect just kept loading a pre-exisitng old index.bas.
Eventually, after tying to hash out the #bank part, and then readd it, I got it working with a simple demo with one added #BANK directive.
Just now I added a second #bank BANK21, but now it just keeps loading up the original .bas
Any ideas? I've saved the file, but it seems to make no difference.

1st Example:
image

Modified:
image

Now if I hash out those #bank directives, it finally loads up the file (that must have been made from a prior run?)
image

I then tried adding a third #bank and this happened:
image

So I hashed out the final #bank:
image
This ought to crash on line 37 because BANK 22 isn't defined, but it just doesn't go there. It isn't loading the BASIC with line 37 in it:
image

Now, it finally works again (after unhashing):
image

Any idea what I am doing wrong here? Is it something to do with file saving? (Is that necessary? Maybe it is a bit slow or something, or not seeing the new file?)

VSCode Extension still doesn't work...

Looks like two issues, 1. Programs don;t automatically run any more. CSPECT used to launch and run program, now you have to manually go into NEXTBasic (where you see your program listing#) and RUN it.
2. Assets no longer get ported over to the CSPECT next image... only index.bas gets copied over into the devel folder

Problems with 'Format Document' and Import.

Issues
As well as the left shunting in the listing for leading dot and semicolon commands , one of the issues seems to be that the extension isn't processing the semicolon correctly understanding that it is a comment but part of a command. In the very first comment line, this is apparent as the "for" was converted to a " FOR " BASIC token. Other spaces were also removed in the comment.
Example
Please find screenshots of the pre and post 'Format Document' applied (manually). I believe the Extension does this Format Document on each export anyway. Demo test case code is also provided to load into VS.
PaulLand NecxtBASIC.zip

Enter at the end of line not working properly

On MacOS, using ENTER at the end of a line with several statements and without spaces truncates the line instead of creating a new empty one.

E.g.:
80 LAYER CLEAR:SPRITE CLEAR:PALETTE CLEAR:PAPER tinta:BORDER tinta:INK papel:CLS

Becomes

80 LAYER CLEAR : SPRITE CLEAR : PALETTE CLEAR : PAPER tinta: BORDER tinta: INK pap
90 el: CLS

instead of

80 LAYER CLEAR : SPRITE CLEAR : PALETTE CLEAR : PAPER tinta: BORDER tinta: INK papel: CLS
90

(see attached video)

EnterError.mp4.zip

Error tokenizing BEEP (i suppose)

Another problem with the tokenizer. This time is with BEEP, I think.

Trying the "breakout.bas" demo that comes with Next it gives always "Nonsense in BASIC" just in the lines where there is a BEEP.

Using dot command "txt2bas" it works right.

Attached is the program for you to try.

breakout.bas.txt

New version of NextBasic

Hello!

First of all I want to thankyou for the NextBasic plugin for VS-Code. It's great. Now on to my question:

From version 22.10a of the NEXT ZX OS they have added support for labels in the Basic language.

Do you have plans to update your NextBasic VS-Code plugin?

BR
Jörgen

Issue with Integer Variable in 1.4.5

Hi Remy,

Just upgrade to 1.4.5 , and my code is showing errors..

eg. %x=255 where integer variable are declared, the % is highlighted as an error. Where ever I declare an integer variable shows the error... " Integer expression should be the start of an argument, "%" "
On their own lines it's ok, but I have them all over as required by my code. Ran ok Yesterday and on Real HW... thx

Another use case...

IF Walk=1 THEN IF %x <= 42 THEN IF View=1 THEN MapSection=MapSection-1: %x=255 :r=r-262: PROC MapDetection()

This was ok in previous build. thx

Running Cspect on mac

Geraldines-MacBook-Pro:cspect2_11_1 geraldinemundy$ ls
3xAY Mouse cspect-next-2gb.img
Beast NXtel.bat dll_src
CSpect.exe NXtel.nex enNextZX.rom
CSpectReadme.txt OpenTK.dll enNxtmmc.rom
DMA OpenTK.dll.config parallax.bat
Layer2 SNASM.rtf parallax.nex
LowResDemo ay8912.dll snasm.exe
Geraldines-MacBook-Pro:cspect2_11_1 geraldinemundy$

...... now what?

Can I run cspect from here just by typing cspect.exe? I've already installed mono from the link shown if vscode. How to run cspect on a mac?

LAYER PALETTE %0 BANK 32,%0 nonsense in basic

LAYER PALETTE %0 BANK 32,%0

Gives: Nonsense in basic

For some reason, the "32" is not encoding correctly.
Solution:
Retype in NextBASIC editor (after crash) and press ENTER. Now it works.
or
Make it an integer: "%32" in VSCode, and then encoding is fine.

Tested on v1.9.1 and v1.11.1 with same behaviour.

Problem setting up on Windows

Sorry, I'm not sure I'm doing this right, just had to create an account so forgive me if I'm backwards.
I posted on your youtube video about setting up nextbasic development. Well, I'm not the sharpest tool in the box and so I'm struggling. I have installed VScode and I have managed to get the next basic 1.5.8 extension installed but the rest I'm struggling with. I copied the cspect folder to my HD and set the path, also copied hdfmonkey to my c:/ drive and set the path but reading the next bit has me stumped. it says to set the 'next image path' but there is no img or image file in my cspect folder. I'm clueless

Export to .bas (when "strip comments enabled") renumbers exported file

v1.11.3
RunInCSpect option works fine, but Export to binary .bas macro (using the same VSCode .txt file) renumbers the output, including any references to GOTO/SUB jump destinations (which then breaks them too):
#autostart 1
5 RUN AT 3: PRINT "<<< MULTI_BANK_OUTPUT >>>"
10 LOAD "BANK20" BANK 20
15 LOAD "BANK21" BANK 21
17 LOAD "BANK22" BANK 22
20 PRINT "BASIC ON THE..."
30 BANK 20 GOSUB 30
35 BANK 21 GOSUB 30
37 BANK 22 GOSUB 30
40 GOTO 20

#bankfile BANK20
30 PRINT "20 ZX"
40 RETURN

#bankfile BANK21
30 PRINT "21 SPECTRUM"
40 RETURN

#bankfile BANK22
30 PRINT "22 NEXT!"
40 RETURN

This is the result in CSpect after loading the exported .bas file
It autoruns, but exits at line 50 (which didn't exist the listing as written, but has been renumbered to 10, 20 etc) because it is trying to jump to BANK 20 line 50, rather than BANK 20 line 30. (Note the exported BANK files themselves do not appear to have been renumbered.)

image

Exported .bas that has been renumbered:
image

BANK 20 as loaded in CSPect and bas2txt:
image

PRINT POINT encoding bug

5 %i=5
10 DIM s$(10,20)
20 PRINT s$(%i,1 TO 10)
30 PRINT POINT %i<<3,%i;s$(%i,1 TO 10)

Fails on line 30.
In case it helps, small mods that pass:
30 PRINT POINT %i,%i;s$(%i,1 TO 10)
30 PRINT POINT %i<<3,%i;s$(%i)

Tested on v1.11.1 (integer slicing is a 2.08/.09 addition).

Corruption of Sprites and Maps

When transferring to CSPECT the first run on files that have included .spr or .map files (raw data) work fine. However subsequent runs appear to overwrite and corrupt the data. For example using the sprite features basic demo from the next distribution along with its' associated dksprite.spr file from the environment to CSPECT will run fine the first (or first few) times but after repeated use will corrupt and show garbage on main character sprite.

Toggling line comment leaves extra space if using semi-colon

As title really. If you have the default of 'REM' set them commenting a line and then uncommenting is fine. If you instead change it to semi-colon then when you comment '; ' is inserted but toggling again removes only the semi-colon, leaving the spurious space behind. Repeating this 10 times will result in 10 new spaces at the start of the line (I know, you wouldn't really do that!).

Command 'nextbasic.run' not found

Hi

I am having problems running a simple program like :

10 PRINT"HELLO WORLD"
20 GOTO 10

When the program is compiled via Visual Studio Code using NextBASIC it returns with an error (command 'nextbasic.run' not found)

I'm running everything on a PC and have the correct paths and arguments setup in the extensions settings whilst using NextBASIC 1.7.1

I had tried everything on two other Laptops using Windows 10 and I get the same results.

Any advice would be great!

Many thanks.

Feature request / Syntax detection

Just a quick one. I am using custom Proc i.e. DEF PROC DisplayBadGuy1 and it doesn't get detected as a subrouteine in blue. It works, so not a big issue, but any PROC where there is a number, doesn;t get recongnised... thx

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.