Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DIM At?
#1
Hi, I'm a newbie with Boriel's ZX Basic and I´m not sure if there is a way to do something like this:

DIM charset(767) As uByte At 49152 => {0,12,48,36,....,(768th byte)}

The idea is to place an array of 768 bytes (like a character set) at a specific memory direction(49152).

I was read the Wiki and I found some references to "DIM At" but it's not clear for me .
Reply
#2
Unfortunately DIM AT for arrays is not supported (yet).
This is because ZXBASIC allocates a table of dimensions (one Uinteger per dimension) just before the data.
I'm working on a Dynamic ARRAY scheme, so this could be possible in the future.
Reply
#3
This has been implemented in ZX Basic 1.9+
Reply
#4
(11-10-2019, 10:02 PM)boriel Wrote: This has been implemented in ZX Basic 1.9+

Hi Smile 

What is the sintaxis for DIM at?

Can you put some examples with initialized array and not initialized array?

thanks
Reply
#5
(11-21-2019, 01:03 PM)maeloterkim Wrote:
(11-10-2019, 10:02 PM)boriel Wrote: This has been implemented in ZX Basic 1.9+

Hi Smile 

What is the sintaxis for DIM at?

Can you put some examples with initialized array and not initialized array?

thanks

DIM AT does not allow initialized values. The content will be whatever there exists already at the given location.

For arrays the syntax is

DIM varname(dim1, dim2, dim3...) AS <type> AT <address>. For example:

DIM a(6144) As UByte AT 16384

This is undocumented (yet) for arrays, but will be updated here: https://zxbasic.readthedocs.io/en/latest/dim/

Hope this helps
Reply
#6
(11-21-2019, 04:28 PM)boriel Wrote:
(11-21-2019, 01:03 PM)maeloterkim Wrote:
(11-10-2019, 10:02 PM)boriel Wrote: This has been implemented in ZX Basic 1.9+

Hi Smile 

What is the sintaxis for DIM at?

Can you put some examples with initialized array and not initialized array?

thanks

DIM AT does not allow initialized values. The content will be whatever there exists already at the given location.

For arrays the syntax is

DIM varname(dim1, dim2, dim3...) AS <type> AT <address>. For example:

DIM a(6144) As UByte AT 16384

This is undocumented (yet) for arrays, but will be updated here: https://zxbasic.readthedocs.io/en/latest/dim/

Hope this helps

Well i'm doing now this for the UDGs

DIM MyUDGs(167) As uByte => {MY...UDG...BYTES}
poke uinteger 23675, @MyUDGs

would be very good do something like this  Wink   

DIM MyUDGs(167) As uByte  AT (PEEK uinteger 23675)  
=> {MY...UDG...BYTES} 

OR 

DIM MyUDGs(167) As uByte  
=> {MY...UDG...BYTES}  AT (PEEK uinteger 23675)

where the UDGs are poked directly where they must be

maybe you can "know" where the programmer want to put the values of the array ( calculate all the memory used and the memory left )

then you know what memory is left to put the compiled program 

and then you know if is compilable or not

i don't know if i'm saying somethig stupid or is a posible idea  Tongue

Hope this helps
Reply
#7
Not sure if I get you.
When you declare an array it's a fixed location (for the moment).
However it's possible to copy array content (if both arrays have the same type and size).
For example:

Code:
DIM myUDGSet1(128) as UByte => {...}
DIM myUDGSet2(128) as UByte => {...}
...
POKE UInteger 23675, @myUDGSet1(0): REM Sets 1st graphics bank. Always use myUDGSet(0) to get the addr of the 1st element
...

Does this help?

What you're asking above looks more like a pointer and it's not yet :-)
Reply
#8
Well i don't know how the compiler works (take this in mind  Smile   ) and i don't know if it's about pointers but "MAYBE" can do something like this

  if i found a DIM with AT ( first i look for all of them)
          
         1)  i copy the bytes of the dim (or others AT) at the position of the AT   
               or something like this or reserve space for this for write it after
               or an array of holes with data

         2)  i calculate the holes of empty memory to put the "normal" stuff
              maybe can make an array of empty memory holes

 end if 

 if i found other stuff without AT 

        i put this things on the empty memory holes in order

end if

I don't know if something like this can work with the compilator

This way the program saves bytes from memory and from the program to copy bytes to other locations
 
OR maybe another way 

    1)  DIM AT
    2) the compiler move the data to the AT place
    3) the programmer knows that CAN'T use the array in a normal way to acces the values of the DIM (can't use array(2,3) per example)
        but is useful for example for poke directly some memory address like UDG

by the way great compiler Smile
Reply
#9
DIM AT only maps an array to a memory region. It does not reserve memory.
If you want to declare an array to map UDGs into it, you should use:

DIM myUDGtable(...) as UBYTE => {...}
POKE UInteger 23675, @myUDGTable(0, 0, ...)

If you have several UDGs sets you can arrange them in different arrays and poke for each one as above when required, or better:
put all the graphics in a single array, were each row is a new charset:
Code:
DIM myUDG1(8, 128) as UByte => { ... }
POKE UInteger 23675, @myUDG1(0, 0): REM uses the 1st 128 bytes charset
...
POKE Uinteger 23675, @myUDG(2, 0): REM used the 3rd 128 bytes charset...

LET UDGset = 5
POKE UInteger  23675, @myUDG(UDGset, 0): REM chooses the charset pointer by the variable UDGSet

Hope this helps.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)