Reading command line
When a transient command is run from a filing system OSARGS 1,0 can be used to find the command line. This command line is always stored in the I/O processor. Transient commands usually run in the I/O processor so they can read the command line directly using code such as LDA (zp),Y
:
\ lptr = address in zero page to point to command line \ Note, four bytes are read, so lptr+2 and lptr+3 are overwritten LDA #1:LDY #0:LDX #lptr:JSR OSARGS :\ Read address of command line \ (lptr),Y now points to the start of the command's parameters
However, if a transient command is written to run in the language processor it must copy the command line to local memory, or scan it character by character over the Tube. The following code fragments copy the command line to local memory.
6502
\ addr = 5-byte buffer in zero page \ cmdline = 256-byte buffer to copy command line to LDA #1:LDY #0:LDX #addr:JSR OSARGS :\ Read address of command line .rdcmdlp TYA:PHA LDX #addr:LDY #0:LDA #5:JSR OSWORD :\ Read byte from I/O memory PLA:TAY:LDA addr+4:STA cmdline,Y:INY :\ Copy byte to local buffer INC addr:BNE rdcmdnxt:INC addr+1 :\ Increment command line address .rdcmdnxt CMP #13:BNE rdcmdlp :\ Loop until <cr>
Z80
\ addr = 5-byte buffer \ cmdline = 256-byte buffer to copy command line to LD A,1:LD E,0:LD HL,addr:CALL OSARGS :\ Read address of command line LD DE,cmdline .rdcmdlp LD HL,addr:LD A,5:CALL OSWORD :\ Read byte from I/O memory LD A,(addr+4):LD (DE),A:INC DE :\ Copy byte to local buffer LD HL,(addr):INC HL:LD (addr),H :\ Increment command line addressL CP 13:JR NZ,rdcmdlp :\ Loop until <cr>
6809
80186
PDP11
\ If code has a Unix header, SP=>stack frame with parameters \ Otherwise, R1=>command line in local memory
32016
ARM
SWI "OS_GetEnv" :\ R0=>command line in local memory
BASIC
If the transient command is written in BASIC, the command line is already in local memory due to it being used by BASIC to local the program, and is collectable with the FNOS_GetEnv function in the ProgEnv program library.
Notes
Some filing systems provide the OSGBPB 9,0 call to copy the command line to local memory.
Jgharston 13:56, 2 December 2009 (UTC)