PVSnesLib  4.6.0
Documentation to code in C or ASM for the Nintendo SNES
Loading...
Searching...
No Matches
fixed.h
1/*---------------------------------------------------------------------------------
2
3 snestypes.h -- fixed points (and a few useful macros)
4
5 Copyright (C) 2025
6 Alekmaul
7
8 This software is provided 'as-is', without any express or implied
9 warranty. In no event will the authors be held liable for any
10 damages arising from the use of this software.
11
12 Permission is granted to anyone to use this software for any
13 purpose, including commercial applications, and to alter it and
14 redistribute it freely, subject to the following restrictions:
15
16 1. The origin of this software must not be misrepresented; you
17 must not claim that you wrote the original software. If you use
18 this software in a product, an acknowledgment in the product
19 documentation would be appreciated but is not required.
20 2. Altered source versions must be plainly marked as such, and
21 must not be misrepresented as being the original software.
22 3. This notice may not be removed or altered from any source
23 distribution.
24
25 fixed point definition inspired by SGDK from Stephane Dallongeville
26 https://github.com/Stephane-D/SGDK/blob/master/inc/maths.h
27---------------------------------------------------------------------------------*/
28#include <snes/snestypes.h>
29
34typedef s16 fx16;
35
36#define FX16_INT_BITS 10
37#define FX16_FRAC_BITS (16 - FX16_INT_BITS)
38#define FX16_INT_MASK (((1 << FX16_INT_BITS) - 1) << FX16_FRAC_BITS)
39#define FX16_FRAC_MASK ((1 << FX16_FRAC_BITS) - 1)
40
47#define FX16(value) ((FX16) ((value) * (1 << FX16_FRAC_BITS)))
48
53#define ifromfx16(value) ((value) >> FX16_FRAC_BITS)
54
59#define dfromfx16(value) ((value) << FX16_FRAC_BITS)
60
65#define fx16mul(val1, val2) ((val1 * val2) >> FX16_FRAC_BITS)
66
71#define fx16div(val1, val2) (((val1 << FX16_FRAC_BITS) / val2);
72
73
Custom types used by libsnes.