Author Topic: What's the best way to store data?  (Read 6203 times)

0 Members and 1 Guest are viewing this topic.

Offline ZippyDee

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 729
  • Rating: +83/-8
  • Why not zoidberg?
    • View Profile
What's the best way to store data?
« on: March 24, 2011, 02:41:40 am »
AXE/ASM noob here! :D

What's the ideal way to store large amounts of data (i.e. map data, sprites, large strings) for your programs? I'd expect that you'd just keep the data in your program, but is there a better way to do it?
Also, could I get some guidance on when to use temp ram areas/external variables rather than portions of program memory for data storage?

Any other data optimization tips would be greatly appreciated!

Thanks!
-Zippy Dee
There's something about Tuesday...


Pushpins 'n' stuff...


Offline Juju

  • Incredibly sexy mare
  • Coder Of Tomorrow
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 5730
  • Rating: +500/-19
  • Weird programmer
    • View Profile
    • juju2143's shed
Re: What's the best way to store data?
« Reply #1 on: March 24, 2011, 02:53:42 am »
Personally, in my Axeanoid program, there is 4 types of bricks (which are stored as 8x8 sprites at the beginning of the program) and the level is stored in an appvar. Said level is a tilemap, each type of brick is assigned a 4-bit number between 0x0 and 0xF. So in Axe, you would retrieve each brick using nib{} (instead of the normal {}) and do the correct conversion (displaying the correct sprite using the number from the tilemap). Useful if you have less than 16 sprites, it divides the size of your level by 2.

Remember the day the walrus started to fly...

I finally cleared my sig after 4 years you're happy now?
THEGAME
This signature is ridiculously large you've been warned.

The cute mare that used to be in my avatar is Yuki Kagayaki, you can follow her on Facebook and Tumblr.

Offline ZippyDee

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 729
  • Rating: +83/-8
  • Why not zoidberg?
    • View Profile
Re: What's the best way to store data?
« Reply #2 on: March 24, 2011, 03:59:44 am »
Yeah, that's a fairly straightforward compression technique, but if you have more than 15 of the same tile in a row, you have to break it up into multiple bytes, but that's still better than it would be without compression. Even so, how do you store the data as an appvar without it adding to the size of your program? Or does axe write to appvars when compiling?
There's something about Tuesday...


Pushpins 'n' stuff...


Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: What's the best way to store data?
« Reply #3 on: March 24, 2011, 10:44:37 am »
Also, could I get some guidance on when to use temp ram areas/external variables rather than portions of program memory for data storage?

There are certain chunks of memory in system RAM ($8000-$9D94) that programs can use for temporary storage:

  • appBackUpScreen - 768 bytes, perfectly safe (L3 in Axe; it's used for the back-buffer, so don't use it if you use grayscale in your game)
  • saveSScreen - 768 bytes, safe unless APD (auto-power-down) starts (L1 in Axe; last 54 bytes are used for A-Z and θ variables in Axe)
  • tempSwapArea - 323 bytes, safe unless you archive/unarchive a variable (L4 in Axe)
  • textShadow - 128 bytes, used to store the contents of the homescreen, so safe as long as you either:
    • not use the homescreen bcalls at all; or
    • run RES appTextSave,(IY+appFlags) before using any homescreen bcall
  • statVars - 531 bytes, not to be used if running from MirageOS or using statistics functions (L2 in Axe; do not use in Axe if custom interrupts are enabled, either)
  • plotSScreen - 768 bytes, safe if you don't draw any graphics, since this is used as the graph buffer (L6 in Axe)

There are more, but they get smaller (<100 bytes).

Generally, it's smaller to use scrap RAM for temporary variables, while constant data should be stored in the program itself.
« Last Edit: March 24, 2011, 10:45:07 am by Deep Thought »




Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: What's the best way to store data?
« Reply #4 on: March 24, 2011, 12:31:40 pm »
AXE/ASM noob here! :D

What's the ideal way to store large amounts of data (i.e. map data, sprites, large strings) for your programs? I'd expect that you'd just keep the data in your program, but is there a better way to do it?
Also, could I get some guidance on when to use temp ram areas/external variables rather than portions of program memory for data storage?

