sierrahotel/tools/scene.c
2024-04-09 19:40:47 -05:00

174 lines
4.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) {
int16_t i;
int16_t x;
int16_t y;
int16_t min = 0;
int16_t max = 10000;
db[bytes++] = STCOL;
db[bytes++] = 2; // Green
for (i=min; i<=max; i+=1000) {
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 100'
min = 1500;
max = min + 300;
x = 1500;
db[bytes++] = STCOL;
db[bytes++] = 8; // Dark Grey
for (i=0; i<=10; i+=2) {
db[bytes++] = SPNT;
db[bytes++] = LOW_BYTE(x+i); // X
db[bytes++] = HIGH_BYTE(x+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(x+i); // X
db[bytes++] = HIGH_BYTE(x+i);
db[bytes++] = 0; // Y
db[bytes++] = 0;
db[bytes++] = LOW_BYTE(max); // Z
db[bytes++] = HIGH_BYTE(max);
}
}
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;
}