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
However, if a transient command is written to run in the language processor it must copy the command line to local memory. The following code fragments will do this.
\ 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>
\ 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>
\ If code has a Unix header, SP=>stack frame with parameters \ Otherwise, R1=>command line in local memory
SWI "OS_GetEnv" :\ R0=>command line in local memory
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.
Some filing systems provide the OSGBPB 9,0 call to copy the command line to local memory.
Jgharston 13:56, 2 December 2009 (UTC)