;
;	EFI.ASM - Edelbrock Pro-Flo dis-assembly
;	Started: 10/18/98
;
	comment ~

	This code as it sits will assemble into the same binary image as what
	is in the Edelbrock PN. 3516 EPROM.
	Note that the code between $8000 and $EFFF is the same for all of the
	Edelbrock ROM's.  The calibration portion between $F000 and $FFD6 that
	contain all of the constants and tables for a particular application
	is the only difference.


09/04/99 - Added comments and definitions found in WS's dis-assembly.  Should
	    help understanding this code.  As usual take with a grain of salt.
	    Probably will never update this version again.  My working copy
	    of the code is much better documented.

	~
yes		equ	-1
no		equ	0
;
my_cl_parms		equ	no	; use my closed loop RPM/Vacuum values
cl_upper_rpm_lim	equ	4200/25 ; 4,200 RPM upper limit (nc)
cl_lower_rpm_lim	equ	600/25	; try bring all the way to Idle
cl_upper_vac_lim	equ	55	; ~22" MAP
cl_lower_vac_lim	equ	194	; ~6"  MAP
;
my_rpm_trip		equ	no	; use my RPM trip table (fuel cutoff)
my_dashpot_table	equ	no	; use my dashpot table
;
no_fills	equ	no	; skip un-needed fills
mis1x		equ	no	; skip...........
mis2x		equ	no	; skip
mis4x		equ	no	; skip
mis5x		equ	no	; skip
mis6x		equ	no	; skip
mis7x		equ	no	; skip
mis8x		equ	no	; clear all unused bits of L00ba
mis9x		equ	no	; skip
mis10x		equ	no	; skip
mis11x		equ	no	; skip - multiple push/pops of same register
mis12x		equ	no	; skip
mis13x		equ	no	; skip
mis14x		equ	no	; skip associated code	(mis44)
mis15x		equ	no	; clean up excessive IAC code and wastes
mis16x		equ	no	; skip - takes care of mis24
mis17x		equ	no	; injector firing code that never gets called
mis18x		equ	no	; skip
mis19x		equ	no	; skip
mis20x		equ	no	; skip
mis21x		equ	no	; skip
mis22x		equ	no	; skip - may not be a problem - 09/04/99
mis25x		equ	no	; skip
mis26x		equ	no	; skip (closed loop stuff)
mis_clsd_lp1	equ	no	; bunch of extra calculation done in trying
				;  to calculate closed loop PW stuff
				; mis27: mis28: mis29 mis30: mis31:
mis32x		equ	no	; TPS closed Spark Angle lookup (mis32,mis33)
mis34x		equ	no	; replace with constant
mis35x		equ	no	; replace with constant
mis36x		equ	no	; cut out usless spark stuff (mis37:, mis37a:)
mis38x		equ	no	; takes care of mis38, mis47, mis23, mis46
mis39x		equ	no	; cut out
mis42x		equ	no	; skip
mis43x		equ	no	; skip
mis45x		equ	no	; skip
mis48x		equ	no	; skip
;
; Some of this needs to be added back in - 09/04/99
mis49x		equ	no	; all the L0008 MAP ADC offset stuff
;
mis51x		equ	no	; skip
mis52x		equ	no	; skip
mis53x		equ	no	; skip
mis55x		equ	no	;
mis56x		equ	no	; skip	(also takes care of mis66:)
mis57x		equ	no	; Lf01d XORing - Ign Coil Driver Mode
mis58x		equ	no	; skip
mis60x		equ	no	; skip
mis61x		equ	no	; skip
mis62x		equ	no	; skip
mis63x		equ	no	; skip
mis64x		equ	no	; skip
mis65x		equ	no	; skip
mis67x		equ	no	; skip
L6000_skip	equ	no	; wire arround L6000 stuff
;
misc1		equ	no	; un-needed test
batt_mis	equ	no	; un-needed test

;
;==============================================================================
; Code sub-routine Map:
;
;  8010 - 83ae		Main Entry - Initialization
;  83af - 8ca8		Main Calibration Run Loop
;  8ca9 - 9512	IC1	Distributor Trigger Interrrupt Handler
;    8ca9 - 8f70	Ign Trigger stuff and #1 detector
;    8f85 - 9121	#8 #3 #5 #2 path
;    9124 - 9238	#1 #4 #6 #7 path
;      923b - 92ee	path join-up
;	 92f5 - 936b	slower than 5,500 rpm
;	 936b - 	faster than 5,500 rpm or faster than Idle Target RPM
;	 9373 - 	faster than Target Idle RPM
;	   9398 	re-join
;	 93ea - 9490	below 5,000 rpm
;	 9490		above 5,000 rpm re-join
;
;  9513 - 9651	TOF	Timer Overflow Interrupt Handler
;  9652 - 9720	OC4	Ignition Amp (SA) Driver Interrupt Handler
;  9721 - 972f	OC3	EEPROM Timer
;  9730 - 973f	OC2	Injector-D Interrupt handler
;  9740 - 97dd	OC1	Idle Air Motor Interrupt Handler
;  97de - cfff		No Code - 14k gap......
;  d000 - d47d		IAS and dashpot
;  d47e - d6e9		Returns new Injector Pulse width subroutine
;  d6ea - d8a4		Save/Restore Dataset subroutine
;  d8a5 - da7d		Numerous subroutines - math - lookups
;  da7e - db06		Fire specified Injector
;  db07 - dbc7		Checks for warning and sensor Errors
;  dbc8 - dc9c		more subroutines ....
;  dc9d - ddf6	SCI	Serial System Interrupt Handler
;  ddf7 - efff		No Code - 4.6k gap......
;  f000 - ffc0		Look-up Tables and Constants
;  ffc0 - ffff		CPU Interrupt vectors
;
; =============================================================================
; Mistake Log . . . . . . .
;
; Distributor Trigger Handler. . . . .
; * mis1: mis2:
;	The code that modifies L0043 checks for roll. Even if all byte values
;	are 255 there is no way for the value to ever get over 255....
; * mis3:
;	The code that detects the narrow #1 cylinder timing pulse does not work.
; * mis10:
;	Bit 1xxxxxxx of L005b is set but never used.
; * mis11:
;	A push/pop that does nothing.....
; * mis12:
;	Will never take this branch because a compare of zero and a BCS..
; * mis13:
;	Bit xxxx1xxx of L005d (ram_005d) is cleared but never tested anywhere
; * mis4:
;	L0038 is cleared but never used anywhere.
; * mis5:
;	L003e is cleared twice almost in a row.
; * mis6:
;	The xxxxx11x bits of L00bc are tested but are never set anywhere.
; * mis7:
;	Will always take this branch because they are comparing a zero to a
;	value and jumping on carry-clear, which it can never set Carry.
; * mis8:
;	Bits xxxxx1xx and xxxxxx1x of L00ba are set but never used anywhere.
; * mis9:
;	Cannot find this target label and jump being used anywhere.
; * mis14: mis14a: mis14b:
;	Never execute this code because above tests always by-passes it.
; * mis15:
;	A mess of code in the IAC computations is usless because of what the
;	 tables are set at.  Goes thru a whole bunch of work to always come
;	 up with the exact same results.
; * mis16:
;	Never take some code because A is loaded with a zero followed by BEQ.
; * mis17:
;	Looks like this code to fire the injectors (maybe during starting)
;	 never gets called...
; * mis18:
;	Will never take this jump.  No byte can be higher than the 255 constant.
; * mis19: mis20:
;	Couple place that will always take a jump needlessly
; * mis21: mis56:
;	Will always take this branch because comparing zero to a non-zero
;	 number followed with a bhi.  Comparing a zero will always clear carry.
; * mis22:
;	Stashed something into L0000 then a few lines later stashed something
;	 else into it.
;	09/03/99 - This may be needed because the next instructions turns on the
;		   interrupts so maybe to assure some value stash now ?
; * mis23: mis24: mis48:
;	Can never take this branch
; * mis25: mis46:
;	more piss-poor logic and needless tests
; * mis26:
;	multiply a number by 16 then divide it by 16 ????? - makes sense
; * mis27: mis28: mis30
;	these stashs are not used anywhere in the following calculations
; * mis29: mis31:
;	a bunch of calculations that always result in zero......
; * mis32: mis33:
;	more bs because tables contain all the same entries......
; * mis34: mis35:
;	don't need to do these calculations - just use constant
; * mis36:
;	more usless lookup because table has all the same entries
; * mis37: mis37a:
;	section of code assumes that the A reg still contains the spark angle
; * mis38: mis39:
;	stash that does nothing because only a zero ever gets loaded
; * mis40:
;	bit x1xxxxxx of L005c gets set but is never cleared anywhere
;	Left because low usage and absolutely sure why they did this
; * mis41:
;	bit 1xxxxxxx of L005c gets set but is never cleared anywhere
;	Left because low usage and absolutely sure why they did this
;
; * mis42: (several locations)
;	with constants used adding a 1 to L0014 will never roll.
; * mis43:
;	with constant used result will always be zero
; * mis44:
;	L0073 never gets used.	Where it is bumped never gets called
; * mis45:
;	storing and loading back the same register
; * mis47:
;	bit 1xxxxxxx of L0058 useless because of mis38:
; * mis49: mis49a: mis49b: mis49c: mis49d: mis49e:
;	problems with the MAP offset that gets loaded into L0008 and applied
;	 to L0000.  The whole MAP correction may not do anything !!!!!
;	 This would mean all the corrected values I applied with L0000
;	 are wrong !
;	12/28/98 - They are. L0008 is always zero !!!!!!!!
;	09/03/99 - Well it looks like I was wrong.  The initial value computed
;		   into is a valid altitude compression value.
;	09/04/99 - There still is a problem with some of the code were it looks
;		   like it is trying to re-compute this compression factor
;		   while the motor is running.	The TPS values choosen will
;		   always by-pass this section of code.
;
; * mis50:
;	why calculate when just get the darn thing
;	01/03/99 - left because low usage and might be needed
;
; * mis51: mis51a: mis51b:
;	needless loads into IY
; * mis52: mis53:
;	needless clc
; * mis54:
;	I believe this bit will always be zero at this point because prev clear
;	01/03/99 - Left because it may affect a situation where the motor was
;		   running then stoped without loosing power to EMU.
;
; * mis55:
;	bit xxxxx1xx of L0058 useless because never tested anywhere
; * mis57:
;	xor with a 0 does nothing....
; * mis58: mis58a: mis58b: mis58c:
;	with values used can never take branch
; * mis59: mis59a: mis59c: mis59d:
;	can jump arround these calculations because results are always zero
; * mis60: mis60a:
;	why test when load sets the flags
; * mis61: mis61a:
;	with L004e and L004f limited to +-127 and the scaling multipliers used
;	  the results can never be this high.
; * mis62:
;	subtract zero from a value
; * mis63:
;	don't think need to clear this work stash......
; * mis64:
;	subtracting zero then branching on carry
;	01/03/99 - left this as I may experiment with it
; * mis65:
;	not needed register set
; * mis66:
;	bunch of do nothing code
; * mis67:
;	another sub-routine that is never called
; * mis68:
;	now that I see where L6000 comes from it can be wired arround
;   mis69:
;	The COP system is not being enabled.  The NOCOP bit in the CONFIG
;	register is set to one (1) disabling the COP watch dog timer !!!!
;	12/13/98 - read the CONFIG register = 00001101
;	01/03/99 - Left it in for the time being.
;
;  mis70:
;	If the only difference in the first dist trigger path decision (over
;	 4,500 rpm is that #1 shutter is looked at maybe can reduce code lines.
;  mis71:
;	Might check and see how often L004e and L004f are zero. If a lot then
;	maybe be able to skip some code here. If these stash are used alot
;	then maybe not.
;
; ==============================================================================
; The following is what is sent to the command module.	This sequence is the
;  current operating conditions......
;
; ECU RPM is ignition trigger period times 125,000
;
;ram_003e	equ	$003e	00c2	; RPM from the ECU	hi byte
;ram_003f	equ	$003f	00c3	;  .....RPM		low byte
;ram_0041	equ	$0041	00c5	; current Vacuum from ECU	hi byte
;ram_0042	equ	$0042	00c6	;  .....VAC			lo byte
;ram_0043	equ	$0043	00c7	; SPK - Spark Angle stash
;ram_0044	equ	$0044	00c8	; FUEL - injector Pulse Width	hi byte
;ram_0045	equ	$0045	00c9	;  .....FUEL			lo byte
;ram_0046	equ	$0046	00ca	; TAIR - Air Temperature
;ram_0047	equ	$0047	00cb	; Battery Voltage
;ram_0048	equ	$0048	00cc	; TPS - Throttle Position Sensor
;ram_0049	equ	$0049		; TH2O - Water Temp from ECU
;ram_004a	equ	$004A		; Idle Target RPM
;ram_004b	equ	$004B		; Idle Motor Activity
;ram_004c	equ	$004C		; Mixture flags
;					; 0xxxxxxx - Both LED's Off
;					; 1xxxxxxx - Both LED's On
;					; x1xxxxxx - Only One LED is on
;					; x0xxxxxx - Both LED's are On or Off
;					; xxxx0xxx - Red LED On (lean)
;					; xxxx1xxx - Green LED On (rich)
;
;ram_004d	equ	$004D		; Warning message index
;					; 1xxxxxxx - MAP Sensor Error
;					; x1xxxxxx - H20 Temp. error
;					; xx1xxxxx - Voltage Hi/Low
;					; xxx1xxxx - Throttle Input Error
;					; xxxx1xxx - AIR Temp. error
;					; xxxxx1xx - O2 Sensor error
;
; -----------------------------------------------------------------------------
;  Message sent to the ECU to request data
;
;  NOTE: The third byte sent is the number of bytes being transmitted.....
;
;	7B 05 12 80 00 - return ECU software revision information
;			 16 ascii characters starting with the 5th received
;	7B 05 0A F0 00 - return CAL info from ECU
;			 8 ascii characters starting with the 5th received
;	7B 02 7D       - request for engine operating conditions
;
;	7B 06 03 00 7F 91 - Save dataset 'A'
;	7B 06 03 00 7F 92 - Save dataset 'B'
;	7B 06 03 00 7F 93 - Save dataset 'C'
;	7B 06 03 00 7F A0 - Restore Base dataset
;	7B 06 03 00 7F A1 - Restore 'A' dataset
;	7B 06 03 00 7F A2 - Restore 'B' dataset
;	7B 06 03 00 7F A3 - Restore 'C' dataset
;
; The following are sent to the ECU to verify that the Save/Restore was
;  successful.	Notice that the only difference is in the 2nd byte (05) between
;  a command to do and a request for success.  If a failure occured then the
;  6th byte (ram_0029) is NZ.  Success then ram_0029 = 0.
;
;	7B 05 03 00 7F 91 - Success saving dataset 'A' ?
;	7B 05 03 00 7F 92 - Success saving dataset 'B' ?
;	7B 05 03 00 7F 93 - Success saving dataset 'C' ?
;	7B 05 03 00 7F A0 - Success Restoring Base dataset ?
;	7B 05 03 00 7F A1 - Success Restoring 'A' dataset ?
;	7B 05 03 00 7F A2 - Success Restoring 'B' dataset ?
;	7B 05 03 00 7F A3 - Success Restoring 'C' dataset ?
;
; These are from the  screens.....
;
; Query:     7B 05 03 00 B0    - ask for target Idle RPM value
; Response:  7B 05 03 00 B0 xx - Target_RPM = (xx-128) * 25
; Update:    7B 06 03 00 B0 VL - VL = (work_value/25) + 128
;
; Query:     7B 05 03 00 B2    - ask for Rev Limiter RPM
; Response:  7B 05 03 00 B2 xx - Rev_Limit_RPM = (xx * 250)
; Update:    7B 06 03 00 B2 VL - VL = (work_value / 250)
;
; Query:     7B 05 03 00 AB    - ask for Idle Fuel Mod		+/-50%
; Response:  7B 05 03 00 AB xx - Idle_Fuel = (xx-128) * .78125 {round up}
; Update:    7B 06 03 00 AB VL - VL = (work_value/.78125) + 128
;
; Query:     7B 05 03 00 AF    - ask for Idle Spark Mod 	+/-16%
; Response:  7B 05 03 00 AF xx - Idle_Spk = (xx-128) * .25
; Update:    7B 06 03 00 AF VL - VL = (work_value/.25) + 128
;
; Query:     7B 05 03 00 B1    - ask for Idle Speed Activity	+/-50%
; Response:  7B 05 03 00 B1 xx - Idle_Activity = (xx-128) * .78125 {round up}
; Update:    7B 06 03 00 B1 VL - VL = (work_value/.78125) + 128
;
; Query:     7B 05 03 00 B3    - on/off flags
; Response:  7B 05 03 00 B3 xx - 1xxxxxxx - Base Timing Set: On
;				 0xxxxxxx - Base Timing Set: Off
;				 x1xxxxxx - Closed Loop Fuel: Off
;				 x0xxxxxx - Closed Loop Fuel: On
;				 xx1xxxxx - Idle Control: Off
;				 xx0xxxxx - Idle Control: On
; Update:    7B 06 03 00 B3 VL - mask byte set to above conditions
;
; The following are for the Spark Modifier pages...............................
;
;   All Spark modifiers are +8 degrees / -16 degrees
;
; Query:     7B 05 03 00 98    - Sprk @ WOT @ 1000 RPM
; Query:     7B 05 03 00 99    - Sprk @ WOT @ 1750 RPM
; Query:     7B 05 03 00 9A    - Sprk @ WOT @ 2500 RPM
; Query:     7B 05 03 00 9B    - Sprk @ WOT @ 3500 RPM
; Query:     7B 05 03 00 9C    - Sprk @ WOT @ 4500 RPM
; Query:     7B 05 03 00 9D    - Sprk @ WOT @ 6000 RPM
;
; Query:     7B 05 03 00 9E    - Sprk @ 09" @ 1000 RPM
; Query:     7B 05 03 00 9F    - Sprk @ 09" @ 1750 RPM
; Query:     7B 05 03 00 A0    - Sprk @ 09" @ 2500 RPM
; Query:     7B 05 03 00 A1    - Sprk @ 09" @ 3500 RPM
; Query:     7B 05 03 00 A2    - Sprk @ 09" @ 4500 RPM
; Query:     7B 05 03 00 A3    - Sprk @ 09" @ 6000 RPM
;
; Query:     7B 05 03 00 A4    - Sprk @ 18" @ 1000 RPM
; Query:     7B 05 03 00 A5    - Sprk @ 18" @ 1750 RPM
; Query:     7B 05 03 00 A6    - Sprk @ 18" @ 2500 RPM
; Query:     7B 05 03 00 A7    - Sprk @ 18" @ 3500 RPM
; Query:     7B 05 03 00 A8    - Sprk @ 18" @ 4500 RPM
; Query:     7B 05 03 00 A9    - Sprk @ 18" @ 6000 RPM
; Query:     7B 05 03 00 AE    - Global Spark
;
; All Responses are at ram_0029 (6th byte) in the format of:
;	Sprk = (xx-128) * .25
;
; To Update, the byte at ram_0025 (2nd byte) is changed to 06.	The 6th
;  location (ram_0029) contains the value to update:
;	VL = (work_value / .25) + 128
;
; .............................................................................
; The following are from the FUEL modifier pages......
;
; All Fuel modifiers are +50% to -30%
;
; Query:     7B 05 03 00 80    - Fuel @ WOT @ 1000 RPM
; Query:     7B 05 03 00 81    - Fuel @ WOT @ 2000 RPM
; Query:     7B 05 03 00 82    - Fuel @ WOT @ 3000 RPM
; Query:     7B 05 03 00 83    - Fuel @ WOT @ 4000 RPM
; Query:     7B 05 03 00 84    - Fuel @ WOT @ 5000 RPM
; Query:     7B 05 03 00 85    - Fuel @ WOT @ 7000 RPM
;
; Query:     7B 05 03 00 86    - Fuel @ 06" @ 1000 RPM
; Query:     7B 05 03 00 87    - Fuel @ 06" @ 2000 RPM
; Query:     7B 05 03 00 88    - Fuel @ 06" @ 3000 RPM
; Query:     7B 05 03 00 89    - Fuel @ 06" @ 4000 RPM
; Query:     7B 05 03 00 8A    - Fuel @ 06" @ 5000 RPM
; Query:     7B 05 03 00 8B    - Fuel @ 06" @ 7000 RPM
;
; Query:     7B 05 03 00 8C    - Fuel @ 12" @ 1000 RPM
; Query:     7B 05 03 00 8D    - Fuel @ 12" @ 2000 RPM
; Query:     7B 05 03 00 8E    - Fuel @ 12" @ 3000 RPM
; Query:     7B 05 03 00 8F    - Fuel @ 12" @ 4000 RPM
; Query:     7B 05 03 00 90    - Fuel @ 12" @ 5000 RPM
; Query:     7B 05 03 00 91    - Fuel @ 12" @ 7000 RPM
;
; Query:     7B 05 03 00 92    - Fuel @ 18" @ 1000 RPM
; Query:     7B 05 03 00 93    - Fuel @ 18" @ 2000 RPM
; Query:     7B 05 03 00 94    - Fuel @ 18" @ 3000 RPM
; Query:     7B 05 03 00 95    - Fuel @ 18" @ 4000 RPM
; Query:     7B 05 03 00 96    - Fuel @ 18" @ 5000 RPM
; Query:     7B 05 03 00 97    - Fuel @ 18" @ 7000 RPM
;
; Query:     7B 05 03 00 AD    - Transient Fuel
; Query:     7B 05 03 00 AC    - Cold Start Fuel
; Query:     7B 05 03 00 AA    - Global Fuel
;
; All Responses are at ram_0029 (6th byte) in the format of:
;	Fuel = (xx-128) * .78125  {round up}
;
; To Update, the byte at ram_0025 (2nd byte) is changed to 06.	The 6th
;  location (ram_0029) contains the value to update:
;	VL = (work_value / .78125) + 128
;
;==============================================================================
;
; The following is what I know (I hope) about the ECU hardware and PAL mapping.
;
;
; Memory Map ............
;
;
;		+---------------------- A15	PAL
;		|+--------------------- A14	PAL  ROM
;		||+-------------------- A13	PAL  ROM
;		|||+------------------- A12	     ROM  Timer(CS1)
;		||||+------------------ A11	     ROM
;		|||||+----------------- A10	     ROM  Timer(RS2)
;		||||||+----------------  A9	     ROM  Timer(RS1)
;		|||||||+---------------  A8	     ROM  Timer(RS0)
;		|||||||| +-------------  A7
;		|||||||| |	+------  A0	A0-A7 PAL only
;		|||||||| |	|
;	0000	00000000 00000000	Base of System RAM  (512 bytes)
;	00FF	00000000 11111111	Top of System RAM
;
;	1000	00010000 00000000	Base of 64-byte register block
;	103F	00010000 00111111	Top of register block
;
;	3000	00110000 00000000	Control Register #1 and #3
;	3100	00110001 00000000	Control Register #2
;	3200	00110010 00000000	MSB Buffer Register #1
;	3300	00110011 00000000	Timer #1 Latchs
;	3400	00110100 00000000	MSB Buffer Register #2
;	3500	00110101 00000000	Timer #2 Latches
;	3600	00110110 00000000	MSB Buffer Register #3
;	3700	00110111 00000000	Timer #3 Latches
;
;	4000	01000000 00000000	Fuel Pump PAL latch
;	6000	01100000 00000000	PAL - reads L9112D Invertor
;
;	8000	10000000 00000000	First block of code
;	97DD	10010111 11011101	End of first block of code
;
;	B600	10110110 00000000	Base of EEPROM	(512 bytes)
;	B7FF	10110111 11111111	Top of EEPROM
;
;	D000	11010000 00000000	Start of second block of code
;	DDF6	11011101 11110110	End of second block
;
;	F000	11110000 00000000	; Look up tables and constants
;	FFB6	11111111 10111111	;......
;
;	FFC0	11111111 11000000	; start of interrupt tables
;	FFFF	11111111 11111111	; Top of 64k address space
;
; ----------------------------------------
; Look-up tables......
;
; First we check out EEPROM.  If the checksum computes transfer it to RAM.
;  If checksum incorrect then get data from ROM.....
;
;  EEPROM   B600-B63E (checksum at B63F) - This is where Dataset 'A' lives
;	    B640-B67E (checksum at B67F) -		 Dataset 'B'
;	    B680-B6BE (checksum at B6BF) -		 Dataset 'C'
;
;  RAM	    0080-00B5			 - modifiers are here
;  ROM	    F740-F775			 - get from here if bad EEPROM
;
; -----------------------------------------------------------------------------
;  System Clock......
;
;	8 MHz XTAL
;	2 MHZ 'E' clock
;	The main system timers prescaler is set to divide by 4.  This would
;	 set its freq to 500 KHz with a period of 2 us.
;	Input into the 6840 time is divided by 8 to 250 KHz (4us)
;
; -----------------------------------------------------------------------------
;  External Timer .......
;
;	SG Thompson EF68B40PV	- Three 16 bit timers
;	Same as EF3840, MC6840, or HD6340
;
;	All the clock inputs are fed with a 250 KHz clock ( E clock / 8)
;	4us per per count
;	All the gates are tied to ground.
;	The are configured in 16 bit Single shot mode...
;
;	Timer #1 (O1) - drives INJ-A (cylinders 1 and 8)
;	Timer #2 (O2) - drives INJ-C (cylinders 4 and 3)
;	Timer #3 (O3) - drives INJ-B (cylinders 6 and 5)
;
;	Addressing:
;		A12 is tied to the CS1
;		A11 - is qualified by the PAL - *CS0
;		A10 - RS2
;		 A9 - RS1
;		 A8 - RS0
;
;	Address 	Write			Read
;
;	 $3000		Control Register #3		0
;			Control Register #1		0
;	 $3100		Control Register #2		Status Register
;	 $3200		MSB Buffer Register #1		Timer #1 Counter
;	 $3300		Timer #1 Latchs 		LSB Buffer Register
;	 $3400		MSB Buffer Register #2		Timer #2 Counter
;	 $3500		Timer #2 Latches		LSB Buffer Register
;	 $3600		MSB Buffer Register #3		Timer #3 Counter
;	 $3700		Timer #3 Latches		LSB Buffer Register
;
timer_cntr_regx equ	$3000
timer_cntr_reg2 equ	$3100
timer_1_msb	equ	$3200
timer_1_lsb	equ	$3300
timer_2_msb	equ	$3400
timer_2_lsb	equ	$3500
timer_3_msb	equ	$3600
timer_3_lsb	equ	$3700
;
;
; -----------------------------------------------------------------------------
;  ADC.......
;
;	The ADC's are referenced to the +5 volt supply.
;	Full scale ADC voltage	-->  5 * (255/256) = 4.98046875 volts
;	Bit sensitivity 	-->  4.98046875 / 255 = 19.53125 mv/bit
;
;	AN0 - Its input is selected thru one of three switches.
;		SW1 - PAL-13 selected - HY3-2 which is not loaded
;		SW2 - PAL-39 selected - HY2-7 which does what ??????
;		SW3 - PAL-40 selected - PT1 which is not loaded
;
;	AN1 - conditioned input from Pin-9 which is a No Connect
;
;	AN2 - MAT input from HY1-7.  The conditioned input is:
;
;			4.3 - Vadc
;	      Vadc - ( ------------  *	358 )
;			   2720
;  Rmat =    --------------------------------
;			4.3 - Vadc
;			----------
;			   2720
;
;  or much simpler........
;
;		R_sensor + 358
;  Vadc =  ( ---------------------- ) * 4.3
;	      2720 + 358 + R_sensor
;
;
;	AN3 - COOL temperature sensor.	Its input follows the same rules as MAT.
;
;	AN4 - O2 Sensor - Gain from Pin-2 (O2 sensor input) to the input
;		of the ADC is * 2.972 with a 46 mv offset.
;	      O2v = ((ADC-2) * Vadc_bit) / 2.972
;
;	AN5 - TPS - 1:1 relationship between the input signal and the ADC
;
;	AN6 - BATT - The battery voltage is divided by 3.2103 before reaching
;		       the ADC.
;		     ADC = ( BATT / 3.2102728725 ) / .01953125	  or
;		     ADC = BATT / .0625
;		     BATT = ADC * .0625
;		     255 = 16 volts
;
;	AN7 - MAP - 1:1 relationship between the input signal and the ADC
;
; -----------------------------------------------------------------------------
;  Misc MPU I/O.....
;
;	-IRQ  (pin 19) - pulled up thru a 1.5k to +5v only - Not Used
;	-XIRQ (pin 18) - pulled up thru a 1.5k to +5v only - Not Used
;	RESET (pin 17) - comes from the input voltage regulator.
;	PA7/pai/OC1 - (pin 27) - goes to the IAC driver.
;	PA4/OC4/oc1 - (pin 30) - goes to the SA (Ign Amplifer)
;	PA2/IC1     - (pin 32) - conditioned input from the distributor trigger.
;	PD1/TxD     - (pin 21) - thru a hi-current driver to Pin-27 (ECU TX)
;	PA6/OC2/oc1 - (pin 28) - to the MUX (INJ-D driver)
;	PD0/RxD     - (pin 20) - from the MUX (Pin-8 ECU RX) ?????
;
;
;  OC1 - IAC driver (pin 27)
;	 Output from OC1 directed to PA7 (pin 27)			$100C
;	 Output a 1 (High) to PA7 (pin 27) after successful compare	$100D
;
;  OC3 - Used for progaming the EEPROM.
;
;  OC4 - Ignition Amplifier drive
;
;  IC1 - Distributor trigger input
;
; -----------------------------------------------------------------------------
;  The PAL ...... (SG F22HA9231)
;
;  Outputs:
;	xxxx	PAL-1	MUX-15	(always hi)
;	xxxx	PAL-3	MUX-12	(always hi)
;	xxxx	PAL-4	MUX-2	(always hi)
;	xxxx	PAL-5	MUX-6	(always hi)
;	xxxx	PAL-38	AN0 switch select (1E) always lo-off
;	xxxx	PAL-39	AN0 switch select (2E) always lo-off
;	xxxx	PAL-40	AN0 switch select (3E) always lo-off
;	xxxx	PAL-41	Thru Hi_current driver to Pin-12 - N/C
;	xxxx	PAL-43	Fuel Pump relay driver
;	xxxx	PAL-44	YY2-7 reset transistor	starts low then hi before PAL-43
;
;
pal_4000_latch	equ	$4000	; latch driving fuel pump and ????
;				; x1xxxxxx - turn on PAL-44
;				; xx1xxxxx - turn on Fuel Pump	PAL-43
;
;==============================================================================
ram_base	equ	$0000	; base of RAM

eeprom_base	equ	$b600	; start of EEPROM
;
; -----------------------------------------------------------------------------
;
register_base	equ	$1000		; base of the register block
;
; Vacuum(in) = 28.9 - (ECU_VAC * .01152)
;
;
; -----------------------------------------------------------------------------
; TPS(degrees) = (ECU_TPS * .4519) - 7.0
;
; These values where measured on car.  DVM on the TPS sensor.  The degrees
;  were read off the command module.  It was somewhat difficults to push the
;  throttle in with precession but values were pretty close.  What is a little
;  puzzling is that the voltage range varied so widely, between 35mv to 61mv.
;  If you take the 14 degree to 90 degree readings and divide by 76 steps
;  you get about 43mv per step with a 313mv offset to get to zero degrees...
;  Well that 313mv offset is the 7.0 that is subtracted in the equation to
;  display degrees above.
;
;     Degrees		Voltage range		 ADC
;	14		0.906 - 0.941		46-48
;	15		0.941 - 0.981		48-50
;	16		0.981 - 1.042		50-53
;	17		1.042 - 1.079		53-55
;	20		1.160 - 1.194		59-61
;	25		1.362 - 1.423		70-73
;	30		1.582 - 1.640		81-84
;	35		1.795 - 1.856		92-95
;	40		2.032 - 2.077	       104-106
;	50		2.461 - 2.500	       126-128
;	60		2.892 - 2.930	       148-150
;	70		3.323 - 3.361	       170-172
;	80		3.75  - 3.79	       192-194
;	90*		4.18  - 	       214-
;
;	* Controller won't disp more than 90 degrees
;	* Throttle was floored..........
;
; -----------------------------------------------------------------------------
; Idle Air(%) = (ECU_Idle * .78125)
;
; -----------------------------------------------------------------------------
; This is the altitude compression compensated MAP ADC stash.	At initial
;  key on the MAP ADC is read and if the atmospheric barometric pressure is low
;  enough (high altitude) and MAP ADC correction amount is computed into L0008
;  and is added to the MAP ADC values.	It is a relatively small amount ranging
;  from 0 to 6 adc counts (about one inch).  Look at the L0008 location for
;  more details as to where the breakpoints are located.  I had originaly
;  thought that the whole L0008 thing was in error because it was alwasy zero.
;  Well it is at sea level.  Above about 1500' it isn't though.  Learning some
;  of the constant's meanings from the WS dis-assembly got me thinking along the;  correct track.
;
; NOTE: The modifications to this value from the actual ADC reading is
;	done by the Calibration routine (new L83e5) where it is increased by
;	~1.56%.  L0008 is the altitude compression corections so at extended
;	elevations a small amount is added to the ADC reading.
;
L0000	equ	$0000		; slope adjusted MAP ADC reading
;
; The below table is what I measured for the MAP sensor that is in the '34
;  (11/14/98)
; The displayed VAC was obtained from the simulator............12/29/98
;
;   TAIR: 59 degrees
;
;   Vacuum    Voltage	 ADC	 L0000	    VAC
;    (in)	       (L002a)		  TAIR=59
;      0	4.55	 237	  240	   -3.2"
;      1	4.44	 231	  234	   -2.4"
;      2	4.32	 225	  228	   -4.7"
;      3	4.15	 216	  219	   -0.6"
;      4	4.00	 208	  211	    0.2"
;      5	3.82	 199	  202	    1.4"
;      6	3.65	 190	  192	    2.5"
;      7	3.463	 180	  182	    3.7"
;      8	3.302	 172	  174	    4.7"
;      9	3.141	 163	  165	    5.6"
;      10	2.953	 154	  156	    6.8"
;      11	2.809	 146	  148	    7.8"
;      12	2.632	 137	  139	    8.8"
;      13	2.415	 126	  127	   10.2"
;      14	2.263	 118	  119	   11.0"
;      15	2.136	 111	  112	   11.9"
;      16	1.954	 102	  103	   13.0"
;      17	1.783	  93	   94	   14.0"
;      18	1.607	  84	   85	   15.2"
;      19	1.437	  75	   76	   16.1"
;      20	1.238	  64	   65	   17.4"
;      21	1.061	  55	   55	   18.6"
;      22	 .874	  45	   45	   19.9"
;      23	 .695	  36	   36	   20.9"
;      24	 .510	  27	   27	   22.0"
;      25	 .316	  16	   16	   23.2"
;      26	 .134	   7	    7	   24.3"
;      27	 .024	   1	    1	   25.0"
;      28	 .024	   1	    1	   25.0"
;      29	 .024	   1	    1	   25.0"
;
; ALL BELOW IS WRONG - WRONG - WRONG !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;
; The below table is what I measured for the MAP sensor that is in the '34
;  (11/14/98)
;
; Input Voltage: 4.92	TAIR: 59 degrees    H20: 55 degrees
;
;   Vacuum     Voltage	  ADC	  L0008     L0000	VAC	    Difference
;    (in)					     (Displayed)    (34-booster)
;      0	 4.55	  237	    0	     237	0.0		+1
;      1	 4.44	  231	    0	     229	0.0		+1
;      2	 4.32	  225	    0	     225	0.0		+4
;      3	 4.15	  216	    1	     217	0.1		+4
;      4	 4.00	  208	    2	     210	0.9		+5
;      5	 3.82	  199	    3	     202	1.9		+4
;      6	 3.65	  190	    4	     194	3.0		+4
;      7	 3.463	  180	    5	     185	4.2		+2
;      8	 3.302	  172	    6	     178	5.1		+3
;      9	 3.141	  163	    6	     169	6.1		+3
;      10	 2.953	  154	    6	     160	7.3		+2
;      11	 2.809	  146	    6	     152	8.1		 0
;      12	 2.632	  137	    6	     143	9.1		+1
;      13	 2.415	  126	    6	     132       10.6		+1
;      14	 2.263	  118	    6	     124       11.5		 0
;      15	 2.136	  111	    6	     117       12.2		+2
;      16	 1.954	  102	    6	     108       13.2		+5
;      17	 1.783	   93	    6	      99       14.3		+5
;      18	 1.607	   84	    6	      90       15.3		+3
;      19	 1.437	   75	    6	      81       16.5		+5
;      20	 1.238	   64	    6	      70       17.6		+3
;      21	 1.061	   55	    6	      61       18.6		+4
;      22	  .874	   45	    6	      51       19.9		+3
;      23	  .695	   36	    6	      42       20.9		+3
;      24	  .510	   27	    6	      33       22.0		+3
;      25	  .316	   16	    6	      22       23.2		+1
;      26	  .134	    7	    6	      13       24.2		+2
;      27	  .024	    1	    6	       7       25.0		 0
;      28	  .024	    1	    6	       7       25.0		 0
;      29	  .024	    1	    6	       7       25.0		 0
;
; V_Step ~= 169.36 mv / in
; ADC_step(uncorrected) ~= 8.8 / in
;
; -----------------------------------------------
; The below table is what I measured for the MAP sensor I used on the vacuum
;  booster pump controller....
;
;   Vacuum     Voltage	  ADC	  L0008     L0000
;    (in)
;      0	 4.61	  236	    0	     236
;      1	 4.45	  228	    0	     228
;      2	 4.29	  220	    1	     221
;      3	 4.13	  211	    2	     213
;      4	 3.96	  203	    2	     205
;      5	 3.80	  195	    3	     198
;      6	 3.63	  186	    4	     190
;      7	 3.475	  178	    5	     183
;      8	 3.30	  169	    6	     175
;      9	 3.12	  160	    6	     166
;      10	 2.971	  152	    6	     158
;      11	 2.85	  146	    6	     152
;      12	 2.656	  136	    6	     142
;      13	 2.444	  125	    6	     131
;      14	 2.301	  118	    6	     124
;      15	 2.123	  109	    6	     115
;      16	 1.890	   97	    6	     103
;      17	 1.713	   88	    6	      94
;      18	 1.574	   81	    6	      87
;      19	 1.368	   70	    6	      76
;      20	 1.201	   61	    6	      67
;      21	 1.000	   51	    6	      57
;      22	  .825	   42	    6	      48
;      23	  .637	   33	    6	      39
;      24	  .460	   24	    6	      30
;      25	  .285	   15	    6	      21
;      26	  .100	    5	    6	      11
;      27	  .026	    1	    6	       7
;      28	  .026	    1	    6	       7
;      29	  .026	    1	    6	       7
;
; V_step		~= 173.4mv / in
; ADC_step(uncorrected) ~= 9 / in
; -----------------------------------------------------------------------------
L0001	equ	$0001		; flags
;				; xxxxxxx1 - Stop IAC 250ms periods (initial)
;				; xxxxxx1x - water over 60 degrees  or
;				;	     motor over 5000 RPM  (IAC flags)
;				; xxxxx1xx - computed Idle Air at max limit
;				; xxxx1xxx - computed Idle Air at min limit
;				; xxx1xxxx - TPS - Throttle plates Not closed

;				; x1xxxxxx - WOT throttle !
;				; 1xxxxxxx - Partial throttle only.  Not closed
;				;	      or WOT.


; -----------------------------------------------------------------------------
; Air = (ECU_Air * 1.2375) - 103.0
;
; Note: These adjusted numbers seem to be about 2 degrees too high for
;	 how the controller reports the Air Temperature.  I have noticed
;	 that on a cold start the Air always seems higher than the water
;	 when you would think they would have stablized to the same.....
;
L0002	equ	$0002		; TAIR - Air Temperature   (Not ADC reading)
;
;   Temp      Res     Vadc	ADC	ADC	L0002 Ajusted
;    -40    93000     4.18	214	D6	56	38
;    -20    45000     4.06	208	D0	71	47
;      0    24200     3.87	198	C6	85	55
;     20    12850     3.57	183	B7	101	65
;     40     7130     3.15	161	A1	138	8A
;     50     5736     2.97	152	98	124	7C
;     60     4182     2.69	138	8A	133	85
;     70     3207     2.44	125	7D	142	8E
;     80     2543     2.22	114	72	149	95
;     90     1957     1.98	101	65	158	9E
;    100     1577     1.79	 92	5C	165	A5
;    110     1260     1.60	 82	52	174	AE
;    120     1028     1.45	 74	4A	182	B6
;    130      814     1.29	 66	42	190	BE
;    140      666     1.18	 60	3C	199	C7
;    150      557     1.08	 55	37	207	CF
;    160      445     0.98	 50	32	215	D7
;    170      366     0.90	 46	2E	223	DF
;    180      317     0.85	 44	2C	228	E4
;    185      289     0.83	 42	2A	232	E8
;    189      260     0.80	 41	29	235	EB
;    193      248     0.78	 40	28	237	ED
;    200      230     0.76	 39	27	239	EF
;    203      206     0.74	 38	26	242	F2
;    220      162     0.69	 35	23	249	F9
;    248      106     0.63	 32	20	255	FF
;    284       64     0.58	 30	1E	255	FF
;
;	All ADC values lower than $21 are $Ff (255)
;	All ADC values higher than $DA are $00 (00)
;
; -----------------------------------------------------------------------------
; TH20 = (ECU_TH20 * 1.35) - 67.0
;
L0003	equ	$0003		; TH2O - Water Temperature (Not ADC reading)
;
;   Temp      Res     Vadc	ADC	ADC	L0003 Ajusted
;    -40    93000     4.18	214	D6	21	15
;    -20    45000     4.06	208	D0	38	26
;      0    24200     3.87	198	C6	50	32
;     20    12850     3.57	183	B7	66	42
;     40     7130     3.15	161	A1	82	52
;     50     5736     2.97	152	98	87	57
;     60     4182     2.69	138	8A	95	5F
;     70     3207     2.44	125	7D	102	66
;     80     2543     2.22	114	72	109	6D
;     90     1957     1.98	101	65	118	76
;    100     1577     1.79	 92	5C	124	7C
;    110     1260     1.60	 82	52	132	84
;    120     1028     1.45	 74	4A	139	8B
;    130      814     1.29	 66	42	147	93
;    140      666     1.18	 60	3C	154	9A
;    150      557     1.08	 55	37	162	A2
;    160      445     0.98	 50	32	169	A9
;    170      366     0.90	 46	2E	177	B1
;    180      317     0.85	 44	2C	181	B5
;    185      289     0.83	 42	2A	187	BB
;    189      260     0.80	 41	29	190	BE
;    193      248     0.78	 40	28	193	C1
;    200      230     0.76	 39	27	197	C5
;    203      206     0.74	 38	26	200	C8
;    220      162     0.69	 35	23	214	D6
;    248      106     0.63	 32	20	235	EB
;    284       64     0.58	 30	1E	246	F6
;
;	All ADC values lower than $20 are $F6 (246)
;	All ADC values higher than $DA are $00 (00)
; --------------------------------------------------------
;  Upper four bits of L0003 when used as index.
;
;   Temp	L0003
;  < -40	  00  0000 0000
;  < -40	  16  0001 0000
;    -27	  32  0010 0000
;    - 3	  48  0011 0000
;     18	  64  0100 0000
;     38	  80  0101 0000
;     61	  96  0110 0000
;     83	 112  0111 0000
;    105	 128  1000 0000
;    126	 144  1001 0000
;    148	 160  1010 0000
;    169	 176  1011 0000
;    192	 192  1100 0000
;    212	 208  1101 0000
;    233	 224  1110 0000
;    264	 240  1111 0000
;
; -----------------------------------------------------------------------------
L0004w	equ	$0004		; Fuel requirement work stash and used by IAS
L0005w	equ	$0005		; work stash
L0006w	equ	$0006		; work stash
L0007w	equ	$0007		; work stash
; -----------------------------------------------------------------------------
; This stash is an altitude compression correction factor that is applied to the
;  MAP ADC value.  The initial call to Ldc0e: at key on checks how high we are
;  and computes an altitude compression correction factor in L0008.  It looks
;  like a minimum elevation of around 1500 feet is needed before anything
;  starts happening.  At 8000' or so a maximum of about 1" of correction is
;  applied.
;
;     ADC	    Aprox
;    Entry	     MAP			L0008
;    000 - 173	  29" - 8"	  > 8000'	  6
;    174 - 183	   8" - 6.5"	  6500'-8000'	  5
;    184 - 193	 6.5" - 5"	  5000'-6500'	  4
;    194 - 203	   5" - 4"	  4000'-5000'	  3
;    204 - 213	   4" - 3"	  3000'-4000'	  2
;    214 - 223	   3" - 1.5"	  1500'-3000'	  1
;    224 - 255	 1.5" - 0"	  0000'-1500'	  0
;
L0008	equ	$0008		; MAP offset value
; -----------------------------------------------------------------------------
; Battery correction value (Adjusted ADC reading)
;
L0009	equ	$0009
; -----------------------------------------------------------------------------
; Battery = (ECU_Batt_ADC * .0625) = ADC / 16
; ADC = Battery * 16
;
L000a	equ	$000a		; BATT - Battery Voltage (in ADC counts)
;
;  Battery	ADC	(ADC-95)*1.5
;     16.0	255	     240
;     15.375	246	     226
;     15.0	240	     217
;     14.0	224	     223
;     13.0	208	     169
;     12.0	192	     145
;     11.0	176	     121
;     10.0	160	      97
;      9.0	144	      73
;      8.0	128	      49
;      7.0	112	      25
;      6.0	96	       0
;
; -----------------------------------------------------------------------------
L000bw	equ	$000b		; general usage local work stash
L000cw	equ	$000c		;  \
L000dw	equ	$000d		;   \
L000ew	equ	$000e		;    \
L000fw	equ	$000f		;     \
L0011w	equ	$0011		;      \
L0012w	equ	$0012		;	\
L0013w	equ	$0013		;	 \
; ----------------------------------------------------------------------------
L0014	equ	$0014		; This is the lowest MAP ADC reading (highest
;				;  vacuum) ever detected this session.	It is
;				;  fed by the MAP average stash L002a.
;				; It only gets set under extreme conditions,
;				;  like over 7324 rpm and extreme hi vacuum....
; ----------------------------------------------------------------------------
L0015	equ	$0015		; revolution counter for ?????
				; Only get bumped in the Dist Trigger Handler
				; Always counts down to zero.  Once it hits zero
				;  it will not roll back to 255.  Each count is
				;  one motor revolution (4 ignition events).
				; It also looks like once the motor is running
				;  this counter is never re-seeded..
;
L0016	equ	$0016		; counter for ?????
;				; Will only count to zero and stop.
;				; Only bumped by Dist Trigger handler
;
L0017	equ	$0017		; RPM (timing_period/16) vs TH20 for dashpot
;				;  threshold tests

L0018	equ	$0018		; RPM (timing_period/16) vs TH2O for potential
;				;  fuel cutoff during deceleration that starts
;				;  above this RPM.

L0019	equ	$0019		; TH2O adjusted Transient Fuel Modifier
L001a	equ	$001a		; TH2O adjusted Cold Start Fuel Modifier
L001bw	equ	$001b		; work stash
; -------------------------------
L001c	equ	$001c		; TPS closed threshold ADC value.  This value
;				; is initially set to ADC 53 but is adjusted
;				; down to where the TPS actually is by L001d.
; -----------------------------------------------------------------------------
; This stash is a running value of the lowest TPS ADC reading ever read. It
;  converges to the lowest value at a max rate of two ADC counts per itteration.
;  Lf48c sets how fast it can increase and Lf48b sets how fast it can decrease.
;  Its only purpose is to give us a real time throttle plates closed ADC value
;  to keep L001c (the stash that gets compared) updated.
;
L001d	equ	$001d		; lowest TPS ADC reading (throttle closed)
; -----------------------------------------------------------------------------
L001e	equ	$001e		; Another last ADC TPS reading.  This stash
;				;  is another last TPS ADC reading.
; -------------------------------
mis39:
L001f	equ	$001f		; Some kind of counter that never gets used
;				;  because it is seed with a zero and never can
;				;  go below zero
;--------------------------------
mis38:
L0020	equ	$0020		; Whatever this is supposed to do it actually
;				;  does nothing.  Only zero ever gets loaded
;				;  into it.
; -----------------------------------------------------------------------------
L0021	equ	$0021		; counter - .131ms tics
;				; Only increase the lowest TPS ADC stash (L001d)
;				; every 8 seconds and this is the counter.
; -----------------------------------------------------------------------------
; TPS(degrees) = (ECU_TPS * .4519) - 7.0
;
L0022	equ	$0022		; Current TPS ADC reading.  This stash is always
;				;  the last ADC reading taken.
; -----------------------------------------------------------------------------
L0023	equ	$0023		; MAT ADC reading
L0024	equ	$0024		; COOL ADC Reading
;				;
;				;   Temp      Res     Vadc	ADC
;				;    -40    93000     4.18	214
;				;    -20    45000     4.06	208
;				;      0    24200     3.87	198
;				;     20    12850     3.57	183
;				;     40     7130     3.15	161
;				;     50     5736     2.97	152
;				;     60     4182     2.69	138
;				;     70     3207     2.44	125
;				;     80     2543     2.22	114
;				;     90     1957     1.98	101
;				;    100     1577     1.79	 92
;				;    110     1260     1.60	 82
;				;    120     1028     1.45	 74
;				;    130      814     1.29	 66
;				;    140      666     1.18	 60
;				;    150      557     1.08	 55
;				;    160      445     0.98	 50
;				;    170      366     0.90	 46
;				;    180      317     0.85	 44
;				;    185      289     0.83	 42
;				;    189      260     0.80	 41
;				;    193      248     0.78	 40
;				;    200      230     0.76	 39
;				;    203      206     0.74	 38
;				;    220      162     0.69	 35
;				;    248      106     0.63	 32
;				;    284       64     0.58	 30
;
; -----------------------------------------------------------------------------
; Fuel(ms) = (ECU_Fuel * .004)
;
L0025	equ	$0025		; Injector Pulse Width	 (4us / count)	hi byte
L0026	equ	$0026		;   ......				lo byte
; ----------------------------------------------------------------------------
;
; SPK(degrees) = (ECU_Spk * .25) + 10.0
;
L0027	equ	$0027		; Spark Angle  (.25 degrees / count)
; ----------------------------------------------------------------------------

L0028	equ	$0028		; calculated optimum injector timing group
L0029	equ	$0029		; what injector phase group we are in
				; 12 - 450 degrees BTDC
				;  8 - 540 degrees BTDC
				;  4 - 630 degrees BTDC
				;  0 - 720 degrees BTDC
;
L002a	equ	$002a		; average of the last two MAP ADC readings
;
;
; The following four locations are used to store the averaged MAP ADC readings
;  per cylinder pair.  The Distributor Trigger handler stores and uses these
;  for ???????
;
L002b	equ	$002b		; averaged MAP ADC for cylinders 1,8
L002c	equ	$002c		;  4,3
L002d	equ	$002d		;   6,5
L002e	equ	$002e		;    7,2
; ------------------------------------------------------------------------------
L002f	equ	$002f		; MAP ADC stash
				; This one used in the Calibration routine and
				; the Dist Trigger handler (#8 #3 #5 #2) event.
				;
L0030	equ	$0030		; another MAP ADC reading stash
				; This one is only used in the Dist Trigger
				; handler on the #1 #4 #6 #7 firing event.
;
; This counter gets bumped each (most) time the main timer overflows.  It is
;  reset by the distributor trigger interrupt handler though...
;
L0031	equ	$0031		; Main timer overflow count (every 131ms)
;
L0032	equ	$0032		; Ign Trigger Timing Stash - timer count
;				;  timer count when trigger got there
L0034	equ	$0034		; Ign Tigger - last tic-timer count
L0036	equ	$0036		; This is the period of time when the output
;				;  from the distributor was high
L0038	equ	$0038		; Not Used ?????
L003a	equ	$003a		; accumulator used during shutter detect
; ----------------------------------------------------------------------------
; L003c and L003e and L0040 are timing periods in 8us units.
;
; L003e is the current timing period we just processed....
; L003c is the previous timing period processed...
; L0040 is the predicted next timing period...
;
;
;	Timing_Period = ECU_x * 8us  or  ECU_x / 125000
;
;	RPM = 1,875,000 / ECU_x
;
;  1,875,000 comes from....  125,000 / events_per_rev  (dist one-half engine)
;			     time 60 (Revs per minute)
;  1,875,000 = (125,000 / 4) * 60
;
L003c	equ	$003c		; Previous timing period (in 8us units).  This
;				;  one will not get reset to zero if a restart
;				;  occures
;
L003e	equ	$003e		; Current Timing period (in 8us units)
;				;  (cleared at re-start)
; -------------------------------
; If we take the current timing pulse minus the period that occured two
;  pulses back plus the last one we can predict what the next one may be.
;
;  L0040 = (t) - (t-2) + (t-1)
;
;  If the motor was decelerating and the last three pulses were: .018 .019 .020
;    then (.020) - (.018) + (.019) = .021 - predicted next timing pulse width
;
L0040	equ	$0040		; Predicted next timing period
;				;  (cleared at re-start)
; -------------------------------
;
; RPM		= (1/Pulse_Width) * 15
; Pulse_Width	= 1 / (RPM/15)
; Timing_period = Pulse_Width / .000008
; L0042 	= Timing_period / 16  =  Pulse_Width / .000128
; RPM		= ( 1/(L0042 * .000128) ) * 15
;
; What the controller has to do to display RPM......
;
; RPM = (187500 / ECU_RPM) * 10
;	From ECU	Displayed RPM
;	493E (18750)	    100
;	0EA6 (3750)	    500
;	0753 (1875)	    1000
;	0271 (625)	    3000
;	0138 (312)	    6009
;	010C (268)	    6996
;	00EA (234)	    8010
;
; It looks like the ECU is transmitting the timing period times 125,000.
; At 1000 rpm, 16.666 revs / sec, 4 firings per rev so firing at 66.666 hertz,
;   which has a period of .015 sec, so .015 * 125,000 = 1,875
; -----------------------------------------------------------------------------
; This value is the timing period divided by 16.  It has the same scale as
;  the target idle stash at L0061.  The 11,718.75 at L0061 is 187,500 / 16
;
L0042	equ	$0042	; this is the ignition timing period * 16 / 256

; -----------------------------------------------------------------------------
; This value is either the high byte of the current timing period if bit
;  xxx1xxxx of L0059 is set or a value that slowly approaches it if the
;  bit is cleared. If the bit is set we are at or above 610 RPM.
;
L0043	equ	$0043
;
;	2100	00100001    222 rpm
;	2000	00100000    229 rpm
;	1F00	00011111    236 rpm
;	1E00	00011110    244
;	1D00	00011101    253
;	1C00	00011100    262
;	1B00	00011011    271
;	1A00	00011010    282
;	1900	00011001    293
;	1800	00011000    305
;	1700	00010111    318
;	1600	00010110    333
;	1500	00010101    349
;	1400	00010100    366
;	1300	00010011    385
;	1200	00010010    407
;	1100	00010001    431 rpm
;	1000	00010000    458 rpm
;	0F00	00001111    488 rpm
;
;	1E00	244 rpm 	0D00	563 rpm
;	1D00	253 rpm 	0C00	610 rpm
;	1C00	262 rpm 	0B00	666 rpm
; -----------------------------------------------------------------------------
L0044	equ	$0044	; This stash indicates which cylinder is firing.
			; If bit 0 clear do Not fire injector this timing event.
			; The #1 shutter detector will set this value after
			;  it is sure that it got #1 shutter followed
			;  immediately by a normal duty-cycle (#8) it will
			;  then set this sequencer to 2.  This means that
			;  when L0044=2 we just hit TDC #8.
			;
			; 0000	#2
			; 0001	#1
			; 0010	#8
			; 0011	#4
			; 0100	#3
			; 0101	#6
			; 0110	#5
			; 0111	#7
; ----------------------------------------------------------------------------
L0045	equ	$0045	; looks to be the pointer to fire an injector pair
;			; 0  -	1,8
;			; 2  -	4,3
;			; 4  -	6,5
;			; 6  -	7,2
;			;
; ------------------------
; When changing the injector timing we will actually fire two sets (four
;  injectors) of injectors during one ignition trigger event.  This is done
;  to ease the transition period while changing timing.  If we just changed
;  the timing a couple of cylinder would get no fuel when they needed it.
;  The pulse widht needed during this transition is put into the the below
;  16 bit stash...
;
L0046	equ	$0046	; extra pulse width needed when changing injector
;
L0048	equ	$0048	; new injector pulse width

L004aw	equ	$004a	; works stash in Dist Trigger and IGN Amp handlers
L004bw	equ	$004b	; work stash
;
L004c	equ	$004c	; This fuel is used during the transition period when
;			; the injector timing need to change. It is derived
;			; from the regular pulse width but the MAP ADC is
;			; factored into it.  If the MAP ADC was 128 it would
;			; be the same value as what is in L0048, but as vacuum
;			; goes up (>>>29") and the ADC goes down this value
;			; increases.....
;			; Centered arround 13" then ??????
;
;------------------------------------------------------------------------------
; The two stashs below and the two counters below them, look to be used by the
;  Dist Trigger handler in calculating magnitude of change (MAP ADC changes)
;  and decay rates for transient fuel responses.  Both L004e and L004f are
;  initially seeded with a percentage of delta MAP (56% of ADC change), then
;  when the L0050 counter hits zero (12 trigger events) start reducing it
;  at a TH2O determined rate.  When the L0051 counts down (6 ignition events)
;  start reducing L004f at a constant rate (19% of its current value). These
;  two stashs are then summed together and used to determine along with
;  the user deterimined transient fuel modifier how much extra fuel is needed.
;  L0052 and L0054 are later used in these calculations.
;
L004e	equ	$004e
L004f	equ	$004f
;
L0050	equ	$0050	; L004e decay rate counter
L0051	equ	$0051	; L004f decay rate counter
;
L0052	equ	$0052	; how much and what direction we changed Pulse Width
L0054w	equ	$0054	; just a work stash for transient fuel calculations
; -----------------------------------------------------------------------------
L0056	equ	$0056	; flags
			; xxxx1xxx - Turning Slower than Idle Target RPM
			; xxxx0xxx - Turning Faster than Idle Target RPM
			; xxxxx1xx - Turning Faster than 5,500 RPM
			; xxxxx0xx - Turning Slower than 5,500 RPM
			; xxxxxx1x - Last Pulse Width was made longer or No
			;	      change last ignition event.
			; xxxxxxx1 - Throttle closed and MAP ADC is decreasing
			;	      Vacuum is increasing.

; -----------------------------------------------------------------------------
L0057	equ	$0057	; Last TPS ADC reading.  This stash is the last ADC
			;   reading taken.  It its loaded from L0022 before
			;   L0022 is updated with the new ADC reading.
; -----------------------------------------------------------------------------
L0058	equ	$0058	; flags
			; 1xxxxxxx - Hard to tell what this was supposed to do
			;	      because of mistakes.  TPS set/clr'd.
			;		 mis38: mis47:
			; x1xxxxxx - This be gets set the first time we make it
			;	      all the way thru the calibration routine.
			;	      It is cleared when then initialization
			;	      code is run.
			; xx1xxxxx - To set this bit we need to be:
			;	      RPM above fuel cutoff, throttle plates
			;	      closed and counter(L0016) = zero.
			;			- or -
			;	      Faster than 7,324 and under No Load
			;	      condition and counter(L0016) = zero.
			;			- or -
			;	      In a high speed high vacuum condition.
			;
			; xxx1xxxx - To set this bit we need to be:
			;	      Not in high speed high vacuum situation
			;		       - and -
			;	      RPM above fuel cutoff threshold and
			;	      throttle closed
			;			- or -
			;	      Faster than 7,324 rpm and under no load
			;
			;	      When this bit gets set the counter at
			;	      L0016 is seeded (6)
			;
			; xxxx1xxx - To set this bit we need to be:
			;	      Slower than dashpot rpm or partial/WOT
			;	      condition
			;		       - and -
			;	      slower than 3,662 rpm or under some Load.
			;
			; xxxxx1xx - This bit gets toggled every time we run
			;	      thru the Calibration loop.
			;	      Useless because it is never tested. mis55:
			; xxxxxx1x - Water is hot or over 3 min running.
			; xxxxxxx1 - We have a current MAP ADC reading.
			;	     This be only gets set every other Dist
			;	     trigger event.  The Calibration loop will
			;	     wait till it gets a new MAP ADC reading.
			;	     This bit holds the Calibration loop.
; -----------------------------------------------------------------------------
L0059	equ	$0059	;
			; xxxxxxx1 - Engine operating parms requested
			; xxxxxx1x - Used during IAC motor activity computaions.
			;	      Can't tell exactly what it does because
			;	      it always gets set.  Looks to be sign flag
			; xxxxx1xx - Signal 8x8 cell lookup table matrix
			; xxxxx0xx - Signal 8x16 cell matrix
			; xxxx1xxx - Signal Load (MAP) out of bounds
			; xxx1xxxx - When set timing period accumulator (L0043)
			;	      is updated directly by the hi-byte of the
			;	      current timing period.  When set we are
			;	      at or above 610 RPM.
			; xx1xxxxx - RPM is past Rev Limit set +500 rpm.
			;	      Motor is being shut down NOW !
			; x1xxxxxx - During the Fuel requirement calculations
			;	      we got an overflow.
; -----------------------------------------------------------------------------
L005a	equ	$005a	; this byte is used to determine when an injector pair
			;  is to be fired.  It is used for injector timing.
;------------------------------------------------------------------------------
L005b	equ	$005b	; flags
			; 1xxxxxxx - Gets set when we have a completed Dist
			;	      Trigger period - Not used ???
			; x1xxxxxx - A Dist Trigger interrupt has occured after
			;	      after intialiaztion.  Got the TCNT count
			;	      when this happened into L0032.
			; xx1xxxxx - Signals we drove the SA output line low
			;	      firing the Coil.
			; xxx1xxxx - The first time we get the #2-#1-#8 sequence
			;	      immediately sync the injector timing. We
			;	      the set this bit.  From that point on it
			;	      will take another confirmed sequence to
			;	      bring us into sync again.
			; xxxx1xxx - Signals firing order sequencer is in sync.
			;	      If not wait for next #2-#1-#8 sequence
			;	      to come along before bringing sequencer
			;	      into sync again.
			; xxxxx1xx - Above 4,500 RPM
			; xxxxxx1x - Signals that we have confirmed the #1
			;	      shutter.
			; xxxxxxx1 - Signals that we have confirmed a non #1
			;	      shutter.
; -----------------------------------------------------------------------------
L005c	equ	$005c	; flags
			; 1xxxxxxx - Signals dashpot is zero.  NEVER gets
			;	      cleared anywhere.  mis41:
			; x1xxxxxx - Set by timer overflow when dashpot
			;	      counter has changed But NEVER cleared
			;	      anywhere. 	mis40:
			; xx1xxxxx - Dashpot modification of idle rpm is in
			;	      operation.
			; xxx1xxxx - Throttle closed and RPM is below dashpot
			;	      trip point.  Signal to continue dashpot
			;	      till countdown or throttle opened.
			; xxxx1xxx - Set if IAS saw that motor was slowing
			;	      down.  Will only get reset when throttle
			;	      is opened again..
			; xxxxx1xx - IAS acknowledged motor slowing down. Will
			;	      only get reset when throttle plates are
			;	      opened again.
			; xxxxxx1x - Allow min IAS counter to tic
			; xxxxxxx1 - Idle activity counter in L0072 has rolled
			;	      thru zero.
; -----------------------------------------------------------------------------
L005d	equ	$005d	; flag byte
			; xxxxxxx0 - Pulse Width < $8000 (65ms)
			; xxxxxxx1 - Pulse Width > $8000
			; xxxxxx1x - Only could have been set or cleared in a
			;	      section of code that never gets executed.
			;	      See below....
			; xxxxx1xx - This bit gets set when the first valid
			;	     Dist Trigger came in.  The only place it
			;	     can get cleared is in a section of code
			;	     that never gets executed (mis21). It looked
			;	     like it could have been part of the
			;	     revolution counter stuff.
			; xxxx1xxx - Timer has Overflowed - NEVER USED
			; xxx1xxxx - EEPROM progaming in effect now
			; xx1xxxxx - EEPROM erase/prgm operation active
			; x1xxxxxx - EEPROM erase/prgm timer active
; -----------------------------------------------------------------------------
L005e	equ	$005e	; Mixture flag (LED control)
			; 0xxxxxxx - Open Loop conditions
			; 1xxxxxxx - Closed Loop operations
			; x1xxxxxx - Only One LED is on
			; x0xxxxxx - Both LED's are On or Off
			; xx1xxxxx - Water Temp under 120 degrees
			; xx0xxxxx - Water Temp over 120/140 degrees
			; xxx1xxxx - Air Temp Above 248 degrees
			; xxx0xxxx - Air Temp below 248 degrees
			; xxxx0xxx - Red LED On (lean)
			; xxxx1xxx - Green LED On (rich)
			; xxxxx1xx - Dist Trigger handler knows mixture is Rich.
			; xxxxx0xx - Dist Trigger handler knows mixture is Lean.
			; xxxxxxx1 - Outside RPM range for closed loop operation
			; xxxxxxx0 - Inside closed loop RPM range
; -----------------------------------------------------------------------------
L005f	equ	$005f	; flags - All of these bits (except bit 7) gets cleared
			;	  every (most?) the Calibration routine runs
			;	  thru.  They also get set there.
			; 1xxxxxxx - To get this set the motor had to be turning
			;	      faster than 7,324 rpm and with highest
			;	      vacuum (>>>29") we have ever seen before.
			;	      Like we were really screaming and let off
			;	      the gas !
			;	     This is the only bit that gets set by
			;	      another routine (Dist Trig) than the
			;	      Calibration loop.
			; x1xxxxxx - RPM above TH2O set trip RPM.  If
			;	      deceleration starts above this RPM the
			;	      fuel is shut off.
			; xx1xxxxx - Slower than TH2O set dashpot RPM
			; xxx1xxxx - Motor turning faster than 7,324 rpm
			; xxxx1xxx - Slower than 3,662 rpm
			; xxxxx1xx - We are under some Load
			; xxxxxx1x - We are under no/light Load
			; xxxxxxx1 - In high speed high vacuum condition.
			;	      This bit gets set by the Calibration loop
			;	      when the 1xxxxxxx bit is set.
; -----------------------------------------------------------------------------
L0060		equ	$60	; Fuel pump and PAL-44 (and what else) control
;				; x1xxxxxx - turn on PAL-44
;				; xx1xxxxx - turn on Fuel Pump	PAL-43
;
; -----------------------------------------------------------------------------
; Target Idle RPM = (11,718.75 / ECU_Target) * 10.0
; Note: Look at L0042 for scaling information...
;	Remember, Bigger number lower rpm
;
L0061	equ	$0061		; Target Idle RPM
;
;  0		    52	  2254	   104	  1127	   156	   751	   208	   563
;  1	117188	    53	  2211	   105	  1116	   157	   746	   209	   561
;  2	 58594	    54	  2170	   106	  1106	   158	   742	   210	   558
;  3	 39063	    55	  2131	   107	  1095	   159	   737	   211	   555
;  4	 29297	    56	  2093	   108	  1085	   160	   732	   212	   553
;  5	 23438	    57	  2056	   109	  1075	   161	   728	   213	   550
;  6	 19531	    58	  2020	   110	  1065	   162	   723	   214	   548
;  7	 16741	    59	  1986	   111	  1056	   163	   719	   215	   545
;  8	 14648	    60	  1953	   112	  1046	   164	   715	   216	   543
;  9	 13021	    61	  1921	   113	  1037	   165	   710	   217	   540
;  10	 11719	    62	  1890	   114	  1028	   166	   706	   218	   538
;  11	 10653	    63	  1860	   115	  1019	   167	   702	   219	   535
;  12	  9766	    64	  1831	   116	  1010	   168	   698	   220	   533
;  13	  9014	    65	  1803	   117	  1002	   169	   693	   221	   530
;  14	  8371	    66	  1776	   118	   993	   170	   689	   222	   528
;  15	  7813	    67	  1749	   119	   985	   171	   685	   223	   526
;  16	  7324	    68	  1723	   120	   977	   172	   681	   224	   523
;  17	  6893	    69	  1698	   121	   968	   173	   677	   225	   521
;  18	  6510	    70	  1674	   122	   961	   174	   673	   226	   519
;  19	  6168	    71	  1651	   123	   953	   175	   670	   227	   516
;  20	  5859	    72	  1628	   124	   945	   176	   666	   228	   514
;  21	  5580	    73	  1605	   125	   938	   177	   662	   229	   512
;  22	  5327	    74	  1584	   126	   930	   178	   658	   230	   510
;  23	  5095	    75	  1563	   127	   923	   179	   655	   231	   507
;  24	  4883	    76	  1542	   128	   916	   180	   651	   232	   505
;  25	  4688	    77	  1522	   129	   908	   181	   647	   233	   503
;  26	  4507	    78	  1502	   130	   901	   182	   644	   234	   501
;  27	  4340	    79	  1483	   131	   895	   183	   640	   235	   499
;  28	  4185	    80	  1465	   132	   888	   184	   637	   236	   497
;  29	  4041	    81	  1447	   133	   881	   185	   633	   237	   494
;  30	  3906	    82	  1429	   134	   875	   186	   630	   238	   492
;  31	  3780	    83	  1412	   135	   868	   187	   627	   239	   490
;  32	  3662	    84	  1395	   136	   862	   188	   623	   240	   488
;  33	  3551	    85	  1379	   137	   855	   189	   620	   241	   486
;  34	  3447	    86	  1363	   138	   849	   190	   617	   242	   484
;  35	  3348	    87	  1347	   139	   843	   191	   614	   243	   482
;  36	  3255	    88	  1332	   140	   837	   192	   610	   244	   480
;  37	  3167	    89	  1317	   141	   831	   193	   607	   245	   478
;  38	  3084	    90	  1302	   142	   825	   194	   604	   246	   476
;  39	  3005	    91	  1288	   143	   819	   195	   601	   247	   474
;  40	  2930	    92	  1274	   144	   814	   196	   598	   248	   473
;  41	  2858	    93	  1260	   145	   808	   197	   595	   249	   471
;  42	  2790	    94	  1247	   146	   803	   198	   592	   250	   469
;  43	  2725	    95	  1234	   147	   797	   199	   589	   251	   467
;  44	  2663	    96	  1221	   148	   792	   200	   586	   252	   465
;  45	  2604	    97	  1208	   149	   786	   201	   583	   253	   463
;  46	  2548	    98	  1196	   150	   781	   202	   580	   254	   461
;  47	  2493	    99	  1184	   151	   776	   203	   577	   255	   460
;  48	  2441	   100	  1172	   152	   771	   204	   574
;  49	  2392	   101	  1160	   153	   766	   205	   572
;  50	  2344	   102	  1149	   154	   761	   206	   569
;  51	  2298	   103	  1138	   155	   756	   207	   566
;
; -----------------------------------------------------------------------------
L0062	equ	$0062		; an accumulator used in IAS calculations
L0064	equ	$0064		; always zero because of mis14a:
; -----------------------------------------------------------------------------
; All of these values are in 1Mhz (1us) units.	They are divided by 2 in the
;  IAC motor interrupt handler before being added to the timer's counter
;  register which is being updated at the tic-count rate of 500 KHz (2us).
;  A number like 6666 is .006666 seconds, 6.666ms
;
L0066	equ	$0066		; New IAC motor On time
L0068	equ	$0068		; New IAC total period
L006a	equ	$006a		; last IAC motor On time.
L006c	equ	$006c		; last IAC total period stash
; -----------------------------------------------------------------------------
L006e	equ	$006e		; This is the electronic dashpot counter
;				; Other than seeding and clearing, the only
;				; place it is bumped is by the timer overflow
;				; handler (at a max 131ms rate).
L0070	equ	$0070		; last min IAS% requirement
L0071	equ	$0071		; min IAS% required for a particular rpm
L0072	equ	$0072		; up counter used in idle activity.  Max rate
;				;  of change is 131ms from timer overflow.
L0073	equ	$0073		; counter that never gets used !!!!! mis44:
L0074	equ	$0074		; O2 Sensor ADC reading
L0075	equ	$0075		; How much to change the injectors pulse width
				;  during closed loop operation.
; -----------------------------------------------------------------------------
; this timer is usless because when true the number that gets multiplied by 16
;  is then it is divided by 16 ????	mis26:
L0076	equ	$0076		; when counts down zero would have allowed
;				;  the closed loop rate of change value to be
;				;  further adjusted.	(X*16)/16

; -----------------------------------------------------------------------------
; This counter is used to determine if we have an O2 sensor error.  If both
;  LED are on for more than 255 iterations and we have been running more than
;  one minute and closed loop fuel is on then signal an error...
;
L0077	equ	$0077		; O2 sensor error counter
; -----------------------------------------------------------------------------
L0078	equ	$0078		; delay counter before Closed Loop is activate
;
L0079	equ	$0079		; This value is a scaled accumulated amount that
;				;  is added/subtracted from the injectors PW. It
;				;  accumulates how much the mixture needs to
;				;  change.  This value is limited to +-16,000
;				;  A negative value will increase the Fuel PW.
;
L007b	equ	$007b		; As long as this counter is Not zero a new rate
;				;  of change value is calculated.  Every time
;				;  we get a rich/lean state change it goes to
;				;  zero
;
L007c	equ	$007c		; Warmup timer. If the water is below 120 deg
;				;  at startup this timer starts counting.
;				;  It is used in determining when we can go
;				;  closed loop and believe the O2 sensor.
;				;  When the water then gets over 140 degrees
;				;  it is pushed to the max count ($ffff).
;				;  Set only in the timer overflow handler.
;				;  Note: Once this counter hits $ffff it will
;				;	 stay there forever.
;				;
L007e	equ	$007e		; How much time to add or subtract from the
;				;  injector pulse width to lean/richen the
;				;  mixture.  It is returned from the Calibration
;				;  routine and is added/subtracted from the
;				;  PW during each ignition event.
;
; -----------------------------------------------------------------------------
L007f	equ	$007f		; Commands to Save and Restore Datasets here
;
; If Second Byte = 06 then
;	10010001  91 - Save dataset 'A'
;	10010010  92 - Save dataset 'B'
;	10010011  93 - Save dataset 'C'
;	10100000  A0 - Restore Base dataset
;	10100001  A1 - Restore 'A' dataset
;	10100010  A2 - Restore 'B' dataset
;	10100011  A3 - Restore 'C' dataset
;
; If Second byte = 05 then	; return success(zr) or fail code(nz)
;	10010001  91 - Saving dataset 'A' ?
;	10010010  92 - Saving dataset 'B' ?
;	10010011  93 - Saving dataset 'C' ?
;	10100000  A0 - Restoring Base dataset ?
;	10100001  A1 - Restoring 'A' dataset ?
;	10100010  A2 - Restoring 'B' dataset ?
;	10100011  A3 - Restoring 'C' dataset ?
;
; If an error occured this location gets set to the following.	This is what
;   goes back to the controller signaling success or failure.....
;
;	01000000  40 - Checksum or command structure error occured
;			Operation not completed.
;	00000000  00 - Save / Restore operation completed to Success
;
; ----------------------------------------------------------------------------
; The current modifier table is stored here.  Normally the Dataset 'A' at
;  EEPROM $b600 is loaded.  If it is bad then load from ROM at $f740 into
;  this location.  Dataset 'B' and 'C' can also be loaded into this list.
;
; All the values between $0080 thru $0097 are the Fuel Modifiers.  Each is
;  adjustable between +50% and -30%   That means their range is from 90 to
;  192.  The scaling factor of .78125 comes from (Max_Percentage / 64).
;
; NOTE: This address must stay the same (or atleast be on a boundry) to
;	 allow the EEPROM programing to work correctly....
;
L0080	equ	$0080		; - Fuel @ WOT @ 1000 RPM
L0081	equ	$0081		; - Fuel @ WOT @ 2000 RPM
L0082	equ	$0082		; - Fuel @ WOT @ 3000 RPM
L0083	equ	$0083		; - Fuel @ WOT @ 4000 RPM
L0084	equ	$0084		; - Fuel @ WOT @ 5000 RPM
L0085	equ	$0085		; - Fuel @ WOT @ 7000 RPM
;				;
L0086	equ	$0086		; - Fuel @ 06" @ 1000 RPM
L0087	equ	$0087		; - Fuel @ 06" @ 2000 RPM
L0088	equ	$0088		; - Fuel @ 06" @ 3000 RPM
L0089	equ	$0089		; - Fuel @ 06" @ 4000 RPM
L008a	equ	$008A		; - Fuel @ 06" @ 5000 RPM
L008b	equ	$008B		; - Fuel @ 06" @ 7000 RPM
;				;
L008c	equ	$008C		; - Fuel @ 12" @ 1000 RPM
L008d	equ	$008D		; - Fuel @ 12" @ 2000 RPM
L008e	equ	$008E		; - Fuel @ 12" @ 3000 RPM
L008f	equ	$008F		; - Fuel @ 12" @ 4000 RPM
L0090	equ	$0090		; - Fuel @ 12" @ 5000 RPM
L0091	equ	$0091		; - Fuel @ 12" @ 7000 RPM
;				;
L0092	equ	$0092		; - Fuel @ 18" @ 1000 RPM
L0093	equ	$0093		; - Fuel @ 18" @ 2000 RPM
L0094	equ	$0094		; - Fuel @ 18" @ 3000 RPM
L0095	equ	$0095		; - Fuel @ 18" @ 4000 RPM
L0096	equ	$0096		; - Fuel @ 18" @ 5000 RPM
L0097	equ	$0097		; - Fuel @ 18" @ 7000 RPM
;
; The following are the Spark Modifiers.  They occupy the ram space between
;  $0098 and $00AE.  All Spark modifiers are +8 degrees / -16 degrees.
;  Each value is weighted by .25 degrees.  The controller changes them with
;  a stepsize of 4 counts which represents 1 degree change.  A count of 128
;  equals a zero degree modifier.  160 = +8 degrees   64 = -16 degrees
;
L0098	equ	$0098		; - Sprk @ WOT @ 1000 RPM
L0099	equ	$0099		; - Sprk @ WOT @ 1750 RPM
L009A	equ	$009A		; - Sprk @ WOT @ 2500 RPM
L009B	equ	$009B		; - Sprk @ WOT @ 3500 RPM
L009C	equ	$009C		; - Sprk @ WOT @ 4500 RPM
L009D	equ	$009D		; - Sprk @ WOT @ 6000 RPM
L009E	equ	$009E		; - Sprk @ 09" @ 1000 RPM
L009F	equ	$009F		; - Sprk @ 09" @ 1750 RPM
L00A0	equ	$00A0		; - Sprk @ 09" @ 2500 RPM
L00A1	equ	$00A1		; - Sprk @ 09" @ 3500 RPM
L00A2	equ	$00A2		; - Sprk @ 09" @ 4500 RPM
L00A3	equ	$00A3		; - Sprk @ 09" @ 6000 RPM
L00A4	equ	$00A4		; - Sprk @ 18" @ 1000 RPM
L00A5	equ	$00A5		; - Sprk @ 18" @ 1750 RPM
L00A6	equ	$00A6		; - Sprk @ 18" @ 2500 RPM
L00A7	equ	$00A7		; - Sprk @ 18" @ 3500 RPM
L00A8	equ	$00A8		; - Sprk @ 18" @ 4500 RPM
L00A9	equ	$00A9		; - Sprk @ 18" @ 6000 RPM
;				;
L00aa	equ	$00aa		; Global Fuel Modifier	(xx-128)*.78125
;				;  This value can range from 90 to 192 which
;				;   represents -30% to +50%  The scaling factor
;				;   comes from 50/64 = .78125
;				;
L00ab	equ	$00ab		; Idle Fuel Modifier  (xx-128)*.78125  +-50%
;				;  This value can range from 64 to 192 which
;				;   represents +-50%   The scaling factor
;				;   comes from 50/64=.78125
;				;
L00ac	equ	$00ac		; Cold Start Fuel	(xx-128)*.78125
;				;  This value can range from 90 to 192 which
;				;   represents -30% to +50%  The scaling factor
;				;   comes from 50/64 = .78125
;				;
L00ad	equ	$00ad		; Transient Fuel	(xx-128)*.78125
;				;  This value can range from 90 to 192 which
;				;   represents -30% to +50%  The scaling factor
;				;   comes from 50/64 = .78125
;				;
L00ae	equ	$00ae		; Global Spark Modifier   +8 / -16 degrees
;				;  Each count is .25 degrees. 160 = +8 degrees
;				;  64 = -16 degrees
;				;
L00af	equ	$00af		; Idle Sprk modifier (xx-128)*.25=percentage
;				;  Each percenatge of change is 4 counts
;				;   centered arround 128.  So the max 16% = 192
;				;   The min (-16%) equals 64...
;				;
L00b0	equ	$00b0		; Target Idle RPM modifier - stepsize = 25 rpm
;				;  Each value weight is 25 rpm.  The ROM default
;				;  is 134.  This value is 128 biased.  Each
;				;  count is a +-25 rpm modification of the
;				;  current idle rpm in L0061.
;				;
L00b1	equ	$00b1		; Idle Speed Activity  (xx-128) * .78125
;				;  This value can range from 64 to 192 which
;				;   represents +-50%.	The scaling factor
;				;   comes from 50/64=.78125
;				;
L00b2	equ	$00b2		; Rev Limiter RPM - stepsize = 250 rpm
;				;  This value times 250 equals the Rev Limit.
;				;  Min=20 (5000rpm)  max=38 (9500rpm)
;				;
L00b3	equ	$00b3		; control flags
;				;  1xxxxxxx - Base Timing Set: On
;				;  0xxxxxxx - Base Timing Set: Off
;				;  x1xxxxxx - Closed Loop Fuel: Off
;				;  x0xxxxxx - Closed Loop Fuel: On
;				;  xx1xxxxx - Idle Control: Off
;				;  xx0xxxxx - Idle Control: On
L00b4	equ	$00b4		; ???? - not modifed by controller - Spare ?
L00b5	equ	$00b5		; ...... always seens to be zero - Spares ??
; -----------------------------------------------------------------------------
L00b6	equ	$00b6		; This byte is used to point to the start of
;				;  the correct EEPROM row/byte that is being
;				;  erased or written to.
; -----------------------------------------------------------------------------
L00b7	equ	$00b7		; This value is the current timing period
;				;  converted into RPM/25
;------------------------------------------------------------------------------
L00b8	equ	$00b8		; current MAP ADC reading
; -----------------------------------------------------------------------------
L00b9	equ	$00b9		; Warning message flags
;				; 1xxxxxxx - MAP Sensor Error
;				; x1xxxxxx - H20 Temperature Error
;				; xx1xxxxx - Voltage Hi/Low
;				; xxx1xxxx - Throttle Input Error
;				; xxxx1xxx - AIR Temp. error
;				; xxxxx1xx - O2 Sensor error
; -----------------------------------------------------------------------------
L00ba	equ	$00ba		; flags - Most never tested !!!!!!!!
; cleared 01/02/99		; 1xxxxxxx - never set here !  one test
;				; x1xxxxxx - H20 Temperature Error
;
; cleared 01/01/99		; xxx1xxxx - MAP above 21"  - never tested
; cleared 01/01/99		; xxxx1xxx - TPS -	    - never tested
; cleared 01/01/99		; xxxxx1xx -		    - never tested
; cleared 01/01/99		; xxxxxx1x -		    - never tested
; -----------------------------------------------------------------------------
L00bb	equ	$00bb		; flags - NEVER USED ANYWHERE !!!!!!!!!
;				; xxxxxx1x - MAT out of range too Hot
;				; xxxxxx0x - MAT out of range too Cold
;				; xxxxx1xx - H20 out of range too Hot
;				; xxxxx0xx - H20 out of range too Cold
;				; xxxx1xxx - TPS out of range too low
;				; xxxx0xxx - TPS out of range too high
;				; 1xxxxxxx - MAP voltage too Low
;				; 0xxxxxxx - MAP voltage too High
;
; -----------------------------------------------------------------------------
; These locations are used by the Serial handler routines and communication
;  with the remote controller...
;
L00bc	equ	$00bc		; Serial flags
				; 1xxxxxxx - If this bit stays high more than
				;	     131ms (one timer overflow period)
				;	     the overflow routine will clr L00bc
				; x1xxxxxx - first byte (7B) received
				; xx1xxxxx - data set/requested      (2nd=06/05)
				; xxx1xxxx - have a completed request
				; xxxx1xxx - need to transmitt data to controler
				; xxxxx00x - can't find where set but are tested
				; xxxxx001 - allow engine status data to be
				;	      sent to the controller.
;				; ---------------------------------------------
L00bd	equ	$00bd		; number of bytes sent/received
L00be	equ	$00be		; index into the Serial Buffer
L00c0	equ	$00c0		; start of Serial work buffer
L00c1	equ	$00c1		; number of characters sent/received location
L00c2	equ	$00c2		; either adddress or data start
; -----------------------------------------------------------------------------
L00fb	equ	$00fb		; This location has some testmode only meaning
;				; It has something to do with the Ignition Coil
;				;  driver mode.  What it could do sitting in
;				;  the middle of the stack makes no sense.
; =============================================================================
;
timer_tcnt_reg	equ	$100e	; TCNT - Timer Count
toc1_data_reg	equ	$1016	; OC1 data register			IAC
toc2_data_reg	equ	$1018	; TOC2 - Timer Output Compare 2 data register
toc4_data_reg	equ	$101c	; TOC4 - IGN Amp data register		OC4
L1020	equ	$1020		; Timer Control register 1
baud_register	equ	$102b	; BAUD - Baud Rate prescaler register
sccr1_register	equ	$102c	; SCI Control register
scsr_register	equ	$102e	; Serial SCI Status Register
scdr_register	equ	$102f	; Serial SCI Data Register
adc_control_reg equ	$1030	; ADC Control/Status Register
adc_result_adr1 equ	$1031	; ADR1 ADC result register
adc_result_adr3 equ	$1033	; ADR3 ADC result register
adc_result_adr4 equ	$1034	; ADR4 ADC result register
;
; The whole COP thing is usless because of mis69: !!!!!!!!!!!!!!!!!!!!!!!!!!
;
coprst_register equ	$103a	; COPRST - COP arm/reset register
;				;  Write $55 to this register to arm the COP
;				;  timer, then immediately write $AA to it
;				;  to clear the timer.	If this sequnce isn't
;				;  performed within the specified timer rate
;				;  period a system reset will occure.
;
cop_arm 	equ	$55	; to arm COP
cop_reset	equ	$AA	; to reset the COP
;
; -----------------------------------------------------------------------------
; This seven section invertor (L9112D) is a strange part.  All of its inputs
;  seem to have a 4.7k resistor to ground, so with nothing pulling it up
;  that sections output will be high. One section (pins 3,4) is used to drive
;  INJ-D from the 68HC11's internall timer, and another section is the serial
;  interface reciever.	All the others, with the exception of the one that seems
;  to be monitoring the IAC motor driver transistor collector (pins 1,2), have
;  some connection to the outside world thru J1.  Some are pulled up and some
;  pulled down either internally and/or externally.  The below displayed bits
;  are the defualt conditions observed.
;
; The only bit that is tested in this code is 00000100.  It is tested several
;  places.  Noting is connected to J1-21 so it is always high.
;
; 08/29/99 - Found what J1-21 purpose is.  It is an input that is connected to
;	     the AC to detect if it is on.  If the ECU senses that an AC is on
;	     there is another 6.6% added to the IAC motor duty cycle to keep the;	     the RPM up.
;
L6000	equ	$6000		; The PAL loacation reads information from
				;  the L9112D invertor
				; xxxxxxx1 - PAL-1  L9912-15 - J1-14
				; xxxxxx0x - PAL-2  L9112-7 - J1-13
				; xxxxx1xx - PAL-3  L9112-12 - J1-21 - AC Sense
				; xxxx1xxx - PAL-4  L9112-2 - IAC motor
				; xxx1xxxx - PAL-5  L9112-6 - J1-16
				;
;				;
; =============================================================================
; This is the start of the ROM.........................
;
	org	$8000
;
L8000:	fcc	"Q1.3(c)WEBER'93f"	; our signature
;
; This is the main entry point.  Most all interupt vectors point to here
;  along with the RESET vector.
;
L8010	lds	#ram_base+$ff	; set the stack to top of ram
	sei			; set interrupt mask - mask all maskable intrpt
	ldx	#register_base	; point to the register block
	bset	$39,X %10101001 ; Setup the Option Regusrer		1039
;				; 1xxxxxxx - Power up the ADC
;				; xx1xxxxx - Set IRQ to edge-sensitive operation
;				; xxxx1xxx - Clock Monitor Enabled
;				; xxxxxxx1 - Setup up COP timer to timeout....
	bclr	$39,X %00000010 ;	     .... in 65.5 ms
	bset	$24,X %00000001 ; Set the Timer Prescaler to /4
	bclr	$35,X %00001111 ; Unprotect all of EEPROM (now it is writeable)
	bclr	$3c,X %00001111 ; Setup to promote the Timer Input Capture 1...
	bset	$3c,X %00001000 ; ... interrupt to highest priority
	bset	$08,X %00000010 ; set PD1 (pin 21) TxD serial output high
	bset	$09,X %00000110 ; set PD1(TxD) and PD2(???) as outputs
	bclr	$00,X %11000000 ; IAC and INJ-D Off
	bclr	$08,X %00000100 ; set PD2 high
	bset	$26,X %10000000 ; configure PA7 (IAC) as an Output
	bset	$0d,X %10000000 ; Output Compare 1 data (hi) to OC1 pin 27 - IAC
;
; Setup the external MC6840 Timer.....
;
	ldaa	#%00100000	; xxxxxxx0 - Control Register #3 may be written
;				; xxxxxx0x - Use External Clock Source
;				; xxxxx0xx - Use Normal 16 bit Counting Mode
;				; xx100xxx - Single Shot Mode
;				; x0xxxxxx - Mask IRQ
;				; 0xxxxxxx - Outputs Disabled (Low)
;				;
	staa	timer_cntr_reg2 ; setup timer #2
;				;
				; With Bit 0 set to 0 the External clock
				; is not prescaled (set in Cntl Reg #3)
	staa	timer_cntr_regx ; setup timer #3
	inca			; set bit 0 to select Control Register #1
	staa	timer_cntr_reg2 ; do it
	deca			;
;				; Bit0 = 0 so all timers are allowed to operate
	staa	timer_cntr_regx ; setup timer #1
	ldd	#$0028		; set pulse width to 160us
	staa	timer_1_msb	; hi byte
	stab	timer_1_lsb	;  low
	staa	timer_2_msb	; timer #2 next
	stab	timer_2_lsb
	staa	timer_3_msb
	stab	timer_3_lsb
;
	ldaa	#%11111111
	staa	$23,X		; clear Timer Interrupt Flag Register 1
	staa	$25,X		; and Timer Interrupt Flag 2
	bclr	$0c,X %11111111 ; clear output compare mask
	bset	$0c,X %10000000 ; enable OC1 (pin 27) IAC driver
	bset	$20,X %00001000 ; OC4 line to zero after Successful Compare
	ldd	timer_tcnt_reg	; read the timer
	addd	#$0014		; plus 40 us (20 * 2 us)
	std	toc2_data_reg	; stash in TOC2 output compare register
	ldaa	$3c,X		; get interrupt priority value
	anda	#%01100000	; mask out SMOD and MDA bits
	cmpa	#%00100000	; are in Expanded mode now ?
L807e:	bne	L807e		; no - some kind of test mode then ???
	ldx	#ram_base+$ff	; point to the top of system RAM
	clra			; lets preset it all to 0
L8084:	staa	$00,X
	dex			; move down ward
	bne	L8084		; more to do
	ldaa	#cop_arm	; reset the COP watchdog timer
	staa	coprst_register
	ldaa	#cop_reset
	staa	coprst_register
	ldx	#eeprom_base	 ; point to start of EEPROM
	ldy	#eeprom_base+$3f ; scan to checksum
	clrb			; clear result stash
	jsr	Ldc78		; compute checksum byte
	cmpb	$00,Y		; does it checksum ?
	beq	L80a9		; yes
	ldy	#Lf740		; nope - get from ROM
	bra	L80ad
;
; Move Data Set 'A' from EEPROM into ram....
;
L80a9:	ldy	#$b600		; good checksum so get from EEPROM
;
L80ad:	ldx	#L0080		; put here
L80b0:	ldaa	$00,Y		; get a byte from the source (EEPROM/ROM)
	staa	$00,X		; stash into memory
	iny			; bump pointers
	inx
	cpx	#$00b6		; end of table yet ?
	bcs	L80b0		; nope
	jsr	Ldc87		; setup the serial interface
;
; The below has something to do with the Ignition Coil Driver Mode.  It compares
;  a constant to some location in RAM right in the middle of the stack.
;  Needles to say it does not work.
;
	if	not mis57x
	ldaa	Lf01d		; Ignition Coil Driver Mode
	anda	L00fb		; no matter what this is we will always endup 0
	beq	L80ca		; ok - has to be
	jmp	L807e		; error - jump to drop dead loop
	endif
;
L80ca:	ldaa	Lf690		; do we need to turn on alt IAC motor driver ?
				; Boost Control Driver - 09/01/99	(WS)
	bne	L80d7		; nope
	ldy	#register_base
	bset	$00,Y %00001000 ; turn on PA3 - alt IAC motor driver
L80d7:	bset	L0060 %01000000 ; turn on PAL-44
	bclr	L0060 %00100000 ; assure the Fuel Pump is Off
	ldaa	L0060
	staa	pal_4000_latch
;
	ldd	Lf47c		; seed the dashpot counter 4.6 seconds	7000
	std	L006e		; seed the dashpot
	ldaa	Lf48e		; Counter value for Idle Threshold Update
				; 8 second counter	64*131ms - 8.3sec
	staa	L0021		; reset counter
	ldd	#%00000111	; Single Scan, Single Channel, AN7 (MAP)
	stab	adc_control_reg
	ldab	#$06		; wait a bit
L80f4:	decb
	bne	L80f4
	nop
	ldaa	adc_result_adr1 ; get the results (MAP)
	staa	L00b8		; stash new current MAP ADC
;
; Check the key-on MAP value for a high altitude condition.  If we are at a
;  high altitude location at engine start then compute an altitude compression
;  compensation value into L0008.
;
	jsr	Ldc0e		; compute MAP ADC altitude compression value
				;  ...and stash in L0008
;
; ..............................................................................
;
	ldaa	L00b8		; get MAP back and....
	staa	L002f		; ...stash here also
	bset	L0060 %00100000 ; turn On the Fuel Pump
	ldaa	L0060
	staa	pal_4000_latch
	ldx	#register_base
	ldaa	#cop_arm	; reset the COP watchdog timer
	staa	$3a,X
	ldaa	#cop_reset
	staa	$3a,X
	bclr	$23,X %00000000 ; clear all timer interrupt flags
	bclr	$23,X %01111111 ; clear OC1F timer interrupt flag
	bset	$0c,X %10000000 ; Point OC1 Output to PA7 (pin 27) - IAC
	bset	$0d,X %10000000 ; set IAC Output Compare data to 1 after compare
	ldd	$0e,X		; get the current timer count
	addd	#$0019		; plus 50 us (25 * 2us)
	std	$16,X		; stash in TOC1 (Output Compare reg 1)
;
; -----------------------------------------------------------------------------
;
; Re-enter here if motor off or ........
;   If Dist Trigger Handle (IC1) couldn't determine which trigger edge
;   If Timer Overflow sent us here after Fuel Pump was turned off (motor off)
;   780ms with no activity
;
L812a:	ldx	#register_base
	ldaa	#%00010000	; setup IC1 to detect rising edge only
	staa	$21,X		;
	bset	$22,X %10000100 ; enable OC1 (IAC) and IC1 (Ign Trig) interrupts
	bclr	$25,X %01111111 ; clear the Timer Overflow Flag (TOF)
	bset	$24,X %10000000 ; enable Timer Overflow interrupt
	ldaa	#cop_arm	; reset the watchdog timer
	staa	$3a,X
	ldaa	#cop_reset
	staa	$3a,X
	clra
	clrb
	staa	L0029		; clear injector phase group
	staa	L0027		; clear Spark Angle
	std	L0058		; clear flags
	staa	L005b		; clear IGN and SA flags
	std	L003e		; clear current timing period
	std	L0040		; clear the predicted next timing period
	std	L0036		; clear dist trig high time period
;
	if	not mis4x
mis4:	std	L0038		; Not Used ??????
	endif
;
	std	L003a		; clear #1 cylinder firing stash
	staa	L0031		; clear timer overflow counter
;
	if	not mis5x
mis5:	std	L003e		; clear current timing_period - AGAIN ????
	endif
;
	staa	L0042		; clear timing_period / 16 stash
	std	L0004w		; clear Fuel work stash - why ????????
	std	L0025		; Injector Pulse Width to zero
	brclr	L005d %00000100 L817e ; first time here before a distributor
				;	    trigger pulse has occured
	ldaa	L1020		; get current Timer Control 1 register value
	oraa	#%00001000
	anda	#%11111011	; OC4 line to zero after Successful Compare
	if	not mis57x
	eora	Lf01d		; xor flag - Ign Coil Driver Mode
	endif
	staa	L1020		; update Timer Control 1
	ldd	L003c		; get previous timing period
	beq	L817e		; motor stopped
	cpd	#$01a1		; below 4500 RPM ?
	bhi	L817e		; yes
	bset	L005b %00000100 ; signal above 4,500 RPM
L817e:
	if	not mis8x
mis8:	bclr	L00ba %00000110 ; clear what - Never used Anywhere
	endif
;
	cli			; enable interrupts now
L8182:	brclr	L005b %01000000 L8189 ; a Dist Trigger intr has not happened yet
	jmp	L82d6		; We got a Dist Trigger interrupt
;
L8189:	ldx	#register_base
	sei			; interrupts off
	brclr	$30,X %00000100 L81f6 ; branch if AN0 thru AN3 was read last
	ldab	#%00010000	; turn MULTI mode on (read AN0 thru AN3)
	stab	adc_control_reg
	ldaa	#cop_arm	; reset the watch dog timer
	staa	$3a,X
	ldaa	#cop_reset
	staa	$3a,X
L819e:	brclr	$30,X %10000000 L819e ; loop here till ADC is finished
	ldd	adc_result_adr3 ; read ADC -->	A = AN2(MAT)	B = AN3(COOL)
	std	L0023		; stash MAT and COOL ADC readings
	cli			; interrupts back on
	ldx	#Lf268		; point to adjustment table
	tba			; a copy into A
	anda	#%11110000	; leave only upper four bits
;
; If the coolant temperature circuit was open the highest ADC (lowest temp)
;  reading possible would be 4.3 volts - ADC=220 $E0
;
	cmpa	#$e0		; warmer than 224 ?
	bcs	L81b5		; yes - circuit probably not bad (open)
	clra			; goto max Hot
	bra	L81d8
;
L81b5:	cmpa	#$30		; warmer than about 160 degrees ?
	bcs	L81c6		; yes
;---------------------------------------------
; TEXPNDH
; EXPANDED TEMPERATURE TABLE
; FOR FORD TEMP SENSORS
;  ENTRIES IN THIS TABLE EXPAND TABH2O
;   H ABOVE FROM 208 to 233d A/D
;
;---------------------------------------------
	cmpa	#$d0		; between -40 to -20 degrees or so ?
	bne	L81ce		; nope
	ldx	#Lf278		; point to Ford Expanded Table
	lslb			; * 2
	lslb
	lslb
	lslb			; * 16
	bra	L81d0
;
; coolant warmer than 160 degrees or so....
;
L81c6:	subb	#$20
	bcs	L81d5		; warmer than 246 degrees - use constant
	lslb			; * 2
	lslb			; * 4
	bra	L81d0
;
L81ce:	addb	#$10		; between -20 and 160 degrees
L81d0:	jsr	Ld9f6		; lookup adjusted coolant temperature
	bra	L81d8		; stash result
;
L81d5:	ldaa	Lf267		; load max hot water temp value (246)
L81d8:	staa	L0003		; stash adjusted TH2O - Water Temperature
;
	ldab	L0023		; get MAT ADC reading
	tba			; stash a copy in A
	anda	#%11110000	; upper 4 bits for now
	cmpa	#$d0		; -20 thru -40 ?
	bne	L81ec		; nope
	ldx	#Lf257		; on cold correction table
	lslb			; * 2
	lslb			; * 4
	lslb			; * 8
	lslb			; * 16
	bra	L81ef		; only looking at the lower four bits * 16
;
L81ec:	ldx	#Lf247		; normal adjustment table
L81ef:	jsr	Ld9f6		; lookup adjusted value
	staa	L0002		; stash TAIR - Air Temperature (adjusted)
	bra	L8182		; loop back till something happens
;
L81f6:	ldab	#%00010100	; MULTI On, AN4 thru AN7 selected
	stab	adc_control_reg
	ldaa	#cop_arm	; reset the watch dog timer
	staa	$3a,X
	ldaa	#cop_reset
	staa	$3a,X
L8203:	brclr	$30,X %10000000 L8203 ; loop till conversion completed
	ldd	adc_result_adr1 ; read ADC -->	A = AN4(O2)   B = AN5(TPS)
	staa	L0074		; stash O2 ADC reading
	stab	L0022		; stash TPS reading
	stab	L001e		; last ADC TPS also
	ldd	adc_result_adr3 ; read ADC -->	A = AN6(BATT)  B = AN7(MAP)
	staa	L000a		; stash Battery Voltage
	stab	L00b8		; stash MAP ADC
	stab	L002f		;   .....
mis22:	stab	L0000		; hold here - why ?  Maybe because following CLI
	cli			; interrupts on
;
;
; If at key-on we were at a high altitude the correct for it now.
;
	tba			; put a copy of MAP into A
	jsr	Ldc2a		; add in compression correction to ADC reading
	staa	L0000		; stash corrected MAP ADC value
;
;
	ldaa	L0002		; get TAIR - adjusted
	ldab	Lf021		; MAT Rescaling Factor		B = 88 ($58)
	mul			; D = TAIR_adj * 88			 D=A*B
	adda	Lf022		; MAT Lower Threshold (Adder)		99
	beq	L8255
	psha
	clra
	ldab	L0000		; get slope/offset corrected MAP ADC reading
	addb	Lf023		; Pressure Sensor Offset, Scaling (Adder)
				; + 4" of vacuum		     32
	adca	#$00		; update hi byte if needed
	xgdx
	ldaa	Lf024		; Re-Scaler for DENSAR. (Multi)  184/256 = .72
	jsr	Ld8a5		; D = (A*IX)/256
	xgdx			; put in IX
	pulb			; get TAIR value
	clra
	std	L000fw		; stash air portion here
	xgdx			; MAP value back to D
	ldy	#$000c		; multiplier	(2^11 - 2048)
	jsr	Ld8d1		; D = (D / L000fw) * 2048
	tst	Lf025		; 3.00 DENSAR, Upper Limit		3072
	beq	L8258		; constant wasn't zero
	cpd	Lf025		; 3.00 DENSAR, Upper Limit
				; 3072 - would be -6.5" computed air density
	bls	L8258		; lower - use calculated air density
L8255:	ldd	Lf025		; 3.00 DENSAR, Upper Limit
				; max air density (-6.5")
L8258:	std	L0006w		; stash computed air density (Vacuum)
	jsr	Ldb07		; check for any sensor errors
	ldab	L00b2		; get Rev limiter value (B*250=Limit RPM)
	cmpb	#5000/250	; set to at or above 5000 RPM ?
	bcc	L8267		; yep
	ldab	#5000/250	; no lower than 5000 rpm allowed
	bra	L826d		; stash new limiter value
;
L8267:	cmpb	#9500/250	; over 9500 RPM ?
	bls	L826f		; nope - it's ok
	ldab	#9500/250	; set upper limit
L826d:	stab	L00b2		; new Rev Limiter value stashed
L826f:	brclr	L0059 %00000001 L82d0 ; Controller does Not want current status
	bclr	L0059 %00000001 ; clear request flag
;
	if	not mis6x
	ldaa	L00bc		; get the serial flags
mis6:	anda	#%00000110	; these bits are always zero ?????????
	bne	L82d0		; never take this branch then ????????
	endif
;
	sei			; interrupts off
	ldx	#L00c2		; point to the start of the serial data buffer
	ldaa	L0000		; corrected MAP ADC value
	staa	$02,X		; Not used by controller
	ldaa	L0006w		; get computed air density
	staa	$03,X		; Stash Vacuum - high byte
	ldaa	L0007w
	staa	$04,X		;  Vacuum - low byte
	ldaa	L0002		; get TAIR adjusted
	staa	$08,X
	ldaa	L000a		; get Battery Voltage
	staa	$09,X
	ldaa	L0022		; get TPS
	staa	$0a,X		; stash TPS reading
	ldaa	L0003		; get TH2O - Water Temperature (adjusted)
	staa	$0b,X
	ldaa	L00b9		; get any warning messages
	staa	$0f,X
	ldaa	#%00100000	; water under 120 degrees ?
	staa	$0e,X		; stash mixture flag
	clra
	clrb
	std	$00,X		; no RPM - motor not turning
	staa	$05,X		; no spark angle yet
	std	$06,X		; no Injector Pulse width
	std	$0c,X		; no idle target RPM or IAC % yet
	std	$10,X		; always clear last two locations
	ldaa	#$02		; second byte back to controller
	ldab	#$12		; 18 bytes back to the controller
	std	L00c0		; stash first two bytes
	ldx	#register_base
	ldab	#%00001000	; signal something needed to be transmitted
	stab	L00bc		; stash into serial flags
	bset	$2d,X %10001000 ; enable the Serial Transmitter and Interrupt
	ldaa	#$7b		; $7B to the serial data register
	staa	$2f,X
	ldab	L00c1		; get number needed to send to controller
	addb	#$02		; plus two for prefix
	stab	L00bd		; stash character to send
	ldd	#L00c0		; start of our serial buffer
	std	L00be		; stash serial buffer index
	cli			; interrupts on
L82d0:	jsr	Ld6ea		; do any Dataset saving/restoring now
	jmp	L8182		; loop back for a while
;
; We have had at least one Dist Trigger interrupt to get here since a restart
;
L82d6:	ldaa	L0003		; get TH2O - Water Temperature (adjusted)
	cmpa	Lf571		; TJ Correction Percentage Coolant Threshold
				; water over 120 degrees ?		140
	bhi	L82e2		; yes
	bset	L005e %00100000 ; signal water under 120 degrees
	bra	L82e5
;
; Water over 120 degrees.....
;
L82e2:	bclr	L005e %00100000 ; signal water over 120 degrees
L82e5:	cmpa	Lf564		; Threshold above which FLGPWO is set at key on
				; over 300 degrees ?			255
	bhi	L82ed		; no - of coarse not
	bset	L0058 %00000010 ; signal hot water
L82ed:	cmpa	#$60		; water under 60 degrees ?		 96
	bls	L82f4		; yes
	bset	L0001 %00000010 ; water over 60 degrees (IAC flag)
L82f4:	ldx	#register_base
;
; Wait in the loop below till the motor starts turning over.  If we spend more
;  than 780ms here then loop back to the top....
;
L82f7:	ldaa	L0031		; get timer overflow count
	cmpa	#$06		; been over .78 seconds without a reset ?
	bls	L8300		; nope - still ok
	jmp	L812a		; loop back to top and restart again
;
L8300:	ldaa	#cop_arm	; reset the watch dog timer
	staa	$3a,X
	ldaa	#cop_reset
	staa	$3a,X
	ldd	L003e		; get current timing period
	beq	L82f7		; none - motor is not turning over
;
	ldaa	#%00000111	; Single Scan, Single Channel, AN7 (MAP)
	staa	adc_control_reg
L8311:	brclr	$30,X %10000000 L8311 ; wait for the ADC to finish
	ldd	adc_result_adr3 ; last two MAP reading in A and B
	std	L002f		; stash ADC counts
	staa	L00b8		; current MAP ADC reading
	staa	L002a		; stash MAP ADC average also
	bset	L0058 %00000001 ; signal we have a MAP ADC reading
	ldaa	L0043		; get hi-byte timing period accumulator value
	suba	Lf50c		; Upper threshold to determine if engine started
				; above 610 RPM ?			12
	bcs	L8333		; yes
mis54:	brset	L0058 %01000000 L8336 ; been thru calibration routine already
	ldaa	Lf515		; init revolution counter		255
	staa	L0015		; set revolution counter
	bra	L8336
;
; At or above 610 RPM....
;
L8333:	bset	L0059 %00010000 ; signal stash the high-by timing period
L8336:	ldaa	L0043		; get the timing period accumulator
	bita	#%11110000	; at or below 458 RPM ?
	bne	L8343		; yes
	brset	L005d %00000100 L8343 ; we have had a dist trig event
;
; This next line is not clear.	We should have never gor here unless the motor
;  is turning over and have had an ignition trigger event.  Well because we
;  have had an ign trigger then the above line will always jump around this
;  line.
;
mis49a: clr	L0008		; clear MAP ADC slope/offset correction factor
;
; The below IAC values are what I see when the motor is cranking over
;  during starting.
;
L8343:	ldx	#register_base
	ldd	Lf466		; 6 msec, Actuation Duty Cycle Max Limit
				; 5999 / 2 * 2us = 5.999ms
	std	L0066		; 5.999ms IAC motor On time
	std	L006a		; 5.999ms IAC last motor On time
	ldd	Lf45c		; Nominal Period for VAE (IAC) Control Signal
	std	L0068		; 6.666ms IAC total period
	std	L006c		; 6.666ms IAC last total period
	bclr	$23,X %01111111 ; reset OC1 (IAC) interrupt
	ldd	$0e,X		; get the current Timer count
	addd	#$0019		; plus 50 us (25 * 2us)
	std	$16,X		; set new IAC (OC1) compare count
	bset	$0d,X %10000000 ; output data (h) to PA7 (Idle Motor) when done
	bset	L0001 %00000001 ; stop IAC from doing 250ms initial banging
	ldaa	Lf48d		; set TPS threshold to 1.035 volts	53
	staa	L001c		; stash initial starting point
	ldaa	L0022		; get current ADC TPS reading
	staa	L001e		; stash last TPS ADC
	staa	L0057		; this is the last TPS ADC reading stash
	cmpa	L001c		; thottle plates closed ?
	bls	L8375		; yes
	ldaa	L001c		; get TPS closed threshold value
L8375:	staa	L001d		; seed stash - lowest TPS ADC reading ever read
	bclr	$23,X %11101111 ; reset OC4 (IGN AMP Driver) compare flag
;
	if	mis57x
	bset	$20,X %00001100 ; force IGN AMP Diver Output to go High
	else
	ldaa	$20,X		; get current timer control state
	oraa	#%00001100	; force IGN AMP Driver output to go high
	eora	Lf01d		; 0 - Ign Coil Driver Mode
	staa	$20,X		; update
	endif
;
	ldd	$0e,X		; get current count
	addd	#$000f		; in 30 us
	std	$1c,X		; set new compare point
	ldab	L0003		; get TH2O - Water Temperature (adjusted)
	ldx	#Lf217		; on dashpot rpm vs TH2O table
	lsrb			; / 2
	lsrb			; / 4
	lsrb			; / 8
	lsrb			; / 16
	lsrb			; / 32
	adcb	#$00		; one more if last bit out was a one
				;  This offsets the divide by 32 by 16
	cmpb	#$07		; max 8 entries ?
	ble	L839c		; nope
	ldab	#$07		; max
L839c:	abx
	ldaa	$00,X		; get it
	staa	L0017		; stash initial - dashpot RPM threshholds
	ldx	#Lf21f		; on rpm (timing_period/16) vs TH2O
	abx
	ldaa	$00,X		; get it
	staa	L0018		; stash initial - deceleration fuel cuttof
	clr	L0014		; clear lowest MAP ADC reading ever read
	bclr	L0058 %01000000 ; signal no Calibration data yet
;
; End of Initialization code - wont ever pass this way again as long as we
;  keep running...........
;
; =============================================================================
; This is the top of the Calibration run loop...............
;
; If we don't have a current MAP ADC reading from the Distributor Trigger
;   handler (every timing event) then wait here till we do.....
;
L83af:	ldaa	#cop_arm	; reset the COP watchdog timer
	staa	coprst_register
	ldaa	#cop_reset
	staa	coprst_register
	brclr	L0058 %00000001 L83af ; wait till we get a new MAP ADC reading
	brclr	L0059 %00000001 L83c7 ; controller does not need current parms
	bclr	L0059 %00000001 ; clear request bit
	bset	L00bc %00000001 ; allow engine parms to be sent to controller
L83c7:	ldaa	#cop_arm	; reset the COP watchdog timer
	staa	coprst_register
	ldaa	#cop_reset
	staa	coprst_register
	bclr	L0058 %00000001 ; signal we used this MAP ADC reading value
	ldaa	L002a		; get average of last two MAP readings
;
; If we started the motor in a high altitude condition add the elevation
;  compression factor in here.
;
mis49d: jsr	Ldc2a		; add in altitude compression correction factor
	staa	L0000		; stash adjusted MAP ADC reading
;
; Increase the MAP ADC reading by 1.56%   (130/128 = 1.015625)
;
	ldaa	#$82		; 130
	ldab	L0000		; get correct ADC reading
	mul
	lsld
	bcc	L83e5		; didn't overflow
	ldaa	#$ff		; 255 upper limit
L83e5:	staa	L0000		; stash adjusted MAP ADC reading
	jsr	Ld000		; do all IAS work
	ldd	L003e		; get the current timing period
	cpd	#$1000		; over 458 RPM ?	      (1,875,000/4096)
	bcs	L83f5		; yes - not cranking over
	ldd	#$0fff		; limit to 458
L83f5:	lsld			; * 2
	lsld			; * 4
	lsld			; * 8
	lsld			; * 16
	jsr	Ldc56		; convert timing period into RPM/25
	stab	L00b7		; stash rpm/25
;
	ldab	L0022		; get the TPS ADC count
	brclr	L00b9 %00010000 L8408 ; Do Not have a Throttle Input Error
	ldab	Lf560		; get 197 (82 degrees)
	decb			; (81.5 degrees)
L8408:	ldaa	L0001		; get flags
	cmpb	Lf48d		; TPS below 1 volt ?	53
	bcs	L8413		; yes
	oraa	#%00010000	; signal plates where opened
	bra	L8456
;
; TPS below a volt (throttle plates closed)....
;
; The below code is mostly responsible for determing the lowest TPS ADC reading.
; We can bring down the lowest stash (L001d) fairly quickly but can only
; increase it at a 2 count rate once every 8 seconds.
;
L8413:	cmpb	L001e		; did TPS change from the last reading ?
	bne	L845a		; yes
	cmpb	L001d		; lower now that what we thought was lowest ?
	bcs	L843f		; yes - set new low value
	bhi	L8421		; TPS higher than our lowest reading
	anda	#%11101111	; signal throttle plates closed
	bra	L8456
;
L8421:	bita	#%00100000	; 8 second counter active ?
	bne	L842f		; yes
	bita	#%00010000	; where the throttle plates opened ?
	beq	L846e		; nope
	oraa	#%00100000	; turn 8 second counter on
	anda	#%11101111	; signal throttle plates closed
	staa	L0001		; replace updated flags
L842f:	ldaa	L0021		; get 8 second counter
	bne	L846e		; has not counted down yet
	ldaa	L001d		; get the lowest read TPS ADC value
	adda	Lf48c		; plus max rate of stash change 	2
	cba			; is lowest read too high ?
	bhi	L8452		; yes - stash current ADC as lowest then
	staa	L001d		; was too low - bring up slowly
	bra	L845a
;
L843f:	anda	#%11101111	; signal throttle plates closed
	staa	L0001		; replace updated flags
	ldaa	L001d		; get lowest TPS ADC read so far
	suba	Lf48b		; less max rate of change		2
	bcc	L844b		; didn't go below zero
	clra			; yep
L844b:	cba			; current ADC higher than old lowest ?
	bls	L8452		; yes - use it then as new lowest
	staa	L001d		; was too high - bring down slowly
	bra	L8454
;
L8452:	stab	L001d		; use current ADC as lowest ever read
L8454:	ldaa	L0001		; get flag byte
L8456:	anda	#%11011111	; turn 8 second counter off
	staa	L0001		; replace updated flags
L845a:	ldaa	Lf48e		; Counter value for Idle Threshold Update
				; 8 second counter	64*131ms = 8.3sec
	staa	L0021		; reset it
	ldaa	L001d		; get lowest TPS ADC reading
	adda	Lf48f		; Min Delta Throttle between TPS A/D and FARSM
	cmpa	Lf48d		; over TPS closed threshold ?		  53
	bls	L846c		; nope - use it as TPS throttle plate closed
;				; threshold then
	ldaa	Lf48d		; get TPS closed threshold (1.035 volts)  53
L846c:	staa	L001c		; stash new throttle plates closed threshold
L846e:	stab	L001e		; stash new last TPS ADC reading
	cmpb	L001c		; throttle plates closed ?
	bls	L84b4		; yes
	ldaa	L00b7		; get rpm/25
;
	if	mis38x		; new 01/02/99
;
; This all boils down to wether we are WOT or partial plates.....
;
	cmpb	Lf561		; 197  3.8 volts  82 degrees   WOT ?
	bhi	L84bc		; yes - WOT
	bset	L0001 %10000000 ; signal throttle plates are opened
	bclr	L0001 %01000000 ; ...but Not WOT
	bra	L84c2
;
	else			; old code
;
; No matter if rpm > 3500 or over 3 minutes because the same tests and the
;  same branchs are always taken..............................................
;
mis46:	cmpa	#$8c		; above 3,500 RPM ?		140*25=3500
	bhi	L8485		; yes
	brset	L0058 %00000010 L8485 ; water is hot / over 3 minutes running
	cmpb	Lf560		; 197  3.8 volts  82 degrees TPS
	bhi	L8498
	bra	L848a
; .............................................................................
; Above 3,500 rpm or Water is hot or been over Three minutes.....
; and everything else because of mis46:...........
;
L8485:	cmpb	Lf561		; 197  3.8 volts  82 degrees   WOT ?
	bhi	L8498		; yes - WOT
L848a:	clr	L0020		; ???? mis38:
	bclr	L0058 %10000000 ; useless mis47:
;
L8490:	bset	L0001 %10000000 ; signal throttle plates are opened
	bclr	L0001 %01000000 ; ...but Not WOT
	bra	L84c2
;
; WOT <<<<<<
; Lots of useless code because of mistakes.  When all is said and done we will
;  always end up at L84bc ....................................................
;
L8498:	brset	L0058 %10000000 L84a4 ; usless jmp because L0020 always zero
	ldaa	Lf588		; WOT Enrichment Enable Delay	  0    mis38:
	staa	L0020		; always get a zero stashed into it ?????
mis47:	bset	L0058 %10000000 ; useless
L84a4:	ldaa	L0000		; get the adjusted MAP ADC reading
	cmpa	Lf58a		; MAP value for Immediate WOT Enrichment     0
mis23:	bls	L84ae		; Will never take this jump because min L0000
;				;  can ever be is 7
;				; NOTE: with L0008=0 then will get lower.....
				;
	clr	L0020		; ????? mis38:
L84ae:	ldaa	L0020		; will always the below jump because always zero
	beq	L84bc		; always take this jump ??????
	bra	L8490		; never take this branch

	endif

;
; .............................................................................
; throttle plates are closed.....
;
L84b4:
	if	not mis38x
	bclr	L0058 %10000000 ; useless bit	mis47:
	endif
;
	bclr	L0001 %11000000 ; signal plates are closed and Not WOT
	bra	L84c2
;
; WOT <<<<<<<
;
L84bc:	bset	L0001 %01000000 ; signal WOT
	bclr	L0001 %10000000 ; signal not partial throttle
;
; B = TPS ADC reading....
;
; ............................................................................
; This below is all questionable.  If the rpm is between 1,670 and 2,070
;  or 2,461 to 2,619 then if the TPS was above a trip point in Lf507/Lf508
;  the MAP correction factor in L0008 would have been computed.  The problem
;  is that we will always jump arround the MAP correction call because the TPS
;  ADC reading can never be over 255.  This means that what gets stashed into
;  L0008 is always zero.
;
; 09/03/99 - Well it looks like this whole L0008 thing needs to be revisited.
;	     What looks like is happening is that the value in L0008 is a
;	     altitude compression factor that is applied to the MAP ADC value.
;	     The initial call to Ldc0e: at key on checks how high we are at and
;	     computes an altitude compression correction factor in L0008.
;	     Where I mad my error is in thinking only in terms of a low lander
;	     (sea level operation) where the value in L0008 is always zero.
;	     At higher initial key-on altitudes this will not always be the
;	     case.  The routine at L84c2: is disabled though.  This routine is
;	     in the main Calibration loop.  It checks to see if the current
;	     RPM is between two windows, either 1670-2070 or 2460-2620, and if
;	     it is then it checks the TPS for a certain threshold value.  If
;	     it passes all these tests it will then recompute the altitude
;	     compression factor in L0008.  The problem is that the TPS check
;	     values are 255.  Well the TPS ADC will never get that high so the
;	     recomputations done by Ldc0e: will never happen and the initial
;	     turn on value in L0008 will remain the same.  So this all boils
;	     down to that the L0008 stash has a valid number in it and the
;	     routine at L84c2: is usless...
;	     Now the fun to back out my mis49: mistake !!!
;
mis49:
;
; This has something to do with altitude correction
;
L84c2:
	if	not mis49x
	ldx	L0040		; get the predicted next timing period
	cpx	Lf4ff		; Lower RPM Threshold for 1st Window
				; Slower than 1,670 RPM ?      (1123 - 1670 RPM)
	bcc	L84e8		; yes - ignore
	cpx	Lf501		; Upper RPM Threshold for 1st Window
				; Faster than 2,070 RPM ?	(906 - 2070 RPM)
	bls	L84d3		; yes
	ldaa	Lf507		; TPS for first RPM Window		255
	bra	L84e0
;
; Faster than 2,070 RPM....
;
L84d3:	cpx	Lf503		; Lower RPM Threshold for 2nd Window,
				; Slower than 2,461 RPM ?	(762 - 2461 RPM)
	bcc	L84e8		; Yes - ignore
	cpx	Lf505		; Upper RPM Threshold for 2nd Window
				; Faster than 2,619 RPM ?	(716 - 2619 RPM)
	bls	L84e8		; yes
	ldaa	Lf508		; TPS for 2nd RPM Window		255
L84e0:	cba			; A-B  255-TPS_ADC
	bcc	L84e8		; will always take this jump because TPS ADC
;				;  can never get over 255 to set CY.....
	ldaa	L002a		; get average of last to MAP ADC readings
	jsr	Ldc0e		; compute MAP altitude compression correction
				;  ...and stash in L0008
	endif
; .............................................................................
;
L84e8:	brclr	L00ba %01000000 L84f2 ; Do Not have a Coolant Error
	ldaa	#$78		; Error - default to 95 degrees
	staa	L0003		; stash TH2O - Water Temperature
	bra	L852a		; continue with TAIR stuff
;
L84f2:	ldx	#Lf268		; point to the correction table
	ldab	L0024		; get COOL ADC reading
	tba			; put a copy into A
	anda	#%11110000	; leave only upper four bits
;
; If the coolant temperature circuit was open the highest ADC (lowest temp)
;  reading possible would be 4.3 volts - ADC=220 $E0
;
	cmpa	#$e0		; warmer than 224 ?
	bcs	L8501		; yes - circuit probably not bad (open)
	clra			; signal trouble - max Hot
	bra	L8524
;
L8501:	cmpa	#$30		; warmer than about 160 degrees ?
	bcs	L8512		; yes
;---------------------------------------------
; TEXPNDH
; EXPANDED TEMPERATURE TABLE
; FOR FORD TEMP SENSORS
;  ENTRIES IN THIS TABLE EXPAND TABH2O
;   H ABOVE FROM 208 to 233d A/D
;
;---------------------------------------------
	cmpa	#$d0		; between -40 to -20 degrees or so ?
	bne	L851a		; nope
	ldx	#Lf278		; point to Ford Expanded Table
	lslb			; * 2
	lslb
	lslb
	lslb			; * 16
	bra	L851c
;
; coolant warmer than 160 or so degrees....
;
L8512:	subb	#$20		;
	bcs	L8521		; warmer than 246 degrees - use constant
	lslb			; * 2
	lslb			; * 4
	bra	L851c		; use lookup table
;
L851a:	addb	#$10		; between -20 and 160 degrees
L851c:	jsr	Ld9f6		; return temp from look-up table
	bra	L8524		; stash results
;
; coolant is warmer than 246 degrees
;
L8521:	ldaa	Lf267		; load highest water temp constant (246)
L8524:	ldx	#L0003		; point to COOL adjusted stash
	jsr	Ld8f0		; update the RAM stash
;
L852a:	brclr	L00b9 %00001000 L8540 ; do Not have a TAIR error (air temp)
;
; We have a bad TAIR sensor.  Warning sent.  Use the water temperature to
;  get us some kind of in the ball park air temp value...
;
	ldaa	L0003		; get TH2O - Water Temperature
	adda	#$20		; TAIR adjusted is about 32 higher
	bcc	L8536		; didn't roll - not too hot (over ~220)
	ldaa	#$ff		; max at 255
L8536:	ldab	#$98		; don't let TAIR go above about 90 degrees
	cba			; is adjusted temp lower than 90 degress ?
	bcs	L853c		; yes
	tba			; nope - use the 90 degree value
L853c:	staa	L0002		; stash new TAIR - Air Temperature
	bra	L856c
;
; don't have MAT sensor error so use it's value

L8540:	ldab	L0023		; get MAT ADC reading
	tba			; a copy into A
	anda	#%11110000
	cmpa	#$d0		; -20 thru -40 ?
	bne	L8552		; nope
	ldx	#Lf257		; on cold table
	lslb			; * 16 so we are only looking at lower 4 bits
	lslb
	lslb
	lslb
	bra	L8555
;
L8552:	ldx	#Lf247		; normal range adjustment table
L8555:	jsr	Ld9f6		; lookup ajusted value (return in A)
	brclr	L0001 %11000000 L855e ; throttle plates are closed !
	bra	L8566		; either partial or WOT
;
L855e:	cmpa	Lf50e		; D3 (211)  - lower than 150 degrees ?
	bls	L8566		; yes
	ldaa	Lf50e		; force 150 degrees max
L8566:	ldx	#L0002		; point to MAT adjusted stash
	jsr	Ld8f0		; update the RAM stash
;
;
;
;			 (MAP_ADC+32)*.72
; Air_Charge = ( -------------------------------- ) * 2048
;		   Air Temp+103
;		 ( ------------ ) * .34375 ) + 99
;		      1.2375
;
;
; Air = Air * .34375	(air * (88/256))
;
L856c:	ldab	Lf021		; MAT Rescaling Factor		B = 88 ($58)
	mul			; D=A*B
;
; Air - Air + 99
;
	adda	Lf022		; MAT Lower Threshold (Adder)		99
	beq	L859d		; use max air density
	psha
	clra
	ldab	L0000		; get adjusted MAP ADC value
	addb	Lf023		; Pressure Sensor Offset, Scaling (Adder)
				; + 4" of vacuum		     32
	adca	#$00
	xgdx			; into IX
	ldaa	Lf024		; Re-Scaler for DENSAR. (Multi)
				; 72%	   184/256 = .72
	jsr	Ld8a5		; D = (A*IX)/256
	xgdx			; IX = (MAP + 3.56") * .72
	pulb
	clra
	std	L000fw		; stash air portion here
	xgdx
	ldy	#$000c		; time 2048  (2^11)
	jsr	Ld8d1		; D = (D / L000fw) * 2048
	tst	Lf025		; 3.00 DENSAR, Upper Limit
				; test max air density constant (3072)
	beq	L85a0		; constant not zero so will never take this bra
	cpd	Lf025		; 3.00 DENSAR, Upper Limit
				; more dense than max ?
	bls	L85a0		; nope - use calculated air density
L859d:	ldd	Lf025		; 3.00 DENSAR, Upper Limit
				; use max constant (-6.5")
;
; Displayed_Vacuum(in) = 28.9 - (L0006w * .01152)
;
L85a0:	std	L0006w		; stash computed air density (displayed Vacuum)
	psha
	ldaa	L00bc		; ok to send current status to controller ?
	anda	#%00000111
	cmpa	#%00000001
	bne	L85d0		; nope
	pshx
	ldx	#L00c2		; point to the serial buffer
	ldaa	L0040		; get predicted next timing period
	staa	$00,X
	ldaa	L0040+1
	staa	$01,X		; .... low byte
	ldaa	L0000		; get adjusted MAP ADC value
	staa	$02,X		; stash in buffer
	ldaa	L0006w		; get computed air density
	staa	$03,X		; stash current Vacuum
	ldaa	L0007w
	staa	$04,X		; .... low byte
	ldaa	L0002		; get TAIR - Air temperature - adjusted
	staa	$08,X		; stash
	ldaa	L001e		; get last TPS ADC reading
	staa	$0a,X
	ldaa	L0003		; get TH2O - Water Temperature
	staa	$0b,X		; stash
	pulx
L85d0:	pula
	ldab	Lf018		; 10
	stab	L001bw		; 11 entries in look-up table
	ldd	L0006w		; get computed air density
	ldx	#Lf047		; point to Load index table
	jsr	Ld907		; look up indexs
	stab	L0012w		; stash distance from the exact match entry
	ldab	L001bw		; get the matched major index
	bne	L85e9		; within legal MAP bounds
	bset	L0059 %00001000 ; signal out of bounds (too hi a Load)
	bra	L85ec
;
L85e9:	bclr	L0059 %00001000 ; signal in bounds
L85ec:	lslb			; * 2
	lslb			; * 4
	lslb			; * 8
	lslb			; * 16 - 16 RPM ranges per Load index
	stab	L0005w		; stash major index*16 (Fuel Load Index)
	ldab	#$0f
	stab	L001bw		; 16 entries in look-up table
	ldd	L0040		; get the predicted next timing period
	ldx	#Lf027		; point to RPM index table
	jsr	Ld907		; look up rpm indexes
	stab	L000bw		; stash distance from the exact match entry
	stab	L0011w		; here also
	ldab	L001bw		; get the matched major index
	stab	L0013w		; stash for later use
	addb	L0005w		; plus major index from Load lookup
	ldx	#Lf067-16-1	; Fuel matrix				Lf056
	jsr	Ld970		; lookup Fuel Pulse width
	xgdx			; result in to IX
	ldaa	Lf020		; 15% of the lookup table value 	38
	jsr	Ld8a5		; D = (A*IX)/256
	std	L0004w		; stash new fuel requirements
;
	brclr	L0059 %00001000 L862d ; found Load in table (not out of bounds)
mis50:	ldx	#Lf047		; point to the highest Load in lookup table
	ldab	Lf018		; 10
	lslb			; * 2 --> 20  (words)
	abx			; IX = $f047+20 = $f05b
	ldd	$00,X		; D=2765 = -3"
	std	L000fw
	ldd	L0006w		; get computed air density (Load)
	subd	L000fw		; less highest Load in lookup table
	bcc	L8631		; computed is larger than what is in table max
;
; Computed Load is smaller than what is in the lookup table so go with what
;  we have so far....
;
L862d:	ldd	L0004w		; get current work Fuel PW into D
	bra	L8641
;
; Computed Load is larger than the max value in the lookup table.
; At this point 'D' is how much above the tables largest and L000fw is the
; largest entry in the lookup table.  It looks like they are projecting outward
; to come up with the fuel required.
;
L8631:	ldy	#$000a		; times 512  (2^9)
	jsr	Ld8d1		; D = (D / L000fw) * 512
	tba			; into A
	ldx	L0004w		; get what we got from the table
	jsr	Ld8a5		; D = (A*IX)/256
	lsrd			; / 2
	addd	L0004w		; plus what we got out of the table
L8641:	std	L0004w		; stash work fuel requirements so far
	ldaa	L0022		; get the ADC TPS count
	cmpa	L001c		; throttle plates closed ?
	bhi	L8653		; nope - opened
	ldaa	L0017		; dashpot threshold rpm
	cmpa	L0042		; compared to timing_period / 16
	bhi	L8653		; faster than threshold rpm
	ldab	L00ab		; get the Idle Fuel modifier value
	bra	L868d		; join modifer
;
L8653:	ldab	Lf700		; 3, TCIC: num DENSAR BREAKPTS. - 1
	stab	L001bw		; 4 entries in look-up table
	ldd	L0006w		; get computed air density (Load)
	ldx	#Lf706		; point to Load index table
	jsr	Ld907		; look up Load indexes
	stab	L0012w		; stash fractional component
	ldab	L001bw		; get the major matched index
	ldaa	Lf701		; get number-1 RPM rows 		5
	inca			; loose the minus 1
	mul
	pshb			; save Load index
	ldab	Lf701		; number-1 RPM cells			5
	stab	L001bw		; 6 items in RPM look-up table
	ldd	L0040		; get the predicted next timing period
	ldx	#Lf70e		; point to the RPM index table
	jsr	Ld907		; look up
	stab	L000bw		; stash distance from the exact match entry
;
	if	mis35x
	ldx	#$0079
	else
mis35:	ldx	#L0080-$fe-2	; point to the timing period table (RPM)   Lff80
	ldab	#$fe		; -2
	subb	Lf701		; 5
	abx			; IX = $0079
	endif
;
	pulb			; get Load base index back
	addb	L001bw		; plus RPM base index
	abx			; IX points to RPM cell in previous Load column
	ldab	Lf701		; number-1 RPM cells			5
	jsr	Ld9bf		; get the interpolated Fuel modifier value
	tab			; into B
;
; Now modifiy Fuel by the user modifier in B.  This could either be from the
; user RPM-vs-Load lookup above or if the throttle is closed from the user
; idle fuel modifier.
;
; Remember: Zero modification value is 128 .........
;
L868d:	ldx	L0004w		; get current calculated Fuel
	jsr	Ldbe9		; D = IX * (B/128)
;
; So at this point we have 15% of what was found in the table plus-or-minus
;  the modifier percentage.....
;
	std	L0004w		; stash new Fuel
	pshb			; get it into IX to multiply
	psha
	pulx
	ldab	L00aa		; get the Global Fuel modifier
	jsr	Ldbe9		; D = IX * (B/128)
	std	L0004w		; stash new work pulse width
; .............................................................................
; End of Fuel calibration, Spark next................
;
	brclr	L0059 %00010000 L86c7 ; Below 610 RPM - zero spark advance
	brset	L00b3 %10000000 L86c7 ; Base Timing Set is On ! - zero Spk Adv
	ldaa	L0015		; get the current revolution counter
	cmpa	Lf516		; Number of revolutions threshold for SA
				;   decreasing updating.
				; over 128 revolutions past by ?	128
	bls	L86b0		; yes
	jmp	L876d		; join spark calculations
;
L86b0:	ldab	L0043		; get the timing period accumulator
	bitb	#%11110000	; above about 458 RPM ?
	beq	L86ce		; yes
	bitb	#%11100000	; at or below 229 RPM ?
	bne	L86c7		; yes - zero spark advance then
;
; between 236 and 458 RPM .....
;
	andb	#%00001111	; low bits only
	ldx	#Lf35c		; point to Spark lookup table
	abx
	ldaa	$00,X		; get advance for RPM
	staa	L0006w		; stash in our work spark advance
	jmp	L8849		; done spark angle calculations
;
; Above 610 RPM and Base Timing Set is active
; Below 610 RPM.....
; Below 229 RPM.....
;
L86c7:	ldaa	#$00		; zero spark advance
	staa	L0006w		; stash
	jmp	L8849		; skip timing computations
;
; Above 458 RPM....
;
L86ce:	ldaa	L0022		; get the ADC TPS count
	cmpa	L001c		; throttle plates closed ?
	bls	L86d7		; yes
	jmp	L876d		; calculate spark here
;

	if	mis32x		; always comes up with the same value
L86d7:	ldaa	#$6c		; 37 degrees
	else
;
; Thottle plates are closed, above 458 RPM, more than 128 revolutions..........
;
L86d7:	ldaa	#$0f
	staa	L001bw		; 16 items in look-up tables
	ldaa	L0003		; get TH2O - Water Temerature
	cmpa	Lf484		; If COOL > than this then use TPNOM (Lf485)
				; at or below 170 degrees ?		176
	bls	L86ed		; yes - use current target RPM
	ldaa	L0061		; get Idle Target RPM
	suba	Lf485		; Delta Period to be subtracted from TPNOM if
				;  COOL > Lf484 when calculating Idle Spark
				;   advance.
				; -148 - If the target RPM was equal to or
;				; slower than 792 RPM then no Carry
	bcc	L86ef		; slower or equal to 792 RPM
	ldab	#$ff		; target is above 792 RPM - make like 460 rpm
	bra	L86f3		; look it up
;
; Entry: Water is at or below 170 degrees, use current Target Idle RPM....
;
L86ed:	ldaa	L0061		; get current Target Idle RPM
;
; Entry: Target RPM (L0061) is equal to or below 792 RPM.
;	  'A' = L0061 - 148
;
L86ef:	clrb			; clear low byte
	jsr	Ldc56		; convert the timing period into RPM/25
;
; Target RPM was above 792 rpm, stash 255 (460 rpm)....
;
L86f3:	stab	L0012w
	ldab	L00b7		; get current rpm/25
	subb	L0012w		; less target idle RPM/25
	bcs	L872e		; we are below the target Idle rpm
	clra
;
; 'B' is how far above the target Idle RPM we are (25 rpm units)....
;
; Of coarse all of this is bull shit because the table at Lf38c contains all
;  of the same entries......
;
mis32:	ldx	#Lf36c		; point to rpm index table
	jsr	Ld907		; lookup
	ldx	#Lf38c		; point to actual spark angle table
	tstb			; exact match ?
	bne	L870f		; nope - didn't get an exact match
	ldab	L001bw		; get index of match
	abx			; point into second table
	ldaa	$00,X		; get new spark angle
	bra	L8763		; join Idle Spark Modifier
;
; didn't get an exact match so interpolate between two entries... (BS)
;
L870f:	tba			; put distance into A
	ldab	L001bw		; get major index
	abx			; IX now points to first spark modifier
	ldab	$00,X		; get it
	stab	L000bw		; stash
	dex			; point to second
	ldab	$00,X		; get it
	subb	L000bw		; B = difference
	bcc	L8725		; positive difference
	negb			; change sign
	mul			; times distances
	suba	L000bw		; less first
	nega			; change sign back
	bra	L8763		; join Idle Spark Modifier
;
L8725:	mul			; times distance
	adda	L000bw		; plus first
	bcc	L8763		; ok - join Idle Spark Modifier now
	ldaa	#$ff		; max out
	bra	L8763		; join Idle Spark Modifier
;
; we are below the target idle rpm....
;
; Of coarse all of this is bull shit because the table at Lf3bc contains all
;  of the same entries......
;
mis33:
L872e:	ldab	L0012w		; get target rpm/25
	subb	L00b7		; less current rpm/25
	clra
	ldx	#Lf39c		; point to rpm/25 table
	jsr	Ld907		; look up
	ldx	#Lf3bc		; point to actual spark angle table
	tstb			; exact match ?
	bne	L8746		; nope - need to interpolate
	ldab	L001bw		; get index
	abx			; point to spark angle
	ldaa	$00,X		; get it
	bra	L8763		; join Idle Spark Modifier
;
; not exact match so we need to interpolate between entries
;
L8746:	tba			; distance into 'A'
	ldab	L001bw		; get major index
	abx			; point to spark angle
	ldab	$00,X		; get it
	stab	L000bw		; stash
	dex			; point to next
	ldab	$00,X		; get it
	subb	L000bw		; B = difference
	bcc	L875c		; positive
	negb			; change signs
	mul			; interpolate
	suba	L000bw		; less first
	nega			; change sign back
	bra	L8763		; join Idle Spark Modifier
;
L875c:	mul			; interpolate
	adda	L000bw		; plus first
	bcc	L8763		; ok - join Idle Spark Modifier
	ldaa	#$ff		; max spark of 255 (63.75 degrees)
;
	endif


; 'A' contains the new calculated spark angle (in .25 degree units)
;
L8763:	ldab	L00af		; get the Idle Spark Modifier
	jsr	Ldbc8		; adjust the Spark value
	staa	L0006w		; stash work value Spark Angle
	jmp	L87de		; join Global Spark modifier
;
; ...................END Throttle Plates Closed Spark ........................
;
; -----------------------------------------------------------------------------
; Above 610 RPM and 128 revolutions have Not past by yet ......................
; Above 458 RPM and more than 128 revolutions and throttle plates opened ......
;
; L0006w still contains the calculated air density charge.....
; Displayed_Vacuum(in) = 28.9 - (L0006w * .01152)
;
; We are going to calculate which spark table cell to use.  Our internal
;  spark table consists of 128 cells (16 rpm x 8 load) 
;
; First look up the Load indexes...............................................
;
L876d:	ldab	Lf019		; 7
	stab	L001bw		; 8 items in look-up table
	ldd	L0006w		; get computed air density
	ldx	#Lf2a8		; on air charge lookup table
	jsr	Ld907		; lookup
	stab	L0012w		; stash distance from the exact match entry
	ldab	L001bw		; get the matched index
	lslb			; * 2
	lslb			; * 4
	lslb			; * 8
	lslb			; * 16 - 16 rpm cells per Load
	pshb			; save Load index
;
; Next the RPM indexes.........................................................
;
	ldab	#$0f
	stab	L001bw		; 16 items in RPM look-up table
	ldd	L0040		; get the predicted next timing period
	ldx	#Lf288		; point to RPM table
	jsr	Ld907		; lookup index and fractional
	stab	L000bw		; stash distance from the exact match entry
	pulb			; get Load base index back
	addb	L001bw		; plus RPM base index
;
; Now that we have both indexes lookup into the main Spark Matrix....
;
	ldx	#Lf2bc-16-1	; point to Spark Matrix table		Lf2ab
	jsr	Ld970		; look up Spark Angle
; .............................................................................
;
; Now we will look-up from the user modification matrix (3 columns x 6 rows)
;
; First lookup the Load indexes......
;
	ldx	L0006w		; get air charge back
	staa	L0006w		; stash new spark angle
	ldab	Lf702		; 2
	stab	L001bw		; 3 items in the lookup table
	xgdx			; D = Air Charge (Load)
	ldx	#Lf71a		; point to index table
	jsr	Ld907		; look up index
	stab	L0012w		; stash distance from the exact match entry
	ldab	L001bw		; get major index of located entry
	ldaa	Lf703		; 5 - number RPM ranges for each MAP column
	inca			; plus 1
	mul			; B = index * 6
	pshb			; save column index (air charge)
;
; Now the RPM indexes..........................................................
;
	ldab	Lf703		; 5
	stab	L001bw		; 6 items in the RPM table
	ldd	L0040		; get the predicted next timing period
	ldx	#Lf720		; point to RPM index table
	jsr	Ld907		; look it up
	stab	L000bw		; stash distance from the exact match entry
;
; Now look up the user adjustable modifier.....................................
;
	if	mis34x
	ldx	#$0091
	else
mis34:	ldx	#L0098-$fe-2	; point to timing period (RPM) table	Lff98
	ldab	#$fe		; seems strange ????
	subb	Lf703		; less rows-1				5
	abx			; IX = $0091  ???? - just use this then.....
	endif
;
	pulb			; Load base index
	addb	L001bw		; plus RPM base index
	abx			; IX points to RPM cell in previous Load column
	ldab	Lf703		; RPM-1 ranges in table 		5
	jsr	Ld9bf		; get interpolated spark modifier
	tab			; in to B
	ldaa	L0006w		; get Spark advance value
	jsr	Ldbc8		; adjust it by modifier value in B
	staa	L0006w		; new user adjusted spark advance value
;
; At this point both 'A' and L0006w contain the new Spark Angle
;
L87de:	ldab	L00ae		; get Global Spark Modifier
	jsr	Ldbc8		; adjust Spark value
	staa	L0006w		; stash adjusted spark advance
;

	if	not mis36x

	ldaa	L0000		; get MAP ADC adjusted value
	cmpa	Lf50d		; MAP Threshold above which Spark is Retarded
				; Vacuum >= ~6"  (6" --> 29")		195
	bls	L880a		; yes - light to moderate Load
;
; Fairly heavy load, < 6" ......
; Adjust spark for Air Temperature.............................................
;
; of coarse more BS because all entries are 128 (zero modifier !)
;
	ldab	L0023		; get MAT ADC reading
mis36:	ldx	#Lf613		; point to adjustment table
	jsr	Ld9f6		; lookup how much to mod spark verses Air Temp
	suba	#$80		; remove 128 bias
	tab			; into B
	bcc	L8802		; positive
	ldaa	L0006w		; get current calculated spark
	negb			; change sign
	sba			; modify
	bcc	L8808		; not below zero
	clra			; zero min
	bra	L8808
;
L8802:	adda	L0006w		; plus current spark
	bcc	L8808		; didn't overfow
	ldaa	#$ff		; max at at 63.75 degrees
L8808:	staa	L0006w		; stash MAT adjusted spark
; .............................................................................
;
L880a:	ldab	L0022		; get the ADC TPS count
	cmpb	L001c		; throttle plates closed ?
	bhi	L882b		; nope - opened
;
; Throttle plates closed.......................................................
; Further adjust the spark if the RPM is above the TH2O RPM set point.
;
; BIG mistake here.  The below code assumes that 'A' still contains the current
;  spark angle.  That would be true if we came from the above code that ended at
;  L8808, but if we got here from the branch that tested the MAP ADC (which
;  trashed the A register) just below L87de the 'A' register does not contain
;  the current spark angle value and we end up storing the MAP ADC value
;  instead.
;
; 01/03/99 - Makes no difference anyhow because the value at Lf4fb is 128
;	      which 128 gets subtracted fromit leaving 0 to add/subtract !!
;
;
mis37:	ldab	L0042		; get the timing_period / 16
	cmpb	L0017		; below dashpot threshold rpm ?
	bcc	L882b		; yes - skip this spark angle adjustment
mis37a: ldab	Lf4fb		; SA Offset during Deceleration with Throttle
				;  at Idle.
	subb	#$80		; remove bias
	bcc	L8824		; positive modifier
	negb			; change sign
	sba			; adjust spark angle
	bcc	L8829		; didn't go below zero
	clra			; it did
	bra	L8829
;
L8824:	aba			; increase spark angle
	bcc	L8829		; didn't go too high
	ldaa	#$ff		; max out
L8829:	staa	L0006w		; stash high speed adjusted spark angle
;
	endif			; mis36: and mis37:
;
; Next adjust the Spark Angle for Water Temperature............................
;
L882b:	ldab	L0003		; get TH2O - Water Temperature
	ldx	#Lf3cc		; point to adjustment table
	jsr	Ld9f6		; lookup modifier value
	suba	#$80		; remove bias
	tab			; into B
	bcc	L8841		; positive direction
	ldaa	L0006w		; get current spark angle
	negb			; change sign of modifier
	sba			; reduce spark angle
	bcc	L8847		; didn't got below zero
	clra			; yep
	bra	L8847
;
L8841:	adda	L0006w		; plus current spark angle
	bcc	L8847		; didn't overflow
	ldaa	#$ff		; max out
L8847:	staa	L0006w		; stash adjusted work Spark Angle
; .............................................................................
;
L8849:	ldaa	L0043		; get hi-byte timing accumulator value
	brclr	L0059 %00010000 L8859 ; We are in the L0043 approach mode which
;				      ;  means we are Below 610 RPM....
	suba	Lf50b		; Lower Theshold to acknowledge Engine Start
				; at or above 253 RPM ? 		29 (1D)
	bls	L8865		; yes
	bclr	L0059 %00010000 ; start L0043 accumulator approach mode
;				;  below 610 RPM
	bra	L885e
;
L8859:	suba	Lf50c		; Upper threshold to determine if engine started
				; at or above 610 RPM now ?		12 (0C)
	bls	L8862		; yes
L885e:	ldaa	#$20		; 32 - injector timing group 0
	bra	L886b
;
L8862:	bset	L0059 %00010000 ; signal we are at or above 610 RPM now....
;
; We are going to look-up next what is the optimumn injector timing for
;  this particular RPM.   The output of the table will point to one of the
;  timing groups at Lff20.  The value stash into L0007w will later be scaled.
; L0013w is the major index we got when we were looking up the Fuel requirements
; It is derived from the Lf027 rpm table and will be the index into this one.
; L0011w was the fractional component of the same lookup.....
;
L8865:	ldx	#Lf237		; point to optimum injector timing table
	jsr	Ld93d		; look it up
L886b:	staa	L0007w		; stash injector timing group for later
;
; .............................................................................
; Lets check out the Rev Limiter next
;
	ldx	#Lff80		; point to the timing period table (RPM's)
	ldab	L00b2		; get Rev Limiter value
	cmpb	#5000/250	; below 5000 rpm ?
	bcc	L887c		; nope
	ldab	#5000/250	; no lower than 5000 please
	stab	L00b2		; stash new rev limiter value
	bra	L8884
;
L887c:	cmpb	#9500/250	; over 9500 rpm ?
	bls	L8884		; nope
	ldab	#9500/250	; 9500 max
	stab	L00b2
L8884:	subb	#5000/250	; make base zero
	lslb			; *2 - words
	abx			; point to timing period for specified RPM
	ldd	$00,X		; get the rev limiter timing period limit
	cpd	L003e		; we beyond the rev limiter period ?
	bls	L88bd		; nope - current period longer than limit period
	brset	L0059 %00100000 L88b0 ; we are still in the process of shutdowm
	ldd	$04,X		; get the 500 RPM higher timing period
	cpd	L003e		; are we there yet ?
	bhi	L88b0		; yes - time to shut her down
;
; Motor is turning faster than the Rev Limit but not by more than 500 RPM
;  Start reducing power to slow it down...
;  Increase Fuel by 33% and pull the Spark back 12 degrees.
;
	ldx	L0004w		; get computed injector pulse width
	ldab	Lf511		; increase it by 33%	  172/128 = 1.34375
	jsr	Ldbe9		; D = IX * (B/128)
	std	L0004w
	ldaa	L0006w		; get spark
	ldab	Lf512		; Soft Spark Rev Limiter Spark Modification.
				; reduce it by 12 degrees
	jsr	Ldbc8		; adjust the spark advance
	staa	L0006w		; re-stash in work
	bra	L88c0
;
; Motor is turning more than 500 RPM faster than the Rev Limiter set point.
;  Shut it down NOW !
;
L88b0:	bset	L0059 %00100000 ; signal rev limiter is shuting the motor down
	clra			; set Fuel required to zero
	clrb
	std	L0004w		; put into temp work stash
	jsr	Ld47e		; convert fuel required into a pulse width
	jmp	L8bac		; jump to end
;
; Motor is slower than the Rev Limiter set point...
;
L88bd:	bclr	L0059 %00100000 ; clear rev limit shutdown flag
L88c0:	brset	L0001 %01000000 L88c6 ; WOT !
	bra	L88db		; could be closed or partial throttle
;
; WOT ...........
;
L88c6:	ldab	L0003		; get TH2O - Water Temperature
	cmpb	Lf589		; Minimum Coolant Temp for WOT Enrichment Enable
				; cooler than 120 degrees ?		140
	bls	L88db		; yes
;
; L0013w is the major index we got when we were looking up the Fuel requirements
; It is derived from the Lf027 rpm table and will be the index into this one.
; L0011w was the fractional component of the same lookup.....
;
	ldx	#Lf207		; point to WOT fuel modifier vs RPM
	jsr	Ld93d		; look modifier
	ldx	L0004w		; get current calculated fuel
	jsr	Ld8a5		; apply WOT modifer	D = (A*IX)/256
	lsld			; times 2 to remove the base 128 modiferir
	std	L0004w		; replace fuel
;
L88db:	ldab	L0015		; get the current revolution counter
	beq	L88e5		; the motor has turned more than 255 revs
	bclr	L005f %10000000 ; signal not in high speed high vacuum condition
	jmp	L8a2b		; jump way ahead
;
; The motor has turned more than 255 revolutions.......
;
L88e5:	bclr	L005f %01111111 ; clear most condition flags
;
; If deceleration starts above this RPM the allow fuel cutoff...
;
	ldab	L0042		; get timing_period / 16
	cmpb	L0018		; rpm below TH2O indexed trip point ?
	bcc	L88f3		; yes
	bset	L005f %01000000 ; signal above - allow cutoff
	bra	L88fa
;
; check if we are slower than the dashpot rpm.....
;
L88f3:	cmpb	L0017		; at or above dashpot rpm ?
	bls	L88fa		; yes - above
	bset	L005f %00100000 ; signal slower
;
; check if we are over 7,324 rpm.......

L88fa:	ldd	L003e		; get the current timing period
	cpd	Lf4db		; Upper RPM Threshold for Cut Off by Pressure
				; Under 7,324 RPM ?	       (256 - 7,324 RPM)
	bcc	L8907		; yes
	bset	L005f %00010000 ; signal over 7,324 rpm
	bra	L8912
;
; check if we are under 3,662 rpm......

L8907:	ldd	L003e		; current timing period
	cpd	Lf4dd		; Lower RPM Threshold for Cut Off by Pressure
				; At or Above 3662 RPM ?    512 - 3,662 RPM
	bls	L8912		; yes
	bset	L005f %00001000 ; signal slower
;
; Check for being under some kind of load.  If the current vacuum is lower
;  than our highest vacuum stash then signal so.  Lower vac (0"<<) means more
;  Load.....
;
L8912:	ldab	L0014		; get lowest MAP ADC (highest VAC) ever read
	addb	Lf4df		; 1
	if	not mis42x
	bcc	L891b		; of coarse it will never roll
	ldab	#$ff		; mis42:
	endif
L891b:	cmpb	L002a		; compared to average MAP ADC value
	bcc	L8924		; we are under very light load (high vac >>27")
	bset	L005f %00000100 ; signal under some load
	bra	L8934
;
; Check for being under a No Load condition.  Current Vac is higher than
;  our store highest reading....
;
L8924:	ldab	L0014		; lowest MAP ADC (highest VAC) ever read
	addb	Lf4e0		; 1
	if	not mis42x
	bcc	L892d		; mis42:
	ldab	#$ff
	endif
L892d:	cmpb	L002a		; compare to average MAP ADC readings
	bls	L8934
	bset	L005f %00000010 ; signal under no Load
;
; If the high speed/high Vac bit (1xxxxxxx) has been set by the Dist Trigger
;  interrupt handler then acknowledged it here.
;
L8934:	brclr	L005f %10000000 L893b ; not in high speed high vacuum condition
	bset	L005f %00000001 ; acknowledge high speed condition
;
L893b:	brclr	L0058 %00100000 L8986 ; not in somekind of fuel cutoff situation
	brset	L005f %00100000 L894e ; slower than TH2O set dashpot rpm
	brset	L0001 %10000000 L894e ; partial throttle !
	brset	L0001 %01000000 L894e ; WOT !
	jmp	L8a05		; throttle plates are closed
;
; Slower than dashpot rpm or partial/WOT condition......
;
L894e:	brset	L005f %00001000 L8959 ; slower than 3,662 rpm
	brset	L005f %00000100 L8959 ; we are under some Load
	jmp	L8a05		; faster than 3,662 and No Load
;
; Slower than dashpot rpm or partial/WOT condition,
;  and slower than 3,662 rpm or under some Load......
;
L8959:	bclr	L0058 %00100000 ; clr in a fuel cutoff situation
	bset	L0058 %00001000 ; signal medium load/rpm condition
	brset	L005f %00010000 L896a ; turning faster than 7,324 rpm
	ldaa	Lf4e9		; 6 - seed counter
	staa	L0016
	bra	L896f
;
; Turning faster than 7,324 rpm...........
;
L896a:	ldaa	Lf4ea		; 64 - seed counter
	staa	L0016
;
; Faster than 7,324 rpm
;	- or -
; (Under 3,662 rpm or under 7,324 rpm) and under some Load
;
L896f:	brset	L005f %00010000 L8978 ; turning faster than 7,324 rpm
	ldaa	Lf4e8		; +4%	133/256*2
	bra	L897b		; slower - bump Fuel a little
;
; Turning faster than 7,324 rpm - turn Off all Fuel.....
;
L8978:	ldaa	Lf4ed		; Fuel Enrichment at Exit from Cut-Off
				; 0 - will zero L0004w and shut off motor...
;
L897b:	ldx	L0004w		; get current Fuel
	jsr	Ld8a5		; modify it by B	D = (A*IX)/256
	lsld			; * 2 - 128 based modifier
	std	L0004w		; replace current Fuel
	jmp	L8a2b		; jmp ahead....
;
L8986:	brclr	L0058 %00010000 L89b1 ; not in fuel reduction situation
	brset	L005f %00000001 L89a2 ; in high speed high Vac condition
	brclr	L005f %01000000 L8996 ; rpm below fuel cutoff threshold
	brclr	L0001 %11000000 L899e ; throttle plates are closed
L8996:	brclr	L005f %00010000 L89ab ; turning slower than 7,324 rpm
	brclr	L005f %00000010 L89ab ; we are under some kind of Load
L899e:	ldaa	L0016		; counter down to zero ?
	bne	L89ae		; nope
;
; RPM above fuel cutoff, throttle plates closed and counter = zero
; Faster than 7,324 and under No Load condition and counter = zero
; In a high speed high vacuum condition.
;
L89a2:	bset	L0058 %00100000 ; signal in a fuel cutoff situation
	bclr	L0058 %00010000 ; clear this fuel reduction flag ??????
	jmp	L8a05
;
L89ab:	bclr	L0058 %00010000 ; clear this fuel reduction flag ?????
L89ae:	jmp	L8a2b		; jmp ahead
;
L89b1:	brclr	L0058 %00001000 L89e2 ; not in medium rpm/load situation
	brclr	L005f %01000000 L89bd ; rpm below fuel cutoff threshold
	brclr	L0001 %11000000 L89c5 ; throttle plates are closed
L89bd:	brclr	L005f %00010000 L89d2 ; turning slower than 7,324 rpm
	brclr	L005f %00000010 L89d2 ; we are under somekind of Load
;
; Above fuel cutoff threshold and throttle plates closed.
; Faster than 7,324, and not under load
;
L89c5:	bclr	L0058 %00001000 ; not in medium rpm/load situation
	bset	L0058 %00010000 ; signal another fuel reduction situation
	ldaa	Lf4e6		; 6 - seed counter
	staa	L0016
	bra	L89d9
;
; Slower than 7,324 rpm or under some Load
;
L89d2:	ldaa	L0016		; counted down yet ?
	bne	L896f		; nope
	bclr	L0058 %00001000 ; not in medium rpm/load situation
L89d9:	bclr	L005f %10000000 ; clear high speed high vacuum condition flag
	bclr	L005f %00000001 ; clear Calibration acknowledge signal also
	jmp	L8a2b		; jmp ahead
;
L89e2:	brclr	L005f %00000001 L89eb ; Not in high speed high Vacuum condition
;
; In high speed high vacuum condition
;
	bset	L0058 %00100000 ; signal in a fuel cutoff situation
	bra	L8a05
;
L89eb:	brclr	L005f %01000000 L89f3 ; rpm below fuel cutoff threshold
	brclr	L0001 %11000000 L89fb ; throttle plates are closed
L89f3:	brclr	L005f %00010000 L8a03 ; turning slower than 7,324 rpm
	brclr	L005f %00000010 L8a03 ; we are under somekind of Load
L89fb:	ldaa	Lf4e6		; 6 - seed counter
	staa	L0016
;
; Not in high speed high vacuum situation and.....
;  RPM above fuel cutoff threshold and throttle closed or ....
;  Faster than 7,324 rpm and under no load
;
	bset	L0058 %00010000 ; signal fuel reduction situation ?????
L8a03:	bra	L8a2b		; jmp ahead
;
L8a05:	brclr	L005f %00010000 L8a16 ; turning slower than 7,324 rpm
	ldaa	L002a		; get average of last two MAP ADC readings
	tst	L0014		; zero now ?
	beq	L8a14		; yes - use this average then
	cmpa	L0014		; stash lower than current MAP ADC ?
	bcc	L8a16		; yes
L8a14:	staa	L0014		; stash lowest MAP ADC (highest VAC) ever
L8a16:
	if	not mis48x
	ldaa	L0006w		; get work Spark Angle
	ldab	Lf4f9		; Static SA during Cut-Off
				; 0 - min spark angle allowed
	suba	Lf4f7		; SA decrement during Cut-Off		0
mis48:	bcs	L8a23		; Never take this branch
	cba			; A-B  B=0 so A-0 always NC
	bcc	L8a24		; will always take this branch
L8a23:	tba			; would have set min spark angle
L8a24:	staa	L0006w		; stash new work Spark Angle
	endif
;
	ldaa	Lf4e7		; Injector Phase during Cut off
				; 96 - injector timing Group 2
	staa	L0007w		; stash for later
;
L8a2b:	brclr	L0058 %01000000 L8a67 ; haven't made it thru Calibration Yet
	ldaa	L0006w		; get current work spark angle
	cmpa	L0027		; compare it to the current Spark Angle
	bls	L8a67		; current is same or larger
	ldab	Lf4f4		; 1
	brclr	L0058 %00001000 L8a41 ; not in mediumn rpm/load situation
	ldab	Lf4f3		; 1 - .25 degrees
	bra	L8a50
;
L8a41:	ldaa	L0042		; timing_period / 16
	cmpa	L0061		; compare to Target Idle RPM
	bls	L8a50		; Faster than or Equal to Target Idle RPM
	ldaa	Lf4f5		; 6
	mul			; D=A*B  D=6*1	D=6   1.5 degrees
	tsta			; overflow ?
	beq	L8a50		; nope
	ldab	#$ff		; 255 max
L8a50:	ldaa	L0027		; get current Spark Angle
;
	if	not mis39x
	tst	L001f		; this stash is always zero	mis39:
	bne	L8a65		;  so it will never take this branch ?????
	endif
;
	aba			; increase spark
	bcc	L8a5c		; didn't overflow
	ldaa	#$ff		; 255 max
L8a5c:	cmpa	L0006w		; compare to our work Spark Angle
	bcc	L8a67		; increased current larger so don't store
;
	if	not mis39x
	ldab	Lf4f6		; Phase counter for Lf4f4 Updating	0
	stab	L001f		; mis39:
	endif
;
L8a65:	staa	L0006w		; stash new Spark Angle (work stash)
L8a67:	brclr	L0058 %01000000 L8a6b ; haven't made it thru Calibration yet
L8a6b:	ldab	L0003		; get TH2O - Water Temperature
	ldx	#Lf197		; on coolant transient fuel mod table
	jsr	Ld9f6		; lookup adjusted value
	tab			; results into B
	clra			; make word
	xgdx			; into IX
	ldab	L00ad		; get Transient Fuel Modifier
	jsr	Ldbe9		; D = IX * (B/128)
	tsta			; overflow ?
	beq	L8a80		; nope
	ldab	#$ff		; 255 max
L8a80:	stab	L0019		; stash TH2O adjusted Transient Fuel Modifier
	ldab	L0003		; get TH2O - Water Temperature
;
	if not mis7x
	ldx	L007c		; get warmup timer
	cpx	Lf576		; has it been bumped yet ?	0000
mis7:	bcc	L8a90		; will always take this jump ! ????????

; Make no different if above jmp is taken or not because both tables
;  are the same.... !!!!!!
	ldx	#Lf187
	bra	L8a93
	endif
;
L8a90:	ldx	#Lf177		; on coolant temp Cold Start Fuel modifiers
L8a93:	jsr	Ld9f6		; lookup adjusted value
	tab			; into B
	clra			; make word
	subb	#$40		; -64
	bhi	L8a9f		; didn't go below zero
	clrb			; yep
	bra	L8aa5
;
L8a9f:	xgdx			; into IX
	ldab	L00ac		; get Cold Start Fuel modifier
	jsr	Ldbe9		; D = IX * (B/128)
L8aa5:	addd	#$0040		; +64
	tsta			; overflow ?
	beq	L8aad		; nope
	ldab	#$ff		; 255 max
L8aad:	stab	L001a		; stash TH2O adjusted Cold Start Fuel
;
; look-up dashpot trip rpm....
;
	ldab	L0003		; get TH2O - Water Temperature (adjusted)
	ldx	#Lf217		; on dashpot rpm vs TH2O table
	lsrb			; / 2
	lsrb			; / 4
	lsrb			; / 8
	lsrb			; / 16
	lsrb			; / 32
	adcb	#$00		; one more if last bit out was a one
				;  This offsets the divide by 32 by 16
	cmpb	#$07		; max at 8 entries
	ble	L8ac1		; ok
	ldab	#$07
L8ac1:
	if	not L6000_skip
	pshb			; save index
	endif
;
	abx			; point to rpm
	ldaa	$00,X		; get it
;
	if	not L6000_skip
	ldab	L0003		; get TH2O - Water Temperature
	cmpb	Lf685		; COOL threshold for TABMIN offset app.
				; below 120 degrees ?			140
	bcs	L8ada		; yes - use Lf217 table value then
	ldab	L6000		; read the PAL status (L9112D)
	bitb	#%00000100	; J1-21 pulled high - Air Conditioner On ?
	bne	L8ada		; no - use table value
	suba	Lf4e1		; less 575 rpm				23
	bcc	L8ada		; didn't go below zero
	ldaa	#$00		; zero min
	endif
;
L8ada:	staa	L0017		; stash new dashpot threshold rpm
;
	if	not L6000_skip
	pulb			; get TH2O index back
	endif
;
	ldx	#Lf21f		; on RPM vs TH2O
	abx			; point to item
	ldaa	$00,X		; get it
;
	if	not L6000_skip
	ldab	L0003		; get TH2O - Water Temperature
	cmpb	Lf685		; COOL threshold for TABMIN offset app.
				; below 120 degrees ?			140
	bcs	L8af8		; yes - use it as is
	ldab	L6000		; read the PAL status (L9112D)
	bitb	#%00000100	; J1-21 pulled high - Air Conditioner On ?
	bne	L8af8		; nope - use table value
	suba	Lf4e2		; 23
	bcc	L8af8		; didn't go below 0
	ldaa	#$00		; min 00
	endif
;
L8af8:	staa	L0018		; stash RPM (timing_period/16) vs TH2O
	ldx	L0004w		; get current Fuel
	ldaa	L001a		; get TH2O adjusted Cold Start modifier
	jsr	Ld8a5		; D = (A*IX)/256
	lsld			; * 2
	lsld			; * 4
	std	L0004w		; replace Fuel
	ldaa	L0015		; get the current revolution counter
	beq	L8b62		; counted down (more than 255 revolutions)
;
; If the motor has turned over less than 255 times add some extra Fuel
;  base on coolant temperature.....
;
	bset	L0059 %00000100 ; signal we are working with a 8x8 cell matrix
	ldab	Lf01b		; 7
	stab	L001bw		; 8 items in table
	ldab	L0003		; get TH2O - Water Temperature
	clra			; make word
	ldx	#Lf1a7		; point to coolant index table
	jsr	Ld907		; look up indexes
	stab	L0012w		; stash fractional component
	ldab	L001bw		; get major index of match item
	lslb			; * 2
	lslb			; * 4
	lslb			; * 8  rows
	stab	L0011w		; stash coolant component index
	ldab	Lf01a		; 7
	stab	L001bw		; 8 items in lookup table
	ldab	L0015		; get the current revolution counter
	clra
	ldx	#Lf1b7		; point to revolution index table
	jsr	Ld907		; look up indexws
	stab	L000bw		; stash fractional component
	ldab	L001bw		; get major revolution index
	addb	L0011w		; plus coolant
	ldx	#Lf1c7-8-1	; point into matrix			Lf1be
	jsr	Ld970		; look up
	bclr	L0059 %00000100 ; clear 8x8 cell matrix
	cmpa	#$10		; 16 - at ending edge of matrixes ?
	beq	L8b62		; yes - don't bother with it
	ldx	L0004w		; get current Fuel
	jsr	Ld8a5		; modify			D = (A*IX)/256
;
	if	not mis53x
mis53:	clc			; needless
	endif
;
	lsld			; * 2
	lsld			; * 4
	lsld			; * 8
	bcc	L8b57		; didn't overflow
	bset	L0059 %01000000 ; signal Fuel Calculation overflow
	ldd	#$ff00		; limit
	bra	L8b60		; satsh
;
L8b57:	lsld			; * 16
	bcc	L8b60		; didn't overflow
	lsrd			; shift back
	oraa	#%10000000	; replace lost bit
	bset	L0059 %01000000 ; signal Fuel Calculation overflow
L8b60:	std	L0004w		; stash new fuel requirements
L8b62:	jsr	Ld47e		; convert Fuel requirements into a pulse width
;				; Compute PW rate of change values
;				; L0011w contains rate of rich/lean change
;
; The following is a little weird.  It will always take the bra to L8b72
;  because $a0+$5f=$ff.  Below $5f (6v) and we get a zero, other wise it
;  will always be under or equal to $a0.....
;
	ldaa	L000a		; get Battery Voltage
	suba	#$5f		; less 6 volts (95 * .0625 = Batt_Volts)
	bcc	L8b6c		; battery is over 6 volts
	clra			; make 0 volts
L8b6c:
	if	not batt_mis
	cmpa	#$a0		;   (160 * .0625 = 10 volts) plus 6 lost above ?
	bls	L8b72		; will always take this jump
	ldaa	#$a0
	endif
;
L8b72:	ldx	#$0180		; 384 (256+128)
	jsr	Ld8a5		; D = (A*IX)/256
;				;
;				; D = ((BATT-6 volts) * 384) / 256
;				; D = (BATT-6) * 1.5
;				;
;				; B is the index into the next table....
	ldx	#Lf167		; lookup table
	jsr	Ld9f6		; lookup adjusted value
	staa	L000bw		; stash battery adjustment factor
	ldd	Lf01e		; 288 - Injection time offset (2 usec/bit)
	lsrd			; / 2 (144)
	lsrd			; / 4 (72)
	lsrd			; / 8 (36)
	addb	L000bw		; add in adjusted value
	bcc	L8b8c		; didn't roll
	ldab	#$ff		; max out at $ff
L8b8c:	stab	L0009		; stash battery correction factor
	clra			; make word
	lsld			; * 2
	lsld			; * 4
	std	L000bw		; hold
	brset	L0059 %01000000 L8ba1 ; had a Fuel calculation overflow already
	ldd	L000bw
	lsld			; * 8 is what we really want
	addd	L0004w
	bcc	L8baa		; didn't overflow - stash battery corrected
	bset	L0059 %01000000 ; signal Fuel calculation overflow
L8ba1:	ldd	L000bw		; get the times 4 value
	addd	L0004w		; plus current Fuel
	bcc	L8baa		; didn't overflow
	ldd	#$ffff		; max out
L8baa:	std	L0004w		; stash new injector pulse width value
L8bac:	ldab	L0007w		; get what injector timing group desired
	subb	#$20		; lets scale it now			32
	lsrb			; / 2
	lsrb			; / 4
	lsrb			; / 8
	stab	L0007w		; save for later
	brset	L0058 %01000000 L8bbd ; been thru Calibration once already
	ldab	#$18		; this will push us past end of 	24
	stab	L0029		;  ....the injector firing phase table
L8bbd:	brset	L0059 %01000000 L8bc6 ; Fuel calculations already overflowed
	ldd	L0004w		; get calculated pulse width
	lsrd			; divide it by two
	bra	L8bc8		; stash new inj pulse width
;
L8bc6:	ldd	L0004w		; get new injector pulse width from work stash
L8bc8:	pshb			; save new inj PW
	psha
;
; This looks to modify the calculated Fuel for a special purpose.
; This special purpose is when the injector timing changes we will use this
; calculated value for the transition injector firing.
; Most of the battery factor is backed out and then the MAP ADC reading is
; used to modifiy it further.	The higher the Vacuum (>>>27") the lower the
; ADC reading so this transition fuel will increase.
; Higher vacuum equals more Fuel.....
; If the MAP ADC was 128 it would be the same value as what is in L0048, but
; as vacuum goes up (>>>29") and the ADC goes down this value increases.....
; Centered arround 13" then.
;
	subd	L000bw		; back out *4 battery correction factor
	xgdx			; Fuel into IX
	clra
	ldab	L0000		; adjusted MAP ADC value
	subb	Lf4b8		; MAP offset for slope calc of Tj=Tj*f(MAP)
				; less ~ .5" of vacuum			4
	std	L000fw		; stash divisor
	xgdx			; get fuel back into D
	ldy	#$0009		; times 256  (2^8)
	jsr	Ld8d1		; D = (D / L000fw) * 256
	std	L000bw		; stash transition fuel
	pulx			; get new inj pulse width
	stx	L0048		; stash new injector pulse width

	if	not mis56x
	brclr	L0058 %00100000 L8beb ; not in a fuel cutoff situation
	ldx	#$0000		; set pulse width to zero
	bra	L8c03
;
L8beb:	brclr	L0058 %00010000 L8c03 ; not in fuel reduction situation ?????
mis66:	ldaa	Lf4e3		; 255
	jsr	Ld8a5		; D = (A*IX)/256
	std	L0048		; stash new injector pulse width
	ldx	L0048
	cpx	Lf4e4		; Minimum value of DJ1 during Cut-Off Entry   00
mis56:	bcc	L8c03		; will always take this jump
	ldx	Lf4e4		; Minimum value of DJ1 during Cut-Off Entry   00
	stx	L0048
	else
	brclr	L0058 %00100000 L8c03 ; not in a fuel cutoff situation
	ldx	#$0000		; set pulse width to zero
	endif
;
; IX	 - new injector pulse width
; L0006w - new spark angle
; L0007w - optimum injector timing group
; L0011w - lean/rich rate of change
; L000bw - Special MAP ADC adjusted Fuel PW used during Inj Timing changes
;
L8c03:	bclr	L0059 %01000000 ; clear any Fuel overflow condition flag
	ldab	L0007w		; get timing group
	ldaa	L0006w		; get new spark angle
	sei			; interrupts off
	stx	L0025		; stash Injectors Pulse Width
	staa	L0027		; stash Spark Angle
	stab	L0028		; stash optimum injector timing group
	ldaa	L0011w		; get rate of change amount
	staa	L007e		; stash lean/en-richen rate (pulse width time)
	ldd	L000bw		; get transition Fuel
	std	L004c		; stash Inj timing transition Fuel
	cli			; interrupts back on

	if	mis55x
	bset	L0058 %01000000 ; signal been thru Calibration
	else
	ldaa	L0058		; get flags
	oraa	#%01000000	; signal been thru Calibration atleast once
mis55:	eora	#%00000100	; toggle been thru Cal bit
	staa	L0058
	endif
;
	if	not mis18x
	ldab	L0015		; get revolution counter
	cmpb	Lf4a5		; Threshold Above which Pressure Transient
				;   is Inhibited.
mis18:	bhi	L8c37		; will NEVER take this branch ?????
	endif
;
	ldx	L003e		; get the current timing period
	cpx	Lf4a6		; Disable Transient Management above this RPM
				; Above 5,500 RPM ?	    (341 - 5,499 RPM)
;
	if	misc1
	bcc	L8c3c		; nope
	else
	bcs	L8c37		; yes
	ldab	L002f		; get current MAP ADC
	cmpb	Lf4a8		; Disable Transient Management above this MAP
				; lower than 255 (more than WOT ????) ? 255
	bcs	L8c3c		; yes - of coarse it always will be !!!
	endif
;
L8c37:	bset	L0056 %00000100 ; signal faster than 5,500 RPM
	bra	L8c3f
;
L8c3c:	bclr	L0056 %00000100 ; slower than 5,500 RPM
L8c3f:	ldaa	L0042		; timing_period / 16
	ldab	L0061		; get current Target Idle RPM
;
	if	not mis62x
mis62:	subb	Lf4a9		; 0
	endif
;
	cba			; cmp A,B     cmp RPM,Target_RPM
	bcs	L8c4e		; Turning too Fast (RPM > Target_RPM)
	bset	L0056 %00001000 ; signal slower than target RPM
	bra	L8c51
;
L8c4e:	bclr	L0056 %00001000 ; signal faster than target RPM
L8c51:
	if	not mis8x	; mis8:
	bclr	L00ba %00000010 ; ???? Never Used Anywhere !
	bset	L00ba %00000100 ; ???? Never Used Anywhere !
	endif
;
	jsr	Ldb07		; ckeck for any sensor errors
	ldaa	L00bc		; allow engine status to be sent to controller ?
	anda	#%00000111
	cmpa	#%00000001
	bne	L8ca3		; nope
	sei			; disable interrupts
	ldx	#L00c2		; point to serial buffer
	ldaa	L0027		; get Spark Angle
	staa	$05,X
	ldaa	L0025		; get Injector Pulse Width
	staa	$06,X
	ldaa	L0026		; ..... low byte
	staa	$07,X
	ldaa	L000a		; get Battery Voltage
	staa	$09,X
	ldaa	L005e		; get Mixture flag (LED control)
	staa	$0e,X
	ldaa	L00b9		; get any warning messages
	staa	$0f,X		; stash
	clra			; always clear last two locations
	staa	$10,X
	staa	$11,X
	ldaa	#$02		; return response
	ldab	#$12		; number of bytes to send
	std	L00c0		; stash first two bytes
	ldx	#register_base
	ldab	#%00001000	; signal we need to transmitt to controller
	stab	L00bc
	bset	$2d,X %10001000 ; enable the Serial Transmitter and Interrupt
	ldaa	#$7b		; $7B to the Serial Data register
	staa	$2f,X		; stash it
	ldab	L00c1		; get bytes to send
	addb	#$02		; plus two for header
	stab	L00bd		; stash characters do send
	ldd	#L00c0		; point to start of serial buffer
	std	L00be		; stash serial buffer index
	cli			; interrupts back on
L8ca3:	jsr	Ld6ea		; do any Dataset saving/restoring now
	jmp	L83af		; back to top of main run loop ................
;
; -----------------------------------------------------------------------------
;			   Distributor Trigger
;
; The Timer Input Capture 1 interrupt points to here........
; This interrupt has been promoted to the highest priority.
; This is the Input from the Distributor Trigger ..........
;
; The rising edged is the actual timing event,	with the falling edge used
; to determine the period of the event.  The narrow period is #1 cylinder
; being fired.	The narrow period (#1) is 75% of a normal firing period
; (amount of time  the input signal is high).
; The normal (non #1) duty cycle is ~55% with the high pulse width being wider.
; When the metal shutter is between the magnet and the hall effect sensor
; the output is high (5v) and with air between them the output is low (0v).
; The input signal from the Dsitributor sensor is in phase with the input
; to the 68HC11 IC1 pin 32.  There is an op-amp to give use some hysterisis
; that is fed into a schmidt trigger inverter.
;
;
;  PW = 1 / (RPM/15)	  RPM = 15 * (1/PW)
;
;   RPM        Period	count @2us	count @8us
;   200        .075	  37,500	  9,375
;  1000        .015	   7,500	  1,875
;  2000        .0075	   3,750	    937
;  5000        .003	   1,500	    375
;  7000        .00214	   1,071	    267
;
L8ca9:	ldx	#register_base
	bclr	$23,X %11111011 ; clear our interrupt flag
	ldy	$10,X		; get the count
	ldab	$21,X		; read TCTL2 - Edge control register
	andb	#%00110000	; look at our edge bits only
	cmpb	#%00100000	; is this the falling edge ?
	beq	L8cc4		; yes
	cmpb	#%00010000	; better be the rising edge then
	beq	L8cca		; yes - ok
	lds	#ram_base+$ff	; reset the stack to top of ram
	jmp	L812a		; big trouble - back to restart
;
; The Falling edge of the distributor trigger has just been detected.
;  This edge is Not the timing event.  We need it to determine the shutter
;  pulse width to detect #1 cylinder has just fired.
;
L8cc4:	brclr	$00,X %00000100 L8ccf ; input is truely low - continue
	bra	L8cce		; return
;
; The Rising edge has just been dectected.  This is the timing event.
;
L8cca:	brset	$00,X %00000100 L8ccf ; truely Hi - continue
L8cce:	rti
;
; We just got a valid Egde.  The Timer count is in IY....
;
L8ccf:	brset	L005b %01000000 L8cf8 ; Not the first time here
	sty	L0032		; stash the current timer count
	bset	L005b %01000000 ; signal been here before
	bset	L005d %00000100 ; signal first edge ever detected
	clr	L0031		; clear the main timer overflow counter
	brset	L005b %00000100 L8ce7 ; Above 4,500 RPM
	brclr	$21,X %00100000 L8cee ; This was the Rising Edge
L8ce7:	bclr	$21,X %00100000 ; setup to detect next Rising edge
	bset	$21,X %00010000
	rti
;
L8cee:	bclr	$21,X %00010000 ; setup next capture for the Falling Edge
	bset	$21,X %00100000
	rti			; done
;
	if	not mis9x
mis9:
L8cf5:	jmp	L9644		; trouble - do a restart - NOT FOUND ??????
	endif
;
; New timer count in IY.  Last count in L0031:L0032
;
L8cf8:	pshy			; put count into D
	pula
	pulb
	brclr	$25,X %10000000 L8d09 ; Did Not have Timer Overflow (main timer)
	tsta			; upper byte zero now ?
	bne	L8d09		; nope
	bclr	$25,X %01111111 ; clear the TOF Timer Overflow flag
	inc	L0031		; bump overflow count one
;
; At this point we have the new count in D and IY, and the last extended count
;  in L0031:L0032.   L0031 is the main timer overflow counter.
;
L8d09:	subd	L0032		; less last trigger count
	pshb
	ldab	L0031		; get the extended count
	sbcb	#$00		; less any carry from subtraction
	stab	L0031		; replace
	pulb
	lsr	L0031		; divide by 2
	rora
	rorb
	lsr	L0031		; divide by 4
	rora
	rorb
	tst	L0031		; better be zero
	beq	L8d2b		; good count
	clr	L0031		; clear overflow count
	sty	L0032		; stash new current count
	jmp	L9644		; trouble - do a restart
;
; This Pulse Width Period is in D in 8us units
; IY still has current pulse count.
;
L8d2b:	cpd	#$0068		; under 832us ??????
	bcc	L8d32		; nope
	rti			; - must have been a glitch
;
L8d32:	sty	L0032		; stash this count (counter value)
	std	L004aw		; stash this period (time)
;
	if	not mis10x
mis10:	bset	L005b %10000000 ; NEVER USED ????????????????
	endif
;
	brclr	L005b %00000100 L8d41 ; Below 4,500 RPM
	jmp	L8e55		; above 4,500 RPM
;
; Below 4,500 rpm....
; If we are below 4,500 then we have time to try to determine where the
; #1 shutter is.
;
L8d41:	brset	$21,X %00010000 L8d4b ; This was the Rising (Firing) edge
	ldd	L004aw		; get this period (time)
	std	L0036		; stash the high time period (time)
	bra	L8ce7		; setup next capture for Rising Edge and exit
;
; This was a Rising Edge event.  This event is the actual timing event.
;
L8d4b:	ldd	L004aw		; get this event time period
	addd	L0036		; plus falling edge event period (time high)
	bcc	L8d5c		; didn't overflow
	bclr	L005b %00000011 ; clear inj timing sync detector bits
	ldd	#$ffff		; too long of time
	std	L004aw		; max out event time period
	jmp	L8e55
;
; The total period of this event (high + low) time is in D
;
L8d5c:	ldy	L003c		; get the last timing period
	sty	L0040		; stash timing period two periods back
	ldy	L003e		; get the last current timing period
	bne	L8d6d		; wasn't zero so motor is turning
	std	L0040		; use this period as predicted period
	pshb			; also use this period to update the
	psha			;  the L003c last period stash
	puly
L8d6d:	sty	L003c		; stash new previous timing period
	std	L003e		; stash new current Timing period
	cpd	#$1000		; Above 458 RPM ?		(4096 - 458 RPM)
	bcs	L8d7b		; yes
	ldd	#$0fff		; limit at 458 RPM value
L8d7b:	lsld			; * 2
	lsld			; * 4
	lsld			; * 8
	lsld			; * 16
	staa	L0042		; stash timing period / 16		/256
;
; Put the high byte of the timing period directly into L0043 when we are above
;  610 RPM or bring what is already there closer to the current high byte value.
;
	ldab	L003e		; get the high byte of this timing period
	brset	L0059 %00010000 L8d9b ; stash the high byte now - Above 610 RPM
	clra
	ldab	L0043
	lsld			; * 2
	lsld			; * 4
	subb	L0043		; times 3
	sbca	#$00
	addb	L003e		; plus high byte of this timing period
	adca	#$00
	lsrd			; / 2
	lsrd			; / 4
;
	if	not mis2x
mis2:	tsta			; overflow into A ?
	beq	L8d9b		; nope - and never can be either !!!
	ldab	#$ff
	endif
;
L8d9b:	stab	L0043
;
; If we take the current timing pulse minus the period that occured two
;  pulses back plus the last one we can predict what the next one may be.
;
;  L0040 = (t) - (t-2) + (t-1)
;
;  If the motor was decelerating and the last three pulses were: .018 .019 .020
;    then (.020) - (.018) + (.019) = .021 - predicted next timing pulse width
;
	ldd	L003e		; get current timing period
	subd	L0040		; less period two periods back
	addd	L003c		; plus previous timing period
	std	L0040		; store predicted next timing period
;
; Bump the firing order sequencer........
;
	ldaa	L0044		; get the firing order sequencer
	inca			; point to next cylinder
	anda	#$07		; 0-7 only of coarse
	staa	L0044
;
	ldd	L0032		; get the timer count when trigger arrived
	std	L0034		; stash when the timing trigger got here
;
; The following must be used to detect the number one cylinder being fired.
;  The distributor shutter for number one is 75% the width of all the others.
;  There is one slight problem, the damn routine does NOT work.  Spent over
;  a week trying to figure it out.  Even simulated it and couldn't get it to
;  work.  Finally put a scope on the car.  One channel triggering off the
;  number one ignition wire and the the other on the number injector.  Every
;  time I fired up the engine the phase would be different between the two !
; The duty cycle of a normal period is 55% (55% high, 45% low).
;
mis3:	ldy	L004aw		; get the time the trigger pulse was low
	ldd	L003e		; get current timing period
;
; Compute a percentage of the total period.
; What we have here is	L004aw = PW/32 + PW/16	   ~4.6%
; This seems too narrow when later we try to determine if the difference between
; low and high periods (which is 10% of the total period) to a number that is
; ~9.2% calculated.  Most of the time it does not detect a normal duty cycle
; and bails.
;
	lsrd			; / 2
	lsrd			; / 4
	lsrd			; / 8
	lsrd			; / 16
	std	L004aw		; hold in work stash
	lsrd			; / 32
	addd	L004aw
	lsrd
	std	L004aw		; L004a = timing event * ~.0467
	ldd	L003a
	bpl	L8dd7		; positive now
	coma			; change signs
	negb
	sbca	#$ff
	subd	L004aw		; is L003a < 5% of the Timing Period ?
	bcs	L8ddf
	ldd	L004aw
	coma			; make a positive number
	negb
	sbca	#$ff
	std	L003a
	bra	L8ddf
;
L8dd7:	subd	L004aw
	bcs	L8ddf
	ldd	L004aw
	std	L003a
;
; At this point abs(L003A) < 5% Timing Period
; Its value is either the calculated one or 5% limited.....
;
L8ddf:	rol	L004bw		; L004aw = 10% Timing Period
	rol	L004aw
	xgdy			; D = Period_Low
	subd	L0036		; less the time when the input was high
	subd	L003a		; less accumulator
	pshb			; D = Period_Low - Period_High - L003a
	psha
	puly			; save in IY
;
; D and IY = the difference between the Period_low and Period_Hi - L003a
;
	bmi	L8e03		; The High period is shorter than the low so
;				;  it can not be the #1 shutter.....
;
	subd	L004aw		; is Duty Cycle difference < 10% Timing Period ?
	bcs	L8e0b		; yes - not narrow pulse
	subd	L0036		; less the time when the input was high
	bcc	L8e50		; unknown pulse - clear flags
;
; The next two addd's should be subd's.......
;
	addd	L004aw		; plus 10% Timing Period
	bcs	L8e43		; Narrow pulse detected
	addd	L004aw		; plus 10% more
	bcs	L8e43		; Narrow Pulse
	bra	L8e50		; unknown pulse - clear flags
;
; It is not the #1 shutter.  If the difference between hi/low is less than
;  10% of the total period then we don't know where we are at.
;
L8e03:	coma			; change signs
	negb
	sbca	#$ff
	subd	L004aw		; is Duty Cycle difference < 10% Timing Period ?
	bcc	L8e50		; yes - don't know where we are at then
L8e0b:	xgdy			; get the difference between pulses back
;
; 25% of delta-L003a
;
	asra			; divide by two but preserve the sign on the
	rorb			;  ....number
	asra			; / 4
	rorb
	addd	L003a		; plus what was there already
	std	L003a		; stash new accumulator
;
; At this point we have a non-narrow duty cycle detected
;
	bset	L005b %00000001       ; signal non-number one found
	brclr	L005b %00000010 L8e40 ; didn't find #1 last time - just continue
	bclr	L005b %00000010       ; clear #1 found lasttime flag
	brset	L005b %00010000 L8e2d ; check if we are in sync now
	bset	L005b %00010000       ; signal in sync for the first time
;
; To set the sequencer we have had to detected a non-narrow (#2) pulse, then
;  the narrow #1 pulse, followed immediately with another confirmed non-narrow
;  pulse (#8).	So when we set this we have just hit TDC #8.....
;
L8e26:	ldaa	#$02		; set the sequencer to #8
	staa	L0044		; reset firing order sequencer now
	jmp	L8eab		; read ADC and continue
;
L8e2d:	ldab	L0044		; get the current sequence value
	cmpb	#$02		; are we still in sync (#8) ?
	bne	L8e39		; nope - clear in sync bit and wait for next
	bset	L005b %00001000 ; signal that we are in sync
	jmp	L8eab		; read ADC and continue
;
L8e39:	brclr	L005b %00001000 L8e26 ; need to sync up now
	bclr	L005b %00001000 ; signal out of sync
L8e40:	jmp	L8eab		; read ADC and continue
;
L8e43:	brclr	L005b %00000001 L8e50 ; didn't get a normal pulse last time
	bclr	L005b %00000001 ; clear normal pulse found
	bset	L005b %00000010 ; signal narrow pulse found
	jmp	L8eab		; read ADC and continue
;
; If we got here then couldn't determine if it was a narrow pulse or a wide one
;
L8e50:	bclr	L005b %00000011 ; clear pulse type found flags
	bra	L8eab		; read ADC and continue
;
;
; ------- end of below 4,500 rpm only path -----------------------------------
;
; Above 4,500 RPM or we got an timing period overflow....
; When we are above 4,500 rpm we never set the edge control bits to detect
; the falling edge.  We are going so fast all we are detecting is the positive
; going firing edge....
;
L8e55:	ldd	L004aw		; just use this period as the timing period
	ldy	L003c		; get previous timing period
	sty	L0040		; stash 2 periods back timing period
	ldy	L003e		; get the current timing period
	bne	L8e68		; not zero so the motor is turning
	std	L0040		; use this period as predicted period
	pshb			; also use this period to update the
	psha			;  the L003c last period stash
	puly
L8e68:	sty	L003c		; stash new previous timing period
	std	L003e		; save new current timing period
	cpd	#$1000		; Above 458 RPM ?		(4096 - 458 RPM)
	bcs	L8e76		; yes
	ldd	#$0fff		; no lower tha 458 RPM please
L8e76:	lsld			; * 2
	lsld			; * 4
	lsld			; * 8
	lsld			; * 16
	staa	L0042		; stash timing period / 16		/256
;
; Put the high byte of the timing period directly into L0043 when we are above
;  610 RPM or bring what is already there closer to the current high byte value.
;
	ldab	L003e		; get high byte of timing period
	brset	L0059 %00010000 L8e96 ; stash high byte now - Above 610 RPM
	clra
	ldab	L0043
	lsld			; * 2
	lsld			; * 4
	subb	L0043		; times 3
	sbca	#$00
	addb	L003e		; plus high byte of timing period
	adca	#$00
	lsrd			; / 2
	lsrd			; / 4

	if	not mis1x
mis1:	tsta			; overflow in A ?
	beq	L8e96		; nope - never can be either
	ldab	#$ff
	endif

L8e96:	stab	L0043
;
; If we take the current timing pulse minus the period that occured two
;  pulses back plus the last one we can predict what the next one may be.
;
;  L0040 = (t) - (t-2) + (t-1)
;
;  If the motor was decelerating and the last three pulses were: .018 .019 .020
;    then (.020) - (.018) + (.019) = .021 - predicted next timing pulse width
;
	ldd	L003e		; get current timing period
	subd	L0040		; less period two periods back
	addd	L003c		; plus previous timing period
	std	L0040		; stash predicted next timing period
;
; Bump the firing sequencer....
;
	ldaa	L0044		; get the firing order sequencer
	inca			; point to next cylinder
	anda	#$07		; 0-7 only
	staa	L0044
;
	ldd	L0032		; get the timer count when the trigger arrived
	std	L0034		; stash when the timing trigger got here
;
; ----------------- end of over 4,500 rpm segment ----------------------------
;
; Common entry point (from under 4,500 RPM handler or over 4,500 RPM handler)
;
; Fire off the ADC..............
;
L8eab:	ldab	#%00010100	; MULTI On, read AN4 thru AN7
	stab	adc_control_reg
;
; Assure that we got an ignition coil firing in progress..........
;
	ldx	#register_base
	ldd	L003e		; get the current timing period
	cpd	#$2000		; over 229 RPM ?		(8192 - 229 RPM)
	bcs	L8ee7		; yes
;
; Motor must be cranking over trying to start (under 229 RPM).......
; Fire the coil Now !
;
	bclr	$22,X %00010000 ; clear the OC4I - disable IGN AMP interrupts
	bsr	L8ed5		; setup IGN AMP (SA) to fire the coil now
;
	if	mis57x
	bset	$20,X %00001100 ; Set the IGN AMP (SA) output line to go high
	else
	ldaa	$20,X		; get Timer Control 1			TCTL1
	oraa	#%00001100	; Set the IGN AMP (SA) output line to go high
	eora	Lf01d		; 0 - Ign Coil Driver Mode
	staa	$20,X		; update timer output compare pin usage
	endif
;
	ldd	$0e,X		; get the current timer count
	addd	#$4e20		; in 40ms   (20,000 * 2us)
	std	$1c,X		; new IGN AMP (SA) OC4 counter value
	bclr	$23,X %11101111 ; clear the OC4 interrupt flag
	bra	L8f23
;
; Setup the OC4 (IGN AMP SA) to output to go low which will fire the coil,
;  then force an immediate compare firing the coil.
;
L8ed5:	ldaa	$20,X		; get current timer control values	TCTL1
	oraa	#%00001000	; IGN output to zero after next compare cycle
	anda	#%11111011
	if	not mis57x
	eora	Lf01d		; 0 - Ign Coil Driver Mode
	endif
	staa	$20,X		; update register
	bset	$0b,X %00010000 ; force IGN output comparison NOW !
	bclr	$23,X %11101111 ; reset the IGN (OC4) interrupt flag
	rts
;
; Motor is turning over 229 RPM.......
;
L8ee7:	brset	L005b %00100000 L8f05 ; coil has been fired by SA amp (OC4)
;
; For some reason the coil wasn't fired !  Do it now......
;
	bsr	L8ed5		; setup IGN AMP handler to fire the coil now
;
	if	mis57x
	bset	$20,X %00001100 ; Set the IGN AMP output line to 1 next time
	else
	ldaa	$20,X		; get timer control state
	oraa	#%00001100	; Set the IGN AMP output line to 1 next time
	eora	Lf01d		; 0 - Ign Coil Driver Mode
	staa	$20,X		;
	endif
;
	ldd	#$0096		; 300 us
	addd	$0e,X		; plus current count
	std	$1c,X		; IGN AMP take action in 300us please
	bset	$22,X %00010000 ; enable the Ign Amp interrupt handler	    OC41
	bclr	$23,X %11101111 ; clear the OC4F flag - enableing IGN handler
	bra	L8f26		; join but don't signal new firing solution
;
; We had a normal ignition coil firing.....
;
L8f05:	ldaa	$00,X		; read Port A
	anda	#%00010000	; mask out PA4	(IGN SA output line)
	lsra
	lsra			; 00000x00
;
	if	not mis57x
	eora	Lf01d		; 0 - Ign Coil Driver Mode
	endif
;
	beq	L8f23		; low now - The coil is has been fired
;
	if	mis57x
	bset	$20,X %00001100 ; output high at next IGN AMP compare
	else
	ldaa	$20,X		; get timer control state
	oraa	#%00001100	; output high at next IGN AMP compare
mis57:	eora	Lf01d		; 0 - Ign Coil Driver Mode
	staa	$20,X
	endif
;
	bset	$22,X %00010000 ; enable IGN AMP interrupt flag
	ldd	#$0020		; in 64us
	addd	$0e,X		; get current counter
	std	$1c,X		; IGN AMP will change states in 64us
L8f23:	bclr	L005b %00100000 ; signal we have a new firing (SA) solution
;
L8f26:	ldx	#Lff40		; inj timing table
	ldab	L0044		; get the firing order sequencer
	abx			; point to pattern
	ldab	$00,X		; get it
	andb	L005a		; and in last
	stab	L005a		; replace
	ldx	#register_base
L8f35:	brclr	$30,X %10000000 L8f35 ; wait for the ADC to finish
	ldd	$31,X		; read ADC -->	A = AN4(O2)   B = AN5(TPS)
	staa	L0074		; stash O2 sensor reading
	ldaa	L0022		; get last ADC TPS count
	staa	L0057		; update last TPS ADC stash
	stab	L0022		; stash new current TPS value
	ldab	adc_result_adr3 ; read ADC -->	B = AN6(BATT)
	stab	L000a		; stash Battery Voltage
	bset	L0060 %00100000 ; turn/keep On the Fuel Pump
	ldaa	L0060
	staa	pal_4000_latch
	ldd	L003e		; get the current timing period
	cpd	#$01a1		; Below 4,500 RPM ?	       (417 - 4,496 RPM)
	bhi	L8f60		; yes
	bset	L005b %00000100 ; signal Above 4,500 RPM
	bclr	L005b %00000011 ; clear inj sync (shutter) detector bits
	bra	L8f69
;
; Below 4,500 RPM .......
;
L8f60:	bclr	L005b %00000100 ; signal below 4,500 RPM
	bclr	$21,X %00010000 ; set to capture Falling edge next time
	bset	$21,X %00100000
;
; Above 4,500 RPM .......
;
L8f69:	brset	L0058 %01000000 L8f70 ; been thru Calibration atleast once
	jmp	L950c		; allow dist ign interrupts - handler done
;
; Been running long enough to make it thru the Calibration routine atleast once.
;
L8f70:	bclr	$23,X %11111011 ; clear the IC1F - Distributor Trigger
	ldd	L003e		; current timing period
	cpd	#$03aa		; Below 2,000 RPM ?		(938 - 1999 RPM)
	bcc	L8f7e		; yes
	bclr	$22,X %00000100 ; disable Dist Trigger interrupt
L8f7e:	brclr	L0044 %00000001 L8f85 ;  #8 #3 #5 #2 just hit TDC ?
	jmp	L9124		; nope - #1 #4 #6 #7
;
; Every other firing period (#8 #3 #5 #2)
;
L8f85:	ldab	adc_result_adr4 ; read ADC -->	B = AN7(MAP)
	ldaa	L002f		; get last MAP
	staa	L004aw		; stash temp copy of last MAP ADC
	stab	L002f		; store new current MAP ADC count
	tba			; put a copy of the MAP ADC into A
;
; The below addition and rotate use the CY bit as the 9th bit so we won't
;  loose the hight bit using 8 bit registers.
;
	adda	L00b8		; plus last MAP ADC reading
	rora			; divide by 2
	staa	L002a		; stash an averaged ADC reading
	stab	L00b8		; stash new current MAP ADC also
	bset	L0058 %00000001 ; Signal we now have a new MAP ADC reading
				;  that the Calibration Loop can use....
	brclr	L0056 %00000100 L8fa5 ; Slower than 5,500 RPM
	clra
	staa	L004e		; clear transient fuel magnitude stashs
	staa	L004f		; don't need them at these high rpms
	jmp	L90d2
;
; Slower than 5,500 rpm......
;
L8fa5:	ldaa	L004e		; get the transeint fuel magnitude/decay value
	bne	L8fb0		; something in it - is it time to modify ?
	ldab	Lf4ad		; transient decay counter value
	stab	L0050		; re-seed counter
	bra	L8fe3
;
; working with a transient amount, is it time to modify it ?
;
L8fb0:	ldab	L0050		; get modify count
	decb			; bump
	beq	L8fb9		; counted down - start modifing
	stab	L0050		; update stash
	bra	L8fe3
;
; time to modify one of the transient magnitude values
;
L8fb9:	ldab	Lf4ad		; transient decay counter value 	13
	stab	L0050		; re-seed counter
	tsta			; is it positive ?
	bmi	L8fd2		; nope
;
; reduce current value by TH2O factor.....
;
	ldab	L0003		; get TH2O - Water Temperature
	ldx	#Lf4bb
	lsrb			; move the upper four bits down as an index
	lsrb
	lsrb
	lsrb
	abx
	ldab	$00,X		; get % modifier
	mul			; (val*TH2O_mod)/256
	staa	L004e		; replace
	bra	L8fe3
;
L8fd2:	nega			; change sign
	ldab	L0003		; get TH2O - Water Temperature
	ldx	#Lf4cb		; NOTE: Same as Lf4bb ??????
	lsrb			; move upper four bits down as an index
	lsrb
	lsrb
	lsrb
	abx
	ldab	$00,X		; get it
	mul			; (val*TH2O_mod)/256
	nega			; change sign back
	staa	L004e		; replace
;
; This is the second factor used in transient fuel response calculations.
;  It decays at a different rate....

L8fe3:	ldaa	L004f		; anything in it now ?
	bne	L8fee		; yep - check if time to modify
	ldab	Lf4b2		; 7
	stab	L0051		; seed counter
	bra	L900f
;
L8fee:	ldab	L0051		; get counter
	decb			; bump
	beq	L8ff7		; counted down - time to modify
	stab	L0051		; update stash
	bra	L900f
;
L8ff7:	ldab	Lf4b2		; 7
	stab	L0051		; seed counter
	tsta
	bmi	L9007		; negative
	ldab	Lf4b4		; 49 - 19%
	mul			; (val*49)/256
	staa	L004f
	bra	L900f
;
L9007:	nega			; change sign
	ldab	Lf4b3		; 49 - 19%
	mul			; (val*49)/256
	nega			; change sign back to negative
	staa	L004f
;
L900f:	ldaa	L0056		; get flags
	ldab	L0022		; get the ADC TPS count
	cmpb	L001c		; throttle plates opened ?
	bhi	L902f		; yes
	ldab	L002f		; get current MAP ADC count
	cmpb	L004aw		; did it change from the last MAP ADC value ?
	bls	L9021		; same or lower vacuum (Load increase)
	oraa	#%00000001	; signal vacuum increasing (Load decreasing)
	staa	L0056
L9021:	bita	#%00000001	; was vacuum increasing (Load decreasing) ?
	beq	L9033		; nope - still decreasing (Load increasing)
	ldab	L0052		; get what direction we changed PW last time
	bmi	L9033		; we made it shorter
	oraa	#%00000010	; signal made it longer or NC last time
	staa	L0056
	bra	L9033
;
L902f:	anda	#%11111100	; clear PW direction and throttle/MAP bits
	staa	L0056		; replace flags
L9033:	bita	#%00001000	; slower than Idle Target RPM ?
	bne	L9059		; yes
	bita	#%00000010	; was Pulse Width decreased last time ?
	bne	L9051		; no - either longer or no-change
	ldab	L0022		; get the ADC TPS count
	cmpb	L001c		; throttle plates opened ?
	bhi	L9059		; yes
;
; faster than target idle rpm, throttle closed, last PW change was negative
;
	ldab	L004e		; factor #1 negative ?
	bmi	L9048		; yes
	clr	L004e		; clear positive factor
L9048:	ldab	L004f		; factor #2 negative ?
	bmi	L9059
	clr	L004f		; clear positive factor
	bra	L9059
;
L9051:	clrb			; PW was longer last time so clear transients
	stab	L004e
	stab	L004f
	jmp	L90d2
;
L9059:	ldaa	L002f		; get current MAP ADC count
	suba	L004aw		; less previous MAP ADC count
	bmi	L909a		; manifold vacuum has increased (Load decreased)
	cmpa	Lf4aa		; less than a ~.25" differenece ?	2
	bcc	L9065		; nope - more
mis59c: clra			; yes - make like no change
;
L9065:	ldab	Lf4ab		; 56% (9/16)				9
	mul			; D = (current_MAP - last_MAP) * 9
	lsrd			; / 2
	lsrd			; / 4
	lsrd			; / 8
	lsrd			; / 16
;
	if	not mis58x
mis58a: tsta			; never be this large
	bne	L9074		; never will take this branch
	endif
;
	cmpb	#$7f		; over 127 ?
	bls	L9076		; nope
L9074:	ldab	#$7f		; max 127  (226 MAP ADC delta)
;
; B now contains a value porportional to the change in vacuum.	With the used
;  constants it is 56% (9/16) of the delta MAP ADC.
;
L9076:	ldaa	L004e
;
	if	not mis60x
mis60:	tsta
	endif
;
	bpl	L907e		; positive - need to check range limits
	aba			; add in MAP delta
	bra	L9085
;
L907e:	aba			; add in MAP delta
	cmpa	#$7f		; over 127 ?
	bls	L9085		; nope
	ldaa	#$7f		; limit
L9085:	staa	L004e
	ldaa	L004f
;
	if	not mis60x
mis60a: tsta
	endif
;
	bpl	L908f		; positive now - need to check bounds then
	aba			; add in MAP delta
	bra	L9096
;
L908f:	aba			; add in MAP delta
	cmpa	#$7f		; above 127 ?
	bls	L9096		; nope
	ldaa	#$7f		; 127 max
L9096:	staa	L004f
	bra	L90d2
;
; Manifold vacuum has increased (Load has decreased).....
;
L909a:	nega			; make differenece a positive number
	cmpa	Lf4aa		; less than ~.25" difference ?		2
	bcc	L90a1		; nope - more
mis59d: clra			; yes - make like no change
;
L90a1:	ldab	Lf4ae		; 56% (9/16)				9
				; DELTAF/DELTAM NEG CONV COEF, DELTA MAP SCALING
	mul			; (delta_ADC*9) / 16
	lsrd
	lsrd
	lsrd			; can never be larger than 143 (255*9)/16=143
	lsrd			; / 16
;
	if	not mis58x
mis58b: tsta			; never
	bne	L90b0		; never take this branch
	endif

	cmpb	#$7f		; over 127 ?
	bls	L90b2		; not likely (delta ADC would be 226 counts !)
L90b0:	ldab	#$7f		; max out
;
; B now contains a value porportional to the change in vacuum.	With the used
;  constants it is 56% (9/16) of the delta MAP ADC.
;
L90b2:	ldaa	L004e		; get current value
	bmi	L90b9		; negative now - need to check range limits
	sba			; less MAP delta
	bra	L90c0
;
L90b9:	sba			; less MAP delta
	cmpa	#$80		; above -128 ?
	bhi	L90c0		; nope
	ldaa	#$80		; min
L90c0:	staa	L004e
	ldaa	L004f
	bmi	L90c9		; negative now - need to check range limits
	sba			; less MAP delta
	bra	L90d0
;
L90c9:	sba			; less MAP delta
	cmpa	#$80		; above -128 ?
	bhi	L90d0		; nope
	ldaa	#$80		; min
L90d0:	staa	L004f
;
; Done with Transeint calculations.......

L90d2:	cli			; interrupts back on
;
	if	not mis39x
	ldaa	L001f		; never counts down because it is seeded with 0
	beq	L90da		; always takes this branch	mis39:
	deca
	staa	L001f
	endif
;
L90da:	brclr	L0058 %00011000 L90e6 ; not in fuel cutoff or medium rpm/load
	tst	L0016		; zero now (counted down ?)
	beq	L90e6		; yes
	dec	L0016		; bump counter ??????
L90e6:	ldab	L0015		; revolution counter at zero ?
	beq	L911a		; yes - don't decrement any further then
;
	if	not mis21x
	cmpb	Lf517		; 0
mis21:	bhi	L9104		; will always take this jump ????? !!!!!
;
; Never do any of the following code ever....................................
;
; Looks like what would have happened here is that every time the firing
;  sequencer was zero then bits in 005d would bump so that every 4th time
;  we would bump the revolution counter which would have been every 8 engine
;  revolutions...
;
	ldab	L0044		; get the sequencer
	bne	L911a		; not at zero
	brclr	L005d %00000110 L910f ; can't take because we set xxxxx1xx
	brclr	L005d %00000100 L9114 ; for same reason as above
	brclr	L005d %00000010 L910f
	bclr	L005d %00000110
	bra	L910a		; dec the revolution counter
	endif
;
; ...........................................................................
;
; Only bump the revolution counter once per engine revoltion.  Every four
;  timing events the lower two bits of the sequencer will be 00.
;
L9104:	ldab	L0044		; get the sequencer
	bitb	#%00000011	; low two bits zero (4th event) ?
	bne	L911a		; not yet
L910a:	dec	L0015		; bump revolution counter down one
;
	if	not mis21x
	bra	L911a
;
; ............ won't get here either .........................................
;
L910f:	bset	L005d %00000010 ; bump counter ?????
	bra	L911a
;
L9114:	bset	L005d %00000100 ; bump counter ?????
	bclr	L005d %00000010 ; bump counter ?????
	endif
;
; ............................................................................
;
L911a:	brset	L0058 %01000000 L9121 ; been thru Calibration atleast once
	jmp	L950c		; finish up and return from interrupt
;
L9121:	jmp	L923b		; got Calibration so we can join common
;
;==============================================================================
; Enter here on every other firing event.  (#1 #4 #6 #7)
;
L9124:	ldab	adc_result_adr4 ; read ADC -->	B = AN7(MAP)
	ldaa	L0030		; get last reading
	staa	L004aw		; stash last reading
	stab	L0030		; stash new current ADC reading
	tba			; put copy of MAP ADC reading into A
	addb	L00b8		; plus last reading
	rorb			; / 2
	stab	L002a		; stash averaged MAP ADC reading
	staa	L00b8		; stash a new current MAP ADC reading also
	brclr	L0056 %00000100 L913f ; turning Slower than 5,500 RPM
	clra
	staa	L004e		; don't need for hi speed stuff
	jmp	L91e3		; jump to PW timing
;
; below 5,500 RPM.....
;
L913f:	ldaa	L004e		; something in it ?
	bne	L914a		; yes - check if time to decay
	ldab	Lf4ad		; transient decay counter value 	13
	stab	L0050		; seed counter
	bra	L917d
;
L914a:	ldab	L0050		; get current count
	decb			; bump
	beq	L9153		; counted down - modify
	stab	L0050		; update stash
	bra	L917d
;
L9153:	ldab	Lf4ad		; transient decay counter value 	13
	stab	L0050		; re-seed counter
	tsta			; check sign
	bmi	L916c		; negative
	ldab	L0003		; get TH2O - Water Temperature
	ldx	#Lf4bb
	lsrb			; move upper four bits as an index
	lsrb
	lsrb
	lsrb
	abx
	ldab	$00,X		; get decay percentage
	mul
	staa	L004e
	bra	L917d
;
L916c:	nega			; change sign
	ldab	L0003		; get TH2O - Water Temperature
	ldx	#Lf4cb		; point to
	lsrb			; move upper four bits as an index
	lsrb
	lsrb
	lsrb
	abx
	ldab	$00,X
	mul
	nega			; make negative again
	staa	L004e
L917d:	ldaa	L0056		; get flags
	bita	#%00001000	; Slower than Target Idle RPM ?
	bne	L918c		; yes
	bita	#%00000010	; was last PW made shorter ?
	beq	L918c		; yes
	clrb
	stab	L004e		; clear transient factor #2 then
	bra	L91e3		; jmp ahead to PW timing
;
L918c:	ldaa	L0030		; get current MAP ADC reading
	suba	L004aw		; less last ADC reading
	bmi	L91bb		; manifold vacuum has increased (Load decrease)
	cmpa	Lf4aa		; more than ~.25" change in vacuum ?	2
	bcc	L9198		; yes
mis59:	clra			; nope - make like no change
;
L9198:	ldab	Lf4ab		; 56% (9/16)				9
	mul			; (Delta_ADC*9)/16
	lsrd			; / 2
	lsrd
	lsrd
	lsrd			; /16
;
	if	not mis58x
mis58:	tsta			; over 255 ? Never ! (255*9)/16 = 143
	bne	L91a7		; never will take this branch
	endif
;
	cmpb	#$7f		; was change in ADC greater than 226 ADC counts?
	bls	L91a9		; not likely
L91a7:	ldab	#$7f		; limit to 127
;
; B now contains a value porportional to the change in vacuum.	With the used
;  constants it is 56% (9/16) of the delta MAP ADC.
;
L91a9:	ldaa	L004e		; get current value
	bpl	L91b0		; it's positive so we will need to check range
	aba			; add in MAP delta
	bra	L91b7
;
L91b0:	aba			; add in MAP delta
	cmpa	#$7f		; 127 or under ?
	bls	L91b7		; yes
	ldaa	#$7f		; range limit
L91b7:	staa	L004e		; stash new amount
	bra	L91e3		; jmp ahead to PW timing
;
; Manifold vacuum has increased (Load decreased)
;
L91bb:	nega			; make a positive number
	cmpa	Lf4aa		; more than ~.25" change in vacuum ?	2
	bcc	L91c2		; yes
mis59a: clra			; nope - make like no change
;
L91c2:	ldab	Lf4ae		; 56% (9/16)				9
				; DELTAF/DELTAM NEG CONV COEF, DELTA MAP SCALING
	mul			; (delta_ADC*9) / 16
	lsrd
	lsrd
	lsrd
	lsrd
;
	if	not mis58x
mis58c: tsta			; never (143 max possible)
	bne	L91d1		; never take this branch
	endif
;
	cmpb	#$7f		; over 127 ?
	bls	L91d3		; not likely - would mean delta_ADC=225 counts !
L91d1:	ldab	#$7f		; max out
;
; B now contains a value porportional to the change in vacuum.	With the used
;  constants it is 56% (9/16) of the delta MAP ADC.
;
L91d3:	ldaa	L004e		; check sign
	bmi	L91da		; negative - need to check range then
	sba
	bra	L91e1
;
L91da:	sba
	cmpa	#$80		; above -128 ?
	bhi	L91e1		; nope
	ldaa	#$80		; max out
L91e1:	staa	L004e
;
; Done with Transeint fuel calculations....
;
L91e3:	cli			; interrupts back on
	ldx	L003e		; get the current timing period
	cpx	#$0177		; Above 5,000 RPM ?		(375 - 5000 RPM)
	bcs	L9235		; yes
	ldaa	L0015		; get revolution counter
	bne	L9235		; hasn't been 255 revolutions yet
	ldab	#$14		; point to last group of injector timings
	jsr	Ldc32		; got a match ?
	bmi	L9235		; not TDC #1, #4, #6 or #7 now
;				; We should have been if we are in sync !!!!!

	lsrb			; make 0-6 into 0-3 index
	sei			; interrupts off
	stab	L004bw		; stash transition injector index
	ldx	#Lff4a
	abx
	ldab	$00,X
	bitb	L005a
	beq	L9235		; should have been the same ??
	comb			; complement bit pattern
	andb	L005a		; clear position
	stab	L005a		; restore
	ldab	L004bw		; get the injector pair index (0-3)
	ldx	#L002b		; point to the MAP storage stash
	abx			; point to one
	ldab	$00,X		; get it
	ldaa	L002a		; get averaged MAP ADC reading
	sba			; has the vacuum (Load) gone Up ?	A=A-B
	bcs	L9235		; yes - current Vacuum is lower (closer to 0)
	cmpa	Lf4b7		; Delta MAP Threshold (Transient Strategy)
				; within 6 ADC counts  (aprox .5") ?
	bls	L9235		; yes
	ldx	L004c		; get previously Calculated transition Fuel
	jsr	Ld8a5		; D = (A*IX)/256
	xgdx			; results into IX
	ldaa	L001a		; get TH2O adjusted Cold Start Fuel modifier
	jsr	Ld8a5		; D = (A*IX)/256
	lsld			; * 2
	lsld			; * 4
	std	L0046
	clra
	ldab	L0009		; get the battery correction factor
	lsld			; * 2
	lsld			; * 4
	addd	L0046
	std	L0046		; fuel PW for Inj timing change transition
	bra	L923b		; done this group
;
; We don't (can't) need to change the injector timing this time trigger
;  event, so clear the transition amount in L0046...
;
; Above 5000 rpm.....
; Hasn't been 255 revolutions yet.....
; Load is increasing .......
; Optimum injector timing didn't match
;
L9235:	clr	L0046		; clear transition pulse width
	clr	L0046+1 	; low byte
;
; Entry from the alternate paths (every other ignition event).......
; If we are changing the injector timing the amount needed to ease the
; transition is in L0046 and the injector pair to fire is in L004bw.
;
L923b:
	if	not mis26x
	ldaa	L0076		; bump closed loop PW rate adjuster counter
	beq	L9242		; don't go past zero
	deca
	staa	L0076
	endif
;
L9242:	ldaa	L0074		; get the O2 Sensor ADC reading
;
	if	not mis11x
mis11:	psha			; why ????
	pula
	endif
;
	cmpa	Lf568		; lower than 447mv ?
	bls	L9250		; yes - lean
	bset	L005e %00001000 ; signal Rich (Green LED)
	bra	L9253
;
L9250:	bclr	L005e %00001000 ; signal Lean (Red LED)
L9253:	brset	L00b3 %01000000 L926b ; Closed Loop Fuel is Off !
	cmpa	Lf57e		; above 618 mv ?
	bhi	L926b		; yes - Rich
	cmpa	Lf57f		; lower than 302 mv ?
	bls	L9266		; yes - way lean
L9261:	bclr	L005e %01000000 ; clear only one LED on flag (both on/off)
	bra	L926e
;
L9266:
	if	not mis12x
	cmpa	Lf580		; Lambda sensor threshold
				; below 0 volts ???????
mis12:	bcs	L9261		; will never take this jump !!!!!!!!!!
	endif
;
L926b:	bset	L005e %01000000 ; signal only one LED is on
L926e:	ldaa	L0022		; get the ADC TPS count
	cmpa	L001c		; throttle plates opened ?
	bhi	L9278		; yes
	brclr	L0058 %00100000 L927d ; not in a fuel cutoff situation
L9278:	ldaa	Lf566	  ; (1) ; if no state change then allow closed loop
;				;  sub to calculate a new rate of change value.
	staa	L007b		; stash counter
;
; If we just changed states (rich-lean or lean-rich), bump the counter (L007b)
;  that signals the closed loop pulse width adjustment routine to calculate
;  a new PW rate of change value.  As long as it is not zero a new value is
;  calculated.	So that means that every time we got a state change it will
;  go to zero.	Also reset the counter that allows the rate of change value
;  to be further multiplied.
;
L927d:	brset	L005e %00001000 L928a ; Mixture is Rich
	brclr	L005e %00000100 L929d ; we already know that is Lean
	bclr	L005e %00000100       ; signal that we know it is Lean
	bra	L9291
;
L928a:	brset	L005e %00000100 L929d ; we already know it is Rich
	bset	L005e %00000100       ; signal that we know it is Rich
;
; Condition changed so bump count down....
;
L9291:	ldaa	L007b		; get current count
	beq	L9298		; at zero now - don't go past zero
	dec	L007b		; bump it
L9298:
	if	not mis26x
	ldaa	Lf586		; 10
	staa	L0076		; stash new closed loop rate multiplier count
	endif
;
L929d:	brset	L005e %10000000 L92a7 ; the Loop is Closed now...
	ldaa	L0079		; is the accumulator negative now ?
	bmi	L92ab		; yes
	bra	L92b3		; nope - positive
;
L92a7:	brclr	L005e %00001000 L92b3 ; LEAN mixture (Red LED On)
L92ab:	ldd	L0079		; get the accumulator
	addb	L0075		; adjust mixture modifier by current rate
	adca	#$00
	bra	L92b9
;
L92b3:	ldd	L0079		; get current mixture modifier accumulator
	subb	L0075		; reduce it
	sbca	#$00
L92b9:	std	L0079		; stash updated mixture accumulator
	bmi	L92c8		; negative now
	cpd	#$3e80		; over 16,000 ?
	bls	L92d3		; nope
	ldd	#$3e80		; limit it
	bra	L92d1
;
; mixture accumulator negative - check limits
;
L92c8:	cpd	#$c180		; over -16,000 ?
	bcc	L92d3		; nope
	ldd	#$c180		; limit
L92d1:	std	L0079		; stash range limited accumulator
;
L92d3:	brset	L0044 %00000001 L92ee ; on #1 #4 #6 #7 now
	ldaa	L0022		; get the ADC TPS count
	cmpa	L001c		; throttle plates closed ?
	bls	L92ee		; yes
	ldab	L0014		; lowest MAP ADC (highest VAC) ever read
	addb	Lf4df		; 1
	if	not mis42x
	bcc	L92e6		; mis42:
	ldab	#$ff
	endif
L92e6:	cmpb	L002a		; compared to averaged MAP ADC reading
	bcc	L92ee		; vacuum is higher (less Load)
	ldx	L0048		; get computed injector pulse width
	stx	L0025		; stash new Injector Pulse Width
L92ee:	brclr	L0056 %00000100 L92f5 ; Turning Slower than 5,500 RPM
	jmp	L936b		; faster
;
; Slower than 5,500 rpm.....
;
;   if ( L004e >= 0  and  L004f >= 0 ) {
;	D = ( L004e * 10 ) + ( L004f * 8 )
;   } elsif ( L004e >= 0  and  L004f < 0 ) {
;	D = ( L004e * 10 ) + ( L004f * 2 )
;   } elsif ( L004e < 0 )  and	L004f >= 0 ) {
;	D = ( L004e * 2 )  + ( L004f * 8 )
;   } elsif ( L004e < 0 )  and ( L004f < 0 ) {
;	D = ( L004e * 2 )  + ( L004f * 2 )
;   }
;
mis71:
L92f5:	ldaa	L004e		; get transient factor #1
	bmi	L931a		; negative now
	ldab	Lf4ac		; 10 - POSITIVE TRANSIENT GAIN	MULT COEF OF
				;	POS DMAPC TO CALC THE ADDITIVE INJ TIME
				;	CORR FOR MAP TRANSIENTS
	mul
	std	L0054w		; hold
	ldaa	L004f		; get second factor
	bmi	L930b		; it is negative
	ldab	Lf4b1		; 8 times -  MULT COEFF. OF POSITIVE DMAPC2 TO
				; CALC ADDITIVE INJ TIME CORR FOR MAP TRANSIENTS
	mul
	addd	L0054w		; plus 10*L004e
	bra	L9340		; join up
;
; L004e > 0  and  L004f < 0
;
L930b:	nega			; make positive
	ldab	Lf4b0		; 2 times - MULT COEFF OF NEG DMAPC2 TO CALC
;				;     SUBTRACTIVE INJ. TIME CORR FOR MAP TRANS
	mul
	coma			; changes sign back
	negb
	sbca	#$ff
	addd	L0054w		; plus (L004e*10)
	bcs	L9340		; went positive
	bra	L935e		; negative
;
; L004e < 0
;
L931a:	nega			; make positive for multiplication
	ldab	Lf4af		; 2 times
	mul
	coma			; change sign back
	negb
	sbca	#$ff
	std	L0054w		; hold
	ldaa	L004f
	bmi	L9333		; negative
	ldab	Lf4b1		; 8 times -  MULT COEFF. OF POSITIVE DMAPC2 TO
				; CALC ADDITIVE INJ TIME CORR FOR MAP TRANSIENTS
	mul
	addd	L0054w		; plus (L004e*2)
	bcs	L9340		; still positive
	bra	L935e		; negative
;
; L004f < 0
;
L9333:	nega			; change sign
	ldab	Lf4b0		; 2 times - MULT COEFF OF NEG DMAPC2 TO CALC
;				;     SUBTRACTIVE INJ. TIME CORR FOR MAP TRANS
	mul
	coma			; change sign back
	negb
	sbca	#$ff
	addd	L0054w
	bra	L935e		; still negative
;
; results of scaling were positive.....
;
L9340:	pshb			; into IX
	psha
	pulx
	ldaa	L0019		; get TH2O adjusted Transient Fuel Modifier
	jsr	Ld8a5		; D = (A*IX)/256
;
	if	not mis61x
mis61:	cmpa	#$3f		; below 16,127 ?
	bcs	L9350		; yes - always (max = 2286)
	ldaa	#$ff		; make negative
	bra	L9354
	endif
;
L9350:	lsld			; * 2
	lsld			; * 4
	std	L0052		; stash how much PW time increased
L9354:
	if	not mis52x
	clc			; mis52: - don't need to clear CY here
	endif
;
	addd	L0025		; plus current Injector Pulse Width
	bcc	L9396		; didn't overflow - stash new pulse width
	ldd	#$ffff		; turn wide open
	bra	L9396		; stash new injector pulse width
;
; results of scaling went negative....................
;
L935e:	coma			; make a positive value
	negb
	sbca	#$ff
	pshb			; into IX
	psha
	pulx
	ldaa	L0056		; get flags
	bita	#%00001000	; Turning Slower than Target Idle RPM ?
	beq	L9373		; no - faster
;
; turing faster than 5,500 rpm...
; turning slower than idle target rpm....
;
L936b:	clra
	clrb
	std	L0052		; clear how much we changed Pulse Width
;
	if	not mis63x
mis63:	std	L0054w		; un-necessary
	endif
;
	bra	L9398		; skip to PW timing stuff
;
; Turning Faster than Target Idle RPM.....
;
L9373:	ldaa	L0019		; get TH2O adjusted Transient Fuel Modifier
	jsr	Ld8a5		; D = (A*IX)/256
;
	if	not mis61x
	cmpa	#$3f		; below 16,127 ($3eff) ?
mis61a: bcs	L9380		; yes -
	ldaa	#$ff		; make ?????
	bra	L9382
	endif
;
L9380:	lsld			; * 2
	lsld			; * 4
L9382:	clc
	coma			; make a negative value again
	negb
	sbca	#$ff
	std	L0052		; stash how much we deceased PW
	tsta			; zero ?
	bne	L938f		; nope - modify
	tstb			; B zero also ?
	beq	L9398		; yes - do nothing
L938f:	addd	L0025		; plus current Injector Pulse Width
	bcs	L9396		; went below zero
	ldd	#$0000		; turn fuel off
L9396:	std	L0025		; stash new decreased Pulse Width
;
; Lets look into the optimum injector timing here...........
; We wont actually change the group we are in until there is some distance
;  from where we are at now to where we want to be.. Gives us some hysterisis
;  to keep from toggling excessively back and forth.
;
L9398:	ldaa	L0028		; get the calibrated optimum injector timing
	ldab	L0029		; get what injector firing group we are in
	sba			; get the difference
	bcc	L93a0		; positive
	nega			; change sign
L93a0:	cmpa	#$03		; time to change ?
	bcs	L93af		; nope - not enough difference yet
	tba			; A = the group we are in
	suba	L0028		; less where we want to be
	bcc	L93ad		; move upwards
	addb	#$04		; move 1 group forward wich will retard the
				;  the injector timing more (relative to TDC)
	bra	L93af
;
L93ad:	subb	#$04		; move 1 group upward
L93af:	stab	L0045		; stash group we are looking into
	jsr	Ldc32		; look for firing solution
	bpl	L93ca		; found one
	ldab	L0045		; get desrired group
	cmpb	L0029		; compared to last group
	bpl	L93c3		; last group behind
	ldab	L0029		; get current again
	jsr	Ldc32		; solution in this group ?
	bpl	L93ca		; yes
L93c3:	ldab	L0045		; get the group we wanted
	stab	L0029		; try for it next time
	jmp	L94ca		; go fire what we got
;
L93ca:	tba			; put a copy of solution into A
	lsrb			; make 0-3
	ldx	#Lff4a
	abx
	ldab	$00,X
	bitb	L005a		; in sync ?
	bne	L93c3		; nope - try next pass
	orab	L005a
	stab	L005a
	ldab	L0045		; get new group
	stab	L0029		; stash as current
	staa	L0045		; stash which injector pair to fire
	ldx	L003e		; get the current timing period
	cpx	#$0177		; Below 5,000 RPM ?		(375 - 5000 RPM)
	bhi	L93ea		; yes
	jmp	L9490		; Above 5,000 RPM
;
; Below 5,000 RPM...
;
L93ea:	ldaa	L0022		; get the ADC TPS count
	cmpa	L001c		; throttle plates closed ?
	bls	L941a		; yes
	ldaa	L0022		; get current ADC TPS reading
	suba	L0057		; less the last ADC reaading
	bcs	L9409		; throttle is moving towards the closed position
	cmpa	Lf49f		; Positive Delta Throttle Threshold
				; 4 (2% ??) - less than this rate of change ?
	bcs	L941a		; yes
	ldd	Lf4a1		; Fixed PW Adder if Throttle Transient	(1ms)
	addd	L0025		; plus current Injector Pulse Width
	bcc	L9405		; didn't overflow
	ldd	#$ffff		; max out at 262ms
L9405:	std	L0025		; stash new Pulse Width
	bra	L941a
;
; The last TPS ADC reading was larger than the current reading so the throttle
;  is moving towards the closed position....
;
L9409:	nega			; make difference a positive number
	cmpa	Lf4a0		; Negative Delta Throttle Threshold
				; less than 4 counts change ?
	bcs	L941a		; yes - do nothing
	ldd	L0025		; get current Injector Pulse Width
mis64:	subd	Lf4a3		; TJ Decreasing during Throttle Neg Transient
	bcc	L9418		; not too low
	clra			; injectors off
	clrb
L9418:	std	L0025		; stash new Pulse Width
;
; The below looks like it is trying to assure that the injector PW would fit
;  within a scaled timing_period ?????	If it doesn't then the only thing it
;  does is not set the bit in L005a.  It uses L0046 (transition fuel) as a
;  temporary work stash.  The original value is held in IX.
;
L941a:	ldab	L0045		; get which injector pair to fire
	lsrb			; adjust down to byte size (was 0-6)
	ldx	#L002b		; point to runing MAP stashs
	abx			; point to one
	ldab	L002a		; get the averaged MAP ADC reading
	stab	$00,X		; stash this average
;
	ldx	L0046		; hold transition fuel in IX
	ldd	L0025		; get Total Injector Pulse Width needed
	lsrd			; / 2
	std	L0046		; stash half of it here
	ldaa	L0029		; get what injector timing group we are in
	beq	L9452		; group zero (~3700 - up rpm)
	suba	#$04		; group 1 ?
	beq	L9448		; yes	     (~2200 - ~3700 rpm)
	suba	#$04		; group 2 ?
	beq	L9441		; yes	     (~1550 - ~2200 rpm)
	suba	#$04		; group 3 ?
	bne	L944e		; no - what group are we in then ?
;
; in injector timing group 3 (below ~1500-1600 rpm)
;			      3125 - 1172  - Timing period 600 rpm - 1600 rpm
;
	ldd	L003e		; get the current timing period
	lsld			; times 2
	bra	L9458		; 6250 - 2372
;
; in injector timing group 2 (1550-2200 rpm)
;			      1210-852
;
L9441:	ldd	L003e		; current timing period
	lsld			; times 2
	addd	L003e		; times 3
	bra	L9458		; 3630-2556
;
; in injector timing group 1 (2200-3700 rpm)
;			       852-507
;
L9448:	ldd	L003e		; current timing period
	lsld			; times 2
	lsld			; times 4
	bra	L9458		; 3408-2028
;
L944e:	stx	L0046		; replace transition fuel amount
	bra	L946e
;
; in injector timing group 0 (3700-6000 rpm)
;			       507-312
;
L9452:	ldd	L003e		; current timing period
	lsld			; times 2
	lsld			; times 4
	addd	L003e		; times 5	2535-1560
;
L9458:	addd	Lf4b9		; Security time step for injection on phase 6
	subd	L0046		; less 1/2 PW needed
	bcs	L944e		; too short a period
	stx	L0046		; replace transition fuel
	ldab	L0045		; get injector pair index (0-6)
	lsrb			; adjust to 0-3
	ldx	#Lff4a
	abx			; on it
	ldab	$00,X		; get bit pattern
	orab	L005a
	stab	L005a
;
L946e:	brclr	L005e %10000000 L9490 ; the Loop is Open.....
	brset	L005e %00001000 L9483 ; RICH mixture (Green LED on)
	ldd	L0025		; get current Injector Pulse Width
;
; Lean now - make richer by increasing the injector On time
;
	addb	L007e		; add some time to increase pulse width
	adca	#$00
	bcc	L948e		; didn't roll
	ldd	#$ffff		; max injector pulse width then
	bra	L948e
;
L9483:	ldd	L0025		; get current Injector Pulse Width
	subb	L007e		; narrow the pulse width
	sbca	#$00
	bcc	L948e		; didn't go below zero
	ldd	#$0000		; turn them off
L948e:	std	L0025		; stash new Pulse Width
;
L9490:	brclr	L005f %10000000 L949a ; not high speed high vacuum condition
	brset	L005f %00000001 L94b9 ; In high speed high vacuum condition
;				      ; This bit was acknowledged in Calibration
	bra	L94b2		; don't fire injector - pulse width --> 0
;
; If we are over 7,324 rpm and have a very high vacuum (closer to 29") then
; injector off and set L005f 1xxxxxxx.
;
L949a:	ldd	L003e		; get the current timing period
	cpd	Lf4db		; Upper RPM Threshold for Cut Off by Pressure
				; Under 7,324 RPM ?	       (256 - 7,324 RPM)
	bcc	L94b9		; yes
	ldab	L0014		; lowest MAP ADC (Highest VAC) ever read
	addb	Lf4e0		; 1
	if	not mis42x
	bcc	L94ab		; mis42:
	ldab	#$ff
	endif
L94ab:	cmpb	L002a		; compared to the averaged MAP ADC reading
	bls	L94b9		; lower vacuum (closer to 0) - fire injector
	bset	L005f %10000000 ; signal high speed high vacuum condition
L94b2:	ldd	#$0000		; injectors off
	std	L0025		; set Injector Pulse Width to zero
	std	L0046		; also clear any transition amount
L94b9:	ldab	L0045		; get injector pair index
	sei			; interrupts off
	ldx	#Lff38		; point to the 6840 timer's data registers
	abx			; point to the injector's timer address
	ldd	L0025		; get the current Injector Pulse Width
;
	if	not mis51x
mis51:	ldy	L0025		; IY also - why ??? - not used
	endif
;
	jsr	Lda7e		; fire the injectors
	bra	L94f3
;
;
L94ca:	brclr	L005f %10000000 L94d4 ; not high speed high vacuum condition
	brset	L005f %00000001 L94f3 ; In high speed high vacuum condition
	bra	L94ec		; don't fire injector - finish and RTI
;
; If we are over 7,324 rpm and have a very high vacuum (closer to 29") then
; injector off and set L005f 1xxxxxxx.
;
L94d4:	ldd	L003e		; get the current timing period
	cpd	Lf4db		; Upper RPM Threshold for Cut Off by Pressure
				; Under 7,324 RPM ?	       (256 - 7,324 RPM)
	bcc	L94f3		; yes
	ldab	L0014		; lowest MAP ADC (highest VAC) ever read
	addb	Lf4e0		; 1
	if	not mis42x
	bcc	L94e5		; mis42:
	ldab	#$ff
	endif
L94e5:	cmpb	L002a		; compared to the averaged MAP ADC reading
	bls	L94f3		; lower vacuum (closer to 0)
	bset	L005f %10000000 ; signal high speed high vacuum condition
L94ec:	ldd	#$0000		; zero pulse width - don't fire the injector
	std	L0025		; stash new Injector Pulse Width
	std	L0046		; also transition pulse width
;
; If we are changing the injector timing then L0046 will have the extra amount
;  needed to smooth the transition.
;
L94f3:	ldd	L0046		; need another inj firing to ease timing change
	beq	L950c		; nope
	brclr	L0044 %00000001 L950c ; even firing cycle - don't fire injector
	ldab	L004bw		; get which pair to fire (0-3)
	cli			; interrupts back on
	lslb			; address are words
	sei			; interrupts off
	ldx	#Lff38		; point to the 6840 timer's data registers
	abx			; point to the address of the Injector timer
	ldd	L0046		; get the transition pulse width
;
	if	not mis51x
mis51a: ldy	L0046
	endif
;
	jsr	Lda7e		; fire the Injectors
L950c:	ldx	#register_base
	bset	$22,X %00000100 ; allow Distributor Trigger interrupts again
	rti
;
; =============================================================================
; Timer Overflow interrupt entry point...  Will get here every 131ms.
;
L9513:	ldy	#register_base
	bclr	$25,Y %01111111 ; clear the Timer Overflow Flag (TOF)
	ldab	#%00010000	; MULTI On , read AN0 thru AN3
	stab	adc_control_reg
;
	if	not mis13x
mis13:	bclr	L005d %00001000 ; clr - Never Tested Anywhere ???????
	endif
;
	tst	L00bc		; any serial operations goining on ?
	beq	L9532		; nope
	bmi	L952f		; been a full period so abort any Serial ops
	bset	L00bc %10000000 ; set our serial watch dog bit
	bra	L9532
;
L952f:	clr	L00bc		; abort any serial operations
L9532:	ldaa	L0031		; get the current overflow count
	brset	L0001 %00000001 L9565 ; IAC out of 250ms banging mode
	cmpa	Lf494		; 1 sec - Time period to enable IAC motor
				; been over 1.05 seconds ?		7
	bls	L9565		; not yet
;
; Been just over a second with no starting actions so stop the IAC motor
;  handler from banging the IAC back and forth
;
	ldy	#register_base
	bset	L0001 %00000001 ; stop IAC from initial banging mode
;
; The below IAC values are what I see when the motor is cranking over
;  during starting.
;
	ldd	Lf466		; 6 msec, Actuation Duty Cycle Max Limit
	std	L0066		; 5.999ms IAC motor On time
	std	L006a		; 5.999ms IAC last motor On time
	ldd	Lf45c		; Nominal Period for VAE (IAC) Control Signal
	std	L0068		; 6.666ms IAC total period
	std	L006c		; 6.666ms IAC last total period
	ldd	timer_tcnt_reg	; get the current timer count
	addd	#$0019		; plus 50 us (25 * 2us)
	std	toc1_data_reg	; set OC1 timer - trigger IAC handler
	bclr	$23,Y %01111111 ; reset IAC (OC1) timer interrupt flag
	bset	$0d,Y %10000000 ; output a 1 when compare is finished
	ldaa	L0031		; get the overflow count back
L9565:	brclr	L005d %00000100 L956f ; We have never rec'd a dist trig edge
	cmpa	#$03		; over 393ms yet since a counter reset ?
	bls	L9580		; nope
	bra	L957d		; Fuel Pump Off and jump to top - restart
;
L956f:	cmpa	Lf509		; How long to wait before Fuel Pump Cutoff
	bls	L9580		; less than 3 seconds have passed
	brset	L0001 %00000001 L957d ; IAC out of initial banging mode
	cmpa	Lf494		; 1 sec - Time period to enable IAC motor
	bls	L9580		; will never take this because above Lf509 cmp
L957d:	jmp	L962b		; motor off - turn off fuel pump and restart
;
L9580:	inca			; bump the overflow counter
	staa	L0031		; stash current overflow count
L9583:	brclr	$30,Y %10000000 L9583 ; wait for ADC to finish.....
	ldx	#L0023		; point to MAT ADC stash
	ldaa	adc_result_adr3 ; read ADC -->	A = AN2(MAT)
	jsr	Ld8f0		; update ram stash
	ldx	#L0024		; point to COOL ADC stash
	ldaa	adc_result_adr4 ; read ADC -->	A = AN3(COOL)
	jsr	Ld8f0		; update ram stash
	brclr	L0058 %01000000 L95a6 ; haven't been thru Calibration yet
	ldx	L003e		; get the current timing period
	cpx	#$0218		; Below 3,500 RPM		(536 - 3498 RPM)
	bhi	L95a6		; yes
	rti
;
; We have NOT been running long enough to make it thru Calibration atleast
;  one time yet or if we have calibration data we are below 3,500 rpm
;
; The below counter is used in the min IAS% required calculations.......
;
L95a6:	brclr	L005c %00000010 L95b4 ; counter not active
	ldaa	L0072		; get idle activity counter
	inca			; bump it
	bne	L95b2		; hasn't gone past zero yet
	bset	L005c %00000001 ; yep - signal rolled thru zero
L95b2:	staa	L0072		; stash updated count
; .............................................................................
; Effect of mistake below - once 1xxxxxxx of L005c gets sets there is no
;  mechanism to clear it so the below code at most only gets executed once ever!
;
L95b4:	brset	L005c %10000000 L95d4 ; dashpot was zero !!!!!! mis41: *******
	ldd	L006e		; get the current dashpot counter
	beq	L95e7		; already counted down
	brset	L005c %01000000 L95c4 ; dashpot been modified before (only once)
	brclr	L0059 %00010000 L95e7 ; Below 610 RPM - only sees this one time
L95c4:	subb	Lf481		; DELTA Target Idle RPM DECR STEP (at CRANK)
	sbca	#$00
	bcc	L95cd		; didn't go below zero
	clra			; clear it
	clrb
L95cd:	std	L006e		; stash new dashpot value
mis40:	bset	L005c %01000000 ; signal dashpot been bumped
	bra	L95e7
; .............................................................................
;
L95d4:	brclr	L005c %00010000 L95e7 ; not in dashpot operation mode
	ldd	L006e		; get the dashpot counter
	beq	L95e7		; already counted down
	subb	Lf482		; 197
	sbca	#$00
	bcc	L95e5		; didn't go below zero yet
	clra			; yep
	clrb
L95e5:	std	L006e		; stash new dashpot counter value
L95e7:	brclr	L0059 %00010000 L961f ; Below 610 RPM
	ldaa	L0003		; get TH2O - Water Temperature (adjusted)
	cmpa	Lf565		; 60c Cool Threshold Lambda Control
				; over 140 degrees ?			153
	bhi	L95f6		; yes
	brset	L005e %00100000 L961f ; water was under 120 degrees
L95f6:	brset	L005e %00100000 L9601 ; water was under 120 degrees at start
;				      ;  so push timer to its max now
	ldd	L007c		; get timer count
	addd	#$0001		; bump one
	bcc	L9604		; didn't roll to zero
;
; Note: Once this timer hits $ffff it will stay there forever...
;
L9601:	ldd	#$ffff		; set to max
L9604:	std	L007c
	brclr	L00b3 %01000000 L960e ; Close Loop Fuel is On !
	brclr	L005e %01000000 L9611 ; both LEDs are either On or Off
L960e:	bclr	L005e %00100000       ; signal water over 140 degrees
L9611:	brset	L0058 %00000010 L961f ; water is hot / over 3 minutes
	ldx	Lf57c		; During this time Lf560 and Lf561 are Different
				; been over three minutes ?	1440*131ms
	cpx	L007c
	bhi	L961f		; not yet
	bset	L0058 %00000010 ; signal over 3 minutes
;
; This counter allows us to increase the lowest TPS ADC reading stash (L001d)
;  when it times out
;
L961f:	brclr	L0001 %00100000 L962a ; counter not enabled
	ldaa	L0021		; get counter
	beq	L962a		; stop counting at zero
	deca
	staa	L0021
L962a:	rti
;
; No ignition pulses - motor off - turn Off the Fuel Pump...
;
L962b:	bclr	L0060 %00100000 ; turn Off the Fuel Pump
	ldaa	L0060
	staa	pal_4000_latch	; do it
	ldaa	#cop_arm	; reset the COP watchdog timer
	staa	coprst_register
	ldaa	#cop_reset
	staa	coprst_register
	brset	L0058 %01000000 L9644 ; been thru Calibration atleast once
	jmp	L9583		; loop back to read ADC (MAT and COOL)
;
; Have NOT been running long enough to have made it all the way thru Calibration
;  atleast one time yet.....
;
L9644:	ldaa	#%00000101	; signal we have had a dist trig and
				;  pulse width > $8000
	staa	L005d
	bclr	$23,Y %11111011 ; clear IC1F - Ignition timer - Dist trigger
	lds	#ram_base+$ff	; reset the stack to top of ram
	jmp	L812a		; back to top of restart loop
;
; -----------------------------------------------------------------------------
;		     Ignition Amp Driver Interrupt Handler
;
; Timer Output Compare 4 interrupt entry point.....
;
; The Falling edge is the event that fires the ignition coil.  When the output
; is high the coil driver's (SA amp) output is pulling current thru the coil's
; primary to build the field.  Looking at the waveforms it is clear that this
; driver has some smarts in it.  It pulls maximun current thru the coil for
; only as long as it is needed to obtain the maximun magnetic field in the
; coil then reduces the current to keep the coil from over-heating.  At the
; falling edge from us the current path to ground is opened and the field
; collapses firing the plug.
; The output from the MCU is in phase with the outside world.  Our internal
; driver double inverts.
;
;
L9652:	ldx	#register_base
	bclr	$23,X %11101111 ; reset output compare flag
	bclr	$22,X %00010000 ; disable this interrupt
	ldaa	$20,X		; get current output control state
	anda	#%00000100	; look at OL4 bit
;
	if	not mis57x
	eora	Lf01d		; 0 - Ign Coil Driver Mode
	endif
;
	beq	L9667		; We just drove output Low  (Fired the Coil)
	jmp	L96f3		; We just drove it High     (recharge Coil)
;
; We just drove the output line to the SA amp Low, Firing the Coil.....
; Compute the dead time.
;
L9667:	bset	L005b %00100000 ; signal we just fired the coil
	ldd	L003e		; get current timing period
	cpd	#$0100		; At or Above 7,300 RPM ?	(256 - 7324 RPM)
	bls	L96ae		; yes
	cpd	#$0400		; Below 1,800 RPM ?	       (1024 - 1831 RPM)
	bhi	L9695		; yes
;
; between 1800 and 7300 RPM...
;
; Dead_Time = (Timing_Period/2) - (Timing_period/16) - .000588

	lsrd			; timing period / 2
	lsrd			; divided by 4
	std	L004aw		; stash for a bit
	ldd	L003e		; get the current timing period back again
	lsld			; times 2
	subd	L004aw
	subd	#$0126		; less .588ms
	addd	toc4_data_reg
	ldy	L003e		; period back again
	cpy	#$0139		; Above 6,000 RPM ?		(313 - 5990 RPM)
	blt	L96b4		; yes
	std	toc4_data_reg	; set new period
	bra	L96e6		; finish up
;
; Below 1,800 RPM.......
;
; Dead_Time = (Timing_Period / 4)  + (Timing_Period / 2) - 3.072ms
;
L9695:	cpd	#$1000		; Above 460 RPM ?		(4096 - 458 RPM)
	bcs	L969e		; yes
	ldd	#$0fff		; max out at the 460 RPM value
L969e:	std	L004aw
	lsld			; * 2
	addd	L004aw
	subd	#$0600		; -.003072 sec
	addd	toc4_data_reg
	std	toc4_data_reg
	bra	L96e6		; finish up
;
; At or Above 7,300 RPM........
;
L96ae:	ldd	#$0096		; .3ms
	addd	toc4_data_reg
L96b4:	std	L004aw
	bmi	L96d9		; hi bit set
	bita	#%11111100
	beq	L96ca
	ldd	#$0018		; 48us
	addd	timer_tcnt_reg	; plus the current timer count
L96c2:	subd	L004aw
	bcs	L96d2		; it rolled
	addd	L004aw
	bra	L96e3		; finish
;
L96ca:	ldd	#$0018		; 48us
	addd	timer_tcnt_reg	; plus the current timer count
	bpl	L96c2
L96d2:	ldd	L004aw
	std	toc4_data_reg
	bra	L96e6		; finish up
;
L96d9:	ldd	#$0018		; 48us
	addd	timer_tcnt_reg	; plus the current timer count
	bita	#%11111110
	bne	L96c2
L96e3:	std	toc4_data_reg
;
	if	mis57x
L96e6:	bset	$20,X %00001100 ; SA IGN Amp High next time - end of dead time
	else
L96e6:	ldaa	$20,X		; get current timer output control state
	oraa	#%00001100	; SA IGN Amp High next time - end of dead time
	eora	Lf01d		; 0 - Ign Coil Driver Mode
	staa	$20,X
	endif
;
	bset	$22,X %00010000 ; enable OC4 (IGN Amp) interrupts again
	rti			; done
; -------------------------------
; We just drove the output line to the SA amp High to recharge coil.
; When to fire the next cylinder is setup here.
;
L96f3:	brset	L005b %00100000 L9720 ; coil fired but we don't have a new
				      ;  timing value from the Dist Trigger
				      ;  handler - just return
	ldab	L0027		; get Spark Angle
	comb			; complement it because as this number gets
;				;  larger the time we spend high gets shorter
;				;  so we will fire sooner....
	ldaa	#$b6		; 182
	mul			; D = A * B   D = 182*B
	addd	#$4aa6		; 19,110
	ldx	L0040		; get the predicted next timing period
	jsr	Ld8a5		; D = (A*IX)/256
	lsld			; * 2
	lsld			; * 4
	addd	L0034		; + the tic-counter count of the timing trigger
	subd	#$0028		; 80us (40)
	std	toc4_data_reg
	ldx	#register_base
	ldaa	$20,X		; get current timer control state
	oraa	#%00001000	; force output low next time to fire the coil
	anda	#%11111011
;
	if	not mis57x
	eora	Lf01d		; 0 - Ign Coil Driver Mode
	endif
;
	staa	$20,X
	bset	$22,X %00010000 ; enable OC4 timer interrupts again
L9720:	rti			; done
;
; -----------------------------------------------------------------------------
;			  EEPROM Timer
;
; Timer Output Compare 3 interrupt entry point
;  Used as timer to program the EEPROM......
;
L9721:	ldx	#register_base
	clr	$3b,X		; return the EEPROM to normal read only mode
	bclr	$22,X %00100000 ; turn OC3 interrupts off
	bclr	$23,X %11011111 ; clear the output compare flag
	bclr	L005d %01000000 ; signal EEPROM timer finished
	rti
;
; -----------------------------------------------------------------------------
; Timer Output Compare 2 interrupt entry point
;  Used to drive the INJ-D driver....
;
;  If we get here assure that the output line stays Low for most of the
;   compare cycle (~130ms). This will turn the Injector Off.
;
L9730:	ldx	#register_base
	bset	$20,X %10000000 ; Force the output low at the compare count
	bclr	$20,X %01000000 ; This turns off the Injector the rest of
;				;  the time....
	bclr	$22,X %01000000 ; clear timer interrupt flag (disable interrupt)
	bclr	$23,X %10111111 ; clear output compare flag
	rti
;
; -----------------------------------------------------------------------------
;			Idle Air Motor - IAC
;
; Timer Output Compare 1 interrupt entry point - IAC
;
; Our output is inverted in our current driver.  When we are high, current is
; being pulled thru the IAC motor.  When current is being pulled thru the
; IAC motor more air is allowed to pass.  When I pulled the drive off of
; the IAC motor the engine would not start.  I had to open the throttle some
; to get it to fire and keep running.  Putting my finger over the feed hole
; in the air horn vacuum did build up but it did slowly.
;
; Looking at the plots it look like the total period is always the same other
; than at initial turn on where it goes thru 5 125 ms on and 125 off cycles.
; At the three points that I checked it (start, 900 and 2700 RPM) the period
; was always 6.9ms. During starting 6ms On and 760us Off.  With the engine
; running turning off the Idle Air Control the motor is driven 2.5ms off and
; 4.3ms on.....
;
;
L9740:	ldy	#register_base
	brset	L0001 %00000001 L9776 ; Not doing our initial banging any more
;
; During initial power up we cycle 5 (times) thru this longer cycling
; (250ms 50% duty cycle).  I guess to shake the cobwebs off or to let us know
; it is still working !!!!!
;
	brset	$0d,Y %10000000 L9763	; output just went high (max air)
	ldd	Lf490		; D = $f424
	subd	Lf492		; D = $f424 - $7A12 = $7A12
	lsld			; D = $f424 - .125 sec
	addd	toc1_data_reg	; add to what is in it now
	std	toc1_data_reg	;
	bclr	$23,Y %01111111 ; clear OC1 interrupt
	bset	$0d,Y %10000000 ; Output a High at next compare
	rti
;
; Output just went high.  Define the On time of the IAC motor now
;
L9763:	ldd	Lf492		; $7a12
	lsld			; $f424 - .125 sec
	addd	toc1_data_reg
	std	toc1_data_reg
	bclr	$23,Y %01111111 ; clear OC1 interrupt
	bclr	$0d,Y %10000000 ; Output low at end of next compare
	rti
;
; -------------------------------
; Enter here for all IAC interrupts after the initial banging mode......
;
L9776:	brset	L0001 %00000010 L9788 ; Over 5000 RPM or water under 60 degrees
	ldx	L003e		; get the current timing period
	beq	L978f		; motor not turning over
	cpx	#$0177		; Below 5,000 RPM ?		(375 - 5000 RPM)
	bhi	L97a4		; yes
	bset	L0001 %00000010 ; signal over 5000 RPM
	bra	L978f
;
; water over 60 degrees or over 5000 RPM.....
;
L9788:	ldx	L003e		; get timing period back
	cpx	#$01a1		; Below 4,500 RPM ?		(417 - 4496 RPM)
	bhi	L97a1		; yes
L978f:	bclr	$23,Y %01111111 ; clear OC1 interrupt
	bclr	$0d,Y %10000000 ; output low at end of next compare
	ldd	L006c		; get last total period
	lsrd
	addd	timer_tcnt_reg	; plus the current timer count
	std	toc1_data_reg	; update timer
	rti			; done
;
; Below 4500 RPM....
;
L97a1:	bclr	L0001 %00000010 ; clear hi speed IAC flag
;
; Below 5000 RPM....
;
L97a4:	brset	$0d,Y %10000000 L97c7	; Output just went High
;
; Output just went low turning Off the IAC motor.  Determine the Off time now.
;
	ldy	#register_base
	ldx	L0066		; get new IAC On time
	stx	L006a		; update for next interrupt
	ldd	L0068		; get new total period
	std	L006c		; update last total period
	subd	L006a		; less On time
	lsrd			; / 2
	addd	toc1_data_reg	; update timer
	std	toc1_data_reg
	bclr	$23,Y %01111111 ; clear interrupt
	bset	$0d,Y %10000000 ; output hi after this period
	rti
;
; Output just went High turning On the IAC motor (max air).  Determine the
;  On time now.
;
L97c7:	ldy	#register_base
	ldd	L006a		; get the last On time
	lsrd			; in 1MHz units - make 500KHz
	addd	toc1_data_reg	; plus what is currently there
	std	toc1_data_reg	; next interrupt compare count
	bclr	$23,Y %01111111 ; clear interrupt
	bclr	$0d,Y %10000000 ; output low next after this period
	rti
;
; -----------------------------------------------------------------------------
	if	not no_fills
	fill	$ff,$3823
	endif
;-----------------------------------------------------------------------------
	org	$d000
;
; This routine calculates the requirements for the IAS.  The dashpot functions
;  are performed here along with calculating the IAS% required........
;
;
; First we will use the current coolant temperature to modify the target idle
;  rpm modifier stash.	Look up coolant mod, add to current modifer, range
;  check, and look up idle rpm.  Strange looking numbers at first glance but
;  the work out because of the negative offsets in some of the tables....
;
Ld000:	ldab	L0003		; TH2O - adjusted water temperature
	tba			; copy into A
	anda	#%00001111
	staa	L000bw		; save for Lda08 interrpolation routine
	lsrb			; move significant bits down
	lsrb			; / 4
	lsrb			; / 8
	lsrb			; / 16
	ldx	#Lf42c		; point to idle rpm mod vs coolant temp table
	abx			; point to modifier
	ldaa	$00,X		; get it
	suba	#$80		; less Idle Speed Modifier bias
	adda	L00b0		; plus Target Idle Speed Modifier
	bcc	Ld01b		; modifier too low for this temperature
	cmpa	#1+19		; too low for rpm table ?
	bcc	Ld027		; nope
Ld01b:	ldaa	#1+19		; rpm lookup table base
	psha
	suba	$00,X		; less this coolant temp modifer
	adda	#$80		; plus 128 bias
	staa	L00b0		; stash new Target Idle Speed Modifier
	pula
	bra	Ld035		; look at second interpolation point
;
Ld027:	cmpa	#45+19		; past end of table ?
	bls	Ld035		; nope
	ldaa	#45+19		; max at end of table
	psha			; save
	suba	$00,X
	adda	#$80		; plus 128 bias
	staa	L00b0		; stash new Target Idle Speed Modifier
	pula
Ld035:	std	L000dw		; B still has upper four TH2O bits
;				; A - index into RPM table
	tab			; put a copy into B
	ldy	#Lff52-19	; point to idle RPM lookup table
	aby			; move to specified rpm
	ldaa	$00,Y		; get idle rpm
	ldab	L000ew		; get water temp index back
	cmpb	#$0f		; TH2O greater than 264 degrees ?
	beq	Ld069		; yes - stash new idle speed rpm in A
;
; coolant is below 264 degrees so we can interrpolate between table ranges.....
;
	ldab	$01,X		; get next coolant index
	subb	#$80		; less 128 bias
	addb	L00b0		; plus Target Idle speed modifier
	bcc	Ld053		; too low for this table
	cmpb	#1+19		; too low ?
	bcc	Ld057		; nope
Ld053:	ldab	#1+19		; point to table start
	bra	Ld05d
;
Ld057:	cmpb	#45+19		; past end of table ?
	bls	Ld05d		; nope
	ldab	#45+19		; point to end of table
Ld05d:	ldx	#Lff52-19	; point to idle RPM lookup table
	abx			; on next rpm
	ldab	$00,X		; get it
	pshy			;
	pulx			; point IX to lookup table location
	jsr	Lda08		; interpolate between the two rpms
Ld069:	staa	L0061		; stash new Idle Target RPM
;
; mistake below - if the dashpot is zero and 1xxxxxxx is set will always take
;  first branch.   1xxxxxxx only set here but never cleared !!!!!!!!!!
;
	brset	L005c %10000000 Ld07c ; dashpot was zero before
	ldx	L006e		; get the current dashpot value
	bne	Ld078		; something in it - modify the idle speed then
mis41:	bset	L005c %10000000 ; signal dashpot is zero (NEVER CLEARED !!!!)
	bra	Ld0c8
;
Ld078:	suba	L006e		; increase the idle speed by dashpot value
	bra	Ld0c6		; stash new idle rpm
; .............................................................................
;
Ld07c:	brset	L005c %00100000 Ld09b ; dashpot is active now
	ldab	L0022		; get ADC TPS count
	cmpb	L001c		; throttle plates closed ?
	bls	Ld0c8		; yes - don't check for dashpot being needed
	ldab	L0017		; dashpot rpm threshold
	subb	Lf483		; Delta Period (Between desired & nominal) for
				;  DECEL Strategy Enable.
				; a little faster (~60 rpm)		2
	cmpb	L0042		; compare to current timing_period / 16
	bls	Ld0c8		; not below dashpot rpm trip point yet
	ldx	Lf47e		; Delta RPM Period Initialization
				; re-seed the dashpot counter  4.85 seconds 7400
	stx	L006e		; stash new dashpot
	bset	L005c %00100000 ; signal dashpot operation active
Ld097:	suba	L006e		; increase the idle speed by dashpot count
	bra	Ld0c6		; stash new idle rpm
;
; Dashpot is active now.
;   If throttle is open keep bumping the idle speed by decreasing dashpot value.
;   If RPM is above trip - continue dashpot
;
Ld09b:	brset	L005c %00010000 Ld0b0 ; doing dashpot - wait till done
	ldab	L0022		; get ADC TPS count
	cmpb	L001c		; throttle plates opened ?
	bhi	Ld097		; yes - continue dashpot
	ldab	L0042		; timing_period / 16
	cmpb	L0017		; rpm faster than trip point ?
	bls	Ld097		; yes - continue
;
; Throttle closed and RPM is below dashpot trip point.	Signal to continue
; with dashpot operation until it counts down or the throttle plates are opened.
;
	bset	L005c %00010000 ; signal we are doing it
	bra	Ld097		; bump idle speed
;
Ld0b0:	ldab	L0022		; get the ADC TPS count
	cmpb	L001c		; throttle plates closed ?
	bls	Ld0bd		; yes - continue dashpot
	ldx	#$0000		; nope - opened so turn the dashpot off
	stx	L006e
	bra	Ld0c1		; stop dashpot mode
;
Ld0bd:	ldx	L006e		; get the current dashpot value
	bne	Ld097		; not zero - bump up the idle target rpm
Ld0c1:	bclr	L005c %00110000 ; stop dashpot mode
	bra	Ld0c8
;
Ld0c6:	staa	L0061		; stash new Target Idle RPM
Ld0c8:	ldab	L0003		; get TH2O - Water Temperature
	ldx	#Lf3ec		; on TH2O idle speed activity factor table
	jsr	Ld9f6		; lookup adjusted value
	staa	L0006w		; stash min needed for TH2O IAS requirements
;
; What we seem to be doing here is looking for an IAS% value for a particular
; rpm.	The first two lookups seem to determine the bounds (min/max) acceptable
; IAS percenatge.  The position of the throttle plates are also factored in.
; Anything over a TPS of ~25 degrees is treaded as opened.
;
;
; This is all very strange below.  They get the modifier from the TH2O table
; add in the current rpm/25, and subtract out the index (which is the upper
; four bits of L0003 TH2O / 16) into the above idle mod vs coolant table.
; Obviously the rpm/25 is going to have the biggest affect because it will
; vary the most.  The last idle speed modifier has a value of 32.  When the
; water temp is in the normal range (170 to 190 degrees) L000dw = 11.
; So:
;	RPM	L00b7	Water	Mod	Result
;
;	  0	 0			  21
;	500	20			  41
;	875	35			  56
;	900	36			  57
;	925	37   -	 11  +	32   =	  58
;	950	38   -	 11  +	32   =	  59
;	975	39			  60
;      1000	40			  61
;      1500	60			  81
;      2000	80			 101
;      3000    120			 141
;      4000    160			 181
;      5000    200			 221
;      6000    240			 261 --> 255 limit
;
	ldx	#Lf42c		; point to idle speed mod table
	clra
	ldab	$0f,X		; get the lowest modifier (highest TH2O) value
	addb	L00b7		; plus current rpm/25
	adca	#$00
	subb	L000dw		; less index into idle RPM table (0-15)
	sbca	#$00
	bcc	Ld0e5		; didn't go below zero
	clrb			; B = 0
	bra	Ld0ea
;
Ld0e5:	tsta			; go past 255 ?
	beq	Ld0ea		; nope
	ldab	#$ff		; max out
Ld0ea:	stab	L000ew		; stash index
;
	if	not mis45x
mis45:	ldab	L000ew		; needless load
	endif
;
	ldx	#Lf43c		; min IAS% vs rpm
	jsr	Ld9f6		; get it
	staa	L000dw		; stash min IAS%
	ldab	L000ew		; get index back
	ldx	#Lf44c		; max IAS% vs rpm
	jsr	Ld9f6		; get it
	staa	L0004w		; stash max IAS%
	ldaa	L0022		; get the ADC TPS count
	suba	L001c		; less closed TPS ADC count (make ADC base 0)
	bcc	Ld107		; didn't go below zero
	clra			; min value
;
; For the multiply not to overflow max ADC value would be ~71 - ~25 degrees
;
Ld107:	ldab	Lf486		; Throttle Potentiometer Scaling Factor
				;  for Dashpot.
				; times 11	(176/16=11)
	mul
	lsrd			; / 2
	lsrd			; / 4
	lsrd			; / 8
	lsrd			; / 16
	tsta			; over 255 ?
	beq	Ld114		; nope
	ldab	#$ff		; max out
;
; put whichever is larger (tps*11 or min IAS%) into A.
;
Ld114:	ldaa	L000dw		; get min IAS% required
	cba			; is it larger than TPS factor ?
	bcc	Ld11a		; yes - use it then
	tba			; put greater TPS into A
;
; put whichever is smaller (output A from above or max IAS%) into A.
;
Ld11a:	ldab	L0004w		; get max IAS %
	cba			; is it less ?
	bls	Ld120		; no - tps factor is smaller
	tba			; put smaller max IAS into A
;
Ld120:	staa	L000ew		; stash min IAS% required
	ldab	L0070		; get last minimun
	cba			; is it larger ?
	bcs	Ld135		; last min is larger than what is required now
	ldab	L0071		; get last min used
	stab	L0070		; stash in previous stash
	staa	L0071		; use the new smaller value
	bclr	L005c %00000011 ; clr timer flags
	clr	L0072		; reset 33 second timer
	bra	Ld172		; done calculating min required
;
; Last min IAS% requirement was larger than what is required now......
;
Ld135:	brclr	L005c %00000001 Ld144 ; L0072 hasn't rolled thru zero (33 secs)
	bclr	L005c %00000001 ; clear 33 sec L0072 counter roll flag
;
	if	not mis43x
mis43:	subb	Lf487		; subtracting 255 from B will always result
	bcc	Ld142		; in zero or less than zero which gives us....
	endif
;
	clrb			; .... zero !
Ld142:	stab	L0070		; clear last minimun stash
Ld144:	ldaa	L0004w		; get max IAS% required
	cba			; is it smaller than what is requested now ?
	bls	Ld14a		; yes
	tba			; no - use smaller requested value then
Ld14a:	staa	L000dw		; stash new IAS% required
	ldaa	Lf487		; 255
	ldab	L0072		; get timer count (131 ms)
	mul
	tab			; / 256 so B ~= number of 131ms tics since reset
	ldaa	L000dw		; get IAS%
	sba			; subtract it from timer count
	bcc	Ld159		; didn't go below zero
	clra
Ld159:	ldab	L000ew		; get minimun required
	cba			; is counter modified larger ?
	bcc	Ld15f		; yes
	tba			; no - use table min then
Ld15f:	staa	L0071		; stash IAS% needed for rpm
	cmpa	L000ew		; is it less than calculated min ?
	bls	Ld16a		; yes
	bset	L005c %00000010 ; no - signal timer to start ticing
	bra	Ld172		; done
;
Ld16a:	clr	L0072		; reset timer
	staa	L0070		; clear previous
	bclr	L005c %00000011 ; clr timer flag and stop IAS counter
;
; Done calculating min IAS% required.  Now calculate other requirements.
; -------------------------------
; Calculate what we need to bring the idle speed into line.............
;
Ld172:	ldd	L0040		; get the predicted next timing period
	lsrd			; / 2  - make same scale as idle target rpm
	lsrd			; / 4
	lsrd			; / 8
	lsrd			; / 16
	tsta			; not below 460 rpm
	beq	Ld17d
	ldab	#$ff		; bottom out at 460 rpm
Ld17d:	subb	L0061		; less Idle Target RPM
	bcc	Ld1a8		; slower than target rpm
;
; turing faster than idle target rpm
;
	negb			; change sign
	cmpb	Lf468		; Delta RPM Threshold for 2nd Neg Prop Term
				; 22 - about 200 rpm at idle speeds
	bhi	Ld18d		; more than ~200 rpm too high
	ldaa	Lf469		; First Neg Proportional Gain Term
	mul
	bra	Ld19f
;
Ld18d:	subb	Lf468		; Delta RPM Threshold for 2nd Neg Prop Term
	ldaa	Lf46a		; 2nd Multi Coef of DCPROP		128
	mul
	std	L000bw
	ldaa	Lf468		; Delta RPM Threshold for 2nd Neg Prop Term
	ldab	Lf469		; First Neg Proportional Gain Term
	mul			; D = 1056
	addd	L000bw
Ld19f:	cmpa	#$80		; less than 128 ?
	bls	Ld1a5		; yes
	ldaa	#$80		; 128 max
Ld1a5:	nega			; change sign back
	bra	Ld1cb		; stash
;
; motor turning slower than idle target rpm
;
Ld1a8:	cmpb	Lf46b		; Delta RPM Threshold for Double Positive
				;   Proportional Term.
				; 16 - about 90 rpm at idle speeds
	bhi	Ld1b3		; more than 90 rpm slow
	ldaa	Lf46c		; First Multi Coef of DCPROPN		96
	mul
	bra	Ld1c5
;
Ld1b3:	subb	Lf46b		; Delta RPM Threshold for Double Positive
				;   Proportional Term
	ldaa	Lf46d		; 2nd Multi Coef of DCPROP, RPM too Low   176
	mul
	std	L000bw
	ldaa	Lf46b		; Delta RPM Threshold for Double Positive
				;   Proportional Term
	ldab	Lf46c		; First Multi Coef of DCPROPN		96
	mul			; D = 1536
	addd	L000bw
Ld1c5:	cmpa	#$7f		; less than 127
	bls	Ld1cb		; yes
	ldaa	#$7f		; limit
Ld1cb:	staa	L000dw		; stash IAS needed for idle speed adjustment
;
	ldaa	L0022		; get the ADC TPS count
	cmpa	L001c		; throttle plates opened ?
	bhi	Ld233		; yes - skip
	ldaa	L0042		; timing period / 16
	cmpa	L0017		; above dashpot threshold rpm ?
	bcs	Ld233		; yes - skip
	ldab	L000dw		; get how much needed for idle speed correction
	bpl	Ld1e3		; need to speed up
	brset	L0001 %00001000 Ld233 ; Idle Air at minimum already - skip
	bra	Ld1e7
;
Ld1e3:	brset	L0001 %00000100 Ld233 ; Idle Air at maximum already - skip
;
; IAS is currently greater than 6.25% and less than 125%.  Take what we
; need for idle speed and multiply by 12 (192/16).
; It looks like L0062 is an accumulator that the idle speed factor * 12 gets
; stashed into.  It's range is +-48.
;
Ld1e7:	ldaa	Lf477		; Gain Applied to Duty Cycle Prop to Speed
				;   Integral Updating
				; 192 - multiply by 12 (192/16=12)
	ldab	L000dw		; get idle speed adjustment factor
	bpl	Ld1fa		; need to go faster
	negb			; chnage sign
	mul
	lsrd			; / 2
	lsrd			; / 4
	lsrd			; / 8
	lsrd			; / 16
	coma			; change sign back
	negb
	sbca	#$ff
	bra	Ld1ff
;
Ld1fa:	mul
	lsrd			; / 2
	lsrd			; / 4
	lsrd			; / 8
	lsrd			; / 16
Ld1ff:	std	L000bw		; what idle speed needs * 12
	bpl	Ld21d		; need to speed up
	ldd	L0062		; get accumulator
	bpl	Ld22f		; its pos now so we can just add in neg value
	addd	L000bw		; plus idle*12
	coma			; change sign
	negb
	sbca	#$ff
	cmpa	Lf476		; under Duty Cycle Int Max Value (Pos or Neg) 48
	bcs	Ld217		; yes
	ldaa	Lf476		; Duty Cycle Int Max Value (Pos or Neg)
	ldab	#$00		; make word
Ld217:	coma			; change sign back
	negb
	sbca	#$ff
	bra	Ld231		; stash
;
Ld21d:	ldd	L0062		; get accumulator
	bmi	Ld22f		; negative - just add in idle speed*12 factor
	addd	L000bw		; plus idle spd*12
	cmpa	Lf476		; under Duty Cycle Int Max Value (Pos or Neg) ?
	bcs	Ld231		; yes
	ldaa	Lf476		; Duty Cycle Int Max Value (Pos or Neg) 48
	ldab	#$00		; clear low byte
	bra	Ld231		; stash
;
Ld22f:	addd	L000bw
Ld231:	std	L0062		; stash (only A gets used later so /256)
;
Ld233:

	if	not mis14x

	ldaa	L0003		; get TH2O - Water Temperature
	cmpa	Lf478		; Threshold for AUTOADAP Calculation
				; (autoadap.calc. applies a learned calc enable)				; below 300+ degrees ??????	       255
mis14:	bls	Ld25d		; will always take this branch !!!!
;
; ................ never execute the below code ...............................
;
	ldaa	L0022		; get the ADC TPS count
	cmpa	L001c		; throttle plates opened ?
	bhi	Ld25d		; yes
	ldaa	L0042		; timing_period / 16
	cmpa	Lf479		; Upper RPM Window Threshhold for the
				;   Autoadaptive Calculation Enable
				; turning faster than 803 RPM ? 	146
	bls	Ld25d		; yes
	cmpa	Lf47a		; Lower RPM Window Threshhold for the
				;   Autoadaptive Calculation Enable
				; slower than 803 RPM ? 		146
	bcc	Ld25d		; yes !!!! ????
;
; Never get here because above tests will always jump to Ld25d......
;
	if	not mis8x	; mis8:
	brset	L00ba %10000000 Ld25d ; bit never set here - maybe controller ?
	endif
;
	ldaa	L00b9		; any warning errors ?
	bne	Ld25d		; yes
mis44:	ldaa	L0073		; bump useless counter
	beq	Ld264
	deca
	staa	L0073
	bra	Ld29a
;
; .............................................................................
;
Ld25d:	ldaa	Lf47b		; 255
	staa	L0073		; never used !!!!  mis44:
	bra	Ld29a
;
; ..................... never execute below code ..............................
mis14a:
Ld264:	clra
	ldab	L0064
	bpl	Ld26a
	coma
Ld26a:	std	L000bw
	ldd	L0064
	subd	L000bw
	std	L0004w
	clra
	ldab	L0062
	bpl	Ld278
	coma
Ld278:	std	L000bw
	bpl	Ld289
	ldd	L0004w
	bpl	Ld296
	addd	L000bw
	bvc	Ld298
	ldd	#$8000
	bra	Ld298
;
Ld289:	ldd	L0004w
	bmi	Ld296
	addd	L000bw
	bvc	Ld298
	ldd	#$7fff
	bra	Ld298
;
Ld296:	addd	L000bw
Ld298:	std	L0064
; ........................... END Never Executed code .........................
	endif
;
; Check for changes in motor speed and direction.
;
;	Faster than ~130 rpm --> L000ew=244
;	Slower than ~96 rpm  --> L000ew=7
;	No change or within the above range then L000ew=0
;
Ld29a:	ldd	L0040		; get the predicted next timing period
	subd	L003c		; less previous timing period
	beq	Ld2c8		; rpm has not changed
	bhi	Ld2b7		; slowing down
;
; motor is speeding up
;
	coma			; change sign
	negb
	sbca	#$ff
	pshb			; into IX
	psha
	pulx
	cpx	Lf46e		; Threshold of last Incr RPM to sub Lf472 from
				;   Duty Cycle
				; 250 - at idle speeds this is arround 130 rpm
	bhi	Ld2b1		; faster by more than 130 rpm
	clra			; lower - null
	bra	Ld2c8
;
; more than ~130 rpm speed change
;
Ld2b1:	ldaa	Lf472		; Positive Derivate ABS Value		12
	nega			; 244
	bra	Ld2c8		; stash factor
;
; motor is slowing down.....
;
Ld2b7:	pshb			; get in IX
	psha
	pulx
	cpx	Lf470		; Threshold for Fast Decrease RPM to Add Lf473
				;   to Duty Cycle
				; 184 - at idle speeds this arround 96 rpm
	bhi	Ld2c2		; slower tha ~96 rpm
	clra			; don't bother
	bra	Ld2c8
;
Ld2c2:	ldaa	Lf473		; Negative Derivate ABS Value		7
	bset	L005c %00001000 ; signal motor slowing down
Ld2c8:	staa	L000ew		; how much RPM has changed (in timing_periods)
;
	ldaa	L0022		; get the ADC TPS count
	cmpa	L001c		; throttle plates closed ?
	bls	Ld2d3		; yes
	bclr	L005c %00001100 ; reset slowing flag and saw once flag
Ld2d3:	ldaa	L006e		; get the current dashpot value (high byte)
	ldab	Lf480		; Extra-Duty for Gain Calculationat Crank or
				;   During Deceleration, TPS at Min.
	mul
	lsld			; * 2
	bcc	Ld2de		; didn't roll
	ldaa	#$ff		; max out
Ld2de:	staa	L0004w		; stash dashpot effect
	clra
	brclr	L00b3 %00100000 Ld2ea ; Idle Control is On !
	tab			; A --> B  --> D=0
	std	L000bw		; zero
	bra	Ld31b		; idle control is Off
;
; Idle Control is On .......
;
Ld2ea:	ldab	L000dw		; get idle speed correction factor
	bpl	Ld2ef		; need to go faster
	coma			; make 16 bit negative number
Ld2ef:	std	L000bw		; stash idle speed factor (correct sign)
	clra
	ldab	L0062		; get accumulator factor
	bpl	Ld2f7		; positive
	coma			; make 16 bit negative number
Ld2f7:	addd	L000bw		; add in current IAS requirements
	std	L000bw		; replace
;
	if	not mis14x
	clra
mis14b: ldab	L0064		; always zero because of mis14a:
	bpl	Ld301		; always take this branch
	coma			; make 16 bit negative number
Ld301:	addd	L000bw		; update
	std	L000bw
	endif
;
	brset	L005c %00000100 Ld318 ; saw motor slowing once
	clra
	ldab	L000ew		; get how much motor is slowing/speeding
	bpl	Ld316		; slowing or within limit window
	brclr	L005c %00001000 Ld315 ; motor is speeding up
	bset	L005c %00000100 ; signal we saw motor slowing once
Ld315:	coma			; make 16 bit negative number
Ld316:	addd	L000bw		; add into accumulator
Ld318:	std	L000bw
	clra
;
; L0004w - IAS% needed for the dashpot function.
; L0006w - IAS% needed vs coolant temperature.
; If Idle Control is Off then L000bw = zero
; If Idle Control id ON the L000bw is the IAS% needed.
;
Ld31b:	ldab	L0004w		; get the dashpot factor
	addd	L000bw		; plus all other IAS requirements
	bmi	Ld334		; negative
	lsld			; * 2 because modifier bias will divide by 2
	pshb			; into IX
	psha
	pulx
	ldaa	L00b1		; get Idle Speed Activity modifier
	jsr	Ld8a5		; D = (A*IX)/256
	cpd	#$007f		; <= 127 ?
	bls	Ld34d		; yep
	ldab	#$7f		; max 127
	bra	Ld34d
;
Ld334:	coma			; change sign
	negb
	sbca	#$ff
	lsld			; * 2
	pshb			; into IX
	psha
	pulx
	ldaa	L00b1		; get Idle Speed Activity
	jsr	Ld8a5		; D = (A*IX)/256
	coma			; change sign back
	negb
	sbca	#$ff
	cpd	#$ff80		; more than -128 ?
	bge	Ld34d		; nope
	ldab	#$80		; -128 max then
;
; At this point it looks like we have a min IAS% needed that is determined
;  by the coolant temperature in L0006w.  B contains the user modified (by
;  the Idle Speed Activity modifier) value of IAS% needed for other factors,
;  like idle rpm and dashpot functions.
;
Ld34d:	stab	L000dw		; temp stash IAS%
	ldaa	L0006w		; get TH2O dependant factor (min IAS % vs TH2O)
	ldab	L000dw		; get it back
	bpl	Ld35d		; positive - less than 100% desired
	negb			; change sign
	sba			; A=A-B
	bcc	Ld35b		; didn't go below zero
	ldaa	#$00		; IAS off
Ld35b:	bra	Ld362
;
Ld35d:	aba			; TH2O factor + Others		A=A+B
	bcc	Ld362		; didn't overflow
	ldaa	#$ff		; idle air to 200%
Ld362:	cmpa	L0071		; min IAS vs rpm higher than other requirements?
	bhi	Ld37b		; nope - use other guys
;
; Use min IAS vs rpm because other requirements are smaller.......
;
	ldaa	L0071		; get min IAS % vs RPM
	bset	L0001 %00001000 ; signal idle air at minimun
;
	if	not L6000_skip
	ldab	L6000		; read the PAL status (L9112D)
	bitb	#%00000100	; J1-21 pulled high - Air Conditioner On ?
	bne	Ld3a5		; no - stash new IAS % value
	adda	Lf48a		; 13.25% added				17
	bcc	Ld3a5		; didn't overflow - stash IAS %
	ldaa	#$ff		; idle air to 200 %
	endif
;
	bra	Ld3a5		; skip range checks and stash IAS %
;
; Other requirements are larger than the min IAS vs rpm so use it
;
Ld37b:
	if	not L6000_skip
	ldab	L6000		; read the PAL status (L9112D)
	bitb	#%00000100	; J1-21 pulled high - Air Conditioner On ?
	bne	Ld392		; nope
	adda	Lf48a		; 13.25% added				17
	bcc	Ld392		; didn't overflow
	ldaa	#$ff		; idle air wide open !
	brclr	L00b3 %00100000 Ld392 ; Idle Control is On
	bset	L0001 %00001100 ; set idle air range limited flags
	bra	Ld3a5		; skip range checks - stash IAS %
	endif
;
Ld392:	bclr	L0001 %00001100 ; clear idle air range limit bits
	cmpa	Lf475		; DCK1, Upper Threshold for D.C Integral Update
				; new Idle Air <= 125% ?		 160
	bls	Ld39d		; yes
	bset	L0001 %00000100 ; signal at maximun
Ld39d:	cmpa	Lf474		; DCK1, Lower Threshold for Duty Cycle Integral
				;  Update.
				; below 6.25% Idle Air ?		  8
	bcc	Ld3a5		; nope - stash IAS %
	bset	L0001 %00001000 ; signal at minimum
Ld3a5:	staa	L0006w		; stash idle motor activity % in work stash
;
; I figured the values of this stash by back computing what the controller
;  reports.....
;				; 125% = 160
;				; 100% = 128	- (in controller terms)
;				; 60%  =  77
;				; 50%  =  64
;				; 40%  =  51
;				; 20%  =  26
;				; 10%  =  13
	if	not mis15x
	psha			; usless push
	endif
	ldaa	L00bc		; allow engine status to be sent to controller ?
	anda	#%00000111
	cmpa	#%00000001
	bne	Ld3c2		; nope
	if	not mis15x
	pshx
	endif
	ldx	#L00c2		; point to the serial output buffer
	clra			; if idle control Off then send a zero
	brset	L00b3 %00100000 Ld3bb ; Idle Control is Off !
	ldaa	L0061		; get Target Idle RPM
Ld3bb:	staa	$0c,X		; stash in serial output buffer
	ldaa	L0006w		; get computed IAS activity back
	staa	$0d,X		; stash Idle Motor Activity %
;
	if	not mis15x
	pulx
Ld3c2:	pula
	else
Ld3c2:
	endif

	if	not mis15x
;
; All the below shit will always come back with $1a00 (6656) to put into
;  L000bw.  Look at routine Ld952 for more details.......
;
mis15:	ldab	Lf01c		; 7
	stab	L001bw		; stash number of items (8) in table
	clra
	ldab	L0006w		; get computed idle activity percentage back
	ldx	#Lf40c		; on table
	jsr	Ld907
	stab	L0011w		; stash distance from the exact match
	ldab	L001bw		; get major index
	stab	L0013w		; stash fractional
	ldx	#Lf41c
	jsr	Ld952
;
;  What I see always return is:
;		D = $1a00 - 6656 (6.656ms)
;		L0059 xxxxxx1x - always set
;
	std	L000bw
	brset	L0059 %00000010 Ld3ea ; will always take this ?????????
	clrb			; change sign
	subb	L000cw
	sbca	#$00
	std	L000bw
Ld3ea:	ldx	#Lf424
	jsr	Ld93d		; for the same reasons as above this will
;				;  always return 10 ($0a)
	tab			; B = A
	ldaa	L000bw		; A = $1a
	addb	L000cw		; B = $0a + $00
	adca	#$00		; no carry
	std	L0004w		; $1a0a (6.666ms) hold new total IAC period here
	endif
;
;   0% -   0   D =   (0*6666)/256 = 6666 * 0	 =    0  0.000ms
;  20% -  26   D =  (26*6666)/256 = 6666 * .1016 =  677  0.677ms
;  30% -  38   D =  (38*6666)/256 = 6666 * .1484 =  989  0.989ms
;  50% -  64   D =  (64*6666)/256 = 6666 * .2500 = 1666  1.666ms
;  70% -  90   D =  (90*6666)/256 = 6666 * .3516 = 2343  2.343ms
; 100% - 128   D = (128*6666)/256 = 6666 * .5000 = 3333  3.333ms
;
	ldaa	L0006w		; get idle activity value (0-130%  0-165)
	ldx	Lf45c		; Nominal Period for VAE (IAC) Control Signal
				; total time period 6.666ms		6666
	jsr	Ld8a5		; D = (A*IX)/256
	addd	Lf45e		; Basic Offset for VAE (IAC) Duty Cycle (30%)
				; plus 2ms offset			2000
;
; So .....
;   0% -   D =	0.000ms + 2ms = 2.000ms  30% duty cycle
;  20% -   D =	0.677ms + 2ms = 2.677ms  40% duty cycle
;  30% -   D =	0.989ms + 2ms = 2.989ms  45% duty cycle
;  50% -   D =	1.666ms + 2ms = 3.666ms  55% duty cycle
;  70% -   D =	2.343ms + 2ms = 4.343ms  65% duty cycle
; 100% -   D =	3.333ms + 2ms = 5.333ms  80% duty cycle
;
	if	not mis15x
	bcc	Ld409		; should never carry with these numbers
	ldd	#$ffff
	endif
;
; have to be above the 1.666ms min On time because of the 2ms offset added
;
	if	not mis15x
Ld409:	cpd	Lf460		; Nominal Duty Cycle Min Limit
				; above 1.666ms ?			1666
	bcc	Ld414		; yes - of coarse
	ldd	Lf460		; Nominal Duty Cycle Min Limit
				; 1.666 min ON time
	bra	Ld41d
	endif
;
Ld414:	cpd	Lf462		; Nominal Duty Cycle Max Limit
				; over 5.999ms On time ?		5999
	bls	Ld41d		; nope - in range
	ldd	Lf462		; Nominal Duty Cycle Max Limit
				; set max of 5.999ms			5999
Ld41d:	std	L000dw		; stash comupted On time
;
; Now lets correct IAC On time for battery voltage.................
;
	ldaa	L000a		; get Battery Voltage
	suba	#$5f		; less 6 volts (95 * .0625 = Batt_Volts)
;				;	       (95 / 16)
	bcc	Ld426		; it was 6 volts or greater
	clra
Ld426:
	if	not batt_mis
	cmpa	#$a0
	bls	Ld42c		; it will always take this branch
	ldaa	#$a0
	endif
;
Ld42c:	ldx	#$0180		; 384
	jsr	Ld8a5		; D = (A*IX)/256
;				;
;				; D = ((BATT-6 volts) * 384) / 256
;				; D = (BATT-6) * 1.5
;				;
	ldx	#Lf3fc		; point to correction table
	jsr	Ld9f6		; lookup adjusted value
	staa	L0006w		; stash for a bit
	ldx	L000dw		; get result of above idle activity computations
	ldaa	L0006w		; get result of battery adjustment
	jsr	Ld8a5		; D = (A*IX)/256
;
; at 15.333 volts  59/256 * L000dw = L000dw * .230
; at 14.667 volts  61/256 * L000dw = L000dw * .238
; at 14.000 volts  64/256 * L000dw = L000dw * .250 <--- zero correction point
; at 13.333 volts  68/256 * L000dw = L000dw * .266
;
	if	not mis15x
	bita	#%11000000	; Above $4000 (16.384ms) ?
	bne	Ld449		; yes - (can't be !!!!)
	endif
;
; At the nominal operation point of 14.000 volts we divided the value by 4,
;  we will re-adjust by multiplying back by 4....
;
	lsld			; times four to adjust for battery corrections
	lsld			; * 4
;
	if	not mis15x
	bra	Ld44c
;
Ld449:	ldd	#$ffff
	endif
;
Ld44c:	cpd	Lf466		; 6 msec, Actuation Duty Cycle Max Limit
				; over 5.999ms On time ?		5999
	bcs	Ld457		; nope
	ldd	Lf466		; 6 msec, Actuation Duty Cycle Max Limit
				; max 5.999ms				5999
	bra	Ld460
;
Ld457:	cpd	Lf464		; Actuation Duty Cycle Min Limit
				; under 1.666ms ?			1666
	bcc	Ld460		; nope
	ldd	Lf464		; Actuation Duty Cycle Min Limit
;
; The below does nothing   T = ((T/6666)*256)*(6666/256) = T
; It actually loses a few micro seconds because of rounding errors)
;
Ld460:
	if	not mis15x
	ldy	#$0009		; times 256   (2^8)
	ldx	Lf45c		; Nominal Period for VAE (IAC) Control Signal
	stx	L000fw		; stash divisor
	jsr	Ld8d1		; D = (D / 6666) * 256
	stab	L0006w
	ldaa	L0006w
	ldx	L0004w		; get total IAC period (always 6.666ms)
	jsr	Ld8a5		; D = (A*IX)/256
	ldx	L0004w		; get total IAC period back
	else
	ldx	Lf45c		; Nominal Period for VAE (IAC) Control Signal
				; total time period 6.666ms		6666
	endif
;
	sei
	std	L0066		; stash new IAC motor On time
	stx	L0068		; stash new IAC total period
	cli			; interrupts back on
	rts
;
; -----------------------------------------------------------------------------
; Convert the Fuel requirement calculations into a pulse width I think ?????
; Compute how much to change the PW during closed loop operation.
;
;	Entry:	L0004w - Fuel requirement
;	Return: L0004w - injector pulse width
;		L0011w - how much time to add/subtract to the pulse width time
;
; To go closed loop...
;	More than 80 revolutions
;	More than 90 seconds run time if at start TH2O was over 120 degrees
;	Within MAP ADC range
;	Within RPM range
;
Ld47e:	ldaa	L0015		; get revolution counter
	cmpa	#$b0		; been more than 80 revolutions yet ?	255-176
	bcs	Ld491		; yes
;
	if	not mis16x
mis16:	ldaa	Lf580		; Lambda sensor threshold
				; 0 - load a zero ???
	beq	Ld48e		; of coarse will always take this jump
mis24:	ldaa	Lf56a		; reset O2 sensor error counter 	255
	staa	L0077		; never get here ????????????
Ld48e:	jmp	Ld688		; can't do closed loop yet
	else
Ld48ex: jmp	Ld688		; can't do closed loop yet
	endif
;
; motor has turned more than 80 revolutions since start up
;
; More smart stuff here.  If the water is cooler than 105 degrees and over
;  90 seconds ok, and if it is hotter than 105 degrees and over 90 seconds
;  it is still ok ????????
;
mis25:
Ld491:
	if	not mis25x
	ldaa	L0003		; get TH2O - Water Temperature
	cmpa	#$80		; cooler than ~105 degrees ?
	bls	Ld4a1		; yes
	ldd	L007c		; get warmup timer
	subd	Lf572	     ; 90 SEC's, OPEN LOOP --> CLSD LP DLY, COOL GT 40c
			     ; Closed Loop delay for COOL GT 40c
				; Val = msec * 131
				; been over 90 seconds ?	687*131ms
	bcc	Ld4a8		; yes
Ld49e:	jmp	Ld688		; not yet - bail
;
Ld4a1:	ldd	L007c
	subd	Lf574		; Closed Loop delay for COOL LT 40c
				; been over 90 seconds ?	687*131ms
	bcs	Ld49e		; not yet - bail
	else
;
	ldd	L007c
	subd	Lf574		; Closed Loop delay for COOL LT 40c
				; been over 90 seconds ?	687*131ms
	bcs	Ld48ex		; not yet - bail
;
	endif
;
;
; Ok, it has been more than 90 seconds of on time..............................
;
; What we are doing now is computing how much time to add/subtract from the
;  injector pulse width.  This will be put into our return stash at L0011w
;
Ld4a8:	ldaa	Lf570		; Proportional Clsd Loop Feed Back term at Idle
				; 9.375%	24
	ldab	L0022		; get the ADC TPS count
	cmpb	L001c		; throttle plates closed ?
	bls	Ld51d		; yes
;
; Ok the throttle plates are Not closed....
;
	ldab	L00b7		; get current rpm/25
	subb	Lf567		; Subtr Offset for Lambda Tables Interpolation
				; below 1,200 rpm ?		48*25=1,200
	bcc	Ld4ba		; nope
	ldab	#$00		; can't go negative
Ld4ba:	lslb			; below 4,400 rpm ? 176-48=128 which would carry
	bcc	Ld4bf		; yes
	ldab	#$ff
Ld4bf:
	if	mis_clsd_lp1
	ldx	#Lf534		; point to lookup table (both are the same)
	jsr	Lda1f		; lookup from interpolated table
;
	else			; OLD code
	pshb			; save (rpm/12.5) - 1200 RPM
	ldx	#Lf534		; point to the > 21" table
	jsr	Lda1f		; lookup from interpolated table
	staa	L000cw		; stash if we need to interpolate
	ldab	L0000		; get adjusted MAP ADC value
	cmpb	Lf56d		; vacuum >= ~21"  (21" -->29")		51
	bls	Ld51c		; yes - use this value
	pulb			; get rpm/12.5 back
	pshb			; re-push
	ldx	#Lf52c		; point to <18.5" table
	jsr	Lda1f		; lookup from interpolated table
mis30:	staa	L000bw		; NOT NEEDED ??????
	ldab	Lf56d		; ~21" MAP ADC value			51
	addb	Lf56c		; + ~4" 				31
	cmpb	L0000		; vacuum less than ~18.5" (18.5" --> 29") ?
	bls	Ld51c		; yes - use this value
;
; They are going to interpolate between the two tables but in usual fashion
;  it means nothing because both tables are exactly the same so there is no
;  difference to compute.........
;
mis31:	ldx	#$0000
	ldab	Lf56c		; ~4" vacuum				31
	abx
	ldab	L0000		; get adjusted MAP ADC back
	subb	Lf56d		; less ~21" MAP ADC value (5.7" worth)	51
	suba	L000cw		; get difference (there is none ??????)
	bcs	Ld508
	mul
	idiv
	xgdx
	cpd	#$00ff
	bls	Ld4ff		; didn't overflow
	ldd	#$00ff
Ld4ff:	ldaa	L000cw
	aba
	bcc	Ld51c		; done
	ldaa	#$ff		; use max
	bra	Ld51c
;
Ld508:	nega			; change sign
	mul
	idiv
	xgdx
	cpd	#$00ff
	bls	Ld515
	ldd	#$00ff
Ld515:	ldaa	L000cw
	sba
	bcc	Ld51c		; SA decreasing step for the first knock    (WS)
				;  (RPM>RPM35)
	ldaa	#$00
;
Ld51c:	pulb			; clear stack of rpm/12.5

	endif			; mis_clsd_lp1
;
;
;  If throttle closed then A = value in Lf570 (24)
;  else what is calculated above.
;
; What is in 'A' is the percentage of the entry pulse width time that we will
;  take.
;
;	(PW * A%) * 1.6
;
Ld51d:	ldx	L0004w		; get pulse width
	jsr	Ld8a5		; D = (A*IX)/256
	std	L000bw
	ldaa	Lf569		; another 20%		51/256
	ldx	L000bw
	jsr	Ld8a5		; D = (A*IX)/256
	lsrd			; * 2
	lsrd			; * 4
	lsrd			; * 8
	tsta			; overflowed ?
	beq	Ld534		; nope
	ldab	#$ff		; max out at 255
Ld534:	stab	L0011w		; stash how much time to add/subtract from the
;				;  pulse width.
;
; ------- done calculating pulse width time modifier -----------------
;
; If L007b is NZ then the rich/lean condition has not changed its state.
; If zero then we just got a O2 sensor toggle.
;
	ldaa	L007b		; calculate a new rate of change value ?
	bne	Ld54a		; yes

	if	not mis26x
	brset	L005e %00001000 Ld544 ; RICH (Green LED On)
	ldaa	Lf56e		; Integral Closed Loop Fuel Step term at Idle
				;   when Rich.
				; 10 - lean rate of change
	jmp	Ld5d5		; don't calculte - just modify
;
Ld544:	ldaa	Lf56f		; Integral Closed Loop Fuel Step term at Idle
				;   when Lean.
				; 10 - rich rate of change constant
	jmp	Ld5d5
	else
	ldaa	Lf56f		; just by-pass all unused
	bra	Ld5e7
	endif
;
; Calculate new rate of change value....
;
; First assure RPM/25 is within 1,200 to 4,400 rpm range then change to RPM/12.5
;
Ld54a:	ldab	L00b7		; get current rpm/25
	subb	Lf567		; Subtr Offset for Lambda Tables Interpolation
				; below 1,200 rpm ?		48*25=1,200
	bcc	Ld553		; nope
	ldab	#$00
Ld553:	lslb			; below 4,400 rpm ? 176-48=128 which would carry
	bcc	Ld558		; yes
	ldab	#$ff
;
	if	mis_clsd_lp1	; new
Ld558:	ldx	#Lf554		; Lean - rpm vs rate modifier
	brclr	L005e %00001000 Ld578 ; LEAN (Red LED On)
	ldx	#Lf544		; point to Rich rpm vs rate modifier
Ld578:	jsr	Lda1f		; lookup from interpolated table
;
	else
;
Ld558:	pshb			; save (rpm/12.5) - 1200 RPM
	brclr	L005e %00001000 Ld578 ; LEAN (Red LED On)
;
; Currently we are Rich....
;
	ldx	#Lf544		; point to rpm vs ?????
	jsr	Lda1f		; lookup from interpolated table
	staa	L000cw		; stash lookup value
	ldab	L0000		; get adjusted MAP ADC value
	cmpb	Lf56d		; vacuum >= ~21"  (21" --> 29") 	51
	bls	Ld5d4		; yes - use this value (in A)
	pulb			; get rpm/12.5 back
	pshb			; save again
	ldx	#Lf53c		; rpm vs ????? (this table same as Lf544 !!)
	jsr	Lda1f		; lookup from interpolated table
mis27:	staa	L000bw		; stash same as L000cw above
	bra	Ld591
;
; Currently we are Lean....
;
Ld578:	ldx	#Lf554		; rpm vs ??????
	jsr	Lda1f		; lookup from interpolated table
	staa	L000cw
	ldab	L0000		; adjusted MAP ADC
	cmpb	Lf56d		; vacuum >= ~21"  (21" -->29")		51
	bls	Ld5d4		; yes - use this value (in A)
	pulb			; get rpm/12.5 back
	pshb			; restash
	ldx	#Lf54c		; rpm vs ?????
	jsr	Lda1f		; lookup from interpolated table
mis28:	staa	L000bw		; same result as L000cw above
;
Ld591:	ldab	Lf56d		; ~21" vacuum (in ADC counts)		51
	addb	Lf56c		; + ~4" vacuum				31
	cmpb	L0000		; vacuum less than ~18.5" (0" --> 18.5" ) ?
	bls	Ld5d4		; yes - use this value (second table - in A)
;
; At this point we have an value from the second table (0" to 18.5") in 'A'
; and the 21" to 29" value in L000cw.	We also know we are below 18.5" of
; vacuum (MAP ADC in L0000 > 82).
;
; What look like what is happening is they are getting the difference between
;  the output of the two tables, multipling by MAP ADC-21", then dividing
;  by ~4".  Add this to the output of the 21" table.  Of coarse all of
;  this is Bull Shit because both tables are exactly the same so we multiply
;  zero and just get the output of the first......???????
;
mis29:	ldx	#$0000		; clear IX
	ldab	Lf56c		; ~4" vacuum				31
	abx			; IX = 31
	ldab	L0000		; get adjusted MAP ADC value
	subb	Lf56d		; less ~21" vacuum (in ADC counts)	51
	suba	L000cw		; get difference between the two
	bcs	Ld5c0		; first was higher
	mul			; times MAP ADC
	idiv			; divided by 31
	xgdx			; result into D
	cpd	#$00ff		; overflow ?
	bls	Ld5b7		; nope
	ldd	#$00ff		; 255 max
Ld5b7:	ldaa	L000cw		; get output of 21" table
	aba			; add in interplated value
	bcc	Ld5d4		; didn't overflow - use it
	ldaa	#$ff		; 255 max
	bra	Ld5d4
;
Ld5c0:	nega			; change sign
	mul
	idiv
	xgdx			; result into D
	cpd	#$00ff
	bls	Ld5cd
	ldd	#$00ff
Ld5cd:	ldaa	L000cw
	sba
	bcc	Ld5d4		; no overflow
	ldaa	#$00		; min zero
Ld5d4:	pulb			; clear stack of rpm/12.5 value
;
	endif
;
; 'A' contains our rate of change value.
;
	if	not mis26x

Ld5d5:	ldab	L0076		; time to futher adjust rate of change value ?
	bne	Ld5e7		; not yet
;
; The below does nothing except multiply by 16 then divide by 16.....
;
mis26:	ldab	Lf587		; 16
	mul			; multiply by 16 then divide by 16 ??????
	lsrd			; / 2
	lsrd			; / 4
	lsrd			; / 8
	lsrd			; / 16
	tsta			; overflow ?
	beq	Ld5e6		; nope
	ldab	#$ff		; 255 max
Ld5e6:	tba			; result into A
	endif
;
Ld5e7:	staa	L0075		; stash new PW rate of change
;
; If both LED's are on for more than 255 itterations and we have been running
;  more than one minute and closed loop fuel is on then signal an O2 error...
;
	brset	L005e %01000000 Ld60a ; Only one LED is On
	ldaa	L0077		; O2 sensor error counter
	bne	Ld612		; haven't counted down yet - just continue
	ldd	L007c		; get warmup counter
	subd	#$01ca		; been running a minute yet ?	458*131ms
	bcs	Ld607		; no - not yet - just bail
	brclr	L00b3 %01000000 Ld604 ; Close Loop Fuel is On - show error
	bclr	L00b9 %00000100 ; clear O2 sensor error
	bset	L005e %00100000 ; signal water is under 120 degrees ?????
	bra	Ld607		; bail
;
Ld604:	bset	L00b9 %00000100 ; signal O2 Sensor Error
Ld607:	jmp	Ld688		; bail
;
; We are either too rich (Green LED) or too Lean (Red LED) so we can reset
;  the O2 sensor error counter...
;
Ld60a:	ldaa	Lf56a		; 255
	staa	L0077		; reset O2 sensor error counter
	bclr	L00b9 %00000100 ; clear O2 sensor error
Ld612:	brset	L00b3 %01000000 Ld607 ; Closed Loop Fuel is Off !
;
; Check that the current vacuum is within the closed loop range....
; Supposed to be between 4" and 16"
;
	ldaa	L0000		; get adjusted MAP ADC value
;
	if	my_cl_parms
	cmpa	#cl_lower_vac_lim  ; below low vacuum limit ?
	bhi	Ld622		   ; yes - out of range
	cmpa	#cl_upper_vac_lim  ; above the upper limit ?
	bhi	Ld625		; nope - in vacuum range
Ld622:	jmp	Ld688		; can't do closed loop
;
	else
	cmpa	Lf55f		; below ~6" (0" --> 6") ?		193
	bhi	Ld622		; yes - out of range
	cmpa	Lf55e		; above 18" (18" --> 29") ?		 86
	bhi	Ld625		; nope - in vacuum range
Ld622:	jmp	Ld688		; can't do closed loop
	endif
;
; Check that the current RPM is within the specified RPM limits for closed
;  loop operation. 4,200 is the upper limit and 1,850 is the lower.  If the
;  RPM was out of range then don't allow closed loop operation until the
;  current RPM is greater than 1,950 rpm or lower than 4,100 rpm.
;
Ld625:	ldaa	L00b7		; get rpm/25
;
	if	my_cl_parms
	ldab	#cl_upper_rpm_lim
	else
	ldab	Lf55c		; above 4,200 rpm ?		168*25=4,200
	endif
;
	cba
	bhi	Ld650		; yes - outside RPM range
	subb	#$04		; less 100 rpm
;
	if	not mis19x
mis19:	bcc	Ld632		; of coarse it won't carry !
	clrb
	endif
;
Ld632:	cba			; at or below 4,100 rpm ?
	bls	Ld63b		; yes
	brset	L005e %00000001 Ld653 ; was out of range so wait till below 4100
	bra	Ld659		; ok - continue with closed loop checks
;
Ld63b:
;
	if	my_cl_parms
	ldab	#cl_lower_rpm_lim
	else
	ldab	Lf55d		; lower closed loop trip point of 1,850 rpm  74
	endif
;
	cba			; below 1,850 rpm ?
	bcs	Ld650		; yes
	addb	#$04		; plus 100 rpm
;
	if	not mis20x
mis20:	bcc	Ld647		; of coarse it is clear
	ldab	#$ff
	endif
;
Ld647:	cba			; above 1,950 rpm ?
	bcc	Ld656		; yes
	brset	L005e %00000001 Ld653 ; was out of range so wait till above 1950
	bra	Ld659		; continue
;
Ld650:	bset	L005e %00000001 ; signal outside closed loop RPM limits
Ld653:	jmp	Ld688		; jmp to end
;
Ld656:	bclr	L005e %00000001 ; within closed loop RPM limits
Ld659:	ldaa	L0002		; get TAIR - Air Temperature - adjusted
	cmpa	Lf562		; MAT Low Threshold for Closed Loop	255
	bcs	Ld66f		; yes
	cmpa	Lf563		; MAT High Threshold for Closed Loop	255
	bhi	Ld669		; yes
	brclr	L005e %00010000 Ld672 ; Air Temp below 248 degrees
Ld669:	bset	L005e %00010000 ; signal Air Temp Above 248 degrees
	jmp	Ld688
;
Ld66f:	bclr	L005e %00010000 ; signal Air Temp under 248 degrees
Ld672:	brset	L0001 %01000000 Ld688 ; WOT !
	brclr	L0058 %00101000 Ld681 ; not in a fuel cutoff situation and
				      ;  not in medium rpm/load situation
	ldaa	Lf56b		;  get delay count			2
	staa	L0078		; seed Closed Loop delay counter
	bra	Ld688
;
; When the L0078 counter has counted down then it is ok to enter Closed Loop
;
Ld681:	ldaa	L0078		; get count
	beq	Ld693		; counted down - Ok to Close the Loop
	dec	L0078		; bump closed loop delay counter
;
; Outside Closed Loop conditions......
;
Ld688:	sei			; interrupts off
	bclr	L005e %10000000 ; signal to open the loop
	ldaa	L007e		; get how much time is being added/subtracted
				;  from the pulse width now.
	staa	L0011w		; use it as the return value
	cli			; interrupts back on
	bra	Ld69d
;
; If this stash (L0077) gets to zero without us ever being able to move the
;  mixture either rich or lean then the O2 sensor must not be working....
;
Ld693:	bset	L005e %10000000 ; signal Closed Loop operation
	ldaa	L0077		; bump O2 sensor error counter
	beq	Ld69d		; stop at zero
	dec	L0077
;
; The +-16,000 closed loop accumulator is in L0079.  Scale it and adjust the
; computed PW here.  A negative value will increase the Pulse Width.  The max
; the pulse width can change is +-20% which is set by Lf569.
;
Ld69d:	ldd	L0079		; get accumulator
	addd	#$3e80		; plus 16000 - make positive value
	lsrd			; / 2
	lsrd			; / 4
	lsrd			; / 8
	lsrd			; / 16
	lsrd			; / 32
	std	L000bw
	ldd	#$01f4		; remove base - 500  (16000/32=500)
	subd	L000bw		;
	bls	Ld6cc		; went negative or is zero
	lsrd			; / 2
	tba			; into A
	ldx	L0004w		; get the calculated pulse width
	jsr	Ld8a5		; D = (A*IX)/256
	std	L000bw		; stash result for a second
	ldaa	Lf569		; 20%				51/256
	ldx	L000bw		; get adjusted PW back
	jsr	Ld8a5		; D = (A*IX)/256
	addd	L0004w		; plus calculated pulse width
	bcc	Ld6c8		; didn't overflow
	ldd	#$ffff		; max out
Ld6c8:	std	L0004w
	bra	Ld6e9		; all done (rts)
;
Ld6cc:	coma			; change sign
	negb
	sbca	#$ff
	lsrd			; / 2
	tba			; into A
	ldx	L0004w		; get Fuel required
	jsr	Ld8a5		; D = (A*IX)/256
	std	L000bw
	ldaa	Lf569		; 20%				51/256
	ldx	L000bw		; 20 % of that
	jsr	Ld8a5		; D = (A*IX)/256
	coma			; change sign back
	negb
	sbca	#$ff
	addd	L0004w
	std	L0004w		; stash closed loop fuel modified PW
Ld6e9:	rts
;
; -----------------------------------------------------------------------------
; Handle the Saving and Restoring of any specified dataset here
;
Ld6ea:	brset	L007f %10000000 Ld6ef  ; Save/Restore State requested
	rts			; nope - return
;
; A Save or Restore operation hase been requested....
;
Ld6ef:	brclr	L005d %01000000 Ld6f8 ; Not waiting on the timer to finish
	brset	L007f %00100000 Ld709 ; Restore operation needs to get started
	rts
;
; The 10 ms timer isn't active so lets see what we can do
;
Ld6f8:	brclr	L007f %00010000 Ld709 ; Not a Save operation - a Restore
	brclr	L005d %00010000 Ld778 ; Programing has not started yet
	jmp	Ld7ee		; in the EEPROM Progaming phase
;
; Somekind off error occured, checksum or illegal command structure....
;
Ld703:	ldaa	#%01000000	; signal error occured
	staa	L007f		; stash it
	bra	Ld767		; finish up
;
; -------------------------------
; Enter here to initiate a Restore operation......
;
Ld709:	ldaa	L007f		; get command bits
	anda	#$03		; mask out dataset bits
	bne	Ld719		; not the Base Dataset
	brclr	L007f %00100000 Ld703 ; not a Restore either ! - error out
	ldy	#Lf740		; point to our ROM Base Dataset modifiers
	bra	Ld754		; move Base dataset into RAM
;
Ld719:	cmpa	#$01		; Dataset 'A' ?
	bne	Ld726		; nope
	ldx	#$b600		; point 'A' dataset
	ldy	#$b63f		; checksum location
	bra	Ld73a		; move it in
;
Ld726:	cmpa	#$02		; Dataset 'B' ?
	bne	Ld733		; nope - must be 'C'
	ldx	#$b640		; start of dataset 'B'
	ldy	#$b67f		; checksum
	bra	Ld73a
;
Ld733:	ldx	#$b680		; start of Dataset 'C'
	ldy	#$b6bf		; checksum
Ld73a:	clra
	clrb			; clear checksum return register
	stx	L000bw		; stash start address of EEPROM dataset
	jsr	Ldc78		; compute checksum
;
	if	not mis11x
	pshb			; on stack....
	pulb			; off again ???
	endif
;
	ldaa	$00,Y		; get checksum from EEPROM
;
	if	not mis11x
	psha			; ??
	pula
	endif
;
	cmpb	$00,Y		; are they the same ?
	bne	Ld703		; nope - error
	brclr	L007f %00100000 Ld764 ; Should have been set - restore bit !!!
	ldy	L000bw		; get EEPROM address of the dataset
;
; IY - pointing to dataset to restore....
;
Ld754:	ldx	#L0080		; point to the start work dataset in RAM
Ld757:	ldaa	$00,Y		; get abyte from the source
	staa	$00,X		; stash into RAM
	iny
	inx
	cpx	#$00b6		; end of transfer ?
	bcs	Ld757		; nope - more
Ld764:	clr	L007f		; clear command flag - operation succeeded
Ld767:	clr	L00b6		; clear EEPROM address index
	bclr	L005d %01110000 ; clear flags
;				; x0xxxxxx - signal no timer interrupt pending
;				; xx0xxxxx - erase/prgm operation inactive
;				; xxx0xxxx - not programing now
	ldx	#register_base
	bclr	$22,X %00100000 ; clear OC3 interrupt - EEPROM programming
	clr	$3b,X		; set EEPROM for normal read only operation
	jmp	Ld8a4		; rts - all done
;
; -------------------------------
; Initialize Saving a Dataset or still prepairing by erasing .....
;
Ld778:	brset	L005d %00100000 Ld7a8 ; erase active now - do next row
	bset	L005d %00100000 ; signal we are now erasing the EEPROM
	bclr	L00b3 %10000000 ; Assure Base Timing Set Off
	clr	L00b6		; clear EEPROM address index
	ldaa	L007f		; get the command flags
	anda	#%00000011	; mask out the dataset requested
	bne	Ld78e		; not Base dataset
	jmp	Ld703		; Can't save Base datase - error out
;
Ld78e:	cmpa	#$01		; save dataset 'A' ?
	bne	Ld798		; nope
	ldy	#$b600		; point to it's address in EEPROM
	bra	Ld7b0
;
Ld798:	cmpa	#$02		; 'B' ?
	bne	Ld7a2		; nope
	ldy	#$b640		; its address
	bra	Ld7b0
;
Ld7a2:	ldy	#$b680		; must be 'C'
	bra	Ld7b0
;
; enter here to erase the next row of the EEPROM
;
Ld7a8:	ldy	#$b600		; EEPROM base
	ldab	L00b6		; get the start of the appropriate row
	aby			; IY now points into the row to erase
;
; What we are doing here is erasing a 16 byte EEPROM row one row at a time.
;  Being that you can only change a bit from an 1 to a 0 during a write
;  operation we need to erase the storage area completely (sets all bits to 1)
;  first.  Each one of the Datasets occupy 4 rows so we need to do this 4 times.
;
Ld7b0:	ldx	#register_base
	ldaa	#%00001110	; Setup the EEPROM for erasing a row
;				; xxxxxxx1x - bus configured for programming
;				; xxxxxx1xx - Erase Mode
;				; xxxxx1xxx - Row Erase
	staa	$3b,X		; do it
	staa	$00,Y		; write to EEPROM to sequence EELAT/EPGM bits
;				;  This will erase an entire 16 byte row
	bset	$3b,X %00000001 ; we can now turn on the charge pump
	ldd	#$1388		; 5000 - 10ms (5000*2us_clock
	addd	$0e,X		; plus the current timer count
	std	$1a,X		; stash it in OC3 timer data register
	bclr	$23,X %11011111 ; enable the OC3 timer interrupt
	bclr	$20,X %00110000 ; assure time not connected to an output pin
	bset	$22,X %00100000 ; turn on hardware interrupt
	bset	L005d %01000000 ; signal timer interrupt pending
	pshy
	pula
	pulb			; get row address into D
	tba			; low byte into A (perserve org low byte in B)
	anda	#$30
	cmpa	#$30		; 4th row just erased ?
	bne	Ld7e7		; nope
	bclr	L005d %00100000 ; signal erase operation completed
	bset	L005d %00010000 ; signal ok to start programing now
	clr	L00b6		; clear row accumulator
	jmp	Ld8a4		; rts
;
Ld7e7:	addb	#$10		; add another 16 bytes to point to next row
	stab	L00b6		; stash row index
	jmp	Ld8a4		; rts
;
; --------------------------------
; We are in the actual EEPROM programing phase now....
;
Ld7ee:	brset	L005d %00100000 Ld81e ; Not the first time here
	bset	L005d %00100000 ; signal EEPROM operation active
	clr	L00b6		; clear EEPROM address pointer
	ldaa	L007f		; get the command
	anda	#$03		; mask out which dataset we are dealing with
	bne	Ld801		; ok - not trying to save the Base Dataset
	jmp	Ld703		; base dataset spec'd - error out
;
Ld801:	cmpa	#$01		; Dataset 'A' ?
	bne	Ld80b		; nope
	ldy	#$b600-1	; point to 'A' location - 1
	bra	Ld819
;
Ld80b:	cmpa	#$02		; 'B' ?
	bne	Ld815		; nope
	ldy	#$b640-1
	bra	Ld819
;
Ld815:	ldy	#$b680-1	; Dataset 'C'
Ld819:	ldx	#L0080-1
	bra	Ld83f
;
; Enter here if not the first time ....
;
;  L00b6 - contains the low order byte of the next EEPROM address to write...
;
Ld81e:	ldy	#$b600-1	; point to EEPROM base
	ldab	L00b6		; get the low byte of the address
	aby			; IY now points to last address programed
	ldaa	$00,Y		; get last byte from EEPROM
;
	if	not mis11x
	psha
	pula
	endif
;
	ldx	#L0080-1
	ldab	L00b6		; get the low byte of the next address
	andb	#$3f		; just leave use with the lower 0-63 byte offset
	abx			; IX - points to last source byte
	ldab	$00,X		; get it
;
	if	not mis11x
	pshb
	pulb
	endif
;
	cba			; should be the same
	bne	Ld85d		; they weren't !
	cpx	#L00b5		; last byte written ?
	beq	Ld843		; yes - checksum time
Ld83f:	ldab	$01,X		; get next byte to write
	bra	Ld869		; do it
;
Ld843:	ldx	#$b600
	ldab	L00b6		; get the low order byte of the next address
	andb	#%11000000	; Clear the 0-63 bits so all we have left
;				;  is the bits neseccary to compute the start
;				;  of the correct EEPROM dataset page
	abx			; IX - points to start of correct dataset
	pshx
	pula
	pulb
	addb	#$3f		; compute ending address
	pshb
	psha
	puly
	clra
	clrb			; clear checksum return register
	jsr	Ldc78		; compute checksum
	dey			; point to checksum area
	bra	Ld869		; save it
;
; The last byte programed did not match the source byte.  Compute the address
;  of the checksum byte (minus one) and write a zero to it.  This will
;  invalidate the dataset because the checksum wont compute correctly.
;
Ld85d:	ldy	#$b63e		; this is one byte before the checksum area
	tba
	ldab	L00b6		; get the low order byte of the next address
	andb	#$c0		; make an index pointing to the correct page
	aby			; IY - points to the checksum-1 of the dataset
	clrb			; write a zero to the checksum stash
;
; Program the next byte in B ................
;
Ld869:	ldx	#register_base
	ldaa	#%00000010	; configure bus for programing
	staa	$3b,X
	stab	$01,Y		; program the next byte
	bset	$3b,X %00000001 ; we can now turn on the charge pump
	iny			; IY to the address we just programed
	ldd	#$1388		; 5000 - 10ms (5000*2us_clock
	addd	$0e,X		; plus the current timer count
	std	$1a,X		; stash it in OC3 timer data register
	bclr	$23,X %11011111 ; enable the OC3 timer interrupt
	bclr	$20,X %00110000 ; assure time not connected to an output pin
	bset	$22,X %00100000 ; turn on hardware interrupt
	bset	L005d %01000000 ; signal timer interrupt pending
	pshy			; current address to D
	pula
	pulb
	tba			; Save the low byte in B of the actual address
	anda	#$3f
	cmpa	#$3f		; all done ?
	bne	Ld8a1		; nope
	bclr	L005d %00110000 ; clear program/eeprom action
	bclr	L007f %00010000 ; clear need to Save bit
	clr	L00b6		; clear work address index
	bra	Ld8a4		; rts
;
Ld8a1:	incb			; point to the next byte
	stab	L00b6		; save the low byte of the next address
Ld8a4:	rts
;
; -----------------------------------------------------------------------------
; Multiply A times IX then divide by 256 and return result in D
;
;  D = (A * IX) / 256
;
Ld8a5:	pshx
	tsx			; point into stack
	ldab	$01,X		; get low byte of IX
	staa	$01,X		; hold A in this location
	mul			; D = A*B
	adca	#$00		; if carried then bump
	ldab	$00,X		; get hi byte
	staa	$00,X		; stash current hi byte here
	ldaa	$01,X		; get entry A back
	mul
	addb	$00,X		; add B from original multiply
	adca	#$00		; bump hi if rolled
	pulx
	rts
; -----------------------------------------------------------------------------
; never called !!!!!!!!
;
	if	not mis67x
mis67:
Ld8bb:	pshx
	tsx
	ldab	$01,X
	staa	$01,X
	mul
	stab	L000bw
	ldab	$00,X
	staa	$00,X
	ldaa	$01,X
	mul
	addb	$00,X
	adca	#$00
	pulx
	rts
	endif
;
; -----------------------------------------------------------------------------
;  Do a fractional divide of what is in register 'D' and the value in L000fw,
;   then multiply the results to the power of 2^IY-1...
;	Entry:	D      - numerator
;		L000fw - denominator
;		IY     - power of 2 (+1) to multiply by
;	Return: D      - results
;
; Note: If L000fw equals zero or overflow durning multiplication then D=$FFFF
;
Ld8d1:	ldx	L000fw
	idiv			; D/IX	IX=Quoteint  D=Remainder
	bcs	Ld8e9		; denominator was zero - divide by zero !
	stx	L000bw
	ldx	L000fw
	fdiv
	xgdx
Ld8dc:	dey			; multiply * 2
	beq	Ld8ed		; done
	lsld
	rol	L000cw
	rol	L000bw
	bcc	Ld8dc		; didn't overflow
Ld8e9:	ldd	#$ffff
	rts
;
Ld8ed:	ldd	L000bw
	rts
;
; -----------------------------------------------------------------------------
; Update specified memory stash.  If bit 6 of L0058 clear then just update
;  the memory stash directly.  If set then only bring the stash half way to
;  the entry value....
;  This bit gets set once we have made it thru the Calibration portion of the
;  atleast one time....
;
;	Entry:	A  - value to stash
;		IX - where to stash it
;	Return: A  - what we came up with
;
Ld8f0:	brclr	L0058 %01000000 Ld904 ; have never made it thru Calibration yet
	ldab	$00,X		; get old value
	sba			; A = A - B
	bcc	Ld900		; new value is higher
	nega			; new value is lower
	lsra			; difference divided by 2
	sbcb	#$00		; less carry
	nega
	bra	Ld903
;
Ld900:	lsra			; difference between old and new divided by 2
	adcb	#$00		; one more if we carry'd out
Ld903:	aba			; add half of difference to new value
Ld904:	staa	$00,X		; stash the results
	rts
;
; -----------------------------------------------------------------------------
; Look up a value in the entry table.  What is returned in L001bw is the index
;  into the table of the closest located item.	It is in inverse order (higher
;  value at the top of the table and zero by the time it reaches the bottom).
;  Also it is a base 0 value (8 items in table so if the first is matched then
;  it returns a 7).
;  'B' is the percentage between the two table entries and the entry lookup
;  value.  If it matches an entry exactly B=0.	This distance is B/255.
;
;  NOTE: Look at Lf2a8 to see how it responds to a table..
;
;	Entry:	D      = value to locate
;		L001bw = number-1 of items in table
;		IX     = lookup table
;	Return: B      = fractional difference between closest entries
;		L001bw = major table index of located entry
;
Ld907:	std	L000dw		; stash
	subd	$00,X
	bhi	Ld90f		; didn't carry and not the same
Ld90d:	clrb
	rts
;
Ld90f:	dec	L001bw		; one less lookup table item
	bmi	Ld93a		; past end
	inx			; point to next entry
	inx
	ldd	L000dw		; get entry value
	subd	$00,X
	bhi	Ld90f		; haven't found a larger value yet - loop
	beq	Ld90d		; exact match
	ldd	$00,X		; get this table entry
	dex			; point to previous one
	dex
	subd	$00,X		; D = difference
	std	L000fw		; stash it
	ldd	L000dw		; get entry back
	subd	$00,X		; less previous table entry
	ldy	#$0009		; times 256  (2^8)
	jsr	Ld8d1		; D = (D / L000fw) * 256
	tsta			; overflow ?
	beq	Ld936		; nope
	ldab	#$ff		; return 255
Ld936:	inc	L001bw		; adjust entry position
	rts
;
Ld93a:	clrb
	bra	Ld936
;
; -----------------------------------------------------------------------------
; Return a value, interpolated (weighted average) as neccessary, from the
; specified table.
;
;	Entry:	L0013w - major index into a lookup table
;		L0011w - the fractional value
;		IX     - table address
;	Return: A      - table value interpolated as needed
;
Ld93d:	ldab	L0013w		; get the index in to the table
	abx			; point to entry
	dex			; the one before
	ldd	$00,X		; get it and the one above
	sba			; get the difference	A=A-B
	ldab	L0011w		; load B with fractional component
	bcs	Ld94d		; first entry lower than second - negative dir
	mul			; D=A*B
Ld949:	ldab	$01,X		; get second (min entry)
	aba			; plus any inerpolated amount	A=A+B
	rts
;
Ld94d:	nega			; change sign
	mul
	nega			; change sign back
	bra	Ld949
;
; -----------------------------------------------------------------------------
;  Used in Idle Air percentage calculations.
;	Entry:	IX - pointing to table
;		L0013w - index of previous lookup
;		L0011w - returned value
;
; All this is BS because I think we always end up with the same answer.  With
;  an idle activity percentage between 0-100% (0 to 128 stash value), the
;  output from the previous search is going to put a 7 thru 4 into L0013w,
;  with some other value into L0011w.  The clincher is the the look-up table
;  at Lf41c contains noting but 8 $1a (26) values.  When the two values are
;  loaded into D and then subtracted from each other the result is always
;  zero.  Carry will not be set and the next multiplication will be by 0
;  so we get nothing except the a table value for the result....
;
;  What I see always return is:
;		D = $1a00 - 6656
;		L0059 xxxxxx1x - always set
;				 looks to be a sign flag if worked
;
	if	not mis15x
;
Ld952:	ldab	L0013w		; index (4-7)
	abx
	dex
	ldd	$00,X
	sba			; A=A-B
	ldab	L0011w		; value
	bcs	Ld967		; won't take
	mul			; D=A*B
	pshb
	bset	L0059 %00000010
Ld962:	ldab	$01,X
	aba			; A=A+B
	pulb
	rts
;
Ld967:	nega			; change sign
	mul
	pshb
	bclr	L0059 %00000010
	nega
	bra	Ld962
;
	endif
;
; -----------------------------------------------------------------------------
; This guy looks up into the large Spark and Fuel tables
;
; The tables and indexes are set up so if you are looking at an even boundry
;  it is the next column (16 or 8 bytes away) that is the base column.
;
;
;	Entry:	B      - index of cell
;		L000bw - how far away from an exact RPM match	    (fractional)
;		L0012w - how far away from an exact Load match	    (fractional)
;		IX = address of table  (-16-1)	or (-8-1)
;		L0059 xxxxx1xx - 8x8 cell matrix
;		L0059 xxxxx0xx - 8x16 cell matrix
;
;	Return: D - interpolated requirement
;
Ld970:	abx			; point into matrix table
	ldab	$00,X		; get previous entry of previous rpm
	subb	$01,X		; less next entry
	bsr	Ld9b2		; times row fractional part	D = L000bw * B
	adda	$01,X		; add in
	xgdy			; hold in IY
	brclr	L0059 %00000100 Ld989 ; 8x16 cell matrix
	ldab	$08,X
	subb	$09,X
	bsr	Ld9b2		; times row fractional part	D = L000bw * B
	adda	$09,X
	bra	Ld991
;
Ld989:	ldab	$10,X		; get entries from next column
	subb	$11,X		; difference
	bsr	Ld9b2		; times row fractional part	D = L000bw * B
	adda	$11,X		; add
Ld991:	std	L000bw		; stash this amount
	xgdy			; get first difference
	subd	L000bw		; less this
	bcs	Ld9a2		; went negative
	xgdx			; put into IX
	ldaa	L0012w		; get column fractional part
	jsr	Ld8a5		; D = (A*IX)/256
Ld99f:	addd	L000bw		; plus base table value
	rts
;
Ld9a2:	coma			; change sign
	negb
	sbca	#$ff
	xgdx			; into IX
	ldaa	L0012w		; get column fractional value
	jsr	Ld8a5		; D = (A*IX)/256
	coma			; change sign back
	negb
	sbca	#$ff
	bra	Ld99f
;
; -----------------------------------------------------------------------------
; Signed multiplication
;	Entry:	CY     - set by previous subtraction (neg numbers)
;		L000bw - one multipier
;		B      - other multiplican
;	Return: D      - result
;
Ld9b2:	ldaa	L000bw
	bcs	Ld9b8		; negative numbers
	mul			; multiply positives
	rts
;
Ld9b8:	negb			; change sign of B
	mul			; multiply
	coma			; change sign back
	negb
	sbca	#$ff
	rts
;
; -----------------------------------------------------------------------------
; Get the user Fuel/Spark modifiers from the tables starting at L0080/L0098
; The Fuel table is 6 rows (RPM) x 4 columns (Load)
; The Spark table is 6 rows (RPM) x 3 columns (Load)
;
;	Entry:	B - number of rows-1  (RPM's)
;		IX - pointing to cell in row before matched cell
;		L000bw - how far away from an exact RPM match
;		L0012w - how far away from an exact Air Charge match
;
;	Return: A - interpolated modifier value
;
Ld9bf:	clra
	xgdy			; stash how far to next Load cell
	ldab	$00,X		; get modifier from previous Load column
	subb	$01,X		; less next one
	bsr	Ld9b2		; multiply by fractional part	D = L000bw * B
	adda	$01,X		; plus base
	xgdy			; get number of rows back - Difference into IY
	abx			; point to cell
	ldab	$01,X		; get previous
	subb	$02,X		; get difference
	bsr	Ld9b2		; times fractional		D = L000bw * B
	adda	$02,X		; plus base
	std	L000bw		; hold
	xgdy			; get difference of previous cells
	subd	L000bw		; less this difference
	bcs	Ld9e6		; negative
	xgdx			; put into IX to multiply
	ldaa	L0012w		; get fractional Load amount
	jsr	Ld8a5		; D = (A*IX)/256
Ld9e3:	addd	L000bw		; plus base
	rts
;
Ld9e6:	coma			; change sign
	negb
	sbca	#$ff
	xgdx
	ldaa	L0012w		; fractional Load
	jsr	Ld8a5		; D = (A*IX)/256
	coma			; correct sign
	negb
	sbca	#$ff
	bra	Ld9e3		; finish up
;
; -----------------------------------------------------------------------------
;  Return the correct value from a 16 byte lookup table.  The upper 4 bits of
;   the entry value points to an entry in the table.  The lower bits are
;   used to interpolate between two entries in the table....
;
;	Entry:	B  - index look-up value
;		IX - 16 byte lookup table address
;	Return: A  - interpolated value
;
Ld9f6:	tba			; put a copy into A
	anda	#%00001111	; low bits only
	staa	L000bw		; save them for a bit
	lsrb			; divide by 2
	lsrb			; 4
	lsrb			; 8
	lsrb			; 16
;
; Being that we just divided the entry value by 16 and lost the lower 4 bits
;  we are pointing to the next entry in the base 1 table.
;
	abx			; point IX into the table (rounded up)
	ldaa	$00,X		; get it's value
	cmpb	#$0f		; did we point to then highest value in table ?
	beq	Lda15		; yes - all done
	ldab	$01,X		; get next table value
Lda08:	sba			; get difference between the two values (A=A-B)
	ldab	L000bw		; get lower 4 bits
	bcs	Lda16		; if we had a carry from above subtraction bra
;
; Got the difference between this entry and the next.  Do a linear interpolation
;  between the two points to determine the returned results.
;
	mul			; Diff * entry low 4 bits (0-15)      D = A * B
	lsrd			; /2
	lsrd			; /4
	lsrd			; /8
	lsrd			; /16
Lda12:	ldaa	$00,X		; get the first value back
	sba			; less the interpolated difference  A = A - B
Lda15:	rts
;
Lda16:	nega			; change sign of A
	mul			; D = A * B
	lsrd			; /2
	lsrd
	lsrd
	lsrd			; /16
	negb
	bra	Lda12
;
; -----------------------------------------------------------------------------
;  Return the correct value from a 8 byte lookup table.  The upper 3 bits of
;   the entry value points to an entry in the table.  The lower bits are
;   used to interpolate between two entries in the table....
;
;	Entry:	B  - look-up index value
;		IX - 8 byte lookup table address
;	Return: A  - interpolated value
;

Lda1f:	tba			; copy into A
	anda	#%00011111	; mask out interoplation bits
	staa	L000bw		; stash for later
	lsrb			; / 2
	lsrb			; / 4
	lsrb			; / 8
	lsrb			; / 16
	lsrb			; / 32
	abx			; point to entry
	ldaa	$00,X		; get it
	cmpb	#$07		; last entry in table ?
	beq	Lda40		; yes - return
	ldab	$01,X		; get next
	sba			; A = A - B
	ldab	L000bw		; get low bits
	bcs	Lda41		; negative
;
; Got the difference between this entry and the next.  Do a linear interpolation
;  between the two points to determine the returned results.
;
	mul
	lsrd
	lsrd
	lsrd
	lsrd
	lsrd
Lda3d:	ldaa	$00,X		; get first entry back
	sba			; lees the difference
Lda40:	rts
;
Lda41:	nega			; need to chenge the sign
	mul
	lsrd
	lsrd
	lsrd
	lsrd
	lsrd
	negb
	bra	Lda3d
;
; -----------------------------------------------------------------------------
; Can Not find anywhere that calls this sub-routine
;
;
;---------------------------------------------
; TABPRI
; PRELIMINARY INJECTION Vs. COOLANT
; 1024uS/bit
;
; NOT USED with 7+1 Shutter wheel
;  phase strategy
;
; Table - usec * 1024
;---------------------------------------------
;
	if	not mis17x

mis17:
Lda4b:	brclr	L005a %00001111 Lda50
	rts
;
Lda50:	pshb
	ldx	#Lf3dc		; point to coolant temp to pulse width maping
	ldab	L0003		; get TH2O - Water Temperature (adjusted)
	jsr	Ld9f6		; lookup injector pulse width
	clrb			; make word
	std	L0025		; stash new Injector Pulse Width
	pulb
	jsr	Lda66
	ldab	#$02
	jsr	Lda66
	rts
;
; B = 0 thru 3
;
Lda66:	ldx	#Lff4a
	abx
	ldaa	$00,X
	oraa	L005a
	staa	L005a
	lslb			; address are words
	ldx	#Lff38		; point to the 6840 timer's data registers
	abx			; point to address of the injector timer
	ldd	L0025		; get Injector Pulse Width
	if	not mis51x
mis51b: ldy	L0025		; mistake !!! - not used
	endif
	jsr	Lda7e		; fire the Injector
	rts

	endif
;
; -----------------------------------------------------------------------------
;  Fire the specified Injector.
;	Entry:	D - desired pulse width (at 250KHz/4us rate)
;		IX - pointing to timer data register
;	Return: IY = register_base ($1000)
;
Lda7e:	cpd	#$0064		; pulse width over .4ms ?
	bcc	Lda89		; yes - setup timer
;
	if	not mis65x
mis65:	ldy	#register_base	; just forget it
	endif
;
	rts
;
Lda89:	pshb
	psha
	ldd	#$a0a1		; A = Enable Output in One-Shot mode
				; B = Same as A but select Cntrl Register #1
	staa	timer_cntr_reg2 ; turn on #2
	staa	timer_cntr_regx ; turn on #3
	stab	timer_cntr_reg2 ; select Control Register 1
	staa	timer_cntr_regx ; turn it on
	ldy	#register_base
	ldab	$00,X		; get first byte of the registers address
	ldx	$00,X		; IX now points to the appropriate data register
;
; 3200	00110010 00000000
; 3400	00110100 00000000
; 3600	00110110 00000000
; 1018	00010000 00011000
;	  |<--- test this bit to determine which timer we are dealing with
;
	andb	#%00100000	; is it the external timer (6840) ?
	beq	Ldaa9		; nope - our internal timer (INJ-D)
	jmp	Ldafb		; yep - set it
;
; The internal timer OC2 INJ-D has been selected...
;
Ldaa9:	bset	$20,Y %11000000 ; set output line high (injector On) after
;				;  compare
	bclr	L005d %00000001 ; clear overflow bit
	ldd	timer_tcnt_reg	; get the current timer count
	addd	#$0005		; add a little
	std	toc2_data_reg	; stash count
	bclr	$23,Y %10111111 ; clear timer OC2 interrupt flag
	ldd	toc2_data_reg	; why ?????
	std	toc2_data_reg
	pula			; get the injector On time
	pulb
	tsta			; under $8000 (130ms) ?
	bpl	Ldacb		; yes
	bset	L005d %00000001 ; signal overflow
Ldacb:	lsld			; times 2 (internal timer running at 500KHz)
	pshb			; save count
	psha
	addd	toc2_data_reg	; add in current count
	std	toc2_data_reg	; stash pulse width
	pulx
	brclr	L005d %00000001 Ldaea ; no overflow
	cpx	#$0044		; less than 1.4ms (68) programmed ?
	bls	Ldae7		; yes
;
; Let timer go till till interrupt occurs
;
	bclr	$23,Y %10111111 ; clear OC2 timer interrupt flag
	bset	$22,Y %01000000 ; enable OC2 interrupt
	rts
;
Ldae7:	bclr	L005d %00000001 ; clear overflow bit
Ldaea:	bset	$20,Y %10000000 ; set output line low at compare time
	bclr	$20,Y %01000000 ;  this will keep injector Off most of the time
	bclr	$22,Y %01000000 ; disable interrupt
	bclr	$23,Y %10111111 ; clear OC2 timer interrupt flag
	rts
;
; Set the External MC6840 timer count value.  Each count is 4us
;	Entry:	IX - MSB of the data register for the selected timer
;		 D - count to program
;
Ldafb:	pula
	pulb
	staa	$00,X		; stash the upper byte
	xgdx
	addd	#$0100		; move to the lower byte address
	xgdx
	stab	$00,X		; stash lower byte
	rts
; =============================================================================
; Check for any warning errors that need to get sent to the controller....
;
Ldb07:	ldaa	L00b8		; get the MAP ADC reading
	cmpa	Lf677		; above 4.94 volts ?			253
	bcc	Ldb18		; yes - error too high
	cmpa	Lf678		; above 19 mv (one ADC count)		  1
	bhi	Ldb20		; yes - OK
	bset	L00bb %10000000 ; signal MAP voltage too low
	bra	Ldb1b
;
Ldb18:	bclr	L00bb %10000000 ; signal MAP voltage too High
Ldb1b:	bset	L00b9 %10000000 ; signal MAP sensor error
	bra	Ldb23
;
Ldb20:	bclr	L00b9 %10000000 ; clear MAP sensor error
Ldb23:
	if	not mis8x	; mis8:
	cmpa	Lf679		; MAP below ~21"  (ADC=55) ?
	bcc	Ldb2d		; yes
	bset	L00ba %00010000 ; signal so - Never Used Anywhere
	bra	Ldb30
;
Ldb2d:	bclr	L00ba %00010000 ; MAP below 21"
;
	endif
;
Ldb30:	ldaa	L0022		; get the ADC TPS count
;
	if	not mis8x	; mis8:
	bset	L00ba %00001000 ; Never tested anywhere ?
	cmpa	L001c		; throttle plates closed ?
	bls	Ldb41		; yes
	cmpa	Lf50a		; over 4.7 volts ?			240
	bhi	Ldb41		; yes
	bclr	L00ba %00001000 ; Never Tested anywhere ?
	endif
;
Ldb41:	cmpa	Lf680		; TPS ADC at or below 2 ?
	bls	Ldb50		; yes - too low - error
	cmpa	Lf67f		; below 253
	bcs	Ldb58		; yes - TPS in range
	bclr	L00bb %00001000 ; TPS out of range too high
	bra	Ldb53		; TPS Error
;
Ldb50:	bset	L00bb %00001000 ; signal TPS out of range too low
Ldb53:	bset	L00b9 %00010000 ; signal Thottle Input error
	bra	Ldb5b
;
Ldb58:	bclr	L00b9 %00010000 ; clear Thottle Input error
Ldb5b:	bclr	L00b9 %01000000 ; clear H2O Temperature error
	bclr	L00ba %01000000 ; clear H20 Temperature error
	ldab	L0024		; get COOL ADC reading
	cmpb	Lf67c		; below lower coolant temperature trip point ?
	bls	Ldb73		; yes - not too cold (colder than -40)
	bset	L00b9 %01000000 ; signal H2O Temperature error
	bset	L00ba %01000000 ; signal H20 Temperature error
	bclr	L00bb %00000100 ; signal H20 out of range too Cold
	bra	Ldb86		; join MAT
;
Ldb73:	cmpb	Lf67e		; Coolant ADC too high (hotter than 220 degrees)
	bcc	Ldb7b		; nope
	bset	L00b9 %01000000 ; signal H2O Temperature error - too Hot
Ldb7b:	cmpb	Lf67d		; warmer than 250 degrees ?
	bcc	Ldb86		; nope
	bset	L00bb %00000100 ; signal Coolant too Hot
	bset	L00ba %01000000 ; signal H20 Temperature Error
Ldb86:	ldab	L0023		; get MAT ADC reading
	cmpb	Lf67a		; colder than -40 ?
	bls	Ldb92		; nope
	bclr	L00bb %00000010 ; signal MAT out of range too Cold
	bra	Ldb9a		; signal error
;
Ldb92:	cmpb	Lf67b		; warmer than +248 degrees ?
	bcc	Ldb9f		; nope - ok sensor then
	bset	L00bb %00000010 ; signal MAT out of range too Hot
Ldb9a:	bset	L00b9 %00001000 ; signal TAIR - Air Temperature error
	bra	Ldba2		; now ckeck the battery
;
Ldb9f:	bclr	L00b9 %00001000 ; clear TAIR error
;
; Lets check for the Battery voltage being in range next ......
;
Ldba2:	bclr	L00b9 %00100000 ; clear Voltage Hi/Lo error
	ldab	L000a		; get Battery Voltage
	cmpb	Lf681		; voltage above the upper trip point ?
	bhi	Ldbc4		; yes - signal error
	ldaa	L0042		; get timing_period / 16
	beq	Ldbbf		; motor at is not turning
	adda	#$18		; If L0042 is above 232, which is 505 RPM,
;				;  A will carry signaling we are below 505 RPM.
	bcs	Ldbbf		; motor below idling RPM  (505 RPM)
	cmpa	L0061		; below Target Idle RPM ?
	bhi	Ldbbf		; yes - the motor is turning slowly
	cmpb	Lf682		; lower than off idle trip point ?
	bcs	Ldbc4		; yes - error
	bra	Ldbc7		; ok
;
Ldbbf:	cmpb	Lf683		; to low at idle ?
	bcc	Ldbc7		; nope - ok
Ldbc4:	bset	L00b9 %00100000 ; signal Voltage Hi/Lo error
Ldbc7:	rts
; ----------------------------------------------------------------------------
;
; Adjust the Spark value by the modifier
;	Entry:	A - spark advance
;		B - modifier
;	Return: A - new spark value
;
;  A count of 128 equals a zero degree modifier.
;   160 = +8 degrees   64 = -16 degrees
;
Ldbc8:	subb	#$80		; remove bias
	bmi	Ldbda		; negative modifier
	cmpb	Lf705		; Max Spark change allowed - 16 deg
				;  better be no higher than 64 (16 degrees)
	ble	Ldbd4		; ok
	ldab	Lf705		; Max Spark change allowed - 16 deg
Ldbd4:	aba			; add in the modifier value	A=B+A
	bcc	Ldbd9		; didn't carry - ok
	ldaa	#$ff		; limit to 255 (63 degrees)
Ldbd9:	rts
;
Ldbda:	psha			; save spark advance amount
	ldaa	Lf705		; 64 - max amount of adjustment (-16 degrees)
	nega			; change signs
	cba			; within modification window ?
	ble	Ldbe3		; yes
	tab			; put max amount we can modify into B
Ldbe3:	pula			; get spark advance back
	aba			; update it
	bcs	Ldbe8		; overflowed
	clra			; min zero
Ldbe8:	rts
;
; -----------------------------------------------------------------------------
; Modify a value by +/- 50% max........
;
; Assure that the modifier is 128 +-64 counts.	If not then limit multiplier
;  to the range of 64-192.    Remember that a multiplier above 128 is a
;  positive percentage and below is negative generally with a full deviation
;  of 64 counts representing 50% worth of modification.
;
;	      modifier
;   D = IX * ---------
;		128
;
;   If B=192 then D = IX * (192/128) = IX * 1.50
;   If B=128 then D = IX * (128/128) = IX * 1.00
;   If B= 64 then D = IX * ( 64/128) = IX * 0.50
;
;
;	Entry:	B  - modifier value.  128 = 0  +/-64 (+/-50%) max deviation
;		     Above 128 is a positive modifier.....
;		IX - Value to adjust
;	Return: D  - results
;
Ldbe9:	tstb			; positive modifier (128 or above) ?
	bmi	Ldbf9		; yes
	ldaa	#$80		; 128
	suba	Lf704		; Max value for Fuel Modifier (calstar) - 50%
	cba
	bls	Ldc06		; ok - less than or equal 64
	ldab	Lf704		; Max value for Fuel Modifier (calstar) - 50%
	bra	Ldc06
;
Ldbf9:	tba			; put a copy into A
	suba	#$80
	cmpa	Lf704		; Max value for Fuel Modifier (calstar) - 50%
	bls	Ldc06		; ok - not higher than +64
	ldab	Lf704		; Max value for Fuel Modifier (calstar) - 50%
	addb	#$80		; 192 max then (128+64)
Ldc06:	xgdx			; what to be modifed into D
	lsld			; times 2
	xgdx			; back to X
	tba			; put B into A to multiply
	jsr	Ld8a5		; D = (A*IX)/256
	rts
; -----------------------------------------------------------------------------
; Compute MAP ADC high altitude compression compensation value.
; If at initial key-on we are at a high altitude location we will need to
; compute a compensation value that will be added to the MAP ADC readings to
; compensate for air compression.
;
;	Entry:	A - MAP ADC reading
;	Return: L0008 - altitude compression compensation factor
;
;		If (Pressure < ~750 feet) {
;		   L0008 = 0;
;		} elsif (Pressure < ~8500 feet) {
;		   L0008 = ( (750 feet-Pressure) * Compression Ratio) / 256;
;		} elsif (Pressure > ~8500 feet) {
;		   L0008 = ( (8500 feet-750 feet) * Compression Ratio) / 256;
;		}
;
;		  If A >= 233 then
;		     L0008 = 0
;		  Else If A >= 167 and A < 233 then
;		     L0008 = ((233-A) * 26) / 256
;		  Else A < 167 then
;		     L0008 = ((233-167)*26)/256 = 6
;
;     ADC	    Aprox			L0008
;    Entry	     MAP
;    000 - 173	  29" - 8"	  > 8000'	  6
;    174 - 183	   8" - 6.5"	  6500'-8000'	  5
;    184 - 193	 6.5" - 5"	  5000'-6500'	  4
;    194 - 203	   5" - 4"	  4000'-5000'	  3
;    204 - 213	   4" - 3"	  3000'-4000'	  2
;    214 - 223	   3" - 1.5"	  1500'-3000'	  1
;    224 - 255	 1.5" - 0"	  0000'-1500'	  0
;
Ldc0e:	tab			; MAP ADC reading into B
	ldaa	Lf4fe		; Barometric Pressure, Upper Threshold to Enable
				;   Altitude Correction.
				; A = 233 ~ 1"	aprox 750'
	cmpb	Lf4fe		; Barometric Pressure, Upper Threshold to Enable
				;   Altitude Correction.
				; B < 233 ?
				; Is MAP ADC above about 750 feet ?
	bcs	Ldc1a		; yes
	clra			; no - store zero - low altitude
	bra	Ldc27
;
; MAP ADC reading is above ~750 feet...
;
Ldc1a:	cmpb	Lf4fd		; Barometric Pressure, Lower Threshold to Enable
				;   Altitude Correction
				; B >= 167 ?
				; Altitude below ~8500 feet ?
	bcc	Ldc22		; yes
	ldab	Lf4fd		; Barometric Pressure, Lower Threshold to Enable
				;   Altitude Correction
				; B = 167
				; max out around 8500 feet correction
Ldc22:	sba			; get the difference between current MAP ADC
				;  and threshold...
				; A = 233 - B	    A = A - B
	ldab	Lf4fc		; Compression Ratio for Altitude Correction
				; B = 26
	mul			; D = A * B
Ldc27:	staa	L0008		; stash correction factor
	rts
;
; -----------------------------------------------------------------------------
; Add the MAP ADC altitude compression correction factor to the MAP ADC reading.;  If results larger than 255 then return 255
;
;	Entry:	A - MAP ADC reading
;	Return: A - altitude adjusted value
;
Ldc2a:	ldab	L0008		; get the compression correction factor
	aba			; A = A + B
	bcc	Ldc31		; not too large
	ldaa	#$ff		; max at 255
Ldc31:	rts
;
; -----------------------------------------------------------------------------
; What this looks like it is doing is searching for the correct injector pair
;  to fire for optimum injector timing.  There are four lists that starts at
;  Lff20.  Each one is structured in the same manner.  There are three for
;  each group (cylinder 1,4,6,7  and  8,3,5,2).  The high bit of the next group
;  delimits the previous group.  The upper nibble (bits 4-6) contain the
;  sequencer's (L0044) pattern to match.  The lowest three bits signal what
;  injector pair to fire.
;
;	Entry:	B = What group to look into
;			0 4 8 12 16 20
;	Return: B = High bit (bit 7) set if didn't match current sequencer
;		  = which injector pair to fire (0-6)
;
Ldc32:	ldx	#Lff20		; point to the base list
	abx			; point to desired group
	ldaa	L0044		; get the firing sequencer index (0-7)
	lsla			; move low four bits into the upper nibble
	lsla
	lsla
	lsla
	ldab	$00,X		; get table value
Ldc3e:	andb	#%01110000	; leave only sequencer bits to match
	cpx	#Lff37		; past end of table ?
	bls	Ldc48		; not yet
	ldab	#$80		; return failure (1000 0000)
	rts
;
Ldc48:	cba			; found match ?
	beq	Ldc51		; yes
	inx			; point to next
	ldab	$00,X		; get it
	bpl	Ldc3e		; not start of next group so keep looking
	rts
;
Ldc51:	ldab	$00,X		; get Injector timing
	andb	#%00001111	; loose sequencer index bits
	rts
;
; -----------------------------------------------------------------------------
; Convert the entry timing period into a value that represents RPM in
;  25 rpm units.  Lowest RPM limit is 458 rpm and the highest than can be
;  represented in a byte is ~6,400 rpm
;
;	Entry:	D - ignition timing period * 16
;	Return: B - RPM/25
;	Uses:	L000fw locally
;
;	RPM    Period	   *16	    Result
;      <458			      19
;	500	3750	  60,000      20
;      1000	1875	  30,000      40
;      2000	 937.5	  15,000      80
;      3000	 625	  10,000     120
;      4000	 468.75    7,500     160
;      5000	 375	   6,000     200
;      6000	 312.5	   5,000     240
;     >6400	 293	   4,688     255
;
Ldc56:	cpd	#$fffc		; faster than 458 RPM ?
	bls	Ldc60		; yes
	ldab	#$13		; 19
	bra	Ldc77		; ret
;
Ldc60:	cpd	#$1250		; faster than 6,400 RPM ?
	bcs	Ldc75		; yes
	std	L000fw
	ldd	#$927c		; 37500
	ldy	#$0006		; times 32  (2^5)
	jsr	Ld8d1		; D = (37,500 / L000fw) * 32
	tsta			; overflow ?
	beq	Ldc77		; nope
Ldc75:	ldab	#$ff
Ldc77:	rts
; -----------------------------------------------------------------------------
; Compute a checksum byte of specified memory..
;	Entry:	B  - byte to add into to compute check sum
;		IX - memory/EEPROM address to start at
;		IY - check to this address ( do not include it)
;	Return: B - sum of all bytes specified
;	Protect: IY
;
Ldc78:	pshy			; end address to the stack
	tsy			; point IY at ending address
Ldc7c:	addb	$00,X		; add in next byte
	inx			; bump memory pointer
	cpx	$00,Y		; at ending address now ?
	bcs	Ldc7c		; nope - not yet - loop
	puly			; reset stack
	rts			; done
;
; -----------------------------------------------------------------------------
; Setup the serial interface....
;
Ldc87:	ldaa	#%00110000	; set baud prescaler to 9600 baud
	staa	baud_register
	ldaa	scsr_register	; read the serial status register
	ldaa	scdr_register	; read the data register
	clra
	staa	scdr_register	; clear it
	clra			; Start bit, 8 data bits, stop bit
	ldab	#%00100100	; enable receiver and its interrupt
	std	sccr1_register	; set 102C and 102D at same time
	rts
;
; -----------------------------------------------------------------------------
; SCI Serial System interrupt entry point
;
Ldc9d:	ldx	#register_base
	brset	$2e,X %00001000 Ldcc0 ; got an Overrun error
	brset	$2e,X %00100000 Ldcb4 ; receiver has data
	brset	$2e,X %10000000 Ldcc8 ; Transmitt buffer is Empty
Ldcac:	ldaa	#%00100100	; Receiver and its interrupt enabled
	staa	$2d,X
	bclr	$2f,X %11111111 ; clear the Serial Data register
	rti			; done
;
Ldcb4:	brset	$2e,X %00000010 Ldcc0 ; got a Framing Error
	brset	$2e,X %00000100 Ldcc0 ; got a Noise Flag Error
	ldab	$2f,X		; get the byte from the Serial Data register
	bra	Ldccf		; good data from the control module
;
Ldcc0:	clr	L00bc		; clear the serial flags
	ldab	$2f,X		; read the Serial Data register
	ldab	$2f,X		; again
	rti
;
; Transmitt buffer empty - do we need to send something ?
;
Ldcc8:	brclr	L00bc %00001000 Ldcac	; nothing to send
	jmp	Lddd2			; transmitt buffer
;
; Got good received data in B .....
;
Ldccf:	brclr	L00bc %01110000 Ldcdd ; no request/command yet sent
;				      ; Check for legal first byte then...
;
	brset	L00bc %01000000 Ldcf4 ; already received '7B' first byte
;				      ; Check for second byte command
;
	brset	L00bc %00100000 Ldd14 ; data requested or to be set
	bra	Ldd28		      ; nope - more bytes being sent
;
; We haven't received anything we recognize yet.  Should be the first byte '7B'
;
Ldcdd:	cmpb	#$7b		; first byte ?
	bne	Ldcf3		; nope - just bail then
	ldd	#L00c0		; point to start of serial buffer
	std	L00be		; stash buffer index
	clr	L00bd		; clear characters sent
	bclr	L0059 %00000001 ; clear engine operating condition request flag
	ldaa	#%01000000	; signal first byte received
	staa	L00bc		; stash in flag byte
	bclr	$2d,X %11000000 ; disable transmitter interupts
Ldcf3:	rti
;
; We have already received the the first byte (7B).  Proccess second...
;
Ldcf4:	cmpb	#$02		; request for current engine operating parms ?
	beq	Ldd04		; yes
	cmpb	#$05		; request specific data/parm ?
	beq	Ldd0c		; yes
	cmpb	#$06		; set some operating parm ?
	beq	Ldd0c		; yes
	clr	L00bc		; don't know what this is so clear seq flag...
	rti			; ...and exit
;
; Got a request for all the engine parameters
;
Ldd04:	bclr	L00bc %11000000 ; clear 1st received and timer overflow watchdog
	bset	L00bc %00010000 ; signal we know what is needed
	bra	Ldd32		; stash byte in buffer and exit
;
; Second byte was '05' - a request for a specific data/parm
; Second byte was '06' - command to set an operating parmameter
;
Ldd0c:	bclr	L00bc %11000000 ; get timer overflow watchdog off of us
	bset	L00bc %00100000 ; signal '05' data request or '06' data set
	bra	Ldd32		; stash byte in buffer and exit
;
; We should just have received the third byte in the sequence.	This is the
;  number of characters being sent to use
;
;	7B 05 12 80 00 - return ECU software revision information
;	7B 05 0A F0 00 - return CAL info from ECU
;	7B 05 03 xx xx - all set/request commands have a 03 as the third
;
Ldd14:	tba			; put it into A
	deca			; minus 1
	cmpa	#$11
	bls	Ldd1e		; it was lower than $12 so OK
	clr	L00bc		; too many so need to start over again
	rti
;
Ldd1e:	bclr	L00bc %10100000 ; clear data requested/set and watchdog flag
	bset	L00bc %00010000 ; signal we know what is needed
	stab	L00bd		; stash number of characters being sent
	bra	Ldd32		; stash byte in buffer and exit
;
; The remaining characters in the command get sent to here....
;
Ldd28:	bclr	L00bc %10000000 ; get timer overflow watchdog off of us
	ldaa	L00bd		; get characters sent counter
	beq	Ldd3a		; no more - all have been received
;				; yes - then this is the checksum byte
	deca
	staa	L00bd		; update bytes received
Ldd32:	ldx	L00be		; get current buffer index
	stab	$00,X		; stash byte
	inx			; bump index
	stx	L00be		; update memory
	rti			; done
;
; Last checksum byte just received...
;
Ldd3a:	stab	L00bd		; stash the checksum
	ldd	#$007b		; start checksum with our first byte (7B)
	ldy	L00be		; get ending buffer address
	ldx	#L00c0		; start of serial buffer
	jsr	Ldc78		; compute checksum
	cmpb	L00bd		; same as sent to us ?
	beq	Ldd50		; yes - good buffer
	clr	L00bc		; nope - bad data - ignore buffer
	rti
;
; We just have received a valid command buffer.  The '7B' lead byte did Not
;  get stashed into the receiver buffer...
;
Ldd50:	ldx	#L00c0		; point to our Serial buffer start
	ldab	$00,X		; get the command
	cmpb	#$02		; request current operating parameters ?
	beq	Ldd63		; yes
	cmpb	#$05		; request data ?
	beq	Ldd99		; yes
	cmpb	#$06		; update one of our operating conditions ?
	beq	Ldd6a		; yes
	bra	Ldd66		; don't know what this is
;
Ldd63:	bset	L0059 %00000001 ; signal operating conditions requested
Ldd66:	clr	L00bc		; clear receiver flags
	rti			; done
;
; A request to update an operating condition was just received.....
;
Ldd6a:	ldx	L00c2		; get the address of the data
	cpx	#register_base	; pointing to some ram loaction ?
	bcs	Ldd84		; yes
	cpx	#baud_register	; want to set the baud rate ? (strange ...)
	beq	Ldd84		; yes
	cpx	#$1040		; any other register ?
	bcs	Ldd80		; yes - abort
	cpx	#$3000		; below the timers ?
	bcs	Ldd84		; ok
Ldd80:	clr	L00bc		; bad request address - ignore
	rti			; done
;
Ldd84:	ldab	L00c1		; get number of byte to modify
	subb	#$02		; less word address
	bcs	Ldd66		; too few - abort
	ldy	#L00c2+2	; get it from here
Ldd8e:	ldaa	$00,Y		; get a byte from the buffer
	staa	$00,X		; update it in our memory
	inx			; bump pointers
	iny
	decb
	bne	Ldd8e		; more to modify
;
; Fall into routine below which will transmitt back what we just modified...
;
; -------------------------------
; Somekind of data was requested from us. Get it and fill the serial buffer
;  with it.
;
Ldd99:	ldx	L00c2		; get the address of the requested data
	ldab	L00c1		; get the number of bytes sent
	subb	#$02		; less two for the address - want the rest back
	bcs	Ldd66		; too few characters - abort
	ldy	#L00c2+2	; where to stash the requested data
Ldda5:	ldaa	$00,X		; get a byte
	staa	$00,Y		; stash it in the serial buffer
	inx			; bump memory indexes
	iny
	decb
	bne	Ldda5		; more requested
	ldaa	#$05
	staa	L00c0		; stash second byte
	ldx	#register_base
	ldab	#%00001000	; signal buffer has data to transmitt
	stab	L00bc
	ldaa	#$7b		; $7B to the Serial Data register
	staa	$2f,X		; stash it
	bset	$2d,X %10001000 ; enable the Serial Transmitter and Interrupt
	ldab	L00c1		; get number of characters sent
	addb	#$02		; plus address word
	stab	L00bd		; stash bytes to send
	ldd	#L00c0		; point to start of buffer
	std	L00be		; stash buffer index
	brset	$2e,X %10000000 Lddd2 ; Transmitter data register empty
	rti
;
; We need to transmitt the serial buffer.........
;
Lddd2:	ldaa	L00bd		; get bytes to sent
	beq	Ldde4		; all done - compute and send checksum
	deca			; one less
	staa	L00bd		; update memory
	ldx	L00be		; get current buffer index
	ldab	$00,X		; get the character
	stab	scdr_register	; to the Serial data register
	inx			; bump memory pointer
	stx	L00be		; update ram
	rti			; all done
;
Ldde4:	ldd	#$007b		; start our checksum with first byte (7B)
	ldy	L00be		; get ending address of buffer
	ldx	#L00c0		; point to start of serial buffer
	jsr	Ldc78		; compute checksum
	stab	scdr_register	; stash it
	clr	L00bc		; reset serial operation flag
	rti
; -----------------------------------------------------------------------------
;
	if	not no_fills
Lddf7:	fill	$FF,$1209
	endif
;
; This address is the CAL info that is requested by the Control Module.
; I see that it also contains cam timing and intake valve specs.
;  NOTE: This address can not change or the controler won't find it
;
	org	$f000
Lf000:	fcc	'Q1.3DH01350 246/254 2.02'
; -----------------------------------------------------------------------------
Lf018:	fcb	$0a	; 10 - 11 Load ranges in the Fuel Matrix
Lf019:	fcb	$07	; 7 - 8 Load ranges in spark table
Lf01a:	fcb	$07	; 7
Lf01b:	fcb	$07
; ----------------------------------------------------------------------------
; TBDUTY
;
; DUTY BKPTs FOR THE PERIOD TABLE  f(DUTY)
;  (IN PCT DC)
;
; (8 LINES, 16 bit val's)
;
;  TABLE = Pct Duty Cycle * 2.56
Lf01c:	fcb	$07
; ----------------------------------------------------------------------------
Lf01d:	fcb	00	; Ignition Coil Driver Mode control (NA)
; ----------------------------------------------------------------------------
; Injection time offset (2 usec/bit) to comp for batt voltage
Lf01e:	fdb	$0120	; 288 - some battery factor in voltage comp calculations
; ----------------------------------------------------------------------------
; This guy here is like a global modifier of the fuel matrix tables......
; If you want to modify all the entries at once here is the variable !!!!!!
;
; Injector time Resolution - 76 us
Lf020:	fcb	$26	; 38 - take 15% of the fuel lookup matrix values
; -----------------------------------------------------------------------------
; MAT Rescaling Factor
Lf021:	fcb	$58	; 88 - multipler used with TAIR computations
; ----------------------------------------------------------------------------
; MAT Lower Threshold (Adder)
Lf022:	fcb	$63	; 99 - added constant used with TAIR computations
; ----------------------------------------------------------------------------
; Pressure Sensor Offset, Scaling (Adder)
Lf023:	fcb	$20	; 32 - constant used in computing Air Density
			;	About 4" of vacuum
; ----------------------------------------------------------------------------
; Re-Scaler for DENSAR. (Multi)
Lf024:	fcb	$b8	; 184
; ----------------------------------------------------------------------------
; 3.00 DENSAR, Upper Limit
Lf025:	fdb	$0c00	; 3072	- max computed air density allowed (-6.5")
; -----------------------------------------------------------------------------
; This is the RPM index table into the Fuel matrix.......
;---------------------------------------------
; TBTPMI
; RPM BREAKPOINTS FOR FUEL LOOKUP TABLE
;
; (16 LINES, 16 Bit val's)
;
; RPM bkpt. table
;	FOR NUM Densar Break Points
;			 INJECTION PHASING
;			 WOT ENRICHMENT MULT Vs. RPM
;
;		(Time between ign events)
;
; TABLE VAL = usec/8
;			= RPM/187500
;---------------------------------------------
;
Lf027:	fdb	$0138	;  312	6,000 rpm
	fdb	$0154	;  340	5,500 rpm
	fdb	$0177	;  375	5,000 rpm
	fdb	$01a0	;  416	4,500 rpm
	fdb	$01d4	;  468	4,000 rpm
	fdb	$0217	;  535	3,500 rpm
	fdb	$0271	;  625	3,000 rpm
	fdb	$02ee	;  750	2,500 rpm
	fdb	$03a9	;  937	2,000 rpm
	fdb	$042f	; 1071	1,750 rpm
	fdb	$04e2	; 1250	1,500 rpm
	fdb	$05dc	; 1500	1,250 rpm
	fdb	$0753	; 1875	1,000 rpm
	fdb	$0823	; 2083	  900 rpm
	fdb	$0928	; 2344	  800 rpm
	fdb	$0c35	; 3125	  600 rpm
;
; This table is indexed by computed Load (comments are in displayed vacuum)
; Its output (index.fractional) will be used to lookup Load in the Fuel matrix
;---------------------------------------------
; TBDI
; Air Density Breakpoints for Fuel Lookup Table
;
; (11 lines, 16 Bit Val's)
;
; 1/1024 mmHg/degK/bit			 mm Hg/degK/bit
;---------------------------------------------
;
Lf047:	fdb	$019a	;  410	24"
	fdb	$0200	;  512	23"
	fdb	$02cd	;  717	21"
	fdb	$0400	; 1024	17"
	fdb	$04cd	; 1229	15"
	fdb	$059a	; 1434	12"
	fdb	$0666	; 1638	10"
	fdb	$0766	; 1894	 7"
	fdb	$0866	; 2150	 4"
	fdb	$099a	; 2458	 0.5"
Lf05b:	fdb	$0acd	; 2765	-3"
	fdb	$0acd	; 2765	-3"
	fdb	$0acd	; 2765	-3"
	fdb	$0acd	; 2765	-3"
	fdb	$0acd	; 2765	-3"
	fdb	$0acd	; 2765	-3"
;
; -----------------------------------------------------------------------------
; Fuel Lookup matrix.
; Remember the inches are computed Load (Air Charge) not MAP inches.........
;
; This is the sensitivity of each bit in these Fuel lookup tables....
; (Battery correction is added in after these tables that is where the offset
;  comes from)
;
;   At 14.1 volts		At 14.7v...
;	0 =  0.720 ms			=  0.640
;      64 =  5.584 ms
;     128 = 10.448 ms			= 10.368
;     192 = 15.321 ms
;     255 = 20.104 ms			= 20.024
;
; This works out to be .076 ms per bit
;	- or -
; aprox .727% per bit.......
;
; WOT.....
;
Lf067:	fcb	$95	; 149		 600 rpm
	fcb	$d1	; 209		 800 rpm
	fcb	$c6	; 198		 900 rpm
	fcb	$be	; 190		1000 rpm
	fcb	$a2	; 162		1250 rpm
	fcb	$93	; 147		1500 rpm
	fcb	$a8	; 168		1750 rpm
	fcb	$9e	; 158		2000 rpm
	fcb	$b1	; 177		2500 rpm
	fcb	$b7	; 183		3000 rpm
	fcb	$ba	; 186		3500 rpm
	fcb	$b5	; 181		4000 rpm
	fcb	$b8	; 184		4500 rpm
	fcb	$b8	; 184		5000 rpm
	fcb	$c8	; 200		5500 rpm
	fcb	$cc	; 204		6000 rpm
;
; 0.5 ".....
;
	fcb	$88	; 136		 600 rpm
	fcb	$c4	; 196		 800 rpm
	fcb	$b9	; 185		 900 rpm
	fcb	$b1	; 177		1000 rpm
	fcb	$95	; 149		1250 rpm
	fcb	$86	; 134		1500 rpm
	fcb	$9b	; 155		1750 rpm
	fcb	$91	; 145		2000 rpm
	fcb	$a4	; 164		2500 rpm
	fcb	$aa	; 170		3000 rpm
	fcb	$ad	; 173		3500 rpm
	fcb	$a8	; 168		4000 rpm
	fcb	$ab	; 171		4500 rpm
	fcb	$aa	; 170		5000 rpm
	fcb	$bb	; 187		5500 rpm
	fcb	$bf	; 191		6000 rpm
;
; 4".....
;
	fcb	$55	;  85		 600 rpm
	fcb	$71	; 113		 800 rpm
	fcb	$70	; 112		 900 rpm
	fcb	$6d	; 109		1000 rpm
	fcb	$6b	; 107		1250 rpm
	fcb	$6b	; 107		1500 rpm
	fcb	$69	; 105		1750 rpm
	fcb	$6d	; 109		2000 rpm
	fcb	$7f	; 127		2500 rpm
	fcb	$90	; 144		3000 rpm
	fcb	$9b	; 155		3500 rpm
	fcb	$92	; 146		4000 rpm
	fcb	$95	; 149		4500 rpm
	fcb	$8b	; 139		5000 rpm
	fcb	$b0	; 176		5500 rpm
	fcb	$bc	; 188		6000 rpm
;
; 7"......
;
	fcb	$31	;  49		 600 rpm
	fcb	$48	;  72		 800 rpm
	fcb	$4b	;  75		 900 rpm
	fcb	$52	;  82		1000 rpm
	fcb	$52	;  82		1250 rpm
	fcb	$54	;  84		1500 rpm
	fcb	$52	;  82		1750 rpm
	fcb	$51	;  81		2000 rpm
	fcb	$64	; 100		2500 rpm
	fcb	$6a	; 106		3000 rpm
	fcb	$75	; 117		3500 rpm
	fcb	$72	; 114		4000 rpm
	fcb	$78	; 120		4500 rpm
	fcb	$7a	; 122		5000 rpm
	fcb	$7a	; 122		5500 rpm
	fcb	$7c	; 124		6000 rpm
;
; 10"......
;
	fcb	$23	;  35		 600 rpm
	fcb	$2f	;  47		 800 rpm
	fcb	$37	;  55		 900 rpm
	fcb	$40	;  64		1000 rpm
	fcb	$3d	;  61		1250 rpm
	fcb	$43	;  67		1500 rpm
	fcb	$44	;  68		1750 rpm
	fcb	$44	;  68		2000 rpm
	fcb	$50	;  80		2500 rpm
	fcb	$56	;  86		3000 rpm
	fcb	$60	;  96		3500 rpm
	fcb	$5c	;  92		4000 rpm
	fcb	$62	;  98		4500 rpm
	fcb	$63	;  99		5000 rpm
	fcb	$68	; 104		5500 rpm
	fcb	$6c	; 108		6000 rpm
;
; 12".......
;
	fcb	$15	;  21		 600 rpm
	fcb	$1f	;  31		 800 rpm
	fcb	$27	;  39		 900 rpm
	fcb	$30	;  48		1000 rpm
	fcb	$32	;  50		1250 rpm
	fcb	$36	;  54		1500 rpm
	fcb	$38	;  56		1750 rpm
	fcb	$37	;  55		2000 rpm
	fcb	$45	;  69		2500 rpm
	fcb	$48	;  72		3000 rpm
	fcb	$4d	;  77		3500 rpm
	fcb	$4f	;  79		4000 rpm
	fcb	$54	;  84		4500 rpm
	fcb	$57	;  87		5000 rpm
	fcb	$58	;  88		5500 rpm
	fcb	$59	;  89		6000 rpm
;
; 15"........
;
	fcb	$15	;  21		 600 rpm
	fcb	$19	;  25		 800 rpm
	fcb	$1d	;  29		 900 rpm
	fcb	$1e	;  30		1000 rpm
	fcb	$29	;  41		1250 rpm
	fcb	$2c	;  44		1500 rpm
	fcb	$2d	;  45		1750 rpm
	fcb	$2d	;  45		2000 rpm
	fcb	$3c	;  60		2500 rpm
	fcb	$3e	;  62		3000 rpm
	fcb	$40	;  64		3500 rpm
	fcb	$40	;  64		4000 rpm
	fcb	$46	;  70		4500 rpm
	fcb	$4d	;  77		5000 rpm
	fcb	$4e	;  78		5500 rpm
	fcb	$4f	;  79		6000 rpm
;
; 17"........
;
	fcb	$19	;  25		 600 rpm
	fcb	$1a	;  26		 800 rpm
	fcb	$1c	;  28		 900 rpm
	fcb	$1e	;  30		1000 rpm
	fcb	$1e	;  30		1250 rpm
	fcb	$22	;  34		1500 rpm
	fcb	$24	;  36		1750 rpm
	fcb	$24	;  36		2000 rpm
	fcb	$31	;  49		2500 rpm
	fcb	$31	;  49		3000 rpm
	fcb	$33	;  51		3500 rpm
	fcb	$34	;  52		4000 rpm
	fcb	$39	;  57		4500 rpm
	fcb	$3e	;  62		5000 rpm
	fcb	$3f	;  63		5500 rpm
	fcb	$41	;  65		6000 rpm
;
; 21"........
;
	fcb	$0e	;  14		 600 rpm
	fcb	$10	;  16		 800 rpm
	fcb	$10	;  16		 900 rpm
	fcb	$11	;  17		1000 rpm
	fcb	$11	;  17		1250 rpm
	fcb	$12	;  18		1500 rpm
	fcb	$18	;  24		1750 rpm
	fcb	$1c	;  28		2000 rpm
	fcb	$22	;  34		2500 rpm
	fcb	$22	;  34		3000 rpm
	fcb	$21	;  33		3500 rpm
	fcb	$23	;  35		4000 rpm
	fcb	$29	;  41		4500 rpm
	fcb	$29	;  41		5000 rpm
	fcb	$2b	;  43		5500 rpm
	fcb	$2c	;  44		6000 rpm
;
; 23"........
;
	fcb	$0d	;  13		 600 rpm
	fcb	$0d	;  13		 800 rpm
	fcb	$0e	;  14		 900 rpm
	fcb	$0e	;  14		1000 rpm
	fcb	$0e	;  14		1250 rpm
	fcb	$0e	;  14		1500 rpm
	fcb	$0e	;  14		1750 rpm
	fcb	$11	;  17		2000 rpm
	fcb	$19	;  25		2500 rpm
	fcb	$1a	;  26		3000 rpm
	fcb	$16	;  22		3500 rpm
	fcb	$18	;  24		4000 rpm
	fcb	$1a	;  26		4500 rpm
	fcb	$1c	;  28		5000 rpm
	fcb	$1e	;  30		5500 rpm
	fcb	$1f	;  31		6000 rpm
;
; 24"........
;
	fcb	$0c	;  12		 600 rpm
	fcb	$0d	;  13		 800 rpm
	fcb	$0d	;  13		 900 rpm
	fcb	$0e	;  14		1000 rpm
	fcb	$0e	;  14		1250 rpm
	fcb	$0e	;  14		1500 rpm
	fcb	$0f	;  15		1750 rpm
	fcb	$0f	;  15		2000 rpm
	fcb	$15	;  21		2500 rpm
	fcb	$16	;  22		3000 rpm
	fcb	$15	;  21		3500 rpm
	fcb	$17	;  23		4000 rpm
	fcb	$18	;  24		4500 rpm
	fcb	$1b	;  27		5000 rpm
	fcb	$1b	;  27		5500 rpm
	fcb	$1c	;  28		6000 rpm
;
	if	not no_fills
f117:	fill	00,80
	endif
;
; Battery adjustment table for correcting Injector Pulse Width timing
;
Lf167:	fcb	$ff	; 255	 6.000 volts
	fcb	$ff	; 255	 6.667 volts
	fcb	$c3	; 195	 7.333 volts
	fcb	$8e	; 142	 8.000 volts
	fcb	$70	; 112	 8.667 volts
	fcb	$58	;  88	 9.333 volts
	fcb	$44	;  68	10.000 volts
	fcb	$35	;  53	10.667 volts
	fcb	$2a	;  42	11.333 volts
	fcb	$1f	;  31	12.000 volts
	fcb	$18	;  24	12.667 volts
	fcb	$12	;  18	13.333 volts
	fcb	$0b	;  11	14.000 volts
	fcb	$04	;   4	14.667 volts
	fcb	$02	;   2	15.333 volts
	fcb	$00	;   0	16.000 volts
;
; The following two tables are water temp look-ups for modifing the Cold Start
;  Fuel modifier.....
; The second table at Lf187 is never looked at, but it wouldn't matter because
; both tables are the same......
;
Lf177:	fcb	$80	; 128			very cold.....
	fcb	$80	; 128			 .....
	fcb	$7a	; 122			  .....
	fcb	$73	; 115			 0' -  20's
	fcb	$66	; 102			20's - 30's
	fcb	$52	;  82			40's - 60's
	fcb	$4c	;  76			70's - 80's
	fcb	$48	;  72			90's - 100's
	fcb	$44	;  68		       110's - 120's
	fcb	$43	;  67		       130's - 140's
	fcb	$40	;  64		       150's - 160's
	fcb	$40	;  64		       180's - 190's
	fcb	$40	;  64		       200's - 210's
	fcb	$40	;  64		       220's - 230's
	fcb	$40	;  64		       240's - 250's
	fcb	$40	;  64		       really Hot !!!!
;
	if not mis7x

Lf187:	fcb	$80
	fcb	$80
	fcb	$7a
	fcb	$73
	fcb	$66
	fcb	$52
	fcb	$4c
	fcb	$48
	fcb	$44
	fcb	$43
	fcb	$40
	fcb	$40
	fcb	$40
	fcb	$40
	fcb	$40
	fcb	$40

	endif
;
; This table is index by water temperature (L0003).
; These values modify the user Transient Fuel modifier for coolant temperature.
;---------------------------------------------
; TBPH2O
; TRANSIENT FUEL CORRECTION Vs. COOLANT
;
; Use this table to calculate CPH2O.
;
; TRANSIENT COLD CORRECTION FOR FUEL  f(TH2O)
;
; VAL = MULT * 64
;---------------------------------------------
;
Lf197:	fcb	$99	; 153			very cold -40 to 0 degrees    00
	fcb	$90	; 144			   .....		      10
	fcb	$87	; 135			     .....		      20
	fcb	$7e	; 126			arround 0 - 20 degrees	      30
	fcb	$75	; 117			in the 20's and 30's	      40
	fcb	$6c	; 108			in the 40's and 60's	      50
	fcb	$63	;  99			in the 70's and 80's	      60
	fcb	$5a	;  90			in the 90's and 100's	      70
	fcb	$51	;  81			in the 110's and 120's	      80
	fcb	$48	;  72			in the 130's and 140's	      90
	fcb	$40	;  64			in the 150's and 160's	      A0
	fcb	$40	;  64			in the 180's and 190's	      B0
	fcb	$40	;  64			in the 200's and 210's	      C0
	fcb	$40	;  64			in the 220's and 230's	      D0
	fcb	$40	;  64			in the 240's adn 250's	      E0
	fcb	$40	;  64			really HOT !!!!!	      F0
; ------------------------------------------------------------------------------
; This table is indexed by water temperature.  Its output is the index into
;  the early extra Fuel
;---------------------------------------------
; TBH2O
; LOOK UP COOL Break Points FOR CRANK FUEL TABLE
;
; (8 Lines, 16 bit val's)
;
; SCALING is 0.75 Deg/bit above -55 deg C
; [see TABH2O]
;---------------------------------------------
;
Lf1a7:	fdb	$0021	; 33	-26 degrees
	fdb	$0028	; 40	-17 degrees
	fdb	$002f	; 47	- 5 degrees
	fdb	$0035	; 53	  0 degrees
	fdb	$0041	; 65	 20 degrees
	fdb	$0051	; 81	 40 degress
	fdb	$0071	; 113	 85 degrees
	fdb	$00a2	; 162	150 degrees
; ----------------------------------------------------------------------------
; This table is indexed by how many revolutions the motor has turned since
;  start up.  The counter starts at 255 and works downwards !
; Its output index is into early extra Fuel
;---------------------------------------------
; TBCRK
; ENGINE PHASE (RPM) BREAKPOINTS FOR CRANK FUEL TABLE
;
; (8 LINES, 16 bit val's)
;
; NOTE: These numbers assume that
;	SLGCRK = 0. At last check,
;	this parameter was located
;	under TABVAR in the "OTHER
;	STUFF" subheading.
;---------------------------------------------
;
Lf1b7:	fdb	$0005	;   5	250 revolutions
	fdb	$0069	; 105	150 revs
	fdb	$009b	; 155	100 revs
	fdb	$00e1	; 225	 30 revs
	fdb	$00ef	; 239	 16 revs
	fdb	$00f7	; 247	  8 revs
	fdb	$00f9	; 249	  6 revs
	fdb	$00fb	; 251	  4 revolutions
;
; This matrix adds some extra Fuel during the early operation of the motor.
;
; 150 degrees and up....
;
Lf1c7:	fcb	$14	; 20		4 revolutions
	fcb	$14	; 20		6 revs
	fcb	$12	; 18		8 revs
	fcb	$10	; 16	       16 revs
	fcb	$10	; 16	       30 revs
	fcb	$10	; 16	      100 revs
	fcb	$10	; 16	      150 revs
	fcb	$10	; 16	      250 revolutions
;
; 85 degrees.....
;
	fcb	$1e	; 30		4 revolutions
	fcb	$1e	; 30		6 revs
	fcb	$18	; 24		8 revs
	fcb	$18	; 24	       16 revs
	fcb	$14	; 20	       30 revs
	fcb	$12	; 18	      100 revs
	fcb	$10	; 16	      150 revs
	fcb	$10	; 16	      250 revolutions
;
; 40 degrees......
;
	fcb	$3c	; 60		4 revolutions
	fcb	$28	; 40		6 revs
	fcb	$1c	; 28		8 revs
	fcb	$1a	; 26	       16 revs
	fcb	$14	; 20	       30 revs
	fcb	$14	; 20	      100 revs
	fcb	$10	; 16	      150 revs
	fcb	$10	; 16	      250 revolutions
;
; 20 degrees.......
;
	fcb	$46	; 70		4 revolutions
	fcb	$3c	; 60		6 revs
	fcb	$1e	; 30		8 revs
	fcb	$1e	; 30	       16 revs
	fcb	$14	; 20	       30 revs
	fcb	$10	; 16	      100 revs
	fcb	$10	; 16	      150 revs
	fcb	$10	; 16	      250 revolutions
;
; 0 degrees......
;
	fcb	$5a	; 90		4 revolutions
	fcb	$50	; 80		6 revs
	fcb	$2d	; 45		8 revs
	fcb	$2d	; 45	       16 revs
	fcb	$19	; 25	       30 revs
	fcb	$14	; 20	      100 revs
	fcb	$10	; 16	      150 revs
	fcb	$10	; 16	      250 revolutions
;
; -5 degrees........
;
	fcb	$6e	; 110		4 revolutions
	fcb	$5a	; 90		6 revs
	fcb	$3c	; 60		8 revs
	fcb	$32	; 50	       16 revs
	fcb	$23	; 35	       30 revs
	fcb	$19	; 25	      100 revs
	fcb	$11	; 17	      150 revs
	fcb	$10	; 16	      250 revolutions
;
; -17 degrees........
;
	fcb	$8c	; 140		4 revolutions
	fcb	$78	; 120		6 revs
	fcb	$50	; 80		8 revs
	fcb	$20	; 32	       16 revs
	fcb	$1b	; 27	       30 revs
	fcb	$13	; 19	      100 revs
	fcb	$11	; 17	      150 revs
	fcb	$10	; 16	      250 revolutions
;
; -26 degrees........
;
	fcb	$a0	; 160		4 revolutions
	fcb	$8e	; 142		6 revs
	fcb	$5a	; 90		8 revs
	fcb	$28	; 40	       16 revs
	fcb	$1e	; 30	       30 revs
	fcb	$14	; 20	      100 revs
	fcb	$11	; 17	      150 revs
	fcb	$10	; 16	      250 revolutions
;
; -----------------------------------------------------------------------------
; This table is rpm indexed by Lf027.  It is used to further adjust the
;  fuel requirements for WOT only and the TH20 > 120 degrees
;---------------------------------------------
; TABJPA
; WOT ENRICHMENT MULT Vs. RPM
;
; SEE LF560 & LF561 for TPS THRESHOLDS to INVOKE THIS TABLE.
;	LF560 = 83 Deg, RPM LT 3500 &  ENG "COLD"
;	LF561 = 82 Deg, RPM GT 3500 or ENG "WARM"
;
; NOTE:
;		THE RPM BKPTS. ARE DEFINED BY
;		TABLE TBTPMI ABOVE.
;
; VAL = MULT * 128
;---------------------------------------------
;
Lf207:	fcb	$86	; 134	+2.3%	 600 rpm
	fcb	$86	; 134	+2.3%	 800 rpm
	fcb	$86	; 134	+2.3%	 900 rpm
	fcb	$86	; 134	+2.3%	1000 rpm
	fcb	$86	; 134	+2.3%	1250 rpm
	fcb	$86	; 134	+2.3%	1500 rpm
	fcb	$86	; 134	+2.3%	1750 rpm
	fcb	$86	; 134	+2.3%	2000 rpm
	fcb	$86	; 134	+2.3%	2500 rpm
	fcb	$86	; 134	+2.3%	3000 rpm
	fcb	$8a	; 138	+3.9%	3500 rpm
	fcb	$8a	; 138	+3.9%	4000 rpm
	fcb	$8a	; 138	+3.9%	4500 rpm
	fcb	$8a	; 138	+3.9%	5000 rpm
	fcb	$8a	; 138	+3.9%	5500 rpm
	fcb	$8a	; 138	+3.9%	6000 rpm
;
; -----------------------------------------------------------------------------
; This table is indexed by water temperature (L0003)...
; It is in timing_period/16 units (like L0042 and L0061).
; The output goes into L0017.... dashpot threshold RPM's
;
	if	my_dashpot_table
;
Lf217:	fcb	$30	; 48  2441 rpm	 0 -  15  < ~-40 degrees
	fcb	$37	; 55  2131 rpm	16 -  47  ~-40 to ~0 deg
	fcb	$37	; 55  2131 rpm	48 -  79  ~0 to ~40 deg
	fcb	$37	; 55  2131 rpm	80 - 111  ~40 to ~80 deg
	fcb	$37	; 55  2131 rpm 112 - 143  ~80 to ~120 deg
	fcb	78	;     1500 rpm 144 - 175  ~120 to ~170 deg
	fcb	78	;     1500 rpm 176 - 207  ~170 to ~210 deg
	fcb	78	;     1500 rpm 208 - 255  > ~210 degrees
;
	else
;
;---------------------------------------------
; TBSCTF
; RPM THRESHOLDS FOR CUT-OFF Vs. COOL
;---------------------------------------------
;
Lf217:	fcb	$30	; 48  2441 rpm	 0 -  15  < ~-40 degrees
	fcb	$37	; 55  2131 rpm	16 -  47  ~-40 to ~0 deg
	fcb	$37	; 55  2131 rpm	48 -  79  ~0 to ~40 deg
	fcb	$37	; 55  2131 rpm	80 - 111  ~40 to ~80 deg
	fcb	$37	; 55  2131 rpm 112 - 143  ~80 to ~120 deg
	fcb	$3f	; 63  1860 rpm 144 - 175  ~120 to ~170 deg
	fcb	$3f	; 63  1860 rpm 176 - 207  ~170 to ~210 deg
	fcb	$3f	; 63  1860 rpm 208 - 255  > ~210 degrees
	endif
;
; -----------------------------------------------------------------------------
; This table is indexed by water temperature (L0003) and gives back RPM (timing
;  period/16).
; We can't shut off the fuel unless we start above this rpm
;
; The output goes into L0018....
;
	if	my_rpm_trip
;
Lf21f:	fcb	$1c	; 28  4185 rpm	 0 -  15  < ~-40 degrees
	fcb	$1d	; 29  4041 rpm	16 -  47  ~-40 to ~0 deg
	fcb	$1f	; 31  3780 rpm	48 -  79  ~0 to ~40 deg
	fcb	$2d	; 45  2604 rpm	80 - 111  ~40 to ~80 deg
	fcb	$2d	; 45  2604 rpm 112 - 143  ~80 to ~120 deg
	fcb	$38	; 56  2093 rpm 144 - 175  ~120 to ~170 deg
	fcb	$38	; 56  2093 rpm 176 - 207  ~170 to ~210 deg
	fcb	$38	; 56  2093 rpm 208 - 255  > ~210 degrees
;
	else
;
Lf21f:	fcb	$1c	; 28  4185 rpm	 0 -  15  < ~-40 degrees
	fcb	$1d	; 29  4041 rpm	16 -  47  ~-40 to ~0 deg
	fcb	$1f	; 31  3780 rpm	48 -  79  ~0 to ~40 deg
	fcb	$2d	; 45  2604 rpm	80 - 111  ~40 to ~80 deg
	fcb	$2d	; 45  2604 rpm 112 - 143  ~80 to ~120 deg
	fcb	$31	; 49  2392 rpm 144 - 175  ~120 to ~170 deg
	fcb	$31	; 49  2392 rpm 176 - 207  ~170 to ~210 deg
	fcb	$31	; 49  2392 rpm 208 - 255  > ~210 degrees
;
	endif
;
	if	not no_fills

f227:	fcb	$30
f228:	fcb	$37
f229:	fcb	$48
f22a:	fcb	$55
f22b:	fdb	$6c6c
f22d:	fdb	$6c6c
f22f:	fcb	$01
f230:	fcb	$01
f231:	fcb	$01
f232:	fcb	$02
f233:	fcb	$04
f234:	fcb	$46
f235:	fcb	$4c
f236:	fcb	$4c

	endif
;
; -----------------------------------------------------------------------------
; This table is indexed by rpm (index table Lf027)
; Its output is used in determining the optimum injector firing phase for
;  a particular rpm.   The values will later be scaled.... (x-32)/8
;  They are indexes into Lff20.
; Because it takes a difference of 3 in the scaled values (hysterisis between
;  L0028 and L0029) the rpm break points are not that obvious.	The four values
;  that L0029 can take are 0,4,8,12 so depending if we are accelerating or
;  decelerating the break points are different.
;
;---------------------------------------------
; TABFAS
; INJECTION PHASING Vs. RPM
; Deg BTDC vs RPM
;---------------------------------------------
;							     Acel     Decel
Lf237:	fcb	$80	; 128	12 - Group 3	 600 rpm
	fcb	$80	; 128	12 - Group 3	 800 rpm
	fcb	$80	; 128	12 - Group 3	 900 rpm
	fcb	$80	; 128	12 - Group 3	1000 rpm
	fcb	$80	; 128	12 - Group 3	1250 rpm
	fcb	$80	; 128	12 - Group 3	1500 rpm	       1562
	fcb	$60	;  96	 8 - Group 2	1750 rpm     1617
	fcb	$60	;  96	 8 - Group 2	2000 rpm	       2100
	fcb	$40	;  64	 4 - Group 1	2500 rpm     2227
	fcb	$40	;  64	 4 - Group 1	3000 rpm
	fcb	$40	;  64	 4 - Group 1	3500 rpm	       3625
	fcb	$20	;  32	 0 - Group 0	4000 rpm     3745
	fcb	$20	;  32	 0 - Group 0	4500 rpm
	fcb	$20	;  32	 0 - Group 0	5000 rpm
	fcb	$20	;  32	 0 - Group 0	5500 rpm
	fcb	$20	;  32	 0 - Group 0	6000 rpm
;
; -----------------------------------------------------------------------------
; Tables used for adjusting the MAT sensor readings...
;
;			   AIR_temp + 103
;  These tables return:   ----------------
;			       1.2375
; TABAR
; MAT LINEARIZATION TABLE:
; NOTE:
; Use the formula x = 16/11(T + 75)
; to enter values in the linearization table.
; Where x = table entry in decimal radix,
;
; T = temperature in degrees Celcius
;---------------------------------------------
;
Lf247:	fcb	$ff	; 255
	fcb	$ff	; 255
	fcb	$ff	; 255
	fcb	$da	; 218
	fcb	$c0	; 192
	fcb	$af	; 175
	fcb	$a1	; 161
	fcb	$96	; 150
	fcb	$8b	; 139
	fcb	$81	; 129
	fcb	$76	; 118
	fcb	$6b	; 107
	fcb	$5c	;  92
	fcb	$47	;  71
	fcb	$00	;   0
	fcb	$00	;   0
;
; ----------------------------------------------------------------------------
; MAT cold adjustment table
;---------------------------------------------
; TEXPNDA
; EXPANDED TEMPERATURE TABLE FOR FORD TEMP. SENSORS
; ENTRIES IN THIS TABLE EXPAND TABAR ABOVE FROM  208 to  223 A/D
;
; GM SENSOR VALUES SHOWN
;---------------------------------------------
;
Lf257:	fcb	$47	;  71
	fcb	$46	;  70
	fcb	$42	;  66
	fcb	$40	;  64
	fcb	$3e	;  62
	fcb	$3b	;  59
	fcb	$38	;  56
	fcb	$35	;  53
	fcb	$30	;  48
	fcb	$29	;  41
	fcb	$1f	;  31
	fcb	$00	;   0
	fcb	$00	;   0
	fcb	$00	;   0
	fcb	$00	;   0
	fcb	$00	;   0
;
; -----------------------------------------------------------------------------
; Correction table for the Coolant temperature sensor.....
;  This values work out as:
;	TH20_degrees_f = (ECU_adjusted_TH20 * 1.35) - 67.0
;
Lf267:	fcb	$f6	; 246  - if coolant sensor too high use this value
;
;---------------------------------------------
; TABH2O
; Coolant Temp Linearization Table:
; note:
;  Use the formula x = 4/3(T + 55) to enter values
;	 in the linearization table.
;
; Where x = table entry in decimal radix,
; T = temperature in degrees Celcius
; 16 LINES
;----------------------------------------------
Lf268:	fcb	$eb	; 235
	fcb	$cf	; 207
	fcb	$c1	; 193
	fcb	$b5	; 181
	fcb	$ac	; 172
	fcb	$94	; 148
	fcb	$85	; 133
	fcb	$79	; 121
	fcb	$6e	; 110
	fcb	$64	; 100
	fcb	$5c	; 92
	fcb	$52	; 82
	fcb	$47	; 71
	fcb	$3a	; 58
	fcb	$26	; 38
	fcb	$00	; 0
; ===========================================================================-
; This one is used for very cold water temperatures.... or is it ?????
;---------------------------------------------
; TEXPNDH								(WS)
; Expanded Temperature Table for Ford Temperature Sensors
;
;  Entries in this Table Expand TABH2O above from D0H to DFH.
;						  208	 233 ADC
;
Lf278:	fcb	$26	; 38
	fcb	$24	; 36
	fcb	$22	; 34
	fcb	$20	; 32
	fcb	$1e	; 30
	fcb	$1b	; 27
	fcb	$18	; 24
	fcb	$15	; 21
	fcb	$11	; 17
	fcb	$0b	; 11
	fcb	$01	;  1
	fcb	$00	;  0
	fcb	$00	;  0
	fcb	$00	;  0
	fcb	$00	;  0
	fcb	$00	;  0
; -----------------------------------------------------------------------------
; The below 16 word table is indexed by rpm (timing period) and is used in
;  spark angle calculations. Its indexed output is used as the RPM pointer
;  into the main Spark matrix table
;---------------------------------------------
; TBTPMA
; RPM BREAKPOINTS FOR SPARK TABLE
;
; (16 Lines, 16 bit values)
;
;  Val = usec * 8
;	 1,875,000/RPM
;---------------------------------------------
;
Lf288:	fdb	$0139	;   313 - 5,990 rpm
	fdb	$0139	;   313 - 5,990 rpm
	fdb	$0154	;   340 - 5,515 rpm
	fdb	$0177	;   375 - 5,000 rpm
	fdb	$01a0	;   416 - 4,507 rpm
	fdb	$01d4	;   468 - 4,006 rpm
	fdb	$0217	;   535 - 3,505 rpm
	fdb	$0271	;   625 - 3,000 rpm
	fdb	$02ee	;   750 - 2,500 rpm
	fdb	$03a9	;   937 - 2,000 rpm
	fdb	$0493	;  1171 - 1,600 rpm
	fdb	$061a	;  1562 - 1,200 rpm
	fdb	$0753	;  1875 - 1,000 rpm
	fdb	$0823	;  2083 -   900 rpm
	fdb	$0927	;  2343 -   800 rpm
	fdb	$c350	; 50000 -    38 rpm
;
; -----------------------------------------------------------------------------
; The below is a 8 word table index by the computed air density charge used
;  for spark angle calculations....
;  The vacuum is what the controller would display as VAC:
;  Displayed_Vacuum(in) = 28.9 - ( X * .01152)
;
; How Ld907 responds with a table like this
;					L001b	   B
;  > 23.0"		000 --> 512	  7	   0
;    23.0" --> 19.1"	513 --> 848	  7	   0 --> 255
;    19.1" --> 17.1"	849 --> 1023	  6	   0 --> 255
;    17.1" --> 12.4"   1024 --> 1432	  5	   0 --> 255
;    12.4" --> 10.0"   1433 --> 1637	  4	   0 --> 255
;    10.0" -->	7.1"   1638 --> 1893	  3	   0 --> 255
;     7.1" -->	4.1"   1894 --> 2149	  2	   0 --> 255
;     4.1" -->	0.6"   2150 --> 2456	  1	   0 --> 255
;   < 0.6"	       2457 --> up	  0	   0
;
;---------------------------------------------
; TBDA
; AIR Density FOR BASE SPARK TABLE
;---------------------------------------------
;
Lf2a8:	fdb	$0200	;  512 - 23.0"
	fdb	$0351	;  849 - 19.1"
	fdb	$0400	; 1024 - 17.1"
	fdb	$0599	; 1433 - 12.4"
	fdb	$0666	; 1638 - 10.0"
	fdb	$0766	; 1894 -  7.1"
	fdb	$0866	; 2150 -  4.1"
	fdb	$0999	; 2457 -  0.6"
;
	if	not no_fills
f2b8:	fill	0,4
	endif
;
; Start of the 8x16 Spark Advance Matrix.................................
; This matrix is organized into 8 columns (air charge) by 16 rows (rpm)
; Remember that these are in .25 degree units and there is a 10 deg base timing
;
;
; WOT......
;
Lf2bc:	fcb	$08	; 12 degrees	  38 rpm
	fcb	$18	; 16 deg	 800 rpm
	fcb	$18	; 16 deg	 900 rpm
	fcb	$18	; 16 deg	1000 rpm
	fcb	$38	; 24 deg	1200 rpm
	fcb	$54	; 31 deg	1600 rpm
	fcb	$54	; 31 deg	2000 rpm
	fcb	$60	; 34 deg	2500 rpm
	fcb	$68	; 36 deg	3000 rpm
	fcb	$64	; 34 deg	3500 rpm
	fcb	$68	; 36 deg	4000 rpm
	fcb	$64	; 34 deg	4500 rpm
	fcb	$68	; 36 deg	5000 rpm
	fcb	$68	; 36 deg	5500 rpm
	fcb	$68	; 36 deg	6000 rpm
	fcb	$64	; 34 deg	above 6000 rpm
;
; 4.1".....
;
	fcb	$08	; 12 degrees
	fcb	$2c	; 21 deg
	fcb	$2c	; 21 deg
	fcb	$3c	; 25 deg
	fcb	$5c	; 23 deg
	fcb	$6c	; 27 deg
	fcb	$6c	; 27 deg
	fcb	$6c	; 27 deg
	fcb	$70	; 28 deg
	fcb	$68	; 36 deg
	fcb	$68	; 36 deg
	fcb	$68	; 36 deg
	fcb	$68	; 36 deg
	fcb	$68	; 36 deg
	fcb	$68	; 36 deg
	fcb	$64	; 34 deg
;
; 7.1"......


	fcb	$28	; 20 degrees
	fcb	$6c	; 37 deg
	fcb	$6c	; 37 deg
	fcb	$80	; 42 deg
	fcb	$84	; 43 deg
	fcb	$84	; 43 deg
	fcb	$84	; 43 deg
	fcb	$7c	; 41 deg
	fcb	$78	; 40 deg
	fcb	$74	; 39 deg
	fcb	$78	; 40 deg
	fcb	$74	; 39 deg
	fcb	$74	; 39 deg
	fcb	$74	; 39 deg
	fcb	$70	; 38 deg
	fcb	$70	; 38 deg
;
; 10.0".....
;
	fcb	$28	; 20 degrees
	fcb	$7c	; 41 deg
	fcb	$7c	; 41 deg
	fcb	$80	; 42 deg
	fcb	$88	; 44 deg
	fcb	$88	; 44 deg
	fcb	$8c	; 45 deg
	fcb	$90	; 46 deg
	fcb	$8c	; 45 deg
	fcb	$84	; 43 deg
	fcb	$8c	; 45 deg
	fcb	$88	; 44 deg
	fcb	$84	; 43 deg
	fcb	$84	; 43 deg
	fcb	$80	; 42 deg
	fcb	$78	; 40 deg
;
; 12.4".....
;
	fcb	$28	; 20 degrees
	fcb	$7c	; 41 deg
	fcb	$7c	; 41 deg
	fcb	$84	; 43 deg
	fcb	$90	; 46 deg
	fcb	$90	; 46 deg
	fcb	$90	; 46 deg
	fcb	$90	; 46 deg
	fcb	$90	; 46 deg
	fcb	$90	; 46 deg
	fcb	$90	; 46 deg
	fcb	$8c	; 45 deg
	fcb	$8c	; 45 deg
	fcb	$88	; 44 deg
	fcb	$84	; 43 deg
	fcb	$78	; 40 deg
;
; 17.1".....
;
	fcb	$38	; 24 degrees
	fcb	$80	; 42 deg
	fcb	$80	; 42 deg
	fcb	$80	; 42 deg
	fcb	$80	; 42 deg
	fcb	$8c	; 45 deg
	fcb	$90	; 46 deg
	fcb	$90	; 46 deg
	fcb	$90	; 46 deg
	fcb	$90	; 46 deg
	fcb	$90	; 46 deg
	fcb	$90	; 46 deg
	fcb	$90	; 46 deg
	fcb	$8c	; 45 deg
	fcb	$88	; 44 deg
	fcb	$78	; 40 deg
;
; 19.1".....
;
	fcb	$38	; 24 degrees
	fcb	$68	; 36 deg
	fcb	$68	; 36 deg
	fcb	$68	; 36 deg
	fcb	$70	; 38 deg
	fcb	$88	; 44 deg
	fcb	$90	; 46 deg
	fcb	$90	; 46 deg
	fcb	$90	; 46 deg
	fcb	$90	; 46 deg
	fcb	$90	; 46 deg
	fcb	$90	; 46 deg
	fcb	$90	; 46 deg
	fcb	$90	; 46 deg
	fcb	$88	; 44 deg
	fcb	$78	; 40 deg
;
; 23"......
;
	fcb	$38	; 24 degrees
	fcb	$50	; 30 deg
	fcb	$50	; 30 deg
	fcb	$50	; 30 deg
	fcb	$50	; 30 deg
	fcb	$50	; 30 deg
	fcb	$50	; 30 deg
	fcb	$64	; 35 deg
	fcb	$64	; 35 deg
	fcb	$64	; 35 deg
	fcb	$64	; 35 deg
	fcb	$64	; 35 deg
	fcb	$64	; 35 deg
	fcb	$64	; 35 deg
	fcb	$64	; 35 deg
	fcb	$64	; 35 deg
;
; ----------------------------------------------------------------------------
;
	if	not no_fills
f33c:	fill	0,32
	endif
;
; Used during starting.  RPM is between 229 and 458 RPM.
;  Used to set the Spark Advance durring Cranking.  These values are in
;  .25 degree units and with a base timing of 10 degrees.
;---------------------------------------------
; TABNGA
; SPARK ADVANCE FOR 228 < RPM < 457
; (not including initial advance)
;
; VAL = Deg SPK * 4
;---------------------------------------------
;
Lf35c:	fcb	$10	; 26 deg	458 rpm
	fcb	$10	; 26 deg	431 rpm
	fcb	$10	; 26 deg	407
	fcb	$10	; 26 deg	385
	fcb	$10	; 26 deg	366
	fcb	$10	; 26 deg	349
	fcb	$0c	; 22 deg	333
	fcb	$0c	; 22 deg	318
	fcb	$0c	; 22 deg	305
	fcb	$0c	; 22 deg	293
	fcb	$08	; 18 deg	282
	fcb	$04	; 14 deg	271
	fcb	$04	; 14 deg	262
	fcb	$00	; 10 deg	253
	fcb	$00	; 10 deg	244
	fcb	$00	; 10 deg	236 rpm
;
; -----------------------------------------------------------------------------

	if	not mis32x

; The following two tables are used in determining the idle spark angle.
;  More than 458 RPM, throttle plates closed, and the current rpm is above
;  the target idle rpm.
;
; this table is index by RPM/25 above target idle
;
;---------------------------------------------
; DELTA RPM BREAKPOINTS FOR SPARK CONTROL OF IDLE SPEED WHEN CURRENT RPM
;  IS > NOMINAL IDLE RPM
;
; (16 LINE 16 bit values)
;
;  TBL =  (CURRENT RPM - TARGET IDLE RPM)/25
;---------------------------------------------
;
Lf36c:	fdb	$0000	; 0	   0 rpm
	fdb	$0001	; 1	  25 rpm
	fdb	$0002	; 2	  50 rpm
	fdb	$0003	; 3	  75 rpm
	fdb	$0004	; 4	 100 rpm
	fdb	$0005	; 5	 125 rpm
	fdb	$0006	; 6	 150 rpm
	fdb	$0008	; 8	 200 rpm
	fdb	$000e	; 14	 350 rpm
	fdb	$001e	; 30	 750 rpm
	fdb	$0038	; 56	1400 rpm
	fdb	$0050	; 80	2000 rpm
	fdb	$006e	; 110	2750 rpm
	fdb	$008c	; 140	3500 rpm
	fdb	$00a6	; 166	4150 rpm
	fdb	$00ce	; 206	5150 rpm
;
; The above table indexes into this table which contains the actual spark angles
;  (remember a base timing of 10 degrees)
;
;--------------------------------------------
; TBANTP
; SPARK MODULATION FOR IDLE SPEED CNTL WHEN DELTA RPM GT 0 RPM vs RPM
;
; (IDLE SPARK ADVANCE vs RPM ERROR
; i.e. SPEED IS HIGHER THAN NOMINAL
;
; (16 LINES, 8 BIT VAL'S)
;
; Val = Deg Spk * 4		(Added spk)
;--------------------------------------------
;
Lf38c:	fcb	$6c	; 108 - 37 degrees   above 5150 rpm
	fcb	$6c	; 108 - 37 degrees  4150 - 5150 rpm
	fcb	$6c	; 108 - 37 degrees  3500 - 4150 rpm
	fcb	$6c	; 108 - 37 degrees  2750 - 3500 rpm
	fcb	$6c	; 108 - 37 degrees  2000 - 2750 rpm
	fcb	$6c	; 108 - 37 degrees  1400 - 2000 rpm
	fcb	$6c	; 108 - 37 degrees   750 - 1400 rpm
	fcb	$6c	; 108 - 37 degrees   350 -  750 rpm
	fcb	$6c	; 108 - 37 degrees   200 -  350 rpm
	fcb	$6c	; 108 - 37 degrees   150 -  200 rpm
	fcb	$6c	; 108 - 37 degrees   125 -  150 rpm
	fcb	$6c	; 108 - 37 degrees   100 -  125 rpm
	fcb	$6c	; 108 - 37 degrees    75 -  100 rpm
	fcb	$6c	; 108 - 37 degrees    50 -   75 rpm
	fcb	$6c	; 108 - 37 degrees    25 -   50 rpm
	fcb	$6c	; 108 - 37 degrees     0 -   25 rpm
;
; -----------------------------------------------------------------------------
; The following two tables are used in determining the idle spark angle.
;  More than 458 RPM, throttle plates closed, and the current rpm is below
;  the target idle rpm.
;
;---------------------------------------------
; TABBKN
; DELTA RPM BREAKPOINTS FOR SPARK CONTROL of IDLE SPEED CONTROL
;   WHEN CURRENT RPM is Less Than NOMINAL IDLE RPM
;
; TBL = (CURRENT RPM + NOMINAL IDLE RPM)/25
;---------------------------------------------
;
Lf39c:	fdb	$0000	;  0	  0 rpm
	fdb	$0001	;  1	 25 rpm
	fdb	$0002	;  2	 50 rpm
	fdb	$0003	;  3	 75 rpm
	fdb	$0004	;  4	100 rpm
	fdb	$0005	;  5	125 rpm
	fdb	$0006	;  6	150 rpm
	fdb	$0007	;  7	175 rpm
	fdb	$0008	;  8	200 rpm
	fdb	$0009	;  9	225 rpm
	fdb	$000a	; 10	250 rpm
	fdb	$000b	; 11	275 rpm
	fdb	$000c	; 12	300 rpm
	fdb	$000e	; 14	350 rpm
	fdb	$0010	; 16	400 rpm
	fdb	$0012	; 18	450 rpm
;
;---------------------------------------------
; TBANTN
; SPARK MODULATION FOR IDLE SPEED CONTROL WHEN DELTA RPM Less Than 0
; i.e. speed is lower than nominal
;
; Table = deg spk * 4
;---------------------------------------------
;
Lf3bc:	fcb	$6c	; 108 - 37 degrees	above 450 rpm
	fcb	$6c	; 108 - 37 degrees	400 - 450 rpm
	fcb	$6c	; 108 - 37 degrees	350 - 400 rpm
	fcb	$6c	; 108 - 37 degrees	300 - 350 rpm
	fcb	$6c	; 108 - 37 degrees	275 - 300 rpm
	fcb	$6c	; 108 - 37 degrees	250 - 275 rpm
	fcb	$6c	; 108 - 37 degrees	225 - 250 rpm
	fcb	$6c	; 108 - 37 degrees	200 - 225 rpm
	fcb	$6c	; 108 - 37 degrees	175 - 200 rpm
	fcb	$6c	; 108 - 37 degrees	150 - 175 rpm
	fcb	$6c	; 108 - 37 degrees	125 - 150 rpm
	fcb	$6c	; 108 - 37 degrees	100 - 125 rpm
	fcb	$6c	; 108 - 37 degrees	 75 - 100 rpm
	fcb	$6c	; 108 - 37 degrees	 50 -  75 rpm
	fcb	$6c	; 108 - 37 degrees	 25 -  50 rpm
	fcb	$6c	; 108 - 37 degrees	  0 -  25 rpm

	endif
;
; -----------------------------------------------------------------------------
; Spark Angle modifier verses Water Temperature.  Each modifier is base 128
;  and in .25 degree units....
;---------------------------------------------
; TETH2O
; SPARK CORRECTION Vs COOLANT
; (Deg spark Added)
;
; TBL = (DEG SPK * 4)+128
;---------------------------------------------
;
Lf3cc:	fcb	$98	; 152 - +6 degrees	very cold -40 to 0 degrees    00
	fcb	$98	; 152 - +6 degrees	  ..... 		      10
	fcb	$98	; 152 - +6 degrees	    .....		      20
	fcb	$98	; 152 - +6 degrees	arround 0 - 20 degrees	      30
	fcb	$98	; 152 - +6 degrees	in the 20's and 30's	      40
	fcb	$98	; 152 - +6 degrees	in the 40's and 60's	      50
	fcb	$98	; 152 - +6 degrees	in the 70's and 80's	      60
	fcb	$98	; 152 - +6 degrees	in the 90's and 100's	      70
	fcb	$90	; 144 - +4 degrees	in the 110's and 120's	      80
	fcb	$88	; 136 - +2 degrees	in the 130's and 140's	      90
	fcb	$80	; 128 -  0 degrees	in the 150's and 160's	      A0
	fcb	$80	; 128 -  0 degrees	in the 180's and 190's	      B0
	fcb	$80	; 128 -  0 degrees	in the 200's and 210's	      C0
	fcb	$80	; 128 -  0 degrees	in the 220's and 230's	      D0
	fcb	$80	; 128 -  0 degrees	in the 240's and 250's	      E0
	fcb	$80	; 128 -  0 degrees	really HOT !!!! 	      F0
;
; -----------------------------------------------------------------------------
; Starting fuel injector pulse widths verse coolant temperature table.	The
;  coolant temp index is the adjusted value in L0003.
;
	if	not mis17x

Lf3dc:	fcb	$f9	; 255ms 	very cold -40 to 0 degrees	     00
	fcb	$f9	; 255ms 	  ......			     10
	fcb	$f4	; 220ms 	     .....			     20
	fcb	$9c	; 160ms 	arround 0 - 20 degrees		     30
	fcb	$45	;  70.7ms	in the 20's and 30's		     40
	fcb	$27	;  39.9ms	in the 40's and 60's		     50
	fcb	$23	;  35.8ms	in the 70's and 80's		     60
	fcb	$1f	;  31.7ms	in the 90's and 100's		     70
	fcb	$1b	;  27.6ms	in the 110's and 120's		     80
	fcb	$17	;  23.5ms	in the 130's and 140's		     90
	fcb	$17	;  23.5ms	in the 150's and 160's		     A0
	fcb	$17	;  23.5ms	in the 180's and 190's		     B0
	fcb	$17	;  23.5ms	in the 200's and 210's		     C0
	fcb	$17	;  23.5ms	in the 220's and 230's		     D0
	fcb	$17	;  23.5ms	in the 240's and 250's		     E0
	fcb	$17	;  23.5ms	really HOT !!!			     F0

	endif
; -----------------------------------------------------------------------------
; Coolant temperature lookup for idle speed activity work....
; Coolant dependant IAS %  If nothing needs more these are the min IAS % needed.
;---------------------------------------------
; TABTHE
; BASIC DUTY TABLE  Vs. COOLANT
;
; (Table for correction coeff. DCH20 interp)
;
; (THIS TABLE VALUE + VALVE OFFSET (LF745E)
;  = OPEN-LOOP DUTY OUTPUT)
;
; VAL = 2.56 * Duty Cycle
;---------------------------------------------
;
Lf3ec:	fcb	$8c	; 140  109%	very cold -40 to 0 degrees	     00
	fcb	$80	; 128  100%	   .....			     10
	fcb	$73	; 115	90%	      .....			     20
	fcb	$66	; 102	80%	arround 0 - 20 degrees		     30
	fcb	$5e	;  94	73%	in the 20's and 30's		     40
	fcb	$59	;  89	70%	in the 40's and 60's		     50
	fcb	$4f	;  79	62%	in the 70's and 80's		     60
	fcb	$45	;  69	54%	in the 90's and 100's		     70
	fcb	$33	;  51	40%	in the 110's and 120's		     80
	fcb	$2b	;  43	34%	in the 130's and 140's		     90
	fcb	$23	;  35	27%	in the 150's and 160's		     A0
	fcb	$1e	;  30	23%	in the 180's and 190's		     B0
	fcb	$19	;  25	20%	in the 200's and 210's		     C0
	fcb	$19	;  25	20%	in the 220's and 230's		     D0
	fcb	$19	;  25	20%	in the 240's and 250's		     E0
	fcb	$19	;  25	20%	really HOT !!!!!		     F0
;
; Battery adjustment table for corrrecting the IAC motor for battery voltage....
;---------------------------------------------
; TBKBAT
; DUTY CYCLE CORRECTION Vs. Vbatt
;  (6 - 16VDC)
; (At 40% duty, 150Hz)
;
;  VAL + %D.C. * 64
;---------------------------------------------
;
Lf3fc:	fcb	$9f	; 159	 6.000 volts
	fcb	$8d	; 141	 6.667 volts
	fcb	$7f	; 127	 7.333 volts
	fcb	$75	; 117	 8.000 volts
	fcb	$6b	; 107	 8.667 volts
	fcb	$62	;  98	 9.333 volts
	fcb	$5c	;  92	10.000 volts
	fcb	$56	;  86	10.667 volts
	fcb	$50	;  80	11.333 volts
	fcb	$4b	;  75	12.000 volts
	fcb	$47	;  71	12.667 volts
	fcb	$44	;  68	13.333 volts
	fcb	$40	;  64	14.000 volts <-- zero correction point
	fcb	$3d	;  61	14.667 volts
	fcb	$3b	;  59	15.333 volts
	fcb	$38	;  56	16.000 volts
;
	if	not mis15x

; An Idle Air lookup table.....
;---------------------------------------------
; TBDUTY
;
; DUTY BKPTs FOR THE PERIOD TABLE  f(DUTY)
;  (IN PCT DC)
;
; (8 LINES, 16 bit val's)
;
;  TABLE = Pct Duty Cycle * 2.56
;---------------------------------------------
;
Lf40c:	fdb	$0018	; 24
	fdb	$0033	; 51
	fdb	$004d	; 77
	fdb	$006b	; 107
	fdb	$0086	; 134
	fdb	$00a4	; 164
	fdb	$00d4	; 212
	fdb	$00ff	; 255
;
; Another Idle Air activity table - which always comes to the same results !!!
;
; TBPRDH
; Period high byte f(DUTY) see LF424 for low byte.
; (512usec/lsb)
;
; (8 LINES 8 BIT VAL'S)
;
; Size of LLF424/LF41C is defined by TBDTYI
; located at the top of file.
;
; 150Hz Period at 100% duty cycle
;
; Table = usec * 512
;
Lf41c:	fcb	$1a	; 26
	fcb	$1a
	fcb	$1a
	fcb	$1a
	fcb	$1a
	fcb	$1a
	fcb	$1a
	fcb	$1a
;
; more idle air.  being all entries are then same will always return 10
;
; TBPRDH
; Period high byte f(DUTY) see LF424 for low byte.
; (512usec/lsb)
;
; (8 LINES 8 BIT VAL'S)
;
; Size of LLF424/LF41C is defined by TBDTYI
; located at the top of file.
;
; 150Hz Period at 100% duty cycle
;
; Table = usec * 512
;
Lf424:	fcb	$0a	; 10
	fcb	$0a
	fcb	$0a
	fcb	$0a
	fcb	$0a
	fcb	$0a
	fcb	$0a
	fcb	$0a
;
	endif
;
; -----------------------------------------------------------------------------
; This table is index by water temperature (upper four bits of L0003).
; Its output is used to increase target idle speed.  It is basically added
; to the idle speed modifier.  Strange numbers because of offset addressing.
; The actual idle rpm table is at Lff52.
;---------------------------------------------				(WS)
; TBGNOM
; NOMINAL RPM TABLE Vs. COOL
; IMPORTANT:
;		TO GET FINAL NOMINAL RPM,
;		OFFSET THIS TABLE by LF770, (-150 RPM)
;
;		  Use the conversion:
;
;		       117,187.5
;		    --------------- = RPM
;			128uS/bit
;
; NOTE: The last line of this table should have
;		the lowest idle speed (800 RPM) for proper
;		dashpot operation.
;
; VAL = RPM/25
;
; My Note: LF770 is the Target Idle RPM value in EEPROM.............
;---------------------------------------------
;
Lf42c:	fcb	$3a	; 58	< -40 degrees
	fcb	$3a	; 58	< -40 degrees
	fcb	$38	; 56	  -27 deg
	fcb	$36	; 54	  - 3 deg
	fcb	$32	; 50	   18 deg
	fcb	$2e	; 46	   38 deg
	fcb	$2a	; 42	   61 deg
	fcb	$28	; 40	   83 deg
	fcb	$27	; 39	  105 deg
	fcb	$25	; 37	  126 deg
	fcb	$22	; 34	  148 deg
	fcb	$20	; 32	  169 deg
	fcb	$20	; 32	  192 deg
	fcb	$20	; 32	  212 deg
	fcb	$20	; 32	  233 deg
	fcb	$20	; 32	  264 deg
;
; This table is indexed by some very strange going ons.  Look arround Ld0c8
;  for more interpotation.  Comment ranges are based on those number also.
; Output values are compared to (TPS*11)-offset  ADC values.
; Used in IAS calculations..
; Min IAS% vs RPM.
;---------------------------------------------
; TBDSPI
; MIN AIR BYPASS MOTOR DASHPOT MULT Vs. RPM
;
;
; LOOKUP RPM =
; CURRENT RPM + RPMNOM(Cool) - RPM NOM(125Deg C)
;
; VAL = Duty Cycle * 2.56
;---------------------------------------------
;
Lf43c:	fcb	$00	;  0		 ~< 0 rpm
	fcb	$00	;  0		 ~ 75 rpm
	fcb	$00	;  0		 ~475 rpm
	fcb	$00	;  0		 ~875 rpm
	fcb	$23	; 35	27%	~1275 rpm
	fcb	$23	; 35	27%	~1675 rpm
	fcb	$26	; 38	30%	~2075 rpm
	fcb	$26	; 38	30%	~2475 rpm
	fcb	$28	; 40	31%	~2875 rpm
	fcb	$28	; 40	31%	~3275 rpm
	fcb	$2b	; 43	33%	~3675 rpm
	fcb	$2b	; 43	33%	~4075 rpm
	fcb	$2e	; 46	36%	~4475 rpm
	fcb	$2e	; 46	36%	~4875 rpm
	fcb	$30	; 48	38%	~5275 rpm
	fcb	$30	; 48	38%	>5675 rpm
;
; Same lookup index as above table........
; Max IAS% vs RPM
;---------------------------------------------
; TBDSPS
; MAX AIR BYPASS MOTOR DASHPOT MULT Vs. RPM
; f(RPM)
;
;
; VAL = Duty Cycle * 2.56
;---------------------------------------------
;
Lf44c:	fcb	$0c	; 12	 9%	 ~< 0 rpm
	fcb	$0c	; 12	 9%	 ~ 75 rpm
	fcb	$1c	; 28	22%	 ~475 rpm
	fcb	$2b	; 43	33%	 ~875 rpm
	fcb	$3a	; 58	45%	~1275 rpm
	fcb	$4f	; 79	62%	~1675 rpm
	fcb	$59	; 89	70%	~2075 rpm
	fcb	$5c	; 92	72%	~2475 rpm
	fcb	$5e	; 94	73%	~2875 rpm
	fcb	$61	; 97	76%	~3275 rpm
	fcb	$61	; 97	76%	~3675 rpm
	fcb	$61	; 97	76%	~4075 rpm
	fcb	$61	; 97	76%	~4475 rpm
	fcb	$61	; 97	76%	~4875 rpm
	fcb	$61	; 97	76%	~5275 rpm
	fcb	$61	; 97	76%	>5675 rpm
; ----------------------------------------------------------------------------
; 6.666 ms, Nominal Period for VAE (IAC) Control Signal (150 Hz).
Lf45c:	fdb	$1a0a	; 6666 - 6.666 ms - total IAC time period
; ----------------------------------------------------------------------------
; Basic Offset for VAE (IAC) Duty Cycle (30%)
Lf45e:	fdb	$07d0	; 2000 - 2.000 ms - added to computed On time value
; ----------------------------------------------------------------------------
; Nominal Duty Cycle Min Limit
Lf460:	fdb	$0682	; 1666 - 1.666 ms - minimun On time allowed
; ----------------------------------------------------------------------------
; Nominal Duty Cycle Max Limit
Lf462:	fdb	$176f	; 5999 - 5.999 ms - maximun On time allowed
; ----------------------------------------------------------------------------
; Actuation Duty Cycle Min Limit
Lf464:	fdb	$0682	; 1666 - 1.666 ms - min On time after Batt adjust
; ----------------------------------------------------------------------------
; 6 msec, Actuation Duty Cycle Max Limit
Lf466:	fdb	$176f	; 5999 - 5.999 ms - max On time after Batt adjust
; ----------------------------------------------------------------------------
; The following six items are used in calculating the IAS requirements to
;  get the idle speed corrected.....
; ----------------------
Lf468:	fcb	$16	; Delta RPM Threshold for 2nd Neg Proportional Term
; ----------------------------------------------------------------------------
Lf469:	fcb	$30	; First Neg Proportional Gain Term
; ----------------------------------------------------------------------------
Lf46a:	fcb	$80	; 2nd Multi Coef of DCPROP
; ----------------------------------------------------------------------------
Lf46b:	fcb	$10	; Delta RPM Threshold for Double Pos Proportional Term
; ----------------------------------------------------------------------------
Lf46c:	fcb	$60	; First Multi Coef of DCPROPN
; ----------------------------------------------------------------------------
Lf46d:	fcb	$b0	; 2nd Multi Coef of DCPROP, RPM too Low
; ----------------------------------------------------------------------------
; Threshold of last Incr RPM to sub Lf472 from Duty Cycle
Lf46e:	fdb	$00fa	; 250 - IAS rpm trip for speeding up motor
; ----------------------------------------------------------------------------
; Threshold for Fast Decrease RPM to Add Lf473 to Duty Cycle
Lf470:	fdb	$00b8	; 184 - IAS rpm trip for slowing down motor
; ----------------------------------------------------------------------------
; Positive Derivate ABS Value
Lf472:	fcb	$0c	; 12 - IAS factor for speeding up motor
; ----------------------------------------------------------------------------
; Negative Derivate ABS Value
Lf473:	fcb	$07	;  7 - IAS factor for slowing down motor
; ---------------------------------------------------------------------------
; DCK1, Lower Threshold for Duty Cycle Integral Update
Lf474:	fcb	$08	; 6.25% - IAC % trip point
; ---------------------------------------------------------------------------
; DCK1, Upper Threshold for Duty Cycle Integral Update
Lf475:	fcb	$a0	;  125% - IAC % trip point
; ---------------------------------------------------------------------------
Lf476:	fcb	$30	; Duty Cycle Int Max Value (Pos or Neg)
; ---------------------------------------------------------------------------
; Gain Applied to Duty Cycle Prop to Speed Integral Updating
Lf477:	fcb	$c0	; 192 - multiply by 12 (192/16=12)
; ---------------------------------------------------------------------------
Lf478:	fcb	$ff	; Threshold for AUTOADAP Calculation
			;  (autoadap.calc. applies a learned calc enable)
; ---------------------------------------------------------------------------
Lf479:	fcb	$92	; Upper RPM Window Threshhold for the Autoadaptive
			;  Calculation Enable - 803 RPM
; ---------------------------------------------------------------------------
Lf47a:	fcb	$92	; Lower RPM Window Threshhold for the Autoadaptive
			;  Calculation Enable - 803 RPM
; ---------------------------------------------------------------------------
Lf47b:	fcb	$ff	; 255 - seed L0073 - never used !	mis44:
;
; The below are dashpot values.  The dahspot counter is bumped at the indicated
;  rate by the timer overflow handler.
;  int(seed/rate) * 131ms = dashpot period
;  int(7400/197)  * 131ms = 4.85 seconds
;
Lf47c:	fdb	$1b58	; 7000 - dashpot seed value	4.59 seconds
; ---------------------------------------------------------------------------
; Delta RPM Period Initialization
Lf47e:	fdb	$1ce8	; 7400 - dashpot seed value	4.85 seconds
; ---------------------------------------------------------------------------
; Extra-Duty for Gain Calculation at Crank or During Decel, TPS at Min
Lf480:	fcb	$20	; 32
; ---------------------------------------------------------------------------
; DELTA Target Idle RPM DECR STEP (at CRANK)
Lf481:	fcb	$c5	; 197  - dashpot countdown rate
; ---------------------------------------------------------------------------
Lf482:	fcb	$c5	; 197  - dashpot countdown rate
; ---------------------------------------------------------------------------
; Delta Period (Between desired & nominal) for Decel Strategy Enable
Lf483:	fcb	$02	; rpm offset - (512 usec WS)
; ............................................................................
; If COOL > than this then use TPNOM (Lf485)
Lf484:	fcb	$b0	; 176 - 170 degree (water)
; ----------------------------------------------------------------------------
; Delta Period to be subtracted from TPNOM if COOL > Lf484 when calculating
;  Idle Spark advance.
Lf485:	fcb	$94	; 148 - 792 target idle rpm sub amount
; ----------------------------------------------------------------------------

Lf486:	fcb	$b0	; Throttle Potentiometer Scaling Factor for Dashpot
Lf487:	fcb	$ff	; 255
f488:	fdb	$1400
; ----------------------------------------------------------------------------
; How much to add to the IAC duty cycle if the Air Conditioner is On.
Lf48a:	fcb	$11	; 17 - 13% added to Idle Air percentage
; ----------------------------------------------------------------------------
Lf48b:	fcb	$02	; how fast we can decrease the lowest TPS ADC stash
Lf48c:	fcb	$02	; how fast we can increase the lowest TPS ADC stash
Lf48d:	fcb	$35	;  TPS closed threshold - 1.035 volts - Max TPS at Idle
Lf48e:	fcb	$40	;  8 sec - Counter value for Idle Threshold Update
Lf48f:	fcb	$03	; Min Delta Throttle between TPS A/D and FARSM
;
; Constants used by the IAC interrupt handler.	Seems that these values will
;  bounce the IAC motor back and forth at a 125ms rate....  About what I
;  hear when the key is first turned on.
;
Lf490:	fdb	$f424
Lf492:	fdb	$7a12
;
Lf494:	fcb	$07	; 1 sec - Time period to enable IAC motor
;
	if	not no_fills
f495:	fdb	$c350
f497:	fcb	$3a
f498:	fdb	$98c8
f49a:	fcb	$07
f49b:	fcb	$53
f49c:	fcb	$02
f49d:	fdb	$ee1e
	endif
;
Lf49f:	fcb	$04	; Positive Delta Throttle Threshold
Lf4a0:	fcb	$04	; Negative Delta Throttle Threshold
Lf4a1:	fdb	$00fa	; Fixed PW Adder if Throttle Transient
Lf4a3:	fdb	$0000	; TJ Decreasing during Throttle Negative Transient
Lf4a5:	fcb	$ff	; Threshold Above which Pressure Transient is Inhibited
Lf4a6:	fdb	$0155	; 5499 RPM - Disable Transient Management above this RPM
Lf4a8:	fcb	$ff	; Disable Transient Management above this MAP ADC
Lf4a9:	fcb	$00
; ----------------------------------------------------------------------------
; Minimum Delta MAP required to compute transient fuel requirements
Lf4aa:	fcb	$02	; MAP ADC threshold - less than this change then make
			;  like no change at all
; ----------------------------------------------------------------------------
Lf4ab:	fcb	$09	; 56% of delta MAP ADC
; ----------------------------------------------------------------------------
; POSITIVE TRANSIENT GAIN MULT COEF OF POS DMAPC TO CALC THE ADDITIVE INJ TIME
;  CORR FOR MAP TRANSIENTS
Lf4ac:	fcb	$0a	; 10
; ----------------------------------------------------------------------------
; counter value of transient decrease phases
Lf4ad:	fcb	$0d	; 13 - dist trig counter -
; ----------------------------------------------------------------------------
; DELTAF/DELTAM NEG CONV COEF, DELTA MAP SCALING
Lf4ae:	fcb	$09	; 56% of delta MAP ADC
; ----------------------------------------------------------------------------
Lf4af:	fcb	$02
; -----------------------------------------------------------------------------
; MULT COEFF OF NEG DMAPC2 TO CALC SUBTRACTIVE INJ. TIME CORR FOR MAP TRANS
Lf4b0:	fcb	$02	; 2 (0.004 - WS for 3512 code)
; -----------------------------------------------------------------------------
; MULT COEFF. OF POSITIVE DMAPC2 TO CALC ADDITIVE INJ TIME CORR FOR
;  MAP TRANSIENTS.
Lf4b1:	fcb	$08	; 8 multiplier of L004e (0.031 - WS for 3512 code)
; -----------------------------------------------------------------------------
Lf4b2:	fcb	$07	; 7
; -----------------------------------------------------------------------------
Lf4b3:	fcb	$31	; 49 - 19% decay rate
; -----------------------------------------------------------------------------
Lf4b4:	fcb	$31	; 49 - 19% decay rate
; -----------------------------------------------------------------------------
f4b5:	fdb	$ffff
Lf4b7:	fcb	$06	; Delta MAP Threshold (Transient Strategy)
Lf4b8:	fcb	$04	; MAP offset for slope calculation of Tj=Tj*f(MAP)
Lf4b9:	fdb	$000a	; Security time step for injection on phase 6
;
; ............................................................................
;
; Transient EnRich Decay Table................(WS)
; This two tables are index by water temperature (L0003 / 16)
;  The are used in calculation transient throttle fuel responses rates
;  These are decay rates...
;
Lf4bb:	fcb	$e6	; 230	90%	< -40 degrees
	fcb	$e6	; 230	90%	< -40 deg
	fcb	$e6	; 230	90%	  -27 deg
	fcb	$e6	; 230	90%	  - 3 deg
	fcb	$e3	; 227	87%	   18 deg
	fcb	$e1	; 225	88%	   38 deg
	fcb	$de	; 222	87%	   61 deg
	fcb	$dc	; 220	86%	   83 deg
	fcb	$cc	; 204	80%	  105 deg
	fcb	$c0	; 192	75%	  126 deg
	fcb	$c0	; 192	75%	  148 deg
	fcb	$c0	; 192	75%	  169 deg
	fcb	$c0	; 192	75%	  192 deg
	fcb	$c0	; 192	75%	  212 deg
	fcb	$c0	; 192	75%	  233 deg
	fcb	$c0	; 192	75%	  264 deg
;
; Transient EnLean Decay Table......
; This table is indexed by water temperature
;
Lf4cb:	fcb	$e6	; 230		< -40 degrees
	fcb	$e6	; 230		< -40 deg
	fcb	$e6	; 230		  -27 deg
	fcb	$e6	; 230		  - 3 deg
	fcb	$e3	; 227		   18 deg
	fcb	$e1	; 225		   38 deg
	fcb	$de	; 222		   61 deg
	fcb	$dc	; 220		   83 deg
	fcb	$cc	; 204		  105 deg
	fcb	$c0	; 192		  126 deg
	fcb	$c0	; 192		  148 deg
	fcb	$c0	; 192		  169 deg
	fcb	$c0	; 192		  192 deg
	fcb	$c0	; 192		  212 deg
	fcb	$c0	; 192		  233 deg
	fcb	$c0	; 192		  264 deg
;
; ----------------------------------------------------------------------------
; Upper RPM Threshold for Cut Off by Pressure
Lf4db:	fdb	$0100	; 256 - 7324 RPM
; ----------------------------------------------------------------------------
; Lower RPM Threshold for Cut Off by Pressure
Lf4dd:	fdb	$0200	; 512 - 3662 RPM
; ----------------------------------------------------------------------------
Lf4df:	fcb	$01	; 1 - added to the lowest MAP ADC ever read stash
Lf4e0:	fcb	$01	; 1
Lf4e1:	fcb	$17	; 23
Lf4e2:	fcb	$17	; 23
Lf4e3:	fcb	$ff	; 255
Lf4e4:	fdb	$0000	; Minimum value of DJ1 during Cut-Off Entry
Lf4e6:	fcb	$06	; 6
Lf4e7:	fcb	$60	; Injector Phase during Cut off
Lf4e8:	fcb	$85	; 133	 +4%
Lf4e9:	fcb	$06	; 6  - counter seed
Lf4ea:	fcb	$40	; 64
;
	if	not no_fills
f4eb:	fcb	$06
f4ec:	fcb	$08
	endif
;
Lf4ed:	fcb	$00	; Fuel Enrichment at Exit from Cut-Off
			; 0 - how much to mod Fuel if over 7300 rpm (shut off)
;
	if	not no_fills
f4ee:	fcb	$00
f4ef:	fcb	$00
f4f0:	fcb	$00
f4f1:	fcb	$00
f4f2:	fcb	$01
	endif

Lf4f3:	fcb	$01		; .25 degree spark increase
Lf4f4:	fcb	$01		; .25 degree spark increase
Lf4f5:	fcb	$06		; 6
	if	not mis39x
Lf4f6:	fcb	$00		; Phase counter for Lf4f4 Updating
	endif
	if	not mis48x
Lf4f7:	fcb	$00		; SA decrement during Cut-Off
	endif
	if	not no_fills
f4f8:	fcb	$10
	endif
	if	not mis48x
Lf4f9:	fcb	$00		; Static SA during Cut-Off
				; min spark angle allowed
	endif
	if	not no_fills
f4fa:	fcb	$28
	endif
	if	not mis36x
; SA Offset during Deceleration with Throttle at Idle
Lf4fb:	fcb	$80		; 128 - spark modifier for rpm's above TH2O
;				;	set rpm trip point (L0017)
	endif
Lf4fc:	fcb	$1a	; Compression Ratio for Altitude Correction
Lf4fd:	fcb	$a7	; Barometric Pressure, Lower Threshold to Enable
			;   Altitude Correction.
Lf4fe:	fcb	$e9	; Barometric Pressure, Upper Threshold to Enable
			;   Altitude Correction.
Lf4ff:	fdb	$0463	; 1,669 RPM - Lower RPM Threshold for 1st Window
Lf501:	fdb	$038a	; 2,070 RPM - Upper RPM Threshold for 1st Window
Lf503:	fdb	$02fa	; 2,461 RPM - Lower RPM Threshold for 2nd Window
Lf505:	fdb	$02cc	; 2,619 RPM - Upper RPM Threshold for 2nd Window
Lf507:	fcb	$ff	; TPS for 1st RPM Window
Lf508:	fcb	$ff	; TPS for 2nd RPM Window
; ---------------------------------------------------------------------------
; How long to wait before Fuel Pump Cutoff
Lf509:	fcb	$17		; 23 - number of 131ms periods before FP Off
; ---------------------------------------------------------------------------
Lf50a:	fcb	$f0		; 240 -
; ---------------------------------------------------------------------------
; Lower Theshold to acknowledge Engine Start
Lf50b:	fcb	$1d	; 253 rpm trip point
; ---------------------------------------------------------------------------
; Upper threshold to determine if engine is started
Lf50c:	fcb	$0c	; 610 RPM
; ----------------------------------------------------------------------------
; MAP Threshold above which Spark is Retarded
Lf50d:	fcb	$c3	; 195 - about 5.5" MAP ADC
; ----------------------------------------------------------------------------
Lf50e:	fcb	$d3	; 211 - (150 deg) max TAIR allowed with throttle plates
;			;	in the closed position.
	if	not no_fills
f50f:	fcb	$00
f510:	fcb	$00
	endif
Lf511:	fcb	$ac	; 172
Lf512:	fcb	$50	; Soft Spark Rev Limiter Spark Modification - 12 degrees

	if	not no_fills
f513:	fdb	$8000
	endif

Lf515:	fcb	$ff	; 255 - init revolution counter
Lf516:	fcb	$80	; Number of revs threshold for SA decreasing updating
			; 128 revolutions
Lf517:	fcb	$00	; 0

	if	not no_fills
f518:	fcb	$09
f519:	fdb	$2802
f51b:	fdb	$1800
f51d:	fcb	$00
f51e:	fcb	$00
f51f:	fcb	$00
f520:	fcb	$00
f521:	fcb	$40
f522:	fcb	$03
f523:	fdb	$c000
f525:	fcb	$00
f526:	fcb	$ff
	fdb	$9030
f529:	fcb	$10
f52a:	fdb	$bb30
	endif
; -----------------------------------------------------------------------------
; The below two table are used in the calculation of how much time we can
;  add/subtract from the pulse width time.  The are what percentage of the
;  current PW verses RPM
;
	if	not mis_clsd_lp1
;
; 0" thru 18.5" of vacuum
;
; TBPROP2								(WS)
; OUT-OF-IDLE PROPORTIONAL TERM IF MAP > LF56C + LF56D
;	 90 + 240 mmhg = 330 mmhg = 43Kpa
;
Lf52c:	fcb	$1e	; 30 - 11.72%  <= 1200 rpm
	fcb	$30	; 48 - 18.75%	  1600 rpm
	fcb	$35	; 53 - 20.70%	  2000 rpm
	fcb	$35	; 53 - 20.70%	  2400 rpm
	fcb	$35	; 53 - 20.70%	  2800 rpm
	fcb	$35	; 53 - 20.70%	  3200 rpm
	fcb	$3b	; 59 - 23.05%	  3600 rpm
	fcb	$3c	; 60 - 23.44%  >= 4000 rpm
;
	endif
;
; ----------------------------------------------------------------------------
; 21" thru 29"
;
; TBPROP1								(WS)
; OUT-OF-IDLE PROPORTIONAL TERM IF  MAP < LF56D Vs. RPM
;	240 mmHG, 28 Kpa
;---------------------------------------------
;
Lf534:	fcb	$1e	; 30 - 11.72%  <= 1200 rpm
	fcb	$30	; 48 - 18.75%	  1600 rpm
	fcb	$35	; 53 - 20.70%	  2000 rpm
	fcb	$35	; 53 - 20.70%	  2400 rpm
	fcb	$35	; 53 - 20.70%	  2800 rpm
	fcb	$35	; 53 - 20.70%	  3200 rpm
	fcb	$3b	; 59 - 23.05%	  3600 rpm
	fcb	$3c	; 60 - 23.44%  >= 4000 rpm
;
; ----------------------------------------------------------------------------
; The below four tables are used in the computations to determine the rate of
;  change of the Pulse Width during closed loop operations.
;
; Rich - 0" to 18.5"
;---------------------------------------------
; TBINTR2
; OUT-OF-IDLE RICH A/F INTEG. TERM IF
; MAP > LF56C + LF56D (MAP Thresh) Vs. RPM
;---------------------------------------------
;
	if	not mis_clsd_lp1
;
Lf53c:	fcb	$1e	; 30 - <= 1200 rpm
	fcb	$28	; 40 - 1600 rpm
	fcb	$28	; 40 - 2000 rpm
	fcb	$32	; 50 - 2400 rpm
	fcb	$32	; 50 - 2800 rpm
	fcb	$40	; 64 - 3200 rpm
	fcb	$45	; 69 - 3600 rpm
	fcb	$4a	; 74 - >= 4000 rpm
;
	endif

; Rich - 21" to 29"
;
Lf544:	fcb	$1e	; 30 - <= 1200 rpm
	fcb	$28	; 40 - 1600 rpm
	fcb	$28	; 40 - 2000 rpm
	fcb	$32	; 50 - 2400 rpm
	fcb	$32	; 50 - 2800 rpm
	fcb	$40	; 64 - 3200 rpm
	fcb	$45	; 69 - 3600 rpm
	fcb	$4a	; 74 - >= 4000 rpm
;
	if	not mis_clsd_lp1

; Lean - 0" to 18.5"
;---------------------------------------------
; TBINTM2
; RICHENS A/F WHEN LEAN
; Out-of-idle lean A/F integ. term if:
;	 MAP > MAPLAM2 + MAPLAM1
;
;---------------------------------------------
;
Lf54c:	fcb	$3c	; 60  - <= 1200 rpm
	fcb	$50	; 80  - 1600 rpm
	fcb	$50	; 80  - 2000 rpm
	fcb	$64	; 100 - 2400 rpm
	fcb	$64	; 100 - 2800 rpm
	fcb	$80	; 128 - 3200 rpm
	fcb	$8a	; 138 - 3600 rpm
	fcb	$94	; 148 - >= 4000 rpm

	endif
;
; Lean - 21" to 29"
;
;---------------------------------------------
; TBINTR1 LF56D
; LEANS OUT A/F WHEN RICH
; OFF IDLE RICH A/F INTEG. TERM IF MAP < LF56D.
;---------------------------------------------\;
Lf554:	fcb	$3c	; 60  - <= 1200 rpm
	fcb	$50	; 80  - 1600 rpm
	fcb	$50	; 80  - 2000 rpm
	fcb	$64	; 100 - 2400 rpm
	fcb	$64	; 100 - 2800 rpm
	fcb	$80	; 128 - 3200 rpm
	fcb	$8a	; 138 - 3600 rpm
	fcb	$94	; 148 - >= 4000 rpm
; ----------------------------------------------------------------------------
	if	not my_cl_parms
;
Lf55c:	fcb	$a8	; 168 - 4,200 rpm upper closed loop trip point
Lf55d:	fcb	$4a	; 74  - 1,850 rpm lower closed loop trip point
Lf55e:	fcb	$56	; 86  - ~18" upper MAP closed loop trip point
Lf55f:	fcb	$c1	; 193 - ~6" lower MAP closed loop trip point
;
	endif
;
Lf560:	fcb	$c5	; 197 3.8 volts  82 degrees   WOT - TPS ????
Lf561:	fcb	$c5	; 197 3.8 volts  82 degrees   WOT - TPS ????
; ---------------------------------------------------------------------------
; MAT Low Threshold for Closed Loop					(WS)
Lf562:	fcb	$ff	; 255 - >= 248 degrees air temp
; ---------------------------------------------------------------------------
; MAT High Threshold for Closed Loop					(WS)
Lf563:	fcb	$ff	; 255 - >= 248 degrees air temp
; ---------------------------------------------------------------------------
; Threshold above which flag FLGPWO is set at key on
Lf564:	fcb	$ff	; 255 - greater than 287 degrees water temperature
; ---------------------------------------------------------------------------
Lf565:	fcb	$99	; 153 - 140 degrees water temperature
			; 60c Cool Threshold Lambda Control
			;
Lf566:	fcb	$01	;     - Number of cycles before a new rate PW change
			;	 value is calculated for closed loop operation
; ---------------------------------------------------------------------------
; Subtract Offset for Lambda Tables Interpolation
Lf567:	fcb	$30	; 48	1,200 RPM  (48*25)
; ---------------------------------------------------------------------------
Lf568:	fcb	$46	; 70	O2 LEAN trip point	.447 volts
Lf569:	fcb	$33	; 51	20% (used in PW calculations) - This is the
			;	maximun that closed loop fuel can pull the
			;	calculated Pulse Width.
Lf56a:	fcb	$ff	; 255	how many itterations before O2 sensor error
Lf56b:	fcb	$02	; 2  - delay count before Closing the Loop
; ----------------------------------------------------------------------------
; 12Kpa, 90*100/287 ABOVE LF56C+LF56D PRESS THRESH			(WS)
;     INTERP DONE ON THE NDEG 2 LAMBDA TABLES (TBL LF53C)
Lf56c:	fcb	$1f	; 31 - about 3.4" worth of vacuum in ADC counts
; ----------------------------------------------------------------------------
; 32Kpa, (240-92)*100/287 LT THIS PRESS THRESH				(WS)
; THE INTERP DONE ON THE NDEG 1 LAMBDA TABLES (TBL LF544)
;
Lf56d:	fcb	$33	; 51 - ~21" of vacuum (compared to adjusted MAP ADC)
; ----------------------------------------------------------------------------
; The two below constants are the values used by the closed loop PW subrountine
;  when we just had a change in the rich/lean condition
;
Lf56e:	fcb	$0a	; Integral Closed Loop Fuel Step term at Idle when Rich
Lf56f:	fcb	$0a	; Integral Closed Loop Fuel Step term at Idle when Lean
;
Lf570:	fcb	$18	; 24  - closed throttle PW mod percentage (clsd loop)
			; Proportional Closed Loop Feed Back term at Idle
;
Lf571:	fcb	$8c	; 140 - 120 degrees water temperature
			; TJ Correction Percentage Coolant Threshold
;
; The following two values are used to determine if it is ok to proceed with
;  closed loop fuel modification checks.  One is for if the coolant is cooler
;  than 105 degrees and the other is for when it is hotter...
;
;  ---------------------------------------------------------------------------
; Open Loop --> Closed Loop Delay, Cool GT 40c (105f)			(WS)
; Closed Loop delay for COOL GT 40c
Lf572:	fdb	$02af	; 687 - 90 second warmup (687*131ms) - hotter than 105
; ----------------------------------------------------------------------------
; Open Loop --> Closed Loop Delay, Cool LT 40c (105f)			(WS)
; Closed Loop delay for COOL LT 40c
Lf574:	fdb	$02af	; 687 - 90 decond warmup (687*131ms) - cooler than 105
; ----------------------------------------------------------------------------
	if not mis7x
Lf576:	fdb	0000	; a water temp test that does nothing
	endif
	if	not no_fills
f578:	fdb	$80ff
f57a:	fdb	$2c00
	endif
;
Lf57c:	fdb	$05a0	; During this time Lf560 and Lf561 are Different
			; 1440	3 minutes (1440*131ms = 3.1 minutes)
Lf57e:	fcb	$60	; 96	O2 RICH trip point	.618 volts
Lf57f:	fcb	$30	; 48	O2			.302 volts
; ----------------------------------------------------------------------------
; Lambda sensor threshold						(WS)
Lf580:	fcb	00	; This guy has something to do with the O2 sensor
;			;  One location it is used in a voltage compare and
;			;  in another a flag to reset the O2 sensor counter ????
; ----------------------------------------------------------------------------
	if	not no_fills
f581:	fdb	$ffff
f583:	fcb	$00
f584:	fcb	$40
f585:	fcb	$40
	endif
; ----------------------------------------------------------------------------
; Delay LF587, use on GRINTE calculation after each sensor  RICH <=>LEAN
Lf586:	fcb	$0a	; 10 - count value to signal further adjustment of the
			;	closed loop PW rate of change value
; ----------------------------------------------------------------------------
Lf587:	fcb	$10	; 16
Lf588:	fcb	00	; WOT ENRICHMENT ENABLE DELAY
Lf589:	fcb	$8c	; Minimum Coolant Temperature for WOT Enrichment Enable
			; 140 - ~120 degrees (coolant)
Lf58a:	fcb	00	; MAP value for Immediate WOT Enrichment
;
	if	not no_fills
f58b:	fcb	$01
f58c:	fcb	$39
f58d:	fcb	$01
f58e:	fcb	$4e
f58f:	fcb	$01
f590:	fdb	$6801
f592:	fdb	$8601
f594:	fdb	$aa01
f596:	fdb	$d502
f598:	fcb	$08
f599:	fcb	$02
f59a:	fcb	$49
f59b:	fcb	$02
f59c:	fdb	$9d03
f59e:	fcb	$0d
f59f:	fcb	$03
f5a0:	fdb	$aa04
f5a2:	fcb	$39
f5a3:	fcb	$06
f5a4:	fdb	$1a09
f5a6:	fdb	$2812
f5a8:	fcb	$4f
f5a9:	fcb	$f4
	fdb	$2400
f5ac:	fdb	$a800
f5ae:	fdb	$c400
f5b0:	fdb	$d300
f5b2:	fdb	$e000
f5b4:	fdb	$e000
f5b6:	fdb	$e000
f5b8:	fdb	$e000
f5ba:	fdb	$e000
f5bc:	fcb	$00
f5bd:	fdb	$8080
f5bf:	fdb	$8080
f5c1:	fdb	$9070
f5c3:	fcb	$58
f5c4:	fcb	$46
f5c5:	fcb	$46
f5c6:	fcb	$46
f5c7:	fcb	$45
f5c8:	fcb	$45
f5c9:	fcb	$58
f5ca:	fcb	$50
f5cb:	fcb	$00
f5cc:	fcb	$00
f5cd:	fdb	$8080
f5cf:	fdb	$8054
f5d1:	fcb	$54
f5d2:	fcb	$42
f5d3:	fcb	$42
f5d4:	fcb	$30
f5d5:	fcb	$30
f5d6:	fcb	$00
f5d7:	fcb	$00
f5d8:	fcb	$00
f5d9:	fcb	$00
f5da:	fcb	$00
f5db:	fcb	$00
f5dc:	fcb	$00
f5dd:	fcb	$70
	fdb	$8080
f5e0:	fdb	$2222
f5e2:	fdb	$2222
f5e4:	fcb	$00
f5e5:	fcb	$00
f5e6:	fcb	$00
f5e7:	fcb	$00
f5e8:	fcb	$00
f5e9:	fcb	$00
f5ea:	fcb	$00
f5eb:	fcb	$00
f5ec:	fcb	$00
f5ed:	fdb	$8080
f5ef:	fdb	$8080
f5f1:	fdb	$8181
f5f3:	fdb	$1800
f5f5:	fcb	$00
f5f6:	fcb	$00
f5f7:	fcb	$00
f5f8:	fcb	$00
f5f9:	fcb	$00
f5fa:	fcb	$00
f5fb:	fill	$FF,$0018
	endif
;
; ----------------------------------------------------------------------------
	if	not mis36x
;
; Table to adjust Spark verses Air Temperature under heavy loads  (<5.5")
; .25 degree units with a 128 bias (128 = zero adjustment)
;---------------------------------------------
; TBTETAR
; Table for SA correction  f(MAT)
; Used to retard spark in high boost conditions.
;
; ALL 0'S, NOT USED
;
;  128 = no change
;  TABLE = (DEG SPK Change * 4)+128
;---------------------------------------------
;
Lf613:	fcb	$80	; 128
	fcb	$80	; 128
	fcb	$80	; 128
	fcb	$80	; 128
	fcb	$80	; 128
	fcb	$80	; 128
	fcb	$80	; 128
	fcb	$80	; 128
	fcb	$80	; 128
	fcb	$80	; 128
	fcb	$80	; 128
	fcb	$80	; 128
	fcb	$80	; 128
	fcb	$80	; 128
	fcb	$80	; 128
	fcb	$80	; 128

	endif
;
; -----------------------------------------------------------------------------
	if	not no_fills
;
f623:	fill	$FF,$0010
f633:	fcb	$50
f634:	fcb	$50
f635:	fcb	$50
f636:	fcb	$50
f637:	fcb	$53
f638:	fdb	$6690
f63a:	fdb	$9a9a
f63c:	fdb	$9893
f63e:	fdb	$9088
f640:	fdb	$827d
f642:	fcb	$7b
f643:	fdb	$8235
f645:	fcb	$ff
	fdb	0000
f648:	fcb	$00
f649:	fcb	$00
f64a:	fcb	$02
f64b:	fcb	$0a
f64c:	fcb	$00
f64d:	fcb	$00
f64e:	fcb	$00
f64f:	fcb	$00
f650:	fcb	$00
f651:	fcb	$00
f652:	fcb	$00
f653:	fcb	$00
f654:	fcb	$00
f655:	fdb	$8000
f657:	fcb	$00
f658:	fdb	$8000
f65a:	fdb	$e00f
f65c:	fdb	$2720
f65e:	fdb	$2702
f660:	fcb	$09
f664:	fill	$FF,$0014
f674:	fdb	$0001
	endif
;
Lf677:	fcb	$fd	; ADC=253  MAP error trip point
Lf678	fcb	$01	; ADC=1    MAP lower trip point
Lf679	fcb	$37	; ADC=55   MAP
Lf67a:	fcb	$d7	; ADC=215  Lower MAT ADC trip point - cooler than  -40
Lf67b	fcb	$1e	; ADC=30   Upper MAT ADC trip point - warmer than +284
Lf67c:	fcb	$d7	; ADC=215  Lower Coolant trip point - cooler than  -40
Lf67d:	fcb	$1f	; ADC=31	 Coolant trip point   warmer than +250
Lf67e:	fcb	$22	; ADC=34   Upper Coolant trip point - warmer than +220
Lf67f	fcb	$fd	; ADC=253  TPS too high trip point
Lf680:	fcb	$02	; ADC=02   TPS too Low trip point
;
; Battery error trip points (in ADC counts)......
;
Lf681:	fcb	$f3	; upper trip error   (243 * .0625 = 15.1875v)
Lf682:	fcb	$c8	; off idle low trip  (200 * .0625 = 12.5v)
Lf683:	fcb	$b3	; at idle low trip   (179 * .0625 = 11.1875v)
;

	if	not no_fills
f684:	fcb	$01
	endif

Lf685:	fcb	$8c	; 140	COOL threshold for TABMIN offset app.

	if	not no_fills
f686:	fdb	$ffff
f688:	fcb	$00
f689:	fcb	$00
f68a:	fcb	$00
f68b:	fcb	$00
f68c:	fcb	$00
f68d:	fcb	$00
f68e:	fcb	$01
f68f:	fcb	$01
	endif

Lf690:	fcb	$ff		; If this flag zero then the second IAC motor
;				;  driver is turned on (not used here)
;				; 09/01/99 - This second driver looks to be
;				;	     some kind of Boost Control    (WS)

	if	not no_fills
f591:	fdb	$9030
f693:	fcb	$10
f694:	fdb	$bb30
	fcb	$04
f697:	fdb	$e2ff
f699:	fill	$FF,$0067
	endif
;
Lf700:	fcb	4-1	; number-1 of Load cells in Fuel Modifier table
Lf701:	fcb	6-1	; number-1 of RPM cells in Fuel Modifier table
Lf702:	fcb	3-1	; number-1 of Load cells in Spark Modifier table
Lf703:	fcb	6-1	; number-1 of RPM cells in Spark Modifier table
; ----------------------------------------------------------------------------
; Max value for Fuel Modifier (calstar)
Lf704:	fcb	$40	; 64 - max count deviation used by modifiers - 50%
; ----------------------------------------------------------------------------
Lf705:	fcb	$40	; 64 -	Max Spark change allowed - 16 deg
; -----------------------------------------------------------------------------
; The following two tables are the index lookups for the User Fuel Modifiers
;  starting at L0091.
;
; This table is indexed by 'Load'....
;---------------------------------------------
; CALSTAR MODIFIER
; (16 bit val's, 4 LINES)
;
; TBDICT  (Fuel overlay table)
; TABLE OF DENSITY BREAKPOINTS (1/1024mm/Deg K/bit)
;---------------------------------------------
Lf706:	fdb	$03b4	;  948	- 18.0"
	fdb	$05bc	; 1468	- 12.0"
	fdb	$07c5	; 1989	-  6.0"
	fdb	$094b	; 2379	-  1.5" (WOT)
;
; ----------------------------------------------------------------------------
; This table is indexed by RPM.....
;---------------------------------------------
; TBTICT  (For Injection Correction Table)
; TABLE OF RPM BREAKPOINTS
;
; (16 bit val's, 6 LINES)
;
; Tbl = usec/8
;---------------------------------------------
;
Lf70e:	fdb	$010c	;  268	- 7000 rpm
	fdb	$0177	;  375	- 5000 rpm
	fdb	$01d5	;  469	- 4000 rpm
	fdb	$0271	;  625	- 3000 rpm
	fdb	$03aa	;  938	- 2000 rpm
	fdb	$0753	; 1875	- 1000 rpm
;
; -----------------------------------------------------------------------------
; The following two tables are the index lookups for the User Spark Modifiers
; starting at L0098.
;
; This spark calculation table is index by air charge (Load) value
;  The vacuum is what the controller would display as VAC:
;  Displayed_Vacuum(in) = 28.9 - ( X * .01152)
;---------------------------------------------
; TBDACT, (Spark Correction Table)
; TABLE OF DENSITY BREAKPOINTS
;
; 3 LINES, 16 bite val's)
;
; 1/1024mm/Deg k/bit
;---------------------------------------------
;
Lf71a:	fdb	$03b4	;  948	- 18.0"
	fdb	$06c1	; 1729	-  9.0"
	fdb	$094b	; 2379	-  1.5"  (WOT)
;
; This index list is indexed by rpm (timing period).
;---------------------------------------------
;  TBTACT  (Spark overlay table)
;  TABLE OF RPM BREAKPOINTS
;  CAL STAR MODIFIER
;
; (6 LINES, 16 bit values)
;
; TBL VALUE = usec/8
;	    = 1,875,000/RPM
;---------------------------------------------
;
Lf720:	fdb	$0138	;  312 - 6010 rpm
	fdb	$01a1	;  417 - 4500 rpm
	fdb	$0218	;  536 - 3500 rpm
	fdb	$02ee	;  750 - 2500 rpm
	fdb	$042f	; 1071 - 1750 rpm
	fdb	$0753	; 1875 - 1000 rpm
;
; -----------------------------------------------------------------------------
	if	not no_fills
	fill	$FF,$0014
	endif
; -----------------------------------------------------------------------------
; This table defines the Base Dataset.........
; The below gets transfered to L0080 if the EEPROM at B600 does not checksum
;
Lf740:	fcb	128		; - Fuel @ WOT @ 1000 RPM	+50% / -30%
	fcb	128		; - Fuel @ WOT @ 2000 RPM
	fcb	128		; - Fuel @ WOT @ 3000 RPM
	fcb	128		; - Fuel @ WOT @ 4000 RPM
	fcb	128		; - Fuel @ WOT @ 5000 RPM
	fcb	128		; - Fuel @ WOT @ 7000 RPM
;
	fcb	128		; - Fuel @ 06" @ 1000 RPM
	fcb	128		; - Fuel @ 06" @ 2000 RPM
	fcb	128		; - Fuel @ 06" @ 3000 RPM
	fcb	128		; - Fuel @ 06" @ 4000 RPM
	fcb	128		; - Fuel @ 06" @ 5000 RPM
	fcb	128		; - Fuel @ 06" @ 7000 RPM
;
	fcb	128		; - Fuel @ 12" @ 1000 RPM
	fcb	128		; - Fuel @ 12" @ 2000 RPM
	fcb	128		; - Fuel @ 12" @ 3000 RPM
	fcb	128		; - Fuel @ 12" @ 4000 RPM
	fcb	128		; - Fuel @ 12" @ 5000 RPM
	fcb	128		; - Fuel @ 12" @ 7000 RPM
;
	fcb	128		; - Fuel @ 18" @ 1000 RPM
	fcb	128		; - Fuel @ 18" @ 2000 RPM
	fcb	128		; - Fuel @ 18" @ 3000 RPM
	fcb	128		; - Fuel @ 18" @ 4000 RPM
	fcb	128		; - Fuel @ 18" @ 5000 RPM
	fcb	128		; - Fuel @ 18" @ 7000 RPM
;
	fcb	128		; - Sprk @ WOT @ 1000 RPM    +8 / -16 degrees
	fcb	128		; - Sprk @ WOT @ 1750 RPM
	fcb	128		; - Sprk @ WOT @ 2500 RPM
	fcb	128		; - Sprk @ WOT @ 3500 RPM
	fcb	128		; - Sprk @ WOT @ 4500 RPM
	fcb	128		; - Sprk @ WOT @ 6000 RPM
;
	fcb	128		; - Sprk @ 09" @ 1000 RPM
	fcb	128		; - Sprk @ 09" @ 1750 RPM
	fcb	128		; - Sprk @ 09" @ 2500 RPM
	fcb	128		; - Sprk @ 09" @ 3500 RPM
	fcb	128		; - Sprk @ 09" @ 4500 RPM
	fcb	128		; - Sprk @ 09" @ 6000 RPM
;
	fcb	128		; - Sprk @ 18" @ 1000 RPM
	fcb	128		; - Sprk @ 18" @ 1750 RPM
	fcb	128		; - Sprk @ 18" @ 2500 RPM
	fcb	128		; - Sprk @ 18" @ 3500 RPM
	fcb	128		; - Sprk @ 18" @ 4500 RPM
	fcb	128		; - Sprk @ 18" @ 6000 RPM
;
	fcb	128		; Global Fuel Modifier	+50% / -30%
	fcb	128		; Idle Fuel Modifier	+50% / -50%
	fcb	128		; Cold Start Fuel	+50% / -30%
	fcb	128		; Transient Fuel	+50% / -30%
	fcb	128		; Global Spark		+8 / -16 degrees
	fcb	128		; Idle Sprk modifier
f770	fcb	134		; Target Idle RPM (25 rpm stepsize)
f771	fcb	128		; Idle Speed Activity
f772	fcb	28		; Rev Limiter (250 rpm stepsize)
				;  initially set to 7000 rpm
f773	fcb	%01000000	; flags
;				 1xxxxxxx - Base Timing Set: On
;				 0xxxxxxx - Base Timing Set: Off
;				 x1xxxxxx - Closed Loop Fuel: Off
;				 x0xxxxxx - Closed Loop Fuel: On
;				 xx1xxxxx - Idle Control: Off
;				 xx0xxxxx - Idle Control: On
f774	fcb	00		; spares ???
f775	fcb	00		; spares ???
;
; -------------------- End of Base Dataset ------------------------------------

	if	not no_fills
f776:	fill	$FF,$078a
ff00:	fdb	$0000
ff02:	fcb	$00
ff03:	fcb	$7f
	fdb	$0080
ff06:	fcb	$00
ff07:	fdb	$b620
	fcb	$00
ff0a:	fcb	$00
ff0b:	fcb	$00
ff0c:	fcb	$00
ff0d:	fcb	$00
ff0e:	fcb	$00
ff0f:	fcb	$00
ff10:	fcb	$10
ff11:	fdb	$2b28
ff13:	fcb	$00
ff14:	fcb	$00
ff15:	fcb	$00
ff16:	fdb	$8000
ff18:	fdb	$f000
	fcb	$f0
ff1b:	fcb	$08
ff1c:	fcb	$00
ff1d:	fcb	$00
ff1e:	fcb	$00
ff1f:	fcb	$00
	endif
;
; -----------------------------------------------------------------------------
; The group of tables determine the phase of the injectors firing.
;
;
;			  +----------------> list delimiter
;			  |+++-------------> firing sequencer patern match
;			  ||||
;			  |||| +-----------> not used
;			  |||| |+++--------> what injector pair to fire
;			  |||| ||||
;			  |||| ||||	L0044	  Injectors	RPM range
Lff20:	fcb	$80	; 1000 0000	0 - #2	   0 - #1,8    ~3700 and up
	fcb	$66	; 0110 0110	6 - #5	   6 - #7,2
	fcb	$22	; 0010 0010	2 - #8	   2 - #4,3
	fcb	$44	; 0100 0100	4 - #3	   4 - #6,5

	fcb	$90	; 1001 0000	1 - #1	   0 - #1,8    ~2200 to ~3700
	fcb	$76	; 0111 0110	7 - #7	   6 - #7,2
	fcb	$32	; 0011 0010	3 - #4	   2 - #4,3
	fcb	$54	; 0101 0100	5 - #6	   4 - #6,5

	fcb	$a0	; 1010 0000	2 - #8	   0 - #1,8    ~1600 to ~2200
	fcb	$06	; 0000 0110	0 - #2	   6 - #7,2
	fcb	$42	; 0100 0010	4 - #3	   2 - #4,3
	fcb	$64	; 0110 0100	6 - #5	   4 - #6,5

	fcb	$b0	; 1011 0000	3 - #4	   0 - #1,8    ~1600 and down
	fcb	$16	; 0001 0110	1 - #1	   6 - #7,2
	fcb	$52	; 0101 0010	5 - #6	   2 - #4,3
	fcb	$74	; 0111 0100	7 - #7	   4 - #6,5

	fcb	$c0	; 1100 0000	4 - #3	   0 - #1,8
	fcb	$26	; 0010 0110	2 - #8	   6 - #7,2
	fcb	$62	; 0110 0010	6 - #5	   2 - #4,3
	fcb	$04	; 0000 0100	0 - #2	   4 - #6,5

ff34	fcb	$d0	; 1101 0000	5 - #6	   0 - #1,8
	fcb	$36	; 0011 0110	3 - #4	   6 - #7,2
	fcb	$72	; 0111 0010	7 - #7	   2 - #4,3
Lff37:	fcb	$14	; 0001 0100	1 - #1	   4 - #6,5
;
; ----------------------------------------------------------------------------
; The following three addresses point to the MSB of the 6840 timer registers.
;  The last one is our internal timer driving INJ-D
;
Lff38:	fdb	timer_1_msb	; 6840 Timer #1 data register MSB	1 8
	fdb	timer_2_msb	;	 Timer #2			4 3
	fdb	timer_3_msb	;	   Timer #3			6 5
	fdb	toc2_data_reg	; OC4					7 2
;
; This table is part of the injector firing order sequencing.
;
Lff40:	fcb	$fb	; 11111011	#2
	fcb	$ff	; 11111111	#1
	fcb	$f7	; 11110111	#8
	fcb	$ff	; 11111111	#4
	fcb	$fd	; 11111101	#3
	fcb	$ff	; 11111111	#6
	fcb	$fe	; 11111110	#5
	fcb	$ff	; 11111111	#7
;
ff48:	fcb	$ff
ff49:	fcb	$ff

Lff4a:	fcb	01	; 00000001	1,8 injector pair
	fcb	04	; 00000100	4,3
	fcb	08	; 00001000	6,5
	fcb	02	; 00000010	7,2

	fcb	02	; 00000010
	fcb	06	; 00000110
	fcb	00	; 00000000
	fcb	04	; 00000100
; -----------------------------------------------------------------------------
; This is the Target Idle RPM look up table.  It's output is in timing_period/16
;  units (same as L0061 and L0042).
;
Lff52:	fcb	$f6	;  476 rpm
	fcb	$ea	;  501 rpm
	fcb	$df	;  526 rpm
	fcb	$d5	;  550 rpm
	fcb	$cc	;  574 rpm
	fcb	$c3	;  601 rpm
	fcb	$bc	;  623 rpm
	fcb	$b4	;  651 tpm
	fcb	$ae	;  673 rpm
	fcb	$a7	;  702 rpm
	fcb	$a2	;  723 rpm
	fcb	$9c	;  751 rpm
	fcb	$97	;  776 rpm
	fcb	$92	;  803 rpm <-- warm engine with L00b0 modifier zero(128)
	fcb	$8e	;  825 rpm
	fcb	$8a	;  849 rpm
	fcb	$86	;  875 rpm
	fcb	$82	;  901 rpm
	fcb	$7f	;  923 rpm
	fcb	$7b	;  953 rpm <-- warm engine with L00b0 mod +6 (134)
	fcb	$78	;  977 rpm
	fcb	$75	; 1002 rpm
	fcb	$72	; 1028 rpm
	fcb	$70	; 1046 rpm
	fcb	$6d	; 1075 rpm
	fcb	$6b	; 1095 rpm
	fcb	$68	; 1127 rpm
	fcb	$66	; 1149 rpm
	fcb	$64	; 1172 rpm
	fcb	$62	; 1196 rpm
	fcb	$60	; 1221 rpm
	fcb	$5e	; 1247 rpm
	fcb	$5c	; 1274 rpm
	fcb	$5a	; 1302 rpm
	fcb	$58	; 1332 rpm
	fcb	$57	; 1347 rpm
	fcb	$55	; 1379 rpm
	fcb	$54	; 1395 rpm
	fcb	$52	; 1429 rpm
	fcb	$51	; 1447 rpm
	fcb	$4f	; 1483 rpm
	fcb	$4e	; 1502 rpm
	fcb	$4d	; 1522 rpm
	fcb	$4c	; 1542 rpm
	fcb	$4a	; 1584 rpm
	fcb	$49	; 1605 rpm
;
; -----------------------------------------------------------------------------
; RPM look-up table for the rev limiter.  These values are timing periods
; RPM = 1,875,000 / timing_period
;
Lff80:	fdb	$0177	; 375	1,875,000 / 375 = 5000 RPM
	fdb	$0165	; 357	5,252
	fdb	$0155	; 341	5,499
	fdb	$0146	; 326	5,752
	fdb	$0138	; 312	6,010
	fdb	$012c	; 300	6,250
	fdb	$0120	; 288	6,510
	fdb	$0116	; 278	6,745
	fdb	$010c	; 268	6,996
	fdb	$0103	; 259	7,239
	fdb	$00fa	; 250	7,500
	fdb	$00f2	; 242	7,748
	fdb	$00ea	; 234	8,013
	fdb	$00e3	; 227	8,641
	fdb	$00dd	; 221	8,787
	fdb	$00d6	; 214	8,762
	fdb	$00d0	; 208	9,014
	fdb	$00cb	; 203	9,236
	fdb	$00c5	; 197	9,518
	fdb	$00c0	; 192	9,766
	fdb	$00bc	; 188	9,973
;
	if	not no_fills
ffaa:	fill	$FF,$0016
	endif
;
; -----------------------------------------------------------------------------
; Start of Interrupt Vectors
;
	org	$ffc0
;
	fill	$ff,$16 	; reserved area
	fdb	Ldc9d		; SCI Serial System
	fdb	L8010		; SPI Serial System
	fdb	L8010		; Pulse Accumulator Input Edge
	fdb	L8010		; Pulse Accumulator Overflow
	fdb	L9513		; Timer Overflow
	fdb	L8010		; Timer Input Capture 4 / Output Compare 5
	fdb	L9652		; Timer Output Compare 4 - Ign Amp Driver - SA
	fdb	L9721		; Timer Output Compare 3 - EEPROM timer
	fdb	L9730		; Timer Output Compare 2 - INJ D
	fdb	L9740		; Timer Output Compare 1 - Idle Air Motor
	fdb	L8010		; Timer Input Capture 3
	fdb	L8010		; Timer Input Capture 2
	fdb	L8ca9		; Timer Input Capture 1  - Distributor Trigger
	fdb	L8010		; Real-Time Interrupt
	fdb	L8010		; IRQ (external pin)
	fdb	L8010		; XIRQ pin
	fdb	L8010		; Software Interrupt
	fdb	L8010		; Illegal Opcode Trap
	fdb	L8010		; COP Failure
	fdb	L8010		; Clock Monitor Fail
	fdb	L8010		; power on RESET vector
;
	end