Any other data optimization tips would be greatly appreciated!

Thanks!
-Zippy Dee


You can use Appvars if you want them saved even when the program is closed.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: What's the best way to store data?
« Reply #5 on: March 24, 2011, 12:34:21 pm »
Don't use them if the data is required for the program to run, though (always have a backup to rely on in-prgm). Appvars are generally useful for saving high scores or external levels.




Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: What's the best way to store data?
« Reply #6 on: March 24, 2011, 12:35:02 pm »
Don't use them if the data is required for the program to run, though (always have a backup to rely on in-prgm). Appvars are generally useful for saving high scores or external levels.

Yes that's right, but they do allow moderately high amount of data.

SirCmpwn

  • Guest
Re: What's the best way to store data?
« Reply #7 on: March 24, 2011, 01:14:31 pm »
If you only have a limited amount of data (0-768 bytes), you could probably use safe ram.  Also, if you want it to be modified, you should use safe ram when possible.  Also, any space you reserve in your program adds to the overall size, and should be avoided.  Large amounts of data can also be compressed, but will most likely have to be decompressed as well.  If you have large amounts of data to manipulate, you can consider swapping in a spare RAM page for tens of thousands of bytes, like I do in Motherload.  However, this restricts you from using many OS routines, and interrupts must be disabled.  Another alternative that is much less common is creating a temporary appvar or program to store information in during the program's lifetime.  However, you aren't always guaranteed to have enough space.
As for compression, there are several ways.  Run length encoding is one popular and simple way.  There are many others.  Both memory usage and compression algorithms should be appropriately used to suit whatever your specific needs are.

Ashbad

  • Guest
Re: What's the best way to store data?
« Reply #8 on: March 24, 2011, 01:24:50 pm »
Don't use them if the data is required for the program to run, though (always have a backup to rely on in-prgm). Appvars are generally useful for saving high scores or external levels.

Yes that's right, but they do allow moderately high amount of data.

Actually, that's what I use in TaNF as a 3rd and 4th screen buffer zone, and it's actually quite helpful (and caused it to speed up by at least 30 FPS) -- but make sure you delete them, I'm sure people don't like to delete appvars called 'A' and 'B' after each runtime.

Offline ZippyDee

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 729
  • Rating: +83/-8
  • Why not zoidberg?
    • View Profile
Re: What's the best way to store data?
« Reply #9 on: March 25, 2011, 03:18:29 am »
How does one use an appvar? I've never done anything with apps or appvars, so I'm kinda new to all this :P
There's something about Tuesday...


Pushpins 'n' stuff...


SirCmpwn

  • Guest
Re: What's the best way to store data?
« Reply #10 on: March 25, 2011, 04:25:48 am »
In assembly, an appear is just a place to dump data.  Look at the WikiTI documentation for the bcalls ChkFindSym and CreateAppVar.

Offline ZippyDee

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 729
  • Rating: +83/-8
  • Why not zoidberg?
    • View Profile
Re: What's the best way to store data?
« Reply #11 on: March 25, 2011, 04:42:51 am »
Ah okay, thanks. What's the size limit for an appvar?
There's something about Tuesday...


Pushpins 'n' stuff...


SirCmpwn

  • Guest
Re: What's the best way to store data?
« Reply #12 on: March 25, 2011, 05:03:07 am »
However much RAM is available.  It can also be stored in Archive (Flash) memory, and take up however much is available.

Offline ZippyDee

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 729
  • Rating: +83/-8
  • Why not zoidberg?
    • View Profile
Re: What's the best way to store data?
« Reply #13 on: March 25, 2011, 05:08:39 am »
But when it's in Archive, wouldn't it only be accessible by an app and not by a regular asm program?
There's something about Tuesday...


Pushpins 'n' stuff...


SirCmpwn

  • Guest
Re: What's the best way to store data?
« Reply #14 on: March 25, 2011, 05:22:04 am »
No - accessible by both (though more difficult), and writable by neither (unless you move it to RAM or you're clever).