FAQ  •  Register  •  Login

POKE STRING and @string$

<<

LCD

Posts: 596

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

Post Tue Jun 01, 2010 11:30 pm

POKE STRING and @string$

Just converted the Proportional text routine to a SUB, so it won't crash at exit, but I ran into some problems.
I remember, I asked about it, but the thread was closed then, but you promised to look at this: POKE and PEEK STRING do not work, and something else: @a$ does not return the correct adress of the string stored in a$. It returns a adress, but peeking memory in emulator reveals that the text stored in string is not at the adress. Testing @variable reveals that the adress of normal ubyte variables is correct.
Is this a bug or "feature"? If it is a feature, how to find out the adress of a string stored in Variable?
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Wed Jun 02, 2010 11:14 am

Re: POKE STRING and @string$

LCD wrote:Is this a bug or "feature"? If it is a feature, how to find out the adress of a string stored in Variable?

Strings are just pointers to memory blocks (chars), so:
  Code:
DIM a$;

PRINT PEEK(Uinteger, @a$)
a$ = "Hello" : REM Assigning a new value *changes* it [u]dynamic[/u] address

PRINT PEEK(Uinteger, @a$)

Notice a$ address pointer changes (reallocates) a$ on each assignation.
<<

LCD

Posts: 596

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

Post Wed Jun 02, 2010 1:01 pm

Re: POKE STRING and @string$

I was expecting, it was a pointer, but I ran into the problem in a sub:
  Code:
SUB test(a$ as string)
PRINT PEEK(Uinteger, @a$)
END SUB

If the String is defined in the header of the SUB, it points to a completly wrong adress (I got one on the Attribute area of screen), but thank to your tip boriel, I found a workaround:
  Code:
SUB test(a$ as string)
DIM dummy$
dummy$=a$
PRINT PEEK(Uinteger, @dummy$)
END SUB

Now I got the correct adress...
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Wed Jun 02, 2010 1:17 pm

Re: POKE STRING and @string$

LCD wrote:I was expecting, it was a pointer, but I ran into the problem in a sub:
  Code:
SUB test(a$ as string)
PRINT PEEK(Uinteger, @a$)
END SUB

If the String is defined in the header of the SUB, it points to a completly wrong adress (I got one on the Attribute area of screen), but thank to your tip boriel, I found a workaround:
  Code:
SUB test(a$ as string)
DIM dummy$
dummy$=a$
PRINT PEEK(Uinteger, @dummy$)
END SUB

Now I got the correct adress...

Not sure, but @parameter should work too. I will investigate it further, as you might catched a bug. @parameter addresses are not in a fixed ram position (the global variables memory block) but in the stack (which is a dynamic one). So, will have a look...
<<

LCD

Posts: 596

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

Post Mon Sep 03, 2012 12:41 pm

Re: POKE STRING and @string$

BUMP!
Are POKE and PEEK STRING supposed to work? This would be great for direct string manipulation. I ask because they do not work. POKE [type] address,value suggest that it should accept any type (Okay, I have not tried floats and doubles yet, and POKE ULONG address,PEEK (ULONG,address) was not working in previous versions, crashing the emulator), so this is something that needs further testing.
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Mon Sep 03, 2012 1:06 pm

Re: POKE STRING and @string$

LCD wrote:BUMP!
Are POKE and PEEK STRING supposed to work? This would be great for direct string manipulation. I ask because they do not work. POKE [type] address,value suggest that it should accept any type (Okay, I have not tried floats and doubles yet, and POKE ULONG address,PEEK (ULONG,address) was not working in previous versions, crashing the emulator), so this is something that needs further testing.

Nope, the don't. In fact, the problem here is most of you are thinking in C/Asm and not in "High level" language (such as BASIC). You can use memcpy (it's in the library) already for that. Memcpy(Destiny, @varname + 2, len(varname)) will copy an entire string starting at Destiny memory address.
<<

LCD

Posts: 596

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

Post Mon Sep 03, 2012 2:34 pm

Re: POKE STRING and @string$

boriel wrote:
LCD wrote:BUMP!
Are POKE and PEEK STRING supposed to work? This would be great for direct string manipulation. I ask because they do not work. POKE [type] address,value suggest that it should accept any type (Okay, I have not tried floats and doubles yet, and POKE ULONG address,PEEK (ULONG,address) was not working in previous versions, crashing the emulator), so this is something that needs further testing.

Nope, the don't. In fact, the problem here is most of you are thinking in C/Asm and not in "High level" language (such as BASIC). You can use memcpy (it's in the library) already for that. Memcpy(Destiny, @varname + 2, len(varname)) will copy an entire string starting at Destiny memory address.


Yes, that is true.
Thanks for clearing this.
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
<<

LCD

Posts: 596

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

Post Tue Sep 04, 2012 7:07 am

Re: POKE STRING and @string$

By the way: http://www.freebasic-portal.de/befehlsr ... e-476.html (german)
FreeBasic supports POKE/PEEK String
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
<<

nitrofurano

Posts: 349

Joined: Thu Sep 29, 2011 12:44 pm

Location: Porto, Portugal

Post Sun Jun 02, 2013 8:02 pm

Re: POKE STRING and @string$

btw, it's missing a description about memcopy (or memcpy) at http://www.boriel.com/wiki/en/index.php ... IC:Library

based on that, i'm trying to create a new subroutine, which attempts to do a memcopy from paged memory (128k) (far still incomplete and accurate, because, besides it doesn't work fine yet, it doesn't copy a group of bytes splitted into different neighbour pages)

  Code:
sub memcpypagedtodisplay(tdest as ulong, tpadr as ulong, tleng as ulong):
  dim tpvl as ulong
  dim tqadr as ulong
  tpvl=int (tpadr/16384)
  tqadr=tpadr mod 16384
  out 32765,16+(int(tpvl*1.5))
  memcopy(tdest,49152+tqadr,tleng)
  end sub
<<

LCD

Posts: 596

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

Post Sun Jun 02, 2013 11:51 pm

Re: POKE STRING and @string$

nitrofurano wrote:btw, it's missing a description about memcopy (or memcpy) at http://www.boriel.com/wiki/en/index.php ... IC:Library

based on that, i'm trying to create a new subroutine, which attempts to do a memcopy from paged memory (128k) (far still incomplete and accurate, because, besides it doesn't work fine yet, it doesn't copy a group of bytes splitted into different neighbour pages)

  Code:
sub memcpypagedtodisplay(tdest as ulong, tpadr as ulong, tleng as ulong):
  dim tpvl as ulong
  dim tqadr as ulong
  tpvl=int (tpadr/16384)
  tqadr=tpadr mod 16384
  out 32765,16+(int(tpvl*1.5))
  memcopy(tdest,49152+tqadr,tleng)
  end sub

Is this not a little bit offtopic?
Anyway, Memcopy is not optimal, it can be replaced with much faster and shorter ASM routine. I made one and it is on my HDD, but I do not remember which one was working and which not.
  Code:
sub CopyMem(src as Uinteger,des as Uinteger,length as Uinteger,bank as ubyte)
   asm
      
      ld a,(ix+11)
      ld bc,32765
      out (c),a
      ld hl,(ix+5)
      ld de,(ix+7)
      ld bc,(ix+9)
      ldir
      ld a,(23388)
      ld bc,32765
      out (c),a
   end asm
end sub

  Code:
sub CopyMem(src as Uinteger,des as Uinteger,length as Uinteger)
   asm
      ld d,(ix+7)
      ld e,(ix+6)
      ld h,(ix+5)
      ld l,(ix+4)
      ld b,(ix+9)
      ld c,(ix+8)
      ldir
   end asm
end sub
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Mon Jun 03, 2013 7:17 am

Re: POKE STRING and @string$

LCD wrote:
nitrofurano wrote:btw, it's missing a description about memcopy (or memcpy) at http://www.boriel.com/wiki/en/index.php ... IC:Library

based on that, i'm trying to create a new subroutine, which attempts to do a memcopy from paged memory (128k) (far still incomplete and accurate, because, besides it doesn't work fine yet, it doesn't copy a group of bytes splitted into different neighbour pages)

  Code:
sub memcpypagedtodisplay(tdest as ulong, tpadr as ulong, tleng as ulong):
  dim tpvl as ulong
  dim tqadr as ulong
  tpvl=int (tpadr/16384)
  tqadr=tpadr mod 16384
  out 32765,16+(int(tpvl*1.5))
  memcopy(tdest,49152+tqadr,tleng)
  end sub

Is this not a little bit offtopic?
Anyway, Memcopy is not optimal, it can be replaced with much faster and shorter ASM routine. I made one and it is on my HDD, but I do not remember which one was working and which not.
  Code:
sub CopyMem(src as Uinteger,des as Uinteger,length as Uinteger,bank as ubyte)
   asm
      
      ld a,(ix+11)
      ld bc,32765
      out (c),a
      ld hl,(ix+5)
      ld de,(ix+7)
      ld bc,(ix+9)
      ldir
      ld a,(23388)
      ld bc,32765
      out (c),a
   end asm
end sub

  Code:
sub CopyMem(src as Uinteger,des as Uinteger,length as Uinteger)
   asm
      ld d,(ix+7)
      ld e,(ix+6)
      ld h,(ix+5)
      ld l,(ix+4)
      ld b,(ix+9)
      ld c,(ix+8)
      ldir
   end asm
end sub

At the moment I'm "tera-busy" (not mega, neither giga :P) with the compiler refactoring and other projects, so I have almost no time to examine this.
This idea is *very* interesting, and this routine may go in the library/ package, bundled with the compiler. :roll:
<<

LCD

Posts: 596

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

Post Mon Jun 03, 2013 7:51 pm

Re: POKE STRING and @string$

boriel wrote:At the moment I'm "tera-busy" (not mega, neither giga :P) with the compiler refactoring and other projects, so I have almost no time to examine this.
This idea is *very* interesting, and this routine may go in the library/ package, bundled with the compiler. :roll:

Cool. Thanks!
Looking forward for the refactored Compiler.
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
<<

LCD

Posts: 596

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

Post Mon Jun 03, 2013 11:16 pm

Re: POKE STRING and @string$

While we are there. How about this?
  Code:
sub FillMem(mem as Uinteger,size as Uinteger,byt as Ubyte)
   asm
      ld h,(ix+5)
      ld l,(ix+4)
      ld d,(ix+5)
      ld e,(ix+4)
      inc de
      ld b,(ix+7)
      ld c,(ix+6)
      dec bc
      ld a,(ix+9)
      ld (hl),a
      ldir
   end asm
end sub

paper 7:ink 0:cls
do
FillMem(16384,6144,85)
asm
   halt
end asm
FillMem(16384,6144,170)
asm
   halt
end asm
loop until inkey$<>""

I think, this may be usefull for some coders here too. But I'm just playing around...
Edit: replacing
  Code:
ld d,(ix+5)
ld e,(ix+4)

with
  Code:
ld de,hl

should work too and save some bytes.
  Code:
sub FillMem(mem as Uinteger,size as Uinteger,byt as Ubyte)
   asm
      ld h,(ix+5)
      ld l,(ix+4)
      ld de,hl
      inc de
      ld b,(ix+7)
      ld c,(ix+6)
      dec bc
      ld a,(ix+9)
      ld (hl),a
      ldir
   end asm
end sub
Last edited by LCD on Tue Jun 04, 2013 10:31 pm, edited 1 time in total.
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
<<

nitrofurano

Posts: 349

Joined: Thu Sep 29, 2011 12:44 pm

Location: Porto, Portugal

Post Tue Jun 04, 2013 12:39 pm

Re: POKE STRING and @string$

thanks, but when testing

  Code:
sub cpymempaged(src as Uinteger,des as Uinteger,length as Uinteger,bank as ubyte):
  asm
    ld a,(ix+11)
    ld bc,32765
    out (c),a
    ld hl,(ix+5)
    ld de,(ix+7)
    ld bc,(ix+9)
    ldir
    ld a,(23388)
    ld bc,32765
    out (c),a
  end asm
end sub
sub cpymem(src as Uinteger,des as Uinteger,length as Uinteger):
  asm
    ld d,(ix+7)
    ld e,(ix+6)
    ld h,(ix+5)
    ld l,(ix+4)
    ld b,(ix+9)
    ld c,(ix+8)
    ldir
  end asm
end sub
cls
cpymem(17000,12000,400)
pause 0


i got from terminal:
  Code:
memcopytest.bas:5: Error: Syntax error. Unexpected token 'IX' [IX]


(btw, sorry about the offtopic... :S )
<<

LCD

Posts: 596

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

Post Tue Jun 04, 2013 10:28 pm

Re: POKE STRING and @string$

nitrofurano wrote:thanks, but when testing

  Code:
sub cpymempaged(src as Uinteger,des as Uinteger,length as Uinteger,bank as ubyte):
  asm
    ld a,(ix+11)
    ld bc,32765
    out (c),a
    ld hl,(ix+5)
    ld de,(ix+7)
    ld bc,(ix+9)
    ldir
    ld a,(23388)
    ld bc,32765
    out (c),a
  end asm
end sub
sub cpymem(src as Uinteger,des as Uinteger,length as Uinteger):
  asm
    ld d,(ix+7)
    ld e,(ix+6)
    ld h,(ix+5)
    ld l,(ix+4)
    ld b,(ix+9)
    ld c,(ix+8)
    ldir
  end asm
end sub
cls
cpymem(17000,12000,400)
pause 0


i got from terminal:
  Code:
memcopytest.bas:5: Error: Syntax error. Unexpected token 'IX' [IX]


(btw, sorry about the offtopic... :S )

Okay, so I do now know which one was not working... LD registerpair,(IX+offset) is invalid. Then this should work:
  Code:
sub cpymempaged(src as Uinteger,des as Uinteger,length as Uinteger,bank as ubyte)
  asm
    ld a,(ix+11)
    ld bc,32765
    out (c),a
    ld h,(ix+5)
    ld l,(ix+4)
    ld d,(ix+7)
    ld e,(ix+6)
    ld b,(ix+9)
    ld c,(ix+8)
    ldir
    ld a,(23388)
    ld bc,32765
    out (c),a
  end asm
end sub
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
Next

Return to Help & Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO