Okay, here's how it can be done.
Assuming the following to make it easier to explain:
- You are using a BBC Master
- The program is loaded into SW RAM bank 4
- The program only uses the first half of the ROM (&8000-&8FFF)
- leaving the second half of the ROM (&9000-&9FFF) free for data
Lets say you have some data, two numbers and a string up to 20 characters. Each number uses 4 bytes so that makes a total size of 28 bytes. First, we create the data in a buffer in main memory (I'm using the tape buffer at &A00 here as an example):
Code:
buffer=&A00
buffer!0=123
buffer!4=456
$(buffer+8)="Example"
Next, to store it away, we copy this memory to SW RAM bank 4 at a free location. The command to do this is
*SRWRITE <start> +<length> <sram-start> <sram-bank>
which can be done in a program like this:
Code:
SWRbank=4
SWRdata=&9000
size=28
OSCLI "SRWRITE "+STR$~buffer+" +"+STR$~size+" "+STR$~SWRdata+" "+STR$SWRbank
This will write 'size' bytes of data from the buffer to the SW RAM data area.
To read the information back, just reverse the process. First copy the data from SW RAM to the buffer:
Code:
size=28
OSCLI "SRREAD "+STR$~buffer+" +"+STR$~size+" "+STR$~SWRdata+" "+STR$SWRbank
Then you can access the data from the buffer with the indirection operators:
Code:
PRINT buffer!0
PRINT buffer!4
PRINT $(buffer+8)
To make things easier you could create procedures to do the memory transfer:
Code:
DEFPROCSWRaccess(mode$,buffer,size,SWRaddr)
OSCLI "SR"+mode$+" "+STR$~buffer+" +"+STR$~size+" "+STR$~SWRaddr+" "+STR$SWRbank
ENDPROC
DEFPROCSWRwrite(buffer,size,SWRaddr)
PROCSWRaccess("WRITE",buffer,size,SWRaddr)
ENDPROC
DEFPROCSWRread(buffer,size,SWRaddr)
PROCSWRaccess("READ",buffer,size,SWRaddr)
ENDPROC
Then you can just do something like:
Code:
PROCSWRread(buffer,50,SWRdata+100)
to read 50 bytes from the 100th position in the SW RAM data. A similar PROCSWRwrite call would write it back again.
Using the tape buffer allows you to work on up to 256 bytes at a time. If you need a larger buffer it will have to be allocated from BASIC memory, e.g:
DIM buffer 1000