Correct useage of USR ?

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
tdg8934
Posts: 304
Joined: Mon Sep 23, 2013 6:10 pm

Correct useage of USR ?

Post by tdg8934 »

I have seen variations of the USR function for calling assembly language routines such as RAND USR 16514 and PRINT USR 16514. From what I understand PRINT USR <address> is used with registers B and C have data loaded within and their values can be "printed" to the screen upon execution of the PRINT USR <address> command. RAND USR <address> is used when you just want to call an assembly language routine that doesn't have anything returning. Is this correct? Are there other variations of USR used?

Thanks,

Tim
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: Correct useage of USR ?

Post by PokeMon »

USR is just a function and give a return value (passed in BC register).
So whenever a function can be used you can use USR as well.

RAND USR is simply executed with no return value (exactly return value will be used as start value for random generator ...)
PRINT USR is used for printing a value on screen.

There maybe formatting options used as well as PRINT AT 22,0 USR 16514.

A way to process or store the return value is in conjunction with LET statement: LET A=USR 16514.

Combinations as IF USR 16514 < 99 THEN GOTO 1060 are possible as many other direct processing.
User avatar
iturbez
Posts: 154
Joined: Fri Dec 25, 2009 1:06 pm
Location: Spain

Re: Correct useage of USR ?

Post by iturbez »

I can remember this line

IF USR 16514 THEN REM

Greetings
dr beep
Posts: 2076
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Correct useage of USR ?

Post by dr beep »

There is no wrong way of starting MC.

Each command/function capable of setting a USR function is possible.

On the ZX Spectrum you can however use certain commands to make sure the right screen is called.
You have a upper and lower screen. Even direct calling the printer can be usefull.

On the ZX81 this not necessary.
User avatar
siggi
Posts: 990
Joined: Thu May 08, 2008 9:30 am
Location: Wetterau, Germany
Contact:

Re: Correct useage of USR ?

Post by siggi »

The "PRINT USR ..." construction is in most cases NOT used to print anything on screen, but to pass parameters to the USR routine. The ZX81-BASIC does not allow to pass parameters to a USR program. So the PRINT statement is "abused" for that, because the syntax checker allows an unlimited number of arguments to be "printed".
Thus the statement

PRINT USR 16514, "hello"+" world"
can be used to pass the string "hello world" to the USR routine. That routine could scan the parameters following the USR-call and process them. When the USR routine is finished, it can abort the "PRINT" statement, so that nothing is printed to screen.

That is a more convenient way to pass parameters from BASIC to the USR program compared to the "standard" way of POKEing values into memory to be read by the USR program.

One example:
LET D$="C:"
LET P$="CMDS/"
LET N$="ASDIS"
PRINT USR 8195; D$+P$+N$+", 32768"
could be a call to MEFISDOS to load the program ASDIS from MMC card (drive C directory CMDS) to memory location 32768. Nothing will be printed to screen.

HTH Siggi
My ZX81 web-server: online since 2007, running since dec. 2020 using ZeddyNet hardware
http://zx81.ddns.net/ZxTeaM
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: Correct useage of USR ?

Post by PokeMon »

siggi wrote:PRINT USR 16514, "hello"+" world"
can be used to pass the string "hello world" to the USR routine. That routine could scan the parameters following the USR-call and process them. When the USR routine is finished, it can abort the "PRINT" statement, so that nothing is printed to screen.
Well than you should at least post how to abort the print statement as not all programming (like this) is related to MEFISDOS. ;)
dr beep
Posts: 2076
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Correct useage of USR ?

Post by dr beep »

On the ZX spectrum it is just deleting 14 bytes from the stack. Probably something like that for the ZX81 too.
User avatar
siggi
Posts: 990
Joined: Thu May 08, 2008 9:30 am
Location: Wetterau, Germany
Contact:

Re: Correct useage of USR ?

Post by siggi »

PokeMon wrote:
siggi wrote:PRINT USR 16514, "hello"+" world"
can be used to pass the string "hello world" to the USR routine. That routine could scan the parameters following the USR-call and process them. When the USR routine is finished, it can abort the "PRINT" statement, so that nothing is printed to screen.
Well than you should at least post how to abort the print statement as not all programming (like this) is related to MEFISDOS. ;)
POKEMON wrote there:
http://forum.tlienhard.com/phpBB3/viewt ... 450#p10153
Die BASERR routine springt in die BASIC Fehlerroutine und beendet das laufende Programm.
Das auf RST $08 folgende Byte wird als "Fehlercode +1" interpretiert.
Die Fehlermeldung erscheint als <Fehlercode>/<Zeilennummer>.
Zeilennummer ist die Zeilennummer, die das Assemblerprogramm gestartet hat (RAND USR oder PRINT USR).
Werte zwischen $00 und $22 entsprechen Fehlermeldungen 0-9 und dann A-Z.
$FF bedeutet kein Fehler (0), das laufende Programm wird dennoch beendet.

Code: Select all

RST $08
DEFB $FF
terminates any BASIC routine, but if the error code is 0, the BASIC program continues to run.

HTH Siggi
My ZX81 web-server: online since 2007, running since dec. 2020 using ZeddyNet hardware
http://zx81.ddns.net/ZxTeaM
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: Correct useage of USR ?

Post by PokeMon »

siggi wrote: terminates any BASIC routine, but if the error code is 0, the BASIC program continues to run.

HTH Siggi
Thanks - that was new information for me. ;)
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: Correct useage of USR ?

Post by sirmorris »

Me too! How about that.
Post Reply