Where are the addresses for the float routines in the VIC20?

Basic and Machine Language

Moderator: Moderators

Post Reply
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Where are the addresses for the float routines in the VIC20?

Post by funkheld »

Hi good afternoon.

Where are the addresses for the float routines in the VIC20?
I wanted to use it in ASM.

this is the c64 :
https://www.c64-wiki.de/wiki/Flie%C3%9Fkommaarithmetik

Thank you.
Greeting
wimoos
Vic 20 Afficionado
Posts: 352
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Re: Where are the addresses for the float routines in the VIC20?

Post by wimoos »

Hello funkheld

The Basic Interpreter in VIC20 is assembled in $C000 - $DFFF.

I always use: https://www.mdawson.net/vic20chrome/vic ... sembly.txt for reference.

Regards,

Wim.
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
User avatar
Mike
Herr VC
Posts: 4901
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Where are the addresses for the float routines in the VIC20?

Post by Mike »

@wimoos: PM sent
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Re: Where are the addresses for the float routines in the VIC20?

Post by funkheld »

Hello, thanks for the help.

I'm going to pick out the float commands.

Thank you.
greeting
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Re: Where are the addresses for the float routines in the VIC20?

Post by funkheld »

Hi good afternoon.

what does that mean please, i don't understand it as german:
convert FAC1 floating to fixed

Thank you.
greeting
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: Where are the addresses for the float routines in the VIC20?

Post by chysn »

Hey, funkheld,

I'm interested in this question, too. So far, I've been working with the integer-to-float and float-to-integer conversions. These are useful for getting input from BASIC (via USR()) and returning output as a USR() return value. The relevant routines are

$D1AA: Converts a floating point value in FAC1 (the first of two floating point accumulators) to a 16-bit integer, with Y as the low byte and A as the high byte
$D391: Writes a 16-bit integer (same format as above) to FAC1

Here's a simple example that basically turns USR() into PEEK

Code: Select all

1800 JSR $D1AA   ; Convert the parameter passed to USR into 16-bit integer (Y low, A high)
1803 STY $F9     ; Save the low and high bytes as a pointer to the location we want to PEEK at
1805 STA $FA
1807 LDY #$00    ; Clearing Y so it can be used as a 0 index in the next instruction
1809 LDA ($F9),Y
180B TAY         ; Y is used as the low byte for the fixed-to-float conversion
180C LDA #$00    ; A is the high byte, so we want it to be 0
180E JSR $D391   ; Convert Y/A over to FAC1, so that USR() returns it
1811 RTS
Then set the USR instruction with

POKE 0, 76:POKE 1, 0:POKE 2,24

?USR(2);
24

The next thing I'm going to do is play around with floating point operations between the two FACs. Most operations are performed on FAC1, but there are routines that copy FAC2 to FAC1 ($DBFC) and vice-versa ($DC0F). So if you don't mind, I'll write more about these experiments on this thread.
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
Mike
Herr VC
Posts: 4901
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Where are the addresses for the float routines in the VIC20?

Post by Mike »

chysn wrote:So if you don't mind, I'll write more about these experiments on this thread.
If you go on exploration mode regarding the floating point routines of the VIC-20 BASIC interpreter, that for sure warrants your own thread - with the prospect that quite some people here in Denial will follow the new thread as it unfolds.

At least that promises to be a much more interesting topic than the trivial question put up in this thread here, where the OP just wants a list of addresses spoon-fed, all of which can be found in standard literature (like "Compute's Mapping the VIC" in English or "VC-20 intern" in German) or - for that matter - in a sticky thread here in the Programming section ("ROM calls and other tricks").
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: Where are the addresses for the float routines in the VIC20?

Post by chysn »

Mike wrote: Mon Feb 17, 2020 3:13 pm
chysn wrote:So if you don't mind, I'll write more about these experiments on this thread.
If you go on exploration mode regarding the floating point routines of the VIC-20 BASIC interpreter, that for sure warrants your own thread
Perhaps I will. I’ll peruse the forum a bit to see if a treatment of floating point arithmetic in ML already exists. Writing about something often helps me understand it better.

I’m finding that Mapping the VIC’s info is really good. It doesn’t really go into the format of the mantissa; but the more I delve, the more I realize that I can treat FAC1 and FAC2 as black boxes. There’s enough software in ROM to deal with them in a civilized way, i.e., as converted strings or data copied from memory.
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
Mike
Herr VC
Posts: 4901
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Where are the addresses for the float routines in the VIC20?

Post by Mike »

chysn wrote:I’ll peruse the forum a bit to see if a treatment of floating point arithmetic in ML already exists.
Such a treatment has not been done yet here in Denial, AFAIK.

You'll find quite some examples of float routines strewn across the forum: SQR() reimplemented with Heron's algorithm, the inner loop of the Mandelbrot fractal, USR() used as popcount or joystick read function, and somewhere there's also an unfinished attempt to provide DIV() and MOD() as functions of two variables.

And there's also a round-up of the multiplication bug in the BASIC interpreter. :mrgreen:
User avatar
srowe
Vic 20 Scientist
Posts: 1356
Joined: Mon Jun 16, 2014 3:19 pm

Re: Where are the addresses for the float routines in the VIC20?

Post by srowe »

You might find this booklet useful

http://69.60.118.202/books/vic20/VIC-20 ... Abacus.zip

It has a long section on floating point routines.
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: Where are the addresses for the float routines in the VIC20?

Post by chysn »

srowe wrote: Thu Feb 20, 2020 1:20 pm You might find this booklet useful

http://69.60.118.202/books/vic20/VIC-20 ... Abacus.zip

It has a long section on floating point routines.
Thank you. Yes, this was an important resource when I was learning about it. Beware the typo on page 40! The string address should be stored in $22 and $23, not $71 and $72 as shown in the code. The other thing is that you don't really need to know how long the string is. The ASCFLT at $DFC3 stops working when it encounters a non-numeric value*. So LDA #$FF works fine if you don't want to be bothered by figuring out the length.

In this book, the string-to-FAC conversion taps into BASIC's VAL() function. I've been using ASCFLT directly, like this:

Code: Select all

STY $7A
STA $7B
JSR $0079
JSR $DCF3
RTS
with preparation for this routine being to set Y and A to the low and high bytes of the string's location. The downside of this is that BASIC isn't very happy with where CHRGET winds up, so I've been ending my programs with a warm start (JMP $E467).

* Except for spaces. I learned by going through the ROM disassembly that everything that parses a floating point number does it through CHRGET, which basically ignores spaces. So spaces in numbers are just glossed over (for example, "5 . 6" is the same as "5.6")
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
Post Reply