Example

PEEK and POKE for pascal string

4

moechofe 2019-07-25 14:58 (Edited)

Two subprogams pokeps() and peekps() allow to store/retrieve a string from an array to memory.

The pascal string came from the pascal language where the length of a string were stored just before the characters list that contains it.

Because calling subprograms with lowresnx do not return, have to pass an array element. They are always passed as reference.

The code:

SUB POKEPS(A,S$)
L=MIN(255,LEN(S$))
POKE A,L
FOR I=1 TO L
POKE A+I,ASC(MID$(S$,I,1))
NEXT I
END SUB

SUB PEEKPS(A,S$)
L=PEEK(A)
S$=""
FOR I=1 TO L
S$=S$+CHR$(PEEK(A+I))
NEXT I
END SUB

The test:

DIM I$(0),O$(0)
I$(0)="TEST 123"
a=$a123
CALL POKEPS(a,I$(0))
CALL PEEKPS(a,O$(0))
PRINT I$(0)
PRINT O$(0)


Timo 2019-07-25 17:48

Simple variables should be passed by reference too, no need for arrays.
Anyway, nice!


was8bit 2019-07-25 19:39

Very nice :)


moechofe 2019-07-26 04:35

Oh yes, I didn’t realize that, as it was not logic for my mind.


Timo 2019-07-26 11:36 (Edited)

This is BASIC, not LOGIC ;)
Not my idea by the way, it’s Microsoft’s fault.


moechofe 2019-07-26 13:19

Well, it's a good feature.


Log in to reply.