Commit b3931a64 authored by Scott Duensing's avatar Scott Duensing

Rearranged folder, added image conversion tools.

parent afdd4dc8
*.sta filter=lfs diff=lfs merge=lfs -text
*.mod filter=lfs diff=lfs merge=lfs -text
*.vec filter=lfs diff=lfs merge=lfs -text
*~
*.user
lib/
src/SDL2/
src/music
src/music.w
src/*.dis
src/*.map
joeylib/lib/
joeylib/src/SDL2/
joeylib/src/music
joeylib/src/music.w
joeylib/src/*.dis
joeylib/src/*.map
TEMPLATE = app
CONFIG += console
CONFIG -= \
app_bundle \
qt
JOEY = /home/scott/joey
JOEY_INCLUDES = \
$$JOEY/dist
JOEY_HEADERS = \
$$JOEY/dist/joey.h
JOEY_LIBS = \
-L$$JOEY/dist/linux/x64 \
-Wl,-rpath,$$JOEY/dist/linux/x64 \
-Wl,--enable-new-dtags \
-l:joeylib.a \
-Wl,--no-undefined \
-ldl \
-lsndio \
-lpthread \
-lrt \
-lm
JOEY_FLAGS = \
-pthread \
-D_REENTRANT
SDL_IMAGE_LIBS = \
-lSDL2_image
QMAKE_CFLAGS += \
$$JOEY_FLAGS
INCLUDEPATH += \
$$JOEY_INCLUDES
HEADERS += \
$$JOEY_HEADERS
SOURCES += \
main.c
LIBS += \
$$JOEY_LIBS \
$$SDL_IMAGE_LIBS
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
#include <limits.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "joey.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
Uint32 getPixel(SDL_Surface *surface, int x, int y) {
int bpp = surface->format->BytesPerPixel;
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
switch(bpp) {
case 1:
return *p;
break;
case 2:
// Generates cast increases required alignment of target type [-Wcast-align] warning. Harmless on x86.
return *(Uint16 *)p;
break;
case 3:
if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
return (Uint32)(p[0] << 16 | p[1] << 8 | p[2]);
else
return (Uint32)(p[0] | p[1] << 8 | p[2] << 16);
break;
case 4:
// Generates cast increases required alignment of target type [-Wcast-align] warning. Harmless on x86.
return *(Uint32 *)p;
break;
default:
return 0;
}
}
#pragma GCC diagnostic pop
int main(int argc, char *argv[]) {
if (argc < 3) {
printf("Usage: %s [infile] [outfile] {anyting}\n", argv[0]);
printf("(If {anything} is provided, image will be displayed as converted until keypress.)\n");
return 1;
}
jlUtilStartup("STA Converter");
int imageFlags = IMG_INIT_JPG | IMG_INIT_PNG | IMG_INIT_TIF;
int imageResult = IMG_Init(imageFlags);
if ((imageResult & imageFlags) != imageFlags) {
printf("Failed to initialize SDL2_Image: %s\n", IMG_GetError());
jlUtilShutdown();
}
SDL_Surface *image = IMG_Load(argv[1]);
int colors = INT_MAX;
SDL_Color *c = NULL;
if (image->format->palette != NULL) {
colors = image->format->palette->ncolors;
if (colors > 16) {
colors = 16;
printf("Source palette has more than 16 colors. Only the first 16 will be used.\n");
}
c = image->format->palette->colors;
}
printf("%s = %dx%d, %d bits per pixel, %d colors\n", argv[1], image->w, image->h, image->format->BitsPerPixel, colors);
if (image->w != 320 || image->h != 200 || image->format->BitsPerPixel != 8 || colors > 16) {
printf("Image must be 320x200 pixels, 8 bits per pixel, with 16 or fewer colors.\n");
free(image);
IMG_Quit();
jlUtilShutdown();
}
jlStaT *sta = NULL;
jlStaCreate(sta);
for (int x=0; x<colors; x++) {
sta->palette[x].r = c[x].r / 16;
sta->palette[x].g = c[x].g / 16;
sta->palette[x].b = c[x].b / 16;
printf("Palette %03d = R%03d G%03d B%03d\n", x, sta->palette[x].r, sta->palette[x].g, sta->palette[x].b);
}
if (colors < 16) {
for (int x=colors; x<16; x++) {
sta->palette[x].r = 0;
sta->palette[x].g = 0;
sta->palette[x].b = 0;
printf("Palette %03d = R000 G000 B000 (added)\n", x);
}
}
int p = 0;
for (int y=0; y<image->h; y++) {
for (int x=0; x<image->w; x+=2) {
//printf("%02X %02X ", getPixel(image, x, y), getPixel(image, x + 1, y));
// These are backwards - no idea why yet.
sta->pixels[p].r = (unsigned char)getPixel(image, x, y);
sta->pixels[p++].l = (unsigned char)getPixel(image, x + 1, y);
}
}
jlStaSave(sta, argv[2]);
SDL_FreeSurface(image);
if (argc > 3) {
jlStaDisplay(sta);
jlDisplayPresent();
jlKeyWaitForAny();
}
IMG_Quit();
jlUtilShutdown();
}
......@@ -7,7 +7,7 @@ if [ -d ${OUT} ]; then
fi
mkdir -p ${OUT}
pushd ${JOEY}/joeylib/src
pushd ${JOEY}/joeylib/joeylib/src
iix assemble jIIgs.asm keep=31:/out/joey/jIIgsasm
iix compile jIIgs.c keep=31:/out/joey/jIIgsc
iix compile joey.c keep=31:/out/joey/joey
......@@ -25,8 +25,8 @@ iix dumpobj +D 31:/out/joey/test &> test.dis || true
php ${JOEY}/sdks/iix/ntconverter.php *.mod
popd
cp -f ${JOEY}/joeylib/lib/IIgs/Tool221#ba0000 ${JOEY}/dist/IIgs/.
cp -f ${JOEY}/joeylib/src/joey.h ${JOEY}/dist/.
cp -f ${JOEY}/joeylib/joeylib/lib/IIgs/Tool221#ba0000 ${JOEY}/dist/IIgs/.
cp -f ${JOEY}/joeylib/joeylib/src/joey.h ${JOEY}/dist/.
cp -f ${OUT}/joeylib ${JOEY}/dist/IIgs/joeylib#b20000
if [ ! -z $1 ]; then
......@@ -38,10 +38,10 @@ if [ ! -z $1 ]; then
rm ${IMPORT} 2> /dev/null || true
cp ${OUT}/test ${OUT}/Test#B30000
cp ${JOEY}/joeylib/src/kanga.sta ${OUT}/kanga.sta#060000
cp ${JOEY}/joeylib/src/font.sta ${OUT}/font.sta#060000
cp ${JOEY}/joeylib/src/music ${OUT}/music#D50000
cp ${JOEY}/joeylib/src/music.w ${OUT}/music.w#060000
cp ${JOEY}/joeylib/joeylib/src/kanga.sta ${OUT}/kanga.sta#060000
cp ${JOEY}/joeylib/joeylib/src/font.sta ${OUT}/font.sta#060000
cp ${JOEY}/joeylib/joeylib/src/music ${OUT}/music#D50000
cp ${JOEY}/joeylib/joeylib/src/music.w ${OUT}/music.w#060000
${CADIUS} createvolume ${IMPORT} ${VOL} 32MB > /dev/null
${CADIUS} createfolder ${IMPORT} ${VOL}/data > /dev/null
......
#!/bin/bash -e
BUILD="${JOEY}/joeylib/build"
SRC="${JOEY}/joeylib/src"
BUILD="${JOEY}/joeylib/joeylib/build"
SRC="${JOEY}/joeylib/joeylib/src"
function doBuild() {
......@@ -28,6 +28,10 @@ function doBuild() {
ar rcs joeylib.a *.o
rm *.o
popd
if [ -d "${BUILD}" ]; then
rm -rf "${BUILD}"
fi
}
CC="gcc"
......@@ -65,5 +69,3 @@ CFLAGS="-Wall -D_REENTRANT -I${SRC}"
DIST="${JOEY}/dist/macos/x64"
INSTALLED="${JOEY}/SDL2/installed/macos/x64/lib"
doBuild
rm -rf build
......@@ -58,16 +58,10 @@ int main(void) {
jlStaT *kanga = NULL;
jlStaT *font = NULL;
jlVecT *vec = NULL;
jint16 y;
jlUtilStartup("JoeyLib Test");
jlVecLoad(vec, "nowhere");
jlVecDisplay(vec, 0, 0);
jlDisplayPresent();
jlKeyWaitForAny();
jlStaLoad(kanga, "kanga");
jlStaLoad(font, "font");
......
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include "joey.h"
#define MAX_LINE_SIZE 8192
#define STATE_COMMAND 1
#define STATE_NUMBER 2
#define STATE_EXECUTE 3
#define COMMAND_COLOR 1 // C
#define COMMAND_CLEAR 2 // E
#define COMMAND_PLOT 3 // D (Draw)
#define COMMAND_LINE 4 // L
#define COMMAND_FILL 5 // F
#define COMMAND_PALETTE 6 // P
#define COMMAND_RESET 7 // R
#define COMMAND_HBOX 8 // B (Box)
#define COMMAND_FBOX 9 // S (Solid Box)
#define COMMAND_FILLTO 10 // T (FillTo)
typedef struct {
char *keyword;
byte command;
byte args;
} CommandT;
static CommandT commands[] = {
{ "COLOR", COMMAND_COLOR, 1 },
{ "CLEAR", COMMAND_CLEAR, 0 },
{ "PLOT", COMMAND_PLOT, 2 },
{ "LINE", COMMAND_LINE, 2 },
{ "FILL", COMMAND_FILL, 2 },
{ "PALETTE", COMMAND_PALETTE, 4 },
{ "PAL", COMMAND_PALETTE, 4 },
{ "RESET", COMMAND_RESET, 0 },
{ "BOX", COMMAND_HBOX, 4 },
{ "FILLEDBOX", COMMAND_FBOX, 4 },
{ "FBOX", COMMAND_FBOX, 4 },
{ "FILLTO", COMMAND_FILLTO, 3 }
};
// Ugly Macros
#define EMIT_COMMAND fputc((byte)data[0], out)
#define EMIT_COUNT fputc((byte)count, out)
#define EMIT_BYTE fputc((byte)data[i], out)
#define EMIT_JINT16 _emitJint16(data[i], out);
void _emitJint16(jint16 data, FILE *out) {
#ifdef JOEY_LITLE_ENDIAN
fputc((byte)(data & 0xFF), out);
fputc((byte)(data >> 8), out);
#else
fputc((byte)(data >> 8), out);
fputc((byte)(data & 0xFF), out);
#endif
}
int _stricmp(const char *a, const char *b) {
int ca;
int cb;
do {
ca = (unsigned char)*a++;
cb = (unsigned char)*b++;
if (islower(ca)) ca = toupper(ca);
if (islower(cb)) cb = toupper(cb);
} while (ca == cb && ca != '\0');
return ca - cb;
}
int main(int argc, char *argv[]) {
FILE *in;
FILE *out = NULL;
char line[MAX_LINE_SIZE];
char *token;
int tokenLength;
jint16 data[1024];
int dIndex;
int state;
int args;
int count;
int i;
int x;
jint16 x1;
jint16 y1;
jint16 x2;
jint16 y2;
if (argc < 3) {
printf("Usage: %s [infile] [outfile]\n", argv[0]);
return 1;
}
jlUtilStartup("JoeyLib VecDraw");
jlDisplayBorder(BORDER_BLACK);
while (!jlUtilMustExit()) {
in = fopen(argv[1], "rt");
if (in == NULL) {
jlUtilShutdown();
}
out = fopen(argv[2], "wb");
if (out == NULL) {
fclose(in);
jlUtilShutdown();
}
fputs("VEC", out); // File "Magic"
fputc(0, out); // Version
while (fgets(line, MAX_LINE_SIZE, in) != NULL) {
state = STATE_COMMAND;
dIndex = 0;
token = strtok(line, " ");
while (token != NULL) {
tokenLength = (int)strlen(token);
if (tokenLength > 0) {
// Handle Comments
if (token[0] == '#') {
break;
}
// Handle EOLs
if ((token[tokenLength - 1] == 10) || (token[tokenLength - 1] == 13)) {
tokenLength--;
token[tokenLength] = 0;
}
if (tokenLength > 0) {
//printf("[%s] %d\n", token, dIndex);
// What is this?
if (state == STATE_COMMAND) {
for (i=0; i<(int)(sizeof(commands)/sizeof(CommandT)); i++) {
//printf("Checking [%s] == [%s]\n", token, commands[i].keyword);
if (_stricmp(token, commands[i].keyword) == 0) {
data[dIndex++] = commands[i].command;
state = (commands[i].args == 0 ? STATE_EXECUTE : STATE_NUMBER);
//printf("Found [%s] expecting %d args\n", token, commands[i].args);
break;
}
}
if (state == STATE_COMMAND) {
printf("Unknown command [%s]\n", token);
break;
}
} else {
if (state == STATE_NUMBER) {
data[dIndex++] = (jint16)atoi(token);
}
}
}
}
token = strtok(NULL, " ");
}
// Can we execute this?
if (dIndex > 0) {
args = dIndex - 1;
i = 1;
//printf("Command %d with %d args\n", data[0], args);
switch (data[0]) {
case COMMAND_COLOR:
if (args == 1) {
EMIT_COMMAND;
EMIT_BYTE;
jlDrawColor((byte)data[i]);
}
break;
case COMMAND_CLEAR:
if (args == 0) {
EMIT_COMMAND;
jlDrawClear();
}
break;
case COMMAND_PLOT:
count = args % 2;
if (count == 0) {
count = args / 2;
EMIT_COMMAND;
EMIT_COUNT;
for (x=0; x<count; x++) {
EMIT_JINT16;
x1 = data[i++];
EMIT_BYTE;
y1 = data[i++];
jlDrawPoint(x1, y1);
}
}
break;
case COMMAND_LINE:
count = args % 2;
if ((count == 0) && (args >= 4)) {
count = args / 2;
EMIT_COMMAND;
EMIT_COUNT;
EMIT_JINT16;
x1 = data[i++];
EMIT_BYTE;
y1 = data[i++];
for (x=1; x<count; x++) {
EMIT_JINT16;
x2 = data[i++];
EMIT_BYTE;
y2 = data[i++];
jlDrawLine(x1, y1, x2, y2);
x1 = x2;
y1 = y2;
}
}
break;
case COMMAND_FILL:
count = args % 2;
if (count == 0) {
count = args / 2;
EMIT_COMMAND;
EMIT_COUNT;
for (x=0; x<count; x++) {
EMIT_JINT16;
x1 = data[i++];
EMIT_BYTE;
y1 = data[i++];
jlDrawFill(x1, y1);
}
}
break;
case COMMAND_PALETTE:
count = args % 4;
if (count == 0) {
count = args / 4;
EMIT_COMMAND;
EMIT_COUNT;
for (x=0; x<count; x++) {
EMIT_BYTE;
x1 = data[i++];
EMIT_BYTE;
y1 = data[i++];
EMIT_BYTE;
x2 = data[i++];
EMIT_BYTE;
y2 = data[i++];
jlPaletteSet((byte)x1, (byte)y1, (byte)x2, (byte)y2);
}
}
break;
case COMMAND_RESET:
if (args == 0) {
EMIT_COMMAND;
jlPaletteDefault();
}
break;
case COMMAND_HBOX:
count = args % 4;
if (count == 0) {
count = args / 4;
EMIT_COMMAND;
EMIT_COUNT;
for (x=0; x<count; x++) {
EMIT_JINT16;
x1 = data[i++];
EMIT_BYTE;
y1 = data[i++];
EMIT_JINT16;
x2 = data[i++];
EMIT_BYTE;
y2 = data[i++];
jlDrawBox(x1, y1, x2, y2);
}
}
break;
case COMMAND_FBOX:
count = args % 4;
if (count == 0) {
count = args / 4;
EMIT_COMMAND;
EMIT_COUNT;
for (x=0; x<count; x++) {
EMIT_JINT16;
x1 = data[i++];
EMIT_BYTE;
y1 = data[i++];
EMIT_JINT16;
x2 = data[i++];
EMIT_BYTE;
y2 = data[i++];
jlDrawBoxFilled(x1, y1, x2, y2);
}
}
break;
case COMMAND_FILLTO:
count = args % 3;
if (count == 0) {
count = args / 3;
EMIT_COMMAND;
EMIT_COUNT;
for (x=0; x<count; x++) {
EMIT_JINT16;
x1 = data[i++];
EMIT_BYTE;
y1 = data[i++];
EMIT_BYTE;
x2 = data[i++];
jlDrawFillTo(x1, y1, (byte)x2);
}
}
break;
}
jlDisplayPresent();
}
}
fclose(out);
fclose(in);
jlKeyWaitForAny();
} // while not exiting
jlUtilShutdown();
}
TEMPLATE = app
CONFIG += console
CONFIG -= \
app_bundle \
qt
JOEY = /home/scott/joey
JOEY_INCLUDES = \
$$JOEY/dist
JOEY_HEADERS = \
$$JOEY/dist/joey.h
JOEY_LIBS = \
-L$$JOEY/dist/linux/x64 \
-Wl,-rpath,$$JOEY/dist/linux/x64 \
-Wl,--enable-new-dtags \
-l:joeylib.a \
-Wl,--no-undefined \
-ldl \
-lsndio \
-lpthread \
-lrt \
-lm
JOEY_FLAGS = \
-pthread \
-D_REENTRANT
QMAKE_CFLAGS += \
$$JOEY_FLAGS
INCLUDEPATH += \
$$JOEY_INCLUDES
HEADERS += \
$$JOEY_HEADERS
SOURCES += \
main.c
LIBS += \
$$JOEY_LIBS
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment