Difference between revisions of "Passing a parameter to a language"

From BeebWiki
Jump to: navigation, search
(Initial page, response to StarDot query.)
 
m (Fixed typos.)
 
Line 5: Line 5:
 
the language is running it is running in the language memory and
 
the language is running it is running in the language memory and
 
can no longer see the command that was used to start it as that
 
can no longer see the command that was used to start it as that
will be neccessity be in the I/O memory.
+
will by neccessity be in the I/O memory.
  
 
Language code can examine the I/O memory with [[OSWORD 5]] and extract
 
Language code can examine the I/O memory with [[OSWORD 5]] and extract
 
a command line. EDIT on the Master does this so you can start EDIT
 
a command line. EDIT on the Master does this so you can start EDIT
 
specifying a file to load. Of course, this is not possible if the
 
specifying a file to load. Of course, this is not possible if the
language was started wqith [[OSBYTE &8E|OSBYTE 142]] as there is no
+
language was started with [[OSBYTE &8E|OSBYTE 142]] as there is no
 
command line. Note that this cannot be done via the [[OSARGS]] call
 
command line. Note that this cannot be done via the [[OSARGS]] call
 
to read the command line parameters, as that points to the command
 
to read the command line parameters, as that points to the command
Line 41: Line 41:
 
command already in local memory and with a register pointing to
 
command already in local memory and with a register pointing to
 
it, or an API call to fetch it:
 
it, or an API call to fetch it:
* 6809: X=>command line parameters
+
* 6809:    X=>command line parameters
 
* PDP11: R1=>command line parameters
 
* PDP11: R1=>command line parameters
* ARM: OS_GetEnv gets command line parameter address
+
* ARM:     OS_GetEnv gets command line parameter address
  
 
== See Also ==
 
== See Also ==
 
* [[Returning exit code]]
 
* [[Returning exit code]]
 
[[User:Jgharston|Jgharston]] ([[User talk:Jgharston|talk]]) 01:09, 1 July 2018 (CEST)
 
[[User:Jgharston|Jgharston]] ([[User talk:Jgharston|talk]]) 01:09, 1 July 2018 (CEST)

Latest revision as of 23:43, 3 April 2020

When a language is entered it is just entered at the language entry point. On the 6502 there is no mechanism to pass a parameter to the language, it is entered as a straight jump of a selected ROM. Once the language is running it is running in the language memory and can no longer see the command that was used to start it as that will by neccessity be in the I/O memory.

Language code can examine the I/O memory with OSWORD 5 and extract a command line. EDIT on the Master does this so you can start EDIT specifying a file to load. Of course, this is not possible if the language was started with OSBYTE 142 as there is no command line. Note that this cannot be done via the OSARGS call to read the command line parameters, as that points to the command line used to run a program from a file, not to the command line used to execute a ROM command.

If the parameter you want to pass to your language is a simple 8-bit byte than it can by passed via the OSBYTE 1 user/return byte. Your *command writes its data to OSBYTE 1, then starts up the language. The language then reads the OSBYTE 1 value to collect the parameter.

   .L8000:JMP Language
   .L8003:JMP Service
   ...
   .Service4
   \ Eventually gets to...
   .mycommand
   JSR ParseNumber          :\ Parse 8-bit parameter to A
   TAX:LDA #1:JSR OSBYTE    :\ Set user/return code
   LDX &F4                  :\ X=my ROM number
   LDA #142:JMP OSBYTE      :\ Enter me as a language
   ...
   .Language
   LDX #&FF:TXS:CLI         :\ Standard language startup
   LDX #0:LDA #1:JSR OSBYTE :\ Read user/return code
   \ X now has the parameter you used with your *command

Other processors

Some non-6502 processors enter language code with the selection command already in local memory and with a register pointing to it, or an API call to fetch it:

  • 6809:    X=>command line parameters
  • PDP11: R1=>command line parameters
  • ARM:     OS_GetEnv gets command line parameter address

See Also

Jgharston (talk) 01:09, 1 July 2018 (CEST)