Advertisement
dgallagher

standard_E932_E931_source

Sep 2nd, 2017
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 975.72 KB | None | 0 0
  1. ;****************************************************************************************************
  2. ;* GENERAL NOTES
  3. ;* =============
  4. ;* Project started with the help of dsm-ecu Yahoo group, thanks for the great info.
  5. ;* Most disassembly comments in this file by Christian, christi999@hotmail.com.
  6. ;*
  7. ;* CPU
  8. ;* ----
  9. ;* The microcomputer chip used in the 1G DSM ECU seems to be a custom application
  10. ;* built around the 6801 architecture, Check the 6801, 6803, 6301, 68HC11 at web sites
  11. ;* such as alldatasheet.com, etc.
  12. ;*
  13. ;* CPU clock frequency is assumed to be 2MHz, i.e. the instructions cycle time is 0.5us.
  14. ;*
  15. ;* Assembly binary verifications:
  16. ;* ------------------------------
  17. ;*
  18. ;* The 2 binaries produced without any customization ("enableCustom" definition is
  19. ;* commented-out) have been verified to be identical to the E931 and E932 eprom
  20. ;* images at hand.
  21. ;*
  22. ;* To check the validity of symbolic substitution, the entire code section and tables
  23. ;* was offset by $0200 using "codeOffset" and the corresponding binary was tested on
  24. ;* my car (E932) without any problems for weeks. Additional tests were conducted by
  25. ;* writing inline code in several part of the code and no adverse effect was ever noted.
  26. ;*
  27. ;* To check the validity of symbolic substitution for ram addresses, every ram location
  28. ;* starting at $0057 was offset by 1 (i.e. temp1 was at memory address $58 instead of
  29. ;* $57, etc) and the corresponding binary was tested on my car (E932) without any problems
  30. ;* during car startup and engine revving. No additional test performed.
  31. ;*
  32. ;* This means that the code can be modified inline and in most cases, ram memories can
  33. ;* be moved around by changing the label addresses. Note however that some groups of
  34. ;* ram memories have to be moved in blocks because the code assumes they are contiguous.
  35. ;* e.g. the temp1 to temp9 variables, the inj1_offT, inj3_offT, inj4_offT and inj2_offT
  36. ;* variables, etc.
  37. ;*
  38. ;* Ram memory:
  39. ;* -----------
  40. ;* Memory from $0040 to $01bf is backed-up by battery, meaning it is preserved when the
  41. ;* ECU is powered-off as long as battery power is supplied. However, memory from $0057 to
  42. ;* $0190 is cleared to 0 by the code every time the ECU is powered-on. That can be however
  43. ;* changed by modifying the code... Battery backup was checked by disabling memory reset using
  44. ;* the "noRamReset" and then check ram memory at $018f to see if it gets preserved after power
  45. ;* off/on cycle, and it did. During the test, $018f was used as a distance counter using
  46. ;* the reed switch.
  47. ;*
  48. ;* Comments:
  49. ;* --------
  50. ;* Some comments use variable names quite loosly. For instance, multi-byte variables
  51. ;* such as [airCnt0:airCnt1:airCnt2] might be refered to as only airCnt0. airCnt0
  52. ;* might therefore refer to the single byte airCnt0, to the 16 bit value
  53. ;* [airCnt0:airCnt1] or to the 24 bit complete variable, depending on the context.
  54. ;*
  55. ;* Comments were added incrementally as my knowledge of code and variables
  56. ;* increased. As new knowledge was learned, old comments were updated or corrected
  57. ;* as much as possible but not necessarily all of them, so beware... In the end, the
  58. ;* code is the only truth... Some small areas of the code were also never completly
  59. ;* understood as a general understanding was reached and I did not care to go further
  60. ;* e.g. airflow sensor active filter reset
  61. ;*
  62. ;* Opcodes:
  63. ;* --------
  64. ;* -cmpd: cmpd1 is used for some addressing modes instead of cmpd since
  65. ;* TASM does not support unusual mitsubishi ECU cmpd opcodes..
  66. ;*
  67. ;* -brclr: branch if ALL the given bits are clear
  68. ;*
  69. ;* -brset: branch if ANY of the given bits are set (as opposed to usual
  70. ;* implementation of ALL bits set...)
  71. ;*
  72. ;* -The addressing mode using Y indexing also implicitly
  73. ;* modifies the y register. It seems that y is increased
  74. ;* by 1 or 2 depending whether the instruction is a 8 bit
  75. ;* or 16 bits operation... The following cases are confirmed
  76. ;*
  77. ;* cmpa $00,y -> y = y + 1
  78. ;* cmpb $00,y -> y = y + 1
  79. ;* ldaa $00,y -> y = y + 1
  80. ;* suba $00,y -> y = y + 1
  81. ;* ldx $00,y -> y = y + 2
  82. ;* std $00,y -> y = y + 2
  83. ;*
  84. ;*
  85. ;* Telemark assembler:
  86. ;* --------------------
  87. ;* This assembler does not provide warning messages when code assembles to
  88. ;* the same memory space, e.g. you insert code in the middle of the file
  89. ;* which result in the rest of the code to be offset by N bytes. This
  90. ;* results in the interrupt vector table to be overwritten. No warning
  91. ;* is given. The only way to know about it is to manually check the listing
  92. ;* file produced by the assembler. Check that the buffer space between
  93. ;* sections is all "$ff". Check that there is no code spilage over .org
  94. ;* statements. Check that the address space does not exceed $ffff. Use the
  95. ;* "codeOffset" at the beginnng of the file to correct the problem.
  96. ;*
  97. ;*
  98. ;* Fuel injector and coil power transistor control
  99. ;* ------------------------------------------------
  100. ;* Although the 4 fuel injectors and the 2 coil power transistors are mapped to
  101. ;* regular ports (port1, port2 and port5) which can be read to know the current
  102. ;* state of these outputs, they are also mapped in hardware to output compare
  103. ;* registers in order to activate or deactivate them at specific time instants.
  104. ;* Writing to the ports might therefore not work unless the output compare
  105. ;* configuration registers are changed to disable harware control of these
  106. ;* outputs. This might not be possible unless an "output enable" bit exists,
  107. ;* which I haven't found at this point...
  108. ;* Another way to activate or deactivate them would be to use the output
  109. ;* compare registers (as currently done by the ECU code) and provoke an
  110. ;* immediat output change.
  111. ;*
  112. ;* Here is my current understanding of how injector scheduling works, not
  113. ;* everything is clear to me so don't take this as gospel...:
  114. ;* The output compare registers for the fuel injectors seem to be at least double
  115. ;* buffered and maybe triple buffered (see schedInjSim routine). That means that
  116. ;* up to 3 different output compare values can be written to t1_outCmpWr and t2_outCmpWr
  117. ;* to activate or deactivate the injectors at those time instants. Each time a value
  118. ;* is written to t1_outCmpWr or t2_outCmpWr, the corresponding injector state
  119. ;* is also internally stored. That means that to activate injector #1 at time X,
  120. ;* you would first reset bit 0 of t1_csr, corresponding to injector #1 and then
  121. ;* write X to t1_outCmpWr. You could then immediately schedule the deactivation
  122. ;* of injector #1 by setting bit 0 of t1_csr to 1 and then write the deactivation
  123. ;* time to t1_outCmpWr. When one of the output compare register stored value matches
  124. ;* the clock at t1t2_clk, the injector is activated/deactivated and the corresponding
  125. ;* interrupt routine is called (if the interrupt mask is clear...) at outCompInt1 or
  126. ;* outCompInt2.
  127. ;*
  128. ;* Here is my current understanding of how the coil power transistor scheduling
  129. ;* works, not everything is clear to me so don't take this as gospel...: t3_outCmpWr
  130. ;* is the output compare register used to activate or deactivate the coil power
  131. ;* transistors (energize the coil and provoke ignition at the specified time instants)
  132. ;* To energize the coil for cylinder 1 and 4 at time X you would write X to t3_outCmpWr
  133. ;* and reset(0) bit 2 of t3_csr0. At time X, t3_csr0.2 would be loaded into port5.1
  134. ;* which would energize the coil. t3_csr0.2 should not be changed until that happens.
  135. ;* In the code, most of the time 2 successive values (the same one) are written to t3_outCmpWr
  136. ;* but there are some instances where only 1 value is written. My impression is that
  137. ;* the first value serves to activate/deactivate the coil power transistor at the
  138. ;* specified instant while the second one only serves to generate an interrupt
  139. ;* in order to call the outCompInt3 routine. Hence when only the coil need
  140. ;* to be activated/deactivated without calling outCompInt3, you would only write
  141. ;* one value. If in addition you want to have outCompInt3 called when the coil
  142. ;* is energized/ignited, you would write two successive values (corresponding to the
  143. ;* same time...). This is all speculation of course... As for the 2 clocks at t3_clock1
  144. ;* and t3_clock1, I assume they are connected to the same internal clock at 250KHz
  145. ;* but might be input capture registers latched when one of the two output compare
  146. ;* at t3_outCmpWr is triggered??????? Again speculation, this is the part of the code
  147. ;* I understand the least...
  148. ;*
  149. ;*
  150. ;* Timing diagram
  151. ;* --------------
  152. ;*
  153. ;* -4 cylinders = 2 rotations = 2 * 360degrees = 720 degrees
  154. ;*
  155. ;* -For sequential injection, fuel injection starts on the cas falling edge
  156. ;* i.e. cylinder #1 injection starts at -5 BTDC of #3 TDC
  157. ;*
  158. ;* -Simultaneous injection of all 4 injectors is performed when starting to
  159. ;* crank or starting a cold engine or during acceleration, check the tech manual
  160. ;* and code for more details. Simultaneous injection starts on the 5deg BTDC
  161. ;* cas signal except in the case of acceleration where it starts when an
  162. ;* injector is deactivated and no other injector is active (i.e. at the
  163. ;* beginning of the time period where no injector is active)
  164. ;*
  165. ;* -Coil energization is usually scheduled (the energization time is loaded into
  166. ;* the output compare register, energization will occur at the specified time)
  167. ;* from the cas rising edge. Coil ignition can be scheduled when energization
  168. ;* occurs (output compare interrupt) or on the cas falling edge depending on
  169. ;* the desired timing. Note however that coil energization can also be scheduled
  170. ;* when ignition occurs on the preceeding cylinder. This would correspond to
  171. ;* scheduling ignition before the cas rising edge (at high rpm I assume). Coil
  172. ;* energization can also be scheduled on the cas falling edge when the desired
  173. ;* timing is high (e.g. 10deg ATDC). As this shows, there are several combinations
  174. ;* and the complexity of the code to handle the coil reflects that fact.
  175. ;*
  176. ;*
  177. ;* No 1 TDC No 3 TDC No 4 TDC No 2 TDC
  178. ;* : : : :
  179. ;* ___________ _____
  180. ;* TDC sensor | | | |
  181. ;* signal | : | : | | : :
  182. ;* ____|___________|_______________________|_____|________________________
  183. ;* degrees 85 55 85 15
  184. ;* (BTDC/ATDC) : : : :
  185. ;* ______ ______ ______ ______
  186. ;* CAS sensor | | | | | | | |
  187. ;* signal | | : | | : | | : | | :
  188. ;* _____|______|__________|______|__________|______|__________|______|____
  189. ;* degrees 75 5 : 75 5 : 75 5 : 75 5 :
  190. ;* (BTDC) : : : :
  191. ;*
  192. ;* : : : :
  193. ;* No 1 cyl. compression : combustion : exhaust : intake : compression
  194. ;* No 3 cyl. intake : compression : combustion : exhaust : intake
  195. ;* No 4 cyl. exhaust : intake : compression : combustion : exhaust
  196. ;* No 2 cyl. combustion : exhaust : intake : compression : combustion
  197. ;*
  198. ;*
  199. ;*
  200. ;* Airflow calculations dependencies, more details in code
  201. ;* --------------------------------------------------------
  202. ;*
  203. ;* masProc: airflow sensor interrupt, increases [airCntNew0:airCntNew1]
  204. ;* | by airQuantum for every airflow sensor pulse received
  205. ;* |
  206. ;* |
  207. ;* |
  208. ;* |--> [airCntNew0:airCntNew1]: Increased by airQuantum for every airflow sensor pulse
  209. ;* | Reset and used as input to [airCnt0:airCnt1:airCnt2]
  210. ;* | on every cas falling edge, i.e. air is counted twice
  211. ;* | per rotation, once for every cylinder cycle... It can
  212. ;* | therefore be seen as the air count per cylinder.
  213. ;* |
  214. ;* |--> [airCnt0:airCnt1:airCnt2]: Filtered version of 256*[airCntNew0:airCntNew1]
  215. ;* | exponential averaging is used.
  216. ;* |
  217. ;* |
  218. ;* |
  219. ;* |--> mafraw16: 16 bit airflow sensor pulse frequency (mafraw16/10.24)Hz
  220. ;* | | mafraw16 = 8205*[airCnt0:airCnt1]/Tcas
  221. ;* | |
  222. ;* | |
  223. ;* | |--> mafraw: 8 bit airflow sensor pulse frequency (6.25*mafraw)Hz
  224. ;* | mafraw: = mafraw16/64
  225. ;* |
  226. ;* |
  227. ;* |
  228. ;* |--> airVol16: Equals [airCnt0:airCnt1] * masScalar/65536
  229. ;* | |
  230. ;* | |
  231. ;* | |
  232. ;* | |--> airVol : Equals airVol16/2
  233. ;* | |--> airVolT : Equals airVol16/2 * iatCompFact/128
  234. ;* | |--> airVolTB : Equals airVol16/2 * iatCompFact/128 * baroFact/128
  235. ;* | |--> airVolB : Equals airVol16/2 * baroFact/128
  236. ;* |
  237. ;* |
  238. ;* |--> injPw: Injector pulse width in "normal" operation,
  239. ;* injPw = [airCnt0:airCnt1] * injFactor/256 + other corrections
  240. ;*
  241. ;*
  242. ;*
  243. ;* Discussion on MAS compensation factors
  244. ;* ---------------------------------------
  245. ;*
  246. ;* Total airflow sensor compensation is made-up of:
  247. ;*
  248. ;* totMasComp(freq,iat,baro) = masComp + t_masComp(freq) + t_masLin(freq,iat,baro)
  249. ;*
  250. ;* where maxComp is a fixed offset ($64 for 1G and $40 for 2G) and t_masComp and t_masLin
  251. ;* are table values interpolated from frequency, intake air temperature and barometric
  252. ;* pressure. t_masComp(freq) is basically compensation for the airflow sensor charcteristic
  253. ;* curve as a function of frequency (to linearize the number of pulse per sec vs. the volume
  254. ;* of air passing through the sensor) while t_masLin(freq,iat,baro) is a smaller factor
  255. ;* probably compensating for temperature drift (electronic) and airflow characteristic
  256. ;* change as a function of air density???
  257. ;*
  258. ;* Assuming the following:
  259. ;*
  260. ;* -injComp = 100% (for 260cc injectors at 36psi)
  261. ;* -workFtrim = 100%
  262. ;* -o2FuelAdj = 100%
  263. ;* -iatCompFact = 100% (at 25.6degC)
  264. ;* -baroFact = 100% (~1 bar)
  265. ;* -openLoopEnr = 100%
  266. ;* -coldTempEnr = 100%
  267. ;* -enrWarmup = 0%
  268. ;*
  269. ;*
  270. ;* Then the injector pulswidth is calculated by the ECU as (excluding deadtime)
  271. ;*
  272. ;* injPw(usec/cylinder) = numPulsePerCasInterrupts *$9c * totMasComp * 16/256
  273. ;* = numPulsePerCasInterrupts * totMasComp * 9.75
  274. ;*
  275. ;* If we also assume a 14.7 air to fuel ratio, Dair=1.18 air density (g/litre) at 25degC,
  276. ;* Dgas=0.775 fuel density (g/cc) then we would need 23900 usec of injection per
  277. ;* litre of air using the same 260cc at 36psi, working that factor into the equation, we
  278. ;* get
  279. ;*
  280. ;* injPw(usec/cylinder) = numPulsePerCasInterrupts * totMasComp * 9.75
  281. ;* = numPulsePerCasInterrupts * totMasComp/2452 * 2452 * 9.75
  282. ;* = numPulsePerCasInterrupts * totMasComp/2452 * 23900usecOfInjection/litreOfAir
  283. ;*
  284. ;* This means that under the above assumptions, totMasComp/2452 has units of
  285. ;* litreOfAirPerAirflowSensorPulse.
  286. ;*
  287. ;* The factor 2452 is similar to the one provided by J. Oberholtzer, I think.
  288. ;* The exact value must be somewhere in that range...
  289. ;*
  290. ;* masScalar is also used for maf compensation ($5e86,24198 for 1G, $7A03,31235 for 2g)
  291. ;* for controls other than fuel injection. It probably correspond to some metric of
  292. ;* the totMasComp curve (average or max under given conditions). From 1G and 2G numbers,
  293. ;* It could correspond to the max of the masComp + t_masComp(freq) curve multiplied
  294. ;* by 0.808*128? It could also correspond to the masComp + t_masComp(freq) curve
  295. ;* sampled at around 69Hz and multiplied by 128.
  296. ;*
  297. ;* masScalar = maxTotMasComp*0.808*128 = totMasComp(69Hz)*128
  298. ;*
  299. ;* We then have in the case of masScalar = maxTotMasComp*0.808*128:
  300. ;*
  301. ;* airVol16 = numPulsePerCasInterrupts * $9c * masScalar / 65536
  302. ;* = numPulsePerCasInterrupts * $9c * maxTotMasComp*0.808*128 / 65536
  303. ;* = numPulsePerCasInterrupts * maxTotMasComp * 0.2462
  304. ;* = numPulsePerCasInterrupts * maxTotMasComp/2452 * 2452*0.2462
  305. ;* = numPulsePerCasInterrupts * maxTotMasComp/2452 * 603.68
  306. ;*
  307. ;* since totMasComp/2452 is litreOfAirPerAirflowSensorPulse, we have
  308. ;*
  309. ;* airVol16 = numPulsePerCasInterrupts * litreOfAirPerAirflowSensorPulse * 603.68
  310. ;*
  311. ;* Using again 1.18g/litre air density we get
  312. ;*
  313. ;* airVol16 = numPulsePerCasInterrupts * litreOfAirPerAirflowSensorPulse *1.18 * 603.68/1.18
  314. ;* = numPulsePerCasInterrupts * gramsOfAirPerAirflowSensorPulse * 512
  315. ;* = gramsOfAirPerCasInterrupts * 512
  316. ;*
  317. ;* In that case, airVol16/512 can be seen has having units of gramsOfAirPerCasInterrupts
  318. ;* (grams of air entering one cylinder). Note that the factor of 512 is not random, the
  319. ;* factor 0.808 is used to get it in that case...
  320. ;*
  321. ;* The load index values used to interpolate the fuel map is then
  322. ;*
  323. ;* airVol16/2 <= 96
  324. ;*
  325. ;* loadIndex = (airVol16/2-32)/16
  326. ;* = (gramsOfAirPerCasInterrupts*512/2 -32)/16
  327. ;* = gramsOfAirPerCasInterrupts*16-2
  328. ;*
  329. ;* airVol16/2 >= 96
  330. ;*
  331. ;* loadIndex = gramsOfAirPerCasInterrupts * 512/2 * 0.668/16
  332. ;* = gramsOfAirPerCasInterrupts*10.69
  333. ;*
  334. ;* Which correspond to (gramsOfAirPerCasInterrupts for each index value)
  335. ;*
  336. ;* 0 1 2 3 4 5 6 7 8 9 10 11
  337. ;* 0.125 0.1875 0.25 0.3125 0.3750 0.4678 0.5614 0.6549 0.7485 0.8421 0.9356 1.0292
  338. ;*
  339. ;* gramsOfAirPerRevolution would be twice those values. Notice that the max value of 1.0292
  340. ;* correspond to about 250HP when BSFC=0.55 which is in the range of the stock 1G 195HP...
  341. ;*
  342. ;* Also notice that the 8 bit airflow airVol = airVol16/2 will saturate to $ff when
  343. ;* airVol16/2 = 255 which correspond to gramsOfAirPerCasInterrupts = 1 gram. airVolT
  344. ;* airVolTB and airVolB will also saturate in the same range...
  345. ;*
  346. ;* We can now compare these results with the stock boost gauge. It has a max range
  347. ;* of 1Kg per sq cm which equals 14.2 psi. The boost gauge duty cycle is given by
  348. ;*
  349. ;* bGaugeODuty = t_bGauge(airVolT/32)/24
  350. ;*
  351. ;* When maximum airVolT = 255 = iatCompFact*airVol16/2, bGaugeODuty = 20/24 = 0.83.
  352. ;* At 25.6 degC, iatCompFact = 1.0 and therefore airVol16=510 which translates to
  353. ;* 1g of air. boost gauge duty of 0.83 correspond to approx. 10.9psi (by eye...).
  354. ;* Assuming a displacement of 0.5litre per cylinder and charge air density of 1.18
  355. ;* (25degC, probably too low for that psi range, unless you have a perfect intercooler..)
  356. ;* we would get 1.18*0.5*(10.9+14.5)/14.5 = 1.03g of air per cylinder (cas
  357. ;* interrupt). This is quite close to the 1.0g we had earlier.
  358. ;*
  359. ;* The 0psi point on the gauge correspond to a duty cycle of about 40.5% which
  360. ;* correspond to bGaugeODuty=9.75/24 which from t_bGauge correspond to
  361. ;* airVolT/32=2.875 which means airVolT = 92. with iatCompFact = 1.0 @25degC,
  362. ;* we get airVol16 = 2*airVolT/iatCompFact = 184 which correspond to 0.36grams of air
  363. ;* Assuming a displacement of 0.5litre per cylinder and charge air density of 1.18@25degC
  364. ;* we would get 1.18*0.5 = 0.59g of air per cylinder (cas interrupt) at 0psi. Compared to
  365. ;* 0.36g we had earlier this is a large error but then there are several factor not taken onto
  366. ;* account in the calculations, I suppose???.
  367. ;*
  368. ;*
  369. ;* Engine coolant and intake air temperature
  370. ;* ------------------------------------------
  371. ;*
  372. ;* Approximate sensor curves (temperature
  373. ;* against ADC value, taken from MMCD). The
  374. ;* control points in the service manual are
  375. ;* quite close (0 to 2 degC off).
  376. ;*
  377. ;*
  378. ;* ADC ECT IAT ADC ECT IAT ADC ECT IAT ADC ECT IAT
  379. ;* degC degC degC degC
  380. ;*
  381. ;* $00 158.0 184.0 $40 52.0 56.0 $80 21.0 23.0 $c0 -7.0 -7.0
  382. ;* $01 154.4 178.1 $41 51.3 55.3 $81 20.6 22.5 $c1 -7.5 -7.6
  383. ;* $02 150.9 172.5 $42 50.7 54.6 $82 20.2 22.1 $c2 -8.1 -8.2
  384. ;* $03 147.5 167.2 $43 50.1 53.9 $83 19.8 21.7 $c3 -8.6 -8.8
  385. ;* $04 144.2 162.0 $44 49.5 53.3 $84 19.4 21.2 $c4 -9.2 -9.4
  386. ;* $05 140.9 157.1 $45 48.9 52.6 $85 19.0 20.8 $c5 -9.8 -10.1
  387. ;* $06 137.7 152.4 $46 48.3 52.0 $86 18.7 20.4 $c6 -10.4 -10.7
  388. ;* $07 134.6 148.0 $47 47.7 51.3 $87 18.3 19.9 $c7 -10.9 -11.3
  389. ;* $08 131.6 143.7 $48 47.2 50.7 $88 17.9 19.5 $c8 -11.5 -12.0
  390. ;* $09 128.6 139.6 $49 46.6 50.1 $89 17.6 19.0 $c9 -12.1 -12.6
  391. ;* $0a 125.7 135.7 $4a 46.1 49.4 $8a 17.2 18.6 $ca -12.7 -13.2
  392. ;* $0b 122.9 132.0 $4b 45.6 48.8 $8b 16.9 18.2 $cb -13.2 -13.9
  393. ;* $0c 120.2 128.5 $4c 45.0 48.2 $8c 16.5 17.7 $cc -13.8 -14.5
  394. ;* $0d 117.5 125.1 $4d 44.5 47.7 $8d 16.1 17.3 $cd -14.3 -15.1
  395. ;* $0e 114.9 121.9 $4e 44.0 47.1 $8e 15.7 16.8 $ce -14.9 -15.7
  396. ;* $0f 112.4 118.8 $4f 43.5 46.5 $8f 15.3 16.4 $cf -15.4 -16.3
  397. ;* $10 110.0 116.0 $50 43.0 46.0 $90 15.0 16.0 $d0 -16.0 -17.0
  398. ;* $11 107.6 113.2 $51 42.4 45.4 $91 14.5 15.5 $d1 -16.5 -17.6
  399. ;* $12 105.3 110.6 $52 41.9 44.9 $92 14.1 15.1 $d2 -17.0 -18.2
  400. ;* $13 103.0 108.1 $53 41.4 44.3 $93 13.7 14.6 $d3 -17.5 -18.8
  401. ;* $14 100.8 105.8 $54 40.9 43.8 $94 13.3 14.2 $d4 -18.0 -19.4
  402. ;* $15 98.7 103.5 $55 40.4 43.3 $95 12.9 13.7 $d5 -18.6 -20.1
  403. ;* $16 96.7 101.4 $56 39.9 42.8 $96 12.4 13.3 $d6 -19.2 -20.8
  404. ;* $17 94.7 99.4 $57 39.3 42.3 $97 12.0 12.8 $d7 -19.8 -21.5
  405. ;* $18 92.8 97.5 $58 38.8 41.8 $98 11.5 12.4 $d8 -20.5 -22.3
  406. ;* $19 91.0 95.7 $59 38.3 41.4 $99 11.1 12.0 $d9 -21.3 -23.1
  407. ;* $1a 89.2 93.9 $5a 37.8 40.9 $9a 10.6 11.5 $da -22.1 -24.0
  408. ;* $1b 87.5 92.3 $5b 37.3 40.4 $9b 10.2 11.1 $db -23.0 -24.9
  409. ;* $1c 85.9 90.7 $5c 36.9 39.9 $9c 9.7 10.7 $dc -24.0 -26.0
  410. ;* $1d 84.3 89.2 $5d 36.4 39.4 $9d 9.3 10.2 $dd -25.0 -27.1
  411. ;* $1e 82.8 87.7 $5e 35.9 38.9 $9e 8.8 9.8 $de -26.2 -28.3
  412. ;* $1f 81.3 86.3 $5f 35.4 38.4 $9f 8.4 9.4 $df -27.5 -29.6
  413. ;* $20 80.0 85.0 $60 35.0 38.0 $a0 8.0 9.0 $e0 -29.0 -31.0
  414. ;* $21 78.6 83.6 $61 34.5 37.5 $a1 7.5 8.5 $e1 -30.5 -32.5
  415. ;* $22 77.4 82.4 $62 34.0 37.0 $a2 7.1 8.1 $e2 -32.2 -34.1
  416. ;* $23 76.2 81.1 $63 33.6 36.4 $a3 6.6 7.7 $e3 -33.9 -35.7
  417. ;* $24 75.0 79.9 $64 33.1 35.9 $a4 6.2 7.3 $e4 -35.8 -37.5
  418. ;* $25 73.9 78.8 $65 32.7 35.4 $a5 5.8 6.9 $e5 -37.7 -39.3
  419. ;* $26 72.9 77.7 $66 32.3 34.9 $a6 5.3 6.4 $e6 -39.7 -41.2
  420. ;* $27 71.9 76.6 $67 31.8 34.4 $a7 4.9 6.0 $e7 -41.7 -43.0
  421. ;* $28 70.9 75.5 $68 31.4 33.9 $a8 4.5 5.6 $e8 -43.7 -44.9
  422. ;* $29 69.9 74.5 $69 31.0 33.4 $a9 4.0 5.2 $e9 -45.8 -46.8
  423. ;* $2a 69.0 73.5 $6a 30.5 32.9 $aa 3.6 4.7 $ea -47.8 -48.7
  424. ;* $2b 68.1 72.5 $6b 30.1 32.4 $ab 3.2 4.3 $eb -49.8 -50.6
  425. ;* $2c 67.3 71.5 $6c 29.7 31.9 $ac 2.7 3.8 $ec -51.8 -52.4
  426. ;* $2d 66.4 70.6 $6d 29.3 31.4 $ad 2.3 3.4 $ed -53.7 -54.1
  427. ;* $2e 65.6 69.7 $6e 28.8 30.9 $ae 1.8 2.9 $ee -55.5 -55.8
  428. ;* $2f 64.8 68.8 $6f 28.4 30.4 $af 1.4 2.4 $ef -57.3 -57.4
  429. ;* $30 64.0 68.0 $70 28.0 30.0 $b0 1.0 2.0 $f0 -59.0 -59.0
  430. ;* $31 63.1 67.1 $71 27.5 29.5 $b1 0.5 1.5 $f1 -59.0 -59.0
  431. ;* $32 62.3 66.3 $72 27.1 29.0 $b2 0.0 0.9 $f2 -59.0 -59.0
  432. ;* $33 61.5 65.5 $73 26.6 28.6 $b3 -0.3 0.4 $f3 -59.0 -59.0
  433. ;* $34 60.7 64.7 $74 26.2 28.1 $b4 -0.8 -0.0 $f4 -59.0 -59.0
  434. ;* $35 59.9 63.9 $75 25.7 27.7 $b5 -1.3 -0.5 $f5 -59.0 -59.0
  435. ;* $36 59.2 63.1 $76 25.3 27.2 $b6 -1.8 -1.1 $f6 -59.0 -59.0
  436. ;* $37 58.4 62.3 $77 24.8 26.8 $b7 -2.3 -1.6 $f7 -59.0 -59.0
  437. ;* $38 57.6 61.6 $78 24.4 26.4 $b8 -2.8 -2.2 $f8 -59.0 -59.0
  438. ;* $39 56.9 60.9 $79 23.9 25.9 $b9 -3.3 -2.8 $f9 -59.0 -59.0
  439. ;* $3a 56.1 60.1 $7a 23.5 25.5 $ba -3.8 -3.3 $fa -59.0 -59.0
  440. ;* $3b 55.4 59.4 $7b 23.0 25.1 $bb -4.3 -3.9 $fb -59.0 -59.0
  441. ;* $3c 54.7 58.7 $7c 22.6 24.7 $bc -4.8 -4.5 $fc -59.0 -59.0
  442. ;* $3d 54.0 58.0 $7d 22.2 24.2 $bd -5.3 -5.1 $fd -59.0 -59.0
  443. ;* $3e 53.3 57.3 $7e 21.8 23.8 $be -5.9 -5.7 $fe -59.0 -59.0
  444. ;* $3f 52.6 56.6 $7f 21.4 23.4 $bf -6.4 -6.3 $ff -59.0 -59.0
  445. ;*
  446. ;*
  447. ;*
  448. ;*
  449. ;****************************************************************************************************
  450.  
  451. ;***************************************************************
  452. ;*
  453. ;*
  454. ;* Assembler general settings
  455. ;*
  456. ;*
  457. ;*
  458. ;***************************************************************
  459. .msfirst ; Assembler endian setting, do not change
  460. .define E931 ; E931 or E932 depending on desired output
  461. ;.define enableCustom ; Define to enable custom features below, comment-out to get the original E931 or E932 binaries
  462.  
  463. #ifdef enableCustom
  464. ;-----------------
  465. ; Custom settings
  466. ;-----------------
  467. codeOffset .equ $0100 ; Allows to move all the code up in the eprom to make space for new code, Original offset is 0.
  468. .define ftrimMax $b3 ; Maximum fuel trim adjustement (xx/$80)%, $b3=140%
  469. .define fuelMapClip $d0 ; Fuel map max value (will be clippped to this in code)
  470. .define injComp $31 ; Injector size compensation referenced to $80=100% for 260cc at 36psi: 390cc(4E,43psi);450(4A);510(41);550(3D);600(38);650(33);660(32);680(31);700(30);750(2C);800(2A);850(27);
  471. .define idleVal $64 ; Idle speed /8, Normal $60
  472. .define idleDrVal $57 ; Idle speed /8, Normal $53
  473. .define fuelCutVal $ff ; Fuel cut value, Original $a0
  474. .define masComp $40 ; Mas multiplier (1G:$64, 2G:$40)
  475. .define masScalar $7a03 ; Mas scalar (1G:$5e86, 2G:$7a03)
  476. .define baudRate $02 ; BaudRate divider->00(125000baud),01(15625baud),02(1953baud),03(488baud)
  477.  
  478. .define custDeadTime ; Use custom injector deadtime table
  479. .define custMas ; Use custom MAS table
  480. .define custFuelMap ; Use custom fuel map
  481. .define custTimingMap ; Use custom timing map
  482. .define custOctaneMap ; Use custom octane map
  483. .define octaneReset ; Reset octane on every start
  484. .define extLoadRange ; Extended load range for timing, fuel and octane maps...
  485. .define extLoadRange2 ; Use temperature compensation for load calc when extLoadRange is enabled
  486. .define batteryGauge ; Battery gauge instead of boost gauge
  487. .define masLog2X ; Double the MAS logging range
  488. ;.define noFuelCut ; Remove fuel cut altogether
  489. ;.define noRamReset ;
  490. ;.define noClosedLoop ; Remove closed loop mode, for testing...
  491.  
  492. #else
  493. #ifdef E931
  494. ;--------------------------------------
  495. ; Default values for original 931 ECU
  496. ;--------------------------------------
  497. codeOffset .equ $0000 ;
  498. .define ftrimMax $b3 ;
  499. .define fuelMapClip $ca ;
  500. .define injComp $4a ; 450cc injectors used at 36psi...
  501. .define idleVal $60 ;
  502. .define fuelCutVal $a0 ;
  503. .define masComp $64 ;
  504. .define masScalar $5e86 ;
  505. .define baudRate $02 ;
  506. #else
  507. ;--------------------------------------
  508. ; Default values for original 932 ECU
  509. ;--------------------------------------
  510. codeOffset .equ $0000 ;
  511. .define ftrimMax $b0 ;
  512. .define fuelMapClip $c0 ;
  513. .define injComp $4e ; 390cc injectors used at 43psi, the value reflects that pressure difference compared to E931
  514. .define idleVal $60 ;
  515. .define idleDrVal $53 ;
  516. .define fuelCutVal $a0 ;
  517. .define masComp $64 ;
  518. .define masScalar $5e86 ;
  519. .define baudRate $02 ;
  520. #endif
  521. #endif
  522.  
  523.  
  524.  
  525. ;***************************************************************
  526. ;*
  527. ;*
  528. ;* Microcontroller registers
  529. ;*
  530. ;*
  531. ;***************************************************************
  532. p1_ddr .EQU $0000 ; Port 1 data direction register. Initialized with $7E=01111110 (0=intput, 1=output)
  533. p2_ddr .EQU $0001 ; Port 2 data direction register. Initialized with $16=00010110
  534. port1 .EQU $0002 ; Port 1 Data register
  535. ; bit 0 (0x01): in - Unused but varies(seems to have correlation with CAS), by extrapolation, set to out for injector #5 or #6 on other ECUs?
  536. ; bit 1 (0x02): out - Set to 0 to activate injector #3?
  537. ; bit 2 (0x04): out - Set to 0 to activate injector #2?
  538. ; bit 3 (0x08): out - Set to 0 to activate injector #4?
  539. ; bit 4 (0x10): out - Fuel pump relay
  540. ; bit 5 (0x20): out - Air cond. clutch
  541. ; bit 6 (0x40): out - ???, reset to 0 on init and first sub
  542. ; bit 7 (0x80): in - Reed switch, 4 square pulse (square wave) per odometer rotation, each of the 4 complete square wave correspond to ~40cm (20cm for each rising or falling edge)
  543. port2 .EQU $0003 ; Port 2 Data register
  544. ; bit 0 (0x01): in - Unused but varies (seems to have correlation with CAS), by extrapolation, set to out for injector #5 or #6 on other ECUs?
  545. ; bit 1 (0x02): out - Set to 0 to activate injector #1?
  546. ; bit 2 (0x04): out - Airflow sensor active filter reset. Set/reset depending on tps,rpm,airVol,idleSwitch?????? (in serial clock)- Connected to serial port clock???
  547. ; bit 3 (0x08): in - Connected to serial port input (if serial RE is enabled) and test connector serial interface
  548. ; bit 4 (0x10): out - Connected to serial port output (if serial TE is enabled) and test connector serial interface, controlled directly to output heart beat code to test connector
  549. ; bit 5 (0x20): in - 0, ECU Operating mode PC0 (latched on ECU reset)
  550. ; bit 6 (0x40): in - 1, ECU Operating mode PC1
  551. ; bit 7 (0x80): in - 0, ECU Operating mode PC2
  552. p3_ddr .EQU $0004 ; Port 3 data direction register, Initialized to 0 (all input)
  553. p4_ddr .EQU $0005 ; Port 4 data direction register, Initialized to 0 (all input)
  554. port3 .EQU $0006 ; Port 3 Data register
  555. ; bit 0 (0x01): in - IG2 related, 0 when IG2 at +12V??? (ABS unit?????) see around Md4d4 and M23db?
  556. ; bit 1 (0x02): in - IG1. 0 when IG1 at +12V. Set to 1 when power has been turned off and control relay is about to turn off. i.e. ECU is going to loose power in a short while.
  557. ; bit 2 (0x04): in - Top dead center sensor signal (TDC). Set to 0 when TDC signal is active
  558. ; bit 3 (0x08): in - Set to 1 if power steering pump is activated
  559. ; bit 4 (0x10): in - Air cond. switch (1=off). 0 indicate that AC should be activated, if possible... Connected to the output of the A/C control unit through the the ECT switch (switch cuts signal therefore asking ECU to cut clutch...)
  560. ; bit 5 (0x20): in - Inhibitor switch (A/T only) Set to 1 when transmission is in park or neutral
  561. ; bit 6 (0x40): in - 0 if key is in start position
  562. ; bit 7 (0x80): in - Set to 1 when the idle switch is on
  563. port4 .EQU $0007 ; Port 4 data register
  564. ; bit 0 (0x01): in - c0, set when config resistor R129 is installed. used in conjucntion with c1 in #t_strap1 lookup, FEDERAL (0) or CALIFORNIA (1)
  565. ; bit 1 (0x02): in - c1, set when config resistor R130 is installed. used in conjucntion with c0 in #t_strap1 lookup, FWD (0) or AWD (1)
  566. ; bit 2 (0x04): in - Signal from the ignition sensing circuit. Toggled on every ignition signal sent to the coil (toggled on every cylinder ignition if the power transistor output changed...), stays at the given level from one ignition to the other
  567. ; bit 3 (0x08): in - Set to 1 when ECU test mode terminal is grounded
  568. ; bit 4 (0x10): in - Set to 1 when the timing terminal is grounded
  569. ; bit 5 (0x20): in - Knock sensor feedback? (set to 1 indicates it works...)???
  570. ; bit 6 (0x40): in - Fuel pump driven feedback? 0 when FP is driven?
  571. ; bit 7 (0x80): in - Injector driven feedback. Set to 0 when injector circuit is working properly??? Bit is tested when an injector to test was just deactivated and no other injector is active??? Bit might be loaded on the falling edge of the injector driving current???
  572. ; Service manual says injector is bad if injector is not continuously driven for 4 sec during idle or cranking. 4 sec is implemented by fault code regular code... So this bit would be "injector driven" bit
  573. t1_csr .EQU $0008 ; Dual of $18, Timer1 control and status register, dual of t2_csr
  574. ; bit 0 (0x01): Injector 1 activation/deactivation bit. Bit is transfered to port2.1 when a t1 or t2 output compare interrupt is generated???
  575. ; bit 1 (0x02): cas edge detection polarity, set to 0 to trigger an interrupt on the CAS rising edge, set to 1 to trigger an interrupt on the CAS falling edge
  576. ; bit 2 (0x04): By extrapolation, set to 0 when injector 5/6 is on????
  577. ; bit 3 (0x08): Set to 1 to enable outCompInt1 interrupts (injector 1 only or 1 and 4)?
  578. ; bit 4 (0x10): Set to 1 to enable inCaptInt1 interrupts (cas)?
  579. ; bit 5 (0x20): By extrapolation, set to 0 when injector 5/6 is on????
  580. ; bit 6 (0x40): 1 indicate that outCompInt1 interrupt is pending/has been activated (injector #1 or #4 activation/deactivation)
  581. ; bit 7 (0x80): 1 indicate that inCaptInt1 interrupt is pending/has been activated (cas)
  582. t1t2_clk .EQU $0009 ;:$000a ; Free running counter at 1MHz for t1 and t2 timer functions
  583. t1_outCmpWr .EQU $000b ;:$000c ; Dual of $001B, Output compare register, value is compared to t1t2_clk and when a match occurs, injector ports are loaded with the values indicated in t1_csr. Seems 2 or 3 successive value can be written (injector activation and deactivation times...)
  584. t1_inCapt .EQU $000d ;:$000e ; Cas sensor input capture register. Contains the value of t1t2_clk when the cas sensor "edge" was detected
  585. L000f .EQU $000f ; Init to 0??????????????
  586. sci_baud .EQU $0010 ; Serial communication rate and mode control register (clock source = 2MHz)
  587. ; bit 0 (0x01): SS0, [SS1:SS0] is baud rate divider, 00(16) 01(128) 10(1024) 11(4096), assuming basic clock of 2MHZ, we get 125000baud, 15625baud, 1953baud, 488baud
  588. ; bit 1 (0x02): SS1
  589. ; bit 2 (0x04): CC0, [CC1:CC0] is the mode control register
  590. ; bit 3 (0x08): CC1
  591. ; bit 4 (0x10): NU?
  592. ; bit 5 (0x20): NU?
  593. ; bit 6 (0x40): NU?
  594. ; bit 7 (0x80): NU?
  595. sci_scr .EQU $0011 ; Serial communication status and control register?
  596. ; bit 0 (0x01): WU - Wake-up on idle line
  597. ; bit 1 (0x02): TE - transmit enable, set to 1
  598. ; bit 2 (0x04): TIE - Tx interrupt enable, reset to 0
  599. ; bit 3 (0x08): RE - Rx enable, checked for set before tx
  600. ; bit 4 (0x10): RIE - Rx interrupt enable, Reset/set to 0/1 in real time int
  601. ; bit 5 (0x20): TDRE - transmit data register empty
  602. ; bit 6 (0x40) ORFE - Overrun and framing error
  603. ; bit 7 (0x80): RDRF - Read data register full
  604. sci_rx .EQU $0012 ; SCI data read register
  605. sci_tx .EQU $0013 ; SCI data write register
  606. ramControl .EQU $0014 ; RAM control register/battery saving status register
  607. ; bit 0 (0x01): Init to 0?
  608. ; bit 1 (0x02): Init to 0?
  609. ; bit 2 (0x04): Init to 0?
  610. ; bit 3 (0x08): Init to 0?
  611. ; bit 4 (0x10): Init to 0?
  612. ; bit 5 (0x20): Init to 0?
  613. ; bit 6 (0x40): Ram enable bit??? Set to 1 after the fresh reset initialization is done, reset to 0 in failureInt?
  614. ; bit 7 (0x80): Power standby bit, Set to 1 after the fresh reset initialization is done, reset to 0 if we loose standby power (i.e. 0 when ram content was not preserved after a power-off)
  615. p5_ddr .EQU $0015 ; Port 5 data direction register, Initialized to $#fe (1111 1110)
  616. port5 .EQU $0016 ; Port 5
  617. ; bit 0 (0x01): in - CAS, crank angle sensor signal. Set to 0 when the CAS signal is activated
  618. ; bit 1 (0x02): out - Power transistor output for cyl 1 and 4. Set to 0 to energize the coil.
  619. ; bit 2 (0x04): out - Power transistor output for cyl 2 and 3. Set to 0 to energize the coil.
  620. ; bit 3 (0x08): out - EGR control solenoid output
  621. ; bit 4 (0x10): out - Fuel pressure solenoid output (0=activated)
  622. ; bit 5 (0x20): out - Boost control solenoid output
  623. ; bit 6 (0x40): out - ISC step control, see table t_iscPattern
  624. ; bit 7 (0x80): out - ISC step control, see table t_iscPattern
  625. L0017 .EQU $0017 ; Init to 0?????
  626. t2_csr .EQU $0018 ; Timer2 control and status register, uses the same clock as timer 1 (t1t2_clk)
  627. ; bit 0 (0x01): Injector 3 activation/deactivation bit. Bit is transfered to port1.1 when a t1 or t2 output compare interrupt is generated
  628. ; bit 1 (0x02): Airflow sensor edge detection polarity (0=rising edge, 1=falling edge, or the opposite?). See masProc subroutine header
  629. ; bit 2 (0x04): Injector 2 activation/deactivation bit. Bit is transfered to port1.2 when a t1 or t2 output compare interrupt is generated
  630. ; bit 3 (0x08): Set to 1 to enable outCompInt2 interrupts (injectors 2, 3 and maybe 4)?
  631. ; bit 4 (0x10): Set to 1 to enable inCaptInt2 interrupts (airflow sensor)?
  632. ; bit 5 (0x20): Injector 4 activation/deactivation bit. Bit is transfered to port1.3 when a t1 or t2 output compare interrupt is generated
  633. ; bit 6 (0x40): 1 indicate that outCompInt2 interrupt is pending/has been activated (injectors #2 or #3 activation/deactivation)
  634. ; bit 7 (0x80): 1 indicate that inCaptInt2 interruot is pending/has been activated (airflow sensor pulse)
  635. t3_csr0 .EQU $0019 ; Normally the dual of $0009 but since the ECU didn't need the equivalent of t1t2_clk for timer 2 (timer 1 and timer 2 both use t1t2_clk), it is used for something else...
  636. ; timer 3 (coil) control ans status register 0 ???
  637. ; bit 0 (0x01): 0 all the time except, set to 1 when no cas interrupt received for 1.275sec???
  638. ; bit 1 (0x02): 1 on every loop
  639. ; bit 2 (0x04): 1 Set to 0 when the output compare interrupt need to energize coil for cylinder 1 or 4, i.e. bit will be loaded in port5.1 when interrupt occur
  640. ; bit 3 (0x08): 1 Set to 0 when the output compare interrupt need to energize coil for cylinder 2 or 3, i.e. bit will be loaded in port5.2 when interrupt occur
  641. ; bit 4 (0x10): 1 on init but not on every loop, Used to decide which of t3_clock1 or t3_clock2 should be used upon a CAS interrupt???
  642. ; bit 5 (0x20): 0 on every loop
  643. ; bit 6 (0x40): 1 on every loop
  644. ; bit 7 (0x80): 0 on every loop
  645. t3_csr1 .EQU $001a ; Normally the dual of $000a but since the ECU didn't need the equivalent of t1t2_clk for timer 2 (timer 1 and timer 2 both use t1t2_clk), it is used for something else...
  646. ; timer 3 (coil) control ans status register 1???
  647. ; bit 0 (0x01): 0 Cylinder 1/4 or 2/3 ?? output compare detection polarity?
  648. ; bit 1 (0x02): 1 Cylinder 1/4 or 2/3 ?? output compare detection polarity?
  649. ; bit 2 (0x04): 0 Cylinder 1/4 or 2/3 ?? output compare detection polarity?
  650. ; bit 3 (0x08): 1 Cylinder 1/4 or 2/3 ?? output compare detection polarity?
  651. ; bit 4 (0x10): 0
  652. ; bit 5 (0x20): 0
  653. ; bit 6 (0x40): 0 1 indicate that the outCompInt3 interrupt is pending/has been activated???
  654. ; bit 7 (0x80): 0
  655. t2_outCmpWr .EQU $001b ;:$001c ; Dual of $0b:$0c, Output compare register, value is compared to t1t2_clk and when a match occurs, injector ports are loaded with the values indicated in t2_csr. seems 2 or 3 successive value can be written (injector activation and deactivation times...)
  656. t2_inCapt .EQU $001d ;:$001e ; Dual of $0d:$0e, Airflow sensor input capture register. Contains the value of t1t2_clk when an airflow sensor pulse edge detected
  657. adc_ctl .EQU $001f ; ADC control; [bit 3 = start bit?, bit 2:0 = channel select ]???
  658. ; bit 0 (0x01): c0 [c2:c1:c0] is the port number to use aas input to the A/D converter
  659. ; bit 1 (0x02): c1
  660. ; bit 2 (0x04): c2
  661. ; bit 3 (0x08): Start bit, set to 1 to start A/D conversion
  662. ; bit 4 (0x10): ?
  663. ; bit 5 (0x20): ?
  664. ; bit 6 (0x40): ?
  665. ; bit 7 (0x80): ?
  666. adc_data .EQU $0020 ; 8 bit A to D converter result data
  667. L0021 .EQU $0021 ; Unused?
  668. L0022 .EQU $0022 ; Unused?
  669. L0023 .EQU $0023 ; Unused?
  670. L0024 .EQU $0024 ; Init to 0?
  671. L0025 .EQU $0025 ; Unused?
  672. rti_ctl .EQU $0026 ; Timer control and status register for real time interrupt? init to $4D = 0100 1101
  673. ; bit 0 (0x01): ?
  674. ; bit 1 (0x02): ?
  675. ; bit 2 (0x04): ?
  676. ; bit 3 (0x08): ?
  677. ; bit 4 (0x10): ?
  678. ; bit 5 (0x20): ?
  679. ; bit 6 (0x40): Set to 1 to enable rti interrupts?
  680. ; bit 7 (0x80): ?
  681. rti_freq .EQU $0027 ; Real time interrupt frequency setting: Freq = 125000/(256-x) where x is the content of rti_freq
  682. L0028 .EQU $0028 ; Unused?
  683. t3_clock1 .EQU $0029 ;:$002a ; Readable counter. Frequency seems to be 250KHz (2MHz/8).
  684. t3_outCmpWr .EQU $002b ;:$002c ; Writable output compare register for counters at $0029:$002A and $002D:$002E
  685. ; Seems to be double buffered...
  686. t3_clock2 .EQU $002d ;:$002e ; Dual of $0029. I think it always has the same value as t3_clock1 but ipon a cas interrupt, the code decides between t3_clock1 and t3_clock2???
  687. port6 .EQU $002f ; Port 6 (all output, no data direction register?)
  688. ; bit 0 (0x01): out - Write 1 to reset instant knock count???
  689. ; bit 1 (0x02): out - ??? Set to 0 when rpm>4688rpm, set to 1 when rpm<4600, could be some kind of ECU board filter setting for the knock sensor???
  690. ; bit 2 (0x04): out - Boost gauge output
  691. ; bit 3 (0x08): out - Check engine (CE) light
  692. ; bit 4 (0x10): out - Reset to 0 to activate purge solenoid?
  693. ; bit 5 (0x20): out - Toggled at F924 if main loop frequency >20Hz, could be tied to ECU reset in case of trouble (COP clock)
  694. ; bit 6 (0x40): out - Not used?
  695. ; bit 7 (0x80): out - Not used?
  696.  
  697. ;------------------------------
  698. ; Block of 16 probably unused
  699. ; microcontroller registers???
  700. ;------------------------------
  701. L0030 .EQU $0030 ; Unused
  702. L0031 .EQU $0031 ; Unused
  703. L0032 .EQU $0032 ; Unused
  704. L0033 .EQU $0033 ; Unused
  705. L0034 .EQU $0034 ; Unused
  706. L0035 .EQU $0035 ; Unused
  707. L0036 .EQU $0036 ; Unused
  708. L0037 .EQU $0037 ; Unused
  709. L0038 .EQU $0038 ; Unused
  710. L0039 .EQU $0039 ; Unused
  711. L003a .EQU $003a ; Unused
  712. L003b .EQU $003b ; Unused
  713. L003c .EQU $003c ; Unused
  714. L003d .EQU $003d ; Unused
  715. L003e .EQU $003e ; Unused
  716. L003f .EQU $003f ; Unused
  717.  
  718.  
  719.  
  720. ;***************************************************************
  721. ;*
  722. ;*
  723. ;* Block of RAM used to preserve settings when the ECU is off
  724. ;* (This block is not cleared to 0 when the ECU is powered-on)
  725. ;*
  726. ;*
  727. ;***************************************************************
  728. ftrim_low .EQU $0040 ; Fuel trim low (.78x)%
  729. ftrim_mid .EQU $0041 ; Fuel trim mid (.78x)%
  730. ftrim_hi .EQU $0042 ; Fuel trim high (.78x)%
  731. ftrimCntr .EQU $0043 ; Fuel trim counter. This counter is increased/decreased by 5 (+/-5 at 40Hz) whenever a fuel trim is below/above o2Fbk threshold. The fuel trim is increased/decreased by 1 whenever this counter rools over, giving an effective update rate of 40Hz/(256/5)=0.78125Hz for the fuel trims update
  732. isc0 .EQU $0044 ;:$0045 ; iscm (isc0 or isc1) are 16 bit long term correction factors/feedback for the isc step adjustment. It is centered at $8000 (100%, no correction). Init to $8c00, A value higher than $8000 indicate that we need to increase the isc step since the current rpm is lower than the desired one
  733. ; The isc step used is increased/decreased by iscm/256 - $80. iscm is updated from the short term iscYn variable.The isc step used is increased/decreased by iscm/256 - $80
  734. ; isc0 is the long term learning variable when A/C is off, 16 bits, see iscPointers function
  735. isc1 .EQU $0046 ;:$0047 ; isc1 is the long term learning variable when A/C is on, 16 bits, see iscPointers function
  736. iscStepCom .EQU $0048 ; isc step complement, shlould be equal to ~iscStepCurr & $7f. Not sure of its utility???
  737. iscStepCurr .EQU $0049 ; Current isc step (x) range of 0 to 120 (or 13x???)
  738. iscPatrnIdx .EQU $004a ; Current ISC pattern index, two lower bits are used as index into t_iscPattern to update port5.6.7 in order to move the ISC spindle...
  739. iscFlags0 .EQU $004b ; Flag register for ISC updating
  740. ; bit 0 (0x01): Set to 1 once the isc calibration is started. This means we initialized iscStepCurr to 135 and set the iscStepTarg to 0. The spindle will therefore be moved to the minimum position irrespective of the starting position, which will allow us to know its real position... Reset to 0 once calibration is finished and ISC is back to iscStepCurr=6
  741. ; bit 1 (0x02): Set to 1 once the isc calibration is finished. i.e. once iscStepCurr reached 0. See bit 0. Reset to 0 once calibration is finished and ISC is back to iscStepCurr=6
  742. ; bit 2 (0x04): Set when basic idle speed adjustment mode is active
  743. ; bit 3 (0x08): Set to 1 when a fixed isc step is used because the engine is running but we are not receiving airflow sensor interrupts.
  744. ; bit 4 (0x10): Set to 1 when a fixed isc step is used because the ECU is about to loose power
  745. ; bit 5 (0x20): Set to 1 when ISC min calibration need to be performed, i.e. move the spindle 135 steps toward 0, that ensures the spindle is positionned at the minimum position, wherever we started from... Reset to 0 once calibration is finished and ISC is back to iscStepCurr=6
  746. ; bit 6 (0x40): Set to 1 when the ISC max calibration has been performed, see bit 7
  747. ; bit 7 (0x80): Set to 1 when ISC max calibration need to be performed. Max calibration is achieved by setting iscStepTarg to 135, wait for iscStepCurr to reach 135 (higher than max usable valu of 120) and then set iscStepCurr to 120 since this is the max usable value
  748. stFaultHi .EQU $004c ; Stored faults, High byte. Notice we say its high byte because it is the ECU convention to store high byte before low byte and it is also used that way in the code
  749. stFaultLo .EQU $004d ; Stored faults, Low byte.
  750. faultHi .EQU $004e ; Faults, high byte. Notice we say its high byte because it is the ECU convention to store high byte before low byte and it is also used that way in the code
  751. faultLo .EQU $004f ; Faults, low byte
  752. o2BadCnt .EQU $0050 ; Used to test the o2 sensor, 0 when 02 sensor not in fault or not tested, 1 or greater when o2 sensor is bad. Can only increase by 1 each time the ECU is turned on and sensor is tested
  753. egrtBadCnt .EQU $0051 ; Used to test the egrt sensor, 0 when egrt sensor not in fault or not tested, 1 or greater when egrt sensor is bad. Can only increase by 1 each time the ECU is turned on and sensor is tested
  754. octane .EQU $0052 ; Octane value used in timing advance calculation with min 0(bad fuel...), max 255 (no knock). Updated at 2.5Hz from knockSum under specific circumstances (decremented by 1 if knocksum>5, incremented by 1 if knocksum<3)
  755. knockFlags .EQU $0053 ; Flags related to knock sensor
  756. ; bit 0 (0x01):
  757. ; bit 1 (0x02):
  758. ; bit 2 (0x04):
  759. ; bit 3 (0x08):
  760. ; bit 4 (0x10):
  761. ; bit 5 (0x20):
  762. ; bit 6 (0x40): Set to 1 when engine has been runnning for more than 1 sec
  763. ; bit 7 (0x80): Set to 1 when airVol>$49, used to know whether engine is under high or loaw load for knockSum and knockSum decay calculations
  764. L0054 .EQU $0054 ; UNUSED?
  765. config1 .EQU $0055 ; Configuration flags depending on config resistors, Loaded with t_strap1[port4& (#$03 << 1)]
  766. ; bit 0 (0x01):
  767. ; bit 1 (0x02):
  768. ; bit 2 (0x04):
  769. ; bit 3 (0x08):
  770. ; bit 4 (0x10):
  771. ; bit 5 (0x20):
  772. ; bit 6 (0x40):
  773. ; bit 7 (0x80):
  774. config2 .EQU $0056 ; Configuration flags depending on config resistors, Loaded with t_strap1[port4& (#$03 << 1)+1]
  775. ; bit 0 (0x01):
  776. ; bit 1 (0x02):
  777. ; bit 2 (0x04):
  778. ; bit 3 (0x08):
  779. ; bit 4 (0x10):
  780. ; bit 5 (0x20):
  781. ; bit 6 (0x40):
  782. ; bit 7 (0x80):
  783.  
  784.  
  785.  
  786. ;***************************************************************
  787. ;*
  788. ;*
  789. ;* RAM, cleared to 0 when the ECU is powered-on
  790. ;*
  791. ;*
  792. ;***************************************************************
  793. ramClearStart .EQU $0057
  794. temp1 .EQU $0057 ;
  795. temp2 .EQU $0058 ;
  796. temp3 .EQU $0059 ;
  797. temp4 .EQU $005a ;
  798. temp5 .EQU $005b ;
  799. temp6 .EQU $005c ;
  800. temp7 .EQU $005d ;
  801. temp8 .EQU $005e ;
  802. temp9 .EQU $005f ;
  803. L0060 .EQU $0060 ; Unused
  804. casFlags0 .EQU $0061 ; Flag register
  805. ; bit 0 (0x01): Bit is set to 1 when rpm(Tcas) >= 505, reset when rpm(Tcas) < 401 (hysteresis)
  806. ; bit 1 (0x02): Old value of bit 0
  807. ; bit 2 (0x04): 1 if rpm(Tcas) > 1775rpm
  808. ; bit 3 (0x08): Old value of bit 2
  809. ; bit 4 (0x10): 1 if rpm(Tcas) > 1540rpm
  810. ; bit 5 (0x20): 1 if rpm(Tcas) > 4801rpm
  811. ; bit 6 (0x40): Set to 1 if timing adjustment mode is active
  812. ; bit 7 (0x80): Unused?
  813. ignFallFlags .EQU $0062 ; Coil ignition scheduling on the cas falling edge
  814. ; bit 0 (0x01): Set to 1 when coil ignition was not scheduled on the CAS
  815. ; rising edge and therefore need to be scheduled on the CAS falling edge?
  816. ; bit 1 (0x02): not used
  817. ; bit 2 (0x04): not used
  818. ; bit 3 (0x08): not used
  819. ; bit 4 (0x10): not used
  820. ; bit 5 (0x20): not used
  821. ; bit 6 (0x40): not used
  822. ; bit 7 (0x80): not used
  823. enerFlags .EQU $0063 ; Coil energization state, bit 0 and 1 are mutually exclusive, they are never set at the same time...
  824. ; Note that when rpm is low, these flags might not be set as indicated (during cranking?)
  825. ; bit 0 (0x01): Set to 1 when coil is currently energized?
  826. ; bit 1 (0x02): Set to 1 when coil energization has been scheduled?
  827. ; bit 2 (0x04): not used
  828. ; bit 3 (0x08): not used
  829. ; bit 4 (0x10): not used
  830. ; bit 5 (0x20): not used
  831. ; bit 6 (0x40): not used
  832. ; bit 7 (0x80): not used
  833. TcasLast0 .EQU $0064 ; TcasLast0:TcasLast1 (250KHz clock) is identical to TcasNew0:TcasNew1 but it has been validated for range. Basically it is the last Tcas value that was valid
  834. TcasLast1 .EQU $0065 ; See TcasLast0
  835. TcasNew0 .EQU $0066 ; TcasNew0:TcasNew1 (250KHz clock) is the new value of Tcas calculated during the CAS interrupt
  836. TcasNew1 .EQU $0067 ; See TcasNew0
  837. casRiseTime0 .EQU $0068 ; casRiseTime0:casRiseTime1 (250KHz clock) is the clock value when the last CAS rising edge interrupt occured
  838. casRiseTime1 .EQU $0069 ; See casRiseTime0
  839. casFallTime0 .EQU $006a ; casFallTime0:casFallTime1 (250KHz clock) is the clock value when the last CAS falling edge interrupt occured
  840. casFallTime1 .EQU $006b ; See casFallTime0
  841. timCas0 .EQU $006c ; The current ignition timing (xx/256*90)degrees referenced to the CAS pulse rising edge (75deg BTDC), [timCas0:timCas1] = 256 * (75.77 - degAdv)/90, calculated from tim61 + $002a
  842. timCas1 .EQU $006d ; See timCas0
  843. ignRelTime0 .EQU $006e ; [ignRelTime0:ignRelTime1] is the current ignition time minus 72us measured in 1/250000 sec (timer clock) and referenced to the CAS rising edge (75deg BTDC). Calculated from timCas0: [ignRelTime0:ignRelTime1] = [TcasNew0:TcasNew1]/2 * [timCas0:timCas1]/256 - $0012
  844. ignRelTime1 .EQU $006f ; See ignRelTime0
  845. ignFallRelTime0 .EQU $0070 ; Similar to ignRelTime0 but measured from te cas falling edge, used to schedule ignition when the timing is high (past the cas falling edge...)
  846. ignFallRelTime1 .EQU $0071 ; See ignFallRelTime0
  847. enerLenX0 .EQU $0072 ; One of the coil energization durations, the one used depends on current conditions...
  848. enerLenX1 .EQU $0073 ; See enerLenX0
  849. enerAbsTime0 .EQU $0074 ; Coil energization absolute time (t3_clock1)
  850. enerAbsTime1 .EQU $0075 ; See enerAbsTime0
  851. ignTime0 .EQU $0076 ; Coil ignition absolute time (t3_clock1)
  852. ignTime1 .EQU $0077 ; See ignTime1
  853. enerAbsTimeNext0 .EQU $0078 ; Coil absolute energization time (ignTime1) but only used when energization of the "next cylinder" is scheduled from the preceeding cylinder coil ignition time...
  854. enerAbsTimeNext1 .EQU $0079 ; See enerAbsTimeNext0
  855. TcasLast128 .EQU $007a ; Set to TcasLast0/128
  856. tdcMask0 .EQU $007b ; tdcMask0:tdcMask1 contains $0204 when TDC signal is active (cylinder 1 or 4) on the CAS rising edge, $0402 otherwise. Toggled on every CAS rising edge
  857. tdcMask1 .EQU $007c ; See tdcMask0
  858. tim61 .EQU $007d ; Current timing (xx/256*90)degrees referenced to 61deg BTDC, tim61 = 256 * (61 - degAdv) / 90, where degAdv is the timing advance in degrees. Calculated from tim61Tot0
  859. temp20 .EQU $007e ;
  860. temp21 .EQU $007f ;
  861. temp22 .EQU $0080 ;
  862. temp23 .EQU $0081 ;
  863. temp24 .EQU $0082 ;
  864. tdcCasCount .EQU $0083 ; CAS rising edge counter when key is not in start, incremented on every CAS rising edge up to a maximum value of 6, used in TDC synch. operation
  865. T40s_casInt .EQU $0084 ; Initialized to 1.275sec on every CAS rising edge interrupt and decremented in first subroutine at ~40Hz. Will reach 0 (expire) only when no CAS interrupt was received for over 1.275sec, i.e. engine is really not rotating or something is wrong?
  866. coilChkFlags .EQU $0085 ; Flag register used to validate the ignition signal using the ignition coil sensing circuit
  867. ; bit 0 (0x01): Injector 1, set to 1 to indicate that the injector can be used, 0 indicate injector is disabled because ignition is not happening on the corresponding cylinder
  868. ; bit 1 (0x02): Injector 3, set to 1 to indicate that the injector can be used, 0 indicate injector is disabled because ignition is not happening on the corresponding cylinder
  869. ; bit 2 (0x04): Injector 4, set to 1 to indicate that the injector can be used, 0 indicate injector is disabled because ignition is not happening on the corresponding cylinder
  870. ; bit 3 (0x08): Injector 2, set to 1 to indicate that the injector can be used, 0 indicate injector is disabled because ignition is not happening on the corresponding cylinder
  871. ; bit 4 (0x10):
  872. ; bit 5 (0x20): Set to 1 when engine is running and rpm<5000 and 8V<=battRaw<=18V, meaning we can proceed with checking the ignition
  873. ; bit 6 (0x40):
  874. ; bit 7 (0x80): Set to 1 when we detected that several ignition signals were missing, ignition is not working properly.
  875. p4Latched .EQU $0086 ; Loaded with port4 and checked for bit #$04 in CAS interrupt
  876. timAdjFlags .EQU $0087 ; Timing adjustment mode flags
  877. ; bit 0 (0x01): Set when rpm31>2000rpm, reset when rpm31 goes lower than 1813rpm (hysteresis)
  878. ; bit 1 (0x02):
  879. ; bit 2 (0x04):
  880. ; bit 3 (0x08):
  881. ; bit 4 (0x10):
  882. ; bit 5 (0x20):
  883. ; bit 6 (0x40):
  884. ; bit 7 (0x80): Set to 1 when timing adjustment mode is active (timing terminal is grounded but the ECU test mode terminal is not grounded
  885. tim61Tot0 .EQU $0088 ; New target timing (xx/256*90)degrees referenced to 61deg BTDC. knockSum is added to this value in order to retard timing further and then a maximum rate of change of 22.5deg/iteration is applied. The result becomes the new timing to apply (tim61 and timCas0:timCas1). Calculated from advTotal
  886. enerLen .EQU $0089 ; Coil energization time as loaded from the t_enerLen(battRaw) table. Actual energization time used might be different, longer...
  887. timingAdv .EQU $008a ; Current timing advance, (x-10)degrees, timingAdv = degAdv+10, Calculated from tim61
  888. knockSum .EQU $008b ; Current knock sum value
  889. T200s_knock .EQU $008c ; Knock attenuation timer decremented at 200Hz and looping at 1.67Hz or 100Hz depending on airVol, knockSum is decremented by 1 every time this timer expires
  890. airCnt0 .EQU $008d ; [airCnt0:airCnt1:airCnt2] is the exponentially averaged 24 bit air count (input is 16 bit [airCntNew0:airCntNew1]*256)
  891. airCnt1 .EQU $008e ; See airCnt0
  892. airCnt2 .EQU $008f ; See airCnt0
  893. airCntNew0 .EQU $0090 ; airCntNew0:airCntNew1 is the 16 bits air count used as input to [airCnt0:airCnt1:airCnt2]. It is equal (N+r) * $9c where N is the number of airflow sensor pulse counted by the mas interrupt between each cas interrupt (1 cas interrupt for every cylinder cycle, 4 per every 2 engine rotations) r<=1 is a "remainder" proportional to the time elapsed since the last interrupt...
  894. airCntNew1 .EQU $0091 ; See airCntNew0
  895. oldAirCnt0 .EQU $0092 ;:$0093 ; This is the old value of airCnt0:airCnt1 used to compute some kind of air count derivative
  896. airDiffPos .EQU $0094 ; Contains airCnt0-oldAirCnt0 when the difference is positive, This is kind of the derivative of air count which is positive when air count is increasing (acceleration)
  897. airDiffNeg .EQU $0095 ; Contains abs(airCnt0-oldAirCnt0) when the difference is negative (contains oldAirCnt0-airCnt0...). This is kind of the derivative of air count which is negative when air count is decreasing (decceleration)
  898. t1_lastCas .EQU $0096 ;:$0097 ; Latest value of t1_inCapt when CAS interrupt was called
  899. t2_lastMas .EQU $0098 ;:$0099 ; Latest value of t2_inCapt when MAS interrupt was called
  900. t2_diff8 .EQU $009a ;:$009b ; Time between 2 edges (2 edges per pulse...) of the airflow sensor with timer based rounding (see code), calculated on each mas interrupts from t2_inCapt/8
  901. airQuantum .EQU $009c ; This value ($9c) is the the "amount of air" corresponding to 1 airflow sensor pulse. Using a non unitary value allows the ECU to interpolate the airflow between pulses, i.e. if at the time we calculate airflow we are at 2/3 in between two pulses then we add 2/3 of airQuantum...
  902. ; It is added to [airCntNew0:airCntNew1] on each mas interrupt call (accumulates N times $9C...). A ratio is also applied to this value when it is added to [airCntNew0:airCntNew1] for the last time (partial count in between pulses) before airCnt0 is calculated.
  903. L009d .EQU $009d ; Not used?
  904. masCasFlags .EQU $009e ; Flag register
  905. ; bit 0 (0x01): Bit is set when the CAS rising edge interrupt code is executed to flag the event to the main loop. Flag is read from main loop to update rpmX4Filt and then reset
  906. ; bit 1 (0x02):
  907. ; bit 2 (0x04):
  908. ; bit 3 (0x08):
  909. ; bit 4 (0x10):
  910. ; bit 5 (0x20):
  911. ; bit 6 (0x40):
  912. ; bit 7 (0x80): Scaling for the airflow sensor pulse counting. Set to 0 when we count both the rising and falling edge of the airflow sensor pulse. Set to 0 in case we count only the rising edges (or only the falling ones)
  913. airFiltFact .EQU $009f ; airCnt0 exponential averaging factor with alpha = airFiltFact/256, 0<=alpha<=1, basically used to filter the air count: new airCnt0 = alpha * old airCnt0 + (1-alpha)*newAirCntValue, possible values in the code are $b3(70%), $d1(82%) or $e4(89%)
  914. airCntMax .EQU $00a0 ; Air count based on rpm, ect and iat, 8*airCntMax is used as a maximum on airCnt0 or when engine not rotating/starting to rotate
  915. accEnr .EQU $00a1 ; Acceleration enrichment (100x/255)%. This value is actually updated with min(airCnt0-oldAirCnt0,$48) under acceleration, see code. Max value is $48 from code
  916. state3 .EQU $00a2 ; Flag register
  917. ; bit 0 (0x01): Copied from same bit in state1 (1=startingToCrank)
  918. ; bit 1 (0x02): Copied from same bit in state1 (1=no pulse accumulator interrupts)
  919. ; bit 2 (0x04): Set when RPM exceeds threshold (rev limiter)
  920. ; bit 3 (0x08): Copied from same bit in state1 (1=rotatingStopInj)
  921. ; bit 4 (0x10): Copied from same bit in state1 (1=notRotating)
  922. ; bit 5 (0x20): Set if rotatingStopInj and not runningFast
  923. ; bit 6 (0x40):
  924. ; bit 7 (0x80): Set to injFlags0.7 (1 when startingToCrankColdEngine)
  925. injFactor .EQU $00a3 ;:$00a4 ; Global injector factor used to calculate injPw from [airCnt0:airCnt1],
  926. ; injFactor = 16*totMasComp * injComp/128 * [workFtrim + o2FuelAdj + 2*$80]/512 * iatCompFact/128 * baroFact/128 * openLoopEnr/128 * coldTempEnr/128 * (2*enrWarmup + $80)/128
  927. oldReedVal .EQU $00a5 ; Old value of the reed switch sensor
  928. deadTime .EQU $00a6 ; Injector deadtime in increment of 24uS (depends on current batteryVoltage)
  929. injPw .EQU $00a7 ;:$00a8 ; 16 bit injector pulse width in microseconds. Logger reports high and low bytes: (.256 highByte)mS
  930. inj1_offT .EQU $00a9 ;:$00aa ; Injector #1? deactivation time (relative to timer t1t2_clk)
  931. inj3_offT .EQU $00ab ;:$00ac ; Injector #3? deactivation time (relative to timer t1t2_clk)
  932. inj4_offT .EQU $00ad ;:$00ae ; Injector #4? deactivation time (relative to timer t1t2_clk)
  933. inj2_offT .EQU $00af ;:$00b0 ; Injector #2? deactivation time (relative to timer t1t2_clk)
  934. last_t1t2_clk .EQU $00b1 ; Initialized to t1t2_clk/256 on CAS falling edge, every one of them???
  935. injToAct .EQU $00b2 ; Indicate which injectors are currently active or should be activated, Set to 1 for an active injector
  936. ; bit 0 (0x01): Inj 1?
  937. ; bit 1 (0x02): Inj 3?
  938. ; bit 2 (0x04): Inj 4?
  939. ; bit 3 (0x08): Inj 2?
  940. ; bit 4 (0x10):
  941. ; bit 5 (0x20):
  942. ; bit 6 (0x40):
  943. ; bit 7 (0x80):
  944. tdcCasFlags .EQU $00b3 ; Init to 5
  945. ; bit 0 (0x01): c0, c2:c1:c0 used as a down counter (on every CAS pulse falling edge) initialized with 5. Reset to 0 when the CAS pulse falling edge correpond to the cylinder #1 TDC pulse (see bit 7)
  946. ; bit 1 (0x02): c1
  947. ; bit 2 (0x04): c2
  948. ; bit 3 (0x08): Set to the last value of TDC bit on port3. 2
  949. ; bit 4 (0x10):
  950. ; bit 5 (0x20):
  951. ; bit 6 (0x40):
  952. ; bit 7 (0x80): Set to 1 when cylinder #1 TDC is detected on the CAS falling edge. Set to 1 when we detect that TDC bit on port3.2 has changed from 1 to 0 (falling edge) from one CAS falling edge to the other. That basically indicate cylinder #1 TDC
  953. casCylIndex .EQU $00b4 ; Cas current cylinder index (0,1,2,3 -> cyl #2,#1,#3,#4). Counter looping from 0 to 3 and increased on every CAS falling edge. re-init to 0 when TDC of cylinder #1 is detected (tdcCasFlags.7 set).
  954. ; bit 0 (0x01):
  955. ; bit 1 (0x02):
  956. ; bit 2 (0x04):
  957. ; bit 3 (0x08):
  958. ; bit 4 (0x10):
  959. ; bit 5 (0x20):
  960. ; bit 6 (0x40):
  961. ; bit 7 (0x80):
  962. newInjToAct .EQU $00b5 ; Indicate which injector should be activated (also, bit 7 is set when doing simultaneous injection). Mostly updated on the CAS falling edge
  963. ; bit 0 (0x01): Inj 1?
  964. ; bit 1 (0x02): Inj 3?
  965. ; bit 2 (0x04): Inj 4?
  966. ; bit 3 (0x08): Inj 2?
  967. ; bit 4 (0x10): Inj 5/6?
  968. ; bit 5 (0x20): Inj 5/6?
  969. ; bit 6 (0x40):
  970. ; bit 7 (0x80): Set to 1 when when we should be doing simultaneous injection on all 4 cylinders, 0 indicate sequential injection
  971. tdcCheck .EQU $00b6 ; Init to 8 on the cas falling edge of the cylinder #1 TDC, decremented by 1 on every cas falling edge. Used to check that TDC sensor is working correctly, it should never reach 0...
  972. oldInjToAct .EQU $00b7 ; Old value of injToAct (before it was updated)
  973. injToTest .EQU $00b8 ; The current injector to test for proper operation (set to 1 to test), 1 bit per injector. Testing proceed from bit 0 to bit 3. We stay on the same injector if it is found to be bad, see around L1884
  974. ; bit 0 (0x01): Inj 1?
  975. ; bit 1 (0x02): Inj 3?
  976. ; bit 2 (0x04): Inj 4?
  977. ; bit 3 (0x08): Inj 2?
  978. ; bit 4 (0x10):
  979. ; bit 5 (0x20):
  980. ; bit 6 (0x40):
  981. ; bit 7 (0x80):
  982. injBad .EQU $00b9 ; Injector testing flags
  983. ; bit 0 (0x01): Set to 1 when one of the injector is not working correctly based on injector feedback bit, see injToTest
  984. ; bit 1 (0x02): Not used
  985. ; bit 2 (0x04): Not used
  986. ; bit 3 (0x08): Not used
  987. ; bit 4 (0x10): Not used
  988. ; bit 5 (0x20): Not used
  989. ; bit 6 (0x40): Not used
  990. ; bit 7 (0x80): Not used
  991. obdInjCmd .EQU $00ba ; processing of OBD code bit 0 to 5 correspond to injectors being turned on/off
  992. ; bit 0 (0x01): Inj. 1, Set to 0 if injector is currently turned off by obd command, 1 in normal operation
  993. ; bit 1 (0x02): Inj. 3, See bit 0
  994. ; bit 2 (0x04): Inj. 4, See bit 0
  995. ; bit 3 (0x08): Inj. 2, See bit 0
  996. ; bit 4 (0x10): Inj 5/6 See bit 0
  997. ; bit 5 (0x20): Inj 5/6 See bit 0
  998. ; bit 6 (0x40): Not used
  999. ; bit 7 (0x80): Not used
  1000. rtiCnt .EQU $00bb ; free counter increased on every real time interrupt (~800Hz), used to execute some functions only 1 out of N times (check count value)
  1001. rtiCnt48 .EQU $00bc ; counter increased on every real time interrupt, maximum value is 2F (47), period 48.
  1002. rtiReedFlags .EQU $00bd ; Flag register
  1003. ; bit 0 (0x01): Bit is set in real time int. at 40Hz when T200_40Hz reach 0 (T200_40Hz loop from 5 to 0 at 200Hz)
  1004. ; bit 1 (0x02): not used?
  1005. ; bit 2 (0x04): not used?
  1006. ; bit 3 (0x08): not used?
  1007. ; bit 4 (0x10): not used?
  1008. ; bit 5 (0x20): not used?
  1009. ; bit 6 (0x40): not used?
  1010. ; bit 7 (0x80): Latest reed switch value
  1011.  
  1012. ;-------------------------------------------------
  1013. ; $be-$c2, series of timers (counting down to 0)
  1014. ; (see L1929) decremented in real time interrupt
  1015. ; at ~200Hz
  1016. ;-------------------------------------------------
  1017. T200_40Hz .EQU $00be ; Loops from from 5 to 0 producing 40Hz for main loop (set rtiReedFlags.0)
  1018. T200_casRise .EQU $00bf ; Used by CAS interrupt as a timeout to validate the time in between CAS interrupts when RPM is very low and 16 bit timers roll over. Timer initialized on every cas rising edge
  1019. T200_casFall .EQU $00c0 ; Used by CAS interrupt as a timeout to validate the time in between CAS interrupts when RPM is very low and 16 bit timers roll over. Timer initialized on every cas falling edge
  1020. T200_mas .EQU $00c1 ; Used by the mas subroutine to know when the pulses are getting too close together (and we need to apply scaling). Re-initialized to 130ms on every airflow sensor interrupt (every pulse received)
  1021. T200_cop .EQU $00c2 ; Used to toggle port6.5 if main loop executes at more than 20Hz, could be some sort of COP to reset ECU in case main loop goes slower than 20Hz.
  1022.  
  1023. oldTps1 .EQU $00c3 ; Set to "old" TPS value for comparison with new during cranking?
  1024. vssCnt1 .EQU $00c4 ; Counter Initialized to $c8 every time the reed switch change value, decreased at real time int. frequency down to 0; Will be 0 only when when speed is lower than X (very slow speed?)
  1025. vssCnt2 .EQU $00c5 ; Counter used for speed sensor calculation, initialized to $E2, decreased on every call, speed = $E2-current value of this register
  1026. vss .EQU $00c6 ; "Vehicle speed sensor", actually computed from the reed switch transitions. Value is the period in 1/400sec of one complete reed switch square wave, approx 40cm. Speed in km/h is approximately given by 3.6*400*0.4/xx
  1027. oldTps2 .EQU $00c7 ;
  1028. tpsDiffMax1 .EQU $00c8 ; Maximum positive rate of change of tpsRaw seen during 1 main loop execution. (high value means driver is stepping on the gas, value of 0 means throttle is at constant position or decreasing). Set to the maximum value of tpsRaw-oldTps2 (updated at 100Hz)
  1029. tempFlagTps .EQU $00c9 ; Used as a temp flag during port2.2 activation/deactivation (aiflow sensor active filter reset???). Set to $ff when tpsRaw has increased by more than 1.5% and is between 26%-50%, $00 otherwise
  1030. L00ca .EQU $00ca ; Init to 6 but never used. Notice it is located in front of the 8 memories used to store ADC values? It also correspond to obd code $ca which erases all fault codes...
  1031. ectRaw .EQU $00cb ; Engine coolant temperature, see curve at beginning of file
  1032. iatRaw .EQU $00cc ; Raw intake air temperature, see curve at beginning of file
  1033. baroRaw .EQU $00cd ; Atmostpheric pressure: (.00486x)bar
  1034. o2Raw .EQU $00ce ; Oxygen sensor (.0195x)v.
  1035. egrtRaw .EQU $00cf ; Exhaust gas recirculation temperature, unknown temperature curve, used this formula for now (-2.7x + 597.7)deg F
  1036. battRaw .EQU $00d0 ; Battery voltage (.0733x)v.
  1037. knockSensor .EQU $00d1 ; Knock sensor
  1038. tpsRaw .EQU $00d2 ; Throttle position sensor (100x/255)%
  1039. ectFiltered .EQU $00d3 ; This is the engine coolant tempterature that has been validated and then filtered to limit its rate of change to a few degrees per sec...
  1040. iatChecked .EQU $00d4 ; Validated intake air temperature
  1041. baroChecked .EQU $00d5 ; Verified barometer voltage, $cd=1bar
  1042. state2 .EQU $00d6 ; bit 0 (0x01): Set if ectRaw >236 OR <5, FAULT VALUE = 30
  1043. ; bit 1 (0x02): Set if iatRaw >234 OR <14, FAULT VALUE = 123
  1044. ; bit 2 (0x04): Set if baroRaw >228 OR <100, FAULT VALUE = 205
  1045. ; bit 3 (0x08): Set when timer T40_mas expires, which means no pulse accumulator interrupt was received for over 0.3s-> no air is getting in or something wrong...
  1046. ; bit 4 (0x10): Engine collant temp related?
  1047. ; bit 5 (0x20): Set to 1 if knock senor is not working???. Set to ^(port4Snap.5)
  1048. ; bit 6 (0x40):
  1049. ; bit 7 (0x80):
  1050. port3Snap0 .EQU $00d7 ; Loaded with port3 with some values reset by code depending on ???,
  1051. ; used in idle speed calc? -> load that need to be considered in calc of idle speed
  1052. ; bit 0 (0x01): IG2 related, 0 when IG2 at +12V, ABS unit? only used used for fuel trim on E931 only, see around Md4d4?
  1053. ; bit 1 (0x02): IG1 related? 0 when IG1 at +12V.
  1054. ; bit 2 (0x04): always reset to 0????
  1055. ; bit 3 (0x08): Set to 1 if power steering pump is on
  1056. ; bit 4 (0x10): AC switch (1=off) -> always set if ??? (config resistor???)
  1057. ; bit 5 (0x20): Park/neutral -> always set by code???
  1058. ; bit 6 (0x40): 0 if key in start?
  1059. ; bit 7 (0x80): idle position switch (1=on)?
  1060. port4Snap .EQU $00d8 ; Snapshot of port4 & 01111000
  1061. ; bit 0 (0x01):
  1062. ; bit 1 (0x02):
  1063. ; bit 2 (0x04):
  1064. ; bit 3 (0x08): 1 when ECU test mode terminal grounded
  1065. ; bit 4 (0x10): 1 when timing terminal grounded
  1066. ; bit 5 (0x20): knock sensor related (set indicates it works...)
  1067. ; bit 6 (0x40): Fuel pump driven feedback?
  1068. ; bit 7 (0x80):
  1069. Tclocks .EQU $00d9 ; State Flags for software counters, Updated from scratch (zero) on every main loop execution
  1070. ; bit 0 (0x01): Set at ~40Hz, set when 40Hz flag from real time interrupt was processed during loop (40Hz counters where decremented if required)
  1071. ; bit 1 (0x02): Set at ~10Hz
  1072. ; bit 2 (0x04): Set at ~2Hz, Used by heart beat mode
  1073. ; bit 3 (0x08): Set at ~0.5Hz
  1074. ; bit 4 (0x10): Not used?
  1075. ; bit 5 (0x20): Not used?
  1076. ; bit 6 (0x40): Not used?
  1077. ; bit 7 (0x80): Not used?
  1078. rpm4 .EQU $00da ;:$00db ; RPM/3.90625
  1079. rpm8 .EQU $00dc ; RPM/7.8125
  1080. rpm31 .EQU $00dd ; RPM/31.25 (engine rpm = RPM31p25 * 31.25)
  1081. airVol16 .EQU $00de ;:$00df ; Air volume, 16 bit, airVol16 = [airCnt0:airCnt1] * masScalar/65536
  1082. airVol .EQU $00e0 ; Air volume, 8 bit, airVol = airVol16/2
  1083. airVolT .EQU $00e1 ; Air volume, 8 bit, airVolT = airVol16/2 * iatCompFact/128
  1084. airVolTB .EQU $00e2 ; Air volume, 8 bit, airVolTB = airVol16/2 * iatCompFact/128 * baroFact/128
  1085. airVolB .EQU $00e3 ; Air volume, 8 bit, airVolB = airVol16/2 * baroFact/128
  1086. mafRaw .EQU $00e4 ; 8 bit airflow sensor pulse frequency (6.25x)Hz, calculated from mafRaw16 (mafRaw = mafRaw16/64)
  1087. ftrimFlags .EQU $00e5 ; Flag register for fuel trim???
  1088. ; bit 0 (0x01): c0: c1c0 form the current trim range (00=low, 01=mid, 10=high) updated according to mafRaw16
  1089. ; bit 1 (0x02): c1
  1090. ; bit 2 (0x04): Set (E931 only) when speed exceed threshold (24km/h) with hysteresis,
  1091. ; bit 3 (0x08): Set (E931 only) if port3Snap0.0 & port3.0 are both set on E931 when speed exceed 24km/h?
  1092. ; bit 4 (0x10): Set when rpm > L1983(xx) ~1000rpm with hysteresis
  1093. ; bit 5 (0x20):
  1094. ; bit 6 (0x40):
  1095. ; bit 7 (0x80): Set when airVolT >24, reset when airVolT<=15. Theshold is 19.5 with +/-4.5 hysteresis
  1096. state1 .EQU $00e6 ; State flags mainly used to track engine start-up stages and running condition (not rotating, startingToCrank, etc.). Bits 0 to 4 will be clear when engine is running normally
  1097. ; bit 0 (0x01): stage1 (startingToCrank?): 1 indicate engine is just rotating but no TDC signal seen yet????, reset to 0 once CAS/TDC??? or engine rpm>~400rpm
  1098. ; bit 1 (0x02): no pulse accumulator interrupts ?: 1 indicate we did not receive a valid pulse accumulator interrupts for a long time, see state2
  1099. ; bit 2 (0x04): stage3 (runningFast): 1 indicate the ECU has detected that the engine rpm was too high for current conditions?
  1100. ; bit 3 (0x08): stage2 (rotatingStopInj): 1 indicate engine should be running or be started but something is preventing us from doing fuel injection (fuel cut, CAS not working, etc.). Injection could still proceed if runningFast is set
  1101. ; bit 4 (0x10): stage0 (notRotating): 1 indicate state1 was calculated but nothing to report, set to 1 on init subr. reset to 0 when engine is rotating
  1102. ; bit 5 (0x20): state1Calculated: 1 indicate state 1 was calculated, never reset?
  1103. ; bit 6 (0x40): Not used?
  1104. ; bit 7 (0x80): closedLoop: 1 indicate closed loop mode, 0 indicate open loop
  1105. injFlags0 .EQU $00e7 ; Flags related to injectors
  1106. ; bit 0 (0x01): Flag is 0 on reset (meaning injectors interrupts not yet initiated?) and set to 1 once sInjPw is initialized. If required, first interrupt for injectors is also scheduled when initializing this flag to 1
  1107. ; bit 1 (0x02): ???
  1108. ; bit 2 (0x04): Set when rpm>=437.5
  1109. ; bit 3 (0x08): ???
  1110. ; bit 4 (0x10):
  1111. ; bit 5 (0x20): Set when temperature(ectFiltered) < -8degC, updated only when engine is notRotating
  1112. ; bit 6 (0x40):
  1113. ; bit 7 (0x80): Set to 1 if startingToCrankColdEngine. Fuel should be injected simultaneously in all cylinders twice per rotation (every cas)
  1114. closedLpFlags .EQU $00e8 ; Flags relaed to closed loop mode, 02 sensor, fuel trims
  1115. ; bit 0 (0x01): Set to 1 when the air volume (airVolTB) is too high to use closed loop mode (first threshold)
  1116. ; bit 1 (0x02): Set to 1 when we should be using closed loop mode??? (might not use it anyway...)
  1117. ; bit 2 (0x04):
  1118. ; bit 3 (0x08):
  1119. ; bit 4 (0x10):
  1120. ; bit 5 (0x20):
  1121. ; bit 6 (0x40): o2 sensor bad flag. Set to 1 when the o2 sensor voltage did not switch from lean to rich or rich to lean for a certain amount of time in closed loop. Also set to 1 if notRotating
  1122. ; bit 7 (0x80): rich/lean flag, set to 1 o2Raw >= 0.6v (rich), Set to 0 if o2Raw < 0.6v (lean), updated once o2 sensor has warmed-up
  1123. o2Fbk .EQU $00e9 ;:$00ea ; Oxygen feedback trim (16 bits actually used, most of the time only highest byte is used...) (.78x)% -> 100% = $80
  1124. o2Fbk_dec .EQU $00eb ; o2Fbk is decreased using this value when in closed loop and running rich
  1125. o2Fbk_inc .EQU $00ec ; o2Fbk is increased using this value when in closed loop and running lean
  1126. iscY0 .EQU $00ed ; iscYn variables are short term correction factors/feedback for the isc step adjustment. It is centered at $80 (100%, no correction). A value higher than $80 indicate that we need to increase the isc step since the current rpm is lower than the desired one
  1127. ; The isc step used is increased/decreased by iscYn-$80
  1128. ; iscY0 is the ISC learning variable when A/C is off and PS is off, see iscPointers function. Value of $80=100%
  1129. iscY1 .EQU $00ee ; iscY1 is the ISC learning variable when A/C is on and PS is off, see iscPointers function. Value of $80=100%
  1130. iscY2 .EQU $00ef ; iscY2 is the ISC learning variable when PS is on, see iscPointers function. Value of $80=100%
  1131. iscStepMax .EQU $00f0 ; Maximum value applied to iscStepCurr in code
  1132. port3Snap1 .EQU $00f1 ; Loaded with port3Snap0 with some values set by code depending on ???,
  1133. ; bit 0 (0x01): IG2 related, 0 when IG2 at +12V, ABS unit? only used used for fuel trim on E931 only, see around Md4d4?
  1134. ; bit 1 (0x02): IG1 related? 0 when IG1 at +12V.
  1135. ; bit 2 (0x04): Set to 1 if vssCnt1 != 0 (car speed > 2.9km/h???)
  1136. ; bit 3 (0x08): Set to 1 if power steering pump is on
  1137. ; bit 4 (0x10): AC switch (1=off)
  1138. ; bit 5 (0x20): Park/neutral -> always set by code
  1139. ; bit 6 (0x40): 0 if key in start?
  1140. ; bit 7 (0x80): idle position switch (1=on)?
  1141. oldP3Snap1 .EQU $00f2 ; Old value of port3Snap1
  1142. iscLrnFlags .EQU $00f3 ; Isc leanrning flags, all flags are reset to 0 in basic idle speed adjustment mode. All flags except bit 0 are reset to 0 when notRotating or startingToCrank
  1143. ; bit 0 (0x01): Set to 1 when engine is notRotating or startingToCrank, reset to 0 when engine is running
  1144. ; bit 1 (0x02):
  1145. ; bit 2 (0x04): Set to 1 when the engine is running too slow? i.e. temperature(ectFiltered) > 55degC, rpm8 < 500rpm, engine is running, T40_acOnTrans is expired
  1146. ; bit 3 (0x08):
  1147. ; bit 4 (0x10): Set to 1 when conditions are good to update the isc leanrning variables.
  1148. ; bit 5 (0x20): Set to 1 when iscStStall has been updated, i.e. when idle switch is off and iscFlags1.7 = 0 and rpm8>=500. Reset to 0 when iscStStall is reset to 0???
  1149. ; bit 6 (0x40):
  1150. ; bit 7 (0x80):
  1151. iscFlags1 .EQU $00f4 ; Flag register
  1152. ; bit 0 (0x01): Set to 1 when engine not rotating or is running (basic idle speed adjustment mode is not active). Reset to 0 when key in start and iscStTargSpec = iscStepCurr
  1153. ; bit 1 (0x02):
  1154. ; bit 2 (0x04):
  1155. ; bit 3 (0x08):
  1156. ; bit 4 (0x10):
  1157. ; bit 5 (0x20): Set to 1 when engine StartingToCrank and temperature(iat) < 75degC. Only changed during startingToCrank. Used is setting isc step during cold engine startup
  1158. ; bit 6 (0x40):
  1159. ; bit 7 (0x80): Set to 1 when tps has been high and airVol low for more than 0.5sec (tpsRaw >= 86% and airVol < $3a)
  1160. T_maxAdv .EQU $00f5 ; E931 only, used to ramp down the effect of maxAdv
  1161. maxAdv .EQU $00f6 ; E931 only, maximum value of timing advance timingOct for E931 when engine is runningFast (timingOct is clipped to that value), T_maxAdv is used to ramp-down its effect with time
  1162. L00f7 .EQU $00f7 ; Unused?
  1163. varFlags0 .EQU $00f8 ; Various flags...
  1164. ; bit 0 (0x01): Used in A/C cutoff for AT, 1 indicates TPS exceeded 82% the last time we checked it...
  1165. ; bit 1 (0x02): Hot start flag, set to 1 when startingToCrank and open loop and temperature(iatChecked) >= 60degC and temperature(ectFiltered) >= 93degC (hot start), used to increase fuel enrichement (reduce vapor lock maybe???)
  1166. ; bit 2 (0x04):
  1167. ; bit 3 (0x08):
  1168. ; bit 4 (0x10):
  1169. ; bit 5 (0x20): Second priority, Set to 1 when purge solenoid is to be deactivated since min conditions for normal purge activation are not met
  1170. ; bit 6 (0x40): First priority, Set to 1 when purge solenoid is to be activated by OBD command or normal activation criteria
  1171. ; bit 7 (0x80): Third priority, Set to 1 when purge solenoid should be deactivated. This flag is toggled between 0 and 1 to implement pulsewidth modulation (very long period) of purge solenoid when the other two higher priority flags are not set
  1172. fpsBcsFlags .EQU $00f9 ; Flags related to fuel pressure solenoid and boost control solenoid
  1173. ; bit 0 (0x01):
  1174. ; bit 1 (0x02):
  1175. ; bit 2 (0x04): Set to 1 when the fuel pressure solenoid was just deactivated (set to 1 only when bit 7 goes from 1 to 0). Reset to 0 at any other time
  1176. ; bit 3 (0x08): Set to 1 when ECU decides that fuel pressure solenoid should be activated to reduce vapor lock
  1177. ; bit 4 (0x10): bcs, Set to 1 when mafRaw16 is above $4e ($4a for E932) with hysteresis, low threshold is $38
  1178. ; bit 5 (0x20): bcs, Set to 1 when octane is above $c0 with hysteresis, low threshold is $9a
  1179. ; bit 6 (0x40): bcs
  1180. ; bit 7 (0x80):
  1181. obdFlags .EQU $00fa ; Current state of diagnostic port command/query processing
  1182. ; bit 0 (0x01): 1 toggle bit on every second "subroutine 1" loop
  1183. ; bit 1 (0x02): 1 if serial output on port 2 is initialized.
  1184. ; bit 2 (0x04): ?
  1185. ; bit 3 (0x08): ?
  1186. ; bit 4 (0x10): ?
  1187. ; bit 5 (0x20): ?
  1188. ; bit 6 (0x40): Set to 1 when a new OBD code was stored in obdCode? reset when obdCode has been processed.
  1189. ; bit 7 (0x80): Set to 1 to indicate that a response to the query/command is being sent on the diagnostic port (new requests will be ignored)
  1190. obdActCmd .EQU $00fb ; processing of OBD code, contains which actuator is being currently processed. Set to 0 when actuator is off
  1191. ; bit 0 (0x01): Purge solenoid
  1192. ; bit 1 (0x02): Fuel pump
  1193. ; bit 2 (0x04): Fuel pressure solenoid
  1194. ; bit 3 (0x08): Egr solemoid
  1195. ; bit 4 (0x10): Unused
  1196. ; bit 5 (0x20): Boost control solenoid
  1197. ; bit 6 (0x40): Unused
  1198. ; bit 7 (0x80): Unused
  1199. validFlags .EQU $00fc ; Flag related to the validation of sensors...
  1200. ; bit 0 (0x01): Set to 1 when T40_engRot is expired (no CAS interrupt received for a long time)
  1201. ; bit 1 (0x02): Set to 1 when the condition of the o2 sensor was determined (good or not). Only reset when car key is put in off I think
  1202. ; bit 2 (0x04): Set to 1 when the condition of the egrt sensor was determined (good or not). Only reset when car key is put if off I think
  1203. ; bit 3 (0x08):
  1204. ; bit 4 (0x10):
  1205. ; bit 5 (0x20):
  1206. ; bit 6 (0x40):
  1207. ; bit 7 (0x80): Set to 1 if o2Raw > 0.6V (rich), 0 otherwise
  1208. iscStepTarg .EQU $00fd ; Target ISC step, that's the target value for iscStepCurr
  1209. idleSpdTarg .EQU $00fe ; Current target idle speed (xx*7.8125)rpm based on ect, A/C switch, etc.
  1210. airCntDef .EQU $00ff ; airCntDef*8*256 is the default value of [airCnt0:airCnt1:airCnt2] when mas interrupts are not being received, calculated from rpm, tps, ect, tables
  1211. injPwStart .EQU $0100 ;:$0101 ; The value of injPw used when engine is "rotating" (start-up). Calculated from fixed values (no air count)
  1212. oldFtrimFlg .EQU $0102 ; Old value of ftrimFlags
  1213. accEnrDecay .EQU $0103 ; Acceleration enrichment decay factor. accEnr is multiplied by (1-accEnrDecay/256) on each iteration. Initialized from a table as a function of ect.
  1214. accEnrTimer .EQU $0104 ; Timer used to continue applying acceleration enrichement for 4 iterations after airflow is below minimum threshold (accEnrMinAf).
  1215. accEnrMinAf .EQU $0105 ;:$0106 ; Minimum value of airCnt0 above/below which acceleration/deceleration enrichment should be applied (for acceleration, when airflow goes below, we stop applying acc enrichment after 4 iterations, see accEnrTimer. For decelaration, we stop reducing injPw as soon as we are above threshold)
  1216. decEnr .EQU $0107 ; Deceleration enrichment (100x/255)%. This value is actually updated with min(airCnt0-oldAirCnt0,$ff) under deceleration, see code. Max value is $ff from code
  1217. accEnrFact .EQU $0108 ;:$0109 ; Factor used in increasing injPw during acceleration enrichment
  1218. decEnrFact .EQU $010a ;:$010b ; Factor used in decreasing injPw during deceleration enrichment
  1219. accEnrDiffT .EQU $010c ; Minimum value of (airCnt0-oldAirCnt0) required to update decEnr or accEnr
  1220. accEnrTmr2 .EQU $010d ; Timer used to hold accEnr for 4 or 5 iterations when it is getting small, before decreasing it to 0.
  1221. oldTps3 .EQU $010e ; Old value of tpsRaw calculated at 100Hz, used to compute tpsDiff100
  1222. tpsDiff100 .EQU $010f ; Used to interpolate t_sInjEnr. Correspond to max(tpsRaw-oldTps3,0) calculated at 100Hz, used in the calculation of sInjEnr.
  1223. T200s_sInj .EQU $0110 ; sInjEnr is reset to 0 when this timer expires (0.2sec after conditions don't warrant having sInjEnr anymore)
  1224. sInjEnr .EQU $0111 ; Kind of acceleration fuel enrichement when still using simultaneous injection?
  1225. sInjEnrMax .EQU $0112 ; Maximum value applied to sInjEnr
  1226. sInjTpsMax .EQU $0113 ; sInjEnr is only increased if oldTps3 <= sInjTpsMax
  1227. sInjPw .EQU $0114 ;:$0115 ; Injector pulsewidth used when simulataneous injection is used
  1228. sInjEnrInc .EQU $0116 ; sInjEnr is increased by sInjEnrInc/128 * t_sInjEnr(tpsDiff100) = sInjEnrMax/32 * t_sInjEnr(tpsDiff100) at 100Hz under specific scenario
  1229.  
  1230. ;----------------------------------------------------
  1231. ; $117-$132, series of software timers (counting down to 0)
  1232. ; decremented in subroutine 4 at ~40Hz
  1233. ;----------------------------------------------------
  1234. T40_2hz .EQU $0117 ; set to $14 on init and loop at $14 (produces 2Hz)
  1235. T40_0p5hz .EQU $0118 ; set to $50 on init and loop at $50 (produces 0.5Hz)
  1236. T40_start .EQU $0119 ; Set to $ff when key in start, start counting when key no more in start?
  1237. T40_crank .EQU $011a ; Set to $ff when startingToCrank, starts counting when engine is no more startingToCrank (engine running or other state...)
  1238. T40_baro .EQU $011b ; Used to ignore barometric sensor input if battery<8V and 0.35s after battery>8V (baro sensor sensitive to voltage...). Sensor is ignore when timer is not 0
  1239. T40_stInj0 .EQU $011c ; Starts counting from 1 sec when rotatingStopInj flag is activated. Used to activate T40_stInj1
  1240. T40_stInj1 .EQU $011d ; Initialized to 2 sec when T40_stInj0 expires (ongoing rotatingStopInj for more than 1sec) starts counting when rotatingStopInj is deactivated. This timer is therefore non-zero 1 sec after rotatingStopInj starts and 2 sec after is stops
  1241. T40_o2Fbk .EQU $011e ; Timer will only be 0 when the low trim range will have been selected for more than 4 sec. Used to eventually calculate o2Fbk_dec,o2Fbk_inc, how fast o2 feedback is adjusting...
  1242. T40_ftrim2 .EQU $011f ; Used on E931 as an additional condition to update fuel trims
  1243. T40_engRot .EQU $0120 ; Kind of an "engine rotating" flag, This timer is re-initialized to 0.6s or 1.2s on every CAS interrupt, will reach 0 only if no CAS int. is received (engine not rotating or very slowy) for more than that time (rpm<0.83/K???)
  1244. T40_mas .EQU $0121 ; This timer is periodically initialized to 12 (0.3s) and will reach 0 only if no mas interrupt is received for that long (no air is getting in or something is wrong...)
  1245. T40_fuelCut .EQU $0122 ; Fuel cut timer, fuel cut is applied only when this timer reach 0: After air flow threshold is exceeded for more than 1s
  1246. T40_ftrim .EQU $0123 ; Fuel trim update timer. Fuel trim are not updated unless this timer is expired (=0). It is set to 5 sec when condition are stable, i.e. fuel trim are update only after conditions are stable for more than 5 sec
  1247. T40_noPower .EQU $0124 ; Timer is init at 0.125sec on every loop when ECU receives power? Will reach 0 when the ECU is about to turn-off (ECU relay turns-off after a few seconds...)
  1248. T40_revving .EQU $0125 ; Timer used in updating iscStStall. Re-init to 0.5sec if tpsRaw < 86% or airVol >= $3a. Timer will start counting when tpsRaw>86% and airVol < $3a and will expire 0.5sec later. Keeps track of rapid throttle plate opening in stalling calculations???
  1249. T40_iscLrn .EQU $0126 ; Timer looping at 40 (produces 1 Hz) used to update isc0/isc1 and iscY1/iscY2/iscY3 at 1Hz (isc learning...)
  1250. T40_stall .EQU $0127 ; Used to update iscStStall at ~2Hz
  1251. T40_acOnTrans .EQU $0128 ; Used to filter out (0.1sec) the impact of A/C being turned-on (transcient load) when evaluating whether the engine is running too slow (<500rpm)
  1252. T40_iscStart .EQU $0129 ; Used to decrement iscStStartMaster as a function of time upon engine startup
  1253. T40_checkTargRpm .EQU $012a ; Timer used to schedule every 1sec the comparison between current rpm to target rpm and adjust isc if necessary
  1254. T40_iSpAdj .EQU $012b ; Timer is 0 when Idle speed adjustment mode is active. Set to 0.2sec after both timing adjustment and ECU test mode terminals are grounded. i.e. idle speed adjustement mode is applied 0.2sec after terminals are grounded...
  1255. T40_21 .EQU $012c ; For E932, used to decrement iscStBaseAcAdj at 2.22Hz
  1256. T40_obdCmd .EQU $012d ; Implement the processing of OBD command code, set to $f0 (6 seconds at 40Hz) if an injector is off or an actuator on
  1257. T40_acOn .EQU $012e ; Implement min time before engaging A/C clutch after A/C button is pressed
  1258. T40_acOnRpm .EQU $012f ; Implement min time before engaging A/C clutch after RPM > 438 (after car is started-up)
  1259. T40_acCut .EQU $0130 ; Implement the 5s A/C cutoff when TPS goes above (and stays above) 82% in AT (5 sec countdown)
  1260. T40_26 .EQU $0131 ; Unused (but decremented...)
  1261. T40_27 .EQU $0132 ; Unused (but decremented...)
  1262.  
  1263.  
  1264. ;-----------------------------------------
  1265. ; Software timer at ~40Hz decremented individually
  1266. ;-----------------------------------------
  1267. T40s_Idle .EQU $0133 ; Only decremented under some specific conditions, init with $1e(0.75s) when idle switch is off, will reach 0 when idle switch has been on for more than 0.75s, used to condition idle flag with A/C switch.
  1268.  
  1269. ;----------------------------------------------------
  1270. ; $134-$13f, series of software timers (counting down to 0)
  1271. ; decremented in subroutine 4 at ~2Hz
  1272. ;----------------------------------------------------
  1273. T2_crank .EQU $0134 ; Set to $ff when startingToCrank, starts counting when engine is no more startingToCrank (engine running or other state...)
  1274. T2_EcuPower .EQU $0135 ; Starts counting from $ff when the ECU receives power, used to blink the "check engine" light when the ECU is turned on.
  1275. T2_closedLp .EQU $0136 ; Used to prolong closed loop mode when we go over an airVolTB threshold for a short period of time, Init to 12sec or 20sec
  1276. T2_o2Sensor .EQU $0137 ; Used to validate the o2 sensor voltage. If timer expires with the o2 sensor voltage never switching (rich/lean) then o2 sensor is not working correctly...
  1277. T2_hotEnrich .EQU $0138 ; Used for fuel enrichement during 120sec after starting engine under very hot intake air temperature (reduce vapor lock???)
  1278. T2_airVolT .EQU $0139 ; Set to 5 sec whenever airVolT>24. Will expire once airVolT<=15 for more than 5sec
  1279. T2_6 .EQU $013a ; Unused? (but decremented...)
  1280. T2_snsrChk .EQU $013b ; Sensor is flagged as bad only when it has been consistently been tested as bad for 4sec. T2_snsrChk implement that 4sec. Initialized to 4 sec everytime sensrChkIdx is reset to 0
  1281. T2_o2Chk .EQU $013c ; Used in o2 sensor testing/validation. re-initialized to 30sec as long as all the testing pre-conditions are not met or as long as we are running rich. Starts counting when we are running lean and pre-conditions are met...
  1282. T2_egrtChk .EQU $013d ; Used in egrt sensor testing/validation.
  1283. T2_stCrank .EQU $013e ; Init to $ff when startingToCrank or when engine just started rotating, starts counting after state change
  1284. T2_11 .EQU $013f ; Unused? (but decremented...)
  1285.  
  1286. ;---------------------------------------------------
  1287. ; 140-144, series of software timers (counting down to 0)
  1288. ; decremented in subroutine 4 at ~0.5Hz
  1289. ;---------------------------------------------------
  1290. T0p5_crank1 .EQU $0140 ; Set to $ff when startingToCrank, starts counting when engine is no more startingToCrank (engine running or other state...)
  1291. T0p5_crCold .EQU $0141 ; Basically not null for 120sec after a cold engine is being cranked/started. Initialized to 120sec when startingToCrank and temperature(ectFiltered) <= 88degC or to 0 if startingToCrank and temperature(ectFiltered) >88degC. Never updated otherwise. Starts counting when we are not startingToCrank. Reset to 0 when notRotating.
  1292. T0p5_purge .EQU $0142 ; Used to implement pulsewidth modulation of the purge solenoid (if some conditions are met), period is very long, 236sec
  1293. T0p5_crank2 .EQU $0143 ; Similar to T0p5_crank1
  1294. T0p5_ect .EQU $0144 ; Reloaded with 5 min on every loop. Starts counting from 5 min only when ect equals exactly 41degC, used in ECT sensor fault routine. Since ect should not stay at that temp for long, counter should never reach 0???
  1295.  
  1296. Tcas .EQU $0145 ;:$0146 ; Tcas (125KHz clock, half the real clock...) is the time(s) per cas interrupt * 125000, rpm = 60/(2*Tcas/125000), Tcas = 60/(2*rpm/125000) (there are 4 cas interrupt for every 2 engine rotations). Tcas is calculated from [TcasLast0:TcasLast1]/2
  1297. TcasOld .EQU $0147 ;:$0148 ; previous value of Tcas
  1298. airDiffPos1 .EQU $0149 ; airDiffPos is transfered to it in subroutine 1
  1299. airDiffNeg1 .EQU $014a ; airDiffNeg is transfered to it in subroutine 1
  1300. mafRaw16 .EQU $014b ;:$014c ; 16 bit mafRaw, Airflow sensor pulse frequency (x/10.24)Hz, calculated from filtered air count (airCnt0:airCnt1) and rpm
  1301. tpsDiffMax2 .EQU $014d ; Value tpsDiffMax1 is transfered here on every main loop execution
  1302. ectCond .EQU $014e ; Conditionned ect for table interpolation, calculated from ectFiltered, see around L1035
  1303. iatCond .EQU $014f ; Condtionned intake air temperature -> validated and offset/clipped = max(min(iatChecked,$e0)-$20,0)
  1304. airVolCond .EQU $0150 ; Conditionned airVol used in table interpolation
  1305. rpmIndex1 .EQU $0151 ; Set to min(max(RPM31p25-500rpm,0),4500rpm), used in 2D interpolation of t_egrDutyFact (column)
  1306. baroCond .EQU $0152 ; Conditionned barometric pressure, non-linear range of $00 to $80 (0.45bar to 0.92bar): 1:1 from $00 to $40 and 2:1 from $40 to $80
  1307. injMasComp .EQU $0153 ;:$0154 ; totMasComp*16 * injComp/128
  1308. totMasComp .EQU $0155 ;:$0156 ; Total mas compensation factor, (masComp+t_masComp(xx))* masLinComp/128
  1309. masLinComp .EQU $0157 ; Interpolated t_masLin, compensate for airflow sensor non-linearity as a function of iat, baro and airflow sensor frequency
  1310. L0158 .EQU $0158 ; Not used????
  1311. openLoopEnr .EQU $0159 ; Open loop enrichement factor, based on timing/knock fuel enrichment conditionned on tps and timer based enrichement
  1312. o2FuelAdj .EQU $015a ; Factor to increase/reduce fuel depending on o2 sensor voltage/feedback, value from 0 to 255, $80=100%->no fuel adjustment. o2FuelAdj = o2Fbk +/- t_closedLpV1(xx) or t_closedLpV2(xx)
  1313. workFtrim .EQU $015b ; Working fuel trim, the fuel trim selected according to current fuel trim range
  1314. coldTempEnr .EQU $015c ; Fuel enrichement factor for cold engine under low airflow conditions, Value of $80=100% means no enrichement
  1315. enrWarmup .EQU $015d ; Current fuel enrichment during warmup/startup, enrichement factor = (2*enrWarmup+$80)/$80
  1316. T_enrWarm .EQU $015e ; Counter used to lower enrWarmup as a function of time down to 0
  1317. iatCompFact .EQU $015f ; Air density factor as a function of temperature ($80=1.0)
  1318. baroFact .EQU $0160 ; Barometric pressure factor, pressure=(baroFact/128)bar
  1319. timFuelEnr .EQU $0161 ; Fuel enrich based on knock/timing??? (Temporarily the timing map value)
  1320. T40s_iscStable .EQU $0162 ; Timer is re-initialized to various values (highest of new and current is kept) every time a ISC impacting load is detected (i.e power steering pump is turned on). Timer is decremented only when iscStepTarg=iscStepCurr, i.e. idle speed target is reached.
  1321. ; It will therefore reach 0 only when the ISC step has reached its target and stayed there for a while, ISC is stable...
  1322. iscStStall .EQU $0163 ; This is the minimum isc step to use when the idle switch transition from off to on. It is decreased by 3 at ~20Hz???. I suppose this is to smooth the rapid change of airflow when the throttle plate closes and reduce the possibility of stalling the engine
  1323. iscStStartUsed .EQU $0164 ; This is the current value of the offset to add to base isc step when the engine was just started. It is slowly decreased (following iscStStartMaster) until the isc step stabilizes. It then stays constant. Whatever value remains after stabilization is used to update iscYn learning variables
  1324. iscLowBatt .EQU $0165 ; Keep track of battery condition for ISC spindle updating. Bit 7 is set when battRaw >= 10V (with hysteresis). 2 lower bits used as counter (3 max) as to how many consecutive times battRaw >= 10V, ISC spindle is not moved until this counter is $03
  1325. iscStTargSpec .EQU $0166 ; The value that will be stored in iscStepTarg when the engine is runnning but iscLrnFlags.1 is set
  1326. iscStBase .EQU $0167 ; Basic ISC step as a function of ECT
  1327. iscStBaseAc .EQU $0168 ; iscStBase corrected for A/C and transmission load
  1328. iscStBaseCSt .EQU $0169 ; iscStBase corrected for cold start period, i.e. high ISC step at start and then decreasing towards iscStBase over 120sec. Set to 0 after 120sec
  1329. iscStBarOff .EQU $016a ; Offset to add to the basic ISC step to compensate for barometric pressure
  1330. iscStBaseAcAdj .EQU $016b ; For E932, used to adjust iscStBaseAc when transmission is engaged, i.e. drive, decremented down to 0 at 2.22Hz...
  1331. idleSpdInit .EQU $016c ; Preliminary idle speed target (xx*7.8125)rpm, t_idleSpd(ect) or t_idleSpdDr(ect), used in the computation of idleSpdTarg
  1332. idleSpdMin .EQU $016d ; Minimum idle speed target (xx*7.8125)rpm, used in the computation of idleSpdTarg
  1333. L016e .EQU $016e ; Unused?
  1334. advTotal .EQU $016f ; Sum of the timing (xx-10)degrees BTDC from the timing maps (timingOct) and of three other timing corrections (advEct-$80, advIat-$80, advRpm-$80)
  1335. timingOct .EQU $0170 ; Base timing (xx-10)degrees corrrected for octane: timingOct = alpha * t_timingHiOct(rpm, load) + (1-alpha) * t_timingLoOct(rpm, load) where alpha = octane/255
  1336. advEct .EQU $0171 ; Ect based timing correction (xx-$80)degrees
  1337. advIat .EQU $0172 ; Iat based timing correction (xx-$80)degrees
  1338. advRpm .EQU $0173 ; Rpm based timing correction (xx-$80)degrees
  1339. coilChkCnt .EQU $0174 ; Used to set an error flag if the ignition coil sensing circuit shows that the ignition is not working properly
  1340. coilHist .EQU $0175 ; coilHist basically contains the ignition coil sensing circuit history (0 or 1 from port4.2) for the last 8 CAS interrupts, bit 7 being the oldest and bit 0 the newest
  1341. T40s_octane .EQU $0176 ; octane timer decremented at 40Hz and looping at $10. octane is updated when timer reaches 0 (at 2.5Hz total)
  1342. knockTimer .EQU $0177 ; Used in the validation of the raw knock sensor voltage received from the ADC
  1343. egrtTimerThr .EQU $0178 ; Timer threshold (compared to T0p5_crank2) used to decide whether enough time has elapsed to test the egrt sensor (180sec or 360sec), threshold is ect based
  1344. sensrChkIdx .EQU $0179 ; The current index in table t_snsrChk indicating which sensor is to be checked/tested next.
  1345. obdCode .EQU $017a ; Contain the latest code received from OBD connector
  1346. errCodeIdx .EQU $017b ; Processing of diagnoctic port error code output (heart beat mode),
  1347. ; c4:c3:c2:c1:c0 is the index of the current error being output
  1348. ; d2:d1:d0 are used as a small 2Hz timer to produce the "heart beat"...
  1349. ; bit 0 (0x01): c0
  1350. ; bit 1 (0x02): c1
  1351. ; bit 2 (0x04): c2
  1352. ; bit 3 (0x08): c3
  1353. ; bit 4 (0x10): c4
  1354. ; bit 5 (0x20): d0
  1355. ; bit 6 (0x40): d1
  1356. ; bit 7 (0x80): d2
  1357. errCodeProc .EQU $017c ; Loaded with the error code (t_snsrChkCode) being output to the test connector (heart beat mode) and then updated as the code is being output.
  1358. ; bit 0 (0x01): a0 a3:a2:a1:a0 is the number of short pulse left to output to connector
  1359. ; bit 1 (0x02): a1
  1360. ; bit 2 (0x04): a2
  1361. ; bit 3 (0x08): a3
  1362. ; bit 4 (0x10): b0 b2:b1:b0 is the number of long pulse left to output to connector
  1363. ; bit 5 (0x20): b1
  1364. ; bit 6 (0x40): b2
  1365. ; bit 7 (0x80): c0 Set to 1 when a new code is loaded, reset to 0 at midpoint between long and short pulses
  1366. egrDuty128 .EQU $017d ; EGR solenoid Duty cycle value from 0 to $80 produces 0 to 100% (not sure of correspondance)
  1367. egrDuty .EQU $017e ; EGR solenoid Duty cycle (48-value)/48, value of table at FF88 interpolated by ECT
  1368. bGaugeODuty .EQU $017f ; Boost gauge "off-duty" cycle, value between $00 and $18, $00 corresponding to the maximum of the boost gauge scale
  1369. T40s_bcs .EQU $0180 ; bcs timer, decremented at 40Hz, loops at $14 (20), bcs duty cycle is updated when this timer reaches 0 (at 2Hz)
  1370. bcsDuty .EQU $0181 ; bcs duty cycle, duty cycle = (48-value)/48
  1371. T40s_tps .EQU $0182 ;
  1372. ectStCrank .EQU $0183 ; Loaded with ectFiltered when engine is startingToCrank, used in ect sensor check
  1373. rpmX4Filt .EQU $0184 ;:$0185 ; Filtered version of 16*rpm4 (xx*16/3.90625)rpm. Filtering is achieved using exponential averaging with alpha = 0.90625
  1374. injCount .EQU $0186 ; Used in the calculation of injPwStart. Incremented by 1 (255 max) every time injPw !=0 in interrupt rountine (fuel is injected)
  1375. airCntMin0 .EQU $0187 ; [airCntMin0:airCntMin1] is the minimum value of [airCntNew0:airCntNew1] before it is used for airCnt0 calcuations
  1376. airCntMin1 .EQU $0188 ; See airCntMin0
  1377.  
  1378.  
  1379. ;------------------------------------------------------------
  1380. ; Unused memory block, except for iscStStartMaster
  1381. ;
  1382. ; Also provides a buffer space in case of stack overflow...
  1383. ; Memories should always be 0 else it means the stack
  1384. ; overflowed in this region...
  1385. ;------------------------------------------------------------
  1386. L0189 .EQU $0189 ;
  1387. L018a .EQU $018a ;
  1388. L018b .EQU $018b ;
  1389. L018c .EQU $018c ;
  1390. iscStStartMaster .EQU $018d ; This is the master isc step offset used upon engine startup. It is initialized with a value from table and then decreased as a function of time down to 0. See iscStStartUsed for more details...
  1391. L018e .EQU $018e ;
  1392. L018f .EQU $018f ;
  1393. L0190 .EQU $0190 ; Memory cleared up to (and including) here
  1394. ramClearEnd .EQU $0190 ;
  1395.  
  1396. ;--------------------------------------------
  1397. ; Memory below is reserved for the stack
  1398. ;--------------------------------------------
  1399. L0191 .EQU $0191 ;
  1400. L0192 .EQU $0192 ;
  1401. L0193 .EQU $0193 ;
  1402. L0194 .EQU $0194 ;
  1403. L0195 .EQU $0195 ;
  1404. L0196 .EQU $0196 ;
  1405. L0197 .EQU $0197 ;
  1406. L0198 .EQU $0198 ;
  1407. L0199 .EQU $0199 ;
  1408. L019a .EQU $019a ;
  1409. L019b .EQU $019b ;
  1410. L019c .EQU $019c ;
  1411. L019d .EQU $019d ;
  1412. L019e .EQU $019e ;
  1413. L019f .EQU $019f ;
  1414. L01a0 .EQU $01a0 ;
  1415. L01a1 .EQU $01a1 ;
  1416. L01a2 .EQU $01a2 ;
  1417. L01a3 .EQU $01a3 ;
  1418. L01a4 .EQU $01a4 ;
  1419. L01a5 .EQU $01a5 ;
  1420. L01a6 .EQU $01a6 ;
  1421. L01a7 .EQU $01a7 ;
  1422. L01a8 .EQU $01a8 ;
  1423. L01a9 .EQU $01a9 ;
  1424. L01aa .EQU $01aa ;
  1425. L01ab .EQU $01ab ;
  1426. L01ac .EQU $01ac ;
  1427. L01ad .EQU $01ad ;
  1428. L01ae .EQU $01ae ;
  1429. L01af .EQU $01af ;
  1430. L01b0 .EQU $01b0 ;
  1431. L01b1 .EQU $01b1 ;
  1432. L01b2 .EQU $01b2 ;
  1433. L01b3 .EQU $01b3 ;
  1434. L01b4 .EQU $01b4 ;
  1435. L01b5 .EQU $01b5 ;
  1436. L01b6 .EQU $01b6 ;
  1437. L01b7 .EQU $01b7 ;
  1438. L01b8 .EQU $01b8 ;
  1439. L01b9 .EQU $01b9 ;
  1440. L01ba .EQU $01ba ;
  1441. L01bb .EQU $01bb ;
  1442. L01bc .EQU $01bc ;
  1443. L01bd .EQU $01bd ;
  1444. L01be .EQU $01be ;
  1445. stack .EQU $01bf ; Top of stack location(grows backward (push-> SP=SP-1)
  1446.  
  1447.  
  1448.  
  1449. ;***************************************************************
  1450. ;*
  1451. ;*
  1452. ;* Unused/Unavailable memory?
  1453. ;*
  1454. ;*
  1455. ;***************************************************************
  1456. empty1 .EQU $01C0 ;:$01FF
  1457.  
  1458.  
  1459.  
  1460. ;******************************************************************
  1461. ;
  1462. ;
  1463. ; 32KB chip address range start
  1464. ;
  1465. ;
  1466. ;******************************************************************
  1467. epromStart .org $8000
  1468.  
  1469.  
  1470.  
  1471. ;******************************************************************
  1472. ;
  1473. ;
  1474. ; Battery gauge code
  1475. ;
  1476. ; 0psi boost ~12.14V ~ 40% duty
  1477. ;
  1478. ;
  1479. ;
  1480. ;******************************************************************
  1481. .fill newCode-$, $ff
  1482. newCode .org $CB00
  1483. #ifdef batteryGauge
  1484. battGauge ldab battRaw ; b=battery voltage
  1485. subb #$8C ; remove 10.262V
  1486. lsrb ;
  1487. lsrb ;
  1488. tba ;
  1489. lsrb ;
  1490. aba ;
  1491. tab ; b = 3/8*(Vbatt-10.262v), gives a effective range of 10.262V to 14.95V (0 to 24 in boost gauge range)
  1492. rts
  1493. #endif
  1494.  
  1495.  
  1496.  
  1497. ;******************************************************************
  1498. ;
  1499. ;
  1500. ; Empty space
  1501. ;
  1502. ;
  1503. ;******************************************************************
  1504. .fill codeStart-$, $ff
  1505.  
  1506.  
  1507.  
  1508. ;******************************************************************
  1509. ;
  1510. ;
  1511. ; Start of code after reset
  1512. ;
  1513. ;
  1514. ;******************************************************************
  1515. codeStart .ORG $ceff-codeOffset
  1516. jmp reset
  1517.  
  1518.  
  1519. ;******************************************************************
  1520. ;
  1521. ;
  1522. ; Empty space
  1523. ;
  1524. ;
  1525. ;******************************************************************
  1526. empty2 .fill obdTable-empty2, $ff
  1527.  
  1528.  
  1529.  
  1530. ;******************************************************************
  1531. ;*
  1532. ;* OBD interface queries, commands
  1533. ;*
  1534. ;* Codes from $00 to $3d: Regular queries, return the value of the
  1535. ;* variables showed in obdTable located below,
  1536. ;* see each variable definition... First value in table
  1537. ;* correspond to obd query code $00, increases by 1
  1538. ;* for each table value
  1539. ;*
  1540. ;* Codes from $3e to $3f: Converted to $3d, see that obd code
  1541. ;*
  1542. ;* Codes from $40 to $c9: Returns what is stored in that ram address
  1543. ;*
  1544. ;* Codes from $ca to $ca:: Erase all fault codes and returns $00 if
  1545. ;* engine not rotating. If engine is rotating, all
  1546. ;* actuators/injector commands are reset and $ff
  1547. ;* is returned.
  1548. ;*
  1549. ;* Codes from $cb to $f0: Returns what is stored in that ram address
  1550. ;*
  1551. ;* Codes from $f1 to $fc: Injector/actuators commands, returns $ff if
  1552. ;* successfull
  1553. ;*
  1554. ;* $f1: Activate boost control solenoid
  1555. ;* $f2: Unused in code
  1556. ;* $f3: Activate egr solemoid
  1557. ;* $f4: Activate fuel pressure solenoid
  1558. ;* $f5: Activate purge solenoid
  1559. ;* $f6: Turn on fuel pump
  1560. ;* $f7: Disable injector #6 (inoperative in code)
  1561. ;* $f8: Disable injector #5 (inoperative in code)
  1562. ;* $f9: Disable injector #4
  1563. ;* $fa: Disable injector #3
  1564. ;* $fb: Disable injector #2
  1565. ;* $fc: Disable injector #1
  1566. ;*
  1567. ;* Codes from $f1 to $ff: Special queries
  1568. ;*
  1569. ;* $fd: Serial link test, returns $b5 (E931) or $b7 (E932)
  1570. ;* $fe: resistor strapping low word from t_strap3
  1571. ;* $ff: resistor strapping high word from t_strap3
  1572. ;*
  1573. ;******************************************************************
  1574. .org $d000-codeOffset
  1575. obdTable .byte port1, port2, port3, port4 ; obd $00 to $03
  1576. .byte port5, port6, timingAdv, ectRaw ; obd $04 to $07
  1577. .byte isc0, iscY0, isc1, iscY1 ; obd $08 to $0b
  1578. .byte ftrim_low, ftrim_mid, ftrim_hi, o2Fbk ; obd $0c to $0f
  1579. .byte ectFiltered, iatChecked, egrtRaw, o2Raw ; obd $10 to $13
  1580. .byte battRaw, baroRaw, iscStepCurr, tpsRaw ; obd $14 to $17
  1581. .byte closedLpFlags, ftrimFlags, mafRaw, ftrim_low ; obd $18 to $1b
  1582. .byte airVol, accEnr, state1, ftrim_low ; obd $1c to $1f
  1583. .byte rpm8, rpm31, port3Snap1, iscLrnFlags ; obd $20 to $23
  1584. .byte idleSpdTarg, iscStepTarg, knockSum, port3Snap0 ; obd $24 to $27
  1585. .byte port4Snap, injPw, injPw+1, enerLen ; obd $28 to $2b
  1586. .byte airCnt0, airCnt1, injFactor, injFactor+1 ; obd $2c to $2f
  1587. .byte iscFlags0, temp1, temp2, temp3 ; obd $30 to $33
  1588. .byte temp4, temp5, o2BadCnt, egrtBadCnt ; obd $34 to $37
  1589. .byte faultHi, faultLo, iatRaw, stFaultHi ; obd $38 to $3b
  1590. .byte stFaultLo, ftrim_low ; obd $3c to $3d
  1591.  
  1592.  
  1593.  
  1594. ;******************************************************************
  1595. ;
  1596. ;
  1597. ; Code executed after reset
  1598. ;
  1599. ;
  1600. ;******************************************************************
  1601. reset lds #stack ; Set the stack pointer
  1602. bsr ecuInit ; Initialization branch
  1603.  
  1604. ;---------------------------------------------
  1605. ; Main ECU loop executed in low priority
  1606. ; (compared to interrupt code). Loop will
  1607. ; execute slower when the computing load
  1608. ; increases...A minimum of 20Hz is monitored
  1609. ; by the COP function?
  1610. ;---------------------------------------------
  1611. L1001 jsr subroutine1 ;
  1612. jsr subroutine2 ;
  1613. jsr subroutine3 ;
  1614. jsr subroutine4 ;
  1615. jmp L1001 ;
  1616.  
  1617.  
  1618.  
  1619. ;******************************************************************
  1620. ;
  1621. ;
  1622. ; Initialization subroutine
  1623. ;
  1624. ;
  1625. ;******************************************************************
  1626. ;------------------------------------------------------------------
  1627. ; Init all outputs (port1, port2 port5 and port6) to known states
  1628. ;------------------------------------------------------------------
  1629. ecuInit ldd #$bf0f ;
  1630. std port1 ; port1 = 1011 1111, port2 = 0000 ffff
  1631. orm port5, #$ff ; port5 = 1111 1111
  1632. andm port6, #$00 ; port6 = 0000 0000
  1633.  
  1634. ;-------------------------------------------------------------
  1635. ; Init port1 through port5 data direction registers
  1636. ; Init real time interrupt frequency
  1637. ; Init L000f, L0017 and L0024 to 0 (never used in the code???)
  1638. ;-------------------------------------------------------------
  1639. jsr initFunc1 ;
  1640. ldd #$1b3d ;
  1641. staa t1_csr ; t1_csr = 0001 1011, enable injectors and cas interrupts, disable injectors, set cas detection edge polarity?
  1642. stab t2_csr ;
  1643. ldd #$5e0a ;
  1644. std t3_csr0 ; t3_csr0 = 0101 1110, t3_csr1 = 0000 1010, both coils not energized
  1645. jsr init_t1_t2 ;
  1646.  
  1647. ;-----------------------------------------------------------
  1648. ; Clear RAM from ramClearStart to ramClearEnd inclusively
  1649. ;-----------------------------------------------------------
  1650. #ifndef noRamReset
  1651. ldy #ramClearStart ;
  1652. clra ;
  1653. clrb ;
  1654. L1003 std $00,y ; Operation does y = y + 2
  1655. cmpy #ramClearEnd+1 ;
  1656. bcs L1003 ;
  1657. #endif
  1658.  
  1659. ;------------------------------------------------
  1660. ; Read all 8 ADC ports values and store in ram
  1661. ;------------------------------------------------
  1662. ldy #ectRaw ;
  1663. ldaa #$08 ; start with port 0 and start bit set ($08)
  1664. L1004 psha ;
  1665. jsr readAdc2 ;
  1666. stab $00,y ; y = y + 1
  1667. pula ;
  1668. inca ;
  1669. cmpa #$10 ;
  1670. bcs L1004 ;
  1671.  
  1672. ;-------------------------------------------------------
  1673. ; Check if all ISC variables are initialized properly
  1674. ; If not then re-initialize ECU from scratch
  1675. ;-------------------------------------------------------
  1676. ldx #$b000 ;
  1677. cpx isc0 ;
  1678. bcs L1005 ; Branch to re-initialize ECU from scratch
  1679. cpx isc1 ;
  1680. bcs L1005 ; Branch to re-initialize ECU from scratch
  1681. ldx #$6c00 ;
  1682. cpx isc0 ;
  1683. bhi L1005 ; Branch to re-initialize ECU from scratch
  1684. cpx isc1 ;
  1685. bhi L1005 ; Branch to re-initialize ECU from scratch
  1686. ldaa iscStepCurr ;
  1687. cmpa #$87 ;
  1688. bhi L1005 ; Branch to re-initialize ECU from scratch
  1689. coma ;
  1690. anda #$7f ;
  1691. cmpa iscStepCom ;
  1692. bne L1005 ; Branch to re-initialize ECU from scratch
  1693.  
  1694. ;-----------------------------------------------------------
  1695. ; All ISC variables look OK
  1696. ; Check if ram control register was erased (loss of power)
  1697. ;-----------------------------------------------------------
  1698. ldab ramControl ;
  1699. #ifdef octaneReset ;
  1700. bmi L1006a ;
  1701. #else
  1702. bmi L1006 ; Branch if ramControl.7 set, i.e. we already did a fresh reset and power was not lost
  1703. #endif
  1704.  
  1705. ;------------------------------------------------------
  1706. ; Perform a fresh reset, i.e. init ECU from scratch
  1707. ;------------------------------------------------------
  1708. ;---------------------------------------
  1709. ; Reset all faults and fault counters
  1710. ;---------------------------------------
  1711. L1005 clra ;
  1712. clrb ;
  1713. std stFaultHi ;
  1714. std faultHi ;
  1715. std o2BadCnt ;
  1716.  
  1717. ;--------------------
  1718. ; Init ISC variables
  1719. ;--------------------
  1720. ldaa #$80 ;
  1721. staa iscFlags0 ; iscFlags0 = $80, isc max calibration is requested
  1722. clra ;
  1723. jsr iscStepComp ; iscStepCurr = $0, iscStepCom = (~$0 & 7F)
  1724. ldd #$8c00 ;
  1725. std isc0 ; isc0 = $8c
  1726. std isc1 ; isc1 = $00
  1727.  
  1728. ;-------------------------------------------------------------
  1729. ; Set isc coil pattern and pattern index to t_iscPattern(0)
  1730. ;-------------------------------------------------------------
  1731. ldab #$04 ;
  1732. stab iscPatrnIdx ; iscPatrnIdx = $04 (lower two bits = 00b)
  1733. orm port5, #$80 ; ISC coil pattern bit 6 and 7 = 10b = t_iscPattern(0)
  1734. andm port5, #$bf ; ISC coil pattern bit 6 and 7 = 10b = t_iscPattern(0)
  1735.  
  1736. ;-------------------------------------------------------------
  1737. ; Init fuel trim to 100% and ftrimCntr to $80
  1738. ;-------------------------------------------------------------
  1739. ldaa #$80
  1740. tab
  1741. std ftrim_low
  1742. std ftrim_hi
  1743.  
  1744. ;------------------------------------
  1745. ; Init octane to max, i.e. good fuel
  1746. ;------------------------------------
  1747. L1006a ldaa #$ff ; Reset octane value to max value (good fuel, no knock)
  1748. staa octane
  1749.  
  1750. ;-------------------------------------------------
  1751. ; Set the ramControl flag bits since
  1752. ; fresh reset steps are (or were already) done
  1753. ;-------------------------------------------------
  1754. L1006 ldaa #$c0 ;
  1755. staa ramControl ;
  1756.  
  1757. ;-----------------------------------------
  1758. ; Init timing/knock variables to defaults
  1759. ;-----------------------------------------
  1760. ldd #$ffa0 ;
  1761. staa TcasLast0 ;
  1762. staa knockTimer ;
  1763. stab tim61Tot0 ;
  1764. ldaa t_enerLen ;
  1765. staa enerLen ;
  1766.  
  1767. ;-----------------------------------------
  1768. ; Init air count variables to default
  1769. ;-----------------------------------------
  1770. ldab t_airCntMax ; b = t_airCntMax(0)
  1771. stab airCntMax ;
  1772. ldaa #$08 ;
  1773. mul ; d = 8 * airCntMax
  1774. std airCnt0 ;
  1775. std oldAirCnt0 ;
  1776.  
  1777. ;-----------------------------------------
  1778. ; Init engine state flags to notRotating
  1779. ;-----------------------------------------
  1780. ldaa #$10 ;
  1781. staa state3 ; engine notRotating
  1782. staa state1 ; engine notRotating
  1783.  
  1784. ;---------------------------------------------
  1785. ; Init cas flags, current cylinder to default
  1786. ;---------------------------------------------
  1787. ldd #$0503 ;
  1788. staa tdcCasFlags ; Why not use std??? I guess it is not obvious taht they are not contiguous just by looking at variable names...
  1789. stab casCylIndex ;
  1790.  
  1791. ;----------------------
  1792. ; More init to default
  1793. ;----------------------
  1794. ldaa #$ff ;
  1795. staa obdInjCmd ; No obd injector command
  1796. staa coilChkCnt ;
  1797. staa T2_EcuPower ;
  1798. staa vss ; speed = 0
  1799.  
  1800. ;-----------------------------------------------------
  1801. ; Init reed switch flag to current reed switch value
  1802. ; and init 40Hz bit to 1
  1803. ;-----------------------------------------------------
  1804. ldaa port1 ;
  1805. anda #$80 ; Keep only reed switch bit
  1806. inca ;
  1807. staa rtiReedFlags ; Store latest Reed switch in bit 7 and set bit 1 for 40Hz based events
  1808.  
  1809. ;---------------------------------------------
  1810. ; More init to default
  1811. ;---------------------------------------------
  1812. ldaa #$06 ; 30ms
  1813. staa T200_cop ;
  1814. staa T200_40Hz ;
  1815. staa L00ca ; Never used in the code??????????????
  1816.  
  1817. ;---------------------------------------------
  1818. ; More init to default
  1819. ;---------------------------------------------
  1820. ldaa tpsRaw ;
  1821. staa oldTps2 ;
  1822. ldaa #$0e ;
  1823. staa T40_baro ;
  1824. ldd #$1450 ;
  1825. staa T40_2hz ;
  1826. stab T40_0p5hz ;
  1827.  
  1828. ;--------------------------------------------------
  1829. ; Reset all iscFlags0 and
  1830. ; If either min or max isc calibration flag was set
  1831. ; set iscStepCurr = 0 and request max calibration
  1832. ; else set flag indicating max calibration is done???
  1833. ;--------------------------------------------------
  1834. ldaa #$40 ; Assume max calibration flag is set
  1835. brclr iscFlags0, #$a0, L1007 ; branch if both max and min calibration flags are clear (1010 0000)
  1836. clra ;
  1837. jsr iscStepComp ; iscStepCurr = $00, iscStepCom = (~$00 & 7F)
  1838. ldaa #$80 ;
  1839. L1007 staa iscFlags0 ; iscFlags0 = $40 or $80
  1840.  
  1841. ;--------------
  1842. ; Init timer
  1843. ;--------------
  1844. ldaa #$05 ;
  1845. staa T40_noPower ;
  1846.  
  1847. ;------------------------------------------
  1848. ; Init TDC and injector testing valriables
  1849. ;------------------------------------------
  1850. ldab #$08 ; b = 0000 1000
  1851. stab tdcCheck ; tdcCheck = 0000 1000
  1852. stab injToTest ; injToTest = 0000 1000
  1853.  
  1854. ;----------------------------------------------------------------------
  1855. ; Load the ECU configuration variables according to resistor strapping
  1856. ;----------------------------------------------------------------------
  1857. jsr loadConfig ;
  1858.  
  1859. ;----------------------
  1860. ; re-enable interrupts
  1861. ;----------------------
  1862. cli ;
  1863.  
  1864. ;-----------------------
  1865. ; More init to defaults
  1866. ;-----------------------
  1867. clrb ;
  1868. stab T40_mas ;
  1869. stab T40_engRot ;
  1870.  
  1871. ;-------------------------------------
  1872. ; Init Tcas and TcasOld to max value
  1873. ; since engine is not rotating
  1874. ;-------------------------------------
  1875. bsr init_Tcas ;
  1876. rts
  1877.  
  1878.  
  1879.  
  1880. ;******************************************************************
  1881. ;
  1882. ; Initialize timer 1 and 2
  1883. ;
  1884. ;
  1885. ;
  1886. ;******************************************************************
  1887. init_t1_t2 orm t1_csr, #$09 ; Deactivate injector 1 and enable injector 1 output compare interrupts
  1888. orm t2_csr, #$3d ; Deactivate injector 3,2,4 and enable injector 3,2,4 output compare interrupts
  1889.  
  1890. ;---------------------------------------------------
  1891. ; Schedule interrupt in 11us for t1 and t2
  1892. ; i.e. Make sure injectors are actually deactivated
  1893. ;---------------------------------------------------
  1894. ldd t1t2_clk
  1895. addd #$000b
  1896. std t1_outCmpWr
  1897. std t2_outCmpWr
  1898. rts
  1899.  
  1900.  
  1901.  
  1902. ;******************************************************************
  1903. ;
  1904. ; Initialize Tcas and TcasOld to $7fff (infinite, not rotating...)
  1905. ;
  1906. ;
  1907. ;
  1908. ;******************************************************************
  1909. init_Tcas ldx #Tcas
  1910. ldd #$7fff
  1911. std $00,x
  1912. std $02,x
  1913. rts
  1914.  
  1915.  
  1916.  
  1917. ;******************************************************************
  1918. ;
  1919. ;
  1920. ; First subroutine
  1921. ;
  1922. ;
  1923. ;******************************************************************
  1924. ;----------------------------------------------
  1925. ; Clear counter state flag and check if 40Hz
  1926. ; flag was set by real time interrupt
  1927. ;----------------------------------------------
  1928. subroutine1 clra ; a=0, used to accumulate various conditions in code below
  1929. brclr rtiReedFlags, #$01, L1013 ; Branch if 40Hz flag is not yet set (flag is set at ~40Hz in RT interrupt)
  1930. andm rtiReedFlags, #$fe ; Reset bit
  1931.  
  1932. ;---------------------------------------------------------------
  1933. ; 40Hz flag is set, process it (code executed 40 times a second,
  1934. ; at the most...)
  1935. ;---------------------------------------------------------------
  1936. ;---------------------------------------------------------------
  1937. ; Decrement all 40Hz timers (min of 0) from $0117 to $0132
  1938. ;---------------------------------------------------------------
  1939. ldx #T40_2hz ;
  1940. ldab #$1c ;
  1941. jsr decTable ;
  1942. inca ; a.0=1, set at 40Hz
  1943.  
  1944. ;------------------------------------------
  1945. ; Update 10Hz flag based on T40_2hz
  1946. ;------------------------------------------
  1947. ldab T40_2hz ;
  1948. bitb #$03 ;
  1949. bne L1011 ; Branch 3 times out of 4???
  1950. oraa #$02 ; a.1=1, set at ~10Hz
  1951.  
  1952. ;----------------------------------------------------------
  1953. ; Check T40_2hz, loops at $14 (20d), which produces 2Hz
  1954. ;----------------------------------------------------------
  1955. L1011 tstb ;
  1956. bne L1012 ; Branch if T40_2hz is not null yet (takes ~0.5sec)
  1957.  
  1958. ;----------------------------------------------------------------------
  1959. ; Decrement all 2Hz timers (min of 0) from $0134 to $13f
  1960. ;----------------------------------------------------------------------
  1961. ldx #T2_crank ;
  1962. ldab #$0c ;
  1963. jsr decTable ;
  1964. oraa #$04 ; a.2=1, set at 2Hz
  1965.  
  1966. ;-----------------
  1967. ; Re-init counter
  1968. ;-----------------
  1969. ldab #$14 ;
  1970. stab T40_2hz ;
  1971. ;
  1972. ;---------------------------------------------------------
  1973. ; Check T40_0p5hz, loops at $50 (80d), which produces 0.5Hz
  1974. ;---------------------------------------------------------
  1975. L1012 ldab T40_0p5hz ;
  1976. bne L1013 ; Branch if T40_0p5hz is not null yet (takes ~2sec)
  1977.  
  1978. ;----------------------------------------------------------------
  1979. ; Decrement all 0.5Hz timers (stop at 0) from $140 to $145
  1980. ;----------------------------------------------------------------
  1981. ldx #T0p5_crank1 ;
  1982. ldab #$05 ;
  1983. jsr decTable ;
  1984. oraa #$08 ; a.3=1
  1985.  
  1986. ;-----------------
  1987. ; Re-init counter
  1988. ;-----------------
  1989. ldab #$50 ;
  1990. stab T40_0p5hz ; Re-init T40_0p5hz with $50 (2sec)
  1991.  
  1992. ;--------------------------------------------------------
  1993. ; At this point, accum. A contains state of counters updated
  1994. ; in the above code, store it in Tclocks
  1995. ;--------------------------------------------------------
  1996. L1013 staa Tclocks
  1997.  
  1998. ;----------------------------------------------------------------------
  1999. ; Re-init T40_crank, T2_crank, T0p5_crank1 to max if startingToCrank
  2000. ;----------------------------------------------------------------------
  2001. ldaa #$ff ; a = $ff
  2002. brclr state1, #$01, L1014 ; Branch if startingToCrank is clear
  2003. staa T40_crank ; Engine startingToCrank, reset a few timers
  2004. staa T2_crank ;
  2005. staa T0p5_crank1 ;
  2006.  
  2007. ;----------------------------------
  2008. ; Re-init T40_start if key is in start
  2009. ;----------------------------------
  2010. L1014 brset port3Snap0, #$40, L1015 ; Branch if key is not in start
  2011. staa T40_start ; Key in start, re-init counter
  2012.  
  2013. ;-------------------------------------------------------------------
  2014. ; Load config1 and config2 memories depending on config resistors
  2015. ;-------------------------------------------------------------------
  2016. L1015 jsr loadConfig
  2017.  
  2018. ;-------------------------------------------------------
  2019. ; Reset counter T200_cop to $0a (on every loop,
  2020. ; will reach 0 only if main loop takes more
  2021. ; than 50ms=10/200Hz, i.e. main loop slower than 20Hz)
  2022. ; Could be used as a COP monitor to reset ECU???
  2023. ;-------------------------------------------------------
  2024. ldaa #$0a ; 50ms or 20Hz
  2025. staa T200_cop ; Re-init counter
  2026. jsr initFunc1 ; Re-init ports and other stuff on every loop???, maybe used in conjunction with T200_cop timer...???
  2027.  
  2028. ;----------------------------------------
  2029. ; Re-init timer 1 and 2 and t3_csr0
  2030. ;----------------------------------------
  2031. sei ;
  2032. andm t1_csr, #$1b ;
  2033. orm t1_csr, #$18 ;
  2034. orm t2_csr, #$18 ;
  2035. andm t3_csr0, #$5e ;
  2036. orm t3_csr0, #$42 ;
  2037. cli
  2038.  
  2039. ;---------------------------------------------------------
  2040. ; Re-init some stuff in case the engine is not rotating
  2041. ;---------------------------------------------------------
  2042. sei ;
  2043. ldab T40_engRot ;
  2044. bne L1016 ; Branch if T40_engRot not expired
  2045. ldd #$0503 ; T40_engRot reached 0, re-init stuff since engine not rotating
  2046. staa tdcCasFlags ;
  2047. stab casCylIndex ; Why not std?
  2048. clr injPw ;
  2049. jsr init_t1_t2 ;
  2050.  
  2051. ;---------------------------------------------------------
  2052. ; Re-init cas related controls if T40s_casInt is expired
  2053. ; i.e. no CAS interrupts received for over 1.275sec
  2054. ;---------------------------------------------------------
  2055. L1016 brset T40s_casInt, #$ff, L1017 ; Branch if T40s_casInt not expired (not 0)
  2056. clr tdcCasCount ; tdcCasCount = 0
  2057. orm t3_csr0, #$0c ; set 0000 1111, disable both power transistor coils and ???
  2058. orm t3_csr1, #$0a ; set 0000 1010,
  2059. clra ;
  2060. staa enerFlags ;
  2061. L1017 cli ;
  2062.  
  2063. ;------------------------------
  2064. ; Check if ECU is in test mode
  2065. ;------------------------------
  2066. brset port4, #$08, L1018 ; Branch if ECU test mode terminal is grounded
  2067.  
  2068. ;--------------------------------------
  2069. ; Not in test mode, Reset serial comm.
  2070. ;--------------------------------------
  2071. ldd sci_scr ; Read serial port at address 0011 (status) and 0012 (data) (clears it)?
  2072. ldd #($0400 |((baudRate & $03)<<8)) ; A=06, B=00
  2073. std sci_baud ; set serial port mode, sci_rate=06, sci_cr=00
  2074. orm obdInjCmd, #$3f ; Reset all injector off commands
  2075. clr obdActCmd ; Reset all actuator on commands
  2076. andm obdFlags, #$3c ; Reset stored serial port state to 00xxxx00?, FA.0 and FA.1 are reset to 0
  2077. bra L1022
  2078.  
  2079. ;------------------------------------
  2080. ; At this point, we are in test mode
  2081. ;------------------------------------
  2082. L1018 brset obdFlags, #$02, L1019 ; Check if port2.4 initialized to 1 (output to serial connector)?
  2083. orm port2, #$10 ; Set output to serial port to 1 (heart beat level on diagnostic port if TE not enabled)
  2084. orm obdFlags, #$02 ; Set $FA.1 indicating we initialized default serial port output
  2085. L1019 brset obdFlags, #$01, L1020 ; branch if FA.0 is 1? (FA.0 seems to be toggled on every loop)
  2086.  
  2087. ;---------------------------------------------------------------------------------
  2088. ; At this point serial tx was previously enabled, reset all parameters anyway
  2089. ; Code is executed only after tx is enabled on first loop (preamble is sent,
  2090. ; we don't want to receive the echo...) and then at 1/2 loop frequency
  2091. ;---------------------------------------------------------------------------------
  2092. ldaa #($04 | (baudRate & $03)) ;
  2093. ldab sci_scr ;
  2094. andb #$fa ;
  2095. orab #$18 ;
  2096. std sci_baud ; Set baud rate and serial port mode
  2097. orm obdFlags, #$01 ;
  2098. bra L1021 ;
  2099. L1020 orm sci_scr, #$02 ;
  2100. andm obdFlags, #$fe ;
  2101. L1021 clr errCodeProc ; Reset code (no code...) being output to test connector (heart beat mode)
  2102.  
  2103. ;------------------------------------------------
  2104. ; Build port3Snap0 from port3
  2105. ;------------------------------------------------
  2106. L1022 ldaa port3 ; a = port3
  2107. anda #$fb ; Reset 0000 0100
  2108. #ifdef E932
  2109. ldab T40_start ;
  2110. addb #$3c ; add 1.5s
  2111. bcc L1023 ; branch if key was out of start for more than than 1.5s
  2112. #endif
  2113. oraa #$20 ; force setting of park/neutral flag
  2114. L1023 ldab T40_crank ;
  2115. addb #$ac ; 4.3s
  2116. bcc L1024 ; branch if engine stopped "startingToCrank" more than 4.3s ago
  2117. oraa #$10 ; Force setting of A/C switch flag
  2118. L1024 brclr state1, #$11, L1025 ; Branch if both notRotating and startingToCrank clear
  2119. oraa #$30 ; engine is either notRotating or startingToCrank, force setting of both A/C switch and park/neutral flags
  2120. L1025 ldab ectFiltered ;
  2121. cmpb #$9b ; 10.2degC
  2122. bcs L1026 ; Branch if ECT temperature lower than threshold
  2123. anda #$f7 ; Reset $08, power steering flag
  2124. L1026 staa port3Snap0 ;
  2125.  
  2126. ;----------------------------
  2127. ; Build port4Snap from port4
  2128. ;----------------------------
  2129. ldaa port4 ;
  2130. anda #$78 ; Only keep 01111000
  2131. staa port4Snap ;
  2132.  
  2133. ;------------------------------------------
  2134. ; Read some ADC inputs
  2135. ; ECT (engine coolant temp)
  2136. ; IAT (intake air temp)
  2137. ; BARO
  2138. ; O2
  2139. ; EGRT
  2140. ;------------------------------------------
  2141. ldy #$00cb ;
  2142. ldaa #$08 ;
  2143. L1027 psha ;
  2144. jsr readAdc1 ;
  2145. cli ;
  2146. stab $00,y ; y = y + 1
  2147. pula ;
  2148. inca ;
  2149. cmpa #$0d ;
  2150. bcs L1027 ;
  2151.  
  2152. ;------------------------------------------------------
  2153. ; Validate and condition raw engine coolant temperature
  2154. ;------------------------------------------------------
  2155. andm state2, #$f0 ; Reset error flags before update below
  2156. ldab ectRaw ; b = ectRaw
  2157. cmpb #$05 ; 141degC
  2158. bcs L1028 ;
  2159. cmpb #$ec ; -52degC
  2160. bls L1029 ;
  2161. L1028 ldab #$1e ; Use default of 83degC
  2162. orm state2, #$01 ; Set error flag
  2163.  
  2164. ;-------------------------------------------------
  2165. ; Check some conditions for filtered ECT update
  2166. ;-------------------------------------------------
  2167. L1029 brclr state2, #$10, L1030 ;
  2168. ldab #$1e ; Use default of 83degC
  2169. L1030 brset state1, #$10, L1033 ; Branch if notRotating
  2170. brclr Tclocks, #$04, L1035 ; Branch if 2Hz signal not set
  2171.  
  2172. ;----------------------------------------------------
  2173. ; At this point 2 Hz signal is set and b = validated ECT
  2174. ;
  2175. ; Filter the validated ECT
  2176. ;
  2177. ; This section of code computes ectFiltered which
  2178. ; is basically the same as validated ECT except
  2179. ; that it can only increase by 3 units every 0.5s...
  2180. ; or decrease by 1 unit every 0.5s
  2181. ;----------------------------------------------------
  2182. ldaa ectFiltered ; a = ectFiltered
  2183. sba ; a = a-b = ectFiltered - validated ECT = ECTdiff
  2184. bcc L1031 ; Branch if ectFiltered >= validated ECT (new temp is higher than old one, which is normal case when warming...)
  2185. ldab ectFiltered ; ectFiltered < validated ECT (temperatured lowered...)
  2186. cmpb #$54 ; 41degC
  2187. beq L1034 ; branch if equal to this temp????
  2188. incb ; else increment validated ECT (decrease temp) by 1 at a time (slowly change it to reflect sensor value...)
  2189. bra L1033 ;
  2190.  
  2191. L1031 cmpa #$03 ; Check ECT difference
  2192. bls L1032 ; Branch if ECT difference <= 3 (5F)
  2193. ldaa #$03 ; Difference higher than 3, use 3
  2194. L1032 suba ectFiltered ;
  2195. nega ; a = ectFiltered-min(ECTdiff,3) = ectFiltered - min(ectFiltered-validatedECT, 3) = validatedECT if difference smaller than 3, else it lags behind...
  2196. tab ; b = ectFiltered-min(ECTdiff,3)
  2197.  
  2198. L1033 ldaa #$96 ; 300s (5 minutes!!!)
  2199. staa T0p5_ect ; Reset counter
  2200. L1034 stab ectFiltered ; ectFiltered = filtered and validated ECT
  2201.  
  2202. ;----------------------------------------------------------
  2203. ; Compute ectCond which is used for table interpolation
  2204. ; Limit max value to $e0 (min temp of -29degC)
  2205. ; Scale by 8 below $20 (temp above 80degC)
  2206. ;
  2207. ; ectFiltered ectFiltered ectCond
  2208. ; -31degC to -59degC $e1-$ff -> $e0
  2209. ; 80degC to -29degC $20-$e0 -> $20-$e0
  2210. ; 81.3degC $1f -> $18
  2211. ; 82.8degC $1e -> $10
  2212. ; 84.3degC $1d -> $08
  2213. ; 158degC to 85.9degC $00-$1c -> $00
  2214. ;----------------------------------------------------------
  2215. L1035 ldab ectFiltered ;
  2216. cmpb #$e0 ; -29degC
  2217. bls L1036 ; Branch if ectFiltered <= $e0
  2218. ldab #$e0 ; Use max of $e0
  2219. L1036 cmpb #$20 ; 80degC
  2220. bcc L1038 ; Branch if ectFiltered >= $20
  2221. subb #$1c ; b = ectFiltered - $1c
  2222. bcc L1037 ; Branch if no underflow
  2223. clrb ; underflow, use 0
  2224. L1037 aslb ;
  2225. aslb ;
  2226. aslb ; b = (ectFiltered-$1c)*8
  2227. L1038 stab ectCond ; Store conditionned ect
  2228.  
  2229. ;-------------------------------------------------
  2230. ; Validate/condition raw intake air temperature
  2231. ;-------------------------------------------------
  2232. ldab iatRaw ;
  2233. cmpb #$0e ; 122degC
  2234. bcs L1039 ; Branch if temp > 122degC
  2235. cmpb #$ea ; -49degC
  2236. bls L1040 ; Branch if temp > -49degC
  2237. L1039 orm state2, #$02 ; Set fault code
  2238. ldab #$7b ; Use 25degC
  2239. L1040 stab iatChecked ;
  2240.  
  2241. ;-----------------------------------------------------------
  2242. ; Compute conditionned IAT for later table interpolation
  2243. ;-----------------------------------------------------------
  2244. ldx #$e020 ; Load x with max/offset (max=$e0)
  2245. jsr clipOffset ; b = max(min(b,$e0)-$20,0)-> offset and clip temp, returns b=$00 to $c0
  2246. stab iatCond ; Conditionned IAT
  2247.  
  2248. ;-------------------------------------------------
  2249. ; Compute air density factor based on air temperature
  2250. ;-------------------------------------------------
  2251. ldx #t_airDens ;
  2252. jsr iatCInterp ;
  2253. stab iatCompFact ; Air density factor
  2254.  
  2255. ;---------------------------------------------------
  2256. ; Check battery voltage for baro sensor validation
  2257. ;---------------------------------------------------
  2258. ldaa battRaw ;
  2259. cmpa #$6d ; 8V
  2260. bcc L1042 ; Branch if more than 8V
  2261. ldaa #$0e ; battery voltage too low, start timer??? (0.35sec)
  2262. staa T40_baro ;
  2263.  
  2264. ;------------------------------------------------------------
  2265. ; Validate baro range, T40_baro is used to ignore baroRaw
  2266. ; When battery<8v (and 0.35s after it is >8V)
  2267. ;------------------------------------------------------------
  2268. L1042 ldab baroRaw ;
  2269. ldaa T40_baro ;
  2270. bne L1044 ; Branch if battery voltage was too low
  2271. cmpb #$e4 ; 1.1 bar
  2272. bcc L1043 ; branch if baroRaw > 1.1
  2273. cmpb #$64 ; .49 bar
  2274. bcc L1045 ; branch if baroRaw > .49
  2275. L1043 orm state2, #$04 ; Set error flag
  2276. L1044 ldab #$cd ; Use 1.0 bar
  2277. L1045 stab baroChecked ;
  2278.  
  2279. ;-----------------------------------------------------
  2280. ; Compute conditionned baro for table interpolation
  2281. ;-----------------------------------------------------
  2282. ldx #$bd5d ;
  2283. jsr clipOffset ; b = max(min(b,$bd)-$5d,0)-> offset and clip baro, returns b = $00 to $60 (0.45bar to 0.92bar???)
  2284. cmpb #$40 ;
  2285. bcs L1046 ; branch if b < $40
  2286. aslb ; else mult by 2
  2287. subb #$40 ; and sub 40 -> 1:1 scale for $00 to $40 and 2:1 scale for $40 to $60, new max is $80, not $60
  2288. L1046 stab baroCond ; Conditionned baro used in table lookup
  2289.  
  2290. ;----------------------------------------------------
  2291. ; Compute barometric pressure factor for fuel inj.
  2292. ;----------------------------------------------------
  2293. ldab baroChecked ;
  2294. ldaa #$a0 ;
  2295. mul ; baroChecked*160
  2296. aslb ;
  2297. adca #$00 ; round-up
  2298. staa baroFact ; barometric pressure factor = rounded baroChecked*160/256 -> pressure is (baroFact/128) bar, i.e. $80 = 1 bar
  2299.  
  2300. ;-------------------------------------------------------------
  2301. ; Transfer tpsDiffMax1 to tpsDiffMax2 and reset tpsDiffMax1
  2302. ;-------------------------------------------------------------
  2303. sei ;
  2304. ldaa tpsDiffMax1 ;
  2305. clr tpsDiffMax1 ;
  2306. cli ;
  2307. staa tpsDiffMax2 ;
  2308.  
  2309. ;-----------------------------------------------------------
  2310. ; If engine is not rotating, re-init Tcas and use rpm = 0
  2311. ;-----------------------------------------------------------
  2312. brclr state1, #$10, L1047 ; Branch if notRotating clear
  2313. jsr init_Tcas ; engine is notRotating, re-init Tcas
  2314. clra ;
  2315. clrb ; use d = rpm = 0 for below
  2316. bra L1048 ;
  2317.  
  2318. ;------------------------------------------------------------------------
  2319. ; Update rpm variables from Tcas (Tcas is obtained from CAS interrupt)
  2320. ;------------------------------------------------------------------------
  2321. L1047 ldd Tcas ;
  2322. jsr calcFreq ; D = $EA600/Tcas = 960000/Tcas = 960000/(125000/2/(rpm/60)) = 0.256*rpm
  2323. L1048 std rpm4 ; RPM4 = #$EA600/Tcas = 0.256*rpm
  2324. jsr scale2m ; scale D by 2
  2325. stab rpm8 ; rpm8 = #$EA600/Tcas/2 = rpm/7.8125
  2326. ldd rpm4 ; D = #$EA600/Tcas
  2327. jsr scale8m ; D = #$EA600/Tcas/8 = rpm/31.25
  2328. stab rpm31 ; rpm31 = #$EA600/Tcas/8 = #$EA600 / (125000/2/(rpm/60)) / 8 = rpm/31.25.
  2329.  
  2330. ;------------------------------------------------------
  2331. ; Compute rpmIndex1 for eventual map interpolation
  2332. ;------------------------------------------------------
  2333. ldaa #$90 ; a=$90 (4500rpm)
  2334. jsr rpmRange ; get rpm for map interpolation, b = min(max(RPM31p25-#$10, 0), $90) = min(max(RPM31p25-500rpm,0),4500rpm)
  2335. stab rpmIndex1 ; rpmIndex1
  2336.  
  2337. ;-------------------------------------------------------------
  2338. ; if notRotating or startingToCrank. Use rpmX4Filt = 16*rpm4
  2339. ;-------------------------------------------------------------
  2340. brclr state1, #$11, L1049 ; branch if notRotating and startingToCrank clear
  2341. ldd rpm4 ; engine is either notRotating or startingToCrank
  2342. asld ;
  2343. asld ;
  2344. asld ;
  2345. asld ; d = 16*rpm4
  2346. andm masCasFlags, #$fe ; reset masCasFlags.1
  2347. bra L1050 ;
  2348.  
  2349. ;-----------------------------------------------------------------
  2350. ; Engine is running, Use rpmX4Filt = filtered(16*rpm4)
  2351. ; Update only when masCasFlags.1 was set by interrupt
  2352. ;
  2353. ; rpmX4Filt is basically the filtered version of rpm4 where
  2354. ; an exponential averaging filter is used
  2355. ;
  2356. ; rpmX4Filt = $e8/256 * oldrpmX4Filt + $18/256 * 16*rpm4
  2357. ; alpha * oldrpmX4Filt + (1-alpha) * 16*rpm4
  2358. ;
  2359. ; where alpha = 0.90625
  2360. ;-----------------------------------------------------------------
  2361. L1049 brclr masCasFlags, #$01, L1051 ; Branch if flag not set
  2362. andm masCasFlags, #$fe ; Reset the flag
  2363. ldx rpmX4Filt ; x = rpmX4Filt
  2364. ldab #$e8 ; b = $e8
  2365. jsr mul816b ; d = $e8/256 * rpmX4Filt, temp3 = lower 8 bits of result
  2366. std rpmX4Filt ; rpmX4Filt = $e8/256 * rpmX4Filt
  2367. ldaa temp3 ;
  2368. staa temp4 ; temp4 = temp3 = lower 8 bits of ($e8/256 * old rpmX4Filt)
  2369. ldd rpm4 ;
  2370. asld ;
  2371. asld ;
  2372. asld ;
  2373. asld ; d = 16 * rpm4
  2374. xgdx ; x = 16 * rpm4
  2375. ldab #$e8 ; b = $e8
  2376. negb ; b = -$e8 = $18 (why not load it directly, maybe mitsu compiler stuff...?)
  2377. jsr mul816b ; d = $18/256 * 16 * rpm4
  2378. xgdx ; x = $18/256 * 16 * rpm4
  2379. clrb ; b = 0
  2380. ldaa temp3 ; a = lower 8 bits of ($18/256 * 16 * rpm4)
  2381. adda temp4 ; a = lower 8 bits of ($18/256 * 16 * rpm4) + lower 8 bits of ($e8/256 * old rpmX4Filt)
  2382. rolb ; b = carry bit (if a carry was generated) from that addition
  2383. rola ; a = a*2 (shift upper bit for roundoff purposes)
  2384. adcb #$00 ; Round off. At this point, b contains the rounded-up highest bit of the addition of the lowest 8 bits
  2385. abx ; x = $18/256 * 16 * rpm4 + rounded lower 1 bit
  2386. xgdx ; d = $18/256 * 16 * rpm4 + rounded lower 1 bit
  2387. addd rpmX4Filt ; d = $18/256 * 16 * rpm4 + $e8/256 * old rpmX4Filt
  2388. L1050 std rpmX4Filt ; Store new value
  2389.  
  2390. ;-------------------------------------------------------------
  2391. ; Restart T40_mas if engine notRotating or startingToCrank
  2392. ;-------------------------------------------------------------
  2393. L1051 brclr state1, #$11, L1052 ; branch if notRotating and startingToCrank clear
  2394. ldaa #$0c ; Engine is either notRotating or startingToCrank
  2395. staa T40_mas ; Restart timer at 0.3s
  2396.  
  2397. ;-----------------------------------------
  2398. ; Set state2 mas flag if T40_mas expired
  2399. ;-----------------------------------------
  2400. L1052 ldaa T40_mas ;
  2401. bne L1053 ; Branch if counter not yet 0
  2402. orm state2, #$08 ; Set bit indicating timer expired
  2403.  
  2404. ;---------------------------------------------------------------------------
  2405. ; Compute mafRaw16 and mafRaw from airCnt0:airCnt1
  2406. ;
  2407. ; Since airCnt0:airCnt1 is filtered airCntNew0:airCntNew1, we have
  2408. ;
  2409. ; mafRaw = $200d * airCnt0 / Tcas / 64
  2410. ; = 8205 * airCntNew0 / Tcas / 64
  2411. ; = 8205 * (N+r) * $9c / Tcas / 64 (see airCntNew0 definition)
  2412. ; = 8205 * (N+r) * $9c / (125000*TcasInSeconds) / 64
  2413. ; = (N+r)/TcasInSeconds/6.25
  2414. ; = "number of airflow sensor pulse per sec" / 6.25
  2415. ;
  2416. ; Where:
  2417. ;
  2418. ; -Tcas is the time required for 1 cas interrupt (there are 4 cas
  2419. ; interrupts for every 2 rotations which basically means 1 cas
  2420. ; interrupt for every complete cycle of one cylinder)
  2421. ; -(N+r) is the number of air sensor pulses received during
  2422. ; one cas interrupt, r<1 is the fractional part. See
  2423. ; the mas interrupt for assumptions...
  2424. ; -Tcas is the cas interrupt period measured at 125KHz
  2425. ;
  2426. ;---------------------------------------------------------------------------
  2427. L1053 ldd Tcas ; d = Tcas
  2428. std temp4 ;
  2429. ldd #$200d ; d = $200d = 8205d
  2430. ldx airCnt0 ;
  2431. stx temp6 ;
  2432. jsr mul1616 ; d = d * temp6:temp7 = ($200d * airCnt0)/65536 = 0.125198*airCnt0
  2433. jsr div3216 ; d = 65536*0.125198*airCnt0/Tcas = 8205 * airCnt0/Tcas
  2434. std mafRaw16 ; 16 bit mafRaw
  2435. #ifdef masLog2X ;
  2436. jsr scale128m ;
  2437. #else ;
  2438. jsr scale64m ; d = 8205*airCnt0/Tcas/64, result is in B...
  2439. #endif
  2440. brset state1, #$10, L1054 ; Branch if engine notRotating
  2441. brclr state2, #$08, L1055 ; Branch if pulse accumulator interrupts received
  2442. L1054 clrb ; No interrupts or notRotating, use 0 air flow
  2443. L1055 stab mafRaw ; Store 8 bit mafRaw = 8205*airCnt0/Tcas/64
  2444.  
  2445. ;----------------------------------------------------------------------
  2446. ; Compute airCntMax (max air count as a function of rpm, ect and iat)
  2447. ;----------------------------------------------------------------------
  2448. ldd rpm4 ; d = rpm4
  2449. cmpa #$03 ; compare high part to 3 -> compare D to 768
  2450. bcs L1057 ; Branch if RPM < 3000
  2451. ldd #$0300 ; RPM >=3000 -> use 3000
  2452. L1057 asld ;
  2453. asld ; scale rpm
  2454. ldx #t_airCntMax ;
  2455. jsr interp1 ; b = t_airCntMax[rpm]
  2456. clra ;
  2457. std temp6 ; temp6:temp7 = t_airCntMax[rpm]
  2458. ldx #L1990 ;
  2459. ldaa ectCond ;
  2460. jsr interp32mul ; D = t_airCntMax[rpm] * L1990[ectCond]
  2461. ldx #L1991 ;
  2462. ldaa iatCond ;
  2463. jsr interp32mul ; D = t_airCntMax[rpm] * L1990[ectCond] * L1991[iatCond]
  2464. jsr ovfCheck ; Check for overflow
  2465. stab airCntMax ; airCntMax = t_airCntMax[rpm] * L1990[ectCond] * L1991[iatCond]
  2466.  
  2467. ;------------------------------------------------
  2468. ; Store airCntMax in airCnt0 and oldAirCnt0
  2469. ; when engine is notRotating or startingToCrank
  2470. ;------------------------------------------------
  2471. brclr state1, #$11, L1060 ; branch if notRotating and startingToCrank clear
  2472. clra ; engine is either notRotating or startingToCrank
  2473. asld ;
  2474. asld ;
  2475. asld ; d = airCntMax*8
  2476. std airCnt0 ; airCnt0:airCnt1 = airCntMax*8
  2477. std oldAirCnt0 ; oldAirCnt0 = airCntMax*8
  2478.  
  2479. ;----------------------------------------------
  2480. ; Compute airCntDef, default airCnt0 value
  2481. ; when no mas interrupts are being received
  2482. ;----------------------------------------------
  2483. L1060 ldy #L2053 ;
  2484. jsr rpmPwise ; b = F(rpm4), see L2053 table
  2485. pshb ;
  2486. ldx #L2036 ;
  2487. jsr interpEct ;
  2488. addb tpsRaw ; b = tpsRaw + L2036[ect]
  2489. bcc L1062 ; overflow check
  2490. ldab #$ff ; Use max
  2491. L1062 ldx #$ba1a ;
  2492. jsr clipOffset ; offset and clip b, b = max(min(tpsRaw + L2036[ect],$ba)-$1a,0)
  2493. lsrb ; b = b/2
  2494. pula ; a = F(rpm4)
  2495. ldx #L1986 ;
  2496. ldy #$0500 ;
  2497. jsr lookup2D2 ; b = L1986[a,b], 2D interpolated air count since stored in airCntDef which is stored in airCnt0 under some cases???
  2498. ldaa #$57 ;
  2499. mul ; b = $57*L1986[a,b]
  2500. jsr scale128m ; b = $57*L1986[a,b]/128
  2501. stab airCntDef ; airCntDef = $57*L1986[a,b]/128
  2502.  
  2503. ;------------------------------------------------------
  2504. ; Re-init airFiltFact (airflow filtering factor)
  2505. ;
  2506. ; Filtering factor depends on current conditions???
  2507. ;------------------------------------------------------
  2508. #ifdef E931
  2509. ldaa #$b3 ; Value to use if timer T40_ftrim2 is expired
  2510. ldab T40_ftrim2 ;
  2511. beq L1064 ;
  2512. #endif
  2513. ldaa #$d1 ;
  2514. brset iscLrnFlags, #$10, L1064 ; Branch if conditions are good to update isc variables
  2515. ldaa #$e4 ;
  2516. L1064 staa airFiltFact
  2517.  
  2518. ;-------------------------------------------------------------
  2519. ; Transfer airDiffPos:airDiffNeg to airDiffPos1:airDiffNeg1
  2520. ; and re-init airDiffPos:airDiffNeg to 0
  2521. ;-------------------------------------------------------------
  2522. clra ;
  2523. clrb ;
  2524. sei ;
  2525. ldx airDiffPos ;
  2526. std airDiffPos ;
  2527. cli ;
  2528. stx airDiffPos1 ;
  2529.  
  2530. ;-----------------------------------------------------------------------------------------
  2531. ; Compute airCntMin0 (minimum value of airCntNew0 before it is used for airCnt0 calc)
  2532. ;-----------------------------------------------------------------------------------------
  2533. clra ;
  2534. clrb ; d = 0
  2535. brset state1, #$11, L1065 ; branch if engine notRotating or startingToCrank (use minimum of 0)
  2536. ldaa #$10 ;
  2537. #ifdef E931
  2538. ldab #$81
  2539. #else
  2540. ldab #$91
  2541. #endif
  2542. mul ;
  2543. ldx Tcas ;
  2544. stx temp6 ;
  2545. jsr mul1616 ;
  2546. ldx #$4000 ;
  2547. stx temp6 ;
  2548. jsr mul1616 ;
  2549. xgdx ;
  2550. #ifdef E931
  2551. ldab baroFact ;
  2552. #else
  2553. ldab #$80 ; Use 1.0 bar
  2554. nop
  2555. #endif
  2556. ldaa iatCompFact ;
  2557. mul ;
  2558. std temp4 ;
  2559. xgdx ;
  2560. jsr div3216 ;
  2561. L1065 std airCntMin0 ; Store "min" used in air count calc
  2562.  
  2563. ;---------------------------------------------------------------
  2564. ; Compute airVol16 and airVol from [airCnt0:airCnt1]*masScalar
  2565. ;---------------------------------------------------------------
  2566. clra ;
  2567. clrb ;
  2568. brset state1, #$10, L1066 ; Branch if engine notRotating
  2569. ldd #masScalar ; 16 bit MAS scalar ($5e86 for 1G, $7A03 for 2g), seem to correspond to (masComp+t_mascomp(72Hz))/512*65536
  2570. std temp6 ; Store for 16 multi.
  2571. ldd airCnt0 ; MAS air count
  2572. jsr mul1616 ; d = masScalar/65536 * [airCnt0:airCnt1]
  2573. L1066 std temp6 ; temp6:temp7 = masScalar/65536 * [airCnt0:airCnt1]
  2574. std airVol16 ; airVol16 = masScalar/65536 * [airCnt0:airCnt1]
  2575. jsr scale2m ; b = masScalar/65536 * airCnt0 / 2 with overflow check
  2576. stab airVol ; airVol = masScalar/65536*[airCnt0:airCnt1]/2 (8 bit airflow)
  2577.  
  2578. ;--------------------
  2579. ; Compute airVolCond
  2580. ;--------------------
  2581. tba ; a = airVol
  2582. jsr L1647 ; b = Apply offset and scaling to airVol???
  2583. stab airVolCond ;
  2584.  
  2585. ;----------------------------------------
  2586. ; At this point [temp6:temp7] = airVol16
  2587. ;
  2588. ; Compute airVolT, airVolTB and airVolB
  2589. ;----------------------------------------
  2590. ldab iatCompFact ;
  2591. jsr mul816_256 ; b = airVol16/2 * iatCompFact/128; [temp6:temp7] = airVol16 * iatCompFact/128
  2592. stab airVolT ; airVolT = airVol16/2 * iatCompFact/128
  2593. jsr mul816_baro ;
  2594. stab airVolTB ; airVolTB = airVol16/2 * iatCompFact/128 * baroFact/128;
  2595. ldd airVol16 ; d = airVol16
  2596. std temp6 ;
  2597. jsr mul816_baro ;
  2598. stab airVolB ; airVolB = airVol16/2 * baroFact/128
  2599.  
  2600. #ifdef E931
  2601. ;---------------------------------------------------
  2602. ; Set ftrimFlags.3 if speed exceed threshold (with
  2603. ; hysteresis) and port3.0 is set?????????
  2604. ;---------------------------------------------------
  2605. andm ftrimFlags, #$f7 ; Assume we reset flag $08, updated below
  2606. ldaa #$18 ; speed threshold = $18
  2607. brclr ftrimFlags, #$04, Md4d4 ; branch is flag not yet set
  2608. ldaa #$1c ; Flag already set, use higher threshold (lower speed threshold)
  2609. Md4d4 andm ftrimFlags, #$fb ; Assume we reset $04
  2610. cmpa vss ;
  2611. bcs L1067 ; Bail if speed < 24km/h (vss=1/speed...)
  2612. orm ftrimFlags, #$04 ; speed > 24km/h, set "threshold exceeded" bit
  2613. ldaa port3Snap0 ; Get stored port3
  2614. anda port3 ; Confirm bit is still set with current value
  2615. lsra ; Get confirmed bit 0 in carry
  2616. bcc L1067 ; Branch if bit was not set
  2617. orm ftrimFlags, #$08 ; Bit was still set, set flag bit
  2618. #endif
  2619.  
  2620. ;-----------------------------------------------
  2621. ; Set ftrimFlags.4 if rpm exceeds
  2622. ; threshold (around 1000rpm), with hysteresis
  2623. ;-----------------------------------------------
  2624. L1067 ldx #L1983 ; x points to initial threshold
  2625. brclr ftrimFlags, #$10, L1068 ; Branch if flag not yet set
  2626. inx ; Flag is set, go to next value (hysteresis)
  2627. L1068 .equ $
  2628. #ifdef E932
  2629. brset port3Snap0, #$20, L1069 ; branch if Park/neutral
  2630. inx ; even more threshold hysteresis...
  2631. inx ; even more threshold hysteresis...
  2632. #endif
  2633. L1069 ldaa rpm31 ;
  2634. andm ftrimFlags, #$ef ; Assume we reset $10
  2635. cmpa $00,x ; Compare rpm to treshold
  2636. bcs L1070 ; branch if rpm31 < L1983(flags...)
  2637. orm ftrimFlags, #$10 ; set flag indicating we are above rpm threshold
  2638.  
  2639. ;----------------------------------------------------------------------------------------
  2640. ; Update the fuel trim range (low, mid, high) according to mafRaw16. Table
  2641. ; t_ftrimRg provides the 2 thresholds with some hysteresis (+/-6Hz)
  2642. ; The trim range is stored in L00e3.0.1 (lowest 2 bits)
  2643. ;
  2644. ; old L00e3.0.1 resulting X new L00e3.0.1
  2645. ; 00 t_ftrimRg 00 if maf < t_ftrimRg(00) otherwise 01
  2646. ; 01 t_ftrimRg 00 if maf < t_ftrimRg(01) otherwise 01 if maf < t_ftrimRg(02) otherwise 10
  2647. ; 10 t_ftrimRg+1 01 if maf < t_ftrimRg(03) otherwise 10
  2648. ; 11 t_ftrimRg+1 01 if maf < t_ftrimRg(03) otherwise 10
  2649. ;
  2650. ; L00e3.0.1 meaning
  2651. ; 00 low trim (below first threshold)
  2652. ; 01 mid trim (between first and second threshold)
  2653. ; 10 high trim (above second threshold)
  2654. ; 11 Never used I think
  2655. ;----------------------------------------------------------------------------------------
  2656. L1070 ldx #t_ftrimRg ; X pointx to t_ftrimRg min1
  2657. ldd mafRaw16 ; d = mafRaw16
  2658. jsr scale64m ; d = mafRaw16/64 (thats equal to mafRaw...?)
  2659. tba ; a = mafRaw16/64 = mafRaw (6.25x)Hz
  2660. clrb ; b=0
  2661. brclr ftrimFlags, #$03, L1074 ;
  2662. brclr ftrimFlags, #$02, L1071 ;
  2663. inx ; X pointx to t_ftrimRg+1
  2664. bra L1073 ;
  2665. L1071 cmpa $01,x ;
  2666. bcs L1077 ; Branch if mafRaw16/64 < t_ftrimRg
  2667. L1073 cmpa $02,x ;
  2668. bcs L1076 ; Branch if mafRaw16/64 < t_ftrimRg
  2669. bra L1075 ;
  2670. L1074 cmpa $00,x ;
  2671. bcs L1077 ; Branch if mafRaw16/64 < t_ftrimRg
  2672. bra L1076 ;
  2673. L1075 incb ;
  2674. L1076 incb
  2675. L1077 ldaa ftrimFlags ; a = ftrimFlags
  2676. anda #$fc ; Reset trim range
  2677. aba ; Add new trim range
  2678. staa ftrimFlags ; Update ftrimFlags
  2679.  
  2680. ;---------------------------------------------------
  2681. ; Restart timer T40_ftrim2 on E931 if
  2682. ;
  2683. ; rpm > 1953rpm
  2684. ; or speed > 15 km/h
  2685. ; or speed < 2.5 km/h
  2686. ; or vss*rpm/15.625 < $cd8 (note speed ~ 1/vss)
  2687. ; or airVol > $38
  2688. ; or tpsDiffMax2 > $04
  2689. ;---------------------------------------------------
  2690. #ifdef E931
  2691. ldd rpm4 ;
  2692. jsr scale4m ;
  2693. cmpb #$7d ; 1953rpm
  2694. bcc Md551 ; Branch if rpm>1953rpm
  2695. ldaa vss ;
  2696. cmpa #$26 ; ~15km/h
  2697. bcs Md551 ; Branch if speed>15km/h
  2698. cmpa #$e2 ; ~2.5km/h
  2699. bcc Md551 ; Branch if speed<2.5km/h
  2700. mul ;
  2701. cmpd #$0cd8 ; d = vss*rpm/15.625
  2702. bcs Md551 ; branch if vss*rpm/15.625 < $cd8
  2703. ldaa airVol ;
  2704. cmpa #$38 ;
  2705. bcc Md551 ; Branch if airVol > $38
  2706. ldaa tpsDiffMax2 ;
  2707. cmpa #$04 ;
  2708. bcs L1078 ; Branch if tpsDiffMax2 < $04
  2709. Md551 ldaa #$78 ; 3 sec
  2710. staa T40_ftrim2 ;
  2711. #endif
  2712.  
  2713. ;---------------------------------------------------
  2714. ; Reload T40s_Idle as long as idle switch is off
  2715. ;---------------------------------------------------
  2716. L1078 brset port3Snap0, #$80, L1079 ; Branch if idle position switch on
  2717. ldaa #$1e ;
  2718. staa T40s_Idle ; Reload down counter (~0.75sec)
  2719.  
  2720. ;---------------------------------------------------------------------
  2721. ; Check for airVolT threshold with hysteresis and update T2_airVolT
  2722. ; ftrimFlags is set when airVolT > 24 and is reset when airVolT <= 15
  2723. ;---------------------------------------------------------------------
  2724. L1079 ldaa #$0f ; Threshold min
  2725. brset ftrimFlags, #$80, L1080 ;
  2726. ldaa #$18 ; Threshold max
  2727. L1080 andm ftrimFlags, #$7f ;
  2728. cmpa airVolT ; Compare current air volume
  2729. bcc L1081 ; Branch if airVolT <= threshold
  2730. orm ftrimFlags, #$80 ; airVolT > threshold, set bit
  2731. ldaa #$0a ; reset timer to 5 seconds
  2732. staa T2_airVolT ;
  2733. L1081 brset state2, #$08, L1083 ; Branch if no pulse accumulator interrupts received
  2734. brset state1, #$10, L1083 ; Branch if engine notRotating
  2735.  
  2736. ;-----------------------------------------------------------
  2737. ; Compute air volume used in fuel cut comparison
  2738. ; it uses 16 bits since 8 bit air volume saturate at ~1g of air/cas
  2739. ;-----------------------------------------------------------
  2740. ldd airVol16 ; d = airVol16
  2741. jsr scale4m ; b = airVol16/4 (makes sure it fits in b only...)
  2742. #ifdef extLoadRange ;
  2743. stab L0054 ;
  2744. #else ;
  2745. stab temp1 ; temp1 = airVol16/4
  2746. #endif ;
  2747. ldaa iatCompFact ; Correct for air temp
  2748. mul ;
  2749. jsr scale128m ; d = airVol16/4 * iatCompFact/128
  2750. ldaa baroFact ; a = baroFact
  2751. mul ;
  2752. jsr scale128m ; d = airVol16/4 * iatCompFact/128 * baroFact/128 (fits in b only)
  2753.  
  2754. ;---------------------------------------------------------------------------------------
  2755. ; Keep the minimum of airVol16/4 and airVol16/4 * iatCompFact/128 * baroFact/128
  2756. ;---------------------------------------------------------------------------------------
  2757. #ifdef extLoadRange
  2758. cmpb L0054 ;
  2759. bcs L1082 ;
  2760. ldab L0054 ;
  2761. #else
  2762. cmpb temp1 ;
  2763. bcs L1082 ; Branch if airVol16/4 * iatCompFact/128 * baroFact/128 <= airVol16/4
  2764. ldab temp1 ; Use max of airVol16/4
  2765. #endif
  2766.  
  2767. ;------------------------------------------------------------------------------
  2768. ; Check air volume for eventual fuel cut
  2769. ; When air volume exceeds a threshold, Timer T40_fuelCut
  2770. ; is not re-initialized on every loop (to 1s) and therefore starts
  2771. ; counting down. when it reaches 0, fuel cut is applied, see L1090 below
  2772. ;------------------------------------------------------------------------------
  2773. L1082 cmpb #fuelCutVal ; Air volume based fuel cut value $a0 = 1.25g/cas
  2774. #ifdef noFuelCut
  2775. brn L1084 ;
  2776. #else
  2777. bcc L1084 ; Branch if air volume>=threshold
  2778. #endif
  2779. L1083 ldab #$28 ; 1 sec
  2780. stab T40_fuelCut ; Re-init counter to 1 sec (Apply fuel cut only after threshold is exceeded for more than 1s)
  2781.  
  2782. ;-----------------------------------------------------------------
  2783. ; Section to update the state1 flags from various conditions
  2784. ;
  2785. ; Bits in b are used to accumulate various loads and states
  2786. ; In this section, b is only set in case we have
  2787. ; to bail to the state1 flag setting section
  2788. ;-----------------------------------------------------------------
  2789. L1084 ldab #$30 ; Starting "state1" value, b=00110000 (not rotating)
  2790. brclr state1, #$20, L1085 ; Bail if this is the first time we compute state1??
  2791. ldaa T40_engRot ;
  2792. beq L1085 ; Bail if engine not rotating
  2793. ldaa T40_noPower ;
  2794. bne L1086 ; Don't bail if timer not expired???
  2795. L1085 jmp L1100 ; bail
  2796.  
  2797. ;----------------------------------------------------
  2798. ; Engine rotating, check if key is in "start"
  2799. ; In this section, b is only set in case we have
  2800. ; to bail to the state1 flag setting section
  2801. ;----------------------------------------------------
  2802. L1086 ldab #$21 ; pre-load new state1 in case we have to bail, b=00100001 (startingToCrank)
  2803. brset port3Snap0, #$40, L1089 ; branch to next state if key not in start???
  2804.  
  2805. ;----------------------------------------------------
  2806. ; Key is in "start", check if rpm is higher than
  2807. ; threshold (engine running?)
  2808. ;----------------------------------------------------
  2809. ldaa #$0e ; starting rpm value (RPM/31.25) $0e = 437.25
  2810. brset state1, #$01, L1087 ; Branch if engine rotating bit was previously set
  2811. ldaa #$0b ; $0b = 343.75RPM
  2812. L1087 brclr injFlags0, #$20, L1088 ; Branch if temperature(ectFiltered) >= -8degC
  2813. adda #$02 ; temperature(ectFiltered) < -8degC, add 62.5 RPM
  2814. L1088 cmpa rpm31 ; compare threshold to current engine speed
  2815. bhi L1085 ; Bail if engine rpm lower than calculated value
  2816.  
  2817. ;---------------------------------------------------------------------
  2818. ; At this point,
  2819. ; key is in "start" or engine rpm is higher than minimum threshold,
  2820. ; minimum conditions are therefore met for the engine to start or be started?
  2821. ;
  2822. ; Use this state to check if we should get fuel injection. If we get stuck in
  2823. ; this state it means engine is rotating but something is wrong...
  2824. ;---------------------------------------------------------------------
  2825. ;---------------------------------------------------------------------
  2826. ; If enough time has elapsed, check if CAS is working normally
  2827. ;---------------------------------------------------------------------
  2828. L1089 ldab #$28 ; pre-load new state1 in case we have to bail, b=00101000 (trying to start but something is wrong...)
  2829. ldaa T40_start ;
  2830. adda #$50 ; add 2s
  2831. bcs L1090 ; Branch if key was out of start for less than 2s (when engine was upgraded from startingToCrank),
  2832. brclr faultHi, #$80, L1090 ; Its been more than ~2s since key was out of start, ECU has had enough time to check if CAS was working, check it, branch if no fault on CAS
  2833. ldaa tdcCasCount ; Fault code set...
  2834. cmpa #$04 ;
  2835. bcs L1085 ; Bail if tdcCasCount<4, this should not have happened at this time since engine has been rotating for a while
  2836.  
  2837. ;----------------------------------------------------------------------
  2838. ; Bail if fuel cut is active (T40_fuelCut=0)
  2839. ;----------------------------------------------------------------------
  2840. L1090 ldaa T40_fuelCut ; Fuel cut timer
  2841. beq L1085 ; Bail if timer 0 (fuel cut is active)
  2842.  
  2843. ;-----------------------------------------------
  2844. ; Bail if ECU is about to be shutoff
  2845. ;-----------------------------------------------
  2846. brset port3, #$02, L1085 ; Bail if IG1 at 0V, ECU is about to turn off after delay...?
  2847.  
  2848. ;-------------------------------------------------------------------------
  2849. ; At this point, minimum conditions are met for the engine
  2850. ; to start or run (rpm>thresh or start switch on), CAS is working,
  2851. ; there is no fuel cut and the ECU is not being turned off
  2852. ;
  2853. ; Basically we know that we should be injecting fuel, do a little more check below...
  2854. ;
  2855. ;
  2856. ; Calculate a maximum rpm that we should have based on maxRpm = baseRpm + rpmOffset
  2857. ; where rpmOffset is additional loads that we calculate below
  2858. ;
  2859. ; Below, a will contain baseRpm and b will be used to accumulate the additional loads as flags...
  2860. ;-------------------------------------------------------------------------
  2861. ;-----------------------------------------------
  2862. ; Get Initial RPM from ECT interpolated table
  2863. ;-----------------------------------------------
  2864. ldx #t_rpmEct ;
  2865. jsr interpEct ;
  2866. tba ; a = initial rpm idle speed, will be changed below (L1095)
  2867. clrb ; b = 00000000, no additionnal loads yet
  2868.  
  2869. ;-----------------------------------------------------------------
  2870. ; Check if T40s_Idle timer expired
  2871. ; (when idle position switch has been on for more than 0.75s)
  2872. ;-----------------------------------------------------------------
  2873. tst T40s_Idle ;
  2874. beq L1091 ; Branch if T40s_Idle already at zero (idle position switch on for more than 0.75s)
  2875.  
  2876. ;----------------------------------------------------------------
  2877. ; Timer not expired, decrement it at 40Hz
  2878. ;----------------------------------------------------------------
  2879. brclr Tclocks, #$01, L1091 ; Branch if basic 40Hz signal not set
  2880. dec T40s_Idle ; Decrement timer
  2881. brset port3Snap0, #$20, L1091 ; Ignore timer if in Park or Neutral (no transmission load)
  2882. beq L1092 ; Branch if T40s_Idle reached 0 this time
  2883.  
  2884. ;-------------------------
  2885. ; Add a load when ???
  2886. ;-------------------------
  2887. L1091 brclr state1, #$04, L1093 ; Branch if state1.2 (idle too fast) was not previously set
  2888. L1092 incb ; Add load
  2889. L1093 .equ $
  2890.  
  2891. ;--------------------------
  2892. ; Add "transmission" load
  2893. ;--------------------------
  2894. #ifdef E932
  2895. brset port3Snap0, #$20, L1094 ; Branch if in Park or Neutral
  2896. addb #$02 ; Set flag indicating "transmission load"
  2897. #endif
  2898. ;--------------------------
  2899. ; Add "A/C" load
  2900. ;--------------------------
  2901. L1094 brset port3Snap0, #$10, L1095 ; Branch if air conditioning switch is off (reverse logic)
  2902. addb #$04 ; A/C on, set flag b += 00000100
  2903.  
  2904. ;---------------------------------------------------------
  2905. ; Compute total rpm threshold from baseRpm+rpmOffset
  2906. ;---------------------------------------------------------
  2907. L1095 ldx #t_rpmEctOff ; x points to table of offsets
  2908. abx ; c points to desired offset
  2909. adda $00,x ; a = baseRpm+rpmOffset
  2910.  
  2911. ;---------------------------------------------------------------------
  2912. ; Based on that threshold, compute which state we will end-up with
  2913. ;---------------------------------------------------------------------
  2914. ;--------------------------------------------------------
  2915. ; If current rpm<threshold, use state1=00100000 (normal)
  2916. ;--------------------------------------------------------
  2917. cmpa rpm31 ; compare to current rpm
  2918. bhi L1099 ; Branch if current rpm lower than calculated value (engine is running normally?)
  2919. #ifdef E931
  2920. brset ftrimFlags, #$08, L1099 ; RPM is higher than threshold, branch anyway if speed>24km/h and IG2 related signal is set on E931??????
  2921. #endif
  2922.  
  2923. ;-----------------------------------------------------
  2924. ; rpm > threshold
  2925. ; if air volume low, use state1=00101100
  2926. ; i.e. runningFast and rotatingStopInj
  2927. ;-----------------------------------------------------
  2928. brset state2, #$08, L1096 ; Skip airVolT check / branch if no pulse accumulator interrupts received (mas broken, skip airFlow check?)
  2929. ldaa T2_airVolT ;
  2930. beq L1098 ; Branch if airVolT below threshold for more than 5s
  2931.  
  2932. ;-----------------------------------------------------
  2933. ; rpm > threshold and air volume high
  2934. ; If engine was started less than 5s ago, use state1=00100000 (normal)
  2935. ; i.e. high rev upon startup is normal
  2936. ;-----------------------------------------------------
  2937. L1096 ldaa T2_crank ;
  2938. adda #$0a ;
  2939. bcs L1099 ; branch if engine stopped "startingToCrank" less than 5s ago...
  2940. brset iscLrnFlags, #$20, L1099 ; branch if iscStStall has been updated
  2941.  
  2942. ;------------------------------------------------------------------------------
  2943. ; rpm > threshold and air volume high and engine started more than 10s ago
  2944. ; If idle switch is off, use state1=00100000 (normal)
  2945. ; i.e. we are stepping on the gas...
  2946. ;------------------------------------------------------------------------------
  2947. ldaa T40s_Idle ;
  2948. bne L1099 ; Branch if timer not yet 0, idle switch not on for more than 0.75s
  2949.  
  2950. ;---------------------------------------------------------------------------------
  2951. ; rpm > threshold and air volume high and engine started more than 10s ago
  2952. ; and idle switch has been on for more than 0.75s
  2953. ; use state1 = 00101100
  2954. ; i.e. runningFast and rotatingStopInj
  2955. ;---------------------------------------------------------------------------------
  2956. L1098 ldab #$2c ; b=00101100, this means the engine is running too fast
  2957. bra L1100 ;
  2958. L1099 ldab #$20 ; use b=00100000 (normal)
  2959.  
  2960. ;-------------------------------------------------------------
  2961. ; Set state1 flag if we are not receiving mas interrupts
  2962. ;-------------------------------------------------------------
  2963. L1100 brclr state2, #$08, L1101 ; Branch if pulse accumulator interrupts received
  2964. orab #$02 ; Set flag indicating we are not receiving pulse accumulator interrupts received
  2965.  
  2966. ;------------------------------------------------
  2967. ; At this point b has been set in preceeding
  2968. ; code to indicate current state, update state1
  2969. ;------------------------------------------------
  2970. L1101 ldaa state1 ;
  2971. anda #$80 ; Reset all except closed loop mode flag
  2972. aba ; Tranfser other flags set in code above
  2973. staa state1 ; Store new state
  2974.  
  2975. ;------------------------------------------------------
  2976. ; Compute index into maf compensation table t_masComp
  2977. ; since the values it contains are not equally spaced.
  2978. ; Basically remaps mafRaw16...
  2979. ;
  2980. ; Note that this mapping is the same for 1G and 2G
  2981. ; maf such that it doesn't need to be changed in case
  2982. ; 2G maf is used in 1G...
  2983. ;------------------------------------------------------
  2984. ldd mafRaw16 ; d = 16 bit mafRaw (a=mafRaw16/256)
  2985. ldy #L2054 ;
  2986. jsr pwiseLin ; d = T(L2054, mafRaw16) (a=T(L2054, mafRaw16/256))
  2987. std temp2 ; temp2:temp3 = T(L2054, mafRaw16)
  2988. jsr scale16m ; d = T(L2054, mafRaw16)/16 (b=16*T(L2054, mafRaw16/256))
  2989. cmpb #$80 ; Check for max of $80. Since max(T(L2054, mafRaw16/256))=20=1600Hz, we trim at $80/16=8=200Hz!
  2990. bcs L1103 ;
  2991. ldab #$80 ; Use max of $80
  2992.  
  2993. ;------------------------------------------------------------
  2994. ; Compute total maf compensation = masComp + t_masComp(Hz)
  2995. ;------------------------------------------------------------
  2996. L1103 stab temp5 ; temp5 = T(L2054, mafRaw16)/16 with max of $80
  2997. ldx #t_masComp ; x point to masCompensation table
  2998. ldd temp2 ; d = T(L2054, mafRaw16)
  2999. jsr interp1 ;
  3000. clra ; d = t_masComp(T(L2054, mafRaw16))
  3001. addb #masComp ; b = masComp + t_masComp(T(L2054, mafRaw16))
  3002. rola ; propagate carry bit in a,
  3003. std temp6 ; temp6:temp7 = d = t_masComp(T(L2054, mafRaw16)) = total MAS compensation
  3004.  
  3005. ;-------------------------------------------------------------------------
  3006. ; Compute conditioned L1992(iat) and compensate for barometric pressure
  3007. ;-------------------------------------------------------------------------
  3008. ldx #L1992 ;
  3009. jsr iatCInterp ; b = L1992(iat)
  3010. ldaa #$cd ; $cd is 1 bar for baroChecked
  3011. mul ; d = $cd*L1992(iat)
  3012. asld ; d = 2*$cd*L1992(iat)
  3013. div baroChecked ; d = 2*$cd*L1992(iat)/baroChecked
  3014. lsrb ; b = $cd*L1992(iat)/baroChecked = L1992(iat) * $cd/baroChecked = L1992(iat)*baroFactor where baroFactor=$cd/baroChecked equals 1.0 if baroChecked=1bar
  3015. adcb #$00 ; Round up result
  3016. ldx #$5222 ;
  3017. jsr clipOffset ; b = max(min(L1992(iat)*baroFactor,$52)-$22,0)
  3018.  
  3019. ;-----------------------------------------------------------------------
  3020. ; Compute airflow sensor linearity compensation factor from 2D table t_masLin
  3021. ; using max(min(L1992(iat)*baroFactor,$52)-$22,0)/16 for rows
  3022. ; and T(L2054, mafRaw16)/16 for columns, see t_masLin description
  3023. ;-----------------------------------------------------------------------
  3024. ldx #t_masLin ;
  3025. ldy #$0900 ;
  3026. ldaa temp5 ;
  3027. jsr lookup2D2 ; a = b = 2D interpolated t_masLin
  3028. stab masLinComp ;
  3029. jsr mul816_128 ; d = masLinComp * (masComp+t_masComp(xx))/128
  3030. std totMasComp ; totMasComp =(masComp+t_masComp(xx)) * t_masLin(xx)/128
  3031.  
  3032. ;-------------------------------------------------------------
  3033. ; Section to check if the o2 sensor is operating normally
  3034. ;-------------------------------------------------------------
  3035. ;-------------------------------------------------------------
  3036. ; If engine is notRotating, init rich/lean flag
  3037. ; and o2 sensor bad flag to default values
  3038. ;-------------------------------------------------------------
  3039. brclr state1, #$10, L1106 ; Branch if notRotating clear
  3040. orm closedLpFlags, #$c0 ; Assume o2Raw is rich and o2 sensor bad
  3041. ldaa o2Raw ; a = o2Raw
  3042. cmpa #$1f ;
  3043. bcc L1105 ; Branch if o2Raw >= 0.6v (rich)
  3044. andm closedLpFlags, #$7f ; o2Raw is lean, reset bit
  3045. L1105 bra L1114 ; Bail
  3046.  
  3047. ;-------------------------------------------------------
  3048. ; Choose how long to wait to check o2 sensor voltage
  3049. ; depending on ect (o2 sensor warm-up time...)
  3050. ;-------------------------------------------------------
  3051. L1106 ldaa T2_crank ; a = T2_crank
  3052. ldab ectFiltered ;
  3053. cmpb #$54 ; 41degC
  3054. bcs L1108 ; Branch if temperature(ectFiltered) > 41degC
  3055. adda #$58 ; a = T2_crank + $58 (44sec)
  3056. bra L1109 ;
  3057. L1108 adda #$1e ; a = T2_crank + $1e (15sec)
  3058.  
  3059. ;---------------------------------------------------------------------------------------
  3060. ; Update the rich/lean flag if sufficient time has elapsed since car was started
  3061. ;---------------------------------------------------------------------------------------
  3062. L1109 bcs L1114 ; bail if engine stopped "startingToCrank" less than 44 or 15 sec ago (depending en ect).
  3063. ldaa closedLpFlags ; a = old closedLpFlags
  3064. orm closedLpFlags, #$80 ; Assume result will be rich
  3065. ldab o2Raw ; b = o2Raw
  3066. cmpb #$1f ;
  3067. bcc L1111 ; Branch if o2Raw >= 0.6v (rich)
  3068. andm closedLpFlags, #$7f ; o2Raw is lean, Reset flag
  3069.  
  3070. ;--------------------------------------------------------
  3071. ; Check if flag value changed compared to the last time
  3072. ;--------------------------------------------------------
  3073. L1111 eora closedLpFlags ; Compare old closedLpFlags t new one
  3074. bmi L1112 ; Branch if rich/lean flag changed (reset o2 bad flag)
  3075.  
  3076. ;-----------------------------------
  3077. ; Rich/lean flag did not change
  3078. ;-----------------------------------
  3079. brclr state1, #$80, L1113 ; Reset timer and bail if open loop mode
  3080.  
  3081. ;----------------------------------------------
  3082. ; Closed loop mode and flag did not change yet
  3083. ; Check if timer is expired which would mean that
  3084. ; something is wrong (in closed loop mode, o2 sensor
  3085. ; voltage should have changed by now...)
  3086. ;----------------------------------------------
  3087. ldaa T2_o2Sensor ;
  3088. bne L1114 ; Bail if timer not yet expired
  3089. orm closedLpFlags, #$40 ; Timer expired, set o2 bad flag
  3090. bra L1114 ; Bail
  3091.  
  3092. ;------------------------------
  3093. ; Reset flag and restart timer
  3094. ;------------------------------
  3095. L1112 andm closedLpFlags, #$bf ; reset o2 bad flag
  3096. L1113 ldaa #$28 ; 20sec
  3097. staa T2_o2Sensor ; re-init timer to 20sec
  3098.  
  3099. ;--------------------------------------------------------------
  3100. ; Re-init T40_stInj0 to 1 sec if engine is not rotatingStopInj
  3101. ; This means that T40_stInj0 starts counting when state
  3102. ; changes to rotatingStopInj
  3103. ;--------------------------------------------------------------
  3104. L1114 brset state1, #$08, L1115 ; Branch if engine rotatingStopInj?
  3105. ldaa #$28 ; 1 sec
  3106. staa T40_stInj0 ;
  3107. bra L1116 ;
  3108.  
  3109. ;----------------------------------------------------------------
  3110. ; Re-init timer T40_stInj1 to 2 sec if engine
  3111. ; is rotatingStopInj and T40_stInj0 expired
  3112. ; This means that T40_stInj1 is only init when rotatingStopInj
  3113. ; has been active for more than 1 sec and will start counting
  3114. ; when rotatingStopInj is no more active. Will expire 2sec later.
  3115. ;----------------------------------------------------------------
  3116. L1115 ldaa T40_stInj0 ;
  3117. bne L1116 ; Branch if timer not expired
  3118. ldaa #$50 ;
  3119. staa T40_stInj1 ;
  3120.  
  3121. ;-------------------------------------------------------------
  3122. ; Section to decide between closed loop and open loop mode
  3123. ; (set/reset state1.7)
  3124. ;-------------------------------------------------------------
  3125. ;-------------------------------------------------------------
  3126. ; Have y point to airVol or airVolTB depending on baroChecked
  3127. ;-------------------------------------------------------------
  3128. L1116 ldy #airVol ;
  3129. ldaa baroChecked ;
  3130. cmpa #$9c ;
  3131. bcs L1117 ; Branch if baroChecked<0.76bar (I think??)
  3132. ldy #airVolTB ;
  3133.  
  3134. ;--------------------------------------------------------
  3135. ; Check airVolTB for first threshold (with hysteresis)
  3136. ;--------------------------------------------------------
  3137. L1117 ldx #t_closedLp1 ;
  3138. jsr interp16rpm ; b = t_closedLp1(rpm)
  3139. brclr closedLpFlags, #$01, L1118 ; Branch if we were not above the threshold the last time we checked
  3140. subb #$06 ; b = t_closedLp1(rpm)-6 (hysteresis)
  3141. bcc L1118 ; Branch if no underflow
  3142. clrb ; Use min of 0
  3143. L1118 andm closedLpFlags, #$fc ; Reset 000000011
  3144. cmpb $00,y ; Notice implicit y = y + 1 here!!!!!!!!!!!
  3145. bls L1119 ; Branch if t_closedLp1(rpm) <= airVol or airVolTB
  3146.  
  3147. ;---------------------------------------------------------
  3148. ; airVolTB smaller than threshold, closed loop is
  3149. ; therefore an option. Re-init timer T2_closedLp to 20sec
  3150. ; or 12sec and then continue trying to go to closed loop
  3151. ;---------------------------------------------------------
  3152. #ifdef E931
  3153. ldaa #$28 ; 20 sec
  3154. #else
  3155. ldaa #$18 ; 12 sec
  3156. #endif
  3157. staa T2_closedLp
  3158. bra L1122 ; Branch to continue closed loop checking
  3159.  
  3160. ;--------------------------------------------------------------------------------
  3161. ; At this point airVolTB is higher than first threshold. Normally,
  3162. ; the airflow is too high to be in closed loop mode but in order to account
  3163. ; for variations, we will remain in closed loop for a certain time
  3164. ; (T2_closedLp) as long as we are below a second threshold t_closedLp2(rpm). If
  3165. ; we go over that second threshold, we go to open loop immediatly. This is
  3166. ; implementing aiflow hysteresis under specific rpm conditions
  3167. ;
  3168. ; Check if airVolTB higher than second threshold (with an hysteresis of 6)
  3169. ;--------------------------------------------------------------------------------
  3170. L1119 orm closedLpFlags, #$01 ; Set flag indicating we are above the first threshold
  3171. #ifdef E931
  3172. ldx #t_closedLp2 ;
  3173. jsr interp16rpm ; b = t_closedLp2(rpm)
  3174. #else
  3175. jmp L1978 ; Jump to code patch for E932 rpm calculation..., jumps back here afterwards...
  3176. L1120 jsr interp16b ;
  3177. #endif
  3178. brset state1, #$80, L1121 ; Branch if closed loop mode
  3179. subb #$06 ; b = t_closedLp2(rpm)-6 (threshold hysteresis)
  3180. bcc L1121 ; Branch if underflow
  3181. clrb ; Use min of 0
  3182. L1121 decy ; y points back to airVol or airVolTB (implicit y=y+1 above...)
  3183. cmpb $00,y ; Notice implicit y = y+1 here!!!!!!!!!!!
  3184. bls L1126 ; Use open loop if airVolTB higher than second threshold
  3185.  
  3186. ;---------------------------------------------------------
  3187. ; airVolTB smaller than second threshold, we could
  3188. ; therefore remain in closed loop if timer not expired
  3189. ;
  3190. ; Check if T2_closedLp timer is expired
  3191. ;---------------------------------------------------------
  3192. ldaa T2_closedLp ;
  3193. beq L1126 ; Use open loop mode if T2_closedLp expired
  3194.  
  3195. ;----------------------------------------------------
  3196. ; Check tspRaw threshold with hysteresis to know
  3197. ; if closed loop is an option
  3198. ;
  3199. ; Go to open loop if
  3200. ; tpsRaw >= t_closedLp3(rpm)
  3201. ; Closed loop is possible if
  3202. ; tpsRaw < t_closedLp3(rpm)-$0d (hysteresis)
  3203. ;
  3204. ;----------------------------------------------------
  3205. L1122 ldx #t_closedLp3 ; x = t_closedLp3
  3206. jsr interp16rpm ; b = t_closedLp3(rpm)
  3207. brset state1, #$80, L1124 ; Branch if closed loop mode
  3208. subb #$0d ; b = t_closedLp3(rpm) - $0d
  3209. bcc L1124 ; Branch if no underflow
  3210. clrb ; Use min of 0
  3211. L1124 cmpb tpsRaw ;
  3212. bls L1126 ; Branch to use open loop if t_closedLp3(rpm)<= tpsRaw
  3213.  
  3214. ;-----------------------------------------------------
  3215. ; We could use closed loop, check a few more things
  3216. ;-----------------------------------------------------
  3217. brset state1, #$1b, L1126 ; Use open loop if engine is either notRotating or rotatingStopInj or runningFast
  3218. brset coilChkFlags, #$80, L1126 ; Use open loop if ignition problem is detected
  3219. brclr ftrimFlags, #$80, L1126 ; Use open loop if airVolT < threshold (15 or 24, used for fTrim...). Means airflow is too low???
  3220. orm closedLpFlags, #$02 ; Set flag indicating we should be using closed loop mode????
  3221. ldaa T40_stInj1 ;
  3222. bne L1126 ; Use open loop if rotatingStopInj has been active for more than 1 sec (and 2 sec after)
  3223. brset closedLpFlags, #$40, L1126 ; Use open loop if o2 sensor is bad
  3224. ldaa ectFiltered ;
  3225. #ifdef E931
  3226. cmpa #$6a ; 31degC
  3227. #else
  3228. cmpa #$70 ; 28degC
  3229. #endif
  3230.  
  3231. #ifdef noClosedLoop
  3232. bra L1126 ;
  3233. #else
  3234. bhi L1126 ; Use open loop if temperature(ectFiltered) < 31degC
  3235. #endif
  3236.  
  3237. ;-----------------------------------------------------
  3238. ; Use closed loop mode, set flag
  3239. ;-----------------------------------------------------
  3240. orm state1, #$80 ; Go into closed loop mode
  3241. bra L1127 ; Bail
  3242.  
  3243. ;---------------------------------
  3244. ; Use open loop mode, reset flag
  3245. ;---------------------------------
  3246. L1126 andm state1, #$7f ; Go into open loop mode
  3247.  
  3248. ;-----------------------------------
  3249. ; Reset o2Fbk in some cases
  3250. ; open loop for instance...
  3251. ;-----------------------------------
  3252. L1127 brset fpsBcsFlags, #$04, L1129 ; Branch to reset if the fuel pressure solenoid was just deactivated
  3253. brset varFlags0, #$02, L1130 ; Bail if hot start flag is set
  3254. brset state1, #$80, L1130 ; Bail if closed loop mode
  3255. L1129 ldd #$8080 ;
  3256. std o2Fbk ;
  3257.  
  3258. ;--------------------------------------------------
  3259. ; Re-init timer T40_o2Fbk to 4 sec if
  3260. ; currentTrimRange!=low (or high speed, E931 only)
  3261. ;
  3262. ; T40_o2Fbk will be 0 when the low trim range will
  3263. ; will have been used for more than 4 sec
  3264. ;--------------------------------------------------
  3265. L1130 brclr ftrimFlags, #$13, L1131 ; Branch if currentTrimRange=low and rpm<threshold
  3266. ldaa #$a0 ; 4sec
  3267. staa T40_o2Fbk ; T40_o2Fbk = 4sec
  3268.  
  3269. ;--------------------------------------------------------------------
  3270. ; Find which table we should be using depending on config resistors
  3271. ; (one of L1999, L2000, L2001, L2002)
  3272. ;--------------------------------------------------------------------
  3273. L1131 ldx #t_strap2 ;
  3274. jsr cfgLookup16 ; x = t_strap2(2*(config2 & $03)) = tableAddress
  3275.  
  3276. ;----------------------------------------------------------
  3277. ; Use o2Fbk_dec:o2Fbk_inc = t_o2Fbk1 if timer expired
  3278. ; i.e. we have been in low trim range for more than 4sec
  3279. ;----------------------------------------------------------
  3280. ldaa T40_o2Fbk ;
  3281. bne L1132 ; Branch if timer not expired
  3282. ldd t_o2Fbk1 ; Timer expired, use t_o2Fbk1
  3283. bra L1138 ; Bail to store
  3284.  
  3285. ;--------------------------------------------------------------------------
  3286. ; Timer not expired, compute values for o2Fbk_dec:o2Fbk_inc
  3287. ; from table pointed by x (see above, one of L1999, L2000, L2001, L2002)
  3288. ; Use b as index into table. Start with b = 0
  3289. ;--------------------------------------------------------------------------
  3290. L1132 clrb ; b = 0
  3291.  
  3292. ;-------------------------------------------------------------
  3293. ; b = b+1 if airVolTB >= threshold
  3294. ; Threshold based on config resistors (AWD vs FWD???)
  3295. ;-------------------------------------------------------------
  3296. ldaa airVolTB ; a = airVolTB
  3297. #ifdef E931
  3298. cmpa #$40 ;
  3299. brclr config2, #$80, L1133 ; Branch if ??? (same as branching if FWD)
  3300. cmpa #$40 ;
  3301. #else
  3302. cmpa #$48 ;
  3303. brclr config2, #$80, L1133 ;
  3304. cmpa #$50 ;
  3305. #endif
  3306. L1133 bcs L1134 ; Branch if airVolTB < threshold
  3307. incb ; airVolTB > threshold, b +=1 (go to next value)
  3308.  
  3309. ;-------------------------------------------------------------
  3310. ; b = b+2 if rpm31 >= (1500rpm or 1406rpm)
  3311. ; b+4 if rpm31 >= (2094rpm or 2313rpm)
  3312. ;-------------------------------------------------------------
  3313. L1134 ldaa rpm31 ;
  3314. cmpa #$2d ;
  3315. brclr config2, #$80, L1135 ; Branch if ??? (same as branching if FWD)
  3316. #ifdef E931
  3317. cmpa #$30 ;
  3318. #else
  3319. cmpa #$2d ;
  3320. #endif
  3321. L1135 bcs L1137 ; Branch if rpm31 < threshold (1500rpm or 1406rpm)
  3322. addb #$02 ; rpm31 > (1500rpm or 1406rpm, b += 2
  3323. cmpa #$43 ; 2094rpm
  3324. brclr config2, #$80, L1136 ; Branch if ??? (same as branching if FWD)
  3325. #ifdef E931
  3326. cmpa #$4a ; 2313rpm
  3327. #else
  3328. cmpa #$43 ; 2094rpm
  3329. #endif
  3330. L1136 bcs L1137 ;
  3331. addb #$02 ; rpm31 > (2313rpm or 2094rpm, b += 2
  3332.  
  3333. ;---------------------------------------------
  3334. ; interpolate table from x+b
  3335. ; (x is one of L1999, L2000, L2001, L2002)
  3336. ;---------------------------------------------
  3337. L1137 abx ;
  3338. ldaa $00,x ;
  3339. ldab $06,x ; ???????????
  3340.  
  3341. ;------------------------------------------------
  3342. ; Update o2Fbk_dec and o2Fbk_inc with new values
  3343. ;------------------------------------------------
  3344. L1138 std o2Fbk_dec
  3345.  
  3346. ;-------------------------------------------------------------
  3347. ; If we are in closed loop mode, limit the range of o2Fbk
  3348. ; depending on ect and then compute o2FuelAdj (how much
  3349. ; fuel to add/remove based on o2 sensor in closed loop....)
  3350. ;
  3351. ; Notice that part of the code has been located somewhere
  3352. ; else... (L1973)
  3353. ;-------------------------------------------------------------
  3354. ldaa #$80 ; pre-load default value of $80 (no fuel adjustment)
  3355. brclr state1, #$80, L1148 ; Branch if open loop mode
  3356.  
  3357. ;----------------------------------------------------
  3358. ; We are in closed loop mode, limit the range
  3359. ; of o2Fbk to $4d-$d6 or $2a-$d6 depending on ect
  3360. ;----------------------------------------------------
  3361. jmp L1973 ; Jump to code snipet for closed loop mode, will jump back to main code as appropriate
  3362. nop
  3363.  
  3364. ;------------------------------------------------
  3365. ; Continuation of code...
  3366. ;------------------------------------------------
  3367. ;---------------------------------------
  3368. ; temperature(ectFiltered) > 86degC
  3369. ; Check for min and max of $2a and $d6
  3370. ;---------------------------------------
  3371. L1140 bcc L1141 ; Branch if o2Fbk >= $2a
  3372. ldaa #$2a ; Use min of $2a
  3373. bra L1142 ;
  3374. L1141 cmpa #$d6 ;
  3375. bcs L1143 ; Branch if o2Fbk < $d6
  3376. ldaa #$d6 ; Use max of $d6
  3377.  
  3378. ;--------------------------
  3379. ; Store new value of o2Fbk
  3380. ;--------------------------
  3381. L1142 clrb ; Set lower 8 bit of o2Fbk
  3382. std o2Fbk ;
  3383.  
  3384. ;-----------------------------------------------------------------------------
  3385. ; Compute o2FuelAdj = o2Fbk +/- t_closedLpV1(xx) or t_closedLpV2(xx) or $02
  3386. ; where +/- depends on o2Raw (lean or rich).
  3387. ;-----------------------------------------------------------------------------
  3388. L1143 psha ; st0 = o2Fbk high byte
  3389. #ifdef E931 ;
  3390. ldab #$02 ; b = $02
  3391. ldaa T40_ftrim2 ; a = T40_ftrim2
  3392. beq L1146 ; Branch if timer expired, use $02 instead of table values if conditions are stable on E931
  3393. #else ;
  3394. ldx #t_closedLpV2 ; x = t_closedLpV2
  3395. brset port3Snap0, #$20, L1144 ; branch if Park/neutral
  3396. #endif
  3397. ldx #t_closedLpV1 ; x = t_closedLpV1
  3398. L1144 brclr ftrimFlags, #$13, L1145 ; branch if trim range is low and rpm<threshold???
  3399. inx ; go to next value in table
  3400. L1145 ldab $00,x ; b = = t_closedLpV1(xx) or t_closedLpV2(xx)
  3401. L1146 ldaa o2Raw ; a = o2Raw
  3402. cmpa #$1a ; 0.5V
  3403. pula ; a = o2Fbk
  3404. bcc L1147 ; Branch if o2Raw > 0.5V
  3405. aba ; o2 lean, a = o2Fbk + t_closedLpV1(xx) or t_closedLpV2(xx)
  3406. bcc L1148 ; branch if no overflow
  3407. ldaa #$ff ; Use max in case of overflow
  3408. bra L1148 ; Branch to store o2FuelAdj
  3409.  
  3410. L1147 sba ; o2 rich, a = o2Fbk - t_closedLpV1(xx) or t_closedLpV2(xx)
  3411. bcc L1148 ; branch if no underflow
  3412. clra ; Use min value of 0
  3413.  
  3414. ;---------------------
  3415. ; Store new o2FuelAdj
  3416. ;---------------------
  3417. L1148 staa o2FuelAdj ; o2Fbk +/- table value for fuel compensation in closed loop
  3418.  
  3419. ;-------------------------------------------------------------
  3420. ; Transfer ftrimFlags to oldFtrimFlg, a = old oldFtrimFlg
  3421. ;-------------------------------------------------------------
  3422. ldaa oldFtrimFlg ;
  3423. ldab ftrimFlags ;
  3424. stab oldFtrimFlg ;
  3425.  
  3426. ;--------------------------------------------------------------
  3427. ; Section to check whether conditions are sufficiently
  3428. ; stable to update fuel trims. Fuel trims are updated
  3429. ; only if T40_ftrim = 0
  3430. ;
  3431. ; Restart timer T40_ftrim at 5s under all the following conditions
  3432. ;
  3433. ; if fuel trim range changed
  3434. ; or open loop mode
  3435. ; or airVolTB too high
  3436. ; or ectRaw malfunction
  3437. ; or iatRaw malfunction
  3438. ; or baroRaw malfunction
  3439. ; or temperature(ectFiltered) < 86degC
  3440. ; or temperature(iatChecked) >= 50degC
  3441. ; or baroChecked < 0.76bar
  3442. ; or baroChecked >= 1.05bar
  3443. ; or accEnr not 0
  3444. ; or airDiffNeg1 >= accEnrDiffT
  3445. ; or airVolT too small
  3446. ; or purge solenoid activated
  3447. ; or fuel pressure solenoid activated
  3448. ; or T40_ftrim2 expired (E931)
  3449. ; or T0p5_crCold not expired
  3450. ;
  3451. ;--------------------------------------------------------------
  3452. eora ftrimFlags ;
  3453. anda #$03 ; a = (oldFtrimFlg eor ftrimFlags) & $03
  3454. bne L1150 ; Branch if trim rancge changed
  3455. brclr state1, #$80, L1150 ; Branch if open loop mode
  3456. brset closedLpFlags, #$01, L1150 ; Branch if airVolTB too high
  3457. brset state2, #$07, L1150 ; Branch if ectRaw, iatRaw or baroRaw in error
  3458. ldaa ectFiltered ;
  3459. #ifdef E931
  3460. cmpa #$1c ; 86degC
  3461. #else
  3462. cmpa #$1b ; 88degC
  3463. #endif
  3464. bhi L1150 ; Branch if temperature(ectFiltered) < 86degC
  3465. ldaa iatChecked ;
  3466. cmpa #$49 ;
  3467. bls L1150 ; Branch if temperature(iatChecked) >= 50degC
  3468. ldaa baroChecked ;
  3469. cmpa #$9c ;
  3470. bcs L1150 ; Branch if baroChecked < 0.76bar?
  3471. cmpa #$d8 ;
  3472. bcc L1150 ; Branch if baroChecked >= 1.05bar?
  3473. ldaa accEnr ;
  3474. bne L1150 ; Branch if accEnr not 0 (we are applying enrichment during acceleration)
  3475. ldaa airDiffNeg1 ;
  3476. cmpa accEnrDiffT ;
  3477. bcc L1150 ; Branch if airDiffNeg1 >= accEnrDiffT (we will apply decceleration enrichment????)
  3478. ldaa airVolT ;
  3479. cmpa #$18 ;
  3480. bcs L1150 ; Branch if airVolT < $18 (air volume too low)
  3481. brclr port6, #$10, L1150 ; Branch if purge solenoid activated
  3482. brclr port5, #$10, L1150 ; Branch if fuel pressure solenoid activated
  3483. #ifdef E931
  3484. ldaa T40_ftrim2 ;
  3485. beq L1150 ; Branch if timer T40_ftrim2 expired on E931???
  3486. #endif
  3487. ldaa T0p5_crCold ;
  3488. beq L1151 ; Branch if T0p5_crCold expired, meaning its been more than 120sec since we started a cold engine (we can update trims...)
  3489.  
  3490. ;-----------------------------------------------------
  3491. ; Conditions not stable, Re-init T40_ftrim at 5 sec
  3492. ;-----------------------------------------------------
  3493. L1150 ldaa #$c8 ; 5 sec
  3494. staa T40_ftrim ;
  3495.  
  3496. ;------------------------------------------------------------------
  3497. ; Get current fuel trim value according to current fuel trim range
  3498. ;------------------------------------------------------------------
  3499. L1151 ldx #ftrim_low ;
  3500. ldab ftrimFlags ;
  3501. andb #$03 ; Get current fuel trim range to update
  3502. abx ; X point to fuel trim
  3503. ldaa $00,x ; a = fuelTrim
  3504. ldab #$80 ; pre-load $80 in case we bail
  3505.  
  3506. ;----------------------------------------------
  3507. ; Don't update trim if T40_ftrim not yet expired
  3508. ;----------------------------------------------
  3509. tst T40_ftrim ;
  3510. bne L1153 ;
  3511.  
  3512. ;-------------------------------------------------------------------------------
  3513. ; Update fuel trim at 40Hz
  3514. ; fuel trim is actually increased/decreased by 1 at 40Hz/(256/5) = 0.78125Hz
  3515. ;-------------------------------------------------------------------------------
  3516. brclr Tclocks, #$01, L1154 ; Branch if 40Hz signal not set
  3517. ldab o2Fbk ; b = o2Fbk
  3518. cmpb #$80 ;
  3519. beq L1154 ; branch if o2Fbk = 100% (no update)
  3520. ldab ftrimCntr ; b = ftrimCntr
  3521. bcs L1152 ; branch if o2Fbk < 100%
  3522. addb #$05 ; b = ftrimCntr + 5
  3523. adca #$00 ; a = fuelTrim+1 if ftrimCntr rolled over (o2Fbk + 5)>255
  3524. bra L1153 ;
  3525. L1152 subb #$05 ; b = ftrimCntr - 5
  3526. sbca #$00 ; a = fuelTrim-1 if ftrimCntr rolled under (o2Fbk - 5)<0
  3527.  
  3528. ;------------------------------
  3529. ; Update ftrimCntr with new value
  3530. ;------------------------------
  3531. L1153 stab ftrimCntr ;
  3532.  
  3533. ;------------------------------------------------
  3534. ; Check a = updated trim value for min/max values
  3535. ;------------------------------------------------
  3536. L1154 cmpa #$68 ;
  3537. bcc L1155 ; Branch if new fuelTrim > $68 (81%)
  3538. ldaa #$68 ; use min
  3539. L1155 cmpa #ftrimMax ;
  3540. bls L1156 ; Branch if new fuelTrim <= max (~140%)
  3541. ldaa #ftrimMax ; use max
  3542.  
  3543. ;---------------------------------------------------------------
  3544. ; Update the stored fuel trim with updated value (in a) and decide
  3545. ; whether we will apply the fuel trim to injector pulse width
  3546. ;---------------------------------------------------------------
  3547. L1156 staa $00,x ; Store new fuel trim value
  3548. ldaa #$80 ; Assume we won't apply fuel trim, a = $80 (100% fuel trim)
  3549. brset state2, #$08, L1157 ; Branch to use 100% if pulse accumulator interrupts are not being received
  3550. brset closedLpFlags, #$01, L1157 ; Branch to use 100% if the "air volume (airVolTB) is too high to use closed loop mode (first threshold)"
  3551. ldaa $00,x ; Load fuel trim from the current range
  3552. L1157 staa workFtrim ; Store working fuel trim
  3553.  
  3554. ;--------------------------------------------------------
  3555. ; Compute coldTempEnr, fuel enrichment factor when engine
  3556. ; is cold...Depends on ect and airflow
  3557. ;
  3558. ; coldTempEnr/$80 = 1 + (f1-1)*f2
  3559. ; 1 + ectNetEnrichment*f2
  3560. ;
  3561. ; where f1 is t_ectEnr(ectCond)/$80, f1>=1.0
  3562. ; f2 is t_airEnr(airVolCond)/$80, f2>=1.0
  3563. ;
  3564. ; Basically this factor adds fuel enrichment under
  3565. ; cold temperature which is reduced down to no enrichement
  3566. ; (coldTempEnr/$80=1.0) as airVolCond increases, i.e. fuel
  3567. ; enrichement is only required under low temperature and
  3568. ; low airflow
  3569. ;--------------------------------------------------------
  3570. ldx #t_ectEnr ;
  3571. jsr interpEct ; b = t_ectEnr(ectCond)
  3572. clra ;
  3573. subb #$80 ; d = t_ectEnr(ectCond)-$80
  3574. bcc L1158 ; Branch if no overflow
  3575. clrb ; Use min of 0
  3576. L1158 std temp6 ; temp6:temp7 = t_ectEnr(ectCond)-$80
  3577. ldx #t_airEnr ;
  3578. ldaa airVolCond ;
  3579. jsr interp16b ; b = t_airEnr(airVolCond)
  3580. ldaa rpm31 ;
  3581. cmpa #$30 ;
  3582. bcc L1159 ;
  3583. ldab #$80 ; Use b=$80 if rpm<1500
  3584. L1159 jsr mul816_128 ; d = t_airEnr(airVolCond) * (t_ectEnr(ectCond)-$80)/$80
  3585. addb #$80 ; b = t_airEnr(airVolCond)*(t_ectEnr(ectCond)-$80)/$80 + $80
  3586. stab coldTempEnr ; coldTempEnr = t_airEnr(airVolCond) * (t_ectEnr(ectCond)-$80)/$80 + $80
  3587.  
  3588.  
  3589. ;----------------------------------------------------------------
  3590. ; Section to update openLoopEnr enrichment factor if in open loop
  3591. ;----------------------------------------------------------------
  3592. ldab #$80 ; Assume an enrichement factor of 1.0
  3593. brset state1, #$80, L1167 ; Branch if closed loop mode
  3594.  
  3595. ;-------------------------------------------------------------
  3596. ; Open loop
  3597. ; Compute conditionned rpm and load for 2D map interpolation
  3598. ;-------------------------------------------------------------
  3599. ldab rpm31 ; b = rpm31
  3600. ldaa #$d0 ; 6500 RPM
  3601. jsr rpmRange ; get rpm for map interpolation, b = min(max(RPM31p25-#$10, 0), $d0) = min(max(RPM31p25-500rpm,0),6500rpm)
  3602. stab temp6 ; temp6 = conditionned rpm
  3603. jsr getLoadForMaps ; get the load value for map interpolation
  3604. stab temp7 ; temp7 = conditionned load
  3605.  
  3606. ;----------------------------------------------
  3607. ; Get basic fuel enrichement from 2D fuel map
  3608. ;----------------------------------------------
  3609. ldx #t_fuelMap ;
  3610. ldy #$0e00 ;
  3611. jsr lookup2D ; a = b = 2D interpolated fuel map value from temp6 (rpm) and temp7 (load)
  3612.  
  3613. ;----------------------------------------
  3614. ; Check airVol vs. RPM (deceleration???)
  3615. ;----------------------------------------
  3616. ldaa airVol ;
  3617. cmpa #$af ;
  3618. bcs L1162 ; branch if airVol<$af
  3619. ldaa rpm31 ;
  3620. #ifdef E931
  3621. cmpa #$46 ; 2187rpm
  3622. #else
  3623. cmpa #$53 ; 2594rpm
  3624. #endif
  3625. bcs L1162 ; branch if current rpm smaller than threshold
  3626. ldaa timFuelEnr ; a = timing/knock based fuel enrichement
  3627. aba ; a = basicFuelEnrichement + timingKnockFuelEnrichment
  3628. bcs L1163 ; branch if overflow
  3629. tab ; b = basicFuelEnrichement + timingKnockFuelEnrichment
  3630.  
  3631. ;-----------------------------------------------------------------------
  3632. ; Check fuel compensation + timing/knock based enrichment for max value
  3633. ;-----------------------------------------------------------------------
  3634. L1162 cmpb #fuelMapClip ;
  3635. bls L1164 ; Branch if below max
  3636. L1163 ldab #fuelMapClip ; Use max
  3637. L1164 pshb ; Store basicFuelEnrichement + timingKnockFuelEnrichment on stack
  3638.  
  3639. ;-----------------------------------
  3640. ; Compute TPS based fuel enrichment
  3641. ;-----------------------------------
  3642. ldab tpsRaw ;
  3643. ldx #$b080 ;
  3644. jsr clipOffset ; b = max(min(tpsRaw,$b0)-$80,0)-> returns b = $00 to $30 (50% to 69%)
  3645. tba ; a = conditionned TPS for table interpolation
  3646. ldx #t_tpsEnr ;
  3647. jsr interp16b ; a = t_tpsEnr(tpsRaw)
  3648.  
  3649. ;-----------------------------------------------------------------------------------------
  3650. ; Keep the highest of t_tpsEnr(tpsRaw) and "basicFuelEnrichement + timingKnockFuelEnrichment"
  3651. ;-----------------------------------------------------------------------------------------
  3652. pulb ; b = basicFuelEnrichement + timingKnockFuelEnrichment
  3653. cba ;
  3654. bcs L1165 ; branch if basicFuelEnrichement + timingKnockFuelEnrichment
  3655. tab ; b = max(t_tpsEnr(tpsRaw), basicFuelEnrichement + timingKnockFuelEnrichment)
  3656.  
  3657.  
  3658. ;-----------------------------------------------------------
  3659. ; Compute timer T2_hotEnrich based fuel enrichement if required
  3660. ;-----------------------------------------------------------
  3661. L1165 brclr varFlags0, #$02, L1167 ; Bail if "hot start" flag was not set
  3662. pshb ; save on stack
  3663. ldab #$30 ;
  3664. ldaa T2_hotEnrich ;
  3665. mul ;
  3666. adda #$80 ; d = T2_hotEnrich*$30 + $80
  3667.  
  3668. ;---------------------
  3669. ; Keep the highest
  3670. ;---------------------
  3671. pulb ; b = max(t_tpsEnr(tpsRaw), basicFuelEnrichement + timingKnockFuelEnrichment)
  3672. cba ;
  3673. bls L1167 ;
  3674. tab ; max(T2_hotEnrich*$30 + $80, t_tpsEnr(tpsRaw), basicFuelEnrichement + timingKnockFuelEnrichment)
  3675.  
  3676. ;-------------------------------------------
  3677. ; Update openLoopEnr with the above result
  3678. ;-------------------------------------------
  3679. L1167 stab openLoopEnr ; Store final value
  3680.  
  3681. ;------------------------------------------------------------------
  3682. ; Update T2_hotEnrich and varFlags0.1 (hot start) used in timer based enrichement above
  3683. ;------------------------------------------------------------------
  3684. brclr state1, #$90, L1168 ; Branch if notRotating and closed loop clear
  3685. andm varFlags0, #$fd ; closedLoop or notRotating, reset flag and reset timer
  3686. clra ; a = 0
  3687. bra L1169 ; Update timer with 0
  3688.  
  3689. L1168 brclr state1, #$01, L1171 ; open loop and at least rotating, Bail if startingToCrank clear
  3690. ldaa iatChecked ; Engine startingToCrank, a = iatChecked
  3691. cmpa #$3a ;
  3692. bhi L1171 ; Bail if temperature(iatChecked) < 60degC
  3693. ldaa ectFiltered ;
  3694. cmpa #$18 ; 93degC
  3695. bhi L1171 ; Bail if temperature(ectFiltered) < 93degC
  3696.  
  3697. ;-----------------------------------------------------------------------------
  3698. ; At this point, engine is startingToCrank and we are in open loop
  3699. ; and temperature(iatChecked) >= 60degC and
  3700. ; temperature(ectFiltered) >= 93degC (hot start)
  3701. ;
  3702. ; Set hot start flag, init o2Fbk to lean(??) and re-init T2_hotEnrich timer to 120sec
  3703. ;-----------------------------------------------------------------------------
  3704. orm varFlags0, #$02 ; Set varFlags0.1 flag (hot start)
  3705. ldaa #$d6 ;
  3706. ldab #$80 ;
  3707. std o2Fbk ; o2Fbk = $d680 (lean?)
  3708. ldaa #$f0 ; Re-init timer with 120sec
  3709. L1169 staa T2_hotEnrich ;
  3710.  
  3711. ;----------------------------------------------
  3712. ; Update enrWarmup when engine startingToCrank
  3713. ; get enrWarmup timer value from table
  3714. ;----------------------------------------------
  3715. L1171 clrb ;
  3716. brset state1, #$10, L1172 ; Branch if notRotating
  3717. brclr state1, #$01, L1173 ; Branch if startingToCrank clear
  3718. ldx #t_enrWarmup ;
  3719. jsr interpEct ;
  3720. L1172 stab enrWarmup ;
  3721. bra L1174 ;
  3722.  
  3723. ;-----------------------------------------------------------------------------------------
  3724. ; Update enrWarmup at 40Hz
  3725. ;
  3726. ; T_enrWarm is decremented at 40Hz and loops at 2 if enrWarmup>$1a or loops
  3727. ; at $18 otherwise decrement enrWarmup each time T_enrWarm reaches 0
  3728. ;
  3729. ; This allows to have rapid lowering of enrWarmup at first and then slow one
  3730. ; enrWarmup is decremented at 20Hz until it reached $1a (fuel enrichment factor of 141%)
  3731. ; and then at 1.67Hz
  3732. ;-----------------------------------------------------------------------------------------
  3733. L1173 brclr Tclocks, #$01, L1176 ; Bail if 40Hz signal not set
  3734. ldaa enrWarmup ;
  3735. beq L1176 ;
  3736. dec T_enrWarm ;
  3737. bne L1176 ;
  3738. dec enrWarmup ;
  3739.  
  3740. L1174 ldaa #$02 ;
  3741. ldab enrWarmup ;
  3742. cmpb #$1a ;
  3743. bhi L1175 ; Branch if enrWarmup>$1a
  3744. ldaa #$18 ; Reset T_enrWarm counter to $18
  3745. L1175 staa T_enrWarm ;
  3746.  
  3747.  
  3748. ;------------------------------------------------
  3749. ; Section to compute injFactor
  3750. ; start with basic value of totMasComp*16
  3751. ;------------------------------------------------
  3752. L1176 ldd totMasComp ; d = totMasComp
  3753. asld ;
  3754. asld ;
  3755. asld ;
  3756. asld ;
  3757. std temp6 ; temp6:temp7 = totMasComp*16
  3758.  
  3759. ;---------------------------------------
  3760. ; Factor in injector size compensation
  3761. ;---------------------------------------
  3762. ldab #injComp ; Injector size compensation factor ($80 = 100% = no compensation, referenced at 260cc, 36psi)
  3763. jsr mul816_128 ; d = [temp6:temp7] = totMasComp*16 * injComp /128
  3764. std injMasComp ; injMasComp = totMasComp*16 * injComp/128
  3765.  
  3766. ;-------------------------------------------------------
  3767. ; Factor in working fuel trim and 02 fuel adjustment
  3768. ; Done this way, total range is limited to [50%,150%]
  3769. ; when both workFtrim and o2FuelAdj are at $00 or $ff
  3770. ;-------------------------------------------------------
  3771. clra ; a=0
  3772. ldab workFtrim ; d = working fuel trim ($80=100%)
  3773. addd #$0100 ; d = workFtrim + 2*$80
  3774. addb o2FuelAdj ; Add o2 adjustment (Add/remove fuel based on o2 sensor voltage/feedback, $80=100%->no fuel adjustment)
  3775. adca #$00 ; propagate carry, d = workFtrim + o2FuelAdj + 2*$80
  3776. jsr mul1616_512 ; D = [temp6:temp7] = [workFtrim + o2FuelAdj + 2*$80]/512 * [temp6:temp7]
  3777.  
  3778. ;-----------------------------------
  3779. ; Factor-in air temp, baro, etc...
  3780. ;-----------------------------------
  3781. ldab iatCompFact ; Correct for air temperature (air density)
  3782. jsr mul816_128 ; D and [temp6:temp7] = b*[temp6:temp7]/128
  3783. ldab baroFact ; Correct for barometric pressure (air density)
  3784. jsr mul816_128 ; D and [temp6:temp7] = b*[temp6:temp7]/128
  3785. ldab openLoopEnr ; Apply the open loop enrichment factor, based on timing/knock, tps and timer
  3786. jsr mul816_128 ; D and [temp6:temp7] = b*[temp6:temp7]/128
  3787. ldab coldTempEnr ; Add fuel enrichement under cold engine temperature and low airflow
  3788. jsr mul816_128 ; D and [temp6:temp7] = b*[temp6:temp7]/128
  3789. ldab enrWarmup ; b = enrichment during warmup/startup, from t_enrWarmup(ECT), can reach 300% in very cold temp but is decreased to 140% very rapidly
  3790. clra ; a=0
  3791. asld ; d = 2*enrWarmup
  3792. addd #$0080 ; d = 2*enrWarmup + $80
  3793. jsr mul1616_128 ; Apply (2*enrWarmup+$80) enrichment factor
  3794. std injFactor ; Store final result in injFactor (global injector factor)
  3795.  
  3796. ;----------------------------
  3797. ; Compute injector deadTime
  3798. ;----------------------------
  3799. ldx #t_deadtime-2
  3800. ldaa battRaw
  3801. jsr interp32
  3802. stab deadTime
  3803.  
  3804. ;-----------------------------------------
  3805. ; Update injFlags0.2 (set but not reset???)
  3806. ;-----------------------------------------
  3807. ldaa rpm31
  3808. cmpa #$0e
  3809. bcs L1178 ; branch if rpm < 437.5
  3810. orm injFlags0, #$04 ; rpm >= 437.5, set bit
  3811.  
  3812. ;-----------------------------------------------
  3813. ; Update injFlags0.1.3.5 if engine notRotating
  3814. ;-----------------------------------------------
  3815. L1178 brclr state1, #$10, L1180 ; Branch if notRotating clear
  3816. andm injFlags0, #$df ; assume we reset 00100000, updated below
  3817. ldaa ectFiltered ;
  3818. cmpa #$c2 ; -8degC
  3819. bcs L1179 ; Branch if temperature(ectFiltered) > -8degC
  3820. orm injFlags0, #$20 ; temperature(ectFiltered) <= -8degC, set bit
  3821. L1179 brclr injFlags0, #$04, L1180 ; Branch if rpm<437.5
  3822. andm injFlags0, #$fa ; Reset 0000 0101
  3823.  
  3824. ;------------------------------------------------------------------------------------
  3825. ; Section to compute injPwStart, the injector pulsewidth when engine "startingToCrank"
  3826. ;
  3827. ; startingToCrank "cold engine" injPwStart injFlags0.7 (startingToCrankColdEngine)
  3828. ; 0 0 0 0
  3829. ; 0 1 0 0
  3830. ; 1 0 pulseWidth*4 0
  3831. ; 1 1 pulseWidth 1
  3832. ;------------------------------------------------------------------------------------
  3833. ;--------------------------------
  3834. ; Get starting value from L2008
  3835. ;--------------------------------
  3836. L1180 clra
  3837. brclr state1, #$01, L1191 ; Bail to end of section if startingToCrank clear
  3838. ldx #L2008 ; Engine is startingToCrank
  3839. jsr interpEct2 ; b = L2008(ectCond)
  3840. ldaa #$80 ; a = $80
  3841. mul ;
  3842. lsrd ; d = $80*L2008(ectCond)
  3843. std temp6 ; [temp6:temp7] = $80*L2008(ectCond)
  3844.  
  3845. ;--------------------------------------------
  3846. ; Factor-in some enrichement if injCount<5
  3847. ; This only adds more fuel when starting to
  3848. ; crank for the first time under very cold
  3849. ; temperature (-16degC). Not sure as to
  3850. ; exactly why but at -16degC, I guess
  3851. ; it just might help???
  3852. ;--------------------------------------------
  3853. ldaa injCount ;
  3854. cmpa #$05 ;
  3855. bcc L1182 ; Branch if injCount>=5
  3856. ldx #L2042 ;
  3857. jsr interpEct2 ; b=L2042(ectCond)
  3858. clra ;
  3859. addd #$0080 ; d = L2042(ectCond) + $80
  3860. jsr mul1616_128 ; [temp6:temp7] = [temp6:temp7] * (L2042(ectCond)+$80)/128
  3861.  
  3862. ;------------------------------------------------------------
  3863. ; Factor in an rpm dependent correction factor if rpm >125???
  3864. ;------------------------------------------------------------
  3865. L1182 ldaa rpm8 ; a = rpm8
  3866. cmpa #$40 ;
  3867. bcs L1183 ; Branch if rpm < max of 500
  3868. ldaa #$40 ; rpm>500, use max of 500rpm
  3869.  
  3870. L1183 suba #$10 ; a = rpm8-$10
  3871. bcs L1185 ; Bail if rpm8<125rpm
  3872. asla ; a = 2*(rpm8-$10)
  3873. #ifdef E931
  3874. ldab #$56 ;
  3875. #else
  3876. ldab #$57 ;
  3877. #endif
  3878. mul ; d = $56*2*(rpm8-$10)
  3879. asld ;
  3880. tab ; b = 2*$56*2*(rpm8-$10)/256
  3881. ldaa #$80 ; a = $80
  3882. sba ; a = $80 - $56*2*(rpm8-$10)/128
  3883. bcc L1184 ; Branch if no underflow
  3884. clra ; Use min of 0
  3885. L1184 tab ; b = $80 - $56*2*(rpm8-$10)/128
  3886. jsr mul816_128 ; [temp6:temp7] = [temp6:temp7] * ($80 - $56*2*(rpm8-$10)/128)/128
  3887.  
  3888.  
  3889. ;------------------------------------------------------------------
  3890. ; Check current value for minimum, keep min
  3891. ; minimum is L2008(0) -> starting value at 86degC (hot engine)
  3892. ;------------------------------------------------------------------
  3893. L1185 ldab L2008 ; b = L2008(0)
  3894. ldaa #$80 ; a = $80
  3895. mul ; d = $80*L2008(0)
  3896. lsrd ; d = $80*L2008(0)/2
  3897. cmpd1 temp6 ;
  3898. bcs L1187 ; branch if current value >
  3899. std temp6 ;
  3900.  
  3901. ;--------------------------------
  3902. ; Factor-in barometric pressure
  3903. ;--------------------------------
  3904. L1187 ldab baroFact ;
  3905. jsr mul816_128 ; d = pulseWidth = [temp6:temp7] = [temp6:temp7] * baroFact/128
  3906.  
  3907. ;-----------------------------------------
  3908. ; Multiply by 2 and check for overflow
  3909. ;-----------------------------------------
  3910. asld ; pulseWidth = d = 2*[temp6:temp7]
  3911. bcc L1188 ; Branch if no overflow
  3912. ldaa #$ff ; Use max
  3913.  
  3914. ;--------------------------------------------------------------
  3915. ; At this point d = pulseWidth
  3916. ;
  3917. ; Set startingToCrankColdEngine flag if pulseWidth > threshold
  3918. ; or reset it (with hysteresis)
  3919. ;
  3920. ; Note that pulseWidth will be larger when the engine is cold, also rpm dependent...
  3921. ;--------------------------------------------------------------
  3922. L1188 pshb ; Put b on stack for temp calculation
  3923. ldab #$35 ; b = $35 = 13.6ms =threshold
  3924. brclr injFlags0, #$80, L1190 ; Branch if startingToCrankColdEngine was not previously set
  3925. ldab #$30 ; Flag was set, use lower threshold (hysteresis) b=$30 = 12.3ms
  3926. L1190 orm injFlags0, #$80 ; By default, assume startingToCrankColdEngine flag set
  3927. cba ;
  3928. pulb ; restore b (lower part of pulseWidth)
  3929. bcc L1192 ; Branch if pulseWidth/256 >= threshold (flag already set), we are startingToCrankColdEngine
  3930.  
  3931. ;-------------------------------------------------------------------------
  3932. ; pulseWidth < threshold, engine is therefore startingToCrank
  3933. ; but the engine is not cold
  3934. ; Multiply pulseWidth by 4?????? and reset the flag
  3935. ;-------------------------------------------------------------------------
  3936. asld ;
  3937. asld ; d = d * 4
  3938. L1191 andm injFlags0, #$7f ; Reset startingToCrankColdEngine flag
  3939. L1192 xgdx ; x = pulseWidth
  3940.  
  3941. ;-----------------------------------------------------
  3942. ; Store injPwStart and update state3.7 from injFlags0.7
  3943. ; (done this way since used in interrupts)
  3944. ;-----------------------------------------------------
  3945. ldaa injFlags0 ;
  3946. anda #$80 ; a = injFlags0 & $80, keep only that bit
  3947. sei ;
  3948. stx injPwStart ; injPwStart = pulseWidth
  3949. ldab state3
  3950. andb #$7f ;
  3951. aba ; b = b&$7f + injFlags0&$80
  3952. staa state3 ; Update state3
  3953.  
  3954. ;----------------------------------------
  3955. ; Update state3 from state1
  3956. ;----------------------------------------
  3957. ldaa state1 ;
  3958. anda #$1b ; Keep 00011011
  3959. brclr state1, #$08, L1193 ; Branch if rotatingStopInj clear
  3960. brset state1, #$04, L1193 ; Engine rotatingStopInj, branch if runningFast
  3961. oraa #$20 ; Engine rotatingStopInj but not runningFast, set bit
  3962. L1193 ldab state3 ;
  3963. andb #$c4 ; Keep 11000100
  3964. aba ;
  3965. staa state3 ;
  3966.  
  3967. ;--------------------------------------------------------------------------
  3968. ; If engine is just startingToCrank and this is the first time we are here
  3969. ; then compute sInjPw and schedule an interrupt to activate simultaneous
  3970. ; injection (if no injector is currently active)
  3971. ;--------------------------------------------------------------------------
  3972. cli ;
  3973. brclr state1, #$01, L1195 ; Bail if startingToCrank clear
  3974. brset injFlags0, #$01, L1195 ; Engine startingToCrank, bail if injFlags0.0 already set, meaning we were already here before and
  3975. orm injFlags0, #$01 ; Set flag
  3976. ldaa #$0c ; a = $0c
  3977. clrb ; d = $0c00
  3978. sei ;
  3979. std sInjPw ; sInjPw = $0c00 = 3.072ms
  3980. brset injToAct, #$0f, L1194 ; Bail if any injector is active
  3981. ldd t1t2_clk ; No injector flag set, schedule interrupt
  3982. addd #$0014 ; 20us
  3983. std t1_outCmpWr ; schedule interrupt in 20us
  3984.  
  3985. ;----------------------
  3986. ; Compute accEnrFact
  3987. ;----------------------
  3988. L1194 cli ;
  3989. L1195 ldx #L2051 ; x point to L2051
  3990. jsr interpEct ; b = L2051(ect)
  3991. ldx #t_accEnr1 ; x point to t_accEnr1
  3992. ldy #t_accEnr2a ;
  3993. addb T2_crank ;
  3994. bcc L1196 ; branch if engine stopped "startingToCrank" more than L2051(ect)/2 sec ago.
  3995. ldy #t_accEnr2b ;
  3996. L1196 jsr L1577 ;
  3997. std accEnrFact ; [accEnrFact:accEnrFact+1] = 8 * injMasComp * t_accEnr1(rpm)/128 * [t_accEnr2a(ect) or t_accEnr2b(ect)]/128 * baroFact/128
  3998.  
  3999. ;-----------------------
  4000. ; Compute accEnrDecay
  4001. ;-----------------------
  4002. ldx #t_accEnrDecay ;
  4003. jsr interpEct ;
  4004. stab accEnrDecay ; accEnrDecay = t_accEnrDecay(ect)
  4005.  
  4006. ;---------------------
  4007. ; Compute accEnrMinAf
  4008. ;---------------------
  4009. ldx #L2039
  4010. jsr interp16rpm ; a = L2039(rpm)
  4011. ldab #$57 ;
  4012. mul ; d = $57*L2039(rpm)
  4013. jsr scale16 ; d = $57*L2039(rpm)/16
  4014. std accEnrMinAf ; accEnrMinAf:L0106 = $57*L2039(rpm)/16
  4015.  
  4016. ;---------------------
  4017. ; Compute decEnrFact
  4018. ;--------------------- ;
  4019. ldaa T40_crank ;
  4020. adda #$78 ; 3s
  4021. bcc L1197 ; branch if engine stopped "startingToCrank" more than 3s ago
  4022. clra ;
  4023. clrb ;
  4024. bra L1199 ;
  4025. L1197 ldx #t_decEnr1 ;
  4026. ldy #t_decEnr2 ;
  4027. jsr L1577 ;
  4028. L1199 std decEnrFact ; [decEnrFact:decEnrFact+1] = 8 * injMasComp * t_decEnr1(rpm)/128 * t_decEnr2/128 * baroFact/128
  4029.  
  4030.  
  4031. ;-------------------------------------------------------------------------
  4032. ; Compute sInjEnrInc
  4033. ; Parameters related to adding fuel during simultaneous injection mode
  4034. ;-------------------------------------------------------------------------
  4035. ldx #L2051 ;
  4036. jsr interpEct ; b = L2051(ect)
  4037. ldx #L2013 ;
  4038. addb T2_crank ; b = L2051(ect) + T2_crank
  4039. bcc L1202 ; branch if engine stopped "startingToCrank" more than L2051(ect)/2 sec ago
  4040. ldx #L2050 ; Overflow, change table
  4041. L1202 jsr interpEct ; b = L2050(ect) or L2013(ect)
  4042. pshb ; st0 = L2050(ect) or L2013(ect)
  4043. ldx #L2015 ;
  4044. jsr interp16rpm ; b = L2015(rpm)
  4045. pula ; a = L2050(ect) or L2013(ect)
  4046. aba ; a = L2050(ect) or L2013(ect) + L2015(rpm)
  4047. bcc L1205 ; Branch if no overflow
  4048. ldaa #$ff ; Overflow, use max
  4049. L1205 staa sInjEnrInc ; sInjEnrInc = L2050(ect) or L2013(ect) + L2015(rpm)
  4050.  
  4051. ;-------------------------------------------------------------------------
  4052. ; Compute sInjEnrMax = sInjEnrInc/4
  4053. ; Parameters related to adding fuel during simultaneous injection mode
  4054. ;-------------------------------------------------------------------------
  4055. ldab #$20 ; b = $20
  4056. mul ; d = $20 * sInjEnrInc
  4057. jsr scale128m ; d = $20/128 * sInjEnrInc = 1/4 * sInjEnrInc, also check for max of 255...
  4058. stab sInjEnrMax ; sInjEnrMax = 1/4 * sInjEnrInc = 1/4 * (L2051(ect) + T2_crank or L2050(ect) + L2015(rpm))
  4059.  
  4060. ;---------------------------------------------------------------------------------
  4061. ; Compute sInjTpsMax, threshold used to increase fuel in simulateneous injection
  4062. ;---------------------------------------------------------------------------------
  4063. ldx #t_sInjTpsMax ;
  4064. jsr interp16rpm ;
  4065. stab sInjTpsMax ; sInjTpsMax = t_sInjTpsMax(rpm)
  4066.  
  4067. ;---------------------------------
  4068. ; Decrement T40s_casInt at 40Hz
  4069. ;---------------------------------
  4070. ldx #T40s_casInt
  4071. jsr decX40Hz ; Decrement T40s_casInt at 40Hz
  4072.  
  4073. ;-------------------------------------------------------------------------
  4074. ; Set the timing adjustment flag (timAdjFlags.7) if the timing
  4075. ; adjustment terminal is grounded but the ECU test mode terminal is not
  4076. ;-------------------------------------------------------------------------
  4077. brclr port4Snap, #$10, L1209 ; Branch if stored timing terminal not grounded?
  4078. brclr port4, #$10, L1209 ; Branch if timing terminal not grounded?
  4079. brset port4Snap, #$08, L1209 ; Branch if ECU test mode terminal grounded?
  4080. orm timAdjFlags, #$80 ; Set flag, timing terminal grounded but ECU test mode terminal NOT grounded
  4081. bra L1210 ; Bail
  4082. L1209 andm timAdjFlags, #$7f ; Reset flag
  4083.  
  4084. ;-----------------------------------------------------
  4085. ; Re-init knockTimer to $ff if engine notRotating
  4086. ;-----------------------------------------------------
  4087. L1210 brclr state1, #$10, L1212 ; Branch if notRotating clear
  4088. ldaa #$ff ; Engine notRotating
  4089. staa knockTimer
  4090.  
  4091. ;-----------------------------------------------------
  4092. ; Update the "knock sensor bad" flag if
  4093. ; engine was started more than 1 sec ago
  4094. ;-----------------------------------------------------
  4095. L1212 brset state1, #$11, L1214 ; Branch if notRotating or startingToCrank
  4096. ldaa T40_crank ; Engine is running
  4097. adda #$28 ;
  4098. bcs L1214 ; branch if engine stopped "startingToCrank" less than 1s ago (don't check knock sensor yet)
  4099. orm knockFlags, #$40 ; Set flag indicating "engine running for more than 1 sec"???
  4100. brset port4Snap, #$20, L1215 ; Branch if knock sensor is OK???
  4101. orm state2, #$20 ; Set flag indicating knock sensor is bad
  4102. bra L1217 ; Bail
  4103. L1214 andm knockFlags, #$bf ; Reset flag indicating "engine running for more than 1 sec"???
  4104. L1215 andm state2, #$df ; Reset bad knock sensor flag
  4105.  
  4106. ;---------------------------------------------------------------------------------
  4107. ; Update knockFlags.7 (airVol threshold flag) and T200s_knock if below threshold
  4108. ;---------------------------------------------------------------------------------
  4109. L1217 ldab airVol ; b=airVol
  4110. cmpb #$49 ;
  4111. bcc L1218 ; branch if airVol>$49
  4112. andm T200s_knock, #$03 ; airVol<$49, reset T200s_knock to a more reasonable value
  4113. andm knockFlags, #$7f ; clear knockFlags.7
  4114. bra L1219 ; branch LDB89
  4115. L1218 orm knockFlags, #$80 ; set knockFlags.7
  4116.  
  4117. ;-----------------------------------------------------
  4118. ; Something activated at 4595rpm with hysteresis??????
  4119. ; Could be related to knock since we are in the area...
  4120. ; Maybe knock sensor filter parameter being changed???
  4121. ;-----------------------------------------------------
  4122. L1219 ldaa #$96 ; 4688rpm
  4123. brclr port6, #$02, L1220 ; branch if ??? not yet activated???
  4124. ldaa #$90 ; 4500rpm
  4125. L1220 cmpa rpm31 ;
  4126. bhi L1221 ; Branch if rpm lower than threshold
  4127. orm port6, #$02 ; rpm higher than threshold, Activate ???
  4128. bra L1222 ;
  4129. L1221 andm port6, #$fd ; De-activate ???
  4130.  
  4131. ;----------------------------
  4132. ; Section to update octane
  4133. ;----------------------------
  4134. ;--------------------------------------------------
  4135. ; Skip octane update if temp(ectFiltered) < 80degC
  4136. ;--------------------------------------------------
  4137. L1222 ldaa ectFiltered
  4138. cmpa #$20 ; 80degC
  4139. bhi L1227 ; Bail if temp(ectFiltered) < 80degC
  4140.  
  4141. ;-----------------------------------------
  4142. ; temp(ectFiltered) >= 80degC
  4143. ; Skip octane update under more cases...
  4144. ;-----------------------------------------
  4145. brset state2, #$28, L1227 ; Bail if no pulse accumulator interrupts or if knock sensor not working?
  4146. brclr knockFlags, #$40, L1227 ; Bail if engine has not been running for more than 1 sec
  4147. ldy #L2052 ; Engine has been running for more than 1 sec
  4148. jsr rpmPwise ; b = piecewise(rpm4) for table interpolation
  4149. ldaa #$b0 ; a = $b0
  4150. jsr abmin ; Apply max to b, b = min($b0,piecewise(rpm4))
  4151. tba ; a = min($b0,piecewise(rpm4))
  4152. ldx #L2041 ; x points to L2041
  4153. jsr interp16b ; a = L2041(rpm4)
  4154. cmpa airVol ;
  4155. bcc L1227 ; Bail if airVol <= L2041(rpm4)
  4156.  
  4157. ;---------------------------------------------
  4158. ; airVol > L2041(rpm4), skip octane update
  4159. ; if 3<=knockSum<=5 (hysteresis zone...)
  4160. ;---------------------------------------------
  4161. ldaa knockSum ;
  4162. cmpa #$03 ;
  4163. bcs L1223 ; Branch if knockSum <3
  4164. cmpa #$05 ;
  4165. bls L1227 ; Bail if knockSum <=5
  4166.  
  4167. ;-------------------------------------------------------------
  4168. ; knockSum<3 or knockSum>5, we can update octane at 2.5Hz
  4169. ;-------------------------------------------------------------
  4170. L1223 rora ; shift in carry bit, rest of a = knockSum/2
  4171.  
  4172. ;-----------------------------------------------------------
  4173. ; Decrement T40s_octane at 40Hz (loops at $10)
  4174. ; and update octane if timer is expired (at 2.5Hz)
  4175. ;-----------------------------------------------------------
  4176. brclr Tclocks, #$01, L1227 ; Bail if 40Hz signal no set
  4177. ldab T40s_octane ; b = T40s_octane
  4178. beq L1224 ; Branch if timer expired
  4179. dec T40s_octane ; Update timer
  4180. bne L1227 ; Bail if timer not yet expired
  4181.  
  4182. ;-------------------------------------
  4183. ; T40s_octane expired, update octane
  4184. ;-------------------------------------
  4185. L1224 ldab octane ; b = octane
  4186. tsta ;
  4187. bpl L1225 ; Branch if knockSum >=3 (see carry bit shited-in above)
  4188.  
  4189. ;--------------------------------------------------
  4190. ; knockSum <3, increment octane by 1 (max 255)
  4191. ;--------------------------------------------------
  4192. ldaa #$10 ; pre-load timer value
  4193. incb ; b = octane+1
  4194. bne L1226 ; Branf if no rollover
  4195. decb ; Rollover, use max of 255
  4196. bra L1226 ; Bail to store
  4197.  
  4198. ;--------------------------------------------------
  4199. ; knockSum >=3, decrement octane by 1 (min 0)
  4200. ;--------------------------------------------------
  4201. L1225 ldaa #$10 ; pre-load timer value
  4202. tstb ;
  4203. beq L1226 ; Branch if octane already 0
  4204. decb ; b = octane - 1
  4205. L1226 stab octane ; update octane
  4206. staa T40s_octane ; Re-init T40s_octane with $10
  4207.  
  4208. ;-------------------------------------------------------------------------------------------------
  4209. ; Section to compute timingOct, the timing interpolated from the
  4210. ; two timing maps (timing under high octane and low octane) according
  4211. ; to the current octane value
  4212. ;
  4213. ; timingOct = alpha * t_timingHiOct(rpm, load) + (1-alpha) * t_timingLoOct(rpm, load)
  4214. ;
  4215. ; where alpha = octane/255, 0<= alpha <=1
  4216. ;-------------------------------------------------------------------------------------------------
  4217. ;-------------------------------------------------
  4218. ; Compute rpm and load for 2D map interpolation
  4219. ;-------------------------------------------------
  4220. L1227 ldy #L2052 ;
  4221. jsr rpmPwise ; b = rpm
  4222. stab temp6 ; temp6 = rpm
  4223. jsr getLoadForMaps ; b = load
  4224. stab temp7 ; temp7 = load
  4225.  
  4226. ;--------------------------------------
  4227. ; Get timing value from t_timingHiOct
  4228. ;--------------------------------------
  4229. ldx #t_timingHiOct ; x points to t_timingHiOct
  4230. ldy #$1000 ;
  4231. jsr lookup2D ; b = t_timingHiOct(rpm,load)
  4232. stab timFuelEnr ; timFuelEnr = t_timingHiOct(rpm,load)
  4233.  
  4234. ;------------------------------------------------------------------------------------
  4235. ; Change load value for t_timingLoOct map interpolation (first three row missing)
  4236. ;------------------------------------------------------------------------------------
  4237. ldaa temp7 ; a = load
  4238. suba #$30 ; a = load - $30
  4239. bcs L1229 ; branch if load <$30 (no interpolation, use t_timingHiOct(rpm,load)
  4240. staa temp7 ; temp7 = load-$30
  4241.  
  4242. ;------------------------------------------------------
  4243. ; Compute t_timingHiOct(rpm,load) * octane and put it on stack
  4244. ;------------------------------------------------------
  4245. jsr getOctane ; a = validated octane
  4246. mul ; d = t_timingHiOct(rpm,load) * octane
  4247. psha ; put on stack
  4248. pshb ; put on stack
  4249.  
  4250. ;-------------------------------------
  4251. ; Get timing value from t_timingLoOct
  4252. ;-------------------------------------
  4253. ldx #t_timingLoOct ; x points to t_timingLoOct
  4254. ldy #$1000 ;
  4255. jsr lookup2D ; b = t_timingLoOct(rpm, load)
  4256.  
  4257. ;-----------------------------------------------------------------------------------------------------------
  4258. ; Compute
  4259. ; timingOct = octane/255 * t_timingHiOct(rpm,load) + (255 - octane)/255 * t_timingLoOct(rpm, load)
  4260. ; = alpha * t_timingHiOct(rpm,load) + (1-alpha) * t_timingLoOct(rpm, load)
  4261. ;-----------------------------------------------------------------------------------------------------------
  4262. jsr getOctane ; a = octane
  4263. coma ; a = not(octane) = 255 - octane
  4264. mul ; d = (255 - octane) * t_timingLoOct(rpm, load)
  4265. std temp6 ; temp6:temp7 = (255 - octane) * t_timingLoOct(rpm, load)
  4266. pulb ;
  4267. pula ; d = octane * t_timingHiOct(rpm,load)
  4268. addd temp6 ; d = octane * t_timingHiOct(rpm,load) + (255 - octane) * t_timingLoOct(rpm, load)
  4269. div #$ff ; a = remainder, b = octane/255 * t_timingHiOct(rpm,load) + (255 - octane)/255 * t_timingLoOct(rpm, load)
  4270. rola ; Put remainder high bit in carry
  4271. adcb #$00 ; roundup b with remainder
  4272. L1229 stab timingOct ; timingOct = octane/255 * t_timingHiOct(rpm,load) + (255 - octane)/255 * t_timingLoOct(rpm, load)
  4273.  
  4274. ;--------------------------------------------------------------------------------------------------
  4275. ; Compute timFuelEnr = $4b/256 * ($b6/64 * (t_timingHiOct(rpm,load) - timingOct) + knockSum - 5)
  4276. ; timFuelEnr is a fuel enrichment based on timing, octane and knockSum
  4277. ;--------------------------------------------------------------------------------------------------
  4278. ldaa timFuelEnr ; a = t_timingHiOct(rpm,load)
  4279. suba timingOct ; a = t_timingHiOct(rpm,load) - timingOct
  4280. bcc L1230 ; Branch if result positive
  4281. clra ; Use min of 0
  4282. L1230 ldab #$b6 ; b = $b6
  4283. mul ; d = $b6 * (t_timingHiOct(rpm,load) - timingOct)
  4284. jsr scale64 ; b = $b6/64 * (t_timingHiOct(rpm,load) - timingOct)
  4285. addb knockSum ; b = $b6/64 * (t_timingHiOct(rpm,load) - timingOct) + knockSum
  4286. bcc L1232 ; Branch if no overflow
  4287. ldab #$ff ; Overflow, use max of 255
  4288. L1232 subb #$05 ; b = $b6/64 * (t_timingHiOct(rpm,load) - timingOct) + knockSum - 5
  4289. bcc L1233 ; Branch if result positive
  4290. clrb ; Use min of 0
  4291. #ifdef E931
  4292. L1233 ldaa #$4b ; a = $4b
  4293. #else
  4294. L1233 ldaa #$86 ; a = $86
  4295. #endif
  4296. mul ; d = $4b*($b6/64 * (t_timingHiOct(rpm,load) - timingOct) + knockSum - 5)
  4297. staa timFuelEnr ; timFuelEnr = $4b/256 * ($b6/64 * (t_timingHiOct(rpm,load) - timingOct) + knockSum - 5)
  4298.  
  4299. ;---------------------------------------
  4300. ; Section to update maxAdv for E931
  4301. ;---------------------------------------
  4302. #ifdef E931
  4303. brset state1, #$04, Mdc7a ; Branch if engine runningFast
  4304. brset state1, #$10, Mdc76 ; Branch if notRotating
  4305. ldaa rpm8 ;
  4306. cmpa t_idleSpd ;
  4307. bcs Mdc76 ; Branch if rpm8 < t_idleSpd (normal idle speed)
  4308. ldaa tpsDiffMax2 ;
  4309. cmpa #$03 ;
  4310. bcc Mdc76 ; Branch if tpsDiffMax2 >= 3 (pedal is moving forward...)
  4311. ldaa airDiffPos1 ;
  4312. cmpa #$0a ;
  4313. bcs L1234 ; Bail (dont even update maxAdv) if airDiffPos1 < $0a (airflow decrease or small airflow increase)
  4314.  
  4315. ;----------------------------------------
  4316. ; Use max of $80 (maxAdv=$80, no limit?)
  4317. ; if notRotating
  4318. ; or rpm8 < t_idleSpd
  4319. ; or tpsDiffMax2 >= 3
  4320. ; or airDiffPos1 >= $0a
  4321. ;----------------------------------------
  4322. Mdc76 ldaa #$80 ; Use default of $80 (no limit)
  4323. bra Mdc90 ; Branch to store
  4324.  
  4325. ;--------------------------------------------------------------------
  4326. ; Engine runningFast, compute maxAdv which will reduce the
  4327. ; timing advance by 13deg or limit it to 12deg
  4328. ;---------------------------------------------------------------------
  4329. Mdc7a ldaa vssCnt1 ;
  4330. beq L1234 ; Bail if car not moving
  4331. ldaa #$05 ;
  4332. staa T_maxAdv ; Init timer T_maxAdv = 5 ?
  4333. ldaa timingOct ;
  4334. suba #$0d ;
  4335. bcc Mdc8a ; Branch if timingOct - $0d positive
  4336. clra ; Use min of 0
  4337. Mdc8a ldab #$12 ; b = $12
  4338. cba ;
  4339. bcc Mdc90 ; Branch if timingOct-$0d >= $12
  4340. tba ; Use max of $12 degrees
  4341. Mdc90 staa maxAdv ; maxAdv = max(timingOct - $0d, 12)
  4342. #endif
  4343.  
  4344. ;-------------------------------------------------
  4345. ; Set timAdjFlags.1 flag if rpm>2000rpm or reset it
  4346. ;-------------------------------------------------
  4347. L1234 ldab #$40 ; assume b = threshold = 2000rpm
  4348. brclr timAdjFlags, #$01, L1235 ; Branch if flag clear
  4349. ldab #$3a ; Flag was previously set, use a lower threshold of 1813rpm (hysteresis)
  4350. L1235 andm timAdjFlags, #$fe ; Reset flag
  4351. cmpb rpm31 ;
  4352. bcc L1237 ; Branch if rpm31 <= threshold (2000rpm or 1813rpm)
  4353. orm timAdjFlags, #$01 ; rpm31 > threshold, set flag
  4354.  
  4355. ;------------------------------------------------------------------------
  4356. ; Compute advRpm under some conditions (low rpm, idle switch off, etc.)
  4357. ; advRpm is an rpm based timing advance/retard with +/-8deg max
  4358. ;------------------------------------------------------------------------
  4359. L1237 ldaa #$80 ; preload a = $80 = default value (no timing change)
  4360. brset timAdjFlags, #$01, L1243 ; Bail if rpm31 > 2000rpm (with hysteresis)
  4361. brset iscFlags0, #$04, L1243 ; Bail if basic idle speed adjustment mode is active (no timing change)
  4362. brset state1, #$19, L1243 ; Bail if notRotating or startingToCrank or rotatingStopInj
  4363. brclr port3Snap0, #$80, L1243 ; Bail if idle switch on
  4364. ldab vssCnt1 ;
  4365. brn L1243 ; Branch never (?)
  4366. ldx #$0000 ; x = 0
  4367. clrb ; b = 0
  4368. ldaa idleSpdTarg ; d = 256*idleSpdTarg
  4369. #ifdef E931 ;
  4370. suba #$06 ; d = 256*(idleSpdTarg - 6) (-47rpm)
  4371. #else ;
  4372. suba #$04 ;
  4373. #endif ;
  4374. bcc L1238 ; Branch if no underflow
  4375. clra ; Underflow, use min of 0
  4376. L1238 jsr scale8 ; a = 256/8 * (idleSpdTarg - 6) = 32*(idleSpdTarg - 6)
  4377. cmpd rpmX4Filt ;
  4378. bcc L1239 ; Branch if 32*(idleSpdTarg - 6) >= rpmX4Filt
  4379. ldd rpmX4Filt ; use min of rpmX4Filt
  4380. L1239 jsr scale16 ; d = 2*(idleSpdTarg - 6)
  4381. subd rpm4 ; d = 2*(idleSpdTarg - 6) - rpm4
  4382. bcc L1240 ; Branch if positive
  4383. inx ; result negative, x = 1
  4384. coma ;
  4385. comb ;
  4386. addd #$0001 ; d = rpm4 - 2*(idleSpdTarg - 6)
  4387. L1240 jsr ovfCheck ; b = result = abs(rpm4 - 2*(idleSpdTarg - 6))
  4388. ldaa #$68 ; a = $68
  4389. mul ; d = $68 * abs(rpm4 - 2*(idleSpdTarg - 6))
  4390. jsr round256 ; a = $68/256 * abs(rpm4 - 2*(idleSpdTarg - 6))
  4391. cmpa #$08 ;
  4392. bls L1241 ; Branch if a <= 8 (+/-8 degrees advance or retard)
  4393. ldaa #$08 ; Use max of 8
  4394. L1241 dex ; x = x-1
  4395. bne L1242 ; Branch if we did not have a negative result earlier
  4396. nega ; Result was negative, negate again to restore it...
  4397. L1242 adda #$80 ; a = $80 + $68/256 * (rpm4 - 2*(idleSpdTarg - 6))
  4398. L1243 staa advRpm ; advRpm = $80 + $68/256 * (rpm4 - 2*(idleSpdTarg - 6))
  4399.  
  4400. ;--------------------------------------------------
  4401. ; Compute advEct, ect based timing advance/retard
  4402. ;--------------------------------------------------
  4403. ldx #L2020
  4404. jsr interpEct
  4405. stab advEct ; advEct = L2020(ect)
  4406.  
  4407. ;---------------------------------------------------------------
  4408. ; Compute advIat iat based advance/retard under low load
  4409. ;---------------------------------------------------------------
  4410. ldx #L2038 ;
  4411. jsr interp16rpm ; b = L2038(rpm)
  4412. cmpa airVolB ;
  4413. bls L1244 ; Branch if L2038(rpm) <= airVolB
  4414. ldaa #$80 ; Use default value of $80 under high load
  4415. bra L1245 ;
  4416. L1244 ldx #L2021 ; L2038(rpm) <= airVolB
  4417. jsr iatCInterp ;
  4418. L1245 staa advIat ; advIat = L2021(iat)
  4419.  
  4420. ;----------------------------------------------------------------------------------
  4421. ; Compute advTotal = min(timingOct, maxAdv) + advEct + advIat + advRpm - $0180
  4422. ; = min(timingOct, maxAdv) + (advEct-$80) + (advIat-$80) + (advRpm-$80)
  4423. ;----------------------------------------------------------------------------------
  4424. ldx #advTotal ; x points to advTotal (table of timing related value)
  4425. ldab $01,x ; b = timingOct (timing corrected for current octane)
  4426. #ifdef E931
  4427. cmpb maxAdv ;
  4428. bls L1246 ; branch if timingOct<=maxAdv
  4429. ldab maxAdv ; Use max of maxAdv
  4430. #endif
  4431. L1246 clra ; d = min(timingOct, maxAdv) (a = 0...)
  4432. xgdy ; y = min(timingOct, maxAdv)
  4433. ldab $02,x ; b = advEct
  4434. aby ; y = min(timingOct, maxAdv) + advEct
  4435. ldab $03,x ; b = advIat
  4436. aby ; y = min(timingOct, maxAdv) + advEct + advIat
  4437. ldab $04,x ; b = advRpm
  4438. aby ; y = min(timingOct, maxAdv) + advEct + advIat + advRpm
  4439. xgdy ; d = min(timingOct, maxAdv) + advEct + advIat + advRpm
  4440. cmpd #$01bc ;
  4441. bls L1247 ; Branch if min(timingOct, maxAdv) + advEct + advIat + advRpm <= $01bc
  4442. ldd #$01bc ; Use max of $01bc
  4443.  
  4444. L1247 cmpd #$0180 ;
  4445. bcc L1248 ; Branch if min(timingOct, maxAdv) + advEct + advIat + advRpm >= $0180
  4446. ldd #$0180 ; Use min of $0180
  4447.  
  4448. L1248 subd #$0180 ; d = min(timingOct, maxAdv) + advEct + advIat + advRpm - $0180
  4449. stab $00,x ; advTotal = min(timingOct, maxAdv) + advEct + advIat + advRpm - $0180
  4450.  
  4451. ;----------------------------------------------------------
  4452. ; Compute tim61Tot0 = $e7 - $b6/64 * (advTotal + $0a)
  4453. ; = 256 * (61deg - (advTotal-10deg)) / 90
  4454. ;
  4455. ; This is timing referenced to -61deg BTDC
  4456. ; -10deg is because advTotal is shifted by 10deg (timingOct
  4457. ; is from the timing maps which are shifted by 10 deg...)
  4458. ;----------------------------------------------------------
  4459. addb #$0a ; b = advTotal + $0a
  4460. ldaa #$b6 ; a = $b6
  4461. mul ; d = $b6 * (advTotal + $0a)
  4462. jsr scale64 ; d = $b6/64 * (advTotal + $0a)
  4463. ldaa #$e7 ; a = $e7
  4464. sba ; a = $e7 - $b6/64 * (advTotal + $0a)
  4465. staa tim61Tot0 ; tim61Tot0 = $e7 - $b6/64 * (advTotal + $0a)
  4466.  
  4467. ;-------------------------------
  4468. ; Compute timingAdv from tim61
  4469. ;-------------------------------
  4470. ldaa #$a0 ; a = $a0 (default when engine not running)
  4471. brset state1, #$11, L1249 ; Branch if notRotating or startingToCrank
  4472. ldaa tim61 ; a = tim61
  4473. L1249 ldab #$5a ; b = $5a
  4474. mul ; d = $5a * tim61
  4475. jsr round256 ; a = $5a * tim61/256
  4476. nega ; a = -($5a * tim61/256)
  4477. adda #$47 ; a = -($5a * tim61/256) + $47 = $47 - $5a * tim61/256
  4478. staa timingAdv ; timingAdv = $147 - $5a * tim61/256
  4479.  
  4480. ;-------------------
  4481. ; Compute enerLen
  4482. ;-------------------
  4483. ldaa battRaw ;
  4484. suba #$80 ; a = battRaw - $80 (9.38v)
  4485. bcc L1250 ; branch if underflow
  4486. clra ; Use min of 0
  4487. L1250 staa temp5 ; temp5 = max(0,battRaw - $80)
  4488. ldx #t_enerLen ; x points to t_enerLen
  4489. jsr interp16b ; b = t_enerLen(battRaw)
  4490. stab enerLen ; enerLen = t_enerLen(battRaw)
  4491.  
  4492. ;-------------------------------------------------
  4493. ; Update coilChkFlags.5 flag, Set bit if engine
  4494. ; running and rpm<5000 and 8V<=battRaw<=18V
  4495. ;-------------------------------------------------
  4496. brset state1, #$11, L1253 ; Branch if notRotating or startingToCrank
  4497. ldaa rpm31 ; a = rpm31
  4498. cmpa #$a0 ;
  4499. bcc L1253 ; Branch if rpm31 >= 5000rpm
  4500. ldaa battRaw ; a = battRaw
  4501. cmpa #$f5 ; 18V
  4502. bhi L1253 ; Branch if battRaw > 18V
  4503. cmpa #$6d ; 8V
  4504. bcs L1253 ; Branch if battRaw < 8V
  4505. orm coilChkFlags, #$20 ; At this point voltage is between 8V and 18V, set bit
  4506. bra L1255 ;
  4507. L1253 andm coilChkFlags, #$df ; Reset bit
  4508.  
  4509. ;------
  4510. ; Exit
  4511. ;------
  4512. L1255 rts ;
  4513.  
  4514.  
  4515.  
  4516. ;******************************************************************
  4517. ;
  4518. ; Return the octane value if sensors look ok, 0 otherwise
  4519. ; (very low octane to be on the safe side)
  4520. ;
  4521. ;
  4522. ;
  4523. ;******************************************************************
  4524. getOctane clra
  4525. brset state2, #$28, L1257 ; Branch if no pulse accumulator interrupts or knock sensor not working
  4526. ldaa octane
  4527. L1257 rts
  4528.  
  4529.  
  4530.  
  4531. ;******************************************************************
  4532. ;
  4533. ;
  4534. ; Third subroutine
  4535. ;
  4536. ;
  4537. ;******************************************************************
  4538. ;-------------------------------------------
  4539. ; Update fuel pump activation/deactivation
  4540. ;-------------------------------------------
  4541. subroutine3 brclr state1, #$10, L1259 ; Branch if notRotating clear
  4542. brset obdActCmd, #$02, L1259 ; Engine notRotating, branch if fuel pump is being actuated through OBD command
  4543. orm port1, #$10 ; De-activate fuel pump relay
  4544. bra L1260 ; Bail
  4545. L1259 andm port1, #$ef ; activate fuel pump relay
  4546.  
  4547. ;------------------------------------------------------------------------
  4548. ; Re-init T40_acOn if A/C switch on is off
  4549. ; (implement a min delay before turning A/C on after button is pressed)
  4550. ;------------------------------------------------------------------------
  4551. L1260 ldx #T40_acOn ; X points to 40Hz timer T40_acOn
  4552. brclr port3Snap0, #$10, L1261 ; Branch if A/C switch flag off (switch is on?)
  4553. ldaa #$18 ; Switch is off, init timer
  4554. staa $00,x ; Re-init T40_acOn with $18 (0.6s, min time before activating A/C)
  4555.  
  4556. ;---------------------------------------------------------------------------------
  4557. ; Re-init T40_acOnRpm if rpm<438
  4558. ; (implement a min delay before turning A/C on after RPM > 438 (after start-up)
  4559. ;---------------------------------------------------------------------------------
  4560. L1261 ldaa rpm31 ; a = rpm
  4561. cmpa #$0e ; 438rpm
  4562. bhi L1262 ; Branch if rpm > 438
  4563. ldaa #$20 ; rpm lower than 438, init timer
  4564. staa $01,x ; rpm<438 -> Re-init timer #T40_acOnRpm with $20 (0.8s)
  4565.  
  4566. ;--------------------------------------------------------------
  4567. ; For AT, decide if we will turn A/C on/off based on TPS...
  4568. ;--------------------------------------------------------------
  4569. L1262 .equ $ ;
  4570. #ifdef E932
  4571. ;-----------------------------------------------------------------
  4572. ; Load TPS value of 78% or 82% (80% target with +/-2% hysteresis)
  4573. ;-----------------------------------------------------------------
  4574. ldaa #$d2 ; Load 82% threshold
  4575. brclr varFlags0, #$01, L1263 ; Do not branch if TPS was higher than 82% the previous time we were here
  4576. ldaa #$c7 ; Use 78% threshold instead (hysteresis)
  4577.  
  4578. ;-----------------------------------------------------------------
  4579. ; Check if TPS is above/below threshold and set varFlags0 accordingly
  4580. ;-----------------------------------------------------------------
  4581. L1263 orm varFlags0, #$01 ; Assume this bit will be set (reset below)
  4582. cmpa tpsRaw ;
  4583. bls L1264 ; Branch if threshold smaller than TPS (TPS higher than threshold)
  4584.  
  4585. ;----------------------------------------------------------------------------------
  4586. ; TPS lower than threshold, reset varFlags0.0 flag and set timer T40_acCut to 5s
  4587. ;----------------------------------------------------------------------------------
  4588. andm varFlags0, #$fe ; TPS lower than threshold, reset varFlags0.0
  4589. ldaa #$c8 ; 5s at 40Hz
  4590. staa $02,x ; Init T40_acCut to 5s (delay before turning A/C back on)
  4591. #endif
  4592.  
  4593. ;---------------------------------------------------------------------------
  4594. ; Make sure both T40_acOn and T40_acOnRpm are 0 before attempting to turn A/C on
  4595. ; Implement a min delay before engaging A/C
  4596. ; clutch once car has started or A/C button is pressed
  4597. ;---------------------------------------------------------------------------
  4598. L1264 ldaa $00,x ; a = T40_acOn
  4599. oraa $01,x ; a = T40_acOn | T40_acOnRpm
  4600. bne L1266 ; Branch if at least one timert not yet 0 (turn A/C off)
  4601.  
  4602. ;-----------------------------------------------------------------------------
  4603. ; At this point, both T40_acOn and T40_acOnRpm timers are at 0, we can turn A/C on
  4604. ;-----------------------------------------------------------------------------
  4605. #ifdef E932
  4606. ;--------------------------------------------------------------
  4607. ; For AT, decide if we will turn A/C on/off based on TPS...
  4608. ; Seems A/C is cutoff for a maximum of 5 seconds when TPS>80%
  4609. ; but it is turned back on whenever TPS goes below 80% (no delay)
  4610. ; It would probably be better to turn-it off for 5s anyway...
  4611. ;--------------------------------------------------------------
  4612. brclr varFlags0, #$01, L1265 ; Branch if TPS was lower than threshold (turn it back on immediately, not the best????)
  4613. brset port3Snap0, #$20, L1265 ; TPS is higher than threshold, branch if Park/neutral flag is set (no need to cutoff if in park)
  4614. ldaa $02,x ; Get T40_acCut value to see if we can turn A/C back on (5 second delay)
  4615. bne L1266 ; Branch if timer not expired
  4616. #endif
  4617.  
  4618. ;----------------
  4619. ; Turn A/C on
  4620. ;----------------
  4621. L1265 andm port1, #$df ; Turn A/C clutch bit to 0
  4622. bra L1267
  4623.  
  4624. ;----------------
  4625. ; Turn A/C off
  4626. ;----------------
  4627. L1266 orm port1, #$20 ; Turn A/C clutch bit to 1
  4628.  
  4629. ;--------------------------------------------------------------
  4630. ; Section to update the purge solenoid activation/deactivation
  4631. ;--------------------------------------------------------------
  4632. ;------------------------------------------------------------
  4633. ; Reset forced activation and forced deactivation flags
  4634. ; since we are going to update them
  4635. ;------------------------------------------------------------
  4636. L1267 andm varFlags0, #$9f ; Reset bits 01100000 ($20 and $40)
  4637.  
  4638. ;-----------------------------------
  4639. ; Branch according to engine state
  4640. ;-----------------------------------
  4641. brclr state1, #$10, L1270 ; Branch if notRotating clear
  4642.  
  4643. ;-----------------------------------------------------------
  4644. ; Engine notRotating, check if an OBD command is ongoing
  4645. ; to activate solenoid, set flags in consequence
  4646. ;-----------------------------------------------------------
  4647. brset obdActCmd, #$01, L1269 ; Branch if purge solenoid is actuated by OBD
  4648. orm varFlags0, #$20 ; Set "forced deactivation flag"
  4649. bra L1276 ; Branch to continue
  4650. L1269 orm varFlags0, #$40 ; Set "forced activation" flag
  4651. bra L1276 ; Branch to reset pulsewidth modulation flag since engine not rotating...
  4652.  
  4653. ;----------------------------------------------------------------
  4654. ; Engine rotating
  4655. ; Check if minimum conditions are met to activate purge solenoid
  4656. ;----------------------------------------------------------------
  4657. L1270 ldaa T2_crank ; a = T2_crank
  4658. adda #$78 ;
  4659. bcs L1271 ; Branch if engine stopped "startingToCrank" less than 60 sec ago.
  4660. brclr ftrimFlags, #$03, L1271 ; Branch if current trim range is "low"
  4661. ldaa ectFiltered ; a = ectFiltered
  4662. cmpa #$2d ; 66degC
  4663. bls L1272 ; Branch if temperature(ectFiltered) >= 66degC
  4664.  
  4665. ;-----------------------------------------------------------
  4666. ; Conditions are not good to activate purge solenoid
  4667. ; Set "forced deactivation" flag
  4668. ;-----------------------------------------------------------
  4669. L1271 orm varFlags0, #$20 ; Set flag
  4670. bra L1274 ; Branch to continue
  4671.  
  4672. ;---------------------------------------------------------------
  4673. ; Minimum condition for activation are met, check if there are
  4674. ; special conditions where we should always activate???
  4675. ;---------------------------------------------------------------
  4676. L1272 brclr state1, #$80, L1273 ; Branch to activate if open loop mode is active
  4677.  
  4678. ;------------------------------
  4679. ; We are in closed loop mode
  4680. ;------------------------------
  4681. ldaa baroChecked ; a = baroChecked
  4682. cmpa #$9c ; 1 bar
  4683. bcs L1273 ; Branch to activate if baroChecked < 0.76 bar, activate if baro is very low?
  4684. ldaa iatChecked ; a = iatChecked
  4685. cmpa #$49 ; 50degC
  4686. bhi L1274 ; Branch if temperature(iatChecked) < 50degC
  4687.  
  4688. ;--------------------------------------------------------------------------------
  4689. ; At this point, min conditions are met and either
  4690. ; open loop mode is active
  4691. ; or
  4692. ; closed loop mode is active and (baroChecked < 0.76 or temperature(iatChecked) >= 50degC)
  4693. ;
  4694. ; Set "forced activation" flag indicating
  4695. ; we should activate purge solenoid
  4696. ;--------------------------------------------------------------------------------
  4697. L1273 orm varFlags0, #$40 ; Set flag
  4698.  
  4699. ;----------------------------------------------------------------
  4700. ; Continuation from code flows above when engine is rotating...
  4701. ; Update varFlags0.7 deactivation flag if its timer is expired
  4702. ;
  4703. ; varFlags0.7 deactivation flag is used to activate/deactivate
  4704. ; solenoid when none of the other two flags are set. Flag
  4705. ; stays set for 24sec and stays reset for 212 sec. Toggled
  4706. ; between the two states, basically implementing pulsewidth
  4707. ; modulation with a very long period...
  4708. ;----------------------------------------------------------------
  4709. L1274 ldaa T0p5_purge ; a = T0p5_purge
  4710. bne L1278 ; Bail to activate/deactivate if timer not expired
  4711.  
  4712. ;-----------------------------------------------------------------
  4713. ; Timer is expired, time to toggle the flag,
  4714. ; branch to appropriate section depending on current flag value
  4715. ;-----------------------------------------------------------------
  4716. brset varFlags0, #$80, L1275 ; Branch if deactivation flag was set previously
  4717.  
  4718. ;-----------------------------------------------------------------------
  4719. ; Flag is not set, first check if "forced activation" is requested
  4720. ; in that case we just bail since it doesn't matter anymore...
  4721. ;-----------------------------------------------------------------------
  4722. brset varFlags0, #$40, L1278 ; Bail to activate if solenoid needs "forced activation"
  4723.  
  4724. ;-----------------------------------------------------------------------
  4725. ; Time has come to toggle the flag to 1 and reset the timer to 24sec
  4726. ;-----------------------------------------------------------------------
  4727. ldaa #$0c ; a = 24s
  4728. orm varFlags0, #$80 ; Set flag
  4729. bra L1277 ; Branch to update timer and activate/deactivate
  4730.  
  4731. ;-----------------------------------------------------------------------
  4732. ; Flag is set, first check if "forced deactivation" is requested
  4733. ; in that case we just bail since it doesn't matter anymore...
  4734. ;-----------------------------------------------------------------------
  4735. L1275 brset varFlags0, #$20, L1278 ; Bail to activate/deactivate if "forced deactivation" flag is set
  4736.  
  4737. ;-----------------------------------------------------------------------
  4738. ; Time has come to toggle the flag to 0 and reset the timer to 212sec
  4739. ;-----------------------------------------------------------------------
  4740. L1276 ldaa #$6a ; 212s
  4741. andm varFlags0, #$7f ; Reset flag
  4742. L1277 staa T0p5_purge ; T0p5_purge = 212sec
  4743.  
  4744. ;------------------------------------------------------------------
  4745. ; Continuation from all code flows above...
  4746. ; Based on flags, decide to activate or deactivate purge solenoid
  4747. ; Flags are tested in priority order...
  4748. ;------------------------------------------------------------------
  4749. L1278 brset varFlags0, #$40, L1279 ; 1st priority, branch to activate if forced activation is set
  4750. brset varFlags0, #$20, L1280 ; 2nd priority, branch to deactivate if forced deactivation is set
  4751. brset varFlags0, #$80, L1280 ; 3rd priority, branch to deactivate if pulswidth modulation flag is set
  4752.  
  4753. ;---------------------------
  4754. ; Activate purge solenoid
  4755. ;---------------------------
  4756. L1279 andm port6, #$ef ; Activate purge solenoid
  4757. bra L1281 ;
  4758.  
  4759. ;----------------------------
  4760. ; Deactivate purge solenoid
  4761. ;----------------------------
  4762. L1280 orm port6, #$10 ; Deactivate purge solenoid
  4763.  
  4764.  
  4765. ;--------------------------------------------------------------
  4766. ; Section to update the EGR solenoid activation/deactivation
  4767. ;--------------------------------------------------------------
  4768. ;----------------------------------------------------------------
  4769. ; Compute egr duty cycle factor
  4770. ; as a function of rpm and airVol from 2D table t_egrDutyFact
  4771. ;----------------------------------------------------------------
  4772. L1281 ldab rpmIndex1 ;
  4773. ldaa #$70 ; max of rpm
  4774. jsr abmin ; b = max(rpmIndex1, $70)
  4775. stab temp6 ; column index is rpm
  4776. ldab airVol ;
  4777. ldaa #$80 ; max of airVol
  4778. jsr rpmRange ;
  4779. stab temp7 ; row index is airVol
  4780. ldab #$80 ; b = 100% duty cycle
  4781. brclr state1, #$10, L1282 ; Branch if notRotating clear
  4782. brset obdActCmd, #$08, L1283 ; Engine notRotating, branch if EGR solenoid actuated (by OBD) -> use 100% duty
  4783. L1282 clrb ; b = 0% duty cycle
  4784. brset state2, #$08, L1283 ; Branch if no pulse accumulator interrupts -> use 0% duty cycle
  4785. brset state1, #$11, L1283 ; Branch if notRotating or startingToCrank -> use 0% duty cycle
  4786. ldx #t_egrDutyFact ;
  4787. ldy #$0800 ;
  4788. jsr lookup2D ; b = t_egrDutyFact(rpm, airVol)
  4789. clra ;
  4790. std temp6 ; temp6:temp7 = t_egrDutyFact(rpm,airVol)
  4791.  
  4792. ;---------------------------------------------------------------------------------
  4793. ; Get EGR solenoid duty cycle from t_egrDuty and apply factor from above
  4794. ;---------------------------------------------------------------------------------
  4795. ldx #t_egrDuty ;
  4796. ldaa ectCond ;
  4797. jsr interp32mul ; b = t_egrDutyFact(rpm,airVol) * t_egrDuty(ect)
  4798. L1283 stab egrDuty128 ; egrDuty128 = t_egrDutyFact(rpm,airVol) * t_egrDuty(ect) with $80=100%
  4799.  
  4800. ;-------------------------------------
  4801. ; Scale duty factor to 00 - $30 range
  4802. ;-------------------------------------
  4803. ldaa #$30 ;
  4804. mul ;
  4805. jsr scale128 ; b = $30 * egrDuty128/128
  4806. stab egrDuty ; egrDuty with max of $30=100%
  4807.  
  4808. ;--------------------------------------------------------------------
  4809. ; Re-Init T2_EcuPower to $ff if T40_noPower expired
  4810. ; (T2_EcuPower will start counting from $ff when power is back on...
  4811. ;--------------------------------------------------------------------
  4812. ldaa T40_noPower ;
  4813. bne L1284 ; Branch if ECU still has power
  4814. ldaa #$ff ; ECU about to loose power, reset T2_EcuPower to max (127.5sec)
  4815. staa T2_EcuPower ;
  4816.  
  4817. ;-----------------------------------------------------------
  4818. ; Section to update boost control solenoid duty cycle
  4819. ;-----------------------------------------------------------
  4820. ;-----------------------------------------------------------
  4821. ; Check if time has come, section is updated at ~40Hz
  4822. ;-----------------------------------------------------------
  4823. L1284 brclr Tclocks, #$01, L1298 ; Bail of section if 40Hz signal no set
  4824. ldab fpsBcsFlags ; b = old fpsBcsFlags
  4825. andm fpsBcsFlags, #$8f ; Assume those three flags are reset, updated below (0111 0000)
  4826.  
  4827. ;-------------------------------------------------------------------
  4828. ; Check if octane is above/below threshold with hysteresis
  4829. ; (high $c0, low $9a) and update fpsBcsFlags.5 flag (reset above)
  4830. ;-------------------------------------------------------------------
  4831. ldaa #$9a ; start with low threshold, a = $9a
  4832. bitb #$20 ; test bit
  4833. bne L1285 ; Branch if old fpsBcsFlags.5 was set
  4834. ldaa #$c0 ; bit was not set, use higher threshold a = $c0
  4835. L1285 cmpa octane ;
  4836. bcc L1286 ; Branch if octane <= threshold
  4837. orm fpsBcsFlags, #$20 ; set flag since we are above threshold
  4838.  
  4839. ;-------------------------------------------------------------------
  4840. ; Check if mafRaw16 is above/below threshold with hysteresis
  4841. ; (high $4e, low $38) and update fpsBcsFlags.4 flag (reset above)
  4842. ;-------------------------------------------------------------------
  4843. L1286 ldaa #$38 ; a = #0038
  4844. bitb #$10 ;
  4845. bne L1287 ; Branch if old fpsBcsFlags.4 was set
  4846. #ifdef E931
  4847. ldaa #$4e ; a = #004e
  4848. #else
  4849. ldaa #$4a ;
  4850. #endif
  4851. L1287 cmpa mafRaw16 ;
  4852. bcc L1288 ; branch if mafRaw16 <= threshold
  4853. orm fpsBcsFlags, #$10 ; set flag since we are above threshold
  4854.  
  4855.  
  4856. ;-------------------------------------------------
  4857. ; Branch to proper section if engine not running
  4858. ;-------------------------------------------------
  4859. L1288 brclr state1, #$10, L1289 ; Branch if notRotating clear
  4860. brset obdActCmd, #$20, L1295 ; Engine notRotating, branch if boost solenoid actuated (by OBD command I assume)
  4861. L1289 brset state1, #$11, L1293 ; branch if notRotating or startingToCrank
  4862.  
  4863. ;----------------------------------------------------
  4864. ; Engine is running...
  4865. ; Check if time has come to update
  4866. ;----------------------------------------------------
  4867. ldaa T40s_bcs ;
  4868. bne L1297 ; Branch if timer not expired
  4869.  
  4870. ;----------------------------------------------------
  4871. ; Timer expired, time to update has come (~2Hz)
  4872. ;
  4873. ; By default, increase bcsDuty by 8 and test if we
  4874. ; should not reduce it instead
  4875. ;----------------------------------------------------
  4876. ldab bcsDuty ; b = bcsDuty
  4877. addb #$08 ; b = bcsDuty + 8
  4878. brset state2, #$28, L1292 ; Branch if no pulse accumulator interrupts being received or knock sensor not working
  4879. brset fpsBcsFlags, #$10, L1292 ; Branch if mafRaw16 above threshold
  4880. brset fpsBcsFlags, #$20, L1294 ; Branch if octane above threshold
  4881.  
  4882. ;--------------------------------------------------------------
  4883. ; At this point, knock sensor is not working or we are not
  4884. ; receiving airflow sensor interrupts or mafRaw16 is above
  4885. ; threshold or octane is below threshold, basically these
  4886. ; are onditions where we would want to reduce turbo pressure
  4887. ;
  4888. ; Reduce bcsDuty by 2 instead of increasing by 8
  4889. ;--------------------------------------------------------------
  4890. L1292 subb #$10 ; b = bcsDuty + 8 - 10 = bcsDuty - 2
  4891. bcc L1294 ; Branch if no underflow
  4892. L1293 clrb ; Use min of 0
  4893.  
  4894. ;---------------------------------------
  4895. ; Check new bcsDuty for max of $30,
  4896. ; store new value and update the timer
  4897. ;---------------------------------------
  4898. L1294 cmpb #$30 ;
  4899. bcs L1296 ; Branch if new bcsDuty < $30
  4900. L1295 ldab #$30 ; Use max of $30
  4901. L1296 stab bcsDuty ; Store new bcsDuty
  4902. ldaa #$14 ; Re-init timer to 20 (0.5sec)
  4903. L1297 deca ; Decrement timer
  4904. staa T40s_bcs ; Store updated timer
  4905.  
  4906.  
  4907. ;-------------------------------------
  4908. ; Decrement T40s_tps at 40Hz
  4909. ;-------------------------------------
  4910. L1298 sei ;
  4911. ldx #T40s_tps ;
  4912. jsr decX40Hz ; Decrement T40s_tps at 40Hz
  4913. cli ;
  4914.  
  4915. ;------------------------------------
  4916. ; Compute the boost gauge duty cycle
  4917. ; depending on current conditions
  4918. ;------------------------------------
  4919. clrb ; load default duty cycle of b = 0
  4920. ldaa T40_noPower ;
  4921. beq L1299 ; Bail if timer expired (ECU is about to shut-down...) (use 0 duty)
  4922. ldab #$0c ; Load default duty cycle of b = $0c
  4923. brset state1, #$10, L1299 ; Bail if notRotating (use half duty...)
  4924. clrb ; load default duty cycle of b = 0
  4925. brset state2, #$08, L1299 ; Bail if no pulse accumulator interrupts (use 0 duty)
  4926. ldx #t_bGauge ; x points to boost gauge table
  4927. ldaa airVolT ; a = airVolT
  4928. #ifdef batteryGauge
  4929. jsr battGauge ;
  4930. #else
  4931. jsr interp32 ; b = t_bGauge(airVolT) (max value is $18...)
  4932. #endif
  4933. ;-------------------------------------------------
  4934. ; Update bGaugeODuty with $18-dutyCycle (min of 0)
  4935. ; bGaugeODuty is the off-duty cycle...
  4936. ;-------------------------------------------------
  4937. L1299 ldaa #$18 ; a = $18
  4938. sba ; a = $18-t_bGauge(airVolT)
  4939. bcc L1300 ; Branch if no underflow
  4940. clra ; underflow, use min
  4941. L1300 staa bGaugeODuty ; Update boost gauge off-duty cycle
  4942.  
  4943. ;----------------------------------------------
  4944. ; Section to update the fuel pressure solenoid
  4945. ;----------------------------------------------
  4946. ;-----------------------------------------------------
  4947. ; First check if there are any reason to activate it
  4948. ;-----------------------------------------------------
  4949. ldab fpsBcsFlags ; b = old fpsBcsFlags, used later...
  4950. andm fpsBcsFlags, #$fb ; Reset bit indicating solenoid was just deactivated will be updated below if required
  4951. brclr state1, #$11, L1302 ; branch if notRotating and startingToCrank clear
  4952. andm fpsBcsFlags, #$f7 ; engine is either notRotating or startingToCrank
  4953. brclr state1, #$10, L1301 ; Branch if notRotating clear (startingToCrank is set...)
  4954. brset obdActCmd, #$04, L1306 ; branch to activate solenoid if OBD command activated
  4955. bra L1307 ; No reason to activate it, branch to deactivate solenoid
  4956.  
  4957. ;-----------------------------------------------------------------
  4958. ; Engine is startingToCrank, check if we should set fpsBcsFlags.3 flag (vapor lock)
  4959. ; Basically set the flag when vapor lock conditions exists
  4960. ;-----------------------------------------------------------------
  4961. L1301 ldaa iatChecked ;
  4962. cmpa #$9d ;
  4963. bhi L1302 ; Branch if temperature(iatChecked) < 10degC
  4964. ldaa ectFiltered ;
  4965. cmpa #$27 ; 72degC
  4966. bhi L1302 ; Branch if temperature(ectFiltered) < 72degC
  4967.  
  4968. ;------------------------------------------------------------------------------------------
  4969. ; At this point engine is startingToCrank and temperature(iatChecked) >= 10degC
  4970. ; and temperature(ectFiltered) >= 72degC, set flag indicating vapor lock conditions exist, NOT???
  4971. ;------------------------------------------------------------------------------------------
  4972. orm fpsBcsFlags, #$08 ; Set flag indicating vapor lock conditions exist
  4973.  
  4974. ;--------------------------------------------------------------------
  4975. ; Engine is running or notRotating or startingToCrank
  4976. ; Check if we should reset vapor lock flag: 3 minutes after
  4977. ; engine was started or if o2Fbk < $4d (meaning we are running rich)
  4978. ;--------------------------------------------------------------------
  4979. L1302 ldaa T0p5_crank1 ;
  4980. adda #$5a ;
  4981. bcc L1303 ; branch to reset flag if engine stopped "startingToCrank" more than 180s ago (engine has been running for 3 minutes)
  4982. ldaa o2Fbk ; a = o2Fbk
  4983. cmpa #$4d ;
  4984. bhi L1304 ; Dont reset if o2Fbk > $4d (running lean???)
  4985. L1303 andm fpsBcsFlags, #$f7 ; Reset vappor lock flag
  4986.  
  4987. ;---------------------------------------------
  4988. ; Check whether we have vapor lock conditions
  4989. ;---------------------------------------------
  4990. L1304 brset fpsBcsFlags, #$08, L1305 ; Branch if vapor lock flag is set
  4991.  
  4992. ;---------------------------------------------------------------------
  4993. ; Vapor lock flag is not set, at this point b = old fpsBcsFlags
  4994. ; Check if solenoid deactivation is just happening now and
  4995. ; set flag to indicate so
  4996. ;---------------------------------------------------------------------
  4997. bitb #$08 ;
  4998. beq L1307 ; Branch to reset solenoid if bit was also 0 on previous iteration
  4999. orm fpsBcsFlags, #$04 ; Set flag indicating solenoid was just deactivated
  5000. bra L1307 ; Branch to deactivate it
  5001.  
  5002. ;----------------------------------------------
  5003. ; Vapor lock flag is set, check additional
  5004. ; conditions before activating solenoid
  5005. ;----------------------------------------------
  5006. L1305 ldaa T40_crank ;
  5007. adda #$50 ;
  5008. bcs L1306 ; branch to activate solenoid if engine stopped "startingToCrank" less than 2s ago
  5009. brset closedLpFlags, #$01, L1307 ; Branch to deactivate solenoid if the ECU has determined that we should be using closed loop mode (or getting close to it)
  5010.  
  5011. ;-------------------------------------
  5012. ; Activate the fuel pressure solenoid
  5013. ;-------------------------------------
  5014. L1306 andm port5, #$ef ; Activate the fuel pressure solenoid
  5015. bra L1309
  5016.  
  5017. ;----------------------------------------
  5018. ; Deactivate the fuel pressure solenoid
  5019. ;----------------------------------------
  5020. L1307 orm port5, #$10 ; Deactivate the fuel pressure solenoid
  5021. L1309 rts
  5022.  
  5023.  
  5024.  
  5025. ;******************************************************************
  5026. ;
  5027. ;
  5028. ; Second subroutine
  5029. ;
  5030. ;
  5031. ;******************************************************************
  5032. ;--------------------------------------------------
  5033. ; Build port3Snap1 from port3Snap0 using a
  5034. ;
  5035. ; Set port3Snap1.2 if vssCnt1!=0, reset otherwise
  5036. ;--------------------------------------------------
  5037. subroutine2 ldaa port3Snap0 ; start with a = port3Snap1 = port3Snap0
  5038. anda #$fb ; reset 00000100
  5039. ldab vssCnt1 ; b = vssCnt1
  5040. beq L1311 ;
  5041. oraa #$04 ; Set flag
  5042.  
  5043. ;---------------------------------------------------------------
  5044. ; Reset iscFlags0.6 if key is in start and T40_noPower not expired??????
  5045. ; (meaning engine is cranking and battery not KO?
  5046. ;---------------------------------------------------------------
  5047. L1311 bita #$40 ;
  5048. bne L1312 ; Bail if key is not is start
  5049. tst T40_noPower ; Key in start
  5050. beq L1312 ; Bail if timer expired
  5051. andm iscFlags0, #$bf ; Key in start and timer not expired, reset max calibration flag 0100 0000
  5052.  
  5053. ;----------------------------------------------------------
  5054. ; Re-init T40_noPower at 5 (0.125s) if ECU still has power
  5055. ;----------------------------------------------------------
  5056. L1312 bita #$02 ;
  5057. bne L1313 ; Branch if IG1 at 0V (No more power, ECU about to turn off?)
  5058. ldab #$05 ; ECU not about to turn off, restart timer
  5059. stab T40_noPower ;
  5060.  
  5061. ;-------------------------------------------
  5062. ; Move old port3Snap1 to oldP3Snap1 and
  5063. ; update port3Snap1 with new value
  5064. ;-------------------------------------------
  5065. L1313 ldab port3Snap1 ; b = old port3Snap1
  5066. staa port3Snap1 ; port3Snap1 = new port3Snap1
  5067. stab oldP3Snap1 ; oldP3Snap1 = old port3Snap1
  5068.  
  5069. ;-------------------
  5070. ; Update iscStepMax
  5071. ;-------------------
  5072. ldaa #$78 ; I believe this is the max iscStepCurr value (120 decimal)
  5073. staa iscStepMax ; iscStepMax = max possible value?
  5074. nop ;
  5075. nop ;
  5076. nop ;
  5077.  
  5078. ;---------------------------------------------------------------
  5079. ; Decrement T40s_iscStable at 40Hz if iscStepCurr = iscStepTarg
  5080. ;---------------------------------------------------------------
  5081. ldaa iscStepTarg ;
  5082. cmpa iscStepCurr ;
  5083. bne L1314 ; Branch if iscStepCurr != iscStepTarg
  5084. ldx #T40s_iscStable ;
  5085. jsr decX40Hz ; Decrement T40s_iscStable at 40Hz
  5086.  
  5087. ;-----------------------------------------------------
  5088. ; If engine is notRotating, re-init some ISC variables
  5089. ;-----------------------------------------------------
  5090. L1314 brclr state1, #$10, L1315 ; Bail if notRotating clear
  5091. jsr iscYnInit ; Init isc variables
  5092. clr iscStStall ;
  5093. #ifdef E932
  5094. clr iscStBaseAcAdj ;
  5095. #endif
  5096. andm iscFlags1, #$5f ; reset flags used when engine rotating or running, 1010 0000
  5097. orm iscFlags1, #$01 ; set flag (flag is only 0 when key in start and iscStTargSpec = iscStepCurr)
  5098.  
  5099. ;-----------------------------------------------------
  5100. ; Update isc stable timer if power
  5101. ; steering flag changed since last time
  5102. ;-----------------------------------------------------
  5103. L1315 ldaa port3Snap1 ;
  5104. eora oldP3Snap1 ;
  5105. bita #$08 ;
  5106. beq L1316 ; Branch if port3Snap1.3 did not change value since last time
  5107. ldab #$50 ;
  5108. jsr updIscStableTimer ;
  5109.  
  5110. ;-----------------------------------------------------
  5111. ; Update isc stable timer if A/C state
  5112. ; changed since last time
  5113. ;-----------------------------------------------------
  5114. L1316 bita #$10 ;
  5115. beq L1317 ; Branch if port3Snap1.4 did not change value since last time
  5116. ldab #$50 ;
  5117. jsr updIscStableTimer ;
  5118. L1317 .equ $ ;
  5119.  
  5120. ;-----------------------------------------------------
  5121. ; Update isc stable timer if park/neutral
  5122. ; changed since last time (E932)
  5123. ;-----------------------------------------------------
  5124. #ifdef E932
  5125. bita #$20 ;
  5126. beq L1319 ; Branch if port3Snap1.5 did not change value since last time
  5127. ldab #$50 ;
  5128. brclr port3Snap1, #$20, L1318 ; Makes no difference, $50 used anyway...
  5129. ldab #$50 ;
  5130. L1318 jsr updIscStableTimer ;
  5131. #endif
  5132.  
  5133. ;-----------------------------------------------------
  5134. ; Update isc stable timer if tpsDiffMax2 > $04
  5135. ; i.e. gas pedal is moving...
  5136. ;-----------------------------------------------------
  5137. L1319 ldaa tpsDiffMax2 ;
  5138. cmpa #$04 ;
  5139. bcs L1320 ;
  5140. ldab #$28 ;
  5141. jsr updIscStableTimer ;
  5142.  
  5143. ;----------------------------------------------------------------
  5144. ; Update isc stable timer if idle switch is off
  5145. ; Timer value is from table t_iscStableIdleSw
  5146. ; Timer will only start counting when idle switch is back on...
  5147. ;----------------------------------------------------------------
  5148. L1320 ldaa port3Snap1 ;
  5149. bmi L1323 ; Bail if idle switch is ON
  5150. ldd rpm4 ;
  5151. lsrd ; d = rpm4/2
  5152. subb idleSpdTarg ;
  5153. sbca #$00 ; d = rpm4/2 - idleSpdTarg
  5154. bcc L1321 ; Branch if no overflow
  5155. clra ;
  5156. clrb ; Use min of d=0
  5157. L1321 lsrd ;
  5158. lsrd ; d = (rpm4/2 - idleSpdTarg)/4
  5159. cmpd #$00a0 ;
  5160. bcs L1322 ; Branch if (rpm4/2 - idleSpdTarg)/4 < $a0 (5000rpm)
  5161. ldab #$a0 ; Use max of $a0 (5000rpm)
  5162. L1322 tba ; a = (rpm4/2 - idleSpdTarg)/4
  5163. ldx #t_iscStableIdleSw ;
  5164. jsr interp16b ; b = t_iscStableIdleSw((rpm4/2 - idleSpdTarg)/4)
  5165. jsr updIscStableTimer ;
  5166.  
  5167. ;---------------------------------------------------
  5168. ; Update isc stable timer if engine is not runnning
  5169. ; or if min or max isc calibration is ongoing or if
  5170. ; we have ignition problems
  5171. ;---------------------------------------------------
  5172. L1323 brset state1, #$11, L1324 ; Branch to update if notRotating or startingToCrank
  5173. brset iscFlags0, #$a0, L1324 ; Branch to update if min or max calibration requested flag is set
  5174. brclr coilChkFlags, #$80, L1325 ; Bail if no problem found on ignition signal
  5175. L1324 ldab #$78 ;
  5176. jsr updIscStableTimer ;
  5177.  
  5178. ;-----------------------------------------------------------------
  5179. ; Update idleSpdInit = t_idleSpd(ect) or t_idleSpdDr(ect) (E932)
  5180. ;-----------------------------------------------------------------
  5181. L1325 .equ $
  5182. #ifdef E931
  5183. ldx #t_idleSpd ;
  5184. jsr interpEct ; b = t_idleSpd(ect)
  5185. #else
  5186. ldx #t_idleSpdDr ;
  5187. brclr port3Snap1, #$20, L1326 ;
  5188. ldx #t_idleSpd ;
  5189. L1326 jsr interpEct ;
  5190. #endif
  5191. stab idleSpdInit ; idleSpdInit = t_idleSpd(ect) or t_idleSpdDr(ect)
  5192.  
  5193. ;-----------------------------------------------------------------
  5194. ; Update idleSpdMin with 0 if A/C switch is on
  5195. ; or if AT is in drive or if T0p5_crCold timer expired
  5196. ;-----------------------------------------------------------------
  5197. clrb ; preload default value of 0
  5198. ldaa port3Snap1 ;
  5199. anda #$30 ;
  5200. cmpa #$30 ;
  5201. bne L1328 ; Branch to use default of 0 if A/C switch is on or if AT is in drive
  5202. ldaa T0p5_crCold ;
  5203. beq L1328 ; Branch to use default of 0 if T0p5_crCold timer expired
  5204.  
  5205. ;-----------------------------------------------
  5206. ; A/C switch is off and AT is in not in drive
  5207. ; and T0p5_crCold timer not expired
  5208. ;
  5209. ; Compute idleSpdMin
  5210. ;-----------------------------------------------
  5211. ldaa #$3c ; a = $3c
  5212. staa temp1 ; temp1 = $3c
  5213. ldaa #$13 ; a = $13
  5214. brset iscFlags1, #$20, L1327 ; Branch if engine startingToCrank and temperature(iat) < 75degC
  5215. #ifdef E931
  5216. ldaa #$20 ; Use higher value
  5217. #else
  5218. ldaa #$13 ; Use same value
  5219. #endif
  5220. L1327 ldab T0p5_crCold ; b = T0p5_crCold
  5221. mul ; d = ($13 or $20) * T0p5_crCold
  5222. div temp1 ; b = ($13 or $20) * T0p5_crCold / $3c
  5223. addb t_idleSpd ; b = ($13 or $20) * T0p5_crCold / $3c + t_idleSpd(0)
  5224. L1328 stab idleSpdMin ; idleSpdMin = 0 or (t_idleSpd(0) + (0.32 0r 0.53) * T0p5_crCold)
  5225.  
  5226. ;----------------------------------------------------------------------------------
  5227. ; Update idleSpdTarg from idleSpdInit and idleSpdMin and A/C park/neutral conditions
  5228. ;----------------------------------------------------------------------------------
  5229. ldaa idleSpdInit ; a = idleSpdInit
  5230. brset port3Snap1, #$10, L1331 ; Branch if A/C switch is off?
  5231. #ifdef E932
  5232. ldab #$53 ; 648rpm
  5233. brclr port3Snap1, #$20, L1330 ; Branch if park/neutral???
  5234. #endif
  5235. ldab #$6d ; 852rpm
  5236. L1330 cba ;
  5237. bcc L1331 ; Branch if idleSpdInit >= $6d
  5238. tba ; Use min of a = $6d
  5239.  
  5240. L1331 cmpa idleSpdMin ;
  5241. bcc L1332 ; Branch if idleSpdInit >= idleSpdMin
  5242. ldaa idleSpdMin ; Use min of idleSpdMin
  5243. L1332 staa idleSpdTarg ; idleSpdTarg = ...
  5244.  
  5245.  
  5246. #ifdef E931
  5247. ;-------------------------------------------
  5248. ; Update iscStBase for E931
  5249. ; iscStBase = t_iscStEct0(ect)
  5250. ;-------------------------------------------
  5251. ldx #t_iscStEct0 ;
  5252. jsr interpEct ;
  5253. stab iscStBase ; iscStBase = t_iscStEct0(ect)
  5254. #else
  5255. ;------------------------------------------------------------------
  5256. ; Update iscStBase for E932
  5257. ; Choose a different table if transmission is engaged (e.g. drive)
  5258. ;
  5259. ; iscStBase = t_iscStEct1(ect) or t_iscStEct0(ect)
  5260. ;------------------------------------------------------------------
  5261. ldx #t_iscStEct1 ;
  5262. brclr port3Snap1, #$20, L1334 ; Branch if park/neutral
  5263. ldx #t_iscStEct0 ;
  5264. L1334 jsr interpEct ;
  5265. stab iscStBase ; iscStBase = t_iscStEct0(ect) or t_iscStEct1(ect)
  5266.  
  5267. ;-------------------------------------------------------------------
  5268. ; For E932, decrement iscStBaseAcAdj by 1 (min of 0) at ~2.2Hz
  5269. ;-------------------------------------------------------------------
  5270. ldaa T40_21 ; a = T40_21
  5271. bne L1336 ; Branch if timer not expired
  5272. ldaa #$12 ; Timer expired, re-init to 0.45sec
  5273. staa T40_21 ; T40_21 = 0.45sec
  5274. ldaa iscStBaseAcAdj ; a = iscStBaseAcAdj
  5275. suba #$01 ; a = iscStBaseAcAdj - 1
  5276. bcc L1335 ; Branch if no underflow
  5277. clra ; Underflow, use min of 0
  5278. L1335 staa iscStBaseAcAdj ; update iscStBaseAcAdj
  5279. #endif
  5280.  
  5281. ;---------------------------------------------------
  5282. ; Compute iscStBaseAc, basic iscStep corrected for
  5283. ; additional A/C and transmission load
  5284. ;---------------------------------------------------
  5285. L1336 clra ; preload default value of offset = 0
  5286. brset port3Snap1, #$10, L1342 ; Bail to use offset of 0 if A/C switch off
  5287. ldaa #$1c ; A/C is on, offset = a = $1c
  5288. ldab #$37 ; minValue = b = $37
  5289. #ifdef E932
  5290. brset port3Snap1, #$20, L1337 ; Branch if park/neutral
  5291. ldaa #$0a ; AT in drive, offset = $0a
  5292. ldab #$25 ; minValue = $25
  5293. #endif
  5294. L1337 adda iscStBase ; a = t_iscStEct0(ect) + offset
  5295. bcc L1338 ; Branch if no overflow
  5296. ldaa #$ff ; Use max of $ff
  5297. L1338 cba ;
  5298. bcc L1339 ; Branch if t_iscStEct0(ect) + offset >= minValue
  5299. tba ; Use minValue
  5300. L1339 .equ $
  5301. #ifdef E932
  5302. brclr port3Snap1, #$20, L1341 ; Branch if AT not in park/neutral
  5303. staa iscStBaseAcAdj ; AT in park, iscStBaseAcAdj = t_iscStEct0(ect) + offset
  5304. bra L1342 ;
  5305. L1341 cmpa iscStBaseAcAdj ; AT in drive, update iscStBaseAc with minimum of iscStBaseAcAdj
  5306. bcc L1342 ;
  5307. ldaa iscStBaseAcAdj ;
  5308. #endif
  5309. L1342 staa iscStBaseAc ; For E931, iscStBaseAc = min(t_iscStEct0(ect) + offset, minValue)
  5310.  
  5311.  
  5312. ;------------------------------------------------------------------
  5313. ; Init iscStStartUsed and iscStStartMaster as long as we are
  5314. ; startingToCrank. These values are used at engine startup
  5315. ;------------------------------------------------------------------
  5316. brclr state1, #$01, L1343 ; Bail if startingToCrank clear
  5317. ldx #L2023 ; Engine is startingToCrank
  5318. jsr interpEct ; b = L2023(ect)
  5319. stab iscStStartUsed ; iscStStartUsed = L2023(ect)
  5320. stab iscStStartMaster ; iscStStartMaster = L2023(ect)
  5321.  
  5322. ;----------------------------------------------------------------
  5323. ; Section to update iscStStartUsed, iscStStartMaster
  5324. ; and eventually iscYn after the engine is started
  5325. ;
  5326. ; learning variable iscYn is only updated after a certain delay
  5327. ; has passed since the engine was started. At that point we have
  5328. ; a good idea of how far we are from the ideal isc step we
  5329. ; should be using...
  5330. ;----------------------------------------------------------------
  5331. ;------------------------------------------
  5332. ; First check if basic conditions are met
  5333. ;------------------------------------------
  5334. L1343 brset state1, #$11, L1349 ; bail if notRotating or startingToCrank
  5335. ldaa iscStStartMaster ; a = iscStStartMaster
  5336. beq L1349 ; Bail if iscStStartMaster = 0 (we already updated iscYn once)
  5337. ldaa T40_iscStart ;
  5338. bne L1347 ; Branch if T40_iscStart no yet expired
  5339.  
  5340. ;---------------------------------------------------------------
  5341. ; Engine is running, iscStStartMaster!=0 and T40_iscStart is expired
  5342. ;---------------------------------------------------------------
  5343. ;--------------------------------------------------------------------------
  5344. ; Decrement iscStStartMaster by 1 (min of 0) at around 6Hz (3Hz if cold)
  5345. ;
  5346. ; T40_iscStart is initialized with values from L2024(ect) on
  5347. ; every timer expiry, if L2024(ect)=7 then freqency
  5348. ; will be around 6Hz... In colder temperature, iscStStartMaster will
  5349. ; be decremented at a slower rate, e.g 3Hz
  5350. ;--------------------------------------------------------------------------
  5351. ldx #L2024 ; x points to L2024
  5352. jsr interpEct ; b = L2024(ect)
  5353. stab T40_iscStart ; T40_iscStart = L2024(ect)
  5354. dec iscStStartMaster ; iscStStartMaster = iscStStartMaster - 1
  5355. bne L1347 ; Branch if iscStStartMaster!=0
  5356.  
  5357. ;------------------------------------------------------------------------
  5358. ; iscStStartMaster reached 0, update iscYn = old iscYn + iscStStartUsed + L2023(ect)
  5359. ; and reset iscStStartUsed since we are now finished updating iscYn
  5360. ; i.e. both iscStStartMaster and iscStStartUsed are now 0
  5361. ;
  5362. ; Basically, update the isc learning variables with how much isc offset
  5363. ; was required to get the isc step stable upon engine startup. If isc
  5364. ; was not stable then iscStStartUsed=0 and we didn't learn anything...
  5365. ;------------------------------------------------------------------------
  5366. jsr iscPointers ;
  5367. ldaa iscStStartUsed ; a = iscStStartUsed
  5368. adda $00,y ; a = iscStStartUsed + iscYn, y = y+1
  5369. decy ; y = y - 1
  5370. bcc L1346 ; Branch if no overflow
  5371. ldaa #$ff ; Use max of $ff
  5372. L1346 staa $00,y ; iscYn = old iscYn + iscStStartUsed + L2023(ect)
  5373. clr iscStStartUsed ; iscStStartUsed = 0 since we are now finished updating iscYn
  5374.  
  5375. ;-------------------------------------------------
  5376. ; Check if we should re-init isc Yn variables???
  5377. ;-------------------------------------------------
  5378. L1347 ldaa T40s_iscStable ;
  5379. bne L1348 ; Branch to re-init if T40s_iscStable not expired, i.e. isc is not yet stable
  5380. brset iscLrnFlags, #$10, L1350 ; Branch if conditions are good to update isc learning variables
  5381.  
  5382. ;-------------------------------------------------
  5383. ; At this point, isc is not yet stable or
  5384. ; conditions are not good to update isc variables
  5385. ;
  5386. ; Re-init isc Yn variables
  5387. ;-------------------------------------------------
  5388. L1348 jsr iscYnInit ;
  5389.  
  5390. ;----------------------------------------------------------------------------
  5391. ; At this point isc not yet stable or engine notRotating or startingToCrank
  5392. ; iscStStartUsed = iscStStartMaster
  5393. ;
  5394. ; Basically synch the isc step currently in use with the master value
  5395. ;----------------------------------------------------------------------------
  5396. L1349 ldaa iscStStartMaster ; a = iscStStartMaster
  5397. staa iscStStartUsed ; iscStStartUsed = iscStStartMaster
  5398.  
  5399. ;-----------------------------------------------------------------------
  5400. ; Decrement iscStStall by 3 (min of 0) at 20Hz (T40_stall looping at 2?)???
  5401. ;-----------------------------------------------------------------------
  5402. L1350 ldaa iscStStall ; a = iscStStall
  5403. beq L1355 ; Bail if iscStStall already at 0
  5404. ldab T40_stall ;
  5405. bne L1352 ; Branch if T40_stall not expired
  5406. suba #$03 ; a = iscStStall-3
  5407. bcc L1351 ; Branch if no underflow
  5408. clra ; use min of 0
  5409. L1351 staa iscStStall ; iscStStall = max(iscStStall-3, 0)
  5410. L1352 ldab #$02 ; b = $02
  5411. #ifdef E932
  5412. brset port3Snap1, #$20, L1353 ; Branch if park/neutral
  5413. ldab #$02 ; Use same value anyway...
  5414. #endif
  5415. L1353 ldaa T40_stall ; a = T40_stall
  5416. beq L1354 ; Branch if T40_stall expired
  5417. cba ;
  5418. bcc L1354 ; Branch to use 2 if T40_stall >= 2
  5419. tab ; Use b = T40_stall when T40_stall < 2
  5420. L1354 stab T40_stall ; T40_stall = min(T40_stall, 2)
  5421.  
  5422. ;--------------------------------------------
  5423. ; Re-init T40_revving to 0.5sec if
  5424. ; tpsRaw < 86% or airVol >= $3a ???
  5425. ;
  5426. ; T40_revving will start counting when tpsRaw>86%
  5427. ; and airVol < $3a????
  5428. ;--------------------------------------------
  5429. L1355 ldaa tpsRaw ; a = tpsRaw
  5430. cmpa #$dc ;
  5431. bcs L1356 ; Branch to re-init if tpsRaw < 86%
  5432. ldaa airVol ; a = airVol
  5433. cmpa #$3a ;
  5434. bcs L1357 ; Branch if airVol < $3a
  5435. L1356 ldaa #$14 ; 0.5sec
  5436. staa T40_revving ; Re-init T40_revving to 0.5sec
  5437.  
  5438. ;-------------------------------------------------
  5439. ; Set iscFlags1.7 flag if T40_revving is expired
  5440. ;
  5441. ; Basically, this flag is set when tps has been
  5442. ; high and airVol low for more than 0.5sec
  5443. ;-------------------------------------------------
  5444. L1357 andm iscFlags1, #$7f ; Assume flag is 0
  5445. ldaa T40_revving ;
  5446. bne L1358 ; Branch if T40_revving not expired
  5447. orm iscFlags1, #$80 ; T40_revving expired, set flag
  5448.  
  5449. ;---------------------------------------------------------
  5450. ; Section to update iscStStall as long as idle switch
  5451. ; is off and rpm8>=500 and iscFlags1.7 = 0 (set to 1 when
  5452. ; tps has been high and airVol low for more than 0.5sec)
  5453. ;
  5454. ; iscStStall will therefore be "stuck" to the value
  5455. ; calculated when all these conditions were met the last
  5456. ; time. Basically says where we are coming from when
  5457. ; the throttle plate closes (likeliness of stalling the
  5458. ; engine...)??
  5459. ;---------------------------------------------------------
  5460. ;------------------------------
  5461. ; First check those conditions
  5462. ;------------------------------
  5463. L1358 ldaa port3Snap1 ;
  5464. bmi L1362 ; Bail if idle position switch is on
  5465. ldaa iscFlags1 ;
  5466. bmi L1362 ; Bail if tps has been high and airVol low for more than 0.5sec
  5467. ldaa rpm8 ;
  5468. cmpa #$40 ; 500rpm
  5469. bcs L1362 ; Bail if rpm8 < 500
  5470.  
  5471. ;------------------------------------------------
  5472. ; Set flag, not directly related to calculation
  5473. ;------------------------------------------------
  5474. orm iscLrnFlags, #$20 ;
  5475.  
  5476. ;---------------------------------------------------------------
  5477. ; Compute conditionned tps and store in temp2 for
  5478. ; table interpolation below
  5479. ; condTps (with range of $00 to $a0) =
  5480. ; 2* max(min(tpsRaw,$ba)-$1a,0) if tpsRaw <= 23%
  5481. ; max(min(tpsRaw,$ba)-$1a,0) + $20 if tpsRaw > 23%
  5482. ;---------------------------------------------------------------
  5483. ldab tpsRaw ;
  5484. ldx #$ba1a ;
  5485. jsr clipOffset ; b = max(min(tpsRaw,$ba)-$1a,0)-> returns b = $00 to $a0 (tpsRaw 10% to 73%)
  5486. cmpb #$20 ;
  5487. bhi L1359 ; Branch if max(min(tpsRaw,$ba)-$1a,0) > $20 (tpsRaw>23%)
  5488. aslb ; b = 2* max(min(tpsRaw,$ba)-$1a,0)
  5489. bra L1360 ;
  5490. L1359 addb #$20 ; b = max(min(tpsRaw,$ba)-$1a,0) + $20
  5491. L1360 stab temp2 ; temp2 = condTps
  5492.  
  5493. ;--------------------------------------------------------------
  5494. ; Update iscStStall = max(old iscStStall, t_iscStStall(condTps))
  5495. ;--------------------------------------------------------------
  5496. ldx #t_iscStStall ; x points to t_iscStStall
  5497. #ifdef E932
  5498. brset port3Snap1, #$20, L1361 ; Branch if park/neutral
  5499. ldx #L2030 ; x points to L2030 for E932
  5500. #endif
  5501. L1361 ldaa temp2 ; a = condTps
  5502. jsr interp32 ; b = t_iscStStall(condTps)
  5503. cmpb iscStStall ;
  5504. bcs L1362 ; Branch if t_iscStStall(condTps) < iscStStall
  5505. stab iscStStall ; iscStStall = max(old iscStStall, t_iscStStall(condTps))
  5506.  
  5507. ;--------------------------------------------------------
  5508. ; If idle switch if off,
  5509. ; subtract (iscStepTarg - iscStepCurr) from iscStStall
  5510. ;
  5511. ; Basically reduce iscStStall if the current isc step is
  5512. ; lower than the target. Reduce it by the same amount...
  5513. ;--------------------------------------------------------
  5514. L1362 ldaa port3Snap1 ; a = port3Snap1
  5515. bpl L1365 ; Bail if idle switch is on
  5516. eora oldP3Snap1 ;
  5517. bpl L1365 ; Bail if it changed in that split second?????? (Am I missing something??? maybe they changed their mind...)
  5518.  
  5519. ldab iscStepTarg ; b = iscStepTarg
  5520. subb iscStepCurr ; b = iscStepTarg - iscStepCurr
  5521. bcc L1363 ; Branch if result positive
  5522. clrb ; Use min of 0
  5523. L1363 ldaa iscStStall ; a = iscStStall
  5524. sba ; a = iscStStall - (iscStepTarg - iscStepCurr)
  5525. bcc L1364 ; Branch if no underflow
  5526. clra ; Use min of 0
  5527. L1364 staa iscStStall ; iscStStall = iscStStall - (iscStepTarg - iscStepCurr)
  5528.  
  5529. ;----------------------------------
  5530. ; Update iscStBarOff
  5531. ;----------------------------------
  5532. L1365 ldaa baroCond ; a = baroCond
  5533. ldx #t_iscStBaro ;
  5534. jsr interp32 ; b = t_iscStBaro(baroCond)
  5535. stab iscStBarOff ; iscStBarOff = t_iscStBaro(baroCond)
  5536.  
  5537. ;--------------------------------------------
  5538. ; Reset T0p5_crCold to 0 if notRotating
  5539. ; or if T0p5_crCold >= $3c (not possible???)
  5540. ;--------------------------------------------
  5541. brset state1, #$10, L1367 ; Branch to reset T0p5_crCold if notRotating
  5542. ldaa #$3c ;
  5543. cmpa T0p5_crCold ;
  5544. bcc L1368 ; Branch if T0p5_crCold <= $3c
  5545. L1367 clr T0p5_crCold ; reset T0p5_crCold to 0
  5546.  
  5547. ;---------------------------------------
  5548. ; Update T0p5_crCold to $00 or $3c
  5549. ; and iscFlags1.1 flag when startingToCrank
  5550. ;---------------------------------------
  5551. L1368 brclr state1, #$01, L1370 ; Bail if startingToCrank clear
  5552. clrb ; preload b=0
  5553. ldaa ectFiltered ;
  5554. cmpa #$1b ; 88degC
  5555. bcc L1369 ; Branch if temperature(ectFiltered) <= 88degC
  5556. ldab #$3c ; b= $3c
  5557. L1369 stab T0p5_crCold ; T0p5_crCold = 0 or $3c
  5558. andm iscFlags1, #$df ; Assume we reset bit
  5559. ldaa iatChecked ;
  5560. cmpa #$29 ; 75degC
  5561. bcs L1370 ; Branch if temperature(iat) > 75degC
  5562. orm iscFlags1, #$20 ; Set flag
  5563.  
  5564. ;-------------------------------------------------------------
  5565. ; Update iscStBaseCSt if T0p5_crCold not expired, else use iscStBaseCSt = 0
  5566. ;
  5567. ; iscStBaseCSt = (0 or $1e or $0f) * T0p5_crCold / $3c + t_iscStEct0
  5568. ;
  5569. ; iscStBaseCSt is basically the iscStep when a cold engine
  5570. ; is being started, starts with a high value and then is
  5571. ; decreased (through T0p5_crCold) towards normal isc step
  5572. ; over a period of 120sec
  5573. ;-------------------------------------------------------------
  5574. L1370 clrb ; preload b = 0
  5575. ldaa T0p5_crCold ;
  5576. beq L1372 ; Bail to store 0 if T0p5_crCold expired
  5577. ldaa #$3c ;
  5578. staa temp1 ; temp1 = $3c
  5579. #ifdef E931
  5580. ldaa #$1e ; assume low iat, high value...a = $1e
  5581. #else
  5582. ldaa #$19 ;
  5583. #endif
  5584. brclr iscFlags1, #$20, L1371 ; Branch if not (startingToCrank and temperature(iat) < 75degC)
  5585. ldaa #$0f ; high iat, use lower value... a = $0f
  5586. L1371 ldab T0p5_crCold ; b = T0p5_crCold
  5587. mul ; d = $1e * T0p5_crCold
  5588. div temp1 ; d = $1e * T0p5_crCold / $3c
  5589. addb t_iscStEct0 ; b = $1e * T0p5_crCold / $3c + t_iscStEct0
  5590. L1372 stab iscStBaseCSt ; iscStBaseCSt = 0 or $1e * T0p5_crCold / $3c + t_iscStEct0
  5591.  
  5592. ;--------------------------------------------------
  5593. ; Check if iscStepCurr and iscStepCom are in synch?
  5594. ;--------------------------------------------------
  5595. sei ; We don't want ISC values to change during check
  5596. ldaa iscStepCurr ;
  5597. coma ;
  5598. anda #$7f ;
  5599. cmpa iscStepCom ;
  5600. cli ;
  5601. bne L1373 ; Branch if iscStepCurr and iscStepCom are not in synch
  5602.  
  5603. ;-------------------------------------------
  5604. ; iscStepCurr and iscStepCom are in synch
  5605. ; Check ISC variables against min/max
  5606. ;-------------------------------------------
  5607. ldx #$b000 ; x = $b000
  5608. cpx isc0 ;
  5609. bcs L1373 ; Branch to re-init if isc0 > $b000
  5610. cpx isc1 ;
  5611. bcs L1373 ; Branch to re-init if isc1 > $b000
  5612. ldx #$6c00 ; x = $6c00
  5613. cpx isc0 ;
  5614. bhi L1373 ; Branch to re-init if isc0 < $6c00
  5615. cpx isc1 ;
  5616. bhi L1373 ; Branch to re-init if isc1 < $6c00
  5617. brset iscFlags0, #$20, L1374 ; Branch if the ISC needs min calibration
  5618. bra L1379 ; Branch to continue processing normal flow???
  5619.  
  5620. ;-----------------------------------------------
  5621. ; iscStepCurr and iscStepCom are not in synch
  5622. ; re-initialize ISC variables
  5623. ; set isc flag indicating we need min calibration
  5624. ; reset all other isc flags
  5625. ;-----------------------------------------------
  5626. L1373 ldd #$8c00 ;
  5627. std isc0 ;
  5628. std isc1 ;
  5629. jsr iscYnInit ;
  5630. ldaa #$20 ; Set flag indicating we need to calibrate ISC, reset all other flags
  5631. staa iscFlags0 ;
  5632.  
  5633. ;------------------------------------------------------------------------
  5634. ; Section for ISC min calibration, code is triggered by iscFlags0.5 being set
  5635. ;
  5636. ; Min calibration proceed as follows.
  5637. ;
  5638. ; 1) iscFlags0.5 is set to indicate calibration is required,
  5639. ; iscStepCurr init to 135, iscStepTarg init to 0
  5640. ; 2) iscFlags0.0 is set to indicate calibration is started,
  5641. ; waiting for iscStepCurr to reach iscStepTarg of 0
  5642. ; 3) iscFlags0.1 is set to indicate calibration is finished,
  5643. ; iscStepCurr reached 0, we are therefore now certain that
  5644. ; the isc pintle is physically at position 0.iscStepTarg
  5645. ; is now init to 6, waiting for iscStepCurr to reach iscStepTarg
  5646. ; 4) iscStepCurr reached iscStepTarg = 6, iscFlags0.0.1.5
  5647. ; are all reset
  5648. ;
  5649. ;------------------------------------------------------------------------
  5650. L1374 brset iscFlags0, #$02, L1376 ; Branch if calibration is finished, we are waiting for ISC to go back to iscStepCurr=6
  5651. brset iscFlags0, #$01, L1375 ; Branch if calibration is started, we are waiting for ISC to reach iscStepCurr=0
  5652. ldaa #$87 ; calibration not started, use iscStepCurr = a = $87 (135, above max, maybe during calibration?)
  5653. sei ;
  5654. jsr iscStepComp ; iscStepCurr = $87, iscStepCom = (~$87 & 7F)
  5655. cli ;
  5656. orm iscFlags0, #$01 ; Set flag indicating we just calculated iscStepCom?
  5657. L1375 clrb ; use iscStepTarg = b = 0
  5658. ldaa iscStepCurr ; a = iscStepCurr
  5659. bne L1377 ; Branch if iscStepCurr != 0
  5660. orm iscFlags0, #$02 ; iscStepCurr=0, set flag
  5661. L1376 ldab #$06 ; b = $06
  5662. cmpb iscStepCurr ;
  5663. beq L1378 ; Branch if iscStepCurr=$06
  5664. L1377 stab iscStepTarg ; iscStepTarg = $00 or $06
  5665. jmp L1389 ; Bail
  5666. L1378 clra ; a = 0
  5667. sei ;
  5668. jsr iscStepComp ; iscStepCurr = $0, iscStepCom = (~$0 & 7F)
  5669. cli ;
  5670. andm iscFlags0, #$dc ; Calibration is over, reset all flags 0010 0011
  5671.  
  5672. ;--------------------------------------------------------
  5673. ; Normal flow continues,
  5674. ; Check if max calibration need to be performed
  5675. ;--------------------------------------------------------
  5676. L1379 brset iscFlags0, #$80, L1380 ; Branch if max calibration is required?
  5677. tst T40_noPower ;
  5678. bne L1382 ; Branch to normal flow if we are not about to loose power
  5679. brset iscFlags0, #$40, L1382 ; Branch to normal flow if max calibration already performed
  5680.  
  5681. ;-------------------------------------------------------------
  5682. ; At this point max calibration flag is set or we are about
  5683. ; to loose power and max calibration was not performed
  5684. ;
  5685. ; Set iscStepTarg to 135 if iscStepCurr not already at 135
  5686. ;-------------------------------------------------------------
  5687. L1380 orm iscFlags0, #$80 ; Set max calibration flag is case it was not set
  5688. ldaa #$87 ; a = 135
  5689. cmpa iscStepCurr ;
  5690. beq L1381 ; Branch if iscStepCurr already at 135
  5691. staa iscStepTarg ; Set target to iscStepTarg = 135
  5692. jmp L1389 ;
  5693.  
  5694. ;-------------------------------------------------------------
  5695. ; At this point iscStepCurr is 135, we are therefore sure the
  5696. ; isc pintle is physically at its maximum value of 120,
  5697. ; set iscStepCurr=120 and set/reset flags
  5698. ;-------------------------------------------------------------
  5699. L1381 ldaa #$78 ; a = $78 (120, max usable value)
  5700. sei ;
  5701. jsr iscStepComp ; iscStepCurr = $78, iscStepCom = (~$78 & 7F)
  5702. cli ;
  5703. orm iscFlags0, #$40 ; set flag 0100 0000, calibration done?
  5704. andm iscFlags0, #$7f ; reset flag indicating we need max calibration 1000 0000
  5705.  
  5706. ;-----------------------------------------------------
  5707. ; if the ECU is about to loose power then
  5708. ;
  5709. ; set/reset flags
  5710. ; use a fixed ISC step of $5a
  5711. ; don't re-init updIscStableTimer since we loose power...
  5712. ;-----------------------------------------------------
  5713. L1382 andm iscFlags0, #$ef ; Assume we reset 0001 0000, updated below
  5714. ldaa T40_noPower ;
  5715. bne L1383 ; Branch if timer not expired
  5716. andm iscFlags0, #$40 ; reset max calibration flag? 0100 0000
  5717. orm iscFlags0, #$10 ; Set 0001 0000
  5718. ldab #$5a ; b = $5a
  5719. bra L1388 ; Branch to use fix ISC step of $5a, i.e. 3/4 of full range
  5720.  
  5721. ;----------------------------------------------------
  5722. ; If the engine is running but we are not receiving
  5723. ; airflow sensor interrupts then
  5724. ;
  5725. ; set/reset flags
  5726. ; re-init iscYn variables
  5727. ; re-init updIscStableTimer
  5728. ; use a fixed ISC step of $3a
  5729. ;----------------------------------------------------
  5730. L1383 andm iscFlags0, #$f7 ; Assume we reset 00001000, updated below
  5731. brclr state1, #$02, L1384 ; Bail if pulse accumulator interrupts are being received
  5732. brset state1, #$11, L1384 ; Bail if notRotating or startingToCrank
  5733. jsr iscYnInit ; Init variables
  5734. andm iscFlags0, #$40 ; reset max calibration flag? 0100 0000
  5735. orm iscFlags0, #$08 ; set 0000 1000
  5736. ldab #$50 ;
  5737. jsr updIscStableTimer ; re-init updIscStableTimer
  5738. ldab #$3a ; b = $3a
  5739. bra L1388 ; Branch to use fix ISC step of $3a
  5740.  
  5741. ;---------------------------------------------------
  5742. ; Section to check for idle speed adjustment mode,
  5743. ; i.e. both ECU test mode terminal grounded and
  5744. ; timing adjustment terminal grounded
  5745. ;---------------------------------------------------
  5746. L1384 andm iscFlags0, #$fb ; Reset 00000010
  5747. ldaa port4Snap ; a = port4Snap
  5748. anda #$18 ; Keep only ECU test mode terminal grounded & timing adjustment terminal grounded
  5749. cmpa #$18 ; ECU test mode terminal grounded & timing adjustment terminal grounded
  5750. bne L1385 ; Bail if not both of them grounded
  5751. brset port3Snap1, #$04, L1385 ; Both terminal grounded, bail if car is moving
  5752. #ifdef E932
  5753. brclr port3Snap1, #$20, L1385 ; Bail if not in park/neutral???
  5754. #endif
  5755. brclr state1, #$11, L1386 ; branch if notRotating and startingToCrank clear
  5756.  
  5757. ;------------------------------------------------------------
  5758. ; Engine is either notRotating or startingToCrank
  5759. ; Reset timer (always done when both terminal not grounded)
  5760. ;------------------------------------------------------------
  5761. L1385 ldaa #$08 ; 0.2s
  5762. staa T40_iSpAdj ;
  5763.  
  5764. ;--------------------------------------------------
  5765. ; If Timer T40_iSpAdj is expired (0.2 sec after
  5766. ; both terminals grounded) we are in basic idle
  5767. ; speed adjustment mode. Branch accordingly...
  5768. ;--------------------------------------------------
  5769. L1386 ldaa T40_iSpAdj ;
  5770. bne L1390 ; Branch to next section if timer not expired
  5771.  
  5772. ;----------------------------------------------------
  5773. ; Timer is expired, we are in basic idle
  5774. ; speed adjustment mode...
  5775. ;
  5776. ; Just compute iscStepTarg (target idle speed) as a
  5777. ; function of temperature and barometric pressure,
  5778. ; reset iscLrnFlags and iscStStall and exit from subroutine
  5779. ;----------------------------------------------------
  5780. orm iscFlags0, #$04 ; Set flag
  5781. ldab #$50 ;
  5782. jsr updIscStableTimer ;
  5783. ldx #t_iscStEct0 ; x points to iscStepCurr(as a function of ECT) table
  5784. jsr interpEct ; b = t_iscStEct0(ect), basic isc value we want as a function of ECT
  5785. addb iscStBarOff ; b = t_iscStEct0(ect) + iscStBarOff, Add an offset to compensate for barometric pressure
  5786. bcc L1388 ; Branch if no overflow
  5787. ldab #$ff ; Use max
  5788. L1388 jsr iscStepMaxFunc ; Apply maximum to calculated value
  5789. stab iscStepTarg ; iscStepTarg = t_iscStEct0(ect) + iscStBarOff
  5790. L1389 clra ;
  5791. staa iscLrnFlags ; iscLrnFlags = 0
  5792. staa iscStStall ; iscStStall = 0
  5793. jmp L1431 ; Bail of subroutine
  5794.  
  5795. ;------------------------------------------------
  5796. ; Basic idle speed adjustment mode is not active
  5797. ; Section to update ISC stuff, long...
  5798. ;------------------------------------------------
  5799. L1390 brset state1, #$11, L1391 ; Branch if notRotating or startingToCrank
  5800.  
  5801. ;--------------------------------------
  5802. ; Engine is running, set /reset flags
  5803. ;--------------------------------------
  5804. andm iscLrnFlags, #$fe ; Reset bit 0
  5805. orm iscFlags1, #$01 ; Set flag indicating "normal running mode"??
  5806. bra L1392 ; Branch to continue
  5807.  
  5808. ;----------------------------------
  5809. ; notRotating or startingToCrank
  5810. ;----------------------------------
  5811. L1391 ldab #$01 ;
  5812. stab iscLrnFlags ; Reset all bit to 0 and set bit 0 to 1
  5813.  
  5814. ;---------------------------------------------------------------
  5815. ; Reset iscFlags1.0 if key in start and iscStTargSpec = iscStepCurr??
  5816. ;---------------------------------------------------------------
  5817. brset port3Snap1, #$40, L1392 ; Branch if key is not is start
  5818. ldaa iscStTargSpec ;
  5819. cmpa iscStepCurr ;
  5820. bne L1392 ; Branch if iscStTargSpec != iscStepCurr
  5821. andm iscFlags1, #$fe ;
  5822.  
  5823. ;------------------------------------------------------------------
  5824. ; Init T40_acOnTrans to 0.1sec if A/C switch was just turned on?
  5825. ;------------------------------------------------------------------
  5826. L1392 ldaa port3Snap1 ;
  5827. eora oldP3Snap1 ;
  5828. bita #$10 ;
  5829. beq L1393 ; Branch if A/C switch did not change state
  5830. brclr port3Snap1, #$10, L1394 ; Branch if A/C switch is on
  5831. L1393 .equ $
  5832. #ifdef E931
  5833. bra L1395 ;
  5834. #else
  5835. bita #$20 ;
  5836. beq L1395 ;
  5837. brset port3Snap1, #$20, L1395 ;
  5838. #endif
  5839. L1394 ldab #$04 ; 0.1sec
  5840. stab T40_acOnTrans ; T40_acOnTrans = 0.1sec
  5841.  
  5842. ;--------------------------------------------------------------
  5843. ; Update iscLrnFlags.2, flag indicating engine is running too slow?
  5844. ;--------------------------------------------------------------
  5845. L1395 ldaa iscLrnFlags ; a = old iscLrnFlags
  5846. andm iscLrnFlags, #$fb ; Assume we reset 00000100, updated below
  5847. ldab ectFiltered ;
  5848. cmpb #$3c ; 55degC
  5849. bcc L1396 ; Bail if temperature(ectFiltered) <= 55degC
  5850. ldab rpm8 ;
  5851. cmpb #$40 ;
  5852. bcc L1396 ; Bail if rpm8 >=500
  5853. brset iscLrnFlags, #$01, L1396 ; Bail if engine is notRotating or startingToCrank (and basic idle speed adjustment mode is off)
  5854. tst T40_acOnTrans ;
  5855. bne L1396 ; Bail if timer not expired
  5856.  
  5857. ;----------------------------------------------------------------------------------
  5858. ; At this point
  5859. ; temperature(ectFiltered) > 55degC
  5860. ; rpm8 < 500rpm
  5861. ; engine is running
  5862. ; T40_acOnTrans is expired (A/C switch was turned on more than 0.1sec ago, or never...)
  5863. ;
  5864. ; Set iscLrnFlags.2 indicating the engine is running to slow
  5865. ; (even though A/C transcient was ignored for 0.1sec)
  5866. ;
  5867. ; Clear T40_checkTargRpm if this condition was just detected in order to perform
  5868. ; current versus target rpm comparison right away and adjust isc step before
  5869. ; the engine stalls...
  5870. ;----------------------------------------------------------------------------------
  5871. orm iscLrnFlags, #$04 ; set 0000 0100
  5872. anda #$04 ; a = old iscLrnFlags & 0000 0100
  5873. bne L1396 ; Bail if old iscLrnFlags.2 was set
  5874. clr T40_checkTargRpm ; old iscLrnFlags.2 was not set, reset timer to trigger fast rpm update...
  5875.  
  5876. ;---------------------------------
  5877. ; Update updIscStableTimer if ???
  5878. ;---------------------------------
  5879. L1396 brclr iscLrnFlags, #$20, Ne301 ; Branch if
  5880. ldab #$50 ;
  5881. jsr updIscStableTimer ;
  5882. Ne301 .equ $
  5883.  
  5884. ;--------------------------------------------
  5885. ; Update updIscStableTimer if ??? for E931
  5886. ;--------------------------------------------
  5887. #ifdef E931
  5888. brclr ftrimFlags, #$08, L1397 ; Branch if not (speed>24km/h and port3.0 is set???)
  5889. ldab #$50 ; speed>24km/h and port3.0 is set, update timer
  5890. jsr updIscStableTimer ;
  5891. #endif
  5892.  
  5893. ;-------------------------------------------------------------------
  5894. ; Section to update iscLrnFlags.4, flag indicating that conditions are
  5895. ; good to update the isc learning variables???
  5896. ;-------------------------------------------------------------------
  5897. L1397 andm iscLrnFlags, #$ef ; Assume we reset iscLrnFlags.4 (0001 0000)
  5898. ldaa port3Snap1 ;
  5899. bpl L1398 ; Branch if idle position switch is off
  5900. brset port3Snap1, #$04, L1398 ; Branch if car is moving
  5901. ldaa T40s_iscStable ;
  5902. bne L1398 ; Branch if isc not stable yet
  5903. ldaa rpm8 ;
  5904. cmpa #$2a ;
  5905. bcc L1399 ; Branch if rpm8 >= 328rpm
  5906. L1398 brclr state1, #$01, L1400 ; Branch if startingToCrank clear
  5907. brset iscFlags1, #$01, L1400 ; Branch if not (key in start and iscStTargSpec = iscStepCurr)
  5908.  
  5909. ;--------------------------------------------
  5910. ; At this point
  5911. ; car is not moving
  5912. ; and idle switch is on
  5913. ; and isc is stable
  5914. ; and rpm8 >= 328
  5915. ;
  5916. ; or these conditions are not met but
  5917. ; engine is startingToCrank
  5918. ; and (key in start and iscStTargSpec = iscStepCurr)
  5919. ;
  5920. ; Set iscLrnFlags.4 indicating we can update the isc
  5921. ; learning variables?
  5922. ;--------------------------------------------
  5923. L1399 orm iscLrnFlags, #$10 ;
  5924. bra L1401 ;
  5925.  
  5926. ;-----------------------------------------------------
  5927. ; At this point,
  5928. ; car is moving
  5929. ; or idle position switch is off
  5930. ; or isc not yet stable
  5931. ; or rpm < 328
  5932. ;
  5933. ; and engine is startingToCrank or key is not
  5934. ; in start or iscStTargSpec != iscStepCurr
  5935. ;
  5936. ; Re-init T40_iscLrn to 5sec
  5937. ; Conditions are not good to update ISC learning variables?
  5938. ; Flag is already reset so just reset that timer so that
  5939. ; we have a 5sec delay when we can go back to being able
  5940. ; to update them...
  5941. ;--------------------------------------------------------------
  5942. L1400 ldab #$c8 ; 5sec
  5943. stab T40_iscLrn ; T40_iscLrn = 5sec
  5944.  
  5945. ;---------------------------------------------------------------------------------------------------
  5946. ; Check whether abs(idleSpdTarg - rpm8) > (5/256 * idleSpdTarg)
  5947. ;
  5948. ; Basically chech if target and current rpm are more than 2% apart
  5949. ;---------------------------------------------------------------------------------------------------
  5950. L1401 brclr iscLrnFlags, #$10, L1403 ; Bail if conditions are not good to update isc variables
  5951. ldaa T40_checkTargRpm ;
  5952. bne L1403 ; Bail if timer not expired
  5953. ldaa idleSpdTarg ; a = idleSpdTarg
  5954. suba rpm8 ; a = idleSpdTarg - rpm8
  5955. ror temp2 ; shift sign (carry) of result in temp2.7
  5956. bpl L1402 ; Branch if (idleSpdTarg - rpm8) >= 0
  5957. nega ; a = abs(idleSpdTarg - rpm8)
  5958. L1402 psha ; st0 = abs(idleSpdTarg - rpm8)
  5959. ldaa idleSpdTarg ; a = idleSpdTarg
  5960. ldab #$0a ; b = $0a
  5961. mul ; d = $0a * idleSpdTarg
  5962. pulb ; b = abs(idleSpdTarg - rpm8); a = $0a/256 * idleSpdTarg
  5963. cba ;
  5964. bcs L1404 ; Branch if ($0a/256 * idleSpdTarg) < abs(idleSpdTarg - rpm8), basically branch if difference between current rpm and desired one is too high
  5965. L1403 jmp L1416 ; Jump to next section
  5966.  
  5967. ;------------------------------------------------------------------
  5968. ; At this point abs(idleSpdTarg - rpm8) > (5/256 * idleSpdTarg)
  5969. ; or equivalently abs(idleSpdTarg - rpm8)/idleSpdTarg > 2%
  5970. ; i.e. Target and current rpm are more than 2% apart
  5971. ;
  5972. ; Section to update iscYn (until L1415).
  5973. ;
  5974. ; Basically this section increases the current iscYn (iscY1, iscY2
  5975. ; or iscY3) if the current rpm is lower than the target and vice-versa
  5976. ; iscYn is centered at $80 (100%, no correction). The isc step used
  5977. ; is increase/decreased by iscYn-$80 later in the code
  5978. ;------------------------------------------------------------------
  5979. L1404 aslb ; b = 2 * abs(idleSpdTarg - rpm8)
  5980. bcs L1405 ; branch to use max of $ff if overflow
  5981. aslb ; b = 4 * abs(idleSpdTarg - rpm8)
  5982. bcc L1406 ; Branch if no overflow
  5983. L1405 ldab #$ff ; use max of $ff
  5984. L1406 stab temp1 ; temp1 = 4 * abs(idleSpdTarg - rpm8)
  5985. ldx #L2035 ; x point to L2035
  5986. ldaa temp1 ; a = 4 * abs(idleSpdTarg - rpm8)
  5987. jsr interp32 ; b = L2035(4 * abs(idleSpdTarg - rpm8))
  5988. stab temp1 ; temp1 = L2035(4 * abs(idleSpdTarg - rpm8))
  5989. jsr iscPointers ; have x point to isc0 or isc1 and have y point to iscY0, iscY1 or iscY2
  5990. ldab $00,y ; b = iscYn, y = y + 1
  5991. decy ; y = y-1, points back to same value
  5992. ldaa temp2 ; a.7 = sign(carry) of idleSpdTarg - rpm8 (see above L1402)
  5993. bpl L1410 ; Branch if idleSpdTarg - rpm8 was positive
  5994.  
  5995. ;---------------------------------------------------------------------------
  5996. ; idleSpdTarg - rpm8 was negative. i.e. current rpm is too high
  5997. ; Compute b = iscYn - min (iscStepTarg, L2035(4 * abs(idleSpdTarg - rpm8)))
  5998. ;---------------------------------------------------------------------------
  5999. ldaa iscStepTarg ; a = iscStepTarg
  6000. beq L1416 ; Branch if iscStepTarg = 0
  6001. cmpa temp1 ;
  6002. bhi L1408 ; Branch if iscStepTarg > L2035(4 * abs(idleSpdTarg - rpm8))
  6003. staa temp1 ; Use max of = iscStepTarg
  6004. L1408 subb temp1 ; b = iscYn - min (iscStepTarg, L2035(4 * abs(idleSpdTarg - rpm8)))
  6005. bcc L1409 ; Branch if no underflow
  6006. clrb ; Use min of 0
  6007. L1409 bra L1412 ;
  6008.  
  6009. ;-------------------------------------------------------------------------------------
  6010. ; idleSpdTarg - rpm8 was positive, i.e. current rpm is too low
  6011. ; Compute b = iscYn + min(iscStepMax - iscStepTarg, L2035(4 * abs(idleSpdTarg - rpm8))
  6012. ;-------------------------------------------------------------------------------------
  6013. L1410 ldaa iscStepMax ; a = iscStepMax
  6014. suba iscStepTarg ; a = iscStepMax - iscStepTarg
  6015. beq L1416 ; Branch if iscStepTarg = iscStepMax
  6016. cmpa temp1 ;
  6017. bhi L1411 ; Branch if iscStepMax - iscStepTarg > L2035(4 * abs(idleSpdTarg - rpm8))
  6018. staa temp1 ; Use max of iscStepMax - iscStepTarg
  6019. L1411 addb temp1 ; b = iscYn + min(iscStepMax - iscStepTarg, L2035(4 * abs(idleSpdTarg - rpm8))
  6020. bcc L1412 ; Branch if no overflow
  6021. ldab #$ff ; Use max of $ff
  6022.  
  6023. ;-------------------------------------------------------------------------------------
  6024. ; at this point
  6025. ; b = iscYn - min(iscStepTarg, L2035(4 * abs(idleSpdTarg - rpm8)))
  6026. ; or
  6027. ; b = iscYn + min(iscStepMax - iscStepTarg, L2035(4 * abs(idleSpdTarg - rpm8))
  6028. ;
  6029. ; Restart T40_checkTargRpm to 1 sec and decide whether to apply min/max to new iscYn=b value
  6030. ;-------------------------------------------------------------------------------------
  6031. L1412 ldaa #$28 ; 1sec
  6032. staa T40_checkTargRpm ; T40_checkTargRpm = 1sec
  6033. brset iscLrnFlags, #$01, L1413 ; Branch to min/max checking if engine is notRotating or startingToCrank
  6034. bra L1415 ; Branch to store b in iscYn, Skip min/max checking
  6035. nop ;
  6036.  
  6037. ;-------------------------------------------------
  6038. ; Check b for min and max and then store in iscYn
  6039. ;-------------------------------------------------
  6040. L1413 cmpb #$86 ;
  6041. bcs L1414 ; Branch if b < $86
  6042. ldab #$86 ; Use max of $86
  6043. L1414 cmpb #$7b ;
  6044. bcc L1415 ; Branch if b >= $7b
  6045. ldab #$7b ; Use min of $7b
  6046. L1415 stab $00,y ; iscYn = b....
  6047.  
  6048.  
  6049. ;---------------------------------------------------------------
  6050. ; re-init iscYn variables if car is moving and rpm8>=1000rpm
  6051. ;---------------------------------------------------------------
  6052. L1416 brclr port3Snap1, #$04, L1417 ; Branch if car is not moving
  6053. ldaa rpm8 ;
  6054. cmpa #$80 ;
  6055. bcs L1417 ; Branch if rpm8 < 1000rpm
  6056. jsr iscYnInit ;
  6057.  
  6058. ;--------------------------------------------------------
  6059. ; Transfer iscY0 to iscY2 if power steering pump is off???
  6060. ;--------------------------------------------------------
  6061. L1417 brset port3Snap1, #$08, L1418 ; Bail if power steering pump is activated
  6062. ldaa iscY0 ;
  6063. staa iscY2 ; iscY2 = iscY0
  6064.  
  6065. ;---------------------------------------------------------
  6066. ; Section to compute iscStepTarg from various information
  6067. ; Ends at L1428
  6068. ;---------------------------------------------------------
  6069. ;-------------------------------------------------------------------------
  6070. ; Compute workIscStep = b = max(iscStBase, iscStBaseAc, iscStBaseCSt)
  6071. ;-------------------------------------------------------------------------
  6072. L1418 ldab iscStBase ; b = iscStBase
  6073. cmpb iscStBaseAc ;
  6074. bcc L1419 ; Branch if iscStBase >= iscStBaseAc
  6075. ldab iscStBaseAc ; Use min of iscStBaseAc
  6076. L1419 cmpb iscStBaseCSt ;
  6077. bcc Ne3cd ; Branch if max(iscStBase, iscStBaseAc) >= iscStBaseCSt
  6078. ldab iscStBaseCSt ; Use min of iscStBaseCSt
  6079. Ne3cd .equ $
  6080.  
  6081. ;-----------------------------------------------------------------
  6082. ; At this point b = workIscStep
  6083. ;
  6084. ; Take into port3.0 signal for E931?????
  6085. ; Basically continue calculating the max isc step to use,
  6086. ; this time check A/C and port3.0
  6087. ;-----------------------------------------------------------------
  6088. #ifdef E931
  6089. brclr ftrimFlags, #$08, L1420 ; Bail if not (speed>24km/h and port3.0 set)
  6090. ldaa #$53 ; Use $53
  6091. brset port3Snap1, #$10, Me3db ; Branch if A/C switch is off
  6092. ldaa #$78 ; Use higher value since A/C is on
  6093. Me3db cba ;
  6094. bcs L1420 ; Branch if we already have max value, i.e. workIscStep > a
  6095. tab ; Use new max value
  6096. #endif
  6097.  
  6098. ;---------------------------------------------
  6099. ; At this point b = workIscStep
  6100. ; Compensate for barometric pressure and
  6101. ;---------------------------------------------
  6102. L1420 clra ; a = 0
  6103. addb iscStBarOff ; d = workIscStep + iscStBarOff
  6104. adca #$00 ; propagate carry
  6105.  
  6106. ;------------------------------------------------
  6107. ; At this point b = workIscStep
  6108. ; Increase iscStep according to iscStStartUsed
  6109. ;
  6110. ; i.e. isc step adjustment upon engine startup
  6111. ;------------------------------------------------
  6112. addb iscStStartUsed ; d = workIscStep + iscStBarOff + iscStStartUsed
  6113. adca #$00 ; propagate carry
  6114. jsr ovfCheck ; Check for overflow (force result to be in b with $ff max)
  6115.  
  6116. ;------------------------------------------------
  6117. ; Check workIscStep for min value in iscStStall
  6118. ;------------------------------------------------
  6119. cmpb iscStStall ;
  6120. bcc L1421 ; Branch if workIscStep + iscStBarOff + iscStStartUsed >= iscStStall
  6121. ldab iscStStall ; Use min of iscStStall
  6122. bra L1422 ; Branch to continue
  6123.  
  6124. ;-------------------------------------------------------------------
  6125. ; At this point workIscStept + iscStBarOff + iscStStartUsed >= iscStStall
  6126. ;
  6127. ; i.e. what we are using is already higher
  6128. ; than the minimum we therefore don't need
  6129. ; that minimum anymore...
  6130. ;
  6131. ; Reset iscStStall to 0 and reset flag
  6132. ;-------------------------------------------------------------------
  6133. L1421 clr iscStStall ; iscStStall = 0
  6134. andm iscLrnFlags, #$df ; Reset 00100000
  6135.  
  6136. ;---------------------------------------------------------------------------------
  6137. ; At this point, b = workIscStep
  6138. ; Add the effect of power steering pump
  6139. ;---------------------------------------------------------------------------------
  6140. L1422 brclr port3Snap1, #$08, L1423 ; Branch if power steering pump is off
  6141. #ifdef E931
  6142. addb #$0f ; b = workIscStep + $0f
  6143. #else
  6144. addb #$11 ;
  6145. #endif
  6146. bcc L1423 ; Branch if no overflow
  6147. ldab #$ff ; Use max of $ff
  6148.  
  6149. ;---------------------------------------------------------------
  6150. ; increase the iscStep if the engine is running too slow
  6151. ; (stall conditions?) and conditions are not good to update
  6152. ; isc variables (to avoid getting confused with cranking maybe?)
  6153. ;---------------------------------------------------------------
  6154. L1423 brclr iscLrnFlags, #$04, L1424 ; Branch if engine is not running too slow
  6155. brset iscLrnFlags, #$10, L1424 ; Branch if conditions are good to update isc variables
  6156. addb #$22 ; b = workIscStep + $22
  6157. bcc L1424 ; Branch if no overflow
  6158. ldab #$ff ; Use max of $ff
  6159.  
  6160. ;-------------------------------------------------------------------
  6161. ; Compute temp3 = workIscStep + (iscm/256 - $80) + (iscYn - $80)
  6162. ; workIscStep'+ iscStBarOff + (iscm/256 - $80) + (iscYn - $80)
  6163. ; This is isc step we are going to use if engine is running
  6164. ;-------------------------------------------------------------------
  6165. L1424 jsr iscCalc3 ; b = workIscStep + (iscm/256 - $80)
  6166. jsr iscCalc4 ; b = workIscStep + (iscm/256 - $80) + (iscYn - $80)
  6167. stab temp3 ; temp3 = workIscStep + (iscm/256 - $80) + (iscYn - $80)
  6168.  
  6169. ;---------------------------------------------------------------
  6170. ; Compute temp2 = L2031(ect) + iscStBarOff + (iscm/256 - $80)
  6171. ; This is isc step we are going to use if the engine is notRotating
  6172. ;---------------------------------------------------------------
  6173. ldx #L2031 ; x points to L2031
  6174. jsr interpEct ; b = L2031(ect)
  6175. addb iscStBarOff ; b = L2031(ect) + iscStBarOff
  6176. bcc L1425 ; Branch if no overflow
  6177. ldab #$ff ; overflow, use max
  6178. L1425 jsr iscCalc3 ; b = L2031(ect) + iscStBarOff + (iscm/256 - $80)
  6179. stab temp2 ; temp2 = L2031(ect) + iscStBarOff + (iscm/256 - $80)
  6180.  
  6181. ;-----------------------------------------------------------------------------
  6182. ; Compute iscStTargSpec = temp2 + (iscYn - $80)
  6183. ; = L2031(ect) + iscStBarOff + (iscm/256 - $80) + (iscYn - $80)
  6184. ;
  6185. ; This is isc step we are going to use if engine is starting to crank
  6186. ;-----------------------------------------------------------------------------
  6187. jsr iscCalc4 ; b = L2031(ect) + iscStBarOff + (iscm/256 - $80) + (iscYn - $80)
  6188. jsr iscStepMaxFunc ; apply max to b
  6189. stab iscStTargSpec ; iscStTargSpec = L2031(ect) + iscStBarOff + (iscm/256 - $80) + (iscYn - $80)
  6190.  
  6191. ;-----------------------------------------------------------------------
  6192. ; At this point,
  6193. ;
  6194. ; temp3 = workIscStep' + iscStBarOff + (iscm/256 - $80) + (iscYn - $80)
  6195. ; b = L2031(ect) + iscStBarOff + (iscm/256 - $80) + (iscYn - $80)
  6196. ; temp2 = L2031(ect) + iscStBarOff + (iscm/256 - $80)
  6197. ;
  6198. ; Now decide which value we are going to use
  6199. ; as working isc step either b, temp2 or temp3
  6200. ; Not sure why engine state is taken from a mix of state1 and iscLrnFlags???
  6201. ;-----------------------------------------------------------------------
  6202. brclr iscLrnFlags, #$01, L1427 ; Branch to use temp3 if engine is not (notRotating or startingToCrank), runnning, normally or not...
  6203. brclr state1, #$10, L1428 ; Branch to use iscStTargSpec (already loaded in b) if notRotating clear, only startingToCrank left???
  6204. ldab temp2 ; notRotating, use temp2
  6205. bra L1428 ;
  6206. L1427 ldab temp3 ; use temp3
  6207.  
  6208. ;-------------------------------------------------------------------------
  6209. ; At this point b contains the working isc step that we have been
  6210. ; updating/calculating for a while now, apply a max to it and store it
  6211. ; in iscStepTarg, this is the is isc step target...
  6212. ;-------------------------------------------------------------------------
  6213. L1428 jsr iscStepMaxFunc ; apply max to b
  6214. stab iscStepTarg ; iscStepTarg
  6215.  
  6216. ;--------------------------------------------
  6217. ; Section to update iscYn and iscm variables
  6218. ;--------------------------------------------
  6219. ;------------------------------------------------------------------------------
  6220. ; Check if a bunch of conditions are met to update the isc learning variables
  6221. ;------------------------------------------------------------------------------
  6222. brclr iscLrnFlags, #$10, L1431 ; Bail if conditions are not good to update isc variables
  6223. ldab iscStepMax ; b = iscStepMax
  6224. ldaa iscStepTarg ; a = iscStepTarg
  6225. beq L1431 ; bail if iscStepTarg = 0
  6226. cba ;
  6227. beq L1431 ; bail if iscStepTarg = iscStepMax
  6228. brset port3Snap1, #$08, L1431 ; bail if power steering pump is on
  6229. brset iscLrnFlags, #$01, L1431 ; bail if notRotating or startingToCrank
  6230. ldaa T0p5_crCold ; a = T0p5_crCold
  6231. bne L1431 ; bail if timer not expired
  6232. ldaa ectFiltered ; a = ectFiltered
  6233. cmpa #$1c ; 86degC
  6234. bcc L1431 ; bail if temperature(ectFiltered) <= 86degC
  6235. brset port4Snap, #$10, L1431 ; Bail if timing terminal grounded
  6236. ldaa iscStStartUsed ; a = iscStStartUsed
  6237. bne L1431 ; Bail if iscStStartUsed != 0
  6238. brclr port5, #$10, L1431 ; Bail if fuel pressure solenoid activated
  6239.  
  6240. ;-----------------------------------------------------------
  6241. ; All the conditions are met, update iscm and iscYn at 1 Hz
  6242. ;-----------------------------------------------------------
  6243. ;------------------------------------------
  6244. ; First check if time has come to update
  6245. ; variables and then re-init timer
  6246. ;------------------------------------------
  6247. ldaa T40_iscLrn ; a = T40_iscLrn
  6248. bne L1431 ; Bail to exit subr. if timer T40_iscLrn not expired (time has not come yet...)
  6249. ldaa #$28 ; Timer is expired, a = 1sec
  6250. staa T40_iscLrn ; re-init T40_iscLrn to 1 sec
  6251.  
  6252. ;-----------------------------------------
  6253. ; Get current pointers and compute
  6254. ; newIscm = old iscm + 3 * (iscYn - $80)
  6255. ;-----------------------------------------
  6256. jsr iscPointers ; have x point to isc0 or isc1 and have y point to iscY0, iscY1 or iscY2
  6257. ldd #$0180 ; d = $0180
  6258. std temp2 ; temp2:temp3 = $0180
  6259. ldaa #$03 ; a = $03
  6260. ldab $00,y ; b = iscYn, y = y + 1
  6261. decy ; y = y - 1
  6262. mul ; d = 3 * iscYn
  6263. subd temp2 ; d = 3 * (iscYn - $80)
  6264. addd $00,x ; d = iscm + 3 * (iscYn - $80)
  6265. jsr iscMinMax ; Apply min and max to d
  6266. std temp1 ; temp1:temp2 = newIscm = iscm + 3 * (iscYn - $80)
  6267.  
  6268. ;---------------------------------------------------
  6269. ; Compute newIscYn = newIscm + 3 * (iscYn - $80)
  6270. ;---------------------------------------------------
  6271. tab ; b = newIscm/256
  6272. ldaa $00,y ; a = iscYn, y = y + 1
  6273. decy ; y = y - 1
  6274. subb $00,x ; b = newIscm/256 - iscm/256
  6275. bcc L1429 ; Branch to continue if newIscm >= old iscm
  6276.  
  6277. ;---------------------
  6278. ; newIscm < old iscm
  6279. ;---------------------
  6280. negb ; b = (iscm - newIscm)/256
  6281. aba ; a = iscYn + (iscm - newIscm)/256
  6282. bcc L1430 ; Branch if no overflow
  6283. ldaa #$ff ; Use max of $ff
  6284. bra L1430 ; Branch to store
  6285.  
  6286. ;----------------------
  6287. ; newIscm >= old iscm
  6288. ;----------------------
  6289. L1429 sba ; a = iscYn - (newIscm - iscm)/256
  6290. bcc L1430 ; branch if no underflow
  6291. clra ; Use min of 0
  6292.  
  6293. ;---------------------------------------------------------
  6294. ; At this point
  6295. ; a = newIscYn
  6296. ; [temp1:temp2] = newIscm
  6297. ;
  6298. ; Where
  6299. ;
  6300. ; newIscm = oldIscm + 3 * (oldIscYn - $80)
  6301. ;
  6302. ; | oldIscYn + (oldIscm - newIscm)/256 if newIscm < oldIscm
  6303. ; newIscYn = |
  6304. ; | oldIscYn - (newIscm - oldIscm)/256 if newIscm >= oldIscm
  6305. ;
  6306. ;---------------------------------------------------------
  6307. L1430 staa $00,y ; Update iscYn with new value
  6308. ldd temp1 ; d = newIscm
  6309. std $00,x ; Update iscm with new value
  6310. L1431 rts ;
  6311.  
  6312.  
  6313.  
  6314. ;******************************************************************
  6315. ;
  6316. ; ISC step calculation
  6317. ;
  6318. ; input: A = step
  6319. ; output: A =(~step & 7F)
  6320. ;
  6321. ; (~step & 7F) stored in iscStepCom
  6322. ; step stored in iscStepCurr
  6323. ;
  6324. ;
  6325. ;******************************************************************
  6326. iscStepComp pshb ; st0 = val
  6327. tab ; b = step
  6328. coma ; a = ~step
  6329. anda #$7f ; a = ~step & $7f
  6330. std iscStepCom ; iscStepCom = ~step & $7f, iscStepCurr = step
  6331. pulb ; b = val
  6332. rts ;
  6333.  
  6334.  
  6335.  
  6336. ;******************************************************************
  6337. ;
  6338. ; Increase the value of T40s_iscStable timer if the
  6339. ; new value is higher than the current one
  6340. ;
  6341. ; T40s_iscStable = max(T40s_iscStable, b)
  6342. ;
  6343. ;******************************************************************
  6344. updIscStableTimer
  6345. cmpb T40s_iscStable ;
  6346. bcs L1434 ; Branch if b < T40s_iscStable
  6347. stab T40s_iscStable ; Use new higher value
  6348. L1434 rts ;
  6349.  
  6350.  
  6351.  
  6352. ;******************************************************************
  6353. ;
  6354. ;
  6355. ; b = min(b,iscStepMax)
  6356. ;
  6357. ;
  6358. ;******************************************************************
  6359. iscStepMaxFunc cmpb iscStepMax
  6360. bcs L1436
  6361. ldab iscStepMax
  6362. L1436 rts
  6363.  
  6364.  
  6365.  
  6366. ;******************************************************************
  6367. ;
  6368. ; Input:
  6369. ; b = val1
  6370. ;
  6371. ;
  6372. ;******************************************************************
  6373. iscCalc3 stab temp1 ; temp1 = val1
  6374. bsr iscPointers ; x points to iscm; y points to iscYn
  6375. ldd $00,x ; d = iscm
  6376. bsr iscMinMax ; apply min and max, d = ...
  6377. tab ; b = iscm/256
  6378. clra ; a = 0
  6379. addb temp1 ; b = iscm/256 + val1
  6380. rola ; propagate carry, d = iscm/256 + val1
  6381. bra L1445 ; go to subtract $80 with min check and then make sure result fits in b (max of $ff)
  6382.  
  6383.  
  6384. ;******************************************************************
  6385. ;
  6386. ; ISC step related, apply min and max to D
  6387. ;
  6388. ; Input:
  6389. ; d = val
  6390. ; Output:
  6391. ; d = max($6c00, min($b000, val))
  6392. ;******************************************************************
  6393. iscMinMax cmpd #$b000 ;
  6394. bcs L1439 ; Branch if d < $b000
  6395. ldd #$b000 ; Use max of $b000
  6396. L1439 cmpd #$6c00 ;
  6397. bcc L1440 ; Branch if d >= $6c00
  6398. ldd #$6c00 ; Use min of $6c00
  6399. L1440 rts ;
  6400.  
  6401.  
  6402.  
  6403. ;******************************************************************
  6404. ;
  6405. ; Get current pointers to ISC step learning variables
  6406. ;
  6407. ; input: none (port3Snap1 is used)
  6408. ; output: X points to isc0 if A/C switch off, isc1 otherwise
  6409. ; Y points to iscY0, iscY1 or iscY2
  6410. ;
  6411. ; A/C switch PS pump x y
  6412. ; off off isc0 iscY0
  6413. ; off on isc0 iscY2
  6414. ; on off isc1 iscY1
  6415. ; on on isc1 iscY2
  6416. ;
  6417. ;******************************************************************
  6418. iscPointers ldx #isc0 ; x points to isc0
  6419. ldy #iscY0 ; y points to iscY0
  6420. brset port3Snap1, #$10, L1442 ; Branch if A/C switch off
  6421. inx ;
  6422. inx ; x points to isc1
  6423. incy ; y points to iscY1
  6424. L1442 brclr port3Snap1, #$08, L1443 ; Branch if power steering pump is deactivated?
  6425. ldy #iscY2 ; y points to iscY2
  6426. L1443 rts ;
  6427.  
  6428.  
  6429.  
  6430. ;******************************************************************
  6431. ;
  6432. ; Input:
  6433. ; b = val
  6434. ;
  6435. ;
  6436. ;******************************************************************
  6437. iscCalc4 bsr iscPointers ; x points to iscm; y points to iscYn
  6438. clra ; a = 0
  6439. addb $00,y ; d = val + iscYn
  6440. adca #$00 ; propagate carry
  6441. L1445 subd #$0080 ; d = val + iscYn -$80
  6442. bcc L1446 ; Branch if no underflow
  6443. clra ;
  6444. clrb ; Use min of 0
  6445. L1446 jmp ovfCheck ; Check that result fits in b ($ff max)
  6446.  
  6447.  
  6448.  
  6449.  
  6450. ;******************************************************************
  6451. ;
  6452. ; Initialize ISC iscYn variables
  6453. ;
  6454. ; E931:
  6455. ;
  6456. ; iscY0 = $86
  6457. ; iscY1 = $8a
  6458. ; iscY2 = $86
  6459. ;
  6460. ; E932:
  6461. ;
  6462. ; iscY0 = $86 or iscY0 = $83
  6463. ; iscY1 = $8a iscY1 = $83
  6464. ; iscY2 = $86 iscY2 = $83
  6465. ;
  6466. ;******************************************************************
  6467. iscYnInit .equ $
  6468. #ifdef E931
  6469. ldaa #$86
  6470. ldab #$8a
  6471. #else
  6472. ldaa #$83
  6473. tab
  6474. brclr port3Snap1, #$20, L1448
  6475. ldaa #$86
  6476. ldab #$8a
  6477. #endif
  6478.  
  6479. L1448 staa iscY0
  6480. staa iscY2
  6481. stab iscY1
  6482. rts
  6483.  
  6484.  
  6485.  
  6486. ;******************************************************************
  6487. ;
  6488. ;
  6489. ; Sensor check related table,
  6490. ; correspond one for one to table at t_snsrChk
  6491. ; Each entry is the bit to set/reset in the faulth:faultl
  6492. ; for the corresponding sensor
  6493. ;
  6494. ;
  6495. ;******************************************************************
  6496. t_snsrChkBit .word $0200, $4000, $8000, $0001
  6497. .word $0008, $0010, $0040, $2000
  6498. .word $0004, $0400, $0800, $0002
  6499.  
  6500.  
  6501.  
  6502. ;****************************************************************
  6503. ;
  6504. ; Used for output of error codes to test connector
  6505. ;
  6506. ; in order: o2 maf iat tps N/A ect cas tdc (high fault, $01, $02, $04, $08, $10, $20, $40, $80)
  6507. ; vss bar knk inj fuel egr coil N/A (low fault, $01, $02, $04, $08, $10, $20, $40, $80)
  6508. ;
  6509. ; Format:
  6510. ;
  6511. ; high nibble = number of "long pulse" to output (max of 7?)
  6512. ; low nibble = number of "short pulse" to output (max of 15?)
  6513. ;
  6514. ;****************************************************************
  6515. t_snsrChkCode .byte $11, $12, $13, $14, $15, $21, $22, $23, $24, $25, $31, $41, $42, $43, $44, $00
  6516.  
  6517.  
  6518.  
  6519. ;****************************************************************
  6520. ;
  6521. ; Sensor check subroutine vectors
  6522. ;
  6523. ;****************************************************************
  6524. t_snsrChk .word test_maf, test_cas, test_tdc, test_reed
  6525. .word test_inj, test_fpump, test_coil, test_ect
  6526. .word test_knock, test_iat, test_tps, test_baro
  6527.  
  6528.  
  6529.  
  6530. ;****************************************************************
  6531. ;
  6532. ; Actuator activate lookup table (OBD command processing)
  6533. ;
  6534. ;****************************************************************
  6535. t_obdActMask .byte $20, $10, $08, $04, $01, $02
  6536.  
  6537.  
  6538.  
  6539. ;****************************************************************
  6540. ;
  6541. ; Injector disable lookup table (OBD command processing)
  6542. ;
  6543. ;****************************************************************
  6544. t_obdInjMask .byte $fb, $fd, $f7, $fe
  6545.  
  6546.  
  6547.  
  6548. ;******************************************************************
  6549. ;
  6550. ;
  6551. ; Fourth subroutine
  6552. ;
  6553. ;
  6554. ;******************************************************************
  6555. ;--------------------------------------------------
  6556. ; Reset a few things (most fault codes, etc)
  6557. ; if ECU power has been on for less than 0.5 sec
  6558. ;--------------------------------------------------
  6559. subroutine4 ldaa T2_EcuPower ;
  6560. adda #$01 ;
  6561. bcc L1454 ; Branch if its been more than 0.5sec since ECU power has been on
  6562. andm validFlags, #$f9 ; Reset o2 and egrt "sensor condition determined" flags
  6563. orm validFlags, #$01 ; set flag indicating no CAS interrupt received for a long time
  6564. andm faultHi, #$01 ; Reset all current faults but o2 sensor bit
  6565. andm faultLo, #$20 ; Reset all current faults but egrt sensor bit
  6566. ldaa #$08 ;
  6567. staa T2_snsrChk ; re-init T2_snsrChk with 4 sec
  6568. ldaa #$ff ;
  6569. staa T2_stCrank ; re-init T2_stCrank with max value (127.5sec)
  6570. andm state2, #$ef ; Reset ECT related flag???
  6571.  
  6572. ;------------------------------------
  6573. ; Set flag if engine not rotating
  6574. ;------------------------------------
  6575. L1454 ldaa T40_engRot
  6576. bne L1455 ; Branch if engine rotating
  6577. orm validFlags, #$01 ; Engine not rotating (or very slowly) set flag
  6578. bra L1458 ; Branch to continue
  6579.  
  6580. ;------------------------------------------------------
  6581. ; If the engine is startingToCrank or was not rotating
  6582. ; the last time we were here and is now rotating
  6583. ;
  6584. ; Update ectStCrank and related timers, the ect when
  6585. ; we started cranking...
  6586. ;------------------------------------------------------
  6587. L1455 brset validFlags, #$01, L1456 ; Branch if engine was not rotating the last time we checked
  6588. brclr state1, #$01, L1458 ; Bail if startingToCrank clear
  6589. L1456 andm validFlags, #$fe ; startingToCrank or was not rotating the last time we were here and is now rotating
  6590. ldaa ectFiltered ;
  6591. staa ectStCrank ; ectStCrank = ectFiltered
  6592. ldab #$ff ;
  6593. stab T2_stCrank ; T2_stCrank = $ff (127.5sec)
  6594. stab T0p5_crank2 ; T0p5_crank2 = $ff (510sec)
  6595. ldaa ectRaw ;
  6596. ldab #$5a ; 180sec
  6597. cmpa #$1c ; 86 degC
  6598. bls L1457 ; Branch if temperature(ectRaw)>= 86degC
  6599. ldab #$b4 ; 360 sec
  6600. L1457 stab egrtTimerThr ; egrtTimerThr = $5a or $b4 (180sec or 360sec depending on ect)
  6601.  
  6602. ;-------------------------------------------------
  6603. ; Section performing the sensor check functions..
  6604. ;-------------------------------------------------
  6605. ;--------------------------------------------------------------------------
  6606. ; Loop sensrChkIdx from 0 to 7 if T2_stCrank (startingToCrank) started counting
  6607. ; less than 60 sec ago (only first 8 sensor tests are performed,
  6608. ; the most important ones I suppose to start the car, except for reed
  6609. ; switch, safety maybe?) else loop at 12 (all tests are performed)
  6610. ;--------------------------------------------------------------------------
  6611. L1458 ldaa #$08 ; a = $08
  6612. ldab T2_stCrank ; b = T2_stCrank
  6613. addb #$78 ; b = T2_stCrank + $78 (60sec)
  6614. bcs L1459 ; Branch if T2_stCrank started counting less than 60 sec ago
  6615. adda #$04 ; a = $0c
  6616. L1459 ldab sensrChkIdx ; b = sensrChkIdx
  6617. cba ;
  6618. bhi L1460 ; Branch to start checking if sensrChkIdx < $0c or $08
  6619.  
  6620. ;-------------------------------------------------
  6621. ; sensrChkIdx >= $0c or $08
  6622. ; re-init T2_snsrChk to 4 sec and sensrChkIdx to 0
  6623. ;-------------------------------------------------
  6624. ldaa #$08 ;
  6625. staa T2_snsrChk ; T2_snsrChk = 8 (4 sec)
  6626. clrb ;
  6627. stab sensrChkIdx ; sensrChkIdx = 0
  6628.  
  6629. ;----------------------------------------------------------
  6630. ; Call the sensor check rountine according to sensrChkIdx
  6631. ;----------------------------------------------------------
  6632. L1460 aslb ; b = 2*sensrChkIdx (2 bytes per address...)
  6633. ldx #t_snsrChk ; x = t_snsrChk
  6634. abx ; x = t_snsrChk + 2*sensrChkIdx
  6635. ldy $00,x ; y points to sensor check function
  6636. ldx #t_snsrChkBit ; x = t_snsrChkBit (sensor "fault bit position" table)
  6637. abx ; x = t_snsrChkBit + 2*sensrChkIdx
  6638. clrb ; b = 0
  6639. jsr $00,y ; call sensor check subroutine
  6640. tstb ;
  6641. beq L1462 ; Branch if no error found
  6642. bpl L1463 ; Branch if inconclusive
  6643.  
  6644. ;------------------------------------------------------
  6645. ; Sensor check returned negative, error is detected
  6646. ;
  6647. ; Check if T2_snsrChk is expired, which would mean we have
  6648. ; been stuck on testing the same sensor for 4 sec and
  6649. ; it never worked properly...)
  6650. ;------------------------------------------------------
  6651. ldd $00,x ; [a:b] = t_snsrChkBit(sensrChkIdx)
  6652. tst T2_snsrChk ;
  6653. beq L1461 ; branch if T2_snsrChk is 0 (more than 4 sec elapsed since sensrChkIdx was reset to 0)
  6654.  
  6655. ;------------------------------------------------------
  6656. ; T2_snsrChk is not expired, don't set the error flags but
  6657. ; if it they were already set increase sensrChkIdx
  6658. ; (meaning this sensor was already detected as bad
  6659. ; with a 4 sec check, don't do it again for that
  6660. ; sensor, go to the next one)
  6661. ;------------------------------------------------------
  6662. anda faultHi ;
  6663. bne L1463 ; Branch to increase sensrChkIdx if error bit was already set (if it was located in faultHi)
  6664. andb faultLo ;
  6665. bne L1463 ; Branch to increase sensrChkIdx if error bit was alrready set (if it was located in faultLo)
  6666. bra L1464 ; Error bit was not already set, don't change sensrChkIdx (check it agaian next time)
  6667.  
  6668. ;-----------------------------------------------------------------------
  6669. ; More than 4 sec elapsed since sensrChkIdx was reset to 0
  6670. ; (this means that we have been stuck on testing the same sensor
  6671. ; for 4 sec and it never worked properly...)
  6672. ;
  6673. ; Set the error flags and increase sensrChkIdx
  6674. ;-----------------------------------------------------------------------
  6675. L1461 oraa faultHi ; Set the error bit if located in faultHi
  6676. orab faultLo ; Set the error bit if located in faultLo
  6677. std faultHi ; Update faultHi:faultLo
  6678. oraa stFaultHi ; Set the error bit if located in stFaultHi
  6679. orab stFaultLo ; Set the error bit if located in stFaultLo
  6680. std stFaultHi ; Update stFaultHi:stFaultLo
  6681. bra L1463 ; Branch to increase sensrChkIdx
  6682.  
  6683. ;---------------------------------------------------
  6684. ; Sensor check returned zero, no error, reset bit
  6685. ;---------------------------------------------------
  6686. L1462 ldd $00,x ; [a:b] = t_snsrChkBit(sensrChkIdx)
  6687. coma ; complement all bits
  6688. comb ; complement all bits
  6689. anda faultHi ; reset the bit if it was in faultHi
  6690. andb faultLo ; reset the bit if it was in faultLo
  6691. std faultHi ; Update faultHi:faultLo
  6692.  
  6693. ;------------------------------------------------------
  6694. ; Go to next sensor and re-init T2_snsrChk to 4 sec
  6695. ;------------------------------------------------------
  6696. L1463 inc sensrChkIdx ; Increment index (go to next sensor check subroutine next time)
  6697. ldaa #$08 ; 4 sec
  6698. staa T2_snsrChk ; re-init timer to 4 sec
  6699.  
  6700. ;-------------------------------------------------------------------------------
  6701. ; Section to verify the O2 sensor under specific conditions
  6702. ;-------------------------------------------------------------------------------
  6703. ;-------------------------------------------------------------------------------
  6704. ; First check if o2Raw indicate rich or lean, set a flag in b for now
  6705. ;-------------------------------------------------------------------------------
  6706. L1464 clrb ; assume we are running lean, b = 0
  6707. ldaa o2Raw ; a = o2Raw
  6708. cmpa #$1f ;
  6709. bcs L1465 ; Branch if o2Raw < 0.6V (lean)
  6710. orab #$80 ; Set flag indicating we are running rich
  6711.  
  6712. ;-------------------------------------------------------------------------------
  6713. ; Now check if all the conditions are met to do the verfication
  6714. ;
  6715. ; engine has been running for more than 180sec
  6716. ; baro sensor value is reliable
  6717. ; no fault code on baro, coil, iat, ect, cas
  6718. ; ectRaw and iatRaw are within acceptable range
  6719. ; temperature(ectRaw) > 86degC
  6720. ; temperature(iatRaw) > 0degC
  6721. ; temperature(iatRaw) < 55degC
  6722. ; engine is running normally (no fuel cut, etc..)
  6723. ; airVolTB < $68
  6724. ; airVolTB > $33
  6725. ; rpm31 < 4000
  6726. ; rpm31 > 2000
  6727. ; all conditions for closed loop mode are met
  6728. ;
  6729. ;-------------------------------------------------------------------------------
  6730. L1465 ldaa T0p5_crank2 ; a = T0p5_crank2
  6731. adda #$5a ;
  6732. bcs L1467 ; Bail if its been less than 180sec since engine started rotating
  6733. ldaa T40_baro ; T40_baro
  6734. bne L1467 ; Bail if T40_baro not zero (meaning baro sensor value is not reliable)
  6735. brset faultLo, #$42, L1467 ; Bail if errors on baro or coil
  6736. brset faultHi, #$26, L1467 ; Bail if errors on iat, ect or cas
  6737. brset state2, #$03, L1467 ; Bail ifectRaw or iatRaw out of acceptable range
  6738. ldaa ectRaw ; a = ectRaw
  6739. cmpa #$1c ;
  6740. bcc L1467 ; Bail if temperature(ectRaw) <= 86degC
  6741. ldaa iatRaw ; a = iatRaw
  6742. cmpa #$b3 ;
  6743. bcc L1467 ; Bail if temperature(iatRaw) <= 0degC
  6744. cmpa #$41 ;
  6745. bls L1467 ; Bail if temperature(iatRaw) >= 55degC
  6746. brset state1, #$1f, L1467 ; Bail if engine not running normally (i.e. notRotating or startingToCrank or rotatingStopInj or runningFast or no pulse accumulator interrupts received )
  6747. ldaa airVolTB ; a = airVolTB
  6748. #ifdef E931
  6749. cmpa #$68 ;
  6750. bcc L1467 ; Bail if airVolTB >= $68
  6751. cmpa #$33 ;
  6752. #else
  6753. cmpa #$90 ;
  6754. bcc L1467 ;
  6755. cmpa #$1a ;
  6756. #endif
  6757. bls L1467 ; Bail if airVolTB <= $33
  6758. ldaa rpm31 ; a = rpm31
  6759. cmpa #$80 ;
  6760. bcc L1467 ; Bail if rpm31 >= 4000
  6761. cmpa #$40 ;
  6762. bls L1467 ; Bail if rpm31 <= 2000
  6763. brclr closedLpFlags, #$02, L1467 ; Bail if not all conditions for closed loop mode are met
  6764.  
  6765. ;---------------------------------------------------------
  6766. ; All the conditions are met
  6767. ; At this point, b = $80 if o2Raw is rich, $00 otherwise
  6768. ;---------------------------------------------------------
  6769. tba ; a = $80 if o2Raw rich else $00
  6770. adda validFlags ; a = validFlags + ($80 or $00)
  6771. bmi L1466 ; Branch if running rich (validFlags + ($80 or $00) > $80 only if o2Raw>=0.6V above...)
  6772.  
  6773. ;-------------------------------
  6774. ; Running lean (o2Raw < 0.6V)
  6775. ;-------------------------------
  6776. ldaa T2_o2Chk ; a = T2_o2Chk
  6777. bne L1468 ; Branch if timer not expired, its been less than 30sec since all conditions were met and we are running lean
  6778. brset validFlags, #$02, L1468 ; Branch if o2 sensor condition already determined (no need to check further)
  6779.  
  6780. ;------------------------------------------------------
  6781. ; Timer is expired and the o2 sensor condition is not
  6782. ; already determined. Since we have been running lean
  6783. ; for over 30sec, we know the sensor is bad...
  6784. ;
  6785. ; Set the flag indicating the o2 sensor conditions was
  6786. ; determined, and increment o2BadCnt (with max of 255) to
  6787. ; indicate we have an error condition
  6788. ; Note that o2BadCnt increase by 1 max every time
  6789. ; the ECU is turned on (which resets validFlags.1)
  6790. ;------------------------------------------------------
  6791. orm validFlags, #$02 ; Set flag indicating o2 sensor condition was checked (bad in this case)
  6792. inc o2BadCnt ; o2BadCnt = o2BadCnt + 1
  6793. bne L1468 ; Branch to continue if o2BadCnt != 0
  6794. dec o2BadCnt ; o2BadCnt equals 0, go back to 255
  6795. bra L1468 ; branch to continue
  6796.  
  6797. ;-----------------------------------------------------------------
  6798. ; Running rich (o2Raw >= 0.6V)
  6799. ; As soon as we are running rich we know the sensor
  6800. ; is good, clear fault and set flag indicating o2 sensor
  6801. ; conditions was determined (good in this case)
  6802. ;-----------------------------------------------------------------
  6803. L1466 clr o2BadCnt ; o2BadCnt = 0
  6804. orm validFlags, #$02 ; Set flag indicating o2 sensor condition was checked (ok in this case)
  6805.  
  6806. ;-------------------------------
  6807. ; Re-init timer T2_o2Chk to 30sec
  6808. ;-------------------------------
  6809. L1467 ldaa #$3c ; 30sec
  6810. staa T2_o2Chk ;
  6811.  
  6812. ;------------------------------------------------------------
  6813. ; Update validFlags.7 rich/lean flag with current o2 conditions
  6814. ;------------------------------------------------------------
  6815. L1468 andm validFlags, #$7f ; Reset rich/lean flag
  6816. addb validFlags ; Add current rich/lean flag (set to 1 if rich)
  6817. stab validFlags ; Update validFlags
  6818.  
  6819. ;---------------------------------------------------------------------------
  6820. ; if o2BadCnt >= 1, set o2 fault code in current and stored fault variables
  6821. ;---------------------------------------------------------------------------
  6822. ldaa o2BadCnt ;
  6823. cmpa #$01 ;
  6824. bcs L1469 ; Branch to no o2 fault if o2BadCnt=0
  6825. orm faultHi, #$01 ; set oxygen sensor fault code?
  6826. orm stFaultHi, #$01 ;
  6827. bra L1470 ;
  6828.  
  6829. ;------------------------------------------------------------
  6830. ; Reset o2 fault code in only current fault variables
  6831. ;------------------------------------------------------------
  6832. L1469 andm faultHi, #$fe ; Clear oxygen sensor fault code
  6833.  
  6834. ;-------------------------------------------------------------------------------
  6835. ; Check if all the conditions are met to test the egrt sensor validity
  6836. ;
  6837. ; more than ($5a or $b4)/0.5 sec have elapsed since engine started rotating
  6838. ; baro sensor value is reliable
  6839. ; no fault code on baro, coil, iat, ect, cas
  6840. ; ectRaw and iatRaw are within acceptable range
  6841. ; temperature(ectRaw) > 86degC
  6842. ; temperature(iatRaw) < 55degC
  6843. ; baroRaw > 0.92bar
  6844. ; rpm31 < 3500
  6845. ; rpm31 > 2094
  6846. ; airVol < L2048(rpm)
  6847. ; airVol > L2047(rpm)
  6848. ;
  6849. ;-------------------------------------------------------------------------------
  6850. L1470 ldaa egrtTimerThr ; a = egrtTimerThr
  6851. adda T0p5_crank2 ;
  6852. bcs L1474 ; Bail if less than ($5a or $b4)/0.5 sec have elapsed since engine started rotating
  6853. ldaa T40_baro ;
  6854. bne L1474 ; Bail if T40_baro not zero (meaning baro sensor value is not reliable)
  6855. brset faultLo, #$42, L1474 ; Bail if errors on baro or coil
  6856. brset faultHi, #$26, L1474 ; Bail if errors on iat, ect or cas
  6857. brset state2, #$03, L1474 ; Bail ifectRaw or iatRaw out of acceptable range
  6858. ldaa ectRaw ;
  6859. cmpa #$1c ;
  6860. bcc L1474 ; Bail if temperature(ectRaw) <= 86degC
  6861. ldaa iatRaw ;
  6862. cmpa #$42 ;
  6863. bls L1474 ; Bail if temperature(iatRaw) >= 55degC
  6864. ldaa baroRaw ;
  6865. cmpa #$bd ;
  6866. bcs L1474 ; Bail if baroRaw < 0.92bar
  6867. ldaa rpm31 ;
  6868. cmpa #$70 ;
  6869. bcc L1474 ; Bail if rpm >=3500
  6870. cmpa #$43 ;
  6871. bls L1474 ; Bail if rpm <= 2094
  6872. ldx #L2048 ;
  6873. jsr interp16rpm ; b = L2048(rpm)
  6874. cmpb airVol ;
  6875. bls L1474 ; Bail if airVol >= L2048(rpm)
  6876. ldx #L2047 ;
  6877. jsr interp16rpm ; b = L2047(rpm)
  6878. cmpb airVol ;
  6879. bcc L1474 ; Bail if airVol <= L2047(rpm)
  6880.  
  6881. ;------------------------------------------
  6882. ; All basic condition are met,
  6883. ; bail if T2_egrtChk > 10
  6884. ;------------------------------------------
  6885. ldaa T2_egrtChk ;
  6886. cmpa #$0a ;
  6887. bhi L1478 ; Bail if T2_egrtChk > 10 ????
  6888.  
  6889. ;----------------------------------------------------
  6890. ; All basic condition are met and T2_egrtChk <= 10
  6891. ; Check the temperature indicated by the egrt
  6892. ; sensor and branch accordingly
  6893. ;----------------------------------------------------
  6894. ldaa #$05 ;
  6895. cmpa egrtRaw ;
  6896. bhi L1477 ; Branch if temperature(egrtRaw) > 307degCC (error, too hot)
  6897. ldx #L2046 ;
  6898. jsr iatCInterp ; b = L2046(iat)
  6899. cmpb egrtRaw ;
  6900. bcs L1477 ; Branch if temperature(egrtRaw) < L2046(iat) (error, too cold)
  6901.  
  6902. ;--------------------------------------------------------
  6903. ; At this point we know the egrt sensor is good
  6904. ; clear fault and set flag indicating sensor condition
  6905. ; was determined (good in this case)
  6906. ;--------------------------------------------------------
  6907. clr egrtBadCnt ; egrtBadCnt = 0, no fault
  6908. orm validFlags, #$04 ; Set flag indicating sensor condition was checked (ok in this case)
  6909. clra ; a = 0
  6910. bra L1475 ; Branch to set timer to 5 sec such that we continously check the sensor
  6911.  
  6912. ;----------------------------------------
  6913. ; Reset T2_egrtChk timer to 20 sec and bail
  6914. ;----------------------------------------
  6915. L1474 ldaa #$1e ; a = 15sec
  6916. L1475 adda #$0a ; a = a + 5sec
  6917. bcc L1476 ; Branch if no overflow
  6918. ldaa #$ff ; Use max of $ff
  6919. L1476 staa T2_egrtChk ; Update T2_egrtChk
  6920. bra L1478 ; Bail
  6921.  
  6922. ;----------------------------------------------------------------------------------
  6923. ; At this point we found that the sensor temperature is out of range (bad sensor)
  6924. ;----------------------------------------------------------------------------------
  6925. L1477 ldaa T2_egrtChk ; a = T2_egrtChk
  6926. bne L1478 ; Branch if timer not expired
  6927. brset validFlags, #$04, L1478 ; Branch if egrt sensor condition already determined
  6928.  
  6929. ;--------------------------------------------------------------------------
  6930. ; Sensor is bad, timer is expired and sensor condition not yet determined
  6931. ;
  6932. ; Set flag indicating sensor condition was determined (bad in this case)
  6933. ; and increment egrtBadCnt (255 max) to indicate we have an error condition
  6934. ; Note that egrtBadCnt increase by 1 max every time the ECU is turned off/on
  6935. ; (which resets validFlags.1)
  6936. ;--------------------------------------------------------------------------
  6937. orm validFlags, #$04 ; Set flag
  6938. inc egrtBadCnt ; egrtBadCnt = egrtBadCnt + 1
  6939. bne L1478 ; Bail if egrtBadCnt != 0
  6940. dec egrtBadCnt ; egrtBadCnt equals 0, go back to 255
  6941.  
  6942. ;---------------------------------------------------------------------------
  6943. ; if egrtBadCnt >= 2, set egrt fault code in current and stored fault variables
  6944. ;
  6945. ; egrtBadCnt >= 2 only if the ECU is turned off and then on again
  6946. ;---------------------------------------------------------------------------
  6947. L1478 ldaa egrtBadCnt ;
  6948. cmpa #$02 ;
  6949. bcs L1479 ; Branch if egrtBadCnt < 2
  6950. orm faultLo, #$20 ; Set egrt sensor fault flag
  6951. orm stFaultLo, #$20 ; Set egrt sensor fault flag
  6952. bra L1480 ;
  6953.  
  6954. ;------------------------------------------------
  6955. ; Reset egrt fault code in current fault variable
  6956. ;------------------------------------------------
  6957. L1479 andm faultLo, #$df ;
  6958.  
  6959. ;---------------------------------------------------------------------------
  6960. ; Reset egrt errors and fault codes if vehicle is not for California
  6961. ;---------------------------------------------------------------------------
  6962. L1480 brset config1, #$04, L1481 ; Bail if California car
  6963. clr egrtBadCnt ; reset egrt error count
  6964. andm stFaultLo, #$df ; Reset egrt stored fault code
  6965. andm faultLo, #$df ; Reset egrt current fault code
  6966.  
  6967. ;---------------------------------------------------------------------------
  6968. ; Reset N/A stored fault codes (fault codes don't correspond to anything)
  6969. ;---------------------------------------------------------------------------
  6970. L1481 andm stFaultHi, #$ef ;
  6971. andm stFaultLo, #$7f ;
  6972.  
  6973. ;----------------------------------------------------------------
  6974. ; If ECU is not about to turn-off check if there are faults set
  6975. ; and inital 5 sec "check engine light on" delay
  6976. ;----------------------------------------------------------------
  6977. ldaa T40_noPower ;
  6978. beq L1482 ; Branch to clear check engine light if timer expired (ECU is about to turn-off)
  6979. ldd faultHi ; d = faultHi:faultLo (current faults)
  6980. anda #$ef ; Reset N/A sensor fault bit
  6981. bne L1483 ; Branch to set check engine light if any errors left in faultHi
  6982. andb #$7e ; Reset vss and baro sensor in faultLo
  6983. bne L1483 ; Branch to set check engine light if any errors left in faultLo
  6984. ldaa T2_EcuPower ;
  6985. adda #$0a ;
  6986. bcs L1483 ; Branch if its been less than 5 sec since ECU power has been on
  6987.  
  6988. ;------------------------------------------------------------------
  6989. ; Its been more than 5 sec since ECU power has been on
  6990. ; and there is no fault set in faultHi:faultLo (apart from vss)
  6991. ; and ECU in not about to turn off
  6992. ;
  6993. ; Clear check engine light
  6994. ;------------------------------------------------------------------
  6995. L1482 orm port6, #$08 ; clear CE light
  6996. bra L1484 ;
  6997.  
  6998. ;-------------------------------------------------------------
  6999. ; Its been less than 5 sec since ECU power has been on
  7000. ; or there are faults set in faultHi:faultLo (apart from vss)
  7001. ; or ECU is about to turn off
  7002. ;
  7003. ; Activate check engine light
  7004. ;-------------------------------------------------------------
  7005. L1483 andm port6, #$f7 ; activate CE light
  7006.  
  7007.  
  7008. ;-----------------------------------------------------------------
  7009. ; Section to process diagnostic connector port commands/requests
  7010. ;-----------------------------------------------------------------
  7011. ;--------------------------------------------------------------
  7012. ; Bail to "heart beat" mode section if port rx is not enabled
  7013. ;--------------------------------------------------------------
  7014. L1484 brset sci_scr, #$08, L1485 ; Branch if serial port rx enabled.
  7015. jmp L_heartBeat ; rx not enabled, branch to section processing heart beat code
  7016.  
  7017. ;-----------------------------------------------------------
  7018. ; rx is enabled, we are in test mode. Check if anything
  7019. ; is being transmited or if anything new was received
  7020. ;-----------------------------------------------------------
  7021. L1485 brclr sci_scr, #$20, L1486 ; Branch if transmit data register is not empty (1 = empty...)
  7022. brset obdFlags, #$40, L1487 ; tx empty, branch if anything to process (e.g. a code was received (in interupt) and stored in obdCode)?
  7023.  
  7024. ;-------------------------------------------------
  7025. ; At this point rx enabled but tx not empty
  7026. ; or it is empty but there is nothing to process
  7027. ;
  7028. ; Reset action related registers and bail
  7029. ;-------------------------------------------------
  7030. L1486 orm obdInjCmd, #$3f ; reset any injector action
  7031. clr obdActCmd ; reset any actuator action
  7032. clr T40_obdCmd ; Clear action timer
  7033. jmp L1504 ; Bail to rest of code
  7034.  
  7035. ;------------------------------------------------------------
  7036. ; At this point we are in test mode, transmit register is
  7037. ; empty and a new code was received and stored in obdCode
  7038. ; Process the new code,
  7039. ;------------------------------------------------------------
  7040. ;------------------------------------------
  7041. ; Check if code is $fd (serial link test)
  7042. ;------------------------------------------
  7043. #ifdef E931
  7044. L1487 ldaa #$b5 ; Default value returned if code = $fd. (serial link test)
  7045. #else
  7046. L1487 ldaa #$b7 ; Default value returned if code = $fd. (serial link test)
  7047. #endif
  7048. ldab obdCode ; load received OBD code
  7049. cmpb #$fd ;
  7050. bcs L1490 ; branch if code is lower than $FD
  7051. beq L1496 ; bail to send response if code is equal to $fd
  7052.  
  7053. ;--------------------------------------------------------
  7054. ; obdCode equals $fe or $ff, respond with high or low
  7055. ; part ($fe or $ff code) of configration data (t_strap3)
  7056. ;--------------------------------------------------------
  7057. ldx #t_strap3 ; x = configuration data
  7058. tba ;
  7059. jsr cfgLookup16 ;
  7060. cmpa #$fe ; compare to FE
  7061. xgdx ;
  7062. beq L1489 ;
  7063. tba ;
  7064. L1489 bra L1496 ; branch to send on serial
  7065.  
  7066. ;------------------------
  7067. ; obdCode lower than $fd
  7068. ;------------------------
  7069. L1490 cmpb #$f1 ;
  7070. bcc L1494 ; branch if code is larger or equal to $f1
  7071. cmpb #$40 ;
  7072. bcs L1491 ; branch if code is lower than $40
  7073.  
  7074. ;------------------------
  7075. ; $40 <= obdCode < $f1
  7076. ; Check if it is $ca
  7077. ;------------------------
  7078. cmpb #$ca ;
  7079. beq L1493 ; branch if code equals $ca
  7080.  
  7081. ;----------------------------------------------------------------------
  7082. ; $40 <= obdCode < $f1 and it is not $ca
  7083. ; just respond with whatever is stored in the corresponding memory
  7084. ;----------------------------------------------------------------------
  7085. clra ; a=0
  7086. xgdx ; x = obdCode
  7087. ldaa $00,x ; a = whatever is in corresponding memory
  7088. bra L1496 ; branch to send on serial
  7089.  
  7090. ;----------------------------------------------------------------------
  7091. ; obdCode lower than $40, respond with sensor value
  7092. ; ($3e and $3f are converted to $3d)
  7093. ;----------------------------------------------------------------------
  7094. L1491 ldx #obdTable ; x points to obdTable
  7095. cmpb #$3d ;
  7096. bls L1492 ; branch if obdCode <= $3d
  7097. ldab #$3d ; Use max of $3d ($3e and $3f are converted to $3d???)
  7098. L1492 abx ; x points to "sensor" address in table
  7099. ldab $00,x ; b = obdTable(obdCode)
  7100. clra ; a = 0
  7101. xgdx ; x = d = obdTable(obdCode)
  7102. ldaa $00,x ; a = sensor value
  7103. bra L1496 ; branch to send on serial
  7104.  
  7105. ;----------------------------------------------------
  7106. ; obdCode = $ca, clear error faults if engine is not
  7107. ; rotating and respond with $00
  7108. ;----------------------------------------------------
  7109. L1493 ldaa T40_engRot ;
  7110. bne L1502 ; Don't reset fault codes if engine is rotating, we use them to run the car...
  7111. clra ;
  7112. clrb ;
  7113. std stFaultHi ; Erase fault codes
  7114. std faultHi ; Erase fault codes
  7115. staa o2BadCnt ; Erase o2 sensor error count
  7116. staa egrtBadCnt ; Erase egrt sensor error count
  7117. clra ;
  7118. bra L1496 ; Branch to send $00 on serial
  7119.  
  7120. ;----------------------------------------------------
  7121. ; obdCode >= $f1, this is a command/action code
  7122. ; Check if any action is already ongoing
  7123. ;----------------------------------------------------
  7124. L1494 ldaa obdInjCmd ; a = obdInjCmd
  7125. coma ; a = ~obdInjCmd
  7126. anda #$3f ; a = ~obdInjCmd & 00111111
  7127. bne L1495 ; branch if any injector already turned-off
  7128. brclr obdActCmd, #$ff, L1497 ; branch to continue processing if no actuator previously activated
  7129.  
  7130. ;----------------------------------------------------
  7131. ; obdCode >= $f1 and an action is already ongoing
  7132. ;----------------------------------------------------
  7133. L1495 ldaa T40_obdCmd ;
  7134. bne L1497 ; Branch if timer not expired
  7135.  
  7136. ;----------------------------------------------------
  7137. ; Action already ongoing and timer is expired,
  7138. ; reset all injector and actuators to normal mode and
  7139. ; respond with $00 (ignore new action)
  7140. ;----------------------------------------------------
  7141. orm obdInjCmd, #$3f ; set all injectors to normal operation
  7142. clr obdActCmd ; clear current actuator commands
  7143. ldaa #$00 ;
  7144. L1496 jmp L1503 ;
  7145.  
  7146. ;-----------------------------------------------
  7147. ; No action is ongoing or an action is ongoing
  7148. ; but not finished (timer not expired)
  7149. ;
  7150. ; continue processing new code
  7151. ;-----------------------------------------------
  7152. L1497 cmpb #$f6 ;
  7153. bls L1498 ; branch if code is $f1 to $f6
  7154.  
  7155. ;-----------------------------------------------------------
  7156. ; $f7 <= obdCode <= $fc, this is a turn injector off command
  7157. ; Bail if vehicle is moving
  7158. ;-----------------------------------------------------------
  7159. ldaa vssCnt1 ; a = check speed
  7160. beq L1499 ; Branch if speed is close to 0
  7161. bra L1502 ; speed too high, bail (safety I assume)
  7162.  
  7163. ;----------------------------------------------------
  7164. ; $f1 <= obdCode <= f6, this is an actuator command
  7165. ; Bail if engine is rotating
  7166. ;----------------------------------------------------
  7167. L1498 ldaa T40_engRot ; code is F1 to F6, check if "engine running"?
  7168. bne L1502 ; bail if engine is rotating (safety I assume)
  7169.  
  7170. ;------------------------------------------------------------
  7171. ; $f1<= obdCode <= $f6 and it is safe to perform the action
  7172. ; continue processing command/action code
  7173. ;------------------------------------------------------------
  7174. ;----------------------------------
  7175. ; Bail if any injector is already
  7176. ; turned-off by previous command
  7177. ;----------------------------------
  7178. L1499 ldaa obdInjCmd ; a = obdInjCmd
  7179. coma ; a = ~obdInjCmd
  7180. anda #$3f ; a = ~obdInjCmd & 00111111
  7181. bne L1504 ; bail if any injector already off
  7182.  
  7183. ;----------------------------------
  7184. ; Bail if an actuator is already
  7185. ; turned-on by previous command
  7186. ;----------------------------------
  7187. brset obdActCmd, #$ff, L1504 ; bail if a previous action is ongoing
  7188.  
  7189. ;-----------------------------------------
  7190. ; Check if injector or actuator command
  7191. ;-----------------------------------------
  7192. subb #$f7 ; b = obdCode - $f7
  7193. bcs L1500 ; Branch if obdCode < $f7 (actuator command)
  7194.  
  7195. ;-------------------------------------------
  7196. ; obdCode >=$f7, it is an injector command,
  7197. ; Ignore it for injectors 5 and 6
  7198. ;-------------------------------------------
  7199. subb #$02 ; b = injIndex = obdCode - $f7 - $02 = -2 to 3 range (injector 6 to 1 respectively...)
  7200. bcs L1502 ; branch if code is negative (injectors 5 and 6, do nothing)
  7201.  
  7202. ;----------------------------------
  7203. ; obdCode >=$f7, injector command
  7204. ;----------------------------------
  7205. ldx #t_obdInjMask ; x points to t_obdInjMask (table t_obdInjMask: $fb $fd $f7 $fe)
  7206. abx ;
  7207. ldaa $00,x ; a = t_obdInjMask(injIndex) ($fb $fd $f7 $fe for injector 4 3 2 1 resp.-> order in nibble -> 2 4 3 1)
  7208. clrb ; b = $00
  7209. bra L1501 ;
  7210.  
  7211. ;--------------------------------------------
  7212. ; obdCode <$f7, it is an actuator command
  7213. ;--------------------------------------------
  7214. L1500 addb #$06 ; b = actIndex = obdCode - $f7 + $06 = 0 to 5
  7215. ldx #t_obdActMask ; x points to t_obdActMask: 20 10 08 04 01 02
  7216. abx ;
  7217. ldab $00,x ; b = t_obdActMask(actIndex)
  7218. ldaa #$ff ; a = $ff
  7219.  
  7220. ;-----------------------------------------------------------
  7221. ; At this point,
  7222. ; a contains the new injector to turn off, if any
  7223. ; b contains the new actuator to turn on, if any
  7224. ;
  7225. ; Update obdInjCmd and obdActCmd. Notice that only one
  7226. ; actuator is activated at a time but multiple injectors
  7227. ; can be turned off...
  7228. ;-----------------------------------------------------------
  7229. L1501 sei ; Disable interrupts
  7230. anda obdInjCmd ; Turn off the new injector and continue turning off the existing ones
  7231. staa obdInjCmd ; Update obdInjCmd
  7232. stab obdActCmd ; Turn on the new actuator
  7233. cli ;
  7234.  
  7235. ;--------------------------------------------
  7236. ; Re-init T40_obdCmd timer to 6sec and bail
  7237. ;--------------------------------------------
  7238. ldaa #$f0 ; 6 sec
  7239. staa T40_obdCmd ; T40_obdCmd = 6 sec
  7240. bra L1504 ; jump to RTS
  7241.  
  7242. ;--------------------------------------------
  7243. ; Reset any ongoing actions (injector or actuator)
  7244. ;--------------------------------------------
  7245. L1502 orm obdInjCmd, #$3f ; Set all injectors to on
  7246. clr obdActCmd ; Set all actuators to off
  7247. clr T40_obdCmd ; Clear timer
  7248. ldaa #$ff ; respond with $ff
  7249.  
  7250. ;-----------------------------------------------------------------
  7251. ; At this point a contains the response to send on diagnostic port
  7252. ; send it...
  7253. ;-----------------------------------------------------------------
  7254. L1503 staa sci_tx ; either FF or 00 or output value to serial port
  7255. orm obdFlags, #$80 ; set bit indicating something has been sent
  7256. andm obdFlags, #$bf ; reset bit $40 since we finished processing the request
  7257.  
  7258. ;---------------------------------------------
  7259. ; Jump to rest of code (skip heart beat mode)
  7260. ;---------------------------------------------
  7261. L1504 jmp L1524 ; Jump to RTS
  7262.  
  7263.  
  7264.  
  7265. ;****************************************************************
  7266. ;
  7267. ; Used in processing the output of error codes to test connector
  7268. ;
  7269. ; Used to Represent the number of shift we need to apply...
  7270. ;
  7271. ;****************************************************************
  7272. t_errCodeShift .byte $80, $40, $20, $10, $08, $04, $02, $01
  7273.  
  7274.  
  7275.  
  7276. ;****************************************************************
  7277. ;
  7278. ; Output error codes to test connector (heart beat mode)
  7279. ;
  7280. ; a and b are used throughout this code to contain
  7281. ; the old/new values of errCodeProc and errCodeIdx
  7282. ;
  7283. ; Freakin difficult code to disassemble!
  7284. ;
  7285. ;
  7286. ;****************************************************************
  7287. ;----------------------------
  7288. ; Only execute code at 2Hz
  7289. ;----------------------------
  7290. L_heartBeat brset Tclocks, #$04, L1507 ; Branch if 2Hz signal set
  7291. jmp L1524 ; 2Hz signal not yet set, bail
  7292.  
  7293. ;--------------------------------------------------
  7294. ; Load basic variables and check whether
  7295. ; a code is currently being output to connector
  7296. ;--------------------------------------------------
  7297. L1507 ldaa errCodeProc ; a = errCodeProc
  7298. ldab errCodeIdx ; b = errCodeIdx
  7299. tsta ;
  7300. bne L1508 ; Branch if errCodeProc != 0 ( a code is currently being output)
  7301. bitb #$e0 ; test 3 bit 2Hz timer...
  7302. beq L1509 ; Branch if timer is expired (we are really finished with previous code...)
  7303. L1508 jmp L1520 ; Jump to continue processing the code currently being output
  7304.  
  7305. ;---------------------------------------------------------------
  7306. ; At this point we are not processing anything, continue trying
  7307. ;---------------------------------------------------------------
  7308. L1509 clra ; a = 0
  7309. staa temp1 ; temp1 = 0
  7310. L1510 ldaa stFaultHi ; preload a = stFaultHi
  7311. stab temp2 ; temp1:temp2 = errCodeIdx, notice "stab" changes zero flag for branch below...
  7312. beq L1512 ; Branch if errCodeIdx = 0
  7313.  
  7314. ;---------------------------------------------
  7315. ; errCodeIdx > 0
  7316. ; Check if errCodeIdx <= 8
  7317. ;---------------------------------------------
  7318. ldx #t_errCodeShift-1 ; x points to t_errCodeShift-1
  7319. subb #$08 ; b = errCodeIdx - 8
  7320. bls L1511 ; Branch if errCodeIdx <= 8
  7321.  
  7322. ;----------------------------------------------
  7323. ; errCodeIdx > 8, current index is in low fault
  7324. ;----------------------------------------------
  7325. ldaa stFaultLo ; a = stFaultLo since thats what we should be using
  7326. abx ; x points to t_errCodeShift - 1 + (errCodeIdx - 8)
  7327. ldab $00,x ; b = t_errCodeShift(errCodeIdx)
  7328. mul ; shift whats left to process in high part of d (in a)
  7329. ldx temp1 ; x = 0:errCodeIdx
  7330. tsta ; test if any fault bit set
  7331. bra L1513 ; Branch
  7332.  
  7333. ;-----------------------------------------------
  7334. ; errCodeIdx <= 8, current index is in high fault
  7335. ;-----------------------------------------------
  7336. L1511 addb #$08 ; b = errCodeIdx - 8 + 8 = errCodeIdx
  7337. abx ; x points to t_errCodeShift-1 + errCodeIdx
  7338. ldab $00,x ; b = t_errCodeShift(errCodeIdx)
  7339. mul ; shift whats left to process in high part of d (in a)
  7340.  
  7341. L1512 ldx temp1 ; x = 0:errCodeIdx
  7342. tsta ; test if any fault bit set
  7343. bne L1514 ; Branch if any fault bit were set
  7344.  
  7345. ;-----------------------------------------------
  7346. ; No fault bit set in high part, try low part now
  7347. ;-----------------------------------------------
  7348. ldx #$0008 ; new errCodeIdx x = 8
  7349. ldaa stFaultLo ; a = stFaultLo
  7350.  
  7351. ;--------------------------------------------------
  7352. ; At this point, a contains the error bits left (if any)
  7353. ; to process and x is the current index error
  7354. ;--------------------------------------------------
  7355. L1513 beq L1515 ; branch if no error are set in what is left to process
  7356.  
  7357. ;---------------------------------
  7358. ; Loop until we find the bit
  7359. ;---------------------------------
  7360. L1514 inx ; ++x
  7361. lsra ; Shift lowest bit in carry
  7362. bcc L1514 ; Loop if bit was 0
  7363.  
  7364. ;----------------------------------------------------------------
  7365. ; We found a bit set -> we found the next error code to output...
  7366. ; update new errCodeProc value (in a for now) and new errCodeIdx
  7367. ; (in a for now)
  7368. ;----------------------------------------------------------------
  7369. stx temp1 ; temp1:temp2 = newBitIndex of next code????
  7370. ldab temp2 ; b = newBitIndex
  7371. ldx #t_snsrChkCode-1 ; x points to t_snsrChkCode-1
  7372. abx ; x points to t_snsrChkCode-1 + newBitIndex
  7373. ldaa $00,x ; a = t_snsrChkCode(newBitIndex)
  7374. oraa #$80 ; a = t_snsrChkCode(newBitIndex) | $80
  7375. andb #$1f ; b = newBitIndex & $1f
  7376. orab #$a0 ; Set newBitIndex high bits (timer) to 2.5 sec
  7377. bra L1521 ; Branch to set heart beat output and store a and b
  7378.  
  7379. ;------------------------------------------------------
  7380. ; No error found in stFaultLo, this means we are
  7381. ; at the end of the cycle... (we checked high part
  7382. ; first and then low part), restart the whole
  7383. ; thing from errCodeIdx=0 if errCodeIdx not already at 0
  7384. ;------------------------------------------------------
  7385. L1515 clrb ; b = 0 = new value of errCodeIdx
  7386. ldaa temp2 ; a = old errCodeIdx
  7387. bne L1510 ; Loop back if old errCodeIdx != 0
  7388.  
  7389. ;--------------------------------------------------------------------------
  7390. ; errCodeIdx already at 0, there where no error during the cycle
  7391. ; toggle heart beat sent to diagnostic port, this is the "no fault" signal
  7392. ;--------------------------------------------------------------------------
  7393. psha ; st0 = a, why, we know a=0 from test above???????????
  7394. sei ; Make sure no interrupt plays with port2 while we change it
  7395. ldaa port2 ;
  7396. eora #$10 ; Toggle heart beat sent to diagnostic port?
  7397. staa port2 ; Update port
  7398. cli ;
  7399. pula ; a = st0 = 0
  7400. bra L1523 ; Branch to exit
  7401.  
  7402. ;----------------------------------------------------------------
  7403. ; errCodeIdx upper 3 bit timer is expired (Branch from below)
  7404. ; First check if there are more long pulse to ouptput
  7405. ;----------------------------------------------------------------
  7406. L1516 bita #$70 ;
  7407. beq L1518 ; Branch if no more long pulse code (errCodeProc & 01110000 = 0)
  7408.  
  7409. ;-------------------------------------
  7410. ; There are more long pulse to output
  7411. ;-------------------------------------
  7412. suba #$10 ; decrement the number of long pulse by 1
  7413. andb #$1f ; reset timer to 0 (upper 3 bits)
  7414. orab #$80 ; Set 2Hz 3 bit timer to 4 (2 sec)
  7415. L1517 andm port2, #$ef ; Set heart beat sent to diagnostic port
  7416. bra L1522 ; Branch to update timer and exit
  7417.  
  7418. ;----------------------------------------------------
  7419. ; No more long pulse to output
  7420. ; Check if bit 7 is set (was set when we
  7421. ; started output of this code)
  7422. ;----------------------------------------------------
  7423. L1518 bita #$80 ;
  7424. beq L1519 ; Branch if bit is not set
  7425.  
  7426. ;-----------------------------------------------------------------------------
  7427. ; bit 7 is set, we are therefore at the midpoint between long and short pulse
  7428. ;
  7429. ; reset the flag, set the timer to 1.5 sec, reset output and exit
  7430. ; This is basically a 1.5 sec pause in between long and short pulse
  7431. ;-----------------------------------------------------------------------------
  7432. anda #$7f ; Reset bit 7 (nothing left to output flag). At this point a should be equal to $7f ???
  7433. andb #$1f ; Reset timer to 0 (upper 3 bits)
  7434. orab #$60 ; Set 2Hz 3 bit timer to 3 (1.5 sec)
  7435. bra L1521 ; Branch to reset hearth beat, update timer and exit
  7436.  
  7437. ;-----------------------------------------------------------------
  7438. ; Flag was not set, just output whatever short pulses are left...
  7439. ;-----------------------------------------------------------------
  7440. L1519 deca ; decrement the number of short pulse by 1
  7441. andb #$1f ; reset timer to 0 (upper 3 bits)
  7442. orab #$40 ; Set 2Hz 3 bit timer to 2 (1 sec)
  7443. bra L1517 ; Branch to set hearth beat, update timer and exit
  7444.  
  7445. ;---------------------------------
  7446. ; A code is currently being output...
  7447. ; At this point we have
  7448. ; a = errCodeProc
  7449. ; b = errCodeIdx
  7450. ;---------------------------------
  7451. L1520 cmpb #$20 ;
  7452. bcs L1516 ; Branch if errCodeIdx < $20 (e.g. timer=0, upper 3 bit timer is expired)
  7453.  
  7454. ;-------------------------------------
  7455. ; Timer not expired check if timer>1
  7456. ;-------------------------------------
  7457. cmpb #$3f ;
  7458. bhi L1522 ; Branch if errCodeIdx > $3f (timer>1)
  7459.  
  7460. ;-------------------------------------------
  7461. ; timer = 1, set heart beat mode output
  7462. ;-------------------------------------------
  7463.  
  7464. ;-------------------------------------------
  7465. ; Reset heart beat output on diagnostic port
  7466. ;-------------------------------------------
  7467. L1521 orm port2, #$10 ; Reset heart beat sent to diagnostic port
  7468.  
  7469. ;-------------------------------------------------------------
  7470. ; Decrement errCodeIdx timer (upper 3 bits) by $20 (0.5sec)
  7471. ;-------------------------------------------------------------
  7472. L1522 subb #$20 ;
  7473.  
  7474. ;-----------------------------------------------------
  7475. ; Store new errCodeProc and errCodeIdx and return
  7476. ;-----------------------------------------------------
  7477. L1523 staa errCodeProc ;
  7478. stab errCodeIdx ;
  7479. L1524 rts ;
  7480.  
  7481.  
  7482.  
  7483. ;****************************************************************
  7484. ;
  7485. ;
  7486. ; Maf sensor check:
  7487. ;
  7488. ;
  7489. ;****************************************************************
  7490. test_maf ldaa rpm31 ;
  7491. cmpa #$10 ;
  7492. bls L1528 ;
  7493. ldaa T40_mas ;
  7494. beq L1526 ; Branch if timer expired (no mas interrupt for a long time...)
  7495. ldaa t2_diff8 ;
  7496. cmpa #$31 ; t2_diff8 more than 49 is an error?
  7497. bcs L1527 ;
  7498. L1526 decb ;
  7499. L1527 rts ;
  7500. L1528 incb ; return 1 (test not conclusive)
  7501. rts ;
  7502.  
  7503.  
  7504.  
  7505. ;******************************************************************
  7506. ;
  7507. ;
  7508. ; Crank angle sensor
  7509. ;
  7510. ;
  7511. ;******************************************************************
  7512. test_cas ldaa T40_engRot ;
  7513. bne L1530 ; Branch if sensor is fine. T40_engRot is non-zero when CAS interrupts are being received... sensor must be fine...
  7514. brset port3Snap0, #$40, L1531 ; Branch if key is not in start
  7515. decb ; Key is in start but T40_engRot is 0, should not happen -> CAS is bad
  7516. L1530 rts ;
  7517. L1531 incb ; return 1 (test not conclusive)
  7518. rts
  7519.  
  7520.  
  7521.  
  7522. ;******************************************************************
  7523. ;
  7524. ;
  7525. ; Top dead sensor
  7526. ;
  7527. ;
  7528. ;******************************************************************
  7529. test_tdc ldaa T40_engRot ;
  7530. beq L1535 ; Branch if timer is 0, (engine not rotating)
  7531. ldaa tdcCheck ; Engine rotating, check if #1 TDC signal is being received
  7532. beq L1533 ; Branch to error if #1 TDC signal is not being received
  7533. ldaa tdcCasCount ;
  7534. cmpa #$04 ;
  7535. bcc L1534 ; Branch if tdcCasCount>=4
  7536. brclr port3, #$40, L1535 ; tdcCasCount<4, branch if key is in start
  7537. L1533 decb ; Set error
  7538. L1534 rts ;
  7539. L1535 incb ; return 1 (test not conclusive)
  7540. rts ;
  7541.  
  7542.  
  7543.  
  7544. ;******************************************************************
  7545. ;
  7546. ;
  7547. ; Reed switch (VSS) sensor check:
  7548. ;
  7549. ;
  7550. ;******************************************************************
  7551. test_reed ldaa vssCnt1
  7552. bne L1537 ; branch if car is moving (no error since we detected that...)
  7553. brset state1, #$02, L1538 ; Branch if no pulse accumulator interrupts?
  7554. brset port3Snap0, #$80, L1538 ; Branch if Idle switch on (car most likely not moving...)
  7555. ldaa rpm31 ;
  7556. cmpa #$60 ;
  7557. bls L1538 ;
  7558. ldaa airVol ;
  7559. cmpa #$6d ;
  7560. bls L1538 ;
  7561. brset state3, #$04, L1538 ; Branch if rev limiter active
  7562. ldaa T2_stCrank ;
  7563. adda #$78 ;
  7564. bcs L1538 ;
  7565. decb ;
  7566. L1537 rts ;
  7567. L1538 incb ; return 1 (test not conclusive)
  7568. rts ;
  7569.  
  7570.  
  7571.  
  7572. ;******************************************************************
  7573. ;
  7574. ;
  7575. ; Injector circuit check
  7576. ;
  7577. ;
  7578. ;******************************************************************
  7579. test_inj ldaa obdInjCmd ; First check if we disabled an injector on purpose (OBD command)
  7580. coma ;
  7581. bita #$3f ; only keep 6 bits (6 inj.)
  7582. bne L1541 ; Branch if disabled on purpose
  7583. ldaa T40_engRot ;
  7584. beq L1541 ; Branch if engine not rotating
  7585. ldaa rpm31 ;
  7586. cmpa #$20 ;
  7587. bcc L1541 ; Branch if rpm > 1000
  7588. ldaa tpsRaw ;
  7589. cmpa #$24 ;
  7590. bcc L1541 ; Branch if tpsRaw > $24
  7591. brclr injBad, #$01, L1540 ; Branch if injector OK?
  7592. decb ; Error, set flag
  7593. L1540 rts ;
  7594. L1541 incb ; return 1 (test not conclusive)
  7595. rts
  7596.  
  7597.  
  7598.  
  7599. ;******************************************************************
  7600. ;
  7601. ;
  7602. ; Fuel pump relay check
  7603. ;
  7604. ;
  7605. ;******************************************************************
  7606. test_fpump brclr port3Snap0, #$40, L1543 ; Branch if key in start position
  7607. brset port1, #$10, L1545 ; Branch if fuel pump relay bit set
  7608. L1543 brclr port4Snap, #$40, L1544 ; Fuel pump driven feedback???
  7609. decb
  7610. L1544 rts
  7611. L1545 incb ; return 1 (test not conclusive)
  7612. rts
  7613.  
  7614.  
  7615.  
  7616. ;******************************************************************
  7617. ;
  7618. ;
  7619. ; Ignition coil check:
  7620. ;
  7621. ;
  7622. ;******************************************************************
  7623. test_coil brset state1, #$11, L1548 ; Branch if notRotating or startingToCrank
  7624. ldaa rpm31 ;
  7625. cmpa #$a0 ;
  7626. bcc L1548 ; Branch if RPM >= 5000
  7627. brclr coilChkFlags, #$80, L1547 ; Branch if no error found on ignition signal
  7628. decb ; Error was found
  7629. L1547 rts ;
  7630. L1548 incb ; return 1 (test not conclusive)
  7631. rts
  7632.  
  7633.  
  7634.  
  7635. ;******************************************************************
  7636. ;
  7637. ;
  7638. ; Knock sensor check:
  7639. ;
  7640. ;
  7641. ;******************************************************************
  7642. test_knock brset port4Snap, #$20, L1550 ; Knock sensor related???
  7643. decb
  7644. L1550 rts
  7645.  
  7646.  
  7647.  
  7648. ;******************************************************************
  7649. ;
  7650. ;
  7651. ; Intake air temperature sensor check:
  7652. ;
  7653. ;
  7654. ;******************************************************************
  7655. test_iat brclr state2, #$02, L1552
  7656. decb
  7657. L1552 rts
  7658.  
  7659.  
  7660.  
  7661. ;******************************************************************
  7662. ;
  7663. ;
  7664. ; Tps sensor check:
  7665. ;
  7666. ;
  7667. ;******************************************************************
  7668. test_tps ldaa tpsRaw
  7669. cmpa #$66
  7670. bhi L1554 ; branch if tpsRaw voltage higher 40%
  7671. cmpa #$0a ;
  7672. bcs L1555 ; branch if voltage lower than 4%
  7673. rts ;
  7674. L1554 brclr port3Snap0, #$80, L1556 ; branch if idle switch is off
  7675. L1555 decb ;
  7676. L1556 rts ;
  7677.  
  7678.  
  7679.  
  7680. ;******************************************************************
  7681. ;
  7682. ;
  7683. ; Ect sensor check:
  7684. ;
  7685. ;
  7686. ;******************************************************************
  7687. test_ect brset state2, #$10, L1563 ; Branch if flag was previously set when we were here (once in error always in error????)
  7688. brclr state2, #$01, L1558 ; Branch if no ect error flag set in main code
  7689. ldaa T2_stCrank ; ect error flag is set in main code, check timer
  7690. adda #$78 ;
  7691. bcc L1562 ; Branch if more than 60sec have elapsed since engine startedToCrank (should have cleared by now?, sensor is in error)
  7692. L1558 brset state1, #$10, L1560 ; Branch if notRotating (not conclusive)
  7693. ldaa T0p5_ect ;
  7694. beq L1563 ; Branch if temperature stayed at exactly 88degC for more than 5 minutes (????)
  7695. ldaa T0p5_crank2 ;
  7696. adda #$5a ;
  7697. bcs L1559 ; Branch if less than 180s have elapsed since ectStCrank was loaded
  7698.  
  7699. ;----------------------------------------------------------
  7700. ; More than 180s have elapsed since ectStCrank was loaded
  7701. ;----------------------------------------------------------
  7702. ldaa ectStCrank ;
  7703. cmpa #$ff ; Not sure how we would get that value, maybe if sensor is broken??
  7704. bcs L1559 ; Branch if ectStCrank < $ff (branch almost always???????)
  7705. suba #$0a ; a=ectStCrank-$0a = $ff-$0a = $f5, am I missing someting??????????????
  7706. cmpa ectFiltered ;
  7707. bcs L1562 ; Branch if ectFiltered > $f5 ?????? (sensor error)
  7708. L1559 ldaa ectFiltered ;
  7709. cmpa #$54 ; 41degC
  7710. bcs L1561 ; Branch if temperature(ectFiltered) > 41degC (no error)
  7711. L1560 incb ; return 1 (test not conclusive)
  7712. L1561 rts
  7713. L1562 ldaa T2_snsrChk
  7714. bne L1563
  7715. orm state2, #$10
  7716. L1563 decb
  7717. rts
  7718.  
  7719.  
  7720.  
  7721. ;******************************************************************
  7722. ;
  7723. ;
  7724. ; Barometer sensor check
  7725. ;
  7726. ;
  7727. ;******************************************************************
  7728. test_baro ldaa T40_baro ;
  7729. bne L1567 ;
  7730. ldaa baroRaw ;
  7731. cmpa #$e6 ;
  7732. bhi L1565 ;
  7733. cmpa #$0a ;
  7734. bcc L1566 ;
  7735. L1565 decb ;
  7736. L1566 rts ;
  7737. L1567 incb ; return 1 (test not conclusive)
  7738. rts
  7739.  
  7740.  
  7741.  
  7742. ;******************************************************************
  7743. ;
  7744. ;
  7745. ; Serial port interrupt subroutine
  7746. ;
  7747. ;
  7748. ;******************************************************************
  7749. serialRxInt ldd sci_scr ; A=sci_cr, B=sci_read
  7750. bita #$80 ; Check if something was received??/start of sequence to clear flag
  7751. beq L1570 ;
  7752. brset obdFlags, #$80, L1569 ; Branch if the code we received is the echo of the one we just sent
  7753. stab obdCode ;
  7754. orm obdFlags, #$40 ; Indicate new value available
  7755. bra L1570 ;
  7756. L1569 andm obdFlags, #$7f ; The code we received is the echo of what we sent, just drop it and reset flag
  7757. L1570 rti ;
  7758.  
  7759.  
  7760.  
  7761. ;******************************************************************
  7762. ;
  7763. ;
  7764. ;
  7765. ;
  7766. ;
  7767. ;******************************************************************
  7768. loadConfig ldx #t_strap1 ;
  7769. ldab port4 ;
  7770. nop ;
  7771. andb #$03 ; Keep only config resistor bits
  7772. aslb ;
  7773. abx ;
  7774. ldd $00,x ;
  7775. std config1 ;
  7776. rts ;
  7777.  
  7778.  
  7779.  
  7780. ;******************************************************************
  7781. ;
  7782. ;
  7783. ; Initialize a few things
  7784. ;
  7785. ;
  7786. ;******************************************************************
  7787. initFunc1 ldd #$7e16 ;
  7788. std p1_ddr ; Initialize port1 and port2 data direction registers
  7789. ldd #$0000 ;
  7790. std p3_ddr ; Initialize port3 and port4 data direction register (all inputs)
  7791. ldaa #$fe ;
  7792. staa p5_ddr ; Initialize port5 data direction register
  7793. clra ;
  7794. staa L000f ;
  7795. staa L0017 ;
  7796. andm port1, #$bf ; Reset ??????
  7797. ldaa #$00 ;
  7798. staa L0024 ;
  7799.  
  7800. ;-------------------------------------------------------
  7801. ; rti_freq is setting the real time interrupt frequency:
  7802. ; F=125000/(256-x)
  7803. ; x F
  7804. ; 0x64 1*801.28Hz
  7805. ; 0xb2 2*801.28Hz
  7806. ; 0xcc 3*801.28Hz
  7807. ; 0xd9 4*801.28Hz
  7808. ;-------------------------------------------------------
  7809. ldd #$4d64 ;
  7810. std rti_ctl
  7811. rts
  7812.  
  7813.  
  7814.  
  7815. ;******************************************************************
  7816. ;
  7817. ; Input: D = Tcas (period of cas interrupts in sec * 125000)
  7818. ; Output: freq = $EA600/D = 960000/D
  7819. ;
  7820. ; in the end, rpm = freq/8*31.25
  7821. ;
  7822. ; e.g. 1000RPM -> Tcas = 60/1000* 125000/2 = 3750
  7823. ; freq = 960000/3750 = 256
  7824. ; rpm = freq/8*31.25 = 1000 RPM
  7825. ;
  7826. ;******************************************************************
  7827. calcFreq std temp4 ;
  7828. ldd #$a600 ;
  7829. std temp2 ;
  7830. ldd #$000e ; numerator = D:temp2 = 000EA600
  7831. bra div3216 ; D = (#$000EA600)/([$5A $5B])
  7832.  
  7833.  
  7834.  
  7835. ;******************************************************************
  7836. ;
  7837. ;
  7838. ;
  7839. ;
  7840. ;******************************************************************
  7841. mul816_baro ldab baroFact
  7842.  
  7843. ;******************************************************************
  7844. ;
  7845. ;
  7846. ;
  7847. ;
  7848. ;******************************************************************
  7849. mul816_256 jsr mul816_128 ; D and [temp6:temp7] = b*[temp6:temp7]/128
  7850. jmp scale2m
  7851.  
  7852.  
  7853.  
  7854. ;******************************************************************
  7855. ;
  7856. ; Input
  7857. ; x = point to table1
  7858. ; y = point to table2
  7859. ;
  7860. ; Output
  7861. ; d = injMasComp * table1(rpm)/128 * table2(ect)/16 * baroFact/128
  7862. ;
  7863. ;******************************************************************
  7864. L1577 ldd injMasComp ; d = injMasComp
  7865. std temp6 ; temp6:temp7 = injMasComp
  7866. jsr interp16rpm ; b = table1(rpm)
  7867. jsr mul816_128 ; [temp6:temp7] = injMasComp * table1(rpm)/128
  7868. xgxy ; x points to table2
  7869. jsr interpEct ; b = table2(ect)
  7870. ldaa baroFact ; a = baroFact
  7871. mul ; d = table2(ect) * baroFact
  7872. jmp mul1616_2K ; d = 8* injMasComp * table1(rpm)/128 * table2(ect)/128 * baroFact/128
  7873.  
  7874.  
  7875.  
  7876. ;******************************************************************
  7877. ;
  7878. ; 8 bit by 16 bit multiplication
  7879. ;
  7880. ; Input
  7881. ; b: 8 bit value
  7882. ; [temp6:temp7]: 16 bit value, optionally in X if called from mul816b
  7883. ;
  7884. ; Output:
  7885. ; D and [temp1:temp2] = b*[temp6:temp7]/256
  7886. ; temp3 = Lo(b*temp7) (fractional part of result)
  7887. ;
  7888. ;
  7889. ;
  7890. ;******************************************************************
  7891. mul816 ldx temp6 ;
  7892. mul816b stx temp1 ; temp1,temp2 = temp6,temp7
  7893. pshb ; save b
  7894. ldaa temp2 ; a = temp7
  7895. mul ; d = b*temp7
  7896. std temp2 ; temp2, temp3 = b*temp7
  7897. ldaa temp1 ; a=temp6
  7898. pulb ;
  7899. mul ; d = b*temp6
  7900. addb temp2 ; d = b*temp6 + b*temp7/256 = b*(temp6+temp7/256) = b*[temp6:temp7]/256
  7901. adca #$00 ; Propagate addition carry
  7902. std temp1 ; temp1, temp2 = b*[temp6:temp7]/256
  7903. rts ;
  7904.  
  7905.  
  7906.  
  7907. ;******************************************************************
  7908. ;
  7909. ;
  7910. ; 16 bit by 16 bit multiplication:
  7911. ;
  7912. ; Input:
  7913. ; a:b = 16 bit value (val1:val2)
  7914. ; temp6:temp7 = 16 bit value1 (val3:val4)
  7915. ;
  7916. ; Output:
  7917. ; d = [a:b]*[temp6:temp7]/65536 (or equivalently, 16 upper bits of result)
  7918. ; temp2 = lower 8 bits (of 24) of results
  7919. ;----------------------------------------
  7920. ;
  7921. ; D * temp6:temp7
  7922. ; - 16 bit multiplication:
  7923. ; - D * temp6:temp7 , High bytes stored in D
  7924. ; -
  7925. ; - (1) * (2) is equal to ( 1A + 1B ) * ( 2A + 2B )
  7926. ;
  7927. ; - = 1A * 2A + 1A * 2B + 1B * 2A + 1B * 2B
  7928. ;
  7929. ; - Where:
  7930. ; - lets call temp6:temp7 Argument (1)
  7931. ; - lets call reg D Argument (2)
  7932. ; -
  7933. ; - temp6 is then named (1A)
  7934. ; - temp7 is then named (1B)
  7935. ; - and temp6:temp7 = (1A) * #$100 + (1B)
  7936. ; -
  7937. ; - Reg D is reg A:reg B
  7938. ; - A is then named (2A)
  7939. ; - B is then named (2B)
  7940. ; - temp6:temp7 = (1A) * #$100 + (1B)
  7941. ;
  7942. ; - D consists of (2A) * #$100 + (2B)
  7943. ;
  7944. ; -Result (R) will be 32 bit, (R3)-(R0) where
  7945. ; -temp3 = (R0) low
  7946. ; -temp2 = (R1)
  7947. ; -temp1 = (R2) --\ Stored and returned in D
  7948. ;
  7949. ;******************************************************************
  7950. mul1616 ldx #temp6 ; x points to temp6
  7951. psha ; st0 = val1
  7952. pshb ; st1 = val2
  7953. ldaa $01,x ; a = val4
  7954. mul ; d = val4*val2
  7955. std temp2 ; temp2:temp3=val4*val2
  7956. pulb ; b = val2
  7957. ldaa $00,x ; a = val3
  7958. mul ; d = val2*val3
  7959. addb temp2 ; d = val2*val3 + val4*val2/256
  7960. adca #$00 ; propagate carry
  7961. std temp1 ; temp1:temp2 = val2*val3 + val4*val2/256
  7962. pula ; a = val1
  7963. psha ; st0 = val1
  7964. ldab $01,x ; b = val4
  7965. mul ; d = val1*val4
  7966. addd temp1 ; d = val1*val4 + val2*val3 + val4*val2/256
  7967. std temp1 ; temp1:temp2 = val1*val4 + val2*val3 + val4*val2/256
  7968. pula ; a = val1
  7969. rorb ; shift in carry bit
  7970. andb #$80 ; keep only carry bit
  7971. pshb ; st0 = carry bit in position $80
  7972. ldab $00,x ; b=val3
  7973. mul ; d=val1*val3
  7974. xgdx ; x=val1*val3, d points to temp6
  7975. pulb ; b=carry bit in position $80
  7976. abx ; add 2 x carry bit (since shifted right previously)
  7977. abx ; x=val1*val3 + carry
  7978. ldab temp1 ; b = (val1*val4 + val2*val3 + val4*val2/256)/256
  7979. abx ; x = val1*val3 + carry + (val1*val4 + val2*val3 + val4*val2/256)/256
  7980. xgdx ; x points to temp6, d = val1*val3 + carry + (val1*val4 + val2*val3 + val4*val2/256)/256
  7981. rts ;
  7982.  
  7983.  
  7984.  
  7985. ;******************************************************************
  7986. ;
  7987. ;
  7988. ; fractional 32 bit by 16 bit division:
  7989. ; input: D:temp2:temp3 = 32 bit numerator;
  7990. ; temp4:temp5 = 16 bit denominator
  7991. ;
  7992. ; output: D = quotient
  7993. ; X = remainder
  7994. ;
  7995. ;******************************************************************
  7996. div3216 cmpd1 temp4 ;
  7997. bcs L1582 ; Branch if denominator > numerator (results<1)
  7998. ldd #$ffff ; denominator<=numerator, return .99998....
  7999. bra L1586 ;
  8000.  
  8001. L1582 ldy #$0010 ; Loop 16 times
  8002. ldx temp2
  8003. L1583 xgdx
  8004. asld
  8005. xgdx
  8006. rolb
  8007. rola
  8008. bcs L1584
  8009. cmpd1 temp4
  8010. bcs L1585
  8011. L1584 subd temp4
  8012. inx
  8013. L1585 decy
  8014. bne L1583
  8015. xgdx
  8016. L1586 rts
  8017.  
  8018.  
  8019.  
  8020. ;******************************************************************
  8021. ;
  8022. ;
  8023. ; 2D table lookup/interpolation
  8024. ;
  8025. ; Input:
  8026. ; temp6 = in1 (column index*16) (optionally in a if using 2Dlookup2)
  8027. ; temp7 = in2 (row index*16) (optionally in b if using 2Dlookup2)
  8028. ; hi(Y) = scale, number of elements per row in the table
  8029. ; lo(Y) = offset, added to value loaded from table before interpolation
  8030. ; X = 2Dtable address
  8031. ;
  8032. ; Output: A and B contain the same 2D interpolated value from the table
  8033. ;
  8034. ;
  8035. ;
  8036. ;******************************************************************
  8037. lookup2D ldd temp6 ; a=in1, b=in2
  8038. lookup2D2 sty temp3 ; temp3 = scale temp4=offset
  8039. staa temp5 ; temp5 = in1
  8040. clra ; a=0, b=in2
  8041. asld ;
  8042. asld ;
  8043. asld ;
  8044. asld ; d = in2*16
  8045. pshb ; st0 = LO(in2*16)
  8046. ldab temp3 ; b=scale
  8047. mul ; d = in2*16/256*scale
  8048. stx temp1 ; temp1:temp2 = 2Dtable
  8049. addd temp1 ; d = 2Dtable + in2*16/256*scale
  8050. std temp1 ; temp1:temp2 = 2Dtable + in2*16/256*scale
  8051. ldx temp1 ; X = 2Dtable + in2*16/256*scale, first row of interpolation
  8052. pshx ; st1:st2 = 2Dtable + in2*16/256*scale
  8053. ldab temp3 ; b=scale
  8054. abx ; X = 2Dtable + in2*16/256*scale + scale, go to next row of interpolation...
  8055. bsr L1589 ; Calculate interpolated value on second row, result in b
  8056. stab temp3 ; temp3 = interpolated value on second row
  8057. pulx ; x = 2Dtable + in2*16/256*scale (first row)
  8058. bsr L1589 ; Calculate interpolated value on first row, result in b
  8059. stab temp2 ; temp3 = interpolated value on first row
  8060. pula ; a = LO(in2*16)
  8061. ldx #temp2 ;
  8062. bra interpSpec ; Interpolate temp variables temp2 and temp3 using fractional part a=LO(in2*16) with no scaling on a and return to calling sub, result in b
  8063.  
  8064.  
  8065.  
  8066. ;******************************************************************
  8067. ;
  8068. ;
  8069. ; Used by lookup2D, interpolate on one row between two columns
  8070. ;
  8071. ;
  8072. ;******************************************************************
  8073. L1589 ldaa temp5 ; a = in1
  8074. clrb ; b=0
  8075. lsrd ;
  8076. lsrd ;
  8077. lsrd ;
  8078. lsrd ; d = in1*256/16 = in1*16
  8079. pshb ; st3 = LO(in1*16)
  8080. tab ; b=in1*16/256=in1/16
  8081. pula ; a=LO(in1*16)
  8082. abx ; X = startOfRow + in1/16
  8083. ldab $00,x ; b = val1, table lookup, get value in row
  8084. addb temp4 ; b = val1 + offset
  8085. stab temp1 ; temp1 = val1 + offset
  8086. ldab $01,x ; b = val2, next value in table on same row
  8087. addb temp4 ; b = val2 + offset
  8088. stab temp2 ; temp2 = val2 + offset
  8089. ldx #temp1 ; X points to temp variables
  8090. bra interpSpec ; Interpolate temp variables temp1 and temp2 using fractional part a=LO(in1*16) with no scaling on a and return to calling sub, result in b
  8091.  
  8092.  
  8093.  
  8094. ;******************************************************************
  8095. ;
  8096. ; Interpolate a table using ectCond, (ectCond is inv. proportional to temp)
  8097. ; This one compensate for non constant distance between the table points
  8098. ;
  8099. ; Used in the calculation of injPwStart
  8100. ; Input X = table
  8101. ;
  8102. ;
  8103. ;
  8104. ;******************************************************************
  8105. interpEct2 ldab ectCond ; b = ectCond (ect conditionned for table interp..)
  8106. cmpb #$c0 ; -7degC
  8107. bcs L1591 ; Branch if ectCond < $c0
  8108. clra ; a = 0, d = ectCond
  8109. asld ; d = 2*ectCond
  8110. subd #$00c0 ; d = 2*ectCond -$c0
  8111. jsr ovfCheck ;
  8112. L1591 tba ; a = 2*ectCond -$c0
  8113. bra interp32 ;
  8114.  
  8115.  
  8116.  
  8117. ;******************************************************************
  8118. ;
  8119. ;
  8120. ; Interpolate a table using ECT (ectCond is inv. proportional to temp)
  8121. ; Input X = table
  8122. ;
  8123. ;
  8124. ;******************************************************************
  8125. interpEct ldaa ectCond
  8126. bra interp32
  8127.  
  8128.  
  8129.  
  8130. ;******************************************************************
  8131. ;
  8132. ;
  8133. ;
  8134. ;
  8135. ;
  8136. ;******************************************************************
  8137. interp16rpm ldaa rpmIndex1
  8138. bra interp16b
  8139.  
  8140.  
  8141.  
  8142. ;******************************************************************
  8143. ;
  8144. ;
  8145. ; Interpolate table using Conditionned IAT (iatCond)
  8146. ;
  8147. ;
  8148. ;******************************************************************
  8149. iatCInterp ldaa iatCond
  8150. bra interp32
  8151.  
  8152.  
  8153.  
  8154. ;******************************************************************
  8155. ;
  8156. ;
  8157. ;
  8158. ;
  8159. ;
  8160. ;******************************************************************
  8161. interp16b clrb
  8162. bra interp16
  8163.  
  8164.  
  8165.  
  8166. ;******************************************************************
  8167. ;
  8168. ; Table lookup with fractional interpolation
  8169. ; input value = A
  8170. ; input table = X
  8171. ; output value in a and b is (interpolated table) = X(A/32)
  8172. ;
  8173. ;
  8174. ;******************************************************************
  8175. interp32 clrb ;
  8176. lsrd ;
  8177. interp16 lsrd ;
  8178. lsrd ;
  8179. lsrd ;
  8180. lsrd ; A=A/32, B = 5 LSB of A in upper part
  8181. interp1 pshb ; \
  8182. tab ; >transfer A to B, only 3 bits left
  8183. pula ; / At this point, B=integer part of input/32, A=fractional part
  8184. abx ; ADD B TO X: B = 0 to 7 (3 bits) (integer table lookup), X=V(0)
  8185.  
  8186. interpSpec tsta ;
  8187. beq L1601 ; Branch if a = 0 (no fractional interp)
  8188. ldab $01,x ; B=V(1)
  8189. subb $00,x ; B=V(1)-V(0)
  8190. bcc L1600 ; banch if V(1)-V(0) > 0
  8191. inx ; negative->X=V(1)
  8192. negb ;
  8193. nega ;
  8194. L1600 mul ; D=A*B (
  8195. aslb ; shift left B (... carry)
  8196. L1601 adca $00,x ; add to a with carry
  8197. tab
  8198. rts
  8199.  
  8200.  
  8201.  
  8202. ;******************************************************************
  8203. ;
  8204. ; Interpolate table an multiply result by [temp6:temp7]
  8205. ;
  8206. ;
  8207. ;
  8208. ;******************************************************************
  8209. interp32mul bsr interp32
  8210. ; continued below...
  8211.  
  8212.  
  8213.  
  8214. ;******************************************************************
  8215. ;
  8216. ; Multiply 8 bit by 16 bits, final result is scaled by 128,
  8217. ; rounded and checked for overflow
  8218. ;
  8219. ; input:
  8220. ; b: 8 bit value
  8221. ; [temp6:temp7]: 16 bit value
  8222. ;
  8223. ; output:
  8224. ; D and [temp6:temp7]: rounded 2*b*[temp6:temp7]/256 = b*[temp6:temp7]/128
  8225. ;
  8226. ;
  8227. ;******************************************************************
  8228. mul816_128 jsr mul816 ; D = b*[temp6:temp7]/256
  8229. asl temp3 ; Get lowest bit from fractional part
  8230. rolb ; Shift it in
  8231. rola ; shift it in, D = 2*b*[temp6:temp7]/256
  8232. bcs L1604 ; Branch if overflow
  8233. asl temp3 ; No overflow, Get second lowest bit from fractional part
  8234. adcb #$00 ; Add it to result (round-up result)
  8235. adca #$00 ; propagate
  8236. bcc L1605 ; Branch if no overflow
  8237. L1604 ldaa #$ff ; Overflow, return max value
  8238. L1605 std temp6 ; Store result
  8239. rts ;
  8240.  
  8241.  
  8242.  
  8243. ;******************************************************************
  8244. ;
  8245. ; Input:
  8246. ; D = 16 bit value1 (should be only 11 or 12 bits???)
  8247. ; temp6:temp7 = 16 bit value2
  8248. ;
  8249. ; Output:
  8250. ; D and [temp6:temp7] = rounded value1*value2/128 (a=$ff in case of overflow)
  8251. ; Optionally, divided by and additional 4 if mul1616_512 is used or 16 if mul1616_2K is used
  8252. ;
  8253. ;******************************************************************
  8254. mul1616_128 asld ;
  8255. asld ;
  8256. mul1616_512 asld ;
  8257. asld ; D = value1 * 16
  8258. mul1616_2K jsr mul1616 ; D = (value1 * 16 * value2)/65536 (upper 16 bits of mul1616)
  8259. ldx temp2 ; X = lower 16 bits of (value1 * 16 * value2)
  8260. xgdx ; D = lower 16 bits of (value1 * 16 * value2), X = (value1 * 16 * value2)/65536
  8261. ldab #$03 ; a = 3rd part of mul1616, b=3=number of loop to execute
  8262.  
  8263. ;--------------------------------------------
  8264. ; Loop 3 times to divide 24 bit result by 8
  8265. ;--------------------------------------------
  8266. L1609 xgdx ; Xhi = 3rd part of mul1616, Xlo = 3, D = (value1 * 16 * value2)/65536
  8267. lsrd ; D = (value1 * 16 * value2)/65536/2^n, carry = lower bit
  8268. xgdx ; X = (value1 * 16 * value2)/65536/2^n, a = 3rd part of mul1616/2^(n-1), b=3 on first loop
  8269. rora ; shift in carry, a = (3rd part of mul1616)/2^n, b=3 on first loop
  8270. decb ; b=b-1
  8271. bne L1609 ; loop
  8272.  
  8273. ;------------------------------------------------------------
  8274. ; Round-up and check for overflow in A
  8275. ; At this point, 24 bit result should have been
  8276. ; shifted down to fit only in 16 bits, upper 8 bit
  8277. ; should be 0, if not, b will be loaded with $ff in scale1m
  8278. ;------------------------------------------------------------
  8279. adca #$00 ; Round-up result 3rd part of result
  8280. psha ; st0 = lower 8 bit of result
  8281. xgdx ; D = (value1 * 16 * value2)/65536/8
  8282. bsr scale1m ; Propagate carry from 3rd part of result to D and check for overflow
  8283.  
  8284. ;-----------------------------------------------------------------------
  8285. ; At this point, we assume upper 8 bits=0 and only keep lower 16 bits
  8286. ;-----------------------------------------------------------------------
  8287. tba ; a = 2nd part of 24 bit result
  8288. pulb ; b = lower 8 bit of 24 bit result, in short, D=(value1 * 16 * value2)/256/8 = value1*value2/128
  8289. std temp6 ; temp6:temp7 = value1*value2/128
  8290. rts ;
  8291.  
  8292.  
  8293.  
  8294. ;******************************************************************
  8295. ;
  8296. ; Scaling function with rounding
  8297. ; Divide d by 128 or 64, etc.
  8298. ;
  8299. ;
  8300. ;
  8301. ;******************************************************************
  8302. scale128 lsrd ;
  8303. scale64 lsrd ;
  8304. lsrd ;
  8305. scale16 lsrd ;
  8306. scale8 lsrd ;
  8307. lsrd ;
  8308. lsrd ;
  8309. adcb #$00 ; Round-up by adding carry bit
  8310. adca #$00 ; propagate addition
  8311. rts ;
  8312.  
  8313.  
  8314.  
  8315. ;******************************************************************
  8316. ;
  8317. ; Input:
  8318. ; d = v1:v0
  8319. ;
  8320. ; Output:
  8321. ; a = v1 rounded up depending on v0, up to max of $ff
  8322. ;
  8323. ;
  8324. ;******************************************************************
  8325. round256 aslb ; Shift high bit of b in carry
  8326. adca #$00 ; roundup a
  8327. bcc L1615 ; branch if no overflow
  8328. deca ; Overflow, use max of $ff
  8329. L1615 rts ;
  8330.  
  8331.  
  8332.  
  8333. ;******************************************************************
  8334. ;
  8335. ;
  8336. ; Divide D by 128 or 64 or 32... in order for the value to fit
  8337. ; only in b (with a=0). If it does not fit (a<>0), b is loaded with
  8338. ; max value of $ff
  8339. ;
  8340. ;
  8341. ;
  8342. ;******************************************************************
  8343. scale128m lsrd
  8344. scale64m lsrd
  8345. lsrd
  8346. scale16m lsrd
  8347. scale8m lsrd
  8348. scale4m lsrd
  8349. scale2m lsrd ; D = D/128, carry contains last bit shifted out
  8350. scale1m adcb #$00 ; Add last bit shifted out (round-up number)
  8351. adca #$00 ; propagate addition of last bit
  8352. ovfCheck tsta
  8353. beq L1624 ; branch if A=0
  8354. ldab #$ff ; A is not 0, set fractional part to FF (the only one returned...)
  8355. L1624 rts
  8356.  
  8357.  
  8358.  
  8359. ;******************************************************************
  8360. ;
  8361. ;
  8362. ; Apply an offset and clip input, the result is usually used to
  8363. ; interpolate a table with a value of known range...
  8364. ;
  8365. ; in Xhi = max value
  8366. ; in Xlo = offset
  8367. ; in b = input value
  8368. ;
  8369. ; out b = max(min(b,Xhi)-Xlo,0)
  8370. ;
  8371. ;
  8372. ;******************************************************************
  8373. clipOffset stx temp1
  8374. cmpb temp1
  8375. bcs L1626
  8376. ldab temp1
  8377. L1626 subb temp2
  8378. bcc L1627
  8379. clrb
  8380. L1627 rts
  8381.  
  8382.  
  8383.  
  8384. ;******************************************************************
  8385. ;
  8386. ; This function is used to apply a piecewise linear transformation
  8387. ; to the input value, see L2052, L2053 and L2054. This can be seen
  8388. ; as calculating the index into a table where the spacing between
  8389. ; table entries is not constant (first three entries spaced by x,
  8390. ; next three spaced by 2x, etc...)
  8391. ;
  8392. ; Input:
  8393. ; a = val
  8394. ; b = 0 (ignored or cleared)
  8395. ; y = points to table with first two values being a max
  8396. ; and offset and the rest being triplets (addVal, nshift, compVal)
  8397. ; where compVal is monotonicaly increasing...
  8398. ;
  8399. ; Output:
  8400. ; a = (min(val,max) - offset + addVal)/2^(nshift-1)
  8401. ;
  8402. ; where max and offset are the first two values of the table
  8403. ; and where addVal and nShift are taken from the table according to val-offset
  8404. ;
  8405. ;******************************************************************
  8406. ;------------------------------------------------------
  8407. ; Apply max value of table, a = min(val,table[0])
  8408. ;------------------------------------------------------
  8409. pwiseLin cmpa $00,y ; Operation does ++y...I assume
  8410. bcs L1629 ; Branch if a < table[0]
  8411. decy ; --y, go back to 0
  8412. ldaa $00,y ; a=table[y++]
  8413. clrb ; b=0
  8414.  
  8415. ;----------------------------------------------------------
  8416. ; Subtract offset of table, a = val-table[1] = val-offset
  8417. ;----------------------------------------------------------
  8418. L1629 suba $00,y ; a = val-table[y++] = val-offset
  8419. bcc L1630 ; Branch if result positive
  8420. clra ; Result negative, d=0
  8421. clrb ; d=0
  8422.  
  8423. ;----------------------------------------------
  8424. ; Loop until we find compVal > a
  8425. ;----------------------------------------------
  8426. L1630 ldx $00,y ; x = table[y]:table[y+1]; y = y + 2
  8427. cmpa $00,y ; Operation does ++y...I assume
  8428. bcc L1630 ; Loop if a >= table[y]
  8429.  
  8430. ;--------------------------------------------------------------
  8431. ; Store the corresponding addVal and nshift in temp1 and temp2
  8432. ;--------------------------------------------------------------
  8433. stx temp1 ; temp1 = addVal;, temp2 = nshift
  8434.  
  8435. ;--------------------------------------------
  8436. ; Add addVal to a, a = val - offset + addVal
  8437. ;--------------------------------------------
  8438. adda temp1 ; a = a-offset+addVal
  8439.  
  8440. ;----------------------------------------------------------------
  8441. ; Apply nshift to a, a = (val - offset + addVal)/2^(nshift-1)
  8442. ;----------------------------------------------------------------
  8443. L1631 dec temp2 ; temp2=table[y+1]-1
  8444. beq L1632 ; Btanch if table[y+1]-1 =0
  8445. lsrd ; d = d/2
  8446. bra L1631 ; Loop
  8447. L1632 rts ;
  8448.  
  8449.  
  8450.  
  8451. ;******************************************************************
  8452. ;
  8453. ; Input:
  8454. ; y: point to piecewise linear transformation table
  8455. ;
  8456. ; Apply piecewise linear transformation to rpm4 and scale
  8457. ;
  8458. ;
  8459. ;******************************************************************
  8460. rpmPwise ldd rpm4 ;
  8461. asld ;
  8462. asld ; d = rpm4*4
  8463. bsr pwiseLin ;
  8464. bra scale16m ;
  8465.  
  8466.  
  8467.  
  8468. ;******************************************************************
  8469. ;
  8470. ;
  8471. ; Decrement value at X by 1 (min of 0) if Tclocks.0 (40Hz signal) is set
  8472. ;
  8473. ;
  8474. ;******************************************************************
  8475. decX40Hz ldab #$01
  8476. brclr Tclocks, #$01, L1637
  8477.  
  8478.  
  8479.  
  8480. ;******************************************************************
  8481. ;
  8482. ;
  8483. ; Decrement all values in a given table by 1, stop at min value 0
  8484. ; X points to table, b is number of elements
  8485. ;
  8486. ;
  8487. ;******************************************************************
  8488. decTable brclr $0000,x,#$ff,L1636
  8489. dec $0000,x
  8490. L1636 inx
  8491. decb
  8492. bne decTable
  8493. L1637 rts
  8494.  
  8495.  
  8496.  
  8497. ;******************************************************************
  8498. ;
  8499. ; Lookup the given table using config2
  8500. ; lowest 2 bits as index to 16 bits values
  8501. ;
  8502. ; Input:
  8503. ; x: points to table
  8504. ;
  8505. ; Output:
  8506. ;
  8507. ; x(16 bits): table(2*(config2 & $03))
  8508. ;
  8509. ;******************************************************************
  8510. cfgLookup16 ldab config2 ; b = config2
  8511. andb #$03 ;
  8512. aslb ; b = 2*(config2 & $03)
  8513. abx ; x points to table(2*(config2 & $03))
  8514. ldx $00,x ; x = table(2*(config2 & $03))
  8515. rts ;
  8516.  
  8517.  
  8518.  
  8519. ;******************************************************************
  8520. ;
  8521. ; Read value from IO port (ADC) using a and b (d) as the values
  8522. ; to write to adc_ctl and adc_data respectively. a should be set
  8523. ; to the port number (0 to 7 as indicated below) with the start bit
  8524. ; set to 1 ($08)
  8525. ;
  8526. ; Port $00: ECT (engine coolant temp)
  8527. ; Port $01: IAT
  8528. ; Port $02: BARO
  8529. ; Port $03: O2
  8530. ; Port $04: EGRT
  8531. ; Port $05: BATT
  8532. ; Port $06: KNOCK count
  8533. ; Port $07: TPS
  8534. ;
  8535. ;
  8536. ;******************************************************************
  8537. readAdc1 sei ; set interrupt mask
  8538. readAdc2 std adc_ctl ; set port #
  8539. brn L1641 ; time delay
  8540. L1641 div airCntDef ; time delay
  8541. mul ; time delay
  8542. mul ; time delay
  8543. mul ; time delay
  8544. mul ; time delay
  8545. mul ; time delay
  8546. mul ; time delay
  8547. mul ; time delay
  8548. ldd adc_ctl ; get port value
  8549. rts
  8550.  
  8551.  
  8552.  
  8553. ;******************************************************************
  8554. ;
  8555. ;
  8556. ; input: rpm in b, maxRpm in a
  8557. ; (note that airVol is also used instead of rpm in
  8558. ; calling this function)
  8559. ;
  8560. ; output: b = min(max(rpm-$10,0), maxRpm) $10->500rpm
  8561. ;
  8562. ;******************************************************************
  8563. rpmRange subb #$10 ;
  8564. bcc abmin ; Branch if result positive
  8565. clrb ; Use min of 0
  8566.  
  8567. ;--------------------------------------------
  8568. ; Code below also called as a function
  8569. ; abmin -> b = minimum of a and b (can also
  8570. ; be seen as applying a max...)
  8571. ;--------------------------------------------
  8572. abmin cba ; compare (A-B)
  8573. bcc L1644 ; Branch if b<=maxRpm
  8574. tab ; b = maxRpm
  8575. L1644 rts ; return
  8576.  
  8577.  
  8578.  
  8579. ;******************************************************************
  8580. ;
  8581. ; Input:
  8582. ; None (a=airVol if called from L1647)
  8583. ;
  8584. ; Output: in b (same result in a):
  8585. ;
  8586. ; airVol[T]B < 60: airVol[T]B - $20
  8587. ; airVol[T]B >= 60: 0.668 * airVol[T]B
  8588. ;
  8589. ; The maximum of airVolTB or airVolB is used, see comments below
  8590. ;
  8591. ;----------------------------------------
  8592. ;
  8593. ; the ecu makes a temp value for the table lookup..
  8594. ; so if 0xe3 <= 96, value = 0xe3 - 32,
  8595. ; if 0xe3 > 96, value = 0xe3 * 2/3
  8596. ;
  8597. ;******************************************************************
  8598. getLoadForMaps
  8599. #ifdef extLoadRange
  8600. #ifdef extLoadRange2
  8601. ldaa L0054 ; a = airVol16/4
  8602. ldab baroFact ; b = baroFact
  8603. mul ; d = airVol16/4 * baroFact
  8604. jsr scale128m ; b = airVol16/4 * baroFact/128
  8605. ldaa iatCompFact ; a = iatCompFact
  8606. bpl test123 ; Branch if iatCompFact < $80
  8607. mul ; d = airVol16/4 * baroFact/128 * iatCompFact
  8608. jsr scale128m ; b = airVol16/4 * baroFact/128 * iatCompFact/128
  8609. test123 tba ; a = airVol16/4 * baroFact/128 [* iatCompFact/128]
  8610. #else
  8611. ldaa L0054 ; a = airVol16/4
  8612. bra L1647
  8613. nop
  8614. nop
  8615. nop
  8616. nop
  8617. nop
  8618. nop
  8619. nop
  8620. #endif
  8621. #else
  8622. ;-----------------------------------------------------
  8623. ; Decide on which value to use, airVolTB or airVolB
  8624. ;
  8625. ; Done this way, it correspond to taking the
  8626. ; highest of the two since:
  8627. ;
  8628. ; airVolTB = airVolB * iatCompFact/128
  8629. ;
  8630. ; if iatCompFact<128 -> max is airVolB
  8631. ; if iatCompFact>=128 -> max is airVolTB
  8632. ;
  8633. ; Since the load is used to interpolate the fuel map,
  8634. ; it is probably safer to use the maximum of the two
  8635. ; value, i.e. assume there is more air than less and
  8636. ; therefore risk of running too rich. The risk of using
  8637. ; only airVolTB is that if the temperature sensor is
  8638. ; heat soaked then it will report a higher temperature
  8639. ; than the actual temperature of the air getting in.
  8640. ; This means that airVolTB will report less air than
  8641. ; is actually getting in and there won't be enough
  8642. ; fuel injected -> we will run too lean...
  8643. ;-----------------------------------------------------
  8644. ldaa iatCompFact ; a=iatCompFact ($80=100%)
  8645. bpl L1646 ; Branch if iatCompFact<100%
  8646. ldaa airVolTB ; iatCompFact>=100%, a = airVolTB
  8647. bra L1647 ;
  8648. L1646 ldaa airVolB ; iatCompFact<100%, a = airVolB
  8649. #endif
  8650.  
  8651. ;-------------------------------------
  8652. ; Compute load index from air volume
  8653. ;-------------------------------------
  8654. L1647 tab ; a = b = airVol[T]B
  8655. subb #$60 ; b = airVol[T]B - $60
  8656. bcs L1648 ; branch if underflow (airVol[T]B <$60)
  8657. ldaa #$ab ; a = $ab
  8658. mul ; d = $ab * (airVol[T]B - $60)
  8659. aslb ; Shift higher bit of b in carry
  8660. adca #$00 ; Round-up a
  8661. adda #$60 ; a = rounded $ab * (airVol[T]B - $60)/256 + $60
  8662. L1648 suba #$20 ; a = a-20
  8663. bcc L1649 ; branch if no overflow
  8664. clra ; use min value
  8665. L1649 tab ; a = b = result
  8666. rts ;
  8667.  
  8668.  
  8669.  
  8670. ;******************************************************************
  8671. ;
  8672. ; Input: temp22:temp23 = v1:v0 (set to Tcas)
  8673. ;
  8674. ; Output
  8675. ; d = abs([temp22:temp23] - TcasLast0) - [temp22:temp23] * $30//256
  8676. ;
  8677. ;******************************************************************
  8678. L1650 ldaa temp22 ; a = v1
  8679. ldab #$30 ; b = $30
  8680. mul ; d = $30 * v1
  8681. xgdx ; x = $30 * v1
  8682. ldaa temp23 ; a = v0
  8683. ldab #$30 ; b = $30
  8684. mul ; d = $30 * v0
  8685. tab ; b = $30 * v0 /256
  8686. abx ; x = $30 * v1 + $30 * v0 /256 = $30*(v1+v0/256) = [temp22:temp23] * $30//256
  8687. stx temp20 ; temp20 = [temp22:temp23] * $30//256
  8688.  
  8689. ;---------------------------------------
  8690. ; Compute abs(temp22:temp23 - TcasLast0)
  8691. ;---------------------------------------
  8692. ldd temp22 ; d = temp22:temp23
  8693. subd TcasLast0 ; d = temp22:temp23 - TcasLast0
  8694. bcc L1651 ; Branch if result positive
  8695. coma ; Result negative, make it positive
  8696. comb ;
  8697. addd #$0001 ; two's complement...
  8698.  
  8699. ;----------------
  8700. ; Compute result
  8701. ;----------------
  8702. L1651 subd temp20 ; d = abs(temp22:temp23 - TcasLast0) - [temp22:temp23] * $30//256
  8703. rts ;
  8704.  
  8705.  
  8706.  
  8707. ;******************************************************************
  8708. ;
  8709. ;
  8710. ; Input capture interrupt 1
  8711. ;
  8712. ; Main CAS interrupt routine, triggered on both the rising
  8713. ; and falling edge of the CAS signal (edge detection polarity
  8714. ; is toggled in the code upon each interrupt)
  8715. ;
  8716. ;
  8717. ;******************************************************************
  8718. ;------------------------------------------------
  8719. ; Read t3_clock1 for later use and then
  8720. ; read t1_csr (not used so I assume it ackowledges
  8721. ; the interrupt ?)
  8722. ;------------------------------------------------
  8723. inCaptInt1 ldx t3_clock1 ; Get current coil clock value when the cas edge changed?
  8724. ldab t1_csr ; Acknowledge cas input capture interrupt?
  8725.  
  8726. ;--------------------------------------------------------
  8727. ; Update t1_lastCas for eventual aiflow calculation
  8728. ;--------------------------------------------------------
  8729. ldd t1_inCapt ; Get cas input timer capture high/low
  8730. std t1_lastCas ; store it here
  8731.  
  8732. ;------------------------------------------------
  8733. ; Update temp20 assuming interrupt is from t2
  8734. ; will be changed later if assumption was wrong
  8735. ;------------------------------------------------
  8736. ldd t3_clock2 ; Get current counter value
  8737. std temp20 ; temp20 = t3_clock2
  8738.  
  8739. ;-------------------------------------------
  8740. ; Branch to rising or falling edge section
  8741. ; depending on the interrupt source
  8742. ;-------------------------------------------
  8743. brclr t1_csr, #$02, casRiseProc ; Branch if this is the cas rising edge
  8744. jmp casFallProc ; Branch to cas failling edge section
  8745.  
  8746.  
  8747.  
  8748. ;******************************************************************
  8749. ;
  8750. ;
  8751. ; Section processing the CAS interrupt on the rising edge
  8752. ;
  8753. ;;
  8754. ;
  8755. ;******************************************************************
  8756. ;-------------------------------------------------------------------------
  8757. ; Check which of t3_clock1 or t3_clock2 should be used?
  8758. ; Not sure what that bit means???????????
  8759. ;-------------------------------------------------------------------------
  8760. casRiseProc brclr t3_csr0, #$10, L1654 ; Branch if we should use t3_clock2, nothing to do, that's what we assumed above
  8761.  
  8762. ;-------------------------------------------------------------------------
  8763. ; t3_clock1 should be used, our assumption that it was
  8764. ; t3_clock2 was wrong, update d and temp20 with the correct values
  8765. ;-------------------------------------------------------------------------
  8766. xgdx ; d = t3_clock1
  8767. std temp20 ; temp20 = t3_clock1
  8768.  
  8769. ;-------------------------------------------------------------
  8770. ; Branch to rest of code if the time between CAS
  8771. ; interrupts makes sense (rpm is not too high...)
  8772. ;
  8773. ; The time measured here is the time in-between cas
  8774. ; pulses since it is measured from the falling edge to the
  8775. ; rising edge. Since this time correspond to 110deg
  8776. ; then the 1ms below correspond to 360/110*1ms = 3.27ms
  8777. ; per rotation which correspond to 18333rpm. The threshold of
  8778. ; 1ms or 0.5 ms (18333 or 23333rpm) on the cas rising and falling
  8779. ; edge section is not the same and it might be due to the fact
  8780. ; that on the cas falling edge, we measure a smaller interval
  8781. ; (70deg instead of 110deg) and therefore the uncertainty is
  8782. ; higher???
  8783. ;-------------------------------------------------------------
  8784. L1654 subd casFallTime0 ; d = t3_clock1 - casFallTime0
  8785. cmpd #$00fa ; 1ms at 250KHz
  8786. bcc L1655 ; Branch if (t3_clock1 or t3_clock2 - casFallTime0) >= $00fa
  8787.  
  8788. ;------------------------------------------------
  8789. ; RPM seems too high to make sense, check if it is
  8790. ; not instead because RPM is so low that the 16 bit
  8791. ; counter subtraction above rolled-over.
  8792. ;
  8793. ; Branch to rest of code if the T200_casFall timer shows
  8794. ; that rpm is very low...
  8795. ;------------------------------------------------
  8796. ldaa T200_casFall ;
  8797. cmpa #$0e ; 70ms at 200Hz
  8798. bcs L1655 ; branch if T200_casFall<70ms, T200_casFall is init with 265ms, the time between interrupt is very high
  8799.  
  8800. ;-------------------------------------------------------------
  8801. ; Time between interrupts doesn't make sense, just ignore it
  8802. ; Return from interrupt
  8803. ;-------------------------------------------------------------
  8804. rti ;
  8805.  
  8806. ;---------------------------------------------------------------
  8807. ; Update temp22:temp23 = Tcas measured on the cas rising edge
  8808. ;---------------------------------------------------------------
  8809. L1655 ldd temp20 ; D = temp20
  8810. subd casRiseTime0 ; D = temp20-casRiseTime0(old counter) = Tcas = 250000/2/(rpm/60)
  8811. std temp22 ; temp22:temp23 = Tcas (temp22 is not dedicated for that purpose...)
  8812.  
  8813. ;--------------------------------
  8814. ; Validate temp22:temp23 = Tcas
  8815. ;--------------------------------
  8816. ldab T200_casRise ;
  8817. beq L1656 ; Branch if timer expired (very long Tcas...)
  8818. tsta ;
  8819. bmi L1657 ; Branch if Tcas/256 >= 128 (rpm<229)
  8820. cmpb #$0e ;
  8821. bhi L1657 ; Branch if T200_casRise > $0e (70ms)
  8822. L1656 ldd #$ffff ; Use max Tcas
  8823. std temp22 ; store Tcas
  8824.  
  8825. ;----------------------------------------------
  8826. ; Section to calculate new casFlags0 value but do
  8827. ; not store it now. It will be stored once the
  8828. ; interrupt is validated
  8829. ;----------------------------------------------
  8830. ;----------------------------------------------
  8831. ; First transfer some bits to "old" positions
  8832. ; and assume some bits will be set...
  8833. ;----------------------------------------------
  8834. L1657 ldaa casFlags0 ; a = casFlags0
  8835. anda #$05 ; a = casFlags0 & 00000101 (keep some old bits)
  8836. asla ; Move the old bits to the "old" positions
  8837. oraa #$35 ; preload some bits (00110101)
  8838.  
  8839. ;--------------------------------------------------
  8840. ; Set flag if timing adjustement mode is active
  8841. ;--------------------------------------------------
  8842. brclr timAdjFlags, #$80, L1658 ; Branch if we are not in timing adjustement mode
  8843. oraa #$40 ; a = (casFlags0 & 00001001)*2 | 01110101
  8844.  
  8845. ;-------------------------------------------------
  8846. ; Reset some new casFlags0 bits depending on rpm
  8847. ;-------------------------------------------------
  8848. L1658 ldx temp22 ; x = temp22:temp23 = Tcas
  8849. cpx #$061a ; 4801rpm
  8850. bcs L1662 ; Branch if rpm(Tcas) > 4801rpm
  8851. anda #$df ; Reset 00100000
  8852. cpx #$1081 ; 1775rpm
  8853. bcs L1659 ; Branch if rpm(Tcas) > 1775rpm
  8854. anda #$fb ; Reset 00000100
  8855. L1659 cpx #$1306 ; 1540rpm
  8856. bcs L1660 ; Branch if rpm(Tcas) > 1540rpm
  8857. anda #$ef ; reset 00010000
  8858.  
  8859. ;---------------------------------------
  8860. ; At this point rpm(Tcas) <= 4801rpm
  8861. ; Choose rpm threshold with hysteresis
  8862. ;---------------------------------------
  8863. L1660 ldab #$49 ; b = $49 (401rpm)
  8864. bita #$02 ;
  8865. bne L1661 ; Branch if bit was already set
  8866. ldab #$3a ; use lower threshold if bit alread set b = $3a (505rpm)
  8867.  
  8868. ;---------------------------------------------------------------------
  8869. ; Reset flag bit if we are above/below threshold, with hysteresis
  8870. ;---------------------------------------------------------------------
  8871. L1661 cmpb temp22 ;
  8872. bhi L1662 ; Branch if rpm(Tcas) < b (401rpm or 505rpm)
  8873. anda #$fe ; Reset 00000001
  8874.  
  8875. ;-----------------------------------------------------------
  8876. ; Store new value of casFlags0 in temp location for now
  8877. ;-----------------------------------------------------------
  8878. L1662 staa temp24 ; Store new casFlags0 in temp memory for now
  8879.  
  8880. ;--------------------------------------------------------------------
  8881. ; At this point, we will check the CAS signal to make sure it stays
  8882. ; set until 56us after the start of the interrupt. I guess this might
  8883. ; be to filter eventual glitches in the CAS signal
  8884. ;--------------------------------------------------------------------
  8885. ldd temp20 ;
  8886. addd #$000e ; d = StartInterruptTime + $0e (56us)
  8887. L1663 brclr port5, #$01, L1664 ; Branch as long as CAS bit is clear (CAS signal is set)
  8888. rti ; CAS bit was set, Bail of interrupt
  8889. L1664 cmpd1 t3_clock1 ; Compare current time to time stored when we started the interrupt processing
  8890. bpl L1663 ; Loop if t3_clock1 < (temp20 + $0e (56us)), i.e. if its been less than 56us since interrupt was called
  8891.  
  8892.  
  8893.  
  8894. ;******************************************************************
  8895. ;
  8896. ; Interrupt was valid
  8897. ; Proceed with processing stuff on the CAS rising edge
  8898. ;
  8899. ;
  8900. ;******************************************************************
  8901. ;------------------------------------------
  8902. ; Update p4Latched
  8903. ; (get our own copy of port4, we don't want
  8904. ; changes during processing)
  8905. ;------------------------------------------
  8906. ldaa port4 ;
  8907. staa p4Latched ;
  8908.  
  8909. ;-----------------------
  8910. ; Update casRiseTime0
  8911. ;-----------------------
  8912. ldd temp20 ; d = temp20
  8913. std casRiseTime0 ; casRiseTime0 = time at interrupt start
  8914.  
  8915. ;--------------------------------------
  8916. ; Finally store the new casFlags0 value
  8917. ; (we now know interrupt was valid...)
  8918. ;--------------------------------------
  8919. ldaa temp24 ;
  8920. staa casFlags0 ;
  8921.  
  8922. ;---------------------------------------------------------
  8923. ; Reset flag ignFallFlags.0
  8924. ;---------------------------------------------------------
  8925. andm ignFallFlags, #$fe ;
  8926.  
  8927. ;---------------------------------------------------------
  8928. ; restart T200_casRise timer to 175ms
  8929. ;---------------------------------------------------------
  8930. ldaa #$35 ; 175ms
  8931. staa T200_casRise ;
  8932.  
  8933. ;------------------------------------
  8934. ; Store current TDC state in temp24
  8935. ;------------------------------------
  8936. ldaa port3 ;
  8937. anda #$04 ; Keep only TDC bit
  8938. staa temp24 ; temp24.2 = TDC bit
  8939.  
  8940. ;-----------------------------------------------
  8941. ; Toggle tdcMask0:tdcMask1 (between $0402 and $0204)
  8942. ;-----------------------------------------------
  8943. ldd #$0402 ;
  8944. brset tdcMask0, #$02, L1665 ; Branch if old tdcMask0.1 is set
  8945. ldd #$0204 ;
  8946. L1665 std tdcMask0 ; Store new value
  8947.  
  8948. ;-----------------------------------------------------
  8949. ; Only execute the following section if the TDC signal
  8950. ; did not change. Why? we just stored it
  8951. ; a few lines earlier????? and if we really are on the
  8952. ; CAS rising edge then TDC cannot change at this time...
  8953. ;
  8954. ; Maybe this is some kind of safety/glitch/noise
  8955. ; safety precaution. TDC signal could get corrupted
  8956. ; when the engine is cranking, low battery...?
  8957. ;-----------------------------------------------------
  8958. ldaa temp24 ; a.2 = TDC bit, we just stored this value a few lines earlier, probability of it changing must be very low? I guess we MUST ensure temp24 is in synch with port3.2?????
  8959. eora port3 ; a.2 = oldTdcbit eor newTdcBit
  8960. anda #$04 ; Keep only TDC bit
  8961. bne L1671 ; branch if TDC bit changed, very low probability or even impossible if we really are on the CAS rising edge????
  8962.  
  8963. ;--------------------------------------------------------------
  8964. ; TDC bit did not change (normal case), execute the section
  8965. ;--------------------------------------------------------------
  8966. ;-----------------------
  8967. ; First check start key
  8968. ;-----------------------
  8969. brclr port3, #$40, L1668 ; Branch if key is in start position
  8970.  
  8971. ;----------------------------------------------------
  8972. ; Key is not in start
  8973. ; Increment tdcCasCount up to a max of 6
  8974. ;----------------------------------------------------
  8975. ldaa tdcCasCount ; a = old tdcCasCount
  8976. inc tdcCasCount ; tdcCasCount += 1
  8977. cmpa #$05 ;
  8978. bls L1666 ; branch if old tdcCasCount <=5 (new one is then <=6, no need to check max)
  8979. ldaa #$06 ; use max of 6
  8980. staa tdcCasCount ; store new value
  8981.  
  8982. ;----------------------------------------------------
  8983. ; Load b=$02 or $04 depending on TDC current value
  8984. ;----------------------------------------------------
  8985. L1666 ldab #$02 ; b = $02
  8986. brclr temp24, #$ff, L1667 ; Branch if TDC bit is 0 (TDC signal active)
  8987. ldab #$04 ; b = $04
  8988.  
  8989. ;------------------------------------------------------------
  8990. ; At this point b=$02 if TDC signal is active, $04 otherwise
  8991. ;------------------------------------------------------------
  8992. L1667 cmpb tdcMask0 ;
  8993. beq L1671 ; Branch if b = tdcMask0 (tdcMask0 is in synch with TDC???)
  8994.  
  8995. ;----------------------------------------------------
  8996. ; b != tdcMask0, we are out of synch, reinstate old
  8997. ; tdcCasCount and branch to re-init tdcMask0
  8998. ;----------------------------------------------------
  8999. deca ;
  9000. staa tdcCasCount ; tdcCasCount -= 1
  9001. cmpa #$03 ;
  9002. beq L1669 ; Branch if tdcCasCount=3
  9003. bpl L1671 ; Branch if tdcCasCount>3
  9004.  
  9005. ;-----------------------------------------------
  9006. ; Key in start or tdcCasCount<3, restart synch
  9007. ; from scratch, i.e. tdcCasCount=0
  9008. ;-----------------------------------------------
  9009. L1668 clra ;
  9010. staa tdcCasCount ; tdcCasCount = 0
  9011.  
  9012. ;------------------------------------------------------------------
  9013. ; Init tdcMask0 with $0204 if TDC is active $0402 otherwise
  9014. ;------------------------------------------------------------------
  9015. L1669 ldd #$0402 ;
  9016. brset temp24, #$ff, L1670 ; Branch if TDC bit is 1 (TDC signal inactive)
  9017. ldd #$0204 ;
  9018. L1670 std tdcMask0 ;
  9019.  
  9020. ;---------------------------------------------
  9021. ; Decide if we are going to calculate timing
  9022. ; or use fix timing of 5deg BTDC
  9023. ;---------------------------------------------
  9024. L1671 ldx #$002a ; x = $002a in case we have to bail to L1679
  9025. brclr tdcCasCount, #$fe, L1672 ; Branch if tdcCasCount = 0 or 1
  9026. brclr casFlags0, #$40, L1673 ; Branch if timing adjustment mode is not active
  9027.  
  9028. ;-----------------------------------------------------------------------
  9029. ; tdcCasCount = 0 or 1 or timing adjustment mode is active
  9030. ; Use default timing of 5 deg BTDC (or 4.75deg? close enough)
  9031. ;-----------------------------------------------------------------------
  9032. L1672 ldab #$a0 ; Use default value of tim61 = $a0 = 160 = 4.75deg BTDC (tech manual says 5deg BTDC)
  9033. bra L1679 ;
  9034.  
  9035. ;------------------------------------
  9036. ; tdcCasCount >= 2 and casFlags0.6 = 0
  9037. ; Reset knockSum if knockSum>43 ???
  9038. ;------------------------------------
  9039. L1673 ldab knockSum ;
  9040. cmpb #$2b ;
  9041. bls L1674 ; Branch if knockSum<= $2b (43)
  9042. clrb ;
  9043. stab knockSum ;
  9044.  
  9045. ;---------------------------------------------------------------
  9046. ; Compute the new target timing tim61Tot1
  9047. ;
  9048. ; tim61Tot1 = temp24 = min(knockSum+tim61Tot0, $bc)
  9049. ;
  9050. ; tim61Tot1 is therefore tim61Tot0 which is further retarded
  9051. ; by a number of degrees equal to knockSum. Maximum value is
  9052. ;
  9053. ; max = $bc = 188 = 256 * 66deg / 90
  9054. ;
  9055. ; which is +5deg ATDC since it is referenced to 61degBTDC
  9056. ;---------------------------------------------------------------
  9057. L1674 addb tim61Tot0 ; b = knockSum + tim61Tot0
  9058. bcs L1675 ; Branch if overflow
  9059. cmpb #$bc ; Check for max
  9060. bcs L1676 ; Branch if knockSum+tim61Tot0 < $bc
  9061. L1675 ldab #$bc ; Use max
  9062. L1676 stab temp24 ; temp24 = tim61Tot1 = min(knockSum+tim61Tot0, $bc)
  9063.  
  9064. ;-------------------------------------------------------------
  9065. ; Compute the new timing newTim61 we are going to apply
  9066. ;
  9067. ; We start with tim61Tot1 computed above but the code below
  9068. ; seem to limit the rate of change of the timing by 22.5
  9069. ; deg per iteration ($40).
  9070. ;-------------------------------------------------------------
  9071. ldd timCas0 ; d = timCas0:timCas1
  9072. subd #$002a ; d = timCas0:timCas1 - $002a
  9073. cmpb temp24 ;
  9074. bcc L1677 ; Branch if timCas0:timCas1 - $002a >= tim61Tot1
  9075.  
  9076. ;----------------------------------------------------
  9077. ; low(timCas0:timCas1 - $002a) < tim61Tot1
  9078. ;----------------------------------------------------
  9079. addb #$40 ; b = timCas0:timCas1 - $002a + $40
  9080. bcs L1678 ; Branch if overflow
  9081. cmpb temp24 ;
  9082. bcs L1679 ; Branch if timCas0:timCas1 - $002a + $40 < tim61Tot1
  9083. bra L1678 ; Use tim61Tot1
  9084.  
  9085. ;----------------------------------------------------
  9086. ; low(timCas0:timCas1 - $002a) >= min(knockSum+tim61Tot0, $bc)
  9087. ;----------------------------------------------------
  9088. L1677 subb #$40 ; b = timCas0:timCas1 - $002a - $40
  9089. bcs L1678 ; Branch if timCas0:timCas1 - $002a - $40 < 0
  9090. cmpb temp24 ;
  9091. bcc L1679 ; Branch if timCas0:timCas1 - $002a - $40 >= tim61Tot1
  9092.  
  9093. ;-------------------
  9094. ; Use tim61Tot1
  9095. ;-------------------
  9096. L1678 ldab temp24 ; Use tim61Tot1
  9097. ldx #$002a ; reload x = $002a (why, did not change)
  9098.  
  9099. ;-----------------------------------------------------------------------------------------------
  9100. ;
  9101. ; At this point x = $002a, b = newTim61
  9102. ;
  9103. ; Where newTim61 is tim61Tot1 with a limit on its
  9104. ; rate of change (21.5deg/iteration max):
  9105. ;
  9106. ; if oldtim61 >= tim61Tot1 if old timing is more retarded
  9107. ; if oldtim61 - $40 < 0 if oldtim61< 22.5deg (minimum allowed)
  9108. ; tim61Tot1 Use new value
  9109. ; else if oldtim61 - $40 >= 0 else if oldtim61 >= 22.5deg (minimum allowed)
  9110. ; max(oldtim61 - $40, tim61Tot1) Use the one with the least amount of change...
  9111. ;
  9112. ; else if oldtim61 < tim61Tot1 else if old timing is less retarded
  9113. ; if oldtim61 + $40 > 256 if oldtim61 > 67.5deg (max allowed)
  9114. ; tim61Tot1 Use new value
  9115. ; else if oldtim61 + $40 < 256 else if oldtim61 < 67.5deg (max allowed)
  9116. ; min(oldtim61 + $40, tim61Tot1) Use the one withe the least amount of change...
  9117. ;
  9118. ; where tim61Tot1 = min(knockSum+tim61Tot0, $bc)
  9119. ; oldtim61 = [timCas0:timCas1] - $002a
  9120. ;
  9121. ;-----------------------------------------------------------------------------------------------
  9122. ;----------------------------------------------------
  9123. ;
  9124. ; Update tim61 and [timCas0:timCas1]
  9125. ; timCas0:timCas1 = tim61 + $002a
  9126. ; = 256 * (61 - degAdv) / 90 + 42
  9127. ; = 256 * ((61 - degAdv) + 14.77) / 90
  9128. ; = 256 * (75.77 - degAdv) / 90
  9129. ;
  9130. ; Since each CAS pulse rising edge is at 75deg BTDC,
  9131. ; [timCas0:timCas1] is the timing referenced to
  9132. ; the CAS pulse rising edge
  9133. ;----------------------------------------------------
  9134. L1679 abx ; x = tim61 + $002a
  9135. stx timCas0 ; [timCas0:timCas1] = tim61 + $002a
  9136. stab tim61 ;
  9137.  
  9138. ;----------------------------------------------------------------------
  9139. ; Branch to re-init timing stuff if rpm<505 or key in start position
  9140. ;----------------------------------------------------------------------
  9141. brclr casFlags0, #$01, L1680 ; Branch to re-init timing stuff if rpm<505, with hysteresis
  9142. brclr port3, #$40, L1680 ; Branch to re-init timing stuff if key in start position
  9143.  
  9144. ;---------------------------------------------------
  9145. ; At this point rpm>505 and key is not is start
  9146. ;
  9147. ; branch to normal code if rpm>505rpm the previous time
  9148. ; else update TcasLast0 and re-init timing stuff
  9149. ;---------------------------------------------------
  9150. brset casFlags0, #$02, L1681 ; Branch to normal code if rpm>=505rpm the previous time
  9151. jsr L1650 ; d = abs(Tcas - TcasLast0) - Tcas * $30/256
  9152. bcc L1680 ; Branch to re-init timing stuff if abs(Tcas - TcasLast0) >= Tcas * $30//256, i.e. abs(Tcas - TcasLast0)/Tcas >= 18.75%
  9153. ldx temp22 ; abs(Tcas - TcasLast0)/Tcas < 18.75%
  9154. stx TcasLast0 ; Update TcasLast0
  9155. jmp L1710 ; Jump to re-init timing stuff
  9156.  
  9157. ;------------------------------
  9158. ; Jump to re-init timing stuff
  9159. ;------------------------------
  9160. L1680 jmp L1709
  9161.  
  9162. ;--------------------------------------------
  9163. ; Section to perform some additional Tcas
  9164. ; validation when rpm(Tcas) <= 4801rpm
  9165. ;--------------------------------------------
  9166. L1681 brclr casFlags0, #$20, L1682 ; Branch if rpm(Tcas) <= 4801rpm
  9167. jmp L1685 ; Bail to next section
  9168.  
  9169. ;---------------------------
  9170. ; rpm(Tcas) <= 4801rpm
  9171. ;---------------------------
  9172. ;---------------------------
  9173. ; Check rpm
  9174. ;---------------------------
  9175. L1682 ldaa temp22 ; a = Tcas/256
  9176. cmpa #$14 ; 1464rpm
  9177. bls L1683 ; Branch if rpm(Tcas) >= 1464rpm
  9178.  
  9179. ;----------------------------------------------------
  9180. ; rpm(Tcas) < 1464
  9181. ;----------------------------------------------------
  9182. ldx timCas0 ; x = timCas0
  9183. cpx #$00ca ;
  9184. bhi L1683 ; branch if timCas0 > $ca (4deg BTDC)
  9185. jsr L1650 ; d = abs(Tcas - TcasLast0) - Tcas * $30/256
  9186. bcs L1683 ; Branch if result was negative
  9187. jmp L1709 ;
  9188.  
  9189. ;----------------------------------------------------
  9190. ; timCas0 > $ca (4deg BTDC)
  9191. ; or abs(Tcas - TcasLast0) - Tcas * $30/256 < 0
  9192. ; or rpm(Tcas) >= 1464
  9193. ;----------------------------------------------------
  9194. L1683 ldd temp22 ; d = Tcas
  9195. cmpa #$19 ; 1171rpm
  9196. bcc L1685 ; Branch if rpm(Tcas) >= 1171rpm
  9197. lsrd ;
  9198. lsrd ;
  9199. lsrd ;
  9200. lsrd ;
  9201. lsrd ;
  9202. lsrd ; d = Tcas/64
  9203. std temp20 ; temp20 = Tcas/64
  9204.  
  9205. ldd TcasLast0 ; d = TcasLast0
  9206. subd temp22 ; d = TcasLast0 - Tcas
  9207. bcc L1684 ; Branch if result positive (rpm is increasing????)
  9208.  
  9209. ldd temp22 ;
  9210. subd TcasLast0 ; d =
  9211. subd temp20 ; d = Tcas - TcasLast0 - Tcas/64
  9212. bcs L1685 ; Branch if result negative
  9213.  
  9214. ;------------------------------------------------------------
  9215. ; d = Tcas - TcasLast0 - Tcas/64 >= 0
  9216. ; Multiply result d = v1:v0 by $80/$80 = 1.0
  9217. ;
  9218. ; Maybe I miss something but this is useless. My guess
  9219. ; is that the multiplicative factor (1.0 in this case) was
  9220. ; configurable but in the end they chose 1.0 which renders this
  9221. ; code useless???
  9222. ;
  9223. ;------------------------------------------------------------
  9224. stab temp24 ; save b
  9225. ldab #$80 ; b = $80
  9226. mul ; d = v1*$80
  9227. xgdx ; x = v1*$80
  9228. ldaa temp24 ; a = v0
  9229. ldab #$80 ; b = $80
  9230. mul ; d = v0 * $80
  9231. tab ; b = v0 * $80/256
  9232. abx ; x = v1*$80 + v0 * $80/256 = [v1:v0] * $80/256
  9233. xgdx ; d = $80/256 * (Tcas - TcasLast0 - Tcas/64)
  9234. asld ; d = $80/128 * (Tcas - TcasLast0 - Tcas/64) = Tcas - TcasLast0 - Tcas/64
  9235.  
  9236. ;---------------------------------------------------------------------------
  9237. ; Branch to re-init if Tcas + (Tcas - TcasLast0 - Tcas/64) > 32767
  9238. ; (TcasLast0 - Tcas - Tcas/64) > Tcas
  9239. ; (TcasLast0 - Tcas ) > Tcas(1+1/64)
  9240. ; (TcasLast0 - Tcas )/Tcas > 101.6%
  9241. ;
  9242. ; We are basically checking if Tcas increased by more than 101.6%
  9243. ;---------------------------------------------------------------------------
  9244. bcs L1687 ; Branch to re-init if overflow
  9245. addd temp22 ; d = Tcas + (Tcas - TcasLast0 - Tcas/64) = Tcas(2-1/64) - TcasLast0
  9246. bcs L1687 ; Branch to re-init if overflow
  9247. bra L1686 ; Branch to code continuation
  9248.  
  9249. ;----------------------------------------------------
  9250. ; (TcasLast0 - Tcas) > 0 (rpm is increasing),
  9251. ;
  9252. ; Check if
  9253. ; TcasLast0 - Tcas < Tcas/64
  9254. ; (TcasLast0 - Tcas)/Tcas < 1/64
  9255. ; (TcasLast0 - Tcas)/Tcas < 1.6%
  9256. ;
  9257. ; We are basically checking if Tcas changed by less than 1.6%
  9258. ; This also correspond to a change of rpm of 1.6%
  9259. ;----------------------------------------------------
  9260. L1684 subd temp20 ; d = TcasLast0 - Tcas - Tcas/64
  9261. bcs L1685 ; Branch if result negative, i.e. change in Tcas is less than 1/64
  9262.  
  9263. ;------------------------------------------------------------
  9264. ; At this point, rpm increased by more than 1.6%
  9265. ; and d = TcasLast0 - Tcas - Tcas/64 >= 0
  9266. ; Multiply result d = v1:v0 by $80/$80 = 1.0
  9267. ;
  9268. ; Maybe I miss something but this is useless. My guess
  9269. ; is that the multiplicative factor (1.0 in this case) was
  9270. ; configurable but in the end they chose 1.0 which renders this
  9271. ; code useless???
  9272. ;------------------------------------------------------------
  9273. stab temp24 ; temp24 = v0
  9274. ldab #$80 ; b = $80
  9275. mul ; d = $80 * v1
  9276. xgdx ; x = $80 * v1
  9277. ldaa temp24 ; a = v0
  9278. ldab #$80 ; b = $80
  9279. mul ; d = $80 * v0
  9280. tab ; b = $80/256 * v0
  9281. abx ; x = $80 * v1 + $80/256 * v0 = $80/256 * [v1:v0]
  9282. xgdx ; d = $80/256 * (TcasLast0 - Tcas - Tcas/64)
  9283. asld ; d = $80/128 * (TcasLast0 - Tcas - Tcas/64) = (TcasLast0 - Tcas - Tcas/64)
  9284.  
  9285. ;-----------------------------------------------------------------------------
  9286. ; Branch to re-init if Tcas - (TcasLast0 - Tcas - Tcas/64) < 0???
  9287. ; (TcasLast0 - Tcas - Tcas/64) > Tcas
  9288. ; (TcasLast0 - Tcas ) > Tcas(1+1/64)
  9289. ; (TcasLast0 - Tcas )/Tcas > 101.6%
  9290. ;
  9291. ; We are basically checking if Tcas increased by more than 101.6%
  9292. ;-----------------------------------------------------------------------------
  9293. bcs L1687 ; Branch to re-init if overflow
  9294. std temp20 ; temp20 = TcasLast0 - Tcas - Tcas/64
  9295. ldd temp22 ; d = Tcas
  9296. subd temp20 ; d = Tcas - (TcasLast0 - Tcas - Tcas/64) = Tcas(2+1/64) - TcasLast0
  9297. bcs L1687 ; Branch to re-init if Tcas increased by more than 101.6%
  9298. bra L1686 ; Branch to code continuation
  9299.  
  9300. ;----------------------------------------
  9301. ; Update TcasNew0:TcasNew1
  9302. ; Check if Tcas is within normal range
  9303. ; Branch to re-init if not
  9304. ;----------------------------------------
  9305. L1685 ldd temp22 ; d = Tcas
  9306. L1686 std TcasNew0 ; [TcasNew0:TcasNew1] = Tcas
  9307. bmi L1687 ; Branch if sign bit set, Tcas at max value, jump to re-init???
  9308. cmpd #$0146 ; Compare to min (max of 23006rpm??)
  9309. bcc L1688 ; Branch if d >= min (rpm < 23006rpm)
  9310. L1687 jmp L1709 ; rpm >= 23006rpm, jump to re-init
  9311.  
  9312. ;-------------------------------
  9313. ; Tcas is within normal range
  9314. ; Update TcasLast0
  9315. ;-------------------------------
  9316. L1688 ldd temp22 ;
  9317. std TcasLast0 ;
  9318.  
  9319. ;--------------------------------------------------------
  9320. ; Compute d = [TcasNew0:TcasNew1] * [timCas0:timCas1]/256
  9321. ; We assume timCas0 can only be 0 or 1
  9322. ; (Higher values are impossible, huge timing retard...)
  9323. ;--------------------------------------------------------
  9324. ldab timCas1 ;
  9325. ldaa TcasNew1 ;
  9326. mul ; d = timCas1 * TcasNew1
  9327. staa temp20 ;
  9328. ldaa timCas1 ;
  9329. ldab TcasNew0 ;
  9330. mul ; d = timCas1 * TcasNew0
  9331. addb temp20 ;
  9332. adca #$00 ; d = [TcasNew0:TcasNew1] * timCas1/256
  9333. brclr timCas0, #$ff, L1689 ; Branch if timCas0=0
  9334. addd TcasNew0 ; d = [TcasNew0:TcasNew1] * [timCas0:timCas1]/256
  9335.  
  9336. ;--------------------------------------------------------------------------------------
  9337. ; At this point d = [TcasNew0:TcasNew1] * [timCas0:timCas1]/256
  9338. ; Update ignRelTime0:ignRelTime1 (ignition timing measured in time instead of degrees)
  9339. ;
  9340. ; ignRelTime0:ignRelTime1 = [TcasNew0:TcasNew1]/2 * [timCas0:timCas1]/256 - $0012
  9341. ;
  9342. ; timCas0/256 is a ratio from 0 to 1 corresponding to 0 to 90deg, since Tcas
  9343. ; correspond to 180 deg, Tcas/2 * timsCas0/256 is equal to the "timing time" referenced
  9344. ; to 75 BTDC
  9345. ;
  9346. ; ignRelTime0:ignRelTime1 is therefore the ignition timing (in timer time)
  9347. ; referenced to 75BTDC and minus 72us
  9348. ;--------------------------------------------------------------------------------------
  9349. L1689 lsrd ; d = [TcasNew0:TcasNew1] * [timCas0:timCas1]/256/2
  9350. subd #$0012 ; d = [TcasNew0:TcasNew1] * [timCas0:timCas1]/256/2 - $0012
  9351. bcc L1690 ; Branch if no underflow
  9352. clra ; use min of 0
  9353. clrb ; use min of 0
  9354. L1690 std ignRelTime0 ; [ignRelTime0:ignRelTime1] = [TcasNew0:TcasNew1] * [timCas0:timCas1]/256/2 - $0012
  9355.  
  9356. ;----------------------------------------------------
  9357. ; Check if the current coil is already energized
  9358. ;----------------------------------------------------
  9359. ldaa port5 ;
  9360. anda tdcMask0 ; $02 or $04
  9361. beq L1698 ; Branch if coil is already energized
  9362.  
  9363. ;----------------------------------------------------------------------
  9364. ; Coil is not yet energized, section to calculate energization time
  9365. ; and schedule the energization...
  9366. ;----------------------------------------------------------------------
  9367. ;-----------------------------------------
  9368. ; Init enerFlags to $02 since we know we
  9369. ; are going to schedule energization
  9370. ;-----------------------------------------
  9371. ldaa #$02 ; a = $02
  9372. staa enerFlags ; enerFlags = $02
  9373.  
  9374. ;-----------------------------------------------------------------------------
  9375. ; If rpm(Tcas) > 1775rpm and previously rpm(Tcas) > 1775rpm
  9376. ; The we can use enerLenX0 (already calculated in previous iteration?)
  9377. ;-----------------------------------------------------------------------------
  9378. brclr casFlags0, #$04, L1691 ; Branch to compute energization time if rpm(Tcas) <= 1775rpm
  9379. ldd enerLenX0 ; d = [enerLenX0:enerLenX1]
  9380. brset casFlags0, #$08, L1695 ; Branch to use enerLenX0 if rpm(Tcas) > 1775rpm the previous time
  9381.  
  9382. ;--------------------------------------------------------------------------
  9383. ; rpm(Tcas) <= 1775rpm
  9384. ; or rpm(Tcas) > 1775rpm but previously rpm(Tcas) <= 1775rpm
  9385. ; We need to compute the energization time
  9386. ;
  9387. ; Check if we can use a short or long energization time??? not sure
  9388. ; why
  9389. ;--------------------------------------------------------------------------
  9390. L1691 ldd TcasNew0 ; d = TcasNew0
  9391. subd #$1130 ; d = TcasNew0 - $1130 (18ms????) (check for rollover???)
  9392. bcc L1692 ; Branch if no underflow
  9393.  
  9394. ;------------------------------------------------------------------
  9395. ; Underflow, use a shorter fixed value of d = 16*enerLen
  9396. ;------------------------------------------------------------------
  9397. ldaa enerLen ; a = enerLen
  9398. clrb ; d = enerLen*256
  9399. lsrd ;
  9400. lsrd ;
  9401. lsrd ;
  9402. lsrd ; d = enerLen*256/16 = 16*enerLen
  9403. bra L1695 ; Bail
  9404.  
  9405. ;----------------------------------------------------------------------------------------------
  9406. ; TcasNew0 >= $1130, i.e. rpm <= 1704rpm,
  9407. ;
  9408. ; Compute a longer energization time????
  9409. ;
  9410. ; d = 16*enerLen + TcasNew0/2 * (timCas0 - $00ca + $04)/256/2 + (TcasNew0 - $1130)/16
  9411. ; = 16*enerLen + TcasNew0/2 * (timCas0 - 71deg + 1.4deg)/256/2 + (TcasNew0 - $1130)/16
  9412. ;
  9413. ;----------------------------------------------------------------------------------------------
  9414. L1692 lsrd ;
  9415. lsrd ;
  9416. lsrd ;
  9417. lsrd ; d = (TcasNew0 - $1130)/16
  9418. std temp22 ; temp22 = (TcasNew0 - $1130)/16
  9419. ldd timCas0 ; d = timCas0
  9420. subd #$00ca ; d = timCas0 - $00ca (71deg)
  9421. bls L1694 ; Branch if timCas0 <= $00ca (71deg)
  9422. addb #$04 ; b = timCas0 - $00ca + $04
  9423. ldaa TcasNew0 ; a = TcasNew0/256
  9424. mul ; d = TcasNew0/256 * (timCas0 - $00ca + $04)
  9425. lsrd ;
  9426. lsrd ; d = TcasNew0/256/4 * (timCas0 - $00ca + $04)
  9427. tsta ;
  9428. beq L1693 ; Branch if a=0 (result <= $ff)
  9429. ldd #$0100 ; Use max of $0100
  9430. L1693 addd temp22 ; d = TcasNew0/256/4 * (timCas0 - $00ca + $04) + (TcasNew0 - $1130)/16
  9431. std temp22 ; temp22 = TcasNew0/256/4 * (timCas0 - $00ca + $04) + (TcasNew0 - $1130)/16
  9432. L1694 ldaa enerLen ; a = enerLen
  9433. clrb ; d = enerLen*256
  9434. lsrd ;
  9435. lsrd ;
  9436. lsrd ;
  9437. lsrd ; d = enerLen*256/16
  9438. addd temp22 ; d = enerLen*16 + (TcasNew0 - $1130)/16 + [TcasNew0/2 * (timCas0 - $00ca + $04)/256/2]
  9439. L1695 std temp22 ; temp22 = enerLen*16 + (TcasNew0 - $1130)/16 + [TcasNew0/2 * (timCas0 - $00ca + $04)/256/2]
  9440.  
  9441.  
  9442. ;---------------------------------------------------------------------------------------
  9443. ; At this point temp22 = energizationDuration contains the energization time, 3 cases:
  9444. ;
  9445. ; temp22 = 16*enerLen
  9446. ; or temp22 = 16*enerLen + (TcasNew0 - $1130)/16 + [if timing >71deg, TcasNew0/2 * (timCas0 - $00ca + $04)/256/2]
  9447. ; or temp22 = enerLenX0:enerLenX1
  9448. ;
  9449. ;
  9450. ; Compute temp22 = the absolute time (timer clock) at
  9451. ; which the coil needs to start being energized
  9452. ;---------------------------------------------------------------------------------------
  9453. ldd ignRelTime0 ;
  9454. subd temp22 ; d = ignRelTime0 - energizationDuration
  9455. addd casRiseTime0 ; d = casRiseTime0 + ignRelTime0 - energizationDuration
  9456. std temp22 ; temp22 = casRiseTime0 + ignRelTime0 - energizationDuration
  9457.  
  9458. ;---------------------------------------------------------------------
  9459. ; Check if the energization time of next coil is sufficientlty far
  9460. ; away from the preceeding coil ignition time. If not then use
  9461. ; an energization time as close as possible to that ignition time???
  9462. ;---------------------------------------------------------------------
  9463. ldd ignTime0 ; d = ignTime0:ignTime1
  9464. addd #$00fa ; d = ignTime0 + $fa (1ms)
  9465. cmpd1 temp22 ;
  9466. bmi L1696 ; Branch if ignTime0 + $fa < energization time, i.e. energization is sufficiently far away from the ignition of the preceeding cylinder, less than 1ms
  9467. std temp22 ; Replace energization time with ignTime0 + $fa
  9468.  
  9469. ;-----------------------------------------
  9470. ; Check that coil energization is
  9471. ; sufficiently in the future to be valid
  9472. ;-----------------------------------------
  9473. L1696 ldd t3_clock1 ; d = t3_clock1
  9474. addd #$000a ; d = t3_clock1 + $0a (40usec)
  9475. xgdx ; x = t3_clock1 + $0a
  9476. cpx temp22 ;
  9477. bpl L1697 ; Branch to use t3_clock1 + $0a if energization is "in the past"
  9478. ldx temp22 ; Energization time is valid, use it
  9479.  
  9480. ;---------------------------------------------------------------------------
  9481. ; Schedule coil energization interrupt time and update enerAbsTime0 with it
  9482. ;---------------------------------------------------------------------------
  9483. L1697 stx t3_outCmpWr ; Schedule interrupt time on first output compare register
  9484. ldaa t3_csr1 ; Go to next output compare register
  9485. stx t3_outCmpWr ; Schedule interrupt time on second output compare register
  9486. stx enerAbsTime0 ; Save energization interrupt time in memory
  9487.  
  9488. ;-------------------------------------------------------------------------
  9489. ; Reset the bit for the corresponding cylinder in control register
  9490. ; in order to energize the proper coil at the scheduled time
  9491. ;
  9492. ; Bits in t3_csr0 are offset by 1 bit compared to tdcMask0, so shift
  9493. ; tdcMask0 by 1 bit and then reset that bit in t3_csr0...
  9494. ;-------------------------------------------------------------------------
  9495. ldaa tdcMask0 ; a = $02 or $04
  9496. asla ; a = $04 or $08 (shift tdcMask0 bit by 1 to have the corresponding bit in t3_csr0)
  9497. coma ; a = ~($04 or $08)
  9498. anda t3_csr0 ; reset that bit in t3_csr0 (energize coil at scheduled time)
  9499. staa t3_csr0 ; Update t3_csr0
  9500. bra L1699 ; Bail to ignition section
  9501.  
  9502. ;---------------------------------------------------------
  9503. ; Coil is already energized
  9504. ;
  9505. ; Flush the first output compare register (write the
  9506. ; fartest possible time) since we don't need an interrupt
  9507. ; to energize it???. Also make sure enerFlags = 1 to indicate
  9508. ; coil is energized?
  9509. ;---------------------------------------------------------
  9510. L1698 ldx t3_clock1 ; x = t3_clock1
  9511. dex ; x = t3_clock1-1
  9512. stx t3_outCmpWr ; Re-init first output compare register with t3_clock1-1, the fartest time possible
  9513. ldaa #$01 ; a = 1
  9514. staa enerFlags ; enerFlags = 1
  9515.  
  9516. ;------------------
  9517. ; Ignition section
  9518. ;------------------
  9519. ;-------------------------------------------------------------------
  9520. ; Compute ignTime0 = absolute ignition time (referenced to timer clock)
  9521. ;-------------------------------------------------------------------
  9522. L1699 ldd ignRelTime0 ; d = ignRelTime0:ignRelTime1
  9523. addd casRiseTime0 ; d = ignRelTime0 + casRiseTime0
  9524. std ignTime0 ; ignTime0:ignTime1 = ignRelTime0:ignRelTime1 + casRiseTime0
  9525.  
  9526. ;-----------------------------------------------------------
  9527. ; Based on ignition timing, check if we are going to schedule
  9528. ; ignition at this time or wait for the cas falling edge???
  9529. ;-----------------------------------------------------------
  9530. ldx timCas0 ; x = timCas0:timCas1
  9531. cpx #$00ca ; (71deg, 4deg BTDC)
  9532. bcs L1701 ; Branch if timCas0:timCas1 < $00ca (71deg, 4deg BTDC)
  9533. brset casFlags0, #$40, L1700 ; Branch if timing adjustment mode is active
  9534. brset casFlags0, #$10, L1701 ; Branch if rpm(Tcas) > 1540rpm
  9535.  
  9536. ;--------------------------------------------------------------
  9537. ; timCas0:timCas1 >= $00ca (71deg, 4deg BTDC)
  9538. ; and timing adjustement mode is active or rpm(Tcas)<=1540rpm
  9539. ;
  9540. ; Set flag and wait for the cas falling edge
  9541. ;--------------------------------------------------------------
  9542. L1700 orm ignFallFlags, #$01 ; Set flag indicating we need to schedule ignition on the cas falling edge
  9543. bra L1703 ; Branch to continue
  9544.  
  9545. ;---------------------------------------------------------------------
  9546. ; At this point, enerFlags=1 if coil is energized or enerFlags=2
  9547. ; if energization has been scheduled. In the case where enerFlags=2
  9548. ; ignition will be scheduled in the output compare subroutine, i.e.
  9549. ; coilFunc, we therefore don't need to schedule it here. In the case
  9550. ; where enerFlags=1, we will now schedule ignition...
  9551. ;---------------------------------------------------------------------
  9552. L1701 ldaa enerFlags ; a = enerFlags
  9553. cmpa #$02 ;
  9554. beq L1703 ; Branch if enerFlags=2
  9555.  
  9556. ;------------------------------------------------------------
  9557. ; enerFlags=1, we will now schedule ignition
  9558. ; Make sure ignition time is sufficiently in
  9559. ; the future to be valid. If not, use ignition time of "now"
  9560. ;------------------------------------------------------------
  9561. ldd t3_clock1 ; d = t3_clock1
  9562. addd #$0006 ; d = t3_clock1 + $0006 (24usec)
  9563. xgdx ; x = t3_clock1 + $0006
  9564. cpx ignTime0 ;
  9565. bpl L1702 ; Branch to use t3_clock1 + $0006 if ignTime0 is "in the past"
  9566. ldx ignTime0 ; ignTime0 is valid, use it
  9567.  
  9568. ;--------------------------------------------------------
  9569. ; Schedule coil ignition time, set the proper coil bits
  9570. ; and update ignTime0 with the interrupt time used
  9571. ;--------------------------------------------------------
  9572. L1702 stx t3_outCmpWr ; Schedule interrupt time on first output compare register
  9573. ldaa t3_csr1 ; Go to next output compare register
  9574. stx t3_outCmpWr ; Schedule interrupt time on second output compare register
  9575. orm t3_csr0, #$0c ; Set both coil bits in t3_csr0, i.e. provoke ignition at scheduled time
  9576. stx ignTime0 ; Store actual value used
  9577.  
  9578. ;---------------------------------------------------------------------------------------
  9579. ; Common branching point for all code above (except re-init)
  9580. ;
  9581. ; Update enerAbsTimeNext0, The absolute coil energization time for the next cylinder???
  9582. ;---------------------------------------------------------------------------------------
  9583. L1703 ldd TcasNew0 ; d = TcasNew0:TcasNew1
  9584. subd enerLenX0 ; d = TcasNew0 - enerLenX0
  9585. addd ignRelTime0 ; d = TcasNew0 - enerLenX0 + ignRelTime0
  9586. addd casRiseTime0 ; d = TcasNew0 - enerLenX0 + ignRelTime0 + casRiseTime0
  9587. std enerAbsTimeNext0 ; enerAbsTimeNext0 = casRiseTime0 + TcasNew0 - enerLenX0 + ignRelTime0
  9588.  
  9589. ;------------------------------------------------------------------
  9590. ; Check enerAbsTimeNext0 to make sure it is not too close
  9591. ; to the current cylinder ignition time (1ms min between the two)
  9592. ;------------------------------------------------------------------
  9593. ldd ignTime0 ; d = ignTime0
  9594. addd #$00fa ; d = ignTime0 + $fa (1ms)
  9595. cmpd1 enerAbsTimeNext0 ;
  9596. bmi L1704 ; Branch if ignTime0 + $fa < enerAbsTimeNext0, energization time of next cylinder is far enough
  9597. std enerAbsTimeNext0 ; Energization of next cylinder is to close to ignition of current cylinder, use closest possible value, enerAbsTimeNext0 = ignTime0 + $fa
  9598.  
  9599. ;----------------------------------------------------------------------------
  9600. ; Section to update ignFallRelTime0, the ignition time relative to the cas falling edge
  9601. ; It will be non zero only if it makes sense to schedule ignition on the falling edge
  9602. ; i.e. timing >= 5degBTDC or timing adjustment mode is active, etc...
  9603. ;----------------------------------------------------------------------------
  9604. L1704 clra ; a = 0
  9605. clrb ; b = 0
  9606. std ignFallRelTime0 ; ignFallRelTime0 = 0, in case we don't update it below
  9607. ldd timCas0 ; d = timCas0
  9608. subd #$00c7 ; d = timCas0 - $00c7
  9609. bls L1708 ; Branch to use ignFallRelTime0=0 if timCas0 <= $00c7 (70deg, 5deg BTDC)
  9610. brclr casFlags0, #$40, L1705 ; Branch to compute ignFallRelTime0 if timing adjustment mode is not active
  9611. ldd #$0032 ; timing adjustment mode is active, use default of d = $0032 (ignFallRelTime0 = 200us, almost on the CAS falling edge, i.e. 5degBTDC)
  9612. bra L1707 ; Branch to update ignFallRelTime0
  9613.  
  9614. ;---------------------------------------------------------------------------------------------
  9615. ; Compute
  9616. ; [ignFallRelTime0:ignFallRelTime1] = [TcasNew0:TcasNew1]/2 * (timCas0 - $00c7)/256 - $12
  9617. ; = [TcasNew0:TcasNew1]/2 * (timCas0 - 70deg)/256 - $12
  9618. ;
  9619. ; [ignFallRelTime0:ignFallRelTime1] is the ignition time (timer clock)
  9620. ; relative to the CAS falling edge (-5 deg BTDC) minus 72us
  9621. ;
  9622. ; Imposed minimum value is 1 since ignFallRelTime0=0 indicate we should not use it...
  9623. ;---------------------------------------------------------------------------------------------
  9624. L1705 stab temp24 ; temp24 = timCas0 - $00c7
  9625. ldaa TcasNew1 ; a = TcasNew1
  9626. mul ; d = TcasNew1 * (timCas0 - $00c7)
  9627. ldab temp24 ; b = timCas0 - $00c7
  9628. staa temp24 ; temp24 = TcasNew1/256 * (timCas0 - $00c7)
  9629. ldaa TcasNew0 ; a = TcasNew0
  9630. mul ; d = TcasNew0 * (timCas0 - $00c7)
  9631. addb temp24 ; d = TcasNew0 * (timCas0 - $00c7) + TcasNew1/256 * (timCas0 - $00c7) = (timCas0 - $00c7) * (TcasNew0 + TcasNew1/256) = (timCas0 - $00c7)/256 * [TcasNew0:TcasNew1]
  9632. adca #$00 ; propagate carry
  9633. lsrd ; d = (timCas0 - $00c7)/256/2 * [TcasNew0:TcasNew1]
  9634. subd #$0012 ; d = (timCas0 - $00c7)/256/2 * [TcasNew0:TcasNew1] - $12
  9635. bcs L1706 ; Branch if underflow
  9636. bne L1707 ; Branch if not null
  9637. L1706 ldd #$0001 ; Null or underflow, use min of $0001
  9638. L1707 std ignFallRelTime0 ; ignFallRelTime0 = [TcasNew0:TcasNew1]/2 * (timCas0 - $00c7)/256 - $12
  9639. L1708 bra L1713 ; Branch to normal code continuation
  9640.  
  9641. ;--------------------------------------------------------------
  9642. ; Section to re-init timing stuff in case of detected problems
  9643. ; 2 different entry points, L1709 and L1710
  9644. ;--------------------------------------------------------------
  9645. ;----------------
  9646. ; Update TcasLast0
  9647. ;----------------
  9648. L1709 ldx temp22 ; get Tcas
  9649. stx TcasLast0 ; store Tcas in TcasLast0
  9650.  
  9651. ;---------------------------------------------------------
  9652. ; Init casFlags0 to 0 or 1 depending where we came from
  9653. ;---------------------------------------------------------
  9654. clra ; a = 1, rpm(Tcas)<505, no timing adjustment mode, etc
  9655. bra L1711 ;
  9656. L1710 ldaa #$01 ; a = 1, rpm(Tcas)>=505, no timing adjustment mode, etc.
  9657. L1711 staa casFlags0 ; casFlags0 = 0 or 1
  9658.  
  9659. ;-------------------------------------------
  9660. ; Flush both coil output compare registers,
  9661. ; i.e. write the fartest possible time
  9662. ;-------------------------------------------
  9663. ldx t3_clock1 ;
  9664. dex ; x = t3_clock1-1, the fartest possible time
  9665. stx t3_outCmpWr ; Flush first output compare register
  9666. ldaa t3_csr1 ; Go to next output compare register
  9667. stx t3_outCmpWr ; Flush second output compare register
  9668.  
  9669. ;----------------------------------
  9670. ; Reset the current coil bit to 0?
  9671. ;----------------------------------
  9672. ldaa tdcMask0 ; a = $02 or $04
  9673. asla ; a = $04 or $08
  9674. coma ; complement, a=~($04 or $08)
  9675. anda t3_csr0 ; Reset the coil bit to 0, energize coil at next interrupt
  9676. staa t3_csr0 ; Update t3_csr0
  9677.  
  9678. ;--------------------------------------------
  9679. ; Re-init control register/flush them???
  9680. ; Not sure what this means???
  9681. ;--------------------------------------------
  9682. ldaa #$09 ; a = $09
  9683. brset tdcMask0, #$02, L1712 ; branch if tdcMask0 is $02 (current TDC is for cylinder 1 or 4)
  9684. ldaa #$06 ; a = $06, current TDC is for 2 or 3
  9685. L1712 staa t3_csr1 ; t3_csr1 = $06 or $09 (00000110 or 00001001)
  9686. clra ; a = 0
  9687. staa t3_csr1 ; t3_csr1 = 0
  9688.  
  9689. ;--------------------------
  9690. ; Re-init timing variables
  9691. ;--------------------------
  9692. ldd TcasLast0 ; d = TcasLast0
  9693. std TcasNew0 ; TcasNew0:TcasNew1 = TcasLast0
  9694. clra ;
  9695. clrb ; d = 0
  9696. std ignFallRelTime0 ; ignFallRelTime0 = 0
  9697. ldx #$00ca ; 4deg BTDC
  9698. stx timCas0 ; timCas0 = 4deg BTDC
  9699. staa enerFlags ; enerFlags = 0
  9700. ldaa #$a0 ; 4.75deg BTDC
  9701. staa tim61 ; tim61 = 4.75deg BTDC
  9702.  
  9703. ;-----------------------
  9704. ; Normal flow continues
  9705. ;-----------------------
  9706. ;--------------------------------------------
  9707. ; Update TcasLast128 = TcasLast0/128
  9708. ;--------------------------------------------
  9709. L1713 ldd TcasLast0 ; d = TcasLast0
  9710. asld ; d = 2 * TcasLast0
  9711. bcc L1714 ; Branch if no overflow
  9712. ldaa #$ff ; use max of $ff
  9713. L1714 staa TcasLast128 ; TcasLast128 = 2 * TcasLast0/256 = TcasLast0/128
  9714.  
  9715. ;---------------------------------------
  9716. ; Re-init t3_csr0 and t1_csr mode bits
  9717. ; This also changes the cas edge detection
  9718. ; polarity for the next interrupt
  9719. ;---------------------------------------
  9720. ldaa t3_csr0 ; a = t3_csr0
  9721. anda #$0c ; Reset 1111 0011, reset all except bits corresponding to coil output
  9722. oraa #$52 ; Set 0101 0010, set normal control bits...
  9723. ldab t1_csr ; b = t1_csr
  9724. andb #$19 ; reset 1110 0110
  9725. orab #$02 ; set 0000 0010, cas edge detection polarity
  9726. ldx t1_inCapt ; x = t1_inCapt (clear input capture flag?)
  9727. staa t3_csr0 ; t3_csr0 = t3_csr0 & 0000 1100 | 0101 0010
  9728. stab t1_csr ; t1_csr = t1_csr & 0001 1001 | 0000 0010
  9729.  
  9730. ;--------------------------------------
  9731. ; Re-init timer T40s_casInt to 1.275sec
  9732. ;--------------------------------------
  9733. ldaa #$33 ; 1.275sec
  9734. staa T40s_casInt ; T40s_casInt = 1.275sec
  9735.  
  9736. ;----------------------
  9737. ; Update TcasOld
  9738. ;----------------------
  9739. ldd Tcas ; d = Tcas
  9740. std TcasOld ; TcasOld = Tcas
  9741.  
  9742. ;---------------------------------------------------
  9743. ; Compute new Tcas = 1/2 * [TcasLast0:TcasLast1]
  9744. ; and limit max value to $7fff (min rpm of 229rpm)
  9745. ;---------------------------------------------------
  9746. ldd TcasLast0 ; d = TcasLast0
  9747. lsrd ; d = TcasLast0/2
  9748. cmpa #$80 ;
  9749. bcs L1715 ; Branch if TcasLast0/2/256 < $80, i.e. TcasLast0/2 < $7fff?
  9750. ldd #$7fff ; Use max of $7fff (229rpm)
  9751. L1715 std Tcas ; store new Tcas for rpm calculation
  9752.  
  9753. ;----------------------------------------------------------
  9754. ; Update coilHist with input from the coil sensing circuit
  9755. ; coilHist basically contains the sensing circuit value
  9756. ; (0 or 1) for the last 8 interrupts, bit 7 being the
  9757. ; oldest and bit 0 the newest
  9758. ;----------------------------------------------------------
  9759. ldaa coilHist ; a = coilHist
  9760. asla ; a = 2*coilHist (shift existing bits left)
  9761. brclr p4Latched, #$04, L1716 ; Branch if CAS "clock" is clear?
  9762. inca ; a = 2*coilHist + 1 (set lower bit)
  9763. L1716 staa coilHist ; coilHist = updated CAS clock history
  9764.  
  9765. ;-------------------------------------------------------------
  9766. ; If "engine is running and rpm<5000 and 8V<=battRaw<=18V"
  9767. ; then check if coilHist lower 4 bits make sense, i.e. should
  9768. ; have changed on every CAS interrupt since we have ignition
  9769. ; just as often...
  9770. ;-------------------------------------------------------------
  9771. ldab #$20 ; preload b = $20 for eventual storage in coilChkCnt
  9772. brclr coilChkFlags, #$20, L1722 ; Bail if not "engine is running and rpm<5000 and 8V<=battRaw<=18V" (we don't perform the test, so reset timer as if no problem...)
  9773. anda #$0f ; a = coilHist & $0f
  9774. cmpa #$05 ;
  9775. beq L1717 ; Branch if coilHist & $0f = $05 (0000 0101)
  9776. cmpa #$0a ;
  9777. bne L1718 ; Branch if coilHist & $0f != $0a (0000 1010)
  9778.  
  9779. ;------------------------------------------------------------------
  9780. ; coilHist & $0f = $05 or $0a (0101 or 1010), this is the normal
  9781. ; alternating pattern of the check circuit, everything is therefore OK,
  9782. ; reset error bit and allow all 4 injectors to be used
  9783. ;------------------------------------------------------------------
  9784. L1717 andm coilChkFlags, #$7f ; Reset error flag
  9785. orm coilChkFlags, #$0f ; Set all 4 lower bits to 1, meaning all 4 injectors can be used
  9786. bra L1722 ; Bail
  9787.  
  9788. ;---------------------------------------------------------------
  9789. ; coilHist & $0f != $05 or $0a
  9790. ; That means some ignition signal were not properly generated.
  9791. ;
  9792. ; Investigate a little more the bit pattern and then decide
  9793. ; if we need to deactivate some injectors.
  9794. ; Did not attempt to understand this yet???
  9795. ;---------------------------------------------------------------
  9796. L1718 lsra ;
  9797. lsra ; a = (coilHist & $0f)/4
  9798. eora coilHist ; a = (coilHist & $0f)/4 eor coilHist
  9799. lsra ; shift lower bit in carry
  9800. bcc L1722 ; Branch if lower bit 0, no error to flag yet??
  9801. ldaa coilHist ; a = coilHist
  9802. lsra ; a = coilHist/2
  9803. eora coilHist ; a = coilHist/2 eor coilHist
  9804. lsra ; shift lower bit in carry
  9805. bcs L1720 ; Branch if lower bit 1, flag an error but dont deactivate injectors
  9806.  
  9807. ;--------------------------------------------------------------------------------
  9808. ; Select injectors that are OK to use depending on whether TDC is active or not
  9809. ;--------------------------------------------------------------------------------
  9810. ldab #$05 ; Set bits corresponding to injectors 1 and 4
  9811. brclr port3, #$04, L1719 ; Branch if TDC signal is active
  9812. ldab #$0a ; Set bits corresponding to injectors 3 and 2
  9813.  
  9814. ;------------------------------------------------------------
  9815. ; Update coilChkFlags with injectors that are ok to use
  9816. ;------------------------------------------------------------
  9817. L1719 ldaa coilChkFlags ; a = coilChkFlags
  9818. anda #$f0 ; reset 4 lower bits
  9819. aba ; Set the injectors that are OK to use in lower 4 bits
  9820. staa coilChkFlags ; Update coilChkFlags
  9821.  
  9822. ;---------------------------------------------------------
  9823. ; We have a missing ignition signal, decrement coilChkCnt
  9824. ; (min of 0) and set coilChkFlags.7 error flag if it reached 0
  9825. ; That would mean we missed $20 ignition signals...
  9826. ;---------------------------------------------------------
  9827. L1720 ldab coilChkCnt ; b = coilChkCnt
  9828. beq L1721 ; Branch if coilChkCnt=0
  9829. decb ;
  9830. bra L1722 ;
  9831. L1721 orm coilChkFlags, #$80 ; Set error flag
  9832.  
  9833. ;---------------------------------------------------
  9834. ; Store new coilChkCnt value, $20 loaded way above
  9835. ; or decremented value just calculated
  9836. ;---------------------------------------------------
  9837. L1722 stab coilChkCnt ;
  9838.  
  9839. ;----------------------------------------------------
  9840. ; Section to update knockSum from the knock sensor
  9841. ;----------------------------------------------------
  9842. ;-----------------------------------------------
  9843. ; Skip section (use knockSum = 0 ) if car has been
  9844. ; running less than 1 sec
  9845. ;-----------------------------------------------
  9846. brclr knockFlags, #$40, L1731 ; Branch to use knockSum = 0 if engine has been running less than 1 sec?
  9847.  
  9848. ;---------------------------------------
  9849. ; b = rawKnock value from the ADC port
  9850. ;---------------------------------------
  9851. ldaa #$0e ; A = knock port number 6 with start bit set = $06 | $08
  9852. jsr readAdc2 ; b = rawKnock from adc port
  9853.  
  9854. ;-----------------------------------------
  9855. ; Increment knockTimer up to max of 255
  9856. ;-----------------------------------------
  9857. ldaa knockTimer ; Read current counter value
  9858. inca ; increment some knock related counter
  9859. bne L1723 ; Branch if no overflow
  9860. ldaa #$ff ; overflow, use max
  9861. L1723 staa knockTimer ; store new counter value
  9862.  
  9863. ;--------------------------------------------------
  9864. ; Decide if we are going to use rawKnock directly
  9865. ;--------------------------------------------------
  9866. cmpb #$0c ;
  9867. bcs L1725 ; branch to use it if rawKnock < $0c
  9868. cmpb #$24 ;
  9869. bhi L1725 ; branch to use it if rawKnock > $24
  9870.  
  9871. ;----------------------------------------------------------------
  9872. ; $0c <= rawKnock <= $24, this is a zone where we don't count
  9873. ; rawKnock except if knockTimer > $78. knockTimer is however
  9874. ; reset to 0 which means it only applies to the first time
  9875. ; that happens. Basically, we ignore rawKnock when it is
  9876. ; between $0c and $24???
  9877. ;----------------------------------------------------------------
  9878. cmpa #$78 ;
  9879. bhi L1724 ; Branch if knockTimer > $78
  9880.  
  9881. ;--------------------------------------------
  9882. ; $0c <= rawKnock <= $24 and knockTimer<78
  9883. ;
  9884. ; Use rawKnock=0 and reset knockTimer
  9885. ;--------------------------------------------
  9886. clrb ; b = 0
  9887. L1724 clr knockTimer ; reset knockTimer
  9888.  
  9889. ;----------------------------------
  9890. ; Update knockSensor from rawKnock
  9891. ;----------------------------------
  9892. L1725 stab knockSensor ; knockSensor = rawKnock (processed port value)
  9893.  
  9894. ;----------------------------------
  9895. ; Compute a = (rawKnock-4)/8
  9896. ;----------------------------------
  9897. ldaa knockSensor ; a = rawKnock
  9898. suba #$04 ; rawKnock -= 4
  9899. bcc L1726 ; Branch rawKnock-4 >= 0
  9900. clra ; Use min of 0
  9901. L1726 lsra ;
  9902. lsra ;
  9903. lsra ; a = (rawKnock-4)/8
  9904.  
  9905. ;-------------------------------------------------
  9906. ; Compute a = (rawKnock-4)/8/2 if under low load
  9907. ;-------------------------------------------------
  9908. brset knockFlags, #$80, L1727 ; branch if airVol>$49 (high load)
  9909. lsra ; knock = knock/2 under low load
  9910. bra L1728 ;
  9911.  
  9912. ;-------------------------------------------------
  9913. ; Check for max value of 7 under high load?
  9914. ;-------------------------------------------------
  9915. L1727 cmpa #$07 ;
  9916. bcs L1728 ; branch if (rawKnock-4)/8 < 7
  9917. ldaa #$07 ; Use max of 7
  9918.  
  9919. ;-----------------------------------------------------------
  9920. ; Add min((rawKnock-4)/8,7) or (rawKnock-4)/8/2 to knockSum
  9921. ; and check for max of 43
  9922. ;-----------------------------------------------------------
  9923. L1728 adda knockSum ; a = knockSum + min((rawKnock-4)/8,7) or (rawKnock-4)/8/2
  9924. bcs L1729 ; Branch if overflow
  9925. cmpa #$2b ; No overflow, check for max of 43
  9926. bls L1730 ; Branch if new knockSum <=43
  9927. L1729 ldaa #$2b ; Use max of 43
  9928.  
  9929. ;-------------------------------------------------------
  9930. ; If knock sensor not working, use knockSum=$09 under
  9931. ; high load and knockSum=$00 under low load
  9932. ;-------------------------------------------------------
  9933. L1730 brclr state2, #$20, L1732 ; Branch if knock sensor working properly?
  9934. ldaa #$09 ; a = $09
  9935. brset knockFlags, #$80, L1732 ; Branch if airVol>$49
  9936. L1731 clra ;
  9937.  
  9938. ;-------------------------------------------------------------
  9939. ; Store new knockSum and reset knock sensor physical filter
  9940. ;-------------------------------------------------------------
  9941. L1732 staa knockSum ; Store new knock sum
  9942. orm port6, #$01 ; Reset knock sensor physical filter?
  9943.  
  9944.  
  9945. ;----------------------------------------------
  9946. ; Update maxAdv for E931 in order to slowly
  9947. ; remove its effect with time
  9948. ;----------------------------------------------
  9949. #ifdef E931
  9950. ldaa T_maxAdv ;
  9951. beq Mf078 ; Branch if timer T_maxAdv expired
  9952. deca ; Decrement timer
  9953. bne Mf081 ; Bail if not expired
  9954.  
  9955. ;---------------------------------------------------------
  9956. ; Timer expired increase maxAdv by 1 (increase
  9957. ; timing advance limit up to $80) and restart timer to 1
  9958. ;---------------------------------------------------------
  9959. Mf078 ldab maxAdv ;
  9960. bmi Mf081 ; Branch if maxAdv>=$80 (no limit to advance)
  9961. inc maxAdv ;
  9962. ldaa #$01 ; re-init timer t0 1 (we do it every loop)
  9963. Mf081 staa T_maxAdv ;
  9964. #endif
  9965.  
  9966. ;------------------------------------------
  9967. ; Set flag masCasFlags.1 indicating to the
  9968. ; main loop that it can update rpmX4Filt
  9969. ;------------------------------------------
  9970. orm masCasFlags, #$01 ;
  9971.  
  9972. ;---------------------------------------------------------------------
  9973. ; Section to update o2Fbk from o2 sensor during closed loop operation
  9974. ;---------------------------------------------------------------------
  9975. brclr state1, #$80, L1735 ; Bail if open loop mode
  9976. clra ; a = 0
  9977. ldab o2Raw ; b = o2Raw
  9978. cmpb #$1a ;
  9979. bcc L1733 ; branch if o2Raw >= 0.507V
  9980.  
  9981. ;-----------------------------------------
  9982. ; o2Raw < 0.507V (lean)
  9983. ; increase o2Fbk = o2Fbk + 8 * o2Fbk_inc
  9984. ;-----------------------------------------
  9985. ldab o2Fbk_inc ; d = o2Fbk_inc (a cleared earlier)
  9986. asld ;
  9987. asld ; d = 8 * o2Fbk_inc
  9988. addd o2Fbk ; d = 8 * o2Fbk_inc + o2Fbk
  9989. bcc L1734 ; Branch if no overflow
  9990. ldd #$ffff ; Use max of $ffff
  9991. bra L1734 ; Branch to store
  9992.  
  9993. ;-------------------------------------
  9994. ; o2Raw >= 0.507V (rich)
  9995. ; decrease o2Fbk = o2Fbk - 4 * o2Fbk_dec
  9996. ;-------------------------------------
  9997. L1733 ldab o2Fbk_dec ; d = o2Fbk_dec (a cleared earlier)
  9998. asld ;
  9999. asld ; d = 4 * o2Fbk_inc
  10000. std temp8 ;
  10001. ldd o2Fbk ;
  10002. subd temp8 ; d = o2Fbk - 4 * o2Fbk_dec
  10003. bcc L1734 ; Branch if no underflow
  10004. clra ;
  10005. clrb ; Underflow, use min of $0000
  10006.  
  10007. ;--------------
  10008. ; Update o2Fbk
  10009. ;--------------
  10010. L1734 std o2Fbk ; Store new o2Fbk
  10011.  
  10012. ;-------------------------------------
  10013. ; Return from interrupt
  10014. ;-------------------------------------
  10015. L1735 rti ;
  10016.  
  10017.  
  10018.  
  10019. ;******************************************************************
  10020. ;
  10021. ;
  10022. ; Section processing the CAS interrupt on the falling edge
  10023. ;
  10024. ;
  10025. ;******************************************************************
  10026. ;------------------------------------------------------------
  10027. ; Check which of t3_clock1 or t3_clock2 should be used?
  10028. ; Not sure what that bit means???????????
  10029. ;------------------------------------------------------------
  10030. casFallProc brset t3_csr0, #$10, L1737 ; Branch if we should use t3_clock2, nothing to do, that's what we assumed above (from where we jumped to casFallProc...)
  10031.  
  10032. ;-------------------------------------------------------------------------
  10033. ; t3_clock1 should be used, our assumption that it was
  10034. ; t3_clock2 was wrong, update d and temp20 with the correct values
  10035. ;-------------------------------------------------------------------------
  10036. xgdx ; d = t3_clock1
  10037. std temp20 ; temp20 = t3_clock1
  10038.  
  10039. ;------------------------------------------------
  10040. ; Branch to rest of code if the time between CAS
  10041. ; interrupts makes sense (rpm is not too high...)
  10042. ;
  10043. ; The time measured here is the cas pulse width
  10044. ; since it is measured from rising to falling edge
  10045. ; Since the cas pulse is 70deg then the 0.5ms below
  10046. ; correspond to 360/70*0.5ms = 2.57ms per rotation which
  10047. ; correspond to 23333rpm???
  10048. ;------------------------------------------------
  10049. L1737 subd casRiseTime0 ; d = (t3_clock1 or t3_clock2) - casRiseTime0
  10050. cmpd #$007d ; 0.5ms at 250KHz
  10051. bcc L1738 ; Branch if (t3_clock1 or t3_clock2 - casRiseTime0) >= $007d
  10052.  
  10053. ;------------------------------------------------
  10054. ; RPM seems too high to make sense, check if it is
  10055. ; not instead because RPM is so low that the 16 bit
  10056. ; counter subtraction above rolled-over.
  10057. ;
  10058. ; Branch to rest of code if the T200_casRise timer shows
  10059. ; that rpm is very low...
  10060. ;------------------------------------------------
  10061. ldaa T200_casRise
  10062. cmpa #$0e ; 70ms at 200Hz
  10063. bcs L1738 ; branch if T200_casRise<70ms, T200_casRise is init with 265ms, the time between interrupt is very high
  10064.  
  10065. ;-------------------------------------------------------------
  10066. ; Time between interrupts doesn't make sense, just ignore it
  10067. ; return from interrupt
  10068. ;-------------------------------------------------------------
  10069. rti
  10070.  
  10071. ;---------------------------------------------------------------
  10072. ; Update temp22:temp23 = Tcas measured on the cas falling edge
  10073. ;---------------------------------------------------------------
  10074. L1738 ldd temp20 ; d = temp20
  10075. subd casFallTime0 ; d = temp20-casFallTime0(old counter) = Tcas = 250000/2/(rpm/60)
  10076. std temp22 ; temp22:temp23 = Tcas (temp22 is not dedicated for that purpose...)
  10077.  
  10078. ;---------------------------------
  10079. ; Validate temp22:temp23 = Tcas
  10080. ;---------------------------------
  10081. ldab T200_casFall ;
  10082. beq L1739 ; Branch if timer expired (very long Tcas...)
  10083. tsta ;
  10084. bmi L1740 ; Bail if Tcas/256 >= 128 (rpm<229)
  10085. cmpb #$0e ;
  10086. bhi L1740 ; Branch if T200_casRise > $0e (70ms)
  10087. L1739 ldd #$ffff ; Use max Tcas
  10088. std temp22 ; store Tcas
  10089.  
  10090. ;--------------------------------------------------------------------
  10091. ; At this point, we will check the CAS signal to make sure it stays
  10092. ; reset until 56us after the start of the interrupt. I guess this might
  10093. ; be to filter eventual glitches in the CAS signal
  10094. ;--------------------------------------------------------------------
  10095. L1740 ldd temp20 ;
  10096. addd #$000e ; d = StartInterruptTime + $0e (56us)
  10097. L1741 brset port5, #$01, L1742 ; Branch as long as CAS bit is set (CAS signal is reset)
  10098. rti ; CAS bit was reset, Bail of interrupt
  10099. L1742 cmpd1 t3_clock1 ; Compare current time to time stored when we started the interrupt processing
  10100. bpl L1741 ; Loop if t3_clock1 < (temp20 + $0e (56us)), i.e. if its been less than 56us since interrupt was called
  10101.  
  10102.  
  10103.  
  10104.  
  10105. ;******************************************************************
  10106. ;
  10107. ;
  10108. ; Interrupt was valid
  10109. ; Proceed with processing stuff on the CAS falling edge
  10110. ;
  10111. ;
  10112. ;******************************************************************
  10113. ;---------------------------------------------------------
  10114. ; restart T200_casRise timer to 175ms
  10115. ;---------------------------------------------------------
  10116. ldaa #$35 ; 265ms
  10117. staa T200_casFall ; T200_casFall = 265ms
  10118.  
  10119. ;-----------------------
  10120. ; Update casFallTime0
  10121. ;-----------------------
  10122. ldd temp20 ;
  10123. std casFallTime0 ; casFallTime0 = temp20
  10124.  
  10125. ;---------------------------------------------------------------------
  10126. ; Branch to re-init if T40s_casInt expired or if Tcas/256 >= $80
  10127. ;
  10128. ; i.e. no cas rising edge interrupt received
  10129. ; in the last 1.275sec or rpm is very low
  10130. ;---------------------------------------------------------------------
  10131. brclr T40s_casInt, #$ff, L1743 ; Branch if T40s_casInt expired
  10132. ldaa temp22 ; a = Tcas/256
  10133. bpl L1744 ; Branch if a < $80
  10134.  
  10135. ;---------------------------------------------------------
  10136. ; T40s_casInt expired or Tcas/256 >= $80 (too big)
  10137. ; Re-init casFlags0, enerFlags and control registers
  10138. ; and jump over the entire ignition section
  10139. ;---------------------------------------------------------
  10140. L1743 clra ; a = 0
  10141. staa casFlags0 ; casFlags0 = 0
  10142. staa enerFlags ; enerFlags = 0
  10143. orm t3_csr0, #$0c ; set 0000 1100, disable both coils
  10144. orm t3_csr1, #$0a ; set 0000 1010, ???
  10145. andm t3_csr1, #$f0 ; reset 0000 1111 (reset the bit we just set...)
  10146. jmp L1765 ; Bail, jump over ignition section
  10147.  
  10148. ;---------------------------------------------------------
  10149. ; Section to process ignFallRelTime0 when it is non-null
  10150. ; Firs check just that...
  10151. ;---------------------------------------------------------
  10152. L1744 ldd ignFallRelTime0 ; d = ignFallRelTime0:ignFallRelTime1
  10153. bne L1745 ; Branch if ignFallRelTime0:ignFallRelTime1 != 0
  10154. jmp L1754 ; Bail since ignFallRelTime0=0
  10155.  
  10156. ;----------------------------------------------------------
  10157. ; At this point ignFallRelTime0 != 0
  10158. ; When ignFallRelTime0:ignFallRelTime1 is not 0, it
  10159. ; means we determined on the cas rising edge that ignition
  10160. ; would be scheduled on the cas falling edge, which we are in
  10161. ; now... But coil need to be energized first...
  10162. ;
  10163. ; Check if current coil is already energized
  10164. ;----------------------------------------------------------
  10165. L1745 ldaa port5 ; a = port5
  10166. anda tdcMask0 ; a = port5 & tdcMask0 ($02 or $04)
  10167. beq L1750 ; Branch if coil is energized
  10168.  
  10169. ;---------------------------------------------
  10170. ; Currrent coil is not yet energized
  10171. ;---------------------------------------------
  10172. ;----------------------------------------------------------------------------
  10173. ; Check if energization has been scheduled?, this would mean energization
  10174. ; will occur soon, or should have occured by now
  10175. ;----------------------------------------------------------------------------
  10176. brset enerFlags, #$02, L1746 ; Branch if enerFlags=2, energization was scheduled
  10177. jmp L1754 ; Bail, not sure what this would mean, probably that ignition already occured and there is nothing left to do??????
  10178.  
  10179. ;--------------------------------------------------------------
  10180. ; At this point
  10181. ; -Coil is not yet energized
  10182. ; -We determined on the cas rising edge that ignition would be
  10183. ; schedule on the cas falling edge (thats now...)
  10184. ; -enerFlags indicates energization was scheduled from
  10185. ; the cas rising edge and should already have occured
  10186. ; or will occur very soon??? Just reschedule energization...
  10187. ;--------------------------------------------------------------
  10188. ;----------------------------------------------------------------------------------
  10189. ; Compute enerAbsTime0:
  10190. ;
  10191. ; enerAbsTime0 = casFallTime0 + ignFallRelTime0 - enerLenX0 - TcasLast128
  10192. ;
  10193. ; enerAbsTime0 is the coil energization absolute time (timer clock)
  10194. ; (calculated from the CAS falling edge in this case)
  10195. ;----------------------------------------------------------------------------------
  10196. L1746 ldd ignFallRelTime0 ; d = ignFallRelTime0
  10197. subd enerLenX0 ; d = ignFallRelTime0 - enerLenX0
  10198. subb TcasLast128 ; d = ignFallRelTime0 - enerLenX0 - TcasLast128
  10199. sbca #$00 ; propagate carry
  10200. addd casFallTime0 ; d = ignFallRelTime0 - enerLenX0 - TcasLast128 + casFallTime0
  10201. std enerAbsTime0 ; enerAbsTime0 = casFallTime0 + ignFallRelTime0 - enerLenX0 - TcasLast128
  10202.  
  10203. ;---------------------------------------------------------------------------
  10204. ; Reset the proper coil bit in t3_csr0, i.e. energize coil at next interrupt
  10205. ;---------------------------------------------------------------------------
  10206. ldaa tdcMask0 ; a = $02 or $04
  10207. asla ; a = $04 or $08
  10208. coma ; a = ~($04 or $08)
  10209. anda t3_csr0 ; Reset that coil bit, i.e. have the coil energized the next time
  10210. staa t3_csr0 ; Update t3_csr0
  10211.  
  10212. ;------------------------------------------------------------------------------
  10213. ; Check if enerAbsTime0 that we just calculated is sufficiently in the future
  10214. ;------------------------------------------------------------------------------
  10215. ldd t3_clock1 ; d = t3_clock1
  10216. addd #$0006 ; d = t3_clock1 + $06 (24us)
  10217. xgdx ; x = t3_clock1 + $06
  10218. cpx enerAbsTime0 ;
  10219. bmi L1747 ; Branch to use enerAbsTime0 if it is sufficiently "in the future", i.e. t3_clock1 + $06 < enerAbsTime0
  10220.  
  10221. ;------------------------------------------------------------------------
  10222. ; enerAbsTime0 is not sufficiently in the future,
  10223. ;
  10224. ; schedule energization for "now", i.e. t3_clock1 + $06
  10225. ; this is 24usec (a few cycles) I assume the output compare will
  10226. ; therefore happen before we schedule the ignition later in the code
  10227. ; below... Note that only the first output compare register is updated.
  10228. ; Also update enerAbsTime0
  10229. ;
  10230. ; Update enerFlags = 1 to reflect the fact that coil is now energized.
  10231. ; It is not really but it will be in 24usec....
  10232. ;------------------------------------------------------------------------
  10233. stx enerAbsTime0 ; enerAbsTime0 = t3_clock1 + $06
  10234. stx t3_outCmpWr ; Schedule energization interrupt time on first output compare register
  10235. ldaa #$01 ;
  10236. staa enerFlags ; Make sure flag reflects the fact that coil is energized or will be very soon???
  10237. bra L1752 ; Branch to compute ignition time
  10238.  
  10239. ;-----------------------------------------------------
  10240. ; enerAbsTime0 is sufficiently in the future
  10241. ; Schedule regular coil energization interrupt time
  10242. ; and update enerAbsTime0 with it.
  10243. ;
  10244. ; Note that Ignition will be calculated below but scheduled
  10245. ; only when the output compare interrupt to energize the
  10246. ; coil actually happens (i.e. in coilFunc)
  10247. ;-----------------------------------------------------
  10248. L1747 ldx enerAbsTime0 ; x = enerAbsTime0
  10249. stx t3_outCmpWr ; Schedule interrupt time on first output compare register
  10250. ldaa t3_csr1 ; Go to next output compare register
  10251. stx t3_outCmpWr ; Schedule interrupt time on second output compare register
  10252.  
  10253. ;---------------------------------------------------------------------------
  10254. ; Branch to compute ignTime0
  10255. ; if we predicted we would schedule ignition on the CAS falling edge???
  10256. ;---------------------------------------------------------------------------
  10257. brset ignFallFlags, #$01, L1749 ; Branch if ignFallFlags = 1
  10258.  
  10259. ;-------------------------------------------------------------------
  10260. ; Flag is not set, do it anyway if
  10261. ;
  10262. ; abs(ignTime0 - casFallTime0 - ignFallRelTime0) >= TcasLast128
  10263. ; abs(compIgnFallRelTime - ignFallRelTime0) >= TcasLast128
  10264. ;
  10265. ; where compIgnFallRelTime = ignTime0 - casFallTime0 is the ignition
  10266. ; time relative to the cas falling edge but calculated from ignTime0...
  10267. ;
  10268. ; i.e. Do it anyway if they are more than 1.4deg apart??? Why not
  10269. ; just recompute it anyway instead of doing this lenghty
  10270. ; computation to check it, there must be a reason??? I guess
  10271. ; in most cases, it might be more acurate to use ignFallRelTime0
  10272. ; but in case it is too far apart from what makes sense at this time
  10273. ; then just use whatever makes sense at this time...
  10274. ;-------------------------------------------------------------------
  10275. ldd ignTime0 ; d = ignTime0
  10276. subd casFallTime0 ; d = ignTime0 - casFallTime0
  10277. subd ignFallRelTime0 ; d = ignTime0 - casFallTime0 - ignFallRelTime0
  10278. bcc L1748 ; Branch if no overflow
  10279. coma ; overflow, compute 2s complement
  10280. comb ;
  10281. addd #$0001 ; d = abs(ignTime0 - casFallTime0 - ignFallRelTime0)
  10282. L1748 tsta ;
  10283. bne L1749 ; Branch if abs(compIgnFallRelTime - ignFallRelTime0)/256 != 0
  10284. cmpb TcasLast128 ; high part is null, check low part
  10285. bcs L1754 ; Bail if difference is small, i.e. abs(compIgnFallRelTime - ignFallRelTime0) < TcasLast128
  10286.  
  10287. ;------------------------------------------------------------------
  10288. ; Compute ignTime0 = ignFallRelTime0 + casFallTime0
  10289. ; The ignition time computed from the cas falling edge
  10290. ;------------------------------------------------------------------
  10291. L1749 ldd ignFallRelTime0 ; d = ignFallRelTime0
  10292. addd casFallTime0 ; d = ignFallRelTime0 + casFallTime0
  10293. std ignTime0 ; ignTime0 = ignFallRelTime0 + casFallTime0
  10294. bra L1754 ; Bail
  10295.  
  10296. ;----------------------------------------------------------------
  10297. ; At this point we detected that coil is already energized...
  10298. ; Section of code similar to above one...
  10299. ;----------------------------------------------------------------
  10300. ;--------------------------------------------------
  10301. ; Check if flag indicate ignition makes sense???
  10302. ;--------------------------------------------------
  10303. L1750 brclr enerFlags, #$03, L1754 ; Bail if flag indicates coil is not energized and energization is not scheduled???
  10304.  
  10305. ;---------------------------------------------------------------------------
  10306. ; Branch to compute ignTime0
  10307. ; if we predicted we would schedule ignition on the CAS falling edge???
  10308. ;---------------------------------------------------------------------------
  10309. brset ignFallFlags, #$01, L1752 ; Branch if ??? TDC related
  10310.  
  10311. ;-------------------------------------------------------------------
  10312. ; Flag is not set, do it anyway if
  10313. ;
  10314. ; abs(ignTime0 - casFallTime0 - ignFallRelTime0) >= TcasLast128
  10315. ; abs(compIgnFallRelTime - ignFallRelTime0) >= TcasLast128
  10316. ;
  10317. ; where compIgnFallRelTime = ignTime0 - casFallTime0 is the ignition
  10318. ; time relative to the cas falling edge but calculated from ignTime0...
  10319. ;
  10320. ; i.e. Do it anyway if they are more than 1.4deg apart??? Why not
  10321. ; just recompute it anyway instead of doing this lenghty
  10322. ; computation to check it, there must be a reason??? I guess
  10323. ; in most cases, it might be more acurate to use ignFallRelTime0
  10324. ; but in case it is too far apart from what makes sense at this time
  10325. ; then just use whatever makes sense at this time...
  10326. ;-------------------------------------------------------------------
  10327. ldd ignTime0 ; d = ignTime0
  10328. subd casFallTime0 ; d = ignTime0 - casFallTime0
  10329. subd ignFallRelTime0 ; d = ignTime0 - casFallTime0 - ignFallRelTime0
  10330. bcc L1751 ; Branch if no overflow
  10331. coma ; overflow, compute 2s complement
  10332. comb ;
  10333. addd #$0001 ; d = abs(ignTime0 - casFallTime0 - ignFallRelTime0)
  10334. L1751 tsta ;
  10335. bne L1752 ; Branch if abs(ignTime0 - casFallTime0 - ignFallRelTime0)/256 > 0
  10336. cmpb TcasLast128 ; high part is zero (a = 0), check low part for minimum
  10337. bcs L1754 ; Branch if difference is small, i.e. abs(ignTime0 - casFallTime0 - ignFallRelTime0) < TcasLast128
  10338.  
  10339. ;----------------------------------------------------
  10340. ; Compute ignTime0 = ignFallRelTime0 + casFallTime0
  10341. ; The ignition time computed from the cas falling edge
  10342. ;----------------------------------------------------
  10343. L1752 ldd ignFallRelTime0 ; d = ignFallRelTime0
  10344. addd casFallTime0 ; d = ignFallRelTime0 + casFallTime0
  10345. std ignTime0 ; ignTime0 = ignFallRelTime0 + casFallTime0
  10346.  
  10347. ;-------------------------------------------
  10348. ; Update enerFlags = 1 since at this
  10349. ; point we know the coil is energized???
  10350. ;-------------------------------------------
  10351. ldaa #$01 ; a = $01
  10352. staa enerFlags ; enerFlags = $01
  10353.  
  10354. ;------------------------------------------
  10355. ; Make sure ignition time is in the future
  10356. ;------------------------------------------
  10357. ldd t3_clock1 ; d = t3_clock1
  10358. addd #$0009 ; d = t3_clock1 + $09 (36usec)
  10359. xgdx ; x = t3_clock1 + $09
  10360. cpx ignTime0 ;
  10361. bpl L1753 ; Branch to use t3_clock1 + $09 if ignTime0 is "in the past"
  10362. ldx ignTime0 ; ignTime0 is valid, use it
  10363.  
  10364. ;-----------------------------------------------------------
  10365. ; Schedule ignition time on both output compare registers
  10366. ; Update the coil bits and save time in ignTime0
  10367. ;-----------------------------------------------------------
  10368. L1753 stx t3_outCmpWr ; Schedule interrupt time on first output compare register
  10369. orm t3_csr0, #$0c ; Set both coil bits for ignition
  10370. ldaa t3_csr1 ; Go to next output compare register
  10371. stx t3_outCmpWr ; Schedule interrupt time on second output compare register
  10372. stx ignTime0 ; ignTime0 = next interrupt time
  10373.  
  10374. ;-----------------------------------------------
  10375. ; Common branching place for most code above...
  10376. ;-----------------------------------------------
  10377. ;---------------------------------------------------------
  10378. ; Section to check if ignition should have occured by
  10379. ; now and schedule it "now" if needed
  10380. ;---------------------------------------------------------
  10381. L1754 brclr casFlags0, #$02, L1755 ; Branch if rpm(Tcas) < 505 previously
  10382. brset casFlags0, #$40, L1756 ; Branch to continue if timing adjustement mode active
  10383. ldd timCas0 ; d = timCas0:timCas1
  10384. cmpd #$00c8 ;
  10385. bcc L1756 ; Branch if timCas0 >= $c8 (4.7 BTDC)
  10386. ldaa port5 ; a = port5
  10387. anda tdcMask0 ; a = port5 & $02 or $04
  10388. bne L1756 ; Branch if current coil bit is 1, i.e. coil is not energized
  10389. brclr enerFlags, #$03, L1756 ; Branch to continue if flag indicate coil is not energized and energization is not scheduled
  10390.  
  10391. ;-----------------------------------------------------------------------------------
  10392. ; At this point,
  10393. ; rpm(Tcas) < 505
  10394. ; or
  10395. ; current coil is energized
  10396. ; and timCas0 < $c8 (4.7 BTDC)
  10397. ; and enerFlags = 1 or 2, coil is energized or energization is scheduled
  10398. ;
  10399. ; In all those cases, ignition should have occured by now???
  10400. ;
  10401. ; Schedule interrupt on first output compare register to provoke
  10402. ; ignition now, save time in ignTime0 and clear enerFlags
  10403. ;-----------------------------------------------------------------------------------
  10404. L1755 orm t3_csr0, #$0c ; Set both coil bits for ignition
  10405. ldx t3_clock1 ; x = t3_clock1
  10406. inx ;
  10407. inx ; x = t3_clock1 + $02
  10408. stx t3_outCmpWr ; Schedule interrupt time on first output compare register
  10409. stx ignTime0 ; Update ignTime0 with the ignition time we just used
  10410. clra ;
  10411. staa enerFlags ; enerFlags = 0
  10412.  
  10413. ;--------------------------------------------------------------
  10414. ; Section to update ignition stuff when rpm(Tcas) < 505???
  10415. ; Probably a dedicated section when engine is cranking???
  10416. ; First check rpm flag...
  10417. ;--------------------------------------------------------------
  10418. L1756 brset casFlags0, #$02, L1757 ; Branch if rpm(Tcas) >= 505 previously
  10419. jmp L1765 ; Bail
  10420.  
  10421. ;---------------------
  10422. ; rpm(Tcas) < 505rpm
  10423. ;---------------------
  10424. ;---------------------------------------------------------
  10425. ; Compute enerLenX0 = min($60/128 * Tcas, 16*enerLen)
  10426. ; = min( 0.75 * Tcas, 16*enerLen)
  10427. ;---------------------------------------------------------
  10428. L1757 ldaa enerLen ; a = enerLen
  10429. clrb ; d = enerLen*256
  10430. lsrd ;
  10431. lsrd ;
  10432. lsrd ;
  10433. lsrd ; d = enerLen*256/16 = 16*enerLen
  10434. std temp20 ; temp20 = 16*enerLen
  10435. L1758 ldaa temp23 ; a = temp23 (low part of Tcas)
  10436. ldab #$60 ; b = $60
  10437. mul ; d = $60 * temp23
  10438. staa enerLenX0 ; enerLenX0 = $60/256 * temp23
  10439. ldaa temp22 ; a = temp22
  10440. ldab #$60 ; b = $60
  10441. mul ; d = $60 * temp22
  10442. addb enerLenX0 ; d = $60 * temp22 + $60/256 * temp23 = $60/256 * [temp22:temp23]
  10443. adca #$00 ; propagate carry
  10444. asld ; d = $60/128 * [temp22:temp23] = $60/128 * Tcas
  10445. bcs L1759 ; Branch if overflow
  10446. cmpd1 temp20 ;
  10447. bcs L1760 ; Branch if $60/128 * Tcas < 16*enerLen
  10448. L1759 ldd temp20 ; Use max of 16*enerLen
  10449. L1760 std enerLenX0 ; enerLenX0 = min($60/128 * Tcas, 16*enerLen)
  10450.  
  10451. ;-------------------------------------------------------------------------------------
  10452. ; Compute temp20 = casFallTime0 + $9c/256 * Tcas + ignRelTime0 - enerLenX0
  10453. ; = casFallTime0 + 110deg + ignRelTime0 - enerLenX0
  10454. ;
  10455. ; 110deg is the number of degrees between the CAS falling edge and the next
  10456. ; CAS rising edge since CAS starts at -75deg and ends at -5deg, CAS width = 70deg
  10457. ; and then distance from falling edge to next rising edge = 180deg - 70deg = 110deg
  10458. ;
  10459. ; we are therefore calculating the coil energization absolute time for the next
  10460. ; CAS/cylinder from the CAS falling edge of the current CAS/cylinder...
  10461. ;-------------------------------------------------------------------------------------
  10462. brclr tdcCasCount, #$fe, L1765 ; Bail if tdcCasCount = 0 or 1
  10463. ldab temp23 ; b = temp23 (low part of Tcas)
  10464. ldaa #$9c ; a = $9c
  10465. mul ; d = $9c * temp23
  10466. staa temp21 ; temp21 = $9c * temp23/256
  10467. ldaa temp22 ; a = temp22
  10468. ldab #$9c ; b = $9c
  10469. mul ; d = $9c * temp22
  10470. addb temp21 ; d = $9c * temp22 + $9c * temp23/256 = $9c/256 * [temp22:temp23]
  10471. adca #$00 ; propagate carry
  10472. addd ignRelTime0 ; d = $9c/256 * Tcas + ignRelTime0
  10473. subd enerLenX0 ; d = $9c/256 * Tcas + ignRelTime0 - enerLenX0
  10474. addd casFallTime0 ; d = $9c/256 * Tcas + ignRelTime0 - enerLenX0 + casFallTime0
  10475. std temp20 ; temp20 = $9c/256 * Tcas + ignRelTime0 - enerLenX0 + casFallTime0
  10476.  
  10477. ;----------------------------------------------------------------------
  10478. ; Verify that energization time does not occur too close to ignition
  10479. ; of current cylinder, i.e. energization should not occur sooner than
  10480. ; 1ms after ignition of preceeding cylinder
  10481. ;----------------------------------------------------------------------
  10482. ldd ignTime0 ; d = ignTime0
  10483. addd #$00fa ; d = ignTime0 + $fa (1ms)
  10484. cmpd1 temp20 ;
  10485. bmi L1761 ; Branch if ignTime0 + $fa < casFallTime0 + $9c/256 * Tcas + ignRelTime0 - enerLenX0
  10486. std temp20 ; Use closest possible energization time of ignTime0 + $fa (1ms)
  10487.  
  10488. ;-------------------------------------
  10489. ; Check if current coil is energized
  10490. ;-------------------------------------
  10491. L1761 ldaa port5 ; a = port5
  10492. anda tdcMask0 ; a = port5 & tdcMask0 ($02 or $04)
  10493. beq L1763 ; Branch if coil bit is 0, i.e. coil is energized
  10494.  
  10495. ;--------------------------------------------------
  10496. ; Current coil is not yet energized,
  10497. ;
  10498. ; Check that energization time computed above and
  10499. ; stored in temp20 is sufficiently in the future
  10500. ;--------------------------------------------------
  10501. brset enerFlags, #$02, L1764 ; Bail if flag indicates coil is energized or energization is scheduled
  10502. ldd t3_clock1 ; d = t3_clock1
  10503. addd #$000a ; d = t3_clock1 + $0a (40usec)
  10504. xgdx ; x = t3_clock1 + $0a
  10505. cpx temp20 ; Compare to energization time
  10506. bpl L1762 ; Branch to use t3_clock1 + $0a if energization time is "in the past"
  10507. ldx temp20 ; Energization time is valid, use it
  10508.  
  10509. ;----------------------------------------------------
  10510. ; Schedule the coil energization
  10511. ; time and store time in enerAbsTimeNext0
  10512. ;----------------------------------------------------
  10513. L1762 stx t3_outCmpWr ; Schedule interrupt time on first output compare register
  10514. ldaa t3_csr1 ; Go to next output compare register
  10515. stx t3_outCmpWr ; Schedule interrupt time on second output compare register
  10516. stx enerAbsTimeNext0 ; Store actual time used
  10517.  
  10518. ;--------------------------------------------------
  10519. ; Reset the corresponding coil bit to
  10520. ; energize the coil at the specified time
  10521. ;--------------------------------------------------
  10522. ldaa tdcMask1 ; a = $02 or $04
  10523. asla ; a = $04 or $08
  10524. coma ; a = ~($04 or $08)
  10525. anda t3_csr0 ; reset that coil bit, i.e. energize that coil at the specified time
  10526. staa t3_csr0 ; update t3_csr0
  10527.  
  10528. ;-----------------------------------------------
  10529. ; Set enerFlags = 0
  10530. ; Although coil is energized, it seems we use
  10531. ; this value when rpm is low...
  10532. ;-----------------------------------------------
  10533. clra ;
  10534. staa enerFlags ;
  10535. bra L1765 ;
  10536.  
  10537. ;------------------------------------------------------------------------------
  10538. ; Update enerAbsTimeNext0 with its latest value if flag indicates
  10539. ; coil is energized or energization has been scheduled
  10540. ; Makes sense to update the variable if energization time was actually used...
  10541. ;------------------------------------------------------------------------------
  10542. L1763 brclr enerFlags, #$03, L1765 ; Branch if flag indicates coil is not energized and energization is not scheduled
  10543. L1764 ldd temp20 ; d = temp20
  10544. std enerAbsTimeNext0 ; enerAbsTimeNext0 = temp20
  10545.  
  10546. ;-------------------------------------------
  10547. ; Common branching place for all code above
  10548. ;-------------------------------------------
  10549. ;-------------------------------------------------------
  10550. ; Update ignFallFlags, t3_csr0 and t1_csr
  10551. ; Change cas edge detection polarity among others...
  10552. ;-------------------------------------------------------
  10553. L1765 andm ignFallFlags, #$fe ; Reset 0000 0001
  10554. ldaa t3_csr0 ; a = t3_csr0
  10555. anda #$0c ; reset both coil bits, i.e. energize both coil at the specified time
  10556. oraa #$42 ; set 0100 0010 ???
  10557. ldab t1_csr ; b = t1_csr
  10558. andb #$19 ; reset 1110 0110, change cas detection polarity, enable injectors 5/6 bits???, reset injector and cas interrupt pending flags
  10559. ldx t1_inCapt ; Clear input capture flag?
  10560. staa t3_csr0 ; Update t3_csr0
  10561. stab t1_csr ; Update t1_csr
  10562.  
  10563. ;-----------------------------------
  10564. ; Reset instant knock sum???
  10565. ;-----------------------------------
  10566. andm port6, #$fe ; Reset instant knock sum???
  10567.  
  10568. ;---------------------------------------------------------------------
  10569. ; Reset engine rotating timer to 0.6sec or 1.2sec depending on
  10570. ; whether key is in start. If key is in start it means we are
  10571. ; cranking, rpm is therefore low and we need a longer timeout value...
  10572. ;---------------------------------------------------------------------
  10573. ldaa #$18 ; a = 0.6sec
  10574. brset port3, #$40, L1766 ; Branch if key is not in start???
  10575. asla ; key in start, use a = 1.2sec
  10576. L1766 staa T40_engRot ; T40_engRot = #$18 (0.6sec) or #$30 (1.2sec)
  10577.  
  10578. ;----------------------------
  10579. ; Update rev limiter flag
  10580. ;----------------------------
  10581. ldx Tcas ; Tcas = Time(s) per engine revolution * 125000, rpm = (125000*60)/(2*Tcas)
  10582. cpx #$01f4 ; Rev limiter (limit rpm = (125000*60)/(2*$01F4) = 7500)
  10583. bcc L1767 ; branch if RPM lower than threshold (Tcas higher than threshold)
  10584. orm state3, #$04 ; RPM exceeds threshold, set bit
  10585. bra L1768 ;
  10586. L1767 andm state3, #$fb ; RPM below threshold, reset bit
  10587.  
  10588. ;-----------------------------
  10589. ; Update cylinder1 TDC state
  10590. ;-----------------------------
  10591. L1768 andm tdcCasFlags, #$7f ; Assume flag is 0
  10592. brclr tdcCasFlags, #$08, L1769 ; branch if TDC was 0 last time
  10593.  
  10594. ;------------------------------------------------
  10595. ; TDC bit was 1 last time, check if it changed
  10596. ;------------------------------------------------
  10597. brset port3, #$04, L1769 ; branch if current TDC bit is 1
  10598.  
  10599. ;-------------------------------------------------------------------------------
  10600. ; TDC bit was 1 last time and is now 0, update flag and reset counter (lower three bits)
  10601. ;
  10602. ; -> since we are executing this code on every falling edge of CAS pulses,
  10603. ; we necessarily are on the cylinder #1 TDC
  10604. ;-------------------------------------------------------------------------------
  10605. orm tdcCasFlags, #$80 ;
  10606. andm tdcCasFlags, #$f8 ; Reset lower 3 bits of tdcCasFlags
  10607.  
  10608. ;------------------------
  10609. ; Update stored TDC bit
  10610. ;------------------------
  10611. L1769 andm tdcCasFlags, #$f7 ; Reset old TDC bit to 0
  10612. brclr port3, #$04, L1770 ; branch if current TDC bit is not set
  10613. orm tdcCasFlags, #$08 ; Current TDC bit set, update the flag with current value
  10614.  
  10615. ;---------------------------------------------------------
  10616. ; Decrement tdcCasFlags lower 3 bits if not already at 0
  10617. ;---------------------------------------------------------
  10618. L1770 brclr tdcCasFlags, #$07, L1771 ; Branch if lower 3 bits have reached 0
  10619. dec tdcCasFlags ; Decrement lower 3 bits
  10620.  
  10621. ;--------------------------------------------------------------------------------------------------
  10622. ; Increment casCylIndex (loop from 0 to 3) and reset it to 0 if TDC detected on #1 cyl (tdcCasFlags.7 set)
  10623. ;--------------------------------------------------------------------------------------------------
  10624. L1771 ldaa casCylIndex ;
  10625. inca ;
  10626. cmpa #$04 ;
  10627. bcc L1772 ; Branch if new value >= 4
  10628. brclr tdcCasFlags, #$80, L1773 ; New value < 4, branch if no TDC detected
  10629. L1772 clra ; TDC detected, restart counter at 0
  10630. L1773 staa casCylIndex ;
  10631.  
  10632.  
  10633. ;------------------------------------------------
  10634. ; Update tdcCheck
  10635. ; Decrement on every cas falling edge and
  10636. ; re-init to 8 on cylinder #1 TDC, tdcCheck
  10637. ; should never reach 0 if TDC sensor is working
  10638. ;------------------------------------------------
  10639. ldaa tdcCheck ;
  10640. beq L1774 ; Branch if tdcCheck already 0
  10641. deca ; a = tdcCheck
  10642. L1774 brclr tdcCasFlags, #$80, L1775 ; branch to store if not cylinder #1 TDC
  10643. ldaa #$08 ; We are at cylinder #1 TDC, restart tdcCheck with 8
  10644. L1775 staa tdcCheck ; Store new value
  10645.  
  10646. ;---------------------
  10647. ; Update oldAirCnt0
  10648. ;---------------------
  10649. ldd airCnt0
  10650. std oldAirCnt0
  10651.  
  10652. ;---------------------------------------------------------------
  10653. ; Compute d = t1_t2_diff/8,
  10654. ; the time between the last time we received a airflow
  10655. ; sensor pulse and the time when the current cas edge was
  10656. ; detected (t1_lastCas stored at the beginning of the interrupt)
  10657. ;
  10658. ; If airCntNew0 is null (we did not count any air since the
  10659. ; last time we were here) then use d = Tcas???
  10660. ;---------------------------------------------------------------
  10661. ldd airCntNew0 ;
  10662. bne L1776 ; Branch if airCntNew0 != 0
  10663. ldd Tcas ; airCntNew0=0, use d = Tcas??
  10664. bra L1777 ;
  10665. L1776 ldd t1_lastCas ; Get cas edge time value
  10666. subd t2_lastMas ; Subtract last time mas interrupt was called, d = t1_lastCas - t2_lastMas = t1_t2_diff
  10667. ldx #T200_mas ;
  10668. jsr masFunc1 ; D = ~t1_t2_diff/8
  10669.  
  10670. ;---------------------------------------------------------------
  10671. ; Loop to scale D=t1_t2_diff (and X=t2_diff8 at the same time)
  10672. ; to fit in lower nibble only
  10673. ;---------------------------------------------------------------
  10674. L1777 ldx t2_diff8 ; X = t2_diff8
  10675. L1778 tsta ;
  10676. beq L1779 ; Branch if high nibble=0
  10677. lsrd ; high nibble<>0, divide by 2
  10678. xgdx ; X<->D
  10679. lsrd ; divide t2_diff8 by 2
  10680. xgdx ; X<->D
  10681. bra L1778 ; At this point, X=t2_diff8/2, D=t1_t2_diff/2, loop back
  10682.  
  10683. ;---------------------------------------------------------------------------
  10684. ; At this point, D=scaledt1_t2_diff fits in lower nibble and X=scaledt2_diff8
  10685. ;----------------------------------------------------------------------------
  10686. L1779 ldaa #$9c ; A=$9C, B=scaledt1_t2_diff
  10687. mul ; D = scaledt1_t2_diff * $9C
  10688. xgdx ; X = scaledt1_t2_diff * $9C, D=scaledt2_diff8
  10689.  
  10690. ;----------------------------------------------------------------
  10691. ; Loop to scale X=scaledt1_t2_diff*$9C to fit in lower nibble
  10692. ; scales D = scaledt2_diff8 by the same amount
  10693. ;----------------------------------------------------------------
  10694. L1780 tsta ;
  10695. beq L1781 ;
  10696. lsrd ;
  10697. xgdx ;
  10698. lsrd ;
  10699. xgdx ;
  10700. bra L1780 ;
  10701.  
  10702. ;---------------------------------------------------------------
  10703. ; At this point, D=scaledt2_diff8 and X=scaledt1_t2_diff * $9C
  10704. ; Compute airQuantumRemainder = scaledt1_t2_diff/scaledt2_diff8 * $9C
  10705. ;---------------------------------------------------------------
  10706. L1781 stab temp8 ; temp8 = scaledt2_diff8
  10707. xgdx ; D=scaledt1_t2_diff * $9C, X=scaledt2_diff8
  10708. div temp8 ; D=D/temp8 = scaledt1_t2_diff * $9C / scaledt2_diff8?
  10709. bcs L1782 ; Branch if overflow
  10710. lsr temp8 ; Check for ???
  10711. cmpa temp8 ;
  10712. bcs L1783 ;
  10713. incb ;
  10714. bne L1783 ;
  10715. L1782 ldab #$ff ; overflow, use max
  10716.  
  10717. ;------------------------------------------------------------------------
  10718. ; At this point, b = airQuantumRemainder = scaledt1_t2_diff/scaledt2_diff8 * $9C
  10719. ; Check if we should use it
  10720. ;------------------------------------------------------------------------
  10721. L1783 cmpb airQuantum ;
  10722. bcs L1784 ; Branch if airQuantumRemainder < airQuantum, which means we can use it
  10723. ldab airQuantum ; airQuantumRemainder >= airQuantum (in theory, I suppose at most it should only be equal to it...) use b=airQuantum
  10724. clr airQuantum ; airQuantum=0 (since we "transfered" all of it to b)
  10725. bra L1785 ;
  10726.  
  10727. ;------------------------------------------------------------------------
  10728. ; At this point airQuantumRemainder < airQuantum
  10729. ; and b = airQuantumRemainder = scaledt1_t2_diff/scaledt2_diff8 * $9C
  10730. ;
  10731. ; We are going to use airQuantumRemainder in this calculation cycle.
  10732. ; Subtract it from airQuantum. What is left in airQuantum
  10733. ; is going to be used as the startup value for the next airflow
  10734. ; calculation cycle. Basically we don't want to loose any air in
  10735. ; the calculations...
  10736. ;------------------------------------------------------------------------
  10737. L1784 ldaa airQuantum ; a = airQuantum
  10738. sba ; a = airQuantum - airQuantumRemainder
  10739. staa airQuantum ; airQuantum = old airQuantum - airQuantumRemainder, basically we subtract what we are going to use
  10740.  
  10741. ;-------------------------------------------------------
  10742. ; Finish calc and scale airQuantumRemainder if required
  10743. ;-------------------------------------------------------
  10744. L1785 clra ; d = airQuantumRemainder (high part=0)
  10745. brclr masCasFlags, #$80, L1786 ; Branch if no scaling
  10746. asld ; scale d = airQuantumRemainder * 2
  10747.  
  10748. ;-----------------------------------------------------------------------
  10749. ; At this point, d = airQuantumRemainder,
  10750. ; add it for a final time to airCntNew0, also check for minimum value
  10751. ;-----------------------------------------------------------------------
  10752. L1786 addd airCntNew0 ; d = airQuantumRemainder + airCntNew0
  10753. cmpd airCntMin0 ;
  10754. bcc L1787 ; Branch if airCntNew0 + airQuantumRemainder > airCntMin0
  10755. ldd airCntMin0 ; Use airCntMin0
  10756. L1787 std airCntNew0 ; airCntNew0 = max(airQuantumRemainder+airCntNew0, airCntMin0)
  10757.  
  10758. ;---------------------------------------------------------------------------------
  10759. ; Adjust airCntNew0 when mafRaw below 50Hz:
  10760. ; If mafRaw below 50Hz and (airCnt0-airCntNew0) >= $004e then airCntNew0 = (airCnt0-$0010)
  10761. ; Limits the downward rate of change of airCntNew0 under rapidly decreasing air flow conditions???
  10762. ;---------------------------------------------------------------------------------
  10763. ldaa mafRaw ; a = mafRaw
  10764. #ifdef masLog2X
  10765. cmpa #$04
  10766. #else
  10767. cmpa #$08
  10768. #endif
  10769. bcc L1788 ; Branch if mafRaw > 50Hz (no adjustment)
  10770. ldd airCnt0 ; mafRaw<50Hz, d = airCnt0
  10771. subd airCntNew0 ; d = airCnt0-airCntNew0
  10772. bcs L1788 ; Branch if airCnt0 < airCntNew0 (no adjustment)
  10773. cmpd #$004e ; airCnt0 >= airCntNew0, check difference
  10774. bcs L1788 ; Branch if (airCnt0-airCntNew0)<$004e (no adjustment)
  10775. ldd airCnt0 ; (airCnt0-airCntNew0)>=$004e, subtract $10
  10776. subd #$0010 ;
  10777. std airCntNew0 ; airCntNew0 = (airCnt0-$0010)
  10778.  
  10779. ;--------------------------------------------------------
  10780. ; Section below is to update airCnt0:airCnt1:airCnt2
  10781. ; (filtered air count) from airCntNew0:airCntNew1 (latest
  10782. ; air count received from aiflow sensor)
  10783. ;--------------------------------------------------------
  10784. ;------------------------------------------------------------
  10785. ; Multiply airCnt0:airCnt1:airCnt2 by 8 * airFiltFact/256
  10786. ;------------------------------------------------------------
  10787. L1788 ldaa airFiltFact ;
  10788. staa temp8 ; temp8=airFiltFact
  10789. ldd airCnt1 ; d = airCnt1:airCnt2
  10790. asld ;
  10791. rol airCnt0 ;
  10792. asld ;
  10793. rol airCnt0 ;
  10794. asld ; d = 8*[airCnt1:airCnt2]
  10795. rol airCnt0 ; airCnt0 = 8*airCnt0
  10796. ldab temp8 ; b = airFiltFact
  10797. mul ; d = airFiltFact * (8*[airCnt1:airCnt2])/256
  10798. std airCnt1 ; airCnt1:airCnt2 = airFiltFact * (8*[airCnt1:airCnt2])/256
  10799. ldaa airCnt0 ;
  10800. ldab temp8 ;
  10801. mul ; d = airCnt0 * airFiltFact
  10802. addb airCnt1 ; Add lower part
  10803. adca #$00 ; Propagate carry
  10804. std airCnt0 ; Store final result, 8*[airCnt0:airCnt1:airCnt2] * airFiltFact/256
  10805.  
  10806. ;------------------------------------------------------------------
  10807. ; Multiply airCntNew0:airCntNew1 by 4 with overflow check
  10808. ;------------------------------------------------------------------
  10809. ldd airCntNew0 ;
  10810. asld ;
  10811. bcs L1789 ;
  10812. asld ;
  10813. bcc L1790 ;
  10814. L1789 ldaa #$ff ; Use max
  10815. L1790 std airCntNew0 ;
  10816.  
  10817. ;-----------------------------------------------------------------------------------------------------------
  10818. ; Add 2*(256-airFiltFact)*4*[airCntNew0:airCntNew1] to 8*[airCnt0:airCnt1:airCnt2] * airFiltFact/256
  10819. ; with overflow check
  10820. ;-----------------------------------------------------------------------------------------------------------
  10821. ldaa temp8 ; Still contains airFiltFact ($d1 or $e4 from code)?
  10822. nega ;
  10823. asla ; a = 2*(256-airFiltFact) -> $d1->$5e $e4->$38 209->94 228->56
  10824. mul ; d = 2*(256-airFiltFact) * airCntNew1
  10825. addd airCnt1 ;
  10826. std airCnt1 ;
  10827. ldaa airCnt0 ;
  10828. adca #$00 ;
  10829. bcc L1791 ; Branch if no overflow
  10830. ldaa #$ff ; Use max if overflow
  10831. L1791 staa airCnt0 ;
  10832.  
  10833. ldaa temp8 ; Still contains airFiltFact
  10834. nega ;
  10835. asla ;
  10836. ldab airCntNew0 ;
  10837. mul ;
  10838. addd airCnt0 ;
  10839. bcc L1792 ; Branch if no overflow
  10840. ldd #$ffff ; Use max if overflow
  10841.  
  10842. ;-------------------------------------------------------------------------------------------------------------------
  10843. ; At this point, D:airCnt2 contains result from above:
  10844. ; D:airCnt2 = 8*[airCnt0:airCnt1:airCnt2] * airFiltFact/256 + 2*4*(256-airFiltFact)*[airCntNew0:airCntNew1]
  10845. ; Divide it by 8 and store it.
  10846. ; If no pulse accumulator interrupts were receive, use airCntDef
  10847. ;-------------------------------------------------------------------------------------------------------------------
  10848. L1792 lsrd ;
  10849. ror airCnt2 ;
  10850. lsrd ;
  10851. ror airCnt2 ;
  10852. lsrd ;
  10853. ror airCnt2 ; Divide D:airCnt2 by 8
  10854. brclr state3, #$02, L1793 ; Branch if pulse accumulator interrupts received
  10855. ldab airCntDef ; No pulse accumulator interrupts
  10856. clra ;
  10857. asld ;
  10858. asld ;
  10859. asld ;
  10860. L1793 std airCnt0 ; Store airCnt0:airCnt1, airCnt2 was stored earlier
  10861.  
  10862. ;-------------------------------------------------------------------------------------------------------------------------------------------
  10863. ; At this point:
  10864. ;
  10865. ; [airCnt0:airCnt1:airCnt2] = 1/8 * ( 8*[airCnt0:airCnt1:airCnt2] * airFiltFact/256 + 2*4*(256-airFiltFact)*[airCntNew0:airCntNew1] )
  10866. ; = 1/8 * ( 8*[airCnt0:airCnt1:airCnt2] * airFiltFact/256 + 256/256*2*4*(256-airFiltFact)*[airCntNew0:airCntNew1] )
  10867. ; = 1/8 * ( 8*[airCnt0:airCnt1:airCnt2] * airFiltFact/256 + 8*(256-airFiltFact)/256 * 256*[airCntNew0:airCntNew1] )
  10868. ; = [airCnt0:airCnt1:airCnt2] * airFiltFact/256 + (256-airFiltFact)/256 * 256*[airCntNew0:airCntNew1]
  10869. ; = [airCnt0:airCnt1:airCnt2] * alpha + (1-alpha) * 256*[airCntNew0:airCntNew1]
  10870. ;
  10871. ; = alpha * oldAirCnt24bits + (1-alpha) * scaledNewAirCnt16bits
  10872. ;
  10873. ; where alpha = airFiltFact/256, 0<=alpha<=1,
  10874. ;
  10875. ; This is exponential averaging of [airCnt0:airCnt1:airCnt2] with [airCntNew0:airCntNew1]*256 as input
  10876. ;
  10877. ;-------------------------------------------------------------------------------------------------------------------------------------------
  10878.  
  10879. ;-----------------------------------------------------------------
  10880. ; If engine is notRotating or startingToCrank then ignore
  10881. ; airCnt0 we just calculated and use airCntMax*8 instead
  10882. ;-----------------------------------------------------------------
  10883. ldab airCntMax ; d = airCntMax
  10884. clra ;
  10885. asld ;
  10886. asld ;
  10887. asld ; d = 8*airCntMax
  10888. brset state3, #$11, L1794 ; Branch if notRotating or startingToCrank -> Always use airCntMax*8 in that case?
  10889.  
  10890.  
  10891. ;-------------------------------------------------
  10892. ; Engine is running, cap airCnt0 with airCntMax*8
  10893. ;-------------------------------------------------
  10894. cmpd1 airCnt0 ;
  10895. bcc L1795 ; Branch if airCntMax*8 >= airCnt0
  10896. L1794 std airCnt0 ; Store airCntMax in airCnt0
  10897.  
  10898. ;----------------------------------------------------------------------
  10899. ; Update oldAirCnt0 if no pulse accumulator interrupts were received????
  10900. ;----------------------------------------------------------------------
  10901. L1795 brclr state3, #$02, L1796 ; Branch if pulse accumulator interrupts are being received
  10902. ldd airCnt0 ; No pulse accumulator interrupts received, store airCnt0 in oldAirCnt0???
  10903. std oldAirCnt0 ;
  10904.  
  10905. ;-----------------------------------------
  10906. ; Re-init airCntNew0, start a new cycle
  10907. ;-----------------------------------------
  10908. L1796 clra
  10909. clrb
  10910. std airCntNew0
  10911.  
  10912. ;---------------------------------------------------------------------------------
  10913. ; Execute the coil interrupt routine if an output capture interrupt is pending
  10914. ;
  10915. ; Might be called from here because we are about to spend
  10916. ; a lot of time to calculate airflow and injectors???? I assume here
  10917. ; that by doing so, the pending interrupt will be cleared?
  10918. ;---------------------------------------------------------------------------------
  10919. brclr t3_csr1, #$40, L1797 ; Branch if no interrupt pending
  10920. jsr coilFunc ;
  10921.  
  10922. ;-------------------------------------------------------------------------------------
  10923. ; Execute the pulse accumulator routine if an interrupt is pending
  10924. ;
  10925. ; At this point, airQuantum contains whatever air remains to be counted
  10926. ; from the time the current CAS interrupt occured up to the time the next
  10927. ; mas interrupt will happen (the next airflow sensor pulse). If the mas interrupt
  10928. ; is pending then this air should already have been added. Do it now. I assume
  10929. ; that by doing so, the pending interrupt will be cleared?
  10930. ;
  10931. ; If no interrupt is pending then the remaining air will be added when the
  10932. ; next mas interrupt will occur, which is the normal way.
  10933. ;
  10934. ; In both cases airQuantum is re-initialized to its maximum value when masProc
  10935. ; is executed
  10936. ;-------------------------------------------------------------------------------------
  10937. L1797 brclr t2_csr, #$80, L1798 ; Branch if no interrupt pending
  10938. jsr masProc ;
  10939.  
  10940. ;------------------------------------------------------------------------------------
  10941. ; Compute a kind of airCnt0 derivative (acceleration and decceleration)
  10942. ; Update airDiffPos or airDiffNeg with airFlowDifference = abs(airCnt0-oldAirCnt0)
  10943. ; airDiffPos is updated when airCnt0-oldAirCnt0 >= 0
  10944. ; airDiffNeg is updated when airCnt0-oldAirCnt0 < 0
  10945. ;------------------------------------------------------------------------------------
  10946. L1798 ldx #airDiffPos ;
  10947. ldd airCnt0 ; d = airCnt0
  10948. subd oldAirCnt0 ; d = airCnt0-oldAirCnt0
  10949. bcc L1799 ; Branch if result positive
  10950. coma ; Result negative, change sign
  10951. comb ;
  10952. addd #$0001 ; d = oldAirCnt0-airCnt0
  10953. inx ; x = x + 1
  10954. L1799 tsta ; Check for overflow in a (we want result in b only)
  10955. beq L1800 ; Branch if a=0 (b contains difference)
  10956. ldab #$ff ; a not null->overflow, use b = maximum
  10957. L1800 cmpb $00,x ;
  10958. bls L1801 ; Branch if abs(airCnt0-oldAirCnt0) <= airDiffPos or airDiffNeg
  10959. stab $00,x ; Store new value of airDiffPos or airDiffNeg
  10960.  
  10961. ;---------------------------------------------------------------------------
  10962. ; Decide what value we are going to use for injPw (0, injPwStart or normal)
  10963. ;---------------------------------------------------------------------------
  10964. L1801 brclr state3, #$01, L1802 ; Branch if startingToCrank clear
  10965. ldd injPwStart ; Engine startingToCrank, use injPwStart
  10966. bra L1803 ; Do not compute injPw from airflow
  10967. L1802 brclr state3, #$3c, L1804 ; startingToCrank clear, branch to compute normal injPw from airflow if all clear: "rotatingStopInj but not runningFast" and "notRotating" and "rotatingStopInj" and "rev limiter active"
  10968. clra ; Use injPw=0 if rev limiter is active or if engine is notRotating, rotatingStopInj or "rotatingStopInj and not runningFast"
  10969. clrb ;
  10970. L1803 std injPw ;
  10971. bra L1807 ;
  10972.  
  10973.  
  10974. ;----------------------------------------------------------------
  10975. ; Compute injector pulsewidth for normal engine conditions
  10976. ;
  10977. ; injPw = [airCnt0:airCnt1] * injFactor/256, 16 bit multiply
  10978. ;----------------------------------------------------------------
  10979. L1804 ldaa airCnt1 ; a = airCnt1
  10980. ldab injFactor+1 ; b = injFactor1
  10981. mul ; d = airCnt1*injFactor1
  10982. tab ; b = airCnt1*injFactor1/256
  10983. clra ; d = airCnt1*injFactor1/256
  10984. std injPw ; injPw = airCnt1*injFactor1/256
  10985. ldaa airCnt1 ;
  10986. ldab injFactor ;
  10987. mul ;
  10988. addd injPw ;
  10989. bcs L1805 ;
  10990. std injPw ;
  10991. ldaa airCnt0 ;
  10992. ldab injFactor+1 ;
  10993. mul ;
  10994. addd injPw ;
  10995. bcs L1805 ;
  10996. std injPw ;
  10997. ldaa airCnt0 ;
  10998. ldab injFactor ;
  10999. mul ;
  11000. addb injPw ;
  11001. adca #$00 ; Propagate carry
  11002. beq L1806 ; Branch if no overflow
  11003. L1805 ldab #$f0 ; Overflow, use max of ~$f000 (61ms) in case of overflow
  11004. L1806 stab injPw ;
  11005.  
  11006. ;----------------------
  11007. ; Compute accEnrDiffT
  11008. ;----------------------
  11009. L1807 ldx #L2040 ; x points to L2040
  11010. ldab oldAirCnt0 ; b = oldAirCnt0/256 (high part only...)
  11011. cmpb #$05 ;
  11012. bcs L1808 ; Branch if below max
  11013. ldab #$05 ; Use max
  11014. L1808 abx ; x = L2040 + min(oldAirCnt0, 5)
  11015. ldab $00,x ; b = L2040(oldAirCnt0/256)
  11016. stab accEnrDiffT ; accEnrDiffT = L2040(oldAirCnt0/256)
  11017.  
  11018. ;------------------------------------------------------------------------
  11019. ; Update accEnr
  11020. ;
  11021. ; At first accEnr is decreased by a fixed factor (exponentially)
  11022. ; on each iteration. When it reaches a certain level, it this
  11023. ; then held constant for the duration of a timer and then
  11024. ; decremented by 1 to 0. First do the exponential part...
  11025. ;------------------------------------------------------------------------
  11026. ldab accEnr ; b = accEnr
  11027. beq L1811 ; Branch if accEnr = 0
  11028. ldaa accEnrDecay ; a = accEnrDecay
  11029. mul ; d = accEnrDecay * accEnr
  11030. tab ; b = accEnr * accEnrDecay/256
  11031. ldaa accEnr ; a = accEnr
  11032. sba ; a = accEnrNew = accEnr - accEnr * accEnrDecay/256 = accEnr * (1-accEnrDecay/256)
  11033. cmpa #$02 ;
  11034. bcc L1811 ; Branch if accEnrNew >= 2
  11035.  
  11036. ;-------------------------------------------------------------------
  11037. ; accEnr - accEnr * accEnrDecay/256 < 2 (which means accEnr much bigger than 2)
  11038. ; Just decrement accEnr by 1 if accEnrTmr2=0 else don't change it
  11039. ;
  11040. ; Basically hold the accEnr to current value for 4 or 5 iterations
  11041. ; and then start decrease it by 1 to 0
  11042. ;-------------------------------------------------------------------
  11043. ldaa accEnrTmr2 ;
  11044. beq L1810 ;
  11045. deca ;
  11046. bne L1812 ;
  11047. L1810 ldab accEnr ;
  11048. decb ;
  11049. L1811 stab accEnr ;
  11050.  
  11051. ;----------------------------------
  11052. ; Update accEnrTmr2 from ect
  11053. ;----------------------------------
  11054. ldaa #$04 ; a = 4
  11055. ldab ectFiltered ; b = ectFiltered
  11056. cmpb #$80 ; 21degC
  11057. bcs L1812 ; Branch if temperature(ectFiltered) >= 21degC
  11058. ldaa #$05 ; temperature <21degC
  11059. L1812 staa accEnrTmr2 ; re-init accEnrTmr2 with 5
  11060.  
  11061. ;--------------------------------------
  11062. ; Decrement accEnrTimer if not yet 0
  11063. ;--------------------------------------
  11064. ldaa accEnrTimer ;
  11065. beq L1813 ; Branch if accEnrTimer = 0
  11066. deca ;
  11067. staa accEnrTimer ;
  11068.  
  11069. ;---------------------------------------------------
  11070. ; Re-init accEnrTimer to 4 if airCnt0>=accEnrMinAf
  11071. ;---------------------------------------------------
  11072. L1813 ldd airCnt0 ;
  11073. cmpd accEnrMinAf ;
  11074. bcc L1814 ; Branch if airCnt0>=accEnrMinAf
  11075. ldaa #$04 ;
  11076. staa accEnrTimer ; re-init accEnrTimer = 4
  11077.  
  11078. ;----------------------------
  11079. ; Bail if engine not running
  11080. ;----------------------------
  11081. L1814 brclr state3, #$13, L1815 ; Branch if notRotating and startingToCrank and "no pulse accumulator interrupts" clear
  11082. clr accEnr ; One of them set, no accEnr should be applied
  11083. jmp L1825 ; Bail
  11084.  
  11085. ;---------------------------------------------------
  11086. ; Skip section if injPw==0
  11087. ;---------------------------------------------------
  11088. L1815 ldd injPw ;
  11089. bne L1816 ; Branch if injPw !=0
  11090. jmp L1825 ; Bail
  11091.  
  11092. ;---------------------------------------------------
  11093. ; Section to factor acceleration/deceleration enrichment
  11094. ; to injPw (when injPw!=0)
  11095. ;---------------------------------------------------
  11096. ;---------------------------------------------------
  11097. ; Compute diff = airCnt0-oldAirCnt0
  11098. ; Check if positive or negative
  11099. ;---------------------------------------------------
  11100. L1816 clr decEnr ; Assume decEnr = 0
  11101. ldd airCnt0 ; d = airCnt0
  11102. subd oldAirCnt0 ; d = airCnt0-oldAirCnt0
  11103. bcs L1820 ; Branch if result negative
  11104.  
  11105. ;---------------------------------------------------
  11106. ; diff>=0 (airCnt0 increased or is unchanged)
  11107. ; Check if conditions are met to apply acceleration enrichment
  11108. ;---------------------------------------------------
  11109. tst accEnrTimer ; Check if timer expired
  11110. beq L1819 ; Bail if accEnrTimer expired (airflow has been below absolute threshold for more than 4 iterations)
  11111. brset port3, #$80, L1819 ; Bail if idle switch is on
  11112.  
  11113. ;----------------------------------
  11114. ; Check diff against max of $48
  11115. ;----------------------------------
  11116. tsta ; test hi part of diff
  11117. bne L1817 ; Branch if diff >=256 (hi(diff)!=0) -> use $48
  11118. cmpb #$48 ; diff <256 check low part against $48
  11119. bcs L1818 ; Branch if diff <$48
  11120. L1817 ldab #$48 ; use $48
  11121.  
  11122. ;---------------------------------------------------------------------------
  11123. ; At this point b contains diff=min(airCnt0-oldAirCnt0,$48)
  11124. ;
  11125. ; Update accEnr with diff if diff is big enough (big increase in airflow)
  11126. ; and higher than old accEnr
  11127. ;---------------------------------------------------------------------------
  11128. L1818 cmpb accEnrDiffT ;
  11129. bls L1819 ; Branch if diff<=accEnrDiffT
  11130. cmpb accEnr ; diff>accEnrDiffT store new value if higher than old one
  11131. bls L1819 ;
  11132. stab accEnr ; accEnr = min(airCnt0-oldAirCnt0,$48)
  11133. L1819 bra L1822 ;
  11134.  
  11135. ;---------------------------------------------------------
  11136. ;
  11137. ;
  11138. ; airCnt0 decreased check if below absolute threshold
  11139. ;
  11140. ;
  11141. ;---------------------------------------------------------
  11142. L1820 ldd airCnt0 ; d = airCnt0
  11143. cmpd accEnrMinAf ;
  11144. bcc L1822 ; Bail if airCnt0 >= accEnrMinAf
  11145.  
  11146. ;---------------------------------------------------------
  11147. ; airCnt0 decreased and is below absolute threshold
  11148. ; compute diff = min(airCnt0-oldAirCnt0,$ff)
  11149. ;---------------------------------------------------------
  11150. ldd oldAirCnt0 ;
  11151. subd airCnt0 ; d = oldAirCnt0-airCnt0
  11152. tsta ; test hi part (diff>=256?)
  11153. beq L1821 ; Branch if below max
  11154. ldab #$ff ; Use max of $ff
  11155.  
  11156. ;---------------------------------------------------------------------------
  11157. ; Clear accEnr if diff is big enough (big decrease in airflow)
  11158. ; At this point b contsains diff=min(airCnt0-oldAirCnt0,$ff)
  11159. ;---------------------------------------------------------------------------
  11160. L1821 cmpb accEnrDiffT ;
  11161. bls L1822 ;
  11162. stab decEnr ; decEnr = min(airCnt0-oldAirCnt0,$ff)
  11163. clr accEnr ; accEnr = 0
  11164.  
  11165. ;---------------------------------------------------
  11166. ; Section to add acceleration enrichment to injPw or
  11167. ; reduce it in case of deceleration
  11168. ;
  11169. ; Check if min(airCnt0-oldAirCnt0,$ff) >0
  11170. ;---------------------------------------------------
  11171. L1822 ldab decEnr ;
  11172. bne L1823 ; Branch if decEnr > 0 (reduce injPw)
  11173.  
  11174. ;---------------------------------------------------------------
  11175. ; decEnr = 0, increase or do not change injPw
  11176. ;
  11177. ; Apply enrichment:
  11178. ; injPw = injPw + accEnr*accEnrFact/256
  11179. ; = injPw + 8 * min(airCnt0-oldAirCnt0,$48) * injMasComp/256 * t_accEnr1(rpm)/128 * [t_accEnr2a(ect) or t_accEnr2b(ect)]/128 * baroFact/128
  11180. ;---------------------------------------------------------------
  11181. ldaa accEnr ; a = accEnr
  11182. ldab accEnrFact ; b = accEnrFact
  11183. mul ; d = accEnr * accEnrFact
  11184. xgdx ; x = accEnr * accEnrFact
  11185. ldaa accEnr ;
  11186. ldab accEnrFact+1 ;
  11187. mul ; d = accEnr * L0109
  11188. tab ; b = accEnr * L0109/256
  11189. abx ; x = accEnr * accEnrFact + accEnr * L0109/256 = accEnr*(accEnrFact + L0109/256)
  11190. xgdx ; d = accEnr*(accEnrFact + L0109/256)
  11191. addd injPw ; d = injPw + accEnr*accEnrFact/256
  11192. bcc L1824 ; Bail if no overflow
  11193. ldaa #$f0 ; Overflow, use max of $f000
  11194. bra L1824 ; Bail
  11195.  
  11196. ;---------------------------------------------------
  11197. ; decEnr > 0. decrease injPw
  11198. ;
  11199. ; Apply reduction
  11200. ; injPw = injPw - decEnr*decEnrFact/256
  11201. ; = injPw + 8 * min(airCnt0-oldAirCnt0,$ff) * injMasComp/256 * t_decEnr1(rpm)/128 * t_decEnr2(ect)/128 * baroFact/128
  11202. ;---------------------------------------------------
  11203. L1823 ldaa decEnr ; a = decEnr
  11204. ldab decEnrFact ; b = decEnrFact
  11205. mul ; d = decEnr * decEnrFact
  11206. xgdx ; x = decEnr * decEnrFact
  11207. ldaa decEnr ;
  11208. ldab decEnrFact+1 ;
  11209. mul ; d = decEnr * L010b
  11210. tab ; b = decEnr * L010b/256
  11211. abx ; x = decEnr * decEnrFact + decEnr * L010b/256
  11212. stx temp8 ; temp8:dTemp2 = decEnr * decEnrFact + decEnr * L010b/256 = decEnr*(decEnrFact+L010b/256)
  11213. ldd injPw ; d = injPw
  11214. subd temp8 ; d = injPw - decEnr*decEnrFact/256
  11215. bhi L1824 ; Bail if positive
  11216. clra ;
  11217. ldab #$01 ; Use min of $0001
  11218. L1824 std injPw ; Update injPw
  11219.  
  11220. ;---------------------------------------------------
  11221. ; Skip section if injPw==0
  11222. ;---------------------------------------------------
  11223. L1825 ldd injPw ;
  11224. bne L1826 ; Branch to do section when injPw!=0
  11225. jmp L1845 ; bail to next section
  11226.  
  11227. ;--------------------------------------------------------
  11228. ; injPw != 0, increment injCount if not already at max(255)
  11229. ;--------------------------------------------------------
  11230. L1826 inc injCount ;
  11231. bne L1827 ; Branch if injCount!=0
  11232. dec injCount ; injCount was 255 and is now 0, go back to max of 255
  11233.  
  11234. ;-------------------------------------------------
  11235. ; Load injPw in d and divide by 4 if necessary???
  11236. ;-------------------------------------------------
  11237. L1827 clr newInjToAct ; newInjToAct = 0
  11238. ldd injPw ;
  11239. brset state3, #$80, L1828 ; Branch if startingToCrankColdEngine
  11240. brclr tdcCasFlags, #$07, L1829 ; Branch if down counter = 0 (first TDC on cyl. #1 was already encoutered)
  11241.  
  11242. ;-------------------------------------------------------------------------------
  11243. ; Seems we are startingToCrank (TDC #1 not yet encountered) but engine is
  11244. ; not cold so divide injPw by 4 since the value it constains(injPwStart)
  11245. ; was multiplied by 4 in injPwStart culculations, why???
  11246. ;-------------------------------------------------------------------------------
  11247. lsrd ;
  11248. lsrd ; d = injPw/4 = injPwStart
  11249. L1828 orm newInjToAct, #$80 ; Set flag indicating we should be doing simultaneous injection
  11250.  
  11251. ;-------------------------------------------------------
  11252. ; Add injector deadtime and check for max and min value
  11253. ;-------------------------------------------------------
  11254. L1829 jsr addDeadtime ; Add deadtime to d
  11255. cmpa #$ea ;
  11256. bcs L1830 ; Branch if d < $ea00
  11257. ldaa #$ea ;
  11258. clrb ; Too big, use max of d=$ea00 (60ms)
  11259. L1830 cmpd #$0514 ;
  11260. bcc L1831 ; Branch if above minimum
  11261. ldd #$0514 ; Too small, use minimum of d=$0514 (1.3ms)
  11262. L1831 std injPw ; Store new value
  11263.  
  11264. ;--------------------------------------------------------------------------------
  11265. ; Schedule all 4 injector interrupts and bail if in simultaneous injection mode
  11266. ;--------------------------------------------------------------------------------
  11267. brclr newInjToAct, #$80, L1832 ; Branch if sequential injection
  11268. orm newInjToAct, #$0f ; Simultaneous injection, set mask corresponding to all 4 injectors
  11269. jsr schedInjSim ; Schedule simultaneous injection interrupts
  11270. jmp L1845 ; Bail to exit routine
  11271.  
  11272. ;---------------------------------------------------
  11273. ; At this point we are in sequential injection mode
  11274. ;---------------------------------------------------
  11275. ;------------------------------------------------------------------------------------
  11276. ; Get the injector mask of the injector to activate for this particular CAS interrupt
  11277. ; Injector for cylinder #1 starts injecting on the CAS falling edge of cylinder #3,
  11278. ; i.e. at the end on #1 combustion cycle/start of #1 exhaust cycle
  11279. ;
  11280. ; casCylIndex Cylinder number Injector number mask
  11281. ; having its TDC to activate on
  11282. ; closest to CAS CAS falling edge
  11283. ; falling edge
  11284. ; 0 1 2 $08
  11285. ; 1 3 1 $01
  11286. ; 2 4 3 $02
  11287. ; 3 2 4 $04
  11288. ;
  11289. ;------------------------------------------------------------------------------------
  11290. L1832 ldx #t_cylMask ; table content: [$08 $01 $02 $04] -> injector numbers: 2 1 3 4
  11291. ldab casCylIndex ; b = casCylIndex
  11292. abx ; x = t_cylMask + casCylIndex
  11293. ldaa $00,x ; a has one bit set to indicate which injector to use (one of $08 $01 $02 $04)
  11294.  
  11295. ;-------------------------------------------------------
  11296. ; Reset the mask if engine not running or if
  11297. ; disabled by an obd command or if ignition is not happening
  11298. ;-------------------------------------------------------
  11299. brset state3, #$11, L1833 ; Branch if notRotating or startingToCrank
  11300. brclr coilChkFlags, #$80, L1833 ; Branch if no ignition error found
  11301. anda coilChkFlags ; Reset the injectors corresponding to missing ignition signal
  11302. L1833 anda obdInjCmd ; Reset injector if disabled by OBD command
  11303.  
  11304. ;-------------------------------------------------------
  11305. ; Update newInjToAct, injToAct and last_t1t2_clk
  11306. ;-------------------------------------------------------
  11307. staa newInjToAct ; newInjToAct = injector to activate
  11308. oraa injToAct ;
  11309. staa injToAct ; injToAct = injToAct | newInjToAct
  11310. ldaa t1t2_clk ;
  11311. staa last_t1t2_clk ; last_t1t2_clk = t1t2_clk/256 (current timer 1 clock?)
  11312.  
  11313. ;----------------------------------------------------------------
  11314. ; Branch to section depending on new injector to activate
  11315. ;----------------------------------------------------------------
  11316. brset newInjToAct, #$0a, L1839 ; Branch if injector to activate is #2 or #3
  11317. brclr newInjToAct, #$05, L1845 ; Bail if remaining injector #1 and #4 don't need activation either
  11318.  
  11319. ;----------------------------------------------------------------
  11320. ; Injector to activate is #1 or #4, check if already activated
  11321. ;----------------------------------------------------------------
  11322. L1833b brclr port2, #$02, L1834 ; Branch if injector #1 activated (reverse logic)
  11323. brset port1, #$08, L1838 ; Branch if injector #4 deactivated (reverse logic)
  11324.  
  11325. ;------------------------------------------------------------------------------
  11326. ; Injector #1 or #4 already activated
  11327. ;
  11328. ; Check how much time remains before next interrupt occurs
  11329. ;------------------------------------------------------------------------------
  11330. L1834 ldd t1_outCmpWr ; d = nextInterruptTime
  11331. subd t1t2_clk ; remainingTime = d = nextInterruptTime - t1t2_clk
  11332. cmpd #$0032 ;
  11333. bcs L1835 ; Branch if remainingTime < $0032 (50us)
  11334. cmpd #$00c8 ;
  11335. bcc L1836 ; Branch if remainingTime >= $00c8 (200us)
  11336.  
  11337. ;--------------------------------------------------------
  11338. ; 50us <= remainingTime < 200us, remaining time before the
  11339. ; next interrupt is long enough to allow us to do something
  11340. ; but is not so long that activation will be too late...
  11341. ;
  11342. ; Enable injector activation bit and compute deactivation
  11343. ; time as nextInterruptTime + injPw Since the injector
  11344. ; will be enabled when the interrupt occur, very shortly.
  11345. ; Then exit this interrupt.
  11346. ;--------------------------------------------------------
  11347. bsr actDeact14 ; Enable injector activation bit and compute deactivation time
  11348. bra L1845 ; Bail of interrupt
  11349.  
  11350. ;--------------------------------------------------------
  11351. ; remainingTime < $0032 (50us). remaining time before the
  11352. ; next interrupt is too short to do what we need to do...
  11353. ; just wait for the interrupt to occur using an infinite
  11354. ; loop (2500 cycles?)
  11355. ;--------------------------------------------------------
  11356. L1835 brclr t1_csr, #$40, L1835 ;
  11357. ;--------------------------------------------------------------------------------
  11358. ; Interrupt has been triggered we can now proceed with activation
  11359. ;--------------------------------------------------------------------------------
  11360.  
  11361. ;------------------------------------------------------------------------------------
  11362. ; At this point the remainingTime before the next interrupt is larger than 200us
  11363. ; or it was smaller than 50us but we waited for the interrupt to occur. In both
  11364. ; cases, we are certain an interrupt will no happen right away, just do what needs
  11365. ; doing...
  11366. ;------------------------------------------------------------------------------------
  11367. ;---------------------------------------------------------------------------
  11368. ; First check if an injector is already activated and if so, just reflect
  11369. ; that fact in the activation bits (such that we don't change that injector
  11370. ; state when we activate a new injector...)???
  11371. ;---------------------------------------------------------------------------
  11372. L1836 brset port2, #$02, L1837 ; Branch if injector #1 is deactivated
  11373. andm t1_csr, #$fe ; injector #1 is activated, enable activation bit for it
  11374. L1837 brset port1, #$08, L1838 ; Branch if injector #4 is deactivated
  11375. andm t2_csr, #$df ; injector #4 is activated, enable activation bit for it
  11376.  
  11377. ;-----------------------------------------------------------------
  11378. ; Enable the activation bit for the new injector #1 or #4.
  11379. ; Schedule an interrupt for "now + 22us" to activate them.
  11380. ; Compute its deactivation time and schedule an interrupt for it
  11381. ;
  11382. ; I assume here that the 22us delay is small enough that it ensures
  11383. ; the injector activation will occur before the deactivation is scheduled???
  11384. ; not sure if interrupt subroutine is called in that case since we are
  11385. ; already in interrupt???????????
  11386. ;-----------------------------------------------------------------
  11387. L1838 ldd t1t2_clk ; d = t1t2_clk (current time)
  11388. addd #$0016 ; activationTime d = t1t2_clk + $16 (22us)
  11389. std t1_outCmpWr ; Schedule interrupt at t1_outCmpWr = t1t2_clk + $16, i.e. activationTime = now + 22us
  11390. bsr actDeact14 ; Enable new injector activation bit and compute deactivation time
  11391. jsr schedDeact14 ; Schedule deactivation time
  11392. bra L1845 ; Bail
  11393.  
  11394. ;-----------------------------------------------------
  11395. ; Injector to activate is #2 or #3
  11396. ; Logic is identical to #1 #4 injectors
  11397. ; above starting at L1833b ......
  11398. ;-----------------------------------------------------
  11399. L1839 brclr port1, #$02, L1840 ; Injector 3
  11400. brset port1, #$04, L1844 ; Injector 2
  11401. L1840 ldd t2_outCmpWr ;
  11402. subd t1t2_clk ;
  11403. cmpd #$0032 ;
  11404. bcs L1841 ;
  11405. cmpd #$00c8 ;
  11406. bcc L1842 ;
  11407. bsr actDeact23 ;
  11408. bra L1845 ;
  11409. L1841 brclr t2_csr, #$40, L1841 ; Infinite loop waiting for interrupt to be triggered
  11410. L1842 brset port1, #$02, L1843 ;
  11411. andm t2_csr, #$fe ;
  11412. L1843 brset port1, #$04, L1844 ;
  11413. andm t2_csr, #$fb ;
  11414. L1844 ldd t1t2_clk ;
  11415. addd #$0016 ;
  11416. std t2_outCmpWr ;
  11417. bsr actDeact23 ;
  11418. jsr schedDeact23 ;
  11419.  
  11420. ;-------
  11421. ; Exit
  11422. ;-------
  11423. L1845 rti ;
  11424. ;
  11425.  
  11426. ;******************************************************************
  11427. ;
  11428. ; Enable injector activation bit for injector #1 or #4
  11429. ; and calculate the corresponding injector deactivation time
  11430. ;
  11431. ;
  11432. ;
  11433. ;******************************************************************
  11434. actDeact14 ldd t1_outCmpWr ;
  11435. addd injPw ; d = t1_outCmpWr + injPw
  11436. brset newInjToAct, #$04, L1847 ; Branch if inj #4 needs activation
  11437.  
  11438. ;--------------------------------
  11439. ; Injector #1 needs activation
  11440. ;--------------------------------
  11441. andm t1_csr, #$fe ; Reset injector #1 bit
  11442. std inj1_offT ; inj1_offT = t1_outCmpWr + injPw
  11443. bra L1848 ; Bail
  11444.  
  11445. ;--------------------------------
  11446. ; Injector #4 needs activation
  11447. ;--------------------------------
  11448. L1847 andm t2_csr, #$df ; Reset injector #4 bit
  11449. std inj4_offT ; inj4_offT = t1_outCmpWr + injPw
  11450. L1848 rts ;
  11451.  
  11452.  
  11453.  
  11454. ;******************************************************************
  11455. ;
  11456. ; Enable injector activation bit for injector #1 or #4
  11457. ; and calculate the corresponding injector deactivation time
  11458. ;
  11459. ;
  11460. ;
  11461. ;******************************************************************
  11462. actDeact23 ldd t2_outCmpWr ;
  11463. addd injPw ; d = t1_outCmpWr + injPw
  11464. brset newInjToAct, #$08, L1850 ;
  11465.  
  11466. ;--------------------------------
  11467. ; Injector #3 needs activation
  11468. ;--------------------------------
  11469. andm t2_csr, #$fe ; Reset injector #3 bit (enable output compare interrupt???)
  11470. std inj3_offT ;
  11471. bra L1851 ;
  11472.  
  11473. ;--------------------------------
  11474. ; Injector #2 needs activation
  11475. ;--------------------------------
  11476. L1850 andm t2_csr, #$fb ; Reset injector #2 bit
  11477. std inj2_offT ;
  11478. L1851 rts ;
  11479.  
  11480.  
  11481.  
  11482. ;******************************************************************
  11483. ;
  11484. ; Table used to determine which cylinder/injector the current
  11485. ; CAS interrupt corresponds to. The table contains injector bit masks
  11486. ;
  11487. ;
  11488. ; t_cylMask[casCylIndex] -> cylinder numbers: 2 1 3 4
  11489. ;
  11490. ;
  11491. ;******************************************************************
  11492. t_cylMask .byte $08, $01, $02, $04
  11493.  
  11494.  
  11495.  
  11496. ;******************************************************************
  11497. ;
  11498. ; Output compare interrupt1
  11499. ;
  11500. ; Triggered by injector #1 and #4 activation/deactivation
  11501. ;
  11502. ;
  11503. ;******************************************************************
  11504. outCompInt1 ldaa t1_csr ; Ack interrupt?
  11505. ldd t1_outCmpWr ;
  11506. std t1_outCmpWr ; Flush the output compare value that triggered the current interrupt???
  11507. jsr schedDeact14 ; Schedule deactivation time
  11508.  
  11509. ;------------------------------------------
  11510. ; Branch to execute rest of subroutine...
  11511. ;------------------------------------------
  11512. bra L1855
  11513.  
  11514.  
  11515.  
  11516. ;******************************************************************
  11517. ;
  11518. ; Output compare interrupt2
  11519. ;
  11520. ; Triggered by injector #2 and #3 activation/deactivation
  11521. ;
  11522. ;
  11523. ;******************************************************************
  11524. outCompInt2 ldaa t2_csr ; Ack interrupt?
  11525. ldd t2_outCmpWr ;
  11526. std t2_outCmpWr ; Flush the output compare value that triggered the current interrupt???
  11527. jsr schedDeact23 ; Schedule deactivation time
  11528.  
  11529. ;------------------------------------------
  11530. ; Perform injector testing and update
  11531. ; simultaneous injection mode if required
  11532. ;------------------------------------------
  11533. L1855 jsr injUpdate0 ;
  11534. rti ;
  11535.  
  11536.  
  11537.  
  11538. ;******************************************************************
  11539. ;
  11540. ; Schedule injector #1 and #4 deactivation
  11541. ; time interrupt if necessary
  11542. ;
  11543. ;
  11544. ;******************************************************************
  11545. ;-----------------------------------
  11546. ; Update oldInjToAct and injToAct
  11547. ;-----------------------------------
  11548. schedDeact14 ldaa injToAct ; a = injToAct
  11549. staa oldInjToAct ; oldInjToAct = old injToAct
  11550. brclr port2, #$02, L1857 ; Branch if injector #1 is activated
  11551. anda #$fe ; Reset injector #1 bit
  11552. L1857 brclr port1, #$08, L1858 ; Branch if injector #4 is activated
  11553. anda #$fb ; Reset injector #4 bit
  11554. L1858 staa injToAct ; Update injToAct
  11555.  
  11556. ;--------------------------------------------------------------------------
  11557. ; Clear sInjPw if injectors from both banks are activated (1 or 4 and 2 or 3)
  11558. ;--------------------------------------------------------------------------
  11559. brclr oldInjToAct, #$05, L1860 ; Branch if both inj #1 and #4 are not activated
  11560. brclr port1, #$04, L1859 ; inj #1 or #4 activated, branch if #2 activated (sim injection on)
  11561. brset port1, #$02, L1860 ; Branch if #3 not activated (sim injection off
  11562. L1859 clr sInjPw ; clear sInjPw and sInjPw+1
  11563. clr sInjPw+1 ;
  11564.  
  11565. ;----------------------------------
  11566. ; Find which of #1 or #4 is active
  11567. ;----------------------------------
  11568. L1860 brclr port2, #$02, L1861 ; Branch if inj #1 activated
  11569. brset port1, #$08, L1866 ; Bail if inj #4 is also deactivated (none activated)
  11570. bra L1862 ; Only inj #4 activated, branch to deactivate it
  11571.  
  11572. ;------------------------------
  11573. ; Inj #1 activated, check #4
  11574. ;------------------------------
  11575. L1861 brset port1, #$08, L1864 ; Branch if #4 deactivated
  11576.  
  11577. ;--------------------------
  11578. ; Inj #1 and #4 activated
  11579. ;--------------------------
  11580. ldx #inj1_offT ; x points to injectors deactivation time table
  11581. jsr injRemTime ; Compute injection remaining time for #1 and #4, a = remTime1, b = remTime4
  11582. sba ; a = remTime1 - remTime4
  11583. bcs L1863 ; Branch if remTime1 < remTime4
  11584.  
  11585. ;---------------------------------------------------------------------------------
  11586. ; Inj #1 and #4 are activated and remTime1 >= remTime4
  11587. ;
  11588. ; This would mean we are in #1 combustion cycle. In that case, we would
  11589. ; deactivate inj #4 first (since it has been injecting for a long time by now)
  11590. ; and eventually inj #1 (which has just started injecting)
  11591. ;
  11592. ; Branch to disable only inj #4 if remTime1 - remTime4 > 1.024ms
  11593. ;---------------------------------------------------------------------------------
  11594. cmpa #$04 ;
  11595. bhi L1862 ; Branch if remTime1-remTime4 > 4 (1.024ms)
  11596.  
  11597. ;--------------------------------------------------------------------
  11598. ; remTime1-remTime4 <= 4 (1.024ms). This means both injectors will
  11599. ; be disabled at about the same time, just deactivate both
  11600. ; of them at that time...
  11601. ;
  11602. ; Disable the activation bit for inj. #1 and #4 (two lines below)
  11603. ; and use inj. #4 deactivation time
  11604. ;--------------------------------------------------------------------
  11605. orm t1_csr, #$01 ; Disable the activation bit for inj. #1
  11606.  
  11607. ;-----------------------------------------
  11608. ; Disable the activation bit for inj. #4
  11609. ; and load deactivation time in d
  11610. ;-----------------------------------------
  11611. L1862 orm t2_csr, #$20 ; Disable the activation bit for inj. #4
  11612. ldd inj4_offT ; d = inj4_offT, injector #4 deactivation time
  11613. bra L1865 ; Branch to schedule deactivation interrupt
  11614.  
  11615. ;--------------------------------------------------------------------------------------
  11616. ; Inj #1 and #4 are activated and remTime1 < remTime4
  11617. ; This would mean we are in #4 combustion cycle. In that case,
  11618. ;--------------------------------------------------------------------------------------
  11619. L1863 nega ; make result positive, a = remTime4 - remTime1
  11620. cmpa #$04 ;
  11621. bhi L1864 ; Branch if remTime4 - remTime1 > 4 (1.024ms)
  11622.  
  11623. ;--------------------------------------------------------------------
  11624. ; remTime4-remTime1 <= 4 (1.024ms). This means both injectors will
  11625. ; be disabled at about the same time, just deactivate both
  11626. ; of them at that time???
  11627. ;
  11628. ; Disable the activation bit for inj. #4 and #1 (two lines below)
  11629. ; and use inj. #1 deactivation time
  11630. ;--------------------------------------------------------------------
  11631. orm t2_csr, #$20 ; Disable the activation bit for inj. #4
  11632.  
  11633. ;-----------------------------------------
  11634. ; Disable the activation bit for inj. #1
  11635. ; and load deactivation time in d
  11636. ;-----------------------------------------
  11637. L1864 orm t1_csr, #$01 ; Disable the activation bit for inj. #1
  11638. ldd inj1_offT ; d = inj1_offT, i.e. inj #1 deactivation time
  11639.  
  11640. ;--------------------------------------------------------------------------
  11641. ; Validate deactivation time and write to timer 1 output compare register
  11642. ;--------------------------------------------------------------------------
  11643. L1865 bsr validDeactT ; Validate deactivation time
  11644. ldx t1_csr ; Read t1_csr and t1t2_clk??? sequence to follow I assume but it is different from schedDeact23???
  11645. std t1_outCmpWr ; Write next interrupt time
  11646. L1866 rts ;
  11647.  
  11648.  
  11649.  
  11650. ;******************************************************************
  11651. ;
  11652. ; Schedule injector #2 and #3 deactivation time interrupt
  11653. ;
  11654. ; Logic is identical to the actDeact14 subroutine
  11655. ;
  11656. ;
  11657. ;******************************************************************
  11658. schedDeact23 ldaa injToAct ;
  11659. staa oldInjToAct ;
  11660. brclr port1, #$04, L1868 ;
  11661. anda #$f7 ;
  11662. L1868 brclr port1, #$02, L1869 ;
  11663. anda #$fd ;
  11664. L1869 staa injToAct ;
  11665. brclr oldInjToAct, #$0a, L1871 ;
  11666. brclr port1, #$08, L1870 ;
  11667. brset port2, #$02, L1871 ;
  11668. L1870 clr sInjPw ;
  11669. clr sInjPw+1 ;
  11670. L1871 brclr port1, #$04, L1872 ;
  11671. brset port1, #$02, L1877 ;
  11672. bra L1875 ;
  11673. L1872 brset port1, #$02, L1873 ;
  11674. ldx #$00ab ;
  11675. bsr injRemTime ;
  11676. sba ;
  11677. bcs L1874 ;
  11678. cmpa #$04 ;
  11679. bhi L1873 ;
  11680. orm t2_csr, #$01 ;
  11681. L1873 orm t2_csr, #$04 ;
  11682. ldd inj2_offT ;
  11683. bra L1876 ;
  11684. L1874 nega ;
  11685. cmpa #$04 ;
  11686. bhi L1875 ;
  11687. orm t2_csr, #$04 ;
  11688. L1875 orm t2_csr, #$01 ;
  11689. ldd inj3_offT ;
  11690.  
  11691. ;--------------------------------------------------------------------------
  11692. ; Validate deactivation time and write to timer 2 output compare register
  11693. ; sequence is different compared to schedDeact14?????? (and the t1 and t2
  11694. ; control registers are also different????)
  11695. ;--------------------------------------------------------------------------
  11696. L1876 bsr validDeactT
  11697. std t2_outCmpWr
  11698. L1877 rts
  11699.  
  11700.  
  11701.  
  11702. ;******************************************************************
  11703. ;
  11704. ; Check injector deactivation time for validity
  11705. ;
  11706. ; Input:
  11707. ; d = deactTime = injector deactivation time
  11708. ;
  11709. ;
  11710. ; Output:
  11711. ; d = deactTime or current time + 20us if deactTime>61ms
  11712. ;
  11713. ;******************************************************************
  11714. validDeactT std temp8 ; temp8 = deactTime
  11715. subd #$0014 ; d = deactTime - $14 (20us)
  11716. subd t1t2_clk ; remTime = d = deactTime - $14 - t1t2_clk (remaining time until deactivation - 20us)
  11717. cmpd #$ee00 ;
  11718. ldd temp8 ; d = deactTime
  11719. bcs L1879 ; Branch if remTime < $ee00 (61ms)
  11720.  
  11721. ;---------------------------------------------
  11722. ; Remaining time too high, deactivate in 20us
  11723. ;---------------------------------------------
  11724. ldd t1t2_clk ; d = t1t2_clk
  11725. addd #$0014 ; d = t1t2_clk + 20us
  11726. L1879 rts ;
  11727.  
  11728.  
  11729.  
  11730. ;******************************************************************
  11731. ;
  11732. ; Compute the remainingInjectionTime/256 for injectors #1 and #4 (or #2 and #3)
  11733. ; remaining time might be measured from the most recent CAS falling edge since
  11734. ; that is what last_t1t2_clk contains... However the function might also be called
  11735. ; just after last_t1t2_clk has been updated... but not always??? In any case, the
  11736. ; difference between the two remaining times is the most important...
  11737. ;
  11738. ; Input:
  11739. ; x: points to inj1_offT or inj3_offT (injector deactivation time table)
  11740. ;
  11741. ; Output:
  11742. ; a = 0 if inj #1 (or #2) remaining injection time > 61ms else remaining injection time/256
  11743. ; b = 0 if inj #4 (or #3) remaining injection time > 61ms else remaining injection time/256
  11744. ;
  11745. ; Basically a and b are the remainingActivationTime/256
  11746. ; or 0 if it doesn't make sense (i.e. > 61ms)
  11747. ;
  11748. ;******************************************************************
  11749. injRemTime ldaa $00,x ; a = inj1_offT/256
  11750. suba last_t1t2_clk ; a = inj1_offT - last_t1t2_clk
  11751. cmpa #$ee ;
  11752. bcs L1881 ; Branch if inj1_offT - last_t1t2_clk <$ee (61ms)
  11753. clra ; a = 0
  11754.  
  11755. L1881 ldab $04,x ; b = inj4_offT/256
  11756. subb last_t1t2_clk ; b = inj4_offT/256 - last_t1t2_clk
  11757. cmpb #$ee ;
  11758. bcs L1882 ; Branch if inj1_offT - last_t1t2_clk <$ee (61ms)
  11759. clrb ; b = 0
  11760. L1882 rts ;
  11761.  
  11762.  
  11763.  
  11764. ;******************************************************************
  11765. ;
  11766. ; Called on every injector activation/deactivation (output compare)
  11767. ;
  11768. ; Tests injector feedback bit if time has come and
  11769. ; perform simultaneous injection activation/deactivation if
  11770. ; required
  11771. ;
  11772. ;
  11773. ;******************************************************************
  11774. ;------------------------------------------------------------------
  11775. ; Check whether we should test the injectors for proper operation
  11776. ;------------------------------------------------------------------
  11777. injUpdate0 ldaa injToTest ; a = injToTest
  11778. cmpa oldInjToAct ;
  11779. bne L1885 ; Bail if injToTest != oldInjToAct, i.e. the injector to test was not the one and only one activated
  11780. brset injToAct, #$0f, L1885 ; Bail if any injector currently activated
  11781.  
  11782. ;--------------------------------------------------------------------------------
  11783. ; At this point, we know that the current injector to test was
  11784. ; active in the past (oldInjToAct) and that it is not active anymore
  11785. ; (injToAct). Basically, we know that the injector to test was just
  11786. ; deactivated and no other injector is currently active.
  11787. ;
  11788. ; port4.7 might be loaded on the falling edge of the injector driving current???
  11789. ;--------------------------------------------------------------------------------
  11790. ;------------------------------------------------------------------
  11791. ; Check feedback flag to know if injector is working correctly???
  11792. ;------------------------------------------------------------------
  11793. brclr port4, #$80, L1884 ; Branch if injector flag shows it is OK?
  11794. orm injBad, #$01 ; Set bit indicating injectors is bad?
  11795. bra L1885 ; Branch to rest of code, we will continue testing the same injector.
  11796.  
  11797. ;--------------------------------------------------------------
  11798. ; Injector is OK, reset injBad flag and go to next injToTest
  11799. ;--------------------------------------------------------------
  11800. L1884 asla ; a = injToTest<<1, go to next injector to test
  11801. andm injBad, #$fe ; Reset bit indicating injectors is bad?
  11802.  
  11803. ;-------------------
  11804. ; Update injToTest
  11805. ;-------------------
  11806. L1885 anda #$0f ; Keep only 4 bits, 4 injectors to test
  11807. bne L1886 ; Branch if any injector bit left
  11808. ldaa #$01 ; Nothing left, restart testing with injector at bit 0
  11809. L1886 staa injToTest ; Update injToTest
  11810. ;-----------------------------------
  11811. ; Code continues in function below......
  11812. ;-----------------------------------
  11813. ;;;;; bra simInject
  11814.  
  11815.  
  11816.  
  11817.  
  11818.  
  11819. ;******************************************************************
  11820. ;
  11821. ; Simultaneous injection code called every 10ms from real time
  11822. ; interrupt or from above code continuation. sInjPw is cleared
  11823. ; if sim. injection is actually scheduled such that even if it
  11824. ; is called from multiple places, sim. injection will only happen
  11825. ; once every time sInjPw is re-loaded...
  11826. ;
  11827. ;
  11828. ;******************************************************************
  11829. ;----------------------------------------------------------------------------
  11830. ; Bail out of function if any injectors are set in injToAct
  11831. ; (rest of function is for simultaneous injection and all bit should be 0?)
  11832. ;----------------------------------------------------------------------------
  11833. simInject brset injToAct, #$0f, L1897 ; branch if any injector bit set
  11834.  
  11835. ;-------------------------------------------------------
  11836. ; All injectors are currently off, we can therefore
  11837. ; proceed with simultaneous injection if sInjPw >256us
  11838. ;
  11839. ; Update injPw from sInjPw if larger than 256us
  11840. ;-------------------------------------------------------
  11841. ldd sInjPw ; d = sInjPw
  11842. tsta ;
  11843. beq L1897 ; Bail of subroutine if sInjPw/256 = 0 (sInjPw<256us), too small....
  11844. clr sInjPw ;
  11845. clr sInjPw+1 ; clear sInjPw
  11846. bsr addDeadtime ; Add deadTime
  11847. std injPw ; injPw = sInjPw + deatTime
  11848.  
  11849. ;------------------------------------------------------------
  11850. ; Round injPw up to specific values if within some ranges,
  11851. ; Not quite sure why but I think that when the
  11852. ; injection time becomes small, injection time is less
  11853. ; predictable or simply non linear in some ranges... In
  11854. ; any case, since these times include the deadtime, they are
  11855. ; quite small..., not sure any fuel will actually come out?
  11856. ;
  11857. ; injPw <= 840us -> 840us
  11858. ; 840us < injPw <= 960us -> no change
  11859. ; 960us < injPw <= 1100us -> 1100us
  11860. ; 1100us < injPw -> no change
  11861. ;------------------------------------------------------------
  11862. ldd #$0348 ;
  11863. cmpd1 injPw ;
  11864. bcc L1888 ; Branch to use $0348 if injPw <= $0348 (840us)
  11865. ldd #$03c0 ;
  11866. cmpd1 injPw ;
  11867. bcc L1889 ; Branch to use injPw if injPw <= $03c0 (960us)
  11868. ldd #$044c ;
  11869. cmpd1 injPw ;
  11870. bcs L1889 ; Branch to use injPw if injPw > $044c (1100us)
  11871. L1888 std injPw ;
  11872.  
  11873. ;------------------------------------------------------
  11874. ; Update newInjToAct, start with all injectors
  11875. ; active and remove the ones disabled by obd
  11876. ; and the ones corresponding to missing ignition
  11877. ; signals
  11878. ;------------------------------------------------------
  11879. L1889 ldaa #$0f ; All 4 injectors set by default
  11880. brset state3, #$01, L1891 ; Branch if startingToCrank
  11881. brclr coilChkFlags, #$80, L1890 ; Branch if no error found on ignition
  11882. anda coilChkFlags ; Disable injectors corresponding to missing ignition
  11883. L1890 anda obdInjCmd ; Disable injectors that are off on purpose (OBD)
  11884. L1891 staa newInjToAct ; Update newInjToAct
  11885.  
  11886. ;-----------------------------------
  11887. ; Code continues in function below......
  11888. ;-----------------------------------
  11889. ;;;;; bra schedInjSim
  11890.  
  11891.  
  11892.  
  11893.  
  11894. ;******************************************************************
  11895. ;
  11896. ; Function to schedule interrupts for injectors activation and
  11897. ; deactivation in the case of simultaneous injection. Called from
  11898. ; main code and from above code continuation...
  11899. ;
  11900. ; Simulataneous injection can be either when startingToCrank or
  11901. ; when starting a cold engine or during acceleration (sInjEnr)
  11902. ;
  11903. ; injPw need to be initialized with the proper value (e.g. sInjPw)
  11904. ; prior to calling this function
  11905. ;
  11906. ;******************************************************************
  11907. ;--------------------
  11908. ; Update last_t1t2_clk
  11909. ;--------------------
  11910. schedInjSim ldd t1t2_clk ; a = t1t2_clk, current time
  11911. staa last_t1t2_clk ; last_t1t2_clk = t1t2_clk/256
  11912.  
  11913. ;------------------------------------------------------
  11914. ; Schedule interrupt in 2.048ms
  11915. ;
  11916. ; This might be to revert to previous injector
  11917. ; settings after 2.048ms ???? t1_outCmpWr
  11918. ; and t2_outCmpWr would need to be triple buffered???
  11919. ;------------------------------------------------------
  11920. adda #$08 ; d = t1t2_clk + 8*256 (2.048ms)
  11921. std t1_outCmpWr ; Store interrupt time for injector #1 and #4
  11922. std t2_outCmpWr ; Store interrupt time for injector #2 and #3
  11923.  
  11924. ;--------------------
  11925. ; Update injToAct
  11926. ;--------------------
  11927. ldaa newInjToAct ;
  11928. anda #$3f ; Keep only lower 6 bits (6 injectors max?)
  11929. staa injToAct ;
  11930.  
  11931. ;-------------------------------------------------------------------
  11932. ; Reset bit of t1_csr and t2_csr according to activated injectors
  11933. ;-------------------------------------------------------------------
  11934. ldaa newInjToAct ; a = newInjToAct
  11935. rora ; transfer bit 0 to carry
  11936. bcc L1893 ; Branch if injector 1 is off
  11937. andm t1_csr, #$fe ; Injector 1 is activated, reset bit
  11938. L1893 rora ;
  11939. bcc L1894 ; Branch if injector 3 is off
  11940. andm t2_csr, #$fe ; Injector 3 is activated, reset bit
  11941. L1894 rora ;
  11942. bcc L1895 ; Branch if injector 4 is off
  11943. andm t2_csr, #$df ; Injector 4 is activated, reset bit
  11944. L1895 rora ;
  11945. bcc L1896 ; Branch if injector 2 is off
  11946. andm t2_csr, #$fb ; Injector 2 is activated, reset bit
  11947.  
  11948. ;-------------------------------------------------------------
  11949. ; Schedule interrupts to activate specified injectors in 10us
  11950. ;-------------------------------------------------------------
  11951. L1896 ldd t1t2_clk ; d = t1t2_clk
  11952. addd #$000a ; d = t1t2_clk + 10us
  11953. std t1_outCmpWr ; Turn injector on in 10us.
  11954. std t2_outCmpWr ; Turn injector on in 10us.
  11955.  
  11956. ;-------------------------------------------------------------
  11957. ; Compute and store deactivation time
  11958. ; (common to all injectors when using simultaneous injection)
  11959. ;-------------------------------------------------------------
  11960. addd injPw ; d = t1t2_clk + 10us + injPw
  11961. std inj1_offT ;
  11962. std inj3_offT ;
  11963. std inj4_offT ;
  11964. std inj2_offT ;
  11965.  
  11966. ;------------------------------------------------------------------------
  11967. ; Schedule interrupts to deactivate all injectors at the specified time
  11968. ;------------------------------------------------------------------------
  11969. orm t1_csr, #$01 ; Set bit for injector 1
  11970. orm t2_csr, #$25 ; Set bits for injector 3 4 and 2
  11971. std t1_outCmpWr ; Turn injector off at that time?
  11972. std t2_outCmpWr ; Turn injector off at that time?
  11973. L1897 rts
  11974.  
  11975.  
  11976.  
  11977. ;******************************************************************
  11978. ;
  11979. ;
  11980. ; Injectors, add $18*deadTime to injPw (in d)
  11981. ;
  11982. ; deadTime is in increment of 24us and injPw in increment of 1us
  11983. ;
  11984. ;
  11985. ;******************************************************************
  11986. addDeadtime std temp8 ; temp8 = injPw
  11987. ldaa deadTime ; a = deadTime
  11988. ldab #$18 ; b = $18
  11989. mul ; d = $18*deadTime
  11990. addd temp8 ; d = injPw + $18*deadTime
  11991. bcc L1899 ; Branch if no overflow
  11992. ldaa #$ff ; Use max of ~$ff00 (65.3ms)
  11993. L1899 rts ;
  11994.  
  11995.  
  11996.  
  11997. ;******************************************************************
  11998. ;
  11999. ; Input capture interrupt 2
  12000. ;
  12001. ; This interrupt is triggered whenever the
  12002. ; airflow sensor emits one pulse
  12003. ;
  12004. ;******************************************************************
  12005. inCaptInt2 ldaa t2_csr ; ack/reset interrupt/timer control ???
  12006. bsr masProc
  12007. rti
  12008.  
  12009.  
  12010.  
  12011. ;******************************************************************
  12012. ;
  12013. ; Mas airflow pulse accumulator subroutine
  12014. ;
  12015. ; Called from interrupt and code (polling)
  12016. ;
  12017. ; Assumptions: t2_csr.1 controls the input capture trigger edge
  12018. ; polarity. This would imply (from mafraw calculations)
  12019. ; that the airflow sensor pulse frequency is
  12020. ; divided by two by the ECU circuitry. In that case,
  12021. ; counting edges (changing polarity through t2_csr.1
  12022. ; on every interrupt) would correspond to counting
  12023. ; airflow sensor pulses.
  12024. ;
  12025. ; Under low airflow, it is called on every rising and falling
  12026. ; edge of incoming signal (airflow sensor frequency/2) and it is
  12027. ; therefore called on every airflow sensor pulse.
  12028. ;
  12029. ; When large airflow is detected or when the time between each
  12030. ; interrupt becomes small, it is called only once for every 2
  12031. ; airflow sensor pulses (called scaling) in order to reduce
  12032. ; the number of interrupts per sec (CPU load).
  12033. ;
  12034. ; airCntNew0:airCntNew1 is increased by airQuantum = $9c on every
  12035. ; call (rising and falling edge) or by 2*airQuantum if we are
  12036. ; scaling.
  12037. ;
  12038. ;******************************************************************
  12039. ;----------------------------------------------
  12040. ; Compute t2_diff8 and update t2_lastMas
  12041. ;----------------------------------------------
  12042. masProc ldd t2_inCapt ; Read current input capture timer value
  12043. subd t2_lastMas ; D = t2_inCapt-t2_lastMas
  12044. ldx #T200_mas ;
  12045. jsr masFunc1 ; D = (t2_inCapt-t2_lastMas)/8 with timer based rounding???
  12046. std t2_diff8 ; t2_diff8 = (t2_inCapt-t2_lastMas)/8 with timer based rounding (see masFunc1)
  12047. ldd t2_inCapt ;
  12048. std t2_lastMas ; t2_lastMas = t2_inCapt
  12049.  
  12050. ;-----------------------------------
  12051. ; Re-init counter used in masFunc1
  12052. ;-----------------------------------
  12053. ldaa #$1a ; 130ms
  12054. staa T200_mas ;
  12055.  
  12056. ;--------------------------------------
  12057. ; Add scaled airQuantum to airCntNew0
  12058. ;--------------------------------------
  12059. clra ;
  12060. ldab airQuantum ; d = airQuantum
  12061. brclr masCasFlags, #$80, L1902 ; Branch if no scaling
  12062. asld ; scale d = 2*airQuantum
  12063. L1902 addd airCntNew0 ; d = airCntNew0 + airQuantum
  12064. bne L1903 ; Branch if result not null
  12065. incb ; Result is null, use min of 1
  12066. L1903 std airCntNew0 ; Store airCntNew0 = max(airCntNew0 + airQuantum, 1)
  12067.  
  12068. ;----------------------------------
  12069. ; Re-init airQuantum with #9c
  12070. ;----------------------------------
  12071. ldaa #$9c ;
  12072. staa airQuantum ; airQuantum = $9C
  12073.  
  12074. ;----------------------------------
  12075. ; Check if we are using scaling
  12076. ;----------------------------------
  12077. brset masCasFlags, #$80, L1905 ; branch if scaling by two
  12078.  
  12079.  
  12080. ;-----------------------------------------------------------
  12081. ; We are not scaling, check if that needs to change
  12082. ; Either if airVol is high (i.e. airVol > $6b, corresponds
  12083. ; to about 0.4gramOfAir) or if airflow sensor pulse
  12084. ; frequency is high (>500Hz)
  12085. ;-----------------------------------------------------------
  12086. ldaa airVol ;
  12087. cmpa #$6b ;
  12088. ldd t2_diff8 ; preload d = t2_diff8
  12089. bhi L1904 ; branch if airVol > $6b
  12090. cmpd #$00fa ; $fa*8/1MHz = 2ms -> 500Hz
  12091. bcc L1907 ; Branch if t2_diff8 > $00fa (freq<500Hz)
  12092.  
  12093. ;----------------------------------------------------------------------------
  12094. ; At this point we were not scaling by 2 but airVol>$6b or t2_diff8 < $00fa
  12095. ; (freq>500Hz) we need to activate scaling
  12096. ;----------------------------------------------------------------------------
  12097. L1904 asld ; t2_diff8 = t2_diff8*2
  12098. orm masCasFlags, #$80 ; set scaling bit
  12099. bra L1906 ; Go to rest of code
  12100.  
  12101. ;------------------------------------------------------
  12102. ; We were scaling by 2, check if that needs to change
  12103. ;------------------------------------------------------
  12104. L1905 ldaa airVol ;
  12105. cmpa #$6b ;
  12106. ldd t2_diff8 ; preload d=t2_diff8
  12107. bhi L1906 ; branch if airVol>$6b
  12108. cmpd #$0271 ; airVol<=$6B
  12109. bcs L1906 ; Branch if t2_diff8 < $0271
  12110.  
  12111. ;----------------------------------------------------------------------------
  12112. ; At this point, we were scaling by 2 but airVol<=$6B and t2_diff8 > $271
  12113. ; we can therefore go back to no scaling
  12114. ;----------------------------------------------------------------------------
  12115. lsrd ; t2_diff8 = t2_diff8/2
  12116. andm masCasFlags, #$7f ; reset scaling bit
  12117.  
  12118. ;----------------------------------
  12119. ; Update t2_diff8
  12120. ;----------------------------------
  12121. L1906 std t2_diff8 ; store new value
  12122.  
  12123. ;-------------------------------------------------------------------------------
  12124. ; Change the interrupt trigger polarity if we are not scaling since in that case
  12125. ; we want interrupts on both rising and falling edges of the incomming signal pulse
  12126. ; In case of scaling by 2, the polarity remains the same on every interrupt and
  12127. ; we therefore only receive interrupts on every two edges...
  12128. ;-------------------------------------------------------------------------------
  12129. L1907 brset masCasFlags, #$80, L1908 ; branch if we are scaling
  12130. ldaa t2_csr ; We are not scaling, switch edge trigger polarity
  12131. eora #$02 ; switch edge trigger polarity
  12132. staa t2_csr ;
  12133.  
  12134. ;----------------------------
  12135. ; Restart timer and return
  12136. ;----------------------------
  12137. L1908 ldaa #$0c
  12138. staa T40_mas
  12139. rts
  12140.  
  12141.  
  12142.  
  12143. ;******************************************************************
  12144. ;
  12145. ; Divide the time between airflow sensor pulse by 8 with a
  12146. ; timer based rounding???
  12147. ;
  12148. ; Input is the time between two airflow sensor pulse in D
  12149. ;
  12150. ; Input is also X which points to the timer T200_mas which is init
  12151. ; to 130ms on every airflow sensor pulse receied.
  12152. ;
  12153. ; output: D = D/8 with timer based rounding if timer not expired (not 0)
  12154. ; D = 3FFF otherwise
  12155. ;
  12156. ;******************************************************************
  12157. masFunc1 lsrd ;
  12158. lsrd ;
  12159. lsrd ; d = diff/8
  12160. std temp8 ; temp8 = diff/8
  12161. ldaa $00,x ; a = timer value
  12162. tsta ; why test, we just loaded in A??????
  12163. bne L1910 ; Branch if counter not zero
  12164.  
  12165. ;-------------------------------
  12166. ; Timer expired, return max value
  12167. ;-------------------------------
  12168. ldd #$3fff ; If timer expired, return $3fff
  12169. bra L1913 ;
  12170.  
  12171. ;-----------------------------------------------
  12172. ; Timer not expired, calculate value to return
  12173. ; based on timeLeft (in ms)
  12174. ;
  12175. ; 0 <= timeLeft < 50 -> diff/8 | $2000
  12176. ;
  12177. ; 50 <= timeLeft < 80
  12178. ; $diff/8 < $1000 -> diff/8 | $2000
  12179. ; $diff/8 >= $1000 -> diff/8
  12180. ;
  12181. ; 80 <= timeLeft < 130 -> diff/8
  12182. ;
  12183. ; I think this is basically some kind of round-up
  12184. ; of the time between airflow sensor pulse when
  12185. ; the frequency is low. timeLeft between 0ms and 50ms
  12186. ; correspond to a time between airflow pulse of
  12187. ; between 130ms to 80ms, which correspond to a
  12188. ; frequency of 7.7Hz to 20Hz. By setting value bit
  12189. ; $2000, we are basically making sure the returned
  12190. ; value corresponds to at least 65ms (15Hz),
  12191. ; assuming a 1MHz clock ($2000*8/1000000)
  12192. ;-----------------------------------------------
  12193. L1910 cmpa #$10 ;
  12194. bcc L1912 ; Branch if time left >=80ms (16/200Hz), return value as is
  12195. cmpa #$0a ;
  12196. bcs L1911 ; Branch if time left <50ms (10/200Hz)
  12197. brset temp8, #$10, L1912 ; Timer is between 50ms<= timer <80ms, branch if diff/8 >= $1000 (value already big enough?, no need to set $2000...)
  12198. L1911 orm temp8, #$20 ; set value bit $2000 (add that much to diff/8???)
  12199. L1912 ldd temp8 ; Load and return value
  12200. L1913 rts ;
  12201.  
  12202.  
  12203.  
  12204.  
  12205. ;******************************************************************
  12206. ;
  12207. ;
  12208. ; Real time Interrupt subroutine
  12209. ; Frequency: 801.28Hz (see rti_freq)
  12210. ;
  12211. ;
  12212. ;******************************************************************
  12213. realTimeInt ldaa rti_ctl ;
  12214. ldaa rti_freq ;
  12215. L1914b inc rtiCnt ; Increment real time interrupt counter
  12216.  
  12217. ;-----------------------------------------------------
  12218. ; Check if key is in start and cas signal is active
  12219. ;-----------------------------------------------------
  12220. brset port3, #$40, L1915 ; Bail if key is not is start
  12221. brset port5, #$01, L1915 ; Bail if cas signal is low
  12222.  
  12223. ;------------------------------------------
  12224. ; key is in start and cas signal is active
  12225. ; reset a few things
  12226. ;------------------------------------------
  12227. clra ;
  12228. clrb ;
  12229. staa casFlags0 ; casFlags0 = 0
  12230. staa enerFlags ; enerFlags = 0
  12231. std ignFallRelTime0 ; ignFallRelTime0 = 0
  12232.  
  12233. ;------------------------------------------------------------------------------------
  12234. ; Key is in start and cas signal is active
  12235. ; If no cas interrupt is pending, enable the current coil bit
  12236. ; and schedule an immediat output compare interrupt to energize it.
  12237. ;
  12238. ; Basically this makes sure the coil is energized for the whole CAS pulse
  12239. ; during start of crank/cranking...
  12240. ;------------------------------------------------------------------------------------
  12241. brset t1_csr, #$80, L1915 ; Branch if cas interrupt is pending?
  12242. ldaa tdcMask0 ; a = $02 or $04
  12243. asla ; a = $04 or $08
  12244. coma ; a = ~($04 or $08)
  12245. anda t3_csr0 ; reset that bit, i.e. energize that coil at scheduled time
  12246. staa t3_csr0 ; update t3_csr0
  12247. ldx t3_clock1 ;
  12248. inx ;
  12249. inx ; x = t3_clock1 + 2, basically in a few microsec
  12250. stx t3_outCmpWr ; Schedule interrupt for "now" on first output compare register
  12251.  
  12252. ;------------------------------------------------
  12253. ; increament rtiCnt48 and loop from 47 to 0...
  12254. ; If we loop to 0, also reset the egr and boost
  12255. ; control solenoid output, i.e. this is the start
  12256. ; of the pulswidth modulation cycle
  12257. ;------------------------------------------------
  12258. L1915 ldab rtiCnt48 ; b = old rtiCnt48
  12259. incb ;
  12260. stab rtiCnt48 ; rtiCnt48 = old rtiCnt48 + 1
  12261. cmpb #$30 ;
  12262. bcs L1916 ; Branch if old rtiCnt48 + 1 < 48
  12263. clrb ; b = 0
  12264. stab rtiCnt48 ; rtiCnt48 = 0
  12265. andm port5, #$d7 ; When rtiCnt48 reaches 48, reset port5.5 and port5.3
  12266.  
  12267. ;-----------------------------------------------------------
  12268. ; Set the egr solenoid output if time has come (duty cycle)
  12269. ;-----------------------------------------------------------
  12270. L1916 cmpb egrDuty ;
  12271. bcs L1917 ; Branch if rtiCnt48 < egrDuty
  12272. orm port5, #$08 ; Set the egr solenoid
  12273.  
  12274. ;-------------------------------------------------------------------------
  12275. ; Set the boost control solenoid output if time has come (duty cycle)
  12276. ;-------------------------------------------------------------------------
  12277. L1917 cmpb bcsDuty ; Boost control solenoid duty cycle, second threshold?
  12278. bcs L1918 ; Branch if rtiCnt48 < egrDuty
  12279. orm port5, #$20 ;
  12280.  
  12281. ;-------------------------------------------
  12282. ; At this point b = new value of rtiCnt48
  12283. ;
  12284. ; Update boost gauge output at 801.28Hz
  12285. ;-------------------------------------------
  12286. L1918 ldaa bGaugeODuty ; a = bGaugeODuty ("off-duty" cycle)
  12287. cmpb #$18 ;
  12288. bcs L1919 ; branch if rtiCnt48 < 24
  12289. subb #$18 ; b = rtiCnt48-24 (we only need a value from 0 to 24 here, use 24 to 48 as a new 0 to 24...)
  12290. brclr state3, #$10, L1919 ; Branch if notRotating clear
  12291. inca ; Engine not rotating, a = bGaugeODuty+1 (why?, wiggle the needle a bit?)
  12292. L1919 tstb ;
  12293. bne L1920 ; Branch if rtiCnt48 != 0
  12294. andm port6, #$fb ; rtiCnt48=0, start with boost gauge output = 0 at the beginning of cycle
  12295. L1920 cba ;
  12296. bhi L1921 ; Branch if bGaugeODuty > rtiCnt48
  12297. orm port6, #$04 ; Change boost gauge output to 1 when rtiCnt48 >= bGaugeODuty
  12298. L1921 .equ $ ;
  12299.  
  12300. ;-----------------------------------------------------
  12301. ; Branch to next section at 400Hz if time has come
  12302. ;-----------------------------------------------------
  12303. L1921b brclr rtiCnt, #$01, L1922 ; Branch once out of two times
  12304. rti ;
  12305.  
  12306.  
  12307.  
  12308.  
  12309. ;******************************************************************
  12310. ;
  12311. ;
  12312. ; Code executed at 1/2 rate (~400Hz)
  12313. ;
  12314. ;
  12315. ;******************************************************************
  12316. ;--------------------------------------------------------------------------------
  12317. ; Although we are still in interrupt code , we will re-enable interrupts
  12318. ; for the important ones (the coil and cas interrupts) until we get out of here
  12319. ;--------------------------------------------------------------------------------
  12320. L1922 andm t1_csr, #$f7 ; reset 0000 1000, disable interrupts from injector 1???
  12321. andm t2_csr, #$e7 ; reset 0001 1000 disable interrupts from injectors 2,3,4 and airflow sensor???
  12322. andm rti_ctl, #$bf ; disable interrupts from real time interrupt (we are already in it and it is not re-entrant...)
  12323. andm sci_scr, #$ef ; Disable serial port rx interrupt
  12324. cli ; Re-enable all interrupts that were not disabled
  12325.  
  12326. ;--------------------------------------------------------------------------------
  12327. ; Speed sensor update:
  12328. ; At 100km/h, reed switch sensor will generate ~reedHz=69Hz square wave (~40cm/cycle)
  12329. ; vssValue will reflect the number of interrupt calls during one complete cycle,
  12330. ; i.e. the quare wave period measured in 1/400sec
  12331. ;--------------------------------------------------------------------------------
  12332. ldaa vssCnt1 ;
  12333. beq L1923 ;
  12334. deca ;
  12335. staa vssCnt1 ;
  12336. L1923 ldaa vssCnt2 ;
  12337. beq L1924 ;
  12338. deca ;
  12339. staa vssCnt2 ;
  12340. L1924 ldab rtiReedFlags ;
  12341. rol rtiReedFlags ;
  12342. ldaa port1 ;
  12343. rola ;
  12344. ror rtiReedFlags ; rtiReedFlags.7 contains latest REED switch value
  12345. eorb rtiReedFlags ; B.7 = 1 if reed switch value changed
  12346. bmi L1925 ; Branch if Reed switch value changed
  12347. ldaa vssCnt2 ; No change in reed switch value
  12348. bne L1927 ; branch if C5 not yet 0
  12349. ldaa #$e2 ;
  12350. bra L1926 ; vssCnt reached 0, prepare to store E2 in speedSensor (lowest possible speed)
  12351.  
  12352. ;-----------------------------------
  12353. ; Reed switch value changed,
  12354. ; update speedSensor pulse counter
  12355. ;-----------------------------------
  12356. L1925 ldab #$c8 ;
  12357. stab vssCnt1 ; Re-initialize vssSlowCnt
  12358. brset rtiReedFlags, #$80, L1927 ; branch if new value is 1
  12359. ldaa #$e2 ; Reed switch value just changed to 0..
  12360. suba vssCnt2 ; A = # pulses counted for the last interval
  12361. ldab #$e2 ;
  12362. stab vssCnt2 ; Re-Initialize vssCnt
  12363. L1926 staa vss ; Store new speedSensor value (number of times interupt was called during an entire pulse (falling edge to falling edge)
  12364.  
  12365. L1927 .equ $
  12366.  
  12367. L1927b brclr rtiCnt, #$03, L1928 ; branch to other stuff at a frequency "real time int freq."/4
  12368. jmp L1950 ;
  12369.  
  12370. ;----------------------------------
  12371. ; Code executed at ~200Hz
  12372. ; Read ADC (tpsRaw, battRaw)
  12373. ;----------------------------------
  12374. L1928 ldaa #$0f ;
  12375. jsr readAdc1 ;
  12376. cli ;
  12377. stab tpsRaw ;
  12378. ldaa #$0d ;
  12379. jsr readAdc1 ;
  12380. cli ;
  12381. stab battRaw ;
  12382.  
  12383. ;-------------------------------------------------------------------------------
  12384. ; Decrement 5 down counters at $be, $bf, $c0, $c1, $c2
  12385. ;-------------------------------------------------------------------------------
  12386. ldx #T200_40Hz
  12387. ldab #$05 ; Loop 5 times, $be, $bf, $c0, $c1, $c2
  12388. L1929 ldaa $00,x
  12389. beq L1930 ; branch if counter already 0
  12390. dec $00,x ; decrement one of $be, $bf, $c0, $c1, $c2
  12391. L1930 inx ; go to next down counter
  12392. decb ;
  12393. bne L1929 ; loop
  12394.  
  12395. ;------------------------------------------
  12396. ; Check/reset 40Hz counter (T200_40Hz)
  12397. ;------------------------------------------
  12398. ldaa T200_40Hz ;
  12399. bne L1931 ; branch if first counter not 0
  12400. orm T200_40Hz, #$05 ; Reinit counter with 5 (5/200 = 25ms->40Hz)
  12401. orm rtiReedFlags, #$01 ; Set flag at 40 Hz for main loop events
  12402.  
  12403. ;------------------------------------------
  12404. ; Check T200_cop and change some output on port 6???
  12405. ; Could be some kind of monitoring function:
  12406. ; If main loop goes slower than 20Hz, port6.5 is not
  12407. ; updated and external check could reset the ECU
  12408. ; in that case (COP)
  12409. ;------------------------------------------
  12410. L1931 ldaa T200_cop ;
  12411. beq L1932 ; Branch if T200_cop reached 0 (meaning main loop is executing at less than 20Hz???)
  12412. sei ;
  12413. ldaa port6 ; T200_cop not 0, toggle port6.5
  12414. eora #$20 ;
  12415. staa port6 ; Toggle bit
  12416. cli
  12417.  
  12418. ;----------------------------------------------------------------------------
  12419. ; Update knock decay:
  12420. ; Decrement knocksum by 1 every time T200s_knock expires and reload timer
  12421. ; T200s_knock with fast or slow decay constant depending on current airVol
  12422. ;----------------------------------------------------------------------------
  12423. L1932 ldaa T200s_knock ; a = T200s_knock, knock attenuation timer
  12424. beq L1933 ; Branch if T200s_knock already expired
  12425. deca ; a = T200s_knock-1
  12426. bne L1935 ; branch if (T200s_knock-1)!=0 -> store T200s_knock-1
  12427. L1933 sei ; at this point T200s_knock = 0 or 1
  12428. ldaa knockSum ; a = knockSum
  12429. beq L1934 ; Branch if knockSum = 0
  12430. dec knockSum ; knockSum = knockSum-1
  12431. L1934 cli ;
  12432. ldaa #$78 ; a=$78 (200Hz/120 = 1.67Hz, slow attenuation)
  12433. brset knockFlags, #$80, L1935 ; Branch if flag indicate that airVol>$49
  12434. ldaa #$02 ; a=$02 (200Hz/2 = 100Hz, fast attenuation)
  12435. L1935 staa T200s_knock ; store current knock attenuation count
  12436.  
  12437. ;---------------------------------------------------------------
  12438. ; Set iscLowBatt.7 flag if battRaw>=10V (with 0.33V hysteresis)
  12439. ; else reset it. If battRaw<10V the ISC spindle is not moved...
  12440. ;---------------------------------------------------------------
  12441. ldab #$8d ; b= 10.33V = threshold
  12442. ldaa iscLowBatt ; a = iscLowBatt
  12443. bpl L1936 ; Branch if iscLowBatt.7 already set, meaning battRaw >=10v last time we were here
  12444. ldab #$88 ; reduce threshold (hysteresis) to 10.00V
  12445. L1936 cmpb battRaw ; Check battRaw against 10.00V or 10.33V
  12446. bcs L1937 ; branch if battRaw > 10.00 or 10.33V
  12447.  
  12448. ;---------------------------------------------------------------------
  12449. ; battRaw <= 10.00 , clear iscLowBatt and bail, no ISC update
  12450. ;---------------------------------------------------------------------
  12451. clr iscLowBatt ; battRaw < 10.00 or 10.33V, clear iscLowBatt
  12452. bra L1939 ; Bail
  12453.  
  12454. ;--------------------------------------------------------------------------
  12455. ; battRaw > 10.00 , set iscLowBatt.7 flag and increase iscLowBatt.0.1 counter by 1
  12456. ; If counter < $03 we don't update the ISC spindle (that means that
  12457. ; battRaw has to be higher than 10.00V for 4/200 sec before we move
  12458. ; the ISC spindle...
  12459. ;--------------------------------------------------------------------------
  12460. L1937 oraa #$80 ; a = iscLowBatt | $80
  12461. inca ; a = iscLowBatt | $80 + 1
  12462. staa iscLowBatt ; iscLowBatt = old iscLowBatt | $80 + 1
  12463. cmpa #$83 ;
  12464. bcs L1939 ; Bail if new iscLowBatt.0.1 < $03, no ISC update
  12465. ldaa #$83 ; Use max of iscLowBatt.0.1 = $03
  12466. staa iscLowBatt ; iscLowBatt = $83 (flag set and counter = $03)
  12467.  
  12468. ;-------------------------
  12469. ; Check ISC complement ???
  12470. ;-------------------------
  12471. ldab iscPatrnIdx ; preload b = iscPatrnIdx for later calc
  12472. ldaa iscStepCurr ; a = iscStepCurr
  12473. coma ;
  12474. anda #$7f ; a = ~iscStepCurr & $7f
  12475. cmpa iscStepCom ;
  12476. bne L1939 ; branch if complement is incorrect???
  12477.  
  12478. ;----------------------------------
  12479. ; Complement is OK, continue???
  12480. ;----------------------------------
  12481. ;---------------------------------------------------------------
  12482. ; Section to move the ICS spindle by +/1 step if iscStepCurr != iscStepTarg
  12483. ; this is where it happens... code executed at 200Hz...
  12484. ;---------------------------------------------------------------
  12485. ldaa iscStepCurr ; a = iscStepCurr
  12486. cmpa iscStepTarg ;
  12487. beq L1939 ; Bail if current ISC step is what we want (no change needed)
  12488. inca ; assume a = iscStepCurr + 1
  12489. incb ; assume b = iscPatrnIdx + 1
  12490. bcs L1938 ; Branch if iscStepCurr < iscStepTarg (tricky, carry flag is not affected by inca, incb...)
  12491. deca ; iscStepCurr >= iscStepTarg, assumption wrong, go in the other direction
  12492. deca ; a = iscStepCurr - 1
  12493. decb ;
  12494. decb ; b = iscPatrnIdx - 1
  12495. L1938 jsr iscStepComp ; Update iscStepCurr and iscStepCom with new values
  12496. stab iscPatrnIdx ; Update iscPatrnIdx with new value
  12497. ldx #t_iscPattern ; x points to t_iscPattern
  12498. andb #$03 ; b = new iscPatrnIdx & 00000011
  12499. abx ; x points to desired pattern
  12500. sei ;
  12501. ldaa port5 ; a = port5
  12502. anda #$3f ; a = port5 & 00111111
  12503. adda $00,x ; a = (port5 & 00111111) + t_iscPattern(iscPatrnIdx)
  12504. staa port5 ; update port5
  12505. cli ;
  12506. ldaa #$81 ; a = $81 = 129
  12507. staa iscLowBatt ; re-init iscLowBatt to $81
  12508.  
  12509. ;------------------------------------------------------
  12510. ; Section of code to update port2.2 (up to ~L1949)
  12511. ; according to TPS/rpm/airVol/idleSwitch/timer?????
  12512. ;
  12513. ; ????Could be airflow sensor filter reset???
  12514. ;------------------------------------------------------
  12515. L1939 brclr state1, #$10, L1941 ; Branch if notRotating clear
  12516.  
  12517. ;-----------------------------------------
  12518. ; Engine notRotating, clear timer T40s_tps
  12519. ;-----------------------------------------
  12520. clr T40s_tps ;
  12521. bra L1948 ;
  12522.  
  12523. ;----------------------------------------------------------------------------
  12524. ; Engine is at least rotating,
  12525. ; Check whether tpsRaw has increased by more than 1.5% and is between 26%-50%
  12526. ;----------------------------------------------------------------------------
  12527. L1941 clr tempFlagTps ; tempFlagTps = 0
  12528. ldab tpsRaw ; b=tpsRaw
  12529. ldaa oldTps1 ;
  12530. sba ; a = tpsDiff = oldTps1-tpsRaw
  12531. bls L1942 ; branch if new TPS is smaller or equal to old one
  12532. cmpa #$04 ; new tps higher than old one
  12533. bcs L1944 ; bail if tpsDiff < 4 (1.5%)
  12534. ldaa #$80 ; tpsDiff is >=4
  12535. cba ;
  12536. bls L1944 ; bail if tps>=50%
  12537. cmpb #$43 ; tps <50%
  12538. bcs L1944 ; bail if tps<26%
  12539. dec tempFlagTps ; at this point tpsDiff and 26%<= tps <50%, set tempFlagTps=$ff
  12540. ldaa #$0e ; set T40s_tps to $0e (0.35s) after branch
  12541. bra L1943 ;
  12542. L1942 cmpb #$43 ; New tps smaller than old one
  12543. bcs L1944 ; branch if tps < 26%
  12544. clra ; tps>26%, clear timer T40s_tps
  12545. L1943 staa T40s_tps ;
  12546.  
  12547. ;-----------------------------------------------------------------
  12548. ; At this point b=tpsRaw and
  12549. ; if TPS has increased by more than 1.5% and new value is between 26% and 50%
  12550. ; T40s_tps = $0e and tempFlagTps = $ff
  12551. ; else
  12552. ; tempFlagTps = $00
  12553. ; if new TPS<26%
  12554. ; previous T40s_tps is reset to 0
  12555. ;-----------------------------------------------------------------
  12556. L1944 ldaa tempFlagTps ;
  12557. bmi L1947 ; Branch if tempFlagTps=FF (TPS increased to between 26% and 50%)
  12558. cmpb #$43 ;
  12559. bcc L1945 ; branch if tps>= 26%
  12560. ldaa T40s_tps ; tps<26%
  12561. bne L1947 ; Branch if timer not expired
  12562. cmpb #$31 ; tps<26% and timer expired
  12563. bcc L1945 ; branch if tps>=19%
  12564. cmpb #$0a ; tps<19% and timer expired
  12565. bcc L1947 ; branch if TPS>=4%
  12566. ; tps<4% and timer expired
  12567.  
  12568. ;---------------------------------------------------------------------
  12569. ; no TPS increase to 26% and 50%
  12570. ; and tps>=26%
  12571. ; or 19%<=tps<26% and timer expired
  12572. ; or tps<4% and timer expired
  12573. ; ......
  12574. ;---------------------------------------------------------------------
  12575. L1945 ldaa rpm31 ;
  12576. cmpa #$20 ; 1000rpm
  12577. bcs L1946 ; branch if rpm<1000
  12578. ldaa airVol ; rpm>=1000
  12579. cmpa #$40 ;
  12580. bcc L1948 ; branch if airVol >= $40
  12581. L1946 ldaa port3 ;
  12582. bpl L1948 ; branch if idle switch off
  12583.  
  12584. ;---------------------------------------------------------------------
  12585. ; Reset port2.2 (Airflow sensor active filter reset?)
  12586. ; under a bunch of conditions
  12587. ;
  12588. ; Not completly checked...
  12589. ; TPS increased to between 26% and 50%
  12590. ; or tps<26% and timer not expired
  12591. ; or 4%<=tps<19% and timer expired
  12592. ; or no TPS increase to 26% and 50%
  12593. ; and tps>=26%
  12594. ; or 19%<=tps<26% and timer expired
  12595. ; or tps<4% and timer expired
  12596. ; and idlSwOn and [ rpm<1000 or ( rpm>1000 and airVol<$40) ]
  12597. ; .....
  12598. ;---------------------------------------------------------------------
  12599. L1947 andm port2, #$fb ; reset port output??????
  12600. bra L1949 ;
  12601.  
  12602. ;---------------------------------------------------------------------
  12603. ; Set port2.2 (Airflow sensor active filter reset?)
  12604. ; under a bunch of conditions...
  12605. ;---------------------------------------------------------------------
  12606. L1948 orm port2, #$04 ; Set port output????
  12607.  
  12608. ;--------------------------
  12609. ; Update oldTps1 at 200Hz
  12610. ;--------------------------
  12611. L1949 ldaa tpsRaw ;
  12612. staa oldTps1 ;
  12613.  
  12614. ;----------------------------------------------
  12615. ; Update oldTps2 and tpsDiffMax1 at 100Hz
  12616. ;----------------------------------------------
  12617. L1950 brset rtiCnt, #$07, L1953 ; Branch if any of those bits set -> branch 7 out of 8 times
  12618. ldaa tpsRaw ; Code executed at ~800Hz/8=100Hz, a=tpsRaw
  12619. tab ; b=tpsRaw
  12620. suba oldTps2 ; a = tpsRaw-oldTps2
  12621. bcc L1951 ; branch if result positive (tpsRaw>=oldTps2)
  12622. clra ; Use min of 0
  12623. L1951 cmpa tpsDiffMax1 ;
  12624. bls L1952 ; branch if (tpsRaw-oldTps2)<=tpsDiffMax1
  12625. staa tpsDiffMax1 ; tpsDiffMax1 = max(tpsDiffMax1, (tpsRaw-oldTps2))
  12626. L1952 stab oldTps2 ; oldTps2 = tpsRaw
  12627.  
  12628. ;------------------------------------------------------
  12629. ; Update section at 200Hz (800Hz/4) if time has come
  12630. ;------------------------------------------------------
  12631. L1953 brset rtiCnt, #$03, L1955 ; Branch if any of those bits set -> branch 3 out of 4 times
  12632.  
  12633. ;-------------------------------
  12634. ; Code executed at 200Hz
  12635. ;-------------------------------
  12636. ;------------------------------------------------
  12637. ; Update T200s_sInj timer and reset sInjEnr
  12638. ; to 0 if timer is expired
  12639. ;
  12640. ; Basically brings down enrichement to 0 a
  12641. ; little while after it is not needed anymore
  12642. ;------------------------------------------------
  12643. ldaa T200s_sInj ;
  12644. beq L1954 ; Branch if T200s_sInj already at 0
  12645. dec T200s_sInj ; decrement T200s_sInj
  12646. bne L1955 ; Bail if T200s_sInj not 0 yet
  12647. L1954 clr sInjEnr ;
  12648.  
  12649. ;-----------------------------------------------------
  12650. ; Update section at 100Hz (800Hz/8) if time has come
  12651. ;-----------------------------------------------------
  12652. L1955 brset rtiCnt, #$07, L1962 ; Branch if any of those bits set -> branch 7 out of 8 times
  12653.  
  12654. ;-------------------------------
  12655. ; Code executed at 100Hz
  12656. ;-------------------------------
  12657. ;------------------------------------------------------------------
  12658. ; Section to increase simultaneous fuel injection time (sInjPw)
  12659. ; when the gas pedal is being pressed, simultaneous injection
  12660. ; during acceleration...
  12661. ;------------------------------------------------------------------
  12662. ldaa tpsRaw ; a = tpsRaw
  12663. suba oldTps3 ; a = tpsRaw - oldTps3
  12664. bcc L1956 ; Branch if result positive
  12665. clra ; Use min of 0
  12666. L1956 staa tpsDiff100 ; tpsDiff100 = max(tpsRaw - oldTps3, 0)
  12667. cmpa #$03
  12668. bcs L1961 ; Bail if (tpsRaw - oldTps3) < 3
  12669. ldab oldTps3 ;
  12670. cmpb sInjTpsMax ;
  12671. bcc L1961 ; Bail if oldTps3 >= sInjTpsMax
  12672. brset state3, #$35, L1961 ; Bail if "rotatingStopInj but not runningFast" or notRotating or rev limiter active or startingToCrank
  12673. brset port3, #$80, L1961 ; Bail if idle switch on
  12674.  
  12675. ;---------------------------------------------------------------------
  12676. ; At this point, idle switch is off, engine is "running normally?",
  12677. ; (tpsRaw - oldTps3) >=3 and oldTps3 < sInjTpsMax
  12678. ;
  12679. ; Basically means the gas pedal is moving forward, acceleration...
  12680. ;
  12681. ; Increase simultaneous fuel injection time if not already at max????
  12682. ; Kind of acceleration enrichement when still using simultaneous
  12683. ; injection????
  12684. ;---------------------------------------------------------------------
  12685. ldaa sInjEnr ; a = sInjEnr
  12686. cmpa sInjEnrMax ;
  12687. bcc L1961 ; Bail if sInjEnr >= sInjEnrMax (maximum enrichment reached)
  12688. ldaa #$28 ;
  12689. staa T200s_sInj ; Init timer T200s_sInj to $28 (0.2s)
  12690. ldab tpsDiff100 ; b = tpsDiff100
  12691. lsrb ;
  12692. lsrb ; b = tpsDiff100/4
  12693. cmpb #$08 ;
  12694. bcs L1957 ; Branch if tpsDiff100/4 < 8
  12695. ldab #$08 ; Use max of 8
  12696. L1957 ldx #t_sInjEnr ; x = t_sInjEnr
  12697. abx ; s = t_sInjEnr + tpsDiff100/4
  12698. ldaa $00,x ; a = t_sInjEnr(tpsDiff100)
  12699. ldab sInjEnrInc ; b = sInjEnrInc
  12700. mul ; d = sInjEnrInc * t_sInjEnr(tpsDiff100)
  12701. asld ; d = 2 * sInjEnrInc * t_sInjEnr(tpsDiff100)
  12702. bcs L1958 ; Branch to use max if overflow
  12703. cmpa #$15 ;
  12704. bcs L1959 ; Branch if 2 * sInjEnrInc * t_sInjEnr(tpsDiff100) < 15*256
  12705. L1958 ldaa #$15 ;
  12706. clrb ; Use Max of d=$1500 (5.3ms)
  12707. L1959 psha ; st0 = 2/256 * sInjEnrInc * t_sInjEnr(tpsDiff100)
  12708. addd sInjPw ; d = 2 * sInjEnrInc * t_sInjEnr(tpsDiff100) + sInjPw
  12709. std sInjPw ; sInjPw = old sInjPw + 2 * sInjEnrInc * t_sInjEnr(tpsDiff100)
  12710. pulb ; b = 1/128 * sInjEnrInc * t_sInjEnr(tpsDiff100)
  12711. addb sInjEnr ;
  12712. stab sInjEnr ; sInjEnr = sInjEnr + 1/128 * sInjEnrInc * t_sInjEnr(tpsDiff100)
  12713.  
  12714. ;----------------------------
  12715. ; Update oldTps3 at 100Hz)
  12716. ;----------------------------
  12717. L1961 ldaa tpsRaw
  12718. staa oldTps3
  12719. sei
  12720.  
  12721. ;-------------------------------------------------------------
  12722. ; Schedule simultaneous injection injector activation and
  12723. ; deactivation at 100Hz, i.e. every 10ms, this is what the
  12724. ; tech manual says...
  12725. ;-------------------------------------------------------------
  12726. jsr simInject
  12727.  
  12728. ;----------------------------------
  12729. ; Re-enable interrupts and return
  12730. ;----------------------------------
  12731. L1962 sei
  12732. orm t1_csr, #$18 ; Re-enable interrupt for
  12733. orm t2_csr, #$18 ; Re-enable interrupt for
  12734. orm rti_ctl, #$40 ; Re-enable interrupt for
  12735. brclr obdFlags, #$02, L1963 ; Branch if serial output on port 2 was previously init to 1 (means serial rx is also init)
  12736. orm sci_scr, #$10 ; re-enable serial port "rx interrupt"
  12737. L1963 rti
  12738.  
  12739.  
  12740.  
  12741. ;******************************************************************
  12742. ;
  12743. ; Output compare interrupt 3
  12744. ;
  12745. ; Triggered when the output compare interrupt for
  12746. ; coil energization or ignition is triggered.
  12747. ;
  12748. ;
  12749. ;******************************************************************
  12750. outCompInt3 bsr coilFunc
  12751. rti
  12752.  
  12753.  
  12754.  
  12755. ;******************************************************************
  12756. ;
  12757. ;
  12758. ; Called by code and interrupt subroutine when an output
  12759. ; compare interrupt for coil energization or ignition is
  12760. ; triggered or pending.
  12761. ;
  12762. ;
  12763. ;******************************************************************
  12764. ;-------------------------------------
  12765. ; Flush both output compare registers
  12766. ; (write fartest possible time)
  12767. ;-------------------------------------
  12768. coilFunc ldx t3_clock1 ; x = t3_clock1
  12769. dex ;
  12770. stx t3_outCmpWr ; re-init count of first register
  12771. ldaa t3_csr1 ;
  12772. stx t3_outCmpWr ; re-init count of second register
  12773.  
  12774. ;-------------------------------------------
  12775. ; Branch to the right section depending on
  12776. ; the current state of affairs
  12777. ;-------------------------------------------
  12778. brset enerFlags, #$02, L1968 ; Branch if coil energization was scheduled and coil is therefore now energized?
  12779. brclr enerFlags, #$01, L1971 ; Bail if enerFlags = 0, nothing needs doing.
  12780.  
  12781. ;----------------------------------------------------------------------
  12782. ; At this point enerFlags=1, the flag indicates coil was energized
  12783. ; and the current interrupt was for coil ignition, check if we should
  12784. ; schedule schedule coil energization for the next cylinder
  12785. ;----------------------------------------------------------------------
  12786. brset ignFallFlags, #$01, L1971 ; Bail if we decided ignition would be scheduled from the cas falling edge, In that case, energization is unlikely to be done before the cas rising edge...
  12787. brclr tdcCasCount, #$fe, L1967 ; Branch if tdcCasCount = 0 or 1, we are starting to crank??
  12788.  
  12789. ;---------------------------------------------------------------------------
  12790. ; At this point enerFlags=1 and ignFallFlags = 0 and tdcCasCount >= 2
  12791. ;
  12792. ; Schedule interrupt to energize the coil of the next cylinder
  12793. ; using energization time and TDC of the next cylinder.
  12794. ;
  12795. ; This might be done in case the energization time falls before the cas
  12796. ; rising edge of the next cylinder (at high rpm). This is the only
  12797. ; place we can schedule such an event. If on the cas rising edge the
  12798. ; energization already occured and the coil is energized, the code will not
  12799. ; schedule energization again...If it did not occure, the output compare
  12800. ; register will be flushed and energization will be scheduled again?
  12801. ;
  12802. ; Note that enerFlags is set to 0 instead of 1. Probably because the coil
  12803. ; being energized is on the next cylinder, not the current one. The
  12804. ; energization we are doing here is more of a precautionary measure????
  12805. ;
  12806. ; Note that the second output compare register was already flushed at
  12807. ; the beginning of subroutine.
  12808. ;---------------------------------------------------------------------------
  12809. ldd t3_clock1 ; d = t3_clock1
  12810. addd #$0009 ; d = t3_clock1 + $09
  12811. cmpd1 enerAbsTimeNext0 ;
  12812. bpl L1966 ; Branch to use t3_clock1 + $09 is enerAbsTimeNext0 is "in the past"
  12813. ldd enerAbsTimeNext0 ; enerAbsTimeNext0 is valid, use it
  12814. L1966 std t3_outCmpWr ; Schedule interrupt on first output compare register
  12815. ldaa tdcMask1 ; a = next tdc mask, not the current one..., $02 or $04
  12816. asla ; a = $04 or $08
  12817. coma ; a = ~($04 or $08)
  12818. anda t3_csr0 ; reset next tdc coil bit, energize that coil at the scheduled time
  12819. staa t3_csr0 ; update t3_csr0
  12820.  
  12821. ;--------------------
  12822. ; Set enerFlags = 0
  12823. ;--------------------
  12824. L1967 clra ;
  12825. staa enerFlags ;
  12826. rts ;
  12827.  
  12828. ;------------------------------------------------------
  12829. ; At this point enerFlags=2, coil energization was
  12830. ; scheduled and coil is therefore now energized...
  12831. ;
  12832. ; Schedule interrupt on first output compare register
  12833. ; to provoke ignition at the specified time
  12834. ; Second output compare register was already
  12835. ; flushed at the beginning of subroutine
  12836. ;------------------------------------------------------
  12837. L1968 brset ignFallFlags, #$01, L1970 ; Branch if flag indicates ignition is to be scheduled on the cas falling edge, it will be done at that time...
  12838. ldd t3_clock1 ; d = t3_clock1
  12839. addd #$0008 ; d = t3_clock1 + $08
  12840. cmpd1 ignTime0 ;
  12841. bpl L1969 ; Branch to use t3_clock1 + $08 if ignTime0 is "in the past"
  12842. ldd ignTime0 ; ignTime0 is valid, use it
  12843. L1969 std t3_outCmpWr ; Schedule interrupt on first output compare register
  12844. orm t3_csr0, #$0c ; Set both coil bits, i.e. provoke ignition on the energized coil at the scheduled time?
  12845.  
  12846. ;----------------------------------------------------
  12847. ; Set enerFlags = 1 indicating coil is energized?
  12848. ;----------------------------------------------------
  12849. L1970 ldaa #$01 ;
  12850. staa enerFlags ;
  12851. L1971 rts ;
  12852.  
  12853.  
  12854.  
  12855. ;******************************************************************
  12856. ;
  12857. ;
  12858. ; Interrupt subroutine when a failure occurs (clock monitor??)
  12859. ;
  12860. ;
  12861. ;******************************************************************
  12862. ;------------------------------------
  12863. ; Clear flag ?????
  12864. ;------------------------------------
  12865. failureInt andm ramControl, #$bf ; Reset 01000000 since we are here, disable ram??? or other function????
  12866.  
  12867. ;-----------------------------------------
  12868. ; Disable all outputs, ie.e re-init all
  12869. ; data direction registers to all inputs
  12870. ;-----------------------------------------
  12871. clra ;
  12872. clrb ;
  12873. std p1_ddr ; Initialize data direction registers for ports 1,2,3,4,5 to all input
  12874. std p3_ddr ;
  12875. staa p5_ddr ;
  12876.  
  12877. ;---------------------------------------------------------------
  12878. ; Wait for an interrupt, I assume only system reset
  12879. ; can be called since other interrupts have lower priority,
  12880. ; might be triggered by above action on ramControl???
  12881. ;---------------------------------------------------------------
  12882. wai ; Wait for an interrupt to jump to codeStart?
  12883.  
  12884. ;-----------------------------------------
  12885. ; I assume we never get here so that
  12886. ; code continuation is from codeStart...
  12887. ;-----------------------------------------
  12888.  
  12889.  
  12890.  
  12891.  
  12892. ;******************************************************************
  12893. ;
  12894. ; Code snipet from the first subroutine (jumps here and then
  12895. ; jumps back to first subroutine)
  12896. ;
  12897. ; This code might have been put here in case the cop function
  12898. ; above (failureInt) ever skips the "wai" opcode above?? That
  12899. ; way we at least are executing some real code instead of
  12900. ; trying to execute the table content located further. Cop
  12901. ; function should kick-in in a short while if everything
  12902. ; is not back to normal...
  12903. ;
  12904. ;******************************************************************
  12905. ;----------------------------------------------------
  12906. ; We are in closed loop mode, limit the range
  12907. ; of o2Fbk to $4d-$d6 or $2a-$d6 depending on ect
  12908. ;----------------------------------------------------
  12909. L1973 ldaa o2Fbk ; a = o2Fbk
  12910. ldab ectFiltered ; b = ectFiltered
  12911. cmpb #$1c ; 86degC
  12912. bcs L1975 ; Branch if temperature(ectFiltered) > 86degC
  12913.  
  12914. ;-------------------------------------------------------
  12915. ; temperature(ectFiltered) <= 86degC
  12916. ; Check for o2Fbk min and max of $4d and $d6
  12917. ;-------------------------------------------------------
  12918. cmpa #$4d ;
  12919. bcc L1974 ; Branch if o2Fbk >= $4d
  12920. ldaa #$4d ; Use min of $4d
  12921. bra L1976 ; Branch to store new o2Fbk
  12922. L1974 cmpa #$d6 ;
  12923. bcs L1977 ; Branch if o2Fbk < $d6
  12924. ldaa #$d6 ; Use max of $d6
  12925. bra L1976 ; Branch to store new o2Fbk
  12926.  
  12927. ;--------------------------------------
  12928. ; temperature(ectFiltered) > 86degC
  12929. ;--------------------------------------
  12930. L1975 cmpa #$2a ;
  12931. jmp L1140 ;
  12932.  
  12933. L1976 jmp L1142 ; Jump to store new o2Fbk
  12934. L1977 jmp L1143 ;
  12935.  
  12936.  
  12937. ;******************************************************************
  12938. ;
  12939. ;
  12940. ; E932 "patch" for rpm calculation, not sure why this is here
  12941. ;
  12942. ;******************************************************************
  12943. #ifdef E932
  12944. L1978 ldab rpm31 ;
  12945. ldx #$8840 ;
  12946. jsr clipOffset ; b = max(min(rpm31,$88)-$40,0)-> returns b = $00 to $48 (2250rpm to 4250rpm)
  12947. aslb ;
  12948. tba ;
  12949. ldx #t_closedLp2 ;
  12950. jmp L1120 ;
  12951. #endif
  12952.  
  12953.  
  12954. ;******************************************************************
  12955. ;
  12956. ; Empty memory block
  12957. ;
  12958. ;******************************************************************
  12959. #ifdef E931
  12960. .byte $ff, $ff, $ff, $ff, $ff, $ff, $ff, $ff, $ff, $ff, $ff, $ff, $ff, $ff, $ff, $ff
  12961. .byte $ff, $ff, $ff
  12962.  
  12963. #else
  12964. .byte $ff, $ff, $ff, $ff, $ff
  12965. #endif
  12966.  
  12967.  
  12968.  
  12969. ;******************************************************************
  12970. ;
  12971. ; Resistor strapping flags
  12972. ;
  12973. ; Stored in config1:config2 based on port4 lowest 2 bits (resistor values)
  12974. ;
  12975. ;
  12976. ;******************************************************************
  12977. t_strap1 .word $8200 ; Fwd Federal
  12978. .word $8401 ; Fwd California
  12979. .word $8282 ; Awd Federal
  12980. .word $8483 ; Awd California
  12981.  
  12982.  
  12983.  
  12984. ;******************************************************************
  12985. ;
  12986. ; Indicates which table to use as a function of config resistors
  12987. ;
  12988. ;
  12989. ;
  12990. ;******************************************************************
  12991. t_strap2 .word L1999 ; Fwd Federal
  12992. .word L2000 ; Fwd California
  12993. .word L2001 ; Awd Federal
  12994. .word L2002 ; Awd California
  12995.  
  12996.  
  12997. ;******************************************************************
  12998. ;
  12999. ; Resistor strapping device id returned on diagnostic port
  13000. ;
  13001. ;******************************************************************
  13002. t_strap3 .word $e022 ; Fwd Federal
  13003. .word $e023 ; Fwd California
  13004. .word $e022 ; Awd Federal
  13005. .word $e023 ; Awd California
  13006.  
  13007.  
  13008.  
  13009. ;******************************************************************
  13010. ;
  13011. ; Table values are compared to mafRaw16/64 = mafRaw -> (xx/6.25)Hz
  13012. ;
  13013. ; These are the 2 thresholds determining which trim range to use,
  13014. ; low, mid, high. The first threshold delimiting "low" from "mid"
  13015. ; corresponds to the first two value. It is 106.5Hz with an hysteresis
  13016. ; of +/-6Hz. The second threshold delimiting mid from high correspond
  13017. ; to the last two values. It is 175Hz with an hysteresis of +/-6.25Hz
  13018. ;
  13019. ; Values are
  13020. ;
  13021. ; $12 = 112.50 Hz
  13022. ; $10 = 100.50 Hz
  13023. ;
  13024. ; $1d = 181.25 Hz
  13025. ; $1b = 168.75 Hz
  13026. ;
  13027. ;******************************************************************
  13028. t_ftrimRg .byte $12, $10, $1d, $1b
  13029.  
  13030.  
  13031.  
  13032. ;******************************************************************
  13033. ;
  13034. ; Table of rpm31 values , $23=1094rpm, $20=1000rpm, $1d=906rpm
  13035. ;
  13036. ; Longer for AT
  13037. ;
  13038. ;******************************************************************
  13039. L1983 .byte $23, $20
  13040. #ifdef E932
  13041. .byte $20, $1d
  13042. #endif
  13043.  
  13044.  
  13045.  
  13046. ;******************************************************************
  13047. ;
  13048. ; Table contains RPM/31.25, interpolated by ECT. Eventually
  13049. ; used as a threshold to determine if the engine is ???.
  13050. ; used in state1 flags update
  13051. ;
  13052. ; Value is increased as a function of loads (see t_rpmEctOff)
  13053. ;
  13054. ;
  13055. ; (1188, 1188, 1594, ....., 3000)
  13056. ;
  13057. ; IX = FB40 from L1097
  13058. ; ECT
  13059. ;
  13060. ;******************************************************************
  13061. t_rpmEct .byte $26, $26, $33, $3c, $46, $50, $56, $60
  13062.  
  13063.  
  13064.  
  13065. ;******************************************************************
  13066. ;
  13067. ; Table contains RPM/31.25 offsets that will be added to
  13068. ; initial value of t_rpmEct, basically increasing RPM as a function
  13069. ; of loads
  13070. ;
  13071. ; $00 = +0rpm,
  13072. ; $08 = +250rpm,
  13073. ; $10 = +500rpm
  13074. ; $1d = +906.25rpm
  13075. ; $0d = +406.25RPM
  13076. ;
  13077. ; 3 bit index into table, b2 b1 b0 where:
  13078. ;
  13079. ; b0 is set if ???
  13080. ; b1 is set if tranmission is engaged
  13081. ; b2 is set if A/C switch is ON
  13082. ;
  13083. ; IX = FB48 from L1102
  13084. ;
  13085. ;******************************************************************
  13086. t_rpmEctOff .byte $08, $00,
  13087. .byte $10, $00,
  13088. .byte $1d, $0d,
  13089. .byte $10, $00
  13090.  
  13091.  
  13092.  
  13093. ;******************************************************************
  13094. ;
  13095. ; Interpolated from modified tps and rpm
  13096. ; Seems to be some kind of default air count used when we are
  13097. ; not receiving airflow sensor interrupts
  13098. ;
  13099. ;******************************************************************
  13100. L1986
  13101. #ifdef E931
  13102. .byte $62, $3d, $20, $16, $12
  13103. .byte $7a, $7a, $78, $6c, $5c
  13104. .byte $7d, $7d, $9e, $c2, $c0
  13105. .byte $7d, $7d, $a0, $cd, $cc
  13106. .byte $7d, $7d, $a8, $ce, $d8
  13107. .byte $8a, $8a, $bb, $d0, $df
  13108. #else
  13109. .byte $4d, $2b, $03, $16, $12
  13110. .byte $78, $84, $84, $60, $4a
  13111. .byte $7a, $88, $d0, $bd, $a2
  13112. .byte $7a, $88, $d2, $e9, $d0
  13113. .byte $7a, $88, $de, $ee, $de
  13114. .byte $7a, $8a, $da, $ec, $e4
  13115. #endif
  13116.  
  13117.  
  13118.  
  13119. ;******************************************************************
  13120. ;
  13121. ; Mas compensation table as a function of airflow sensor frequency
  13122. ;
  13123. ;
  13124. ; Index into t_masComp table are for the following frequencies:
  13125. ;
  13126. ; 85 85 A8 B6 BE C3 C8 CC D0 D4 D7 DA DC E3 E6 E8 EB EA EA E8 E7
  13127. ; Hz 0 25 50 75 100 125 150 175 200 225 250 275 300 400 500 600 800 1000 1200 1400 1600
  13128. ;
  13129. ;******************************************************************
  13130. t_masComp
  13131. #ifdef custMas
  13132. .byte $85, $85, $A8, $B6, $BE, $C3, $C8, $CC, $D0, $D4, $D7, $DA, $DC, $E3, $E6, $E8, $EB, $EA, $EA, $E8, $E7
  13133. #else
  13134. #ifdef E931
  13135. .byte $5b, $5b, $59, $59, $60, $65, $6c, $6e, $6e, $6f, $73, $76, $7a, $81, $82, $84, $87, $85, $7f, $7a, $7f
  13136. #else
  13137. .byte $5d, $5d, $5c, $5a, $61, $68, $6c, $6f, $70, $74, $76, $77, $7a, $7f, $84, $85, $88, $86, $81, $7f, $7e
  13138. #endif
  13139. #endif
  13140.  
  13141.  
  13142.  
  13143. ;******************************************************************
  13144. ;
  13145. ; This table is an airflow sensor compensation table (for temperature
  13146. ; drift, flow characteristic change, etc?) as a function of
  13147. ; air temperature, barometric pressure and airflow frequency.
  13148. ; Notice that frequency range is short which would mean airflow
  13149. ; sensor only need compensation under low flow conditions...
  13150. ;
  13151. ; Column index are airflow sensor frequency:
  13152. ;
  13153. ; 0Hz 25Hz 50Hz 75Hz 100Hz 125Hz 150Hz 175Hz 200Hz
  13154. ;
  13155. ; Row index are max(min(L1992(iat)*baroFactor,$52)-$22,0)/16,
  13156. ; at 1 bar that would correspond to (from top to bottom):
  13157. ;
  13158. ; 85degC, 84degC, 26degC, -31degC ??
  13159. ;
  13160. ; 2G mas table: $87, $87, $87, $85, $85, $85, $85, $85, $80
  13161. ; $80, $80, $80, $80, $80, $80, $80, $80, $80
  13162. ; $7d, $7d, $78, $7a, $7b, $7c, $7c, $7c, $80
  13163. ; $7b, $7b, $75, $78, $7a, $7a, $7a, $7a, $80
  13164. ;
  13165. ;
  13166. ;******************************************************************
  13167. t_masLin .byte $7d, $7d, $7f, $81, $84, $81, $81, $83, $80
  13168. .byte $80, $80, $80, $80, $80, $80, $80, $80, $80
  13169. .byte $83, $83, $83, $82, $80, $7d, $7f, $7f, $80
  13170. .byte $85, $85, $85, $83, $80, $7d, $7c, $7f, $80
  13171.  
  13172.  
  13173. ;******************************************************************
  13174. ;
  13175. ; Interpolated using rpm (max=3000rpm)
  13176. ;
  13177. ; Could be maximum air count as a function of RPM, used in
  13178. ; conjucntion with L1990 and L1991
  13179. ;
  13180. ;******************************************************************
  13181. t_airCntMax
  13182. #ifdef E931
  13183. .byte $5a, $5a, $5b, $5b, $61, $63, $8f, $a0, $ff, $ff, $ff, $ff, $ff
  13184. #else
  13185. .byte $5f, $5f, $5f, $5f, $64, $6c, $73, $ff, $ff, $ff, $ff, $ff, $ff
  13186. #endif
  13187.  
  13188.  
  13189.  
  13190. ;******************************************************************
  13191. ;
  13192. ; Interpolated from ectCond
  13193. ;
  13194. ; ECT based correction factor for t_airCntMax
  13195. ;
  13196. ;******************************************************************
  13197. L1990 .byte $80, $80, $80, $84, $88, $8b, $8f, $93
  13198.  
  13199.  
  13200.  
  13201. ;******************************************************************
  13202. ;
  13203. ; Interpolated from iatCond
  13204. ;
  13205. ; IAT based correction factor for t_airCntMax
  13206. ;
  13207. ;******************************************************************
  13208. L1991 .byte $8c, $86, $83, $80, $7d, $79, $73
  13209.  
  13210.  
  13211.  
  13212. ;******************************************************************
  13213. ;
  13214. ; Interpolated from iatCond. Value from table is then compensated for
  13215. ; barometric pressure and then used to interpolate t_masLin
  13216. ;
  13217. ; in degC
  13218. ;
  13219. ; 85 56 38 23 9 -7 -31 ??
  13220. ;
  13221. ;******************************************************************
  13222. L1992 .byte $45, $3b, $36, $31, $2d, $29, $22
  13223.  
  13224.  
  13225.  
  13226. ;******************************************************************
  13227. ;
  13228. ; Close loop table 1, interpolated from rpm
  13229. ;
  13230. ; The values of this table are airVolTB thresholds. Closed loop
  13231. ; only happens when airVolTB < theshold (with hysteresis of $06)
  13232. ;
  13233. ; rpm scale 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
  13234. ;
  13235. ;******************************************************************
  13236. t_closedLp1 .byte $9d, $9d, $9d, $9d, $9d, $80, $68, $55, $00, $00
  13237.  
  13238.  
  13239.  
  13240. ;******************************************************************
  13241. ;
  13242. ; Close loop table 2, interpolated from rpm
  13243. ;
  13244. ; The values of this table are airVolTB thresholds. Once we are
  13245. ; in closed loop, we will remain in closed loop as long as airVolTB
  13246. ; does not exceed the threshold of this table (with hysteresis of
  13247. ; 6) for more than 12sec or 20sec.
  13248. ;
  13249. ; rpm scale 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
  13250. ;
  13251. ;******************************************************************
  13252. t_closedLp2
  13253. #ifdef E931
  13254. .byte $9d, $9d, $9d, $a6, $ae, $ae, $9d, $73, $00, $00
  13255. #else
  13256. .byte $c3, $cd, $da, $eb, $cd, $aa, $68, $5f, $55, $00
  13257. #endif
  13258.  
  13259.  
  13260.  
  13261. ;******************************************************************
  13262. ;
  13263. ; Closed loop table 3, interpolated from rpm
  13264. ;
  13265. ; Values are tspRaw threshold. Open loop only happens
  13266. ; when tpsRaw > threshold (with hysteresis of $0d to go
  13267. ; back to closed loop)
  13268. ;
  13269. ; rpm scale 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
  13270. ;
  13271. ;******************************************************************
  13272. t_closedLp3
  13273. #ifdef E931
  13274. .byte $5c, $66, $73, $8d, $8d, $85, $71, $5c, $00, $00
  13275. #else
  13276. .byte $5c, $5c, $73, $8d, $94, $8a, $66, $33, $00, $00
  13277. #endif
  13278.  
  13279.  
  13280.  
  13281. ;******************************************************************
  13282. ;
  13283. ; Closed loop fuel adjustment values,
  13284. ;
  13285. ; First value is used in low trim range under low speed/rpm,
  13286. ; second value in other cases
  13287. ;
  13288. ; Values are used in closed loop mode to adjust fuel amount:
  13289. ;
  13290. ; o2FuelAdj = o2Fbk +/- t_closedLpV1(xx) or t_closedLpV2(xx) or $02
  13291. ;
  13292. ; where +/- depends on o2Raw (lean or rich).
  13293. ; Basically this controls how fast we change the mixture based on o2Fbk
  13294. ;
  13295. ;******************************************************************
  13296. #ifdef E932
  13297. t_closedLpV2 .byte $03, $07
  13298. #endif
  13299.  
  13300.  
  13301.  
  13302. ;******************************************************************
  13303. ;
  13304. ; Closed loop fuel adjustment values,
  13305. ;
  13306. ; First value is used in low trim range under low speed/rpm,
  13307. ; second value in other cases
  13308. ;
  13309. ; Values are used in closed loop mode to adjust fuel amount:
  13310. ;
  13311. ; o2FuelAdj = o2Fbk +/- t_closedLpV1(xx) or t_closedLpV2(xx) or $02
  13312. ;
  13313. ; where +/- depends on o2Raw (lean or rich).
  13314. ; Basically this controls how fast we change the mixture based on o2Fbk
  13315. ;
  13316. ;******************************************************************
  13317. t_closedLpV1 .byte $03, $07
  13318.  
  13319.  
  13320.  
  13321. ;******************************************************************
  13322. ;
  13323. ; Default o2Fbk decrease and increase values (in that order)
  13324. ; when T40_o2Fbk is expired
  13325. ;
  13326. ;
  13327. ;******************************************************************
  13328. t_o2Fbk1 .byte $20, $15
  13329.  
  13330.  
  13331.  
  13332. ;******************************************************************
  13333. ;
  13334. ; Tables of o2Fbk decrease/increase values. One table for
  13335. ; each possible resistor strapping combinations
  13336. ;
  13337. ; Table format:
  13338. ; First sub-table of six values: o2Fbk decrease values
  13339. ; Last sub-table of six values: 02Fbk increase values
  13340. ;
  13341. ; Within each sub-table of six value we have
  13342. ; First pair: rpm < ~1500rpm
  13343. ; Second pair: ~1500rpm < rpm < 2100rpm
  13344. ; Third pair: rpm > 2100rpm
  13345. ;
  13346. ; Within each pair we have
  13347. ; First value: airVolTB < ~40
  13348. ; Second value: airVolTB > ~40
  13349. ;
  13350. ;******************************************************************
  13351. #ifdef E931
  13352. L1999 .byte $32, $42, $36, $47, $35, $43, $2e, $42, $36, $49, $37, $51 ; Fwd Federal
  13353. L2000 .byte $32, $42, $36, $41, $31, $3d, $2e, $42, $36, $4f, $3b, $57 ; Fwd California
  13354. L2001 .byte $32, $42, $36, $45, $34, $43, $2e, $42, $36, $4b, $38, $51 ; Awd Federal
  13355. L2002 .byte $32, $42, $36, $41, $31, $3b, $2e, $42, $36, $4f, $3b, $59 ; Awd California
  13356. #else
  13357. L1999 .byte $32, $46, $40, $50, $42, $52, $2e, $46, $40, $50, $42, $62 ; Fwd Federal
  13358. L2000 .byte $32, $46, $40, $49, $3c, $4b, $2e, $46, $40, $57, $48, $69 ; Fwd California
  13359. L2001 .byte $32, $46, $40, $4f, $41, $52, $2e, $46, $40, $51, $43, $62 ; Awd Federal
  13360. L2002 .byte $32, $46, $40, $49, $3c, $48, $2e, $46, $40, $57, $48, $6c ; Awd California
  13361. #endif
  13362.  
  13363.  
  13364. ;******************************************************************
  13365. ;
  13366. ; Table of relative air density as a function of temperature
  13367. ; Factor of 1.0 correspond to around 25.6degC
  13368. ; Interpolated from iatCond
  13369. ;
  13370. ; Fits the gas law quite well, taking the two extreme
  13371. ; points (85degC and -31degC) and using Kelvins, we have
  13372. ;
  13373. ; T1/T2 = density2/density1
  13374. ;
  13375. ; In theory
  13376. ; (273+85)/(273-31) = 1.479
  13377. ;
  13378. ; The table gives us
  13379. ;
  13380. ; density2/density1 = 1.23/0.828 = 1.486
  13381. ;
  13382. ; This is a 0.5% difference.
  13383. ;
  13384. ;
  13385. ; degC 85 56 38 23 9 -7 -31
  13386. ; table value $6a $73 $7a $81 $87 $8f $9e
  13387. ; density 0.828 0.898 0.953 1.01 1.05 1.12 1.23
  13388. ;
  13389. ;
  13390. ;******************************************************************
  13391. t_airDens .byte $6a, $73, $7a, $81, $87, $8f, $9e
  13392.  
  13393.  
  13394. ;******************************************************************
  13395. ;
  13396. ; Fuel enrichment factor as a function of airVolCond
  13397. ; The value of this table reduces the enrichement of t_ectEnr
  13398. ; down to 0 as airflow is increased
  13399. ;
  13400. ;******************************************************************
  13401. t_airEnr .byte $80, $80, $80, $80, $76, $4f, $38, $38, $2d, $2a, $20, $20
  13402.  
  13403.  
  13404.  
  13405. ;******************************************************************
  13406. ;
  13407. ; Fuel enrichment factor as a function of ect (from 0% to 47%
  13408. ; enrichment in cold temp). This value is reduced by a factor taken
  13409. ; from t_airEnr when airflow is increased, see code
  13410. ;
  13411. ;******************************************************************
  13412. t_ectEnr
  13413. #ifdef E931
  13414. .byte $80, $80, $87, $89, $8f, $9d, $ab, $bc
  13415. #else
  13416. .byte $80, $80, $87, $89, $8f, $9a, $a4, $b5
  13417. #endif
  13418.  
  13419.  
  13420.  
  13421. ;******************************************************************
  13422. ;
  13423. ; Seem to contain enrichment values as a function of ECT
  13424. ; (run richer during warm-up/start-up)
  13425. ; $09 when hot, $80 when cold..., seems a bit high??????
  13426. ;
  13427. ; fuel enrichment applied = ($80+2*xx)/$80, enrich=$80=100%=no enrichment
  13428. ;
  13429. ; value xx $09 $0d $10 $1a $27 $33 $4d $80
  13430. ; enrich 1.14 1.20 1.26 1.40 1.60 1.80 2.2 3.00
  13431. ;
  13432. ;******************************************************************
  13433. t_enrWarmup .byte $09, $0d, $10, $1a, $27, $33, $4d, $80
  13434.  
  13435.  
  13436. ;******************************************************************
  13437. ;
  13438. ; Fuel map, value of $80 represent an enrichment factor of 1.0
  13439. ;
  13440. ; rpm 500 1000 1500 2000 2500 3000 3500 4000 4500 5000 5500 6000 6500 7000
  13441. ;
  13442. ;
  13443. ;******************************************************************
  13444. t_fuelMap
  13445. #ifdef custFuelMap
  13446. .byte $84, $82, $81, $80, $80, $80, $80, $80, $80, $80, $80, $80, $80, $80
  13447. .byte $87, $85, $84, $82, $82, $82, $82, $84, $85, $85, $85, $85, $85, $85
  13448. .byte $90, $8e, $8c, $8b, $8a, $8b, $8d, $8f, $8f, $90, $91, $91, $91, $91
  13449. .byte $94, $94, $94, $96, $98, $9a, $9c, $9e, $a0, $a2, $a4, $a6, $a8, $aa
  13450. .byte $a5, $a6, $a9, $ae, $b2, $b6, $b8, $b8, $ba, $ba, $ba, $ba, $bc, $bc
  13451. .byte $b0, $b6, $b9, $bc, $c0, $c2, $c3, $c3, $c4, $c5, $c6, $c6, $c6, $c6
  13452. .byte $b2, $b8, $bb, $be, $c2, $c4, $c5, $c5, $c6, $c7, $c8, $c8, $c8, $c8
  13453. .byte $b4, $ba, $bd, $c0, $c4, $c6, $c7, $c7, $c8, $c9, $ca, $ca, $ca, $ca
  13454. .byte $b6, $bc, $bf, $c2, $c6, $c8, $c9, $c9, $ca, $cb, $cc, $cc, $cc, $cc
  13455. .byte $b8, $be, $c1, $c4, $c8, $ca, $cb, $cb, $cc, $cd, $ce, $ce, $ce, $ce
  13456. .byte $b9, $bf, $c2, $c5, $c9, $cb, $cc, $cc, $cd, $ce, $cf, $cf, $cf, $cf
  13457. .byte $ba, $c0, $c3, $c6, $ca, $cc, $cd, $cd, $ce, $cf, $d0, $d0, $d0, $d0
  13458. #else
  13459. #ifdef E931
  13460. .byte $8d, $85, $80, $7c, $7f, $7f, $80, $82, $85, $85, $85, $98, $98, $a0
  13461. .byte $8d, $85, $80, $7c, $7f, $7f, $80, $83, $85, $85, $85, $98, $98, $a0
  13462. .byte $8d, $85, $80, $80, $80, $80, $80, $80, $80, $80, $80, $98, $98, $a0
  13463. .byte $8d, $86, $80, $80, $80, $80, $80, $83, $84, $8a, $96, $98, $9f, $a7
  13464. .byte $91, $86, $80, $80, $80, $80, $80, $85, $8f, $96, $98, $a8, $a8, $ae
  13465. .byte $92, $9c, $98, $80, $80, $80, $86, $90, $98, $a0, $a6, $af, $af, $b6
  13466. .byte $94, $9e, $98, $80, $80, $87, $91, $98, $a5, $a8, $b3, $b6, $b6, $be
  13467. .byte $94, $9e, $98, $98, $95, $93, $98, $a0, $ac, $b0, $b8, $bb, $be, $c5
  13468. .byte $94, $9e, $98, $98, $96, $a0, $a8, $a8, $b3, $b8, $bd, $c0, $c6, $ca
  13469. .byte $94, $9e, $98, $98, $a7, $b4, $ae, $b3, $ba, $bf, $c3, $c4, $ca, $ca
  13470. .byte $94, $9e, $98, $98, $a7, $b6, $b8, $b9, $c4, $c8, $ca, $c8, $ca, $ca
  13471. .byte $94, $9e, $98, $98, $a7, $b6, $b8, $b9, $ca, $ca, $ca, $c8, $ca, $ca
  13472.  
  13473. #else
  13474. .byte $8d, $85, $80, $7e, $7c, $7c, $7c, $7c, $85, $89, $9a, $a0, $a0, $a3
  13475. .byte $8d, $85, $80, $7e, $7c, $7c, $7c, $7c, $85, $89, $9a, $a0, $a0, $a3
  13476. .byte $8d, $85, $80, $7e, $7c, $7c, $7c, $7c, $85, $89, $9a, $a0, $a0, $a3
  13477. .byte $8d, $85, $80, $7e, $7c, $7c, $7c, $8a, $90, $96, $a0, $a3, $a6, $a9
  13478. .byte $91, $85, $80, $7e, $7c, $7c, $86, $90, $9a, $a0, $a4, $a9, $aa, $ad
  13479. .byte $97, $97, $80, $7e, $7c, $94, $91, $9c, $a0, $a3, $aa, $ac, $b2, $b5
  13480. .byte $97, $97, $99, $7e, $92, $94, $95, $a2, $a8, $a8, $ad, $b3, $b9, $bb
  13481. .byte $97, $97, $99, $92, $92, $98, $9f, $a8, $ac, $ad, $b2, $b9, $bb, $be
  13482. .byte $97, $97, $99, $92, $9c, $a2, $a7, $ac, $b3, $b4, $b7, $bc, $bc, $c0
  13483. .byte $97, $97, $99, $a4, $a9, $ac, $ad, $b0, $b7, $bb, $bd, $bc, $c0, $c0
  13484. .byte $97, $97, $99, $aa, $ae, $b0, $b2, $b6, $bd, $c0, $c0, $c0, $c0, $c0
  13485. .byte $97, $97, $99, $aa, $ae, $b0, $b2, $b6, $bd, $c0, $c0, $c0, $c0, $c0
  13486. #endif
  13487. #endif
  13488.  
  13489.  
  13490.  
  13491. ;******************************************************************
  13492. ;
  13493. ;
  13494. ; Injector deatime as a function of battery voltage
  13495. ;
  13496. ; Each unit correspond to 24us ($08 = 192us)
  13497. ;
  13498. ;
  13499. ; Volts: 4.7, 7.0, 9.4, 11.7, 14.1, 16.4, 18.8
  13500. ;
  13501. ;******************************************************************
  13502. t_deadtime
  13503. #ifdef custDeadTime
  13504. ; Denso 660 .byte $b0, $5f, $37, $2a, $22, $1e, $1a
  13505. ; Worchester, fuel trim = 125,105, 100? .byte $b5, $64, $3c, $2f, $27, $23, $1f
  13506. ; Worchester, fuel trim = <81, 102, 100? .byte $bc, $6b, $43, $36, $2e, $2a, $26
  13507. ; Worchester, fuel trim = <81, 100, 103 .byte $b9, $68, $40, $33, $2b, $27, $23
  13508. .byte $b7, $66, $3e, $31, $29, $25, $21
  13509. #else
  13510. #ifdef E931
  13511. .byte $a9, $58, $30, $23, $1b, $17, $13
  13512. #else
  13513. .byte $a8, $5a, $32, $26, $1a, $17, $11
  13514. #endif
  13515. #endif
  13516.  
  13517.  
  13518.  
  13519. ;******************************************************************
  13520. ;
  13521. ; Table used for the calculation of injPwStart
  13522. ;
  13523. ; non constant sample spacing:
  13524. ;
  13525. ; ectCond/32 ectCond<$c0
  13526. ; (2*ectCond-$c0)/32 ectCond>=$c0
  13527. ;
  13528. ; scale in degC:
  13529. ;
  13530. ; 86 80 52 35 21 8 -7 -16 -29
  13531. ;
  13532. ;******************************************************************
  13533. L2008
  13534. #ifdef E931
  13535. .byte $07, $07, $0d, $14, $22, $36, $60, $83, $a6
  13536. #else
  13537. .byte $07, $07, $0d, $14, $22, $39, $65, $8a, $af
  13538. #endif
  13539.  
  13540.  
  13541.  
  13542. ;******************************************************************
  13543. ;
  13544. ; ect
  13545. ;
  13546. ;
  13547. ;******************************************************************
  13548. t_accEnr2a .byte $17, $17, $28, $45, $60, $70, $80, $80
  13549.  
  13550.  
  13551.  
  13552. ;******************************************************************
  13553. ;
  13554. ; rpm
  13555. ;
  13556. ;
  13557. ;******************************************************************
  13558. t_accEnr1 .byte $ff, $b0, $a8, $80, $80, $88, $90, $a0, $b0, $c0
  13559.  
  13560.  
  13561.  
  13562. ;******************************************************************
  13563. ;
  13564. ; Table is interpolated from ect and used to initialize
  13565. ; accEnrDecay. Basically the values in this table are
  13566. ; the decay factor applied to accEnr on each iteration
  13567. ;
  13568. ; accEnr = accEnr * (1-t_accEnrDecay(ect)/256)
  13569. ;
  13570. ; Slower decay under cold conditions...
  13571. ;
  13572. ;******************************************************************
  13573. t_accEnrDecay .byte $a0, $a0, $f3, $f6, $f7, $f8, $f9, $fa
  13574.  
  13575.  
  13576.  
  13577. ;******************************************************************
  13578. ;
  13579. ; Interpolated from tpsDiff100/4
  13580. ;
  13581. ; Used to compute fuel enrichement when doing simultaneous
  13582. ; injection under acceleration. It is basically a multipler
  13583. ; of the basic enrichment time (sInjEnrInc) depending on
  13584. ; how much acceleration is requested, i.e. how fast the pedal is
  13585. ; moving
  13586. ;
  13587. ;******************************************************************
  13588. t_sInjEnr .byte $03, $04, $05, $07, $09, $0b, $0e, $11, $18
  13589.  
  13590.  
  13591.  
  13592. ;******************************************************************
  13593. ;
  13594. ; Table interpolated from ect. Used in the calculation
  13595. ; of sInjEnrInc, fuel enrichment factor for sim injection
  13596. ; during acceleration
  13597. ;
  13598. ;******************************************************************
  13599. L2013 .byte $00, $00, $04, $12, $18, $20, $30, $40
  13600.  
  13601.  
  13602.  
  13603. ;******************************************************************
  13604. ;
  13605. ; Values are used as a maximum threshold on TPS when calculating fuel
  13606. ; enrichement for simultaneous injection
  13607. ;
  13608. ; rpm scale: 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
  13609. ;
  13610. ;******************************************************************
  13611. t_sInjTpsMax .byte $5b, $6c, $76, $85, $94, $b3, $cd, $cd, $cd, $cd
  13612.  
  13613.  
  13614.  
  13615. ;******************************************************************
  13616. ;
  13617. ; IX = FD2C from L1213
  13618. ; 5 10 15 20 25 30 35 40 45 50 x 100 RPM
  13619. ;
  13620. ;******************************************************************
  13621. L2015 .byte $30, $28, $20, $20, $20, $20, $20, $20, $20, $20
  13622.  
  13623.  
  13624.  
  13625. ;******************************************************************
  13626. ;
  13627. ; XX = FD36 from L1207
  13628. ;
  13629. ;******************************************************************
  13630. t_decEnr2 .byte $50, $50, $8c, $b4, $f0, $f0, $ff, $ff
  13631.  
  13632.  
  13633.  
  13634. ;******************************************************************
  13635. ;
  13636. ; IX = FD3E from L1206
  13637. ;
  13638. ;******************************************************************
  13639. t_decEnr1 .byte $1a, $20, $26, $2d, $33, $4d, $66, $80, $c0, $ff
  13640.  
  13641.  
  13642.  
  13643. ;******************************************************************
  13644. ;
  13645. ; Table of timing values under high octane conditions, values are shifted by
  13646. ; 10deg in oder to allow for timing retard (0 = -10deg advance, 18 = 8 deg advance)
  13647. ; It contains timing values to use when octane=255 (no knock)
  13648. ;
  13649. ; Timing used is interpolated from
  13650. ;
  13651. ; timingOct = alpha * t_timingHiOct(rpm, load) + (1-alpha) * t_timingLoOct(rpm, load)
  13652. ;
  13653. ; where alpha = octane/255, 0<= alpha <=1
  13654. ;
  13655. ; rpm 500 1000 1500 2000 2500 3000 3500 4000 4500 5000 5500 6000 6500 7000 7500 8000
  13656. ;
  13657. ;******************************************************************
  13658. t_timingHiOct
  13659. #ifdef custTimingMap
  13660. .byte $14, $1a, $23, $26, $29, $2b, $2e, $30, $32, $32, $32, $32, $32, $32, $32, $32
  13661. .byte $14, $1a, $22, $25, $26, $27, $2a, $2b, $2c, $2c, $2c, $2c, $2c, $2c, $2d, $2d
  13662. .byte $13, $18, $1e, $20, $21, $24, $27, $27, $27, $27, $27, $27, $28, $2a, $2b, $2b
  13663. .byte $12, $16, $18, $1c, $1d, $1e, $21, $23, $24, $24, $25, $25, $26, $28, $29, $29
  13664. .byte $11, $12, $16, $18, $19, $1a, $1c, $1f, $21, $22, $23, $23, $26, $28, $28, $28
  13665. .byte $10, $11, $12, $14, $15, $16, $17, $19, $1a, $1c, $1d, $1e, $20, $22, $24, $24
  13666. .byte $0f, $10, $11, $12, $13, $14, $15, $16, $17, $19, $1a, $1b, $1d, $1f, $21, $21
  13667. .byte $0d, $0d, $0e, $0f, $10, $12, $13, $14, $15, $17, $18, $19, $1b, $1d, $1f, $1f
  13668. .byte $0b, $0c, $0c, $0d, $0e, $10, $11, $12, $13, $15, $16, $17, $19, $1b, $1c, $1d
  13669. .byte $0a, $0b, $0b, $0c, $0d, $0e, $0f, $10, $11, $13, $14, $15, $17, $19, $1a, $1b
  13670. .byte $09, $0a, $0a, $0b, $0b, $0c, $0d, $0e, $0f, $11, $12, $13, $15, $17, $18, $19
  13671. .byte $08, $09, $09, $0a, $0a, $0b, $0c, $0c, $0d, $0f, $10, $11, $13, $15, $16, $17
  13672. #else
  13673. #ifdef E931
  13674. .byte $12, $17, $1c, $22, $28, $2f, $30, $31, $32, $33, $36, $37, $37, $37, $37, $37
  13675. .byte $12, $17, $1d, $23, $27, $2d, $2e, $30, $30, $32, $34, $37, $37, $37, $37, $37
  13676. .byte $12, $18, $1f, $25, $28, $2b, $2d, $2f, $32, $32, $32, $32, $32, $32, $32, $32
  13677. .byte $12, $1a, $22, $26, $28, $29, $2a, $2d, $2d, $2d, $2d, $2d, $2f, $2f, $2f, $2f
  13678. .byte $12, $1a, $22, $25, $25, $27, $28, $2b, $2b, $2b, $2b, $2b, $2b, $2b, $2d, $2d
  13679. .byte $12, $18, $20, $22, $22, $23, $26, $28, $28, $28, $28, $28, $29, $2a, $2c, $2d
  13680. .byte $12, $18, $19, $1c, $1d, $1f, $24, $25, $25, $25, $26, $26, $27, $29, $2b, $29
  13681. .byte $0f, $16, $18, $1c, $19, $19, $1e, $22, $24, $24, $25, $25, $26, $28, $28, $24
  13682. .byte $0c, $12, $16, $18, $19, $17, $19, $1e, $22, $22, $23, $23, $26, $28, $26, $20
  13683. .byte $0a, $0f, $13, $16, $17, $17, $15, $19, $1d, $1f, $20, $21, $23, $27, $22, $1d
  13684. .byte $08, $0d, $11, $14, $15, $16, $15, $19, $19, $1c, $1c, $1d, $20, $23, $1e, $1d
  13685. .byte $06, $0b, $0f, $12, $13, $14, $14, $18, $19, $1c, $1c, $1d, $20, $22, $1e, $1c
  13686. #else
  13687. .byte $12, $17, $1c, $22, $28, $2f, $30, $31, $32, $33, $36, $37, $37, $37, $37, $37
  13688. .byte $12, $17, $1d, $23, $27, $2d, $2d, $2d, $2d, $30, $33, $37, $37, $37, $37, $37
  13689. .byte $12, $18, $1e, $25, $28, $2a, $2a, $2e, $2e, $2f, $2e, $2d, $2d, $2d, $2a, $2a
  13690. .byte $12, $19, $1f, $23, $24, $28, $28, $2a, $2a, $2a, $2a, $2a, $2a, $2a, $2a, $2a
  13691. .byte $12, $1a, $20, $21, $22, $24, $25, $27, $27, $27, $27, $27, $28, $28, $28, $28
  13692. .byte $12, $1a, $1d, $20, $21, $22, $23, $24, $25, $25, $26, $26, $27, $27, $27, $27
  13693. .byte $12, $16, $18, $19, $1c, $1e, $20, $22, $24, $24, $25, $26, $26, $27, $26, $24
  13694. .byte $0f, $14, $16, $16, $14, $16, $1a, $22, $24, $24, $24, $24, $25, $27, $24, $22
  13695. .byte $0c, $12, $14, $16, $12, $13, $17, $1d, $21, $22, $22, $22, $24, $26, $22, $20
  13696. .byte $0a, $10, $12, $14, $0f, $10, $15, $1a, $1d, $20, $20, $20, $22, $24, $20, $1e
  13697. .byte $08, $0e, $10, $12, $0d, $10, $15, $19, $1c, $1f, $1f, $1f, $21, $22, $1f, $1e
  13698. .byte $06, $0c, $0e, $10, $0c, $0e, $15, $19, $1c, $1e, $1e, $1f, $21, $20, $1f, $1d
  13699. #endif
  13700. #endif
  13701.  
  13702.  
  13703.  
  13704. ;******************************************************************
  13705. ;
  13706. ; Table of timing values under low octane conditions values are shifted by
  13707. ; 10deg in oder to allow for timing retard (0 = -10deg advance, 18 = 8 deg advance)
  13708. ; It contains timing values to use when octane=0 (lots of knock)
  13709. ;
  13710. ; Timing applied is interpolated from
  13711. ;
  13712. ; timingOct = alpha * t_timingHiOct(rpm, load) + (1-alpha) * t_timingLoOct(rpm, load)
  13713. ;
  13714. ; where alpha = octane/255, 0<= alpha <=1
  13715. ;
  13716. ; Note that the first three rows of t_timingLoOct have been eliminated from
  13717. ; this table (t_timingLoOct correspond to the last 9 rows of t_timingHiOct)
  13718. ;
  13719. ;
  13720. ;******************************************************************
  13721. t_timingLoOct
  13722. #ifdef custOctaneMap
  13723. .byte $12, $16, $18, $1c, $1d, $1e, $21, $23, $24, $24, $25, $25, $26, $28, $29, $2a
  13724. .byte $11, $12, $16, $18, $19, $1a, $1c, $1f, $21, $22, $23, $24, $25, $27, $28, $29
  13725. .byte $10, $11, $12, $14, $15, $16, $17, $19, $1a, $1c, $1d, $1e, $20, $22, $24, $24
  13726. .byte $0f, $10, $11, $12, $13, $14, $15, $16, $17, $19, $1a, $1b, $1d, $1f, $21, $21
  13727. .byte $0b, $0d, $0e, $0f, $10, $12, $13, $14, $15, $17, $18, $19, $1b, $1d, $1f, $1f
  13728. .byte $0a, $0c, $0c, $0d, $0e, $10, $11, $12, $13, $15, $16, $17, $19, $1b, $1c, $1d
  13729. .byte $09, $0b, $0b, $0c, $0d, $0e, $0f, $10, $11, $13, $14, $15, $17, $19, $1a, $1b
  13730. .byte $08, $0a, $0a, $0b, $0b, $0c, $0d, $0e, $0f, $11, $12, $13, $15, $17, $18, $19
  13731. .byte $07, $08, $09, $0a, $0a, $0b, $0c, $0c, $0d, $0f, $10, $11, $13, $15, $16, $17
  13732. #else
  13733. #ifdef E931
  13734. .byte $12, $1a, $22, $26, $28, $29, $2a, $2d, $2d, $2d, $2d, $2d, $2f, $2f, $2f, $2f
  13735. .byte $12, $19, $1e, $21, $22, $24, $27, $2a, $2a, $2a, $2a, $2a, $2c, $2c, $2d, $2d
  13736. .byte $0c, $13, $19, $1d, $1e, $20, $24, $27, $28, $28, $28, $28, $28, $2a, $2a, $27
  13737. .byte $09, $0c, $11, $14, $15, $1b, $21, $24, $25, $25, $25, $25, $25, $25, $24, $20
  13738. .byte $07, $0c, $0d, $0e, $11, $13, $1b, $1f, $1f, $21, $23, $24, $24, $22, $22, $1c
  13739. .byte $05, $0a, $0b, $0c, $0e, $0e, $14, $18, $1d, $1e, $1e, $1f, $21, $21, $20, $1a
  13740. .byte $03, $08, $09, $0a, $0c, $0c, $0f, $16, $18, $1a, $1c, $1c, $1d, $20, $1e, $18
  13741. .byte $01, $06, $07, $08, $0b, $0b, $0e, $10, $15, $17, $17, $18, $18, $1a, $18, $16
  13742. .byte $00, $04, $05, $06, $0a, $0a, $0c, $0e, $12, $13, $14, $16, $16, $18, $16, $14
  13743. #else
  13744. .byte $12, $19, $1f, $23, $24, $28, $28, $2a, $2a, $2a, $2a, $2a, $2a, $2a, $2a, $2a
  13745. .byte $12, $1c, $21, $23, $24, $26, $28, $2a, $2a, $2a, $2a, $2a, $2a, $2a, $2a, $2a
  13746. .byte $12, $14, $19, $1b, $1e, $20, $24, $27, $26, $29, $29, $29, $2a, $2a, $2a, $2a
  13747. .byte $0c, $10, $12, $14, $16, $18, $1c, $26, $26, $26, $25, $24, $26, $27, $27, $24
  13748. .byte $0b, $0f, $0d, $0e, $0e, $11, $16, $1b, $1d, $20, $1c, $1b, $21, $22, $22, $1c
  13749. .byte $09, $0d, $0b, $0c, $0c, $0c, $10, $17, $18, $1a, $1a, $19, $1e, $20, $1e, $18
  13750. .byte $07, $0b, $09, $0a, $0a, $0b, $0e, $12, $15, $17, $17, $18, $1b, $1d, $1a, $16
  13751. .byte $05, $09, $07, $08, $08, $09, $0d, $0f, $12, $15, $15, $16, $19, $1a, $18, $14
  13752. .byte $03, $07, $05, $06, $06, $07, $0b, $0d, $10, $13, $13, $14, $17, $18, $16, $12
  13753. #endif
  13754. #endif
  13755.  
  13756.  
  13757. ;******************************************************************
  13758. ;
  13759. ; Interpolated from ect, used in timing advance calculations
  13760. ;
  13761. ; $81 = 1 deg advance
  13762. ; $80 = 0 deg
  13763. ; $7f = -1 deg advance
  13764. ;
  13765. ;******************************************************************
  13766. L2020 .byte $80, $80, $80, $80, $80, $84, $88, $8b
  13767.  
  13768.  
  13769.  
  13770. ;******************************************************************
  13771. ;
  13772. ; Interpolated from iat, values used in
  13773. ; timing advance calculations
  13774. ;
  13775. ; $81 = 1 deg advance
  13776. ; $80 = 0 deg
  13777. ; $7f = -1 deg advance
  13778. ;
  13779. ;******************************************************************
  13780. L2021 .byte $7d, $7f, $80, $80, $80, $7f, $7e
  13781.  
  13782.  
  13783.  
  13784. ;******************************************************************
  13785. ;
  13786. ; Interpolated from battRaw. Values are basic coil
  13787. ; energization time, each unit correspond to 64usec?
  13788. ;
  13789. ;
  13790. ; Voltages: 9.38v 10.56v 11.73v 12.9v 14.1v 15.2v 16.4v 17.6v 18.8v
  13791. ;
  13792. ;******************************************************************
  13793. t_enerLen .byte $bc, $9c, $7a, $64, $56, $49, $42, $3a, $37
  13794.  
  13795.  
  13796.  
  13797. ;******************************************************************
  13798. ;
  13799. ; Interpolated from ect, This is the isc step offset added to the
  13800. ; base isc step when the engine is started.
  13801. ;
  13802. ;
  13803. ;******************************************************************
  13804. L2023 .byte $1f, $1a, $1b, $1c, $21, $2b, $3b, $46
  13805.  
  13806.  
  13807.  
  13808. ;******************************************************************
  13809. ;
  13810. ; Interpolated from ect, values xx are loaded
  13811. ; into T40_iscStart to produce 40/xx Hz
  13812. ;
  13813. ;******************************************************************
  13814. L2024 .byte $07, $07, $07, $07, $07, $08, $0a, $0c
  13815.  
  13816.  
  13817.  
  13818.  
  13819. ;******************************************************************
  13820. ;
  13821. ; Target idle speed as a function of ect
  13822. ;
  13823. ; idle speed = xx * 7.8125
  13824. ;
  13825. ; default = 750, 750, 1000, 1148, 1273, 1398, 1500, 1648
  13826. ;******************************************************************
  13827. t_idleSpd .byte idleVal, idleVal, $80, $93, $a3, $b3, $c0, $d3
  13828.  
  13829.  
  13830.  
  13831. ;******************************************************************
  13832. ;
  13833. ; AT specific table (in drive???)
  13834. ;
  13835. ; idle speed = xx * 7.8125
  13836. ;
  13837. ; default = 648, 648, 797, 898, 1000, 1047, 1101, 1148
  13838. ;******************************************************************
  13839. #ifdef E932
  13840. t_idleSpdDr .byte idleDrVal, idleDrVal, $66, $73, $80, $86, $8d, $93
  13841. #endif
  13842.  
  13843.  
  13844.  
  13845. ;******************************************************************
  13846. ;
  13847. ; Target or basic ISC step value as a function of ect
  13848. ; Used for instance to set iscStepTarg during basic
  13849. ; idle speed adjustment
  13850. ;
  13851. ;******************************************************************
  13852. t_iscStEct0
  13853. #ifdef E931
  13854. .byte $09, $12, $2e, $3b, $3c, $41, $4a, $54
  13855. #else
  13856. .byte $09, $10, $34, $3f, $46, $50, $5a, $64
  13857. #endif
  13858.  
  13859.  
  13860.  
  13861. ;******************************************************************
  13862. ;
  13863. ; Target ISC step value as a function of ect
  13864. ;
  13865. ; AT specific table. This table corresponds to t_iscStEct0
  13866. ; but is used when AT is in drive
  13867. ;
  13868. ;******************************************************************
  13869. #ifdef E932
  13870. t_iscStEct1 .byte $0c, $13, $3c, $46, $4e, $58, $64, $6e
  13871. #endif
  13872.  
  13873.  
  13874. ;******************************************************************
  13875. ;
  13876. ; Interpolated from conditionned TPS (conTps) (see main code)
  13877. ;
  13878. ; This is related to the minimum isc step to use when the idle
  13879. ; switch transition from off to on and rpm8 goes too low (500rpm)
  13880. ; We don't want the engine to stall...
  13881. ;
  13882. ;
  13883. ;******************************************************************
  13884. t_iscStStall .byte $09, $23, $2c, $3b, $45, $4c, $53
  13885.  
  13886.  
  13887.  
  13888. ;******************************************************************
  13889. ;
  13890. ; AT specific table, equivalent of t_iscStStall when not in park/neutral
  13891. ;
  13892. ;******************************************************************
  13893. #ifdef E932
  13894. L2030 .byte $09, $23, $45, $4f, $4f, $4f, $4f
  13895. #endif
  13896.  
  13897.  
  13898.  
  13899. ;******************************************************************
  13900. ;
  13901. ; Interpolated from ect, contains ISC step values
  13902. ;
  13903. ;******************************************************************
  13904. L2031 .byte $5a, $5a, $5a, $64, $6e, $78, $78, $78
  13905.  
  13906.  
  13907.  
  13908. ;******************************************************************
  13909. ;
  13910. ; Table is interpolated from (rpm4/2 - idleSpdTarg)/4.
  13911. ; Values are timer values (40Hz) used to update T40s_iscStable
  13912. ; when idle switch is off (isc is considered stable when this
  13913. ; timer expires...).
  13914. ;
  13915. ;******************************************************************
  13916. t_iscStableIdleSw .byte $50, $50, $6e, $82, $96, $aa, $be, $d2, $e6, $f4, $ff
  13917.  
  13918.  
  13919.  
  13920. ;******************************************************************
  13921. ;
  13922. ; ISC pattern sequence to load to port5 bit 6
  13923. ; and 7 to move the ISC spindle
  13924. ;
  13925. ;
  13926. ; --> move spindle
  13927. ; bit 7 1 0 0 1
  13928. ; bit 6 0 0 1 1
  13929. ;
  13930. ;******************************************************************
  13931. t_iscPattern .byte $80, $00, $40, $c0
  13932.  
  13933.  
  13934.  
  13935. ;******************************************************************
  13936. ;
  13937. ; ISC step offset as a function of barometric pressure?
  13938. ; The value in this table is added to iscStepCurr to compensate
  13939. ; for barometric pressure
  13940. ;
  13941. ; Table interpolated with baroCond (0.45bar to 0.92bar)
  13942. ; which means there is no offset ($00) when baroCond > 0.92bar
  13943. ;
  13944. ;******************************************************************
  13945. t_iscStBaro .byte $1a, $12, $09, $04, $00
  13946.  
  13947.  
  13948.  
  13949. ;******************************************************************
  13950. ;
  13951. ; Interpolated from 4 * abs(idleSpdTarg - rpm8), the difference
  13952. ; between target idle speed and the current rpm
  13953. ;
  13954. ; Values are compared to iscStepTarg
  13955. ;
  13956. ;******************************************************************
  13957. L2035 .byte $00, $02, $06, $0a, $0d, $0e, $0e, $0f, $0f
  13958.  
  13959.  
  13960.  
  13961. ;******************************************************************
  13962. ;
  13963. ; Used in the calculation of the default air count when we are
  13964. ; not receiving airflow sensor interrupts, interpolated from ect
  13965. ; Seem to be some kind of tps offset...
  13966. ;
  13967. ;******************************************************************
  13968. L2036 .byte $00, $00, $00, $02, $03, $04, $0a, $10
  13969.  
  13970.  
  13971.  
  13972. ;******************************************************************
  13973. ;
  13974. ; Open loop minimum fuel enrichment table ($80=100)
  13975. ; interpolated by TPS
  13976. ;
  13977. ;
  13978. ;******************************************************************
  13979. t_tpsEnr .byte $78, $80, $90, $92
  13980.  
  13981.  
  13982.  
  13983. ;******************************************************************
  13984. ;
  13985. ; Interpolated from rpm, contains airVolB thresholds used in
  13986. ; timing advance calculations, used in conjuction with L2021
  13987. ;
  13988. ; 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
  13989. ;
  13990. ;******************************************************************
  13991. L2038 .byte $00, $00, $71, $71, $71, $80, $90, $a0, $a0, $a0
  13992.  
  13993.  
  13994.  
  13995. ;******************************************************************
  13996. ;
  13997. ; Table contains airCnt0 thresholds as a function of RPM
  13998. ;
  13999. ; airCnt0 > $57*L2039(rpm)/16 ?
  14000. ;
  14001. ; 5 10 15 20 25 30 35 40 45 50 x 100 RPM
  14002. ;
  14003. ;******************************************************************
  14004. L2039 .byte $6d, $6d, $85, $b4, $c8, $d0, $d6, $f0, $ff, $ff
  14005.  
  14006.  
  14007.  
  14008. ;******************************************************************
  14009. ;
  14010. ; Acceleration enrichment
  14011. ;
  14012. ; Interpolated from L2040(min(oldAirCnt0/256,5))
  14013. ;
  14014. ;******************************************************************
  14015. L2040 .byte $0b, $0b, $0d, $10, $15, $1b
  14016.  
  14017.  
  14018.  
  14019. ;******************************************************************
  14020. ;
  14021. ; Interpolated from f(rpm4)
  14022. ;
  14023. ; Table contain airVol threshold values
  14024. ;
  14025. ;******************************************************************
  14026. L2041 .byte $ff, $ff, $ff, $ff, $ff, $9b, $a0, $a5, $b8, $c8, $d0, $ff
  14027.  
  14028.  
  14029.  
  14030. ;******************************************************************
  14031. ;
  14032. ; Table used for the calculation of injPwStart
  14033. ; Only factored-in if injCount<5 (when the engine starts to crank??)
  14034. ;
  14035. ; non constant sample spacing:
  14036. ;
  14037. ; ectCond/32 if ectCond<$c0
  14038. ; (2*ectCond-$c0)/32 if ectCond>=$c0
  14039. ;
  14040. ; scale in degC:
  14041. ;
  14042. ; 86 80 52 35 21 8 -7 -16 -29
  14043. ;
  14044. ;******************************************************************
  14045. L2042 .byte $00, $00, $00, $00, $00, $00, $00, $20, $40
  14046.  
  14047.  
  14048.  
  14049. ;******************************************************************
  14050. ;
  14051. ;
  14052. ; Boost gauge scale interpolated from airVolT/16
  14053. ;
  14054. ;
  14055. ;******************************************************************
  14056. t_bGauge .byte $02, $05, $08, $0a, $0d, $0f, $11, $13, $14
  14057.  
  14058.  
  14059.  
  14060. ;******************************************************************
  14061. ;
  14062. ; EGR solenoid duty cycle
  14063. ; as a function of rpm(column) and airVol(row)
  14064. ;
  14065. ;******************************************************************
  14066. t_egrDutyFact
  14067. #ifdef E931
  14068. .byte $00, $00, $00, $00, $00, $00, $00, $00
  14069. .byte $00, $00, $00, $5b, $56, $4c, $4d, $00
  14070. .byte $00, $00, $00, $5b, $56, $4c, $4d, $00
  14071. .byte $00, $00, $00, $5b, $56, $60, $5c, $00
  14072. .byte $00, $00, $60, $76, $6c, $5f, $5b, $00
  14073. .byte $80, $80, $80, $7d, $6e, $5f, $60, $00
  14074. .byte $80, $80, $80, $80, $76, $68, $61, $00
  14075. .byte $80, $80, $80, $80, $80, $60, $61, $00
  14076. .byte $00, $80, $80, $80, $80, $78, $6e, $00
  14077. #else
  14078. .byte $00, $00, $00, $00, $00, $00, $00, $00
  14079. .byte $00, $00, $00, $5a, $40, $3b, $41, $00
  14080. .byte $00, $00, $00, $5a, $40, $3b, $41, $00
  14081. .byte $00, $00, $00, $4c, $48, $5a, $56, $00
  14082. .byte $00, $00, $53, $4d, $5d, $57, $55, $00
  14083. .byte $80, $80, $68, $6a, $5c, $57, $53, $00
  14084. .byte $80, $80, $80, $6e, $5f, $57, $55, $00
  14085. .byte $80, $80, $80, $80, $5f, $5a, $56, $00
  14086. .byte $00, $80, $80, $80, $80, $80, $80, $00
  14087. #endif
  14088.  
  14089.  
  14090.  
  14091.  
  14092. ;******************************************************************
  14093. ;
  14094. ; EGR solenoid duty cycle as a function of ECT
  14095. ;
  14096. ; Value of $00 to $80 will produce
  14097. ; 0 to 100% duty cycle
  14098. ;
  14099. ;
  14100. ;******************************************************************
  14101. t_egrDuty .byte $80, $80, $5b, $4f, $00, $00, $00, $00
  14102.  
  14103.  
  14104.  
  14105. ;******************************************************************
  14106. ;
  14107. ; Interpolated from iat, values are used as minimum egrt
  14108. ; temperature for egrt sensor to be considered as working correctly
  14109. ;
  14110. ; if temperature(egrtRaw) < L2046(iat) then egrt is probably in error
  14111. ;
  14112. ;
  14113. ; in degCC for E931: 83 83 53 41 31 -31 -68
  14114. ;
  14115. ;******************************************************************
  14116. L2046
  14117. #ifdef E931
  14118. .byte $9a, $9a, $ae, $b6, $bd, $e6, $ff
  14119. #else
  14120. .byte $9a, $9a, $a4, $ab, $bd, $e6, $ff
  14121. #endif
  14122.  
  14123.  
  14124.  
  14125. ;******************************************************************
  14126. ;
  14127. ; Interpolated from rpm, values are used as minimum airVol
  14128. ; to verify if egrt sensor is working properly
  14129. ;
  14130. ; 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
  14131. ;
  14132. ;******************************************************************
  14133. L2047
  14134. #ifdef E931
  14135. .byte $60, $60, $58, $44, $35, $33, $30, $30, $30, $30
  14136. #else
  14137. .byte $60, $60, $60, $4c, $40, $38, $33, $30, $30, $30
  14138. #endif
  14139.  
  14140.  
  14141.  
  14142. ;******************************************************************
  14143. ;
  14144. ; Interpolated from rpm, values are used as maxmimum airVol
  14145. ; to verify if egrt sensor is working properly
  14146. ;
  14147. ; 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
  14148. ;
  14149. ;******************************************************************
  14150. L2048
  14151. #ifdef E931
  14152. .byte $60, $60, $68, $88, $98, $9c, $a4, $88, $88, $88
  14153. #else
  14154. .byte $60, $60, $78, $98, $a8, $b0, $b0, $b0, $b0, $b0
  14155. #endif
  14156.  
  14157.  
  14158.  
  14159. ;******************************************************************
  14160. ;
  14161. ; Table interpolated from ect
  14162. ;
  14163. ;******************************************************************
  14164. t_accEnr2b .byte $1c, $1e, $30, $53, $73, $86, $9a, $9a
  14165.  
  14166.  
  14167.  
  14168. ;******************************************************************
  14169. ;
  14170. ; Table interpolated from ect. Used in the calculation
  14171. ; of sInjEnrInc, fuel enrichment factor for sim injection
  14172. ; during acceleration
  14173. ;
  14174. ;******************************************************************
  14175. L2050 .byte $10, $14, $18, $29, $30, $3a, $4d, $60
  14176.  
  14177.  
  14178.  
  14179. ;******************************************************************
  14180. ;
  14181. ; Table interpolated from ect. Values are timer thresholds (2Hz timer)
  14182. ; used in deciding acceleration enrichment factor and simultaneous
  14183. ; injection enrichment
  14184. ;
  14185. ;******************************************************************
  14186. L2051 .byte $1e, $22, $2e, $36, $3c, $42, $4a, $56
  14187.  
  14188.  
  14189.  
  14190. ;******************************************************************
  14191. ;
  14192. ; Piecewise linear rpm transformation data
  14193. ;
  14194. ; Using pwiseLin with this table, we get input(x)/output(y) relationship:
  14195. ;
  14196. ; $00<=x<=$03 -> y = 0
  14197. ; $04<=x<=$07 -> y = x-$03
  14198. ; $08<=x<=$1c -> y = (x+$02)/2
  14199. ; $1d<=x -> y = ($1c+$02)/2
  14200. ;
  14201. ; First row is
  14202. ; max, offset
  14203. ; Other rows (i=1 to n) are
  14204. ; addVal(i), nshift(i), compVal(i)
  14205. ;
  14206. ;******************************************************************
  14207. L2052 .byte $1c, $03,
  14208. .byte $00, $01, $05,
  14209. .byte $05, $02, $ff
  14210.  
  14211.  
  14212.  
  14213. ;******************************************************************
  14214. ;
  14215. ; Piecewise linear rpm transformation data
  14216. ;
  14217. ; Using pwiseLin with this table, we get input(x)/output(y) relationship:
  14218. ;
  14219. ; $00<=x<=$02 -> y = 0
  14220. ; $03<=x<=$03 -> y = (x-$02)/2
  14221. ; $04<=x<=$10 -> y = x/4
  14222. ; $11<=x -> y = $10/4
  14223. ;
  14224. ; First row is
  14225. ; max, offset
  14226. ; Other rows (i=1 to n) are
  14227. ; addVal(i), nshift(i), compVal(i)
  14228. ;
  14229. ;******************************************************************
  14230. L2053 .byte $10, $02,
  14231. .byte $00, $02, $02,
  14232. .byte $02, $03, $ff
  14233.  
  14234.  
  14235.  
  14236. ;******************************************************************
  14237. ;
  14238. ; Piecewise linear mafRaw16 (gramOfAir/sec) transformation data
  14239. ; Note that this table is the same in 2G ECUs so that it doesn't need
  14240. ; to be changed if 2G maf is used...
  14241. ;
  14242. ; The output of pwiseLin using this table is used to interpolate t_masComp
  14243. ; This means that t_masComp is a table with non-constant spacing between values
  14244. ; The spacing is given by the transformation in this table...
  14245. ;
  14246. ; Using pwiseLin with this table, we get input(x)/output(y) relationship:
  14247. ;
  14248. ; $00<=x<=$0b -> y = x
  14249. ; $0c<=x<=$17 -> y = (x+$24)/4
  14250. ; $18<=x<=$40 -> y = (x+$60)/8
  14251. ; $41<=x -> y = ($40+$60)/8
  14252. ;
  14253. ; First row is
  14254. ; max, offset
  14255. ; Other rows (i=1 to n) are
  14256. ; addVal(i), nshift(i), compVal(i)
  14257. ;
  14258. ;******************************************************************
  14259. L2054 .byte $40, $00,
  14260. .byte $00, $01, $0c,
  14261. .byte $24, $03, $18,
  14262. .byte $60, $04, $ff
  14263.  
  14264. ;******************************************************************
  14265. ;
  14266. ; Unused??????
  14267. ;
  14268. ;******************************************************************
  14269. L2055 .byte $01, $01
  14270.  
  14271.  
  14272.  
  14273. ;******************************************************************
  14274. ;
  14275. ; Interrupt vector
  14276. ;
  14277. ;
  14278. ;
  14279. ;******************************************************************
  14280. #if (codeOffset > 0)
  14281. .fill intVector-$, $ff
  14282. #endif
  14283. intVector .org $ffe0
  14284. .word serialRxInt ; Serial port Rx interrupt subroutine
  14285. .word reset ; ???
  14286. .word realTimeInt ; Real time interrupt (801.28Hz)
  14287. .word reset ; ???
  14288. .word reset ; ???
  14289. .word reset ; ???
  14290. .word outCompInt3 ; Output compare interrupt3 (coil power transistor activation/deactivation)
  14291. .word outCompInt2 ; Output compare interrupt2 (injector 2 or 3 activation/deactivation)
  14292. .word outCompInt1 ; Output compare interrupt1 (injector 1 or 4 activation/deactivation)
  14293. .word reset ; ???
  14294. .word inCaptInt2 ; Input capture interrupt 2 (airflow sensor pulse)
  14295. .word inCaptInt1 ; Input capture interrupt 1 (cas rising or falling edge)
  14296. .word reset ; Illegal opcode trap?
  14297. .word reset ; Cop failure?
  14298. .word failureInt ; Timer clock failure?
  14299. .word codeStart ; System reset
  14300. .end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement