230 lines
6 KiB
C
230 lines
6 KiB
C
/*
|
|
* 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 <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "a23d2.h"
|
|
|
|
|
|
#define LOW_BYTE(x) ((uint8_t)(x))
|
|
#define HIGH_BYTE(x) ((uint8_t)(((uint16_t)(x)) >> 8))
|
|
|
|
|
|
uint8_t db[8192] = { 0 };
|
|
uint16_t bytes = 0;
|
|
|
|
|
|
void cube(void) {
|
|
int16_t i = 0;
|
|
uint8_t scene[] = {
|
|
STCOL, 0x04, // Red
|
|
SPNT, 0x00, 0xff, 0x00, 0xff, 0x00, 0x03, // Cube
|
|
CPNT, 0x00, 0x01, 0x00, 0xff, 0x00, 0x03,
|
|
CPNT, 0x00, 0x01, 0x00, 0x01, 0x00, 0x03,
|
|
CPNT, 0x00, 0xff, 0x00, 0x01, 0x00, 0x03,
|
|
CPNT, 0x00, 0xff, 0x00, 0xff, 0x00, 0x03,
|
|
CPNT, 0x00, 0xff, 0x00, 0xff, 0x00, 0x05,
|
|
CPNT, 0x00, 0x01, 0x00, 0xff, 0x00, 0x05,
|
|
RAY, 0x00, 0x01, 0x00, 0xff, 0x00, 0x03,
|
|
CPNT, 0x00, 0x01, 0x00, 0x01, 0x00, 0x05,
|
|
RAY, 0x00, 0x01, 0x00, 0x01, 0x00, 0x03,
|
|
CPNT, 0x00, 0xff, 0x00, 0x01, 0x00, 0x05,
|
|
RAY, 0x00, 0xff, 0x00, 0x01, 0x00, 0x03,
|
|
CPNT, 0x00, 0xff, 0x00, 0xff, 0x00, 0x05,
|
|
SPNT, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, // Edge Line
|
|
CPNT, 0x00, 0x00, 0x80, 0x00, 0x00, 0x03,
|
|
END
|
|
};
|
|
|
|
while (scene[i] != END) {
|
|
db[bytes++] = scene[i++];
|
|
}
|
|
}
|
|
|
|
|
|
void landscape(void) {
|
|
int32_t i;
|
|
int32_t x;
|
|
int32_t z;
|
|
int32_t w;
|
|
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++] = 2; // Green
|
|
|
|
for (i=min; i<=max; i+=skip) {
|
|
db[bytes++] = SPNT;
|
|
db[bytes++] = LOW_BYTE(i); // X
|
|
db[bytes++] = HIGH_BYTE(i);
|
|
db[bytes++] = 0; // Y
|
|
db[bytes++] = 0;
|
|
db[bytes++] = LOW_BYTE(min); // Z
|
|
db[bytes++] = HIGH_BYTE(min);
|
|
|
|
db[bytes++] = CPNT;
|
|
db[bytes++] = LOW_BYTE(i); // X
|
|
db[bytes++] = HIGH_BYTE(i);
|
|
db[bytes++] = 0; // Y
|
|
db[bytes++] = 0;
|
|
db[bytes++] = LOW_BYTE(max); // Z
|
|
db[bytes++] = HIGH_BYTE(max);
|
|
|
|
db[bytes++] = SPNT;
|
|
db[bytes++] = LOW_BYTE(min); // X
|
|
db[bytes++] = HIGH_BYTE(min);
|
|
db[bytes++] = 0; // Y
|
|
db[bytes++] = 0;
|
|
db[bytes++] = LOW_BYTE(i); // Z
|
|
db[bytes++] = HIGH_BYTE(i);
|
|
|
|
db[bytes++] = CPNT;
|
|
db[bytes++] = LOW_BYTE(max); // X
|
|
db[bytes++] = HIGH_BYTE(max);
|
|
db[bytes++] = 0; // Y
|
|
db[bytes++] = 0;
|
|
db[bytes++] = LOW_BYTE(i); // Z
|
|
db[bytes++] = HIGH_BYTE(i);
|
|
}
|
|
|
|
// 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++] = 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+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++] = LOW_BYTE(x); // X
|
|
db[bytes++] = HIGH_BYTE(x);
|
|
db[bytes++] = 0; // Y
|
|
db[bytes++] = 0;
|
|
db[bytes++] = LOW_BYTE(i); // Z
|
|
db[bytes++] = HIGH_BYTE(i);
|
|
|
|
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(i+skip); // Z
|
|
db[bytes++] = HIGH_BYTE(i+skip);
|
|
}
|
|
db[bytes++] = END;
|
|
}
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
FILE *out;
|
|
|
|
(void)argc;
|
|
(void)argv;
|
|
|
|
// All scene databases need to begin with the ARRAY and EYE records.
|
|
// The CLPSW clipping setting is up to you. :-)
|
|
|
|
db[bytes++] = ARRAY; // Will be filled in by the program.
|
|
db[bytes++] = 0;
|
|
db[bytes++] = 0;
|
|
|
|
db[bytes++] = EYE; // Will be filled in by the program.
|
|
db[bytes++] = 0x00; // X
|
|
db[bytes++] = 0x00;
|
|
db[bytes++] = 0x00; // Y
|
|
db[bytes++] = 0x00;
|
|
db[bytes++] = 0x00; // Z
|
|
db[bytes++] = 0x00;
|
|
db[bytes++] = 0x00; // P
|
|
db[bytes++] = 0x00; // B
|
|
db[bytes++] = 0x00; // H
|
|
|
|
db[bytes++] = CLPSW;
|
|
db[bytes++] = 0x00;
|
|
|
|
//cube();
|
|
landscape();
|
|
|
|
db[bytes++] = END;
|
|
|
|
out = fopen("scene.3d", "wb");
|
|
if (out) {
|
|
fwrite(db, 1, 8192, out);
|
|
fclose(out);
|
|
}
|
|
|
|
return 0;
|
|
}
|