Working on fixed point conversion.
This commit is contained in:
parent
7040fff6e7
commit
e33a37b3b6
14 changed files with 609 additions and 217 deletions
14
build.sh
14
build.sh
|
@ -28,8 +28,8 @@ PROJECT=shotel
|
|||
F256=$(readlink -f $(pwd)/../f256)
|
||||
LLVM=${F256}/llvm-mos
|
||||
PATH=${LLVM}/bin:${PATH}
|
||||
CLANG="mos-f256k-clang -I${F256} -I$(pwd)/src -Os -Wall"
|
||||
|
||||
CLANG="mos-f256-clang -I${F256} -I$(pwd)/src -Os -Wall"
|
||||
ROOT=$(pwd)
|
||||
|
||||
# Update f256lib and tools.
|
||||
pushd ${F256}
|
||||
|
@ -41,9 +41,6 @@ popd
|
|||
[[ -d .builddir ]] && rm -rf .builddir
|
||||
mkdir -p .builddir
|
||||
|
||||
# Do not use relative paths.
|
||||
${F256}/overlay 5 $(pwd)/.builddir $(pwd)/src
|
||||
|
||||
pushd .builddir
|
||||
|
||||
cp ../a2-3d/A2-3D2#066000 a2-3d2.bin
|
||||
|
@ -54,10 +51,15 @@ cc -I../src -I${F256} ../tools/scene.c -o scene
|
|||
|
||||
cat a2-3d2.bin scene.3d > embedded.bin
|
||||
|
||||
# Do not use relative paths.
|
||||
${F256}/overlay 5 ${ROOT}/.builddir ${ROOT}/src
|
||||
|
||||
cp ${LLVM}/mos-platform/f256/lib/link.ld f256.ld
|
||||
|
||||
${CLANG} -c main.c
|
||||
${CLANG} -c a23d2.c
|
||||
|
||||
${CLANG} -T ../f256.ld \
|
||||
${CLANG} -T f256.ld \
|
||||
-Wl,-Map=${PROJECT}.map \
|
||||
-o ${PROJECT} \
|
||||
main.o a23d2.o
|
||||
|
|
19
f256.ld
19
f256.ld
|
@ -43,8 +43,8 @@ __block22_lma = (22<<24)|__SLOT_ADDR;
|
|||
__block23_lma = (23<<24)|__SLOT_ADDR;
|
||||
|
||||
/* Stash preloaded binary data */
|
||||
__binarydata_lma = 0x54000; /* Block 42 */
|
||||
__BINARYDATA_SIZE = 0x2C000; /* Size of A2-3D2, 3D/2D data area, and 2 bitmaps. */
|
||||
__embedded_lma = 0x54000; /* Block 42 */
|
||||
__embedded_size = 0x2C000; /* Size of A2-3D2, 3D/2D data area, and 2 bitmaps. */
|
||||
|
||||
MEMORY {
|
||||
block8 : ORIGIN = __block8_lma, LENGTH = __BLOCK_SIZE
|
||||
|
@ -63,7 +63,8 @@ MEMORY {
|
|||
block21 : ORIGIN = __block21_lma, LENGTH = __BLOCK_SIZE
|
||||
block22 : ORIGIN = __block22_lma, LENGTH = __BLOCK_SIZE
|
||||
block23 : ORIGIN = __block23_lma, LENGTH = __BLOCK_SIZE
|
||||
binarydata : ORIGIN = __binarydata_lma, LENGTH = __BINARYDATA_SIZE
|
||||
|
||||
embedded : ORIGIN = __embedded_lma, LENGTH = __embedded_size
|
||||
}
|
||||
|
||||
REGION_ALIAS("c_writeable", ram)
|
||||
|
@ -87,7 +88,7 @@ SECTIONS {
|
|||
.block21 : { *(.block21 .block21.*) } >block21 end_block21 = .;
|
||||
.block22 : { *(.block22 .block22.*) } >block22 end_block22 = .;
|
||||
.block23 : { *(.block23 .block23.*) } >block23 end_block23 = .;
|
||||
.binarydata : { *(.binarydata .binarydata.*) } >binarydata end_binarydata = .;
|
||||
.embedded : { *(.embedded .embedded.*) } >embedded end_embedded = .;
|
||||
}
|
||||
|
||||
OUTPUT_FORMAT {
|
||||
|
@ -104,11 +105,11 @@ OUTPUT_FORMAT {
|
|||
INCLUDE output.ld
|
||||
|
||||
/* Binary Data */
|
||||
SHORT(ORIGIN(binarydata))
|
||||
BYTE(ORIGIN(binarydata)>>16)
|
||||
SHORT(end_binarydata - __binarydata_lma)
|
||||
BYTE((end_binarydata - __binarydata_lma)>>16)
|
||||
TRIM(binarydata)
|
||||
SHORT(ORIGIN(embedded))
|
||||
BYTE(ORIGIN(embedded)>>16)
|
||||
SHORT(end_embedded - __embedded_lma)
|
||||
BYTE((end_embedded - __embedded_lma)>>16)
|
||||
TRIM(embedded)
|
||||
|
||||
/* Launch the program, at _start */
|
||||
SHORT(_start)
|
||||
|
|
|
@ -33,6 +33,9 @@ add_executable(${CMAKE_PROJECT_NAME}
|
|||
src/a23d2.c
|
||||
include/bitmap.h
|
||||
src/bitmap.c
|
||||
include/fmath.h
|
||||
src/fmath.c
|
||||
include/mem.h
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -30,16 +30,6 @@
|
|||
#endif
|
||||
|
||||
|
||||
//#define scdMemCpy memcpy
|
||||
#define scdMemCpy(d,s,l) \
|
||||
({ \
|
||||
volatile byte *dp = (d); \
|
||||
volatile byte *sp = (s); \
|
||||
uint16_t i = 0; \
|
||||
for (i=0; i<(l); i++) *dp++ = *sp++; \
|
||||
})
|
||||
|
||||
|
||||
#define A23D2_FAR_BLOCK 42
|
||||
#define DATABASE_FAR_BLOCK 43
|
||||
|
||||
|
@ -132,18 +122,14 @@ extern uint16_t _drawlistInDatabase;
|
|||
|
||||
extern uint16_t _bytes;
|
||||
extern uint8_t _x1;
|
||||
#define _tdata _x1 // Alias.
|
||||
extern uint8_t _y1;
|
||||
extern uint8_t _x2;
|
||||
extern uint8_t _y2;
|
||||
extern bool _useColor;
|
||||
extern byte _mmu;
|
||||
extern byte _ram;
|
||||
extern float _trig;
|
||||
|
||||
|
||||
void a23d2Cos(void);
|
||||
void a23d2Draw(void);
|
||||
void a23d2Init(void);
|
||||
void a23d2Render(void);
|
||||
void a23d2Sin(void);
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
|
||||
#define HEIGHT 240
|
||||
#define WIDTH 320
|
||||
#define SCALE 1.25 // Scale factor for 256->320
|
||||
|
||||
|
||||
// ***FIX*** Somehow we're getting invalid drawing coordinates from A2-3D2.
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "fmath.h"
|
||||
|
||||
|
||||
#define PLANE_HEIGHT 20
|
||||
|
@ -45,49 +45,50 @@ typedef struct airplaneS {
|
|||
bool ignition;
|
||||
bool engine;
|
||||
int16_t rpm;
|
||||
float hSpeed;
|
||||
float vSpeed;
|
||||
float deltaZ;
|
||||
float efAOF;
|
||||
float climbRate;
|
||||
fixT FhSpeed;
|
||||
fixT FvSpeed;
|
||||
fixT FdeltaZ;
|
||||
fixT FefAOF;
|
||||
fixT FclimbRate;
|
||||
bool airborne;
|
||||
bool stall;
|
||||
bool brake;
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
int16_t z;
|
||||
double pitch; // 0 to 255
|
||||
double yaw; // 0 to 255
|
||||
double roll; // 0 to 255
|
||||
fixT Fpitch; // 0 to 255
|
||||
fixT Fyaw; // 0 to 255
|
||||
fixT Froll; // 0 to 255
|
||||
// Flight model stuff below here.
|
||||
float tmpX;
|
||||
float tmpY;
|
||||
float tmpZ;
|
||||
float newX;
|
||||
float newY;
|
||||
float newZ;
|
||||
float iSpeed;
|
||||
float lSpeed;
|
||||
float hAccel;
|
||||
float lVeloc;
|
||||
float gVeloc;
|
||||
float AOA;
|
||||
float torque;
|
||||
float torque2;
|
||||
fixT FtmpX;
|
||||
fixT FtmpY;
|
||||
fixT FtmpZ;
|
||||
fixT FnewX;
|
||||
fixT FnewY;
|
||||
fixT FnewZ;
|
||||
fixT FiSpeed;
|
||||
fixT FlSpeed;
|
||||
fixT FhAccel;
|
||||
fixT FlVeloc;
|
||||
fixT FgVeloc;
|
||||
fixT FAOA;
|
||||
fixT Ftorque;
|
||||
fixT Ftorque2;
|
||||
uint16_t loopTime; // Milliseconds
|
||||
// Used to be static. Need preserved.
|
||||
double dPitch;
|
||||
double dYaw;
|
||||
double dRoll;
|
||||
float collectX;
|
||||
float collectY;
|
||||
float collectZ;
|
||||
fixT FdPitch;
|
||||
fixT FdYaw;
|
||||
fixT FdRoll;
|
||||
fixT FcollectX;
|
||||
fixT FcollectY;
|
||||
fixT FcollectZ;
|
||||
} airplaneT;
|
||||
|
||||
|
||||
extern airplaneT _plane;
|
||||
|
||||
|
||||
void initAircraft(void);
|
||||
void resetAircraft(void);
|
||||
void updateAircraft(void);
|
||||
|
||||
|
|
86
pc/include/fmath.h
Normal file
86
pc/include/fmath.h
Normal file
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Copyright (c) 2024 Scott Duensing, scott@kangaroopunch.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FMATH_H
|
||||
#define FMATH_H
|
||||
|
||||
|
||||
#define FAUX_FIXED
|
||||
|
||||
|
||||
#ifdef FAUX_FIXED
|
||||
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
||||
// Fake fixed point for debugging while porting.
|
||||
typedef double fixT;
|
||||
|
||||
|
||||
#define fixAdd(x, y) ((x) + (y))
|
||||
#define fixAtan(x) atan(x)
|
||||
#define fixCos(x) cos(x)
|
||||
#define fixDegs(x) ((x) * 180 / M_PI)
|
||||
#define fixDiv(x, y) ((x) / (y))
|
||||
#define fixMul(x, y) ((x) * (y))
|
||||
#define fixSin(x) sin(x)
|
||||
#define fixSub(x, y) ((x) - (y))
|
||||
#define fixToF(x) (x)
|
||||
#define fixToI(x) ((int)(x))
|
||||
#define fToFix(x) (x)
|
||||
#define iToFix(x) ((fixT)(x))
|
||||
|
||||
|
||||
#else // FAUX_FIXED
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
// Ratios for converting between radians and fixed point angles.
|
||||
#define fixToRad 1608 // 2pi/256
|
||||
#define radToFix 2670177 // 256/2pi
|
||||
|
||||
|
||||
typedef int32_t fixT;
|
||||
|
||||
|
||||
fixT fixAdd(fixT x, fixT y);
|
||||
fixT fixAtan(fixT x);
|
||||
fixT fixCos(fixT x);
|
||||
//fixT fixDegs(fixT x);
|
||||
fixT fixDiv(fixT x, fixT y);
|
||||
fixT fixMul(fixT x, fixT y);
|
||||
fixT fixSin(fixT x);
|
||||
fixT fixSub(fixT x, fixT y);
|
||||
double fixToF(fixT x);
|
||||
int16_t fixToI(fixT x);
|
||||
fixT fToFix(double x);
|
||||
fixT iToFix(int16_t x);
|
||||
|
||||
|
||||
#endif // FAUX_FIXED
|
||||
|
||||
|
||||
#endif // FMATH_H
|
48
pc/include/mem.h
Normal file
48
pc/include/mem.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2024 Scott Duensing, scott@kangaroopunch.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MEM_H
|
||||
#define MEM_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#define scdMemCpy(d,s,l) \
|
||||
({ \
|
||||
volatile byte *dp = (d); \
|
||||
volatile byte *sp = (s); \
|
||||
uint32_t i = 0; \
|
||||
for (i=0; i<(l); i++) *dp++ = *sp++; \
|
||||
})
|
||||
|
||||
|
||||
#define scdMemSet(d,v,l) \
|
||||
({ \
|
||||
volatile byte *dp = (d); \
|
||||
uint32_t i = 0; \
|
||||
for (i=0; i<(l); i++) *dp++ = v; \
|
||||
})
|
||||
|
||||
|
||||
#endif // MEM_H
|
|
@ -27,6 +27,7 @@
|
|||
#include "a23d2bin.h"
|
||||
#include "bitmap.h"
|
||||
#include "flight.h"
|
||||
#include "mem.h"
|
||||
|
||||
#include "a23d2.h"
|
||||
|
||||
|
@ -35,9 +36,18 @@
|
|||
byte _RAM[0x10000]; // 6502 memory.
|
||||
VrEmu6502 *_v6502 = NULL;
|
||||
|
||||
// Externs.
|
||||
uint16_t _drawlistInDatabase;
|
||||
float _trig;
|
||||
uint8_t _x1;
|
||||
|
||||
|
||||
#define SCALE 1.25 // Scale factor for 256->320
|
||||
|
||||
#define SCREEN3DX 255 // Resolution of A2-3D2 renderer.
|
||||
#define SCREEN3DY 233 // These get scaled up to full-screen.
|
||||
|
||||
|
||||
byte _scaleX[SCREEN3DX + 1];
|
||||
byte _scaleY[SCREEN3DY + 1];
|
||||
|
||||
|
||||
void jsr(uint16_t addr);
|
||||
|
@ -46,20 +56,6 @@ byte memoryRead(uint16_t addr, bool isDebug);
|
|||
void memoryWrite(uint16_t addr, byte value);
|
||||
|
||||
|
||||
void a23d2Cos(void) {
|
||||
// Map 0-359 into 0-255.
|
||||
_tdata = _tdata % 359;
|
||||
_x1 = (360/256) * _tdata;
|
||||
|
||||
// Call COSEX.
|
||||
_RAM[A23D2_TDATA] = _x1;
|
||||
jsr(A23D2_COSEX);
|
||||
|
||||
// Convert to float.
|
||||
_trig = (float)(_RAM[A23D2_TDATA] + _RAM[A23D2_TDATA + 1] * 256) / 32768;
|
||||
}
|
||||
|
||||
|
||||
void a23d2Draw(void) {
|
||||
uint16_t pointer = DRAWLIST_P0;
|
||||
int16_t x1;
|
||||
|
@ -76,16 +72,14 @@ void a23d2Draw(void) {
|
|||
y1 = 255 - ((int8_t)_RAM[pointer++] + 128);
|
||||
x2 = (int8_t)_RAM[pointer++] + 128;
|
||||
y2 = 255 - ((int8_t)_RAM[pointer++] + 128);
|
||||
bitmapLine(x1 * SCALE, y1 / SCALE, x2 * SCALE, y2 / SCALE);
|
||||
bitmapLine(x1 + _scaleX[x1], _scaleY[y1], x2 + _scaleX[x2], _scaleY[y2]);
|
||||
continue;
|
||||
|
||||
// Point.
|
||||
case PNT2D:
|
||||
x1 = (int8_t)_RAM[pointer++] + 128;
|
||||
y1 = 255 - ((int8_t)_RAM[pointer++] + 128);
|
||||
x1 *= SCALE;
|
||||
y1 /= SCALE;
|
||||
bitmapPutPixelIOSet(x1, y1);
|
||||
bitmapPutPixelIOSet(x1 + _scaleX[x1], _scaleY[y1]);
|
||||
continue;
|
||||
|
||||
// Set Color.
|
||||
|
@ -114,19 +108,19 @@ void a23d2Init(void) {
|
|||
uint16_t bytes;
|
||||
|
||||
// Clear VM RAM.
|
||||
memset(_RAM, 0, 0x10000);
|
||||
scdMemSet(_RAM, 0, 0x10000);
|
||||
|
||||
// Create our VM.
|
||||
_v6502 = vrEmu6502New(CPU_W65C02, memoryRead, memoryWrite);
|
||||
|
||||
// Copy A2-3D2 into 6502 RAM.
|
||||
memcpy(&_RAM[0x6000], a23d2bin, a23d2bin_len);
|
||||
scdMemCpy(&_RAM[0x6000], a23d2bin, a23d2bin_len);
|
||||
|
||||
// Initialize A2-3D2 so we can use the "fast entry point" (NXTPT) when rendering.
|
||||
bytes = A23D2_TEST_DATABASE;
|
||||
_RAM[bytes++] = SCRSZ; // Screen size. 256x240. Center is 0,0. We're going to scale this up.
|
||||
_RAM[bytes++] = 255; // Scales up to 320.
|
||||
_RAM[bytes++] = 233; // Scales up to 193 (leaves 46 pixels for a control panel).
|
||||
_RAM[bytes++] = SCREEN3DX; // Scales up to 320.
|
||||
_RAM[bytes++] = SCREEN3DY; // Scales up to 193 (leaves 46 pixels for a control panel).
|
||||
_RAM[bytes++] = 0;
|
||||
_RAM[bytes++] = 0;
|
||||
_RAM[bytes++] = END; // Setup complete!
|
||||
|
@ -146,6 +140,12 @@ void a23d2Init(void) {
|
|||
_camera->z = 10500;
|
||||
_camera->p = 0;
|
||||
_camera->h = 0;
|
||||
|
||||
// Build scaling tables for stretching 3D scene to fill display.
|
||||
// X table is the difference needed. Allows us to store it in one byte.
|
||||
// Y table is the actual coordinate since it fits in a byte anyway.
|
||||
for (bytes=0; bytes<=SCREEN3DX; bytes++) _scaleX[bytes] = (bytes * SCALE) - bytes;
|
||||
for (bytes=0; bytes<=SCREEN3DY; bytes++) _scaleY[bytes] = (bytes / SCALE);
|
||||
}
|
||||
|
||||
|
||||
|
@ -169,20 +169,6 @@ void a23d2Shutdown(void) {
|
|||
}
|
||||
|
||||
|
||||
void a23d2Sin(void) {
|
||||
// Map 0-359 into 0-255.
|
||||
_tdata = _tdata % 359;
|
||||
_x1 = (360/256) * _tdata;
|
||||
|
||||
// Call COSEX.
|
||||
_RAM[A23D2_TDATA] = _x1;
|
||||
jsr(A23D2_SINEX);
|
||||
|
||||
// Convert to float.
|
||||
_trig = (float)(_RAM[A23D2_TDATA] + _RAM[A23D2_TDATA + 1] * 256) / 32768;
|
||||
}
|
||||
|
||||
|
||||
void jsr(uint16_t addr) {
|
||||
int32_t depth = 0;
|
||||
//int32_t instructions = 0;
|
||||
|
@ -289,7 +275,7 @@ void landscape(void) {
|
|||
l = 3000;
|
||||
x = skip * 3.5;
|
||||
z = skip * 3.5;
|
||||
printf("%dx%d\n", x, z);
|
||||
//printf("%dx%d\n", x, z);
|
||||
|
||||
db[bytes++] = STCOL;
|
||||
db[bytes++] = 7; // Light Grey
|
||||
|
|
184
pc/src/flight.c
184
pc/src/flight.c
|
@ -21,65 +21,16 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "flight.h"
|
||||
#include "a23d2.h"
|
||||
#include "mem.h"
|
||||
|
||||
#include "flight.h"
|
||||
|
||||
|
||||
// Extern.
|
||||
airplaneT _plane;
|
||||
|
||||
|
||||
#define SEGMENT_MATH
|
||||
|
||||
|
||||
#define PI 3.1415
|
||||
|
||||
#define Rads(d) (((d) < 0 ? (d) + 360 : (d)) * (PI / 180))
|
||||
#define Degs(r) ((r) * (180 / PI))
|
||||
|
||||
// https://www.reddit.com/r/programming/comments/3e7ghi/discrete_arctan_in_6502
|
||||
#define ATAN_SPLINE_C0 (double)(-0.14380550980765507115) // 3pi/4 - 5/2
|
||||
#define ATAN_SPLINE_C1 (double)(-0.07079632679489661923) // 3/2 - pi/2
|
||||
double ourAtan(double x){
|
||||
if (x >= 0) {
|
||||
if ( x<= 1) {
|
||||
return x + (ATAN_SPLINE_C0 + ATAN_SPLINE_C1 * x) * x * x;
|
||||
} else {
|
||||
x = 1 / x;
|
||||
return PI / 2 - (x + (ATAN_SPLINE_C0 + ATAN_SPLINE_C1 * x) * x * x);
|
||||
}
|
||||
} else {
|
||||
if (x >= -1) {
|
||||
return x - (ATAN_SPLINE_C0 - ATAN_SPLINE_C1 * x) * x * x;
|
||||
} else {
|
||||
x = -1 / x;
|
||||
return (x + (ATAN_SPLINE_C0 + ATAN_SPLINE_C1 * x) * x * x) - PI / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
float cosD(float d) {
|
||||
return cos(Rads(d));
|
||||
/*
|
||||
// Map 0-359 into 0-255.
|
||||
_tdata = (int)d % 359;
|
||||
a23d2Cos();
|
||||
return _trig;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
float sinD(float d) {
|
||||
return sin(Rads(d));
|
||||
/*
|
||||
// Map 0-359 into 0-255.
|
||||
_tdata = (int)d % 359;
|
||||
a23d2Sin();
|
||||
return _trig;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
#define SEGMENT_FLIGHT_MODEL_1
|
||||
|
||||
|
||||
|
@ -103,69 +54,101 @@ void lightPlane(void) {
|
|||
|
||||
// Flight model. Flight Dynamics.
|
||||
// Calculate speed from RPM.
|
||||
_plane.iSpeed = _plane.rpm / 17.5;
|
||||
//_plane.iSpeed = _plane.rpm / 17.5;
|
||||
_plane.FiSpeed = fixDiv(iToFix(_plane.rpm), fToFix(17.5));
|
||||
// Modify speed by pitch.
|
||||
_plane.iSpeed += (_plane.pitch * 1.5);
|
||||
//_plane.iSpeed += (_plane.pitch * 1.5);
|
||||
_plane.FiSpeed = fixAdd(_plane.FiSpeed, fixMul(_plane.Fpitch, fToFix(1.5)));
|
||||
// Horizontal acceleration - thrust.
|
||||
_plane.hAccel = ((_plane.rpm * (_plane.iSpeed - _plane.hSpeed)) / 10000);
|
||||
_plane.hAccel /= 1000;
|
||||
_plane.hAccel *= _plane.loopTime;
|
||||
//_plane.hAccel = ((_plane.rpm * (_plane.iSpeed - _plane.hSpeed)) / 10000);
|
||||
//_plane.hAccel /= 1000;
|
||||
//_plane.hAccel *= _plane.loopTime;
|
||||
_plane.FtmpX = fixSub(_plane.FiSpeed, _plane.FhSpeed);
|
||||
_plane.FtmpX = fixMul(iToFix(_plane.rpm), _plane.FtmpX);
|
||||
_plane.FhAccel = fixDiv(_plane.FtmpX, iToFix(10000));
|
||||
_plane.FhAccel = fixDiv(_plane.FhAccel, iToFix(1000));
|
||||
_plane.FhAccel = fixMul(_plane.FhAccel, iToFix(_plane.loopTime));
|
||||
if (_plane.brake && !_plane.airborne) {
|
||||
// Handle brakes.
|
||||
if (_plane.hSpeed > 0) {
|
||||
_plane.hSpeed -= 1;
|
||||
if (_plane.FhSpeed > 0) {
|
||||
//_plane.hSpeed -= 1;
|
||||
_plane.FhSpeed = fixSub(_plane.FhSpeed, iToFix(1));
|
||||
} else {
|
||||
_plane.hSpeed = 0;
|
||||
//_plane.hSpeed = 0;
|
||||
_plane.FhSpeed = iToFix(0);
|
||||
}
|
||||
} else {
|
||||
// Accelerate normally.
|
||||
_plane.hSpeed += _plane.hAccel;
|
||||
//_plane.hSpeed += _plane.hAccel;
|
||||
_plane.FhSpeed = fixAdd(_plane.FhSpeed, _plane.FhAccel);
|
||||
}
|
||||
// Force speed to range -1..1.
|
||||
_plane.lSpeed = (_plane.hSpeed / 65) - 1;
|
||||
if (_plane.lSpeed > 1) _plane.lSpeed = 1;
|
||||
//_plane.lSpeed = (_plane.hSpeed / 65) - 1;
|
||||
_plane.FlSpeed = fixSub(fixDiv(_plane.FhSpeed, iToFix(65)), iToFix(1));
|
||||
//if (_plane.lSpeed > 1) _plane.lSpeed = 1;
|
||||
if (_plane.FlSpeed > iToFix(1)) _plane.FlSpeed = iToFix(1);
|
||||
// Lift curve.
|
||||
_plane.lVeloc = Degs(ourAtan(_plane.lSpeed));
|
||||
//_plane.lVeloc = Degs(ourAtan(_plane.lSpeed));
|
||||
_plane.FlVeloc = fixDegs(fixAtan(_plane.FlSpeed));
|
||||
// Force lift to range 0..90.
|
||||
_plane.lVeloc += 45;
|
||||
//_plane.lVeloc += 45;
|
||||
_plane.FlVeloc = fixAdd(_plane.FlVeloc, 45);
|
||||
// Shift range to 0..-17.
|
||||
_plane.lVeloc /= 5.29;
|
||||
//_plane.lVeloc /= 5.29;
|
||||
_plane.FlVeloc = fixDiv(_plane.FlVeloc, 5.29);
|
||||
// Multiply by pitch modifier.
|
||||
_plane.lVeloc *= (-(_plane.pitch * 0.157) + 1);
|
||||
//_plane.lVeloc *= (-(_plane.pitch * 0.157) + 1);
|
||||
_plane.FlVeloc = fixAdd(_plane.FlVeloc, fixAdd(-(fixMul(_plane.Fpitch, fToFix(0.157))), iToFix(1)));
|
||||
// Time slice.
|
||||
_plane.lVeloc /= 1000;
|
||||
_plane.lVeloc *= _plane.loopTime;
|
||||
//_plane.lVeloc /= 1000;
|
||||
//_plane.lVeloc *= _plane.loopTime;
|
||||
_plane.FlVeloc = fixDiv(_plane.FlVeloc, 1000);
|
||||
_plane.FlVeloc = fixAdd(_plane.FlVeloc, _plane.loopTime);
|
||||
// Gravity.
|
||||
_plane.gVeloc = _plane.loopTime * (-16.0 / 1000); // -16.0 is ft/sec for gravity.
|
||||
//_plane.gVeloc = _plane.loopTime * (-16.0 / 1000); // -16.0 is ft/sec for gravity.
|
||||
_plane.FgVeloc = fixMul(iToFix(_plane.loopTime), fToFix(-0.016)); // -16.0 is ft/sec for gravity.
|
||||
// Sum vertical velocity.
|
||||
_plane.vSpeed = _plane.gVeloc + _plane.lVeloc;
|
||||
//_plane.vSpeed = _plane.gVeloc + _plane.lVeloc;
|
||||
_plane.FvSpeed = fixAdd(_plane.FgVeloc, _plane.FlVeloc);
|
||||
// No vertical speed if we're on the ground.
|
||||
if ((!_plane.airborne) && (_plane.vSpeed < 0)) _plane.vSpeed = 0;
|
||||
if ((!_plane.airborne) && (_plane.FvSpeed < 0)) _plane.FvSpeed = 0;
|
||||
// Save climb rate in ft/min.
|
||||
_plane.climbRate = _plane.vSpeed / _plane.loopTime;
|
||||
_plane.climbRate *= 60000L;
|
||||
//_plane.climbRate = _plane.vSpeed / _plane.loopTime;
|
||||
//_plane.climbRate *= 60000L;
|
||||
_plane.FclimbRate = fixDiv(_plane.FvSpeed, iToFix(_plane.loopTime));
|
||||
_plane.FclimbRate = fixMul(_plane.FclimbRate, iToFix(60000L)); //***TODO*** This long could be an issue.
|
||||
// Expand to ft/hr.
|
||||
_plane.deltaZ = _plane.hSpeed * 5280;
|
||||
//_plane.deltaZ = _plane.hSpeed * 5280;
|
||||
_plane.FdeltaZ = fixMul(_plane.FhSpeed, iToFix(5280));
|
||||
// Get ft/ms.
|
||||
_plane.deltaZ /= 3600000L;
|
||||
_plane.deltaZ *= _plane.loopTime;
|
||||
//_plane.deltaZ /= 3600000L;
|
||||
//_plane.deltaZ *= _plane.loopTime;
|
||||
_plane.FdeltaZ = fixDiv(_plane.FdeltaZ, iToFix(3600000L)); //***TODO*** This long could be an issue.
|
||||
_plane.FdeltaZ = fixMul(_plane.FdeltaZ, iToFix(_plane.loopTime));
|
||||
// Find effective angle of flight.
|
||||
if (_plane.deltaZ) {
|
||||
_plane.efAOF = -(ourAtan(_plane.vSpeed / _plane.deltaZ));
|
||||
if (_plane.FdeltaZ) {
|
||||
//_plane.efAOF = -(ourAtan(_plane.vSpeed / _plane.deltaZ));
|
||||
_plane.FefAOF = -(fixAtan(fixDiv(_plane.FvSpeed, _plane.FdeltaZ)));
|
||||
} else {
|
||||
_plane.efAOF = -(ourAtan(_plane.vSpeed));
|
||||
//_plane.efAOF = -(ourAtan(_plane.vSpeed));
|
||||
_plane.FefAOF = -(fixAtan(_plane.FvSpeed));
|
||||
}
|
||||
// Convert to degrees.
|
||||
_plane.AOA = Degs(_plane.efAOF);
|
||||
//_plane.AOA = Degs(_plane.efAOF);
|
||||
_plane.FAOA = fixDegs(_plane.FefAOF);
|
||||
// Handle stalling.
|
||||
if (((_plane.pitch < _plane.AOA) && (_plane.AOA < 0)) && (_plane.hSpeed < 40)) {
|
||||
if ((_plane.pitch - _plane.AOA) < -20) _plane.stall = true;
|
||||
//if (((_plane.pitch < _plane.AOA) && (_plane.AOA < 0)) && (_plane.hSpeed < 40)) {
|
||||
if (((_plane.Fpitch < _plane.FAOA) && (_plane.FAOA < iToFix(0))) && (_plane.FhSpeed < iToFix(40))) {
|
||||
//if ((_plane.pitch - _plane.AOA) < -20) _plane.stall = true;
|
||||
if (fixSub(_plane.Fpitch, _plane.FAOA) < iToFix(-20)) _plane.stall = true;
|
||||
}
|
||||
if (_plane.stall) {
|
||||
if (_plane.pitch > 30) {
|
||||
//if (_plane.pitch > 30) {
|
||||
if (_plane.Fpitch > iToFix(30)) {
|
||||
_plane.stall = false;
|
||||
} else {
|
||||
_plane.pitch++;
|
||||
//_plane.pitch++;
|
||||
_plane.Fpitch = fixAdd(_plane.Fpitch, iToFix(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -176,17 +159,23 @@ void lightPlane(void) {
|
|||
|
||||
void lightPlane2(void) {
|
||||
// Flight model. Inertial Damping.
|
||||
if (_plane.dPitch) {
|
||||
_plane.dPitch -= _plane.dPitch / 10;
|
||||
if (((_plane.dPitch > 0) && (_plane.dPitch < 0.01)) || ((_plane.dPitch < 0) && (_plane.dPitch > -0.01))) _plane.dPitch = 0;
|
||||
if (_plane.FdPitch != iToFix(0)) {
|
||||
//_plane.dPitch -= _plane.dPitch / 10;
|
||||
_plane.FdPitch = fixSub(_plane.FdPitch, fixDiv(_plane.FdPitch, iToFix(10)));
|
||||
//if (((_plane.dPitch > 0) && (_plane.dPitch < 0.01)) || ((_plane.dPitch < 0) && (_plane.dPitch > -0.01))) _plane.dPitch = 0;
|
||||
if (((_plane.FdPitch > iToFix(0)) && (_plane.FdPitch < fToFix(0.01))) || ((_plane.FdPitch < iToFix(0)) && (_plane.FdPitch > fToFix(-0.01)))) _plane.FdPitch = iToFix(0);
|
||||
}
|
||||
if (_plane.dYaw) {
|
||||
_plane.dYaw -= _plane.dYaw / 10;
|
||||
if (((_plane.dYaw > 0) && (_plane.dYaw < 0.01)) || ((_plane.dYaw < 0) && (_plane.dYaw > -0.01))) _plane.dYaw = 0;
|
||||
if (_plane.FdYaw != iToFix(0)) {
|
||||
//_plane.dYaw -= _plane.dYaw / 10;
|
||||
_plane.FdYaw = fixSub(_plane.FdYaw, fixDiv(_plane.FdYaw, iToFix(10)));
|
||||
//if (((_plane.dYaw > 0) && (_plane.dYaw < 0.01)) || ((_plane.dYaw < 0) && (_plane.dYaw > -0.01))) _plane.dYaw = 0;
|
||||
if (((_plane.FdYaw > iToFix(0)) && (_plane.FdYaw < fToFix(0.01))) || ((_plane.FdYaw < iToFix(0)) && (_plane.FdYaw > fToFix(-0.01)))) _plane.FdYaw = iToFix(0);
|
||||
}
|
||||
if (_plane.dRoll) {
|
||||
_plane.dRoll -= _plane.dRoll / 10;
|
||||
if (((_plane.dRoll > 0) && (_plane.dRoll < 0.01)) || ((_plane.dRoll < 0) && (_plane.dRoll > -0.01))) _plane.dRoll = 0;
|
||||
if (_plane.FdRoll != iToFix(0)) {
|
||||
//_plane.dRoll -= _plane.dRoll / 10;
|
||||
_plane.FdRoll = fixSub(_plane.FdRoll, fixDiv(_plane.FdRoll, iToFix(10)));
|
||||
//if (((_plane.dRoll > 0) && (_plane.dRoll < 0.01)) || ((_plane.dRoll < 0) && (_plane.dRoll > -0.01))) _plane.dRoll = 0;
|
||||
if (((_plane.FdRoll > iToFix(0)) && (_plane.FdRoll < fToFix(0.01))) || ((_plane.FdRoll < iToFix(0)) && (_plane.FdRoll > fToFix(-0.01)))) _plane.FdRoll = iToFix(0);
|
||||
}
|
||||
|
||||
// Flight model. Rate of Change.
|
||||
|
@ -299,9 +288,12 @@ void moveAircraft(void) {
|
|||
}
|
||||
|
||||
|
||||
#define SEGMENT_SETUP
|
||||
|
||||
|
||||
void resetAircraft(void) {
|
||||
// Initialize airplane.
|
||||
memset(&_plane, 0, sizeof(airplaneT));
|
||||
scdMemSet((byte *)&_plane, 0, sizeof(airplaneT));
|
||||
|
||||
_plane.brake = true;
|
||||
_plane.loopTime = 40;
|
||||
|
|
287
pc/src/fmath.c
Normal file
287
pc/src/fmath.c
Normal file
|
@ -0,0 +1,287 @@
|
|||
/*
|
||||
* Copyright (c) 2024 Scott Duensing, scott@kangaroopunch.com
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#include "fmath.h"
|
||||
|
||||
|
||||
#ifndef FAUX_FIXED
|
||||
|
||||
|
||||
// Shamelessly (mostly) stolen from Allegro 4.2.2.
|
||||
// https://github.com/msikma/allegro-4.2.2-xc
|
||||
|
||||
|
||||
// Fixed point (16.16) cosines for a full circle (0-255)
|
||||
fixT _cos_tbl[512] = {
|
||||
65536L, 65531L, 65516L, 65492L, 65457L, 65413L, 65358L, 65294L,
|
||||
65220L, 65137L, 65043L, 64940L, 64827L, 64704L, 64571L, 64429L,
|
||||
64277L, 64115L, 63944L, 63763L, 63572L, 63372L, 63162L, 62943L,
|
||||
62714L, 62476L, 62228L, 61971L, 61705L, 61429L, 61145L, 60851L,
|
||||
60547L, 60235L, 59914L, 59583L, 59244L, 58896L, 58538L, 58172L,
|
||||
57798L, 57414L, 57022L, 56621L, 56212L, 55794L, 55368L, 54934L,
|
||||
54491L, 54040L, 53581L, 53114L, 52639L, 52156L, 51665L, 51166L,
|
||||
50660L, 50146L, 49624L, 49095L, 48559L, 48015L, 47464L, 46906L,
|
||||
46341L, 45769L, 45190L, 44604L, 44011L, 43412L, 42806L, 42194L,
|
||||
41576L, 40951L, 40320L, 39683L, 39040L, 38391L, 37736L, 37076L,
|
||||
36410L, 35738L, 35062L, 34380L, 33692L, 33000L, 32303L, 31600L,
|
||||
30893L, 30182L, 29466L, 28745L, 28020L, 27291L, 26558L, 25821L,
|
||||
25080L, 24335L, 23586L, 22834L, 22078L, 21320L, 20557L, 19792L,
|
||||
19024L, 18253L, 17479L, 16703L, 15924L, 15143L, 14359L, 13573L,
|
||||
12785L, 11996L, 11204L, 10411L, 9616L, 8820L, 8022L, 7224L,
|
||||
6424L, 5623L, 4821L, 4019L, 3216L, 2412L, 1608L, 804L,
|
||||
0L, -804L, -1608L, -2412L, -3216L, -4019L, -4821L, -5623L,
|
||||
-6424L, -7224L, -8022L, -8820L, -9616L, -10411L, -11204L, -11996L,
|
||||
-12785L, -13573L, -14359L, -15143L, -15924L, -16703L, -17479L, -18253L,
|
||||
-19024L, -19792L, -20557L, -21320L, -22078L, -22834L, -23586L, -24335L,
|
||||
-25080L, -25821L, -26558L, -27291L, -28020L, -28745L, -29466L, -30182L,
|
||||
-30893L, -31600L, -32303L, -33000L, -33692L, -34380L, -35062L, -35738L,
|
||||
-36410L, -37076L, -37736L, -38391L, -39040L, -39683L, -40320L, -40951L,
|
||||
-41576L, -42194L, -42806L, -43412L, -44011L, -44604L, -45190L, -45769L,
|
||||
-46341L, -46906L, -47464L, -48015L, -48559L, -49095L, -49624L, -50146L,
|
||||
-50660L, -51166L, -51665L, -52156L, -52639L, -53114L, -53581L, -54040L,
|
||||
-54491L, -54934L, -55368L, -55794L, -56212L, -56621L, -57022L, -57414L,
|
||||
-57798L, -58172L, -58538L, -58896L, -59244L, -59583L, -59914L, -60235L,
|
||||
-60547L, -60851L, -61145L, -61429L, -61705L, -61971L, -62228L, -62476L,
|
||||
-62714L, -62943L, -63162L, -63372L, -63572L, -63763L, -63944L, -64115L,
|
||||
-64277L, -64429L, -64571L, -64704L, -64827L, -64940L, -65043L, -65137L,
|
||||
-65220L, -65294L, -65358L, -65413L, -65457L, -65492L, -65516L, -65531L,
|
||||
-65536L, -65531L, -65516L, -65492L, -65457L, -65413L, -65358L, -65294L,
|
||||
-65220L, -65137L, -65043L, -64940L, -64827L, -64704L, -64571L, -64429L,
|
||||
-64277L, -64115L, -63944L, -63763L, -63572L, -63372L, -63162L, -62943L,
|
||||
-62714L, -62476L, -62228L, -61971L, -61705L, -61429L, -61145L, -60851L,
|
||||
-60547L, -60235L, -59914L, -59583L, -59244L, -58896L, -58538L, -58172L,
|
||||
-57798L, -57414L, -57022L, -56621L, -56212L, -55794L, -55368L, -54934L,
|
||||
-54491L, -54040L, -53581L, -53114L, -52639L, -52156L, -51665L, -51166L,
|
||||
-50660L, -50146L, -49624L, -49095L, -48559L, -48015L, -47464L, -46906L,
|
||||
-46341L, -45769L, -45190L, -44604L, -44011L, -43412L, -42806L, -42194L,
|
||||
-41576L, -40951L, -40320L, -39683L, -39040L, -38391L, -37736L, -37076L,
|
||||
-36410L, -35738L, -35062L, -34380L, -33692L, -33000L, -32303L, -31600L,
|
||||
-30893L, -30182L, -29466L, -28745L, -28020L, -27291L, -26558L, -25821L,
|
||||
-25080L, -24335L, -23586L, -22834L, -22078L, -21320L, -20557L, -19792L,
|
||||
-19024L, -18253L, -17479L, -16703L, -15924L, -15143L, -14359L, -13573L,
|
||||
-12785L, -11996L, -11204L, -10411L, -9616L, -8820L, -8022L, -7224L,
|
||||
-6424L, -5623L, -4821L, -4019L, -3216L, -2412L, -1608L, -804L,
|
||||
0L, 804L, 1608L, 2412L, 3216L, 4019L, 4821L, 5623L,
|
||||
6424L, 7224L, 8022L, 8820L, 9616L, 10411L, 11204L, 11996L,
|
||||
12785L, 13573L, 14359L, 15143L, 15924L, 16703L, 17479L, 18253L,
|
||||
19024L, 19792L, 20557L, 21320L, 22078L, 22834L, 23586L, 24335L,
|
||||
25080L, 25821L, 26558L, 27291L, 28020L, 28745L, 29466L, 30182L,
|
||||
30893L, 31600L, 32303L, 33000L, 33692L, 34380L, 35062L, 35738L,
|
||||
36410L, 37076L, 37736L, 38391L, 39040L, 39683L, 40320L, 40951L,
|
||||
41576L, 42194L, 42806L, 43412L, 44011L, 44604L, 45190L, 45769L,
|
||||
46341L, 46906L, 47464L, 48015L, 48559L, 49095L, 49624L, 50146L,
|
||||
50660L, 51166L, 51665L, 52156L, 52639L, 53114L, 53581L, 54040L,
|
||||
54491L, 54934L, 55368L, 55794L, 56212L, 56621L, 57022L, 57414L,
|
||||
57798L, 58172L, 58538L, 58896L, 59244L, 59583L, 59914L, 60235L,
|
||||
60547L, 60851L, 61145L, 61429L, 61705L, 61971L, 62228L, 62476L,
|
||||
62714L, 62943L, 63162L, 63372L, 63572L, 63763L, 63944L, 64115L,
|
||||
64277L, 64429L, 64571L, 64704L, 64827L, 64940L, 65043L, 65137L,
|
||||
65220L, 65294L, 65358L, 65413L, 65457L, 65492L, 65516L, 65531L
|
||||
};
|
||||
|
||||
|
||||
// Fixed point (16.16) tangents for a half circle (0-127)
|
||||
fixT _tan_tbl[256] = {
|
||||
0L, 804L, 1609L, 2414L, 3220L, 4026L, 4834L, 5644L,
|
||||
6455L, 7268L, 8083L, 8901L, 9721L, 10545L, 11372L, 12202L,
|
||||
13036L, 13874L, 14717L, 15564L, 16416L, 17273L, 18136L, 19005L,
|
||||
19880L, 20762L, 21650L, 22546L, 23449L, 24360L, 25280L, 26208L,
|
||||
27146L, 28093L, 29050L, 30018L, 30996L, 31986L, 32988L, 34002L,
|
||||
35030L, 36071L, 37126L, 38196L, 39281L, 40382L, 41500L, 42636L,
|
||||
43790L, 44963L, 46156L, 47369L, 48605L, 49863L, 51145L, 52451L,
|
||||
53784L, 55144L, 56532L, 57950L, 59398L, 60880L, 62395L, 63947L,
|
||||
65536L, 67165L, 68835L, 70548L, 72308L, 74116L, 75974L, 77887L,
|
||||
79856L, 81885L, 83977L, 86135L, 88365L, 90670L, 93054L, 95523L,
|
||||
98082L, 100736L, 103493L, 106358L, 109340L, 112447L, 115687L, 119071L,
|
||||
122609L, 126314L, 130198L, 134276L, 138564L, 143081L, 147847L, 152884L,
|
||||
158218L, 163878L, 169896L, 176309L, 183161L, 190499L, 198380L, 206870L,
|
||||
216043L, 225990L, 236817L, 248648L, 261634L, 275959L, 291845L, 309568L,
|
||||
329472L, 351993L, 377693L, 407305L, 441808L, 482534L, 531352L, 590958L,
|
||||
665398L, 761030L, 888450L, 1066730L,1334016L,1779314L,2669641L,5340086L,
|
||||
-2147483647L,-5340086L,-2669641L,-1779314L,-1334016L,-1066730L,-888450L,-761030L,
|
||||
-665398L,-590958L,-531352L,-482534L,-441808L,-407305L,-377693L,-351993L,
|
||||
-329472L,-309568L,-291845L,-275959L,-261634L,-248648L,-236817L,-225990L,
|
||||
-216043L,-206870L,-198380L,-190499L,-183161L,-176309L,-169896L,-163878L,
|
||||
-158218L,-152884L,-147847L,-143081L,-138564L,-134276L,-130198L,-126314L,
|
||||
-122609L,-119071L,-115687L,-112447L,-109340L,-106358L,-103493L,-100736L,
|
||||
-98082L, -95523L, -93054L, -90670L, -88365L, -86135L, -83977L, -81885L,
|
||||
-79856L, -77887L, -75974L, -74116L, -72308L, -70548L, -68835L, -67165L,
|
||||
-65536L, -63947L, -62395L, -60880L, -59398L, -57950L, -56532L, -55144L,
|
||||
-53784L, -52451L, -51145L, -49863L, -48605L, -47369L, -46156L, -44963L,
|
||||
-43790L, -42636L, -41500L, -40382L, -39281L, -38196L, -37126L, -36071L,
|
||||
-35030L, -34002L, -32988L, -31986L, -30996L, -30018L, -29050L, -28093L,
|
||||
-27146L, -26208L, -25280L, -24360L, -23449L, -22546L, -21650L, -20762L,
|
||||
-19880L, -19005L, -18136L, -17273L, -16416L, -15564L, -14717L, -13874L,
|
||||
-13036L, -12202L, -11372L, -10545L, -9721L, -8901L, -8083L, -7268L,
|
||||
-6455L, -5644L, -4834L, -4026L, -3220L, -2414L, -1609L, -804L
|
||||
};
|
||||
|
||||
|
||||
#define SEGMENT_MATH
|
||||
|
||||
|
||||
fixT fixAdd(fixT x, fixT y) {
|
||||
fixT result = x + y;
|
||||
|
||||
if (result >= 0) {
|
||||
if ((x < 0) && (y < 0)) {
|
||||
return -0x7FFFFFFF;
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
} else {
|
||||
if ((x > 0) && (y > 0)) {
|
||||
return 0x7FFFFFFF;
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fixT fixAtan(fixT x) {
|
||||
int32_t a; // for binary search
|
||||
int32_t b;
|
||||
int32_t c;
|
||||
fixT d; // difference value for search
|
||||
|
||||
if (x >= 0) { // search the first part of tan table
|
||||
a = 0;
|
||||
b = 127;
|
||||
} else { // search the second half instead */
|
||||
a = 128;
|
||||
b = 255;
|
||||
}
|
||||
|
||||
do {
|
||||
c = (a + b) >> 1;
|
||||
d = x - _tan_tbl[c];
|
||||
|
||||
if (d > 0) {
|
||||
a = c + 1;
|
||||
} else {
|
||||
if (d < 0) {
|
||||
b = c - 1;
|
||||
}
|
||||
}
|
||||
} while ((a <= b) && (d));
|
||||
|
||||
if (x >= 0) {
|
||||
return ((int32_t)c) << 15;
|
||||
}
|
||||
|
||||
return (-0x00800000L + (((int32_t)c) << 15));
|
||||
}
|
||||
|
||||
|
||||
fixT fixCos(fixT x) {
|
||||
return _cos_tbl[((x + 0x4000) >> 15) & 0x1FF];
|
||||
}
|
||||
|
||||
|
||||
// ***TODO*** This isn't how this is supposed to work!
|
||||
fixT fixDiv(fixT x, fixT y) {
|
||||
if (y == 0) {
|
||||
return (x < 0) ? -0x7FFFFFFF : 0x7FFFFFFF;
|
||||
} else {
|
||||
return fToFix(fixToF(x) / fixToF(y));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fixT fixMul(fixT x, fixT y) {
|
||||
int64_t lx = x;
|
||||
int64_t ly = y;
|
||||
int64_t lres = (lx * ly);
|
||||
int32_t res;
|
||||
|
||||
if (lres > 0x7FFFFFFF0000LL) {
|
||||
return 0x7FFFFFFF;
|
||||
} else {
|
||||
if (lres < -0x7FFFFFFF0000LL) {
|
||||
return 0x80000000;
|
||||
} else {
|
||||
res = lres >> 16;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fixT fixSin(fixT x) {
|
||||
return _cos_tbl[((x - 0x400000 + 0x4000) >> 15) & 0x1FF];
|
||||
}
|
||||
|
||||
|
||||
fixT fixSub(fixT x, fixT y) {
|
||||
fixT result = x - y;
|
||||
|
||||
if (result >= 0) {
|
||||
if ((x < 0) && (y < 0)) {
|
||||
return -0x7FFFFFFF;
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
} else {
|
||||
if ((x > 0) && (y > 0)) {
|
||||
return 0x7FFFFFFF;
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double fixToF(fixT x) {
|
||||
return (double)x / 65536.0;
|
||||
}
|
||||
|
||||
|
||||
int16_t fixToI(fixT x) {
|
||||
fixT y;
|
||||
|
||||
// Apparently, x>>16 isn't entirely portable.
|
||||
if (x >= 0) {
|
||||
y = x >> 16;
|
||||
} else {
|
||||
y = ~((~x) >> 16);
|
||||
}
|
||||
|
||||
return y + ((x & 0x8000) >> 15);
|
||||
}
|
||||
|
||||
|
||||
fixT fToFix(double x) {
|
||||
if (x > 32767.0) return 0x7FFFFFFF;
|
||||
if (x < -32767.0) return -0x7FFFFFFF;
|
||||
|
||||
return (fixT)(x * 65536.0 + (x < 0 ? -0.5 : 0.5));
|
||||
}
|
||||
|
||||
|
||||
fixT iToFix(int16_t x) {
|
||||
return x << 16;
|
||||
}
|
||||
|
||||
|
||||
#endif // FAUX_FIXED
|
|
@ -106,6 +106,7 @@ int appMain(app_t *app, void *userData) {
|
|||
a23d2Init();
|
||||
|
||||
// Build a plane!
|
||||
initAircraft();
|
||||
resetAircraft();
|
||||
_plane.x = _camera->x;
|
||||
_plane.y = _camera->y - PLANE_HEIGHT;
|
||||
|
@ -239,10 +240,10 @@ int appMain(app_t *app, void *userData) {
|
|||
if (_plane.throttle) _plane.ignition = 1;
|
||||
}
|
||||
|
||||
printAt(0, 21, "X:%d Y:%d Z:%d", _plane.x, _plane.y, _plane.z);
|
||||
printAt(0, 22, "P:%f R:%f Y:%f", _plane.pitch, _plane.roll, _plane.yaw);
|
||||
printAt(0, 23, "T:%d E:%d A:%d B:%d", _plane.throttle, _plane.elevator, _plane.aileron, _plane.brake);
|
||||
printAt(0, 24, "I:%d A:%d R:%d H:%f V:%f", _plane.ignition, _plane.airborne, _plane.rpm, _plane.hSpeed, _plane.vSpeed);
|
||||
printAt(0, 25, "X:%d Y:%d Z:%d", _plane.x, _plane.y, _plane.z);
|
||||
printAt(0, 26, "P:%f R:%f Y:%f", _plane.pitch, _plane.roll, _plane.yaw);
|
||||
printAt(0, 27, "T:%d E:%d A:%d B:%d", _plane.throttle, _plane.elevator, _plane.aileron, _plane.brake);
|
||||
printAt(0, 28, "I:%d A:%d R:%d H:%f V:%f", _plane.ignition, _plane.airborne, _plane.rpm, _plane.hSpeed, _plane.vSpeed);
|
||||
|
||||
// Update timers.
|
||||
_plane.loopTime = (app_time_count(app) - lastTime) / timeFreqMs;
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
*/
|
||||
|
||||
|
||||
#ifdef __F256K__
|
||||
#ifdef __F256__
|
||||
#include "f256lib.h"
|
||||
#else
|
||||
#include <stdint.h>
|
||||
|
|
|
@ -128,7 +128,7 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __F256K__
|
||||
#ifdef __F256__
|
||||
#define WITHOUT_FILE
|
||||
#define WITHOUT_SPRITE
|
||||
#define WITHOUT_TILE
|
||||
|
@ -141,7 +141,7 @@
|
|||
* 8k scene.3d @ 0x56000
|
||||
*
|
||||
*/
|
||||
EMBED(".binarydata.embedded", embedded, "embedded.bin");
|
||||
EMBED(embedded, "embedded.bin", 0x54000);
|
||||
#endif
|
||||
|
||||
#include "a23d2.h"
|
||||
|
|
Loading…
Add table
Reference in a new issue