'*************************************************************************** *** '** TableRead - will use the cal table referenced by TableCnt and the ** '** 12bit # in DataBuf(+1) to interpolate a fuel weight and store result ** '** in DataBuf. ** '*************************************************************************** *** TableRead: Index = 0 temp = 0 TableLoop: WHILE DataBuf >= (temp & $7FFF) 'the AND nixes the high bit of the last byte inthe table 'DEBUG "COND=",#(temp & $7FFF) GOSUB ParseCal IF tempH.7 = 1 THEN 'if it is, then DataBuf > max input count IF DataBuf >= (temp & $7FFF) THEN Index = Index + 1 GOSUB ParseCal DataBuf = temp RETURN 'exit loop, highest possible fuel weight in DataBuf ELSE GOTO EndTableRead ENDIF ENDIF Index = Index + 2 WEND 'Index will point at higher count number when exiting loop 'DEBUG ",I=",#Index,",T=",#temp,",D=",#DataBuf,10,13 Index = Index - 2 'reset pointer IF Index = 0 THEN Index = 1 GOSUB ParseCal:DataBuf = temp 'set answer to lowest fuel weight RETURN 'get out if lowest value read ENDIF EndTableRead: CalHIcnt = temp & $7FFF 'get the four numbers needed to extrapolate Index = Index + 1 'point to high fuel qty GOSUB ParseCal CalHIfuel = temp Index = Index - 3 GOSUB ParseCal CalLOcnt = temp Index = Index + 1 'point to low fuel qty GOSUB ParseCal 'don't need to transfer result cause CalLOFuel = temp 'do the math AARGlow = 0 AARGhigh = DataBuf - CalLOcnt BARG = CalHIfuel - CalLOfuel CALL UD_mpy 'result is in AARG pair BARG = CalHIcnt - CalLOcnt CALL UD_div 'result is in AARG pair DataBuf = AARGlow + CalLOfuel 'fuel weight * 10 now in DataBuf RETURN ParseCal: BRANCHL TableCnt,[LTCal,RTCal] LTCal: LOOKUP2 Index,[95,0,340,290,777,890,1090,1490,1366,2090,1624,2690,_ 1909,3290,2217,3890,2555,4490,2904,5090,3288,5690,36626,6290],temp 'last byte is count + 32768 RETURN RTCal: LOOKUP2 Index,[171,0,390,310,815,910,1121,1510,1392,2110,1652,2710,1930,3310,_ 2228,3910,2552,4510,2694,4770,2885,5110,3267,5710,36661,6310],temp 'last byte is count + 32768 RETURN '**** capacity of each tank is ~105 gallons (630 lbs)