• 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
Need help in memory manipulation

I want to write a game where I want to put all the resources into specific memory location (Fast RAM) and then stream them as I need them to the CHIP RAM. Ones I used or needed that information into CHIP RAM, I wish to remove them from the CHIP RAM then put them back into the Fast RAM. I have purchased ACA500 and I wish to put files into memory location in the ACA500 and I do not know how to do that. I would like to be able to specify the location in memory in Fast RAM where I can store everything I need and from that location in Fast RAM as I go by during game play stream it to CHIP RAM and back and forth between Fast RAM and CHIP RAM. How do I go about doing that?

Thanks in advance.
If you allocate memory and request any memory type, the OS will allocate to the highest priority memory automatically. This is normally your fastest RAM, so just allocate the memory you need with the type set to public. For Blitz commands, you can use

InitBank 1, 32768, 0

where 1 is the bank number for easy reference, 32768 is the number of bytes to allocate and 0 is the type of memory (0=any, 1=public, 2=chip). This memory should be in your fast RAM unless there isn't a large enough chunk free.

If you want to load a file directly into memory, you can use the LoadBank command. This automatically initialises the memory so you don't need the InitBank command above. Use it like this:

LoadBank 1, "Work:Myfile.dat", 0

Where 1 is the bank number, "Work:Myfile.dat" is the file you want to load into memory, and 0 is the memory type (any in this case).

After either of these commands, use the Bank() function to get the address of the bank.

MyAddr.l = Bank(1)

Where the 1 is the bank number used above. Be sure to check that MyAddr is >0, just in case it wasn't allocated for any reason. You *will* crash the machine if you try to use unallocated memory!

Once that's in place you can use the OS calls to copy memory between addresses as you need. The Copymem_(src.l,dest.l,size.l) call will copy size.l bytes from the src.l address to the dest.l address. Again, BE VERY CAREFUL to ensure you've properly allocated both source and destination memory or you will most likely crash!

The CopymemQuick_() call is similar but faster. The only difference is that you can only use long-aligned address and copy sizes.

Finally, free up all memory you allocate when your program ends. If you used InitBank, you can use FreeBank 1 to free it again.

Gehe zu:

Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste