Z80 BBCBASIC - Customising floating-point math

Here you can talk about anything related to BBC BASIC, not covered in another category
nockieboy
Posts: 2
Joined: Wed 19 Oct 2022, 07:42

Z80 BBCBASIC - Customising floating-point math

Post by nockieboy »

Hi everyone,

I'm new here, so go easy on me! :D I didn't know where else to ask this, so here I am - apologies if it's in the wrong area.

I need some help/advice from anyone who has gotten their hands dirty with the Z80 assembly source code for BBCBASIC. I'm basically looking to replace the floating-point math routines with calls to my custom-built FPGA FPU in my DIY computer. I've made a multiplier and have tried replacing the FMUL routine in fpp.z80, but the results I'm getting back in BBCBASIC are all 2x what they should be and I can't work out why.

This is a very niche/technical question, I know, but I'm hoping someone out there might have a better understanding of how all the FP routines fit together in BBCBASIC and can give me a clue as to where I'm going wrong.

I've attached my current fpp.z80 module that I've modified. Lines 424-520 are where I've replaced the BBCBASIC fp multiplier with an interface to my hardware FPU.

Any help or thoughts would be appreciated!
You do not have the required permissions to view the files attached to this post.
Hated Moron

Re: Z80 BBCBASIC - Customising floating-point math

Post by Hated Moron »

nockieboy wrote: Wed 19 Oct 2022, 07:48 This is a very niche/technical question, I know, but I'm hoping someone out there might have a better understanding of how all the FP routines fit together in BBCBASIC and can give me a clue as to where I'm going wrong.
Have you checked out this description of the 40-bit (5 byte) floating-point format, which I think is the same as that used by Z80 BBC BASIC? If your calculated values are exactly double what they should be, it would suggest that your exponent byte is off-by-one (I think the 6502 and Z80 formats differ in exactly that way, which could be significant).
nockieboy
Posts: 2
Joined: Wed 19 Oct 2022, 07:42

Re: Z80 BBCBASIC - Customising floating-point math

Post by nockieboy »

Hated Moron wrote: Wed 19 Oct 2022, 16:09 Have you checked out this description of the 40-bit (5 byte) floating-point format, which I think is the same as that used by Z80 BBC BASIC? If your calculated values are exactly double what they should be, it would suggest that your exponent byte is off-by-one (I think the 6502 and Z80 formats differ in exactly that way, which could be significant).
Ahh, yes, it's an off-by-one error. It appears from the page you've linked that I need to subtract 1 from the exponent before returning it to BBCBASIC (it's not even a bit-shift, it's literally a 'subtract one' operation that's required). It's working perfectly now (aside from my FPU being 32-bit, not 40-bit - might widen it by another byte!)

Thanks for the tip, Hated Moron, it set me onto the right path. :D