2 ; Ullrich von Bassewitz, 2005-04-21
4 ; Search the environment for a string.
7 .export searchenv, copyenvptr
8 .import __environ, __envcount
9 .import ptr1:zp, ptr2:zp, ptr3:zp
13 ;----------------------------------------------------------------------------
16 ; ptr1 must contain the string to search for. On exit, the N flag will tell
17 ; if the entry was found, and X will contain the index of the environment
18 ; string in the environment (a negative value if the entry was not found).
19 ; On success, ptr3 will contain the entry and Y the offset of the '=' within
24 ; Copy the pointer to the environment to the zero page
28 ; Loop over all environment entries trying to find the requested one.
32 bmi @L9 ; Out of entries
34 ; Since the maximum number of entries is 64, the index can only be 63, so
35 ; the following shift cannot overflow and the carry is clear.
38 asl a ; Mul by two for word access
46 ; ptr1 points to name, ptr3 points to the next environment entry. Compare the
47 ; two. The following loop limits the length of name to 255 bytes.
51 beq @L2 ; Jump on end of name
53 bne @L0 ; Next environment entry
57 ; End of name reached, check if the environment entry contains a '=' char
61 bne @L0 ; Next environment entry
63 ; Done. The function result is in X and the N flag is set correctly.
70 ;----------------------------------------------------------------------------
71 ; copyenvptr: Copy _environ to ptr2