Converting to NextBasic

This is where most of us started. Classic Spectrum basic.

Moderator: Programming Moderators

Post Reply
User avatar
Maziac
Posts: 60
Joined: Sun Jul 09, 2017 5:56 am

Converting to NextBasic

Post by Maziac » Mon Jul 22, 2019 3:37 pm

Hi,

I would like to convert an old ZX Spectrum 48K basic program to NextBasic to enhance it with new features.
At first I thought that would be easy, but I'm not so sure anymore.

What would be the exact steps to do so? The program is available as .tap file, but I also have an ASCII listing
(created with snaplist) if that helps, and I want to convert it to a NextBasic .bas file.

seedy1812
Posts: 67
Joined: Tue May 30, 2017 11:31 am

Re: Converting to NextBasic

Post by seedy1812 » Mon Jul 22, 2019 5:09 pm

Garry Lancaster mentioned on facebook
NextZXOS v2.01 is now available! As well as the new .BAS2TXT and .TXT2BAS dot commands shown in the last kickstarter update
A new distribution is being prepared, but if you are impatient you can grab the new version now directly from gitlab: https://gitlab.com/thesmog358/tbblue/tree/master

User avatar
Maziac
Posts: 60
Joined: Sun Jul 09, 2017 5:56 am

Re: Converting to NextBasic

Post by Maziac » Mon Jul 22, 2019 8:42 pm

That sounds very interesting.
But I was unlucky creating an iso image (mmc file for zesarux).
Is there a recent description available somewhere?

And looking at the repository I could find the dot commands for TXT2BAS and BAS2TXT. But I couldn't find the sources.
Would be interesting to compile that for Mac or Linux to run it already there.

Ped7g
Posts: 110
Joined: Mon Jul 16, 2018 7:11 pm

Re: Converting to NextBasic

Post by Ped7g » Mon Jul 22, 2019 9:33 pm

AFAIK you can just load the original ZX basic program into Next BASIC. It should be backward compatible, all the new stuff is just extensions on top of it. So if you have it already as tap, just `merge ""` it (to avoid autostart), and that should be it?

About txt2bas/bas2txt sources... I think Garry or somebody with insight wrote those two are heavily reusing ROM routines (as both tasks are something what the NextBASIC ROM must to deal with all the time), so even if the sources would be available, there's probably no simple way to compile them as native x86... (although I'm curious how much work it would be to hack it into some kind of x86 tool doing the work by running actual Z80 emulator internally, I guess somebody with well designed emulator source would be capable to pull that off in days/weeks of work, but maybe it's more tricky).

Then again there's already the bas2tap project for classic ZX, I'm too busy to look into it, but I guess if somebody is serious about this, it should be possible to extend it with Next stuff... (maybe not easy). (but I want first stable assembler, before moving onto other tools, so I'm busy for few more months or a year).

User avatar
SevenFFF
Posts: 221
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Re: Converting to NextBasic

Post by SevenFFF » Mon Jul 22, 2019 10:37 pm

The sources are both here. As Ped says, they won’t tell you much - all the real work is done in the IDE_TOKENISER API call, which calls into the ROM.

https://gitlab.com/thesmog358/tbblue/tr ... t_commands
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel Spectron 2084blog

User avatar
SevenFFF
Posts: 221
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Re: Converting to NextBasic

Post by SevenFFF » Mon Jul 22, 2019 10:41 pm

IDE_TOKENISER is documented here, on page 22-23:

https://gitlab.com/thesmog358/tbblue/bl ... S_APIs.pdf

IDE_TOKENISER ($01d8)
Available from NextZXOS v2.01
Convert BASIC between plain text & tokenised forms
IN: B=0, tokenise BASIC line (plain text -> tokenised)
B=1, detokenise BASIC line (tokenised -> plain text)
C=8K bank containing buffer for untokenised BASIC line (ASCII text)
HL=offset in bank of buffer for untokenised BASIC line ($0000..$1fff)
If tokenising (B=0):
the untokenised BASIC line should be terminated with ENTER ($0d)
If detokenising (B=1):
DE=address of tokenised BASIC line within normal BASIC workspace,
terminated with ENTER ($0d)
The recommended way to reserve and use this space is:
(i) Call the 48K ROM routine SET_WORK ($16bf) to clear the
workspace area
(ii) Call the 48K ROM routine BC_SPACES ($0030) to reserve
enough room in the workspace area to hold the tokenised
line (enter with BC=line length, including the ENTER)
(iii) Copy the tokenised line (including the ENTER) to the
address returned by BC_SPACES in the DE register, and
use this as the DE entry parameter for IDE_TOKENISER
Alternatively, you could map a bank containing the entire
tokenised line into any of MMU3/4/5 and provide an address to
there. Care must be taken that there is no possibility of the
stack being in the MMU that you have selected.
OUT(f): Fc=0
A=rc_badparam (bad parameter)
OUT(s): Fc=1
If tokenising (B=0):
HL=(E_LINE)=address of (partly or fully) tokenised line
BC=length of tokenised line, including ENTER ($0d)
Fz=0, line successfully tokenised and syntax-checked
Fz=1, syntax error occurred, and:
DE=count of successfully processed chars in untokenised line
If detokenising (B=1):
HL=offset in provided buffer following the detokenised line

Register status on return:
......../.. same
AFBCDEHL/IX different
NOTES:
Only attempt to use this call if running on at least v2.01 of NextZXOS.
This call can be useful in preparing a BASIC line to be executed by IDE_BASIC.
Line numbers should NOT be present at the start of the input buffer.
If tokenising, the tokenised line should be reclaimed after use by calling
RECLAIM_2 ($19e8) in ROM3, with the values of HL & BC returned by this call.
This effectively restores the original contents of the E_LINE area (which
directly follow the newly-tokenised line) and allows a return to BASIC to be
made successfully.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel Spectron 2084blog

User avatar
Maziac
Posts: 60
Joined: Sun Jul 09, 2017 5:56 am

Re: Converting to NextBasic

Post by Maziac » Tue Jul 23, 2019 6:41 pm

OK, I see: using the sources to compile on x86 might become difficult.

However, I tried
merge "prg.tap"
as suggested by Ped7g but this results in an
"R Tape loading error, 0:1"

Can I really load .tap files with 'merge' or only .bas files?

(I'm on ZEsarUX).

User avatar
Maziac
Posts: 60
Joined: Sun Jul 09, 2017 5:56 am

Re: Converting to NextBasic

Post by Maziac » Tue Jul 23, 2019 6:54 pm

OK, I was now able to load the program with tape emulation and I could save it to a .bas file.
So, thanks for the help. That's what I wanted to achieve.

Ped7g
Posts: 110
Joined: Mon Jul 16, 2018 7:11 pm

Re: Converting to NextBasic

Post by Ped7g » Tue Jul 23, 2019 8:06 pm

yep. tap is container, you must open it first with NextZXOS with some kind of magic (probably opening it in browser will set up tape emulation?), then you can merge/load particular files from the "tape".

Post Reply