string in memory

Pagina 1/2
| 2

Door TheKid

Paragon (1108)

afbeelding van TheKid

18-02-2021, 23:11

Hi, I have a simple question (I guess).

I am programming in MSX-basic and I have a string variable TX$="example".
I want to 'give' this variable from one listing to another. With numbers I can use poke, and use peek in the next listing to read the variable, but how can I acchieve this for a string variable?

Aangemeld of registreer om reacties te plaatsen

Van Meits

Scribe (6335)

afbeelding van Meits

18-02-2021, 23:22

poke the chr$(x) ?

Van TheKid

Paragon (1108)

afbeelding van TheKid

19-02-2021, 00:06

yeah, but how? Or another way to get a string accross listings

Van Meits

Scribe (6335)

afbeelding van Meits

19-02-2021, 00:09

The x is a pokable number. Smile

Van TheKid

Paragon (1108)

afbeelding van TheKid

19-02-2021, 07:53

Okay, I hoped for a better way, but converting each string to character value and place them in a poke is doable, thanx.

Van ro

Scribe (4356)

afbeelding van ro

19-02-2021, 08:22

Funny, I did exactly that last evening. Trying to figure out how to put a string in memory in basic. Havent dun baisc for 30 years...
I could post the solution her if ye like.

Van theNestruo

Champion (274)

afbeelding van theNestruo

19-02-2021, 08:28

I'm not quite sure I've understood what are you trying to achieve... but VARPTR() may come handy:

10 DEFINTA-Y:DEFSTRZ:Z="HELLO, MSX!"
20 I=VARPTR(Z):NB=LEN(Z):NP=PEEK(I):?"Length:";NB;NP
30 ZA=RIGHT$("00"+HEX$(PEEK(I+2)),2)+RIGHT$("00"+HEX$(PEEK(I+1)),2):A=VAL("&H"+ZA):?"Address: &H";ZA;" ";A
40 B=A:E=B+NB-1:FORI=BTOE:C=PEEK(I):?"Char at &H";HEX$(I);": ";CHR$(C);C:NEXT

See it live: https://msxpen.com/codes/-MTtA_WMng0wnKfTYQQf

Van TheKid

Paragon (1108)

afbeelding van TheKid

19-02-2021, 09:20

What I want is simple.

In listing A i have a string tx$=“test”

In listing B i want to use tx$ With it’s value “test”

Van thegeps

Paladin (719)

afbeelding van thegeps

19-02-2021, 11:20

Not sure, but if you load a new listing probably variables (and varptr too) will be erased. So you have first to peek into varptr pos (offsetting until end of string) and poke values in a safe area (set it using CLEAR). Then load new listing and read (peek) from safe area. Not tested but it should work

Van Thom

Paladin (667)

afbeelding van Thom

19-02-2021, 15:53

Don't know if it fits into your code, but using sprite$(0)="test" and then in listing B tx$=sprite$(0) could work. The length of the string is limited though.

Van ray2day

Hero (632)

afbeelding van ray2day

19-02-2021, 16:26

Quote:

Not sure, but if you load a new listing probably variables (and varptr too) will be erased. So you have first to peek into varptr pos (offsetting until end of string) and poke values in a safe area (set it using CLEAR). Then load new listing and read (peek) from safe area. Not tested but it should work

I think this should be the right way to do it, Remy!
But what part of the memory will be the 'safe area'? (asking myself...)

Pagina 1/2
| 2