Array storage in RAM

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Array storage in RAM

Post by FFMan »

Trying to work out an elegant way to shift my data one bit at a time to create a smooth scroll on my matrix display and I wondered if i could use BitCopy like so:-

Code: Select all

		for byChr=1 to byMaxDisplays
			for byRow=1 to Ubound(byMsgBuf,2)
				inBufRam=MemAddress(byMsgBuf(byChr,byRow))
				inTmpRam=MemAddress(byMsgTmp(byChr,byRow))
	
				Call BitCopy(inTmpRam,0,inBufRam,inScrollStep,32)
			next
		next
byMsgBuf(50,8 ) - storage of the required message bit patterns, 8 rows

byMsgTmp(4,8 ) - display buffer, 1 column per physical display (4) times number of rows.

the intention being to move the bits required into the displaybuffer but this relies upon my assumption that in ram an array is stored sequentially in column order. The code isn't producing the desired effect and i wonder if the ram storage order in not what I think
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Array storage in RAM

Post by dkinzer »

FFMan wrote:i wonder if the ram storage order in not what I think
Two dimensional RAM arrays are arranged in memory sequentially with the leftmost index varying the fastest. This is documented in the ZBasic Language Reference Manual:
http://www.zbasic.net/doc/ZBasicRef.php?page=90

You can verify that this is so using a simple test program like the one below. It superimposes a one dimensional array on top of a two dimensional array, initializes one and displays from the other.

Code: Select all

Dim a(1 to 4, 1 to 4) as Byte
Dim b(1 to 16) as Byte Based a.DataAddress

Sub Main()
    Dim i as Integer, j as Integer
    Dim bval as Byte

    bval = 1
    For i = 1 to 4
        For j = 1 to 4
            a(j, i) = bval
            bval = bval + 1
        Next j
    Next i

    For i = 1 to 16
        Debug.Print b(i); " ";
    Next i
    Debug.Print
End Sub
- Don Kinzer
Post Reply