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

Knowledge Base

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

Q10020. Routine (ExpandMacros) of expanded macros in an ASCII buffer with the nth ASCIIZ string from another buffer.

More information

Will replace occurrences of "%1" to "%9" in an ASCIIZ buffer for the Nth ASCIIZ string from a parameter buffer, delivering an ASCII (not ASCIIZ) string in a supplied address. The parameter string block MUST start with a NULL char (ASCII 0).

Example:
	Src:	DB	"Marcelo %1 %2."
	Param:	DB	00,"made",00,"me.",00
	Desti:	DB	00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
After executing the routine, DESTI will hold the following string (note that the destination string is not ASCIIZ):
	Desti:	DB	"Marcelo made me."

Assembler

Any assembler.

Input

(SP+6) -> Source buffer start address (Src in the example)
(SP+4) -> Param buffer start address (Param in the example)
(SP+2) -> Destination buffer start address (Desti in the example)
(SP+0) -> Normal return address

Output

A : Zero
B : Zero (if strings replaced), Hi byte of param buff addr if not
C : Low byte of parameter buffer address
DE: Pointer to the last byte in the output buffer + 1
HL: Pointer to the last byte in the source buffer + 1

Routine

ExpandMacros:	POP	HL		;Fetch ret addr briefly
		POP	DE		;Fetch OutBuffer in DE
		POP	BC		;Fetch ParBuffer in BC
		EX	(SP),HL		;Exchg Ret to (SP) and RawBuff to HL
EM_SavePtr:	LD	(EM_PBuff),BC	;Save param buffer ptr
EM_Loop:	LD	A,(HL)		;Char to A
		INC	HL		;Point to next char
		OR	A		;Is it a zero?
		RET	Z		;Finished if so
		CP	"%"		;Is it the macro indicator?
		JR	NZ,EM_CopyChr	;Jump if not
		LD	A,(HL)		;Char after "%" to A
		CP	"0"		;Is char > "0"?
		JR	NC,EM_ChkNine	;Jump if so
EM_CopyPct:	LD	A,"%"		;Restore percentage sign in A
		JR	EM_CopyChr	;And transfer it to out buffer
EM_ChkNine:	CP	"9"		;Is char lower than "9"?
		JR	NC,EM_CopyPct	;Jump if not to transfer the "%"
		SUB	"0"		;Now is 0 <= A <= 9
		PUSH	HL		;Save input buffer pointer
		LD	HL,(EM_PBuff)	;Get Param Buffer address in HL
		LD	B,A		;Param number to B
		XOR	A		;Reset A to zero
EM_FindPar:	PUSH	BC		;Save counter in B
		LD	BC,0		;Prepare to loop thru 64K
		CPIR			;Look for a zero char
		POP	BC		;Restore zeroes counter
		DJNZ	EM_FindPar	;Loop back until param is found
EM_CopyPar:	LD	A,(HL)		;Param char to A
		INC	HL		;Point to next char in param
		OR	A		;Is it zero?
		JR	NZ,EM_CopyPar2	;Go on to copy char
		POP	HL		;Restore main in buffer pointer
		INC	HL		;Skip param number
		JR	EM_Loop		;And continue looping
EM_CopyPar2:	LD	(DE),A		;Copy char in param to output buffer
		INC	DE		;Advance out buffer pointer
		JR	EM_CopyPar	;And loop thru all chars in param
EM_CopyChr:	LD	(DE),A		;Copy char in main to output buffer
		INC	DE		;Advance out buffer pointer
		JR	EM_Loop		;And loop thru all chars in main

EM_PBuff:	DW	0000h		;Param buffer save zone

Added by

Marcelo Lopez

5 May 2003.
PETERS PLUS LTD.

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