Page 1 of 2
Correct useage of USR ?
Posted: Tue Nov 12, 2013 9:50 pm
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
Re: Correct useage of USR ?
Posted: Tue Nov 12, 2013 10:05 pm
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.
Re: Correct useage of USR ?
Posted: Wed Nov 13, 2013 12:54 pm
by iturbez
I can remember this line
IF USR 16514 THEN REM
Greetings
Re: Correct useage of USR ?
Posted: Wed Nov 13, 2013 3:28 pm
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.
Re: Correct useage of USR ?
Posted: Wed Nov 13, 2013 11:31 pm
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
Re: Correct useage of USR ?
Posted: Thu Nov 14, 2013 12:54 am
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.

Re: Correct useage of USR ?
Posted: Fri Nov 15, 2013 5:44 am
by dr beep
On the ZX spectrum it is just deleting 14 bytes from the stack. Probably something like that for the ZX81 too.
Re: Correct useage of USR ?
Posted: Fri Nov 15, 2013 9:05 am
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.
terminates any BASIC routine, but if the error code is 0, the BASIC program continues to run.
HTH Siggi
Re: Correct useage of USR ?
Posted: Fri Nov 15, 2013 6:34 pm
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.

Re: Correct useage of USR ?
Posted: Sat Nov 16, 2013 12:31 pm
by sirmorris
Me too! How about that.