Problems with banked BASIC procedures

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

Moderator: Programming Moderators

User avatar
programandala.net
Posts: 45
Joined: Thu Nov 02, 2017 11:55 am
Location: Spain
Contact:

Problems with banked BASIC procedures

Postby programandala.net » Fri Mar 26, 2021 11:49 am

I'm trying the banked BASIC modules with a big program for the first time, but I'm having some problems.

I create banked BASIC files with zmakebas, in Linux. The first procedure I have moved to a bank contains several long lines like the following, with calls to the main program:

Code: Select all

defproc x
bank 255 proc echo("...long text, more than 300 bytes...")
bank 255 proc echo("...long text, more than 300 bytes...")
bank 255 proc echo("...long text, more than 300 bytes...")
rem etc
endproc
When I called that banked procedure from the main program, the execution failed at the first long line with a "Too big" error, though the very same code worked fine in the main program.

Then I splitted the code into several procedure calls with shorter and shorter lines, until it worked fine. It seems the maximum allowed length is c. 164 bytes of source code (not tokenized). I've found no mention in the manual about such limitation in banked procedures.

But then a new problem happens: after the banked procedure is executed, I get "Q Parameter error" in the main program:

Code: Select all

proc echo("string"+str$ fn f ()+"string)
...code that worked perfectly before the bank call.

I will investigate further in order to isolate the problem and write a simple test program, also comparing the modules created with zmakebas with modules created directly in NextBASIC.

Has anybody tried banked BASIC procedures?
Marcos Cruz (programandala.net)

User avatar
programandala.net
Posts: 45
Joined: Thu Nov 02, 2017 11:55 am
Location: Spain
Contact:

Re: Problems with banked BASIC procedures

Postby programandala.net » Sat Mar 27, 2021 10:26 am

After doing some tests, It's clear the problem has nothing to do with my code or with using zmakebas to build the banked programs. It seems there's a bug in the system. I've written a test program that demonstrates the problem:

Code: Select all

#program banktest
  10 REM BankTest
  20 REM programandala.net
  30 REM 2021-03-27
  40 :
  50 BANK NEW b
  60 PROC echo("Type:")
  70 PROC echo("  bank b line 140,160:goto 180")
  80 STOP 
  90 :
 100 DEFPROC echo(t$)
 110 PRINT t$
 120 ENDPROC 
 130 :
 140 DEFPROC banked()
 150 BANK 255 PROC echo("This is printed from the bank!")
 160 ENDPROC 
 170 :
 180 REM Test
 190 BANK b PROC banked()
 200 PROC echo("Test passed, but...")
 210 PRINT "Now type 'goto 60'  and see"'"what happens: 'Q Parameter"'"error' and wrong"'"strings printed."
 215 PRINT "The only solution is to reset the machine."
 220 STOP 
 230 :
 240 SAVE "banktest.bas"
It seems something gets corrupted after calling the banked procedure the first time, affecting the handling of procedure parameters. I tried `bank b clear` and reloaded the program, just in case, but the problem persists. The only solution is to reset the machine.

I will do more tests in order to isolate the error condition as much as possible.
Marcos Cruz (programandala.net)

Alcoholics Anonymous
Posts: 777
Joined: Mon May 29, 2017 7:00 pm

Re: Problems with banked BASIC procedures

Postby Alcoholics Anonymous » Mon Mar 29, 2021 3:44 am

Still happening in the dev version of nextzxos so I will let Garry know.

User avatar
programandala.net
Posts: 45
Joined: Thu Nov 02, 2017 11:55 am
Location: Spain
Contact:

Re: Problems with banked BASIC procedures

Postby programandala.net » Mon Mar 29, 2021 8:45 am

Alcoholics Anonymous wrote:
Mon Mar 29, 2021 3:44 am
Still happening in the dev version of nextzxos so I will let Garry know.
Thank you.

Beside the main problem that seems to corrupt the interpreter, I wonder why long lines are not allowed in banked procedures. In fact `bank n line first,last` rejects them with an error. Maybe it's not a bug but an actual limitation of the system. If so, it should be documented.

Meanwhile, I will use banks just to store BASIC data and strings, and see what happens.
Marcos Cruz (programandala.net)

garrylancaster
Posts: 36
Joined: Mon Feb 19, 2018 2:44 pm

Re: Problems with banked BASIC procedures

Postby garrylancaster » Mon Mar 29, 2021 8:35 pm

programandala.net wrote:
Mon Mar 29, 2021 8:45 am
In fact `bank n line first,last` rejects them with an error. Maybe it's not a bug but an actual limitation of the system. If so, it should be documented.
Yes, it is a limitation: program lines in banked program sections are limited to 256 bytes in length. Unfortunately this information is not in the manual, but it was added a while back to the main document describing the new features of NextBASIC. You can find that here:

https://gitlab.com/thesmog358/tbblue/-/ ... atures.pdf

The relevant information is on p19, in the section describing the BANK...LINE command.

User avatar
programandala.net
Posts: 45
Joined: Thu Nov 02, 2017 11:55 am
Location: Spain
Contact:

Re: Problems with banked BASIC procedures

Postby programandala.net » Mon Mar 29, 2021 9:57 pm

Thank you. I had the older 2020-03-30 version of the document.
Marcos Cruz (programandala.net)


Who is online

Users browsing this forum: No registered users and 2 guests