CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 TV_BASE_PIN = 12 ' Propeller Demo Board TV Out OBJ tv : "TV_Text" VAR word pokeAddress PUB MainEntry | index tv.start(TV_BASE_PIN) ' Use TV for reporting operation tv.str(String("Started ...",$D)) repeat index from 0 to 3 ' Use the traditional Case statement UsingCaseStatement(index) InitPokeAddress ' Determine the pokeAddress repeat index from 0 to 3 ' Use self-modifying code trickery tv.str(String("Poke ")) UsingSelfModifiedCode(index) repeat index from 0 to 3 tv.str(String("Poke ")) UsingSelfModifiedCode(index) repeat PRI UsingCaseStatement( index ) tv.str(String("Case ")) Case index 0 : Sub0 1 : Sub1 2 : Sub2 3 : Sub3 ' ***** BELOW MUST BE CONTIGUOUS ' ***** DO NOT ADD ANYTHING HERE ' ***** MUST BE SECOND AND THIRD "PUB" METHODS IN THE FILE ' ***** THAT IS, NO "PUB" BEFORE HERE EXCEPT THE MAIN "PUB" PUB UsingSelfModifiedCode( index ) byte [ pokeAddress ] := index + 4 Sub0 ' This will get updated by the above poke PUB InitPokeAddress InitPokeAddress_Main ' ***** ABOVE MUST BE CONTIGUOUS PRI InitPokeAddress_Main | sp tv.str(String("Init ")) result := $DEAD_C0DE sp := word[ $000A ] repeat sp += 4 tv.hex( long[sp] , 8 ) tv.out ( " ") until long[sp] == $DEAD_C0DE pokeAddress := ( long[sp-4] >> 16 ) - 5 tv.hex(pokeAddress,4) tv.out($D) PUB Sub0 tv.str(String("0 ")) PUB Sub1 tv.str(String("1 ")) PUB Sub2 tv.str(String("2 ")) PUB Sub3 tv.str(String("3",$D))