Pushing latest.

This commit is contained in:
Scott Duensing 2024-04-17 17:59:29 -05:00
parent d9db602f3d
commit fe52add80e
5 changed files with 107 additions and 40 deletions

View file

@ -28,7 +28,7 @@ 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"
CLANG="mos-f256k-clang -I${F256} -I$(pwd)/src -Os -Wall"
# Update f256lib and tools.

View file

@ -26,13 +26,13 @@
#include <string.h> // For memcopy
cameraT *_camera = (cameraT *)0x200; // Simulation copy of camera.
cameraT *_cameraInDatabase;
volatile cameraT *_camera = (cameraT *)0x200; // Simulation copy of camera.
volatile cameraT *_cameraInDatabase;
volatile byte *_pointer;
uint16_t _drawlist;
uint16_t _drawlistInDatabase;
byte *_pointer;
uint16_t _bytes;
uint8_t _x1;
uint8_t _y1;
@ -41,7 +41,7 @@ uint8_t _y2;
bool _useColor;
byte _mmu;
byte _ram;
float _trig;
//float _trig;
#define SEGMENT_A23D2
@ -50,14 +50,28 @@ float _trig;
// There's a lot of global use in here. We can't use the virtual stack.
#if 0
void a23d2Cos(void) {
// We need to manually page 0x54000 into 0x6000.
// This isn't actually large enough for A2-3D2 but what we should only
// lose Apple ][ stuff we're not using anyway.
POKE(MMU_MEM_BANK_3, A23D2_FAR_BLOCK);
// Map 0-359 into 0-255.
_tdata = _tdata % 359;
_y1 = (360/256) * _tdata;
// Call COSEX.
POKE(A23D2_TDATA, _y1);
asm("jsr %[addy]":: [addy] "i"(A23D2_COSEX));
__attribute__((leaf)) asm volatile("jsr %[addy]":: [addy] "i"(A23D2_COSEX));
// Convert to float.
_trig = (float)PEEKW(A23D2_TDATA) / 32768;
// Restore memory map.
POKE(MMU_MEM_BANK_3, 3);
}
#endif
void a23d2Draw(void) {
@ -118,7 +132,7 @@ void a23d2Init(void) {
POKE(MMU_MEM_BANK_3, A23D2_FAR_BLOCK);
// We're going to clobber from 0x80fb to 0x8101. Back it up.
memcpy((byte *)0x2f7, (byte *)A23D2_TEST_DATABASE, 0x06);
memcpy((byte *)(0x2ff - 0x06), (byte *)A23D2_TEST_DATABASE, 0x06);
// Initialize A2-3D2 so we can use the "fast entry point" (NXTPT) when rendering.
_bytes = 0;
@ -130,11 +144,11 @@ void a23d2Init(void) {
_pointer[_bytes++] = 0;
_pointer[_bytes++] = END; // Setup complete!
asm("jsr %[addy]":: [addy] "i"(A23D2_ENTRYS)); // Call ENTRYS. This preserves the ZP for us.
// asm("jsr 0x606c"); // Call ENTRYS. This preserves the ZP for us.
// __attribute__((leaf)) asm volatile("jsr %[addy]":: [addy] "i"(A23D2_ENTRYS)); // Call ENTRYS. This preserves the ZP for us.
__attribute__((leaf)) asm volatile("jsr 0x606c"); // Call ENTRYS. This preserves the ZP for us.
// Put back the RAM we clobbered.
memcpy((byte *)A23D2_TEST_DATABASE, (byte *)0x2f7, 0x06);
memcpy((byte *)A23D2_TEST_DATABASE, (byte *)(0x2ff - 0x06), 0x06);
// Move our 3D/2D data buffer at 0x56000 into slot 4.
POKE(MMU_MEM_BANK_4, DATABASE_FAR_BLOCK);
@ -160,6 +174,8 @@ void a23d2Init(void) {
void a23d2Render(void) {
uint16_t i;
// We need to manually page 0x54000 into 0x6000.
// This isn't actually large enough for A2-3D2 but what we should only
// lose Apple ][ stuff we're not using anyway.
@ -179,11 +195,30 @@ void a23d2Render(void) {
_cameraInDatabase->b = _camera->b;
_cameraInDatabase->h = _camera->h;
memcpy((byte *)0x29d, (byte *)A23D2_ZP_START, A23D2_ZP_LENGTH); // Save the ZP we're going to clobber.
POKEW(A23D2_IBP, DATABASE); // Set IBP.
__attribute__((leaf)) asm("jsr %[addy]":: [addy] "i"(A23D2_NXTPT) : "a","x","y","c","v"); // Call NXTPT.
// __attribute__((leaf)) asm("jsr 0x6118"::: "a","x","y","c","v"); // Call NXTPT.
memcpy((byte *)A23D2_ZP_START, (byte *)0x29d, A23D2_ZP_LENGTH); // Put the ZP back.
//memcpy((byte *)(0x2ff - A23D2_ZP_LENGTH), (byte *)A23D2_ZP_START, A23D2_ZP_LENGTH); // Save the ZP we're going to clobber.
for (i=0; i<A23D2_ZP_LENGTH; i++) POKE(0x2ff + i, PEEK(A23D2_ZP_START + i));
/*
__attribute__((leaf)) asm volatile( \
" ldx #%[length] \n" \
"%=: \n" \
" lda %[start],x \n" \
" sta %[dest],x \n" \
" dex \n" \
" bne %=b \n" \
: \
: [length] "i"(A23D2_ZP_LENGTH), [start] "i"(A23D2_ZP_START), [dest] "i"(0x2ff) \
: "a", "x", "c", "v");
*/
POKEW(A23D2_IBP, DATABASE); // Set IBP.
// __attribute__((leaf)) asm volatile("jsr %[addy]":: [addy] "i"(A23D2_NXTPT) : "a","x","y","c","v"); // Call NXTPT.
__attribute__((leaf)) asm volatile("jsr 0x6118"::: "a","x","y","c","v"); // Call NXTPT.
//memcpy((byte *)A23D2_ZP_START, (byte *)(0x2ff - A23D2_ZP_LENGTH), A23D2_ZP_LENGTH); // Put the ZP back.
for (i=0; i<A23D2_ZP_LENGTH; i++) POKE(A23D2_ZP_START + i, PEEK(0x2ff + i));
// Restore memory map.
POKE(MMU_MEM_BANK_4, 4);
@ -191,11 +226,25 @@ void a23d2Render(void) {
}
#if 0
void a23d2Sin(void) {
// We need to manually page 0x54000 into 0x6000.
// This isn't actually large enough for A2-3D2 but what we should only
// lose Apple ][ stuff we're not using anyway.
POKE(MMU_MEM_BANK_3, A23D2_FAR_BLOCK);
// Map 0-359 into 0-255.
_tdata = _tdata % 359;
_y1 = (360/256) * _tdata;
// Call SINEX.
POKE(A23D2_TDATA, _y1);
asm("jsr %[addy]":: [addy] "i"(A23D2_SINEX));
__attribute__((leaf)) asm volatile("jsr %[addy]":: [addy] "i"(A23D2_SINEX));
// Convert to float.
_trig = (float)PEEKW(A23D2_TDATA) / 32768;
// Restore memory map.
POKE(MMU_MEM_BANK_3, 3);
}
#endif

View file

@ -102,13 +102,13 @@ typedef struct cameraS {
} cameraT;
extern cameraT *_camera;
extern cameraT *_cameraInDatabase;
extern volatile cameraT *_camera;
extern volatile cameraT *_cameraInDatabase;
extern volatile byte *_pointer;
extern uint16_t _drawlist;
extern uint16_t _drawlistInDatabase;
extern byte *_pointer;
extern uint16_t _bytes;
extern uint8_t _x1;
#define _tdata _x1 // Alias.
@ -121,7 +121,8 @@ extern byte _ram;
extern float _trig;
// NOTE:
// There are no function prototypes in this header.
// This library lives in it's own overlay segment and the overlay tool
// will generate prototypes as well as trampoline macros for us.
void a23d2Cos(void);
void a23d2Draw(void);
void a23d2Init(void);
void a23d2Render(void);
void a23d2Sin(void);

View file

@ -132,6 +132,7 @@
#include "a23d2.h"
#if 0
typedef struct airplaneS {
int8_t aileron; // -15 to 15
int8_t elevator; // -15 to 15
@ -159,6 +160,7 @@ typedef struct airplaneS {
airplaneT _plane;
byte _gamepad;
#endif
/*
@ -171,7 +173,8 @@ byte _gamepad;
EMBED(".binarydata.embedded", embedded, "embedded.bin");
#define SEGMENT_MATH
#if 0
//#define SEGMENT_MATH
#define PI 3.1415926
@ -215,7 +218,7 @@ float cos(float d) {
}
#define SEGMENT_INPUT
//#define SEGMENT_INPUT
void getInput(void) {
@ -306,7 +309,7 @@ void getInput(void) {
}
#define SEGMENT_FLIGHT_MODEL_1
//#define SEGMENT_FLIGHT_MODEL_1
// These didn't use to be global. Ugly.
@ -328,12 +331,13 @@ float torque2;
uint16_t loopTime = 40;
static double dPitch = 0;
static double dYaw = 0;
static double dRoll = 0;
static float collectX = 0;
static float collectY = 0;
static float collectZ = 0;
// Used to be static. Need preserved.
double dPitch = 0;
double dYaw = 0;
double dRoll = 0;
float collectX = 0;
float collectY = 0;
float collectZ = 0;
@ -425,7 +429,7 @@ void lightPlane(void) {
}
#define SEGMENT_FLIGHT_MODEL_2
//#define SEGMENT_FLIGHT_MODEL_2
void lightPlane2(void) {
@ -511,7 +515,7 @@ void lightPlane2(void) {
}
#define SEGMENT_FLIGHT_MODEL_3
//#define SEGMENT_FLIGHT_MODEL_3
void moveAircraft(void) {
@ -559,6 +563,7 @@ void moveAircraft(void) {
// Are we flying?
if ((!_plane.airborne) && (-_plane.y)) _plane.airborne = true;
}
#endif
#define SEGMENT_MAIN
@ -568,7 +573,7 @@ void runSimulation(void) {
bool pageZero;
// Initialize airplane.
memset(&_plane, 0, sizeof(airplaneT));
// memset(&_plane, 0, sizeof(airplaneT));
// Which page is visible?
pageZero = true;
@ -596,13 +601,17 @@ void runSimulation(void) {
// Erase old scene.
bitmapSetColor(0);
_useColor = false;
textPrint("a23d2Draw()\n");
a23d2Draw();
// Draw new scene.
textPrint("a23d2Render()\n");
a23d2Render();
_useColor = true;
textPrint("a23d2Draw()\n");
a23d2Draw();
#if 0
// Update player input.
getInput();
@ -626,11 +635,12 @@ void runSimulation(void) {
lightPlane();
lightPlane2();
moveAircraft();
#endif
// Move camera.
_camera->p += 1; // Change pitch angle.
_camera->b += 2; // Change bank angle.
_camera->h += 3; // Change heading angle.
//_camera->p += 1; // Change pitch angle.
//_camera->b += 2; // Change bank angle.
_camera->h += 1; // Change heading angle.
}
}
@ -660,8 +670,14 @@ int main(int argc, char *argv[]) {
// Load EGA palette into CLUT0.
for (c=0; c<16; c++) graphicsDefineColor(0, c, ega[c][0], ega[c][1], ega[c][2]);
textPrint("a23d2Init()\n");
a23d2Init();
_camera->x = 5000;
_camera->y = 1000;
_camera->z = 5000;
_camera->p = 25;
// Set up bitmap planes.
for (c=0; c<2; c++) {
// Clear screen.
@ -675,6 +691,7 @@ int main(int argc, char *argv[]) {
bitmapSetVisible(0, true);
bitmapSetVisible(1, false);
textPrint("runSimulation()\n");
runSimulation();
return 0;

View file

@ -107,9 +107,9 @@ void landscape(void) {
}
// Runway - 3000' x 100'
min = 1500;
min = 3500;
max = min + 300;
x = 1500;
x = 3500;
db[bytes++] = STCOL;
db[bytes++] = 8; // Dark Grey
for (i=0; i<=10; i+=2) {