Is it just me who reads back code and finds you get confused on why you did something, and once you've re-read the entire code find its a clever way to reduce code space or processing times?
just recently I have been writing new code for the macro rail to account for internally focusing lenses, and instead of loading 2 constants to the fpu and running a different sum (and there for needing 2 large i2c commands) I alter the FPU constant between the required states. This had the affect of removing the addition of an extra 4 if statements.
alas that programme was abandoned due to constraints in another programme slot. Moving to use uM FPU functions and the additional if statements save about 100 bytes of programme space in the latest version of the programme. In the end the updated sub procedures saved 10 lines of code, 8 hi2couts, 2 i2cin, 2 if statements and added 4 new if statements. I am o not sure how it compares in the form of speed, but I should imagine it would not be slower as there is less time transmitting on the i2c bus
A bit of random 5AM thought I know, but I cant the only one who surprises themselves when they look back at old code.
an old sub
a new sub
pre compiled FPU code for increasing the unit width
and post compling
just recently I have been writing new code for the macro rail to account for internally focusing lenses, and instead of loading 2 constants to the fpu and running a different sum (and there for needing 2 large i2c commands) I alter the FPU constant between the required states. This had the affect of removing the addition of an extra 4 if statements.
alas that programme was abandoned due to constraints in another programme slot. Moving to use uM FPU functions and the additional if statements save about 100 bytes of programme space in the latest version of the programme. In the end the updated sub procedures saved 10 lines of code, 8 hi2couts, 2 i2cin, 2 if statements and added 4 new if statements. I am o not sure how it compares in the form of speed, but I should imagine it would not be slower as there is less time transmitting on the i2c bus
A bit of random 5AM thought I know, but I cant the only one who surprises themselves when they look back at old code.
an old sub
Code:
[color=Black]increment:
[/color][color=Blue]if [/color][color=Purple]tempbyte [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then
[/color][color=Green]'increment width
[/color][color=Blue]hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](selecta[/color][color=Black], [/color][color=Blue]uwidth[/color][color=Black], [/color][color=Blue]fadd[/color][color=Black], [/color][color=Blue]tfloat0)
hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](selecta[/color][color=Black], [/color][color=Blue]uwidth[/color][color=Black], [/color][color=Blue]fcmp[/color][color=Black], [/color][color=Blue]tfloat1) [/color][color=Green]'>300
[/color][color=Blue]hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](readstatus)
hi2cin [/color][color=Navy]0[/color][color=Black], [/color][color=Blue]([/color][color=Purple]status[/color][color=Blue])
if [/color][color=Purple]status [/color][color=DarkCyan]= [/color][color=Navy]128 [/color][color=Blue]then
hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](selecta[/color][color=Black], [/color][color=Blue]uwidth[/color][color=Black], [/color][color=Blue]fsub[/color][color=Black], [/color][color=Blue]tfloat0)
end if
else
[/color][color=Green]'increment hight
[/color][color=Blue]hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](selecta[/color][color=Black], [/color][color=Blue]uhight[/color][color=Black], [/color][color=Blue]fadd[/color][color=Black], [/color][color=Blue]tfloat0)
hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](selecta[/color][color=Black], [/color][color=Blue]uhight[/color][color=Black], [/color][color=Blue]fcmp[/color][color=Black], [/color][color=Blue]tfloat1)
hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](readstatus)
hi2cin [/color][color=Navy]0[/color][color=Black], [/color][color=Blue]([/color][color=Purple]status[/color][color=Blue])
if [/color][color=Purple]status [/color][color=DarkCyan]= [/color][color=Navy]128 [/color][color=Blue]then
hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](selecta[/color][color=Black], [/color][color=Blue]uhight[/color][color=Black], [/color][color=Blue]fsub[/color][color=Black], [/color][color=Blue]tfloat0)
end if
end if
gosub [/color][color=Black]display
[/color][color=Blue]return[/color]
Code:
[color=Black]increment:
[/color][color=Blue]if [/color][color=Purple]tempbyte [/color][color=DarkCyan]= [/color][color=Navy]1 [/color][color=Blue]then
[/color][color=Green]'increment width
[/color][color=Blue]if [/color][color=Purple]tempbyte1 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then
hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](fcall[/color][color=Black], [/color][color=Blue]inc_sens_width_deci)
else
hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](fcall[/color][color=Black], [/color][color=Blue]inc_sens_width_unit)
end if
else
[/color][color=Green]'increment hight
[/color][color=Blue]if [/color][color=Purple]tempbyte1 [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then
hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](fcall[/color][color=Black], [/color][color=Blue]inc_sens_hight_deci)
else
hi2cout [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](fcall[/color][color=Black], [/color][color=Blue]inc_sens_hight_unit)
end if
end if
gosub [/color][color=Black]display
[/color][color=Blue]return[/color]
Code:
#function inc_sens_width_unit
uwidth = uwidth + 1
if uwidth > 300 then
uwidth = uwidth - 1
endif
Code:
' #function inc_sens_width_unit
' uwidth = uwidth + 1
' ;; SELECTA, 23
' ;; FADDI, 1
' if uwidth > 300 then
' ;; LOADWORD, 300
' ;; FCMP2, 23, 0
' ;; PJMP, LE, __3
' uwidth = uwidth - 1
' ;; SELECTA, 23
' ;; FSUBI, 1
' endif
' ;;__3: