Floating point in Kernal?

Chat about anything CX16 related that doesn't fit elsewhere
Post Reply
Dacobi
Posts: 292
Joined: Sun Dec 19, 2021 1:44 am
Location: Samsø, Denmark
Contact:

Floating point in Kernal?

Post by Dacobi »


I'm trying to compile a program using; https://github.com/mrdudz/cc65-floatlib

I've changed system type to cx16 in the makefile and it does compile.

But if I try to do anything with float besides print the sizeof float the program crashes.

Does the x16 Kernal have the built in floating point calls?

(Edit) Nevermind. I found it in the Programming Reference (Floating Point Library)

voidstar
Posts: 498
Joined: Thu Apr 15, 2021 8:05 am

Floating point in Kernal?

Post by voidstar »


 

Hey, that's really neat (to have that spelled out in the docs).

cc65 doesn't have a floating point library.  And sure, a lot of games here won't ever really need floating point.  

 

One "application" for floating point that I tried doing on the Commodore PET was a scale "model" of the solar system -- which involves some really big numbers, depending on your units.  There may be a non-integer way to do it, but I wanted the program to do this:  if I have a fence 50 feet long, at what distances do I paint the planets to keep an accurate 1:1 scale of the actual solar system?    Again, maybe there is a way to do that with integers  (maybe like early business software, you multiply by a hundred so the cent portion becomes part of the integer).

 

Anyway, that was the problem-challenge.  Being able to access these existing floating routines in ROM saves a lot of code-space (where you don't have to replicate all that conversion stuff in your own code, although I'm not sure about the performance).   A solution example to this problem in both BASIC and C and ASM might be a good tutorial on using the system - it's also a small enough problem, to think about separating "business logic" (calculating the distances) from however you want to present the interface (asking the length of your fence, and showing the resulting scaled distances).

 

The BASIC and C samples that I put together are here:   (the C sample won't work for cc65 since it doesn't support the float type -- but one could retrofit in some ROM BASIC system calls to do the float point)

voidstar78/SolarSystemCalculator: Solar System Calculator (github.com)

 

 

User avatar
desertfish
Posts: 1098
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

Floating point in Kernal?

Post by desertfish »


Prog8 supports floating point math using those kernal's FP routines. It's not using them in the most efficient way possible, but that doesn't really matter. Because doing any sort of floating point calculations is extremely slow, way too slow for most games. Perhaps you can use it for precalculating things or the occasional calculation to set things up, but doing any serious FP math inside a game update loop is probably off the table.

To get an feel of the difference, here is a Prog8 program drawing dots using integers only


 

And here is a more or less equivalent version of that program, using FP math


 

 

Post Reply