This is the entire 1D/Function byte lookup code from the early 'AA' box. This is the simplest I've seen, but still is the exact same technique used throughout all single bank bins. I've even labelled the signed/unsigned flag for you. This contains all the lookup loop logic and maths necessary to do a 1d lookup, both for signed and unsigned functions.
( Later bins have 4 options, signed in/out, unsigned in/out, and have a bit more code....but not that much extra.)
On entry - R32 is address of function, R34 is input (lookup) value. Answer is returned in R38.
See if you can sort out how this works, it's fairly straightforward and doesn't have any nasty tricks.
Code: Select all
SBFuncLu: #signed
2f9c: 91,02,f6 orb Rf6,2 SIGNED = 1;
UBFuncLu: #unsigned
2f9f: 9b,32,02,34 cmpb R34,[R32+2]
2fa3: 31,f6,04 jnb B1,Rf6,2faa if (!SIGNED) goto 2faa;
2fa6: db,0a jc 2fb2 if (CYflag) goto 2fb2;
2fa8: 20,02 sjmp 2fac goto 2fac;
2faa: d6,06 jge 2fb2 if (R34 < [R32+2]) {
2fac: 65,02,00,32 ad2w R32,2 R32 += 2;
2fb0: 27,ed sjmp 2f9f goto UBFuncLu; }
2fb2: b2,33,36 ldb R36,[R32++] R36 = [R32++];
2fb5: b2,33,38 ldb R38,[R32++] R38 = [R32++];
2fb8: 7a,32,36 sb2b R36,[R32] R36 -= [R32];
2fbb: 7a,33,34 sb2b R34,[R32++] R34 -= [R32++];
2fbe: 7a,32,38 sb2b R38,[R32] R38 -= [R32];
2fc1: 31,f6,04 jnb B1,Rf6,2fc8 if (!SIGNED) goto 2fc8;
2fc4: db,09 jc 2fcf if (CYflag) goto 2fcf;
2fc6: 20,02 sjmp 2fca goto 2fca;
2fc8: d6,05 jge 2fcf if (R38 < [R32]) {
2fca: 91,01,f6 orb Rf6,1 Rf6 |= 1;
2fcd: 13,38 negb R38 R38 = -R38; }
2fcf: 7c,34,38 ml2b R38,R34 R38 *= R34;
2fd2: 9c,36,38 divb R38,R36 R38 = R38 / R36;
2fd5: 30,f6,02 jnb B0,Rf6,2fda if (B0 Rf6) {
2fd8: 13,38 negb R38 R38 = -R38; }
2fda: 76,32,38 ad2b R38,[R32] R38 += [R32];
2fdd: 71,fc,f6 an2b Rf6,fc B0_Rf6 = 0;
SIGNED = 0;
2fe0: f0 ret return;