The PC is flying!
This commit is contained in:
parent
9fe53fcae7
commit
eea86533cc
4 changed files with 73 additions and 66 deletions
|
@ -13,6 +13,7 @@ set(HEADERS
|
||||||
vrEmu6502.h
|
vrEmu6502.h
|
||||||
a23d2bin.h
|
a23d2bin.h
|
||||||
a23d2.h
|
a23d2.h
|
||||||
|
util.h
|
||||||
)
|
)
|
||||||
list(TRANSFORM HEADERS PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/include/")
|
list(TRANSFORM HEADERS PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/include/")
|
||||||
|
|
||||||
|
@ -21,6 +22,7 @@ set(SOURCE
|
||||||
main.c
|
main.c
|
||||||
flight.c
|
flight.c
|
||||||
vrEmu6502.c
|
vrEmu6502.c
|
||||||
|
util.c
|
||||||
)
|
)
|
||||||
list(TRANSFORM SOURCE PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/src/")
|
list(TRANSFORM SOURCE PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/src/")
|
||||||
|
|
||||||
|
@ -28,8 +30,6 @@ list(TRANSFORM SOURCE PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/src/")
|
||||||
add_executable(${CMAKE_PROJECT_NAME}
|
add_executable(${CMAKE_PROJECT_NAME}
|
||||||
${HEADERS}
|
${HEADERS}
|
||||||
${SOURCE}
|
${SOURCE}
|
||||||
src/util.c
|
|
||||||
include/util.h
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,5 +48,12 @@ target_link_libraries(${CMAKE_PROJECT_NAME}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE -fsanitize=address)
|
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE
|
||||||
target_link_options(${CMAKE_PROJECT_NAME} PRIVATE -fsanitize=address)
|
-Wall
|
||||||
|
-fsanitize=address
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
target_link_options(${CMAKE_PROJECT_NAME} PRIVATE
|
||||||
|
-fsanitize=address
|
||||||
|
)
|
||||||
|
|
|
@ -1013,6 +1013,8 @@ static int app_internal_opengl_init( app_t* app, struct app_internal_opengl_t* g
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||||
static int app_internal_opengl_term( struct app_internal_opengl_t* gl )
|
static int app_internal_opengl_term( struct app_internal_opengl_t* gl )
|
||||||
{
|
{
|
||||||
gl->DeleteProgram( gl->shader );
|
gl->DeleteProgram( gl->shader );
|
||||||
|
@ -1020,6 +1022,7 @@ static int app_internal_opengl_term( struct app_internal_opengl_t* gl )
|
||||||
gl->DeleteTextures( 1, &gl->texture );
|
gl->DeleteTextures( 1, &gl->texture );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
|
|
||||||
static int app_internal_opengl_present( struct app_internal_opengl_t* gl, APP_U32 const* pixels_xbgr, int width,
|
static int app_internal_opengl_present( struct app_internal_opengl_t* gl, APP_U32 const* pixels_xbgr, int width,
|
||||||
|
|
|
@ -30,7 +30,7 @@ airplaneT _plane;
|
||||||
#define SEGMENT_MATH
|
#define SEGMENT_MATH
|
||||||
|
|
||||||
|
|
||||||
#define PI 3.1415926
|
#define PI 3.1415
|
||||||
|
|
||||||
#define Rads(d) (((d) < 0 ? (d) + 360 : (d)) * (PI / 180))
|
#define Rads(d) (((d) < 0 ? (d) + 360 : (d)) * (PI / 180))
|
||||||
#define Degs(r) ((r) * (180 / PI))
|
#define Degs(r) ((r) * (180 / PI))
|
||||||
|
@ -279,13 +279,13 @@ void moveAircraft(void) {
|
||||||
_plane.collectY = 0;
|
_plane.collectY = 0;
|
||||||
}
|
}
|
||||||
_plane.collectZ += _plane.newZ;
|
_plane.collectZ += _plane.newZ;
|
||||||
if ((_plane.collectY > 1) || (_plane.collectY < -1)) {
|
if ((_plane.collectZ > 1) || (_plane.collectZ < -1)) {
|
||||||
_plane.z += _plane.collectZ;
|
_plane.z += _plane.collectZ;
|
||||||
_plane.collectZ = 0;
|
_plane.collectZ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Are we flying?
|
// Are we flying?
|
||||||
if ((!_plane.airborne) && (_plane.y > PLANE_HEIGHT)) _plane.airborne = true;
|
if ((!_plane.airborne) && (_plane.y != 0)) _plane.airborne = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -294,23 +294,6 @@ void resetAircraft(void) {
|
||||||
memset(&_plane, 0, sizeof(airplaneT));
|
memset(&_plane, 0, sizeof(airplaneT));
|
||||||
|
|
||||||
_plane.brake = true;
|
_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;
|
_plane.loopTime = 40;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,11 +58,6 @@
|
||||||
#define JOY_BUTTON_3 64
|
#define JOY_BUTTON_3 64
|
||||||
|
|
||||||
|
|
||||||
typedef struct ArgsS {
|
|
||||||
int count;
|
|
||||||
char **args;
|
|
||||||
} ArgsT;
|
|
||||||
|
|
||||||
typedef struct ColorS {
|
typedef struct ColorS {
|
||||||
byte r;
|
byte r;
|
||||||
byte g;
|
byte g;
|
||||||
|
@ -252,7 +247,7 @@ void draw(void) {
|
||||||
|
|
||||||
void jsr(uint16_t addr) {
|
void jsr(uint16_t addr) {
|
||||||
int32_t depth = 0;
|
int32_t depth = 0;
|
||||||
int32_t instructions = 0;
|
// int32_t instructions = 0;
|
||||||
uint16_t PC = addr;
|
uint16_t PC = addr;
|
||||||
|
|
||||||
vrEmu6502SetPC(_v6502, PC);
|
vrEmu6502SetPC(_v6502, PC);
|
||||||
|
@ -261,7 +256,7 @@ void jsr(uint16_t addr) {
|
||||||
// Did we execute an instruction?
|
// Did we execute an instruction?
|
||||||
if (PC != vrEmu6502GetPC(_v6502)) {
|
if (PC != vrEmu6502GetPC(_v6502)) {
|
||||||
PC = vrEmu6502GetPC(_v6502);
|
PC = vrEmu6502GetPC(_v6502);
|
||||||
instructions++;
|
// instructions++;
|
||||||
// Track JSRs & RTSs.
|
// Track JSRs & RTSs.
|
||||||
if (vrEmu6502GetCurrentOpcode(_v6502) == 0x20) depth++;
|
if (vrEmu6502GetCurrentOpcode(_v6502) == 0x20) depth++;
|
||||||
if (vrEmu6502GetCurrentOpcode(_v6502) == 0x60) {
|
if (vrEmu6502GetCurrentOpcode(_v6502) == 0x60) {
|
||||||
|
@ -372,15 +367,23 @@ void landscape(void) {
|
||||||
db[bytes++] = CPNT;
|
db[bytes++] = CPNT;
|
||||||
db[bytes++] = LOW_BYTE(x+w); // X
|
db[bytes++] = LOW_BYTE(x+w); // X
|
||||||
db[bytes++] = HIGH_BYTE(x+w);
|
db[bytes++] = HIGH_BYTE(x+w);
|
||||||
db[bytes++] = 0; // Y
|
db[bytes++] = 0; // Y
|
||||||
db[bytes++] = 0;
|
db[bytes++] = 0;
|
||||||
db[bytes++] = LOW_BYTE(z); // Z
|
db[bytes++] = LOW_BYTE(z); // Z
|
||||||
db[bytes++] = HIGH_BYTE(z);
|
db[bytes++] = HIGH_BYTE(z);
|
||||||
|
|
||||||
db[bytes++] = CPNT;
|
db[bytes++] = CPNT;
|
||||||
db[bytes++] = LOW_BYTE(x+w); // X
|
db[bytes++] = LOW_BYTE(x+w); // X
|
||||||
db[bytes++] = HIGH_BYTE(x+w);
|
db[bytes++] = HIGH_BYTE(x+w);
|
||||||
db[bytes++] = 0; // Y
|
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++] = 0;
|
||||||
db[bytes++] = LOW_BYTE(z+l); // Z
|
db[bytes++] = LOW_BYTE(z+l); // Z
|
||||||
db[bytes++] = HIGH_BYTE(z+l);
|
db[bytes++] = HIGH_BYTE(z+l);
|
||||||
|
@ -445,13 +448,15 @@ void printAt(uint8_t x, uint8_t y, char *format, ...) {
|
||||||
|
|
||||||
|
|
||||||
int appMain(app_t *app, void *userData) {
|
int appMain(app_t *app, void *userData) {
|
||||||
ArgsT *args = (ArgsT *)userData;
|
|
||||||
uint16_t bytes;
|
uint16_t bytes;
|
||||||
app_input_t input;
|
app_input_t input;
|
||||||
uint64_t timeFreqMs = app_time_freq(app) / 1000; // Divisor to get time in milliseconds
|
uint64_t timeFreqMs = app_time_freq(app) / 1000; // Divisor to get time in milliseconds
|
||||||
uint64_t milliseconds;
|
uint64_t milliseconds;
|
||||||
uint64_t lastTime;
|
uint64_t lastTime;
|
||||||
uint32_t fps;
|
uint32_t fps;
|
||||||
|
bool exit = false;
|
||||||
|
|
||||||
|
(void)userData;
|
||||||
|
|
||||||
// Set up window.
|
// Set up window.
|
||||||
app_screenmode(app, APP_SCREENMODE_WINDOW);
|
app_screenmode(app, APP_SCREENMODE_WINDOW);
|
||||||
|
@ -498,12 +503,12 @@ int appMain(app_t *app, void *userData) {
|
||||||
|
|
||||||
// Build a plane!
|
// Build a plane!
|
||||||
resetAircraft();
|
resetAircraft();
|
||||||
_plane.z = _camera->y;
|
|
||||||
_plane.y = -_camera->z;
|
|
||||||
_plane.x = _camera->x;
|
_plane.x = _camera->x;
|
||||||
|
_plane.y = _camera->y - PLANE_HEIGHT;
|
||||||
|
_plane.z = _camera->z;
|
||||||
_plane.pitch = -_camera->p * CAM2DEG;
|
_plane.pitch = -_camera->p * CAM2DEG;
|
||||||
|
_plane.roll = -_camera->b * CAM2DEG;
|
||||||
_plane.yaw = _camera->h * CAM2DEG;
|
_plane.yaw = _camera->h * CAM2DEG;
|
||||||
_plane.roll = _camera->b * CAM2DEG;
|
|
||||||
|
|
||||||
// No input.
|
// No input.
|
||||||
_gamepad = 0;
|
_gamepad = 0;
|
||||||
|
@ -514,7 +519,7 @@ int appMain(app_t *app, void *userData) {
|
||||||
lastTime = app_time_count(app);
|
lastTime = app_time_count(app);
|
||||||
|
|
||||||
// Loop until exit.
|
// Loop until exit.
|
||||||
while (app_yield(app) != APP_STATE_EXIT_REQUESTED) {
|
while ((!exit) && (app_yield(app) != APP_STATE_EXIT_REQUESTED)) {
|
||||||
// Clear screen.
|
// Clear screen.
|
||||||
memset(_pixels, 0, HEIGHT * WIDTH * 4);
|
memset(_pixels, 0, HEIGHT * WIDTH * 4);
|
||||||
|
|
||||||
|
@ -602,32 +607,43 @@ int appMain(app_t *app, void *userData) {
|
||||||
_gamepad &= ~JOY_BUTTON_3;
|
_gamepad &= ~JOY_BUTTON_3;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case APP_KEY_ESCAPE:
|
||||||
|
exit = true;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update aircraft control state.
|
// Hack. Slow down input.
|
||||||
if ((_gamepad & JOY_BUTTON_1) || (_gamepad & JOY_BUTTON_2) || (_gamepad & JOY_BUTTON_3)) {
|
if (fps % 5 == 0) {
|
||||||
// Modified input with button down.
|
// Update aircraft control state.
|
||||||
if ((_gamepad & JOY_UP) && (_plane.throttle < 15)) _plane.throttle++;
|
if ((_gamepad & JOY_BUTTON_1) || (_gamepad & JOY_BUTTON_2) || (_gamepad & JOY_BUTTON_3)) {
|
||||||
if ((_gamepad & JOY_DOWN) && (_plane.throttle > 0)) _plane.throttle--;
|
// Modified input with button down.
|
||||||
if (_gamepad & JOY_RIGHT) _plane.brake = !_plane.brake;
|
if ((_gamepad & JOY_UP) && (_plane.throttle < 15)) _plane.throttle++;
|
||||||
} else {
|
if ((_gamepad & JOY_DOWN) && (_plane.throttle > 0)) _plane.throttle--;
|
||||||
// No button pressed.
|
if (_gamepad & JOY_RIGHT) _plane.brake = !_plane.brake;
|
||||||
if ((_gamepad & JOY_UP) && (_plane.elevator > -15)) _plane.elevator--;
|
if (_gamepad & JOY_LEFT) {
|
||||||
if ((_gamepad & JOY_DOWN) && (_plane.elevator < 15)) _plane.elevator++;
|
_plane.elevator = 0;
|
||||||
if ((_gamepad & JOY_LEFT) && (_plane.aileron > -15)) _plane.aileron--;
|
_plane.aileron = 0;
|
||||||
if ((_gamepad & JOY_RIGHT) && (_plane.aileron < 15)) _plane.aileron++;
|
}
|
||||||
|
} else {
|
||||||
|
// No button pressed.
|
||||||
|
if ((_gamepad & JOY_UP) && (_plane.elevator > -15)) _plane.elevator--;
|
||||||
|
if ((_gamepad & JOY_DOWN) && (_plane.elevator < 15)) _plane.elevator++;
|
||||||
|
if ((_gamepad & JOY_LEFT) && (_plane.aileron > -15)) _plane.aileron--;
|
||||||
|
if ((_gamepad & JOY_RIGHT) && (_plane.aileron < 15)) _plane.aileron++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We have no rudder input. "Coordinated" flight.
|
||||||
|
_plane.rudder = _plane.aileron;
|
||||||
|
|
||||||
|
// We have no ignition input.
|
||||||
|
if (_plane.throttle) _plane.ignition = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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, 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, 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, 23, "T:%d E:%d A:%d B:%d", _plane.throttle, _plane.elevator, _plane.aileron, _plane.brake);
|
||||||
|
@ -648,14 +664,15 @@ int appMain(app_t *app, void *userData) {
|
||||||
|
|
||||||
// Move camera.
|
// Move camera.
|
||||||
_camera->x = _plane.x;
|
_camera->x = _plane.x;
|
||||||
_camera->y = _plane.z;
|
_camera->y = _plane.y + PLANE_HEIGHT;
|
||||||
_camera->z = -_plane.y;
|
_camera->z = _plane.z;
|
||||||
_camera->p = -_plane.pitch * DEG2CAM;
|
_camera->p = -_plane.pitch * DEG2CAM;
|
||||||
_camera->b = _plane.roll * DEG2CAM;
|
_camera->b = -_plane.roll * DEG2CAM;
|
||||||
_camera->h = _plane.yaw * DEG2CAM;
|
_camera->h = _plane.yaw * DEG2CAM;
|
||||||
|
|
||||||
printAt(0, 0, "X:%d Y:%d Z:%d", _camera->x, _camera->y, _camera->z);
|
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);
|
printAt(0, 1, "P:%d B:%d H:%d", _camera->p, _camera->b, _camera->h);
|
||||||
|
printAt(0, 2, "F:%d", fps);
|
||||||
|
|
||||||
// Update screen.
|
// Update screen.
|
||||||
app_present(app, (uint32_t *)_pixels, WIDTH, HEIGHT, 0xffffff, 0x000000);
|
app_present(app, (uint32_t *)_pixels, WIDTH, HEIGHT, 0xffffff, 0x000000);
|
||||||
|
@ -673,10 +690,7 @@ int appMain(app_t *app, void *userData) {
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
ArgsT args;
|
(void)argc;
|
||||||
|
(void)argv;
|
||||||
args.count = argc;
|
return app_run(appMain, NULL, NULL, NULL, NULL);
|
||||||
args.args = argv;
|
|
||||||
|
|
||||||
return app_run(appMain, &args, NULL, NULL, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue