Posts: 615
Threads: 49
Joined: Feb 2009
Reputation:
2
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?
Posts: 1,763
Threads: 55
Joined: Aug 2019
Reputation:
24
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.
Posts: 615
Threads: 49
Joined: Feb 2009
Reputation:
2
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...
Posts: 1,763
Threads: 55
Joined: Aug 2019
Reputation:
24
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...
Posts: 615
Threads: 49
Joined: Feb 2009
Reputation:
2
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.
Posts: 1,763
Threads: 55
Joined: Aug 2019
Reputation:
24
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.
Posts: 615
Threads: 49
Joined: Feb 2009
Reputation:
2
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.
Posts: 615
Threads: 49
Joined: Feb 2009
Reputation:
2
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
Posts: 366
Threads: 186
Joined: Sep 2011
Reputation:
0
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 sub
Posts: 615
Threads: 49
Joined: Feb 2009
Reputation:
2
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 -->
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
Posts: 1,763
Threads: 55
Joined: Aug 2019
Reputation:
24
LCD Wrote: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 -->
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 ![Tongue Tongue](https://www.boriel.com/forum/images/smilies/tongue.png) ) 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:
Posts: 615
Threads: 49
Joined: Feb 2009
Reputation:
2
boriel Wrote:At the moment I'm "tera-busy" (not mega, neither giga ) 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.
Posts: 615
Threads: 49
Joined: Feb 2009
Reputation:
2
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
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
Posts: 366
Threads: 186
Joined: Sep 2011
Reputation:
0
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 )
Posts: 615
Threads: 49
Joined: Feb 2009
Reputation:
2
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
|