Msx Basic array to asm

Por PingPong

Prophet (4087)

imagem de PingPong

18-09-2018, 14:23

How i can Pass a int [] array via usr ti a machine language sub getting both ptr to data and size of array?

Entrar ou registrar-se para comentar

Por gdx

Enlighted (5996)

imagem de gdx

18-09-2018, 14:37

See here:
https://www.msx.org/wiki/USR%28%29
And here:
https://www.msx.org/wiki/BASIC_Routines_In_Main-ROM
if you want more information about variables format and more.

Por Eugeny_Brychkov

Paragon (1226)

imagem de Eugeny_Brychkov

18-09-2018, 15:20

10 defint a:dim a[20]
20 a[0]=100:a[1]=200
30 defusr=&hc000:a=usr(varptr(a[0]))

In this code routine at &hc000 is called with HL pointing to DAC, and HL+2 (DAC+2) containing pointer to the start of the array (element a[0]). I think it is fair to expect that array is contiguous, thus (DAC+2) + 10 will point to word of a[5].

Here's format (example of bi-dimensional array from here):

    +-----+-----+-----+-----------+-----+-----------+-----------+
    |     |     |     |  Offset   | Dim |   Count   |   Count   |
    | 02H | "A" | "B" | 2DH   00H | 02H | 05H   00H | 04H   00H |
    +-----+-----+-----+-----------+-----+-----------+-----------+

(DAC+2) pointing to the first byte after the array, thus if you know it is single dimensioned array you move pointer -2 bytes and read word of the array's size. Move pointer another byte position -1 will give you 1 (single dimension).

I do not think it is possible to pass pointer to array this way; alternatively you can pass name of array to USR as a string, and use PTRGET to know pointer to the array - playing with SUBFLG. But it needs testing.

Por PingPong

Prophet (4087)

imagem de PingPong

18-09-2018, 19:46

Thx to all expecially to Eugeny. I've noticed the unusual double type storage format, wondering if this have or not speed benefits compared to IEEE like formats that are full & true binary based.

Por mzoran

Master (154)

imagem de mzoran

23-07-2022, 21:34

I have been testing extending BASIC commands and passing array variables.
When I set SUBFLG=1 and call PTRGET I do get a pointer in BC to the Dim part of the array and VALTYP is correctly set.
This is all fine, however, this appears to mess something up in BASIC parser.
Trying to assign a value to an array member will result in syntax error, further attempts will succeed.
Equally if I simply try to print value, it will print two values, first some negative value and then the correct one.
Has anyone a good code example of using PTRGET on arrays ?

Por mzoran

Master (154)

imagem de mzoran

28-07-2022, 12:20

Just for future reference, it seems one just needs to set SUBFLG back to 0 for normal operation. This little code will work:

    
LD A,1
LD (SUBFLG),A ; search for arrays only
LD IX, PTRGET
CALL CALBAS
XOR A
LD (SUBFLG),A ; if not reset will cause syntax errors

BC will point to Dim location