[edit: Is your car starting, shifting, and driving normally? If so, perhaps the repairs were made and the codes were never cleared from the computer. If these codes were active, seems like you would be having some serious issues like no 4th gear, no TC lockup, and 10 degrees of retarded timing yeilding sluggish acceleration. To clear codes, disconnect the negative battery cable for a couple of minutes, then re-connect it. Drive the car for a while then check for the codes again.]
Most of the following information was lifted from the '92 FSM. Also included is some guesswork by me. I only have personal experience working with the PRNDL switch alignment and knock sensor circuit. Others more knowledgable with the 31 and 38 codes will hopefully chime in.
Code 31 PRNDL switch circuit:
The PRNDL switch is mounted on the transaxle assembly. It is possible that the switch has loosened and become misaligned. There is a procedure for re-aligning the switch.
"When code 31 is present, the PCM assumes the D4 (overdrive) position until a correct combination is received by the PCM. Therefore, some gear select positions may not be possible until the fault is repaired."
Check for poor connections, rubbed through wire insulation, or a wire broken inside the insulation on the wires from the switch on the transaxle to the PCM.
Inspect the PCM harness connectors for backed-out terminals, improper mating, broken locks, damaged terminals, poor connections and damaged harness
Functions are tested with a Tech 1 scan tool at the dealer.
Code 38 TCC Brake input circuit: (tcc= torque converter clutch)
This switch is attached under the instrument panel and presses against the brake pedal arm so that when you depress the brake, the switch cycles. Maybe it is just misaligned, or not properly adjusted.
"A single code 38 is the result of an open in CKT 420 between the splice and the PCM, poor connection at PCM, or possibly a faulty PCM."
"If the brake switch has failed in an open state, TCC will not engage."
"When code 38 is set, the PCM will not allow 4th gear or TCC operation."
Need year and model specific info for further tests
Code 43 knock sensor (ESC circuit): (paraphrased)
"If the knock sensor circuit becomes open or shorted to ground, code 43 will be stored"
"If Code 43 is set, PCM will retard spark by 10 degrees"
Check the knock sensor connection on the front of the engine near the starter.