NewsProductsSprinterSupportDownloadSprinter ForumAbout usLinksSite map Russian site
Support
 Updates | Knowledge base | Manuals | Resellers | Warranties | Feedback

Knowledge Base

[ Back ] [ Index ] [ Categories ] [ Next ]

Q10019. Routine (GetSwitch) of filling of ASCIIZ buffer with the command-line parameter value.

More information

Routine fills an ASCIIZ buffer with the string after the "=" sign of a predetermined command-line switch of the form /SWITCH=VALUE. The switch name is *NOT* case sensitive.

Assembler

Any assembler.

Input

(SP+0)=Ret address
(SP+2)=Address of cmdline ASCIIZ string, preceded by its len in ONE byte
(SP+4)=Address of ASCIIZ parameter to find its value
(SP+6)=Address of ASCIIZ buffer to fill with the parameter's value

Output

Carry flag reset=OK
Carry flag set=Error (no chars in cmdline, etc)
A : Zero
BC: Amount of chars remaining in command line
DE: Points to the terminating NULL of the buffer to fill
HL: Points to one after the last byte copied from the cmdline

Routine

GetSwitch:	POP	HL		;Fetch return address in HL
		POP	DE		;Fetch cmdline address in DE
		POP	BC		;Fetch param address in BC
		EX	(SP),HL		;Push ret addr, buffer addr to HL
		LD	(GS_Param),BC	;Save param ASCIIZ address
		LD	(GS_OutBf),HL	;Save output buffer address
		EX	DE,HL		;CmdLine to HL, OutBuff to DE
		LD	C,(HL)		;CmdLine len to C (just-a-byte)
		LD	B,0		;Hi-byte of BC is zero
		INC	HL		;Point to first char in CmdLine
GS_GetSlash:	LD	A,"/"		;Char to find to A
		CPIR			;Find the slash
		JR	Z,GS_ChkParam	;Slash found. Check param.
		JR	GS_Error	;Outta chars or no slashes!
GS_ChkParam:	LD	DE,(GS_Param)	;Param name address to DE
		DEC	HL		;Compensate for first INC HL
GS_CP_Loop:	DEC	BC		;Take char into account
		INC	HL		;Point to next char
		LD	A,(DE)		;Param name char to A
		INC	DE		;Point to next char in param name
		OR	A		;Is End Of String?
		JR	Z,GS_Found	;Jump if so: Param found!
		CP	(HL)		;Same as (HL)?
		JR	Z,GS_CP_Loop	;Continue if so
		XOR	020h		;Toggle uppercase/lowercase bit
		CP	(HL)		;Same as (HL)?
		JR	Z,GS_CP_Loop	;Jump if so
		JR	GS_GetSlash	;Bad param: Continue search for "/"
GS_Found:	LD	A,(HL)		;Char should be "="
		CP	"="		;Is it?
		JR	NZ,GS_GetSlash	;Jump back if not: Wrong param
		INC	HL		;Point to char after equals sign
		LD	DE,(GS_OutBf)	;DE points to start of buffer
GS_CopyBuff:	LD	A,(HL)		;Move value char to A
		CP	" "		;Is space?
		JR	Z,GS_Done	;Jump if so. Transfer finished
		CP	00h		;End of cmdline?
		JR	Z,GS_Done	;Jump if so. No more to transfer
		LD	(DE),A		;Copy char to output buffer
		INC	HL		;Point to next char
		INC	DE		;Point to next placeholder
		JR	GS_CopyBuff	;Loop back until done
GS_Done:	XOR	A		;Reset A
		LD	(DE),A		;Terminate the string  
		RET			;Done :)
GS_Error:	SCF			;Flag "ERROR!!!"
		RET			;Done :(

GS_OutBf:	DB	00h,00h		;Output buffer address
GS_Param:	DB	00h,00h		;Parameter name address

Added by

Marcelo Lopez

5 May 2003.
PETERS PLUS LTD.

[ Back ] [ Index ] [ Categories ] [ Next ]