EFD74A is a snazzy bcall that you will want to use. As you now know, it is bcall(_RclAns). It first returns the variable type in the A register and if Ans is a number, it copies the value to OP1. If Ans is not a number, it returns pointers to the data as if you had used EFF142 or D7. They return pointers to the variable named in OP1 such that DE points to the size bytes of the variable, HL points to the VAT entry, B is the flashpage the var data is on (0 if it is in RAM), C is the size of the name, A is the variable type.
Ans needs to be a real number
Complex numbers are type 0C and have their imaginary component stored in OP2.
B7 ;'or a' is an optimised way of doing 'cp 0'
C0 ;Exit if it isn't a number
EFEF4A ;Convert the value in OP1 (must be at most four digits). The converted number is stored in DE and A, so E=A.
Ans needs to be a string
You want Ans to be a string which is variable type 4. You can use FE04 to check if A is 4, but I prefer to subtract 4 from A because it sometimes allows for later optimisations if A becomes 0.
D604 ;'sub 4' will return zero if a=4, so the z flag will be set.
C0 ;ret nz (RET if the z flag is not set)
EB ;Switch DE and HL
4E234623 ;Now BC is the size of the variable, HL points to the data
Ans needs to be a list
Because I think it will be useful, if Ans is a list, say of size 3:
Lists are type 01, Complex lists are type 0D, and list elements are 9 bytes each, like a real number. (complex list elements are two numbers long, so 18 bytes)
3D ;dec a. If A was 1, it is decremented to zero, setting the z flag
1313 ;don't care about the size bytes
EB ;exchange de and hl
E7 ;copies the nine bytes at HL to OP1. HL is incremented 9
E5 ;' push hl' saves HL to the stack
<<do stuff with A or DE>>
E1 ;' pop hl' removes the last value off the stack and stores it to HL
E1E7 ;no need to 'push hl' again since we won't need it.
If you use the stack, don't leave anything on it when you exit. What RET actually
does is it pops off the last value on the stack and jumps to that address. So if you push to the satck and it isn't a valid address, you will almost definitely crash your calc.