some help with math


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 65
  1. #1
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838

    Default some help with math

    Hi guys i need to make this table of value in code
    Code:
    count		byte code	end value 
    1	-1	0	         0
    2		1              	42
    3		2	        84
    4		3	       126
    5		4	       168
    6		5	       210
    7	-7	0	       0
    8		1             42
    9		2	      84
    10		3	     126
    11		4	     168
    12		5	     210
    13	-13	0	     0
    14		1	     42
    15		2	     84
    16		3	    126
    17		4	    168
    18		5	    210
    19	-19	0	    0
    20		1	   42
    21		2	   84
    22		3	   126
    23		4	   168
    24		5	   210
    25	-25	0	   0
    26		1	  42
    27		2	   84
    28		3	  126
    29		4	  168
    30		5	  210
    code attempt
    Code:
     Data_Length = 42                                  ' 38chrs + 4 byte setting  - required varable for spi flash routine 
            SDC_Page = 129 + (Menu_Subtxt-1)/6                ' page start point + 1 page per each 6 subtxt placed
            IF Menu_subtxt-1 //6 = 0 THEN 
                 SDC_Byte = 0    
            ELSE   
                 SDC_Byte = (Menu_Subtxt-1)+6 *6 + (Menu_Subtxt-1)-6 *6 /6 * Data_Length         ' byte start point per data length
                 
            ENDIF

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    count in the table is Menu_subtxt varable
    end code in the table is the value of SDC_Byte
    byte code in table the intrum caculation prior to mulitply data length

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,519


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    Try
    Code:
    EndValue = ((Count - 1) // 6) * 42
    Is that what you want?

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    OMG - gee i been playing with hours and i have variations of this same code but it did not work , THANKYOU hendrick , sometime you cant see the wood for the trees

  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

    end code
    - it is used to put 42 bytes into flash per page of 256 bytes of data

    Code:
    Data_Length = 42                                  ' 38chrs + 4 byte setting  - required varable for spi flash routine 
            SDC_Page = 129 + (Menu_Subtxt-1)/6                ' page start point + 1 page per each 6 subtxt placed
            IF Menu_subtxt-1 //6 = 0 THEN 
               SDC_Byte = 0                                   ' set byte to 0 when  Menu_subtxt = 7, 13, 19etc 
            ELSE   
               SDC_Byte = ((Menu_Subtxt-1)//6) * Data_Length  ' byte start point per data length
            ENDIF
            
            HSEROUT ["write SDC_Page = ",dec SDC_Page ,", SDC_Byte = ",dec SDC_Byte,13,10 ] 
            gosub Flash_Font_Common_write                     ' use flash font common write to save subtxt data                 
    
    return

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    Hi,
    I don't think you need the IF/ELSE/ENDIF block in there. SDC_Byte = ((Menu_Subtxt-1)//6) * Data_Length should work fine even when Menu_Subtxt - 1 equals 0.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    yes your correct hendrick have removed the if/else statements

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    i think what threw me in my thinking hendrick was that the math command of "//" remainder (modulus) in that i have only ever used it to test for the remainder value of 0 or 1 being true /false in a if statement , not to use the remainder value directly

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    and the maths eqivalant of this

    lookup gl_i,[24,32,40,24,32,40,24,32,40,24,32,40],gl_y ' menu row lines 8,24,32,40 for gl_y

    gl_y = 24+ (gl_i//3 *8) ????

  10. #10
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,519


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    Hi,
    Have you tried it, doesn't it work?
    Looks alright to me at first glance.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    no not tried it just looked wrong

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    it appears to work , i have about 10 of these lookups , looking to save space

  13. #13
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    Better?
    Code:
    gl_y = 24+((gl_i//3)*8)
    Don’t know if you get screwed over for gl_i less than 3 though.
    I’d expect PBP gives you zero modulus for a value less than 1.
    Last edited by Art; - 8th September 2015 at 19:57.

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    gives 0 when less then 3

  15. #15
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    If you have to check for <3 as well you might be approaching the code size of the lookup table.
    Are all the lookup tables repeating like this? It’s the sort of problem I like,
    certianly a mind F* though.

  16. #16
    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

  17. #17
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    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 ...........

  18. #18
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    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

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


    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 ...........
    umm no i did not i am very new to using pokecode and peekcode , i am just trying it out now , and using darrel getaddress built into the INTs18.inc to get the the address in mem or where its put the label

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    looking at a hex dump noticed that pokecode stores a byte as a word value in the flash , this is real waist of space , can i store the data as a word and then get it back as a byte or if needed a word if so how , this must have been done a lot before

  21. #21
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    Hey Longpole001, you asked this:

    and this i cant find a better way to do to reduce its compile size

    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

    Why not use the PBP command "DCD for the lookup table problem like this:

    Value = DCD Value

    When you come into the statement value will be a number between 0 and something less than 31, DCD will give it a value based on the bit position which is what you are doing with the lookup command. a value of 0 = 1, a value of 1 = 2, a value of 2 = 4 and so on. At lease that's how I would do it...
    Dave Purola,
    N8NTA
    EN82fn

  22. #22
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    You might also explore the use of MAX and MIN for setting bounds in situations like:

    if Event1_OT_Hour >23 then Event1_OT_Hour = 23
    or
    if Event1_OT_Hour <1 then Event1_OT_Hour = 0
    Last edited by Amoque; - 10th September 2015 at 13:27. Reason: Sorry, missed Richard's post above.

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    Event1_OT_Hour=Event1_OT_Hour min 23
    yes have a done this - saved some space there - thanks

  24. #24
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    can i store the data as a word and then get it back as a byte or if needed a word if so how
    http://www.picbasic.co.uk/forum/showthread.php?t=19949

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    thanks richard
    i am using darrels hi and low interupts services

  26. #26
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    If it’s bigger now, it won’t be if you put all of them in the same big array and skip to each group
    with an outer loop around that.

    Code:
    Event_OT var byte[8] ‘ or however many there are
    
    Event_OT_Day var Event_OT[0] ‘create alias to keep those names used elsewhere
    Event_OT_AllThoseOtherThings var Event_OT[1] ‘create alias
    …
    …
    
    index var byte ‘ this is re-useable for all of them
    
    if Event1_OT[0] >7 then 
    for index = 0 to 4
    Event_OT[index] = 0
    next index
    ENDIF

    You could check it isn’t cheaper to check for 0.
    It might not be now, but an earlier PBP, it would be cheaper.
    Code:
    'if Event_Penalty_Sec <1
    if Event_Penalty_Sec =0
    if your program uses the watchdog timer, there will be some buried in all of that.
    Code:
    DEFINE NO_CLRWDT
    You should get away with only one for that entire slab,
    and sprinkle any others only where needed
    Code:
    @ clrwdt
    definitely if there are any nops in code they can be replaced with them.
    Last edited by Art; - 11th September 2015 at 20:42.

  27. #27
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    this:
    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
    this should work instead (directly replaced) :


    Code:
    thingyousubtract var byte ‘ new variable
    
    
       if val < 6 AND Menu_Select = 211 then 
                thingyousubtract = 0 : gosub memorysavelookup      '  reasign  val to 
                gosub Show_current_sel_2   ' place "*    *" on the selected channel
             endif 
             if val =>6  and val <= 11 and Menu_Select = 2112 then 
                thingyousubtract = 6 : gosub memorysavelookup 
                gosub Show_current_sel_2 
             endif
             if val =>12 and Menu_Select = 2113 then
                thingyousubtract = 12 : gosub memorysavelookup 
                gosub Show_current_sel_2
            endif
    
    
    memorysavelookup:
    lookup val-thingyousubtract,[1,2,4,8,16,32],val
    return
    and if that still works, you might as well:

    Code:
    thingyousubtract var byte ‘ new variable
    
       if val < 6 AND Menu_Select = 211 then 
                thingyousubtract = 0 : gosub memorysavelookup      '  reasign  val to 
             endif 
             if val =>6  and val <= 11 and Menu_Select = 2112 then 
                thingyousubtract = 6 : gosub memorysavelookup 
             endif
             if val =>12 and Menu_Select = 2113 then
                thingyousubtract = 12 : gosub memorysavelookup 
            endif
    
    memorysavelookup:
    lookup val-thingyousubtract,[1,2,4,8,16,32],val
    gosub Show_current_sel_2
    return
    then if it still works, you should be able to:

    Code:
    memorysavelookup:
    lookup val-thingyousubtract,[1,2,4,8,16,32],val
    goto Show_current_sel_2
    Now this is still assuming I haven’t broken it yet, you can:

    Code:
    thingyousubtract var byte ‘ new variable
    thingyousubtract = 0
    
       if val < 6 AND Menu_Select = 211 then 
             gosub memorysavelookup
             endif 
             if val =>6  and val <= 11 and Menu_Select = 2112 then 
             gosub memorysavelookup 
             endif
             if val =>12 and Menu_Select = 2113 then
             gosub memorysavelookup 
            endif
    
    memorysavelookup:
    lookup val-thingyousubtract,[1,2,4,8,16,32],val
    thingyousubtract = thingyousubtract + 6
    goto Show_current_sel_2
    Last edited by Art; - 11th September 2015 at 20:56.

  28. #28
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    But wait there’s more!
    If you call within the next 20 minutes I’ll also throw in this rotating bit
    (but also found I broke it and got to steal some memory back)

    Code:
    thingyousubtract var byte ‘ new variable
    thingyousubtract = 0
    
       if val < 6 AND Menu_Select = 211 then 
       thingyousubtract = 0 : gosub memorysaverotate
       endif 
       if val =>6  and val <= 11 and Menu_Select = 2112 then 
       thingyousubtract = 6 : gosub memorysaverotate 
       endif
       if val =>12 and Menu_Select = 2113 then
       thingyousubtract = 12 : gosub memorysaverotate 
       endif
    
    memorysaverotate:
    val = 1<<(val-thingyousubtract)
    goto Show_current_sel_2
    Last edited by Art; - 11th September 2015 at 21:29.

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    thanks art that works well
    i used an exiting variable for the temp one

    i also did multi if /then statements , which reduced the compile further - those "and " do add up in compile

    i have not seen the command ":" to allow you to put on the same line before btw

    here what works

    cheers

    Sheldon

    Code:
     Show_RF_CH_Select:
     
             gl_y = 8                                           ' show current channel in use on menu heading line  - gl_y = 8  , gl_x= 162,168 
             gl_x= 160                                             
             read $09,val                                       ' get channel ref 
             g_num = val   
             if g_num dig 1 = 0  then                           ' leading 0 supression 
                 gosub put_1dig
                 gl_x = gl_x +6 
                 g_char = " "       ' clear 2nd digit space, case it was used 
                 gosub put_char 
             else
                 gosub put_2dig 
             endif                     
            g_num = 0                                 ' use as temp verable 
             if val < 6 then                          ' if current RF ch = 0-5
                if Menu_Select = 211 then             ' and menu 211
                  g_num = 0                           ' value offset for ch
                  gosub Show_RF_CH_Select_common      ' show  *     * on the selected ch
                endif
             endif    
                                                     
             if val =>6 then                           ' if current RF ch = 6-11
                 if val <= 11 then                     
                   if Menu_Select = 2112 then          ' and on menu 2112
                      g_num = 6                        ' value offset for ch 
                      gosub Show_RF_CH_Select_common
                   endif
                 endif
             endif     
             if val =>12 then                           ' if current RF ch = 6-11
               if Menu_Select = 2113 then           
                   g_num = 12                           ' value offset for ch
                   gosub Show_RF_CH_Select_common       ' show  *     * on the selected ch
               endif
             endif   
     return
     '------------------------------
     Show_RF_CH_Select_common:
        val = 1<<(val-g_num)      ' val = shift right 1 of VAL- Offset RF menu to get   1,2,4,8,16,32 in bit pattern
        gosub Show_current_sel_2  ' show "*   * on selected menu / ch using the bit pattern of VAL 
     return

  30. #30
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    I’m glad if it saved some memory... I made a bigger post but it looks to have disappeared.

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    yes i am the point that every bit really counts even a large change to get a small result has its merits

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    if i do write data to the flash mem using the the write table asm , how do reserve the space so the compiler does not use it , write all over the top of it

  33. #33
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    13 words

    Code:
    g_num var byte 
        g_num = 10   
             if g_num <10  then                           ' leading 0 supression 
                 gosub d1
                 
             else
                 gosub d2
             endif                     
     d1:
     return
     d2:
     return

    84 words
    Code:
    g_num var byte 
        g_num = 10   
             if g_num dig 1 =0 then                           ' leading 0 supression 
                 gosub d1
                 
             else
                 gosub d2
             endif                     
     d1:
     return
     d2:
     return

    if i do write data to the flash mem using the the write table asm , how do reserve the space so the compiler does not use it , write all over the top of it

    do u mean with TBLWT OR DT

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    thanks richard that little change got back 600 byte over all

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    in relation to using the peek/poke code routine i have is to put font tables into cpu flash , but that uses 2 times the space in flash than what is need for the data alone as it takes it sotres a command + data byte

    i would like to use the same arrangment from @getaddress which is incorporated in to darrel's int-18 routines
    but not store the instruction as the pokecode does

    Code:
    LG_Font_Base:
              ' Note gl_x char space need be 12 , not normal 24 when using chr else too big a gap space _
              ' Code for "-"  Asci 45   : note -gl_i(0) is ASCI CHR CODE , 90 real values _
    pokecode $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_    
                 $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$3F,$FC,$00,$3F,$FC,$00,$3F,$FC,_   
                 $00,$3F,$FC,$00,$3F,$FC,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,_
                 $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00

    Code:
    
    '=================== FONT COMMON ROUTINE - pokecode use ========================== 
    ' Assumes gl_x, gl_y,X_scan,Y_scan,Font_lookup   
    ' ALL FONTS MUST BE gl_x = 8 , 16 , 24 etc 
    ' Inv_font = 0 = normal 1= inverse   
     Font_Common: 
       x_save = gl_x                ' save the gl_x start point value 
       y_save = gl_y                ' save the gl_y start point value
       gl_yb  = y_save + Y_scan     ' number of y scans for the char from y starting point(0) 
       gl_xb  = 0 
       Address = 0 
       if Font_lookup = 1  then 
    @ GetAddress _LG_Font_Base, _Font_Base_Address                 ; gets base start address of LG_font into  Font_Base_Address varable 
          Font_Index = (LG_font - 45)* (90*2)                       ' remove the ascii chr value 45 offset  0 * font chr length x 2 cos of RETLW INSTRUCTION for each byte read  in index 
       endif
            
       if Font_lookup = 2  then                                    ' remove the offset of the first symbol $2D / 45  so start at 0 
    @ GetAddress _Med_Font_Base, _Font_Base_Address
            Font_Index = (Med_font - 45)* (40*2)                   ' remove the ascii chr value 45 offset * font chr length in index
       endif                                        
       Address = Font_Base_Address + Font_Index                    'gets you to the start of the glyph
     
       for gl_y = y_save to gl_yb      ' y scan lines, start to finish values
           gl_x = x_save               ' clear x position to start point (keep it an 8bit multiple)
           gosub gl_gaddr              ' Set address
           
          for gl_xb = 1 to X_scan        ' gl_x byte x  X scan bytes on each line
              peekcode Address,gl_byte   ' read the indexed byte in
              glcd_msb = gl_byte         
              glcd_cmd = DATA_WR_INC     ' write and increment
              gosub send_1               ' send to glcd
              Address = Address+2        ' inc address here +2 cos each byte includes , as data start at 0 not 1 as per lookup tables previously  
          next gl_xb                     ' next byte of font
       next gl_y                       ' next scan line of font
       gl_y = y_save                   ' Restore the Y location    
       gl_x = x_save                   ' Restore the X location
     return

  36. #36
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    Code:
    LG_Font_Base:
      
    @ db      0x00,0x00,...................................
    16 bytes to a line is good

    good
    Code:
    @ GetAddress _LG_Font_Base, _Font_Base_Address
    note 64k address limit


    Code:
    @ GetAddress _Med_Font_Base, _Font_Base_Address ;note  64k address limit
            Font_Index = (Med_font - 45)* (40*2)                   ' remove the ascii chr value 45 offset * font chr length in index
       endif                                        
       Address = Font_Base_Address + Font_Index                    'gets you to the start of the glyph
     
       for gl_y = y_save to gl_yb      ' y scan lines, start to finish values
           gl_x = x_save               ' clear x position to start point (keep it an 8bit multiple)
           gosub gl_gaddr              ' Set address
           
          for gl_xb = 1 to X_scan        ' gl_x byte x  X scan bytes on each line
              readcode Address,gl_byte   ' read the indexed byte in   ;note  64k address limit for readcode
              glcd_msb = gl_byte         
              glcd_cmd = DATA_WR_INC     ' write and increment
              gosub send_1               ' send to glcd
              Address = Address+1        ' inc address here +2 cos each byte includes , as data start at 0 not 1 as per lookup tables previously  
          next gl_xb                     ' next byte of font
       next gl_y                       ' next scan line of font

    look at my tft font and tft-spi.pbpmod (gcga: subroutine)

    there are other ways to get around the 64k limitation in that code too

  37. #37
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    What am I missing here?
    PBP integer math, if something is less than 1 is another way to check if it’s zero.
    and should be able to be deleted without any consequence.
    ie.. if something = 0 then something = 0.

    Code:
     if Event2_OT_Min <1        then Event2_OT_Min     = 0

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    yes that was stuff up - it was to stop it going passed a 0 value when a key was pushed and it never worked cos it was checked after the key had removed the value, so then value was the max value and so it never worked
    so it was changed in the key routines to

    if key = x then
    if value <> 0 then value = value - 1
    endif

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    the problem i am having with the @ db 0x?? , 0x?? is it takes the 1st byte as the low byte , the next as the high byte , so the data is out of sequance when stored into the flash

    is there away to reverce the seqaunce ( eg high byte 1st , lowbyte 2nd m etc , without changing the font data

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


    Did you find this post helpful? Yes | No

    Default Re: some help with math

    or i guess readcode can reads in a word value and i swap it in the routine some how

Similar Threads

  1. Help with A/D math!
    By dbodenheimer in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 19th March 2011, 00:51
  2. Math help please...
    By Ioannis in forum General
    Replies: 2
    Last Post: - 20th June 2008, 10: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, 10:22
  4. Math help please!!!
    By jbirnsch in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 10th August 2007, 14:45
  5. math help
    By houa in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 30th January 2006, 16:58

Members who have read this thread : 1

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