13 February 2021, 18:37 | #1 |
Registered User
Join Date: May 2017
Location: AmigaLand
Posts: 459
|
Saving an array to File
Hi,
I use BlitzBasic 2 on Amiga 500 KS1.3 I'd like to save an array rawb.B(x) to a file. Straight bytes from rawb(x) to file. I use to have the code but lost it and can't find it anywhere on web. So I seak for your help. Thanks |
14 February 2021, 03:09 | #2 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,186
|
In DOS.library there's a call called Write() that will do it but I don't know the Blitz BASIC handle to it.
|
14 February 2021, 15:29 | #3 |
Gets there in the end...
Join Date: Sep 2005
Location: Wales
Posts: 862
|
On Wormy I created a bank using InitBank and then Poked the values into it. Then used SaveBank to save it. Loading was the same but in reverse using Peek.
There may be a better way but that worked. |
14 February 2021, 15:46 | #4 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
|
Yep, savebank and loadbank will work fine, but if you already have the memory you want to save, you can save and load any memory range with WriteMem and ReadMem. Knowing the size of an array, you can save the entire block and read it back to the variables if you wished. It's not foolproof so you'd want to make absolutely sure you're giving it valid values, but it's quite straightforward.
The address of the start of an array is obtained using &arrayname(0), and the size is (number of elements + 1) * element size. If you're dealing in bytes, each element is 1 byte so an array set up with Dim arrayname(50) is size 51. Then, WriteMem(myFile, &arrayname(0), 51) should do the trick to save it to a file you're opened, and ReadMem will load it back in. Make sure you have the array set up before you load anything into it this way! |
14 February 2021, 16:37 | #5 |
Registered User
Join Date: May 2017
Location: AmigaLand
Posts: 459
|
@all : Thanks for your help mates.
I thought using Allocmem, copy array to allocmem's adress and then Writemem. But your bank method suits me better because faster and easier. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Creating an array gives me a Guru | Shatterhand | Coders. Blitz Basic | 14 | 13 August 2019 20:54 |
Problem saving ROM in config file with 3.6.1 | AlphaUMi | support.WinUAE | 8 | 21 March 2018 19:55 |
Blitz2: Pointer to array | idrougge | Coders. Blitz Basic | 3 | 26 March 2015 21:44 |
Where is my file saving too? Need to back it up | Kola | New to Emulation or Amiga scene | 19 | 20 December 2008 20:23 |
Saving the Amiga confiq file? | neil324 | project.MAGE | 2 | 06 October 2008 18:42 |
|
|