Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to pack and unpack a string?
#4
I used unpacking [search for megaLZ] in the tutorial here: <!-- m --><a class="postlink" href="https://docs.google.com/document/d/1vUneCCC18oXLglzoRcJdrMDUSh7vaO_tGDjzjOc8IhU/edit">https://docs.google.com/document/d/1vUn ... c8IhU/edit</a><!-- m -->

Though it's not strings specifically.

To pack:
Write the text into a file, and use the windows based packer to make a compressed data lump. You can then #include that data lump in your code in asm context.


I don't think you can unpack text to a string space and use it like a string, so you're going to have to have a spot of memory to unpack these to. You can either use the malloc function to make one, or DIM a space, and use @variable to access the memory address. Make sure it's a big enough buffer to allow the largest piece of text into, so you don't overwrite anything after it. (Buffer overrun problems are notorious).

Then you'd need to write a function to print each character at that address. It's basically a for/next loop increasing the address and printing chr$(peek address) to the screen. The easiest way to do it is to have a unique terminator character - such as a 0 or 255 byte, at the end, and detect that so you know to stop printing and exit your loop. Then you don't need to know the unpacked length of each string, which is probably a size saving over the alternative, which would be to put bytes representing the size of the text at the start of each text block.

Don't forget to put in labels for each block so you can find them. Maybe you can put those labels into an array?
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)