some help with math


Closed Thread
Results 1 to 40 of 65

Hybrid View

  1. #1
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    well i been going though my code and i had about 35 lookup tables in various values and size , most have been changed now to math calculation , most were of simular in how they need to place font, chrs , on a glcd within menus
    the goal is to reduce code size as lookups really do chew up space

    this along with change any IF /then to a math caclulation where possible
    removing any multi if /then when used to compare to for/next loop compare

    moving bit varables into the same byte to use bit matching on them
    remove any "and " in if/then and just doing 2 if/then statements - this often saved about 50 bytes each
    moving any lookup "txt into spi flash so it not on the main cpu flash

    all these saved so far a total of 33k from a code that started at 127k
    still trying more space as i really would like to get to 90k code before i add the next section

    found pokecode has a limit of 256 bytes before for adata string ,

    and this i cant find a better way to do to reduce its compile size
    Code:
       if val < 6 AND Menu_Select = 211 then 
                lookup val,[1,2,4,8,16,32],val      '  reasign  val to 
                gosub Show_current_sel_2            ' place "*    *" on the selected channel in menu using bit pattern sleection 
             endif 
             
             if val =>6  and val <= 11 and Menu_Select = 2112 then 
                lookup val-6,[1,2,4,8,16,32],val 
                gosub Show_current_sel_2 
             endif
             if val =>12 and Menu_Select = 2113 then
                lookup val-12,[1,2,4,8,16,32],val 
                gosub Show_current_sel_2
            endif



    i am also ll stuck with a lot of if then statements when input range checks are done when a key is pressed such as
    and i cant see away to reduce them
    Code:
     Input_Timevalue_Check:
      ' input checks for time inputs from menu1111  
        if Event1_OT_Day >7 then 
           Event1_OT_Day     = 0
           Event1_OT_hour    = 0
           Event1_OT_Min     = 0
           Event1_OT_sec     = 0
           Event1_OT_100th   = 0
           ENDIF
        
        if Countdwn_Day > 7 then
           Countdwn_Day      = 0   ' day settings 
           Countdwn_Hour     = 0
           Countdwn_Min      = 0
           Countdwn_Sec      = 0
           Countdwn_100th    = 0
           ENDIF
           
        if Event_Penalty_Day >7 then 
           Event_Penalty_Day   = 0
           Event_Penalty_Hour  = 0 
           Event_Penalty_Min   = 0
           Event_Penalty_Sec   = 0
           Event_Penalty_100th = 0
           ENDIF 
           
        if Event2_OT_Day >7  then 
           Event2_OT_Day     = 0
           Event2_OT_hour    = 0
           Event2_OT_Min     = 0
           Event2_OT_sec     = 0
           Event2_OT_100th   = 0
           ENDIF
           
        if Preset_EL0_Day >7 then 
           Preset_EL0_Day    = 0
           Preset_EL0_Hour   = 0
           Preset_EL0_Min    = 0
           Preset_EL0_Sec    = 0
           Preset_EL0_100th  = 0
           ENDIF
                                                                                            
        if Event1_OT_Hour >23      then Event1_OT_Hour     = 23
        if Countdwn_Hour  >23      then Countdwn_Hour      = 23
        if Event_Penalty_Hour > 23 then Event_Penalty_Hour = 23
        if Event2_OT_Hour > 23     then Event2_OT_Hour     = 23
        if Preset_EL0_Hour > 23    then Preset_EL0_Hour    = 23
        if Event1_OT_Hour <1       then Event1_OT_Hour     = 0 
        if Countdwn_Hour  <1       then Countdwn_Hour      = 0 
        if Event_Penalty_Hour <1   then Event_Penalty_Hour = 0 
        if Event2_OT_Hour  <1      then Event2_OT_Hour     = 0 
        if Preset_EL0_Hour <1      then Preset_EL0_Hour    = 0 
                                                                                                
        if Event1_OT_Min >59       then Event1_OT_Min     = 59 
        if Countdwn_Min > 59       then Countdwn_Min      = 59
        if Event_Penalty_Min > 59  then Event_Penalty_Min = 59
        if Event2_OT_Min >59       then Event2_OT_Min     = 59
        if Preset_EL0_Min >59      then Preset_EL0_Min    = 59
        if Event1_OT_Min <1        then Event1_OT_Min     = 0 
        if Countdwn_Min <1         then Countdwn_Min      = 0
        if Event_Penalty_Min <1    then Event_Penalty_Min = 0
        if Event2_OT_Min <1        then Event2_OT_Min     = 0
        if Preset_EL0_Min <1       then Preset_EL0_Min    = 0
       
        if Event1_OT_Sec >59       then Event1_OT_Sec     = 59
        if Countdwn_Sec >59        then Countdwn_Sec      = 59
        if Event_Penalty_Sec >59   then Event_Penalty_Sec = 59
        if Event2_OT_Sec > 59      then Event2_OT_Sec     = 59 
        if Preset_EL0_Sec > 59     then Preset_EL0_Sec    = 59
        if Event1_OT_Sec <1        then Event1_OT_Sec     = 0
        if Countdwn_Sec <1         then Countdwn_Sec      = 0
        if Event_Penalty_Sec <1    then Event_Penalty_Sec = 0
        if Event2_OT_Sec <1        then Event2_OT_Sec     = 0
        if Preset_EL0_Sec <1       then Preset_EL0_Sec    = 0
       
        if Event1_OT_100th > 99    then Event1_OT_100th     = 99        
        if Countdwn_100th > 99     then Countdwn_100th      = 99
        if Event_Penalty_100th >99 then Event_Penalty_100th = 99
        if Event2_OT_100th > 99    then Event2_OT_100th     = 99
        if Preset_EL0_100th > 99   then Preset_EL0_100th    = 99
        if Event1_OT_100th <1      then Event1_OT_100th     = 0      
        if Countdwn_100th <1       then Countdwn_100th      = 0
        if Event_Penalty_100th <1  then Event_Penalty_100th = 0
        if Event2_OT_100th <1      then Event2_OT_100th     = 0
        if Preset_EL0_100th <1     then Preset_EL0_100th    = 0
    
     return

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,705


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    I expect you realise that pokecode uses twice the memory to store a byte compared to @ db , @ data ...........

  3. #3
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    thats what i ended up doing art and swapped the lot arround , although pain in butt readcode is the best option for the fonts that are not loaded in the spi flash , fortunately there are only 30 font chrs like this

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,705


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    if Event1_OT_Hour >23 then Event1_OT_Hour = 23
    if Event1_OT_Hour <1 then Event1_OT_Hour = 0
    can be replaced by if Event1_OT_Hour is a byte

    Event1_OT_Hour=Event1_OT_Hour min 23
    saves heaps of typing if nothing else

  5. #5
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    has anyone a way to use 2 word value varables to accumulate an math value with out using longs or floating point

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    Hi,
    Depends on your particular needs, here's one way to be used when the value to be added fits within a WORD:
    Code:
    HW VAR WORD
    LW VAR WORD
    Temp VAR WORD
    AddValue VAR WORD
    
    Temp = LW    ' Copy low word
    
    LW = LW + AddValue
    
    IF LW < Temp THEN   ' Low word wrapped around
      HW = HW + 1
    ENDIF
    If the value to be added is always one then:
    Code:
    HW VAR WORD
    LW VAR WORD
    
    LW = LW + 1
    IF LW = 0 THEN    'Low word wrapped around.
       HW = HW + 1
    ENDIF
    /Henrik.

  7. #7
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    Why you don't try N-Bit_MATH?
    http://www.picbasic.co.uk/forum/show...2694#post82694
    I use this code to store result as string in array
    Code:
    'Convert 64Bit to string
        @  MOVE?CP  10, _Tmp64bit   ; copy a CONSTANT to a Pvar
        FOR i=19 TO 0 STEP -1
            @  MATH_DIV  _Int64Bit, _Tmp64bit, _Res64bit    ; Res = A / B;  Remainder in REG_Z
            ValueStr[i]=REG_Z+48
            @  MOVE?PP  _Res64bit, _Int64Bit                ; copy a Pvar to a Pvar
        NEXT i

Similar Threads

  1. Help with A/D math!
    By dbodenheimer in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 19th March 2011, 01:51
  2. Math help please...
    By Ioannis in forum General
    Replies: 2
    Last Post: - 20th June 2008, 11:18
  3. PBPL Math...new math takes more cycles...Always?
    By skimask in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th February 2008, 11:22
  4. Math help please!!!
    By jbirnsch in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 10th August 2007, 15:45
  5. math help
    By houa in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 30th January 2006, 17:58

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts