![]() |
|
POKE STRING and @string$ - Printable Version +- Boriel Basic Forum (https://forum.boriel.com) +-- Forum: Compilers and Computer Languages (https://forum.boriel.com/forumdisplay.php?fid=12) +--- Forum: ZX Basic Compiler (https://forum.boriel.com/forumdisplay.php?fid=11) +---- Forum: Help & Support (https://forum.boriel.com/forumdisplay.php?fid=16) +---- Thread: POKE STRING and @string$ (/showthread.php?tid=229) Pages:
1
2
|
POKE STRING and @string$ - LCD - 2010-06-02 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? Re: POKE STRING and @string$ - boriel - 2010-06-02 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$)Re: POKE STRING and @string$ - LCD - 2010-06-02 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 SUBCode: SUB test(a$ as string)
DIM dummy$
dummy$=a$
PRINT PEEK(Uinteger, @dummy$)
END SUBRe: POKE STRING and @string$ - boriel - 2010-06-02 LCD Wrote:I was expecting, it was a pointer, but I ran into the problem in a sub: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... Re: POKE STRING and @string$ - LCD - 2012-09-03 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. Re: POKE STRING and @string$ - boriel - 2012-09-03 LCD Wrote:BUMP!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. Re: POKE STRING and @string$ - LCD - 2012-09-03 boriel Wrote:LCD Wrote:BUMP!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. Re: POKE STRING and @string$ - LCD - 2012-09-04 By the way: <!-- m --><a class="postlink" href="http://www.freebasic-portal.de/befehlsreferenz/poke-476.html">http://www.freebasic-portal.de/befehlsr ... e-476.html</a><!-- m --> (german) FreeBasic supports POKE/PEEK String Re: POKE STRING and @string$ - nitrofurano - 2013-06-02 btw, it's missing a description about memcopy (or memcpy) at <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Library">http://www.boriel.com/wiki/en/index.php ... IC:Library</a><!-- m --> 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 subRe: POKE STRING and @string$ - LCD - 2013-06-03 nitrofurano Wrote:btw, it's missing a description about memcopy (or memcpy) at <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Library">http://www.boriel.com/wiki/en/index.php ... IC:Library</a><!-- m -->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 subCode: 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 subRe: POKE STRING and @string$ - boriel - 2013-06-03 LCD Wrote:At the moment I'm "tera-busy" (not mega, neither giganitrofurano Wrote:btw, it's missing a description about memcopy (or memcpy) at <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Library">http://www.boriel.com/wiki/en/index.php ... IC:Library</a><!-- m -->Is this not a little bit offtopic? ) 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: Re: POKE STRING and @string$ - LCD - 2013-06-03 boriel Wrote:At the moment I'm "tera-busy" (not mega, neither gigaCool. Thanks! Looking forward for the refactored Compiler. Re: POKE STRING and @string$ - LCD - 2013-06-04 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$<>""Edit: replacing Code: ld d,(ix+5)
ld e,(ix+4)Code: ld de,hlCode: 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 subRe: POKE STRING and @string$ - nitrofurano - 2013-06-04 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 0i got from terminal: Code: memcopytest.bas:5: Error: Syntax error. Unexpected token 'IX' [IX](btw, sorry about the offtopic... :S ) Re: POKE STRING and @string$ - LCD - 2013-06-04 nitrofurano Wrote:thanks, but when testingOkay, 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 |