From 9fe53fcae7430c2781b83f0e4cac6a4c75f7fd72 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Sat, 20 Apr 2024 19:38:20 -0500 Subject: [PATCH] Not flying yet, but closer! --- .gitignore | 2 +- pc/CMakeLists.txt | 3 + pc/include/flight.h | 5 +- pc/include/sysfont.h | 266 +++++++++++++++++++++++++++++++++++++++++++ pc/include/util.h | 35 ++++++ pc/src/flight.c | 61 ++++++---- pc/src/main.c | 217 ++++++++++++++++++++++++++--------- pc/src/util.c | 58 ++++++++++ 8 files changed, 569 insertions(+), 78 deletions(-) create mode 100644 pc/include/sysfont.h create mode 100644 pc/include/util.h create mode 100644 pc/src/util.c diff --git a/.gitignore b/.gitignore index 0292164..f7b4c04 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,6 @@ backup/ *.iso *~ *.pgz -apple2/ +reference/ build-*/ *.user diff --git a/pc/CMakeLists.txt b/pc/CMakeLists.txt index a0d7665..ace60b8 100644 --- a/pc/CMakeLists.txt +++ b/pc/CMakeLists.txt @@ -8,6 +8,7 @@ find_package(SDL2 REQUIRED) set(HEADERS app.h + sysfont.h flight.h vrEmu6502.h a23d2bin.h @@ -27,6 +28,8 @@ list(TRANSFORM SOURCE PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/src/") add_executable(${CMAKE_PROJECT_NAME} ${HEADERS} ${SOURCE} + src/util.c + include/util.h ) diff --git a/pc/include/flight.h b/pc/include/flight.h index 7d26957..2881270 100644 --- a/pc/include/flight.h +++ b/pc/include/flight.h @@ -31,6 +31,9 @@ #include +#define PLANE_HEIGHT 20 + + typedef unsigned char byte; @@ -71,7 +74,7 @@ typedef struct airplaneS { float AOA; float torque; float torque2; - uint16_t loopTime; + uint16_t loopTime; // Milliseconds // Used to be static. Need preserved. double dPitch; double dYaw; diff --git a/pc/include/sysfont.h b/pc/include/sysfont.h new file mode 100644 index 0000000..b70127f --- /dev/null +++ b/pc/include/sysfont.h @@ -0,0 +1,266 @@ +/* +------------------------------------------------------------------------------ + Licensing information can be found at the end of the file. +------------------------------------------------------------------------------ + +sysfont.h - v1.0 - Simple debug text renderer for C/C++. +*/ + +#ifndef sysfont_h +#define sysfont_h + +#ifndef SYSFONT_U8 + #define SYSFONT_U8 unsigned char +#endif +#ifndef SYSFONT_U16 + #define SYSFONT_U16 unsigned short +#endif +#ifndef SYSFONT_U32 + #define SYSFONT_U32 unsigned int +#endif + +void sysfont_9x16_u8( SYSFONT_U8* pixels, int width, int height, int x, int y, char const* text, SYSFONT_U8 color ); +void sysfont_9x16_u16( SYSFONT_U16* pixels, int width, int height, int x, int y, char const* text, SYSFONT_U16 color ); +void sysfont_9x16_u32( SYSFONT_U32* pixels, int width, int height, int x, int y, char const* text, SYSFONT_U32 color ); + +void sysfont_8x8_u8( SYSFONT_U8* pixels, int width, int height, int x, int y, char const* text, SYSFONT_U8 color ); +void sysfont_8x8_u16( SYSFONT_U16* pixels, int width, int height, int x, int y, char const* text, SYSFONT_U16 color ); +void sysfont_8x8_u32( SYSFONT_U32* pixels, int width, int height, int x, int y, char const* text, SYSFONT_U32 color ); + +#define SYSFONT_TEXWIDTH 256 +#define SYSFONT_TEXHEIGHT 256 +#define SYSFONT_TEX8X8OFS 160 +void sysfont_texture_u8( SYSFONT_U8* texture, int pitch_in_bytes, SYSFONT_U8 color, SYSFONT_U8 bgcolor ); +void sysfont_texture_u16( SYSFONT_U16* texture, int pitch_in_bytes, SYSFONT_U16 color, SYSFONT_U16 bgcolor ); +void sysfont_texture_u32( SYSFONT_U32* texture, int pitch_in_bytes, SYSFONT_U32 color, SYSFONT_U32 bgcolor ); + +#endif /* sysfont_h */ + + +/* + +Examples: + +------------------------------------------------------------------------------ + + #define SYSFONT_IMPLEMENTATION + #include "sysfont.h" + + #define STB_IMAGE_WRITE_IMPLEMENTATION + #include "stb_image_write.h" + + int main() + { + static unsigned tex[ SYSFONT_TEXWIDTH * SYSFONT_TEXHEIGHT ]; + sysfont_texture_u32( tex, SYSFONT_TEXWIDTH * sizeof( unsigned ), 0xffffffff, 0xff000000 ); + stbi_write_png( "texture.png", SYSFONT_TEXWIDTH, SYSFONT_TEXHEIGHT, 4, tex, SYSFONT_TEXWIDTH * 4 ); + + static unsigned test[ 320 * 200 ]; + for( int i = 0; i < 320 * 200; ++i ) test[ i ] = 0xff800000; + sysfont_9x16_u32( test, 320, 200, 20, 40, "A world can only take so much.", 0xffff00ff ); + sysfont_8x8_u32( test, 320, 200, 30, 80, "Testing the sysfont lib.", 0xff00ffff ); + stbi_write_png( "test.png", 320, 200, 4, test, 320 * 4 ); + + return 0; + } +*/ + + +/* +---------------------- + IMPLEMENTATION +---------------------- +*/ + +#ifdef SYSFONT_IMPLEMENTATION + + +#define SYSFONT_DATA static SYSFONT_U32 sysfont_data[] = { \ +0x00000000,0x00000000,0xfc00ff00,0x00000003,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0xfc00ff00,0x00000003,0x80010000,0xc0000000,0x00000007,0x00000000,0x01f8fc00,0x00000000,0xfc00ff00,0x9f83c3c3,0xc003003f,0x6fe33060,0x180c000c,0x00000030,0x03fd0200,0x06030000,0xfc00ff00,0x99866383,0xe0070c31,0xcdb330f0,0x3c1e0000,0x00000030,0xb36d4a00,0x0f078081,0xfc00ff00,0x9f8662c3,0xf00f0c3f,0x8db331f8,0x7e3f0003,0x00000030,0xfbfd0200,0x1f8781c3,0x0c78ff00,0x81866263,0xf81f6db1,0xcdb33060,0x180c0006,0x00606030,0xfbfd0200,0x3fdce3e3,0x64cce70c,0x818660f2,0xfe7f1e31,0x6de33060,0x180c000c,0x0030c030,0xfb0d7a00,0x3fdce7f3,0xf484c31e,0x8183c19a,0xf81f73b1,0x6d833060,0x180c000c,0x03f9fc30,0xfb9d3200,0x1f9ce3e3,0xf484c31e,0x8181819a,0xf00f1e31,0xcd8331f8,0x183f1fc6,0x0030c030,0xf3fd0200,0x060301c1,0x64cce70c,0x81c7e19a,0xe0076db9,0x8d8000f0,0x181e1fc3,0x006060fc,0xe3fd0200,0x06030080,0x0c78ff00,0xc1e1819b,0xc0030c39,0x0d833060,0x180c1fc6,0x00000078,0x41f8fc00,0x0f078000,0xfc00ff00,0xc0e180f3,0x80010c19,0x6d833000,0x183f1fcc,0x00000030,0x00000000,0x00000000,0xfc00ff00,0xc0000003,0x00000000,0xc0000000,0x00000007,0x00000000,0x00000000,0x00000000,0xfc00ff00,0x00000003,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0xfc00ff00,0x00000003,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0xfc00ff00,0x00000003,0x00000000,0x00000000,0x00000000,0x00000000, \ +0x00000000,0x00000000,0x00001800,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x19800000,0x00001800,0x00000060,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x19830000,0x70003e00,0x01830060,0x00000000,0x03c00000,0x301f0f83,0x03f870fe,0x00000000,0x19878000,0xd800631b,0x03018060,0x00000000,0x86600000,0x383198c3,0x03181806,0xf8200000,0x09078003,0xd886431b,0x0600c030,0x00000000,0xcc320000,0x3c301803,0x03000c06,0xf8704800,0x80078003,0x70c6033f,0x8600c000,0x00000c19,0x0c330000,0x36300c03,0x03000c06,0xf070cc03,0x00030001,0xb8603e1b,0x0600c001,0x00000c0f,0x0db18000,0x331e0603,0x0180fc7e,0xf0f9fe03,0x00030001,0xec30601b,0xc600c000,0xfe003f3f,0x0db0c000,0x7f300303,0x00c18cc0,0xe0f8cc03,0x00030000,0xcc18601b,0x0600c000,0x00000c0f,0x0c306000,0x30300183,0x00618cc0,0xe1fc487f,0x80000000,0xcc0c613f,0x8600c000,0x00180c19,0x0c303000,0x303000c3,0x00618cc0,0x41fc0000,0x00030000,0xccc6631b,0x03018000,0x00180000,0x06601860,0x303198c3,0x00618cc6,0x00000000,0x00030000,0xb8c23e1b,0x01830001,0x00180000,0xc3c00860,0x781f1fcf,0x0060f87c,0x00000000,0x00000000,0x00001800,0x00000000,0x000c0000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00001800,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, \ +0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00007c3e,0x00000000,0xfc10001f,0xcfe1f1e0,0x78631e1f,0x60f339e0,0x3f1f18d8,0x01f0fc7c,0x0000c663,0x81800600,0x98383e31,0x8cc36331,0x30633319,0xe06330c0,0x663199dc,0x031998c6,0xc060c663,0x83000300,0x986c6331,0x88c66219,0x30632191,0xe06330c0,0x66319bdf,0x031998c6,0xc060c663,0x060fc180,0x98c66318,0x82c66019,0x30630185,0xe061b0c0,0x66319fdf,0x003198c6,0x0000fc3e,0x0c0000c0,0xf8c67b0c,0x83c66018,0x307f0187,0x6060f0c0,0x3e319edb,0x00e0f8c6,0x0000c063,0x18000060,0x98fe7b0c,0x82c66019,0x30633d85,0x6060f0c0,0x06319cd8,0x0180d8c6,0x0000c063,0x0c0fc0c0,0x98c67b0c,0x80c66019,0x30633181,0x6061b0cc,0x063198d8,0x030198c6,0xc060c063,0x06000180,0x98c63b00,0x88c66219,0x30633181,0x646330cc,0x063198d8,0x031998d6,0xc0606063,0x03000300,0x98c6030c,0x8cc36331,0x30633301,0x666330cc,0x063198d8,0x031998f6,0x60003c3e,0x01800600,0xfcc63e0c,0xcfe1f1e0,0x78632e03,0x67f33878,0x0f1f18d8,0x01f19c7c,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000060,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x000000e0,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, \ +0x00000000,0x00000000,0x20000000,0x0000c000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x70000000,0x0000c000,0x00000000,0x00000000,0x00000000,0x00000000,0x1b0cc6ff,0x3fd86c36,0xd878001e,0xc0018000,0x00380001,0x00700070,0x1c039803,0x00000000,0x1b0cc6db,0x30d86c36,0x8c600106,0x80000001,0x00300001,0x006000d8,0x18031803,0x00000000,0x1b0cc699,0x18586666,0x00600306,0x80000000,0x00300001,0x00600098,0x18030000,0x00000000,0x1b0cc618,0x0c0cc3c6,0x00600706,0x83c00000,0x7c3c1f07,0x83637018,0x18331c03,0x01f0ecce,0x1b0cc618,0x06078186,0x00600e06,0x86000000,0xc636318d,0x06e1983c,0x181b1803,0x031999fe,0xdb0cc618,0x03030186,0x00601c06,0x87c00000,0xfe330199,0x06619818,0x180f1803,0x031999b6,0xdb0cc618,0x018303c6,0x00603806,0x86600000,0x06330199,0x06619818,0x180f1803,0x031999b6,0xf998c618,0x20c30667,0x00607006,0x86600000,0x06330199,0x06619818,0x181b1803,0x031999b6,0x30f0c618,0x30c30c33,0x00606006,0x86600000,0xc6333199,0x06619818,0x18331803,0x031999b6,0x30607c3c,0x3fc78c33,0x0078401e,0x8dc00000,0x7c6e1f0f,0x8671f03c,0x3c339807,0x01f199b6,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00018000,0x00001980,0x00000000,0x00000000,0x00000000,0x00000000,0x000007f8,0x00000000,0x00019800,0x00001980,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x0000f000,0x00000f00,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, \ +0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0xc00040c0,0x08000700,0x00001800,0x00000000,0x00000080,0x00000000,0x81c18380,0x663c001b,0x8330e060,0x1c000d81,0x033030c6,0x00000000,0x000000c0,0x00000000,0xc30180c0,0x0066000e,0x0001b030,0x36000703,0x00006000,0x00000000,0x000000c0,0x00000000,0x030180c0,0x00430400,0x00000000,0x001e0000,0x00000000,0xf0ecdc3b,0xb0c663f1,0xfcc6c361,0x030180c1,0x66030e00,0xc1e0f0f8,0x3e330783,0x00e0f87c,0x19b86666,0xb0c660c3,0xccc66661,0x0e000070,0x66031b00,0x0301818c,0x63030c06,0x00c18cc6,0x31986666,0xb0c660c0,0x60c63c61,0x030180c0,0x66033180,0xc3e1f1fc,0x7f030f87,0x00c1fcfe,0xe0186666,0xb0c660c0,0x30c6186d,0x030180c0,0x66433180,0x6331980c,0x03330cc6,0x00c00c06,0x80186666,0x998660c1,0x18c63c6d,0x030180c0,0x66663180,0x6331980c,0x031e0cc6,0x00c00c06,0x18186666,0x8f0666c3,0x8cc6667f,0x030180c1,0x663c3f80,0x6331998c,0x63180cc6,0x00c18cc6,0xf03c7c3e,0x060dc381,0xfcfcc333,0x01c18381,0xdc300000,0xc6e370f8,0x3e301b8d,0x01e0f87c,0x00006006,0x00000000,0x00c00000,0x00000000,0x00600000,0x00000000,0x001e0000,0x00000000,0x00006006,0x00000000,0x00600000,0x00000000,0x003e0000,0x00000000,0x00000000,0x00000000,0x0000f00f,0x00000000,0x003e0000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, \ +0xe0000000,0x00000180,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x000000dc,0xb18c0c18,0x000000c1,0x300c0004,0xcc600030,0x001c0c18,0x018380fc,0x000c0606,0x00e0f076,0xe000183c,0x1f000060,0x7818630e,0x00063060,0x86360c00,0x00c6c199,0x6e060303,0x01b0d800,0x00203066,0x0d800000,0xcc30001b,0xc7c000c0,0xcc263f18,0x8060c198,0x3b030181,0x01b0d8c6,0xe0700000,0x0cc007f0,0x00000000,0xcc600000,0x78066198,0x0000c0f8,0x00000000,0x00e1f0ce,0xb0d8381c,0x0ccec661,0xcc7c3e1f,0xcc663198,0x300f0198,0x81e0c118,0x3b198f83,0x000000de,0x198c3018,0x9fdb8063,0xccc66331,0xcc663198,0xfe060198,0x0303f199,0x661998c3,0x01f1f8fe,0x198c3018,0x8cdb03e3,0xccc66331,0xcc663198,0x30060198,0x03e0c3d8,0x661998c3,0x000000f6,0xf9fc3018,0x8ccfc063,0xccc66331,0xcc663198,0xfe066198,0x0330c199,0x661998c3,0x000000e6,0x198c3018,0x8cc36063,0xccc66331,0xcc663198,0x30063f18,0x0330c198,0x661998c3,0x000000c6,0x198c3018,0x8cc76663,0xccc66331,0xcc663198,0x30670c18,0x0330c198,0x661998c3,0x000000c6,0x198c783c,0x1cddc7f3,0xb87c3e1f,0x87c7e371,0x303f0c0f,0x86e0c33c,0x66370f87,0x000000c6,0x00000000,0x00000000,0x00000000,0x00060000,0x00000000,0x0000d800,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00030000,0x00000000,0x00007000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x0001e000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, \ +0x00000000,0x00000000,0xef558800,0x030180c6,0xd800001b,0x86c001b0,0x1800060d,0x00c00030,0x18000000,0x00000030,0xb8aa2200,0x030180c7,0xd800001b,0x86c001b0,0x1800060d,0x00c00030,0x1800000c,0x00030030,0xef558800,0x030180c6,0xd800001b,0x86c001b0,0x1800060d,0x00c00030,0x1800000c,0x00030432,0xb8aa2200,0x030180c7,0xd800001b,0x86c001b0,0x1800060d,0x00c00030,0x18000000,0x00000633,0xef558800,0x030180c6,0xd800001b,0x86c001b0,0x1800060d,0x00c00030,0x9800000c,0x9b030331,0xb8aa220d,0x03e180c7,0xde1f001b,0x86f3f9b0,0x180007cd,0x00c00030,0xc1fcfe0c,0x0d830180,0xef55881b,0x030180c6,0xc018001b,0x860301b0,0x1800060d,0x00c00030,0x61800606,0x06c300c0,0xb8aa2236,0xc3e1f0c7,0xde1f3f9b,0xe7f379b0,0xf80f87cf,0x0fc7ffff,0x31800603,0x0d878660,0xef55881b,0x030180c6,0xd818361b,0x000361b0,0x000c0000,0x00c06000,0x99800663,0x9b078733,0xb8aa220d,0x030180c7,0xd818361b,0x000361b0,0x000c0000,0x00c06000,0xc9800663,0x00078696,0xef558800,0x030180c6,0xd818361b,0x000361b0,0x000c0000,0x00c06000,0x0000003e,0x000307c3,0xb8aa2200,0x030180c7,0xd818361b,0x000361b0,0x000c0000,0x00c06000,0x80000000,0x00000601,0xef558800,0x030180c6,0xd818361b,0x000361b0,0x000c0000,0x00c06000,0xc0000000,0x00000607,0xb8aa2200,0x030180c7,0xd818361b,0x000361b0,0x000c0000,0x00c06000,0x00000000,0x00000000,0xef558800,0x030180c6,0xd818361b,0x000361b0,0x000c0000,0x00c06000,0x00000000,0x00000000,0xb8aa2200,0x030180c7,0xd818361b,0x000361b0,0x000c0000,0x00c06000, \ +0x60603000,0x1b0006c3,0xb0006c00,0x0006c0c1,0x00183600,0x01836000,0x00ff8003,0x0fffc01e,0x60603000,0x1b0006c3,0xb0006c00,0x0006c0c1,0x00183600,0x01836000,0x00ff8003,0x0fffc01e,0x60603000,0x1b0006c3,0xb0006c00,0x0006c0c1,0x00183600,0x01836000,0x00ff8003,0x0fffc01e,0x60603000,0x1b0006c3,0xb0006c00,0x0006c0c1,0x00183600,0x01836000,0x00ff8003,0x0fffc01e,0x60603000,0x1b0006c3,0xb0006c00,0x0006c0c1,0x00183600,0x01836000,0x00ff8003,0x0fffc01e,0x67e03000,0xfbff9ec3,0xbfffecff,0x3fe6cfff,0xf1f83600,0x1ff36003,0x00ff8003,0x0fffc01e,0x60603000,0x000180c3,0x00000c00,0x0006c000,0x30183600,0x01836000,0x00ff8003,0x0fffc01e,0x67e3ffff,0xfffd9fcf,0xbfffecf7,0xffffffff,0xf1f8fe7f,0xfffffff3,0xfffffe03,0x0007c01f,0x60603000,0x000d8003,0xb0006c36,0x03000001,0x3000001b,0x018361b0,0xffff8600,0x0007c01f,0x60603000,0x000d8003,0xb0006c36,0x03000001,0x3000001b,0x018361b0,0xffff8600,0x0007c01f,0x60603000,0x000d8003,0xb0006c36,0x03000001,0x3000001b,0x018361b0,0xffff8600,0x0007c01f,0x60603000,0x000d8003,0xb0006c36,0x03000001,0x3000001b,0x018361b0,0xffff8600,0x0007c01f,0x60603000,0x000d8003,0xb0006c36,0x03000001,0x3000001b,0x018361b0,0xffff8600,0x0007c01f,0x60603000,0x000d8003,0xb0006c36,0x03000001,0x3000001b,0x018361b0,0xffff8600,0x0007c01f,0x60603000,0x000d8003,0xb0006c36,0x03000001,0x3000001b,0x018361b0,0xffff8600,0x0007c01f,0x60603000,0x000d8003,0xb0006c36,0x03000001,0x3000001b,0x018361b0,0xffff8600,0x0007c01f, \ +0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000003,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x1c000003,0x07800000,0x01fc3c00,0x00000000,0x70000000,0x000003c0,0x0000000e,0x07000000,0x36000003,0x01800000,0x018c6600,0x000007f0,0xd8387e00,0x18000060,0x00001f03,0x0d818030,0x36000003,0x01800000,0xf98c6600,0x19800633,0x8c6c1837,0x8c0000c1,0x307f3181,0x0d80c060,0x1c000603,0x01800000,0xb00c666e,0x998fc061,0x8cc63c1d,0x8fc7e181,0x30003181,0x018060c0,0x00370603,0x01800000,0xb00c363b,0x198360c1,0x8cc6660c,0x9b6db3e1,0xfc00318f,0x01803180,0x001d8003,0x01800000,0xb00c661b,0x19836181,0xd8fe660c,0x9b6db330,0x307f3181,0x018060c0,0x00001f83,0x01b80030,0xb00cc61b,0x198360c1,0xd8c6660c,0x99edb330,0x30003181,0x6180c060,0x00370003,0x01b06030,0xb00cc61b,0x0f836061,0xd8c63c0c,0x8fc7e330,0x00003181,0x61818030,0x001d8603,0x01b00000,0xb00cc63b,0x01836631,0xd86c180c,0x00c00330,0x007f3183,0x61800000,0x00000603,0x01e00000,0xb00c666e,0x0181c7f1,0xdc387e0c,0x006001e1,0xfe00318e,0xc183f1f9,0x00000001,0x01c00000,0x00000000,0x00c00000,0x00000000,0x00000000,0x00000000,0x01800000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x01800000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x01800000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x01800000,0x00000000,0x00000000, \ +0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00001c1b,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00003636,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00001836,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00f80c36,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00f82636,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00f83e36,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00f80000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00f80000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00f80000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00f80000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, \ +0x367e7e00,0x00081c08,0xf0ff00ff,0x18fefc3c,0x66184001,0x18007cfe,0x00001818,0x00000000,0x7fff8100,0x00083e1c,0xe0c33cff,0xdbc6cc66,0x663c7007,0x3c00c6db,0x0c18183c,0xff182400,0x7fdba500,0x181c1c3e,0xf09966e7,0x3cfefc66,0x667e7c1f,0x7e001cdb,0x0630187e,0xff3c6603,0x7fff8100,0x3c3e7f7f,0xbebd42c3,0xe7c60c66,0x66187f7f,0x180036de,0x7f7f1818,0x7e7eff03,0x3ec3bd00,0x3c7f7f3e,0x33bd42c3,0xe7c60c3c,0x66187c1f,0x7e7e36d8,0x06307e18,0x3cff6603,0x1ce79900,0x183e6b1c,0x339966e7,0x3ce60e18,0x007e7007,0x3c7e1cd8,0x0c183c18,0x18ff247f,0x08ff8100,0x00080808,0x33c33cff,0xdb670f7e,0x663c4001,0x187e33d8,0x00001818,0x00000000,0x007e7e00,0x001c1c00,0x1eff00ff,0x18030718,0x00180000,0xff001e00,0x00000000,0x00000000,0x36360c00,0x061c000c,0x00000618,0x60000000,0x1e1e0c3e,0x3f1c3f38,0x00001e1e,0x1e060018,0x36361e00,0x0636633e,0x0c660c0c,0x30000000,0x33330e63,0x3306033c,0x0c0c3333,0x330c000c,0x7f361e00,0x031c3303,0x0c3c1806,0x18000000,0x30300c73,0x30031f36,0x0c0c3333,0x30183f06,0x36000c00,0x006e181e,0x3fff1806,0x0c003f00,0x1c1c0c7b,0x181f3033,0x00003e1e,0x18300003,0x7f000c00,0x003b0c30,0x0c3c1806,0x06000000,0x30060c6f,0x0c33307f,0x00003033,0x0c180006,0x36000000,0x0033661f,0x0c660c0c,0x030c000c,0x33330c67,0x0c333330,0x0c0c1833,0x000c3f0c,0x36000c00,0x006e630c,0x00000618,0x010c000c,0x1e3f3f3e,0x0c1e1e78,0x0c0c0e1e,0x0c060018,0x00000000,0x00000000,0x00000000,0x00000006,0x00000000,0x00000000,0x06000000,0x00000000, \ +0x3c3f0c3e,0x3c7f7f1f,0x67781e33,0x1c63630f,0x1e3f1e3f,0x6333333f,0x1e7f3363,0x00081e03,0x66661e63,0x66464636,0x66300c33,0x36677706,0x33663366,0x6333332d,0x06633363,0x001c1806,0x0366337b,0x03161666,0x36300c33,0x636f7f06,0x06663366,0x6333330c,0x06313336,0x0036180c,0x033e337b,0x031e1e66,0x1e300c3f,0x637b7f06,0x0c3e333e,0x6b33330c,0x06181e1c,0x00631818,0x03663f7b,0x73161666,0x36330c33,0x63736b46,0x18363b06,0x7f33330c,0x064c0c1c,0x00001830,0x66663303,0x66064636,0x66330c33,0x36636366,0x33661e06,0x771e330c,0x06660c36,0x00001860,0x3c3f331e,0x7c0f7f1f,0x671e1e33,0x1c63637f,0x1e67380f,0x630c3f1e,0x1e7f1e63,0x00001e40,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0xff000000,0x0007000c,0x001c0038,0x07300c07,0x0000000e,0x00000000,0x00000008,0x38000000,0x006e0718,0x0006000c,0x00360030,0x06000006,0x0000000c,0x00000000,0x0000000c,0x0c000000,0x083b0c18,0x1e061e18,0x6e061e30,0x66300e36,0x1e1f330c,0x3e3b6e3b,0x6333333e,0x0c3f3363,0x1c000c18,0x333e3000,0x330f333e,0x36300c6e,0x33337f0c,0x036e3366,0x6b33330c,0x07193336,0x36003800,0x03663e00,0x33063f33,0x1e300c66,0x33337f0c,0x1e663366,0x7f33330c,0x0c0c331c,0x63000c18,0x33663300,0x3e060333,0x36330c66,0x33336b0c,0x30063e3e,0x7f1e332c,0x0c263e36,0x63000c18,0x1e3b6e00,0x300f1e6e,0x67331e67,0x1e33631e,0x1f0f3006,0x360c6e18,0x383f3063,0x7f000718,0x00000000,0x1f000000,0x001e0000,0x00000000,0x0000780f,0x00000000,0x00001f00,0x00000000, \ +0x7e38001e,0x000c0733,0x3307337e,0x0c63073e,0x1e7c0038,0x001e0000,0x1833c300,0x701f331c,0xc3003333,0x000c0000,0x000000c3,0x0c1c0063,0x33360000,0x07330733,0x18001833,0xd8333336,0x3c1e0003,0x1e1e1e1e,0x0e1e1e3c,0x00360e1c,0x0033fe3f,0x00000000,0x7e333c00,0x18331e26,0x60333333,0x03303030,0x0c333366,0x1e630c18,0x1e7f3006,0x33331e1e,0x03336633,0x3c5f3f0f,0x7c3f331e,0x033e3e3e,0x0c3f3f7e,0x337f0c18,0x3333fe1e,0x33333333,0x03336633,0x18630c06,0x66033318,0x1e333333,0x0c030306,0x3f630c18,0x33333306,0x33333333,0x7e333c3e,0x18f33f67,0xfc1e7e30,0x307e7e7e,0x1e1e1e3c,0x33631e3c,0x1e73fe3f,0x7e7e1e1e,0x181e1830,0x1b630c3f,0x0000001e,0x1c000000,0x00000000,0x00000000,0x00000000,0x00000000,0x1800001f,0x0ee30c00,0x00001c38,0x1c3c3f00,0xc300000c,0x000018c3,0x18dbaa44,0x006c1818,0x006c6c00,0x00186c6c,0x38380000,0x3636001f,0x63000000,0x33cc1863,0x18ee5511,0x006c1818,0x006c6c00,0x00186c6c,0x00000e1e,0x36363300,0x3300000c,0x66660033,0x18dbaa44,0x006c1f18,0x7f6c6f1f,0x001f6c6f,0x331e0c30,0x1c7c371f,0x7b3f3f06,0xcc3318db,0x18775511,0x006c1818,0x606c6018,0x00186c60,0x33330c3e,0x00003f33,0xcc300303,0x666618ec,0x18dbaa44,0x7f6f1f1f,0x6f6c6f1f,0x1f1f7f7f,0x33330c33,0x3e7e3b33,0x66300333,0x33cc18f6,0x18ee5511,0x6c6c1818,0x6c6c6c18,0x18000000,0x7e1e1e7e,0x00003333,0x3300001e,0x000018f3,0x18dbaa44,0x6c6c1818,0x6c6c6c18,0x18000000,0x00000000,0x00000000,0xf0000000,0x000000c0,0x18775511,0x6c6c1818,0x6c6c6c18,0x18000000, \ +0x18001818,0x6c181800,0x006c006c,0x186c006c,0x6c00006c,0x6c000018,0xff001818,0xfff00f00,0x18001818,0x6c181800,0x006c006c,0x186c006c,0x6c00006c,0x6c000018,0xff001818,0xfff00f00,0x18001818,0x6cf81800,0xffeffcec,0xffefffec,0x6c00ff6c,0x6c00f8f8,0xff0018ff,0xfff00f00,0x18001818,0x6c181800,0x00000c0c,0x0000000c,0x6c00006c,0x6c001818,0xff001818,0xfff00f00,0xf8fffff8,0xecf8ffff,0xefffecfc,0xffefffec,0xfcffffff,0xfffcf8f8,0xfff81fff,0x00f00fff,0x18180000,0x6c181800,0x6c006c00,0x006c006c,0x006c1800,0x6c6c1800,0xff180018,0x00f00fff,0x18180000,0x6c181800,0x6c006c00,0x006c006c,0x006c1800,0x6c6c1800,0xff180018,0x00f00fff,0x18180000,0x6c181800,0x6c006c00,0x006c006c,0x006c1800,0x6c6c1800,0xff180018,0x00f00fff,0x00000000,0x0000003f,0x381c1c3f,0x1e1c6000,0x18060c00,0x000c1870,0xf000001c,0x00000e1e,0x7f3f1e00,0x6e660033,0x0c36360c,0x33063000,0x0c0c0c3f,0x6e0c18d8,0x30000036,0x00001836,0x3633336e,0x3b667e06,0x1863631e,0x33037e7e,0x06183f00,0x3b0018d8,0x30000036,0x003c0c36,0x36031f3b,0x18661b0c,0x3e637f33,0x331fdbdb,0x0c0c0c3f,0x003f1818,0x3000181c,0x003c0636,0x36033313,0x18661b06,0x33366333,0x3303dbdb,0x18060c00,0x6e001818,0x37181800,0x003c1e36,0x36031f3b,0x183e1b33,0x3336361e,0x33067e7e,0x0000003f,0x3b0c1b18,0x36000000,0x003c0000,0x3603036e,0x18060e3f,0x1e771c0c,0x331c0600,0x3f3f3f00,0x000c1b18,0x3c000000,0x00000000,0x00000300,0x00030000,0x0000003f,0x00000300,0x00000000,0x00000e18,0x38000000,0x00000000, \ +}; + + +#define SYSFONT_DRAW( T, M, W, H, O ) \ + SYSFONT_DATA \ + if( !text || !pixels ) return; \ + char const* str = text; \ + SYSFONT_U32* const data = sysfont_data; \ + int px = x; \ + while( *str ) \ + { \ + SYSFONT_U8 c = (SYSFONT_U8) *str++; \ + int sx = ( c % M ) * W; \ + int sy = ( c / M ) * H + O; \ + int dx = px; \ + int dy = y; \ + for( int iy = 0; iy < H; ++iy ) \ + { \ + for( int ix = 0; ix < W; ++ix ) \ + { \ + int v = ( sx + ix ) / 32; \ + int u = ( sx + ix ) - ( v * 32 ); \ + SYSFONT_U32 b = data[ v + ( sy + iy ) * 8 ]; \ + if( b & ( 1 << u ) ) \ + { \ + int xp = dx + ix; \ + int yp = dy + iy; \ + if( xp >= 0 && xp < width && yp >= 0 && yp < height ) pixels[ xp + yp * width ] = color; \ + } \ + } \ + } \ + px += W; \ + } + + +#define SYSFONT_TEX( T ) \ + SYSFONT_DATA \ + SYSFONT_U32* src = sysfont_data; \ + T* row = texture; \ + for( int iy = 0; iy < 224; ++iy ) \ + { \ + T* dst = row; \ + for( int ix = 0; ix < 256 / 32; ++ix ) \ + { \ + SYSFONT_U32 b = *src++; \ + for( int i = 0; i < 32; ++i ) \ + *dst++ = ( b & ( 1 << i ) ) ? color : bgcolor; \ + } \ + row = (T*) ( ( (SYSFONT_U8*) row ) + pitch_in_bytes ); \ + } \ + for( int iy = 224; iy < 256; ++iy ) \ + { \ + T* dst = row; \ + for( int ix = 0; ix < 256; ++ix ) \ + *dst++ = bgcolor; \ + row = (T*) ( ( (SYSFONT_U8*) row ) + pitch_in_bytes ); \ + } + + +void sysfont_9x16_u8( SYSFONT_U8* pixels, int width, int height, int x, int y, char const* text, SYSFONT_U8 color ) + { + SYSFONT_DRAW( SYSFONT_U8, 28, 9, 16, 0 ); + } + + +void sysfont_9x16_u16( SYSFONT_U16* pixels, int width, int height, int x, int y, char const* text, SYSFONT_U16 color ) + { + SYSFONT_DRAW( SYSFONT_U16, 28, 9, 16, 0 ); + } + + +void sysfont_9x16_u32( SYSFONT_U32* pixels, int width, int height, int x, int y, char const* text, SYSFONT_U32 color ) + { + SYSFONT_DRAW( SYSFONT_U32, 28, 9, 16, 0 ); + } + + +void sysfont_8x8_u8( SYSFONT_U8* pixels, int width, int height, int x, int y, char const* text, SYSFONT_U8 color ) + { + SYSFONT_DRAW( SYSFONT_U8, 32, 8, 8, 160 ); + } + + +void sysfont_8x8_u16( SYSFONT_U16* pixels, int width, int height, int x, int y, char const* text, SYSFONT_U16 color ) + { + SYSFONT_DRAW( SYSFONT_U16, 32, 8, 8, 160 ); + } + + +void sysfont_8x8_u32( SYSFONT_U32* pixels, int width, int height, int x, int y, char const* text, SYSFONT_U32 color ) + { + SYSFONT_DRAW( SYSFONT_U32, 32, 8, 8, 160 ); + } + + +void sysfont_texture_u8( SYSFONT_U8* texture, int pitch_in_bytes, SYSFONT_U8 color, SYSFONT_U8 bgcolor ) + { + SYSFONT_TEX(SYSFONT_U8); + } + + +void sysfont_texture_u16( SYSFONT_U16* texture, int pitch_in_bytes, SYSFONT_U16 color, SYSFONT_U16 bgcolor ) + { + SYSFONT_TEX(SYSFONT_U16); + } + + +void sysfont_texture_u32( SYSFONT_U32* texture, int pitch_in_bytes, SYSFONT_U32 color, SYSFONT_U32 bgcolor ) + { + SYSFONT_TEX(SYSFONT_U32); + } + + +#undef SYSFONT_TEX +#undef SYSFONT_DRAW +#undef SYSFONT_DATA + +#endif /* SYSFONT_IMPLEMENTATION */ + +/* +------------------------------------------------------------------------------ + +This software is available under 2 licenses - you may choose the one you like. + +------------------------------------------------------------------------------ + +ALTERNATIVE A - MIT License + +Copyright (c) 2015 Mattias Gustavsson + +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. + +------------------------------------------------------------------------------ + +ALTERNATIVE B - Public Domain (www.unlicense.org) + +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or distribute this +software, either in source code form or as a compiled binary, for any purpose, +commercial or non-commercial, and by any means. + +In jurisdictions that recognize copyright laws, the author or authors of this +software dedicate any and all copyright interest in the software to the public +domain. We make this dedication for the benefit of the public at large and to +the detriment of our heirs and successors. We intend this dedication to be an +overt act of relinquishment in perpetuity of all present and future rights to +this software under copyright law. + +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 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. + +------------------------------------------------------------------------------ +*/ diff --git a/pc/include/util.h b/pc/include/util.h new file mode 100644 index 0000000..9f635bf --- /dev/null +++ b/pc/include/util.h @@ -0,0 +1,35 @@ +/* + * 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 UTIL_H +#define UTIL_H + + +#include + + +char *utilCreateString(char *format, ...); +char *utilCreateStringVArgs(char *format, va_list args); + + +#endif // UTIL_H diff --git a/pc/src/flight.c b/pc/src/flight.c index cd765d7..7aeba27 100644 --- a/pc/src/flight.c +++ b/pc/src/flight.c @@ -39,6 +39,8 @@ airplaneT _plane; #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){ + return atan(x); +/* if (x >= 0) { if ( x<= 1) { return x + (ATAN_SPLINE_C0 + ATAN_SPLINE_C1 * x) * x * x; @@ -54,6 +56,7 @@ double ourAtan(double x){ return (x + (ATAN_SPLINE_C0 + ATAN_SPLINE_C1 * x) * x * x) - PI / 2; } } +*/ } @@ -78,13 +81,13 @@ void lightPlane(void) { // Start engine. if (!_plane.engine) _plane.engine = true; // Adjust RPM. - if (_plane.rpm < (375 + (_plane.throttle * 117))) _plane.rpm += _plane.loopTime * 0.5; //***TODO*** T + if (_plane.rpm < (375 + (_plane.throttle * 117))) _plane.rpm += _plane.loopTime * 0.5; if (_plane.rpm > (375 + (_plane.throttle * 117))) _plane.rpm -= _plane.loopTime * 0.5; } else { // Stop engine. if (_plane.engine) _plane.engine = false; // Run down engine. - if (_plane.rpm > 0) _plane.rpm -= (int16_t)(_plane.loopTime / 2); //***TODO*** This will never work. + if (_plane.rpm > 0) _plane.rpm -= (int16_t)(_plane.loopTime / 2); if (_plane.rpm < 0) _plane.rpm = 0; } @@ -118,16 +121,16 @@ void lightPlane(void) { // Shift range to 0..-17. _plane.lVeloc /= 5.29; // Multiply by pitch modifier. - _plane.lVeloc *= (-(_plane.pitch * .157) + 1); + _plane.lVeloc *= (-(_plane.pitch * 0.157) + 1); // Time slice. _plane.lVeloc /= 1000; _plane.lVeloc *= _plane.loopTime; // Gravity. - _plane.gVeloc = _plane.loopTime * (-16.0 / 10000); // -16.0 is ft/sec for gravity. + _plane.gVeloc = _plane.loopTime * (-16.0 / 1000); // -16.0 is ft/sec for gravity. // Sum vertical velocity. _plane.vSpeed = _plane.gVeloc + _plane.lVeloc; // No vertical speed if we're on the ground. - if (!_plane.airborne && (_plane.vSpeed < 0)) _plane.vSpeed = 0; + if ((!_plane.airborne) && (_plane.vSpeed < 0)) _plane.vSpeed = 0; // Save climb rate in ft/min. _plane.climbRate = _plane.vSpeed / _plane.loopTime; _plane.climbRate *= 60000L; @@ -190,7 +193,7 @@ void lightPlane2(void) { } if (_plane.hSpeed) { _plane.torque = 0.0; - if (_plane.rudder != 0) _plane.torque -= ((_plane.hSpeed * _plane.rudder) / 10000); + if (_plane.rudder != 0) _plane.torque = -((_plane.hSpeed * _plane.rudder) / 10000); _plane.torque2 = 0.0; if ((_plane.roll > 0) && (_plane.roll <= 90)) { //***FIX*** This is dumb. _plane.torque2 = _plane.roll * 0.00050; @@ -205,10 +208,10 @@ void lightPlane2(void) { // Flight model. Apply Rotations. // Transform pitch into components of yaw and pitch based on roll. - _plane.roll += _plane.dRoll; - _plane.yaw += _plane.dYaw; + _plane.roll += _plane.dRoll; + _plane.yaw += _plane.dYaw; _plane.pitch += (_plane.dPitch * cosD(_plane.roll)); - _plane.yaw += -(_plane.dPitch * sinD(_plane.roll)); + _plane.yaw += -(_plane.dPitch * sinD(_plane.roll)); if (_plane.roll > 180) { _plane.roll = -180 + (_plane.roll - 180); } else { @@ -254,22 +257,14 @@ void moveAircraft(void) { _plane.tmpZ = _plane.deltaZ; // Order of these points is significant. - // Rotate in Z. - _plane.newX = (_plane.tmpX * cosD(_plane.roll)) - (_plane.tmpY * sinD(_plane.roll)); - _plane.newY = (_plane.tmpX * sinD(_plane.roll)) + (_plane.tmpY * cosD(_plane.roll)); - _plane.tmpX = _plane.newX; - _plane.tmpY = _plane.newY; - // Rotate in X; - _plane.efAOF = Degs(_plane.efAOF); - _plane.newY = (_plane.tmpY * cosD(_plane.efAOF)) - (_plane.tmpZ * sinD(_plane.efAOF)); - _plane.newZ = (_plane.tmpY * sinD(_plane.efAOF)) + (_plane.tmpZ * cosD(_plane.efAOF)); + // Rotate in X. + _plane.newY = -(_plane.tmpZ * sinD(_plane.AOA)); + _plane.newZ = (_plane.tmpZ * cosD(_plane.AOA)); _plane.tmpY = _plane.newY; _plane.tmpZ = _plane.newZ; - // Rotate in X; - _plane.newX = (_plane.tmpZ * sinD(_plane.yaw)) + (_plane.tmpX * cosD(_plane.yaw)); - _plane.newZ = (_plane.tmpZ * cosD(_plane.yaw)) - (_plane.tmpX * sinD(_plane.yaw)); - _plane.tmpX = _plane.newX; - _plane.tmpZ = _plane.newZ; + // Rotate in Y. + _plane.newX = (_plane.tmpZ * sinD(_plane.yaw)); + _plane.newZ = (_plane.tmpZ * cosD(_plane.yaw)); // Translate rotated point back to where it should be // relative to it's last position. @@ -290,7 +285,7 @@ void moveAircraft(void) { } // Are we flying? - if ((!_plane.airborne) && (-_plane.y)) _plane.airborne = true; + if ((!_plane.airborne) && (_plane.y > PLANE_HEIGHT)) _plane.airborne = true; } @@ -298,6 +293,24 @@ void resetAircraft(void) { // Initialize airplane. memset(&_plane, 0, sizeof(airplaneT)); + _plane.brake = true; + /* + _plane.rpm = 0; + _plane.hSpeed = 0; + _plane.vSpeed = 0; + _plane.deltaZ = 0; + _plane.ignition = false; + _plane.engine = false; + _plane.efAOF = 0; + _plane.x = 0; + _plane.y = 0; + _plane.z = 0; + _plane.pitch = 0; + _plane.roll = 0; + _plane.yaw = 0; + _plane.airborne = false; + */ + _plane.loopTime = 40; } diff --git a/pc/src/main.c b/pc/src/main.c index 6dd7f95..403a468 100644 --- a/pc/src/main.c +++ b/pc/src/main.c @@ -25,18 +25,28 @@ #include "a23d2bin.h" #include "a23d2.h" #include "flight.h" +#include "util.h" #define APP_IMPLEMENTATION #define APP_SDL -#define APP_S16 int16_t -#define APP_U32 uint32_t -#define APP_U64 uint64_t +#define APP_S16 int16_t +#define APP_U32 uint32_t +#define APP_U64 uint64_t #include "app.h" +#define SYSFONT_IMPLEMENTATION +#define SYSFONT_U8 uint8_t +#define SYSFONT_U16 uint16_t +#define SYSFONT_U32 uint32_t +#include "sysfont.h" -#define HEIGHT 240 -#define WIDTH 320 + +#define HEIGHT 240 +#define WIDTH 320 +#define SCALE 1.25 // Scale factor for 256->320 +#define DEG2CAM 0.711111111 +#define CAM2DEG 1.40625 #define JOY_UP 1 @@ -105,6 +115,9 @@ uint16_t _drawlistInDatabase; *p++ = _color.g; \ *p++ = _color.b; \ *p++ = 255; \ + } else { \ + printf("CLIPPED!\n"); \ + fflush(0); \ } \ }) @@ -116,6 +129,7 @@ void jsr(uint16_t addr); void landscape(void); byte memoryRead(uint16_t addr, bool isDebug); void memoryWrite(uint16_t addr, byte value); +void printAt(uint8_t x, uint8_t y, char *format, ...); int appMain(app_t *app, void *userData); @@ -202,13 +216,15 @@ void draw(void) { y1 = 255 - ((int8_t)_RAM[pointer++] + 128); x2 = (int8_t)_RAM[pointer++] + 128; y2 = 255 - ((int8_t)_RAM[pointer++] + 128); - bitmapLine(x1, y1, x2, y2); + bitmapLine(x1 * SCALE, y1 / SCALE, x2 * SCALE, y2 / SCALE); continue; // Point. case PNT2D: x1 = (int8_t)_RAM[pointer++] + 128; y1 = 255 - ((int8_t)_RAM[pointer++] + 128); + x1 *= SCALE; + y1 /= SCALE; bitmapPutPixelIOSet(x1, y1); continue; @@ -262,13 +278,17 @@ void jsr(uint16_t addr) { void landscape(void) { - int16_t i; - int16_t x; - int16_t y; - int16_t min = 0; - int16_t max = 10000; - byte *db = _RAM; - uint16_t bytes = DATABASE; + int32_t i; + int32_t x; + int32_t z; + int32_t w; + int32_t l; + int32_t min = 0; + int32_t max = 30000; // A mile is 5280. + int32_t lines = 10; + int32_t skip = (abs(min) + abs(max)) / lines; + byte *db = _RAM; + uint16_t bytes = DATABASE; // All scene databases need to begin with the ARRAY and EYE records. @@ -297,7 +317,7 @@ void landscape(void) { db[bytes++] = STCOL; db[bytes++] = 2; // Green - for (i=min; i<=max; i+=1000) { + for (i=min; i<=max; i+=skip) { db[bytes++] = SPNT; db[bytes++] = LOW_BYTE(i); // X db[bytes++] = HIGH_BYTE(i); @@ -331,31 +351,70 @@ void landscape(void) { db[bytes++] = HIGH_BYTE(i); } - // Runway - 3000' x 100' - min = 3500; - max = min + 300; - x = 3500; + // Runway - 3000' x 200' + w = 200; + l = 3000; + x = skip * 3.5; + z = skip * 3.5; + printf("%dx%d\n", x, z); + db[bytes++] = STCOL; - db[bytes++] = 8; // Dark Grey - for (i=0; i<=10; i+=2) { + db[bytes++] = 7; // Light Grey + + db[bytes++] = SPNT; + db[bytes++] = LOW_BYTE(x); // X + db[bytes++] = HIGH_BYTE(x); + db[bytes++] = 0; // Y + db[bytes++] = 0; + db[bytes++] = LOW_BYTE(z); // Z + db[bytes++] = HIGH_BYTE(z); + + db[bytes++] = CPNT; + db[bytes++] = LOW_BYTE(x+w); // X + db[bytes++] = HIGH_BYTE(x+w); + db[bytes++] = 0; // Y + db[bytes++] = 0; + db[bytes++] = LOW_BYTE(z); // Z + db[bytes++] = HIGH_BYTE(z); + + db[bytes++] = CPNT; + db[bytes++] = LOW_BYTE(x+w); // X + db[bytes++] = HIGH_BYTE(x+w); + db[bytes++] = 0; // Y + db[bytes++] = 0; + db[bytes++] = LOW_BYTE(z+l); // Z + db[bytes++] = HIGH_BYTE(z+l); + + db[bytes++] = CPNT; + db[bytes++] = LOW_BYTE(x); // X + db[bytes++] = HIGH_BYTE(x); + db[bytes++] = 0; // Y + db[bytes++] = 0; + db[bytes++] = LOW_BYTE(z); // Z + db[bytes++] = HIGH_BYTE(z); + + db[bytes++] = STCOL; + db[bytes++] = 15; // White + + skip = l / (lines * 2); + x += (w / 2); + for (i=z + skip; ix = 5000; - _camera->y = 1000; - _camera->z = 5000; - _camera->p = 25; + _camera->x = 10600; + _camera->y = PLANE_HEIGHT; + _camera->z = 10500; + _camera->p = 0; + _camera->h = 0; // Set up render surface. _pixels = (byte *)malloc(HEIGHT * WIDTH * 4); // Build a plane! resetAircraft(); + _plane.z = _camera->y; + _plane.y = -_camera->z; + _plane.x = _camera->x; + _plane.pitch = -_camera->p * CAM2DEG; + _plane.yaw = _camera->h * CAM2DEG; + _plane.roll = _camera->b * CAM2DEG; // No input. _gamepad = 0; + // Reset timers + fps = 0; + milliseconds = 0; + lastTime = app_time_count(app); + // Loop until exit. while (app_yield(app) != APP_STATE_EXIT_REQUESTED) { // Clear screen. memset(_pixels, 0, HEIGHT * WIDTH * 4); - // 3D Viewport edge. - colorSet(14); - bitmapLine(256, 0, 256, 239); - // Update drawlist. _RAM[_drawlistInDatabase + 1] = HIGH_BYTE(DRAWLIST_P0); _RAM[_drawlistInDatabase + 0] = LOW_BYTE(DRAWLIST_P0); @@ -444,6 +529,11 @@ int appMain(app_t *app, void *userData) { // Render. jsr(A23D2_NXTPT); draw(); + fps++; + + // Control Panel. + colorSet(8); + bitmapLine(0, 194, 319, 194); // Leaves 45 pixels at the bottom below this line. // Get input. input = app_input(app); @@ -521,8 +611,8 @@ int appMain(app_t *app, void *userData) { // Update aircraft control state. if ((_gamepad & JOY_BUTTON_1) || (_gamepad & JOY_BUTTON_2) || (_gamepad & JOY_BUTTON_3)) { // Modified input with button down. - if ((_gamepad & JOY_UP) && (_plane.throttle > -15)) _plane.throttle++; - if ((_gamepad & JOY_DOWN) && (_plane.throttle < 15)) _plane.throttle--; + if ((_gamepad & JOY_UP) && (_plane.throttle < 15)) _plane.throttle++; + if ((_gamepad & JOY_DOWN) && (_plane.throttle > 0)) _plane.throttle--; if (_gamepad & JOY_RIGHT) _plane.brake = !_plane.brake; } else { // No button pressed. @@ -531,21 +621,44 @@ int appMain(app_t *app, void *userData) { if ((_gamepad & JOY_LEFT) && (_plane.aileron > -15)) _plane.aileron--; if ((_gamepad & JOY_RIGHT) && (_plane.aileron < 15)) _plane.aileron++; } - // "Coordinated" flight. + + // We have no rudder input. "Coordinated" flight. _plane.rudder = _plane.aileron; + // We have no ignition input. + 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); + + // Update timers. + _plane.loopTime = (app_time_count(app) - lastTime) / timeFreqMs; + if (_plane.loopTime == 0) _plane.loopTime = 1; + lastTime = app_time_count(app); + milliseconds += _plane.loopTime; + if (milliseconds > 1000) { + milliseconds -= 1000; + fps = 0; + } + // FLY! updateAircraft(); // Move camera. - //_camera->p += 1; // Change pitch angle. - //_camera->b += 2; // Change bank angle. - _camera->h += 1; // Change heading angle. + _camera->x = _plane.x; + _camera->y = _plane.z; + _camera->z = -_plane.y; + _camera->p = -_plane.pitch * DEG2CAM; + _camera->b = _plane.roll * DEG2CAM; + _camera->h = _plane.yaw * DEG2CAM; - //printf("H = %d\n", _camera->h); + printAt(0, 0, "X:%d Y:%d Z:%d", _camera->x, _camera->y, _camera->z); + printAt(0, 1, "P:%d B:%d H:%d", _camera->p, _camera->b, _camera->h); // Update screen. - app_present(app, (APP_U32 *)_pixels, WIDTH, HEIGHT, 0xffffff, 0x000000); + app_present(app, (uint32_t *)_pixels, WIDTH, HEIGHT, 0xffffff, 0x000000); } // Destroy VM. diff --git a/pc/src/util.c b/pc/src/util.c new file mode 100644 index 0000000..7c0c466 --- /dev/null +++ b/pc/src/util.c @@ -0,0 +1,58 @@ +/* + * 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 +#include +#include + +#include "util.h" + + +char *utilCreateString(char *format, ...) { + va_list args; + char *string; + + va_start(args, format); + string = utilCreateStringVArgs(format, args); + va_end(args); + + return string; +} + + +__attribute__((__format__(__printf__, 1, 0))) +char *utilCreateStringVArgs(char *format, va_list args) { + va_list argsCopy; + int32_t size = 0; + char *buffer = NULL; + + va_copy(argsCopy, args); + size = vsnprintf(NULL, 0, format, argsCopy) + 1; + va_end(argsCopy); + buffer = calloc(1, (size_t)size); + if (buffer) { + vsnprintf(buffer, (size_t)size, format, args); + } + + return buffer; +}