Peek$ and Poke$ macros

Started by Charles Pegge, February 07, 2025, 08:15:11 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Charles Pegge

PowerBasic style:

macro peek$ as string(r,pt,le)
==============================
r=nuls le
copy strptr(r),pt,le
end macro

macro poke$ (s,pt)
==================
copy pt, strptr(s),len(s)
end macro

function Hexabyte$(string s) as string
======================================
int a
int i
int j=1
int le=len(s)
string t=space(le*3)
for i=1 to len(s)
  a=asc(s,i)
  mid(t,j)=hex(a,2)
  j+=3
next
return t
end function

'TESTS
'=====
string s="Hello World!"
sys p=strptr(s)
poke$("Ha",p)
'print s               'Hallo
dimstring t=peek$(s,3) '
'print t               'Hal
'print hexabyte$ t     '48 61 6c
dim ubyte x[10]        '
copy @x,strptr(t),3    'PeekBytes to array
'print x[2]            '97