Return to BASIC

Anything Sinclair Basic related; history, development, tips

Return to BASIC

Postby Forthretro.new.fr on Mon Feb 08, 2010 9:51 pm

Hello friends,

I am sure the answer to be somewhere, but let ask it again :
I have a program I call from the BASIC with the usual RAND USR XXXX

But in the program I will use all the REG and the Stack.
My question is : where is the information for to comeback to the BASIC ?
In the STACK ? In a REG ?
If in the stack I can do, at the start of the program something like
POP DE
LD (save_return),DE
....
Then
LD DE, (save_return)
PUSH DE
C9

But none of the solution seems to work

Merci
User avatar
Forthretro.new.fr
 
Posts: 30
Joined: Thu Nov 19, 2009 9:34 pm

Re: Return to BASIC

Postby sirmorris on Mon Feb 08, 2010 11:01 pm

I seem to remember that BC has something to do with it :)

if the machine code is:
LD BC, returnvalue
RET

LET N = USR(..)

will put the return value in the variable N.

Don't use IX and IY, AF' registers in slow mode - you'll crash the computer. If you do use them in FAST, make sure that IY = $4000 on return.

Charlie
5 x -go-hold rings, 4 x calling birds, 3 x french hens, 2 x turtle doves and 1 x partridge (in a pear tree)
User avatar
sirmorris
 
Posts: 275
Joined: Thu May 08, 2008 4:45 pm
Location: oxon, uk

Re: Return to BASIC

Postby siggi on Mon Feb 08, 2010 11:06 pm

Forthretro.new.fr wrote:Hello friends,

I am sure the answer to be somewhere, but let ask it again :
I have a program I call from the BASIC with the usual RAND USR XXXX

But in the program I will use all the REG and the Stack.

If you run the program in SLOW mode, NEVER touch the IX, IY and AF' registers, because they are used by the display routine and /INT and /NMI. The only exception is, when you want to write your own display driver and you know, what you do ...

My question is : where is the information for to comeback to the BASIC ?
In the STACK ? In a REG ?
If in the stack I can do, at the start of the program something like
POP DE
LD (save_return),DE
....
Then
LD DE, (save_return)
PUSH DE
C9

But none of the solution seems to work

Merci


The solution is

RST 08H
DEFB 0xFF

That calls the Basic error routine with "error" 0, cleans up the stack and jumps back to BASIC.

HTH Siggi
siggi
 
Posts: 142
Joined: Thu May 08, 2008 8:30 am
Location: Germany

Re: Return to BASIC

Postby Forthretro.new.fr on Tue Feb 09, 2010 1:01 am

Many thanks for the answer. It helped me to understand the RAND USR !

With a debug I noted that the adress of the SP allway was 7FEA at the start.

While the SP was at 7FEA I could come back to the BASIC with C9.

However FORTH change the Stack adress later. It is why the computer crashed with any C9.

The solution was to put 7FEA in a 'return_adress' and for to exit, to use the instruction

ED 7B 'return_adress' ; LD SP, (return_adress) -> LD SP , 7FEA
C9


OK !!!
User avatar
Forthretro.new.fr
 
Posts: 30
Joined: Thu Nov 19, 2009 9:34 pm


Return to Sinclair BASIC

Who is online

Users browsing this forum: No registered users and 0 guests

cron