Correct useage of USR ?
Correct useage of USR ?
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
Thanks,
Tim
Re: Correct useage of USR ?
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.
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 ?
I can remember this line
IF USR 16514 THEN REM
Greetings
IF USR 16514 THEN REM
Greetings
Re: Correct useage of USR ?
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.
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 ?
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
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
http://zx81.ddns.net/ZxTeaM
Re: Correct useage of USR ?
Well than you should at least post how to abort the print statement as not all programming (like this) is related to MEFISDOS.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.

Re: Correct useage of USR ?
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 ?
POKEMON wrote there:PokeMon wrote:Well than you should at least post how to abort the print statement as not all programming (like this) is related to MEFISDOS.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.
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
HTH Siggi
My ZX81 web-server: online since 2007, running since dec. 2020 using ZeddyNet hardware
http://zx81.ddns.net/ZxTeaM
http://zx81.ddns.net/ZxTeaM
Re: Correct useage of USR ?
Thanks - that was new information for me.siggi wrote: terminates any BASIC routine, but if the error code is 0, the BASIC program continues to run.
HTH Siggi

Re: Correct useage of USR ?
Me too! How about that.