Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DEFADD trick with ZX BASIC compiler?
#1
Hi

In the normal basic of zx spectrum 48k there is a behaviour or trick like this

you can change the address of DEFADD variable

and after this you can copy bytes very fast  Is like an assembler LDIR

I will explain more

you can have 2 variables A$ and B$  for example

every one of this variables can have 1000 bytes

when you do A$ = B$  the 1000 bytes of B$ are copied on A$

Normally DEFADD points to the beginning of the variables definitions

for example  (invented numbers)

DEFADD_POINTER_ADDRESS    ;;'' defadd initial definitions of variables
A$ begins on 30000 and have 1000 bytes of size
B$ begins on 32000 and have 1000 bytes of size
etc ...


The trick is that in BASIC we can change the DEFADD address and put any thing

for example we can do

CHANGED_DEFADD_POINTER_ADDRESS    ;;'' CHANGED defadd initial definitions of variables
A$ begins on 16384 and have 256 bytes of size
B$ begins on 32000 and have 256 bytes of size
etc ...


This way we can do A$ = B$ and copy 256 very fast to the screen !!!

this is better explained here in spanish
https://blog.jafma.net/2020/03/16/effici...m-iv/#sp_5

and here in english
https://blog.jafma.net/2020/03/16/effici...m-iv/#en_5

and here a video in spanish explaining this trick
https://www.youtube.com/watch?v=VKJ2dePykdA

I tried this trick with compiled zx basic but is not working because seems
that string variables are not doing the same behavior that original ROM
Reply
#2
(09-22-2021, 07:45 PM)maeloterkim Wrote: Hi

In the normal basic of zx spectrum 48k there is a behaviour or trick like this

you can change the address of DEFADD variable

and after this you can copy bytes very fast  Is like an assembler LDIR

I will explain more

you can have 2 variables A$ and B$  for example

every one of this variables can have 1000 bytes

when you do A$ = B$  the 1000 bytes of B$ are copied on A$

Normally DEFADD points to the beginning of the variables definitions

for example  (invented numbers)

DEFADD_POINTER_ADDRESS    ;;'' defadd initial definitions of variables
A$ begins on 30000 and have 1000 bytes of size
B$ begins on 32000 and have 1000 bytes of size
etc ...

[...]

I tried this trick with compiled zx basic but is not working because seems
that string variables are not doing the same behavior that original ROM

You don't need this in ZX Basic. Use memcopy:
Code:
#include <memcopy.bas>

memcopy(32768, 16784, 256)

The above code copies from 32768 (source) to 16784 (dest) 256 bytes. Cool 
Hope this helps!

EDIT: I'm documenting the standard library bundled with ZX Basic, as it includes many things, like scroll, sprites (faster than print), etc. etc.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)