Passing a parameter to a language

From BeebWiki
Jump to: navigation, search

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)