F256 3D scene and view updated to match PC.
This commit is contained in:
parent
dcd51e860e
commit
ecb49409e7
3 changed files with 110 additions and 36 deletions
40
src/a23d2.c
40
src/a23d2.c
|
@ -26,6 +26,17 @@
|
||||||
#include <string.h> // For memcopy
|
#include <string.h> // For memcopy
|
||||||
|
|
||||||
|
|
||||||
|
#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.
|
||||||
|
#define SCREEN3DXH 128 // Half of SCREEN3DX.
|
||||||
|
#define SCREEN3DYH 117 // Half of SCREEN3DY.
|
||||||
|
|
||||||
|
|
||||||
|
byte _scaleX[SCREEN3DX + 1];
|
||||||
|
byte _scaleY[SCREEN3DY + 1];
|
||||||
|
|
||||||
|
|
||||||
volatile cameraT *_camera = (cameraT *)CAMERA_SHARED_START; // Simulation copy of camera.
|
volatile cameraT *_camera = (cameraT *)CAMERA_SHARED_START; // Simulation copy of camera.
|
||||||
volatile cameraT *_cameraInDatabase;
|
volatile cameraT *_cameraInDatabase;
|
||||||
volatile byte *_pointer;
|
volatile byte *_pointer;
|
||||||
|
@ -44,6 +55,7 @@ byte _ram;
|
||||||
//float _trig;
|
//float _trig;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define SEGMENT_A23D2
|
#define SEGMENT_A23D2
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,18 +98,18 @@ void a23d2Draw(void) {
|
||||||
|
|
||||||
// Line.
|
// Line.
|
||||||
case (byte)LIN2D:
|
case (byte)LIN2D:
|
||||||
_x1 = (uint8_t)((int8_t)(*_pointer++) + 128);
|
_x1 = (uint8_t)((int8_t)(*_pointer++) + SCREEN3DXH);
|
||||||
_y1 = 255 - (uint8_t)((int8_t)(*_pointer++) + 128);
|
_y1 = SCREEN3DYH - (int8_t)(*_pointer++);
|
||||||
_x2 = (uint8_t)((int8_t)(*_pointer++) + 128);
|
_x2 = (uint8_t)((int8_t)(*_pointer++) + SCREEN3DXH);
|
||||||
_y2 = 255 - (uint8_t)((int8_t)(*_pointer++) + 128);
|
_y2 = SCREEN3DYH - (int8_t)(*_pointer++);
|
||||||
bitmapLine(_x1, _y1, _x2, _y2);
|
bitmapLine(_x1 + _scaleX[_x1], _scaleY[_y1], _x2 + _scaleX[_x2], _scaleY[_y2]);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Point.
|
// Point.
|
||||||
case (byte)PNT2D:
|
case (byte)PNT2D:
|
||||||
_x1 = (uint8_t)((int8_t)(*_pointer++) + 128);
|
_x1 = (uint8_t)((int8_t)(*_pointer++) + SCREEN3DXH);
|
||||||
_y1 = 255 - (uint8_t)((int8_t)(*_pointer++) + 128);
|
_y1 = SCREEN3DYH - (int8_t)(*_pointer++);
|
||||||
bitmapPutPixel(_x1, _y1);
|
bitmapPutPixel(_x1 + _scaleX[_x1], _scaleY[_y1]);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Set Color.
|
// Set Color.
|
||||||
|
@ -138,9 +150,9 @@ void a23d2Init(void) {
|
||||||
// Initialize A2-3D2 so we can use the "fast entry point" (NXTPT) when rendering.
|
// Initialize A2-3D2 so we can use the "fast entry point" (NXTPT) when rendering.
|
||||||
_bytes = 0;
|
_bytes = 0;
|
||||||
_pointer = (byte *)A23D2_TEST_DATABASE; // Standard location for test database in A2-3D2.
|
_pointer = (byte *)A23D2_TEST_DATABASE; // Standard location for test database in A2-3D2.
|
||||||
_pointer[_bytes++] = SCRSZ; // Screen size. 256x240. Center is 0,0.
|
_pointer[_bytes++] = SCRSZ; // Screen size. 255x233. Center is 0,0. We're going to scale this up.
|
||||||
_pointer[_bytes++] = 255;
|
_pointer[_bytes++] = SCREEN3DX; // Scales up to 320.
|
||||||
_pointer[_bytes++] = 239;
|
_pointer[_bytes++] = SCREEN3DY; // Scales up to 193 (leaves 46 pixels for a control panel).
|
||||||
_pointer[_bytes++] = 0;
|
_pointer[_bytes++] = 0;
|
||||||
_pointer[_bytes++] = 0;
|
_pointer[_bytes++] = 0;
|
||||||
_pointer[_bytes++] = END; // Setup complete!
|
_pointer[_bytes++] = END; // Setup complete!
|
||||||
|
@ -180,6 +192,12 @@ void a23d2Init(void) {
|
||||||
// Restore memory map.
|
// Restore memory map.
|
||||||
POKE(MMU_MEM_BANK_4, 4);
|
POKE(MMU_MEM_BANK_4, 4);
|
||||||
POKE(MMU_MEM_BANK_3, 3);
|
POKE(MMU_MEM_BANK_3, 3);
|
||||||
|
|
||||||
|
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -689,9 +689,9 @@ int main(int argc, char *argv[]) {
|
||||||
bitmapSetActive(c);
|
bitmapSetActive(c);
|
||||||
bitmapSetColor(0);
|
bitmapSetColor(0);
|
||||||
bitmapClear();
|
bitmapClear();
|
||||||
// 3D Viewport edge.
|
// Control Panel.
|
||||||
bitmapSetColor(14);
|
bitmapSetColor(8);
|
||||||
bitmapLine(256, 0, 256, 239);
|
bitmapLine(0, 194, 319, 194); // Leaves 45 pixels at the bottom below this line.
|
||||||
}
|
}
|
||||||
bitmapSetVisible(0, true);
|
bitmapSetVisible(0, true);
|
||||||
bitmapSetVisible(1, false);
|
bitmapSetVisible(1, false);
|
||||||
|
|
100
tools/scene.c
100
tools/scene.c
|
@ -63,16 +63,22 @@ void cube(void) {
|
||||||
|
|
||||||
|
|
||||||
void landscape(void) {
|
void landscape(void) {
|
||||||
int16_t i;
|
int32_t i;
|
||||||
int16_t x;
|
int32_t x;
|
||||||
int16_t y;
|
int32_t z;
|
||||||
int16_t min = 0;
|
int32_t w;
|
||||||
int16_t max = 10000;
|
int32_t l;
|
||||||
|
int32_t min = 0;
|
||||||
|
int32_t max = 20000; // A mile is 5280.
|
||||||
|
int32_t lines = 10;
|
||||||
|
int32_t skip = (abs(min) + abs(max)) / lines;
|
||||||
|
|
||||||
|
// Landscape
|
||||||
|
|
||||||
db[bytes++] = STCOL;
|
db[bytes++] = STCOL;
|
||||||
db[bytes++] = 2; // Green
|
db[bytes++] = 2; // Green
|
||||||
|
|
||||||
for (i=min; i<=max; i+=1000) {
|
for (i=min; i<=max; i+=skip) {
|
||||||
db[bytes++] = SPNT;
|
db[bytes++] = SPNT;
|
||||||
db[bytes++] = LOW_BYTE(i); // X
|
db[bytes++] = LOW_BYTE(i); // X
|
||||||
db[bytes++] = HIGH_BYTE(i);
|
db[bytes++] = HIGH_BYTE(i);
|
||||||
|
@ -106,29 +112,79 @@ void landscape(void) {
|
||||||
db[bytes++] = HIGH_BYTE(i);
|
db[bytes++] = HIGH_BYTE(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Runway - 3000' x 100'
|
// Runway - 3000' x 200'
|
||||||
min = 3500;
|
w = 200;
|
||||||
max = min + 300;
|
l = 3000;
|
||||||
x = 3500;
|
x = skip * 3.5;
|
||||||
|
z = skip * 3.5;
|
||||||
|
//printf("%dx%d\n", x, z);
|
||||||
|
|
||||||
db[bytes++] = STCOL;
|
db[bytes++] = STCOL;
|
||||||
db[bytes++] = 8; // Dark Grey
|
db[bytes++] = 7; // Light Grey
|
||||||
for (i=0; i<=10; i+=2) {
|
|
||||||
|
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+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; i<z+l-skip; i+=(skip*2)) {
|
||||||
db[bytes++] = SPNT;
|
db[bytes++] = SPNT;
|
||||||
db[bytes++] = LOW_BYTE(x+i); // X
|
db[bytes++] = LOW_BYTE(x); // X
|
||||||
db[bytes++] = HIGH_BYTE(x+i);
|
db[bytes++] = HIGH_BYTE(x);
|
||||||
db[bytes++] = 0; // Y
|
db[bytes++] = 0; // Y
|
||||||
db[bytes++] = 0;
|
db[bytes++] = 0;
|
||||||
db[bytes++] = LOW_BYTE(min); // Z
|
db[bytes++] = LOW_BYTE(i); // Z
|
||||||
db[bytes++] = HIGH_BYTE(min);
|
db[bytes++] = HIGH_BYTE(i);
|
||||||
|
|
||||||
db[bytes++] = CPNT;
|
db[bytes++] = CPNT;
|
||||||
db[bytes++] = LOW_BYTE(x+i); // X
|
db[bytes++] = LOW_BYTE(x); // X
|
||||||
db[bytes++] = HIGH_BYTE(x+i);
|
db[bytes++] = HIGH_BYTE(x);
|
||||||
db[bytes++] = 0; // Y
|
db[bytes++] = 0; // Y
|
||||||
db[bytes++] = 0;
|
db[bytes++] = 0;
|
||||||
db[bytes++] = LOW_BYTE(max); // Z
|
db[bytes++] = LOW_BYTE(i+skip); // Z
|
||||||
db[bytes++] = HIGH_BYTE(max);
|
db[bytes++] = HIGH_BYTE(i+skip);
|
||||||
}
|
}
|
||||||
|
db[bytes++] = END;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue