Shop OBEX P1 Docs P2 Docs Learn Events
Can you add the peek/poke/addr family to the FlexBasic? — Parallax Forums

Can you add the peek/poke/addr family to the FlexBasic?

(1) I use it everywhere...
(2) ... because they are equivalents of Spin's byte[], word[], long[] and @...
(3) ... and they provide an easy access to P2's memory to interact with PASM drivers

Then, every 8-bit Basic has at least peek/poke (and several of them have also dpeek/dpoke)

I defined them and I keep them in a .bi file to include, but having them in the language itself will allow to get rid of this .bi

About addr and @.... The FlexBasic's @ returns a pointer while Spin's @ returns a long, as there is no such thing as a pointer in Spin. A "pointer type" @ is useful, but to interact with PASM I often need to get a pointer, then add the offset, and to do it, cast have to be used first. That's why I added the addr function, which is also present in 8-bit Basics.

Not a high priority (I alredy have and use these function in a include file)

function peek(addr) as ubyte
dim r as ubyte
asm
rdbyte r,addr
end asm
return r
end function

function dpeek(addr) as ushort
dim r as ushort
asm
rdword r,addr
end asm
return r
end function

function lpeek(addr) as ulong
dim r as ulong
asm
rdlong r,addr
end asm
return r
end function

function slpeek(addr) as integer
dim r as integer
asm
rdlong r,addr
end asm
return r
end function

sub poke(addr as ulong,value as ubyte)
asm
wrbyte value, addr
end asm
end sub

sub dpoke(addr as ulong,value as ushort)
asm
wrword value, addr
end asm
end sub

sub lpoke(addr as ulong,value as ulong)
asm
wrlong value, addr
end asm
end sub

sub slpoke(addr as ulong,value as integer)
asm
wrlong value, addr
end asm
end sub

function addr(byref v as const any) as ulong
return(cast(ulong,@v))
end function

Comments

  • Thanks for the suggestions. I've added DPEEK, DPOKE, PEEK, and POKE. Instead of ADDR I used VARPTR, which seems to be QBasic's name for that.

  • :+1:
    Best language ever gets even better :smiley:

    Many thanks, Eric

  • pik33pik33 Posts: 2,350

    @Mickster said:
    :+1:
    Best language ever gets even better :smiley:

    Many thanks, Eric

    Long versions still needed :) but yes, the language gets better every iteration. I now write everything for a P2 - except PASM drivers - in it.

  • @pik33 said:
    the language gets better every iteration. I now write everything for a P2 - except PASM drivers - in it.

    It has been very satisfying to see this BASIC implementation grow and mature.

    A couple of years ago FlexBASIC was buggy to the point where Eric and I were in almost daily email exchange reporting bugs. It was essentially a “toy” language. No more! Its been months now since I’ve rattled his cage. I have P2 code deployed that runs unattended for months without issues. He (and recently Ada) have made amazing progress here. Kudos!

  • +1
    Mike

Sign In or Register to comment.