`CONTINUE` fails when OLDPP/OSPPC are modified

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:

`CONTINUE` fails when OLDPP/OSPPC are modified

Postby programandala.net » Tue May 26, 2020 10:48 am

Some years ago I wrote a simulated `ON GOTO` in Sinclair BASIC in order to simplify a big program. Now I've tried it in NextBASIC, but it doesn't work.

I've written a simple demo of the original trick in Sinclair BASIC:

Code: Select all

   10 REM ON GOTO
   20 REM By Marcos Cruz (programandala.net)
   30 REM Original idea: 2014-08-30. This demo: 2020-05-24.
   40:
   50 REM System variables
   60 LET ppc=23621
   70 LET subppc=23623
   80 LET oldppc=23662
   90 LET osppc=23664
  100:
  110 INPUT "Enter number (1..3 or 0 to stop)"'n
  120 IF n<0 OR n>3 THEN GO TO n
  130 IF NOT n THEN STOP 
  140:
  150 REM ON GOTO n
  160 POKE oldppc,PEEK ppc: POKE oldppc+1,PEEK (oldppc+1): POKE osppc,PEEK subppc+1+n: CONTINUE : GO TO 180: GO TO 190: GO TO 200
  170:
  180 PRINT "One": GO TO 110
  190 PRINT "Two": GO TO 110
  200 PRINT "Three": GO TO 110
The idea is simple: `CONTINUE` jumps to the line and statement contained in two system variables: OLDPPC and OSPPC.

I used this technic in a project for the +3e, but I've tried it also on 48, 128 and +3. There's no reason why it shouldn't work on any model. But to my surprise, in NextBASIC `CONTINUE` always fails with "Statement Lost".

In fact I wrote a NextBASIC version first:

Code: Select all

160 DPOKE oldppc,% DPEEK INT{ppc}:POKE osppc,PEEK subppc+1+n:CONTINUE:GOTO 180:GOTO 190:GOTO 200
When it failed, I tried also the generic one, just in case. But it made no difference.

I've written some small tests, but other usages of `CONTINUE` seem to work fine in NextBASIC, for example:

Code: Select all

10 LET n=400
20 PRINT "After the error, type ""GOTO 50"""
30 PRINT CHR$ n;
40 PRINT "ontinued!"
50 LET n=67:CONTINUE
Then I supposed NextBASIC's `CONTINUE` cannot jump to its own line (!?), and tried this alternative, but it doesn't work either:

Code: Select all

160 POKE oldppc,165:POKE oldppc+1,0:POKE osppc, n:CONTINUE
165 GO TO 180: GO TO 190: GO TO 200
No change: `CONTINUE` halts with a "Statement lost" error.

It seems `CONTINUE` doesn't work as before, or the system variables are used differently, though their description in the manual has not changed. I've searched the PDF manual for `CONTINUE` but there's nothing new, I see now difference from Sinclair BASIC. Maybe the problem has something to do with the implementation of `ON ERROR`? Or maybe I'm missing something.

Any clue?
Last edited by programandala.net on Thu Jun 11, 2020 12:11 pm, edited 2 times in total.
Marcos Cruz (programandala.net)

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

`ON GOTO`can be simulated with NEWPPC/NSPPC (Re:`CONTINUE` fails when OLDPP/OSPPC are modified)

Postby programandala.net » Thu Jun 11, 2020 12:04 pm

I have written a simpler alternative without `CONTINUE`, poking NEWPPC (23618) with the contents of PPC (23621) and NSPPC (23620) with the index:

Code: Select all

REM ON GOTO %n (1..4)
DPOKE newppc,% DPEEK INT {ppc}: POKE nsppc,%2+n: GOTO line1: GOTO line2: GOTO line2: GOTO line4
Marcos Cruz (programandala.net)


Who is online

Users browsing this forum: No registered users and 2 guests