float asm...read the value with peek?

All aspects of programming on the Commander X16.
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

float asm...read the value with peek?

Post by funkheld »

Hi good afternoon.
Where is the string stored in float's memory so that it can be read with peek and written with "print"?

I would like to output this loop in basic with print/poke and not in asm:
-------------------------
loop:
lda ($02),y
beq done
jsr CHROUT
iny
bne loop
done:
------------------------
Thanks.

Code: Select all

; calculate how far an object has fallen:  d = 1/2 * g * t^2.
; we set g = 9.81 m/sec^2, time = 5 sec -> d = 122.625 m.

   org $00
CHROUT = $ffd2
FOUT   = $fe06
FMULTT = $fe21
FDIV   = $fe24
CONUPK = $fe5a
MOVFM  = $fe63
   
    lda  #4
    sta  $01         ; rom bank 4 (BASIC) contains the fp routines.
    lda  #<flt_two
    ldy  #>flt_two
    jsr  MOVFM
    lda  #<flt_g
    ldy  #>flt_g
    jsr  FDIV        ; FACC= g/2
    lda  #<flt_time
    ldy  #>flt_time
    jsr  CONUPK      ; ARG = time
    jsr  FMULTT      ; FACC = g/2 * time
    lda  #<flt_time
    ldy  #>flt_time
    jsr  CONUPK      ; again ARG = time
    jsr  FMULTT      ; FACC = g/2 * time * time
    jsr  FOUT        ; to string
    ; print string in AY
    sta  $02
    sty  $03
    ldy  #0
loop:
    lda  ($02),y
    beq  done
    jsr  CHROUT
    iny
    bne  loop
done:
    rts

flt_g:      .byte  $84, $1c, $f5, $c2, $8f  ; float 9.81
flt_time:   .byte  $83, $20, $00, $00, $00  ; float 5.0
flt_two:    .byte  $82, $00, $00, $00, $00  ; float 2.0
User avatar
ahenry3068
Posts: 1134
Joined: Tue Apr 04, 2023 9:57 pm

Re: float asm...read the value with peek?

Post by ahenry3068 »

Floating point numbers are a lot more complicated internally that ints and bytes. Even more complicated than a String representation (which uses a pointer to the actual string data). Unless you need to manipulate them in an Assembly routine it's usually better to leave the internal stuff to BASIC. POINTER(A) does return the floats address, but dealing with what's there is complicated.

That being said here's a good treatise. X16 uses the same Floating Point format as C64. (Anything you read about ROM here is almost certainly WRONG for X16). The math stuff should be applicable.

https://c64os.com/post/floatingpointmath
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: float asm...read the value with peek?

Post by funkheld »

I'm looking for the address where the string is located.
I had already found it once on the c64, but it was a long time ago.
Since the x16 works with the c64, I thought that you would know the address for the string.

Thanks.
User avatar
ahenry3068
Posts: 1134
Joined: Tue Apr 04, 2023 9:57 pm

Re: float asm...read the value with peek?

Post by ahenry3068 »

funkheld wrote: Sat Apr 13, 2024 8:41 am I'm looking for the address where the string is located.
I had already found it once on the c64, but it was a long time ago.
Since the x16 works with the c64, I thought that you would know the address for the string.

Thanks.
Are you talking about the variable Name ? If so I believe it is Pointer(X) - 2.

OK Tested some code. The above is correct. If the Variable is a float it's name is there in ASCII value.
If the Variable is an Integer it's characters are OR'd with 128 so you AND it with 127 to get the ASCII value.

10 XX=100 20 P=POINTER(XX) 30 PRINT CHR$(PEEK(P-2));CHR$(PEEK(P-1)); Will Print XX if it's a float. If XX was an Integer 30 PRINT CHR$(PEEK(P-2) AND 127);CHR$(PEEK(P-1) AND 127); Would print the same.

Remember when using BASLOAD you are going to get the 2 character names BASLOAD creates, Not what is in your source.
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: float asm...read the value with peek?

Post by funkheld »

Hello.

forget my program, there is an error in it.

greeting
Last edited by funkheld on Sat Apr 13, 2024 6:53 pm, edited 2 times in total.
User avatar
ahenry3068
Posts: 1134
Joined: Tue Apr 04, 2023 9:57 pm

Re: float asm...read the value with peek?

Post by ahenry3068 »

I really haven't figured out what your trying to do.

If you want to make a STRING out of any number in BASIC (Int or Float)

A=122.25
A$=STR$(A)

PRINT A$
122.25.
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: float asm...read the value with peek?

Post by funkheld »

hello thanks for your solution.

greeting
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: float asm...read the value with peek?

Post by funkheld »

Hi good afternoon.

a result printed out by the asm program and underneath simply the string from address $100
read out with peek and printed out.

greeting

Code: Select all

BANK 1

RESTORE ASM

READ Z
FOR P = 0 TO Z-1
  READ A
  POKE $a000+P,A
NEXT 

SYS $a000

PRINT ""
PRINT ""

FOR A=0 TO 10
  PRINT CHR$(PEEK($100+A));
NEXT

ASM:
 DATA 73
 DATA  $A9, $04, $85, $01, $A9, $44, $A0, $A0, $20, $63
 DATA  $FE, $A9, $3A, $A0, $A0, $20, $24, $FE, $A9, $3F
 DATA  $A0, $A0, $20, $5A, $FE, $20, $21, $FE, $A9, $3F
 DATA  $A0, $A0, $20, $5A, $FE, $20, $21, $FE, $20, $06
 DATA  $FE, $85, $02, $84, $03, $A0, $00, $B1, $02, $F0
 DATA  $06, $20, $D2, $FF, $C8, $D0, $F6, $60, $84, $1C
 DATA  $F5, $C2, $8F, $83, $20, $00, $00, $00, $82, $00
 DATA  $00, $00, $00,
 
Attachments
asmmath.jpg
asmmath.jpg (17.02 KiB) Viewed 2420 times
Edmond D
Posts: 489
Joined: Thu Aug 19, 2021 1:42 am

Re: float asm...read the value with peek?

Post by Edmond D »

Rather than poke the code into memory then execute it, consider creating an auto launching program directly.

To start read:

https://github.com/commanderx16/x16-emu ... 2-programs

Then try this example:

https://techblog.dansbo.dk/?p=38

If you don't have an Assembler, you can use the built in monitor (MON) to the CodeX environment - https://sites.google.com/view/x16asmenv/v0-90-beta
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: float asm...read the value with peek?

Post by funkheld »

Thanks for the info.

the editor is already in R47.

I only want to use the data on demand in basic and should not be output by the ASM program. I'm doing a test that float
in linine is faster than in basic.

i have the mads-asm-compiler :
https://mads.atari8.info/mad-assembler-mkdocs/en/
also for him 65C816 CPU from x16 (Emulator).

I have a self-written program which creates an inline data from the prg for basic.

greeting
Post Reply