Gered
62af8575c6
- rename standard integer types to a more familiar (u)int(8/16/32) - many function/struct renames. i don't _really_ know if what i've done for this is better, but it "feels" better to me. many draw/blit function names are shorter which is nice, at least. kinda important to me because i develop this on a real DOS machine in 80x50 text mode. - add 'extern "C"' blocks to headers for C++ compiler usage - draw/pixel color value arguments for functions should all have been changed to be uint8 instead of a full 32-bit int. feels right, but maybe should've left alone... - small fix to keyboard handler. noticed a problem on one thinkpad laptop. was a result of what i think was a typo in a constant value used during the part of the interrupt handler that tells the keyboard controller the key event was processed - fix uncommon potential crash function return in draw_filled_rect - renamed low-level "direct" assembly functions to "lowlevel_xxx" to be a little bit more explicit about what they are - add some convenience event helper functions for determining event types - add fixed point atan2 - fixed some tabs/spaces inconsistences (should all be spaces now?) - maybe some other minor things i've forgotten
99 lines
2.4 KiB
C
Executable file
99 lines
2.4 KiB
C
Executable file
#ifndef LIBDGL_DGLFIXP_H
|
|
#define LIBDGL_DGLFIXP_H
|
|
|
|
#include "dglcmn.h"
|
|
#include <math.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef int32 fixed;
|
|
|
|
#define FP_INT_SHIFT 16
|
|
#define FP_FLOAT_SHIFT 65536.0f
|
|
|
|
static fixed fix_sin(fixed x);
|
|
static fixed fix_cos(fixed x);
|
|
static fixed fix_tan(fixed x);
|
|
|
|
fixed fix_sqrt(fixed x);
|
|
fixed fix_atan2(fixed y, fixed x);
|
|
|
|
fixed fix_mul(fixed a, fixed b);
|
|
#pragma aux fix_mul = \
|
|
"imul ebx" \
|
|
"shrd eax, edx, 16" \
|
|
parm [eax] [ebx] \
|
|
modify [eax ebx edx];
|
|
|
|
fixed fix_div(fixed a, fixed b);
|
|
#pragma aux fix_div = \
|
|
"cdq" \
|
|
"shld edx, eax, 16" \
|
|
"sal eax, 16" \
|
|
"idiv ebx" \
|
|
parm [eax] [ebx] \
|
|
modify [eax ebx edx];
|
|
|
|
#define FTOFIX(f) ((fixed)((f) * FP_FLOAT_SHIFT))
|
|
#define ITOFIX(i) ((fixed)((i) << FP_INT_SHIFT))
|
|
#define FIXTOF(x) ((float)((x) / FP_FLOAT_SHIFT))
|
|
#define FIXTOI(x) ((int32)(((x) + 0x8000) >> FP_INT_SHIFT))
|
|
|
|
#define FP_1 ITOFIX(1)
|
|
#define FP_2 ITOFIX(2)
|
|
#define FP_3 ITOFIX(3)
|
|
#define FP_4 ITOFIX(4)
|
|
#define FP_5 ITOFIX(5)
|
|
#define FP_6 ITOFIX(6)
|
|
#define FP_7 ITOFIX(7)
|
|
#define FP_8 ITOFIX(8)
|
|
#define FP_9 ITOFIX(9)
|
|
#define FP_10 ITOFIX(10)
|
|
|
|
#define FP_16 ITOFIX(16)
|
|
#define FP_32 ITOFIX(32)
|
|
#define FP_64 ITOFIX(64)
|
|
#define FP_128 ITOFIX(128)
|
|
#define FP_256 ITOFIX(256)
|
|
|
|
#define FP_0_1 FTOFIX(0.1f)
|
|
#define FP_0_2 FTOFIX(0.2f)
|
|
#define FP_0_3 FTOFIX(0.3f)
|
|
#define FP_0_4 FTOFIX(0.4f)
|
|
#define FP_0_5 FTOFIX(0.5f)
|
|
#define FP_0_6 FTOFIX(0.6f)
|
|
#define FP_0_7 FTOFIX(0.7f)
|
|
#define FP_0_8 FTOFIX(0.8f)
|
|
#define FP_0_9 FTOFIX(0.9f)
|
|
|
|
#define FP_0_25 FTOFIX(0.25f)
|
|
#define FP_0_75 FTOFIX(0.75f)
|
|
|
|
#define FP_1_OVER_3 FTOFIX(1.0f / 3.0f)
|
|
#define FP_2_OVER_3 FTOFIX(2.0f / 3.0f)
|
|
|
|
#define FP_PI FTOFIX(3.1415927f)
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
static fixed fix_sin(fixed x) {
|
|
return FTOFIX(sin(FIXTOF(x)));
|
|
}
|
|
|
|
static fixed fix_cos(fixed x) {
|
|
return FTOFIX(cos(FIXTOF(x)));
|
|
}
|
|
|
|
static fixed fix_tan(fixed x) {
|
|
return FTOFIX(tan(FIXTOF(x)));
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|
|
|