With the link posted by Manel46, I started doing some experiments, like this one:

CHGET: EQU 0x9F ; aguarda uma tecla ser pressionada

CALL_BASIC: EQU 0x159 ; endereço para chamar o BASIC

PLAY: EQU 0x39AE

COLOR: EQU 0x39A6

ORG 0xd000

start:

LD HL, LINHA_BASIC_COLOR ; carrega a linha basic

LD IX, (COLOR) ; seta a função color para execução

CALL CALL_BASIC ; executa

LD HL, LINHA_BASIC_PLAY ; carrega a linha basic

LD IX, (PLAY) ; seta a função play para execução

CALL CALL_BASIC ; executa

RET ; encerra.

LINHA_BASIC_PLAY: db 34,"ACD",34,0

LINHA_BASIC_COLOR: db "15,1,1",0

end start

My question is, how to get the result returned by a function like SQR ? Where is the result stored ?

Hi!,

I'm glad to hear that my post has been useful for you, @Iamweasel2! ;-)

Gracias & Saludetes. ;-)

*manolito74*wrote:

Hi!,

I'm glad to hear that my post has been useful for you, @Iamweasel2! ;-)

Gracias & Saludetes. ;-)

Indeed It was very useful Manolito, thanks!

I was wondering , do you know how to get the result from the Basic Math functions like SQR , Sin and others?

*iamweasel2*wrote:

My question is, how to get the result returned by a function like SQR ? Where is the result stored ?

The result is probably stored in DAC (0F7F6h), and the type in VALTYP (0F663h).

*pgimeno*wrote:

*iamweasel2*wrote:

My question is, how to get the result returned by a function like SQR ? Where is the result stored ?

The result is probably stored in DAC (0F7F6h), and the type in VALTYP (0F663h).

Yes, but after reading MSX Top Secret and some info here at MRC about the mathpack, I couldn't understand how to set up those variables (DAC and VALTYP) in order to have for example, SQR to calculate the square root of 4. I think I'll quit this, it has been most frustrating.

I got it working here, but I must STILL be doing something wrong. The COS function works with some values (0 degree, 360 degree, 90 degree) but not others. I couldn't get it to work with SQR or SIN, despite the fact they all take the same parameter (DAC) and returns the result in DAC too.

If someone can tell me what I'm doing wrong, I would really appreciate it, it is driving me crazy:

CHPUT: equ 0x00a2 ;

VALTYP: EQU 0XF663 ;

DAC: EQU 0XF7F6

MOVFM: EQU 2EBEh ; DAC <- (HL)

COS: EQU 2993h ;

MOVMF: EQU 2EE8h ; (HL) <- DAC

PUFOUT: EQU 3426h ; converts DAC to a formatted string and returns it in HL.

SIN: EQU 29ACh

SQR: EQU 2AFFh

ORG 0xd000

start:

LD HL,NOME

call print

LD HL, data_360 ; parameter to the function (DAC)

LD A,4 ; single precision real number

LD (VALTYP),A

CALL MOVFM ; copy HL --> DAC

CALL COS ; execute

; PUFOUT parameters

; A = each bit defines the way the string will be formatted.

; bit 7: 1--> formatted String.

;bit 3 1 --> adds '+' to positive numbers

LD A,10001000b ;

LD B,1 ; number of digits before .

LD C,4 ; Number of digits after ., including the point. (?)

CALL PUFOUT ;

CALL print

; prints the string in HL

print:

LD A,(HL)

or A

ret z

CALL CHPUT

inc HL

jr print

data_0: DB 41h,00h,00h,00h ; number 3 =0,00000

data_30: DB 40h,52h,36h,00 ; number = 0,523600

data_45: DB 40,78h, 54h, 00; number = 0,7854

data_90: DB 41h,15h,70h,80h; number: 1.57080

data_PI: DB 41h,31h,41h,59h; number: 3.14159

data_360: DB 41,62h,83h,19h; number: 6,28319

data_4: DB 41,90h,00h,00h; numero = 4,00000

NOME: DB "Math Pack Program",13,10,10,0

end start

I got it, it was the MOVFM the problem. Plus, there were some typos in two numbers (missing the h, which changed them to decimal).

I'll post a clean code later, in order to become useful to others with the same idea as me (using the math-pack).

*iamweasel2*wrote:

If someone can tell me what I'm doing wrong, I would really appreciate it, it is driving me crazy:

You forgot some h's in the first bytes of the numbers. In particular in data_360, in data_45 and in data_4.

COS is working, as evidenced by trying this in BASIC:

defusr1=&h2993 ' COS ?usr1(0.5) .877582

Therefore there must be something wrong in your handling of the input or output numbers. I've checked the MOVFM routine and it expects arguments in a weird order: first the second word, then the first word. For example, 0.7854 needs to be represented like this:

data_45: DB 54h,00h, 40h,78h ; number = 0,7854

After that change and fixing the h's, it works. But note you're not returning after the last call to print, therefore it falls through.

Edit: oops, too slow!

*pgimeno*wrote:

*iamweasel2*wrote:

If someone can tell me what I'm doing wrong, I would really appreciate it, it is driving me crazy:

You forgot some h's in the first bytes of the numbers. In particular in data_360, in data_45 and in data_4.

COS is working, as evidenced by trying this in BASIC:

defusr1=&h2993 ' COS ?usr1(0.5) .877582

Therefore there must be something wrong in your handling of the input or output numbers. I've checked the MOVFM routine and it expects arguments in a weird order: first the second word, then the first word. For example, 0.7854 needs to be represented like this:

data_45: DB 54h,00h, 40h,78h ; number = 0,7854

After that change and fixing the h's, it works. But note you're not returning after the last call to print, therefore it falls through.

Edit: oops, too slow!

Thanks a lot for your coments and corrections pgimeno. Indeed, the missing h in the numbers is a proof that I shouldn't try to code past midnight.

In the end, I just did a LDIR of the bytes directly to the DAC instead of using MOVFM, it solved the issue. But I was wondering what was wrong with this function MOVFM. Your explanation cleared the issue, thanks again.