Useful math for noob coders


Enlighted (5938)

ARTRAG's picture

18-06-2017, 12:39

By sd_snatcher

Prophet (2727)

sd_snatcher's picture

18-06-2017, 13:18

Wonderful article! It shows algorithms for many of the game coding needs.

By DarkSchneider

Hero (598)

DarkSchneider's picture

18-06-2017, 19:50

Mapping could be a bit heavy for the poor z80 Tongue

I remember to read some of these interesting articles in the time of GBA, including generating the LUT for trigonometrical and multiple ways to use them (by steps, interpolating). Unfortunately too much time passed and lost the track Sad
About what is says about fixed mul and div, that is not exactly as says. The result is it adds the decimal part precision to the result. So if you multiply 2 Q16 numbers the result is a Q32 number (a number that use 32 bits for decimal). Then what it says is true, as it uses an integer that is a Q0 FP number, so it doesn't add bits to the FP precision requirements, but it would be good if it'd explain the reason. In fact you could adjust the operands removing some bits of decimal part to fit into your type. I.e. we want yo multiply 2 Q8 numbers and fit into Q8, we could >>4 both and then multiply. Take care as it can overflow, but that is another story.
For division I think is different but don't remember at this moment.

Someone knows a good implementation of fixed-point for z80? What I find are Q8 because use a 16bit register like HL for the purpose as the "easy way". But I'd need more than 8 bits for the integer part. I think that the ideal one would be use 16bit for integer and another 8 for decimal, using the carry operations.
On PC is much easier I already have a fixed-point implementation but then we have 32bit registers and can expando to 64 using long not taking much work, not portable to MSX as is.


Enlighted (5938)

ARTRAG's picture

19-06-2017, 16:59

DarkSchneider wrote:

Mapping could be a bit heavy for the poor z80 Tongue

It can be done offline (maybe by a pc), you have plenty of pages for pre-computed animations.
In this gyruss demo the tunnel is computed offline

By ricbit

Champion (409)

ricbit's picture

20-06-2017, 19:05

I have written once a true type font renderer for MSX. In that source code there are a bunch of fixed point fixed point routines.

My MSX profile