Updated to latest JoeyLib API. Added {B} command to display bitmaps.

This commit is contained in:
Scott Duensing 2020-07-07 17:14:27 -05:00
parent be75c40812
commit e4f974496e
11 changed files with 97 additions and 98 deletions

2
.gitattributes vendored
View file

@ -1,4 +1,4 @@
*.sta filter=lfs diff=lfs merge=lfs -text *.img filter=lfs diff=lfs merge=lfs -text
*.z5 filter=lfs diff=lfs merge=lfs -text *.z5 filter=lfs diff=lfs merge=lfs -text
*.z8 filter=lfs diff=lfs merge=lfs -text *.z8 filter=lfs diff=lfs merge=lfs -text
*.vec filter=lfs diff=lfs merge=lfs -text *.vec filter=lfs diff=lfs merge=lfs -text

View file

@ -37,7 +37,7 @@ static byte _number = 0;
static byte _parameters[5]; static byte _parameters[5];
static byte _parameterCount = 0; static byte _parameterCount = 0;
static byte _hiddenLines = 0; static byte _hiddenLines = 0;
static jlStaT *_ansiFont = NULL; static jlImgT *_ansiFont = NULL;
static PositionT _cursorSave; static PositionT _cursorSave;
static PositionT _cursor; static PositionT _cursor;
static PositionT *_screenBuffer = NULL; static PositionT *_screenBuffer = NULL;
@ -161,35 +161,35 @@ bool termParseANSI(char c) {
// Cursor up. // Cursor up.
case 'A': case 'A':
y = _number; y = _number;
termDebug("Moving cursor up %d", y); //termDebug("Moving cursor up %d", y);
termMoveCursor(cursor.x, cursor.y - y); termMoveCursor(cursor.x, cursor.y - y);
termResetSequence(); termResetSequence();
break; break;
// Cursor down. // Cursor down.
case 'B': case 'B':
y = _number; y = _number;
termDebug("Moving cursor down %d", y); //termDebug("Moving cursor down %d", y);
termMoveCursor(cursor.x, cursor.y + y); termMoveCursor(cursor.x, cursor.y + y);
termResetSequence(); termResetSequence();
break; break;
// Cursor forward. // Cursor forward.
case 'C': case 'C':
x = _number; x = _number;
termDebug("Moving cursor right %d", x); //termDebug("Moving cursor right %d", x);
termMoveCursor(cursor.x + x, cursor.y); termMoveCursor(cursor.x + x, cursor.y);
termResetSequence(); termResetSequence();
break; break;
// Cursor backward. // Cursor backward.
case 'D': case 'D':
x = _number; x = _number;
termDebug("Moving cursor left %d", x); //termDebug("Moving cursor left %d", x);
termMoveCursor(cursor.x - x, cursor.y); termMoveCursor(cursor.x - x, cursor.y);
termResetSequence(); termResetSequence();
break; break;
// Cursor line down. // Cursor line down.
case 'E': case 'E':
y = _number; y = _number;
termDebug("Moving cursor down line %d", y); //termDebug("Moving cursor down line %d", y);
termMoveCursor(1, cursor.y + y); termMoveCursor(1, cursor.y + y);
//***TODO*** This should allow scrolling //***TODO*** This should allow scrolling
termResetSequence(); termResetSequence();
@ -197,14 +197,14 @@ bool termParseANSI(char c) {
// Cursor line up. // Cursor line up.
case 'F': case 'F':
y = _number; y = _number;
termDebug("Moving cursor up line %d", y); //termDebug("Moving cursor up line %d", y);
termMoveCursor(1, cursor.y - y); termMoveCursor(1, cursor.y - y);
termResetSequence(); termResetSequence();
break; break;
// Cursor horizontal absolute. // Cursor horizontal absolute.
case 'G': case 'G':
x = _number; x = _number;
termDebug("Moving cursor horizontally to %d", x); //termDebug("Moving cursor horizontally to %d", x);
termMoveCursor(x, cursor.y); termMoveCursor(x, cursor.y);
termResetSequence(); termResetSequence();
break; break;
@ -215,14 +215,14 @@ bool termParseANSI(char c) {
case 0: case 0:
// Absolute position, Y. Kinda. Moves X to 1. // Absolute position, Y. Kinda. Moves X to 1.
y = _number; y = _number;
termDebug("Moving cursor to 1x%d", y); //termDebug("Moving cursor to 1x%d", y);
termMoveCursor(1, y); termMoveCursor(1, y);
break; break;
case 1: case 1:
// Absolute position. // Absolute position.
x = _number; x = _number;
y = _parameters[0]; y = _parameters[0];
termDebug("Moving cursor to %dx%d", x, y); //termDebug("Moving cursor to %dx%d", x, y);
termMoveCursor(x, y); termMoveCursor(x, y);
break; break;
default: default:
@ -234,7 +234,7 @@ bool termParseANSI(char c) {
// Clear display. // Clear display.
case 'J': case 'J':
if ((_parameterCount == 0) && (_number == 2)) { if ((_parameterCount == 0) && (_number == 2)) {
termDebug("Clear display"); //termDebug("Clear display");
termClearScreen(); termClearScreen();
updateDisplay = true; updateDisplay = true;
termMoveCursor(1, 1); termMoveCursor(1, 1);
@ -247,7 +247,7 @@ bool termParseANSI(char c) {
case 'K': case 'K':
x = _number; x = _number;
if (x == 0) { if (x == 0) {
termDebug("Clear to end of line"); //termDebug("Clear to end of line");
oldX = cursor.x; oldX = cursor.x;
for (cx=cursor.x; cx<=_columns; cx++) { for (cx=cursor.x; cx<=_columns; cx++) {
termMoveCursor(cx, cursor.y); termMoveCursor(cx, cursor.y);
@ -311,7 +311,7 @@ bool termParseANSI(char c) {
case 'm': case 'm':
_parameters[_parameterCount++] = _number; _parameters[_parameterCount++] = _number;
for (p=0; p<_parameterCount; p++) { for (p=0; p<_parameterCount; p++) {
termDebug("Set attribute %d", _parameters[p]); //termDebug("Set attribute %d", _parameters[p]);
x = _parameters[p]; x = _parameters[p];
switch (x) { switch (x) {
case 0: case 0:
@ -381,13 +381,13 @@ bool termParseANSI(char c) {
break; break;
// Cursor save. // Cursor save.
case 's': case 's':
termDebug("Saving cursor"); //termDebug("Saving cursor");
_cursorSave = cursor; _cursorSave = cursor;
termResetSequence(); termResetSequence();
break; break;
// Cursor restore. // Cursor restore.
case 'u': case 'u':
termDebug("Restoring cursor"); //termDebug("Restoring cursor");
termMoveCursor(_cursorSave.x, _cursorSave.y); termMoveCursor(_cursorSave.x, _cursorSave.y);
termResetSequence(); termResetSequence();
break; break;
@ -415,7 +415,7 @@ bool termParseANSI(char c) {
cursor.x--; cursor.x--;
} else { } else {
if (cursor.y > 1) { if (cursor.y > 1) {
termDebug("Cursor wrapped off left"); //termDebug("Cursor wrapped off left");
cursor.y--; cursor.y--;
cursor.x = _columns; cursor.x = _columns;
} }
@ -460,11 +460,11 @@ bool termParseANSI(char c) {
} }
cursor.x++; cursor.x++;
if (cursor.x > _columns) { if (cursor.x > _columns) {
termDebug("Cursor wrapped off right"); //termDebug("Cursor wrapped off right");
cursor.x = 1; cursor.x = 1;
cursor.y++; cursor.y++;
if (cursor.y > _rows) { if (cursor.y > _rows) {
termDebug("Cursor went off bottom"); //termDebug("Cursor went off bottom");
cursor.y--; cursor.y--;
termScrollUp(); termScrollUp();
} }
@ -502,7 +502,7 @@ void termRenderCharacterAtCursor(byte c) {
_screenBuffer[i].x = cx; _screenBuffer[i].x = cx;
_screenBuffer[i].y = cy; _screenBuffer[i].y = cy;
if (_cursor.y > _hiddenLines) { if (_cursor.y > _hiddenLines) {
jlDrawBlit8x8(jlStaSurfaceGet(_ansiFont), cx, cy, (_cursor.x - 1 + _xoff) * 8, (_cursor.y - 1 + _yoff) * 8); jlDrawBlit8x8(jlImgSurfaceGet(_ansiFont), cx, cy, (_cursor.x - 1 + _xoff) * 8, (_cursor.y - 1 + _yoff) * 8);
} }
} }
@ -513,7 +513,7 @@ void termRepaint(void) {
int y; int y;
for (y=_hiddenLines; y<_rows; y++) { for (y=_hiddenLines; y<_rows; y++) {
for (x=0; x<_columns; x++) { for (x=0; x<_columns; x++) {
jlDrawBlit8x8(jlStaSurfaceGet(_ansiFont), _screenBuffer[i].x, _screenBuffer[i].y, (jint16)(x + _xoff) * 8, (jint16)(y + _yoff) * 8); jlDrawBlit8x8(jlImgSurfaceGet(_ansiFont), _screenBuffer[i].x, _screenBuffer[i].y, (jint16)(x + _xoff) * 8, (jint16)(y + _yoff) * 8);
i++; i++;
} }
} }
@ -554,7 +554,7 @@ void termScrollUp(void) {
} }
void termStart(jlStaT *font, byte xoff, byte yoff, byte cols, byte rows) { void termStart(jlImgT *font, byte xoff, byte yoff, byte cols, byte rows) {
_ansiFont = font; _ansiFont = font;
_xoff = xoff; _xoff = xoff;
_yoff = yoff; _yoff = yoff;

View file

@ -13,7 +13,7 @@ void termPrintChar(char c);
void termRepaint(void); void termRepaint(void);
void termRestoreCursor(void); void termRestoreCursor(void);
void termSaveCursor(void); void termSaveCursor(void);
void termStart(jlStaT *font, byte xoff, byte yoff, byte cols, byte rows); void termStart(jlImgT *font, byte xoff, byte yoff, byte cols, byte rows);
void termStop(void); void termStop(void);
#endif // _H_ANSITERM_ #endif // _H_ANSITERM_

View file

@ -5,4 +5,6 @@ DATA=(thin.sta output.z8 gamedata.dat nowhere.vec)
#SOURCE=(*.c *.h) #SOURCE=(*.c *.h)
SOURCE=() SOURCE=()
. ${JOEY}/joeylib/joeylib/build-IIgs.helper.sh . ${JOEY}/joeylib/scripts/build-IIgs.helper.sh
buildIIgs $1

View file

@ -1,3 +1,3 @@
IF Engine Test Game IF Engine Test Game
data/output.z8 data/output.z8
thin.sta thin

View file

@ -1,49 +1,15 @@
TEMPLATE = app
CONFIG += console
CONFIG -= \
app_bundle \
qt
DESTDIR = $$OUT_PWD/build
JOEY = /home/scott/joey JOEY = /home/scott/joey
include($$JOEY/dist/joey.pri)
JOEY_INCLUDES = \ #ZIP_FLAGS = \
$$JOEY/dist # -DANSI_COLOR \
# -DUNIX \
# -DSCREEN_WIDTH=40 \
# -DSCREEN_HEIGHT=25
JOEY_HEADERS = \ #QMAKE_CFLAGS += $$ZIP_FLAGS
$$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
ZIP_FLAGS = \
-DANSI_COLOR \
-DUNIX \
-DSCREEN_WIDTH=40 \
-DSCREEN_HEIGHT=25 \
QMAKE_CFLAGS += \
$$JOEY_FLAGS
INCLUDEPATH += \
$$JOEY_INCLUDES
HEADERS += \ HEADERS += \
$$JOEY_HEADERS \
ansiterm.h \ ansiterm.h \
ztypes.h ztypes.h
@ -65,11 +31,12 @@ SOURCES += \
screen.c \ screen.c \
text.c \ text.c \
variable.c \ variable.c \
joeyio.c joeyio.c
LIBS += \ OTHER_FILES += \
$$JOEY_LIBS \ build-IIgs.sh \
postlink.sh \
notes.txt \
gamedata.dat
DISTFILES += \ linux:QMAKE_POST_LINK = $$PWD/postlink.sh "$$PWD" "$$JOEY"
build-IIgs.sh \
gamedata.dat

View file

@ -19,17 +19,18 @@ typedef enum {
} DModeT; } DModeT;
static jlImgT *_bitmap = NULL;
static jlVecT *_vectorImage = NULL; static jlVecT *_vectorImage = NULL;
static jlStaT *_graphicsPage = NULL; static jlImgT *_graphicsPage = NULL;
static jlSoundT *_soundEffect = NULL; static jlSoundT *_soundEffect = NULL;
static DModeT _displayMode = DISPLAY_MODE_TEXT; static DModeT _displayMode = DISPLAY_MODE_TEXT;
static byte _bufferCount = 0; static byte _bufferCount = 0;
static char _buffer[COMMAND_BUFFER_SIZE]; static char _buffer[COMMAND_BUFFER_SIZE];
static bool _inCommand = false; static bool _inCommand = false;
static byte _cursorIndex = 0; static byte _cursorIndex = 0;
static byte _cursorSize = 9; static byte _cursorSize = 8;
static unsigned int _cursorTime = 0; static unsigned int _cursorTime = 0;
static byte _cursor[] = { 32, 176, 177, 178, 219, 178, 177, 176, 32 }; static byte _cursor[] = { 32, 176, 177, 178, 219, 178, 177, 176 };
void set_next_display_mode(void); void set_next_display_mode(void);
@ -74,22 +75,24 @@ void clear_text_window(void) {
void create_status_window(void) { void create_status_window(void) {
printf("Create Status Window\n"); //printf("Create Status Window\n");
} }
void delete_status_window(void) { void delete_status_window(void) {
printf("Delete Status Window\n"); //printf("Delete Status Window\n");
} }
void display_char(int c) { void display_char(int c) {
char command; char command;
char *token; char *token;
int x; int x;
int y; int y;
// This also handles processing of embedded media commands: // This also handles processing of embedded media commands:
// {I name x y} - Display Image "name" @ x, y // {B name} - Display Bitmap
// {I name x y} - Display Vector Image "name" @ x, y
// {M name} - Play Music "name" // {M name} - Play Music "name"
// {S name} - Play Sound "name" // {S name} - Play Sound "name"
// {Q} - Quiet! // {Q} - Quiet!
@ -102,6 +105,20 @@ void display_char(int c) {
_buffer[_bufferCount] = 0; _buffer[_bufferCount] = 0;
(void)strtok(_buffer, " "); (void)strtok(_buffer, " ");
switch (command) { switch (command) {
case 'B':
token = strtok(NULL, " ");
if (jlImgLoad(_bitmap, token)) {
// Put user into GRAPHICS mode if they aren't.
_displayMode = DISPLAY_MODE_GRAPHICS - 1;
set_next_display_mode();
// Render the image.
jlImgDisplay(_bitmap);
// Save it to the graphics page.
jlImgCreate(_graphicsPage);
}
jlSoundMusicPlay(token);
break;
case 'I': case 'I':
token = strtok(NULL, " "); token = strtok(NULL, " ");
if (jlVecLoad(_vectorImage, token)) { if (jlVecLoad(_vectorImage, token)) {
@ -120,7 +137,7 @@ void display_char(int c) {
// Render the image. // Render the image.
jlVecDisplay(_vectorImage, (jint16)x, (jint16)y); jlVecDisplay(_vectorImage, (jint16)x, (jint16)y);
// Save it to the graphics page. // Save it to the graphics page.
jlStaCreate(_graphicsPage); jlImgCreate(_graphicsPage);
} }
break; break;
@ -183,17 +200,19 @@ void initialize_screen(void) {
jlDrawClear(); jlDrawClear();
jlDrawColorSet(15); jlDrawColorSet(15);
jlDisplayPresent(); jlDisplayPresent();
jlStaCreate(_graphicsPage); jlImgCreate(_graphicsPage);
} }
int input_character(int timeout) { int input_character(int timeout) {
char k = 0; char k = 0;
(void)timeout; // In 1/10ths of a second (void)timeout; // In 1/10ths of a second
if (!jlKeyPressed()) { if (!jlKeyPressed()) {
while (!jlKeyPressed() && !jlUtilMustExit()) { while (!jlKeyPressed() && !jlUtilMustExit()) {
// Animate cursor // Animate cursor
if (_cursorTime != jlUtilTimer()) { if (jlUtilTimeSpan(_cursorTime, jlUtilTimer()) > 3) {
display_char(_cursor[_cursorIndex++]); display_char(_cursor[_cursorIndex++]);
display_char(8); display_char(8);
if (_cursorIndex >= _cursorSize) { if (_cursorIndex >= _cursorSize) {
@ -273,7 +292,8 @@ void move_cursor(int row, int col) {
void reset_screen(void) { void reset_screen(void) {
// Also handled in main // Also handled in main
jlStaFree(_graphicsPage); jlImgFree(_graphicsPage);
jlImgFree(_bitmap);
jlVecFree(_vectorImage); jlVecFree(_vectorImage);
jlSoundFree(_soundEffect); jlSoundFree(_soundEffect);
} }
@ -330,21 +350,21 @@ void set_next_display_mode(void) {
switch (_displayMode) { switch (_displayMode) {
case DISPLAY_MODE_TEXT: case DISPLAY_MODE_TEXT:
printf("Terminal now TEXT\n"); //printf("Terminal now TEXT\n");
termHideTopLines(0); termHideTopLines(0);
termRepaint(); termRepaint();
break; break;
case DISPLAY_MODE_GRAPHICS: case DISPLAY_MODE_GRAPHICS:
printf("Terminal now GRAPHICS\n"); //printf("Terminal now GRAPHICS\n");
termHideTopLines((byte)screen_rows); termHideTopLines((byte)screen_rows);
jlStaDisplay(_graphicsPage); jlImgDisplay(_graphicsPage);
break; break;
case DISPLAY_MODE_MIXED: case DISPLAY_MODE_MIXED:
printf("Terminal now MIXED\n"); //printf("Terminal now MIXED\n");
termHideTopLines((byte)screen_rows - DISPLAY_MIXED_SIZE); termHideTopLines((byte)screen_rows - DISPLAY_MIXED_SIZE);
jlStaDisplay(_graphicsPage); jlImgDisplay(_graphicsPage);
termRepaint(); termRepaint();
break; break;

6
main.c
View file

@ -101,7 +101,7 @@ void process_arguments(char *game) {
int main(void) { int main(void) {
FILE *in; FILE *in;
jlStaT *font = NULL; jlImgT *font = NULL;
char name[40]; char name[40];
char game[40]; char game[40];
char text[40]; char text[40];
@ -121,7 +121,7 @@ int main(void) {
jlUtilStartup(name); jlUtilStartup(name);
if (!jlStaLoad(font, text)) { if (!jlImgLoad(font, text)) {
jlUtilDie("Unable to load [%s] (%d)", text, strlen(text)); jlUtilDie("Unable to load [%s] (%d)", text, strlen(text));
} }
@ -142,7 +142,7 @@ int main(void) {
reset_screen(); reset_screen();
termStop(); termStop();
jlStaFree(font); jlImgFree(font);
jlUtilShutdown(); jlUtilShutdown();
} }

10
postlink.sh Executable file
View file

@ -0,0 +1,10 @@
#!/bin/bash
GAME=$1
export JOEY=$2
mkdir -p data
cp -f "${GAME}"/gamedata.dat data/.
cp -f "${GAME}"/output.z8 data/.
cp -f "${GAME}"/*.vec data/.
cp -f "${GAME}"/*.img data/.

BIN
thin.img (Stored with Git LFS) Normal file

Binary file not shown.

BIN
thin.sta (Stored with Git LFS)

Binary file not shown.