Shop OBEX P1 Docs P2 Docs Learn Events
How much DATA can be used in SX/B — Parallax Forums

How much DATA can be used in SX/B

Jim FouchJim Fouch Posts: 395
edited 2005-12-19 16:00 in General Discussion
I have a project that I need to send several packets of Bytes using DATA statements to store the packets. These packets contain a starting Byte that says how many bytes are in that packet, followed by the actual packet bytes. Here is are the packets I have to send...

DATA $05,$01,$42,$00,$00,$00
DATA $05,$01,$43,$00,$01,$00
DATA $09,$01,$45,$00,$5A,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$46,$00,$00,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$46,$00,$01,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$47,$00,$00,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$4C,$00,$00,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$4C,$00,$01,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$4D,$00,$FF,$FF,$FF,$FF,$FF,$FF
DATA $09,$01,$41,$00,$5A,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$43,$00,$00,$5A,$5A,$5A,$5A,$5A
DATA $05,$01,$42,$00,$00,$00
DATA $05,$01,$42,$00,$00,$00
DATA $05,$01,$42,$00,$00,$00
DATA $05,$01,$42,$00,$00,$00
DATA $05,$01,$43,$00,$01,$00
DATA $09,$01,$44,$00,$01,$03,$00,$00,$00,$00
DATA $09,$01,$43,$00,$00,$5A,$5A,$5A,$5A,$5A
DATA $05,$01,$42,$00,$00,$00
DATA $05,$01,$42,$00,$00,$00
DATA $09,$01,$43,$00,$01,$00,$00,$00,$00,$00
DATA $09,$01,$45,$00,$5A,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$46,$00,$00,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$46,$00,$01,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$47,$00,$00,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$4C,$00,$00,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$4C,$00,$01,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$4D,$00,$00,$01,$FF,$FF,$FF,$FF
DATA $09,$01,$41,$00,$5A,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$43,$00,$00,$5A,$5A,$5A,$5A,$5A
DATA $05,$01,$42,$00,$00,$00
DATA $09,$01,$42,$00,$00,$00,$00,$00,$00,$00
DATA $09,$01,$42,$00,$00,$00,$00,$00,$00,$00
DATA $09,$01,$42,$00,$00,$00,$00,$00,$00,$00
DATA $09,$01,$43,$00,$01,$00,$00,$00,$00,$00
DATA $09,$01,$44,$00,$01,$03,$00,$00,$00,$00
DATA $09,$01,$43,$00,$00,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$42,$00,$00,$00,$00,$00,$00,$00
DATA $09,$01,$42,$00,$00,$00,$00,$00,$00,$00
DATA $09,$01,$43,$00,$01,$00,$00,$00,$00,$00
DATA $09,$01,$4F,$00,$FF,$FF,$03,$00,$00,$00
DATA $09,$01,$40,$00,$00,$02,$00,$00,$00,$00
DATA $09,$01,$40,$00,$01,$02,$00,$00,$00,$00
DATA $09,$01,$40,$00,$02,$02,$00,$00,$00,$00
DATA $09,$01,$40,$00,$03,$02,$00,$00,$00,$00
DATA $09,$01,$40,$00,$04,$02,$00,$00,$00,$00
DATA $09,$01,$40,$00,$05,$02,$00,$00,$00,$00
DATA $09,$01,$40,$00,$06,$02,$00,$00,$00,$00
DATA $09,$01,$40,$00,$07,$02,$00,$00,$00,$00
DATA $09,$01,$40,$00,$08,$02,$00,$00,$00,$00
DATA $09,$01,$40,$00,$09,$02,$00,$00,$00,$00
DATA $09,$01,$40,$00,$0A,$02,$00,$00,$00,$00
DATA $09,$01,$40,$00,$0B,$02,$00,$00,$00,$00
DATA $09,$01,$43,$00,$00,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$42,$00,$00,$00,$00,$00,$00,$00
DATA $05,$01,$42,$00,$00,$00
DATA $15,$01,$43,$00,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DATA $09,$01,$45,$00,$5A,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$46,$00,$00,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$46,$00,$01,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$47,$00,$00,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$4C,$00,$00,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$4C,$00,$01,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$4D,$00,$00,$01,$FF,$FF,$FF,$FF
DATA $09,$01,$41,$00,$5A,$5A,$5A,$5A,$5A,$5A
DATA $09,$01,$43,$00,$00,$5A,$5A,$5A,$5A,$5A
DATA $05,$01,$42,$00,$00,$00
DATA $15,$01,$42,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DATA $15,$01,$42,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DATA $15,$01,$43,$00,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
DATA $09,$01,$4D,$00,$00,$01,$FF,$FF,$FF,$FF
DATA $09,$01,$43,$00,$00,$5A,$5A,$5A,$5A,$5A



I need to start at the first packet and move through each packet and process each one. My thought was to have a label before the first packet and use a counter index to keep track of which data packet I was on, however I know I have more than 255 data bytes. I'm going to have to break the total packets into 3-4 smaller groups.

I'm wondering if the SX28 will have enough memory. Also, will I have problems with overrunning page boundrys.

Jim

Comments

  • BeanBean Posts: 8,129
    edited 2005-12-14 18:21
    Jim,
    As of version 1.4 the READ command can use two variables (as base and offset) to read data from large tables.
    See the help file under "READ", the base and offset basically form a 16-bit pointer to the data being read.

    I didn't count all the bytes in the data lines, but they use program space. So you have 2K for data and program.

    [noparse][[/noparse]edit] Okay it looks like you have about 720 bytes of data, so that's going to use about 35% of your program space.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    Forget about the past, plan for the future, and live for today.


    Post Edited (Bean (Hitt Consulting)) : 12/14/2005 6:25:56 PM GMT
  • Jim FouchJim Fouch Posts: 395
    edited 2005-12-14 18:59
    I guess I can break it into segs that don't exceed 255 bytes. I can then do it in maybe 3 or 4 data blocks. In some cases, teh packets repeat. I'm thinking of making the first byte hold both the Number of Bytes in the packet and how many times to repeat the packet. I never have more than 21 bytes and a packet will never repeat more than 4 times.

    Thanks,

    Jim
  • BeanBean Posts: 8,129
    edited 2005-12-14 19:09
    Jim,
    Using "READ base+offset" you data block can be as large as you want.
    See the help file. When the offset "rolls-over" from 255 to zero you simple add 1 to the base.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    Forget about the past, plan for the future, and live for today.
    ·
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-12-14 20:16
    Am I correct that packet length including the length byte is either 6, 10 or 22 bytes long? If you eliminate duplicate packets can you get the total number of bytes to be less than 512 bytes? If this is the case you can use double indirection. This means you have a table of pointers seperate from the above defined table, this table would store the offset pointer to the beginning of the packet. I count 72 packets including the duplicates, so the offset pointer table would have 72 entries. The first entry would be $00, meaning it starts at the base address of your packet data. Now your packet lengths (including the length byte) is divisible by 2, so we can store the offset into your packet data as the offset/2, meaning we can accomodate 512 bytes total, not including the length of the last packet (since it is only pointing to the head of the packet). So with this divided by 2 offset the next entry in your offset table would be $03 ($06/2). So given this double indirection scheme, the plain word english algorithm would look something like this:

    Determine the packet number needed (Lets call this pnum)
    Read the pnum'th entry of the offset table (Lets call this offset)
    Shift offset to the left once (same as multiply by 2)
    If carry bit is set goto UpperHalf else
    · Read data at packet data base address + offset
    · Continue to process the data by incrementing the offset number until packet data is exhausted
    End of algorithm branch
    UpperHalf branch:
    · Read data at packet data base address + 256 + offset
    · Continue to process the data by incrementing the offset number until packet data is exhausted
    End of algorithm branch

    By using double indirection, you can eliminate duplicate packets. Since the first packet is the same as the 12th-15th packets, the 12th-15th entries in the offset table would also be $00 and 24 bytes will be saved, because it is processed as though that data was stored for each of the packets. This method is more robust than the run length encoded that you are thinking about because it removes all duplicate packets, not just the identical ones that are adjacent.

    This is a fairly advanced method of data encoding so dont be afraid to ask for clarification on anything you don't fully understand.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10

    Post Edited (Paul Baker) : 12/14/2005 8:29:24 PM GMT
  • Jim FouchJim Fouch Posts: 395
    edited 2005-12-14 20:49
    Paul,

    This is a great Idea!!! I'll give it a try. Thanks...

    Jim
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-12-14 21:01
    I also see another space saving solution, your data packets first data byte is always $01, also the 3rd data byte is always $00. You can eliminate these from your table as well and adjust your stored packet lengths to 4, 8 and 20. Then specifically code that whenever these two data bytes are to be fetched, the proper (but not stored) byte is generated. Doing this will reduce your total packet data by 144 bytes.

    Now get this, I just recalculated your packets using both double indirection (eliminating duplicate packets), and removing the two constant bytes, and guess what I calculate the total number of bytes are? 256! Here is the packet data table Ive made:

    DATA $03,$42,$00,$00
    DATA $03,$43,$01,$00
    DATA $07,$45,$5A,$5A,$5A,$5A,$5A,$5A
    DATA $07,$46,$00,$5A,$5A,$5A,$5A,$5A
    DATA $07,$46,$01,$5A,$5A,$5A,$5A,$5A
    DATA $07,$47,$00,$5A,$5A,$5A,$5A,$5A
    DATA $07,$4C,$00,$5A,$5A,$5A,$5A,$5A
    DATA $07,$4C,$01,$5A,$5A,$5A,$5A,$5A
    DATA $07,$4D,$FF,$FF,$FF,$FF,$FF,$FF
    DATA $07,$41,$5A,$5A,$5A,$5A,$5A,$5A
    DATA $07,$43,$00,$5A,$5A,$5A,$5A,$5A
    DATA $07,$44,$01,$03,$00,$00,$00,$00
    DATA $07,$43,$01,$00,$00,$00,$00,$00
    DATA $07,$4D,$00,$01,$FF,$FF,$FF,$FF
    DATA $07,$42,$00,$00,$00,$00,$00,$00
    DATA $07,$4F,$FF,$FF,$03,$00,$00,$00
    DATA $07,$40,$00,$02,$00,$00,$00,$00
    DATA $07,$40,$01,$02,$00,$00,$00,$00
    DATA $07,$40,$02,$02,$00,$00,$00,$00
    DATA $07,$40,$03,$02,$00,$00,$00,$00
    DATA $07,$40,$04,$02,$00,$00,$00,$00
    DATA $07,$40,$05,$02,$00,$00,$00,$00
    DATA $07,$40,$06,$02,$00,$00,$00,$00
    DATA $07,$40,$07,$02,$00,$00,$00,$00
    DATA $07,$40,$08,$02,$00,$00,$00,$00
    DATA $07,$40,$09,$02,$00,$00,$00,$00
    DATA $07,$40,$0A,$02,$00,$00,$00,$00
    DATA $07,$40,$0B,$02,$00,$00,$00,$00
    DATA $13,$43,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
    DATA $13,$42,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
    
    

    This means you dont need to do the divide by 2 trick to accomodate all of the table! The algorithm would look something like this:

    Determine the packet number needed (Lets call this pnum)
    Read the pnum'th entry of the offset table (Lets call this offset)
    Output $01 for the first packet data byte
    Read data at packet data base address + offset·and output
    Output $00 for the third packet data byte
    Increment offset
    Read data at packet data base address + offset and output
    Continue to process the data by incrementing the offset number until packet data is exhausted
    End of algorithm

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10

    Post Edited (Paul Baker) : 12/14/2005 9:04:47 PM GMT
  • Jim FouchJim Fouch Posts: 395
    edited 2005-12-15 12:41
    Paul,

    Your idea worked great. It's amazing the the talent on this forum!

    Strange how numbers work out. I was also amazed to see the Packet·data worked out to be 256 bytes.· LOL

    Jim
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-12-15 14:35
    Glad to hear it worked. Data structures are my forte, I find creating optimal data structures more fun than straight up programming.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10

    Post Edited (Paul Baker) : 12/15/2005 2:40:01 PM GMT
  • cbmeekscbmeeks Posts: 634
    edited 2005-12-19 16:00
    Paul Baker said...
    Glad to hear it worked. Data structures are my forte, I find creating optimal data structures more fun than straight up programming.

    And just as important.

    Great work Paul.

    -cbmeeks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://metroidclassic.com

    =========
    DMCA Sucks
    RIAA Sucks
Sign In or Register to comment.