Looking up a 2D table; How to recognize the code

This is where the BIN Hackers and definition junkies discuss the inner workings of the EEC code and hardware. General tuning questions do not go here. Only technical/hardware-specific/code questions and discussions belong here.

Moderators: cgrey8, EDS50, Jon 94GT, 2Shaker

Post Reply
mpaton
BIN Hacker
Posts: 370
Joined: Mon Jun 23, 2008 1:39 pm

Looking up a 2D table; How to recognize the code

Post by mpaton » Sat Oct 17, 2015 10:59 am

I've said in a another thread that you can rely on finding routines to look up 1D functions and 2D tables, and that they will usually have inline parameters.
They don't have to; many EEC-V bins pass parameters in registers.

So all ECUs need to look up valies in 2D and 1D data structures. Ford ECU folklore calls the 1D structure a function and the 2D one a table.

Ford in particular always uses 2 lookups of 1D functions prior to and whenever it looks up a 2D table.

This allows a smaller table that is more "precise" in some smaller regions, than a larger table that is precise everywhere. So it saves space.

However 1D lookups are also done not for 2D lookups. The airflow correction structure for a MAF system is a 1D lookup, and the airflow correction structure for a Speed Density system is a 2D lookup. That is the primary reason why SD calibration is a little bit harder. (it's not as hard as its made out to be).

All these lookups do the math for interpolation.

If your 1D lookup has 2 input values of 2 and 6 and corresponding output values of 50 and 30, and your input is 3, then what is your output?

it's 45.

But we need to know that math for that so we can recognize the code that does it.

Who wants to explain the math. I'm going on coffee break! :-)

Michael

tvrfan
Tuning Addict
Posts: 368
Joined: Sat May 14, 2011 11:41 pm
Location: New Zealand

Re: Looking up a 2D table; How to recognize the code

Post by tvrfan » Sat Oct 17, 2015 3:34 pm

I'm not going to post the answer, but as I'm inclined to give a little clue, I will say the way the the Ford code INTERPOLATES (look that up, it's a clue) on a 2D lookup (often called a table) and their use of non-linear values is actually very clever. No not in an obfuscated way, but simple, clever, and mathematically neat.

So far I've only found that one 2D method in all the bins I've looked at, so it's easy to spot. Sure there are a few twiddles around it, but the core code stays very much the same.

The 1D (function) lookup uses a simple interpolation too, and similarly the method hasn't changed much ever since the very oldest bins I've seen.

Michael can argue, but I think (must double check) that the later bins have more accurate ROLAV maths, but again use same core algorithm
TVR, Triumph (cars), kit cars, classics. Ex IT geek, development and databases.

https://github.com/tvrfan/EEC-IV-disassembler

mpaton
BIN Hacker
Posts: 370
Joined: Mon Jun 23, 2008 1:39 pm

Re: Looking up a 2D table; How to recognize the code

Post by mpaton » Sat Oct 17, 2015 5:08 pm

My intent in starting this thread is so that people can identify the function and table lookup code with great accuracy.

To do this, we need to understand the code, and to do that we want to understand the math that the code is trying to implement.

It's pretty simple math, but without it, people would be left guessing at what code they are looking at.

And we're doing all this because many of you good and curious people have asked how you know how many parameters might be inline.

So I'm hoping for another volunteer to explain the math for interpolation, perhaps using my example, and then together we can go over what code to do that would look like.

Michael

jsa
Tuning Addict
Posts: 519
Joined: Sat Nov 23, 2013 7:28 pm
Location: 'straya

Re: Looking up a 2D table; How to recognize the code

Post by jsa » Sat Oct 17, 2015 6:11 pm

mpaton wrote: This allows a smaller table that is more "precise" in some smaller regions, than a larger table that is precise everywhere. So it saves space.
Thank you for the detailed background information. Probably need to work through an example to see how precision and space trade off.
mpaton wrote:The airflow correction structure for a MAF system is a 1D lookup, and the airflow correction structure for a Speed Density system is a 2D lookup.


MAF volt row to get Mass of air from MAF Transfer function. SD needs MAP frequency row to get pressure and ACT Volt row to get temperature, then take pressure and temperature results to look up air mass table.

mpaton wrote: If your 1D lookup has 2 input values of 2 and 6 and corresponding output values of 50 and 30, and your input is 3, then what is your output?

it's 45.
6-2=4 the difference in the input range
50-30=20 the difference in the output range
20/4=5 per increment of output range
3-2=1 difference between present value of the input and one end of the input range
50-5=45 so working from the same end of the range, deduct the output range increment for 1 increment

50-(3-2)/(6-2)*(50-30)=45

Now it just needs to be put together as a formula that can be coded with 8061 opcodes.
mpaton wrote: Who wants to explain the math. I'm going on coffee break! :-)

Michael
I'll have double black with two please, that should jump start the head :)
tvrfan wrote:INTERPOLATES (look that up, it's a clue)
INTERPOLATION turns up results in the LHBH strategy document.
Some reading to do to see how my way compares to Ford's best.
Cheers

John

95 Escort RS Cosworth - GHAJ0 / ANTI on a COSY box code
Moates QH & BE
ForDiag

mpaton
BIN Hacker
Posts: 370
Joined: Mon Jun 23, 2008 1:39 pm

Re: Looking up a 2D table; How to recognize the code

Post by mpaton » Sat Oct 17, 2015 7:11 pm

jsa wrote:
mpaton wrote:The airflow correction structure for a MAF system is a 1D lookup, and the airflow correction structure for a Speed Density system is a 2D lookup.


MAF volt row to get Mass of air from MAF Transfer function. SD needs MAP frequency row to get pressure and ACT Volt row to get temperature, then take pressure and temperature results to look up air mass table.
The SD correction table is actually N,MAPPA if i recall correctly. You can read about it in the LHBH doc. Absolute ACT is important, and in the equation, but it's not part of ford's correction table.

jsa wrote:
mpaton wrote: If your 1D lookup has 2 input values of 2 and 6 and corresponding output values of 50 and 30, and your input is 3, then what is your output?

it's 45.
6-2=4 the difference in the input range
50-30=20 the difference in the output range
20/4=5 per increment of output range
3-2=1 difference between present value of the input and one end of the input range
50-5=45 so working from the same end of the range, deduct the output range increment for 1 increment

50-(3-2)/(6-2)*(50-30)=45

Now it just needs to be put together as a formula that can be coded with 8061 opcodes.
Thanks John

And of course when we get to the code, it's from the old days when a byte saved was worth something, so clever assembly code that was smaller was valued.

Michael

jsa
Tuning Addict
Posts: 519
Joined: Sat Nov 23, 2013 7:28 pm
Location: 'straya

Re: Looking up a 2D table; How to recognize the code

Post by jsa » Sat Oct 17, 2015 7:45 pm

LHBH talks about 4 point interpolation, so that would be for a 2D table ?

Probably what tvrfan was hinting at;
viewtopic.php?f=8&t=19610&hilit=interpolates

Sailorbob's example
viewtopic.php?p=47551#p47551
lower output + (((upper output - lower output) x (value in - lower input)) / (upper input - lower input)) = value out
50+(((30-50)*(3-2))/(6-2))=45
Cheers

John

95 Escort RS Cosworth - GHAJ0 / ANTI on a COSY box code
Moates QH & BE
ForDiag

tvrfan
Tuning Addict
Posts: 368
Joined: Sat May 14, 2011 11:41 pm
Location: New Zealand

Re: Looking up a 2D table; How to recognize the code

Post by tvrfan » Sat Oct 17, 2015 11:07 pm

In case it helps anyone, when I first looked at this (the code), I actually visualised in my head a spreadsheet like or matrix structure, with 11 X 11 (or whatever) cells, or dots, where the exact input values intersect.
Then when the two input values each fall between their data points, and where the answer would be as a point between 4 fixed ones.
That worked for me, and then I understood the code workings immediately....and why you only need 3 calls to the interpolation routine.

Just my 2c worth...
TVR, Triumph (cars), kit cars, classics. Ex IT geek, development and databases.

https://github.com/tvrfan/EEC-IV-disassembler

mpaton
BIN Hacker
Posts: 370
Joined: Mon Jun 23, 2008 1:39 pm

Re: Looking up a 2D table; How to recognize the code

Post by mpaton » Sat Oct 17, 2015 11:21 pm

I agree with both of you.

Michael

decipha

Re: Looking up a 2D table; How to recognize the code

Post by decipha » Sun Oct 18, 2015 1:07 am

most all the lookup interpolation routines in henrys code uses 34 36 38 or 3c as inputs in all that ive looked at

the function address is then incremented by a byte or word to find the less than value compared by the input

once it finds it those 4 values 2x x and 2x y are interpolated

Its usually pretty easy to find since there arent many places an L is incremented [xx+4] followed by a compare loop

mpaton
BIN Hacker
Posts: 370
Joined: Mon Jun 23, 2008 1:39 pm

Re: Looking up a 2D table; How to recognize the code

Post by mpaton » Tue Oct 20, 2015 12:10 pm

So now ironman has "fixed" all the calls to the 1D lookups, what are they doing?

Here's the first call

3F3B EF6006 call L459E
3F3E 8E00 word $008E
3F40 B600 word $00B6

or maybe we have
3F3B EF6006 call L459E
3F3E 8E byte $8E
3F3F 00 byte $00
3F40 B6 byte $B6
3F41 00 byte $00

depending on whether we used word or byte for the directives. That didn't matter when we did it, because our goal was just to disassemble code as code. Now we're going to look at the data.

So what's the code at $459E look like? We know it's going to look up a 1D table (single input, single output),we know there will be interpolation code. So there are 2 inputs to this routine, and one output. The inputs are the input to the table, or more likely the address of the input, and also the table, or more likely the address of the table.

So the code at $459E is

Code: Select all

459E  91209D        L459E   orb   REG_9D,#$20                   ; set REG_9D,BIT_05
45A1  2006                  sjmp  L45A9
45A3  91209D                orb   REG_9D,#$20                   ; set REG_9D,BIT_05
45A6  91109D                orb   REG_9D,#$10                   ; set REG_9D,BIT_04
45A9  CC36          L45A9   popw  REG_36
45AB  B23732                ldb   REG_32,[REG_36]+
45AE  B23733                ldb   REG_33,[REG_36]+
45B1  AC3334                ldzbw REG_34,REG_33
45B4  710F33                an2b  REG_33,#$0F                   ; clr REG_33,BIT_04 Edit
;                                                               ; clr REG_33,BIT_05
;                                                               ; clr REG_33,BIT_06
;                                                               ; clr REG_33,BIT_07
45B7  080434                shrw  REG_34,#$04
45BA  6735F00032            ad2w  REG_32,$00F0[REG_34]
45BF  B23734                ldb   REG_34,[REG_36]+
45C2  B23735                ldb   REG_35,[REG_36]+
45C5  C836                  pushw REG_36
45C7  B23434                ldb   REG_34,[REG_34]
45CA  9B320234      L45CA   cmpb  REG_34,$02[REG_32]
45CE  3D9D04                jb    REG_9D,BIT_05,L45D5
45D1  DB0A                  jc    L45DD
45D3  2002                  sjmp  L45D7
45D5  D606          L45D5   jge   L45DD
45D7  65020032      L45D7   ad2w  REG_32,#$0002
45DB  27ED                  sjmp  L45CA
45DD  71DF9D        L45DD   an2b  REG_9D,#$DF                   ; clr REG_9D,BIT_05
45E0  B23336                ldb   REG_36,[REG_32]+
45E3  B23338                ldb   REG_38,[REG_32]+
45E6  7A3236                sb2b  REG_36,[REG_32]
45E9  7A3334                sb2b  REG_34,[REG_32]+
45EC  7A3238                sb2b  REG_38,[REG_32]
45EF  3C9D04                jb    REG_9D,BIT_04,L45F6
45F2  DB09                  jc    L45FD
45F4  2002                  sjmp  L45F8
45F6  D605          L45F6   jge   L45FD
45F8  91209D        L45F8   orb   REG_9D,#$20                   ; set REG_9D,BIT_05
45FB  1338                  negb  REG_38
45FD  7C3438        L45FD   ml2b  REG_38,REG_34
4600  9C3638                divb  REG_38,REG_36
4603  359D02                jnb   REG_9D,BIT_05,L4608
4606  1338                  negb  REG_38
4608  763238        L4608   ad2b  REG_38,[REG_32]
460B  1139                  clrb  REG_39
460D  71DF9D                an2b  REG_9D,#$DF                   ; clr REG_9D,BIT_05
4610  71EF9D                an2b  REG_9D,#$EF                   ; clr REG_9D,BIT_04
4613  F0                    ret
So we see that after 45A9, it's going to execute the instructions at
45A9
45AB
45AE

Ironman, or jsa, would you like to explain what those 3 instructions do? you'll need to have downloaded the 8061 instruction guide.

Michael

jsa
Tuning Addict
Posts: 519
Joined: Sat Nov 23, 2013 7:28 pm
Location: 'straya

Re: Looking up a 2D table; How to recognize the code

Post by jsa » Tue Oct 20, 2015 9:16 pm

Ok, it will be a couple days until I can do it justice.
Cheers

John

95 Escort RS Cosworth - GHAJ0 / ANTI on a COSY box code
Moates QH & BE
ForDiag

ironmanisanemic
Regular
Posts: 175
Joined: Tue May 24, 2011 8:33 pm
Location: Vandenberg AFB, CA

Re: Looking up a 2D table; How to recognize the code

Post by ironmanisanemic » Thu Oct 22, 2015 9:03 pm

mpaton wrote:So now ironman has "fixed" all the calls to the 1D lookups, what are they doing?

Here's the first call

3F3B EF6006 call L459E
3F3E 8E00 word $008E
3F40 B600 word $00B6

or maybe we have
3F3B EF6006 call L459E
3F3E 8E byte $8E
3F3F 00 byte $00
3F40 B6 byte $B6
3F41 00 byte $00

depending on whether we used word or byte for the directives. That didn't matter when we did it, because our goal was just to disassemble code as code. Now we're going to look at the data.

So what's the code at $459E look like? We know it's going to look up a 1D table (single input, single output),we know there will be interpolation code. So there are 2 inputs to this routine, and one output. The inputs are the input to the table, or more likely the address of the input, and also the table, or more likely the address of the table.

So the code at $459E is

Code: Select all

459E  91209D        L459E   orb   REG_9D,#$20                   ; set REG_9D,BIT_05
45A1  2006                  sjmp  L45A9
45A3  91209D                orb   REG_9D,#$20                   ; set REG_9D,BIT_05
45A6  91109D                orb   REG_9D,#$10                   ; set REG_9D,BIT_04
45A9  CC36          L45A9   popw  REG_36
45AB  B23732                ldb   REG_32,[REG_36]+
45AE  B23733                ldb   REG_33,[REG_36]+
45B1  AC3334                ldzbw REG_34,REG_33
45B4  710F33                an2b  REG_33,#$0F                   ; clr REG_33,BIT_04 Edit
;                                                               ; clr REG_33,BIT_05
;                                                               ; clr REG_33,BIT_06
;                                                               ; clr REG_33,BIT_07
45B7  080434                shrw  REG_34,#$04
45BA  6735F00032            ad2w  REG_32,$00F0[REG_34]
45BF  B23734                ldb   REG_34,[REG_36]+
45C2  B23735                ldb   REG_35,[REG_36]+
45C5  C836                  pushw REG_36
45C7  B23434                ldb   REG_34,[REG_34]
45CA  9B320234      L45CA   cmpb  REG_34,$02[REG_32]
45CE  3D9D04                jb    REG_9D,BIT_05,L45D5
45D1  DB0A                  jc    L45DD
45D3  2002                  sjmp  L45D7
45D5  D606          L45D5   jge   L45DD
45D7  65020032      L45D7   ad2w  REG_32,#$0002
45DB  27ED                  sjmp  L45CA
45DD  71DF9D        L45DD   an2b  REG_9D,#$DF                   ; clr REG_9D,BIT_05
45E0  B23336                ldb   REG_36,[REG_32]+
45E3  B23338                ldb   REG_38,[REG_32]+
45E6  7A3236                sb2b  REG_36,[REG_32]
45E9  7A3334                sb2b  REG_34,[REG_32]+
45EC  7A3238                sb2b  REG_38,[REG_32]
45EF  3C9D04                jb    REG_9D,BIT_04,L45F6
45F2  DB09                  jc    L45FD
45F4  2002                  sjmp  L45F8
45F6  D605          L45F6   jge   L45FD
45F8  91209D        L45F8   orb   REG_9D,#$20                   ; set REG_9D,BIT_05
45FB  1338                  negb  REG_38
45FD  7C3438        L45FD   ml2b  REG_38,REG_34
4600  9C3638                divb  REG_38,REG_36
4603  359D02                jnb   REG_9D,BIT_05,L4608
4606  1338                  negb  REG_38
4608  763238        L4608   ad2b  REG_38,[REG_32]
460B  1139                  clrb  REG_39
460D  71DF9D                an2b  REG_9D,#$DF                   ; clr REG_9D,BIT_05
4610  71EF9D                an2b  REG_9D,#$EF                   ; clr REG_9D,BIT_04
4613  F0                    ret
So we see that after 45A9, it's going to execute the instructions at
45A9
45AB
45AE

Ironman, or jsa, would you like to explain what those 3 instructions do? you'll need to have downloaded the 8061 instruction guide.

Michael
Its going to be a while before i will be able to get to this. I have a bunch of stuff at work that i just got slammed with, plus all hell just broke out in my house. I might be having to do a trans rebuild on my wifes car and dont have the cash at the moment so i might have to take a second job. But i will try to work on this slowly when i have time.

Do you have a link to the 8061 instruction guide? I dont believe i have it already.

Thank you
1989 Ford Bronco:
-393W, Edelbrock Performer RPM heads, ProComp Upper and lower intake, Custom Comp Hyd Roller cam, 10:1 compression, 30lb injectors, 75mm TB, Pro-M 80mm MAF, equal length short tube headers, 2.5 inch y pipe merged into single 3 inch with hooker aerochamber muffler and no cat, QH w/ BE and EA running U4P0, AOD

1995 Ford Mustang GT
-Bone stock minus the QH. 5 Speed. T4M0

mpaton
BIN Hacker
Posts: 370
Joined: Mon Jun 23, 2008 1:39 pm

Re: Looking up a 2D table; How to recognize the code

Post by mpaton » Fri Oct 23, 2015 7:08 pm

ironmanisanemic wrote:
Do you have a link to the 8061 instruction guide? I dont believe i have it already.

Thank you
That's a good point. Calling cgrey!

was this just not restored after the board crash a few years ago, or is it gone for good?

Michael

User avatar
cgrey8
Administrator
Posts: 10565
Joined: Fri Jun 24, 2005 5:54 am
Location: Acworth, Ga (Metro Atlanta)
Contact:

Re: Looking up a 2D table; How to recognize the code

Post by cgrey8 » Sat Oct 24, 2015 5:09 am

If it was between April and September of 2014, then yeah, it was lost. I'm just glad I had a backup at all since none of Jon's backups were viable.
...Always Somethin'

89 Ranger Supercab, 331 w/GT40p heads, ported Explorer lower, Crane Powermax 2020 cam, 1.6RRs, FMS Explorer (GT40p) headers, Slot Style MAF, aftermarket T5 'Z-Spec', 8.8" rear w/3.27s, Powertrax Locker, Innovate LC-1, GUFB, Moates QuarterHorse tuned using BE&EA

Member V8-Ranger.com

mpaton
BIN Hacker
Posts: 370
Joined: Mon Jun 23, 2008 1:39 pm

Re: Looking up a 2D table; How to recognize the code

Post by mpaton » Sat Oct 24, 2015 12:28 pm

Could you put up a link for ironman please?

jsa
Tuning Addict
Posts: 519
Joined: Sat Nov 23, 2013 7:28 pm
Location: 'straya

Re: Looking up a 2D table; How to recognize the code

Post by jsa » Sat Oct 24, 2015 12:53 pm

Is it this or something better ?
Attachments
8061-5 Opcodes.xls
(45.5 KiB) Downloaded 199 times
Cheers

John

95 Escort RS Cosworth - GHAJ0 / ANTI on a COSY box code
Moates QH & BE
ForDiag

tvrfan
Tuning Addict
Posts: 368
Joined: Sat May 14, 2011 11:41 pm
Location: New Zealand

Re: Looking up a 2D table; How to recognize the code

Post by tvrfan » Sat Oct 24, 2015 2:47 pm

Here is a M$ doc one I got from somewhere a long time ago 8061 and 8065.
Attachments
8061_opcodes.doc
(205.98 KiB) Downloaded 398 times
TVR, Triumph (cars), kit cars, classics. Ex IT geek, development and databases.

https://github.com/tvrfan/EEC-IV-disassembler

jsa
Tuning Addict
Posts: 519
Joined: Sat Nov 23, 2013 7:28 pm
Location: 'straya

Re: Looking up a 2D table; How to recognize the code

Post by jsa » Sat Oct 24, 2015 3:22 pm

Page 45 on, of linked book below, gives some decent explanation of addressing modes.

http://bitsavers.informatik.uni-stuttga ... ndbook.pdf
Cheers

John

95 Escort RS Cosworth - GHAJ0 / ANTI on a COSY box code
Moates QH & BE
ForDiag

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests