Forum
Get a value after the call (*solved*) - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+---- Forum: Bug Reports (https://www.boriel.com/forum/forumdisplay.php?fid=15)
+---- Thread: Get a value after the call (*solved*) (/showthread.php?tid=653)



Get a value after the call (*solved*) - Sinclair - 04-29-2015

Is there any way that a program in ZX BASIC returns a value?

That I need is, once end my program this return a value to the +3 BASIC as in the following example:

Code:
10 LOAD "program.bin" CODE 32768
20 LET r =  USR 32768
30 PRINT r

Simply this Smile

Thank you.


Re: Get a value after the call - boriel - 04-29-2015

Sinclair Wrote:Is there any way that a program in ZX BASIC returns a value?

That I need is, once end my program this return a value to the +3 BASIC as in the following example:

Code:
10 LOAD "program.bin" CODE 32768
20 LET r =  USR 32768
30 PRINT r

Thank you.
This case is the same as in normal machine code. The value you can return is always a 16 bit integer stored in the BC register.
You can use END for that:

END 27613

Other than that, you must store the result in RAM and BASIC must PEEK from there.


Re: Get a value after the call - Sinclair - 04-29-2015

boriel Wrote:
Sinclair Wrote:Is there any way that a program in ZX BASIC returns a value?

That I need is, once end my program this return a value to the +3 BASIC as in the following example:

Code:
10 LOAD "program.bin" CODE 32768
20 LET r =  USR 32768
30 PRINT r

Thank you.
This case is the same as in normal machine code. The value you can return is always a 16 bit integer stored in the BC register.
You can use END for that:

END 27613

Other than that, you must store the result in RAM and BASIC must PEEK from there.

It doesn't work in a program compiled with some lines of code.

Code:
2 Variable not found, 30:  1

However, your simple example works :!:


Re: Get a value after the call - boriel - 04-29-2015

Sinclair Wrote:However, your simple example works :!:
This usually indicated some corruption in the BASIC system / stack. Check you're not overwriting the ERR_NR or any other system variables.


Re: Get a value after the call - Sinclair - 04-29-2015

boriel Wrote:
Sinclair Wrote:However, your simple example works :!:
This usually indicated some corruption in the BASIC system / stack. Check you're not overwriting the ERR_NR or any other system variables.

OK, thank you.

Tell me please, how I can do this check because the compiler not throws any error.


Re: Get a value after the call - Sinclair - 04-30-2015

And that the PAUSE freeze the flow of the program also has something to do or is another bug?


Re: Get a value after the call - boriel - 05-04-2015

Could be. PAUSE statement uses ROM PAUSE implementation which relays on interruptions.
This could also indicate a problem with interruptions (EI, DI), vector interruptions, etc.
I usually used EmuZWin with its integrated debugger to debug the asm code generated by the compiler, BTW.


Re: Get a value after the call - Sinclair - 05-04-2015

boriel Wrote:Could be. PAUSE statement uses ROM PAUSE implementation which relays on interruptions.
This could also indicate a problem with interruptions (EI, DI), vector interruptions, etc.
I usually used EmuZWin with its integrated debugger to debug the asm code generated by the compiler, BTW.

OK, I understand.

But going back to the previous question:

boriel Wrote:
Sinclair Wrote:Is there any way that a program in ZX BASIC returns a value?

That I need is, once end my program this return a value to the +3 BASIC as in the following example:

Code:
10 LOAD "program.bin" CODE 32768
20 LET r =  USR 32768
30 PRINT r

Thank you.
This case is the same as in normal machine code. The value you can return is always a 16 bit integer stored in the BC register.
You can use END for that:

END 27613

Other than that, you must store the result in RAM and BASIC must PEEK from there.

Which is the reason for which this program always returns on the r variable of the Sinclair BASIC the value 10027 and not the N value of the ZX BASIC?

Code:
dim N as uinteger = 12345
end N



Re: Get a value after the call - boriel - 05-16-2017

Sorry!
I completely overlooked this message!
Let me check it...


Re: Get a value after the call - britlion - 09-19-2018

Did you find a solution here?


Re: Get a value after the call - boriel - 09-19-2018

Not yet. But this is a BUG (I forgot about it, OMG).
Let me fix this...


Re: Get a value after the call - boriel - 09-20-2018

Okay, Fixed in version 1.8.6. Download from here:
<!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Archive#Latest_Development_Version">http://www.boriel.com/wiki/en/index.php ... nt_Version</a><!-- m -->

A pitty I forgot about this issue. Now I wonder is Sinclair is already interested... :?