PDA

View Full Version : Shift starting position for ARRAYWRITE?



CuriousOne
- 11th August 2022, 06:20
Hello.

Say I have some array, with say, 32 byte length.
I want to write a text string "Hello world!" starting from position, 20
How should I?
I know that I can break the text apart and write each letter to each address individually, but that's not practical.

Ioannis
- 11th August 2022, 09:24
From the manual:

7.6.3 Sub-Arrays within Arrays

Consider the following variable declarations:

all_data VAR BYTE[48] ' Array for all my data
samples VAR all_data[0] ' 16 bytes for ADC samples
calcs VAR all_data[16] ' 16 bytes for calculated values
readings VAR all_data[32] ' 16 bytes for port readings

Ioannis

CuriousOne
- 11th August 2022, 13:19
And how that going to help?
I want to change that offset runtime...

mpgmike
- 11th August 2022, 16:39
If you know the offset is 20, give that byte a name as Ioannis suggested. This will act as a place marker for your start point. You can also use a variable start point:


CondVar = inputVal
TXREG = all_data[20+CondVar]

HenrikOlsson
- 11th August 2022, 19:30
There's no way to do that directly using ARRAYWRITE (perhaps there is, by preloading system variables, but I'm not going to research that). But if you have some RAM to spare you can:


ActualArray VAR BYTE[32]
TempArray VAR BYTE[16]
Start VAR BYTE
idx VAR BYTE


Main:
ArrayWrite TempArray,["Hello World!", 0] ' What you want written, note the null at the end = important!
Start = 10 ' Where you want it written in the main array, make sure to not go out of bounds.
GOSUB WriteArray
END

WriteArray:
idx = 0
WHILE TempArray[idx] <> 0
ActualArray[Start + idx] = TempArray[idx]
idx = idx + 1
WEND
RETURN

CuriousOne
- 11th August 2022, 19:59
Well the situation is as follows, I have an array, which is used as a display buffer - separate routine reads data from it, decodes and sends to display.
I want to do some text scrolling, so want to write same line of text into that array, with some offset, to create the scroll effect.
9262

HenrikOlsson
- 11th August 2022, 21:45
And I belive what I showed can be made to do that - not that it neccesarily is the best way to achieve your end result but never the less :-)

Instead of "write same line of text into that array, with some offset" modify the actual display routine so that it doesn't start displaying from index 0 of the screen buffer.

CuriousOne
- 12th August 2022, 05:29
Yes that is what I planned.
To make display buffer 24 byte wide, instead of 8, and "read" it with changing offset, to achieve the scrolling effect. But this means that text data should be written into "center" of array - from 8th position to 16th.