FAQ  •  Register  •  Login

Get a value after the call

<<

Sinclair

User avatar

Posts: 10

Joined: Wed Apr 08, 2015 10:28 am

Post Wed Apr 29, 2015 10:53 am

Get a value after the call

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 :)

Thank you.
Image
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Wed Apr 29, 2015 11:04 am

Re: Get a value after the call

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.
<<

Sinclair

User avatar

Posts: 10

Joined: Wed Apr 08, 2015 10:28 am

Post Wed Apr 29, 2015 3:38 pm

Re: Get a value after the call

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 :!:
Image
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Wed Apr 29, 2015 3:41 pm

Re: Get a value after the call

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.
<<

Sinclair

User avatar

Posts: 10

Joined: Wed Apr 08, 2015 10:28 am

Post Wed Apr 29, 2015 6:53 pm

Re: Get a value after the call

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.
Image
<<

Sinclair

User avatar

Posts: 10

Joined: Wed Apr 08, 2015 10:28 am

Post Thu Apr 30, 2015 3:39 pm

Re: Get a value after the call

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

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Mon May 04, 2015 7:47 am

Re: Get a value after the call

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.
<<

Sinclair

User avatar

Posts: 10

Joined: Wed Apr 08, 2015 10:28 am

Post Mon May 04, 2015 8:50 pm

Re: Get a value after the call

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
Image
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Tue May 16, 2017 7:50 am

Re: Get a value after the call

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

Return to Help & Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO